Permalink
Browse files

Nicify webadmin interface for flood protection.

  • Loading branch information...
1 parent 19dff7c commit e83efead2692f912ca53ac4a5723f752bdfddd0b @DarthGandalf DarthGandalf committed Mar 22, 2012
Showing with 44 additions and 5 deletions.
  1. +3 −0 include/znc/IRCSock.h
  2. +27 −2 modules/data/webadmin/tmpl/add_edit_network.tmpl
  3. +9 −2 modules/webadmin.cpp
  4. +5 −1 src/IRCSock.cpp
@@ -100,6 +100,9 @@ class CIRCSock : public CZNCSock {
// This handles NAMESX and UHNAMES in a raw 353 reply
void ForwardRaw353(const CString& sLine) const;
void ForwardRaw353(const CString& sLine, CClient* pClient) const;
+
+ // TODO move this function to CIRCNetwork and make it non-static?
+ static bool IsFloodProtected(double fRate);
private:
void SetNick(const CString& sNick);
void ParseISupport(const CString& sLine);
@@ -58,14 +58,39 @@
<br /><span class="info">One server per line, host [[+]port] [password]</span>
</div>
+ <script type="text/javascript">
+ function floodprotection_change() {
+ var protection = document.getElementById('floodprotection_checkbox');
+ var rate = document.getElementById('floodrate');
+ var burst = document.getElementById('floodburst');
+ if (protection.checked) {
+ rate.removeAttribute('disabled');
+ burst.removeAttribute('disabled');
+ } else {
+ rate.disabled = 'disabled';
+ burst.disabled = 'disabled';
+ }
+ }
+ </script>
+ <div class="subsection">
+ <div class="inputlabel">Flood protection:</div>
+ <div class="checkbox">
+ <input type="checkbox" name="floodprotection" id="floodprotection_checkbox"
+ onchange="floodprotection_change();"
+ <? IF FloodProtection ?>checked="checked"<? ENDIF ?> />
+ <label for="floodprotection_checkbox">Enabled</label>
+ </div>
+ </div>
<div class="subsection">
<div class="inputlabel">Flood protection rate:</div>
- <div><input type="text" name="floodrate" value="<? VAR FloodRate ?>" />Set to -1 to disable flood protection</div>
+ <div><input type="number" name="floodrate" min="0.3" step="0.05" id="floodrate"
+ <? IF FloodProtection ?> value="<? VAR FloodRate ?>" <? ELSE ?> value="1.00" disabled="disabled" <? ENDIF ?> /> seconds per line</div>
</div>
<div class="subsection">
<div class="inputlabel">Flood protection burst:</div>
- <div><input type="number" name="floodburst" value="<? VAR FloodBurst ?>" min="0" /></div>
+ <div><input type="number" name="floodburst" value="<? VAR FloodBurst ?>" min="1" id="floodburst"
+ <? IF FloodProtection ?> value="<? VAR FloodBurst ?>" <? ELSE ?> value="4" disabled="disabled" <? ENDIF ?> /> lines can be send immediately</div>
</div>
<div style="clear: both;"></div>
</div>
View
@@ -16,6 +16,7 @@
#include <znc/ZNCString.h>
#include <znc/Listener.h>
#include <znc/IRCNetwork.h>
+#include <znc/IRCSock.h>
#include <sstream>
#include <utility>
@@ -677,6 +678,7 @@ class CWebAdminMod : public CModule {
Tmpl["Ident"] = pNetwork->GetIdent();
Tmpl["RealName"] = pNetwork->GetRealName();
+ Tmpl["FloodProtection"] = CString(CIRCSock::IsFloodProtected(pNetwork->GetFloodRate()));
Tmpl["FloodRate"] = CString(pNetwork->GetFloodRate());
Tmpl["FloodBurst"] = CString(pNetwork->GetFloodBurst());
@@ -717,6 +719,7 @@ class CWebAdminMod : public CModule {
Tmpl["Action"] = "addnetwork";
Tmpl["Title"] = "Add Network for User [" + pUser->GetUserName() + "]";
Tmpl["IRCConnectEnabled"] = "true";
+ Tmpl["FloodProtection"] = "true";
Tmpl["FloodRate"] = "1.0";
Tmpl["FloodBurst"] = "4";
}
@@ -747,8 +750,12 @@ class CWebAdminMod : public CModule {
pNetwork->SetIRCConnectEnabled(WebSock.GetParam("doconnect").ToBool());
- pNetwork->SetFloodRate(WebSock.GetParam("floodrate").ToDouble());
- pNetwork->SetFloodBurst(WebSock.GetParam("floodburst").ToUInt());
+ if (WebSock.GetParam("floodprotection").ToBool()) {
+ pNetwork->SetFloodRate(WebSock.GetParam("floodrate").ToDouble());
+ pNetwork->SetFloodBurst(WebSock.GetParam("floodburst").ToUInt());
+ } else {
+ pNetwork->SetFloodRate(-1);
+ }
VCString vsArgs;
View
@@ -21,6 +21,7 @@ const unsigned int CIRCSock::m_uCTCPFloodCount = 5;
// It will be bad if user sets it to 0.00000000000001
// If you want no flood protection, set network's flood rate to -1
+// TODO move this constant to CIRCNetwork?
static const double FLOOD_MINIMAL_RATE = 0.3;
class CIRCFloodTimer : public CCron {
@@ -38,6 +39,9 @@ class CIRCFloodTimer : public CCron {
}
};
+bool CIRCSock::IsFloodProtected(double fRate) {
+ return fRate > FLOOD_MINIMAL_RATE;
+}
CIRCSock::CIRCSock(CIRCNetwork* pNetwork) : CZNCSock() {
m_pNetwork = pNetwork;
@@ -46,7 +50,7 @@ CIRCSock::CIRCSock(CIRCNetwork* pNetwork) : CZNCSock() {
m_bUHNames = false;
m_fFloodRate = m_pNetwork->GetFloodRate();
m_uFloodBurst = m_pNetwork->GetFloodBurst();
- m_bFloodProtection = m_fFloodRate > FLOOD_MINIMAL_RATE;
+ m_bFloodProtection = IsFloodProtected(m_fFloodRate);
m_iSendsAllowed = m_uFloodBurst;
EnableReadLine();
m_Nick.SetIdent(m_pNetwork->GetIdent());

0 comments on commit e83efea

Please sign in to comment.