Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
cym1102 committed Nov 15, 2024
1 parent ab4c440 commit b98c941
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 336 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ Path : JDK安装目录\bin

```
Linux: mkdir /home/nginxWebUI/
wget -O /home/nginxWebUI/nginxWebUI.jar https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.4/nginxWebUI-4.2.4.jar
wget -O /home/nginxWebUI/nginxWebUI.jar https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.5/nginxWebUI-4.2.5.jar
Windows: 直接使用浏览器下载 https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.4/nginxWebUI-4.2.4.jar 到 D:/home/nginxWebUI/nginxWebUI.jar
Windows: 直接使用浏览器下载 https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.5/nginxWebUI-4.2.5.jar 到 D:/home/nginxWebUI/nginxWebUI.jar
```

有新版本只需要修改路径中的版本即可
Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ reboot

```
Linux: mkdir /home/nginxWebUI/
wget -O /home/nginxWebUI/nginxWebUI.jar https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.4/nginxWebUI-4.2.4.jar
wget -O /home/nginxWebUI/nginxWebUI.jar https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.5/nginxWebUI-4.2.5.jar
Windows: Download directly from your browser https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.4/nginxWebUI-4.2.4.jar into D:/home/nginxWebUI/
Windows: Download directly from your browser https://gitee.com/cym1102/nginxWebUI/releases/download/4.2.5/nginxWebUI-4.2.5.jar into D:/home/nginxWebUI/
```

With a new version, you just need to change the version in the path
Expand Down
18 changes: 11 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.4.5</version>
<version>3.0.3</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.cym</groupId>
<artifactId>nginxWebUI</artifactId>
<version>4.2.4</version>
<version>4.2.5</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<nginxparser.version>0.9.6</nginxparser.version>
<h2.version>2.1.214</h2.version>
<sqlite-jdbc.version>3.46.0.0</sqlite-jdbc.version>
<sqlite-jdbc.version>3.47.0.0</sqlite-jdbc.version>
<mysql.version>8.0.33</mysql.version>
<googleauth.version>1.5.0</googleauth.version>
<hutool.version>5.8.25</hutool.version>
Expand All @@ -40,16 +40,21 @@

<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.boot.undertow</artifactId>
<artifactId>solon-view-freemarker</artifactId>
</dependency>

<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.logging.logback</artifactId>
<artifactId>solon-boot-undertow</artifactId>
</dependency>

<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.scheduling.simple</artifactId>
<artifactId>solon-logging-logback</artifactId>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-scheduling-simple</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -134,7 +139,6 @@
<artifactId>expiringmap</artifactId>
<version>${expiringmap.version}</version>
</dependency>

</dependencies>

<build>
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/com/cym/NginxWebUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,7 @@ public static void main(String[] args) {
logger.error(e.getMessage(), e);
}

Solon.start(NginxWebUI.class, args, app -> {
app.onError(e -> logger.error(e.getMessage(), e));

app.before(c -> {
String path = c.path();
while (path.contains("//")) {
path = path.replace("//", "/");
}
c.pathNew(path);
});

app.onEvent(freemarker.template.Configuration.class, cfg -> {
cfg.setSetting("classic_compatible", "true");
cfg.setSetting("number_format", "0.##");
});
});
Solon.start(NginxWebUI.class, args);
}

