]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
17
18 class ModuleSecureList : public Module
19 {
20  private:
21         std::vector<std::string> allowlist;
22         time_t WaitTime;
23  public:
24         ModuleSecureList()      {
25                 OnRehash(NULL);
26                 Implementation eventlist[] = { I_OnRehash, I_OnPreCommand, I_On005Numeric };
27                 ServerInstance->Modules->Attach(eventlist, this, 3);
28         }
29
30         virtual ~ModuleSecureList()
31         {
32         }
33
34         virtual Version GetVersion()
35         {
36                 return Version("A module overriding /list, and making it safe - stop those sendq problems.",VF_VENDOR,API_VERSION);
37         }
38
39         void OnRehash(User* user)
40         {
41                 ConfigReader* MyConf = new ConfigReader;
42                 allowlist.clear();
43
44                 for (int i = 0; i < MyConf->Enumerate("securehost"); i++)
45                         allowlist.push_back(MyConf->ReadValue("securehost", "exception", i));
46
47                 WaitTime = MyConf->ReadInteger("securelist", "waittime", "60", 0, true);
48                 delete MyConf;
49         }
50
51
52         /*
53          * OnPreCommand()
54          *   Intercept the LIST command.
55          */
56         virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
57         {
58                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
59                 if (!validated)
60                         return MOD_RES_PASSTHRU;
61
62                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!IS_OPER(user)))
63                 {
64                         /* Normally wouldnt be allowed here, are they exempt? */
65                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
66                                 if (InspIRCd::Match(user->MakeHost(), *x, ascii_case_insensitive_map))
67                                         return MOD_RES_PASSTHRU;
68
69                         /* Not exempt, BOOK EM DANNO! */
70                         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);
71                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
72                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
73                          */
74                         user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
75                         user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
76                         return MOD_RES_DENY;
77                 }
78                 return MOD_RES_PASSTHRU;
79         }
80
81         virtual void On005Numeric(std::string &output)
82         {
83                 output.append(" SECURELIST");
84         }
85
86         void Prioritize()
87         {
88                 Module* safelist = ServerInstance->Modules->Find("m_safelist.so");
89                 ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_BEFORE, &safelist);
90         }
91
92 };
93
94 MODULE_INIT(ModuleSecureList)