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 3 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.
36 #include <tre/regex.h>
38 #ifdef HAVE_SYS_TIMES_H
39 #include <sys/times.h>
41 #ifdef HAVE_NETINET_IN_H
42 #include <netinet/in.h>
44 #ifdef HAVE_ARPA_INET_H
45 #include <arpa/inet.h>
48 #define OPSERV_CONF_NAME "services/opserv"
50 #define KEY_ALERT_CHANNEL "alert_channel"
51 #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes"
52 #define KEY_DEBUG_CHANNEL "debug_channel"
53 #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes"
54 #define KEY_UNTRUSTED_MAX "untrusted_max"
55 #define KEY_PURGE_LOCK_DELAY "purge_lock_delay"
56 #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate"
57 #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold"
58 #define KEY_NICK "nick"
59 #define KEY_JOIN_POLICER "join_policer"
60 #define KEY_NEW_USER_POLICER "new_user_policer"
61 #define KEY_AUTOJOIN_CHANNELS "autojoin_channels"
62 #define KEY_REASON "reason"
63 #define KEY_RESERVES "reserves"
64 #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */
65 #define KEY_HOSTNAME "hostname"
66 #define KEY_DESC "description"
67 #define KEY_BAD_WORDS "bad"
68 #define KEY_EXEMPT_CHANNELS "exempt"
69 #define KEY_SECRET_WORDS "secret"
70 #define KEY_TRUSTED_HOSTS "trusted"
71 #define KEY_OWNER "owner"
72 #define KEY_GAGS "gags"
73 #define KEY_ALERTS "alerts"
74 #define KEY_REACTION "reaction"
75 #define KEY_DISCRIM "discrim"
76 #define KEY_WARN "chanwarn"
78 #define KEY_TIME "time"
79 #define KEY_LAST "last"
80 #define KEY_MAX_CLIENTS "max_clients"
81 #define KEY_LIMIT "limit"
82 #define KEY_EXPIRES "expires"
83 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
84 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
85 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
86 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
87 #define KEY_BLOCK_SHUN_DURATION "block_shun_duration"
88 #define KEY_ISSUER "issuer"
89 #define KEY_ISSUED "issued"
90 #define KEY_ADMIN_LEVEL "admin_level"
91 #define KEY_SILENT_LEVEL "silent_level"
92 #define KEY_UPLINK "uplink"
93 #define KEY_SECOND "secondaryuplink"
94 #define KEY_PORT "port"
95 #define KEY_KARMA "karma"
96 #define KEY_OFFLINE "offline"
97 #define KEY_ROUTINGPLAN "routingplan"
98 #define KEY_ROUTINGPLAN_OPTIONS "routingplan_options"
99 #define KEY_DEFCON1 "DefCon1"
100 #define KEY_DEFCON2 "DefCon2"
101 #define KEY_DEFCON3 "DefCon3"
102 #define KEY_DEFCON4 "DefCon4"
103 #define KEY_DEFCON_LEVEL "DefConLevel"
104 #define KEY_DEFCON_CHANMODES "DefConChanModes"
105 #define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit"
106 #define KEY_DEFCON_TIMEOUT "DefConTimeOut"
107 #define KEY_DEFCON_GLOBAL "GlobalOnDefcon"
108 #define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore"
109 #define KEY_DEFCON_MESSAGE "DefconMessage"
110 #define KEY_DEFCON_OFF_MESSAGE "DefConOffMessage"
111 #define KEY_DEFCON_GLINE_DURATION "DefConGlineExpire"
112 #define KEY_DEFCON_GLINE_REASON "DefConGlineReason"
114 /* Routing karma values: */
115 /* What value we start out with when new servers are added: */
116 #define KARMA_DEFAULT 10
119 #define KARMA_MIN -10
120 /* ping out, reduce karma by this much: */
121 #define KARMA_PINGOUT -8
122 /* read err, reduce karma by this much: */
123 #define KARMA_READERROR -5
124 /* every 24 hours everyone gets this much added (so we eventually re-try bad servers) */
125 #define KARMA_ENTROPE 1
126 /* every 24 hours servers linked for 24 hours get an additional ammount: */
127 #define KARMA_RELIABLE 1
128 /* How often to run entrope and reliable checks */
129 #define KARMA_TIMER 86400 /* 1 day */
131 #define ROUTING_CONNECT_TIMEOUT 30 /* 30 seconds */
133 #define IDENT_FORMAT "%s [%s@%s/%s]"
134 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, irc_ntoa(&user->ip)
135 #define MAX_CHANNELS_WHOIS 50
136 #define OSMSG_PART_REASON "%s has no reason."
137 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
138 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
139 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
141 static const struct message_entry msgtab
[] = {
142 { "OSMSG_BAR", "----------------------------------------" },
143 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
144 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
145 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
146 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
147 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
148 { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." },
149 { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." },
150 { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." },
151 { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." },
152 { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." },
153 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
154 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
155 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
156 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
157 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
158 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
159 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
160 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
161 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
162 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
163 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
164 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
165 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
166 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
167 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
168 { "OSMSG_USER_ALREADY_THERE", "%s is already in $b%s$b." },
169 { "OSMSG_NOT_THERE", "You not in $b%s$b." },
170 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
171 { "OSMSG_MARK_SET", "Set the MARK." },
172 { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." },
173 { "OSMSG_SVSPART_SENT", "Sent the SVSPART." },
174 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
175 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
176 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
177 { "OSMSG_LEAVING", "Leaving $b%s$b." },
178 { "OSMSG_MARK_INVALID", "Sorry, marks must contain only letters, numbers, and dashes ('-')." },
179 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
180 { "OSMSG_OP_DONE", "Opped the requested lusers." },
181 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
182 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
183 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
184 { "OMSG_BAD_SVSNICK", "$b%s$b is an invalid nickname." },
186 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
187 { "OSMSG_WHOIS_NICK", "Nick : %s" },
188 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
189 { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" },
190 { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" },
191 { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" },
192 { "OSMSG_WHOIS_IP", "Real IP : %s" },
193 { "OSMSG_WHOIS_COUNTRY", "Country : %s" },
194 { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" },
195 { "OSMSG_WHOIS_CITY", "City : %s" },
196 { "OSMSG_WHOIS_REGION", "Region/State : %s" },
197 { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" },
198 { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" },
199 { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" },
200 { "OSMSG_WHOIS_MAP", "Map : %s" },
201 { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" },
202 { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" },
203 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
204 { "OSMSG_WHOIS_INFO", "Info : %s" },
205 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
206 { "OSMSG_WHOIS_SERVER", "Server : %s" },
207 { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" },
208 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
209 { "OSMSG_WHOIS_PRIVS", "IRCd Privs : %s" },
210 { "OSMSG_WHOIS_CHANNELS", "Channels : %s" },
211 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
212 { "OSMSG_WHOIS_VERSION", "Version : %s" },
213 { "OSMSG_WHOIS_MARK", "Mark : %s" },
214 { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" },
215 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
216 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
217 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
218 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
219 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
220 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
221 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
222 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
223 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
224 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
225 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
226 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
227 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
228 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
229 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
230 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
231 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
232 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
233 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
234 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
235 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
236 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
237 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
238 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
239 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
240 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
241 { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." },
242 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
243 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
244 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
245 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
246 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
247 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
248 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
249 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
250 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
251 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
252 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
253 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
254 { "OSMSG_LINE_DUMPED", "Raw line sent." },
255 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
256 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
257 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
258 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
259 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
260 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
261 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
262 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
263 { "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." },
264 { "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." },
265 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
266 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
267 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
268 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
269 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
270 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
271 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
272 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
273 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
274 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
275 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
276 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
277 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
278 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
279 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
280 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
281 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
282 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
283 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
284 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
285 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
286 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
287 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
288 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
289 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
290 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
291 { "OSMSG_MARK_NO_MARK", "MARK action requires mark criteria (what do you want to mark them as?)" },
292 { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" },
293 { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" },
294 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
295 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
296 { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" },
297 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
298 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
299 { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
300 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
301 { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
302 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
303 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
304 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
305 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
306 { "OSMSG_NO_GAGS", "No gags have been set." },
307 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
308 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
309 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
310 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
311 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
312 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
313 { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" },
314 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
315 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
316 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" },
317 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
318 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
319 { "OSMSG_ALERTS_DESC", " $uCriteria$u: %s" },
320 { "OSMSG_ALERTS_LAST", " $uTriggered$u: %s" },
321 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
322 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
323 /* routing messages */
324 { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" },
325 { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" },
326 { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" },
327 { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" },
328 { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" },
329 { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." },
330 { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." },
331 { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." },
332 { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." },
333 { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" },
334 { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" },
335 { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" },
336 { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." },
337 { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." },
338 { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." },
339 { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." },
340 { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." },
341 { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." },
342 { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." },
343 { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." },
344 { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." },
345 { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" },
346 { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" },
347 { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" },
348 { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" },
349 { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" },
350 { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." },
351 { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." },
352 { "OSMSG_CONNECT", "->connect %s %d %s" },
353 { "OSMSG_SQUIT", "->squit %s" },
354 { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" },
355 { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" },
356 { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." },
357 { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." },
358 { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." },
359 { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." },
360 { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." },
361 { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", },
362 { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." },
363 { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." },
365 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
366 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
367 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
368 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
369 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
370 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
371 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
372 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
373 { "OSMSG_INVALID_NUMERIC", "Invalid numeric" },
374 { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." },
375 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
376 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
378 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
379 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
380 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
381 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
382 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
383 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
384 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
386 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
387 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
388 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
389 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
390 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
391 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
392 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
393 { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." },
394 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
395 { "OSMSG_CHANINFO_HEADER", "%s Information" },
396 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
397 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
398 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
399 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
400 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
401 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
402 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
403 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
404 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
405 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
406 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
407 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
408 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
409 { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" },
410 { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" },
412 { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" },
413 { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" },
414 { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" },
415 { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" },
416 { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" },
417 { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" },
418 { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" },
419 { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" },
420 { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" },
421 { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" },
422 { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" },
423 { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" },
424 { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" },
425 { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" },
427 { "OSMSG_PRIV_UNKNOWN", "Unknown privilege flag %s, see /msg $O HELP PRIVFLAGS for a flag list" },
428 { "OSMSG_PRIV_SET", "Privilege flag %s has been %sset" },
433 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
438 int GlobalOnDefcon
= 0;
439 int GlobalOnDefconMore
= 0;
440 int DefConGlineExpire
;
441 int DefConModesSet
= 0;
442 unsigned int DefConSessionLimit
;
443 char *DefConChanModes
;
444 char *DefConGlineReason
;
446 char *DefConOffMessage
;
448 extern void add_track_user(struct userNode
*user
);
449 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
451 struct userNode
*opserv
;
452 static struct service
*opserv_service
;
454 /*static dict_t opserv_chan_warn; */ /* data is char* */
455 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
456 static struct string_list
*opserv_bad_words
;
457 static dict_t opserv_exempt_channels
; /* data is not used */
458 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
459 static dict_t opserv_routing_plans
; /* data is struct routingPlan */
460 static dict_t opserv_routing_plan_options
; /* data is a dict_t key->val list*/
461 static dict_t opserv_waiting_connections
; /* data is struct waitingConnection */
462 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
463 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
464 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
465 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
466 static struct module *opserv_module
;
467 static struct log_type
*OS_LOG
;
468 static unsigned int new_user_flood
;
469 static char *level_strings
[1001];
470 struct string_list
*autojoin_channels
;
471 struct route
*opserv_route
= NULL
; /* Main active routing table from activate_routing()*/
474 struct chanNode
*debug_channel
;
475 struct chanNode
*alert_channel
;
476 struct chanNode
*staff_auth_channel
;
477 struct policer_params
*join_policer_params
;
478 struct policer new_user_policer
;
479 unsigned long untrusted_max
;
480 unsigned long clone_gline_duration
;
481 unsigned long block_gline_duration
;
482 unsigned long block_shun_duration
;
483 unsigned long purge_lock_delay
;
484 unsigned long join_flood_moderate
;
485 unsigned long join_flood_moderate_threshold
;
486 unsigned long admin_level
;
487 unsigned long silent_level
;
490 struct trusted_host
{
504 struct gag_entry
*next
;
507 static struct gag_entry
*gagList
;
509 struct opserv_hostinfo
{
510 struct userList clients
;
511 struct trusted_host
*trusted
;
515 opserv_free_hostinfo(void *data
)
517 struct opserv_hostinfo
*ohi
= data
;
518 userList_clean(&ohi
->clients
);
523 opserv_free_waiting_connection(void *data
)
525 struct waitingConnection
*wc
= data
;
531 typedef struct opservDiscrim
{
532 struct chanNode
*channel
;
533 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *mask_version
, *server
, *reason
, *accountmask
, *chantarget
, *mark
, *mask_mark
, *modes
;
534 irc_in_addr_t ip_mask
;
536 time_t min_ts
, max_ts
;
537 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
, regex_version
;
538 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1, has_regex_version
: 1;
539 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
540 unsigned char ip_mask_bits
;
541 unsigned int match_opers
: 1, option_log
: 1;
542 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
543 int authed
: 2, info_space
: 2;
544 unsigned int intra_scmp
: 2, intra_dcmp
: 2;
545 unsigned int use_regex
: 1;
546 unsigned int silent
: 1;
547 unsigned int checkrestrictions
: 2;
550 struct discrim_and_source
{
552 struct userNode
*source
;
553 struct userNode
*destination
;
555 unsigned int disp_limit
;
558 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
559 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
560 static int gag_helper_func(struct userNode
*match
, void *extra
);
561 static int ungag_helper_func(struct userNode
*match
, void *extra
);
573 } opserv_alert_reaction
;
575 struct opserv_user_alert
{
577 char *text_discrim
, *split_discrim
;
579 opserv_alert_reaction reaction
;
583 /* funny type to make it acceptible to dict_set_free_data, far below */
585 opserv_free_user_alert(void *data
)
587 struct opserv_user_alert
*alert
= data
;
588 if (alert
->discrim
->channel
)
589 UnlockChannel(alert
->discrim
->channel
);
591 free(alert
->text_discrim
);
592 free(alert
->split_discrim
);
593 if(alert
->discrim
->has_regex_nick
)
594 regfree(&alert
->discrim
->regex_nick
);
595 if(alert
->discrim
->has_regex_ident
)
596 regfree(&alert
->discrim
->regex_ident
);
597 if(alert
->discrim
->has_regex_host
)
598 regfree(&alert
->discrim
->regex_host
);
599 if(alert
->discrim
->has_regex_info
)
600 regfree(&alert
->discrim
->regex_info
);
601 if(alert
->discrim
->has_regex_version
)
602 regfree(&alert
->discrim
->regex_version
);
603 free(alert
->discrim
->reason
);
604 free(alert
->discrim
);
608 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
609 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
612 char *defconReverseModes(const char *modes
)
614 char *newmodes
= NULL
;
619 if (!(newmodes
= malloc(sizeof(char) * strlen(modes
) + 1))) {
622 for (i
= 0; i
< strlen(modes
); i
++) {
625 else if (modes
[i
] == '-')
628 newmodes
[i
] = modes
[i
];
634 int checkDefCon(int level
)
636 return DefCon
[DefConLevel
] & level
;
639 void showDefConSettings(struct userNode
*user
, struct svccmd
*cmd
)
641 if (DefConLevel
== 5) {
642 reply("OSMSG_DEFCON_ALLOWING_ALL");
645 reply("OSMSG_DEFCON_DISALLOWING", DefConLevel
);
647 if (checkDefCon(DEFCON_NO_NEW_CHANNELS
))
648 reply("OSMSG_DEFCON_NO_NEW_CHANNELS");
650 if (checkDefCon(DEFCON_NO_NEW_NICKS
))
651 reply("OSMSG_DEFCON_NO_NEW_NICKS");
653 if (checkDefCon(DEFCON_NO_MODE_CHANGE
))
654 reply("OSMSG_DEFCON_NO_MODE_CHANGE");
656 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
) && (DefConChanModes
))
657 reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes
);
659 if (checkDefCon(DEFCON_REDUCE_SESSION
))
660 reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit
);
662 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
))
663 reply("OSMSG_DEFCON_NO_NEW_CLIENTS");
665 if (checkDefCon(DEFCON_OPER_ONLY
))
666 reply("OSMSG_DEFCON_OPER_ONLY");
668 if (checkDefCon(DEFCON_SILENT_OPER_ONLY
))
669 reply("OSMSG_DEFCON_SILENT_OPER_ONLY");
671 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
672 reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS");
674 if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
675 reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS");
677 if (checkDefCon(DEFCON_NO_NEW_MEMOS
))
678 reply("OSMSG_DEFCON_NO_NEW_MEMOS");
683 void do_mass_mode(char *modes
)
690 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
691 struct chanNode
*chan
= iter_data(it
);
693 irc_mode(opserv
, chan
, modes
);
698 void DefConProcess(struct userNode
*user
)
703 global_message_args(MESSAGE_RECIPIENT_LUSERS
, "DEFCON_NETWORK_CHANGED", DefConLevel
);
705 if (GlobalOnDefconMore
&& GlobalOnDefcon
)
706 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConMessage
);
708 if ((DefConLevel
== 5) && !GlobalOnDefconMore
&& !GlobalOnDefcon
)
709 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConOffMessage
);
712 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_OPER_LEVEL_CHANGE", user
->nick
, DefConLevel
);
714 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel
);
716 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
)) {
717 if (DefConChanModes
&& !DefConModesSet
) {
718 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
719 do_mass_mode(DefConChanModes
);
724 if (DefConChanModes
&& (DefConModesSet
!= 0)) {
725 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
726 if ((newmodes
= defconReverseModes(DefConChanModes
))) {
727 do_mass_mode(newmodes
);
739 defcon_timeout(UNUSED_ARG(void *data
))
745 static MODCMD_FUNC(cmd_defcon
)
747 if ((argc
< 2) || (atoi(argv
[1]) == DefConLevel
)) {
748 showDefConSettings(user
, cmd
);
752 if ((atoi(argv
[1]) < 1) || (atoi(argv
[1]) > 5)) {
753 reply("OSMSG_DEFCON_INVALID", atoi(argv
[1]));
757 DefConLevel
= atoi(argv
[1]);
758 showDefConSettings(user
, cmd
);
760 if (DefConTimeOut
> 0) {
761 timeq_del(0, defcon_timeout
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
762 timeq_add(now
+ DefConTimeOut
, defcon_timeout
, NULL
);
770 static MODCMD_FUNC(cmd_privallow)
772 //privallow servername/username +/-flag (global is set in conf)
775 static MODCMD_FUNC(cmd_privdissallow)
777 //privdisallow servername/username +/-flag (global is set in conf)
780 static MODCMD_FUNC(cmd_privlist)
782 //privlist servername/user (global with none)
786 static MODCMD_FUNC(cmd_privset
)
788 struct userNode
*target
;
796 } else if (*flag
== '+') {
801 target
= GetUserH(argv
[1]);
803 reply("MSG_NICK_UNKNOWN", argv
[1]);
807 if (check_priv(flag
)) {
808 irc_privs(target
, flag
, add
);
809 reply("OSMSG_PRIV_SET", argv
[2], (add
== 1) ? "" : "un");
811 reply("OSMSG_PRIV_UNKNOWN", argv
[2]);
818 /* A lot of these commands are very similar to what ChanServ can do,
819 * but OpServ can do them even on channels that aren't registered.
822 static MODCMD_FUNC(cmd_access
)
824 struct handle_info
*hi
;
828 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
829 if (!irccasecmp(target
, "*")) {
830 nickserv_show_oper_accounts(user
, cmd
);
833 if (!(hi
= modcmd_get_handle_info(user
, target
)))
835 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
836 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
840 static MODCMD_FUNC(cmd_ban
)
842 struct mod_chanmode change
;
843 struct userNode
*victim
;
845 mod_chanmode_init(&change
);
847 change
.args
[0].mode
= MODE_BAN
;
848 if (is_ircmask(argv
[1]))
849 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
850 else if ((victim
= GetUserH(argv
[1])))
851 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
853 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
856 modcmd_chanmode_announce(&change
);
857 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
858 free((char*)change
.args
[0].u
.hostmask
);
862 static MODCMD_FUNC(cmd_chaninfo
)
867 struct exemptNode
*exempt
;
868 struct modeNode
*moden
;
871 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
872 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
873 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
874 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
875 irc_make_chanmode(channel
, buffer
);
876 if (channel
->bad_channel
)
877 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
879 reply("OSMSG_CHANINFO_MODES", buffer
);
880 if (channel
->topic_time
) {
881 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
882 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
883 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
885 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
886 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
888 if (channel
->banlist
.used
) {
889 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
890 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
891 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
892 ban
= channel
->banlist
.list
[n
];
893 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
894 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
897 if (channel
->exemptlist
.used
) {
898 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
899 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
900 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
901 exempt
= channel
->exemptlist
.list
[n
];
902 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
903 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
906 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
907 /* early out unless they ask for users */
908 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
911 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
912 for (n
=0; n
<channel
->members
.used
; n
++) {
913 moden
= channel
->members
.list
[n
];
914 if (moden
->modes
& MODE_CHANOP
) {
915 if (moden
->oplevel
>= 0)
916 send_message_type(4, user
, cmd
->parent
->bot
, " @%s:%d (%s@%s)", moden
->user
->nick
, moden
->oplevel
, moden
->user
->ident
, moden
->user
->hostname
);
918 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
921 for (n
=0; n
<channel
->members
.used
; n
++) {
922 moden
= channel
->members
.list
[n
];
923 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
924 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
926 for (n
=0; n
<channel
->members
.used
; n
++) {
927 moden
= channel
->members
.list
[n
];
928 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
929 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
931 for (n
=0; n
<channel
->members
.used
; n
++) {
932 moden
= channel
->members
.list
[n
];
933 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
934 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
939 /* This command has been replaced by 'alert notice channel #foo' */
941 static MODCMD_FUNC(cmd_warn)
943 char *reason, *message;
945 if (!IsChannelName(argv[1])) {
946 reply("OSMSG_NEED_CHANNEL", argv[0]);
949 reason = dict_find(opserv_chan_warn, argv[1], NULL);
951 reply("OSMSG_WARN_EXISTS", argv[1]);
955 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
957 reason = strdup("No reason");
958 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
959 reply("OSMSG_WARN_ADDED", argv[1], reason);
960 if (dict_find(channels, argv[1], NULL)) {
961 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason);
966 static MODCMD_FUNC(cmd_unwarn)
968 if ((argc < 2) || !IsChannelName(argv[1])) {
969 reply("OSMSG_NEED_CHANNEL", argv[0]);
972 if (!dict_remove(opserv_chan_warn, argv[1])) {
973 reply("OSMSG_WARN_NOEXIST", argv[1]);
976 reply("OSMSG_WARN_DELETED", argv[1]);
981 static MODCMD_FUNC(cmd_clearbans
)
983 struct mod_chanmode
*change
;
986 change
= mod_chanmode_alloc(channel
->banlist
.used
);
987 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
988 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
989 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
991 modcmd_chanmode_announce(change
);
992 for (ii
=0; ii
<change
->argc
; ++ii
)
993 free((char*)change
->args
[ii
].u
.hostmask
);
994 mod_chanmode_free(change
);
995 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
999 static MODCMD_FUNC(cmd_clearmodes
)
1001 struct mod_chanmode change
;
1003 if (!channel
->modes
) {
1004 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
1007 mod_chanmode_init(&change
);
1008 change
.modes_clear
= channel
->modes
;
1009 modcmd_chanmode_announce(&change
);
1010 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
1014 static MODCMD_FUNC(cmd_deop
)
1016 struct mod_chanmode
*change
;
1017 unsigned int arg
, count
;
1019 change
= mod_chanmode_alloc(argc
-1);
1020 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1021 struct userNode
*victim
= GetUserH(argv
[arg
]);
1022 struct modeNode
*mn
;
1023 if (!victim
|| IsService(victim
)
1024 || !(mn
= GetUserMode(channel
, victim
))
1025 || !(mn
->modes
& MODE_CHANOP
))
1027 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1028 change
->args
[count
++].u
.member
= mn
;
1031 change
->argc
= count
;
1032 modcmd_chanmode_announce(change
);
1034 mod_chanmode_free(change
);
1035 reply("OSMSG_DEOP_DONE");
1039 static MODCMD_FUNC(cmd_dehop
)
1041 struct mod_chanmode
*change
;
1042 unsigned int arg
, count
;
1044 change
= mod_chanmode_alloc(argc
-1);
1045 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1046 struct userNode
*victim
= GetUserH(argv
[arg
]);
1047 struct modeNode
*mn
;
1048 if (!victim
|| IsService(victim
)
1049 || !(mn
= GetUserMode(channel
, victim
))
1050 || !(mn
->modes
& MODE_HALFOP
))
1052 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1053 change
->args
[count
++].u
.member
= mn
;
1056 change
->argc
= count
;
1057 modcmd_chanmode_announce(change
);
1059 mod_chanmode_free(change
);
1060 reply("OSMSG_DEHOP_DONE");
1064 static MODCMD_FUNC(cmd_deopall
)
1066 struct mod_chanmode
*change
;
1067 unsigned int ii
, count
;
1069 change
= mod_chanmode_alloc(channel
->members
.used
);
1070 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1071 struct modeNode
*mn
= channel
->members
.list
[ii
];
1072 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
1074 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1075 change
->args
[count
++].u
.member
= mn
;
1078 change
->argc
= count
;
1079 modcmd_chanmode_announce(change
);
1081 mod_chanmode_free(change
);
1082 reply("OSMSG_DEOPALL_DONE", channel
->name
);
1086 static MODCMD_FUNC(cmd_dehopall
)
1088 struct mod_chanmode
*change
;
1089 unsigned int ii
, count
;
1091 change
= mod_chanmode_alloc(channel
->members
.used
);
1092 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1093 struct modeNode
*mn
= channel
->members
.list
[ii
];
1094 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
1096 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1097 change
->args
[count
++].u
.member
= mn
;
1100 change
->argc
= count
;
1101 modcmd_chanmode_announce(change
);
1103 mod_chanmode_free(change
);
1104 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
1108 static MODCMD_FUNC(cmd_resetmax
)
1110 max_clients
= dict_size(clients
);
1111 max_clients_time
= now
;
1112 reply("OSMSG_MAXUSERS_RESET", max_clients
);
1116 static MODCMD_FUNC(cmd_rehash
)
1118 extern char *services_config
;
1120 if (conf_read(services_config
))
1121 reply("OSMSG_REHASH_COMPLETE");
1123 reply("OSMSG_REHASH_FAILED");
1127 static MODCMD_FUNC(cmd_reopen
)
1130 reply("OSMSG_REOPEN_COMPLETE");
1134 static MODCMD_FUNC(cmd_reconnect
)
1136 reply("OSMSG_RECONNECTING");
1137 irc_squit(self
, "Reconnecting.", NULL
);
1141 static MODCMD_FUNC(cmd_jupe
)
1143 extern int force_n2k
;
1144 struct server
*newsrv
;
1146 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
1148 num
= atoi(argv
[2]);
1150 reply("OSMSG_INVALID_NUMERIC");
1153 if ((num
< 64) && !force_n2k
) {
1154 inttobase64(numeric
, num
, 1);
1155 inttobase64(numeric
+1, 64*64-1, 2);
1157 inttobase64(numeric
, num
, 2);
1158 inttobase64(numeric
+2, 64*64*64-1, 3);
1160 #ifdef WITH_PROTOCOL_P10
1161 if (GetServerN(numeric
)) {
1162 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
1166 if (GetServerH(argv
[1])) {
1167 reply("OSMSG_NAME_COLLIDE");
1170 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
1171 if(!strchr(argv
[1], '.')) {
1172 reply("OSMSG_INVALID_SERVERNAME");
1175 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
1177 reply("OSMSG_SRV_CREATE_FAILED");
1181 reply("OSMSG_SERVER_JUPED", argv
[1]);
1185 static MODCMD_FUNC(cmd_unjupe
)
1190 srv
= GetServerH(argv
[1]);
1192 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1195 if (strncmp(srv
->description
, "JUPE", 4)) {
1196 reply("OSMSG_SERVER_NOT_JUPE");
1199 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
1200 DelServer(srv
, 1, reason
);
1201 reply("OSMSG_SERVER_UNJUPED");
1205 static MODCMD_FUNC(cmd_jump
)
1207 extern struct cManagerNode cManager
;
1208 void uplink_select(char *name
);
1209 struct uplinkNode
*uplink_find(char *name
);
1210 struct uplinkNode
*uplink
;
1213 target
= unsplit_string(argv
+1, argc
-1, NULL
);
1215 if (!strcmp(cManager
.uplink
->name
, target
)) {
1216 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
1220 uplink
= uplink_find(target
);
1222 reply("OSMSG_INVALID_UPLINK", target
);
1225 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
1226 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
1230 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
1231 uplink_select(target
);
1232 irc_squit(self
, "Reconnecting.", NULL
);
1236 static MODCMD_FUNC(cmd_die
)
1238 char *reason
, *text
;
1240 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1241 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
1242 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
1243 irc_squit(self
, reason
, text
);
1248 static MODCMD_FUNC(cmd_restart
)
1250 extern int services_argc
;
1251 extern char **services_argv
;
1252 char **restart_argv
, *reason
, *text
;
1254 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1255 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
1256 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
1257 irc_squit(self
, reason
, text
);
1259 /* Append a NULL to the end of argv[]. */
1260 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
1261 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
1262 restart_argv
[services_argc
] = NULL
;
1267 execv(services_argv
[0], restart_argv
);
1269 /* If we're still here, that means something went wrong. Reconnect. */
1273 static struct gline
*
1274 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
, int silent
)
1276 char mask
[IRC_NTOP_MAX_SIZE
+3] = { '*', '@', '\0' };
1277 irc_ntop(mask
+ 2, sizeof(mask
) - 2, &target
->ip
);
1279 snprintf(reason
= alloca(MAXLEN
), MAXLEN
,
1280 "G-line requested by %s.", src_handle
);
1282 duration
= opserv_conf
.block_gline_duration
;
1283 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1, silent
? 1 : 0);
1286 static MODCMD_FUNC(cmd_block
)
1288 struct userNode
*target
;
1289 struct gline
*gline
;
1292 target
= GetUserH(argv
[1]);
1294 reply("MSG_NICK_UNKNOWN", argv
[1]);
1297 if (IsService(target
)) {
1298 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1301 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1302 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0, 0);
1303 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1307 static MODCMD_FUNC(cmd_gline
)
1309 unsigned long duration
;
1311 struct gline
*gline
;
1313 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1314 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1315 reply("MSG_INVALID_GLINE", argv
[1]);
1318 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1319 reply("OSMSG_STUPID_GLINE", argv
[1]);
1322 duration
= ParseInterval(argv
[2]);
1324 reply("MSG_INVALID_DURATION", argv
[2]);
1327 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1, 0);
1328 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1332 static MODCMD_FUNC(cmd_ungline
)
1334 if (gline_remove(argv
[1], 1))
1335 reply("OSMSG_GLINE_REMOVED", argv
[1]);
1337 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
1341 static MODCMD_FUNC(cmd_refreshg
)
1348 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1349 srv
= iter_data(it
);
1350 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1352 gline_refresh_server(srv
);
1353 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
1357 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1361 gline_refresh_all();
1362 reply("OSMSG_GLINES_REFRESHED");
1368 opserv_version(struct userNode
*target
)
1370 irc_version_user(opserv
, target
);
1374 opserv_mark(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *mark
)
1378 irc_mark(target
, mark
);
1382 opserv_svsjoin(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
, unsigned int checkrestrictions
)
1384 struct chanNode
*channel
;
1386 if(!channame
|| !IsChannelName(channame
)) {
1387 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1391 if (!(channel
= GetChannel(channame
))) {
1392 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
1394 if (GetUserMode(channel
, target
)) {
1399 if (checkrestrictions
) {
1400 if (trace_check_bans(target
, channel
) == 1) {
1401 return; /* found on lamer list */
1404 if (channel
->modes
& MODE_INVITEONLY
) {
1405 return; /* channel is invite only */
1408 if (channel
->limit
> 0) {
1409 if (channel
->members
.used
>= channel
->limit
) {
1410 return; /* channel is invite on */
1414 if (*channel
->key
) {
1415 return; /* channel is password protected */
1419 irc_svsjoin(opserv
, target
, channel
);
1420 /* Should we tell the user they got joined? -Rubin*/
1424 opserv_svspart(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
)
1426 struct chanNode
*channel
;
1428 if(!channame
|| !IsChannelName(channame
)) {
1429 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1433 if (!(channel
= GetChannel(channame
))) {
1434 /* channel doesnt exist */
1438 if (!GetUserMode(channel
, target
)) {
1443 irc_svspart(opserv
, target
, channel
);
1446 static struct shun
*
1447 opserv_shun(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
1450 mask
= alloca(MAXLEN
);
1451 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
1453 reason
= alloca(MAXLEN
);
1454 snprintf(reason
, MAXLEN
, "Shun requested by %s.", src_handle
);
1456 if (!duration
) duration
= opserv_conf
.block_shun_duration
;
1457 return shun_add(src_handle
, mask
, duration
, reason
, now
, 1);
1460 static MODCMD_FUNC(cmd_sblock
)
1462 struct userNode
*target
;
1466 target
= GetUserH(argv
[1]);
1468 reply("MSG_NICK_UNKNOWN", argv
[1]);
1471 if (IsService(target
)) {
1472 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1475 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1476 shun
= opserv_shun(target
, user
->handle_info
->handle
, reason
, 0);
1477 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1481 static MODCMD_FUNC(cmd_shun
)
1483 unsigned long duration
;
1487 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1488 if (!is_shun(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1489 reply("MSG_INVALID_SHUN", argv
[1]);
1492 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1493 reply("OSMSG_STUPID_SHUN", argv
[1]);
1496 duration
= ParseInterval(argv
[2]);
1498 reply("MSG_INVALID_DURATION", argv
[2]);
1501 shun
= shun_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
1502 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1506 static MODCMD_FUNC(cmd_unshun
)
1508 if (shun_remove(argv
[1], 1))
1509 reply("OSMSG_SHUN_REMOVED", argv
[1]);
1511 reply("OSMSG_SHUN_FORCE_REMOVED", argv
[1]);
1515 static MODCMD_FUNC(cmd_refreshs
)
1522 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1523 srv
= iter_data(it
);
1524 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1526 shun_refresh_server(srv
);
1527 reply("OSMSG_SHUNS_ONE_REFRESHED", srv
->name
);
1531 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1536 reply("OSMSG_SHUNS_REFRESHED");
1542 opserv_ison(struct userNode
*bot
, struct userNode
*tell
, struct userNode
*target
, const char *message
)
1544 struct modeNode
*mn
;
1545 unsigned int count
, here_len
, n
, maxlen
;
1548 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
1550 maxlen
= MAX_LINE_SIZE
;
1551 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
1552 mn
= target
->channels
.list
[n
];
1553 here_len
= strlen(mn
->channel
->name
);
1554 if ((count
+ here_len
+ 4) > maxlen
) {
1556 send_message(tell
, bot
, message
, buff
);
1559 if (mn
->modes
& MODE_CHANOP
)
1560 buff
[count
++] = '@';
1561 if (mn
->modes
& MODE_HALFOP
)
1562 buff
[count
++] = '%';
1563 if (mn
->modes
& MODE_VOICE
)
1564 buff
[count
++] = '+';
1565 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
1567 buff
[count
++] = ' ';
1571 send_message(tell
, bot
, message
, buff
);
1575 static MODCMD_FUNC(cmd_inviteme
)
1577 struct userNode
*target
;
1582 target
= GetUserH(argv
[1]);
1584 reply("MSG_NICK_UNKNOWN", argv
[1]);
1588 if (opserv_conf
.debug_channel
== NULL
) {
1589 reply("OSMSG_NO_DEBUG_CHANNEL");
1592 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
1593 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1596 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1598 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1602 static MODCMD_FUNC(cmd_invite
)
1604 if (GetUserMode(channel
, user
)) {
1605 reply("OSMSG_ALREADY_THERE", channel
->name
);
1608 irc_invite(cmd
->parent
->bot
, user
, channel
);
1612 static MODCMD_FUNC(cmd_svsjoin
)
1614 struct userNode
*target
;
1617 if(!IsChannelName(argv
[2])) {
1618 reply("MSG_NOT_CHANNEL_NAME");
1621 target
= GetUserH(argv
[1]);
1623 reply("MSG_NICK_UNKNOWN", argv
[1]);
1627 if (!(channel
= GetChannel(argv
[2]))) {
1628 channel
= AddChannel(argv
[2], now
, NULL
, NULL
, NULL
);
1630 if (GetUserMode(channel
, target
)) {
1631 reply("OSMSG_USER_ALREADY_THERE", target
->nick
, channel
->name
);
1634 irc_svsjoin(opserv
, target
, channel
);
1635 reply("OSMSG_SVSJOIN_SENT");
1639 static MODCMD_FUNC(cmd_svsnick
)
1641 struct userNode
*target
;
1643 target
= GetUserH(argv
[1]);
1645 reply("MSG_NICK_UNKNOWN", argv
[1]);
1648 if(!is_valid_nick(argv
[2])) {
1649 reply("OMSG_BAD_SVSNICK", argv
[2]);
1652 irc_svsnick(opserv
, target
, argv
[2]);
1656 static MODCMD_FUNC(cmd_join
)
1658 struct userNode
*bot
= cmd
->parent
->bot
;
1660 if (!IsChannelName(argv
[1])) {
1661 reply("MSG_NOT_CHANNEL_NAME");
1663 } else if (!(channel
= GetChannel(argv
[1]))) {
1664 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1665 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1666 } else if (GetUserMode(channel
, bot
)) {
1667 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1670 struct mod_chanmode change
;
1671 mod_chanmode_init(&change
);
1673 change
.args
[0].mode
= MODE_CHANOP
;
1674 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1675 modcmd_chanmode_announce(&change
);
1677 irc_fetchtopic(bot
, channel
->name
);
1678 reply("OSMSG_JOIN_DONE", channel
->name
);
1682 static MODCMD_FUNC(cmd_kick
)
1684 struct userNode
*target
;
1688 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1689 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1691 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1693 target
= GetUserH(argv
[1]);
1695 reply("MSG_NICK_UNKNOWN", argv
[1]);
1698 if (!GetUserMode(channel
, target
)) {
1699 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1702 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1706 static MODCMD_FUNC(cmd_kickall
)
1708 unsigned int limit
, n
, inchan
;
1709 struct modeNode
*mn
;
1711 struct userNode
*bot
= cmd
->parent
->bot
;
1713 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1714 * channel, we have to join it in temporarily. */
1715 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1716 struct mod_chanmode change
;
1717 mod_chanmode_init(&change
);
1718 change
.args
[0].mode
= MODE_CHANOP
;
1719 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1720 modcmd_chanmode_announce(&change
);
1723 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1724 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1726 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1728 limit
= user
->handle_info
->opserv_level
;
1729 for (n
=channel
->members
.used
; n
>0;) {
1730 mn
= channel
->members
.list
[--n
];
1731 if (IsService(mn
->user
)
1732 || (mn
->user
->handle_info
1733 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1736 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1739 DelChannelUser(bot
, channel
, "My work here is done", 0);
1740 reply("OSMSG_KICKALL_DONE", channel
->name
);
1744 static MODCMD_FUNC(cmd_kickban
)
1746 struct mod_chanmode change
;
1747 struct userNode
*target
;
1752 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1753 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1755 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1757 target
= GetUserH(argv
[1]);
1759 reply("MSG_NICK_UNKNOWN", argv
[1]);
1762 if (!GetUserMode(channel
, target
)) {
1763 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1766 mod_chanmode_init(&change
);
1768 change
.args
[0].mode
= MODE_BAN
;
1769 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1770 modcmd_chanmode_announce(&change
);
1771 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1776 static MODCMD_FUNC(cmd_kickbanall
)
1778 struct modeNode
*mn
;
1779 struct userNode
*bot
= cmd
->parent
->bot
;
1780 struct mod_chanmode
*change
;
1782 unsigned int limit
, n
, inchan
;
1784 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1785 * channel, we have to join it in temporarily. */
1786 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1787 change
= mod_chanmode_alloc(2);
1788 change
->args
[0].mode
= MODE_CHANOP
;
1789 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1790 change
->args
[1].mode
= MODE_BAN
;
1791 change
->args
[1].u
.hostmask
= "*!*@*";
1793 change
= mod_chanmode_alloc(1);
1794 change
->args
[0].mode
= MODE_BAN
;
1795 change
->args
[0].u
.hostmask
= "*!*@*";
1797 modcmd_chanmode_announce(change
);
1798 mod_chanmode_free(change
);
1800 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1801 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1803 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1806 limit
= user
->handle_info
->opserv_level
;
1807 for (n
=channel
->members
.used
; n
>0; ) {
1808 mn
= channel
->members
.list
[--n
];
1809 if (IsService(mn
->user
)
1810 || (mn
->user
->handle_info
1811 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1814 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1817 DelChannelUser(bot
, channel
, "My work here is done", 0);
1818 reply("OSMSG_KICKALL_DONE", channel
->name
);
1822 static MODCMD_FUNC(cmd_svspart
)
1824 struct userNode
*target
;
1825 struct chanNode
*target_channel
;
1827 if(!IsChannelName(argv
[2])) {
1828 reply("MSG_NOT_CHANNEL_NAME");
1831 if(!(target_channel
= GetChannel(argv
[2])))
1833 reply("MSG_INVALID_CHANNEL");
1836 target
= GetUserH(argv
[1]);
1838 reply("MSG_NICK_UNKNOWN", argv
[1]);
1842 if (!GetUserMode(target_channel
, target
)) {
1843 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, target_channel
->name
);
1847 irc_svspart(opserv
, target
, target_channel
);
1848 reply("OSMSG_SVSPART_SENT");
1852 static MODCMD_FUNC(cmd_part
)
1856 if (!IsChannelName(argv
[1])) {
1857 reply("MSG_NOT_CHANNEL_NAME");
1860 if ((channel
= GetChannel(argv
[1]))) {
1861 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1862 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1865 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1866 reply("OSMSG_LEAVING", channel
->name
);
1867 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1872 static MODCMD_FUNC(cmd_mode
)
1874 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1875 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1878 reply("OSMSG_MODE_SET", channel
->name
);
1882 int is_valid_mark(char *mark
)
1888 if(strlen(mark
) > MARKLEN
)
1891 for(ptr
= mark
; *ptr
; ptr
++) {
1892 if(! (isalnum(*ptr
) || *ptr
== '-'))
1899 static MODCMD_FUNC(cmd_mark
)
1901 char *mark
= argv
[2];
1902 struct userNode
*victim
= GetUserH(argv
[1]);
1905 reply("MSG_NICK_UNKNOWN", argv
[1]);
1906 else if(!is_valid_mark(mark
))
1907 reply("OSMSG_MARK_INVALID");
1909 irc_mark(victim
, mark
);
1910 reply("OSMSG_MARK_SET");
1916 static MODCMD_FUNC(cmd_op
)
1918 struct mod_chanmode
*change
;
1919 unsigned int arg
, count
;
1921 change
= mod_chanmode_alloc(argc
-1);
1922 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1923 struct userNode
*victim
;
1924 struct modeNode
*mn
;
1925 if (!(victim
= GetUserH(argv
[arg
])))
1927 if (!(mn
= GetUserMode(channel
, victim
)))
1929 if (mn
->modes
& MODE_CHANOP
)
1931 change
->args
[count
].mode
= MODE_CHANOP
;
1932 change
->args
[count
++].u
.member
= mn
;
1935 change
->argc
= count
;
1936 modcmd_chanmode_announce(change
);
1938 mod_chanmode_free(change
);
1939 reply("OSMSG_OP_DONE");
1943 static MODCMD_FUNC(cmd_hop
)
1945 struct mod_chanmode
*change
;
1946 unsigned int arg
, count
;
1948 change
= mod_chanmode_alloc(argc
-1);
1949 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1950 struct userNode
*victim
;
1951 struct modeNode
*mn
;
1952 if (!(victim
= GetUserH(argv
[arg
])))
1954 if (!(mn
= GetUserMode(channel
, victim
)))
1956 if (mn
->modes
& MODE_HALFOP
)
1958 change
->args
[count
].mode
= MODE_HALFOP
;
1959 change
->args
[count
++].u
.member
= mn
;
1962 change
->argc
= count
;
1963 modcmd_chanmode_announce(change
);
1965 mod_chanmode_free(change
);
1966 reply("OSMSG_HOP_DONE");
1970 static MODCMD_FUNC(cmd_opall
)
1972 struct mod_chanmode
*change
;
1973 unsigned int ii
, count
;
1975 change
= mod_chanmode_alloc(channel
->members
.used
);
1976 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1977 struct modeNode
*mn
= channel
->members
.list
[ii
];
1978 if (mn
->modes
& MODE_CHANOP
)
1980 change
->args
[count
].mode
= MODE_CHANOP
;
1981 change
->args
[count
++].u
.member
= mn
;
1984 change
->argc
= count
;
1985 modcmd_chanmode_announce(change
);
1987 mod_chanmode_free(change
);
1988 reply("OSMSG_OPALL_DONE", channel
->name
);
1992 static MODCMD_FUNC(cmd_hopall
)
1994 struct mod_chanmode
*change
;
1995 unsigned int ii
, count
;
1997 change
= mod_chanmode_alloc(channel
->members
.used
);
1998 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1999 struct modeNode
*mn
= channel
->members
.list
[ii
];
2000 if (mn
->modes
& MODE_HALFOP
)
2002 change
->args
[count
].mode
= MODE_HALFOP
;
2003 change
->args
[count
++].u
.member
= mn
;
2006 change
->argc
= count
;
2007 modcmd_chanmode_announce(change
);
2009 mod_chanmode_free(change
);
2010 reply("OSMSG_HOPALL_DONE", channel
->name
);
2014 static MODCMD_FUNC(cmd_whois
)
2016 struct userNode
*target
;
2020 #ifdef WITH_PROTOCOL_P10
2021 if (argv
[1][0] == '*')
2022 target
= GetUserN(argv
[1]+1);
2025 target
= GetUserH(argv
[1]);
2027 reply("MSG_NICK_UNKNOWN", argv
[1]);
2030 reply("OSMSG_WHOIS_NICK", target
->nick
);
2031 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
2032 if (IsFakeHost(target
))
2033 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
2034 reply("OSMSG_WHOIS_CRYPT_HOST", target
->crypthost
);
2035 reply("OSMSG_WHOIS_CRYPT_IP", target
->cryptip
);
2036 reply("OSMSG_WHOIS_IP", irc_ntoa(&target
->ip
));
2039 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2040 reply("OSMSG_WHOIS_COUNTRY_CODE", target
->country_code
);
2041 reply("OSMSG_WHOIS_CITY", target
->city
);
2042 reply("OSMSG_WHOIS_REGION", target
->region
);
2044 reply("OSMSG_WHOIS_POSTAL_CODE", target
->postal_code
);
2045 reply("OSMSG_WHOIS_LATITUDE", target
->latitude
);
2046 reply("OSMSG_WHOIS_LONGITUDE", target
->longitude
);
2047 /* Only show a map url if we have a city, latitude and longitude.
2048 * Theres not much point of latitude and longitude coordinates are
2049 * returned but no city, the coordinates are useless.
2051 if (target
->latitude
&& target
->longitude
&& target
->city
) {
2052 char map_url
[MAXLEN
];
2053 snprintf(map_url
, sizeof(map_url
), "http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=%f&longitude=%f",
2054 target
->latitude
, target
->longitude
);
2055 reply("OSMSG_WHOIS_MAP", map_url
);
2057 reply("OSMSG_WHOIS_DMA_CODE", target
->dma_code
);
2058 reply("OSMSG_WHOIS_AREA_CODE", target
->area_code
);
2059 } else if (target
->country_name
) {
2060 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2062 if(target
->version_reply
) {
2063 reply("OSMSG_WHOIS_VERSION", target
->version_reply
);
2066 reply("OSMSG_WHOIS_MARK", target
->mark
);
2068 reply("OSMSG_WHOIS_NO_NOTICE", target
->no_notice
? "YES":"NO");
2070 if (target
->modes
) {
2072 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
2073 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
2074 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
2075 if (IsOper(target
)) buffer
[bpos
++] = 'o';
2076 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
2077 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
2079 // sethost - reed/apples
2080 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
2081 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
2083 if (IsService(target
)) buffer
[bpos
++] = 'k';
2084 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
2085 if (target
->handle_info
) buffer
[bpos
++] = 'r';
2086 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
2087 if (IsBotM(target
)) buffer
[bpos
++] = 'B';
2088 if (IsHideChans(target
)) buffer
[bpos
++] = 'n';
2089 if (IsHideIdle(target
)) buffer
[bpos
++] = 'I';
2090 if (IsXtraOp(target
)) buffer
[bpos
++] = 'X';
2091 if (IsGagged(target
)) buffer_cat(" (gagged)");
2092 if (IsRegistering(target
)) buffer_cat(" (registered account)");
2095 reply("OSMSG_WHOIS_MODES", buffer
);
2097 reply("OSMSG_WHOIS_INFO", target
->info
);
2098 #ifdef WITH_PROTOCOL_P10
2099 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
2101 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
2102 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
2104 reply("OSMSG_WHOIS_PRIVS", client_report_privs(target
));
2106 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
2107 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
2108 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
2109 opserv_ison(cmd
->parent
->bot
, user
, target
, "OSMSG_WHOIS_CHANNELS");
2111 reply("OSMSG_WHOIS_HIDECHANS");
2115 static MODCMD_FUNC(cmd_unban
)
2117 struct mod_chanmode change
;
2118 mod_chanmode_init(&change
);
2120 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
2121 change
.args
[0].u
.hostmask
= argv
[1];
2122 modcmd_chanmode_announce(&change
);
2123 reply("OSMSG_UNBAN_DONE", channel
->name
);
2127 static MODCMD_FUNC(cmd_voiceall
)
2129 struct mod_chanmode
*change
;
2130 unsigned int ii
, count
;
2132 change
= mod_chanmode_alloc(channel
->members
.used
);
2133 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2134 struct modeNode
*mn
= channel
->members
.list
[ii
];
2135 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
2137 change
->args
[count
].mode
= MODE_VOICE
;
2138 change
->args
[count
++].u
.member
= mn
;
2141 change
->argc
= count
;
2142 modcmd_chanmode_announce(change
);
2144 mod_chanmode_free(change
);
2145 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
2149 static MODCMD_FUNC(cmd_devoiceall
)
2151 struct mod_chanmode
*change
;
2152 unsigned int ii
, count
;
2154 change
= mod_chanmode_alloc(channel
->members
.used
);
2155 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2156 struct modeNode
*mn
= channel
->members
.list
[ii
];
2157 if (!(mn
->modes
& MODE_VOICE
))
2159 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
2160 change
->args
[count
++].u
.member
= mn
;
2163 change
->argc
= count
;
2164 modcmd_chanmode_announce(change
);
2166 mod_chanmode_free(change
);
2167 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
2171 static MODCMD_FUNC(cmd_stats_bad
) {
2173 unsigned int ii
, end
, here_len
;
2176 /* Show the bad word list.. */
2177 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
2178 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
2179 here_len
= strlen(opserv_bad_words
->list
[ii
]);
2180 /* If the line is full output it & start again */
2181 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2183 reply("OSMSG_BADWORD_LIST", buffer
);
2186 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
2188 buffer
[end
++] = ' ';
2191 reply("OSMSG_BADWORD_LIST", buffer
);
2193 /* Show the exemption list.. */
2194 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
2195 here_len
= strlen(iter_key(it
));
2196 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2198 reply("OSMSG_EXEMPTED_LIST", buffer
);
2201 memcpy(buffer
+end
, iter_key(it
), here_len
);
2203 buffer
[end
++] = ' ';
2206 reply("OSMSG_EXEMPTED_LIST", buffer
);
2210 static MODCMD_FUNC(cmd_stats_glines
) {
2211 reply("OSMSG_GLINE_COUNT", gline_count());
2215 static MODCMD_FUNC(cmd_stats_shuns
) {
2216 reply("OSMSG_SHUN_COUNT", shun_count());
2221 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
2222 unsigned int nn
, pos
;
2225 for (nn
=1; nn
<=depth
; nn
<<=1) ;
2226 for (pos
=0, nn
>>=1; nn
>1; ) {
2228 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
2229 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
2232 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
2233 if (!server
->children
.used
)
2235 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
2236 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
2238 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
2241 static MODCMD_FUNC(cmd_stats_links
) {
2242 trace_links(cmd
->parent
->bot
, user
, self
, 1);
2247 static MODCMD_FUNC(cmd_stats_max
) {
2248 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
2252 static MODCMD_FUNC(cmd_stats_network
) {
2253 struct helpfile_table tbl
;
2254 unsigned int nn
, tot_clients
;
2257 tot_clients
= dict_size(clients
);
2258 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
2259 tbl
.length
= dict_size(servers
)+1;
2261 tbl
.flags
= TABLE_NO_FREE
;
2262 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2263 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2264 tbl
.contents
[0][0] = "Server Name";
2265 tbl
.contents
[0][1] = "Clients";
2266 tbl
.contents
[0][2] = "Load";
2267 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2268 struct server
*server
= iter_data(it
);
2269 char *buffer
= malloc(32);
2270 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2271 tbl
.contents
[nn
][0] = server
->name
;
2272 tbl
.contents
[nn
][1] = buffer
;
2273 sprintf(buffer
, "%u", server
->clients
);
2274 tbl
.contents
[nn
][2] = buffer
+ 16;
2275 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
2278 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2279 for (nn
=1; nn
<tbl
.length
; nn
++) {
2280 free((char*)tbl
.contents
[nn
][1]);
2281 free(tbl
.contents
[nn
]);
2283 free(tbl
.contents
[0]);
2288 static MODCMD_FUNC(cmd_stats_network2
) {
2289 struct helpfile_table tbl
;
2293 tbl
.length
= dict_size(servers
)+1;
2295 tbl
.flags
= TABLE_NO_FREE
;
2296 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2297 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2298 tbl
.contents
[0][0] = "Server Name";
2299 tbl
.contents
[0][1] = "Numeric";
2300 tbl
.contents
[0][2] = "Link Time";
2301 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2302 struct server
*server
= iter_data(it
);
2303 char *buffer
= malloc(64);
2306 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2307 tbl
.contents
[nn
][0] = server
->name
;
2308 #ifdef WITH_PROTOCOL_P10
2309 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
2313 tbl
.contents
[nn
][1] = buffer
;
2314 ofs
= strlen(buffer
) + 1;
2315 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
2316 if (server
->self_burst
)
2317 strcat(buffer
+ ofs
, " Bursting");
2318 tbl
.contents
[nn
][2] = buffer
+ ofs
;
2321 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2322 for (nn
=1; nn
<tbl
.length
; nn
++) {
2323 free((char*)tbl
.contents
[nn
][1]);
2324 free(tbl
.contents
[nn
]);
2326 free(tbl
.contents
[0]);
2331 static MODCMD_FUNC(cmd_stats_reserved
) {
2334 reply("OSMSG_RESERVED_LIST");
2335 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
2336 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
2340 static MODCMD_FUNC(cmd_stats_trusted
) {
2342 struct trusted_host
*th
;
2343 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
2345 reply("OSMSG_TRUSTED_LIST");
2346 reply("OSMSG_TRUSTED_LIST_BAR");
2347 reply("OSMSG_TRUSTED_LIST_HEADER");
2348 reply("OSMSG_TRUSTED_LIST_BAR");
2350 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2353 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2355 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2357 sprintf(limit
, "%lu", th
->limit
);
2358 reply("OSMSG_HOST_IS_TRUSTED",
2360 (th
->limit
? limit
: "none"),
2361 (th
->issuer
? th
->issuer
: "<unknown>"),
2362 (th
->issued
? issued
: "some time"),
2363 (th
->expires
? length
: "never"));
2364 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2366 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
2369 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2372 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2374 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2376 sprintf(limit
, "%lu", th
->limit
);
2377 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
2378 (th
->limit
? limit
: "none"),
2379 (th
->issuer
? th
->issuer
: "<unknown>"),
2380 (th
->issued
? issued
: "some time"),
2381 (th
->expires
? length
: "never"));
2382 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2385 reply("OSMSG_TRUSTED_LIST_END");
2389 static MODCMD_FUNC(cmd_stats_uplink
) {
2390 extern struct cManagerNode cManager
;
2391 struct uplinkNode
*uplink
;
2393 uplink
= cManager
.uplink
;
2394 reply("OSMSG_UPLINK_START", uplink
->name
);
2395 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
2399 static MODCMD_FUNC(cmd_stats_uptime
) {
2400 char uptime
[INTERVALLEN
];
2402 extern time_t boot_time
;
2403 extern int lines_processed
;
2404 static long clocks_per_sec
;
2406 if (!clocks_per_sec
) {
2407 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
2408 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
2409 if (clocks_per_sec
<= 0)
2412 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
2413 clocks_per_sec
= CLOCKS_PER_SEC
;
2416 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
2418 reply("OSMSG_UPTIME_STATS",
2419 uptime
, lines_processed
,
2420 buf
.tms_utime
/(double)clocks_per_sec
,
2421 buf
.tms_stime
/(double)clocks_per_sec
);
2425 static MODCMD_FUNC(cmd_stats_alerts
) {
2427 struct opserv_user_alert
*alert
;
2428 const char *reaction
;
2429 char t_buffer
[INTERVALLEN
];
2433 m
= unsplit_string(argv
+ 1, argc
- 1, NULL
);
2434 reply("OSMSG_ALERTS_LIST", m
? m
: "*");
2435 reply("OSMSG_ALERTS_BAR");
2436 reply("OSMSG_ALERTS_HEADER");
2437 reply("OSMSG_ALERTS_BAR");
2438 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2439 alert
= iter_data(it
);
2440 if(m
&& (!match_ircglob(alert
->text_discrim
, m
) && strcasecmp(alert
->owner
, m
) && strcasecmp(iter_key(it
), m
)))
2441 continue; /* not a match to requested filter */
2442 switch (alert
->reaction
) {
2443 case REACT_NOTICE
: reaction
= "notice"; break;
2444 case REACT_KILL
: reaction
= "kill"; break;
2445 // case REACT_SILENT: reaction = "silent"; break;
2446 case REACT_GLINE
: reaction
= "gline"; break;
2447 case REACT_TRACK
: reaction
= "track"; break;
2448 case REACT_SHUN
: reaction
= "shun"; break;
2449 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
2450 case REACT_SVSPART
: reaction
= "svspart"; break;
2451 case REACT_VERSION
: reaction
= "version"; break;
2452 case REACT_MARK
: reaction
= "mark"; break;
2453 default: reaction
= "<unknown>"; break;
2455 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
2456 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
2457 if (alert
->last
> 0)
2458 reply("OSMSG_ALERTS_LAST", intervalString(t_buffer
, now
- alert
->last
, user
->handle_info
));
2460 reply("OSMSG_ALERTS_LAST", "Never");
2462 reply("OSMSG_ALERT_END");
2466 static MODCMD_FUNC(cmd_stats_gags
) {
2467 struct gag_entry
*gag
;
2468 struct helpfile_table table
;
2472 reply("OSMSG_NO_GAGS");
2475 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
2476 table
.length
= nn
+1;
2478 table
.flags
= TABLE_NO_FREE
;
2479 table
.contents
= calloc(table
.length
, sizeof(char**));
2480 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
2481 table
.contents
[0][0] = "Mask";
2482 table
.contents
[0][1] = "Owner";
2483 table
.contents
[0][2] = "Expires";
2484 table
.contents
[0][3] = "Reason";
2485 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
2486 char expstr
[INTERVALLEN
];
2488 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
2490 strcpy(expstr
, "Never");
2491 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
2492 table
.contents
[nn
][0] = gag
->mask
;
2493 table
.contents
[nn
][1] = gag
->owner
;
2494 table
.contents
[nn
][2] = strdup(expstr
);
2495 table
.contents
[nn
][3] = gag
->reason
;
2497 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
2498 for (nn
=1; nn
<table
.length
; nn
++) {
2499 free((char*)table
.contents
[nn
][2]);
2500 free(table
.contents
[nn
]);
2502 free(table
.contents
[0]);
2503 free(table
.contents
);
2507 static MODCMD_FUNC(cmd_stats_timeq
) {
2508 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
2513 static MODCMD_FUNC(cmd_stats_warn) {
2516 reply("OSMSG_WARN_LISTSTART");
2517 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
2518 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
2519 reply("OSMSG_WARN_LISTEND");
2524 #if defined(WITH_MALLOC_X3)
2525 static MODCMD_FUNC(cmd_stats_memory
) {
2526 extern unsigned long alloc_count
, alloc_size
;
2527 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2528 "%u allocations totalling %u bytes.",
2529 alloc_count
, alloc_size
);
2532 #elif defined(WITH_MALLOC_SLAB)
2533 static MODCMD_FUNC(cmd_stats_memory
) {
2534 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
2535 extern unsigned long big_alloc_count
, big_alloc_size
;
2536 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2537 "%u allocations in %u slabs totalling %u bytes.",
2538 slab_alloc_count
, slab_count
, slab_alloc_size
);
2539 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2540 "%u big allocations totalling %u bytes.",
2541 big_alloc_count
, big_alloc_size
);
2546 static MODCMD_FUNC(cmd_dump
)
2548 char linedup
[MAXLEN
], original
[MAXLEN
];
2550 unsplit_string(argv
+1, argc
-1, original
);
2551 safestrncpy(linedup
, original
, sizeof(linedup
));
2552 /* assume it's only valid IRC if we can parse it */
2553 if (parse_line(linedup
, 1)) {
2555 reply("OSMSG_LINE_DUMPED");
2557 reply("OSMSG_RAW_PARSE_ERROR");
2561 static MODCMD_FUNC(cmd_raw
)
2563 char linedup
[MAXLEN
], original
[MAXLEN
];
2565 unsplit_string(argv
+1, argc
-1, original
);
2566 safestrncpy(linedup
, original
, sizeof(linedup
));
2567 /* Try to parse the line before sending it; if it's too wrong,
2568 * maybe it will core us instead of our uplink. */
2569 parse_line(linedup
, 1);
2571 reply("OSMSG_LINE_DUMPED");
2575 static struct userNode
*
2576 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
2578 struct userNode
*resv
= GetUserH(nick
);
2580 if (IsService(resv
)) {
2581 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
2584 if (resv
->handle_info
2585 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
2586 reply("OSMSG_LEVEL_TOO_LOW");
2590 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
2591 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
2596 static MODCMD_FUNC(cmd_collide
)
2598 struct userNode
*resv
;
2600 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2602 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
2605 reply("OSMSG_CLONE_FAILED", argv
[1]);
2610 static MODCMD_FUNC(cmd_reserve
)
2612 struct userNode
*resv
;
2614 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2616 resv
->modes
|= FLAGS_PERSISTENT
;
2617 reply("OSMSG_RESERVED_NICK", resv
->nick
);
2620 reply("OSMSG_CLONE_FAILED", argv
[1]);
2626 free_reserve(char *nick
)
2628 struct userNode
*resv
;
2632 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
2636 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
2637 reason
= alloca(rlen
);
2638 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
2639 DelUser(resv
, NULL
, 1, reason
);
2640 dict_remove(opserv_reserved_nick_dict
, nick
);
2644 static MODCMD_FUNC(cmd_unreserve
)
2646 if (free_reserve(argv
[1]))
2647 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
2649 reply("OSMSG_NOT_RESERVED", argv
[1]);
2654 opserv_part_channel(void *data
)
2656 DelChannelUser(opserv
, data
, "Leaving.", 0);
2659 static int alert_check_user(const char *key
, void *data
, void *extra
);
2662 opserv_new_user_check(struct userNode
*user
)
2664 struct opserv_hostinfo
*ohi
;
2665 struct gag_entry
*gag
;
2666 char addr
[IRC_NTOP_MAX_SIZE
];
2668 /* Check to see if we should ignore them entirely. */
2669 if (IsLocal(user
) || IsService(user
))
2672 /* Check for alerts, and stop if we find one that kills them. */
2673 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
2676 /* Gag them if appropriate. */
2677 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2678 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
2679 gag_helper_func(user
, NULL
);
2684 /* Add to host info struct */
2685 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2686 if (!(ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2687 ohi
= calloc(1, sizeof(*ohi
));
2688 dict_insert(opserv_hostinfo_dict
, strdup(addr
), ohi
);
2689 userList_init(&ohi
->clients
);
2691 userList_append(&ohi
->clients
, user
);
2693 /* Only warn of new user floods outside of bursts. */
2694 if (!user
->uplink
->burst
) {
2695 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
2696 if (!new_user_flood
) {
2698 opserv_alert("Warning: Possible new-user flood.");
2705 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
)) {
2706 DelUser(user
, opserv
, 1, DefConGlineReason
);
2710 if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS
)) && !IsOper(user
)) {
2711 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2713 strcpy(target
+ 2, user
->hostname
);
2714 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
2715 gline_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1, 0);
2716 else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
2717 shun_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1);
2722 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
2723 if (opserv_conf
.untrusted_max
2724 && irc_in_addr_is_valid(user
->ip
)
2725 && !irc_in_addr_is_loopback(user
->ip
)) {
2726 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, addr
, NULL
);
2727 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
2729 if (checkDefCon(DEFCON_REDUCE_SESSION
) && !th
)
2730 limit
= DefConSessionLimit
;
2733 /* 0 means unlimited hosts */
2734 } else if (ohi
->clients
.used
== limit
) {
2736 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
2737 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
2738 } else if (ohi
->clients
.used
> limit
) {
2739 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2740 strcpy(target
+ 2, addr
);
2741 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "Excessive connections from a single host.", now
, 1, 1);
2749 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
2751 struct opserv_hostinfo
*ohi
;
2752 char addr
[IRC_NTOP_MAX_SIZE
];
2754 if (IsLocal(user
)) {
2755 /* Try to remove it from the reserved nick dict without
2756 * calling free_reserve, because that would call DelUser(),
2757 * and we'd loop back to here. */
2758 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
2761 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2762 if ((ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2763 userList_remove(&ohi
->clients
, user
);
2764 if (ohi
->clients
.used
== 0)
2765 dict_remove(opserv_hostinfo_dict
, addr
);
2770 opserv_bad_channel(const char *name
)
2775 dict_find(opserv_exempt_channels
, name
, &present
);
2779 if (gline_find(name
))
2782 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
2783 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
2790 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
2792 struct mod_chanmode
*change
;
2795 change
= mod_chanmode_alloc(2);
2796 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2797 change
->args
[0].mode
= MODE_CHANOP
;
2798 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2799 change
->args
[1].mode
= MODE_BAN
;
2800 change
->args
[1].u
.hostmask
= "*!*@*";
2801 mod_chanmode_announce(opserv
, channel
, change
);
2802 mod_chanmode_free(change
);
2803 for (nn
=channel
->members
.used
; nn
>0; ) {
2804 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2805 if (IsService(mNode
->user
))
2807 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2809 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2813 opserv_channel_check(struct chanNode
*newchan
)
2817 if (!newchan
->join_policer
.params
) {
2818 newchan
->join_policer
.last_req
= now
;
2819 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2822 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2823 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning);
2827 /* Wait until the join check to shut channels down. */
2828 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2832 opserv_channel_delete(struct chanNode
*chan
)
2834 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2838 opserv_notice_handler(struct userNode
*user
, struct userNode
*bot
, char *text
, UNUSED_ARG(int server_qualified
))
2841 /* if its a version reply, do an alert check (only alerts with version=something) */
2843 if(text
[0] == '\001') {
2845 cmd
= mysep(&text
, " ");
2846 if(cmd
&& !irccasecmp(cmd
, "VERSION")) {
2847 char *version
= mysep(&text
, "\n");
2850 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
2851 /* user->version_reply = strdup(version); done in parse-p10.c now */
2852 dict_foreach(opserv_user_alerts
, alert_check_user
, user
);
2859 opserv_join_check(struct modeNode
*mNode
)
2861 struct userNode
*user
= mNode
->user
;
2862 struct chanNode
*channel
= mNode
->channel
;
2865 if (IsService(user
))
2868 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2870 if (channel
->bad_channel
) {
2871 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2872 if (channel
->name
[0] != '#')
2873 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2874 else if (!GetUserMode(channel
, opserv
))
2875 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2877 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2878 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2879 KickChannelUser(user
, channel
, opserv
, msg
);
2884 if (user
->uplink
->burst
)
2886 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2887 channel
->join_flooded
= 0;
2890 if (!channel
->join_flooded
) {
2891 /* Don't moderate the channel unless it is activated and
2892 the number of users in the channel is over the threshold. */
2893 struct mod_chanmode change
;
2894 mod_chanmode_init(&change
);
2895 channel
->join_flooded
= 1;
2896 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2897 if (!GetUserMode(channel
, opserv
)) {
2898 /* If we aren't in the channel, join it. */
2899 change
.args
[0].mode
= MODE_CHANOP
;
2900 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2903 if (!(channel
->modes
& MODE_MODERATED
))
2904 change
.modes_set
|= MODE_MODERATED
;
2905 if (change
.modes_set
|| change
.argc
)
2906 mod_chanmode_announce(opserv
, channel
, &change
);
2907 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2908 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2910 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2913 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2918 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2919 unsigned int bad_idx
;
2921 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2922 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2923 if (irccasestr(new_bad
, orig_bad
)) {
2925 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2927 } else if (irccasestr(orig_bad
, new_bad
)) {
2929 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2931 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2932 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2933 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2934 if (!irccasestr(orig_bad
, new_bad
))
2937 reply("OSMSG_BAD_NUKING", orig_bad
);
2938 string_list_delete(opserv_bad_words
, bad_idx
);
2945 string_list_append(opserv_bad_words
, strdup(new_bad
));
2947 reply("OSMSG_ADDED_BAD", new_bad
);
2952 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
)
2954 struct routingPlanServer
*rps
;
2955 rps
= calloc(1, sizeof(*rps
));
2958 /* duplicate servers replace */
2959 rps
->uplink
= strdup(uplink
);
2961 rps
->secondaryuplink
= strdup(second
);
2963 rps
->secondaryuplink
= NULL
;
2964 rps
->port
= port
? port
: 4400; /* lame hardcodede default port. maybe get from config file somewhere? */
2966 rps
->offline
= offline
; /* 1 = yes, 0 = no */
2967 dict_insert(rp
->servers
, strdup(name
), rps
);
2968 log_module(OS_LOG
, LOG_DEBUG
, "Adding rp server %s with uplink %s", name
, uplink
);
2973 free_routing_plan_server(void *data
)
2975 struct routingPlanServer
*rps
= data
;
2977 if(rps
->secondaryuplink
)
2978 free(rps
->secondaryuplink
);
2983 opserv_add_routing_plan(const char *name
)
2985 struct routingPlan
*rp
;
2986 rp
= calloc(1, sizeof(*rp
));
2989 if(dict_find(opserv_routing_plans
, name
, NULL
))
2990 return NULL
; /* plan already exists */
2991 rp
->servers
= dict_new();
2992 dict_set_free_data(rp
->servers
, free_routing_plan_server
);
2994 dict_insert(opserv_routing_plans
, strdup(name
), rp
);
2995 /* TODO: check for duplicate */
3000 free_routing_plan(void *data
)
3002 struct routingPlan
*rp
= data
;
3003 /* delete all the servers attached to this plan */
3004 dict_delete(rp
->servers
);
3005 /* free the plan struct */
3009 /*************************************************
3010 * Functions to handle the active routing struct */
3013 *find_routeList_server(struct route
*route
, const char *server
)
3015 struct routeList
*rptr
;
3018 for(rptr
= route
->servers
;rptr
;rptr
=rptr
->next
) {
3019 if(!strcasecmp(rptr
->server
, server
))
3025 /* Wipes out the routing structure, freeing properly.
3026 * note: does NOT free itself, we just re-use it usually.*/
3028 wipe_route_list(struct route
*route
) {
3029 struct routeList
*nextptr
, *rptr
;
3032 for(rptr
= opserv_route
->servers
; rptr
; rptr
=nextptr
)
3034 nextptr
= rptr
->next
;
3038 if(rptr
->secondaryuplink
)
3039 free(rptr
->secondaryuplink
);
3042 route
->centered
= true;
3044 route
->maxdepth
= 0;
3045 route
->servers
= NULL
;
3050 rank_outside_rec(struct route
*route
, char *server
, int count
)
3052 struct routeList
*rptr
;
3055 if(count
> 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */
3058 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3060 if(!strcasecmp(server
, rptr
->uplink
)) {
3061 log_module(MAIN_LOG
, LOG_DEBUG
, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count
, i
, rptr
->server
, rptr
->uplink
);
3062 n
= rank_outside_rec(route
, rptr
->server
, count
+1);
3063 if(n
< 0) /* handle error condition */
3069 if((rptr
= find_routeList_server(route
, server
))) {
3070 rptr
->outsideness
= max
;
3074 log_module(MAIN_LOG
, LOG_WARNING
, "routing struct rank_outsideness() couldnt find %s", server
);
3080 rank_outsideness(struct route
*route
)
3082 log_module(MAIN_LOG
, LOG_DEBUG
, "rank_outsideness(): Running...");
3083 route
->maxdepth
= rank_outside_rec(route
, self
->uplink
->name
, 0) - 1;
3084 if(route
->maxdepth
< 0) { /* if the rank failed, remove route */
3085 log_module(MAIN_LOG
, LOG_WARNING
, "The active routing plan has a loop! auto routing disabled.");
3086 wipe_route_list(route
);
3093 /* Add servers to the routing structure */
3095 add_routestruct_server(struct route
*route
, const char *server
, unsigned int port
, char *uplink
, char *secondary
)
3097 struct routeList
*rptr
;
3099 if(find_routeList_server(route
, server
))
3101 log_module(MAIN_LOG
, LOG_WARNING
, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server
);
3104 rptr
= calloc(1, sizeof(*rptr
));
3105 rptr
->server
= strdup(server
);
3108 hname
= conf_get_data("server/hostname", RECDB_QSTRING
);
3111 rptr
->uplink
= strdup(uplink
);
3113 rptr
->secondaryuplink
= strdup(secondary
);
3114 /* tack this server on the front of the list */
3115 rptr
->next
= route
->servers
;
3116 route
->servers
= rptr
;
3119 #ifdef notdef /* I dont quite get this. there could be uncentered things
3120 * added after our own uplink, and this function doesnt center
3121 * as it adds. -Rubin */
3122 /* If the map hasnt been centered yet... */
3123 if(route
->centered
== false) {
3124 /* AND we just added our own uplink to it... */
3125 if(!strcasecmp(server
, self
->uplink
->name
)) {
3126 change_route_uplinks(route
); /* recenter it, n mark it centered. */
3132 /* Recenter the routing struct around our current uplink */
3134 change_route_uplinks(struct route
*route
)
3136 struct routeList
*rptr
;
3137 char lastserver
[MAXLEN
];
3138 char nextserver
[MAXLEN
];
3141 return false; /* no map to recenter */
3142 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks(): running...");
3143 char *servicename
= conf_get_data("server/hostname", RECDB_QSTRING
);
3144 strcpy(lastserver
, servicename
);
3145 rptr
= find_routeList_server(route
, self
->uplink
->name
);
3147 log_module(MAIN_LOG
, LOG_WARNING
, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered.");
3148 route
->centered
= false;
3151 if(!strcasecmp(rptr
->uplink
, servicename
)) {
3152 log_module(MAIN_LOG
, LOG_DEBUG
, "Already centered");
3154 else { /* else, center it */
3156 strcpy(nextserver
, rptr
->uplink
);
3157 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks() changing %s uplink to %s.", rptr
->server
, lastserver
);
3159 rptr
->uplink
= strdup(lastserver
);
3160 strcpy(lastserver
, rptr
->server
);
3161 rptr
= find_routeList_server(route
, nextserver
);
3164 if(rank_outsideness(route
) > 0) {
3165 route
->centered
= true;
3173 activate_routing(struct svccmd
*cmd
, struct userNode
*user
, char *plan_name
)
3175 static struct routingPlan
*rp
;
3179 if(plan_name
) { /* make this the new active plan */
3180 if(!strcmp(plan_name
, "*")) {
3181 /* disable routing */
3182 dict_remove(opserv_routing_plan_options
, "ACTIVE");
3186 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3189 reply("OSMSG_PLAN_NOT_FOUND", plan_name
);
3191 /* since it doesnt exist, remove the active setting */
3192 dict_remove(opserv_routing_plan_options
, plan_name
);
3194 log_module(MAIN_LOG
, LOG_WARNING
, "activate_routing() couldnt find active routing plan!");
3199 else { /* find the active plan in settings */
3200 plan_name
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3202 if(!plan_name
) { /* deactivated, or no plan was set active */
3203 /* TODO: delete routing map if it exists */
3204 wipe_route_list(opserv_route
);
3208 karma
= dict_find(opserv_routing_plan_options
, "KARMA", NULL
);
3210 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3212 /* this should really be done during opserv init */
3214 opserv_route
= calloc(1, sizeof(*opserv_route
));
3216 /* Delete the existing active route */
3217 wipe_route_list(opserv_route
);
3219 if(!rp
|| !rp
->servers
)
3221 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3222 const char* servername
= iter_key(it
);
3223 struct routingPlanServer
*rps
= iter_data(it
),
3224 *rp_uplink
, *rp_second
= NULL
;
3225 char *uplink
= rps
->uplink
;
3226 rp_uplink
= dict_find(rp
->servers
, rps
->uplink
, NULL
);
3227 if(rps
->secondaryuplink
)
3228 rp_second
= dict_find(rp
->servers
, rps
->secondaryuplink
, NULL
);
3230 /* If the normal uplink has bad karma, don't use it as a hub,
3231 * switch to the secondary uplink.
3233 if(karma
&& enabled_string(karma
) && rp_uplink
&& rp_uplink
->karma
< 0) {
3234 if(rps
->secondaryuplink
) {
3235 uplink
= rps
->secondaryuplink
;
3236 /* unless the secondary uplinks karma is worse than the uplink. */
3237 if((rp_second
= dict_find(rp
->servers
, uplink
, NULL
)) && rp_second
->karma
< rp_uplink
->karma
)
3238 uplink
= rps
->uplink
;
3242 * If _WE_ have bad karma, don't link us to our normal uplink, maybe
3243 * its a bad route. switch to secondary. Important: dont neg karma when we arnt on
3244 * our primary uplink, or we'll get stuck on secondary when THAT link is worse.
3246 if(karma
&& enabled_string(karma
) && (rps
->karma
< 0 || rps
->offline
) ) {
3247 if(rps
->secondaryuplink
) {
3248 uplink
= rps
->secondaryuplink
;
3251 log_module(MAIN_LOG
, LOG_DEBUG
, "activate_routing() adding %s:%d %s", servername
, rps
->port
, uplink
);
3252 add_routestruct_server(opserv_route
, servername
, rps
->port
, uplink
, NULL
);
3254 if(change_route_uplinks(opserv_route
))
3259 reply("OSMSG_ROUTING_ACTIVATION_ERROR");
3260 activate_routing(cmd
, user
, "*");
3263 /* routing activation failed but we dont do anything? */
3270 activate_routing(NULL
, NULL
, NULL
);
3272 /* start auto-routing system */
3273 reroute_timer_reset(0);
3276 /*******************************************************
3277 * Functions to handle online route configuration via opserv
3279 static void route_show_option(struct svccmd
*cmd
, struct userNode
*user
, char *name
)
3281 char *value
= dict_find(opserv_routing_plan_options
, name
, NULL
);
3283 if(!strcmp("RETRY_PERIOD", name
)) { /* Show as an interval */
3284 char buff
[INTERVALLEN
+1];
3285 reply("OSMSG_ROUTINGPLAN_OPTION", name
, intervalString(buff
, atoi(value
), user
->handle_info
));
3287 else if(!strcmp("ACTIVE", name
)) {
3288 if(opserv_route
&& opserv_route
->servers
)
3289 reply("OSMSG_ROUTINGPLAN_ACTIVE", value
);
3291 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3294 reply("OSMSG_ROUTINGPLAN_OPTION", name
, value
);
3298 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3302 static void route_show_options(struct svccmd
*cmd
, struct userNode
*user
)
3304 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3306 for(i
= 0; options
[i
]; i
++) {
3307 route_show_option(cmd
, user
, options
[i
]);
3311 /* called from timeq */
3312 void routing_connect_timeout(void *data
)
3314 struct waitingConnection
*wc
= data
;
3315 struct server
*target
= GetServerH(wc
->target
);
3317 dict_remove(opserv_waiting_connections
, wc
->server
);
3318 return; /* server we wanted to connect new server to is gone, just give up */
3320 routing_handle_connect_failure(target
, wc
->server
, "Connection timed out");
3321 /* the following invalidates server variable! */
3322 dict_remove(opserv_waiting_connections
, wc
->server
);
3325 void routing_delete_connect_timer(char *server
)
3327 struct waitingConnection
*wc
= dict_find(opserv_waiting_connections
, server
, 0);
3329 timeq_del(0, routing_connect_timeout
, wc
, TIMEQ_IGNORE_WHEN
);
3330 dict_remove(opserv_waiting_connections
, server
);
3336 routing_connect_server(char *server
, int port
, struct server
*to
)
3338 struct waitingConnection
*wc
= calloc(sizeof(*wc
), 1);
3340 wc
->server
= strdup(server
);
3341 wc
->target
= strdup(to
->name
);
3342 /* Just to make sure there isn't one left hanging
3343 * if 2 connections are attempted at once..
3345 routing_delete_connect_timer(server
);
3346 dict_insert(opserv_waiting_connections
, strdup(server
), wc
);
3347 timeq_add(now
+ ROUTING_CONNECT_TIMEOUT
, routing_connect_timeout
, wc
);
3349 irc_connect(opserv
, server
, port
, to
);
3353 routing_connect_one(struct route
*route
, char *server
)
3355 struct routeList
*rptr
;
3356 struct server
*sptr
, *suptr
;
3357 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3358 if(!strcasecmp(rptr
->server
, server
)) {
3359 /* this is the one, connect it */
3360 suptr
= GetServerH(rptr
->uplink
);
3361 sptr
= GetServerH(rptr
->server
);
3363 return 1; /* already linked */
3365 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3366 return 1; /* attempted link */
3368 return 0; /* its uplink isnt here to link to */
3371 log_module(MAIN_LOG
, LOG_DEBUG
, "Tried to link %s but its not in the active routing struct!", server
);
3372 return 0; /* server wasnt found in active route struct. */
3375 int routing_connect_children(struct route
*route
, char *server
)
3377 struct routeList
*rptr
;
3378 struct server
*sptr
, *suptr
;
3379 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3380 if(!strcasecmp(rptr
->uplink
, server
)) {
3381 /* this is the one, connect it */
3382 suptr
= GetServerH(rptr
->uplink
);
3383 sptr
= GetServerH(rptr
->server
);
3385 continue; /* already linked */
3387 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3388 continue; /* attempted link */
3390 continue; /* its uplink isnt here to link to */
3393 return 1; /* server wasnt found in active route struct ?! */
3396 int reroute(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
, char *directive
)
3398 struct routeList
*rptr
;
3399 struct server
*sptr
, *suptr
;
3400 int connect
= 0, move
= 0, missing
= 0, i
;
3401 char d
= toupper(*directive
);
3403 if(!route
|| !route
->servers
) {
3404 reply("OSMSG_REROUTING_NOTCONFIGURED");
3408 if(d
== 'N') { /* normal */
3409 irc_wallops("%s", "Attempting a reroute of the network according to loaded map...");
3410 reply("OSMSG_REROUTING_ACC_MAP");
3412 else if(d
== 'C') { /* only connect */
3413 reply("OSMSG_CONNECTING_MISSING_ONLY");
3415 else if(d
== 'T') { /* test */
3416 reply("OSMSG_TESTING_REROUTE");
3420 reply("OSMSG_INVALID_DIRECTIVE", directive
);
3424 for(i
= 0; i
<= route
->maxdepth
-1; i
++) {
3425 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3426 if(rptr
->outsideness
== i
) {
3429 reply("OSMSG_INSPECTING_SERVER", rptr
->server
);
3430 suptr
= GetServerH(rptr
->uplink
);
3432 if(rptr
->secondaryuplink
&& (suptr
= GetServerH(rptr
->secondaryuplink
))) {
3434 reply("OSMSG_COULDNT_FIND_SERVER", rptr
->uplink
, rptr
->secondaryuplink
, rptr
->server
);
3437 if(suptr
) { /* if the proper uplink is connected.. */
3438 sptr
= GetServerH(rptr
->server
);
3439 if(d
== 'C' && sptr
) {
3440 continue; /* Already linked */
3442 /* If server is missing or the uplinks are not the same then... */
3443 else if(!sptr
|| strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3447 else { /* Server is already connected somewhere */
3448 if(strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3449 if(d
!= 'T') { /* do it for real */
3450 irc_squit_route(sptr
, "%s issued reroute.", user
? user
->nick
: opserv
->nick
);
3452 else { /* just pretend */
3453 reply("OSMSG_SQUIT", rptr
->server
);
3458 if(d
!= 'T') /* do the real thing */
3459 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3460 else /* just pretend */
3461 reply("OSMSG_CONNECT", rptr
->server
, rptr
->port
, suptr
->name
);
3465 log_module(MAIN_LOG
, LOG_DEBUG
, "server uplink %s was not found, cant connect %s", rptr
->uplink
, rptr
->server
);
3468 } /* outsideness = 1 */
3471 if(user
) { /* report on what we did */
3472 if(!strcasecmp(directive
, "C")) {
3474 reply("OSMSG_CONNECTING_MISSING", connect
);
3476 reply("OSMSG_NO_SERVERS_MISSING");
3479 if(move
+connect
> 0)
3480 reply("OSMSG_REROUTE_COMPLETE", move
, connect
, move
+connect
);
3482 reply("OSMSG_NO_ROUTING_NECESSARY");
3484 reply("OSMSG_UPLINKS_MISSING", missing
);
3487 return(move
+connect
);
3490 static MODCMD_FUNC(cmd_reroute
) {
3493 if(reroute(opserv_route
, user
, cmd
, upper
))
3499 /* reroute_timer(run)
3500 * run - if it is null, just setup the timer
3501 * but dont run reroute now. otherwise reroute
3504 void reroute_timer(void *data
) {
3505 /* Delete any other timers such as this one.. */
3506 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3508 if(!opserv_route
|| !opserv_route
->servers
)
3509 return; /* no active route */
3510 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3512 return; /* retry_period invalid */
3513 unsigned int freq
= atoi(retry_period
);
3515 return; /* retry_period set to 0, disable */
3517 /* opserv_debug("Reroute timer checking reroute"); */
3518 log_module(MAIN_LOG
, LOG_DEBUG
, "Reroute timer checking reroute()");
3520 /* Do the reroute C attempt */
3522 reroute(opserv_route
, NULL
, NULL
, "C");
3524 /* Re-add ourselves to the timer queue */
3525 timeq_add(now
+ freq
, reroute_timer
, "run");
3528 void routing_change_karma(struct routingPlanServer
*rps
, const char *server
, int change
) {
3530 int oldkarma
= rps
->karma
;
3531 rps
->karma
+= change
;
3532 if(rps
->karma
< KARMA_MIN
)
3533 rps
->karma
= KARMA_MIN
;
3534 if(rps
->karma
> KARMA_MAX
)
3535 rps
->karma
= KARMA_MAX
;
3536 log_module(MAIN_LOG
, LOG_DEBUG
, "Changing %s karma by %d. new karma %d.", server
, change
, rps
->karma
);
3537 if(oldkarma
> 0 && rps
->karma
< 0) {
3538 /* we just crossed over to negitive */
3539 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went negitive karma!", server
);
3540 activate_routing(NULL
, NULL
, NULL
);
3542 else if(oldkarma
< 0 && rps
->karma
> 0) {
3543 /* we just crossed over to positive */
3544 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went back positive karma.", server
);
3545 activate_routing(NULL
, NULL
, NULL
);
3549 void routing_karma_timer(void *data
) {
3551 time_t timer_init
= data
? atoi(data
) : 0;
3554 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init
);
3556 /* If theres a time passed in, dont run unless that time is overdue. */
3557 if(!timer_init
|| (timer_init
< now
)) {
3558 if(opserv_route
&& opserv_route
->servers
) {
3559 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3560 struct routingPlan
*rp
;
3561 if(active
&& (rp
= dict_find(opserv_routing_plans
, active
, NULL
))) {
3563 /* Walk through each server in the active routing plan.. */
3564 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3565 struct routingPlanServer
*rps
= iter_data(it
);
3566 struct server
*server
= GetServerH(iter_key(it
));
3567 /* Give everyone +KARMA_ENTROPE just for nothing */
3568 routing_change_karma(rps
, iter_key(it
), KARMA_ENTROPE
);
3569 /* give an additonal +KARMA_RELIABLE to servers that
3570 * have been linked at least KARMA_TIMER seconds. */
3571 if(server
&& (server
->link
< (now
- KARMA_TIMER
) ) ) {
3572 routing_change_karma(rps
, iter_key(it
), KARMA_RELIABLE
);
3578 if(timer_init
> now
) /* loading a saved value */
3580 else /* no scheduled timer, or we missed it. start from now */
3581 next
= now
+ KARMA_TIMER
;
3582 /* Save when karma_timer should run again in case we restart before then */
3583 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next
);
3584 sprintf(buf
, "%u", (unsigned int) next
);
3585 dict_insert(opserv_routing_plan_options
, "KARMA_TIMER", strdup(buf
));
3586 /* add a timer to run this again .. */
3587 timeq_add(next
, routing_karma_timer
, NULL
);
3590 void routing_handle_neg_karma(char *server
, char *uplink
, int change
)
3592 /* if server's primary uplink is uplink, OR, uplink's primary uplink is server,
3593 * then whichever one, gets its karma changed. */
3594 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3595 struct routingPlan
*rp
;
3596 struct routingPlanServer
*rps
;
3599 if(!(rp
= dict_find(opserv_routing_plans
, active
, NULL
)))
3601 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3602 if(!strcasecmp(rps
->uplink
, uplink
)) {
3603 /* server's uplink is uplink */
3604 routing_change_karma(rps
, server
, change
);
3608 if((rps
= dict_find(rp
->servers
, uplink
, NULL
))) {
3609 if(!strcasecmp(rps
->uplink
, server
)) {
3610 /* uplink's uplink is server */
3611 routing_change_karma(rps
, uplink
, change
);
3618 routing_handle_squit(char *server
, char *uplink
, char *message
)
3620 log_module(MAIN_LOG
, LOG_DEBUG
, "Routing_handle_squit(%s, %s)", server
, message
);
3624 if(match_ircglob(message
, "Ping timeout")) {
3625 routing_handle_neg_karma(server
, uplink
, KARMA_PINGOUT
);
3626 /* if conn_pingout is true, try to reconnect it obaying karma rules. */
3628 val
= dict_find(opserv_routing_plan_options
, "CONN_PINGOUT", 0);
3629 if(val
&& enabled_string(val
))
3630 routing_connect_one(opserv_route
, server
);
3632 else if(match_ircglob(message
, "Read error:*")) {
3633 routing_handle_neg_karma(server
, uplink
, KARMA_READERROR
);
3634 /* if conn_readerror is true, try to reconnect it obaying karma rules. */
3635 val
= dict_find(opserv_routing_plan_options
, "CONN_READERROR", 0);
3636 if(val
&& enabled_string(val
))
3637 routing_connect_one(opserv_route
, server
);
3639 /* Else whats the message (an oper squit it?) dont interfere */
3643 routing_handle_connect(char *server
, char *uplink
)
3646 struct routingPlan
*rp
;
3647 struct routingPlanServer
*rps
;
3650 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect(%s, %s)", server
, uplink
);
3651 /* delete a pending connection timer, if any */
3652 routing_delete_connect_timer(server
);
3653 /* check if routing is active... */
3654 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3657 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3661 /* If its offline, mark it online again.. */
3662 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3663 if(rps
->offline
== true) {
3664 rps
->offline
= false;
3665 if(rps
->secondaryuplink
) {
3666 /* re-activate to move it back to its primary */
3667 activate_routing(NULL
, NULL
, NULL
);
3670 /* if there are any servers missing who have this server as uplink try to connect them. */
3671 routing_connect_children(opserv_route
, server
);
3673 /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */
3674 for (it
=dict_first(servers
); it
; it
=iter_next(it
)) {
3675 struct server
*sptr
= iter_data(it
);
3676 if(sptr
&& sptr
->uplink
&& !strcasecmp(server
, sptr
->uplink
->name
)) {
3677 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect calling self on %s's leaf %s", server
, sptr
->name
);
3678 routing_handle_connect(sptr
->name
, sptr
->uplink
->name
);
3683 /* Handle a failed attempt at connecting servers
3684 * - we should only get here regarding servers X3 attempted to link, other
3685 * opers link messages go to them not to us
3688 routing_handle_connect_failure(struct server
*source
, char *server
, char *message
)
3691 struct routingPlan
*rp
;
3692 struct routingPlanServer
*rps
;
3693 log_module(MAIN_LOG
, LOG_WARNING
, "Failed to connect %s to %s: %s", server
, source
->name
, message
);
3694 /* remove the waiting connection n timeq */
3695 routing_delete_connect_timer(server
);
3696 /* check if routing is active.. */
3697 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3700 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3704 if( ((rps
= dict_find(rp
->servers
, server
, NULL
)) && !strcasecmp(rps
->uplink
, source
->name
))) {
3705 /* failed to connect to its primary uplink */
3706 if(rps
->offline
== false) {
3707 rps
->offline
= true;
3708 if(rps
->secondaryuplink
) {
3709 /* re-activate routing so the secondary
3710 * becomes its uplink, and try again */
3711 activate_routing(NULL
, NULL
, NULL
);
3712 /* attempt to link it again. */
3713 routing_connect_one(opserv_route
, server
);
3714 /* TODO: reconnect any missing servers who
3715 * normally connect to server, using their backups.
3716 * Probably should just issue a reroute C here. */
3722 /* Delete any existing timers, and start the timer again
3723 * using the passed time for the first run.
3724 * - this is called during a retry_period change
3725 * before it has saved the new value.
3727 * If time is 0, lookup the interval. */
3728 void reroute_timer_reset(unsigned int time
)
3730 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3732 if(!opserv_route
|| !opserv_route
->servers
)
3733 return; /* no active route */
3734 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3736 return; /* retry_period invalid */
3737 time
= atoi(retry_period
);
3739 return; /* retry_period set to 0, disable */
3742 timeq_add(now
+ time
, reroute_timer
, "run");
3745 static MODCMD_FUNC(cmd_routing_set
)
3747 char *option
= argv
[1];
3748 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3751 route_show_options(cmd
, user
);
3754 char *found_option
= NULL
;
3755 for(i
= 0; options
[i
]; i
++) {
3756 if(!strcasecmp(options
[i
], option
))
3757 found_option
= options
[i
];
3760 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option
);
3764 char *value
= argv
[2];
3765 char buff
[MAXLEN
]; /* whats the max length of unsigned int as printf'd? */
3766 if(!strcmp(found_option
, "ACTIVE")) { /* must be an existing route. */
3767 if(disabled_string(value
) || false_string(value
)) {
3768 /* make none of the maps active */
3769 activate_routing(cmd
, user
, "*");
3770 reply("OSMSG_ROUTING_DISABLED");
3773 else if(!activate_routing(cmd
, user
, value
)) {
3774 /* neg reply handled in activate_routing */
3778 if(!strcmp(found_option
, "CONN_READERROR") || !strcmp(found_option
, "CONN_PINGOUT") ||
3779 !strcmp(found_option
, "KARMA") ) {
3780 if( enabled_string(value
)) {
3783 else if( disabled_string(value
) ) {
3787 reply("MSG_INVALID_BINARY", value
);
3791 if(!strcmp(found_option
, "RETRY_PERIOD")) {
3792 unsigned int duration
= ParseInterval(value
);
3793 sprintf(buff
, "%d", duration
);
3795 reroute_timer_reset(duration
);
3797 /* set the value here */
3798 dict_remove(opserv_routing_plan_options
, found_option
);
3799 dict_insert(opserv_routing_plan_options
, strdup(found_option
), strdup(value
));
3800 route_show_option(cmd
, user
, found_option
);
3803 /* show the current value */
3804 route_show_option(cmd
, user
, found_option
);
3810 static MODCMD_FUNC(cmd_stats_routing_plans
) {
3811 dict_iterator_t rpit
;
3813 struct routingPlan
*rp
;
3815 reply("OSMSG_ROUTINGPLAN");
3816 reply("OSMSG_ROUTINGPLAN_BAR");
3817 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3818 const char* name
= iter_key(rpit
);
3819 rp
= iter_data(rpit
);
3820 if(match_ircglob(name
, argv
[1])) {
3821 reply("OSMSG_ROUTINGPLAN_NAME", name
);
3822 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3823 const char* servername
= iter_key(it
);
3824 struct routingPlanServer
*rps
= iter_data(it
);
3825 reply("OSMSG_ROUTINGPLAN_SERVER", servername
, rps
->port
, rps
->uplink
, rps
->karma
, rps
->offline
? "offline" : "online", rps
->secondaryuplink
? rps
->secondaryuplink
: "None");
3830 reply("OSMSG_ROUTINGPLAN_END");
3833 reply("OSMSG_ROUTINGPLAN_LIST_HEAD");
3834 reply("OSMSG_ROUTINGPLAN_BAR");
3835 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3836 const char* name
= iter_key(rpit
);
3837 reply("OSMSG_ROUTINGPLAN_LIST", name
);
3839 reply("OSMSG_ROUTINGPLAN_END");
3840 route_show_options(cmd
, user
);
3846 static MODCMD_FUNC(cmd_routing_addplan
)
3850 /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */
3851 if(*name
&& !disabled_string(name
) && !false_string(name
)) {
3852 if(opserv_add_routing_plan(name
)) {
3853 reply("OSMSG_ADDPLAN_SUCCESS", name
);
3857 reply("OSMSG_ADDPLAN_FAILED", name
);
3863 reply("OSMSG_INVALID_PLAN");
3868 static MODCMD_FUNC(cmd_routing_delplan
)
3870 char *name
= argv
[1];
3871 if( dict_remove(opserv_routing_plans
, name
) ) {
3872 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3873 if(active
&& !strcasecmp(active
, name
)) {
3874 /* if this was the active plan, disable routing */
3875 activate_routing(cmd
, user
, "*");
3876 reply("OSMSG_ROUTING_DISABLED");
3878 reply("OSMSG_PLAN_DELETED");
3882 reply("OSMSG_PLAN_NOT_FOUND", name
);
3887 static MODCMD_FUNC(cmd_routing_addserver
)
3895 struct routingPlan
*rp
;
3898 server
= strdup(argv
[2]);
3899 server
= strtok(server
, ":");
3900 portstr
= strtok(NULL
, ":");
3902 port
= atoi(portstr
);
3904 char *str
= dict_find(opserv_routing_plan_options
, "DEFAULT_PORT", NULL
);
3906 port
= str
? atoi(str
) : 0;
3914 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3916 opserv_routing_plan_add_server(rp
, server
, uplink
, port
, KARMA_DEFAULT
, second
, 0);
3917 reply("OSMSG_PLAN_SERVER_ADDED", server
);
3918 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3919 /* re-activate routing with new info */
3920 activate_routing(cmd
, user
, NULL
);
3927 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3933 static MODCMD_FUNC(cmd_routing_delserver
)
3937 struct routingPlan
*rp
;
3940 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3941 if(dict_remove(rp
->servers
, server
)) {
3943 reply("OSMSG_PLAN_SERVER_DELETED");
3944 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3945 /* re-activate routing with new info */
3946 activate_routing(cmd
, user
, NULL
);
3952 reply("OSMSG_PLAN_SERVER_NOT_FOUND", server
);
3957 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3963 /*************************************************
3964 * Functions to deal with 'route map' command */
3966 /* Figures out how many downlinks there are for proper
3967 * drawing of the route map */
3969 num_route_downlinks(struct route
*route
, char *name
)
3971 struct routeList
*rptr
;
3973 rptr
= route
->servers
;
3975 if(!strcasecmp(rptr
->uplink
, name
))
3983 show_route_downlinks(struct svccmd
*cmd
, struct route
*route
, struct userNode
*user
, char *name
, char *prevpre
, char *arrowchar
, int reset
)
3985 struct routeList
*servPtr
;
3986 struct server
*sptr
;
3992 static int depth
= 0;
3997 nextpre
= malloc(MAXLEN
);
3998 strcpy(pre
, prevpre
);
4000 sptr
= GetServerH(name
);
4001 if((servPtr
= find_routeList_server(route
, name
))) {
4004 else if (!strcasecmp(sptr
->uplink
->name
, servPtr
->uplink
))
4006 else if(servPtr
->secondaryuplink
&& !strcasecmp(sptr
->name
, servPtr
->secondaryuplink
))
4010 reply("OSMSG_DOWNLINKS_FORMAT_A", pre
, arrowchar
, name
, status
);
4013 reply("OSMSG_DOWNLINKS_FORMAT_B", self
->name
);
4014 j
= num_route_downlinks(route
, name
);
4015 servPtr
= route
->servers
;
4017 if(!strcasecmp(servPtr
->uplink
, name
)) {
4018 strcpy(nextpre
, pre
);
4020 if(arrowchar
[0] == '`')
4021 strcat(nextpre
, " ");
4023 strcat(nextpre
, "| ");
4026 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "|", 0);
4029 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "`", 0);
4032 servPtr
= servPtr
->next
;
4038 show_route_map(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
)
4040 if(!route
|| !route
->servers
) {
4041 reply("OSMSG_ROUTELIST_EMPTY");
4045 char *serviceName
= conf_get_data("server/hostname", RECDB_QSTRING
);
4046 reply("OSMSG_ROUTELIST_AS_PLANNED");
4047 show_route_downlinks(cmd
, route
, user
, serviceName
, "", "`", 1);
4048 reply("OSMSG_MAP_CENTERED", route
->centered
? "is" : "is not", route
->maxdepth
);
4052 static MODCMD_FUNC(cmd_routing_map
)
4054 show_route_map(opserv_route
, user
, cmd
);
4061 /* End of auto routing functions *
4062 *********************************/
4064 static MODCMD_FUNC(cmd_addbad
)
4066 unsigned int arg
, count
;
4068 int bad_found
, exempt_found
;
4070 /* Create the bad word if it doesn't exist. */
4071 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
4073 /* Look for exception modifiers. */
4074 for (arg
=2; arg
<argc
; arg
++) {
4075 if (!irccasecmp(argv
[arg
], "except")) {
4076 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
4078 reply("MSG_MISSING_PARAMS", "except");
4081 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
4082 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
4083 if (!exempt_found
) {
4084 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
4088 reply("OSMSG_ADDED_EXEMPTIONS", count
);
4090 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
4091 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
4095 /* Scan for existing channels that match the new bad word. */
4097 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4098 struct chanNode
*channel
= iter_data(it
);
4100 if (!opserv_bad_channel(channel
->name
))
4102 channel
->bad_channel
= 1;
4103 if (channel
->name
[0] == '#')
4104 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
4107 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
4108 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
4109 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
4118 static MODCMD_FUNC(cmd_delbad
)
4123 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
4124 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
4125 string_list_delete(opserv_bad_words
, nn
);
4126 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4127 channel
= iter_data(it
);
4128 if (irccasestr(channel
->name
, argv
[1])
4129 && !opserv_bad_channel(channel
->name
)) {
4130 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
4131 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4132 channel
->bad_channel
= 0;
4135 reply("OSMSG_REMOVED_BAD", argv
[1]);
4139 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
4143 static MODCMD_FUNC(cmd_addexempt
)
4145 const char *chanName
;
4147 if ((argc
> 1) && IsChannelName(argv
[1])) {
4150 reply("MSG_NOT_CHANNEL_NAME");
4154 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
4155 channel
= GetChannel(chanName
);
4157 if (channel
->bad_channel
) {
4158 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
4159 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4161 channel
->bad_channel
= 0;
4163 reply("OSMSG_ADDED_EXEMPTION", chanName
);
4167 static MODCMD_FUNC(cmd_delexempt
)
4169 const char *chanName
;
4171 if ((argc
> 1) && IsChannelName(argv
[1])) {
4174 reply("MSG_NOT_CHANNEL_NAME");
4178 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
4179 reply("OSMSG_NOT_EXEMPT", chanName
);
4182 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
4187 opserv_expire_trusted_host(void *data
)
4189 struct trusted_host
*th
= data
;
4190 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
4194 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
4196 struct trusted_host
*th
;
4197 th
= calloc(1, sizeof(*th
));
4200 th
->ipaddr
= strdup(ipaddr
);
4201 th
->reason
= reason
? strdup(reason
) : NULL
;
4202 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
4203 th
->issued
= issued
;
4205 th
->expires
= expires
;
4206 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
4208 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4212 free_trusted_host(void *data
)
4214 struct trusted_host
*th
= data
;
4221 static MODCMD_FUNC(cmd_addtrust
)
4223 unsigned long interval
;
4225 irc_in_addr_t tmpaddr
;
4228 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
4229 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
4233 if (!irc_pton(&tmpaddr
, NULL
, argv
[1])) {
4234 reply("OSMSG_BAD_IP", argv
[1]);
4238 count
= strtoul(argv
[2], &tmp
, 10);
4240 reply("OSMSG_BAD_NUMBER", argv
[2]);
4244 interval
= ParseInterval(argv
[3]);
4245 if (!interval
&& strcmp(argv
[3], "0")) {
4246 reply("MSG_INVALID_DURATION", argv
[3]);
4250 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4251 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
4252 reply("OSMSG_ADDED_TRUSTED");
4256 static MODCMD_FUNC(cmd_edittrust
)
4258 unsigned long interval
;
4259 struct trusted_host
*th
;
4263 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
4265 reply("OSMSG_NOT_TRUSTED", argv
[1]);
4268 count
= strtoul(argv
[2], &tmp
, 10);
4269 if (!count
|| *tmp
) {
4270 reply("OSMSG_BAD_NUMBER", argv
[2]);
4273 interval
= ParseInterval(argv
[3]);
4274 if (!interval
&& strcmp(argv
[3], "0")) {
4275 reply("MSG_INVALID_DURATION", argv
[3]);
4278 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4280 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4283 th
->reason
= strdup(reason
);
4285 th
->issuer
= strdup(user
->handle_info
->handle
);
4289 th
->expires
= now
+ interval
;
4290 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4293 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
4297 static MODCMD_FUNC(cmd_deltrust
)
4301 for (n
=1; n
<argc
; n
++) {
4302 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
4306 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4307 dict_remove(opserv_trusted_hosts
, argv
[n
]);
4309 reply("OSMSG_REMOVED_TRUSTED");
4313 /* This doesn't use dict_t because it's a little simpler to open-code the
4314 * comparisons (and simpler arg-passing for the ADD subcommand).
4316 static MODCMD_FUNC(cmd_clone
)
4319 struct userNode
*clone
;
4321 clone
= GetUserH(argv
[2]);
4322 if (!irccasecmp(argv
[1], "ADD")) {
4324 char ident
[USERLEN
+1];
4327 reply("MSG_MISSING_PARAMS", argv
[1]);
4332 reply("OSMSG_CLONE_EXISTS", argv
[2]);
4335 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
4336 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
4337 if (argv
[3][i
] == '@') {
4341 ident
[i
] = argv
[3][i
];
4344 if (!argv
[3][i
] || (i
==USERLEN
)) {
4345 reply("OSMSG_NOT_A_HOSTMASK");
4348 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
4349 reply("OSMSG_CLONE_FAILED", argv
[2]);
4352 reply("OSMSG_CLONE_ADDED", clone
->nick
);
4356 reply("MSG_NICK_UNKNOWN", argv
[2]);
4359 if (clone
->uplink
!= self
|| IsService(clone
)) {
4360 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
4363 if (!irccasecmp(argv
[1], "REMOVE")) {
4366 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
4369 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
4370 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
4373 DelUser(clone
, NULL
, 1, reason
);
4374 reply("OSMSG_CLONE_REMOVED", argv
[2]);
4378 reply("MSG_MISSING_PARAMS", argv
[1]);
4382 channel
= GetChannel(argv
[3]);
4383 if (!irccasecmp(argv
[1], "JOIN")) {
4385 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
4386 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4389 AddChannelUser(clone
, channel
);
4390 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
4393 if (!irccasecmp(argv
[1], "PART")) {
4395 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4398 if (!GetUserMode(channel
, clone
)) {
4399 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4402 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
4403 DelChannelUser(clone
, channel
, "Leaving.", 0);
4406 if (!irccasecmp(argv
[1], "OP")) {
4407 struct mod_chanmode change
;
4409 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4412 mod_chanmode_init(&change
);
4414 change
.args
[0].mode
= MODE_CHANOP
;
4415 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4416 if (!change
.args
[0].u
.member
) {
4417 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4420 modcmd_chanmode_announce(&change
);
4421 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
4424 if (!irccasecmp(argv
[1], "HOP")) {
4425 struct mod_chanmode change
;
4427 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4430 mod_chanmode_init(&change
);
4432 change
.args
[0].mode
= MODE_HALFOP
;
4433 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4434 if (!change
.args
[0].u
.member
) {
4435 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4438 modcmd_chanmode_announce(&change
);
4439 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
4443 reply("MSG_MISSING_PARAMS", argv
[1]);
4447 if (!irccasecmp(argv
[1], "SAY")) {
4448 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
4449 irc_privmsg(clone
, argv
[3], text
);
4450 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
4453 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
4457 static struct helpfile_expansion
4458 opserv_help_expand(const char *variable
)
4460 extern struct userNode
*message_source
;
4461 struct helpfile_expansion exp
;
4462 struct service
*service
;
4468 if (!(service
= service_find(message_source
->nick
))) {
4469 exp
.type
= HF_STRING
;
4470 exp
.value
.str
= NULL
;
4471 } else if (!irccasecmp(variable
, "index")) {
4472 exp
.type
= HF_TABLE
;
4473 exp
.value
.table
.length
= 1;
4474 exp
.value
.table
.width
= 2;
4475 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
4476 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
4477 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
4478 exp
.value
.table
.contents
[0][0] = "Command";
4479 exp
.value
.table
.contents
[0][1] = "Level";
4480 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
4481 cmd
= iter_data(it
);
4482 row
= exp
.value
.table
.length
++;
4483 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
4484 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
4485 level
= cmd
->min_opserv_level
;
4486 if (!level_strings
[level
]) {
4487 level_strings
[level
] = malloc(16);
4488 snprintf(level_strings
[level
], 16, "%3d", level
);
4490 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
4492 } else if (!strncasecmp(variable
, "level", 5)) {
4493 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
4494 exp
.type
= HF_STRING
;
4496 level
= cmd
->min_opserv_level
;
4497 exp
.value
.str
= malloc(16);
4498 snprintf(exp
.value
.str
, 16, "%3d", level
);
4500 exp
.value
.str
= NULL
;
4503 exp
.type
= HF_STRING
;
4504 exp
.value
.str
= NULL
;
4510 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
4512 char buf
[16], *flags
= NULL
;
4513 unsigned int iflags
= 0;
4514 sprintf(buf
, "%d", min_level
);
4516 case 1: flags
= "+acceptchan"; break;
4517 case 3: flags
= "+acceptpluschan"; /* fall through */
4518 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
4521 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
4523 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
4527 int add_reserved(const char *key
, void *data
, void *extra
)
4529 struct chanNode
*chan
;
4530 struct record_data
*rd
= data
;
4531 const char *ident
, *hostname
, *desc
;
4533 struct userNode
*reserve
;
4534 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
4536 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
4539 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
4541 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
4544 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
4546 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
4549 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
4550 reserve
->modes
|= FLAGS_PERSISTENT
;
4551 dict_insert(extra
, reserve
->nick
, reserve
);
4554 if (autojoin_channels
&& reserve
) {
4555 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
4556 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
4557 AddChannelUser(reserve
, chan
)->modes
|= MODE_VOICE
;
4565 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
4569 unsigned int matched
;
4571 if (!self
->uplink
) return 0;
4572 discrim
= calloc(1, sizeof(*discrim
));
4573 discrim
->limit
= dict_size(clients
);
4574 discrim
->max_level
= ~0;
4575 discrim
->max_ts
= now
;
4576 discrim
->max_channels
= INT_MAX
;
4577 discrim
->authed
= -1;
4578 discrim
->info_space
= -1;
4579 discrim
->intra_scmp
= 0;
4580 discrim
->intra_dcmp
= 0;
4581 discrim
->use_regex
= 0;
4582 discrim
->silent
= 0;
4583 dupmask
= strdup(hostmask
);
4584 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
4585 if (!irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, discrim
->mask_host
))
4586 discrim
->ip_mask_bits
= 0;
4587 matched
= opserv_discrim_search(discrim
, func
, extra
);
4589 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
4598 gag_free(struct gag_entry
*gag
)
4600 unsigned int ungagged
;
4602 /* Remove from gag list */
4603 if (gagList
== gag
) {
4604 gagList
= gag
->next
;
4606 struct gag_entry
*prev
;
4607 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
4608 prev
->next
= gag
->next
;
4611 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
4613 /* Deallocate storage */
4623 gag_expire(void *data
)
4629 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
4631 struct gag_entry
*gag
;
4633 /* Create gag and put it into linked list */
4634 gag
= calloc(1, sizeof(*gag
));
4635 gag
->mask
= strdup(mask
);
4636 gag
->owner
= strdup(owner
? owner
: "<unknown>");
4637 gag
->reason
= strdup(reason
? reason
: "<unknown>");
4638 gag
->expires
= expires
;
4640 timeq_add(gag
->expires
, gag_expire
, gag
);
4641 gag
->next
= gagList
;
4644 /* If we're linked, see if who the gag applies to */
4645 return foreach_matching_user(mask
, gag_helper_func
, gag
);
4649 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4651 struct record_data
*rd
= data
;
4652 char *owner
, *reason
, *expstr
;
4655 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
4656 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
4657 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
4658 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
4659 gag_create(key
, owner
, reason
, expires
);
4664 static struct opserv_user_alert
*
4665 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
, int last
)
4668 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
4669 struct opserv_user_alert
*alert
;
4672 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
4673 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
4676 alert
= malloc(sizeof(*alert
));
4677 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
4678 alert
->text_discrim
= strdup(text_discrim
);
4680 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
4681 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
4682 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
4683 /* Check for missing required criteria or broken records */
4684 if (!alert
->discrim
|| (reaction
==REACT_SVSJOIN
&& !alert
->discrim
->chantarget
) ||
4685 (reaction
==REACT_SVSPART
&& !alert
->discrim
->chantarget
) ||
4686 (reaction
==REACT_MARK
&& !alert
->discrim
->mark
)) {
4687 free(alert
->text_discrim
);
4692 alert
->split_discrim
= discrim_copy
;
4693 name_dup
= strdup(name
);
4694 if (!alert
->discrim
->reason
)
4695 alert
->discrim
->reason
= strdup(name
);
4696 alert
->reaction
= reaction
;
4697 dict_insert(opserv_user_alerts
, name_dup
, alert
);
4698 /* Stick the alert into the appropriate additional alert dict(s).
4699 * For channel alerts, we only use channels and min_channels;
4700 * max_channels would have to be checked on /part, which we do not
4701 * yet do, and which seems of questionable value.
4703 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
4704 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
4705 if (alert
->discrim
->mask_nick
)
4706 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
4712 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
4714 struct record_data *rd = data;
4715 char *reason = GET_RECORD_QSTRING(rd);
4717 * i hope this can't happen *
4719 reason = "No Reason";
4721 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
4728 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4733 const char *discrim
, *react
, *owner
;
4734 opserv_alert_reaction reaction
;
4735 struct opserv_user_alert
*alert
;
4737 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
4738 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
4741 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
4742 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
4743 str
= database_get_data(alert_dict
, KEY_LAST
, RECDB_QSTRING
);
4747 if (!react
|| !irccasecmp(react
, "notice"))
4748 reaction
= REACT_NOTICE
;
4749 else if (!irccasecmp(react
, "kill"))
4750 reaction
= REACT_KILL
;
4752 else if (!irccasecmp(react, "silent"))
4753 reaction = REACT_SILENT;
4755 else if (!irccasecmp(react
, "gline"))
4756 reaction
= REACT_GLINE
;
4757 else if (!irccasecmp(react
, "track"))
4758 reaction
= REACT_TRACK
;
4759 else if (!irccasecmp(react
, "shun"))
4760 reaction
= REACT_SHUN
;
4761 else if (!irccasecmp(react
, "svsjoin"))
4762 reaction
= REACT_SVSJOIN
;
4763 else if (!irccasecmp(react
, "svspart"))
4764 reaction
= REACT_SVSPART
;
4765 else if (!irccasecmp(react
, "version"))
4766 reaction
= REACT_VERSION
;
4767 else if (!irccasecmp(react
, "mark"))
4768 reaction
= REACT_MARK
;
4770 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
4773 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
, last
);
4775 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
4778 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
4780 alert
->owner
= strdup(owner
? owner
: "<unknown>");
4785 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
4787 struct record_data
*rd
= data
;
4788 const char *limit
, *str
, *reason
, *issuer
;
4789 time_t issued
, expires
;
4791 if (rd
->type
== RECDB_QSTRING
) {
4792 /* old style host by itself */
4793 limit
= GET_RECORD_QSTRING(rd
);
4798 } else if (rd
->type
== RECDB_OBJECT
) {
4799 dict_t obj
= GET_RECORD_OBJECT(rd
);
4800 /* new style structure */
4801 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
4802 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
4803 expires
= str
? ParseInterval(str
) : 0;
4804 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
4805 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
4806 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
4807 issued
= str
? ParseInterval(str
) : 0;
4811 if (expires
&& (expires
< now
))
4813 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
4818 add_routing_plan_server(const char *name
, void *data
, void *rp
)
4820 struct record_data
*rd
= data
;
4821 const char *uplink
, *portstr
, *karma
, *second
, *offline
;
4823 dict_t obj
= GET_RECORD_OBJECT(rd
);
4824 if(rd
->type
== RECDB_OBJECT
) {
4825 uplink
= database_get_data(obj
, KEY_UPLINK
, RECDB_QSTRING
);
4826 second
= database_get_data(obj
, KEY_SECOND
, RECDB_QSTRING
);
4827 portstr
= database_get_data(obj
, KEY_PORT
, RECDB_QSTRING
);
4828 karma
= database_get_data(obj
, KEY_KARMA
, RECDB_QSTRING
);
4829 offline
= database_get_data(obj
, KEY_OFFLINE
, RECDB_QSTRING
);
4830 /* create routing plan server named key, with uplink uplink. */
4831 opserv_routing_plan_add_server(rp
, name
, uplink
, portstr
? atoi(portstr
) : 0,
4832 karma
? atoi(karma
) : KARMA_DEFAULT
, second
,
4833 offline
? atoi(offline
) : 0);
4840 routing_plan_set_option(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4842 struct record_data
*rd
= data
;
4843 if(rd
->type
== RECDB_QSTRING
)
4845 char *value
= GET_RECORD_QSTRING(rd
);
4846 dict_insert(opserv_routing_plan_options
, strdup(name
), strdup(value
));
4852 add_routing_plan(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4854 struct record_data
*rd
= data
;
4855 struct routingPlan
*rp
;
4857 if(rd
->type
== RECDB_OBJECT
) {
4858 dict_t obj
= GET_RECORD_OBJECT(rd
);
4859 rp
= opserv_add_routing_plan(name
);
4860 dict_foreach(obj
, add_routing_plan_server
, rp
);
4866 opserv_saxdb_read(struct dict
*conf_db
)
4869 struct record_data
*rd
;
4873 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
4874 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
4875 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
4877 case RECDB_STRING_LIST
:
4878 /* Add words one by one just in case there are overlaps from an old DB. */
4879 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4880 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
4883 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
4884 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
4886 if (rd
->type
== RECDB_STRING_LIST
)
4887 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
4888 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4895 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
4896 && (rd
->type
== RECDB_STRING_LIST
)) {
4897 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4898 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4900 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
4902 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
4903 max_clients
= atoi(str
);
4904 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
4905 max_clients_time
= atoi(str
);
4907 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
4908 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
4909 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
4910 dict_foreach(object
, add_gag_helper
, NULL
);
4911 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
4912 dict_foreach(object
, add_user_alert
, NULL
);
4914 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
4915 dict_foreach(object, add_chan_warn, NULL);
4918 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN
, RECDB_OBJECT
)))
4919 dict_foreach(object
, add_routing_plan
, NULL
);
4921 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN_OPTIONS
, RECDB_OBJECT
)))
4922 dict_foreach(object
, routing_plan_set_option
, NULL
);
4928 opserv_saxdb_write(struct saxdb_context
*ctx
)
4930 struct string_list
*slist
;
4933 /* reserved nicks */
4934 if (dict_size(opserv_reserved_nick_dict
)) {
4935 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
4936 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
4937 struct userNode
*user
= iter_data(it
);
4938 if (!IsPersistent(user
)) continue;
4939 saxdb_start_record(ctx
, iter_key(it
), 0);
4940 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
4941 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
4942 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
4943 saxdb_end_record(ctx
);
4945 saxdb_end_record(ctx
);
4948 if (opserv_bad_words
->used
) {
4949 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
4951 /* routing plan options */
4952 if (dict_size(opserv_routing_plan_options
)) {
4953 saxdb_start_record(ctx
, KEY_ROUTINGPLAN_OPTIONS
, 1);
4954 for(it
= dict_first(opserv_routing_plan_options
); it
; it
= iter_next(it
)) {
4955 saxdb_write_string(ctx
, iter_key(it
), iter_data(it
));
4957 saxdb_end_record(ctx
);
4960 if (dict_size(opserv_routing_plans
)) {
4961 dict_iterator_t svrit
;
4962 struct routingPlan
*rp
;
4963 struct routingPlanServer
*rps
;
4964 saxdb_start_record(ctx
, KEY_ROUTINGPLAN
, 1);
4965 for (it
= dict_first(opserv_routing_plans
); it
; it
= iter_next(it
)) {
4967 saxdb_start_record(ctx
, iter_key(it
), 0);
4968 for(svrit
= dict_first(rp
->servers
); svrit
; svrit
= iter_next(svrit
)) {
4970 rps
= iter_data(svrit
);
4971 saxdb_start_record(ctx
, iter_key(svrit
), 0);
4972 saxdb_write_string(ctx
, KEY_UPLINK
, rps
->uplink
);
4973 if(rps
->secondaryuplink
)
4974 saxdb_write_string(ctx
, KEY_SECOND
, rps
->secondaryuplink
);
4975 sprintf(buf
, "%d", rps
->port
);
4976 saxdb_write_string(ctx
, KEY_PORT
, buf
);
4977 sprintf(buf
, "%d", rps
->karma
);
4978 saxdb_write_string(ctx
, KEY_KARMA
, buf
);
4979 sprintf(buf
, "%d", rps
->offline
);
4980 saxdb_write_string(ctx
, KEY_OFFLINE
, buf
);
4981 saxdb_end_record(ctx
);
4983 saxdb_end_record(ctx
);
4985 saxdb_end_record(ctx
);
4987 /* insert exempt channel names */
4988 if (dict_size(opserv_exempt_channels
)) {
4989 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
4990 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
4991 string_list_append(slist
, strdup(iter_key(it
)));
4993 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
4994 free_string_list(slist
);
4996 /* trusted hosts takes a little more work */
4997 if (dict_size(opserv_trusted_hosts
)) {
4998 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
4999 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
5000 struct trusted_host
*th
= iter_data(it
);
5001 saxdb_start_record(ctx
, iter_key(it
), 0);
5002 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
5003 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
5004 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
5005 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
5006 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
5007 saxdb_end_record(ctx
);
5009 saxdb_end_record(ctx
);
5013 struct gag_entry
*gag
;
5014 saxdb_start_record(ctx
, KEY_GAGS
, 1);
5015 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5016 saxdb_start_record(ctx
, gag
->mask
, 0);
5017 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
5018 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
5019 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
5020 saxdb_end_record(ctx
);
5022 saxdb_end_record(ctx
);
5024 /* channel warnings */
5026 if (dict_size(opserv_chan_warn)) {
5027 saxdb_start_record(ctx, KEY_WARN, 0);
5028 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
5029 saxdb_write_string(ctx, iter_key(it), iter_data(it));
5031 saxdb_end_record(ctx);
5035 if (dict_size(opserv_user_alerts
)) {
5036 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
5037 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
5038 struct opserv_user_alert
*alert
= iter_data(it
);
5039 const char *reaction
;
5040 saxdb_start_record(ctx
, iter_key(it
), 0);
5041 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
5042 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
5043 saxdb_write_int(ctx
, KEY_LAST
, alert
->last
);
5044 switch (alert
->reaction
) {
5045 case REACT_NOTICE
: reaction
= "notice"; break;
5046 case REACT_KILL
: reaction
= "kill"; break;
5047 // case REACT_SILENT: reaction = "silent"; break;
5048 case REACT_GLINE
: reaction
= "gline"; break;
5049 case REACT_TRACK
: reaction
= "track"; break;
5050 case REACT_SHUN
: reaction
= "shun"; break;
5051 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
5052 case REACT_SVSPART
: reaction
= "svspart"; break;
5053 case REACT_VERSION
: reaction
= "version"; break;
5054 case REACT_MARK
: reaction
= "mark"; break;
5057 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
5060 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
5061 saxdb_end_record(ctx
);
5063 saxdb_end_record(ctx
);
5066 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
5067 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
5068 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
5069 saxdb_end_record(ctx
);
5074 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
5076 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
5080 static MODCMD_FUNC(cmd_query
)
5082 struct record_data
*rd
;
5087 reply("OSMSG_OPTION_ROOT");
5088 conf_enum_root(query_keys_helper
, user
);
5092 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
5093 if (!(rd
= conf_get_node(nodename
))) {
5094 reply("OSMSG_UNKNOWN_OPTION", nodename
);
5098 if (rd
->type
== RECDB_QSTRING
)
5099 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
5100 else if (rd
->type
== RECDB_STRING_LIST
) {
5101 reply("OSMSG_OPTION_LIST", nodename
);
5102 if (rd
->d
.slist
->used
)
5103 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
5104 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
5106 reply("OSMSG_OPTION_LIST_EMPTY");
5107 } else if (rd
->type
== RECDB_OBJECT
) {
5108 reply("OSMSG_OPTION_KEYS", nodename
);
5109 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
5115 static MODCMD_FUNC(cmd_set
)
5117 struct record_data
*rd
;
5119 /* I originally wanted to be able to fully manipulate the config
5120 db with this, but i wussed out. feel free to fix this - you'll
5121 need to handle quoted strings which have been split, and likely
5122 invent a syntax for it. -Zoot */
5124 if (!(rd
= conf_get_node(argv
[1]))) {
5125 reply("OSMSG_SET_NOT_SET", argv
[1]);
5129 if (rd
->type
!= RECDB_QSTRING
) {
5130 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
5134 free(rd
->d
.qstring
);
5135 rd
->d
.qstring
= strdup(argv
[2]);
5136 conf_call_reload_funcs();
5137 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
5141 static MODCMD_FUNC(cmd_settime
)
5143 const char *srv_name_mask
= "*";
5144 time_t new_time
= now
;
5147 srv_name_mask
= argv
[1];
5149 new_time
= time(NULL
);
5150 irc_settime(srv_name_mask
, new_time
);
5151 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
5156 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
5161 discrim
= calloc(1, sizeof(*discrim
));
5162 discrim
->limit
= 250;
5163 discrim
->max_level
= ~0;
5164 discrim
->max_ts
= INT_MAX
;
5165 discrim
->domain_depth
= 2;
5166 discrim
->max_channels
= INT_MAX
;
5167 discrim
->authed
= -1;
5168 discrim
->info_space
= -1;
5169 discrim
->intra_dcmp
= 0;
5170 discrim
->intra_scmp
= 0;
5171 discrim
->use_regex
= 0;
5172 discrim
->silent
= 0;
5174 for (i
=0; i
<argc
; i
++) {
5175 if (irccasecmp(argv
[i
], "log") == 0) {
5176 discrim
->option_log
= 1;
5179 /* Assume all other criteria require arguments. */
5180 if (i
== argc
- 1) {
5181 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5184 if (argv
[i
+1][0] == '&') {
5185 /* Looking for intra-userNode matches */
5186 char *tmp
= &(argv
[i
+1][1]);
5187 if (strcasecmp(tmp
, argv
[i
]) != 0) { /* Don't allow "nick &nick" etc */
5188 if (!strcasecmp(tmp
, "nick"))
5189 discrim
->intra_dcmp
= 1;
5190 else if (!strcasecmp(tmp
, "ident"))
5191 discrim
->intra_dcmp
= 2;
5192 else if (!strcasecmp(tmp
, "info"))
5193 discrim
->intra_dcmp
= 3;
5196 if (irccasecmp(argv
[i
], "mask") == 0) {
5197 if (!is_ircmask(argv
[++i
])) {
5198 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5201 if (!split_ircmask(argv
[i
],
5202 &discrim
->mask_nick
,
5203 &discrim
->mask_ident
,
5204 &discrim
->mask_host
)) {
5205 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5208 } else if (irccasecmp(argv
[i
], "nick") == 0) {
5210 if (discrim
->intra_dcmp
> 0)
5211 discrim
->intra_scmp
= 1;
5213 discrim
->mask_nick
= argv
[i
];
5214 } else if (irccasecmp(argv
[i
], "ident") == 0) {
5216 if (discrim
->intra_dcmp
> 0)
5217 discrim
->intra_scmp
= 2;
5219 discrim
->mask_ident
= argv
[i
];
5220 } else if (irccasecmp(argv
[i
], "host") == 0) {
5221 discrim
->mask_host
= argv
[++i
];
5222 } else if (irccasecmp(argv
[i
], "info") == 0) {
5224 if (discrim
->intra_dcmp
> 0)
5225 discrim
->intra_scmp
= 3;
5227 discrim
->mask_info
= argv
[i
];
5228 } else if (irccasecmp(argv
[i
], "version") == 0) {
5229 discrim
->mask_version
= argv
[++i
];
5230 } else if (irccasecmp(argv
[i
], "server") == 0) {
5231 discrim
->server
= argv
[++i
];
5232 } else if (irccasecmp(argv
[i
], "ip") == 0) {
5233 j
= irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, argv
[++i
]);
5235 send_message(user
, bot
, "OSMSG_BAD_IP", argv
[i
]);
5238 } else if (irccasecmp(argv
[i
], "account") == 0) {
5239 if (discrim
->authed
== 0) {
5240 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5243 discrim
->accountmask
= argv
[++i
];
5244 discrim
->authed
= 1;
5245 } else if (irccasecmp(argv
[i
], "marked") == 0) {
5246 discrim
->mask_mark
= argv
[++i
];
5247 } else if (irccasecmp(argv
[i
], "chantarget") == 0) {
5248 if(!IsChannelName(argv
[i
+1])) {
5249 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5252 discrim
->chantarget
= argv
[++i
];
5253 } else if (irccasecmp(argv
[i
], "checkrestrictions") == 0) {
5255 if (true_string(argv
[i
])) {
5256 discrim
->checkrestrictions
= 1;
5257 } else if (false_string(argv
[i
])) {
5258 discrim
->checkrestrictions
= 0;
5260 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5263 } else if (irccasecmp(argv
[i
], "mark") == 0) {
5264 if(!is_valid_mark(argv
[i
+1])) {
5265 send_message(user
, bot
, "OSMSG_MARK_INVALID");
5268 discrim
->mark
= argv
[++i
];
5269 } else if (irccasecmp(argv
[i
], "authed") == 0) {
5270 i
++; /* true_string and false_string are macros! */
5271 if (true_string(argv
[i
])) {
5272 discrim
->authed
= 1;
5273 } else if (false_string(argv
[i
])) {
5274 if (discrim
->accountmask
) {
5275 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5278 discrim
->authed
= 0;
5280 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5283 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
5284 /* XXX: A hack because you can't check explicitly for a space through
5285 * any other means */
5287 if (true_string(argv
[i
])) {
5288 discrim
->info_space
= 1;
5289 } else if (false_string(argv
[i
])) {
5290 discrim
->info_space
= 0;
5292 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5295 } else if (irccasecmp(argv
[i
], "regex") == 0) {
5297 if (true_string(argv
[i
])) {
5298 discrim
->use_regex
= 1;
5299 } else if (false_string(argv
[i
])) {
5300 discrim
->use_regex
= 0;
5302 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5305 } else if (irccasecmp(argv
[i
], "silent") == 0) {
5307 if(user
!= opserv
&& !oper_has_access(user
, opserv
, opserv_conf
.silent_level
, 0)) {
5309 } else if (true_string(argv
[i
])) {
5310 discrim
->silent
= 1;
5311 } else if (false_string(argv
[i
])) {
5312 discrim
->silent
= 0;
5314 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5317 } else if (irccasecmp(argv
[i
], "duration") == 0) {
5318 discrim
->duration
= ParseInterval(argv
[++i
]);
5319 } else if (irccasecmp(argv
[i
], "channel") == 0) {
5320 for (j
=0, i
++; ; j
++) {
5321 switch (argv
[i
][j
]) {
5325 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
5328 discrim
->chan_req_modes
|= MODE_VOICE
;
5329 discrim
->chan_no_modes
|= MODE_CHANOP
;
5330 discrim
->chan_no_modes
|= MODE_HALFOP
;
5333 discrim
->chan_req_modes
|= MODE_HALFOP
;
5334 discrim
->chan_no_modes
|= MODE_CHANOP
;
5335 discrim
->chan_no_modes
|= MODE_VOICE
;
5338 discrim
->chan_req_modes
|= MODE_CHANOP
;
5341 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5346 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
5347 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
5348 /* secretly "allow_channel" now means "if a channel name is
5349 * specified, require that it currently exist" */
5350 if (allow_channel
) {
5351 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
5354 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
5357 LockChannel(discrim
->channel
);
5358 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
5359 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
5360 } else if (irccasecmp(argv
[i
], "limit") == 0) {
5361 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
5362 } else if (irccasecmp(argv
[i
], "reason") == 0) {
5363 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
5365 } else if (irccasecmp(argv
[i
], "last") == 0) {
5366 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
5367 } else if ((irccasecmp(argv
[i
], "linked") == 0)
5368 || (irccasecmp(argv
[i
], "nickage") == 0)) {
5369 const char *cmp
= argv
[++i
];
5370 if (cmp
[0] == '<') {
5371 if (cmp
[1] == '=') {
5372 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5374 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
5376 } else if (cmp
[0] == '>') {
5377 if (cmp
[1] == '=') {
5378 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
5380 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
5383 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5385 } else if (irccasecmp(argv
[i
], "access") == 0) {
5386 const char *cmp
= argv
[++i
];
5387 if (cmp
[0] == '<') {
5388 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
5389 if (cmp
[1] == '=') {
5390 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
5392 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
5394 } else if (cmp
[0] == '=') {
5395 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
5396 } else if (cmp
[0] == '>') {
5397 if (cmp
[1] == '=') {
5398 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5400 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
5403 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5405 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
5406 && (irccasecmp(argv
[++i
], "opers") == 0)) {
5407 discrim
->match_opers
= 1;
5408 } else if (irccasecmp(argv
[i
], "depth") == 0) {
5409 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
5410 } else if (irccasecmp(argv
[i
], "clones") == 0) {
5411 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
5412 } else if (irccasecmp(argv
[i
], "modes") == 0) {
5413 discrim
->modes
= argv
[++i
];
5415 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
5420 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
5421 discrim
->mask_nick
= 0;
5423 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
5424 discrim
->mask_ident
= 0;
5426 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
5427 discrim
->mask_info
= 0;
5429 if (discrim
->mask_version
&& !strcmp(discrim
->mask_version
, "*")) {
5430 discrim
->mask_version
= 0;
5432 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
5433 discrim
->mask_host
= 0;
5436 if(discrim
->use_regex
)
5438 if(discrim
->mask_nick
)
5440 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_NOSUB
);
5441 discrim
->has_regex_nick
= !err
;
5445 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
5447 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
5452 if(discrim
->mask_ident
)
5454 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_NOSUB
);
5455 discrim
->has_regex_ident
= !err
;
5459 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
5461 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
5466 if(discrim
->mask_host
)
5468 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_NOSUB
);
5469 discrim
->has_regex_host
= !err
;
5473 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
5475 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
5480 if(discrim
->mask_info
)
5482 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_NOSUB
);
5483 discrim
->has_regex_info
= !err
;
5487 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
5489 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
5494 if(discrim
->mask_version
)
5496 int err
= regcomp(&discrim
->regex_version
, discrim
->mask_version
, REG_EXTENDED
|REG_NOSUB
);
5497 discrim
->has_regex_version
= !err
;
5501 buff
[regerror(err
, &discrim
->regex_version
, buff
, sizeof(buff
))] = 0;
5503 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_version
, buff
, err
);
5516 if(discrim
->has_regex_nick
)
5517 regfree(&discrim
->regex_nick
);
5518 if(discrim
->has_regex_ident
)
5519 regfree(&discrim
->regex_ident
);
5520 if(discrim
->has_regex_host
)
5521 regfree(&discrim
->regex_host
);
5522 if(discrim
->has_regex_info
)
5523 regfree(&discrim
->regex_info
);
5530 discrim_match(discrim_t discrim
, struct userNode
*user
)
5532 unsigned int access
;
5533 char *scmp
=NULL
, *dcmp
=NULL
;
5535 if ((user
->timestamp
< discrim
->min_ts
)
5536 || (user
->timestamp
> discrim
->max_ts
)
5537 || (user
->channels
.used
< discrim
->min_channels
)
5538 || (user
->channels
.used
> discrim
->max_channels
)
5539 || (discrim
->authed
== 0 && user
->handle_info
)
5540 || (discrim
->authed
== 1 && !user
->handle_info
)
5541 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
5542 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
5543 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
5544 || (discrim
->mask_mark
&& (!user
->mark
|| !match_ircglob(user
->mark
, discrim
->mask_mark
)))
5545 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
5546 || (discrim
->ip_mask_bits
&& !irc_check_mask(&user
->ip
, &discrim
->ip_mask
, discrim
->ip_mask_bits
))
5550 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
))
5553 if(discrim
->use_regex
)
5555 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
5556 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
5557 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
5558 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))
5559 || (discrim
->has_regex_version
&& (!user
->version_reply
|| regexec(&discrim
->regex_version
, user
->version_reply
, 0, 0, 0)))) {
5565 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
5566 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
5567 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
5568 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))
5569 || (discrim
->mask_version
&& (!user
->version_reply
|| !match_ircglob(user
->version_reply
, discrim
->mask_version
))) ) {
5574 if ((discrim
->intra_scmp
> 0 && discrim
->intra_dcmp
> 0)) {
5575 switch(discrim
->intra_scmp
) {
5576 case 1: scmp
=user
->nick
; break;
5577 case 2: scmp
=user
->ident
; break;
5580 if (discrim
->info_space
== 1) scmp
++;
5583 switch(discrim
->intra_dcmp
) {
5584 case 1: dcmp
=user
->nick
; break;
5585 case 2: dcmp
=user
->ident
; break;
5586 case 3: /* When checking INFO, and info_space is enabled
5587 * ignore the first character in a search
5588 * XXX: Should we ignore ALL leading whitespace?
5589 * Also, what about ignoring ~ in ident?
5592 if (discrim
->info_space
== 1) dcmp
++;
5595 if (irccasecmp(scmp
,dcmp
))
5599 if (discrim
->modes
) {
5600 unsigned int ii
, matches
= 0;
5601 for (ii
= 0; ii
< strlen(discrim
->modes
); ii
++) {
5602 switch(discrim
->modes
[ii
]) {
5604 if(IsOper(user
)) matches
++;
5607 if(IsOper(user
)) matches
++;
5610 if(IsInvisible(user
)) matches
++;
5613 if(IsWallOp(user
)) matches
++;
5616 if(IsServNotice(user
)) matches
++;
5619 if(IsDeaf(user
)) matches
++;
5622 if(IsService(user
)) matches
++;
5625 if(IsGlobal(user
)) matches
++;
5628 if(IsSetHost(user
)) matches
++;
5631 if(IsBotM(user
)) matches
++;
5634 if(IsHideChans(user
)) matches
++;
5637 if(IsHideIdle(user
)) matches
++;
5640 if(IsXtraOp(user
)) matches
++;
5643 if(IsHiddenHost(user
)) matches
++;
5647 if (matches
!= strlen(discrim
->modes
)) return 0;
5650 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
5651 if ((access
< discrim
->min_level
)
5652 || (access
> discrim
->max_level
)) {
5655 if (discrim
->min_clones
> 1) {
5656 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&user
->ip
), NULL
);
5657 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
))
5664 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
5666 unsigned int nn
, count
;
5667 struct userList matched
;
5669 userList_init(&matched
);
5670 /* Try most optimized search methods first */
5671 if (discrim
->channel
) {
5673 (nn
< discrim
->channel
->members
.used
)
5674 && (matched
.used
< discrim
->limit
);
5676 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
5677 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
5678 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
5681 if (discrim_match(discrim
, mn
->user
)) {
5682 userList_append(&matched
, mn
->user
);
5685 } else if (discrim
->ip_mask_bits
== 128) {
5686 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&discrim
->ip_mask
), NULL
);
5688 userList_clean(&matched
);
5691 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
5692 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
5693 userList_append(&matched
, ohi
->clients
.list
[nn
]);
5698 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
5699 if (discrim_match(discrim
, iter_data(it
))) {
5700 userList_append(&matched
, iter_data(it
));
5705 if (!matched
.used
) {
5706 userList_clean(&matched
);
5710 if (discrim
->option_log
) {
5711 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
5713 for (nn
=0; nn
<matched
.used
; nn
++) {
5714 struct userNode
*user
= matched
.list
[nn
];
5715 if (discrim
->option_log
) {
5716 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
5718 if (dsf(user
, data
)) {
5719 /* If a search function returns true, it ran into a
5720 problem. Stop going through the list. */
5724 if (discrim
->option_log
) {
5725 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
5727 count
= matched
.used
;
5728 userList_clean(&matched
);
5733 trace_print_func(struct userNode
*match
, void *extra
)
5735 struct discrim_and_source
*das
= extra
;
5736 if (match
->handle_info
) {
5737 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
);
5739 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
5745 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
5751 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
5753 return !(IsService(target
)
5754 || (!match_opers
&& IsOper(target
))
5755 || (target
->handle_info
5756 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
5760 trace_gline_func(struct userNode
*match
, void *extra
)
5762 struct discrim_and_source
*das
= extra
;
5764 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5765 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
, das
->discrim
->silent
);
5772 trace_shun_func(struct userNode
*match
, void *extra
)
5774 struct discrim_and_source
*das
= extra
;
5776 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5777 opserv_shun(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
5784 trace_kill_func(struct userNode
*match
, void *extra
)
5786 struct discrim_and_source
*das
= extra
;
5788 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5790 if (das
->discrim
->reason
) {
5791 reason
= das
->discrim
->reason
;
5793 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
5794 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
5796 DelUser(match
, opserv
, 1, reason
);
5803 trace_mark_func(struct userNode
*match
, void *extra
)
5805 struct discrim_and_source
*das
= extra
;
5806 char *mark
= das
->discrim
->mark
;
5810 irc_mark(match
, mark
);
5815 trace_svsjoin_func(struct userNode
*match
, void *extra
)
5817 struct discrim_and_source
*das
= extra
;
5819 char *channame
= das
->discrim
->chantarget
;
5820 int checkrestrictions
= das
->discrim
->checkrestrictions
;
5821 struct chanNode
*channel
;
5823 if(!channame
|| !IsChannelName(channame
)) {
5824 //reply("MSG_NOT_CHANNEL_NAME");
5828 if (!(channel
= GetChannel(channame
))) {
5829 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
5832 if (checkrestrictions
) {
5833 if (trace_check_bans(match
, channel
) == 1) {
5834 return 1; /* found on lamer list */
5837 if (channel
->modes
& MODE_INVITEONLY
) {
5838 return 1; /* channel is invite only */
5841 if (channel
->limit
> 0) {
5842 if (channel
->members
.used
>= channel
->limit
) {
5843 return 1; /* channel is invite on */
5847 if (*channel
->key
) {
5848 return 1; /* channel is password protected */
5852 if (GetUserMode(channel
, match
)) {
5853 // reply("OSMSG_ALREADY_THERE", channel->name);
5856 irc_svsjoin(opserv
, match
, channel
);
5857 // reply("OSMSG_SVSJOIN_SENT");
5862 trace_svspart_func(struct userNode
*match
, void *extra
)
5864 struct discrim_and_source
*das
= extra
;
5865 char *channame
= das
->discrim
->chantarget
;
5866 struct chanNode
*channel
;
5868 if(!channame
|| !IsChannelName(channame
))
5871 if (!(channel
= GetChannel(channame
)))
5874 if (!GetUserMode(channel
, match
))
5877 irc_svspart(opserv
, match
, channel
);
5882 trace_version_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
5884 irc_version_user(opserv
, match
);
5889 is_gagged(char *mask
)
5891 struct gag_entry
*gag
;
5893 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5894 if (match_ircglobs(gag
->mask
, mask
)) return 1;
5900 trace_gag_func(struct userNode
*match
, void *extra
)
5902 struct discrim_and_source
*das
= extra
;
5904 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5905 char *reason
, *mask
;
5907 if (das
->discrim
->reason
) {
5908 reason
= das
->discrim
->reason
;
5910 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
5911 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
5913 masksize
= 5+strlen(match
->hostname
);
5914 mask
= alloca(masksize
);
5915 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
5916 if (!is_gagged(mask
)) {
5917 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
5918 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
5926 trace_domains_func(struct userNode
*match
, void *extra
)
5928 struct discrim_and_source
*das
= extra
;
5930 unsigned long *count
;
5933 char ipmask
[IRC_NTOP_MASK_MAX_SIZE
];
5935 if (irc_pton(&ip
, NULL
, match
->hostname
)) {
5936 if (irc_in_addr_is_ipv4(ip
)) {
5937 unsigned long matchip
= ntohl(ip
.in6_32
[3]);
5938 /* raw IP address.. use up to first three octets of IP */
5939 switch (das
->discrim
->domain_depth
) {
5941 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
5944 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
5947 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
5950 } else if (irc_in_addr_is_ipv6(ip
)) {
5951 switch (das
->discrim
->domain_depth
) {
5952 case 1: depth
= 16; goto ipv6_pfx
;
5953 case 2: depth
= 24; goto ipv6_pfx
;
5954 case 3: depth
= 32; goto ipv6_pfx
;
5955 default: depth
= das
->discrim
->domain_depth
;
5957 irc_ntop_mask(ipmask
, sizeof(ipmask
), &ip
, depth
);
5959 } else safestrncpy(ipmask
, match
->hostname
, sizeof(ipmask
));
5960 ipmask
[sizeof(ipmask
) - 1] = '\0';
5963 hostname
= match
->hostname
+ strlen(match
->hostname
);
5964 for (depth
=das
->discrim
->domain_depth
;
5965 depth
&& (hostname
> match
->hostname
);
5968 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
5970 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
5972 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
5973 count
= calloc(1, sizeof(*count
));
5974 dict_insert(das
->dict
, strdup(hostname
), count
);
5981 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
5983 unsigned long *count
= data
;
5984 struct discrim_and_source
*das
= extra
;
5986 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
5987 return !--das
->disp_limit
;
5990 static MODCMD_FUNC(cmd_trace
)
5992 struct discrim_and_source das
;
5993 discrim_search_func action
;
5994 unsigned int matches
;
5995 struct svccmd
*subcmd
;
5999 sprintf(buf
, "trace %s", argv
[1]);
6000 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6001 reply("OSMSG_BAD_ACTION", argv
[1]);
6004 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
6006 if (!irccasecmp(argv
[1], "print"))
6007 action
= trace_print_func
;
6008 else if (!irccasecmp(argv
[1], "count"))
6009 action
= trace_count_func
;
6010 else if (!irccasecmp(argv
[1], "domains"))
6011 action
= trace_domains_func
;
6012 else if (!irccasecmp(argv
[1], "gline"))
6013 action
= trace_gline_func
;
6014 else if (!irccasecmp(argv
[1], "shun"))
6015 action
= trace_shun_func
;
6016 else if (!irccasecmp(argv
[1], "kill"))
6017 action
= trace_kill_func
;
6018 else if (!irccasecmp(argv
[1], "gag"))
6019 action
= trace_gag_func
;
6020 else if (!irccasecmp(argv
[1], "svsjoin"))
6021 action
= trace_svsjoin_func
;
6022 else if (!irccasecmp(argv
[1], "svspart"))
6023 action
= trace_svspart_func
;
6024 else if (!irccasecmp(argv
[1], "version"))
6025 action
= trace_version_func
;
6026 else if (!irccasecmp(argv
[1], "mark"))
6027 action
= trace_mark_func
;
6029 reply("OSMSG_BAD_ACTION", argv
[1]);
6033 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
6034 reply("OSMSG_LEVEL_TOO_LOW");
6040 das
.destination
= cmd
->parent
->bot
;
6041 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
6045 if (action
== trace_print_func
)
6047 reply("OSMSG_USER_SEARCH_RESULTS");
6048 reply("OSMSG_USER_SEARCH_BAR");
6049 reply("OSMSG_USER_SEARCH_HEADER");
6050 reply("OSMSG_USER_SEARCH_BAR");
6052 else if (action
== trace_count_func
)
6053 das
.discrim
->limit
= INT_MAX
;
6054 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
6055 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
6056 else if ((action
== trace_shun_func
) && !das
.discrim
->duration
)
6057 das
.discrim
->duration
= opserv_conf
.block_shun_duration
;
6058 else if (action
== trace_domains_func
) {
6059 das
.dict
= dict_new();
6060 dict_set_free_data(das
.dict
, free
);
6061 dict_set_free_keys(das
.dict
, free
);
6062 das
.disp_limit
= das
.discrim
->limit
;
6063 das
.discrim
->limit
= INT_MAX
;
6066 if (action
== trace_svsjoin_func
&& !das
.discrim
->chantarget
) {
6067 reply("OSMSG_SVSJOIN_NO_TARGET");
6070 else if (action
== trace_svspart_func
&& !das
.discrim
->chantarget
) {
6071 reply("OSMSG_SVSPART_NO_TARGET");
6074 else if (action
== trace_mark_func
&& !das
.discrim
->mark
) {
6075 reply("OSMSG_MARK_NO_MARK");
6079 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
6081 if (action
== trace_domains_func
)
6082 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
6086 if(action
== trace_print_func
)
6087 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
6089 reply("OSMSG_USER_SEARCH_COUNT", matches
);
6092 reply("MSG_NO_MATCHES");
6095 if (das
.discrim
->channel
)
6096 UnlockChannel(das
.discrim
->channel
);
6097 free(das
.discrim
->reason
);
6099 if(das
.discrim
->has_regex_nick
)
6100 regfree(&das
.discrim
->regex_nick
);
6101 if(das
.discrim
->has_regex_ident
)
6102 regfree(&das
.discrim
->regex_ident
);
6103 if(das
.discrim
->has_regex_host
)
6104 regfree(&das
.discrim
->regex_host
);
6105 if(das
.discrim
->has_regex_info
)
6106 regfree(&das
.discrim
->regex_info
);
6107 if(das
.discrim
->has_regex_version
)
6108 regfree(&das
.discrim
->regex_version
);
6111 dict_delete(das
.dict
);
6115 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
6117 typedef struct channel_discrim
{
6120 unsigned int min_users
, max_users
;
6121 time_t min_ts
, max_ts
;
6125 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
6126 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
6129 smart_parse_time(const char *str
) {
6130 /* If an interval-style string is given, treat as time before now.
6131 * If it's all digits, treat directly as a Unix timestamp. */
6132 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
6136 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
6141 discrim
= calloc(1, sizeof(*discrim
));
6142 discrim
->limit
= 25;
6144 for (i
= 0; i
< argc
; i
++) {
6145 /* Assume all criteria require arguments. */
6146 if (i
== (argc
- 1)) {
6147 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
6151 if (!irccasecmp(argv
[i
], "name"))
6152 discrim
->name
= argv
[++i
];
6153 else if (!irccasecmp(argv
[i
], "topic"))
6154 discrim
->topic
= argv
[++i
];
6155 else if (!irccasecmp(argv
[i
], "users")) {
6156 const char *cmp
= argv
[++i
];
6157 if (cmp
[0] == '<') {
6159 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
6161 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
6162 } else if (cmp
[0] == '=') {
6163 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
6164 } else if (cmp
[0] == '>') {
6166 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6168 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
6170 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6172 } else if (!irccasecmp(argv
[i
], "timestamp")) {
6173 const char *cmp
= argv
[++i
];
6174 if (cmp
[0] == '<') {
6176 discrim
->max_ts
= smart_parse_time(cmp
+2);
6178 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
6179 } else if (cmp
[0] == '=') {
6180 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
6181 } else if (cmp
[0] == '>') {
6183 discrim
->min_ts
= smart_parse_time(cmp
+2);
6185 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
6187 discrim
->min_ts
= smart_parse_time(cmp
);
6189 } else if (!irccasecmp(argv
[i
], "limit")) {
6190 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
6192 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
6197 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
6199 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
6209 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
6211 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
6212 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
6213 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
6214 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
6215 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
6216 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
6222 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
6224 unsigned int count
= 0;
6225 dict_iterator_t it
, next
;
6227 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
6228 struct chanNode
*chan
= iter_data(it
);
6230 /* Hold on to the next channel in case we decide to
6231 add actions that destructively modify the channel. */
6232 next
= iter_next(it
);
6233 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
6234 dsf(chan
, data
, bot
);
6242 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
6246 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
6249 irc_make_chanmode(channel
, modes
);
6250 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
6253 static MODCMD_FUNC(cmd_csearch
)
6256 unsigned int matches
;
6257 cdiscrim_search_func action
;
6258 struct svccmd
*subcmd
;
6261 if (!irccasecmp(argv
[1], "count"))
6262 action
= channel_count
;
6263 else if (!irccasecmp(argv
[1], "print"))
6264 action
= channel_print
;
6266 reply("OSMSG_BAD_ACTION", argv
[1]);
6270 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6271 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6272 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6276 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
6280 if (action
== channel_print
)
6281 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
6282 else if (action
== channel_count
)
6283 discrim
->limit
= INT_MAX
;
6285 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
6288 reply("MSG_MATCH_COUNT", matches
);
6290 reply("MSG_NO_MATCHES");
6296 static MODCMD_FUNC(cmd_gsync
)
6300 src
= GetServerH(argv
[1]);
6302 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6308 irc_stats(cmd
->parent
->bot
, src
, 'G');
6309 reply("OSMSG_GSYNC_RUNNING", src
->name
);
6313 static MODCMD_FUNC(cmd_ssync
)
6317 src
= GetServerH(argv
[1]);
6319 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6325 irc_stats(cmd
->parent
->bot
, src
, 'S');
6326 reply("OSMSG_SSYNC_RUNNING", src
->name
);
6330 struct gline_extra
{
6331 struct userNode
*user
;
6332 struct string_list
*glines
;
6333 struct userNode
*bot
;
6337 gtrace_print_func(struct gline
*gline
, void *extra
)
6339 struct gline_extra
*xtra
= extra
;
6340 char *when_text
, set_text
[20];
6341 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
6342 when_text
= asctime(localtime(&gline
->expires
));
6343 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6344 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
6348 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
6353 gtrace_ungline_func(struct gline
*gline
, void *extra
)
6355 struct gline_extra
*xtra
= extra
;
6356 string_list_append(xtra
->glines
, strdup(gline
->target
));
6359 static MODCMD_FUNC(cmd_gtrace
)
6361 struct gline_discrim
*discrim
;
6362 gline_search_func action
;
6363 unsigned int matches
, nn
;
6364 struct gline_extra extra
;
6365 struct svccmd
*subcmd
;
6368 if (!irccasecmp(argv
[1], "print"))
6369 action
= gtrace_print_func
;
6370 else if (!irccasecmp(argv
[1], "count"))
6371 action
= gtrace_count_func
;
6372 else if (!irccasecmp(argv
[1], "ungline"))
6373 action
= gtrace_ungline_func
;
6375 reply("OSMSG_BAD_ACTION", argv
[1]);
6378 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6379 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6380 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6384 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6388 if (action
== gtrace_print_func
)
6389 reply("OSMSG_GLINE_SEARCH_RESULTS");
6390 else if (action
== gtrace_count_func
)
6391 discrim
->limit
= INT_MAX
;
6394 extra
.glines
= alloc_string_list(4);
6395 extra
.bot
= cmd
->parent
->bot
;
6396 matches
= gline_discrim_search(discrim
, action
, &extra
);
6398 if (action
== gtrace_ungline_func
)
6399 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
6400 gline_remove(extra
.glines
->list
[nn
], 1);
6401 free_string_list(extra
.glines
);
6404 reply("MSG_MATCH_COUNT", matches
);
6406 reply("MSG_NO_MATCHES");
6407 free(discrim
->alt_target_mask
);
6413 struct userNode
*user
;
6414 struct string_list
*shuns
;
6415 struct userNode
*bot
;
6419 strace_print_func(struct shun
*shun
, void *extra
)
6421 struct shun_extra
*xtra
= extra
;
6422 char *when_text
, set_text
[20];
6423 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&shun
->issued
));
6424 when_text
= asctime(localtime(&shun
->expires
));
6425 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6426 send_message(xtra
->user
, xtra
->bot
, "OSMSG_STRACE_FORMAT", shun
->target
, set_text
, shun
->issuer
, when_text
, shun
->reason
);
6430 strace_count_func(UNUSED_ARG(struct shun
*shun
), UNUSED_ARG(void *extra
))
6435 strace_unshun_func(struct shun
*shun
, void *extra
)
6437 struct shun_extra
*xtra
= extra
;
6438 string_list_append(xtra
->shuns
, strdup(shun
->target
));
6441 static MODCMD_FUNC(cmd_strace
)
6443 struct shun_discrim
*discrim
;
6444 shun_search_func action
;
6445 unsigned int matches
, nn
;
6446 struct shun_extra extra
;
6447 struct svccmd
*subcmd
;
6450 if (!irccasecmp(argv
[1], "print"))
6451 action
= strace_print_func
;
6452 else if (!irccasecmp(argv
[1], "count"))
6453 action
= strace_count_func
;
6454 else if (!irccasecmp(argv
[1], "unshun"))
6455 action
= strace_unshun_func
;
6457 reply("OSMSG_BAD_ACTION", argv
[1]);
6460 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6461 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6462 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6466 discrim
= shun_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6470 if (action
== strace_print_func
)
6471 reply("OSMSG_SHUN_SEARCH_RESULTS");
6472 else if (action
== strace_count_func
)
6473 discrim
->limit
= INT_MAX
;
6476 extra
.shuns
= alloc_string_list(4);
6477 extra
.bot
= cmd
->parent
->bot
;
6478 matches
= shun_discrim_search(discrim
, action
, &extra
);
6480 if (action
== strace_unshun_func
)
6481 for (nn
=0; nn
<extra
.shuns
->used
; nn
++)
6482 shun_remove(extra
.shuns
->list
[nn
], 1);
6483 free_string_list(extra
.shuns
);
6486 reply("MSG_MATCH_COUNT", matches
);
6488 reply("MSG_NO_MATCHES");
6489 free(discrim
->alt_target_mask
);
6495 alert_check_user(const char *key
, void *data
, void *extra
)
6497 struct opserv_user_alert
*alert
= data
;
6498 struct userNode
*user
= extra
;
6500 if (!discrim_match(alert
->discrim
, user
))
6503 if ((alert
->reaction
!= REACT_NOTICE
)
6505 && !alert
->discrim
->match_opers
) {
6509 /* The user matches the alert criteria, so trigger the reaction. */
6510 if (alert
->discrim
->option_log
)
6511 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
);
6515 /* Return 1 to halt alert matching, such as when killing the user
6516 that triggered the alert. */
6517 switch (alert
->reaction
) {
6519 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
6522 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
, alert
->discrim
->silent
);
6525 opserv_shun(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
6528 opserv_svsjoin(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
, alert
->discrim
->checkrestrictions
);
6531 opserv_svspart(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
);
6534 /* Don't auto-version a user who we already have a version on, because the version reply itself
6535 * re-triggers this check...
6536 * TODO: maybe safer if we didn't even check react_version type alerts for the 2nd check?
6537 * sort of like we only look at channel alerts on join. -Rubin
6539 if(!user
->version_reply
)
6540 opserv_version(user
);
6543 opserv_mark(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->mark
);
6546 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
6547 /* fall through to REACT_NOTICE case */
6549 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
);
6553 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
);
6554 add_track_user(user
);
6562 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
6564 struct gag_entry
*gag
;
6565 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
6566 /* Gag them if appropriate (and only if). */
6567 user
->modes
&= ~FLAGS_GAGGED
;
6568 for (gag
= gagList
; gag
; gag
= gag
->next
) {
6569 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
6570 gag_helper_func(user
, NULL
);
6577 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
6581 if (!opserv_conf
.staff_auth_channel
6582 || user
->uplink
->burst
6583 || !user
->handle_info
)
6585 else if (user
->handle_info
->opserv_level
)
6587 else if (IsNetworkHelper(user
))
6588 type
= "NETWORK HELPER";
6589 else if (IsSupportHelper(user
))
6590 type
= "SUPPORT HELPER";
6594 if (irc_in_addr_is_valid(user
->ip
))
6595 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
6597 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
);
6600 static MODCMD_FUNC(cmd_log
)
6602 struct logSearch
*discrim
;
6603 unsigned int matches
;
6604 struct logReport report
;
6606 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
6610 reply("OSMSG_LOG_SEARCH_RESULTS");
6611 report
.reporter
= opserv
;
6613 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
6616 reply("MSG_MATCH_COUNT", matches
);
6618 reply("MSG_NO_MATCHES");
6625 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6627 if (IsOper(match
) || IsLocal(match
))
6629 match
->modes
|= FLAGS_GAGGED
;
6633 static MODCMD_FUNC(cmd_gag
)
6635 struct gag_entry
*gag
;
6636 unsigned int gagged
;
6637 unsigned long duration
;
6640 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
6642 if (!is_ircmask(argv
[1])) {
6643 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
6647 for (gag
= gagList
; gag
; gag
= gag
->next
)
6648 if (match_ircglobs(gag
->mask
, argv
[1]))
6652 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
6656 duration
= ParseInterval(argv
[2]);
6657 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
6660 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
6662 reply("OSMSG_GAG_ADDED", argv
[1]);
6667 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6669 match
->modes
&= ~FLAGS_GAGGED
;
6673 static MODCMD_FUNC(cmd_ungag
)
6675 struct gag_entry
*gag
;
6676 unsigned int ungagged
;
6678 for (gag
= gagList
; gag
; gag
= gag
->next
)
6679 if (!strcmp(gag
->mask
, argv
[1]))
6683 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
6687 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
6688 ungagged
= gag_free(gag
);
6691 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
6693 reply("OSMSG_UNGAG_ADDED", argv
[1]);
6697 static MODCMD_FUNC(cmd_addalert
)
6699 opserv_alert_reaction reaction
;
6700 struct svccmd
*subcmd
;
6705 sprintf(buf
, "addalert %s", argv
[2]);
6706 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6707 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6710 if (!irccasecmp(argv
[2], "notice"))
6711 reaction
= REACT_NOTICE
;
6712 else if (!irccasecmp(argv
[2], "kill"))
6713 reaction
= REACT_KILL
;
6714 else if (!irccasecmp(argv
[2], "gline"))
6715 reaction
= REACT_GLINE
;
6716 else if (!irccasecmp(argv
[2], "track")) {
6718 reply("OSMSG_TRACK_DISABLED");
6721 reaction
= REACT_TRACK
;
6723 } else if (!irccasecmp(argv
[2], "shun"))
6724 reaction
= REACT_SHUN
;
6725 else if(!irccasecmp(argv
[2], "svsjoin"))
6726 reaction
= REACT_SVSJOIN
;
6727 else if(!irccasecmp(argv
[2], "svspart"))
6728 reaction
= REACT_SVSPART
;
6729 else if(!irccasecmp(argv
[2], "version"))
6730 reaction
= REACT_VERSION
;
6731 else if(!irccasecmp(argv
[2], "mark"))
6732 reaction
= REACT_MARK
;
6734 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6737 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
6738 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
), 0)) {
6739 reply("OSMSG_ALERT_ADD_FAILED");
6742 reply("OSMSG_ADDED_ALERT", name
);
6746 static MODCMD_FUNC(cmd_delalert
)
6749 for (i
=1; i
<argc
; i
++) {
6750 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
6751 dict_remove(opserv_channel_alerts
, argv
[i
]);
6752 if (dict_remove(opserv_user_alerts
, argv
[i
]))
6753 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
6755 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
6761 opserv_conf_read(void)
6763 struct chanNode
*chan
;
6765 struct record_data
*rd
;
6766 dict_t conf_node
, child
;
6767 const char *str
, *str2
;
6768 struct policer_params
*pp
;
6771 rd
= conf_get_node(OPSERV_CONF_NAME
);
6772 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
6773 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
6776 conf_node
= rd
->d
.object
;
6777 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
6778 if (opserv
&& str
) {
6779 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
6782 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6783 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
6785 opserv_conf
.debug_channel
= NULL
;
6787 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
6788 if (opserv
&& str
) {
6789 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
6792 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6793 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
6795 opserv_conf
.alert_channel
= NULL
;
6797 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
6798 if (opserv
&& str
) {
6799 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
6802 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6803 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
6805 opserv_conf
.staff_auth_channel
= NULL
;
6808 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
6809 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
6811 str
= database_get_data(conf_node
, KEY_SILENT_LEVEL
, RECDB_QSTRING
);
6812 opserv_conf
.silent_level
= str
? strtoul(str
, NULL
, 0): 700;
6814 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
6815 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
6816 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
6817 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
6818 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
6819 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
6820 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
6821 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
6822 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
6824 NickChange(opserv
, str
, 0);
6826 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
6827 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
6828 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
6829 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
6831 free_string_list(autojoin_channels
);
6832 autojoin_channels
= database_get_data(conf_node
, KEY_AUTOJOIN_CHANNELS
, RECDB_STRING_LIST
);
6834 if(autojoin_channels
)
6835 autojoin_channels
= string_list_copy(autojoin_channels
);
6837 if (autojoin_channels
&& opserv
) {
6838 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
6839 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
6840 AddChannelUser(opserv
, chan
)->modes
|= MODE_CHANOP
;
6844 str
= database_get_data(conf_node
, KEY_BLOCK_SHUN_DURATION
, RECDB_QSTRING
);
6845 opserv_conf
.block_shun_duration
= str
? ParseInterval(str
) : 3600;
6847 if (!opserv_conf
.join_policer_params
)
6848 opserv_conf
.join_policer_params
= policer_params_new();
6849 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
6850 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
6851 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
6852 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
6854 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
6855 struct chanNode
*cNode
= iter_data(it
);
6856 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
6859 if (opserv_conf
.new_user_policer
.params
)
6860 pp
= opserv_conf
.new_user_policer
.params
;
6862 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
6863 policer_params_set(pp
, "size", "200");
6864 policer_params_set(pp
, "drain-rate", "3");
6865 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
6866 dict_foreach(child
, set_policer_param
, pp
);
6868 /* Defcon configuration */
6870 str
= database_get_data(conf_node
, KEY_DEFCON1
, RECDB_QSTRING
);
6871 DefCon
[1] = str
? atoi(str
) : 415;
6872 str
= database_get_data(conf_node
, KEY_DEFCON2
, RECDB_QSTRING
);
6873 DefCon
[2] = str
? atoi(str
) : 159;
6874 str
= database_get_data(conf_node
, KEY_DEFCON3
, RECDB_QSTRING
);
6875 DefCon
[3] = str
? atoi(str
) : 31;
6876 str
= database_get_data(conf_node
, KEY_DEFCON4
, RECDB_QSTRING
);
6877 DefCon
[4] = str
? atoi(str
) : 23;
6880 str
= database_get_data(conf_node
, KEY_DEFCON_LEVEL
, RECDB_QSTRING
);
6881 DefConLevel
= str
? atoi(str
) : 5;
6883 str
= database_get_data(conf_node
, KEY_DEFCON_CHANMODES
, RECDB_QSTRING
);
6884 DefConChanModes
= str
? strdup(str
) : "+r";
6886 str
= database_get_data(conf_node
, KEY_DEFCON_SESSION_LIMIT
, RECDB_QSTRING
);
6887 DefConSessionLimit
= str
? atoi(str
) : 2;
6889 str
= database_get_data(conf_node
, KEY_DEFCON_TIMEOUT
, RECDB_QSTRING
);
6890 DefConTimeOut
= str
? ParseInterval(str
) : 900;
6892 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_DURATION
, RECDB_QSTRING
);
6893 DefConGlineExpire
= str
? ParseInterval(str
) : 300;
6895 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL
, RECDB_QSTRING
);
6896 GlobalOnDefcon
= str
? atoi(str
) : 0;
6898 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL_MORE
, RECDB_QSTRING
);
6899 GlobalOnDefconMore
= str
? atoi(str
) : 0;
6901 str
= database_get_data(conf_node
, KEY_DEFCON_MESSAGE
, RECDB_QSTRING
);
6902 DefConMessage
= str
? strdup(str
) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore";
6904 str
= database_get_data(conf_node
, KEY_DEFCON_OFF_MESSAGE
, RECDB_QSTRING
);
6905 DefConOffMessage
= str
? strdup(str
) : "Services are now back to normal, sorry for any inconvenience";
6907 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_REASON
, RECDB_QSTRING
);
6908 DefConGlineReason
= str
? strdup(str
) : "This network is currently not accepting connections, please try again later";
6911 /* lame way to export opserv_conf value to nickserv.c ... */
6913 opserv_conf_admin_level()
6915 return(opserv_conf
.admin_level
);
6919 opserv_db_init(void) {
6920 /* set up opserv_trusted_hosts dict */
6921 dict_delete(opserv_trusted_hosts
);
6922 opserv_trusted_hosts
= dict_new();
6923 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
6925 opserv_routing_plan_options
= dict_new();
6927 opserv_routing_plans
= dict_new();
6928 dict_set_free_data(opserv_routing_plans
, free_routing_plan
);
6929 /* set up opserv_chan_warn dict */
6931 /* alert trace notice channel #x replaces warnings
6932 dict_delete(opserv_chan_warn);
6933 opserv_chan_warn = dict_new();
6934 dict_set_free_keys(opserv_chan_warn, free);
6935 dict_set_free_data(opserv_chan_warn, free);
6937 /* set up opserv_user_alerts */
6938 dict_delete(opserv_channel_alerts
);
6939 opserv_channel_alerts
= dict_new();
6940 dict_delete(opserv_nick_based_alerts
);
6941 opserv_nick_based_alerts
= dict_new();
6942 dict_delete(opserv_user_alerts
);
6943 opserv_user_alerts
= dict_new();
6944 dict_set_free_keys(opserv_user_alerts
, free
);
6945 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
6946 /* set up opserv_bad_words */
6947 free_string_list(opserv_bad_words
);
6948 opserv_bad_words
= alloc_string_list(4);
6949 /* and opserv_exempt_channels */
6950 dict_delete(opserv_exempt_channels
);
6951 opserv_exempt_channels
= dict_new();
6952 dict_set_free_keys(opserv_exempt_channels
, free
);
6956 opserv_db_cleanup(void)
6960 /* dict_delete(opserv_chan_warn); */
6961 dict_delete(opserv_reserved_nick_dict
);
6962 free_string_list(opserv_bad_words
);
6963 dict_delete(opserv_exempt_channels
);
6964 dict_delete(opserv_trusted_hosts
);
6965 unreg_del_user_func(opserv_user_cleanup
);
6966 dict_delete(opserv_hostinfo_dict
);
6967 dict_delete(opserv_nick_based_alerts
);
6968 dict_delete(opserv_channel_alerts
);
6969 dict_delete(opserv_user_alerts
);
6970 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
6971 free(level_strings
[nn
]);
6974 policer_params_delete(opserv_conf
.join_policer_params
);
6975 policer_params_delete(opserv_conf
.new_user_policer
.params
);
6979 init_opserv(const char *nick
)
6981 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
6983 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
6984 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
6986 conf_register_reload(opserv_conf_read
);
6988 memset(level_strings
, 0, sizeof(level_strings
));
6989 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
6990 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
6991 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
6992 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
6993 opserv_define_func("ADDALERT SILENT", NULL
, 900, 0, 0);
6994 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
6995 opserv_define_func("ADDALERT SHUN", NULL
, 900, 0, 0);
6996 opserv_define_func("ADDALERT TRACK", NULL
, 900, 0, 0);
6997 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
6998 opserv_define_func("ADDALERT SVSJOIN", NULL
, 999, 0, 0);
6999 opserv_define_func("ADDALERT SVSPART", NULL
, 999, 0, 0);
7000 opserv_define_func("ADDALERT VERSION", NULL
, 999, 0, 0);
7001 opserv_define_func("ADDALERT MARK", NULL
, 999, 0, 0);
7002 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
7003 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
7004 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
7005 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
7006 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
7007 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
7008 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
7009 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
7010 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
7011 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
7012 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
7013 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
7014 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
7015 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
7016 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
7017 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
7018 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
7019 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
7020 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
7021 opserv_define_func("DEFCON", cmd_defcon
, 900, 0, 0);
7022 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
7023 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
7024 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
7025 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
7026 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
7027 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
7028 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
7029 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
7030 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
7031 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
7032 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
7033 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
7034 opserv_define_func("SBLOCK", cmd_sblock
, 100, 0, 2);
7035 opserv_define_func("SHUN", cmd_shun
, 600, 0, 4);
7036 opserv_define_func("SSYNC", cmd_ssync
, 600, 0, 0);
7037 opserv_define_func("STRACE", cmd_strace
, 100, 0, 3);
7038 opserv_define_func("STRACE COUNT", NULL
, 0, 0, 0);
7039 opserv_define_func("STRACE PRINT", NULL
, 0, 0, 0);
7040 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
7041 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
7042 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
7043 opserv_define_func("SVSNICK", cmd_svsnick
, 999, 0, 3);
7044 opserv_define_func("SVSJOIN", cmd_svsjoin
, 999, 0, 3);
7045 opserv_define_func("SVSPART", cmd_svspart
, 999, 0, 3);
7046 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
7047 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
7048 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
7049 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
7050 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
7051 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
7052 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
7053 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
7054 opserv_define_func("MARK", cmd_mark
, 900, 0, 3);
7055 opserv_define_func("OP", cmd_op
, 100, 2, 2);
7056 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
7057 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
7058 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
7059 opserv_define_func("MAP", cmd_stats_links
, 0, 0, 0);
7060 opserv_define_func("PRIVSET", cmd_privset
, 900, 0, 3);
7061 opserv_define_func("PART", cmd_part
, 601, 0, 2);
7062 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
7063 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
7064 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
7065 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
7066 opserv_define_func("REFRESHS", cmd_refreshs
, 600, 0, 0);
7067 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
7068 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
7069 opserv_define_func("RESETMAX", cmd_resetmax
, 900, 0, 0);
7070 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
7071 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
7072 opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan
, 800, 0, 2);
7073 opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan
, 800, 0, 2);
7074 opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver
, 800, 0, 4);
7075 opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver
, 800, 0, 3);
7076 opserv_define_func("ROUTING MAP", cmd_routing_map
, 800, 0, 0);
7077 opserv_define_func("ROUTING SET", cmd_routing_set
, 800, 0, 0);
7078 opserv_define_func("REROUTE", cmd_reroute
, 800, 0, 2);
7079 opserv_define_func("SET", cmd_set
, 900, 0, 3);
7080 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
7081 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
7082 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
7083 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
7084 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
7085 opserv_define_func("STATS SHUNS", cmd_stats_shuns
, 0, 0, 0);
7086 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
7087 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
7088 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
7089 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
7090 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
7091 opserv_define_func("STATS ROUTING", cmd_stats_routing_plans
, 0, 0, 0);
7092 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
7093 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
7094 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
7095 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
7096 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
7097 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
7098 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
7100 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
7101 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
7102 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
7103 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
7104 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
7105 opserv_define_func("TRACE SHUN", NULL
, 600, 0, 0);
7106 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
7107 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
7108 opserv_define_func("TRACE VERSION", NULL
, 999, 0, 0);
7109 opserv_define_func("TRACE SVSJOIN", NULL
, 999, 0, 0);
7110 opserv_define_func("TRACE SVSPART", NULL
, 999, 0, 0);
7111 opserv_define_func("TRACE MARK", NULL
, 999, 0, 0);
7112 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
7113 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
7114 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
7115 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
7116 opserv_define_func("UNSHUN", cmd_unshun
, 600, 0, 2);
7117 modcmd_register(opserv_module
, "GTRACE UNSHUN", NULL
, 0, 0, "template", "unshun", NULL
);
7118 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
7119 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
7120 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
7121 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
7122 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
7123 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
7125 opserv_reserved_nick_dict
= dict_new();
7126 opserv_hostinfo_dict
= dict_new();
7128 dict_set_free_keys(opserv_hostinfo_dict
, free
);
7129 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
7131 opserv_waiting_connections
= dict_new();
7132 dict_set_free_data(opserv_waiting_connections
, opserv_free_waiting_connection
);
7134 reg_new_user_func(opserv_new_user_check
);
7135 reg_nick_change_func(opserv_alert_check_nick
);
7136 reg_del_user_func(opserv_user_cleanup
);
7137 reg_new_channel_func(opserv_channel_check
);
7138 reg_del_channel_func(opserv_channel_delete
);
7139 reg_join_func(opserv_join_check
);
7140 reg_auth_func(opserv_staff_alert
);
7141 reg_notice_func(opserv
, opserv_notice_handler
);
7144 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
7147 opserv_service
= service_register(opserv
);
7148 opserv_service
->trigger
= '?';
7151 /* start auto-routing system */
7152 /* this cant be done here, because the routing system isnt marked active yet. */
7153 /* reroute_timer(NULL); */
7155 /* start the karma timer, using the saved one if available */
7156 routing_karma_timer(dict_find(opserv_routing_plan_options
, "KARMA_TIMER", NULL
));
7158 reg_exit_func(opserv_db_cleanup
);
7159 message_register_table(msgtab
);