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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/*
* Anope IRC Services
*
* Copyright (C) 2003-2017 Anope Team <team@anope.org>
*
* This file is part of Anope. Anope is free software; you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software
* Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "module.h"
#include "modules/nickserv/info.h"
#include "modules/nickserv/set.h"
class CommandNSList : public Command
{
public:
CommandNSList(Module *creator) : Command(creator, "nickserv/list", 1, 2)
{
this->SetDesc(_("List all registered nicknames that match a given pattern"));
this->SetSyntax(_("\037pattern\037 [SUSPENDED] [NOEXPIRE] [UNCONFIRMED]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
Anope::string pattern = params[0];
const NickServ::Account *mync;
unsigned nnicks;
bool is_servadmin = source.HasCommand("nickserv/list");
int count = 0, from = 0, to = 0;
bool suspended, nsnoexpire, unconfirmed;
unsigned listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50");
suspended = nsnoexpire = unconfirmed = false;
if (pattern[0] == '#')
{
Anope::string n1, n2;
sepstream(pattern.substr(1), '-').GetToken(n1, 0);
sepstream(pattern, '-').GetToken(n2, 1);
try
{
from = convertTo<int>(n1);
to = convertTo<int>(n2);
}
catch (const ConvertException &)
{
source.Reply(_("Incorrect range specified. The correct syntax is \002#\037from\037-\037to\037\002."));
return;
}
pattern = "*";
}
nnicks = 0;
if (is_servadmin && params.size() > 1)
{
Anope::string keyword;
spacesepstream keywords(params[1]);
while (keywords.GetToken(keyword))
{
if (keyword.equals_ci("NOEXPIRE"))
nsnoexpire = true;
if (keyword.equals_ci("SUSPENDED"))
suspended = true;
if (keyword.equals_ci("UNCONFIRMED"))
unconfirmed = true;
}
}
mync = source.nc;
ListFormatter list(source.GetAccount());
list.AddColumn(_("Nick")).AddColumn(_("Last usermask"));
Anope::map<NickServ::Nick *> ordered_map;
for (NickServ::Nick *na : NickServ::service->GetNickList())
ordered_map[na->GetNick()] = na;
for (Anope::map<NickServ::Nick *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it)
{
NickServ::Nick *na = it->second;
/* Don't show private nicks to non-services admins. */
if (na->GetAccount()->IsPrivate() && !is_servadmin && na->GetAccount() != mync)
continue;
else if (nsnoexpire && !na->IsNoExpire())
continue;
else if (suspended && !na->GetAccount()->HasFieldS("NS_SUSPENDED"))
continue;
else if (unconfirmed && !na->GetAccount()->IsUnconfirmed())
continue;
/* We no longer compare the pattern against the output buffer.
* Instead we build a nice nick!user@host buffer to compare.
* The output is then generated separately. -TheShadow */
Anope::string buf = Anope::printf("%s!%s", na->GetNick().c_str(), !na->GetLastUsermask().empty() ? na->GetLastUsermask().c_str() : "*@*");
if (na->GetNick().equals_ci(pattern) || Anope::Match(buf, pattern, false, true))
{
if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nnicks <= listmax)
{
bool isnoexpire = false;
if (is_servadmin && na->IsNoExpire())
isnoexpire = true;
ListFormatter::ListEntry entry;
entry["Nick"] = (isnoexpire ? "!" : "") + na->GetNick();
if (na->GetAccount()->IsHideMask() && !is_servadmin && na->GetAccount() != mync)
entry["Last usermask"] = Language::Translate(source.GetAccount(), _("[Hostname hidden]"));
else if (na->GetAccount()->HasFieldS("NS_SUSPENDED"))
entry["Last usermask"] = Language::Translate(source.GetAccount(), _("[Suspended]"));
else if (na->GetAccount()->IsUnconfirmed())
entry["Last usermask"] = Language::Translate(source.GetAccount(), _("[Unconfirmed]"));
else
entry["Last usermask"] = na->GetLastUsermask();
list.AddEntry(entry);
}
++count;
}
}
source.Reply(_("List of entries matching \002{0}\002:"), pattern);
std::vector<Anope::string> replies;
list.Process(replies);
for (unsigned i = 0; i < replies.size(); ++i)
source.Reply(replies[i]);
source.Reply(_("End of list - \002{0}\002/\002{1}\002 matches shown."), nnicks > listmax ? listmax : nnicks, nnicks);
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Lists all registered nicknames which match the given pattern, in \037nick!user@host\037 format."
" Nicks with the \002PRIVATE\002 option set will only be displayed to Services Operators with the proper access."
" Nicks with the \002NOEXPIRE\002 option set will have a \002!\002 prefixed to the nickname for Services Operators to see.\n"
"\n"
"Note that a preceding '#' specifies a range.\n"
"\n"
"If the SUSPENDED, UNCONFIRMED or NOEXPIRE options are given, only\n"
"nicks which, respectively, are SUSPENDED, UNCONFIRMED or have the\n"
"NOEXPIRE flag set will be displayed. If multiple options are\n"
"given, all nicks matching at least one option will be displayed.\n"
"Note that these options are limited to \037Services Operators\037.\n"
"\n"
"Examples:\n"
"\n"
" {0} *!joeuser@foo.com\n"
" Lists all registered nicks owned by joeuser@foo.com.\n"
"\n"
" {0} *Bot*!*@*\n"
" Lists all registered nicks with \002Bot\002 in their names (case insensitive).\n"
"\n"
" {0} * NOEXPIRE\n"
" Lists all registered nicks which have been set to not expire.\n"
"\n"
" {0} #51-100\n"
" Lists all registered nicks within the given range (51-100)."));
const Anope::string ®exengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
if (!regexengine.empty())
{
source.Reply(" ");
source.Reply(_("Regex matches are also supported using the {0} engine. Enclose your pattern in // if this is desired."), regexengine);
}
return true;
}
};
class CommandNSSetPrivate : public Command
{
public:
CommandNSSetPrivate(Module *creator, const Anope::string &sname = "nickserv/set/private", size_t min = 1) : Command(creator, sname, min, min + 1)
{
this->SetDesc(_("Prevent your account from appearing in the LIST command"));
this->SetSyntax("{ON | OFF}");
}
void Run(CommandSource &source, const Anope::string &user, const Anope::string ¶m)
{
if (Anope::ReadOnly)
{
source.Reply(_("Services are in read-only mode."));
return;
}
NickServ::Nick *na = NickServ::FindNick(user);
if (!na)
{
source.Reply(_("\002{0}\002 isn't registered."), user);
return;
}
NickServ::Account *nc = na->GetAccount();
EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
if (param.equals_ci("ON"))
{
logger.Command(nc == source.GetAccount() ? LogType::COMMAND : LogType::ADMIN, source,
_("{source} used {command} to enable private for {0}"), nc->GetDisplay());
nc->SetPrivate(true);
source.Reply(_("Private option is now \002on\002 for \002{0}\002."), nc->GetDisplay());
}
else if (param.equals_ci("OFF"))
{
logger.Command(nc == source.GetAccount() ? LogType::COMMAND : LogType::ADMIN, source,
_("{source} used {command} to disable private for {0}"), nc->GetDisplay());
nc->SetPrivate(true);
source.Reply(_("Private option is now \002off\002 for \002{0}\002."), nc->GetDisplay());
}
else
this->OnSyntaxError(source, "PRIVATE");
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
this->Run(source, source.nc->GetDisplay(), params[0]);
}
bool OnHelp(CommandSource &source, const Anope::string &) override
{
source.Reply(_("Turns the privacy option on or off for your account."
" When \002PRIVATE\002 is set, your account will not appear in the account list."
" However, anyone who knows your account can still request information about it."));
return true;
}
};
class CommandNSSASetPrivate : public CommandNSSetPrivate
{
public:
CommandNSSASetPrivate(Module *creator) : CommandNSSetPrivate(creator, "nickserv/saset/private", 2)
{
this->ClearSyntax();
this->SetSyntax(_("\037account\037 {ON | OFF}"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
this->Run(source, params[0], params[1]);
}
bool OnHelp(CommandSource &source, const Anope::string &) override
{
source.Reply(_("Turns the privacy option on or off for \037account\037."
" When \002PRIVATE\002 is set, the account will not appear in the account list."
" However, anyone who knows your account can still request information about it."));
return true;
}
};
class NSList : public Module
, public EventHook<Event::NickInfo>
{
CommandNSList commandnslist;
CommandNSSetPrivate commandnssetprivate;
CommandNSSASetPrivate commandnssasetprivate;
public:
NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
, EventHook<Event::NickInfo>(this)
, commandnslist(this)
, commandnssetprivate(this)
, commandnssasetprivate(this)
{
}
void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_all) override
{
if (!show_all)
return;
if (na->GetAccount()->IsPrivate())
info.AddOption(_("Private"));
}
};
MODULE_INIT(NSList)
|