]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Add <securelist:exception> to allow certain masks to get around securelist.
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17
18 #include <vector>
19 #include "inspircd.h"
20
21 /* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
22
23 class ModuleSecureList : public Module
24 {
25  private:
26         std::vector<std::string> allowlist;
27  public:
28         ModuleSecureList(InspIRCd* Me) : Module::Module(Me)
29         {
30                 OnRehash(NULL,"");
31         }
32  
33         virtual ~ModuleSecureList()
34         {
35         }
36  
37         virtual Version GetVersion()
38         {
39                 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
40         }
41
42         void OnRehash(userrec* user, const std::string &parameter)
43         {
44                 ConfigReader* MyConf = new ConfigReader(ServerInstance);
45                 allowlist.clear();
46                 for (int i = 0; i < MyConf->Enumerate("securelist"); i++)
47                         allowlist.push_back(MyConf->ReadValue("securelist", "exception", i));
48                 DELETE(MyConf);
49         }
50  
51         void Implements(char* List)
52         {
53                 List[I_OnRehash] = List[I_OnPreCommand] = List[I_On005Numeric] = 1;
54         }
55
56         /*
57          * OnPreCommand()
58          *   Intercept the LIST command.
59          */ 
60         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
61         {
62                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
63                 if (!validated)
64                         return 0;
65  
66                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+60)) && (!*user->oper))
67                 {
68                         /* Normally wouldnt be allowed here, are they exempt? */
69                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
70                                 if (ServerInstance->MatchText(user->MakeHost(), *x))
71                                         return 0;
72
73                         /* Not exempt, BOOK EM DANNO! */
74                         user->WriteServ("NOTICE %s :*** You cannot list within the first minute of connecting. Please try again later.",user->nick);
75                         /* Some crap clients (read: mIRC, various java chat applets) muck up if they don't
76                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
77                          */
78                         user->WriteServ("321 %s Channel :Users Name",user->nick);
79                         user->WriteServ("323 %s :End of channel list.",user->nick);
80                         return 1;
81                 }
82                 return 0;
83         }
84
85         virtual void On005Numeric(std::string &output)
86         {
87                 output.append(" SECURELIST");
88         }
89
90         virtual Priority Prioritize()
91         {
92                 return (Priority)ServerInstance->PriorityBefore("m_safelist.so");
93         }
94
95 };
96  
97  
98  
99 /******************************************************************************************************/
100  
101 class ModuleSecureListFactory : public ModuleFactory
102 {
103  public:
104         ModuleSecureListFactory()
105         {
106         }
107  
108         ~ModuleSecureListFactory()
109         {
110         }
111  
112         virtual Module * CreateModule(InspIRCd* Me)
113         {
114                 return new ModuleSecureList(Me);
115         }
116  
117 };
118  
119 extern "C" void * init_module( void )
120 {
121         return new ModuleSecureListFactory;
122 }