mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-29 18:38:32 +08:00
fix
This commit is contained in:
parent
dbe9c00332
commit
9edaf5c90b
@ -12,6 +12,11 @@
|
||||
3. 【server】优化 项目编辑和节点分发页面支持快捷配置授权目录
|
||||
4. 【server】优化 项目编辑支持切换节点(快速同步其他节点项目)
|
||||
5. 【server】修复 没有工作空间权限时页面循环跳转(感谢[@王先生](https://gitee.com/whz_gmg1) [Gitee issues I8RR01](https://gitee.com/dromara/Jpom/issues/I8RR01))
|
||||
6. 【all】优化 授权目录判断逻辑
|
||||
|
||||
### ⚠️ 注意
|
||||
|
||||
1. 如果您配置了授权目录但是保存项目报错您可以尝试重新报错一下授权目录来自动修复授权目录配置数据
|
||||
|
||||
------
|
||||
|
||||
|
@ -67,29 +67,29 @@ public abstract class AbstractSystemCommander {
|
||||
*/
|
||||
public abstract String emptyLogFile(File file);
|
||||
|
||||
/**
|
||||
* 查询服务状态
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @return true 运行中
|
||||
*/
|
||||
public abstract boolean getServiceStatus(String serviceName);
|
||||
|
||||
/**
|
||||
* 启动服务
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @return 结果
|
||||
*/
|
||||
public abstract String startService(String serviceName);
|
||||
|
||||
/**
|
||||
* 关闭服务
|
||||
*
|
||||
* @param serviceName 服务名称
|
||||
* @return 结果
|
||||
*/
|
||||
public abstract String stopService(String serviceName);
|
||||
// /**
|
||||
// * 查询服务状态
|
||||
// *
|
||||
// * @param serviceName 服务名称
|
||||
// * @return true 运行中
|
||||
// */
|
||||
// public abstract boolean getServiceStatus(String serviceName);
|
||||
//
|
||||
// /**
|
||||
// * 启动服务
|
||||
// *
|
||||
// * @param serviceName 服务名称
|
||||
// * @return 结果
|
||||
// */
|
||||
// public abstract String startService(String serviceName);
|
||||
//
|
||||
// /**
|
||||
// * 关闭服务
|
||||
// *
|
||||
// * @param serviceName 服务名称
|
||||
// * @return 结果
|
||||
// */
|
||||
// public abstract String stopService(String serviceName);
|
||||
|
||||
/**
|
||||
* 构建kill 命令
|
||||
|
@ -22,16 +22,12 @@
|
||||
*/
|
||||
package org.dromara.jpom.common.commander.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.jpom.common.commander.AbstractSystemCommander;
|
||||
import org.dromara.jpom.util.CommandUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author bwcx_jzy
|
||||
@ -47,55 +43,55 @@ public class LinuxSystemCommander extends AbstractSystemCommander {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getServiceStatus(String serviceName) {
|
||||
if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
String ps = getPs(serviceName);
|
||||
return StrUtil.isNotEmpty(ps);
|
||||
}
|
||||
String format = StrUtil.format("service {} status", serviceName);
|
||||
String result = CommandUtil.execSystemCommand(format);
|
||||
return StrUtil.containsIgnoreCase(result, "RUNNING");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String startService(String serviceName) {
|
||||
if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
try {
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(SystemUtil.getUserInfo().getHomeDir()), serviceName);
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
log.error("执行异常", e);
|
||||
return "执行异常:" + e.getMessage();
|
||||
}
|
||||
}
|
||||
String format = StrUtil.format("service {} start", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stopService(String serviceName) {
|
||||
if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
String ps = getPs(serviceName);
|
||||
List<String> list = StrUtil.splitTrim(ps, StrUtil.LF);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return "stop";
|
||||
}
|
||||
String s = list.get(0);
|
||||
list = StrUtil.splitTrim(s, StrUtil.SPACE);
|
||||
if (list == null || list.size() < 2) {
|
||||
return "stop";
|
||||
}
|
||||
File file = new File(SystemUtil.getUserInfo().getHomeDir());
|
||||
int pid = Convert.toInt(list.get(1), 0);
|
||||
if (pid <= 0) {
|
||||
return "error stop";
|
||||
}
|
||||
return kill(file, pid);
|
||||
}
|
||||
String format = StrUtil.format("service {} stop", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
// @Override
|
||||
// public boolean getServiceStatus(String serviceName) {
|
||||
// if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
// String ps = getPs(serviceName);
|
||||
// return StrUtil.isNotEmpty(ps);
|
||||
// }
|
||||
// String format = StrUtil.format("service {} status", serviceName);
|
||||
// String result = CommandUtil.execSystemCommand(format);
|
||||
// return StrUtil.containsIgnoreCase(result, "RUNNING");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String startService(String serviceName) {
|
||||
// if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
// try {
|
||||
// CommandUtil.asyncExeLocalCommand(FileUtil.file(SystemUtil.getUserInfo().getHomeDir()), serviceName);
|
||||
// return "ok";
|
||||
// } catch (Exception e) {
|
||||
// log.error("执行异常", e);
|
||||
// return "执行异常:" + e.getMessage();
|
||||
// }
|
||||
// }
|
||||
// String format = StrUtil.format("service {} start", serviceName);
|
||||
// return CommandUtil.execSystemCommand(format);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String stopService(String serviceName) {
|
||||
// if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
// String ps = getPs(serviceName);
|
||||
// List<String> list = StrUtil.splitTrim(ps, StrUtil.LF);
|
||||
// if (list == null || list.isEmpty()) {
|
||||
// return "stop";
|
||||
// }
|
||||
// String s = list.get(0);
|
||||
// list = StrUtil.splitTrim(s, StrUtil.SPACE);
|
||||
// if (list == null || list.size() < 2) {
|
||||
// return "stop";
|
||||
// }
|
||||
// File file = new File(SystemUtil.getUserInfo().getHomeDir());
|
||||
// int pid = Convert.toInt(list.get(1), 0);
|
||||
// if (pid <= 0) {
|
||||
// return "error stop";
|
||||
// }
|
||||
// return kill(file, pid);
|
||||
// }
|
||||
// String format = StrUtil.format("service {} stop", serviceName);
|
||||
// return CommandUtil.execSystemCommand(format);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String buildKill(int pid) {
|
||||
|
@ -22,16 +22,11 @@
|
||||
*/
|
||||
package org.dromara.jpom.common.commander.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.jpom.common.commander.AbstractSystemCommander;
|
||||
import org.dromara.jpom.util.CommandUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author User
|
||||
@ -46,72 +41,72 @@ public class MacOsSystemCommander extends AbstractSystemCommander {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getServiceStatus(String serviceName) {
|
||||
if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
String ps = getPs(serviceName);
|
||||
return StrUtil.isNotEmpty(ps);
|
||||
}
|
||||
/**
|
||||
* Mac OS 里面查询服务的命令是 launchctl list | grep serverName
|
||||
* 第一个数字是进程的 PID,如果进程正在运行,如果它不在运行,则显示 "-"
|
||||
* 第二个数字是进程的退出代码(如果已完成)。如果为负,则为终止信号的数量
|
||||
* 第三列进程名称
|
||||
*/
|
||||
String format = StrUtil.format("service {} status", serviceName);
|
||||
String result = CommandUtil.execSystemCommand(format);
|
||||
return StrUtil.containsIgnoreCase(result, "RUNNING");
|
||||
}
|
||||
|
||||
private String getPs(final String serviceName) {
|
||||
String ps = StrUtil.format(" ps -ef |grep -w {} | grep -v grep", serviceName);
|
||||
return CommandUtil.execSystemCommand(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String startService(String serviceName) {
|
||||
if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
try {
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(SystemUtil.getUserInfo().getHomeDir()), serviceName);
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
log.error("执行异常", e);
|
||||
return "执行异常:" + e.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Mac OS 里面启动服务命令是 launchctl start serverName
|
||||
*/
|
||||
String format = StrUtil.format("service {} start", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stopService(String serviceName) {
|
||||
if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
String ps = getPs(serviceName);
|
||||
List<String> list = StrUtil.splitTrim(ps, StrUtil.LF);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return "stop";
|
||||
}
|
||||
String s = list.get(0);
|
||||
list = StrUtil.splitTrim(s, StrUtil.SPACE);
|
||||
if (list == null || list.size() < 2) {
|
||||
return "stop";
|
||||
}
|
||||
File file = new File(SystemUtil.getUserInfo().getHomeDir());
|
||||
int pid = Convert.toInt(list.get(1), 0);
|
||||
if (pid <= 0) {
|
||||
return "error stop";
|
||||
}
|
||||
return kill(file, pid);
|
||||
}
|
||||
/**
|
||||
* Mac OS 里面启动服务命令是 launchctl stop serverName
|
||||
*/
|
||||
String format = StrUtil.format("service {} stop", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
// @Override
|
||||
// public boolean getServiceStatus(String serviceName) {
|
||||
// if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
// String ps = getPs(serviceName);
|
||||
// return StrUtil.isNotEmpty(ps);
|
||||
// }
|
||||
// /**
|
||||
// * Mac OS 里面查询服务的命令是 launchctl list | grep serverName
|
||||
// * 第一个数字是进程的 PID,如果进程正在运行,如果它不在运行,则显示 "-"
|
||||
// * 第二个数字是进程的退出代码(如果已完成)。如果为负,则为终止信号的数量
|
||||
// * 第三列进程名称
|
||||
// */
|
||||
// String format = StrUtil.format("service {} status", serviceName);
|
||||
// String result = CommandUtil.execSystemCommand(format);
|
||||
// return StrUtil.containsIgnoreCase(result, "RUNNING");
|
||||
// }
|
||||
//
|
||||
// private String getPs(final String serviceName) {
|
||||
// String ps = StrUtil.format(" ps -ef |grep -w {} | grep -v grep", serviceName);
|
||||
// return CommandUtil.execSystemCommand(ps);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String startService(String serviceName) {
|
||||
// if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
// try {
|
||||
// CommandUtil.asyncExeLocalCommand(FileUtil.file(SystemUtil.getUserInfo().getHomeDir()), serviceName);
|
||||
// return "ok";
|
||||
// } catch (Exception e) {
|
||||
// log.error("执行异常", e);
|
||||
// return "执行异常:" + e.getMessage();
|
||||
// }
|
||||
// }
|
||||
// /**
|
||||
// * Mac OS 里面启动服务命令是 launchctl start serverName
|
||||
// */
|
||||
// String format = StrUtil.format("service {} start", serviceName);
|
||||
// return CommandUtil.execSystemCommand(format);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String stopService(String serviceName) {
|
||||
// if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
|
||||
// String ps = getPs(serviceName);
|
||||
// List<String> list = StrUtil.splitTrim(ps, StrUtil.LF);
|
||||
// if (list == null || list.isEmpty()) {
|
||||
// return "stop";
|
||||
// }
|
||||
// String s = list.get(0);
|
||||
// list = StrUtil.splitTrim(s, StrUtil.SPACE);
|
||||
// if (list == null || list.size() < 2) {
|
||||
// return "stop";
|
||||
// }
|
||||
// File file = new File(SystemUtil.getUserInfo().getHomeDir());
|
||||
// int pid = Convert.toInt(list.get(1), 0);
|
||||
// if (pid <= 0) {
|
||||
// return "error stop";
|
||||
// }
|
||||
// return kill(file, pid);
|
||||
// }
|
||||
// /**
|
||||
// * Mac OS 里面启动服务命令是 launchctl stop serverName
|
||||
// */
|
||||
// String format = StrUtil.format("service {} stop", serviceName);
|
||||
// return CommandUtil.execSystemCommand(format);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String buildKill(int pid) {
|
||||
|
@ -42,23 +42,23 @@ public class WindowsSystemCommander extends AbstractSystemCommander {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getServiceStatus(String serviceName) {
|
||||
String result = CommandUtil.execSystemCommand("sc query " + serviceName);
|
||||
return StrUtil.containsIgnoreCase(result, "RUNNING");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String startService(String serviceName) {
|
||||
String format = StrUtil.format("net start {}", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stopService(String serviceName) {
|
||||
String format = StrUtil.format("net stop {}", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
// @Override
|
||||
// public boolean getServiceStatus(String serviceName) {
|
||||
// String result = CommandUtil.execSystemCommand("sc query " + serviceName);
|
||||
// return StrUtil.containsIgnoreCase(result, "RUNNING");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String startService(String serviceName) {
|
||||
// String format = StrUtil.format("net start {}", serviceName);
|
||||
// return CommandUtil.execSystemCommand(format);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String stopService(String serviceName) {
|
||||
// String format = StrUtil.format("net stop {}", serviceName);
|
||||
// return CommandUtil.execSystemCommand(format);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String buildKill(int pid) {
|
||||
|
@ -144,14 +144,8 @@ public class NodeProjectInfoModel extends BaseWorkspaceModel {
|
||||
return whitelistDirectory;
|
||||
}
|
||||
|
||||
public void setWhitelistDirectory(String whitelistDirectory) {
|
||||
this.whitelistDirectory = whitelistDirectory;
|
||||
}
|
||||
|
||||
|
||||
public String allLib() {
|
||||
String directory = this.getWhitelistDirectory();
|
||||
directory = AgentWhitelist.convertRealPath(directory);
|
||||
return FileUtil.file(directory, this.getLib()).getAbsolutePath();
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,12 @@ public class ProjectFileBackupUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析项目的备份路径
|
||||
*
|
||||
* @param dslYmlDto dsl 配置
|
||||
* @return path
|
||||
*/
|
||||
public static String resolveBackupPath(DslYmlDto dslYmlDto) {
|
||||
return Optional.ofNullable(dslYmlDto)
|
||||
.map(DslYmlDto::getFile)
|
||||
|
@ -85,7 +85,7 @@ public class WhitelistDirectoryService extends BaseDataService {
|
||||
|
||||
public boolean checkProjectDirectory(String path) {
|
||||
AgentWhitelist agentWhitelist = getWhitelist();
|
||||
List<String> list = agentWhitelist.project();
|
||||
List<String> list = agentWhitelist.getProject();
|
||||
return AgentWhitelist.checkPath(list, path);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,6 @@
|
||||
<artifactId>hutool-cron</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- aop-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -63,23 +63,6 @@ public class AgentWhitelist extends BaseJsonModel {
|
||||
*/
|
||||
private List<String> allowEditSuffix;
|
||||
|
||||
public static String convertRealPath(String path) {
|
||||
String val = String.format("/%s/", path);
|
||||
return FileUtil.normalize(val);
|
||||
}
|
||||
|
||||
public static List<String> useConvert(List<String> list) {
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
return list.stream().map(AgentWhitelist::convertRealPath).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
public List<String> project() {
|
||||
return useConvert(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化,判断是否与jpom 数据路径冲突
|
||||
*
|
||||
@ -143,7 +126,7 @@ public class AgentWhitelist extends BaseJsonModel {
|
||||
if (StrUtil.isEmpty(path)) {
|
||||
return false;
|
||||
}
|
||||
File file1, file2 = FileUtil.file(convertRealPath(path));
|
||||
File file1, file2 = FileUtil.file(path);
|
||||
for (String item : list) {
|
||||
file1 = FileUtil.file(item);
|
||||
if (FileUtil.pathEquals(file1, file2)) {
|
||||
|
@ -300,7 +300,7 @@ public class OutGivingProjectEditController extends BaseServerController {
|
||||
}
|
||||
String whitelistDirectory = getParameter("whitelistDirectory");
|
||||
ServerWhitelist configDeNewInstance = outGivingWhitelistService.getServerWhitelistData(getRequest());
|
||||
List<String> whitelistServerOutGiving = configDeNewInstance.outGiving();
|
||||
List<String> whitelistServerOutGiving = configDeNewInstance.getOutGiving();
|
||||
Assert.state(AgentWhitelist.checkPath(whitelistServerOutGiving, whitelistDirectory), "请选择正确的项目路径,或者还没有配置授权");
|
||||
|
||||
defData.put("whitelistDirectory", whitelistDirectory);
|
||||
|
@ -355,7 +355,7 @@ public class CertificateInfoController extends BaseServerController {
|
||||
HttpServletRequest request) {
|
||||
// 判断参数
|
||||
ServerWhitelist configDeNewInstance = outGivingWhitelistService.getServerWhitelistData(request);
|
||||
List<String> whitelistServerOutGiving = configDeNewInstance.outGiving();
|
||||
List<String> whitelistServerOutGiving = configDeNewInstance.getOutGiving();
|
||||
Assert.state(AgentWhitelist.checkPath(whitelistServerOutGiving, releasePathParent), "请选择正确的项目路径,或者还没有配置授权");
|
||||
Assert.hasText(releasePathSecondary, "请填写发布文件的二级目录");
|
||||
// 判断证书是否存在
|
||||
|
@ -89,7 +89,7 @@ public class FileReleaseTaskController extends BaseServerController {
|
||||
HttpServletRequest request) {
|
||||
// 判断参数
|
||||
ServerWhitelist configDeNewInstance = outGivingWhitelistService.getServerWhitelistData(request);
|
||||
List<String> whitelistServerOutGiving = configDeNewInstance.outGiving();
|
||||
List<String> whitelistServerOutGiving = configDeNewInstance.getOutGiving();
|
||||
Assert.state(AgentWhitelist.checkPath(whitelistServerOutGiving, releasePathParent), "请选择正确的项目路径,或者还没有配置授权");
|
||||
Assert.hasText(releasePathSecondary, "请填写发布文件的二级目录");
|
||||
|
||||
|
@ -101,10 +101,6 @@ public class ServerWhitelist extends BaseJsonModel {
|
||||
Assert.state(contains, "没有当前静态目录权限");
|
||||
}
|
||||
|
||||
public List<String> outGiving() {
|
||||
return AgentWhitelist.useConvert(outGiving);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定 url 是否在授权范围
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user