public static void killSelf(String[] args) {
Expand Down
39 changes: 24 additions & 15 deletions src/main/java/com/cym/config/AppFilter.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
package com.cym.config;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.exception.StatusException;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;
import org.noear.solon.core.handle.UploadedFile;
import org.noear.solon.core.util.KeyValues;
import org.noear.solon.core.util.MultiMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,12 +35,10 @@
import com.cym.utils.PropertiesUtils;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

@Component
Expand All @@ -68,7 +63,22 @@ public class AppFilter implements Filter {

@Override
public void doFilter(Context ctx, FilterChain chain) throws Throwable {
//todo: 原异常处理改为正常的上抛了
try {
doFilterDo(ctx, chain);
} catch (StatusException e) {
//4xx 相关状态异常
ctx.status(e.getCode());

if (404 != e.getCode()) {
logger.error(e.getMessage(), e);
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}

private void doFilterDo(Context ctx, FilterChain chain) throws Throwable {
String path = ctx.path().toLowerCase();

// 全局过滤器
Expand Down Expand Up @@ -174,7 +184,8 @@ private boolean adminInterceptor(Context ctx) {
} else {
// 普通请求
Admin admin = new BaseController().getAdmin();
String body = buldBody(ctx.paramsMap(), remote, admin);
//todo: ctx.paramsMap() 已取消,复用 ctx.paramMap()
String body = buldBody(ctx.paramMap(), remote, admin);

httpResponse = HttpRequest.post(url).body(body).execute();
}
Expand Down Expand Up @@ -277,18 +288,16 @@ private void frontInterceptor(Context ctx) {

}

private String buldBody(Map<String, List<String>> parameterMap, Remote remote, Admin admin) throws UnsupportedEncodingException {
private String buldBody(MultiMap<String> parameterMap, Remote remote, Admin admin) throws UnsupportedEncodingException {
List<String> body = new ArrayList<>();
body.add("creditKey=" + remote.getCreditKey());
if (admin != null) {
body.add("adminName=" + admin.getName());
}

for (Iterator itr = parameterMap.entrySet().iterator(); itr.hasNext();) {
Map.Entry me = (Map.Entry) itr.next();

for (String value : (List<String>) me.getValue()) {
body.add(me.getKey() + "=" + URLEncoder.encode(value, "UTF-8"));
for (KeyValues<String> kv : parameterMap) {
for (String value : kv.getValues()) {
body.add(kv.getKey() + "=" + URLEncoder.encode(value, "UTF-8"));
}

}
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/cym/config/InitConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,16 @@ public void start() throws Throwable {
settingService.set("nginxExe", "nginx");
}

// 尝试启动nginx
// 重启nginx, 拿到pid
String nginxExe = settingService.get("nginxExe");
String nginxDir = settingService.get("nginxDir");

logger.info("nginxIsRun:" + NginxUtils.isRun());
if (!NginxUtils.isRun() && StrUtil.isNotEmpty(nginxExe) && StrUtil.isNotEmpty(nginxPath)) {
if (StrUtil.isNotEmpty(nginxExe) && StrUtil.isNotEmpty(nginxPath)) {
RuntimeUtil.execForStr("/bin/sh", "-c", "pkill -9 nginx");
String cmd = nginxExe + " -c " + nginxPath;

if (StrUtil.isNotEmpty(nginxDir)) {
cmd += " -p " + nginxDir;
}
logger.info("runCmd:" + cmd);
RuntimeUtil.execForStr("/bin/sh", "-c", cmd);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/cym/config/ViewConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cym.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.view.freemarker.FreemarkerRender;

@Configuration
public class ViewConfig {
@Bean
public void init(FreemarkerRender render) throws Exception {
//todo: 从 “app.onEvent(freemarker.template.Configuration.class, cfg->{})“ 迁移过来
render.getProvider().setSetting("classic_compatible", "true");
render.getProvider().setSetting("number_format", "0.##");

if (render.getProviderOfDebug() != null) {
render.getProviderOfDebug().setSetting("classic_compatible", "true");
render.getProviderOfDebug().setSetting("number_format", "0.##");
}
}
}
16 changes: 3 additions & 13 deletions src/main/java/com/cym/controller/adminPage/LogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.ModelAndView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -84,17 +81,10 @@ public ModelAndView tail(ModelAndView modelAndView, String id, String protocol)
}

@Mapping("down")
public void down(ModelAndView modelAndView, String id) throws IOException {
public File down(String id) throws IOException {
Log log = sqlHelper.findById(id, Log.class);
File file = new File(log.getPath());

Context.current().contentType("application/octet-stream");
String headerKey = "Content-Disposition";
String headerValue = "attachment; filename=" + URLUtil.encode(file.getName());
Context.current().header(headerKey, headerValue);

InputStream inputStream = Files.newInputStream(file.toPath());
Context.current().output(inputStream);
//todo: 简化下载处理
return new File(log.getPath());
}

@Mapping("tailCmd")
Expand Down
57 changes: 50 additions & 7 deletions src/main/java/com/cym/service/ServerService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.cym.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;

import cn.hutool.json.JSONArray;
//import com.alibaba.fastjson.JSONObject;
import cn.hutool.json.JSONObject;
import com.beust.jcommander.internal.Lists;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.slf4j.Logger;
Expand Down Expand Up @@ -235,10 +236,13 @@ public void importServer(String nginxPath) throws Exception {
// 设置location
List<Location> locations = new ArrayList<>();
List<NgxEntry> locationBlocks = serverNgx.findAll(NgxBlock.class, "location");
NgxBlock locationBlockTemp;
for (NgxEntry item : locationBlocks) {
Location location = new Location();
// 目前只支持http段的 proxy_pass
NgxParam proxyPassParam = ((NgxBlock) item).findParam("proxy_pass");
locationBlockTemp = (NgxBlock) item;

NgxParam proxyPassParam = locationBlockTemp.findParam("proxy_pass");

location.setPath(((NgxBlock) item).getValue());
// 如果没有proxy_pass type 0,说明可能是静态文件夹映射 type 1
Expand All @@ -264,19 +268,58 @@ public void importServer(String nginxPath) throws Exception {

location.setType(1);
}
location.setLocationParamJson(null);
location.setLocationParamJson(getParamJsonFromLocationBlock(locationBlockTemp));
location.setHeader(0);
locations.add(location);
}

server.setDef(0);
server.setSeq(SnowFlakeUtils.getId());
addOver(server, "", locations);
}


// 删除临时文件
FileUtil.del(initNginxPath);
}


private String getParamJsonFromLocationBlock(NgxBlock locationBlock){

List<String> proxyConfigList = Lists.newArrayList("proxy_http_version", "proxy_redirect",
"proxy_set_header", "proxy_cache", "proxy_cache_valid", "proxy_cache_key", "proxy_connect_timeout",
"proxy_read_timeout", "proxy_send_timeout", "proxy_buffer_size", "proxy_buffers",
"proxy_busy_buffers_size", "proxy_cookie_path","proxy_intercept_errors","proxy_request_buffering",
"proxy_buffering",
"proxy_ignore_client_abort","expires","add_header","client_max_body_size"
);

Collection<NgxEntry> entries = locationBlock.getEntries();
List<NgxEntry> paramsTemp;
JSONObject paramJsonTemp = null;
JSONArray paramJsonArray = new JSONArray();
NgxParam ngxParamTemp;
for (String proxyConfig : proxyConfigList) {
paramsTemp = locationBlock.findAll(NgxParam.class,proxyConfig);
if (paramsTemp != null && !paramsTemp.isEmpty()){

for (NgxEntry paramEntry : paramsTemp) {
ngxParamTemp = (NgxParam) paramEntry;
ngxParamTemp.getName();
paramJsonTemp = new JSONObject();
paramJsonTemp.put("name",ngxParamTemp.getName());
paramJsonTemp.put("value",ngxParamTemp.getValue());
paramJsonArray.add(paramJsonTemp);
}
}

}
if (!paramJsonArray.isEmpty()){
return paramJsonArray.toString();
}else {
return null;
}

}
/**
* 重新创建配置文件,删除影响解析的行(比如#号开头,但是此行没有其他内容)
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/lib/layui/css/layui.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/main/resources/static/lib/layui/css/modules/code.css

This file was deleted.

Loading

0 comments on commit b98c941

Please sign in to comment.