]> jfr.im git - irc/rizon/znc.git/commitdiff
Port over blockuser changes to allow blocking users with a reason
authorAdam <redacted>
Fri, 11 Jan 2013 06:36:19 +0000 (01:36 -0500)
committerAdam <redacted>
Fri, 11 Jan 2013 06:36:19 +0000 (01:36 -0500)
modules/awaystore.cpp
modules/blockuser.cpp

index 0f939d050cac2d4793d3b7e57b11fad6ee4524bf..267697bf2eaf0678c8ed4451e626dc4d19d2b53e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2011  See the AUTHORS file for details.
+ * Copyright (C) 2004-2013  See the AUTHORS file for details.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
@@ -7,15 +7,24 @@
  *
  * Quiet Away and message logger
  * Author: imaginos <imaginos@imaginos.net>
+ *
+ * I originally wrote this module for when I had multiple clients connected to ZNC. I would leave work and forget to close my client, arriving at home
+ * and re-attaching there someone may have messaged me in commute and I wouldn't know it until I would arrive back at work the next day. I wrote it such that
+ * my xchat client would monitor desktop activity and ping the module to let it know I was active. Within a few minutes of inactivity the pinging stops and
+ * the away module sets the user as away and logging commences.
  */
 
 #define REQUIRESSL
 
-#include "Client.h"
-#include "User.h"
-#include "FileUtils.h"
+#include <znc/Client.h>
+#include <znc/User.h>
+#include <znc/IRCNetwork.h>
+#include <znc/FileUtils.h>
 #include <sys/stat.h>
 
+using std::vector;
+using std::map;
+
 #define CRYPT_VERIFICATION_TOKEN "::__:AWAY:__::"
 
 class CAway;
@@ -438,7 +447,7 @@ private:
 
        void AddMessage(time_t iTime, const CNick & Nick, CString & sMessage)
        {
-               if (m_pUser && Nick.GetNick() == m_pUser->GetIRCNick().GetNick())
+               if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick())
                        return; // ignore messages from self
                AddMessage(CString(iTime) + ":" + Nick.GetNickMask() + ":" + sMessage);
        }
@@ -474,5 +483,11 @@ void CAwayJob::RunJob()
        }
 }
 
-MODULEDEFS(CAway, "You don't need this module, ZNC works ok without it")
+template<> void TModInfo<CAway>(CModInfo& Info) {
+       Info.SetWikiPage("awaystore");
+       Info.SetHasArgs(true);
+       Info.SetArgsHelpText("[ -notimer | -timer N ]  passw0rd . N is number of seconds, 600 by default.");
+}
+
+NETWORKMODULEDEFS(CAway, "Adds auto-away with logging, useful when you use ZNC from different locations");
 
index 9a502ac90d548cbe480d823d02251fd4540b8308..0fe30821a53827fe0e8129b3b51a5a4818d5675c 100644 (file)
@@ -13,7 +13,7 @@
 
 using std::vector;
 
-#define MESSAGE "Your account has been disabled. Contact your administrator."
+#define MESSAGE "Your account has been disabled"
 
 class CBlockUser : public CModule {
 public:
@@ -29,14 +29,14 @@ public:
                // Load saved settings
                for (it2 = BeginNV(); it2 != EndNV(); ++it2) {
                        // Ignore errors
-                       Block(it2->first);
+                       Block(it2->first, it2->second);
                }
 
                // Parse arguments, each argument is a user name to block
                sArgs.Split(" ", vArgs, false);
 
                for (it = vArgs.begin(); it != vArgs.end(); ++it) {
-                       if (!Block(*it)) {
+                       if (!Block(*it, "no reason")) {
                                sMessage = "Could not block [" + *it + "]";
                                return false;
                        }
@@ -67,10 +67,12 @@ public:
                        MCString::iterator it;
 
                        Table.AddColumn("Blocked user");
+                       Table.AddColumn("Reason");
 
                        for (it = BeginNV(); it != EndNV(); ++it) {
                                Table.AddRow();
                                Table.SetCell("Blocked user", it->first);
+                               Table.SetCell("Reason", it->second);
                        }
 
                        if (PutModule(Table) == 0)
@@ -83,7 +85,7 @@ public:
                                return;
                        }
 
-                       if (Block(sUser))
+                       if (Block(sUser, sCommand.Token(2, true)))
                                PutModule("Blocked [" + sUser + "]");
                        else
                                PutModule("Could not block [" + sUser + "] (misspelled?)");
@@ -99,6 +101,7 @@ public:
                }
        }
 
+#if 0
        bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
                if (sPageName == "webadmin/user" && WebSock.GetSession()->IsAdmin()) {
                        CString sAction = Tmpl["WebadminAction"];
@@ -131,6 +134,7 @@ public:
                }
                return false;
        }
+#endif
 
 private:
        bool IsBlocked(const CString& sUser) {
@@ -143,17 +147,17 @@ private:
                return false;
        }
 
-       bool Block(const CString& sUser) {
+       bool Block(const CString& sUser, const CString &reason) {
                CUser *pUser = CZNC::Get().FindUser(sUser);
 
-               if (!pUser)
+               if (!pUser || reason.empty())
                        return false;
 
                // Disconnect all clients
                vector<CClient*> vpClients = pUser->GetAllClients();
                vector<CClient*>::iterator it;
                for (it = vpClients.begin(); it != vpClients.end(); ++it) {
-                       (*it)->PutStatusNotice(MESSAGE);
+                       (*it)->PutStatusNotice(MESSAGE + reason);
                        (*it)->Close(Csock::CLT_AFTERWRITE);
                }
 
@@ -163,7 +167,7 @@ private:
                        (*it2)->SetIRCConnectEnabled(false);
                }
 
-               SetNV(pUser->GetUserName(), "");
+               SetNV(pUser->GetUserName(), reason);
                return true;
        }
 };