Search in sources :

Example 1 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class ScriptController method upload.

@RequestMapping(value = "upload.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String upload() throws IOException {
    MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file").setFileExt("bat", "sh");
    multipartFileBuilder.setSavePath(AgentConfigBean.getInstance().getTempPathName());
    multipartFileBuilder.setUseOriginalFilename(true);
    String path = multipartFileBuilder.save();
    File file = FileUtil.file(path);
    String context = FileUtil.readString(path, ExtConfigBean.getInstance().getConsoleLogCharset());
    Assert.hasText(context, "脚本内容为空");
    String name = file.getName();
    String id = SecureUtil.sha1(name);
    NodeScriptModel eModel = nodeScriptServer.getItem(id);
    if (eModel != null) {
        return JsonMessage.getString(405, "对应脚本模板已经存在啦");
    }
    eModel = new NodeScriptModel();
    eModel.setId(id);
    eModel.setName(name);
    eModel.setWorkspaceId(getWorkspaceId());
    eModel.setContext(context);
    file = eModel.getFile(true);
    if (file.exists() || file.isDirectory()) {
        return JsonMessage.getString(405, "当地id路径文件已经存在来,请修改");
    }
    nodeScriptServer.addItem(eModel);
    return JsonMessage.getString(200, "导入成功");
}
Also used : NodeScriptModel(io.jpom.model.data.NodeScriptModel) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class CertificateController method getCertFile.

private String getCertFile(CertModel certModel, boolean add) throws IOException {
    String certPath = null;
    try {
        String path = AgentConfigBean.getInstance().getTempPathName();
        MultipartFileBuilder cert = createMultipart().addFieldName("file").setSavePath(path);
        certPath = cert.save();
        Object val = getUpdateFileInfo(certModel, certPath);
        if (val instanceof String) {
            return val.toString();
        }
        JSONObject jsonObject = (JSONObject) val;
        String domain = jsonObject.getString("domain");
        if (add) {
            List<CertModel> array = certService.list();
            if (array != null) {
                for (CertModel certModel1 : array) {
                    if (StrUtil.emptyToDefault(domain, "").equals(certModel1.getDomain())) {
                        return JsonMessage.getString(405, "证书的域名已经存在啦");
                    }
                }
            }
        } else {
            if (!StrUtil.emptyToDefault(domain, "").equals(certModel.getDomain())) {
                return JsonMessage.getString(405, "新证书的域名不一致");
            }
        }
        // 移动位置
        String temporary = certModel.getWhitePath() + StrUtil.SLASH + certModel.getId() + StrUtil.SLASH;
        File pemFile = FileUtil.file(temporary + certModel.getId() + "." + certModel.getType().name());
        File keyFile = FileUtil.file(temporary + certModel.getId() + ".key");
        if (add) {
            if (pemFile.exists()) {
                return JsonMessage.getString(405, pemFile.getAbsolutePath() + " 已经被占用啦");
            }
            if (keyFile.exists()) {
                return JsonMessage.getString(405, keyFile.getAbsolutePath() + " 已经被占用啦");
            }
        }
        String pemPath = jsonObject.getString("pemPath");
        String keyPath = jsonObject.getString("keyPath");
        FileUtil.move(FileUtil.file(pemPath), pemFile, true);
        FileUtil.move(FileUtil.file(keyPath), keyFile, true);
        certModel.setCert(pemFile.getAbsolutePath());
        certModel.setKey(keyFile.getAbsolutePath());
        // 
        certModel.setDomain(domain);
        certModel.setExpirationTime(jsonObject.getLongValue("expirationTime"));
        certModel.setEffectiveTime(jsonObject.getLongValue("effectiveTime"));
    } finally {
        if (certPath != null) {
            FileUtil.del(certPath);
        }
    }
    return null;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) CertModel(io.jpom.model.data.CertModel) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 3 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class TomcatManageController method uploadWar.

/**
 * 上传war文件
 *
 * @param id tomcat id
 * @return 操作结果
 */
@RequestMapping(value = "uploadWar", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String uploadWar(String id) {
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file");
    File dir = new File(tomcatInfoModel.getAppBase());
    multipartFileBuilder.setSavePath(dir.getAbsolutePath()).setUseOriginalFilename(true);
    // 保存
    try {
        multipartFileBuilder.save();
    } catch (IOException e) {
        return JsonMessage.getString(500, "上传异常");
    }
    return JsonMessage.getString(200, "上传成功");
}
Also used : TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) IOException(java.io.IOException) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class TomcatManageController method upload.

/**
 * 上传文件
 *
 * @param id   tomcat id
 * @param path 文件路径
 * @return 操作结果
 */
@RequestMapping(value = "upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String upload(String id, String path) {
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file");
    File dir = new File(tomcatInfoModel.getAppBase().concat(FileUtil.normalize(path)));
    multipartFileBuilder.setSavePath(dir.getAbsolutePath()).setUseOriginalFilename(true);
    // 保存
    try {
        multipartFileBuilder.save();
    } catch (IOException e) {
        return JsonMessage.getString(500, "上传异常");
    }
    return JsonMessage.getString(200, "上传成功");
}
Also used : TomcatInfoModel(io.jpom.model.data.TomcatInfoModel) IOException(java.io.IOException) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MultipartFileBuilder

use of cn.jiangzeyin.controller.multipart.MultipartFileBuilder in project Jpom by dromara.

the class SystemUpdateController method uploadJar.

@PostMapping(value = "uploadJar.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String uploadJar() throws IOException {
    NodeModel nodeModel = tryGetNode();
    if (nodeModel != null) {
        return NodeForward.requestMultipart(getNode(), getMultiRequest(), NodeUrl.SystemUploadJar).toString();
    }
    // 
    Objects.requireNonNull(JpomManifest.getScriptFile());
    MultipartFileBuilder multipartFileBuilder = createMultipart();
    String absolutePath = ServerConfigBean.getInstance().getUserTempPath().getAbsolutePath();
    multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(absolutePath);
    String path = multipartFileBuilder.save();
    // 解析压缩包
    File file = JpomManifest.zipFileFind(path, Type.Server, absolutePath);
    path = FileUtil.getAbsolutePath(file);
    // 基础检查
    JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Server);
    if (error.getCode() != HttpStatus.HTTP_OK) {
        return error.toString();
    }
    Tuple data = error.getData();
    String version = data.get(0);
    JpomManifest.releaseJar(path, version);
    // 
    backupInfoService.autoBackup();
    // 
    JpomApplication.restart();
    return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) Tuple(cn.hutool.core.lang.Tuple) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)12 File (java.io.File)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ClassFeature (io.jpom.permission.ClassFeature)6 Feature (io.jpom.permission.Feature)6 MethodFeature (io.jpom.permission.MethodFeature)6 Tuple (cn.hutool.core.lang.Tuple)3 SystemPermission (io.jpom.permission.SystemPermission)3 JSONObject (com.alibaba.fastjson.JSONObject)2 AfterOpt (io.jpom.model.AfterOpt)2 TomcatInfoModel (io.jpom.model.data.TomcatInfoModel)2 IOException (java.io.IOException)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)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