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

(新增)[整体](增加Nginx在线编辑ui)

上级 46c56f39
worker_processes 1;
http {
server {
# 端口号
listen 80;
server_name www.nginx.cn;
location / {
proxy_pass http://www.nginx.cn;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 注释
server {
listen 8444;
server_name localhost;
location / {
proxy_pass http://192.168.0.1;
}
}
}
package com.laker.admin.module.sys.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.github.odiszapc.nginxparser.NgxConfig;
import com.github.odiszapc.nginxparser.NgxDumper;
import com.laker.admin.framework.Response;
import com.laker.admin.module.sys.pojo.NginxQo;
import com.laker.admin.module.sys.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.IOException;
import java.util.Date;
/**
* <p>
* nginx前端控制器
* </p>
*
* @author laker
* @since 2021-08-11
*/
@RestController
@RequestMapping("/sys/nginx")
public class NginxController {
@Autowired
ISysDeptService sysDeptService;
@GetMapping
public Response get(@RequestParam(required = false, defaultValue = "file/nginx.conf") String path) {
NgxConfig conf = null;
try {
conf = NgxConfig.read(path);
} catch (IOException e) {
e.printStackTrace();
return Response.error("500", "路径错误:" + path);
}
String content = new NgxDumper(conf).dump();
return Response.ok(content);
}
@PostMapping
public Response update(@RequestBody NginxQo nginxQo) {
if (StrUtil.isBlank(nginxQo.getPath())) {
nginxQo.setPath("file/nginx.conf");
}
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");
return Response.ok();
}
}
\ No newline at end of file
package com.laker.admin.module.sys.pojo;
import lombok.Data;
@Data
public class NginxQo {
private String path;
private String context;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="../../component/pear/css/pear.css" rel="stylesheet"/>
</head>
<body class="pear-container">
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-btn-group">
<button type="button" class="layui-btn">校验</button>
<button type="button" class="layui-btn ">启动</button>
<button type="button" class="layui-btn">停止</button>
<button type="button" class="layui-btn">热启动</button>
</div>
</div>
<div class="layui-card-body">
<form class="layui-form" action="">
<div class="layui-form-item" style="width: 100%;">
<label class="layui-form-label">配置路径</label>
<div class="layui-input-inline" style="width: 36%;">
<input type="text" name="path" id="nginxConfPath" autocomplete="off" class="layui-input"
style="width: 99%;"
placeholder="请输入nginx配置文件路径" lay-verify="title">
</div>
<button type="button" class="layui-btn" id="getConf">加载</button>
<button type="submit" class="layui-btn" lay-submit="" lay-filter="save">保存</button>
</div>
<div class="layui-form-item adminj-sort-item" id="did_1629876782412_1" cpt_id="textarea"
style="width: 100%;">
<label class="layui-form-label"></label>
<div class="layui-input-inline" style="width: 66%;">
<textarea id="nginxContent" name="context" class="layui-textarea"
style="width: 99%; height: 600px"></textarea>
</div>
</div>
</form>
</div>
</div>
</body>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
layui.use(['easyAdmin', 'form'], function () {
let easyAdmin = layui.easyAdmin;
var $ = layui.$; //使用jQuery 重点处
let form = layui.form;
getConfContent();
$("#getConf").click(function () {
getConfContent();
});
form.on('submit(save)', function (data) {
// 转换
easyAdmin.http({
url: "/sys/nginx",
data: JSON.stringify(data.field),
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: "保存成功"
}, function () {
getConfContent();
});
} else {
layer.msg(result.msg,
{
icon: 2,
time: 2000,
area: ['220px', '70px']
}
);
}
}
})
return false;
});
function getConfContent() {
var nginxConfPath = $('#nginxConfPath').val();
easyAdmin.httpGet("/sys/nginx?path=" + nginxConfPath, function (res) {
if (res.success) {
$('#nginxContent').val(res.data);
} else {
layer.msg(res.msg,
{icon: 2, time: 2000, area: ['230px', '65px']}
);
}
});
}
})
</script>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册