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
|
/* NickServ core functions
*
* (C) 2003-2013 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 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) anope_override
{
Anope::string pattern = params[0];
const NickCore *mync;
unsigned nnicks;
bool is_servadmin = source.HasCommand("nickserv/list");
int count = 0, from = 0, to = 0;
bool suspended, nsnoexpire, unconfirmed;
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(LIST_INCORRECT_RANGE);
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;
list.AddColumn("Nick").AddColumn("Last usermask");
Anope::map<NickAlias *> ordered_map;
for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
ordered_map[it->first] = it->second;
for (Anope::map<NickAlias *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it)
{
const NickAlias *na = it->second;
/* Don't show private nicks to non-services admins. */
if (na->nc->HasExt("PRIVATE") && !is_servadmin && na->nc != mync)
continue;
else if (nsnoexpire && !na->HasExt("NO_EXPIRE"))
continue;
else if (suspended && !na->nc->HasExt("SUSPENDED"))
continue;
else if (unconfirmed && !na->nc->HasExt("UNCONFIRMED"))
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->nick.c_str(), !na->last_usermask.empty() ? na->last_usermask.c_str() : "*@*");
if (na->nick.equals_ci(pattern) || Anope::Match(buf, pattern, false, true))
{
if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nnicks <= Config->NSListMax)
{
bool isnoexpire = false;
if (is_servadmin && na->HasExt("NO_EXPIRE"))
isnoexpire = true;
ListFormatter::ListEntry entry;
entry["Nick"] = (isnoexpire ? "!" : "") + na->nick;
if (na->nc->HasExt("HIDE_MASK") && !is_servadmin && na->nc != mync)
entry["Last usermask"] = "[Hostname hidden]";
else if (na->nc->HasExt("SUSPENDED"))
entry["Last usermask"] = "[Suspended]";
else if (na->nc->HasExt("UNCONFIRMED"))
entry["Last usermask"] = "[Unconfirmed]";
else
entry["Last usermask"] = na->last_usermask;
list.AddEntry(entry);
}
++count;
}
}
source.Reply(_("List of entries matching \002%s\002:"), pattern.c_str());
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 - %d/%d matches shown."), nnicks > Config->NSListMax ? Config->NSListMax : nnicks, nnicks);
return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Lists all registered nicknames which match the given\n"
"pattern, in \037nick!user@host\037 format. Nicks with the \002PRIVATE\002\n"
"option set will only be displayed to Services Operators with the\n"
"proper access. Nicks with the \002NOEXPIRE\002 option set will have\n"
"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"
" \002LIST *!joeuser@foo.com\002\n"
" Lists all registered nicks owned by joeuser@foo.com.\n"
" \n"
" \002LIST *Bot*!*@*\002\n"
" Lists all registered nicks with \002Bot\002 in their\n"
" names (case insensitive).\n"
" \n"
" \002LIST * NOEXPIRE\002\n"
" Lists all registered nicks which have been set to not expire.\n"
" \n"
" \002LIST #51-100\002\n"
" Lists all registered nicks within the given range (51-100)."));
if (!Config->RegexEngine.empty())
{
source.Reply(" ");
source.Reply(_("Regex matches are also supported using the %s engine.\n"
"Enclose your pattern in // if this is desired."), Config->RegexEngine.c_str());
}
return true;
}
};
class NSList : public Module
{
CommandNSList commandnslist;
public:
NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
commandnslist(this)
{
this->SetAuthor("Anope");
}
};
MODULE_INIT(NSList)
|