Skip to content
Browse files

Add URIPrefix listener option

  • Loading branch information...
1 parent d3ddb9b commit 88c85b0396670e53aee9b6e1dae5fa473937c649 @uu1101 uu1101 committed Feb 15, 2014
View
6 include/znc/HTTPSock.h
@@ -25,8 +25,8 @@ class CModule;
class CHTTPSock : public CSocket {
public:
- CHTTPSock(CModule *pMod);
- CHTTPSock(CModule *pMod, const CString& sHostname, unsigned short uPort, int iTimeout = 60);
+ CHTTPSock(CModule *pMod, const CString& sURIPrefix);
+ CHTTPSock(CModule *pMod, const CString& sURIPrefix, const CString& sHostname, unsigned short uPort, int iTimeout = 60);
virtual ~CHTTPSock();
// Csocket derived members
@@ -76,6 +76,7 @@ class CHTTPSock : public CSocket {
const CString& GetPass() const;
const CString& GetParamString() const;
const CString& GetContentType() const;
+ const CString& GetURIPrefix() const;
bool IsPost() const;
// !Getters
@@ -121,6 +122,7 @@ class CHTTPSock : public CSocket {
bool m_bAcceptGzip;
MCString m_msRequestCookies;
MCString m_msResponseCookies;
+ CString m_sURIPrefix;
};
#endif // !_HTTPSOCK_H
View
8 include/znc/Listener.h
@@ -32,11 +32,12 @@ class CListener {
ACCEPT_ALL
} EAcceptType;
- CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, EAddrType eAddr, EAcceptType eAccept) {
+ CListener(unsigned short uPort, const CString& sBindHost, const CString& sURIPrefix, bool bSSL, EAddrType eAddr, EAcceptType eAccept) {
m_uPort = uPort;
m_sBindHost = sBindHost;
m_bSSL = bSSL;
m_eAddr = eAddr;
+ m_sURIPrefix = sURIPrefix;
m_pListener = NULL;
m_eAcceptType = eAccept;
}
@@ -49,6 +50,7 @@ class CListener {
unsigned short GetPort() const { return m_uPort; }
const CString& GetBindHost() const { return m_sBindHost; }
CRealListener* GetRealListener() const { return m_pListener; }
+ const CString& GetURIPrefix() const { return m_sURIPrefix; }
EAcceptType GetAcceptType() const { return m_eAcceptType; }
// !Getters
@@ -65,6 +67,7 @@ class CListener {
EAddrType m_eAddr;
unsigned short m_uPort;
CString m_sBindHost;
+ CString m_sURIPrefix;
CRealListener* m_pListener;
EAcceptType m_eAcceptType;
};
@@ -84,13 +87,14 @@ class CRealListener : public CZNCSock {
class CIncomingConnection : public CZNCSock {
public:
- CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType);
+ CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType, const CString& sURIPrefix);
virtual ~CIncomingConnection() {}
virtual void ReadLine(const CString& sData);
virtual void ReachedMaxBuffer();
private:
CListener::EAcceptType m_eAcceptType;
+ const CString m_sURIPrefix;
};
#endif // !_LISTENER_H
View
2 include/znc/WebModules.h
@@ -117,7 +117,7 @@ class CWebSock : public CHTTPSock {
PAGE_DONE // all stuff has been done
};
- CWebSock();
+ CWebSock(const CString& sURIPrefix);
virtual ~CWebSock();
virtual bool ForceLogin();
View
3 include/znc/znc.h
@@ -152,7 +152,8 @@ class CZNC {
// Listener yummy
CListener* FindListener(u_short uPort, const CString& BindHost, EAddrType eAddr);
bool AddListener(CListener*);
- bool AddListener(unsigned short uPort, const CString& sBindHost, bool bSSL,
+ bool AddListener(unsigned short uPort, const CString& sBindHost,
+ const CString& sURIPrefix, bool bSSL,
EAddrType eAddr, CListener::EAcceptType eAccept, CString& sError);
bool DelListener(CListener*);
View
5 modules/data/webadmin/tmpl/settings.tmpl
@@ -16,6 +16,7 @@
<td>IPv6</td>
<td>IRC</td>
<td>Web</td>
+ <td>URIPrefix</td>
</tr>
</thead>
@@ -38,6 +39,7 @@
<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">
@@ -56,12 +58,13 @@
<form action="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>
View
8 modules/webadmin.cpp
@@ -101,6 +101,7 @@ class CWebAdminMod : public CModule {
CString sArgs(sArgStr);
CString sPort;
CString sListenHost;
+ CString sURIPrefix;
while (sArgs.Left(1) == "-") {
CString sOpt = sArgs.Token(0);
@@ -150,7 +151,7 @@ class CWebAdminMod : public CModule {
}
// 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()) {
@@ -1420,6 +1421,7 @@ class CWebAdminMod : public CModule {
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 @@ class CWebAdminMod : public CModule {
}
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 @@ class CWebAdminMod : public CModule {
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
View
7 src/ClientCommand.cpp
@@ -1430,6 +1430,7 @@ void CClient::UserPortCommand(CString& sLine) {
Table.AddColumn("SSL");
Table.AddColumn("Proto");
Table.AddColumn("IRC/Web");
+ Table.AddColumn("URIPrefix");
vector<CListener*>::const_iterator it;
const vector<CListener*>& vpListeners = CZNC::Get().GetListeners();
@@ -1445,6 +1446,7 @@ void CClient::UserPortCommand(CString& sLine) {
CListener::EAcceptType eAccept = (*it)->GetAcceptType();
Table.SetCell("IRC/Web", (eAccept == CListener::ACCEPT_ALL ? "All" : (eAccept == CListener::ACCEPT_IRC ? "IRC" : "Web")));
+ Table.SetCell("URIPrefix", (*it)->GetURIPrefix() + "/");
}
PutStatus(Table);
@@ -1483,12 +1485,13 @@ void CClient::UserPortCommand(CString& sLine) {
}
if (sPort.empty() || sAddr.empty() || sAccept.empty()) {
- PutStatus("Usage: AddPort <[+]port> <ipv4|ipv6|all> <web|irc|all> [bindhost]");
+ PutStatus("Usage: AddPort <[+]port> <ipv4|ipv6|all> <web|irc|all> [bindhost [uriprefix]]");
} else {
bool bSSL = (sPort.Left(1).Equals("+"));
const CString sBindHost = sLine.Token(4);
+ const CString sURIPrefix = sLine.Token(5);
- CListener* pListener = new CListener(uPort, sBindHost, bSSL, eAddr, eAccept);
+ CListener* pListener = new CListener(uPort, sBindHost, sURIPrefix, bSSL, eAddr, eAccept);
if (!pListener->Listen()) {
delete pListener;
View
8 src/HTTPSock.cpp
@@ -28,11 +28,11 @@ using std::set;
#define MAX_POST_SIZE 1024 * 1024
-CHTTPSock::CHTTPSock(CModule *pMod) : CSocket(pMod) {
+CHTTPSock::CHTTPSock(CModule *pMod, const CString& sURIPrefix) : CSocket(pMod), m_sURIPrefix(sURIPrefix) {
Init();
}
-CHTTPSock::CHTTPSock(CModule *pMod, const CString& sHostname, unsigned short uPort, int iTimeout) : CSocket(pMod, sHostname, uPort, iTimeout) {
+CHTTPSock::CHTTPSock(CModule *pMod, const CString& sURIPrefix, const CString& sHostname, unsigned short uPort, int iTimeout) : CSocket(pMod, sHostname, uPort, iTimeout), m_sURIPrefix(sURIPrefix) {
Init();
}
@@ -495,6 +495,10 @@ const CString& CHTTPSock::GetParamString() const {
return m_sPostData;
}
+const CString& CHTTPSock::GetURIPrefix() const {
+ return m_sURIPrefix;
+}
+
bool CHTTPSock::HasParam(const CString& sName, bool bPost) const {
if (bPost)
return (m_msvsPOSTParams.find(sName) != m_msvsPOSTParams.end());
View
8 src/Listener.cpp
@@ -60,7 +60,9 @@ bool CRealListener::ConnectionFrom(const CString& sHost, unsigned short uPort) {
}
Csock* CRealListener::GetSockObj(const CString& sHost, unsigned short uPort) {
- CIncomingConnection *pClient = new CIncomingConnection(sHost, uPort, m_Listener.GetAcceptType());
+ CIncomingConnection *pClient = new CIncomingConnection(sHost, uPort,
+ m_Listener.GetAcceptType(),
+ m_Listener.GetURIPrefix());
if (CZNC::Get().AllowConnectionFrom(sHost)) {
GLOBALMODULECALL(OnClientConnect(pClient, sHost, uPort), NOTHING);
} else {
@@ -83,7 +85,7 @@ void CRealListener::SockError(int iErrno, const CString& sDescription) {
}
}
-CIncomingConnection::CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType) : CZNCSock(sHostname, uPort) {
+CIncomingConnection::CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType, const CString& sURIPrefix) : CZNCSock(sHostname, uPort), m_sURIPrefix(sURIPrefix) {
m_eAcceptType = eAcceptType;
// The socket will time out in 120 secs, no matter what.
// This has to be fixed up later, if desired.
@@ -141,7 +143,7 @@ void CIncomingConnection::ReadLine(const CString& sLine) {
return;
}
- pSock = new CWebSock();
+ pSock = new CWebSock(m_sURIPrefix);
CZNC::Get().GetManager().SwapSockByAddr(pSock, this);
// And don't forget to give it some sane name / timeout
View
2 src/WebModules.cpp
@@ -185,7 +185,7 @@ void CWebAuth::Invalidate() {
m_pWebSock = NULL;
}
-CWebSock::CWebSock() : CHTTPSock(NULL) {
+CWebSock::CWebSock(const CString& sURIPrefix) : CHTTPSock(NULL, sURIPrefix) {
m_bPathsSet = false;
m_Template.AddTagHandler(new CZNCTagHandler(*this));
View
30 src/znc.cpp
@@ -454,6 +454,7 @@ bool CZNC::WriteConfig() {
CConfig listenerConfig;
listenerConfig.AddKeyValuePair("Host", pListener->GetBindHost());
+ listenerConfig.AddKeyValuePair("URIPrefix", pListener->GetURIPrefix() + "/");
listenerConfig.AddKeyValuePair("Port", CString(pListener->GetPort()));
listenerConfig.AddKeyValuePair("IPv4", CString(pListener->GetAddrType() != ADDR_IPV6ONLY));
@@ -582,6 +583,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
bool b6 = false;
#endif
CString sListenHost;
+ CString sURIPrefix;
bool bListenSSL = false;
unsigned int uListenPort = 0;
bool bSuccess;
@@ -610,7 +612,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
CUtils::GetInput("Listen Host", sListenHost, sListenHost, "Blank for all ips");
CUtils::PrintAction("Verifying the listener");
- CListener* pListener = new CListener((unsigned short int)uListenPort, sListenHost, bListenSSL,
+ CListener* pListener = new CListener((unsigned short int)uListenPort, sListenHost, sURIPrefix, bListenSSL,
b6 ? ADDR_ALL : ADDR_IPV4ONLY, CListener::ACCEPT_ALL);
if (!pListener->Listen()) {
CUtils::PrintStatus(false, FormatBindError());
@@ -1695,12 +1697,15 @@ bool CZNC::AddListener(const CString& sLine, CString& sError) {
bSSL = true;
}
+ // No support for URIPrefix for old-style configs.
+ CString sURIPrefix;
unsigned short uPort = sPort.ToUShort();
- return AddListener(uPort, sBindHost, bSSL, eAddr, eAccept, sError);
+ return AddListener(uPort, sBindHost, sURIPrefix, bSSL, eAddr, eAccept, sError);
}
-bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, bool bSSL,
- EAddrType eAddr, CListener::EAcceptType eAccept, CString& sError) {
+bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost,
+ const CString& sURIPrefixRaw, bool bSSL,
+ EAddrType eAddr, CListener::EAcceptType eAccept, CString& sError) {
CString sHostComment;
if (!sBindHost.empty()) {
@@ -1761,7 +1766,18 @@ bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, bool bSSL
return false;
}
- CListener* pListener = new CListener(uPort, sBindHost, bSSL, eAddr, eAccept);
+ // URIPrefix must start with a slash and end without one.
+ CString sURIPrefix = CString(sURIPrefixRaw);
+ if(!sURIPrefix.empty()) {
+ if (!sURIPrefix.StartsWith("/")) {
+ sURIPrefix = "/" + sURIPrefix;
+ }
+ if (sURIPrefix.EndsWith("/")) {
+ sURIPrefix.TrimRight("/");
+ }
+ }
+
+ CListener* pListener = new CListener(uPort, sBindHost, sURIPrefix, bSSL, eAddr, eAccept);
if (!pListener->Listen()) {
sError = FormatBindError();
@@ -1778,6 +1794,7 @@ bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, bool bSSL
bool CZNC::AddListener(CConfig* pConfig, CString& sError) {
CString sBindHost;
+ CString sURIPrefix;
bool bSSL;
bool b4;
#ifdef HAVE_IPV6
@@ -1799,6 +1816,7 @@ bool CZNC::AddListener(CConfig* pConfig, CString& sError) {
pConfig->FindBoolEntry("ipv6", b6, b6);
pConfig->FindBoolEntry("allowirc", bIRC, true);
pConfig->FindBoolEntry("allowweb", bWeb, true);
+ pConfig->FindStringEntry("uriprefix", sURIPrefix);
EAddrType eAddr;
if (b4 && b6) {
@@ -1826,7 +1844,7 @@ bool CZNC::AddListener(CConfig* pConfig, CString& sError) {
return false;
}
- return AddListener(uPort, sBindHost, bSSL, eAddr, eAccept, sError);
+ return AddListener(uPort, sBindHost, sURIPrefix, bSSL, eAddr, eAccept, sError);
}
bool CZNC::AddListener(CListener* pListener) {

0 comments on commit 88c85b0

Please sign in to comment.
Something went wrong with that request. Please try again.