Search in sources :

Example 96 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class SystemConfigController method saveIpConfig.

@RequestMapping(value = "save_ip_config.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_CONFIG_IP, method = MethodFeature.EDIT)
public String saveIpConfig(String allowed, String prohibited) {
    SystemIpConfigModel systemIpConfigModel = new SystemIpConfigModel();
    String allowed1 = StrUtil.emptyToDefault(allowed, StrUtil.EMPTY);
    this.checkIpV4(allowed1);
    systemIpConfigModel.setAllowed(allowed1);
    // 
    String prohibited1 = StrUtil.emptyToDefault(prohibited, StrUtil.EMPTY);
    systemIpConfigModel.setProhibited(prohibited1);
    this.checkIpV4(prohibited1);
    systemParametersServer.upsert(SystemIpConfigModel.ID, systemIpConfigModel, SystemIpConfigModel.ID);
    // 
    return JsonMessage.getString(200, "修改成功");
}
Also used : SystemIpConfigModel(io.jpom.model.data.SystemIpConfigModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 97 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class SystemConfigController method saveConfig.

@PostMapping(value = "save_config.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
@SystemPermission(superUser = true)
public String saveConfig(String nodeId, String content, String restart) throws IOException, SQLException {
    if (StrUtil.isNotEmpty(nodeId)) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.SystemSaveConfig).toString();
    }
    Assert.hasText(content, "内容不能为空");
    try {
        YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader();
        // @author hjk 前端编辑器允许使用tab键,并设定为2个空格,再转换为yml时要把tab键换成2个空格
        ByteArrayResource resource = new ByteArrayResource(content.replace("\t", "  ").getBytes(StandardCharsets.UTF_8));
        yamlPropertySourceLoader.load("test", resource);
    } catch (Exception e) {
        DefaultSystemLog.getLog().warn("内容格式错误,请检查修正", e);
        return JsonMessage.getString(500, "内容格式错误,请检查修正:" + e.getMessage());
    }
    boolean restartBool = Convert.toBool(restart, false);
    // 修改数据库密码
    DbExtConfig oldDbExtConfig = DbExtConfig.parse(ExtConfigBean.getResource().getInputStream());
    DbExtConfig newDbExtConfig = DbExtConfig.parse(content);
    if (!StrUtil.equals(oldDbExtConfig.getUserName(), newDbExtConfig.getUserName()) || !StrUtil.equals(oldDbExtConfig.getUserPwd(), newDbExtConfig.getUserPwd())) {
        // 执行修改数据库账号密码
        Assert.state(restartBool, "修改数据库密码必须重启");
        initDb.alterUser(oldDbExtConfig.getUserName(), newDbExtConfig.getUserName(), newDbExtConfig.getUserPwd());
    }
    Assert.state(!JpomManifest.getInstance().isDebug(), "调试模式下不支持在线修改,请到resources目录下的bin目录修改extConfig.yml");
    File resourceFile = ExtConfigBean.getResourceFile();
    FileUtil.writeString(content, resourceFile, CharsetUtil.CHARSET_UTF_8);
    if (restartBool) {
        // 重启
        ThreadUtil.execute(() -> {
            ThreadUtil.sleep(2000);
            JpomApplication.restart();
        });
        return JsonMessage.getString(200, Const.UPGRADE_MSG);
    }
    return JsonMessage.getString(200, "修改成功");
}
Also used : DbExtConfig(io.jpom.system.extconf.DbExtConfig) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) ByteArrayResource(org.springframework.core.io.ByteArrayResource) File(java.io.File) SQLException(java.sql.SQLException) IOException(java.io.IOException) 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 98 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class SystemConfigController method configData.

/**
 * get server's config or node's config
 * 加载服务端或者节点端配置
 *
 * @param nodeId 节点ID
 * @return json
 * @throws IOException io
 * @author Hotstrip
 */
