Added inbound hostname edit function

- Added inbound hostname edit function
- Removed all "proxy root" and replaced with "default site"
This commit is contained in:
Toby Chui 2025-06-12 20:53:06 +08:00
parent 6d0c0be8c2
commit 31ba4f20ae
5 changed files with 141 additions and 7 deletions

View File

@ -34,6 +34,7 @@ func RegisterHTTPProxyAPIs(authRouter *auth.RouterDef) {
authRouter.HandleFunc("/api/proxy/detail", ReverseProxyListDetail)
authRouter.HandleFunc("/api/proxy/edit", ReverseProxyHandleEditEndpoint)
authRouter.HandleFunc("/api/proxy/setAlias", ReverseProxyHandleAlias)
authRouter.HandleFunc("/api/proxy/setHostname", ReverseProxyHandleSetHostname)
authRouter.HandleFunc("/api/proxy/del", DeleteProxyEndpoint)
authRouter.HandleFunc("/api/proxy/updateCredentials", UpdateProxyBasicAuthCredentials)
authRouter.HandleFunc("/api/proxy/tlscheck", domainsniff.HandleCheckSiteSupportTLS)

View File

@ -673,6 +673,83 @@ func ReverseProxyHandleAlias(w http.ResponseWriter, r *http.Request) {
utils.SendOK(w)
}
func ReverseProxyHandleSetHostname(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
utils.SendErrorResponse(w, "Method not supported")
return
}
originalRootnameOrMatchingDomain, err := utils.PostPara(r, "oldHostname")
if err != nil {
utils.SendErrorResponse(w, "Invalid original hostname given")
return
}
newHostname, err := utils.PostPara(r, "newHostname")
if err != nil {
utils.SendErrorResponse(w, "Invalid new hostname given")
return
}
originalRootnameOrMatchingDomain = strings.TrimSpace(originalRootnameOrMatchingDomain)
newHostname = strings.TrimSpace(newHostname)
if newHostname == "/" {
//Reserevd, reutrn error
utils.SendErrorResponse(w, "Invalid new hostname: system reserved path")
return
}
//Check if the endpoint already exists
_, err = dynamicProxyRouter.LoadProxy(newHostname)
if err == nil {
//Endpoint already exists, return error
utils.SendErrorResponse(w, "Endpoint with this hostname already exists")
return
}
//Clone, edit the endpoint and remove the original one
ept, err := dynamicProxyRouter.LoadProxy(originalRootnameOrMatchingDomain)
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
newEndpoint := ept.Clone()
newEndpoint.RootOrMatchingDomain = newHostname
//Prepare to replace the current routing rule
readyRoutingRule, err := dynamicProxyRouter.PrepareProxyRoute(newEndpoint)
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
//Remove the old endpoint from runtime
err = dynamicProxyRouter.RemoveProxyEndpointByRootname(originalRootnameOrMatchingDomain)
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
//Remove the config from file
err = RemoveReverseProxyConfig(originalRootnameOrMatchingDomain)
if err != nil {
utils.SendErrorResponse(w, err.Error())
return
}
//Add the new endpoint to runtime
dynamicProxyRouter.AddProxyRouteToRuntime(readyRoutingRule)
//Save it to file
SaveReverseProxyConfig(newEndpoint)
//Update uptime monitor targets
UpdateUptimeMonitorTargets()
utils.SendOK(w)
}
func DeleteProxyEndpoint(w http.ResponseWriter, r *http.Request) {
ep, err := utils.PostPara(r, "ep")
if err != nil {

View File

@ -259,9 +259,21 @@
<!-- Downstream -->
<div class="rpconfig_content" rpcfg="downstream">
<div class="ui segment">
<h3 class="downstream_primary_hostname">
<h3>
<button class="ui right floated small icon circular basic button downstream_primary_hostname_edit_btn">
<i class="ui edit icon"></i>
</button>
<span class="downstream_primary_hostname"></span>
</h3>
<div class="ui action small fluid input downstream_primary_hostname_edit_input" style="margin-bottom: 0.4em;">
<input type="text" placeholder="new.example.com">
<button class="ui green basic icon button saveDownstreamHostnameBtn">
<i class="ui save icon"></i>
</button>
<button class="ui basic icon button cancelDownstreamHostnameBtn">
<i class="times icon"></i>
</button>
</div>
<div class="downstream_alias_hostname">
</div>
@ -324,7 +336,8 @@
<!-- TLS / SSL -->
<div class="rpconfig_content" rpcfg="ssl">
<div class="ui segment">
<p>Work In Progress </p>
<p>Work In Progress <br>
Please use the outer-most menu TLS / SSL tab for now. </p>
<br>
<button class="ui basic small button getCertificateBtn" style="margin-left: 0.4em; margin-top: 0.4em;"><i class="green lock icon"></i> Get Certificate</button>
</div>
@ -1020,6 +1033,50 @@
saveProxyInlineEdit(uuid);
});
//Bind the edit button
editor.find(".downstream_primary_hostname_edit_btn").off("click").on("click", function(){
editor.find(".downstream_primary_hostname_edit_btn").parent().hide();
editor.find(".downstream_primary_hostname_edit_input input").val(subd.RootOrMatchingDomain)
editor.find(".downstream_primary_hostname_edit_input").show();
});
editor.find(".cancelDownstreamHostnameBtn").off("click").on("click", function(){
editor.find(".downstream_primary_hostname_edit_input").hide();
editor.find(".downstream_primary_hostname_edit_btn").parent().show();
});
editor.find(".saveDownstreamHostnameBtn").off("click").on("click", function(){
let newHostname = editor.find(".downstream_primary_hostname_edit_input input").val().trim();
if (newHostname.length == 0){
msgbox("Hostname cannot be empty", false);
return;
}
if (newHostname == subd.RootOrMatchingDomain){
//No need to update
editor.find(".downstream_primary_hostname_edit_input").hide();
editor.find(".downstream_primary_hostname_edit_btn").parent().show();
return;
}
$.cjax({
url: "/api/proxy/setHostname",
method: "POST",
data: {
"oldHostname":subd.RootOrMatchingDomain,
"newHostname":newHostname,
},
success: function(data){
if (data.error != undefined){
msgbox(data.error, false);
}else{
//Update the current editing hostname to DOM
$("#httprpEditModal").attr("editing-host", encodeURIComponent(newHostname));
//Grab the new hostname from server
resyncProxyEditorConfig();
}
}
});
});
editor.find(".downstream_primary_hostname_edit_input").hide();
editor.find(".downstream_primary_hostname_edit_btn").parent().show();
//Build the alias hostname list
let aliasHTML = "";

View File

@ -1,7 +1,7 @@
<div class="standardContainer">
<div class="ui basic segment">
<h2>Default Site</h2>
<p>Default routing options for inbound traffic (previously called Proxy Root)</p>
<p>Default routing options for inbound traffic</p>
<div class="ui form">
<div class="grouped fields">
<label>What to show when Zoraxy is hit with an unknown Host?</label>
@ -209,14 +209,13 @@
})
}
//Set the new proxy root option
//Set the new proxy root (aka default site) option
function setProxyRoot(btn=undefined){
var newpr = $("#proxyRoot").val();
if (newpr.trim() == "" && currentDefaultSiteOption == 0){
//Fill in the web server info
newpr = "127.0.0.1:" + $("#webserv_listenPort").val();
$("#proxyRoot").val(newpr);
}
var rootReqTls = $("#rootReqTLS")[0].checked;

View File

@ -120,7 +120,7 @@
<!-- Create Rules -->
<div id="rules" class="functiontab" target="rules.html"></div>
<!-- Set proxy root -->
<!-- Set default site -->
<div id="setroot" class="functiontab" target="rproot.html"></div>
<!-- Set TLS cert -->