1 /* opserv.c - IRC Operator assistance service
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * srvx is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
30 #ifdef HAVE_SYS_TIMES_H
31 #include <sys/times.h>
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
36 #ifdef HAVE_ARPA_INET_H
37 #include <arpa/inet.h>
40 #define OPSERV_CONF_NAME "services/opserv"
42 #define KEY_ALERT_CHANNEL "alert_channel"
43 #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes"
44 #define KEY_DEBUG_CHANNEL "debug_channel"
45 #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes"
46 #define KEY_UNTRUSTED_MAX "untrusted_max"
47 #define KEY_PURGE_LOCK_DELAY "purge_lock_delay"
48 #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate"
49 #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold"
50 #define KEY_NICK "nick"
51 #define KEY_JOIN_POLICER "join_policer"
52 #define KEY_NEW_USER_POLICER "new_user_policer"
53 #define KEY_REASON "reason"
54 #define KEY_RESERVES "reserves"
55 #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */
56 #define KEY_HOSTNAME "hostname"
57 #define KEY_DESC "description"
58 #define KEY_BAD_WORDS "bad"
59 #define KEY_EXEMPT_CHANNELS "exempt"
60 #define KEY_SECRET_WORDS "secret"
61 #define KEY_TRUSTED_HOSTS "trusted"
62 #define KEY_OWNER "owner"
63 #define KEY_GAGS "gags"
64 #define KEY_ALERTS "alerts"
65 #define KEY_REACTION "reaction"
66 #define KEY_DISCRIM "discrim"
67 #define KEY_WARN "chanwarn"
69 #define KEY_TIME "time"
70 #define KEY_MAX_CLIENTS "max_clients"
71 #define KEY_LIMIT "limit"
72 #define KEY_EXPIRES "expires"
73 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
74 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
75 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
76 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
77 #define KEY_ISSUER "issuer"
78 #define KEY_ISSUED "issued"
80 #define IDENT_FORMAT "%s [%s@%s/%s]"
81 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, inet_ntoa(user->ip)
82 #define MAX_CHANNELS_WHOIS 50
83 #define OSMSG_PART_REASON "%s has no reason."
84 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
85 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
86 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
88 static const struct message_entry msgtab
[] = {
89 { "OSMSG_BAR", "----------------------------------------" },
90 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
91 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
92 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
93 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
94 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
95 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
96 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
97 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
98 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
99 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
100 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
101 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
102 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
103 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
104 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
105 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
106 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
107 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
108 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
109 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
110 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
111 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
112 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
113 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
114 { "OSMSG_LEAVING", "Leaving $b%s$b." },
115 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
116 { "OSMSG_OP_DONE", "Opped the requested lusers." },
117 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
118 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
119 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
120 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
121 { "OSMSG_WHOIS_NICK", "Nick : %s" },
122 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
123 { "OSMSG_WHOIS_FAKEHOST", "Fakehost: %s" },
124 { "OSMSG_WHOIS_IP", "Real IP : %s" },
125 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
126 { "OSMSG_WHOIS_INFO", "Info : %s" },
127 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
128 { "OSMSG_WHOIS_SERVER", "Server : %s" },
129 { "OSMSG_WHOIS_NICK_AGE", "Nick Age: %s" },
130 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
131 { "OSMSG_WHOIS_CHANNELS", "Channels: %s" },
132 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
133 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
134 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
135 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
136 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
137 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
138 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
139 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
140 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
141 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
142 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
143 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
144 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
145 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
146 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
147 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
148 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
149 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
150 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
151 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
152 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
153 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
154 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
155 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
156 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
157 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
158 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
159 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
160 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
161 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
162 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
163 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
164 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
165 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
166 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
167 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
168 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
169 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
170 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
171 { "OSMSG_LINE_DUMPED", "Raw line sent." },
172 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
173 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
174 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
175 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
176 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
177 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
178 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
179 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
180 { "OSMSG_FLOOD_MODERATE", "This channel has been temporarily moderated due to a possible join flood attack detected in this channel; network staff have been notified and will investigate." },
181 { "OSMSG_CLONE_WARNING", "WARNING: You have connected the maximum permitted number of clients from one IP address (clones). If you connect any more, your host will be temporarily banned from the network." },
182 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
183 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
184 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
185 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
186 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
187 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
188 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
189 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
190 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
191 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
192 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
193 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
194 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
195 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
196 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
197 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
198 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
199 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
200 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
201 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
202 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
203 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
204 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
205 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
206 { "OSMSG_USER_SEARCH_COUNT", "------------ Found %4u matches -----------" },
207 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
208 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
209 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
210 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
211 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
212 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
213 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
214 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
215 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
216 { "OSMSG_NO_GAGS", "No gags have been set." },
217 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
218 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
219 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
220 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
221 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
222 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
223 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
224 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
225 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" },
226 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
227 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
228 { "OSMSG_ALERTS_DESC", " Criteria: %s" },
229 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
230 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
231 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
232 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
233 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
234 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
235 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
236 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
237 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
238 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
239 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
240 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
242 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
243 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
244 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
245 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
246 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
247 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
248 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
250 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
251 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
252 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
253 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
254 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
255 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
256 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
257 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
258 { "OSMSG_CHANINFO_HEADER", "%s Information" },
259 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
260 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
261 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
262 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
263 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
264 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
265 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
266 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
267 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
268 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
269 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
270 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
274 #define OPSERV_SYNTAX() svccmd_send_help(user, opserv, cmd)
276 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
278 struct userNode
*opserv
;
280 /*static dict_t opserv_chan_warn; */ /* data is char* */
281 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
282 static struct string_list
*opserv_bad_words
;
283 static dict_t opserv_exempt_channels
; /* data is not used */
284 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
285 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
286 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
287 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
288 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
289 static struct module *opserv_module
;
290 static struct log_type
*OS_LOG
;
291 static unsigned int new_user_flood
;
292 static char *level_strings
[1001];
295 struct chanNode
*debug_channel
;
296 struct chanNode
*alert_channel
;
297 struct chanNode
*staff_auth_channel
;
298 struct policer_params
*join_policer_params
;
299 struct policer new_user_policer
;
300 unsigned long untrusted_max
;
301 unsigned long clone_gline_duration
;
302 unsigned long block_gline_duration
;
303 unsigned long purge_lock_delay
;
304 unsigned long join_flood_moderate
;
305 unsigned long join_flood_moderate_threshold
;
308 struct trusted_host
{
322 struct gag_entry
*next
;
325 static struct gag_entry
*gagList
;
327 struct opserv_hostinfo
{
328 struct userList clients
;
329 struct trusted_host
*trusted
;
333 opserv_free_hostinfo(void *data
)
335 struct opserv_hostinfo
*ohi
= data
;
336 userList_clean(&ohi
->clients
);
340 typedef struct opservDiscrim
{
341 struct chanNode
*channel
;
342 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *server
, *ip_mask_str
, *reason
, *accountmask
;
343 unsigned long limit
, ip_mask
;
344 struct in_addr ip_addr
;
345 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
346 unsigned int match_opers
: 1, option_log
: 1;
347 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
348 int authed
: 2, info_space
: 2;
349 time_t min_ts
, max_ts
;
352 struct discrim_and_source
{
354 struct userNode
*source
;
356 unsigned int disp_limit
;
359 static discrim_t
opserv_discrim_create(struct userNode
*user
, unsigned int argc
, char *argv
[], int allow_channel
);
360 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
361 static int gag_helper_func(struct userNode
*match
, void *extra
);
362 static int ungag_helper_func(struct userNode
*match
, void *extra
);
368 } opserv_alert_reaction
;
370 struct opserv_user_alert
{
372 char *text_discrim
, *split_discrim
;
374 opserv_alert_reaction reaction
;
377 /* funny type to make it acceptible to dict_set_free_data, far below */
379 opserv_free_user_alert(void *data
)
381 struct opserv_user_alert
*alert
= data
;
382 if (alert
->discrim
->channel
)
383 UnlockChannel(alert
->discrim
->channel
);
385 free(alert
->text_discrim
);
386 free(alert
->split_discrim
);
387 free(alert
->discrim
->reason
);
388 free(alert
->discrim
);
392 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
393 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
395 /* A lot of these commands are very similar to what ChanServ can do,
396 * but OpServ can do them even on channels that aren't registered.
399 static MODCMD_FUNC(cmd_access
)
401 struct handle_info
*hi
;
405 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
406 if (!irccasecmp(target
, "*")) {
407 nickserv_show_oper_accounts(user
, cmd
);
410 if (!(hi
= modcmd_get_handle_info(user
, target
)))
412 res
= (argc
> 2) ? oper_try_set_access(user
, cmd
->parent
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
413 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
417 static MODCMD_FUNC(cmd_ban
)
419 struct mod_chanmode change
;
420 struct userNode
*victim
;
422 mod_chanmode_init(&change
);
424 change
.args
[0].mode
= MODE_BAN
;
425 if (is_ircmask(argv
[1]))
426 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
427 else if ((victim
= GetUserH(argv
[1])))
428 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
430 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
433 modcmd_chanmode_announce(&change
);
434 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
435 free((char*)change
.args
[0].u
.hostmask
);
439 static MODCMD_FUNC(cmd_chaninfo
)
444 struct exemptNode
*exempt
;
445 struct modeNode
*moden
;
448 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
449 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
450 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
451 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
452 irc_make_chanmode(channel
, buffer
);
453 if (channel
->bad_channel
)
454 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
456 reply("OSMSG_CHANINFO_MODES", buffer
);
457 if (channel
->topic_time
) {
458 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
459 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
460 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
462 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
463 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
465 if (channel
->banlist
.used
) {
466 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
467 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
468 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
469 ban
= channel
->banlist
.list
[n
];
470 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
471 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
474 if (channel
->exemptlist
.used
) {
475 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
476 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
477 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
478 exempt
= channel
->exemptlist
.list
[n
];
479 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
480 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
483 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
484 /* early out unless they ask for users */
485 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
488 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
489 for (n
=0; n
<channel
->members
.used
; n
++) {
490 moden
= channel
->members
.list
[n
];
491 if (moden
->modes
& MODE_CHANOP
)
492 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
494 for (n
=0; n
<channel
->members
.used
; n
++) {
495 moden
= channel
->members
.list
[n
];
496 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
497 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
499 for (n
=0; n
<channel
->members
.used
; n
++) {
500 moden
= channel
->members
.list
[n
];
501 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
502 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
504 for (n
=0; n
<channel
->members
.used
; n
++) {
505 moden
= channel
->members
.list
[n
];
506 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
507 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
512 /* This command has been replaced by 'alert notice channel #foo' */
514 static MODCMD_FUNC(cmd_warn)
516 char *reason, *message;
518 if (!IsChannelName(argv[1])) {
519 reply("OSMSG_NEED_CHANNEL", argv[0]);
522 reason = dict_find(opserv_chan_warn, argv[1], NULL);
524 reply("OSMSG_WARN_EXISTS", argv[1]);
528 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
530 reason = strdup("No reason");
531 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
532 reply("OSMSG_WARN_ADDED", argv[1], reason);
533 if (dict_find(channels, argv[1], NULL)) {
534 message = alloca(strlen(reason) + strlen(argv[1]) + 55);
535 sprintf(message, "Channel activity warning for channel %s: %s", argv[1], reason);
536 global_message(MESSAGE_RECIPIENT_OPERS, message);
541 static MODCMD_FUNC(cmd_unwarn)
543 if ((argc < 2) || !IsChannelName(argv[1])) {
544 reply("OSMSG_NEED_CHANNEL", argv[0]);
547 if (!dict_remove(opserv_chan_warn, argv[1])) {
548 reply("OSMSG_WARN_NOEXIST", argv[1]);
551 reply("OSMSG_WARN_DELETED", argv[1]);
556 static MODCMD_FUNC(cmd_clearbans
)
558 struct mod_chanmode
*change
;
561 change
= mod_chanmode_alloc(channel
->banlist
.used
);
562 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
563 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
564 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
566 modcmd_chanmode_announce(change
);
567 for (ii
=0; ii
<change
->argc
; ++ii
)
568 free((char*)change
->args
[ii
].u
.hostmask
);
569 mod_chanmode_free(change
);
570 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
574 static MODCMD_FUNC(cmd_clearmodes
)
576 struct mod_chanmode change
;
578 if (!channel
->modes
) {
579 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
582 mod_chanmode_init(&change
);
583 change
.modes_clear
= channel
->modes
;
584 modcmd_chanmode_announce(&change
);
585 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
589 static MODCMD_FUNC(cmd_deop
)
591 struct mod_chanmode
*change
;
592 unsigned int arg
, count
;
594 change
= mod_chanmode_alloc(argc
-1);
595 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
596 struct userNode
*victim
= GetUserH(argv
[arg
]);
598 if (!victim
|| IsService(victim
)
599 || !(mn
= GetUserMode(channel
, victim
))
600 || !(mn
->modes
& MODE_CHANOP
))
602 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
603 change
->args
[count
++].u
.member
= mn
;
606 change
->argc
= count
;
607 modcmd_chanmode_announce(change
);
609 mod_chanmode_free(change
);
610 reply("OSMSG_DEOP_DONE");
614 static MODCMD_FUNC(cmd_dehop
)
616 struct mod_chanmode
*change
;
617 unsigned int arg
, count
;
619 change
= mod_chanmode_alloc(argc
-1);
620 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
621 struct userNode
*victim
= GetUserH(argv
[arg
]);
623 if (!victim
|| IsService(victim
)
624 || !(mn
= GetUserMode(channel
, victim
))
625 || !(mn
->modes
& MODE_HALFOP
))
627 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
628 change
->args
[count
++].u
.member
= mn
;
631 change
->argc
= count
;
632 modcmd_chanmode_announce(change
);
634 mod_chanmode_free(change
);
635 reply("OSMSG_DEHOP_DONE");
639 static MODCMD_FUNC(cmd_deopall
)
641 struct mod_chanmode
*change
;
642 unsigned int ii
, count
;
644 change
= mod_chanmode_alloc(channel
->members
.used
);
645 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
646 struct modeNode
*mn
= channel
->members
.list
[ii
];
647 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
649 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
650 change
->args
[count
++].u
.member
= mn
;
653 change
->argc
= count
;
654 modcmd_chanmode_announce(change
);
656 mod_chanmode_free(change
);
657 reply("OSMSG_DEOPALL_DONE", channel
->name
);
661 static MODCMD_FUNC(cmd_dehopall
)
663 struct mod_chanmode
*change
;
664 unsigned int ii
, count
;
666 change
= mod_chanmode_alloc(channel
->members
.used
);
667 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
668 struct modeNode
*mn
= channel
->members
.list
[ii
];
669 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
671 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
672 change
->args
[count
++].u
.member
= mn
;
675 change
->argc
= count
;
676 modcmd_chanmode_announce(change
);
678 mod_chanmode_free(change
);
679 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
683 static MODCMD_FUNC(cmd_rehash
)
685 extern char *services_config
;
687 if (conf_read(services_config
))
688 reply("OSMSG_REHASH_COMPLETE");
690 reply("OSMSG_REHASH_FAILED");
694 static MODCMD_FUNC(cmd_reopen
)
697 reply("OSMSG_REOPEN_COMPLETE");
701 static MODCMD_FUNC(cmd_reconnect
)
703 reply("OSMSG_RECONNECTING");
704 irc_squit(self
, "Reconnecting.", NULL
);
708 static MODCMD_FUNC(cmd_jupe
)
710 extern int force_n2k
;
711 struct server
*newsrv
;
713 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
716 if ((num
< 64) && !force_n2k
) {
717 inttobase64(numeric
, num
, 1);
718 inttobase64(numeric
+1, 64*64-1, 2);
720 inttobase64(numeric
, num
, 2);
721 inttobase64(numeric
+2, 64*64*64-1, 3);
723 #ifdef WITH_PROTOCOL_P10
724 if (GetServerN(numeric
)) {
725 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
729 if (GetServerH(argv
[1])) {
730 reply("OSMSG_NAME_COLLIDE");
733 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
734 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
736 reply("OSMSG_SRV_CREATE_FAILED");
740 reply("OSMSG_SERVER_JUPED", argv
[1]);
744 static MODCMD_FUNC(cmd_unjupe
)
749 srv
= GetServerH(argv
[1]);
751 reply("MSG_SERVER_UNKNOWN", argv
[1]);
754 if (strncmp(srv
->description
, "JUPE", 4)) {
755 reply("OSMSG_SERVER_NOT_JUPE");
758 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
759 DelServer(srv
, 1, reason
);
760 reply("OSMSG_SERVER_UNJUPED");
764 static MODCMD_FUNC(cmd_jump
)
766 extern struct cManagerNode cManager
;
767 void uplink_select(char *name
);
768 struct uplinkNode
*uplink_find(char *name
);
769 struct uplinkNode
*uplink
;
772 target
= unsplit_string(argv
+1, argc
-1, NULL
);
774 if (!strcmp(cManager
.uplink
->name
, target
)) {
775 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
779 uplink
= uplink_find(target
);
781 reply("OSMSG_INVALID_UPLINK", target
);
784 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
785 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
789 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
790 uplink_select(target
);
791 irc_squit(self
, "Reconnecting.", NULL
);
795 static MODCMD_FUNC(cmd_die
)
799 text
= unsplit_string(argv
+1, argc
-1, NULL
);
800 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
801 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
802 irc_squit(self
, reason
, text
);
807 static MODCMD_FUNC(cmd_restart
)
809 extern int services_argc
;
810 extern char **services_argv
;
811 char **restart_argv
, *reason
, *text
;
813 text
= unsplit_string(argv
+1, argc
-1, NULL
);
814 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
815 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
816 irc_squit(self
, reason
, text
);
818 /* Append a NULL to the end of argv[]. */
819 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
820 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
821 restart_argv
[services_argc
] = NULL
;
826 execv(services_argv
[0], restart_argv
);
828 /* If we're still here, that means something went wrong. Reconnect. */
832 static struct gline
*
833 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
836 mask
= alloca(MAXLEN
);
837 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
839 reason
= alloca(MAXLEN
);
840 snprintf(reason
, MAXLEN
, "G-line requested by %s.", src_handle
);
842 if (!duration
) duration
= opserv_conf
.block_gline_duration
;
843 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1);
846 static MODCMD_FUNC(cmd_block
)
848 struct userNode
*target
;
852 target
= GetUserH(argv
[1]);
854 reply("MSG_NICK_UNKNOWN", argv
[1]);
857 if (IsService(target
)) {
858 reply("MSG_SERVICE_IMMUNE", target
->nick
);
861 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
862 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0);
863 reply("OSMSG_GLINE_ISSUED", gline
->target
);
867 static MODCMD_FUNC(cmd_gline
)
869 unsigned long duration
;
873 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
874 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
875 reply("MSG_INVALID_GLINE", argv
[1]);
878 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
879 reply("OSMSG_STUPID_GLINE", argv
[1]);
882 duration
= ParseInterval(argv
[2]);
884 reply("MSG_INVALID_DURATION", argv
[2]);
887 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
888 reply("OSMSG_GLINE_ISSUED", gline
->target
);
892 static MODCMD_FUNC(cmd_ungline
)
894 if (gline_remove(argv
[1], 1))
895 reply("OSMSG_GLINE_REMOVED", argv
[1]);
897 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
901 static MODCMD_FUNC(cmd_refreshg
)
908 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
910 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
912 gline_refresh_server(srv
);
913 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
917 reply("MSG_SERVER_UNKNOWN", argv
[1]);
922 reply("OSMSG_GLINES_REFRESHED");
928 opserv_ison(struct userNode
*tell
, struct userNode
*target
, const char *message
)
931 unsigned int count
, here_len
, n
, maxlen
;
934 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
936 maxlen
= MAX_LINE_SIZE
;
937 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
938 mn
= target
->channels
.list
[n
];
939 here_len
= strlen(mn
->channel
->name
);
940 if ((count
+ here_len
+ 4) > maxlen
) {
942 send_message(tell
, opserv
, message
, buff
);
945 if (mn
->modes
& MODE_CHANOP
)
947 if (mn
->modes
& MODE_HALFOP
)
949 if (mn
->modes
& MODE_VOICE
)
951 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
957 send_message(tell
, opserv
, message
, buff
);
961 static MODCMD_FUNC(cmd_inviteme
)
963 struct userNode
*target
;
968 target
= GetUserH(argv
[1]);
970 reply("MSG_NICK_UNKNOWN", argv
[1]);
974 if (opserv_conf
.debug_channel
== NULL
) {
975 reply("OSMSG_NO_DEBUG_CHANNEL");
978 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
979 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
982 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
984 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
988 static MODCMD_FUNC(cmd_invite
)
990 if (GetUserMode(channel
, user
)) {
991 reply("OSMSG_ALREADY_THERE", channel
->name
);
994 irc_invite(cmd
->parent
->bot
, user
, channel
);
998 static MODCMD_FUNC(cmd_join
)
1000 struct userNode
*bot
= cmd
->parent
->bot
;
1002 if (!IsChannelName(argv
[1])) {
1003 reply("MSG_NOT_CHANNEL_NAME");
1005 } else if (!(channel
= GetChannel(argv
[1]))) {
1006 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1007 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1008 } else if (GetUserMode(channel
, bot
)) {
1009 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1012 struct mod_chanmode change
;
1013 mod_chanmode_init(&change
);
1015 change
.args
[0].mode
= MODE_CHANOP
;
1016 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1017 modcmd_chanmode_announce(&change
);
1019 irc_fetchtopic(bot
, channel
->name
);
1020 reply("OSMSG_JOIN_DONE", channel
->name
);
1024 static MODCMD_FUNC(cmd_kick
)
1026 struct userNode
*target
;
1030 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1031 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1033 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1035 target
= GetUserH(argv
[1]);
1037 reply("MSG_NICK_UNKNOWN", argv
[1]);
1040 if (!GetUserMode(channel
, target
)) {
1041 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1044 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1048 static MODCMD_FUNC(cmd_kickall
)
1050 unsigned int limit
, n
, inchan
;
1051 struct modeNode
*mn
;
1053 struct userNode
*bot
= cmd
->parent
->bot
;
1055 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1056 * channel, we have to join it in temporarily. */
1057 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1058 struct mod_chanmode change
;
1059 mod_chanmode_init(&change
);
1060 change
.args
[0].mode
= MODE_CHANOP
;
1061 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1062 modcmd_chanmode_announce(&change
);
1065 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1066 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1068 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1070 limit
= user
->handle_info
->opserv_level
;
1071 for (n
=channel
->members
.used
; n
>0;) {
1072 mn
= channel
->members
.list
[--n
];
1073 if (IsService(mn
->user
)
1074 || (mn
->user
->handle_info
1075 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1078 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1081 DelChannelUser(bot
, channel
, "My work here is done", 0);
1082 reply("OSMSG_KICKALL_DONE", channel
->name
);
1086 static MODCMD_FUNC(cmd_kickban
)
1088 struct mod_chanmode change
;
1089 struct userNode
*target
;
1094 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1095 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1097 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1099 target
= GetUserH(argv
[1]);
1101 reply("MSG_NICK_UNKNOWN", argv
[1]);
1104 if (!GetUserMode(channel
, target
)) {
1105 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1108 mod_chanmode_init(&change
);
1110 change
.args
[0].mode
= MODE_BAN
;
1111 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1112 modcmd_chanmode_announce(&change
);
1113 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1118 static MODCMD_FUNC(cmd_kickbanall
)
1120 struct modeNode
*mn
;
1121 struct userNode
*bot
= cmd
->parent
->bot
;
1122 struct mod_chanmode
*change
;
1124 unsigned int limit
, n
, inchan
;
1126 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1127 * channel, we have to join it in temporarily. */
1128 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1129 change
= mod_chanmode_alloc(2);
1130 change
->args
[0].mode
= MODE_CHANOP
;
1131 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1132 change
->args
[1].mode
= MODE_BAN
;
1133 change
->args
[1].u
.hostmask
= "*!*@*";
1135 change
= mod_chanmode_alloc(1);
1136 change
->args
[0].mode
= MODE_BAN
;
1137 change
->args
[0].u
.hostmask
= "*!*@*";
1139 modcmd_chanmode_announce(change
);
1140 mod_chanmode_free(change
);
1142 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1143 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1145 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1148 limit
= user
->handle_info
->opserv_level
;
1149 for (n
=channel
->members
.used
; n
>0; ) {
1150 mn
= channel
->members
.list
[--n
];
1151 if (IsService(mn
->user
)
1152 || (mn
->user
->handle_info
1153 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1156 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1159 DelChannelUser(bot
, channel
, "My work here is done", 0);
1160 reply("OSMSG_KICKALL_DONE", channel
->name
);
1164 static MODCMD_FUNC(cmd_part
)
1168 if (!IsChannelName(argv
[1])) {
1169 reply("MSG_NOT_CHANNEL_NAME");
1172 if ((channel
= GetChannel(argv
[1]))) {
1173 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1174 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1177 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1178 reply("OSMSG_LEAVING", channel
->name
);
1179 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1184 static MODCMD_FUNC(cmd_mode
)
1186 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1187 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1190 reply("OSMSG_MODE_SET", channel
->name
);
1194 static MODCMD_FUNC(cmd_op
)
1196 struct mod_chanmode
*change
;
1197 unsigned int arg
, count
;
1199 change
= mod_chanmode_alloc(argc
-1);
1200 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1201 struct userNode
*victim
;
1202 struct modeNode
*mn
;
1203 if (!(victim
= GetUserH(argv
[arg
])))
1205 if (!(mn
= GetUserMode(channel
, victim
)))
1207 if (mn
->modes
& MODE_CHANOP
)
1209 change
->args
[count
].mode
= MODE_CHANOP
;
1210 change
->args
[count
++].u
.member
= mn
;
1213 change
->argc
= count
;
1214 modcmd_chanmode_announce(change
);
1216 mod_chanmode_free(change
);
1217 reply("OSMSG_OP_DONE");
1221 static MODCMD_FUNC(cmd_hop
)
1223 struct mod_chanmode
*change
;
1224 unsigned int arg
, count
;
1226 change
= mod_chanmode_alloc(argc
-1);
1227 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1228 struct userNode
*victim
;
1229 struct modeNode
*mn
;
1230 if (!(victim
= GetUserH(argv
[arg
])))
1232 if (!(mn
= GetUserMode(channel
, victim
)))
1234 if (mn
->modes
& MODE_HALFOP
)
1236 change
->args
[count
].mode
= MODE_HALFOP
;
1237 change
->args
[count
++].u
.member
= mn
;
1240 change
->argc
= count
;
1241 modcmd_chanmode_announce(change
);
1243 mod_chanmode_free(change
);
1244 reply("OSMSG_HOP_DONE");
1248 static MODCMD_FUNC(cmd_opall
)
1250 struct mod_chanmode
*change
;
1251 unsigned int ii
, count
;
1253 change
= mod_chanmode_alloc(channel
->members
.used
);
1254 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1255 struct modeNode
*mn
= channel
->members
.list
[ii
];
1256 if (mn
->modes
& MODE_CHANOP
)
1258 change
->args
[count
].mode
= MODE_CHANOP
;
1259 change
->args
[count
++].u
.member
= mn
;
1262 change
->argc
= count
;
1263 modcmd_chanmode_announce(change
);
1265 mod_chanmode_free(change
);
1266 reply("OSMSG_OPALL_DONE", channel
->name
);
1270 static MODCMD_FUNC(cmd_hopall
)
1272 struct mod_chanmode
*change
;
1273 unsigned int ii
, count
;
1275 change
= mod_chanmode_alloc(channel
->members
.used
);
1276 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1277 struct modeNode
*mn
= channel
->members
.list
[ii
];
1278 if (mn
->modes
& MODE_HALFOP
)
1280 change
->args
[count
].mode
= MODE_HALFOP
;
1281 change
->args
[count
++].u
.member
= mn
;
1284 change
->argc
= count
;
1285 modcmd_chanmode_announce(change
);
1287 mod_chanmode_free(change
);
1288 reply("OSMSG_HOPALL_DONE", channel
->name
);
1292 static MODCMD_FUNC(cmd_whois
)
1294 struct userNode
*target
;
1298 #ifdef WITH_PROTOCOL_P10
1299 if (argv
[1][0] == '*')
1300 target
= GetUserN(argv
[1]+1);
1303 target
= GetUserH(argv
[1]);
1305 reply("MSG_NICK_UNKNOWN", argv
[1]);
1308 reply("OSMSG_WHOIS_NICK", target
->nick
);
1309 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
1310 if (IsFakeHost(target
))
1311 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
1312 reply("OSMSG_WHOIS_IP", inet_ntoa(target
->ip
));
1313 if (target
->modes
) {
1315 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
1316 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
1317 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
1318 if (IsOper(target
)) buffer
[bpos
++] = 'o';
1319 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
1320 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
1322 // sethost - reed/apples
1323 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
1324 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
1326 if (IsService(target
)) buffer
[bpos
++] = 'k';
1327 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
1328 if (target
->handle_info
) buffer
[bpos
++] = 'r';
1329 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
1330 if (IsGagged(target
)) buffer_cat(" (gagged)");
1331 if (IsRegistering(target
)) buffer_cat(" (registered account)");
1334 reply("OSMSG_WHOIS_MODES", buffer
);
1336 reply("OSMSG_WHOIS_INFO", target
->info
);
1337 #ifdef WITH_PROTOCOL_P10
1338 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
1340 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
1341 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
1342 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
1343 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
1344 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
1345 opserv_ison(user
, target
, "OSMSG_WHOIS_CHANNELS");
1347 reply("OSMSG_WHOIS_HIDECHANS");
1351 static MODCMD_FUNC(cmd_unban
)
1353 struct mod_chanmode change
;
1354 mod_chanmode_init(&change
);
1356 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
1357 change
.args
[0].u
.hostmask
= argv
[1];
1358 modcmd_chanmode_announce(&change
);
1359 reply("OSMSG_UNBAN_DONE", channel
->name
);
1363 static MODCMD_FUNC(cmd_voiceall
)
1365 struct mod_chanmode
*change
;
1366 unsigned int ii
, count
;
1368 change
= mod_chanmode_alloc(channel
->members
.used
);
1369 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1370 struct modeNode
*mn
= channel
->members
.list
[ii
];
1371 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
1373 change
->args
[count
].mode
= MODE_VOICE
;
1374 change
->args
[count
++].u
.member
= mn
;
1377 change
->argc
= count
;
1378 modcmd_chanmode_announce(change
);
1380 mod_chanmode_free(change
);
1381 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
1385 static MODCMD_FUNC(cmd_devoiceall
)
1387 struct mod_chanmode
*change
;
1388 unsigned int ii
, count
;
1390 change
= mod_chanmode_alloc(channel
->members
.used
);
1391 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1392 struct modeNode
*mn
= channel
->members
.list
[ii
];
1393 if (!(mn
->modes
& MODE_VOICE
))
1395 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
1396 change
->args
[count
++].u
.member
= mn
;
1399 change
->argc
= count
;
1400 modcmd_chanmode_announce(change
);
1402 mod_chanmode_free(change
);
1403 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
1407 static MODCMD_FUNC(cmd_stats_bad
) {
1409 unsigned int ii
, end
, here_len
;
1412 /* Show the bad word list.. */
1413 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
1414 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
1415 here_len
= strlen(opserv_bad_words
->list
[ii
]);
1416 /* If the line is full output it & start again */
1417 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1419 reply("OSMSG_BADWORD_LIST", buffer
);
1422 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
1424 buffer
[end
++] = ' ';
1427 reply("OSMSG_BADWORD_LIST", buffer
);
1429 /* Show the exemption list.. */
1430 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
1431 here_len
= strlen(iter_key(it
));
1432 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1434 reply("OSMSG_EXEMPTED_LIST", buffer
);
1437 memcpy(buffer
+end
, iter_key(it
), here_len
);
1439 buffer
[end
++] = ' ';
1442 reply("OSMSG_EXEMPTED_LIST", buffer
);
1446 static MODCMD_FUNC(cmd_stats_glines
) {
1447 reply("OSMSG_GLINE_COUNT", gline_count());
1452 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
1453 unsigned int nn
, pos
;
1456 for (nn
=1; nn
<=depth
; nn
<<=1) ;
1457 for (pos
=0, nn
>>=1; nn
>1; ) {
1459 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
1460 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
1463 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
1464 if (!server
->children
.used
)
1466 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
1467 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
1469 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
1472 static MODCMD_FUNC(cmd_stats_links
) {
1473 trace_links(cmd
->parent
->bot
, user
, self
, 1);
1478 static MODCMD_FUNC(cmd_stats_max
) {
1479 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
1483 static MODCMD_FUNC(cmd_stats_network
) {
1484 struct helpfile_table tbl
;
1485 unsigned int nn
, tot_clients
;
1488 tot_clients
= dict_size(clients
);
1489 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
1490 tbl
.length
= dict_size(servers
)+1;
1492 tbl
.flags
= TABLE_NO_FREE
;
1493 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1494 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1495 tbl
.contents
[0][0] = "Server Name";
1496 tbl
.contents
[0][1] = "Clients";
1497 tbl
.contents
[0][2] = "Load";
1498 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1499 struct server
*server
= iter_data(it
);
1500 char *buffer
= malloc(32);
1501 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1502 tbl
.contents
[nn
][0] = server
->name
;
1503 tbl
.contents
[nn
][1] = buffer
;
1504 sprintf(buffer
, "%u", server
->clients
);
1505 tbl
.contents
[nn
][2] = buffer
+ 16;
1506 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
1509 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1510 for (nn
=1; nn
<tbl
.length
; nn
++) {
1511 free((char*)tbl
.contents
[nn
][1]);
1512 free(tbl
.contents
[nn
]);
1514 free(tbl
.contents
[0]);
1519 static MODCMD_FUNC(cmd_stats_network2
) {
1520 struct helpfile_table tbl
;
1524 tbl
.length
= dict_size(servers
)+1;
1526 tbl
.flags
= TABLE_NO_FREE
;
1527 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1528 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1529 tbl
.contents
[0][0] = "Server Name";
1530 tbl
.contents
[0][1] = "Numeric";
1531 tbl
.contents
[0][2] = "Link Time";
1532 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1533 struct server
*server
= iter_data(it
);
1534 char *buffer
= malloc(64);
1537 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1538 tbl
.contents
[nn
][0] = server
->name
;
1539 #ifdef WITH_PROTOCOL_P10
1540 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
1544 tbl
.contents
[nn
][1] = buffer
;
1545 ofs
= strlen(buffer
) + 1;
1546 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
1547 if (server
->self_burst
)
1548 strcat(buffer
+ ofs
, " Bursting");
1549 tbl
.contents
[nn
][2] = buffer
+ ofs
;
1552 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1553 for (nn
=1; nn
<tbl
.length
; nn
++) {
1554 free((char*)tbl
.contents
[nn
][1]);
1555 free(tbl
.contents
[nn
]);
1557 free(tbl
.contents
[0]);
1562 static MODCMD_FUNC(cmd_stats_reserved
) {
1565 reply("OSMSG_RESERVED_LIST");
1566 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
1567 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
1571 static MODCMD_FUNC(cmd_stats_trusted
) {
1573 struct trusted_host
*th
;
1574 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
1576 reply("OSMSG_TRUSTED_LIST");
1577 reply("OSMSG_TRUSTED_LIST_BAR");
1578 reply("OSMSG_TRUSTED_LIST_HEADER");
1579 reply("OSMSG_TRUSTED_LIST_BAR");
1581 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
1584 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
1586 intervalString(length
, th
->expires
- now
, user
->handle_info
);
1588 sprintf(limit
, "%lu", th
->limit
);
1589 reply("OSMSG_HOST_IS_TRUSTED",
1591 (th
->limit
? limit
: "none"),
1592 (th
->issuer
? th
->issuer
: "<unknown>"),
1593 (th
->issued
? issued
: "some time"),
1594 (th
->expires
? length
: "never"));
1595 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
1597 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
1600 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
1603 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
1605 intervalString(length
, th
->expires
- now
, user
->handle_info
);
1607 sprintf(limit
, "%lu", th
->limit
);
1608 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
1609 (th
->limit
? limit
: "none"),
1610 (th
->issuer
? th
->issuer
: "<unknown>"),
1611 (th
->issued
? issued
: "some time"),
1612 (th
->expires
? length
: "never"));
1613 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
1616 reply("OSMSG_TRUSTED_LIST_END");
1620 static MODCMD_FUNC(cmd_stats_uplink
) {
1621 extern struct cManagerNode cManager
;
1622 struct uplinkNode
*uplink
;
1624 uplink
= cManager
.uplink
;
1625 reply("OSMSG_UPLINK_START", uplink
->name
);
1626 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
1630 static MODCMD_FUNC(cmd_stats_uptime
) {
1631 char uptime
[INTERVALLEN
];
1633 extern time_t boot_time
;
1634 extern int lines_processed
;
1635 static long clocks_per_sec
;
1637 if (!clocks_per_sec
) {
1638 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
1639 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
1640 if (clocks_per_sec
<= 0)
1643 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
1644 clocks_per_sec
= CLOCKS_PER_SEC
;
1647 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
1649 reply("OSMSG_UPTIME_STATS",
1650 uptime
, lines_processed
,
1651 buf
.tms_utime
/(double)clocks_per_sec
,
1652 buf
.tms_stime
/(double)clocks_per_sec
);
1656 static MODCMD_FUNC(cmd_stats_alerts
) {
1658 struct opserv_user_alert
*alert
;
1659 const char *reaction
;
1661 reply("OSMSG_ALERTS_LIST");
1662 reply("OSMSG_ALERTS_BAR");
1663 reply("OSMSG_ALERTS_HEADER");
1664 reply("OSMSG_ALERTS_BAR");
1665 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
1666 alert
= iter_data(it
);
1667 switch (alert
->reaction
) {
1668 case REACT_NOTICE
: reaction
= "notice"; break;
1669 case REACT_KILL
: reaction
= "kill"; break;
1670 case REACT_GLINE
: reaction
= "gline"; break;
1671 default: reaction
= "<unknown>"; break;
1673 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
1674 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
1676 reply("OSMSG_ALERT_END");
1680 static MODCMD_FUNC(cmd_stats_gags
) {
1681 struct gag_entry
*gag
;
1682 struct helpfile_table table
;
1686 reply("OSMSG_NO_GAGS");
1689 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
1690 table
.length
= nn
+1;
1692 table
.flags
= TABLE_NO_FREE
;
1693 table
.contents
= calloc(table
.length
, sizeof(char**));
1694 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1695 table
.contents
[0][0] = "Mask";
1696 table
.contents
[0][1] = "Owner";
1697 table
.contents
[0][2] = "Expires";
1698 table
.contents
[0][3] = "Reason";
1699 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
1700 char expstr
[INTERVALLEN
];
1702 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
1704 strcpy(expstr
, "Never");
1705 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
1706 table
.contents
[nn
][0] = gag
->mask
;
1707 table
.contents
[nn
][1] = gag
->owner
;
1708 table
.contents
[nn
][2] = strdup(expstr
);
1709 table
.contents
[nn
][3] = gag
->reason
;
1711 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
1712 for (nn
=1; nn
<table
.length
; nn
++) {
1713 free((char*)table
.contents
[nn
][2]);
1714 free(table
.contents
[nn
]);
1716 free(table
.contents
[0]);
1717 free(table
.contents
);
1721 static MODCMD_FUNC(cmd_stats_timeq
) {
1722 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
1727 static MODCMD_FUNC(cmd_stats_warn) {
1730 reply("OSMSG_WARN_LISTSTART");
1731 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
1732 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
1733 reply("OSMSG_WARN_LISTEND");
1738 #if defined(WITH_MALLOC_X3)
1739 static MODCMD_FUNC(cmd_stats_memory
) {
1740 extern unsigned long alloc_count
, alloc_size
;
1741 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
1742 "%u allocations totalling %u bytes.",
1743 alloc_count
, alloc_size
);
1746 #elif defined(WITH_MALLOC_SLAB)
1747 static MODCMD_FUNC(cmd_stats_memory
) {
1748 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
1749 extern unsigned long big_alloc_count
, big_alloc_size
;
1750 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
1751 "%u allocations in %u slabs totalling %u bytes.",
1752 slab_alloc_count
, slab_count
, slab_alloc_size
);
1753 /* send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot,
1754 "%u big allocations totalling %u bytes.",
1760 static MODCMD_FUNC(cmd_dump
)
1762 char linedup
[MAXLEN
], original
[MAXLEN
];
1764 unsplit_string(argv
+1, argc
-1, original
);
1765 safestrncpy(linedup
, original
, sizeof(linedup
));
1766 /* assume it's only valid IRC if we can parse it */
1767 if (parse_line(linedup
, 1)) {
1769 reply("OSMSG_LINE_DUMPED");
1771 reply("OSMSG_RAW_PARSE_ERROR");
1775 static MODCMD_FUNC(cmd_raw
)
1777 char linedup
[MAXLEN
], original
[MAXLEN
];
1779 unsplit_string(argv
+1, argc
-1, original
);
1780 safestrncpy(linedup
, original
, sizeof(linedup
));
1781 /* Try to parse the line before sending it; if it's too wrong,
1782 * maybe it will core us instead of our uplink. */
1783 parse_line(linedup
, 1);
1785 reply("OSMSG_LINE_DUMPED");
1789 static struct userNode
*
1790 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
1792 struct userNode
*resv
= GetUserH(nick
);
1794 if (IsService(resv
)) {
1795 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
1798 if (resv
->handle_info
1799 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
1800 reply("OSMSG_LEVEL_TOO_LOW");
1804 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
1805 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
1810 static MODCMD_FUNC(cmd_collide
)
1812 struct userNode
*resv
;
1814 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
1816 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
1819 reply("OSMSG_CLONE_FAILED", argv
[1]);
1824 static MODCMD_FUNC(cmd_reserve
)
1826 struct userNode
*resv
;
1828 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
1830 resv
->modes
|= FLAGS_PERSISTENT
;
1831 reply("OSMSG_RESERVED_NICK", resv
->nick
);
1834 reply("OSMSG_CLONE_FAILED", argv
[1]);
1840 free_reserve(char *nick
)
1842 struct userNode
*resv
;
1846 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
1850 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
1851 reason
= alloca(rlen
);
1852 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
1853 DelUser(resv
, NULL
, 1, reason
);
1854 dict_remove(opserv_reserved_nick_dict
, nick
);
1858 static MODCMD_FUNC(cmd_unreserve
)
1860 if (free_reserve(argv
[1]))
1861 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
1863 reply("OSMSG_NOT_RESERVED", argv
[1]);
1868 opserv_part_channel(void *data
)
1870 DelChannelUser(opserv
, data
, "Leaving.", 0);
1873 static int alert_check_user(const char *key
, void *data
, void *extra
);
1876 opserv_new_user_check(struct userNode
*user
)
1878 struct opserv_hostinfo
*ohi
;
1879 struct gag_entry
*gag
;
1881 /* Check to see if we should ignore them entirely. */
1882 if (IsLocal(user
) || IsService(user
))
1885 /* Check for alerts, and stop if we find one that kills them. */
1886 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
1889 /* Gag them if appropriate. */
1890 for (gag
= gagList
; gag
; gag
= gag
->next
) {
1891 if (user_matches_glob(user
, gag
->mask
, 1)) {
1892 gag_helper_func(user
, NULL
);
1897 /* Add to host info struct */
1898 if (!(ohi
= dict_find(opserv_hostinfo_dict
, inet_ntoa(user
->ip
), NULL
))) {
1899 ohi
= calloc(1, sizeof(*ohi
));
1900 dict_insert(opserv_hostinfo_dict
, strdup(inet_ntoa(user
->ip
)), ohi
);
1901 userList_init(&ohi
->clients
);
1903 userList_append(&ohi
->clients
, user
);
1905 /* Only warn of new user floods outside of bursts. */
1906 if (!user
->uplink
->burst
) {
1907 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
1908 if (!new_user_flood
) {
1910 opserv_alert("Warning: Possible new-user flood.");
1917 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
1918 if (opserv_conf
.untrusted_max
&& user
->ip
.s_addr
&& (ntohl(user
->ip
.s_addr
) != INADDR_LOOPBACK
)) {
1919 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, inet_ntoa(user
->ip
), NULL
);
1920 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
1922 /* 0 means unlimited hosts */
1923 } else if (ohi
->clients
.used
== limit
) {
1925 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
1926 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
1927 } else if (ohi
->clients
.used
> limit
) {
1929 sprintf(target
, "*@%s", inet_ntoa(user
->ip
));
1930 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "AUTO Excessive connections from a single host.", now
, 1);
1938 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
1940 struct opserv_hostinfo
*ohi
;
1942 if (IsLocal(user
)) {
1943 /* Try to remove it from the reserved nick dict without
1944 * calling free_reserve, because that would call DelUser(),
1945 * and we'd loop back to here. */
1946 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
1949 if ((ohi
= dict_find(opserv_hostinfo_dict
, inet_ntoa(user
->ip
), NULL
))) {
1950 userList_remove(&ohi
->clients
, user
);
1951 if (ohi
->clients
.used
== 0) dict_remove(opserv_hostinfo_dict
, inet_ntoa(user
->ip
));
1956 opserv_bad_channel(const char *name
)
1960 dict_find(opserv_exempt_channels
, name
, &found
);
1964 if (gline_find(name
))
1967 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
1968 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
1975 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
1977 struct mod_chanmode
*change
;
1980 change
= mod_chanmode_alloc(2);
1981 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
1982 change
->args
[0].mode
= MODE_CHANOP
;
1983 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
1984 change
->args
[1].mode
= MODE_BAN
;
1985 change
->args
[1].u
.hostmask
= "*!*@*";
1986 mod_chanmode_announce(opserv
, channel
, change
);
1987 mod_chanmode_free(change
);
1988 for (nn
=channel
->members
.used
; nn
>0; ) {
1989 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
1990 if (IsService(mNode
->user
))
1992 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
1994 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
1998 opserv_channel_check(struct chanNode
*newchan
)
2002 if (!newchan
->join_policer
.params
) {
2003 newchan
->join_policer
.last_req
= now
;
2004 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2007 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2008 char message[MAXLEN];
2009 snprintf(message, sizeof(message), "Channel activity warning for channel %s: %s", newchan->name, warning);
2010 global_message(MESSAGE_RECIPIENT_OPERS, message);
2014 /* Wait until the join check to shut channels down. */
2015 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2019 opserv_channel_delete(struct chanNode
*chan
)
2021 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2025 opserv_join_check(struct modeNode
*mNode
)
2027 struct userNode
*user
= mNode
->user
;
2028 struct chanNode
*channel
= mNode
->channel
;
2031 if (IsService(user
))
2034 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2036 if (channel
->bad_channel
) {
2037 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2038 if (channel
->name
[0] != '#')
2039 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2040 else if (!GetUserMode(channel
, opserv
))
2041 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2043 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2044 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2045 KickChannelUser(user
, channel
, opserv
, msg
);
2050 if (user
->uplink
->burst
)
2052 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2053 channel
->join_flooded
= 0;
2056 if (!channel
->join_flooded
) {
2057 /* Don't moderate the channel unless it is activated and
2058 the number of users in the channel is over the threshold. */
2059 struct mod_chanmode change
;
2060 mod_chanmode_init(&change
);
2061 channel
->join_flooded
= 1;
2062 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2063 if (!GetUserMode(channel
, opserv
)) {
2064 /* If we aren't in the channel, join it. */
2065 change
.args
[0].mode
= MODE_CHANOP
;
2066 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2069 if (!(channel
->modes
& MODE_MODERATED
))
2070 change
.modes_set
|= MODE_MODERATED
;
2071 if (change
.modes_set
|| change
.argc
)
2072 mod_chanmode_announce(opserv
, channel
, &change
);
2073 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2074 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2076 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2079 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2084 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2085 unsigned int bad_idx
;
2087 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2088 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2089 if (irccasestr(new_bad
, orig_bad
)) {
2091 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2093 } else if (irccasestr(orig_bad
, new_bad
)) {
2095 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2097 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2098 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2099 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2100 if (!irccasestr(orig_bad
, new_bad
))
2103 reply("OSMSG_BAD_NUKING", orig_bad
);
2104 string_list_delete(opserv_bad_words
, bad_idx
);
2111 string_list_append(opserv_bad_words
, strdup(new_bad
));
2113 reply("OSMSG_ADDED_BAD", new_bad
);
2117 static MODCMD_FUNC(cmd_addbad
)
2119 unsigned int arg
, count
;
2121 int bad_found
, exempt_found
;
2123 /* Create the bad word if it doesn't exist. */
2124 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
2126 /* Look for exception modifiers. */
2127 for (arg
=2; arg
<argc
; arg
++) {
2128 if (!irccasecmp(argv
[arg
], "except")) {
2129 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
2131 reply("MSG_MISSING_PARAMS", "except");
2134 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
2135 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
2136 if (!exempt_found
) {
2137 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
2141 reply("OSMSG_ADDED_EXEMPTIONS", count
);
2143 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
2144 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
2148 /* Scan for existing channels that match the new bad word. */
2150 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
2151 struct chanNode
*channel
= iter_data(it
);
2153 if (!opserv_bad_channel(channel
->name
))
2155 channel
->bad_channel
= 1;
2156 if (channel
->name
[0] == '#')
2157 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2160 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
2161 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
2162 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2171 static MODCMD_FUNC(cmd_delbad
)
2176 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
2177 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
2178 string_list_delete(opserv_bad_words
, nn
);
2179 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
2180 channel
= iter_data(it
);
2181 if (irccasestr(channel
->name
, argv
[1])
2182 && !opserv_bad_channel(channel
->name
)) {
2183 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
2184 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
2185 channel
->bad_channel
= 0;
2188 reply("OSMSG_REMOVED_BAD", argv
[1]);
2192 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
2196 static MODCMD_FUNC(cmd_addexempt
)
2198 const char *chanName
;
2200 if ((argc
> 1) && IsChannelName(argv
[1])) {
2203 reply("MSG_NOT_CHANNEL_NAME");
2207 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
2208 channel
= GetChannel(chanName
);
2210 if (channel
->bad_channel
) {
2211 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
2212 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
2214 channel
->bad_channel
= 0;
2216 reply("OSMSG_ADDED_EXEMPTION", chanName
);
2220 static MODCMD_FUNC(cmd_delexempt
)
2222 const char *chanName
;
2224 if ((argc
> 1) && IsChannelName(argv
[1])) {
2227 reply("MSG_NOT_CHANNEL_NAME");
2231 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
2232 reply("OSMSG_NOT_EXEMPT", chanName
);
2235 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
2240 opserv_expire_trusted_host(void *data
)
2242 struct trusted_host
*th
= data
;
2243 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
2247 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
2249 struct trusted_host
*th
;
2250 th
= calloc(1, sizeof(*th
));
2253 th
->ipaddr
= strdup(ipaddr
);
2254 th
->reason
= reason
? strdup(reason
) : NULL
;
2255 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
2256 th
->issued
= issued
;
2258 th
->expires
= expires
;
2259 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
2261 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
2265 free_trusted_host(void *data
)
2267 struct trusted_host
*th
= data
;
2274 static MODCMD_FUNC(cmd_addtrust
)
2276 unsigned long interval
;
2278 struct in_addr tmpaddr
;
2281 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
2282 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
2286 if (!inet_aton(argv
[1], &tmpaddr
)) {
2287 reply("OSMSG_BAD_IP", argv
[1]);
2291 count
= strtoul(argv
[2], &tmp
, 10);
2293 reply("OSMSG_BAD_NUMBER", argv
[2]);
2297 interval
= ParseInterval(argv
[3]);
2298 if (!interval
&& strcmp(argv
[3], "0")) {
2299 reply("MSG_INVALID_DURATION", argv
[3]);
2303 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
2304 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
2305 reply("OSMSG_ADDED_TRUSTED");
2309 static MODCMD_FUNC(cmd_edittrust
)
2311 unsigned long interval
;
2312 struct trusted_host
*th
;
2316 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2318 reply("OSMSG_NOT_TRUSTED", argv
[1]);
2321 count
= strtoul(argv
[2], &tmp
, 10);
2322 if (!count
|| *tmp
) {
2323 reply("OSMSG_BAD_NUMBER", argv
[2]);
2326 interval
= ParseInterval(argv
[3]);
2327 if (!interval
&& strcmp(argv
[3], "0")) {
2328 reply("MSG_INVALID_DURATION", argv
[3]);
2331 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
2333 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
2336 th
->reason
= strdup(reason
);
2338 th
->issuer
= strdup(user
->handle_info
->handle
);
2342 th
->expires
= now
+ interval
;
2343 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
2346 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
2350 static MODCMD_FUNC(cmd_deltrust
)
2354 for (n
=1; n
<argc
; n
++) {
2355 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
2359 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
2360 dict_remove(opserv_trusted_hosts
, argv
[n
]);
2362 reply("OSMSG_REMOVED_TRUSTED");
2366 /* This doesn't use dict_t because it's a little simpler to open-code the
2367 * comparisons (and simpler arg-passing for the ADD subcommand).
2369 static MODCMD_FUNC(cmd_clone
)
2372 struct userNode
*clone
;
2374 clone
= GetUserH(argv
[2]);
2375 if (!irccasecmp(argv
[1], "ADD")) {
2377 char ident
[USERLEN
+1];
2380 reply("MSG_MISSING_PARAMS", argv
[1]);
2385 reply("OSMSG_CLONE_EXISTS", argv
[2]);
2388 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
2389 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
2390 if (argv
[3][i
] == '@') {
2394 ident
[i
] = argv
[3][i
];
2397 if (!argv
[3][i
] || (i
==USERLEN
)) {
2398 reply("OSMSG_NOT_A_HOSTMASK");
2401 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
2402 reply("OSMSG_CLONE_FAILED", argv
[2]);
2405 reply("OSMSG_CLONE_ADDED", clone
->nick
);
2409 reply("MSG_NICK_UNKNOWN", argv
[2]);
2412 if (clone
->uplink
!= self
|| IsService(clone
)) {
2413 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
2416 if (!irccasecmp(argv
[1], "REMOVE")) {
2419 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
2422 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
2423 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
2426 DelUser(clone
, NULL
, 1, reason
);
2427 reply("OSMSG_CLONE_REMOVED", argv
[2]);
2431 reply("MSG_MISSING_PARAMS", argv
[1]);
2435 channel
= GetChannel(argv
[3]);
2436 if (!irccasecmp(argv
[1], "JOIN")) {
2438 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
2439 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2442 AddChannelUser(clone
, channel
);
2443 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
2446 if (!irccasecmp(argv
[1], "PART")) {
2448 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2451 if (!GetUserMode(channel
, clone
)) {
2452 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
2455 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
2456 DelChannelUser(clone
, channel
, "Leaving.", 0);
2459 if (!irccasecmp(argv
[1], "OP")) {
2460 struct mod_chanmode change
;
2462 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2465 mod_chanmode_init(&change
);
2467 change
.args
[0].mode
= MODE_CHANOP
;
2468 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
2469 if (!change
.args
[0].u
.member
) {
2470 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
2473 modcmd_chanmode_announce(&change
);
2474 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
2477 if (!irccasecmp(argv
[1], "HOP")) {
2478 struct mod_chanmode change
;
2480 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2483 mod_chanmode_init(&change
);
2485 change
.args
[0].mode
= MODE_HALFOP
;
2486 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
2487 if (!change
.args
[0].u
.member
) {
2488 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
2491 modcmd_chanmode_announce(&change
);
2492 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
2496 reply("MSG_MISSING_PARAMS", argv
[1]);
2500 if (!irccasecmp(argv
[1], "SAY")) {
2501 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
2502 irc_privmsg(clone
, argv
[3], text
);
2503 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
2506 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
2510 static struct helpfile_expansion
2511 opserv_help_expand(const char *variable
)
2513 extern struct userNode
*message_source
;
2514 struct helpfile_expansion exp
;
2515 struct service
*service
;
2521 if (!(service
= service_find(message_source
->nick
))) {
2522 exp
.type
= HF_STRING
;
2523 exp
.value
.str
= NULL
;
2524 } else if (!irccasecmp(variable
, "index")) {
2525 exp
.type
= HF_TABLE
;
2526 exp
.value
.table
.length
= 1;
2527 exp
.value
.table
.width
= 2;
2528 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
2529 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
2530 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
2531 exp
.value
.table
.contents
[0][0] = "Command";
2532 exp
.value
.table
.contents
[0][1] = "Level";
2533 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
2534 cmd
= iter_data(it
);
2535 row
= exp
.value
.table
.length
++;
2536 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
2537 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
2538 level
= cmd
->min_opserv_level
;
2539 if (!level_strings
[level
]) {
2540 level_strings
[level
] = malloc(16);
2541 snprintf(level_strings
[level
], 16, "%3d", level
);
2543 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
2545 } else if (!strncasecmp(variable
, "level", 5)) {
2546 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
2547 exp
.type
= HF_STRING
;
2549 level
= cmd
->min_opserv_level
;
2550 exp
.value
.str
= malloc(16);
2551 snprintf(exp
.value
.str
, 16, "%3d", level
);
2553 exp
.value
.str
= NULL
;
2556 exp
.type
= HF_STRING
;
2557 exp
.value
.str
= NULL
;
2563 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
2565 char buf
[16], *flags
= NULL
;
2566 unsigned int iflags
= 0;
2567 sprintf(buf
, "%d", min_level
);
2569 case 1: flags
= "+acceptchan"; break;
2570 case 3: flags
= "+acceptpluschan"; /* fall through */
2571 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
2574 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
2576 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
2580 int add_reserved(const char *key
, void *data
, void *extra
)
2582 struct record_data
*rd
= data
;
2583 const char *ident
, *hostname
, *desc
;
2584 struct userNode
*reserve
;
2585 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
2587 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
2590 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
2592 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
2595 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
2597 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
2600 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
2601 reserve
->modes
|= FLAGS_PERSISTENT
;
2602 dict_insert(extra
, reserve
->nick
, reserve
);
2608 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
2612 unsigned int matched
;
2614 if (!self
->uplink
) return 0;
2615 discrim
= calloc(1, sizeof(*discrim
));
2616 discrim
->limit
= dict_size(clients
);
2617 discrim
->max_level
= ~0;
2618 discrim
->max_ts
= now
;
2619 discrim
->max_channels
= INT_MAX
;
2620 discrim
->authed
= -1;
2621 discrim
->info_space
= -1;
2622 dupmask
= strdup(hostmask
);
2623 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
2624 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "0123456789.?*")]) {
2625 if (!parse_ipmask(discrim
->mask_host
, &discrim
->ip_addr
, &discrim
->ip_mask
)) {
2626 log_module(OS_LOG
, LOG_ERROR
, "Couldn't parse %s as an IP mask!", discrim
->mask_host
);
2631 discrim
->mask_host
= 0;
2633 matched
= opserv_discrim_search(discrim
, func
, extra
);
2635 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
2644 gag_free(struct gag_entry
*gag
)
2646 unsigned int ungagged
;
2648 /* Remove from gag list */
2649 if (gagList
== gag
) {
2650 gagList
= gag
->next
;
2652 struct gag_entry
*prev
;
2653 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
2654 prev
->next
= gag
->next
;
2657 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
2659 /* Deallocate storage */
2669 gag_expire(void *data
)
2675 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
2677 struct gag_entry
*gag
;
2679 /* Create gag and put it into linked list */
2680 gag
= calloc(1, sizeof(*gag
));
2681 gag
->mask
= strdup(mask
);
2682 gag
->owner
= strdup(owner
? owner
: "<unknown>");
2683 gag
->reason
= strdup(reason
? reason
: "<unknown>");
2684 gag
->expires
= expires
;
2686 timeq_add(gag
->expires
, gag_expire
, gag
);
2687 gag
->next
= gagList
;
2690 /* If we're linked, see if who the gag applies to */
2691 return foreach_matching_user(mask
, gag_helper_func
, gag
);
2695 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
2697 struct record_data
*rd
= data
;
2698 char *owner
, *reason
, *expstr
;
2701 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
2702 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
2703 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
2704 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
2705 gag_create(key
, owner
, reason
, expires
);
2710 static struct opserv_user_alert
*
2711 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
)
2714 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
2715 struct opserv_user_alert
*alert
;
2718 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
2719 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
2722 alert
= malloc(sizeof(*alert
));
2723 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
2724 alert
->text_discrim
= strdup(text_discrim
);
2725 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
2726 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
2727 alert
->discrim
= opserv_discrim_create(req
, wordc
, wordv
, 0);
2728 if (!alert
->discrim
) {
2729 free(alert
->text_discrim
);
2734 alert
->split_discrim
= discrim_copy
;
2735 name_dup
= strdup(name
);
2736 if (!alert
->discrim
->reason
)
2737 alert
->discrim
->reason
= strdup(name
);
2738 alert
->reaction
= reaction
;
2739 dict_insert(opserv_user_alerts
, name_dup
, alert
);
2740 if (alert
->discrim
->channel
)
2741 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
2742 else if (alert
->discrim
->mask_nick
)
2743 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
2749 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
2751 struct record_data *rd = data;
2752 char *reason = GET_RECORD_QSTRING(rd);
2754 * i hope this can't happen *
2756 reason = "No Reason";
2758 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
2764 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
2767 const char *discrim
, *react
, *owner
;
2768 opserv_alert_reaction reaction
;
2769 struct opserv_user_alert
*alert
;
2771 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
2772 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
2775 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
2776 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
2777 if (!react
|| !irccasecmp(react
, "notice"))
2778 reaction
= REACT_NOTICE
;
2779 else if (!irccasecmp(react
, "kill"))
2780 reaction
= REACT_KILL
;
2781 else if (!irccasecmp(react
, "gline"))
2782 reaction
= REACT_GLINE
;
2784 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
2787 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
);
2789 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
2792 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
2794 alert
->owner
= strdup(owner
? owner
: "<unknown>");
2799 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
2801 struct record_data
*rd
= data
;
2802 const char *limit
, *str
, *reason
, *issuer
;
2803 time_t issued
, expires
;
2805 if (rd
->type
== RECDB_QSTRING
) {
2806 /* old style host by itself */
2807 limit
= GET_RECORD_QSTRING(rd
);
2812 } else if (rd
->type
== RECDB_OBJECT
) {
2813 dict_t obj
= GET_RECORD_OBJECT(rd
);
2814 /* new style structure */
2815 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
2816 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
2817 expires
= str
? ParseInterval(str
) : 0;
2818 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
2819 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
2820 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
2821 issued
= str
? ParseInterval(str
) : 0;
2825 if (expires
&& (expires
< now
))
2827 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
2832 opserv_saxdb_read(struct dict
*conf_db
)
2835 struct record_data
*rd
;
2839 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
2840 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
2841 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
2843 case RECDB_STRING_LIST
:
2844 /* Add words one by one just in case there are overlaps from an old DB. */
2845 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
2846 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
2849 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
2850 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
2852 if (rd
->type
== RECDB_STRING_LIST
)
2853 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
2854 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
2861 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
2862 && (rd
->type
== RECDB_STRING_LIST
)) {
2863 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
2864 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
2866 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
2868 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
2869 max_clients
= atoi(str
);
2870 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
2871 max_clients_time
= atoi(str
);
2873 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
2874 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
2875 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
2876 dict_foreach(object
, add_gag_helper
, NULL
);
2877 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
2878 dict_foreach(object
, add_user_alert
, NULL
);
2880 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
2881 dict_foreach(object, add_chan_warn, NULL);
2887 opserv_saxdb_write(struct saxdb_context
*ctx
)
2889 struct string_list
*slist
;
2892 /* reserved nicks */
2893 if (dict_size(opserv_reserved_nick_dict
)) {
2894 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
2895 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
2896 struct userNode
*user
= iter_data(it
);
2897 if (!IsPersistent(user
)) continue;
2898 saxdb_start_record(ctx
, iter_key(it
), 0);
2899 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
2900 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
2901 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
2902 saxdb_end_record(ctx
);
2904 saxdb_end_record(ctx
);
2907 if (opserv_bad_words
->used
) {
2908 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
2910 /* insert exempt channel names */
2911 if (dict_size(opserv_exempt_channels
)) {
2912 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
2913 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
2914 string_list_append(slist
, strdup(iter_key(it
)));
2916 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
2917 free_string_list(slist
);
2919 /* trusted hosts takes a little more work */
2920 if (dict_size(opserv_trusted_hosts
)) {
2921 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
2922 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2923 struct trusted_host
*th
= iter_data(it
);
2924 saxdb_start_record(ctx
, iter_key(it
), 0);
2925 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
2926 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
2927 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
2928 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
2929 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
2930 saxdb_end_record(ctx
);
2932 saxdb_end_record(ctx
);
2936 struct gag_entry
*gag
;
2937 saxdb_start_record(ctx
, KEY_GAGS
, 1);
2938 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2939 saxdb_start_record(ctx
, gag
->mask
, 0);
2940 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
2941 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
2942 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
2943 saxdb_end_record(ctx
);
2945 saxdb_end_record(ctx
);
2947 /* channel warnings */
2949 if (dict_size(opserv_chan_warn)) {
2950 saxdb_start_record(ctx, KEY_WARN, 0);
2951 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
2952 saxdb_write_string(ctx, iter_key(it), iter_data(it));
2954 saxdb_end_record(ctx);
2958 if (dict_size(opserv_user_alerts
)) {
2959 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
2960 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2961 struct opserv_user_alert
*alert
= iter_data(it
);
2962 const char *reaction
;
2963 saxdb_start_record(ctx
, iter_key(it
), 0);
2964 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
2965 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
2966 switch (alert
->reaction
) {
2967 case REACT_NOTICE
: reaction
= "notice"; break;
2968 case REACT_KILL
: reaction
= "kill"; break;
2969 case REACT_GLINE
: reaction
= "gline"; break;
2972 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
2975 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
2976 saxdb_end_record(ctx
);
2978 saxdb_end_record(ctx
);
2981 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
2982 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
2983 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
2984 saxdb_end_record(ctx
);
2989 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
2991 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
2995 static MODCMD_FUNC(cmd_query
)
2997 struct record_data
*rd
;
3002 reply("OSMSG_OPTION_ROOT");
3003 conf_enum_root(query_keys_helper
, user
);
3007 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
3008 if (!(rd
= conf_get_node(nodename
))) {
3009 reply("OSMSG_UNKNOWN_OPTION", nodename
);
3013 if (rd
->type
== RECDB_QSTRING
)
3014 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
3015 else if (rd
->type
== RECDB_STRING_LIST
) {
3016 reply("OSMSG_OPTION_LIST", nodename
);
3017 if (rd
->d
.slist
->used
)
3018 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
3019 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
3021 reply("OSMSG_OPTION_LIST_EMPTY");
3022 } else if (rd
->type
== RECDB_OBJECT
) {
3023 reply("OSMSG_OPTION_KEYS", nodename
);
3024 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
3030 static MODCMD_FUNC(cmd_set
)
3032 struct record_data
*rd
;
3034 /* I originally wanted to be able to fully manipulate the config
3035 db with this, but i wussed out. feel free to fix this - you'll
3036 need to handle quoted strings which have been split, and likely
3037 invent a syntax for it. -Zoot */
3039 if (!(rd
= conf_get_node(argv
[1]))) {
3040 reply("OSMSG_SET_NOT_SET", argv
[1]);
3044 if (rd
->type
!= RECDB_QSTRING
) {
3045 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
3049 free(rd
->d
.qstring
);
3050 rd
->d
.qstring
= strdup(argv
[2]);
3051 conf_call_reload_funcs();
3052 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
3056 static MODCMD_FUNC(cmd_settime
)
3058 const char *srv_name_mask
= "*";
3059 time_t new_time
= now
;
3062 srv_name_mask
= argv
[1];
3064 new_time
= time(NULL
);
3065 irc_settime(srv_name_mask
, new_time
);
3066 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
3071 opserv_discrim_create(struct userNode
*user
, unsigned int argc
, char *argv
[], int allow_channel
)
3076 discrim
= calloc(1, sizeof(*discrim
));
3077 discrim
->limit
= 250;
3078 discrim
->max_level
= ~0;
3079 discrim
->max_ts
= INT_MAX
;
3080 discrim
->domain_depth
= 2;
3081 discrim
->max_channels
= INT_MAX
;
3082 discrim
->authed
= -1;
3083 discrim
->info_space
= -1;
3085 for (i
=0; i
<argc
; i
++) {
3086 if (irccasecmp(argv
[i
], "log") == 0) {
3087 discrim
->option_log
= 1;
3090 /* Assume all other criteria require arguments. */
3091 if (i
== argc
- 1) {
3092 send_message(user
, opserv
, "MSG_MISSING_PARAMS", argv
[i
]);
3095 if (irccasecmp(argv
[i
], "mask") == 0) {
3096 if (!is_ircmask(argv
[++i
])) {
3097 send_message(user
, opserv
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
3100 if (!split_ircmask(argv
[i
],
3101 &discrim
->mask_nick
,
3102 &discrim
->mask_ident
,
3103 &discrim
->mask_host
)) {
3104 send_message(user
, opserv
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
3107 } else if (irccasecmp(argv
[i
], "nick") == 0) {
3108 discrim
->mask_nick
= argv
[++i
];
3109 } else if (irccasecmp(argv
[i
], "ident") == 0) {
3110 discrim
->mask_ident
= argv
[++i
];
3111 } else if (irccasecmp(argv
[i
], "host") == 0) {
3112 discrim
->mask_host
= argv
[++i
];
3113 } else if (irccasecmp(argv
[i
], "info") == 0) {
3114 discrim
->mask_info
= argv
[++i
];
3115 } else if (irccasecmp(argv
[i
], "server") == 0) {
3116 discrim
->server
= argv
[++i
];
3117 } else if (irccasecmp(argv
[i
], "ip") == 0) {
3118 j
= parse_ipmask(argv
[++i
], &discrim
->ip_addr
, &discrim
->ip_mask
);
3119 if (!j
) discrim
->ip_mask_str
= argv
[i
];
3120 } else if (irccasecmp(argv
[i
], "account") == 0) {
3121 if (discrim
->authed
== 0) {
3122 send_message(user
, opserv
, "OSMSG_ACCOUNTMASK_AUTHED");
3125 discrim
->accountmask
= argv
[++i
];
3126 discrim
->authed
= 1;
3127 } else if (irccasecmp(argv
[i
], "authed") == 0) {
3128 i
++; /* true_string and false_string are macros! */
3129 if (true_string(argv
[i
])) {
3130 discrim
->authed
= 1;
3131 } else if (false_string(argv
[i
])) {
3132 if (discrim
->accountmask
) {
3133 send_message(user
, opserv
, "OSMSG_ACCOUNTMASK_AUTHED");
3136 discrim
->authed
= 0;
3138 send_message(user
, opserv
, "MSG_INVALID_BINARY", argv
[i
]);
3141 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
3142 /* XXX: A hack because you can't check explicitly for a space through
3143 * any other means */
3145 if (true_string(argv
[i
])) {
3146 discrim
->info_space
= 1;
3147 } else if (false_string(argv
[i
])) {
3148 discrim
->info_space
= 0;
3150 send_message(user
, opserv
, "MSG_INVALID_BINARY", argv
[i
]);
3153 } else if (irccasecmp(argv
[i
], "duration") == 0) {
3154 discrim
->duration
= ParseInterval(argv
[++i
]);
3155 } else if (irccasecmp(argv
[i
], "channel") == 0) {
3156 for (j
=0, i
++; ; j
++) {
3157 switch (argv
[i
][j
]) {
3161 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
3164 discrim
->chan_req_modes
|= MODE_VOICE
;
3165 discrim
->chan_no_modes
|= MODE_CHANOP
;
3166 discrim
->chan_no_modes
|= MODE_HALFOP
;
3169 discrim
->chan_req_modes
|= MODE_HALFOP
;
3170 discrim
->chan_no_modes
|= MODE_CHANOP
;
3171 discrim
->chan_no_modes
|= MODE_VOICE
;
3174 discrim
->chan_req_modes
|= MODE_CHANOP
;
3177 send_message(user
, opserv
, "MSG_NOT_CHANNEL_NAME");
3182 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
3183 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
3184 /* secretly "allow_channel" now means "if a channel name is
3185 * specified, require that it currently exist" */
3186 if (allow_channel
) {
3187 send_message(user
, opserv
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
3190 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
3193 LockChannel(discrim
->channel
);
3194 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
3195 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
3196 } else if (irccasecmp(argv
[i
], "limit") == 0) {
3197 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
3198 } else if (irccasecmp(argv
[i
], "reason") == 0) {
3199 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
3201 } else if (irccasecmp(argv
[i
], "last") == 0) {
3202 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
3203 } else if ((irccasecmp(argv
[i
], "linked") == 0)
3204 || (irccasecmp(argv
[i
], "nickage") == 0)) {
3205 const char *cmp
= argv
[++i
];
3206 if (cmp
[0] == '<') {
3207 if (cmp
[1] == '=') {
3208 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
3210 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
3212 } else if (cmp
[0] == '>') {
3213 if (cmp
[1] == '=') {
3214 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
3216 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
3219 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
3221 } else if (irccasecmp(argv
[i
], "access") == 0) {
3222 const char *cmp
= argv
[++i
];
3223 if (cmp
[0] == '<') {
3224 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
3225 if (cmp
[1] == '=') {
3226 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
3228 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
3230 } else if (cmp
[0] == '=') {
3231 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
3232 } else if (cmp
[0] == '>') {
3233 if (cmp
[1] == '=') {
3234 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
3236 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
3239 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
3241 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
3242 && (irccasecmp(argv
[++i
], "opers") == 0)) {
3243 discrim
->match_opers
= 1;
3244 } else if (irccasecmp(argv
[i
], "depth") == 0) {
3245 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
3246 } else if (irccasecmp(argv
[i
], "clones") == 0) {
3247 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
3249 send_message(user
, opserv
, "MSG_INVALID_CRITERIA", argv
[i
]);
3254 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
3255 discrim
->mask_nick
= 0;
3257 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
3258 discrim
->mask_ident
= 0;
3260 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
3261 discrim
->mask_info
= 0;
3263 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
3264 discrim
->mask_host
= 0;
3273 discrim_match(discrim_t discrim
, struct userNode
*user
)
3275 unsigned int access
;
3277 if ((user
->timestamp
< discrim
->min_ts
)
3278 || (user
->timestamp
> discrim
->max_ts
)
3279 || (user
->channels
.used
< discrim
->min_channels
)
3280 || (user
->channels
.used
> discrim
->max_channels
)
3281 || (discrim
->authed
== 0 && user
->handle_info
)
3282 || (discrim
->authed
== 1 && !user
->handle_info
)
3283 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
3284 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
3285 || (discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
3286 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
3287 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
3288 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))
3289 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
3290 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
3291 || (discrim
->ip_mask
&& !MATCH_IPMASK(user
->ip
, discrim
->ip_addr
, discrim
->ip_mask
))) {
3294 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
)) return 0;
3295 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
3296 if ((access
< discrim
->min_level
)
3297 || (access
> discrim
->max_level
)) {
3300 if (discrim
->ip_mask_str
) {
3301 if (!match_ircglob(inet_ntoa(user
->ip
), discrim
->ip_mask_str
)) return 0;
3303 if (discrim
->min_clones
> 1) {
3304 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, inet_ntoa(user
->ip
), NULL
);
3305 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
)) return 0;
3311 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
3313 unsigned int nn
, count
;
3314 struct userList matched
;
3316 userList_init(&matched
);
3317 /* Try most optimized search methods first */
3318 if (discrim
->channel
) {
3320 (nn
< discrim
->channel
->members
.used
)
3321 && (matched
.used
< discrim
->limit
);
3323 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
3324 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
3325 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
3328 if (discrim_match(discrim
, mn
->user
)) {
3329 userList_append(&matched
, mn
->user
);
3332 } else if (discrim
->ip_mask_str
&& !discrim
->ip_mask_str
[strcspn(discrim
->ip_mask_str
, "?*")]) {
3333 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, discrim
->ip_mask_str
, NULL
);
3335 userList_clean(&matched
);
3338 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
3339 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
3340 userList_append(&matched
, ohi
->clients
.list
[nn
]);
3345 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
3346 if (discrim_match(discrim
, iter_data(it
))) {
3347 userList_append(&matched
, iter_data(it
));
3352 if (!matched
.used
) {
3353 userList_clean(&matched
);
3357 if (discrim
->option_log
) {
3358 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
3360 for (nn
=0; nn
<matched
.used
; nn
++) {
3361 struct userNode
*user
= matched
.list
[nn
];
3362 if (discrim
->option_log
) {
3363 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
3365 if (dsf(user
, data
)) {
3366 /* If a search function returns true, it ran into a
3367 problem. Stop going through the list. */
3371 if (discrim
->option_log
) {
3372 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
3374 count
= matched
.used
;
3375 userList_clean(&matched
);
3380 trace_print_func(struct userNode
*match
, void *extra
)
3382 struct discrim_and_source
*das
= extra
;
3383 if (match
->handle_info
) {
3384 send_message_type(4, das
->source
, opserv
, "%-15s\002 \002%10s\002@\002%s (%s)", match
->nick
, match
->ident
, match
->hostname
, match
->handle_info
->handle
);
3386 send_message_type(4, das
->source
, opserv
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
3392 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
3398 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
3400 return !(IsService(target
)
3401 || (!match_opers
&& IsOper(target
))
3402 || (target
->handle_info
3403 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
3407 trace_gline_func(struct userNode
*match
, void *extra
)
3409 struct discrim_and_source
*das
= extra
;
3411 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
3412 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
3419 trace_kill_func(struct userNode
*match
, void *extra
)
3421 struct discrim_and_source
*das
= extra
;
3423 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
3425 if (das
->discrim
->reason
) {
3426 reason
= das
->discrim
->reason
;
3428 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
3429 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
3431 DelUser(match
, opserv
, 1, reason
);
3438 is_gagged(char *mask
)
3440 struct gag_entry
*gag
;
3442 for (gag
= gagList
; gag
; gag
= gag
->next
) {
3443 if (match_ircglobs(gag
->mask
, mask
)) return 1;
3449 trace_gag_func(struct userNode
*match
, void *extra
)
3451 struct discrim_and_source
*das
= extra
;
3453 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
3454 char *reason
, *mask
;
3456 if (das
->discrim
->reason
) {
3457 reason
= das
->discrim
->reason
;
3459 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
3460 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
3462 masksize
= 5+strlen(match
->hostname
);
3463 mask
= alloca(masksize
);
3464 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
3465 if (!is_gagged(mask
)) {
3466 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
3467 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
3475 trace_domains_func(struct userNode
*match
, void *extra
)
3477 struct discrim_and_source
*das
= extra
;
3478 unsigned long *count
;
3482 if (!match
->hostname
[strspn(match
->hostname
, "0123456789.")]) {
3484 unsigned long matchip
= ntohl(match
->ip
.s_addr
);
3485 /* raw IP address.. use up to first three octets of IP */
3486 switch (das
->discrim
->domain_depth
) {
3488 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
3491 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
3494 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
3499 hostname
= match
->hostname
+ strlen(match
->hostname
);
3500 for (depth
=das
->discrim
->domain_depth
;
3501 depth
&& (hostname
> match
->hostname
);
3504 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
3506 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
3508 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
3509 count
= calloc(1, sizeof(*count
));
3510 dict_insert(das
->dict
, strdup(hostname
), count
);
3517 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
3519 unsigned long *count
= data
;
3520 struct discrim_and_source
*das
= extra
;
3522 send_message_type(4, das
->source
, opserv
, "%s %lu", key
, *count
);
3523 return !--das
->disp_limit
;
3526 static MODCMD_FUNC(cmd_trace
)
3528 struct discrim_and_source das
;
3529 discrim_search_func action
;
3530 unsigned int matches
;
3531 struct svccmd
*subcmd
;
3534 sprintf(buf
, "trace %s", argv
[1]);
3535 if (!(subcmd
= dict_find(cmd
->parent
->commands
, buf
, NULL
))) {
3536 reply("OSMSG_BAD_ACTION", argv
[1]);
3539 if (!svccmd_can_invoke(user
, cmd
->parent
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
3541 if (!irccasecmp(argv
[1], "print"))
3542 action
= trace_print_func
;
3543 else if (!irccasecmp(argv
[1], "count"))
3544 action
= trace_count_func
;
3545 else if (!irccasecmp(argv
[1], "domains"))
3546 action
= trace_domains_func
;
3547 else if (!irccasecmp(argv
[1], "gline"))
3548 action
= trace_gline_func
;
3549 else if (!irccasecmp(argv
[1], "kill"))
3550 action
= trace_kill_func
;
3551 else if (!irccasecmp(argv
[1], "gag"))
3552 action
= trace_gag_func
;
3554 reply("OSMSG_BAD_ACTION", argv
[1]);
3558 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
3559 reply("OSMSG_LEVEL_TOO_LOW");
3565 das
.discrim
= opserv_discrim_create(user
, argc
-2, argv
+2, 1);
3569 if (action
== trace_print_func
)
3571 reply("OSMSG_USER_SEARCH_RESULTS");
3572 reply("OSMSG_USER_SEARCH_BAR");
3573 reply("OSMSG_USER_SEARCH_HEADER");
3574 reply("OSMSG_USER_SEARCH_BAR");
3576 else if (action
== trace_count_func
)
3577 das
.discrim
->limit
= INT_MAX
;
3578 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
3579 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
3580 else if (action
== trace_domains_func
) {
3581 das
.dict
= dict_new();
3582 dict_set_free_data(das
.dict
, free
);
3583 dict_set_free_keys(das
.dict
, free
);
3584 das
.disp_limit
= das
.discrim
->limit
;
3585 das
.discrim
->limit
= INT_MAX
;
3587 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
3589 if (action
== trace_domains_func
)
3590 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
3593 reply("OSMSG_USER_SEARCH_COUNT", matches
);
3595 reply("MSG_NO_MATCHES");
3597 if (das
.discrim
->channel
)
3598 UnlockChannel(das
.discrim
->channel
);
3599 free(das
.discrim
->reason
);
3601 dict_delete(das
.dict
);
3605 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
);
3607 typedef struct channel_discrim
{
3610 unsigned int min_users
, max_users
;
3611 time_t min_ts
, max_ts
;
3615 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, unsigned int argc
, char *argv
[]);
3616 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
);
3619 smart_parse_time(const char *str
) {
3620 /* If an interval-style string is given, treat as time before now.
3621 * If it's all digits, treat directly as a Unix timestamp. */
3622 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
3626 opserv_cdiscrim_create(struct userNode
*user
, unsigned int argc
, char *argv
[])
3631 discrim
= calloc(1, sizeof(*discrim
));
3632 discrim
->limit
= 25;
3634 for (i
= 0; i
< argc
; i
++) {
3635 /* Assume all criteria require arguments. */
3636 if (i
== (argc
- 1)) {
3637 send_message(user
, opserv
, "MSG_MISSING_PARAMS", argv
[i
]);
3641 if (!irccasecmp(argv
[i
], "name"))
3642 discrim
->name
= argv
[++i
];
3643 else if (!irccasecmp(argv
[i
], "topic"))
3644 discrim
->topic
= argv
[++i
];
3645 else if (!irccasecmp(argv
[i
], "users")) {
3646 const char *cmp
= argv
[++i
];
3647 if (cmp
[0] == '<') {
3649 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
3651 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
3652 } else if (cmp
[0] == '=') {
3653 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
3654 } else if (cmp
[0] == '>') {
3656 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
3658 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
3660 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
3662 } else if (!irccasecmp(argv
[i
], "timestamp")) {
3663 const char *cmp
= argv
[++i
];
3664 if (cmp
[0] == '<') {
3666 discrim
->max_ts
= smart_parse_time(cmp
+2);
3668 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
3669 } else if (cmp
[0] == '=') {
3670 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
3671 } else if (cmp
[0] == '>') {
3673 discrim
->min_ts
= smart_parse_time(cmp
+2);
3675 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
3677 discrim
->min_ts
= smart_parse_time(cmp
);
3679 } else if (!irccasecmp(argv
[i
], "limit")) {
3680 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
3682 send_message(user
, opserv
, "MSG_INVALID_CRITERIA", argv
[i
]);
3687 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
3689 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
3699 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
3701 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
3702 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
3703 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
3704 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
3705 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
3706 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
3712 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
)
3714 unsigned int count
= 0;
3715 dict_iterator_t it
, next
;
3717 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
3718 struct chanNode
*chan
= iter_data(it
);
3720 /* Hold on to the next channel in case we decide to
3721 add actions that destructively modify the channel. */
3722 next
= iter_next(it
);
3723 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
3732 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
))
3736 void channel_print(struct chanNode
*channel
, void *data
)
3739 irc_make_chanmode(channel
, modes
);
3740 send_message(data
, opserv
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
3743 static MODCMD_FUNC(cmd_csearch
)
3746 unsigned int matches
;
3747 cdiscrim_search_func action
;
3748 struct svccmd
*subcmd
;
3751 if (!irccasecmp(argv
[1], "count"))
3752 action
= channel_count
;
3753 else if (!irccasecmp(argv
[1], "print"))
3754 action
= channel_print
;
3756 reply("OSMSG_BAD_ACTION", argv
[1]);
3760 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
3761 if ((subcmd
= dict_find(cmd
->parent
->commands
, buf
, NULL
))
3762 && !svccmd_can_invoke(user
, cmd
->parent
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
3766 discrim
= opserv_cdiscrim_create(user
, argc
- 2, argv
+ 2);
3770 if (action
== channel_print
)
3771 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
3772 else if (action
== channel_count
)
3773 discrim
->limit
= INT_MAX
;
3775 matches
= opserv_cdiscrim_search(discrim
, action
, user
);
3778 reply("MSG_MATCH_COUNT", matches
);
3780 reply("MSG_NO_MATCHES");
3786 static MODCMD_FUNC(cmd_gsync
)
3790 src
= GetServerH(argv
[1]);
3792 reply("MSG_SERVER_UNKNOWN", argv
[1]);
3798 irc_stats(cmd
->parent
->bot
, src
, 'G');
3799 reply("OSMSG_GSYNC_RUNNING", src
->name
);
3803 struct gline_extra
{
3804 struct userNode
*user
;
3805 struct string_list
*glines
;
3809 gtrace_print_func(struct gline
*gline
, void *extra
)
3811 struct gline_extra
*xtra
= extra
;
3812 char *when_text
, set_text
[20];
3813 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
3814 when_text
= asctime(localtime(&gline
->expires
));
3815 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
3816 send_message(xtra
->user
, opserv
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
3820 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
3825 gtrace_ungline_func(struct gline
*gline
, void *extra
)
3827 struct gline_extra
*xtra
= extra
;
3828 string_list_append(xtra
->glines
, strdup(gline
->target
));
3831 static MODCMD_FUNC(cmd_gtrace
)
3833 struct gline_discrim
*discrim
;
3834 gline_search_func action
;
3835 unsigned int matches
, nn
;
3836 struct gline_extra extra
;
3837 struct svccmd
*subcmd
;
3840 if (!irccasecmp(argv
[1], "print"))
3841 action
= gtrace_print_func
;
3842 else if (!irccasecmp(argv
[1], "count"))
3843 action
= gtrace_count_func
;
3844 else if (!irccasecmp(argv
[1], "ungline"))
3845 action
= gtrace_ungline_func
;
3847 reply("OSMSG_BAD_ACTION", argv
[1]);
3850 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
3851 if ((subcmd
= dict_find(cmd
->parent
->commands
, buf
, NULL
))
3852 && !svccmd_can_invoke(user
, cmd
->parent
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
3856 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
3860 if (action
== gtrace_print_func
)
3861 reply("OSMSG_GLINE_SEARCH_RESULTS");
3862 else if (action
== gtrace_count_func
)
3863 discrim
->limit
= INT_MAX
;
3866 extra
.glines
= alloc_string_list(4);
3867 matches
= gline_discrim_search(discrim
, action
, &extra
);
3869 if (action
== gtrace_ungline_func
)
3870 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
3871 gline_remove(extra
.glines
->list
[nn
], 1);
3872 free_string_list(extra
.glines
);
3875 reply("MSG_MATCH_COUNT", matches
);
3877 reply("MSG_NO_MATCHES");
3878 free(discrim
->alt_target_mask
);
3884 alert_check_user(const char *key
, void *data
, void *extra
)
3886 struct opserv_user_alert
*alert
= data
;
3887 struct userNode
*user
= extra
;
3889 if (!discrim_match(alert
->discrim
, user
))
3892 if ((alert
->reaction
!= REACT_NOTICE
)
3894 && !alert
->discrim
->match_opers
) {
3898 /* The user matches the alert criteria, so trigger the reaction. */
3899 if (alert
->discrim
->option_log
)
3900 log_module(OS_LOG
, LOG_INFO
, "Alert %s triggered by user %s!%s@%s (%s).", key
, user
->nick
, user
->ident
, user
->hostname
, alert
->discrim
->reason
);
3902 /* Return 1 to halt alert matching, such as when killing the user
3903 that triggered the alert. */
3904 switch (alert
->reaction
) {
3906 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
3909 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
3912 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
3913 /* fall through to REACT_NOTICE case */
3915 opserv_alert("Alert $b%s$b triggered by user $b%s$b!%s@%s (%s).", key
, user
->nick
, user
->ident
, user
->hostname
, alert
->discrim
->reason
);
3922 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
3924 struct gag_entry
*gag
;
3925 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
3926 /* Gag them if appropriate (and only if). */
3927 user
->modes
&= ~FLAGS_GAGGED
;
3928 for (gag
= gagList
; gag
; gag
= gag
->next
) {
3929 if (user_matches_glob(user
, gag
->mask
, 1)) {
3930 gag_helper_func(user
, NULL
);
3937 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
3941 if (!opserv_conf
.staff_auth_channel
3942 || user
->uplink
->burst
3943 || !user
->handle_info
)
3945 else if (user
->handle_info
->opserv_level
)
3947 else if (IsNetworkHelper(user
))
3948 type
= "NETWORK HELPER";
3949 else if (IsSupportHelper(user
))
3950 type
= "SUPPORT HELPER";
3954 if (user
->ip
.s_addr
)
3955 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
3957 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, "%s [%s@%s] authed to %s account %s", user
->nick
, user
->ident
, user
->hostname
, type
, user
->handle_info
->handle
);
3960 static MODCMD_FUNC(cmd_log
)
3962 struct logSearch
*discrim
;
3963 unsigned int matches
;
3964 struct logReport report
;
3966 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
3970 reply("OSMSG_LOG_SEARCH_RESULTS");
3971 report
.reporter
= opserv
;
3973 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
3976 reply("MSG_MATCH_COUNT", matches
);
3978 reply("MSG_NO_MATCHES");
3985 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
3987 if (IsOper(match
) || IsLocal(match
))
3989 match
->modes
|= FLAGS_GAGGED
;
3993 static MODCMD_FUNC(cmd_gag
)
3995 struct gag_entry
*gag
;
3996 unsigned int gagged
;
3997 unsigned long duration
;
4000 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
4002 if (!is_ircmask(argv
[1])) {
4003 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
4007 for (gag
= gagList
; gag
; gag
= gag
->next
)
4008 if (match_ircglobs(gag
->mask
, argv
[1]))
4012 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
4016 duration
= ParseInterval(argv
[2]);
4017 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
4020 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
4022 reply("OSMSG_GAG_ADDED", argv
[1]);
4027 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
4029 match
->modes
&= ~FLAGS_GAGGED
;
4033 static MODCMD_FUNC(cmd_ungag
)
4035 struct gag_entry
*gag
;
4036 unsigned int ungagged
;
4038 for (gag
= gagList
; gag
; gag
= gag
->next
)
4039 if (!strcmp(gag
->mask
, argv
[1]))
4043 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
4047 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
4048 ungagged
= gag_free(gag
);
4051 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
4053 reply("OSMSG_UNGAG_ADDED", argv
[1]);
4057 static MODCMD_FUNC(cmd_addalert
)
4059 opserv_alert_reaction reaction
;
4060 struct svccmd
*subcmd
;
4065 sprintf(buf
, "addalert %s", argv
[2]);
4066 if (!(subcmd
= dict_find(cmd
->parent
->commands
, buf
, NULL
))) {
4067 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
4070 if (!irccasecmp(argv
[2], "notice"))
4071 reaction
= REACT_NOTICE
;
4072 else if (!irccasecmp(argv
[2], "kill"))
4073 reaction
= REACT_KILL
;
4074 else if (!irccasecmp(argv
[2], "gline"))
4075 reaction
= REACT_GLINE
;
4077 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
4080 if (!svccmd_can_invoke(user
, cmd
->parent
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
4081 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
)))
4083 reply("OSMSG_ADDED_ALERT", name
);
4087 static MODCMD_FUNC(cmd_delalert
)
4090 for (i
=1; i
<argc
; i
++) {
4091 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
4092 dict_remove(opserv_channel_alerts
, argv
[i
]);
4093 if (dict_remove(opserv_user_alerts
, argv
[i
]))
4094 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
4096 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
4102 opserv_conf_read(void)
4104 struct record_data
*rd
;
4105 dict_t conf_node
, child
;
4106 const char *str
, *str2
;
4107 struct policer_params
*pp
;
4110 rd
= conf_get_node(OPSERV_CONF_NAME
);
4111 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
4112 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
4115 conf_node
= rd
->d
.object
;
4116 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
4117 if (opserv
&& str
) {
4118 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
4121 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
4122 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
4124 opserv_conf
.debug_channel
= NULL
;
4126 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
4127 if (opserv
&& str
) {
4128 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
4131 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
4132 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
4134 opserv_conf
.alert_channel
= NULL
;
4136 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
4137 if (opserv
&& str
) {
4138 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
4141 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
4142 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
4144 opserv_conf
.staff_auth_channel
= NULL
;
4146 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
4147 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
4148 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
4149 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
4150 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
4151 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
4152 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
4153 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
4154 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
4156 NickChange(opserv
, str
, 0);
4157 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
4158 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
4159 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
4160 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
4162 if (!opserv_conf
.join_policer_params
)
4163 opserv_conf
.join_policer_params
= policer_params_new();
4164 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
4165 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
4166 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
4167 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
4169 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4170 struct chanNode
*cNode
= iter_data(it
);
4171 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
4174 if (opserv_conf
.new_user_policer
.params
)
4175 pp
= opserv_conf
.new_user_policer
.params
;
4177 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
4178 policer_params_set(pp
, "size", "200");
4179 policer_params_set(pp
, "drain-rate", "3");
4180 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
4181 dict_foreach(child
, set_policer_param
, pp
);
4185 opserv_db_init(void) {
4186 /* set up opserv_trusted_hosts dict */
4187 dict_delete(opserv_trusted_hosts
);
4188 opserv_trusted_hosts
= dict_new();
4189 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
4190 /* set up opserv_chan_warn dict */
4192 /* alert trace notice channel #x replaces warnings
4193 dict_delete(opserv_chan_warn);
4194 opserv_chan_warn = dict_new();
4195 dict_set_free_keys(opserv_chan_warn, free);
4196 dict_set_free_data(opserv_chan_warn, free);
4198 /* set up opserv_user_alerts */
4199 dict_delete(opserv_channel_alerts
);
4200 opserv_channel_alerts
= dict_new();
4201 dict_delete(opserv_nick_based_alerts
);
4202 opserv_nick_based_alerts
= dict_new();
4203 dict_delete(opserv_user_alerts
);
4204 opserv_user_alerts
= dict_new();
4205 dict_set_free_keys(opserv_user_alerts
, free
);
4206 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
4207 /* set up opserv_bad_words */
4208 free_string_list(opserv_bad_words
);
4209 opserv_bad_words
= alloc_string_list(4);
4210 /* and opserv_exempt_channels */
4211 dict_delete(opserv_exempt_channels
);
4212 opserv_exempt_channels
= dict_new();
4213 dict_set_free_keys(opserv_exempt_channels
, free
);
4217 opserv_db_cleanup(void)
4221 /* dict_delete(opserv_chan_warn); */
4222 dict_delete(opserv_reserved_nick_dict
);
4223 free_string_list(opserv_bad_words
);
4224 dict_delete(opserv_exempt_channels
);
4225 dict_delete(opserv_trusted_hosts
);
4226 unreg_del_user_func(opserv_user_cleanup
);
4227 dict_delete(opserv_hostinfo_dict
);
4228 dict_delete(opserv_nick_based_alerts
);
4229 dict_delete(opserv_channel_alerts
);
4230 dict_delete(opserv_user_alerts
);
4231 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
4232 free(level_strings
[nn
]);
4235 policer_params_delete(opserv_conf
.join_policer_params
);
4236 policer_params_delete(opserv_conf
.new_user_policer
.params
);
4240 init_opserv(const char *nick
)
4242 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
4244 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
4245 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
4247 conf_register_reload(opserv_conf_read
);
4249 memset(level_strings
, 0, sizeof(level_strings
));
4250 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
4251 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
4252 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
4253 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
4254 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
4255 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
4256 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
4257 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
4258 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
4259 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
4260 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
4261 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
4262 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
4263 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
4264 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
4265 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
4266 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
4267 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
4268 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
4269 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
4270 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
4271 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
4272 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
4273 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
4274 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
4275 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
4276 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
4277 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
4278 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
4279 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
4280 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
4281 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
4282 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
4283 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
4284 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
4285 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
4286 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
4287 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
4288 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
4289 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
4290 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
4291 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
4292 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
4293 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
4294 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
4295 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
4296 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
4297 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
4298 opserv_define_func("OP", cmd_op
, 100, 2, 2);
4299 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
4300 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
4301 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
4302 opserv_define_func("PART", cmd_part
, 601, 0, 2);
4303 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
4304 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
4305 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
4306 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
4307 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
4308 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
4309 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
4310 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
4311 opserv_define_func("SET", cmd_set
, 900, 0, 3);
4312 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
4313 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
4314 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
4315 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
4316 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
4317 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
4318 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
4319 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
4320 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
4321 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
4322 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
4323 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
4324 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
4325 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
4326 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
4327 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
4328 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
4330 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
4331 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
4332 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
4333 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
4334 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
4335 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
4336 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
4337 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
4338 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
4339 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
4340 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
4341 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
4342 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
4343 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
4344 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
4345 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
4346 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
4348 opserv_reserved_nick_dict
= dict_new();
4349 opserv_hostinfo_dict
= dict_new();
4350 dict_set_free_keys(opserv_hostinfo_dict
, free
);
4351 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
4353 reg_new_user_func(opserv_new_user_check
);
4354 reg_nick_change_func(opserv_alert_check_nick
);
4355 reg_del_user_func(opserv_user_cleanup
);
4356 reg_new_channel_func(opserv_channel_check
);
4357 reg_del_channel_func(opserv_channel_delete
);
4358 reg_join_func(opserv_join_check
);
4359 reg_auth_func(opserv_staff_alert
);
4362 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
4364 service_register(opserv
)->trigger
= '?';
4366 reg_exit_func(opserv_db_cleanup
);
4367 message_register_table(msgtab
);