Search in sources :

Example 1 with ServerWhitelist

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());
    }
}
Also used : MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServerWhitelist(io.jpom.model.data.ServerWhitelist) ServerConfigBean(io.jpom.system.ServerConfigBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Feature(io.jpom.permission.Feature) ProjectInfoCacheService(io.jpom.service.node.ProjectInfoCacheService) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) BaseEnum(io.jpom.model.BaseEnum) OutGivingRun(io.jpom.outgiving.OutGivingRun) BaseNodeModel(io.jpom.model.BaseNodeModel) OutGivingServer(io.jpom.service.node.OutGivingServer) MethodFeature(io.jpom.permission.MethodFeature) NodeForward(io.jpom.common.forward.NodeForward) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) NodeModel(io.jpom.model.data.NodeModel) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IOException(java.io.IOException) AfterOpt(io.jpom.model.AfterOpt) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanUtil(cn.hutool.core.util.BooleanUtil) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) Objects(java.util.Objects) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ValidatorRule(cn.jiangzeyin.common.validator.ValidatorRule) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) StringUtil(io.jpom.util.StringUtil) Convert(cn.hutool.core.convert.Convert) ConfigBean(io.jpom.system.ConfigBean) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) ServerWhitelist(io.jpom.model.data.ServerWhitelist) AfterOpt(io.jpom.model.AfterOpt) OutGivingModel(io.jpom.model.data.OutGivingModel) File(java.io.File) IOException(java.io.IOException) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ServerWhitelist

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

Example 3 with ServerWhitelist

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;
}
Also used : ServerWhitelist(io.jpom.model.data.ServerWhitelist)

Example 4 with 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);
}
Also used : ServerWhitelist(io.jpom.model.data.ServerWhitelist) SystemPermission(io.jpom.permission.SystemPermission) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ServerWhitelist (io.jpom.model.data.ServerWhitelist)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ClassFeature (io.jpom.permission.ClassFeature)2 Feature (io.jpom.permission.Feature)2 MethodFeature (io.jpom.permission.MethodFeature)2 CollUtil (cn.hutool.core.collection.CollUtil)1 Convert (cn.hutool.core.convert.Convert)1 FileUtil (cn.hutool.core.io.FileUtil)1 BooleanUtil (cn.hutool.core.util.BooleanUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 HttpUtil (cn.hutool.http.HttpUtil)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 ValidatorItem (cn.jiangzeyin.common.validator.ValidatorItem)1 ValidatorRule (cn.jiangzeyin.common.validator.ValidatorRule)1 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)1 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseServerController (io.jpom.common.BaseServerController)1 NodeForward (io.jpom.common.forward.NodeForward)1 NodeUrl (io.jpom.common.forward.NodeUrl)1