2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2012 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
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.
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
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/>.
31 const std::string name;
32 const std::string password;
33 const std::string hash;
34 const std::string vhost;
36 CustomVhost(const std::string& n, const std::string& p, const std::string& h, const std::string& v)
44 bool CheckPass(User* user, const std::string& pass) const
46 return ServerInstance->PassCompare(user, password, pass, hash);
50 typedef std::multimap<std::string, CustomVhost> CustomVhostMap;
51 typedef std::pair<CustomVhostMap::iterator, CustomVhostMap::iterator> MatchingConfigs;
55 class CommandVhost : public Command
58 CustomVhostMap vhosts;
60 CommandVhost(Module* Creator)
61 : Command(Creator, "VHOST", 2)
63 syntax = "<username> <password>";
66 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
68 MatchingConfigs matching = vhosts.equal_range(parameters[0]);
70 for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i)
72 CustomVhost config = i->second;
73 if (config.CheckPass(user, parameters[1]))
75 user->WriteNotice("Setting your VHost: " + config.vhost);
76 user->ChangeDisplayedHost(config.vhost);
81 user->WriteNotice("Invalid username or password.");
86 class ModuleVHost : public Module
96 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
98 CustomVhostMap newhosts;
99 ConfigTagList tags = ServerInstance->Config->ConfTags("vhost");
100 for (ConfigIter i = tags.first; i != tags.second; ++i)
102 ConfigTag* tag = i->second;
103 std::string mask = tag->getString("host");
105 throw ModuleException("<vhost:host> is empty! at " + tag->getTagLocation());
107 std::string username = tag->getString("user");
108 if (username.empty())
109 throw ModuleException("<vhost:user> is empty! at " + tag->getTagLocation());
111 std::string pass = tag->getString("pass");
113 throw ModuleException("<vhost:pass> is empty! at " + tag->getTagLocation());
115 const std::string hash = tag->getString("hash", "plaintext", 1);
116 if (stdalgo::string::equalsci(hash, "plaintext"))
118 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "<vhost> tag for %s at %s contains an plain text password, this is insecure!",
119 username.c_str(), tag->getTagLocation().c_str());
122 CustomVhost vhost(username, pass, hash, mask);
123 newhosts.insert(std::make_pair(username, vhost));
126 cmd.vhosts.swap(newhosts);
129 Version GetVersion() CXX11_OVERRIDE
131 return Version("Allows the server administrator to define accounts which can grant a custom virtual host.", VF_VENDOR);
135 MODULE_INIT(ModuleVHost)