@RequestMapping(value = "config-data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String configData(String nodeId) throws IOException {
    JSONObject jsonObject;
    if (StrUtil.isNotEmpty(nodeId)) {
        jsonObject = NodeForward.requestData(getNode(), NodeUrl.SystemGetConfig, getRequest(), JSONObject.class);
    } else {
        jsonObject = new JSONObject();
        Resource resource = ExtConfigBean.getResource();
        String content = IoUtil.read(resource.getInputStream(), CharsetUtil.CHARSET_UTF_8);
        jsonObject.put("content", content);
        jsonObject.put("file", FileUtil.getAbsolutePath(resource.getFile()));
    }
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 99 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class SystemConfigController method saveNodeConfig.

@PostMapping(value = "save_node_config.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
@SystemPermission(superUser = true)
public String saveNodeConfig(@ValidatorItem(msg = "请选择分发的节点") String nodeIds, String templateNodeId, String content, String restart) {
    Assert.hasText(content, "内容不能为空");
    HttpServletRequest httpServletRequest = getRequest();
    String workspaceId = nodeService.getCheckUserWorkspace(httpServletRequest);
    String id = StrUtil.format("node_config_{}", workspaceId);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("templateNodeId", templateNodeId);
    jsonObject.put("nodeIds", nodeIds);
    systemParametersServer.upsert(id, jsonObject, id);
    // 
    List<String> nodeIdsStr = StrUtil.splitTrim(nodeIds, StrUtil.LF);
    UserModel user = getUser();
    for (String s : nodeIdsStr) {
        NodeModel byKey = nodeService.getByKey(s, httpServletRequest);
        JSONObject reqData = new JSONObject();
        reqData.put("content", content);
        reqData.put("restart", restart);
        JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.SystemSaveConfig, user, reqData);
        Assert.state(request.getCode() == 200, "分发 " + byKey.getName() + " 节点配置失败" + request.getMsg());
    }
    return JsonMessage.getString(200, "修改成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) 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 100 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class SystemConfigController method saveWhitelist.

/**
 * 保存白名单配置
 *
 * @return json
 */
@RequestMapping(value = "save_whitelist", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_NODE_WHITELIST, method = MethodFeature.EDIT)
public String saveWhitelist(@ValidatorItem(msg = "请选择分发的节点") String nodeIds, String project, String certificate, String nginx, String allowEditSuffix, String allowRemoteDownloadHost) {
    HttpServletRequest httpServletRequest = getRequest();
    String workspaceId = nodeService.getCheckUserWorkspace(httpServletRequest);
    NodeAgentWhitelist agentWhitelist = new NodeAgentWhitelist();
    agentWhitelist.setNodeIds(nodeIds);
    agentWhitelist.setProject(project);
    agentWhitelist.setCertificate(certificate);
    agentWhitelist.setNginx(nginx);
    agentWhitelist.setAllowEditSuffix(allowEditSuffix);
    agentWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHost);
    String format = StrUtil.format("node_whitelist_{}", workspaceId);
    systemParametersServer.upsert(format, agentWhitelist, format);
    // 
    List<String> nodeIdsStr = StrUtil.splitTrim(nodeIds, StrUtil.LF);
    UserModel user = getUser();
    for (String s : nodeIdsStr) {
        NodeModel byKey = nodeService.getByKey(s, httpServletRequest);
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(agentWhitelist);
        JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.WhitelistDirectory_Submit, user, jsonObject);
        Assert.state(request.getCode() == 200, "分发 " + byKey.getName() + " 节点配置失败" + request.getMsg());
    }
    return JsonMessage.getString(200, "保存成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) NodeAgentWhitelist(io.jpom.model.node.NodeAgentWhitelist) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Feature (io.jpom.permission.Feature)129 MethodFeature (io.jpom.permission.MethodFeature)129 ClassFeature (io.jpom.permission.ClassFeature)128 JSONObject (com.alibaba.fastjson.JSONObject)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 File (java.io.File)36 PostMapping (org.springframework.web.bind.annotation.PostMapping)25 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)22 NodeModel (io.jpom.model.data.NodeModel)21 GetMapping (org.springframework.web.bind.annotation.GetMapping)21 UserModel (io.jpom.model.data.UserModel)14 SystemPermission (io.jpom.permission.SystemPermission)14 BuildInfoModel (io.jpom.model.data.BuildInfoModel)12 SshModel (io.jpom.model.data.SshModel)10 Entity (cn.hutool.db.Entity)8 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)8 JSONArray (com.alibaba.fastjson.JSONArray)8 JsonMessage (cn.jiangzeyin.common.JsonMessage)7 List (java.util.List)7