1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/* NickServ core functions
*
* (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#include "module.h"
class CommandNSAccess : public Command
{
private:
void DoAdd(CommandSource &source, NickCore *nc, const Anope::string &mask)
{
if (mask.empty())
{
this->OnSyntaxError(source, "ADD");
return;
}
if (Anope::ReadOnly)
{
source.Reply(READ_ONLY_MODE);
return;
}
if (nc->access.size() >= Config->GetModule(this->owner)->Get<unsigned>("accessmax", "32"))
{
source.Reply(_("Sorry, the maximum of %d access entries has been reached."), Config->GetModule(this->owner)->Get<unsigned>("accessmax"));
return;
}
if (nc->FindAccess(mask))
{
source.Reply(_("Mask \002%s\002 already present on %s's access list."), mask.c_str(), nc->display.c_str());
return;
}
nc->AddAccess(mask);
Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to ADD mask " << mask << " to " << nc->display;
source.Reply(_("\002%s\002 added to %s's access list."), mask.c_str(), nc->display.c_str());
return;
}
void DoDel(CommandSource &source, NickCore *nc, const Anope::string &mask)
{
if (mask.empty())
{
this->OnSyntaxError(source, "DEL");
return;
}
if (Anope::ReadOnly)
{
source.Reply(READ_ONLY_MODE);
return;
}
if (!nc->FindAccess(mask))
{
source.Reply(_("\002%s\002 not found on %s's access list."), mask.c_str(), nc->display.c_str());
return;
}
nc->EraseAccess(mask);
Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to DELETE mask " << mask << " from " << nc->display;
source.Reply(_("\002%s\002 deleted from %s's access list."), mask.c_str(), nc->display.c_str());
return;
}
void DoList(CommandSource &source, NickCore *nc, const Anope::string &mask)
{
unsigned i, end;
if (nc->access.empty())
{
source.Reply(_("%s's access list is empty."), nc->display.c_str());
return;
}
source.Reply(_("Access list for %s:"), nc->display.c_str());
for (i = 0, end = nc->access.size(); i < end; ++i)
{
Anope::string access = nc->GetAccess(i);
if (!mask.empty() && !Anope::Match(access, mask))
continue;
source.Reply(" %s", access.c_str());
}
return;
}
public:
CommandNSAccess(Module *creator) : Command(creator, "nickserv/access", 1, 3)
{
this->SetDesc(_("Modify the list of authorized addresses"));
this->SetSyntax(_("ADD [\037nickname\037] \037mask\037"));
this->SetSyntax(_("DEL [\037nickname\037] \037mask\037"));
this->SetSyntax(_("LIST [\037nickname\037]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
const Anope::string &cmd = params[0];
Anope::string nick, mask;
if (cmd.equals_ci("LIST"))
nick = params.size() > 1 ? params[1] : "";
else
{
nick = params.size() == 3 ? params[1] : "";
mask = params.size() > 1 ? params[params.size() - 1] : "";
}
NickCore *nc;
if (!nick.empty())
{
const NickAlias *na = NickAlias::Find(nick);
if (na == NULL)
{
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
return;
}
else if (na->nc != source.GetAccount() && !source.HasPriv("nickserv/access"))
{
source.Reply(ACCESS_DENIED);
return;
}
else if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && source.GetAccount() != na->nc && na->nc->IsServicesOper() && !cmd.equals_ci("LIST"))
{
source.Reply(_("You may view but not modify the access list of other Services Operators."));
return;
}
nc = na->nc;
}
else
nc = source.nc;
if (!mask.empty() && (mask.find('@') == Anope::string::npos || mask.find('!') != Anope::string::npos))
{
source.Reply(BAD_USERHOST_MASK);
source.Reply(MORE_INFO, Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), source.command.c_str());
}
else if (cmd.equals_ci("LIST"))
return this->DoList(source, nc, mask);
else if (nc->HasExt("NS_SUSPENDED"))
source.Reply(NICK_X_SUSPENDED, nc->display.c_str());
else if (cmd.equals_ci("ADD"))
return this->DoAdd(source, nc, mask);
else if (cmd.equals_ci("DEL"))
return this->DoDel(source, nc, mask);
else
this->OnSyntaxError(source, "");
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Modifies or displays the access list for your nick. This\n"
"is the list of addresses which will be automatically\n"
"recognized by %s as allowed to use the nick. If\n"
"you want to use the nick from a different address, you\n"
"need to send an \002IDENTIFY\002 command to make %s\n"
"recognize you. Services Operators may provide a nick\n"
"to modify other users' access lists.\n"
" \n"
"Examples:\n"
" \n"
" \002ACCESS ADD anyone@*.bepeg.com\002\n"
" Allows access to user \002anyone\002 from any machine in\n"
" the \002bepeg.com\002 domain.\n"
" \n"
" \002ACCESS DEL anyone@*.bepeg.com\002\n"
" Reverses the previous command.\n"
" \n"
" \002ACCESS LIST\002\n"
" Displays the current access list."), source.service->nick.c_str(), source.service->nick.c_str());
return true;
}
};
class NSAccess : public Module
{
CommandNSAccess commandnsaccess;
public:
NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
commandnsaccess(this)
{
}
void OnNickRegister(User *u, NickAlias *na, const Anope::string &) anope_override
{
if (u && Config->GetModule(this)->Get<bool>("addaccessonreg"))
na->nc->AddAccess(u->Mask());
}
};
MODULE_INIT(NSAccess)
|