From a81253d62e37d99cc23d97aec563ae0c2eac3bfe Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 09:04:32 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/adminPage/bak/index.html | 4 ++-- src/main/resources/templates/adminPage/menu.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index cb92dac6..f4176a6d 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -8,9 +8,9 @@
-
+ diff --git a/src/main/resources/templates/adminPage/menu.html b/src/main/resources/templates/adminPage/menu.html index a1a7db8a..a3a2ff7f 100644 --- a/src/main/resources/templates/adminPage/menu.html +++ b/src/main/resources/templates/adminPage/menu.html @@ -38,9 +38,9 @@
${menuStr.template}
-
+
${menuStr.password}
-- Gitee From 8b0dba416f92241eaa5c3f3be8f832b544986c22 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 09:29:45 +0800 Subject: [PATCH 02/24] 1 --- .../controller/adminPage/ConfController.java | 6 +- src/main/java/com/cym/model/Bak.java | 44 +++++++- .../java/com/cym/service/ConfService.java | 21 +++- .../static/js/adminPage/conf/index.js | 32 +++++- .../templates/adminPage/bak/index.html | 11 ++ .../templates/adminPage/conf/index.html | 101 +++++++++++------- .../resources/templates/adminPage/menu.html | 4 +- 7 files changed, 174 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/ConfController.java b/src/main/java/com/cym/controller/adminPage/ConfController.java index b30cad6a..cdb91bb0 100644 --- a/src/main/java/com/cym/controller/adminPage/ConfController.java +++ b/src/main/java/com/cym/controller/adminPage/ConfController.java @@ -132,7 +132,11 @@ public class ConfController extends BaseController { adminName = admin.getName(); } - confService.replace(nginxPath, nginxContent, subContent, subName, true, adminName); + String version = jsonObject.getStr("version"); + String applyNumber = jsonObject.getStr("applyNumber"); + String changeContent = jsonObject.getStr("changeContent"); + + confService.replaceApply(nginxContent, subContent, subName, adminName, version, applyNumber, changeContent); return renderSuccess(m.get("confStr.replaceSuccess")); } catch (Exception e) { logger.error(e.getMessage(), e); diff --git a/src/main/java/com/cym/model/Bak.java b/src/main/java/com/cym/model/Bak.java index 2c352d79..3779c3f4 100644 --- a/src/main/java/com/cym/model/Bak.java +++ b/src/main/java/com/cym/model/Bak.java @@ -1,18 +1,60 @@ package com.cym.model; import cn.craccd.sqlHelper.bean.BaseModel; +import cn.craccd.sqlHelper.config.InitValue; import cn.craccd.sqlHelper.config.Table; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @ApiModel("备份文件") @Table -public class Bak extends BaseModel{ +public class Bak extends BaseModel { @ApiModelProperty("时间") String time; @ApiModelProperty("主文件内容") String content; + @ApiModelProperty("版本号") + String version; + @ApiModelProperty("审批编号") + String applyNumber; + @ApiModelProperty("变更内容") + String changeContent; + @InitValue("0") + @ApiModelProperty("状态 0未审批 1已通过 2未通过") + Integer status; + + public String getChangeContent() { + return changeContent; + } + + public void setChangeContent(String changeContent) { + this.changeContent = changeContent; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getApplyNumber() { + return applyNumber; + } + + public void setApplyNumber(String applyNumber) { + this.applyNumber = applyNumber; + } public String getContent() { return content; diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 0057773b..925ee4f7 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -639,9 +639,28 @@ public class ConfService { return ToolUtils.handleConf(new NgxDumper(ngxConfig).dump()); } + public void replaceApply(String nginxContent, List subContent, List subName, String adminName, String version, String applyNumber, String changeContent) { + Bak bak = new Bak(); + bak.setTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); + bak.setContent(nginxContent); + bak.setVersion(version); + bak.setApplyNumber(applyNumber); + bak.setChangeContent(changeContent); + sqlHelper.insert(bak); + + // 子文件 + for (int i = 0; i < subContent.size(); i++) { + BakSub bakSub = new BakSub(); + bakSub.setBakId(bak.getId()); + bakSub.setName(subName.get(i)); + bakSub.setContent(subContent.get(i)); + sqlHelper.insert(bakSub); + } + } + @Transactional public void replace(String nginxPath, String nginxContent, List subContent, List subName, Boolean isReplace, String adminName) { - + String beforeConf = null; if (isReplace) { // 先读取已有的配置 diff --git a/src/main/resources/static/js/adminPage/conf/index.js b/src/main/resources/static/js/adminPage/conf/index.js index 8cce66f9..118d3076 100644 --- a/src/main/resources/static/js/adminPage/conf/index.js +++ b/src/main/resources/static/js/adminPage/conf/index.js @@ -60,13 +60,43 @@ function buildJson(){ return json; } -function replace() { +function replaceApply() { + $("#version").val(""); + $("#applyNumber").val(""); + $("#changeContent").val(""); + + layer.open({ + type : 1, + title : title, + area : [ '450px', '600px' ], // 宽高 + content : $('#applyForm') + }); +} + + +function replaceOver() { if ($("#nginxPath").val() == '') { layer.msg(confStr.jserror2); return; } + + if ($("#applyNumber").val() == '') { + layer.msg("未填写审批编号"); + return; + } + if ($("#version").val() == '') { + layer.msg("未填写版本号"); + return; + } + if ($("#changeContent").val() == '') { + layer.msg("未填写变更内容"); + return; + } var json = buildJson(); + json.version = $("#version").val(); + json.applyNumber = $("#applyNumber").val(); + json.changeContent = $("#changeContent").val(); $.ajax({ type : 'POST', diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index f4176a6d..b7b694b5 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -20,6 +20,9 @@ ${commonStr.createTime} + 版本号 + 审批编号 + 状态 ${commonStr.operation} @@ -27,6 +30,14 @@ <#list page.records as bak> ${bak.time} + ${bak.version} + ${bak.applyNumber} + + + <#if bak.status == 0>未审批 + <#if bak.status == 1>已审批 + <#if bak.status == 2>未审批 + diff --git a/src/main/resources/templates/adminPage/conf/index.html b/src/main/resources/templates/adminPage/conf/index.html index ea578ed1..99bff8c3 100644 --- a/src/main/resources/templates/adminPage/conf/index.html +++ b/src/main/resources/templates/adminPage/conf/index.html @@ -13,8 +13,8 @@ .title { margin-top: 5px; margin-bottom: 5px; - height:30px; - line-height:30px; + height: 30px; + line-height: 30px; cursor: pointer; } @@ -22,20 +22,17 @@ table.diff { width: 100%; } - -.long{ - width: 150px!important; +.long { + width: 150px !important; } - -.layui-form-radio{ +.layui-form-radio { width: 700px; } -input[type='radio']{ +input[type='radio'] { width: 1000px; } - @@ -78,20 +75,20 @@ input[type='radio']{
- +
- +
- +
- +
@@ -118,18 +115,18 @@ input[type='radio']{
-
- +
+
- +
- +
@@ -137,8 +134,8 @@ input[type='radio']{
- - + +
@@ -151,25 +148,22 @@ input[type='radio']{
- -
+ + + - <#include '/adminPage/script.html'/> - <#include '/adminPage/select_root.html'/> - - - - - + <#include '/adminPage/script.html'/> + <#include '/adminPage/select_root.html'/> + + + + + diff --git a/src/main/resources/templates/adminPage/menu.html b/src/main/resources/templates/adminPage/menu.html index a3a2ff7f..92414806 100644 --- a/src/main/resources/templates/adminPage/menu.html +++ b/src/main/resources/templates/adminPage/menu.html @@ -51,9 +51,9 @@
${menuStr.log}
-
+
${menuStr.export}
-- Gitee From e5289b9b10fb930f338232d35de63f7f1ef29e94 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 09:38:52 +0800 Subject: [PATCH 03/24] 1 --- .../com/cym/controller/adminPage/ConfController.java | 2 +- src/main/resources/static/js/adminPage/conf/index.js | 9 ++++----- src/main/resources/templates/adminPage/conf/index.html | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/ConfController.java b/src/main/java/com/cym/controller/adminPage/ConfController.java index cdb91bb0..9f552797 100644 --- a/src/main/java/com/cym/controller/adminPage/ConfController.java +++ b/src/main/java/com/cym/controller/adminPage/ConfController.java @@ -137,7 +137,7 @@ public class ConfController extends BaseController { String changeContent = jsonObject.getStr("changeContent"); confService.replaceApply(nginxContent, subContent, subName, adminName, version, applyNumber, changeContent); - return renderSuccess(m.get("confStr.replaceSuccess")); + return renderSuccess(); } catch (Exception e) { logger.error(e.getMessage(), e); return renderError(m.get("confStr.error3") + ":" + e.getMessage()); diff --git a/src/main/resources/static/js/adminPage/conf/index.js b/src/main/resources/static/js/adminPage/conf/index.js index 118d3076..4e54b5ce 100644 --- a/src/main/resources/static/js/adminPage/conf/index.js +++ b/src/main/resources/static/js/adminPage/conf/index.js @@ -67,8 +67,8 @@ function replaceApply() { layer.open({ type : 1, - title : title, - area : [ '450px', '600px' ], // 宽高 + title : confStr.replaceFile, + area : [ '600px', '450px' ], // 宽高 content : $('#applyForm') }); } @@ -107,9 +107,8 @@ function replaceOver() { dataType : 'json', success : function(data) { if (data.success) { - layer.msg(data.obj); - loadOrg(); - + layer.closeAll(); + layer.msg("审批已提交,请等待审核"); } else { layer.alert(data.msg); } diff --git a/src/main/resources/templates/adminPage/conf/index.html b/src/main/resources/templates/adminPage/conf/index.html index 99bff8c3..a12d31ba 100644 --- a/src/main/resources/templates/adminPage/conf/index.html +++ b/src/main/resources/templates/adminPage/conf/index.html @@ -81,7 +81,7 @@ input[type='radio'] {
- +
-- Gitee From 933c58a8651348a3b6f238045de31b49a033e02f Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 09:51:27 +0800 Subject: [PATCH 04/24] 1 --- src/main/resources/static/js/adminPage/conf/index.js | 2 +- src/main/resources/templates/adminPage/bak/index.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/js/adminPage/conf/index.js b/src/main/resources/static/js/adminPage/conf/index.js index 4e54b5ce..89e33a3a 100644 --- a/src/main/resources/static/js/adminPage/conf/index.js +++ b/src/main/resources/static/js/adminPage/conf/index.js @@ -486,7 +486,7 @@ function showBak(){ layer.open({ type: 2, title: bakStr.bakFile, - area : [ '900px', '90%' ], + area : [ '80%', '90%' ], content: ctx + "/adminPage/bak" }); } \ No newline at end of file diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index b7b694b5..9e9160cc 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -22,6 +22,7 @@ ${commonStr.createTime} 版本号 审批编号 + 变更内容 状态 ${commonStr.operation} @@ -32,7 +33,7 @@ ${bak.time} ${bak.version} ${bak.applyNumber} - + ${bak.changeContent} <#if bak.status == 0>未审批 <#if bak.status == 1>已审批 -- Gitee From 0197d9dae7bde51d68b3dd37bd9139f51fddb71a Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 10:26:06 +0800 Subject: [PATCH 05/24] 1 --- .../controller/adminPage/ConfController.java | 10 ++++ .../controller/api/NginxApiController.java | 60 +++++++++---------- src/main/java/com/cym/model/Bak.java | 1 + src/main/java/com/cym/service/BakService.java | 8 +++ .../java/com/cym/service/ConfService.java | 18 ++++++ 5 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/ConfController.java b/src/main/java/com/cym/controller/adminPage/ConfController.java index 9f552797..c01428d3 100644 --- a/src/main/java/com/cym/controller/adminPage/ConfController.java +++ b/src/main/java/com/cym/controller/adminPage/ConfController.java @@ -21,6 +21,7 @@ import com.cym.config.VersionConfig; import com.cym.ext.ConfExt; import com.cym.ext.ConfFile; import com.cym.model.Admin; +import com.cym.service.BakService; import com.cym.service.ConfService; import com.cym.service.ServerService; import com.cym.service.SettingService; @@ -56,6 +57,8 @@ public class ConfController extends BaseController { ConfService confService; @Autowired MainController mainController; + @Autowired + BakService bakService; @Autowired VersionConfig versionConfig; @@ -136,6 +139,13 @@ public class ConfController extends BaseController { String applyNumber = jsonObject.getStr("applyNumber"); String changeContent = jsonObject.getStr("changeContent"); + if(bakService.hasApplyNumber(applyNumber)) { + return renderError("该审批编号已存在"); + } + if(bakService.hasVersion(version)) { + return renderError("该版本号已存在"); + } + confService.replaceApply(nginxContent, subContent, subName, adminName, version, applyNumber, changeContent); return renderSuccess(); } catch (Exception e) { diff --git a/src/main/java/com/cym/controller/api/NginxApiController.java b/src/main/java/com/cym/controller/api/NginxApiController.java index 19078771..8dabc14d 100644 --- a/src/main/java/com/cym/controller/api/NginxApiController.java +++ b/src/main/java/com/cym/controller/api/NginxApiController.java @@ -13,7 +13,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.cym.controller.adminPage.ConfController; +import com.cym.model.Admin; import com.cym.service.AdminService; +import com.cym.service.ConfService; import com.cym.service.SettingService; import com.cym.utils.BaseController; import com.cym.utils.JsonResult; @@ -35,6 +37,8 @@ public class NginxApiController extends BaseController { AdminService adminService; @Autowired SettingService settingService; + @Autowired + ConfService confService; @ApiOperation("获取nginx状态") @PostMapping("nginxStatus") @@ -46,17 +50,30 @@ public class NginxApiController extends BaseController { } } - @ApiOperation("替换conf文件") - @PostMapping("replace") - public JsonResult replace(@RequestHeader String token, HttpServletRequest request) { - JsonResult jsonResult = confController.replace(confController.getReplaceJson(), request, null); - if (jsonResult.isSuccess()) { - return renderSuccess("替换成功"); - } else { - return renderError("替换失败"); - } + @ApiOperation("下发审批结果") + @PostMapping("applyResult") + public JsonResult applyResult(@RequestHeader String token, HttpServletRequest request,// + @RequestParam @ApiParam("审批编号") String applyNumber, // + @RequestParam @ApiParam("审批结果 1已通过 2未通过") Integer status) { + Admin admin = getAdmin(request); + confService.replaceApplyOver(applyNumber, status,admin.getName()); + + return renderSuccess("下发成功"); } - + + +// @ApiOperation("替换conf文件") +// @PostMapping("replace") +// public JsonResult replace(@RequestHeader String token, HttpServletRequest request) { +// JsonResult jsonResult = confController.replace(confController.getReplaceJson(), request, null); +// if (jsonResult.isSuccess()) { +// return renderSuccess("替换成功"); +// } else { +// return renderError("替换失败"); +// } +// } + + @ApiOperation("效验conf文件") @PostMapping("check") public JsonResult checkBase() { @@ -127,27 +144,4 @@ public class NginxApiController extends BaseController { return jsonResult; } -// @ApiOperation("停止nginx") -// @PostMapping("stop") -// public synchronized JsonResult stop() { -// JsonResult jsonResult = confController.stop(null, null); -// -// if (jsonResult.isSuccess()) { -// return renderSuccess("停止成功"); -// } else { -// return renderError("停止失败"); -// } -// } -// -// @ApiOperation("启动nginx") -// @PostMapping("start") -// public synchronized JsonResult start() { -// JsonResult jsonResult = confController.start(null, null, null); -// -// if (jsonResult.isSuccess()) { -// return renderSuccess("启动成功"); -// } else { -// return renderError("启动失败"); -// } -// } } diff --git a/src/main/java/com/cym/model/Bak.java b/src/main/java/com/cym/model/Bak.java index 3779c3f4..80091cec 100644 --- a/src/main/java/com/cym/model/Bak.java +++ b/src/main/java/com/cym/model/Bak.java @@ -15,6 +15,7 @@ public class Bak extends BaseModel { String content; @ApiModelProperty("版本号") String version; + @ApiModelProperty("审批编号") String applyNumber; @ApiModelProperty("变更内容") diff --git a/src/main/java/com/cym/service/BakService.java b/src/main/java/com/cym/service/BakService.java index 19c7c5eb..e5b870e5 100644 --- a/src/main/java/com/cym/service/BakService.java +++ b/src/main/java/com/cym/service/BakService.java @@ -44,4 +44,12 @@ public class BakService { return pre; } + public boolean hasApplyNumber(String applyNumber) { + return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getApplyNumber, applyNumber), Bak.class) > 0; + } + + public boolean hasVersion(String version) { + return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getVersion, version), Bak.class) > 0; + } + } diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 925ee4f7..1e2771dc 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -65,6 +65,8 @@ public class ConfService { TemplateService templateService; @Autowired OperateLogService operateLogService; + @Autowired + BakService bakService; public synchronized ConfExt buildConf(Boolean decompose, Boolean check) { ConfExt confExt = new ConfExt(); @@ -658,6 +660,22 @@ public class ConfService { } } + public void replaceApplyOver(String applyNumber, Integer status, String adminName) { + Bak bak = sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Bak::getApplyNumber, applyNumber), Bak.class); + if (bak != null) { + List subList = bakService.getSubList(bak.getId()); + List subName = new ArrayList<>(); + List subContent = new ArrayList<>(); + for (BakSub bakSub : subList) { + subName.add(bakSub.getName()); + subContent.add(bakSub.getContent()); + } + + String nginxPath = settingService.get("nginxPath"); + replace(nginxPath, bak.getContent(), subContent, subName, true, adminName); + } + } + @Transactional public void replace(String nginxPath, String nginxContent, List subContent, List subName, Boolean isReplace, String adminName) { -- Gitee From 988257f64f92b87ac3cf4058b1a6de81a25515d3 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 15:11:22 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminPage/ConfController.java | 15 +++++++++------ .../controller/api/NginxApiController.java | 19 ++++++++++++------- src/main/java/com/cym/model/Bak.java | 2 +- src/main/java/com/cym/service/BakService.java | 4 ++++ .../java/com/cym/service/ConfService.java | 8 +++++--- .../static/js/adminPage/conf/index.js | 5 ----- .../templates/adminPage/bak/index.html | 2 +- .../templates/adminPage/conf/index.html | 12 ++++-------- 8 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/ConfController.java b/src/main/java/com/cym/controller/adminPage/ConfController.java index c01428d3..13dda9bb 100644 --- a/src/main/java/com/cym/controller/adminPage/ConfController.java +++ b/src/main/java/com/cym/controller/adminPage/ConfController.java @@ -81,6 +81,9 @@ public class ConfController extends BaseController { String decompose = settingService.get("decompose"); modelAndView.addObject("decompose", decompose); + Boolean applying = bakService.isApplying(); + modelAndView.addObject("applying", applying); + modelAndView.addObject("tmp", InitConfig.home + "temp/nginx.conf"); modelAndView.setViewName("/adminPage/conf/index"); @@ -101,7 +104,11 @@ public class ConfController extends BaseController { @RequestMapping(value = "replace") @ResponseBody public JsonResult replace(String json, HttpServletRequest request, String adminName) { - + + if(bakService.isApplying()) { + return renderError("已有变更正在审批中,请稍后再试"); + } + if (StrUtil.isEmpty(json)) { json = getReplaceJson(); } @@ -136,17 +143,13 @@ public class ConfController extends BaseController { } String version = jsonObject.getStr("version"); - String applyNumber = jsonObject.getStr("applyNumber"); String changeContent = jsonObject.getStr("changeContent"); - if(bakService.hasApplyNumber(applyNumber)) { - return renderError("该审批编号已存在"); - } if(bakService.hasVersion(version)) { return renderError("该版本号已存在"); } - confService.replaceApply(nginxContent, subContent, subName, adminName, version, applyNumber, changeContent); + confService.replaceApply(nginxContent, subContent, subName, adminName, version, changeContent); return renderSuccess(); } catch (Exception e) { logger.error(e.getMessage(), e); diff --git a/src/main/java/com/cym/controller/api/NginxApiController.java b/src/main/java/com/cym/controller/api/NginxApiController.java index 8dabc14d..7be3965d 100644 --- a/src/main/java/com/cym/controller/api/NginxApiController.java +++ b/src/main/java/com/cym/controller/api/NginxApiController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController; import com.cym.controller.adminPage.ConfController; import com.cym.model.Admin; import com.cym.service.AdminService; +import com.cym.service.BakService; import com.cym.service.ConfService; import com.cym.service.SettingService; import com.cym.utils.BaseController; @@ -39,6 +40,8 @@ public class NginxApiController extends BaseController { SettingService settingService; @Autowired ConfService confService; + @Autowired + BakService bakService; @ApiOperation("获取nginx状态") @PostMapping("nginxStatus") @@ -52,16 +55,19 @@ public class NginxApiController extends BaseController { @ApiOperation("下发审批结果") @PostMapping("applyResult") - public JsonResult applyResult(@RequestHeader String token, HttpServletRequest request,// + public JsonResult applyResult(@RequestHeader String token, HttpServletRequest request, // @RequestParam @ApiParam("审批编号") String applyNumber, // @RequestParam @ApiParam("审批结果 1已通过 2未通过") Integer status) { + if (!bakService.isApplying()) { + return renderError("当前没有申请中的更改"); + } + Admin admin = getAdmin(request); - confService.replaceApplyOver(applyNumber, status,admin.getName()); - + confService.replaceApplyOver(applyNumber, status, admin.getName()); + return renderSuccess("下发成功"); } - - + // @ApiOperation("替换conf文件") // @PostMapping("replace") // public JsonResult replace(@RequestHeader String token, HttpServletRequest request) { @@ -72,8 +78,7 @@ public class NginxApiController extends BaseController { // return renderError("替换失败"); // } // } - - + @ApiOperation("效验conf文件") @PostMapping("check") public JsonResult checkBase() { diff --git a/src/main/java/com/cym/model/Bak.java b/src/main/java/com/cym/model/Bak.java index 80091cec..6634450d 100644 --- a/src/main/java/com/cym/model/Bak.java +++ b/src/main/java/com/cym/model/Bak.java @@ -21,7 +21,7 @@ public class Bak extends BaseModel { @ApiModelProperty("变更内容") String changeContent; @InitValue("0") - @ApiModelProperty("状态 0未审批 1已通过 2未通过") + @ApiModelProperty("状态 0审批中 1已通过 2未通过") Integer status; diff --git a/src/main/java/com/cym/service/BakService.java b/src/main/java/com/cym/service/BakService.java index e5b870e5..6d657550 100644 --- a/src/main/java/com/cym/service/BakService.java +++ b/src/main/java/com/cym/service/BakService.java @@ -52,4 +52,8 @@ public class BakService { return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getVersion, version), Bak.class) > 0; } + public Boolean isApplying() { + return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class) > 0; + } + } diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 1e2771dc..8f07d548 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -641,12 +641,11 @@ public class ConfService { return ToolUtils.handleConf(new NgxDumper(ngxConfig).dump()); } - public void replaceApply(String nginxContent, List subContent, List subName, String adminName, String version, String applyNumber, String changeContent) { + public void replaceApply(String nginxContent, List subContent, List subName, String adminName, String version, String changeContent) { Bak bak = new Bak(); bak.setTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); bak.setContent(nginxContent); bak.setVersion(version); - bak.setApplyNumber(applyNumber); bak.setChangeContent(changeContent); sqlHelper.insert(bak); @@ -661,8 +660,11 @@ public class ConfService { } public void replaceApplyOver(String applyNumber, Integer status, String adminName) { - Bak bak = sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Bak::getApplyNumber, applyNumber), Bak.class); + Bak bak = sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class); if (bak != null) { + bak.setApplyNumber(applyNumber); + sqlHelper.updateById(bak); + List subList = bakService.getSubList(bak.getId()); List subName = new ArrayList<>(); List subContent = new ArrayList<>(); diff --git a/src/main/resources/static/js/adminPage/conf/index.js b/src/main/resources/static/js/adminPage/conf/index.js index 89e33a3a..eb7bbfb8 100644 --- a/src/main/resources/static/js/adminPage/conf/index.js +++ b/src/main/resources/static/js/adminPage/conf/index.js @@ -62,7 +62,6 @@ function buildJson(){ function replaceApply() { $("#version").val(""); - $("#applyNumber").val(""); $("#changeContent").val(""); layer.open({ @@ -80,10 +79,6 @@ function replaceOver() { return; } - if ($("#applyNumber").val() == '') { - layer.msg("未填写审批编号"); - return; - } if ($("#version").val() == '') { layer.msg("未填写版本号"); return; diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index 9e9160cc..fa91bcd5 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -35,7 +35,7 @@ ${bak.applyNumber} ${bak.changeContent} - <#if bak.status == 0>未审批 + <#if bak.status == 0>审批中 <#if bak.status == 1>已审批 <#if bak.status == 2>未审批 diff --git a/src/main/resources/templates/adminPage/conf/index.html b/src/main/resources/templates/adminPage/conf/index.html index a12d31ba..e89e6efe 100644 --- a/src/main/resources/templates/adminPage/conf/index.html +++ b/src/main/resources/templates/adminPage/conf/index.html @@ -81,7 +81,10 @@ input[type='radio'] {
- +
@@ -182,13 +185,6 @@ input[type='radio'] {
- -
- -
- -
-
-- Gitee From 62ff13e2c7e0354b11966c52dac05402aa2649f4 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 15:22:40 +0800 Subject: [PATCH 07/24] 1 --- src/main/resources/application.yml | 2 +- src/main/resources/static/js/adminPage/conf/index.js | 8 +++++++- src/main/resources/templates/adminPage/bak/index.html | 2 +- src/main/resources/templates/adminPage/conf/index.html | 4 ++-- src/main/resources/templates/adminPage/menu.html | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 35b6ac12..ab7a50bd 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -37,4 +37,4 @@ logging: knife4j: enable: true - production: true # 生产环境屏蔽 \ No newline at end of file + production: false # 生产环境屏蔽 \ No newline at end of file diff --git a/src/main/resources/static/js/adminPage/conf/index.js b/src/main/resources/static/js/adminPage/conf/index.js index eb7bbfb8..be0df9cb 100644 --- a/src/main/resources/static/js/adminPage/conf/index.js +++ b/src/main/resources/static/js/adminPage/conf/index.js @@ -61,6 +61,11 @@ function buildJson(){ } function replaceApply() { + if($("#replaceApplyBtn").html().trim() == "等待审核"){ + layer.msg("审批已提交,请等待审核"); + return; + } + $("#version").val(""); $("#changeContent").val(""); @@ -104,6 +109,7 @@ function replaceOver() { if (data.success) { layer.closeAll(); layer.msg("审批已提交,请等待审核"); + $("#replaceApplyBtn").html("等待审核"); } else { layer.alert(data.msg); } @@ -480,7 +486,7 @@ function showBak(){ layer.open({ type: 2, - title: bakStr.bakFile, + title: '回滚', area : [ '80%', '90%' ], content: ctx + "/adminPage/bak" }); diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index fa91bcd5..15501663 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -43,7 +43,7 @@ - + diff --git a/src/main/resources/templates/adminPage/conf/index.html b/src/main/resources/templates/adminPage/conf/index.html index e89e6efe..0939555d 100644 --- a/src/main/resources/templates/adminPage/conf/index.html +++ b/src/main/resources/templates/adminPage/conf/index.html @@ -81,7 +81,7 @@ input[type='radio'] {
- @@ -109,7 +109,7 @@ input[type='radio'] {
- +
diff --git a/src/main/resources/templates/adminPage/menu.html b/src/main/resources/templates/adminPage/menu.html index 92414806..a3a2ff7f 100644 --- a/src/main/resources/templates/adminPage/menu.html +++ b/src/main/resources/templates/adminPage/menu.html @@ -51,9 +51,9 @@
${menuStr.log}
- +
${menuStr.export}
-- Gitee From e4630b41700c46523583c9e11e1b6c679019f8b5 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Fri, 3 Dec 2021 15:29:16 +0800 Subject: [PATCH 08/24] 123 --- .../java/com/cym/service/ConfService.java | 53 ++++++++++--------- .../templates/adminPage/bak/index.html | 4 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 8f07d548..4210e7ec 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -663,6 +663,7 @@ public class ConfService { Bak bak = sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class); if (bak != null) { bak.setApplyNumber(applyNumber); + bak.setStatus(status); sqlHelper.updateById(bak); List subList = bakService.getSubList(bak.getId()); @@ -681,11 +682,11 @@ public class ConfService { @Transactional public void replace(String nginxPath, String nginxContent, List subContent, List subName, Boolean isReplace, String adminName) { - String beforeConf = null; - if (isReplace) { - // 先读取已有的配置 - beforeConf = FileUtil.readString(nginxPath, StandardCharsets.UTF_8); - } +// String beforeConf = null; +// if (isReplace) { +// // 先读取已有的配置 +// beforeConf = FileUtil.readString(nginxPath, StandardCharsets.UTF_8); +// } String confd = new File(nginxPath).getParent().replace("\\", "/") + "/conf.d/"; // 删除conf.d下全部文件 @@ -707,27 +708,27 @@ public class ConfService { } // 备份文件 - if (isReplace) { - Bak bak = new Bak(); - bak.setTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); - bak.setContent(nginxContent); - sqlHelper.insert(bak); - - // 备份子文件 - for (int i = 0; i < subContent.size(); i++) { - BakSub bakSub = new BakSub(); - bakSub.setBakId(bak.getId()); - - bakSub.setName(subName.get(i)); - bakSub.setContent(subContent.get(i)); - sqlHelper.insert(bakSub); - } - - // 写入操作日志 - if (StrUtil.isNotEmpty(adminName)) { - operateLogService.addLog(beforeConf, nginxContent, adminName); - } - } +// if (isReplace) { +// Bak bak = new Bak(); +// bak.setTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); +// bak.setContent(nginxContent); +// sqlHelper.insert(bak); +// +// // 备份子文件 +// for (int i = 0; i < subContent.size(); i++) { +// BakSub bakSub = new BakSub(); +// bakSub.setBakId(bak.getId()); +// +// bakSub.setName(subName.get(i)); +// bakSub.setContent(subContent.get(i)); +// sqlHelper.insert(bakSub); +// } +// +// // 写入操作日志 +// if (StrUtil.isNotEmpty(adminName)) { +// operateLogService.addLog(beforeConf, nginxContent, adminName); +// } +// } } public AsycPack getAsycPack(String[] asycData) { diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index 15501663..52e6fefa 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -36,8 +36,8 @@ ${bak.changeContent} <#if bak.status == 0>审批中 - <#if bak.status == 1>已审批 - <#if bak.status == 2>未审批 + <#if bak.status == 1>已通过 + <#if bak.status == 2>未通过 -- Gitee From bcbd11d8261f371cfbbefa9c4d547bd92f17f3ea Mon Sep 17 00:00:00 2001 From: cym1102 Date: Sat, 4 Dec 2021 08:53:04 +0800 Subject: [PATCH 09/24] 123 --- .../controller/api/NginxApiController.java | 6 +- .../java/com/cym/service/ConfService.java | 70 ++++++++++++++----- .../java/com/cym/service/RemoteService.java | 4 ++ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/cym/controller/api/NginxApiController.java b/src/main/java/com/cym/controller/api/NginxApiController.java index 7be3965d..ec6a7ea3 100644 --- a/src/main/java/com/cym/controller/api/NginxApiController.java +++ b/src/main/java/com/cym/controller/api/NginxApiController.java @@ -57,13 +57,15 @@ public class NginxApiController extends BaseController { @PostMapping("applyResult") public JsonResult applyResult(@RequestHeader String token, HttpServletRequest request, // @RequestParam @ApiParam("审批编号") String applyNumber, // - @RequestParam @ApiParam("审批结果 1已通过 2未通过") Integer status) { + @RequestParam @ApiParam("审批结果 1已通过 2未通过") Integer status, // + @RequestParam @ApiParam("机器别名(不填为本地)") String remoteName// + ) { if (!bakService.isApplying()) { return renderError("当前没有申请中的更改"); } Admin admin = getAdmin(request); - confService.replaceApplyOver(applyNumber, status, admin.getName()); + confService.replaceApplyOver(applyNumber, status, admin.getName(), remoteName); return renderSuccess("下发成功"); } diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 4210e7ec..896be998 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -1,12 +1,13 @@ package com.cym.service; import java.io.File; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +26,7 @@ import com.cym.model.Http; import com.cym.model.Location; import com.cym.model.Param; import com.cym.model.Password; +import com.cym.model.Remote; import com.cym.model.Server; import com.cym.model.Stream; import com.cym.model.Template; @@ -43,8 +45,9 @@ import cn.craccd.sqlHelper.utils.ConditionAndWrapper; import cn.craccd.sqlHelper.utils.SqlHelper; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.RuntimeUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.core.util.ZipUtil; +import cn.hutool.http.HttpUtil; @Service public class ConfService { @@ -67,6 +70,8 @@ public class ConfService { OperateLogService operateLogService; @Autowired BakService bakService; + @Autowired + RemoteService remoteService; public synchronized ConfExt buildConf(Boolean decompose, Boolean check) { ConfExt confExt = new ConfExt(); @@ -659,23 +664,36 @@ public class ConfService { } } - public void replaceApplyOver(String applyNumber, Integer status, String adminName) { - Bak bak = sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class); - if (bak != null) { - bak.setApplyNumber(applyNumber); - bak.setStatus(status); - sqlHelper.updateById(bak); - - List subList = bakService.getSubList(bak.getId()); - List subName = new ArrayList<>(); - List subContent = new ArrayList<>(); - for (BakSub bakSub : subList) { - subName.add(bakSub.getName()); - subContent.add(bakSub.getContent()); - } - - String nginxPath = settingService.get("nginxPath"); - replace(nginxPath, bak.getContent(), subContent, subName, true, adminName); + public void replaceApplyOver(String applyNumber, Integer status, String adminName, String remoteName) { + if (StrUtil.isEmpty(remoteName)) { + // 本地替换 + Bak bak = sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class); + if (bak != null) { + bak.setApplyNumber(applyNumber); + bak.setStatus(status); + sqlHelper.updateById(bak); + + List subList = bakService.getSubList(bak.getId()); + List subName = new ArrayList<>(); + List subContent = new ArrayList<>(); + for (BakSub bakSub : subList) { + subName.add(bakSub.getName()); + subContent.add(bakSub.getContent()); + } + + String nginxPath = settingService.get("nginxPath"); + replace(nginxPath, bak.getContent(), subContent, subName, true, adminName); + } + } else { + // 远程替换 + Remote remote = remoteService.findByName(remoteName); + if (remote != null) { + Map map = new HashMap<>(); + map.put("applyNumber", applyNumber); + map.put("status", status); + map.put("creditKey", remote.getCreditKey()); + HttpUtil.post("http://" + remote.getIp() + ":" + remote.getPort() + "/api/nginx/applyResult", map); + } } } @@ -707,6 +725,20 @@ public class ConfService { } } + // 重载Nginx + String nginxExe = settingService.get("nginxExe"); + String nginxDir = settingService.get("nginxDir"); + + try { + String cmd = nginxExe + " -s reload -c " + nginxPath; + if (StrUtil.isNotEmpty(nginxDir)) { + cmd += " -p " + nginxDir; + } + RuntimeUtil.execForStr(cmd); + } catch (Exception e) { + logger.info(e.getMessage(), e); + } + // 备份文件 // if (isReplace) { // Bak bak = new Bak(); diff --git a/src/main/java/com/cym/service/RemoteService.java b/src/main/java/com/cym/service/RemoteService.java index 0c29ce66..2aa9ab21 100644 --- a/src/main/java/com/cym/service/RemoteService.java +++ b/src/main/java/com/cym/service/RemoteService.java @@ -97,4 +97,8 @@ public class RemoteService { } + public Remote findByName(String remoteName) { + return sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Remote::getName, remoteName), Remote.class); + } + } -- Gitee From 68a0b098e0e2f1ebc930e2363d5661e7792b99a1 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Sat, 4 Dec 2021 09:50:38 +0800 Subject: [PATCH 10/24] 1 --- src/main/java/com/cym/config/ApiInterceptor.java | 4 ++++ .../com/cym/controller/api/NginxApiController.java | 11 ++++++----- src/main/java/com/cym/service/ConfService.java | 3 ++- src/main/java/com/cym/service/RemoteService.java | 2 +- src/main/resources/static/js/adminPage/bak/index.js | 2 +- src/main/resources/templates/adminPage/bak/index.html | 5 +++++ src/main/resources/templates/adminPage/header.html | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/cym/config/ApiInterceptor.java b/src/main/java/com/cym/config/ApiInterceptor.java index 71421e38..557f6769 100644 --- a/src/main/java/com/cym/config/ApiInterceptor.java +++ b/src/main/java/com/cym/config/ApiInterceptor.java @@ -48,6 +48,10 @@ public class ApiInterceptor implements HandlerInterceptor { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { String token = request.getHeader("token"); Admin admin = adminService.getByToken(token); + if (admin == null) { + String creditKey = request.getParameter("creditKey"); + admin = adminService.getByCreditKey(creditKey); + } if (admin != null && admin.getApi()) { return true; diff --git a/src/main/java/com/cym/controller/api/NginxApiController.java b/src/main/java/com/cym/controller/api/NginxApiController.java index ec6a7ea3..cb82aefd 100644 --- a/src/main/java/com/cym/controller/api/NginxApiController.java +++ b/src/main/java/com/cym/controller/api/NginxApiController.java @@ -24,6 +24,7 @@ import com.cym.utils.NginxUtils; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HtmlUtil; +import cn.hutool.http.server.HttpServerRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -55,14 +56,14 @@ public class NginxApiController extends BaseController { @ApiOperation("下发审批结果") @PostMapping("applyResult") - public JsonResult applyResult(@RequestHeader String token, HttpServletRequest request, // + public JsonResult applyResult(HttpServletRequest request, @RequestParam @ApiParam("审批编号") String applyNumber, // @RequestParam @ApiParam("审批结果 1已通过 2未通过") Integer status, // - @RequestParam @ApiParam("机器别名(不填为本地)") String remoteName// + @RequestParam(required = false) @ApiParam("机器别名(不填为本地)") String remoteName// ) { - if (!bakService.isApplying()) { - return renderError("当前没有申请中的更改"); - } +// if (!bakService.isApplying()) { +// return renderError("当前没有申请中的更改"); +// } Admin admin = getAdmin(request); confService.replaceApplyOver(applyNumber, status, admin.getName(), remoteName); diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 896be998..d45f3229 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -692,7 +692,8 @@ public class ConfService { map.put("applyNumber", applyNumber); map.put("status", status); map.put("creditKey", remote.getCreditKey()); - HttpUtil.post("http://" + remote.getIp() + ":" + remote.getPort() + "/api/nginx/applyResult", map); + String rs = HttpUtil.post("http://" + remote.getIp() + ":" + remote.getPort() + "/api/nginx/applyResult", map); + System.out.println(rs); } } } diff --git a/src/main/java/com/cym/service/RemoteService.java b/src/main/java/com/cym/service/RemoteService.java index 2aa9ab21..ff312c01 100644 --- a/src/main/java/com/cym/service/RemoteService.java +++ b/src/main/java/com/cym/service/RemoteService.java @@ -98,7 +98,7 @@ public class RemoteService { } public Remote findByName(String remoteName) { - return sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Remote::getName, remoteName), Remote.class); + return sqlHelper.findOneByQuery(new ConditionAndWrapper().eq(Remote::getDescr, remoteName), Remote.class); } } diff --git a/src/main/resources/static/js/adminPage/bak/index.js b/src/main/resources/static/js/adminPage/bak/index.js index a9680c20..e3e7686d 100644 --- a/src/main/resources/static/js/adminPage/bak/index.js +++ b/src/main/resources/static/js/adminPage/bak/index.js @@ -116,7 +116,7 @@ function diffUsingJS(pre, bak){ layer.open({ type : 1, title: false, - area : [ '90%', '90%' ], //宽高 + area : [ '1000px', '90%' ], //宽高 content : $('#diffoutput') }); } diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index 52e6fefa..016e5997 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -3,6 +3,11 @@ <#include "/adminPage/common.html"/> + diff --git a/src/main/resources/templates/adminPage/header.html b/src/main/resources/templates/adminPage/header.html index cf4b9253..60054425 100644 --- a/src/main/resources/templates/adminPage/header.html +++ b/src/main/resources/templates/adminPage/header.html @@ -1,5 +1,5 @@
- +
  • -- Gitee From ac0faea9bc685f13927dcaa90e23764880bb49cc Mon Sep 17 00:00:00 2001 From: cym1102 Date: Sat, 4 Dec 2021 16:47:41 +0800 Subject: [PATCH 11/24] 1 --- .../controller/adminPage/ConfController.java | 4 +-- .../controller/api/NginxApiController.java | 16 +++++++---- src/main/java/com/cym/service/BakService.java | 28 +++++++++++++++++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/ConfController.java b/src/main/java/com/cym/controller/adminPage/ConfController.java index 13dda9bb..edb84241 100644 --- a/src/main/java/com/cym/controller/adminPage/ConfController.java +++ b/src/main/java/com/cym/controller/adminPage/ConfController.java @@ -81,7 +81,7 @@ public class ConfController extends BaseController { String decompose = settingService.get("decompose"); modelAndView.addObject("decompose", decompose); - Boolean applying = bakService.isApplying(); + Boolean applying = bakService.isApplying(null); modelAndView.addObject("applying", applying); modelAndView.addObject("tmp", InitConfig.home + "temp/nginx.conf"); @@ -105,7 +105,7 @@ public class ConfController extends BaseController { @ResponseBody public JsonResult replace(String json, HttpServletRequest request, String adminName) { - if(bakService.isApplying()) { + if(bakService.isApplying(null)) { return renderError("已有变更正在审批中,请稍后再试"); } diff --git a/src/main/java/com/cym/controller/api/NginxApiController.java b/src/main/java/com/cym/controller/api/NginxApiController.java index cb82aefd..a626d781 100644 --- a/src/main/java/com/cym/controller/api/NginxApiController.java +++ b/src/main/java/com/cym/controller/api/NginxApiController.java @@ -56,14 +56,13 @@ public class NginxApiController extends BaseController { @ApiOperation("下发审批结果") @PostMapping("applyResult") - public JsonResult applyResult(HttpServletRequest request, - @RequestParam @ApiParam("审批编号") String applyNumber, // + public JsonResult applyResult(HttpServletRequest request, @RequestParam @ApiParam("审批编号") String applyNumber, // @RequestParam @ApiParam("审批结果 1已通过 2未通过") Integer status, // @RequestParam(required = false) @ApiParam("机器别名(不填为本地)") String remoteName// ) { -// if (!bakService.isApplying()) { -// return renderError("当前没有申请中的更改"); -// } + if (!bakService.isApplying(remoteName)) { + return renderError("当前没有申请中的更改"); + } Admin admin = getAdmin(request); confService.replaceApplyOver(applyNumber, status, admin.getName(), remoteName); @@ -71,6 +70,13 @@ public class NginxApiController extends BaseController { return renderSuccess("下发成功"); } + @ApiOperation("查看是否有审批") + @PostMapping("isApplying") + public JsonResult isApplying(HttpServletRequest request) { + + return renderSuccess(bakService.isApplying(null)); + } + // @ApiOperation("替换conf文件") // @PostMapping("replace") // public JsonResult replace(@RequestHeader String token, HttpServletRequest request) { diff --git a/src/main/java/com/cym/service/BakService.java b/src/main/java/com/cym/service/BakService.java index 6d657550..d4f53c5f 100644 --- a/src/main/java/com/cym/service/BakService.java +++ b/src/main/java/com/cym/service/BakService.java @@ -1,23 +1,33 @@ package com.cym.service; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.cym.model.Bak; import com.cym.model.BakSub; +import com.cym.model.Remote; +import com.cym.utils.JsonResult; import cn.craccd.sqlHelper.bean.Page; import cn.craccd.sqlHelper.bean.Sort; import cn.craccd.sqlHelper.bean.Sort.Direction; import cn.craccd.sqlHelper.utils.ConditionAndWrapper; import cn.craccd.sqlHelper.utils.SqlHelper; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; @Service public class BakService { @Autowired SqlHelper sqlHelper; + @Autowired + RemoteService remoteService; public Page getList(Page page) { return sqlHelper.findPage(new ConditionAndWrapper(), new Sort(Bak::getTime, Direction.DESC), page, Bak.class); @@ -52,8 +62,22 @@ public class BakService { return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getVersion, version), Bak.class) > 0; } - public Boolean isApplying() { - return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class) > 0; + public Boolean isApplying(String remoteName) { + if(StrUtil.isEmpty(remoteName)) { + return sqlHelper.findCountByQuery(new ConditionAndWrapper().eq(Bak::getStatus, 0), Bak.class) > 0; + } else { + Remote remote = remoteService.findByName(remoteName); + if (remote != null) { + Map map = new HashMap<>(); + map.put("creditKey", remote.getCreditKey()); + String rs = HttpUtil.post("http://" + remote.getIp() + ":" + remote.getPort() + "/api/nginx/isApplying", map); + System.out.println(rs); + JsonResult jsonResult = JSONUtil.toBean(rs, JsonResult.class); + return (Boolean) jsonResult.getObj(); + } + return false; + } + } } -- Gitee From 35a667df0f751072f72d11da078a0ec52584e002 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Sat, 4 Dec 2021 23:05:06 +0800 Subject: [PATCH 12/24] 1 --- README.md | 2 +- README_EN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aba3255f..8c5f3c92 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Windows: java -jar -Xmx64m D:/home/nginxWebUI/nginxWebUI.jar --server.port=8080 #### docker安装说明 -本项目制作了docker镜像, 支持 x86/x86_64/arm64/arm v7/arm v6/ppc64 平台,同时包含nginx和nginxWebUI在内, 一体化管理与运行nginx. +本项目制作了docker镜像, 支持 x86_64/arm64/arm v7 平台,同时包含nginx和nginxWebUI在内, 一体化管理与运行nginx. 1.安装docker容器环境 diff --git a/README_EN.md b/README_EN.md index 6df83478..ad099557 100644 --- a/README_EN.md +++ b/README_EN.md @@ -112,7 +112,7 @@ Note that the command ends with an & to indicate that the project is running in #### docker installation instructions -Docker image supports x86/x86_64/arm64/arm v7/arm v6/ppc64 platforms. Note that an & sign is added at the end of the command, indicating that the docker image of this project has been produced by the background operation of the project, including nginx and nginxWebUI, for integrated management and operation of Nginx. +Docker image supports x86_64/arm64/arm v7 platforms. Note that an & sign is added at the end of the command, indicating that the docker image of this project has been produced by the background operation of the project, including nginx and nginxWebUI, for integrated management and operation of Nginx. 1.Install the Docker environment -- Gitee From 778d30e8b31eb46250eff978ed7151822227f4e1 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Mon, 6 Dec 2021 14:55:42 +0800 Subject: [PATCH 13/24] 1 --- pom.xml | 2 +- src/main/java/com/cym/config/InitConfig.java | 15 +- .../com/cym/utils/FilePermissionUtil.java | 160 ++++++++++++++++++ src/main/resources/messages.properties | 1 + src/main/resources/messages_en_US.properties | 1 + .../resources/templates/adminPage/script.html | 4 +- 6 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/cym/utils/FilePermissionUtil.java diff --git a/pom.xml b/pom.xml index 678b00ba..1c531823 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.cym nginxWebUI - 2.8.6 + 2.8.7 org.springframework.boot diff --git a/src/main/java/com/cym/config/InitConfig.java b/src/main/java/com/cym/config/InitConfig.java index 6f859d3f..4971a3e6 100644 --- a/src/main/java/com/cym/config/InitConfig.java +++ b/src/main/java/com/cym/config/InitConfig.java @@ -1,5 +1,6 @@ package com.cym.config; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -11,7 +12,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.system.ApplicationHome; +import org.springframework.boot.SpringApplication; +import org.springframework.context.ApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; @@ -20,6 +22,7 @@ import com.cym.model.Basic; import com.cym.model.Http; import com.cym.service.BasicService; import com.cym.service.SettingService; +import com.cym.utils.FilePermissionUtil; import com.cym.utils.MessageUtils; import com.cym.utils.NginxUtils; import com.cym.utils.SystemTool; @@ -51,6 +54,8 @@ public class InitConfig { SqlHelper sqlHelper; @Autowired JdbcTemplate jdbcTemplate; + @Autowired + ApplicationContext applicationContext; @Value("${project.home}") public void setHome(String home) { @@ -62,8 +67,12 @@ public class InitConfig { @PostConstruct public void init() throws IOException { - - + // 判断目录是否有写权限 + if (!FilePermissionUtil.canWrite(new File(home))) { + logger.info(m.get("commonStr.noWrite")); + SpringApplication.exit(applicationContext); + } + // 初始化base值 Long count = sqlHelper.findAllCount(Basic.class); if (count == 0) { diff --git a/src/main/java/com/cym/utils/FilePermissionUtil.java b/src/main/java/com/cym/utils/FilePermissionUtil.java new file mode 100644 index 00000000..8a2f002f --- /dev/null +++ b/src/main/java/com/cym/utils/FilePermissionUtil.java @@ -0,0 +1,160 @@ +package com.cym.utils; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * 文件处理工具类,实现文件的复制、移动、查找、追加内容等。 + * @author huangsq + * @version 2.0, 2013-10-23 + * @since 1.0, 2013-02-19 + */ +public class FilePermissionUtil { + + + /** + * 判断文件是否有读权限 + * @param file + * @return + */ + public static Boolean canRead(File file) { + if (file.isDirectory()) { + try { + File[] listFiles = file.listFiles(); + if (listFiles == null) { // 返回null表示无法读取或访问,如果为空目录返回的是一个空数组 + return false; + } else { + return true; + } + } catch (Exception e) { + return false; + } + } else if (!file.exists()) { // 文件不存在 + return false; + } + return checkRead(file); + } + + /** + * 检测文件是否有读权限 + * @param file + * @return + */ + private static boolean checkRead(File file) { + FileReader fd = null; + try { + fd = new FileReader(file); + while ((fd.read()) != -1) { + break; + } + return true; + } catch (IOException e) { + return false; + } finally { + try { + fd.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 判断文件是否有写权限 + * @param file + * @return + */ + public static Boolean canWrite(File file) { + if (file.isDirectory()) { + try { + file = new File(file, "canWriteTestDeleteOnExit.temp"); + if (file.exists()) { + boolean checkWrite = checkWrite(file); + if (!deleteFile(file)) { + file.deleteOnExit(); + } + return checkWrite; + } else if (file.createNewFile()) { + if (!deleteFile(file)) { + file.deleteOnExit(); + } + return true; + } else { + return false; + } + } catch (Exception e) { + return false; + } + } + return checkWrite(file); + } + + /** + * 检测文件是否有写权限 + * @param file + * @return + */ + private static boolean checkWrite(File file) { + FileWriter fw = null; + boolean delete = !file.exists(); + boolean result = false; + try { + fw = new FileWriter(file, true); + fw.write(""); + fw.flush(); + result = true; + return result; + } catch (IOException e) { + return false; + } finally { + try { + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (delete && result) { + deleteFile(file); + } + } + } + + /** + * 删除文件,如果要删除的对象是文件夹,先删除所有子文件(夹),再删除该文件 + * @param file 要删除的文件对象 + * @return 删除是否成功 + */ + public static boolean deleteFile(File file) { + return deleteFile(file, true); + } + + /** + * 删除文件,如果要删除的对象是文件夹,则根据delDir判断是否同时删除文件夹 + * @param file 要删除的文件对象 + * @param delDir 是否删除目录 + * @return 删除是否成功 + */ + public static boolean deleteFile(File file, boolean delDir) { + if (!file.exists()) { // 文件不存在 + return true; + } + if (file.isFile()) { + return file.delete(); + } else { + boolean result = true; + File[] children = file.listFiles(); + for (int i = 0; i < children.length; i++) { // 删除所有子文件和子文件夹 + result = deleteFile(children[i], delDir);// 递归删除文件 + if (!result) { + return false; + } + } + if (delDir) { + result = file.delete(); // 删除当前文件夹 + } + return result; + } + } + +} diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 999edce2..7ed609c1 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -123,6 +123,7 @@ commonStr.newVersion = \u6709\u65B0\u7248\u672C\u53D1\u5E03 commonStr.ngxStream = \u6B63\u5728\u67E5\u627Engx_stream_module.so\u6A21\u5757\uFF0C\u53EF\u80FD\u9700\u8981\u4E00\u4E9B\u65F6\u95F4\uFF0C\u8BF7\u8010\u5FC3\u7B49\u5F85\u3002 commonStr.no = \u5426 commonStr.noDir = \u672A\u9009\u62E9\u8DEF\u5F84 +commonStr.noWrite = project.home\u76EE\u5F55\u6CA1\u6709\u53EF\u5199\u6743\u9650,\u8BF7\u91CD\u65B0\u6307\u5B9A. commonStr.null = --\u65E0-- commonStr.ok = \u786E\u5B9A commonStr.open = \u5F00\u542F diff --git a/src/main/resources/messages_en_US.properties b/src/main/resources/messages_en_US.properties index b50fbb80..4ae6636b 100644 --- a/src/main/resources/messages_en_US.properties +++ b/src/main/resources/messages_en_US.properties @@ -123,6 +123,7 @@ commonStr.newVersion = There is a new release commonStr.ngxStream = Searching for the ngx_stream_module.so module, may take some time, please be patient. commonStr.no = No commonStr.noDir = Unselected path +commonStr.noWrite = The project.home directory does not have writable permission. Please specify it again. commonStr.null = --null-- commonStr.ok =   OK   commonStr.open = Open diff --git a/src/main/resources/templates/adminPage/script.html b/src/main/resources/templates/adminPage/script.html index 1c15bcd2..5e1d59b2 100644 --- a/src/main/resources/templates/adminPage/script.html +++ b/src/main/resources/templates/adminPage/script.html @@ -13,8 +13,8 @@ // 翻页参数 var page = { count : '${page.count!0}', - curr : '${page.curr!0}', - limit : '${page.limit!0}' + curr : '${page.curr!1}', + limit : '${page.limit!10}' }; -- Gitee From 267a075a5501cb58ad624f235a4adac31055923e Mon Sep 17 00:00:00 2001 From: cym1102 Date: Mon, 6 Dec 2021 14:59:41 +0800 Subject: [PATCH 14/24] 1 --- src/main/java/com/cym/config/InitConfig.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/cym/config/InitConfig.java b/src/main/java/com/cym/config/InitConfig.java index 4971a3e6..2f9546ff 100644 --- a/src/main/java/com/cym/config/InitConfig.java +++ b/src/main/java/com/cym/config/InitConfig.java @@ -67,12 +67,6 @@ public class InitConfig { @PostConstruct public void init() throws IOException { - // 判断目录是否有写权限 - if (!FilePermissionUtil.canWrite(new File(home))) { - logger.info(m.get("commonStr.noWrite")); - SpringApplication.exit(applicationContext); - } - // 初始化base值 Long count = sqlHelper.findAllCount(Basic.class); if (count == 0) { -- Gitee From 1f5128311fe4b8ad3750800e13c3e7e291bad291 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Mon, 6 Dec 2021 14:59:51 +0800 Subject: [PATCH 15/24] 1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1c531823..678b00ba 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.cym nginxWebUI - 2.8.7 + 2.8.6 org.springframework.boot -- Gitee From 4d6ded319008f07abc98f6504be5f50866713bba Mon Sep 17 00:00:00 2001 From: cym1102 Date: Tue, 7 Dec 2021 09:05:54 +0800 Subject: [PATCH 16/24] 1 --- pom.xml | 2 +- src/main/java/com/cym/config/FrontInterceptor.java | 14 +++++++------- .../cym/controller/adminPage/LoginController.java | 2 +- src/main/resources/templates/adminPage/header.html | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 1c531823..cabc0613 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.cym nginxWebUI - 2.8.7 + custom org.springframework.boot diff --git a/src/main/java/com/cym/config/FrontInterceptor.java b/src/main/java/com/cym/config/FrontInterceptor.java index fbe496e6..25b69852 100644 --- a/src/main/java/com/cym/config/FrontInterceptor.java +++ b/src/main/java/com/cym/config/FrontInterceptor.java @@ -84,13 +84,13 @@ public class FrontInterceptor implements HandlerInterceptor { request.setAttribute("showAdmin", request.getParameter("showAdmin")); // 显示版本更新 - if (versionConfig.getVersion() != null) { - request.setAttribute("newVersion", versionConfig.getVersion()); - - if (Integer.parseInt(currentVersion.replace(".", "").replace("v", "")) < Integer.parseInt(versionConfig.getVersion().getVersion().replace(".", "").replace("v", ""))) { - request.setAttribute("hasNewVersion", 1); - } - } +// if (versionConfig.getVersion() != null) { +// request.setAttribute("newVersion", versionConfig.getVersion()); +// +// if (Integer.parseInt(currentVersion.replace(".", "").replace("v", "")) < Integer.parseInt(versionConfig.getVersion().getVersion().replace(".", "").replace("v", ""))) { +// request.setAttribute("hasNewVersion", 1); +// } +// } // 读取配置文件 Properties properties = null; diff --git a/src/main/java/com/cym/controller/adminPage/LoginController.java b/src/main/java/com/cym/controller/adminPage/LoginController.java index 96e0ed74..55d96d95 100644 --- a/src/main/java/com/cym/controller/adminPage/LoginController.java +++ b/src/main/java/com/cym/controller/adminPage/LoginController.java @@ -118,7 +118,7 @@ public class LoginController extends BaseController { httpSession.removeAttribute("imgCode"); // 立刻销毁验证码 // 检查更新 - versionConfig.getNewVersion(); +// versionConfig.getNewVersion(); return renderSuccess(admin); } diff --git a/src/main/resources/templates/adminPage/header.html b/src/main/resources/templates/adminPage/header.html index 60054425..cf4b9253 100644 --- a/src/main/resources/templates/adminPage/header.html +++ b/src/main/resources/templates/adminPage/header.html @@ -1,5 +1,5 @@
    - +
    • -- Gitee From 603f91923f73c1bbdf11c0251e313f9a0352bcc4 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Tue, 7 Dec 2021 11:08:57 +0800 Subject: [PATCH 17/24] 1 --- .../cym/controller/api/NginxApiController.java | 9 +++++++++ src/main/java/com/cym/model/Remote.java | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cym/controller/api/NginxApiController.java b/src/main/java/com/cym/controller/api/NginxApiController.java index a626d781..fae85f7c 100644 --- a/src/main/java/com/cym/controller/api/NginxApiController.java +++ b/src/main/java/com/cym/controller/api/NginxApiController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import com.cym.controller.adminPage.ConfController; import com.cym.model.Admin; +import com.cym.model.Remote; import com.cym.service.AdminService; import com.cym.service.BakService; import com.cym.service.ConfService; @@ -76,6 +77,14 @@ public class NginxApiController extends BaseController { return renderSuccess(bakService.isApplying(null)); } + + + @ApiOperation("获取全部远程机器") + @PostMapping("getAllRemote") + public JsonResult> getAllRemote(HttpServletRequest request) { + + return renderSuccess(sqlHelper.findAll(Remote.class)); + } // @ApiOperation("替换conf文件") // @PostMapping("replace") diff --git a/src/main/java/com/cym/model/Remote.java b/src/main/java/com/cym/model/Remote.java index f8c91d61..abc90013 100644 --- a/src/main/java/com/cym/model/Remote.java +++ b/src/main/java/com/cym/model/Remote.java @@ -3,25 +3,39 @@ package com.cym.model; import cn.craccd.sqlHelper.bean.BaseModel; import cn.craccd.sqlHelper.config.InitValue; import cn.craccd.sqlHelper.config.Table; +import io.swagger.annotations.ApiModelProperty; @Table public class Remote extends BaseModel{ + @ApiModelProperty("访问协议") String protocol; + @ApiModelProperty("ip") String ip; + @ApiModelProperty("端口") Integer port; + @ApiModelProperty("状态 0 掉线 1在线") @InitValue("0") Integer status; // 0 掉线 1在线 + @ApiModelProperty("授权码") String creditKey; + @ApiModelProperty("用户名") String name; + @ApiModelProperty("密码") String pass; + @ApiModelProperty("版本") String version; + @ApiModelProperty("操作系统") String system; + @ApiModelProperty("别名") String descr; + @ApiModelProperty("是否监控") @InitValue("0") Integer monitor; - + @ApiModelProperty("父id") String parentId; + @ApiModelProperty("类型 0 服务器 1分组") Integer type; //0 服务器 1分组 + @ApiModelProperty("nginx状态") Integer nginx; //0未运行 1在运行 2未知 -- Gitee From b87476cc88a3dacd7cf88b45a7675db3810685eb Mon Sep 17 00:00:00 2001 From: cym1102 Date: Tue, 7 Dec 2021 18:15:03 +0800 Subject: [PATCH 18/24] 1 --- src/main/java/com/cym/service/ConfService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cym/service/ConfService.java b/src/main/java/com/cym/service/ConfService.java index 49febd96..880f66d8 100644 --- a/src/main/java/com/cym/service/ConfService.java +++ b/src/main/java/com/cym/service/ConfService.java @@ -681,8 +681,11 @@ public class ConfService { subContent.add(bakSub.getContent()); } - String nginxPath = settingService.get("nginxPath"); - replace(nginxPath, bak.getContent(), subContent, subName, true, adminName); + if (status == 1) { + // 审批通过, 执行替换 + String nginxPath = settingService.get("nginxPath"); + replace(nginxPath, bak.getContent(), subContent, subName, true, adminName); + } } } else { // 远程替换 -- Gitee From 90bc270e137b5f15bfaa3fd5222116c377f9b5da Mon Sep 17 00:00:00 2001 From: cym1102 Date: Wed, 15 Dec 2021 17:03:01 +0800 Subject: [PATCH 19/24] 1 --- .../cym/controller/adminPage/MainController.java | 11 +++++++++++ src/main/resources/static/js/adminPage/base.js | 16 ++++++++++++++++ src/main/resources/templates/adminPage/menu.html | 13 ++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/MainController.java b/src/main/java/com/cym/controller/adminPage/MainController.java index 1ccca853..367a0105 100644 --- a/src/main/java/com/cym/controller/adminPage/MainController.java +++ b/src/main/java/com/cym/controller/adminPage/MainController.java @@ -19,6 +19,7 @@ import org.springframework.web.servlet.ModelAndView; import com.cym.config.InitConfig; import com.cym.model.Remote; +import com.cym.service.BakService; import com.cym.service.SettingService; import com.cym.utils.BaseController; import com.cym.utils.JsonResult; @@ -38,6 +39,10 @@ public class MainController extends BaseController { @Autowired SettingService settingService; + @Autowired + BakService bakService; + + private static final Logger LOG = LoggerFactory.getLogger(MainController.class); @RequestMapping("") @@ -107,4 +112,10 @@ public class MainController extends BaseController { return renderSuccess(); } + + @ResponseBody + @RequestMapping("/adminPage/main/isApply") + public JsonResult isApply() { + return renderSuccess(bakService.isApplying(null)); + } } \ No newline at end of file diff --git a/src/main/resources/static/js/adminPage/base.js b/src/main/resources/static/js/adminPage/base.js index 02933b4d..0d7c6ed1 100644 --- a/src/main/resources/static/js/adminPage/base.js +++ b/src/main/resources/static/js/adminPage/base.js @@ -61,6 +61,22 @@ $(function() { var url = location.pathname + location.search; $("a[href='" + ctx + url.substr(1) + "']").parent().addClass("layui-this"); + // 申请中判断 + $.ajax({ + type: 'POST', + url: ctx + '/adminPage/main/isApply', + dataType: 'json', + success: function(data) { + if (data.success && data.obj) { + $(".apply").attr("href","javascript:"); + $(".apply").css("color","gray"); + } + }, + error: function() { + layer.alert(commonStr.errorInfo); + } + }); + $.ajax({ type: 'POST', diff --git a/src/main/resources/templates/adminPage/menu.html b/src/main/resources/templates/adminPage/menu.html index a3a2ff7f..725e6ad9 100644 --- a/src/main/resources/templates/adminPage/menu.html +++ b/src/main/resources/templates/adminPage/menu.html @@ -15,19 +15,19 @@
      - ${menuStr.basic} + ${menuStr.basic}
      - ${menuStr.http} + ${menuStr.http}
      - ${menuStr.stream} + ${menuStr.stream}
      - ${menuStr.server} + ${menuStr.server}
      - ${menuStr.upstream} + ${menuStr.upstream}
      @@ -38,9 +38,12 @@
      ${menuStr.template}
      + + +
      ${menuStr.password}
      -- Gitee From f0f26301d880f2f9b6d147d5cf3ff0659842b60b Mon Sep 17 00:00:00 2001 From: cym1102 Date: Wed, 15 Dec 2021 17:17:31 +0800 Subject: [PATCH 20/24] 1 --- .../cym/controller/adminPage/LoginController.java | 12 +++++++++++- .../cym/controller/adminPage/MainController.java | 13 +------------ src/main/resources/static/js/adminPage/base.js | 10 ++++++---- src/main/resources/templates/adminPage/menu.html | 1 + 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/cym/controller/adminPage/LoginController.java b/src/main/java/com/cym/controller/adminPage/LoginController.java index 55d96d95..23a4a696 100644 --- a/src/main/java/com/cym/controller/adminPage/LoginController.java +++ b/src/main/java/com/cym/controller/adminPage/LoginController.java @@ -18,6 +18,7 @@ import com.cym.config.VersionConfig; import com.cym.model.Admin; import com.cym.model.Remote; import com.cym.service.AdminService; +import com.cym.service.BakService; import com.cym.service.CreditService; import com.cym.service.SettingService; import com.cym.utils.AuthUtils; @@ -51,7 +52,9 @@ public class LoginController extends BaseController { AuthUtils authUtils; @Value("${project.version}") String currentVersion; - + @Autowired + BakService bakService; + @Autowired SettingService settingService; @@ -296,4 +299,11 @@ public class LoginController extends BaseController { return renderSuccess(); } + + @ResponseBody + @RequestMapping("/isApply") + public JsonResult isApply() { + return renderSuccess(bakService.isApplying(null)); + } + } diff --git a/src/main/java/com/cym/controller/adminPage/MainController.java b/src/main/java/com/cym/controller/adminPage/MainController.java index 367a0105..10f4080d 100644 --- a/src/main/java/com/cym/controller/adminPage/MainController.java +++ b/src/main/java/com/cym/controller/adminPage/MainController.java @@ -39,10 +39,6 @@ public class MainController extends BaseController { @Autowired SettingService settingService; - @Autowired - BakService bakService; - - private static final Logger LOG = LoggerFactory.getLogger(MainController.class); @RequestMapping("") @@ -98,8 +94,7 @@ public class MainController extends BaseController { updateUtils.run(path); return renderSuccess(); } - - + @ResponseBody @RequestMapping("/adminPage/main/changeLang") public JsonResult changeLang() { @@ -112,10 +107,4 @@ public class MainController extends BaseController { return renderSuccess(); } - - @ResponseBody - @RequestMapping("/adminPage/main/isApply") - public JsonResult isApply() { - return renderSuccess(bakService.isApplying(null)); - } } \ No newline at end of file diff --git a/src/main/resources/static/js/adminPage/base.js b/src/main/resources/static/js/adminPage/base.js index 0d7c6ed1..98f61a3a 100644 --- a/src/main/resources/static/js/adminPage/base.js +++ b/src/main/resources/static/js/adminPage/base.js @@ -61,15 +61,18 @@ $(function() { var url = location.pathname + location.search; $("a[href='" + ctx + url.substr(1) + "']").parent().addClass("layui-this"); - // 申请中判断 + + //申请中判断 $.ajax({ type: 'POST', - url: ctx + '/adminPage/main/isApply', + url: ctx + '/adminPage/login/isApply', dataType: 'json', success: function(data) { if (data.success && data.obj) { - $(".apply").attr("href","javascript:"); + $(".apply").attr("href","javascript:void(0)"); $(".apply").css("color","gray"); + + $(".apply").unbind(); } }, error: function() { @@ -77,7 +80,6 @@ $(function() { } }); - $.ajax({ type: 'POST', url: ctx + 'adminPage/login/getLocalType', diff --git a/src/main/resources/templates/adminPage/menu.html b/src/main/resources/templates/adminPage/menu.html index 725e6ad9..96a7ff50 100644 --- a/src/main/resources/templates/adminPage/menu.html +++ b/src/main/resources/templates/adminPage/menu.html @@ -87,3 +87,4 @@
+ -- Gitee From fb0c8c0414d191fd219a0d99cb6be7d67dfbc27f Mon Sep 17 00:00:00 2001 From: cym1102 Date: Wed, 15 Dec 2021 17:48:22 +0800 Subject: [PATCH 21/24] 1 --- src/main/java/com/cym/controller/adminPage/LoginController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cym/controller/adminPage/LoginController.java b/src/main/java/com/cym/controller/adminPage/LoginController.java index 23a4a696..6e88cd37 100644 --- a/src/main/java/com/cym/controller/adminPage/LoginController.java +++ b/src/main/java/com/cym/controller/adminPage/LoginController.java @@ -230,7 +230,7 @@ public class LoginController extends BaseController { String localType = (String) httpSession.getAttribute("localType"); if (StrUtil.isNotEmpty(localType)) { if ("local".equals(localType)) { - return renderSuccess(m.get("remoteStr.local")); + return renderSuccess("control机"); } else { Remote remote = (Remote) httpSession.getAttribute("remote"); if (StrUtil.isNotEmpty(remote.getDescr())) { -- Gitee From cc8a448d520c19e5f57f910e825ee97c7803424e Mon Sep 17 00:00:00 2001 From: cym1102 Date: Wed, 15 Dec 2021 17:58:28 +0800 Subject: [PATCH 22/24] 1 --- src/main/resources/static/js/adminPage/conf/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/js/adminPage/conf/index.js b/src/main/resources/static/js/adminPage/conf/index.js index be0df9cb..490071b0 100644 --- a/src/main/resources/static/js/adminPage/conf/index.js +++ b/src/main/resources/static/js/adminPage/conf/index.js @@ -108,8 +108,9 @@ function replaceOver() { success : function(data) { if (data.success) { layer.closeAll(); - layer.msg("审批已提交,请等待审核"); - $("#replaceApplyBtn").html("等待审核"); + //layer.msg("审批已提交,请等待审核"); + //$("#replaceApplyBtn").html("等待审核"); + location.reload(); } else { layer.alert(data.msg); } -- Gitee From db425be6359c4e44430055dfedd9f23d59383388 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Wed, 15 Dec 2021 18:05:04 +0800 Subject: [PATCH 23/24] 1 --- .../java/com/cym/config/AdminInterceptor.java | 17 ----------------- .../controller/adminPage/ConfController.java | 2 ++ .../controller/adminPage/LoginController.java | 5 ----- .../controller/adminPage/MainController.java | 10 ++++++++++ .../controller/adminPage/RemoteController.java | 2 +- src/main/resources/static/js/adminPage/base.js | 4 ++-- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/cym/config/AdminInterceptor.java b/src/main/java/com/cym/config/AdminInterceptor.java index 01864cf7..b433d3dc 100644 --- a/src/main/java/com/cym/config/AdminInterceptor.java +++ b/src/main/java/com/cym/config/AdminInterceptor.java @@ -122,23 +122,6 @@ public class AdminInterceptor implements HandlerInterceptor { rs = HttpUtil.post(url, body); } -// String remoteDomain = "//" + remote.getIp() + ":" + remote.getPort(); -// String remoteDomainNoPort = "//" + remote.getIp(); -// String localDomain = "//" + request.getServerName() + ":" + request.getServerPort(); -// -// rs = rs.replace(remoteDomain + "/", localDomain + "/")// -// .replace(remoteDomainNoPort + "/", localDomain + "/")// -// .replace(remoteDomain + "/adminPage", localDomain + "/adminPage")// -// .replace(remoteDomainNoPort + "/adminPage", localDomain + "/adminPage")// -// .replace(remoteDomain + "/lib", localDomain + "/lib")// -// .replace(remoteDomainNoPort + "/lib", localDomain + "/lib")// -// .replace(remoteDomain + "/js", localDomain + "/js")// -// .replace(remoteDomainNoPort + "/js", localDomain + "/js")// -// .replace(remoteDomain + "/css", localDomain + "/css")// -// .replace(remoteDomainNoPort + "/css", localDomain + "/css")// -// .replace(remoteDomain + "/img", localDomain + "/img")// -// .replace(remoteDomainNoPort + "/img", localDomain + "/img")// -// ; response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); diff --git a/src/main/java/com/cym/controller/adminPage/ConfController.java b/src/main/java/com/cym/controller/adminPage/ConfController.java index edb84241..55d5d135 100644 --- a/src/main/java/com/cym/controller/adminPage/ConfController.java +++ b/src/main/java/com/cym/controller/adminPage/ConfController.java @@ -445,5 +445,7 @@ public class ConfController extends BaseController { settingService.set(key, val); return renderSuccess(); } + + } diff --git a/src/main/java/com/cym/controller/adminPage/LoginController.java b/src/main/java/com/cym/controller/adminPage/LoginController.java index 6e88cd37..fbb3f7ff 100644 --- a/src/main/java/com/cym/controller/adminPage/LoginController.java +++ b/src/main/java/com/cym/controller/adminPage/LoginController.java @@ -300,10 +300,5 @@ public class LoginController extends BaseController { } - @ResponseBody - @RequestMapping("/isApply") - public JsonResult isApply() { - return renderSuccess(bakService.isApplying(null)); - } } diff --git a/src/main/java/com/cym/controller/adminPage/MainController.java b/src/main/java/com/cym/controller/adminPage/MainController.java index 10f4080d..14a6e24c 100644 --- a/src/main/java/com/cym/controller/adminPage/MainController.java +++ b/src/main/java/com/cym/controller/adminPage/MainController.java @@ -38,6 +38,8 @@ public class MainController extends BaseController { UpdateUtils updateUtils; @Autowired SettingService settingService; + @Autowired + BakService bakService; private static final Logger LOG = LoggerFactory.getLogger(MainController.class); @@ -106,5 +108,13 @@ public class MainController extends BaseController { return renderSuccess(); } + + + @ResponseBody + @RequestMapping("/adminPage/main/isApply") + public JsonResult isApply() { + return renderSuccess(bakService.isApplying(null)); + } + } \ No newline at end of file diff --git a/src/main/java/com/cym/controller/adminPage/RemoteController.java b/src/main/java/com/cym/controller/adminPage/RemoteController.java index 276c5aa1..aca6ed32 100644 --- a/src/main/java/com/cym/controller/adminPage/RemoteController.java +++ b/src/main/java/com/cym/controller/adminPage/RemoteController.java @@ -134,7 +134,7 @@ public class RemoteController extends BaseController { remoteLocal.setIp(""); remoteLocal.setProtocol(""); remoteLocal.setParentId(""); - remoteLocal.setDescr(m.get("remoteStr.local")); + remoteLocal.setDescr("control机"); Map map = version(); remoteLocal.setVersion((String) map.get("version")); remoteLocal.setNginx((Integer) map.get("nginx")); diff --git a/src/main/resources/static/js/adminPage/base.js b/src/main/resources/static/js/adminPage/base.js index 98f61a3a..05fc6acc 100644 --- a/src/main/resources/static/js/adminPage/base.js +++ b/src/main/resources/static/js/adminPage/base.js @@ -65,7 +65,7 @@ $(function() { //申请中判断 $.ajax({ type: 'POST', - url: ctx + '/adminPage/login/isApply', + url: ctx + '/adminPage/main/isApply', dataType: 'json', success: function(data) { if (data.success && data.obj) { @@ -76,7 +76,7 @@ $(function() { } }, error: function() { - layer.alert(commonStr.errorInfo); + //layer.alert(commonStr.errorInfo); } }); -- Gitee From dd95f626d708844ad70fc5690c8c752859568c72 Mon Sep 17 00:00:00 2001 From: cym1102 Date: Thu, 16 Dec 2021 09:19:51 +0800 Subject: [PATCH 24/24] 1 --- README.md | 2 -- README_EN.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/README.md b/README.md index 8c5f3c92..bdf48a12 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,6 @@ nginx本身功能复杂, nginxWebUI并不能涵盖nginx所有功能, 但能覆 本项目是基于springBoot的web系统, 数据库使用sqlite, 因此服务器上不需要安装任何数据库 -项目启动时会释放一个.sqlite.db到系统用户文件夹中, 注意进行备份 - 本系统通过Let's encrypt申请证书, 使用acme.sh脚本进行自动化申请和续签, 开启续签的证书将在每天凌晨2点进行续签, 只有超过60天的证书才会进行续签. 只支持在linux下签发证书. 添加tcp/ip转发配置支持时, 一些低版本的nginx可能需要重新编译,通过添加–with-stream参数指定安装stream模块才能使用, 但在ubuntu 18.04下, 官方软件库中的nginx已经带有stream模块, 不需要重新编译. 本系统如果配置了tcp转发项的话, 会自动引入ngx_stream_module.so的配置项, 如果没有开启则不引入, 最大限度优化ngnix配置文件. diff --git a/README_EN.md b/README_EN.md index ad099557..39215f95 100644 --- a/README_EN.md +++ b/README_EN.md @@ -34,8 +34,6 @@ password: Admin123 This project is a Web system based on springBoot. The database use SQLite, so there is no need to install any database on the server. -sqlite.db will be released into the system user folder when the project starts, so pay attention to backup. - This system applies for the certificate through Let's ENCRYPT and USES acme.sh script to automatically apply for and renew the certificate. Once the certificate is renewed, it will be renewed at 2 am every day, and only certificates exceeding 60 days will be renewed. When adding TCP/IP forwarding configuration support, some lower versions of Nginx may need to be recompiled,You can install the stream module by adding the -with-stream parameter, but under Ubuntu 18.04, the nginx in the official software library already has the stream module, which does not need to be recompiled. If the TCP forwarding item is configured in this system, the configuration item of ngx_stream_module.so will be introduced automatically, and the configuration file of Ngnix will be optimized to the maximum. -- Gitee