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
|
/*
* 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"
class CommandOSOper : public Command
{
bool HasPrivs(CommandSource &source, OperType *ot) const
{
std::list<Anope::string> commands = ot->GetCommands(), privs = ot->GetPrivs();
for (std::list<Anope::string>::iterator it = commands.begin(); it != commands.end(); ++it)
if (!source.HasCommand(*it))
return false;
for (std::list<Anope::string>::iterator it = privs.begin(); it != privs.end(); ++it)
if (!source.HasPriv(*it))
return false;
return true;
}
public:
CommandOSOper(Module *creator) : Command(creator, "operserv/oper", 1, 3)
{
this->SetDesc(_("View and change Services Operators"));
this->SetSyntax(_("ADD \037oper\037 \037type\037"));
this->SetSyntax(_("DEL \037oper\037"));
this->SetSyntax(_("INFO [\037type\037]"));
this->SetSyntax("LIST");
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
const Anope::string &subcommand = params[0];
if (subcommand.equals_ci("ADD") && params.size() > 2)
{
const Anope::string &oper = params[1];
const Anope::string &otype = params[2];
if (!source.HasPriv("operserv/oper/modify"))
{
source.Reply(_("Access denied. You do not have the operator privilege \002{0}\002."), "operserv/oper/modify");
return;
}
NickServ::Nick *na = NickServ::FindNick(oper);
if (na == NULL)
{
source.Reply(_("\002{0}\002 isn't currently online."), oper);
return;
}
OperType *ot = OperType::Find(otype);
if (ot == NULL)
{
source.Reply(_("Oper type \002{0}\002 has not been configured."), otype);
return;
}
if (!HasPrivs(source, ot))
{
source.Reply(_("Access denied."));
return;
}
Oper *o = na->GetAccount()->GetOper();
if (o != nullptr)
{
o->Delete();
}
o = Serialize::New<Oper *>();
o->SetName(na->GetAccount()->GetDisplay());
o->SetType(ot);
o->SetRequireOper(true);
na->GetAccount()->SetOper(o);
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
logger.Admin(source, _("{source} used {command} to add {0} as an oper of type {1}"), na->GetNick(), ot->GetName());
source.Reply("\002{0}\002 (\002{1}\002) added to the \002{2}\002 list.", na->GetNick(), na->GetAccount()->GetDisplay(), ot->GetName());
}
else if (subcommand.equals_ci("DEL") && params.size() > 1)
{
const Anope::string &oper = params[1];
if (!source.HasPriv("operserv/oper/modify"))
{
source.Reply(_("Access denied. You do not have the operator privilege \002{0}\002."), "operserv/oper/modify");
return;
}
NickServ::Nick *na = NickServ::FindNick(oper);
if (na == nullptr || na->GetAccount() == nullptr)
{
source.Reply(_("\002{0}\002 isn't registered."), oper);
return;
}
Oper *o = na->GetAccount()->GetOper();
if (o == nullptr)
{
source.Reply(_("Nick \002{0}\002 is not a Services Operator."), oper);
return;
}
if (!HasPrivs(source, o->GetType()))
{
source.Reply(_("Access denied."));
return;
}
o->Delete();
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
logger.Admin(source, _("{source} used {command} to remove {0}"), na->GetNick());
source.Reply(_("Oper privileges removed from \002{0}\002 (\002{1}\002)."), na->GetNick(), na->GetAccount()->GetDisplay());
}
else if (subcommand.equals_ci("LIST"))
{
source.Reply(_("Name Type"));
for (NickServ::Account *nc : NickServ::service->GetAccountList())
{
Oper *oper = nc->GetOper();
if (oper == nullptr)
continue;
source.Reply(Anope::printf("%-8s %s", oper->GetName().c_str(), oper->GetType()->GetName().c_str()));
for (User *u : nc->users)
source.Reply(_(" \002{0}\002 is online using this oper block."), u->nick);
}
}
else if (subcommand.equals_ci("INFO"))
{
if (params.size() < 2)
{
source.Reply(_("Available opertypes:"));
for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i)
{
OperType *ot = Config->MyOperTypes[i];
source.Reply("%s", ot->GetName().c_str());
}
return;
}
Anope::string fulltype = params[1];
if (params.size() > 2)
fulltype += " " + params[2];
OperType *ot = OperType::Find(fulltype);
if (ot == NULL)
{
source.Reply(_("Oper type \002{0}\002 has not been configured."), fulltype);
return;
}
if (ot->GetCommands().empty())
{
source.Reply(_("Opertype \002{0}\002 has no allowed commands."), ot->GetName());
}
else
{
source.Reply(_("Available commands for \002{0}\002:"), ot->GetName());
Anope::string buf;
std::list<Anope::string> cmds = ot->GetCommands();
for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it)
{
buf += *it + " ";
if (buf.length() > 400)
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (!buf.empty())
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (ot->GetPrivs().empty())
{
source.Reply(_("Opertype \002{0}\002 has no allowed privileges."), ot->GetName());
}
else
{
source.Reply(_("Available privileges for \002{0}\002:"), ot->GetName());
Anope::string buf;
std::list<Anope::string> privs = ot->GetPrivs();
for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it)
{
buf += *it + " ";
if (buf.length() > 400)
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (!buf.empty())
{
source.Reply("%s", buf.c_str());
buf.clear();
}
}
if (!ot->modes.empty())
source.Reply(_("Opertype \002{0}\002 receives modes \002{1}\002 once identified."), ot->GetName(), ot->modes);
}
else
{
this->OnSyntaxError(source);
}
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Allows you to change and view Services Operators.\n"
" Note that operators removed by this command but are still set in the configuration file are not permanently affected by this."));
return true;
}
};
class OSOper : public Module
{
CommandOSOper commandosoper;
public:
OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
, commandosoper(this)
{
}
};
MODULE_INIT(OSOper)
|