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_NOT_THERE", "You not in $b%s$b." },
169 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
170 { "OSMSG_MARK_SET", "Set the MARK." },
171 { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." },
172 { "OSMSG_SVSPART_SENT", "Sent the SVSPART." },
173 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
174 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
175 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
176 { "OSMSG_LEAVING", "Leaving $b%s$b." },
177 { "OSMSG_MARK_INVALID", "Sorry, marks must contain only letters, numbers, and dashes ('-')." },
178 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
179 { "OSMSG_OP_DONE", "Opped the requested lusers." },
180 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
181 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
182 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
183 { "OMSG_BAD_SVSNICK", "$b%s$b is an invalid nickname." },
185 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
186 { "OSMSG_WHOIS_NICK", "Nick : %s" },
187 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
188 { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" },
189 { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" },
190 { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" },
191 { "OSMSG_WHOIS_IP", "Real IP : %s" },
192 { "OSMSG_WHOIS_COUNTRY", "Country : %s" },
193 { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" },
194 { "OSMSG_WHOIS_CITY", "City : %s" },
195 { "OSMSG_WHOIS_REGION", "Region/State : %s" },
196 { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" },
197 { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" },
198 { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" },
199 { "OSMSG_WHOIS_MAP", "Map : %s" },
200 { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" },
201 { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" },
202 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
203 { "OSMSG_WHOIS_INFO", "Info : %s" },
204 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
205 { "OSMSG_WHOIS_SERVER", "Server : %s" },
206 { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" },
207 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
208 { "OSMSG_WHOIS_PRIVS", "IRCd Privs : %s" },
209 { "OSMSG_WHOIS_CHANNELS", "Channels : %s" },
210 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
211 { "OSMSG_WHOIS_VERSION", "Version : %s" },
212 { "OSMSG_WHOIS_MARK", "Mark : %s" },
213 { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" },
214 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
215 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
216 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
217 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
218 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
219 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
220 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
221 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
222 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
223 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
224 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
225 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
226 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
227 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
228 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
229 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
230 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
231 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
232 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
233 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
234 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
235 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
236 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
237 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
238 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
239 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
240 { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." },
241 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
242 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
243 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
244 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
245 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
246 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
247 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
248 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
249 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
250 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
251 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
252 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
253 { "OSMSG_LINE_DUMPED", "Raw line sent." },
254 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
255 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
256 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
257 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
258 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
259 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
260 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
261 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
262 { "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." },
263 { "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." },
264 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
265 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
266 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
267 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
268 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
269 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
270 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
271 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
272 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
273 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
274 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
275 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
276 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
277 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
278 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
279 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
280 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
281 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
282 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
283 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
284 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
285 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
286 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
287 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
288 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
289 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
290 { "OSMSG_MARK_NO_MARK", "MARK action requires mark criteria (what do you want to mark them as?)" },
291 { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" },
292 { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" },
293 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
294 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
295 { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" },
296 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
297 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
298 { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
299 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
300 { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
301 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
302 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
303 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
304 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
305 { "OSMSG_NO_GAGS", "No gags have been set." },
306 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
307 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
308 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
309 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
310 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
311 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
312 { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" },
313 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
314 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
315 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" },
316 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
317 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
318 { "OSMSG_ALERTS_DESC", " $uCriteria$u: %s" },
319 { "OSMSG_ALERTS_LAST", " $uTriggered$u: %s" },
320 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
321 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
322 /* routing messages */
323 { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" },
324 { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" },
325 { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" },
326 { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" },
327 { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" },
328 { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." },
329 { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." },
330 { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." },
331 { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." },
332 { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" },
333 { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" },
334 { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" },
335 { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." },
336 { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." },
337 { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." },
338 { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." },
339 { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." },
340 { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." },
341 { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." },
342 { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." },
343 { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." },
344 { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" },
345 { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" },
346 { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" },
347 { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" },
348 { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" },
349 { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." },
350 { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." },
351 { "OSMSG_CONNECT", "->connect %s %d %s" },
352 { "OSMSG_SQUIT", "->squit %s" },
353 { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" },
354 { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" },
355 { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." },
356 { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." },
357 { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." },
358 { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." },
359 { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." },
360 { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", },
361 { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." },
362 { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." },
364 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
365 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
366 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
367 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
368 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
369 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
370 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
371 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
372 { "OSMSG_INVALID_NUMERIC", "Invalid numeric" },
373 { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." },
374 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
375 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
377 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
378 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
379 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
380 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
381 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
382 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
383 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
385 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
386 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
387 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
388 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
389 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
390 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
391 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
392 { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." },
393 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
394 { "OSMSG_CHANINFO_HEADER", "%s Information" },
395 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
396 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
397 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
398 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
399 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
400 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
401 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
402 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
403 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
404 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
405 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
406 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
407 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
408 { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" },
409 { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" },
411 { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" },
412 { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" },
413 { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" },
414 { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" },
415 { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" },
416 { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" },
417 { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" },
418 { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" },
419 { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" },
420 { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" },
421 { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" },
422 { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" },
423 { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" },
424 { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" },
426 { "OSMSG_PRIV_UNKNOWN", "Unknown privilege flag %s, see /msg $O HELP PRIVFLAGS for a flag list" },
427 { "OSMSG_PRIV_SET", "Privilege flag %s has been %sset" },
432 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
437 int GlobalOnDefcon
= 0;
438 int GlobalOnDefconMore
= 0;
439 int DefConGlineExpire
;
440 int DefConModesSet
= 0;
441 unsigned int DefConSessionLimit
;
442 char *DefConChanModes
;
443 char *DefConGlineReason
;
445 char *DefConOffMessage
;
447 extern void add_track_user(struct userNode
*user
);
448 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
450 struct userNode
*opserv
;
451 static struct service
*opserv_service
;
453 /*static dict_t opserv_chan_warn; */ /* data is char* */
454 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
455 static struct string_list
*opserv_bad_words
;
456 static dict_t opserv_exempt_channels
; /* data is not used */
457 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
458 static dict_t opserv_routing_plans
; /* data is struct routingPlan */
459 static dict_t opserv_routing_plan_options
; /* data is a dict_t key->val list*/
460 static dict_t opserv_waiting_connections
; /* data is struct waitingConnection */
461 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
462 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
463 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
464 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
465 static struct module *opserv_module
;
466 static struct log_type
*OS_LOG
;
467 static unsigned int new_user_flood
;
468 static char *level_strings
[1001];
469 struct string_list
*autojoin_channels
;
470 struct route
*opserv_route
= NULL
; /* Main active routing table from activate_routing()*/
473 struct chanNode
*debug_channel
;
474 struct chanNode
*alert_channel
;
475 struct chanNode
*staff_auth_channel
;
476 struct policer_params
*join_policer_params
;
477 struct policer new_user_policer
;
478 unsigned long untrusted_max
;
479 unsigned long clone_gline_duration
;
480 unsigned long block_gline_duration
;
481 unsigned long block_shun_duration
;
482 unsigned long purge_lock_delay
;
483 unsigned long join_flood_moderate
;
484 unsigned long join_flood_moderate_threshold
;
485 unsigned long admin_level
;
486 unsigned long silent_level
;
489 struct trusted_host
{
503 struct gag_entry
*next
;
506 static struct gag_entry
*gagList
;
508 struct opserv_hostinfo
{
509 struct userList clients
;
510 struct trusted_host
*trusted
;
514 opserv_free_hostinfo(void *data
)
516 struct opserv_hostinfo
*ohi
= data
;
517 userList_clean(&ohi
->clients
);
522 opserv_free_waiting_connection(void *data
)
524 struct waitingConnection
*wc
= data
;
530 typedef struct opservDiscrim
{
531 struct chanNode
*channel
;
532 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *mask_version
, *server
, *reason
, *accountmask
, *chantarget
, *mark
, *mask_mark
, *modes
;
533 irc_in_addr_t ip_mask
;
535 time_t min_ts
, max_ts
;
536 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
, regex_version
;
537 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1, has_regex_version
: 1;
538 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
539 unsigned char ip_mask_bits
;
540 unsigned int match_opers
: 1, option_log
: 1;
541 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
542 int authed
: 2, info_space
: 2;
543 unsigned int intra_scmp
: 2, intra_dcmp
: 2;
544 unsigned int use_regex
: 1;
545 unsigned int silent
: 1;
546 unsigned int checkrestrictions
: 2;
549 struct discrim_and_source
{
551 struct userNode
*source
;
552 struct userNode
*destination
;
554 unsigned int disp_limit
;
557 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
558 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
559 static int gag_helper_func(struct userNode
*match
, void *extra
);
560 static int ungag_helper_func(struct userNode
*match
, void *extra
);
572 } opserv_alert_reaction
;
574 struct opserv_user_alert
{
576 char *text_discrim
, *split_discrim
;
578 opserv_alert_reaction reaction
;
582 /* funny type to make it acceptible to dict_set_free_data, far below */
584 opserv_free_user_alert(void *data
)
586 struct opserv_user_alert
*alert
= data
;
587 if (alert
->discrim
->channel
)
588 UnlockChannel(alert
->discrim
->channel
);
590 free(alert
->text_discrim
);
591 free(alert
->split_discrim
);
592 if(alert
->discrim
->has_regex_nick
)
593 regfree(&alert
->discrim
->regex_nick
);
594 if(alert
->discrim
->has_regex_ident
)
595 regfree(&alert
->discrim
->regex_ident
);
596 if(alert
->discrim
->has_regex_host
)
597 regfree(&alert
->discrim
->regex_host
);
598 if(alert
->discrim
->has_regex_info
)
599 regfree(&alert
->discrim
->regex_info
);
600 if(alert
->discrim
->has_regex_version
)
601 regfree(&alert
->discrim
->regex_version
);
602 free(alert
->discrim
->reason
);
603 free(alert
->discrim
);
607 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
608 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
611 char *defconReverseModes(const char *modes
)
613 char *newmodes
= NULL
;
618 if (!(newmodes
= malloc(sizeof(char) * strlen(modes
) + 1))) {
621 for (i
= 0; i
< strlen(modes
); i
++) {
624 else if (modes
[i
] == '-')
627 newmodes
[i
] = modes
[i
];
633 int checkDefCon(int level
)
635 return DefCon
[DefConLevel
] & level
;
638 void showDefConSettings(struct userNode
*user
, struct svccmd
*cmd
)
640 if (DefConLevel
== 5) {
641 reply("OSMSG_DEFCON_ALLOWING_ALL");
644 reply("OSMSG_DEFCON_DISALLOWING", DefConLevel
);
646 if (checkDefCon(DEFCON_NO_NEW_CHANNELS
))
647 reply("OSMSG_DEFCON_NO_NEW_CHANNELS");
649 if (checkDefCon(DEFCON_NO_NEW_NICKS
))
650 reply("OSMSG_DEFCON_NO_NEW_NICKS");
652 if (checkDefCon(DEFCON_NO_MODE_CHANGE
))
653 reply("OSMSG_DEFCON_NO_MODE_CHANGE");
655 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
) && (DefConChanModes
))
656 reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes
);
658 if (checkDefCon(DEFCON_REDUCE_SESSION
))
659 reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit
);
661 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
))
662 reply("OSMSG_DEFCON_NO_NEW_CLIENTS");
664 if (checkDefCon(DEFCON_OPER_ONLY
))
665 reply("OSMSG_DEFCON_OPER_ONLY");
667 if (checkDefCon(DEFCON_SILENT_OPER_ONLY
))
668 reply("OSMSG_DEFCON_SILENT_OPER_ONLY");
670 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
671 reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS");
673 if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
674 reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS");
676 if (checkDefCon(DEFCON_NO_NEW_MEMOS
))
677 reply("OSMSG_DEFCON_NO_NEW_MEMOS");
682 void do_mass_mode(char *modes
)
689 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
690 struct chanNode
*chan
= iter_data(it
);
692 irc_mode(opserv
, chan
, modes
);
697 void DefConProcess(struct userNode
*user
)
702 global_message_args(MESSAGE_RECIPIENT_LUSERS
, "DEFCON_NETWORK_CHANGED", DefConLevel
);
704 if (GlobalOnDefconMore
&& GlobalOnDefcon
)
705 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConMessage
);
707 if ((DefConLevel
== 5) && !GlobalOnDefconMore
&& !GlobalOnDefcon
)
708 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConOffMessage
);
711 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_OPER_LEVEL_CHANGE", user
->nick
, DefConLevel
);
713 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel
);
715 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
)) {
716 if (DefConChanModes
&& !DefConModesSet
) {
717 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
718 do_mass_mode(DefConChanModes
);
723 if (DefConChanModes
&& (DefConModesSet
!= 0)) {
724 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
725 if ((newmodes
= defconReverseModes(DefConChanModes
))) {
726 do_mass_mode(newmodes
);
738 defcon_timeout(UNUSED_ARG(void *data
))
744 static MODCMD_FUNC(cmd_defcon
)
746 if ((argc
< 2) || (atoi(argv
[1]) == DefConLevel
)) {
747 showDefConSettings(user
, cmd
);
751 if ((atoi(argv
[1]) < 1) || (atoi(argv
[1]) > 5)) {
752 reply("OSMSG_DEFCON_INVALID", atoi(argv
[1]));
756 DefConLevel
= atoi(argv
[1]);
757 showDefConSettings(user
, cmd
);
759 if (DefConTimeOut
> 0) {
760 timeq_del(0, defcon_timeout
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
761 timeq_add(now
+ DefConTimeOut
, defcon_timeout
, NULL
);
769 static MODCMD_FUNC(cmd_privallow)
771 //privallow servername/username +/-flag (global is set in conf)
774 static MODCMD_FUNC(cmd_privdissallow)
776 //privdisallow servername/username +/-flag (global is set in conf)
779 static MODCMD_FUNC(cmd_privlist)
781 //privlist servername/user (global with none)
785 static MODCMD_FUNC(cmd_privset
)
787 struct userNode
*target
;
795 } else if (*flag
== '+') {
800 target
= GetUserH(argv
[1]);
802 reply("MSG_NICK_UNKNOWN", argv
[1]);
806 if (check_priv(flag
)) {
807 irc_privs(target
, flag
, add
);
808 reply("OSMSG_PRIV_SET", argv
[2], (add
== 1) ? "" : "un");
810 reply("OSMSG_PRIV_UNKNOWN", argv
[2]);
817 /* A lot of these commands are very similar to what ChanServ can do,
818 * but OpServ can do them even on channels that aren't registered.
821 static MODCMD_FUNC(cmd_access
)
823 struct handle_info
*hi
;
827 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
828 if (!irccasecmp(target
, "*")) {
829 nickserv_show_oper_accounts(user
, cmd
);
832 if (!(hi
= modcmd_get_handle_info(user
, target
)))
834 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
835 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
839 static MODCMD_FUNC(cmd_ban
)
841 struct mod_chanmode change
;
842 struct userNode
*victim
;
844 mod_chanmode_init(&change
);
846 change
.args
[0].mode
= MODE_BAN
;
847 if (is_ircmask(argv
[1]))
848 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
849 else if ((victim
= GetUserH(argv
[1])))
850 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
852 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
855 modcmd_chanmode_announce(&change
);
856 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
857 free((char*)change
.args
[0].u
.hostmask
);
861 static MODCMD_FUNC(cmd_chaninfo
)
866 struct exemptNode
*exempt
;
867 struct modeNode
*moden
;
870 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
871 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
872 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
873 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
874 irc_make_chanmode(channel
, buffer
);
875 if (channel
->bad_channel
)
876 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
878 reply("OSMSG_CHANINFO_MODES", buffer
);
879 if (channel
->topic_time
) {
880 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
881 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
882 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
884 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
885 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
887 if (channel
->banlist
.used
) {
888 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
889 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
890 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
891 ban
= channel
->banlist
.list
[n
];
892 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
893 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
896 if (channel
->exemptlist
.used
) {
897 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
898 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
899 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
900 exempt
= channel
->exemptlist
.list
[n
];
901 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
902 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
905 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
906 /* early out unless they ask for users */
907 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
910 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
911 for (n
=0; n
<channel
->members
.used
; n
++) {
912 moden
= channel
->members
.list
[n
];
913 if (moden
->modes
& MODE_CHANOP
) {
914 if (moden
->oplevel
>= 0)
915 send_message_type(4, user
, cmd
->parent
->bot
, " @%s:%d (%s@%s)", moden
->user
->nick
, moden
->oplevel
, moden
->user
->ident
, moden
->user
->hostname
);
917 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
920 for (n
=0; n
<channel
->members
.used
; n
++) {
921 moden
= channel
->members
.list
[n
];
922 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
923 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
925 for (n
=0; n
<channel
->members
.used
; n
++) {
926 moden
= channel
->members
.list
[n
];
927 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
928 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
930 for (n
=0; n
<channel
->members
.used
; n
++) {
931 moden
= channel
->members
.list
[n
];
932 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
933 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
938 /* This command has been replaced by 'alert notice channel #foo' */
940 static MODCMD_FUNC(cmd_warn)
942 char *reason, *message;
944 if (!IsChannelName(argv[1])) {
945 reply("OSMSG_NEED_CHANNEL", argv[0]);
948 reason = dict_find(opserv_chan_warn, argv[1], NULL);
950 reply("OSMSG_WARN_EXISTS", argv[1]);
954 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
956 reason = strdup("No reason");
957 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
958 reply("OSMSG_WARN_ADDED", argv[1], reason);
959 if (dict_find(channels, argv[1], NULL)) {
960 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason);
965 static MODCMD_FUNC(cmd_unwarn)
967 if ((argc < 2) || !IsChannelName(argv[1])) {
968 reply("OSMSG_NEED_CHANNEL", argv[0]);
971 if (!dict_remove(opserv_chan_warn, argv[1])) {
972 reply("OSMSG_WARN_NOEXIST", argv[1]);
975 reply("OSMSG_WARN_DELETED", argv[1]);
980 static MODCMD_FUNC(cmd_clearbans
)
982 struct mod_chanmode
*change
;
985 change
= mod_chanmode_alloc(channel
->banlist
.used
);
986 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
987 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
988 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
990 modcmd_chanmode_announce(change
);
991 for (ii
=0; ii
<change
->argc
; ++ii
)
992 free((char*)change
->args
[ii
].u
.hostmask
);
993 mod_chanmode_free(change
);
994 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
998 static MODCMD_FUNC(cmd_clearmodes
)
1000 struct mod_chanmode change
;
1002 if (!channel
->modes
) {
1003 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
1006 mod_chanmode_init(&change
);
1007 change
.modes_clear
= channel
->modes
;
1008 modcmd_chanmode_announce(&change
);
1009 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
1013 static MODCMD_FUNC(cmd_deop
)
1015 struct mod_chanmode
*change
;
1016 unsigned int arg
, count
;
1018 change
= mod_chanmode_alloc(argc
-1);
1019 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1020 struct userNode
*victim
= GetUserH(argv
[arg
]);
1021 struct modeNode
*mn
;
1022 if (!victim
|| IsService(victim
)
1023 || !(mn
= GetUserMode(channel
, victim
))
1024 || !(mn
->modes
& MODE_CHANOP
))
1026 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1027 change
->args
[count
++].u
.member
= mn
;
1030 change
->argc
= count
;
1031 modcmd_chanmode_announce(change
);
1033 mod_chanmode_free(change
);
1034 reply("OSMSG_DEOP_DONE");
1038 static MODCMD_FUNC(cmd_dehop
)
1040 struct mod_chanmode
*change
;
1041 unsigned int arg
, count
;
1043 change
= mod_chanmode_alloc(argc
-1);
1044 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1045 struct userNode
*victim
= GetUserH(argv
[arg
]);
1046 struct modeNode
*mn
;
1047 if (!victim
|| IsService(victim
)
1048 || !(mn
= GetUserMode(channel
, victim
))
1049 || !(mn
->modes
& MODE_HALFOP
))
1051 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1052 change
->args
[count
++].u
.member
= mn
;
1055 change
->argc
= count
;
1056 modcmd_chanmode_announce(change
);
1058 mod_chanmode_free(change
);
1059 reply("OSMSG_DEHOP_DONE");
1063 static MODCMD_FUNC(cmd_deopall
)
1065 struct mod_chanmode
*change
;
1066 unsigned int ii
, count
;
1068 change
= mod_chanmode_alloc(channel
->members
.used
);
1069 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1070 struct modeNode
*mn
= channel
->members
.list
[ii
];
1071 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
1073 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1074 change
->args
[count
++].u
.member
= mn
;
1077 change
->argc
= count
;
1078 modcmd_chanmode_announce(change
);
1080 mod_chanmode_free(change
);
1081 reply("OSMSG_DEOPALL_DONE", channel
->name
);
1085 static MODCMD_FUNC(cmd_dehopall
)
1087 struct mod_chanmode
*change
;
1088 unsigned int ii
, count
;
1090 change
= mod_chanmode_alloc(channel
->members
.used
);
1091 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1092 struct modeNode
*mn
= channel
->members
.list
[ii
];
1093 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
1095 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1096 change
->args
[count
++].u
.member
= mn
;
1099 change
->argc
= count
;
1100 modcmd_chanmode_announce(change
);
1102 mod_chanmode_free(change
);
1103 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
1107 static MODCMD_FUNC(cmd_resetmax
)
1109 max_clients
= dict_size(clients
);
1110 max_clients_time
= now
;
1111 reply("OSMSG_MAXUSERS_RESET", max_clients
);
1115 static MODCMD_FUNC(cmd_rehash
)
1117 extern char *services_config
;
1119 if (conf_read(services_config
))
1120 reply("OSMSG_REHASH_COMPLETE");
1122 reply("OSMSG_REHASH_FAILED");
1126 static MODCMD_FUNC(cmd_reopen
)
1129 reply("OSMSG_REOPEN_COMPLETE");
1133 static MODCMD_FUNC(cmd_reconnect
)
1135 reply("OSMSG_RECONNECTING");
1136 irc_squit(self
, "Reconnecting.", NULL
);
1140 static MODCMD_FUNC(cmd_jupe
)
1142 extern int force_n2k
;
1143 struct server
*newsrv
;
1145 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
1147 num
= atoi(argv
[2]);
1149 reply("OSMSG_INVALID_NUMERIC");
1152 if ((num
< 64) && !force_n2k
) {
1153 inttobase64(numeric
, num
, 1);
1154 inttobase64(numeric
+1, 64*64-1, 2);
1156 inttobase64(numeric
, num
, 2);
1157 inttobase64(numeric
+2, 64*64*64-1, 3);
1159 #ifdef WITH_PROTOCOL_P10
1160 if (GetServerN(numeric
)) {
1161 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
1165 if (GetServerH(argv
[1])) {
1166 reply("OSMSG_NAME_COLLIDE");
1169 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
1170 if(!strchr(argv
[1], '.')) {
1171 reply("OSMSG_INVALID_SERVERNAME");
1174 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
1176 reply("OSMSG_SRV_CREATE_FAILED");
1180 reply("OSMSG_SERVER_JUPED", argv
[1]);
1184 static MODCMD_FUNC(cmd_unjupe
)
1189 srv
= GetServerH(argv
[1]);
1191 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1194 if (strncmp(srv
->description
, "JUPE", 4)) {
1195 reply("OSMSG_SERVER_NOT_JUPE");
1198 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
1199 DelServer(srv
, 1, reason
);
1200 reply("OSMSG_SERVER_UNJUPED");
1204 static MODCMD_FUNC(cmd_jump
)
1206 extern struct cManagerNode cManager
;
1207 void uplink_select(char *name
);
1208 struct uplinkNode
*uplink_find(char *name
);
1209 struct uplinkNode
*uplink
;
1212 target
= unsplit_string(argv
+1, argc
-1, NULL
);
1214 if (!strcmp(cManager
.uplink
->name
, target
)) {
1215 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
1219 uplink
= uplink_find(target
);
1221 reply("OSMSG_INVALID_UPLINK", target
);
1224 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
1225 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
1229 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
1230 uplink_select(target
);
1231 irc_squit(self
, "Reconnecting.", NULL
);
1235 static MODCMD_FUNC(cmd_die
)
1237 char *reason
, *text
;
1239 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1240 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
1241 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
1242 irc_squit(self
, reason
, text
);
1247 static MODCMD_FUNC(cmd_restart
)
1249 extern int services_argc
;
1250 extern char **services_argv
;
1251 char **restart_argv
, *reason
, *text
;
1253 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1254 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
1255 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
1256 irc_squit(self
, reason
, text
);
1258 /* Append a NULL to the end of argv[]. */
1259 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
1260 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
1261 restart_argv
[services_argc
] = NULL
;
1266 execv(services_argv
[0], restart_argv
);
1268 /* If we're still here, that means something went wrong. Reconnect. */
1272 static struct gline
*
1273 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
, int silent
)
1275 char mask
[IRC_NTOP_MAX_SIZE
+3] = { '*', '@', '\0' };
1276 irc_ntop(mask
+ 2, sizeof(mask
) - 2, &target
->ip
);
1278 snprintf(reason
= alloca(MAXLEN
), MAXLEN
,
1279 "G-line requested by %s.", src_handle
);
1281 duration
= opserv_conf
.block_gline_duration
;
1282 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1, silent
? 1 : 0);
1285 static MODCMD_FUNC(cmd_block
)
1287 struct userNode
*target
;
1288 struct gline
*gline
;
1291 target
= GetUserH(argv
[1]);
1293 reply("MSG_NICK_UNKNOWN", argv
[1]);
1296 if (IsService(target
)) {
1297 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1300 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1301 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0, 0);
1302 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1306 static MODCMD_FUNC(cmd_gline
)
1308 unsigned long duration
;
1310 struct gline
*gline
;
1312 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1313 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1314 reply("MSG_INVALID_GLINE", argv
[1]);
1317 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1318 reply("OSMSG_STUPID_GLINE", argv
[1]);
1321 duration
= ParseInterval(argv
[2]);
1323 reply("MSG_INVALID_DURATION", argv
[2]);
1326 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1, 0);
1327 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1331 static MODCMD_FUNC(cmd_ungline
)
1333 if (gline_remove(argv
[1], 1))
1334 reply("OSMSG_GLINE_REMOVED", argv
[1]);
1336 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
1340 static MODCMD_FUNC(cmd_refreshg
)
1347 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1348 srv
= iter_data(it
);
1349 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1351 gline_refresh_server(srv
);
1352 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
1356 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1360 gline_refresh_all();
1361 reply("OSMSG_GLINES_REFRESHED");
1367 opserv_version(struct userNode
*target
)
1369 irc_version_user(opserv
, target
);
1373 opserv_mark(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *mark
)
1377 irc_mark(target
, mark
);
1381 opserv_svsjoin(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
, unsigned int checkrestrictions
)
1383 struct chanNode
*channel
;
1385 if(!channame
|| !IsChannelName(channame
)) {
1386 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1390 if (!(channel
= GetChannel(channame
))) {
1391 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
1393 if (GetUserMode(channel
, target
)) {
1398 if (checkrestrictions
) {
1399 if (trace_check_bans(target
, channel
) == 1) {
1400 return; /* found on lamer list */
1403 if (channel
->modes
& MODE_INVITEONLY
) {
1404 return; /* channel is invite only */
1407 if (channel
->limit
> 0) {
1408 if (channel
->members
.used
>= channel
->limit
) {
1409 return; /* channel is invite on */
1413 if (*channel
->key
) {
1414 return; /* channel is password protected */
1418 irc_svsjoin(opserv
, target
, channel
);
1419 /* Should we tell the user they got joined? -Rubin*/
1423 opserv_svspart(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
)
1425 struct chanNode
*channel
;
1427 if(!channame
|| !IsChannelName(channame
)) {
1428 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1432 if (!(channel
= GetChannel(channame
))) {
1433 /* channel doesnt exist */
1437 if (!GetUserMode(channel
, target
)) {
1442 irc_svspart(opserv
, target
, channel
);
1445 static struct shun
*
1446 opserv_shun(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
1449 mask
= alloca(MAXLEN
);
1450 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
1452 reason
= alloca(MAXLEN
);
1453 snprintf(reason
, MAXLEN
, "Shun requested by %s.", src_handle
);
1455 if (!duration
) duration
= opserv_conf
.block_shun_duration
;
1456 return shun_add(src_handle
, mask
, duration
, reason
, now
, 1);
1459 static MODCMD_FUNC(cmd_sblock
)
1461 struct userNode
*target
;
1465 target
= GetUserH(argv
[1]);
1467 reply("MSG_NICK_UNKNOWN", argv
[1]);
1470 if (IsService(target
)) {
1471 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1474 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1475 shun
= opserv_shun(target
, user
->handle_info
->handle
, reason
, 0);
1476 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1480 static MODCMD_FUNC(cmd_shun
)
1482 unsigned long duration
;
1486 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1487 if (!is_shun(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1488 reply("MSG_INVALID_SHUN", argv
[1]);
1491 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1492 reply("OSMSG_STUPID_SHUN", argv
[1]);
1495 duration
= ParseInterval(argv
[2]);
1497 reply("MSG_INVALID_DURATION", argv
[2]);
1500 shun
= shun_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
1501 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1505 static MODCMD_FUNC(cmd_unshun
)
1507 if (shun_remove(argv
[1], 1))
1508 reply("OSMSG_SHUN_REMOVED", argv
[1]);
1510 reply("OSMSG_SHUN_FORCE_REMOVED", argv
[1]);
1514 static MODCMD_FUNC(cmd_refreshs
)
1521 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1522 srv
= iter_data(it
);
1523 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1525 shun_refresh_server(srv
);
1526 reply("OSMSG_SHUNS_ONE_REFRESHED", srv
->name
);
1530 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1535 reply("OSMSG_SHUNS_REFRESHED");
1541 opserv_ison(struct userNode
*bot
, struct userNode
*tell
, struct userNode
*target
, const char *message
)
1543 struct modeNode
*mn
;
1544 unsigned int count
, here_len
, n
, maxlen
;
1547 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
1549 maxlen
= MAX_LINE_SIZE
;
1550 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
1551 mn
= target
->channels
.list
[n
];
1552 here_len
= strlen(mn
->channel
->name
);
1553 if ((count
+ here_len
+ 4) > maxlen
) {
1555 send_message(tell
, bot
, message
, buff
);
1558 if (mn
->modes
& MODE_CHANOP
)
1559 buff
[count
++] = '@';
1560 if (mn
->modes
& MODE_HALFOP
)
1561 buff
[count
++] = '%';
1562 if (mn
->modes
& MODE_VOICE
)
1563 buff
[count
++] = '+';
1564 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
1566 buff
[count
++] = ' ';
1570 send_message(tell
, bot
, message
, buff
);
1574 static MODCMD_FUNC(cmd_inviteme
)
1576 struct userNode
*target
;
1581 target
= GetUserH(argv
[1]);
1583 reply("MSG_NICK_UNKNOWN", argv
[1]);
1587 if (opserv_conf
.debug_channel
== NULL
) {
1588 reply("OSMSG_NO_DEBUG_CHANNEL");
1591 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
1592 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1595 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1597 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1601 static MODCMD_FUNC(cmd_invite
)
1603 if (GetUserMode(channel
, user
)) {
1604 reply("OSMSG_ALREADY_THERE", channel
->name
);
1607 irc_invite(cmd
->parent
->bot
, user
, channel
);
1611 static MODCMD_FUNC(cmd_svsjoin
)
1613 struct userNode
*target
;
1616 if(!IsChannelName(argv
[2])) {
1617 reply("MSG_NOT_CHANNEL_NAME");
1620 target
= GetUserH(argv
[1]);
1622 reply("MSG_NICK_UNKNOWN", argv
[1]);
1626 if (!(channel
= GetChannel(argv
[2]))) {
1627 channel
= AddChannel(argv
[2], now
, NULL
, NULL
, NULL
);
1629 if (GetUserMode(channel
, target
)) {
1630 reply("OSMSG_ALREADY_THERE", channel
->name
);
1633 irc_svsjoin(opserv
, target
, channel
);
1634 reply("OSMSG_SVSJOIN_SENT");
1638 static MODCMD_FUNC(cmd_svsnick
)
1640 struct userNode
*target
;
1642 target
= GetUserH(argv
[1]);
1644 reply("MSG_NICK_UNKNOWN", argv
[1]);
1647 if(!is_valid_nick(argv
[2])) {
1648 reply("OMSG_BAD_SVSNICK", argv
[2]);
1651 irc_svsnick(opserv
, target
, argv
[2]);
1655 static MODCMD_FUNC(cmd_join
)
1657 struct userNode
*bot
= cmd
->parent
->bot
;
1659 if (!IsChannelName(argv
[1])) {
1660 reply("MSG_NOT_CHANNEL_NAME");
1662 } else if (!(channel
= GetChannel(argv
[1]))) {
1663 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1664 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1665 } else if (GetUserMode(channel
, bot
)) {
1666 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1669 struct mod_chanmode change
;
1670 mod_chanmode_init(&change
);
1672 change
.args
[0].mode
= MODE_CHANOP
;
1673 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1674 modcmd_chanmode_announce(&change
);
1676 irc_fetchtopic(bot
, channel
->name
);
1677 reply("OSMSG_JOIN_DONE", channel
->name
);
1681 static MODCMD_FUNC(cmd_kick
)
1683 struct userNode
*target
;
1687 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1688 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1690 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1692 target
= GetUserH(argv
[1]);
1694 reply("MSG_NICK_UNKNOWN", argv
[1]);
1697 if (!GetUserMode(channel
, target
)) {
1698 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1701 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1705 static MODCMD_FUNC(cmd_kickall
)
1707 unsigned int limit
, n
, inchan
;
1708 struct modeNode
*mn
;
1710 struct userNode
*bot
= cmd
->parent
->bot
;
1712 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1713 * channel, we have to join it in temporarily. */
1714 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1715 struct mod_chanmode change
;
1716 mod_chanmode_init(&change
);
1717 change
.args
[0].mode
= MODE_CHANOP
;
1718 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1719 modcmd_chanmode_announce(&change
);
1722 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1723 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1725 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1727 limit
= user
->handle_info
->opserv_level
;
1728 for (n
=channel
->members
.used
; n
>0;) {
1729 mn
= channel
->members
.list
[--n
];
1730 if (IsService(mn
->user
)
1731 || (mn
->user
->handle_info
1732 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1735 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1738 DelChannelUser(bot
, channel
, "My work here is done", 0);
1739 reply("OSMSG_KICKALL_DONE", channel
->name
);
1743 static MODCMD_FUNC(cmd_kickban
)
1745 struct mod_chanmode change
;
1746 struct userNode
*target
;
1751 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1752 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1754 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1756 target
= GetUserH(argv
[1]);
1758 reply("MSG_NICK_UNKNOWN", argv
[1]);
1761 if (!GetUserMode(channel
, target
)) {
1762 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1765 mod_chanmode_init(&change
);
1767 change
.args
[0].mode
= MODE_BAN
;
1768 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1769 modcmd_chanmode_announce(&change
);
1770 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1775 static MODCMD_FUNC(cmd_kickbanall
)
1777 struct modeNode
*mn
;
1778 struct userNode
*bot
= cmd
->parent
->bot
;
1779 struct mod_chanmode
*change
;
1781 unsigned int limit
, n
, inchan
;
1783 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1784 * channel, we have to join it in temporarily. */
1785 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1786 change
= mod_chanmode_alloc(2);
1787 change
->args
[0].mode
= MODE_CHANOP
;
1788 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1789 change
->args
[1].mode
= MODE_BAN
;
1790 change
->args
[1].u
.hostmask
= "*!*@*";
1792 change
= mod_chanmode_alloc(1);
1793 change
->args
[0].mode
= MODE_BAN
;
1794 change
->args
[0].u
.hostmask
= "*!*@*";
1796 modcmd_chanmode_announce(change
);
1797 mod_chanmode_free(change
);
1799 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1800 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1802 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1805 limit
= user
->handle_info
->opserv_level
;
1806 for (n
=channel
->members
.used
; n
>0; ) {
1807 mn
= channel
->members
.list
[--n
];
1808 if (IsService(mn
->user
)
1809 || (mn
->user
->handle_info
1810 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1813 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1816 DelChannelUser(bot
, channel
, "My work here is done", 0);
1817 reply("OSMSG_KICKALL_DONE", channel
->name
);
1821 static MODCMD_FUNC(cmd_svspart
)
1823 struct userNode
*target
;
1824 struct chanNode
*target_channel
;
1826 if(!IsChannelName(argv
[2])) {
1827 reply("MSG_NOT_CHANNEL_NAME");
1830 if(!(target_channel
= GetChannel(argv
[2])))
1832 reply("MSG_INVALID_CHANNEL");
1835 target
= GetUserH(argv
[1]);
1837 reply("MSG_NICK_UNKNOWN", argv
[1]);
1841 if (!GetUserMode(target_channel
, target
)) {
1842 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, target_channel
->name
);
1846 irc_svspart(opserv
, target
, target_channel
);
1847 reply("OSMSG_SVSPART_SENT");
1851 static MODCMD_FUNC(cmd_part
)
1855 if (!IsChannelName(argv
[1])) {
1856 reply("MSG_NOT_CHANNEL_NAME");
1859 if ((channel
= GetChannel(argv
[1]))) {
1860 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1861 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1864 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1865 reply("OSMSG_LEAVING", channel
->name
);
1866 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1871 static MODCMD_FUNC(cmd_mode
)
1873 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1874 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1877 reply("OSMSG_MODE_SET", channel
->name
);
1881 int is_valid_mark(char *mark
)
1887 if(strlen(mark
) > MARKLEN
)
1890 for(ptr
= mark
; *ptr
; ptr
++) {
1891 if(! (isalnum(*ptr
) || *ptr
== '-'))
1898 static MODCMD_FUNC(cmd_mark
)
1900 char *mark
= argv
[2];
1901 struct userNode
*victim
= GetUserH(argv
[1]);
1904 reply("MSG_NICK_UNKNOWN", argv
[1]);
1905 else if(!is_valid_mark(mark
))
1906 reply("OSMSG_MARK_INVALID");
1908 irc_mark(victim
, mark
);
1909 reply("OSMSG_MARK_SET");
1915 static MODCMD_FUNC(cmd_op
)
1917 struct mod_chanmode
*change
;
1918 unsigned int arg
, count
;
1920 change
= mod_chanmode_alloc(argc
-1);
1921 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1922 struct userNode
*victim
;
1923 struct modeNode
*mn
;
1924 if (!(victim
= GetUserH(argv
[arg
])))
1926 if (!(mn
= GetUserMode(channel
, victim
)))
1928 if (mn
->modes
& MODE_CHANOP
)
1930 change
->args
[count
].mode
= MODE_CHANOP
;
1931 change
->args
[count
++].u
.member
= mn
;
1934 change
->argc
= count
;
1935 modcmd_chanmode_announce(change
);
1937 mod_chanmode_free(change
);
1938 reply("OSMSG_OP_DONE");
1942 static MODCMD_FUNC(cmd_hop
)
1944 struct mod_chanmode
*change
;
1945 unsigned int arg
, count
;
1947 change
= mod_chanmode_alloc(argc
-1);
1948 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1949 struct userNode
*victim
;
1950 struct modeNode
*mn
;
1951 if (!(victim
= GetUserH(argv
[arg
])))
1953 if (!(mn
= GetUserMode(channel
, victim
)))
1955 if (mn
->modes
& MODE_HALFOP
)
1957 change
->args
[count
].mode
= MODE_HALFOP
;
1958 change
->args
[count
++].u
.member
= mn
;
1961 change
->argc
= count
;
1962 modcmd_chanmode_announce(change
);
1964 mod_chanmode_free(change
);
1965 reply("OSMSG_HOP_DONE");
1969 static MODCMD_FUNC(cmd_opall
)
1971 struct mod_chanmode
*change
;
1972 unsigned int ii
, count
;
1974 change
= mod_chanmode_alloc(channel
->members
.used
);
1975 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1976 struct modeNode
*mn
= channel
->members
.list
[ii
];
1977 if (mn
->modes
& MODE_CHANOP
)
1979 change
->args
[count
].mode
= MODE_CHANOP
;
1980 change
->args
[count
++].u
.member
= mn
;
1983 change
->argc
= count
;
1984 modcmd_chanmode_announce(change
);
1986 mod_chanmode_free(change
);
1987 reply("OSMSG_OPALL_DONE", channel
->name
);
1991 static MODCMD_FUNC(cmd_hopall
)
1993 struct mod_chanmode
*change
;
1994 unsigned int ii
, count
;
1996 change
= mod_chanmode_alloc(channel
->members
.used
);
1997 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1998 struct modeNode
*mn
= channel
->members
.list
[ii
];
1999 if (mn
->modes
& MODE_HALFOP
)
2001 change
->args
[count
].mode
= MODE_HALFOP
;
2002 change
->args
[count
++].u
.member
= mn
;
2005 change
->argc
= count
;
2006 modcmd_chanmode_announce(change
);
2008 mod_chanmode_free(change
);
2009 reply("OSMSG_HOPALL_DONE", channel
->name
);
2013 static MODCMD_FUNC(cmd_whois
)
2015 struct userNode
*target
;
2019 #ifdef WITH_PROTOCOL_P10
2020 if (argv
[1][0] == '*')
2021 target
= GetUserN(argv
[1]+1);
2024 target
= GetUserH(argv
[1]);
2026 reply("MSG_NICK_UNKNOWN", argv
[1]);
2029 reply("OSMSG_WHOIS_NICK", target
->nick
);
2030 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
2031 if (IsFakeHost(target
))
2032 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
2033 reply("OSMSG_WHOIS_CRYPT_HOST", target
->crypthost
);
2034 reply("OSMSG_WHOIS_CRYPT_IP", target
->cryptip
);
2035 reply("OSMSG_WHOIS_IP", irc_ntoa(&target
->ip
));
2038 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2039 reply("OSMSG_WHOIS_COUNTRY_CODE", target
->country_code
);
2040 reply("OSMSG_WHOIS_CITY", target
->city
);
2041 reply("OSMSG_WHOIS_REGION", target
->region
);
2043 reply("OSMSG_WHOIS_POSTAL_CODE", target
->postal_code
);
2044 reply("OSMSG_WHOIS_LATITUDE", target
->latitude
);
2045 reply("OSMSG_WHOIS_LONGITUDE", target
->longitude
);
2046 /* Only show a map url if we have a city, latitude and longitude.
2047 * Theres not much point of latitude and longitude coordinates are
2048 * returned but no city, the coordinates are useless.
2050 if (target
->latitude
&& target
->longitude
&& target
->city
) {
2051 char map_url
[MAXLEN
];
2052 snprintf(map_url
, sizeof(map_url
), "http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=%f&longitude=%f",
2053 target
->latitude
, target
->longitude
);
2054 reply("OSMSG_WHOIS_MAP", map_url
);
2056 reply("OSMSG_WHOIS_DMA_CODE", target
->dma_code
);
2057 reply("OSMSG_WHOIS_AREA_CODE", target
->area_code
);
2058 } else if (target
->country_name
) {
2059 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2061 if(target
->version_reply
) {
2062 reply("OSMSG_WHOIS_VERSION", target
->version_reply
);
2065 reply("OSMSG_WHOIS_MARK", target
->mark
);
2067 reply("OSMSG_WHOIS_NO_NOTICE", target
->no_notice
? "YES":"NO");
2069 if (target
->modes
) {
2071 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
2072 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
2073 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
2074 if (IsOper(target
)) buffer
[bpos
++] = 'o';
2075 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
2076 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
2078 // sethost - reed/apples
2079 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
2080 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
2082 if (IsService(target
)) buffer
[bpos
++] = 'k';
2083 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
2084 if (target
->handle_info
) buffer
[bpos
++] = 'r';
2085 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
2086 if (IsBotM(target
)) buffer
[bpos
++] = 'B';
2087 if (IsHideChans(target
)) buffer
[bpos
++] = 'n';
2088 if (IsHideIdle(target
)) buffer
[bpos
++] = 'I';
2089 if (IsXtraOp(target
)) buffer
[bpos
++] = 'X';
2090 if (IsGagged(target
)) buffer_cat(" (gagged)");
2091 if (IsRegistering(target
)) buffer_cat(" (registered account)");
2094 reply("OSMSG_WHOIS_MODES", buffer
);
2096 reply("OSMSG_WHOIS_INFO", target
->info
);
2097 #ifdef WITH_PROTOCOL_P10
2098 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
2100 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
2101 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
2103 reply("OSMSG_WHOIS_PRIVS", client_report_privs(target
));
2105 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
2106 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
2107 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
2108 opserv_ison(cmd
->parent
->bot
, user
, target
, "OSMSG_WHOIS_CHANNELS");
2110 reply("OSMSG_WHOIS_HIDECHANS");
2114 static MODCMD_FUNC(cmd_unban
)
2116 struct mod_chanmode change
;
2117 mod_chanmode_init(&change
);
2119 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
2120 change
.args
[0].u
.hostmask
= argv
[1];
2121 modcmd_chanmode_announce(&change
);
2122 reply("OSMSG_UNBAN_DONE", channel
->name
);
2126 static MODCMD_FUNC(cmd_voiceall
)
2128 struct mod_chanmode
*change
;
2129 unsigned int ii
, count
;
2131 change
= mod_chanmode_alloc(channel
->members
.used
);
2132 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2133 struct modeNode
*mn
= channel
->members
.list
[ii
];
2134 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
2136 change
->args
[count
].mode
= MODE_VOICE
;
2137 change
->args
[count
++].u
.member
= mn
;
2140 change
->argc
= count
;
2141 modcmd_chanmode_announce(change
);
2143 mod_chanmode_free(change
);
2144 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
2148 static MODCMD_FUNC(cmd_devoiceall
)
2150 struct mod_chanmode
*change
;
2151 unsigned int ii
, count
;
2153 change
= mod_chanmode_alloc(channel
->members
.used
);
2154 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2155 struct modeNode
*mn
= channel
->members
.list
[ii
];
2156 if (!(mn
->modes
& MODE_VOICE
))
2158 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
2159 change
->args
[count
++].u
.member
= mn
;
2162 change
->argc
= count
;
2163 modcmd_chanmode_announce(change
);
2165 mod_chanmode_free(change
);
2166 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
2170 static MODCMD_FUNC(cmd_stats_bad
) {
2172 unsigned int ii
, end
, here_len
;
2175 /* Show the bad word list.. */
2176 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
2177 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
2178 here_len
= strlen(opserv_bad_words
->list
[ii
]);
2179 /* If the line is full output it & start again */
2180 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2182 reply("OSMSG_BADWORD_LIST", buffer
);
2185 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
2187 buffer
[end
++] = ' ';
2190 reply("OSMSG_BADWORD_LIST", buffer
);
2192 /* Show the exemption list.. */
2193 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
2194 here_len
= strlen(iter_key(it
));
2195 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2197 reply("OSMSG_EXEMPTED_LIST", buffer
);
2200 memcpy(buffer
+end
, iter_key(it
), here_len
);
2202 buffer
[end
++] = ' ';
2205 reply("OSMSG_EXEMPTED_LIST", buffer
);
2209 static MODCMD_FUNC(cmd_stats_glines
) {
2210 reply("OSMSG_GLINE_COUNT", gline_count());
2214 static MODCMD_FUNC(cmd_stats_shuns
) {
2215 reply("OSMSG_SHUN_COUNT", shun_count());
2220 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
2221 unsigned int nn
, pos
;
2224 for (nn
=1; nn
<=depth
; nn
<<=1) ;
2225 for (pos
=0, nn
>>=1; nn
>1; ) {
2227 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
2228 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
2231 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
2232 if (!server
->children
.used
)
2234 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
2235 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
2237 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
2240 static MODCMD_FUNC(cmd_stats_links
) {
2241 trace_links(cmd
->parent
->bot
, user
, self
, 1);
2246 static MODCMD_FUNC(cmd_stats_max
) {
2247 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
2251 static MODCMD_FUNC(cmd_stats_network
) {
2252 struct helpfile_table tbl
;
2253 unsigned int nn
, tot_clients
;
2256 tot_clients
= dict_size(clients
);
2257 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
2258 tbl
.length
= dict_size(servers
)+1;
2260 tbl
.flags
= TABLE_NO_FREE
;
2261 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2262 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2263 tbl
.contents
[0][0] = "Server Name";
2264 tbl
.contents
[0][1] = "Clients";
2265 tbl
.contents
[0][2] = "Load";
2266 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2267 struct server
*server
= iter_data(it
);
2268 char *buffer
= malloc(32);
2269 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2270 tbl
.contents
[nn
][0] = server
->name
;
2271 tbl
.contents
[nn
][1] = buffer
;
2272 sprintf(buffer
, "%u", server
->clients
);
2273 tbl
.contents
[nn
][2] = buffer
+ 16;
2274 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
2277 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2278 for (nn
=1; nn
<tbl
.length
; nn
++) {
2279 free((char*)tbl
.contents
[nn
][1]);
2280 free(tbl
.contents
[nn
]);
2282 free(tbl
.contents
[0]);
2287 static MODCMD_FUNC(cmd_stats_network2
) {
2288 struct helpfile_table tbl
;
2292 tbl
.length
= dict_size(servers
)+1;
2294 tbl
.flags
= TABLE_NO_FREE
;
2295 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2296 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2297 tbl
.contents
[0][0] = "Server Name";
2298 tbl
.contents
[0][1] = "Numeric";
2299 tbl
.contents
[0][2] = "Link Time";
2300 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2301 struct server
*server
= iter_data(it
);
2302 char *buffer
= malloc(64);
2305 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2306 tbl
.contents
[nn
][0] = server
->name
;
2307 #ifdef WITH_PROTOCOL_P10
2308 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
2312 tbl
.contents
[nn
][1] = buffer
;
2313 ofs
= strlen(buffer
) + 1;
2314 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
2315 if (server
->self_burst
)
2316 strcat(buffer
+ ofs
, " Bursting");
2317 tbl
.contents
[nn
][2] = buffer
+ ofs
;
2320 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2321 for (nn
=1; nn
<tbl
.length
; nn
++) {
2322 free((char*)tbl
.contents
[nn
][1]);
2323 free(tbl
.contents
[nn
]);
2325 free(tbl
.contents
[0]);
2330 static MODCMD_FUNC(cmd_stats_reserved
) {
2333 reply("OSMSG_RESERVED_LIST");
2334 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
2335 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
2339 static MODCMD_FUNC(cmd_stats_trusted
) {
2341 struct trusted_host
*th
;
2342 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
2344 reply("OSMSG_TRUSTED_LIST");
2345 reply("OSMSG_TRUSTED_LIST_BAR");
2346 reply("OSMSG_TRUSTED_LIST_HEADER");
2347 reply("OSMSG_TRUSTED_LIST_BAR");
2349 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2352 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2354 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2356 sprintf(limit
, "%lu", th
->limit
);
2357 reply("OSMSG_HOST_IS_TRUSTED",
2359 (th
->limit
? limit
: "none"),
2360 (th
->issuer
? th
->issuer
: "<unknown>"),
2361 (th
->issued
? issued
: "some time"),
2362 (th
->expires
? length
: "never"));
2363 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2365 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
2368 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2371 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2373 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2375 sprintf(limit
, "%lu", th
->limit
);
2376 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
2377 (th
->limit
? limit
: "none"),
2378 (th
->issuer
? th
->issuer
: "<unknown>"),
2379 (th
->issued
? issued
: "some time"),
2380 (th
->expires
? length
: "never"));
2381 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2384 reply("OSMSG_TRUSTED_LIST_END");
2388 static MODCMD_FUNC(cmd_stats_uplink
) {
2389 extern struct cManagerNode cManager
;
2390 struct uplinkNode
*uplink
;
2392 uplink
= cManager
.uplink
;
2393 reply("OSMSG_UPLINK_START", uplink
->name
);
2394 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
2398 static MODCMD_FUNC(cmd_stats_uptime
) {
2399 char uptime
[INTERVALLEN
];
2401 extern time_t boot_time
;
2402 extern int lines_processed
;
2403 static long clocks_per_sec
;
2405 if (!clocks_per_sec
) {
2406 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
2407 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
2408 if (clocks_per_sec
<= 0)
2411 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
2412 clocks_per_sec
= CLOCKS_PER_SEC
;
2415 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
2417 reply("OSMSG_UPTIME_STATS",
2418 uptime
, lines_processed
,
2419 buf
.tms_utime
/(double)clocks_per_sec
,
2420 buf
.tms_stime
/(double)clocks_per_sec
);
2424 static MODCMD_FUNC(cmd_stats_alerts
) {
2426 struct opserv_user_alert
*alert
;
2427 const char *reaction
;
2428 char t_buffer
[INTERVALLEN
];
2432 m
= unsplit_string(argv
+ 1, argc
- 1, NULL
);
2433 reply("OSMSG_ALERTS_LIST", m
? m
: "*");
2434 reply("OSMSG_ALERTS_BAR");
2435 reply("OSMSG_ALERTS_HEADER");
2436 reply("OSMSG_ALERTS_BAR");
2437 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2438 alert
= iter_data(it
);
2439 if(m
&& (!match_ircglob(alert
->text_discrim
, m
) && strcasecmp(alert
->owner
, m
) && strcasecmp(iter_key(it
), m
)))
2440 continue; /* not a match to requested filter */
2441 switch (alert
->reaction
) {
2442 case REACT_NOTICE
: reaction
= "notice"; break;
2443 case REACT_KILL
: reaction
= "kill"; break;
2444 // case REACT_SILENT: reaction = "silent"; break;
2445 case REACT_GLINE
: reaction
= "gline"; break;
2446 case REACT_TRACK
: reaction
= "track"; break;
2447 case REACT_SHUN
: reaction
= "shun"; break;
2448 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
2449 case REACT_SVSPART
: reaction
= "svspart"; break;
2450 case REACT_VERSION
: reaction
= "version"; break;
2451 case REACT_MARK
: reaction
= "mark"; break;
2452 default: reaction
= "<unknown>"; break;
2454 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
2455 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
2456 if (alert
->last
> 0)
2457 reply("OSMSG_ALERTS_LAST", intervalString(t_buffer
, now
- alert
->last
, user
->handle_info
));
2459 reply("OSMSG_ALERTS_LAST", "Never");
2461 reply("OSMSG_ALERT_END");
2465 static MODCMD_FUNC(cmd_stats_gags
) {
2466 struct gag_entry
*gag
;
2467 struct helpfile_table table
;
2471 reply("OSMSG_NO_GAGS");
2474 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
2475 table
.length
= nn
+1;
2477 table
.flags
= TABLE_NO_FREE
;
2478 table
.contents
= calloc(table
.length
, sizeof(char**));
2479 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
2480 table
.contents
[0][0] = "Mask";
2481 table
.contents
[0][1] = "Owner";
2482 table
.contents
[0][2] = "Expires";
2483 table
.contents
[0][3] = "Reason";
2484 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
2485 char expstr
[INTERVALLEN
];
2487 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
2489 strcpy(expstr
, "Never");
2490 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
2491 table
.contents
[nn
][0] = gag
->mask
;
2492 table
.contents
[nn
][1] = gag
->owner
;
2493 table
.contents
[nn
][2] = strdup(expstr
);
2494 table
.contents
[nn
][3] = gag
->reason
;
2496 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
2497 for (nn
=1; nn
<table
.length
; nn
++) {
2498 free((char*)table
.contents
[nn
][2]);
2499 free(table
.contents
[nn
]);
2501 free(table
.contents
[0]);
2502 free(table
.contents
);
2506 static MODCMD_FUNC(cmd_stats_timeq
) {
2507 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
2512 static MODCMD_FUNC(cmd_stats_warn) {
2515 reply("OSMSG_WARN_LISTSTART");
2516 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
2517 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
2518 reply("OSMSG_WARN_LISTEND");
2523 #if defined(WITH_MALLOC_X3)
2524 static MODCMD_FUNC(cmd_stats_memory
) {
2525 extern unsigned long alloc_count
, alloc_size
;
2526 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2527 "%u allocations totalling %u bytes.",
2528 alloc_count
, alloc_size
);
2531 #elif defined(WITH_MALLOC_SLAB)
2532 static MODCMD_FUNC(cmd_stats_memory
) {
2533 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
2534 extern unsigned long big_alloc_count
, big_alloc_size
;
2535 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2536 "%u allocations in %u slabs totalling %u bytes.",
2537 slab_alloc_count
, slab_count
, slab_alloc_size
);
2538 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2539 "%u big allocations totalling %u bytes.",
2540 big_alloc_count
, big_alloc_size
);
2545 static MODCMD_FUNC(cmd_dump
)
2547 char linedup
[MAXLEN
], original
[MAXLEN
];
2549 unsplit_string(argv
+1, argc
-1, original
);
2550 safestrncpy(linedup
, original
, sizeof(linedup
));
2551 /* assume it's only valid IRC if we can parse it */
2552 if (parse_line(linedup
, 1)) {
2554 reply("OSMSG_LINE_DUMPED");
2556 reply("OSMSG_RAW_PARSE_ERROR");
2560 static MODCMD_FUNC(cmd_raw
)
2562 char linedup
[MAXLEN
], original
[MAXLEN
];
2564 unsplit_string(argv
+1, argc
-1, original
);
2565 safestrncpy(linedup
, original
, sizeof(linedup
));
2566 /* Try to parse the line before sending it; if it's too wrong,
2567 * maybe it will core us instead of our uplink. */
2568 parse_line(linedup
, 1);
2570 reply("OSMSG_LINE_DUMPED");
2574 static struct userNode
*
2575 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
2577 struct userNode
*resv
= GetUserH(nick
);
2579 if (IsService(resv
)) {
2580 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
2583 if (resv
->handle_info
2584 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
2585 reply("OSMSG_LEVEL_TOO_LOW");
2589 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
2590 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
2595 static MODCMD_FUNC(cmd_collide
)
2597 struct userNode
*resv
;
2599 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2601 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
2604 reply("OSMSG_CLONE_FAILED", argv
[1]);
2609 static MODCMD_FUNC(cmd_reserve
)
2611 struct userNode
*resv
;
2613 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2615 resv
->modes
|= FLAGS_PERSISTENT
;
2616 reply("OSMSG_RESERVED_NICK", resv
->nick
);
2619 reply("OSMSG_CLONE_FAILED", argv
[1]);
2625 free_reserve(char *nick
)
2627 struct userNode
*resv
;
2631 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
2635 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
2636 reason
= alloca(rlen
);
2637 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
2638 DelUser(resv
, NULL
, 1, reason
);
2639 dict_remove(opserv_reserved_nick_dict
, nick
);
2643 static MODCMD_FUNC(cmd_unreserve
)
2645 if (free_reserve(argv
[1]))
2646 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
2648 reply("OSMSG_NOT_RESERVED", argv
[1]);
2653 opserv_part_channel(void *data
)
2655 DelChannelUser(opserv
, data
, "Leaving.", 0);
2658 static int alert_check_user(const char *key
, void *data
, void *extra
);
2661 opserv_new_user_check(struct userNode
*user
)
2663 struct opserv_hostinfo
*ohi
;
2664 struct gag_entry
*gag
;
2665 char addr
[IRC_NTOP_MAX_SIZE
];
2667 /* Check to see if we should ignore them entirely. */
2668 if (IsLocal(user
) || IsService(user
))
2671 /* Check for alerts, and stop if we find one that kills them. */
2672 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
2675 /* Gag them if appropriate. */
2676 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2677 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
2678 gag_helper_func(user
, NULL
);
2683 /* Add to host info struct */
2684 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2685 if (!(ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2686 ohi
= calloc(1, sizeof(*ohi
));
2687 dict_insert(opserv_hostinfo_dict
, strdup(addr
), ohi
);
2688 userList_init(&ohi
->clients
);
2690 userList_append(&ohi
->clients
, user
);
2692 /* Only warn of new user floods outside of bursts. */
2693 if (!user
->uplink
->burst
) {
2694 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
2695 if (!new_user_flood
) {
2697 opserv_alert("Warning: Possible new-user flood.");
2704 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
)) {
2705 DelUser(user
, opserv
, 1, DefConGlineReason
);
2709 if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS
)) && !IsOper(user
)) {
2710 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2712 strcpy(target
+ 2, user
->hostname
);
2713 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
2714 gline_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1, 0);
2715 else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
2716 shun_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1);
2721 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
2722 if (opserv_conf
.untrusted_max
2723 && irc_in_addr_is_valid(user
->ip
)
2724 && !irc_in_addr_is_loopback(user
->ip
)) {
2725 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, addr
, NULL
);
2726 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
2728 if (checkDefCon(DEFCON_REDUCE_SESSION
) && !th
)
2729 limit
= DefConSessionLimit
;
2732 /* 0 means unlimited hosts */
2733 } else if (ohi
->clients
.used
== limit
) {
2735 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
2736 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
2737 } else if (ohi
->clients
.used
> limit
) {
2738 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2739 strcpy(target
+ 2, addr
);
2740 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "Excessive connections from a single host.", now
, 1, 1);
2748 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
2750 struct opserv_hostinfo
*ohi
;
2751 char addr
[IRC_NTOP_MAX_SIZE
];
2753 if (IsLocal(user
)) {
2754 /* Try to remove it from the reserved nick dict without
2755 * calling free_reserve, because that would call DelUser(),
2756 * and we'd loop back to here. */
2757 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
2760 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2761 if ((ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2762 userList_remove(&ohi
->clients
, user
);
2763 if (ohi
->clients
.used
== 0)
2764 dict_remove(opserv_hostinfo_dict
, addr
);
2769 opserv_bad_channel(const char *name
)
2774 dict_find(opserv_exempt_channels
, name
, &present
);
2778 if (gline_find(name
))
2781 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
2782 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
2789 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
2791 struct mod_chanmode
*change
;
2794 change
= mod_chanmode_alloc(2);
2795 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2796 change
->args
[0].mode
= MODE_CHANOP
;
2797 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2798 change
->args
[1].mode
= MODE_BAN
;
2799 change
->args
[1].u
.hostmask
= "*!*@*";
2800 mod_chanmode_announce(opserv
, channel
, change
);
2801 mod_chanmode_free(change
);
2802 for (nn
=channel
->members
.used
; nn
>0; ) {
2803 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2804 if (IsService(mNode
->user
))
2806 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2808 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2812 opserv_channel_check(struct chanNode
*newchan
)
2816 if (!newchan
->join_policer
.params
) {
2817 newchan
->join_policer
.last_req
= now
;
2818 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2821 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2822 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning);
2826 /* Wait until the join check to shut channels down. */
2827 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2831 opserv_channel_delete(struct chanNode
*chan
)
2833 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2837 opserv_notice_handler(struct userNode
*user
, struct userNode
*bot
, char *text
, UNUSED_ARG(int server_qualified
))
2840 /* if its a version reply, do an alert check (only alerts with version=something) */
2842 if(text
[0] == '\001') {
2844 cmd
= mysep(&text
, " ");
2845 if(cmd
&& !irccasecmp(cmd
, "VERSION")) {
2846 char *version
= mysep(&text
, "\n");
2849 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
2850 /* user->version_reply = strdup(version); done in parse-p10.c now */
2851 dict_foreach(opserv_user_alerts
, alert_check_user
, user
);
2858 opserv_join_check(struct modeNode
*mNode
)
2860 struct userNode
*user
= mNode
->user
;
2861 struct chanNode
*channel
= mNode
->channel
;
2864 if (IsService(user
))
2867 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2869 if (channel
->bad_channel
) {
2870 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2871 if (channel
->name
[0] != '#')
2872 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2873 else if (!GetUserMode(channel
, opserv
))
2874 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2876 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2877 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2878 KickChannelUser(user
, channel
, opserv
, msg
);
2883 if (user
->uplink
->burst
)
2885 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2886 channel
->join_flooded
= 0;
2889 if (!channel
->join_flooded
) {
2890 /* Don't moderate the channel unless it is activated and
2891 the number of users in the channel is over the threshold. */
2892 struct mod_chanmode change
;
2893 mod_chanmode_init(&change
);
2894 channel
->join_flooded
= 1;
2895 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2896 if (!GetUserMode(channel
, opserv
)) {
2897 /* If we aren't in the channel, join it. */
2898 change
.args
[0].mode
= MODE_CHANOP
;
2899 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2902 if (!(channel
->modes
& MODE_MODERATED
))
2903 change
.modes_set
|= MODE_MODERATED
;
2904 if (change
.modes_set
|| change
.argc
)
2905 mod_chanmode_announce(opserv
, channel
, &change
);
2906 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2907 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2909 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2912 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2917 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2918 unsigned int bad_idx
;
2920 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2921 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2922 if (irccasestr(new_bad
, orig_bad
)) {
2924 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2926 } else if (irccasestr(orig_bad
, new_bad
)) {
2928 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2930 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2931 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2932 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2933 if (!irccasestr(orig_bad
, new_bad
))
2936 reply("OSMSG_BAD_NUKING", orig_bad
);
2937 string_list_delete(opserv_bad_words
, bad_idx
);
2944 string_list_append(opserv_bad_words
, strdup(new_bad
));
2946 reply("OSMSG_ADDED_BAD", new_bad
);
2951 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
)
2953 struct routingPlanServer
*rps
;
2954 rps
= calloc(1, sizeof(*rps
));
2957 /* duplicate servers replace */
2958 rps
->uplink
= strdup(uplink
);
2960 rps
->secondaryuplink
= strdup(second
);
2962 rps
->secondaryuplink
= NULL
;
2963 rps
->port
= port
? port
: 4400; /* lame hardcodede default port. maybe get from config file somewhere? */
2965 rps
->offline
= offline
; /* 1 = yes, 0 = no */
2966 dict_insert(rp
->servers
, strdup(name
), rps
);
2967 log_module(OS_LOG
, LOG_DEBUG
, "Adding rp server %s with uplink %s", name
, uplink
);
2972 free_routing_plan_server(void *data
)
2974 struct routingPlanServer
*rps
= data
;
2976 if(rps
->secondaryuplink
)
2977 free(rps
->secondaryuplink
);
2982 opserv_add_routing_plan(const char *name
)
2984 struct routingPlan
*rp
;
2985 rp
= calloc(1, sizeof(*rp
));
2988 if(dict_find(opserv_routing_plans
, name
, NULL
))
2989 return NULL
; /* plan already exists */
2990 rp
->servers
= dict_new();
2991 dict_set_free_data(rp
->servers
, free_routing_plan_server
);
2993 dict_insert(opserv_routing_plans
, strdup(name
), rp
);
2994 /* TODO: check for duplicate */
2999 free_routing_plan(void *data
)
3001 struct routingPlan
*rp
= data
;
3002 /* delete all the servers attached to this plan */
3003 dict_delete(rp
->servers
);
3004 /* free the plan struct */
3008 /*************************************************
3009 * Functions to handle the active routing struct */
3012 *find_routeList_server(struct route
*route
, const char *server
)
3014 struct routeList
*rptr
;
3017 for(rptr
= route
->servers
;rptr
;rptr
=rptr
->next
) {
3018 if(!strcasecmp(rptr
->server
, server
))
3024 /* Wipes out the routing structure, freeing properly.
3025 * note: does NOT free itself, we just re-use it usually.*/
3027 wipe_route_list(struct route
*route
) {
3028 struct routeList
*nextptr
, *rptr
;
3031 for(rptr
= opserv_route
->servers
; rptr
; rptr
=nextptr
)
3033 nextptr
= rptr
->next
;
3037 if(rptr
->secondaryuplink
)
3038 free(rptr
->secondaryuplink
);
3041 route
->centered
= true;
3043 route
->maxdepth
= 0;
3044 route
->servers
= NULL
;
3049 rank_outside_rec(struct route
*route
, char *server
, int count
)
3051 struct routeList
*rptr
;
3054 if(count
> 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */
3057 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3059 if(!strcasecmp(server
, rptr
->uplink
)) {
3060 log_module(MAIN_LOG
, LOG_DEBUG
, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count
, i
, rptr
->server
, rptr
->uplink
);
3061 n
= rank_outside_rec(route
, rptr
->server
, count
+1);
3062 if(n
< 0) /* handle error condition */
3068 if((rptr
= find_routeList_server(route
, server
))) {
3069 rptr
->outsideness
= max
;
3073 log_module(MAIN_LOG
, LOG_WARNING
, "routing struct rank_outsideness() couldnt find %s", server
);
3079 rank_outsideness(struct route
*route
)
3081 log_module(MAIN_LOG
, LOG_DEBUG
, "rank_outsideness(): Running...");
3082 route
->maxdepth
= rank_outside_rec(route
, self
->uplink
->name
, 0) - 1;
3083 if(route
->maxdepth
< 0) { /* if the rank failed, remove route */
3084 log_module(MAIN_LOG
, LOG_WARNING
, "The active routing plan has a loop! auto routing disabled.");
3085 wipe_route_list(route
);
3092 /* Add servers to the routing structure */
3094 add_routestruct_server(struct route
*route
, const char *server
, unsigned int port
, char *uplink
, char *secondary
)
3096 struct routeList
*rptr
;
3098 if(find_routeList_server(route
, server
))
3100 log_module(MAIN_LOG
, LOG_WARNING
, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server
);
3103 rptr
= calloc(1, sizeof(*rptr
));
3104 rptr
->server
= strdup(server
);
3107 hname
= conf_get_data("server/hostname", RECDB_QSTRING
);
3110 rptr
->uplink
= strdup(uplink
);
3112 rptr
->secondaryuplink
= strdup(secondary
);
3113 /* tack this server on the front of the list */
3114 rptr
->next
= route
->servers
;
3115 route
->servers
= rptr
;
3118 #ifdef notdef /* I dont quite get this. there could be uncentered things
3119 * added after our own uplink, and this function doesnt center
3120 * as it adds. -Rubin */
3121 /* If the map hasnt been centered yet... */
3122 if(route
->centered
== false) {
3123 /* AND we just added our own uplink to it... */
3124 if(!strcasecmp(server
, self
->uplink
->name
)) {
3125 change_route_uplinks(route
); /* recenter it, n mark it centered. */
3131 /* Recenter the routing struct around our current uplink */
3133 change_route_uplinks(struct route
*route
)
3135 struct routeList
*rptr
;
3136 char lastserver
[MAXLEN
];
3137 char nextserver
[MAXLEN
];
3140 return false; /* no map to recenter */
3141 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks(): running...");
3142 char *servicename
= conf_get_data("server/hostname", RECDB_QSTRING
);
3143 strcpy(lastserver
, servicename
);
3144 rptr
= find_routeList_server(route
, self
->uplink
->name
);
3146 log_module(MAIN_LOG
, LOG_WARNING
, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered.");
3147 route
->centered
= false;
3150 if(!strcasecmp(rptr
->uplink
, servicename
)) {
3151 log_module(MAIN_LOG
, LOG_DEBUG
, "Already centered");
3153 else { /* else, center it */
3155 strcpy(nextserver
, rptr
->uplink
);
3156 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks() changing %s uplink to %s.", rptr
->server
, lastserver
);
3158 rptr
->uplink
= strdup(lastserver
);
3159 strcpy(lastserver
, rptr
->server
);
3160 rptr
= find_routeList_server(route
, nextserver
);
3163 if(rank_outsideness(route
) > 0) {
3164 route
->centered
= true;
3172 activate_routing(struct svccmd
*cmd
, struct userNode
*user
, char *plan_name
)
3174 static struct routingPlan
*rp
;
3178 if(plan_name
) { /* make this the new active plan */
3179 if(!strcmp(plan_name
, "*")) {
3180 /* disable routing */
3181 dict_remove(opserv_routing_plan_options
, "ACTIVE");
3185 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3188 reply("OSMSG_PLAN_NOT_FOUND", plan_name
);
3190 /* since it doesnt exist, remove the active setting */
3191 dict_remove(opserv_routing_plan_options
, plan_name
);
3193 log_module(MAIN_LOG
, LOG_WARNING
, "activate_routing() couldnt find active routing plan!");
3198 else { /* find the active plan in settings */
3199 plan_name
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3201 if(!plan_name
) { /* deactivated, or no plan was set active */
3202 /* TODO: delete routing map if it exists */
3203 wipe_route_list(opserv_route
);
3207 karma
= dict_find(opserv_routing_plan_options
, "KARMA", NULL
);
3209 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3211 /* this should really be done during opserv init */
3213 opserv_route
= calloc(1, sizeof(*opserv_route
));
3215 /* Delete the existing active route */
3216 wipe_route_list(opserv_route
);
3218 if(!rp
|| !rp
->servers
)
3220 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3221 const char* servername
= iter_key(it
);
3222 struct routingPlanServer
*rps
= iter_data(it
),
3223 *rp_uplink
, *rp_second
= NULL
;
3224 char *uplink
= rps
->uplink
;
3225 rp_uplink
= dict_find(rp
->servers
, rps
->uplink
, NULL
);
3226 if(rps
->secondaryuplink
)
3227 rp_second
= dict_find(rp
->servers
, rps
->secondaryuplink
, NULL
);
3229 /* If the normal uplink has bad karma, don't use it as a hub,
3230 * switch to the secondary uplink.
3232 if(karma
&& enabled_string(karma
) && rp_uplink
&& rp_uplink
->karma
< 0) {
3233 if(rps
->secondaryuplink
) {
3234 uplink
= rps
->secondaryuplink
;
3235 /* unless the secondary uplinks karma is worse than the uplink. */
3236 if((rp_second
= dict_find(rp
->servers
, uplink
, NULL
)) && rp_second
->karma
< rp_uplink
->karma
)
3237 uplink
= rps
->uplink
;
3241 * If _WE_ have bad karma, don't link us to our normal uplink, maybe
3242 * its a bad route. switch to secondary. Important: dont neg karma when we arnt on
3243 * our primary uplink, or we'll get stuck on secondary when THAT link is worse.
3245 if(karma
&& enabled_string(karma
) && (rps
->karma
< 0 || rps
->offline
) ) {
3246 if(rps
->secondaryuplink
) {
3247 uplink
= rps
->secondaryuplink
;
3250 log_module(MAIN_LOG
, LOG_DEBUG
, "activate_routing() adding %s:%d %s", servername
, rps
->port
, uplink
);
3251 add_routestruct_server(opserv_route
, servername
, rps
->port
, uplink
, NULL
);
3253 if(change_route_uplinks(opserv_route
))
3258 reply("OSMSG_ROUTING_ACTIVATION_ERROR");
3259 activate_routing(cmd
, user
, "*");
3262 /* routing activation failed but we dont do anything? */
3269 activate_routing(NULL
, NULL
, NULL
);
3271 /* start auto-routing system */
3272 reroute_timer_reset(0);
3275 /*******************************************************
3276 * Functions to handle online route configuration via opserv
3278 static void route_show_option(struct svccmd
*cmd
, struct userNode
*user
, char *name
)
3280 char *value
= dict_find(opserv_routing_plan_options
, name
, NULL
);
3282 if(!strcmp("RETRY_PERIOD", name
)) { /* Show as an interval */
3283 char buff
[INTERVALLEN
+1];
3284 reply("OSMSG_ROUTINGPLAN_OPTION", name
, intervalString(buff
, atoi(value
), user
->handle_info
));
3286 else if(!strcmp("ACTIVE", name
)) {
3287 if(opserv_route
&& opserv_route
->servers
)
3288 reply("OSMSG_ROUTINGPLAN_ACTIVE", value
);
3290 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3293 reply("OSMSG_ROUTINGPLAN_OPTION", name
, value
);
3297 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3301 static void route_show_options(struct svccmd
*cmd
, struct userNode
*user
)
3303 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3305 for(i
= 0; options
[i
]; i
++) {
3306 route_show_option(cmd
, user
, options
[i
]);
3310 /* called from timeq */
3311 void routing_connect_timeout(void *data
)
3313 struct waitingConnection
*wc
= data
;
3314 struct server
*target
= GetServerH(wc
->target
);
3316 dict_remove(opserv_waiting_connections
, wc
->server
);
3317 return; /* server we wanted to connect new server to is gone, just give up */
3319 routing_handle_connect_failure(target
, wc
->server
, "Connection timed out");
3320 /* the following invalidates server variable! */
3321 dict_remove(opserv_waiting_connections
, wc
->server
);
3324 void routing_delete_connect_timer(char *server
)
3326 struct waitingConnection
*wc
= dict_find(opserv_waiting_connections
, server
, 0);
3328 timeq_del(0, routing_connect_timeout
, wc
, TIMEQ_IGNORE_WHEN
);
3329 dict_remove(opserv_waiting_connections
, server
);
3335 routing_connect_server(char *server
, int port
, struct server
*to
)
3337 struct waitingConnection
*wc
= calloc(sizeof(*wc
), 1);
3339 wc
->server
= strdup(server
);
3340 wc
->target
= strdup(to
->name
);
3341 /* Just to make sure there isn't one left hanging
3342 * if 2 connections are attempted at once..
3344 routing_delete_connect_timer(server
);
3345 dict_insert(opserv_waiting_connections
, strdup(server
), wc
);
3346 timeq_add(now
+ ROUTING_CONNECT_TIMEOUT
, routing_connect_timeout
, wc
);
3348 irc_connect(opserv
, server
, port
, to
);
3352 routing_connect_one(struct route
*route
, char *server
)
3354 struct routeList
*rptr
;
3355 struct server
*sptr
, *suptr
;
3356 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3357 if(!strcasecmp(rptr
->server
, server
)) {
3358 /* this is the one, connect it */
3359 suptr
= GetServerH(rptr
->uplink
);
3360 sptr
= GetServerH(rptr
->server
);
3362 return 1; /* already linked */
3364 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3365 return 1; /* attempted link */
3367 return 0; /* its uplink isnt here to link to */
3370 log_module(MAIN_LOG
, LOG_DEBUG
, "Tried to link %s but its not in the active routing struct!", server
);
3371 return 0; /* server wasnt found in active route struct. */
3374 int routing_connect_children(struct route
*route
, char *server
)
3376 struct routeList
*rptr
;
3377 struct server
*sptr
, *suptr
;
3378 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3379 if(!strcasecmp(rptr
->uplink
, server
)) {
3380 /* this is the one, connect it */
3381 suptr
= GetServerH(rptr
->uplink
);
3382 sptr
= GetServerH(rptr
->server
);
3384 continue; /* already linked */
3386 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3387 continue; /* attempted link */
3389 continue; /* its uplink isnt here to link to */
3392 return 1; /* server wasnt found in active route struct ?! */
3395 int reroute(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
, char *directive
)
3397 struct routeList
*rptr
;
3398 struct server
*sptr
, *suptr
;
3399 int connect
= 0, move
= 0, missing
= 0, i
;
3400 char d
= toupper(*directive
);
3402 if(!route
|| !route
->servers
) {
3403 reply("OSMSG_REROUTING_NOTCONFIGURED");
3407 if(d
== 'N') { /* normal */
3408 irc_wallops("%s", "Attempting a reroute of the network according to loaded map...");
3409 reply("OSMSG_REROUTING_ACC_MAP");
3411 else if(d
== 'C') { /* only connect */
3412 reply("OSMSG_CONNECTING_MISSING_ONLY");
3414 else if(d
== 'T') { /* test */
3415 reply("OSMSG_TESTING_REROUTE");
3419 reply("OSMSG_INVALID_DIRECTIVE", directive
);
3423 for(i
= 0; i
<= route
->maxdepth
-1; i
++) {
3424 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3425 if(rptr
->outsideness
== i
) {
3428 reply("OSMSG_INSPECTING_SERVER", rptr
->server
);
3429 suptr
= GetServerH(rptr
->uplink
);
3431 if(rptr
->secondaryuplink
&& (suptr
= GetServerH(rptr
->secondaryuplink
))) {
3433 reply("OSMSG_COULDNT_FIND_SERVER", rptr
->uplink
, rptr
->secondaryuplink
, rptr
->server
);
3436 if(suptr
) { /* if the proper uplink is connected.. */
3437 sptr
= GetServerH(rptr
->server
);
3438 if(d
== 'C' && sptr
) {
3439 continue; /* Already linked */
3441 /* If server is missing or the uplinks are not the same then... */
3442 else if(!sptr
|| strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3446 else { /* Server is already connected somewhere */
3447 if(strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3448 if(d
!= 'T') { /* do it for real */
3449 irc_squit_route(sptr
, "%s issued reroute.", user
? user
->nick
: opserv
->nick
);
3451 else { /* just pretend */
3452 reply("OSMSG_SQUIT", rptr
->server
);
3457 if(d
!= 'T') /* do the real thing */
3458 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3459 else /* just pretend */
3460 reply("OSMSG_CONNECT", rptr
->server
, rptr
->port
, suptr
->name
);
3464 log_module(MAIN_LOG
, LOG_DEBUG
, "server uplink %s was not found, cant connect %s", rptr
->uplink
, rptr
->server
);
3467 } /* outsideness = 1 */
3470 if(user
) { /* report on what we did */
3471 if(!strcasecmp(directive
, "C")) {
3473 reply("OSMSG_CONNECTING_MISSING", connect
);
3475 reply("OSMSG_NO_SERVERS_MISSING");
3478 if(move
+connect
> 0)
3479 reply("OSMSG_REROUTE_COMPLETE", move
, connect
, move
+connect
);
3481 reply("OSMSG_NO_ROUTING_NECESSARY");
3483 reply("OSMSG_UPLINKS_MISSING", missing
);
3486 return(move
+connect
);
3489 static MODCMD_FUNC(cmd_reroute
) {
3492 if(reroute(opserv_route
, user
, cmd
, upper
))
3498 /* reroute_timer(run)
3499 * run - if it is null, just setup the timer
3500 * but dont run reroute now. otherwise reroute
3503 void reroute_timer(void *data
) {
3504 /* Delete any other timers such as this one.. */
3505 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3507 if(!opserv_route
|| !opserv_route
->servers
)
3508 return; /* no active route */
3509 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3511 return; /* retry_period invalid */
3512 unsigned int freq
= atoi(retry_period
);
3514 return; /* retry_period set to 0, disable */
3516 /* opserv_debug("Reroute timer checking reroute"); */
3517 log_module(MAIN_LOG
, LOG_DEBUG
, "Reroute timer checking reroute()");
3519 /* Do the reroute C attempt */
3521 reroute(opserv_route
, NULL
, NULL
, "C");
3523 /* Re-add ourselves to the timer queue */
3524 timeq_add(now
+ freq
, reroute_timer
, "run");
3527 void routing_change_karma(struct routingPlanServer
*rps
, const char *server
, int change
) {
3529 int oldkarma
= rps
->karma
;
3530 rps
->karma
+= change
;
3531 if(rps
->karma
< KARMA_MIN
)
3532 rps
->karma
= KARMA_MIN
;
3533 if(rps
->karma
> KARMA_MAX
)
3534 rps
->karma
= KARMA_MAX
;
3535 log_module(MAIN_LOG
, LOG_DEBUG
, "Changing %s karma by %d. new karma %d.", server
, change
, rps
->karma
);
3536 if(oldkarma
> 0 && rps
->karma
< 0) {
3537 /* we just crossed over to negitive */
3538 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went negitive karma!", server
);
3539 activate_routing(NULL
, NULL
, NULL
);
3541 else if(oldkarma
< 0 && rps
->karma
> 0) {
3542 /* we just crossed over to positive */
3543 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went back positive karma.", server
);
3544 activate_routing(NULL
, NULL
, NULL
);
3548 void routing_karma_timer(void *data
) {
3550 time_t timer_init
= data
? atoi(data
) : 0;
3553 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init
);
3555 /* If theres a time passed in, dont run unless that time is overdue. */
3556 if(!timer_init
|| (timer_init
< now
)) {
3557 if(opserv_route
&& opserv_route
->servers
) {
3558 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3559 struct routingPlan
*rp
;
3560 if(active
&& (rp
= dict_find(opserv_routing_plans
, active
, NULL
))) {
3562 /* Walk through each server in the active routing plan.. */
3563 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3564 struct routingPlanServer
*rps
= iter_data(it
);
3565 struct server
*server
= GetServerH(iter_key(it
));
3566 /* Give everyone +KARMA_ENTROPE just for nothing */
3567 routing_change_karma(rps
, iter_key(it
), KARMA_ENTROPE
);
3568 /* give an additonal +KARMA_RELIABLE to servers that
3569 * have been linked at least KARMA_TIMER seconds. */
3570 if(server
&& (server
->link
< (now
- KARMA_TIMER
) ) ) {
3571 routing_change_karma(rps
, iter_key(it
), KARMA_RELIABLE
);
3577 if(timer_init
> now
) /* loading a saved value */
3579 else /* no scheduled timer, or we missed it. start from now */
3580 next
= now
+ KARMA_TIMER
;
3581 /* Save when karma_timer should run again in case we restart before then */
3582 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next
);
3583 sprintf(buf
, "%u", (unsigned int) next
);
3584 dict_insert(opserv_routing_plan_options
, "KARMA_TIMER", strdup(buf
));
3585 /* add a timer to run this again .. */
3586 timeq_add(next
, routing_karma_timer
, NULL
);
3589 void routing_handle_neg_karma(char *server
, char *uplink
, int change
)
3591 /* if server's primary uplink is uplink, OR, uplink's primary uplink is server,
3592 * then whichever one, gets its karma changed. */
3593 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3594 struct routingPlan
*rp
;
3595 struct routingPlanServer
*rps
;
3598 if(!(rp
= dict_find(opserv_routing_plans
, active
, NULL
)))
3600 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3601 if(!strcasecmp(rps
->uplink
, uplink
)) {
3602 /* server's uplink is uplink */
3603 routing_change_karma(rps
, server
, change
);
3607 if((rps
= dict_find(rp
->servers
, uplink
, NULL
))) {
3608 if(!strcasecmp(rps
->uplink
, server
)) {
3609 /* uplink's uplink is server */
3610 routing_change_karma(rps
, uplink
, change
);
3617 routing_handle_squit(char *server
, char *uplink
, char *message
)
3619 log_module(MAIN_LOG
, LOG_DEBUG
, "Routing_handle_squit(%s, %s)", server
, message
);
3623 if(match_ircglob(message
, "Ping timeout")) {
3624 routing_handle_neg_karma(server
, uplink
, KARMA_PINGOUT
);
3625 /* if conn_pingout is true, try to reconnect it obaying karma rules. */
3627 val
= dict_find(opserv_routing_plan_options
, "CONN_PINGOUT", 0);
3628 if(val
&& enabled_string(val
))
3629 routing_connect_one(opserv_route
, server
);
3631 else if(match_ircglob(message
, "Read error:*")) {
3632 routing_handle_neg_karma(server
, uplink
, KARMA_READERROR
);
3633 /* if conn_readerror is true, try to reconnect it obaying karma rules. */
3634 val
= dict_find(opserv_routing_plan_options
, "CONN_READERROR", 0);
3635 if(val
&& enabled_string(val
))
3636 routing_connect_one(opserv_route
, server
);
3638 /* Else whats the message (an oper squit it?) dont interfere */
3642 routing_handle_connect(char *server
, char *uplink
)
3645 struct routingPlan
*rp
;
3646 struct routingPlanServer
*rps
;
3649 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect(%s, %s)", server
, uplink
);
3650 /* delete a pending connection timer, if any */
3651 routing_delete_connect_timer(server
);
3652 /* check if routing is active... */
3653 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3656 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3660 /* If its offline, mark it online again.. */
3661 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3662 if(rps
->offline
== true) {
3663 rps
->offline
= false;
3664 if(rps
->secondaryuplink
) {
3665 /* re-activate to move it back to its primary */
3666 activate_routing(NULL
, NULL
, NULL
);
3669 /* if there are any servers missing who have this server as uplink try to connect them. */
3670 routing_connect_children(opserv_route
, server
);
3672 /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */
3673 for (it
=dict_first(servers
); it
; it
=iter_next(it
)) {
3674 struct server
*sptr
= iter_data(it
);
3675 if(sptr
&& sptr
->uplink
&& !strcasecmp(server
, sptr
->uplink
->name
)) {
3676 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect calling self on %s's leaf %s", server
, sptr
->name
);
3677 routing_handle_connect(sptr
->name
, sptr
->uplink
->name
);
3682 /* Handle a failed attempt at connecting servers
3683 * - we should only get here regarding servers X3 attempted to link, other
3684 * opers link messages go to them not to us
3687 routing_handle_connect_failure(struct server
*source
, char *server
, char *message
)
3690 struct routingPlan
*rp
;
3691 struct routingPlanServer
*rps
;
3692 log_module(MAIN_LOG
, LOG_WARNING
, "Failed to connect %s to %s: %s", server
, source
->name
, message
);
3693 /* remove the waiting connection n timeq */
3694 routing_delete_connect_timer(server
);
3695 /* check if routing is active.. */
3696 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3699 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3703 if( ((rps
= dict_find(rp
->servers
, server
, NULL
)) && !strcasecmp(rps
->uplink
, source
->name
))) {
3704 /* failed to connect to its primary uplink */
3705 if(rps
->offline
== false) {
3706 rps
->offline
= true;
3707 if(rps
->secondaryuplink
) {
3708 /* re-activate routing so the secondary
3709 * becomes its uplink, and try again */
3710 activate_routing(NULL
, NULL
, NULL
);
3711 /* attempt to link it again. */
3712 routing_connect_one(opserv_route
, server
);
3713 /* TODO: reconnect any missing servers who
3714 * normally connect to server, using their backups.
3715 * Probably should just issue a reroute C here. */
3721 /* Delete any existing timers, and start the timer again
3722 * using the passed time for the first run.
3723 * - this is called during a retry_period change
3724 * before it has saved the new value.
3726 * If time is 0, lookup the interval. */
3727 void reroute_timer_reset(unsigned int time
)
3729 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3731 if(!opserv_route
|| !opserv_route
->servers
)
3732 return; /* no active route */
3733 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3735 return; /* retry_period invalid */
3736 time
= atoi(retry_period
);
3738 return; /* retry_period set to 0, disable */
3741 timeq_add(now
+ time
, reroute_timer
, "run");
3744 static MODCMD_FUNC(cmd_routing_set
)
3746 char *option
= argv
[1];
3747 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3750 route_show_options(cmd
, user
);
3753 char *found_option
= NULL
;
3754 for(i
= 0; options
[i
]; i
++) {
3755 if(!strcasecmp(options
[i
], option
))
3756 found_option
= options
[i
];
3759 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option
);
3763 char *value
= argv
[2];
3764 char buff
[MAXLEN
]; /* whats the max length of unsigned int as printf'd? */
3765 if(!strcmp(found_option
, "ACTIVE")) { /* must be an existing route. */
3766 if(disabled_string(value
) || false_string(value
)) {
3767 /* make none of the maps active */
3768 activate_routing(cmd
, user
, "*");
3769 reply("OSMSG_ROUTING_DISABLED");
3772 else if(!activate_routing(cmd
, user
, value
)) {
3773 /* neg reply handled in activate_routing */
3777 if(!strcmp(found_option
, "CONN_READERROR") || !strcmp(found_option
, "CONN_PINGOUT") ||
3778 !strcmp(found_option
, "KARMA") ) {
3779 if( enabled_string(value
)) {
3782 else if( disabled_string(value
) ) {
3786 reply("MSG_INVALID_BINARY", value
);
3790 if(!strcmp(found_option
, "RETRY_PERIOD")) {
3791 unsigned int duration
= ParseInterval(value
);
3792 sprintf(buff
, "%d", duration
);
3794 reroute_timer_reset(duration
);
3796 /* set the value here */
3797 dict_remove(opserv_routing_plan_options
, found_option
);
3798 dict_insert(opserv_routing_plan_options
, strdup(found_option
), strdup(value
));
3799 route_show_option(cmd
, user
, found_option
);
3802 /* show the current value */
3803 route_show_option(cmd
, user
, found_option
);
3809 static MODCMD_FUNC(cmd_stats_routing_plans
) {
3810 dict_iterator_t rpit
;
3812 struct routingPlan
*rp
;
3814 reply("OSMSG_ROUTINGPLAN");
3815 reply("OSMSG_ROUTINGPLAN_BAR");
3816 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3817 const char* name
= iter_key(rpit
);
3818 rp
= iter_data(rpit
);
3819 if(match_ircglob(name
, argv
[1])) {
3820 reply("OSMSG_ROUTINGPLAN_NAME", name
);
3821 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3822 const char* servername
= iter_key(it
);
3823 struct routingPlanServer
*rps
= iter_data(it
);
3824 reply("OSMSG_ROUTINGPLAN_SERVER", servername
, rps
->port
, rps
->uplink
, rps
->karma
, rps
->offline
? "offline" : "online", rps
->secondaryuplink
? rps
->secondaryuplink
: "None");
3829 reply("OSMSG_ROUTINGPLAN_END");
3832 reply("OSMSG_ROUTINGPLAN_LIST_HEAD");
3833 reply("OSMSG_ROUTINGPLAN_BAR");
3834 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3835 const char* name
= iter_key(rpit
);
3836 reply("OSMSG_ROUTINGPLAN_LIST", name
);
3838 reply("OSMSG_ROUTINGPLAN_END");
3839 route_show_options(cmd
, user
);
3845 static MODCMD_FUNC(cmd_routing_addplan
)
3849 /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */
3850 if(*name
&& !disabled_string(name
) && !false_string(name
)) {
3851 if(opserv_add_routing_plan(name
)) {
3852 reply("OSMSG_ADDPLAN_SUCCESS", name
);
3856 reply("OSMSG_ADDPLAN_FAILED", name
);
3862 reply("OSMSG_INVALID_PLAN");
3867 static MODCMD_FUNC(cmd_routing_delplan
)
3869 char *name
= argv
[1];
3870 if( dict_remove(opserv_routing_plans
, name
) ) {
3871 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3872 if(active
&& !strcasecmp(active
, name
)) {
3873 /* if this was the active plan, disable routing */
3874 activate_routing(cmd
, user
, "*");
3875 reply("OSMSG_ROUTING_DISABLED");
3877 reply("OSMSG_PLAN_DELETED");
3881 reply("OSMSG_PLAN_NOT_FOUND", name
);
3886 static MODCMD_FUNC(cmd_routing_addserver
)
3894 struct routingPlan
*rp
;
3897 server
= strdup(argv
[2]);
3898 server
= strtok(server
, ":");
3899 portstr
= strtok(NULL
, ":");
3901 port
= atoi(portstr
);
3903 char *str
= dict_find(opserv_routing_plan_options
, "DEFAULT_PORT", NULL
);
3905 port
= str
? atoi(str
) : 0;
3913 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3915 opserv_routing_plan_add_server(rp
, server
, uplink
, port
, KARMA_DEFAULT
, second
, 0);
3916 reply("OSMSG_PLAN_SERVER_ADDED", server
);
3917 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3918 /* re-activate routing with new info */
3919 activate_routing(cmd
, user
, NULL
);
3926 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3932 static MODCMD_FUNC(cmd_routing_delserver
)
3936 struct routingPlan
*rp
;
3939 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3940 if(dict_remove(rp
->servers
, server
)) {
3942 reply("OSMSG_PLAN_SERVER_DELETED");
3943 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3944 /* re-activate routing with new info */
3945 activate_routing(cmd
, user
, NULL
);
3951 reply("OSMSG_PLAN_SERVER_NOT_FOUND", server
);
3956 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3962 /*************************************************
3963 * Functions to deal with 'route map' command */
3965 /* Figures out how many downlinks there are for proper
3966 * drawing of the route map */
3968 num_route_downlinks(struct route
*route
, char *name
)
3970 struct routeList
*rptr
;
3972 rptr
= route
->servers
;
3974 if(!strcasecmp(rptr
->uplink
, name
))
3982 show_route_downlinks(struct svccmd
*cmd
, struct route
*route
, struct userNode
*user
, char *name
, char *prevpre
, char *arrowchar
, int reset
)
3984 struct routeList
*servPtr
;
3985 struct server
*sptr
;
3991 static int depth
= 0;
3996 nextpre
= malloc(MAXLEN
);
3997 strcpy(pre
, prevpre
);
3999 sptr
= GetServerH(name
);
4000 if((servPtr
= find_routeList_server(route
, name
))) {
4003 else if (!strcasecmp(sptr
->uplink
->name
, servPtr
->uplink
))
4005 else if(servPtr
->secondaryuplink
&& !strcasecmp(sptr
->name
, servPtr
->secondaryuplink
))
4009 reply("OSMSG_DOWNLINKS_FORMAT_A", pre
, arrowchar
, name
, status
);
4012 reply("OSMSG_DOWNLINKS_FORMAT_B", self
->name
);
4013 j
= num_route_downlinks(route
, name
);
4014 servPtr
= route
->servers
;
4016 if(!strcasecmp(servPtr
->uplink
, name
)) {
4017 strcpy(nextpre
, pre
);
4019 if(arrowchar
[0] == '`')
4020 strcat(nextpre
, " ");
4022 strcat(nextpre
, "| ");
4025 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "|", 0);
4028 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "`", 0);
4031 servPtr
= servPtr
->next
;
4037 show_route_map(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
)
4039 if(!route
|| !route
->servers
) {
4040 reply("OSMSG_ROUTELIST_EMPTY");
4044 char *serviceName
= conf_get_data("server/hostname", RECDB_QSTRING
);
4045 reply("OSMSG_ROUTELIST_AS_PLANNED");
4046 show_route_downlinks(cmd
, route
, user
, serviceName
, "", "`", 1);
4047 reply("OSMSG_MAP_CENTERED", route
->centered
? "is" : "is not", route
->maxdepth
);
4051 static MODCMD_FUNC(cmd_routing_map
)
4053 show_route_map(opserv_route
, user
, cmd
);
4060 /* End of auto routing functions *
4061 *********************************/
4063 static MODCMD_FUNC(cmd_addbad
)
4065 unsigned int arg
, count
;
4067 int bad_found
, exempt_found
;
4069 /* Create the bad word if it doesn't exist. */
4070 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
4072 /* Look for exception modifiers. */
4073 for (arg
=2; arg
<argc
; arg
++) {
4074 if (!irccasecmp(argv
[arg
], "except")) {
4075 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
4077 reply("MSG_MISSING_PARAMS", "except");
4080 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
4081 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
4082 if (!exempt_found
) {
4083 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
4087 reply("OSMSG_ADDED_EXEMPTIONS", count
);
4089 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
4090 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
4094 /* Scan for existing channels that match the new bad word. */
4096 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4097 struct chanNode
*channel
= iter_data(it
);
4099 if (!opserv_bad_channel(channel
->name
))
4101 channel
->bad_channel
= 1;
4102 if (channel
->name
[0] == '#')
4103 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
4106 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
4107 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
4108 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
4117 static MODCMD_FUNC(cmd_delbad
)
4122 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
4123 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
4124 string_list_delete(opserv_bad_words
, nn
);
4125 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4126 channel
= iter_data(it
);
4127 if (irccasestr(channel
->name
, argv
[1])
4128 && !opserv_bad_channel(channel
->name
)) {
4129 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
4130 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4131 channel
->bad_channel
= 0;
4134 reply("OSMSG_REMOVED_BAD", argv
[1]);
4138 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
4142 static MODCMD_FUNC(cmd_addexempt
)
4144 const char *chanName
;
4146 if ((argc
> 1) && IsChannelName(argv
[1])) {
4149 reply("MSG_NOT_CHANNEL_NAME");
4153 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
4154 channel
= GetChannel(chanName
);
4156 if (channel
->bad_channel
) {
4157 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
4158 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4160 channel
->bad_channel
= 0;
4162 reply("OSMSG_ADDED_EXEMPTION", chanName
);
4166 static MODCMD_FUNC(cmd_delexempt
)
4168 const char *chanName
;
4170 if ((argc
> 1) && IsChannelName(argv
[1])) {
4173 reply("MSG_NOT_CHANNEL_NAME");
4177 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
4178 reply("OSMSG_NOT_EXEMPT", chanName
);
4181 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
4186 opserv_expire_trusted_host(void *data
)
4188 struct trusted_host
*th
= data
;
4189 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
4193 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
4195 struct trusted_host
*th
;
4196 th
= calloc(1, sizeof(*th
));
4199 th
->ipaddr
= strdup(ipaddr
);
4200 th
->reason
= reason
? strdup(reason
) : NULL
;
4201 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
4202 th
->issued
= issued
;
4204 th
->expires
= expires
;
4205 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
4207 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4211 free_trusted_host(void *data
)
4213 struct trusted_host
*th
= data
;
4220 static MODCMD_FUNC(cmd_addtrust
)
4222 unsigned long interval
;
4224 irc_in_addr_t tmpaddr
;
4227 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
4228 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
4232 if (!irc_pton(&tmpaddr
, NULL
, argv
[1])) {
4233 reply("OSMSG_BAD_IP", argv
[1]);
4237 count
= strtoul(argv
[2], &tmp
, 10);
4239 reply("OSMSG_BAD_NUMBER", argv
[2]);
4243 interval
= ParseInterval(argv
[3]);
4244 if (!interval
&& strcmp(argv
[3], "0")) {
4245 reply("MSG_INVALID_DURATION", argv
[3]);
4249 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4250 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
4251 reply("OSMSG_ADDED_TRUSTED");
4255 static MODCMD_FUNC(cmd_edittrust
)
4257 unsigned long interval
;
4258 struct trusted_host
*th
;
4262 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
4264 reply("OSMSG_NOT_TRUSTED", argv
[1]);
4267 count
= strtoul(argv
[2], &tmp
, 10);
4268 if (!count
|| *tmp
) {
4269 reply("OSMSG_BAD_NUMBER", argv
[2]);
4272 interval
= ParseInterval(argv
[3]);
4273 if (!interval
&& strcmp(argv
[3], "0")) {
4274 reply("MSG_INVALID_DURATION", argv
[3]);
4277 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4279 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4282 th
->reason
= strdup(reason
);
4284 th
->issuer
= strdup(user
->handle_info
->handle
);
4288 th
->expires
= now
+ interval
;
4289 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4292 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
4296 static MODCMD_FUNC(cmd_deltrust
)
4300 for (n
=1; n
<argc
; n
++) {
4301 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
4305 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4306 dict_remove(opserv_trusted_hosts
, argv
[n
]);
4308 reply("OSMSG_REMOVED_TRUSTED");
4312 /* This doesn't use dict_t because it's a little simpler to open-code the
4313 * comparisons (and simpler arg-passing for the ADD subcommand).
4315 static MODCMD_FUNC(cmd_clone
)
4318 struct userNode
*clone
;
4320 clone
= GetUserH(argv
[2]);
4321 if (!irccasecmp(argv
[1], "ADD")) {
4323 char ident
[USERLEN
+1];
4326 reply("MSG_MISSING_PARAMS", argv
[1]);
4331 reply("OSMSG_CLONE_EXISTS", argv
[2]);
4334 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
4335 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
4336 if (argv
[3][i
] == '@') {
4340 ident
[i
] = argv
[3][i
];
4343 if (!argv
[3][i
] || (i
==USERLEN
)) {
4344 reply("OSMSG_NOT_A_HOSTMASK");
4347 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
4348 reply("OSMSG_CLONE_FAILED", argv
[2]);
4351 reply("OSMSG_CLONE_ADDED", clone
->nick
);
4355 reply("MSG_NICK_UNKNOWN", argv
[2]);
4358 if (clone
->uplink
!= self
|| IsService(clone
)) {
4359 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
4362 if (!irccasecmp(argv
[1], "REMOVE")) {
4365 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
4368 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
4369 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
4372 DelUser(clone
, NULL
, 1, reason
);
4373 reply("OSMSG_CLONE_REMOVED", argv
[2]);
4377 reply("MSG_MISSING_PARAMS", argv
[1]);
4381 channel
= GetChannel(argv
[3]);
4382 if (!irccasecmp(argv
[1], "JOIN")) {
4384 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
4385 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4388 AddChannelUser(clone
, channel
);
4389 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
4392 if (!irccasecmp(argv
[1], "PART")) {
4394 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4397 if (!GetUserMode(channel
, clone
)) {
4398 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4401 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
4402 DelChannelUser(clone
, channel
, "Leaving.", 0);
4405 if (!irccasecmp(argv
[1], "OP")) {
4406 struct mod_chanmode change
;
4408 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4411 mod_chanmode_init(&change
);
4413 change
.args
[0].mode
= MODE_CHANOP
;
4414 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4415 if (!change
.args
[0].u
.member
) {
4416 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4419 modcmd_chanmode_announce(&change
);
4420 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
4423 if (!irccasecmp(argv
[1], "HOP")) {
4424 struct mod_chanmode change
;
4426 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4429 mod_chanmode_init(&change
);
4431 change
.args
[0].mode
= MODE_HALFOP
;
4432 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4433 if (!change
.args
[0].u
.member
) {
4434 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4437 modcmd_chanmode_announce(&change
);
4438 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
4442 reply("MSG_MISSING_PARAMS", argv
[1]);
4446 if (!irccasecmp(argv
[1], "SAY")) {
4447 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
4448 irc_privmsg(clone
, argv
[3], text
);
4449 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
4452 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
4456 static struct helpfile_expansion
4457 opserv_help_expand(const char *variable
)
4459 extern struct userNode
*message_source
;
4460 struct helpfile_expansion exp
;
4461 struct service
*service
;
4467 if (!(service
= service_find(message_source
->nick
))) {
4468 exp
.type
= HF_STRING
;
4469 exp
.value
.str
= NULL
;
4470 } else if (!irccasecmp(variable
, "index")) {
4471 exp
.type
= HF_TABLE
;
4472 exp
.value
.table
.length
= 1;
4473 exp
.value
.table
.width
= 2;
4474 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
4475 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
4476 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
4477 exp
.value
.table
.contents
[0][0] = "Command";
4478 exp
.value
.table
.contents
[0][1] = "Level";
4479 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
4480 cmd
= iter_data(it
);
4481 row
= exp
.value
.table
.length
++;
4482 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
4483 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
4484 level
= cmd
->min_opserv_level
;
4485 if (!level_strings
[level
]) {
4486 level_strings
[level
] = malloc(16);
4487 snprintf(level_strings
[level
], 16, "%3d", level
);
4489 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
4491 } else if (!strncasecmp(variable
, "level", 5)) {
4492 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
4493 exp
.type
= HF_STRING
;
4495 level
= cmd
->min_opserv_level
;
4496 exp
.value
.str
= malloc(16);
4497 snprintf(exp
.value
.str
, 16, "%3d", level
);
4499 exp
.value
.str
= NULL
;
4502 exp
.type
= HF_STRING
;
4503 exp
.value
.str
= NULL
;
4509 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
4511 char buf
[16], *flags
= NULL
;
4512 unsigned int iflags
= 0;
4513 sprintf(buf
, "%d", min_level
);
4515 case 1: flags
= "+acceptchan"; break;
4516 case 3: flags
= "+acceptpluschan"; /* fall through */
4517 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
4520 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
4522 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
4526 int add_reserved(const char *key
, void *data
, void *extra
)
4528 struct chanNode
*chan
;
4529 struct record_data
*rd
= data
;
4530 const char *ident
, *hostname
, *desc
;
4532 struct userNode
*reserve
;
4533 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
4535 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
4538 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
4540 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
4543 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
4545 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
4548 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
4549 reserve
->modes
|= FLAGS_PERSISTENT
;
4550 dict_insert(extra
, reserve
->nick
, reserve
);
4553 if (autojoin_channels
&& reserve
) {
4554 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
4555 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
4556 AddChannelUser(reserve
, chan
)->modes
|= MODE_VOICE
;
4564 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
4568 unsigned int matched
;
4570 if (!self
->uplink
) return 0;
4571 discrim
= calloc(1, sizeof(*discrim
));
4572 discrim
->limit
= dict_size(clients
);
4573 discrim
->max_level
= ~0;
4574 discrim
->max_ts
= now
;
4575 discrim
->max_channels
= INT_MAX
;
4576 discrim
->authed
= -1;
4577 discrim
->info_space
= -1;
4578 discrim
->intra_scmp
= 0;
4579 discrim
->intra_dcmp
= 0;
4580 discrim
->use_regex
= 0;
4581 discrim
->silent
= 0;
4582 dupmask
= strdup(hostmask
);
4583 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
4584 if (!irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, discrim
->mask_host
))
4585 discrim
->ip_mask_bits
= 0;
4586 matched
= opserv_discrim_search(discrim
, func
, extra
);
4588 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
4597 gag_free(struct gag_entry
*gag
)
4599 unsigned int ungagged
;
4601 /* Remove from gag list */
4602 if (gagList
== gag
) {
4603 gagList
= gag
->next
;
4605 struct gag_entry
*prev
;
4606 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
4607 prev
->next
= gag
->next
;
4610 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
4612 /* Deallocate storage */
4622 gag_expire(void *data
)
4628 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
4630 struct gag_entry
*gag
;
4632 /* Create gag and put it into linked list */
4633 gag
= calloc(1, sizeof(*gag
));
4634 gag
->mask
= strdup(mask
);
4635 gag
->owner
= strdup(owner
? owner
: "<unknown>");
4636 gag
->reason
= strdup(reason
? reason
: "<unknown>");
4637 gag
->expires
= expires
;
4639 timeq_add(gag
->expires
, gag_expire
, gag
);
4640 gag
->next
= gagList
;
4643 /* If we're linked, see if who the gag applies to */
4644 return foreach_matching_user(mask
, gag_helper_func
, gag
);
4648 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4650 struct record_data
*rd
= data
;
4651 char *owner
, *reason
, *expstr
;
4654 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
4655 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
4656 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
4657 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
4658 gag_create(key
, owner
, reason
, expires
);
4663 static struct opserv_user_alert
*
4664 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
, int last
)
4667 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
4668 struct opserv_user_alert
*alert
;
4671 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
4672 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
4675 alert
= malloc(sizeof(*alert
));
4676 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
4677 alert
->text_discrim
= strdup(text_discrim
);
4679 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
4680 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
4681 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
4682 /* Check for missing required criteria or broken records */
4683 if (!alert
->discrim
|| (reaction
==REACT_SVSJOIN
&& !alert
->discrim
->chantarget
) ||
4684 (reaction
==REACT_SVSPART
&& !alert
->discrim
->chantarget
) ||
4685 (reaction
==REACT_MARK
&& !alert
->discrim
->mark
)) {
4686 free(alert
->text_discrim
);
4691 alert
->split_discrim
= discrim_copy
;
4692 name_dup
= strdup(name
);
4693 if (!alert
->discrim
->reason
)
4694 alert
->discrim
->reason
= strdup(name
);
4695 alert
->reaction
= reaction
;
4696 dict_insert(opserv_user_alerts
, name_dup
, alert
);
4697 /* Stick the alert into the appropriate additional alert dict(s).
4698 * For channel alerts, we only use channels and min_channels;
4699 * max_channels would have to be checked on /part, which we do not
4700 * yet do, and which seems of questionable value.
4702 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
4703 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
4704 if (alert
->discrim
->mask_nick
)
4705 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
4711 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
4713 struct record_data *rd = data;
4714 char *reason = GET_RECORD_QSTRING(rd);
4716 * i hope this can't happen *
4718 reason = "No Reason";
4720 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
4727 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4732 const char *discrim
, *react
, *owner
;
4733 opserv_alert_reaction reaction
;
4734 struct opserv_user_alert
*alert
;
4736 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
4737 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
4740 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
4741 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
4742 str
= database_get_data(alert_dict
, KEY_LAST
, RECDB_QSTRING
);
4746 if (!react
|| !irccasecmp(react
, "notice"))
4747 reaction
= REACT_NOTICE
;
4748 else if (!irccasecmp(react
, "kill"))
4749 reaction
= REACT_KILL
;
4751 else if (!irccasecmp(react, "silent"))
4752 reaction = REACT_SILENT;
4754 else if (!irccasecmp(react
, "gline"))
4755 reaction
= REACT_GLINE
;
4756 else if (!irccasecmp(react
, "track"))
4757 reaction
= REACT_TRACK
;
4758 else if (!irccasecmp(react
, "shun"))
4759 reaction
= REACT_SHUN
;
4760 else if (!irccasecmp(react
, "svsjoin"))
4761 reaction
= REACT_SVSJOIN
;
4762 else if (!irccasecmp(react
, "svspart"))
4763 reaction
= REACT_SVSPART
;
4764 else if (!irccasecmp(react
, "version"))
4765 reaction
= REACT_VERSION
;
4766 else if (!irccasecmp(react
, "mark"))
4767 reaction
= REACT_MARK
;
4769 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
4772 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
, last
);
4774 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
4777 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
4779 alert
->owner
= strdup(owner
? owner
: "<unknown>");
4784 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
4786 struct record_data
*rd
= data
;
4787 const char *limit
, *str
, *reason
, *issuer
;
4788 time_t issued
, expires
;
4790 if (rd
->type
== RECDB_QSTRING
) {
4791 /* old style host by itself */
4792 limit
= GET_RECORD_QSTRING(rd
);
4797 } else if (rd
->type
== RECDB_OBJECT
) {
4798 dict_t obj
= GET_RECORD_OBJECT(rd
);
4799 /* new style structure */
4800 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
4801 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
4802 expires
= str
? ParseInterval(str
) : 0;
4803 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
4804 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
4805 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
4806 issued
= str
? ParseInterval(str
) : 0;
4810 if (expires
&& (expires
< now
))
4812 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
4817 add_routing_plan_server(const char *name
, void *data
, void *rp
)
4819 struct record_data
*rd
= data
;
4820 const char *uplink
, *portstr
, *karma
, *second
, *offline
;
4822 dict_t obj
= GET_RECORD_OBJECT(rd
);
4823 if(rd
->type
== RECDB_OBJECT
) {
4824 uplink
= database_get_data(obj
, KEY_UPLINK
, RECDB_QSTRING
);
4825 second
= database_get_data(obj
, KEY_SECOND
, RECDB_QSTRING
);
4826 portstr
= database_get_data(obj
, KEY_PORT
, RECDB_QSTRING
);
4827 karma
= database_get_data(obj
, KEY_KARMA
, RECDB_QSTRING
);
4828 offline
= database_get_data(obj
, KEY_OFFLINE
, RECDB_QSTRING
);
4829 /* create routing plan server named key, with uplink uplink. */
4830 opserv_routing_plan_add_server(rp
, name
, uplink
, portstr
? atoi(portstr
) : 0,
4831 karma
? atoi(karma
) : KARMA_DEFAULT
, second
,
4832 offline
? atoi(offline
) : 0);
4839 routing_plan_set_option(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4841 struct record_data
*rd
= data
;
4842 if(rd
->type
== RECDB_QSTRING
)
4844 char *value
= GET_RECORD_QSTRING(rd
);
4845 dict_insert(opserv_routing_plan_options
, strdup(name
), strdup(value
));
4851 add_routing_plan(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4853 struct record_data
*rd
= data
;
4854 struct routingPlan
*rp
;
4856 if(rd
->type
== RECDB_OBJECT
) {
4857 dict_t obj
= GET_RECORD_OBJECT(rd
);
4858 rp
= opserv_add_routing_plan(name
);
4859 dict_foreach(obj
, add_routing_plan_server
, rp
);
4865 opserv_saxdb_read(struct dict
*conf_db
)
4868 struct record_data
*rd
;
4872 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
4873 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
4874 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
4876 case RECDB_STRING_LIST
:
4877 /* Add words one by one just in case there are overlaps from an old DB. */
4878 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4879 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
4882 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
4883 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
4885 if (rd
->type
== RECDB_STRING_LIST
)
4886 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
4887 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4894 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
4895 && (rd
->type
== RECDB_STRING_LIST
)) {
4896 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4897 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4899 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
4901 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
4902 max_clients
= atoi(str
);
4903 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
4904 max_clients_time
= atoi(str
);
4906 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
4907 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
4908 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
4909 dict_foreach(object
, add_gag_helper
, NULL
);
4910 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
4911 dict_foreach(object
, add_user_alert
, NULL
);
4913 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
4914 dict_foreach(object, add_chan_warn, NULL);
4917 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN
, RECDB_OBJECT
)))
4918 dict_foreach(object
, add_routing_plan
, NULL
);
4920 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN_OPTIONS
, RECDB_OBJECT
)))
4921 dict_foreach(object
, routing_plan_set_option
, NULL
);
4927 opserv_saxdb_write(struct saxdb_context
*ctx
)
4929 struct string_list
*slist
;
4932 /* reserved nicks */
4933 if (dict_size(opserv_reserved_nick_dict
)) {
4934 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
4935 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
4936 struct userNode
*user
= iter_data(it
);
4937 if (!IsPersistent(user
)) continue;
4938 saxdb_start_record(ctx
, iter_key(it
), 0);
4939 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
4940 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
4941 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
4942 saxdb_end_record(ctx
);
4944 saxdb_end_record(ctx
);
4947 if (opserv_bad_words
->used
) {
4948 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
4950 /* routing plan options */
4951 if (dict_size(opserv_routing_plan_options
)) {
4952 saxdb_start_record(ctx
, KEY_ROUTINGPLAN_OPTIONS
, 1);
4953 for(it
= dict_first(opserv_routing_plan_options
); it
; it
= iter_next(it
)) {
4954 saxdb_write_string(ctx
, iter_key(it
), iter_data(it
));
4956 saxdb_end_record(ctx
);
4959 if (dict_size(opserv_routing_plans
)) {
4960 dict_iterator_t svrit
;
4961 struct routingPlan
*rp
;
4962 struct routingPlanServer
*rps
;
4963 saxdb_start_record(ctx
, KEY_ROUTINGPLAN
, 1);
4964 for (it
= dict_first(opserv_routing_plans
); it
; it
= iter_next(it
)) {
4966 saxdb_start_record(ctx
, iter_key(it
), 0);
4967 for(svrit
= dict_first(rp
->servers
); svrit
; svrit
= iter_next(svrit
)) {
4969 rps
= iter_data(svrit
);
4970 saxdb_start_record(ctx
, iter_key(svrit
), 0);
4971 saxdb_write_string(ctx
, KEY_UPLINK
, rps
->uplink
);
4972 if(rps
->secondaryuplink
)
4973 saxdb_write_string(ctx
, KEY_SECOND
, rps
->secondaryuplink
);
4974 sprintf(buf
, "%d", rps
->port
);
4975 saxdb_write_string(ctx
, KEY_PORT
, buf
);
4976 sprintf(buf
, "%d", rps
->karma
);
4977 saxdb_write_string(ctx
, KEY_KARMA
, buf
);
4978 sprintf(buf
, "%d", rps
->offline
);
4979 saxdb_write_string(ctx
, KEY_OFFLINE
, buf
);
4980 saxdb_end_record(ctx
);
4982 saxdb_end_record(ctx
);
4984 saxdb_end_record(ctx
);
4986 /* insert exempt channel names */
4987 if (dict_size(opserv_exempt_channels
)) {
4988 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
4989 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
4990 string_list_append(slist
, strdup(iter_key(it
)));
4992 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
4993 free_string_list(slist
);
4995 /* trusted hosts takes a little more work */
4996 if (dict_size(opserv_trusted_hosts
)) {
4997 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
4998 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
4999 struct trusted_host
*th
= iter_data(it
);
5000 saxdb_start_record(ctx
, iter_key(it
), 0);
5001 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
5002 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
5003 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
5004 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
5005 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
5006 saxdb_end_record(ctx
);
5008 saxdb_end_record(ctx
);
5012 struct gag_entry
*gag
;
5013 saxdb_start_record(ctx
, KEY_GAGS
, 1);
5014 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5015 saxdb_start_record(ctx
, gag
->mask
, 0);
5016 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
5017 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
5018 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
5019 saxdb_end_record(ctx
);
5021 saxdb_end_record(ctx
);
5023 /* channel warnings */
5025 if (dict_size(opserv_chan_warn)) {
5026 saxdb_start_record(ctx, KEY_WARN, 0);
5027 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
5028 saxdb_write_string(ctx, iter_key(it), iter_data(it));
5030 saxdb_end_record(ctx);
5034 if (dict_size(opserv_user_alerts
)) {
5035 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
5036 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
5037 struct opserv_user_alert
*alert
= iter_data(it
);
5038 const char *reaction
;
5039 saxdb_start_record(ctx
, iter_key(it
), 0);
5040 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
5041 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
5042 saxdb_write_int(ctx
, KEY_LAST
, alert
->last
);
5043 switch (alert
->reaction
) {
5044 case REACT_NOTICE
: reaction
= "notice"; break;
5045 case REACT_KILL
: reaction
= "kill"; break;
5046 // case REACT_SILENT: reaction = "silent"; break;
5047 case REACT_GLINE
: reaction
= "gline"; break;
5048 case REACT_TRACK
: reaction
= "track"; break;
5049 case REACT_SHUN
: reaction
= "shun"; break;
5050 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
5051 case REACT_SVSPART
: reaction
= "svspart"; break;
5052 case REACT_VERSION
: reaction
= "version"; break;
5053 case REACT_MARK
: reaction
= "mark"; break;
5056 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
5059 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
5060 saxdb_end_record(ctx
);
5062 saxdb_end_record(ctx
);
5065 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
5066 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
5067 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
5068 saxdb_end_record(ctx
);
5073 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
5075 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
5079 static MODCMD_FUNC(cmd_query
)
5081 struct record_data
*rd
;
5086 reply("OSMSG_OPTION_ROOT");
5087 conf_enum_root(query_keys_helper
, user
);
5091 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
5092 if (!(rd
= conf_get_node(nodename
))) {
5093 reply("OSMSG_UNKNOWN_OPTION", nodename
);
5097 if (rd
->type
== RECDB_QSTRING
)
5098 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
5099 else if (rd
->type
== RECDB_STRING_LIST
) {
5100 reply("OSMSG_OPTION_LIST", nodename
);
5101 if (rd
->d
.slist
->used
)
5102 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
5103 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
5105 reply("OSMSG_OPTION_LIST_EMPTY");
5106 } else if (rd
->type
== RECDB_OBJECT
) {
5107 reply("OSMSG_OPTION_KEYS", nodename
);
5108 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
5114 static MODCMD_FUNC(cmd_set
)
5116 struct record_data
*rd
;
5118 /* I originally wanted to be able to fully manipulate the config
5119 db with this, but i wussed out. feel free to fix this - you'll
5120 need to handle quoted strings which have been split, and likely
5121 invent a syntax for it. -Zoot */
5123 if (!(rd
= conf_get_node(argv
[1]))) {
5124 reply("OSMSG_SET_NOT_SET", argv
[1]);
5128 if (rd
->type
!= RECDB_QSTRING
) {
5129 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
5133 free(rd
->d
.qstring
);
5134 rd
->d
.qstring
= strdup(argv
[2]);
5135 conf_call_reload_funcs();
5136 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
5140 static MODCMD_FUNC(cmd_settime
)
5142 const char *srv_name_mask
= "*";
5143 time_t new_time
= now
;
5146 srv_name_mask
= argv
[1];
5148 new_time
= time(NULL
);
5149 irc_settime(srv_name_mask
, new_time
);
5150 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
5155 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
5160 discrim
= calloc(1, sizeof(*discrim
));
5161 discrim
->limit
= 250;
5162 discrim
->max_level
= ~0;
5163 discrim
->max_ts
= INT_MAX
;
5164 discrim
->domain_depth
= 2;
5165 discrim
->max_channels
= INT_MAX
;
5166 discrim
->authed
= -1;
5167 discrim
->info_space
= -1;
5168 discrim
->intra_dcmp
= 0;
5169 discrim
->intra_scmp
= 0;
5170 discrim
->use_regex
= 0;
5171 discrim
->silent
= 0;
5173 for (i
=0; i
<argc
; i
++) {
5174 if (irccasecmp(argv
[i
], "log") == 0) {
5175 discrim
->option_log
= 1;
5178 /* Assume all other criteria require arguments. */
5179 if (i
== argc
- 1) {
5180 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5183 if (argv
[i
+1][0] == '&') {
5184 /* Looking for intra-userNode matches */
5185 char *tmp
= &(argv
[i
+1][1]);
5186 if (strcasecmp(tmp
, argv
[i
]) != 0) { /* Don't allow "nick &nick" etc */
5187 if (!strcasecmp(tmp
, "nick"))
5188 discrim
->intra_dcmp
= 1;
5189 else if (!strcasecmp(tmp
, "ident"))
5190 discrim
->intra_dcmp
= 2;
5191 else if (!strcasecmp(tmp
, "info"))
5192 discrim
->intra_dcmp
= 3;
5195 if (irccasecmp(argv
[i
], "mask") == 0) {
5196 if (!is_ircmask(argv
[++i
])) {
5197 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5200 if (!split_ircmask(argv
[i
],
5201 &discrim
->mask_nick
,
5202 &discrim
->mask_ident
,
5203 &discrim
->mask_host
)) {
5204 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5207 } else if (irccasecmp(argv
[i
], "nick") == 0) {
5209 if (discrim
->intra_dcmp
> 0)
5210 discrim
->intra_scmp
= 1;
5212 discrim
->mask_nick
= argv
[i
];
5213 } else if (irccasecmp(argv
[i
], "ident") == 0) {
5215 if (discrim
->intra_dcmp
> 0)
5216 discrim
->intra_scmp
= 2;
5218 discrim
->mask_ident
= argv
[i
];
5219 } else if (irccasecmp(argv
[i
], "host") == 0) {
5220 discrim
->mask_host
= argv
[++i
];
5221 } else if (irccasecmp(argv
[i
], "info") == 0) {
5223 if (discrim
->intra_dcmp
> 0)
5224 discrim
->intra_scmp
= 3;
5226 discrim
->mask_info
= argv
[i
];
5227 } else if (irccasecmp(argv
[i
], "version") == 0) {
5228 discrim
->mask_version
= argv
[++i
];
5229 } else if (irccasecmp(argv
[i
], "server") == 0) {
5230 discrim
->server
= argv
[++i
];
5231 } else if (irccasecmp(argv
[i
], "ip") == 0) {
5232 j
= irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, argv
[++i
]);
5234 send_message(user
, bot
, "OSMSG_BAD_IP", argv
[i
]);
5237 } else if (irccasecmp(argv
[i
], "account") == 0) {
5238 if (discrim
->authed
== 0) {
5239 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5242 discrim
->accountmask
= argv
[++i
];
5243 discrim
->authed
= 1;
5244 } else if (irccasecmp(argv
[i
], "marked") == 0) {
5245 discrim
->mask_mark
= argv
[++i
];
5246 } else if (irccasecmp(argv
[i
], "chantarget") == 0) {
5247 if(!IsChannelName(argv
[i
+1])) {
5248 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5251 discrim
->chantarget
= argv
[++i
];
5252 } else if (irccasecmp(argv
[i
], "checkrestrictions") == 0) {
5254 if (true_string(argv
[i
])) {
5255 discrim
->checkrestrictions
= 1;
5256 } else if (false_string(argv
[i
])) {
5257 discrim
->checkrestrictions
= 0;
5259 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5262 } else if (irccasecmp(argv
[i
], "mark") == 0) {
5263 if(!is_valid_mark(argv
[i
+1])) {
5264 send_message(user
, bot
, "OSMSG_MARK_INVALID");
5267 discrim
->mark
= argv
[++i
];
5268 } else if (irccasecmp(argv
[i
], "authed") == 0) {
5269 i
++; /* true_string and false_string are macros! */
5270 if (true_string(argv
[i
])) {
5271 discrim
->authed
= 1;
5272 } else if (false_string(argv
[i
])) {
5273 if (discrim
->accountmask
) {
5274 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5277 discrim
->authed
= 0;
5279 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5282 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
5283 /* XXX: A hack because you can't check explicitly for a space through
5284 * any other means */
5286 if (true_string(argv
[i
])) {
5287 discrim
->info_space
= 1;
5288 } else if (false_string(argv
[i
])) {
5289 discrim
->info_space
= 0;
5291 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5294 } else if (irccasecmp(argv
[i
], "regex") == 0) {
5296 if (true_string(argv
[i
])) {
5297 discrim
->use_regex
= 1;
5298 } else if (false_string(argv
[i
])) {
5299 discrim
->use_regex
= 0;
5301 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5304 } else if (irccasecmp(argv
[i
], "silent") == 0) {
5306 if(user
!= opserv
&& !oper_has_access(user
, opserv
, opserv_conf
.silent_level
, 0)) {
5308 } else if (true_string(argv
[i
])) {
5309 discrim
->silent
= 1;
5310 } else if (false_string(argv
[i
])) {
5311 discrim
->silent
= 0;
5313 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5316 } else if (irccasecmp(argv
[i
], "duration") == 0) {
5317 discrim
->duration
= ParseInterval(argv
[++i
]);
5318 } else if (irccasecmp(argv
[i
], "channel") == 0) {
5319 for (j
=0, i
++; ; j
++) {
5320 switch (argv
[i
][j
]) {
5324 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
5327 discrim
->chan_req_modes
|= MODE_VOICE
;
5328 discrim
->chan_no_modes
|= MODE_CHANOP
;
5329 discrim
->chan_no_modes
|= MODE_HALFOP
;
5332 discrim
->chan_req_modes
|= MODE_HALFOP
;
5333 discrim
->chan_no_modes
|= MODE_CHANOP
;
5334 discrim
->chan_no_modes
|= MODE_VOICE
;
5337 discrim
->chan_req_modes
|= MODE_CHANOP
;
5340 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5345 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
5346 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
5347 /* secretly "allow_channel" now means "if a channel name is
5348 * specified, require that it currently exist" */
5349 if (allow_channel
) {
5350 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
5353 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
5356 LockChannel(discrim
->channel
);
5357 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
5358 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
5359 } else if (irccasecmp(argv
[i
], "limit") == 0) {
5360 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
5361 } else if (irccasecmp(argv
[i
], "reason") == 0) {
5362 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
5364 } else if (irccasecmp(argv
[i
], "last") == 0) {
5365 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
5366 } else if ((irccasecmp(argv
[i
], "linked") == 0)
5367 || (irccasecmp(argv
[i
], "nickage") == 0)) {
5368 const char *cmp
= argv
[++i
];
5369 if (cmp
[0] == '<') {
5370 if (cmp
[1] == '=') {
5371 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5373 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
5375 } else if (cmp
[0] == '>') {
5376 if (cmp
[1] == '=') {
5377 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
5379 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
5382 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5384 } else if (irccasecmp(argv
[i
], "access") == 0) {
5385 const char *cmp
= argv
[++i
];
5386 if (cmp
[0] == '<') {
5387 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
5388 if (cmp
[1] == '=') {
5389 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
5391 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
5393 } else if (cmp
[0] == '=') {
5394 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
5395 } else if (cmp
[0] == '>') {
5396 if (cmp
[1] == '=') {
5397 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5399 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
5402 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5404 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
5405 && (irccasecmp(argv
[++i
], "opers") == 0)) {
5406 discrim
->match_opers
= 1;
5407 } else if (irccasecmp(argv
[i
], "depth") == 0) {
5408 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
5409 } else if (irccasecmp(argv
[i
], "clones") == 0) {
5410 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
5411 } else if (irccasecmp(argv
[i
], "modes") == 0) {
5412 discrim
->modes
= argv
[++i
];
5414 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
5419 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
5420 discrim
->mask_nick
= 0;
5422 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
5423 discrim
->mask_ident
= 0;
5425 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
5426 discrim
->mask_info
= 0;
5428 if (discrim
->mask_version
&& !strcmp(discrim
->mask_version
, "*")) {
5429 discrim
->mask_version
= 0;
5431 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
5432 discrim
->mask_host
= 0;
5435 if(discrim
->use_regex
)
5437 if(discrim
->mask_nick
)
5439 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_NOSUB
);
5440 discrim
->has_regex_nick
= !err
;
5444 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
5446 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
5451 if(discrim
->mask_ident
)
5453 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_NOSUB
);
5454 discrim
->has_regex_ident
= !err
;
5458 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
5460 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
5465 if(discrim
->mask_host
)
5467 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_NOSUB
);
5468 discrim
->has_regex_host
= !err
;
5472 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
5474 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
5479 if(discrim
->mask_info
)
5481 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_NOSUB
);
5482 discrim
->has_regex_info
= !err
;
5486 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
5488 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
5493 if(discrim
->mask_version
)
5495 int err
= regcomp(&discrim
->regex_version
, discrim
->mask_version
, REG_EXTENDED
|REG_NOSUB
);
5496 discrim
->has_regex_version
= !err
;
5500 buff
[regerror(err
, &discrim
->regex_version
, buff
, sizeof(buff
))] = 0;
5502 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_version
, buff
, err
);
5515 if(discrim
->has_regex_nick
)
5516 regfree(&discrim
->regex_nick
);
5517 if(discrim
->has_regex_ident
)
5518 regfree(&discrim
->regex_ident
);
5519 if(discrim
->has_regex_host
)
5520 regfree(&discrim
->regex_host
);
5521 if(discrim
->has_regex_info
)
5522 regfree(&discrim
->regex_info
);
5529 discrim_match(discrim_t discrim
, struct userNode
*user
)
5531 unsigned int access
;
5532 char *scmp
=NULL
, *dcmp
=NULL
;
5534 if ((user
->timestamp
< discrim
->min_ts
)
5535 || (user
->timestamp
> discrim
->max_ts
)
5536 || (user
->channels
.used
< discrim
->min_channels
)
5537 || (user
->channels
.used
> discrim
->max_channels
)
5538 || (discrim
->authed
== 0 && user
->handle_info
)
5539 || (discrim
->authed
== 1 && !user
->handle_info
)
5540 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
5541 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
5542 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
5543 || (discrim
->mask_mark
&& (!user
->mark
|| !match_ircglob(user
->mark
, discrim
->mask_mark
)))
5544 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
5545 || (discrim
->ip_mask_bits
&& !irc_check_mask(&user
->ip
, &discrim
->ip_mask
, discrim
->ip_mask_bits
))
5549 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
))
5552 if(discrim
->use_regex
)
5554 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
5555 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
5556 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
5557 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))
5558 || (discrim
->has_regex_version
&& (!user
->version_reply
|| regexec(&discrim
->regex_version
, user
->version_reply
, 0, 0, 0)))) {
5564 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
5565 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
5566 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
5567 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))
5568 || (discrim
->mask_version
&& (!user
->version_reply
|| !match_ircglob(user
->version_reply
, discrim
->mask_version
))) ) {
5573 if ((discrim
->intra_scmp
> 0 && discrim
->intra_dcmp
> 0)) {
5574 switch(discrim
->intra_scmp
) {
5575 case 1: scmp
=user
->nick
; break;
5576 case 2: scmp
=user
->ident
; break;
5579 if (discrim
->info_space
== 1) scmp
++;
5582 switch(discrim
->intra_dcmp
) {
5583 case 1: dcmp
=user
->nick
; break;
5584 case 2: dcmp
=user
->ident
; break;
5585 case 3: /* When checking INFO, and info_space is enabled
5586 * ignore the first character in a search
5587 * XXX: Should we ignore ALL leading whitespace?
5588 * Also, what about ignoring ~ in ident?
5591 if (discrim
->info_space
== 1) dcmp
++;
5594 if (irccasecmp(scmp
,dcmp
))
5598 if (discrim
->modes
) {
5599 unsigned int ii
, matches
= 0;
5600 for (ii
= 0; ii
< strlen(discrim
->modes
); ii
++) {
5601 switch(discrim
->modes
[ii
]) {
5603 if(IsOper(user
)) matches
++;
5606 if(IsOper(user
)) matches
++;
5609 if(IsInvisible(user
)) matches
++;
5612 if(IsWallOp(user
)) matches
++;
5615 if(IsServNotice(user
)) matches
++;
5618 if(IsDeaf(user
)) matches
++;
5621 if(IsService(user
)) matches
++;
5624 if(IsGlobal(user
)) matches
++;
5627 if(IsSetHost(user
)) matches
++;
5630 if(IsBotM(user
)) matches
++;
5633 if(IsHideChans(user
)) matches
++;
5636 if(IsHideIdle(user
)) matches
++;
5639 if(IsXtraOp(user
)) matches
++;
5642 if(IsHiddenHost(user
)) matches
++;
5646 if (matches
!= strlen(discrim
->modes
)) return 0;
5649 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
5650 if ((access
< discrim
->min_level
)
5651 || (access
> discrim
->max_level
)) {
5654 if (discrim
->min_clones
> 1) {
5655 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&user
->ip
), NULL
);
5656 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
))
5663 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
5665 unsigned int nn
, count
;
5666 struct userList matched
;
5668 userList_init(&matched
);
5669 /* Try most optimized search methods first */
5670 if (discrim
->channel
) {
5672 (nn
< discrim
->channel
->members
.used
)
5673 && (matched
.used
< discrim
->limit
);
5675 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
5676 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
5677 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
5680 if (discrim_match(discrim
, mn
->user
)) {
5681 userList_append(&matched
, mn
->user
);
5684 } else if (discrim
->ip_mask_bits
== 128) {
5685 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&discrim
->ip_mask
), NULL
);
5687 userList_clean(&matched
);
5690 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
5691 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
5692 userList_append(&matched
, ohi
->clients
.list
[nn
]);
5697 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
5698 if (discrim_match(discrim
, iter_data(it
))) {
5699 userList_append(&matched
, iter_data(it
));
5704 if (!matched
.used
) {
5705 userList_clean(&matched
);
5709 if (discrim
->option_log
) {
5710 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
5712 for (nn
=0; nn
<matched
.used
; nn
++) {
5713 struct userNode
*user
= matched
.list
[nn
];
5714 if (discrim
->option_log
) {
5715 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
5717 if (dsf(user
, data
)) {
5718 /* If a search function returns true, it ran into a
5719 problem. Stop going through the list. */
5723 if (discrim
->option_log
) {
5724 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
5726 count
= matched
.used
;
5727 userList_clean(&matched
);
5732 trace_print_func(struct userNode
*match
, void *extra
)
5734 struct discrim_and_source
*das
= extra
;
5735 if (match
->handle_info
) {
5736 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
);
5738 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
5744 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
5750 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
5752 return !(IsService(target
)
5753 || (!match_opers
&& IsOper(target
))
5754 || (target
->handle_info
5755 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
5759 trace_gline_func(struct userNode
*match
, void *extra
)
5761 struct discrim_and_source
*das
= extra
;
5763 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5764 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
, das
->discrim
->silent
);
5771 trace_shun_func(struct userNode
*match
, void *extra
)
5773 struct discrim_and_source
*das
= extra
;
5775 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5776 opserv_shun(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
5783 trace_kill_func(struct userNode
*match
, void *extra
)
5785 struct discrim_and_source
*das
= extra
;
5787 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5789 if (das
->discrim
->reason
) {
5790 reason
= das
->discrim
->reason
;
5792 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
5793 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
5795 DelUser(match
, opserv
, 1, reason
);
5802 trace_mark_func(struct userNode
*match
, void *extra
)
5804 struct discrim_and_source
*das
= extra
;
5805 char *mark
= das
->discrim
->mark
;
5809 irc_mark(match
, mark
);
5814 trace_svsjoin_func(struct userNode
*match
, void *extra
)
5816 struct discrim_and_source
*das
= extra
;
5818 char *channame
= das
->discrim
->chantarget
;
5819 int checkrestrictions
= das
->discrim
->checkrestrictions
;
5820 struct chanNode
*channel
;
5822 if(!channame
|| !IsChannelName(channame
)) {
5823 //reply("MSG_NOT_CHANNEL_NAME");
5827 if (!(channel
= GetChannel(channame
))) {
5828 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
5831 if (checkrestrictions
) {
5832 if (trace_check_bans(match
, channel
) == 1) {
5833 return 1; /* found on lamer list */
5836 if (channel
->modes
& MODE_INVITEONLY
) {
5837 return 1; /* channel is invite only */
5840 if (channel
->limit
> 0) {
5841 if (channel
->members
.used
>= channel
->limit
) {
5842 return 1; /* channel is invite on */
5846 if (*channel
->key
) {
5847 return 1; /* channel is password protected */
5851 if (GetUserMode(channel
, match
)) {
5852 // reply("OSMSG_ALREADY_THERE", channel->name);
5855 irc_svsjoin(opserv
, match
, channel
);
5856 // reply("OSMSG_SVSJOIN_SENT");
5861 trace_svspart_func(struct userNode
*match
, void *extra
)
5863 struct discrim_and_source
*das
= extra
;
5864 char *channame
= das
->discrim
->chantarget
;
5865 struct chanNode
*channel
;
5867 if(!channame
|| !IsChannelName(channame
))
5870 if (!(channel
= GetChannel(channame
)))
5873 if (!GetUserMode(channel
, match
))
5876 irc_svspart(opserv
, match
, channel
);
5881 trace_version_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
5883 irc_version_user(opserv
, match
);
5888 is_gagged(char *mask
)
5890 struct gag_entry
*gag
;
5892 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5893 if (match_ircglobs(gag
->mask
, mask
)) return 1;
5899 trace_gag_func(struct userNode
*match
, void *extra
)
5901 struct discrim_and_source
*das
= extra
;
5903 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5904 char *reason
, *mask
;
5906 if (das
->discrim
->reason
) {
5907 reason
= das
->discrim
->reason
;
5909 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
5910 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
5912 masksize
= 5+strlen(match
->hostname
);
5913 mask
= alloca(masksize
);
5914 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
5915 if (!is_gagged(mask
)) {
5916 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
5917 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
5925 trace_domains_func(struct userNode
*match
, void *extra
)
5927 struct discrim_and_source
*das
= extra
;
5929 unsigned long *count
;
5932 char ipmask
[IRC_NTOP_MASK_MAX_SIZE
];
5934 if (irc_pton(&ip
, NULL
, match
->hostname
)) {
5935 if (irc_in_addr_is_ipv4(ip
)) {
5936 unsigned long matchip
= ntohl(ip
.in6_32
[3]);
5937 /* raw IP address.. use up to first three octets of IP */
5938 switch (das
->discrim
->domain_depth
) {
5940 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
5943 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
5946 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
5949 } else if (irc_in_addr_is_ipv6(ip
)) {
5950 switch (das
->discrim
->domain_depth
) {
5951 case 1: depth
= 16; goto ipv6_pfx
;
5952 case 2: depth
= 24; goto ipv6_pfx
;
5953 case 3: depth
= 32; goto ipv6_pfx
;
5954 default: depth
= das
->discrim
->domain_depth
;
5956 irc_ntop_mask(ipmask
, sizeof(ipmask
), &ip
, depth
);
5958 } else safestrncpy(ipmask
, match
->hostname
, sizeof(ipmask
));
5959 ipmask
[sizeof(ipmask
) - 1] = '\0';
5962 hostname
= match
->hostname
+ strlen(match
->hostname
);
5963 for (depth
=das
->discrim
->domain_depth
;
5964 depth
&& (hostname
> match
->hostname
);
5967 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
5969 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
5971 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
5972 count
= calloc(1, sizeof(*count
));
5973 dict_insert(das
->dict
, strdup(hostname
), count
);
5980 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
5982 unsigned long *count
= data
;
5983 struct discrim_and_source
*das
= extra
;
5985 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
5986 return !--das
->disp_limit
;
5989 static MODCMD_FUNC(cmd_trace
)
5991 struct discrim_and_source das
;
5992 discrim_search_func action
;
5993 unsigned int matches
;
5994 struct svccmd
*subcmd
;
5998 sprintf(buf
, "trace %s", argv
[1]);
5999 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6000 reply("OSMSG_BAD_ACTION", argv
[1]);
6003 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
6005 if (!irccasecmp(argv
[1], "print"))
6006 action
= trace_print_func
;
6007 else if (!irccasecmp(argv
[1], "count"))
6008 action
= trace_count_func
;
6009 else if (!irccasecmp(argv
[1], "domains"))
6010 action
= trace_domains_func
;
6011 else if (!irccasecmp(argv
[1], "gline"))
6012 action
= trace_gline_func
;
6013 else if (!irccasecmp(argv
[1], "shun"))
6014 action
= trace_shun_func
;
6015 else if (!irccasecmp(argv
[1], "kill"))
6016 action
= trace_kill_func
;
6017 else if (!irccasecmp(argv
[1], "gag"))
6018 action
= trace_gag_func
;
6019 else if (!irccasecmp(argv
[1], "svsjoin"))
6020 action
= trace_svsjoin_func
;
6021 else if (!irccasecmp(argv
[1], "svspart"))
6022 action
= trace_svspart_func
;
6023 else if (!irccasecmp(argv
[1], "version"))
6024 action
= trace_version_func
;
6025 else if (!irccasecmp(argv
[1], "mark"))
6026 action
= trace_mark_func
;
6028 reply("OSMSG_BAD_ACTION", argv
[1]);
6032 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
6033 reply("OSMSG_LEVEL_TOO_LOW");
6039 das
.destination
= cmd
->parent
->bot
;
6040 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
6044 if (action
== trace_print_func
)
6046 reply("OSMSG_USER_SEARCH_RESULTS");
6047 reply("OSMSG_USER_SEARCH_BAR");
6048 reply("OSMSG_USER_SEARCH_HEADER");
6049 reply("OSMSG_USER_SEARCH_BAR");
6051 else if (action
== trace_count_func
)
6052 das
.discrim
->limit
= INT_MAX
;
6053 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
6054 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
6055 else if ((action
== trace_shun_func
) && !das
.discrim
->duration
)
6056 das
.discrim
->duration
= opserv_conf
.block_shun_duration
;
6057 else if (action
== trace_domains_func
) {
6058 das
.dict
= dict_new();
6059 dict_set_free_data(das
.dict
, free
);
6060 dict_set_free_keys(das
.dict
, free
);
6061 das
.disp_limit
= das
.discrim
->limit
;
6062 das
.discrim
->limit
= INT_MAX
;
6065 if (action
== trace_svsjoin_func
&& !das
.discrim
->chantarget
) {
6066 reply("OSMSG_SVSJOIN_NO_TARGET");
6069 else if (action
== trace_svspart_func
&& !das
.discrim
->chantarget
) {
6070 reply("OSMSG_SVSPART_NO_TARGET");
6073 else if (action
== trace_mark_func
&& !das
.discrim
->mark
) {
6074 reply("OSMSG_MARK_NO_MARK");
6078 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
6080 if (action
== trace_domains_func
)
6081 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
6085 if(action
== trace_print_func
)
6086 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
6088 reply("OSMSG_USER_SEARCH_COUNT", matches
);
6091 reply("MSG_NO_MATCHES");
6094 if (das
.discrim
->channel
)
6095 UnlockChannel(das
.discrim
->channel
);
6096 free(das
.discrim
->reason
);
6098 if(das
.discrim
->has_regex_nick
)
6099 regfree(&das
.discrim
->regex_nick
);
6100 if(das
.discrim
->has_regex_ident
)
6101 regfree(&das
.discrim
->regex_ident
);
6102 if(das
.discrim
->has_regex_host
)
6103 regfree(&das
.discrim
->regex_host
);
6104 if(das
.discrim
->has_regex_info
)
6105 regfree(&das
.discrim
->regex_info
);
6106 if(das
.discrim
->has_regex_version
)
6107 regfree(&das
.discrim
->regex_version
);
6110 dict_delete(das
.dict
);
6114 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
6116 typedef struct channel_discrim
{
6119 unsigned int min_users
, max_users
;
6120 time_t min_ts
, max_ts
;
6124 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
6125 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
6128 smart_parse_time(const char *str
) {
6129 /* If an interval-style string is given, treat as time before now.
6130 * If it's all digits, treat directly as a Unix timestamp. */
6131 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
6135 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
6140 discrim
= calloc(1, sizeof(*discrim
));
6141 discrim
->limit
= 25;
6143 for (i
= 0; i
< argc
; i
++) {
6144 /* Assume all criteria require arguments. */
6145 if (i
== (argc
- 1)) {
6146 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
6150 if (!irccasecmp(argv
[i
], "name"))
6151 discrim
->name
= argv
[++i
];
6152 else if (!irccasecmp(argv
[i
], "topic"))
6153 discrim
->topic
= argv
[++i
];
6154 else if (!irccasecmp(argv
[i
], "users")) {
6155 const char *cmp
= argv
[++i
];
6156 if (cmp
[0] == '<') {
6158 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
6160 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
6161 } else if (cmp
[0] == '=') {
6162 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
6163 } else if (cmp
[0] == '>') {
6165 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6167 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
6169 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6171 } else if (!irccasecmp(argv
[i
], "timestamp")) {
6172 const char *cmp
= argv
[++i
];
6173 if (cmp
[0] == '<') {
6175 discrim
->max_ts
= smart_parse_time(cmp
+2);
6177 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
6178 } else if (cmp
[0] == '=') {
6179 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
6180 } else if (cmp
[0] == '>') {
6182 discrim
->min_ts
= smart_parse_time(cmp
+2);
6184 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
6186 discrim
->min_ts
= smart_parse_time(cmp
);
6188 } else if (!irccasecmp(argv
[i
], "limit")) {
6189 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
6191 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
6196 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
6198 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
6208 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
6210 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
6211 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
6212 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
6213 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
6214 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
6215 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
6221 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
6223 unsigned int count
= 0;
6224 dict_iterator_t it
, next
;
6226 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
6227 struct chanNode
*chan
= iter_data(it
);
6229 /* Hold on to the next channel in case we decide to
6230 add actions that destructively modify the channel. */
6231 next
= iter_next(it
);
6232 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
6233 dsf(chan
, data
, bot
);
6241 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
6245 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
6248 irc_make_chanmode(channel
, modes
);
6249 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
6252 static MODCMD_FUNC(cmd_csearch
)
6255 unsigned int matches
;
6256 cdiscrim_search_func action
;
6257 struct svccmd
*subcmd
;
6260 if (!irccasecmp(argv
[1], "count"))
6261 action
= channel_count
;
6262 else if (!irccasecmp(argv
[1], "print"))
6263 action
= channel_print
;
6265 reply("OSMSG_BAD_ACTION", argv
[1]);
6269 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6270 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6271 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6275 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
6279 if (action
== channel_print
)
6280 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
6281 else if (action
== channel_count
)
6282 discrim
->limit
= INT_MAX
;
6284 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
6287 reply("MSG_MATCH_COUNT", matches
);
6289 reply("MSG_NO_MATCHES");
6295 static MODCMD_FUNC(cmd_gsync
)
6299 src
= GetServerH(argv
[1]);
6301 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6307 irc_stats(cmd
->parent
->bot
, src
, 'G');
6308 reply("OSMSG_GSYNC_RUNNING", src
->name
);
6312 static MODCMD_FUNC(cmd_ssync
)
6316 src
= GetServerH(argv
[1]);
6318 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6324 irc_stats(cmd
->parent
->bot
, src
, 'S');
6325 reply("OSMSG_SSYNC_RUNNING", src
->name
);
6329 struct gline_extra
{
6330 struct userNode
*user
;
6331 struct string_list
*glines
;
6332 struct userNode
*bot
;
6336 gtrace_print_func(struct gline
*gline
, void *extra
)
6338 struct gline_extra
*xtra
= extra
;
6339 char *when_text
, set_text
[20];
6340 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
6341 when_text
= asctime(localtime(&gline
->expires
));
6342 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6343 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
6347 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
6352 gtrace_ungline_func(struct gline
*gline
, void *extra
)
6354 struct gline_extra
*xtra
= extra
;
6355 string_list_append(xtra
->glines
, strdup(gline
->target
));
6358 static MODCMD_FUNC(cmd_gtrace
)
6360 struct gline_discrim
*discrim
;
6361 gline_search_func action
;
6362 unsigned int matches
, nn
;
6363 struct gline_extra extra
;
6364 struct svccmd
*subcmd
;
6367 if (!irccasecmp(argv
[1], "print"))
6368 action
= gtrace_print_func
;
6369 else if (!irccasecmp(argv
[1], "count"))
6370 action
= gtrace_count_func
;
6371 else if (!irccasecmp(argv
[1], "ungline"))
6372 action
= gtrace_ungline_func
;
6374 reply("OSMSG_BAD_ACTION", argv
[1]);
6377 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6378 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6379 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6383 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6387 if (action
== gtrace_print_func
)
6388 reply("OSMSG_GLINE_SEARCH_RESULTS");
6389 else if (action
== gtrace_count_func
)
6390 discrim
->limit
= INT_MAX
;
6393 extra
.glines
= alloc_string_list(4);
6394 extra
.bot
= cmd
->parent
->bot
;
6395 matches
= gline_discrim_search(discrim
, action
, &extra
);
6397 if (action
== gtrace_ungline_func
)
6398 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
6399 gline_remove(extra
.glines
->list
[nn
], 1);
6400 free_string_list(extra
.glines
);
6403 reply("MSG_MATCH_COUNT", matches
);
6405 reply("MSG_NO_MATCHES");
6406 free(discrim
->alt_target_mask
);
6412 struct userNode
*user
;
6413 struct string_list
*shuns
;
6414 struct userNode
*bot
;
6418 strace_print_func(struct shun
*shun
, void *extra
)
6420 struct shun_extra
*xtra
= extra
;
6421 char *when_text
, set_text
[20];
6422 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&shun
->issued
));
6423 when_text
= asctime(localtime(&shun
->expires
));
6424 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6425 send_message(xtra
->user
, xtra
->bot
, "OSMSG_STRACE_FORMAT", shun
->target
, set_text
, shun
->issuer
, when_text
, shun
->reason
);
6429 strace_count_func(UNUSED_ARG(struct shun
*shun
), UNUSED_ARG(void *extra
))
6434 strace_unshun_func(struct shun
*shun
, void *extra
)
6436 struct shun_extra
*xtra
= extra
;
6437 string_list_append(xtra
->shuns
, strdup(shun
->target
));
6440 static MODCMD_FUNC(cmd_strace
)
6442 struct shun_discrim
*discrim
;
6443 shun_search_func action
;
6444 unsigned int matches
, nn
;
6445 struct shun_extra extra
;
6446 struct svccmd
*subcmd
;
6449 if (!irccasecmp(argv
[1], "print"))
6450 action
= strace_print_func
;
6451 else if (!irccasecmp(argv
[1], "count"))
6452 action
= strace_count_func
;
6453 else if (!irccasecmp(argv
[1], "unshun"))
6454 action
= strace_unshun_func
;
6456 reply("OSMSG_BAD_ACTION", argv
[1]);
6459 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6460 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6461 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6465 discrim
= shun_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6469 if (action
== strace_print_func
)
6470 reply("OSMSG_SHUN_SEARCH_RESULTS");
6471 else if (action
== strace_count_func
)
6472 discrim
->limit
= INT_MAX
;
6475 extra
.shuns
= alloc_string_list(4);
6476 extra
.bot
= cmd
->parent
->bot
;
6477 matches
= shun_discrim_search(discrim
, action
, &extra
);
6479 if (action
== strace_unshun_func
)
6480 for (nn
=0; nn
<extra
.shuns
->used
; nn
++)
6481 shun_remove(extra
.shuns
->list
[nn
], 1);
6482 free_string_list(extra
.shuns
);
6485 reply("MSG_MATCH_COUNT", matches
);
6487 reply("MSG_NO_MATCHES");
6488 free(discrim
->alt_target_mask
);
6494 alert_check_user(const char *key
, void *data
, void *extra
)
6496 struct opserv_user_alert
*alert
= data
;
6497 struct userNode
*user
= extra
;
6499 if (!discrim_match(alert
->discrim
, user
))
6502 if ((alert
->reaction
!= REACT_NOTICE
)
6504 && !alert
->discrim
->match_opers
) {
6508 /* The user matches the alert criteria, so trigger the reaction. */
6509 if (alert
->discrim
->option_log
)
6510 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
);
6514 /* Return 1 to halt alert matching, such as when killing the user
6515 that triggered the alert. */
6516 switch (alert
->reaction
) {
6518 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
6521 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
, alert
->discrim
->silent
);
6524 opserv_shun(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
6527 opserv_svsjoin(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
, alert
->discrim
->checkrestrictions
);
6530 opserv_svspart(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
);
6533 /* Don't auto-version a user who we already have a version on, because the version reply itself
6534 * re-triggers this check...
6535 * TODO: maybe safer if we didn't even check react_version type alerts for the 2nd check?
6536 * sort of like we only look at channel alerts on join. -Rubin
6538 if(!user
->version_reply
)
6539 opserv_version(user
);
6542 opserv_mark(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->mark
);
6545 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
6546 /* fall through to REACT_NOTICE case */
6548 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
);
6552 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
);
6553 add_track_user(user
);
6561 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
6563 struct gag_entry
*gag
;
6564 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
6565 /* Gag them if appropriate (and only if). */
6566 user
->modes
&= ~FLAGS_GAGGED
;
6567 for (gag
= gagList
; gag
; gag
= gag
->next
) {
6568 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
6569 gag_helper_func(user
, NULL
);
6576 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
6580 if (!opserv_conf
.staff_auth_channel
6581 || user
->uplink
->burst
6582 || !user
->handle_info
)
6584 else if (user
->handle_info
->opserv_level
)
6586 else if (IsNetworkHelper(user
))
6587 type
= "NETWORK HELPER";
6588 else if (IsSupportHelper(user
))
6589 type
= "SUPPORT HELPER";
6593 if (irc_in_addr_is_valid(user
->ip
))
6594 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
6596 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
);
6599 static MODCMD_FUNC(cmd_log
)
6601 struct logSearch
*discrim
;
6602 unsigned int matches
;
6603 struct logReport report
;
6605 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
6609 reply("OSMSG_LOG_SEARCH_RESULTS");
6610 report
.reporter
= opserv
;
6612 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
6615 reply("MSG_MATCH_COUNT", matches
);
6617 reply("MSG_NO_MATCHES");
6624 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6626 if (IsOper(match
) || IsLocal(match
))
6628 match
->modes
|= FLAGS_GAGGED
;
6632 static MODCMD_FUNC(cmd_gag
)
6634 struct gag_entry
*gag
;
6635 unsigned int gagged
;
6636 unsigned long duration
;
6639 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
6641 if (!is_ircmask(argv
[1])) {
6642 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
6646 for (gag
= gagList
; gag
; gag
= gag
->next
)
6647 if (match_ircglobs(gag
->mask
, argv
[1]))
6651 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
6655 duration
= ParseInterval(argv
[2]);
6656 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
6659 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
6661 reply("OSMSG_GAG_ADDED", argv
[1]);
6666 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6668 match
->modes
&= ~FLAGS_GAGGED
;
6672 static MODCMD_FUNC(cmd_ungag
)
6674 struct gag_entry
*gag
;
6675 unsigned int ungagged
;
6677 for (gag
= gagList
; gag
; gag
= gag
->next
)
6678 if (!strcmp(gag
->mask
, argv
[1]))
6682 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
6686 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
6687 ungagged
= gag_free(gag
);
6690 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
6692 reply("OSMSG_UNGAG_ADDED", argv
[1]);
6696 static MODCMD_FUNC(cmd_addalert
)
6698 opserv_alert_reaction reaction
;
6699 struct svccmd
*subcmd
;
6704 sprintf(buf
, "addalert %s", argv
[2]);
6705 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6706 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6709 if (!irccasecmp(argv
[2], "notice"))
6710 reaction
= REACT_NOTICE
;
6711 else if (!irccasecmp(argv
[2], "kill"))
6712 reaction
= REACT_KILL
;
6713 else if (!irccasecmp(argv
[2], "gline"))
6714 reaction
= REACT_GLINE
;
6715 else if (!irccasecmp(argv
[2], "track")) {
6717 reply("OSMSG_TRACK_DISABLED");
6720 reaction
= REACT_TRACK
;
6722 } else if (!irccasecmp(argv
[2], "shun"))
6723 reaction
= REACT_SHUN
;
6724 else if(!irccasecmp(argv
[2], "svsjoin"))
6725 reaction
= REACT_SVSJOIN
;
6726 else if(!irccasecmp(argv
[2], "svspart"))
6727 reaction
= REACT_SVSPART
;
6728 else if(!irccasecmp(argv
[2], "version"))
6729 reaction
= REACT_VERSION
;
6730 else if(!irccasecmp(argv
[2], "mark"))
6731 reaction
= REACT_MARK
;
6733 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6736 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
6737 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
), 0)) {
6738 reply("OSMSG_ALERT_ADD_FAILED");
6741 reply("OSMSG_ADDED_ALERT", name
);
6745 static MODCMD_FUNC(cmd_delalert
)
6748 for (i
=1; i
<argc
; i
++) {
6749 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
6750 dict_remove(opserv_channel_alerts
, argv
[i
]);
6751 if (dict_remove(opserv_user_alerts
, argv
[i
]))
6752 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
6754 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
6760 opserv_conf_read(void)
6762 struct chanNode
*chan
;
6764 struct record_data
*rd
;
6765 dict_t conf_node
, child
;
6766 const char *str
, *str2
;
6767 struct policer_params
*pp
;
6770 rd
= conf_get_node(OPSERV_CONF_NAME
);
6771 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
6772 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
6775 conf_node
= rd
->d
.object
;
6776 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
6777 if (opserv
&& str
) {
6778 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
6781 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6782 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
6784 opserv_conf
.debug_channel
= NULL
;
6786 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
6787 if (opserv
&& str
) {
6788 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
6791 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6792 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
6794 opserv_conf
.alert_channel
= NULL
;
6796 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
6797 if (opserv
&& str
) {
6798 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
6801 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6802 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
6804 opserv_conf
.staff_auth_channel
= NULL
;
6807 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
6808 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
6810 str
= database_get_data(conf_node
, KEY_SILENT_LEVEL
, RECDB_QSTRING
);
6811 opserv_conf
.silent_level
= str
? strtoul(str
, NULL
, 0): 700;
6813 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
6814 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
6815 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
6816 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
6817 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
6818 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
6819 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
6820 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
6821 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
6823 NickChange(opserv
, str
, 0);
6825 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
6826 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
6827 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
6828 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
6830 free_string_list(autojoin_channels
);
6831 autojoin_channels
= database_get_data(conf_node
, KEY_AUTOJOIN_CHANNELS
, RECDB_STRING_LIST
);
6833 if(autojoin_channels
)
6834 autojoin_channels
= string_list_copy(autojoin_channels
);
6836 if (autojoin_channels
&& opserv
) {
6837 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
6838 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
6839 AddChannelUser(opserv
, chan
)->modes
|= MODE_CHANOP
;
6843 str
= database_get_data(conf_node
, KEY_BLOCK_SHUN_DURATION
, RECDB_QSTRING
);
6844 opserv_conf
.block_shun_duration
= str
? ParseInterval(str
) : 3600;
6846 if (!opserv_conf
.join_policer_params
)
6847 opserv_conf
.join_policer_params
= policer_params_new();
6848 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
6849 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
6850 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
6851 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
6853 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
6854 struct chanNode
*cNode
= iter_data(it
);
6855 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
6858 if (opserv_conf
.new_user_policer
.params
)
6859 pp
= opserv_conf
.new_user_policer
.params
;
6861 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
6862 policer_params_set(pp
, "size", "200");
6863 policer_params_set(pp
, "drain-rate", "3");
6864 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
6865 dict_foreach(child
, set_policer_param
, pp
);
6867 /* Defcon configuration */
6869 str
= database_get_data(conf_node
, KEY_DEFCON1
, RECDB_QSTRING
);
6870 DefCon
[1] = str
? atoi(str
) : 415;
6871 str
= database_get_data(conf_node
, KEY_DEFCON2
, RECDB_QSTRING
);
6872 DefCon
[2] = str
? atoi(str
) : 159;
6873 str
= database_get_data(conf_node
, KEY_DEFCON3
, RECDB_QSTRING
);
6874 DefCon
[3] = str
? atoi(str
) : 31;
6875 str
= database_get_data(conf_node
, KEY_DEFCON4
, RECDB_QSTRING
);
6876 DefCon
[4] = str
? atoi(str
) : 23;
6879 str
= database_get_data(conf_node
, KEY_DEFCON_LEVEL
, RECDB_QSTRING
);
6880 DefConLevel
= str
? atoi(str
) : 5;
6882 str
= database_get_data(conf_node
, KEY_DEFCON_CHANMODES
, RECDB_QSTRING
);
6883 DefConChanModes
= str
? strdup(str
) : "+r";
6885 str
= database_get_data(conf_node
, KEY_DEFCON_SESSION_LIMIT
, RECDB_QSTRING
);
6886 DefConSessionLimit
= str
? atoi(str
) : 2;
6888 str
= database_get_data(conf_node
, KEY_DEFCON_TIMEOUT
, RECDB_QSTRING
);
6889 DefConTimeOut
= str
? ParseInterval(str
) : 900;
6891 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_DURATION
, RECDB_QSTRING
);
6892 DefConGlineExpire
= str
? ParseInterval(str
) : 300;
6894 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL
, RECDB_QSTRING
);
6895 GlobalOnDefcon
= str
? atoi(str
) : 0;
6897 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL_MORE
, RECDB_QSTRING
);
6898 GlobalOnDefconMore
= str
? atoi(str
) : 0;
6900 str
= database_get_data(conf_node
, KEY_DEFCON_MESSAGE
, RECDB_QSTRING
);
6901 DefConMessage
= str
? strdup(str
) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore";
6903 str
= database_get_data(conf_node
, KEY_DEFCON_OFF_MESSAGE
, RECDB_QSTRING
);
6904 DefConOffMessage
= str
? strdup(str
) : "Services are now back to normal, sorry for any inconvenience";
6906 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_REASON
, RECDB_QSTRING
);
6907 DefConGlineReason
= str
? strdup(str
) : "This network is currently not accepting connections, please try again later";
6910 /* lame way to export opserv_conf value to nickserv.c ... */
6912 opserv_conf_admin_level()
6914 return(opserv_conf
.admin_level
);
6918 opserv_db_init(void) {
6919 /* set up opserv_trusted_hosts dict */
6920 dict_delete(opserv_trusted_hosts
);
6921 opserv_trusted_hosts
= dict_new();
6922 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
6924 opserv_routing_plan_options
= dict_new();
6926 opserv_routing_plans
= dict_new();
6927 dict_set_free_data(opserv_routing_plans
, free_routing_plan
);
6928 /* set up opserv_chan_warn dict */
6930 /* alert trace notice channel #x replaces warnings
6931 dict_delete(opserv_chan_warn);
6932 opserv_chan_warn = dict_new();
6933 dict_set_free_keys(opserv_chan_warn, free);
6934 dict_set_free_data(opserv_chan_warn, free);
6936 /* set up opserv_user_alerts */
6937 dict_delete(opserv_channel_alerts
);
6938 opserv_channel_alerts
= dict_new();
6939 dict_delete(opserv_nick_based_alerts
);
6940 opserv_nick_based_alerts
= dict_new();
6941 dict_delete(opserv_user_alerts
);
6942 opserv_user_alerts
= dict_new();
6943 dict_set_free_keys(opserv_user_alerts
, free
);
6944 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
6945 /* set up opserv_bad_words */
6946 free_string_list(opserv_bad_words
);
6947 opserv_bad_words
= alloc_string_list(4);
6948 /* and opserv_exempt_channels */
6949 dict_delete(opserv_exempt_channels
);
6950 opserv_exempt_channels
= dict_new();
6951 dict_set_free_keys(opserv_exempt_channels
, free
);
6955 opserv_db_cleanup(void)
6959 /* dict_delete(opserv_chan_warn); */
6960 dict_delete(opserv_reserved_nick_dict
);
6961 free_string_list(opserv_bad_words
);
6962 dict_delete(opserv_exempt_channels
);
6963 dict_delete(opserv_trusted_hosts
);
6964 unreg_del_user_func(opserv_user_cleanup
);
6965 dict_delete(opserv_hostinfo_dict
);
6966 dict_delete(opserv_nick_based_alerts
);
6967 dict_delete(opserv_channel_alerts
);
6968 dict_delete(opserv_user_alerts
);
6969 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
6970 free(level_strings
[nn
]);
6973 policer_params_delete(opserv_conf
.join_policer_params
);
6974 policer_params_delete(opserv_conf
.new_user_policer
.params
);
6978 init_opserv(const char *nick
)
6980 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
6982 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
6983 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
6985 conf_register_reload(opserv_conf_read
);
6987 memset(level_strings
, 0, sizeof(level_strings
));
6988 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
6989 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
6990 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
6991 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
6992 opserv_define_func("ADDALERT SILENT", NULL
, 900, 0, 0);
6993 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
6994 opserv_define_func("ADDALERT SHUN", NULL
, 900, 0, 0);
6995 opserv_define_func("ADDALERT TRACK", NULL
, 900, 0, 0);
6996 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
6997 opserv_define_func("ADDALERT SVSJOIN", NULL
, 999, 0, 0);
6998 opserv_define_func("ADDALERT SVSPART", NULL
, 999, 0, 0);
6999 opserv_define_func("ADDALERT VERSION", NULL
, 999, 0, 0);
7000 opserv_define_func("ADDALERT MARK", NULL
, 999, 0, 0);
7001 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
7002 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
7003 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
7004 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
7005 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
7006 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
7007 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
7008 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
7009 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
7010 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
7011 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
7012 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
7013 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
7014 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
7015 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
7016 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
7017 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
7018 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
7019 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
7020 opserv_define_func("DEFCON", cmd_defcon
, 900, 0, 0);
7021 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
7022 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
7023 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
7024 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
7025 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
7026 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
7027 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
7028 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
7029 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
7030 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
7031 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
7032 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
7033 opserv_define_func("SBLOCK", cmd_sblock
, 100, 0, 2);
7034 opserv_define_func("SHUN", cmd_shun
, 600, 0, 4);
7035 opserv_define_func("SSYNC", cmd_ssync
, 600, 0, 0);
7036 opserv_define_func("STRACE", cmd_strace
, 100, 0, 3);
7037 opserv_define_func("STRACE COUNT", NULL
, 0, 0, 0);
7038 opserv_define_func("STRACE PRINT", NULL
, 0, 0, 0);
7039 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
7040 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
7041 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
7042 opserv_define_func("SVSNICK", cmd_svsnick
, 999, 0, 3);
7043 opserv_define_func("SVSJOIN", cmd_svsjoin
, 999, 0, 3);
7044 opserv_define_func("SVSPART", cmd_svspart
, 999, 0, 3);
7045 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
7046 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
7047 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
7048 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
7049 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
7050 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
7051 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
7052 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
7053 opserv_define_func("MARK", cmd_mark
, 900, 0, 3);
7054 opserv_define_func("OP", cmd_op
, 100, 2, 2);
7055 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
7056 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
7057 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
7058 opserv_define_func("MAP", cmd_stats_links
, 0, 0, 0);
7059 opserv_define_func("PRIVSET", cmd_privset
, 900, 0, 3);
7060 opserv_define_func("PART", cmd_part
, 601, 0, 2);
7061 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
7062 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
7063 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
7064 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
7065 opserv_define_func("REFRESHS", cmd_refreshs
, 600, 0, 0);
7066 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
7067 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
7068 opserv_define_func("RESETMAX", cmd_resetmax
, 900, 0, 0);
7069 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
7070 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
7071 opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan
, 800, 0, 2);
7072 opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan
, 800, 0, 2);
7073 opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver
, 800, 0, 4);
7074 opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver
, 800, 0, 3);
7075 opserv_define_func("ROUTING MAP", cmd_routing_map
, 800, 0, 0);
7076 opserv_define_func("ROUTING SET", cmd_routing_set
, 800, 0, 0);
7077 opserv_define_func("REROUTE", cmd_reroute
, 800, 0, 2);
7078 opserv_define_func("SET", cmd_set
, 900, 0, 3);
7079 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
7080 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
7081 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
7082 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
7083 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
7084 opserv_define_func("STATS SHUNS", cmd_stats_shuns
, 0, 0, 0);
7085 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
7086 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
7087 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
7088 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
7089 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
7090 opserv_define_func("STATS ROUTING", cmd_stats_routing_plans
, 0, 0, 0);
7091 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
7092 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
7093 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
7094 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
7095 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
7096 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
7097 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
7099 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
7100 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
7101 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
7102 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
7103 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
7104 opserv_define_func("TRACE SHUN", NULL
, 600, 0, 0);
7105 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
7106 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
7107 opserv_define_func("TRACE VERSION", NULL
, 999, 0, 0);
7108 opserv_define_func("TRACE SVSJOIN", NULL
, 999, 0, 0);
7109 opserv_define_func("TRACE SVSPART", NULL
, 999, 0, 0);
7110 opserv_define_func("TRACE MARK", NULL
, 999, 0, 0);
7111 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
7112 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
7113 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
7114 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
7115 opserv_define_func("UNSHUN", cmd_unshun
, 600, 0, 2);
7116 modcmd_register(opserv_module
, "GTRACE UNSHUN", NULL
, 0, 0, "template", "unshun", NULL
);
7117 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
7118 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
7119 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
7120 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
7121 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
7122 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
7124 opserv_reserved_nick_dict
= dict_new();
7125 opserv_hostinfo_dict
= dict_new();
7127 dict_set_free_keys(opserv_hostinfo_dict
, free
);
7128 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
7130 opserv_waiting_connections
= dict_new();
7131 dict_set_free_data(opserv_waiting_connections
, opserv_free_waiting_connection
);
7133 reg_new_user_func(opserv_new_user_check
);
7134 reg_nick_change_func(opserv_alert_check_nick
);
7135 reg_del_user_func(opserv_user_cleanup
);
7136 reg_new_channel_func(opserv_channel_check
);
7137 reg_del_channel_func(opserv_channel_delete
);
7138 reg_join_func(opserv_join_check
);
7139 reg_auth_func(opserv_staff_alert
);
7140 reg_notice_func(opserv
, opserv_notice_handler
);
7143 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
7146 opserv_service
= service_register(opserv
);
7147 opserv_service
->trigger
= '?';
7150 /* start auto-routing system */
7151 /* this cant be done here, because the routing system isnt marked active yet. */
7152 /* reroute_timer(NULL); */
7154 /* start the karma timer, using the saved one if available */
7155 routing_karma_timer(dict_find(opserv_routing_plan_options
, "KARMA_TIMER", NULL
));
7157 reg_exit_func(opserv_db_cleanup
);
7158 message_register_table(msgtab
);