1 /* opserv.c - IRC Operator assistance service
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 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.
35 #ifdef HAVE_SYS_TIMES_H
36 #include <sys/times.h>
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
41 #ifdef HAVE_ARPA_INET_H
42 #include <arpa/inet.h>
46 #define OPSERV_CONF_NAME "services/opserv"
48 #define KEY_ALERT_CHANNEL "alert_channel"
49 #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes"
50 #define KEY_DEBUG_CHANNEL "debug_channel"
51 #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes"
52 #define KEY_UNTRUSTED_MAX "untrusted_max"
53 #define KEY_PURGE_LOCK_DELAY "purge_lock_delay"
54 #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate"
55 #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold"
56 #define KEY_NICK "nick"
57 #define KEY_JOIN_POLICER "join_policer"
58 #define KEY_NEW_USER_POLICER "new_user_policer"
59 #define KEY_AUTOJOIN_CHANNELS "autojoin_channels"
60 #define KEY_REASON "reason"
61 #define KEY_RESERVES "reserves"
62 #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */
63 #define KEY_HOSTNAME "hostname"
64 #define KEY_DESC "description"
65 #define KEY_BAD_WORDS "bad"
66 #define KEY_EXEMPT_CHANNELS "exempt"
67 #define KEY_SECRET_WORDS "secret"
68 #define KEY_TRUSTED_HOSTS "trusted"
69 #define KEY_OWNER "owner"
70 #define KEY_GAGS "gags"
71 #define KEY_ALERTS "alerts"
72 #define KEY_REACTION "reaction"
73 #define KEY_DISCRIM "discrim"
74 #define KEY_WARN "chanwarn"
76 #define KEY_TIME "time"
77 #define KEY_MAX_CLIENTS "max_clients"
78 #define KEY_LIMIT "limit"
79 #define KEY_EXPIRES "expires"
80 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
81 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
82 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
83 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
84 #define KEY_BLOCK_SHUN_DURATION "block_shun_duration"
85 #define KEY_ISSUER "issuer"
86 #define KEY_ISSUED "issued"
87 #define KEY_ADMIN_LEVEL "admin_level"
88 #define KEY_SILENT_LEVEL "silent_level"
89 #define KEY_UPLINK "uplink"
90 #define KEY_SECOND "secondaryuplink"
91 #define KEY_PORT "port"
92 #define KEY_KARMA "karma"
93 #define KEY_OFFLINE "offline"
94 #define KEY_ROUTINGPLAN "routingplan"
95 #define KEY_ROUTINGPLAN_OPTIONS "routingplan_options"
97 /* Routing karma values: */
98 /* What value we start out with when new servers are added: */
99 #define KARMA_DEFAULT 10
102 #define KARMA_MIN -10
103 /* ping out, reduce karma by this much: */
104 #define KARMA_PINGOUT -8
105 /* read err, reduce karma by this much: */
106 #define KARMA_READERROR -5
107 /* every 24 hours everyone gets this much added (so we eventually re-try bad servers) */
108 #define KARMA_ENTROPE 1
109 /* every 24 hours servers linked for 24 hours get an additional ammount: */
110 #define KARMA_RELIABLE 1
111 /* How often to run entrope and reliable checks */
112 #define KARMA_TIMER 86400 /* 1 day */
114 #define ROUTING_CONNECT_TIMEOUT 30 /* 30 seconds */
116 #define IDENT_FORMAT "%s [%s@%s/%s]"
117 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, irc_ntoa(&user->ip)
118 #define MAX_CHANNELS_WHOIS 50
119 #define OSMSG_PART_REASON "%s has no reason."
120 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
121 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
122 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
124 static const struct message_entry msgtab
[] = {
125 { "OSMSG_BAR", "----------------------------------------" },
126 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
127 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
128 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
129 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
130 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
131 { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." },
132 { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." },
133 { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." },
134 { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." },
135 { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." },
136 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
137 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
138 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
139 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
140 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
141 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
142 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
143 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
144 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
145 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
146 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
147 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
148 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
149 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
150 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
151 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
152 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
153 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
154 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
155 { "OSMSG_LEAVING", "Leaving $b%s$b." },
156 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
157 { "OSMSG_OP_DONE", "Opped the requested lusers." },
158 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
159 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
160 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
161 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
162 { "OSMSG_WHOIS_NICK", "Nick : %s" },
163 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
164 { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" },
165 { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" },
166 { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" },
167 { "OSMSG_WHOIS_IP", "Real IP : %s" },
168 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
169 { "OSMSG_WHOIS_INFO", "Info : %s" },
170 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
171 { "OSMSG_WHOIS_SERVER", "Server : %s" },
172 { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" },
173 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
174 { "OSMSG_WHOIS_CHANNELS", "Channels : %s" },
175 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
176 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
177 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
178 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
179 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
180 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
181 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
182 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
183 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
184 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
185 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
186 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
187 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
188 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
189 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
190 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
191 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
192 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
193 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
194 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
195 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
196 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
197 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
198 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
199 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
200 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
201 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
202 { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." },
203 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
204 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
205 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
206 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
207 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
208 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
209 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
210 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
211 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
212 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
213 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
214 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
215 { "OSMSG_LINE_DUMPED", "Raw line sent." },
216 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
217 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
218 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
219 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
220 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
221 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
222 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
223 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
224 { "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." },
225 { "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." },
226 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
227 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
228 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
229 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
230 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
231 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
232 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
233 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
234 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
235 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
236 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
237 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
238 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
239 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
240 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
241 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
242 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
243 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
244 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
245 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
246 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
247 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
248 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
249 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
250 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
251 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
252 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
253 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
254 { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" },
255 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
256 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
257 { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
258 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
259 { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
260 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
261 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
262 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
263 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
264 { "OSMSG_NO_GAGS", "No gags have been set." },
265 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
266 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
267 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
268 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
269 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
270 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
271 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
272 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
273 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" },
274 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
275 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
276 { "OSMSG_ALERTS_DESC", " Criteria: %s" },
277 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
278 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
279 /* routing messages */
280 { "OSMSG_ROUTINGPLAN_LIST", "$bRouting Plans$b" },
281 { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" },
282 { "OSMSG_ROUTINGPLAN_END", "-------------End of Routing Plans-------------" },
283 { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" },
284 { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." },
285 { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." },
286 { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." },
287 { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." },
288 { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" },
289 { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" },
290 { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." },
291 { "OSMSG_ADDPLAN_FAILURE", "Could not add new plan '%s' (does it already exist?)." },
292 { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." },
293 { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." },
294 { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." },
295 { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." },
296 { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." },
297 { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." },
298 { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." },
299 { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" },
300 { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" },
301 { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" },
302 { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" },
303 { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" },
304 { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." },
305 { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." },
306 { "OSMSG_CONNECT", "->connect %s %d %s" },
307 { "OSMSG_SQUIT", "->squit %s" },
308 { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" },
309 { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" },
310 { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." },
311 { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." },
312 { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." },
313 { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." },
314 { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." },
315 { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", },
316 { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." },
317 { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." },
319 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
320 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
321 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
322 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
323 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
324 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
325 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
326 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
327 { "OSMSG_INVALID_NUMERIC", "Invalid numeric" },
328 { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." },
329 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
330 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
332 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
333 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
334 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
335 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
336 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
337 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
338 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
340 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
341 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
342 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
343 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
344 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
345 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
346 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
347 { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." },
348 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
349 { "OSMSG_CHANINFO_HEADER", "%s Information" },
350 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
351 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
352 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
353 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
354 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
355 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
356 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
357 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
358 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
359 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
360 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
361 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
362 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
363 { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" },
364 { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" },
368 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
370 extern void add_track_user(struct userNode
*user
);
371 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
373 struct userNode
*opserv
;
374 static struct service
*opserv_service
;
376 /*static dict_t opserv_chan_warn; */ /* data is char* */
377 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
378 static struct string_list
*opserv_bad_words
;
379 static dict_t opserv_exempt_channels
; /* data is not used */
380 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
381 static dict_t opserv_routing_plans
; /* data is struct routingPlan */
382 static dict_t opserv_routing_plan_options
; /* data is a dict_t key->val list*/
383 static dict_t opserv_waiting_connections
; /* data is struct waitingConnection */
384 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
385 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
386 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
387 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
388 static struct module *opserv_module
;
389 static struct log_type
*OS_LOG
;
390 static unsigned int new_user_flood
;
391 static char *level_strings
[1001];
392 struct string_list
*autojoin_channels
;
393 struct route
*opserv_route
= NULL
; /* Main active routing table from activate_routing()*/
396 struct chanNode
*debug_channel
;
397 struct chanNode
*alert_channel
;
398 struct chanNode
*staff_auth_channel
;
399 struct policer_params
*join_policer_params
;
400 struct policer new_user_policer
;
401 unsigned long untrusted_max
;
402 unsigned long clone_gline_duration
;
403 unsigned long block_gline_duration
;
404 unsigned long block_shun_duration
;
405 unsigned long purge_lock_delay
;
406 unsigned long join_flood_moderate
;
407 unsigned long join_flood_moderate_threshold
;
408 unsigned long admin_level
;
409 unsigned long silent_level
;
412 struct trusted_host
{
426 struct gag_entry
*next
;
429 static struct gag_entry
*gagList
;
431 struct opserv_hostinfo
{
432 struct userList clients
;
433 struct trusted_host
*trusted
;
437 opserv_free_hostinfo(void *data
)
439 struct opserv_hostinfo
*ohi
= data
;
440 userList_clean(&ohi
->clients
);
445 opserv_free_waiting_connection(void *data
)
447 struct waitingConnection
*wc
= data
;
453 typedef struct opservDiscrim
{
454 struct chanNode
*channel
;
455 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *server
, *reason
, *accountmask
;
456 irc_in_addr_t ip_mask
;
458 time_t min_ts
, max_ts
;
459 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
;
460 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1;
461 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
462 unsigned char ip_mask_bits
;
463 unsigned int match_opers
: 1, option_log
: 1;
464 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
465 int authed
: 2, info_space
: 2;
466 unsigned int intra_scmp
: 2, intra_dcmp
: 2;
467 unsigned int use_regex
: 1;
468 unsigned int silent
: 1;
471 struct discrim_and_source
{
473 struct userNode
*source
;
474 struct userNode
*destination
;
476 unsigned int disp_limit
;
479 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
480 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
481 static int gag_helper_func(struct userNode
*match
, void *extra
);
482 static int ungag_helper_func(struct userNode
*match
, void *extra
);
491 } opserv_alert_reaction
;
493 struct opserv_user_alert
{
495 char *text_discrim
, *split_discrim
;
497 opserv_alert_reaction reaction
;
500 /* funny type to make it acceptible to dict_set_free_data, far below */
502 opserv_free_user_alert(void *data
)
504 struct opserv_user_alert
*alert
= data
;
505 if (alert
->discrim
->channel
)
506 UnlockChannel(alert
->discrim
->channel
);
508 free(alert
->text_discrim
);
509 free(alert
->split_discrim
);
510 if(alert
->discrim
->has_regex_nick
)
511 regfree(&alert
->discrim
->regex_nick
);
512 if(alert
->discrim
->has_regex_ident
)
513 regfree(&alert
->discrim
->regex_ident
);
514 if(alert
->discrim
->has_regex_host
)
515 regfree(&alert
->discrim
->regex_host
);
516 if(alert
->discrim
->has_regex_info
)
517 regfree(&alert
->discrim
->regex_info
);
518 free(alert
->discrim
->reason
);
519 free(alert
->discrim
);
523 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
524 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
527 /* A lot of these commands are very similar to what ChanServ can do,
528 * but OpServ can do them even on channels that aren't registered.
531 static MODCMD_FUNC(cmd_access
)
533 struct handle_info
*hi
;
537 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
538 if (!irccasecmp(target
, "*")) {
539 nickserv_show_oper_accounts(user
, cmd
);
542 if (!(hi
= modcmd_get_handle_info(user
, target
)))
544 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
545 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
549 static MODCMD_FUNC(cmd_ban
)
551 struct mod_chanmode change
;
552 struct userNode
*victim
;
554 mod_chanmode_init(&change
);
556 change
.args
[0].mode
= MODE_BAN
;
557 if (is_ircmask(argv
[1]))
558 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
559 else if ((victim
= GetUserH(argv
[1])))
560 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
562 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
565 modcmd_chanmode_announce(&change
);
566 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
567 free((char*)change
.args
[0].u
.hostmask
);
571 static MODCMD_FUNC(cmd_chaninfo
)
576 struct exemptNode
*exempt
;
577 struct modeNode
*moden
;
580 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
581 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
582 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
583 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
584 irc_make_chanmode(channel
, buffer
);
585 if (channel
->bad_channel
)
586 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
588 reply("OSMSG_CHANINFO_MODES", buffer
);
589 if (channel
->topic_time
) {
590 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
591 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
592 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
594 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
595 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
597 if (channel
->banlist
.used
) {
598 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
599 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
600 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
601 ban
= channel
->banlist
.list
[n
];
602 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
603 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
606 if (channel
->exemptlist
.used
) {
607 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
608 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
609 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
610 exempt
= channel
->exemptlist
.list
[n
];
611 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
612 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
615 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
616 /* early out unless they ask for users */
617 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
620 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
621 for (n
=0; n
<channel
->members
.used
; n
++) {
622 moden
= channel
->members
.list
[n
];
623 if (moden
->modes
& MODE_CHANOP
) {
624 if (moden
->oplevel
>= 0)
625 send_message_type(4, user
, cmd
->parent
->bot
, " @%s:%d (%s@%s)", moden
->user
->nick
, moden
->oplevel
, moden
->user
->ident
, moden
->user
->hostname
);
627 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
630 for (n
=0; n
<channel
->members
.used
; n
++) {
631 moden
= channel
->members
.list
[n
];
632 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
633 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
635 for (n
=0; n
<channel
->members
.used
; n
++) {
636 moden
= channel
->members
.list
[n
];
637 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
638 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
640 for (n
=0; n
<channel
->members
.used
; n
++) {
641 moden
= channel
->members
.list
[n
];
642 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
643 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
648 /* This command has been replaced by 'alert notice channel #foo' */
650 static MODCMD_FUNC(cmd_warn)
652 char *reason, *message;
654 if (!IsChannelName(argv[1])) {
655 reply("OSMSG_NEED_CHANNEL", argv[0]);
658 reason = dict_find(opserv_chan_warn, argv[1], NULL);
660 reply("OSMSG_WARN_EXISTS", argv[1]);
664 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
666 reason = strdup("No reason");
667 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
668 reply("OSMSG_WARN_ADDED", argv[1], reason);
669 if (dict_find(channels, argv[1], NULL)) {
670 message = alloca(strlen(reason) + strlen(argv[1]) + 55);
671 sprintf(message, "Channel activity warning for channel %s: %s", argv[1], reason);
672 global_message(MESSAGE_RECIPIENT_OPERS, message);
677 static MODCMD_FUNC(cmd_unwarn)
679 if ((argc < 2) || !IsChannelName(argv[1])) {
680 reply("OSMSG_NEED_CHANNEL", argv[0]);
683 if (!dict_remove(opserv_chan_warn, argv[1])) {
684 reply("OSMSG_WARN_NOEXIST", argv[1]);
687 reply("OSMSG_WARN_DELETED", argv[1]);
692 static MODCMD_FUNC(cmd_clearbans
)
694 struct mod_chanmode
*change
;
697 change
= mod_chanmode_alloc(channel
->banlist
.used
);
698 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
699 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
700 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
702 modcmd_chanmode_announce(change
);
703 for (ii
=0; ii
<change
->argc
; ++ii
)
704 free((char*)change
->args
[ii
].u
.hostmask
);
705 mod_chanmode_free(change
);
706 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
710 static MODCMD_FUNC(cmd_clearmodes
)
712 struct mod_chanmode change
;
714 if (!channel
->modes
) {
715 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
718 mod_chanmode_init(&change
);
719 change
.modes_clear
= channel
->modes
;
720 modcmd_chanmode_announce(&change
);
721 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
725 static MODCMD_FUNC(cmd_deop
)
727 struct mod_chanmode
*change
;
728 unsigned int arg
, count
;
730 change
= mod_chanmode_alloc(argc
-1);
731 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
732 struct userNode
*victim
= GetUserH(argv
[arg
]);
734 if (!victim
|| IsService(victim
)
735 || !(mn
= GetUserMode(channel
, victim
))
736 || !(mn
->modes
& MODE_CHANOP
))
738 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
739 change
->args
[count
++].u
.member
= mn
;
742 change
->argc
= count
;
743 modcmd_chanmode_announce(change
);
745 mod_chanmode_free(change
);
746 reply("OSMSG_DEOP_DONE");
750 static MODCMD_FUNC(cmd_dehop
)
752 struct mod_chanmode
*change
;
753 unsigned int arg
, count
;
755 change
= mod_chanmode_alloc(argc
-1);
756 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
757 struct userNode
*victim
= GetUserH(argv
[arg
]);
759 if (!victim
|| IsService(victim
)
760 || !(mn
= GetUserMode(channel
, victim
))
761 || !(mn
->modes
& MODE_HALFOP
))
763 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
764 change
->args
[count
++].u
.member
= mn
;
767 change
->argc
= count
;
768 modcmd_chanmode_announce(change
);
770 mod_chanmode_free(change
);
771 reply("OSMSG_DEHOP_DONE");
775 static MODCMD_FUNC(cmd_deopall
)
777 struct mod_chanmode
*change
;
778 unsigned int ii
, count
;
780 change
= mod_chanmode_alloc(channel
->members
.used
);
781 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
782 struct modeNode
*mn
= channel
->members
.list
[ii
];
783 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
785 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
786 change
->args
[count
++].u
.member
= mn
;
789 change
->argc
= count
;
790 modcmd_chanmode_announce(change
);
792 mod_chanmode_free(change
);
793 reply("OSMSG_DEOPALL_DONE", channel
->name
);
797 static MODCMD_FUNC(cmd_dehopall
)
799 struct mod_chanmode
*change
;
800 unsigned int ii
, count
;
802 change
= mod_chanmode_alloc(channel
->members
.used
);
803 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
804 struct modeNode
*mn
= channel
->members
.list
[ii
];
805 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
807 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
808 change
->args
[count
++].u
.member
= mn
;
811 change
->argc
= count
;
812 modcmd_chanmode_announce(change
);
814 mod_chanmode_free(change
);
815 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
819 static MODCMD_FUNC(cmd_resetmax
)
821 max_clients
= dict_size(clients
);
822 max_clients_time
= now
;
823 reply("OSMSG_MAXUSERS_RESET", max_clients
);
827 static MODCMD_FUNC(cmd_rehash
)
829 extern char *services_config
;
831 if (conf_read(services_config
))
832 reply("OSMSG_REHASH_COMPLETE");
834 reply("OSMSG_REHASH_FAILED");
838 static MODCMD_FUNC(cmd_reopen
)
841 reply("OSMSG_REOPEN_COMPLETE");
845 static MODCMD_FUNC(cmd_reconnect
)
847 reply("OSMSG_RECONNECTING");
848 irc_squit(self
, "Reconnecting.", NULL
);
852 static MODCMD_FUNC(cmd_jupe
)
854 extern int force_n2k
;
855 struct server
*newsrv
;
857 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
861 reply("OSMSG_INVALID_NUMERIC");
864 if ((num
< 64) && !force_n2k
) {
865 inttobase64(numeric
, num
, 1);
866 inttobase64(numeric
+1, 64*64-1, 2);
868 inttobase64(numeric
, num
, 2);
869 inttobase64(numeric
+2, 64*64*64-1, 3);
871 #ifdef WITH_PROTOCOL_P10
872 if (GetServerN(numeric
)) {
873 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
877 if (GetServerH(argv
[1])) {
878 reply("OSMSG_NAME_COLLIDE");
881 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
882 if(!strchr(argv
[1], '.')) {
883 reply("OSMSG_INVALID_SERVERNAME");
886 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
888 reply("OSMSG_SRV_CREATE_FAILED");
892 reply("OSMSG_SERVER_JUPED", argv
[1]);
896 static MODCMD_FUNC(cmd_unjupe
)
901 srv
= GetServerH(argv
[1]);
903 reply("MSG_SERVER_UNKNOWN", argv
[1]);
906 if (strncmp(srv
->description
, "JUPE", 4)) {
907 reply("OSMSG_SERVER_NOT_JUPE");
910 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
911 DelServer(srv
, 1, reason
);
912 reply("OSMSG_SERVER_UNJUPED");
916 static MODCMD_FUNC(cmd_jump
)
918 extern struct cManagerNode cManager
;
919 void uplink_select(char *name
);
920 struct uplinkNode
*uplink_find(char *name
);
921 struct uplinkNode
*uplink
;
924 target
= unsplit_string(argv
+1, argc
-1, NULL
);
926 if (!strcmp(cManager
.uplink
->name
, target
)) {
927 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
931 uplink
= uplink_find(target
);
933 reply("OSMSG_INVALID_UPLINK", target
);
936 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
937 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
941 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
942 uplink_select(target
);
943 irc_squit(self
, "Reconnecting.", NULL
);
947 static MODCMD_FUNC(cmd_die
)
951 text
= unsplit_string(argv
+1, argc
-1, NULL
);
952 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
953 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
954 irc_squit(self
, reason
, text
);
959 static MODCMD_FUNC(cmd_restart
)
961 extern int services_argc
;
962 extern char **services_argv
;
963 char **restart_argv
, *reason
, *text
;
965 text
= unsplit_string(argv
+1, argc
-1, NULL
);
966 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
967 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
968 irc_squit(self
, reason
, text
);
970 /* Append a NULL to the end of argv[]. */
971 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
972 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
973 restart_argv
[services_argc
] = NULL
;
978 execv(services_argv
[0], restart_argv
);
980 /* If we're still here, that means something went wrong. Reconnect. */
984 static struct gline
*
985 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
, int silent
)
987 char mask
[IRC_NTOP_MAX_SIZE
+3] = { '*', '@', '\0' };
988 irc_ntop(mask
+ 2, sizeof(mask
) - 2, &target
->ip
);
990 snprintf(reason
= alloca(MAXLEN
), MAXLEN
,
991 "G-line requested by %s.", src_handle
);
993 duration
= opserv_conf
.block_gline_duration
;
994 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1, silent
? 1 : 0);
997 static MODCMD_FUNC(cmd_block
)
999 struct userNode
*target
;
1000 struct gline
*gline
;
1003 target
= GetUserH(argv
[1]);
1005 reply("MSG_NICK_UNKNOWN", argv
[1]);
1008 if (IsService(target
)) {
1009 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1012 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1013 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0, 0);
1014 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1018 static MODCMD_FUNC(cmd_gline
)
1020 unsigned long duration
;
1022 struct gline
*gline
;
1024 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1025 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1026 reply("MSG_INVALID_GLINE", argv
[1]);
1029 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1030 reply("OSMSG_STUPID_GLINE", argv
[1]);
1033 duration
= ParseInterval(argv
[2]);
1035 reply("MSG_INVALID_DURATION", argv
[2]);
1038 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1, 0);
1039 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1043 static MODCMD_FUNC(cmd_ungline
)
1045 if (gline_remove(argv
[1], 1))
1046 reply("OSMSG_GLINE_REMOVED", argv
[1]);
1048 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
1052 static MODCMD_FUNC(cmd_refreshg
)
1059 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1060 srv
= iter_data(it
);
1061 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1063 gline_refresh_server(srv
);
1064 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
1068 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1072 gline_refresh_all();
1073 reply("OSMSG_GLINES_REFRESHED");
1078 static struct shun
*
1079 opserv_shun(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
1082 mask
= alloca(MAXLEN
);
1083 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
1085 reason
= alloca(MAXLEN
);
1086 snprintf(reason
, MAXLEN
, "Shun requested by %s.", src_handle
);
1088 if (!duration
) duration
= opserv_conf
.block_shun_duration
;
1089 return shun_add(src_handle
, mask
, duration
, reason
, now
, 1);
1092 static MODCMD_FUNC(cmd_sblock
)
1094 struct userNode
*target
;
1098 target
= GetUserH(argv
[1]);
1100 reply("MSG_NICK_UNKNOWN", argv
[1]);
1103 if (IsService(target
)) {
1104 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1107 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1108 shun
= opserv_shun(target
, user
->handle_info
->handle
, reason
, 0);
1109 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1113 static MODCMD_FUNC(cmd_shun
)
1115 unsigned long duration
;
1119 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1120 if (!is_shun(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1121 reply("MSG_INVALID_SHUN", argv
[1]);
1124 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1125 reply("OSMSG_STUPID_SHUN", argv
[1]);
1128 duration
= ParseInterval(argv
[2]);
1130 reply("MSG_INVALID_DURATION", argv
[2]);
1133 shun
= shun_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
1134 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1138 static MODCMD_FUNC(cmd_unshun
)
1140 if (shun_remove(argv
[1], 1))
1141 reply("OSMSG_SHUN_REMOVED", argv
[1]);
1143 reply("OSMSG_SHUN_FORCE_REMOVED", argv
[1]);
1147 static MODCMD_FUNC(cmd_refreshs
)
1154 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1155 srv
= iter_data(it
);
1156 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1158 shun_refresh_server(srv
);
1159 reply("OSMSG_SHUNS_ONE_REFRESHED", srv
->name
);
1163 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1168 reply("OSMSG_SHUNS_REFRESHED");
1174 opserv_ison(struct userNode
*tell
, struct userNode
*target
, const char *message
)
1176 struct modeNode
*mn
;
1177 unsigned int count
, here_len
, n
, maxlen
;
1180 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
1182 maxlen
= MAX_LINE_SIZE
;
1183 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
1184 mn
= target
->channels
.list
[n
];
1185 here_len
= strlen(mn
->channel
->name
);
1186 if ((count
+ here_len
+ 4) > maxlen
) {
1188 send_message(tell
, opserv
, message
, buff
);
1191 if (mn
->modes
& MODE_CHANOP
)
1192 buff
[count
++] = '@';
1193 if (mn
->modes
& MODE_HALFOP
)
1194 buff
[count
++] = '%';
1195 if (mn
->modes
& MODE_VOICE
)
1196 buff
[count
++] = '+';
1197 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
1199 buff
[count
++] = ' ';
1203 send_message(tell
, opserv
, message
, buff
);
1207 static MODCMD_FUNC(cmd_inviteme
)
1209 struct userNode
*target
;
1214 target
= GetUserH(argv
[1]);
1216 reply("MSG_NICK_UNKNOWN", argv
[1]);
1220 if (opserv_conf
.debug_channel
== NULL
) {
1221 reply("OSMSG_NO_DEBUG_CHANNEL");
1224 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
1225 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1228 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1230 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1234 static MODCMD_FUNC(cmd_invite
)
1236 if (GetUserMode(channel
, user
)) {
1237 reply("OSMSG_ALREADY_THERE", channel
->name
);
1240 irc_invite(cmd
->parent
->bot
, user
, channel
);
1244 static MODCMD_FUNC(cmd_join
)
1246 struct userNode
*bot
= cmd
->parent
->bot
;
1248 if (!IsChannelName(argv
[1])) {
1249 reply("MSG_NOT_CHANNEL_NAME");
1251 } else if (!(channel
= GetChannel(argv
[1]))) {
1252 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1253 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1254 } else if (GetUserMode(channel
, bot
)) {
1255 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1258 struct mod_chanmode change
;
1259 mod_chanmode_init(&change
);
1261 change
.args
[0].mode
= MODE_CHANOP
;
1262 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1263 modcmd_chanmode_announce(&change
);
1265 irc_fetchtopic(bot
, channel
->name
);
1266 reply("OSMSG_JOIN_DONE", channel
->name
);
1270 static MODCMD_FUNC(cmd_kick
)
1272 struct userNode
*target
;
1276 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1277 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1279 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1281 target
= GetUserH(argv
[1]);
1283 reply("MSG_NICK_UNKNOWN", argv
[1]);
1286 if (!GetUserMode(channel
, target
)) {
1287 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1290 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1294 static MODCMD_FUNC(cmd_kickall
)
1296 unsigned int limit
, n
, inchan
;
1297 struct modeNode
*mn
;
1299 struct userNode
*bot
= cmd
->parent
->bot
;
1301 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1302 * channel, we have to join it in temporarily. */
1303 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1304 struct mod_chanmode change
;
1305 mod_chanmode_init(&change
);
1306 change
.args
[0].mode
= MODE_CHANOP
;
1307 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1308 modcmd_chanmode_announce(&change
);
1311 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1312 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1314 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1316 limit
= user
->handle_info
->opserv_level
;
1317 for (n
=channel
->members
.used
; n
>0;) {
1318 mn
= channel
->members
.list
[--n
];
1319 if (IsService(mn
->user
)
1320 || (mn
->user
->handle_info
1321 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1324 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1327 DelChannelUser(bot
, channel
, "My work here is done", 0);
1328 reply("OSMSG_KICKALL_DONE", channel
->name
);
1332 static MODCMD_FUNC(cmd_kickban
)
1334 struct mod_chanmode change
;
1335 struct userNode
*target
;
1340 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1341 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1343 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1345 target
= GetUserH(argv
[1]);
1347 reply("MSG_NICK_UNKNOWN", argv
[1]);
1350 if (!GetUserMode(channel
, target
)) {
1351 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1354 mod_chanmode_init(&change
);
1356 change
.args
[0].mode
= MODE_BAN
;
1357 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1358 modcmd_chanmode_announce(&change
);
1359 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1364 static MODCMD_FUNC(cmd_kickbanall
)
1366 struct modeNode
*mn
;
1367 struct userNode
*bot
= cmd
->parent
->bot
;
1368 struct mod_chanmode
*change
;
1370 unsigned int limit
, n
, inchan
;
1372 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1373 * channel, we have to join it in temporarily. */
1374 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1375 change
= mod_chanmode_alloc(2);
1376 change
->args
[0].mode
= MODE_CHANOP
;
1377 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1378 change
->args
[1].mode
= MODE_BAN
;
1379 change
->args
[1].u
.hostmask
= "*!*@*";
1381 change
= mod_chanmode_alloc(1);
1382 change
->args
[0].mode
= MODE_BAN
;
1383 change
->args
[0].u
.hostmask
= "*!*@*";
1385 modcmd_chanmode_announce(change
);
1386 mod_chanmode_free(change
);
1388 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1389 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1391 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1394 limit
= user
->handle_info
->opserv_level
;
1395 for (n
=channel
->members
.used
; n
>0; ) {
1396 mn
= channel
->members
.list
[--n
];
1397 if (IsService(mn
->user
)
1398 || (mn
->user
->handle_info
1399 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1402 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1405 DelChannelUser(bot
, channel
, "My work here is done", 0);
1406 reply("OSMSG_KICKALL_DONE", channel
->name
);
1410 static MODCMD_FUNC(cmd_part
)
1414 if (!IsChannelName(argv
[1])) {
1415 reply("MSG_NOT_CHANNEL_NAME");
1418 if ((channel
= GetChannel(argv
[1]))) {
1419 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1420 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1423 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1424 reply("OSMSG_LEAVING", channel
->name
);
1425 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1430 static MODCMD_FUNC(cmd_mode
)
1432 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1433 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1436 reply("OSMSG_MODE_SET", channel
->name
);
1440 static MODCMD_FUNC(cmd_op
)
1442 struct mod_chanmode
*change
;
1443 unsigned int arg
, count
;
1445 change
= mod_chanmode_alloc(argc
-1);
1446 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1447 struct userNode
*victim
;
1448 struct modeNode
*mn
;
1449 if (!(victim
= GetUserH(argv
[arg
])))
1451 if (!(mn
= GetUserMode(channel
, victim
)))
1453 if (mn
->modes
& MODE_CHANOP
)
1455 change
->args
[count
].mode
= MODE_CHANOP
;
1456 change
->args
[count
++].u
.member
= mn
;
1459 change
->argc
= count
;
1460 modcmd_chanmode_announce(change
);
1462 mod_chanmode_free(change
);
1463 reply("OSMSG_OP_DONE");
1467 static MODCMD_FUNC(cmd_hop
)
1469 struct mod_chanmode
*change
;
1470 unsigned int arg
, count
;
1472 change
= mod_chanmode_alloc(argc
-1);
1473 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1474 struct userNode
*victim
;
1475 struct modeNode
*mn
;
1476 if (!(victim
= GetUserH(argv
[arg
])))
1478 if (!(mn
= GetUserMode(channel
, victim
)))
1480 if (mn
->modes
& MODE_HALFOP
)
1482 change
->args
[count
].mode
= MODE_HALFOP
;
1483 change
->args
[count
++].u
.member
= mn
;
1486 change
->argc
= count
;
1487 modcmd_chanmode_announce(change
);
1489 mod_chanmode_free(change
);
1490 reply("OSMSG_HOP_DONE");
1494 static MODCMD_FUNC(cmd_opall
)
1496 struct mod_chanmode
*change
;
1497 unsigned int ii
, count
;
1499 change
= mod_chanmode_alloc(channel
->members
.used
);
1500 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1501 struct modeNode
*mn
= channel
->members
.list
[ii
];
1502 if (mn
->modes
& MODE_CHANOP
)
1504 change
->args
[count
].mode
= MODE_CHANOP
;
1505 change
->args
[count
++].u
.member
= mn
;
1508 change
->argc
= count
;
1509 modcmd_chanmode_announce(change
);
1511 mod_chanmode_free(change
);
1512 reply("OSMSG_OPALL_DONE", channel
->name
);
1516 static MODCMD_FUNC(cmd_hopall
)
1518 struct mod_chanmode
*change
;
1519 unsigned int ii
, count
;
1521 change
= mod_chanmode_alloc(channel
->members
.used
);
1522 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1523 struct modeNode
*mn
= channel
->members
.list
[ii
];
1524 if (mn
->modes
& MODE_HALFOP
)
1526 change
->args
[count
].mode
= MODE_HALFOP
;
1527 change
->args
[count
++].u
.member
= mn
;
1530 change
->argc
= count
;
1531 modcmd_chanmode_announce(change
);
1533 mod_chanmode_free(change
);
1534 reply("OSMSG_HOPALL_DONE", channel
->name
);
1538 static MODCMD_FUNC(cmd_whois
)
1540 struct userNode
*target
;
1544 #ifdef WITH_PROTOCOL_P10
1545 if (argv
[1][0] == '*')
1546 target
= GetUserN(argv
[1]+1);
1549 target
= GetUserH(argv
[1]);
1551 reply("MSG_NICK_UNKNOWN", argv
[1]);
1554 reply("OSMSG_WHOIS_NICK", target
->nick
);
1555 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
1556 if (IsFakeHost(target
))
1557 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
1558 reply("OSMSG_WHOIS_CRYPT_HOST", target
->crypthost
);
1559 reply("OSMSG_WHOIS_CRYPT_IP", target
->cryptip
);
1560 reply("OSMSG_WHOIS_IP", irc_ntoa(&target
->ip
));
1561 if (target
->modes
) {
1563 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
1564 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
1565 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
1566 if (IsOper(target
)) buffer
[bpos
++] = 'o';
1567 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
1568 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
1570 // sethost - reed/apples
1571 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
1572 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
1574 if (IsService(target
)) buffer
[bpos
++] = 'k';
1575 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
1576 if (target
->handle_info
) buffer
[bpos
++] = 'r';
1577 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
1578 if (IsGagged(target
)) buffer_cat(" (gagged)");
1579 if (IsRegistering(target
)) buffer_cat(" (registered account)");
1582 reply("OSMSG_WHOIS_MODES", buffer
);
1584 reply("OSMSG_WHOIS_INFO", target
->info
);
1585 #ifdef WITH_PROTOCOL_P10
1586 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
1588 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
1589 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
1590 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
1591 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
1592 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
1593 opserv_ison(user
, target
, "OSMSG_WHOIS_CHANNELS");
1595 reply("OSMSG_WHOIS_HIDECHANS");
1599 static MODCMD_FUNC(cmd_unban
)
1601 struct mod_chanmode change
;
1602 mod_chanmode_init(&change
);
1604 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
1605 change
.args
[0].u
.hostmask
= argv
[1];
1606 modcmd_chanmode_announce(&change
);
1607 reply("OSMSG_UNBAN_DONE", channel
->name
);
1611 static MODCMD_FUNC(cmd_voiceall
)
1613 struct mod_chanmode
*change
;
1614 unsigned int ii
, count
;
1616 change
= mod_chanmode_alloc(channel
->members
.used
);
1617 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1618 struct modeNode
*mn
= channel
->members
.list
[ii
];
1619 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
1621 change
->args
[count
].mode
= MODE_VOICE
;
1622 change
->args
[count
++].u
.member
= mn
;
1625 change
->argc
= count
;
1626 modcmd_chanmode_announce(change
);
1628 mod_chanmode_free(change
);
1629 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
1633 static MODCMD_FUNC(cmd_devoiceall
)
1635 struct mod_chanmode
*change
;
1636 unsigned int ii
, count
;
1638 change
= mod_chanmode_alloc(channel
->members
.used
);
1639 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1640 struct modeNode
*mn
= channel
->members
.list
[ii
];
1641 if (!(mn
->modes
& MODE_VOICE
))
1643 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
1644 change
->args
[count
++].u
.member
= mn
;
1647 change
->argc
= count
;
1648 modcmd_chanmode_announce(change
);
1650 mod_chanmode_free(change
);
1651 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
1655 static MODCMD_FUNC(cmd_stats_bad
) {
1657 unsigned int ii
, end
, here_len
;
1660 /* Show the bad word list.. */
1661 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
1662 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
1663 here_len
= strlen(opserv_bad_words
->list
[ii
]);
1664 /* If the line is full output it & start again */
1665 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1667 reply("OSMSG_BADWORD_LIST", buffer
);
1670 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
1672 buffer
[end
++] = ' ';
1675 reply("OSMSG_BADWORD_LIST", buffer
);
1677 /* Show the exemption list.. */
1678 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
1679 here_len
= strlen(iter_key(it
));
1680 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1682 reply("OSMSG_EXEMPTED_LIST", buffer
);
1685 memcpy(buffer
+end
, iter_key(it
), here_len
);
1687 buffer
[end
++] = ' ';
1690 reply("OSMSG_EXEMPTED_LIST", buffer
);
1694 static MODCMD_FUNC(cmd_stats_glines
) {
1695 reply("OSMSG_GLINE_COUNT", gline_count());
1699 static MODCMD_FUNC(cmd_stats_shuns
) {
1700 reply("OSMSG_SHUN_COUNT", shun_count());
1705 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
1706 unsigned int nn
, pos
;
1709 for (nn
=1; nn
<=depth
; nn
<<=1) ;
1710 for (pos
=0, nn
>>=1; nn
>1; ) {
1712 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
1713 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
1716 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
1717 if (!server
->children
.used
)
1719 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
1720 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
1722 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
1725 static MODCMD_FUNC(cmd_stats_links
) {
1726 trace_links(cmd
->parent
->bot
, user
, self
, 1);
1731 static MODCMD_FUNC(cmd_stats_max
) {
1732 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
1736 static MODCMD_FUNC(cmd_stats_network
) {
1737 struct helpfile_table tbl
;
1738 unsigned int nn
, tot_clients
;
1741 tot_clients
= dict_size(clients
);
1742 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
1743 tbl
.length
= dict_size(servers
)+1;
1745 tbl
.flags
= TABLE_NO_FREE
;
1746 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1747 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1748 tbl
.contents
[0][0] = "Server Name";
1749 tbl
.contents
[0][1] = "Clients";
1750 tbl
.contents
[0][2] = "Load";
1751 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1752 struct server
*server
= iter_data(it
);
1753 char *buffer
= malloc(32);
1754 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1755 tbl
.contents
[nn
][0] = server
->name
;
1756 tbl
.contents
[nn
][1] = buffer
;
1757 sprintf(buffer
, "%u", server
->clients
);
1758 tbl
.contents
[nn
][2] = buffer
+ 16;
1759 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
1762 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1763 for (nn
=1; nn
<tbl
.length
; nn
++) {
1764 free((char*)tbl
.contents
[nn
][1]);
1765 free(tbl
.contents
[nn
]);
1767 free(tbl
.contents
[0]);
1772 static MODCMD_FUNC(cmd_stats_network2
) {
1773 struct helpfile_table tbl
;
1777 tbl
.length
= dict_size(servers
)+1;
1779 tbl
.flags
= TABLE_NO_FREE
;
1780 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1781 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1782 tbl
.contents
[0][0] = "Server Name";
1783 tbl
.contents
[0][1] = "Numeric";
1784 tbl
.contents
[0][2] = "Link Time";
1785 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1786 struct server
*server
= iter_data(it
);
1787 char *buffer
= malloc(64);
1790 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1791 tbl
.contents
[nn
][0] = server
->name
;
1792 #ifdef WITH_PROTOCOL_P10
1793 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
1797 tbl
.contents
[nn
][1] = buffer
;
1798 ofs
= strlen(buffer
) + 1;
1799 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
1800 if (server
->self_burst
)
1801 strcat(buffer
+ ofs
, " Bursting");
1802 tbl
.contents
[nn
][2] = buffer
+ ofs
;
1805 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1806 for (nn
=1; nn
<tbl
.length
; nn
++) {
1807 free((char*)tbl
.contents
[nn
][1]);
1808 free(tbl
.contents
[nn
]);
1810 free(tbl
.contents
[0]);
1815 static MODCMD_FUNC(cmd_stats_reserved
) {
1818 reply("OSMSG_RESERVED_LIST");
1819 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
1820 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
1824 static MODCMD_FUNC(cmd_stats_trusted
) {
1826 struct trusted_host
*th
;
1827 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
1829 reply("OSMSG_TRUSTED_LIST");
1830 reply("OSMSG_TRUSTED_LIST_BAR");
1831 reply("OSMSG_TRUSTED_LIST_HEADER");
1832 reply("OSMSG_TRUSTED_LIST_BAR");
1834 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
1837 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
1839 intervalString(length
, th
->expires
- now
, user
->handle_info
);
1841 sprintf(limit
, "%lu", th
->limit
);
1842 reply("OSMSG_HOST_IS_TRUSTED",
1844 (th
->limit
? limit
: "none"),
1845 (th
->issuer
? th
->issuer
: "<unknown>"),
1846 (th
->issued
? issued
: "some time"),
1847 (th
->expires
? length
: "never"));
1848 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
1850 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
1853 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
1856 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
1858 intervalString(length
, th
->expires
- now
, user
->handle_info
);
1860 sprintf(limit
, "%lu", th
->limit
);
1861 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
1862 (th
->limit
? limit
: "none"),
1863 (th
->issuer
? th
->issuer
: "<unknown>"),
1864 (th
->issued
? issued
: "some time"),
1865 (th
->expires
? length
: "never"));
1866 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
1869 reply("OSMSG_TRUSTED_LIST_END");
1873 static MODCMD_FUNC(cmd_stats_uplink
) {
1874 extern struct cManagerNode cManager
;
1875 struct uplinkNode
*uplink
;
1877 uplink
= cManager
.uplink
;
1878 reply("OSMSG_UPLINK_START", uplink
->name
);
1879 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
1883 static MODCMD_FUNC(cmd_stats_uptime
) {
1884 char uptime
[INTERVALLEN
];
1886 extern time_t boot_time
;
1887 extern int lines_processed
;
1888 static long clocks_per_sec
;
1890 if (!clocks_per_sec
) {
1891 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
1892 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
1893 if (clocks_per_sec
<= 0)
1896 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
1897 clocks_per_sec
= CLOCKS_PER_SEC
;
1900 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
1902 reply("OSMSG_UPTIME_STATS",
1903 uptime
, lines_processed
,
1904 buf
.tms_utime
/(double)clocks_per_sec
,
1905 buf
.tms_stime
/(double)clocks_per_sec
);
1909 static MODCMD_FUNC(cmd_stats_alerts
) {
1911 struct opserv_user_alert
*alert
;
1912 const char *reaction
;
1914 reply("OSMSG_ALERTS_LIST");
1915 reply("OSMSG_ALERTS_BAR");
1916 reply("OSMSG_ALERTS_HEADER");
1917 reply("OSMSG_ALERTS_BAR");
1918 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
1919 alert
= iter_data(it
);
1920 switch (alert
->reaction
) {
1921 case REACT_NOTICE
: reaction
= "notice"; break;
1922 case REACT_KILL
: reaction
= "kill"; break;
1923 // case REACT_SILENT: reaction = "silent"; break;
1924 case REACT_GLINE
: reaction
= "gline"; break;
1925 case REACT_TRACK
: reaction
= "track"; break;
1926 case REACT_SHUN
: reaction
= "shun"; break;
1927 default: reaction
= "<unknown>"; break;
1929 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
1930 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
1932 reply("OSMSG_ALERT_END");
1936 static MODCMD_FUNC(cmd_stats_gags
) {
1937 struct gag_entry
*gag
;
1938 struct helpfile_table table
;
1942 reply("OSMSG_NO_GAGS");
1945 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
1946 table
.length
= nn
+1;
1948 table
.flags
= TABLE_NO_FREE
;
1949 table
.contents
= calloc(table
.length
, sizeof(char**));
1950 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1951 table
.contents
[0][0] = "Mask";
1952 table
.contents
[0][1] = "Owner";
1953 table
.contents
[0][2] = "Expires";
1954 table
.contents
[0][3] = "Reason";
1955 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
1956 char expstr
[INTERVALLEN
];
1958 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
1960 strcpy(expstr
, "Never");
1961 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
1962 table
.contents
[nn
][0] = gag
->mask
;
1963 table
.contents
[nn
][1] = gag
->owner
;
1964 table
.contents
[nn
][2] = strdup(expstr
);
1965 table
.contents
[nn
][3] = gag
->reason
;
1967 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
1968 for (nn
=1; nn
<table
.length
; nn
++) {
1969 free((char*)table
.contents
[nn
][2]);
1970 free(table
.contents
[nn
]);
1972 free(table
.contents
[0]);
1973 free(table
.contents
);
1977 static MODCMD_FUNC(cmd_stats_timeq
) {
1978 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
1983 static MODCMD_FUNC(cmd_stats_warn) {
1986 reply("OSMSG_WARN_LISTSTART");
1987 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
1988 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
1989 reply("OSMSG_WARN_LISTEND");
1994 #if defined(WITH_MALLOC_X3)
1995 static MODCMD_FUNC(cmd_stats_memory
) {
1996 extern unsigned long alloc_count
, alloc_size
;
1997 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
1998 "%u allocations totalling %u bytes.",
1999 alloc_count
, alloc_size
);
2002 #elif defined(WITH_MALLOC_SLAB)
2003 static MODCMD_FUNC(cmd_stats_memory
) {
2004 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
2005 extern unsigned long big_alloc_count
, big_alloc_size
;
2006 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2007 "%u allocations in %u slabs totalling %u bytes.",
2008 slab_alloc_count
, slab_count
, slab_alloc_size
);
2009 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2010 "%u big allocations totalling %u bytes.",
2011 big_alloc_count
, big_alloc_size
);
2016 static MODCMD_FUNC(cmd_dump
)
2018 char linedup
[MAXLEN
], original
[MAXLEN
];
2020 unsplit_string(argv
+1, argc
-1, original
);
2021 safestrncpy(linedup
, original
, sizeof(linedup
));
2022 /* assume it's only valid IRC if we can parse it */
2023 if (parse_line(linedup
, 1)) {
2025 reply("OSMSG_LINE_DUMPED");
2027 reply("OSMSG_RAW_PARSE_ERROR");
2031 static MODCMD_FUNC(cmd_raw
)
2033 char linedup
[MAXLEN
], original
[MAXLEN
];
2035 unsplit_string(argv
+1, argc
-1, original
);
2036 safestrncpy(linedup
, original
, sizeof(linedup
));
2037 /* Try to parse the line before sending it; if it's too wrong,
2038 * maybe it will core us instead of our uplink. */
2039 parse_line(linedup
, 1);
2041 reply("OSMSG_LINE_DUMPED");
2045 static struct userNode
*
2046 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
2048 struct userNode
*resv
= GetUserH(nick
);
2050 if (IsService(resv
)) {
2051 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
2054 if (resv
->handle_info
2055 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
2056 reply("OSMSG_LEVEL_TOO_LOW");
2060 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
2061 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
2066 static MODCMD_FUNC(cmd_collide
)
2068 struct userNode
*resv
;
2070 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2072 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
2075 reply("OSMSG_CLONE_FAILED", argv
[1]);
2080 static MODCMD_FUNC(cmd_reserve
)
2082 struct userNode
*resv
;
2084 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2086 resv
->modes
|= FLAGS_PERSISTENT
;
2087 reply("OSMSG_RESERVED_NICK", resv
->nick
);
2090 reply("OSMSG_CLONE_FAILED", argv
[1]);
2096 free_reserve(char *nick
)
2098 struct userNode
*resv
;
2102 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
2106 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
2107 reason
= alloca(rlen
);
2108 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
2109 DelUser(resv
, NULL
, 1, reason
);
2110 dict_remove(opserv_reserved_nick_dict
, nick
);
2114 static MODCMD_FUNC(cmd_unreserve
)
2116 if (free_reserve(argv
[1]))
2117 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
2119 reply("OSMSG_NOT_RESERVED", argv
[1]);
2124 opserv_part_channel(void *data
)
2126 DelChannelUser(opserv
, data
, "Leaving.", 0);
2129 static int alert_check_user(const char *key
, void *data
, void *extra
);
2132 opserv_new_user_check(struct userNode
*user
)
2134 struct opserv_hostinfo
*ohi
;
2135 struct gag_entry
*gag
;
2136 char addr
[IRC_NTOP_MAX_SIZE
];
2138 /* Check to see if we should ignore them entirely. */
2139 if (IsLocal(user
) || IsService(user
))
2142 /* Check for alerts, and stop if we find one that kills them. */
2143 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
2146 /* Gag them if appropriate. */
2147 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2148 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
2149 gag_helper_func(user
, NULL
);
2154 /* Add to host info struct */
2155 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2156 if (!(ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2157 ohi
= calloc(1, sizeof(*ohi
));
2158 dict_insert(opserv_hostinfo_dict
, strdup(addr
), ohi
);
2159 userList_init(&ohi
->clients
);
2161 userList_append(&ohi
->clients
, user
);
2163 /* Only warn of new user floods outside of bursts. */
2164 if (!user
->uplink
->burst
) {
2165 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
2166 if (!new_user_flood
) {
2168 opserv_alert("Warning: Possible new-user flood.");
2175 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
2176 if (opserv_conf
.untrusted_max
2177 && irc_in_addr_is_valid(user
->ip
)
2178 && !irc_in_addr_is_loopback(user
->ip
)) {
2179 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, addr
, NULL
);
2180 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
2182 /* 0 means unlimited hosts */
2183 } else if (ohi
->clients
.used
== limit
) {
2185 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
2186 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
2187 } else if (ohi
->clients
.used
> limit
) {
2188 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2189 strcpy(target
+ 2, addr
);
2190 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "Excessive connections from a single host.", now
, 1, 1);
2198 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
2200 struct opserv_hostinfo
*ohi
;
2201 char addr
[IRC_NTOP_MAX_SIZE
];
2203 if (IsLocal(user
)) {
2204 /* Try to remove it from the reserved nick dict without
2205 * calling free_reserve, because that would call DelUser(),
2206 * and we'd loop back to here. */
2207 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
2210 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2211 if ((ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2212 userList_remove(&ohi
->clients
, user
);
2213 if (ohi
->clients
.used
== 0)
2214 dict_remove(opserv_hostinfo_dict
, addr
);
2219 opserv_bad_channel(const char *name
)
2224 dict_find(opserv_exempt_channels
, name
, &present
);
2228 if (gline_find(name
))
2231 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
2232 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
2239 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
2241 struct mod_chanmode
*change
;
2244 change
= mod_chanmode_alloc(2);
2245 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2246 change
->args
[0].mode
= MODE_CHANOP
;
2247 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2248 change
->args
[1].mode
= MODE_BAN
;
2249 change
->args
[1].u
.hostmask
= "*!*@*";
2250 mod_chanmode_announce(opserv
, channel
, change
);
2251 mod_chanmode_free(change
);
2252 for (nn
=channel
->members
.used
; nn
>0; ) {
2253 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2254 if (IsService(mNode
->user
))
2256 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2258 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2262 opserv_channel_check(struct chanNode
*newchan
)
2266 if (!newchan
->join_policer
.params
) {
2267 newchan
->join_policer
.last_req
= now
;
2268 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2271 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2272 char message[MAXLEN];
2273 snprintf(message, sizeof(message), "Channel activity warning for channel %s: %s", newchan->name, warning);
2274 global_message(MESSAGE_RECIPIENT_OPERS, message);
2278 /* Wait until the join check to shut channels down. */
2279 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2283 opserv_channel_delete(struct chanNode
*chan
)
2285 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2289 opserv_join_check(struct modeNode
*mNode
)
2291 struct userNode
*user
= mNode
->user
;
2292 struct chanNode
*channel
= mNode
->channel
;
2295 if (IsService(user
))
2298 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2300 if (channel
->bad_channel
) {
2301 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2302 if (channel
->name
[0] != '#')
2303 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2304 else if (!GetUserMode(channel
, opserv
))
2305 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2307 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2308 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2309 KickChannelUser(user
, channel
, opserv
, msg
);
2314 if (user
->uplink
->burst
)
2316 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2317 channel
->join_flooded
= 0;
2320 if (!channel
->join_flooded
) {
2321 /* Don't moderate the channel unless it is activated and
2322 the number of users in the channel is over the threshold. */
2323 struct mod_chanmode change
;
2324 mod_chanmode_init(&change
);
2325 channel
->join_flooded
= 1;
2326 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2327 if (!GetUserMode(channel
, opserv
)) {
2328 /* If we aren't in the channel, join it. */
2329 change
.args
[0].mode
= MODE_CHANOP
;
2330 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2333 if (!(channel
->modes
& MODE_MODERATED
))
2334 change
.modes_set
|= MODE_MODERATED
;
2335 if (change
.modes_set
|| change
.argc
)
2336 mod_chanmode_announce(opserv
, channel
, &change
);
2337 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2338 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2340 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2343 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2348 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2349 unsigned int bad_idx
;
2351 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2352 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2353 if (irccasestr(new_bad
, orig_bad
)) {
2355 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2357 } else if (irccasestr(orig_bad
, new_bad
)) {
2359 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2361 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2362 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2363 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2364 if (!irccasestr(orig_bad
, new_bad
))
2367 reply("OSMSG_BAD_NUKING", orig_bad
);
2368 string_list_delete(opserv_bad_words
, bad_idx
);
2375 string_list_append(opserv_bad_words
, strdup(new_bad
));
2377 reply("OSMSG_ADDED_BAD", new_bad
);
2382 opserv_routing_plan_add_server(struct routingPlan
*rp
, const char *name
, const char *uplink
, const unsigned int port
, int karma
, const char *second
, const unsigned int offline
)
2384 struct routingPlanServer
*rps
;
2385 rps
= calloc(1, sizeof(*rps
));
2388 /* duplicate servers replace */
2389 rps
->uplink
= strdup(uplink
);
2391 rps
->secondaryuplink
= strdup(second
);
2393 rps
->secondaryuplink
= NULL
;
2394 rps
->port
= port
? port
: 4400; /* lame hardcodede default port. maybe get from config file somewhere? */
2396 rps
->offline
= offline
; /* 1 = yes, 0 = no */
2397 dict_insert(rp
->servers
, strdup(name
), rps
);
2398 log_module(OS_LOG
, LOG_DEBUG
, "Adding rp server %s with uplink %s", name
, uplink
);
2403 free_routing_plan_server(void *data
)
2405 struct routingPlanServer
*rps
= data
;
2407 if(rps
->secondaryuplink
)
2408 free(rps
->secondaryuplink
);
2413 opserv_add_routing_plan(const char *name
)
2415 struct routingPlan
*rp
;
2416 rp
= calloc(1, sizeof(*rp
));
2419 if(dict_find(opserv_routing_plans
, name
, NULL
))
2420 return NULL
; /* plan already exists */
2421 rp
->servers
= dict_new();
2422 dict_set_free_data(rp
->servers
, free_routing_plan_server
);
2424 dict_insert(opserv_routing_plans
, strdup(name
), rp
);
2425 /* TODO: check for duplicate */
2430 free_routing_plan(void *data
)
2432 struct routingPlan
*rp
= data
;
2433 /* delete all the servers attached to this plan */
2434 dict_delete(rp
->servers
);
2435 /* free the plan struct */
2439 /*************************************************
2440 * Functions to handle the active routing struct */
2443 *find_routeList_server(struct route
*route
, const char *server
)
2445 struct routeList
*rptr
;
2448 for(rptr
= route
->servers
;rptr
;rptr
=rptr
->next
) {
2449 if(!strcasecmp(rptr
->server
, server
))
2455 /* Wipes out the routing structure, freeing properly.
2456 * note: does NOT free itself, we just re-use it usually.*/
2458 wipe_route_list(struct route
*route
) {
2459 struct routeList
*nextptr
, *rptr
;
2462 for(rptr
= opserv_route
->servers
; rptr
; rptr
=nextptr
)
2464 nextptr
= rptr
->next
;
2468 if(rptr
->secondaryuplink
)
2469 free(rptr
->secondaryuplink
);
2472 route
->centered
= true;
2474 route
->maxdepth
= 0;
2475 route
->servers
= NULL
;
2480 rank_outside_rec(struct route
*route
, char *server
, int count
)
2482 struct routeList
*rptr
;
2485 if(count
> 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */
2488 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
2490 if(!strcasecmp(server
, rptr
->uplink
)) {
2491 log_module(MAIN_LOG
, LOG_DEBUG
, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count
, i
, rptr
->server
, rptr
->uplink
);
2492 n
= rank_outside_rec(route
, rptr
->server
, count
+1);
2493 if(n
< 0) /* handle error condition */
2499 if((rptr
= find_routeList_server(route
, server
))) {
2500 rptr
->outsideness
= max
;
2504 log_module(MAIN_LOG
, LOG_ERROR
, "routing struct rank_outsideness() couldnt find %s", server
);
2510 rank_outsideness(struct route
*route
)
2512 log_module(MAIN_LOG
, LOG_DEBUG
, "rank_outsideness(): Running...");
2513 route
->maxdepth
= rank_outside_rec(route
, self
->uplink
->name
, 0) - 1;
2514 if(route
->maxdepth
< 0) { /* if the rank failed, remove route */
2515 log_module(MAIN_LOG
, LOG_WARNING
, "The active routing plan has a loop! auto routing disabled.");
2516 wipe_route_list(route
);
2523 /* Add servers to the routing structure */
2525 add_routestruct_server(struct route
*route
, const char *server
, unsigned int port
, char *uplink
, char *secondary
)
2527 struct routeList
*rptr
;
2529 if(find_routeList_server(route
, server
))
2531 log_module(MAIN_LOG
, LOG_WARNING
, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server
);
2534 rptr
= calloc(1, sizeof(*rptr
));
2535 rptr
->server
= strdup(server
);
2538 hname
= conf_get_data("server/hostname", RECDB_QSTRING
);
2541 rptr
->uplink
= strdup(uplink
);
2543 rptr
->secondaryuplink
= strdup(secondary
);
2544 /* tack this server on the front of the list */
2545 rptr
->next
= route
->servers
;
2546 route
->servers
= rptr
;
2549 #ifdef notdef /* I dont quite get this. there could be uncentered things
2550 * added after our own uplink, and this function doesnt center
2551 * as it adds. -Rubin */
2552 /* If the map hasnt been centered yet... */
2553 if(route
->centered
== false) {
2554 /* AND we just added our own uplink to it... */
2555 if(!strcasecmp(server
, self
->uplink
->name
)) {
2556 change_route_uplinks(route
); /* recenter it, n mark it centered. */
2562 /* Recenter the routing struct around our current uplink */
2564 change_route_uplinks(struct route
*route
)
2566 struct routeList
*rptr
;
2567 char lastserver
[MAXLEN
];
2568 char nextserver
[MAXLEN
];
2571 return false; /* no map to recenter */
2572 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks(): running...");
2573 char *servicename
= conf_get_data("server/hostname", RECDB_QSTRING
);
2574 strcpy(lastserver
, servicename
);
2575 rptr
= find_routeList_server(route
, self
->uplink
->name
);
2577 log_module(MAIN_LOG
, LOG_ERROR
, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered.");
2578 route
->centered
= false;
2581 if(!strcasecmp(rptr
->uplink
, servicename
)) {
2582 log_module(MAIN_LOG
, LOG_DEBUG
, "Already centered");
2584 else { /* else, center it */
2586 strcpy(nextserver
, rptr
->uplink
);
2587 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks() changing %s uplink to %s.", rptr
->server
, lastserver
);
2589 rptr
->uplink
= strdup(lastserver
);
2590 strcpy(lastserver
, rptr
->server
);
2591 rptr
= find_routeList_server(route
, nextserver
);
2594 if(rank_outsideness(route
) > 0) {
2595 route
->centered
= true;
2603 activate_routing(struct svccmd
*cmd
, struct userNode
*user
, char *plan_name
)
2605 static struct routingPlan
*rp
;
2609 if(plan_name
) { /* make this the new active plan */
2610 if(!strcmp(plan_name
, "*")) {
2611 /* disable routing */
2612 dict_remove(opserv_routing_plan_options
, "ACTIVE");
2616 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
2619 reply("OSMSG_PLAN_NOT_FOUND", plan_name
);
2621 /* since it doesnt exist, remove the active setting */
2622 dict_remove(opserv_routing_plan_options
, plan_name
);
2624 log_module(MAIN_LOG
, LOG_ERROR
, "activate_routing() couldnt find active routing plan!");
2629 else { /* find the active plan in settings */
2630 plan_name
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
2632 if(!plan_name
) { /* deactivated, or no plan was set active */
2633 /* TODO: delete routing map if it exists */
2634 wipe_route_list(opserv_route
);
2638 karma
= dict_find(opserv_routing_plan_options
, "KARMA", NULL
);
2640 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
2642 /* this should really be done during opserv init */
2644 opserv_route
= calloc(1, sizeof(*opserv_route
));
2646 /* Delete the existing active route */
2647 wipe_route_list(opserv_route
);
2649 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
2650 const char* servername
= iter_key(it
);
2651 struct routingPlanServer
*rps
= iter_data(it
),
2652 *rp_uplink
, *rp_second
= NULL
;
2653 char *uplink
= rps
->uplink
;
2654 rp_uplink
= dict_find(rp
->servers
, rps
->uplink
, NULL
);
2655 if(rps
->secondaryuplink
)
2656 rp_second
= dict_find(rp
->servers
, rps
->secondaryuplink
, NULL
);
2658 /* If the normal uplink has bad karma, don't use it as a hub,
2659 * switch to the secondary uplink.
2661 if(karma
&& enabled_string(karma
) && rp_uplink
&& rp_uplink
->karma
< 0) {
2662 if(rps
->secondaryuplink
) {
2663 uplink
= rps
->secondaryuplink
;
2664 /* unless the secondary uplinks karma is worse than the uplink. */
2665 if((rp_second
= dict_find(rp
->servers
, uplink
, NULL
)) && rp_second
->karma
< rp_uplink
->karma
)
2666 uplink
= rps
->uplink
;
2670 * If _WE_ have bad karma, don't link us to our normal uplink, maybe
2671 * its a bad route. switch to secondary. Important: dont neg karma when we arnt on
2672 * our primary uplink, or we'll get stuck on secondary when THAT link is worse.
2674 if(karma
&& enabled_string(karma
) && (rps
->karma
< 0 || rps
->offline
) ) {
2675 if(rps
->secondaryuplink
) {
2676 uplink
= rps
->secondaryuplink
;
2679 log_module(MAIN_LOG
, LOG_DEBUG
, "activate_routing() adding %s:%d %s", servername
, rps
->port
, uplink
);
2680 add_routestruct_server(opserv_route
, servername
, rps
->port
, uplink
, NULL
);
2682 if(change_route_uplinks(opserv_route
))
2685 reply("OSMSG_ROUTING_ACTIVATION_ERROR");
2686 activate_routing(cmd
, user
, "*");
2692 /*******************************************************
2693 * Functions to handle online route configuration via opserv
2695 static void route_show_option(struct svccmd
*cmd
, struct userNode
*user
, char *name
)
2697 char *value
= dict_find(opserv_routing_plan_options
, name
, NULL
);
2699 if(!strcmp("RETRY_PERIOD", name
)) { /* Show as an interval */
2700 char buff
[INTERVALLEN
+1];
2701 reply("OSMSG_ROUTINGPLAN_OPTION", name
, intervalString(buff
, atoi(value
), user
->handle_info
));
2703 else if(!strcmp("ACTIVE", name
)) {
2704 if(opserv_route
&& opserv_route
->servers
)
2705 reply("OSMSG_ROUTINGPLAN_ACTIVE", value
);
2707 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
2710 reply("OSMSG_ROUTINGPLAN_OPTION", name
, value
);
2714 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
2718 static void route_show_options(struct svccmd
*cmd
, struct userNode
*user
)
2720 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
2722 for(i
= 0; options
[i
]; i
++) {
2723 route_show_option(cmd
, user
, options
[i
]);
2727 /* called from timeq */
2728 void routing_connect_timeout(void *data
)
2730 struct waitingConnection
*wc
= data
;
2731 struct server
*target
= GetServerH(wc
->target
);
2733 dict_remove(opserv_waiting_connections
, wc
->server
);
2734 return; /* server we wanted to connect new server to is gone, just give up */
2736 routing_handle_connect_failure(target
, wc
->server
, "Connection timed out");
2737 /* the following invalidates server variable! */
2738 dict_remove(opserv_waiting_connections
, wc
->server
);
2741 void routing_delete_connect_timer(char *server
)
2743 struct waitingConnection
*wc
= dict_find(opserv_waiting_connections
, server
, 0);
2745 timeq_del(0, routing_connect_timeout
, wc
, TIMEQ_IGNORE_WHEN
);
2746 dict_remove(opserv_waiting_connections
, server
);
2752 routing_connect_server(char *server
, int port
, struct server
*to
)
2754 struct waitingConnection
*wc
= calloc(sizeof(*wc
), 1);
2756 wc
->server
= strdup(server
);
2757 wc
->target
= strdup(to
->name
);
2758 dict_insert(opserv_waiting_connections
, strdup(server
), wc
);
2759 timeq_add(now
+ ROUTING_CONNECT_TIMEOUT
, routing_connect_timeout
, wc
);
2761 irc_connect(opserv
, server
, port
, to
);
2765 routing_connect_one(struct route
*route
, char *server
)
2767 struct routeList
*rptr
;
2768 struct server
*sptr
, *suptr
;
2769 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
2770 if(!strcasecmp(rptr
->server
, server
)) {
2771 /* this is the one, connect it */
2772 suptr
= GetServerH(rptr
->uplink
);
2773 sptr
= GetServerH(rptr
->server
);
2775 return 1; /* already linked */
2777 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
2778 return 1; /* attempted link */
2780 return 0; /* its uplink isnt here to link to */
2783 log_module(MAIN_LOG
, LOG_DEBUG
, "Tried to link %s but its not in the active routing struct!", server
);
2784 return 0; /* server wasnt found in active route struct. */
2787 int routing_connect_children(struct route
*route
, char *server
)
2789 struct routeList
*rptr
;
2790 struct server
*sptr
, *suptr
;
2791 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
2792 if(!strcasecmp(rptr
->uplink
, server
)) {
2793 /* this is the one, connect it */
2794 suptr
= GetServerH(rptr
->uplink
);
2795 sptr
= GetServerH(rptr
->server
);
2797 continue; /* already linked */
2799 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
2800 continue; /* attempted link */
2802 continue; /* its uplink isnt here to link to */
2805 return 1; /* server wasnt found in active route struct ?! */
2808 int reroute(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
, char *directive
)
2810 struct routeList
*rptr
;
2811 struct server
*sptr
, *suptr
;
2812 int connect
= 0, move
= 0, missing
= 0, i
;
2813 char d
= toupper(*directive
);
2815 if(!route
|| !route
->servers
) {
2816 reply("OSMSG_REROUTING_NOTCONFIGURED");
2820 if(d
== 'N') { /* normal */
2821 irc_wallops("%s", "Attempting a reroute of the network according to loaded map...");
2822 reply("OSMSG_REROUTING_ACC_MAP");
2824 else if(d
== 'C') { /* only connect */
2825 reply("OSMSG_CONNECTING_MISSING_ONLY");
2827 else if(d
== 'T') { /* test */
2828 reply("OSMSG_TESTING_REROUTE");
2832 reply("OSMSG_INVALID_DIRECTIVE", directive
);
2836 for(i
= 0; i
<= route
->maxdepth
-1; i
++) {
2837 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
2838 if(rptr
->outsideness
== i
) {
2841 reply("OSMSG_INSPECTING_SERVER", rptr
->server
);
2842 suptr
= GetServerH(rptr
->uplink
);
2844 if(rptr
->secondaryuplink
&& (suptr
= GetServerH(rptr
->secondaryuplink
))) {
2846 reply("OSMSG_COULDNT_FIND_SERVER", rptr
->uplink
, rptr
->secondaryuplink
, rptr
->server
);
2849 if(suptr
) { /* if the proper uplink is connected.. */
2850 sptr
= GetServerH(rptr
->server
);
2851 if(d
== 'C' && sptr
) {
2852 continue; /* Already linked */
2854 /* If server is missing or the uplinks are not the same then... */
2855 else if(!sptr
|| strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
2859 else { /* Server is already connected somewhere */
2860 if(strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
2861 if(d
!= 'T') { /* do it for real */
2862 irc_squit_route(sptr
, "%s issued reroute.", user
? user
->nick
: opserv
->nick
);
2864 else { /* just pretend */
2865 reply("OSMSG_SQUIT", rptr
->server
);
2870 if(d
!= 'T') /* do the real thing */
2871 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
2872 else /* just pretend */
2873 reply("OSMSG_CONNECT", rptr
->server
, rptr
->port
, suptr
->name
);
2877 log_module(MAIN_LOG
, LOG_DEBUG
, "server uplink %s was not found, cant connect %s", rptr
->uplink
, rptr
->server
);
2880 } /* outsideness = 1 */
2883 if(user
) { /* report on what we did */
2884 if(!strcasecmp(directive
, "C")) {
2886 reply("OSMSG_CONNECTING_MISSING", connect
);
2888 reply("OSMSG_NO_SERVERS_MISSING");
2891 if(move
+connect
> 0)
2892 reply("OSMSG_REROUTE_COMPLETE", move
, connect
, move
+connect
);
2894 reply("OSMSG_NO_ROUTING_NECESSARY");
2896 reply("OSMSG_UPLINKS_MISSING", missing
);
2899 return(move
+connect
);
2902 static MODCMD_FUNC(cmd_reroute
) {
2905 if(reroute(opserv_route
, user
, cmd
, upper
))
2911 /* reroute_timer(run)
2912 * run - if it is null, just setup the timer
2913 * but dont run reroute now. otherwise reroute
2916 void reroute_timer(void *data
) {
2917 if(!opserv_route
|| !opserv_route
->servers
)
2918 return; /* no active route */
2919 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
2921 return; /* retry_period invalid */
2922 unsigned int freq
= atoi(retry_period
);
2924 return; /* retry_period set to 0, disable */
2926 /* Do the reroute C attempt */
2928 reroute(opserv_route
, NULL
, NULL
, "C");
2930 /* Re-add ourselves to the timer queue */
2931 timeq_add(now
+ freq
, reroute_timer
, "run");
2934 void routing_change_karma(struct routingPlanServer
*rps
, const char *server
, int change
) {
2936 int oldkarma
= rps
->karma
;
2937 rps
->karma
+= change
;
2938 if(rps
->karma
< KARMA_MIN
)
2939 rps
->karma
= KARMA_MIN
;
2940 if(rps
->karma
> KARMA_MAX
)
2941 rps
->karma
= KARMA_MAX
;
2942 log_module(MAIN_LOG
, LOG_DEBUG
, "Changing %s karma by %d. new karma %d.", server
, change
, rps
->karma
);
2943 if(oldkarma
> 0 && rps
->karma
< 0) {
2944 /* we just crossed over to negitive */
2945 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went negitive karma!", server
);
2946 activate_routing(NULL
, NULL
, NULL
);
2948 else if(oldkarma
< 0 && rps
->karma
> 0) {
2949 /* we just crossed over to positive */
2950 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went back positive karma.", server
);
2951 activate_routing(NULL
, NULL
, NULL
);
2955 void routing_karma_timer(void *data
) {
2957 time_t timer_init
= data
? atoi(data
) : 0;
2960 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init
);
2962 /* If theres a time passed in, dont run unless that time is overdue. */
2963 if(!timer_init
|| (timer_init
< now
)) {
2964 if(opserv_route
&& opserv_route
->servers
) {
2965 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
2966 struct routingPlan
*rp
;
2967 if(active
&& (rp
= dict_find(opserv_routing_plans
, active
, NULL
))) {
2969 /* Walk through each server in the active routing plan.. */
2970 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
2971 struct routingPlanServer
*rps
= iter_data(it
);
2972 struct server
*server
= GetServerH(iter_key(it
));
2973 /* Give everyone +KARMA_ENTROPE just for nothing */
2974 routing_change_karma(rps
, iter_key(it
), KARMA_ENTROPE
);
2975 /* give an additonal +KARMA_RELIABLE to servers that
2976 * have been linked at least KARMA_TIMER seconds. */
2977 if(server
&& (server
->link
< (now
- KARMA_TIMER
) ) ) {
2978 routing_change_karma(rps
, iter_key(it
), KARMA_RELIABLE
);
2984 if(timer_init
> now
) /* loading a saved value */
2986 else /* no scheduled timer, or we missed it. start from now */
2987 next
= now
+ KARMA_TIMER
;
2988 /* Save when karma_timer should run again in case we restart before then */
2989 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next
);
2990 sprintf(buf
, "%u", (unsigned int) next
);
2991 dict_insert(opserv_routing_plan_options
, "KARMA_TIMER", strdup(buf
));
2992 /* add a timer to run this again .. */
2993 timeq_add(next
, routing_karma_timer
, NULL
);
2996 void routing_handle_neg_karma(char *server
, char *uplink
, int change
)
2998 /* if server's primary uplink is uplink, OR, uplink's primary uplink is server,
2999 * then whichever one, gets its karma changed. */
3000 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3001 struct routingPlan
*rp
;
3002 struct routingPlanServer
*rps
;
3005 if(!(rp
= dict_find(opserv_routing_plans
, active
, NULL
)))
3007 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3008 if(!strcasecmp(rps
->uplink
, uplink
)) {
3009 /* server's uplink is uplink */
3010 routing_change_karma(rps
, server
, change
);
3014 if((rps
= dict_find(rp
->servers
, uplink
, NULL
))) {
3015 if(!strcasecmp(rps
->uplink
, server
)) {
3016 /* uplink's uplink is server */
3017 routing_change_karma(rps
, uplink
, change
);
3024 routing_handle_squit(char *server
, char *uplink
, char *message
)
3026 log_module(MAIN_LOG
, LOG_DEBUG
, "Routing_handle_squit(%s, %s)", server
, message
);
3030 if(match_ircglob(message
, "Ping timeout")) {
3031 routing_handle_neg_karma(server
, uplink
, KARMA_PINGOUT
);
3032 /* if conn_pingout is true, try to reconnect it obaying karma rules. */
3034 val
= dict_find(opserv_routing_plan_options
, "CONN_PINGOUT", 0);
3035 if(val
&& enabled_string(val
))
3036 routing_connect_one(opserv_route
, server
);
3038 else if(match_ircglob(message
, "Read error:*")) {
3039 routing_handle_neg_karma(server
, uplink
, KARMA_READERROR
);
3040 /* if conn_readerror is true, try to reconnect it obaying karma rules. */
3041 val
= dict_find(opserv_routing_plan_options
, "CONN_READERROR", 0);
3042 if(val
&& enabled_string(val
))
3043 routing_connect_one(opserv_route
, server
);
3045 /* Else whats the message (an oper squit it?) dont interfere */
3049 routing_handle_connect(char *server
, char *uplink
)
3052 struct routingPlan
*rp
;
3053 struct routingPlanServer
*rps
;
3056 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect(%s, %s)", server
, uplink
);
3057 /* delete a pending connection timer, if any */
3058 routing_delete_connect_timer(server
);
3059 /* check if routing is active... */
3060 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3063 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3067 /* If its offline, mark it online again.. */
3068 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3069 if(rps
->offline
== true) {
3070 rps
->offline
= false;
3071 if(rps
->secondaryuplink
) {
3072 /* re-activate to move it back to its primary */
3073 activate_routing(NULL
, NULL
, NULL
);
3076 /* if there are any servers missing who have this server as uplink try to connect them. */
3077 routing_connect_children(opserv_route
, server
);
3079 /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */
3080 for (it
=dict_first(servers
); it
; it
=iter_next(it
)) {
3081 struct server
*sptr
= iter_data(it
);
3082 if(sptr
&& sptr
->uplink
&& !strcasecmp(server
, sptr
->uplink
->name
)) {
3083 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect calling self on %s's leaf %s", server
, sptr
->name
);
3084 routing_handle_connect(sptr
->name
, sptr
->uplink
->name
);
3089 /* Handle a failed attempt at connecting servers
3090 * - we should only get here regarding servers X3 attempted to link, other
3091 * opers link messages go to them not to us
3094 routing_handle_connect_failure(struct server
*source
, char *server
, char *message
)
3097 struct routingPlan
*rp
;
3098 struct routingPlanServer
*rps
;
3099 log_module(MAIN_LOG
, LOG_ERROR
, "Failed to connect %s to %s: %s", server
, source
->name
, message
);
3100 /* remove the waiting connection n timeq */
3101 routing_delete_connect_timer(server
);
3102 /* check if routing is active.. */
3103 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3106 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3110 if( ((rps
= dict_find(rp
->servers
, server
, NULL
)) && !strcasecmp(rps
->uplink
, source
->name
))) {
3111 /* failed to connect to its primary uplink */
3112 if(rps
->offline
== false) {
3113 rps
->offline
= true;
3114 if(rps
->secondaryuplink
) {
3115 /* re-activate routing so the secondary
3116 * becomes its uplink, and try again */
3117 activate_routing(NULL
, NULL
, NULL
);
3118 /* attempt to link it again. */
3119 routing_connect_one(opserv_route
, server
);
3120 /* TODO: reconnect any missing servers who
3121 * normally connect to server, using their backups.
3122 * Probably should just issue a reroute C here. */
3128 /* Delete any existing timers, and start the timer again
3129 * using the passed time for the first run.
3130 * - this is called during a retry_period change
3131 * before it has saved the new value. */
3132 void reroute_timer_reset(unsigned int time
)
3134 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
& TIMEQ_IGNORE_WHEN
);
3135 timeq_add(now
+ time
, reroute_timer
, "run");
3138 static MODCMD_FUNC(cmd_routing_set
)
3140 char *option
= argv
[1];
3141 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3144 route_show_options(cmd
, user
);
3147 char *found_option
= NULL
;
3148 for(i
= 0; options
[i
]; i
++) {
3149 if(!strcasecmp(options
[i
], option
))
3150 found_option
= options
[i
];
3153 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option
);
3157 char *value
= argv
[2];
3158 char buff
[MAXLEN
]; /* whats the max length of unsigned int as printf'd? */
3159 if(!strcmp(found_option
, "ACTIVE")) { /* must be an existing route. */
3160 if(disabled_string(value
) || false_string(value
)) {
3161 /* make none of the maps active */
3162 activate_routing(cmd
, user
, "*");
3163 reply("OSMSG_ROUTING_DISABLED");
3166 else if(!activate_routing(cmd
, user
, value
)) {
3167 /* neg reply handled in activate_routing */
3171 if(!strcmp(found_option
, "CONN_READERROR") || !strcmp(found_option
, "CONN_PINGOUT") ||
3172 !strcmp(found_option
, "KARMA") ) {
3173 if( enabled_string(value
)) {
3176 else if( disabled_string(value
) ) {
3180 reply("MSG_INVALID_BINARY", value
);
3184 if(!strcmp(found_option
, "RETRY_PERIOD")) {
3185 unsigned int duration
= ParseInterval(value
);
3186 sprintf(buff
, "%d", duration
);
3188 reroute_timer_reset(duration
);
3190 /* set the value here */
3191 dict_remove(opserv_routing_plan_options
, found_option
);
3192 dict_insert(opserv_routing_plan_options
, strdup(found_option
), strdup(value
));
3193 route_show_option(cmd
, user
, found_option
);
3196 /* show the current value */
3197 route_show_option(cmd
, user
, found_option
);
3203 static MODCMD_FUNC(cmd_stats_routing_plans
) {
3204 dict_iterator_t rpit
;
3206 struct routingPlan
*rp
;
3207 reply("OSMSG_ROUTINGPLAN_LIST");
3208 reply("OSMSG_ROUTINGPLAN_BAR");
3209 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3210 const char* name
= iter_key(rpit
);
3211 rp
= iter_data(rpit
);
3212 reply("OSMSG_ROUTINGPLAN_NAME", name
);
3213 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3214 const char* servername
= iter_key(it
);
3215 struct routingPlanServer
*rps
= iter_data(it
);
3216 reply("OSMSG_ROUTINGPLAN_SERVER", servername
, rps
->port
, rps
->uplink
, rps
->karma
, rps
->offline
? "offline" : "online", rps
->secondaryuplink
? rps
->secondaryuplink
: "None");
3220 reply("OSMSG_ROUTINGPLAN_END");
3221 route_show_options(cmd
, user
);
3226 static MODCMD_FUNC(cmd_routing_addplan
)
3230 /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */
3231 if(*name
&& !disabled_string(name
) && !false_string(name
)) {
3232 if(opserv_add_routing_plan(name
)) {
3233 reply("OSMSG_ADDPLAN_SUCCESS", name
);
3237 reply("OSMSG_ADDPLAN_FAILED", name
);
3243 reply("OSMSG_INVALID_PLAN");
3248 static MODCMD_FUNC(cmd_routing_delplan
)
3250 char *name
= argv
[1];
3251 if( dict_remove(opserv_routing_plans
, name
) ) {
3252 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3253 if(active
&& !strcasecmp(active
, name
)) {
3254 /* if this was the active plan, disable routing */
3255 activate_routing(cmd
, user
, "*");
3256 reply("OSMSG_ROUTING_DISABLED");
3258 reply("OSMSG_PLAN_DELETED");
3262 reply("OSMSG_PLAN_NOT_FOUND", name
);
3267 static MODCMD_FUNC(cmd_routing_addserver
)
3275 struct routingPlan
*rp
;
3278 server
= strdup(argv
[2]);
3279 server
= strtok(server
, ":");
3280 portstr
= strtok(NULL
, ":");
3282 port
= atoi(portstr
);
3284 char *str
= dict_find(opserv_routing_plan_options
, "DEFAULT_PORT", NULL
);
3286 port
= str
? atoi(str
) : 0;
3294 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3296 opserv_routing_plan_add_server(rp
, server
, uplink
, port
, KARMA_DEFAULT
, second
, 0);
3297 reply("OSMSG_PLAN_SERVER_ADDED", server
);
3298 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3299 /* re-activate routing with new info */
3300 activate_routing(cmd
, user
, NULL
);
3307 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3313 static MODCMD_FUNC(cmd_routing_delserver
)
3317 struct routingPlan
*rp
;
3320 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3321 if(dict_remove(rp
->servers
, server
)) {
3323 reply("OSMSG_PLAN_SERVER_DELETED");
3324 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3325 /* re-activate routing with new info */
3326 activate_routing(cmd
, user
, NULL
);
3332 reply("OSMSG_PLAN_SERVER_NOT_FOUND", server
);
3337 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3343 /*************************************************
3344 * Functions to deal with 'route map' command */
3346 /* Figures out how many downlinks there are for proper
3347 * drawing of the route map */
3349 num_route_downlinks(struct route
*route
, char *name
)
3351 struct routeList
*rptr
;
3353 rptr
= route
->servers
;
3355 if(!strcasecmp(rptr
->uplink
, name
))
3363 show_route_downlinks(struct svccmd
*cmd
, struct route
*route
, struct userNode
*user
, char *name
, char *prevpre
, char *arrowchar
, int reset
)
3365 struct routeList
*servPtr
;
3366 struct server
*sptr
;
3372 static int depth
= 0;
3377 nextpre
= malloc(MAXLEN
);
3378 strcpy(pre
, prevpre
);
3380 sptr
= GetServerH(name
);
3381 if((servPtr
= find_routeList_server(route
, name
))) {
3384 else if (!strcasecmp(sptr
->uplink
->name
, servPtr
->uplink
))
3386 else if(servPtr
->secondaryuplink
&& !strcasecmp(sptr
->name
, servPtr
->secondaryuplink
))
3390 reply("OSMSG_DOWNLINKS_FORMAT_A", pre
, arrowchar
, name
, status
);
3393 reply("OSMSG_DOWNLINKS_FORMAT_B", self
->name
);
3394 j
= num_route_downlinks(route
, name
);
3395 servPtr
= route
->servers
;
3397 if(!strcasecmp(servPtr
->uplink
, name
)) {
3398 strcpy(nextpre
, pre
);
3400 if(arrowchar
[0] == '`')
3401 strcat(nextpre
, " ");
3403 strcat(nextpre
, "| ");
3406 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "|", 0);
3409 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "`", 0);
3412 servPtr
= servPtr
->next
;
3418 show_route_map(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
)
3420 if(!route
|| !route
->servers
) {
3421 reply("OSMSG_ROUTELIST_EMPTY");
3425 char *serviceName
= conf_get_data("server/hostname", RECDB_QSTRING
);
3426 reply("OSMSG_ROUTELIST_AS_PLANNED");
3427 show_route_downlinks(cmd
, route
, user
, serviceName
, "", "`", 1);
3428 reply("OSMSG_MAP_CENTERED", route
->centered
? "is" : "is not", route
->maxdepth
);
3432 static MODCMD_FUNC(cmd_routing_map
)
3434 show_route_map(opserv_route
, user
, cmd
);
3441 /* End of auto routing functions *
3442 *********************************/
3444 static MODCMD_FUNC(cmd_addbad
)
3446 unsigned int arg
, count
;
3448 int bad_found
, exempt_found
;
3450 /* Create the bad word if it doesn't exist. */
3451 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
3453 /* Look for exception modifiers. */
3454 for (arg
=2; arg
<argc
; arg
++) {
3455 if (!irccasecmp(argv
[arg
], "except")) {
3456 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
3458 reply("MSG_MISSING_PARAMS", "except");
3461 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
3462 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
3463 if (!exempt_found
) {
3464 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
3468 reply("OSMSG_ADDED_EXEMPTIONS", count
);
3470 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
3471 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
3475 /* Scan for existing channels that match the new bad word. */
3477 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
3478 struct chanNode
*channel
= iter_data(it
);
3480 if (!opserv_bad_channel(channel
->name
))
3482 channel
->bad_channel
= 1;
3483 if (channel
->name
[0] == '#')
3484 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
3487 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
3488 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
3489 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
3498 static MODCMD_FUNC(cmd_delbad
)
3503 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
3504 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
3505 string_list_delete(opserv_bad_words
, nn
);
3506 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
3507 channel
= iter_data(it
);
3508 if (irccasestr(channel
->name
, argv
[1])
3509 && !opserv_bad_channel(channel
->name
)) {
3510 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
3511 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
3512 channel
->bad_channel
= 0;
3515 reply("OSMSG_REMOVED_BAD", argv
[1]);
3519 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
3523 static MODCMD_FUNC(cmd_addexempt
)
3525 const char *chanName
;
3527 if ((argc
> 1) && IsChannelName(argv
[1])) {
3530 reply("MSG_NOT_CHANNEL_NAME");
3534 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
3535 channel
= GetChannel(chanName
);
3537 if (channel
->bad_channel
) {
3538 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
3539 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
3541 channel
->bad_channel
= 0;
3543 reply("OSMSG_ADDED_EXEMPTION", chanName
);
3547 static MODCMD_FUNC(cmd_delexempt
)
3549 const char *chanName
;
3551 if ((argc
> 1) && IsChannelName(argv
[1])) {
3554 reply("MSG_NOT_CHANNEL_NAME");
3558 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
3559 reply("OSMSG_NOT_EXEMPT", chanName
);
3562 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
3567 opserv_expire_trusted_host(void *data
)
3569 struct trusted_host
*th
= data
;
3570 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
3574 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
3576 struct trusted_host
*th
;
3577 th
= calloc(1, sizeof(*th
));
3580 th
->ipaddr
= strdup(ipaddr
);
3581 th
->reason
= reason
? strdup(reason
) : NULL
;
3582 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
3583 th
->issued
= issued
;
3585 th
->expires
= expires
;
3586 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
3588 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
3592 free_trusted_host(void *data
)
3594 struct trusted_host
*th
= data
;
3601 static MODCMD_FUNC(cmd_addtrust
)
3603 unsigned long interval
;
3605 irc_in_addr_t tmpaddr
;
3608 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
3609 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
3613 if (!irc_pton(&tmpaddr
, NULL
, argv
[1])) {
3614 reply("OSMSG_BAD_IP", argv
[1]);
3618 count
= strtoul(argv
[2], &tmp
, 10);
3620 reply("OSMSG_BAD_NUMBER", argv
[2]);
3624 interval
= ParseInterval(argv
[3]);
3625 if (!interval
&& strcmp(argv
[3], "0")) {
3626 reply("MSG_INVALID_DURATION", argv
[3]);
3630 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
3631 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
3632 reply("OSMSG_ADDED_TRUSTED");
3636 static MODCMD_FUNC(cmd_edittrust
)
3638 unsigned long interval
;
3639 struct trusted_host
*th
;
3643 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
3645 reply("OSMSG_NOT_TRUSTED", argv
[1]);
3648 count
= strtoul(argv
[2], &tmp
, 10);
3649 if (!count
|| *tmp
) {
3650 reply("OSMSG_BAD_NUMBER", argv
[2]);
3653 interval
= ParseInterval(argv
[3]);
3654 if (!interval
&& strcmp(argv
[3], "0")) {
3655 reply("MSG_INVALID_DURATION", argv
[3]);
3658 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
3660 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
3663 th
->reason
= strdup(reason
);
3665 th
->issuer
= strdup(user
->handle_info
->handle
);
3669 th
->expires
= now
+ interval
;
3670 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
3673 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
3677 static MODCMD_FUNC(cmd_deltrust
)
3681 for (n
=1; n
<argc
; n
++) {
3682 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
3686 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
3687 dict_remove(opserv_trusted_hosts
, argv
[n
]);
3689 reply("OSMSG_REMOVED_TRUSTED");
3693 /* This doesn't use dict_t because it's a little simpler to open-code the
3694 * comparisons (and simpler arg-passing for the ADD subcommand).
3696 static MODCMD_FUNC(cmd_clone
)
3699 struct userNode
*clone
;
3701 clone
= GetUserH(argv
[2]);
3702 if (!irccasecmp(argv
[1], "ADD")) {
3704 char ident
[USERLEN
+1];
3707 reply("MSG_MISSING_PARAMS", argv
[1]);
3712 reply("OSMSG_CLONE_EXISTS", argv
[2]);
3715 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
3716 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
3717 if (argv
[3][i
] == '@') {
3721 ident
[i
] = argv
[3][i
];
3724 if (!argv
[3][i
] || (i
==USERLEN
)) {
3725 reply("OSMSG_NOT_A_HOSTMASK");
3728 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
3729 reply("OSMSG_CLONE_FAILED", argv
[2]);
3732 reply("OSMSG_CLONE_ADDED", clone
->nick
);
3736 reply("MSG_NICK_UNKNOWN", argv
[2]);
3739 if (clone
->uplink
!= self
|| IsService(clone
)) {
3740 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
3743 if (!irccasecmp(argv
[1], "REMOVE")) {
3746 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
3749 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
3750 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
3753 DelUser(clone
, NULL
, 1, reason
);
3754 reply("OSMSG_CLONE_REMOVED", argv
[2]);
3758 reply("MSG_MISSING_PARAMS", argv
[1]);
3762 channel
= GetChannel(argv
[3]);
3763 if (!irccasecmp(argv
[1], "JOIN")) {
3765 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
3766 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
3769 AddChannelUser(clone
, channel
);
3770 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
3773 if (!irccasecmp(argv
[1], "PART")) {
3775 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
3778 if (!GetUserMode(channel
, clone
)) {
3779 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
3782 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
3783 DelChannelUser(clone
, channel
, "Leaving.", 0);
3786 if (!irccasecmp(argv
[1], "OP")) {
3787 struct mod_chanmode change
;
3789 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
3792 mod_chanmode_init(&change
);
3794 change
.args
[0].mode
= MODE_CHANOP
;
3795 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
3796 if (!change
.args
[0].u
.member
) {
3797 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
3800 modcmd_chanmode_announce(&change
);
3801 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
3804 if (!irccasecmp(argv
[1], "HOP")) {
3805 struct mod_chanmode change
;
3807 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
3810 mod_chanmode_init(&change
);
3812 change
.args
[0].mode
= MODE_HALFOP
;
3813 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
3814 if (!change
.args
[0].u
.member
) {
3815 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
3818 modcmd_chanmode_announce(&change
);
3819 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
3823 reply("MSG_MISSING_PARAMS", argv
[1]);
3827 if (!irccasecmp(argv
[1], "SAY")) {
3828 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
3829 irc_privmsg(clone
, argv
[3], text
);
3830 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
3833 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
3837 static struct helpfile_expansion
3838 opserv_help_expand(const char *variable
)
3840 extern struct userNode
*message_source
;
3841 struct helpfile_expansion exp
;
3842 struct service
*service
;
3848 if (!(service
= service_find(message_source
->nick
))) {
3849 exp
.type
= HF_STRING
;
3850 exp
.value
.str
= NULL
;
3851 } else if (!irccasecmp(variable
, "index")) {
3852 exp
.type
= HF_TABLE
;
3853 exp
.value
.table
.length
= 1;
3854 exp
.value
.table
.width
= 2;
3855 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
3856 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
3857 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
3858 exp
.value
.table
.contents
[0][0] = "Command";
3859 exp
.value
.table
.contents
[0][1] = "Level";
3860 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
3861 cmd
= iter_data(it
);
3862 row
= exp
.value
.table
.length
++;
3863 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
3864 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
3865 level
= cmd
->min_opserv_level
;
3866 if (!level_strings
[level
]) {
3867 level_strings
[level
] = malloc(16);
3868 snprintf(level_strings
[level
], 16, "%3d", level
);
3870 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
3872 } else if (!strncasecmp(variable
, "level", 5)) {
3873 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
3874 exp
.type
= HF_STRING
;
3876 level
= cmd
->min_opserv_level
;
3877 exp
.value
.str
= malloc(16);
3878 snprintf(exp
.value
.str
, 16, "%3d", level
);
3880 exp
.value
.str
= NULL
;
3883 exp
.type
= HF_STRING
;
3884 exp
.value
.str
= NULL
;
3890 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
3892 char buf
[16], *flags
= NULL
;
3893 unsigned int iflags
= 0;
3894 sprintf(buf
, "%d", min_level
);
3896 case 1: flags
= "+acceptchan"; break;
3897 case 3: flags
= "+acceptpluschan"; /* fall through */
3898 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
3901 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
3903 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
3907 int add_reserved(const char *key
, void *data
, void *extra
)
3909 struct chanNode
*chan
;
3910 struct record_data
*rd
= data
;
3911 const char *ident
, *hostname
, *desc
;
3913 struct userNode
*reserve
;
3914 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
3916 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
3919 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
3921 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
3924 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
3926 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
3929 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
3930 reserve
->modes
|= FLAGS_PERSISTENT
;
3931 dict_insert(extra
, reserve
->nick
, reserve
);
3934 if (autojoin_channels
&& reserve
) {
3935 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
3936 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
3937 AddChannelUser(reserve
, chan
)->modes
|= MODE_VOICE
;
3945 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
3949 unsigned int matched
;
3951 if (!self
->uplink
) return 0;
3952 discrim
= calloc(1, sizeof(*discrim
));
3953 discrim
->limit
= dict_size(clients
);
3954 discrim
->max_level
= ~0;
3955 discrim
->max_ts
= now
;
3956 discrim
->max_channels
= INT_MAX
;
3957 discrim
->authed
= -1;
3958 discrim
->info_space
= -1;
3959 discrim
->intra_scmp
= 0;
3960 discrim
->intra_dcmp
= 0;
3961 discrim
->use_regex
= 0;
3962 discrim
->silent
= 0;
3963 dupmask
= strdup(hostmask
);
3964 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
3965 if (!irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, discrim
->mask_host
))
3966 discrim
->ip_mask_bits
= 0;
3967 matched
= opserv_discrim_search(discrim
, func
, extra
);
3969 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
3978 gag_free(struct gag_entry
*gag
)
3980 unsigned int ungagged
;
3982 /* Remove from gag list */
3983 if (gagList
== gag
) {
3984 gagList
= gag
->next
;
3986 struct gag_entry
*prev
;
3987 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
3988 prev
->next
= gag
->next
;
3991 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
3993 /* Deallocate storage */
4003 gag_expire(void *data
)
4009 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
4011 struct gag_entry
*gag
;
4013 /* Create gag and put it into linked list */
4014 gag
= calloc(1, sizeof(*gag
));
4015 gag
->mask
= strdup(mask
);
4016 gag
->owner
= strdup(owner
? owner
: "<unknown>");
4017 gag
->reason
= strdup(reason
? reason
: "<unknown>");
4018 gag
->expires
= expires
;
4020 timeq_add(gag
->expires
, gag_expire
, gag
);
4021 gag
->next
= gagList
;
4024 /* If we're linked, see if who the gag applies to */
4025 return foreach_matching_user(mask
, gag_helper_func
, gag
);
4029 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4031 struct record_data
*rd
= data
;
4032 char *owner
, *reason
, *expstr
;
4035 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
4036 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
4037 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
4038 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
4039 gag_create(key
, owner
, reason
, expires
);
4044 static struct opserv_user_alert
*
4045 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
)
4048 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
4049 struct opserv_user_alert
*alert
;
4052 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
4053 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
4056 alert
= malloc(sizeof(*alert
));
4057 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
4058 alert
->text_discrim
= strdup(text_discrim
);
4059 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
4060 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
4061 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
4062 if (!alert
->discrim
) {
4063 free(alert
->text_discrim
);
4068 alert
->split_discrim
= discrim_copy
;
4069 name_dup
= strdup(name
);
4070 if (!alert
->discrim
->reason
)
4071 alert
->discrim
->reason
= strdup(name
);
4072 alert
->reaction
= reaction
;
4073 dict_insert(opserv_user_alerts
, name_dup
, alert
);
4074 /* Stick the alert into the appropriate additional alert dict(s).
4075 * For channel alerts, we only use channels and min_channels;
4076 * max_channels would have to be checked on /part, which we do not
4077 * yet do, and which seems of questionable value.
4079 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
4080 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
4081 if (alert
->discrim
->mask_nick
)
4082 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
4088 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
4090 struct record_data *rd = data;
4091 char *reason = GET_RECORD_QSTRING(rd);
4093 * i hope this can't happen *
4095 reason = "No Reason";
4097 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
4104 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4107 const char *discrim
, *react
, *owner
;
4108 opserv_alert_reaction reaction
;
4109 struct opserv_user_alert
*alert
;
4111 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
4112 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
4115 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
4116 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
4117 if (!react
|| !irccasecmp(react
, "notice"))
4118 reaction
= REACT_NOTICE
;
4119 else if (!irccasecmp(react
, "kill"))
4120 reaction
= REACT_KILL
;
4122 else if (!irccasecmp(react, "silent"))
4123 reaction = REACT_SILENT;
4125 else if (!irccasecmp(react
, "gline"))
4126 reaction
= REACT_GLINE
;
4127 else if (!irccasecmp(react
, "track"))
4128 reaction
= REACT_TRACK
;
4129 else if (!irccasecmp(react
, "shun"))
4130 reaction
= REACT_SHUN
;
4132 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
4135 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
);
4137 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
4140 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
4142 alert
->owner
= strdup(owner
? owner
: "<unknown>");
4147 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
4149 struct record_data
*rd
= data
;
4150 const char *limit
, *str
, *reason
, *issuer
;
4151 time_t issued
, expires
;
4153 if (rd
->type
== RECDB_QSTRING
) {
4154 /* old style host by itself */
4155 limit
= GET_RECORD_QSTRING(rd
);
4160 } else if (rd
->type
== RECDB_OBJECT
) {
4161 dict_t obj
= GET_RECORD_OBJECT(rd
);
4162 /* new style structure */
4163 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
4164 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
4165 expires
= str
? ParseInterval(str
) : 0;
4166 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
4167 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
4168 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
4169 issued
= str
? ParseInterval(str
) : 0;
4173 if (expires
&& (expires
< now
))
4175 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
4180 add_routing_plan_server(const char *name
, void *data
, void *rp
)
4182 struct record_data
*rd
= data
;
4183 const char *uplink
, *portstr
, *karma
, *second
, *offline
;
4185 dict_t obj
= GET_RECORD_OBJECT(rd
);
4186 if(rd
->type
== RECDB_OBJECT
) {
4187 uplink
= database_get_data(obj
, KEY_UPLINK
, RECDB_QSTRING
);
4188 second
= database_get_data(obj
, KEY_SECOND
, RECDB_QSTRING
);
4189 portstr
= database_get_data(obj
, KEY_PORT
, RECDB_QSTRING
);
4190 karma
= database_get_data(obj
, KEY_KARMA
, RECDB_QSTRING
);
4191 offline
= database_get_data(obj
, KEY_OFFLINE
, RECDB_QSTRING
);
4192 /* create routing plan server named key, with uplink uplink. */
4193 opserv_routing_plan_add_server(rp
, name
, uplink
, portstr
? atoi(portstr
) : 0,
4194 karma
? atoi(karma
) : KARMA_DEFAULT
, second
,
4195 offline
? atoi(offline
) : 0);
4202 routing_plan_set_option(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4204 struct record_data
*rd
= data
;
4205 if(rd
->type
== RECDB_QSTRING
)
4207 char *value
= GET_RECORD_QSTRING(rd
);
4208 dict_insert(opserv_routing_plan_options
, strdup(name
), strdup(value
));
4214 add_routing_plan(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4216 struct record_data
*rd
= data
;
4217 struct routingPlan
*rp
;
4219 if(rd
->type
== RECDB_OBJECT
) {
4220 dict_t obj
= GET_RECORD_OBJECT(rd
);
4221 rp
= opserv_add_routing_plan(name
);
4222 dict_foreach(obj
, add_routing_plan_server
, rp
);
4228 opserv_saxdb_read(struct dict
*conf_db
)
4231 struct record_data
*rd
;
4235 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
4236 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
4237 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
4239 case RECDB_STRING_LIST
:
4240 /* Add words one by one just in case there are overlaps from an old DB. */
4241 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4242 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
4245 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
4246 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
4248 if (rd
->type
== RECDB_STRING_LIST
)
4249 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
4250 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4257 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
4258 && (rd
->type
== RECDB_STRING_LIST
)) {
4259 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4260 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4262 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
4264 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
4265 max_clients
= atoi(str
);
4266 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
4267 max_clients_time
= atoi(str
);
4269 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
4270 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
4271 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
4272 dict_foreach(object
, add_gag_helper
, NULL
);
4273 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
4274 dict_foreach(object
, add_user_alert
, NULL
);
4276 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
4277 dict_foreach(object, add_chan_warn, NULL);
4280 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN
, RECDB_OBJECT
)))
4281 dict_foreach(object
, add_routing_plan
, NULL
);
4283 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN_OPTIONS
, RECDB_OBJECT
)))
4284 dict_foreach(object
, routing_plan_set_option
, NULL
);
4290 opserv_saxdb_write(struct saxdb_context
*ctx
)
4292 struct string_list
*slist
;
4295 /* reserved nicks */
4296 if (dict_size(opserv_reserved_nick_dict
)) {
4297 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
4298 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
4299 struct userNode
*user
= iter_data(it
);
4300 if (!IsPersistent(user
)) continue;
4301 saxdb_start_record(ctx
, iter_key(it
), 0);
4302 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
4303 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
4304 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
4305 saxdb_end_record(ctx
);
4307 saxdb_end_record(ctx
);
4310 if (opserv_bad_words
->used
) {
4311 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
4313 /* routing plan options */
4314 if (dict_size(opserv_routing_plan_options
)) {
4315 saxdb_start_record(ctx
, KEY_ROUTINGPLAN_OPTIONS
, 1);
4316 for(it
= dict_first(opserv_routing_plan_options
); it
; it
= iter_next(it
)) {
4317 saxdb_write_string(ctx
, iter_key(it
), iter_data(it
));
4319 saxdb_end_record(ctx
);
4322 if (dict_size(opserv_routing_plans
)) {
4323 dict_iterator_t svrit
;
4324 struct routingPlan
*rp
;
4325 struct routingPlanServer
*rps
;
4326 saxdb_start_record(ctx
, KEY_ROUTINGPLAN
, 1);
4327 for (it
= dict_first(opserv_routing_plans
); it
; it
= iter_next(it
)) {
4329 saxdb_start_record(ctx
, iter_key(it
), 0);
4330 for(svrit
= dict_first(rp
->servers
); svrit
; svrit
= iter_next(svrit
)) {
4332 rps
= iter_data(svrit
);
4333 saxdb_start_record(ctx
, iter_key(svrit
), 0);
4334 saxdb_write_string(ctx
, KEY_UPLINK
, rps
->uplink
);
4335 if(rps
->secondaryuplink
)
4336 saxdb_write_string(ctx
, KEY_SECOND
, rps
->secondaryuplink
);
4337 sprintf(buf
, "%d", rps
->port
);
4338 saxdb_write_string(ctx
, KEY_PORT
, buf
);
4339 sprintf(buf
, "%d", rps
->karma
);
4340 saxdb_write_string(ctx
, KEY_KARMA
, buf
);
4341 sprintf(buf
, "%d", rps
->offline
);
4342 saxdb_write_string(ctx
, KEY_OFFLINE
, buf
);
4343 saxdb_end_record(ctx
);
4345 saxdb_end_record(ctx
);
4347 saxdb_end_record(ctx
);
4349 /* insert exempt channel names */
4350 if (dict_size(opserv_exempt_channels
)) {
4351 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
4352 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
4353 string_list_append(slist
, strdup(iter_key(it
)));
4355 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
4356 free_string_list(slist
);
4358 /* trusted hosts takes a little more work */
4359 if (dict_size(opserv_trusted_hosts
)) {
4360 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
4361 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
4362 struct trusted_host
*th
= iter_data(it
);
4363 saxdb_start_record(ctx
, iter_key(it
), 0);
4364 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
4365 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
4366 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
4367 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
4368 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
4369 saxdb_end_record(ctx
);
4371 saxdb_end_record(ctx
);
4375 struct gag_entry
*gag
;
4376 saxdb_start_record(ctx
, KEY_GAGS
, 1);
4377 for (gag
= gagList
; gag
; gag
= gag
->next
) {
4378 saxdb_start_record(ctx
, gag
->mask
, 0);
4379 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
4380 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
4381 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
4382 saxdb_end_record(ctx
);
4384 saxdb_end_record(ctx
);
4386 /* channel warnings */
4388 if (dict_size(opserv_chan_warn)) {
4389 saxdb_start_record(ctx, KEY_WARN, 0);
4390 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
4391 saxdb_write_string(ctx, iter_key(it), iter_data(it));
4393 saxdb_end_record(ctx);
4397 if (dict_size(opserv_user_alerts
)) {
4398 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
4399 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
4400 struct opserv_user_alert
*alert
= iter_data(it
);
4401 const char *reaction
;
4402 saxdb_start_record(ctx
, iter_key(it
), 0);
4403 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
4404 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
4405 switch (alert
->reaction
) {
4406 case REACT_NOTICE
: reaction
= "notice"; break;
4407 case REACT_KILL
: reaction
= "kill"; break;
4408 // case REACT_SILENT: reaction = "silent"; break;
4409 case REACT_GLINE
: reaction
= "gline"; break;
4410 case REACT_TRACK
: reaction
= "track"; break;
4411 case REACT_SHUN
: reaction
= "shun"; break;
4414 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
4417 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
4418 saxdb_end_record(ctx
);
4420 saxdb_end_record(ctx
);
4423 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
4424 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
4425 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
4426 saxdb_end_record(ctx
);
4431 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
4433 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
4437 static MODCMD_FUNC(cmd_query
)
4439 struct record_data
*rd
;
4444 reply("OSMSG_OPTION_ROOT");
4445 conf_enum_root(query_keys_helper
, user
);
4449 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
4450 if (!(rd
= conf_get_node(nodename
))) {
4451 reply("OSMSG_UNKNOWN_OPTION", nodename
);
4455 if (rd
->type
== RECDB_QSTRING
)
4456 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
4457 else if (rd
->type
== RECDB_STRING_LIST
) {
4458 reply("OSMSG_OPTION_LIST", nodename
);
4459 if (rd
->d
.slist
->used
)
4460 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
4461 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
4463 reply("OSMSG_OPTION_LIST_EMPTY");
4464 } else if (rd
->type
== RECDB_OBJECT
) {
4465 reply("OSMSG_OPTION_KEYS", nodename
);
4466 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
4472 static MODCMD_FUNC(cmd_set
)
4474 struct record_data
*rd
;
4476 /* I originally wanted to be able to fully manipulate the config
4477 db with this, but i wussed out. feel free to fix this - you'll
4478 need to handle quoted strings which have been split, and likely
4479 invent a syntax for it. -Zoot */
4481 if (!(rd
= conf_get_node(argv
[1]))) {
4482 reply("OSMSG_SET_NOT_SET", argv
[1]);
4486 if (rd
->type
!= RECDB_QSTRING
) {
4487 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
4491 free(rd
->d
.qstring
);
4492 rd
->d
.qstring
= strdup(argv
[2]);
4493 conf_call_reload_funcs();
4494 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
4498 static MODCMD_FUNC(cmd_settime
)
4500 const char *srv_name_mask
= "*";
4501 time_t new_time
= now
;
4504 srv_name_mask
= argv
[1];
4506 new_time
= time(NULL
);
4507 irc_settime(srv_name_mask
, new_time
);
4508 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
4513 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
4518 discrim
= calloc(1, sizeof(*discrim
));
4519 discrim
->limit
= 250;
4520 discrim
->max_level
= ~0;
4521 discrim
->max_ts
= INT_MAX
;
4522 discrim
->domain_depth
= 2;
4523 discrim
->max_channels
= INT_MAX
;
4524 discrim
->authed
= -1;
4525 discrim
->info_space
= -1;
4526 discrim
->intra_dcmp
= 0;
4527 discrim
->intra_scmp
= 0;
4528 discrim
->use_regex
= 0;
4529 discrim
->silent
= 0;
4531 for (i
=0; i
<argc
; i
++) {
4532 if (irccasecmp(argv
[i
], "log") == 0) {
4533 discrim
->option_log
= 1;
4536 /* Assume all other criteria require arguments. */
4537 if (i
== argc
- 1) {
4538 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
4541 if (argv
[i
+1][0] == '&') {
4542 /* Looking for intra-userNode matches */
4543 char *tmp
= &(argv
[i
+1][1]);
4544 if (strcasecmp(tmp
, argv
[i
]) != 0) { /* Don't allow "nick &nick" etc */
4545 if (!strcasecmp(tmp
, "nick"))
4546 discrim
->intra_dcmp
= 1;
4547 else if (!strcasecmp(tmp
, "ident"))
4548 discrim
->intra_dcmp
= 2;
4549 else if (!strcasecmp(tmp
, "info"))
4550 discrim
->intra_dcmp
= 3;
4553 if (irccasecmp(argv
[i
], "mask") == 0) {
4554 if (!is_ircmask(argv
[++i
])) {
4555 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
4558 if (!split_ircmask(argv
[i
],
4559 &discrim
->mask_nick
,
4560 &discrim
->mask_ident
,
4561 &discrim
->mask_host
)) {
4562 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
4565 } else if (irccasecmp(argv
[i
], "nick") == 0) {
4567 if (discrim
->intra_dcmp
> 0)
4568 discrim
->intra_scmp
= 1;
4570 discrim
->mask_nick
= argv
[i
];
4571 } else if (irccasecmp(argv
[i
], "ident") == 0) {
4573 if (discrim
->intra_dcmp
> 0)
4574 discrim
->intra_scmp
= 2;
4576 discrim
->mask_ident
= argv
[i
];
4577 } else if (irccasecmp(argv
[i
], "host") == 0) {
4578 discrim
->mask_host
= argv
[++i
];
4579 } else if (irccasecmp(argv
[i
], "info") == 0) {
4581 if (discrim
->intra_dcmp
> 0)
4582 discrim
->intra_scmp
= 3;
4584 discrim
->mask_info
= argv
[i
];
4585 } else if (irccasecmp(argv
[i
], "server") == 0) {
4586 discrim
->server
= argv
[++i
];
4587 } else if (irccasecmp(argv
[i
], "ip") == 0) {
4588 j
= irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, argv
[++i
]);
4590 send_message(user
, bot
, "OSMSG_BAD_IP", argv
[i
]);
4593 } else if (irccasecmp(argv
[i
], "account") == 0) {
4594 if (discrim
->authed
== 0) {
4595 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
4598 discrim
->accountmask
= argv
[++i
];
4599 discrim
->authed
= 1;
4600 } else if (irccasecmp(argv
[i
], "authed") == 0) {
4601 i
++; /* true_string and false_string are macros! */
4602 if (true_string(argv
[i
])) {
4603 discrim
->authed
= 1;
4604 } else if (false_string(argv
[i
])) {
4605 if (discrim
->accountmask
) {
4606 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
4609 discrim
->authed
= 0;
4611 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4614 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
4615 /* XXX: A hack because you can't check explicitly for a space through
4616 * any other means */
4618 if (true_string(argv
[i
])) {
4619 discrim
->info_space
= 1;
4620 } else if (false_string(argv
[i
])) {
4621 discrim
->info_space
= 0;
4623 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4626 } else if (irccasecmp(argv
[i
], "regex") == 0) {
4628 if (true_string(argv
[i
])) {
4629 discrim
->use_regex
= 1;
4630 } else if (false_string(argv
[i
])) {
4631 discrim
->use_regex
= 0;
4633 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4636 } else if (irccasecmp(argv
[i
], "silent") == 0) {
4638 if(user
!= opserv
&& !oper_has_access(user
, opserv
, opserv_conf
.silent_level
, 0)) {
4640 } else if (true_string(argv
[i
])) {
4641 discrim
->silent
= 1;
4642 } else if (false_string(argv
[i
])) {
4643 discrim
->silent
= 0;
4645 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4648 } else if (irccasecmp(argv
[i
], "duration") == 0) {
4649 discrim
->duration
= ParseInterval(argv
[++i
]);
4650 } else if (irccasecmp(argv
[i
], "channel") == 0) {
4651 for (j
=0, i
++; ; j
++) {
4652 switch (argv
[i
][j
]) {
4656 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
4659 discrim
->chan_req_modes
|= MODE_VOICE
;
4660 discrim
->chan_no_modes
|= MODE_CHANOP
;
4661 discrim
->chan_no_modes
|= MODE_HALFOP
;
4664 discrim
->chan_req_modes
|= MODE_HALFOP
;
4665 discrim
->chan_no_modes
|= MODE_CHANOP
;
4666 discrim
->chan_no_modes
|= MODE_VOICE
;
4669 discrim
->chan_req_modes
|= MODE_CHANOP
;
4672 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
4677 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
4678 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
4679 /* secretly "allow_channel" now means "if a channel name is
4680 * specified, require that it currently exist" */
4681 if (allow_channel
) {
4682 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
4685 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
4688 LockChannel(discrim
->channel
);
4689 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
4690 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
4691 } else if (irccasecmp(argv
[i
], "limit") == 0) {
4692 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
4693 } else if (irccasecmp(argv
[i
], "reason") == 0) {
4694 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
4696 } else if (irccasecmp(argv
[i
], "last") == 0) {
4697 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
4698 } else if ((irccasecmp(argv
[i
], "linked") == 0)
4699 || (irccasecmp(argv
[i
], "nickage") == 0)) {
4700 const char *cmp
= argv
[++i
];
4701 if (cmp
[0] == '<') {
4702 if (cmp
[1] == '=') {
4703 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
4705 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
4707 } else if (cmp
[0] == '>') {
4708 if (cmp
[1] == '=') {
4709 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
4711 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
4714 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
4716 } else if (irccasecmp(argv
[i
], "access") == 0) {
4717 const char *cmp
= argv
[++i
];
4718 if (cmp
[0] == '<') {
4719 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
4720 if (cmp
[1] == '=') {
4721 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
4723 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
4725 } else if (cmp
[0] == '=') {
4726 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
4727 } else if (cmp
[0] == '>') {
4728 if (cmp
[1] == '=') {
4729 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
4731 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
4734 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
4736 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
4737 && (irccasecmp(argv
[++i
], "opers") == 0)) {
4738 discrim
->match_opers
= 1;
4739 } else if (irccasecmp(argv
[i
], "depth") == 0) {
4740 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
4741 } else if (irccasecmp(argv
[i
], "clones") == 0) {
4742 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
4744 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
4749 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
4750 discrim
->mask_nick
= 0;
4752 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
4753 discrim
->mask_ident
= 0;
4755 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
4756 discrim
->mask_info
= 0;
4758 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
4759 discrim
->mask_host
= 0;
4762 if(discrim
->use_regex
)
4764 if(discrim
->mask_nick
)
4766 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
4767 discrim
->has_regex_nick
= !err
;
4771 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
4773 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
4778 if(discrim
->mask_ident
)
4780 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
4781 discrim
->has_regex_ident
= !err
;
4785 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
4787 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
4792 if(discrim
->mask_host
)
4794 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
4795 discrim
->has_regex_host
= !err
;
4799 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
4801 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
4806 if(discrim
->mask_info
)
4808 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
4809 discrim
->has_regex_info
= !err
;
4813 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
4815 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
4828 if(discrim
->has_regex_nick
)
4829 regfree(&discrim
->regex_nick
);
4830 if(discrim
->has_regex_ident
)
4831 regfree(&discrim
->regex_ident
);
4832 if(discrim
->has_regex_host
)
4833 regfree(&discrim
->regex_host
);
4834 if(discrim
->has_regex_info
)
4835 regfree(&discrim
->regex_info
);
4842 discrim_match(discrim_t discrim
, struct userNode
*user
)
4844 unsigned int access
;
4845 char *scmp
=NULL
, *dcmp
=NULL
;
4847 if ((user
->timestamp
< discrim
->min_ts
)
4848 || (user
->timestamp
> discrim
->max_ts
)
4849 || (user
->channels
.used
< discrim
->min_channels
)
4850 || (user
->channels
.used
> discrim
->max_channels
)
4851 || (discrim
->authed
== 0 && user
->handle_info
)
4852 || (discrim
->authed
== 1 && !user
->handle_info
)
4853 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
4854 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
4855 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
4856 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
4857 || (discrim
->ip_mask_bits
&& !irc_check_mask(&user
->ip
, &discrim
->ip_mask
, discrim
->ip_mask_bits
))
4861 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
))
4864 if(discrim
->use_regex
)
4866 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
4867 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
4868 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
4869 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))) {
4875 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
4876 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
4877 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
4878 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))) {
4883 if ((discrim
->intra_scmp
> 0 && discrim
->intra_dcmp
> 0)) {
4884 switch(discrim
->intra_scmp
) {
4885 case 1: scmp
=user
->nick
; break;
4886 case 2: scmp
=user
->ident
; break;
4889 if (discrim
->info_space
== 1) scmp
++;
4892 switch(discrim
->intra_dcmp
) {
4893 case 1: dcmp
=user
->nick
; break;
4894 case 2: dcmp
=user
->ident
; break;
4895 case 3: /* When checking INFO, and info_space is enabled
4896 * ignore the first character in a search
4897 * XXX: Should we ignore ALL leading whitespace?
4898 * Also, what about ignoring ~ in ident?
4901 if (discrim
->info_space
== 1) dcmp
++;
4904 if (irccasecmp(scmp
,dcmp
))
4908 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
4909 if ((access
< discrim
->min_level
)
4910 || (access
> discrim
->max_level
)) {
4913 if (discrim
->min_clones
> 1) {
4914 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&user
->ip
), NULL
);
4915 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
))
4922 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
4924 unsigned int nn
, count
;
4925 struct userList matched
;
4927 userList_init(&matched
);
4928 /* Try most optimized search methods first */
4929 if (discrim
->channel
) {
4931 (nn
< discrim
->channel
->members
.used
)
4932 && (matched
.used
< discrim
->limit
);
4934 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
4935 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
4936 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
4939 if (discrim_match(discrim
, mn
->user
)) {
4940 userList_append(&matched
, mn
->user
);
4943 } else if (discrim
->ip_mask_bits
== 128) {
4944 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&discrim
->ip_mask
), NULL
);
4946 userList_clean(&matched
);
4949 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
4950 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
4951 userList_append(&matched
, ohi
->clients
.list
[nn
]);
4956 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
4957 if (discrim_match(discrim
, iter_data(it
))) {
4958 userList_append(&matched
, iter_data(it
));
4963 if (!matched
.used
) {
4964 userList_clean(&matched
);
4968 if (discrim
->option_log
) {
4969 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
4971 for (nn
=0; nn
<matched
.used
; nn
++) {
4972 struct userNode
*user
= matched
.list
[nn
];
4973 if (discrim
->option_log
) {
4974 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
4976 if (dsf(user
, data
)) {
4977 /* If a search function returns true, it ran into a
4978 problem. Stop going through the list. */
4982 if (discrim
->option_log
) {
4983 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
4985 count
= matched
.used
;
4986 userList_clean(&matched
);
4991 trace_print_func(struct userNode
*match
, void *extra
)
4993 struct discrim_and_source
*das
= extra
;
4994 if (match
->handle_info
) {
4995 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
);
4997 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
5003 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
5009 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
5011 return !(IsService(target
)
5012 || (!match_opers
&& IsOper(target
))
5013 || (target
->handle_info
5014 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
5018 trace_gline_func(struct userNode
*match
, void *extra
)
5020 struct discrim_and_source
*das
= extra
;
5022 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5023 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
, das
->discrim
->silent
);
5030 trace_shun_func(struct userNode
*match
, void *extra
)
5032 struct discrim_and_source
*das
= extra
;
5034 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5035 opserv_shun(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
5042 trace_kill_func(struct userNode
*match
, void *extra
)
5044 struct discrim_and_source
*das
= extra
;
5046 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5048 if (das
->discrim
->reason
) {
5049 reason
= das
->discrim
->reason
;
5051 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
5052 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
5054 DelUser(match
, opserv
, 1, reason
);
5061 is_gagged(char *mask
)
5063 struct gag_entry
*gag
;
5065 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5066 if (match_ircglobs(gag
->mask
, mask
)) return 1;
5072 trace_gag_func(struct userNode
*match
, void *extra
)
5074 struct discrim_and_source
*das
= extra
;
5076 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5077 char *reason
, *mask
;
5079 if (das
->discrim
->reason
) {
5080 reason
= das
->discrim
->reason
;
5082 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
5083 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
5085 masksize
= 5+strlen(match
->hostname
);
5086 mask
= alloca(masksize
);
5087 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
5088 if (!is_gagged(mask
)) {
5089 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
5090 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
5098 trace_domains_func(struct userNode
*match
, void *extra
)
5100 struct discrim_and_source
*das
= extra
;
5102 unsigned long *count
;
5105 char ipmask
[IRC_NTOP_MASK_MAX_SIZE
];
5107 if (irc_pton(&ip
, NULL
, match
->hostname
)) {
5108 if (irc_in_addr_is_ipv4(ip
)) {
5109 unsigned long matchip
= ntohl(ip
.in6_32
[3]);
5110 /* raw IP address.. use up to first three octets of IP */
5111 switch (das
->discrim
->domain_depth
) {
5113 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
5116 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
5119 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
5122 } else if (irc_in_addr_is_ipv6(ip
)) {
5123 switch (das
->discrim
->domain_depth
) {
5124 case 1: depth
= 16; goto ipv6_pfx
;
5125 case 2: depth
= 24; goto ipv6_pfx
;
5126 case 3: depth
= 32; goto ipv6_pfx
;
5127 default: depth
= das
->discrim
->domain_depth
;
5129 irc_ntop_mask(ipmask
, sizeof(ipmask
), &ip
, depth
);
5131 } else safestrncpy(ipmask
, match
->hostname
, sizeof(ipmask
));
5132 ipmask
[sizeof(ipmask
) - 1] = '\0';
5135 hostname
= match
->hostname
+ strlen(match
->hostname
);
5136 for (depth
=das
->discrim
->domain_depth
;
5137 depth
&& (hostname
> match
->hostname
);
5140 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
5142 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
5144 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
5145 count
= calloc(1, sizeof(*count
));
5146 dict_insert(das
->dict
, strdup(hostname
), count
);
5153 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
5155 unsigned long *count
= data
;
5156 struct discrim_and_source
*das
= extra
;
5158 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
5159 return !--das
->disp_limit
;
5162 static MODCMD_FUNC(cmd_trace
)
5164 struct discrim_and_source das
;
5165 discrim_search_func action
;
5166 unsigned int matches
;
5167 struct svccmd
*subcmd
;
5170 sprintf(buf
, "trace %s", argv
[1]);
5171 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
5172 reply("OSMSG_BAD_ACTION", argv
[1]);
5175 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
5177 if (!irccasecmp(argv
[1], "print"))
5178 action
= trace_print_func
;
5179 else if (!irccasecmp(argv
[1], "count"))
5180 action
= trace_count_func
;
5181 else if (!irccasecmp(argv
[1], "domains"))
5182 action
= trace_domains_func
;
5183 else if (!irccasecmp(argv
[1], "gline"))
5184 action
= trace_gline_func
;
5185 else if (!irccasecmp(argv
[1], "shun"))
5186 action
= trace_shun_func
;
5187 else if (!irccasecmp(argv
[1], "kill"))
5188 action
= trace_kill_func
;
5189 else if (!irccasecmp(argv
[1], "gag"))
5190 action
= trace_gag_func
;
5192 reply("OSMSG_BAD_ACTION", argv
[1]);
5196 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
5197 reply("OSMSG_LEVEL_TOO_LOW");
5203 das
.destination
= cmd
->parent
->bot
;
5204 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
5208 if (action
== trace_print_func
)
5210 reply("OSMSG_USER_SEARCH_RESULTS");
5211 reply("OSMSG_USER_SEARCH_BAR");
5212 reply("OSMSG_USER_SEARCH_HEADER");
5213 reply("OSMSG_USER_SEARCH_BAR");
5215 else if (action
== trace_count_func
)
5216 das
.discrim
->limit
= INT_MAX
;
5217 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
5218 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
5219 else if ((action
== trace_shun_func
) && !das
.discrim
->duration
)
5220 das
.discrim
->duration
= opserv_conf
.block_shun_duration
;
5221 else if (action
== trace_domains_func
) {
5222 das
.dict
= dict_new();
5223 dict_set_free_data(das
.dict
, free
);
5224 dict_set_free_keys(das
.dict
, free
);
5225 das
.disp_limit
= das
.discrim
->limit
;
5226 das
.discrim
->limit
= INT_MAX
;
5228 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
5230 if (action
== trace_domains_func
)
5231 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
5235 if(action
== trace_print_func
)
5236 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
5238 reply("OSMSG_USER_SEARCH_COUNT", matches
);
5241 reply("MSG_NO_MATCHES");
5243 if (das
.discrim
->channel
)
5244 UnlockChannel(das
.discrim
->channel
);
5245 free(das
.discrim
->reason
);
5247 if(das
.discrim
->has_regex_nick
)
5248 regfree(&das
.discrim
->regex_nick
);
5249 if(das
.discrim
->has_regex_ident
)
5250 regfree(&das
.discrim
->regex_ident
);
5251 if(das
.discrim
->has_regex_host
)
5252 regfree(&das
.discrim
->regex_host
);
5253 if(das
.discrim
->has_regex_info
)
5254 regfree(&das
.discrim
->regex_info
);
5257 dict_delete(das
.dict
);
5261 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
5263 typedef struct channel_discrim
{
5266 unsigned int min_users
, max_users
;
5267 time_t min_ts
, max_ts
;
5271 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
5272 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
5275 smart_parse_time(const char *str
) {
5276 /* If an interval-style string is given, treat as time before now.
5277 * If it's all digits, treat directly as a Unix timestamp. */
5278 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
5282 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
5287 discrim
= calloc(1, sizeof(*discrim
));
5288 discrim
->limit
= 25;
5290 for (i
= 0; i
< argc
; i
++) {
5291 /* Assume all criteria require arguments. */
5292 if (i
== (argc
- 1)) {
5293 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5297 if (!irccasecmp(argv
[i
], "name"))
5298 discrim
->name
= argv
[++i
];
5299 else if (!irccasecmp(argv
[i
], "topic"))
5300 discrim
->topic
= argv
[++i
];
5301 else if (!irccasecmp(argv
[i
], "users")) {
5302 const char *cmp
= argv
[++i
];
5303 if (cmp
[0] == '<') {
5305 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
5307 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
5308 } else if (cmp
[0] == '=') {
5309 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
5310 } else if (cmp
[0] == '>') {
5312 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
5314 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
5316 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
5318 } else if (!irccasecmp(argv
[i
], "timestamp")) {
5319 const char *cmp
= argv
[++i
];
5320 if (cmp
[0] == '<') {
5322 discrim
->max_ts
= smart_parse_time(cmp
+2);
5324 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
5325 } else if (cmp
[0] == '=') {
5326 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
5327 } else if (cmp
[0] == '>') {
5329 discrim
->min_ts
= smart_parse_time(cmp
+2);
5331 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
5333 discrim
->min_ts
= smart_parse_time(cmp
);
5335 } else if (!irccasecmp(argv
[i
], "limit")) {
5336 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
5338 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
5343 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
5345 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
5355 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
5357 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
5358 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
5359 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
5360 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
5361 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
5362 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
5368 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
5370 unsigned int count
= 0;
5371 dict_iterator_t it
, next
;
5373 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
5374 struct chanNode
*chan
= iter_data(it
);
5376 /* Hold on to the next channel in case we decide to
5377 add actions that destructively modify the channel. */
5378 next
= iter_next(it
);
5379 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
5380 dsf(chan
, data
, bot
);
5388 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
5392 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
5395 irc_make_chanmode(channel
, modes
);
5396 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
5399 static MODCMD_FUNC(cmd_csearch
)
5402 unsigned int matches
;
5403 cdiscrim_search_func action
;
5404 struct svccmd
*subcmd
;
5407 if (!irccasecmp(argv
[1], "count"))
5408 action
= channel_count
;
5409 else if (!irccasecmp(argv
[1], "print"))
5410 action
= channel_print
;
5412 reply("OSMSG_BAD_ACTION", argv
[1]);
5416 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
5417 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
5418 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
5422 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
5426 if (action
== channel_print
)
5427 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
5428 else if (action
== channel_count
)
5429 discrim
->limit
= INT_MAX
;
5431 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
5434 reply("MSG_MATCH_COUNT", matches
);
5436 reply("MSG_NO_MATCHES");
5442 static MODCMD_FUNC(cmd_gsync
)
5446 src
= GetServerH(argv
[1]);
5448 reply("MSG_SERVER_UNKNOWN", argv
[1]);
5454 irc_stats(cmd
->parent
->bot
, src
, 'G');
5455 reply("OSMSG_GSYNC_RUNNING", src
->name
);
5459 static MODCMD_FUNC(cmd_ssync
)
5463 src
= GetServerH(argv
[1]);
5465 reply("MSG_SERVER_UNKNOWN", argv
[1]);
5471 irc_stats(cmd
->parent
->bot
, src
, 'S');
5472 reply("OSMSG_SSYNC_RUNNING", src
->name
);
5476 struct gline_extra
{
5477 struct userNode
*user
;
5478 struct string_list
*glines
;
5479 struct userNode
*bot
;
5483 gtrace_print_func(struct gline
*gline
, void *extra
)
5485 struct gline_extra
*xtra
= extra
;
5486 char *when_text
, set_text
[20];
5487 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
5488 when_text
= asctime(localtime(&gline
->expires
));
5489 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
5490 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
5494 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
5499 gtrace_ungline_func(struct gline
*gline
, void *extra
)
5501 struct gline_extra
*xtra
= extra
;
5502 string_list_append(xtra
->glines
, strdup(gline
->target
));
5505 static MODCMD_FUNC(cmd_gtrace
)
5507 struct gline_discrim
*discrim
;
5508 gline_search_func action
;
5509 unsigned int matches
, nn
;
5510 struct gline_extra extra
;
5511 struct svccmd
*subcmd
;
5514 if (!irccasecmp(argv
[1], "print"))
5515 action
= gtrace_print_func
;
5516 else if (!irccasecmp(argv
[1], "count"))
5517 action
= gtrace_count_func
;
5518 else if (!irccasecmp(argv
[1], "ungline"))
5519 action
= gtrace_ungline_func
;
5521 reply("OSMSG_BAD_ACTION", argv
[1]);
5524 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
5525 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
5526 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
5530 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
5534 if (action
== gtrace_print_func
)
5535 reply("OSMSG_GLINE_SEARCH_RESULTS");
5536 else if (action
== gtrace_count_func
)
5537 discrim
->limit
= INT_MAX
;
5540 extra
.glines
= alloc_string_list(4);
5541 extra
.bot
= cmd
->parent
->bot
;
5542 matches
= gline_discrim_search(discrim
, action
, &extra
);
5544 if (action
== gtrace_ungline_func
)
5545 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
5546 gline_remove(extra
.glines
->list
[nn
], 1);
5547 free_string_list(extra
.glines
);
5550 reply("MSG_MATCH_COUNT", matches
);
5552 reply("MSG_NO_MATCHES");
5553 free(discrim
->alt_target_mask
);
5559 struct userNode
*user
;
5560 struct string_list
*shuns
;
5561 struct userNode
*bot
;
5565 strace_print_func(struct shun
*shun
, void *extra
)
5567 struct shun_extra
*xtra
= extra
;
5568 char *when_text
, set_text
[20];
5569 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&shun
->issued
));
5570 when_text
= asctime(localtime(&shun
->expires
));
5571 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
5572 send_message(xtra
->user
, xtra
->bot
, "OSMSG_STRACE_FORMAT", shun
->target
, set_text
, shun
->issuer
, when_text
, shun
->reason
);
5576 strace_count_func(UNUSED_ARG(struct shun
*shun
), UNUSED_ARG(void *extra
))
5581 strace_unshun_func(struct shun
*shun
, void *extra
)
5583 struct shun_extra
*xtra
= extra
;
5584 string_list_append(xtra
->shuns
, strdup(shun
->target
));
5587 static MODCMD_FUNC(cmd_strace
)
5589 struct shun_discrim
*discrim
;
5590 shun_search_func action
;
5591 unsigned int matches
, nn
;
5592 struct shun_extra extra
;
5593 struct svccmd
*subcmd
;
5596 if (!irccasecmp(argv
[1], "print"))
5597 action
= strace_print_func
;
5598 else if (!irccasecmp(argv
[1], "count"))
5599 action
= strace_count_func
;
5600 else if (!irccasecmp(argv
[1], "unshun"))
5601 action
= strace_unshun_func
;
5603 reply("OSMSG_BAD_ACTION", argv
[1]);
5606 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
5607 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
5608 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
5612 discrim
= shun_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
5616 if (action
== strace_print_func
)
5617 reply("OSMSG_SHUN_SEARCH_RESULTS");
5618 else if (action
== strace_count_func
)
5619 discrim
->limit
= INT_MAX
;
5622 extra
.shuns
= alloc_string_list(4);
5623 extra
.bot
= cmd
->parent
->bot
;
5624 matches
= shun_discrim_search(discrim
, action
, &extra
);
5626 if (action
== strace_unshun_func
)
5627 for (nn
=0; nn
<extra
.shuns
->used
; nn
++)
5628 shun_remove(extra
.shuns
->list
[nn
], 1);
5629 free_string_list(extra
.shuns
);
5632 reply("MSG_MATCH_COUNT", matches
);
5634 reply("MSG_NO_MATCHES");
5635 free(discrim
->alt_target_mask
);
5641 alert_check_user(const char *key
, void *data
, void *extra
)
5643 struct opserv_user_alert
*alert
= data
;
5644 struct userNode
*user
= extra
;
5646 if (!discrim_match(alert
->discrim
, user
))
5649 if ((alert
->reaction
!= REACT_NOTICE
)
5651 && !alert
->discrim
->match_opers
) {
5655 /* The user matches the alert criteria, so trigger the reaction. */
5656 if (alert
->discrim
->option_log
)
5657 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
);
5659 /* Return 1 to halt alert matching, such as when killing the user
5660 that triggered the alert. */
5661 switch (alert
->reaction
) {
5663 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
5667 opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, 1);
5671 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
, alert
->discrim
->silent
);
5674 opserv_shun(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
5677 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
5678 /* fall through to REACT_NOTICE case */
5680 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
);
5684 opserv_alert("Alert $b%s$b triggered by user $b%s$b!%s@%s (%s) (Tracking).", key
, user
->nick
, user
->ident
, user
->hostname
, alert
->discrim
->reason
);
5685 add_track_user(user
);
5693 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
5695 struct gag_entry
*gag
;
5696 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
5697 /* Gag them if appropriate (and only if). */
5698 user
->modes
&= ~FLAGS_GAGGED
;
5699 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5700 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
5701 gag_helper_func(user
, NULL
);
5708 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
5712 if (!opserv_conf
.staff_auth_channel
5713 || user
->uplink
->burst
5714 || !user
->handle_info
)
5716 else if (user
->handle_info
->opserv_level
)
5718 else if (IsNetworkHelper(user
))
5719 type
= "NETWORK HELPER";
5720 else if (IsSupportHelper(user
))
5721 type
= "SUPPORT HELPER";
5725 if (irc_in_addr_is_valid(user
->ip
))
5726 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
5728 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
);
5731 static MODCMD_FUNC(cmd_log
)
5733 struct logSearch
*discrim
;
5734 unsigned int matches
;
5735 struct logReport report
;
5737 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
5741 reply("OSMSG_LOG_SEARCH_RESULTS");
5742 report
.reporter
= opserv
;
5744 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
5747 reply("MSG_MATCH_COUNT", matches
);
5749 reply("MSG_NO_MATCHES");
5756 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
5758 if (IsOper(match
) || IsLocal(match
))
5760 match
->modes
|= FLAGS_GAGGED
;
5764 static MODCMD_FUNC(cmd_gag
)
5766 struct gag_entry
*gag
;
5767 unsigned int gagged
;
5768 unsigned long duration
;
5771 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
5773 if (!is_ircmask(argv
[1])) {
5774 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
5778 for (gag
= gagList
; gag
; gag
= gag
->next
)
5779 if (match_ircglobs(gag
->mask
, argv
[1]))
5783 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
5787 duration
= ParseInterval(argv
[2]);
5788 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
5791 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
5793 reply("OSMSG_GAG_ADDED", argv
[1]);
5798 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
5800 match
->modes
&= ~FLAGS_GAGGED
;
5804 static MODCMD_FUNC(cmd_ungag
)
5806 struct gag_entry
*gag
;
5807 unsigned int ungagged
;
5809 for (gag
= gagList
; gag
; gag
= gag
->next
)
5810 if (!strcmp(gag
->mask
, argv
[1]))
5814 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
5818 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
5819 ungagged
= gag_free(gag
);
5822 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
5824 reply("OSMSG_UNGAG_ADDED", argv
[1]);
5828 static MODCMD_FUNC(cmd_addalert
)
5830 opserv_alert_reaction reaction
;
5831 struct svccmd
*subcmd
;
5836 sprintf(buf
, "addalert %s", argv
[2]);
5837 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
5838 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
5841 if (!irccasecmp(argv
[2], "notice"))
5842 reaction
= REACT_NOTICE
;
5843 else if (!irccasecmp(argv
[2], "kill"))
5844 reaction
= REACT_KILL
;
5846 else if (!irccasecmp(argv[2], "silent"))
5847 reaction = REACT_SILENT;
5849 else if (!irccasecmp(argv
[2], "gline"))
5850 reaction
= REACT_GLINE
;
5851 else if (!irccasecmp(argv
[2], "track")) {
5853 reply("OSMSG_TRACK_DISABLED");
5856 reaction
= REACT_TRACK
;
5858 } else if (!irccasecmp(argv
[2], "shun"))
5859 reaction
= REACT_SHUN
;
5861 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
5864 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
5865 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
)))
5867 reply("OSMSG_ADDED_ALERT", name
);
5871 static MODCMD_FUNC(cmd_delalert
)
5874 for (i
=1; i
<argc
; i
++) {
5875 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
5876 dict_remove(opserv_channel_alerts
, argv
[i
]);
5877 if (dict_remove(opserv_user_alerts
, argv
[i
]))
5878 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
5880 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
5886 opserv_conf_read(void)
5888 struct chanNode
*chan
;
5890 struct record_data
*rd
;
5891 dict_t conf_node
, child
;
5892 const char *str
, *str2
;
5893 struct policer_params
*pp
;
5896 rd
= conf_get_node(OPSERV_CONF_NAME
);
5897 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
5898 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
5901 conf_node
= rd
->d
.object
;
5902 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
5903 if (opserv
&& str
) {
5904 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
5907 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
5908 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
5910 opserv_conf
.debug_channel
= NULL
;
5912 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
5913 if (opserv
&& str
) {
5914 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
5917 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
5918 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
5920 opserv_conf
.alert_channel
= NULL
;
5922 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
5923 if (opserv
&& str
) {
5924 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
5927 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
5928 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
5930 opserv_conf
.staff_auth_channel
= NULL
;
5933 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
5934 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
5936 str
= database_get_data(conf_node
, KEY_SILENT_LEVEL
, RECDB_QSTRING
);
5937 opserv_conf
.silent_level
= str
? strtoul(str
, NULL
, 0): 700;
5939 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
5940 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
5941 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
5942 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
5943 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
5944 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
5945 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
5946 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
5947 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
5949 NickChange(opserv
, str
, 0);
5951 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
5952 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
5953 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
5954 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
5956 free_string_list(autojoin_channels
);
5957 autojoin_channels
= database_get_data(conf_node
, KEY_AUTOJOIN_CHANNELS
, RECDB_STRING_LIST
);
5959 if(autojoin_channels
)
5960 autojoin_channels
= string_list_copy(autojoin_channels
);
5962 if (autojoin_channels
&& opserv
) {
5963 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
5964 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
5965 AddChannelUser(opserv
, chan
)->modes
|= MODE_CHANOP
;
5969 str
= database_get_data(conf_node
, KEY_BLOCK_SHUN_DURATION
, RECDB_QSTRING
);
5970 opserv_conf
.block_shun_duration
= str
? ParseInterval(str
) : 3600;
5972 if (!opserv_conf
.join_policer_params
)
5973 opserv_conf
.join_policer_params
= policer_params_new();
5974 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
5975 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
5976 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
5977 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
5979 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
5980 struct chanNode
*cNode
= iter_data(it
);
5981 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
5984 if (opserv_conf
.new_user_policer
.params
)
5985 pp
= opserv_conf
.new_user_policer
.params
;
5987 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
5988 policer_params_set(pp
, "size", "200");
5989 policer_params_set(pp
, "drain-rate", "3");
5990 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
5991 dict_foreach(child
, set_policer_param
, pp
);
5994 /* lame way to export opserv_conf value to nickserv.c ... */
5996 opserv_conf_admin_level()
5998 return(opserv_conf
.admin_level
);
6002 opserv_db_init(void) {
6003 /* set up opserv_trusted_hosts dict */
6004 dict_delete(opserv_trusted_hosts
);
6005 opserv_trusted_hosts
= dict_new();
6006 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
6008 opserv_routing_plan_options
= dict_new();
6010 opserv_routing_plans
= dict_new();
6011 dict_set_free_data(opserv_routing_plans
, free_routing_plan
);
6012 /* set up opserv_chan_warn dict */
6014 /* alert trace notice channel #x replaces warnings
6015 dict_delete(opserv_chan_warn);
6016 opserv_chan_warn = dict_new();
6017 dict_set_free_keys(opserv_chan_warn, free);
6018 dict_set_free_data(opserv_chan_warn, free);
6020 /* set up opserv_user_alerts */
6021 dict_delete(opserv_channel_alerts
);
6022 opserv_channel_alerts
= dict_new();
6023 dict_delete(opserv_nick_based_alerts
);
6024 opserv_nick_based_alerts
= dict_new();
6025 dict_delete(opserv_user_alerts
);
6026 opserv_user_alerts
= dict_new();
6027 dict_set_free_keys(opserv_user_alerts
, free
);
6028 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
6029 /* set up opserv_bad_words */
6030 free_string_list(opserv_bad_words
);
6031 opserv_bad_words
= alloc_string_list(4);
6032 /* and opserv_exempt_channels */
6033 dict_delete(opserv_exempt_channels
);
6034 opserv_exempt_channels
= dict_new();
6035 dict_set_free_keys(opserv_exempt_channels
, free
);
6039 opserv_db_cleanup(void)
6043 /* dict_delete(opserv_chan_warn); */
6044 dict_delete(opserv_reserved_nick_dict
);
6045 free_string_list(opserv_bad_words
);
6046 dict_delete(opserv_exempt_channels
);
6047 dict_delete(opserv_trusted_hosts
);
6048 unreg_del_user_func(opserv_user_cleanup
);
6049 dict_delete(opserv_hostinfo_dict
);
6050 dict_delete(opserv_nick_based_alerts
);
6051 dict_delete(opserv_channel_alerts
);
6052 dict_delete(opserv_user_alerts
);
6053 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
6054 free(level_strings
[nn
]);
6057 policer_params_delete(opserv_conf
.join_policer_params
);
6058 policer_params_delete(opserv_conf
.new_user_policer
.params
);
6062 init_opserv(const char *nick
)
6064 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
6066 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
6067 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
6069 conf_register_reload(opserv_conf_read
);
6071 memset(level_strings
, 0, sizeof(level_strings
));
6072 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
6073 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
6074 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
6075 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
6076 opserv_define_func("ADDALERT SILENT", NULL
, 900, 0, 0);
6077 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
6078 opserv_define_func("ADDALERT SHUN", NULL
, 900, 0, 0);
6079 opserv_define_func("ADDALERT TRACK", NULL
, 900, 0, 0);
6080 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
6081 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
6082 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
6083 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
6084 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
6085 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
6086 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
6087 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
6088 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
6089 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
6090 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
6091 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
6092 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
6093 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
6094 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
6095 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
6096 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
6097 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
6098 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
6099 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
6100 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
6101 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
6102 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
6103 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
6104 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
6105 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
6106 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
6107 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
6108 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
6109 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
6110 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
6111 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
6112 opserv_define_func("SBLOCK", cmd_sblock
, 100, 0, 2);
6113 opserv_define_func("SHUN", cmd_shun
, 600, 0, 4);
6114 opserv_define_func("SSYNC", cmd_ssync
, 600, 0, 0);
6115 opserv_define_func("STRACE", cmd_strace
, 100, 0, 3);
6116 opserv_define_func("STRACE COUNT", NULL
, 0, 0, 0);
6117 opserv_define_func("STRACE PRINT", NULL
, 0, 0, 0);
6118 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
6119 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
6120 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
6121 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
6122 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
6123 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
6124 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
6125 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
6126 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
6127 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
6128 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
6129 opserv_define_func("OP", cmd_op
, 100, 2, 2);
6130 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
6131 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
6132 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
6133 opserv_define_func("MAP", cmd_stats_links
, 0, 0, 0);
6134 opserv_define_func("PART", cmd_part
, 601, 0, 2);
6135 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
6136 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
6137 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
6138 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
6139 opserv_define_func("REFRESHS", cmd_refreshs
, 600, 0, 0);
6140 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
6141 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
6142 opserv_define_func("RESETMAX", cmd_resetmax
, 900, 0, 0);
6143 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
6144 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
6145 opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan
, 800, 0, 2);
6146 opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan
, 800, 0, 2);
6147 opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver
, 800, 0, 4);
6148 opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver
, 800, 0, 3);
6149 opserv_define_func("ROUTING MAP", cmd_routing_map
, 800, 0, 0);
6150 opserv_define_func("ROUTING SET", cmd_routing_set
, 800, 0, 0);
6151 opserv_define_func("REROUTE", cmd_reroute
, 800, 0, 2);
6152 opserv_define_func("SET", cmd_set
, 900, 0, 3);
6153 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
6154 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
6155 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
6156 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
6157 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
6158 opserv_define_func("STATS SHUNS", cmd_stats_shuns
, 0, 0, 0);
6159 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
6160 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
6161 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
6162 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
6163 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
6164 opserv_define_func("STATS ROUTING", cmd_stats_routing_plans
, 0, 0, 0);
6165 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
6166 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
6167 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
6168 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
6169 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
6170 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
6171 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
6173 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
6174 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
6175 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
6176 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
6177 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
6178 opserv_define_func("TRACE SHUN", NULL
, 600, 0, 0);
6179 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
6180 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
6181 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
6182 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
6183 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
6184 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
6185 opserv_define_func("UNSHUN", cmd_unshun
, 600, 0, 2);
6186 modcmd_register(opserv_module
, "GTRACE UNSHUN", NULL
, 0, 0, "template", "unshun", NULL
);
6187 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
6188 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
6189 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
6190 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
6191 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
6192 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
6194 opserv_reserved_nick_dict
= dict_new();
6195 opserv_hostinfo_dict
= dict_new();
6197 dict_set_free_keys(opserv_hostinfo_dict
, free
);
6198 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
6200 opserv_waiting_connections
= dict_new();
6201 dict_set_free_data(opserv_waiting_connections
, opserv_free_waiting_connection
);
6203 reg_new_user_func(opserv_new_user_check
);
6204 reg_nick_change_func(opserv_alert_check_nick
);
6205 reg_del_user_func(opserv_user_cleanup
);
6206 reg_new_channel_func(opserv_channel_check
);
6207 reg_del_channel_func(opserv_channel_delete
);
6208 reg_join_func(opserv_join_check
);
6209 reg_auth_func(opserv_staff_alert
);
6212 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
6215 opserv_service
= service_register(opserv
);
6216 opserv_service
->trigger
= '?';
6219 /* start auto-routing system */
6220 reroute_timer(NULL
);
6221 /* start the karma timer, using the saved one if available */
6222 routing_karma_timer(dict_find(opserv_routing_plan_options
, "KARMA_TIMER", NULL
));
6224 reg_exit_func(opserv_db_cleanup
);
6225 message_register_table(msgtab
);