forked from KNEMC/KLALB
✨ feat(web): integrate embedded web server, REST/SSE APIs and modernize configuration
- Add embedded KLALBWebServer with REST API, SSE streaming (200ms) and SPA hosting - Introduce enableTUN configuration flag with fallback and non-admin execution support - Refactor LineTable and ConnectLineTable to openConnections and autoConnections - Rename denyLineTableQuery/Broadcast to denyConnectionQuery/Broadcast with backwards compatibility - Support runtime config hot-reloading and automatic persistence to klalb-config.json - Update default Web API port to 4665 and update dashboard submodule reference
This commit is contained in:
@@ -52,6 +52,13 @@ public class KLALBMain {
|
||||
}catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if(kpcje.getControllerConfig() != null && kpcje.getControllerConfig().isWebUI()) {
|
||||
kpcje.enableWebServer();
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
System.err.println("Failed to start web server: " + e.getMessage());
|
||||
}
|
||||
dtb.putTime("UI");
|
||||
//dtb.print();
|
||||
/*MultipurposeSocketAddress mpa=new MultipurposeSocketAddress("127.9.9.9", 49573);
|
||||
@@ -84,6 +91,7 @@ public class KLALBMain {
|
||||
case "help":
|
||||
System.out.println(" help / ?: see help");
|
||||
System.out.println(" monitor: show monitor GUI");
|
||||
System.out.println(" web [start|stop|status <port>]: manage web dashboard");
|
||||
System.out.println(" links-state: query link states");
|
||||
System.out.println(" links-add <addr:port>: add link");
|
||||
System.out.println(" links-remove <addr:port>: remove link");
|
||||
@@ -102,6 +110,42 @@ public class KLALBMain {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case "web":
|
||||
if(sc.length >= 2) {
|
||||
String action = sc[1].toLowerCase();
|
||||
if("start".equals(action)) {
|
||||
int p = 4665;
|
||||
if(sc.length >= 3) {
|
||||
try { p = Integer.parseInt(sc[2]); } catch (NumberFormatException ignored) {}
|
||||
} else if(kpcje.getControllerConfig() != null && kpcje.getControllerConfig().getWebPort() > 0) {
|
||||
p = kpcje.getControllerConfig().getWebPort();
|
||||
}
|
||||
try {
|
||||
kpcje.enableWebServer(p);
|
||||
System.out.println("Web dashboard started on http://localhost:" + p);
|
||||
} catch(Exception e) {
|
||||
System.out.println("Failed to start web server: " + e.getMessage());
|
||||
}
|
||||
} else if("stop".equals(action)) {
|
||||
kpcje.disableWebServer();
|
||||
System.out.println("Web dashboard stopped.");
|
||||
} else if("status".equals(action)) {
|
||||
if(kpcje.isWebServerEnabled()) {
|
||||
System.out.println("Web dashboard is running on port " + kpcje.getWebServer().getPort());
|
||||
} else {
|
||||
System.out.println("Web dashboard is stopped.");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Usage: web [start|stop|status <port>]");
|
||||
}
|
||||
} else {
|
||||
if(kpcje.isWebServerEnabled()) {
|
||||
System.out.println("Web dashboard is running on port " + kpcje.getWebServer().getPort());
|
||||
} else {
|
||||
System.out.println("Web dashboard is not running. Use 'web start [port]' to start.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "links-state":
|
||||
System.out.println("links state:");
|
||||
//System.out.println("状态\t上传流量\t下载流量\t上传速度\t下载速度\t上传延迟\t下载延迟\t上传抖动\t下载抖动");
|
||||
|
||||
Reference in New Issue
Block a user