]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Merge pull request #92 from Robby-/insp20-headers
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
25
26 class ModuleSecureList : public Module
27 {
28  private:
29         std::vector<std::string> allowlist;
30         time_t WaitTime;
31  public:
32         ModuleSecureList()      {
33                 OnRehash(NULL);
34                 Implementation eventlist[] = { I_OnRehash, I_OnPreCommand, I_On005Numeric };
35                 ServerInstance->Modules->Attach(eventlist, this, 3);
36         }
37
38         virtual ~ModuleSecureList()
39         {
40         }
41
42         virtual Version GetVersion()
43         {
44                 return Version("A module overriding /list, and making it safe - stop those sendq problems.",VF_VENDOR);
45         }
46
47         void OnRehash(User* user)
48         {
49                 ConfigReader MyConf;
50                 allowlist.clear();
51
52                 for (int i = 0; i < MyConf.Enumerate("securehost"); i++)
53                         allowlist.push_back(MyConf.ReadValue("securehost", "exception", i));
54
55                 WaitTime = MyConf.ReadInteger("securelist", "waittime", "60", 0, true);
56         }
57
58
59         /*
60          * OnPreCommand()
61          *   Intercept the LIST command.
62          */
63         virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
64         {
65                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
66                 if (!validated)
67                         return MOD_RES_PASSTHRU;
68
69                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!IS_OPER(user)))
70                 {
71                         /* Normally wouldnt be allowed here, are they exempt? */
72                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
73                                 if (InspIRCd::Match(user->MakeHost(), *x, ascii_case_insensitive_map))
74                                         return MOD_RES_PASSTHRU;
75
76                         /* Not exempt, BOOK EM DANNO! */
77                         user->WriteServ("NOTICE %s :*** You cannot list within the first %lu seconds of connecting. Please try again later.",user->nick.c_str(), (unsigned long) WaitTime);
78                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
79                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
80                          */
81                         user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
82                         user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
83                         return MOD_RES_DENY;
84                 }
85                 return MOD_RES_PASSTHRU;
86         }
87
88         virtual void On005Numeric(std::string &output)
89         {
90                 output.append(" SECURELIST");
91         }
92 };
93
94 MODULE_INIT(ModuleSecureList)