diff --git a/src/main/java/com/cym/NginxWebUI.java b/src/main/java/com/cym/NginxWebUI.java index 8b99968a7e8b6b4bd1a8ec17168f0976825a5e9e..6a5f771fafd9728927f516ebd861cfb9c8af7c0c 100644 --- a/src/main/java/com/cym/NginxWebUI.java +++ b/src/main/java/com/cym/NginxWebUI.java @@ -33,11 +33,14 @@ public class NginxWebUI { } catch (Exception e) { logger.error(e.getMessage(), e); } - + // 启动springboot SpringApplication.run(NginxWebUI.class, args); + + logger.info("启动成功"); } + public static void killSelf() { RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); String myPid = runtimeMXBean.getName().split("@")[0]; diff --git a/src/main/java/com/cym/config/ScheduleTask.java b/src/main/java/com/cym/config/ScheduleTask.java index 0ca1bbbf2352f96d3c1e7517d619b04736a5be37..ca80451c1b4bf43ef69f87fcaec03f5e8d54b3d6 100644 --- a/src/main/java/com/cym/config/ScheduleTask.java +++ b/src/main/java/com/cym/config/ScheduleTask.java @@ -76,6 +76,9 @@ public class ScheduleTask { @Autowired MessageUtils m; + @Value("${server.servlet.context-path}") + String contextPath; + // 续签证书 @Scheduled(cron = "0 0 2 * * ?") public void certTasks() { @@ -189,7 +192,7 @@ public class ScheduleTask { List remoteList = remoteService.getMonitorRemoteList(); for (Remote remote : remoteList) { try { - String json = HttpUtil.get(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + "/adminPage/remote/version?creditKey=" + remote.getCreditKey(), 1000); + String json = HttpUtil.get(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + contextPath+"/adminPage/remote/version?creditKey=" + remote.getCreditKey(), 1000); Map map = JSONUtil.toBean(json, new TypeReference>() { }.getType(), false); @@ -263,4 +266,4 @@ public class ScheduleTask { } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/cym/controller/adminPage/MainController.java b/src/main/java/com/cym/controller/adminPage/MainController.java index 1ccca8536f9a797d4d2e51dbd7a35f038b35e419..c26fba0c1b53bded2be3e80b858d0372038f82da 100644 --- a/src/main/java/com/cym/controller/adminPage/MainController.java +++ b/src/main/java/com/cym/controller/adminPage/MainController.java @@ -9,6 +9,7 @@ import javax.servlet.http.HttpSession; 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.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -38,6 +39,9 @@ public class MainController extends BaseController { @Autowired SettingService settingService; + @Value("${server.servlet.context-path}") + String contextPath; + private static final Logger LOG = LoggerFactory.getLogger(MainController.class); @RequestMapping("") @@ -64,7 +68,7 @@ public class MainController extends BaseController { HashMap paramMap = new HashMap<>(); paramMap.put("file", dest); - String rs = HttpUtil.post(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + "/upload", paramMap); + String rs = HttpUtil.post(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + contextPath+"/upload", paramMap); JsonResult jsonResult = JSONUtil.toBean(rs, JsonResult.class); FileUtil.del(dest); return jsonResult; @@ -93,8 +97,8 @@ public class MainController extends BaseController { updateUtils.run(path); return renderSuccess(); } - - + + @ResponseBody @RequestMapping("/adminPage/main/changeLang") public JsonResult changeLang() { @@ -107,4 +111,4 @@ public class MainController extends BaseController { return renderSuccess(); } -} \ 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 c25752ed677bdb52800de2c74179d2c33e205c17..bdf04da62a45868c9fefbf53a67219e44085db90 100644 --- a/src/main/java/com/cym/controller/adminPage/RemoteController.java +++ b/src/main/java/com/cym/controller/adminPage/RemoteController.java @@ -48,559 +48,562 @@ import cn.hutool.json.JSONUtil; @Controller @RequestMapping("/adminPage/remote") public class RemoteController extends BaseController { - Logger logger = LoggerFactory.getLogger(this.getClass()); - @Autowired - RemoteService remoteService; - @Autowired - SettingService settingService; - @Autowired - ConfService confService; - @Autowired - GroupService groupService; - @Autowired - ConfController confController; - @Autowired - MainController mainController; - @Autowired - NginxApiController nginxApiController; - - @Value("${project.version}") - String projectVersion; - @Value("${server.port}") - Integer port; - - @RequestMapping("version") - @ResponseBody - public Map version() { - Map map = new HashMap<>(); - map.put("version", projectVersion); - - if (NginxUtils.isRun()) { - map.put("nginx", 1); - } else { - map.put("nginx", 0); - } - - return map; - } - - @RequestMapping("") - public ModelAndView index(ModelAndView modelAndView, HttpSession httpSession) { - - JsonResult> jsonResult = nginxApiController.getNginxStartCmd(); - modelAndView.addObject("startCmds", jsonResult.getObj()); - - jsonResult = nginxApiController.getNginxStopCmd(); - modelAndView.addObject("stopCmds", jsonResult.getObj()); - - modelAndView.addObject("projectVersion", projectVersion); - modelAndView.setViewName("/adminPage/remote/index"); - - return modelAndView; - } - - @RequestMapping("allTable") - @ResponseBody - public List allTable(HttpServletRequest request) { - Admin admin = getAdmin(request); - List remoteList = sqlHelper.findAll(Remote.class); - - for (Remote remote : remoteList) { - remote.setStatus(0); - remote.setType(0); - if (remote.getParentId() == null) { - remote.setParentId(""); - } - - try { - String json = HttpUtil.get(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + "/adminPage/remote/version?creditKey=" + remote.getCreditKey(), 1000); - if (StrUtil.isNotEmpty(json)) { - Map map = JSONUtil.toBean(json, new TypeReference>() { - }.getType(), false); - - remote.setStatus(1); - remote.setVersion((String) map.get("version")); - remote.setNginx((Integer) map.get("nginx")); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - - } - - Remote remoteLocal = new Remote(); - remoteLocal.setId("local"); - remoteLocal.setIp(""); - remoteLocal.setProtocol(""); - remoteLocal.setParentId(""); - remoteLocal.setDescr(m.get("remoteStr.local")); - Map map = version(); - remoteLocal.setVersion((String) map.get("version")); - remoteLocal.setNginx((Integer) map.get("nginx")); - remoteLocal.setPort(port); - remoteLocal.setStatus(1); - remoteLocal.setType(0); - remoteLocal.setMonitor(settingService.get("monitorLocal") != null ? Integer.parseInt(settingService.get("monitorLocal")) : 0); - remoteLocal.setSystem(SystemTool.getSystem()); - remoteList.add(0, remoteLocal); - - List groupList = remoteService.getGroupByAdmin(admin); - for (Group group : groupList) { - Remote remoteGroup = new Remote(); - remoteGroup.setDescr(group.getName()); - remoteGroup.setId(group.getId()); - remoteGroup.setParentId(checkParent(group.getParentId(), groupList)); - remoteGroup.setType(1); - - remoteGroup.setIp(""); - remoteGroup.setProtocol(""); - remoteGroup.setVersion(""); - remoteGroup.setSystem(""); - - remoteList.add(remoteGroup); - } - - return remoteList; - } - - private String checkParent(String parentId, List groupList) { - - if (parentId == null) { - return ""; - } - - for (Group group : groupList) { - if (group.getId().equals(parentId)) { - return parentId; - } - } - - return ""; - } - - @RequestMapping("addGroupOver") - @ResponseBody - public JsonResult addGroupOver(Group group) { - if (StrUtil.isNotEmpty(group.getParentId()) && StrUtil.isNotEmpty(group.getId()) && group.getId().equals(group.getParentId())) { - return renderError(m.get("remoteStr.parentGroupMsg")); - } - sqlHelper.insertOrUpdate(group); - - return renderSuccess(); - } - - @RequestMapping("groupDetail") - @ResponseBody - public JsonResult groupDetail(String id) { - return renderSuccess(sqlHelper.findById(id, Group.class)); - } - - @RequestMapping("delGroup") - @ResponseBody - public JsonResult delGroup(String id) { - - groupService.delete(id); - return renderSuccess(); - } - - @RequestMapping("getGroupTree") - @ResponseBody - public JsonResult getGroupTree(HttpServletRequest request) { - Admin admin = getAdmin(request); - - List treeList = new ArrayList<>(); - Tree tree = new Tree(); - tree.setName(m.get("remoteStr.noGroup")); - tree.setValue(""); - treeList.add(0, tree); - - List groups = remoteService.getGroupByAdmin(admin); - fillTree(groups, treeList); - - return renderSuccess(treeList); - } - - public void fillTree(List groups, List treeList) { - for (Group group : groups) { - if (!hasParentIn(group.getParentId(), groups)) { - Tree tree = new Tree(); - tree.setName(group.getName()); - tree.setValue(group.getId()); - - List treeSubList = new ArrayList<>(); - fillTree(groupService.getListByParent(group.getId()), treeSubList); - tree.setChildren(treeSubList); - - treeList.add(tree); - } - } - - } - - private boolean hasParentIn(String parentId, List groups) { - for (Group group : groups) { - if (group.getId().equals(parentId)) { - return true; - } - } - return false; - } - - @RequestMapping("getCmdRemote") - @ResponseBody - public JsonResult getCmdRemote(HttpServletRequest request) { - Admin admin = getAdmin(request); - - List groups = remoteService.getGroupByAdmin(admin); - List remotes = remoteService.getListByParent(null); - - List treeList = new ArrayList<>(); - fillTreeRemote(groups, remotes, treeList); - - Tree tree = new Tree(); - tree.setName(m.get("remoteStr.local")); - tree.setValue("local"); - - treeList.add(0, tree); - - return renderSuccess(treeList); - } - - private void fillTreeRemote(List groups, List remotes, List treeList) { - for (Group group : groups) { - if (!hasParentIn(group.getParentId(), groups)) { - Tree tree = new Tree(); - tree.setName(group.getName()); - tree.setValue(group.getId()); - - List treeSubList = new ArrayList<>(); - - fillTreeRemote(groupService.getListByParent(group.getId()), remoteService.getListByParent(group.getId()), treeSubList); - - tree.setChildren(treeSubList); - - treeList.add(tree); - } - } - - for (Remote remote : remotes) { - Tree tree = new Tree(); - tree.setName(remote.getIp() + "【" + remote.getDescr() + "】"); - tree.setValue(remote.getId()); - - treeList.add(tree); - } - - } - - @RequestMapping("cmdOver") - @ResponseBody - public JsonResult cmdOver(String[] remoteId, String cmd, Integer interval, HttpServletRequest request) { - if (remoteId == null || remoteId.length == 0) { - return renderSuccess(m.get("remoteStr.noSelect")); - } - - StringBuilder rs = new StringBuilder(); - for (String id : remoteId) { - JsonResult jsonResult = null; - if (id.equals("local")) { - if (cmd.contentEquals("check")) { - jsonResult = confController.checkBase(); - } - if (cmd.contentEquals("reload")) { - jsonResult = confController.reload(null, null, null); - } - if (cmd.contentEquals("replace")) { - jsonResult = confController.replace(confController.getReplaceJson(), request, null); - } - if (cmd.startsWith("start") || cmd.startsWith("stop")) { - jsonResult = confController.runCmd(cmd.replace("start ", "").replace("stop ", ""), null); - } - if (cmd.contentEquals("update")) { - jsonResult = renderError(m.get("remoteStr.notAllow")); - } - rs.append("" + m.get("remoteStr.local") + "> "); - } else { - Remote remote = sqlHelper.findById(id, Remote.class); - rs.append("").append(remote.getIp() + ":" + remote.getPort()).append("> "); - - if (cmd.contentEquals("check")) { - cmd = "checkBase"; - } - - try { - String action = cmd; - if (cmd.startsWith("start") || cmd.startsWith("stop")) { - action = "runCmd"; - } - - String url = remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + "/adminPage/conf/" + action + "?creditKey=" + remote.getCreditKey(); - - Map map = new HashMap<>(); - if (cmd.startsWith("start") || cmd.startsWith("stop")) { - map.put("cmd", cmd.replace("start ", "").replace("stop ", "")); - } - - String json = HttpUtil.post(url, map); - jsonResult = JSONUtil.toBean(json, JsonResult.class); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - if (jsonResult != null) { - if (jsonResult.isSuccess()) { - rs.append(jsonResult.getObj().toString()); - } else { - rs.append(jsonResult.getMsg()); - } - } - rs.append("
"); - - if (interval != null) { - try { - Thread.sleep(interval * 1000); - } catch (InterruptedException e) { - logger.error(e.getMessage(), e); - } - } - } - - return renderSuccess(rs.toString()); - } - - @RequestMapping("asyc") - @ResponseBody - public JsonResult asyc(String fromId, String[] remoteId, String[] asycData, HttpServletRequest request) { - if (StrUtil.isEmpty(fromId) || remoteId == null || remoteId.length == 0) { - return renderError(m.get("remoteStr.noChoice")); - } - - Remote remoteFrom = sqlHelper.findById(fromId, Remote.class); - String json; - if (remoteFrom == null) { - // 本地 - json = getAsycPack(asycData); - } else { - // 远程 - json = HttpUtil.get(remoteFrom.getProtocol() + "://" + remoteFrom.getIp() + ":" + remoteFrom.getPort() + "/adminPage/remote/getAsycPack?creditKey=" + remoteFrom.getCreditKey() - + "&asycData=" + StrUtil.join(",", Arrays.asList(asycData)) - , 1000); - } - - String adminName = getAdmin(request).getName(); - - for (String remoteToId : remoteId) { - if (remoteToId.equals("local") || remoteToId.equals("本地")) { - setAsycPack(json, request, adminName); - } else { - Remote remoteTo = sqlHelper.findById(remoteToId, Remote.class); - try { - String version = HttpUtil.get(remoteTo.getProtocol() + "://" + remoteTo.getIp() + ":" + remoteTo.getPort() + "/adminPage/remote/version?creditKey=" + remoteTo.getCreditKey(), - 1000); - if (StrUtil.isNotEmpty(version)) { - // 在线 - Map map = new HashMap<>(); - map.put("json", json); - HttpUtil.post(remoteTo.getProtocol() + "://" + remoteTo.getIp() + ":" + remoteTo.getPort() + "/adminPage/remote/setAsycPack?creditKey=" + remoteTo.getCreditKey() - + "&adminName=" + adminName, map); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - } - return renderSuccess(); - } - - @RequestMapping("getAsycPack") - @ResponseBody - public String getAsycPack(String[] asycData) { - AsycPack asycPack = confService.getAsycPack(asycData); - - return JSONUtil.toJsonPrettyStr(asycPack); - } - - @RequestMapping("setAsycPack") - @ResponseBody - public JsonResult setAsycPack(String json, HttpServletRequest request, String adminName) { - AsycPack asycPack = JSONUtil.toBean(json, AsycPack.class); - if (StrUtil.isEmpty(adminName)) { - Admin admin = getAdmin(request); - adminName = admin.getName(); - } - confService.setAsycPack(asycPack, adminName); - - return renderSuccess(); - } - - @RequestMapping("addOver") - @ResponseBody - public JsonResult addOver(Remote remote, String code, String auth) { - remote.setIp(remote.getIp().trim()); - - if (remoteService.hasSame(remote)) { - return renderError(m.get("remoteStr.sameIp")); - } - - remoteService.getCreditKey(remote, code, auth); - - if (StrUtil.isNotEmpty(remote.getCreditKey())) { - sqlHelper.insertOrUpdate(remote); - return renderSuccess(); - } else { - return renderError(m.get("remoteStr.noAuth")); - } - - } - - @RequestMapping("getAuth") - @ResponseBody - public JsonResult getAuth(Remote remote) { - try { - Map map = new HashMap<>(); - map.put("name", remote.getName()); - map.put("pass", remote.getPass()); - map.put("remote", 1); - - String rs = HttpUtil.post(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + "/adminPage/login/getAuth", map, 3000); - - if (StrUtil.isNotEmpty(rs)) { - JsonResult jsonResult = JSONUtil.toBean(rs, JsonResult.class); - if (jsonResult.isSuccess()) { - return renderSuccess(jsonResult.getObj()); - } else { - return renderError(jsonResult.getMsg()); - } - } else { - return renderError(m.get("remoteStr.noAuth")); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - return renderError(m.get("remoteStr.noAuth")); - } - } - - @RequestMapping("detail") - @ResponseBody - public JsonResult detail(String id) { - return renderSuccess(sqlHelper.findById(id, Remote.class)); - } - - @RequestMapping("del") - @ResponseBody - public JsonResult del(String id) { - sqlHelper.deleteById(id, Remote.class); - - return renderSuccess(); - } - - @RequestMapping("content") - @ResponseBody - public JsonResult content(String id) { - - Remote remote = sqlHelper.findById(id, Remote.class); - - String rs = HttpUtil.get(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + "/adminPage/remote/readContent?creditKey=" + remote.getCreditKey()); - - return renderSuccess(rs); - } - - @RequestMapping("readContent") - @ResponseBody - public String readContent() { - - String nginxPath = settingService.get("nginxPath"); - - if (FileUtil.exist(nginxPath)) { - return FileUtil.readString(nginxPath, StandardCharsets.UTF_8); - } else { - return m.get("remoteStr.noFile"); - } - - } - - @RequestMapping("change") - @ResponseBody - public JsonResult change(String id, HttpSession httpSession) { - Remote remote = sqlHelper.findById(id, Remote.class); - - if (remote == null) { - httpSession.setAttribute("localType", "local"); - httpSession.removeAttribute("remote"); - } else { - httpSession.setAttribute("localType", "remote"); - httpSession.setAttribute("remote", remote); - } - - return renderSuccess(); - } - - @RequestMapping("nginxStatus") - @ResponseBody - public JsonResult nginxStatus(HttpSession httpSession) { - Map map = new HashMap<>(); - map.put("mail", settingService.get("mail")); - - String nginxMonitor = settingService.get("nginxMonitor"); - map.put("nginxMonitor", nginxMonitor != null ? nginxMonitor : "false"); - - return renderSuccess(map); - } - - @RequestMapping("nginxOver") - @ResponseBody - public JsonResult nginxOver(String mail, String nginxMonitor) { - settingService.set("mail", mail); - settingService.set("nginxMonitor", nginxMonitor); - - return renderSuccess(); - } - - @RequestMapping("setMonitor") - @ResponseBody - public JsonResult setMonitor(String id, Integer monitor) { - if (!"local".equals(id)) { - Remote remote = new Remote(); - remote.setId(id); - remote.setMonitor(monitor); - sqlHelper.updateById(remote); - } else { - settingService.set("monitorLocal", monitor.toString()); - } - - return renderSuccess(); - } - - @RequestMapping("/src") - public void src(HttpServletRequest httpServletRequest, HttpServletResponse response, String url) throws Exception { + Logger logger = LoggerFactory.getLogger(this.getClass()); + @Autowired + RemoteService remoteService; + @Autowired + SettingService settingService; + @Autowired + ConfService confService; + @Autowired + GroupService groupService; + @Autowired + ConfController confController; + @Autowired + MainController mainController; + @Autowired + NginxApiController nginxApiController; + + @Value("${project.version}") + String projectVersion; + @Value("${server.port}") + Integer port; + + @Value("${server.servlet.context-path}") + String contextPath; + + @RequestMapping("version") + @ResponseBody + public Map version() { + Map map = new HashMap<>(); + map.put("version", projectVersion); + + if (NginxUtils.isRun()) { + map.put("nginx", 1); + } else { + map.put("nginx", 0); + } + + return map; + } + + @RequestMapping("") + public ModelAndView index(ModelAndView modelAndView, HttpSession httpSession) { + + JsonResult> jsonResult = nginxApiController.getNginxStartCmd(); + modelAndView.addObject("startCmds", jsonResult.getObj()); + + jsonResult = nginxApiController.getNginxStopCmd(); + modelAndView.addObject("stopCmds", jsonResult.getObj()); + + modelAndView.addObject("projectVersion", projectVersion); + modelAndView.setViewName("/adminPage/remote/index"); + + return modelAndView; + } + + @RequestMapping("allTable") + @ResponseBody + public List allTable(HttpServletRequest request) { + Admin admin = getAdmin(request); + List remoteList = sqlHelper.findAll(Remote.class); + + for (Remote remote : remoteList) { + remote.setStatus(0); + remote.setType(0); + if (remote.getParentId() == null) { + remote.setParentId(""); + } + + try { + String json = HttpUtil.get(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + contextPath+"/adminPage/remote/version?creditKey=" + remote.getCreditKey(), 1000); + if (StrUtil.isNotEmpty(json)) { + Map map = JSONUtil.toBean(json, new TypeReference>() { + }.getType(), false); + + remote.setStatus(1); + remote.setVersion((String) map.get("version")); + remote.setNginx((Integer) map.get("nginx")); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + + } + + Remote remoteLocal = new Remote(); + remoteLocal.setId("local"); + remoteLocal.setIp(""); + remoteLocal.setProtocol(""); + remoteLocal.setParentId(""); + remoteLocal.setDescr(m.get("remoteStr.local")); + Map map = version(); + remoteLocal.setVersion((String) map.get("version")); + remoteLocal.setNginx((Integer) map.get("nginx")); + remoteLocal.setPort(port); + remoteLocal.setStatus(1); + remoteLocal.setType(0); + remoteLocal.setMonitor(settingService.get("monitorLocal") != null ? Integer.parseInt(settingService.get("monitorLocal")) : 0); + remoteLocal.setSystem(SystemTool.getSystem()); + remoteList.add(0, remoteLocal); + + List groupList = remoteService.getGroupByAdmin(admin); + for (Group group : groupList) { + Remote remoteGroup = new Remote(); + remoteGroup.setDescr(group.getName()); + remoteGroup.setId(group.getId()); + remoteGroup.setParentId(checkParent(group.getParentId(), groupList)); + remoteGroup.setType(1); + + remoteGroup.setIp(""); + remoteGroup.setProtocol(""); + remoteGroup.setVersion(""); + remoteGroup.setSystem(""); + + remoteList.add(remoteGroup); + } + + return remoteList; + } + + private String checkParent(String parentId, List groupList) { + + if (parentId == null) { + return ""; + } + + for (Group group : groupList) { + if (group.getId().equals(parentId)) { + return parentId; + } + } + + return ""; + } + + @RequestMapping("addGroupOver") + @ResponseBody + public JsonResult addGroupOver(Group group) { + if (StrUtil.isNotEmpty(group.getParentId()) && StrUtil.isNotEmpty(group.getId()) && group.getId().equals(group.getParentId())) { + return renderError(m.get("remoteStr.parentGroupMsg")); + } + sqlHelper.insertOrUpdate(group); + + return renderSuccess(); + } + + @RequestMapping("groupDetail") + @ResponseBody + public JsonResult groupDetail(String id) { + return renderSuccess(sqlHelper.findById(id, Group.class)); + } + + @RequestMapping("delGroup") + @ResponseBody + public JsonResult delGroup(String id) { + + groupService.delete(id); + return renderSuccess(); + } + + @RequestMapping("getGroupTree") + @ResponseBody + public JsonResult getGroupTree(HttpServletRequest request) { + Admin admin = getAdmin(request); + + List treeList = new ArrayList<>(); + Tree tree = new Tree(); + tree.setName(m.get("remoteStr.noGroup")); + tree.setValue(""); + treeList.add(0, tree); + + List groups = remoteService.getGroupByAdmin(admin); + fillTree(groups, treeList); + + return renderSuccess(treeList); + } + + public void fillTree(List groups, List treeList) { + for (Group group : groups) { + if (!hasParentIn(group.getParentId(), groups)) { + Tree tree = new Tree(); + tree.setName(group.getName()); + tree.setValue(group.getId()); + + List treeSubList = new ArrayList<>(); + fillTree(groupService.getListByParent(group.getId()), treeSubList); + tree.setChildren(treeSubList); + + treeList.add(tree); + } + } + + } + + private boolean hasParentIn(String parentId, List groups) { + for (Group group : groups) { + if (group.getId().equals(parentId)) { + return true; + } + } + return false; + } + + @RequestMapping("getCmdRemote") + @ResponseBody + public JsonResult getCmdRemote(HttpServletRequest request) { + Admin admin = getAdmin(request); + + List groups = remoteService.getGroupByAdmin(admin); + List remotes = remoteService.getListByParent(null); + + List treeList = new ArrayList<>(); + fillTreeRemote(groups, remotes, treeList); + + Tree tree = new Tree(); + tree.setName(m.get("remoteStr.local")); + tree.setValue("local"); + + treeList.add(0, tree); + + return renderSuccess(treeList); + } + + private void fillTreeRemote(List groups, List remotes, List treeList) { + for (Group group : groups) { + if (!hasParentIn(group.getParentId(), groups)) { + Tree tree = new Tree(); + tree.setName(group.getName()); + tree.setValue(group.getId()); + + List treeSubList = new ArrayList<>(); + + fillTreeRemote(groupService.getListByParent(group.getId()), remoteService.getListByParent(group.getId()), treeSubList); + + tree.setChildren(treeSubList); + + treeList.add(tree); + } + } + + for (Remote remote : remotes) { + Tree tree = new Tree(); + tree.setName(remote.getIp() + "【" + remote.getDescr() + "】"); + tree.setValue(remote.getId()); + + treeList.add(tree); + } + + } + + @RequestMapping("cmdOver") + @ResponseBody + public JsonResult cmdOver(String[] remoteId, String cmd, Integer interval, HttpServletRequest request) { + if (remoteId == null || remoteId.length == 0) { + return renderSuccess(m.get("remoteStr.noSelect")); + } + + StringBuilder rs = new StringBuilder(); + for (String id : remoteId) { + JsonResult jsonResult = null; + if (id.equals("local")) { + if (cmd.contentEquals("check")) { + jsonResult = confController.checkBase(); + } + if (cmd.contentEquals("reload")) { + jsonResult = confController.reload(null, null, null); + } + if (cmd.contentEquals("replace")) { + jsonResult = confController.replace(confController.getReplaceJson(), request, null); + } + if (cmd.startsWith("start") || cmd.startsWith("stop")) { + jsonResult = confController.runCmd(cmd.replace("start ", "").replace("stop ", ""), null); + } + if (cmd.contentEquals("update")) { + jsonResult = renderError(m.get("remoteStr.notAllow")); + } + rs.append("" + m.get("remoteStr.local") + "> "); + } else { + Remote remote = sqlHelper.findById(id, Remote.class); + rs.append("").append(remote.getIp() + ":" + remote.getPort()).append("> "); + + if (cmd.contentEquals("check")) { + cmd = "checkBase"; + } + + try { + String action = cmd; + if (cmd.startsWith("start") || cmd.startsWith("stop")) { + action = "runCmd"; + } + + String url = remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + contextPath+"/adminPage/conf/" + action + "?creditKey=" + remote.getCreditKey(); + + Map map = new HashMap<>(); + if (cmd.startsWith("start") || cmd.startsWith("stop")) { + map.put("cmd", cmd.replace("start ", "").replace("stop ", "")); + } + + String json = HttpUtil.post(url, map); + jsonResult = JSONUtil.toBean(json, JsonResult.class); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + if (jsonResult != null) { + if (jsonResult.isSuccess()) { + rs.append(jsonResult.getObj().toString()); + } else { + rs.append(jsonResult.getMsg()); + } + } + rs.append("
"); + + if (interval != null) { + try { + Thread.sleep(interval * 1000); + } catch (InterruptedException e) { + logger.error(e.getMessage(), e); + } + } + } + + return renderSuccess(rs.toString()); + } + + @RequestMapping("asyc") + @ResponseBody + public JsonResult asyc(String fromId, String[] remoteId, String[] asycData, HttpServletRequest request) { + if (StrUtil.isEmpty(fromId) || remoteId == null || remoteId.length == 0) { + return renderError(m.get("remoteStr.noChoice")); + } + + Remote remoteFrom = sqlHelper.findById(fromId, Remote.class); + String json; + if (remoteFrom == null) { + // 本地 + json = getAsycPack(asycData); + } else { + // 远程 + json = HttpUtil.get(remoteFrom.getProtocol() + "://" + remoteFrom.getIp() + ":" + remoteFrom.getPort() + contextPath+"/adminPage/remote/getAsycPack?creditKey=" + remoteFrom.getCreditKey() + + "&asycData=" + StrUtil.join(",", Arrays.asList(asycData)) + , 1000); + } + + String adminName = getAdmin(request).getName(); + + for (String remoteToId : remoteId) { + if (remoteToId.equals("local") || remoteToId.equals("本地")) { + setAsycPack(json, request, adminName); + } else { + Remote remoteTo = sqlHelper.findById(remoteToId, Remote.class); + try { + String version = HttpUtil.get(remoteTo.getProtocol() + "://" + remoteTo.getIp() + ":" + remoteTo.getPort() + contextPath+"/adminPage/remote/version?creditKey=" + remoteTo.getCreditKey(), + 1000); + if (StrUtil.isNotEmpty(version)) { + // 在线 + Map map = new HashMap<>(); + map.put("json", json); + HttpUtil.post(remoteTo.getProtocol() + "://" + remoteTo.getIp() + ":" + remoteTo.getPort() + contextPath+"/adminPage/remote/setAsycPack?creditKey=" + remoteTo.getCreditKey() + + "&adminName=" + adminName, map); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + } + return renderSuccess(); + } + + @RequestMapping("getAsycPack") + @ResponseBody + public String getAsycPack(String[] asycData) { + AsycPack asycPack = confService.getAsycPack(asycData); + + return JSONUtil.toJsonPrettyStr(asycPack); + } + + @RequestMapping("setAsycPack") + @ResponseBody + public JsonResult setAsycPack(String json, HttpServletRequest request, String adminName) { + AsycPack asycPack = JSONUtil.toBean(json, AsycPack.class); + if (StrUtil.isEmpty(adminName)) { + Admin admin = getAdmin(request); + adminName = admin.getName(); + } + confService.setAsycPack(asycPack, adminName); + + return renderSuccess(); + } + + @RequestMapping("addOver") + @ResponseBody + public JsonResult addOver(Remote remote, String code, String auth) { + remote.setIp(remote.getIp().trim()); + + if (remoteService.hasSame(remote)) { + return renderError(m.get("remoteStr.sameIp")); + } + + remoteService.getCreditKey(remote, code, auth,contextPath); + + if (StrUtil.isNotEmpty(remote.getCreditKey())) { + sqlHelper.insertOrUpdate(remote); + return renderSuccess(); + } else { + return renderError(m.get("remoteStr.noAuth")); + } + + } + + @RequestMapping("getAuth") + @ResponseBody + public JsonResult getAuth(Remote remote) { + try { + Map map = new HashMap<>(); + map.put("name", remote.getName()); + map.put("pass", remote.getPass()); + map.put("remote", 1); + + String rs = HttpUtil.post(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + contextPath + "/adminPage/login/getAuth", map, 3000); + + if (StrUtil.isNotEmpty(rs)) { + JsonResult jsonResult = JSONUtil.toBean(rs, JsonResult.class); + if (jsonResult.isSuccess()) { + return renderSuccess(jsonResult.getObj()); + } else { + return renderError(jsonResult.getMsg()); + } + } else { + return renderError(m.get("remoteStr.noAuth")); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + return renderError(m.get("remoteStr.noAuth")); + } + } + + @RequestMapping("detail") + @ResponseBody + public JsonResult detail(String id) { + return renderSuccess(sqlHelper.findById(id, Remote.class)); + } + + @RequestMapping("del") + @ResponseBody + public JsonResult del(String id) { + sqlHelper.deleteById(id, Remote.class); + + return renderSuccess(); + } + + @RequestMapping("content") + @ResponseBody + public JsonResult content(String id) { + + Remote remote = sqlHelper.findById(id, Remote.class); + + String rs = HttpUtil.get(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() + contextPath+"/adminPage/remote/readContent?creditKey=" + remote.getCreditKey()); + + return renderSuccess(rs); + } + + @RequestMapping("readContent") + @ResponseBody + public String readContent() { + + String nginxPath = settingService.get("nginxPath"); + + if (FileUtil.exist(nginxPath)) { + return FileUtil.readString(nginxPath, StandardCharsets.UTF_8); + } else { + return m.get("remoteStr.noFile"); + } + + } + + @RequestMapping("change") + @ResponseBody + public JsonResult change(String id, HttpSession httpSession) { + Remote remote = sqlHelper.findById(id, Remote.class); + + if (remote == null) { + httpSession.setAttribute("localType", "local"); + httpSession.removeAttribute("remote"); + } else { + httpSession.setAttribute("localType", "remote"); + httpSession.setAttribute("remote", remote); + } + + return renderSuccess(); + } + + @RequestMapping("nginxStatus") + @ResponseBody + public JsonResult nginxStatus(HttpSession httpSession) { + Map map = new HashMap<>(); + map.put("mail", settingService.get("mail")); + + String nginxMonitor = settingService.get("nginxMonitor"); + map.put("nginxMonitor", nginxMonitor != null ? nginxMonitor : "false"); + + return renderSuccess(map); + } + + @RequestMapping("nginxOver") + @ResponseBody + public JsonResult nginxOver(String mail, String nginxMonitor) { + settingService.set("mail", mail); + settingService.set("nginxMonitor", nginxMonitor); + + return renderSuccess(); + } + + @RequestMapping("setMonitor") + @ResponseBody + public JsonResult setMonitor(String id, Integer monitor) { + if (!"local".equals(id)) { + Remote remote = new Remote(); + remote.setId(id); + remote.setMonitor(monitor); + sqlHelper.updateById(remote); + } else { + settingService.set("monitorLocal", monitor.toString()); + } + + return renderSuccess(); + } + + @RequestMapping("/src") + public void src(HttpServletRequest httpServletRequest, HttpServletResponse response, String url) throws Exception { // response.addHeader("Content-Type", "image/jpeg"); // response.setHeader("content-disposition", "attachment;filename=code.jpg"); // 设置文件名 - byte[] buffer = new byte[1024]; - URL downUrl = new URL(url); - BufferedInputStream bis = null; - try { - bis = new BufferedInputStream(downUrl.openConnection().getInputStream()); - OutputStream os = response.getOutputStream(); - int i = bis.read(buffer); - while (i != -1) { - os.write(buffer, 0, i); - i = bis.read(buffer); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - } finally { - if (bis != null) { - try { - bis.close(); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - } - } - - } + byte[] buffer = new byte[1024]; + URL downUrl = new URL(url); + BufferedInputStream bis = null; + try { + bis = new BufferedInputStream(downUrl.openConnection().getInputStream()); + OutputStream os = response.getOutputStream(); + int i = bis.read(buffer); + while (i != -1) { + os.write(buffer, 0, i); + i = bis.read(buffer); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + } finally { + if (bis != null) { + try { + bis.close(); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + } + + } } diff --git a/src/main/java/com/cym/controller/adminPage/UpstreamController.java b/src/main/java/com/cym/controller/adminPage/UpstreamController.java index a81237e5f4cf52e21bc576b60d92abe99cde6713..ce3837c5768d242d4f1e8920e180333c213fb9b8 100644 --- a/src/main/java/com/cym/controller/adminPage/UpstreamController.java +++ b/src/main/java/com/cym/controller/adminPage/UpstreamController.java @@ -1,22 +1,9 @@ package com.cym.controller.adminPage; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import javax.servlet.http.HttpSession; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - +import cn.craccd.sqlHelper.bean.Page; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; import com.cym.ext.UpstreamExt; -import com.cym.model.Remote; -import com.cym.model.Server; import com.cym.model.Upstream; import com.cym.model.UpstreamServer; import com.cym.service.ParamService; @@ -25,187 +12,191 @@ import com.cym.service.UpstreamService; import com.cym.utils.BaseController; import com.cym.utils.JsonResult; import com.cym.utils.SnowFlakeUtils; -import com.cym.utils.TelnetUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; -import cn.craccd.sqlHelper.bean.Page; -import cn.hutool.core.lang.TypeReference; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpUtil; -import cn.hutool.json.JSONUtil; +import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Controller @RequestMapping("/adminPage/upstream") public class UpstreamController extends BaseController { - @Autowired - UpstreamService upstreamService; - @Autowired - ParamService paramService; - @Autowired - SettingService settingService; - - @RequestMapping("") - public ModelAndView index(HttpSession httpSession, ModelAndView modelAndView, Page page, String keywords) { - - page = upstreamService.search(page, keywords); - - List list = new ArrayList(); - for (Upstream upstream :(List) page.getRecords()) { - UpstreamExt upstreamExt = new UpstreamExt(); - upstreamExt.setUpstream(upstream); - - List str = new ArrayList(); - List servers = upstreamService.getUpstreamServers(upstream.getId()); - for (UpstreamServer upstreamServer : servers) { - str.add(buildStr(upstreamServer, upstream.getProxyType())); - } - - upstreamExt.setServerStr(StrUtil.join("", str)); - list.add(upstreamExt); - } - page.setRecords(list); - - modelAndView.addObject("page", page); - modelAndView.addObject("keywords", keywords); - - modelAndView.addObject("upstreamMonitor", settingService.get("upstreamMonitor")); - modelAndView.setViewName("/adminPage/upstream/index"); - return modelAndView; - } - - public String buildStr(UpstreamServer upstreamServer, Integer proxyType) { - String status = m.get("upstreamStr.noStatus"); - if (!"none".equals(upstreamServer.getStatus())) { - status = upstreamServer.getStatus(); - } - - String monitorStatus = ""; - - String upstreamMonitor = settingService.get("upstreamMonitor"); - if ("true".equals(upstreamMonitor)) { - monitorStatus += ""; - if (upstreamServer.getMonitorStatus() == -1) { - monitorStatus += "" + m.get("upstreamStr.gray") + ""; - } else if (upstreamServer.getMonitorStatus() == 1) { - monitorStatus += "" + m.get("upstreamStr.green") + ""; - } else { - monitorStatus += "" + m.get("upstreamStr.red") + ""; - } - monitorStatus += ""; - } - - if (upstreamServer.getServer().contains(":")) { - upstreamServer.setServer("[" + upstreamServer.getServer() + "]"); - } - - String html = "" + upstreamServer.getServer() + ":" + upstreamServer.getPort() + ""; - - if(upstreamServer.getWeight()!=null) { - html += "weight=" + upstreamServer.getWeight() + " "; - } - if(upstreamServer.getFailTimeout()!=null) { - html += "fail_timeout=" + upstreamServer.getFailTimeout() + "s "; - } - if(upstreamServer.getMaxFails()!=null) { - html += "max_fails=" + upstreamServer.getMaxFails() + " "; - } - if(upstreamServer.getMaxConns()!=null) { - html += "max_conns=" + upstreamServer.getMaxConns() + " "; - } - html+= "" + status + "" + monitorStatus + ""; - return html; - } - - @RequestMapping("addOver") - @ResponseBody - public JsonResult addOver(String upstreamJson, String upstreamParamJson, String upstreamServerJson) { - Upstream upstream = JSONUtil.toBean(upstreamJson, Upstream.class); - List upstreamServers = JSONUtil.toList(JSONUtil.parseArray(upstreamServerJson), UpstreamServer.class); - - - if (StrUtil.isEmpty(upstream.getId())) { - upstream.setSeq( SnowFlakeUtils.getId()); - } - - if (StrUtil.isEmpty(upstream.getId())) { - Long count = upstreamService.getCountByName(upstream.getName()); - if (count > 0) { - return renderError(m.get("upstreamStr.sameName")); - } - } else { - Long count = upstreamService.getCountByNameWithOutId(upstream.getName(), upstream.getId()); - if (count > 0) { - return renderError(m.get("upstreamStr.sameName")); - } - } - - upstreamService.addOver(upstream, upstreamServers, upstreamParamJson); - - return renderSuccess(); - } - - @RequestMapping("detail") - @ResponseBody - public JsonResult detail(String id) { - - UpstreamExt upstreamExt = new UpstreamExt(); - upstreamExt.setUpstream(sqlHelper.findById(id, Upstream.class)); - upstreamExt.setUpstreamServerList(upstreamService.getUpstreamServers(id)); - - upstreamExt.setParamJson(paramService.getJsonByTypeId(upstreamExt.getUpstream().getId(), "upstream")); - - return renderSuccess(upstreamExt); - } - - @RequestMapping("del") - @ResponseBody - public JsonResult del(String id) { - - upstreamService.del(id); - - return renderSuccess(); - } - - @RequestMapping("setMonitor") - @ResponseBody - public JsonResult setMonitor(String id, Integer monitor) { - Upstream upstream = new Upstream(); - upstream.setId(id); - upstream.setMonitor(monitor); - sqlHelper.updateById(upstream); - - return renderSuccess(); - } - - @RequestMapping("upstreamStatus") - @ResponseBody - public JsonResult upstreamStatus(HttpSession httpSession) { - Map map = new HashMap<>(); - map.put("mail", settingService.get("mail")); - - String upstreamMonitor = settingService.get("upstreamMonitor"); - map.put("upstreamMonitor", upstreamMonitor != null ? upstreamMonitor : "false"); - - return renderSuccess(map); - } - - @RequestMapping("upstreamOver") - @ResponseBody - public JsonResult upstreamOver(String mail, String upstreamMonitor) { - settingService.set("mail", mail); - settingService.set("upstreamMonitor", upstreamMonitor); - - if (upstreamMonitor.equals("true")) { - upstreamService.resetMonitorStatus(); - } - - return renderSuccess(); - } - - @RequestMapping("setOrder") - @ResponseBody - public JsonResult setOrder(String id, Integer count) { - upstreamService.setSeq(id, count); - return renderSuccess(); - } + @Autowired + UpstreamService upstreamService; + @Autowired + ParamService paramService; + @Autowired + SettingService settingService; + + @RequestMapping("") + public ModelAndView index(HttpSession httpSession, ModelAndView modelAndView, Page page, String keywords) { + + page = upstreamService.search(page, keywords); + + List list = new ArrayList(); + for (Upstream upstream : (List) page.getRecords()) { + UpstreamExt upstreamExt = new UpstreamExt(); + upstreamExt.setUpstream(upstream); + + List str = new ArrayList(); + List servers = upstreamService.getUpstreamServers(upstream.getId()); + for (UpstreamServer upstreamServer : servers) { + str.add(buildStr(upstreamServer, upstream.getProxyType())); + } + + upstreamExt.setServerStr(StrUtil.join("", str)); + list.add(upstreamExt); + } + page.setRecords(list); + + modelAndView.addObject("page", page); + modelAndView.addObject("keywords", keywords); + + modelAndView.addObject("upstreamMonitor", settingService.get("upstreamMonitor")); + modelAndView.setViewName("/adminPage/upstream/index"); + return modelAndView; + } + + public String buildStr(UpstreamServer upstreamServer, Integer proxyType) { + String status = m.get("upstreamStr.noStatus"); + if (!"none".equals(upstreamServer.getStatus())) { + status = upstreamServer.getStatus(); + } + + String monitorStatus = ""; + + String upstreamMonitor = settingService.get("upstreamMonitor"); + if ("true".equals(upstreamMonitor)) { + monitorStatus += ""; + if (upstreamServer.getMonitorStatus() == -1) { + monitorStatus += "" + m.get("upstreamStr.gray") + ""; + } else if (upstreamServer.getMonitorStatus() == 1) { + monitorStatus += "" + m.get("upstreamStr.green") + ""; + } else { + monitorStatus += "" + m.get("upstreamStr.red") + ""; + } + monitorStatus += ""; + } + + if (upstreamServer.getServer().contains(":")) { + upstreamServer.setServer("[" + upstreamServer.getServer() + "]"); + } + + String html = "" + upstreamServer.getServer() + ":" + upstreamServer.getPort() + ""; + + if (upstreamServer.getWeight() != null) { + html += "weight=" + upstreamServer.getWeight() + " "; + } + if (upstreamServer.getFailTimeout() != null) { + html += "fail_timeout=" + upstreamServer.getFailTimeout() + "s "; + } + if (upstreamServer.getMaxFails() != null) { + html += "max_fails=" + upstreamServer.getMaxFails() + " "; + } + if (upstreamServer.getMaxConns() != null) { + html += "max_conns=" + upstreamServer.getMaxConns() + " "; + } + html += "" + status + "" + monitorStatus + ""; + return html; + } + + @RequestMapping("addOver") + @ResponseBody + public JsonResult addOver(String upstreamJson, String upstreamParamJson, String upstreamServerJson) { + Upstream upstream = JSONUtil.toBean(upstreamJson, Upstream.class); + List upstreamServers = JSONUtil.toList(JSONUtil.parseArray(upstreamServerJson), UpstreamServer.class); + + + if (StrUtil.isEmpty(upstream.getId())) { + upstream.setSeq(SnowFlakeUtils.getId()); + } + + if (StrUtil.isEmpty(upstream.getId())) { + Long count = upstreamService.getCountByName(upstream.getName()); + if (count > 0) { + return renderError(m.get("upstreamStr.sameName")); + } + } else { + Long count = upstreamService.getCountByNameWithOutId(upstream.getName(), upstream.getId()); + if (count > 0) { + return renderError(m.get("upstreamStr.sameName")); + } + } + + upstreamService.addOver(upstream, upstreamServers, upstreamParamJson); + + return renderSuccess(); + } + + @RequestMapping("detail") + @ResponseBody + public JsonResult detail(String id) { + + UpstreamExt upstreamExt = new UpstreamExt(); + upstreamExt.setUpstream(sqlHelper.findById(id, Upstream.class)); + upstreamExt.setUpstreamServerList(upstreamService.getUpstreamServers(id)); + + upstreamExt.setParamJson(paramService.getJsonByTypeId(upstreamExt.getUpstream().getId(), "upstream")); + + return renderSuccess(upstreamExt); + } + + @RequestMapping("del") + @ResponseBody + public JsonResult del(String id) { + + upstreamService.del(id); + + return renderSuccess(); + } + + @RequestMapping("setMonitor") + @ResponseBody + public JsonResult setMonitor(String id, Integer monitor) { + Upstream upstream = new Upstream(); + upstream.setId(id); + upstream.setMonitor(monitor); + sqlHelper.updateById(upstream); + + return renderSuccess(); + } + + @RequestMapping("upstreamStatus") + @ResponseBody + public JsonResult upstreamStatus(HttpSession httpSession) { + Map map = new HashMap<>(); + map.put("mail", settingService.get("mail")); + + String upstreamMonitor = settingService.get("upstreamMonitor"); + map.put("upstreamMonitor", upstreamMonitor != null ? upstreamMonitor : "false"); + + return renderSuccess(map); + } + + @RequestMapping("upstreamOver") + @ResponseBody + public JsonResult upstreamOver(String mail, String upstreamMonitor) { + settingService.set("mail", mail); + settingService.set("upstreamMonitor", upstreamMonitor); + + if (upstreamMonitor.equals("true")) { + upstreamService.resetMonitorStatus(); + } + + return renderSuccess(); + } + + @RequestMapping("setOrder") + @ResponseBody + public JsonResult setOrder(String id, Integer count) { + upstreamService.setSeq(id, count); + return renderSuccess(); + } } diff --git a/src/main/java/com/cym/service/RemoteService.java b/src/main/java/com/cym/service/RemoteService.java index ff3eaa0e7bd1ff750949d8d44a811b8cc9599aa7..58f866a243c20f83c64f5e436cda749cfd78a196 100644 --- a/src/main/java/com/cym/service/RemoteService.java +++ b/src/main/java/com/cym/service/RemoteService.java @@ -29,7 +29,7 @@ public class RemoteService { @Autowired AdminService adminService; - public void getCreditKey(Remote remote, String code, String auth) { + public void getCreditKey(Remote remote, String code, String auth,String contextPath) { Map paramMap = new HashMap(); paramMap.put("name", remote.getName()); @@ -38,7 +38,7 @@ public class RemoteService { paramMap.put("auth", auth); try { String rs = HttpUtil.post(remote.getProtocol() + "://" + remote.getIp() + ":" + remote.getPort() - + "/adminPage/login/getCredit", paramMap, 2000); + + contextPath+"/adminPage/login/getCredit", paramMap, 2000); if (StrUtil.isNotEmpty(rs)) { JSONObject jsonObject = new JSONObject(rs); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 35b6ac12a7d9b2a9d5b081581b936ea778d766df..6223265a01a9efb3488bfd5e3208a91b362ae1ee 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,8 +1,9 @@ server: port: 8080 - servlet: + servlet: + context-path: /nadmin/ session: - timeout: 7200 + timeout: 7200 tomcat: # 默认是200 threads: @@ -17,8 +18,8 @@ spring: jackson: default-property-inclusion: NON_NULL jmx: - enabled: true - database: + enabled: true + database: type: sqlite package: com.cym.model print: false @@ -26,15 +27,15 @@ spring: project: version: v@project.version@ - home: /home/nginxWebUI/ - -logging: + home: D:\source\_Git\nginxWebUI + +logging: file: name: ${project.home}log/nginxWebUI.log max-size: 1024MB - level: + level: root: info knife4j: enable: true - production: true # 生产环境屏蔽 \ No newline at end of file + production: true # 生产环境屏蔽 diff --git a/src/main/resources/static/js/adminPage/remote/index.js b/src/main/resources/static/js/adminPage/remote/index.js index dcc16ff60a8696bdad4db66c794ade30d54b16bd..c1109ff196fa2cea5a977f7b992a665b7aa59238 100644 --- a/src/main/resources/static/js/adminPage/remote/index.js +++ b/src/main/resources/static/js/adminPage/remote/index.js @@ -164,7 +164,7 @@ $(function(){ } }); }) - + form.on('switch(monitor)', function(data){ $.ajax({ type : 'POST', @@ -175,7 +175,7 @@ $(function(){ }, dataType : 'json', success : function(data) { - + if (data.success) { //location.reload(); } else { @@ -186,16 +186,16 @@ $(function(){ layer.alert(commonStr.errorInfo); } }); - }); - + }); + form.on('select(cmd)', function(data){ if(data.value=='reload'){ $("#intervalDiv").show(); }else{ $("#intervalDiv").hide(); } - }); - + }); + layer.load(); layui.config({ base: ctx + 'lib/layui/exts/treeTable/' @@ -241,7 +241,7 @@ $(function(){ },{ key: 'system', title : remoteStr.system - },{ + },{ title : 'nginx', template : function(remote) { if(remote.nginx == 2){ @@ -253,10 +253,10 @@ $(function(){ if(remote.nginx == 0){ return `${remoteStr.stopped}` } - + return ""; } - },{ + },{ title : commonStr.status, template : function(remote) { if(remote.status == 1){ @@ -265,10 +265,10 @@ $(function(){ if(remote.status == 0){ return `${remoteStr.offline}` } - + return ""; } - },{ + },{ title : remoteStr.mailNotice, template : function(remote) { if(remote.type == 0){ @@ -281,20 +281,20 @@ $(function(){ title :commonStr.operation, template : function(remote) { var html = ""; - + if(remote.type == 0){ // 服务器(同版本的才能切换) //console.log( remote.version + " : " + $("#projectVersion").val()); if(remote.status == 1 && remote.version == $("#projectVersion").val()){ html += ``; } - + if(remote.id != 'local'){ // 本地 if(remote.status == 1){ html += ``; } - + html += ` @@ -305,7 +305,7 @@ $(function(){ html += ``; } } - + } else { // 分组 html += ` @@ -323,16 +323,16 @@ $(function(){ function add() { - $("#id").val(""); - $("#ip").val(""); - $("#port").val(""); - $("#descr").val(""); - $("#protocol").val("http"); - $("#name").val(""); - $("#pass").val(""); + $("#id").val(""); + $("#ip").val(""); + $("#port").val(""); + $("#descr").val(""); + $("#protocol").val("http"); + $("#name").val(""); + $("#pass").val(""); $("#monitor option:first").prop("checked", true); parentId.setValue([""]); - + showWindow(remoteStr.add); } @@ -352,7 +352,7 @@ function contentLocal(){ url : ctx + '/adminPage/remote/readContent', success : function(data) { if (data) { - + $("#preview").val(data); layer.open({ type: 1, @@ -360,8 +360,8 @@ function contentLocal(){ area: ['800px', '600px'], // 宽高 content: $('#previewDiv') }); - - + + }else{ layer.msg(data.msg); } @@ -382,7 +382,7 @@ function content(id) { }, success : function(data) { if (data.success) { - + $("#preview").val(data.obj); layer.open({ type: 1, @@ -401,8 +401,8 @@ function content(id) { } function edit(id) { - $("#id").val(id); - + $("#id").val(id); + $.ajax({ type : 'GET', url : ctx + '/adminPage/remote/detail', @@ -413,16 +413,16 @@ function edit(id) { success : function(data) { if (data.success) { var remote = data.obj; - $("#id").val(remote.id); - $("#pass").val(remote.pass); + $("#id").val(remote.id); + $("#pass").val(remote.pass); $("#name").val(remote.name); - $("#ip").val(remote.ip); - $("#port").val(remote.port); - $("#protocol").val(remote.protocol); - $("#descr").val(remote.descr); - $("#monitor").val(remote.monitor); + $("#ip").val(remote.ip); + $("#port").val(remote.port); + $("#protocol").val(remote.protocol); + $("#descr").val(remote.descr); + $("#monitor").val(remote.monitor); parentId.setValue([remote.parentId]); - + form.render(); showWindow(remoteStr.edit); }else{ @@ -484,7 +484,7 @@ function change(id){ } function asycSelect(){ - + layer.open({ type : 1, title : remoteStr.asycSelect, @@ -495,7 +495,7 @@ function asycSelect(){ function asycOver(){ - + $(".asycData") var asycData = []; $(".asycData").each(function() { @@ -507,8 +507,8 @@ function asycOver(){ layer.msg(remoteStr.noData); return; } - - + + load = layer.load(); $.ajax({ type : 'POST', @@ -536,16 +536,16 @@ function cmdGroup(){ type : 'POST', url : ctx + '/adminPage/remote/getCmdRemote', data : { - + }, dataType : 'json', success : function(data) { layer.closeAll(); if (data.success) { - + // 渲染多选 remoteCmdId = xmSelect.render({ - el: '#remoteCmdSelectId', + el: '#remoteCmdSelectId', name : 'remoteId', // 显示为text模式 model: { label: { type: 'text' } }, @@ -565,9 +565,9 @@ function cmdGroup(){ }, data: data.obj }) - + form.render(); - + layer.open({ type : 1, title : remoteStr.cmdOver, @@ -583,7 +583,7 @@ function cmdGroup(){ layer.alert(commonStr.errorInfo); } }); - + } @@ -593,8 +593,8 @@ function cmdOver(){ layer.msg(remoteStr.noSelect); return; } - - + + layer.load(); $.ajax({ type : 'POST', @@ -605,7 +605,7 @@ function cmdOver(){ layer.closeAll(); if (data.success) { layer.open({ - type: 0, + type: 0, area : [ '810px', '400px' ], content: data.obj }); @@ -625,20 +625,20 @@ function addGroup(){ $("#groupId").val(""); $("#groupName").val(""); groupParentId.setValue([""]); - + layer.open({ type : 1, title :remoteStr.addGroup, area : [ '400px', '450px' ], // 宽高 content : $('#groupDiv') }); - + } function editGroup(id) { - $("#groupId").val(id); - + $("#groupId").val(id); + $.ajax({ type : 'GET', url : ctx + '/adminPage/remote/groupDetail', @@ -649,7 +649,7 @@ function editGroup(id) { success : function(data) { if (data.success) { var group = data.obj; - $("#groupId").val(group.id); + $("#groupId").val(group.id); $("#groupName").val(group.name); groupParentId.setValue([group.parentId]); layer.open({ @@ -658,7 +658,7 @@ function editGroup(id) { area : [ '400px', '500px' ], // 宽高 content : $('#groupDiv') }); - + form.render(); }else{ layer.msg(data.msg); @@ -714,12 +714,12 @@ function delGroup(id){ } }); } - + } function nginxMonitor(){ - + $.ajax({ type : 'POST', url : ctx + '/adminPage/remote/nginxStatus', @@ -728,7 +728,7 @@ function nginxMonitor(){ if (data.success) { $("#mail").val(data.obj.mail); $("#nginxMonitor").val(data.obj.nginxMonitor); - + form.render(); layer.open({ type : 1, @@ -748,11 +748,11 @@ function nginxMonitor(){ } function nginxOver(){ - if ($("#mail").val().indexOf("@") == -1) { - layer.alert(remoteStr.emailTips); - return; + if ($("#mail").val().indexOf("@") == -1) { + layer.alert(remoteStr.emailTips); + return; } - + $.ajax({ type : 'POST', url : ctx + '/adminPage/remote/nginxOver', @@ -780,11 +780,11 @@ function nginxOver(){ var loadIndex; function testMail(){ if(confirm(remoteStr.testSend)){ - if ($("#mail").val().indexOf("@") == -1) { - layer.alert(remoteStr.emailTips); - return; + if ($("#mail").val().indexOf("@") == -1) { + layer.alert(remoteStr.emailTips); + return; } - + loadIndex = layer.load(); $.ajax({ type: 'POST', @@ -832,7 +832,7 @@ function addOver() { $("#authCode").hide(); $("#imgCode").show(); } - + refreshCode(); codeIndex = layer.open({ type : 1, @@ -849,7 +849,7 @@ function addOver() { layer.alert(commonStr.errorInfo); } }); - + } function addOverSubmit(){ @@ -877,7 +877,7 @@ function addOverSubmit(){ } function refreshCode(){ - var src = encodeURIComponent($("#protocol").val() + "://" + $("#ip").val() + ":" + $("#port").val() + "/adminPage/login/getRemoteCode?t=" + guid()); - + var src = encodeURIComponent($("#protocol").val() + "://" + $("#ip").val() + ":" + $("#port").val() + ctx +"/adminPage/login/getRemoteCode?t=" + guid()); + $("#codeImg").attr("src", ctx + "/adminPage/remote/src?url=" + src) -} \ No newline at end of file +} diff --git a/src/main/resources/templates/adminPage/abort/index.html b/src/main/resources/templates/adminPage/abort/index.html index e86aa9d8a888d71aaca9c92b1321cc524668c489..a5a22258108c0c9ac1f6d51f9d435a431b640533 100644 --- a/src/main/resources/templates/adminPage/abort/index.html +++ b/src/main/resources/templates/adminPage/abort/index.html @@ -27,7 +27,7 @@ h3{

