use of io.jpom.model.data.ServerWhitelist in project Jpom by dromara.
the class OutGivingProjectController method remoteDownload.
/**
* 远程下载节点分发文件
*
* @param id 分发id
* @param afterOpt 之后的操作
* @return json
*/
@RequestMapping(value = "remote_download", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.REMOTE_DOWNLOAD)
public String remoteDownload(String id, String afterOpt, String clearOld, String url, String autoUnzip) {
OutGivingModel outGivingModel = this.check(id);
AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
Assert.notNull(afterOpt1, "请选择分发后的操作");
// 验证远程 地址
ServerWhitelist whitelist = outGivingWhitelistService.getServerWhitelistData(getRequest());
Set<String> allowRemoteDownloadHost = whitelist.getAllowRemoteDownloadHost();
Assert.state(CollUtil.isNotEmpty(allowRemoteDownloadHost), "还没有配置运行的远程地址");
List<String> collect = allowRemoteDownloadHost.stream().filter(s -> StrUtil.startWith(url, s)).collect(Collectors.toList());
Assert.state(CollUtil.isNotEmpty(collect), "不允许下载当前地址的文件");
try {
// outGivingModel = outGivingServer.getItem(id);
outGivingModel.setClearOld(Convert.toBool(clearOld, false));
outGivingModel.setAfterOpt(afterOpt1.getCode());
outGivingServer.update(outGivingModel);
// 下载
File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), ServerConfigBean.OUTGIVING_FILE, id);
FileUtil.mkdir(file);
File downloadFile = HttpUtil.downloadFileFromUrl(url, file);
boolean unzip = BooleanUtil.toBoolean(autoUnzip);
//
this.checkZip(downloadFile, unzip);
// 开启
OutGivingRun.startRun(outGivingModel.getId(), downloadFile, getUser(), unzip);
return JsonMessage.getString(200, "分发成功");
} catch (Exception e) {
DefaultSystemLog.getLog().error("下载远程文件异常", e);
return JsonMessage.getString(500, "下载远程文件失败:" + e.getMessage());
}
}
use of io.jpom.model.data.ServerWhitelist in project Jpom by dromara.
the class OutGivingWhitelistController method whiteList.
/**
* get whiteList data
* 白名单数据接口
*
* @return json
* @author Hotstrip
*/
@RequestMapping(value = "white-list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String whiteList() {
ServerWhitelist serverWhitelist = outGivingWhitelistService.getServerWhitelistData(getRequest());
Field[] fields = ReflectUtil.getFields(ServerWhitelist.class);
Map<String, Object> map = new HashMap<>(8);
for (Field field : fields) {
Object value = ReflectUtil.getFieldValue(serverWhitelist, field);
if (value instanceof Collection) {
Collection<String> fieldValue = (Collection<String>) value;
map.put(field.getName(), AgentWhitelist.convertToLine(fieldValue));
map.put(field.getName() + "Array", fieldValue);
}
}
return JsonMessage.getString(200, "ok", map);
}
use of io.jpom.model.data.ServerWhitelist in project Jpom by dromara.
the class OutGivingWhitelistService method getServerWhitelistData.
public ServerWhitelist getServerWhitelistData(HttpServletRequest request) {
String workspaceId = nodeService.getCheckUserWorkspace(request);
String id = ServerWhitelist.workspaceId(workspaceId);
ServerWhitelist serverWhitelist = systemParametersServer.getConfig(id, ServerWhitelist.class);
if (serverWhitelist == null) {
// 兼容旧数据
serverWhitelist = systemParametersServer.getConfigDefNewInstance(ServerWhitelist.ID, ServerWhitelist.class);
}
return serverWhitelist;
}
use of io.jpom.model.data.ServerWhitelist in project Jpom by dromara.
the class OutGivingWhitelistController method whitelistDirectorySubmit.
/**
* 保存节点白名单
*
* @param outGiving 数据
* @return json
*/
@RequestMapping(value = "whitelistDirectory_submit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission
@Feature(method = MethodFeature.EDIT)
public String whitelistDirectorySubmit(String outGiving, String allowRemoteDownloadHost) {
List<String> list = AgentWhitelist.parseToList(outGiving, true, "项目路径白名单不能为空");
list = AgentWhitelist.covertToArray(list, "项目路径白名单不能位于Jpom目录下");
ServerWhitelist serverWhitelist = outGivingWhitelistService.getServerWhitelistData(getRequest());
serverWhitelist.setOutGiving(list);
//
List<String> allowRemoteDownloadHostList = AgentWhitelist.parseToList(allowRemoteDownloadHost, "运行远程下载的 host 不能配置为空");
//
if (CollUtil.isNotEmpty(allowRemoteDownloadHostList)) {
for (String s : allowRemoteDownloadHostList) {
Assert.state(ReUtil.isMatch(RegexPool.URL_HTTP, s), "配置的远程地址不规范,请重新填写:" + s);
}
}
serverWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHostList == null ? null : CollUtil.newHashSet(allowRemoteDownloadHostList));
//
String workspaceId = nodeService.getCheckUserWorkspace(getRequest());
String id = ServerWhitelist.workspaceId(workspaceId);
systemParametersServer.upsert(id, serverWhitelist, id);
String resultData = AgentWhitelist.convertToLine(list);
return JsonMessage.getString(200, "保存成功", resultData);
}
Aggregations