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, "保存成功");
}
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);
}
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);
}
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();
}
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);
}
Aggregations