Search in sources :

Example 1 with AgentWhitelist

use of io.jpom.model.data.AgentWhitelist in project Jpom by dromara.

the class WhitelistDirectoryController method save.

// 
// private JsonMessage<String> save(String project, List<String> certificate, List<String> nginx, List<String> allowEditSuffixList) {
// 
// return save(list, certificate, nginx);
// }
private JsonMessage<String> save(List<String> projects, List<String> certificate, List<String> nginx, List<String> allowEditSuffixList, List<String> allowRemoteDownloadHostList) {
    List<String> projectArray;
    {
        projectArray = AgentWhitelist.covertToArray(projects, "项目路径白名单不能位于Jpom目录下");
        String error = findStartsWith(projectArray, 0);
        if (error != null) {
            return new JsonMessage<>(401, "白名单目录中不能存在包含关系:" + error);
        }
    }
    List<String> certificateArray = null;
    if (certificate != null && !certificate.isEmpty()) {
        certificateArray = AgentWhitelist.covertToArray(certificate, "证书路径白名单不能位于Jpom目录下");
        String error = findStartsWith(certificateArray, 0);
        if (error != null) {
            return new JsonMessage<>(401, "证书目录中不能存在包含关系:" + error);
        }
    }
    List<String> nginxArray = null;
    if (nginx != null && !nginx.isEmpty()) {
        nginxArray = AgentWhitelist.covertToArray(nginx, "nginx路径白名单不能位于Jpom目录下");
        String error = findStartsWith(nginxArray, 0);
        if (error != null) {
            return new JsonMessage<>(401, "nginx目录中不能存在包含关系:" + error);
        }
    }
    // 
    if (CollUtil.isNotEmpty(allowEditSuffixList)) {
        for (String s : allowEditSuffixList) {
            List<String> split = StrUtil.split(s, StrUtil.AT);
            if (split.size() > 1) {
                String last = CollUtil.getLast(split);
                try {
                    CharsetUtil.charset(last);
                } catch (Exception e) {
                    throw new IllegalArgumentException("配置的字符编码格式不合法:" + s);
                }
            }
        }
    }
    if (CollUtil.isNotEmpty(allowRemoteDownloadHostList)) {
        for (String s : allowRemoteDownloadHostList) {
            Assert.state(ReUtil.isMatch(RegexPool.URL_HTTP, s), "配置的远程地址不规范,请重新填写:" + s);
        }
    }
    AgentWhitelist agentWhitelist = whitelistDirectoryService.getWhitelist();
    agentWhitelist.setProject(projectArray);
    agentWhitelist.setCertificate(certificateArray);
    agentWhitelist.setNginx(nginxArray);
    agentWhitelist.setAllowEditSuffix(allowEditSuffixList);
    agentWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHostList == null ? null : CollUtil.newHashSet(allowRemoteDownloadHostList));
    whitelistDirectoryService.saveWhitelistDirectory(agentWhitelist);
    return new JsonMessage<>(200, "保存成功");
}
Also used : JsonMessage(cn.jiangzeyin.common.JsonMessage) AgentWhitelist(io.jpom.model.data.AgentWhitelist)

Example 2 with AgentWhitelist

use of io.jpom.model.data.AgentWhitelist in project Jpom by dromara.

the class WhitelistDirectoryService method addProjectWhiteList.

/**
 * 单项添加白名单
 *
 * @param item 白名单
 */
public void addProjectWhiteList(String item) {
    AgentWhitelist agentWhitelist = getWhitelist();
    List<String> project = agentWhitelist.getProject();
    if (project == null) {
        project = new ArrayList<>();
    }
    project.add(item);
    saveWhitelistDirectory(agentWhitelist);
}
Also used : AgentWhitelist(io.jpom.model.data.AgentWhitelist)

Example 3 with AgentWhitelist

use of io.jpom.model.data.AgentWhitelist in project Jpom by dromara.

the class WhitelistDirectoryService method checkProjectDirectory.

public boolean checkProjectDirectory(String path) {
    AgentWhitelist agentWhitelist = getWhitelist();
    List<String> list = agentWhitelist.getProject();
    return AgentWhitelist.checkPath(list, path);
}
Also used : AgentWhitelist(io.jpom.model.data.AgentWhitelist)

Example 4 with AgentWhitelist

use of io.jpom.model.data.AgentWhitelist in project Jpom by dromara.

the class WhitelistDirectoryService method isInstalled.

public boolean isInstalled() {
    AgentWhitelist agentWhitelist = getWhitelist();
    List<String> project = agentWhitelist.getProject();
    return project != null && !project.isEmpty();
}
Also used : AgentWhitelist(io.jpom.model.data.AgentWhitelist)

Example 5 with AgentWhitelist

use of io.jpom.model.data.AgentWhitelist in project Jpom by dromara.

the class ProjectFileControl method readFile.

/**
 * 读取文件内容 (只能处理文本文件)
 *
 * @param filePath 相对项目文件的文件夹
 * @param filename 读取的文件名
 * @return json
 */
@PostMapping(value = "read_file", produces = MediaType.APPLICATION_JSON_VALUE)
public String readFile(String filePath, String filename) {
    NodeProjectInfoModel pim = getProjectInfoModel();
    filePath = StrUtil.emptyToDefault(filePath, File.separator);
    // 判断文件后缀
    AgentWhitelist whitelist = whitelistDirectoryService.getWhitelist();
    Charset charset = AgentWhitelist.checkFileSuffix(whitelist.getAllowEditSuffix(), filename);
    File file = FileUtil.file(pim.allLib(), filePath, filename);
    String ymlString = FileUtil.readString(file, charset);
    return JsonMessage.getString(200, "", ymlString);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) Charset(java.nio.charset.Charset) AgentWhitelist(io.jpom.model.data.AgentWhitelist) File(java.io.File)

Aggregations

AgentWhitelist (io.jpom.model.data.AgentWhitelist)11 JSONObject (com.alibaba.fastjson.JSONObject)4 NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)4 File (java.io.File)4 JSONArray (com.alibaba.fastjson.JSONArray)3 Charset (java.nio.charset.Charset)3 JsonMessage (cn.jiangzeyin.common.JsonMessage)2 CollStreamUtil (cn.hutool.core.collection.CollStreamUtil)1 CollUtil (cn.hutool.core.collection.CollUtil)1 Convert (cn.hutool.core.convert.Convert)1 FileUtil (cn.hutool.core.io.FileUtil)1 ThreadUtil (cn.hutool.core.thread.ThreadUtil)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 BooleanUtil (cn.hutool.core.util.BooleanUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 SecureUtil (cn.hutool.crypto.SecureUtil)1 ServletUtil (cn.hutool.extra.servlet.ServletUtil)1 HttpUtil (cn.hutool.http.HttpUtil)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)1