]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_vhost.cpp
72b5d669c27ee24d418597cdffb7ae7591479144
[user/henk/code/inspircd.git] / src / modules / m_vhost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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: Provides masking of user hostnames via traditional /VHOST command */
17
18 /** Handle /VHOST
19  */
20 class CommandVhost : public Command
21 {
22  public:
23         CommandVhost(Module* Creator) : Command(Creator,"VHOST", 2)
24         {
25                 syntax = "<username> <password>";
26         }
27
28         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
29         {
30                 ConfigReader *Conf = new ConfigReader(ServerInstance);
31
32                 for (int index = 0; index < Conf->Enumerate("vhost"); index++)
33                 {
34                         std::string mask = Conf->ReadValue("vhost","host",index);
35                         std::string username = Conf->ReadValue("vhost","user",index);
36                         std::string pass = Conf->ReadValue("vhost","pass",index);
37                         std::string hash = Conf->ReadValue("vhost","hash",index);
38
39                         if ((!strcmp(parameters[0].c_str(),username.c_str())) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()))
40                         {
41                                 if (!mask.empty())
42                                 {
43                                         user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
44                                         user->ChangeDisplayedHost(mask.c_str());
45                                         delete Conf;
46                                         return CMD_SUCCESS;
47                                 }
48                         }
49                 }
50
51                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
52                 delete Conf;
53                 return CMD_FAILURE;
54         }
55 };
56
57 class ModuleVHost : public Module
58 {
59  private:
60         CommandVhost cmd;
61
62  public:
63         ModuleVHost(InspIRCd* Me) : Module(Me), cmd(this)
64         {
65                 ServerInstance->AddCommand(&cmd);
66         }
67
68         virtual ~ModuleVHost()
69         {
70         }
71
72
73         virtual Version GetVersion()
74         {
75                 return Version("Provides masking of user hostnames via traditional /VHOST command",VF_VENDOR,API_VERSION);
76         }
77
78 };
79
80 MODULE_INIT(ModuleVHost)
81