mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-03 06:07:20 +02:00
Added new UI feature
- Added toggle for uptime monitor - Added toggle for enable custom header passthrough to websocket
This commit is contained in:
parent
0b1768ab5b
commit
30dfb9cb65
@ -59,6 +59,7 @@ func RegisterHTTPProxyAPIs(authRouter *auth.RouterDef) {
|
|||||||
authRouter.HandleFunc("/api/proxy/header/handleHopByHop", HandleHopByHop)
|
authRouter.HandleFunc("/api/proxy/header/handleHopByHop", HandleHopByHop)
|
||||||
authRouter.HandleFunc("/api/proxy/header/handleHostOverwrite", HandleHostOverwrite)
|
authRouter.HandleFunc("/api/proxy/header/handleHostOverwrite", HandleHostOverwrite)
|
||||||
authRouter.HandleFunc("/api/proxy/header/handlePermissionPolicy", HandlePermissionPolicy)
|
authRouter.HandleFunc("/api/proxy/header/handlePermissionPolicy", HandlePermissionPolicy)
|
||||||
|
authRouter.HandleFunc("/api/proxy/header/handleWsHeaderBehavior", HandleWsHeaderBehavior)
|
||||||
/* Reverse proxy auth related */
|
/* Reverse proxy auth related */
|
||||||
authRouter.HandleFunc("/api/proxy/auth/exceptions/list", ListProxyBasicAuthExceptionPaths)
|
authRouter.HandleFunc("/api/proxy/auth/exceptions/list", ListProxyBasicAuthExceptionPaths)
|
||||||
authRouter.HandleFunc("/api/proxy/auth/exceptions/add", AddProxyBasicAuthExceptionPaths)
|
authRouter.HandleFunc("/api/proxy/auth/exceptions/add", AddProxyBasicAuthExceptionPaths)
|
||||||
|
@ -42,7 +42,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
/* Build Constants */
|
/* Build Constants */
|
||||||
SYSTEM_NAME = "Zoraxy"
|
SYSTEM_NAME = "Zoraxy"
|
||||||
SYSTEM_VERSION = "3.1.5"
|
SYSTEM_VERSION = "3.1.6"
|
||||||
DEVELOPMENT_BUILD = false /* Development: Set to false to use embedded web fs */
|
DEVELOPMENT_BUILD = false /* Development: Set to false to use embedded web fs */
|
||||||
|
|
||||||
/* System Constants */
|
/* System Constants */
|
||||||
|
@ -467,6 +467,12 @@ func ReverseProxyHandleEditEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
bypassGlobalTLS := (bpgtls == "true")
|
bypassGlobalTLS := (bpgtls == "true")
|
||||||
|
|
||||||
|
//Disable uptime monitor
|
||||||
|
disbleUtm, err := utils.PostBool(r, "dutm")
|
||||||
|
if err != nil {
|
||||||
|
disbleUtm = false
|
||||||
|
}
|
||||||
|
|
||||||
// Auth Provider
|
// Auth Provider
|
||||||
authProviderTypeStr, _ := utils.PostPara(r, "authprovider")
|
authProviderTypeStr, _ := utils.PostPara(r, "authprovider")
|
||||||
if authProviderTypeStr == "" {
|
if authProviderTypeStr == "" {
|
||||||
@ -532,6 +538,7 @@ func ReverseProxyHandleEditEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||||||
newProxyEndpoint.RequireRateLimit = requireRateLimit
|
newProxyEndpoint.RequireRateLimit = requireRateLimit
|
||||||
newProxyEndpoint.RateLimit = proxyRateLimit
|
newProxyEndpoint.RateLimit = proxyRateLimit
|
||||||
newProxyEndpoint.UseStickySession = useStickySession
|
newProxyEndpoint.UseStickySession = useStickySession
|
||||||
|
newProxyEndpoint.DisableUptimeMonitor = disbleUtm
|
||||||
|
|
||||||
//Prepare to replace the current routing rule
|
//Prepare to replace the current routing rule
|
||||||
readyRoutingRule, err := dynamicProxyRouter.PrepareProxyRoute(newProxyEndpoint)
|
readyRoutingRule, err := dynamicProxyRouter.PrepareProxyRoute(newProxyEndpoint)
|
||||||
@ -1553,3 +1560,39 @@ func HandlePermissionPolicy(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
http.Error(w, "405 - Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "405 - Method not allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandleWsHeaderBehavior(w http.ResponseWriter, r *http.Request) {
|
||||||
|
domain, err := utils.PostPara(r, "domain")
|
||||||
|
if err != nil {
|
||||||
|
domain, err = utils.GetPara(r, "domain")
|
||||||
|
if err != nil {
|
||||||
|
utils.SendErrorResponse(w, "domain or matching rule not defined")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targetProxyEndpoint, err := dynamicProxyRouter.LoadProxy(domain)
|
||||||
|
if err != nil {
|
||||||
|
utils.SendErrorResponse(w, "target endpoint not exists")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == http.MethodGet {
|
||||||
|
js, _ := json.Marshal(targetProxyEndpoint.EnableWebsocketCustomHeaders)
|
||||||
|
utils.SendJSONResponse(w, string(js))
|
||||||
|
} else if r.Method == http.MethodPost {
|
||||||
|
enableWsHeader, err := utils.PostBool(r, "enable")
|
||||||
|
if err != nil {
|
||||||
|
utils.SendErrorResponse(w, "invalid enable state given")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
targetProxyEndpoint.EnableWebsocketCustomHeaders = enableWsHeader
|
||||||
|
SaveReverseProxyConfig(targetProxyEndpoint)
|
||||||
|
targetProxyEndpoint.UpdateToRuntime()
|
||||||
|
utils.SendOK(w)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
http.Error(w, "405 - Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -258,6 +258,13 @@
|
|||||||
if (payload.UseStickySession){
|
if (payload.UseStickySession){
|
||||||
useStickySessionChecked = "checked";
|
useStickySessionChecked = "checked";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let enableUptimeMonitor = "";
|
||||||
|
//Note the config file store the uptime monitor as disable, so we need to reverse the logic
|
||||||
|
if (!payload.DisableUptimeMonitor){
|
||||||
|
enableUptimeMonitor = "checked";
|
||||||
|
}
|
||||||
|
|
||||||
input = `<button class="ui basic compact tiny button" style="margin-left: 0.4em; margin-top: 1em;" onclick="editUpstreams('${uuid}');"><i class="grey server icon"></i> Edit Upstreams</button>
|
input = `<button class="ui basic compact tiny button" style="margin-left: 0.4em; margin-top: 1em;" onclick="editUpstreams('${uuid}');"><i class="grey server icon"></i> Edit Upstreams</button>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<div class="ui checkbox" style="margin-top: 0.4em;">
|
<div class="ui checkbox" style="margin-top: 0.4em;">
|
||||||
@ -265,7 +272,11 @@
|
|||||||
<label>Use Sticky Session<br>
|
<label>Use Sticky Session<br>
|
||||||
<small>Enable stick session on load balancing</small></label>
|
<small>Enable stick session on load balancing</small></label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ui checkbox" style="margin-top: 0.4em;">
|
||||||
|
<input type="checkbox" class="EnableUptimeMonitor" ${enableUptimeMonitor}>
|
||||||
|
<label>Monitor Uptime<br>
|
||||||
|
<small>Enable active uptime monitor</small></label>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
column.append(input);
|
column.append(input);
|
||||||
$(column).find(".upstreamList").addClass("editing");
|
$(column).find(".upstreamList").addClass("editing");
|
||||||
@ -441,6 +452,7 @@
|
|||||||
|
|
||||||
var epttype = "host";
|
var epttype = "host";
|
||||||
let useStickySession = $(row).find(".UseStickySession")[0].checked;
|
let useStickySession = $(row).find(".UseStickySession")[0].checked;
|
||||||
|
let DisableUptimeMonitor = !$(row).find(".EnableUptimeMonitor")[0].checked;
|
||||||
let authProviderType = $(row).find(".authProviderPicker input[type='radio']:checked").val();
|
let authProviderType = $(row).find(".authProviderPicker input[type='radio']:checked").val();
|
||||||
let requireRateLimit = $(row).find(".RequireRateLimit")[0].checked;
|
let requireRateLimit = $(row).find(".RequireRateLimit")[0].checked;
|
||||||
let rateLimit = $(row).find(".RateLimit").val();
|
let rateLimit = $(row).find(".RateLimit").val();
|
||||||
@ -453,6 +465,7 @@
|
|||||||
"type": epttype,
|
"type": epttype,
|
||||||
"rootname": uuid,
|
"rootname": uuid,
|
||||||
"ss":useStickySession,
|
"ss":useStickySession,
|
||||||
|
"dutm": DisableUptimeMonitor,
|
||||||
"bpgtls": bypassGlobalTLS,
|
"bpgtls": bypassGlobalTLS,
|
||||||
"authprovider" :authProviderType,
|
"authprovider" :authProviderType,
|
||||||
"rate" :requireRateLimit,
|
"rate" :requireRateLimit,
|
||||||
|
@ -117,6 +117,16 @@
|
|||||||
<label>Remove Hop-by-hop Header<br>
|
<label>Remove Hop-by-hop Header<br>
|
||||||
<small>This should be ON by default</small></label>
|
<small>This should be ON by default</small></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<h4> WebSocket Custom Headers</h4>
|
||||||
|
<p>Copy custom headers from HTTP requests to WebSocket connections.
|
||||||
|
Might be required by some projects like MeshCentral.</p>
|
||||||
|
<div class="ui toggle checkbox">
|
||||||
|
<input type="checkbox" id="copyCustomHeadersWS" name="">
|
||||||
|
<label>Enable WebSocket Custom Header<br>
|
||||||
|
<small>This should be OFF by default</small></label>
|
||||||
|
</div>
|
||||||
<div class="ui yellow message">
|
<div class="ui yellow message">
|
||||||
<p><i class="exclamation triangle icon"></i>Settings in this section are for advanced users. Invalid settings might cause werid, unexpected behavior.</p>
|
<p><i class="exclamation triangle icon"></i>Settings in this section are for advanced users. Invalid settings might cause werid, unexpected behavior.</p>
|
||||||
</div>
|
</div>
|
||||||
@ -597,6 +607,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Manual Hostname overwrite */
|
||||||
function initManualHostOverwriteValue(){
|
function initManualHostOverwriteValue(){
|
||||||
$.get("/api/proxy/header/handleHostOverwrite?domain=" + editingEndpoint.ep, function(data){
|
$.get("/api/proxy/header/handleHostOverwrite?domain=" + editingEndpoint.ep, function(data){
|
||||||
if (data.error != undefined){
|
if (data.error != undefined){
|
||||||
@ -643,6 +654,42 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
initHopByHopRemoverState();
|
initHopByHopRemoverState();
|
||||||
|
|
||||||
|
/* WebSocket Custom Headers */
|
||||||
|
function initWebSocketCustomHeaderState(){
|
||||||
|
$.get("/api/proxy/header/handleWsHeaderBehavior?domain=" + editingEndpoint.ep, function(data){
|
||||||
|
if (data.error != undefined){
|
||||||
|
parent.msgbox(data.error);
|
||||||
|
}else{
|
||||||
|
if (data == true){
|
||||||
|
$("#copyCustomHeadersWS").parent().checkbox("set checked");
|
||||||
|
}else{
|
||||||
|
$("#copyCustomHeadersWS").parent().checkbox("set unchecked");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Bind event to the checkbox
|
||||||
|
$("#copyCustomHeadersWS").on("change", function(evt){
|
||||||
|
let isChecked = $(this)[0].checked;
|
||||||
|
$.cjax({
|
||||||
|
url: "/api/proxy/header/handleWsHeaderBehavior",
|
||||||
|
method: "POST",
|
||||||
|
data: {
|
||||||
|
"domain": editingEndpoint.ep,
|
||||||
|
"enable": isChecked,
|
||||||
|
},
|
||||||
|
success: function(data){
|
||||||
|
if (data.error != undefined){
|
||||||
|
parent.msgbox(data.error, false);
|
||||||
|
}else{
|
||||||
|
parent.msgbox("WebSocket Custom Header rule updated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
initWebSocketCustomHeaderState();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user