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.
36 #include <tre/regex.h>
38 #ifdef HAVE_SYS_TIMES_H
39 #include <sys/times.h>
41 #ifdef HAVE_NETINET_IN_H
42 #include <netinet/in.h>
44 #ifdef HAVE_ARPA_INET_H
45 #include <arpa/inet.h>
49 #define OPSERV_CONF_NAME "services/opserv"
51 #define KEY_ALERT_CHANNEL "alert_channel"
52 #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes"
53 #define KEY_DEBUG_CHANNEL "debug_channel"
54 #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes"
55 #define KEY_UNTRUSTED_MAX "untrusted_max"
56 #define KEY_PURGE_LOCK_DELAY "purge_lock_delay"
57 #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate"
58 #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold"
59 #define KEY_NICK "nick"
60 #define KEY_JOIN_POLICER "join_policer"
61 #define KEY_NEW_USER_POLICER "new_user_policer"
62 #define KEY_AUTOJOIN_CHANNELS "autojoin_channels"
63 #define KEY_REASON "reason"
64 #define KEY_RESERVES "reserves"
65 #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */
66 #define KEY_HOSTNAME "hostname"
67 #define KEY_DESC "description"
68 #define KEY_BAD_WORDS "bad"
69 #define KEY_EXEMPT_CHANNELS "exempt"
70 #define KEY_SECRET_WORDS "secret"
71 #define KEY_TRUSTED_HOSTS "trusted"
72 #define KEY_OWNER "owner"
73 #define KEY_GAGS "gags"
74 #define KEY_ALERTS "alerts"
75 #define KEY_REACTION "reaction"
76 #define KEY_DISCRIM "discrim"
77 #define KEY_WARN "chanwarn"
79 #define KEY_TIME "time"
80 #define KEY_MAX_CLIENTS "max_clients"
81 #define KEY_LIMIT "limit"
82 #define KEY_EXPIRES "expires"
83 #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel"
84 #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes"
85 #define KEY_CLONE_GLINE_DURATION "clone_gline_duration"
86 #define KEY_BLOCK_GLINE_DURATION "block_gline_duration"
87 #define KEY_BLOCK_SHUN_DURATION "block_shun_duration"
88 #define KEY_ISSUER "issuer"
89 #define KEY_ISSUED "issued"
90 #define KEY_ADMIN_LEVEL "admin_level"
91 #define KEY_SILENT_LEVEL "silent_level"
92 #define KEY_UPLINK "uplink"
93 #define KEY_SECOND "secondaryuplink"
94 #define KEY_PORT "port"
95 #define KEY_KARMA "karma"
96 #define KEY_OFFLINE "offline"
97 #define KEY_ROUTINGPLAN "routingplan"
98 #define KEY_ROUTINGPLAN_OPTIONS "routingplan_options"
99 #define KEY_DEFCON1 "DefCon1"
100 #define KEY_DEFCON2 "DefCon2"
101 #define KEY_DEFCON3 "DefCon3"
102 #define KEY_DEFCON4 "DefCon4"
103 #define KEY_DEFCON_LEVEL "DefConLevel"
104 #define KEY_DEFCON_CHANMODES "DefConChanModes"
105 #define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit"
106 #define KEY_DEFCON_TIMEOUT "DefConTimeOut"
107 #define KEY_DEFCON_GLOBAL "GlobalOnDefcon"
108 #define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore"
109 #define KEY_DEFCON_MESSAGE "DefconMessage"
110 #define KEY_DEFCON_OFF_MESSAGE "DefConOffMessage"
111 #define KEY_DEFCON_GLINE_DURATION "DefConGlineExpire"
112 #define KEY_DEFCON_GLINE_REASON "DefConGlineReason"
114 /* Routing karma values: */
115 /* What value we start out with when new servers are added: */
116 #define KARMA_DEFAULT 10
119 #define KARMA_MIN -10
120 /* ping out, reduce karma by this much: */
121 #define KARMA_PINGOUT -8
122 /* read err, reduce karma by this much: */
123 #define KARMA_READERROR -5
124 /* every 24 hours everyone gets this much added (so we eventually re-try bad servers) */
125 #define KARMA_ENTROPE 1
126 /* every 24 hours servers linked for 24 hours get an additional ammount: */
127 #define KARMA_RELIABLE 1
128 /* How often to run entrope and reliable checks */
129 #define KARMA_TIMER 86400 /* 1 day */
131 #define ROUTING_CONNECT_TIMEOUT 30 /* 30 seconds */
133 #define IDENT_FORMAT "%s [%s@%s/%s]"
134 #define IDENT_DATA(user) user->nick, user->ident, user->hostname, irc_ntoa(&user->ip)
135 #define MAX_CHANNELS_WHOIS 50
136 #define OSMSG_PART_REASON "%s has no reason."
137 #define OSMSG_KICK_REQUESTED "Kick requested by %s."
138 #define OSMSG_KILL_REQUESTED "Kill requested by %s."
139 #define OSMSG_GAG_REQUESTED "Gag requested by %s."
141 static const struct message_entry msgtab
[] = {
142 { "OSMSG_BAR", "----------------------------------------" },
143 { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." },
144 { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." },
145 { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." },
146 { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." },
147 { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." },
148 { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." },
149 { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." },
150 { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." },
151 { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." },
152 { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." },
153 { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." },
154 { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." },
155 { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." },
156 { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." },
157 { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." },
158 { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." },
159 { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." },
160 { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." },
161 { "OSMSG_DEOP_DONE", "Deopped the requested lusers." },
162 { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." },
163 { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." },
164 { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." },
165 { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." },
166 { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." },
167 { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." },
168 { "OSMSG_NOT_THERE", "You not in $b%s$b." },
169 { "OSMSG_JOIN_DONE", "I have joined $b%s$b." },
170 { "OSMSG_MARK_SET", "Set the MARK." },
171 { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." },
172 { "OSMSG_SVSPART_SENT", "Sent the SVSPART." },
173 { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." },
174 { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." },
175 { "OSMSG_KICKALL_DONE", "I have cleared out %s." },
176 { "OSMSG_LEAVING", "Leaving $b%s$b." },
177 { "OSMSG_MARK_INVALID", "Sorry, marks must contain only letters, numbers, and dashes ('-')." },
178 { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." },
179 { "OSMSG_OP_DONE", "Opped the requested lusers." },
180 { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." },
181 { "OSMSG_HOP_DONE", "Halfopped the requested lusers." },
182 { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." },
183 { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" },
184 { "OSMSG_WHOIS_NICK", "Nick : %s" },
185 { "OSMSG_WHOIS_HOST", "Host : %s@%s" },
186 { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" },
187 { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" },
188 { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" },
189 { "OSMSG_WHOIS_IP", "Real IP : %s" },
190 { "OSMSG_WHOIS_COUNTRY", "Country : %s" },
191 { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" },
192 { "OSMSG_WHOIS_CITY", "City : %s" },
193 { "OSMSG_WHOIS_REGION", "Region/State : %s" },
194 { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" },
195 { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" },
196 { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" },
197 { "OSMSG_WHOIS_MAP", "Map : %s" },
198 { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" },
199 { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" },
200 { "OSMSG_WHOIS_MODES", "Modes : +%s " },
201 { "OSMSG_WHOIS_INFO", "Info : %s" },
202 { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" },
203 { "OSMSG_WHOIS_SERVER", "Server : %s" },
204 { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" },
205 { "OSMSG_WHOIS_ACCOUNT", "Account : %s" },
206 { "OSMSG_WHOIS_PRIVS", "IRCd Privs : %s" },
207 { "OSMSG_WHOIS_CHANNELS", "Channels : %s" },
208 { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." },
209 { "OSMSG_WHOIS_VERSION", "Version : %s" },
210 { "OSMSG_WHOIS_MARK", "Mark : %s" },
211 { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" },
212 { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
213 { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." },
214 { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." },
215 { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." },
216 { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." },
217 { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." },
218 { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." },
219 { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." },
220 { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." },
221 { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." },
222 { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." },
223 { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." },
224 { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." },
225 { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." },
226 { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." },
227 { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." },
228 { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" },
229 { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" },
230 { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." },
231 { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." },
232 { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." },
233 { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." },
234 { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." },
235 { "OSMSG_BADWORD_LIST", "Bad words: %s" },
236 { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
237 { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
238 { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." },
239 { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
240 { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
241 { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
242 { "OSMSG_RESERVED_LIST", "List of reserved nicks:" },
243 { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" },
244 { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" },
245 { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" },
246 { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" },
247 { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
248 { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" },
249 { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
250 { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" },
251 { "OSMSG_LINE_DUMPED", "Raw line sent." },
252 { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." },
253 { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." },
254 { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." },
255 { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." },
256 { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." },
257 { "OSMSG_ILLEGAL_REASON", "This channel is illegal." },
258 { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." },
259 { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." },
260 { "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." },
261 { "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." },
262 { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." },
263 { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." },
264 { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." },
265 { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." },
266 { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." },
267 { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." },
268 { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." },
269 { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." },
270 { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." },
271 { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." },
272 { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." },
273 { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." },
274 { "OSMSG_OPTION_ROOT", "The following keys can be queried:" },
275 { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" },
276 { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" },
277 { "OSMSG_OPTION_LIST_EMPTY", "Empty list." },
278 { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." },
279 { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." },
280 { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." },
281 { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." },
282 { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." },
283 { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" },
284 { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" },
285 { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" },
286 { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" },
287 { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" },
288 { "OSMSG_MARK_NO_MARK", "MARK action requires mark criteria (what do you want to mark them as?)" },
289 { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" },
290 { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" },
291 { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" },
292 { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
293 { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" },
294 { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
295 { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
296 { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
297 { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
298 { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
299 { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
300 { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
301 { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
302 { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." },
303 { "OSMSG_NO_GAGS", "No gags have been set." },
304 { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." },
305 { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." },
306 { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." },
307 { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
308 { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
309 { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
310 { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" },
311 { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." },
312 { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." },
313 { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" },
314 { "OSMSG_ALERTS_BAR", "----------------------------------------------" },
315 { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" },
316 { "OSMSG_ALERTS_DESC", " Criteria: %s" },
317 { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" },
318 { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" },
319 /* routing messages */
320 { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" },
321 { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" },
322 { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" },
323 { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" },
324 { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" },
325 { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." },
326 { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." },
327 { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." },
328 { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." },
329 { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" },
330 { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" },
331 { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" },
332 { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." },
333 { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." },
334 { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." },
335 { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." },
336 { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." },
337 { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." },
338 { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." },
339 { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." },
340 { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." },
341 { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" },
342 { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" },
343 { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" },
344 { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" },
345 { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" },
346 { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." },
347 { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." },
348 { "OSMSG_CONNECT", "->connect %s %d %s" },
349 { "OSMSG_SQUIT", "->squit %s" },
350 { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" },
351 { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" },
352 { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." },
353 { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." },
354 { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." },
355 { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." },
356 { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." },
357 { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", },
358 { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." },
359 { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." },
361 { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." },
362 { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." },
363 { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." },
364 { "OSMSG_RECONNECTING", "Reconnecting to my uplink." },
365 { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." },
366 { "OSMSG_NAME_COLLIDE", "That name is already in use." },
367 { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." },
368 { "OSMSG_SERVER_JUPED", "Added new jupe server %s." },
369 { "OSMSG_INVALID_NUMERIC", "Invalid numeric" },
370 { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." },
371 { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." },
372 { "OSMSG_SERVER_UNJUPED", "Server jupe removed." },
374 { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" },
375 { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." },
376 { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" },
377 { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." },
378 { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" },
379 { "OSMSG_WARN_LISTENTRY", "%s (%s)" },
380 { "OSMSG_WARN_LISTEND", "End of activity warning list." },
382 { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." },
383 { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." },
384 { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." },
385 { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." },
386 { "OSMSG_UPLINK_START", "Uplink $b%s$b:" },
387 { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" },
388 { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." },
389 { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." },
390 { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" },
391 { "OSMSG_CHANINFO_HEADER", "%s Information" },
392 { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" },
393 { "OSMSG_CHANINFO_MODES", "Modes: %s" },
394 { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" },
395 { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" },
396 { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" },
397 { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" },
398 { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
399 { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" },
400 { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" },
401 { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" },
402 { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" },
403 { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" },
404 { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" },
405 { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" },
406 { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" },
408 { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" },
409 { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" },
410 { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" },
411 { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" },
412 { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" },
413 { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" },
414 { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" },
415 { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" },
416 { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" },
417 { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" },
418 { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" },
419 { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" },
420 { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" },
421 { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" },
423 { "OSMSG_PRIV_UNKNOWN", "Unknown privilege flag %s, see /msg $O HELP PRIVFLAGS for a flag list" },
424 { "OSMSG_PRIV_SET", "Privilege flag %s has been %sset" },
429 #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd)
434 int GlobalOnDefcon
= 0;
435 int GlobalOnDefconMore
= 0;
436 int DefConGlineExpire
;
437 int DefConModesSet
= 0;
438 unsigned int DefConSessionLimit
;
439 char *DefConChanModes
;
440 char *DefConGlineReason
;
442 char *DefConOffMessage
;
444 extern void add_track_user(struct userNode
*user
);
445 typedef int (*discrim_search_func
)(struct userNode
*match
, void *extra
);
447 struct userNode
*opserv
;
448 static struct service
*opserv_service
;
450 /*static dict_t opserv_chan_warn; */ /* data is char* */
451 static dict_t opserv_reserved_nick_dict
; /* data is struct userNode* */
452 static struct string_list
*opserv_bad_words
;
453 static dict_t opserv_exempt_channels
; /* data is not used */
454 static dict_t opserv_trusted_hosts
; /* data is struct trusted_host* */
455 static dict_t opserv_routing_plans
; /* data is struct routingPlan */
456 static dict_t opserv_routing_plan_options
; /* data is a dict_t key->val list*/
457 static dict_t opserv_waiting_connections
; /* data is struct waitingConnection */
458 static dict_t opserv_hostinfo_dict
; /* data is struct opserv_hostinfo* */
459 static dict_t opserv_user_alerts
; /* data is struct opserv_user_alert* */
460 static dict_t opserv_nick_based_alerts
; /* data is struct opserv_user_alert* */
461 static dict_t opserv_channel_alerts
; /* data is struct opserv_user_alert* */
462 static struct module *opserv_module
;
463 static struct log_type
*OS_LOG
;
464 static unsigned int new_user_flood
;
465 static char *level_strings
[1001];
466 struct string_list
*autojoin_channels
;
467 struct route
*opserv_route
= NULL
; /* Main active routing table from activate_routing()*/
470 struct chanNode
*debug_channel
;
471 struct chanNode
*alert_channel
;
472 struct chanNode
*staff_auth_channel
;
473 struct policer_params
*join_policer_params
;
474 struct policer new_user_policer
;
475 unsigned long untrusted_max
;
476 unsigned long clone_gline_duration
;
477 unsigned long block_gline_duration
;
478 unsigned long block_shun_duration
;
479 unsigned long purge_lock_delay
;
480 unsigned long join_flood_moderate
;
481 unsigned long join_flood_moderate_threshold
;
482 unsigned long admin_level
;
483 unsigned long silent_level
;
486 struct trusted_host
{
500 struct gag_entry
*next
;
503 static struct gag_entry
*gagList
;
505 struct opserv_hostinfo
{
506 struct userList clients
;
507 struct trusted_host
*trusted
;
511 opserv_free_hostinfo(void *data
)
513 struct opserv_hostinfo
*ohi
= data
;
514 userList_clean(&ohi
->clients
);
519 opserv_free_waiting_connection(void *data
)
521 struct waitingConnection
*wc
= data
;
527 typedef struct opservDiscrim
{
528 struct chanNode
*channel
;
529 char *mask_nick
, *mask_ident
, *mask_host
, *mask_info
, *mask_version
, *server
, *reason
, *accountmask
, *chantarget
, *mark
, *mask_mark
;
530 irc_in_addr_t ip_mask
;
532 time_t min_ts
, max_ts
;
533 regex_t regex_nick
, regex_ident
, regex_host
, regex_info
, regex_version
;
534 unsigned int has_regex_nick
: 1, has_regex_ident
: 1, has_regex_host
: 1, has_regex_info
: 1, has_regex_version
: 1;
535 unsigned int min_level
, max_level
, domain_depth
, duration
, min_clones
, min_channels
, max_channels
;
536 unsigned char ip_mask_bits
;
537 unsigned int match_opers
: 1, option_log
: 1;
538 unsigned int chan_req_modes
: 2, chan_no_modes
: 2;
539 int authed
: 2, info_space
: 2;
540 unsigned int intra_scmp
: 2, intra_dcmp
: 2;
541 unsigned int use_regex
: 1;
542 unsigned int silent
: 1;
543 unsigned int checkrestrictions
: 2;
546 struct discrim_and_source
{
548 struct userNode
*source
;
549 struct userNode
*destination
;
551 unsigned int disp_limit
;
554 static discrim_t
opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
);
555 static unsigned int opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
);
556 static int gag_helper_func(struct userNode
*match
, void *extra
);
557 static int ungag_helper_func(struct userNode
*match
, void *extra
);
569 } opserv_alert_reaction
;
571 struct opserv_user_alert
{
573 char *text_discrim
, *split_discrim
;
575 opserv_alert_reaction reaction
;
578 /* funny type to make it acceptible to dict_set_free_data, far below */
580 opserv_free_user_alert(void *data
)
582 struct opserv_user_alert
*alert
= data
;
583 if (alert
->discrim
->channel
)
584 UnlockChannel(alert
->discrim
->channel
);
586 free(alert
->text_discrim
);
587 free(alert
->split_discrim
);
588 if(alert
->discrim
->has_regex_nick
)
589 regfree(&alert
->discrim
->regex_nick
);
590 if(alert
->discrim
->has_regex_ident
)
591 regfree(&alert
->discrim
->regex_ident
);
592 if(alert
->discrim
->has_regex_host
)
593 regfree(&alert
->discrim
->regex_host
);
594 if(alert
->discrim
->has_regex_info
)
595 regfree(&alert
->discrim
->regex_info
);
596 if(alert
->discrim
->has_regex_version
)
597 regfree(&alert
->discrim
->regex_version
);
598 free(alert
->discrim
->reason
);
599 free(alert
->discrim
);
603 #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0)
604 #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0)
607 char *defconReverseModes(const char *modes
)
609 char *newmodes
= NULL
;
614 if (!(newmodes
= malloc(sizeof(char) * strlen(modes
) + 1))) {
617 for (i
= 0; i
< strlen(modes
); i
++) {
620 else if (modes
[i
] == '-')
623 newmodes
[i
] = modes
[i
];
629 int checkDefCon(int level
)
631 return DefCon
[DefConLevel
] & level
;
634 void showDefConSettings(struct userNode
*user
, struct svccmd
*cmd
)
636 if (DefConLevel
== 5) {
637 reply("OSMSG_DEFCON_ALLOWING_ALL");
640 reply("OSMSG_DEFCON_DISALLOWING", DefConLevel
);
642 if (checkDefCon(DEFCON_NO_NEW_CHANNELS
))
643 reply("OSMSG_DEFCON_NO_NEW_CHANNELS");
645 if (checkDefCon(DEFCON_NO_NEW_NICKS
))
646 reply("OSMSG_DEFCON_NO_NEW_NICKS");
648 if (checkDefCon(DEFCON_NO_MODE_CHANGE
))
649 reply("OSMSG_DEFCON_NO_MODE_CHANGE");
651 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
) && (DefConChanModes
))
652 reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes
);
654 if (checkDefCon(DEFCON_REDUCE_SESSION
))
655 reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit
);
657 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
))
658 reply("OSMSG_DEFCON_NO_NEW_CLIENTS");
660 if (checkDefCon(DEFCON_OPER_ONLY
))
661 reply("OSMSG_DEFCON_OPER_ONLY");
663 if (checkDefCon(DEFCON_SILENT_OPER_ONLY
))
664 reply("OSMSG_DEFCON_SILENT_OPER_ONLY");
666 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
667 reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS");
669 if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
670 reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS");
672 if (checkDefCon(DEFCON_NO_NEW_MEMOS
))
673 reply("OSMSG_DEFCON_NO_NEW_MEMOS");
678 void do_mass_mode(char *modes
)
685 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
686 struct chanNode
*chan
= iter_data(it
);
688 irc_mode(opserv
, chan
, modes
);
693 void DefConProcess(struct userNode
*user
)
698 global_message_args(MESSAGE_RECIPIENT_LUSERS
, "DEFCON_NETWORK_CHANGED", DefConLevel
);
700 if (GlobalOnDefconMore
&& GlobalOnDefcon
)
701 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConMessage
);
703 if ((DefConLevel
== 5) && !GlobalOnDefconMore
&& !GlobalOnDefcon
)
704 global_message(MESSAGE_RECIPIENT_LUSERS
, DefConOffMessage
);
707 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_OPER_LEVEL_CHANGE", user
->nick
, DefConLevel
);
709 global_message_args(MESSAGE_RECIPIENT_OPERS
, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel
);
711 if (checkDefCon(DEFCON_FORCE_CHAN_MODES
)) {
712 if (DefConChanModes
&& !DefConModesSet
) {
713 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
714 do_mass_mode(DefConChanModes
);
719 if (DefConChanModes
&& (DefConModesSet
!= 0)) {
720 if (DefConChanModes
[0] == '+' || DefConChanModes
[0] == '-') {
721 if ((newmodes
= defconReverseModes(DefConChanModes
))) {
722 do_mass_mode(newmodes
);
734 defcon_timeout(UNUSED_ARG(void *data
))
740 static MODCMD_FUNC(cmd_defcon
)
742 if ((argc
< 2) || (atoi(argv
[1]) == DefConLevel
)) {
743 showDefConSettings(user
, cmd
);
747 if ((atoi(argv
[1]) < 1) || (atoi(argv
[1]) > 5)) {
748 reply("OSMSG_DEFCON_INVALID", atoi(argv
[1]));
752 DefConLevel
= atoi(argv
[1]);
753 showDefConSettings(user
, cmd
);
755 if (DefConTimeOut
> 0) {
756 timeq_del(0, defcon_timeout
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
757 timeq_add(now
+ DefConTimeOut
, defcon_timeout
, NULL
);
765 static MODCMD_FUNC(cmd_privallow)
767 //privallow servername/username +/-flag (global is set in conf)
770 static MODCMD_FUNC(cmd_privdissallow)
772 //privdisallow servername/username +/-flag (global is set in conf)
775 static MODCMD_FUNC(cmd_privlist)
777 //privlist servername/user (global with none)
781 static MODCMD_FUNC(cmd_privset
)
783 struct userNode
*target
;
791 } else if (*flag
== '+') {
796 target
= GetUserH(argv
[1]);
798 reply("MSG_NICK_UNKNOWN", argv
[1]);
802 if (check_priv(flag
)) {
803 irc_privs(target
, flag
, add
);
804 reply("OSMSG_PRIV_SET", argv
[2], (add
== 1) ? "" : "un");
806 reply("OSMSG_PRIV_UNKNOWN", argv
[2]);
813 /* A lot of these commands are very similar to what ChanServ can do,
814 * but OpServ can do them even on channels that aren't registered.
817 static MODCMD_FUNC(cmd_access
)
819 struct handle_info
*hi
;
823 target
= (argc
> 1) ? (const char*)argv
[1] : user
->nick
;
824 if (!irccasecmp(target
, "*")) {
825 nickserv_show_oper_accounts(user
, cmd
);
828 if (!(hi
= modcmd_get_handle_info(user
, target
)))
830 res
= (argc
> 2) ? oper_try_set_access(user
, opserv_service
->bot
, hi
, strtoul(argv
[2], NULL
, 0)) : 0;
831 reply("OSMSG_USER_ACCESS_IS", target
, hi
->handle
, hi
->opserv_level
);
835 static MODCMD_FUNC(cmd_ban
)
837 struct mod_chanmode change
;
838 struct userNode
*victim
;
840 mod_chanmode_init(&change
);
842 change
.args
[0].mode
= MODE_BAN
;
843 if (is_ircmask(argv
[1]))
844 change
.args
[0].u
.hostmask
= strdup(argv
[1]);
845 else if ((victim
= GetUserH(argv
[1])))
846 change
.args
[0].u
.hostmask
= generate_hostmask(victim
, 0);
848 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
851 modcmd_chanmode_announce(&change
);
852 reply("OSMSG_ADDED_BAN", change
.args
[0].u
.hostmask
, channel
->name
);
853 free((char*)change
.args
[0].u
.hostmask
);
857 static MODCMD_FUNC(cmd_chaninfo
)
862 struct exemptNode
*exempt
;
863 struct modeNode
*moden
;
866 reply("OSMSG_CHANINFO_HEADER", channel
->name
);
867 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TIMESTAMP");
868 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->timestamp
));
869 send_message_type(4, user
, cmd
->parent
->bot
, "%s", buffer
);
870 irc_make_chanmode(channel
, buffer
);
871 if (channel
->bad_channel
)
872 reply("OSMSG_CHANINFO_MODES_BADWORD", buffer
);
874 reply("OSMSG_CHANINFO_MODES", buffer
);
875 if (channel
->topic_time
) {
876 fmt
= user_find_message(user
, "OSMSG_CHANINFO_TOPIC");
877 strftime(buffer
, sizeof(buffer
), fmt
, gmtime(&channel
->topic_time
));
878 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, channel
->topic_nick
, channel
->topic
);
880 irc_fetchtopic(cmd
->parent
->bot
, channel
->name
);
881 reply("OSMSG_CHANINFO_TOPIC_UNKNOWN");
883 if (channel
->banlist
.used
) {
884 reply("OSMSG_CHANINFO_BAN_COUNT", channel
->banlist
.used
);
885 fmt
= user_find_message(user
, "OSMSG_CHANINFO_BAN");
886 for (n
= 0; n
< channel
->banlist
.used
; n
++) {
887 ban
= channel
->banlist
.list
[n
];
888 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&ban
->set
));
889 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, ban
->ban
, ban
->who
);
892 if (channel
->exemptlist
.used
) {
893 reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel
->exemptlist
.used
);
894 fmt
= user_find_message(user
, "OSMSG_CHANINFO_EXEMPT");
895 for (n
= 0; n
< channel
->exemptlist
.used
; n
++) {
896 exempt
= channel
->exemptlist
.list
[n
];
897 strftime(buffer
, sizeof(buffer
), fmt
, localtime(&exempt
->set
));
898 send_message_type(4, user
, cmd
->parent
->bot
, buffer
, exempt
->exempt
, exempt
->who
);
901 if ((argc
< 2) && (channel
->members
.used
>= 50)) {
902 /* early out unless they ask for users */
903 reply("OSMSG_CHANINFO_MANY_USERS", channel
->members
.used
, argv
[0], channel
->name
);
906 reply("OSMSG_CHANINFO_USER_COUNT", channel
->members
.used
);
907 for (n
=0; n
<channel
->members
.used
; n
++) {
908 moden
= channel
->members
.list
[n
];
909 if (moden
->modes
& MODE_CHANOP
) {
910 if (moden
->oplevel
>= 0)
911 send_message_type(4, user
, cmd
->parent
->bot
, " @%s:%d (%s@%s)", moden
->user
->nick
, moden
->oplevel
, moden
->user
->ident
, moden
->user
->hostname
);
913 send_message_type(4, user
, cmd
->parent
->bot
, " @%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
916 for (n
=0; n
<channel
->members
.used
; n
++) {
917 moden
= channel
->members
.list
[n
];
918 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_HALFOP
)
919 send_message_type(4, user
, cmd
->parent
->bot
, " %s%s (%s@%s)", "%", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
921 for (n
=0; n
<channel
->members
.used
; n
++) {
922 moden
= channel
->members
.list
[n
];
923 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == MODE_VOICE
)
924 send_message_type(4, user
, cmd
->parent
->bot
, " +%s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
926 for (n
=0; n
<channel
->members
.used
; n
++) {
927 moden
= channel
->members
.list
[n
];
928 if ((moden
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
)) == 0)
929 send_message_type(4, user
, cmd
->parent
->bot
, " %s (%s@%s)", moden
->user
->nick
, moden
->user
->ident
, moden
->user
->hostname
);
934 /* This command has been replaced by 'alert notice channel #foo' */
936 static MODCMD_FUNC(cmd_warn)
938 char *reason, *message;
940 if (!IsChannelName(argv[1])) {
941 reply("OSMSG_NEED_CHANNEL", argv[0]);
944 reason = dict_find(opserv_chan_warn, argv[1], NULL);
946 reply("OSMSG_WARN_EXISTS", argv[1]);
950 reason = strdup(unsplit_string(argv+2, argc-2, NULL));
952 reason = strdup("No reason");
953 dict_insert(opserv_chan_warn, strdup(argv[1]), reason);
954 reply("OSMSG_WARN_ADDED", argv[1], reason);
955 if (dict_find(channels, argv[1], NULL)) {
956 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason);
961 static MODCMD_FUNC(cmd_unwarn)
963 if ((argc < 2) || !IsChannelName(argv[1])) {
964 reply("OSMSG_NEED_CHANNEL", argv[0]);
967 if (!dict_remove(opserv_chan_warn, argv[1])) {
968 reply("OSMSG_WARN_NOEXIST", argv[1]);
971 reply("OSMSG_WARN_DELETED", argv[1]);
976 static MODCMD_FUNC(cmd_clearbans
)
978 struct mod_chanmode
*change
;
981 change
= mod_chanmode_alloc(channel
->banlist
.used
);
982 for (ii
=0; ii
<channel
->banlist
.used
; ii
++) {
983 change
->args
[ii
].mode
= MODE_REMOVE
| MODE_BAN
;
984 change
->args
[ii
].u
.hostmask
= strdup(channel
->banlist
.list
[ii
]->ban
);
986 modcmd_chanmode_announce(change
);
987 for (ii
=0; ii
<change
->argc
; ++ii
)
988 free((char*)change
->args
[ii
].u
.hostmask
);
989 mod_chanmode_free(change
);
990 reply("OSMSG_CLEARBANS_DONE", channel
->name
);
994 static MODCMD_FUNC(cmd_clearmodes
)
996 struct mod_chanmode change
;
998 if (!channel
->modes
) {
999 reply("OSMSG_NO_CHANNEL_MODES", channel
->name
);
1002 mod_chanmode_init(&change
);
1003 change
.modes_clear
= channel
->modes
;
1004 modcmd_chanmode_announce(&change
);
1005 reply("OSMSG_CLEARMODES_DONE", channel
->name
);
1009 static MODCMD_FUNC(cmd_deop
)
1011 struct mod_chanmode
*change
;
1012 unsigned int arg
, count
;
1014 change
= mod_chanmode_alloc(argc
-1);
1015 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1016 struct userNode
*victim
= GetUserH(argv
[arg
]);
1017 struct modeNode
*mn
;
1018 if (!victim
|| IsService(victim
)
1019 || !(mn
= GetUserMode(channel
, victim
))
1020 || !(mn
->modes
& MODE_CHANOP
))
1022 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1023 change
->args
[count
++].u
.member
= mn
;
1026 change
->argc
= count
;
1027 modcmd_chanmode_announce(change
);
1029 mod_chanmode_free(change
);
1030 reply("OSMSG_DEOP_DONE");
1034 static MODCMD_FUNC(cmd_dehop
)
1036 struct mod_chanmode
*change
;
1037 unsigned int arg
, count
;
1039 change
= mod_chanmode_alloc(argc
-1);
1040 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1041 struct userNode
*victim
= GetUserH(argv
[arg
]);
1042 struct modeNode
*mn
;
1043 if (!victim
|| IsService(victim
)
1044 || !(mn
= GetUserMode(channel
, victim
))
1045 || !(mn
->modes
& MODE_HALFOP
))
1047 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1048 change
->args
[count
++].u
.member
= mn
;
1051 change
->argc
= count
;
1052 modcmd_chanmode_announce(change
);
1054 mod_chanmode_free(change
);
1055 reply("OSMSG_DEHOP_DONE");
1059 static MODCMD_FUNC(cmd_deopall
)
1061 struct mod_chanmode
*change
;
1062 unsigned int ii
, count
;
1064 change
= mod_chanmode_alloc(channel
->members
.used
);
1065 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1066 struct modeNode
*mn
= channel
->members
.list
[ii
];
1067 if (IsService(mn
->user
) || !(mn
->modes
& MODE_CHANOP
))
1069 change
->args
[count
].mode
= MODE_REMOVE
| MODE_CHANOP
;
1070 change
->args
[count
++].u
.member
= mn
;
1073 change
->argc
= count
;
1074 modcmd_chanmode_announce(change
);
1076 mod_chanmode_free(change
);
1077 reply("OSMSG_DEOPALL_DONE", channel
->name
);
1081 static MODCMD_FUNC(cmd_dehopall
)
1083 struct mod_chanmode
*change
;
1084 unsigned int ii
, count
;
1086 change
= mod_chanmode_alloc(channel
->members
.used
);
1087 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1088 struct modeNode
*mn
= channel
->members
.list
[ii
];
1089 if (IsService(mn
->user
) || !(mn
->modes
& MODE_HALFOP
))
1091 change
->args
[count
].mode
= MODE_REMOVE
| MODE_HALFOP
;
1092 change
->args
[count
++].u
.member
= mn
;
1095 change
->argc
= count
;
1096 modcmd_chanmode_announce(change
);
1098 mod_chanmode_free(change
);
1099 reply("OSMSG_DEHOPALL_DONE", channel
->name
);
1103 static MODCMD_FUNC(cmd_resetmax
)
1105 max_clients
= dict_size(clients
);
1106 max_clients_time
= now
;
1107 reply("OSMSG_MAXUSERS_RESET", max_clients
);
1111 static MODCMD_FUNC(cmd_rehash
)
1113 extern char *services_config
;
1115 if (conf_read(services_config
))
1116 reply("OSMSG_REHASH_COMPLETE");
1118 reply("OSMSG_REHASH_FAILED");
1122 static MODCMD_FUNC(cmd_reopen
)
1125 reply("OSMSG_REOPEN_COMPLETE");
1129 static MODCMD_FUNC(cmd_reconnect
)
1131 reply("OSMSG_RECONNECTING");
1132 irc_squit(self
, "Reconnecting.", NULL
);
1136 static MODCMD_FUNC(cmd_jupe
)
1138 extern int force_n2k
;
1139 struct server
*newsrv
;
1141 char numeric
[COMBO_NUMERIC_LEN
+1], srvdesc
[SERVERDESCRIPTMAX
+1];
1143 num
= atoi(argv
[2]);
1145 reply("OSMSG_INVALID_NUMERIC");
1148 if ((num
< 64) && !force_n2k
) {
1149 inttobase64(numeric
, num
, 1);
1150 inttobase64(numeric
+1, 64*64-1, 2);
1152 inttobase64(numeric
, num
, 2);
1153 inttobase64(numeric
+2, 64*64*64-1, 3);
1155 #ifdef WITH_PROTOCOL_P10
1156 if (GetServerN(numeric
)) {
1157 reply("OSMSG_NUMERIC_COLLIDE", num
, numeric
);
1161 if (GetServerH(argv
[1])) {
1162 reply("OSMSG_NAME_COLLIDE");
1165 snprintf(srvdesc
, sizeof(srvdesc
), "JUPE %s", unsplit_string(argv
+3, argc
-3, NULL
));
1166 if(!strchr(argv
[1], '.')) {
1167 reply("OSMSG_INVALID_SERVERNAME");
1170 newsrv
= AddServer(self
, argv
[1], 1, now
, now
, numeric
, srvdesc
);
1172 reply("OSMSG_SRV_CREATE_FAILED");
1176 reply("OSMSG_SERVER_JUPED", argv
[1]);
1180 static MODCMD_FUNC(cmd_unjupe
)
1185 srv
= GetServerH(argv
[1]);
1187 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1190 if (strncmp(srv
->description
, "JUPE", 4)) {
1191 reply("OSMSG_SERVER_NOT_JUPE");
1194 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : "Unjuping server";
1195 DelServer(srv
, 1, reason
);
1196 reply("OSMSG_SERVER_UNJUPED");
1200 static MODCMD_FUNC(cmd_jump
)
1202 extern struct cManagerNode cManager
;
1203 void uplink_select(char *name
);
1204 struct uplinkNode
*uplink_find(char *name
);
1205 struct uplinkNode
*uplink
;
1208 target
= unsplit_string(argv
+1, argc
-1, NULL
);
1210 if (!strcmp(cManager
.uplink
->name
, target
)) {
1211 reply("OSMSG_CURRENT_UPLINK", cManager
.uplink
->name
);
1215 uplink
= uplink_find(target
);
1217 reply("OSMSG_INVALID_UPLINK", target
);
1220 if (uplink
->flags
& UPLINK_UNAVAILABLE
) {
1221 reply("OSMSG_UPLINK_DISABLED", uplink
->name
);
1225 reply("OSMSG_UPLINK_CONNECTING", uplink
->name
, uplink
->host
, uplink
->port
);
1226 uplink_select(target
);
1227 irc_squit(self
, "Reconnecting.", NULL
);
1231 static MODCMD_FUNC(cmd_die
)
1233 char *reason
, *text
;
1235 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1236 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 20);
1237 sprintf(reason
, "Disconnected by %s [%s]", user
->nick
, text
);
1238 irc_squit(self
, reason
, text
);
1243 static MODCMD_FUNC(cmd_restart
)
1245 extern int services_argc
;
1246 extern char **services_argv
;
1247 char **restart_argv
, *reason
, *text
;
1249 text
= unsplit_string(argv
+1, argc
-1, NULL
);
1250 reason
= alloca(strlen(text
) + strlen(user
->nick
) + 17);
1251 sprintf(reason
, "Restarted by %s [%s]", user
->nick
, text
);
1252 irc_squit(self
, reason
, text
);
1254 /* Append a NULL to the end of argv[]. */
1255 restart_argv
= (char **)alloca((services_argc
+ 1) * sizeof(char *));
1256 memcpy(restart_argv
, services_argv
, services_argc
* sizeof(char *));
1257 restart_argv
[services_argc
] = NULL
;
1262 execv(services_argv
[0], restart_argv
);
1264 /* If we're still here, that means something went wrong. Reconnect. */
1268 static struct gline
*
1269 opserv_block(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
, int silent
)
1271 char mask
[IRC_NTOP_MAX_SIZE
+3] = { '*', '@', '\0' };
1272 irc_ntop(mask
+ 2, sizeof(mask
) - 2, &target
->ip
);
1274 snprintf(reason
= alloca(MAXLEN
), MAXLEN
,
1275 "G-line requested by %s.", src_handle
);
1277 duration
= opserv_conf
.block_gline_duration
;
1278 return gline_add(src_handle
, mask
, duration
, reason
, now
, 1, silent
? 1 : 0);
1281 static MODCMD_FUNC(cmd_block
)
1283 struct userNode
*target
;
1284 struct gline
*gline
;
1287 target
= GetUserH(argv
[1]);
1289 reply("MSG_NICK_UNKNOWN", argv
[1]);
1292 if (IsService(target
)) {
1293 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1296 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1297 gline
= opserv_block(target
, user
->handle_info
->handle
, reason
, 0, 0);
1298 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1302 static MODCMD_FUNC(cmd_gline
)
1304 unsigned long duration
;
1306 struct gline
*gline
;
1308 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1309 if (!is_gline(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1310 reply("MSG_INVALID_GLINE", argv
[1]);
1313 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1314 reply("OSMSG_STUPID_GLINE", argv
[1]);
1317 duration
= ParseInterval(argv
[2]);
1319 reply("MSG_INVALID_DURATION", argv
[2]);
1322 gline
= gline_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1, 0);
1323 reply("OSMSG_GLINE_ISSUED", gline
->target
);
1327 static MODCMD_FUNC(cmd_ungline
)
1329 if (gline_remove(argv
[1], 1))
1330 reply("OSMSG_GLINE_REMOVED", argv
[1]);
1332 reply("OSMSG_GLINE_FORCE_REMOVED", argv
[1]);
1336 static MODCMD_FUNC(cmd_refreshg
)
1343 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1344 srv
= iter_data(it
);
1345 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1347 gline_refresh_server(srv
);
1348 reply("OSMSG_GLINES_ONE_REFRESHED", srv
->name
);
1352 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1356 gline_refresh_all();
1357 reply("OSMSG_GLINES_REFRESHED");
1363 opserv_version(struct userNode
*target
)
1365 irc_version_user(opserv
, target
);
1369 opserv_mark(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *mark
)
1373 irc_mark(target
, mark
);
1377 opserv_svsjoin(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
, unsigned int checkrestrictions
)
1379 struct chanNode
*channel
;
1381 if(!channame
|| !IsChannelName(channame
)) {
1382 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1386 if (!(channel
= GetChannel(channame
))) {
1387 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
1389 if (GetUserMode(channel
, target
)) {
1394 if (checkrestrictions
) {
1395 if (trace_check_bans(target
, channel
) == 1) {
1396 return; /* found on lamer list */
1399 if (channel
->modes
& MODE_INVITEONLY
) {
1400 return; /* channel is invite only */
1403 if (channel
->limit
> 0) {
1404 if (channel
->members
.used
>= channel
->limit
) {
1405 return; /* channel is invite on */
1409 if (*channel
->key
) {
1410 return; /* channel is password protected */
1414 irc_svsjoin(opserv
, target
, channel
);
1415 /* Should we tell the user they got joined? -Rubin*/
1419 opserv_svspart(struct userNode
*target
, UNUSED_ARG(char *src_handle
), UNUSED_ARG(char *reason
), char *channame
)
1421 struct chanNode
*channel
;
1423 if(!channame
|| !IsChannelName(channame
)) {
1424 /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */
1428 if (!(channel
= GetChannel(channame
))) {
1429 /* channel doesnt exist */
1433 if (!GetUserMode(channel
, target
)) {
1438 irc_svspart(opserv
, target
, channel
);
1441 static struct shun
*
1442 opserv_shun(struct userNode
*target
, char *src_handle
, char *reason
, unsigned long duration
)
1445 mask
= alloca(MAXLEN
);
1446 snprintf(mask
, MAXLEN
, "*@%s", target
->hostname
);
1448 reason
= alloca(MAXLEN
);
1449 snprintf(reason
, MAXLEN
, "Shun requested by %s.", src_handle
);
1451 if (!duration
) duration
= opserv_conf
.block_shun_duration
;
1452 return shun_add(src_handle
, mask
, duration
, reason
, now
, 1);
1455 static MODCMD_FUNC(cmd_sblock
)
1457 struct userNode
*target
;
1461 target
= GetUserH(argv
[1]);
1463 reply("MSG_NICK_UNKNOWN", argv
[1]);
1466 if (IsService(target
)) {
1467 reply("MSG_SERVICE_IMMUNE", target
->nick
);
1470 reason
= (argc
> 2) ? unsplit_string(argv
+2, argc
-2, NULL
) : NULL
;
1471 shun
= opserv_shun(target
, user
->handle_info
->handle
, reason
, 0);
1472 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1476 static MODCMD_FUNC(cmd_shun
)
1478 unsigned long duration
;
1482 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
1483 if (!is_shun(argv
[1]) && !IsChannelName(argv
[1]) && (argv
[1][0] != '&')) {
1484 reply("MSG_INVALID_SHUN", argv
[1]);
1487 if (!argv
[1][strspn(argv
[1], "#&*?@.")] && (strlen(argv
[1]) < 10)) {
1488 reply("OSMSG_STUPID_SHUN", argv
[1]);
1491 duration
= ParseInterval(argv
[2]);
1493 reply("MSG_INVALID_DURATION", argv
[2]);
1496 shun
= shun_add(user
->handle_info
->handle
, argv
[1], duration
, reason
, now
, 1);
1497 reply("OSMSG_SHUN_ISSUED", shun
->target
);
1501 static MODCMD_FUNC(cmd_unshun
)
1503 if (shun_remove(argv
[1], 1))
1504 reply("OSMSG_SHUN_REMOVED", argv
[1]);
1506 reply("OSMSG_SHUN_FORCE_REMOVED", argv
[1]);
1510 static MODCMD_FUNC(cmd_refreshs
)
1517 for (it
=dict_first(servers
), count
=0; it
; it
=iter_next(it
)) {
1518 srv
= iter_data(it
);
1519 if ((srv
== self
) || !match_ircglob(srv
->name
, argv
[1]))
1521 shun_refresh_server(srv
);
1522 reply("OSMSG_SHUNS_ONE_REFRESHED", srv
->name
);
1526 reply("MSG_SERVER_UNKNOWN", argv
[1]);
1531 reply("OSMSG_SHUNS_REFRESHED");
1537 opserv_ison(struct userNode
*bot
, struct userNode
*tell
, struct userNode
*target
, const char *message
)
1539 struct modeNode
*mn
;
1540 unsigned int count
, here_len
, n
, maxlen
;
1543 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
1545 maxlen
= MAX_LINE_SIZE
;
1546 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
1547 mn
= target
->channels
.list
[n
];
1548 here_len
= strlen(mn
->channel
->name
);
1549 if ((count
+ here_len
+ 4) > maxlen
) {
1551 send_message(tell
, bot
, message
, buff
);
1554 if (mn
->modes
& MODE_CHANOP
)
1555 buff
[count
++] = '@';
1556 if (mn
->modes
& MODE_HALFOP
)
1557 buff
[count
++] = '%';
1558 if (mn
->modes
& MODE_VOICE
)
1559 buff
[count
++] = '+';
1560 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
1562 buff
[count
++] = ' ';
1566 send_message(tell
, bot
, message
, buff
);
1570 static MODCMD_FUNC(cmd_inviteme
)
1572 struct userNode
*target
;
1577 target
= GetUserH(argv
[1]);
1579 reply("MSG_NICK_UNKNOWN", argv
[1]);
1583 if (opserv_conf
.debug_channel
== NULL
) {
1584 reply("OSMSG_NO_DEBUG_CHANNEL");
1587 if (GetUserMode(opserv_conf
.debug_channel
, user
)) {
1588 reply("OSMSG_ALREADY_THERE", opserv_conf
.debug_channel
->name
);
1591 irc_invite(cmd
->parent
->bot
, target
, opserv_conf
.debug_channel
);
1593 reply("OSMSG_INVITE_DONE", target
->nick
, opserv_conf
.debug_channel
->name
);
1597 static MODCMD_FUNC(cmd_invite
)
1599 if (GetUserMode(channel
, user
)) {
1600 reply("OSMSG_ALREADY_THERE", channel
->name
);
1603 irc_invite(cmd
->parent
->bot
, user
, channel
);
1607 static MODCMD_FUNC(cmd_svsjoin
)
1609 struct userNode
*target
;
1612 if(!IsChannelName(argv
[2])) {
1613 reply("MSG_NOT_CHANNEL_NAME");
1616 target
= GetUserH(argv
[1]);
1618 reply("MSG_NICK_UNKNOWN", argv
[1]);
1622 if (!(channel
= GetChannel(argv
[2]))) {
1623 channel
= AddChannel(argv
[2], now
, NULL
, NULL
, NULL
);
1625 if (GetUserMode(channel
, target
)) {
1626 reply("OSMSG_ALREADY_THERE", channel
->name
);
1629 irc_svsjoin(opserv
, target
, channel
);
1630 reply("OSMSG_SVSJOIN_SENT");
1634 static MODCMD_FUNC(cmd_join
)
1636 struct userNode
*bot
= cmd
->parent
->bot
;
1638 if (!IsChannelName(argv
[1])) {
1639 reply("MSG_NOT_CHANNEL_NAME");
1641 } else if (!(channel
= GetChannel(argv
[1]))) {
1642 channel
= AddChannel(argv
[1], now
, NULL
, NULL
, NULL
);
1643 AddChannelUser(bot
, channel
)->modes
|= MODE_CHANOP
;
1644 } else if (GetUserMode(channel
, bot
)) {
1645 reply("OSMSG_ALREADY_JOINED", channel
->name
);
1648 struct mod_chanmode change
;
1649 mod_chanmode_init(&change
);
1651 change
.args
[0].mode
= MODE_CHANOP
;
1652 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1653 modcmd_chanmode_announce(&change
);
1655 irc_fetchtopic(bot
, channel
->name
);
1656 reply("OSMSG_JOIN_DONE", channel
->name
);
1660 static MODCMD_FUNC(cmd_kick
)
1662 struct userNode
*target
;
1666 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1667 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1669 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1671 target
= GetUserH(argv
[1]);
1673 reply("MSG_NICK_UNKNOWN", argv
[1]);
1676 if (!GetUserMode(channel
, target
)) {
1677 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1680 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1684 static MODCMD_FUNC(cmd_kickall
)
1686 unsigned int limit
, n
, inchan
;
1687 struct modeNode
*mn
;
1689 struct userNode
*bot
= cmd
->parent
->bot
;
1691 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1692 * channel, we have to join it in temporarily. */
1693 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1694 struct mod_chanmode change
;
1695 mod_chanmode_init(&change
);
1696 change
.args
[0].mode
= MODE_CHANOP
;
1697 change
.args
[0].u
.member
= AddChannelUser(bot
, channel
);
1698 modcmd_chanmode_announce(&change
);
1701 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1702 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1704 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1706 limit
= user
->handle_info
->opserv_level
;
1707 for (n
=channel
->members
.used
; n
>0;) {
1708 mn
= channel
->members
.list
[--n
];
1709 if (IsService(mn
->user
)
1710 || (mn
->user
->handle_info
1711 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1714 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1717 DelChannelUser(bot
, channel
, "My work here is done", 0);
1718 reply("OSMSG_KICKALL_DONE", channel
->name
);
1722 static MODCMD_FUNC(cmd_kickban
)
1724 struct mod_chanmode change
;
1725 struct userNode
*target
;
1730 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1731 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1733 reason
= unsplit_string(argv
+2, argc
-2, NULL
);
1735 target
= GetUserH(argv
[1]);
1737 reply("MSG_NICK_UNKNOWN", argv
[1]);
1740 if (!GetUserMode(channel
, target
)) {
1741 reply("OSMSG_NOT_ON_CHANNEL", target
->nick
, channel
->name
);
1744 mod_chanmode_init(&change
);
1746 change
.args
[0].mode
= MODE_BAN
;
1747 change
.args
[0].u
.hostmask
= mask
= generate_hostmask(target
, 0);
1748 modcmd_chanmode_announce(&change
);
1749 KickChannelUser(target
, channel
, cmd
->parent
->bot
, reason
);
1754 static MODCMD_FUNC(cmd_kickbanall
)
1756 struct modeNode
*mn
;
1757 struct userNode
*bot
= cmd
->parent
->bot
;
1758 struct mod_chanmode
*change
;
1760 unsigned int limit
, n
, inchan
;
1762 /* ircu doesn't let servers KICK users, so if OpServ's not in the
1763 * channel, we have to join it in temporarily. */
1764 if (!(inchan
= GetUserMode(channel
, bot
) ? 1 : 0)) {
1765 change
= mod_chanmode_alloc(2);
1766 change
->args
[0].mode
= MODE_CHANOP
;
1767 change
->args
[0].u
.member
= AddChannelUser(bot
, channel
);
1768 change
->args
[1].mode
= MODE_BAN
;
1769 change
->args
[1].u
.hostmask
= "*!*@*";
1771 change
= mod_chanmode_alloc(1);
1772 change
->args
[0].mode
= MODE_BAN
;
1773 change
->args
[0].u
.hostmask
= "*!*@*";
1775 modcmd_chanmode_announce(change
);
1776 mod_chanmode_free(change
);
1778 reason
= alloca(strlen(OSMSG_KICK_REQUESTED
)+strlen(user
->nick
)+1);
1779 sprintf(reason
, OSMSG_KICK_REQUESTED
, user
->nick
);
1781 reason
= unsplit_string(argv
+1, argc
-1, NULL
);
1784 limit
= user
->handle_info
->opserv_level
;
1785 for (n
=channel
->members
.used
; n
>0; ) {
1786 mn
= channel
->members
.list
[--n
];
1787 if (IsService(mn
->user
)
1788 || (mn
->user
->handle_info
1789 && (mn
->user
->handle_info
->opserv_level
>= limit
))) {
1792 KickChannelUser(mn
->user
, channel
, bot
, reason
);
1795 DelChannelUser(bot
, channel
, "My work here is done", 0);
1796 reply("OSMSG_KICKALL_DONE", channel
->name
);
1800 static MODCMD_FUNC(cmd_svspart
)
1802 struct userNode
*target
;
1804 if(!IsChannelName(argv
[2])) {
1805 reply("MSG_NOT_CHANNEL_NAME");
1808 target
= GetUserH(argv
[1]);
1810 reply("MSG_NICK_UNKNOWN", argv
[1]);
1814 if (!(channel
= GetChannel(argv
[2]))) {
1815 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1819 if (!GetUserMode(channel
, target
)) {
1820 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1824 irc_svspart(opserv
, target
, channel
);
1825 reply("OSMSG_SVSPART_SENT");
1829 static MODCMD_FUNC(cmd_part
)
1833 if (!IsChannelName(argv
[1])) {
1834 reply("MSG_NOT_CHANNEL_NAME");
1837 if ((channel
= GetChannel(argv
[1]))) {
1838 if (!GetUserMode(channel
, cmd
->parent
->bot
)) {
1839 reply("OSMSG_NOT_ON_CHANNEL", cmd
->parent
->bot
->nick
, channel
->name
);
1842 reason
= (argc
< 3) ? "Leaving." : unsplit_string(argv
+2, argc
-2, NULL
);
1843 reply("OSMSG_LEAVING", channel
->name
);
1844 DelChannelUser(cmd
->parent
->bot
, channel
, reason
, 0);
1849 static MODCMD_FUNC(cmd_mode
)
1851 if (!modcmd_chanmode(argv
+1, argc
-1, MCP_ALLOW_OVB
|MCP_KEY_FREE
|MC_ANNOUNCE
)) {
1852 reply("MSG_INVALID_MODES", unsplit_string(argv
+1, argc
-1, NULL
));
1855 reply("OSMSG_MODE_SET", channel
->name
);
1859 int is_valid_mark(char *mark
)
1865 if(strlen(mark
) > MARKLEN
)
1868 for(ptr
= mark
; *ptr
; ptr
++) {
1869 if(! (isalnum(*ptr
) || *ptr
== '-'))
1876 static MODCMD_FUNC(cmd_mark
)
1878 char *mark
= argv
[2];
1879 struct userNode
*victim
= GetUserH(argv
[1]);
1882 reply("MSG_NICK_UNKNOWN", argv
[1]);
1883 else if(!is_valid_mark(mark
))
1884 reply("OSMSG_MARK_INVALID");
1886 irc_mark(victim
, mark
);
1887 reply("OSMSG_MARK_SET");
1893 static MODCMD_FUNC(cmd_op
)
1895 struct mod_chanmode
*change
;
1896 unsigned int arg
, count
;
1898 change
= mod_chanmode_alloc(argc
-1);
1899 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1900 struct userNode
*victim
;
1901 struct modeNode
*mn
;
1902 if (!(victim
= GetUserH(argv
[arg
])))
1904 if (!(mn
= GetUserMode(channel
, victim
)))
1906 if (mn
->modes
& MODE_CHANOP
)
1908 change
->args
[count
].mode
= MODE_CHANOP
;
1909 change
->args
[count
++].u
.member
= mn
;
1912 change
->argc
= count
;
1913 modcmd_chanmode_announce(change
);
1915 mod_chanmode_free(change
);
1916 reply("OSMSG_OP_DONE");
1920 static MODCMD_FUNC(cmd_hop
)
1922 struct mod_chanmode
*change
;
1923 unsigned int arg
, count
;
1925 change
= mod_chanmode_alloc(argc
-1);
1926 for (arg
= 1, count
= 0; arg
< argc
; ++arg
) {
1927 struct userNode
*victim
;
1928 struct modeNode
*mn
;
1929 if (!(victim
= GetUserH(argv
[arg
])))
1931 if (!(mn
= GetUserMode(channel
, victim
)))
1933 if (mn
->modes
& MODE_HALFOP
)
1935 change
->args
[count
].mode
= MODE_HALFOP
;
1936 change
->args
[count
++].u
.member
= mn
;
1939 change
->argc
= count
;
1940 modcmd_chanmode_announce(change
);
1942 mod_chanmode_free(change
);
1943 reply("OSMSG_HOP_DONE");
1947 static MODCMD_FUNC(cmd_opall
)
1949 struct mod_chanmode
*change
;
1950 unsigned int ii
, count
;
1952 change
= mod_chanmode_alloc(channel
->members
.used
);
1953 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1954 struct modeNode
*mn
= channel
->members
.list
[ii
];
1955 if (mn
->modes
& MODE_CHANOP
)
1957 change
->args
[count
].mode
= MODE_CHANOP
;
1958 change
->args
[count
++].u
.member
= mn
;
1961 change
->argc
= count
;
1962 modcmd_chanmode_announce(change
);
1964 mod_chanmode_free(change
);
1965 reply("OSMSG_OPALL_DONE", channel
->name
);
1969 static MODCMD_FUNC(cmd_hopall
)
1971 struct mod_chanmode
*change
;
1972 unsigned int ii
, count
;
1974 change
= mod_chanmode_alloc(channel
->members
.used
);
1975 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
1976 struct modeNode
*mn
= channel
->members
.list
[ii
];
1977 if (mn
->modes
& MODE_HALFOP
)
1979 change
->args
[count
].mode
= MODE_HALFOP
;
1980 change
->args
[count
++].u
.member
= mn
;
1983 change
->argc
= count
;
1984 modcmd_chanmode_announce(change
);
1986 mod_chanmode_free(change
);
1987 reply("OSMSG_HOPALL_DONE", channel
->name
);
1991 static MODCMD_FUNC(cmd_whois
)
1993 struct userNode
*target
;
1997 #ifdef WITH_PROTOCOL_P10
1998 if (argv
[1][0] == '*')
1999 target
= GetUserN(argv
[1]+1);
2002 target
= GetUserH(argv
[1]);
2004 reply("MSG_NICK_UNKNOWN", argv
[1]);
2007 reply("OSMSG_WHOIS_NICK", target
->nick
);
2008 reply("OSMSG_WHOIS_HOST", target
->ident
, target
->hostname
);
2009 if (IsFakeHost(target
))
2010 reply("OSMSG_WHOIS_FAKEHOST", target
->fakehost
);
2011 reply("OSMSG_WHOIS_CRYPT_HOST", target
->crypthost
);
2012 reply("OSMSG_WHOIS_CRYPT_IP", target
->cryptip
);
2013 reply("OSMSG_WHOIS_IP", irc_ntoa(&target
->ip
));
2016 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2017 reply("OSMSG_WHOIS_COUNTRY_CODE", target
->country_code
);
2018 reply("OSMSG_WHOIS_CITY", target
->city
);
2019 reply("OSMSG_WHOIS_REGION", target
->region
);
2021 reply("OSMSG_WHOIS_POSTAL_CODE", target
->postal_code
);
2022 reply("OSMSG_WHOIS_LATITUDE", target
->latitude
);
2023 reply("OSMSG_WHOIS_LONGITUDE", target
->longitude
);
2024 /* Only show a map url if we have a city, latitude and longitude.
2025 * Theres not much point of latitude and longitude coordinates are
2026 * returned but no city, the coordinates are useless.
2028 if (target
->latitude
&& target
->longitude
&& target
->city
) {
2029 char map_url
[MAXLEN
];
2030 snprintf(map_url
, sizeof(map_url
), "http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=%f&longitude=%f",
2031 target
->latitude
, target
->longitude
);
2032 reply("OSMSG_WHOIS_MAP", map_url
);
2034 reply("OSMSG_WHOIS_DMA_CODE", target
->dma_code
);
2035 reply("OSMSG_WHOIS_AREA_CODE", target
->area_code
);
2036 } else if (target
->country_name
) {
2037 reply("OSMSG_WHOIS_COUNTRY", target
->country_name
);
2039 if(target
->version_reply
) {
2040 reply("OSMSG_WHOIS_VERSION", target
->version_reply
);
2043 reply("OSMSG_WHOIS_MARK", target
->mark
);
2045 reply("OSMSG_WHOIS_NO_NOTICE", target
->no_notice
? "YES":"NO");
2047 if (target
->modes
) {
2049 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
2050 if (IsInvisible(target
)) buffer
[bpos
++] = 'i';
2051 if (IsWallOp(target
)) buffer
[bpos
++] = 'w';
2052 if (IsOper(target
)) buffer
[bpos
++] = 'o';
2053 if (IsGlobal(target
)) buffer
[bpos
++] = 'g';
2054 if (IsServNotice(target
)) buffer
[bpos
++] = 's';
2056 // sethost - reed/apples
2057 // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
2058 if (IsSetHost(target
)) buffer
[bpos
++] = 'h';
2060 if (IsService(target
)) buffer
[bpos
++] = 'k';
2061 if (IsDeaf(target
)) buffer
[bpos
++] = 'd';
2062 if (target
->handle_info
) buffer
[bpos
++] = 'r';
2063 if (IsHiddenHost(target
)) buffer
[bpos
++] = 'x';
2064 if (IsGagged(target
)) buffer_cat(" (gagged)");
2065 if (IsRegistering(target
)) buffer_cat(" (registered account)");
2068 reply("OSMSG_WHOIS_MODES", buffer
);
2070 reply("OSMSG_WHOIS_INFO", target
->info
);
2071 #ifdef WITH_PROTOCOL_P10
2072 reply("OSMSG_WHOIS_NUMERIC", target
->numeric
);
2074 reply("OSMSG_WHOIS_SERVER", target
->uplink
->name
);
2075 reply("OSMSG_WHOIS_ACCOUNT", (target
->handle_info
? target
->handle_info
->handle
: "Not authenticated"));
2077 reply("OSMSG_WHOIS_PRIVS", client_report_privs(target
));
2079 intervalString(buffer
, now
- target
->timestamp
, user
->handle_info
);
2080 reply("OSMSG_WHOIS_NICK_AGE", buffer
);
2081 if (target
->channels
.used
<= MAX_CHANNELS_WHOIS
)
2082 opserv_ison(cmd
->parent
->bot
, user
, target
, "OSMSG_WHOIS_CHANNELS");
2084 reply("OSMSG_WHOIS_HIDECHANS");
2088 static MODCMD_FUNC(cmd_unban
)
2090 struct mod_chanmode change
;
2091 mod_chanmode_init(&change
);
2093 change
.args
[0].mode
= MODE_REMOVE
| MODE_BAN
;
2094 change
.args
[0].u
.hostmask
= argv
[1];
2095 modcmd_chanmode_announce(&change
);
2096 reply("OSMSG_UNBAN_DONE", channel
->name
);
2100 static MODCMD_FUNC(cmd_voiceall
)
2102 struct mod_chanmode
*change
;
2103 unsigned int ii
, count
;
2105 change
= mod_chanmode_alloc(channel
->members
.used
);
2106 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2107 struct modeNode
*mn
= channel
->members
.list
[ii
];
2108 if (mn
->modes
& (MODE_CHANOP
|MODE_HALFOP
|MODE_VOICE
))
2110 change
->args
[count
].mode
= MODE_VOICE
;
2111 change
->args
[count
++].u
.member
= mn
;
2114 change
->argc
= count
;
2115 modcmd_chanmode_announce(change
);
2117 mod_chanmode_free(change
);
2118 reply("OSMSG_CHANNEL_VOICED", channel
->name
);
2122 static MODCMD_FUNC(cmd_devoiceall
)
2124 struct mod_chanmode
*change
;
2125 unsigned int ii
, count
;
2127 change
= mod_chanmode_alloc(channel
->members
.used
);
2128 for (ii
= count
= 0; ii
< channel
->members
.used
; ++ii
) {
2129 struct modeNode
*mn
= channel
->members
.list
[ii
];
2130 if (!(mn
->modes
& MODE_VOICE
))
2132 change
->args
[count
].mode
= MODE_REMOVE
| MODE_VOICE
;
2133 change
->args
[count
++].u
.member
= mn
;
2136 change
->argc
= count
;
2137 modcmd_chanmode_announce(change
);
2139 mod_chanmode_free(change
);
2140 reply("OSMSG_CHANNEL_DEVOICED", channel
->name
);
2144 static MODCMD_FUNC(cmd_stats_bad
) {
2146 unsigned int ii
, end
, here_len
;
2149 /* Show the bad word list.. */
2150 /* TODO: convert nonprinting chars like bold to $b etc in a usable way */
2151 for (ii
=end
=0; ii
<opserv_bad_words
->used
; ii
++) {
2152 here_len
= strlen(opserv_bad_words
->list
[ii
]);
2153 /* If the line is full output it & start again */
2154 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2156 reply("OSMSG_BADWORD_LIST", buffer
);
2159 memcpy(buffer
+end
, opserv_bad_words
->list
[ii
], here_len
);
2161 buffer
[end
++] = ' ';
2164 reply("OSMSG_BADWORD_LIST", buffer
);
2166 /* Show the exemption list.. */
2167 for (it
=dict_first(opserv_exempt_channels
), end
=0; it
; it
=iter_next(it
)) {
2168 here_len
= strlen(iter_key(it
));
2169 if ((end
+ here_len
+ 2) > sizeof(buffer
)) {
2171 reply("OSMSG_EXEMPTED_LIST", buffer
);
2174 memcpy(buffer
+end
, iter_key(it
), here_len
);
2176 buffer
[end
++] = ' ';
2179 reply("OSMSG_EXEMPTED_LIST", buffer
);
2183 static MODCMD_FUNC(cmd_stats_glines
) {
2184 reply("OSMSG_GLINE_COUNT", gline_count());
2188 static MODCMD_FUNC(cmd_stats_shuns
) {
2189 reply("OSMSG_SHUN_COUNT", shun_count());
2194 trace_links(struct userNode
*bot
, struct userNode
*user
, struct server
*server
, unsigned int depth
) {
2195 unsigned int nn
, pos
;
2198 for (nn
=1; nn
<=depth
; nn
<<=1) ;
2199 for (pos
=0, nn
>>=1; nn
>1; ) {
2201 buffer
[pos
++] = (depth
& nn
) ? ((nn
== 1) ? '`' : ' ') : '|';
2202 buffer
[pos
++] = (nn
== 1) ? '-': ' ';
2205 send_message(user
, bot
, "OSMSG_LINKS_SERVER", buffer
, server
->name
, server
->clients
, server
->description
);
2206 if (!server
->children
.used
)
2208 for (nn
=0; nn
<server
->children
.used
-1; nn
++) {
2209 trace_links(bot
, user
, server
->children
.list
[nn
], depth
<<1);
2211 trace_links(bot
, user
, server
->children
.list
[nn
], (depth
<<1)|1);
2214 static MODCMD_FUNC(cmd_stats_links
) {
2215 trace_links(cmd
->parent
->bot
, user
, self
, 1);
2220 static MODCMD_FUNC(cmd_stats_max
) {
2221 reply("OSMSG_MAX_CLIENTS", max_clients
, asctime(localtime(&max_clients_time
)));
2225 static MODCMD_FUNC(cmd_stats_network
) {
2226 struct helpfile_table tbl
;
2227 unsigned int nn
, tot_clients
;
2230 tot_clients
= dict_size(clients
);
2231 reply("OSMSG_NETWORK_INFO", tot_clients
, invis_clients
, curr_opers
.used
);
2232 tbl
.length
= dict_size(servers
)+1;
2234 tbl
.flags
= TABLE_NO_FREE
;
2235 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2236 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2237 tbl
.contents
[0][0] = "Server Name";
2238 tbl
.contents
[0][1] = "Clients";
2239 tbl
.contents
[0][2] = "Load";
2240 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2241 struct server
*server
= iter_data(it
);
2242 char *buffer
= malloc(32);
2243 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2244 tbl
.contents
[nn
][0] = server
->name
;
2245 tbl
.contents
[nn
][1] = buffer
;
2246 sprintf(buffer
, "%u", server
->clients
);
2247 tbl
.contents
[nn
][2] = buffer
+ 16;
2248 sprintf(buffer
+16, "%3.3g%%", ((double)server
->clients
/tot_clients
)*100);
2251 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2252 for (nn
=1; nn
<tbl
.length
; nn
++) {
2253 free((char*)tbl
.contents
[nn
][1]);
2254 free(tbl
.contents
[nn
]);
2256 free(tbl
.contents
[0]);
2261 static MODCMD_FUNC(cmd_stats_network2
) {
2262 struct helpfile_table tbl
;
2266 tbl
.length
= dict_size(servers
)+1;
2268 tbl
.flags
= TABLE_NO_FREE
;
2269 tbl
.contents
= calloc(tbl
.length
, sizeof(*tbl
.contents
));
2270 tbl
.contents
[0] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2271 tbl
.contents
[0][0] = "Server Name";
2272 tbl
.contents
[0][1] = "Numeric";
2273 tbl
.contents
[0][2] = "Link Time";
2274 for (it
=dict_first(servers
), nn
=1; it
; it
=iter_next(it
)) {
2275 struct server
*server
= iter_data(it
);
2276 char *buffer
= malloc(64);
2279 tbl
.contents
[nn
] = calloc(tbl
.width
, sizeof(**tbl
.contents
));
2280 tbl
.contents
[nn
][0] = server
->name
;
2281 #ifdef WITH_PROTOCOL_P10
2282 sprintf(buffer
, "%s (%ld)", server
->numeric
, base64toint(server
->numeric
, strlen(server
->numeric
)));
2286 tbl
.contents
[nn
][1] = buffer
;
2287 ofs
= strlen(buffer
) + 1;
2288 intervalString(buffer
+ ofs
, now
- server
->link
, user
->handle_info
);
2289 if (server
->self_burst
)
2290 strcat(buffer
+ ofs
, " Bursting");
2291 tbl
.contents
[nn
][2] = buffer
+ ofs
;
2294 table_send(cmd
->parent
->bot
, user
->nick
, 0, 0, tbl
);
2295 for (nn
=1; nn
<tbl
.length
; nn
++) {
2296 free((char*)tbl
.contents
[nn
][1]);
2297 free(tbl
.contents
[nn
]);
2299 free(tbl
.contents
[0]);
2304 static MODCMD_FUNC(cmd_stats_reserved
) {
2307 reply("OSMSG_RESERVED_LIST");
2308 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
))
2309 send_message_type(4, user
, cmd
->parent
->bot
, "%s", iter_key(it
));
2313 static MODCMD_FUNC(cmd_stats_trusted
) {
2315 struct trusted_host
*th
;
2316 char length
[INTERVALLEN
], issued
[INTERVALLEN
], limit
[32];
2318 reply("OSMSG_TRUSTED_LIST");
2319 reply("OSMSG_TRUSTED_LIST_BAR");
2320 reply("OSMSG_TRUSTED_LIST_HEADER");
2321 reply("OSMSG_TRUSTED_LIST_BAR");
2323 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
2326 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2328 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2330 sprintf(limit
, "%lu", th
->limit
);
2331 reply("OSMSG_HOST_IS_TRUSTED",
2333 (th
->limit
? limit
: "none"),
2334 (th
->issuer
? th
->issuer
: "<unknown>"),
2335 (th
->issued
? issued
: "some time"),
2336 (th
->expires
? length
: "never"));
2337 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2339 reply("OSMSG_HOST_NOT_TRUSTED", argv
[1]);
2342 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
2345 intervalString(issued
, now
- th
->issued
, user
->handle_info
);
2347 intervalString(length
, th
->expires
- now
, user
->handle_info
);
2349 sprintf(limit
, "%lu", th
->limit
);
2350 reply("OSMSG_HOST_IS_TRUSTED", iter_key(it
),
2351 (th
->limit
? limit
: "none"),
2352 (th
->issuer
? th
->issuer
: "<unknown>"),
2353 (th
->issued
? issued
: "some time"),
2354 (th
->expires
? length
: "never"));
2355 reply("OSMSG_HOST_IS_TRUSTED_DESC", (th
->reason
? th
->reason
: "<unknown>"));
2358 reply("OSMSG_TRUSTED_LIST_END");
2362 static MODCMD_FUNC(cmd_stats_uplink
) {
2363 extern struct cManagerNode cManager
;
2364 struct uplinkNode
*uplink
;
2366 uplink
= cManager
.uplink
;
2367 reply("OSMSG_UPLINK_START", uplink
->name
);
2368 reply("OSMSG_UPLINK_ADDRESS", uplink
->host
, uplink
->port
);
2372 static MODCMD_FUNC(cmd_stats_uptime
) {
2373 char uptime
[INTERVALLEN
];
2375 extern time_t boot_time
;
2376 extern int lines_processed
;
2377 static long clocks_per_sec
;
2379 if (!clocks_per_sec
) {
2380 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
2381 clocks_per_sec
= sysconf(_SC_CLK_TCK
);
2382 if (clocks_per_sec
<= 0)
2385 log_module(OS_LOG
, LOG_ERROR
, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong");
2386 clocks_per_sec
= CLOCKS_PER_SEC
;
2389 intervalString(uptime
, time(NULL
)-boot_time
, user
->handle_info
);
2391 reply("OSMSG_UPTIME_STATS",
2392 uptime
, lines_processed
,
2393 buf
.tms_utime
/(double)clocks_per_sec
,
2394 buf
.tms_stime
/(double)clocks_per_sec
);
2398 static MODCMD_FUNC(cmd_stats_alerts
) {
2400 struct opserv_user_alert
*alert
;
2401 const char *reaction
;
2405 m
= unsplit_string(argv
+ 1, argc
- 1, NULL
);
2406 reply("OSMSG_ALERTS_LIST", m
? m
: "*");
2407 reply("OSMSG_ALERTS_BAR");
2408 reply("OSMSG_ALERTS_HEADER");
2409 reply("OSMSG_ALERTS_BAR");
2410 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
2411 alert
= iter_data(it
);
2412 if(m
&& (!match_ircglob(alert
->text_discrim
, m
) && strcasecmp(alert
->owner
, m
)) )
2413 continue; /* not a match to requested filter */
2414 switch (alert
->reaction
) {
2415 case REACT_NOTICE
: reaction
= "notice"; break;
2416 case REACT_KILL
: reaction
= "kill"; break;
2417 // case REACT_SILENT: reaction = "silent"; break;
2418 case REACT_GLINE
: reaction
= "gline"; break;
2419 case REACT_TRACK
: reaction
= "track"; break;
2420 case REACT_SHUN
: reaction
= "shun"; break;
2421 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
2422 case REACT_SVSPART
: reaction
= "svspart"; break;
2423 case REACT_VERSION
: reaction
= "version"; break;
2424 case REACT_MARK
: reaction
= "mark"; break;
2425 default: reaction
= "<unknown>"; break;
2427 reply("OSMSG_ALERT_IS", iter_key(it
), reaction
, alert
->owner
);
2428 reply("OSMSG_ALERTS_DESC", alert
->text_discrim
);
2430 reply("OSMSG_ALERT_END");
2434 static MODCMD_FUNC(cmd_stats_gags
) {
2435 struct gag_entry
*gag
;
2436 struct helpfile_table table
;
2440 reply("OSMSG_NO_GAGS");
2443 for (nn
=0, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) ;
2444 table
.length
= nn
+1;
2446 table
.flags
= TABLE_NO_FREE
;
2447 table
.contents
= calloc(table
.length
, sizeof(char**));
2448 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
2449 table
.contents
[0][0] = "Mask";
2450 table
.contents
[0][1] = "Owner";
2451 table
.contents
[0][2] = "Expires";
2452 table
.contents
[0][3] = "Reason";
2453 for (nn
=1, gag
=gagList
; gag
; nn
++, gag
=gag
->next
) {
2454 char expstr
[INTERVALLEN
];
2456 intervalString(expstr
, gag
->expires
- now
, user
->handle_info
);
2458 strcpy(expstr
, "Never");
2459 table
.contents
[nn
] = calloc(table
.width
, sizeof(char*));
2460 table
.contents
[nn
][0] = gag
->mask
;
2461 table
.contents
[nn
][1] = gag
->owner
;
2462 table
.contents
[nn
][2] = strdup(expstr
);
2463 table
.contents
[nn
][3] = gag
->reason
;
2465 table_send(cmd
->parent
->bot
, user
->nick
, 0, NULL
, table
);
2466 for (nn
=1; nn
<table
.length
; nn
++) {
2467 free((char*)table
.contents
[nn
][2]);
2468 free(table
.contents
[nn
]);
2470 free(table
.contents
[0]);
2471 free(table
.contents
);
2475 static MODCMD_FUNC(cmd_stats_timeq
) {
2476 reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now
);
2481 static MODCMD_FUNC(cmd_stats_warn) {
2484 reply("OSMSG_WARN_LISTSTART");
2485 for (it=dict_first(opserv_chan_warn); it; it=iter_next(it))
2486 reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it));
2487 reply("OSMSG_WARN_LISTEND");
2492 #if defined(WITH_MALLOC_X3)
2493 static MODCMD_FUNC(cmd_stats_memory
) {
2494 extern unsigned long alloc_count
, alloc_size
;
2495 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2496 "%u allocations totalling %u bytes.",
2497 alloc_count
, alloc_size
);
2500 #elif defined(WITH_MALLOC_SLAB)
2501 static MODCMD_FUNC(cmd_stats_memory
) {
2502 extern unsigned long slab_alloc_count
, slab_count
, slab_alloc_size
;
2503 extern unsigned long big_alloc_count
, big_alloc_size
;
2504 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2505 "%u allocations in %u slabs totalling %u bytes.",
2506 slab_alloc_count
, slab_count
, slab_alloc_size
);
2507 send_message_type(MSG_TYPE_NOXLATE
, user
, cmd
->parent
->bot
,
2508 "%u big allocations totalling %u bytes.",
2509 big_alloc_count
, big_alloc_size
);
2514 static MODCMD_FUNC(cmd_dump
)
2516 char linedup
[MAXLEN
], original
[MAXLEN
];
2518 unsplit_string(argv
+1, argc
-1, original
);
2519 safestrncpy(linedup
, original
, sizeof(linedup
));
2520 /* assume it's only valid IRC if we can parse it */
2521 if (parse_line(linedup
, 1)) {
2523 reply("OSMSG_LINE_DUMPED");
2525 reply("OSMSG_RAW_PARSE_ERROR");
2529 static MODCMD_FUNC(cmd_raw
)
2531 char linedup
[MAXLEN
], original
[MAXLEN
];
2533 unsplit_string(argv
+1, argc
-1, original
);
2534 safestrncpy(linedup
, original
, sizeof(linedup
));
2535 /* Try to parse the line before sending it; if it's too wrong,
2536 * maybe it will core us instead of our uplink. */
2537 parse_line(linedup
, 1);
2539 reply("OSMSG_LINE_DUMPED");
2543 static struct userNode
*
2544 opserv_add_reserve(struct svccmd
*cmd
, struct userNode
*user
, const char *nick
, const char *ident
, const char *host
, const char *desc
)
2546 struct userNode
*resv
= GetUserH(nick
);
2548 if (IsService(resv
)) {
2549 reply("MSG_SERVICE_IMMUNE", resv
->nick
);
2552 if (resv
->handle_info
2553 && resv
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
) {
2554 reply("OSMSG_LEVEL_TOO_LOW");
2558 if ((resv
= AddClone(nick
, ident
, host
, desc
))) {
2559 dict_insert(opserv_reserved_nick_dict
, resv
->nick
, resv
);
2564 static MODCMD_FUNC(cmd_collide
)
2566 struct userNode
*resv
;
2568 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2570 reply("OSMSG_COLLIDED_NICK", resv
->nick
);
2573 reply("OSMSG_CLONE_FAILED", argv
[1]);
2578 static MODCMD_FUNC(cmd_reserve
)
2580 struct userNode
*resv
;
2582 resv
= opserv_add_reserve(cmd
, user
, argv
[1], argv
[2], argv
[3], unsplit_string(argv
+4, argc
-4, NULL
));
2584 resv
->modes
|= FLAGS_PERSISTENT
;
2585 reply("OSMSG_RESERVED_NICK", resv
->nick
);
2588 reply("OSMSG_CLONE_FAILED", argv
[1]);
2594 free_reserve(char *nick
)
2596 struct userNode
*resv
;
2600 resv
= dict_find(opserv_reserved_nick_dict
, nick
, NULL
);
2604 rlen
= strlen(resv
->nick
)+strlen(OSMSG_PART_REASON
);
2605 reason
= alloca(rlen
);
2606 snprintf(reason
, rlen
, OSMSG_PART_REASON
, resv
->nick
);
2607 DelUser(resv
, NULL
, 1, reason
);
2608 dict_remove(opserv_reserved_nick_dict
, nick
);
2612 static MODCMD_FUNC(cmd_unreserve
)
2614 if (free_reserve(argv
[1]))
2615 reply("OSMSG_NICK_UNRESERVED", argv
[1]);
2617 reply("OSMSG_NOT_RESERVED", argv
[1]);
2622 opserv_part_channel(void *data
)
2624 DelChannelUser(opserv
, data
, "Leaving.", 0);
2627 static int alert_check_user(const char *key
, void *data
, void *extra
);
2630 opserv_new_user_check(struct userNode
*user
)
2632 struct opserv_hostinfo
*ohi
;
2633 struct gag_entry
*gag
;
2634 char addr
[IRC_NTOP_MAX_SIZE
];
2636 /* Check to see if we should ignore them entirely. */
2637 if (IsLocal(user
) || IsService(user
))
2640 /* Check for alerts, and stop if we find one that kills them. */
2641 if (dict_foreach(opserv_user_alerts
, alert_check_user
, user
))
2644 /* Gag them if appropriate. */
2645 for (gag
= gagList
; gag
; gag
= gag
->next
) {
2646 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
2647 gag_helper_func(user
, NULL
);
2652 /* Add to host info struct */
2653 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2654 if (!(ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2655 ohi
= calloc(1, sizeof(*ohi
));
2656 dict_insert(opserv_hostinfo_dict
, strdup(addr
), ohi
);
2657 userList_init(&ohi
->clients
);
2659 userList_append(&ohi
->clients
, user
);
2661 /* Only warn of new user floods outside of bursts. */
2662 if (!user
->uplink
->burst
) {
2663 if (!policer_conforms(&opserv_conf
.new_user_policer
, now
, 10)) {
2664 if (!new_user_flood
) {
2666 opserv_alert("Warning: Possible new-user flood.");
2673 if (checkDefCon(DEFCON_NO_NEW_CLIENTS
)) {
2674 irc_kill(opserv
, user
, DefConGlineReason
);
2678 if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS
)) && !IsOper(user
)) {
2679 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2681 strcpy(target
+ 2, user
->hostname
);
2682 if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS
))
2683 gline_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1, 0);
2684 else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS
))
2685 shun_add(opserv
->nick
, target
, DefConGlineExpire
, DefConGlineReason
, now
, 1);
2690 /* Only warn or G-line if there's an untrusted max and their IP is sane. */
2691 if (opserv_conf
.untrusted_max
2692 && irc_in_addr_is_valid(user
->ip
)
2693 && !irc_in_addr_is_loopback(user
->ip
)) {
2694 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, addr
, NULL
);
2695 unsigned int limit
= th
? th
->limit
: opserv_conf
.untrusted_max
;
2697 if (checkDefCon(DEFCON_REDUCE_SESSION
) && !th
)
2698 limit
= DefConSessionLimit
;
2701 /* 0 means unlimited hosts */
2702 } else if (ohi
->clients
.used
== limit
) {
2704 for (nn
=0; nn
<ohi
->clients
.used
; nn
++)
2705 send_message(ohi
->clients
.list
[nn
], opserv
, "OSMSG_CLONE_WARNING");
2706 } else if (ohi
->clients
.used
> limit
) {
2707 char target
[IRC_NTOP_MAX_SIZE
+ 3] = { '*', '@', '\0' };
2708 strcpy(target
+ 2, addr
);
2709 gline_add(opserv
->nick
, target
, opserv_conf
.clone_gline_duration
, "Excessive connections from a single host.", now
, 1, 1);
2717 opserv_user_cleanup(struct userNode
*user
, UNUSED_ARG(struct userNode
*killer
), UNUSED_ARG(const char *why
))
2719 struct opserv_hostinfo
*ohi
;
2720 char addr
[IRC_NTOP_MAX_SIZE
];
2722 if (IsLocal(user
)) {
2723 /* Try to remove it from the reserved nick dict without
2724 * calling free_reserve, because that would call DelUser(),
2725 * and we'd loop back to here. */
2726 dict_remove(opserv_reserved_nick_dict
, user
->nick
);
2729 irc_ntop(addr
, sizeof(addr
), &user
->ip
);
2730 if ((ohi
= dict_find(opserv_hostinfo_dict
, addr
, NULL
))) {
2731 userList_remove(&ohi
->clients
, user
);
2732 if (ohi
->clients
.used
== 0)
2733 dict_remove(opserv_hostinfo_dict
, addr
);
2738 opserv_bad_channel(const char *name
)
2743 dict_find(opserv_exempt_channels
, name
, &present
);
2747 if (gline_find(name
))
2750 for (found
=0; found
<opserv_bad_words
->used
; ++found
)
2751 if (irccasestr(name
, opserv_bad_words
->list
[found
]))
2758 opserv_shutdown_channel(struct chanNode
*channel
, const char *reason
)
2760 struct mod_chanmode
*change
;
2763 change
= mod_chanmode_alloc(2);
2764 change
->modes_set
= MODE_SECRET
| MODE_INVITEONLY
;
2765 change
->args
[0].mode
= MODE_CHANOP
;
2766 change
->args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2767 change
->args
[1].mode
= MODE_BAN
;
2768 change
->args
[1].u
.hostmask
= "*!*@*";
2769 mod_chanmode_announce(opserv
, channel
, change
);
2770 mod_chanmode_free(change
);
2771 for (nn
=channel
->members
.used
; nn
>0; ) {
2772 struct modeNode
*mNode
= channel
->members
.list
[--nn
];
2773 if (IsService(mNode
->user
))
2775 KickChannelUser(mNode
->user
, channel
, opserv
, user_find_message(mNode
->user
, reason
));
2777 timeq_add(now
+ opserv_conf
.purge_lock_delay
, opserv_part_channel
, channel
);
2781 opserv_channel_check(struct chanNode
*newchan
)
2785 if (!newchan
->join_policer
.params
) {
2786 newchan
->join_policer
.last_req
= now
;
2787 newchan
->join_policer
.params
= opserv_conf
.join_policer_params
;
2790 if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) {
2791 global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning);
2795 /* Wait until the join check to shut channels down. */
2796 newchan
->bad_channel
= opserv_bad_channel(newchan
->name
);
2800 opserv_channel_delete(struct chanNode
*chan
)
2802 timeq_del(0, opserv_part_channel
, chan
, TIMEQ_IGNORE_WHEN
);
2806 opserv_notice_handler(struct userNode
*user
, struct userNode
*bot
, char *text
, UNUSED_ARG(int server_qualified
))
2809 /* if its a version reply, do an alert check (only alerts with version=something) */
2811 if(text
[0] == '\001') {
2813 cmd
= mysep(&text
, " ");
2814 if(cmd
&& !irccasecmp(cmd
, "VERSION")) {
2815 char *version
= mysep(&text
, "\n");
2818 /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */
2819 /* user->version_reply = strdup(version); done in parse-p10.c now */
2820 dict_foreach(opserv_user_alerts
, alert_check_user
, user
);
2827 opserv_join_check(struct modeNode
*mNode
)
2829 struct userNode
*user
= mNode
->user
;
2830 struct chanNode
*channel
= mNode
->channel
;
2833 if (IsService(user
))
2836 dict_foreach(opserv_channel_alerts
, alert_check_user
, user
);
2838 if (channel
->bad_channel
) {
2839 opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user
->nick
, channel
->name
);
2840 if (channel
->name
[0] != '#')
2841 DelUser(user
, opserv
, 1, "OSMSG_ILLEGAL_KILL_REASON");
2842 else if (!GetUserMode(channel
, opserv
))
2843 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
2845 send_message(user
, opserv
, "OSMSG_ILLEGAL_CHANNEL", channel
->name
);
2846 msg
= user_find_message(user
, "OSMSG_ILLEGAL_REASON");
2847 KickChannelUser(user
, channel
, opserv
, msg
);
2852 if (user
->uplink
->burst
)
2854 if (policer_conforms(&channel
->join_policer
, now
, 1.0)) {
2855 channel
->join_flooded
= 0;
2858 if (!channel
->join_flooded
) {
2859 /* Don't moderate the channel unless it is activated and
2860 the number of users in the channel is over the threshold. */
2861 struct mod_chanmode change
;
2862 mod_chanmode_init(&change
);
2863 channel
->join_flooded
= 1;
2864 if (opserv_conf
.join_flood_moderate
&& (channel
->members
.used
> opserv_conf
.join_flood_moderate_threshold
)) {
2865 if (!GetUserMode(channel
, opserv
)) {
2866 /* If we aren't in the channel, join it. */
2867 change
.args
[0].mode
= MODE_CHANOP
;
2868 change
.args
[0].u
.member
= AddChannelUser(opserv
, channel
);
2871 if (!(channel
->modes
& MODE_MODERATED
))
2872 change
.modes_set
|= MODE_MODERATED
;
2873 if (change
.modes_set
|| change
.argc
)
2874 mod_chanmode_announce(opserv
, channel
, &change
);
2875 send_target_message(0, channel
->name
, opserv
, "OSMSG_FLOOD_MODERATE");
2876 opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel
->name
, channel
->members
.used
);
2878 opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel
->name
, channel
->members
.used
);
2881 log_module(OS_LOG
, LOG_INFO
, "Join to %s during flood: "IDENT_FORMAT
, channel
->name
, IDENT_DATA(user
));
2886 opserv_add_bad_word(struct svccmd
*cmd
, struct userNode
*user
, const char *new_bad
) {
2887 unsigned int bad_idx
;
2889 for (bad_idx
= 0; bad_idx
< opserv_bad_words
->used
; ++bad_idx
) {
2890 char *orig_bad
= opserv_bad_words
->list
[bad_idx
];
2891 if (irccasestr(new_bad
, orig_bad
)) {
2893 reply("OSMSG_BAD_REDUNDANT", new_bad
, orig_bad
);
2895 } else if (irccasestr(orig_bad
, new_bad
)) {
2897 reply("OSMSG_BAD_GROWING", orig_bad
, new_bad
);
2899 opserv_bad_words
->list
[bad_idx
] = strdup(new_bad
);
2900 for (bad_idx
++; bad_idx
< opserv_bad_words
->used
; bad_idx
++) {
2901 orig_bad
= opserv_bad_words
->list
[bad_idx
];
2902 if (!irccasestr(orig_bad
, new_bad
))
2905 reply("OSMSG_BAD_NUKING", orig_bad
);
2906 string_list_delete(opserv_bad_words
, bad_idx
);
2913 string_list_append(opserv_bad_words
, strdup(new_bad
));
2915 reply("OSMSG_ADDED_BAD", new_bad
);
2920 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
)
2922 struct routingPlanServer
*rps
;
2923 rps
= calloc(1, sizeof(*rps
));
2926 /* duplicate servers replace */
2927 rps
->uplink
= strdup(uplink
);
2929 rps
->secondaryuplink
= strdup(second
);
2931 rps
->secondaryuplink
= NULL
;
2932 rps
->port
= port
? port
: 4400; /* lame hardcodede default port. maybe get from config file somewhere? */
2934 rps
->offline
= offline
; /* 1 = yes, 0 = no */
2935 dict_insert(rp
->servers
, strdup(name
), rps
);
2936 log_module(OS_LOG
, LOG_DEBUG
, "Adding rp server %s with uplink %s", name
, uplink
);
2941 free_routing_plan_server(void *data
)
2943 struct routingPlanServer
*rps
= data
;
2945 if(rps
->secondaryuplink
)
2946 free(rps
->secondaryuplink
);
2951 opserv_add_routing_plan(const char *name
)
2953 struct routingPlan
*rp
;
2954 rp
= calloc(1, sizeof(*rp
));
2957 if(dict_find(opserv_routing_plans
, name
, NULL
))
2958 return NULL
; /* plan already exists */
2959 rp
->servers
= dict_new();
2960 dict_set_free_data(rp
->servers
, free_routing_plan_server
);
2962 dict_insert(opserv_routing_plans
, strdup(name
), rp
);
2963 /* TODO: check for duplicate */
2968 free_routing_plan(void *data
)
2970 struct routingPlan
*rp
= data
;
2971 /* delete all the servers attached to this plan */
2972 dict_delete(rp
->servers
);
2973 /* free the plan struct */
2977 /*************************************************
2978 * Functions to handle the active routing struct */
2981 *find_routeList_server(struct route
*route
, const char *server
)
2983 struct routeList
*rptr
;
2986 for(rptr
= route
->servers
;rptr
;rptr
=rptr
->next
) {
2987 if(!strcasecmp(rptr
->server
, server
))
2993 /* Wipes out the routing structure, freeing properly.
2994 * note: does NOT free itself, we just re-use it usually.*/
2996 wipe_route_list(struct route
*route
) {
2997 struct routeList
*nextptr
, *rptr
;
3000 for(rptr
= opserv_route
->servers
; rptr
; rptr
=nextptr
)
3002 nextptr
= rptr
->next
;
3006 if(rptr
->secondaryuplink
)
3007 free(rptr
->secondaryuplink
);
3010 route
->centered
= true;
3012 route
->maxdepth
= 0;
3013 route
->servers
= NULL
;
3018 rank_outside_rec(struct route
*route
, char *server
, int count
)
3020 struct routeList
*rptr
;
3023 if(count
> 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */
3026 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3028 if(!strcasecmp(server
, rptr
->uplink
)) {
3029 log_module(MAIN_LOG
, LOG_DEBUG
, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count
, i
, rptr
->server
, rptr
->uplink
);
3030 n
= rank_outside_rec(route
, rptr
->server
, count
+1);
3031 if(n
< 0) /* handle error condition */
3037 if((rptr
= find_routeList_server(route
, server
))) {
3038 rptr
->outsideness
= max
;
3042 log_module(MAIN_LOG
, LOG_ERROR
, "routing struct rank_outsideness() couldnt find %s", server
);
3048 rank_outsideness(struct route
*route
)
3050 log_module(MAIN_LOG
, LOG_DEBUG
, "rank_outsideness(): Running...");
3051 route
->maxdepth
= rank_outside_rec(route
, self
->uplink
->name
, 0) - 1;
3052 if(route
->maxdepth
< 0) { /* if the rank failed, remove route */
3053 log_module(MAIN_LOG
, LOG_WARNING
, "The active routing plan has a loop! auto routing disabled.");
3054 wipe_route_list(route
);
3061 /* Add servers to the routing structure */
3063 add_routestruct_server(struct route
*route
, const char *server
, unsigned int port
, char *uplink
, char *secondary
)
3065 struct routeList
*rptr
;
3067 if(find_routeList_server(route
, server
))
3069 log_module(MAIN_LOG
, LOG_WARNING
, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server
);
3072 rptr
= calloc(1, sizeof(*rptr
));
3073 rptr
->server
= strdup(server
);
3076 hname
= conf_get_data("server/hostname", RECDB_QSTRING
);
3079 rptr
->uplink
= strdup(uplink
);
3081 rptr
->secondaryuplink
= strdup(secondary
);
3082 /* tack this server on the front of the list */
3083 rptr
->next
= route
->servers
;
3084 route
->servers
= rptr
;
3087 #ifdef notdef /* I dont quite get this. there could be uncentered things
3088 * added after our own uplink, and this function doesnt center
3089 * as it adds. -Rubin */
3090 /* If the map hasnt been centered yet... */
3091 if(route
->centered
== false) {
3092 /* AND we just added our own uplink to it... */
3093 if(!strcasecmp(server
, self
->uplink
->name
)) {
3094 change_route_uplinks(route
); /* recenter it, n mark it centered. */
3100 /* Recenter the routing struct around our current uplink */
3102 change_route_uplinks(struct route
*route
)
3104 struct routeList
*rptr
;
3105 char lastserver
[MAXLEN
];
3106 char nextserver
[MAXLEN
];
3109 return false; /* no map to recenter */
3110 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks(): running...");
3111 char *servicename
= conf_get_data("server/hostname", RECDB_QSTRING
);
3112 strcpy(lastserver
, servicename
);
3113 rptr
= find_routeList_server(route
, self
->uplink
->name
);
3115 log_module(MAIN_LOG
, LOG_ERROR
, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered.");
3116 route
->centered
= false;
3119 if(!strcasecmp(rptr
->uplink
, servicename
)) {
3120 log_module(MAIN_LOG
, LOG_DEBUG
, "Already centered");
3122 else { /* else, center it */
3124 strcpy(nextserver
, rptr
->uplink
);
3125 log_module(MAIN_LOG
, LOG_DEBUG
, "change_route_uplinks() changing %s uplink to %s.", rptr
->server
, lastserver
);
3127 rptr
->uplink
= strdup(lastserver
);
3128 strcpy(lastserver
, rptr
->server
);
3129 rptr
= find_routeList_server(route
, nextserver
);
3132 if(rank_outsideness(route
) > 0) {
3133 route
->centered
= true;
3141 activate_routing(struct svccmd
*cmd
, struct userNode
*user
, char *plan_name
)
3143 static struct routingPlan
*rp
;
3147 if(plan_name
) { /* make this the new active plan */
3148 if(!strcmp(plan_name
, "*")) {
3149 /* disable routing */
3150 dict_remove(opserv_routing_plan_options
, "ACTIVE");
3154 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3157 reply("OSMSG_PLAN_NOT_FOUND", plan_name
);
3159 /* since it doesnt exist, remove the active setting */
3160 dict_remove(opserv_routing_plan_options
, plan_name
);
3162 log_module(MAIN_LOG
, LOG_ERROR
, "activate_routing() couldnt find active routing plan!");
3167 else { /* find the active plan in settings */
3168 plan_name
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3170 if(!plan_name
) { /* deactivated, or no plan was set active */
3171 /* TODO: delete routing map if it exists */
3172 wipe_route_list(opserv_route
);
3176 karma
= dict_find(opserv_routing_plan_options
, "KARMA", NULL
);
3178 rp
= dict_find(opserv_routing_plans
, plan_name
, NULL
);
3180 /* this should really be done during opserv init */
3182 opserv_route
= calloc(1, sizeof(*opserv_route
));
3184 /* Delete the existing active route */
3185 wipe_route_list(opserv_route
);
3187 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3188 const char* servername
= iter_key(it
);
3189 struct routingPlanServer
*rps
= iter_data(it
),
3190 *rp_uplink
, *rp_second
= NULL
;
3191 char *uplink
= rps
->uplink
;
3192 rp_uplink
= dict_find(rp
->servers
, rps
->uplink
, NULL
);
3193 if(rps
->secondaryuplink
)
3194 rp_second
= dict_find(rp
->servers
, rps
->secondaryuplink
, NULL
);
3196 /* If the normal uplink has bad karma, don't use it as a hub,
3197 * switch to the secondary uplink.
3199 if(karma
&& enabled_string(karma
) && rp_uplink
&& rp_uplink
->karma
< 0) {
3200 if(rps
->secondaryuplink
) {
3201 uplink
= rps
->secondaryuplink
;
3202 /* unless the secondary uplinks karma is worse than the uplink. */
3203 if((rp_second
= dict_find(rp
->servers
, uplink
, NULL
)) && rp_second
->karma
< rp_uplink
->karma
)
3204 uplink
= rps
->uplink
;
3208 * If _WE_ have bad karma, don't link us to our normal uplink, maybe
3209 * its a bad route. switch to secondary. Important: dont neg karma when we arnt on
3210 * our primary uplink, or we'll get stuck on secondary when THAT link is worse.
3212 if(karma
&& enabled_string(karma
) && (rps
->karma
< 0 || rps
->offline
) ) {
3213 if(rps
->secondaryuplink
) {
3214 uplink
= rps
->secondaryuplink
;
3217 log_module(MAIN_LOG
, LOG_DEBUG
, "activate_routing() adding %s:%d %s", servername
, rps
->port
, uplink
);
3218 add_routestruct_server(opserv_route
, servername
, rps
->port
, uplink
, NULL
);
3220 if(change_route_uplinks(opserv_route
))
3225 reply("OSMSG_ROUTING_ACTIVATION_ERROR");
3226 activate_routing(cmd
, user
, "*");
3229 /* routing activation failed but we dont do anything? */
3236 activate_routing(NULL
, NULL
, NULL
);
3238 /* start auto-routing system */
3239 reroute_timer_reset(0);
3242 /*******************************************************
3243 * Functions to handle online route configuration via opserv
3245 static void route_show_option(struct svccmd
*cmd
, struct userNode
*user
, char *name
)
3247 char *value
= dict_find(opserv_routing_plan_options
, name
, NULL
);
3249 if(!strcmp("RETRY_PERIOD", name
)) { /* Show as an interval */
3250 char buff
[INTERVALLEN
+1];
3251 reply("OSMSG_ROUTINGPLAN_OPTION", name
, intervalString(buff
, atoi(value
), user
->handle_info
));
3253 else if(!strcmp("ACTIVE", name
)) {
3254 if(opserv_route
&& opserv_route
->servers
)
3255 reply("OSMSG_ROUTINGPLAN_ACTIVE", value
);
3257 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3260 reply("OSMSG_ROUTINGPLAN_OPTION", name
, value
);
3264 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name
);
3268 static void route_show_options(struct svccmd
*cmd
, struct userNode
*user
)
3270 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3272 for(i
= 0; options
[i
]; i
++) {
3273 route_show_option(cmd
, user
, options
[i
]);
3277 /* called from timeq */
3278 void routing_connect_timeout(void *data
)
3280 struct waitingConnection
*wc
= data
;
3281 struct server
*target
= GetServerH(wc
->target
);
3283 dict_remove(opserv_waiting_connections
, wc
->server
);
3284 return; /* server we wanted to connect new server to is gone, just give up */
3286 routing_handle_connect_failure(target
, wc
->server
, "Connection timed out");
3287 /* the following invalidates server variable! */
3288 dict_remove(opserv_waiting_connections
, wc
->server
);
3291 void routing_delete_connect_timer(char *server
)
3293 struct waitingConnection
*wc
= dict_find(opserv_waiting_connections
, server
, 0);
3295 timeq_del(0, routing_connect_timeout
, wc
, TIMEQ_IGNORE_WHEN
);
3296 dict_remove(opserv_waiting_connections
, server
);
3302 routing_connect_server(char *server
, int port
, struct server
*to
)
3304 struct waitingConnection
*wc
= calloc(sizeof(*wc
), 1);
3306 wc
->server
= strdup(server
);
3307 wc
->target
= strdup(to
->name
);
3308 /* Just to make sure there isn't one left hanging
3309 * if 2 connections are attempted at once..
3311 routing_delete_connect_timer(server
);
3312 dict_insert(opserv_waiting_connections
, strdup(server
), wc
);
3313 timeq_add(now
+ ROUTING_CONNECT_TIMEOUT
, routing_connect_timeout
, wc
);
3315 irc_connect(opserv
, server
, port
, to
);
3319 routing_connect_one(struct route
*route
, char *server
)
3321 struct routeList
*rptr
;
3322 struct server
*sptr
, *suptr
;
3323 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3324 if(!strcasecmp(rptr
->server
, server
)) {
3325 /* this is the one, connect it */
3326 suptr
= GetServerH(rptr
->uplink
);
3327 sptr
= GetServerH(rptr
->server
);
3329 return 1; /* already linked */
3331 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3332 return 1; /* attempted link */
3334 return 0; /* its uplink isnt here to link to */
3337 log_module(MAIN_LOG
, LOG_DEBUG
, "Tried to link %s but its not in the active routing struct!", server
);
3338 return 0; /* server wasnt found in active route struct. */
3341 int routing_connect_children(struct route
*route
, char *server
)
3343 struct routeList
*rptr
;
3344 struct server
*sptr
, *suptr
;
3345 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3346 if(!strcasecmp(rptr
->uplink
, server
)) {
3347 /* this is the one, connect it */
3348 suptr
= GetServerH(rptr
->uplink
);
3349 sptr
= GetServerH(rptr
->server
);
3351 continue; /* already linked */
3353 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3354 continue; /* attempted link */
3356 continue; /* its uplink isnt here to link to */
3359 return 1; /* server wasnt found in active route struct ?! */
3362 int reroute(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
, char *directive
)
3364 struct routeList
*rptr
;
3365 struct server
*sptr
, *suptr
;
3366 int connect
= 0, move
= 0, missing
= 0, i
;
3367 char d
= toupper(*directive
);
3369 if(!route
|| !route
->servers
) {
3370 reply("OSMSG_REROUTING_NOTCONFIGURED");
3374 if(d
== 'N') { /* normal */
3375 irc_wallops("%s", "Attempting a reroute of the network according to loaded map...");
3376 reply("OSMSG_REROUTING_ACC_MAP");
3378 else if(d
== 'C') { /* only connect */
3379 reply("OSMSG_CONNECTING_MISSING_ONLY");
3381 else if(d
== 'T') { /* test */
3382 reply("OSMSG_TESTING_REROUTE");
3386 reply("OSMSG_INVALID_DIRECTIVE", directive
);
3390 for(i
= 0; i
<= route
->maxdepth
-1; i
++) {
3391 for(rptr
= route
->servers
; rptr
; rptr
= rptr
->next
) {
3392 if(rptr
->outsideness
== i
) {
3395 reply("OSMSG_INSPECTING_SERVER", rptr
->server
);
3396 suptr
= GetServerH(rptr
->uplink
);
3398 if(rptr
->secondaryuplink
&& (suptr
= GetServerH(rptr
->secondaryuplink
))) {
3400 reply("OSMSG_COULDNT_FIND_SERVER", rptr
->uplink
, rptr
->secondaryuplink
, rptr
->server
);
3403 if(suptr
) { /* if the proper uplink is connected.. */
3404 sptr
= GetServerH(rptr
->server
);
3405 if(d
== 'C' && sptr
) {
3406 continue; /* Already linked */
3408 /* If server is missing or the uplinks are not the same then... */
3409 else if(!sptr
|| strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3413 else { /* Server is already connected somewhere */
3414 if(strcasecmp(sptr
->uplink
->name
, rptr
->uplink
)) {
3415 if(d
!= 'T') { /* do it for real */
3416 irc_squit_route(sptr
, "%s issued reroute.", user
? user
->nick
: opserv
->nick
);
3418 else { /* just pretend */
3419 reply("OSMSG_SQUIT", rptr
->server
);
3424 if(d
!= 'T') /* do the real thing */
3425 routing_connect_server(rptr
->server
, rptr
->port
, suptr
);
3426 else /* just pretend */
3427 reply("OSMSG_CONNECT", rptr
->server
, rptr
->port
, suptr
->name
);
3431 log_module(MAIN_LOG
, LOG_DEBUG
, "server uplink %s was not found, cant connect %s", rptr
->uplink
, rptr
->server
);
3434 } /* outsideness = 1 */
3437 if(user
) { /* report on what we did */
3438 if(!strcasecmp(directive
, "C")) {
3440 reply("OSMSG_CONNECTING_MISSING", connect
);
3442 reply("OSMSG_NO_SERVERS_MISSING");
3445 if(move
+connect
> 0)
3446 reply("OSMSG_REROUTE_COMPLETE", move
, connect
, move
+connect
);
3448 reply("OSMSG_NO_ROUTING_NECESSARY");
3450 reply("OSMSG_UPLINKS_MISSING", missing
);
3453 return(move
+connect
);
3456 static MODCMD_FUNC(cmd_reroute
) {
3459 if(reroute(opserv_route
, user
, cmd
, upper
))
3465 /* reroute_timer(run)
3466 * run - if it is null, just setup the timer
3467 * but dont run reroute now. otherwise reroute
3470 void reroute_timer(void *data
) {
3471 /* Delete any other timers such as this one.. */
3472 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3474 if(!opserv_route
|| !opserv_route
->servers
)
3475 return; /* no active route */
3476 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3478 return; /* retry_period invalid */
3479 unsigned int freq
= atoi(retry_period
);
3481 return; /* retry_period set to 0, disable */
3483 /* opserv_debug("Reroute timer checking reroute"); */
3484 log_module(MAIN_LOG
, LOG_DEBUG
, "Reroute timer checking reroute()");
3486 /* Do the reroute C attempt */
3488 reroute(opserv_route
, NULL
, NULL
, "C");
3490 /* Re-add ourselves to the timer queue */
3491 timeq_add(now
+ freq
, reroute_timer
, "run");
3494 void routing_change_karma(struct routingPlanServer
*rps
, const char *server
, int change
) {
3496 int oldkarma
= rps
->karma
;
3497 rps
->karma
+= change
;
3498 if(rps
->karma
< KARMA_MIN
)
3499 rps
->karma
= KARMA_MIN
;
3500 if(rps
->karma
> KARMA_MAX
)
3501 rps
->karma
= KARMA_MAX
;
3502 log_module(MAIN_LOG
, LOG_DEBUG
, "Changing %s karma by %d. new karma %d.", server
, change
, rps
->karma
);
3503 if(oldkarma
> 0 && rps
->karma
< 0) {
3504 /* we just crossed over to negitive */
3505 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went negitive karma!", server
);
3506 activate_routing(NULL
, NULL
, NULL
);
3508 else if(oldkarma
< 0 && rps
->karma
> 0) {
3509 /* we just crossed over to positive */
3510 log_module(MAIN_LOG
, LOG_INFO
, "Server %s just went back positive karma.", server
);
3511 activate_routing(NULL
, NULL
, NULL
);
3515 void routing_karma_timer(void *data
) {
3517 time_t timer_init
= data
? atoi(data
) : 0;
3520 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init
);
3522 /* If theres a time passed in, dont run unless that time is overdue. */
3523 if(!timer_init
|| (timer_init
< now
)) {
3524 if(opserv_route
&& opserv_route
->servers
) {
3525 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3526 struct routingPlan
*rp
;
3527 if(active
&& (rp
= dict_find(opserv_routing_plans
, active
, NULL
))) {
3529 /* Walk through each server in the active routing plan.. */
3530 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3531 struct routingPlanServer
*rps
= iter_data(it
);
3532 struct server
*server
= GetServerH(iter_key(it
));
3533 /* Give everyone +KARMA_ENTROPE just for nothing */
3534 routing_change_karma(rps
, iter_key(it
), KARMA_ENTROPE
);
3535 /* give an additonal +KARMA_RELIABLE to servers that
3536 * have been linked at least KARMA_TIMER seconds. */
3537 if(server
&& (server
->link
< (now
- KARMA_TIMER
) ) ) {
3538 routing_change_karma(rps
, iter_key(it
), KARMA_RELIABLE
);
3544 if(timer_init
> now
) /* loading a saved value */
3546 else /* no scheduled timer, or we missed it. start from now */
3547 next
= now
+ KARMA_TIMER
;
3548 /* Save when karma_timer should run again in case we restart before then */
3549 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next
);
3550 sprintf(buf
, "%u", (unsigned int) next
);
3551 dict_insert(opserv_routing_plan_options
, "KARMA_TIMER", strdup(buf
));
3552 /* add a timer to run this again .. */
3553 timeq_add(next
, routing_karma_timer
, NULL
);
3556 void routing_handle_neg_karma(char *server
, char *uplink
, int change
)
3558 /* if server's primary uplink is uplink, OR, uplink's primary uplink is server,
3559 * then whichever one, gets its karma changed. */
3560 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3561 struct routingPlan
*rp
;
3562 struct routingPlanServer
*rps
;
3565 if(!(rp
= dict_find(opserv_routing_plans
, active
, NULL
)))
3567 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3568 if(!strcasecmp(rps
->uplink
, uplink
)) {
3569 /* server's uplink is uplink */
3570 routing_change_karma(rps
, server
, change
);
3574 if((rps
= dict_find(rp
->servers
, uplink
, NULL
))) {
3575 if(!strcasecmp(rps
->uplink
, server
)) {
3576 /* uplink's uplink is server */
3577 routing_change_karma(rps
, uplink
, change
);
3584 routing_handle_squit(char *server
, char *uplink
, char *message
)
3586 log_module(MAIN_LOG
, LOG_DEBUG
, "Routing_handle_squit(%s, %s)", server
, message
);
3590 if(match_ircglob(message
, "Ping timeout")) {
3591 routing_handle_neg_karma(server
, uplink
, KARMA_PINGOUT
);
3592 /* if conn_pingout is true, try to reconnect it obaying karma rules. */
3594 val
= dict_find(opserv_routing_plan_options
, "CONN_PINGOUT", 0);
3595 if(val
&& enabled_string(val
))
3596 routing_connect_one(opserv_route
, server
);
3598 else if(match_ircglob(message
, "Read error:*")) {
3599 routing_handle_neg_karma(server
, uplink
, KARMA_READERROR
);
3600 /* if conn_readerror is true, try to reconnect it obaying karma rules. */
3601 val
= dict_find(opserv_routing_plan_options
, "CONN_READERROR", 0);
3602 if(val
&& enabled_string(val
))
3603 routing_connect_one(opserv_route
, server
);
3605 /* Else whats the message (an oper squit it?) dont interfere */
3609 routing_handle_connect(char *server
, char *uplink
)
3612 struct routingPlan
*rp
;
3613 struct routingPlanServer
*rps
;
3616 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect(%s, %s)", server
, uplink
);
3617 /* delete a pending connection timer, if any */
3618 routing_delete_connect_timer(server
);
3619 /* check if routing is active... */
3620 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3623 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3627 /* If its offline, mark it online again.. */
3628 if((rps
= dict_find(rp
->servers
, server
, NULL
))) {
3629 if(rps
->offline
== true) {
3630 rps
->offline
= false;
3631 if(rps
->secondaryuplink
) {
3632 /* re-activate to move it back to its primary */
3633 activate_routing(NULL
, NULL
, NULL
);
3636 /* if there are any servers missing who have this server as uplink try to connect them. */
3637 routing_connect_children(opserv_route
, server
);
3639 /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */
3640 for (it
=dict_first(servers
); it
; it
=iter_next(it
)) {
3641 struct server
*sptr
= iter_data(it
);
3642 if(sptr
&& sptr
->uplink
&& !strcasecmp(server
, sptr
->uplink
->name
)) {
3643 log_module(MAIN_LOG
, LOG_DEBUG
, "routing_handle_connect calling self on %s's leaf %s", server
, sptr
->name
);
3644 routing_handle_connect(sptr
->name
, sptr
->uplink
->name
);
3649 /* Handle a failed attempt at connecting servers
3650 * - we should only get here regarding servers X3 attempted to link, other
3651 * opers link messages go to them not to us
3654 routing_handle_connect_failure(struct server
*source
, char *server
, char *message
)
3657 struct routingPlan
*rp
;
3658 struct routingPlanServer
*rps
;
3659 log_module(MAIN_LOG
, LOG_ERROR
, "Failed to connect %s to %s: %s", server
, source
->name
, message
);
3660 /* remove the waiting connection n timeq */
3661 routing_delete_connect_timer(server
);
3662 /* check if routing is active.. */
3663 active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3666 rp
= dict_find(opserv_routing_plans
, active
, NULL
);
3670 if( ((rps
= dict_find(rp
->servers
, server
, NULL
)) && !strcasecmp(rps
->uplink
, source
->name
))) {
3671 /* failed to connect to its primary uplink */
3672 if(rps
->offline
== false) {
3673 rps
->offline
= true;
3674 if(rps
->secondaryuplink
) {
3675 /* re-activate routing so the secondary
3676 * becomes its uplink, and try again */
3677 activate_routing(NULL
, NULL
, NULL
);
3678 /* attempt to link it again. */
3679 routing_connect_one(opserv_route
, server
);
3680 /* TODO: reconnect any missing servers who
3681 * normally connect to server, using their backups.
3682 * Probably should just issue a reroute C here. */
3688 /* Delete any existing timers, and start the timer again
3689 * using the passed time for the first run.
3690 * - this is called during a retry_period change
3691 * before it has saved the new value.
3693 * If time is 0, lookup the interval. */
3694 void reroute_timer_reset(unsigned int time
)
3696 timeq_del(0, reroute_timer
, NULL
, TIMEQ_IGNORE_DATA
| TIMEQ_IGNORE_WHEN
);
3698 if(!opserv_route
|| !opserv_route
->servers
)
3699 return; /* no active route */
3700 char *retry_period
= dict_find(opserv_routing_plan_options
, "RETRY_PERIOD", NULL
);
3702 return; /* retry_period invalid */
3703 time
= atoi(retry_period
);
3705 return; /* retry_period set to 0, disable */
3708 timeq_add(now
+ time
, reroute_timer
, "run");
3711 static MODCMD_FUNC(cmd_routing_set
)
3713 char *option
= argv
[1];
3714 char *options
[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL
};
3717 route_show_options(cmd
, user
);
3720 char *found_option
= NULL
;
3721 for(i
= 0; options
[i
]; i
++) {
3722 if(!strcasecmp(options
[i
], option
))
3723 found_option
= options
[i
];
3726 reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option
);
3730 char *value
= argv
[2];
3731 char buff
[MAXLEN
]; /* whats the max length of unsigned int as printf'd? */
3732 if(!strcmp(found_option
, "ACTIVE")) { /* must be an existing route. */
3733 if(disabled_string(value
) || false_string(value
)) {
3734 /* make none of the maps active */
3735 activate_routing(cmd
, user
, "*");
3736 reply("OSMSG_ROUTING_DISABLED");
3739 else if(!activate_routing(cmd
, user
, value
)) {
3740 /* neg reply handled in activate_routing */
3744 if(!strcmp(found_option
, "CONN_READERROR") || !strcmp(found_option
, "CONN_PINGOUT") ||
3745 !strcmp(found_option
, "KARMA") ) {
3746 if( enabled_string(value
)) {
3749 else if( disabled_string(value
) ) {
3753 reply("MSG_INVALID_BINARY", value
);
3757 if(!strcmp(found_option
, "RETRY_PERIOD")) {
3758 unsigned int duration
= ParseInterval(value
);
3759 sprintf(buff
, "%d", duration
);
3761 reroute_timer_reset(duration
);
3763 /* set the value here */
3764 dict_remove(opserv_routing_plan_options
, found_option
);
3765 dict_insert(opserv_routing_plan_options
, strdup(found_option
), strdup(value
));
3766 route_show_option(cmd
, user
, found_option
);
3769 /* show the current value */
3770 route_show_option(cmd
, user
, found_option
);
3776 static MODCMD_FUNC(cmd_stats_routing_plans
) {
3777 dict_iterator_t rpit
;
3779 struct routingPlan
*rp
;
3781 reply("OSMSG_ROUTINGPLAN");
3782 reply("OSMSG_ROUTINGPLAN_BAR");
3783 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3784 const char* name
= iter_key(rpit
);
3785 rp
= iter_data(rpit
);
3786 if(match_ircglob(name
, argv
[1])) {
3787 reply("OSMSG_ROUTINGPLAN_NAME", name
);
3788 for(it
= dict_first(rp
->servers
); it
; it
= iter_next(it
)) {
3789 const char* servername
= iter_key(it
);
3790 struct routingPlanServer
*rps
= iter_data(it
);
3791 reply("OSMSG_ROUTINGPLAN_SERVER", servername
, rps
->port
, rps
->uplink
, rps
->karma
, rps
->offline
? "offline" : "online", rps
->secondaryuplink
? rps
->secondaryuplink
: "None");
3796 reply("OSMSG_ROUTINGPLAN_END");
3799 reply("OSMSG_ROUTINGPLAN_LIST_HEAD");
3800 reply("OSMSG_ROUTINGPLAN_BAR");
3801 for(rpit
= dict_first(opserv_routing_plans
); rpit
; rpit
= iter_next(rpit
)) {
3802 const char* name
= iter_key(rpit
);
3803 reply("OSMSG_ROUTINGPLAN_LIST", name
);
3805 reply("OSMSG_ROUTINGPLAN_END");
3806 route_show_options(cmd
, user
);
3812 static MODCMD_FUNC(cmd_routing_addplan
)
3816 /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */
3817 if(*name
&& !disabled_string(name
) && !false_string(name
)) {
3818 if(opserv_add_routing_plan(name
)) {
3819 reply("OSMSG_ADDPLAN_SUCCESS", name
);
3823 reply("OSMSG_ADDPLAN_FAILED", name
);
3829 reply("OSMSG_INVALID_PLAN");
3834 static MODCMD_FUNC(cmd_routing_delplan
)
3836 char *name
= argv
[1];
3837 if( dict_remove(opserv_routing_plans
, name
) ) {
3838 char *active
= dict_find(opserv_routing_plan_options
, "ACTIVE", NULL
);
3839 if(active
&& !strcasecmp(active
, name
)) {
3840 /* if this was the active plan, disable routing */
3841 activate_routing(cmd
, user
, "*");
3842 reply("OSMSG_ROUTING_DISABLED");
3844 reply("OSMSG_PLAN_DELETED");
3848 reply("OSMSG_PLAN_NOT_FOUND", name
);
3853 static MODCMD_FUNC(cmd_routing_addserver
)
3861 struct routingPlan
*rp
;
3864 server
= strdup(argv
[2]);
3865 server
= strtok(server
, ":");
3866 portstr
= strtok(NULL
, ":");
3868 port
= atoi(portstr
);
3870 char *str
= dict_find(opserv_routing_plan_options
, "DEFAULT_PORT", NULL
);
3872 port
= str
? atoi(str
) : 0;
3880 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3882 opserv_routing_plan_add_server(rp
, server
, uplink
, port
, KARMA_DEFAULT
, second
, 0);
3883 reply("OSMSG_PLAN_SERVER_ADDED", server
);
3884 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3885 /* re-activate routing with new info */
3886 activate_routing(cmd
, user
, NULL
);
3893 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3899 static MODCMD_FUNC(cmd_routing_delserver
)
3903 struct routingPlan
*rp
;
3906 if( (rp
= dict_find(opserv_routing_plans
, plan
, 0))) {
3907 if(dict_remove(rp
->servers
, server
)) {
3909 reply("OSMSG_PLAN_SERVER_DELETED");
3910 if((active
= dict_find(opserv_routing_plan_options
, "ACTIVE", 0)) && !strcasecmp(plan
, active
)) {
3911 /* re-activate routing with new info */
3912 activate_routing(cmd
, user
, NULL
);
3918 reply("OSMSG_PLAN_SERVER_NOT_FOUND", server
);
3923 reply("OSMSG_PLAN_NOT_FOUND", plan
);
3929 /*************************************************
3930 * Functions to deal with 'route map' command */
3932 /* Figures out how many downlinks there are for proper
3933 * drawing of the route map */
3935 num_route_downlinks(struct route
*route
, char *name
)
3937 struct routeList
*rptr
;
3939 rptr
= route
->servers
;
3941 if(!strcasecmp(rptr
->uplink
, name
))
3949 show_route_downlinks(struct svccmd
*cmd
, struct route
*route
, struct userNode
*user
, char *name
, char *prevpre
, char *arrowchar
, int reset
)
3951 struct routeList
*servPtr
;
3952 struct server
*sptr
;
3958 static int depth
= 0;
3963 nextpre
= malloc(MAXLEN
);
3964 strcpy(pre
, prevpre
);
3966 sptr
= GetServerH(name
);
3967 if((servPtr
= find_routeList_server(route
, name
))) {
3970 else if (!strcasecmp(sptr
->uplink
->name
, servPtr
->uplink
))
3972 else if(servPtr
->secondaryuplink
&& !strcasecmp(sptr
->name
, servPtr
->secondaryuplink
))
3976 reply("OSMSG_DOWNLINKS_FORMAT_A", pre
, arrowchar
, name
, status
);
3979 reply("OSMSG_DOWNLINKS_FORMAT_B", self
->name
);
3980 j
= num_route_downlinks(route
, name
);
3981 servPtr
= route
->servers
;
3983 if(!strcasecmp(servPtr
->uplink
, name
)) {
3984 strcpy(nextpre
, pre
);
3986 if(arrowchar
[0] == '`')
3987 strcat(nextpre
, " ");
3989 strcat(nextpre
, "| ");
3992 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "|", 0);
3995 show_route_downlinks(cmd
, route
, user
, servPtr
->server
, nextpre
, "`", 0);
3998 servPtr
= servPtr
->next
;
4004 show_route_map(struct route
*route
, struct userNode
*user
, struct svccmd
*cmd
)
4006 if(!route
|| !route
->servers
) {
4007 reply("OSMSG_ROUTELIST_EMPTY");
4011 char *serviceName
= conf_get_data("server/hostname", RECDB_QSTRING
);
4012 reply("OSMSG_ROUTELIST_AS_PLANNED");
4013 show_route_downlinks(cmd
, route
, user
, serviceName
, "", "`", 1);
4014 reply("OSMSG_MAP_CENTERED", route
->centered
? "is" : "is not", route
->maxdepth
);
4018 static MODCMD_FUNC(cmd_routing_map
)
4020 show_route_map(opserv_route
, user
, cmd
);
4027 /* End of auto routing functions *
4028 *********************************/
4030 static MODCMD_FUNC(cmd_addbad
)
4032 unsigned int arg
, count
;
4034 int bad_found
, exempt_found
;
4036 /* Create the bad word if it doesn't exist. */
4037 bad_found
= !opserv_add_bad_word(cmd
, user
, argv
[1]);
4039 /* Look for exception modifiers. */
4040 for (arg
=2; arg
<argc
; arg
++) {
4041 if (!irccasecmp(argv
[arg
], "except")) {
4042 reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt");
4044 reply("MSG_MISSING_PARAMS", "except");
4047 for (count
= 0; (arg
< argc
) && IsChannelName(argv
[arg
]); arg
++) {
4048 dict_find(opserv_exempt_channels
, argv
[arg
], &exempt_found
);
4049 if (!exempt_found
) {
4050 dict_insert(opserv_exempt_channels
, strdup(argv
[arg
]), NULL
);
4054 reply("OSMSG_ADDED_EXEMPTIONS", count
);
4056 reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad");
4057 reply("OSMSG_BAD_MODIFIER", argv
[arg
]);
4061 /* Scan for existing channels that match the new bad word. */
4063 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4064 struct chanNode
*channel
= iter_data(it
);
4066 if (!opserv_bad_channel(channel
->name
))
4068 channel
->bad_channel
= 1;
4069 if (channel
->name
[0] == '#')
4070 opserv_shutdown_channel(channel
, "OSMSG_ILLEGAL_REASON");
4073 for (nn
=0; nn
<channel
->members
.used
; nn
++) {
4074 struct userNode
*user
= channel
->members
.list
[nn
]->user
;
4075 DelUser(user
, cmd
->parent
->bot
, 1, "OSMSG_ILLEGAL_KILL_REASON");
4084 static MODCMD_FUNC(cmd_delbad
)
4089 for (nn
=0; nn
<opserv_bad_words
->used
; nn
++) {
4090 if (!irccasecmp(opserv_bad_words
->list
[nn
], argv
[1])) {
4091 string_list_delete(opserv_bad_words
, nn
);
4092 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
4093 channel
= iter_data(it
);
4094 if (irccasestr(channel
->name
, argv
[1])
4095 && !opserv_bad_channel(channel
->name
)) {
4096 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel name no longer contains a bad word.", 1);
4097 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4098 channel
->bad_channel
= 0;
4101 reply("OSMSG_REMOVED_BAD", argv
[1]);
4105 reply("OSMSG_NOT_BAD_WORD", argv
[1]);
4109 static MODCMD_FUNC(cmd_addexempt
)
4111 const char *chanName
;
4113 if ((argc
> 1) && IsChannelName(argv
[1])) {
4116 reply("MSG_NOT_CHANNEL_NAME");
4120 dict_insert(opserv_exempt_channels
, strdup(chanName
), NULL
);
4121 channel
= GetChannel(chanName
);
4123 if (channel
->bad_channel
) {
4124 DelChannelUser(cmd
->parent
->bot
, channel
, "Channel is now exempt from bad-word checking.", 1);
4125 timeq_del(0, opserv_part_channel
, channel
, TIMEQ_IGNORE_WHEN
);
4127 channel
->bad_channel
= 0;
4129 reply("OSMSG_ADDED_EXEMPTION", chanName
);
4133 static MODCMD_FUNC(cmd_delexempt
)
4135 const char *chanName
;
4137 if ((argc
> 1) && IsChannelName(argv
[1])) {
4140 reply("MSG_NOT_CHANNEL_NAME");
4144 if (!dict_remove(opserv_exempt_channels
, chanName
)) {
4145 reply("OSMSG_NOT_EXEMPT", chanName
);
4148 reply("OSMSG_REMOVED_EXEMPTION", chanName
);
4153 opserv_expire_trusted_host(void *data
)
4155 struct trusted_host
*th
= data
;
4156 dict_remove(opserv_trusted_hosts
, th
->ipaddr
);
4160 opserv_add_trusted_host(const char *ipaddr
, unsigned int limit
, const char *issuer
, time_t issued
, time_t expires
, const char *reason
)
4162 struct trusted_host
*th
;
4163 th
= calloc(1, sizeof(*th
));
4166 th
->ipaddr
= strdup(ipaddr
);
4167 th
->reason
= reason
? strdup(reason
) : NULL
;
4168 th
->issuer
= issuer
? strdup(issuer
) : NULL
;
4169 th
->issued
= issued
;
4171 th
->expires
= expires
;
4172 dict_insert(opserv_trusted_hosts
, th
->ipaddr
, th
);
4174 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4178 free_trusted_host(void *data
)
4180 struct trusted_host
*th
= data
;
4187 static MODCMD_FUNC(cmd_addtrust
)
4189 unsigned long interval
;
4191 irc_in_addr_t tmpaddr
;
4194 if (dict_find(opserv_trusted_hosts
, argv
[1], NULL
)) {
4195 reply("OSMSG_ALREADY_TRUSTED", argv
[1]);
4199 if (!irc_pton(&tmpaddr
, NULL
, argv
[1])) {
4200 reply("OSMSG_BAD_IP", argv
[1]);
4204 count
= strtoul(argv
[2], &tmp
, 10);
4206 reply("OSMSG_BAD_NUMBER", argv
[2]);
4210 interval
= ParseInterval(argv
[3]);
4211 if (!interval
&& strcmp(argv
[3], "0")) {
4212 reply("MSG_INVALID_DURATION", argv
[3]);
4216 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4217 opserv_add_trusted_host(argv
[1], count
, user
->handle_info
->handle
, now
, interval
? (now
+ interval
) : 0, reason
);
4218 reply("OSMSG_ADDED_TRUSTED");
4222 static MODCMD_FUNC(cmd_edittrust
)
4224 unsigned long interval
;
4225 struct trusted_host
*th
;
4229 th
= dict_find(opserv_trusted_hosts
, argv
[1], NULL
);
4231 reply("OSMSG_NOT_TRUSTED", argv
[1]);
4234 count
= strtoul(argv
[2], &tmp
, 10);
4235 if (!count
|| *tmp
) {
4236 reply("OSMSG_BAD_NUMBER", argv
[2]);
4239 interval
= ParseInterval(argv
[3]);
4240 if (!interval
&& strcmp(argv
[3], "0")) {
4241 reply("MSG_INVALID_DURATION", argv
[3]);
4244 reason
= unsplit_string(argv
+4, argc
-4, NULL
);
4246 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4249 th
->reason
= strdup(reason
);
4251 th
->issuer
= strdup(user
->handle_info
->handle
);
4255 th
->expires
= now
+ interval
;
4256 timeq_add(th
->expires
, opserv_expire_trusted_host
, th
);
4259 reply("OSMSG_UPDATED_TRUSTED", th
->ipaddr
);
4263 static MODCMD_FUNC(cmd_deltrust
)
4267 for (n
=1; n
<argc
; n
++) {
4268 struct trusted_host
*th
= dict_find(opserv_trusted_hosts
, argv
[n
], NULL
);
4272 timeq_del(th
->expires
, opserv_expire_trusted_host
, th
, 0);
4273 dict_remove(opserv_trusted_hosts
, argv
[n
]);
4275 reply("OSMSG_REMOVED_TRUSTED");
4279 /* This doesn't use dict_t because it's a little simpler to open-code the
4280 * comparisons (and simpler arg-passing for the ADD subcommand).
4282 static MODCMD_FUNC(cmd_clone
)
4285 struct userNode
*clone
;
4287 clone
= GetUserH(argv
[2]);
4288 if (!irccasecmp(argv
[1], "ADD")) {
4290 char ident
[USERLEN
+1];
4293 reply("MSG_MISSING_PARAMS", argv
[1]);
4298 reply("OSMSG_CLONE_EXISTS", argv
[2]);
4301 userinfo
= unsplit_string(argv
+4, argc
-4, NULL
);
4302 for (i
=0; argv
[3][i
] && (i
<USERLEN
); i
++) {
4303 if (argv
[3][i
] == '@') {
4307 ident
[i
] = argv
[3][i
];
4310 if (!argv
[3][i
] || (i
==USERLEN
)) {
4311 reply("OSMSG_NOT_A_HOSTMASK");
4314 if (!(clone
= AddClone(argv
[2], ident
, argv
[3]+i
, userinfo
))) {
4315 reply("OSMSG_CLONE_FAILED", argv
[2]);
4318 reply("OSMSG_CLONE_ADDED", clone
->nick
);
4322 reply("MSG_NICK_UNKNOWN", argv
[2]);
4325 if (clone
->uplink
!= self
|| IsService(clone
)) {
4326 reply("OSMSG_NOT_A_CLONE", clone
->nick
);
4329 if (!irccasecmp(argv
[1], "REMOVE")) {
4332 reason
= unsplit_string(argv
+3, argc
-3, NULL
);
4335 tmp
= alloca(strlen(clone
->nick
) + strlen(OSMSG_PART_REASON
));
4336 sprintf(tmp
, OSMSG_PART_REASON
, clone
->nick
);
4339 DelUser(clone
, NULL
, 1, reason
);
4340 reply("OSMSG_CLONE_REMOVED", argv
[2]);
4344 reply("MSG_MISSING_PARAMS", argv
[1]);
4348 channel
= GetChannel(argv
[3]);
4349 if (!irccasecmp(argv
[1], "JOIN")) {
4351 && !(channel
= AddChannel(argv
[3], now
, NULL
, NULL
, NULL
))) {
4352 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4355 AddChannelUser(clone
, channel
);
4356 reply("OSMSG_CLONE_JOINED", clone
->nick
, channel
->name
);
4359 if (!irccasecmp(argv
[1], "PART")) {
4361 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4364 if (!GetUserMode(channel
, clone
)) {
4365 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4368 reply("OSMSG_CLONE_PARTED", clone
->nick
, channel
->name
);
4369 DelChannelUser(clone
, channel
, "Leaving.", 0);
4372 if (!irccasecmp(argv
[1], "OP")) {
4373 struct mod_chanmode change
;
4375 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4378 mod_chanmode_init(&change
);
4380 change
.args
[0].mode
= MODE_CHANOP
;
4381 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4382 if (!change
.args
[0].u
.member
) {
4383 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4386 modcmd_chanmode_announce(&change
);
4387 reply("OSMSG_OPS_GIVEN", channel
->name
, clone
->nick
);
4390 if (!irccasecmp(argv
[1], "HOP")) {
4391 struct mod_chanmode change
;
4393 reply("MSG_CHANNEL_UNKNOWN", argv
[3]);
4396 mod_chanmode_init(&change
);
4398 change
.args
[0].mode
= MODE_HALFOP
;
4399 change
.args
[0].u
.member
= GetUserMode(channel
, clone
);
4400 if (!change
.args
[0].u
.member
) {
4401 reply("OSMSG_NOT_ON_CHANNEL", clone
->nick
, channel
->name
);
4404 modcmd_chanmode_announce(&change
);
4405 reply("OSMSG_HOPS_GIVEN", channel
->name
, clone
->nick
);
4409 reply("MSG_MISSING_PARAMS", argv
[1]);
4413 if (!irccasecmp(argv
[1], "SAY")) {
4414 char *text
= unsplit_string(argv
+4, argc
-4, NULL
);
4415 irc_privmsg(clone
, argv
[3], text
);
4416 reply("OSMSG_CLONE_SAID", clone
->nick
, argv
[3]);
4419 reply("OSMSG_UNKNOWN_SUBCOMMAND", argv
[1], argv
[0]);
4423 static struct helpfile_expansion
4424 opserv_help_expand(const char *variable
)
4426 extern struct userNode
*message_source
;
4427 struct helpfile_expansion exp
;
4428 struct service
*service
;
4434 if (!(service
= service_find(message_source
->nick
))) {
4435 exp
.type
= HF_STRING
;
4436 exp
.value
.str
= NULL
;
4437 } else if (!irccasecmp(variable
, "index")) {
4438 exp
.type
= HF_TABLE
;
4439 exp
.value
.table
.length
= 1;
4440 exp
.value
.table
.width
= 2;
4441 exp
.value
.table
.flags
= TABLE_REPEAT_HEADERS
| TABLE_REPEAT_ROWS
;
4442 exp
.value
.table
.contents
= calloc(dict_size(service
->commands
)+1, sizeof(char**));
4443 exp
.value
.table
.contents
[0] = calloc(exp
.value
.table
.width
, sizeof(char*));
4444 exp
.value
.table
.contents
[0][0] = "Command";
4445 exp
.value
.table
.contents
[0][1] = "Level";
4446 for (it
=dict_first(service
->commands
); it
; it
=iter_next(it
)) {
4447 cmd
= iter_data(it
);
4448 row
= exp
.value
.table
.length
++;
4449 exp
.value
.table
.contents
[row
] = calloc(exp
.value
.table
.width
, sizeof(char*));
4450 exp
.value
.table
.contents
[row
][0] = iter_key(it
);
4451 level
= cmd
->min_opserv_level
;
4452 if (!level_strings
[level
]) {
4453 level_strings
[level
] = malloc(16);
4454 snprintf(level_strings
[level
], 16, "%3d", level
);
4456 exp
.value
.table
.contents
[row
][1] = level_strings
[level
];
4458 } else if (!strncasecmp(variable
, "level", 5)) {
4459 cmd
= dict_find(service
->commands
, variable
+6, NULL
);
4460 exp
.type
= HF_STRING
;
4462 level
= cmd
->min_opserv_level
;
4463 exp
.value
.str
= malloc(16);
4464 snprintf(exp
.value
.str
, 16, "%3d", level
);
4466 exp
.value
.str
= NULL
;
4469 exp
.type
= HF_STRING
;
4470 exp
.value
.str
= NULL
;
4476 opserv_define_func(const char *name
, modcmd_func_t
*func
, int min_level
, int reqchan
, int min_argc
)
4478 char buf
[16], *flags
= NULL
;
4479 unsigned int iflags
= 0;
4480 sprintf(buf
, "%d", min_level
);
4482 case 1: flags
= "+acceptchan"; break;
4483 case 3: flags
= "+acceptpluschan"; /* fall through */
4484 case 2: iflags
= MODCMD_REQUIRE_CHANNEL
; break;
4487 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", flags
, "flags", "+oper", NULL
);
4489 return modcmd_register(opserv_module
, name
, func
, min_argc
, iflags
, "level", buf
, "flags", "+oper", NULL
);
4493 int add_reserved(const char *key
, void *data
, void *extra
)
4495 struct chanNode
*chan
;
4496 struct record_data
*rd
= data
;
4497 const char *ident
, *hostname
, *desc
;
4499 struct userNode
*reserve
;
4500 ident
= database_get_data(rd
->d
.object
, KEY_IDENT
, RECDB_QSTRING
);
4502 log_module(OS_LOG
, LOG_ERROR
, "Missing ident for reserve of %s", key
);
4505 hostname
= database_get_data(rd
->d
.object
, KEY_HOSTNAME
, RECDB_QSTRING
);
4507 log_module(OS_LOG
, LOG_ERROR
, "Missing hostname for reserve of %s", key
);
4510 desc
= database_get_data(rd
->d
.object
, KEY_DESC
, RECDB_QSTRING
);
4512 log_module(OS_LOG
, LOG_ERROR
, "Missing description for reserve of %s", key
);
4515 if ((reserve
= AddClone(key
, ident
, hostname
, desc
))) {
4516 reserve
->modes
|= FLAGS_PERSISTENT
;
4517 dict_insert(extra
, reserve
->nick
, reserve
);
4520 if (autojoin_channels
&& reserve
) {
4521 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
4522 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
4523 AddChannelUser(reserve
, chan
)->modes
|= MODE_VOICE
;
4531 foreach_matching_user(const char *hostmask
, discrim_search_func func
, void *extra
)
4535 unsigned int matched
;
4537 if (!self
->uplink
) return 0;
4538 discrim
= calloc(1, sizeof(*discrim
));
4539 discrim
->limit
= dict_size(clients
);
4540 discrim
->max_level
= ~0;
4541 discrim
->max_ts
= now
;
4542 discrim
->max_channels
= INT_MAX
;
4543 discrim
->authed
= -1;
4544 discrim
->info_space
= -1;
4545 discrim
->intra_scmp
= 0;
4546 discrim
->intra_dcmp
= 0;
4547 discrim
->use_regex
= 0;
4548 discrim
->silent
= 0;
4549 dupmask
= strdup(hostmask
);
4550 if (split_ircmask(dupmask
, &discrim
->mask_nick
, &discrim
->mask_ident
, &discrim
->mask_host
)) {
4551 if (!irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, discrim
->mask_host
))
4552 discrim
->ip_mask_bits
= 0;
4553 matched
= opserv_discrim_search(discrim
, func
, extra
);
4555 log_module(OS_LOG
, LOG_ERROR
, "Couldn't split IRC mask for gag %s!", hostmask
);
4564 gag_free(struct gag_entry
*gag
)
4566 unsigned int ungagged
;
4568 /* Remove from gag list */
4569 if (gagList
== gag
) {
4570 gagList
= gag
->next
;
4572 struct gag_entry
*prev
;
4573 for (prev
= gagList
; prev
->next
!= gag
; prev
= prev
->next
) ;
4574 prev
->next
= gag
->next
;
4577 ungagged
= foreach_matching_user(gag
->mask
, ungag_helper_func
, NULL
);
4579 /* Deallocate storage */
4589 gag_expire(void *data
)
4595 gag_create(const char *mask
, const char *owner
, const char *reason
, time_t expires
)
4597 struct gag_entry
*gag
;
4599 /* Create gag and put it into linked list */
4600 gag
= calloc(1, sizeof(*gag
));
4601 gag
->mask
= strdup(mask
);
4602 gag
->owner
= strdup(owner
? owner
: "<unknown>");
4603 gag
->reason
= strdup(reason
? reason
: "<unknown>");
4604 gag
->expires
= expires
;
4606 timeq_add(gag
->expires
, gag_expire
, gag
);
4607 gag
->next
= gagList
;
4610 /* If we're linked, see if who the gag applies to */
4611 return foreach_matching_user(mask
, gag_helper_func
, gag
);
4615 add_gag_helper(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4617 struct record_data
*rd
= data
;
4618 char *owner
, *reason
, *expstr
;
4621 owner
= database_get_data(rd
->d
.object
, KEY_OWNER
, RECDB_QSTRING
);
4622 reason
= database_get_data(rd
->d
.object
, KEY_REASON
, RECDB_QSTRING
);
4623 expstr
= database_get_data(rd
->d
.object
, KEY_EXPIRES
, RECDB_QSTRING
);
4624 expires
= expstr
? strtoul(expstr
, NULL
, 0) : 0;
4625 gag_create(key
, owner
, reason
, expires
);
4630 static struct opserv_user_alert
*
4631 opserv_add_user_alert(struct userNode
*req
, const char *name
, opserv_alert_reaction reaction
, const char *text_discrim
)
4634 char *wordv
[MAXNUMPARAMS
], *discrim_copy
;
4635 struct opserv_user_alert
*alert
;
4638 if (dict_find(opserv_user_alerts
, name
, NULL
)) {
4639 send_message(req
, opserv
, "OSMSG_ALERT_EXISTS", name
);
4642 alert
= malloc(sizeof(*alert
));
4643 alert
->owner
= strdup(req
->handle_info
? req
->handle_info
->handle
: req
->nick
);
4644 alert
->text_discrim
= strdup(text_discrim
);
4645 discrim_copy
= strdup(text_discrim
); /* save a copy of the discrim */
4646 wordc
= split_line(discrim_copy
, false, ArrayLength(wordv
), wordv
);
4647 alert
->discrim
= opserv_discrim_create(req
, opserv
, wordc
, wordv
, 0);
4648 /* Check for missing required criteria or broken records */
4649 if (!alert
->discrim
|| (reaction
==REACT_SVSJOIN
&& !alert
->discrim
->chantarget
) ||
4650 (reaction
==REACT_SVSPART
&& !alert
->discrim
->chantarget
) ||
4651 (reaction
==REACT_MARK
&& !alert
->discrim
->mark
)) {
4652 free(alert
->text_discrim
);
4657 alert
->split_discrim
= discrim_copy
;
4658 name_dup
= strdup(name
);
4659 if (!alert
->discrim
->reason
)
4660 alert
->discrim
->reason
= strdup(name
);
4661 alert
->reaction
= reaction
;
4662 dict_insert(opserv_user_alerts
, name_dup
, alert
);
4663 /* Stick the alert into the appropriate additional alert dict(s).
4664 * For channel alerts, we only use channels and min_channels;
4665 * max_channels would have to be checked on /part, which we do not
4666 * yet do, and which seems of questionable value.
4668 if (alert
->discrim
->channel
|| alert
->discrim
->min_channels
)
4669 dict_insert(opserv_channel_alerts
, name_dup
, alert
);
4670 if (alert
->discrim
->mask_nick
)
4671 dict_insert(opserv_nick_based_alerts
, name_dup
, alert
);
4677 add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra))
4679 struct record_data *rd = data;
4680 char *reason = GET_RECORD_QSTRING(rd);
4682 * i hope this can't happen *
4684 reason = "No Reason";
4686 dict_insert(opserv_chan_warn, strdup(key), strdup(reason));
4693 add_user_alert(const char *key
, void *data
, UNUSED_ARG(void *extra
))
4696 const char *discrim
, *react
, *owner
;
4697 opserv_alert_reaction reaction
;
4698 struct opserv_user_alert
*alert
;
4700 if (!(alert_dict
= GET_RECORD_OBJECT((struct record_data
*)data
))) {
4701 log_module(OS_LOG
, LOG_ERROR
, "Bad type (not a record) for alert %s.", key
);
4704 discrim
= database_get_data(alert_dict
, KEY_DISCRIM
, RECDB_QSTRING
);
4705 react
= database_get_data(alert_dict
, KEY_REACTION
, RECDB_QSTRING
);
4706 if (!react
|| !irccasecmp(react
, "notice"))
4707 reaction
= REACT_NOTICE
;
4708 else if (!irccasecmp(react
, "kill"))
4709 reaction
= REACT_KILL
;
4711 else if (!irccasecmp(react, "silent"))
4712 reaction = REACT_SILENT;
4714 else if (!irccasecmp(react
, "gline"))
4715 reaction
= REACT_GLINE
;
4716 else if (!irccasecmp(react
, "track"))
4717 reaction
= REACT_TRACK
;
4718 else if (!irccasecmp(react
, "shun"))
4719 reaction
= REACT_SHUN
;
4720 else if (!irccasecmp(react
, "svsjoin"))
4721 reaction
= REACT_SVSJOIN
;
4722 else if (!irccasecmp(react
, "svspart"))
4723 reaction
= REACT_SVSPART
;
4724 else if (!irccasecmp(react
, "version"))
4725 reaction
= REACT_VERSION
;
4726 else if (!irccasecmp(react
, "mark"))
4727 reaction
= REACT_MARK
;
4729 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction %s for alert %s.", react
, key
);
4732 alert
= opserv_add_user_alert(opserv
, key
, reaction
, discrim
);
4734 log_module(OS_LOG
, LOG_ERROR
, "Unable to create alert %s from database.", key
);
4737 owner
= database_get_data(alert_dict
, KEY_OWNER
, RECDB_QSTRING
);
4739 alert
->owner
= strdup(owner
? owner
: "<unknown>");
4744 trusted_host_read(const char *host
, void *data
, UNUSED_ARG(void *extra
))
4746 struct record_data
*rd
= data
;
4747 const char *limit
, *str
, *reason
, *issuer
;
4748 time_t issued
, expires
;
4750 if (rd
->type
== RECDB_QSTRING
) {
4751 /* old style host by itself */
4752 limit
= GET_RECORD_QSTRING(rd
);
4757 } else if (rd
->type
== RECDB_OBJECT
) {
4758 dict_t obj
= GET_RECORD_OBJECT(rd
);
4759 /* new style structure */
4760 limit
= database_get_data(obj
, KEY_LIMIT
, RECDB_QSTRING
);
4761 str
= database_get_data(obj
, KEY_EXPIRES
, RECDB_QSTRING
);
4762 expires
= str
? ParseInterval(str
) : 0;
4763 reason
= database_get_data(obj
, KEY_REASON
, RECDB_QSTRING
);
4764 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
4765 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
4766 issued
= str
? ParseInterval(str
) : 0;
4770 if (expires
&& (expires
< now
))
4772 opserv_add_trusted_host(host
, (limit
? strtoul(limit
, NULL
, 0) : 0), issuer
, issued
, expires
, reason
);
4777 add_routing_plan_server(const char *name
, void *data
, void *rp
)
4779 struct record_data
*rd
= data
;
4780 const char *uplink
, *portstr
, *karma
, *second
, *offline
;
4782 dict_t obj
= GET_RECORD_OBJECT(rd
);
4783 if(rd
->type
== RECDB_OBJECT
) {
4784 uplink
= database_get_data(obj
, KEY_UPLINK
, RECDB_QSTRING
);
4785 second
= database_get_data(obj
, KEY_SECOND
, RECDB_QSTRING
);
4786 portstr
= database_get_data(obj
, KEY_PORT
, RECDB_QSTRING
);
4787 karma
= database_get_data(obj
, KEY_KARMA
, RECDB_QSTRING
);
4788 offline
= database_get_data(obj
, KEY_OFFLINE
, RECDB_QSTRING
);
4789 /* create routing plan server named key, with uplink uplink. */
4790 opserv_routing_plan_add_server(rp
, name
, uplink
, portstr
? atoi(portstr
) : 0,
4791 karma
? atoi(karma
) : KARMA_DEFAULT
, second
,
4792 offline
? atoi(offline
) : 0);
4799 routing_plan_set_option(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4801 struct record_data
*rd
= data
;
4802 if(rd
->type
== RECDB_QSTRING
)
4804 char *value
= GET_RECORD_QSTRING(rd
);
4805 dict_insert(opserv_routing_plan_options
, strdup(name
), strdup(value
));
4811 add_routing_plan(const char *name
, void *data
, UNUSED_ARG(void *extra
))
4813 struct record_data
*rd
= data
;
4814 struct routingPlan
*rp
;
4816 if(rd
->type
== RECDB_OBJECT
) {
4817 dict_t obj
= GET_RECORD_OBJECT(rd
);
4818 rp
= opserv_add_routing_plan(name
);
4819 dict_foreach(obj
, add_routing_plan_server
, rp
);
4825 opserv_saxdb_read(struct dict
*conf_db
)
4828 struct record_data
*rd
;
4832 if ((object
= database_get_data(conf_db
, KEY_RESERVES
, RECDB_OBJECT
)))
4833 dict_foreach(object
, add_reserved
, opserv_reserved_nick_dict
);
4834 if ((rd
= database_get_path(conf_db
, KEY_BAD_WORDS
))) {
4836 case RECDB_STRING_LIST
:
4837 /* Add words one by one just in case there are overlaps from an old DB. */
4838 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4839 opserv_add_bad_word(NULL
, NULL
, rd
->d
.slist
->list
[nn
]);
4842 for (it
=dict_first(rd
->d
.object
); it
; it
=iter_next(it
)) {
4843 opserv_add_bad_word(NULL
, NULL
, iter_key(it
));
4845 if (rd
->type
== RECDB_STRING_LIST
)
4846 for (nn
=0; nn
<rd
->d
.slist
->used
; nn
++)
4847 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4854 if ((rd
= database_get_path(conf_db
, KEY_EXEMPT_CHANNELS
))
4855 && (rd
->type
== RECDB_STRING_LIST
)) {
4856 for (nn
=0; nn
<rd
->d
.slist
->used
; ++nn
)
4857 dict_insert(opserv_exempt_channels
, strdup(rd
->d
.slist
->list
[nn
]), NULL
);
4859 if ((object
= database_get_data(conf_db
, KEY_MAX_CLIENTS
, RECDB_OBJECT
))) {
4861 if ((str
= database_get_data(object
, KEY_MAX
, RECDB_QSTRING
)))
4862 max_clients
= atoi(str
);
4863 if ((str
= database_get_data(object
, KEY_TIME
, RECDB_QSTRING
)))
4864 max_clients_time
= atoi(str
);
4866 if ((object
= database_get_data(conf_db
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
4867 dict_foreach(object
, trusted_host_read
, opserv_trusted_hosts
);
4868 if ((object
= database_get_data(conf_db
, KEY_GAGS
, RECDB_OBJECT
)))
4869 dict_foreach(object
, add_gag_helper
, NULL
);
4870 if ((object
= database_get_data(conf_db
, KEY_ALERTS
, RECDB_OBJECT
)))
4871 dict_foreach(object
, add_user_alert
, NULL
);
4873 if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT)))
4874 dict_foreach(object, add_chan_warn, NULL);
4877 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN
, RECDB_OBJECT
)))
4878 dict_foreach(object
, add_routing_plan
, NULL
);
4880 if ((object
= database_get_data(conf_db
, KEY_ROUTINGPLAN_OPTIONS
, RECDB_OBJECT
)))
4881 dict_foreach(object
, routing_plan_set_option
, NULL
);
4887 opserv_saxdb_write(struct saxdb_context
*ctx
)
4889 struct string_list
*slist
;
4892 /* reserved nicks */
4893 if (dict_size(opserv_reserved_nick_dict
)) {
4894 saxdb_start_record(ctx
, KEY_RESERVES
, 1);
4895 for (it
= dict_first(opserv_reserved_nick_dict
); it
; it
= iter_next(it
)) {
4896 struct userNode
*user
= iter_data(it
);
4897 if (!IsPersistent(user
)) continue;
4898 saxdb_start_record(ctx
, iter_key(it
), 0);
4899 saxdb_write_string(ctx
, KEY_IDENT
, user
->ident
);
4900 saxdb_write_string(ctx
, KEY_HOSTNAME
, user
->hostname
);
4901 saxdb_write_string(ctx
, KEY_DESC
, user
->info
);
4902 saxdb_end_record(ctx
);
4904 saxdb_end_record(ctx
);
4907 if (opserv_bad_words
->used
) {
4908 saxdb_write_string_list(ctx
, KEY_BAD_WORDS
, opserv_bad_words
);
4910 /* routing plan options */
4911 if (dict_size(opserv_routing_plan_options
)) {
4912 saxdb_start_record(ctx
, KEY_ROUTINGPLAN_OPTIONS
, 1);
4913 for(it
= dict_first(opserv_routing_plan_options
); it
; it
= iter_next(it
)) {
4914 saxdb_write_string(ctx
, iter_key(it
), iter_data(it
));
4916 saxdb_end_record(ctx
);
4919 if (dict_size(opserv_routing_plans
)) {
4920 dict_iterator_t svrit
;
4921 struct routingPlan
*rp
;
4922 struct routingPlanServer
*rps
;
4923 saxdb_start_record(ctx
, KEY_ROUTINGPLAN
, 1);
4924 for (it
= dict_first(opserv_routing_plans
); it
; it
= iter_next(it
)) {
4926 saxdb_start_record(ctx
, iter_key(it
), 0);
4927 for(svrit
= dict_first(rp
->servers
); svrit
; svrit
= iter_next(svrit
)) {
4929 rps
= iter_data(svrit
);
4930 saxdb_start_record(ctx
, iter_key(svrit
), 0);
4931 saxdb_write_string(ctx
, KEY_UPLINK
, rps
->uplink
);
4932 if(rps
->secondaryuplink
)
4933 saxdb_write_string(ctx
, KEY_SECOND
, rps
->secondaryuplink
);
4934 sprintf(buf
, "%d", rps
->port
);
4935 saxdb_write_string(ctx
, KEY_PORT
, buf
);
4936 sprintf(buf
, "%d", rps
->karma
);
4937 saxdb_write_string(ctx
, KEY_KARMA
, buf
);
4938 sprintf(buf
, "%d", rps
->offline
);
4939 saxdb_write_string(ctx
, KEY_OFFLINE
, buf
);
4940 saxdb_end_record(ctx
);
4942 saxdb_end_record(ctx
);
4944 saxdb_end_record(ctx
);
4946 /* insert exempt channel names */
4947 if (dict_size(opserv_exempt_channels
)) {
4948 slist
= alloc_string_list(dict_size(opserv_exempt_channels
));
4949 for (it
=dict_first(opserv_exempt_channels
); it
; it
=iter_next(it
)) {
4950 string_list_append(slist
, strdup(iter_key(it
)));
4952 saxdb_write_string_list(ctx
, KEY_EXEMPT_CHANNELS
, slist
);
4953 free_string_list(slist
);
4955 /* trusted hosts takes a little more work */
4956 if (dict_size(opserv_trusted_hosts
)) {
4957 saxdb_start_record(ctx
, KEY_TRUSTED_HOSTS
, 1);
4958 for (it
= dict_first(opserv_trusted_hosts
); it
; it
= iter_next(it
)) {
4959 struct trusted_host
*th
= iter_data(it
);
4960 saxdb_start_record(ctx
, iter_key(it
), 0);
4961 if (th
->limit
) saxdb_write_int(ctx
, KEY_LIMIT
, th
->limit
);
4962 if (th
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, th
->expires
);
4963 if (th
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, th
->issued
);
4964 if (th
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, th
->issuer
);
4965 if (th
->reason
) saxdb_write_string(ctx
, KEY_REASON
, th
->reason
);
4966 saxdb_end_record(ctx
);
4968 saxdb_end_record(ctx
);
4972 struct gag_entry
*gag
;
4973 saxdb_start_record(ctx
, KEY_GAGS
, 1);
4974 for (gag
= gagList
; gag
; gag
= gag
->next
) {
4975 saxdb_start_record(ctx
, gag
->mask
, 0);
4976 saxdb_write_string(ctx
, KEY_OWNER
, gag
->owner
);
4977 saxdb_write_string(ctx
, KEY_REASON
, gag
->reason
);
4978 if (gag
->expires
) saxdb_write_int(ctx
, KEY_EXPIRES
, gag
->expires
);
4979 saxdb_end_record(ctx
);
4981 saxdb_end_record(ctx
);
4983 /* channel warnings */
4985 if (dict_size(opserv_chan_warn)) {
4986 saxdb_start_record(ctx, KEY_WARN, 0);
4987 for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) {
4988 saxdb_write_string(ctx, iter_key(it), iter_data(it));
4990 saxdb_end_record(ctx);
4994 if (dict_size(opserv_user_alerts
)) {
4995 saxdb_start_record(ctx
, KEY_ALERTS
, 1);
4996 for (it
= dict_first(opserv_user_alerts
); it
; it
= iter_next(it
)) {
4997 struct opserv_user_alert
*alert
= iter_data(it
);
4998 const char *reaction
;
4999 saxdb_start_record(ctx
, iter_key(it
), 0);
5000 saxdb_write_string(ctx
, KEY_DISCRIM
, alert
->text_discrim
);
5001 saxdb_write_string(ctx
, KEY_OWNER
, alert
->owner
);
5002 switch (alert
->reaction
) {
5003 case REACT_NOTICE
: reaction
= "notice"; break;
5004 case REACT_KILL
: reaction
= "kill"; break;
5005 // case REACT_SILENT: reaction = "silent"; break;
5006 case REACT_GLINE
: reaction
= "gline"; break;
5007 case REACT_TRACK
: reaction
= "track"; break;
5008 case REACT_SHUN
: reaction
= "shun"; break;
5009 case REACT_SVSJOIN
: reaction
= "svsjoin"; break;
5010 case REACT_SVSPART
: reaction
= "svspart"; break;
5011 case REACT_VERSION
: reaction
= "version"; break;
5012 case REACT_MARK
: reaction
= "mark"; break;
5015 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s (while writing database).", alert
->reaction
, iter_key(it
));
5018 if (reaction
) saxdb_write_string(ctx
, KEY_REACTION
, reaction
);
5019 saxdb_end_record(ctx
);
5021 saxdb_end_record(ctx
);
5024 saxdb_start_record(ctx
, KEY_MAX_CLIENTS
, 0);
5025 saxdb_write_int(ctx
, KEY_MAX
, max_clients
);
5026 saxdb_write_int(ctx
, KEY_TIME
, max_clients_time
);
5027 saxdb_end_record(ctx
);
5032 query_keys_helper(const char *key
, UNUSED_ARG(void *data
), void *extra
)
5034 send_message_type(4, extra
, opserv
, "$b%s$b", key
);
5038 static MODCMD_FUNC(cmd_query
)
5040 struct record_data
*rd
;
5045 reply("OSMSG_OPTION_ROOT");
5046 conf_enum_root(query_keys_helper
, user
);
5050 nodename
= unsplit_string(argv
+1, argc
-1, NULL
);
5051 if (!(rd
= conf_get_node(nodename
))) {
5052 reply("OSMSG_UNKNOWN_OPTION", nodename
);
5056 if (rd
->type
== RECDB_QSTRING
)
5057 reply("OSMSG_OPTION_IS", nodename
, rd
->d
.qstring
);
5058 else if (rd
->type
== RECDB_STRING_LIST
) {
5059 reply("OSMSG_OPTION_LIST", nodename
);
5060 if (rd
->d
.slist
->used
)
5061 for (i
=0; i
<rd
->d
.slist
->used
; i
++)
5062 send_message_type(4, user
, cmd
->parent
->bot
, "$b%s$b", rd
->d
.slist
->list
[i
]);
5064 reply("OSMSG_OPTION_LIST_EMPTY");
5065 } else if (rd
->type
== RECDB_OBJECT
) {
5066 reply("OSMSG_OPTION_KEYS", nodename
);
5067 dict_foreach(rd
->d
.object
, query_keys_helper
, user
);
5073 static MODCMD_FUNC(cmd_set
)
5075 struct record_data
*rd
;
5077 /* I originally wanted to be able to fully manipulate the config
5078 db with this, but i wussed out. feel free to fix this - you'll
5079 need to handle quoted strings which have been split, and likely
5080 invent a syntax for it. -Zoot */
5082 if (!(rd
= conf_get_node(argv
[1]))) {
5083 reply("OSMSG_SET_NOT_SET", argv
[1]);
5087 if (rd
->type
!= RECDB_QSTRING
) {
5088 reply("OSMSG_SET_BAD_TYPE", argv
[1]);
5092 free(rd
->d
.qstring
);
5093 rd
->d
.qstring
= strdup(argv
[2]);
5094 conf_call_reload_funcs();
5095 reply("OSMSG_SET_SUCCESS", argv
[1], argv
[2]);
5099 static MODCMD_FUNC(cmd_settime
)
5101 const char *srv_name_mask
= "*";
5102 time_t new_time
= now
;
5105 srv_name_mask
= argv
[1];
5107 new_time
= time(NULL
);
5108 irc_settime(srv_name_mask
, new_time
);
5109 reply("OSMSG_SETTIME_SUCCESS", srv_name_mask
);
5114 opserv_discrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[], int allow_channel
)
5119 discrim
= calloc(1, sizeof(*discrim
));
5120 discrim
->limit
= 250;
5121 discrim
->max_level
= ~0;
5122 discrim
->max_ts
= INT_MAX
;
5123 discrim
->domain_depth
= 2;
5124 discrim
->max_channels
= INT_MAX
;
5125 discrim
->authed
= -1;
5126 discrim
->info_space
= -1;
5127 discrim
->intra_dcmp
= 0;
5128 discrim
->intra_scmp
= 0;
5129 discrim
->use_regex
= 0;
5130 discrim
->silent
= 0;
5132 for (i
=0; i
<argc
; i
++) {
5133 if (irccasecmp(argv
[i
], "log") == 0) {
5134 discrim
->option_log
= 1;
5137 /* Assume all other criteria require arguments. */
5138 if (i
== argc
- 1) {
5139 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
5142 if (argv
[i
+1][0] == '&') {
5143 /* Looking for intra-userNode matches */
5144 char *tmp
= &(argv
[i
+1][1]);
5145 if (strcasecmp(tmp
, argv
[i
]) != 0) { /* Don't allow "nick &nick" etc */
5146 if (!strcasecmp(tmp
, "nick"))
5147 discrim
->intra_dcmp
= 1;
5148 else if (!strcasecmp(tmp
, "ident"))
5149 discrim
->intra_dcmp
= 2;
5150 else if (!strcasecmp(tmp
, "info"))
5151 discrim
->intra_dcmp
= 3;
5154 if (irccasecmp(argv
[i
], "mask") == 0) {
5155 if (!is_ircmask(argv
[++i
])) {
5156 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5159 if (!split_ircmask(argv
[i
],
5160 &discrim
->mask_nick
,
5161 &discrim
->mask_ident
,
5162 &discrim
->mask_host
)) {
5163 send_message(user
, bot
, "OSMSG_INVALID_IRCMASK", argv
[i
]);
5166 } else if (irccasecmp(argv
[i
], "nick") == 0) {
5168 if (discrim
->intra_dcmp
> 0)
5169 discrim
->intra_scmp
= 1;
5171 discrim
->mask_nick
= argv
[i
];
5172 } else if (irccasecmp(argv
[i
], "ident") == 0) {
5174 if (discrim
->intra_dcmp
> 0)
5175 discrim
->intra_scmp
= 2;
5177 discrim
->mask_ident
= argv
[i
];
5178 } else if (irccasecmp(argv
[i
], "host") == 0) {
5179 discrim
->mask_host
= argv
[++i
];
5180 } else if (irccasecmp(argv
[i
], "info") == 0) {
5182 if (discrim
->intra_dcmp
> 0)
5183 discrim
->intra_scmp
= 3;
5185 discrim
->mask_info
= argv
[i
];
5186 } else if (irccasecmp(argv
[i
], "version") == 0) {
5187 discrim
->mask_version
= argv
[++i
];
5188 } else if (irccasecmp(argv
[i
], "server") == 0) {
5189 discrim
->server
= argv
[++i
];
5190 } else if (irccasecmp(argv
[i
], "ip") == 0) {
5191 j
= irc_pton(&discrim
->ip_mask
, &discrim
->ip_mask_bits
, argv
[++i
]);
5193 send_message(user
, bot
, "OSMSG_BAD_IP", argv
[i
]);
5196 } else if (irccasecmp(argv
[i
], "account") == 0) {
5197 if (discrim
->authed
== 0) {
5198 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5201 discrim
->accountmask
= argv
[++i
];
5202 discrim
->authed
= 1;
5203 } else if (irccasecmp(argv
[i
], "marked") == 0) {
5204 discrim
->mask_mark
= argv
[++i
];
5205 } else if (irccasecmp(argv
[i
], "chantarget") == 0) {
5206 if(!IsChannelName(argv
[i
+1])) {
5207 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5210 discrim
->chantarget
= argv
[++i
];
5211 } else if (irccasecmp(argv
[i
], "checkrestrictions") == 0) {
5213 if (true_string(argv
[i
])) {
5214 discrim
->checkrestrictions
= 1;
5215 } else if (false_string(argv
[i
])) {
5216 discrim
->checkrestrictions
= 0;
5218 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5221 } else if (irccasecmp(argv
[i
], "mark") == 0) {
5222 if(!is_valid_mark(argv
[i
+1])) {
5223 send_message(user
, bot
, "OSMSG_MARK_INVALID");
5226 discrim
->mark
= argv
[++i
];
5227 } else if (irccasecmp(argv
[i
], "authed") == 0) {
5228 i
++; /* true_string and false_string are macros! */
5229 if (true_string(argv
[i
])) {
5230 discrim
->authed
= 1;
5231 } else if (false_string(argv
[i
])) {
5232 if (discrim
->accountmask
) {
5233 send_message(user
, bot
, "OSMSG_ACCOUNTMASK_AUTHED");
5236 discrim
->authed
= 0;
5238 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5241 } else if (irccasecmp(argv
[i
], "info_space") == 0) {
5242 /* XXX: A hack because you can't check explicitly for a space through
5243 * any other means */
5245 if (true_string(argv
[i
])) {
5246 discrim
->info_space
= 1;
5247 } else if (false_string(argv
[i
])) {
5248 discrim
->info_space
= 0;
5250 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5253 } else if (irccasecmp(argv
[i
], "regex") == 0) {
5255 if (true_string(argv
[i
])) {
5256 discrim
->use_regex
= 1;
5257 } else if (false_string(argv
[i
])) {
5258 discrim
->use_regex
= 0;
5260 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5263 } else if (irccasecmp(argv
[i
], "silent") == 0) {
5265 if(user
!= opserv
&& !oper_has_access(user
, opserv
, opserv_conf
.silent_level
, 0)) {
5267 } else if (true_string(argv
[i
])) {
5268 discrim
->silent
= 1;
5269 } else if (false_string(argv
[i
])) {
5270 discrim
->silent
= 0;
5272 send_message(user
, bot
, "MSG_INVALID_BINARY", argv
[i
]);
5275 } else if (irccasecmp(argv
[i
], "duration") == 0) {
5276 discrim
->duration
= ParseInterval(argv
[++i
]);
5277 } else if (irccasecmp(argv
[i
], "channel") == 0) {
5278 for (j
=0, i
++; ; j
++) {
5279 switch (argv
[i
][j
]) {
5283 discrim
->chan_no_modes
|= MODE_CHANOP
| MODE_HALFOP
| MODE_VOICE
;
5286 discrim
->chan_req_modes
|= MODE_VOICE
;
5287 discrim
->chan_no_modes
|= MODE_CHANOP
;
5288 discrim
->chan_no_modes
|= MODE_HALFOP
;
5291 discrim
->chan_req_modes
|= MODE_HALFOP
;
5292 discrim
->chan_no_modes
|= MODE_CHANOP
;
5293 discrim
->chan_no_modes
|= MODE_VOICE
;
5296 discrim
->chan_req_modes
|= MODE_CHANOP
;
5299 send_message(user
, bot
, "MSG_NOT_CHANNEL_NAME");
5304 discrim
->chan_no_modes
&= ~discrim
->chan_req_modes
;
5305 if (!(discrim
->channel
= GetChannel(argv
[i
]+j
))) {
5306 /* secretly "allow_channel" now means "if a channel name is
5307 * specified, require that it currently exist" */
5308 if (allow_channel
) {
5309 send_message(user
, bot
, "MSG_CHANNEL_UNKNOWN", argv
[i
]);
5312 discrim
->channel
= AddChannel(argv
[i
]+j
, now
, NULL
, NULL
, NULL
);
5315 LockChannel(discrim
->channel
);
5316 } else if (irccasecmp(argv
[i
], "numchannels") == 0) {
5317 discrim
->min_channels
= discrim
->max_channels
= strtoul(argv
[++i
], NULL
, 10);
5318 } else if (irccasecmp(argv
[i
], "limit") == 0) {
5319 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
5320 } else if (irccasecmp(argv
[i
], "reason") == 0) {
5321 discrim
->reason
= strdup(unsplit_string(argv
+i
+1, argc
-i
-1, NULL
));
5323 } else if (irccasecmp(argv
[i
], "last") == 0) {
5324 discrim
->min_ts
= now
- ParseInterval(argv
[++i
]);
5325 } else if ((irccasecmp(argv
[i
], "linked") == 0)
5326 || (irccasecmp(argv
[i
], "nickage") == 0)) {
5327 const char *cmp
= argv
[++i
];
5328 if (cmp
[0] == '<') {
5329 if (cmp
[1] == '=') {
5330 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5332 discrim
->min_ts
= now
- (ParseInterval(cmp
+1) - 1);
5334 } else if (cmp
[0] == '>') {
5335 if (cmp
[1] == '=') {
5336 discrim
->max_ts
= now
- ParseInterval(cmp
+2);
5338 discrim
->max_ts
= now
- (ParseInterval(cmp
+1) - 1);
5341 discrim
->min_ts
= now
- ParseInterval(cmp
+2);
5343 } else if (irccasecmp(argv
[i
], "access") == 0) {
5344 const char *cmp
= argv
[++i
];
5345 if (cmp
[0] == '<') {
5346 if (discrim
->min_level
== 0) discrim
->min_level
= 1;
5347 if (cmp
[1] == '=') {
5348 discrim
->max_level
= strtoul(cmp
+2, NULL
, 0);
5350 discrim
->max_level
= strtoul(cmp
+1, NULL
, 0) - 1;
5352 } else if (cmp
[0] == '=') {
5353 discrim
->min_level
= discrim
->max_level
= strtoul(cmp
+1, NULL
, 0);
5354 } else if (cmp
[0] == '>') {
5355 if (cmp
[1] == '=') {
5356 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5358 discrim
->min_level
= strtoul(cmp
+1, NULL
, 0) + 1;
5361 discrim
->min_level
= strtoul(cmp
+2, NULL
, 0);
5363 } else if ((irccasecmp(argv
[i
], "abuse") == 0)
5364 && (irccasecmp(argv
[++i
], "opers") == 0)) {
5365 discrim
->match_opers
= 1;
5366 } else if (irccasecmp(argv
[i
], "depth") == 0) {
5367 discrim
->domain_depth
= strtoul(argv
[++i
], NULL
, 0);
5368 } else if (irccasecmp(argv
[i
], "clones") == 0) {
5369 discrim
->min_clones
= strtoul(argv
[++i
], NULL
, 0);
5371 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
5376 if (discrim
->mask_nick
&& !strcmp(discrim
->mask_nick
, "*")) {
5377 discrim
->mask_nick
= 0;
5379 if (discrim
->mask_ident
&& !strcmp(discrim
->mask_ident
, "*")) {
5380 discrim
->mask_ident
= 0;
5382 if (discrim
->mask_info
&& !strcmp(discrim
->mask_info
, "*")) {
5383 discrim
->mask_info
= 0;
5385 if (discrim
->mask_version
&& !strcmp(discrim
->mask_version
, "*")) {
5386 discrim
->mask_version
= 0;
5388 if (discrim
->mask_host
&& !discrim
->mask_host
[strspn(discrim
->mask_host
, "*.")]) {
5389 discrim
->mask_host
= 0;
5392 if(discrim
->use_regex
)
5394 if(discrim
->mask_nick
)
5396 int err
= regcomp(&discrim
->regex_nick
, discrim
->mask_nick
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5397 discrim
->has_regex_nick
= !err
;
5401 buff
[regerror(err
, &discrim
->regex_nick
, buff
, sizeof(buff
))] = 0;
5403 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_nick
, buff
, err
);
5408 if(discrim
->mask_ident
)
5410 int err
= regcomp(&discrim
->regex_ident
, discrim
->mask_ident
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5411 discrim
->has_regex_ident
= !err
;
5415 buff
[regerror(err
, &discrim
->regex_ident
, buff
, sizeof(buff
))] = 0;
5417 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_ident
, buff
, err
);
5422 if(discrim
->mask_host
)
5424 int err
= regcomp(&discrim
->regex_host
, discrim
->mask_host
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5425 discrim
->has_regex_host
= !err
;
5429 buff
[regerror(err
, &discrim
->regex_host
, buff
, sizeof(buff
))] = 0;
5431 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_host
, buff
, err
);
5436 if(discrim
->mask_info
)
5438 int err
= regcomp(&discrim
->regex_info
, discrim
->mask_info
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5439 discrim
->has_regex_info
= !err
;
5443 buff
[regerror(err
, &discrim
->regex_info
, buff
, sizeof(buff
))] = 0;
5445 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_info
, buff
, err
);
5450 if(discrim
->mask_version
)
5452 int err
= regcomp(&discrim
->regex_version
, discrim
->mask_version
, REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
5453 discrim
->has_regex_version
= !err
;
5457 buff
[regerror(err
, &discrim
->regex_version
, buff
, sizeof(buff
))] = 0;
5459 send_message(user
, bot
, "OSMSG_INVALID_REGEX", discrim
->mask_version
, buff
, err
);
5472 if(discrim
->has_regex_nick
)
5473 regfree(&discrim
->regex_nick
);
5474 if(discrim
->has_regex_ident
)
5475 regfree(&discrim
->regex_ident
);
5476 if(discrim
->has_regex_host
)
5477 regfree(&discrim
->regex_host
);
5478 if(discrim
->has_regex_info
)
5479 regfree(&discrim
->regex_info
);
5486 discrim_match(discrim_t discrim
, struct userNode
*user
)
5488 unsigned int access
;
5489 char *scmp
=NULL
, *dcmp
=NULL
;
5491 if ((user
->timestamp
< discrim
->min_ts
)
5492 || (user
->timestamp
> discrim
->max_ts
)
5493 || (user
->channels
.used
< discrim
->min_channels
)
5494 || (user
->channels
.used
> discrim
->max_channels
)
5495 || (discrim
->authed
== 0 && user
->handle_info
)
5496 || (discrim
->authed
== 1 && !user
->handle_info
)
5497 || (discrim
->info_space
== 0 && user
->info
[0] == ' ')
5498 || (discrim
->info_space
== 1 && user
->info
[0] != ' ')
5499 || (discrim
->server
&& !match_ircglob(user
->uplink
->name
, discrim
->server
))
5500 || (discrim
->mask_mark
&& (!user
->mark
|| !match_ircglob(user
->mark
, discrim
->mask_mark
)))
5501 || (discrim
->accountmask
&& (!user
->handle_info
|| !match_ircglob(user
->handle_info
->handle
, discrim
->accountmask
)))
5502 || (discrim
->ip_mask_bits
&& !irc_check_mask(&user
->ip
, &discrim
->ip_mask
, discrim
->ip_mask_bits
))
5506 if (discrim
->channel
&& !GetUserMode(discrim
->channel
, user
))
5509 if(discrim
->use_regex
)
5511 if((discrim
->has_regex_nick
&& regexec(&discrim
->regex_nick
, user
->nick
, 0, 0, 0))
5512 || (discrim
->has_regex_ident
&& regexec(&discrim
->regex_ident
, user
->ident
, 0, 0, 0))
5513 || (discrim
->has_regex_host
&& regexec(&discrim
->regex_host
, user
->hostname
, 0, 0, 0))
5514 || (discrim
->has_regex_info
&& regexec(&discrim
->regex_info
, user
->info
, 0, 0, 0))
5515 || (discrim
->has_regex_version
&& (!user
->version_reply
|| regexec(&discrim
->regex_version
, user
->version_reply
, 0, 0, 0)))) {
5521 if ((discrim
->mask_nick
&& !match_ircglob(user
->nick
, discrim
->mask_nick
))
5522 || (discrim
->mask_ident
&& !match_ircglob(user
->ident
, discrim
->mask_ident
))
5523 || (discrim
->mask_host
&& !match_ircglob(user
->hostname
, discrim
->mask_host
))
5524 || (discrim
->mask_info
&& !match_ircglob(user
->info
, discrim
->mask_info
))
5525 || (discrim
->mask_version
&& (!user
->version_reply
|| !match_ircglob(user
->version_reply
, discrim
->mask_version
))) ) {
5530 if ((discrim
->intra_scmp
> 0 && discrim
->intra_dcmp
> 0)) {
5531 switch(discrim
->intra_scmp
) {
5532 case 1: scmp
=user
->nick
; break;
5533 case 2: scmp
=user
->ident
; break;
5536 if (discrim
->info_space
== 1) scmp
++;
5539 switch(discrim
->intra_dcmp
) {
5540 case 1: dcmp
=user
->nick
; break;
5541 case 2: dcmp
=user
->ident
; break;
5542 case 3: /* When checking INFO, and info_space is enabled
5543 * ignore the first character in a search
5544 * XXX: Should we ignore ALL leading whitespace?
5545 * Also, what about ignoring ~ in ident?
5548 if (discrim
->info_space
== 1) dcmp
++;
5551 if (irccasecmp(scmp
,dcmp
))
5555 access
= user
->handle_info
? user
->handle_info
->opserv_level
: 0;
5556 if ((access
< discrim
->min_level
)
5557 || (access
> discrim
->max_level
)) {
5560 if (discrim
->min_clones
> 1) {
5561 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&user
->ip
), NULL
);
5562 if (!ohi
|| (ohi
->clients
.used
< discrim
->min_clones
))
5569 opserv_discrim_search(discrim_t discrim
, discrim_search_func dsf
, void *data
)
5571 unsigned int nn
, count
;
5572 struct userList matched
;
5574 userList_init(&matched
);
5575 /* Try most optimized search methods first */
5576 if (discrim
->channel
) {
5578 (nn
< discrim
->channel
->members
.used
)
5579 && (matched
.used
< discrim
->limit
);
5581 struct modeNode
*mn
= discrim
->channel
->members
.list
[nn
];
5582 if (((mn
->modes
& discrim
->chan_req_modes
) != discrim
->chan_req_modes
)
5583 || ((mn
->modes
& discrim
->chan_no_modes
) != 0)) {
5586 if (discrim_match(discrim
, mn
->user
)) {
5587 userList_append(&matched
, mn
->user
);
5590 } else if (discrim
->ip_mask_bits
== 128) {
5591 struct opserv_hostinfo
*ohi
= dict_find(opserv_hostinfo_dict
, irc_ntoa(&discrim
->ip_mask
), NULL
);
5593 userList_clean(&matched
);
5596 for (nn
=0; (nn
<ohi
->clients
.used
) && (matched
.used
< discrim
->limit
); nn
++) {
5597 if (discrim_match(discrim
, ohi
->clients
.list
[nn
])) {
5598 userList_append(&matched
, ohi
->clients
.list
[nn
]);
5603 for (it
=dict_first(clients
); it
&& (matched
.used
< discrim
->limit
); it
=iter_next(it
)) {
5604 if (discrim_match(discrim
, iter_data(it
))) {
5605 userList_append(&matched
, iter_data(it
));
5610 if (!matched
.used
) {
5611 userList_clean(&matched
);
5615 if (discrim
->option_log
) {
5616 log_module(OS_LOG
, LOG_INFO
, "Logging matches for search:");
5618 for (nn
=0; nn
<matched
.used
; nn
++) {
5619 struct userNode
*user
= matched
.list
[nn
];
5620 if (discrim
->option_log
) {
5621 log_module(OS_LOG
, LOG_INFO
, " %s!%s@%s", user
->nick
, user
->ident
, user
->hostname
);
5623 if (dsf(user
, data
)) {
5624 /* If a search function returns true, it ran into a
5625 problem. Stop going through the list. */
5629 if (discrim
->option_log
) {
5630 log_module(OS_LOG
, LOG_INFO
, "End of matching users.");
5632 count
= matched
.used
;
5633 userList_clean(&matched
);
5638 trace_print_func(struct userNode
*match
, void *extra
)
5640 struct discrim_and_source
*das
= extra
;
5641 if (match
->handle_info
) {
5642 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
);
5644 send_message_type(4, das
->source
, das
->destination
, "%-15s\002 \002%10s\002@\002%s", match
->nick
, match
->ident
, match
->hostname
);
5650 trace_count_func(UNUSED_ARG(struct userNode
*match
), UNUSED_ARG(void *extra
))
5656 is_oper_victim(struct userNode
*user
, struct userNode
*target
, int match_opers
)
5658 return !(IsService(target
)
5659 || (!match_opers
&& IsOper(target
))
5660 || (target
->handle_info
5661 && target
->handle_info
->opserv_level
> user
->handle_info
->opserv_level
));
5665 trace_gline_func(struct userNode
*match
, void *extra
)
5667 struct discrim_and_source
*das
= extra
;
5669 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5670 opserv_block(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
, das
->discrim
->silent
);
5677 trace_shun_func(struct userNode
*match
, void *extra
)
5679 struct discrim_and_source
*das
= extra
;
5681 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5682 opserv_shun(match
, das
->source
->handle_info
->handle
, das
->discrim
->reason
, das
->discrim
->duration
);
5689 trace_kill_func(struct userNode
*match
, void *extra
)
5691 struct discrim_and_source
*das
= extra
;
5693 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5695 if (das
->discrim
->reason
) {
5696 reason
= das
->discrim
->reason
;
5698 reason
= alloca(strlen(OSMSG_KILL_REQUESTED
)+strlen(das
->source
->nick
)+1);
5699 sprintf(reason
, OSMSG_KILL_REQUESTED
, das
->source
->nick
);
5701 DelUser(match
, opserv
, 1, reason
);
5708 trace_mark_func(struct userNode
*match
, void *extra
)
5710 struct discrim_and_source
*das
= extra
;
5711 char *mark
= das
->discrim
->mark
;
5715 irc_mark(match
, mark
);
5720 trace_svsjoin_func(struct userNode
*match
, void *extra
)
5722 struct discrim_and_source
*das
= extra
;
5724 char *channame
= das
->discrim
->chantarget
;
5725 int checkrestrictions
= das
->discrim
->checkrestrictions
;
5726 struct chanNode
*channel
;
5728 if(!channame
|| !IsChannelName(channame
)) {
5729 //reply("MSG_NOT_CHANNEL_NAME");
5733 if (!(channel
= GetChannel(channame
))) {
5734 channel
= AddChannel(channame
, now
, NULL
, NULL
, NULL
);
5737 if (checkrestrictions
) {
5738 if (trace_check_bans(match
, channel
) == 1) {
5739 return 1; /* found on lamer list */
5742 if (channel
->modes
& MODE_INVITEONLY
) {
5743 return 1; /* channel is invite only */
5746 if (channel
->limit
> 0) {
5747 if (channel
->members
.used
>= channel
->limit
) {
5748 return 1; /* channel is invite on */
5752 if (*channel
->key
) {
5753 return 1; /* channel is password protected */
5757 if (GetUserMode(channel
, match
)) {
5758 // reply("OSMSG_ALREADY_THERE", channel->name);
5761 irc_svsjoin(opserv
, match
, channel
);
5762 // reply("OSMSG_SVSJOIN_SENT");
5767 trace_svspart_func(struct userNode
*match
, void *extra
)
5769 struct discrim_and_source
*das
= extra
;
5770 char *channame
= das
->discrim
->chantarget
;
5771 struct chanNode
*channel
;
5773 if(!channame
|| !IsChannelName(channame
))
5776 if (!(channel
= GetChannel(channame
)))
5779 if (!GetUserMode(channel
, match
))
5782 irc_svspart(opserv
, match
, channel
);
5787 trace_version_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
5789 irc_version_user(opserv
, match
);
5794 is_gagged(char *mask
)
5796 struct gag_entry
*gag
;
5798 for (gag
= gagList
; gag
; gag
= gag
->next
) {
5799 if (match_ircglobs(gag
->mask
, mask
)) return 1;
5805 trace_gag_func(struct userNode
*match
, void *extra
)
5807 struct discrim_and_source
*das
= extra
;
5809 if (is_oper_victim(das
->source
, match
, das
->discrim
->match_opers
)) {
5810 char *reason
, *mask
;
5812 if (das
->discrim
->reason
) {
5813 reason
= das
->discrim
->reason
;
5815 reason
= alloca(strlen(OSMSG_GAG_REQUESTED
)+strlen(das
->source
->nick
)+1);
5816 sprintf(reason
, OSMSG_GAG_REQUESTED
, das
->source
->nick
);
5818 masksize
= 5+strlen(match
->hostname
);
5819 mask
= alloca(masksize
);
5820 snprintf(mask
, masksize
, "*!*@%s", match
->hostname
);
5821 if (!is_gagged(mask
)) {
5822 gag_create(mask
, das
->source
->handle_info
->handle
, reason
,
5823 das
->discrim
->duration
? (now
+ das
->discrim
->duration
) : 0);
5831 trace_domains_func(struct userNode
*match
, void *extra
)
5833 struct discrim_and_source
*das
= extra
;
5835 unsigned long *count
;
5838 char ipmask
[IRC_NTOP_MASK_MAX_SIZE
];
5840 if (irc_pton(&ip
, NULL
, match
->hostname
)) {
5841 if (irc_in_addr_is_ipv4(ip
)) {
5842 unsigned long matchip
= ntohl(ip
.in6_32
[3]);
5843 /* raw IP address.. use up to first three octets of IP */
5844 switch (das
->discrim
->domain_depth
) {
5846 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255, (matchip
>>8)&255);
5849 snprintf(ipmask
, sizeof(ipmask
), "%lu.%lu.*", (matchip
>>24)&255, (matchip
>>16)&255);
5852 snprintf(ipmask
, sizeof(ipmask
), "%lu.*", (matchip
>>24)&255);
5855 } else if (irc_in_addr_is_ipv6(ip
)) {
5856 switch (das
->discrim
->domain_depth
) {
5857 case 1: depth
= 16; goto ipv6_pfx
;
5858 case 2: depth
= 24; goto ipv6_pfx
;
5859 case 3: depth
= 32; goto ipv6_pfx
;
5860 default: depth
= das
->discrim
->domain_depth
;
5862 irc_ntop_mask(ipmask
, sizeof(ipmask
), &ip
, depth
);
5864 } else safestrncpy(ipmask
, match
->hostname
, sizeof(ipmask
));
5865 ipmask
[sizeof(ipmask
) - 1] = '\0';
5868 hostname
= match
->hostname
+ strlen(match
->hostname
);
5869 for (depth
=das
->discrim
->domain_depth
;
5870 depth
&& (hostname
> match
->hostname
);
5873 while ((hostname
> match
->hostname
) && (*hostname
!= '.')) hostname
--;
5875 if (*hostname
== '.') hostname
++; /* advance past last dot we saw */
5877 if (!(count
= dict_find(das
->dict
, hostname
, NULL
))) {
5878 count
= calloc(1, sizeof(*count
));
5879 dict_insert(das
->dict
, strdup(hostname
), count
);
5886 opserv_show_hostinfo(const char *key
, void *data
, void *extra
)
5888 unsigned long *count
= data
;
5889 struct discrim_and_source
*das
= extra
;
5891 send_message_type(4, das
->source
, das
->destination
, "%s %lu", key
, *count
);
5892 return !--das
->disp_limit
;
5895 static MODCMD_FUNC(cmd_trace
)
5897 struct discrim_and_source das
;
5898 discrim_search_func action
;
5899 unsigned int matches
;
5900 struct svccmd
*subcmd
;
5904 sprintf(buf
, "trace %s", argv
[1]);
5905 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
5906 reply("OSMSG_BAD_ACTION", argv
[1]);
5909 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
))
5911 if (!irccasecmp(argv
[1], "print"))
5912 action
= trace_print_func
;
5913 else if (!irccasecmp(argv
[1], "count"))
5914 action
= trace_count_func
;
5915 else if (!irccasecmp(argv
[1], "domains"))
5916 action
= trace_domains_func
;
5917 else if (!irccasecmp(argv
[1], "gline"))
5918 action
= trace_gline_func
;
5919 else if (!irccasecmp(argv
[1], "shun"))
5920 action
= trace_shun_func
;
5921 else if (!irccasecmp(argv
[1], "kill"))
5922 action
= trace_kill_func
;
5923 else if (!irccasecmp(argv
[1], "gag"))
5924 action
= trace_gag_func
;
5925 else if (!irccasecmp(argv
[1], "svsjoin"))
5926 action
= trace_svsjoin_func
;
5927 else if (!irccasecmp(argv
[1], "svspart"))
5928 action
= trace_svspart_func
;
5929 else if (!irccasecmp(argv
[1], "version"))
5930 action
= trace_version_func
;
5931 else if (!irccasecmp(argv
[1], "mark"))
5932 action
= trace_mark_func
;
5934 reply("OSMSG_BAD_ACTION", argv
[1]);
5938 if (user
->handle_info
->opserv_level
< subcmd
->min_opserv_level
) {
5939 reply("OSMSG_LEVEL_TOO_LOW");
5945 das
.destination
= cmd
->parent
->bot
;
5946 das
.discrim
= opserv_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2, 1);
5950 if (action
== trace_print_func
)
5952 reply("OSMSG_USER_SEARCH_RESULTS");
5953 reply("OSMSG_USER_SEARCH_BAR");
5954 reply("OSMSG_USER_SEARCH_HEADER");
5955 reply("OSMSG_USER_SEARCH_BAR");
5957 else if (action
== trace_count_func
)
5958 das
.discrim
->limit
= INT_MAX
;
5959 else if ((action
== trace_gline_func
) && !das
.discrim
->duration
)
5960 das
.discrim
->duration
= opserv_conf
.block_gline_duration
;
5961 else if ((action
== trace_shun_func
) && !das
.discrim
->duration
)
5962 das
.discrim
->duration
= opserv_conf
.block_shun_duration
;
5963 else if (action
== trace_domains_func
) {
5964 das
.dict
= dict_new();
5965 dict_set_free_data(das
.dict
, free
);
5966 dict_set_free_keys(das
.dict
, free
);
5967 das
.disp_limit
= das
.discrim
->limit
;
5968 das
.discrim
->limit
= INT_MAX
;
5971 if (action
== trace_svsjoin_func
&& !das
.discrim
->chantarget
) {
5972 reply("OSMSG_SVSJOIN_NO_TARGET");
5975 else if (action
== trace_svspart_func
&& !das
.discrim
->chantarget
) {
5976 reply("OSMSG_SVSPART_NO_TARGET");
5979 else if (action
== trace_mark_func
&& !das
.discrim
->mark
) {
5980 reply("OSMSG_MARK_NO_MARK");
5984 matches
= opserv_discrim_search(das
.discrim
, action
, &das
);
5986 if (action
== trace_domains_func
)
5987 dict_foreach(das
.dict
, opserv_show_hostinfo
, &das
);
5991 if(action
== trace_print_func
)
5992 reply("OSMSG_USER_SEARCH_COUNT_BAR", matches
);
5994 reply("OSMSG_USER_SEARCH_COUNT", matches
);
5997 reply("MSG_NO_MATCHES");
6000 if (das
.discrim
->channel
)
6001 UnlockChannel(das
.discrim
->channel
);
6002 free(das
.discrim
->reason
);
6004 if(das
.discrim
->has_regex_nick
)
6005 regfree(&das
.discrim
->regex_nick
);
6006 if(das
.discrim
->has_regex_ident
)
6007 regfree(&das
.discrim
->regex_ident
);
6008 if(das
.discrim
->has_regex_host
)
6009 regfree(&das
.discrim
->regex_host
);
6010 if(das
.discrim
->has_regex_info
)
6011 regfree(&das
.discrim
->regex_info
);
6012 if(das
.discrim
->has_regex_version
)
6013 regfree(&das
.discrim
->regex_version
);
6016 dict_delete(das
.dict
);
6020 typedef void (*cdiscrim_search_func
)(struct chanNode
*match
, void *data
, struct userNode
*bot
);
6022 typedef struct channel_discrim
{
6025 unsigned int min_users
, max_users
;
6026 time_t min_ts
, max_ts
;
6030 static cdiscrim_t
opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[]);
6031 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
);
6034 smart_parse_time(const char *str
) {
6035 /* If an interval-style string is given, treat as time before now.
6036 * If it's all digits, treat directly as a Unix timestamp. */
6037 return str
[strspn(str
, "0123456789")] ? (time_t)(now
- ParseInterval(str
)) : (time_t)atoi(str
);
6041 opserv_cdiscrim_create(struct userNode
*user
, struct userNode
*bot
, unsigned int argc
, char *argv
[])
6046 discrim
= calloc(1, sizeof(*discrim
));
6047 discrim
->limit
= 25;
6049 for (i
= 0; i
< argc
; i
++) {
6050 /* Assume all criteria require arguments. */
6051 if (i
== (argc
- 1)) {
6052 send_message(user
, bot
, "MSG_MISSING_PARAMS", argv
[i
]);
6056 if (!irccasecmp(argv
[i
], "name"))
6057 discrim
->name
= argv
[++i
];
6058 else if (!irccasecmp(argv
[i
], "topic"))
6059 discrim
->topic
= argv
[++i
];
6060 else if (!irccasecmp(argv
[i
], "users")) {
6061 const char *cmp
= argv
[++i
];
6062 if (cmp
[0] == '<') {
6064 discrim
->max_users
= strtoul(cmp
+2, NULL
, 0);
6066 discrim
->max_users
= strtoul(cmp
+1, NULL
, 0) - 1;
6067 } else if (cmp
[0] == '=') {
6068 discrim
->min_users
= discrim
->max_users
= strtoul(cmp
+1, NULL
, 0);
6069 } else if (cmp
[0] == '>') {
6071 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6073 discrim
->min_users
= strtoul(cmp
+1, NULL
, 0) + 1;
6075 discrim
->min_users
= strtoul(cmp
+2, NULL
, 0);
6077 } else if (!irccasecmp(argv
[i
], "timestamp")) {
6078 const char *cmp
= argv
[++i
];
6079 if (cmp
[0] == '<') {
6081 discrim
->max_ts
= smart_parse_time(cmp
+2);
6083 discrim
->max_ts
= smart_parse_time(cmp
+1)-1;
6084 } else if (cmp
[0] == '=') {
6085 discrim
->min_ts
= discrim
->max_ts
= smart_parse_time(cmp
+1);
6086 } else if (cmp
[0] == '>') {
6088 discrim
->min_ts
= smart_parse_time(cmp
+2);
6090 discrim
->min_ts
= smart_parse_time(cmp
+1)+1;
6092 discrim
->min_ts
= smart_parse_time(cmp
);
6094 } else if (!irccasecmp(argv
[i
], "limit")) {
6095 discrim
->limit
= strtoul(argv
[++i
], NULL
, 10);
6097 send_message(user
, bot
, "MSG_INVALID_CRITERIA", argv
[i
]);
6102 if (discrim
->name
&& !strcmp(discrim
->name
, "*"))
6104 if (discrim
->topic
&& !strcmp(discrim
->topic
, "*"))
6114 cdiscrim_match(cdiscrim_t discrim
, struct chanNode
*chan
)
6116 if ((discrim
->name
&& !match_ircglob(chan
->name
, discrim
->name
)) ||
6117 (discrim
->topic
&& !match_ircglob(chan
->topic
, discrim
->topic
)) ||
6118 (discrim
->min_users
&& chan
->members
.used
< discrim
->min_users
) ||
6119 (discrim
->max_users
&& chan
->members
.used
> discrim
->max_users
) ||
6120 (discrim
->min_ts
&& chan
->timestamp
< discrim
->min_ts
) ||
6121 (discrim
->max_ts
&& chan
->timestamp
> discrim
->max_ts
)) {
6127 static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim
, cdiscrim_search_func dsf
, void *data
, struct userNode
*bot
)
6129 unsigned int count
= 0;
6130 dict_iterator_t it
, next
;
6132 for (it
= dict_first(channels
); it
&& count
< discrim
->limit
; it
= next
) {
6133 struct chanNode
*chan
= iter_data(it
);
6135 /* Hold on to the next channel in case we decide to
6136 add actions that destructively modify the channel. */
6137 next
= iter_next(it
);
6138 if ((chan
->members
.used
> 0) && cdiscrim_match(discrim
, chan
)) {
6139 dsf(chan
, data
, bot
);
6147 void channel_count(UNUSED_ARG(struct chanNode
*channel
), UNUSED_ARG(void *data
), UNUSED_ARG(struct userNode
*bot
))
6151 void channel_print(struct chanNode
*channel
, void *data
, struct userNode
*bot
)
6154 irc_make_chanmode(channel
, modes
);
6155 send_message(data
, bot
, "OSMSG_CSEARCH_CHANNEL_INFO", channel
->name
, channel
->members
.used
, modes
, channel
->topic
);
6158 static MODCMD_FUNC(cmd_csearch
)
6161 unsigned int matches
;
6162 cdiscrim_search_func action
;
6163 struct svccmd
*subcmd
;
6166 if (!irccasecmp(argv
[1], "count"))
6167 action
= channel_count
;
6168 else if (!irccasecmp(argv
[1], "print"))
6169 action
= channel_print
;
6171 reply("OSMSG_BAD_ACTION", argv
[1]);
6175 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6176 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6177 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6181 discrim
= opserv_cdiscrim_create(user
, cmd
->parent
->bot
, argc
- 2, argv
+ 2);
6185 if (action
== channel_print
)
6186 reply("OSMSG_CHANNEL_SEARCH_RESULTS");
6187 else if (action
== channel_count
)
6188 discrim
->limit
= INT_MAX
;
6190 matches
= opserv_cdiscrim_search(discrim
, action
, user
, cmd
->parent
->bot
);
6193 reply("MSG_MATCH_COUNT", matches
);
6195 reply("MSG_NO_MATCHES");
6201 static MODCMD_FUNC(cmd_gsync
)
6205 src
= GetServerH(argv
[1]);
6207 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6213 irc_stats(cmd
->parent
->bot
, src
, 'G');
6214 reply("OSMSG_GSYNC_RUNNING", src
->name
);
6218 static MODCMD_FUNC(cmd_ssync
)
6222 src
= GetServerH(argv
[1]);
6224 reply("MSG_SERVER_UNKNOWN", argv
[1]);
6230 irc_stats(cmd
->parent
->bot
, src
, 'S');
6231 reply("OSMSG_SSYNC_RUNNING", src
->name
);
6235 struct gline_extra
{
6236 struct userNode
*user
;
6237 struct string_list
*glines
;
6238 struct userNode
*bot
;
6242 gtrace_print_func(struct gline
*gline
, void *extra
)
6244 struct gline_extra
*xtra
= extra
;
6245 char *when_text
, set_text
[20];
6246 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&gline
->issued
));
6247 when_text
= asctime(localtime(&gline
->expires
));
6248 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6249 send_message(xtra
->user
, xtra
->bot
, "OSMSG_GTRACE_FORMAT", gline
->target
, set_text
, gline
->issuer
, when_text
, gline
->reason
);
6253 gtrace_count_func(UNUSED_ARG(struct gline
*gline
), UNUSED_ARG(void *extra
))
6258 gtrace_ungline_func(struct gline
*gline
, void *extra
)
6260 struct gline_extra
*xtra
= extra
;
6261 string_list_append(xtra
->glines
, strdup(gline
->target
));
6264 static MODCMD_FUNC(cmd_gtrace
)
6266 struct gline_discrim
*discrim
;
6267 gline_search_func action
;
6268 unsigned int matches
, nn
;
6269 struct gline_extra extra
;
6270 struct svccmd
*subcmd
;
6273 if (!irccasecmp(argv
[1], "print"))
6274 action
= gtrace_print_func
;
6275 else if (!irccasecmp(argv
[1], "count"))
6276 action
= gtrace_count_func
;
6277 else if (!irccasecmp(argv
[1], "ungline"))
6278 action
= gtrace_ungline_func
;
6280 reply("OSMSG_BAD_ACTION", argv
[1]);
6283 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6284 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6285 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6289 discrim
= gline_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6293 if (action
== gtrace_print_func
)
6294 reply("OSMSG_GLINE_SEARCH_RESULTS");
6295 else if (action
== gtrace_count_func
)
6296 discrim
->limit
= INT_MAX
;
6299 extra
.glines
= alloc_string_list(4);
6300 extra
.bot
= cmd
->parent
->bot
;
6301 matches
= gline_discrim_search(discrim
, action
, &extra
);
6303 if (action
== gtrace_ungline_func
)
6304 for (nn
=0; nn
<extra
.glines
->used
; nn
++)
6305 gline_remove(extra
.glines
->list
[nn
], 1);
6306 free_string_list(extra
.glines
);
6309 reply("MSG_MATCH_COUNT", matches
);
6311 reply("MSG_NO_MATCHES");
6312 free(discrim
->alt_target_mask
);
6318 struct userNode
*user
;
6319 struct string_list
*shuns
;
6320 struct userNode
*bot
;
6324 strace_print_func(struct shun
*shun
, void *extra
)
6326 struct shun_extra
*xtra
= extra
;
6327 char *when_text
, set_text
[20];
6328 strftime(set_text
, sizeof(set_text
), "%Y-%m-%d", localtime(&shun
->issued
));
6329 when_text
= asctime(localtime(&shun
->expires
));
6330 when_text
[strlen(when_text
)-1] = 0; /* strip lame \n */
6331 send_message(xtra
->user
, xtra
->bot
, "OSMSG_STRACE_FORMAT", shun
->target
, set_text
, shun
->issuer
, when_text
, shun
->reason
);
6335 strace_count_func(UNUSED_ARG(struct shun
*shun
), UNUSED_ARG(void *extra
))
6340 strace_unshun_func(struct shun
*shun
, void *extra
)
6342 struct shun_extra
*xtra
= extra
;
6343 string_list_append(xtra
->shuns
, strdup(shun
->target
));
6346 static MODCMD_FUNC(cmd_strace
)
6348 struct shun_discrim
*discrim
;
6349 shun_search_func action
;
6350 unsigned int matches
, nn
;
6351 struct shun_extra extra
;
6352 struct svccmd
*subcmd
;
6355 if (!irccasecmp(argv
[1], "print"))
6356 action
= strace_print_func
;
6357 else if (!irccasecmp(argv
[1], "count"))
6358 action
= strace_count_func
;
6359 else if (!irccasecmp(argv
[1], "unshun"))
6360 action
= strace_unshun_func
;
6362 reply("OSMSG_BAD_ACTION", argv
[1]);
6365 sprintf(buf
, "%s %s", argv
[0], argv
[0]);
6366 if ((subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))
6367 && !svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)) {
6371 discrim
= shun_discrim_create(user
, cmd
->parent
->bot
, argc
-2, argv
+2);
6375 if (action
== strace_print_func
)
6376 reply("OSMSG_SHUN_SEARCH_RESULTS");
6377 else if (action
== strace_count_func
)
6378 discrim
->limit
= INT_MAX
;
6381 extra
.shuns
= alloc_string_list(4);
6382 extra
.bot
= cmd
->parent
->bot
;
6383 matches
= shun_discrim_search(discrim
, action
, &extra
);
6385 if (action
== strace_unshun_func
)
6386 for (nn
=0; nn
<extra
.shuns
->used
; nn
++)
6387 shun_remove(extra
.shuns
->list
[nn
], 1);
6388 free_string_list(extra
.shuns
);
6391 reply("MSG_MATCH_COUNT", matches
);
6393 reply("MSG_NO_MATCHES");
6394 free(discrim
->alt_target_mask
);
6400 alert_check_user(const char *key
, void *data
, void *extra
)
6402 struct opserv_user_alert
*alert
= data
;
6403 struct userNode
*user
= extra
;
6405 if (!discrim_match(alert
->discrim
, user
))
6408 if ((alert
->reaction
!= REACT_NOTICE
)
6410 && !alert
->discrim
->match_opers
) {
6414 /* The user matches the alert criteria, so trigger the reaction. */
6415 if (alert
->discrim
->option_log
)
6416 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
);
6418 /* Return 1 to halt alert matching, such as when killing the user
6419 that triggered the alert. */
6420 switch (alert
->reaction
) {
6422 DelUser(user
, opserv
, 1, alert
->discrim
->reason
);
6425 opserv_block(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
, alert
->discrim
->silent
);
6428 opserv_shun(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->duration
);
6431 opserv_svsjoin(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
, alert
->discrim
->checkrestrictions
);
6434 opserv_svspart(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->chantarget
);
6437 /* Don't auto-version a user who we already have a version on, because the version reply itself
6438 * re-triggers this check...
6439 * TODO: maybe safer if we didn't even check react_version type alerts for the 2nd check?
6440 * sort of like we only look at channel alerts on join. -Rubin
6442 if(!user
->version_reply
)
6443 opserv_version(user
);
6446 opserv_mark(user
, alert
->owner
, alert
->discrim
->reason
, alert
->discrim
->mark
);
6449 log_module(OS_LOG
, LOG_ERROR
, "Invalid reaction type %d for alert %s.", alert
->reaction
, key
);
6450 /* fall through to REACT_NOTICE case */
6452 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
);
6456 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
);
6457 add_track_user(user
);
6465 opserv_alert_check_nick(struct userNode
*user
, UNUSED_ARG(const char *old_nick
))
6467 struct gag_entry
*gag
;
6468 dict_foreach(opserv_nick_based_alerts
, alert_check_user
, user
);
6469 /* Gag them if appropriate (and only if). */
6470 user
->modes
&= ~FLAGS_GAGGED
;
6471 for (gag
= gagList
; gag
; gag
= gag
->next
) {
6472 if (user_matches_glob(user
, gag
->mask
, MATCH_USENICK
)) {
6473 gag_helper_func(user
, NULL
);
6480 opserv_staff_alert(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
))
6484 if (!opserv_conf
.staff_auth_channel
6485 || user
->uplink
->burst
6486 || !user
->handle_info
)
6488 else if (user
->handle_info
->opserv_level
)
6490 else if (IsNetworkHelper(user
))
6491 type
= "NETWORK HELPER";
6492 else if (IsSupportHelper(user
))
6493 type
= "SUPPORT HELPER";
6497 if (irc_in_addr_is_valid(user
->ip
))
6498 send_channel_notice(opserv_conf
.staff_auth_channel
, opserv
, IDENT_FORMAT
" authed to %s account %s", IDENT_DATA(user
), type
, user
->handle_info
->handle
);
6500 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
);
6503 static MODCMD_FUNC(cmd_log
)
6505 struct logSearch
*discrim
;
6506 unsigned int matches
;
6507 struct logReport report
;
6509 discrim
= log_discrim_create(cmd
->parent
->bot
, user
, argc
, argv
);
6513 reply("OSMSG_LOG_SEARCH_RESULTS");
6514 report
.reporter
= opserv
;
6516 matches
= log_entry_search(discrim
, log_report_entry
, &report
);
6519 reply("MSG_MATCH_COUNT", matches
);
6521 reply("MSG_NO_MATCHES");
6528 gag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6530 if (IsOper(match
) || IsLocal(match
))
6532 match
->modes
|= FLAGS_GAGGED
;
6536 static MODCMD_FUNC(cmd_gag
)
6538 struct gag_entry
*gag
;
6539 unsigned int gagged
;
6540 unsigned long duration
;
6543 reason
= unsplit_string(argv
+ 3, argc
- 3, NULL
);
6545 if (!is_ircmask(argv
[1])) {
6546 reply("OSMSG_INVALID_IRCMASK", argv
[1]);
6550 for (gag
= gagList
; gag
; gag
= gag
->next
)
6551 if (match_ircglobs(gag
->mask
, argv
[1]))
6555 reply("OSMSG_REDUNDANT_GAG", argv
[1]);
6559 duration
= ParseInterval(argv
[2]);
6560 gagged
= gag_create(argv
[1], user
->handle_info
->handle
, reason
, (duration
?now
+duration
:0));
6563 reply("OSMSG_GAG_APPLIED", argv
[1], gagged
);
6565 reply("OSMSG_GAG_ADDED", argv
[1]);
6570 ungag_helper_func(struct userNode
*match
, UNUSED_ARG(void *extra
))
6572 match
->modes
&= ~FLAGS_GAGGED
;
6576 static MODCMD_FUNC(cmd_ungag
)
6578 struct gag_entry
*gag
;
6579 unsigned int ungagged
;
6581 for (gag
= gagList
; gag
; gag
= gag
->next
)
6582 if (!strcmp(gag
->mask
, argv
[1]))
6586 reply("OSMSG_GAG_NOT_FOUND", argv
[1]);
6590 timeq_del(gag
->expires
, gag_expire
, gag
, 0);
6591 ungagged
= gag_free(gag
);
6594 reply("OSMSG_UNGAG_APPLIED", argv
[1], ungagged
);
6596 reply("OSMSG_UNGAG_ADDED", argv
[1]);
6600 static MODCMD_FUNC(cmd_addalert
)
6602 opserv_alert_reaction reaction
;
6603 struct svccmd
*subcmd
;
6608 sprintf(buf
, "addalert %s", argv
[2]);
6609 if (!(subcmd
= dict_find(opserv_service
->commands
, buf
, NULL
))) {
6610 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6613 if (!irccasecmp(argv
[2], "notice"))
6614 reaction
= REACT_NOTICE
;
6615 else if (!irccasecmp(argv
[2], "kill"))
6616 reaction
= REACT_KILL
;
6617 else if (!irccasecmp(argv
[2], "gline"))
6618 reaction
= REACT_GLINE
;
6619 else if (!irccasecmp(argv
[2], "track")) {
6621 reply("OSMSG_TRACK_DISABLED");
6624 reaction
= REACT_TRACK
;
6626 } else if (!irccasecmp(argv
[2], "shun"))
6627 reaction
= REACT_SHUN
;
6628 else if(!irccasecmp(argv
[2], "svsjoin"))
6629 reaction
= REACT_SVSJOIN
;
6630 else if(!irccasecmp(argv
[2], "svspart"))
6631 reaction
= REACT_SVSPART
;
6632 else if(!irccasecmp(argv
[2], "version"))
6633 reaction
= REACT_VERSION
;
6634 else if(!irccasecmp(argv
[2], "mark"))
6635 reaction
= REACT_MARK
;
6637 reply("OSMSG_UNKNOWN_REACTION", argv
[2]);
6640 if (!svccmd_can_invoke(user
, opserv_service
->bot
, subcmd
, channel
, SVCCMD_NOISY
)
6641 || !opserv_add_user_alert(user
, name
, reaction
, unsplit_string(argv
+ 3, argc
- 3, NULL
))) {
6642 reply("OSMSG_ALERT_ADD_FAILED");
6645 reply("OSMSG_ADDED_ALERT", name
);
6649 static MODCMD_FUNC(cmd_delalert
)
6652 for (i
=1; i
<argc
; i
++) {
6653 dict_remove(opserv_nick_based_alerts
, argv
[i
]);
6654 dict_remove(opserv_channel_alerts
, argv
[i
]);
6655 if (dict_remove(opserv_user_alerts
, argv
[i
]))
6656 reply("OSMSG_REMOVED_ALERT", argv
[i
]);
6658 reply("OSMSG_NO_SUCH_ALERT", argv
[i
]);
6664 opserv_conf_read(void)
6666 struct chanNode
*chan
;
6668 struct record_data
*rd
;
6669 dict_t conf_node
, child
;
6670 const char *str
, *str2
;
6671 struct policer_params
*pp
;
6674 rd
= conf_get_node(OPSERV_CONF_NAME
);
6675 if (!rd
|| rd
->type
!= RECDB_OBJECT
) {
6676 log_module(OS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME
);
6679 conf_node
= rd
->d
.object
;
6680 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
6681 if (opserv
&& str
) {
6682 str2
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL_MODES
, RECDB_QSTRING
);
6685 opserv_conf
.debug_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6686 AddChannelUser(opserv
, opserv_conf
.debug_channel
)->modes
|= MODE_CHANOP
;
6688 opserv_conf
.debug_channel
= NULL
;
6690 str
= database_get_data(conf_node
, KEY_ALERT_CHANNEL
, RECDB_QSTRING
);
6691 if (opserv
&& str
) {
6692 str2
= database_get_data(conf_node
, KEY_ALERT_CHANNEL_MODES
, RECDB_QSTRING
);
6695 opserv_conf
.alert_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6696 AddChannelUser(opserv
, opserv_conf
.alert_channel
)->modes
|= MODE_CHANOP
;
6698 opserv_conf
.alert_channel
= NULL
;
6700 str
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL
, RECDB_QSTRING
);
6701 if (opserv
&& str
) {
6702 str2
= database_get_data(conf_node
, KEY_STAFF_AUTH_CHANNEL_MODES
, RECDB_QSTRING
);
6705 opserv_conf
.staff_auth_channel
= AddChannel(str
, now
, str2
, NULL
, NULL
);
6706 AddChannelUser(opserv
, opserv_conf
.staff_auth_channel
)->modes
|= MODE_CHANOP
;
6708 opserv_conf
.staff_auth_channel
= NULL
;
6711 str
= database_get_data(conf_node
, KEY_ADMIN_LEVEL
, RECDB_QSTRING
);
6712 opserv_conf
.admin_level
= str
? strtoul(str
, NULL
, 0): 800;
6714 str
= database_get_data(conf_node
, KEY_SILENT_LEVEL
, RECDB_QSTRING
);
6715 opserv_conf
.silent_level
= str
? strtoul(str
, NULL
, 0): 700;
6717 str
= database_get_data(conf_node
, KEY_UNTRUSTED_MAX
, RECDB_QSTRING
);
6718 opserv_conf
.untrusted_max
= str
? strtoul(str
, NULL
, 0) : 5;
6719 str
= database_get_data(conf_node
, KEY_PURGE_LOCK_DELAY
, RECDB_QSTRING
);
6720 opserv_conf
.purge_lock_delay
= str
? strtoul(str
, NULL
, 0) : 60;
6721 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE
, RECDB_QSTRING
);
6722 opserv_conf
.join_flood_moderate
= str
? strtoul(str
, NULL
, 0) : 1;
6723 str
= database_get_data(conf_node
, KEY_JOIN_FLOOD_MODERATE_THRESH
, RECDB_QSTRING
);
6724 opserv_conf
.join_flood_moderate_threshold
= str
? strtoul(str
, NULL
, 0) : 50;
6725 str
= database_get_data(conf_node
, KEY_NICK
, RECDB_QSTRING
);
6727 NickChange(opserv
, str
, 0);
6729 str
= database_get_data(conf_node
, KEY_CLONE_GLINE_DURATION
, RECDB_QSTRING
);
6730 opserv_conf
.clone_gline_duration
= str
? ParseInterval(str
) : 3600;
6731 str
= database_get_data(conf_node
, KEY_BLOCK_GLINE_DURATION
, RECDB_QSTRING
);
6732 opserv_conf
.block_gline_duration
= str
? ParseInterval(str
) : 3600;
6734 free_string_list(autojoin_channels
);
6735 autojoin_channels
= database_get_data(conf_node
, KEY_AUTOJOIN_CHANNELS
, RECDB_STRING_LIST
);
6737 if(autojoin_channels
)
6738 autojoin_channels
= string_list_copy(autojoin_channels
);
6740 if (autojoin_channels
&& opserv
) {
6741 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
6742 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
6743 AddChannelUser(opserv
, chan
)->modes
|= MODE_CHANOP
;
6747 str
= database_get_data(conf_node
, KEY_BLOCK_SHUN_DURATION
, RECDB_QSTRING
);
6748 opserv_conf
.block_shun_duration
= str
? ParseInterval(str
) : 3600;
6750 if (!opserv_conf
.join_policer_params
)
6751 opserv_conf
.join_policer_params
= policer_params_new();
6752 policer_params_set(opserv_conf
.join_policer_params
, "size", "20");
6753 policer_params_set(opserv_conf
.join_policer_params
, "drain-rate", "1");
6754 if ((child
= database_get_data(conf_node
, KEY_JOIN_POLICER
, RECDB_OBJECT
)))
6755 dict_foreach(child
, set_policer_param
, opserv_conf
.join_policer_params
);
6757 for (it
= dict_first(channels
); it
; it
= iter_next(it
)) {
6758 struct chanNode
*cNode
= iter_data(it
);
6759 cNode
->join_policer
.params
= opserv_conf
.join_policer_params
;
6762 if (opserv_conf
.new_user_policer
.params
)
6763 pp
= opserv_conf
.new_user_policer
.params
;
6765 pp
= opserv_conf
.new_user_policer
.params
= policer_params_new();
6766 policer_params_set(pp
, "size", "200");
6767 policer_params_set(pp
, "drain-rate", "3");
6768 if ((child
= database_get_data(conf_node
, KEY_NEW_USER_POLICER
, RECDB_OBJECT
)))
6769 dict_foreach(child
, set_policer_param
, pp
);
6771 /* Defcon configuration */
6773 str
= database_get_data(conf_node
, KEY_DEFCON1
, RECDB_QSTRING
);
6774 DefCon
[1] = str
? atoi(str
) : 415;
6775 str
= database_get_data(conf_node
, KEY_DEFCON2
, RECDB_QSTRING
);
6776 DefCon
[2] = str
? atoi(str
) : 159;
6777 str
= database_get_data(conf_node
, KEY_DEFCON3
, RECDB_QSTRING
);
6778 DefCon
[3] = str
? atoi(str
) : 31;
6779 str
= database_get_data(conf_node
, KEY_DEFCON4
, RECDB_QSTRING
);
6780 DefCon
[4] = str
? atoi(str
) : 23;
6783 str
= database_get_data(conf_node
, KEY_DEFCON_LEVEL
, RECDB_QSTRING
);
6784 DefConLevel
= str
? atoi(str
) : 5;
6786 str
= database_get_data(conf_node
, KEY_DEFCON_CHANMODES
, RECDB_QSTRING
);
6787 DefConChanModes
= str
? strdup(str
) : "+r";
6789 str
= database_get_data(conf_node
, KEY_DEFCON_SESSION_LIMIT
, RECDB_QSTRING
);
6790 DefConSessionLimit
= str
? atoi(str
) : 2;
6792 str
= database_get_data(conf_node
, KEY_DEFCON_TIMEOUT
, RECDB_QSTRING
);
6793 DefConTimeOut
= str
? ParseInterval(str
) : 900;
6795 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_DURATION
, RECDB_QSTRING
);
6796 DefConGlineExpire
= str
? ParseInterval(str
) : 300;
6798 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL
, RECDB_QSTRING
);
6799 GlobalOnDefcon
= str
? atoi(str
) : 0;
6801 str
= database_get_data(conf_node
, KEY_DEFCON_GLOBAL_MORE
, RECDB_QSTRING
);
6802 GlobalOnDefconMore
= str
? atoi(str
) : 0;
6804 str
= database_get_data(conf_node
, KEY_DEFCON_MESSAGE
, RECDB_QSTRING
);
6805 DefConMessage
= str
? strdup(str
) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore";
6807 str
= database_get_data(conf_node
, KEY_DEFCON_OFF_MESSAGE
, RECDB_QSTRING
);
6808 DefConOffMessage
= str
? strdup(str
) : "Services are now back to normal, sorry for any inconvenience";
6810 str
= database_get_data(conf_node
, KEY_DEFCON_GLINE_REASON
, RECDB_QSTRING
);
6811 DefConGlineReason
= str
? strdup(str
) : "This network is currently not accepting connections, please try again later";
6814 /* lame way to export opserv_conf value to nickserv.c ... */
6816 opserv_conf_admin_level()
6818 return(opserv_conf
.admin_level
);
6822 opserv_db_init(void) {
6823 /* set up opserv_trusted_hosts dict */
6824 dict_delete(opserv_trusted_hosts
);
6825 opserv_trusted_hosts
= dict_new();
6826 dict_set_free_data(opserv_trusted_hosts
, free_trusted_host
);
6828 opserv_routing_plan_options
= dict_new();
6830 opserv_routing_plans
= dict_new();
6831 dict_set_free_data(opserv_routing_plans
, free_routing_plan
);
6832 /* set up opserv_chan_warn dict */
6834 /* alert trace notice channel #x replaces warnings
6835 dict_delete(opserv_chan_warn);
6836 opserv_chan_warn = dict_new();
6837 dict_set_free_keys(opserv_chan_warn, free);
6838 dict_set_free_data(opserv_chan_warn, free);
6840 /* set up opserv_user_alerts */
6841 dict_delete(opserv_channel_alerts
);
6842 opserv_channel_alerts
= dict_new();
6843 dict_delete(opserv_nick_based_alerts
);
6844 opserv_nick_based_alerts
= dict_new();
6845 dict_delete(opserv_user_alerts
);
6846 opserv_user_alerts
= dict_new();
6847 dict_set_free_keys(opserv_user_alerts
, free
);
6848 dict_set_free_data(opserv_user_alerts
, opserv_free_user_alert
);
6849 /* set up opserv_bad_words */
6850 free_string_list(opserv_bad_words
);
6851 opserv_bad_words
= alloc_string_list(4);
6852 /* and opserv_exempt_channels */
6853 dict_delete(opserv_exempt_channels
);
6854 opserv_exempt_channels
= dict_new();
6855 dict_set_free_keys(opserv_exempt_channels
, free
);
6859 opserv_db_cleanup(void)
6863 /* dict_delete(opserv_chan_warn); */
6864 dict_delete(opserv_reserved_nick_dict
);
6865 free_string_list(opserv_bad_words
);
6866 dict_delete(opserv_exempt_channels
);
6867 dict_delete(opserv_trusted_hosts
);
6868 unreg_del_user_func(opserv_user_cleanup
);
6869 dict_delete(opserv_hostinfo_dict
);
6870 dict_delete(opserv_nick_based_alerts
);
6871 dict_delete(opserv_channel_alerts
);
6872 dict_delete(opserv_user_alerts
);
6873 for (nn
=0; nn
<ArrayLength(level_strings
); ++nn
)
6874 free(level_strings
[nn
]);
6877 policer_params_delete(opserv_conf
.join_policer_params
);
6878 policer_params_delete(opserv_conf
.new_user_policer
.params
);
6882 init_opserv(const char *nick
)
6884 OS_LOG
= log_register_type("OpServ", "file:opserv.log");
6886 const char *modes
= conf_get_data("services/opserv/modes", RECDB_QSTRING
);
6887 opserv
= AddService(nick
, modes
? modes
: NULL
, "Oper Services", NULL
);
6889 conf_register_reload(opserv_conf_read
);
6891 memset(level_strings
, 0, sizeof(level_strings
));
6892 opserv_module
= module_register("OpServ", OS_LOG
, "opserv.help", opserv_help_expand
);
6893 opserv_define_func("ACCESS", cmd_access
, 0, 0, 0);
6894 opserv_define_func("ADDALERT", cmd_addalert
, 800, 0, 4);
6895 opserv_define_func("ADDALERT NOTICE", NULL
, 0, 0, 0);
6896 opserv_define_func("ADDALERT SILENT", NULL
, 900, 0, 0);
6897 opserv_define_func("ADDALERT GLINE", NULL
, 900, 0, 0);
6898 opserv_define_func("ADDALERT SHUN", NULL
, 900, 0, 0);
6899 opserv_define_func("ADDALERT TRACK", NULL
, 900, 0, 0);
6900 opserv_define_func("ADDALERT KILL", NULL
, 900, 0, 0);
6901 opserv_define_func("ADDALERT SVSJOIN", NULL
, 999, 0, 0);
6902 opserv_define_func("ADDALERT SVSPART", NULL
, 999, 0, 0);
6903 opserv_define_func("ADDALERT VERSION", NULL
, 999, 0, 0);
6904 opserv_define_func("ADDALERT MARK", NULL
, 999, 0, 0);
6905 opserv_define_func("ADDBAD", cmd_addbad
, 800, 0, 2);
6906 opserv_define_func("ADDEXEMPT", cmd_addexempt
, 800, 0, 2);
6907 opserv_define_func("ADDTRUST", cmd_addtrust
, 800, 0, 5);
6908 opserv_define_func("BAN", cmd_ban
, 100, 2, 2);
6909 opserv_define_func("BLOCK", cmd_block
, 100, 0, 2);
6910 opserv_define_func("CHANINFO", cmd_chaninfo
, 0, 3, 0);
6911 opserv_define_func("CLEARBANS", cmd_clearbans
, 300, 2, 0);
6912 opserv_define_func("CLEARMODES", cmd_clearmodes
, 400, 2, 0);
6913 opserv_define_func("CLONE", cmd_clone
, 999, 0, 3);
6914 opserv_define_func("COLLIDE", cmd_collide
, 800, 0, 5);
6915 opserv_define_func("CSEARCH", cmd_csearch
, 100, 0, 3);
6916 opserv_define_func("CSEARCH COUNT", cmd_csearch
, 0, 0, 0);
6917 opserv_define_func("CSEARCH PRINT", cmd_csearch
, 0, 0, 0);
6918 opserv_define_func("DELALERT", cmd_delalert
, 800, 0, 2);
6919 opserv_define_func("DELBAD", cmd_delbad
, 800, 0, 2);
6920 opserv_define_func("DELEXEMPT", cmd_delexempt
, 800, 0, 2);
6921 opserv_define_func("DELTRUST", cmd_deltrust
, 800, 0, 2);
6922 opserv_define_func("DEOP", cmd_deop
, 100, 2, 2);
6923 opserv_define_func("DEOPALL", cmd_deopall
, 400, 2, 0);
6924 opserv_define_func("DEFCON", cmd_defcon
, 900, 0, 0);
6925 opserv_define_func("DEHOP", cmd_dehop
, 100, 2, 2);
6926 opserv_define_func("DEHOPALL", cmd_dehopall
, 400, 2, 0);
6927 opserv_define_func("DEVOICEALL", cmd_devoiceall
, 300, 2, 0);
6928 opserv_define_func("DIE", cmd_die
, 900, 0, 2);
6929 opserv_define_func("DUMP", cmd_dump
, 999, 0, 2);
6930 opserv_define_func("EDITTRUST", cmd_edittrust
, 800, 0, 5);
6931 opserv_define_func("GAG", cmd_gag
, 600, 0, 4);
6932 opserv_define_func("GLINE", cmd_gline
, 600, 0, 4);
6933 opserv_define_func("GSYNC", cmd_gsync
, 600, 0, 0);
6934 opserv_define_func("GTRACE", cmd_gtrace
, 100, 0, 3);
6935 opserv_define_func("GTRACE COUNT", NULL
, 0, 0, 0);
6936 opserv_define_func("GTRACE PRINT", NULL
, 0, 0, 0);
6937 opserv_define_func("SBLOCK", cmd_sblock
, 100, 0, 2);
6938 opserv_define_func("SHUN", cmd_shun
, 600, 0, 4);
6939 opserv_define_func("SSYNC", cmd_ssync
, 600, 0, 0);
6940 opserv_define_func("STRACE", cmd_strace
, 100, 0, 3);
6941 opserv_define_func("STRACE COUNT", NULL
, 0, 0, 0);
6942 opserv_define_func("STRACE PRINT", NULL
, 0, 0, 0);
6943 opserv_define_func("INVITE", cmd_invite
, 100, 2, 0);
6944 opserv_define_func("INVITEME", cmd_inviteme
, 100, 0, 0);
6945 opserv_define_func("JOIN", cmd_join
, 601, 0, 2);
6946 opserv_define_func("SVSJOIN", cmd_svsjoin
, 999, 0, 3);
6947 opserv_define_func("SVSPART", cmd_svspart
, 999, 0, 3);
6948 opserv_define_func("JUMP", cmd_jump
, 900, 0, 2);
6949 opserv_define_func("JUPE", cmd_jupe
, 900, 0, 4);
6950 opserv_define_func("KICK", cmd_kick
, 100, 2, 2);
6951 opserv_define_func("KICKALL", cmd_kickall
, 400, 2, 0);
6952 opserv_define_func("KICKBAN", cmd_kickban
, 100, 2, 2);
6953 opserv_define_func("KICKBANALL", cmd_kickbanall
, 450, 2, 0);
6954 opserv_define_func("LOG", cmd_log
, 900, 0, 2);
6955 opserv_define_func("MODE", cmd_mode
, 100, 2, 2);
6956 opserv_define_func("MARK", cmd_mark
, 900, 0, 3);
6957 opserv_define_func("OP", cmd_op
, 100, 2, 2);
6958 opserv_define_func("OPALL", cmd_opall
, 400, 2, 0);
6959 opserv_define_func("HOP", cmd_hop
, 100, 2, 2);
6960 opserv_define_func("HOPALL", cmd_hopall
, 400, 2, 0);
6961 opserv_define_func("MAP", cmd_stats_links
, 0, 0, 0);
6962 opserv_define_func("PRIVSET", cmd_privset
, 900, 0, 3);
6963 opserv_define_func("PART", cmd_part
, 601, 0, 2);
6964 opserv_define_func("QUERY", cmd_query
, 0, 0, 0);
6965 opserv_define_func("RAW", cmd_raw
, 999, 0, 2);
6966 opserv_define_func("RECONNECT", cmd_reconnect
, 900, 0, 0);
6967 opserv_define_func("REFRESHG", cmd_refreshg
, 600, 0, 0);
6968 opserv_define_func("REFRESHS", cmd_refreshs
, 600, 0, 0);
6969 opserv_define_func("REHASH", cmd_rehash
, 900, 0, 0);
6970 opserv_define_func("REOPEN", cmd_reopen
, 900, 0, 0);
6971 opserv_define_func("RESETMAX", cmd_resetmax
, 900, 0, 0);
6972 opserv_define_func("RESERVE", cmd_reserve
, 800, 0, 5);
6973 opserv_define_func("RESTART", cmd_restart
, 900, 0, 2);
6974 opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan
, 800, 0, 2);
6975 opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan
, 800, 0, 2);
6976 opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver
, 800, 0, 4);
6977 opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver
, 800, 0, 3);
6978 opserv_define_func("ROUTING MAP", cmd_routing_map
, 800, 0, 0);
6979 opserv_define_func("ROUTING SET", cmd_routing_set
, 800, 0, 0);
6980 opserv_define_func("REROUTE", cmd_reroute
, 800, 0, 2);
6981 opserv_define_func("SET", cmd_set
, 900, 0, 3);
6982 opserv_define_func("SETTIME", cmd_settime
, 901, 0, 0);
6983 opserv_define_func("STATS ALERTS", cmd_stats_alerts
, 0, 0, 0);
6984 opserv_define_func("STATS BAD", cmd_stats_bad
, 0, 0, 0);
6985 opserv_define_func("STATS GAGS", cmd_stats_gags
, 0, 0, 0);
6986 opserv_define_func("STATS GLINES", cmd_stats_glines
, 0, 0, 0);
6987 opserv_define_func("STATS SHUNS", cmd_stats_shuns
, 0, 0, 0);
6988 opserv_define_func("STATS LINKS", cmd_stats_links
, 0, 0, 0);
6989 opserv_define_func("STATS MAX", cmd_stats_max
, 0, 0, 0);
6990 opserv_define_func("STATS NETWORK", cmd_stats_network
, 0, 0, 0);
6991 opserv_define_func("STATS NETWORK2", cmd_stats_network2
, 0, 0, 0);
6992 opserv_define_func("STATS RESERVED", cmd_stats_reserved
, 0, 0, 0);
6993 opserv_define_func("STATS ROUTING", cmd_stats_routing_plans
, 0, 0, 0);
6994 opserv_define_func("STATS TIMEQ", cmd_stats_timeq
, 0, 0, 0);
6995 opserv_define_func("STATS TRUSTED", cmd_stats_trusted
, 0, 0, 0);
6996 opserv_define_func("STATS UPLINK", cmd_stats_uplink
, 0, 0, 0);
6997 opserv_define_func("STATS UPTIME", cmd_stats_uptime
, 0, 0, 0);
6998 /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */
6999 #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB)
7000 opserv_define_func("STATS MEMORY", cmd_stats_memory
, 0, 0, 0);
7002 opserv_define_func("TRACE", cmd_trace
, 100, 0, 3);
7003 opserv_define_func("TRACE PRINT", NULL
, 0, 0, 0);
7004 opserv_define_func("TRACE COUNT", NULL
, 0, 0, 0);
7005 opserv_define_func("TRACE DOMAINS", NULL
, 0, 0, 0);
7006 opserv_define_func("TRACE GLINE", NULL
, 600, 0, 0);
7007 opserv_define_func("TRACE SHUN", NULL
, 600, 0, 0);
7008 opserv_define_func("TRACE GAG", NULL
, 600, 0, 0);
7009 opserv_define_func("TRACE KILL", NULL
, 600, 0, 0);
7010 opserv_define_func("TRACE VERSION", NULL
, 999, 0, 0);
7011 opserv_define_func("TRACE SVSJOIN", NULL
, 999, 0, 0);
7012 opserv_define_func("TRACE SVSPART", NULL
, 999, 0, 0);
7013 opserv_define_func("TRACE MARK", NULL
, 999, 0, 0);
7014 opserv_define_func("UNBAN", cmd_unban
, 100, 2, 2);
7015 opserv_define_func("UNGAG", cmd_ungag
, 600, 0, 2);
7016 opserv_define_func("UNGLINE", cmd_ungline
, 600, 0, 2);
7017 modcmd_register(opserv_module
, "GTRACE UNGLINE", NULL
, 0, 0, "template", "ungline", NULL
);
7018 opserv_define_func("UNSHUN", cmd_unshun
, 600, 0, 2);
7019 modcmd_register(opserv_module
, "GTRACE UNSHUN", NULL
, 0, 0, "template", "unshun", NULL
);
7020 opserv_define_func("UNJUPE", cmd_unjupe
, 900, 0, 2);
7021 opserv_define_func("UNRESERVE", cmd_unreserve
, 800, 0, 2);
7022 /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */
7023 opserv_define_func("VOICEALL", cmd_voiceall
, 300, 2, 0);
7024 /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */
7025 opserv_define_func("WHOIS", cmd_whois
, 0, 0, 2);
7027 opserv_reserved_nick_dict
= dict_new();
7028 opserv_hostinfo_dict
= dict_new();
7030 dict_set_free_keys(opserv_hostinfo_dict
, free
);
7031 dict_set_free_data(opserv_hostinfo_dict
, opserv_free_hostinfo
);
7033 opserv_waiting_connections
= dict_new();
7034 dict_set_free_data(opserv_waiting_connections
, opserv_free_waiting_connection
);
7036 reg_new_user_func(opserv_new_user_check
);
7037 reg_nick_change_func(opserv_alert_check_nick
);
7038 reg_del_user_func(opserv_user_cleanup
);
7039 reg_new_channel_func(opserv_channel_check
);
7040 reg_del_channel_func(opserv_channel_delete
);
7041 reg_join_func(opserv_join_check
);
7042 reg_auth_func(opserv_staff_alert
);
7043 reg_notice_func(opserv
, opserv_notice_handler
);
7046 saxdb_register("OpServ", opserv_saxdb_read
, opserv_saxdb_write
);
7049 opserv_service
= service_register(opserv
);
7050 opserv_service
->trigger
= '?';
7053 /* start auto-routing system */
7054 /* this cant be done here, because the routing system isnt marked active yet. */
7055 /* reroute_timer(NULL); */
7057 /* start the karma timer, using the saved one if available */
7058 routing_karma_timer(dict_find(opserv_routing_plan_options
, "KARMA_TIMER", NULL
));
7060 reg_exit_func(opserv_db_cleanup
);
7061 message_register_table(msgtab
);