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
|
/* OperServ core functions
*
* (C) 2003-2010 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 CommandOSSet : public Command
{
private:
CommandReturn DoList(User *u)
{
Log(LOG_ADMIN, u, this);
LanguageString index;
index = allow_ignore ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF;
u->SendMessage(OperServ, index, "IGNORE");
index = readonly ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF;
u->SendMessage(OperServ, index, "READONLY");
index = debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF;
u->SendMessage(OperServ, index, "DEBUG");
index = noexpire ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF;
u->SendMessage(OperServ, index, "NOEXPIRE");
return MOD_CONT;
}
CommandReturn DoSetIgnore(User *u, const std::vector<Anope::string> ¶ms)
{
Anope::string setting = params.size() > 1 ? params[1] : "";
if (setting.empty())
{
this->OnSyntaxError(u, "IGNORE");
return MOD_CONT;
}
if (setting.equals_ci("ON"))
{
Log(LOG_ADMIN, u, this) << "IGNORE ON";
allow_ignore = 1;
u->SendMessage(OperServ, OPER_SET_IGNORE_ON);
}
else if (setting.equals_ci("OFF"))
{
Log(LOG_ADMIN, u, this) << "IGNORE OFF";
allow_ignore = 0;
u->SendMessage(OperServ, OPER_SET_IGNORE_OFF);
}
else
u->SendMessage(OperServ, OPER_SET_IGNORE_ERROR);
return MOD_CONT;
}
CommandReturn DoSetReadOnly(User *u, const std::vector<Anope::string> ¶ms)
{
Anope::string setting = params.size() > 1 ? params[1] : "";
if (setting.empty())
{
this->OnSyntaxError(u, "READONLY");
return MOD_CONT;
}
if (setting.equals_ci("ON"))
{
readonly = true;
Log(LOG_ADMIN, u, this) << "READONLY ON";
u->SendMessage(OperServ, OPER_SET_READONLY_ON);
}
else if (setting.equals_ci("OFF"))
{
readonly = false;
Log(LOG_ADMIN, u, this) << "READONLY OFF";
u->SendMessage(OperServ, OPER_SET_READONLY_OFF);
}
else
u->SendMessage(OperServ, OPER_SET_READONLY_ERROR);
return MOD_CONT;
}
CommandReturn DoSetSuperAdmin(User *u, const std::vector<Anope::string> ¶ms)
{
Anope::string setting = params.size() > 1 ? params[1] : "";
if (setting.empty())
{
this->OnSyntaxError(u, "SUPERADMIN");
return MOD_CONT;
}
/**
* Allow the user to turn super admin on/off
*
* Rob
**/
if (!Config->SuperAdmin)
u->SendMessage(OperServ, OPER_SUPER_ADMIN_NOT_ENABLED);
else if (setting.equals_ci("ON"))
{
u->isSuperAdmin = 1;
u->SendMessage(OperServ, OPER_SUPER_ADMIN_ON);
Log(LOG_ADMIN, u, this) << "SUPERADMIN ON";
ircdproto->SendGlobops(OperServ, GetString(OPER_SUPER_ADMIN_WALL_ON).c_str(), u->nick.c_str());
}
else if (setting.equals_ci("OFF"))
{
u->isSuperAdmin = 0;
u->SendMessage(OperServ, OPER_SUPER_ADMIN_OFF);
Log(LOG_ADMIN, u, this) << "SUPERADMIN OFF";
ircdproto->SendGlobops(OperServ, GetString(OPER_SUPER_ADMIN_WALL_OFF).c_str(), u->nick.c_str());
}
else
u->SendMessage(OperServ, OPER_SUPER_ADMIN_SYNTAX);
return MOD_CONT;
}
CommandReturn DoSetDebug(User *u, const std::vector<Anope::string> ¶ms)
{
Anope::string setting = params.size() > 1 ? params[1] : "";
if (setting.empty())
{
this->OnSyntaxError(u, "DEBUG");
return MOD_CONT;
}
if (setting.equals_ci("ON"))
{
debug = 1;
Log(LOG_ADMIN, u, this) << "DEBUG ON";
u->SendMessage(OperServ, OPER_SET_DEBUG_ON);
}
else if (setting.equals_ci("OFF") || (setting[0] == '0' && setting.is_number_only() && !convertTo<int>(setting)))
{
Log(LOG_ADMIN, u, this) << "DEBUG OFF";
debug = 0;
u->SendMessage(OperServ, OPER_SET_DEBUG_OFF);
}
else if (setting.is_number_only() && convertTo<int>(setting) > 0)
{
debug = convertTo<int>(setting);
Log(LOG_ADMIN, u, this) << "DEBUG " << debug;
u->SendMessage(OperServ, OPER_SET_DEBUG_LEVEL, debug);
}
else
u->SendMessage(OperServ, OPER_SET_DEBUG_ERROR);
return MOD_CONT;
}
CommandReturn DoSetNoExpire(User *u, const std::vector<Anope::string> ¶ms)
{
Anope::string setting = params.size() > 1 ? params[1] : "";
if (setting.empty())
{
this->OnSyntaxError(u, "NOEXPIRE");
return MOD_CONT;
}
if (setting.equals_ci("ON"))
{
noexpire = true;
Log(LOG_ADMIN, u, this) << "NOEXPIRE ON";
u->SendMessage(OperServ, OPER_SET_NOEXPIRE_ON);
}
else if (setting.equals_ci("OFF"))
{
noexpire = false;
Log(LOG_ADMIN, u, this) << "NOEXPIRE OFF";
u->SendMessage(OperServ, OPER_SET_NOEXPIRE_OFF);
}
else
u->SendMessage(OperServ, OPER_SET_NOEXPIRE_ERROR);
return MOD_CONT;
}
public:
CommandOSSet() : Command("SET", 1, 2, "operserv/set")
{
}
CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms)
{
Anope::string option = params[0];
if (option.equals_ci("LIST"))
return this->DoList(u);
else if (option.equals_ci("IGNORE"))
return this->DoSetIgnore(u, params);
else if (option.equals_ci("READONLY"))
return this->DoSetReadOnly(u, params);
else if (option.equals_ci("SUPERADMIN"))
return this->DoSetSuperAdmin(u, params);
else if (option.equals_ci("DEBUG"))
return this->DoSetDebug(u, params);
else if (option.equals_ci("NOEXPIRE"))
return this->DoSetNoExpire(u, params);
else
u->SendMessage(OperServ, OPER_SET_UNKNOWN_OPTION, option.c_str());
return MOD_CONT;
}
bool OnHelp(User *u, const Anope::string &subcommand)
{
if (subcommand.empty())
u->SendMessage(OperServ, OPER_HELP_SET);
else if (subcommand.equals_ci("LIST"))
u->SendMessage(OperServ, OPER_HELP_SET_LIST);
else if (subcommand.equals_ci("READONLY"))
u->SendMessage(OperServ, OPER_HELP_SET_READONLY);
else if (subcommand.equals_ci("DEBUG"))
u->SendMessage(OperServ, OPER_HELP_SET_DEBUG);
else if (subcommand.equals_ci("NOEXPIRE"))
u->SendMessage(OperServ, OPER_HELP_SET_NOEXPIRE);
else if (subcommand.equals_ci("IGNORE"))
u->SendMessage(OperServ, OPER_HELP_SET_IGNORE);
else if (subcommand.equals_ci("SUPERADMIN"))
u->SendMessage(OperServ, OPER_HELP_SET_SUPERADMIN);
else
return false;
return true;
}
void OnSyntaxError(User *u, const Anope::string &subcommand)
{
SyntaxError(OperServ, u, "SET", OPER_SET_SYNTAX);
}
void OnServHelp(User *u)
{
u->SendMessage(OperServ, OPER_HELP_CMD_SET);
}
};
class OSSet : public Module
{
CommandOSSet commandosset;
public:
OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(CORE);
this->AddCommand(OperServ, &commandosset);
}
};
MODULE_INIT(OSSet)
|