1 /* opserv.c - IRC Operator assistance service
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
34 #include <tre/regex.h>
36 #ifdef HAVE_SYS_TIMES_H
37 #include <sys/times.h>
39 #ifdef HAVE_NETINET_IN_H
40 #include <netinet/in.h>
42 #ifdef HAVE_ARPA_INET_H
43 #include <arpa/inet.h>
47 #define OPSERV_CONF_NAME "services/opserv"
49 #define KEY_ALERT_CHANNEL "alert_channel"
50 #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes"
51 #define KEY_DEBUG_CHANNEL "debug_channel"
52 #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes"
53 #define KEY_UNTRUSTED_MAX "untrusted_max"
54 #define KEY_PURGE_LOCK_DELAY "purge_lock_delay"
55 #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate"
56 #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold"
57 #define KEY_NICK "nick"
58 #define KEY_JOIN_POLICER "join_policer"
59 #define KEY_NEW_USER_POLICER "new_user_policer"
60 #define KEY_AUTOJOIN_CHANNELS "autojoin_channels"
61 #define KEY_REASON "reason"
62 #define KEY_RESERVES "reserves"
63 #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */
64 #define KEY_HOSTNAME "hostname"
65 #define KEY_DESC "description"
66 #define KEY_BAD_WORDS "bad"
67 #define KEY_EXEMPT_CHANNELS "exempt"
68 #define KEY_SECRET_WORDS "secret"
69 #define KEY_TRUSTED_HOSTS "trusted"
70 #define KEY_OWNER "owner"
71 #define KEY_GAGS "gags"
72 #define KEY_ALERTS "alerts"
73 #define KEY_REACTION "reaction"
74 #define KEY_DISCRIM "discrim"
75 #define KEY_WARN "chanwarn"
77 #define KEY_TIME "time"
78 #define KEY_MAX_CLIENTS "max_clients"
79 #define KEY_LIMIT "limit"
80 #define KEY_EXPIRES "expires"
81 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
82 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
83 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
84 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
85 #define KEY_BLOCK_SHUN_DURATION "block_shun_duration"
86 #define KEY_ISSUER "issuer"
87 #define KEY_ISSUED "issued"
88 #define KEY_ADMIN_LEVEL "admin_level"
89 #define KEY_SILENT_LEVEL "silent_level"
90 #define KEY_UPLINK "uplink"
91 #define KEY_SECOND "secondaryuplink"
92 #define KEY_PORT "port"
93 #define KEY_KARMA "karma"
94 #define KEY_OFFLINE "offline"
95 #define KEY_ROUTINGPLAN "routingplan"
96 #define KEY_ROUTINGPLAN_OPTIONS "routingplan_options"
97 #define KEY_DEFCON1 "DefCon1"
98 #define KEY_DEFCON2 "DefCon2"
99 #define KEY_DEFCON3 "DefCon3"
100 #define KEY_DEFCON4 "DefCon4"
101 #define KEY_DEFCON_LEVEL "DefConLevel"
102 #define KEY_DEFCON_CHANMODES "DefConChanModes"
103 #define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit"
104 #define KEY_DEFCON_TIMEOUT "DefConTimeOut"
105 #define KEY_DEFCON_GLOBAL "GlobalOnDefcon"
106 #define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore"
107 #define KEY_DEFCON_MESSAGE "DefconMessage"
108 #define KEY_DEFCON_OFF_MESSAGE "DefConOffMessage"
109 #define KEY_DEFCON_GLINE_DURATION "DefConGlineExpire"
110 #define KEY_DEFCON_GLINE_REASON "DefConGlineReason"
112 /* Routing karma values: */
113 /* What value we start out with when new servers are added: */
114 #define KARMA_DEFAULT 10
117 #define KARMA_MIN -10
118 /* ping out, reduce karma by this much: */
119 #define KARMA_PINGOUT -8
120 /* read err, reduce karma by this much: */
121 #define KARMA_READERROR -5
122 /* every 24 hours everyone gets this much added (so we eventually re-try bad servers) */
123 #define KARMA_ENTROPE 1
124 /* every 24 hours servers linked for 24 hours get an additional ammount: */
125 #define KARMA_RELIABLE 1
126 /* How often to run entrope and reliable checks */
127 #define KARMA_TIMER 86400 /* 1 day */
129 #define ROUTING_CONNECT_TIMEOUT 30 /* 30 seconds */
131 #define IDENT_FORMAT "%s [%s@%s/%s]"
132 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, irc_ntoa(&user->ip)
133 #define MAX_CHANNELS_WHOIS 50
134 #define OSMSG_PART_REASON "%s has no reason."
135 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
136 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
137 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
139 static const struct message_entry msgtab
[] = {
140 { "OSMSG_BAR", "----------------------------------------" },
141 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
142 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
143 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
144 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
145 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
146 { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." },
147 { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." },
148 { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." },
149 { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." },
150 { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." },
151 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
152 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
153 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
154 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
155 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
156 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
157 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
158 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
159 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
160 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
161 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
162 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
163 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
164 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
165 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
166 { "OSMSG_NOT_THERE", "You not in $b%s$b." },
167 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
168 { "OSMSG_MARK_SET", "Set the MARK." },
169 { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." },
170 { "OSMSG_SVSPART_SENT", "Sent the SVSPART." },
171 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
172 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
173 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
174 { "OSMSG_LEAVING", "Leaving $b%s$b." },
175 { "OSMSG_MARK_INVALID", "Sorry, marks must contain only letters, numbers, and dashes ('-')." },
176 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
177 { "OSMSG_OP_DONE", "Opped the requested lusers." },
178 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
179 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
180 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
181 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
182 { "OSMSG_WHOIS_NICK", "Nick : %s" },
183 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
184 { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" },
185 { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" },
186 { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" },
187 { "OSMSG_WHOIS_IP", "Real IP : %s" },
188 { "OSMSG_WHOIS_COUNTRY", "Country : %s" },
189 { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" },
190 { "OSMSG_WHOIS_CITY", "City : %s" },
191 { "OSMSG_WHOIS_REGION", "Region/State : %s" },
192 { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" },
193 { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" },
194 { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" },
195 { "OSMSG_WHOIS_MAP", "Map : %s" },
196 { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" },
197 { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" },
198 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
199 { "OSMSG_WHOIS_INFO", "Info : %s" },
200 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
201 { "OSMSG_WHOIS_SERVER", "Server : %s" },
202 { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" },
203 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
204 { "OSMSG_WHOIS_PRIVS", "IRCd Privs : %s" },
205 { "OSMSG_WHOIS_CHANNELS", "Channels : %s" },
206 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
207 { "OSMSG_WHOIS_VERSION", "Version : %s" },
208 { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" },
209 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
210 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
211 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
212 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
213 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
214 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
215 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
216 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
217 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
218 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
219 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
220 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
221 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
222 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
223 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
224 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
225 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
226 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
227 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
228 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
229 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
230 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
231 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
232 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
233 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
234 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
235 { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." },
236 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
237 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
238 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
239 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
240 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
241 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
242 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
243 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
244 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
245 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
246 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
247 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
248 { "OSMSG_LINE_DUMPED", "Raw line sent." },
249 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
250 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
251 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
252 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
253 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
254 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
255 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
256 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
257 { "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." },
258 { "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." },
259 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
260 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
261 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
262 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
263 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
264 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
265 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
266 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
267 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
268 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
269 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
270 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
271 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
272 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
273 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
274 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
275 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
276 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
277 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
278 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
279 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
280 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
281 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
282 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
283 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
284 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
285 { "OSMSG_MARK_NO_MARK", "MARK action requires mark criteria (what do you want to mark them as?)" },
286 { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" },
287 { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" },
288 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
289 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
290 { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" },
291 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
292 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
293 { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
294 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
295 { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
296 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
297 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
298 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
299 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
300 { "OSMSG_NO_GAGS", "No gags have been set." },
301 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
302 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
303 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
304 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
305 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
306 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
307 { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" },
308 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
309 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
310 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" },
311 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
312 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
313 { "OSMSG_ALERTS_DESC", " Criteria: %s" },
314 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
315 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
316 /* routing messages */
317 { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" },
318 { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" },
319 { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" },
320 { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" },
321 { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" },
322 { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." },
323 { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." },
324 { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." },
325 { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." },
326 { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" },
327 { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" },
328 { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" },
329 { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." },
330 { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." },
331 { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." },
332 { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." },
333 { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." },
334 { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." },
335 { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." },
336 { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." },
337 { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." },
338 { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" },
339 { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" },
340 { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" },
341 { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" },
342 { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" },
343 { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." },
344 { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." },
345 { "OSMSG_CONNECT", "->connect %s %d %s" },
346 { "OSMSG_SQUIT", "->squit %s" },
347 { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" },
348 { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" },
349 { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." },
350 { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." },
351 { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." },
352 { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." },
353 { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." },
354 { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", },
355 { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." },
356 { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." },
358 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
359 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
360 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
361 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
362 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
363 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
364 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
365 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
366 { "OSMSG_INVALID_NUMERIC", "Invalid numeric" },
367 { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." },
368 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
369 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
371 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
372 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
373 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
374 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
375 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
376 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
377 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
379 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
380 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
381 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
382 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
383 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
384 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
385 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
386 { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." },
387 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
388 { "OSMSG_CHANINFO_HEADER", "%s Information" },
389 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
390 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
391 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
392 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
393 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
394 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
395 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
396 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
397 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
398 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
399 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
400 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
401 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
402 { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" },
403 { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" },
405 { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" },
406 { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" },
407 { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" },
408 { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" },
409 { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" },
410 { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" },
411 { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" },
412 { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" },
413 { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" },
414 { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" },
415 { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" },
416 { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" },
417 { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" },
418 { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" },
420 { "OSMSG_PRIV_UNKNOWN", "Unknown privilege flag %s, see /msg $O HELP PRIVFLAGS for a flag list" },
421 { "OSMSG_PRIV_SET", "Privilege flag %s has been %sset" },
426 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
431 int GlobalOnDefcon
= 0;
432 int GlobalOnDefconMore
= 0;
433 int DefConGlineExpire
;
434 int DefConModesSet
= 0;
435 unsigned int DefConSessionLimit
;
436 char *DefConChanModes
;
437 char *DefConGlineReason
;
439 char *DefConOffMessage
;
441 extern void add_track_user(struct userNode
*user
);
442 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
444 struct userNode
*opserv
;
445 static struct service
*opserv_service
;
447 /*static dict_t opserv_chan_warn; */ /* data is char* */
448 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
449 static struct string_list
*opserv_bad_words
;
450 static dict_t opserv_exempt_channels
; /* data is not used */
451 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
452 static dict_t opserv_routing_plans
; /* data is struct routingPlan */
453 static dict_t opserv_routing_plan_options
; /* data is a dict_t key->val list*/
454 static dict_t opserv_waiting_connections
; /* data is struct waitingConnection */
455 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
456 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
457 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
458 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
459 static struct module *opserv_module
;
460 static struct log_type
*OS_LOG
;
461 static unsigned int new_user_flood
;
462 static char *level_strings
[1001];
463 struct string_list
*autojoin_channels
;
464 struct route
*opserv_route
= NULL
; /* Main active routing table from activate_routing()*/
467 struct chanNode
*debug_channel
;
468 struct chanNode
*alert_channel
;
469 struct chanNode
*staff_auth_channel
;
470 struct policer_params
*join_policer_params
;
471 struct policer new_user_policer
;
472 unsigned long untrusted_max
;
473 unsigned long clone_gline_duration
;
474 unsigned long block_gline_duration
;
475 unsigned long block_shun_duration
;
476 unsigned long purge_lock_delay
;
477 unsigned long join_flood_moderate
;
478 unsigned long join_flood_moderate_threshold
;
479 unsigned long admin_level
;
480 unsigned long silent_level
;
483 struct trusted_host
{
497 struct gag_entry
*next
;
500 static struct gag_entry
*gagList
;
502 struct opserv_hostinfo
{
503 struct userList clients
;
504 struct trusted_host
*trusted
;
508 opserv_free_hostinfo(void *data
)
510 struct opserv_hostinfo
*ohi
= data
;
511 userList_clean(&ohi
->clients
);
516 opserv_free_waiting_connection(void *data
)
518 struct waitingConnection
*wc
= data
;
524 typedef struct opservDiscrim
{
525 struct chanNode
*channel
;
526 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *mask_version
, *server
, *reason
, *accountmask
, *chantarget
, *mark
;
527 irc_in_addr_t ip_mask
;
529 time_t min_ts
, max_ts
;
530 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
, regex_version
;
531 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1, has_regex_version
: 1;
532 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
533 unsigned char ip_mask_bits
;
534 unsigned int match_opers
: 1, option_log
: 1;
535 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
536 int authed
: 2, info_space
: 2;
537 unsigned int intra_scmp
: 2, intra_dcmp
: 2;
538 unsigned int use_regex
: 1;
539 unsigned int silent
: 1;
542 struct discrim_and_source
{
544 struct userNode
*source
;
545 struct userNode
*destination
;
547 unsigned int disp_limit
;
550 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
551 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
552 static int gag_helper_func(struct userNode
*match
, void *extra
);
553 static int ungag_helper_func(struct userNode
*match
, void *extra
);
565 } opserv_alert_reaction
;
567 struct opserv_user_alert
{
569 char *text_discrim
, *split_discrim
;
571 opserv_alert_reaction reaction
;
574 /* funny type to make it acceptible to dict_set_free_data, far below */
576 opserv_free_user_alert(void *data
)
578 struct opserv_user_alert
*alert
= data
;
579 if (alert
->discrim
->channel
)
580 UnlockChannel(alert
->discrim
->channel
);
582 free(alert
->text_discrim
);
583 free(alert
->split_discrim
);
584 if(alert
->discrim
->has_regex_nick
)
585 regfree(&alert
->discrim
->regex_nick
);
586 if(alert
->discrim
->has_regex_ident
)
587 regfree(&alert
->discrim
->regex_ident
);
588 if(alert
->discrim
->has_regex_host
)
589 regfree(&alert
->discrim
->regex_host
);
590 if(alert
->discrim
->has_regex_info
)
591 regfree(&alert
->discrim
->regex_info
);
592 if(alert
->discrim
->has_regex_version
)
593 regfree(&alert
->discrim
->regex_version
);
594 free(alert
->discrim
->reason
);
595 free(alert
->discrim
);
599 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
600 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
603 char *defconReverseModes(const char *modes
)
605 char *newmodes
= NULL
;
610 if (!(newmodes
= malloc(sizeof(char) * strlen(modes
) + 1))) {
613 for (i
= 0; i
< strlen(modes
); i
++) {
616 else if (modes
[i
] == '-')
619 newmodes
[i
] = modes
[i
];
625 int checkDefCon(int level
)
627 return DefCon
[DefConLevel
] & level
;
630 void showDefConSettings(struct userNode
*user
, struct svccmd
*cmd
)
632 if (DefConLevel
== 5) {
633 reply("OSMSG_DEFCON_ALLOWING_ALL");
636 reply("OSMSG_DEFCON_DISALLOWING", DefConLevel
);
638 if (checkDefCon(DEFCON_NO_NEW_CHANNELS
))
639 reply("OSMSG_DEFCON_NO_NEW_CHANNELS");
641 if (checkDefCon(DEFCON_NO_NEW_NICKS
))
642 reply("OSMSG_DEFCON_NO_NEW_NICKS");
644 if (checkDefCon(DEFCON_NO_MODE_CHANGE
))
645 reply("OSMSG_DEFCON_NO_MODE_CHANGE");
647 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
) && (DefConChanModes
))
648 reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes
);
650 if (checkDefCon(DEFCON_REDUCE_SESSION
))
651 reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit
);
653 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
))
654 reply("OSMSG_DEFCON_NO_NEW_CLIENTS");
656 if (checkDefCon(DEFCON_OPER_ONLY
))
657 reply("OSMSG_DEFCON_OPER_ONLY");
659 if (checkDefCon(DEFCON_SILENT_OPER_ONLY
))
660 reply("OSMSG_DEFCON_SILENT_OPER_ONLY");
662 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
663 reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS");
665 if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
666 reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS");
668 if (checkDefCon(DEFCON_NO_NEW_MEMOS
))
669 reply("OSMSG_DEFCON_NO_NEW_MEMOS");
674 void do_mass_mode(char *modes
)
681 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
682 struct chanNode
*chan
= iter_data(it
);
684 irc_mode(opserv
, chan
, modes
);
689 void DefConProcess(struct userNode
*user
)
694 global_message_args(MESSAGE_RECIPIENT_LUSERS
, "DEFCON_NETWORK_CHANGED", DefConLevel
);
696 if (GlobalOnDefconMore
&& GlobalOnDefcon
)
697 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConMessage
);
699 if ((DefConLevel
== 5) && !GlobalOnDefconMore
&& !GlobalOnDefcon
)
700 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConOffMessage
);
703 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_OPER_LEVEL_CHANGE", user
->nick
, DefConLevel
);
705 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel
);
707 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
)) {
708 if (DefConChanModes
&& !DefConModesSet
) {
709 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
710 do_mass_mode(DefConChanModes
);
715 if (DefConChanModes
&& (DefConModesSet
!= 0)) {
716 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
717 if ((newmodes
= defconReverseModes(DefConChanModes
))) {
718 do_mass_mode(newmodes
);
730 defcon_timeout(UNUSED_ARG(void *data
))
736 static MODCMD_FUNC(cmd_defcon
)
738 if ((argc
< 2) || (atoi(argv
[1]) == DefConLevel
)) {
739 showDefConSettings(user
, cmd
);
743 if ((atoi(argv
[1]) < 1) || (atoi(argv
[1]) > 5)) {
744 reply("OSMSG_DEFCON_INVALID", atoi(argv
[1]));
748 DefConLevel
= atoi(argv
[1]);
749 showDefConSettings(user
, cmd
);
751 if (DefConTimeOut
> 0) {
752 timeq_del(0, defcon_timeout
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
753 timeq_add(now
+ DefConTimeOut
, defcon_timeout
, NULL
);
761 static MODCMD_FUNC(cmd_privallow)
763 //privallow servername/username +/-flag (global is set in conf)
766 static MODCMD_FUNC(cmd_privdissallow)
768 //privdisallow servername/username +/-flag (global is set in conf)
771 static MODCMD_FUNC(cmd_privlist)
773 //privlist servername/user (global with none)
777 static MODCMD_FUNC(cmd_privset
)
779 struct userNode
*target
;
787 } else if (*flag
== '+') {
792 target
= GetUserH(argv
[1]);
794 reply("MSG_NICK_UNKNOWN", argv
[1]);
798 if (check_priv(flag
)) {
799 irc_privs(target
, flag
, add
);
800 reply("OSMSG_PRIV_SET", argv
[2], (add
== 1) ? "" : "un");
802 reply("OSMSG_PRIV_UNKNOWN", argv
[2]);
809 /* A lot of these commands are very similar to what ChanServ can do,
810 * but OpServ can do them even on channels that aren't registered.
813 static MODCMD_FUNC(cmd_access
)
815 struct handle_info
*hi
;
819 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
820 if (!irccasecmp(target
, "*")) {
821 nickserv_show_oper_accounts(user
, cmd
);
824 if (!(hi
= modcmd_get_handle_info(user
, target
)))
826 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
827 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
831 static MODCMD_FUNC(cmd_ban
)
833 struct mod_chanmode change
;
834 struct userNode
*victim
;
836 mod_chanmode_init(&change
);
838 change
.args
[0].mode
= MODE_BAN
;
839 if (is_ircmask(argv
[1]))
840 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
841 else if ((victim
= GetUserH(argv
[1])))
842 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
844 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
847 modcmd_chanmode_announce(&change
);
848 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
849 free((char*)change
.args
[0].u
.hostmask
);
853 static MODCMD_FUNC(cmd_chaninfo
)
858 struct exemptNode
*exempt
;
859 struct modeNode
*moden
;
862 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
863 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
864 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
865 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
866 irc_make_chanmode(channel
, buffer
);
867 if (channel
->bad_channel
)
868 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
870 reply("OSMSG_CHANINFO_MODES", buffer
);
871 if (channel
->topic_time
) {
872 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
873 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
874 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
876 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
877 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
879 if (channel
->banlist
.used
) {
880 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
881 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
882 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
883 ban
= channel
->banlist
.list
[n
];
884 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
885 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
888 if (channel
->exemptlist
.used
) {
889 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
890 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
891 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
892 exempt
= channel
->exemptlist
.list
[n
];
893 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
894 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
897 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
898 /* early out unless they ask for users */
899 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
902 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
903 for (n
=0; n
<channel
->members
.used
; n
++) {
904 moden
= channel
->members
.list
[n
];
905 if (moden
->modes
& MODE_CHANOP
) {
906 if (moden
->oplevel
>= 0)
907 send_message_type(4, user
, cmd
->parent
->bot
, " @%s:%d (%s@%s)", moden
->user
->nick
, moden
->oplevel
, moden
->user
->ident
, moden
->user
->hostname
);
909 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
912 for (n
=0; n
<channel
->members
.used
; n
++) {
913 moden
= channel
->members
.list
[n
];
914 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
915 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
917 for (n
=0; n
<channel
->members
.used
; n
++) {
918 moden
= channel
->members
.list
[n
];
919 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
920 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
922 for (n
=0; n
<channel
->members
.used
; n
++) {
923 moden
= channel
->members
.list
[n
];
924 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
925 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
930 /* This command has been replaced by 'alert notice channel #foo' */
932 static MODCMD_FUNC(cmd_warn)
934 char *reason, *message;
936 if (!IsChannelName(argv[1])) {
937 reply("OSMSG_NEED_CHANNEL", argv[0]);
940 reason = dict_find(opserv_chan_warn, argv[1], NULL);
942 reply("OSMSG_WARN_EXISTS", argv[1]);
946 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
948 reason = strdup("No reason");
949 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
950 reply("OSMSG_WARN_ADDED", argv[1], reason);
951 if (dict_find(channels, argv[1], NULL)) {
952 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason);
957 static MODCMD_FUNC(cmd_unwarn)
959 if ((argc < 2) || !IsChannelName(argv[1])) {
960 reply("OSMSG_NEED_CHANNEL", argv[0]);
963 if (!dict_remove(opserv_chan_warn, argv[1])) {
964 reply("OSMSG_WARN_NOEXIST", argv[1]);
967 reply("OSMSG_WARN_DELETED", argv[1]);
972 static MODCMD_FUNC(cmd_clearbans
)
974 struct mod_chanmode
*change
;
977 change
= mod_chanmode_alloc(channel
->banlist
.used
);
978 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
979 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
980 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
982 modcmd_chanmode_announce(change
);
983 for (ii
=0; ii
<change
->argc
; ++ii
)
984 free((char*)change
->args
[ii
].u
.hostmask
);
985 mod_chanmode_free(change
);
986 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
990 static MODCMD_FUNC(cmd_clearmodes
)
992 struct mod_chanmode change
;
994 if (!channel
->modes
) {
995 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
998 mod_chanmode_init(&change
);
999 change
.modes_clear
= channel
->modes
;
1000 modcmd_chanmode_announce(&change
);
1001 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
1005 static MODCMD_FUNC(cmd_deop
)
1007 struct mod_chanmode
*change
;
1008 unsigned int arg
, count
;
1010 change
= mod_chanmode_alloc(argc
-1);
1011 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1012 struct userNode
*victim
= GetUserH(argv
[arg
]);
1013 struct modeNode
*mn
;
1014 if (!victim
|| IsService(victim
)
1015 || !(mn
= GetUserMode(channel
, victim
))
1016 || !(mn
->modes
& MODE_CHANOP
))
1018 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1019 change
->args
[count
++].u
.member
= mn
;
1022 change
->argc
= count
;
1023 modcmd_chanmode_announce(change
);
1025 mod_chanmode_free(change
);
1026 reply("OSMSG_DEOP_DONE");
1030 static MODCMD_FUNC(cmd_dehop
)
1032 struct mod_chanmode
*change
;
1033 unsigned int arg
, count
;
1035 change
= mod_chanmode_alloc(argc
-1);
1036 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1037 struct userNode
*victim
= GetUserH(argv
[arg
]);
1038 struct modeNode
*mn
;
1039 if (!victim
|| IsService(victim
)
1040 || !(mn
= GetUserMode(channel
, victim
))
1041 || !(mn
->modes
& MODE_HALFOP
))
1043 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1044 change
->args
[count
++].u
.member
= mn
;
1047 change
->argc
= count
;
1048 modcmd_chanmode_announce(change
);
1050 mod_chanmode_free(change
);
1051 reply("OSMSG_DEHOP_DONE");
1055 static MODCMD_FUNC(cmd_deopall
)
1057 struct mod_chanmode
*change
;
1058 unsigned int ii
, count
;
1060 change
= mod_chanmode_alloc(channel
->members
.used
);
1061 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1062 struct modeNode
*mn
= channel
->members
.list
[ii
];
1063 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
1065 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1066 change
->args
[count
++].u
.member
= mn
;
1069 change
->argc
= count
;
1070 modcmd_chanmode_announce(change
);
1072 mod_chanmode_free(change
);
1073 reply("OSMSG_DEOPALL_DONE", channel
->name
);
1077 static MODCMD_FUNC(cmd_dehopall
)
1079 struct mod_chanmode
*change
;
1080 unsigned int ii
, count
;
1082 change
= mod_chanmode_alloc(channel
->members
.used
);
1083 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1084 struct modeNode
*mn
= channel
->members
.list
[ii
];
1085 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
1087 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1088 change
->args
[count
++].u
.member
= mn
;
1091 change
->argc
= count
;
1092 modcmd_chanmode_announce(change
);
1094 mod_chanmode_free(change
);
1095 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
1099 static MODCMD_FUNC(cmd_resetmax
)
1101 max_clients
= dict_size(clients
);
1102 max_clients_time
= now
;
1103 reply("OSMSG_MAXUSERS_RESET", max_clients
);
1107 static MODCMD_FUNC(cmd_rehash
)
1109 extern char *services_config
;
1111 if (conf_read(services_config
))
1112 reply("OSMSG_REHASH_COMPLETE");
1114 reply("OSMSG_REHASH_FAILED");
1118 static MODCMD_FUNC(cmd_reopen
)
1121 reply("OSMSG_REOPEN_COMPLETE");
1125 static MODCMD_FUNC(cmd_reconnect
)
1127 reply("OSMSG_RECONNECTING");
1128 irc_squit(self
, "Reconnecting.", NULL
);
1132 static MODCMD_FUNC(cmd_jupe
)
1134 extern int force_n2k
;
1135 struct server
*newsrv
;
1137 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
1139 num
= atoi(argv
[2]);
1141 reply("OSMSG_INVALID_NUMERIC");
1144 if ((num
< 64) && !force_n2k
) {
1145 inttobase64(numeric
, num
, 1);
1146 inttobase64(numeric
+1, 64*64-1, 2);
1148 inttobase64(numeric
, num
, 2);
1149 inttobase64(numeric
+2, 64*64*64-1, 3);
1151 #ifdef WITH_PROTOCOL_P10
1152 if (GetServerN(numeric
)) {
1153 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
1157 if (GetServerH(argv
[1])) {
1158 reply("OSMSG_NAME_COLLIDE");
1161 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
1162 if(!strchr(argv
[1], '.')) {
1163 reply("OSMSG_INVALID_SERVERNAME");
1166 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
1168 reply("OSMSG_SRV_CREATE_FAILED");
1172 reply("OSMSG_SERVER_JUPED", argv
[1]);
1176 static MODCMD_FUNC(cmd_unjupe
)
1181 srv
= GetServerH(argv
[1]);
1183 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1186 if (strncmp(srv
->description
, "JUPE", 4)) {
1187 reply("OSMSG_SERVER_NOT_JUPE");
1190 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
1191 DelServer(srv
, 1, reason
);
1192 reply("OSMSG_SERVER_UNJUPED");
1196 static MODCMD_FUNC(cmd_jump
)
1198 extern struct cManagerNode cManager
;
1199 void uplink_select(char *name
);
1200 struct uplinkNode
*uplink_find(char *name
);
1201 struct uplinkNode
*uplink
;
1204 target
= unsplit_string(argv
+1, argc
-1, NULL
);
1206 if (!strcmp(cManager
.uplink
->name
, target
)) {
1207 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
1211 uplink
= uplink_find(target
);
1213 reply("OSMSG_INVALID_UPLINK", target
);
1216 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
1217 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
1221 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
1222 uplink_select(target
);
1223 irc_squit(self
, "Reconnecting.", NULL
);
1227 static MODCMD_FUNC(cmd_die
)
1229 char *reason
, *text
;
1231 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1232 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
1233 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
1234 irc_squit(self
, reason
, text
);
1239 static MODCMD_FUNC(cmd_restart
)
1241 extern int services_argc
;
1242 extern char **services_argv
;
1243 char **restart_argv
, *reason
, *text
;
1245 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1246 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
1247 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
1248 irc_squit(self
, reason
, text
);
1250 /* Append a NULL to the end of argv[]. */
1251 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
1252 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
1253 restart_argv
[services_argc
] = NULL
;
1258 execv(services_argv
[0], restart_argv
);
1260 /* If we're still here, that means something went wrong. Reconnect. */
1264 static struct gline
*
1265 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
, int silent
)
1267 char mask
[IRC_NTOP_MAX_SIZE
+3] = { '*', '@', '\0' };
1268 irc_ntop(mask
+ 2, sizeof(mask
) - 2, &target
->ip
);
1270 snprintf(reason
= alloca(MAXLEN
), MAXLEN
,
1271 "G-line requested by %s.", src_handle
);
1273 duration
= opserv_conf
.block_gline_duration
;
1274 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1, silent
? 1 : 0);
1277 static MODCMD_FUNC(cmd_block
)
1279 struct userNode
*target
;
1280 struct gline
*gline
;
1283 target
= GetUserH(argv
[1]);
1285 reply("MSG_NICK_UNKNOWN", argv
[1]);
1288 if (IsService(target
)) {
1289 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1292 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1293 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0, 0);
1294 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1298 static MODCMD_FUNC(cmd_gline
)
1300 unsigned long duration
;
1302 struct gline
*gline
;
1304 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1305 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1306 reply("MSG_INVALID_GLINE", argv
[1]);
1309 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1310 reply("OSMSG_STUPID_GLINE", argv
[1]);
1313 duration
= ParseInterval(argv
[2]);
1315 reply("MSG_INVALID_DURATION", argv
[2]);
1318 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1, 0);
1319 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1323 static MODCMD_FUNC(cmd_ungline
)
1325 if (gline_remove(argv
[1], 1))
1326 reply("OSMSG_GLINE_REMOVED", argv
[1]);
1328 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
1332 static MODCMD_FUNC(cmd_refreshg
)
1339 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1340 srv
= iter_data(it
);
1341 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1343 gline_refresh_server(srv
);
1344 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
1348 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1352 gline_refresh_all();
1353 reply("OSMSG_GLINES_REFRESHED");
1359 opserv_version(struct userNode
*target
)
1361 irc_version_user(opserv
, target
);
1365 opserv_mark(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *mark
)
1369 irc_mark(target
, mark
);
1373 opserv_svsjoin(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
)
1375 struct chanNode
*channel
;
1377 if(!channame
|| !IsChannelName(channame
)) {
1378 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1382 if (!(channel
= GetChannel(channame
))) {
1383 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
1385 if (GetUserMode(channel
, target
)) {
1390 irc_svsjoin(opserv
, target
, channel
);
1391 /* Should we tell the user they got joined? -Rubin*/
1395 opserv_svspart(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
)
1397 struct chanNode
*channel
;
1399 if(!channame
|| !IsChannelName(channame
)) {
1400 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1404 if (!(channel
= GetChannel(channame
))) {
1405 /* channel doesnt exist */
1409 if (!GetUserMode(channel
, target
)) {
1414 irc_svspart(opserv
, target
, channel
);
1417 static struct shun
*
1418 opserv_shun(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
1421 mask
= alloca(MAXLEN
);
1422 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
1424 reason
= alloca(MAXLEN
);
1425 snprintf(reason
, MAXLEN
, "Shun requested by %s.", src_handle
);
1427 if (!duration
) duration
= opserv_conf
.block_shun_duration
;
1428 return shun_add(src_handle
, mask
, duration
, reason
, now
, 1);
1431 static MODCMD_FUNC(cmd_sblock
)
1433 struct userNode
*target
;
1437 target
= GetUserH(argv
[1]);
1439 reply("MSG_NICK_UNKNOWN", argv
[1]);
1442 if (IsService(target
)) {
1443 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1446 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1447 shun
= opserv_shun(target
, user
->handle_info
->handle
, reason
, 0);
1448 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1452 static MODCMD_FUNC(cmd_shun
)
1454 unsigned long duration
;
1458 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1459 if (!is_shun(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1460 reply("MSG_INVALID_SHUN", argv
[1]);
1463 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1464 reply("OSMSG_STUPID_SHUN", argv
[1]);
1467 duration
= ParseInterval(argv
[2]);
1469 reply("MSG_INVALID_DURATION", argv
[2]);
1472 shun
= shun_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
1473 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1477 static MODCMD_FUNC(cmd_unshun
)
1479 if (shun_remove(argv
[1], 1))
1480 reply("OSMSG_SHUN_REMOVED", argv
[1]);
1482 reply("OSMSG_SHUN_FORCE_REMOVED", argv
[1]);
1486 static MODCMD_FUNC(cmd_refreshs
)
1493 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1494 srv
= iter_data(it
);
1495 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1497 shun_refresh_server(srv
);
1498 reply("OSMSG_SHUNS_ONE_REFRESHED", srv
->name
);
1502 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1507 reply("OSMSG_SHUNS_REFRESHED");
1513 opserv_ison(struct userNode
*bot
, struct userNode
*tell
, struct userNode
*target
, const char *message
)
1515 struct modeNode
*mn
;
1516 unsigned int count
, here_len
, n
, maxlen
;
1519 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
1521 maxlen
= MAX_LINE_SIZE
;
1522 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
1523 mn
= target
->channels
.list
[n
];
1524 here_len
= strlen(mn
->channel
->name
);
1525 if ((count
+ here_len
+ 4) > maxlen
) {
1527 send_message(tell
, bot
, message
, buff
);
1530 if (mn
->modes
& MODE_CHANOP
)
1531 buff
[count
++] = '@';
1532 if (mn
->modes
& MODE_HALFOP
)
1533 buff
[count
++] = '%';
1534 if (mn
->modes
& MODE_VOICE
)
1535 buff
[count
++] = '+';
1536 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
1538 buff
[count
++] = ' ';
1542 send_message(tell
, bot
, message
, buff
);
1546 static MODCMD_FUNC(cmd_inviteme
)
1548 struct userNode
*target
;
1553 target
= GetUserH(argv
[1]);
1555 reply("MSG_NICK_UNKNOWN", argv
[1]);
1559 if (opserv_conf
.debug_channel
== NULL
) {
1560 reply("OSMSG_NO_DEBUG_CHANNEL");
1563 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
1564 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1567 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1569 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1573 static MODCMD_FUNC(cmd_invite
)
1575 if (GetUserMode(channel
, user
)) {
1576 reply("OSMSG_ALREADY_THERE", channel
->name
);
1579 irc_invite(cmd
->parent
->bot
, user
, channel
);
1583 static MODCMD_FUNC(cmd_svsjoin
)
1585 struct userNode
*target
;
1588 if(!IsChannelName(argv
[2])) {
1589 reply("MSG_NOT_CHANNEL_NAME");
1592 target
= GetUserH(argv
[1]);
1594 reply("MSG_NICK_UNKNOWN", argv
[1]);
1598 if (!(channel
= GetChannel(argv
[2]))) {
1599 channel
= AddChannel(argv
[2], now
, NULL
, NULL
, NULL
);
1601 if (GetUserMode(channel
, target
)) {
1602 reply("OSMSG_ALREADY_THERE", channel
->name
);
1605 irc_svsjoin(opserv
, target
, channel
);
1606 reply("OSMSG_SVSJOIN_SENT");
1610 static MODCMD_FUNC(cmd_join
)
1612 struct userNode
*bot
= cmd
->parent
->bot
;
1614 if (!IsChannelName(argv
[1])) {
1615 reply("MSG_NOT_CHANNEL_NAME");
1617 } else if (!(channel
= GetChannel(argv
[1]))) {
1618 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1619 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1620 } else if (GetUserMode(channel
, bot
)) {
1621 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1624 struct mod_chanmode change
;
1625 mod_chanmode_init(&change
);
1627 change
.args
[0].mode
= MODE_CHANOP
;
1628 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1629 modcmd_chanmode_announce(&change
);
1631 irc_fetchtopic(bot
, channel
->name
);
1632 reply("OSMSG_JOIN_DONE", channel
->name
);
1636 static MODCMD_FUNC(cmd_kick
)
1638 struct userNode
*target
;
1642 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1643 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1645 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1647 target
= GetUserH(argv
[1]);
1649 reply("MSG_NICK_UNKNOWN", argv
[1]);
1652 if (!GetUserMode(channel
, target
)) {
1653 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1656 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1660 static MODCMD_FUNC(cmd_kickall
)
1662 unsigned int limit
, n
, inchan
;
1663 struct modeNode
*mn
;
1665 struct userNode
*bot
= cmd
->parent
->bot
;
1667 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1668 * channel, we have to join it in temporarily. */
1669 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1670 struct mod_chanmode change
;
1671 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
);
1677 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1678 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1680 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1682 limit
= user
->handle_info
->opserv_level
;
1683 for (n
=channel
->members
.used
; n
>0;) {
1684 mn
= channel
->members
.list
[--n
];
1685 if (IsService(mn
->user
)
1686 || (mn
->user
->handle_info
1687 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1690 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1693 DelChannelUser(bot
, channel
, "My work here is done", 0);
1694 reply("OSMSG_KICKALL_DONE", channel
->name
);
1698 static MODCMD_FUNC(cmd_kickban
)
1700 struct mod_chanmode change
;
1701 struct userNode
*target
;
1706 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1707 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1709 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1711 target
= GetUserH(argv
[1]);
1713 reply("MSG_NICK_UNKNOWN", argv
[1]);
1716 if (!GetUserMode(channel
, target
)) {
1717 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1720 mod_chanmode_init(&change
);
1722 change
.args
[0].mode
= MODE_BAN
;
1723 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1724 modcmd_chanmode_announce(&change
);
1725 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1730 static MODCMD_FUNC(cmd_kickbanall
)
1732 struct modeNode
*mn
;
1733 struct userNode
*bot
= cmd
->parent
->bot
;
1734 struct mod_chanmode
*change
;
1736 unsigned int limit
, n
, inchan
;
1738 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1739 * channel, we have to join it in temporarily. */
1740 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1741 change
= mod_chanmode_alloc(2);
1742 change
->args
[0].mode
= MODE_CHANOP
;
1743 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1744 change
->args
[1].mode
= MODE_BAN
;
1745 change
->args
[1].u
.hostmask
= "*!*@*";
1747 change
= mod_chanmode_alloc(1);
1748 change
->args
[0].mode
= MODE_BAN
;
1749 change
->args
[0].u
.hostmask
= "*!*@*";
1751 modcmd_chanmode_announce(change
);
1752 mod_chanmode_free(change
);
1754 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1755 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1757 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1760 limit
= user
->handle_info
->opserv_level
;
1761 for (n
=channel
->members
.used
; n
>0; ) {
1762 mn
= channel
->members
.list
[--n
];
1763 if (IsService(mn
->user
)
1764 || (mn
->user
->handle_info
1765 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1768 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1771 DelChannelUser(bot
, channel
, "My work here is done", 0);
1772 reply("OSMSG_KICKALL_DONE", channel
->name
);
1776 static MODCMD_FUNC(cmd_svspart
)
1778 struct userNode
*target
;
1780 if(!IsChannelName(argv
[2])) {
1781 reply("MSG_NOT_CHANNEL_NAME");
1784 target
= GetUserH(argv
[1]);
1786 reply("MSG_NICK_UNKNOWN", argv
[1]);
1790 if (!(channel
= GetChannel(argv
[2]))) {
1791 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1795 if (!GetUserMode(channel
, target
)) {
1796 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1800 irc_svspart(opserv
, target
, channel
);
1801 reply("OSMSG_SVSPART_SENT");
1805 static MODCMD_FUNC(cmd_part
)
1809 if (!IsChannelName(argv
[1])) {
1810 reply("MSG_NOT_CHANNEL_NAME");
1813 if ((channel
= GetChannel(argv
[1]))) {
1814 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1815 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1818 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1819 reply("OSMSG_LEAVING", channel
->name
);
1820 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1825 static MODCMD_FUNC(cmd_mode
)
1827 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1828 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1831 reply("OSMSG_MODE_SET", channel
->name
);
1835 int is_valid_mark(char *mark
)
1841 if(strlen(mark
) > MARKLEN
)
1844 for(ptr
= mark
; *ptr
; ptr
++) {
1845 if(! (isalnum(*ptr
) || *ptr
== '-'))
1852 static MODCMD_FUNC(cmd_mark
)
1854 char *mark
= argv
[2];
1855 struct userNode
*victim
= GetUserH(argv
[1]);
1858 reply("MSG_NICK_UNKNOWN", argv
[1]);
1859 else if(!is_valid_mark(mark
))
1860 reply("OSMSG_MARK_INVALID");
1862 irc_mark(victim
, mark
);
1863 reply("OSMSG_MARK_SET");
1869 static MODCMD_FUNC(cmd_op
)
1871 struct mod_chanmode
*change
;
1872 unsigned int arg
, count
;
1874 change
= mod_chanmode_alloc(argc
-1);
1875 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1876 struct userNode
*victim
;
1877 struct modeNode
*mn
;
1878 if (!(victim
= GetUserH(argv
[arg
])))
1880 if (!(mn
= GetUserMode(channel
, victim
)))
1882 if (mn
->modes
& MODE_CHANOP
)
1884 change
->args
[count
].mode
= MODE_CHANOP
;
1885 change
->args
[count
++].u
.member
= mn
;
1888 change
->argc
= count
;
1889 modcmd_chanmode_announce(change
);
1891 mod_chanmode_free(change
);
1892 reply("OSMSG_OP_DONE");
1896 static MODCMD_FUNC(cmd_hop
)
1898 struct mod_chanmode
*change
;
1899 unsigned int arg
, count
;
1901 change
= mod_chanmode_alloc(argc
-1);
1902 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1903 struct userNode
*victim
;
1904 struct modeNode
*mn
;
1905 if (!(victim
= GetUserH(argv
[arg
])))
1907 if (!(mn
= GetUserMode(channel
, victim
)))
1909 if (mn
->modes
& MODE_HALFOP
)
1911 change
->args
[count
].mode
= MODE_HALFOP
;
1912 change
->args
[count
++].u
.member
= mn
;
1915 change
->argc
= count
;
1916 modcmd_chanmode_announce(change
);
1918 mod_chanmode_free(change
);
1919 reply("OSMSG_HOP_DONE");
1923 static MODCMD_FUNC(cmd_opall
)
1925 struct mod_chanmode
*change
;
1926 unsigned int ii
, count
;
1928 change
= mod_chanmode_alloc(channel
->members
.used
);
1929 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1930 struct modeNode
*mn
= channel
->members
.list
[ii
];
1931 if (mn
->modes
& MODE_CHANOP
)
1933 change
->args
[count
].mode
= MODE_CHANOP
;
1934 change
->args
[count
++].u
.member
= mn
;
1937 change
->argc
= count
;
1938 modcmd_chanmode_announce(change
);
1940 mod_chanmode_free(change
);
1941 reply("OSMSG_OPALL_DONE", channel
->name
);
1945 static MODCMD_FUNC(cmd_hopall
)
1947 struct mod_chanmode
*change
;
1948 unsigned int ii
, count
;
1950 change
= mod_chanmode_alloc(channel
->members
.used
);
1951 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1952 struct modeNode
*mn
= channel
->members
.list
[ii
];
1953 if (mn
->modes
& MODE_HALFOP
)
1955 change
->args
[count
].mode
= MODE_HALFOP
;
1956 change
->args
[count
++].u
.member
= mn
;
1959 change
->argc
= count
;
1960 modcmd_chanmode_announce(change
);
1962 mod_chanmode_free(change
);
1963 reply("OSMSG_HOPALL_DONE", channel
->name
);
1967 static MODCMD_FUNC(cmd_whois
)
1969 struct userNode
*target
;
1973 #ifdef WITH_PROTOCOL_P10
1974 if (argv
[1][0] == '*')
1975 target
= GetUserN(argv
[1]+1);
1978 target
= GetUserH(argv
[1]);
1980 reply("MSG_NICK_UNKNOWN", argv
[1]);
1983 reply("OSMSG_WHOIS_NICK", target
->nick
);
1984 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
1985 if (IsFakeHost(target
))
1986 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
1987 reply("OSMSG_WHOIS_CRYPT_HOST", target
->crypthost
);
1988 reply("OSMSG_WHOIS_CRYPT_IP", target
->cryptip
);
1989 reply("OSMSG_WHOIS_IP", irc_ntoa(&target
->ip
));
1992 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
1993 reply("OSMSG_WHOIS_COUNTRY_CODE", target
->country_code
);
1994 reply("OSMSG_WHOIS_CITY", target
->city
);
1995 reply("OSMSG_WHOIS_REGION", target
->region
);
1997 reply("OSMSG_WHOIS_POSTAL_CODE", target
->postal_code
);
1998 reply("OSMSG_WHOIS_LATITUDE", target
->latitude
);
1999 reply("OSMSG_WHOIS_LONGITUDE", target
->longitude
);
2000 /* Only show a map url if we have a city, latitude and longitude.
2001 * Theres not much point of latitude and longitude coordinates are
2002 * returned but no city, the coordinates are useless.
2004 if (target
->latitude
&& target
->longitude
&& target
->city
) {
2005 char map_url
[MAXLEN
];
2006 snprintf(map_url
, sizeof(map_url
), "http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=%f&longitude=%f",
2007 target
->latitude
, target
->longitude
);
2008 reply("OSMSG_WHOIS_MAP", map_url
);
2010 reply("OSMSG_WHOIS_DMA_CODE", target
->dma_code
);
2011 reply("OSMSG_WHOIS_AREA_CODE", target
->area_code
);
2012 } else if (target
->country_name
) {
2013 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2015 if(target
->version_reply
) {
2016 reply("OSMSG_WHOIS_VERSION", target
->version_reply
);
2018 reply("OSMSG_WHOIS_NO_NOTICE", target
->no_notice
? "YES":"NO");
2020 if (target
->modes
) {
2022 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
2023 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
2024 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
2025 if (IsOper(target
)) buffer
[bpos
++] = 'o';
2026 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
2027 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
2029 // sethost - reed/apples
2030 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
2031 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
2033 if (IsService(target
)) buffer
[bpos
++] = 'k';
2034 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
2035 if (target
->handle_info
) buffer
[bpos
++] = 'r';
2036 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
2037 if (IsGagged(target
)) buffer_cat(" (gagged)");
2038 if (IsRegistering(target
)) buffer_cat(" (registered account)");
2041 reply("OSMSG_WHOIS_MODES", buffer
);
2043 reply("OSMSG_WHOIS_INFO", target
->info
);
2044 #ifdef WITH_PROTOCOL_P10
2045 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
2047 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
2048 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
2050 reply("OSMSG_WHOIS_PRIVS", client_report_privs(target
));
2052 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
2053 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
2054 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
2055 opserv_ison(cmd
->parent
->bot
, user
, target
, "OSMSG_WHOIS_CHANNELS");
2057 reply("OSMSG_WHOIS_HIDECHANS");
2061 static MODCMD_FUNC(cmd_unban
)
2063 struct mod_chanmode change
;
2064 mod_chanmode_init(&change
);
2066 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
2067 change
.args
[0].u
.hostmask
= argv
[1];
2068 modcmd_chanmode_announce(&change
);
2069 reply("OSMSG_UNBAN_DONE", channel
->name
);
2073 static MODCMD_FUNC(cmd_voiceall
)
2075 struct mod_chanmode
*change
;
2076 unsigned int ii
, count
;
2078 change
= mod_chanmode_alloc(channel
->members
.used
);
2079 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2080 struct modeNode
*mn
= channel
->members
.list
[ii
];
2081 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
2083 change
->args
[count
].mode
= MODE_VOICE
;
2084 change
->args
[count
++].u
.member
= mn
;
2087 change
->argc
= count
;
2088 modcmd_chanmode_announce(change
);
2090 mod_chanmode_free(change
);
2091 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
2095 static MODCMD_FUNC(cmd_devoiceall
)
2097 struct mod_chanmode
*change
;
2098 unsigned int ii
, count
;
2100 change
= mod_chanmode_alloc(channel
->members
.used
);
2101 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2102 struct modeNode
*mn
= channel
->members
.list
[ii
];
2103 if (!(mn
->modes
& MODE_VOICE
))
2105 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
2106 change
->args
[count
++].u
.member
= mn
;
2109 change
->argc
= count
;
2110 modcmd_chanmode_announce(change
);
2112 mod_chanmode_free(change
);
2113 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
2117 static MODCMD_FUNC(cmd_stats_bad
) {
2119 unsigned int ii
, end
, here_len
;
2122 /* Show the bad word list.. */
2123 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
2124 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
2125 here_len
= strlen(opserv_bad_words
->list
[ii
]);
2126 /* If the line is full output it & start again */
2127 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2129 reply("OSMSG_BADWORD_LIST", buffer
);
2132 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
2134 buffer
[end
++] = ' ';
2137 reply("OSMSG_BADWORD_LIST", buffer
);
2139 /* Show the exemption list.. */
2140 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
2141 here_len
= strlen(iter_key(it
));
2142 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2144 reply("OSMSG_EXEMPTED_LIST", buffer
);
2147 memcpy(buffer
+end
, iter_key(it
), here_len
);
2149 buffer
[end
++] = ' ';
2152 reply("OSMSG_EXEMPTED_LIST", buffer
);
2156 static MODCMD_FUNC(cmd_stats_glines
) {
2157 reply("OSMSG_GLINE_COUNT", gline_count());
2161 static MODCMD_FUNC(cmd_stats_shuns
) {
2162 reply("OSMSG_SHUN_COUNT", shun_count());
2167 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
2168 unsigned int nn
, pos
;
2171 for (nn
=1; nn
<=depth
; nn
<<=1) ;
2172 for (pos
=0, nn
>>=1; nn
>1; ) {
2174 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
2175 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
2178 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
2179 if (!server
->children
.used
)
2181 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
2182 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
2184 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
2187 static MODCMD_FUNC(cmd_stats_links
) {
2188 trace_links(cmd
->parent
->bot
, user
, self
, 1);
2193 static MODCMD_FUNC(cmd_stats_max
) {
2194 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
2198 static MODCMD_FUNC(cmd_stats_network
) {
2199 struct helpfile_table tbl
;
2200 unsigned int nn
, tot_clients
;
2203 tot_clients
= dict_size(clients
);
2204 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
2205 tbl
.length
= dict_size(servers
)+1;
2207 tbl
.flags
= TABLE_NO_FREE
;
2208 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2209 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2210 tbl
.contents
[0][0] = "Server Name";
2211 tbl
.contents
[0][1] = "Clients";
2212 tbl
.contents
[0][2] = "Load";
2213 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2214 struct server
*server
= iter_data(it
);
2215 char *buffer
= malloc(32);
2216 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2217 tbl
.contents
[nn
][0] = server
->name
;
2218 tbl
.contents
[nn
][1] = buffer
;
2219 sprintf(buffer
, "%u", server
->clients
);
2220 tbl
.contents
[nn
][2] = buffer
+ 16;
2221 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
2224 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2225 for (nn
=1; nn
<tbl
.length
; nn
++) {
2226 free((char*)tbl
.contents
[nn
][1]);
2227 free(tbl
.contents
[nn
]);
2229 free(tbl
.contents
[0]);
2234 static MODCMD_FUNC(cmd_stats_network2
) {
2235 struct helpfile_table tbl
;
2239 tbl
.length
= dict_size(servers
)+1;
2241 tbl
.flags
= TABLE_NO_FREE
;
2242 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2243 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2244 tbl
.contents
[0][0] = "Server Name";
2245 tbl
.contents
[0][1] = "Numeric";
2246 tbl
.contents
[0][2] = "Link Time";
2247 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2248 struct server
*server
= iter_data(it
);
2249 char *buffer
= malloc(64);
2252 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2253 tbl
.contents
[nn
][0] = server
->name
;
2254 #ifdef WITH_PROTOCOL_P10
2255 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
2259 tbl
.contents
[nn
][1] = buffer
;
2260 ofs
= strlen(buffer
) + 1;
2261 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
2262 if (server
->self_burst
)
2263 strcat(buffer
+ ofs
, " Bursting");
2264 tbl
.contents
[nn
][2] = buffer
+ ofs
;
2267 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2268 for (nn
=1; nn
<tbl
.length
; nn
++) {
2269 free((char*)tbl
.contents
[nn
][1]);
2270 free(tbl
.contents
[nn
]);
2272 free(tbl
.contents
[0]);
2277 static MODCMD_FUNC(cmd_stats_reserved
) {
2280 reply("OSMSG_RESERVED_LIST");
2281 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
2282 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
2286 static MODCMD_FUNC(cmd_stats_trusted
) {
2288 struct trusted_host
*th
;
2289 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
2291 reply("OSMSG_TRUSTED_LIST");
2292 reply("OSMSG_TRUSTED_LIST_BAR");
2293 reply("OSMSG_TRUSTED_LIST_HEADER");
2294 reply("OSMSG_TRUSTED_LIST_BAR");
2296 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2299 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2301 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2303 sprintf(limit
, "%lu", th
->limit
);
2304 reply("OSMSG_HOST_IS_TRUSTED",
2306 (th
->limit
? limit
: "none"),
2307 (th
->issuer
? th
->issuer
: "<unknown>"),
2308 (th
->issued
? issued
: "some time"),
2309 (th
->expires
? length
: "never"));
2310 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2312 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
2315 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2318 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2320 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2322 sprintf(limit
, "%lu", th
->limit
);
2323 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
2324 (th
->limit
? limit
: "none"),
2325 (th
->issuer
? th
->issuer
: "<unknown>"),
2326 (th
->issued
? issued
: "some time"),
2327 (th
->expires
? length
: "never"));
2328 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2331 reply("OSMSG_TRUSTED_LIST_END");
2335 static MODCMD_FUNC(cmd_stats_uplink
) {
2336 extern struct cManagerNode cManager
;
2337 struct uplinkNode
*uplink
;
2339 uplink
= cManager
.uplink
;
2340 reply("OSMSG_UPLINK_START", uplink
->name
);
2341 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
2345 static MODCMD_FUNC(cmd_stats_uptime
) {
2346 char uptime
[INTERVALLEN
];
2348 extern time_t boot_time
;
2349 extern int lines_processed
;
2350 static long clocks_per_sec
;
2352 if (!clocks_per_sec
) {
2353 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
2354 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
2355 if (clocks_per_sec
<= 0)
2358 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
2359 clocks_per_sec
= CLOCKS_PER_SEC
;
2362 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
2364 reply("OSMSG_UPTIME_STATS",
2365 uptime
, lines_processed
,
2366 buf
.tms_utime
/(double)clocks_per_sec
,
2367 buf
.tms_stime
/(double)clocks_per_sec
);
2371 static MODCMD_FUNC(cmd_stats_alerts
) {
2373 struct opserv_user_alert
*alert
;
2374 const char *reaction
;
2378 m
= unsplit_string(argv
+ 1, argc
- 1, NULL
);
2379 reply("OSMSG_ALERTS_LIST", m
? m
: "*");
2380 reply("OSMSG_ALERTS_BAR");
2381 reply("OSMSG_ALERTS_HEADER");
2382 reply("OSMSG_ALERTS_BAR");
2383 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2384 alert
= iter_data(it
);
2385 if(m
&& (!match_ircglob(alert
->text_discrim
, m
) && strcasecmp(alert
->owner
, m
)) )
2386 continue; /* not a match to requested filter */
2387 switch (alert
->reaction
) {
2388 case REACT_NOTICE
: reaction
= "notice"; break;
2389 case REACT_KILL
: reaction
= "kill"; break;
2390 // case REACT_SILENT: reaction = "silent"; break;
2391 case REACT_GLINE
: reaction
= "gline"; break;
2392 case REACT_TRACK
: reaction
= "track"; break;
2393 case REACT_SHUN
: reaction
= "shun"; break;
2394 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
2395 case REACT_SVSPART
: reaction
= "svspart"; break;
2396 case REACT_VERSION
: reaction
= "version"; break;
2397 case REACT_MARK
: reaction
= "mark"; break;
2398 default: reaction
= "<unknown>"; break;
2400 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
2401 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
2403 reply("OSMSG_ALERT_END");
2407 static MODCMD_FUNC(cmd_stats_gags
) {
2408 struct gag_entry
*gag
;
2409 struct helpfile_table table
;
2413 reply("OSMSG_NO_GAGS");
2416 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
2417 table
.length
= nn
+1;
2419 table
.flags
= TABLE_NO_FREE
;
2420 table
.contents
= calloc(table
.length
, sizeof(char**));
2421 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
2422 table
.contents
[0][0] = "Mask";
2423 table
.contents
[0][1] = "Owner";
2424 table
.contents
[0][2] = "Expires";
2425 table
.contents
[0][3] = "Reason";
2426 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
2427 char expstr
[INTERVALLEN
];
2429 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
2431 strcpy(expstr
, "Never");
2432 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
2433 table
.contents
[nn
][0] = gag
->mask
;
2434 table
.contents
[nn
][1] = gag
->owner
;
2435 table
.contents
[nn
][2] = strdup(expstr
);
2436 table
.contents
[nn
][3] = gag
->reason
;
2438 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
2439 for (nn
=1; nn
<table
.length
; nn
++) {
2440 free((char*)table
.contents
[nn
][2]);
2441 free(table
.contents
[nn
]);
2443 free(table
.contents
[0]);
2444 free(table
.contents
);
2448 static MODCMD_FUNC(cmd_stats_timeq
) {
2449 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
2454 static MODCMD_FUNC(cmd_stats_warn) {
2457 reply("OSMSG_WARN_LISTSTART");
2458 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
2459 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
2460 reply("OSMSG_WARN_LISTEND");
2465 #if defined(WITH_MALLOC_X3)
2466 static MODCMD_FUNC(cmd_stats_memory
) {
2467 extern unsigned long alloc_count
, alloc_size
;
2468 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2469 "%u allocations totalling %u bytes.",
2470 alloc_count
, alloc_size
);
2473 #elif defined(WITH_MALLOC_SLAB)
2474 static MODCMD_FUNC(cmd_stats_memory
) {
2475 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
2476 extern unsigned long big_alloc_count
, big_alloc_size
;
2477 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2478 "%u allocations in %u slabs totalling %u bytes.",
2479 slab_alloc_count
, slab_count
, slab_alloc_size
);
2480 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2481 "%u big allocations totalling %u bytes.",
2482 big_alloc_count
, big_alloc_size
);
2487 static MODCMD_FUNC(cmd_dump
)
2489 char linedup
[MAXLEN
], original
[MAXLEN
];
2491 unsplit_string(argv
+1, argc
-1, original
);
2492 safestrncpy(linedup
, original
, sizeof(linedup
));
2493 /* assume it's only valid IRC if we can parse it */
2494 if (parse_line(linedup
, 1)) {
2496 reply("OSMSG_LINE_DUMPED");
2498 reply("OSMSG_RAW_PARSE_ERROR");
2502 static MODCMD_FUNC(cmd_raw
)
2504 char linedup
[MAXLEN
], original
[MAXLEN
];
2506 unsplit_string(argv
+1, argc
-1, original
);
2507 safestrncpy(linedup
, original
, sizeof(linedup
));
2508 /* Try to parse the line before sending it; if it's too wrong,
2509 * maybe it will core us instead of our uplink. */
2510 parse_line(linedup
, 1);
2512 reply("OSMSG_LINE_DUMPED");
2516 static struct userNode
*
2517 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
2519 struct userNode
*resv
= GetUserH(nick
);
2521 if (IsService(resv
)) {
2522 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
2525 if (resv
->handle_info
2526 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
2527 reply("OSMSG_LEVEL_TOO_LOW");
2531 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
2532 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
2537 static MODCMD_FUNC(cmd_collide
)
2539 struct userNode
*resv
;
2541 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2543 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
2546 reply("OSMSG_CLONE_FAILED", argv
[1]);
2551 static MODCMD_FUNC(cmd_reserve
)
2553 struct userNode
*resv
;
2555 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2557 resv
->modes
|= FLAGS_PERSISTENT
;
2558 reply("OSMSG_RESERVED_NICK", resv
->nick
);
2561 reply("OSMSG_CLONE_FAILED", argv
[1]);
2567 free_reserve(char *nick
)
2569 struct userNode
*resv
;
2573 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
2577 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
2578 reason
= alloca(rlen
);
2579 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
2580 DelUser(resv
, NULL
, 1, reason
);
2581 dict_remove(opserv_reserved_nick_dict
, nick
);
2585 static MODCMD_FUNC(cmd_unreserve
)
2587 if (free_reserve(argv
[1]))
2588 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
2590 reply("OSMSG_NOT_RESERVED", argv
[1]);
2595 opserv_part_channel(void *data
)
2597 DelChannelUser(opserv
, data
, "Leaving.", 0);
2600 static int alert_check_user(const char *key
, void *data
, void *extra
);
2603 opserv_new_user_check(struct userNode
*user
)
2605 struct opserv_hostinfo
*ohi
;
2606 struct gag_entry
*gag
;
2607 char addr
[IRC_NTOP_MAX_SIZE
];
2609 /* Check to see if we should ignore them entirely. */
2610 if (IsLocal(user
) || IsService(user
))
2613 /* Check for alerts, and stop if we find one that kills them. */
2614 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
2617 /* Gag them if appropriate. */
2618 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2619 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
2620 gag_helper_func(user
, NULL
);
2625 /* Add to host info struct */
2626 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2627 if (!(ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2628 ohi
= calloc(1, sizeof(*ohi
));
2629 dict_insert(opserv_hostinfo_dict
, strdup(addr
), ohi
);
2630 userList_init(&ohi
->clients
);
2632 userList_append(&ohi
->clients
, user
);
2634 /* Only warn of new user floods outside of bursts. */
2635 if (!user
->uplink
->burst
) {
2636 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
2637 if (!new_user_flood
) {
2639 opserv_alert("Warning: Possible new-user flood.");
2646 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
)) {
2647 irc_kill(opserv
, user
, DefConGlineReason
);
2651 if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS
)) && !IsOper(user
)) {
2652 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2654 strcpy(target
+ 2, user
->hostname
);
2655 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
2656 gline_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1, 0);
2657 else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
2658 shun_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1);
2663 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
2664 if (opserv_conf
.untrusted_max
2665 && irc_in_addr_is_valid(user
->ip
)
2666 && !irc_in_addr_is_loopback(user
->ip
)) {
2667 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, addr
, NULL
);
2668 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
2670 if (checkDefCon(DEFCON_REDUCE_SESSION
) && !th
)
2671 limit
= DefConSessionLimit
;
2674 /* 0 means unlimited hosts */
2675 } else if (ohi
->clients
.used
== limit
) {
2677 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
2678 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
2679 } else if (ohi
->clients
.used
> limit
) {
2680 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2681 strcpy(target
+ 2, addr
);
2682 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "Excessive connections from a single host.", now
, 1, 1);
2690 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
2692 struct opserv_hostinfo
*ohi
;
2693 char addr
[IRC_NTOP_MAX_SIZE
];
2695 if (IsLocal(user
)) {
2696 /* Try to remove it from the reserved nick dict without
2697 * calling free_reserve, because that would call DelUser(),
2698 * and we'd loop back to here. */
2699 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
2702 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2703 if ((ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2704 userList_remove(&ohi
->clients
, user
);
2705 if (ohi
->clients
.used
== 0)
2706 dict_remove(opserv_hostinfo_dict
, addr
);
2711 opserv_bad_channel(const char *name
)
2716 dict_find(opserv_exempt_channels
, name
, &present
);
2720 if (gline_find(name
))
2723 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
2724 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
2731 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
2733 struct mod_chanmode
*change
;
2736 change
= mod_chanmode_alloc(2);
2737 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2738 change
->args
[0].mode
= MODE_CHANOP
;
2739 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2740 change
->args
[1].mode
= MODE_BAN
;
2741 change
->args
[1].u
.hostmask
= "*!*@*";
2742 mod_chanmode_announce(opserv
, channel
, change
);
2743 mod_chanmode_free(change
);
2744 for (nn
=channel
->members
.used
; nn
>0; ) {
2745 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2746 if (IsService(mNode
->user
))
2748 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2750 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2754 opserv_channel_check(struct chanNode
*newchan
)
2758 if (!newchan
->join_policer
.params
) {
2759 newchan
->join_policer
.last_req
= now
;
2760 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2763 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2764 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning);
2768 /* Wait until the join check to shut channels down. */
2769 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2773 opserv_channel_delete(struct chanNode
*chan
)
2775 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2779 opserv_notice_handler(struct userNode
*user
, struct userNode
*bot
, char *text
, UNUSED_ARG(int server_qualified
))
2782 /* if its a version reply, do an alert check (only alerts with version=something) */
2784 if(text
[0] == '\001') {
2786 cmd
= mysep(&text
, " ");
2787 if(!irccasecmp(cmd
, "VERSION")) {
2788 char *version
= mysep(&text
, "\n");
2791 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
2792 /* user->version_reply = strdup(version); done in parse-p10.c now */
2793 dict_foreach(opserv_user_alerts
, alert_check_user
, user
);
2800 opserv_join_check(struct modeNode
*mNode
)
2802 struct userNode
*user
= mNode
->user
;
2803 struct chanNode
*channel
= mNode
->channel
;
2806 if (IsService(user
))
2809 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2811 if (channel
->bad_channel
) {
2812 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2813 if (channel
->name
[0] != '#')
2814 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2815 else if (!GetUserMode(channel
, opserv
))
2816 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2818 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2819 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2820 KickChannelUser(user
, channel
, opserv
, msg
);
2825 if (user
->uplink
->burst
)
2827 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2828 channel
->join_flooded
= 0;
2831 if (!channel
->join_flooded
) {
2832 /* Don't moderate the channel unless it is activated and
2833 the number of users in the channel is over the threshold. */
2834 struct mod_chanmode change
;
2835 mod_chanmode_init(&change
);
2836 channel
->join_flooded
= 1;
2837 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2838 if (!GetUserMode(channel
, opserv
)) {
2839 /* If we aren't in the channel, join it. */
2840 change
.args
[0].mode
= MODE_CHANOP
;
2841 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2844 if (!(channel
->modes
& MODE_MODERATED
))
2845 change
.modes_set
|= MODE_MODERATED
;
2846 if (change
.modes_set
|| change
.argc
)
2847 mod_chanmode_announce(opserv
, channel
, &change
);
2848 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2849 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2851 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2854 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2859 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2860 unsigned int bad_idx
;
2862 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2863 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2864 if (irccasestr(new_bad
, orig_bad
)) {
2866 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2868 } else if (irccasestr(orig_bad
, new_bad
)) {
2870 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2872 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2873 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2874 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2875 if (!irccasestr(orig_bad
, new_bad
))
2878 reply("OSMSG_BAD_NUKING", orig_bad
);
2879 string_list_delete(opserv_bad_words
, bad_idx
);
2886 string_list_append(opserv_bad_words
, strdup(new_bad
));
2888 reply("OSMSG_ADDED_BAD", new_bad
);
2893 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
)
2895 struct routingPlanServer
*rps
;
2896 rps
= calloc(1, sizeof(*rps
));
2899 /* duplicate servers replace */
2900 rps
->uplink
= strdup(uplink
);
2902 rps
->secondaryuplink
= strdup(second
);
2904 rps
->secondaryuplink
= NULL
;
2905 rps
->port
= port
? port
: 4400; /* lame hardcodede default port. maybe get from config file somewhere? */
2907 rps
->offline
= offline
; /* 1 = yes, 0 = no */
2908 dict_insert(rp
->servers
, strdup(name
), rps
);
2909 log_module(OS_LOG
, LOG_DEBUG
, "Adding rp server %s with uplink %s", name
, uplink
);
2914 free_routing_plan_server(void *data
)
2916 struct routingPlanServer
*rps
= data
;
2918 if(rps
->secondaryuplink
)
2919 free(rps
->secondaryuplink
);
2924 opserv_add_routing_plan(const char *name
)
2926 struct routingPlan
*rp
;
2927 rp
= calloc(1, sizeof(*rp
));
2930 if(dict_find(opserv_routing_plans
, name
, NULL
))
2931 return NULL
; /* plan already exists */
2932 rp
->servers
= dict_new();
2933 dict_set_free_data(rp
->servers
, free_routing_plan_server
);
2935 dict_insert(opserv_routing_plans
, strdup(name
), rp
);
2936 /* TODO: check for duplicate */
2941 free_routing_plan(void *data
)
2943 struct routingPlan
*rp
= data
;
2944 /* delete all the servers attached to this plan */
2945 dict_delete(rp
->servers
);
2946 /* free the plan struct */
2950 /*************************************************
2951 * Functions to handle the active routing struct */
2954 *find_routeList_server(struct route
*route
, const char *server
)
2956 struct routeList
*rptr
;
2959 for(rptr
= route
->servers
;rptr
;rptr
=rptr
->next
) {
2960 if(!strcasecmp(rptr
->server
, server
))
2966 /* Wipes out the routing structure, freeing properly.
2967 * note: does NOT free itself, we just re-use it usually.*/
2969 wipe_route_list(struct route
*route
) {
2970 struct routeList
*nextptr
, *rptr
;
2973 for(rptr
= opserv_route
->servers
; rptr
; rptr
=nextptr
)
2975 nextptr
= rptr
->next
;
2979 if(rptr
->secondaryuplink
)
2980 free(rptr
->secondaryuplink
);
2983 route
->centered
= true;
2985 route
->maxdepth
= 0;
2986 route
->servers
= NULL
;
2991 rank_outside_rec(struct route
*route
, char *server
, int count
)
2993 struct routeList
*rptr
;
2996 if(count
> 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */
2999 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3001 if(!strcasecmp(server
, rptr
->uplink
)) {
3002 log_module(MAIN_LOG
, LOG_DEBUG
, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count
, i
, rptr
->server
, rptr
->uplink
);
3003 n
= rank_outside_rec(route
, rptr
->server
, count
+1);
3004 if(n
< 0) /* handle error condition */
3010 if((rptr
= find_routeList_server(route
, server
))) {
3011 rptr
->outsideness
= max
;
3015 log_module(MAIN_LOG
, LOG_ERROR
, "routing struct rank_outsideness() couldnt find %s", server
);
3021 rank_outsideness(struct route
*route
)
3023 log_module(MAIN_LOG
, LOG_DEBUG
, "rank_outsideness(): Running...");
3024 route
->maxdepth
= rank_outside_rec(route
, self
->uplink
->name
, 0) - 1;
3025 if(route
->maxdepth
< 0) { /* if the rank failed, remove route */
3026 log_module(MAIN_LOG
, LOG_WARNING
, "The active routing plan has a loop! auto routing disabled.");
3027 wipe_route_list(route
);
3034 /* Add servers to the routing structure */
3036 add_routestruct_server(struct route
*route
, const char *server
, unsigned int port
, char *uplink
, char *secondary
)
3038 struct routeList
*rptr
;
3040 if(find_routeList_server(route
, server
))
3042 log_module(MAIN_LOG
, LOG_WARNING
, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server
);
3045 rptr
= calloc(1, sizeof(*rptr
));
3046 rptr
->server
= strdup(server
);
3049 hname
= conf_get_data("server/hostname", RECDB_QSTRING
);
3052 rptr
->uplink
= strdup(uplink
);
3054 rptr
->secondaryuplink
= strdup(secondary
);
3055 /* tack this server on the front of the list */
3056 rptr
->next
= route
->servers
;
3057 route
->servers
= rptr
;
3060 #ifdef notdef /* I dont quite get this. there could be uncentered things
3061 * added after our own uplink, and this function doesnt center
3062 * as it adds. -Rubin */
3063 /* If the map hasnt been centered yet... */
3064 if(route
->centered
== false) {
3065 /* AND we just added our own uplink to it... */
3066 if(!strcasecmp(server
, self
->uplink
->name
)) {
3067 change_route_uplinks(route
); /* recenter it, n mark it centered. */
3073 /* Recenter the routing struct around our current uplink */
3075 change_route_uplinks(struct route
*route
)
3077 struct routeList
*rptr
;
3078 char lastserver
[MAXLEN
];
3079 char nextserver
[MAXLEN
];
3082 return false; /* no map to recenter */
3083 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks(): running...");
3084 char *servicename
= conf_get_data("server/hostname", RECDB_QSTRING
);
3085 strcpy(lastserver
, servicename
);
3086 rptr
= find_routeList_server(route
, self
->uplink
->name
);
3088 log_module(MAIN_LOG
, LOG_ERROR
, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered.");
3089 route
->centered
= false;
3092 if(!strcasecmp(rptr
->uplink
, servicename
)) {
3093 log_module(MAIN_LOG
, LOG_DEBUG
, "Already centered");
3095 else { /* else, center it */
3097 strcpy(nextserver
, rptr
->uplink
);
3098 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks() changing %s uplink to %s.", rptr
->server
, lastserver
);
3100 rptr
->uplink
= strdup(lastserver
);
3101 strcpy(lastserver
, rptr
->server
);
3102 rptr
= find_routeList_server(route
, nextserver
);
3105 if(rank_outsideness(route
) > 0) {
3106 route
->centered
= true;
3114 activate_routing(struct svccmd
*cmd
, struct userNode
*user
, char *plan_name
)
3116 static struct routingPlan
*rp
;
3120 if(plan_name
) { /* make this the new active plan */
3121 if(!strcmp(plan_name
, "*")) {
3122 /* disable routing */
3123 dict_remove(opserv_routing_plan_options
, "ACTIVE");
3127 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3130 reply("OSMSG_PLAN_NOT_FOUND", plan_name
);
3132 /* since it doesnt exist, remove the active setting */
3133 dict_remove(opserv_routing_plan_options
, plan_name
);
3135 log_module(MAIN_LOG
, LOG_ERROR
, "activate_routing() couldnt find active routing plan!");
3140 else { /* find the active plan in settings */
3141 plan_name
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3143 if(!plan_name
) { /* deactivated, or no plan was set active */
3144 /* TODO: delete routing map if it exists */
3145 wipe_route_list(opserv_route
);
3149 karma
= dict_find(opserv_routing_plan_options
, "KARMA", NULL
);
3151 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3153 /* this should really be done during opserv init */
3155 opserv_route
= calloc(1, sizeof(*opserv_route
));
3157 /* Delete the existing active route */
3158 wipe_route_list(opserv_route
);
3160 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3161 const char* servername
= iter_key(it
);
3162 struct routingPlanServer
*rps
= iter_data(it
),
3163 *rp_uplink
, *rp_second
= NULL
;
3164 char *uplink
= rps
->uplink
;
3165 rp_uplink
= dict_find(rp
->servers
, rps
->uplink
, NULL
);
3166 if(rps
->secondaryuplink
)
3167 rp_second
= dict_find(rp
->servers
, rps
->secondaryuplink
, NULL
);
3169 /* If the normal uplink has bad karma, don't use it as a hub,
3170 * switch to the secondary uplink.
3172 if(karma
&& enabled_string(karma
) && rp_uplink
&& rp_uplink
->karma
< 0) {
3173 if(rps
->secondaryuplink
) {
3174 uplink
= rps
->secondaryuplink
;
3175 /* unless the secondary uplinks karma is worse than the uplink. */
3176 if((rp_second
= dict_find(rp
->servers
, uplink
, NULL
)) && rp_second
->karma
< rp_uplink
->karma
)
3177 uplink
= rps
->uplink
;
3181 * If _WE_ have bad karma, don't link us to our normal uplink, maybe
3182 * its a bad route. switch to secondary. Important: dont neg karma when we arnt on
3183 * our primary uplink, or we'll get stuck on secondary when THAT link is worse.
3185 if(karma
&& enabled_string(karma
) && (rps
->karma
< 0 || rps
->offline
) ) {
3186 if(rps
->secondaryuplink
) {
3187 uplink
= rps
->secondaryuplink
;
3190 log_module(MAIN_LOG
, LOG_DEBUG
, "activate_routing() adding %s:%d %s", servername
, rps
->port
, uplink
);
3191 add_routestruct_server(opserv_route
, servername
, rps
->port
, uplink
, NULL
);
3193 if(change_route_uplinks(opserv_route
))
3198 reply("OSMSG_ROUTING_ACTIVATION_ERROR");
3199 activate_routing(cmd
, user
, "*");
3202 /* routing activation failed but we dont do anything? */
3209 activate_routing(NULL
, NULL
, NULL
);
3211 /* start auto-routing system */
3212 reroute_timer_reset(0);
3215 /*******************************************************
3216 * Functions to handle online route configuration via opserv
3218 static void route_show_option(struct svccmd
*cmd
, struct userNode
*user
, char *name
)
3220 char *value
= dict_find(opserv_routing_plan_options
, name
, NULL
);
3222 if(!strcmp("RETRY_PERIOD", name
)) { /* Show as an interval */
3223 char buff
[INTERVALLEN
+1];
3224 reply("OSMSG_ROUTINGPLAN_OPTION", name
, intervalString(buff
, atoi(value
), user
->handle_info
));
3226 else if(!strcmp("ACTIVE", name
)) {
3227 if(opserv_route
&& opserv_route
->servers
)
3228 reply("OSMSG_ROUTINGPLAN_ACTIVE", value
);
3230 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3233 reply("OSMSG_ROUTINGPLAN_OPTION", name
, value
);
3237 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3241 static void route_show_options(struct svccmd
*cmd
, struct userNode
*user
)
3243 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3245 for(i
= 0; options
[i
]; i
++) {
3246 route_show_option(cmd
, user
, options
[i
]);
3250 /* called from timeq */
3251 void routing_connect_timeout(void *data
)
3253 struct waitingConnection
*wc
= data
;
3254 struct server
*target
= GetServerH(wc
->target
);
3256 dict_remove(opserv_waiting_connections
, wc
->server
);
3257 return; /* server we wanted to connect new server to is gone, just give up */
3259 routing_handle_connect_failure(target
, wc
->server
, "Connection timed out");
3260 /* the following invalidates server variable! */
3261 dict_remove(opserv_waiting_connections
, wc
->server
);
3264 void routing_delete_connect_timer(char *server
)
3266 struct waitingConnection
*wc
= dict_find(opserv_waiting_connections
, server
, 0);
3268 timeq_del(0, routing_connect_timeout
, wc
, TIMEQ_IGNORE_WHEN
);
3269 dict_remove(opserv_waiting_connections
, server
);
3275 routing_connect_server(char *server
, int port
, struct server
*to
)
3277 struct waitingConnection
*wc
= calloc(sizeof(*wc
), 1);
3279 wc
->server
= strdup(server
);
3280 wc
->target
= strdup(to
->name
);
3281 /* Just to make sure there isn't one left hanging
3282 * if 2 connections are attempted at once..
3284 routing_delete_connect_timer(server
);
3285 dict_insert(opserv_waiting_connections
, strdup(server
), wc
);
3286 timeq_add(now
+ ROUTING_CONNECT_TIMEOUT
, routing_connect_timeout
, wc
);
3288 irc_connect(opserv
, server
, port
, to
);
3292 routing_connect_one(struct route
*route
, char *server
)
3294 struct routeList
*rptr
;
3295 struct server
*sptr
, *suptr
;
3296 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3297 if(!strcasecmp(rptr
->server
, server
)) {
3298 /* this is the one, connect it */
3299 suptr
= GetServerH(rptr
->uplink
);
3300 sptr
= GetServerH(rptr
->server
);
3302 return 1; /* already linked */
3304 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3305 return 1; /* attempted link */
3307 return 0; /* its uplink isnt here to link to */
3310 log_module(MAIN_LOG
, LOG_DEBUG
, "Tried to link %s but its not in the active routing struct!", server
);
3311 return 0; /* server wasnt found in active route struct. */
3314 int routing_connect_children(struct route
*route
, char *server
)
3316 struct routeList
*rptr
;
3317 struct server
*sptr
, *suptr
;
3318 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3319 if(!strcasecmp(rptr
->uplink
, server
)) {
3320 /* this is the one, connect it */
3321 suptr
= GetServerH(rptr
->uplink
);
3322 sptr
= GetServerH(rptr
->server
);
3324 continue; /* already linked */
3326 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3327 continue; /* attempted link */
3329 continue; /* its uplink isnt here to link to */
3332 return 1; /* server wasnt found in active route struct ?! */
3335 int reroute(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
, char *directive
)
3337 struct routeList
*rptr
;
3338 struct server
*sptr
, *suptr
;
3339 int connect
= 0, move
= 0, missing
= 0, i
;
3340 char d
= toupper(*directive
);
3342 if(!route
|| !route
->servers
) {
3343 reply("OSMSG_REROUTING_NOTCONFIGURED");
3347 if(d
== 'N') { /* normal */
3348 irc_wallops("%s", "Attempting a reroute of the network according to loaded map...");
3349 reply("OSMSG_REROUTING_ACC_MAP");
3351 else if(d
== 'C') { /* only connect */
3352 reply("OSMSG_CONNECTING_MISSING_ONLY");
3354 else if(d
== 'T') { /* test */
3355 reply("OSMSG_TESTING_REROUTE");
3359 reply("OSMSG_INVALID_DIRECTIVE", directive
);
3363 for(i
= 0; i
<= route
->maxdepth
-1; i
++) {
3364 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3365 if(rptr
->outsideness
== i
) {
3368 reply("OSMSG_INSPECTING_SERVER", rptr
->server
);
3369 suptr
= GetServerH(rptr
->uplink
);
3371 if(rptr
->secondaryuplink
&& (suptr
= GetServerH(rptr
->secondaryuplink
))) {
3373 reply("OSMSG_COULDNT_FIND_SERVER", rptr
->uplink
, rptr
->secondaryuplink
, rptr
->server
);
3376 if(suptr
) { /* if the proper uplink is connected.. */
3377 sptr
= GetServerH(rptr
->server
);
3378 if(d
== 'C' && sptr
) {
3379 continue; /* Already linked */
3381 /* If server is missing or the uplinks are not the same then... */
3382 else if(!sptr
|| strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3386 else { /* Server is already connected somewhere */
3387 if(strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3388 if(d
!= 'T') { /* do it for real */
3389 irc_squit_route(sptr
, "%s issued reroute.", user
? user
->nick
: opserv
->nick
);
3391 else { /* just pretend */
3392 reply("OSMSG_SQUIT", rptr
->server
);
3397 if(d
!= 'T') /* do the real thing */
3398 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3399 else /* just pretend */
3400 reply("OSMSG_CONNECT", rptr
->server
, rptr
->port
, suptr
->name
);
3404 log_module(MAIN_LOG
, LOG_DEBUG
, "server uplink %s was not found, cant connect %s", rptr
->uplink
, rptr
->server
);
3407 } /* outsideness = 1 */
3410 if(user
) { /* report on what we did */
3411 if(!strcasecmp(directive
, "C")) {
3413 reply("OSMSG_CONNECTING_MISSING", connect
);
3415 reply("OSMSG_NO_SERVERS_MISSING");
3418 if(move
+connect
> 0)
3419 reply("OSMSG_REROUTE_COMPLETE", move
, connect
, move
+connect
);
3421 reply("OSMSG_NO_ROUTING_NECESSARY");
3423 reply("OSMSG_UPLINKS_MISSING", missing
);
3426 return(move
+connect
);
3429 static MODCMD_FUNC(cmd_reroute
) {
3432 if(reroute(opserv_route
, user
, cmd
, upper
))
3438 /* reroute_timer(run)
3439 * run - if it is null, just setup the timer
3440 * but dont run reroute now. otherwise reroute
3443 void reroute_timer(void *data
) {
3444 /* Delete any other timers such as this one.. */
3445 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3447 if(!opserv_route
|| !opserv_route
->servers
)
3448 return; /* no active route */
3449 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3451 return; /* retry_period invalid */
3452 unsigned int freq
= atoi(retry_period
);
3454 return; /* retry_period set to 0, disable */
3456 /* opserv_debug("Reroute timer checking reroute"); */
3457 log_module(MAIN_LOG
, LOG_DEBUG
, "Reroute timer checking reroute()");
3459 /* Do the reroute C attempt */
3461 reroute(opserv_route
, NULL
, NULL
, "C");
3463 /* Re-add ourselves to the timer queue */
3464 timeq_add(now
+ freq
, reroute_timer
, "run");
3467 void routing_change_karma(struct routingPlanServer
*rps
, const char *server
, int change
) {
3469 int oldkarma
= rps
->karma
;
3470 rps
->karma
+= change
;
3471 if(rps
->karma
< KARMA_MIN
)
3472 rps
->karma
= KARMA_MIN
;
3473 if(rps
->karma
> KARMA_MAX
)
3474 rps
->karma
= KARMA_MAX
;
3475 log_module(MAIN_LOG
, LOG_DEBUG
, "Changing %s karma by %d. new karma %d.", server
, change
, rps
->karma
);
3476 if(oldkarma
> 0 && rps
->karma
< 0) {
3477 /* we just crossed over to negitive */
3478 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went negitive karma!", server
);
3479 activate_routing(NULL
, NULL
, NULL
);
3481 else if(oldkarma
< 0 && rps
->karma
> 0) {
3482 /* we just crossed over to positive */
3483 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went back positive karma.", server
);
3484 activate_routing(NULL
, NULL
, NULL
);
3488 void routing_karma_timer(void *data
) {
3490 time_t timer_init
= data
? atoi(data
) : 0;
3493 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init
);
3495 /* If theres a time passed in, dont run unless that time is overdue. */
3496 if(!timer_init
|| (timer_init
< now
)) {
3497 if(opserv_route
&& opserv_route
->servers
) {
3498 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3499 struct routingPlan
*rp
;
3500 if(active
&& (rp
= dict_find(opserv_routing_plans
, active
, NULL
))) {
3502 /* Walk through each server in the active routing plan.. */
3503 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3504 struct routingPlanServer
*rps
= iter_data(it
);
3505 struct server
*server
= GetServerH(iter_key(it
));
3506 /* Give everyone +KARMA_ENTROPE just for nothing */
3507 routing_change_karma(rps
, iter_key(it
), KARMA_ENTROPE
);
3508 /* give an additonal +KARMA_RELIABLE to servers that
3509 * have been linked at least KARMA_TIMER seconds. */
3510 if(server
&& (server
->link
< (now
- KARMA_TIMER
) ) ) {
3511 routing_change_karma(rps
, iter_key(it
), KARMA_RELIABLE
);
3517 if(timer_init
> now
) /* loading a saved value */
3519 else /* no scheduled timer, or we missed it. start from now */
3520 next
= now
+ KARMA_TIMER
;
3521 /* Save when karma_timer should run again in case we restart before then */
3522 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next
);
3523 sprintf(buf
, "%u", (unsigned int) next
);
3524 dict_insert(opserv_routing_plan_options
, "KARMA_TIMER", strdup(buf
));
3525 /* add a timer to run this again .. */
3526 timeq_add(next
, routing_karma_timer
, NULL
);
3529 void routing_handle_neg_karma(char *server
, char *uplink
, int change
)
3531 /* if server's primary uplink is uplink, OR, uplink's primary uplink is server,
3532 * then whichever one, gets its karma changed. */
3533 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3534 struct routingPlan
*rp
;
3535 struct routingPlanServer
*rps
;
3538 if(!(rp
= dict_find(opserv_routing_plans
, active
, NULL
)))
3540 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3541 if(!strcasecmp(rps
->uplink
, uplink
)) {
3542 /* server's uplink is uplink */
3543 routing_change_karma(rps
, server
, change
);
3547 if((rps
= dict_find(rp
->servers
, uplink
, NULL
))) {
3548 if(!strcasecmp(rps
->uplink
, server
)) {
3549 /* uplink's uplink is server */
3550 routing_change_karma(rps
, uplink
, change
);
3557 routing_handle_squit(char *server
, char *uplink
, char *message
)
3559 log_module(MAIN_LOG
, LOG_DEBUG
, "Routing_handle_squit(%s, %s)", server
, message
);
3563 if(match_ircglob(message
, "Ping timeout")) {
3564 routing_handle_neg_karma(server
, uplink
, KARMA_PINGOUT
);
3565 /* if conn_pingout is true, try to reconnect it obaying karma rules. */
3567 val
= dict_find(opserv_routing_plan_options
, "CONN_PINGOUT", 0);
3568 if(val
&& enabled_string(val
))
3569 routing_connect_one(opserv_route
, server
);
3571 else if(match_ircglob(message
, "Read error:*")) {
3572 routing_handle_neg_karma(server
, uplink
, KARMA_READERROR
);
3573 /* if conn_readerror is true, try to reconnect it obaying karma rules. */
3574 val
= dict_find(opserv_routing_plan_options
, "CONN_READERROR", 0);
3575 if(val
&& enabled_string(val
))
3576 routing_connect_one(opserv_route
, server
);
3578 /* Else whats the message (an oper squit it?) dont interfere */
3582 routing_handle_connect(char *server
, char *uplink
)
3585 struct routingPlan
*rp
;
3586 struct routingPlanServer
*rps
;
3589 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect(%s, %s)", server
, uplink
);
3590 /* delete a pending connection timer, if any */
3591 routing_delete_connect_timer(server
);
3592 /* check if routing is active... */
3593 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3596 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3600 /* If its offline, mark it online again.. */
3601 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3602 if(rps
->offline
== true) {
3603 rps
->offline
= false;
3604 if(rps
->secondaryuplink
) {
3605 /* re-activate to move it back to its primary */
3606 activate_routing(NULL
, NULL
, NULL
);
3609 /* if there are any servers missing who have this server as uplink try to connect them. */
3610 routing_connect_children(opserv_route
, server
);
3612 /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */
3613 for (it
=dict_first(servers
); it
; it
=iter_next(it
)) {
3614 struct server
*sptr
= iter_data(it
);
3615 if(sptr
&& sptr
->uplink
&& !strcasecmp(server
, sptr
->uplink
->name
)) {
3616 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect calling self on %s's leaf %s", server
, sptr
->name
);
3617 routing_handle_connect(sptr
->name
, sptr
->uplink
->name
);
3622 /* Handle a failed attempt at connecting servers
3623 * - we should only get here regarding servers X3 attempted to link, other
3624 * opers link messages go to them not to us
3627 routing_handle_connect_failure(struct server
*source
, char *server
, char *message
)
3630 struct routingPlan
*rp
;
3631 struct routingPlanServer
*rps
;
3632 log_module(MAIN_LOG
, LOG_ERROR
, "Failed to connect %s to %s: %s", server
, source
->name
, message
);
3633 /* remove the waiting connection n timeq */
3634 routing_delete_connect_timer(server
);
3635 /* check if routing is active.. */
3636 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3639 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3643 if( ((rps
= dict_find(rp
->servers
, server
, NULL
)) && !strcasecmp(rps
->uplink
, source
->name
))) {
3644 /* failed to connect to its primary uplink */
3645 if(rps
->offline
== false) {
3646 rps
->offline
= true;
3647 if(rps
->secondaryuplink
) {
3648 /* re-activate routing so the secondary
3649 * becomes its uplink, and try again */
3650 activate_routing(NULL
, NULL
, NULL
);
3651 /* attempt to link it again. */
3652 routing_connect_one(opserv_route
, server
);
3653 /* TODO: reconnect any missing servers who
3654 * normally connect to server, using their backups.
3655 * Probably should just issue a reroute C here. */
3661 /* Delete any existing timers, and start the timer again
3662 * using the passed time for the first run.
3663 * - this is called during a retry_period change
3664 * before it has saved the new value.
3666 * If time is 0, lookup the interval. */
3667 void reroute_timer_reset(unsigned int time
)
3669 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3671 if(!opserv_route
|| !opserv_route
->servers
)
3672 return; /* no active route */
3673 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3675 return; /* retry_period invalid */
3676 time
= atoi(retry_period
);
3678 return; /* retry_period set to 0, disable */
3681 timeq_add(now
+ time
, reroute_timer
, "run");
3684 static MODCMD_FUNC(cmd_routing_set
)
3686 char *option
= argv
[1];
3687 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3690 route_show_options(cmd
, user
);
3693 char *found_option
= NULL
;
3694 for(i
= 0; options
[i
]; i
++) {
3695 if(!strcasecmp(options
[i
], option
))
3696 found_option
= options
[i
];
3699 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option
);
3703 char *value
= argv
[2];
3704 char buff
[MAXLEN
]; /* whats the max length of unsigned int as printf'd? */
3705 if(!strcmp(found_option
, "ACTIVE")) { /* must be an existing route. */
3706 if(disabled_string(value
) || false_string(value
)) {
3707 /* make none of the maps active */
3708 activate_routing(cmd
, user
, "*");
3709 reply("OSMSG_ROUTING_DISABLED");
3712 else if(!activate_routing(cmd
, user
, value
)) {
3713 /* neg reply handled in activate_routing */
3717 if(!strcmp(found_option
, "CONN_READERROR") || !strcmp(found_option
, "CONN_PINGOUT") ||
3718 !strcmp(found_option
, "KARMA") ) {
3719 if( enabled_string(value
)) {
3722 else if( disabled_string(value
) ) {
3726 reply("MSG_INVALID_BINARY", value
);
3730 if(!strcmp(found_option
, "RETRY_PERIOD")) {
3731 unsigned int duration
= ParseInterval(value
);
3732 sprintf(buff
, "%d", duration
);
3734 reroute_timer_reset(duration
);
3736 /* set the value here */
3737 dict_remove(opserv_routing_plan_options
, found_option
);
3738 dict_insert(opserv_routing_plan_options
, strdup(found_option
), strdup(value
));
3739 route_show_option(cmd
, user
, found_option
);
3742 /* show the current value */
3743 route_show_option(cmd
, user
, found_option
);
3749 static MODCMD_FUNC(cmd_stats_routing_plans
) {
3750 dict_iterator_t rpit
;
3752 struct routingPlan
*rp
;
3754 reply("OSMSG_ROUTINGPLAN");
3755 reply("OSMSG_ROUTINGPLAN_BAR");
3756 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3757 const char* name
= iter_key(rpit
);
3758 rp
= iter_data(rpit
);
3759 if(match_ircglob(name
, argv
[1])) {
3760 reply("OSMSG_ROUTINGPLAN_NAME", name
);
3761 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3762 const char* servername
= iter_key(it
);
3763 struct routingPlanServer
*rps
= iter_data(it
);
3764 reply("OSMSG_ROUTINGPLAN_SERVER", servername
, rps
->port
, rps
->uplink
, rps
->karma
, rps
->offline
? "offline" : "online", rps
->secondaryuplink
? rps
->secondaryuplink
: "None");
3769 reply("OSMSG_ROUTINGPLAN_END");
3772 reply("OSMSG_ROUTINGPLAN_LIST_HEAD");
3773 reply("OSMSG_ROUTINGPLAN_BAR");
3774 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3775 const char* name
= iter_key(rpit
);
3776 reply("OSMSG_ROUTINGPLAN_LIST", name
);
3778 reply("OSMSG_ROUTINGPLAN_END");
3779 route_show_options(cmd
, user
);
3785 static MODCMD_FUNC(cmd_routing_addplan
)
3789 /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */
3790 if(*name
&& !disabled_string(name
) && !false_string(name
)) {
3791 if(opserv_add_routing_plan(name
)) {
3792 reply("OSMSG_ADDPLAN_SUCCESS", name
);
3796 reply("OSMSG_ADDPLAN_FAILED", name
);
3802 reply("OSMSG_INVALID_PLAN");
3807 static MODCMD_FUNC(cmd_routing_delplan
)
3809 char *name
= argv
[1];
3810 if( dict_remove(opserv_routing_plans
, name
) ) {
3811 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3812 if(active
&& !strcasecmp(active
, name
)) {
3813 /* if this was the active plan, disable routing */
3814 activate_routing(cmd
, user
, "*");
3815 reply("OSMSG_ROUTING_DISABLED");
3817 reply("OSMSG_PLAN_DELETED");
3821 reply("OSMSG_PLAN_NOT_FOUND", name
);
3826 static MODCMD_FUNC(cmd_routing_addserver
)
3834 struct routingPlan
*rp
;
3837 server
= strdup(argv
[2]);
3838 server
= strtok(server
, ":");
3839 portstr
= strtok(NULL
, ":");
3841 port
= atoi(portstr
);
3843 char *str
= dict_find(opserv_routing_plan_options
, "DEFAULT_PORT", NULL
);
3845 port
= str
? atoi(str
) : 0;
3853 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3855 opserv_routing_plan_add_server(rp
, server
, uplink
, port
, KARMA_DEFAULT
, second
, 0);
3856 reply("OSMSG_PLAN_SERVER_ADDED", server
);
3857 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3858 /* re-activate routing with new info */
3859 activate_routing(cmd
, user
, NULL
);
3866 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3872 static MODCMD_FUNC(cmd_routing_delserver
)
3876 struct routingPlan
*rp
;
3879 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3880 if(dict_remove(rp
->servers
, server
)) {
3882 reply("OSMSG_PLAN_SERVER_DELETED");
3883 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3884 /* re-activate routing with new info */
3885 activate_routing(cmd
, user
, NULL
);
3891 reply("OSMSG_PLAN_SERVER_NOT_FOUND", server
);
3896 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3902 /*************************************************
3903 * Functions to deal with 'route map' command */
3905 /* Figures out how many downlinks there are for proper
3906 * drawing of the route map */
3908 num_route_downlinks(struct route
*route
, char *name
)
3910 struct routeList
*rptr
;
3912 rptr
= route
->servers
;
3914 if(!strcasecmp(rptr
->uplink
, name
))
3922 show_route_downlinks(struct svccmd
*cmd
, struct route
*route
, struct userNode
*user
, char *name
, char *prevpre
, char *arrowchar
, int reset
)
3924 struct routeList
*servPtr
;
3925 struct server
*sptr
;
3931 static int depth
= 0;
3936 nextpre
= malloc(MAXLEN
);
3937 strcpy(pre
, prevpre
);
3939 sptr
= GetServerH(name
);
3940 if((servPtr
= find_routeList_server(route
, name
))) {
3943 else if (!strcasecmp(sptr
->uplink
->name
, servPtr
->uplink
))
3945 else if(servPtr
->secondaryuplink
&& !strcasecmp(sptr
->name
, servPtr
->secondaryuplink
))
3949 reply("OSMSG_DOWNLINKS_FORMAT_A", pre
, arrowchar
, name
, status
);
3952 reply("OSMSG_DOWNLINKS_FORMAT_B", self
->name
);
3953 j
= num_route_downlinks(route
, name
);
3954 servPtr
= route
->servers
;
3956 if(!strcasecmp(servPtr
->uplink
, name
)) {
3957 strcpy(nextpre
, pre
);
3959 if(arrowchar
[0] == '`')
3960 strcat(nextpre
, " ");
3962 strcat(nextpre
, "| ");
3965 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "|", 0);
3968 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "`", 0);
3971 servPtr
= servPtr
->next
;
3977 show_route_map(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
)
3979 if(!route
|| !route
->servers
) {
3980 reply("OSMSG_ROUTELIST_EMPTY");
3984 char *serviceName
= conf_get_data("server/hostname", RECDB_QSTRING
);
3985 reply("OSMSG_ROUTELIST_AS_PLANNED");
3986 show_route_downlinks(cmd
, route
, user
, serviceName
, "", "`", 1);
3987 reply("OSMSG_MAP_CENTERED", route
->centered
? "is" : "is not", route
->maxdepth
);
3991 static MODCMD_FUNC(cmd_routing_map
)
3993 show_route_map(opserv_route
, user
, cmd
);
4000 /* End of auto routing functions *
4001 *********************************/
4003 static MODCMD_FUNC(cmd_addbad
)
4005 unsigned int arg
, count
;
4007 int bad_found
, exempt_found
;
4009 /* Create the bad word if it doesn't exist. */
4010 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
4012 /* Look for exception modifiers. */
4013 for (arg
=2; arg
<argc
; arg
++) {
4014 if (!irccasecmp(argv
[arg
], "except")) {
4015 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
4017 reply("MSG_MISSING_PARAMS", "except");
4020 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
4021 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
4022 if (!exempt_found
) {
4023 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
4027 reply("OSMSG_ADDED_EXEMPTIONS", count
);
4029 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
4030 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
4034 /* Scan for existing channels that match the new bad word. */
4036 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4037 struct chanNode
*channel
= iter_data(it
);
4039 if (!opserv_bad_channel(channel
->name
))
4041 channel
->bad_channel
= 1;
4042 if (channel
->name
[0] == '#')
4043 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
4046 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
4047 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
4048 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
4057 static MODCMD_FUNC(cmd_delbad
)
4062 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
4063 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
4064 string_list_delete(opserv_bad_words
, nn
);
4065 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4066 channel
= iter_data(it
);
4067 if (irccasestr(channel
->name
, argv
[1])
4068 && !opserv_bad_channel(channel
->name
)) {
4069 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
4070 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4071 channel
->bad_channel
= 0;
4074 reply("OSMSG_REMOVED_BAD", argv
[1]);
4078 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
4082 static MODCMD_FUNC(cmd_addexempt
)
4084 const char *chanName
;
4086 if ((argc
> 1) && IsChannelName(argv
[1])) {
4089 reply("MSG_NOT_CHANNEL_NAME");
4093 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
4094 channel
= GetChannel(chanName
);
4096 if (channel
->bad_channel
) {
4097 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
4098 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4100 channel
->bad_channel
= 0;
4102 reply("OSMSG_ADDED_EXEMPTION", chanName
);
4106 static MODCMD_FUNC(cmd_delexempt
)
4108 const char *chanName
;
4110 if ((argc
> 1) && IsChannelName(argv
[1])) {
4113 reply("MSG_NOT_CHANNEL_NAME");
4117 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
4118 reply("OSMSG_NOT_EXEMPT", chanName
);
4121 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
4126 opserv_expire_trusted_host(void *data
)
4128 struct trusted_host
*th
= data
;
4129 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
4133 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
4135 struct trusted_host
*th
;
4136 th
= calloc(1, sizeof(*th
));
4139 th
->ipaddr
= strdup(ipaddr
);
4140 th
->reason
= reason
? strdup(reason
) : NULL
;
4141 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
4142 th
->issued
= issued
;
4144 th
->expires
= expires
;
4145 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
4147 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4151 free_trusted_host(void *data
)
4153 struct trusted_host
*th
= data
;
4160 static MODCMD_FUNC(cmd_addtrust
)
4162 unsigned long interval
;
4164 irc_in_addr_t tmpaddr
;
4167 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
4168 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
4172 if (!irc_pton(&tmpaddr
, NULL
, argv
[1])) {
4173 reply("OSMSG_BAD_IP", argv
[1]);
4177 count
= strtoul(argv
[2], &tmp
, 10);
4179 reply("OSMSG_BAD_NUMBER", argv
[2]);
4183 interval
= ParseInterval(argv
[3]);
4184 if (!interval
&& strcmp(argv
[3], "0")) {
4185 reply("MSG_INVALID_DURATION", argv
[3]);
4189 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4190 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
4191 reply("OSMSG_ADDED_TRUSTED");
4195 static MODCMD_FUNC(cmd_edittrust
)
4197 unsigned long interval
;
4198 struct trusted_host
*th
;
4202 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
4204 reply("OSMSG_NOT_TRUSTED", argv
[1]);
4207 count
= strtoul(argv
[2], &tmp
, 10);
4208 if (!count
|| *tmp
) {
4209 reply("OSMSG_BAD_NUMBER", argv
[2]);
4212 interval
= ParseInterval(argv
[3]);
4213 if (!interval
&& strcmp(argv
[3], "0")) {
4214 reply("MSG_INVALID_DURATION", argv
[3]);
4217 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4219 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4222 th
->reason
= strdup(reason
);
4224 th
->issuer
= strdup(user
->handle_info
->handle
);
4228 th
->expires
= now
+ interval
;
4229 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4232 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
4236 static MODCMD_FUNC(cmd_deltrust
)
4240 for (n
=1; n
<argc
; n
++) {
4241 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
4245 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4246 dict_remove(opserv_trusted_hosts
, argv
[n
]);
4248 reply("OSMSG_REMOVED_TRUSTED");
4252 /* This doesn't use dict_t because it's a little simpler to open-code the
4253 * comparisons (and simpler arg-passing for the ADD subcommand).
4255 static MODCMD_FUNC(cmd_clone
)
4258 struct userNode
*clone
;
4260 clone
= GetUserH(argv
[2]);
4261 if (!irccasecmp(argv
[1], "ADD")) {
4263 char ident
[USERLEN
+1];
4266 reply("MSG_MISSING_PARAMS", argv
[1]);
4271 reply("OSMSG_CLONE_EXISTS", argv
[2]);
4274 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
4275 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
4276 if (argv
[3][i
] == '@') {
4280 ident
[i
] = argv
[3][i
];
4283 if (!argv
[3][i
] || (i
==USERLEN
)) {
4284 reply("OSMSG_NOT_A_HOSTMASK");
4287 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
4288 reply("OSMSG_CLONE_FAILED", argv
[2]);
4291 reply("OSMSG_CLONE_ADDED", clone
->nick
);
4295 reply("MSG_NICK_UNKNOWN", argv
[2]);
4298 if (clone
->uplink
!= self
|| IsService(clone
)) {
4299 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
4302 if (!irccasecmp(argv
[1], "REMOVE")) {
4305 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
4308 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
4309 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
4312 DelUser(clone
, NULL
, 1, reason
);
4313 reply("OSMSG_CLONE_REMOVED", argv
[2]);
4317 reply("MSG_MISSING_PARAMS", argv
[1]);
4321 channel
= GetChannel(argv
[3]);
4322 if (!irccasecmp(argv
[1], "JOIN")) {
4324 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
4325 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4328 AddChannelUser(clone
, channel
);
4329 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
4332 if (!irccasecmp(argv
[1], "PART")) {
4334 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4337 if (!GetUserMode(channel
, clone
)) {
4338 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4341 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
4342 DelChannelUser(clone
, channel
, "Leaving.", 0);
4345 if (!irccasecmp(argv
[1], "OP")) {
4346 struct mod_chanmode change
;
4348 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4351 mod_chanmode_init(&change
);
4353 change
.args
[0].mode
= MODE_CHANOP
;
4354 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4355 if (!change
.args
[0].u
.member
) {
4356 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4359 modcmd_chanmode_announce(&change
);
4360 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
4363 if (!irccasecmp(argv
[1], "HOP")) {
4364 struct mod_chanmode change
;
4366 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4369 mod_chanmode_init(&change
);
4371 change
.args
[0].mode
= MODE_HALFOP
;
4372 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4373 if (!change
.args
[0].u
.member
) {
4374 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4377 modcmd_chanmode_announce(&change
);
4378 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
4382 reply("MSG_MISSING_PARAMS", argv
[1]);
4386 if (!irccasecmp(argv
[1], "SAY")) {
4387 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
4388 irc_privmsg(clone
, argv
[3], text
);
4389 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
4392 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
4396 static struct helpfile_expansion
4397 opserv_help_expand(const char *variable
)
4399 extern struct userNode
*message_source
;
4400 struct helpfile_expansion exp
;
4401 struct service
*service
;
4407 if (!(service
= service_find(message_source
->nick
))) {
4408 exp
.type
= HF_STRING
;
4409 exp
.value
.str
= NULL
;
4410 } else if (!irccasecmp(variable
, "index")) {
4411 exp
.type
= HF_TABLE
;
4412 exp
.value
.table
.length
= 1;
4413 exp
.value
.table
.width
= 2;
4414 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
4415 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
4416 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
4417 exp
.value
.table
.contents
[0][0] = "Command";
4418 exp
.value
.table
.contents
[0][1] = "Level";
4419 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
4420 cmd
= iter_data(it
);
4421 row
= exp
.value
.table
.length
++;
4422 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
4423 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
4424 level
= cmd
->min_opserv_level
;
4425 if (!level_strings
[level
]) {
4426 level_strings
[level
] = malloc(16);
4427 snprintf(level_strings
[level
], 16, "%3d", level
);
4429 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
4431 } else if (!strncasecmp(variable
, "level", 5)) {
4432 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
4433 exp
.type
= HF_STRING
;
4435 level
= cmd
->min_opserv_level
;
4436 exp
.value
.str
= malloc(16);
4437 snprintf(exp
.value
.str
, 16, "%3d", level
);
4439 exp
.value
.str
= NULL
;
4442 exp
.type
= HF_STRING
;
4443 exp
.value
.str
= NULL
;
4449 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
4451 char buf
[16], *flags
= NULL
;
4452 unsigned int iflags
= 0;
4453 sprintf(buf
, "%d", min_level
);
4455 case 1: flags
= "+acceptchan"; break;
4456 case 3: flags
= "+acceptpluschan"; /* fall through */
4457 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
4460 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
4462 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
4466 int add_reserved(const char *key
, void *data
, void *extra
)
4468 struct chanNode
*chan
;
4469 struct record_data
*rd
= data
;
4470 const char *ident
, *hostname
, *desc
;
4472 struct userNode
*reserve
;
4473 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
4475 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
4478 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
4480 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
4483 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
4485 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
4488 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
4489 reserve
->modes
|= FLAGS_PERSISTENT
;
4490 dict_insert(extra
, reserve
->nick
, reserve
);
4493 if (autojoin_channels
&& reserve
) {
4494 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
4495 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
4496 AddChannelUser(reserve
, chan
)->modes
|= MODE_VOICE
;
4504 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
4508 unsigned int matched
;
4510 if (!self
->uplink
) return 0;
4511 discrim
= calloc(1, sizeof(*discrim
));
4512 discrim
->limit
= dict_size(clients
);
4513 discrim
->max_level
= ~0;
4514 discrim
->max_ts
= now
;
4515 discrim
->max_channels
= INT_MAX
;
4516 discrim
->authed
= -1;
4517 discrim
->info_space
= -1;
4518 discrim
->intra_scmp
= 0;
4519 discrim
->intra_dcmp
= 0;
4520 discrim
->use_regex
= 0;
4521 discrim
->silent
= 0;
4522 dupmask
= strdup(hostmask
);
4523 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
4524 if (!irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, discrim
->mask_host
))
4525 discrim
->ip_mask_bits
= 0;
4526 matched
= opserv_discrim_search(discrim
, func
, extra
);
4528 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
4537 gag_free(struct gag_entry
*gag
)
4539 unsigned int ungagged
;
4541 /* Remove from gag list */
4542 if (gagList
== gag
) {
4543 gagList
= gag
->next
;
4545 struct gag_entry
*prev
;
4546 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
4547 prev
->next
= gag
->next
;
4550 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
4552 /* Deallocate storage */
4562 gag_expire(void *data
)
4568 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
4570 struct gag_entry
*gag
;
4572 /* Create gag and put it into linked list */
4573 gag
= calloc(1, sizeof(*gag
));
4574 gag
->mask
= strdup(mask
);
4575 gag
->owner
= strdup(owner
? owner
: "<unknown>");
4576 gag
->reason
= strdup(reason
? reason
: "<unknown>");
4577 gag
->expires
= expires
;
4579 timeq_add(gag
->expires
, gag_expire
, gag
);
4580 gag
->next
= gagList
;
4583 /* If we're linked, see if who the gag applies to */
4584 return foreach_matching_user(mask
, gag_helper_func
, gag
);
4588 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4590 struct record_data
*rd
= data
;
4591 char *owner
, *reason
, *expstr
;
4594 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
4595 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
4596 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
4597 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
4598 gag_create(key
, owner
, reason
, expires
);
4603 static struct opserv_user_alert
*
4604 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
)
4607 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
4608 struct opserv_user_alert
*alert
;
4611 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
4612 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
4615 alert
= malloc(sizeof(*alert
));
4616 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
4617 alert
->text_discrim
= strdup(text_discrim
);
4618 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
4619 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
4620 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
4621 /* Check for missing required criteria or broken records */
4622 if (!alert
->discrim
|| (reaction
==REACT_SVSJOIN
&& !alert
->discrim
->chantarget
) ||
4623 (reaction
==REACT_SVSPART
&& !alert
->discrim
->chantarget
) ||
4624 (reaction
==REACT_MARK
&& !alert
->discrim
->mark
)) {
4625 free(alert
->text_discrim
);
4630 alert
->split_discrim
= discrim_copy
;
4631 name_dup
= strdup(name
);
4632 if (!alert
->discrim
->reason
)
4633 alert
->discrim
->reason
= strdup(name
);
4634 alert
->reaction
= reaction
;
4635 dict_insert(opserv_user_alerts
, name_dup
, alert
);
4636 /* Stick the alert into the appropriate additional alert dict(s).
4637 * For channel alerts, we only use channels and min_channels;
4638 * max_channels would have to be checked on /part, which we do not
4639 * yet do, and which seems of questionable value.
4641 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
4642 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
4643 if (alert
->discrim
->mask_nick
)
4644 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
4650 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
4652 struct record_data *rd = data;
4653 char *reason = GET_RECORD_QSTRING(rd);
4655 * i hope this can't happen *
4657 reason = "No Reason";
4659 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
4666 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4669 const char *discrim
, *react
, *owner
;
4670 opserv_alert_reaction reaction
;
4671 struct opserv_user_alert
*alert
;
4673 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
4674 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
4677 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
4678 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
4679 if (!react
|| !irccasecmp(react
, "notice"))
4680 reaction
= REACT_NOTICE
;
4681 else if (!irccasecmp(react
, "kill"))
4682 reaction
= REACT_KILL
;
4684 else if (!irccasecmp(react, "silent"))
4685 reaction = REACT_SILENT;
4687 else if (!irccasecmp(react
, "gline"))
4688 reaction
= REACT_GLINE
;
4689 else if (!irccasecmp(react
, "track"))
4690 reaction
= REACT_TRACK
;
4691 else if (!irccasecmp(react
, "shun"))
4692 reaction
= REACT_SHUN
;
4693 else if (!irccasecmp(react
, "svsjoin"))
4694 reaction
= REACT_SVSJOIN
;
4695 else if (!irccasecmp(react
, "svspart"))
4696 reaction
= REACT_SVSPART
;
4697 else if (!irccasecmp(react
, "version"))
4698 reaction
= REACT_VERSION
;
4699 else if (!irccasecmp(react
, "mark"))
4700 reaction
= REACT_MARK
;
4702 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
4705 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
);
4707 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
4710 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
4712 alert
->owner
= strdup(owner
? owner
: "<unknown>");
4717 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
4719 struct record_data
*rd
= data
;
4720 const char *limit
, *str
, *reason
, *issuer
;
4721 time_t issued
, expires
;
4723 if (rd
->type
== RECDB_QSTRING
) {
4724 /* old style host by itself */
4725 limit
= GET_RECORD_QSTRING(rd
);
4730 } else if (rd
->type
== RECDB_OBJECT
) {
4731 dict_t obj
= GET_RECORD_OBJECT(rd
);
4732 /* new style structure */
4733 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
4734 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
4735 expires
= str
? ParseInterval(str
) : 0;
4736 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
4737 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
4738 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
4739 issued
= str
? ParseInterval(str
) : 0;
4743 if (expires
&& (expires
< now
))
4745 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
4750 add_routing_plan_server(const char *name
, void *data
, void *rp
)
4752 struct record_data
*rd
= data
;
4753 const char *uplink
, *portstr
, *karma
, *second
, *offline
;
4755 dict_t obj
= GET_RECORD_OBJECT(rd
);
4756 if(rd
->type
== RECDB_OBJECT
) {
4757 uplink
= database_get_data(obj
, KEY_UPLINK
, RECDB_QSTRING
);
4758 second
= database_get_data(obj
, KEY_SECOND
, RECDB_QSTRING
);
4759 portstr
= database_get_data(obj
, KEY_PORT
, RECDB_QSTRING
);
4760 karma
= database_get_data(obj
, KEY_KARMA
, RECDB_QSTRING
);
4761 offline
= database_get_data(obj
, KEY_OFFLINE
, RECDB_QSTRING
);
4762 /* create routing plan server named key, with uplink uplink. */
4763 opserv_routing_plan_add_server(rp
, name
, uplink
, portstr
? atoi(portstr
) : 0,
4764 karma
? atoi(karma
) : KARMA_DEFAULT
, second
,
4765 offline
? atoi(offline
) : 0);
4772 routing_plan_set_option(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4774 struct record_data
*rd
= data
;
4775 if(rd
->type
== RECDB_QSTRING
)
4777 char *value
= GET_RECORD_QSTRING(rd
);
4778 dict_insert(opserv_routing_plan_options
, strdup(name
), strdup(value
));
4784 add_routing_plan(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4786 struct record_data
*rd
= data
;
4787 struct routingPlan
*rp
;
4789 if(rd
->type
== RECDB_OBJECT
) {
4790 dict_t obj
= GET_RECORD_OBJECT(rd
);
4791 rp
= opserv_add_routing_plan(name
);
4792 dict_foreach(obj
, add_routing_plan_server
, rp
);
4798 opserv_saxdb_read(struct dict
*conf_db
)
4801 struct record_data
*rd
;
4805 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
4806 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
4807 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
4809 case RECDB_STRING_LIST
:
4810 /* Add words one by one just in case there are overlaps from an old DB. */
4811 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4812 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
4815 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
4816 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
4818 if (rd
->type
== RECDB_STRING_LIST
)
4819 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
4820 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4827 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
4828 && (rd
->type
== RECDB_STRING_LIST
)) {
4829 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4830 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4832 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
4834 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
4835 max_clients
= atoi(str
);
4836 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
4837 max_clients_time
= atoi(str
);
4839 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
4840 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
4841 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
4842 dict_foreach(object
, add_gag_helper
, NULL
);
4843 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
4844 dict_foreach(object
, add_user_alert
, NULL
);
4846 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
4847 dict_foreach(object, add_chan_warn, NULL);
4850 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN
, RECDB_OBJECT
)))
4851 dict_foreach(object
, add_routing_plan
, NULL
);
4853 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN_OPTIONS
, RECDB_OBJECT
)))
4854 dict_foreach(object
, routing_plan_set_option
, NULL
);
4860 opserv_saxdb_write(struct saxdb_context
*ctx
)
4862 struct string_list
*slist
;
4865 /* reserved nicks */
4866 if (dict_size(opserv_reserved_nick_dict
)) {
4867 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
4868 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
4869 struct userNode
*user
= iter_data(it
);
4870 if (!IsPersistent(user
)) continue;
4871 saxdb_start_record(ctx
, iter_key(it
), 0);
4872 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
4873 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
4874 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
4875 saxdb_end_record(ctx
);
4877 saxdb_end_record(ctx
);
4880 if (opserv_bad_words
->used
) {
4881 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
4883 /* routing plan options */
4884 if (dict_size(opserv_routing_plan_options
)) {
4885 saxdb_start_record(ctx
, KEY_ROUTINGPLAN_OPTIONS
, 1);
4886 for(it
= dict_first(opserv_routing_plan_options
); it
; it
= iter_next(it
)) {
4887 saxdb_write_string(ctx
, iter_key(it
), iter_data(it
));
4889 saxdb_end_record(ctx
);
4892 if (dict_size(opserv_routing_plans
)) {
4893 dict_iterator_t svrit
;
4894 struct routingPlan
*rp
;
4895 struct routingPlanServer
*rps
;
4896 saxdb_start_record(ctx
, KEY_ROUTINGPLAN
, 1);
4897 for (it
= dict_first(opserv_routing_plans
); it
; it
= iter_next(it
)) {
4899 saxdb_start_record(ctx
, iter_key(it
), 0);
4900 for(svrit
= dict_first(rp
->servers
); svrit
; svrit
= iter_next(svrit
)) {
4902 rps
= iter_data(svrit
);
4903 saxdb_start_record(ctx
, iter_key(svrit
), 0);
4904 saxdb_write_string(ctx
, KEY_UPLINK
, rps
->uplink
);
4905 if(rps
->secondaryuplink
)
4906 saxdb_write_string(ctx
, KEY_SECOND
, rps
->secondaryuplink
);
4907 sprintf(buf
, "%d", rps
->port
);
4908 saxdb_write_string(ctx
, KEY_PORT
, buf
);
4909 sprintf(buf
, "%d", rps
->karma
);
4910 saxdb_write_string(ctx
, KEY_KARMA
, buf
);
4911 sprintf(buf
, "%d", rps
->offline
);
4912 saxdb_write_string(ctx
, KEY_OFFLINE
, buf
);
4913 saxdb_end_record(ctx
);
4915 saxdb_end_record(ctx
);
4917 saxdb_end_record(ctx
);
4919 /* insert exempt channel names */
4920 if (dict_size(opserv_exempt_channels
)) {
4921 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
4922 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
4923 string_list_append(slist
, strdup(iter_key(it
)));
4925 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
4926 free_string_list(slist
);
4928 /* trusted hosts takes a little more work */
4929 if (dict_size(opserv_trusted_hosts
)) {
4930 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
4931 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
4932 struct trusted_host
*th
= iter_data(it
);
4933 saxdb_start_record(ctx
, iter_key(it
), 0);
4934 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
4935 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
4936 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
4937 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
4938 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
4939 saxdb_end_record(ctx
);
4941 saxdb_end_record(ctx
);
4945 struct gag_entry
*gag
;
4946 saxdb_start_record(ctx
, KEY_GAGS
, 1);
4947 for (gag
= gagList
; gag
; gag
= gag
->next
) {
4948 saxdb_start_record(ctx
, gag
->mask
, 0);
4949 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
4950 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
4951 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
4952 saxdb_end_record(ctx
);
4954 saxdb_end_record(ctx
);
4956 /* channel warnings */
4958 if (dict_size(opserv_chan_warn)) {
4959 saxdb_start_record(ctx, KEY_WARN, 0);
4960 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
4961 saxdb_write_string(ctx, iter_key(it), iter_data(it));
4963 saxdb_end_record(ctx);
4967 if (dict_size(opserv_user_alerts
)) {
4968 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
4969 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
4970 struct opserv_user_alert
*alert
= iter_data(it
);
4971 const char *reaction
;
4972 saxdb_start_record(ctx
, iter_key(it
), 0);
4973 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
4974 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
4975 switch (alert
->reaction
) {
4976 case REACT_NOTICE
: reaction
= "notice"; break;
4977 case REACT_KILL
: reaction
= "kill"; break;
4978 // case REACT_SILENT: reaction = "silent"; break;
4979 case REACT_GLINE
: reaction
= "gline"; break;
4980 case REACT_TRACK
: reaction
= "track"; break;
4981 case REACT_SHUN
: reaction
= "shun"; break;
4982 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
4983 case REACT_SVSPART
: reaction
= "svspart"; break;
4984 case REACT_VERSION
: reaction
= "version"; break;
4985 case REACT_MARK
: reaction
= "mark"; break;
4988 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
4991 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
4992 saxdb_end_record(ctx
);
4994 saxdb_end_record(ctx
);
4997 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
4998 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
4999 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
5000 saxdb_end_record(ctx
);
5005 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
5007 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
5011 static MODCMD_FUNC(cmd_query
)
5013 struct record_data
*rd
;
5018 reply("OSMSG_OPTION_ROOT");
5019 conf_enum_root(query_keys_helper
, user
);
5023 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
5024 if (!(rd
= conf_get_node(nodename
))) {
5025 reply("OSMSG_UNKNOWN_OPTION", nodename
);
5029 if (rd
->type
== RECDB_QSTRING
)
5030 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
5031 else if (rd
->type
== RECDB_STRING_LIST
) {
5032 reply("OSMSG_OPTION_LIST", nodename
);
5033 if (rd
->d
.slist
->used
)
5034 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
5035 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
5037 reply("OSMSG_OPTION_LIST_EMPTY");
5038 } else if (rd
->type
== RECDB_OBJECT
) {
5039 reply("OSMSG_OPTION_KEYS", nodename
);
5040 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
5046 static MODCMD_FUNC(cmd_set
)
5048 struct record_data
*rd
;
5050 /* I originally wanted to be able to fully manipulate the config
5051 db with this, but i wussed out. feel free to fix this - you'll
5052 need to handle quoted strings which have been split, and likely
5053 invent a syntax for it. -Zoot */
5055 if (!(rd
= conf_get_node(argv
[1]))) {
5056 reply("OSMSG_SET_NOT_SET", argv
[1]);
5060 if (rd
->type
!= RECDB_QSTRING
) {
5061 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
5065 free(rd
->d
.qstring
);
5066 rd
->d
.qstring
= strdup(argv
[2]);
5067 conf_call_reload_funcs();
5068 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
5072 static MODCMD_FUNC(cmd_settime
)
5074 const char *srv_name_mask
= "*";
5075 time_t new_time
= now
;
5078 srv_name_mask
= argv
[1];
5080 new_time
= time(NULL
);
5081 irc_settime(srv_name_mask
, new_time
);
5082 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
5087 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
5092 discrim
= calloc(1, sizeof(*discrim
));
5093 discrim
->limit
= 250;
5094 discrim
->max_level
= ~0;
5095 discrim
->max_ts
= INT_MAX
;
5096 discrim
->domain_depth
= 2;
5097 discrim
->max_channels
= INT_MAX
;
5098 discrim
->authed
= -1;
5099 discrim
->info_space
= -1;
5100 discrim
->intra_dcmp
= 0;
5101 discrim
->intra_scmp
= 0;
5102 discrim
->use_regex
= 0;
5103 discrim
->silent
= 0;
5105 for (i
=0; i
<argc
; i
++) {
5106 if (irccasecmp(argv
[i
], "log") == 0) {
5107 discrim
->option_log
= 1;
5110 /* Assume all other criteria require arguments. */
5111 if (i
== argc
- 1) {
5112 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5115 if (argv
[i
+1][0] == '&') {
5116 /* Looking for intra-userNode matches */
5117 char *tmp
= &(argv
[i
+1][1]);
5118 if (strcasecmp(tmp
, argv
[i
]) != 0) { /* Don't allow "nick &nick" etc */
5119 if (!strcasecmp(tmp
, "nick"))
5120 discrim
->intra_dcmp
= 1;
5121 else if (!strcasecmp(tmp
, "ident"))
5122 discrim
->intra_dcmp
= 2;
5123 else if (!strcasecmp(tmp
, "info"))
5124 discrim
->intra_dcmp
= 3;
5127 if (irccasecmp(argv
[i
], "mask") == 0) {
5128 if (!is_ircmask(argv
[++i
])) {
5129 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5132 if (!split_ircmask(argv
[i
],
5133 &discrim
->mask_nick
,
5134 &discrim
->mask_ident
,
5135 &discrim
->mask_host
)) {
5136 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5139 } else if (irccasecmp(argv
[i
], "nick") == 0) {
5141 if (discrim
->intra_dcmp
> 0)
5142 discrim
->intra_scmp
= 1;
5144 discrim
->mask_nick
= argv
[i
];
5145 } else if (irccasecmp(argv
[i
], "ident") == 0) {
5147 if (discrim
->intra_dcmp
> 0)
5148 discrim
->intra_scmp
= 2;
5150 discrim
->mask_ident
= argv
[i
];
5151 } else if (irccasecmp(argv
[i
], "host") == 0) {
5152 discrim
->mask_host
= argv
[++i
];
5153 } else if (irccasecmp(argv
[i
], "info") == 0) {
5155 if (discrim
->intra_dcmp
> 0)
5156 discrim
->intra_scmp
= 3;
5158 discrim
->mask_info
= argv
[i
];
5159 } else if (irccasecmp(argv
[i
], "version") == 0) {
5160 discrim
->mask_version
= argv
[++i
];
5161 } else if (irccasecmp(argv
[i
], "server") == 0) {
5162 discrim
->server
= argv
[++i
];
5163 } else if (irccasecmp(argv
[i
], "ip") == 0) {
5164 j
= irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, argv
[++i
]);
5166 send_message(user
, bot
, "OSMSG_BAD_IP", argv
[i
]);
5169 } else if (irccasecmp(argv
[i
], "account") == 0) {
5170 if (discrim
->authed
== 0) {
5171 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5174 discrim
->accountmask
= argv
[++i
];
5175 discrim
->authed
= 1;
5176 } else if (irccasecmp(argv
[i
], "chantarget") == 0) {
5177 if(!IsChannelName(argv
[i
+1])) {
5178 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5181 discrim
->chantarget
= argv
[++i
];
5182 } else if (irccasecmp(argv
[i
], "mark") == 0) {
5183 if(!is_valid_mark(argv
[i
+1])) {
5184 send_message(user
, bot
, "OSMSG_MARK_INVALID");
5187 discrim
->mark
= argv
[++i
];
5188 } else if (irccasecmp(argv
[i
], "authed") == 0) {
5189 i
++; /* true_string and false_string are macros! */
5190 if (true_string(argv
[i
])) {
5191 discrim
->authed
= 1;
5192 } else if (false_string(argv
[i
])) {
5193 if (discrim
->accountmask
) {
5194 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5197 discrim
->authed
= 0;
5199 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5202 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
5203 /* XXX: A hack because you can't check explicitly for a space through
5204 * any other means */
5206 if (true_string(argv
[i
])) {
5207 discrim
->info_space
= 1;
5208 } else if (false_string(argv
[i
])) {
5209 discrim
->info_space
= 0;
5211 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5214 } else if (irccasecmp(argv
[i
], "regex") == 0) {
5216 if (true_string(argv
[i
])) {
5217 discrim
->use_regex
= 1;
5218 } else if (false_string(argv
[i
])) {
5219 discrim
->use_regex
= 0;
5221 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5224 } else if (irccasecmp(argv
[i
], "silent") == 0) {
5226 if(user
!= opserv
&& !oper_has_access(user
, opserv
, opserv_conf
.silent_level
, 0)) {
5228 } else if (true_string(argv
[i
])) {
5229 discrim
->silent
= 1;
5230 } else if (false_string(argv
[i
])) {
5231 discrim
->silent
= 0;
5233 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5236 } else if (irccasecmp(argv
[i
], "duration") == 0) {
5237 discrim
->duration
= ParseInterval(argv
[++i
]);
5238 } else if (irccasecmp(argv
[i
], "channel") == 0) {
5239 for (j
=0, i
++; ; j
++) {
5240 switch (argv
[i
][j
]) {
5244 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
5247 discrim
->chan_req_modes
|= MODE_VOICE
;
5248 discrim
->chan_no_modes
|= MODE_CHANOP
;
5249 discrim
->chan_no_modes
|= MODE_HALFOP
;
5252 discrim
->chan_req_modes
|= MODE_HALFOP
;
5253 discrim
->chan_no_modes
|= MODE_CHANOP
;
5254 discrim
->chan_no_modes
|= MODE_VOICE
;
5257 discrim
->chan_req_modes
|= MODE_CHANOP
;
5260 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5265 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
5266 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
5267 /* secretly "allow_channel" now means "if a channel name is
5268 * specified, require that it currently exist" */
5269 if (allow_channel
) {
5270 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
5273 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
5276 LockChannel(discrim
->channel
);
5277 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
5278 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
5279 } else if (irccasecmp(argv
[i
], "limit") == 0) {
5280 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
5281 } else if (irccasecmp(argv
[i
], "reason") == 0) {
5282 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
5284 } else if (irccasecmp(argv
[i
], "last") == 0) {
5285 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
5286 } else if ((irccasecmp(argv
[i
], "linked") == 0)
5287 || (irccasecmp(argv
[i
], "nickage") == 0)) {
5288 const char *cmp
= argv
[++i
];
5289 if (cmp
[0] == '<') {
5290 if (cmp
[1] == '=') {
5291 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5293 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
5295 } else if (cmp
[0] == '>') {
5296 if (cmp
[1] == '=') {
5297 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
5299 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
5302 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5304 } else if (irccasecmp(argv
[i
], "access") == 0) {
5305 const char *cmp
= argv
[++i
];
5306 if (cmp
[0] == '<') {
5307 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
5308 if (cmp
[1] == '=') {
5309 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
5311 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
5313 } else if (cmp
[0] == '=') {
5314 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
5315 } else if (cmp
[0] == '>') {
5316 if (cmp
[1] == '=') {
5317 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5319 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
5322 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5324 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
5325 && (irccasecmp(argv
[++i
], "opers") == 0)) {
5326 discrim
->match_opers
= 1;
5327 } else if (irccasecmp(argv
[i
], "depth") == 0) {
5328 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
5329 } else if (irccasecmp(argv
[i
], "clones") == 0) {
5330 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
5332 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
5337 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
5338 discrim
->mask_nick
= 0;
5340 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
5341 discrim
->mask_ident
= 0;
5343 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
5344 discrim
->mask_info
= 0;
5346 if (discrim
->mask_version
&& !strcmp(discrim
->mask_version
, "*")) {
5347 discrim
->mask_version
= 0;
5349 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
5350 discrim
->mask_host
= 0;
5353 if(discrim
->use_regex
)
5355 if(discrim
->mask_nick
)
5357 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5358 discrim
->has_regex_nick
= !err
;
5362 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
5364 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
5369 if(discrim
->mask_ident
)
5371 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5372 discrim
->has_regex_ident
= !err
;
5376 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
5378 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
5383 if(discrim
->mask_host
)
5385 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5386 discrim
->has_regex_host
= !err
;
5390 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
5392 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
5397 if(discrim
->mask_info
)
5399 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5400 discrim
->has_regex_info
= !err
;
5404 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
5406 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
5411 if(discrim
->mask_version
)
5413 int err
= regcomp(&discrim
->regex_version
, discrim
->mask_version
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5414 discrim
->has_regex_version
= !err
;
5418 buff
[regerror(err
, &discrim
->regex_version
, buff
, sizeof(buff
))] = 0;
5420 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_version
, buff
, err
);
5433 if(discrim
->has_regex_nick
)
5434 regfree(&discrim
->regex_nick
);
5435 if(discrim
->has_regex_ident
)
5436 regfree(&discrim
->regex_ident
);
5437 if(discrim
->has_regex_host
)
5438 regfree(&discrim
->regex_host
);
5439 if(discrim
->has_regex_info
)
5440 regfree(&discrim
->regex_info
);
5447 discrim_match(discrim_t discrim
, struct userNode
*user
)
5449 unsigned int access
;
5450 char *scmp
=NULL
, *dcmp
=NULL
;
5452 if ((user
->timestamp
< discrim
->min_ts
)
5453 || (user
->timestamp
> discrim
->max_ts
)
5454 || (user
->channels
.used
< discrim
->min_channels
)
5455 || (user
->channels
.used
> discrim
->max_channels
)
5456 || (discrim
->authed
== 0 && user
->handle_info
)
5457 || (discrim
->authed
== 1 && !user
->handle_info
)
5458 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
5459 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
5460 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
5461 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
5462 || (discrim
->ip_mask_bits
&& !irc_check_mask(&user
->ip
, &discrim
->ip_mask
, discrim
->ip_mask_bits
))
5466 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
))
5469 if(discrim
->use_regex
)
5471 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
5472 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
5473 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
5474 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))
5475 || (discrim
->has_regex_version
&& (!user
->version_reply
|| regexec(&discrim
->regex_version
, user
->version_reply
, 0, 0, 0)))) {
5481 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
5482 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
5483 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
5484 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))
5485 || (discrim
->mask_version
&& (!user
->version_reply
|| !match_ircglob(user
->version_reply
, discrim
->mask_version
))) ) {
5490 if ((discrim
->intra_scmp
> 0 && discrim
->intra_dcmp
> 0)) {
5491 switch(discrim
->intra_scmp
) {
5492 case 1: scmp
=user
->nick
; break;
5493 case 2: scmp
=user
->ident
; break;
5496 if (discrim
->info_space
== 1) scmp
++;
5499 switch(discrim
->intra_dcmp
) {
5500 case 1: dcmp
=user
->nick
; break;
5501 case 2: dcmp
=user
->ident
; break;
5502 case 3: /* When checking INFO, and info_space is enabled
5503 * ignore the first character in a search
5504 * XXX: Should we ignore ALL leading whitespace?
5505 * Also, what about ignoring ~ in ident?
5508 if (discrim
->info_space
== 1) dcmp
++;
5511 if (irccasecmp(scmp
,dcmp
))
5515 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
5516 if ((access
< discrim
->min_level
)
5517 || (access
> discrim
->max_level
)) {
5520 if (discrim
->min_clones
> 1) {
5521 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&user
->ip
), NULL
);
5522 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
))
5529 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
5531 unsigned int nn
, count
;
5532 struct userList matched
;
5534 userList_init(&matched
);
5535 /* Try most optimized search methods first */
5536 if (discrim
->channel
) {
5538 (nn
< discrim
->channel
->members
.used
)
5539 && (matched
.used
< discrim
->limit
);
5541 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
5542 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
5543 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
5546 if (discrim_match(discrim
, mn
->user
)) {
5547 userList_append(&matched
, mn
->user
);
5550 } else if (discrim
->ip_mask_bits
== 128) {
5551 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&discrim
->ip_mask
), NULL
);
5553 userList_clean(&matched
);
5556 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
5557 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
5558 userList_append(&matched
, ohi
->clients
.list
[nn
]);
5563 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
5564 if (discrim_match(discrim
, iter_data(it
))) {
5565 userList_append(&matched
, iter_data(it
));
5570 if (!matched
.used
) {
5571 userList_clean(&matched
);
5575 if (discrim
->option_log
) {
5576 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
5578 for (nn
=0; nn
<matched
.used
; nn
++) {
5579 struct userNode
*user
= matched
.list
[nn
];
5580 if (discrim
->option_log
) {
5581 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
5583 if (dsf(user
, data
)) {
5584 /* If a search function returns true, it ran into a
5585 problem. Stop going through the list. */
5589 if (discrim
->option_log
) {
5590 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
5592 count
= matched
.used
;
5593 userList_clean(&matched
);
5598 trace_print_func(struct userNode
*match
, void *extra
)
5600 struct discrim_and_source
*das
= extra
;
5601 if (match
->handle_info
) {
5602 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
);
5604 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
5610 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
5616 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
5618 return !(IsService(target
)
5619 || (!match_opers
&& IsOper(target
))
5620 || (target
->handle_info
5621 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
5625 trace_gline_func(struct userNode
*match
, void *extra
)
5627 struct discrim_and_source
*das
= extra
;
5629 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5630 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
, das
->discrim
->silent
);
5637 trace_shun_func(struct userNode
*match
, void *extra
)
5639 struct discrim_and_source
*das
= extra
;
5641 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5642 opserv_shun(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
5649 trace_kill_func(struct userNode
*match
, void *extra
)
5651 struct discrim_and_source
*das
= extra
;
5653 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5655 if (das
->discrim
->reason
) {
5656 reason
= das
->discrim
->reason
;
5658 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
5659 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
5661 DelUser(match
, opserv
, 1, reason
);
5668 trace_mark_func(struct userNode
*match
, void *extra
)
5670 struct discrim_and_source
*das
= extra
;
5671 char *mark
= das
->discrim
->mark
;
5675 irc_mark(match
, mark
);
5680 trace_svsjoin_func(struct userNode
*match
, void *extra
)
5682 struct discrim_and_source
*das
= extra
;
5684 char *channame
= das
->discrim
->chantarget
;
5685 struct chanNode
*channel
;
5687 if(!channame
|| !IsChannelName(channame
)) {
5688 //reply("MSG_NOT_CHANNEL_NAME");
5692 if (!(channel
= GetChannel(channame
))) {
5693 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
5695 if (GetUserMode(channel
, match
)) {
5696 // reply("OSMSG_ALREADY_THERE", channel->name);
5699 irc_svsjoin(opserv
, match
, channel
);
5700 // reply("OSMSG_SVSJOIN_SENT");
5705 trace_svspart_func(struct userNode
*match
, void *extra
)
5707 struct discrim_and_source
*das
= extra
;
5708 char *channame
= das
->discrim
->chantarget
;
5709 struct chanNode
*channel
;
5711 if(!channame
|| !IsChannelName(channame
))
5714 if (!(channel
= GetChannel(channame
)))
5717 if (!GetUserMode(channel
, match
))
5720 irc_svspart(opserv
, match
, channel
);
5725 trace_version_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
5727 irc_version_user(opserv
, match
);
5732 is_gagged(char *mask
)
5734 struct gag_entry
*gag
;
5736 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5737 if (match_ircglobs(gag
->mask
, mask
)) return 1;
5743 trace_gag_func(struct userNode
*match
, void *extra
)
5745 struct discrim_and_source
*das
= extra
;
5747 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5748 char *reason
, *mask
;
5750 if (das
->discrim
->reason
) {
5751 reason
= das
->discrim
->reason
;
5753 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
5754 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
5756 masksize
= 5+strlen(match
->hostname
);
5757 mask
= alloca(masksize
);
5758 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
5759 if (!is_gagged(mask
)) {
5760 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
5761 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
5769 trace_domains_func(struct userNode
*match
, void *extra
)
5771 struct discrim_and_source
*das
= extra
;
5773 unsigned long *count
;
5776 char ipmask
[IRC_NTOP_MASK_MAX_SIZE
];
5778 if (irc_pton(&ip
, NULL
, match
->hostname
)) {
5779 if (irc_in_addr_is_ipv4(ip
)) {
5780 unsigned long matchip
= ntohl(ip
.in6_32
[3]);
5781 /* raw IP address.. use up to first three octets of IP */
5782 switch (das
->discrim
->domain_depth
) {
5784 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
5787 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
5790 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
5793 } else if (irc_in_addr_is_ipv6(ip
)) {
5794 switch (das
->discrim
->domain_depth
) {
5795 case 1: depth
= 16; goto ipv6_pfx
;
5796 case 2: depth
= 24; goto ipv6_pfx
;
5797 case 3: depth
= 32; goto ipv6_pfx
;
5798 default: depth
= das
->discrim
->domain_depth
;
5800 irc_ntop_mask(ipmask
, sizeof(ipmask
), &ip
, depth
);
5802 } else safestrncpy(ipmask
, match
->hostname
, sizeof(ipmask
));
5803 ipmask
[sizeof(ipmask
) - 1] = '\0';
5806 hostname
= match
->hostname
+ strlen(match
->hostname
);
5807 for (depth
=das
->discrim
->domain_depth
;
5808 depth
&& (hostname
> match
->hostname
);
5811 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
5813 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
5815 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
5816 count
= calloc(1, sizeof(*count
));
5817 dict_insert(das
->dict
, strdup(hostname
), count
);
5824 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
5826 unsigned long *count
= data
;
5827 struct discrim_and_source
*das
= extra
;
5829 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
5830 return !--das
->disp_limit
;
5833 static MODCMD_FUNC(cmd_trace
)
5835 struct discrim_and_source das
;
5836 discrim_search_func action
;
5837 unsigned int matches
;
5838 struct svccmd
*subcmd
;
5842 sprintf(buf
, "trace %s", argv
[1]);
5843 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
5844 reply("OSMSG_BAD_ACTION", argv
[1]);
5847 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
5849 if (!irccasecmp(argv
[1], "print"))
5850 action
= trace_print_func
;
5851 else if (!irccasecmp(argv
[1], "count"))
5852 action
= trace_count_func
;
5853 else if (!irccasecmp(argv
[1], "domains"))
5854 action
= trace_domains_func
;
5855 else if (!irccasecmp(argv
[1], "gline"))
5856 action
= trace_gline_func
;
5857 else if (!irccasecmp(argv
[1], "shun"))
5858 action
= trace_shun_func
;
5859 else if (!irccasecmp(argv
[1], "kill"))
5860 action
= trace_kill_func
;
5861 else if (!irccasecmp(argv
[1], "gag"))
5862 action
= trace_gag_func
;
5863 else if (!irccasecmp(argv
[1], "svsjoin"))
5864 action
= trace_svsjoin_func
;
5865 else if (!irccasecmp(argv
[1], "svspart"))
5866 action
= trace_svspart_func
;
5867 else if (!irccasecmp(argv
[1], "version"))
5868 action
= trace_version_func
;
5869 else if (!irccasecmp(argv
[1], "mark"))
5870 action
= trace_mark_func
;
5872 reply("OSMSG_BAD_ACTION", argv
[1]);
5876 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
5877 reply("OSMSG_LEVEL_TOO_LOW");
5883 das
.destination
= cmd
->parent
->bot
;
5884 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
5888 if (action
== trace_print_func
)
5890 reply("OSMSG_USER_SEARCH_RESULTS");
5891 reply("OSMSG_USER_SEARCH_BAR");
5892 reply("OSMSG_USER_SEARCH_HEADER");
5893 reply("OSMSG_USER_SEARCH_BAR");
5895 else if (action
== trace_count_func
)
5896 das
.discrim
->limit
= INT_MAX
;
5897 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
5898 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
5899 else if ((action
== trace_shun_func
) && !das
.discrim
->duration
)
5900 das
.discrim
->duration
= opserv_conf
.block_shun_duration
;
5901 else if (action
== trace_domains_func
) {
5902 das
.dict
= dict_new();
5903 dict_set_free_data(das
.dict
, free
);
5904 dict_set_free_keys(das
.dict
, free
);
5905 das
.disp_limit
= das
.discrim
->limit
;
5906 das
.discrim
->limit
= INT_MAX
;
5909 if (action
== trace_svsjoin_func
&& !das
.discrim
->chantarget
) {
5910 reply("OSMSG_SVSJOIN_NO_TARGET");
5913 else if (action
== trace_svspart_func
&& !das
.discrim
->chantarget
) {
5914 reply("OSMSG_SVSPART_NO_TARGET");
5917 else if (action
== trace_mark_func
&& !das
.discrim
->mark
) {
5918 reply("OSMSG_MARK_NO_MARK");
5922 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
5924 if (action
== trace_domains_func
)
5925 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
5929 if(action
== trace_print_func
)
5930 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
5932 reply("OSMSG_USER_SEARCH_COUNT", matches
);
5935 reply("MSG_NO_MATCHES");
5938 if (das
.discrim
->channel
)
5939 UnlockChannel(das
.discrim
->channel
);
5940 free(das
.discrim
->reason
);
5942 if(das
.discrim
->has_regex_nick
)
5943 regfree(&das
.discrim
->regex_nick
);
5944 if(das
.discrim
->has_regex_ident
)
5945 regfree(&das
.discrim
->regex_ident
);
5946 if(das
.discrim
->has_regex_host
)
5947 regfree(&das
.discrim
->regex_host
);
5948 if(das
.discrim
->has_regex_info
)
5949 regfree(&das
.discrim
->regex_info
);
5950 if(das
.discrim
->has_regex_version
)
5951 regfree(&das
.discrim
->regex_version
);
5954 dict_delete(das
.dict
);
5958 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
5960 typedef struct channel_discrim
{
5963 unsigned int min_users
, max_users
;
5964 time_t min_ts
, max_ts
;
5968 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
5969 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
5972 smart_parse_time(const char *str
) {
5973 /* If an interval-style string is given, treat as time before now.
5974 * If it's all digits, treat directly as a Unix timestamp. */
5975 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
5979 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
5984 discrim
= calloc(1, sizeof(*discrim
));
5985 discrim
->limit
= 25;
5987 for (i
= 0; i
< argc
; i
++) {
5988 /* Assume all criteria require arguments. */
5989 if (i
== (argc
- 1)) {
5990 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5994 if (!irccasecmp(argv
[i
], "name"))
5995 discrim
->name
= argv
[++i
];
5996 else if (!irccasecmp(argv
[i
], "topic"))
5997 discrim
->topic
= argv
[++i
];
5998 else if (!irccasecmp(argv
[i
], "users")) {
5999 const char *cmp
= argv
[++i
];
6000 if (cmp
[0] == '<') {
6002 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
6004 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
6005 } else if (cmp
[0] == '=') {
6006 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
6007 } else if (cmp
[0] == '>') {
6009 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6011 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
6013 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6015 } else if (!irccasecmp(argv
[i
], "timestamp")) {
6016 const char *cmp
= argv
[++i
];
6017 if (cmp
[0] == '<') {
6019 discrim
->max_ts
= smart_parse_time(cmp
+2);
6021 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
6022 } else if (cmp
[0] == '=') {
6023 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
6024 } else if (cmp
[0] == '>') {
6026 discrim
->min_ts
= smart_parse_time(cmp
+2);
6028 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
6030 discrim
->min_ts
= smart_parse_time(cmp
);
6032 } else if (!irccasecmp(argv
[i
], "limit")) {
6033 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
6035 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
6040 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
6042 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
6052 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
6054 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
6055 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
6056 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
6057 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
6058 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
6059 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
6065 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
6067 unsigned int count
= 0;
6068 dict_iterator_t it
, next
;
6070 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
6071 struct chanNode
*chan
= iter_data(it
);
6073 /* Hold on to the next channel in case we decide to
6074 add actions that destructively modify the channel. */
6075 next
= iter_next(it
);
6076 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
6077 dsf(chan
, data
, bot
);
6085 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
6089 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
6092 irc_make_chanmode(channel
, modes
);
6093 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
6096 static MODCMD_FUNC(cmd_csearch
)
6099 unsigned int matches
;
6100 cdiscrim_search_func action
;
6101 struct svccmd
*subcmd
;
6104 if (!irccasecmp(argv
[1], "count"))
6105 action
= channel_count
;
6106 else if (!irccasecmp(argv
[1], "print"))
6107 action
= channel_print
;
6109 reply("OSMSG_BAD_ACTION", argv
[1]);
6113 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6114 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6115 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6119 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
6123 if (action
== channel_print
)
6124 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
6125 else if (action
== channel_count
)
6126 discrim
->limit
= INT_MAX
;
6128 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
6131 reply("MSG_MATCH_COUNT", matches
);
6133 reply("MSG_NO_MATCHES");
6139 static MODCMD_FUNC(cmd_gsync
)
6143 src
= GetServerH(argv
[1]);
6145 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6151 irc_stats(cmd
->parent
->bot
, src
, 'G');
6152 reply("OSMSG_GSYNC_RUNNING", src
->name
);
6156 static MODCMD_FUNC(cmd_ssync
)
6160 src
= GetServerH(argv
[1]);
6162 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6168 irc_stats(cmd
->parent
->bot
, src
, 'S');
6169 reply("OSMSG_SSYNC_RUNNING", src
->name
);
6173 struct gline_extra
{
6174 struct userNode
*user
;
6175 struct string_list
*glines
;
6176 struct userNode
*bot
;
6180 gtrace_print_func(struct gline
*gline
, void *extra
)
6182 struct gline_extra
*xtra
= extra
;
6183 char *when_text
, set_text
[20];
6184 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
6185 when_text
= asctime(localtime(&gline
->expires
));
6186 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6187 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
6191 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
6196 gtrace_ungline_func(struct gline
*gline
, void *extra
)
6198 struct gline_extra
*xtra
= extra
;
6199 string_list_append(xtra
->glines
, strdup(gline
->target
));
6202 static MODCMD_FUNC(cmd_gtrace
)
6204 struct gline_discrim
*discrim
;
6205 gline_search_func action
;
6206 unsigned int matches
, nn
;
6207 struct gline_extra extra
;
6208 struct svccmd
*subcmd
;
6211 if (!irccasecmp(argv
[1], "print"))
6212 action
= gtrace_print_func
;
6213 else if (!irccasecmp(argv
[1], "count"))
6214 action
= gtrace_count_func
;
6215 else if (!irccasecmp(argv
[1], "ungline"))
6216 action
= gtrace_ungline_func
;
6218 reply("OSMSG_BAD_ACTION", argv
[1]);
6221 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6222 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6223 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6227 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6231 if (action
== gtrace_print_func
)
6232 reply("OSMSG_GLINE_SEARCH_RESULTS");
6233 else if (action
== gtrace_count_func
)
6234 discrim
->limit
= INT_MAX
;
6237 extra
.glines
= alloc_string_list(4);
6238 extra
.bot
= cmd
->parent
->bot
;
6239 matches
= gline_discrim_search(discrim
, action
, &extra
);
6241 if (action
== gtrace_ungline_func
)
6242 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
6243 gline_remove(extra
.glines
->list
[nn
], 1);
6244 free_string_list(extra
.glines
);
6247 reply("MSG_MATCH_COUNT", matches
);
6249 reply("MSG_NO_MATCHES");
6250 free(discrim
->alt_target_mask
);
6256 struct userNode
*user
;
6257 struct string_list
*shuns
;
6258 struct userNode
*bot
;
6262 strace_print_func(struct shun
*shun
, void *extra
)
6264 struct shun_extra
*xtra
= extra
;
6265 char *when_text
, set_text
[20];
6266 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&shun
->issued
));
6267 when_text
= asctime(localtime(&shun
->expires
));
6268 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6269 send_message(xtra
->user
, xtra
->bot
, "OSMSG_STRACE_FORMAT", shun
->target
, set_text
, shun
->issuer
, when_text
, shun
->reason
);
6273 strace_count_func(UNUSED_ARG(struct shun
*shun
), UNUSED_ARG(void *extra
))
6278 strace_unshun_func(struct shun
*shun
, void *extra
)
6280 struct shun_extra
*xtra
= extra
;
6281 string_list_append(xtra
->shuns
, strdup(shun
->target
));
6284 static MODCMD_FUNC(cmd_strace
)
6286 struct shun_discrim
*discrim
;
6287 shun_search_func action
;
6288 unsigned int matches
, nn
;
6289 struct shun_extra extra
;
6290 struct svccmd
*subcmd
;
6293 if (!irccasecmp(argv
[1], "print"))
6294 action
= strace_print_func
;
6295 else if (!irccasecmp(argv
[1], "count"))
6296 action
= strace_count_func
;
6297 else if (!irccasecmp(argv
[1], "unshun"))
6298 action
= strace_unshun_func
;
6300 reply("OSMSG_BAD_ACTION", argv
[1]);
6303 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6304 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6305 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6309 discrim
= shun_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6313 if (action
== strace_print_func
)
6314 reply("OSMSG_SHUN_SEARCH_RESULTS");
6315 else if (action
== strace_count_func
)
6316 discrim
->limit
= INT_MAX
;
6319 extra
.shuns
= alloc_string_list(4);
6320 extra
.bot
= cmd
->parent
->bot
;
6321 matches
= shun_discrim_search(discrim
, action
, &extra
);
6323 if (action
== strace_unshun_func
)
6324 for (nn
=0; nn
<extra
.shuns
->used
; nn
++)
6325 shun_remove(extra
.shuns
->list
[nn
], 1);
6326 free_string_list(extra
.shuns
);
6329 reply("MSG_MATCH_COUNT", matches
);
6331 reply("MSG_NO_MATCHES");
6332 free(discrim
->alt_target_mask
);
6338 alert_check_user(const char *key
, void *data
, void *extra
)
6340 struct opserv_user_alert
*alert
= data
;
6341 struct userNode
*user
= extra
;
6343 if (!discrim_match(alert
->discrim
, user
))
6346 if ((alert
->reaction
!= REACT_NOTICE
)
6348 && !alert
->discrim
->match_opers
) {
6352 /* The user matches the alert criteria, so trigger the reaction. */
6353 if (alert
->discrim
->option_log
)
6354 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
);
6356 /* Return 1 to halt alert matching, such as when killing the user
6357 that triggered the alert. */
6358 switch (alert
->reaction
) {
6360 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
6363 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
, alert
->discrim
->silent
);
6366 opserv_shun(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
6369 opserv_svsjoin(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
);
6372 opserv_svspart(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
);
6375 /* Don't auto-version a user who we already have a version on, because the version reply itself
6376 * re-triggers this check...
6377 * TODO: maybe safer if we didn't even check react_version type alerts for the 2nd check?
6378 * sort of like we only look at channel alerts on join. -Rubin
6380 if(!user
->version_reply
)
6381 opserv_version(user
);
6384 opserv_mark(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->mark
);
6387 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
6388 /* fall through to REACT_NOTICE case */
6390 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
);
6394 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
);
6395 add_track_user(user
);
6403 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
6405 struct gag_entry
*gag
;
6406 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
6407 /* Gag them if appropriate (and only if). */
6408 user
->modes
&= ~FLAGS_GAGGED
;
6409 for (gag
= gagList
; gag
; gag
= gag
->next
) {
6410 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
6411 gag_helper_func(user
, NULL
);
6418 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
6422 if (!opserv_conf
.staff_auth_channel
6423 || user
->uplink
->burst
6424 || !user
->handle_info
)
6426 else if (user
->handle_info
->opserv_level
)
6428 else if (IsNetworkHelper(user
))
6429 type
= "NETWORK HELPER";
6430 else if (IsSupportHelper(user
))
6431 type
= "SUPPORT HELPER";
6435 if (irc_in_addr_is_valid(user
->ip
))
6436 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
6438 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
);
6441 static MODCMD_FUNC(cmd_log
)
6443 struct logSearch
*discrim
;
6444 unsigned int matches
;
6445 struct logReport report
;
6447 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
6451 reply("OSMSG_LOG_SEARCH_RESULTS");
6452 report
.reporter
= opserv
;
6454 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
6457 reply("MSG_MATCH_COUNT", matches
);
6459 reply("MSG_NO_MATCHES");
6466 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6468 if (IsOper(match
) || IsLocal(match
))
6470 match
->modes
|= FLAGS_GAGGED
;
6474 static MODCMD_FUNC(cmd_gag
)
6476 struct gag_entry
*gag
;
6477 unsigned int gagged
;
6478 unsigned long duration
;
6481 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
6483 if (!is_ircmask(argv
[1])) {
6484 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
6488 for (gag
= gagList
; gag
; gag
= gag
->next
)
6489 if (match_ircglobs(gag
->mask
, argv
[1]))
6493 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
6497 duration
= ParseInterval(argv
[2]);
6498 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
6501 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
6503 reply("OSMSG_GAG_ADDED", argv
[1]);
6508 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6510 match
->modes
&= ~FLAGS_GAGGED
;
6514 static MODCMD_FUNC(cmd_ungag
)
6516 struct gag_entry
*gag
;
6517 unsigned int ungagged
;
6519 for (gag
= gagList
; gag
; gag
= gag
->next
)
6520 if (!strcmp(gag
->mask
, argv
[1]))
6524 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
6528 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
6529 ungagged
= gag_free(gag
);
6532 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
6534 reply("OSMSG_UNGAG_ADDED", argv
[1]);
6538 static MODCMD_FUNC(cmd_addalert
)
6540 opserv_alert_reaction reaction
;
6541 struct svccmd
*subcmd
;
6546 sprintf(buf
, "addalert %s", argv
[2]);
6547 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6548 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6551 if (!irccasecmp(argv
[2], "notice"))
6552 reaction
= REACT_NOTICE
;
6553 else if (!irccasecmp(argv
[2], "kill"))
6554 reaction
= REACT_KILL
;
6555 else if (!irccasecmp(argv
[2], "gline"))
6556 reaction
= REACT_GLINE
;
6557 else if (!irccasecmp(argv
[2], "track")) {
6559 reply("OSMSG_TRACK_DISABLED");
6562 reaction
= REACT_TRACK
;
6564 } else if (!irccasecmp(argv
[2], "shun"))
6565 reaction
= REACT_SHUN
;
6566 else if(!irccasecmp(argv
[2], "svsjoin"))
6567 reaction
= REACT_SVSJOIN
;
6568 else if(!irccasecmp(argv
[2], "svspart"))
6569 reaction
= REACT_SVSPART
;
6570 else if(!irccasecmp(argv
[2], "version"))
6571 reaction
= REACT_VERSION
;
6572 else if(!irccasecmp(argv
[2], "mark"))
6573 reaction
= REACT_MARK
;
6575 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6578 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
6579 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
))) {
6580 reply("OSMSG_ALERT_ADD_FAILED");
6583 reply("OSMSG_ADDED_ALERT", name
);
6587 static MODCMD_FUNC(cmd_delalert
)
6590 for (i
=1; i
<argc
; i
++) {
6591 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
6592 dict_remove(opserv_channel_alerts
, argv
[i
]);
6593 if (dict_remove(opserv_user_alerts
, argv
[i
]))
6594 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
6596 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
6602 opserv_conf_read(void)
6604 struct chanNode
*chan
;
6606 struct record_data
*rd
;
6607 dict_t conf_node
, child
;
6608 const char *str
, *str2
;
6609 struct policer_params
*pp
;
6612 rd
= conf_get_node(OPSERV_CONF_NAME
);
6613 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
6614 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
6617 conf_node
= rd
->d
.object
;
6618 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
6619 if (opserv
&& str
) {
6620 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
6623 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6624 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
6626 opserv_conf
.debug_channel
= NULL
;
6628 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
6629 if (opserv
&& str
) {
6630 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
6633 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6634 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
6636 opserv_conf
.alert_channel
= NULL
;
6638 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
6639 if (opserv
&& str
) {
6640 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
6643 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6644 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
6646 opserv_conf
.staff_auth_channel
= NULL
;
6649 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
6650 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
6652 str
= database_get_data(conf_node
, KEY_SILENT_LEVEL
, RECDB_QSTRING
);
6653 opserv_conf
.silent_level
= str
? strtoul(str
, NULL
, 0): 700;
6655 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
6656 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
6657 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
6658 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
6659 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
6660 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
6661 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
6662 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
6663 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
6665 NickChange(opserv
, str
, 0);
6667 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
6668 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
6669 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
6670 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
6672 free_string_list(autojoin_channels
);
6673 autojoin_channels
= database_get_data(conf_node
, KEY_AUTOJOIN_CHANNELS
, RECDB_STRING_LIST
);
6675 if(autojoin_channels
)
6676 autojoin_channels
= string_list_copy(autojoin_channels
);
6678 if (autojoin_channels
&& opserv
) {
6679 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
6680 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
6681 AddChannelUser(opserv
, chan
)->modes
|= MODE_CHANOP
;
6685 str
= database_get_data(conf_node
, KEY_BLOCK_SHUN_DURATION
, RECDB_QSTRING
);
6686 opserv_conf
.block_shun_duration
= str
? ParseInterval(str
) : 3600;
6688 if (!opserv_conf
.join_policer_params
)
6689 opserv_conf
.join_policer_params
= policer_params_new();
6690 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
6691 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
6692 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
6693 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
6695 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
6696 struct chanNode
*cNode
= iter_data(it
);
6697 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
6700 if (opserv_conf
.new_user_policer
.params
)
6701 pp
= opserv_conf
.new_user_policer
.params
;
6703 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
6704 policer_params_set(pp
, "size", "200");
6705 policer_params_set(pp
, "drain-rate", "3");
6706 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
6707 dict_foreach(child
, set_policer_param
, pp
);
6709 /* Defcon configuration */
6711 str
= database_get_data(conf_node
, KEY_DEFCON1
, RECDB_QSTRING
);
6712 DefCon
[1] = str
? atoi(str
) : 415;
6713 str
= database_get_data(conf_node
, KEY_DEFCON2
, RECDB_QSTRING
);
6714 DefCon
[2] = str
? atoi(str
) : 159;
6715 str
= database_get_data(conf_node
, KEY_DEFCON3
, RECDB_QSTRING
);
6716 DefCon
[3] = str
? atoi(str
) : 31;
6717 str
= database_get_data(conf_node
, KEY_DEFCON4
, RECDB_QSTRING
);
6718 DefCon
[4] = str
? atoi(str
) : 23;
6721 str
= database_get_data(conf_node
, KEY_DEFCON_LEVEL
, RECDB_QSTRING
);
6722 DefConLevel
= str
? atoi(str
) : 5;
6724 str
= database_get_data(conf_node
, KEY_DEFCON_CHANMODES
, RECDB_QSTRING
);
6725 DefConChanModes
= str
? strdup(str
) : "+r";
6727 str
= database_get_data(conf_node
, KEY_DEFCON_SESSION_LIMIT
, RECDB_QSTRING
);
6728 DefConSessionLimit
= str
? atoi(str
) : 2;
6730 str
= database_get_data(conf_node
, KEY_DEFCON_TIMEOUT
, RECDB_QSTRING
);
6731 DefConTimeOut
= str
? ParseInterval(str
) : 900;
6733 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_DURATION
, RECDB_QSTRING
);
6734 DefConGlineExpire
= str
? ParseInterval(str
) : 300;
6736 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL
, RECDB_QSTRING
);
6737 GlobalOnDefcon
= str
? atoi(str
) : 0;
6739 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL_MORE
, RECDB_QSTRING
);
6740 GlobalOnDefconMore
= str
? atoi(str
) : 0;
6742 str
= database_get_data(conf_node
, KEY_DEFCON_MESSAGE
, RECDB_QSTRING
);
6743 DefConMessage
= str
? strdup(str
) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore";
6745 str
= database_get_data(conf_node
, KEY_DEFCON_OFF_MESSAGE
, RECDB_QSTRING
);
6746 DefConOffMessage
= str
? strdup(str
) : "Services are now back to normal, sorry for any inconvenience";
6748 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_REASON
, RECDB_QSTRING
);
6749 DefConGlineReason
= str
? strdup(str
) : "This network is currently not accepting connections, please try again later";
6752 /* lame way to export opserv_conf value to nickserv.c ... */
6754 opserv_conf_admin_level()
6756 return(opserv_conf
.admin_level
);
6760 opserv_db_init(void) {
6761 /* set up opserv_trusted_hosts dict */
6762 dict_delete(opserv_trusted_hosts
);
6763 opserv_trusted_hosts
= dict_new();
6764 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
6766 opserv_routing_plan_options
= dict_new();
6768 opserv_routing_plans
= dict_new();
6769 dict_set_free_data(opserv_routing_plans
, free_routing_plan
);
6770 /* set up opserv_chan_warn dict */
6772 /* alert trace notice channel #x replaces warnings
6773 dict_delete(opserv_chan_warn);
6774 opserv_chan_warn = dict_new();
6775 dict_set_free_keys(opserv_chan_warn, free);
6776 dict_set_free_data(opserv_chan_warn, free);
6778 /* set up opserv_user_alerts */
6779 dict_delete(opserv_channel_alerts
);
6780 opserv_channel_alerts
= dict_new();
6781 dict_delete(opserv_nick_based_alerts
);
6782 opserv_nick_based_alerts
= dict_new();
6783 dict_delete(opserv_user_alerts
);
6784 opserv_user_alerts
= dict_new();
6785 dict_set_free_keys(opserv_user_alerts
, free
);
6786 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
6787 /* set up opserv_bad_words */
6788 free_string_list(opserv_bad_words
);
6789 opserv_bad_words
= alloc_string_list(4);
6790 /* and opserv_exempt_channels */
6791 dict_delete(opserv_exempt_channels
);
6792 opserv_exempt_channels
= dict_new();
6793 dict_set_free_keys(opserv_exempt_channels
, free
);
6797 opserv_db_cleanup(void)
6801 /* dict_delete(opserv_chan_warn); */
6802 dict_delete(opserv_reserved_nick_dict
);
6803 free_string_list(opserv_bad_words
);
6804 dict_delete(opserv_exempt_channels
);
6805 dict_delete(opserv_trusted_hosts
);
6806 unreg_del_user_func(opserv_user_cleanup
);
6807 dict_delete(opserv_hostinfo_dict
);
6808 dict_delete(opserv_nick_based_alerts
);
6809 dict_delete(opserv_channel_alerts
);
6810 dict_delete(opserv_user_alerts
);
6811 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
6812 free(level_strings
[nn
]);
6815 policer_params_delete(opserv_conf
.join_policer_params
);
6816 policer_params_delete(opserv_conf
.new_user_policer
.params
);
6820 init_opserv(const char *nick
)
6822 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
6824 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
6825 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
6827 conf_register_reload(opserv_conf_read
);
6829 memset(level_strings
, 0, sizeof(level_strings
));
6830 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
6831 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
6832 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
6833 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
6834 opserv_define_func("ADDALERT SILENT", NULL
, 900, 0, 0);
6835 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
6836 opserv_define_func("ADDALERT SHUN", NULL
, 900, 0, 0);
6837 opserv_define_func("ADDALERT TRACK", NULL
, 900, 0, 0);
6838 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
6839 opserv_define_func("ADDALERT SVSJOIN", NULL
, 999, 0, 0);
6840 opserv_define_func("ADDALERT SVSPART", NULL
, 999, 0, 0);
6841 opserv_define_func("ADDALERT VERSION", NULL
, 999, 0, 0);
6842 opserv_define_func("ADDALERT MARK", NULL
, 999, 0, 0);
6843 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
6844 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
6845 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
6846 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
6847 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
6848 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
6849 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
6850 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
6851 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
6852 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
6853 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
6854 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
6855 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
6856 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
6857 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
6858 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
6859 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
6860 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
6861 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
6862 opserv_define_func("DEFCON", cmd_defcon
, 900, 0, 0);
6863 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
6864 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
6865 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
6866 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
6867 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
6868 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
6869 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
6870 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
6871 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
6872 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
6873 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
6874 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
6875 opserv_define_func("SBLOCK", cmd_sblock
, 100, 0, 2);
6876 opserv_define_func("SHUN", cmd_shun
, 600, 0, 4);
6877 opserv_define_func("SSYNC", cmd_ssync
, 600, 0, 0);
6878 opserv_define_func("STRACE", cmd_strace
, 100, 0, 3);
6879 opserv_define_func("STRACE COUNT", NULL
, 0, 0, 0);
6880 opserv_define_func("STRACE PRINT", NULL
, 0, 0, 0);
6881 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
6882 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
6883 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
6884 opserv_define_func("SVSJOIN", cmd_svsjoin
, 999, 0, 3);
6885 opserv_define_func("SVSPART", cmd_svspart
, 999, 0, 3);
6886 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
6887 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
6888 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
6889 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
6890 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
6891 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
6892 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
6893 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
6894 opserv_define_func("MARK", cmd_mark
, 900, 0, 3);
6895 opserv_define_func("OP", cmd_op
, 100, 2, 2);
6896 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
6897 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
6898 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
6899 opserv_define_func("MAP", cmd_stats_links
, 0, 0, 0);
6900 opserv_define_func("PRIVSET", cmd_privset
, 900, 0, 3);
6901 opserv_define_func("PART", cmd_part
, 601, 0, 2);
6902 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
6903 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
6904 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
6905 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
6906 opserv_define_func("REFRESHS", cmd_refreshs
, 600, 0, 0);
6907 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
6908 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
6909 opserv_define_func("RESETMAX", cmd_resetmax
, 900, 0, 0);
6910 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
6911 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
6912 opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan
, 800, 0, 2);
6913 opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan
, 800, 0, 2);
6914 opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver
, 800, 0, 4);
6915 opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver
, 800, 0, 3);
6916 opserv_define_func("ROUTING MAP", cmd_routing_map
, 800, 0, 0);
6917 opserv_define_func("ROUTING SET", cmd_routing_set
, 800, 0, 0);
6918 opserv_define_func("REROUTE", cmd_reroute
, 800, 0, 2);
6919 opserv_define_func("SET", cmd_set
, 900, 0, 3);
6920 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
6921 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
6922 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
6923 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
6924 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
6925 opserv_define_func("STATS SHUNS", cmd_stats_shuns
, 0, 0, 0);
6926 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
6927 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
6928 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
6929 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
6930 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
6931 opserv_define_func("STATS ROUTING", cmd_stats_routing_plans
, 0, 0, 0);
6932 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
6933 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
6934 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
6935 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
6936 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
6937 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
6938 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
6940 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
6941 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
6942 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
6943 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
6944 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
6945 opserv_define_func("TRACE SHUN", NULL
, 600, 0, 0);
6946 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
6947 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
6948 opserv_define_func("TRACE VERSION", NULL
, 999, 0, 0);
6949 opserv_define_func("TRACE SVSJOIN", NULL
, 999, 0, 0);
6950 opserv_define_func("TRACE SVSPART", NULL
, 999, 0, 0);
6951 opserv_define_func("TRACE MARK", NULL
, 999, 0, 0);
6952 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
6953 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
6954 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
6955 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
6956 opserv_define_func("UNSHUN", cmd_unshun
, 600, 0, 2);
6957 modcmd_register(opserv_module
, "GTRACE UNSHUN", NULL
, 0, 0, "template", "unshun", NULL
);
6958 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
6959 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
6960 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
6961 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
6962 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
6963 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
6965 opserv_reserved_nick_dict
= dict_new();
6966 opserv_hostinfo_dict
= dict_new();
6968 dict_set_free_keys(opserv_hostinfo_dict
, free
);
6969 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
6971 opserv_waiting_connections
= dict_new();
6972 dict_set_free_data(opserv_waiting_connections
, opserv_free_waiting_connection
);
6974 reg_new_user_func(opserv_new_user_check
);
6975 reg_nick_change_func(opserv_alert_check_nick
);
6976 reg_del_user_func(opserv_user_cleanup
);
6977 reg_new_channel_func(opserv_channel_check
);
6978 reg_del_channel_func(opserv_channel_delete
);
6979 reg_join_func(opserv_join_check
);
6980 reg_auth_func(opserv_staff_alert
);
6981 reg_notice_func(opserv
, opserv_notice_handler
);
6984 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
6987 opserv_service
= service_register(opserv
);
6988 opserv_service
->trigger
= '?';
6991 /* start auto-routing system */
6992 /* this cant be done here, because the routing system isnt marked active yet. */
6993 /* reroute_timer(NULL); */
6995 /* start the karma timer, using the saved one if available */
6996 routing_karma_timer(dict_find(opserv_routing_plan_options
, "KARMA_TIMER", NULL
));
6998 reg_exit_func(opserv_db_cleanup
);
6999 message_register_table(msgtab
);