]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_userip.cpp
838e129c13e529751e0952364591c29c332da1ff
[user/henk/code/inspircd.git] / src / modules / m_userip.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
11  *   Copyright (C) 2007 Craig Edwards <brain@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
29 /** Handle /USERIP
30  */
31 class CommandUserip : public Command
32 {
33  public:
34         CommandUserip(Module* Creator) : Command(Creator,"USERIP", 1)
35         {
36                 syntax = "<nick> [<nick>]+";
37         }
38
39         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
40         {
41                 std::string retbuf;
42                 int nicks = 0;
43                 bool checked_privs = false;
44                 bool has_privs = false;
45
46                 for (size_t i = 0; i < parameters.size(); i++)
47                 {
48                         User *u = ServerInstance->FindNickOnly(parameters[i]);
49                         if ((u) && (u->registered == REG_ALL))
50                         {
51                                 // Anyone may query their own IP
52                                 if (u != user)
53                                 {
54                                         if (!checked_privs)
55                                         {
56                                                 // Do not trigger the insufficient privileges message more than once
57                                                 checked_privs = true;
58                                                 has_privs = user->HasPrivPermission("users/auspex");
59                                                 if (!has_privs)
60                                                         user->WriteNumeric(ERR_NOPRIVILEGES, "Permission Denied - You do not have the required operator privileges");
61                                         }
62
63                                         if (!has_privs)
64                                                 continue;
65                                 }
66
67                                 retbuf = retbuf + u->nick + (u->IsOper() ? "*" : "") + "=";
68                                 if (u->IsAway())
69                                         retbuf += "-";
70                                 else
71                                         retbuf += "+";
72                                 retbuf += u->ident + "@" + u->GetIPString() + " ";
73                                 nicks++;
74                         }
75                 }
76
77                 if (nicks != 0)
78                         user->WriteNumeric(RPL_USERIP, retbuf);
79
80                 return CMD_SUCCESS;
81         }
82 };
83
84 class ModuleUserIP : public Module
85 {
86         CommandUserip cmd;
87  public:
88         ModuleUserIP()
89                 : cmd(this)
90         {
91         }
92
93         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
94         {
95                 tokens["USERIP"];
96         }
97
98         Version GetVersion() CXX11_OVERRIDE
99         {
100                 return Version("Adds the /USERIP command which allows users to find out the IP address of one or more connected users.", VF_VENDOR);
101         }
102 };
103
104 MODULE_INIT(ModuleUserIP)