]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
c553aa7423f2c30fa7f1ec4f0945b24a79059970
[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);
37         }
38
39         void OnRehash(User* user)
40         {
41                 ConfigReader MyConf;
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         }
49
50
51         /*
52          * OnPreCommand()
53          *   Intercept the LIST command.
54          */
55         virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
56         {
57                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
58                 if (!validated)
59                         return MOD_RES_PASSTHRU;
60
61                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!IS_OPER(user)))
62                 {
63                         /* Normally wouldnt be allowed here, are they exempt? */
64                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
65                                 if (InspIRCd::Match(user->MakeHost(), *x, ascii_case_insensitive_map))
66                                         return MOD_RES_PASSTHRU;
67
68                         /* Not exempt, BOOK EM DANNO! */
69                         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);
70                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
71                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
72                          */
73                         user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
74                         user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
75                         return MOD_RES_DENY;
76                 }
77                 return MOD_RES_PASSTHRU;
78         }
79
80         virtual void On005Numeric(std::string &output)
81         {
82                 output.append(" SECURELIST");
83         }
84 };
85
86 MODULE_INIT(ModuleSecureList)