Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: znc/znc
base: ed5610f
...
head fork: znc/znc
compare: ba99a64
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
4 include/znc/znc.h
@@ -143,6 +143,8 @@ class CZNC {
// Listener yummy
CListener* FindListener(u_short uPort, const CString& BindHost, EAddrType eAddr);
bool AddListener(CListener*);
+ bool AddListener(unsigned int uPort, const CString& sBindHost, bool bSSL,
+ EAddrType eAddr, CListener::EAcceptType eAccept, CString& sError);
bool DelListener(CListener*);
// Message of the Day
@@ -178,8 +180,6 @@ class CZNC {
CString MakeConfigHeader();
bool AddListener(const CString& sLine, CString& sError);
bool AddListener(CConfig* pConfig, CString& sError);
- bool AddListener(unsigned int uPort, const CString& sBindHost, bool bSSL,
- EAddrType eAddr, CListener::EAcceptType eAccept, CString& sError);
protected:
time_t m_TimeStarted;
View
2  modules/data/certauth/tmpl/index.tmpl
@@ -25,7 +25,7 @@
<table class="data">
<thead>
<tr>
- <td style="width: 10px;"></td>
+ <td></td>
<td>Key</td>
</tr>
</thead>
View
5 modules/data/lastseen/tmpl/lastseen_WebadminUser.tmpl
@@ -1,9 +1,8 @@
<div class="sectionbg">
<div class="sectionbody">
<div class="subsection">
- <div class="inputlabel">Last login time:</div>
- <div><? VAR LastSeen DEFAULT="- unknown -" ?></div>
+ <label id="last_login">Last login time:</label>
+ <span id="lastseen"><? VAR LastSeen DEFAULT="- unknown -" ?></span>
</div>
- <div style="clear:both;"></div>
</div>
</div>
View
79 modules/data/webadmin/tmpl/settings.tmpl
@@ -10,35 +10,60 @@
<div class="sectionbody">
<div class="subsection">
<div>
- <table>
- <thead>
- <tr>
- <td>Port</td>
- <td>BindHost</td>
- <td>SSL</td>
- <td>IPv4</td>
- <td>IPv6</td>
- <td>IRC</td>
- <td>Web</td>
- </tr>
- </thead>
- <tbody>
- <? LOOP ListenLoop ?>
- <tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
- <td><? VAR Port ?></td>
- <td><? VAR BindHost DEFAULT=** ?></td>
- <td><? IF IsSSL ?>Yes<? ELSE ?>No<? ENDIF ?></td>
- <td><? IF IsIPV4 ?>Yes<? ELSE ?>No<? ENDIF ?></td>
- <td><? IF IsIPV6 ?>Yes<? ELSE ?>No<? ENDIF ?></td>
- <td><? IF IsIRC ?>Yes<? ELSE ?>No<? ENDIF ?></td>
- <td><? IF IsWeb ?>Yes<? ELSE ?>No<? ENDIF ?></td>
- </tr>
- <? ENDLOOP ?>
- </tbody>
- </table>
+ <form action="add_listener" method="post">
+ <table>
+ <thead>
+ <tr>
+ <td>Port</td>
+ <td>BindHost</td>
+ <td>SSL</td>
+ <td>IPv4</td>
+ <td>IPv6</td>
+ <td>IRC</td>
+ <td>Web</td>
+ <td/>
+ </tr>
+ </thead>
+ <tbody>
+ <? LOOP ListenLoop ?>
+ <tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
+ <td><? VAR Port ?></td>
+ <td><? VAR BindHost DEFAULT=** ?></td>
+ <td><div class="checkbox"><input type="checkbox" disabled="disabled" <? IF IsSSL ?>checked="checked"<? ENDIF ?>/></div></td>
+ <td><div class="checkbox"><input type="checkbox" disabled="disabled" <? IF IsIPV4 ?>checked="checked"<? ENDIF ?>/></div></td>
+ <td><div class="checkbox"><input type="checkbox" disabled="disabled" <? IF IsIPV6 ?>checked="checked"<? ENDIF ?>/></div></td>
+ <td><div class="checkbox"><input type="checkbox" disabled="disabled" <? IF IsIRC ?>checked="checked"<? ENDIF ?>/></div></td>
+ <td><div class="checkbox"><input type="checkbox" disabled="disabled" <? IF IsWeb ?>checked="checked"<? ENDIF ?>/></div></td>
+ <td>
+ <? IF SuggestDeletion ?>
+ <form action="del_listener" method="post">
+ <? INC _csrf_check.tmpl ?>
+ <input name="host" type="hidden" value="<? VAR BindHost ?>"/>
+ <input name="port" type="hidden" value="<? VAR Port ?>"/>
+ <input name="ipv4" type="hidden" value="<? VAR IsIPV4 ?>"/>
+ <input name="ipv6" type="hidden" value="<? VAR IsIPV6 ?>"/>
+ <input type="submit" value="Del"/>
+ </form>
+ <? ENDIF ?>
+ </td>
+ </tr>
+ <? ENDLOOP ?>
+ <tr>
+ <? 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><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 type="submit" value="Add"/></td>
+ </tr>
+ </tbody>
+ </table>
+ </form>
</div>
</div>
- <div style="clear: both;"></div>
</div>
</div>
</div>
View
122 modules/webadmin.cpp
@@ -513,6 +513,20 @@ class CWebAdminMod : public CModule {
return TrafficPage(WebSock, Tmpl);
} else if (sPageName == "index") {
return true;
+ } else if (sPageName == "add_listener") {
+ // Admin Check
+ if (!spSession->IsAdmin()) {
+ return false;
+ }
+
+ return AddListener(WebSock, Tmpl);
+ } else if (sPageName == "del_listener") {
+ // Admin Check
+ if (!spSession->IsAdmin()) {
+ return false;
+ }
+
+ return DelListener(WebSock, Tmpl);
}
return false;
@@ -1233,7 +1247,110 @@ class CWebAdminMod : public CModule {
return true;
}
+ bool AddListener(CWebSock& WebSock, CTemplate& Tmpl) {
+ unsigned int uPort = WebSock.GetParam("port").ToUInt();
+ CString sHost = WebSock.GetParam("host");
+ if (sHost == "*") sHost = "";
+ bool bSSL = WebSock.GetParam("ssl").ToBool();
+ bool bIPv4 = WebSock.GetParam("ipv4").ToBool();
+ bool bIPv6 = WebSock.GetParam("ipv6").ToBool();
+ bool bIRC = WebSock.GetParam("irc").ToBool();
+ bool bWeb = WebSock.GetParam("web").ToBool();
+
+ EAddrType eAddr = ADDR_ALL;
+ if (bIPv4) {
+ if (bIPv6) {
+ eAddr = ADDR_ALL;
+ } else {
+ eAddr = ADDR_IPV4ONLY;
+ }
+ } else {
+ if (bIPv6) {
+ eAddr = ADDR_IPV6ONLY;
+ } else {
+ WebSock.GetSession()->AddError("Choose either IPv4 or IPv6 or both.");
+ return SettingsPage(WebSock, Tmpl);
+ }
+ }
+
+ CListener::EAcceptType eAccept;
+ if (bIRC) {
+ if (bWeb) {
+ eAccept = CListener::ACCEPT_ALL;
+ } else {
+ eAccept = CListener::ACCEPT_IRC;
+ }
+ } else {
+ if (bWeb) {
+ eAccept = CListener::ACCEPT_HTTP;
+ } else {
+ WebSock.GetSession()->AddError("Choose either IRC or Web or both.");
+ return SettingsPage(WebSock, Tmpl);
+ }
+ }
+
+ CString sMessage;
+ if (CZNC::Get().AddListener(uPort, sHost, bSSL, eAddr, eAccept, sMessage)) {
+ if (!sMessage.empty()) {
+ WebSock.GetSession()->AddSuccess(sMessage);
+ }
+ if (!CZNC::Get().WriteConfig()) {
+ WebSock.GetSession()->AddError("Port changed, but config was not written");
+ }
+ } else {
+ WebSock.GetSession()->AddError(sMessage);
+ }
+
+ return SettingsPage(WebSock, Tmpl);
+ }
+
+ bool DelListener(CWebSock& WebSock, CTemplate& Tmpl) {
+ map<CString, VCString> m = WebSock.GetParams();
+ DEBUG("zzz");
+ for (map<CString, VCString>::iterator i = m.begin(); i != m.end(); ++i) {
+ DEBUG("xxxxxxxxxxxxxxxxxxx[" << i->first << "]");
+ for (VCString::iterator it = i->second.begin(); it != i->second.end(); ++it) {
+ DEBUG("yyyyyyyy[" << *it << "]");
+ }
+ }
+ unsigned int uPort = WebSock.GetParam("port").ToUInt();
+ CString sHost = WebSock.GetParam("host");
+ bool bIPv4 = WebSock.GetParam("ipv4").ToBool();
+ bool bIPv6 = WebSock.GetParam("ipv6").ToBool();
+
+ DEBUG("Port [" << WebSock.GetParam("port") << "]");
+
+ EAddrType eAddr = ADDR_ALL;
+ if (bIPv4) {
+ if (bIPv6) {
+ eAddr = ADDR_ALL;
+ } else {
+ eAddr = ADDR_IPV4ONLY;
+ }
+ } else {
+ if (bIPv6) {
+ eAddr = ADDR_IPV6ONLY;
+ } else {
+ WebSock.GetSession()->AddError("Invalid request.");
+ return SettingsPage(WebSock, Tmpl);
+ }
+ }
+
+ CListener* pListener = CZNC::Get().FindListener(uPort, sHost, eAddr);
+ if (pListener) {
+ CZNC::Get().DelListener(pListener);
+ if (!CZNC::Get().WriteConfig()) {
+ WebSock.GetSession()->AddError("Port changed, but config was not written");
+ }
+ } else {
+ WebSock.GetSession()->AddError("The specified listener was not found.");
+ }
+
+ return SettingsPage(WebSock, Tmpl);
+ }
+
bool SettingsPage(CWebSock& WebSock, CTemplate& Tmpl) {
+ Tmpl.SetFile("settings.tmpl");
if (!WebSock.GetParam("submitted").ToUInt()) {
CString sBindHosts, sMotd;
Tmpl["Action"] = "settings";
@@ -1268,6 +1385,11 @@ class CWebAdminMod : public CModule {
l["IsWeb"] = CString(pListener->GetAcceptType() != CListener::ACCEPT_IRC);
l["IsIRC"] = CString(pListener->GetAcceptType() != CListener::ACCEPT_HTTP);
+ // 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
+ l["SuggestDeletion"] = CString(pListener->GetPort() != WebSock.GetLocalPort());
+
#ifdef HAVE_LIBSSL
if (pListener->IsSSL()) {
l["IsSSL"] = "true";
View
8 webskins/_default_/pub/_default_.css
@@ -247,14 +247,18 @@ input.third, textarea.third,
width: 150px;
}
+input.number {
+ width: 40px;
+}
+
table {
border: 1px solid #ccc;
border-spacing: 1px;
}
td, th {
- padding: 5px 10px;
- min-width: 50px;
+ padding: 5px 7px;
+ min-width: 35px;
}
thead td, th {
View
2  webskins/ice/pub/ice.css
@@ -92,7 +92,7 @@ table thead {
thead td {
font-size: 13px;
border-bottom: 1px solid #000;
- min-width: 50px;
+ min-width: 35px;
}
th {

No commit comments for this range

Something went wrong with that request. Please try again.