use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class UserListController method closeMfa.
/**
* 关闭用户 mfa
*
* @param id id
* @return json
*/
@GetMapping(value = "close_user_mfa", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
@SystemPermission(superUser = true)
public String closeMfa(@ValidatorItem String id) {
UserModel update = new UserModel(id);
update.setTwoFactorAuthKey(StrUtil.EMPTY);
userService.update(update);
return JsonMessage.getString(200, "关闭成功");
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class SshInstallAgentController method installAgentSubmit.
@RequestMapping(value = "installAgentSubmit.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
@SystemPermission
public String installAgentSubmit(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "节点数据") String nodeData, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "安装路径") String path) throws Exception {
//
SshModel sshModel = sshService.getByKey(id, false);
Objects.requireNonNull(sshModel, "没有找到对应ssh");
// 判断输入的节点信息
NodeModel nodeModel = this.getNodeModel(nodeData, sshModel);
//
ServerConfigBean instance = ServerConfigBean.getInstance();
String tempFilePath = instance.getUserTempPath().getAbsolutePath();
JSONObject agentFile = this.getAgentFile();
String filePath = agentFile.getString("path");
//
File outFle = FileUtil.file(tempFilePath, Type.Agent.name() + "_" + IdUtil.fastSimpleUUID());
try {
String tag = this.unZipGetTag(filePath, outFle);
//
this.readNodeAuthorize(outFle, nodeModel);
// 查询远程是否运行
Assert.state(!sshService.checkSshRun(sshModel, tag), "对应服务器中已经存在 Jpom 插件端,不需要再次安装啦");
// 上传文件到服务器
sshService.uploadDir(sshModel, path, outFle);
//
String shPtah = FileUtil.normalize(path + StrUtil.SLASH + Type.Agent.name() + ".sh");
String chmod = getParameter("chmod");
if (StrUtil.isEmptyOrUndefined(chmod)) {
chmod = StrUtil.EMPTY;
} else {
chmod = StrUtil.format("{} {} && ", chmod, shPtah);
}
String command = StrUtil.format("{}bash {} start upgrade", chmod, shPtah);
String result = sshService.exec(sshModel, command);
DefaultSystemLog.getLog().debug("ssh install agent node {} {}", command, result);
// 休眠 5 秒, 尝试 5 次
int waitCount = getParameterInt("waitCount", 5);
this.loopCheck(waitCount, nodeModel, sshModel, path, result);
// 绑定关系
nodeModel.setSshId(sshModel.getId());
nodeService.insert(nodeModel);
//
return JsonMessage.getString(200, "操作成功:" + result);
} finally {
// 清理资源
FileUtil.del(outFle);
}
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class NodeProjectInfoController method clearAll.
/**
* 删除节点缓存的所有项目
*
* @return json
*/
@GetMapping(value = "clear_all_project", produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission(superUser = true)
@Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL)
public String clearAll() {
Entity where = Entity.create();
where.set("id", " <> id");
int del = projectInfoCacheService.del(where);
return JsonMessage.getString(200, "成功删除" + del + "条项目缓存");
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class BackupInfoController method uploadBackupFile.
/**
* 导入备份数据
*
* @return json
*/
@PostMapping(value = "/system/backup/upload")
@Feature(method = MethodFeature.UPLOAD)
@SystemPermission(superUser = true)
public Object uploadBackupFile() throws IOException {
MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file");
// 备份类型
// int backupType = Integer.parseInt(getParameter("backupType"));
// 存储目录
File directory = FileUtil.file(DbConfig.getInstance().dbLocalPath(), Const.BACKUP_DIRECTORY_NAME);
// 保存文件
multipartFileBuilder.setSavePath(FileUtil.getAbsolutePath(directory)).setUseOriginalFilename(false);
String backupSqlPath = multipartFileBuilder.save();
// 记录到数据库
final File file = new File(backupSqlPath);
String sha1Sum = SecureUtil.sha1(file);
BackupInfoModel backupInfoModel = new BackupInfoModel();
backupInfoModel.setSha1Sum(sha1Sum);
boolean exists = backupInfoService.exists(backupInfoModel);
if (exists) {
FileUtil.del(file);
return JsonMessage.getString(400, "导入的数据已经存在啦");
}
// backupInfoModel.setId(IdUtil.fastSimpleUUID());
backupInfoModel.setName(file.getName());
backupInfoModel.setBackupType(BackupTypeEnum.IMPORT.getCode());
backupInfoModel.setStatus(BackupStatusEnum.SUCCESS.getCode());
backupInfoModel.setFileSize(FileUtil.size(file));
backupInfoModel.setSha1Sum(sha1Sum);
backupInfoModel.setFilePath(backupSqlPath);
backupInfoService.insert(backupInfoModel);
return JsonMessage.toJson(200, "导入成功");
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class WhitelistDirectoryController method whiteList.
/**
* get whiteList data
* 白名单数据接口
*
* @return json
* @author Hotstrip
*/
@RequestMapping(value = "white-list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission
public String whiteList() {
AgentWhitelist agentWhitelist = whitelistDirectoryService.getData(getNode());
Map<String, String> map = new HashMap<>(8);
if (agentWhitelist != null) {
/**
* put key and value into map
* 赋值给 map 对象返回
*/
Field[] fields = ReflectUtil.getFields(AgentWhitelist.class);
for (Field field : fields) {
Collection<String> fieldValue = (Collection<String>) ReflectUtil.getFieldValue(agentWhitelist, field);
map.put(field.getName(), AgentWhitelist.convertToLine(fieldValue));
}
}
return JsonMessage.getString(200, "ok", map);
}
Aggregations