]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
e4fc76478f656ab7033effc0da6f1c118a6bba0a
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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         }
28  
29         virtual ~ModuleSecureList()
30         {
31         }
32  
33         virtual Version GetVersion()
34         {
35                 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
36         }
37
38         void OnRehash(userrec* user, const std::string &parameter)
39         {
40                 ConfigReader* MyConf = new ConfigReader(ServerInstance);
41                 allowlist.clear();
42
43                 for (int i = 0; i < MyConf->Enumerate("securehost"); i++)
44                         allowlist.push_back(MyConf->ReadValue("securehost", "exception", i));
45
46                 WaitTime = MyConf->ReadInteger("securelist", "waittime", "60", 0, true);
47                 delete MyConf;
48         }
49  
50         void Implements(char* List)
51         {
52                 List[I_OnRehash] = List[I_OnPreCommand] = List[I_On005Numeric] = 1;
53         }
54
55         /*
56          * OnPreCommand()
57          *   Intercept the LIST command.
58          */ 
59         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
60         {
61                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
62                 if (!validated)
63                         return 0;
64  
65                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!IS_OPER(user)))
66                 {
67                         /* Normally wouldnt be allowed here, are they exempt? */
68                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
69                                 if (ServerInstance->MatchText(user->MakeHost(), *x))
70                                         return 0;
71
72                         /* Not exempt, BOOK EM DANNO! */
73                         user->WriteServ("NOTICE %s :*** You cannot list within the first %d seconds of connecting. Please try again later.",user->nick, WaitTime);
74                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
75                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
76                          */
77                         user->WriteServ("321 %s Channel :Users Name",user->nick);
78                         user->WriteServ("323 %s :End of channel list.",user->nick);
79                         return 1;
80                 }
81                 return 0;
82         }
83
84         virtual void On005Numeric(std::string &output)
85         {
86                 output.append(" SECURELIST");
87         }
88
89         virtual Priority Prioritize()
90         {
91                 return (Priority)ServerInstance->Modules->PriorityBefore("m_safelist.so");
92         }
93
94 };
95  
96 MODULE_INIT(ModuleSecureList)