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>
43 #define OPSERV_CONF_NAME "services/opserv"
45 #define KEY_ALERT_CHANNEL "alert_channel"
46 #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes"
47 #define KEY_DEBUG_CHANNEL "debug_channel"
48 #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes"
49 #define KEY_UNTRUSTED_MAX "untrusted_max"
50 #define KEY_PURGE_LOCK_DELAY "purge_lock_delay"
51 #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate"
52 #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold"
53 #define KEY_NICK "nick"
54 #define KEY_JOIN_POLICER "join_policer"
55 #define KEY_NEW_USER_POLICER "new_user_policer"
56 #define KEY_REASON "reason"
57 #define KEY_RESERVES "reserves"
58 #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */
59 #define KEY_HOSTNAME "hostname"
60 #define KEY_DESC "description"
61 #define KEY_BAD_WORDS "bad"
62 #define KEY_EXEMPT_CHANNELS "exempt"
63 #define KEY_SECRET_WORDS "secret"
64 #define KEY_TRUSTED_HOSTS "trusted"
65 #define KEY_OWNER "owner"
66 #define KEY_GAGS "gags"
67 #define KEY_ALERTS "alerts"
68 #define KEY_REACTION "reaction"
69 #define KEY_DISCRIM "discrim"
70 #define KEY_WARN "chanwarn"
72 #define KEY_TIME "time"
73 #define KEY_MAX_CLIENTS "max_clients"
74 #define KEY_LIMIT "limit"
75 #define KEY_EXPIRES "expires"
76 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
77 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
78 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
79 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
80 #define KEY_ISSUER "issuer"
81 #define KEY_ISSUED "issued"
82 #define KEY_ADMIN_LEVEL "admin_level"
84 #define IDENT_FORMAT "%s [%s@%s/%s]"
85 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, inet_ntoa(user->ip)
86 #define MAX_CHANNELS_WHOIS 50
87 #define OSMSG_PART_REASON "%s has no reason."
88 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
89 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
90 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
92 static const struct message_entry msgtab
[] = {
93 { "OSMSG_BAR", "----------------------------------------" },
94 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
95 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
96 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
97 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
98 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
99 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
100 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
101 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
102 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
103 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
104 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
105 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
106 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
107 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
108 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
109 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
110 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
111 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
112 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
113 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
114 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
115 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
116 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
117 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
118 { "OSMSG_LEAVING", "Leaving $b%s$b." },
119 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
120 { "OSMSG_OP_DONE", "Opped the requested lusers." },
121 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
122 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
123 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
124 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
125 { "OSMSG_WHOIS_NICK", "Nick : %s" },
126 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
127 { "OSMSG_WHOIS_FAKEHOST", "Fakehost: %s" },
128 { "OSMSG_WHOIS_IP", "Real IP : %s" },
129 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
130 { "OSMSG_WHOIS_INFO", "Info : %s" },
131 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
132 { "OSMSG_WHOIS_SERVER", "Server : %s" },
133 { "OSMSG_WHOIS_NICK_AGE", "Nick Age: %s" },
134 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
135 { "OSMSG_WHOIS_CHANNELS", "Channels: %s" },
136 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
137 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
138 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
139 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
140 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
141 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
142 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
143 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
144 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
145 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
146 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
147 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
148 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
149 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
150 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
151 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
152 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
153 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
154 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
155 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
156 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
157 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
158 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
159 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
160 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
161 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
162 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
163 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
164 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
165 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
166 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
167 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
168 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
169 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
170 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
171 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
172 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
173 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
174 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
175 { "OSMSG_LINE_DUMPED", "Raw line sent." },
176 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
177 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
178 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
179 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
180 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
181 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
182 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
183 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
184 { "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." },
185 { "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." },
186 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
187 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
188 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
189 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
190 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
191 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
192 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
193 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
194 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
195 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
196 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
197 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
198 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
199 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
200 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
201 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
202 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
203 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
204 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
205 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
206 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
207 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
208 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
209 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
210 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
211 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
212 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
213 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
214 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
215 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
216 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
217 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
218 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
219 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
220 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
221 { "OSMSG_NO_GAGS", "No gags have been set." },
222 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
223 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
224 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
225 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
226 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
227 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
228 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
229 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
230 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" },
231 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
232 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
233 { "OSMSG_ALERTS_DESC", " Criteria: %s" },
234 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
235 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
236 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
237 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
238 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
239 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
240 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
241 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
242 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
243 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
244 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
245 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
247 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
248 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
249 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
250 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
251 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
252 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
253 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
255 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
256 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
257 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
258 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
259 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
260 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
261 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
262 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
263 { "OSMSG_CHANINFO_HEADER", "%s Information" },
264 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
265 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
266 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
267 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
268 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
269 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
270 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
271 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
272 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
273 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
274 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
275 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
276 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
280 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
282 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
284 struct userNode
*opserv
;
285 static struct service
*opserv_service
;
287 /*static dict_t opserv_chan_warn; */ /* data is char* */
288 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
289 static struct string_list
*opserv_bad_words
;
290 static dict_t opserv_exempt_channels
; /* data is not used */
291 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
292 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
293 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
294 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
295 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
296 static struct module *opserv_module
;
297 static struct log_type
*OS_LOG
;
298 static unsigned int new_user_flood
;
299 static char *level_strings
[1001];
302 struct chanNode
*debug_channel
;
303 struct chanNode
*alert_channel
;
304 struct chanNode
*staff_auth_channel
;
305 struct policer_params
*join_policer_params
;
306 struct policer new_user_policer
;
307 unsigned long untrusted_max
;
308 unsigned long clone_gline_duration
;
309 unsigned long block_gline_duration
;
310 unsigned long purge_lock_delay
;
311 unsigned long join_flood_moderate
;
312 unsigned long join_flood_moderate_threshold
;
313 unsigned long admin_level
;
316 struct trusted_host
{
330 struct gag_entry
*next
;
333 static struct gag_entry
*gagList
;
335 struct opserv_hostinfo
{
336 struct userList clients
;
337 struct trusted_host
*trusted
;
341 opserv_free_hostinfo(void *data
)
343 struct opserv_hostinfo
*ohi
= data
;
344 userList_clean(&ohi
->clients
);
348 typedef struct opservDiscrim
{
349 struct chanNode
*channel
;
350 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *server
, *ip_mask_str
, *reason
, *accountmask
;
351 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
;
352 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1;
353 unsigned long limit
, ip_mask
;
354 struct in_addr ip_addr
;
355 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
356 unsigned int match_opers
: 1, option_log
: 1;
357 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
358 int authed
: 2, info_space
: 2;
359 time_t min_ts
, max_ts
;
360 unsigned int use_regex
: 1;
363 struct discrim_and_source
{
365 struct userNode
*source
;
366 struct userNode
*destination
;
368 unsigned int disp_limit
;
371 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
372 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
373 static int gag_helper_func(struct userNode
*match
, void *extra
);
374 static int ungag_helper_func(struct userNode
*match
, void *extra
);
380 } opserv_alert_reaction
;
382 struct opserv_user_alert
{
384 char *text_discrim
, *split_discrim
;
386 opserv_alert_reaction reaction
;
389 /* funny type to make it acceptible to dict_set_free_data, far below */
391 opserv_free_user_alert(void *data
)
393 struct opserv_user_alert
*alert
= data
;
394 if (alert
->discrim
->channel
)
395 UnlockChannel(alert
->discrim
->channel
);
397 free(alert
->text_discrim
);
398 free(alert
->split_discrim
);
399 if(alert
->discrim
->has_regex_nick
)
400 regfree(&alert
->discrim
->regex_nick
);
401 if(alert
->discrim
->has_regex_ident
)
402 regfree(&alert
->discrim
->regex_ident
);
403 if(alert
->discrim
->has_regex_host
)
404 regfree(&alert
->discrim
->regex_host
);
405 if(alert
->discrim
->has_regex_info
)
406 regfree(&alert
->discrim
->regex_info
);
407 free(alert
->discrim
->reason
);
408 free(alert
->discrim
);
412 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
413 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
415 /* A lot of these commands are very similar to what ChanServ can do,
416 * but OpServ can do them even on channels that aren't registered.
419 static MODCMD_FUNC(cmd_access
)
421 struct handle_info
*hi
;
425 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
426 if (!irccasecmp(target
, "*")) {
427 nickserv_show_oper_accounts(user
, cmd
);
430 if (!(hi
= modcmd_get_handle_info(user
, target
)))
432 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
433 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
437 static MODCMD_FUNC(cmd_ban
)
439 struct mod_chanmode change
;
440 struct userNode
*victim
;
442 mod_chanmode_init(&change
);
444 change
.args
[0].mode
= MODE_BAN
;
445 if (is_ircmask(argv
[1]))
446 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
447 else if ((victim
= GetUserH(argv
[1])))
448 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
450 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
453 modcmd_chanmode_announce(&change
);
454 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
455 free((char*)change
.args
[0].u
.hostmask
);
459 static MODCMD_FUNC(cmd_chaninfo
)
464 struct exemptNode
*exempt
;
465 struct modeNode
*moden
;
468 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
469 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
470 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
471 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
472 irc_make_chanmode(channel
, buffer
);
473 if (channel
->bad_channel
)
474 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
476 reply("OSMSG_CHANINFO_MODES", buffer
);
477 if (channel
->topic_time
) {
478 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
479 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
480 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
482 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
483 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
485 if (channel
->banlist
.used
) {
486 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
487 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
488 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
489 ban
= channel
->banlist
.list
[n
];
490 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
491 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
494 if (channel
->exemptlist
.used
) {
495 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
496 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
497 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
498 exempt
= channel
->exemptlist
.list
[n
];
499 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
500 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
503 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
504 /* early out unless they ask for users */
505 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
508 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
509 for (n
=0; n
<channel
->members
.used
; n
++) {
510 moden
= channel
->members
.list
[n
];
511 if (moden
->modes
& MODE_CHANOP
)
512 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
514 for (n
=0; n
<channel
->members
.used
; n
++) {
515 moden
= channel
->members
.list
[n
];
516 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
517 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
519 for (n
=0; n
<channel
->members
.used
; n
++) {
520 moden
= channel
->members
.list
[n
];
521 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
522 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
524 for (n
=0; n
<channel
->members
.used
; n
++) {
525 moden
= channel
->members
.list
[n
];
526 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
527 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
532 /* This command has been replaced by 'alert notice channel #foo' */
534 static MODCMD_FUNC(cmd_warn)
536 char *reason, *message;
538 if (!IsChannelName(argv[1])) {
539 reply("OSMSG_NEED_CHANNEL", argv[0]);
542 reason = dict_find(opserv_chan_warn, argv[1], NULL);
544 reply("OSMSG_WARN_EXISTS", argv[1]);
548 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
550 reason = strdup("No reason");
551 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
552 reply("OSMSG_WARN_ADDED", argv[1], reason);
553 if (dict_find(channels, argv[1], NULL)) {
554 message = alloca(strlen(reason) + strlen(argv[1]) + 55);
555 sprintf(message, "Channel activity warning for channel %s: %s", argv[1], reason);
556 global_message(MESSAGE_RECIPIENT_OPERS, message);
561 static MODCMD_FUNC(cmd_unwarn)
563 if ((argc < 2) || !IsChannelName(argv[1])) {
564 reply("OSMSG_NEED_CHANNEL", argv[0]);
567 if (!dict_remove(opserv_chan_warn, argv[1])) {
568 reply("OSMSG_WARN_NOEXIST", argv[1]);
571 reply("OSMSG_WARN_DELETED", argv[1]);
576 static MODCMD_FUNC(cmd_clearbans
)
578 struct mod_chanmode
*change
;
581 change
= mod_chanmode_alloc(channel
->banlist
.used
);
582 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
583 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
584 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
586 modcmd_chanmode_announce(change
);
587 for (ii
=0; ii
<change
->argc
; ++ii
)
588 free((char*)change
->args
[ii
].u
.hostmask
);
589 mod_chanmode_free(change
);
590 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
594 static MODCMD_FUNC(cmd_clearmodes
)
596 struct mod_chanmode change
;
598 if (!channel
->modes
) {
599 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
602 mod_chanmode_init(&change
);
603 change
.modes_clear
= channel
->modes
;
604 modcmd_chanmode_announce(&change
);
605 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
609 static MODCMD_FUNC(cmd_deop
)
611 struct mod_chanmode
*change
;
612 unsigned int arg
, count
;
614 change
= mod_chanmode_alloc(argc
-1);
615 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
616 struct userNode
*victim
= GetUserH(argv
[arg
]);
618 if (!victim
|| IsService(victim
)
619 || !(mn
= GetUserMode(channel
, victim
))
620 || !(mn
->modes
& MODE_CHANOP
))
622 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
623 change
->args
[count
++].u
.member
= mn
;
626 change
->argc
= count
;
627 modcmd_chanmode_announce(change
);
629 mod_chanmode_free(change
);
630 reply("OSMSG_DEOP_DONE");
634 static MODCMD_FUNC(cmd_dehop
)
636 struct mod_chanmode
*change
;
637 unsigned int arg
, count
;
639 change
= mod_chanmode_alloc(argc
-1);
640 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
641 struct userNode
*victim
= GetUserH(argv
[arg
]);
643 if (!victim
|| IsService(victim
)
644 || !(mn
= GetUserMode(channel
, victim
))
645 || !(mn
->modes
& MODE_HALFOP
))
647 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
648 change
->args
[count
++].u
.member
= mn
;
651 change
->argc
= count
;
652 modcmd_chanmode_announce(change
);
654 mod_chanmode_free(change
);
655 reply("OSMSG_DEHOP_DONE");
659 static MODCMD_FUNC(cmd_deopall
)
661 struct mod_chanmode
*change
;
662 unsigned int ii
, count
;
664 change
= mod_chanmode_alloc(channel
->members
.used
);
665 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
666 struct modeNode
*mn
= channel
->members
.list
[ii
];
667 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
669 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
670 change
->args
[count
++].u
.member
= mn
;
673 change
->argc
= count
;
674 modcmd_chanmode_announce(change
);
676 mod_chanmode_free(change
);
677 reply("OSMSG_DEOPALL_DONE", channel
->name
);
681 static MODCMD_FUNC(cmd_dehopall
)
683 struct mod_chanmode
*change
;
684 unsigned int ii
, count
;
686 change
= mod_chanmode_alloc(channel
->members
.used
);
687 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
688 struct modeNode
*mn
= channel
->members
.list
[ii
];
689 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
691 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
692 change
->args
[count
++].u
.member
= mn
;
695 change
->argc
= count
;
696 modcmd_chanmode_announce(change
);
698 mod_chanmode_free(change
);
699 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
703 static MODCMD_FUNC(cmd_rehash
)
705 extern char *services_config
;
707 if (conf_read(services_config
))
708 reply("OSMSG_REHASH_COMPLETE");
710 reply("OSMSG_REHASH_FAILED");
714 static MODCMD_FUNC(cmd_reopen
)
717 reply("OSMSG_REOPEN_COMPLETE");
721 static MODCMD_FUNC(cmd_reconnect
)
723 reply("OSMSG_RECONNECTING");
724 irc_squit(self
, "Reconnecting.", NULL
);
728 static MODCMD_FUNC(cmd_jupe
)
730 extern int force_n2k
;
731 struct server
*newsrv
;
733 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
736 if ((num
< 64) && !force_n2k
) {
737 inttobase64(numeric
, num
, 1);
738 inttobase64(numeric
+1, 64*64-1, 2);
740 inttobase64(numeric
, num
, 2);
741 inttobase64(numeric
+2, 64*64*64-1, 3);
743 #ifdef WITH_PROTOCOL_P10
744 if (GetServerN(numeric
)) {
745 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
749 if (GetServerH(argv
[1])) {
750 reply("OSMSG_NAME_COLLIDE");
753 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
754 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
756 reply("OSMSG_SRV_CREATE_FAILED");
760 reply("OSMSG_SERVER_JUPED", argv
[1]);
764 static MODCMD_FUNC(cmd_unjupe
)
769 srv
= GetServerH(argv
[1]);
771 reply("MSG_SERVER_UNKNOWN", argv
[1]);
774 if (strncmp(srv
->description
, "JUPE", 4)) {
775 reply("OSMSG_SERVER_NOT_JUPE");
778 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
779 DelServer(srv
, 1, reason
);
780 reply("OSMSG_SERVER_UNJUPED");
784 static MODCMD_FUNC(cmd_jump
)
786 extern struct cManagerNode cManager
;
787 void uplink_select(char *name
);
788 struct uplinkNode
*uplink_find(char *name
);
789 struct uplinkNode
*uplink
;
792 target
= unsplit_string(argv
+1, argc
-1, NULL
);
794 if (!strcmp(cManager
.uplink
->name
, target
)) {
795 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
799 uplink
= uplink_find(target
);
801 reply("OSMSG_INVALID_UPLINK", target
);
804 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
805 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
809 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
810 uplink_select(target
);
811 irc_squit(self
, "Reconnecting.", NULL
);
815 static MODCMD_FUNC(cmd_die
)
819 text
= unsplit_string(argv
+1, argc
-1, NULL
);
820 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
821 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
822 irc_squit(self
, reason
, text
);
827 static MODCMD_FUNC(cmd_restart
)
829 extern int services_argc
;
830 extern char **services_argv
;
831 char **restart_argv
, *reason
, *text
;
833 text
= unsplit_string(argv
+1, argc
-1, NULL
);
834 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
835 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
836 irc_squit(self
, reason
, text
);
838 /* Append a NULL to the end of argv[]. */
839 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
840 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
841 restart_argv
[services_argc
] = NULL
;
846 execv(services_argv
[0], restart_argv
);
848 /* If we're still here, that means something went wrong. Reconnect. */
852 static struct gline
*
853 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
856 mask
= alloca(MAXLEN
);
857 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
859 reason
= alloca(MAXLEN
);
860 snprintf(reason
, MAXLEN
, "G-line requested by %s.", src_handle
);
862 if (!duration
) duration
= opserv_conf
.block_gline_duration
;
863 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1);
866 static MODCMD_FUNC(cmd_block
)
868 struct userNode
*target
;
872 target
= GetUserH(argv
[1]);
874 reply("MSG_NICK_UNKNOWN", argv
[1]);
877 if (IsService(target
)) {
878 reply("MSG_SERVICE_IMMUNE", target
->nick
);
881 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
882 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0);
883 reply("OSMSG_GLINE_ISSUED", gline
->target
);
887 static MODCMD_FUNC(cmd_gline
)
889 unsigned long duration
;
893 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
894 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
895 reply("MSG_INVALID_GLINE", argv
[1]);
898 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
899 reply("OSMSG_STUPID_GLINE", argv
[1]);
902 duration
= ParseInterval(argv
[2]);
904 reply("MSG_INVALID_DURATION", argv
[2]);
907 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
908 reply("OSMSG_GLINE_ISSUED", gline
->target
);
912 static MODCMD_FUNC(cmd_ungline
)
914 if (gline_remove(argv
[1], 1))
915 reply("OSMSG_GLINE_REMOVED", argv
[1]);
917 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
921 static MODCMD_FUNC(cmd_refreshg
)
928 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
930 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
932 gline_refresh_server(srv
);
933 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
937 reply("MSG_SERVER_UNKNOWN", argv
[1]);
942 reply("OSMSG_GLINES_REFRESHED");
948 opserv_ison(struct userNode
*tell
, struct userNode
*target
, const char *message
)
951 unsigned int count
, here_len
, n
, maxlen
;
954 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
956 maxlen
= MAX_LINE_SIZE
;
957 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
958 mn
= target
->channels
.list
[n
];
959 here_len
= strlen(mn
->channel
->name
);
960 if ((count
+ here_len
+ 4) > maxlen
) {
962 send_message(tell
, opserv
, message
, buff
);
965 if (mn
->modes
& MODE_CHANOP
)
967 if (mn
->modes
& MODE_HALFOP
)
969 if (mn
->modes
& MODE_VOICE
)
971 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
977 send_message(tell
, opserv
, message
, buff
);
981 static MODCMD_FUNC(cmd_inviteme
)
983 struct userNode
*target
;
988 target
= GetUserH(argv
[1]);
990 reply("MSG_NICK_UNKNOWN", argv
[1]);
994 if (opserv_conf
.debug_channel
== NULL
) {
995 reply("OSMSG_NO_DEBUG_CHANNEL");
998 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
999 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1002 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1004 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1008 static MODCMD_FUNC(cmd_invite
)
1010 if (GetUserMode(channel
, user
)) {
1011 reply("OSMSG_ALREADY_THERE", channel
->name
);
1014 irc_invite(cmd
->parent
->bot
, user
, channel
);
1018 static MODCMD_FUNC(cmd_join
)
1020 struct userNode
*bot
= cmd
->parent
->bot
;
1022 if (!IsChannelName(argv
[1])) {
1023 reply("MSG_NOT_CHANNEL_NAME");
1025 } else if (!(channel
= GetChannel(argv
[1]))) {
1026 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1027 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1028 } else if (GetUserMode(channel
, bot
)) {
1029 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1032 struct mod_chanmode change
;
1033 mod_chanmode_init(&change
);
1035 change
.args
[0].mode
= MODE_CHANOP
;
1036 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1037 modcmd_chanmode_announce(&change
);
1039 irc_fetchtopic(bot
, channel
->name
);
1040 reply("OSMSG_JOIN_DONE", channel
->name
);
1044 static MODCMD_FUNC(cmd_kick
)
1046 struct userNode
*target
;
1050 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1051 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1053 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1055 target
= GetUserH(argv
[1]);
1057 reply("MSG_NICK_UNKNOWN", argv
[1]);
1060 if (!GetUserMode(channel
, target
)) {
1061 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1064 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1068 static MODCMD_FUNC(cmd_kickall
)
1070 unsigned int limit
, n
, inchan
;
1071 struct modeNode
*mn
;
1073 struct userNode
*bot
= cmd
->parent
->bot
;
1075 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1076 * channel, we have to join it in temporarily. */
1077 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1078 struct mod_chanmode change
;
1079 mod_chanmode_init(&change
);
1080 change
.args
[0].mode
= MODE_CHANOP
;
1081 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1082 modcmd_chanmode_announce(&change
);
1085 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1086 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1088 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1090 limit
= user
->handle_info
->opserv_level
;
1091 for (n
=channel
->members
.used
; n
>0;) {
1092 mn
= channel
->members
.list
[--n
];
1093 if (IsService(mn
->user
)
1094 || (mn
->user
->handle_info
1095 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1098 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1101 DelChannelUser(bot
, channel
, "My work here is done", 0);
1102 reply("OSMSG_KICKALL_DONE", channel
->name
);
1106 static MODCMD_FUNC(cmd_kickban
)
1108 struct mod_chanmode change
;
1109 struct userNode
*target
;
1114 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1115 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1117 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1119 target
= GetUserH(argv
[1]);
1121 reply("MSG_NICK_UNKNOWN", argv
[1]);
1124 if (!GetUserMode(channel
, target
)) {
1125 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1128 mod_chanmode_init(&change
);
1130 change
.args
[0].mode
= MODE_BAN
;
1131 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1132 modcmd_chanmode_announce(&change
);
1133 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1138 static MODCMD_FUNC(cmd_kickbanall
)
1140 struct modeNode
*mn
;
1141 struct userNode
*bot
= cmd
->parent
->bot
;
1142 struct mod_chanmode
*change
;
1144 unsigned int limit
, n
, inchan
;
1146 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1147 * channel, we have to join it in temporarily. */
1148 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1149 change
= mod_chanmode_alloc(2);
1150 change
->args
[0].mode
= MODE_CHANOP
;
1151 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1152 change
->args
[1].mode
= MODE_BAN
;
1153 change
->args
[1].u
.hostmask
= "*!*@*";
1155 change
= mod_chanmode_alloc(1);
1156 change
->args
[0].mode
= MODE_BAN
;
1157 change
->args
[0].u
.hostmask
= "*!*@*";
1159 modcmd_chanmode_announce(change
);
1160 mod_chanmode_free(change
);
1162 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1163 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1165 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1168 limit
= user
->handle_info
->opserv_level
;
1169 for (n
=channel
->members
.used
; n
>0; ) {
1170 mn
= channel
->members
.list
[--n
];
1171 if (IsService(mn
->user
)
1172 || (mn
->user
->handle_info
1173 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1176 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1179 DelChannelUser(bot
, channel
, "My work here is done", 0);
1180 reply("OSMSG_KICKALL_DONE", channel
->name
);
1184 static MODCMD_FUNC(cmd_part
)
1188 if (!IsChannelName(argv
[1])) {
1189 reply("MSG_NOT_CHANNEL_NAME");
1192 if ((channel
= GetChannel(argv
[1]))) {
1193 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1194 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1197 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1198 reply("OSMSG_LEAVING", channel
->name
);
1199 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1204 static MODCMD_FUNC(cmd_mode
)
1206 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1207 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1210 reply("OSMSG_MODE_SET", channel
->name
);
1214 static MODCMD_FUNC(cmd_op
)
1216 struct mod_chanmode
*change
;
1217 unsigned int arg
, count
;
1219 change
= mod_chanmode_alloc(argc
-1);
1220 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1221 struct userNode
*victim
;
1222 struct modeNode
*mn
;
1223 if (!(victim
= GetUserH(argv
[arg
])))
1225 if (!(mn
= GetUserMode(channel
, victim
)))
1227 if (mn
->modes
& MODE_CHANOP
)
1229 change
->args
[count
].mode
= MODE_CHANOP
;
1230 change
->args
[count
++].u
.member
= mn
;
1233 change
->argc
= count
;
1234 modcmd_chanmode_announce(change
);
1236 mod_chanmode_free(change
);
1237 reply("OSMSG_OP_DONE");
1241 static MODCMD_FUNC(cmd_hop
)
1243 struct mod_chanmode
*change
;
1244 unsigned int arg
, count
;
1246 change
= mod_chanmode_alloc(argc
-1);
1247 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1248 struct userNode
*victim
;
1249 struct modeNode
*mn
;
1250 if (!(victim
= GetUserH(argv
[arg
])))
1252 if (!(mn
= GetUserMode(channel
, victim
)))
1254 if (mn
->modes
& MODE_HALFOP
)
1256 change
->args
[count
].mode
= MODE_HALFOP
;
1257 change
->args
[count
++].u
.member
= mn
;
1260 change
->argc
= count
;
1261 modcmd_chanmode_announce(change
);
1263 mod_chanmode_free(change
);
1264 reply("OSMSG_HOP_DONE");
1268 static MODCMD_FUNC(cmd_opall
)
1270 struct mod_chanmode
*change
;
1271 unsigned int ii
, count
;
1273 change
= mod_chanmode_alloc(channel
->members
.used
);
1274 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1275 struct modeNode
*mn
= channel
->members
.list
[ii
];
1276 if (mn
->modes
& MODE_CHANOP
)
1278 change
->args
[count
].mode
= MODE_CHANOP
;
1279 change
->args
[count
++].u
.member
= mn
;
1282 change
->argc
= count
;
1283 modcmd_chanmode_announce(change
);
1285 mod_chanmode_free(change
);
1286 reply("OSMSG_OPALL_DONE", channel
->name
);
1290 static MODCMD_FUNC(cmd_hopall
)
1292 struct mod_chanmode
*change
;
1293 unsigned int ii
, count
;
1295 change
= mod_chanmode_alloc(channel
->members
.used
);
1296 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1297 struct modeNode
*mn
= channel
->members
.list
[ii
];
1298 if (mn
->modes
& MODE_HALFOP
)
1300 change
->args
[count
].mode
= MODE_HALFOP
;
1301 change
->args
[count
++].u
.member
= mn
;
1304 change
->argc
= count
;
1305 modcmd_chanmode_announce(change
);
1307 mod_chanmode_free(change
);
1308 reply("OSMSG_HOPALL_DONE", channel
->name
);
1312 static MODCMD_FUNC(cmd_whois
)
1314 struct userNode
*target
;
1318 #ifdef WITH_PROTOCOL_P10
1319 if (argv
[1][0] == '*')
1320 target
= GetUserN(argv
[1]+1);
1323 target
= GetUserH(argv
[1]);
1325 reply("MSG_NICK_UNKNOWN", argv
[1]);
1328 reply("OSMSG_WHOIS_NICK", target
->nick
);
1329 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
1330 if (IsFakeHost(target
))
1331 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
1332 reply("OSMSG_WHOIS_IP", inet_ntoa(target
->ip
));
1333 if (target
->modes
) {
1335 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
1336 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
1337 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
1338 if (IsOper(target
)) buffer
[bpos
++] = 'o';
1339 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
1340 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
1342 // sethost - reed/apples
1343 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
1344 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
1346 if (IsService(target
)) buffer
[bpos
++] = 'k';
1347 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
1348 if (target
->handle_info
) buffer
[bpos
++] = 'r';
1349 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
1350 if (IsGagged(target
)) buffer_cat(" (gagged)");
1351 if (IsRegistering(target
)) buffer_cat(" (registered account)");
1354 reply("OSMSG_WHOIS_MODES", buffer
);
1356 reply("OSMSG_WHOIS_INFO", target
->info
);
1357 #ifdef WITH_PROTOCOL_P10
1358 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
1360 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
1361 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
1362 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
1363 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
1364 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
1365 opserv_ison(user
, target
, "OSMSG_WHOIS_CHANNELS");
1367 reply("OSMSG_WHOIS_HIDECHANS");
1371 static MODCMD_FUNC(cmd_unban
)
1373 struct mod_chanmode change
;
1374 mod_chanmode_init(&change
);
1376 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
1377 change
.args
[0].u
.hostmask
= argv
[1];
1378 modcmd_chanmode_announce(&change
);
1379 reply("OSMSG_UNBAN_DONE", channel
->name
);
1383 static MODCMD_FUNC(cmd_voiceall
)
1385 struct mod_chanmode
*change
;
1386 unsigned int ii
, count
;
1388 change
= mod_chanmode_alloc(channel
->members
.used
);
1389 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1390 struct modeNode
*mn
= channel
->members
.list
[ii
];
1391 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
1393 change
->args
[count
].mode
= MODE_VOICE
;
1394 change
->args
[count
++].u
.member
= mn
;
1397 change
->argc
= count
;
1398 modcmd_chanmode_announce(change
);
1400 mod_chanmode_free(change
);
1401 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
1405 static MODCMD_FUNC(cmd_devoiceall
)
1407 struct mod_chanmode
*change
;
1408 unsigned int ii
, count
;
1410 change
= mod_chanmode_alloc(channel
->members
.used
);
1411 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1412 struct modeNode
*mn
= channel
->members
.list
[ii
];
1413 if (!(mn
->modes
& MODE_VOICE
))
1415 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
1416 change
->args
[count
++].u
.member
= mn
;
1419 change
->argc
= count
;
1420 modcmd_chanmode_announce(change
);
1422 mod_chanmode_free(change
);
1423 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
1427 static MODCMD_FUNC(cmd_stats_bad
) {
1429 unsigned int ii
, end
, here_len
;
1432 /* Show the bad word list.. */
1433 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
1434 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
1435 here_len
= strlen(opserv_bad_words
->list
[ii
]);
1436 /* If the line is full output it & start again */
1437 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1439 reply("OSMSG_BADWORD_LIST", buffer
);
1442 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
1444 buffer
[end
++] = ' ';
1447 reply("OSMSG_BADWORD_LIST", buffer
);
1449 /* Show the exemption list.. */
1450 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
1451 here_len
= strlen(iter_key(it
));
1452 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1454 reply("OSMSG_EXEMPTED_LIST", buffer
);
1457 memcpy(buffer
+end
, iter_key(it
), here_len
);
1459 buffer
[end
++] = ' ';
1462 reply("OSMSG_EXEMPTED_LIST", buffer
);
1466 static MODCMD_FUNC(cmd_stats_glines
) {
1467 reply("OSMSG_GLINE_COUNT", gline_count());
1472 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
1473 unsigned int nn
, pos
;
1476 for (nn
=1; nn
<=depth
; nn
<<=1) ;
1477 for (pos
=0, nn
>>=1; nn
>1; ) {
1479 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
1480 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
1483 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
1484 if (!server
->children
.used
)
1486 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
1487 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
1489 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
1492 static MODCMD_FUNC(cmd_stats_links
) {
1493 trace_links(cmd
->parent
->bot
, user
, self
, 1);
1498 static MODCMD_FUNC(cmd_stats_max
) {
1499 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
1503 static MODCMD_FUNC(cmd_stats_network
) {
1504 struct helpfile_table tbl
;
1505 unsigned int nn
, tot_clients
;
1508 tot_clients
= dict_size(clients
);
1509 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
1510 tbl
.length
= dict_size(servers
)+1;
1512 tbl
.flags
= TABLE_NO_FREE
;
1513 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1514 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1515 tbl
.contents
[0][0] = "Server Name";
1516 tbl
.contents
[0][1] = "Clients";
1517 tbl
.contents
[0][2] = "Load";
1518 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1519 struct server
*server
= iter_data(it
);
1520 char *buffer
= malloc(32);
1521 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1522 tbl
.contents
[nn
][0] = server
->name
;
1523 tbl
.contents
[nn
][1] = buffer
;
1524 sprintf(buffer
, "%u", server
->clients
);
1525 tbl
.contents
[nn
][2] = buffer
+ 16;
1526 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
1529 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1530 for (nn
=1; nn
<tbl
.length
; nn
++) {
1531 free((char*)tbl
.contents
[nn
][1]);
1532 free(tbl
.contents
[nn
]);
1534 free(tbl
.contents
[0]);
1539 static MODCMD_FUNC(cmd_stats_network2
) {
1540 struct helpfile_table tbl
;
1544 tbl
.length
= dict_size(servers
)+1;
1546 tbl
.flags
= TABLE_NO_FREE
;
1547 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1548 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1549 tbl
.contents
[0][0] = "Server Name";
1550 tbl
.contents
[0][1] = "Numeric";
1551 tbl
.contents
[0][2] = "Link Time";
1552 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1553 struct server
*server
= iter_data(it
);
1554 char *buffer
= malloc(64);
1557 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1558 tbl
.contents
[nn
][0] = server
->name
;
1559 #ifdef WITH_PROTOCOL_P10
1560 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
1564 tbl
.contents
[nn
][1] = buffer
;
1565 ofs
= strlen(buffer
) + 1;
1566 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
1567 if (server
->self_burst
)
1568 strcat(buffer
+ ofs
, " Bursting");
1569 tbl
.contents
[nn
][2] = buffer
+ ofs
;
1572 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1573 for (nn
=1; nn
<tbl
.length
; nn
++) {
1574 free((char*)tbl
.contents
[nn
][1]);
1575 free(tbl
.contents
[nn
]);
1577 free(tbl
.contents
[0]);
1582 static MODCMD_FUNC(cmd_stats_reserved
) {
1585 reply("OSMSG_RESERVED_LIST");
1586 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
1587 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
1591 static MODCMD_FUNC(cmd_stats_trusted
) {
1593 struct trusted_host
*th
;
1594 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
1596 reply("OSMSG_TRUSTED_LIST");
1597 reply("OSMSG_TRUSTED_LIST_BAR");
1598 reply("OSMSG_TRUSTED_LIST_HEADER");
1599 reply("OSMSG_TRUSTED_LIST_BAR");
1601 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
1604 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
1606 intervalString(length
, th
->expires
- now
, user
->handle_info
);
1608 sprintf(limit
, "%lu", th
->limit
);
1609 reply("OSMSG_HOST_IS_TRUSTED",
1611 (th
->limit
? limit
: "none"),
1612 (th
->issuer
? th
->issuer
: "<unknown>"),
1613 (th
->issued
? issued
: "some time"),
1614 (th
->expires
? length
: "never"));
1615 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
1617 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
1620 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
1623 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
1625 intervalString(length
, th
->expires
- now
, user
->handle_info
);
1627 sprintf(limit
, "%lu", th
->limit
);
1628 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
1629 (th
->limit
? limit
: "none"),
1630 (th
->issuer
? th
->issuer
: "<unknown>"),
1631 (th
->issued
? issued
: "some time"),
1632 (th
->expires
? length
: "never"));
1633 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
1636 reply("OSMSG_TRUSTED_LIST_END");
1640 static MODCMD_FUNC(cmd_stats_uplink
) {
1641 extern struct cManagerNode cManager
;
1642 struct uplinkNode
*uplink
;
1644 uplink
= cManager
.uplink
;
1645 reply("OSMSG_UPLINK_START", uplink
->name
);
1646 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
1650 static MODCMD_FUNC(cmd_stats_uptime
) {
1651 char uptime
[INTERVALLEN
];
1653 extern time_t boot_time
;
1654 extern int lines_processed
;
1655 static long clocks_per_sec
;
1657 if (!clocks_per_sec
) {
1658 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
1659 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
1660 if (clocks_per_sec
<= 0)
1663 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
1664 clocks_per_sec
= CLOCKS_PER_SEC
;
1667 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
1669 reply("OSMSG_UPTIME_STATS",
1670 uptime
, lines_processed
,
1671 buf
.tms_utime
/(double)clocks_per_sec
,
1672 buf
.tms_stime
/(double)clocks_per_sec
);
1676 static MODCMD_FUNC(cmd_stats_alerts
) {
1678 struct opserv_user_alert
*alert
;
1679 const char *reaction
;
1681 reply("OSMSG_ALERTS_LIST");
1682 reply("OSMSG_ALERTS_BAR");
1683 reply("OSMSG_ALERTS_HEADER");
1684 reply("OSMSG_ALERTS_BAR");
1685 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
1686 alert
= iter_data(it
);
1687 switch (alert
->reaction
) {
1688 case REACT_NOTICE
: reaction
= "notice"; break;
1689 case REACT_KILL
: reaction
= "kill"; break;
1690 case REACT_GLINE
: reaction
= "gline"; break;
1691 default: reaction
= "<unknown>"; break;
1693 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
1694 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
1696 reply("OSMSG_ALERT_END");
1700 static MODCMD_FUNC(cmd_stats_gags
) {
1701 struct gag_entry
*gag
;
1702 struct helpfile_table table
;
1706 reply("OSMSG_NO_GAGS");
1709 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
1710 table
.length
= nn
+1;
1712 table
.flags
= TABLE_NO_FREE
;
1713 table
.contents
= calloc(table
.length
, sizeof(char**));
1714 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1715 table
.contents
[0][0] = "Mask";
1716 table
.contents
[0][1] = "Owner";
1717 table
.contents
[0][2] = "Expires";
1718 table
.contents
[0][3] = "Reason";
1719 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
1720 char expstr
[INTERVALLEN
];
1722 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
1724 strcpy(expstr
, "Never");
1725 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
1726 table
.contents
[nn
][0] = gag
->mask
;
1727 table
.contents
[nn
][1] = gag
->owner
;
1728 table
.contents
[nn
][2] = strdup(expstr
);
1729 table
.contents
[nn
][3] = gag
->reason
;
1731 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
1732 for (nn
=1; nn
<table
.length
; nn
++) {
1733 free((char*)table
.contents
[nn
][2]);
1734 free(table
.contents
[nn
]);
1736 free(table
.contents
[0]);
1737 free(table
.contents
);
1741 static MODCMD_FUNC(cmd_stats_timeq
) {
1742 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
1747 static MODCMD_FUNC(cmd_stats_warn) {
1750 reply("OSMSG_WARN_LISTSTART");
1751 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
1752 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
1753 reply("OSMSG_WARN_LISTEND");
1758 #if defined(WITH_MALLOC_X3)
1759 static MODCMD_FUNC(cmd_stats_memory
) {
1760 extern unsigned long alloc_count
, alloc_size
;
1761 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
1762 "%u allocations totalling %u bytes.",
1763 alloc_count
, alloc_size
);
1766 #elif defined(WITH_MALLOC_SLAB)
1767 static MODCMD_FUNC(cmd_stats_memory
) {
1768 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
1769 extern unsigned long big_alloc_count
, big_alloc_size
;
1770 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
1771 "%u allocations in %u slabs totalling %u bytes.",
1772 slab_alloc_count
, slab_count
, slab_alloc_size
);
1773 /* send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot,
1774 "%u big allocations totalling %u bytes.",
1780 static MODCMD_FUNC(cmd_dump
)
1782 char linedup
[MAXLEN
], original
[MAXLEN
];
1784 unsplit_string(argv
+1, argc
-1, original
);
1785 safestrncpy(linedup
, original
, sizeof(linedup
));
1786 /* assume it's only valid IRC if we can parse it */
1787 if (parse_line(linedup
, 1)) {
1789 reply("OSMSG_LINE_DUMPED");
1791 reply("OSMSG_RAW_PARSE_ERROR");
1795 static MODCMD_FUNC(cmd_raw
)
1797 char linedup
[MAXLEN
], original
[MAXLEN
];
1799 unsplit_string(argv
+1, argc
-1, original
);
1800 safestrncpy(linedup
, original
, sizeof(linedup
));
1801 /* Try to parse the line before sending it; if it's too wrong,
1802 * maybe it will core us instead of our uplink. */
1803 parse_line(linedup
, 1);
1805 reply("OSMSG_LINE_DUMPED");
1809 static struct userNode
*
1810 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
1812 struct userNode
*resv
= GetUserH(nick
);
1814 if (IsService(resv
)) {
1815 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
1818 if (resv
->handle_info
1819 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
1820 reply("OSMSG_LEVEL_TOO_LOW");
1824 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
1825 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
1830 static MODCMD_FUNC(cmd_collide
)
1832 struct userNode
*resv
;
1834 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
1836 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
1839 reply("OSMSG_CLONE_FAILED", argv
[1]);
1844 static MODCMD_FUNC(cmd_reserve
)
1846 struct userNode
*resv
;
1848 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
1850 resv
->modes
|= FLAGS_PERSISTENT
;
1851 reply("OSMSG_RESERVED_NICK", resv
->nick
);
1854 reply("OSMSG_CLONE_FAILED", argv
[1]);
1860 free_reserve(char *nick
)
1862 struct userNode
*resv
;
1866 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
1870 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
1871 reason
= alloca(rlen
);
1872 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
1873 DelUser(resv
, NULL
, 1, reason
);
1874 dict_remove(opserv_reserved_nick_dict
, nick
);
1878 static MODCMD_FUNC(cmd_unreserve
)
1880 if (free_reserve(argv
[1]))
1881 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
1883 reply("OSMSG_NOT_RESERVED", argv
[1]);
1888 opserv_part_channel(void *data
)
1890 DelChannelUser(opserv
, data
, "Leaving.", 0);
1893 static int alert_check_user(const char *key
, void *data
, void *extra
);
1896 opserv_new_user_check(struct userNode
*user
)
1898 struct opserv_hostinfo
*ohi
;
1899 struct gag_entry
*gag
;
1901 /* Check to see if we should ignore them entirely. */
1902 if (IsLocal(user
) || IsService(user
))
1905 /* Check for alerts, and stop if we find one that kills them. */
1906 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
1909 /* Gag them if appropriate. */
1910 for (gag
= gagList
; gag
; gag
= gag
->next
) {
1911 if (user_matches_glob(user
, gag
->mask
, 1)) {
1912 gag_helper_func(user
, NULL
);
1917 /* Add to host info struct */
1918 if (!(ohi
= dict_find(opserv_hostinfo_dict
, inet_ntoa(user
->ip
), NULL
))) {
1919 ohi
= calloc(1, sizeof(*ohi
));
1920 dict_insert(opserv_hostinfo_dict
, strdup(inet_ntoa(user
->ip
)), ohi
);
1921 userList_init(&ohi
->clients
);
1923 userList_append(&ohi
->clients
, user
);
1925 /* Only warn of new user floods outside of bursts. */
1926 if (!user
->uplink
->burst
) {
1927 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
1928 if (!new_user_flood
) {
1930 opserv_alert("Warning: Possible new-user flood.");
1937 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
1938 if (opserv_conf
.untrusted_max
&& user
->ip
.s_addr
&& (ntohl(user
->ip
.s_addr
) != INADDR_LOOPBACK
)) {
1939 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, inet_ntoa(user
->ip
), NULL
);
1940 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
1942 /* 0 means unlimited hosts */
1943 } else if (ohi
->clients
.used
== limit
) {
1945 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
1946 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
1947 } else if (ohi
->clients
.used
> limit
) {
1949 sprintf(target
, "*@%s", inet_ntoa(user
->ip
));
1950 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "AUTO Excessive connections from a single host.", now
, 1);
1958 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
1960 struct opserv_hostinfo
*ohi
;
1962 if (IsLocal(user
)) {
1963 /* Try to remove it from the reserved nick dict without
1964 * calling free_reserve, because that would call DelUser(),
1965 * and we'd loop back to here. */
1966 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
1969 if ((ohi
= dict_find(opserv_hostinfo_dict
, inet_ntoa(user
->ip
), NULL
))) {
1970 userList_remove(&ohi
->clients
, user
);
1971 if (ohi
->clients
.used
== 0) dict_remove(opserv_hostinfo_dict
, inet_ntoa(user
->ip
));
1976 opserv_bad_channel(const char *name
)
1981 dict_find(opserv_exempt_channels
, name
, &present
);
1985 if (gline_find(name
))
1988 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
1989 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
1996 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
1998 struct mod_chanmode
*change
;
2001 change
= mod_chanmode_alloc(2);
2002 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2003 change
->args
[0].mode
= MODE_CHANOP
;
2004 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2005 change
->args
[1].mode
= MODE_BAN
;
2006 change
->args
[1].u
.hostmask
= "*!*@*";
2007 mod_chanmode_announce(opserv
, channel
, change
);
2008 mod_chanmode_free(change
);
2009 for (nn
=channel
->members
.used
; nn
>0; ) {
2010 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2011 if (IsService(mNode
->user
))
2013 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2015 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2019 opserv_channel_check(struct chanNode
*newchan
)
2023 if (!newchan
->join_policer
.params
) {
2024 newchan
->join_policer
.last_req
= now
;
2025 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2028 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2029 char message[MAXLEN];
2030 snprintf(message, sizeof(message), "Channel activity warning for channel %s: %s", newchan->name, warning);
2031 global_message(MESSAGE_RECIPIENT_OPERS, message);
2035 /* Wait until the join check to shut channels down. */
2036 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2040 opserv_channel_delete(struct chanNode
*chan
)
2042 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2046 opserv_join_check(struct modeNode
*mNode
)
2048 struct userNode
*user
= mNode
->user
;
2049 struct chanNode
*channel
= mNode
->channel
;
2052 if (IsService(user
))
2055 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2057 if (channel
->bad_channel
) {
2058 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2059 if (channel
->name
[0] != '#')
2060 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2061 else if (!GetUserMode(channel
, opserv
))
2062 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2064 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2065 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2066 KickChannelUser(user
, channel
, opserv
, msg
);
2071 if (user
->uplink
->burst
)
2073 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2074 channel
->join_flooded
= 0;
2077 if (!channel
->join_flooded
) {
2078 /* Don't moderate the channel unless it is activated and
2079 the number of users in the channel is over the threshold. */
2080 struct mod_chanmode change
;
2081 mod_chanmode_init(&change
);
2082 channel
->join_flooded
= 1;
2083 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2084 if (!GetUserMode(channel
, opserv
)) {
2085 /* If we aren't in the channel, join it. */
2086 change
.args
[0].mode
= MODE_CHANOP
;
2087 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2090 if (!(channel
->modes
& MODE_MODERATED
))
2091 change
.modes_set
|= MODE_MODERATED
;
2092 if (change
.modes_set
|| change
.argc
)
2093 mod_chanmode_announce(opserv
, channel
, &change
);
2094 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2095 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2097 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2100 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2105 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2106 unsigned int bad_idx
;
2108 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2109 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2110 if (irccasestr(new_bad
, orig_bad
)) {
2112 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2114 } else if (irccasestr(orig_bad
, new_bad
)) {
2116 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2118 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2119 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2120 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2121 if (!irccasestr(orig_bad
, new_bad
))
2124 reply("OSMSG_BAD_NUKING", orig_bad
);
2125 string_list_delete(opserv_bad_words
, bad_idx
);
2132 string_list_append(opserv_bad_words
, strdup(new_bad
));
2134 reply("OSMSG_ADDED_BAD", new_bad
);
2138 static MODCMD_FUNC(cmd_addbad
)
2140 unsigned int arg
, count
;
2142 int bad_found
, exempt_found
;
2144 /* Create the bad word if it doesn't exist. */
2145 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
2147 /* Look for exception modifiers. */
2148 for (arg
=2; arg
<argc
; arg
++) {
2149 if (!irccasecmp(argv
[arg
], "except")) {
2150 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
2152 reply("MSG_MISSING_PARAMS", "except");
2155 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
2156 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
2157 if (!exempt_found
) {
2158 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
2162 reply("OSMSG_ADDED_EXEMPTIONS", count
);
2164 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
2165 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
2169 /* Scan for existing channels that match the new bad word. */
2171 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
2172 struct chanNode
*channel
= iter_data(it
);
2174 if (!opserv_bad_channel(channel
->name
))
2176 channel
->bad_channel
= 1;
2177 if (channel
->name
[0] == '#')
2178 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2181 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
2182 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
2183 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2192 static MODCMD_FUNC(cmd_delbad
)
2197 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
2198 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
2199 string_list_delete(opserv_bad_words
, nn
);
2200 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
2201 channel
= iter_data(it
);
2202 if (irccasestr(channel
->name
, argv
[1])
2203 && !opserv_bad_channel(channel
->name
)) {
2204 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
2205 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
2206 channel
->bad_channel
= 0;
2209 reply("OSMSG_REMOVED_BAD", argv
[1]);
2213 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
2217 static MODCMD_FUNC(cmd_addexempt
)
2219 const char *chanName
;
2221 if ((argc
> 1) && IsChannelName(argv
[1])) {
2224 reply("MSG_NOT_CHANNEL_NAME");
2228 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
2229 channel
= GetChannel(chanName
);
2231 if (channel
->bad_channel
) {
2232 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
2233 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
2235 channel
->bad_channel
= 0;
2237 reply("OSMSG_ADDED_EXEMPTION", chanName
);
2241 static MODCMD_FUNC(cmd_delexempt
)
2243 const char *chanName
;
2245 if ((argc
> 1) && IsChannelName(argv
[1])) {
2248 reply("MSG_NOT_CHANNEL_NAME");
2252 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
2253 reply("OSMSG_NOT_EXEMPT", chanName
);
2256 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
2261 opserv_expire_trusted_host(void *data
)
2263 struct trusted_host
*th
= data
;
2264 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
2268 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
2270 struct trusted_host
*th
;
2271 th
= calloc(1, sizeof(*th
));
2274 th
->ipaddr
= strdup(ipaddr
);
2275 th
->reason
= reason
? strdup(reason
) : NULL
;
2276 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
2277 th
->issued
= issued
;
2279 th
->expires
= expires
;
2280 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
2282 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
2286 free_trusted_host(void *data
)
2288 struct trusted_host
*th
= data
;
2295 static MODCMD_FUNC(cmd_addtrust
)
2297 unsigned long interval
;
2299 struct in_addr tmpaddr
;
2302 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
2303 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
2307 if (!inet_aton(argv
[1], &tmpaddr
)) {
2308 reply("OSMSG_BAD_IP", argv
[1]);
2312 count
= strtoul(argv
[2], &tmp
, 10);
2314 reply("OSMSG_BAD_NUMBER", argv
[2]);
2318 interval
= ParseInterval(argv
[3]);
2319 if (!interval
&& strcmp(argv
[3], "0")) {
2320 reply("MSG_INVALID_DURATION", argv
[3]);
2324 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
2325 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
2326 reply("OSMSG_ADDED_TRUSTED");
2330 static MODCMD_FUNC(cmd_edittrust
)
2332 unsigned long interval
;
2333 struct trusted_host
*th
;
2337 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2339 reply("OSMSG_NOT_TRUSTED", argv
[1]);
2342 count
= strtoul(argv
[2], &tmp
, 10);
2343 if (!count
|| *tmp
) {
2344 reply("OSMSG_BAD_NUMBER", argv
[2]);
2347 interval
= ParseInterval(argv
[3]);
2348 if (!interval
&& strcmp(argv
[3], "0")) {
2349 reply("MSG_INVALID_DURATION", argv
[3]);
2352 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
2354 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
2357 th
->reason
= strdup(reason
);
2359 th
->issuer
= strdup(user
->handle_info
->handle
);
2363 th
->expires
= now
+ interval
;
2364 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
2367 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
2371 static MODCMD_FUNC(cmd_deltrust
)
2375 for (n
=1; n
<argc
; n
++) {
2376 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
2380 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
2381 dict_remove(opserv_trusted_hosts
, argv
[n
]);
2383 reply("OSMSG_REMOVED_TRUSTED");
2387 /* This doesn't use dict_t because it's a little simpler to open-code the
2388 * comparisons (and simpler arg-passing for the ADD subcommand).
2390 static MODCMD_FUNC(cmd_clone
)
2393 struct userNode
*clone
;
2395 clone
= GetUserH(argv
[2]);
2396 if (!irccasecmp(argv
[1], "ADD")) {
2398 char ident
[USERLEN
+1];
2401 reply("MSG_MISSING_PARAMS", argv
[1]);
2406 reply("OSMSG_CLONE_EXISTS", argv
[2]);
2409 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
2410 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
2411 if (argv
[3][i
] == '@') {
2415 ident
[i
] = argv
[3][i
];
2418 if (!argv
[3][i
] || (i
==USERLEN
)) {
2419 reply("OSMSG_NOT_A_HOSTMASK");
2422 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
2423 reply("OSMSG_CLONE_FAILED", argv
[2]);
2426 reply("OSMSG_CLONE_ADDED", clone
->nick
);
2430 reply("MSG_NICK_UNKNOWN", argv
[2]);
2433 if (clone
->uplink
!= self
|| IsService(clone
)) {
2434 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
2437 if (!irccasecmp(argv
[1], "REMOVE")) {
2440 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
2443 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
2444 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
2447 DelUser(clone
, NULL
, 1, reason
);
2448 reply("OSMSG_CLONE_REMOVED", argv
[2]);
2452 reply("MSG_MISSING_PARAMS", argv
[1]);
2456 channel
= GetChannel(argv
[3]);
2457 if (!irccasecmp(argv
[1], "JOIN")) {
2459 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
2460 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2463 AddChannelUser(clone
, channel
);
2464 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
2467 if (!irccasecmp(argv
[1], "PART")) {
2469 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2472 if (!GetUserMode(channel
, clone
)) {
2473 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
2476 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
2477 DelChannelUser(clone
, channel
, "Leaving.", 0);
2480 if (!irccasecmp(argv
[1], "OP")) {
2481 struct mod_chanmode change
;
2483 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2486 mod_chanmode_init(&change
);
2488 change
.args
[0].mode
= MODE_CHANOP
;
2489 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
2490 if (!change
.args
[0].u
.member
) {
2491 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
2494 modcmd_chanmode_announce(&change
);
2495 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
2498 if (!irccasecmp(argv
[1], "HOP")) {
2499 struct mod_chanmode change
;
2501 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
2504 mod_chanmode_init(&change
);
2506 change
.args
[0].mode
= MODE_HALFOP
;
2507 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
2508 if (!change
.args
[0].u
.member
) {
2509 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
2512 modcmd_chanmode_announce(&change
);
2513 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
2517 reply("MSG_MISSING_PARAMS", argv
[1]);
2521 if (!irccasecmp(argv
[1], "SAY")) {
2522 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
2523 irc_privmsg(clone
, argv
[3], text
);
2524 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
2527 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
2531 static struct helpfile_expansion
2532 opserv_help_expand(const char *variable
)
2534 extern struct userNode
*message_source
;
2535 struct helpfile_expansion exp
;
2536 struct service
*service
;
2542 if (!(service
= service_find(message_source
->nick
))) {
2543 exp
.type
= HF_STRING
;
2544 exp
.value
.str
= NULL
;
2545 } else if (!irccasecmp(variable
, "index")) {
2546 exp
.type
= HF_TABLE
;
2547 exp
.value
.table
.length
= 1;
2548 exp
.value
.table
.width
= 2;
2549 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
2550 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
2551 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
2552 exp
.value
.table
.contents
[0][0] = "Command";
2553 exp
.value
.table
.contents
[0][1] = "Level";
2554 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
2555 cmd
= iter_data(it
);
2556 row
= exp
.value
.table
.length
++;
2557 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
2558 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
2559 level
= cmd
->min_opserv_level
;
2560 if (!level_strings
[level
]) {
2561 level_strings
[level
] = malloc(16);
2562 snprintf(level_strings
[level
], 16, "%3d", level
);
2564 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
2566 } else if (!strncasecmp(variable
, "level", 5)) {
2567 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
2568 exp
.type
= HF_STRING
;
2570 level
= cmd
->min_opserv_level
;
2571 exp
.value
.str
= malloc(16);
2572 snprintf(exp
.value
.str
, 16, "%3d", level
);
2574 exp
.value
.str
= NULL
;
2577 exp
.type
= HF_STRING
;
2578 exp
.value
.str
= NULL
;
2584 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
2586 char buf
[16], *flags
= NULL
;
2587 unsigned int iflags
= 0;
2588 sprintf(buf
, "%d", min_level
);
2590 case 1: flags
= "+acceptchan"; break;
2591 case 3: flags
= "+acceptpluschan"; /* fall through */
2592 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
2595 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
2597 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
2601 int add_reserved(const char *key
, void *data
, void *extra
)
2603 struct record_data
*rd
= data
;
2604 const char *ident
, *hostname
, *desc
;
2605 struct userNode
*reserve
;
2606 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
2608 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
2611 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
2613 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
2616 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
2618 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
2621 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
2622 reserve
->modes
|= FLAGS_PERSISTENT
;
2623 dict_insert(extra
, reserve
->nick
, reserve
);
2629 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
2633 unsigned int matched
;
2635 if (!self
->uplink
) return 0;
2636 discrim
= calloc(1, sizeof(*discrim
));
2637 discrim
->limit
= dict_size(clients
);
2638 discrim
->max_level
= ~0;
2639 discrim
->max_ts
= now
;
2640 discrim
->max_channels
= INT_MAX
;
2641 discrim
->authed
= -1;
2642 discrim
->info_space
= -1;
2643 discrim
->use_regex
= 0;
2644 dupmask
= strdup(hostmask
);
2645 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
2646 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "0123456789.?*")]) {
2647 if (!parse_ipmask(discrim
->mask_host
, &discrim
->ip_addr
, &discrim
->ip_mask
)) {
2648 log_module(OS_LOG
, LOG_ERROR
, "Couldn't parse %s as an IP mask!", discrim
->mask_host
);
2653 discrim
->mask_host
= 0;
2655 matched
= opserv_discrim_search(discrim
, func
, extra
);
2657 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
2666 gag_free(struct gag_entry
*gag
)
2668 unsigned int ungagged
;
2670 /* Remove from gag list */
2671 if (gagList
== gag
) {
2672 gagList
= gag
->next
;
2674 struct gag_entry
*prev
;
2675 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
2676 prev
->next
= gag
->next
;
2679 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
2681 /* Deallocate storage */
2691 gag_expire(void *data
)
2697 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
2699 struct gag_entry
*gag
;
2701 /* Create gag and put it into linked list */
2702 gag
= calloc(1, sizeof(*gag
));
2703 gag
->mask
= strdup(mask
);
2704 gag
->owner
= strdup(owner
? owner
: "<unknown>");
2705 gag
->reason
= strdup(reason
? reason
: "<unknown>");
2706 gag
->expires
= expires
;
2708 timeq_add(gag
->expires
, gag_expire
, gag
);
2709 gag
->next
= gagList
;
2712 /* If we're linked, see if who the gag applies to */
2713 return foreach_matching_user(mask
, gag_helper_func
, gag
);
2717 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
2719 struct record_data
*rd
= data
;
2720 char *owner
, *reason
, *expstr
;
2723 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
2724 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
2725 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
2726 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
2727 gag_create(key
, owner
, reason
, expires
);
2732 static struct opserv_user_alert
*
2733 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
)
2736 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
2737 struct opserv_user_alert
*alert
;
2740 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
2741 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
2744 alert
= malloc(sizeof(*alert
));
2745 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
2746 alert
->text_discrim
= strdup(text_discrim
);
2747 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
2748 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
2749 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
2750 if (!alert
->discrim
) {
2751 free(alert
->text_discrim
);
2756 alert
->split_discrim
= discrim_copy
;
2757 name_dup
= strdup(name
);
2758 if (!alert
->discrim
->reason
)
2759 alert
->discrim
->reason
= strdup(name
);
2760 alert
->reaction
= reaction
;
2761 dict_insert(opserv_user_alerts
, name_dup
, alert
);
2762 /* Stick the alert into the appropriate additional alert dict(s).
2763 * For channel alerts, we only use channels and min_channels;
2764 * max_channels would have to be checked on /part, which we do not
2765 * yet do, and which seems of questionable value.
2767 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
2768 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
2769 if (alert
->discrim
->mask_nick
)
2770 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
2776 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
2778 struct record_data *rd = data;
2779 char *reason = GET_RECORD_QSTRING(rd);
2781 * i hope this can't happen *
2783 reason = "No Reason";
2785 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
2791 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
2794 const char *discrim
, *react
, *owner
;
2795 opserv_alert_reaction reaction
;
2796 struct opserv_user_alert
*alert
;
2798 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
2799 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
2802 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
2803 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
2804 if (!react
|| !irccasecmp(react
, "notice"))
2805 reaction
= REACT_NOTICE
;
2806 else if (!irccasecmp(react
, "kill"))
2807 reaction
= REACT_KILL
;
2808 else if (!irccasecmp(react
, "gline"))
2809 reaction
= REACT_GLINE
;
2811 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
2814 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
);
2816 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
2819 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
2821 alert
->owner
= strdup(owner
? owner
: "<unknown>");
2826 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
2828 struct record_data
*rd
= data
;
2829 const char *limit
, *str
, *reason
, *issuer
;
2830 time_t issued
, expires
;
2832 if (rd
->type
== RECDB_QSTRING
) {
2833 /* old style host by itself */
2834 limit
= GET_RECORD_QSTRING(rd
);
2839 } else if (rd
->type
== RECDB_OBJECT
) {
2840 dict_t obj
= GET_RECORD_OBJECT(rd
);
2841 /* new style structure */
2842 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
2843 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
2844 expires
= str
? ParseInterval(str
) : 0;
2845 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
2846 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
2847 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
2848 issued
= str
? ParseInterval(str
) : 0;
2852 if (expires
&& (expires
< now
))
2854 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
2859 opserv_saxdb_read(struct dict
*conf_db
)
2862 struct record_data
*rd
;
2866 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
2867 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
2868 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
2870 case RECDB_STRING_LIST
:
2871 /* Add words one by one just in case there are overlaps from an old DB. */
2872 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
2873 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
2876 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
2877 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
2879 if (rd
->type
== RECDB_STRING_LIST
)
2880 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
2881 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
2888 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
2889 && (rd
->type
== RECDB_STRING_LIST
)) {
2890 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
2891 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
2893 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
2895 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
2896 max_clients
= atoi(str
);
2897 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
2898 max_clients_time
= atoi(str
);
2900 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
2901 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
2902 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
2903 dict_foreach(object
, add_gag_helper
, NULL
);
2904 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
2905 dict_foreach(object
, add_user_alert
, NULL
);
2907 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
2908 dict_foreach(object, add_chan_warn, NULL);
2914 opserv_saxdb_write(struct saxdb_context
*ctx
)
2916 struct string_list
*slist
;
2919 /* reserved nicks */
2920 if (dict_size(opserv_reserved_nick_dict
)) {
2921 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
2922 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
2923 struct userNode
*user
= iter_data(it
);
2924 if (!IsPersistent(user
)) continue;
2925 saxdb_start_record(ctx
, iter_key(it
), 0);
2926 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
2927 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
2928 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
2929 saxdb_end_record(ctx
);
2931 saxdb_end_record(ctx
);
2934 if (opserv_bad_words
->used
) {
2935 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
2937 /* insert exempt channel names */
2938 if (dict_size(opserv_exempt_channels
)) {
2939 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
2940 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
2941 string_list_append(slist
, strdup(iter_key(it
)));
2943 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
2944 free_string_list(slist
);
2946 /* trusted hosts takes a little more work */
2947 if (dict_size(opserv_trusted_hosts
)) {
2948 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
2949 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2950 struct trusted_host
*th
= iter_data(it
);
2951 saxdb_start_record(ctx
, iter_key(it
), 0);
2952 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
2953 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
2954 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
2955 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
2956 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
2957 saxdb_end_record(ctx
);
2959 saxdb_end_record(ctx
);
2963 struct gag_entry
*gag
;
2964 saxdb_start_record(ctx
, KEY_GAGS
, 1);
2965 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2966 saxdb_start_record(ctx
, gag
->mask
, 0);
2967 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
2968 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
2969 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
2970 saxdb_end_record(ctx
);
2972 saxdb_end_record(ctx
);
2974 /* channel warnings */
2976 if (dict_size(opserv_chan_warn)) {
2977 saxdb_start_record(ctx, KEY_WARN, 0);
2978 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
2979 saxdb_write_string(ctx, iter_key(it), iter_data(it));
2981 saxdb_end_record(ctx);
2985 if (dict_size(opserv_user_alerts
)) {
2986 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
2987 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2988 struct opserv_user_alert
*alert
= iter_data(it
);
2989 const char *reaction
;
2990 saxdb_start_record(ctx
, iter_key(it
), 0);
2991 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
2992 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
2993 switch (alert
->reaction
) {
2994 case REACT_NOTICE
: reaction
= "notice"; break;
2995 case REACT_KILL
: reaction
= "kill"; break;
2996 case REACT_GLINE
: reaction
= "gline"; break;
2999 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
3002 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
3003 saxdb_end_record(ctx
);
3005 saxdb_end_record(ctx
);
3008 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
3009 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
3010 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
3011 saxdb_end_record(ctx
);
3016 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
3018 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
3022 static MODCMD_FUNC(cmd_query
)
3024 struct record_data
*rd
;
3029 reply("OSMSG_OPTION_ROOT");
3030 conf_enum_root(query_keys_helper
, user
);
3034 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
3035 if (!(rd
= conf_get_node(nodename
))) {
3036 reply("OSMSG_UNKNOWN_OPTION", nodename
);
3040 if (rd
->type
== RECDB_QSTRING
)
3041 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
3042 else if (rd
->type
== RECDB_STRING_LIST
) {
3043 reply("OSMSG_OPTION_LIST", nodename
);
3044 if (rd
->d
.slist
->used
)
3045 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
3046 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
3048 reply("OSMSG_OPTION_LIST_EMPTY");
3049 } else if (rd
->type
== RECDB_OBJECT
) {
3050 reply("OSMSG_OPTION_KEYS", nodename
);
3051 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
3057 static MODCMD_FUNC(cmd_set
)
3059 struct record_data
*rd
;
3061 /* I originally wanted to be able to fully manipulate the config
3062 db with this, but i wussed out. feel free to fix this - you'll
3063 need to handle quoted strings which have been split, and likely
3064 invent a syntax for it. -Zoot */
3066 if (!(rd
= conf_get_node(argv
[1]))) {
3067 reply("OSMSG_SET_NOT_SET", argv
[1]);
3071 if (rd
->type
!= RECDB_QSTRING
) {
3072 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
3076 free(rd
->d
.qstring
);
3077 rd
->d
.qstring
= strdup(argv
[2]);
3078 conf_call_reload_funcs();
3079 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
3083 static MODCMD_FUNC(cmd_settime
)
3085 const char *srv_name_mask
= "*";
3086 time_t new_time
= now
;
3089 srv_name_mask
= argv
[1];
3091 new_time
= time(NULL
);
3092 irc_settime(srv_name_mask
, new_time
);
3093 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
3098 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
3103 discrim
= calloc(1, sizeof(*discrim
));
3104 discrim
->limit
= 250;
3105 discrim
->max_level
= ~0;
3106 discrim
->max_ts
= INT_MAX
;
3107 discrim
->domain_depth
= 2;
3108 discrim
->max_channels
= INT_MAX
;
3109 discrim
->authed
= -1;
3110 discrim
->info_space
= -1;
3112 for (i
=0; i
<argc
; i
++) {
3113 if (irccasecmp(argv
[i
], "log") == 0) {
3114 discrim
->option_log
= 1;
3117 /* Assume all other criteria require arguments. */
3118 if (i
== argc
- 1) {
3119 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
3122 if (irccasecmp(argv
[i
], "mask") == 0) {
3123 if (!is_ircmask(argv
[++i
])) {
3124 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
3127 if (!split_ircmask(argv
[i
],
3128 &discrim
->mask_nick
,
3129 &discrim
->mask_ident
,
3130 &discrim
->mask_host
)) {
3131 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
3134 } else if (irccasecmp(argv
[i
], "nick") == 0) {
3135 discrim
->mask_nick
= argv
[++i
];
3136 } else if (irccasecmp(argv
[i
], "ident") == 0) {
3137 discrim
->mask_ident
= argv
[++i
];
3138 } else if (irccasecmp(argv
[i
], "host") == 0) {
3139 discrim
->mask_host
= argv
[++i
];
3140 } else if (irccasecmp(argv
[i
], "info") == 0) {
3141 discrim
->mask_info
= argv
[++i
];
3142 } else if (irccasecmp(argv
[i
], "server") == 0) {
3143 discrim
->server
= argv
[++i
];
3144 } else if (irccasecmp(argv
[i
], "ip") == 0) {
3145 j
= parse_ipmask(argv
[++i
], &discrim
->ip_addr
, &discrim
->ip_mask
);
3146 if (!j
) discrim
->ip_mask_str
= argv
[i
];
3147 } else if (irccasecmp(argv
[i
], "account") == 0) {
3148 if (discrim
->authed
== 0) {
3149 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
3152 discrim
->accountmask
= argv
[++i
];
3153 discrim
->authed
= 1;
3154 } else if (irccasecmp(argv
[i
], "authed") == 0) {
3155 i
++; /* true_string and false_string are macros! */
3156 if (true_string(argv
[i
])) {
3157 discrim
->authed
= 1;
3158 } else if (false_string(argv
[i
])) {
3159 if (discrim
->accountmask
) {
3160 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
3163 discrim
->authed
= 0;
3165 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
3168 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
3169 /* XXX: A hack because you can't check explicitly for a space through
3170 * any other means */
3172 if (true_string(argv
[i
])) {
3173 discrim
->info_space
= 1;
3174 } else if (false_string(argv
[i
])) {
3175 discrim
->info_space
= 0;
3177 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
3180 } else if (irccasecmp(argv
[i
], "regex") == 0) {
3182 if (true_string(argv
[i
])) {
3183 discrim
->use_regex
= 1;
3184 } else if (false_string(argv
[i
])) {
3185 discrim
->use_regex
= 0;
3187 send_message(user
, opserv
, "MSG_INVALID_BINARY", argv
[i
]);
3190 } else if (irccasecmp(argv
[i
], "duration") == 0) {
3191 discrim
->duration
= ParseInterval(argv
[++i
]);
3192 } else if (irccasecmp(argv
[i
], "channel") == 0) {
3193 for (j
=0, i
++; ; j
++) {
3194 switch (argv
[i
][j
]) {
3198 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
3201 discrim
->chan_req_modes
|= MODE_VOICE
;
3202 discrim
->chan_no_modes
|= MODE_CHANOP
;
3203 discrim
->chan_no_modes
|= MODE_HALFOP
;
3206 discrim
->chan_req_modes
|= MODE_HALFOP
;
3207 discrim
->chan_no_modes
|= MODE_CHANOP
;
3208 discrim
->chan_no_modes
|= MODE_VOICE
;
3211 discrim
->chan_req_modes
|= MODE_CHANOP
;
3214 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
3219 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
3220 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
3221 /* secretly "allow_channel" now means "if a channel name is
3222 * specified, require that it currently exist" */
3223 if (allow_channel
) {
3224 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
3227 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
3230 LockChannel(discrim
->channel
);
3231 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
3232 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
3233 } else if (irccasecmp(argv
[i
], "limit") == 0) {
3234 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
3235 } else if (irccasecmp(argv
[i
], "reason") == 0) {
3236 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
3238 } else if (irccasecmp(argv
[i
], "last") == 0) {
3239 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
3240 } else if ((irccasecmp(argv
[i
], "linked") == 0)
3241 || (irccasecmp(argv
[i
], "nickage") == 0)) {
3242 const char *cmp
= argv
[++i
];
3243 if (cmp
[0] == '<') {
3244 if (cmp
[1] == '=') {
3245 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
3247 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
3249 } else if (cmp
[0] == '>') {
3250 if (cmp
[1] == '=') {
3251 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
3253 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
3256 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
3258 } else if (irccasecmp(argv
[i
], "access") == 0) {
3259 const char *cmp
= argv
[++i
];
3260 if (cmp
[0] == '<') {
3261 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
3262 if (cmp
[1] == '=') {
3263 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
3265 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
3267 } else if (cmp
[0] == '=') {
3268 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
3269 } else if (cmp
[0] == '>') {
3270 if (cmp
[1] == '=') {
3271 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
3273 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
3276 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
3278 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
3279 && (irccasecmp(argv
[++i
], "opers") == 0)) {
3280 discrim
->match_opers
= 1;
3281 } else if (irccasecmp(argv
[i
], "depth") == 0) {
3282 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
3283 } else if (irccasecmp(argv
[i
], "clones") == 0) {
3284 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
3286 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
3291 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
3292 discrim
->mask_nick
= 0;
3294 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
3295 discrim
->mask_ident
= 0;
3297 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
3298 discrim
->mask_info
= 0;
3300 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
3301 discrim
->mask_host
= 0;
3304 if(discrim
->use_regex
)
3306 if(discrim
->mask_nick
)
3308 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
3309 discrim
->has_regex_nick
= !err
;
3313 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
3315 send_message(user
, opserv
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
3320 if(discrim
->mask_ident
)
3322 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
3323 discrim
->has_regex_ident
= !err
;
3327 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
3329 send_message(user
, opserv
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
3334 if(discrim
->mask_host
)
3336 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
3337 discrim
->has_regex_host
= !err
;
3341 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
3343 send_message(user
, opserv
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
3348 if(discrim
->mask_info
)
3350 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
3351 discrim
->has_regex_info
= !err
;
3355 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
3357 send_message(user
, opserv
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
3370 if(discrim
->has_regex_nick
)
3371 regfree(&discrim
->regex_nick
);
3372 if(discrim
->has_regex_ident
)
3373 regfree(&discrim
->regex_ident
);
3374 if(discrim
->has_regex_host
)
3375 regfree(&discrim
->regex_host
);
3376 if(discrim
->has_regex_info
)
3377 regfree(&discrim
->regex_info
);
3384 discrim_match(discrim_t discrim
, struct userNode
*user
)
3386 unsigned int access
;
3388 if ((user
->timestamp
< discrim
->min_ts
)
3389 || (user
->timestamp
> discrim
->max_ts
)
3390 || (user
->channels
.used
< discrim
->min_channels
)
3391 || (user
->channels
.used
> discrim
->max_channels
)
3392 || (discrim
->authed
== 0 && user
->handle_info
)
3393 || (discrim
->authed
== 1 && !user
->handle_info
)
3394 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
3395 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
3396 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
3397 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
3398 || (discrim
->ip_mask
&& !MATCH_IPMASK(user
->ip
, discrim
->ip_addr
, discrim
->ip_mask
))) {
3402 if(discrim
->use_regex
)
3404 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
3405 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
3406 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
3407 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))) {
3413 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
3414 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
3415 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
3416 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))) {
3421 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
)) return 0;
3422 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
3423 if ((access
< discrim
->min_level
)
3424 || (access
> discrim
->max_level
)) {
3427 if (discrim
->ip_mask_str
) {
3428 if (!match_ircglob(inet_ntoa(user
->ip
), discrim
->ip_mask_str
)) return 0;
3430 if (discrim
->min_clones
> 1) {
3431 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, inet_ntoa(user
->ip
), NULL
);
3432 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
)) return 0;
3438 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
3440 unsigned int nn
, count
;
3441 struct userList matched
;
3443 userList_init(&matched
);
3444 /* Try most optimized search methods first */
3445 if (discrim
->channel
) {
3447 (nn
< discrim
->channel
->members
.used
)
3448 && (matched
.used
< discrim
->limit
);
3450 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
3451 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
3452 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
3455 if (discrim_match(discrim
, mn
->user
)) {
3456 userList_append(&matched
, mn
->user
);
3459 } else if (discrim
->ip_mask_str
&& !discrim
->ip_mask_str
[strcspn(discrim
->ip_mask_str
, "?*")]) {
3460 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, discrim
->ip_mask_str
, NULL
);
3462 userList_clean(&matched
);
3465 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
3466 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
3467 userList_append(&matched
, ohi
->clients
.list
[nn
]);
3472 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
3473 if (discrim_match(discrim
, iter_data(it
))) {
3474 userList_append(&matched
, iter_data(it
));
3479 if (!matched
.used
) {
3480 userList_clean(&matched
);
3484 if (discrim
->option_log
) {
3485 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
3487 for (nn
=0; nn
<matched
.used
; nn
++) {
3488 struct userNode
*user
= matched
.list
[nn
];
3489 if (discrim
->option_log
) {
3490 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
3492 if (dsf(user
, data
)) {
3493 /* If a search function returns true, it ran into a
3494 problem. Stop going through the list. */
3498 if (discrim
->option_log
) {
3499 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
3501 count
= matched
.used
;
3502 userList_clean(&matched
);
3507 trace_print_func(struct userNode
*match
, void *extra
)
3509 struct discrim_and_source
*das
= extra
;
3510 if (match
->handle_info
) {
3511 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s (%s)", match
->nick
, match
->ident
, match
->hostname
, match
->handle_info
->handle
);
3513 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
3519 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
3525 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
3527 return !(IsService(target
)
3528 || (!match_opers
&& IsOper(target
))
3529 || (target
->handle_info
3530 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
3534 trace_gline_func(struct userNode
*match
, void *extra
)
3536 struct discrim_and_source
*das
= extra
;
3538 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
3539 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
3546 trace_kill_func(struct userNode
*match
, void *extra
)
3548 struct discrim_and_source
*das
= extra
;
3550 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
3552 if (das
->discrim
->reason
) {
3553 reason
= das
->discrim
->reason
;
3555 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
3556 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
3558 DelUser(match
, opserv
, 1, reason
);
3565 is_gagged(char *mask
)
3567 struct gag_entry
*gag
;
3569 for (gag
= gagList
; gag
; gag
= gag
->next
) {
3570 if (match_ircglobs(gag
->mask
, mask
)) return 1;
3576 trace_gag_func(struct userNode
*match
, void *extra
)
3578 struct discrim_and_source
*das
= extra
;
3580 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
3581 char *reason
, *mask
;
3583 if (das
->discrim
->reason
) {
3584 reason
= das
->discrim
->reason
;
3586 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
3587 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
3589 masksize
= 5+strlen(match
->hostname
);
3590 mask
= alloca(masksize
);
3591 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
3592 if (!is_gagged(mask
)) {
3593 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
3594 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
3602 trace_domains_func(struct userNode
*match
, void *extra
)
3604 struct discrim_and_source
*das
= extra
;
3605 unsigned long *count
;
3609 if (!match
->hostname
[strspn(match
->hostname
, "0123456789.")]) {
3611 unsigned long matchip
= ntohl(match
->ip
.s_addr
);
3612 /* raw IP address.. use up to first three octets of IP */
3613 switch (das
->discrim
->domain_depth
) {
3615 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
3618 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
3621 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
3626 hostname
= match
->hostname
+ strlen(match
->hostname
);
3627 for (depth
=das
->discrim
->domain_depth
;
3628 depth
&& (hostname
> match
->hostname
);
3631 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
3633 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
3635 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
3636 count
= calloc(1, sizeof(*count
));
3637 dict_insert(das
->dict
, strdup(hostname
), count
);
3644 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
3646 unsigned long *count
= data
;
3647 struct discrim_and_source
*das
= extra
;
3649 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
3650 return !--das
->disp_limit
;
3653 static MODCMD_FUNC(cmd_trace
)
3655 struct discrim_and_source das
;
3656 discrim_search_func action
;
3657 unsigned int matches
;
3658 struct svccmd
*subcmd
;
3661 sprintf(buf
, "trace %s", argv
[1]);
3662 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
3663 reply("OSMSG_BAD_ACTION", argv
[1]);
3666 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
3668 if (!irccasecmp(argv
[1], "print"))
3669 action
= trace_print_func
;
3670 else if (!irccasecmp(argv
[1], "count"))
3671 action
= trace_count_func
;
3672 else if (!irccasecmp(argv
[1], "domains"))
3673 action
= trace_domains_func
;
3674 else if (!irccasecmp(argv
[1], "gline"))
3675 action
= trace_gline_func
;
3676 else if (!irccasecmp(argv
[1], "kill"))
3677 action
= trace_kill_func
;
3678 else if (!irccasecmp(argv
[1], "gag"))
3679 action
= trace_gag_func
;
3681 reply("OSMSG_BAD_ACTION", argv
[1]);
3685 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
3686 reply("OSMSG_LEVEL_TOO_LOW");
3692 das
.destination
= cmd
->parent
->bot
;
3693 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
3697 if (action
== trace_print_func
)
3699 reply("OSMSG_USER_SEARCH_RESULTS");
3700 reply("OSMSG_USER_SEARCH_BAR");
3701 reply("OSMSG_USER_SEARCH_HEADER");
3702 reply("OSMSG_USER_SEARCH_BAR");
3704 else if (action
== trace_count_func
)
3705 das
.discrim
->limit
= INT_MAX
;
3706 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
3707 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
3708 else if (action
== trace_domains_func
) {
3709 das
.dict
= dict_new();
3710 dict_set_free_data(das
.dict
, free
);
3711 dict_set_free_keys(das
.dict
, free
);
3712 das
.disp_limit
= das
.discrim
->limit
;
3713 das
.discrim
->limit
= INT_MAX
;
3715 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
3717 if (action
== trace_domains_func
)
3718 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
3722 if(action
== trace_print_func
)
3723 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
3725 reply("OSMSG_USER_SEARCH_COUNT", matches
);
3728 reply("MSG_NO_MATCHES");
3730 if (das
.discrim
->channel
)
3731 UnlockChannel(das
.discrim
->channel
);
3732 free(das
.discrim
->reason
);
3734 if(das
.discrim
->has_regex_nick
)
3735 regfree(&das
.discrim
->regex_nick
);
3736 if(das
.discrim
->has_regex_ident
)
3737 regfree(&das
.discrim
->regex_ident
);
3738 if(das
.discrim
->has_regex_host
)
3739 regfree(&das
.discrim
->regex_host
);
3740 if(das
.discrim
->has_regex_info
)
3741 regfree(&das
.discrim
->regex_info
);
3744 dict_delete(das
.dict
);
3748 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
3750 typedef struct channel_discrim
{
3753 unsigned int min_users
, max_users
;
3754 time_t min_ts
, max_ts
;
3758 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
3759 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
3762 smart_parse_time(const char *str
) {
3763 /* If an interval-style string is given, treat as time before now.
3764 * If it's all digits, treat directly as a Unix timestamp. */
3765 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
3769 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
3774 discrim
= calloc(1, sizeof(*discrim
));
3775 discrim
->limit
= 25;
3777 for (i
= 0; i
< argc
; i
++) {
3778 /* Assume all criteria require arguments. */
3779 if (i
== (argc
- 1)) {
3780 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
3784 if (!irccasecmp(argv
[i
], "name"))
3785 discrim
->name
= argv
[++i
];
3786 else if (!irccasecmp(argv
[i
], "topic"))
3787 discrim
->topic
= argv
[++i
];
3788 else if (!irccasecmp(argv
[i
], "users")) {
3789 const char *cmp
= argv
[++i
];
3790 if (cmp
[0] == '<') {
3792 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
3794 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
3795 } else if (cmp
[0] == '=') {
3796 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
3797 } else if (cmp
[0] == '>') {
3799 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
3801 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
3803 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
3805 } else if (!irccasecmp(argv
[i
], "timestamp")) {
3806 const char *cmp
= argv
[++i
];
3807 if (cmp
[0] == '<') {
3809 discrim
->max_ts
= smart_parse_time(cmp
+2);
3811 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
3812 } else if (cmp
[0] == '=') {
3813 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
3814 } else if (cmp
[0] == '>') {
3816 discrim
->min_ts
= smart_parse_time(cmp
+2);
3818 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
3820 discrim
->min_ts
= smart_parse_time(cmp
);
3822 } else if (!irccasecmp(argv
[i
], "limit")) {
3823 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
3825 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
3830 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
3832 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
3842 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
3844 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
3845 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
3846 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
3847 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
3848 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
3849 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
3855 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
3857 unsigned int count
= 0;
3858 dict_iterator_t it
, next
;
3860 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
3861 struct chanNode
*chan
= iter_data(it
);
3863 /* Hold on to the next channel in case we decide to
3864 add actions that destructively modify the channel. */
3865 next
= iter_next(it
);
3866 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
3867 dsf(chan
, data
, bot
);
3875 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
3879 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
3882 irc_make_chanmode(channel
, modes
);
3883 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
3886 static MODCMD_FUNC(cmd_csearch
)
3889 unsigned int matches
;
3890 cdiscrim_search_func action
;
3891 struct svccmd
*subcmd
;
3894 if (!irccasecmp(argv
[1], "count"))
3895 action
= channel_count
;
3896 else if (!irccasecmp(argv
[1], "print"))
3897 action
= channel_print
;
3899 reply("OSMSG_BAD_ACTION", argv
[1]);
3903 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
3904 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
3905 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
3909 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
3913 if (action
== channel_print
)
3914 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
3915 else if (action
== channel_count
)
3916 discrim
->limit
= INT_MAX
;
3918 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
3921 reply("MSG_MATCH_COUNT", matches
);
3923 reply("MSG_NO_MATCHES");
3929 static MODCMD_FUNC(cmd_gsync
)
3933 src
= GetServerH(argv
[1]);
3935 reply("MSG_SERVER_UNKNOWN", argv
[1]);
3941 irc_stats(cmd
->parent
->bot
, src
, 'G');
3942 reply("OSMSG_GSYNC_RUNNING", src
->name
);
3946 struct gline_extra
{
3947 struct userNode
*user
;
3948 struct string_list
*glines
;
3949 struct userNode
*bot
;
3953 gtrace_print_func(struct gline
*gline
, void *extra
)
3955 struct gline_extra
*xtra
= extra
;
3956 char *when_text
, set_text
[20];
3957 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
3958 when_text
= asctime(localtime(&gline
->expires
));
3959 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
3960 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
3964 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
3969 gtrace_ungline_func(struct gline
*gline
, void *extra
)
3971 struct gline_extra
*xtra
= extra
;
3972 string_list_append(xtra
->glines
, strdup(gline
->target
));
3975 static MODCMD_FUNC(cmd_gtrace
)
3977 struct gline_discrim
*discrim
;
3978 gline_search_func action
;
3979 unsigned int matches
, nn
;
3980 struct gline_extra extra
;
3981 struct svccmd
*subcmd
;
3984 if (!irccasecmp(argv
[1], "print"))
3985 action
= gtrace_print_func
;
3986 else if (!irccasecmp(argv
[1], "count"))
3987 action
= gtrace_count_func
;
3988 else if (!irccasecmp(argv
[1], "ungline"))
3989 action
= gtrace_ungline_func
;
3991 reply("OSMSG_BAD_ACTION", argv
[1]);
3994 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
3995 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
3996 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
4000 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
4004 if (action
== gtrace_print_func
)
4005 reply("OSMSG_GLINE_SEARCH_RESULTS");
4006 else if (action
== gtrace_count_func
)
4007 discrim
->limit
= INT_MAX
;
4010 extra
.glines
= alloc_string_list(4);
4011 extra
.bot
= cmd
->parent
->bot
;
4012 matches
= gline_discrim_search(discrim
, action
, &extra
);
4014 if (action
== gtrace_ungline_func
)
4015 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
4016 gline_remove(extra
.glines
->list
[nn
], 1);
4017 free_string_list(extra
.glines
);
4020 reply("MSG_MATCH_COUNT", matches
);
4022 reply("MSG_NO_MATCHES");
4023 free(discrim
->alt_target_mask
);
4029 alert_check_user(const char *key
, void *data
, void *extra
)
4031 struct opserv_user_alert
*alert
= data
;
4032 struct userNode
*user
= extra
;
4034 if (!discrim_match(alert
->discrim
, user
))
4037 if ((alert
->reaction
!= REACT_NOTICE
)
4039 && !alert
->discrim
->match_opers
) {
4043 /* The user matches the alert criteria, so trigger the reaction. */
4044 if (alert
->discrim
->option_log
)
4045 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
);
4047 /* Return 1 to halt alert matching, such as when killing the user
4048 that triggered the alert. */
4049 switch (alert
->reaction
) {
4051 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
4054 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
4057 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
4058 /* fall through to REACT_NOTICE case */
4060 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
);
4067 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
4069 struct gag_entry
*gag
;
4070 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
4071 /* Gag them if appropriate (and only if). */
4072 user
->modes
&= ~FLAGS_GAGGED
;
4073 for (gag
= gagList
; gag
; gag
= gag
->next
) {
4074 if (user_matches_glob(user
, gag
->mask
, 1)) {
4075 gag_helper_func(user
, NULL
);
4082 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
4086 if (!opserv_conf
.staff_auth_channel
4087 || user
->uplink
->burst
4088 || !user
->handle_info
)
4090 else if (user
->handle_info
->opserv_level
)
4092 else if (IsNetworkHelper(user
))
4093 type
= "NETWORK HELPER";
4094 else if (IsSupportHelper(user
))
4095 type
= "SUPPORT HELPER";
4099 if (user
->ip
.s_addr
)
4100 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
4102 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
);
4105 static MODCMD_FUNC(cmd_log
)
4107 struct logSearch
*discrim
;
4108 unsigned int matches
;
4109 struct logReport report
;
4111 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
4115 reply("OSMSG_LOG_SEARCH_RESULTS");
4116 report
.reporter
= opserv
;
4118 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
4121 reply("MSG_MATCH_COUNT", matches
);
4123 reply("MSG_NO_MATCHES");
4130 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
4132 if (IsOper(match
) || IsLocal(match
))
4134 match
->modes
|= FLAGS_GAGGED
;
4138 static MODCMD_FUNC(cmd_gag
)
4140 struct gag_entry
*gag
;
4141 unsigned int gagged
;
4142 unsigned long duration
;
4145 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
4147 if (!is_ircmask(argv
[1])) {
4148 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
4152 for (gag
= gagList
; gag
; gag
= gag
->next
)
4153 if (match_ircglobs(gag
->mask
, argv
[1]))
4157 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
4161 duration
= ParseInterval(argv
[2]);
4162 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
4165 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
4167 reply("OSMSG_GAG_ADDED", argv
[1]);
4172 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
4174 match
->modes
&= ~FLAGS_GAGGED
;
4178 static MODCMD_FUNC(cmd_ungag
)
4180 struct gag_entry
*gag
;
4181 unsigned int ungagged
;
4183 for (gag
= gagList
; gag
; gag
= gag
->next
)
4184 if (!strcmp(gag
->mask
, argv
[1]))
4188 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
4192 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
4193 ungagged
= gag_free(gag
);
4196 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
4198 reply("OSMSG_UNGAG_ADDED", argv
[1]);
4202 static MODCMD_FUNC(cmd_addalert
)
4204 opserv_alert_reaction reaction
;
4205 struct svccmd
*subcmd
;
4210 sprintf(buf
, "addalert %s", argv
[2]);
4211 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
4212 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
4215 if (!irccasecmp(argv
[2], "notice"))
4216 reaction
= REACT_NOTICE
;
4217 else if (!irccasecmp(argv
[2], "kill"))
4218 reaction
= REACT_KILL
;
4219 else if (!irccasecmp(argv
[2], "gline"))
4220 reaction
= REACT_GLINE
;
4222 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
4225 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
4226 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
)))
4228 reply("OSMSG_ADDED_ALERT", name
);
4232 static MODCMD_FUNC(cmd_delalert
)
4235 for (i
=1; i
<argc
; i
++) {
4236 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
4237 dict_remove(opserv_channel_alerts
, argv
[i
]);
4238 if (dict_remove(opserv_user_alerts
, argv
[i
]))
4239 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
4241 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
4247 opserv_conf_read(void)
4249 struct record_data
*rd
;
4250 dict_t conf_node
, child
;
4251 const char *str
, *str2
;
4252 struct policer_params
*pp
;
4255 rd
= conf_get_node(OPSERV_CONF_NAME
);
4256 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
4257 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
4260 conf_node
= rd
->d
.object
;
4261 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
4262 if (opserv
&& str
) {
4263 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
4266 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
4267 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
4269 opserv_conf
.debug_channel
= NULL
;
4271 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
4272 if (opserv
&& str
) {
4273 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
4276 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
4277 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
4279 opserv_conf
.alert_channel
= NULL
;
4281 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
4282 if (opserv
&& str
) {
4283 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
4286 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
4287 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
4289 opserv_conf
.staff_auth_channel
= NULL
;
4292 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
4293 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
4295 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
4296 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
4297 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
4298 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
4299 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
4300 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
4301 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
4302 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
4303 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
4305 NickChange(opserv
, str
, 0);
4306 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
4307 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
4308 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
4309 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
4311 if (!opserv_conf
.join_policer_params
)
4312 opserv_conf
.join_policer_params
= policer_params_new();
4313 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
4314 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
4315 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
4316 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
4318 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4319 struct chanNode
*cNode
= iter_data(it
);
4320 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
4323 if (opserv_conf
.new_user_policer
.params
)
4324 pp
= opserv_conf
.new_user_policer
.params
;
4326 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
4327 policer_params_set(pp
, "size", "200");
4328 policer_params_set(pp
, "drain-rate", "3");
4329 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
4330 dict_foreach(child
, set_policer_param
, pp
);
4333 /* lame way to export opserv_conf value to nickserv.c ... */
4335 opserv_conf_admin_level()
4337 return(opserv_conf
.admin_level
);
4341 opserv_db_init(void) {
4342 /* set up opserv_trusted_hosts dict */
4343 dict_delete(opserv_trusted_hosts
);
4344 opserv_trusted_hosts
= dict_new();
4345 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
4346 /* set up opserv_chan_warn dict */
4348 /* alert trace notice channel #x replaces warnings
4349 dict_delete(opserv_chan_warn);
4350 opserv_chan_warn = dict_new();
4351 dict_set_free_keys(opserv_chan_warn, free);
4352 dict_set_free_data(opserv_chan_warn, free);
4354 /* set up opserv_user_alerts */
4355 dict_delete(opserv_channel_alerts
);
4356 opserv_channel_alerts
= dict_new();
4357 dict_delete(opserv_nick_based_alerts
);
4358 opserv_nick_based_alerts
= dict_new();
4359 dict_delete(opserv_user_alerts
);
4360 opserv_user_alerts
= dict_new();
4361 dict_set_free_keys(opserv_user_alerts
, free
);
4362 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
4363 /* set up opserv_bad_words */
4364 free_string_list(opserv_bad_words
);
4365 opserv_bad_words
= alloc_string_list(4);
4366 /* and opserv_exempt_channels */
4367 dict_delete(opserv_exempt_channels
);
4368 opserv_exempt_channels
= dict_new();
4369 dict_set_free_keys(opserv_exempt_channels
, free
);
4373 opserv_db_cleanup(void)
4377 /* dict_delete(opserv_chan_warn); */
4378 dict_delete(opserv_reserved_nick_dict
);
4379 free_string_list(opserv_bad_words
);
4380 dict_delete(opserv_exempt_channels
);
4381 dict_delete(opserv_trusted_hosts
);
4382 unreg_del_user_func(opserv_user_cleanup
);
4383 dict_delete(opserv_hostinfo_dict
);
4384 dict_delete(opserv_nick_based_alerts
);
4385 dict_delete(opserv_channel_alerts
);
4386 dict_delete(opserv_user_alerts
);
4387 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
4388 free(level_strings
[nn
]);
4391 policer_params_delete(opserv_conf
.join_policer_params
);
4392 policer_params_delete(opserv_conf
.new_user_policer
.params
);
4396 init_opserv(const char *nick
)
4398 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
4400 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
4401 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
4403 conf_register_reload(opserv_conf_read
);
4405 memset(level_strings
, 0, sizeof(level_strings
));
4406 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
4407 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
4408 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
4409 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
4410 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
4411 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
4412 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
4413 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
4414 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
4415 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
4416 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
4417 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
4418 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
4419 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
4420 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
4421 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
4422 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
4423 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
4424 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
4425 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
4426 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
4427 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
4428 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
4429 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
4430 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
4431 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
4432 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
4433 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
4434 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
4435 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
4436 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
4437 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
4438 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
4439 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
4440 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
4441 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
4442 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
4443 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
4444 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
4445 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
4446 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
4447 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
4448 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
4449 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
4450 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
4451 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
4452 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
4453 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
4454 opserv_define_func("OP", cmd_op
, 100, 2, 2);
4455 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
4456 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
4457 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
4458 opserv_define_func("PART", cmd_part
, 601, 0, 2);
4459 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
4460 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
4461 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
4462 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
4463 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
4464 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
4465 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
4466 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
4467 opserv_define_func("SET", cmd_set
, 900, 0, 3);
4468 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
4469 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
4470 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
4471 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
4472 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
4473 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
4474 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
4475 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
4476 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
4477 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
4478 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
4479 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
4480 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
4481 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
4482 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
4483 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
4484 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
4486 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
4487 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
4488 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
4489 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
4490 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
4491 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
4492 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
4493 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
4494 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
4495 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
4496 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
4497 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
4498 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
4499 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
4500 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
4501 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
4502 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
4504 opserv_reserved_nick_dict
= dict_new();
4505 opserv_hostinfo_dict
= dict_new();
4506 dict_set_free_keys(opserv_hostinfo_dict
, free
);
4507 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
4509 reg_new_user_func(opserv_new_user_check
);
4510 reg_nick_change_func(opserv_alert_check_nick
);
4511 reg_del_user_func(opserv_user_cleanup
);
4512 reg_new_channel_func(opserv_channel_check
);
4513 reg_del_channel_func(opserv_channel_delete
);
4514 reg_join_func(opserv_join_check
);
4515 reg_auth_func(opserv_staff_alert
);
4518 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
4521 opserv_service
= service_register(opserv
);
4522 opserv_service
->trigger
= '?';
4525 reg_exit_func(opserv_db_cleanup
);
4526 message_register_table(msgtab
);