]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Update user-facing text and comments of SSL to TLS.
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012-2013, 2016 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007-2008, 2010 Craig Edwards <brain@inspircd.org>
10  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
11  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28 #include "modules/account.h"
29
30 typedef std::vector<std::string> AllowList;
31
32 class ModuleSecureList : public Module
33 {
34         AllowList allowlist;
35         bool exemptregistered;
36         unsigned int WaitTime;
37
38  public:
39         Version GetVersion() CXX11_OVERRIDE
40         {
41                 return Version("Prevents users from using the /LIST command until a predefined period has passed.", VF_VENDOR);
42         }
43
44         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
45         {
46                 AllowList newallows;
47
48                 ConfigTagList tags = ServerInstance->Config->ConfTags("securehost");
49                 for (ConfigIter i = tags.first; i != tags.second; ++i)
50                 {
51                         std::string host = i->second->getString("exception");
52                         if (host.empty())
53                                 throw ModuleException("<securehost:exception> is a required field at " + i->second->getTagLocation());
54                         newallows.push_back(host);
55                 }
56
57                 ConfigTag* tag = ServerInstance->Config->ConfValue("securelist");
58
59                 exemptregistered = tag->getBool("exemptregistered");
60                 WaitTime = tag->getDuration("waittime", 60, 1);
61                 allowlist.swap(newallows);
62         }
63
64
65         /*
66          * OnPreCommand()
67          *   Intercept the LIST command.
68          */
69         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
70         {
71                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
72                 if (!validated)
73                         return MOD_RES_PASSTHRU;
74
75                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!user->IsOper()))
76                 {
77                         /* Normally wouldnt be allowed here, are they exempt? */
78                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
79                                 if (InspIRCd::Match(user->MakeHost(), *x, ascii_case_insensitive_map))
80                                         return MOD_RES_PASSTHRU;
81
82                         const AccountExtItem* ext = GetAccountExtItem();
83                         if (exemptregistered && ext && ext->get(user))
84                                 return MOD_RES_PASSTHRU;
85
86                         /* Not exempt, BOOK EM DANNO! */
87                         user->WriteNotice("*** You cannot list within the first " + ConvToStr(WaitTime) + " seconds of connecting. Please try again later.");
88                         /* Some clients (e.g. mIRC, various java chat applets) muck up if they don't
89                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
90                          */
91                         user->WriteNumeric(RPL_LISTSTART, "Channel", "Users Name");
92                         user->WriteNumeric(RPL_LISTEND, "End of channel list.");
93                         return MOD_RES_DENY;
94                 }
95                 return MOD_RES_PASSTHRU;
96         }
97
98         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
99         {
100                 tokens["SECURELIST"];
101         }
102 };
103
104 MODULE_INIT(ModuleSecureList)