]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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                 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(1,1,0,0,VF_VENDOR,API_VERSION);
38         }
39
40         void OnRehash(User* user, const std::string &parameter)
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 int OnPreCommand(const std::string &command, const char** parameters, int pcnt, 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 0;
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 (ServerInstance->MatchText(user->MakeHost(), *x))
68                                         return 0;
69
70                         /* Not exempt, BOOK EM DANNO! */
71                         user->WriteServ("NOTICE %s :*** You cannot list within the first %d seconds of connecting. Please try again later.",user->nick, 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->WriteServ("321 %s Channel :Users Name",user->nick);
76                         user->WriteServ("323 %s :End of channel list.",user->nick);
77                         return 1;
78                 }
79                 return 0;
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, PRIO_BEFORE, &safelist);
91         }
92
93 };
94  
95 MODULE_INIT(ModuleSecureList)