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.
33 #include <tre/regex.h>
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"
96 #define KEY_DEFCON1 "DefCon1"
97 #define KEY_DEFCON2 "DefCon2"
98 #define KEY_DEFCON3 "DefCon3"
99 #define KEY_DEFCON4 "DefCon4"
100 #define KEY_DEFCON_LEVEL "DefConLevel"
101 #define KEY_DEFCON_CHANMODES "DefConChanModes"
102 #define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit"
103 #define KEY_DEFCON_TIMEOUT "DefConTimeOut"
104 #define KEY_DEFCON_GLOBAL "GlobalOnDefcon"
105 #define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore"
106 #define KEY_DEFCON_MESSAGE "DefconMessage"
107 #define KEY_DEFCON_OFF_MESSAGE "DefConOffMessage"
108 #define KEY_DEFCON_GLINE_DURATION "DefConGlineExpire"
109 #define KEY_DEFCON_GLINE_REASON "DefConGlineReason"
111 /* Routing karma values: */
112 /* What value we start out with when new servers are added: */
113 #define KARMA_DEFAULT 10
116 #define KARMA_MIN -10
117 /* ping out, reduce karma by this much: */
118 #define KARMA_PINGOUT -8
119 /* read err, reduce karma by this much: */
120 #define KARMA_READERROR -5
121 /* every 24 hours everyone gets this much added (so we eventually re-try bad servers) */
122 #define KARMA_ENTROPE 1
123 /* every 24 hours servers linked for 24 hours get an additional ammount: */
124 #define KARMA_RELIABLE 1
125 /* How often to run entrope and reliable checks */
126 #define KARMA_TIMER 86400 /* 1 day */
128 #define ROUTING_CONNECT_TIMEOUT 30 /* 30 seconds */
130 #define IDENT_FORMAT "%s [%s@%s/%s]"
131 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, irc_ntoa(&user->ip)
132 #define MAX_CHANNELS_WHOIS 50
133 #define OSMSG_PART_REASON "%s has no reason."
134 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
135 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
136 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
138 static const struct message_entry msgtab
[] = {
139 { "OSMSG_BAR", "----------------------------------------" },
140 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
141 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
142 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
143 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
144 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
145 { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." },
146 { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." },
147 { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." },
148 { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." },
149 { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." },
150 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
151 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
152 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
153 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
154 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
155 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
156 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
157 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
158 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
159 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
160 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
161 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
162 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
163 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
164 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
165 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
166 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
167 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
168 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
169 { "OSMSG_LEAVING", "Leaving $b%s$b." },
170 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
171 { "OSMSG_OP_DONE", "Opped the requested lusers." },
172 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
173 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
174 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
175 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
176 { "OSMSG_WHOIS_NICK", "Nick : %s" },
177 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
178 { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" },
179 { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" },
180 { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" },
181 { "OSMSG_WHOIS_IP", "Real IP : %s" },
182 { "OSMSG_WHOIS_COUNTRY", "Country : %s" },
183 { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" },
184 { "OSMSG_WHOIS_CITY", "City : %s" },
185 { "OSMSG_WHOIS_REGION", "Region/State : %s" },
186 { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" },
187 { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" },
188 { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" },
189 { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" },
190 { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" },
191 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
192 { "OSMSG_WHOIS_INFO", "Info : %s" },
193 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
194 { "OSMSG_WHOIS_SERVER", "Server : %s" },
195 { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" },
196 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
197 { "OSMSG_WHOIS_CHANNELS", "Channels : %s" },
198 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
199 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
200 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
201 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
202 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
203 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
204 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
205 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
206 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
207 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
208 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
209 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
210 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
211 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
212 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
213 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
214 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
215 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
216 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
217 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
218 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
219 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
220 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
221 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
222 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
223 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
224 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
225 { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." },
226 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
227 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
228 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
229 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
230 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
231 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
232 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
233 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
234 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
235 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
236 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
237 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
238 { "OSMSG_LINE_DUMPED", "Raw line sent." },
239 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
240 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
241 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
242 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
243 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
244 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
245 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
246 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
247 { "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." },
248 { "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." },
249 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
250 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
251 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
252 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
253 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
254 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
255 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
256 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
257 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
258 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
259 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
260 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
261 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
262 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
263 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
264 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
265 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
266 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
267 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
268 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
269 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
270 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
271 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
272 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
273 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
274 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
275 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
276 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
277 { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" },
278 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
279 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
280 { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
281 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
282 { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
283 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
284 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
285 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
286 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
287 { "OSMSG_NO_GAGS", "No gags have been set." },
288 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
289 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
290 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
291 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
292 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
293 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
294 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
295 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
296 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" },
297 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
298 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
299 { "OSMSG_ALERTS_DESC", " Criteria: %s" },
300 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
301 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
302 /* routing messages */
303 { "OSMSG_ROUTINGPLAN_LIST", "$bRouting Plans$b" },
304 { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" },
305 { "OSMSG_ROUTINGPLAN_END", "-------------End of Routing Plans-------------" },
306 { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" },
307 { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." },
308 { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." },
309 { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." },
310 { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." },
311 { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" },
312 { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" },
313 { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." },
314 { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." },
315 { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." },
316 { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." },
317 { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." },
318 { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." },
319 { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." },
320 { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." },
321 { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." },
322 { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" },
323 { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" },
324 { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" },
325 { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" },
326 { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" },
327 { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." },
328 { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." },
329 { "OSMSG_CONNECT", "->connect %s %d %s" },
330 { "OSMSG_SQUIT", "->squit %s" },
331 { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" },
332 { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" },
333 { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." },
334 { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." },
335 { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." },
336 { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." },
337 { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." },
338 { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", },
339 { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." },
340 { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." },
342 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
343 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
344 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
345 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
346 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
347 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
348 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
349 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
350 { "OSMSG_INVALID_NUMERIC", "Invalid numeric" },
351 { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." },
352 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
353 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
355 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
356 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
357 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
358 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
359 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
360 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
361 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
363 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
364 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
365 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
366 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
367 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
368 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
369 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
370 { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." },
371 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
372 { "OSMSG_CHANINFO_HEADER", "%s Information" },
373 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
374 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
375 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
376 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
377 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
378 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
379 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
380 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
381 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
382 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
383 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
384 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
385 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
386 { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" },
387 { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" },
389 { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" },
390 { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" },
391 { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" },
392 { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" },
393 { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" },
394 { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" },
395 { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" },
396 { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" },
397 { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" },
398 { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" },
399 { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" },
400 { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" },
401 { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" },
402 { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" },
407 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
412 int GlobalOnDefcon
= 0;
413 int GlobalOnDefconMore
= 0;
414 int DefConGlineExpire
;
415 int DefConModesSet
= 0;
416 unsigned int DefConSessionLimit
;
417 char *DefConChanModes
;
418 char *DefConGlineReason
;
420 char *DefConOffMessage
;
422 extern void add_track_user(struct userNode
*user
);
423 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
425 struct userNode
*opserv
;
426 static struct service
*opserv_service
;
428 /*static dict_t opserv_chan_warn; */ /* data is char* */
429 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
430 static struct string_list
*opserv_bad_words
;
431 static dict_t opserv_exempt_channels
; /* data is not used */
432 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
433 static dict_t opserv_routing_plans
; /* data is struct routingPlan */
434 static dict_t opserv_routing_plan_options
; /* data is a dict_t key->val list*/
435 static dict_t opserv_waiting_connections
; /* data is struct waitingConnection */
436 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
437 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
438 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
439 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
440 static struct module *opserv_module
;
441 static struct log_type
*OS_LOG
;
442 static unsigned int new_user_flood
;
443 static char *level_strings
[1001];
444 struct string_list
*autojoin_channels
;
445 struct route
*opserv_route
= NULL
; /* Main active routing table from activate_routing()*/
448 struct chanNode
*debug_channel
;
449 struct chanNode
*alert_channel
;
450 struct chanNode
*staff_auth_channel
;
451 struct policer_params
*join_policer_params
;
452 struct policer new_user_policer
;
453 unsigned long untrusted_max
;
454 unsigned long clone_gline_duration
;
455 unsigned long block_gline_duration
;
456 unsigned long block_shun_duration
;
457 unsigned long purge_lock_delay
;
458 unsigned long join_flood_moderate
;
459 unsigned long join_flood_moderate_threshold
;
460 unsigned long admin_level
;
461 unsigned long silent_level
;
464 struct trusted_host
{
478 struct gag_entry
*next
;
481 static struct gag_entry
*gagList
;
483 struct opserv_hostinfo
{
484 struct userList clients
;
485 struct trusted_host
*trusted
;
489 opserv_free_hostinfo(void *data
)
491 struct opserv_hostinfo
*ohi
= data
;
492 userList_clean(&ohi
->clients
);
497 opserv_free_waiting_connection(void *data
)
499 struct waitingConnection
*wc
= data
;
505 typedef struct opservDiscrim
{
506 struct chanNode
*channel
;
507 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *server
, *reason
, *accountmask
;
508 irc_in_addr_t ip_mask
;
510 time_t min_ts
, max_ts
;
511 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
;
512 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1;
513 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
514 unsigned char ip_mask_bits
;
515 unsigned int match_opers
: 1, option_log
: 1;
516 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
517 int authed
: 2, info_space
: 2;
518 unsigned int intra_scmp
: 2, intra_dcmp
: 2;
519 unsigned int use_regex
: 1;
520 unsigned int silent
: 1;
523 struct discrim_and_source
{
525 struct userNode
*source
;
526 struct userNode
*destination
;
528 unsigned int disp_limit
;
531 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
532 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
533 static int gag_helper_func(struct userNode
*match
, void *extra
);
534 static int ungag_helper_func(struct userNode
*match
, void *extra
);
543 } opserv_alert_reaction
;
545 struct opserv_user_alert
{
547 char *text_discrim
, *split_discrim
;
549 opserv_alert_reaction reaction
;
552 /* funny type to make it acceptible to dict_set_free_data, far below */
554 opserv_free_user_alert(void *data
)
556 struct opserv_user_alert
*alert
= data
;
557 if (alert
->discrim
->channel
)
558 UnlockChannel(alert
->discrim
->channel
);
560 free(alert
->text_discrim
);
561 free(alert
->split_discrim
);
562 if(alert
->discrim
->has_regex_nick
)
563 regfree(&alert
->discrim
->regex_nick
);
564 if(alert
->discrim
->has_regex_ident
)
565 regfree(&alert
->discrim
->regex_ident
);
566 if(alert
->discrim
->has_regex_host
)
567 regfree(&alert
->discrim
->regex_host
);
568 if(alert
->discrim
->has_regex_info
)
569 regfree(&alert
->discrim
->regex_info
);
570 free(alert
->discrim
->reason
);
571 free(alert
->discrim
);
575 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
576 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
579 char *defconReverseModes(const char *modes
)
581 char *newmodes
= NULL
;
586 if (!(newmodes
= malloc(sizeof(char) * strlen(modes
) + 1))) {
589 for (i
= 0; i
< strlen(modes
); i
++) {
592 else if (modes
[i
] == '-')
595 newmodes
[i
] = modes
[i
];
601 int checkDefCon(int level
)
603 return DefCon
[DefConLevel
] & level
;
606 void showDefConSettings(struct userNode
*user
, struct svccmd
*cmd
)
608 if (DefConLevel
== 5) {
609 reply("OSMSG_DEFCON_ALLOWING_ALL");
612 reply("OSMSG_DEFCON_DISALLOWING", DefConLevel
);
614 if (checkDefCon(DEFCON_NO_NEW_CHANNELS
))
615 reply("OSMSG_DEFCON_NO_NEW_CHANNELS");
617 if (checkDefCon(DEFCON_NO_NEW_NICKS
))
618 reply("OSMSG_DEFCON_NO_NEW_NICKS");
620 if (checkDefCon(DEFCON_NO_MODE_CHANGE
))
621 reply("OSMSG_DEFCON_NO_MODE_CHANGE");
623 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
) && (DefConChanModes
))
624 reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes
);
626 if (checkDefCon(DEFCON_REDUCE_SESSION
))
627 reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit
);
629 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
))
630 reply("OSMSG_DEFCON_NO_NEW_CLIENTS");
632 if (checkDefCon(DEFCON_OPER_ONLY
))
633 reply("OSMSG_DEFCON_OPER_ONLY");
635 if (checkDefCon(DEFCON_SILENT_OPER_ONLY
))
636 reply("OSMSG_DEFCON_SILENT_OPER_ONLY");
638 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
639 reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS");
641 if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
642 reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS");
644 if (checkDefCon(DEFCON_NO_NEW_MEMOS
))
645 reply("OSMSG_DEFCON_NO_NEW_MEMOS");
650 void do_mass_mode(char *modes
)
657 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
658 struct chanNode
*chan
= iter_data(it
);
660 irc_mode(opserv
, chan
, modes
);
665 void DefConProcess(struct userNode
*user
)
670 global_message_args(MESSAGE_RECIPIENT_LUSERS
, "DEFCON_NETWORK_CHANGED", DefConLevel
);
672 if (GlobalOnDefconMore
&& GlobalOnDefcon
)
673 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConMessage
);
675 if ((DefConLevel
== 5) && !GlobalOnDefconMore
&& !GlobalOnDefcon
)
676 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConOffMessage
);
679 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_OPER_LEVEL_CHANGE", user
->nick
, DefConLevel
);
681 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel
);
683 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
)) {
684 if (DefConChanModes
&& !DefConModesSet
) {
685 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
686 do_mass_mode(DefConChanModes
);
691 if (DefConChanModes
&& (DefConModesSet
!= 0)) {
692 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
693 if ((newmodes
= defconReverseModes(DefConChanModes
))) {
694 do_mass_mode(newmodes
);
706 defcon_timeout(UNUSED_ARG(void *data
))
712 static MODCMD_FUNC(cmd_defcon
)
714 if ((argc
< 2) || (atoi(argv
[1]) == DefConLevel
)) {
715 showDefConSettings(user
, cmd
);
719 if ((atoi(argv
[1]) < 1) || (atoi(argv
[1]) > 5)) {
720 reply("OSMSG_DEFCON_INVALID", atoi(argv
[1]));
724 DefConLevel
= atoi(argv
[1]);
725 showDefConSettings(user
, cmd
);
727 if (DefConTimeOut
> 0) {
728 timeq_del(0, defcon_timeout
, NULL
, TIMEQ_IGNORE_DATA
& TIMEQ_IGNORE_WHEN
);
729 timeq_add(now
+ DefConTimeOut
, defcon_timeout
, NULL
);
736 /* A lot of these commands are very similar to what ChanServ can do,
737 * but OpServ can do them even on channels that aren't registered.
740 static MODCMD_FUNC(cmd_access
)
742 struct handle_info
*hi
;
746 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
747 if (!irccasecmp(target
, "*")) {
748 nickserv_show_oper_accounts(user
, cmd
);
751 if (!(hi
= modcmd_get_handle_info(user
, target
)))
753 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
754 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
758 static MODCMD_FUNC(cmd_ban
)
760 struct mod_chanmode change
;
761 struct userNode
*victim
;
763 mod_chanmode_init(&change
);
765 change
.args
[0].mode
= MODE_BAN
;
766 if (is_ircmask(argv
[1]))
767 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
768 else if ((victim
= GetUserH(argv
[1])))
769 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
771 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
774 modcmd_chanmode_announce(&change
);
775 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
776 free((char*)change
.args
[0].u
.hostmask
);
780 static MODCMD_FUNC(cmd_chaninfo
)
785 struct exemptNode
*exempt
;
786 struct modeNode
*moden
;
789 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
790 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
791 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
792 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
793 irc_make_chanmode(channel
, buffer
);
794 if (channel
->bad_channel
)
795 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
797 reply("OSMSG_CHANINFO_MODES", buffer
);
798 if (channel
->topic_time
) {
799 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
800 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
801 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
803 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
804 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
806 if (channel
->banlist
.used
) {
807 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
808 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
809 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
810 ban
= channel
->banlist
.list
[n
];
811 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
812 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
815 if (channel
->exemptlist
.used
) {
816 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
817 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
818 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
819 exempt
= channel
->exemptlist
.list
[n
];
820 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
821 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
824 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
825 /* early out unless they ask for users */
826 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
829 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
830 for (n
=0; n
<channel
->members
.used
; n
++) {
831 moden
= channel
->members
.list
[n
];
832 if (moden
->modes
& MODE_CHANOP
) {
833 if (moden
->oplevel
>= 0)
834 send_message_type(4, user
, cmd
->parent
->bot
, " @%s:%d (%s@%s)", moden
->user
->nick
, moden
->oplevel
, moden
->user
->ident
, moden
->user
->hostname
);
836 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
839 for (n
=0; n
<channel
->members
.used
; n
++) {
840 moden
= channel
->members
.list
[n
];
841 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
842 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
844 for (n
=0; n
<channel
->members
.used
; n
++) {
845 moden
= channel
->members
.list
[n
];
846 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
847 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
849 for (n
=0; n
<channel
->members
.used
; n
++) {
850 moden
= channel
->members
.list
[n
];
851 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
852 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
857 /* This command has been replaced by 'alert notice channel #foo' */
859 static MODCMD_FUNC(cmd_warn)
861 char *reason, *message;
863 if (!IsChannelName(argv[1])) {
864 reply("OSMSG_NEED_CHANNEL", argv[0]);
867 reason = dict_find(opserv_chan_warn, argv[1], NULL);
869 reply("OSMSG_WARN_EXISTS", argv[1]);
873 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
875 reason = strdup("No reason");
876 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
877 reply("OSMSG_WARN_ADDED", argv[1], reason);
878 if (dict_find(channels, argv[1], NULL)) {
879 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason);
884 static MODCMD_FUNC(cmd_unwarn)
886 if ((argc < 2) || !IsChannelName(argv[1])) {
887 reply("OSMSG_NEED_CHANNEL", argv[0]);
890 if (!dict_remove(opserv_chan_warn, argv[1])) {
891 reply("OSMSG_WARN_NOEXIST", argv[1]);
894 reply("OSMSG_WARN_DELETED", argv[1]);
899 static MODCMD_FUNC(cmd_clearbans
)
901 struct mod_chanmode
*change
;
904 change
= mod_chanmode_alloc(channel
->banlist
.used
);
905 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
906 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
907 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
909 modcmd_chanmode_announce(change
);
910 for (ii
=0; ii
<change
->argc
; ++ii
)
911 free((char*)change
->args
[ii
].u
.hostmask
);
912 mod_chanmode_free(change
);
913 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
917 static MODCMD_FUNC(cmd_clearmodes
)
919 struct mod_chanmode change
;
921 if (!channel
->modes
) {
922 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
925 mod_chanmode_init(&change
);
926 change
.modes_clear
= channel
->modes
;
927 modcmd_chanmode_announce(&change
);
928 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
932 static MODCMD_FUNC(cmd_deop
)
934 struct mod_chanmode
*change
;
935 unsigned int arg
, count
;
937 change
= mod_chanmode_alloc(argc
-1);
938 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
939 struct userNode
*victim
= GetUserH(argv
[arg
]);
941 if (!victim
|| IsService(victim
)
942 || !(mn
= GetUserMode(channel
, victim
))
943 || !(mn
->modes
& MODE_CHANOP
))
945 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
946 change
->args
[count
++].u
.member
= mn
;
949 change
->argc
= count
;
950 modcmd_chanmode_announce(change
);
952 mod_chanmode_free(change
);
953 reply("OSMSG_DEOP_DONE");
957 static MODCMD_FUNC(cmd_dehop
)
959 struct mod_chanmode
*change
;
960 unsigned int arg
, count
;
962 change
= mod_chanmode_alloc(argc
-1);
963 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
964 struct userNode
*victim
= GetUserH(argv
[arg
]);
966 if (!victim
|| IsService(victim
)
967 || !(mn
= GetUserMode(channel
, victim
))
968 || !(mn
->modes
& MODE_HALFOP
))
970 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
971 change
->args
[count
++].u
.member
= mn
;
974 change
->argc
= count
;
975 modcmd_chanmode_announce(change
);
977 mod_chanmode_free(change
);
978 reply("OSMSG_DEHOP_DONE");
982 static MODCMD_FUNC(cmd_deopall
)
984 struct mod_chanmode
*change
;
985 unsigned int ii
, count
;
987 change
= mod_chanmode_alloc(channel
->members
.used
);
988 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
989 struct modeNode
*mn
= channel
->members
.list
[ii
];
990 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
992 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
993 change
->args
[count
++].u
.member
= mn
;
996 change
->argc
= count
;
997 modcmd_chanmode_announce(change
);
999 mod_chanmode_free(change
);
1000 reply("OSMSG_DEOPALL_DONE", channel
->name
);
1004 static MODCMD_FUNC(cmd_dehopall
)
1006 struct mod_chanmode
*change
;
1007 unsigned int ii
, count
;
1009 change
= mod_chanmode_alloc(channel
->members
.used
);
1010 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1011 struct modeNode
*mn
= channel
->members
.list
[ii
];
1012 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
1014 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1015 change
->args
[count
++].u
.member
= mn
;
1018 change
->argc
= count
;
1019 modcmd_chanmode_announce(change
);
1021 mod_chanmode_free(change
);
1022 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
1026 static MODCMD_FUNC(cmd_resetmax
)
1028 max_clients
= dict_size(clients
);
1029 max_clients_time
= now
;
1030 reply("OSMSG_MAXUSERS_RESET", max_clients
);
1034 static MODCMD_FUNC(cmd_rehash
)
1036 extern char *services_config
;
1038 if (conf_read(services_config
))
1039 reply("OSMSG_REHASH_COMPLETE");
1041 reply("OSMSG_REHASH_FAILED");
1045 static MODCMD_FUNC(cmd_reopen
)
1048 reply("OSMSG_REOPEN_COMPLETE");
1052 static MODCMD_FUNC(cmd_reconnect
)
1054 reply("OSMSG_RECONNECTING");
1055 irc_squit(self
, "Reconnecting.", NULL
);
1059 static MODCMD_FUNC(cmd_jupe
)
1061 extern int force_n2k
;
1062 struct server
*newsrv
;
1064 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
1066 num
= atoi(argv
[2]);
1068 reply("OSMSG_INVALID_NUMERIC");
1071 if ((num
< 64) && !force_n2k
) {
1072 inttobase64(numeric
, num
, 1);
1073 inttobase64(numeric
+1, 64*64-1, 2);
1075 inttobase64(numeric
, num
, 2);
1076 inttobase64(numeric
+2, 64*64*64-1, 3);
1078 #ifdef WITH_PROTOCOL_P10
1079 if (GetServerN(numeric
)) {
1080 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
1084 if (GetServerH(argv
[1])) {
1085 reply("OSMSG_NAME_COLLIDE");
1088 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
1089 if(!strchr(argv
[1], '.')) {
1090 reply("OSMSG_INVALID_SERVERNAME");
1093 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
1095 reply("OSMSG_SRV_CREATE_FAILED");
1099 reply("OSMSG_SERVER_JUPED", argv
[1]);
1103 static MODCMD_FUNC(cmd_unjupe
)
1108 srv
= GetServerH(argv
[1]);
1110 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1113 if (strncmp(srv
->description
, "JUPE", 4)) {
1114 reply("OSMSG_SERVER_NOT_JUPE");
1117 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
1118 DelServer(srv
, 1, reason
);
1119 reply("OSMSG_SERVER_UNJUPED");
1123 static MODCMD_FUNC(cmd_jump
)
1125 extern struct cManagerNode cManager
;
1126 void uplink_select(char *name
);
1127 struct uplinkNode
*uplink_find(char *name
);
1128 struct uplinkNode
*uplink
;
1131 target
= unsplit_string(argv
+1, argc
-1, NULL
);
1133 if (!strcmp(cManager
.uplink
->name
, target
)) {
1134 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
1138 uplink
= uplink_find(target
);
1140 reply("OSMSG_INVALID_UPLINK", target
);
1143 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
1144 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
1148 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
1149 uplink_select(target
);
1150 irc_squit(self
, "Reconnecting.", NULL
);
1154 static MODCMD_FUNC(cmd_die
)
1156 char *reason
, *text
;
1158 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1159 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
1160 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
1161 irc_squit(self
, reason
, text
);
1166 static MODCMD_FUNC(cmd_restart
)
1168 extern int services_argc
;
1169 extern char **services_argv
;
1170 char **restart_argv
, *reason
, *text
;
1172 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1173 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
1174 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
1175 irc_squit(self
, reason
, text
);
1177 /* Append a NULL to the end of argv[]. */
1178 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
1179 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
1180 restart_argv
[services_argc
] = NULL
;
1185 execv(services_argv
[0], restart_argv
);
1187 /* If we're still here, that means something went wrong. Reconnect. */
1191 static struct gline
*
1192 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
, int silent
)
1194 char mask
[IRC_NTOP_MAX_SIZE
+3] = { '*', '@', '\0' };
1195 irc_ntop(mask
+ 2, sizeof(mask
) - 2, &target
->ip
);
1197 snprintf(reason
= alloca(MAXLEN
), MAXLEN
,
1198 "G-line requested by %s.", src_handle
);
1200 duration
= opserv_conf
.block_gline_duration
;
1201 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1, silent
? 1 : 0);
1204 static MODCMD_FUNC(cmd_block
)
1206 struct userNode
*target
;
1207 struct gline
*gline
;
1210 target
= GetUserH(argv
[1]);
1212 reply("MSG_NICK_UNKNOWN", argv
[1]);
1215 if (IsService(target
)) {
1216 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1219 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1220 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0, 0);
1221 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1225 static MODCMD_FUNC(cmd_gline
)
1227 unsigned long duration
;
1229 struct gline
*gline
;
1231 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1232 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1233 reply("MSG_INVALID_GLINE", argv
[1]);
1236 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1237 reply("OSMSG_STUPID_GLINE", argv
[1]);
1240 duration
= ParseInterval(argv
[2]);
1242 reply("MSG_INVALID_DURATION", argv
[2]);
1245 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1, 0);
1246 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1250 static MODCMD_FUNC(cmd_ungline
)
1252 if (gline_remove(argv
[1], 1))
1253 reply("OSMSG_GLINE_REMOVED", argv
[1]);
1255 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
1259 static MODCMD_FUNC(cmd_refreshg
)
1266 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1267 srv
= iter_data(it
);
1268 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1270 gline_refresh_server(srv
);
1271 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
1275 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1279 gline_refresh_all();
1280 reply("OSMSG_GLINES_REFRESHED");
1285 static struct shun
*
1286 opserv_shun(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
1289 mask
= alloca(MAXLEN
);
1290 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
1292 reason
= alloca(MAXLEN
);
1293 snprintf(reason
, MAXLEN
, "Shun requested by %s.", src_handle
);
1295 if (!duration
) duration
= opserv_conf
.block_shun_duration
;
1296 return shun_add(src_handle
, mask
, duration
, reason
, now
, 1);
1299 static MODCMD_FUNC(cmd_sblock
)
1301 struct userNode
*target
;
1305 target
= GetUserH(argv
[1]);
1307 reply("MSG_NICK_UNKNOWN", argv
[1]);
1310 if (IsService(target
)) {
1311 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1314 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1315 shun
= opserv_shun(target
, user
->handle_info
->handle
, reason
, 0);
1316 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1320 static MODCMD_FUNC(cmd_shun
)
1322 unsigned long duration
;
1326 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1327 if (!is_shun(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1328 reply("MSG_INVALID_SHUN", argv
[1]);
1331 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1332 reply("OSMSG_STUPID_SHUN", argv
[1]);
1335 duration
= ParseInterval(argv
[2]);
1337 reply("MSG_INVALID_DURATION", argv
[2]);
1340 shun
= shun_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
1341 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1345 static MODCMD_FUNC(cmd_unshun
)
1347 if (shun_remove(argv
[1], 1))
1348 reply("OSMSG_SHUN_REMOVED", argv
[1]);
1350 reply("OSMSG_SHUN_FORCE_REMOVED", argv
[1]);
1354 static MODCMD_FUNC(cmd_refreshs
)
1361 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1362 srv
= iter_data(it
);
1363 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1365 shun_refresh_server(srv
);
1366 reply("OSMSG_SHUNS_ONE_REFRESHED", srv
->name
);
1370 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1375 reply("OSMSG_SHUNS_REFRESHED");
1381 opserv_ison(struct userNode
*tell
, struct userNode
*target
, const char *message
)
1383 struct modeNode
*mn
;
1384 unsigned int count
, here_len
, n
, maxlen
;
1387 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
1389 maxlen
= MAX_LINE_SIZE
;
1390 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
1391 mn
= target
->channels
.list
[n
];
1392 here_len
= strlen(mn
->channel
->name
);
1393 if ((count
+ here_len
+ 4) > maxlen
) {
1395 send_message(tell
, opserv
, message
, buff
);
1398 if (mn
->modes
& MODE_CHANOP
)
1399 buff
[count
++] = '@';
1400 if (mn
->modes
& MODE_HALFOP
)
1401 buff
[count
++] = '%';
1402 if (mn
->modes
& MODE_VOICE
)
1403 buff
[count
++] = '+';
1404 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
1406 buff
[count
++] = ' ';
1410 send_message(tell
, opserv
, message
, buff
);
1414 static MODCMD_FUNC(cmd_inviteme
)
1416 struct userNode
*target
;
1421 target
= GetUserH(argv
[1]);
1423 reply("MSG_NICK_UNKNOWN", argv
[1]);
1427 if (opserv_conf
.debug_channel
== NULL
) {
1428 reply("OSMSG_NO_DEBUG_CHANNEL");
1431 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
1432 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1435 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1437 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1441 static MODCMD_FUNC(cmd_invite
)
1443 if (GetUserMode(channel
, user
)) {
1444 reply("OSMSG_ALREADY_THERE", channel
->name
);
1447 irc_invite(cmd
->parent
->bot
, user
, channel
);
1451 static MODCMD_FUNC(cmd_join
)
1453 struct userNode
*bot
= cmd
->parent
->bot
;
1455 if (!IsChannelName(argv
[1])) {
1456 reply("MSG_NOT_CHANNEL_NAME");
1458 } else if (!(channel
= GetChannel(argv
[1]))) {
1459 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1460 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1461 } else if (GetUserMode(channel
, bot
)) {
1462 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1465 struct mod_chanmode change
;
1466 mod_chanmode_init(&change
);
1468 change
.args
[0].mode
= MODE_CHANOP
;
1469 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1470 modcmd_chanmode_announce(&change
);
1472 irc_fetchtopic(bot
, channel
->name
);
1473 reply("OSMSG_JOIN_DONE", channel
->name
);
1477 static MODCMD_FUNC(cmd_kick
)
1479 struct userNode
*target
;
1483 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1484 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1486 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1488 target
= GetUserH(argv
[1]);
1490 reply("MSG_NICK_UNKNOWN", argv
[1]);
1493 if (!GetUserMode(channel
, target
)) {
1494 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1497 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1501 static MODCMD_FUNC(cmd_kickall
)
1503 unsigned int limit
, n
, inchan
;
1504 struct modeNode
*mn
;
1506 struct userNode
*bot
= cmd
->parent
->bot
;
1508 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1509 * channel, we have to join it in temporarily. */
1510 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1511 struct mod_chanmode change
;
1512 mod_chanmode_init(&change
);
1513 change
.args
[0].mode
= MODE_CHANOP
;
1514 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1515 modcmd_chanmode_announce(&change
);
1518 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1519 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1521 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1523 limit
= user
->handle_info
->opserv_level
;
1524 for (n
=channel
->members
.used
; n
>0;) {
1525 mn
= channel
->members
.list
[--n
];
1526 if (IsService(mn
->user
)
1527 || (mn
->user
->handle_info
1528 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1531 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1534 DelChannelUser(bot
, channel
, "My work here is done", 0);
1535 reply("OSMSG_KICKALL_DONE", channel
->name
);
1539 static MODCMD_FUNC(cmd_kickban
)
1541 struct mod_chanmode change
;
1542 struct userNode
*target
;
1547 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1548 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1550 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1552 target
= GetUserH(argv
[1]);
1554 reply("MSG_NICK_UNKNOWN", argv
[1]);
1557 if (!GetUserMode(channel
, target
)) {
1558 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1561 mod_chanmode_init(&change
);
1563 change
.args
[0].mode
= MODE_BAN
;
1564 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1565 modcmd_chanmode_announce(&change
);
1566 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1571 static MODCMD_FUNC(cmd_kickbanall
)
1573 struct modeNode
*mn
;
1574 struct userNode
*bot
= cmd
->parent
->bot
;
1575 struct mod_chanmode
*change
;
1577 unsigned int limit
, n
, inchan
;
1579 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1580 * channel, we have to join it in temporarily. */
1581 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1582 change
= mod_chanmode_alloc(2);
1583 change
->args
[0].mode
= MODE_CHANOP
;
1584 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1585 change
->args
[1].mode
= MODE_BAN
;
1586 change
->args
[1].u
.hostmask
= "*!*@*";
1588 change
= mod_chanmode_alloc(1);
1589 change
->args
[0].mode
= MODE_BAN
;
1590 change
->args
[0].u
.hostmask
= "*!*@*";
1592 modcmd_chanmode_announce(change
);
1593 mod_chanmode_free(change
);
1595 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1596 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1598 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1601 limit
= user
->handle_info
->opserv_level
;
1602 for (n
=channel
->members
.used
; n
>0; ) {
1603 mn
= channel
->members
.list
[--n
];
1604 if (IsService(mn
->user
)
1605 || (mn
->user
->handle_info
1606 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1609 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1612 DelChannelUser(bot
, channel
, "My work here is done", 0);
1613 reply("OSMSG_KICKALL_DONE", channel
->name
);
1617 static MODCMD_FUNC(cmd_part
)
1621 if (!IsChannelName(argv
[1])) {
1622 reply("MSG_NOT_CHANNEL_NAME");
1625 if ((channel
= GetChannel(argv
[1]))) {
1626 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1627 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1630 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1631 reply("OSMSG_LEAVING", channel
->name
);
1632 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1637 static MODCMD_FUNC(cmd_mode
)
1639 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1640 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1643 reply("OSMSG_MODE_SET", channel
->name
);
1647 static MODCMD_FUNC(cmd_op
)
1649 struct mod_chanmode
*change
;
1650 unsigned int arg
, count
;
1652 change
= mod_chanmode_alloc(argc
-1);
1653 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1654 struct userNode
*victim
;
1655 struct modeNode
*mn
;
1656 if (!(victim
= GetUserH(argv
[arg
])))
1658 if (!(mn
= GetUserMode(channel
, victim
)))
1660 if (mn
->modes
& MODE_CHANOP
)
1662 change
->args
[count
].mode
= MODE_CHANOP
;
1663 change
->args
[count
++].u
.member
= mn
;
1666 change
->argc
= count
;
1667 modcmd_chanmode_announce(change
);
1669 mod_chanmode_free(change
);
1670 reply("OSMSG_OP_DONE");
1674 static MODCMD_FUNC(cmd_hop
)
1676 struct mod_chanmode
*change
;
1677 unsigned int arg
, count
;
1679 change
= mod_chanmode_alloc(argc
-1);
1680 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1681 struct userNode
*victim
;
1682 struct modeNode
*mn
;
1683 if (!(victim
= GetUserH(argv
[arg
])))
1685 if (!(mn
= GetUserMode(channel
, victim
)))
1687 if (mn
->modes
& MODE_HALFOP
)
1689 change
->args
[count
].mode
= MODE_HALFOP
;
1690 change
->args
[count
++].u
.member
= mn
;
1693 change
->argc
= count
;
1694 modcmd_chanmode_announce(change
);
1696 mod_chanmode_free(change
);
1697 reply("OSMSG_HOP_DONE");
1701 static MODCMD_FUNC(cmd_opall
)
1703 struct mod_chanmode
*change
;
1704 unsigned int ii
, count
;
1706 change
= mod_chanmode_alloc(channel
->members
.used
);
1707 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1708 struct modeNode
*mn
= channel
->members
.list
[ii
];
1709 if (mn
->modes
& MODE_CHANOP
)
1711 change
->args
[count
].mode
= MODE_CHANOP
;
1712 change
->args
[count
++].u
.member
= mn
;
1715 change
->argc
= count
;
1716 modcmd_chanmode_announce(change
);
1718 mod_chanmode_free(change
);
1719 reply("OSMSG_OPALL_DONE", channel
->name
);
1723 static MODCMD_FUNC(cmd_hopall
)
1725 struct mod_chanmode
*change
;
1726 unsigned int ii
, count
;
1728 change
= mod_chanmode_alloc(channel
->members
.used
);
1729 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1730 struct modeNode
*mn
= channel
->members
.list
[ii
];
1731 if (mn
->modes
& MODE_HALFOP
)
1733 change
->args
[count
].mode
= MODE_HALFOP
;
1734 change
->args
[count
++].u
.member
= mn
;
1737 change
->argc
= count
;
1738 modcmd_chanmode_announce(change
);
1740 mod_chanmode_free(change
);
1741 reply("OSMSG_HOPALL_DONE", channel
->name
);
1745 static MODCMD_FUNC(cmd_whois
)
1747 struct userNode
*target
;
1751 #ifdef WITH_PROTOCOL_P10
1752 if (argv
[1][0] == '*')
1753 target
= GetUserN(argv
[1]+1);
1756 target
= GetUserH(argv
[1]);
1758 reply("MSG_NICK_UNKNOWN", argv
[1]);
1761 reply("OSMSG_WHOIS_NICK", target
->nick
);
1762 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
1763 if (IsFakeHost(target
))
1764 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
1765 reply("OSMSG_WHOIS_CRYPT_HOST", target
->crypthost
);
1766 reply("OSMSG_WHOIS_CRYPT_IP", target
->cryptip
);
1767 reply("OSMSG_WHOIS_IP", irc_ntoa(&target
->ip
));
1770 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
1771 reply("OSMSG_WHOIS_COUNTRY_CODE", target
->country_code
);
1772 reply("OSMSG_WHOIS_CITY", target
->city
);
1773 reply("OSMSG_WHOIS_REGION", target
->region
);
1775 reply("OSMSG_WHOIS_POSTAL_CODE", target
->postal_code
);
1776 reply("OSMSG_WHOIS_LATITUDE", target
->latitude
);
1777 reply("OSMSG_WHOIS_LONGITUDE", target
->longitude
);
1778 reply("OSMSG_WHOIS_DMA_CODE", target
->dma_code
);
1779 reply("OSMSG_WHOIS_AREA_CODE", target
->area_code
);
1780 } else if (target
->country_name
) {
1781 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
1784 if (target
->modes
) {
1786 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
1787 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
1788 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
1789 if (IsOper(target
)) buffer
[bpos
++] = 'o';
1790 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
1791 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
1793 // sethost - reed/apples
1794 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
1795 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
1797 if (IsService(target
)) buffer
[bpos
++] = 'k';
1798 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
1799 if (target
->handle_info
) buffer
[bpos
++] = 'r';
1800 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
1801 if (IsGagged(target
)) buffer_cat(" (gagged)");
1802 if (IsRegistering(target
)) buffer_cat(" (registered account)");
1805 reply("OSMSG_WHOIS_MODES", buffer
);
1807 reply("OSMSG_WHOIS_INFO", target
->info
);
1808 #ifdef WITH_PROTOCOL_P10
1809 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
1811 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
1812 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
1813 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
1814 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
1815 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
1816 opserv_ison(user
, target
, "OSMSG_WHOIS_CHANNELS");
1818 reply("OSMSG_WHOIS_HIDECHANS");
1822 static MODCMD_FUNC(cmd_unban
)
1824 struct mod_chanmode change
;
1825 mod_chanmode_init(&change
);
1827 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
1828 change
.args
[0].u
.hostmask
= argv
[1];
1829 modcmd_chanmode_announce(&change
);
1830 reply("OSMSG_UNBAN_DONE", channel
->name
);
1834 static MODCMD_FUNC(cmd_voiceall
)
1836 struct mod_chanmode
*change
;
1837 unsigned int ii
, count
;
1839 change
= mod_chanmode_alloc(channel
->members
.used
);
1840 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1841 struct modeNode
*mn
= channel
->members
.list
[ii
];
1842 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
1844 change
->args
[count
].mode
= MODE_VOICE
;
1845 change
->args
[count
++].u
.member
= mn
;
1848 change
->argc
= count
;
1849 modcmd_chanmode_announce(change
);
1851 mod_chanmode_free(change
);
1852 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
1856 static MODCMD_FUNC(cmd_devoiceall
)
1858 struct mod_chanmode
*change
;
1859 unsigned int ii
, count
;
1861 change
= mod_chanmode_alloc(channel
->members
.used
);
1862 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1863 struct modeNode
*mn
= channel
->members
.list
[ii
];
1864 if (!(mn
->modes
& MODE_VOICE
))
1866 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
1867 change
->args
[count
++].u
.member
= mn
;
1870 change
->argc
= count
;
1871 modcmd_chanmode_announce(change
);
1873 mod_chanmode_free(change
);
1874 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
1878 static MODCMD_FUNC(cmd_stats_bad
) {
1880 unsigned int ii
, end
, here_len
;
1883 /* Show the bad word list.. */
1884 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
1885 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
1886 here_len
= strlen(opserv_bad_words
->list
[ii
]);
1887 /* If the line is full output it & start again */
1888 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1890 reply("OSMSG_BADWORD_LIST", buffer
);
1893 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
1895 buffer
[end
++] = ' ';
1898 reply("OSMSG_BADWORD_LIST", buffer
);
1900 /* Show the exemption list.. */
1901 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
1902 here_len
= strlen(iter_key(it
));
1903 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
1905 reply("OSMSG_EXEMPTED_LIST", buffer
);
1908 memcpy(buffer
+end
, iter_key(it
), here_len
);
1910 buffer
[end
++] = ' ';
1913 reply("OSMSG_EXEMPTED_LIST", buffer
);
1917 static MODCMD_FUNC(cmd_stats_glines
) {
1918 reply("OSMSG_GLINE_COUNT", gline_count());
1922 static MODCMD_FUNC(cmd_stats_shuns
) {
1923 reply("OSMSG_SHUN_COUNT", shun_count());
1928 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
1929 unsigned int nn
, pos
;
1932 for (nn
=1; nn
<=depth
; nn
<<=1) ;
1933 for (pos
=0, nn
>>=1; nn
>1; ) {
1935 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
1936 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
1939 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
1940 if (!server
->children
.used
)
1942 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
1943 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
1945 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
1948 static MODCMD_FUNC(cmd_stats_links
) {
1949 trace_links(cmd
->parent
->bot
, user
, self
, 1);
1954 static MODCMD_FUNC(cmd_stats_max
) {
1955 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
1959 static MODCMD_FUNC(cmd_stats_network
) {
1960 struct helpfile_table tbl
;
1961 unsigned int nn
, tot_clients
;
1964 tot_clients
= dict_size(clients
);
1965 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
1966 tbl
.length
= dict_size(servers
)+1;
1968 tbl
.flags
= TABLE_NO_FREE
;
1969 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
1970 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1971 tbl
.contents
[0][0] = "Server Name";
1972 tbl
.contents
[0][1] = "Clients";
1973 tbl
.contents
[0][2] = "Load";
1974 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
1975 struct server
*server
= iter_data(it
);
1976 char *buffer
= malloc(32);
1977 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
1978 tbl
.contents
[nn
][0] = server
->name
;
1979 tbl
.contents
[nn
][1] = buffer
;
1980 sprintf(buffer
, "%u", server
->clients
);
1981 tbl
.contents
[nn
][2] = buffer
+ 16;
1982 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
1985 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
1986 for (nn
=1; nn
<tbl
.length
; nn
++) {
1987 free((char*)tbl
.contents
[nn
][1]);
1988 free(tbl
.contents
[nn
]);
1990 free(tbl
.contents
[0]);
1995 static MODCMD_FUNC(cmd_stats_network2
) {
1996 struct helpfile_table tbl
;
2000 tbl
.length
= dict_size(servers
)+1;
2002 tbl
.flags
= TABLE_NO_FREE
;
2003 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2004 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2005 tbl
.contents
[0][0] = "Server Name";
2006 tbl
.contents
[0][1] = "Numeric";
2007 tbl
.contents
[0][2] = "Link Time";
2008 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2009 struct server
*server
= iter_data(it
);
2010 char *buffer
= malloc(64);
2013 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2014 tbl
.contents
[nn
][0] = server
->name
;
2015 #ifdef WITH_PROTOCOL_P10
2016 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
2020 tbl
.contents
[nn
][1] = buffer
;
2021 ofs
= strlen(buffer
) + 1;
2022 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
2023 if (server
->self_burst
)
2024 strcat(buffer
+ ofs
, " Bursting");
2025 tbl
.contents
[nn
][2] = buffer
+ ofs
;
2028 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2029 for (nn
=1; nn
<tbl
.length
; nn
++) {
2030 free((char*)tbl
.contents
[nn
][1]);
2031 free(tbl
.contents
[nn
]);
2033 free(tbl
.contents
[0]);
2038 static MODCMD_FUNC(cmd_stats_reserved
) {
2041 reply("OSMSG_RESERVED_LIST");
2042 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
2043 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
2047 static MODCMD_FUNC(cmd_stats_trusted
) {
2049 struct trusted_host
*th
;
2050 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
2052 reply("OSMSG_TRUSTED_LIST");
2053 reply("OSMSG_TRUSTED_LIST_BAR");
2054 reply("OSMSG_TRUSTED_LIST_HEADER");
2055 reply("OSMSG_TRUSTED_LIST_BAR");
2057 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2060 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2062 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2064 sprintf(limit
, "%lu", th
->limit
);
2065 reply("OSMSG_HOST_IS_TRUSTED",
2067 (th
->limit
? limit
: "none"),
2068 (th
->issuer
? th
->issuer
: "<unknown>"),
2069 (th
->issued
? issued
: "some time"),
2070 (th
->expires
? length
: "never"));
2071 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2073 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
2076 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2079 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2081 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2083 sprintf(limit
, "%lu", th
->limit
);
2084 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
2085 (th
->limit
? limit
: "none"),
2086 (th
->issuer
? th
->issuer
: "<unknown>"),
2087 (th
->issued
? issued
: "some time"),
2088 (th
->expires
? length
: "never"));
2089 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2092 reply("OSMSG_TRUSTED_LIST_END");
2096 static MODCMD_FUNC(cmd_stats_uplink
) {
2097 extern struct cManagerNode cManager
;
2098 struct uplinkNode
*uplink
;
2100 uplink
= cManager
.uplink
;
2101 reply("OSMSG_UPLINK_START", uplink
->name
);
2102 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
2106 static MODCMD_FUNC(cmd_stats_uptime
) {
2107 char uptime
[INTERVALLEN
];
2109 extern time_t boot_time
;
2110 extern int lines_processed
;
2111 static long clocks_per_sec
;
2113 if (!clocks_per_sec
) {
2114 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
2115 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
2116 if (clocks_per_sec
<= 0)
2119 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
2120 clocks_per_sec
= CLOCKS_PER_SEC
;
2123 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
2125 reply("OSMSG_UPTIME_STATS",
2126 uptime
, lines_processed
,
2127 buf
.tms_utime
/(double)clocks_per_sec
,
2128 buf
.tms_stime
/(double)clocks_per_sec
);
2132 static MODCMD_FUNC(cmd_stats_alerts
) {
2134 struct opserv_user_alert
*alert
;
2135 const char *reaction
;
2137 reply("OSMSG_ALERTS_LIST");
2138 reply("OSMSG_ALERTS_BAR");
2139 reply("OSMSG_ALERTS_HEADER");
2140 reply("OSMSG_ALERTS_BAR");
2141 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2142 alert
= iter_data(it
);
2143 switch (alert
->reaction
) {
2144 case REACT_NOTICE
: reaction
= "notice"; break;
2145 case REACT_KILL
: reaction
= "kill"; break;
2146 // case REACT_SILENT: reaction = "silent"; break;
2147 case REACT_GLINE
: reaction
= "gline"; break;
2148 case REACT_TRACK
: reaction
= "track"; break;
2149 case REACT_SHUN
: reaction
= "shun"; break;
2150 default: reaction
= "<unknown>"; break;
2152 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
2153 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
2155 reply("OSMSG_ALERT_END");
2159 static MODCMD_FUNC(cmd_stats_gags
) {
2160 struct gag_entry
*gag
;
2161 struct helpfile_table table
;
2165 reply("OSMSG_NO_GAGS");
2168 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
2169 table
.length
= nn
+1;
2171 table
.flags
= TABLE_NO_FREE
;
2172 table
.contents
= calloc(table
.length
, sizeof(char**));
2173 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
2174 table
.contents
[0][0] = "Mask";
2175 table
.contents
[0][1] = "Owner";
2176 table
.contents
[0][2] = "Expires";
2177 table
.contents
[0][3] = "Reason";
2178 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
2179 char expstr
[INTERVALLEN
];
2181 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
2183 strcpy(expstr
, "Never");
2184 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
2185 table
.contents
[nn
][0] = gag
->mask
;
2186 table
.contents
[nn
][1] = gag
->owner
;
2187 table
.contents
[nn
][2] = strdup(expstr
);
2188 table
.contents
[nn
][3] = gag
->reason
;
2190 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
2191 for (nn
=1; nn
<table
.length
; nn
++) {
2192 free((char*)table
.contents
[nn
][2]);
2193 free(table
.contents
[nn
]);
2195 free(table
.contents
[0]);
2196 free(table
.contents
);
2200 static MODCMD_FUNC(cmd_stats_timeq
) {
2201 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
2206 static MODCMD_FUNC(cmd_stats_warn) {
2209 reply("OSMSG_WARN_LISTSTART");
2210 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
2211 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
2212 reply("OSMSG_WARN_LISTEND");
2217 #if defined(WITH_MALLOC_X3)
2218 static MODCMD_FUNC(cmd_stats_memory
) {
2219 extern unsigned long alloc_count
, alloc_size
;
2220 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2221 "%u allocations totalling %u bytes.",
2222 alloc_count
, alloc_size
);
2225 #elif defined(WITH_MALLOC_SLAB)
2226 static MODCMD_FUNC(cmd_stats_memory
) {
2227 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
2228 extern unsigned long big_alloc_count
, big_alloc_size
;
2229 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2230 "%u allocations in %u slabs totalling %u bytes.",
2231 slab_alloc_count
, slab_count
, slab_alloc_size
);
2232 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2233 "%u big allocations totalling %u bytes.",
2234 big_alloc_count
, big_alloc_size
);
2239 static MODCMD_FUNC(cmd_dump
)
2241 char linedup
[MAXLEN
], original
[MAXLEN
];
2243 unsplit_string(argv
+1, argc
-1, original
);
2244 safestrncpy(linedup
, original
, sizeof(linedup
));
2245 /* assume it's only valid IRC if we can parse it */
2246 if (parse_line(linedup
, 1)) {
2248 reply("OSMSG_LINE_DUMPED");
2250 reply("OSMSG_RAW_PARSE_ERROR");
2254 static MODCMD_FUNC(cmd_raw
)
2256 char linedup
[MAXLEN
], original
[MAXLEN
];
2258 unsplit_string(argv
+1, argc
-1, original
);
2259 safestrncpy(linedup
, original
, sizeof(linedup
));
2260 /* Try to parse the line before sending it; if it's too wrong,
2261 * maybe it will core us instead of our uplink. */
2262 parse_line(linedup
, 1);
2264 reply("OSMSG_LINE_DUMPED");
2268 static struct userNode
*
2269 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
2271 struct userNode
*resv
= GetUserH(nick
);
2273 if (IsService(resv
)) {
2274 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
2277 if (resv
->handle_info
2278 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
2279 reply("OSMSG_LEVEL_TOO_LOW");
2283 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
2284 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
2289 static MODCMD_FUNC(cmd_collide
)
2291 struct userNode
*resv
;
2293 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2295 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
2298 reply("OSMSG_CLONE_FAILED", argv
[1]);
2303 static MODCMD_FUNC(cmd_reserve
)
2305 struct userNode
*resv
;
2307 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2309 resv
->modes
|= FLAGS_PERSISTENT
;
2310 reply("OSMSG_RESERVED_NICK", resv
->nick
);
2313 reply("OSMSG_CLONE_FAILED", argv
[1]);
2319 free_reserve(char *nick
)
2321 struct userNode
*resv
;
2325 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
2329 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
2330 reason
= alloca(rlen
);
2331 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
2332 DelUser(resv
, NULL
, 1, reason
);
2333 dict_remove(opserv_reserved_nick_dict
, nick
);
2337 static MODCMD_FUNC(cmd_unreserve
)
2339 if (free_reserve(argv
[1]))
2340 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
2342 reply("OSMSG_NOT_RESERVED", argv
[1]);
2347 opserv_part_channel(void *data
)
2349 DelChannelUser(opserv
, data
, "Leaving.", 0);
2352 static int alert_check_user(const char *key
, void *data
, void *extra
);
2355 opserv_new_user_check(struct userNode
*user
)
2357 struct opserv_hostinfo
*ohi
;
2358 struct gag_entry
*gag
;
2359 char addr
[IRC_NTOP_MAX_SIZE
];
2361 /* Check to see if we should ignore them entirely. */
2362 if (IsLocal(user
) || IsService(user
))
2365 /* Check for alerts, and stop if we find one that kills them. */
2366 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
2369 /* Gag them if appropriate. */
2370 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2371 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
2372 gag_helper_func(user
, NULL
);
2377 /* Add to host info struct */
2378 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2379 if (!(ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2380 ohi
= calloc(1, sizeof(*ohi
));
2381 dict_insert(opserv_hostinfo_dict
, strdup(addr
), ohi
);
2382 userList_init(&ohi
->clients
);
2384 userList_append(&ohi
->clients
, user
);
2386 /* Only warn of new user floods outside of bursts. */
2387 if (!user
->uplink
->burst
) {
2388 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
2389 if (!new_user_flood
) {
2391 opserv_alert("Warning: Possible new-user flood.");
2398 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
)) {
2399 irc_kill(opserv
, user
, DefConGlineReason
);
2403 if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS
)) && !IsOper(user
)) {
2404 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2406 strcpy(target
+ 2, user
->hostname
);
2407 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
2408 gline_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1, 0);
2409 else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
2410 shun_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1);
2415 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
2416 if (opserv_conf
.untrusted_max
2417 && irc_in_addr_is_valid(user
->ip
)
2418 && !irc_in_addr_is_loopback(user
->ip
)) {
2419 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, addr
, NULL
);
2420 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
2422 if (checkDefCon(DEFCON_REDUCE_SESSION
) && !th
)
2423 limit
= DefConSessionLimit
;
2426 /* 0 means unlimited hosts */
2427 } else if (ohi
->clients
.used
== limit
) {
2429 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
2430 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
2431 } else if (ohi
->clients
.used
> limit
) {
2432 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2433 strcpy(target
+ 2, addr
);
2434 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "Excessive connections from a single host.", now
, 1, 1);
2442 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
2444 struct opserv_hostinfo
*ohi
;
2445 char addr
[IRC_NTOP_MAX_SIZE
];
2447 if (IsLocal(user
)) {
2448 /* Try to remove it from the reserved nick dict without
2449 * calling free_reserve, because that would call DelUser(),
2450 * and we'd loop back to here. */
2451 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
2454 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2455 if ((ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2456 userList_remove(&ohi
->clients
, user
);
2457 if (ohi
->clients
.used
== 0)
2458 dict_remove(opserv_hostinfo_dict
, addr
);
2463 opserv_bad_channel(const char *name
)
2468 dict_find(opserv_exempt_channels
, name
, &present
);
2472 if (gline_find(name
))
2475 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
2476 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
2483 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
2485 struct mod_chanmode
*change
;
2488 change
= mod_chanmode_alloc(2);
2489 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2490 change
->args
[0].mode
= MODE_CHANOP
;
2491 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2492 change
->args
[1].mode
= MODE_BAN
;
2493 change
->args
[1].u
.hostmask
= "*!*@*";
2494 mod_chanmode_announce(opserv
, channel
, change
);
2495 mod_chanmode_free(change
);
2496 for (nn
=channel
->members
.used
; nn
>0; ) {
2497 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2498 if (IsService(mNode
->user
))
2500 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2502 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2506 opserv_channel_check(struct chanNode
*newchan
)
2510 if (!newchan
->join_policer
.params
) {
2511 newchan
->join_policer
.last_req
= now
;
2512 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2515 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2516 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning);
2520 /* Wait until the join check to shut channels down. */
2521 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2525 opserv_channel_delete(struct chanNode
*chan
)
2527 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2531 opserv_join_check(struct modeNode
*mNode
)
2533 struct userNode
*user
= mNode
->user
;
2534 struct chanNode
*channel
= mNode
->channel
;
2537 if (IsService(user
))
2540 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2542 if (channel
->bad_channel
) {
2543 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2544 if (channel
->name
[0] != '#')
2545 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2546 else if (!GetUserMode(channel
, opserv
))
2547 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2549 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2550 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2551 KickChannelUser(user
, channel
, opserv
, msg
);
2556 if (user
->uplink
->burst
)
2558 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2559 channel
->join_flooded
= 0;
2562 if (!channel
->join_flooded
) {
2563 /* Don't moderate the channel unless it is activated and
2564 the number of users in the channel is over the threshold. */
2565 struct mod_chanmode change
;
2566 mod_chanmode_init(&change
);
2567 channel
->join_flooded
= 1;
2568 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2569 if (!GetUserMode(channel
, opserv
)) {
2570 /* If we aren't in the channel, join it. */
2571 change
.args
[0].mode
= MODE_CHANOP
;
2572 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2575 if (!(channel
->modes
& MODE_MODERATED
))
2576 change
.modes_set
|= MODE_MODERATED
;
2577 if (change
.modes_set
|| change
.argc
)
2578 mod_chanmode_announce(opserv
, channel
, &change
);
2579 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2580 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2582 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2585 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2590 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2591 unsigned int bad_idx
;
2593 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2594 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2595 if (irccasestr(new_bad
, orig_bad
)) {
2597 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2599 } else if (irccasestr(orig_bad
, new_bad
)) {
2601 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2603 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2604 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2605 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2606 if (!irccasestr(orig_bad
, new_bad
))
2609 reply("OSMSG_BAD_NUKING", orig_bad
);
2610 string_list_delete(opserv_bad_words
, bad_idx
);
2617 string_list_append(opserv_bad_words
, strdup(new_bad
));
2619 reply("OSMSG_ADDED_BAD", new_bad
);
2624 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
)
2626 struct routingPlanServer
*rps
;
2627 rps
= calloc(1, sizeof(*rps
));
2630 /* duplicate servers replace */
2631 rps
->uplink
= strdup(uplink
);
2633 rps
->secondaryuplink
= strdup(second
);
2635 rps
->secondaryuplink
= NULL
;
2636 rps
->port
= port
? port
: 4400; /* lame hardcodede default port. maybe get from config file somewhere? */
2638 rps
->offline
= offline
; /* 1 = yes, 0 = no */
2639 dict_insert(rp
->servers
, strdup(name
), rps
);
2640 log_module(OS_LOG
, LOG_DEBUG
, "Adding rp server %s with uplink %s", name
, uplink
);
2645 free_routing_plan_server(void *data
)
2647 struct routingPlanServer
*rps
= data
;
2649 if(rps
->secondaryuplink
)
2650 free(rps
->secondaryuplink
);
2655 opserv_add_routing_plan(const char *name
)
2657 struct routingPlan
*rp
;
2658 rp
= calloc(1, sizeof(*rp
));
2661 if(dict_find(opserv_routing_plans
, name
, NULL
))
2662 return NULL
; /* plan already exists */
2663 rp
->servers
= dict_new();
2664 dict_set_free_data(rp
->servers
, free_routing_plan_server
);
2666 dict_insert(opserv_routing_plans
, strdup(name
), rp
);
2667 /* TODO: check for duplicate */
2672 free_routing_plan(void *data
)
2674 struct routingPlan
*rp
= data
;
2675 /* delete all the servers attached to this plan */
2676 dict_delete(rp
->servers
);
2677 /* free the plan struct */
2681 /*************************************************
2682 * Functions to handle the active routing struct */
2685 *find_routeList_server(struct route
*route
, const char *server
)
2687 struct routeList
*rptr
;
2690 for(rptr
= route
->servers
;rptr
;rptr
=rptr
->next
) {
2691 if(!strcasecmp(rptr
->server
, server
))
2697 /* Wipes out the routing structure, freeing properly.
2698 * note: does NOT free itself, we just re-use it usually.*/
2700 wipe_route_list(struct route
*route
) {
2701 struct routeList
*nextptr
, *rptr
;
2704 for(rptr
= opserv_route
->servers
; rptr
; rptr
=nextptr
)
2706 nextptr
= rptr
->next
;
2710 if(rptr
->secondaryuplink
)
2711 free(rptr
->secondaryuplink
);
2714 route
->centered
= true;
2716 route
->maxdepth
= 0;
2717 route
->servers
= NULL
;
2722 rank_outside_rec(struct route
*route
, char *server
, int count
)
2724 struct routeList
*rptr
;
2727 if(count
> 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */
2730 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
2732 if(!strcasecmp(server
, rptr
->uplink
)) {
2733 log_module(MAIN_LOG
, LOG_DEBUG
, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count
, i
, rptr
->server
, rptr
->uplink
);
2734 n
= rank_outside_rec(route
, rptr
->server
, count
+1);
2735 if(n
< 0) /* handle error condition */
2741 if((rptr
= find_routeList_server(route
, server
))) {
2742 rptr
->outsideness
= max
;
2746 log_module(MAIN_LOG
, LOG_ERROR
, "routing struct rank_outsideness() couldnt find %s", server
);
2752 rank_outsideness(struct route
*route
)
2754 log_module(MAIN_LOG
, LOG_DEBUG
, "rank_outsideness(): Running...");
2755 route
->maxdepth
= rank_outside_rec(route
, self
->uplink
->name
, 0) - 1;
2756 if(route
->maxdepth
< 0) { /* if the rank failed, remove route */
2757 log_module(MAIN_LOG
, LOG_WARNING
, "The active routing plan has a loop! auto routing disabled.");
2758 wipe_route_list(route
);
2765 /* Add servers to the routing structure */
2767 add_routestruct_server(struct route
*route
, const char *server
, unsigned int port
, char *uplink
, char *secondary
)
2769 struct routeList
*rptr
;
2771 if(find_routeList_server(route
, server
))
2773 log_module(MAIN_LOG
, LOG_WARNING
, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server
);
2776 rptr
= calloc(1, sizeof(*rptr
));
2777 rptr
->server
= strdup(server
);
2780 hname
= conf_get_data("server/hostname", RECDB_QSTRING
);
2783 rptr
->uplink
= strdup(uplink
);
2785 rptr
->secondaryuplink
= strdup(secondary
);
2786 /* tack this server on the front of the list */
2787 rptr
->next
= route
->servers
;
2788 route
->servers
= rptr
;
2791 #ifdef notdef /* I dont quite get this. there could be uncentered things
2792 * added after our own uplink, and this function doesnt center
2793 * as it adds. -Rubin */
2794 /* If the map hasnt been centered yet... */
2795 if(route
->centered
== false) {
2796 /* AND we just added our own uplink to it... */
2797 if(!strcasecmp(server
, self
->uplink
->name
)) {
2798 change_route_uplinks(route
); /* recenter it, n mark it centered. */
2804 /* Recenter the routing struct around our current uplink */
2806 change_route_uplinks(struct route
*route
)
2808 struct routeList
*rptr
;
2809 char lastserver
[MAXLEN
];
2810 char nextserver
[MAXLEN
];
2813 return false; /* no map to recenter */
2814 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks(): running...");
2815 char *servicename
= conf_get_data("server/hostname", RECDB_QSTRING
);
2816 strcpy(lastserver
, servicename
);
2817 rptr
= find_routeList_server(route
, self
->uplink
->name
);
2819 log_module(MAIN_LOG
, LOG_ERROR
, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered.");
2820 route
->centered
= false;
2823 if(!strcasecmp(rptr
->uplink
, servicename
)) {
2824 log_module(MAIN_LOG
, LOG_DEBUG
, "Already centered");
2826 else { /* else, center it */
2828 strcpy(nextserver
, rptr
->uplink
);
2829 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks() changing %s uplink to %s.", rptr
->server
, lastserver
);
2831 rptr
->uplink
= strdup(lastserver
);
2832 strcpy(lastserver
, rptr
->server
);
2833 rptr
= find_routeList_server(route
, nextserver
);
2836 if(rank_outsideness(route
) > 0) {
2837 route
->centered
= true;
2845 activate_routing(struct svccmd
*cmd
, struct userNode
*user
, char *plan_name
)
2847 static struct routingPlan
*rp
;
2851 if(plan_name
) { /* make this the new active plan */
2852 if(!strcmp(plan_name
, "*")) {
2853 /* disable routing */
2854 dict_remove(opserv_routing_plan_options
, "ACTIVE");
2858 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
2861 reply("OSMSG_PLAN_NOT_FOUND", plan_name
);
2863 /* since it doesnt exist, remove the active setting */
2864 dict_remove(opserv_routing_plan_options
, plan_name
);
2866 log_module(MAIN_LOG
, LOG_ERROR
, "activate_routing() couldnt find active routing plan!");
2871 else { /* find the active plan in settings */
2872 plan_name
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
2874 if(!plan_name
) { /* deactivated, or no plan was set active */
2875 /* TODO: delete routing map if it exists */
2876 wipe_route_list(opserv_route
);
2880 karma
= dict_find(opserv_routing_plan_options
, "KARMA", NULL
);
2882 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
2884 /* this should really be done during opserv init */
2886 opserv_route
= calloc(1, sizeof(*opserv_route
));
2888 /* Delete the existing active route */
2889 wipe_route_list(opserv_route
);
2891 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
2892 const char* servername
= iter_key(it
);
2893 struct routingPlanServer
*rps
= iter_data(it
),
2894 *rp_uplink
, *rp_second
= NULL
;
2895 char *uplink
= rps
->uplink
;
2896 rp_uplink
= dict_find(rp
->servers
, rps
->uplink
, NULL
);
2897 if(rps
->secondaryuplink
)
2898 rp_second
= dict_find(rp
->servers
, rps
->secondaryuplink
, NULL
);
2900 /* If the normal uplink has bad karma, don't use it as a hub,
2901 * switch to the secondary uplink.
2903 if(karma
&& enabled_string(karma
) && rp_uplink
&& rp_uplink
->karma
< 0) {
2904 if(rps
->secondaryuplink
) {
2905 uplink
= rps
->secondaryuplink
;
2906 /* unless the secondary uplinks karma is worse than the uplink. */
2907 if((rp_second
= dict_find(rp
->servers
, uplink
, NULL
)) && rp_second
->karma
< rp_uplink
->karma
)
2908 uplink
= rps
->uplink
;
2912 * If _WE_ have bad karma, don't link us to our normal uplink, maybe
2913 * its a bad route. switch to secondary. Important: dont neg karma when we arnt on
2914 * our primary uplink, or we'll get stuck on secondary when THAT link is worse.
2916 if(karma
&& enabled_string(karma
) && (rps
->karma
< 0 || rps
->offline
) ) {
2917 if(rps
->secondaryuplink
) {
2918 uplink
= rps
->secondaryuplink
;
2921 log_module(MAIN_LOG
, LOG_DEBUG
, "activate_routing() adding %s:%d %s", servername
, rps
->port
, uplink
);
2922 add_routestruct_server(opserv_route
, servername
, rps
->port
, uplink
, NULL
);
2924 if(change_route_uplinks(opserv_route
))
2927 reply("OSMSG_ROUTING_ACTIVATION_ERROR");
2928 activate_routing(cmd
, user
, "*");
2934 /*******************************************************
2935 * Functions to handle online route configuration via opserv
2937 static void route_show_option(struct svccmd
*cmd
, struct userNode
*user
, char *name
)
2939 char *value
= dict_find(opserv_routing_plan_options
, name
, NULL
);
2941 if(!strcmp("RETRY_PERIOD", name
)) { /* Show as an interval */
2942 char buff
[INTERVALLEN
+1];
2943 reply("OSMSG_ROUTINGPLAN_OPTION", name
, intervalString(buff
, atoi(value
), user
->handle_info
));
2945 else if(!strcmp("ACTIVE", name
)) {
2946 if(opserv_route
&& opserv_route
->servers
)
2947 reply("OSMSG_ROUTINGPLAN_ACTIVE", value
);
2949 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
2952 reply("OSMSG_ROUTINGPLAN_OPTION", name
, value
);
2956 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
2960 static void route_show_options(struct svccmd
*cmd
, struct userNode
*user
)
2962 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
2964 for(i
= 0; options
[i
]; i
++) {
2965 route_show_option(cmd
, user
, options
[i
]);
2969 /* called from timeq */
2970 void routing_connect_timeout(void *data
)
2972 struct waitingConnection
*wc
= data
;
2973 struct server
*target
= GetServerH(wc
->target
);
2975 dict_remove(opserv_waiting_connections
, wc
->server
);
2976 return; /* server we wanted to connect new server to is gone, just give up */
2978 routing_handle_connect_failure(target
, wc
->server
, "Connection timed out");
2979 /* the following invalidates server variable! */
2980 dict_remove(opserv_waiting_connections
, wc
->server
);
2983 void routing_delete_connect_timer(char *server
)
2985 struct waitingConnection
*wc
= dict_find(opserv_waiting_connections
, server
, 0);
2987 timeq_del(0, routing_connect_timeout
, wc
, TIMEQ_IGNORE_WHEN
);
2988 dict_remove(opserv_waiting_connections
, server
);
2994 routing_connect_server(char *server
, int port
, struct server
*to
)
2996 struct waitingConnection
*wc
= calloc(sizeof(*wc
), 1);
2998 wc
->server
= strdup(server
);
2999 wc
->target
= strdup(to
->name
);
3000 dict_insert(opserv_waiting_connections
, strdup(server
), wc
);
3001 timeq_add(now
+ ROUTING_CONNECT_TIMEOUT
, routing_connect_timeout
, wc
);
3003 irc_connect(opserv
, server
, port
, to
);
3007 routing_connect_one(struct route
*route
, char *server
)
3009 struct routeList
*rptr
;
3010 struct server
*sptr
, *suptr
;
3011 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3012 if(!strcasecmp(rptr
->server
, server
)) {
3013 /* this is the one, connect it */
3014 suptr
= GetServerH(rptr
->uplink
);
3015 sptr
= GetServerH(rptr
->server
);
3017 return 1; /* already linked */
3019 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3020 return 1; /* attempted link */
3022 return 0; /* its uplink isnt here to link to */
3025 log_module(MAIN_LOG
, LOG_DEBUG
, "Tried to link %s but its not in the active routing struct!", server
);
3026 return 0; /* server wasnt found in active route struct. */
3029 int routing_connect_children(struct route
*route
, char *server
)
3031 struct routeList
*rptr
;
3032 struct server
*sptr
, *suptr
;
3033 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3034 if(!strcasecmp(rptr
->uplink
, server
)) {
3035 /* this is the one, connect it */
3036 suptr
= GetServerH(rptr
->uplink
);
3037 sptr
= GetServerH(rptr
->server
);
3039 continue; /* already linked */
3041 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3042 continue; /* attempted link */
3044 continue; /* its uplink isnt here to link to */
3047 return 1; /* server wasnt found in active route struct ?! */
3050 int reroute(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
, char *directive
)
3052 struct routeList
*rptr
;
3053 struct server
*sptr
, *suptr
;
3054 int connect
= 0, move
= 0, missing
= 0, i
;
3055 char d
= toupper(*directive
);
3057 if(!route
|| !route
->servers
) {
3058 reply("OSMSG_REROUTING_NOTCONFIGURED");
3062 if(d
== 'N') { /* normal */
3063 irc_wallops("%s", "Attempting a reroute of the network according to loaded map...");
3064 reply("OSMSG_REROUTING_ACC_MAP");
3066 else if(d
== 'C') { /* only connect */
3067 reply("OSMSG_CONNECTING_MISSING_ONLY");
3069 else if(d
== 'T') { /* test */
3070 reply("OSMSG_TESTING_REROUTE");
3074 reply("OSMSG_INVALID_DIRECTIVE", directive
);
3078 for(i
= 0; i
<= route
->maxdepth
-1; i
++) {
3079 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3080 if(rptr
->outsideness
== i
) {
3083 reply("OSMSG_INSPECTING_SERVER", rptr
->server
);
3084 suptr
= GetServerH(rptr
->uplink
);
3086 if(rptr
->secondaryuplink
&& (suptr
= GetServerH(rptr
->secondaryuplink
))) {
3088 reply("OSMSG_COULDNT_FIND_SERVER", rptr
->uplink
, rptr
->secondaryuplink
, rptr
->server
);
3091 if(suptr
) { /* if the proper uplink is connected.. */
3092 sptr
= GetServerH(rptr
->server
);
3093 if(d
== 'C' && sptr
) {
3094 continue; /* Already linked */
3096 /* If server is missing or the uplinks are not the same then... */
3097 else if(!sptr
|| strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3101 else { /* Server is already connected somewhere */
3102 if(strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3103 if(d
!= 'T') { /* do it for real */
3104 irc_squit_route(sptr
, "%s issued reroute.", user
? user
->nick
: opserv
->nick
);
3106 else { /* just pretend */
3107 reply("OSMSG_SQUIT", rptr
->server
);
3112 if(d
!= 'T') /* do the real thing */
3113 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3114 else /* just pretend */
3115 reply("OSMSG_CONNECT", rptr
->server
, rptr
->port
, suptr
->name
);
3119 log_module(MAIN_LOG
, LOG_DEBUG
, "server uplink %s was not found, cant connect %s", rptr
->uplink
, rptr
->server
);
3122 } /* outsideness = 1 */
3125 if(user
) { /* report on what we did */
3126 if(!strcasecmp(directive
, "C")) {
3128 reply("OSMSG_CONNECTING_MISSING", connect
);
3130 reply("OSMSG_NO_SERVERS_MISSING");
3133 if(move
+connect
> 0)
3134 reply("OSMSG_REROUTE_COMPLETE", move
, connect
, move
+connect
);
3136 reply("OSMSG_NO_ROUTING_NECESSARY");
3138 reply("OSMSG_UPLINKS_MISSING", missing
);
3141 return(move
+connect
);
3144 static MODCMD_FUNC(cmd_reroute
) {
3147 if(reroute(opserv_route
, user
, cmd
, upper
))
3153 /* reroute_timer(run)
3154 * run - if it is null, just setup the timer
3155 * but dont run reroute now. otherwise reroute
3158 void reroute_timer(void *data
) {
3159 if(!opserv_route
|| !opserv_route
->servers
)
3160 return; /* no active route */
3161 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3163 return; /* retry_period invalid */
3164 unsigned int freq
= atoi(retry_period
);
3166 return; /* retry_period set to 0, disable */
3168 /* Do the reroute C attempt */
3170 reroute(opserv_route
, NULL
, NULL
, "C");
3172 /* Re-add ourselves to the timer queue */
3173 timeq_add(now
+ freq
, reroute_timer
, "run");
3176 void routing_change_karma(struct routingPlanServer
*rps
, const char *server
, int change
) {
3178 int oldkarma
= rps
->karma
;
3179 rps
->karma
+= change
;
3180 if(rps
->karma
< KARMA_MIN
)
3181 rps
->karma
= KARMA_MIN
;
3182 if(rps
->karma
> KARMA_MAX
)
3183 rps
->karma
= KARMA_MAX
;
3184 log_module(MAIN_LOG
, LOG_DEBUG
, "Changing %s karma by %d. new karma %d.", server
, change
, rps
->karma
);
3185 if(oldkarma
> 0 && rps
->karma
< 0) {
3186 /* we just crossed over to negitive */
3187 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went negitive karma!", server
);
3188 activate_routing(NULL
, NULL
, NULL
);
3190 else if(oldkarma
< 0 && rps
->karma
> 0) {
3191 /* we just crossed over to positive */
3192 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went back positive karma.", server
);
3193 activate_routing(NULL
, NULL
, NULL
);
3197 void routing_karma_timer(void *data
) {
3199 time_t timer_init
= data
? atoi(data
) : 0;
3202 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init
);
3204 /* If theres a time passed in, dont run unless that time is overdue. */
3205 if(!timer_init
|| (timer_init
< now
)) {
3206 if(opserv_route
&& opserv_route
->servers
) {
3207 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3208 struct routingPlan
*rp
;
3209 if(active
&& (rp
= dict_find(opserv_routing_plans
, active
, NULL
))) {
3211 /* Walk through each server in the active routing plan.. */
3212 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3213 struct routingPlanServer
*rps
= iter_data(it
);
3214 struct server
*server
= GetServerH(iter_key(it
));
3215 /* Give everyone +KARMA_ENTROPE just for nothing */
3216 routing_change_karma(rps
, iter_key(it
), KARMA_ENTROPE
);
3217 /* give an additonal +KARMA_RELIABLE to servers that
3218 * have been linked at least KARMA_TIMER seconds. */
3219 if(server
&& (server
->link
< (now
- KARMA_TIMER
) ) ) {
3220 routing_change_karma(rps
, iter_key(it
), KARMA_RELIABLE
);
3226 if(timer_init
> now
) /* loading a saved value */
3228 else /* no scheduled timer, or we missed it. start from now */
3229 next
= now
+ KARMA_TIMER
;
3230 /* Save when karma_timer should run again in case we restart before then */
3231 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next
);
3232 sprintf(buf
, "%u", (unsigned int) next
);
3233 dict_insert(opserv_routing_plan_options
, "KARMA_TIMER", strdup(buf
));
3234 /* add a timer to run this again .. */
3235 timeq_add(next
, routing_karma_timer
, NULL
);
3238 void routing_handle_neg_karma(char *server
, char *uplink
, int change
)
3240 /* if server's primary uplink is uplink, OR, uplink's primary uplink is server,
3241 * then whichever one, gets its karma changed. */
3242 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3243 struct routingPlan
*rp
;
3244 struct routingPlanServer
*rps
;
3247 if(!(rp
= dict_find(opserv_routing_plans
, active
, NULL
)))
3249 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3250 if(!strcasecmp(rps
->uplink
, uplink
)) {
3251 /* server's uplink is uplink */
3252 routing_change_karma(rps
, server
, change
);
3256 if((rps
= dict_find(rp
->servers
, uplink
, NULL
))) {
3257 if(!strcasecmp(rps
->uplink
, server
)) {
3258 /* uplink's uplink is server */
3259 routing_change_karma(rps
, uplink
, change
);
3266 routing_handle_squit(char *server
, char *uplink
, char *message
)
3268 log_module(MAIN_LOG
, LOG_DEBUG
, "Routing_handle_squit(%s, %s)", server
, message
);
3272 if(match_ircglob(message
, "Ping timeout")) {
3273 routing_handle_neg_karma(server
, uplink
, KARMA_PINGOUT
);
3274 /* if conn_pingout is true, try to reconnect it obaying karma rules. */
3276 val
= dict_find(opserv_routing_plan_options
, "CONN_PINGOUT", 0);
3277 if(val
&& enabled_string(val
))
3278 routing_connect_one(opserv_route
, server
);
3280 else if(match_ircglob(message
, "Read error:*")) {
3281 routing_handle_neg_karma(server
, uplink
, KARMA_READERROR
);
3282 /* if conn_readerror is true, try to reconnect it obaying karma rules. */
3283 val
= dict_find(opserv_routing_plan_options
, "CONN_READERROR", 0);
3284 if(val
&& enabled_string(val
))
3285 routing_connect_one(opserv_route
, server
);
3287 /* Else whats the message (an oper squit it?) dont interfere */
3291 routing_handle_connect(char *server
, char *uplink
)
3294 struct routingPlan
*rp
;
3295 struct routingPlanServer
*rps
;
3298 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect(%s, %s)", server
, uplink
);
3299 /* delete a pending connection timer, if any */
3300 routing_delete_connect_timer(server
);
3301 /* check if routing is active... */
3302 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3305 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3309 /* If its offline, mark it online again.. */
3310 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3311 if(rps
->offline
== true) {
3312 rps
->offline
= false;
3313 if(rps
->secondaryuplink
) {
3314 /* re-activate to move it back to its primary */
3315 activate_routing(NULL
, NULL
, NULL
);
3318 /* if there are any servers missing who have this server as uplink try to connect them. */
3319 routing_connect_children(opserv_route
, server
);
3321 /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */
3322 for (it
=dict_first(servers
); it
; it
=iter_next(it
)) {
3323 struct server
*sptr
= iter_data(it
);
3324 if(sptr
&& sptr
->uplink
&& !strcasecmp(server
, sptr
->uplink
->name
)) {
3325 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect calling self on %s's leaf %s", server
, sptr
->name
);
3326 routing_handle_connect(sptr
->name
, sptr
->uplink
->name
);
3331 /* Handle a failed attempt at connecting servers
3332 * - we should only get here regarding servers X3 attempted to link, other
3333 * opers link messages go to them not to us
3336 routing_handle_connect_failure(struct server
*source
, char *server
, char *message
)
3339 struct routingPlan
*rp
;
3340 struct routingPlanServer
*rps
;
3341 log_module(MAIN_LOG
, LOG_ERROR
, "Failed to connect %s to %s: %s", server
, source
->name
, message
);
3342 /* remove the waiting connection n timeq */
3343 routing_delete_connect_timer(server
);
3344 /* check if routing is active.. */
3345 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3348 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3352 if( ((rps
= dict_find(rp
->servers
, server
, NULL
)) && !strcasecmp(rps
->uplink
, source
->name
))) {
3353 /* failed to connect to its primary uplink */
3354 if(rps
->offline
== false) {
3355 rps
->offline
= true;
3356 if(rps
->secondaryuplink
) {
3357 /* re-activate routing so the secondary
3358 * becomes its uplink, and try again */
3359 activate_routing(NULL
, NULL
, NULL
);
3360 /* attempt to link it again. */
3361 routing_connect_one(opserv_route
, server
);
3362 /* TODO: reconnect any missing servers who
3363 * normally connect to server, using their backups.
3364 * Probably should just issue a reroute C here. */
3370 /* Delete any existing timers, and start the timer again
3371 * using the passed time for the first run.
3372 * - this is called during a retry_period change
3373 * before it has saved the new value. */
3374 void reroute_timer_reset(unsigned int time
)
3376 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
& TIMEQ_IGNORE_WHEN
);
3377 timeq_add(now
+ time
, reroute_timer
, "run");
3380 static MODCMD_FUNC(cmd_routing_set
)
3382 char *option
= argv
[1];
3383 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3386 route_show_options(cmd
, user
);
3389 char *found_option
= NULL
;
3390 for(i
= 0; options
[i
]; i
++) {
3391 if(!strcasecmp(options
[i
], option
))
3392 found_option
= options
[i
];
3395 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option
);
3399 char *value
= argv
[2];
3400 char buff
[MAXLEN
]; /* whats the max length of unsigned int as printf'd? */
3401 if(!strcmp(found_option
, "ACTIVE")) { /* must be an existing route. */
3402 if(disabled_string(value
) || false_string(value
)) {
3403 /* make none of the maps active */
3404 activate_routing(cmd
, user
, "*");
3405 reply("OSMSG_ROUTING_DISABLED");
3408 else if(!activate_routing(cmd
, user
, value
)) {
3409 /* neg reply handled in activate_routing */
3413 if(!strcmp(found_option
, "CONN_READERROR") || !strcmp(found_option
, "CONN_PINGOUT") ||
3414 !strcmp(found_option
, "KARMA") ) {
3415 if( enabled_string(value
)) {
3418 else if( disabled_string(value
) ) {
3422 reply("MSG_INVALID_BINARY", value
);
3426 if(!strcmp(found_option
, "RETRY_PERIOD")) {
3427 unsigned int duration
= ParseInterval(value
);
3428 sprintf(buff
, "%d", duration
);
3430 reroute_timer_reset(duration
);
3432 /* set the value here */
3433 dict_remove(opserv_routing_plan_options
, found_option
);
3434 dict_insert(opserv_routing_plan_options
, strdup(found_option
), strdup(value
));
3435 route_show_option(cmd
, user
, found_option
);
3438 /* show the current value */
3439 route_show_option(cmd
, user
, found_option
);
3445 static MODCMD_FUNC(cmd_stats_routing_plans
) {
3446 dict_iterator_t rpit
;
3448 struct routingPlan
*rp
;
3449 reply("OSMSG_ROUTINGPLAN_LIST");
3450 reply("OSMSG_ROUTINGPLAN_BAR");
3451 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3452 const char* name
= iter_key(rpit
);
3453 rp
= iter_data(rpit
);
3454 reply("OSMSG_ROUTINGPLAN_NAME", name
);
3455 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3456 const char* servername
= iter_key(it
);
3457 struct routingPlanServer
*rps
= iter_data(it
);
3458 reply("OSMSG_ROUTINGPLAN_SERVER", servername
, rps
->port
, rps
->uplink
, rps
->karma
, rps
->offline
? "offline" : "online", rps
->secondaryuplink
? rps
->secondaryuplink
: "None");
3462 reply("OSMSG_ROUTINGPLAN_END");
3463 route_show_options(cmd
, user
);
3468 static MODCMD_FUNC(cmd_routing_addplan
)
3472 /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */
3473 if(*name
&& !disabled_string(name
) && !false_string(name
)) {
3474 if(opserv_add_routing_plan(name
)) {
3475 reply("OSMSG_ADDPLAN_SUCCESS", name
);
3479 reply("OSMSG_ADDPLAN_FAILED", name
);
3485 reply("OSMSG_INVALID_PLAN");
3490 static MODCMD_FUNC(cmd_routing_delplan
)
3492 char *name
= argv
[1];
3493 if( dict_remove(opserv_routing_plans
, name
) ) {
3494 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3495 if(active
&& !strcasecmp(active
, name
)) {
3496 /* if this was the active plan, disable routing */
3497 activate_routing(cmd
, user
, "*");
3498 reply("OSMSG_ROUTING_DISABLED");
3500 reply("OSMSG_PLAN_DELETED");
3504 reply("OSMSG_PLAN_NOT_FOUND", name
);
3509 static MODCMD_FUNC(cmd_routing_addserver
)
3517 struct routingPlan
*rp
;
3520 server
= strdup(argv
[2]);
3521 server
= strtok(server
, ":");
3522 portstr
= strtok(NULL
, ":");
3524 port
= atoi(portstr
);
3526 char *str
= dict_find(opserv_routing_plan_options
, "DEFAULT_PORT", NULL
);
3528 port
= str
? atoi(str
) : 0;
3536 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3538 opserv_routing_plan_add_server(rp
, server
, uplink
, port
, KARMA_DEFAULT
, second
, 0);
3539 reply("OSMSG_PLAN_SERVER_ADDED", server
);
3540 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3541 /* re-activate routing with new info */
3542 activate_routing(cmd
, user
, NULL
);
3549 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3555 static MODCMD_FUNC(cmd_routing_delserver
)
3559 struct routingPlan
*rp
;
3562 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3563 if(dict_remove(rp
->servers
, server
)) {
3565 reply("OSMSG_PLAN_SERVER_DELETED");
3566 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3567 /* re-activate routing with new info */
3568 activate_routing(cmd
, user
, NULL
);
3574 reply("OSMSG_PLAN_SERVER_NOT_FOUND", server
);
3579 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3585 /*************************************************
3586 * Functions to deal with 'route map' command */
3588 /* Figures out how many downlinks there are for proper
3589 * drawing of the route map */
3591 num_route_downlinks(struct route
*route
, char *name
)
3593 struct routeList
*rptr
;
3595 rptr
= route
->servers
;
3597 if(!strcasecmp(rptr
->uplink
, name
))
3605 show_route_downlinks(struct svccmd
*cmd
, struct route
*route
, struct userNode
*user
, char *name
, char *prevpre
, char *arrowchar
, int reset
)
3607 struct routeList
*servPtr
;
3608 struct server
*sptr
;
3614 static int depth
= 0;
3619 nextpre
= malloc(MAXLEN
);
3620 strcpy(pre
, prevpre
);
3622 sptr
= GetServerH(name
);
3623 if((servPtr
= find_routeList_server(route
, name
))) {
3626 else if (!strcasecmp(sptr
->uplink
->name
, servPtr
->uplink
))
3628 else if(servPtr
->secondaryuplink
&& !strcasecmp(sptr
->name
, servPtr
->secondaryuplink
))
3632 reply("OSMSG_DOWNLINKS_FORMAT_A", pre
, arrowchar
, name
, status
);
3635 reply("OSMSG_DOWNLINKS_FORMAT_B", self
->name
);
3636 j
= num_route_downlinks(route
, name
);
3637 servPtr
= route
->servers
;
3639 if(!strcasecmp(servPtr
->uplink
, name
)) {
3640 strcpy(nextpre
, pre
);
3642 if(arrowchar
[0] == '`')
3643 strcat(nextpre
, " ");
3645 strcat(nextpre
, "| ");
3648 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "|", 0);
3651 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "`", 0);
3654 servPtr
= servPtr
->next
;
3660 show_route_map(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
)
3662 if(!route
|| !route
->servers
) {
3663 reply("OSMSG_ROUTELIST_EMPTY");
3667 char *serviceName
= conf_get_data("server/hostname", RECDB_QSTRING
);
3668 reply("OSMSG_ROUTELIST_AS_PLANNED");
3669 show_route_downlinks(cmd
, route
, user
, serviceName
, "", "`", 1);
3670 reply("OSMSG_MAP_CENTERED", route
->centered
? "is" : "is not", route
->maxdepth
);
3674 static MODCMD_FUNC(cmd_routing_map
)
3676 show_route_map(opserv_route
, user
, cmd
);
3683 /* End of auto routing functions *
3684 *********************************/
3686 static MODCMD_FUNC(cmd_addbad
)
3688 unsigned int arg
, count
;
3690 int bad_found
, exempt_found
;
3692 /* Create the bad word if it doesn't exist. */
3693 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
3695 /* Look for exception modifiers. */
3696 for (arg
=2; arg
<argc
; arg
++) {
3697 if (!irccasecmp(argv
[arg
], "except")) {
3698 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
3700 reply("MSG_MISSING_PARAMS", "except");
3703 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
3704 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
3705 if (!exempt_found
) {
3706 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
3710 reply("OSMSG_ADDED_EXEMPTIONS", count
);
3712 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
3713 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
3717 /* Scan for existing channels that match the new bad word. */
3719 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
3720 struct chanNode
*channel
= iter_data(it
);
3722 if (!opserv_bad_channel(channel
->name
))
3724 channel
->bad_channel
= 1;
3725 if (channel
->name
[0] == '#')
3726 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
3729 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
3730 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
3731 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
3740 static MODCMD_FUNC(cmd_delbad
)
3745 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
3746 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
3747 string_list_delete(opserv_bad_words
, nn
);
3748 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
3749 channel
= iter_data(it
);
3750 if (irccasestr(channel
->name
, argv
[1])
3751 && !opserv_bad_channel(channel
->name
)) {
3752 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
3753 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
3754 channel
->bad_channel
= 0;
3757 reply("OSMSG_REMOVED_BAD", argv
[1]);
3761 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
3765 static MODCMD_FUNC(cmd_addexempt
)
3767 const char *chanName
;
3769 if ((argc
> 1) && IsChannelName(argv
[1])) {
3772 reply("MSG_NOT_CHANNEL_NAME");
3776 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
3777 channel
= GetChannel(chanName
);
3779 if (channel
->bad_channel
) {
3780 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
3781 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
3783 channel
->bad_channel
= 0;
3785 reply("OSMSG_ADDED_EXEMPTION", chanName
);
3789 static MODCMD_FUNC(cmd_delexempt
)
3791 const char *chanName
;
3793 if ((argc
> 1) && IsChannelName(argv
[1])) {
3796 reply("MSG_NOT_CHANNEL_NAME");
3800 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
3801 reply("OSMSG_NOT_EXEMPT", chanName
);
3804 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
3809 opserv_expire_trusted_host(void *data
)
3811 struct trusted_host
*th
= data
;
3812 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
3816 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
3818 struct trusted_host
*th
;
3819 th
= calloc(1, sizeof(*th
));
3822 th
->ipaddr
= strdup(ipaddr
);
3823 th
->reason
= reason
? strdup(reason
) : NULL
;
3824 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
3825 th
->issued
= issued
;
3827 th
->expires
= expires
;
3828 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
3830 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
3834 free_trusted_host(void *data
)
3836 struct trusted_host
*th
= data
;
3843 static MODCMD_FUNC(cmd_addtrust
)
3845 unsigned long interval
;
3847 irc_in_addr_t tmpaddr
;
3850 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
3851 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
3855 if (!irc_pton(&tmpaddr
, NULL
, argv
[1])) {
3856 reply("OSMSG_BAD_IP", argv
[1]);
3860 count
= strtoul(argv
[2], &tmp
, 10);
3862 reply("OSMSG_BAD_NUMBER", argv
[2]);
3866 interval
= ParseInterval(argv
[3]);
3867 if (!interval
&& strcmp(argv
[3], "0")) {
3868 reply("MSG_INVALID_DURATION", argv
[3]);
3872 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
3873 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
3874 reply("OSMSG_ADDED_TRUSTED");
3878 static MODCMD_FUNC(cmd_edittrust
)
3880 unsigned long interval
;
3881 struct trusted_host
*th
;
3885 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
3887 reply("OSMSG_NOT_TRUSTED", argv
[1]);
3890 count
= strtoul(argv
[2], &tmp
, 10);
3891 if (!count
|| *tmp
) {
3892 reply("OSMSG_BAD_NUMBER", argv
[2]);
3895 interval
= ParseInterval(argv
[3]);
3896 if (!interval
&& strcmp(argv
[3], "0")) {
3897 reply("MSG_INVALID_DURATION", argv
[3]);
3900 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
3902 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
3905 th
->reason
= strdup(reason
);
3907 th
->issuer
= strdup(user
->handle_info
->handle
);
3911 th
->expires
= now
+ interval
;
3912 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
3915 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
3919 static MODCMD_FUNC(cmd_deltrust
)
3923 for (n
=1; n
<argc
; n
++) {
3924 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
3928 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
3929 dict_remove(opserv_trusted_hosts
, argv
[n
]);
3931 reply("OSMSG_REMOVED_TRUSTED");
3935 /* This doesn't use dict_t because it's a little simpler to open-code the
3936 * comparisons (and simpler arg-passing for the ADD subcommand).
3938 static MODCMD_FUNC(cmd_clone
)
3941 struct userNode
*clone
;
3943 clone
= GetUserH(argv
[2]);
3944 if (!irccasecmp(argv
[1], "ADD")) {
3946 char ident
[USERLEN
+1];
3949 reply("MSG_MISSING_PARAMS", argv
[1]);
3954 reply("OSMSG_CLONE_EXISTS", argv
[2]);
3957 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
3958 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
3959 if (argv
[3][i
] == '@') {
3963 ident
[i
] = argv
[3][i
];
3966 if (!argv
[3][i
] || (i
==USERLEN
)) {
3967 reply("OSMSG_NOT_A_HOSTMASK");
3970 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
3971 reply("OSMSG_CLONE_FAILED", argv
[2]);
3974 reply("OSMSG_CLONE_ADDED", clone
->nick
);
3978 reply("MSG_NICK_UNKNOWN", argv
[2]);
3981 if (clone
->uplink
!= self
|| IsService(clone
)) {
3982 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
3985 if (!irccasecmp(argv
[1], "REMOVE")) {
3988 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
3991 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
3992 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
3995 DelUser(clone
, NULL
, 1, reason
);
3996 reply("OSMSG_CLONE_REMOVED", argv
[2]);
4000 reply("MSG_MISSING_PARAMS", argv
[1]);
4004 channel
= GetChannel(argv
[3]);
4005 if (!irccasecmp(argv
[1], "JOIN")) {
4007 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
4008 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4011 AddChannelUser(clone
, channel
);
4012 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
4015 if (!irccasecmp(argv
[1], "PART")) {
4017 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4020 if (!GetUserMode(channel
, clone
)) {
4021 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4024 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
4025 DelChannelUser(clone
, channel
, "Leaving.", 0);
4028 if (!irccasecmp(argv
[1], "OP")) {
4029 struct mod_chanmode change
;
4031 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4034 mod_chanmode_init(&change
);
4036 change
.args
[0].mode
= MODE_CHANOP
;
4037 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4038 if (!change
.args
[0].u
.member
) {
4039 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4042 modcmd_chanmode_announce(&change
);
4043 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
4046 if (!irccasecmp(argv
[1], "HOP")) {
4047 struct mod_chanmode change
;
4049 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4052 mod_chanmode_init(&change
);
4054 change
.args
[0].mode
= MODE_HALFOP
;
4055 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4056 if (!change
.args
[0].u
.member
) {
4057 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4060 modcmd_chanmode_announce(&change
);
4061 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
4065 reply("MSG_MISSING_PARAMS", argv
[1]);
4069 if (!irccasecmp(argv
[1], "SAY")) {
4070 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
4071 irc_privmsg(clone
, argv
[3], text
);
4072 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
4075 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
4079 static struct helpfile_expansion
4080 opserv_help_expand(const char *variable
)
4082 extern struct userNode
*message_source
;
4083 struct helpfile_expansion exp
;
4084 struct service
*service
;
4090 if (!(service
= service_find(message_source
->nick
))) {
4091 exp
.type
= HF_STRING
;
4092 exp
.value
.str
= NULL
;
4093 } else if (!irccasecmp(variable
, "index")) {
4094 exp
.type
= HF_TABLE
;
4095 exp
.value
.table
.length
= 1;
4096 exp
.value
.table
.width
= 2;
4097 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
4098 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
4099 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
4100 exp
.value
.table
.contents
[0][0] = "Command";
4101 exp
.value
.table
.contents
[0][1] = "Level";
4102 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
4103 cmd
= iter_data(it
);
4104 row
= exp
.value
.table
.length
++;
4105 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
4106 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
4107 level
= cmd
->min_opserv_level
;
4108 if (!level_strings
[level
]) {
4109 level_strings
[level
] = malloc(16);
4110 snprintf(level_strings
[level
], 16, "%3d", level
);
4112 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
4114 } else if (!strncasecmp(variable
, "level", 5)) {
4115 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
4116 exp
.type
= HF_STRING
;
4118 level
= cmd
->min_opserv_level
;
4119 exp
.value
.str
= malloc(16);
4120 snprintf(exp
.value
.str
, 16, "%3d", level
);
4122 exp
.value
.str
= NULL
;
4125 exp
.type
= HF_STRING
;
4126 exp
.value
.str
= NULL
;
4132 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
4134 char buf
[16], *flags
= NULL
;
4135 unsigned int iflags
= 0;
4136 sprintf(buf
, "%d", min_level
);
4138 case 1: flags
= "+acceptchan"; break;
4139 case 3: flags
= "+acceptpluschan"; /* fall through */
4140 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
4143 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
4145 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
4149 int add_reserved(const char *key
, void *data
, void *extra
)
4151 struct chanNode
*chan
;
4152 struct record_data
*rd
= data
;
4153 const char *ident
, *hostname
, *desc
;
4155 struct userNode
*reserve
;
4156 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
4158 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
4161 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
4163 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
4166 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
4168 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
4171 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
4172 reserve
->modes
|= FLAGS_PERSISTENT
;
4173 dict_insert(extra
, reserve
->nick
, reserve
);
4176 if (autojoin_channels
&& reserve
) {
4177 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
4178 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
4179 AddChannelUser(reserve
, chan
)->modes
|= MODE_VOICE
;
4187 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
4191 unsigned int matched
;
4193 if (!self
->uplink
) return 0;
4194 discrim
= calloc(1, sizeof(*discrim
));
4195 discrim
->limit
= dict_size(clients
);
4196 discrim
->max_level
= ~0;
4197 discrim
->max_ts
= now
;
4198 discrim
->max_channels
= INT_MAX
;
4199 discrim
->authed
= -1;
4200 discrim
->info_space
= -1;
4201 discrim
->intra_scmp
= 0;
4202 discrim
->intra_dcmp
= 0;
4203 discrim
->use_regex
= 0;
4204 discrim
->silent
= 0;
4205 dupmask
= strdup(hostmask
);
4206 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
4207 if (!irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, discrim
->mask_host
))
4208 discrim
->ip_mask_bits
= 0;
4209 matched
= opserv_discrim_search(discrim
, func
, extra
);
4211 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
4220 gag_free(struct gag_entry
*gag
)
4222 unsigned int ungagged
;
4224 /* Remove from gag list */
4225 if (gagList
== gag
) {
4226 gagList
= gag
->next
;
4228 struct gag_entry
*prev
;
4229 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
4230 prev
->next
= gag
->next
;
4233 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
4235 /* Deallocate storage */
4245 gag_expire(void *data
)
4251 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
4253 struct gag_entry
*gag
;
4255 /* Create gag and put it into linked list */
4256 gag
= calloc(1, sizeof(*gag
));
4257 gag
->mask
= strdup(mask
);
4258 gag
->owner
= strdup(owner
? owner
: "<unknown>");
4259 gag
->reason
= strdup(reason
? reason
: "<unknown>");
4260 gag
->expires
= expires
;
4262 timeq_add(gag
->expires
, gag_expire
, gag
);
4263 gag
->next
= gagList
;
4266 /* If we're linked, see if who the gag applies to */
4267 return foreach_matching_user(mask
, gag_helper_func
, gag
);
4271 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4273 struct record_data
*rd
= data
;
4274 char *owner
, *reason
, *expstr
;
4277 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
4278 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
4279 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
4280 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
4281 gag_create(key
, owner
, reason
, expires
);
4286 static struct opserv_user_alert
*
4287 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
)
4290 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
4291 struct opserv_user_alert
*alert
;
4294 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
4295 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
4298 alert
= malloc(sizeof(*alert
));
4299 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
4300 alert
->text_discrim
= strdup(text_discrim
);
4301 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
4302 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
4303 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
4304 if (!alert
->discrim
) {
4305 free(alert
->text_discrim
);
4310 alert
->split_discrim
= discrim_copy
;
4311 name_dup
= strdup(name
);
4312 if (!alert
->discrim
->reason
)
4313 alert
->discrim
->reason
= strdup(name
);
4314 alert
->reaction
= reaction
;
4315 dict_insert(opserv_user_alerts
, name_dup
, alert
);
4316 /* Stick the alert into the appropriate additional alert dict(s).
4317 * For channel alerts, we only use channels and min_channels;
4318 * max_channels would have to be checked on /part, which we do not
4319 * yet do, and which seems of questionable value.
4321 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
4322 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
4323 if (alert
->discrim
->mask_nick
)
4324 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
4330 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
4332 struct record_data *rd = data;
4333 char *reason = GET_RECORD_QSTRING(rd);
4335 * i hope this can't happen *
4337 reason = "No Reason";
4339 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
4346 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4349 const char *discrim
, *react
, *owner
;
4350 opserv_alert_reaction reaction
;
4351 struct opserv_user_alert
*alert
;
4353 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
4354 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
4357 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
4358 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
4359 if (!react
|| !irccasecmp(react
, "notice"))
4360 reaction
= REACT_NOTICE
;
4361 else if (!irccasecmp(react
, "kill"))
4362 reaction
= REACT_KILL
;
4364 else if (!irccasecmp(react, "silent"))
4365 reaction = REACT_SILENT;
4367 else if (!irccasecmp(react
, "gline"))
4368 reaction
= REACT_GLINE
;
4369 else if (!irccasecmp(react
, "track"))
4370 reaction
= REACT_TRACK
;
4371 else if (!irccasecmp(react
, "shun"))
4372 reaction
= REACT_SHUN
;
4374 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
4377 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
);
4379 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
4382 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
4384 alert
->owner
= strdup(owner
? owner
: "<unknown>");
4389 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
4391 struct record_data
*rd
= data
;
4392 const char *limit
, *str
, *reason
, *issuer
;
4393 time_t issued
, expires
;
4395 if (rd
->type
== RECDB_QSTRING
) {
4396 /* old style host by itself */
4397 limit
= GET_RECORD_QSTRING(rd
);
4402 } else if (rd
->type
== RECDB_OBJECT
) {
4403 dict_t obj
= GET_RECORD_OBJECT(rd
);
4404 /* new style structure */
4405 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
4406 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
4407 expires
= str
? ParseInterval(str
) : 0;
4408 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
4409 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
4410 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
4411 issued
= str
? ParseInterval(str
) : 0;
4415 if (expires
&& (expires
< now
))
4417 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
4422 add_routing_plan_server(const char *name
, void *data
, void *rp
)
4424 struct record_data
*rd
= data
;
4425 const char *uplink
, *portstr
, *karma
, *second
, *offline
;
4427 dict_t obj
= GET_RECORD_OBJECT(rd
);
4428 if(rd
->type
== RECDB_OBJECT
) {
4429 uplink
= database_get_data(obj
, KEY_UPLINK
, RECDB_QSTRING
);
4430 second
= database_get_data(obj
, KEY_SECOND
, RECDB_QSTRING
);
4431 portstr
= database_get_data(obj
, KEY_PORT
, RECDB_QSTRING
);
4432 karma
= database_get_data(obj
, KEY_KARMA
, RECDB_QSTRING
);
4433 offline
= database_get_data(obj
, KEY_OFFLINE
, RECDB_QSTRING
);
4434 /* create routing plan server named key, with uplink uplink. */
4435 opserv_routing_plan_add_server(rp
, name
, uplink
, portstr
? atoi(portstr
) : 0,
4436 karma
? atoi(karma
) : KARMA_DEFAULT
, second
,
4437 offline
? atoi(offline
) : 0);
4444 routing_plan_set_option(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4446 struct record_data
*rd
= data
;
4447 if(rd
->type
== RECDB_QSTRING
)
4449 char *value
= GET_RECORD_QSTRING(rd
);
4450 dict_insert(opserv_routing_plan_options
, strdup(name
), strdup(value
));
4456 add_routing_plan(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4458 struct record_data
*rd
= data
;
4459 struct routingPlan
*rp
;
4461 if(rd
->type
== RECDB_OBJECT
) {
4462 dict_t obj
= GET_RECORD_OBJECT(rd
);
4463 rp
= opserv_add_routing_plan(name
);
4464 dict_foreach(obj
, add_routing_plan_server
, rp
);
4470 opserv_saxdb_read(struct dict
*conf_db
)
4473 struct record_data
*rd
;
4477 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
4478 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
4479 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
4481 case RECDB_STRING_LIST
:
4482 /* Add words one by one just in case there are overlaps from an old DB. */
4483 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4484 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
4487 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
4488 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
4490 if (rd
->type
== RECDB_STRING_LIST
)
4491 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
4492 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4499 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
4500 && (rd
->type
== RECDB_STRING_LIST
)) {
4501 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4502 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4504 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
4506 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
4507 max_clients
= atoi(str
);
4508 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
4509 max_clients_time
= atoi(str
);
4511 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
4512 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
4513 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
4514 dict_foreach(object
, add_gag_helper
, NULL
);
4515 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
4516 dict_foreach(object
, add_user_alert
, NULL
);
4518 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
4519 dict_foreach(object, add_chan_warn, NULL);
4522 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN
, RECDB_OBJECT
)))
4523 dict_foreach(object
, add_routing_plan
, NULL
);
4525 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN_OPTIONS
, RECDB_OBJECT
)))
4526 dict_foreach(object
, routing_plan_set_option
, NULL
);
4532 opserv_saxdb_write(struct saxdb_context
*ctx
)
4534 struct string_list
*slist
;
4537 /* reserved nicks */
4538 if (dict_size(opserv_reserved_nick_dict
)) {
4539 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
4540 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
4541 struct userNode
*user
= iter_data(it
);
4542 if (!IsPersistent(user
)) continue;
4543 saxdb_start_record(ctx
, iter_key(it
), 0);
4544 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
4545 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
4546 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
4547 saxdb_end_record(ctx
);
4549 saxdb_end_record(ctx
);
4552 if (opserv_bad_words
->used
) {
4553 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
4555 /* routing plan options */
4556 if (dict_size(opserv_routing_plan_options
)) {
4557 saxdb_start_record(ctx
, KEY_ROUTINGPLAN_OPTIONS
, 1);
4558 for(it
= dict_first(opserv_routing_plan_options
); it
; it
= iter_next(it
)) {
4559 saxdb_write_string(ctx
, iter_key(it
), iter_data(it
));
4561 saxdb_end_record(ctx
);
4564 if (dict_size(opserv_routing_plans
)) {
4565 dict_iterator_t svrit
;
4566 struct routingPlan
*rp
;
4567 struct routingPlanServer
*rps
;
4568 saxdb_start_record(ctx
, KEY_ROUTINGPLAN
, 1);
4569 for (it
= dict_first(opserv_routing_plans
); it
; it
= iter_next(it
)) {
4571 saxdb_start_record(ctx
, iter_key(it
), 0);
4572 for(svrit
= dict_first(rp
->servers
); svrit
; svrit
= iter_next(svrit
)) {
4574 rps
= iter_data(svrit
);
4575 saxdb_start_record(ctx
, iter_key(svrit
), 0);
4576 saxdb_write_string(ctx
, KEY_UPLINK
, rps
->uplink
);
4577 if(rps
->secondaryuplink
)
4578 saxdb_write_string(ctx
, KEY_SECOND
, rps
->secondaryuplink
);
4579 sprintf(buf
, "%d", rps
->port
);
4580 saxdb_write_string(ctx
, KEY_PORT
, buf
);
4581 sprintf(buf
, "%d", rps
->karma
);
4582 saxdb_write_string(ctx
, KEY_KARMA
, buf
);
4583 sprintf(buf
, "%d", rps
->offline
);
4584 saxdb_write_string(ctx
, KEY_OFFLINE
, buf
);
4585 saxdb_end_record(ctx
);
4587 saxdb_end_record(ctx
);
4589 saxdb_end_record(ctx
);
4591 /* insert exempt channel names */
4592 if (dict_size(opserv_exempt_channels
)) {
4593 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
4594 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
4595 string_list_append(slist
, strdup(iter_key(it
)));
4597 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
4598 free_string_list(slist
);
4600 /* trusted hosts takes a little more work */
4601 if (dict_size(opserv_trusted_hosts
)) {
4602 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
4603 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
4604 struct trusted_host
*th
= iter_data(it
);
4605 saxdb_start_record(ctx
, iter_key(it
), 0);
4606 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
4607 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
4608 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
4609 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
4610 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
4611 saxdb_end_record(ctx
);
4613 saxdb_end_record(ctx
);
4617 struct gag_entry
*gag
;
4618 saxdb_start_record(ctx
, KEY_GAGS
, 1);
4619 for (gag
= gagList
; gag
; gag
= gag
->next
) {
4620 saxdb_start_record(ctx
, gag
->mask
, 0);
4621 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
4622 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
4623 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
4624 saxdb_end_record(ctx
);
4626 saxdb_end_record(ctx
);
4628 /* channel warnings */
4630 if (dict_size(opserv_chan_warn)) {
4631 saxdb_start_record(ctx, KEY_WARN, 0);
4632 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
4633 saxdb_write_string(ctx, iter_key(it), iter_data(it));
4635 saxdb_end_record(ctx);
4639 if (dict_size(opserv_user_alerts
)) {
4640 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
4641 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
4642 struct opserv_user_alert
*alert
= iter_data(it
);
4643 const char *reaction
;
4644 saxdb_start_record(ctx
, iter_key(it
), 0);
4645 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
4646 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
4647 switch (alert
->reaction
) {
4648 case REACT_NOTICE
: reaction
= "notice"; break;
4649 case REACT_KILL
: reaction
= "kill"; break;
4650 // case REACT_SILENT: reaction = "silent"; break;
4651 case REACT_GLINE
: reaction
= "gline"; break;
4652 case REACT_TRACK
: reaction
= "track"; break;
4653 case REACT_SHUN
: reaction
= "shun"; break;
4656 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
4659 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
4660 saxdb_end_record(ctx
);
4662 saxdb_end_record(ctx
);
4665 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
4666 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
4667 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
4668 saxdb_end_record(ctx
);
4673 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
4675 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
4679 static MODCMD_FUNC(cmd_query
)
4681 struct record_data
*rd
;
4686 reply("OSMSG_OPTION_ROOT");
4687 conf_enum_root(query_keys_helper
, user
);
4691 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
4692 if (!(rd
= conf_get_node(nodename
))) {
4693 reply("OSMSG_UNKNOWN_OPTION", nodename
);
4697 if (rd
->type
== RECDB_QSTRING
)
4698 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
4699 else if (rd
->type
== RECDB_STRING_LIST
) {
4700 reply("OSMSG_OPTION_LIST", nodename
);
4701 if (rd
->d
.slist
->used
)
4702 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
4703 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
4705 reply("OSMSG_OPTION_LIST_EMPTY");
4706 } else if (rd
->type
== RECDB_OBJECT
) {
4707 reply("OSMSG_OPTION_KEYS", nodename
);
4708 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
4714 static MODCMD_FUNC(cmd_set
)
4716 struct record_data
*rd
;
4718 /* I originally wanted to be able to fully manipulate the config
4719 db with this, but i wussed out. feel free to fix this - you'll
4720 need to handle quoted strings which have been split, and likely
4721 invent a syntax for it. -Zoot */
4723 if (!(rd
= conf_get_node(argv
[1]))) {
4724 reply("OSMSG_SET_NOT_SET", argv
[1]);
4728 if (rd
->type
!= RECDB_QSTRING
) {
4729 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
4733 free(rd
->d
.qstring
);
4734 rd
->d
.qstring
= strdup(argv
[2]);
4735 conf_call_reload_funcs();
4736 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
4740 static MODCMD_FUNC(cmd_settime
)
4742 const char *srv_name_mask
= "*";
4743 time_t new_time
= now
;
4746 srv_name_mask
= argv
[1];
4748 new_time
= time(NULL
);
4749 irc_settime(srv_name_mask
, new_time
);
4750 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
4755 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
4760 discrim
= calloc(1, sizeof(*discrim
));
4761 discrim
->limit
= 250;
4762 discrim
->max_level
= ~0;
4763 discrim
->max_ts
= INT_MAX
;
4764 discrim
->domain_depth
= 2;
4765 discrim
->max_channels
= INT_MAX
;
4766 discrim
->authed
= -1;
4767 discrim
->info_space
= -1;
4768 discrim
->intra_dcmp
= 0;
4769 discrim
->intra_scmp
= 0;
4770 discrim
->use_regex
= 0;
4771 discrim
->silent
= 0;
4773 for (i
=0; i
<argc
; i
++) {
4774 if (irccasecmp(argv
[i
], "log") == 0) {
4775 discrim
->option_log
= 1;
4778 /* Assume all other criteria require arguments. */
4779 if (i
== argc
- 1) {
4780 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
4783 if (argv
[i
+1][0] == '&') {
4784 /* Looking for intra-userNode matches */
4785 char *tmp
= &(argv
[i
+1][1]);
4786 if (strcasecmp(tmp
, argv
[i
]) != 0) { /* Don't allow "nick &nick" etc */
4787 if (!strcasecmp(tmp
, "nick"))
4788 discrim
->intra_dcmp
= 1;
4789 else if (!strcasecmp(tmp
, "ident"))
4790 discrim
->intra_dcmp
= 2;
4791 else if (!strcasecmp(tmp
, "info"))
4792 discrim
->intra_dcmp
= 3;
4795 if (irccasecmp(argv
[i
], "mask") == 0) {
4796 if (!is_ircmask(argv
[++i
])) {
4797 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
4800 if (!split_ircmask(argv
[i
],
4801 &discrim
->mask_nick
,
4802 &discrim
->mask_ident
,
4803 &discrim
->mask_host
)) {
4804 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
4807 } else if (irccasecmp(argv
[i
], "nick") == 0) {
4809 if (discrim
->intra_dcmp
> 0)
4810 discrim
->intra_scmp
= 1;
4812 discrim
->mask_nick
= argv
[i
];
4813 } else if (irccasecmp(argv
[i
], "ident") == 0) {
4815 if (discrim
->intra_dcmp
> 0)
4816 discrim
->intra_scmp
= 2;
4818 discrim
->mask_ident
= argv
[i
];
4819 } else if (irccasecmp(argv
[i
], "host") == 0) {
4820 discrim
->mask_host
= argv
[++i
];
4821 } else if (irccasecmp(argv
[i
], "info") == 0) {
4823 if (discrim
->intra_dcmp
> 0)
4824 discrim
->intra_scmp
= 3;
4826 discrim
->mask_info
= argv
[i
];
4827 } else if (irccasecmp(argv
[i
], "server") == 0) {
4828 discrim
->server
= argv
[++i
];
4829 } else if (irccasecmp(argv
[i
], "ip") == 0) {
4830 j
= irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, argv
[++i
]);
4832 send_message(user
, bot
, "OSMSG_BAD_IP", argv
[i
]);
4835 } else if (irccasecmp(argv
[i
], "account") == 0) {
4836 if (discrim
->authed
== 0) {
4837 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
4840 discrim
->accountmask
= argv
[++i
];
4841 discrim
->authed
= 1;
4842 } else if (irccasecmp(argv
[i
], "authed") == 0) {
4843 i
++; /* true_string and false_string are macros! */
4844 if (true_string(argv
[i
])) {
4845 discrim
->authed
= 1;
4846 } else if (false_string(argv
[i
])) {
4847 if (discrim
->accountmask
) {
4848 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
4851 discrim
->authed
= 0;
4853 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4856 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
4857 /* XXX: A hack because you can't check explicitly for a space through
4858 * any other means */
4860 if (true_string(argv
[i
])) {
4861 discrim
->info_space
= 1;
4862 } else if (false_string(argv
[i
])) {
4863 discrim
->info_space
= 0;
4865 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4868 } else if (irccasecmp(argv
[i
], "regex") == 0) {
4870 if (true_string(argv
[i
])) {
4871 discrim
->use_regex
= 1;
4872 } else if (false_string(argv
[i
])) {
4873 discrim
->use_regex
= 0;
4875 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4878 } else if (irccasecmp(argv
[i
], "silent") == 0) {
4880 if(user
!= opserv
&& !oper_has_access(user
, opserv
, opserv_conf
.silent_level
, 0)) {
4882 } else if (true_string(argv
[i
])) {
4883 discrim
->silent
= 1;
4884 } else if (false_string(argv
[i
])) {
4885 discrim
->silent
= 0;
4887 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
4890 } else if (irccasecmp(argv
[i
], "duration") == 0) {
4891 discrim
->duration
= ParseInterval(argv
[++i
]);
4892 } else if (irccasecmp(argv
[i
], "channel") == 0) {
4893 for (j
=0, i
++; ; j
++) {
4894 switch (argv
[i
][j
]) {
4898 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
4901 discrim
->chan_req_modes
|= MODE_VOICE
;
4902 discrim
->chan_no_modes
|= MODE_CHANOP
;
4903 discrim
->chan_no_modes
|= MODE_HALFOP
;
4906 discrim
->chan_req_modes
|= MODE_HALFOP
;
4907 discrim
->chan_no_modes
|= MODE_CHANOP
;
4908 discrim
->chan_no_modes
|= MODE_VOICE
;
4911 discrim
->chan_req_modes
|= MODE_CHANOP
;
4914 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
4919 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
4920 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
4921 /* secretly "allow_channel" now means "if a channel name is
4922 * specified, require that it currently exist" */
4923 if (allow_channel
) {
4924 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
4927 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
4930 LockChannel(discrim
->channel
);
4931 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
4932 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
4933 } else if (irccasecmp(argv
[i
], "limit") == 0) {
4934 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
4935 } else if (irccasecmp(argv
[i
], "reason") == 0) {
4936 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
4938 } else if (irccasecmp(argv
[i
], "last") == 0) {
4939 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
4940 } else if ((irccasecmp(argv
[i
], "linked") == 0)
4941 || (irccasecmp(argv
[i
], "nickage") == 0)) {
4942 const char *cmp
= argv
[++i
];
4943 if (cmp
[0] == '<') {
4944 if (cmp
[1] == '=') {
4945 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
4947 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
4949 } else if (cmp
[0] == '>') {
4950 if (cmp
[1] == '=') {
4951 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
4953 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
4956 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
4958 } else if (irccasecmp(argv
[i
], "access") == 0) {
4959 const char *cmp
= argv
[++i
];
4960 if (cmp
[0] == '<') {
4961 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
4962 if (cmp
[1] == '=') {
4963 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
4965 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
4967 } else if (cmp
[0] == '=') {
4968 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
4969 } else if (cmp
[0] == '>') {
4970 if (cmp
[1] == '=') {
4971 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
4973 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
4976 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
4978 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
4979 && (irccasecmp(argv
[++i
], "opers") == 0)) {
4980 discrim
->match_opers
= 1;
4981 } else if (irccasecmp(argv
[i
], "depth") == 0) {
4982 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
4983 } else if (irccasecmp(argv
[i
], "clones") == 0) {
4984 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
4986 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
4991 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
4992 discrim
->mask_nick
= 0;
4994 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
4995 discrim
->mask_ident
= 0;
4997 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
4998 discrim
->mask_info
= 0;
5000 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
5001 discrim
->mask_host
= 0;
5004 if(discrim
->use_regex
)
5006 if(discrim
->mask_nick
)
5008 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5009 discrim
->has_regex_nick
= !err
;
5013 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
5015 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
5020 if(discrim
->mask_ident
)
5022 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5023 discrim
->has_regex_ident
= !err
;
5027 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
5029 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
5034 if(discrim
->mask_host
)
5036 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5037 discrim
->has_regex_host
= !err
;
5041 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
5043 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
5048 if(discrim
->mask_info
)
5050 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5051 discrim
->has_regex_info
= !err
;
5055 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
5057 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
5070 if(discrim
->has_regex_nick
)
5071 regfree(&discrim
->regex_nick
);
5072 if(discrim
->has_regex_ident
)
5073 regfree(&discrim
->regex_ident
);
5074 if(discrim
->has_regex_host
)
5075 regfree(&discrim
->regex_host
);
5076 if(discrim
->has_regex_info
)
5077 regfree(&discrim
->regex_info
);
5084 discrim_match(discrim_t discrim
, struct userNode
*user
)
5086 unsigned int access
;
5087 char *scmp
=NULL
, *dcmp
=NULL
;
5089 if ((user
->timestamp
< discrim
->min_ts
)
5090 || (user
->timestamp
> discrim
->max_ts
)
5091 || (user
->channels
.used
< discrim
->min_channels
)
5092 || (user
->channels
.used
> discrim
->max_channels
)
5093 || (discrim
->authed
== 0 && user
->handle_info
)
5094 || (discrim
->authed
== 1 && !user
->handle_info
)
5095 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
5096 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
5097 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
5098 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
5099 || (discrim
->ip_mask_bits
&& !irc_check_mask(&user
->ip
, &discrim
->ip_mask
, discrim
->ip_mask_bits
))
5103 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
))
5106 if(discrim
->use_regex
)
5108 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
5109 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
5110 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
5111 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))) {
5117 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
5118 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
5119 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
5120 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))) {
5125 if ((discrim
->intra_scmp
> 0 && discrim
->intra_dcmp
> 0)) {
5126 switch(discrim
->intra_scmp
) {
5127 case 1: scmp
=user
->nick
; break;
5128 case 2: scmp
=user
->ident
; break;
5131 if (discrim
->info_space
== 1) scmp
++;
5134 switch(discrim
->intra_dcmp
) {
5135 case 1: dcmp
=user
->nick
; break;
5136 case 2: dcmp
=user
->ident
; break;
5137 case 3: /* When checking INFO, and info_space is enabled
5138 * ignore the first character in a search
5139 * XXX: Should we ignore ALL leading whitespace?
5140 * Also, what about ignoring ~ in ident?
5143 if (discrim
->info_space
== 1) dcmp
++;
5146 if (irccasecmp(scmp
,dcmp
))
5150 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
5151 if ((access
< discrim
->min_level
)
5152 || (access
> discrim
->max_level
)) {
5155 if (discrim
->min_clones
> 1) {
5156 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&user
->ip
), NULL
);
5157 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
))
5164 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
5166 unsigned int nn
, count
;
5167 struct userList matched
;
5169 userList_init(&matched
);
5170 /* Try most optimized search methods first */
5171 if (discrim
->channel
) {
5173 (nn
< discrim
->channel
->members
.used
)
5174 && (matched
.used
< discrim
->limit
);
5176 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
5177 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
5178 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
5181 if (discrim_match(discrim
, mn
->user
)) {
5182 userList_append(&matched
, mn
->user
);
5185 } else if (discrim
->ip_mask_bits
== 128) {
5186 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&discrim
->ip_mask
), NULL
);
5188 userList_clean(&matched
);
5191 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
5192 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
5193 userList_append(&matched
, ohi
->clients
.list
[nn
]);
5198 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
5199 if (discrim_match(discrim
, iter_data(it
))) {
5200 userList_append(&matched
, iter_data(it
));
5205 if (!matched
.used
) {
5206 userList_clean(&matched
);
5210 if (discrim
->option_log
) {
5211 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
5213 for (nn
=0; nn
<matched
.used
; nn
++) {
5214 struct userNode
*user
= matched
.list
[nn
];
5215 if (discrim
->option_log
) {
5216 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
5218 if (dsf(user
, data
)) {
5219 /* If a search function returns true, it ran into a
5220 problem. Stop going through the list. */
5224 if (discrim
->option_log
) {
5225 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
5227 count
= matched
.used
;
5228 userList_clean(&matched
);
5233 trace_print_func(struct userNode
*match
, void *extra
)
5235 struct discrim_and_source
*das
= extra
;
5236 if (match
->handle_info
) {
5237 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
);
5239 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
5245 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
5251 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
5253 return !(IsService(target
)
5254 || (!match_opers
&& IsOper(target
))
5255 || (target
->handle_info
5256 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
5260 trace_gline_func(struct userNode
*match
, void *extra
)
5262 struct discrim_and_source
*das
= extra
;
5264 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5265 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
, das
->discrim
->silent
);
5272 trace_shun_func(struct userNode
*match
, void *extra
)
5274 struct discrim_and_source
*das
= extra
;
5276 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5277 opserv_shun(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
5284 trace_kill_func(struct userNode
*match
, void *extra
)
5286 struct discrim_and_source
*das
= extra
;
5288 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5290 if (das
->discrim
->reason
) {
5291 reason
= das
->discrim
->reason
;
5293 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
5294 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
5296 DelUser(match
, opserv
, 1, reason
);
5303 is_gagged(char *mask
)
5305 struct gag_entry
*gag
;
5307 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5308 if (match_ircglobs(gag
->mask
, mask
)) return 1;
5314 trace_gag_func(struct userNode
*match
, void *extra
)
5316 struct discrim_and_source
*das
= extra
;
5318 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5319 char *reason
, *mask
;
5321 if (das
->discrim
->reason
) {
5322 reason
= das
->discrim
->reason
;
5324 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
5325 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
5327 masksize
= 5+strlen(match
->hostname
);
5328 mask
= alloca(masksize
);
5329 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
5330 if (!is_gagged(mask
)) {
5331 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
5332 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
5340 trace_domains_func(struct userNode
*match
, void *extra
)
5342 struct discrim_and_source
*das
= extra
;
5344 unsigned long *count
;
5347 char ipmask
[IRC_NTOP_MASK_MAX_SIZE
];
5349 if (irc_pton(&ip
, NULL
, match
->hostname
)) {
5350 if (irc_in_addr_is_ipv4(ip
)) {
5351 unsigned long matchip
= ntohl(ip
.in6_32
[3]);
5352 /* raw IP address.. use up to first three octets of IP */
5353 switch (das
->discrim
->domain_depth
) {
5355 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
5358 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
5361 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
5364 } else if (irc_in_addr_is_ipv6(ip
)) {
5365 switch (das
->discrim
->domain_depth
) {
5366 case 1: depth
= 16; goto ipv6_pfx
;
5367 case 2: depth
= 24; goto ipv6_pfx
;
5368 case 3: depth
= 32; goto ipv6_pfx
;
5369 default: depth
= das
->discrim
->domain_depth
;
5371 irc_ntop_mask(ipmask
, sizeof(ipmask
), &ip
, depth
);
5373 } else safestrncpy(ipmask
, match
->hostname
, sizeof(ipmask
));
5374 ipmask
[sizeof(ipmask
) - 1] = '\0';
5377 hostname
= match
->hostname
+ strlen(match
->hostname
);
5378 for (depth
=das
->discrim
->domain_depth
;
5379 depth
&& (hostname
> match
->hostname
);
5382 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
5384 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
5386 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
5387 count
= calloc(1, sizeof(*count
));
5388 dict_insert(das
->dict
, strdup(hostname
), count
);
5395 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
5397 unsigned long *count
= data
;
5398 struct discrim_and_source
*das
= extra
;
5400 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
5401 return !--das
->disp_limit
;
5404 static MODCMD_FUNC(cmd_trace
)
5406 struct discrim_and_source das
;
5407 discrim_search_func action
;
5408 unsigned int matches
;
5409 struct svccmd
*subcmd
;
5412 sprintf(buf
, "trace %s", argv
[1]);
5413 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
5414 reply("OSMSG_BAD_ACTION", argv
[1]);
5417 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
5419 if (!irccasecmp(argv
[1], "print"))
5420 action
= trace_print_func
;
5421 else if (!irccasecmp(argv
[1], "count"))
5422 action
= trace_count_func
;
5423 else if (!irccasecmp(argv
[1], "domains"))
5424 action
= trace_domains_func
;
5425 else if (!irccasecmp(argv
[1], "gline"))
5426 action
= trace_gline_func
;
5427 else if (!irccasecmp(argv
[1], "shun"))
5428 action
= trace_shun_func
;
5429 else if (!irccasecmp(argv
[1], "kill"))
5430 action
= trace_kill_func
;
5431 else if (!irccasecmp(argv
[1], "gag"))
5432 action
= trace_gag_func
;
5434 reply("OSMSG_BAD_ACTION", argv
[1]);
5438 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
5439 reply("OSMSG_LEVEL_TOO_LOW");
5445 das
.destination
= cmd
->parent
->bot
;
5446 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
5450 if (action
== trace_print_func
)
5452 reply("OSMSG_USER_SEARCH_RESULTS");
5453 reply("OSMSG_USER_SEARCH_BAR");
5454 reply("OSMSG_USER_SEARCH_HEADER");
5455 reply("OSMSG_USER_SEARCH_BAR");
5457 else if (action
== trace_count_func
)
5458 das
.discrim
->limit
= INT_MAX
;
5459 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
5460 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
5461 else if ((action
== trace_shun_func
) && !das
.discrim
->duration
)
5462 das
.discrim
->duration
= opserv_conf
.block_shun_duration
;
5463 else if (action
== trace_domains_func
) {
5464 das
.dict
= dict_new();
5465 dict_set_free_data(das
.dict
, free
);
5466 dict_set_free_keys(das
.dict
, free
);
5467 das
.disp_limit
= das
.discrim
->limit
;
5468 das
.discrim
->limit
= INT_MAX
;
5470 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
5472 if (action
== trace_domains_func
)
5473 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
5477 if(action
== trace_print_func
)
5478 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
5480 reply("OSMSG_USER_SEARCH_COUNT", matches
);
5483 reply("MSG_NO_MATCHES");
5485 if (das
.discrim
->channel
)
5486 UnlockChannel(das
.discrim
->channel
);
5487 free(das
.discrim
->reason
);
5489 if(das
.discrim
->has_regex_nick
)
5490 regfree(&das
.discrim
->regex_nick
);
5491 if(das
.discrim
->has_regex_ident
)
5492 regfree(&das
.discrim
->regex_ident
);
5493 if(das
.discrim
->has_regex_host
)
5494 regfree(&das
.discrim
->regex_host
);
5495 if(das
.discrim
->has_regex_info
)
5496 regfree(&das
.discrim
->regex_info
);
5499 dict_delete(das
.dict
);
5503 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
5505 typedef struct channel_discrim
{
5508 unsigned int min_users
, max_users
;
5509 time_t min_ts
, max_ts
;
5513 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
5514 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
5517 smart_parse_time(const char *str
) {
5518 /* If an interval-style string is given, treat as time before now.
5519 * If it's all digits, treat directly as a Unix timestamp. */
5520 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
5524 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
5529 discrim
= calloc(1, sizeof(*discrim
));
5530 discrim
->limit
= 25;
5532 for (i
= 0; i
< argc
; i
++) {
5533 /* Assume all criteria require arguments. */
5534 if (i
== (argc
- 1)) {
5535 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5539 if (!irccasecmp(argv
[i
], "name"))
5540 discrim
->name
= argv
[++i
];
5541 else if (!irccasecmp(argv
[i
], "topic"))
5542 discrim
->topic
= argv
[++i
];
5543 else if (!irccasecmp(argv
[i
], "users")) {
5544 const char *cmp
= argv
[++i
];
5545 if (cmp
[0] == '<') {
5547 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
5549 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
5550 } else if (cmp
[0] == '=') {
5551 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
5552 } else if (cmp
[0] == '>') {
5554 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
5556 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
5558 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
5560 } else if (!irccasecmp(argv
[i
], "timestamp")) {
5561 const char *cmp
= argv
[++i
];
5562 if (cmp
[0] == '<') {
5564 discrim
->max_ts
= smart_parse_time(cmp
+2);
5566 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
5567 } else if (cmp
[0] == '=') {
5568 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
5569 } else if (cmp
[0] == '>') {
5571 discrim
->min_ts
= smart_parse_time(cmp
+2);
5573 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
5575 discrim
->min_ts
= smart_parse_time(cmp
);
5577 } else if (!irccasecmp(argv
[i
], "limit")) {
5578 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
5580 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
5585 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
5587 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
5597 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
5599 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
5600 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
5601 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
5602 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
5603 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
5604 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
5610 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
5612 unsigned int count
= 0;
5613 dict_iterator_t it
, next
;
5615 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
5616 struct chanNode
*chan
= iter_data(it
);
5618 /* Hold on to the next channel in case we decide to
5619 add actions that destructively modify the channel. */
5620 next
= iter_next(it
);
5621 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
5622 dsf(chan
, data
, bot
);
5630 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
5634 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
5637 irc_make_chanmode(channel
, modes
);
5638 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
5641 static MODCMD_FUNC(cmd_csearch
)
5644 unsigned int matches
;
5645 cdiscrim_search_func action
;
5646 struct svccmd
*subcmd
;
5649 if (!irccasecmp(argv
[1], "count"))
5650 action
= channel_count
;
5651 else if (!irccasecmp(argv
[1], "print"))
5652 action
= channel_print
;
5654 reply("OSMSG_BAD_ACTION", argv
[1]);
5658 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
5659 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
5660 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
5664 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
5668 if (action
== channel_print
)
5669 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
5670 else if (action
== channel_count
)
5671 discrim
->limit
= INT_MAX
;
5673 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
5676 reply("MSG_MATCH_COUNT", matches
);
5678 reply("MSG_NO_MATCHES");
5684 static MODCMD_FUNC(cmd_gsync
)
5688 src
= GetServerH(argv
[1]);
5690 reply("MSG_SERVER_UNKNOWN", argv
[1]);
5696 irc_stats(cmd
->parent
->bot
, src
, 'G');
5697 reply("OSMSG_GSYNC_RUNNING", src
->name
);
5701 static MODCMD_FUNC(cmd_ssync
)
5705 src
= GetServerH(argv
[1]);
5707 reply("MSG_SERVER_UNKNOWN", argv
[1]);
5713 irc_stats(cmd
->parent
->bot
, src
, 'S');
5714 reply("OSMSG_SSYNC_RUNNING", src
->name
);
5718 struct gline_extra
{
5719 struct userNode
*user
;
5720 struct string_list
*glines
;
5721 struct userNode
*bot
;
5725 gtrace_print_func(struct gline
*gline
, void *extra
)
5727 struct gline_extra
*xtra
= extra
;
5728 char *when_text
, set_text
[20];
5729 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
5730 when_text
= asctime(localtime(&gline
->expires
));
5731 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
5732 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
5736 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
5741 gtrace_ungline_func(struct gline
*gline
, void *extra
)
5743 struct gline_extra
*xtra
= extra
;
5744 string_list_append(xtra
->glines
, strdup(gline
->target
));
5747 static MODCMD_FUNC(cmd_gtrace
)
5749 struct gline_discrim
*discrim
;
5750 gline_search_func action
;
5751 unsigned int matches
, nn
;
5752 struct gline_extra extra
;
5753 struct svccmd
*subcmd
;
5756 if (!irccasecmp(argv
[1], "print"))
5757 action
= gtrace_print_func
;
5758 else if (!irccasecmp(argv
[1], "count"))
5759 action
= gtrace_count_func
;
5760 else if (!irccasecmp(argv
[1], "ungline"))
5761 action
= gtrace_ungline_func
;
5763 reply("OSMSG_BAD_ACTION", argv
[1]);
5766 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
5767 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
5768 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
5772 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
5776 if (action
== gtrace_print_func
)
5777 reply("OSMSG_GLINE_SEARCH_RESULTS");
5778 else if (action
== gtrace_count_func
)
5779 discrim
->limit
= INT_MAX
;
5782 extra
.glines
= alloc_string_list(4);
5783 extra
.bot
= cmd
->parent
->bot
;
5784 matches
= gline_discrim_search(discrim
, action
, &extra
);
5786 if (action
== gtrace_ungline_func
)
5787 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
5788 gline_remove(extra
.glines
->list
[nn
], 1);
5789 free_string_list(extra
.glines
);
5792 reply("MSG_MATCH_COUNT", matches
);
5794 reply("MSG_NO_MATCHES");
5795 free(discrim
->alt_target_mask
);
5801 struct userNode
*user
;
5802 struct string_list
*shuns
;
5803 struct userNode
*bot
;
5807 strace_print_func(struct shun
*shun
, void *extra
)
5809 struct shun_extra
*xtra
= extra
;
5810 char *when_text
, set_text
[20];
5811 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&shun
->issued
));
5812 when_text
= asctime(localtime(&shun
->expires
));
5813 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
5814 send_message(xtra
->user
, xtra
->bot
, "OSMSG_STRACE_FORMAT", shun
->target
, set_text
, shun
->issuer
, when_text
, shun
->reason
);
5818 strace_count_func(UNUSED_ARG(struct shun
*shun
), UNUSED_ARG(void *extra
))
5823 strace_unshun_func(struct shun
*shun
, void *extra
)
5825 struct shun_extra
*xtra
= extra
;
5826 string_list_append(xtra
->shuns
, strdup(shun
->target
));
5829 static MODCMD_FUNC(cmd_strace
)
5831 struct shun_discrim
*discrim
;
5832 shun_search_func action
;
5833 unsigned int matches
, nn
;
5834 struct shun_extra extra
;
5835 struct svccmd
*subcmd
;
5838 if (!irccasecmp(argv
[1], "print"))
5839 action
= strace_print_func
;
5840 else if (!irccasecmp(argv
[1], "count"))
5841 action
= strace_count_func
;
5842 else if (!irccasecmp(argv
[1], "unshun"))
5843 action
= strace_unshun_func
;
5845 reply("OSMSG_BAD_ACTION", argv
[1]);
5848 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
5849 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
5850 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
5854 discrim
= shun_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
5858 if (action
== strace_print_func
)
5859 reply("OSMSG_SHUN_SEARCH_RESULTS");
5860 else if (action
== strace_count_func
)
5861 discrim
->limit
= INT_MAX
;
5864 extra
.shuns
= alloc_string_list(4);
5865 extra
.bot
= cmd
->parent
->bot
;
5866 matches
= shun_discrim_search(discrim
, action
, &extra
);
5868 if (action
== strace_unshun_func
)
5869 for (nn
=0; nn
<extra
.shuns
->used
; nn
++)
5870 shun_remove(extra
.shuns
->list
[nn
], 1);
5871 free_string_list(extra
.shuns
);
5874 reply("MSG_MATCH_COUNT", matches
);
5876 reply("MSG_NO_MATCHES");
5877 free(discrim
->alt_target_mask
);
5883 alert_check_user(const char *key
, void *data
, void *extra
)
5885 struct opserv_user_alert
*alert
= data
;
5886 struct userNode
*user
= extra
;
5888 if (!discrim_match(alert
->discrim
, user
))
5891 if ((alert
->reaction
!= REACT_NOTICE
)
5893 && !alert
->discrim
->match_opers
) {
5897 /* The user matches the alert criteria, so trigger the reaction. */
5898 if (alert
->discrim
->option_log
)
5899 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
);
5901 /* Return 1 to halt alert matching, such as when killing the user
5902 that triggered the alert. */
5903 switch (alert
->reaction
) {
5905 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
5909 opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, 1);
5913 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
, alert
->discrim
->silent
);
5916 opserv_shun(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
5919 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
5920 /* fall through to REACT_NOTICE case */
5922 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
);
5926 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
);
5927 add_track_user(user
);
5935 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
5937 struct gag_entry
*gag
;
5938 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
5939 /* Gag them if appropriate (and only if). */
5940 user
->modes
&= ~FLAGS_GAGGED
;
5941 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5942 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
5943 gag_helper_func(user
, NULL
);
5950 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
5954 if (!opserv_conf
.staff_auth_channel
5955 || user
->uplink
->burst
5956 || !user
->handle_info
)
5958 else if (user
->handle_info
->opserv_level
)
5960 else if (IsNetworkHelper(user
))
5961 type
= "NETWORK HELPER";
5962 else if (IsSupportHelper(user
))
5963 type
= "SUPPORT HELPER";
5967 if (irc_in_addr_is_valid(user
->ip
))
5968 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
5970 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
);
5973 static MODCMD_FUNC(cmd_log
)
5975 struct logSearch
*discrim
;
5976 unsigned int matches
;
5977 struct logReport report
;
5979 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
5983 reply("OSMSG_LOG_SEARCH_RESULTS");
5984 report
.reporter
= opserv
;
5986 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
5989 reply("MSG_MATCH_COUNT", matches
);
5991 reply("MSG_NO_MATCHES");
5998 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6000 if (IsOper(match
) || IsLocal(match
))
6002 match
->modes
|= FLAGS_GAGGED
;
6006 static MODCMD_FUNC(cmd_gag
)
6008 struct gag_entry
*gag
;
6009 unsigned int gagged
;
6010 unsigned long duration
;
6013 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
6015 if (!is_ircmask(argv
[1])) {
6016 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
6020 for (gag
= gagList
; gag
; gag
= gag
->next
)
6021 if (match_ircglobs(gag
->mask
, argv
[1]))
6025 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
6029 duration
= ParseInterval(argv
[2]);
6030 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
6033 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
6035 reply("OSMSG_GAG_ADDED", argv
[1]);
6040 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6042 match
->modes
&= ~FLAGS_GAGGED
;
6046 static MODCMD_FUNC(cmd_ungag
)
6048 struct gag_entry
*gag
;
6049 unsigned int ungagged
;
6051 for (gag
= gagList
; gag
; gag
= gag
->next
)
6052 if (!strcmp(gag
->mask
, argv
[1]))
6056 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
6060 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
6061 ungagged
= gag_free(gag
);
6064 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
6066 reply("OSMSG_UNGAG_ADDED", argv
[1]);
6070 static MODCMD_FUNC(cmd_addalert
)
6072 opserv_alert_reaction reaction
;
6073 struct svccmd
*subcmd
;
6078 sprintf(buf
, "addalert %s", argv
[2]);
6079 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6080 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6083 if (!irccasecmp(argv
[2], "notice"))
6084 reaction
= REACT_NOTICE
;
6085 else if (!irccasecmp(argv
[2], "kill"))
6086 reaction
= REACT_KILL
;
6088 else if (!irccasecmp(argv[2], "silent"))
6089 reaction = REACT_SILENT;
6091 else if (!irccasecmp(argv
[2], "gline"))
6092 reaction
= REACT_GLINE
;
6093 else if (!irccasecmp(argv
[2], "track")) {
6095 reply("OSMSG_TRACK_DISABLED");
6098 reaction
= REACT_TRACK
;
6100 } else if (!irccasecmp(argv
[2], "shun"))
6101 reaction
= REACT_SHUN
;
6103 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6106 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
6107 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
)))
6109 reply("OSMSG_ADDED_ALERT", name
);
6113 static MODCMD_FUNC(cmd_delalert
)
6116 for (i
=1; i
<argc
; i
++) {
6117 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
6118 dict_remove(opserv_channel_alerts
, argv
[i
]);
6119 if (dict_remove(opserv_user_alerts
, argv
[i
]))
6120 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
6122 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
6128 opserv_conf_read(void)
6130 struct chanNode
*chan
;
6132 struct record_data
*rd
;
6133 dict_t conf_node
, child
;
6134 const char *str
, *str2
;
6135 struct policer_params
*pp
;
6138 rd
= conf_get_node(OPSERV_CONF_NAME
);
6139 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
6140 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
6143 conf_node
= rd
->d
.object
;
6144 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
6145 if (opserv
&& str
) {
6146 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
6149 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6150 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
6152 opserv_conf
.debug_channel
= NULL
;
6154 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
6155 if (opserv
&& str
) {
6156 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
6159 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6160 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
6162 opserv_conf
.alert_channel
= NULL
;
6164 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
6165 if (opserv
&& str
) {
6166 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
6169 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6170 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
6172 opserv_conf
.staff_auth_channel
= NULL
;
6175 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
6176 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
6178 str
= database_get_data(conf_node
, KEY_SILENT_LEVEL
, RECDB_QSTRING
);
6179 opserv_conf
.silent_level
= str
? strtoul(str
, NULL
, 0): 700;
6181 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
6182 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
6183 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
6184 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
6185 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
6186 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
6187 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
6188 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
6189 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
6191 NickChange(opserv
, str
, 0);
6193 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
6194 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
6195 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
6196 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
6198 free_string_list(autojoin_channels
);
6199 autojoin_channels
= database_get_data(conf_node
, KEY_AUTOJOIN_CHANNELS
, RECDB_STRING_LIST
);
6201 if(autojoin_channels
)
6202 autojoin_channels
= string_list_copy(autojoin_channels
);
6204 if (autojoin_channels
&& opserv
) {
6205 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
6206 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
6207 AddChannelUser(opserv
, chan
)->modes
|= MODE_CHANOP
;
6211 str
= database_get_data(conf_node
, KEY_BLOCK_SHUN_DURATION
, RECDB_QSTRING
);
6212 opserv_conf
.block_shun_duration
= str
? ParseInterval(str
) : 3600;
6214 if (!opserv_conf
.join_policer_params
)
6215 opserv_conf
.join_policer_params
= policer_params_new();
6216 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
6217 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
6218 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
6219 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
6221 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
6222 struct chanNode
*cNode
= iter_data(it
);
6223 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
6226 if (opserv_conf
.new_user_policer
.params
)
6227 pp
= opserv_conf
.new_user_policer
.params
;
6229 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
6230 policer_params_set(pp
, "size", "200");
6231 policer_params_set(pp
, "drain-rate", "3");
6232 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
6233 dict_foreach(child
, set_policer_param
, pp
);
6235 /* Defcon configuration */
6237 str
= database_get_data(conf_node
, KEY_DEFCON1
, RECDB_QSTRING
);
6238 DefCon
[1] = str
? atoi(str
) : 415;
6239 str
= database_get_data(conf_node
, KEY_DEFCON2
, RECDB_QSTRING
);
6240 DefCon
[2] = str
? atoi(str
) : 159;
6241 str
= database_get_data(conf_node
, KEY_DEFCON3
, RECDB_QSTRING
);
6242 DefCon
[3] = str
? atoi(str
) : 31;
6243 str
= database_get_data(conf_node
, KEY_DEFCON4
, RECDB_QSTRING
);
6244 DefCon
[4] = str
? atoi(str
) : 23;
6247 str
= database_get_data(conf_node
, KEY_DEFCON_LEVEL
, RECDB_QSTRING
);
6248 DefConLevel
= str
? atoi(str
) : 5;
6250 str
= database_get_data(conf_node
, KEY_DEFCON_CHANMODES
, RECDB_QSTRING
);
6251 DefConChanModes
= str
? strdup(str
) : "+r";
6253 str
= database_get_data(conf_node
, KEY_DEFCON_SESSION_LIMIT
, RECDB_QSTRING
);
6254 DefConSessionLimit
= str
? atoi(str
) : 2;
6256 str
= database_get_data(conf_node
, KEY_DEFCON_TIMEOUT
, RECDB_QSTRING
);
6257 DefConTimeOut
= str
? ParseInterval(str
) : 900;
6259 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_DURATION
, RECDB_QSTRING
);
6260 DefConGlineExpire
= str
? ParseInterval(str
) : 300;
6262 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL
, RECDB_QSTRING
);
6263 GlobalOnDefcon
= str
? atoi(str
) : 0;
6265 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL_MORE
, RECDB_QSTRING
);
6266 GlobalOnDefconMore
= str
? atoi(str
) : 0;
6268 str
= database_get_data(conf_node
, KEY_DEFCON_MESSAGE
, RECDB_QSTRING
);
6269 DefConMessage
= str
? strdup(str
) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore";
6271 str
= database_get_data(conf_node
, KEY_DEFCON_OFF_MESSAGE
, RECDB_QSTRING
);
6272 DefConOffMessage
= str
? strdup(str
) : "Services are now back to normal, sorry for any inconvenience";
6274 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_REASON
, RECDB_QSTRING
);
6275 DefConGlineReason
= str
? strdup(str
) : "This network is currently not accepting connections, please try again later";
6278 /* lame way to export opserv_conf value to nickserv.c ... */
6280 opserv_conf_admin_level()
6282 return(opserv_conf
.admin_level
);
6286 opserv_db_init(void) {
6287 /* set up opserv_trusted_hosts dict */
6288 dict_delete(opserv_trusted_hosts
);
6289 opserv_trusted_hosts
= dict_new();
6290 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
6292 opserv_routing_plan_options
= dict_new();
6294 opserv_routing_plans
= dict_new();
6295 dict_set_free_data(opserv_routing_plans
, free_routing_plan
);
6296 /* set up opserv_chan_warn dict */
6298 /* alert trace notice channel #x replaces warnings
6299 dict_delete(opserv_chan_warn);
6300 opserv_chan_warn = dict_new();
6301 dict_set_free_keys(opserv_chan_warn, free);
6302 dict_set_free_data(opserv_chan_warn, free);
6304 /* set up opserv_user_alerts */
6305 dict_delete(opserv_channel_alerts
);
6306 opserv_channel_alerts
= dict_new();
6307 dict_delete(opserv_nick_based_alerts
);
6308 opserv_nick_based_alerts
= dict_new();
6309 dict_delete(opserv_user_alerts
);
6310 opserv_user_alerts
= dict_new();
6311 dict_set_free_keys(opserv_user_alerts
, free
);
6312 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
6313 /* set up opserv_bad_words */
6314 free_string_list(opserv_bad_words
);
6315 opserv_bad_words
= alloc_string_list(4);
6316 /* and opserv_exempt_channels */
6317 dict_delete(opserv_exempt_channels
);
6318 opserv_exempt_channels
= dict_new();
6319 dict_set_free_keys(opserv_exempt_channels
, free
);
6323 opserv_db_cleanup(void)
6327 /* dict_delete(opserv_chan_warn); */
6328 dict_delete(opserv_reserved_nick_dict
);
6329 free_string_list(opserv_bad_words
);
6330 dict_delete(opserv_exempt_channels
);
6331 dict_delete(opserv_trusted_hosts
);
6332 unreg_del_user_func(opserv_user_cleanup
);
6333 dict_delete(opserv_hostinfo_dict
);
6334 dict_delete(opserv_nick_based_alerts
);
6335 dict_delete(opserv_channel_alerts
);
6336 dict_delete(opserv_user_alerts
);
6337 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
6338 free(level_strings
[nn
]);
6341 policer_params_delete(opserv_conf
.join_policer_params
);
6342 policer_params_delete(opserv_conf
.new_user_policer
.params
);
6346 init_opserv(const char *nick
)
6348 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
6350 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
6351 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
6353 conf_register_reload(opserv_conf_read
);
6355 memset(level_strings
, 0, sizeof(level_strings
));
6356 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
6357 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
6358 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
6359 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
6360 opserv_define_func("ADDALERT SILENT", NULL
, 900, 0, 0);
6361 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
6362 opserv_define_func("ADDALERT SHUN", NULL
, 900, 0, 0);
6363 opserv_define_func("ADDALERT TRACK", NULL
, 900, 0, 0);
6364 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
6365 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
6366 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
6367 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
6368 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
6369 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
6370 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
6371 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
6372 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
6373 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
6374 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
6375 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
6376 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
6377 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
6378 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
6379 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
6380 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
6381 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
6382 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
6383 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
6384 opserv_define_func("DEFCON", cmd_defcon
, 900, 0, 0);
6385 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
6386 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
6387 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
6388 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
6389 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
6390 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
6391 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
6392 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
6393 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
6394 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
6395 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
6396 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
6397 opserv_define_func("SBLOCK", cmd_sblock
, 100, 0, 2);
6398 opserv_define_func("SHUN", cmd_shun
, 600, 0, 4);
6399 opserv_define_func("SSYNC", cmd_ssync
, 600, 0, 0);
6400 opserv_define_func("STRACE", cmd_strace
, 100, 0, 3);
6401 opserv_define_func("STRACE COUNT", NULL
, 0, 0, 0);
6402 opserv_define_func("STRACE PRINT", NULL
, 0, 0, 0);
6403 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
6404 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
6405 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
6406 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
6407 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
6408 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
6409 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
6410 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
6411 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
6412 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
6413 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
6414 opserv_define_func("OP", cmd_op
, 100, 2, 2);
6415 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
6416 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
6417 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
6418 opserv_define_func("MAP", cmd_stats_links
, 0, 0, 0);
6419 opserv_define_func("PART", cmd_part
, 601, 0, 2);
6420 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
6421 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
6422 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
6423 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
6424 opserv_define_func("REFRESHS", cmd_refreshs
, 600, 0, 0);
6425 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
6426 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
6427 opserv_define_func("RESETMAX", cmd_resetmax
, 900, 0, 0);
6428 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
6429 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
6430 opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan
, 800, 0, 2);
6431 opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan
, 800, 0, 2);
6432 opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver
, 800, 0, 4);
6433 opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver
, 800, 0, 3);
6434 opserv_define_func("ROUTING MAP", cmd_routing_map
, 800, 0, 0);
6435 opserv_define_func("ROUTING SET", cmd_routing_set
, 800, 0, 0);
6436 opserv_define_func("REROUTE", cmd_reroute
, 800, 0, 2);
6437 opserv_define_func("SET", cmd_set
, 900, 0, 3);
6438 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
6439 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
6440 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
6441 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
6442 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
6443 opserv_define_func("STATS SHUNS", cmd_stats_shuns
, 0, 0, 0);
6444 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
6445 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
6446 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
6447 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
6448 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
6449 opserv_define_func("STATS ROUTING", cmd_stats_routing_plans
, 0, 0, 0);
6450 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
6451 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
6452 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
6453 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
6454 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
6455 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
6456 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
6458 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
6459 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
6460 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
6461 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
6462 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
6463 opserv_define_func("TRACE SHUN", NULL
, 600, 0, 0);
6464 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
6465 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
6466 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
6467 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
6468 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
6469 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
6470 opserv_define_func("UNSHUN", cmd_unshun
, 600, 0, 2);
6471 modcmd_register(opserv_module
, "GTRACE UNSHUN", NULL
, 0, 0, "template", "unshun", NULL
);
6472 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
6473 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
6474 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
6475 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
6476 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
6477 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
6479 opserv_reserved_nick_dict
= dict_new();
6480 opserv_hostinfo_dict
= dict_new();
6482 dict_set_free_keys(opserv_hostinfo_dict
, free
);
6483 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
6485 opserv_waiting_connections
= dict_new();
6486 dict_set_free_data(opserv_waiting_connections
, opserv_free_waiting_connection
);
6488 reg_new_user_func(opserv_new_user_check
);
6489 reg_nick_change_func(opserv_alert_check_nick
);
6490 reg_del_user_func(opserv_user_cleanup
);
6491 reg_new_channel_func(opserv_channel_check
);
6492 reg_del_channel_func(opserv_channel_delete
);
6493 reg_join_func(opserv_join_check
);
6494 reg_auth_func(opserv_staff_alert
);
6497 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
6500 opserv_service
= service_register(opserv
);
6501 opserv_service
->trigger
= '?';
6504 /* start auto-routing system */
6505 reroute_timer(NULL
);
6506 /* start the karma timer, using the saved one if available */
6507 routing_karma_timer(dict_find(opserv_routing_plan_options
, "KARMA_TIMER", NULL
));
6509 reg_exit_func(opserv_db_cleanup
);
6510 message_register_table(msgtab
);