${aboutStr.donation}

- +

${aboutStr.author}

${aboutStr.email}

@@ -45,7 +45,7 @@ h3{ <#include '/adminPage/script.html'/> - + diff --git a/src/main/resources/templates/adminPage/admin/index.html b/src/main/resources/templates/adminPage/admin/index.html index 600d58f372af0f426ee2e5e5713c46b8647df78a..b524a3968ad03048539f988eb16ba04faa9034ba 100644 --- a/src/main/resources/templates/adminPage/admin/index.html +++ b/src/main/resources/templates/adminPage/admin/index.html @@ -26,7 +26,7 @@ ${menuStr.admin} -
+
@@ -177,7 +177,7 @@
- +
${adminStr.android} @@ -185,7 +185,7 @@
- +
${adminStr.ios} @@ -197,7 +197,7 @@
<#include '/adminPage/script.html'/> - + diff --git a/src/main/resources/templates/adminPage/bak/index.html b/src/main/resources/templates/adminPage/bak/index.html index 59a029e7767e88573bfe29a3cee741924dbd96b1..c18acca09e46eaac69573d754b7fc5cd4101e89e 100644 --- a/src/main/resources/templates/adminPage/bak/index.html +++ b/src/main/resources/templates/adminPage/bak/index.html @@ -7,7 +7,7 @@
- +
@@ -43,7 +43,7 @@ <#include '/adminPage/script.html'/> <#include '/adminPage/select_preview.html'/> - + diff --git a/src/main/resources/templates/adminPage/basic/index.html b/src/main/resources/templates/adminPage/basic/index.html index 787b18d2f9eee9b5de93ec27432bbf42d01141fe..92195ace93b3484af69703c9a7eea634f0f6e146 100644 --- a/src/main/resources/templates/adminPage/basic/index.html +++ b/src/main/resources/templates/adminPage/basic/index.html @@ -17,7 +17,7 @@ ${menuStr.basic} - +
@@ -84,7 +84,7 @@
<#include '/adminPage/script.html'/> - + diff --git a/src/main/resources/templates/adminPage/cert/index.html b/src/main/resources/templates/adminPage/cert/index.html index 8ea5aee464215a627b9e1d598d788b45e220634e..d2b1487669c47bdf67e83eeb92b9aaa1edbfe1c7 100644 --- a/src/main/resources/templates/adminPage/cert/index.html +++ b/src/main/resources/templates/adminPage/cert/index.html @@ -30,7 +30,7 @@ ${menuStr.cert} - +