Search in sources :

Example 26 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class NodeEditController method nodeStatus.

@RequestMapping(value = "node_status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String nodeStatus() {
    long timeMillis = System.currentTimeMillis();
    NodeModel node = getNode();
    JSONObject jsonObject = NodeForward.requestData(node, NodeUrl.Status, getRequest(), JSONObject.class);
    Assert.notNull(jsonObject, "获取信息失败");
    JSONArray jsonArray = new JSONArray();
    jsonObject.put("timeOut", System.currentTimeMillis() - timeMillis);
    jsonObject.put("nodeId", node.getId());
    jsonArray.add(jsonObject);
    return JsonMessage.getString(200, "", jsonArray);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 27 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class LogManageController method logData.

/**
 * 删除 需要验证是否最后修改时间
 *
 * @param nodeId 节点
 * @param path   路径
 * @return json
 */
@RequestMapping(value = "log_del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String logData(String nodeId, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
    if (StrUtil.isNotEmpty(nodeId)) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.DelSystemLog).toString();
    }
    WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
    File file = FileUtil.file(webAopLog.getPropertyValue(), path);
    // 判断修改时间
    long modified = file.lastModified();
    if (System.currentTimeMillis() - modified < TimeUnit.DAYS.toMillis(1)) {
        return JsonMessage.getString(405, "不能删除当天的日志");
    }
    if (FileUtil.del(file)) {
        // 离线上一个日志
        ServiceFileTailWatcher.offlineFile(file);
        return JsonMessage.getString(200, "删除成功");
    }
    return JsonMessage.getString(500, "删除失败");
}
Also used : WebAopLog(io.jpom.system.WebAopLog) File(java.io.File) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class LogManageController method logDownload.

@RequestMapping(value = "log_download", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DOWNLOAD)
public void logDownload(String nodeId, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
    if (StrUtil.isNotEmpty(nodeId)) {
        NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.DownloadSystemLog);
        return;
    }
    WebAopLog webAopLog = SpringUtil.getBean(WebAopLog.class);
    File file = FileUtil.file(webAopLog.getPropertyValue(), path);
    if (file.isFile()) {
        ServletUtil.write(getResponse(), file);
    }
}
Also used : WebAopLog(io.jpom.system.WebAopLog) File(java.io.File) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with Feature

use of io.jpom.permission.Feature 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)

Example 30 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class SystemUpdateController method upgrade.

/**
 * 远程下载升级
 *
 * @return json
 * @see RemoteVersion
 */
@GetMapping(value = "remote_upgrade.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DOWNLOAD)
public String upgrade() throws IOException {
    NodeModel nodeModel = tryGetNode();
    if (nodeModel != null) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.REMOTE_UPGRADE).toString();
    }
    RemoteVersion.upgrade(ConfigBean.getInstance().getTempPath().getAbsolutePath(), objects -> backupInfoService.autoBackup());
    return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

Feature (io.jpom.permission.Feature)129 MethodFeature (io.jpom.permission.MethodFeature)129 ClassFeature (io.jpom.permission.ClassFeature)128 JSONObject (com.alibaba.fastjson.JSONObject)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 File (java.io.File)36 PostMapping (org.springframework.web.bind.annotation.PostMapping)25 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)22 NodeModel (io.jpom.model.data.NodeModel)21 GetMapping (org.springframework.web.bind.annotation.GetMapping)21 UserModel (io.jpom.model.data.UserModel)14 SystemPermission (io.jpom.permission.SystemPermission)14 BuildInfoModel (io.jpom.model.data.BuildInfoModel)12 SshModel (io.jpom.model.data.SshModel)10 Entity (cn.hutool.db.Entity)8 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)8 JSONArray (com.alibaba.fastjson.JSONArray)8 JsonMessage (cn.jiangzeyin.common.JsonMessage)7 List (java.util.List)7