Merge pull request #485 from uu1101/uriprefix

Allow serving the web interface under a subpath
Fix #480
Fix #138
This commit is contained in:
Alexey Sokolov
2014-02-17 00:44:37 +00:00
32 changed files with 175 additions and 82 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
<? INC Header.tmpl ?>
<? IF Cert ?>
<p>You already have a certificate set, use the form below to overwrite the current certificate. Alternatively click <a href="<? VAR ModPath ?>delete">here</a> to <a href="<? VAR ModPath ?>delete">delete</a> your certificate.</p>
<p>You already have a certificate set, use the form below to overwrite the current certificate. Alternatively click <a href="<? VAR URIPrefix TOP ?><? VAR ModPath ?>delete">here</a> to <a href="<? VAR URIPrefix TOP ?><? VAR ModPath ?>delete">delete</a> your certificate.</p>
<? ELSE ?>
<p>You do not have a cert.</p>
<? ENDIF ?>
<form method="post" action="<? VAR ModPath ?>update">
<form method="post" action="<? VAR URIPrefix TOP ?><? VAR ModPath ?>update">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Certificate</h3>
+1 -1
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="<? VAR ModPath ?>add">
<form method="post" action="<? VAR URIPrefix TOP ?><? VAR ModPath ?>add">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Add A Note</h3>
+2 -2
View File
@@ -17,8 +17,8 @@
<td><? VAR LastSeen DEFAULT="- unknown -" ?></td>
<td><? VAR Info ?></td>
<? IF WebAdminLoaded TOP ?><td><span class="nowrap">
[<a href="/mods/global/webadmin/edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
<? IF !IsSelf ?>[<a href="/mods/global/webadmin/deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
[<a href="<? VAR URIPrefix TOP ?>/mods/global/webadmin/edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
<? IF !IsSelf ?>[<a href="<? VAR URIPrefix TOP ?>/mods/global/webadmin/deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
</span></td><? ENDIF ?>
</tr>
<? ENDLOOP ?>
+2 -2
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="<? VAR ModPath ?>addnote">
<form method="post" action="<? VAR URIPrefix TOP ?><? VAR ModPath ?>addnote">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Add A Note</h3>
@@ -37,7 +37,7 @@
<tbody>
<? LOOP NotesLoop ?>
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
<td><a href="<? VAR ModPath TOP ?>delnote?key=<? VAR Key ESC=URL,HTML ?>"><img src="<? VAR ModFilesPath TOP ?>trash.gif" alt="[del]" /></a></td>
<td><a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>delnote?key=<? VAR Key ESC=URL,HTML ?>"><img src="<? VAR URIPrefix TOP ?><? VAR ModFilesPath TOP ?>trash.gif" alt="[del]" /></a></td>
<td><? VAR Key ?></td>
<td><? VAR Note ?></td>
</tr>
+1 -1
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form method="post" action="<? VAR ModPath ?>">
<form method="post" action="<? VAR URIPrefix TOP ?><? VAR ModPath ?>">
<? INC _csrf_check.tmpl ?>
<div class="section">
<h3>Perform</h3>
+1 -1
View File
@@ -1,7 +1,7 @@
<? ADDROW JSLoop HREF=/modfiles/user/send_raw/select.js ?>
<? INC Header.tmpl ?>
<form method="post" action="<? VAR ModPath ?>">
<form method="post" action="<? VAR URIPrefix TOP ?><? VAR ModPath ?>">
<? INC _csrf_check.tmpl ?>
<div class="section">
+1 -1
View File
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form action="" method="post">
<form method="post" action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>">
<? INC _csrf_check.tmpl ?>
<table class="data">
<thead>
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form action="<? IF Edit ?>editchan<? ELSE ?>addchan<? ENDIF ?>" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?><? IF Edit ?>editchan<? ELSE ?>addchan<? ENDIF ?>" method="post">
<? INC _csrf_check.tmpl ?>
<div class="section">
<input type="hidden" name="submitted" value="1" />
@@ -5,7 +5,7 @@
<p>To connect to this network from your IRC client, you can set the server password field as follows: <code><? VAR Username ?>/<? IF Edit ?><? VAR Name ?><? ELSE ?>&lt;network&gt;<? ENDIF ?>:&lt;password&gt;</code> or username field as <code><? VAR Username ?>/<? IF Edit ?><? VAR Name ?><? ELSE ?>&lt;network&gt;<? ENDIF ?></code></p>
</div>
<form action="<? IF Edit ?>editnetwork<? ELSE ?>addnetwork<? ENDIF ?>" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?><? IF Edit ?>editnetwork<? ELSE ?>addnetwork<? ENDIF ?>" method="post">
<? INC _csrf_check.tmpl ?>
<div class="section">
<input type="hidden" name="submitted" value="1" />
@@ -116,7 +116,7 @@
<table>
<thead>
<tr>
<td>[<a href="addchan?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Name ESC=URL ?>">Add</a>]</td>
<td>[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>addchan?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Name ESC=URL ?>">Add</a>]</td>
<? IF ChannelLoop ?>
<td>Save</td>
<td>Name</td>
@@ -135,7 +135,7 @@
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
<td>
<input type="hidden" name="channel" value="<? VAR Name ?>" />
[<a href="editchan?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Network ESC=URL ?>&amp;name=<? VAR Name ESC=URL ?>">Edit</a>] [<a href="delchan?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Network ESC=URL ?>&amp;name=<? VAR Name ESC=URL ?>">Del</a>]
[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>editchan?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Network ESC=URL ?>&amp;name=<? VAR Name ESC=URL ?>">Edit</a>] [<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>delchan?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Network ESC=URL ?>&amp;name=<? VAR Name ESC=URL ?>">Del</a>]
</td>
<td><input type="checkbox" name="save_<? VAR Name ?>"<? IF InConfig ?> checked="checked"<? ENDIF ?> /></td>
<td><? VAR Name ?></td>
@@ -1,6 +1,6 @@
<? INC Header.tmpl ?>
<form action="<? IF Edit ?>edituser<? ELSE ?>adduser<? ENDIF ?>" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?><? IF Edit ?>edituser<? ELSE ?>adduser<? ENDIF ?>" method="post">
<? INC _csrf_check.tmpl ?>
<div class="section">
<input type="hidden" name="submitted" value="1" />
@@ -128,7 +128,7 @@
<table>
<thead>
<tr>
<td>[<a href="addnetwork?user=<? VAR Username ESC=URL ?>">Add</a>]</td>
<td>[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>addnetwork?user=<? VAR Username ESC=URL ?>">Add</a>]</td>
<? IF NetworkLoop ?>
<td>Name</td>
<td>Clients</td>
@@ -145,7 +145,7 @@
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
<td>
<input type="hidden" name="network" value="<? VAR Name ?>" />
[<a href="editnetwork?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Name ESC=URL ?>">Edit</a>] [<a href="delnetwork?user=<? VAR Username ESC=URL ?>&amp;name=<? VAR Name ESC=URL ?>">Del</a>]
[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>editnetwork?user=<? VAR Username ESC=URL ?>&amp;network=<? VAR Name ESC=URL ?>">Edit</a>] [<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>delnetwork?user=<? VAR Username ESC=URL ?>&amp;name=<? VAR Name ESC=URL ?>">Del</a>]
</td>
<td><? VAR Name ?></td>
<td><? VAR Clients ?></td>
+2 -2
View File
@@ -6,13 +6,13 @@
<div class="sectionbody">
<div class="subsection">
Are you sure you want to delete "<? VAR Username ?>/<? VAR Network ?>"?
<form action="delnetwork" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>delnetwork" method="post">
<? INC _csrf_check.tmpl ?>
<input type="hidden" name="user" value="<? VAR Username ?>" />
<input type="hidden" name="name" value="<? VAR Network ?>" />
<div class="yesnobutton"><input type="submit" value="Yes" /></div>
</form>
<form action="listusers" method="get">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>listusers" method="get">
<div class="yesnobutton"><input type="submit" value="No" /></div>
</form>
</div>
+2 -2
View File
@@ -6,13 +6,13 @@
<div class="sectionbody">
<div class="subsection">
Are you sure you want to delete "<? VAR Username ?>"?
<form action="deluser" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>deluser" method="post">
<? INC _csrf_check.tmpl ?>
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="user" value="<? VAR Username ?>" />
<div class="yesnobutton"><input type="submit" value="Yes" /></div>
</form>
<form action="listusers" method="get">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>listusers" method="get">
<div class="yesnobutton"><input type="submit" value="No" /></div>
</form>
</div>
+4 -4
View File
@@ -2,7 +2,7 @@
<?IF !UserLoop?>
<div class="textsection">
There are no users defined. Click <a href="adduser">here</a> if you would like to add one.
There are no users defined. Click <a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>adduser">here</a> if you would like to add one.
</div>
<?ELSE?>
<div class="toptable">
@@ -21,9 +21,9 @@
<tr class="<?IF __EVEN__?>evenrow<?ELSE?>oddrow<?ENDIF?>">
<td>
<span class="nowrap">
[<a href="edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
[<a href="adduser?clone=<? VAR Username ESC=URL ?>" alt="Clone <? VAR Username ESC=URL ?>">Clone</a>]
<? IF !IsSelf ?>[<a href="deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>edituser?user=<?VAR Username ESC=URL?>">Edit</a>]
[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>adduser?clone=<? VAR Username ESC=URL ?>" alt="Clone <? VAR Username ESC=URL ?>">Clone</a>]
<? IF !IsSelf ?>[<a href="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>deluser?user=<?VAR Username ESC=URL?>">Delete</a>]<? ENDIF ?>
</span>
</td>
<td><? VAR Username ?></td>
+7 -4
View File
@@ -16,6 +16,7 @@
<td>IPv6</td>
<td>IRC</td>
<td>Web</td>
<td>URIPrefix</td>
</tr>
</thead>
@@ -38,9 +39,10 @@
<td>
<div class="checkbox"><input type="checkbox" disabled="disabled" <? IF IsWeb ?>checked="checked"<? ENDIF ?>/></div>
</td>
<td><? VAR URIPrefix ?></td>
<td>
<? IF SuggestDeletion ?>
<form action="del_listener" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>del_listener" method="post">
<? INC _csrf_check.tmpl ?>
<input name="host" type="hidden" value="<? VAR BindHost ?>"/>
<input name="port" type="hidden" value="<? VAR Port ?>"/>
@@ -53,15 +55,16 @@
</tr>
<? ENDLOOP ?>
<tr>
<form action="add_listener" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>add_listener" method="post">
<? INC _csrf_check.tmpl ?>
<td><input name="port" type="number" min="1" max="65535" class="number"/></td>
<td><input name="host" type="text" value="*" class="third"/></td>
<td><input name="host" type="text" value="*" class="sixth"/></td>
<td><div class="checkbox"><input name="ssl" type="checkbox"/></div></td>
<td><div class="checkbox"><input name="ipv4" type="checkbox" checked="checked"/></div></td>
<td><div class="checkbox"><input name="ipv6" type="checkbox" checked="checked"/></div></td>
<td><div class="checkbox"><input name="irc" type="checkbox" checked="checked"/></div></td>
<td><div class="checkbox"><input name="web" type="checkbox" checked="checked"/></div></td>
<td><input name="uriprefix" type="text" value="" class="sixth"/></td>
<td><input type="submit" value="Add"/></td>
</form>
</tr>
@@ -71,7 +74,7 @@
</div>
</div>
<form action="settings" method="post">
<form action="<? VAR URIPrefix TOP ?><? VAR ModPath TOP ?>settings" method="post">
<? INC _csrf_check.tmpl ?>
<input type="hidden" name="submitted" value="1" />
+14 -10
View File
@@ -101,6 +101,7 @@ public:
CString sArgs(sArgStr);
CString sPort;
CString sListenHost;
CString sURIPrefix;
while (sArgs.Left(1) == "-") {
CString sOpt = sArgs.Token(0);
@@ -150,7 +151,7 @@ public:
}
// Now turn that into a listener instance
CListener *pListener = new CListener(uPort, sListenHost, bSSL,
CListener *pListener = new CListener(uPort, sListenHost, sURIPrefix, bSSL,
(!bIPv6 ? ADDR_IPV4ONLY : ADDR_ALL), CListener::ACCEPT_HTTP);
if (!pListener->Listen()) {
@@ -542,7 +543,7 @@ public:
WebSock.PrintErrorPage("Please don't delete yourself, suicide is not the answer!");
return true;
} else if (CZNC::Get().DeleteUser(sUser)) {
WebSock.Redirect("listusers");
WebSock.Redirect(GetWebPath() + "listusers");
return true;
}
@@ -710,7 +711,7 @@ public:
return true;
}
WebSock.Redirect("editnetwork?user=" + pUser->GetUserName().Escape_n(CString::EURL) + "&network=" + pNetwork->GetName().Escape_n(CString::EURL));
WebSock.Redirect(GetWebPath() + "editnetwork?user=" + pUser->GetUserName().Escape_n(CString::EURL) + "&network=" + pNetwork->GetName().Escape_n(CString::EURL));
return true;
}
@@ -984,7 +985,7 @@ public:
return true;
}
WebSock.Redirect("edituser?user=" + pUser->GetUserName().Escape_n(CString::EURL));
WebSock.Redirect(GetWebPath() + "edituser?user=" + pUser->GetUserName().Escape_n(CString::EURL));
return true;
}
@@ -1020,7 +1021,7 @@ public:
return true;
}
WebSock.Redirect("edituser?user=" + pUser->GetUserName().Escape_n(CString::EURL));
WebSock.Redirect(GetWebPath() + "edituser?user=" + pUser->GetUserName().Escape_n(CString::EURL));
return false;
}
@@ -1040,7 +1041,7 @@ public:
return true;
}
WebSock.Redirect("editnetwork?user=" + pNetwork->GetUser()->GetUserName().Escape_n(CString::EURL) + "&network=" + pNetwork->GetName().Escape_n(CString::EURL));
WebSock.Redirect(GetWebPath() + "editnetwork?user=" + pNetwork->GetUser()->GetUserName().Escape_n(CString::EURL) + "&network=" + pNetwork->GetName().Escape_n(CString::EURL));
return false;
}
@@ -1320,9 +1321,9 @@ public:
}
if (!spSession->IsAdmin()) {
WebSock.Redirect("edituser");
WebSock.Redirect(GetWebPath() + "edituser");
} else {
WebSock.Redirect("listusers");
WebSock.Redirect(GetWebPath() + "listusers");
}
/* we don't want the template to be printed while we redirect */
@@ -1420,6 +1421,7 @@ public:
bool AddListener(CWebSock& WebSock, CTemplate& Tmpl) {
unsigned short uPort = WebSock.GetParam("port").ToUShort();
CString sHost = WebSock.GetParam("host");
CString sURIPrefix = WebSock.GetParam("uriprefix");
if (sHost == "*") sHost = "";
bool bSSL = WebSock.GetParam("ssl").ToBool();
bool bIPv4 = WebSock.GetParam("ipv4").ToBool();
@@ -1460,7 +1462,7 @@ public:
}
CString sMessage;
if (CZNC::Get().AddListener(uPort, sHost, bSSL, eAddr, eAccept, sMessage)) {
if (CZNC::Get().AddListener(uPort, sHost, sURIPrefix, bSSL, eAddr, eAccept, sMessage)) {
if (!sMessage.empty()) {
WebSock.GetSession()->AddSuccess(sMessage);
}
@@ -1545,6 +1547,8 @@ public:
l["IsWeb"] = CString(pListener->GetAcceptType() != CListener::ACCEPT_IRC);
l["IsIRC"] = CString(pListener->GetAcceptType() != CListener::ACCEPT_HTTP);
l["URIPrefix"] = pListener->GetURIPrefix() + "/";
// simple protection for user from shooting his own foot
// TODO check also for hosts/families
// such check is only here, user still can forge HTTP request to delete web port
@@ -1688,7 +1692,7 @@ public:
WebSock.GetSession()->AddError("Settings changed, but config was not written");
}
WebSock.Redirect("settings");
WebSock.Redirect(GetWebPath() + "settings");
/* we don't want the template to be printed while we redirect */
return false;
}