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