提交 80b9d289 编写于 作者: lakernote's avatar lakernote

(update)[整体](nginxui功能新增)

上级 c01928c3
...@@ -28,6 +28,38 @@ public class LakerConfig { ...@@ -28,6 +28,38 @@ public class LakerConfig {
*/ */
private Waf waf = new Waf(); private Waf waf = new Waf();
/**
* nginx
*/
private Nginx nginx = new Nginx();
public static class Nginx {
/**
* nginx路径
*/
private String path;
/**
* nginx配置文件路径
*/
private String confPath = "file/nginx.conf";
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getConfPath() {
return confPath;
}
public void setConfPath(String confPath) {
this.confPath = confPath;
}
}
public static class Waf { public static class Waf {
private boolean xssEnabled = true; private boolean xssEnabled = true;
private boolean sqlEnabled = true; private boolean sqlEnabled = true;
......
...@@ -2,9 +2,11 @@ package com.laker.admin.module.sys.controller; ...@@ -2,9 +2,11 @@ package com.laker.admin.module.sys.controller;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.github.odiszapc.nginxparser.NgxConfig; import com.github.odiszapc.nginxparser.NgxConfig;
import com.github.odiszapc.nginxparser.NgxDumper; import com.github.odiszapc.nginxparser.NgxDumper;
import com.laker.admin.config.LakerConfig;
import com.laker.admin.framework.model.Response; import com.laker.admin.framework.model.Response;
import com.laker.admin.module.sys.pojo.NginxQo; import com.laker.admin.module.sys.pojo.NginxQo;
import com.laker.admin.module.sys.service.ISysDeptService; import com.laker.admin.module.sys.service.ISysDeptService;
...@@ -28,11 +30,16 @@ import java.util.Date; ...@@ -28,11 +30,16 @@ import java.util.Date;
public class NginxController { public class NginxController {
@Autowired @Autowired
ISysDeptService sysDeptService; ISysDeptService sysDeptService;
@Autowired
LakerConfig lakerConfig;
@GetMapping @GetMapping
public Response get(@RequestParam(required = false, defaultValue = "file/nginx.conf") String path) { public Response get(@RequestParam(required = false) String path) {
NgxConfig conf = null; NgxConfig conf = null;
try { try {
if (StrUtil.isBlank(path)) {
path = lakerConfig.getNginx().getConfPath();
}
conf = NgxConfig.read(path); conf = NgxConfig.read(path);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -45,10 +52,43 @@ public class NginxController { ...@@ -45,10 +52,43 @@ public class NginxController {
@PostMapping @PostMapping
public Response update(@RequestBody NginxQo nginxQo) { public Response update(@RequestBody NginxQo nginxQo) {
if (StrUtil.isBlank(nginxQo.getPath())) { if (StrUtil.isBlank(nginxQo.getPath())) {
nginxQo.setPath("file/nginx.conf"); nginxQo.setPath(lakerConfig.getNginx().getConfPath());
} }
FileUtil.rename(new File(nginxQo.getPath()), "nginx.conf-bak-" + DateUtil.format(new Date(), "yyyy-MM-dd-HH-mm-ss"), true); FileUtil.rename(new File(nginxQo.getPath()), "nginx.conf-bak-" + DateUtil.format(new Date(), "yyyy-MM-dd-HH-mm-ss"), true);
FileUtil.writeString(nginxQo.getContext(), new File(nginxQo.getPath()), "utf-8"); FileUtil.writeString(nginxQo.getContext(), new File(nginxQo.getPath()), "utf-8");
return Response.ok(); return Response.ok();
} }
@PostMapping("/check")
public Response check(@RequestBody NginxQo nginxQo) {
if (StrUtil.isBlank(nginxQo.getPath())) {
nginxQo.setPath(lakerConfig.getNginx().getConfPath());
}
String res = RuntimeUtil.execForStr("nginx -t -c " + nginxQo.getPath());
return Response.ok(res);
}
@PostMapping("/reload")
public Response reload(@RequestBody NginxQo nginxQo) {
if (StrUtil.isBlank(nginxQo.getPath())) {
nginxQo.setPath(lakerConfig.getNginx().getConfPath());
}
String res = RuntimeUtil.execForStr("nginx -s reload -c " + nginxQo.getPath());
return Response.ok(res);
}
@PostMapping("/start")
public Response start(@RequestBody NginxQo nginxQo) {
if (StrUtil.isBlank(nginxQo.getPath())) {
nginxQo.setPath(lakerConfig.getNginx().getConfPath());
}
String res = RuntimeUtil.execForStr("nginx -c " + nginxQo.getPath());
return Response.ok(res);
}
@PostMapping("/stop")
public Response stop() {
String res = RuntimeUtil.execForStr("nginx -s quit");
return Response.ok(res);
}
} }
\ No newline at end of file
...@@ -57,4 +57,4 @@ laker: ...@@ -57,4 +57,4 @@ laker:
waf: waf:
sql-enabled: true sql-enabled: true
xss-enabled: true xss-enabled: true
excludes: /flow/* excludes: /flow/*,/sys/nginx/*
\ No newline at end of file \ No newline at end of file
...@@ -9,14 +9,16 @@ ...@@ -9,14 +9,16 @@
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<div class="layui-btn-group"> <div class="layui-btn-group">
<button type="button" class="layui-btn">校验</button> <button type="button" class="layui-btn" id="check">校验</button>
<button type="button" class="layui-btn ">启动</button> <button type="button" class="layui-btn" id="start">启动</button>
<button type="button" class="layui-btn">停止</button> <button type="button" class="layui-btn" id="stop">停止</button>
<button type="button" class="layui-btn">热启动</button> <button type="button" class="layui-btn" id="reload">热启动</button>
</div> </div>
</div> </div>
</div>
<div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<form class="layui-form" action=""> <form class="layui-form" action="" lay-filter="nginx">
<div class="layui-form-item" style="width: 100%;"> <div class="layui-form-item" style="width: 100%;">
<label class="layui-form-label">配置路径</label> <label class="layui-form-label">配置路径</label>
...@@ -41,6 +43,7 @@ ...@@ -41,6 +43,7 @@
</div> </div>
</div> </div>
</body> </body>
<script src="../../component/layui/layui.js"></script> <script src="../../component/layui/layui.js"></script>
...@@ -54,6 +57,118 @@ ...@@ -54,6 +57,118 @@
$("#getConf").click(function () { $("#getConf").click(function () {
getConfContent(); getConfContent();
}); });
$("#check").click(function () {
easyAdmin.http({
url: "/sys/nginx/check",
data: JSON.stringify(form.val("nginx")),
dataType: 'json',
contentType: 'application/json',
type: 'post',
success: function (result) {
if (result.success) {
layer.msg(result.msg,
{
icon: 1,
time: 2000,
area: ['100px', '65px'],
content: "执行成功"
});
} else {
layer.msg(result.msg,
{
icon: 2,
time: 2000,
area: ['220px', '70px']
}
);
}
}
})
});
$("#start").click(function () {
easyAdmin.http({
url: "/sys/nginx/start",
data: JSON.stringify(form.val("nginx")),
dataType: 'json',
contentType: 'application/json',
type: 'post',
success: function (result) {
if (result.success) {
layer.msg(result.msg,
{
icon: 1,
time: 2000,
area: ['100px', '65px'],
content: "执行成功"
});
} else {
layer.msg(result.msg,
{
icon: 2,
time: 2000,
area: ['220px', '70px']
}
);
}
}
})
});
$("#stop").click(function () {
easyAdmin.http({
url: "/sys/nginx/stop",
dataType: 'json',
contentType: 'application/json',
type: 'post',
success: function (result) {
if (result.success) {
layer.msg(result.msg,
{
icon: 1,
time: 2000,
area: ['100px', '65px'],
content: "执行成功"
});
} else {
layer.msg(result.msg,
{
icon: 2,
time: 2000,
area: ['220px', '70px']
}
);
}
}
})
});
$("#reload").click(function () {
easyAdmin.http({
url: "/sys/nginx/reload",
data: JSON.stringify(form.val("nginx")),
dataType: 'json',
contentType: 'application/json',
type: 'post',
success: function (result) {
if (result.success) {
layer.msg(result.msg,
{
icon: 1,
time: 2000,
area: ['100px', '65px'],
content: "执行成功"
});
} else {
layer.msg(result.msg,
{
icon: 2,
time: 2000,
area: ['220px', '70px']
}
);
}
}
})
});
form.on('submit(save)', function (data) { form.on('submit(save)', function (data) {
// 转换 // 转换
easyAdmin.http({ easyAdmin.http({
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="text" name="keyWord" placeholder="" class="layui-input"> <input type="text" name="keyWord" placeholder="" class="layui-input">
</div> </div>
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="dict-type-query"> <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
<i class="layui-icon layui-icon-search"></i> <i class="layui-icon layui-icon-search"></i>
查询 查询
</button> </button>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册