package com.cym.service;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cym.config.HomeConfig;
import com.cym.ext.AsycPack;
import com.cym.ext.ConfExt;
import com.cym.ext.ConfFile;
import com.cym.model.Bak;
import com.cym.model.BakSub;
import com.cym.model.Basic;
import com.cym.model.Cert;
import com.cym.model.CertCode;
import com.cym.model.DenyAllow;
import com.cym.model.Http;
import com.cym.model.Location;
import com.cym.model.Param;
import com.cym.model.Password;
import com.cym.model.Server;
import com.cym.model.Stream;
import com.cym.model.Template;
import com.cym.model.Upstream;
import com.cym.model.UpstreamServer;
import com.cym.sqlhelper.bean.Sort;
import com.cym.sqlhelper.bean.Sort.Direction;
import com.cym.sqlhelper.utils.ConditionAndWrapper;
import com.cym.sqlhelper.utils.SqlHelper;
import com.cym.utils.SystemTool;
import com.cym.utils.ToolUtils;
import com.github.odiszapc.nginxparser.NgxBlock;
import com.github.odiszapc.nginxparser.NgxConfig;
import com.github.odiszapc.nginxparser.NgxDumper;
import com.github.odiszapc.nginxparser.NgxEntry;
import com.github.odiszapc.nginxparser.NgxParam;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
@Component
public class ConfService {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Inject
UpstreamService upstreamService;
@Inject
SettingService settingService;
@Inject
ServerService serverService;
@Inject
LocationService locationService;
@Inject
ParamService paramService;
@Inject
SqlHelper sqlHelper;
@Inject
TemplateService templateService;
@Inject
OperateLogService operateLogService;
@Inject
HomeConfig homeConfig;
@Inject
CertService certService;
@Inject
DenyAllowService denyAllowService;
public synchronized ConfExt buildConf(Boolean decompose, Boolean check) {
ConfExt confExt = new ConfExt();
confExt.setFileList(new ArrayList<>());
// String nginxPath = settingService.get("nginxPath");
// if (check) {
// nginxPath = homeConfig.home + "temp/nginx.conf";
// }
try {
NgxConfig ngxConfig = new NgxConfig();
// 获取基本参数
List<Basic> basicList = sqlHelper.findAll(new Sort("seq", Direction.ASC), Basic.class);
for (Basic basic : basicList) {
NgxParam ngxParam = new NgxParam();
ngxParam.addValue(basic.getName().trim() + " " + basic.getValue().trim());
ngxConfig.addEntry(ngxParam);
}
// 获取http
List<Http> httpList = sqlHelper.findAll(new Sort("seq", Direction.ASC), Http.class);
boolean hasHttp = false;
NgxBlock ngxBlockHttp = new NgxBlock();
ngxBlockHttp.addValue("http");
for (Http http : httpList) {
if (http.getEnable() == null || !http.getEnable()) {
continue;
}
NgxParam ngxParam = new NgxParam();
ngxParam.addValue(http.getName().trim() + " " + http.getValue().trim());
ngxBlockHttp.addEntry(ngxParam);
hasHttp = true;
}
// 黑白名单
buildDenyAllow(ngxBlockHttp, "http", "http", confExt);
// 添加upstream
NgxParam ngxParam;
List<Upstream> upstreams = upstreamService.getListByProxyType(0);
for (Upstream upstream : upstreams) {
NgxBlock ngxBlockServer = new NgxBlock();
ngxBlockServer.addValue("upstream " + upstream.getName().trim());
if (StrUtil.isNotEmpty(upstream.getDescr())) {
String[] descrs = upstream.getDescr().split("\n");
for (String d : descrs) {
ngxParam = new NgxParam();
ngxParam.addValue("# " + d);
ngxBlockServer.addEntry(ngxParam);
}
}
if (StrUtil.isNotEmpty(upstream.getTactics())) {
ngxParam = new NgxParam();
ngxParam.addValue(upstream.getTactics());
ngxBlockServer.addEntry(ngxParam);
}
List<UpstreamServer> upstreamServers = upstreamService.getUpstreamServers(upstream.getId());
for (UpstreamServer upstreamServer : upstreamServers) {
ngxParam = new NgxParam();
ngxParam.addValue("server " + buildNodeStr(upstreamServer));
ngxBlockServer.addEntry(ngxParam);
}
// 自定义参数
List<Param> paramList = paramService.getListByTypeId(upstream.getId(), "upstream");
for (Param param : paramList) {
setSameParam(param, ngxBlockServer);
}
hasHttp = true;
if (decompose) {
String filename = addConfFile(confExt, "upstreams." + upstream.getName() + ".conf", ngxBlockServer);
ngxParam = new NgxParam();
ngxParam.addValue("include " + filename);
ngxBlockHttp.addEntry(ngxParam);
} else {
ngxBlockHttp.addEntry(ngxBlockServer);
}
}
// 添加server
List<Server> servers = serverService.getListByProxyType(new String[] { "0" });
for (Server server : servers) {
if (server.getEnable() == null || !server.getEnable()) {
continue;
}
NgxBlock ngxBlockServer = bulidBlockServer(server, confExt);
hasHttp = true;
// 是否需要分解
if (decompose) {
String name = "all";
if (StrUtil.isNotEmpty(server.getServerName())) {
name = server.getServerName();
}
String filename = addConfFile(confExt, name + ".conf", ngxBlockServer);
ngxParam = new NgxParam();
ngxParam.addValue("include " + filename);
if (noContain(ngxBlockHttp, ngxParam)) {
ngxBlockHttp.addEntry(ngxParam);
}
} else {
ngxBlockHttp.addEntry(ngxBlockServer);
}
}
if (hasHttp) {
ngxConfig.addEntry(ngxBlockHttp);
}
// TCP/UDP转发
// 创建stream
List<Stream> streamList = sqlHelper.findAll(new Sort("seq", Direction.ASC), Stream.class);
boolean hasStream = false;
NgxBlock ngxBlockStream = new NgxBlock();
ngxBlockStream.addValue("stream");
for (Stream stream : streamList) {
ngxParam = new NgxParam();
ngxParam.addValue(stream.getName() + " " + stream.getValue());
ngxBlockStream.addEntry(ngxParam);
hasStream = true;
}
// 黑白名单
buildDenyAllow(ngxBlockStream, "stream", "stream", confExt);
// 添加upstream
upstreams = upstreamService.getListByProxyType(1);
for (Upstream upstream : upstreams) {
NgxBlock ngxBlockServer = buildBlockUpstream(upstream);
if (decompose) {
String filename = addConfFile(confExt, "upstreams." + upstream.getName() + ".conf", ngxBlockServer);
ngxParam = new NgxParam();
ngxParam.addValue("include " + filename);
ngxBlockStream.addEntry(ngxParam);
} else {
ngxBlockStream.addEntry(ngxBlockServer);
}
hasStream = true;
}
// 添加server
servers = serverService.getListByProxyType(new String[] { "1", "2" });
for (Server server : servers) {
if (server.getEnable() == null || !server.getEnable()) {
continue;
}
NgxBlock ngxBlockServer = bulidBlockServer(server, confExt);
if (decompose) {
String type = "";
if (server.getProxyType() == 0) {
type = "http";
} else if (server.getProxyType() == 1) {
type = "tcp";
} else if (server.getProxyType() == 2) {
type = "udp";
}
String filename = addConfFile(confExt, type + "." + server.getListen() + ".conf", ngxBlockServer);
ngxParam = new NgxParam();
ngxParam.addValue("include " + filename);
ngxBlockStream.addEntry(ngxParam);
} else {
ngxBlockStream.addEntry(ngxBlockServer);
}
hasStream = true;
}
if (hasStream) {
ngxConfig.addEntry(ngxBlockStream);
}
String conf = ToolUtils.handleConf(new NgxDumper(ngxConfig).dump());
// 将多个;替换成单一;
while (conf.contains(";;")) {
conf = conf.replaceAll(";;", ";");
}
没有合适的资源?快使用搜索试试~ 我知道了~
方便快捷易用的Nginx可视化UI网页管理部署配置工具系统,使用Web网页系统来快速配置部署
共708个文件
html:385个
java:151个
js:55个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 137 浏览量
2024-09-10
14:41:38
上传
评论
收藏 3.98MB ZIP 举报
温馨提示
方便快捷易用的Nginx可视化UI网页管理部署配置工具系统,使用Web网页系统来快速配置部署,支持在线配置你的Nginx/Openresty的反向代理、负载均衡、SSL/HTTPS证书免费签发,自动续签、TCP/UDP 3-4层转发、可以自定义参数字段、均衡负载节点、Nginx服务状态监控故障报警、集群配置同步等,快速部署多个或N个Nginx集群节点,支持导入现有Nginx配置文件让你无忧使用.
资源推荐
资源详情
资源评论
收起资源包目录
方便快捷易用的Nginx可视化UI网页管理部署配置工具系统,使用Web网页系统来快速配置部署 (708个子文件)
README.asciidoc 9KB
nginx.conf 63B
layui.css 123KB
AllInOne.css 61KB
xterm.css 34KB
font.css 21KB
layer.css 14KB
common.css 13KB
awesome.css 8KB
laydate.css 7KB
metroStyle.css 6KB
zTreeStyle.css 6KB
zTreeStyleForApi.css 3KB
diffview.css 3KB
demo.css 2KB
code.css 1KB
common_ie6.css 1KB
base.css 783B
xt256.min.css 745B
Dockerfile 915B
.dockerignore 54B
iconfont.eot 53KB
zTreeStandard.gif 7KB
loading-0.gif 6KB
zTreeStandard.gif 5KB
metro.gif 5KB
loading-2.gif 2KB
apiMenu.gif 2KB
loading-1.gif 701B
overlay_arrow.gif 625B
overlay_close_IE6.gif 441B
loading.gif 381B
loading.gif 381B
loading.gif 381B
line_conn.gif 45B
.gitignore 378B
ServerApiController.html 84KB
CertApiController.html 77KB
api.html 76KB
UpstreamApiController.html 59KB
NginxApiController.html 44KB
ParamApiController.html 37KB
PasswordApiController.html 32KB
DenyAllowApiController.html 31KB
index.html 22KB
TokenController.html 19KB
UploadController.html 18KB
index.html 14KB
index.html 13KB
index.html 12KB
error.html 12KB
dict.html 12KB
index.html 12KB
index.html 8KB
index.html 7KB
index.html 7KB
index.html 5KB
API_cn.html 5KB
API_en.html 5KB
index.html 5KB
index.html 4KB
index.html 4KB
fn.zTree.init.html 4KB
fn.zTree.init.html 4KB
index.html 3KB
setting.check.chkStyle.html 3KB
index.html 3KB
index.html 3KB
index.html 3KB
setting.check.chkStyle.html 3KB
zTreeObj.expandNode.html 3KB
zTreeObj.addNodes.html 3KB
treeNode.getCheckStatus.html 3KB
zTreeObj.addNodes.html 3KB
treeNode.getCheckStatus.html 3KB
zTreeObj.expandNode.html 3KB
zTreeObj.setChkDisabled.html 3KB
zTreeObj.checkNode.html 3KB
zTreeObj.reAsyncChildNodes.html 3KB
setting.callback.onClick.html 3KB
zTreeObj.copyNode.html 3KB
zTreeObj.moveNode.html 3KB
setting.callback.beforeClick.html 2KB
setting.callback.onDrop.html 2KB
setting.callback.beforeDrop.html 2KB
zTreeObj.reAsyncChildNodesPromise.html 2KB
zTreeObj.reAsyncChildNodesPromise.html 2KB
zTreeObj.reAsyncChildNodes.html 2KB
zTreeObj.checkNode.html 2KB
setting.callback.onClick.html 2KB
setting.callback.beforeClick.html 2KB
setting.callback.beforeRename.html 2KB
menu.html 2KB
setting.callback.onDrop.html 2KB
zTreeObj.copyNode.html 2KB
setting.callback.beforeRename.html 2KB
zTreeObj.moveNode.html 2KB
zTreeObj.setChkDisabled.html 2KB
setting.async.autoParam.html 2KB
setting.callback.beforeDrop.html 2KB
共 708 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7451
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功