Search in sources :

Example 1 with SystemPermission

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, "关闭成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) SystemPermission(io.jpom.permission.SystemPermission) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 2 with SystemPermission

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);
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) SshModel(io.jpom.model.data.SshModel) ZipFile(java.util.zip.ZipFile) File(java.io.File) ServerConfigBean(io.jpom.system.ServerConfigBean) SystemPermission(io.jpom.permission.SystemPermission) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SystemPermission

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 + "条项目缓存");
}
Also used : Entity(cn.hutool.db.Entity) SystemPermission(io.jpom.permission.SystemPermission) GetMapping(org.springframework.web.bind.annotation.GetMapping) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 4 with SystemPermission

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, "导入成功");
}
Also used : BackupInfoModel(io.jpom.model.data.BackupInfoModel) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) SystemPermission(io.jpom.permission.SystemPermission) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 5 with SystemPermission

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);
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Collection(java.util.Collection) AgentWhitelist(io.jpom.model.data.AgentWhitelist) SystemPermission(io.jpom.permission.SystemPermission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SystemPermission (io.jpom.permission.SystemPermission)15 ClassFeature (io.jpom.permission.ClassFeature)13 Feature (io.jpom.permission.Feature)13 MethodFeature (io.jpom.permission.MethodFeature)13 File (java.io.File)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 Entity (cn.hutool.db.Entity)3 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)3 JSONObject (com.alibaba.fastjson.JSONObject)3 NodeModel (io.jpom.model.data.NodeModel)3 Tuple (cn.hutool.core.lang.Tuple)2 UserModel (io.jpom.model.data.UserModel)2 ServerConfigBean (io.jpom.system.ServerConfigBean)2 HashMap (java.util.HashMap)2 ZipFile (java.util.zip.ZipFile)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 BaseNodeModel (io.jpom.model.BaseNodeModel)1 BaseWorkspaceModel (io.jpom.model.BaseWorkspaceModel)1 AgentWhitelist (io.jpom.model.data.AgentWhitelist)1