2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2006 Robin Burchell <robin+git@viroteck.net>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 const std::string name;
28 const std::string password;
29 const std::string hash;
30 const std::string vhost;
32 CustomVhost(const std::string& n, const std::string& p, const std::string& h, const std::string& v)
40 bool CheckPass(User* user, const std::string& pass) const
42 return ServerInstance->PassCompare(user, password, pass, hash);
46 typedef std::multimap<std::string, CustomVhost> CustomVhostMap;
47 typedef std::pair<CustomVhostMap::iterator, CustomVhostMap::iterator> MatchingConfigs;
51 class CommandVhost : public Command
54 CustomVhostMap vhosts;
56 CommandVhost(Module* Creator)
57 : Command(Creator, "VHOST", 2)
59 syntax = "<username> <password>";
62 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
64 MatchingConfigs matching = vhosts.equal_range(parameters[0]);
66 for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i)
68 CustomVhost config = i->second;
69 if (config.CheckPass(user, parameters[1]))
71 user->WriteNotice("Setting your VHost: " + config.vhost);
72 user->ChangeDisplayedHost(config.vhost);
77 user->WriteNotice("Invalid username or password.");
82 class ModuleVHost : public Module
92 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
94 CustomVhostMap newhosts;
95 ConfigTagList tags = ServerInstance->Config->ConfTags("vhost");
96 for (ConfigIter i = tags.first; i != tags.second; ++i)
98 ConfigTag* tag = i->second;
99 std::string mask = tag->getString("host");
101 throw ModuleException("<vhost:host> is empty! at " + tag->getTagLocation());
102 std::string username = tag->getString("user");
103 if (username.empty())
104 throw ModuleException("<vhost:user> is empty! at " + tag->getTagLocation());
105 std::string pass = tag->getString("pass");
107 throw ModuleException("<vhost:pass> is empty! at " + tag->getTagLocation());
108 std::string hash = tag->getString("hash");
110 CustomVhost vhost(username, pass, hash, mask);
111 newhosts.insert(std::make_pair(username, vhost));
114 cmd.vhosts.swap(newhosts);
117 Version GetVersion() CXX11_OVERRIDE
119 return Version("Provides masking of user hostnames via the VHOST command", VF_VENDOR);
123 MODULE_INIT(ModuleVHost)