]>
Commit | Line | Data |
---|---|---|
d76ed9a9 | 1 | /* opserv.c - IRC Operator assistance service |
2 | * Copyright 2000-2004 srvx Development Team | |
3 | * | |
83ff05c3 | 4 | * This file is part of x3. |
d76ed9a9 | 5 | * |
d0f04f71 | 6 | * x3 is free software; you can redistribute it and/or modify |
d76ed9a9 | 7 | * it under the terms of the GNU General Public License as published by |
348683aa | 8 | * the Free Software Foundation; either version 3 of the License, or |
d76ed9a9 | 9 | * (at your option) any later version. |
10 | * | |
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. | |
15 | * | |
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. | |
19 | */ | |
20 | ||
8de34abd | 21 | #include "config.h" |
5aa400d2 | 22 | #include "chanserv.h" |
d76ed9a9 | 23 | #include "conf.h" |
47956fc5 | 24 | #include "common.h" |
d76ed9a9 | 25 | #include "gline.h" |
26 | #include "global.h" | |
27 | #include "nickserv.h" | |
28 | #include "modcmd.h" | |
ec311f39 | 29 | #include "modules.h" |
89d871d8 | 30 | #include "proto.h" |
d76ed9a9 | 31 | #include "opserv.h" |
32 | #include "timeq.h" | |
33 | #include "saxdb.h" | |
d914d1cb | 34 | #include "shun.h" |
d76ed9a9 | 35 | |
35305a49 | 36 | #include <tre/regex.h> |
5b1166fd | 37 | |
d76ed9a9 | 38 | #ifdef HAVE_SYS_TIMES_H |
39 | #include <sys/times.h> | |
40 | #endif | |
41 | #ifdef HAVE_NETINET_IN_H | |
42 | #include <netinet/in.h> | |
43 | #endif | |
44 | #ifdef HAVE_ARPA_INET_H | |
45 | #include <arpa/inet.h> | |
46 | #endif | |
5b1166fd | 47 | |
d76ed9a9 | 48 | #define OPSERV_CONF_NAME "services/opserv" |
49 | ||
50 | #define KEY_ALERT_CHANNEL "alert_channel" | |
51 | #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes" | |
52 | #define KEY_DEBUG_CHANNEL "debug_channel" | |
53 | #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes" | |
54 | #define KEY_UNTRUSTED_MAX "untrusted_max" | |
55 | #define KEY_PURGE_LOCK_DELAY "purge_lock_delay" | |
56 | #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate" | |
57 | #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold" | |
58 | #define KEY_NICK "nick" | |
59 | #define KEY_JOIN_POLICER "join_policer" | |
60 | #define KEY_NEW_USER_POLICER "new_user_policer" | |
7637f48f | 61 | #define KEY_AUTOJOIN_CHANNELS "autojoin_channels" |
d76ed9a9 | 62 | #define KEY_REASON "reason" |
63 | #define KEY_RESERVES "reserves" | |
64 | #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */ | |
65 | #define KEY_HOSTNAME "hostname" | |
66 | #define KEY_DESC "description" | |
67 | #define KEY_BAD_WORDS "bad" | |
68 | #define KEY_EXEMPT_CHANNELS "exempt" | |
69 | #define KEY_SECRET_WORDS "secret" | |
70 | #define KEY_TRUSTED_HOSTS "trusted" | |
71 | #define KEY_OWNER "owner" | |
72 | #define KEY_GAGS "gags" | |
73 | #define KEY_ALERTS "alerts" | |
74 | #define KEY_REACTION "reaction" | |
75 | #define KEY_DISCRIM "discrim" | |
76 | #define KEY_WARN "chanwarn" | |
77 | #define KEY_MAX "max" | |
78 | #define KEY_TIME "time" | |
79 | #define KEY_MAX_CLIENTS "max_clients" | |
80 | #define KEY_LIMIT "limit" | |
81 | #define KEY_EXPIRES "expires" | |
82 | #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel" | |
83 | #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes" | |
84 | #define KEY_CLONE_GLINE_DURATION "clone_gline_duration" | |
85 | #define KEY_BLOCK_GLINE_DURATION "block_gline_duration" | |
d914d1cb | 86 | #define KEY_BLOCK_SHUN_DURATION "block_shun_duration" |
d76ed9a9 | 87 | #define KEY_ISSUER "issuer" |
88 | #define KEY_ISSUED "issued" | |
5a1daaab | 89 | #define KEY_ADMIN_LEVEL "admin_level" |
1c5f6697 | 90 | #define KEY_SILENT_LEVEL "silent_level" |
47956fc5 | 91 | #define KEY_UPLINK "uplink" |
92 | #define KEY_SECOND "secondaryuplink" | |
93 | #define KEY_PORT "port" | |
94 | #define KEY_KARMA "karma" | |
95 | #define KEY_OFFLINE "offline" | |
96 | #define KEY_ROUTINGPLAN "routingplan" | |
97 | #define KEY_ROUTINGPLAN_OPTIONS "routingplan_options" | |
08895577 | 98 | #define KEY_DEFCON1 "DefCon1" |
99 | #define KEY_DEFCON2 "DefCon2" | |
100 | #define KEY_DEFCON3 "DefCon3" | |
101 | #define KEY_DEFCON4 "DefCon4" | |
102 | #define KEY_DEFCON_LEVEL "DefConLevel" | |
103 | #define KEY_DEFCON_CHANMODES "DefConChanModes" | |
104 | #define KEY_DEFCON_SESSION_LIMIT "DefConSessionLimit" | |
105 | #define KEY_DEFCON_TIMEOUT "DefConTimeOut" | |
08895577 | 106 | #define KEY_DEFCON_GLOBAL "GlobalOnDefcon" |
107 | #define KEY_DEFCON_GLOBAL_MORE "GlobalOnDefconMore" | |
108 | #define KEY_DEFCON_MESSAGE "DefconMessage" | |
109 | #define KEY_DEFCON_OFF_MESSAGE "DefConOffMessage" | |
110 | #define KEY_DEFCON_GLINE_DURATION "DefConGlineExpire" | |
111 | #define KEY_DEFCON_GLINE_REASON "DefConGlineReason" | |
47956fc5 | 112 | |
113 | /* Routing karma values: */ | |
114 | /* What value we start out with when new servers are added: */ | |
115 | #define KARMA_DEFAULT 10 | |
116 | /* max, min */ | |
117 | #define KARMA_MAX 10 | |
118 | #define KARMA_MIN -10 | |
119 | /* ping out, reduce karma by this much: */ | |
120 | #define KARMA_PINGOUT -8 | |
121 | /* read err, reduce karma by this much: */ | |
122 | #define KARMA_READERROR -5 | |
123 | /* every 24 hours everyone gets this much added (so we eventually re-try bad servers) */ | |
124 | #define KARMA_ENTROPE 1 | |
125 | /* every 24 hours servers linked for 24 hours get an additional ammount: */ | |
126 | #define KARMA_RELIABLE 1 | |
127 | /* How often to run entrope and reliable checks */ | |
128 | #define KARMA_TIMER 86400 /* 1 day */ | |
129 | ||
130 | #define ROUTING_CONNECT_TIMEOUT 30 /* 30 seconds */ | |
d76ed9a9 | 131 | |
258d1427 | 132 | #define IDENT_FORMAT "%s [%s@%s/%s]" |
2f61d1d7 | 133 | #define IDENT_DATA(user) user->nick, user->ident, user->hostname, irc_ntoa(&user->ip) |
258d1427 | 134 | #define MAX_CHANNELS_WHOIS 50 |
d76ed9a9 | 135 | #define OSMSG_PART_REASON "%s has no reason." |
136 | #define OSMSG_KICK_REQUESTED "Kick requested by %s." | |
137 | #define OSMSG_KILL_REQUESTED "Kill requested by %s." | |
138 | #define OSMSG_GAG_REQUESTED "Gag requested by %s." | |
139 | ||
140 | static const struct message_entry msgtab[] = { | |
de9510bc | 141 | { "OSMSG_BAR", "----------------------------------------" }, |
d76ed9a9 | 142 | { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." }, |
143 | { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." }, | |
144 | { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." }, | |
145 | { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." }, | |
146 | { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." }, | |
d914d1cb | 147 | { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." }, |
148 | { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." }, | |
149 | { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." }, | |
150 | { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." }, | |
151 | { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." }, | |
d76ed9a9 | 152 | { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." }, |
153 | { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." }, | |
154 | { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." }, | |
155 | { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." }, | |
156 | { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." }, | |
157 | { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." }, | |
158 | { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." }, | |
159 | { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." }, | |
160 | { "OSMSG_DEOP_DONE", "Deopped the requested lusers." }, | |
161 | { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." }, | |
55342ce8 | 162 | { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." }, |
163 | { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." }, | |
d76ed9a9 | 164 | { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." }, |
165 | { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." }, | |
166 | { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." }, | |
39c1a4ef | 167 | { "OSMSG_NOT_THERE", "You not in $b%s$b." }, |
d76ed9a9 | 168 | { "OSMSG_JOIN_DONE", "I have joined $b%s$b." }, |
d82cf2f0 | 169 | { "OSMSG_MARK_SET", "Set the MARK." }, |
c408f18a | 170 | { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." }, |
39c1a4ef | 171 | { "OSMSG_SVSPART_SENT", "Sent the SVSPART." }, |
d76ed9a9 | 172 | { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." }, |
173 | { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." }, | |
174 | { "OSMSG_KICKALL_DONE", "I have cleared out %s." }, | |
175 | { "OSMSG_LEAVING", "Leaving $b%s$b." }, | |
d82cf2f0 | 176 | { "OSMSG_MARK_INVALID", "Sorry, marks must contain only letters, numbers, and dashes ('-')." }, |
d76ed9a9 | 177 | { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." }, |
178 | { "OSMSG_OP_DONE", "Opped the requested lusers." }, | |
179 | { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." }, | |
55342ce8 | 180 | { "OSMSG_HOP_DONE", "Halfopped the requested lusers." }, |
181 | { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." }, | |
964a842d | 182 | { "OMSG_BAD_SVSNICK", "$b%s$b is an invalid nickname." }, |
183 | ||
37ef8ee3 | 184 | { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" }, |
21f6caee | 185 | { "OSMSG_WHOIS_NICK", "Nick : %s" }, |
186 | { "OSMSG_WHOIS_HOST", "Host : %s@%s" }, | |
187 | { "OSMSG_WHOIS_FAKEHOST", "Fakehost : %s" }, | |
188 | { "OSMSG_WHOIS_CRYPT_HOST", "Crypt Host : %s" }, | |
189 | { "OSMSG_WHOIS_CRYPT_IP", "Crypt IP : %s" }, | |
190 | { "OSMSG_WHOIS_IP", "Real IP : %s" }, | |
191 | { "OSMSG_WHOIS_COUNTRY", "Country : %s" }, | |
192 | { "OSMSG_WHOIS_COUNTRY_CODE","Country Code : %s" }, | |
193 | { "OSMSG_WHOIS_CITY", "City : %s" }, | |
194 | { "OSMSG_WHOIS_REGION", "Region/State : %s" }, | |
195 | { "OSMSG_WHOIS_POSTAL_CODE","Postal Code : %s" }, | |
196 | { "OSMSG_WHOIS_LATITUDE", "Latitude : %f" }, | |
197 | { "OSMSG_WHOIS_LONGITUDE", "Longitude : %f" }, | |
1ad7ac15 | 198 | { "OSMSG_WHOIS_MAP", "Map : %s" }, |
21f6caee | 199 | { "OSMSG_WHOIS_DMA_CODE", "DMA Code : %d" }, |
200 | { "OSMSG_WHOIS_AREA_CODE", "Area Code : %d" }, | |
201 | { "OSMSG_WHOIS_MODES", "Modes : +%s " }, | |
202 | { "OSMSG_WHOIS_INFO", "Info : %s" }, | |
203 | { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" }, | |
204 | { "OSMSG_WHOIS_SERVER", "Server : %s" }, | |
205 | { "OSMSG_WHOIS_NICK_AGE", "Nick Age : %s" }, | |
206 | { "OSMSG_WHOIS_ACCOUNT", "Account : %s" }, | |
89d871d8 | 207 | { "OSMSG_WHOIS_PRIVS", "IRCd Privs : %s" }, |
21f6caee | 208 | { "OSMSG_WHOIS_CHANNELS", "Channels : %s" }, |
37ef8ee3 | 209 | { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." }, |
0e08a8e0 | 210 | { "OSMSG_WHOIS_VERSION", "Version : %s" }, |
2c00fbc2 | 211 | { "OSMSG_WHOIS_MARK", "Mark : %s" }, |
da5b7dfc | 212 | { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" }, |
d76ed9a9 | 213 | { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." }, |
214 | { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." }, | |
215 | { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." }, | |
216 | { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." }, | |
217 | { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." }, | |
218 | { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." }, | |
219 | { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." }, | |
220 | { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." }, | |
221 | { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." }, | |
222 | { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." }, | |
223 | { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." }, | |
224 | { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." }, | |
225 | { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." }, | |
226 | { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." }, | |
227 | { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." }, | |
228 | { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." }, | |
229 | { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" }, | |
230 | { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" }, | |
231 | { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." }, | |
232 | { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." }, | |
233 | { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." }, | |
234 | { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." }, | |
235 | { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." }, | |
236 | { "OSMSG_BADWORD_LIST", "Bad words: %s" }, | |
237 | { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" }, | |
238 | { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." }, | |
d914d1cb | 239 | { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." }, |
d76ed9a9 | 240 | { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" }, |
241 | { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" }, | |
242 | { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" }, | |
243 | { "OSMSG_RESERVED_LIST", "List of reserved nicks:" }, | |
de9510bc | 244 | { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" }, |
245 | { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" }, | |
246 | { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" }, | |
247 | { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" }, | |
248 | { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" }, | |
249 | { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" }, | |
d76ed9a9 | 250 | { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." }, |
251 | { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" }, | |
252 | { "OSMSG_LINE_DUMPED", "Raw line sent." }, | |
253 | { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." }, | |
254 | { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." }, | |
255 | { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." }, | |
256 | { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." }, | |
257 | { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." }, | |
258 | { "OSMSG_ILLEGAL_REASON", "This channel is illegal." }, | |
259 | { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." }, | |
260 | { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." }, | |
261 | { "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." }, | |
262 | { "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." }, | |
263 | { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." }, | |
264 | { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." }, | |
265 | { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." }, | |
266 | { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." }, | |
267 | { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." }, | |
268 | { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." }, | |
269 | { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." }, | |
55342ce8 | 270 | { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." }, |
d76ed9a9 | 271 | { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." }, |
272 | { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." }, | |
273 | { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." }, | |
274 | { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." }, | |
275 | { "OSMSG_OPTION_ROOT", "The following keys can be queried:" }, | |
276 | { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" }, | |
277 | { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" }, | |
278 | { "OSMSG_OPTION_LIST_EMPTY", "Empty list." }, | |
279 | { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." }, | |
280 | { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." }, | |
281 | { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." }, | |
282 | { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." }, | |
283 | { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." }, | |
284 | { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" }, | |
de9510bc | 285 | { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" }, |
286 | { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" }, | |
8e11460f | 287 | { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" }, |
288 | { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" }, | |
d82cf2f0 | 289 | { "OSMSG_MARK_NO_MARK", "MARK action requires mark criteria (what do you want to mark them as?)" }, |
a62ba70c | 290 | { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" }, |
39c1a4ef | 291 | { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" }, |
d76ed9a9 | 292 | { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" }, |
293 | { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" }, | |
d914d1cb | 294 | { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" }, |
d76ed9a9 | 295 | { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" }, |
296 | { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." }, | |
d914d1cb | 297 | { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." }, |
0f6fe38c | 298 | { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" }, |
299 | { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" }, | |
d76ed9a9 | 300 | { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." }, |
301 | { "OSMSG_GAG_ADDED", "Gagged $b%s$b." }, | |
302 | { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." }, | |
303 | { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." }, | |
304 | { "OSMSG_NO_GAGS", "No gags have been set." }, | |
305 | { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." }, | |
306 | { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." }, | |
307 | { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." }, | |
308 | { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." }, | |
309 | { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." }, | |
310 | { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." }, | |
a62ba70c | 311 | { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" }, |
d76ed9a9 | 312 | { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." }, |
313 | { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." }, | |
eaf715f1 | 314 | { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" }, |
de9510bc | 315 | { "OSMSG_ALERTS_BAR", "----------------------------------------------" }, |
316 | { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" }, | |
317 | { "OSMSG_ALERTS_DESC", " Criteria: %s" }, | |
318 | { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" }, | |
319 | { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" }, | |
47956fc5 | 320 | /* routing messages */ |
5c6bff84 | 321 | { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" }, |
322 | { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" }, | |
47956fc5 | 323 | { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" }, |
5c6bff84 | 324 | { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" }, |
47956fc5 | 325 | { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" }, |
326 | { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." }, | |
327 | { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." }, | |
328 | { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." }, | |
329 | { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." }, | |
330 | { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" }, | |
5c6bff84 | 331 | { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" }, |
47956fc5 | 332 | { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" }, |
333 | { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." }, | |
ce9266cf | 334 | { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." }, |
47956fc5 | 335 | { "OSMSG_INVALID_PLAN", "That routing plan name is not valid." }, |
336 | { "OSMSG_PLAN_DELETED", "The routing plan was sucessfully deleted." }, | |
337 | { "OSMSG_PLAN_NOT_FOUND", "There is no routing plan called '%s'." }, | |
338 | { "OSMSG_PLAN_SERVER_ADDED", "Added %s to the routing plan." }, | |
339 | { "OSMSG_PLAN_SERVER_DELETED", "The server has been deleted." }, | |
340 | { "OSMSG_PLAN_SERVER_NOT_FOUND", "The server '%s' was not found in that routing plan." }, | |
341 | { "OSMSG_ROUTING_DISABLED", "Routing is now disabled." }, | |
342 | { "OSMSG_DOWNLINKS_FORMAT_A", "%s%s-$b%s$b [%s]" }, | |
343 | { "OSMSG_DOWNLINKS_FORMAT_B", "$b%s$b (me)" }, | |
344 | { "OSMSG_ROUTELIST_EMPTY", "No servers in route list" }, | |
345 | { "OSMSG_ROUTELIST_AS_PLANNED", "Routing plan: Servers as they SHOULD be linked" }, | |
346 | { "OSMSG_MAP_CENTERED", "map %s centered, Maxdepth:%d" }, | |
347 | { "OSMSG_NO_SERVERS_MISSING", "No servers are missing." }, | |
348 | { "OSMSG_CONNECTING_MISSING", "Attempted to connect %d missing servers." }, | |
349 | { "OSMSG_CONNECT", "->connect %s %d %s" }, | |
350 | { "OSMSG_SQUIT", "->squit %s" }, | |
351 | { "OSMSG_COULDNT_FIND_SERVER", "Couldnt find %s, so using %s to link %s" }, | |
352 | { "OSMSG_INSPECTING_SERVER", "Inspecting server [%s]" }, | |
353 | { "OSMSG_REROUTING_ACC_MAP", "Rerouting network according to loaded map.." }, | |
964abe6b | 354 | { "OSMSG_REROUTING_NOTCONFIGURED", "You have not configured routing. See $/msg $O help routing$b." }, |
47956fc5 | 355 | { "OSMSG_CONNECTING_MISSING_ONLY", "Connecting missing servers only.." }, |
356 | { "OSMSG_NO_ROUTING_NECESSARY", "No rerouting appears necessary." }, | |
357 | { "OSMSG_TESTING_REROUTE", "Testing Reroute(): Commands not sent to socket.." }, | |
358 | { "OSMSG_INVALID_DIRECTIVE", "Reroute(): Invalid directive %s", }, | |
359 | { "OSMSG_UPLINKS_MISSING", "%d servers' uplinks were missing, and were not connected." }, | |
360 | { "OSMSG_REROUTE_COMPLETE", "Reroute complete: Moved %d, connected %d, total %d changes." }, | |
361 | /* end of routing */ | |
d76ed9a9 | 362 | { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." }, |
363 | { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." }, | |
364 | { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." }, | |
365 | { "OSMSG_RECONNECTING", "Reconnecting to my uplink." }, | |
366 | { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." }, | |
367 | { "OSMSG_NAME_COLLIDE", "That name is already in use." }, | |
368 | { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." }, | |
369 | { "OSMSG_SERVER_JUPED", "Added new jupe server %s." }, | |
df5f6070 | 370 | { "OSMSG_INVALID_NUMERIC", "Invalid numeric" }, |
371 | { "OSMSG_INVALID_SERVERNAME", "Server name must contain a '.'." }, | |
d76ed9a9 | 372 | { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." }, |
373 | { "OSMSG_SERVER_UNJUPED", "Server jupe removed." }, | |
c52666c6 | 374 | /* |
d76ed9a9 | 375 | { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" }, |
376 | { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." }, | |
377 | { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" }, | |
378 | { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." }, | |
379 | { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" }, | |
380 | { "OSMSG_WARN_LISTENTRY", "%s (%s)" }, | |
381 | { "OSMSG_WARN_LISTEND", "End of activity warning list." }, | |
c52666c6 | 382 | */ |
d76ed9a9 | 383 | { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." }, |
384 | { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." }, | |
385 | { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." }, | |
386 | { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." }, | |
387 | { "OSMSG_UPLINK_START", "Uplink $b%s$b:" }, | |
388 | { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" }, | |
389 | { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." }, | |
d914d1cb | 390 | { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." }, |
d76ed9a9 | 391 | { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" }, |
392 | { "OSMSG_CHANINFO_HEADER", "%s Information" }, | |
393 | { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" }, | |
394 | { "OSMSG_CHANINFO_MODES", "Modes: %s" }, | |
395 | { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" }, | |
396 | { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" }, | |
397 | { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" }, | |
398 | { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" }, | |
399 | { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" }, | |
2aef5f4b | 400 | { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" }, |
401 | { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" }, | |
d76ed9a9 | 402 | { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" }, |
403 | { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" }, | |
404 | { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" }, | |
27eaa617 | 405 | { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" }, |
ec311f39 | 406 | { "OSMSG_TRACK_DISABLED", "Tracking is not currently compiled into X3" }, |
7637f48f | 407 | { "OSMSG_MAXUSERS_RESET", "Max clients has been reset to $b%d$b" }, |
08895577 | 408 | |
409 | { "OSMSG_DEFCON_INVALID", "DefCon level %d is invalid, please choose a value between 1 and 5" }, | |
410 | { "OSMSG_DEFCON_ALLOWING_ALL", "DefCon is at level 5 and allowing everything" }, | |
411 | { "OSMSG_DEFCON_DISALLOWING", "DefCon is at level %d and enforcing:" }, | |
412 | { "OSMSG_DEFCON_NO_NEW_CHANNELS", "No Channel Registrations" }, | |
413 | { "OSMSG_DEFCON_NO_NEW_NICKS", "No Nickname/Account Registrations" }, | |
414 | { "OSMSG_DEFCON_NO_MODE_CHANGE", "No Channel Mode Changes" }, | |
415 | { "OSMSG_DEFCON_NO_NEW_CLIENTS", "No New Clients" }, | |
416 | { "OSMSG_DEFCON_FORCE_CHANMODES", "Forcing Channel Mode(s): %s" }, | |
417 | { "OSMSG_DEFCON_REDUCE_SESSION", "Forcing Reduced Session: %d" }, | |
418 | { "OSMSG_DEFCON_OPER_ONLY", "Allowing Services Communication With Opers Only" }, | |
419 | { "OSMSG_DEFCON_SILENT_OPER_ONLY", "Allowing Services Communication With Opers Only AND Silently Ignoring Regular Users" }, | |
420 | { "OSMSG_DEFCON_GLINE_NEW_CLIENTS", "Glining New Clients" }, | |
0272358e | 421 | { "OSMSG_DEFCON_SHUN_NEW_CLIENTS", "Shunning New Clients" }, |
08895577 | 422 | { "OSMSG_DEFCON_NO_NEW_MEMOS", "Disallowing New Memos" }, |
423 | ||
6c34bb5a | 424 | { "OSMSG_PRIV_UNKNOWN", "Unknown privilege flag %s, see /msg $O HELP PRIVFLAGS for a flag list" }, |
425 | { "OSMSG_PRIV_SET", "Privilege flag %s has been %sset" }, | |
426 | ||
d76ed9a9 | 427 | { NULL, NULL } |
428 | }; | |
429 | ||
b1bf690d | 430 | #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd) |
d76ed9a9 | 431 | |
08895577 | 432 | int DefConLevel = 5; |
433 | int DefCon[6]; | |
434 | int DefConTimeOut; | |
435 | int GlobalOnDefcon = 0; | |
436 | int GlobalOnDefconMore = 0; | |
437 | int DefConGlineExpire; | |
438 | int DefConModesSet = 0; | |
08895577 | 439 | unsigned int DefConSessionLimit; |
440 | char *DefConChanModes; | |
441 | char *DefConGlineReason; | |
442 | char *DefConMessage; | |
443 | char *DefConOffMessage; | |
444 | ||
ec311f39 | 445 | extern void add_track_user(struct userNode *user); |
d76ed9a9 | 446 | typedef int (*discrim_search_func)(struct userNode *match, void *extra); |
447 | ||
448 | struct userNode *opserv; | |
258d1427 | 449 | static struct service *opserv_service; |
d76ed9a9 | 450 | |
de9510bc | 451 | /*static dict_t opserv_chan_warn; */ /* data is char* */ |
d76ed9a9 | 452 | static dict_t opserv_reserved_nick_dict; /* data is struct userNode* */ |
453 | static struct string_list *opserv_bad_words; | |
454 | static dict_t opserv_exempt_channels; /* data is not used */ | |
455 | static dict_t opserv_trusted_hosts; /* data is struct trusted_host* */ | |
47956fc5 | 456 | static dict_t opserv_routing_plans; /* data is struct routingPlan */ |
457 | static dict_t opserv_routing_plan_options; /* data is a dict_t key->val list*/ | |
458 | static dict_t opserv_waiting_connections; /* data is struct waitingConnection */ | |
d76ed9a9 | 459 | static dict_t opserv_hostinfo_dict; /* data is struct opserv_hostinfo* */ |
460 | static dict_t opserv_user_alerts; /* data is struct opserv_user_alert* */ | |
461 | static dict_t opserv_nick_based_alerts; /* data is struct opserv_user_alert* */ | |
462 | static dict_t opserv_channel_alerts; /* data is struct opserv_user_alert* */ | |
463 | static struct module *opserv_module; | |
464 | static struct log_type *OS_LOG; | |
465 | static unsigned int new_user_flood; | |
466 | static char *level_strings[1001]; | |
7637f48f | 467 | struct string_list *autojoin_channels; |
47956fc5 | 468 | struct route *opserv_route = NULL; /* Main active routing table from activate_routing()*/ |
d76ed9a9 | 469 | |
470 | static struct { | |
471 | struct chanNode *debug_channel; | |
472 | struct chanNode *alert_channel; | |
473 | struct chanNode *staff_auth_channel; | |
474 | struct policer_params *join_policer_params; | |
475 | struct policer new_user_policer; | |
476 | unsigned long untrusted_max; | |
477 | unsigned long clone_gline_duration; | |
478 | unsigned long block_gline_duration; | |
d914d1cb | 479 | unsigned long block_shun_duration; |
d76ed9a9 | 480 | unsigned long purge_lock_delay; |
481 | unsigned long join_flood_moderate; | |
482 | unsigned long join_flood_moderate_threshold; | |
5a1daaab | 483 | unsigned long admin_level; |
1c5f6697 | 484 | unsigned long silent_level; |
d76ed9a9 | 485 | } opserv_conf; |
486 | ||
487 | struct trusted_host { | |
488 | char *ipaddr; | |
489 | char *issuer; | |
490 | char *reason; | |
491 | unsigned long limit; | |
492 | time_t issued; | |
493 | time_t expires; | |
494 | }; | |
495 | ||
496 | struct gag_entry { | |
497 | char *mask; | |
498 | char *owner; | |
499 | char *reason; | |
500 | time_t expires; | |
501 | struct gag_entry *next; | |
502 | }; | |
503 | ||
504 | static struct gag_entry *gagList; | |
505 | ||
506 | struct opserv_hostinfo { | |
507 | struct userList clients; | |
508 | struct trusted_host *trusted; | |
509 | }; | |
510 | ||
511 | static void | |
512 | opserv_free_hostinfo(void *data) | |
513 | { | |
514 | struct opserv_hostinfo *ohi = data; | |
515 | userList_clean(&ohi->clients); | |
516 | free(ohi); | |
517 | } | |
518 | ||
47956fc5 | 519 | static void |
520 | opserv_free_waiting_connection(void *data) | |
521 | { | |
522 | struct waitingConnection *wc = data; | |
523 | free(wc->server); | |
524 | free(wc->target); | |
525 | free(wc); | |
526 | } | |
527 | ||
d76ed9a9 | 528 | typedef struct opservDiscrim { |
0f6fe38c | 529 | struct chanNode *channel; |
530 | char *mask_nick, *mask_ident, *mask_host, *mask_info, *mask_version, *server, *reason, *accountmask, *chantarget, *mark, *mask_mark; | |
2f61d1d7 | 531 | irc_in_addr_t ip_mask; |
532 | unsigned long limit; | |
533 | time_t min_ts, max_ts; | |
0e08a8e0 | 534 | regex_t regex_nick, regex_ident, regex_host, regex_info, regex_version; |
535 | unsigned int has_regex_nick : 1, has_regex_ident : 1, has_regex_host : 1, has_regex_info : 1, has_regex_version : 1; | |
d76ed9a9 | 536 | unsigned int min_level, max_level, domain_depth, duration, min_clones, min_channels, max_channels; |
2f61d1d7 | 537 | unsigned char ip_mask_bits; |
0f6fe38c | 538 | unsigned int match_opers : 1, option_log : 1; |
539 | unsigned int chan_req_modes : 2, chan_no_modes : 2; | |
d76ed9a9 | 540 | int authed : 2, info_space : 2; |
63665495 | 541 | unsigned int intra_scmp : 2, intra_dcmp : 2; |
27eaa617 | 542 | unsigned int use_regex : 1; |
1c5f6697 | 543 | unsigned int silent : 1; |
5aa400d2 | 544 | unsigned int checkrestrictions : 2; |
d76ed9a9 | 545 | } *discrim_t; |
546 | ||
547 | struct discrim_and_source { | |
548 | discrim_t discrim; | |
549 | struct userNode *source; | |
258d1427 | 550 | struct userNode *destination; |
d76ed9a9 | 551 | dict_t dict; |
552 | unsigned int disp_limit; | |
553 | }; | |
554 | ||
258d1427 | 555 | static discrim_t opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[], int allow_channel); |
d76ed9a9 | 556 | static unsigned int opserv_discrim_search(discrim_t discrim, discrim_search_func dsf, void *data); |
557 | static int gag_helper_func(struct userNode *match, void *extra); | |
558 | static int ungag_helper_func(struct userNode *match, void *extra); | |
559 | ||
560 | typedef enum { | |
561 | REACT_NOTICE, | |
562 | REACT_KILL, | |
d914d1cb | 563 | REACT_GLINE, |
ec311f39 | 564 | REACT_TRACK, |
c408f18a | 565 | REACT_SHUN, |
0e08a8e0 | 566 | REACT_SVSJOIN, |
39c1a4ef | 567 | REACT_SVSPART, |
d82cf2f0 | 568 | REACT_VERSION, |
569 | REACT_MARK | |
d76ed9a9 | 570 | } opserv_alert_reaction; |
571 | ||
572 | struct opserv_user_alert { | |
573 | char *owner; | |
574 | char *text_discrim, *split_discrim; | |
575 | discrim_t discrim; | |
576 | opserv_alert_reaction reaction; | |
577 | }; | |
578 | ||
579 | /* funny type to make it acceptible to dict_set_free_data, far below */ | |
580 | static void | |
581 | opserv_free_user_alert(void *data) | |
582 | { | |
583 | struct opserv_user_alert *alert = data; | |
0f6fe38c | 584 | if (alert->discrim->channel) |
585 | UnlockChannel(alert->discrim->channel); | |
d76ed9a9 | 586 | free(alert->owner); |
587 | free(alert->text_discrim); | |
588 | free(alert->split_discrim); | |
27eaa617 | 589 | if(alert->discrim->has_regex_nick) |
590 | regfree(&alert->discrim->regex_nick); | |
591 | if(alert->discrim->has_regex_ident) | |
592 | regfree(&alert->discrim->regex_ident); | |
593 | if(alert->discrim->has_regex_host) | |
594 | regfree(&alert->discrim->regex_host); | |
595 | if(alert->discrim->has_regex_info) | |
596 | regfree(&alert->discrim->regex_info); | |
0e08a8e0 | 597 | if(alert->discrim->has_regex_version) |
598 | regfree(&alert->discrim->regex_version); | |
d76ed9a9 | 599 | free(alert->discrim->reason); |
600 | free(alert->discrim); | |
601 | free(alert); | |
602 | } | |
603 | ||
604 | #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0) | |
605 | #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0) | |
606 | ||
7637f48f | 607 | |
08895577 | 608 | char *defconReverseModes(const char *modes) |
609 | { | |
610 | char *newmodes = NULL; | |
611 | unsigned int i = 0; | |
612 | if (!modes) { | |
613 | return NULL; | |
614 | } | |
615 | if (!(newmodes = malloc(sizeof(char) * strlen(modes) + 1))) { | |
616 | return NULL; | |
617 | } | |
618 | for (i = 0; i < strlen(modes); i++) { | |
619 | if (modes[i] == '+') | |
620 | newmodes[i] = '-'; | |
621 | else if (modes[i] == '-') | |
622 | newmodes[i] = '+'; | |
623 | else | |
624 | newmodes[i] = modes[i]; | |
625 | } | |
626 | newmodes[i] = '\0'; | |
627 | return newmodes; | |
628 | } | |
629 | ||
630 | int checkDefCon(int level) | |
631 | { | |
632 | return DefCon[DefConLevel] & level; | |
633 | } | |
634 | ||
635 | void showDefConSettings(struct userNode *user, struct svccmd *cmd) | |
636 | { | |
637 | if (DefConLevel == 5) { | |
638 | reply("OSMSG_DEFCON_ALLOWING_ALL"); | |
639 | return; | |
640 | } else | |
641 | reply("OSMSG_DEFCON_DISALLOWING", DefConLevel); | |
642 | ||
643 | if (checkDefCon(DEFCON_NO_NEW_CHANNELS)) | |
644 | reply("OSMSG_DEFCON_NO_NEW_CHANNELS"); | |
645 | ||
646 | if (checkDefCon(DEFCON_NO_NEW_NICKS)) | |
647 | reply("OSMSG_DEFCON_NO_NEW_NICKS"); | |
648 | ||
649 | if (checkDefCon(DEFCON_NO_MODE_CHANGE)) | |
650 | reply("OSMSG_DEFCON_NO_MODE_CHANGE"); | |
651 | ||
652 | if (checkDefCon(DEFCON_FORCE_CHAN_MODES) && (DefConChanModes)) | |
653 | reply("OSMSG_DEFCON_FORCE_CHANMODES", DefConChanModes); | |
654 | ||
655 | if (checkDefCon(DEFCON_REDUCE_SESSION)) | |
656 | reply("OSMSG_DEFCON_REDUCE_SESSION", DefConSessionLimit); | |
657 | ||
658 | if (checkDefCon(DEFCON_NO_NEW_CLIENTS)) | |
659 | reply("OSMSG_DEFCON_NO_NEW_CLIENTS"); | |
660 | ||
661 | if (checkDefCon(DEFCON_OPER_ONLY)) | |
662 | reply("OSMSG_DEFCON_OPER_ONLY"); | |
663 | ||
664 | if (checkDefCon(DEFCON_SILENT_OPER_ONLY)) | |
665 | reply("OSMSG_DEFCON_SILENT_OPER_ONLY"); | |
666 | ||
667 | if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS)) | |
668 | reply("OSMSG_DEFCON_GLINE_NEW_CLIENTS"); | |
669 | ||
0272358e | 670 | if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS)) |
671 | reply("OSMSG_DEFCON_SHUN_NEW_CLIENTS"); | |
672 | ||
08895577 | 673 | if (checkDefCon(DEFCON_NO_NEW_MEMOS)) |
674 | reply("OSMSG_DEFCON_NO_NEW_MEMOS"); | |
675 | ||
676 | return; | |
677 | } | |
678 | ||
679 | void do_mass_mode(char *modes) | |
680 | { | |
681 | dict_iterator_t it; | |
682 | ||
683 | if (!modes) | |
684 | return; | |
685 | ||
686 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
687 | struct chanNode *chan = iter_data(it); | |
688 | ||
689 | irc_mode(opserv, chan, modes); | |
690 | } | |
691 | ||
692 | } | |
693 | ||
694 | void DefConProcess(struct userNode *user) | |
695 | { | |
696 | char *newmodes; | |
08895577 | 697 | |
985d4109 | 698 | if (GlobalOnDefcon) |
699 | global_message_args(MESSAGE_RECIPIENT_LUSERS, "DEFCON_NETWORK_CHANGED", DefConLevel); | |
08895577 | 700 | |
985d4109 | 701 | if (GlobalOnDefconMore && GlobalOnDefcon) |
702 | global_message(MESSAGE_RECIPIENT_LUSERS, DefConMessage); | |
08895577 | 703 | |
704 | if ((DefConLevel == 5) && !GlobalOnDefconMore && !GlobalOnDefcon) | |
985d4109 | 705 | global_message(MESSAGE_RECIPIENT_LUSERS, DefConOffMessage); |
08895577 | 706 | |
985d4109 | 707 | if (user) |
708 | global_message_args(MESSAGE_RECIPIENT_OPERS, "DEFCON_OPER_LEVEL_CHANGE", user->nick, DefConLevel); | |
709 | else | |
710 | global_message_args(MESSAGE_RECIPIENT_OPERS, "DEFCON_TIMEOUT_LEVEL_CHANGE", DefConLevel); | |
08895577 | 711 | |
712 | if (checkDefCon(DEFCON_FORCE_CHAN_MODES)) { | |
713 | if (DefConChanModes && !DefConModesSet) { | |
714 | if (DefConChanModes[0] == '+' || DefConChanModes[0] == '-') { | |
715 | do_mass_mode(DefConChanModes); | |
716 | DefConModesSet = 1; | |
717 | } | |
718 | } | |
719 | } else { | |
720 | if (DefConChanModes && (DefConModesSet != 0)) { | |
721 | if (DefConChanModes[0] == '+' || DefConChanModes[0] == '-') { | |
722 | if ((newmodes = defconReverseModes(DefConChanModes))) { | |
723 | do_mass_mode(newmodes); | |
724 | free(newmodes); | |
725 | } | |
726 | DefConModesSet = 0; | |
727 | } | |
728 | } | |
729 | } | |
730 | ||
731 | return; | |
732 | } | |
733 | ||
734 | void | |
735 | defcon_timeout(UNUSED_ARG(void *data)) | |
736 | { | |
737 | DefConLevel = 5; | |
738 | DefConProcess(NULL); | |
739 | } | |
740 | ||
741 | static MODCMD_FUNC(cmd_defcon) | |
742 | { | |
743 | if ((argc < 2) || (atoi(argv[1]) == DefConLevel)) { | |
744 | showDefConSettings(user, cmd); | |
745 | return 1; | |
746 | } | |
747 | ||
748 | if ((atoi(argv[1]) < 1) || (atoi(argv[1]) > 5)) { | |
749 | reply("OSMSG_DEFCON_INVALID", atoi(argv[1])); | |
750 | return 0; | |
751 | } | |
752 | ||
753 | DefConLevel = atoi(argv[1]); | |
754 | showDefConSettings(user, cmd); | |
755 | ||
756 | if (DefConTimeOut > 0) { | |
9079d26c | 757 | timeq_del(0, defcon_timeout, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); |
08895577 | 758 | timeq_add(now + DefConTimeOut, defcon_timeout, NULL); |
759 | } | |
760 | ||
761 | DefConProcess(user); | |
762 | return 1; | |
763 | } | |
764 | ||
6c34bb5a | 765 | /* TODO |
766 | static MODCMD_FUNC(cmd_privallow) | |
767 | { | |
768 | //privallow servername/username +/-flag (global is set in conf) | |
769 | } | |
770 | ||
771 | static MODCMD_FUNC(cmd_privdissallow) | |
772 | { | |
773 | //privdisallow servername/username +/-flag (global is set in conf) | |
774 | } | |
775 | ||
776 | static MODCMD_FUNC(cmd_privlist) | |
777 | { | |
778 | //privlist servername/user (global with none) | |
779 | } | |
780 | */ | |
781 | ||
782 | static MODCMD_FUNC(cmd_privset) | |
783 | { | |
784 | struct userNode *target; | |
785 | char *flag; | |
786 | int add = PRIV_ADD; | |
787 | ||
788 | flag = argv[2]; | |
789 | if (*flag == '-') { | |
790 | add = PRIV_DEL; | |
791 | flag++; | |
792 | } else if (*flag == '+') { | |
793 | add = PRIV_ADD; | |
794 | flag++; | |
795 | } | |
796 | ||
797 | target = GetUserH(argv[1]); | |
798 | if (!target) { | |
799 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
800 | return 0; | |
801 | } | |
802 | ||
803 | if (check_priv(flag)) { | |
804 | irc_privs(target, flag, add); | |
805 | reply("OSMSG_PRIV_SET", argv[2], (add == 1) ? "" : "un"); | |
806 | } else { | |
807 | reply("OSMSG_PRIV_UNKNOWN", argv[2]); | |
808 | return 0; | |
809 | } | |
810 | ||
811 | return 1; | |
812 | } | |
813 | ||
d76ed9a9 | 814 | /* A lot of these commands are very similar to what ChanServ can do, |
815 | * but OpServ can do them even on channels that aren't registered. | |
816 | */ | |
817 | ||
818 | static MODCMD_FUNC(cmd_access) | |
819 | { | |
820 | struct handle_info *hi; | |
821 | const char *target; | |
822 | unsigned int res; | |
823 | ||
824 | target = (argc > 1) ? (const char*)argv[1] : user->nick; | |
825 | if (!irccasecmp(target, "*")) { | |
826 | nickserv_show_oper_accounts(user, cmd); | |
827 | return 1; | |
828 | } | |
829 | if (!(hi = modcmd_get_handle_info(user, target))) | |
830 | return 0; | |
258d1427 | 831 | res = (argc > 2) ? oper_try_set_access(user, opserv_service->bot, hi, strtoul(argv[2], NULL, 0)) : 0; |
d76ed9a9 | 832 | reply("OSMSG_USER_ACCESS_IS", target, hi->handle, hi->opserv_level); |
833 | return res; | |
834 | } | |
835 | ||
836 | static MODCMD_FUNC(cmd_ban) | |
837 | { | |
838 | struct mod_chanmode change; | |
839 | struct userNode *victim; | |
840 | ||
841 | mod_chanmode_init(&change); | |
842 | change.argc = 1; | |
843 | change.args[0].mode = MODE_BAN; | |
844 | if (is_ircmask(argv[1])) | |
a32da4c7 | 845 | change.args[0].u.hostmask = strdup(argv[1]); |
d76ed9a9 | 846 | else if ((victim = GetUserH(argv[1]))) |
a32da4c7 | 847 | change.args[0].u.hostmask = generate_hostmask(victim, 0); |
d76ed9a9 | 848 | else { |
258d1427 | 849 | reply("OSMSG_INVALID_IRCMASK", argv[1]); |
850 | return 0; | |
d76ed9a9 | 851 | } |
852 | modcmd_chanmode_announce(&change); | |
a32da4c7 | 853 | reply("OSMSG_ADDED_BAN", change.args[0].u.hostmask, channel->name); |
854 | free((char*)change.args[0].u.hostmask); | |
d76ed9a9 | 855 | return 1; |
856 | } | |
857 | ||
858 | static MODCMD_FUNC(cmd_chaninfo) | |
859 | { | |
860 | char buffer[MAXLEN]; | |
861 | const char *fmt; | |
862 | struct banNode *ban; | |
2aef5f4b | 863 | struct exemptNode *exempt; |
d76ed9a9 | 864 | struct modeNode *moden; |
865 | unsigned int n; | |
866 | ||
867 | reply("OSMSG_CHANINFO_HEADER", channel->name); | |
868 | fmt = user_find_message(user, "OSMSG_CHANINFO_TIMESTAMP"); | |
869 | strftime(buffer, sizeof(buffer), fmt, gmtime(&channel->timestamp)); | |
870 | send_message_type(4, user, cmd->parent->bot, "%s", buffer); | |
871 | irc_make_chanmode(channel, buffer); | |
872 | if (channel->bad_channel) | |
873 | reply("OSMSG_CHANINFO_MODES_BADWORD", buffer); | |
874 | else | |
875 | reply("OSMSG_CHANINFO_MODES", buffer); | |
876 | if (channel->topic_time) { | |
877 | fmt = user_find_message(user, "OSMSG_CHANINFO_TOPIC"); | |
878 | strftime(buffer, sizeof(buffer), fmt, gmtime(&channel->topic_time)); | |
879 | send_message_type(4, user, cmd->parent->bot, buffer, channel->topic_nick, channel->topic); | |
880 | } else { | |
258d1427 | 881 | irc_fetchtopic(cmd->parent->bot, channel->name); |
882 | reply("OSMSG_CHANINFO_TOPIC_UNKNOWN"); | |
d76ed9a9 | 883 | } |
884 | if (channel->banlist.used) { | |
258d1427 | 885 | reply("OSMSG_CHANINFO_BAN_COUNT", channel->banlist.used); |
d76ed9a9 | 886 | fmt = user_find_message(user, "OSMSG_CHANINFO_BAN"); |
258d1427 | 887 | for (n = 0; n < channel->banlist.used; n++) { |
888 | ban = channel->banlist.list[n]; | |
889 | strftime(buffer, sizeof(buffer), fmt, localtime(&ban->set)); | |
890 | send_message_type(4, user, cmd->parent->bot, buffer, ban->ban, ban->who); | |
891 | } | |
d76ed9a9 | 892 | } |
2aef5f4b | 893 | if (channel->exemptlist.used) { |
894 | reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel->exemptlist.used); | |
895 | fmt = user_find_message(user, "OSMSG_CHANINFO_EXEMPT"); | |
896 | for (n = 0; n < channel->exemptlist.used; n++) { | |
897 | exempt = channel->exemptlist.list[n]; | |
898 | strftime(buffer, sizeof(buffer), fmt, localtime(&exempt->set)); | |
899 | send_message_type(4, user, cmd->parent->bot, buffer, exempt->exempt, exempt->who); | |
900 | } | |
901 | } | |
d76ed9a9 | 902 | if ((argc < 2) && (channel->members.used >= 50)) { |
903 | /* early out unless they ask for users */ | |
904 | reply("OSMSG_CHANINFO_MANY_USERS", channel->members.used, argv[0], channel->name); | |
905 | return 1; | |
906 | } | |
907 | reply("OSMSG_CHANINFO_USER_COUNT", channel->members.used); | |
908 | for (n=0; n<channel->members.used; n++) { | |
258d1427 | 909 | moden = channel->members.list[n]; |
2f61d1d7 | 910 | if (moden->modes & MODE_CHANOP) { |
911 | if (moden->oplevel >= 0) | |
912 | send_message_type(4, user, cmd->parent->bot, " @%s:%d (%s@%s)", moden->user->nick, moden->oplevel, moden->user->ident, moden->user->hostname); | |
913 | else | |
914 | send_message_type(4, user, cmd->parent->bot, " @%s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); | |
915 | } | |
d76ed9a9 | 916 | } |
55342ce8 | 917 | for (n=0; n<channel->members.used; n++) { |
918 | moden = channel->members.list[n]; | |
919 | if ((moden->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) == MODE_HALFOP) | |
920 | send_message_type(4, user, cmd->parent->bot, " %s%s (%s@%s)", "%", moden->user->nick, moden->user->ident, moden->user->hostname); | |
921 | } | |
d76ed9a9 | 922 | for (n=0; n<channel->members.used; n++) { |
258d1427 | 923 | moden = channel->members.list[n]; |
924 | if ((moden->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) == MODE_VOICE) | |
d76ed9a9 | 925 | send_message_type(4, user, cmd->parent->bot, " +%s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); |
926 | } | |
927 | for (n=0; n<channel->members.used; n++) { | |
258d1427 | 928 | moden = channel->members.list[n]; |
929 | if ((moden->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) == 0) | |
d76ed9a9 | 930 | send_message_type(4, user, cmd->parent->bot, " %s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); |
931 | } | |
932 | return 1; | |
933 | } | |
934 | ||
de9510bc | 935 | /* This command has been replaced by 'alert notice channel #foo' */ |
936 | /* | |
2f61d1d7 | 937 | static MODCMD_FUNC(cmd_warn) |
d76ed9a9 | 938 | { |
939 | char *reason, *message; | |
940 | ||
941 | if (!IsChannelName(argv[1])) { | |
258d1427 | 942 | reply("OSMSG_NEED_CHANNEL", argv[0]); |
943 | return 0; | |
d76ed9a9 | 944 | } |
945 | reason = dict_find(opserv_chan_warn, argv[1], NULL); | |
946 | if (reason) { | |
947 | reply("OSMSG_WARN_EXISTS", argv[1]); | |
948 | return 0; | |
949 | } | |
950 | if (argv[2]) | |
951 | reason = strdup(unsplit_string(argv+2, argc-2, NULL)); | |
952 | else | |
953 | reason = strdup("No reason"); | |
954 | dict_insert(opserv_chan_warn, strdup(argv[1]), reason); | |
955 | reply("OSMSG_WARN_ADDED", argv[1], reason); | |
956 | if (dict_find(channels, argv[1], NULL)) { | |
57692f5e | 957 | global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN" argv[1], reason); |
d76ed9a9 | 958 | } |
959 | return 1; | |
960 | } | |
961 | ||
962 | static MODCMD_FUNC(cmd_unwarn) | |
963 | { | |
964 | if ((argc < 2) || !IsChannelName(argv[1])) { | |
965 | reply("OSMSG_NEED_CHANNEL", argv[0]); | |
258d1427 | 966 | return 0; |
d76ed9a9 | 967 | } |
968 | if (!dict_remove(opserv_chan_warn, argv[1])) { | |
969 | reply("OSMSG_WARN_NOEXIST", argv[1]); | |
970 | return 0; | |
971 | } | |
972 | reply("OSMSG_WARN_DELETED", argv[1]); | |
973 | return 1; | |
974 | } | |
de9510bc | 975 | */ |
d76ed9a9 | 976 | |
977 | static MODCMD_FUNC(cmd_clearbans) | |
978 | { | |
979 | struct mod_chanmode *change; | |
980 | unsigned int ii; | |
981 | ||
982 | change = mod_chanmode_alloc(channel->banlist.used); | |
983 | for (ii=0; ii<channel->banlist.used; ii++) { | |
984 | change->args[ii].mode = MODE_REMOVE | MODE_BAN; | |
ec1a68c8 | 985 | change->args[ii].u.hostmask = strdup(channel->banlist.list[ii]->ban); |
d76ed9a9 | 986 | } |
987 | modcmd_chanmode_announce(change); | |
ec1a68c8 | 988 | for (ii=0; ii<change->argc; ++ii) |
989 | free((char*)change->args[ii].u.hostmask); | |
d76ed9a9 | 990 | mod_chanmode_free(change); |
991 | reply("OSMSG_CLEARBANS_DONE", channel->name); | |
992 | return 1; | |
993 | } | |
994 | ||
995 | static MODCMD_FUNC(cmd_clearmodes) | |
996 | { | |
997 | struct mod_chanmode change; | |
998 | ||
999 | if (!channel->modes) { | |
258d1427 | 1000 | reply("OSMSG_NO_CHANNEL_MODES", channel->name); |
d76ed9a9 | 1001 | return 0; |
1002 | } | |
1003 | mod_chanmode_init(&change); | |
1004 | change.modes_clear = channel->modes; | |
1005 | modcmd_chanmode_announce(&change); | |
1006 | reply("OSMSG_CLEARMODES_DONE", channel->name); | |
1007 | return 1; | |
1008 | } | |
1009 | ||
1010 | static MODCMD_FUNC(cmd_deop) | |
1011 | { | |
1012 | struct mod_chanmode *change; | |
1013 | unsigned int arg, count; | |
1014 | ||
1015 | change = mod_chanmode_alloc(argc-1); | |
1016 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
1017 | struct userNode *victim = GetUserH(argv[arg]); | |
1018 | struct modeNode *mn; | |
258d1427 | 1019 | if (!victim || IsService(victim) |
d76ed9a9 | 1020 | || !(mn = GetUserMode(channel, victim)) |
1021 | || !(mn->modes & MODE_CHANOP)) | |
1022 | continue; | |
1023 | change->args[count].mode = MODE_REMOVE | MODE_CHANOP; | |
a32da4c7 | 1024 | change->args[count++].u.member = mn; |
d76ed9a9 | 1025 | } |
1026 | if (count) { | |
1027 | change->argc = count; | |
1028 | modcmd_chanmode_announce(change); | |
1029 | } | |
1030 | mod_chanmode_free(change); | |
1031 | reply("OSMSG_DEOP_DONE"); | |
1032 | return 1; | |
1033 | } | |
1034 | ||
55342ce8 | 1035 | static MODCMD_FUNC(cmd_dehop) |
1036 | { | |
1037 | struct mod_chanmode *change; | |
1038 | unsigned int arg, count; | |
1039 | ||
1040 | change = mod_chanmode_alloc(argc-1); | |
1041 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
1042 | struct userNode *victim = GetUserH(argv[arg]); | |
1043 | struct modeNode *mn; | |
1044 | if (!victim || IsService(victim) | |
1045 | || !(mn = GetUserMode(channel, victim)) | |
1046 | || !(mn->modes & MODE_HALFOP)) | |
1047 | continue; | |
1048 | change->args[count].mode = MODE_REMOVE | MODE_HALFOP; | |
11408ce4 | 1049 | change->args[count++].u.member = mn; |
55342ce8 | 1050 | } |
1051 | if (count) { | |
1052 | change->argc = count; | |
1053 | modcmd_chanmode_announce(change); | |
1054 | } | |
1055 | mod_chanmode_free(change); | |
1056 | reply("OSMSG_DEHOP_DONE"); | |
1057 | return 1; | |
1058 | } | |
1059 | ||
d76ed9a9 | 1060 | static MODCMD_FUNC(cmd_deopall) |
1061 | { | |
1062 | struct mod_chanmode *change; | |
1063 | unsigned int ii, count; | |
1064 | ||
1065 | change = mod_chanmode_alloc(channel->members.used); | |
1066 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 | 1067 | struct modeNode *mn = channel->members.list[ii]; |
1068 | if (IsService(mn->user) || !(mn->modes & MODE_CHANOP)) | |
d76ed9a9 | 1069 | continue; |
1070 | change->args[count].mode = MODE_REMOVE | MODE_CHANOP; | |
a32da4c7 | 1071 | change->args[count++].u.member = mn; |
d76ed9a9 | 1072 | } |
1073 | if (count) { | |
1074 | change->argc = count; | |
1075 | modcmd_chanmode_announce(change); | |
1076 | } | |
1077 | mod_chanmode_free(change); | |
1078 | reply("OSMSG_DEOPALL_DONE", channel->name); | |
1079 | return 1; | |
1080 | } | |
1081 | ||
55342ce8 | 1082 | static MODCMD_FUNC(cmd_dehopall) |
1083 | { | |
1084 | struct mod_chanmode *change; | |
1085 | unsigned int ii, count; | |
1086 | ||
1087 | change = mod_chanmode_alloc(channel->members.used); | |
1088 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
1089 | struct modeNode *mn = channel->members.list[ii]; | |
1090 | if (IsService(mn->user) || !(mn->modes & MODE_HALFOP)) | |
1091 | continue; | |
1092 | change->args[count].mode = MODE_REMOVE | MODE_HALFOP; | |
11408ce4 | 1093 | change->args[count++].u.member = mn; |
55342ce8 | 1094 | } |
1095 | if (count) { | |
1096 | change->argc = count; | |
1097 | modcmd_chanmode_announce(change); | |
1098 | } | |
1099 | mod_chanmode_free(change); | |
1100 | reply("OSMSG_DEHOPALL_DONE", channel->name); | |
1101 | return 1; | |
1102 | } | |
1103 | ||
7637f48f | 1104 | static MODCMD_FUNC(cmd_resetmax) |
1105 | { | |
1106 | max_clients = dict_size(clients); | |
1107 | max_clients_time = now; | |
1108 | reply("OSMSG_MAXUSERS_RESET", max_clients); | |
1109 | return 1; | |
1110 | } | |
1111 | ||
d76ed9a9 | 1112 | static MODCMD_FUNC(cmd_rehash) |
1113 | { | |
1114 | extern char *services_config; | |
1115 | ||
1116 | if (conf_read(services_config)) | |
258d1427 | 1117 | reply("OSMSG_REHASH_COMPLETE"); |
d76ed9a9 | 1118 | else |
258d1427 | 1119 | reply("OSMSG_REHASH_FAILED"); |
d76ed9a9 | 1120 | return 1; |
1121 | } | |
1122 | ||
1123 | static MODCMD_FUNC(cmd_reopen) | |
1124 | { | |
1125 | log_reopen(); | |
1126 | reply("OSMSG_REOPEN_COMPLETE"); | |
1127 | return 1; | |
1128 | } | |
1129 | ||
1130 | static MODCMD_FUNC(cmd_reconnect) | |
1131 | { | |
1132 | reply("OSMSG_RECONNECTING"); | |
1133 | irc_squit(self, "Reconnecting.", NULL); | |
1134 | return 1; | |
1135 | } | |
1136 | ||
1137 | static MODCMD_FUNC(cmd_jupe) | |
1138 | { | |
1139 | extern int force_n2k; | |
1140 | struct server *newsrv; | |
1141 | unsigned int num; | |
1142 | char numeric[COMBO_NUMERIC_LEN+1], srvdesc[SERVERDESCRIPTMAX+1]; | |
1143 | ||
1144 | num = atoi(argv[2]); | |
df5f6070 | 1145 | if(num == 0) { |
1146 | reply("OSMSG_INVALID_NUMERIC"); | |
1147 | return 0; | |
1148 | } | |
d76ed9a9 | 1149 | if ((num < 64) && !force_n2k) { |
1150 | inttobase64(numeric, num, 1); | |
1151 | inttobase64(numeric+1, 64*64-1, 2); | |
1152 | } else { | |
1153 | inttobase64(numeric, num, 2); | |
1154 | inttobase64(numeric+2, 64*64*64-1, 3); | |
1155 | } | |
1156 | #ifdef WITH_PROTOCOL_P10 | |
1157 | if (GetServerN(numeric)) { | |
1158 | reply("OSMSG_NUMERIC_COLLIDE", num, numeric); | |
1159 | return 0; | |
1160 | } | |
1161 | #endif | |
1162 | if (GetServerH(argv[1])) { | |
1163 | reply("OSMSG_NAME_COLLIDE"); | |
1164 | return 0; | |
1165 | } | |
1166 | snprintf(srvdesc, sizeof(srvdesc), "JUPE %s", unsplit_string(argv+3, argc-3, NULL)); | |
df5f6070 | 1167 | if(!strchr(argv[1], '.')) { |
1168 | reply("OSMSG_INVALID_SERVERNAME"); | |
1169 | return 0; | |
1170 | } | |
d76ed9a9 | 1171 | newsrv = AddServer(self, argv[1], 1, now, now, numeric, srvdesc); |
1172 | if (!newsrv) { | |
1173 | reply("OSMSG_SRV_CREATE_FAILED"); | |
1174 | return 0; | |
1175 | } | |
1176 | irc_server(newsrv); | |
1177 | reply("OSMSG_SERVER_JUPED", argv[1]); | |
1178 | return 1; | |
1179 | } | |
1180 | ||
1181 | static MODCMD_FUNC(cmd_unjupe) | |
1182 | { | |
1183 | struct server *srv; | |
1184 | char *reason; | |
1185 | ||
1186 | srv = GetServerH(argv[1]); | |
1187 | if (!srv) { | |
1188 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
1189 | return 0; | |
1190 | } | |
1191 | if (strncmp(srv->description, "JUPE", 4)) { | |
1192 | reply("OSMSG_SERVER_NOT_JUPE"); | |
1193 | return 0; | |
1194 | } | |
1195 | reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : "Unjuping server"; | |
1196 | DelServer(srv, 1, reason); | |
1197 | reply("OSMSG_SERVER_UNJUPED"); | |
1198 | return 1; | |
1199 | } | |
1200 | ||
1201 | static MODCMD_FUNC(cmd_jump) | |
1202 | { | |
1203 | extern struct cManagerNode cManager; | |
1204 | void uplink_select(char *name); | |
1205 | struct uplinkNode *uplink_find(char *name); | |
1206 | struct uplinkNode *uplink; | |
1207 | char *target; | |
1208 | ||
1209 | target = unsplit_string(argv+1, argc-1, NULL); | |
1210 | ||
1211 | if (!strcmp(cManager.uplink->name, target)) { | |
258d1427 | 1212 | reply("OSMSG_CURRENT_UPLINK", cManager.uplink->name); |
1213 | return 0; | |
d76ed9a9 | 1214 | } |
1215 | ||
1216 | uplink = uplink_find(target); | |
1217 | if (!uplink) { | |
258d1427 | 1218 | reply("OSMSG_INVALID_UPLINK", target); |
1219 | return 0; | |
d76ed9a9 | 1220 | } |
1221 | if (uplink->flags & UPLINK_UNAVAILABLE) { | |
1222 | reply("OSMSG_UPLINK_DISABLED", uplink->name); | |
1223 | return 0; | |
1224 | } | |
1225 | ||
1226 | reply("OSMSG_UPLINK_CONNECTING", uplink->name, uplink->host, uplink->port); | |
1227 | uplink_select(target); | |
1228 | irc_squit(self, "Reconnecting.", NULL); | |
1229 | return 1; | |
1230 | } | |
1231 | ||
1232 | static MODCMD_FUNC(cmd_die) | |
1233 | { | |
1234 | char *reason, *text; | |
1235 | ||
1236 | text = unsplit_string(argv+1, argc-1, NULL); | |
1237 | reason = alloca(strlen(text) + strlen(user->nick) + 20); | |
1238 | sprintf(reason, "Disconnected by %s [%s]", user->nick, text); | |
1239 | irc_squit(self, reason, text); | |
1240 | quit_services = 1; | |
1241 | return 1; | |
1242 | } | |
1243 | ||
1244 | static MODCMD_FUNC(cmd_restart) | |
1245 | { | |
1246 | extern int services_argc; | |
1247 | extern char **services_argv; | |
1248 | char **restart_argv, *reason, *text; | |
1249 | ||
1250 | text = unsplit_string(argv+1, argc-1, NULL); | |
1251 | reason = alloca(strlen(text) + strlen(user->nick) + 17); | |
1252 | sprintf(reason, "Restarted by %s [%s]", user->nick, text); | |
1253 | irc_squit(self, reason, text); | |
1254 | ||
1255 | /* Append a NULL to the end of argv[]. */ | |
1256 | restart_argv = (char **)alloca((services_argc + 1) * sizeof(char *)); | |
1257 | memcpy(restart_argv, services_argv, services_argc * sizeof(char *)); | |
1258 | restart_argv[services_argc] = NULL; | |
1259 | ||
1260 | call_exit_funcs(); | |
1261 | ||
1262 | /* Don't blink. */ | |
1263 | execv(services_argv[0], restart_argv); | |
1264 | ||
1265 | /* If we're still here, that means something went wrong. Reconnect. */ | |
1266 | return 1; | |
1267 | } | |
1268 | ||
1269 | static struct gline * | |
9a75756e | 1270 | opserv_block(struct userNode *target, char *src_handle, char *reason, unsigned long duration, int silent) |
d76ed9a9 | 1271 | { |
2f61d1d7 | 1272 | char mask[IRC_NTOP_MAX_SIZE+3] = { '*', '@', '\0' }; |
1273 | irc_ntop(mask + 2, sizeof(mask) - 2, &target->ip); | |
1274 | if (!reason) | |
1275 | snprintf(reason = alloca(MAXLEN), MAXLEN, | |
1276 | "G-line requested by %s.", src_handle); | |
1277 | if (!duration) | |
1278 | duration = opserv_conf.block_gline_duration; | |
0f6fe38c | 1279 | return gline_add(src_handle, mask, duration, reason, now, 1, silent ? 1 : 0); |
d76ed9a9 | 1280 | } |
1281 | ||
1282 | static MODCMD_FUNC(cmd_block) | |
1283 | { | |
1284 | struct userNode *target; | |
1285 | struct gline *gline; | |
1286 | char *reason; | |
1287 | ||
1288 | target = GetUserH(argv[1]); | |
1289 | if (!target) { | |
258d1427 | 1290 | reply("MSG_NICK_UNKNOWN", argv[1]); |
1291 | return 0; | |
d76ed9a9 | 1292 | } |
1293 | if (IsService(target)) { | |
258d1427 | 1294 | reply("MSG_SERVICE_IMMUNE", target->nick); |
1295 | return 0; | |
d76ed9a9 | 1296 | } |
0f6fe38c | 1297 | reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : NULL; |
1298 | gline = opserv_block(target, user->handle_info->handle, reason, 0, 0); | |
d76ed9a9 | 1299 | reply("OSMSG_GLINE_ISSUED", gline->target); |
1300 | return 1; | |
1301 | } | |
1302 | ||
1303 | static MODCMD_FUNC(cmd_gline) | |
1304 | { | |
1305 | unsigned long duration; | |
1306 | char *reason; | |
1307 | struct gline *gline; | |
1308 | ||
1309 | reason = unsplit_string(argv+3, argc-3, NULL); | |
1310 | if (!is_gline(argv[1]) && !IsChannelName(argv[1]) && (argv[1][0] != '&')) { | |
258d1427 | 1311 | reply("MSG_INVALID_GLINE", argv[1]); |
1312 | return 0; | |
d76ed9a9 | 1313 | } |
1314 | if (!argv[1][strspn(argv[1], "#&*?@.")] && (strlen(argv[1]) < 10)) { | |
1315 | reply("OSMSG_STUPID_GLINE", argv[1]); | |
1316 | return 0; | |
1317 | } | |
1318 | duration = ParseInterval(argv[2]); | |
1319 | if (!duration) { | |
1320 | reply("MSG_INVALID_DURATION", argv[2]); | |
1321 | return 0; | |
1322 | } | |
0f6fe38c | 1323 | gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, 1, 0); |
d76ed9a9 | 1324 | reply("OSMSG_GLINE_ISSUED", gline->target); |
1325 | return 1; | |
1326 | } | |
1327 | ||
1328 | static MODCMD_FUNC(cmd_ungline) | |
1329 | { | |
1330 | if (gline_remove(argv[1], 1)) | |
1331 | reply("OSMSG_GLINE_REMOVED", argv[1]); | |
1332 | else | |
1333 | reply("OSMSG_GLINE_FORCE_REMOVED", argv[1]); | |
1334 | return 1; | |
1335 | } | |
1336 | ||
1337 | static MODCMD_FUNC(cmd_refreshg) | |
1338 | { | |
1339 | if (argc > 1) { | |
1340 | unsigned int count; | |
1341 | dict_iterator_t it; | |
1342 | struct server *srv; | |
1343 | ||
1344 | for (it=dict_first(servers), count=0; it; it=iter_next(it)) { | |
1345 | srv = iter_data(it); | |
1346 | if ((srv == self) || !match_ircglob(srv->name, argv[1])) | |
1347 | continue; | |
1348 | gline_refresh_server(srv); | |
1349 | reply("OSMSG_GLINES_ONE_REFRESHED", srv->name); | |
1350 | count++; | |
1351 | } | |
1352 | if (!count) { | |
1353 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
1354 | return 0; | |
1355 | } | |
1356 | } else { | |
1357 | gline_refresh_all(); | |
1358 | reply("OSMSG_GLINES_REFRESHED"); | |
1359 | } | |
1360 | return 1; | |
1361 | } | |
1362 | ||
c408f18a | 1363 | static void |
0e08a8e0 | 1364 | opserv_version(struct userNode *target) |
1365 | { | |
1366 | irc_version_user(opserv, target); | |
1367 | } | |
1368 | ||
d82cf2f0 | 1369 | static void |
1370 | opserv_mark(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *mark) | |
1371 | { | |
1372 | if(!mark) | |
1373 | return; | |
1374 | irc_mark(target, mark); | |
1375 | } | |
1376 | ||
0e08a8e0 | 1377 | static void |
5aa400d2 | 1378 | opserv_svsjoin(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *channame, unsigned int checkrestrictions) |
c408f18a | 1379 | { |
1380 | struct chanNode *channel; | |
1381 | ||
1382 | if(!channame || !IsChannelName(channame)) { | |
1383 | /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */ | |
1384 | return; | |
1385 | } | |
1386 | ||
1387 | if (!(channel = GetChannel(channame))) { | |
1388 | channel = AddChannel(channame, now, NULL, NULL, NULL); | |
1389 | } | |
1390 | if (GetUserMode(channel, target)) { | |
1391 | /* already in it */ | |
1392 | return; | |
1393 | } | |
1394 | ||
5aa400d2 | 1395 | if (checkrestrictions) { |
1396 | if (trace_check_bans(target, channel) == 1) { | |
1397 | return; /* found on lamer list */ | |
1398 | } | |
1399 | ||
1400 | if (channel->modes & MODE_INVITEONLY) { | |
1401 | return; /* channel is invite only */ | |
1402 | } | |
1403 | ||
1e993296 | 1404 | if (channel->limit > 0) { |
1405 | if (channel->members.used >= channel->limit) { | |
1406 | return; /* channel is invite on */ | |
1407 | } | |
5aa400d2 | 1408 | } |
1409 | ||
1410 | if (*channel->key) { | |
1411 | return; /* channel is password protected */ | |
1412 | } | |
1413 | } | |
1414 | ||
c408f18a | 1415 | irc_svsjoin(opserv, target, channel); |
1416 | /* Should we tell the user they got joined? -Rubin*/ | |
1417 | } | |
1418 | ||
39c1a4ef | 1419 | static void |
1420 | opserv_svspart(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *channame) | |
1421 | { | |
1422 | struct chanNode *channel; | |
1423 | ||
1424 | if(!channame || !IsChannelName(channame)) { | |
1425 | /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */ | |
1426 | return; | |
1427 | } | |
1428 | ||
1429 | if (!(channel = GetChannel(channame))) { | |
1430 | /* channel doesnt exist */ | |
1431 | return; | |
1432 | } | |
1433 | ||
1434 | if (!GetUserMode(channel, target)) { | |
1435 | /* not in it */ | |
1436 | return; | |
1437 | } | |
1438 | ||
1439 | irc_svspart(opserv, target, channel); | |
1440 | } | |
1441 | ||
d914d1cb | 1442 | static struct shun * |
1443 | opserv_shun(struct userNode *target, char *src_handle, char *reason, unsigned long duration) | |
1444 | { | |
1445 | char *mask; | |
1446 | mask = alloca(MAXLEN); | |
1447 | snprintf(mask, MAXLEN, "*@%s", target->hostname); | |
1448 | if (!reason) { | |
1449 | reason = alloca(MAXLEN); | |
1450 | snprintf(reason, MAXLEN, "Shun requested by %s.", src_handle); | |
1451 | } | |
1452 | if (!duration) duration = opserv_conf.block_shun_duration; | |
0f6fe38c | 1453 | return shun_add(src_handle, mask, duration, reason, now, 1); |
d914d1cb | 1454 | } |
1455 | ||
1456 | static MODCMD_FUNC(cmd_sblock) | |
1457 | { | |
1458 | struct userNode *target; | |
1459 | struct shun *shun; | |
1460 | char *reason; | |
1461 | ||
1462 | target = GetUserH(argv[1]); | |
1463 | if (!target) { | |
1464 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1465 | return 0; | |
1466 | } | |
1467 | if (IsService(target)) { | |
1468 | reply("MSG_SERVICE_IMMUNE", target->nick); | |
1469 | return 0; | |
1470 | } | |
1471 | reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : NULL; | |
1472 | shun = opserv_shun(target, user->handle_info->handle, reason, 0); | |
1473 | reply("OSMSG_SHUN_ISSUED", shun->target); | |
1474 | return 1; | |
1475 | } | |
1476 | ||
1477 | static MODCMD_FUNC(cmd_shun) | |
1478 | { | |
1479 | unsigned long duration; | |
1480 | char *reason; | |
1481 | struct shun *shun; | |
1482 | ||
1483 | reason = unsplit_string(argv+3, argc-3, NULL); | |
1484 | if (!is_shun(argv[1]) && !IsChannelName(argv[1]) && (argv[1][0] != '&')) { | |
1485 | reply("MSG_INVALID_SHUN", argv[1]); | |
1486 | return 0; | |
1487 | } | |
1488 | if (!argv[1][strspn(argv[1], "#&*?@.")] && (strlen(argv[1]) < 10)) { | |
1489 | reply("OSMSG_STUPID_SHUN", argv[1]); | |
1490 | return 0; | |
1491 | } | |
1492 | duration = ParseInterval(argv[2]); | |
1493 | if (!duration) { | |
1494 | reply("MSG_INVALID_DURATION", argv[2]); | |
1495 | return 0; | |
1496 | } | |
0f6fe38c | 1497 | shun = shun_add(user->handle_info->handle, argv[1], duration, reason, now, 1); |
d914d1cb | 1498 | reply("OSMSG_SHUN_ISSUED", shun->target); |
1499 | return 1; | |
1500 | } | |
1501 | ||
1502 | static MODCMD_FUNC(cmd_unshun) | |
1503 | { | |
1504 | if (shun_remove(argv[1], 1)) | |
1505 | reply("OSMSG_SHUN_REMOVED", argv[1]); | |
1506 | else | |
1507 | reply("OSMSG_SHUN_FORCE_REMOVED", argv[1]); | |
1508 | return 1; | |
1509 | } | |
1510 | ||
1511 | static MODCMD_FUNC(cmd_refreshs) | |
1512 | { | |
1513 | if (argc > 1) { | |
1514 | unsigned int count; | |
1515 | dict_iterator_t it; | |
1516 | struct server *srv; | |
1517 | ||
1518 | for (it=dict_first(servers), count=0; it; it=iter_next(it)) { | |
1519 | srv = iter_data(it); | |
1520 | if ((srv == self) || !match_ircglob(srv->name, argv[1])) | |
1521 | continue; | |
1522 | shun_refresh_server(srv); | |
1523 | reply("OSMSG_SHUNS_ONE_REFRESHED", srv->name); | |
1524 | count++; | |
1525 | } | |
1526 | if (!count) { | |
1527 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
1528 | return 0; | |
1529 | } | |
1530 | } else { | |
1531 | shun_refresh_all(); | |
1532 | reply("OSMSG_SHUNS_REFRESHED"); | |
1533 | } | |
1534 | return 1; | |
1535 | } | |
1536 | ||
d76ed9a9 | 1537 | static void |
4b44eb0f | 1538 | opserv_ison(struct userNode *bot, struct userNode *tell, struct userNode *target, const char *message) |
d76ed9a9 | 1539 | { |
1540 | struct modeNode *mn; | |
1541 | unsigned int count, here_len, n, maxlen; | |
1542 | char buff[MAXLEN]; | |
1543 | ||
1544 | maxlen = tell->handle_info ? tell->handle_info->screen_width : 0; | |
1545 | if (!maxlen) | |
1546 | maxlen = MAX_LINE_SIZE; | |
1547 | for (n=count=0; n<target->channels.used; n++) { | |
258d1427 | 1548 | mn = target->channels.list[n]; |
1549 | here_len = strlen(mn->channel->name); | |
1550 | if ((count + here_len + 4) > maxlen) { | |
1551 | buff[count] = 0; | |
4b44eb0f | 1552 | send_message(tell, bot, message, buff); |
258d1427 | 1553 | count = 0; |
1554 | } | |
1555 | if (mn->modes & MODE_CHANOP) | |
d76ed9a9 | 1556 | buff[count++] = '@'; |
55342ce8 | 1557 | if (mn->modes & MODE_HALFOP) |
1558 | buff[count++] = '%'; | |
258d1427 | 1559 | if (mn->modes & MODE_VOICE) |
d76ed9a9 | 1560 | buff[count++] = '+'; |
258d1427 | 1561 | memcpy(buff+count, mn->channel->name, here_len); |
1562 | count += here_len; | |
1563 | buff[count++] = ' '; | |
d76ed9a9 | 1564 | } |
1565 | if (count) { | |
258d1427 | 1566 | buff[count] = 0; |
4b44eb0f | 1567 | send_message(tell, bot, message, buff); |
d76ed9a9 | 1568 | } |
1569 | } | |
1570 | ||
1571 | static MODCMD_FUNC(cmd_inviteme) | |
1572 | { | |
1573 | struct userNode *target; | |
1574 | ||
1575 | if (argc < 2) { | |
258d1427 | 1576 | target = user; |
d76ed9a9 | 1577 | } else { |
258d1427 | 1578 | target = GetUserH(argv[1]); |
1579 | if (!target) { | |
1580 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1581 | return 0; | |
1582 | } | |
d76ed9a9 | 1583 | } |
1584 | if (opserv_conf.debug_channel == NULL) { | |
258d1427 | 1585 | reply("OSMSG_NO_DEBUG_CHANNEL"); |
1586 | return 0; | |
d76ed9a9 | 1587 | } |
1588 | if (GetUserMode(opserv_conf.debug_channel, user)) { | |
a32da4c7 | 1589 | reply("OSMSG_ALREADY_THERE", opserv_conf.debug_channel->name); |
d76ed9a9 | 1590 | return 0; |
1591 | } | |
1592 | irc_invite(cmd->parent->bot, target, opserv_conf.debug_channel); | |
1593 | if (target != user) | |
258d1427 | 1594 | reply("OSMSG_INVITE_DONE", target->nick, opserv_conf.debug_channel->name); |
d76ed9a9 | 1595 | return 1; |
1596 | } | |
1597 | ||
1598 | static MODCMD_FUNC(cmd_invite) | |
1599 | { | |
1600 | if (GetUserMode(channel, user)) { | |
1601 | reply("OSMSG_ALREADY_THERE", channel->name); | |
1602 | return 0; | |
1603 | } | |
1604 | irc_invite(cmd->parent->bot, user, channel); | |
1605 | return 1; | |
1606 | } | |
1607 | ||
c408f18a | 1608 | static MODCMD_FUNC(cmd_svsjoin) |
1609 | { | |
1610 | struct userNode *target; | |
1611 | ||
1612 | ||
1613 | if(!IsChannelName(argv[2])) { | |
1614 | reply("MSG_NOT_CHANNEL_NAME"); | |
1615 | return 0; | |
1616 | } | |
1617 | target = GetUserH(argv[1]); | |
1618 | if (!target) { | |
1619 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1620 | return 0; | |
1621 | } | |
1622 | ||
1623 | if (!(channel = GetChannel(argv[2]))) { | |
1624 | channel = AddChannel(argv[2], now, NULL, NULL, NULL); | |
1625 | } | |
1626 | if (GetUserMode(channel, target)) { | |
1627 | reply("OSMSG_ALREADY_THERE", channel->name); | |
1628 | return 0; | |
1629 | } | |
1630 | irc_svsjoin(opserv, target, channel); | |
1631 | reply("OSMSG_SVSJOIN_SENT"); | |
1632 | return 1; | |
1633 | } | |
1634 | ||
964a842d | 1635 | static MODCMD_FUNC(cmd_svsnick) |
1636 | { | |
1637 | struct userNode *target; | |
1638 | ||
1639 | target = GetUserH(argv[1]); | |
1640 | if (!target) { | |
1641 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1642 | return 0; | |
1643 | } | |
1644 | if(!is_valid_nick(argv[2])) { | |
1645 | reply("OMSG_BAD_SVSNICK", argv[2]); | |
1646 | return 0; | |
1647 | } | |
1648 | irc_svsnick(opserv, target, argv[2]); | |
1649 | return 1; | |
1650 | } | |
1651 | ||
d76ed9a9 | 1652 | static MODCMD_FUNC(cmd_join) |
1653 | { | |
1654 | struct userNode *bot = cmd->parent->bot; | |
1655 | ||
0f6fe38c | 1656 | if (!IsChannelName(argv[1])) { |
d76ed9a9 | 1657 | reply("MSG_NOT_CHANNEL_NAME"); |
1658 | return 0; | |
0f6fe38c | 1659 | } else if (!(channel = GetChannel(argv[1]))) { |
2aef5f4b | 1660 | channel = AddChannel(argv[1], now, NULL, NULL, NULL); |
d76ed9a9 | 1661 | AddChannelUser(bot, channel)->modes |= MODE_CHANOP; |
1662 | } else if (GetUserMode(channel, bot)) { | |
1663 | reply("OSMSG_ALREADY_JOINED", channel->name); | |
1664 | return 0; | |
1665 | } else { | |
1666 | struct mod_chanmode change; | |
1667 | mod_chanmode_init(&change); | |
1668 | change.argc = 1; | |
1669 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 1670 | change.args[0].u.member = AddChannelUser(bot, channel); |
d76ed9a9 | 1671 | modcmd_chanmode_announce(&change); |
1672 | } | |
1673 | irc_fetchtopic(bot, channel->name); | |
1674 | reply("OSMSG_JOIN_DONE", channel->name); | |
1675 | return 1; | |
1676 | } | |
1677 | ||
1678 | static MODCMD_FUNC(cmd_kick) | |
1679 | { | |
1680 | struct userNode *target; | |
1681 | char *reason; | |
1682 | ||
1683 | if (argc < 3) { | |
258d1427 | 1684 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1685 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1686 | } else { |
258d1427 | 1687 | reason = unsplit_string(argv+2, argc-2, NULL); |
d76ed9a9 | 1688 | } |
1689 | target = GetUserH(argv[1]); | |
1690 | if (!target) { | |
258d1427 | 1691 | reply("MSG_NICK_UNKNOWN", argv[1]); |
1692 | return 0; | |
d76ed9a9 | 1693 | } |
1694 | if (!GetUserMode(channel, target)) { | |
258d1427 | 1695 | reply("OSMSG_NOT_ON_CHANNEL", target->nick, channel->name); |
1696 | return 0; | |
d76ed9a9 | 1697 | } |
1698 | KickChannelUser(target, channel, cmd->parent->bot, reason); | |
1699 | return 1; | |
1700 | } | |
1701 | ||
1702 | static MODCMD_FUNC(cmd_kickall) | |
1703 | { | |
1704 | unsigned int limit, n, inchan; | |
1705 | struct modeNode *mn; | |
1706 | char *reason; | |
1707 | struct userNode *bot = cmd->parent->bot; | |
1708 | ||
1709 | /* ircu doesn't let servers KICK users, so if OpServ's not in the | |
1710 | * channel, we have to join it in temporarily. */ | |
1711 | if (!(inchan = GetUserMode(channel, bot) ? 1 : 0)) { | |
1712 | struct mod_chanmode change; | |
1713 | mod_chanmode_init(&change); | |
1714 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 1715 | change.args[0].u.member = AddChannelUser(bot, channel); |
d76ed9a9 | 1716 | modcmd_chanmode_announce(&change); |
1717 | } | |
1718 | if (argc < 2) { | |
258d1427 | 1719 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1720 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1721 | } else { |
258d1427 | 1722 | reason = unsplit_string(argv+1, argc-1, NULL); |
d76ed9a9 | 1723 | } |
1724 | limit = user->handle_info->opserv_level; | |
1725 | for (n=channel->members.used; n>0;) { | |
258d1427 | 1726 | mn = channel->members.list[--n]; |
1727 | if (IsService(mn->user) | |
1728 | || (mn->user->handle_info | |
1729 | && (mn->user->handle_info->opserv_level >= limit))) { | |
1730 | continue; | |
1731 | } | |
1732 | KickChannelUser(mn->user, channel, bot, reason); | |
d76ed9a9 | 1733 | } |
1734 | if (!inchan) | |
1735 | DelChannelUser(bot, channel, "My work here is done", 0); | |
1736 | reply("OSMSG_KICKALL_DONE", channel->name); | |
1737 | return 1; | |
1738 | } | |
1739 | ||
1740 | static MODCMD_FUNC(cmd_kickban) | |
1741 | { | |
1742 | struct mod_chanmode change; | |
1743 | struct userNode *target; | |
1744 | char *reason; | |
1745 | char *mask; | |
1746 | ||
1747 | if (argc == 2) { | |
258d1427 | 1748 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1749 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1750 | } else { |
258d1427 | 1751 | reason = unsplit_string(argv+2, argc-2, NULL); |
d76ed9a9 | 1752 | } |
1753 | target = GetUserH(argv[1]); | |
1754 | if (!target) { | |
258d1427 | 1755 | reply("MSG_NICK_UNKNOWN", argv[1]); |
1756 | return 0; | |
d76ed9a9 | 1757 | } |
1758 | if (!GetUserMode(channel, target)) { | |
258d1427 | 1759 | reply("OSMSG_NOT_ON_CHANNEL", target->nick, channel->name); |
1760 | return 0; | |
d76ed9a9 | 1761 | } |
1762 | mod_chanmode_init(&change); | |
1763 | change.argc = 1; | |
1764 | change.args[0].mode = MODE_BAN; | |
a32da4c7 | 1765 | change.args[0].u.hostmask = mask = generate_hostmask(target, 0); |
d76ed9a9 | 1766 | modcmd_chanmode_announce(&change); |
1767 | KickChannelUser(target, channel, cmd->parent->bot, reason); | |
1768 | free(mask); | |
1769 | return 1; | |
1770 | } | |
1771 | ||
1772 | static MODCMD_FUNC(cmd_kickbanall) | |
1773 | { | |
1774 | struct modeNode *mn; | |
1775 | struct userNode *bot = cmd->parent->bot; | |
1776 | struct mod_chanmode *change; | |
1777 | char *reason; | |
1778 | unsigned int limit, n, inchan; | |
1779 | ||
1780 | /* ircu doesn't let servers KICK users, so if OpServ's not in the | |
1781 | * channel, we have to join it in temporarily. */ | |
1782 | if (!(inchan = GetUserMode(channel, bot) ? 1 : 0)) { | |
1783 | change = mod_chanmode_alloc(2); | |
1784 | change->args[0].mode = MODE_CHANOP; | |
a32da4c7 | 1785 | change->args[0].u.member = AddChannelUser(bot, channel); |
d76ed9a9 | 1786 | change->args[1].mode = MODE_BAN; |
a32da4c7 | 1787 | change->args[1].u.hostmask = "*!*@*"; |
d76ed9a9 | 1788 | } else { |
1789 | change = mod_chanmode_alloc(1); | |
1790 | change->args[0].mode = MODE_BAN; | |
a32da4c7 | 1791 | change->args[0].u.hostmask = "*!*@*"; |
d76ed9a9 | 1792 | } |
1793 | modcmd_chanmode_announce(change); | |
a32da4c7 | 1794 | mod_chanmode_free(change); |
d76ed9a9 | 1795 | if (argc < 2) { |
258d1427 | 1796 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1797 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1798 | } else { |
258d1427 | 1799 | reason = unsplit_string(argv+1, argc-1, NULL); |
d76ed9a9 | 1800 | } |
1801 | /* now kick them */ | |
1802 | limit = user->handle_info->opserv_level; | |
1803 | for (n=channel->members.used; n>0; ) { | |
258d1427 | 1804 | mn = channel->members.list[--n]; |
1805 | if (IsService(mn->user) | |
1806 | || (mn->user->handle_info | |
1807 | && (mn->user->handle_info->opserv_level >= limit))) { | |
1808 | continue; | |
1809 | } | |
1810 | KickChannelUser(mn->user, channel, bot, reason); | |
d76ed9a9 | 1811 | } |
1812 | if (!inchan) | |
1813 | DelChannelUser(bot, channel, "My work here is done", 0); | |
1814 | reply("OSMSG_KICKALL_DONE", channel->name); | |
1815 | return 1; | |
1816 | } | |
1817 | ||
39c1a4ef | 1818 | static MODCMD_FUNC(cmd_svspart) |
1819 | { | |
1820 | struct userNode *target; | |
1821 | ||
1822 | if(!IsChannelName(argv[2])) { | |
1823 | reply("MSG_NOT_CHANNEL_NAME"); | |
1824 | return 0; | |
1825 | } | |
1826 | target = GetUserH(argv[1]); | |
1827 | if (!target) { | |
1828 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1829 | return 0; | |
1830 | } | |
1831 | ||
1832 | if (!(channel = GetChannel(argv[2]))) { | |
1833 | reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); | |
1834 | return 0; | |
1835 | } | |
1836 | ||
1837 | if (!GetUserMode(channel, target)) { | |
1838 | reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); | |
1839 | return 0; | |
1840 | } | |
1841 | ||
1842 | irc_svspart(opserv, target, channel); | |
1843 | reply("OSMSG_SVSPART_SENT"); | |
1844 | return 1; | |
1845 | } | |
1846 | ||
d76ed9a9 | 1847 | static MODCMD_FUNC(cmd_part) |
1848 | { | |
1849 | char *reason; | |
1850 | ||
1851 | if (!IsChannelName(argv[1])) { | |
1852 | reply("MSG_NOT_CHANNEL_NAME"); | |
1853 | return 0; | |
1854 | } | |
1855 | if ((channel = GetChannel(argv[1]))) { | |
1856 | if (!GetUserMode(channel, cmd->parent->bot)) { | |
1857 | reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); | |
1858 | return 0; | |
1859 | } | |
1860 | reason = (argc < 3) ? "Leaving." : unsplit_string(argv+2, argc-2, NULL); | |
1861 | reply("OSMSG_LEAVING", channel->name); | |
1862 | DelChannelUser(cmd->parent->bot, channel, reason, 0); | |
1863 | } | |
1864 | return 1; | |
1865 | } | |
1866 | ||
1867 | static MODCMD_FUNC(cmd_mode) | |
1868 | { | |
1869 | if (!modcmd_chanmode(argv+1, argc-1, MCP_ALLOW_OVB|MCP_KEY_FREE|MC_ANNOUNCE)) { | |
1870 | reply("MSG_INVALID_MODES", unsplit_string(argv+1, argc-1, NULL)); | |
1871 | return 0; | |
1872 | } | |
1873 | reply("OSMSG_MODE_SET", channel->name); | |
1874 | return 1; | |
1875 | } | |
1876 | ||
d82cf2f0 | 1877 | int is_valid_mark(char *mark) |
1878 | { | |
1879 | char *ptr; | |
1880 | ||
1881 | if(!mark || !*mark) | |
1882 | return 0; | |
1883 | if(strlen(mark) > MARKLEN) | |
1884 | return 0; | |
1885 | ||
1886 | for(ptr = mark; *ptr; ptr++) { | |
1887 | if(! (isalnum(*ptr) || *ptr == '-')) | |
1888 | return 0; | |
1889 | } | |
1890 | ||
1891 | return 1; | |
1892 | } | |
1893 | ||
1894 | static MODCMD_FUNC(cmd_mark) | |
1895 | { | |
1896 | char *mark = argv[2]; | |
1897 | struct userNode *victim = GetUserH(argv[1]); | |
1898 | ||
1899 | if(!victim) | |
1900 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1901 | else if(!is_valid_mark(mark)) | |
1902 | reply("OSMSG_MARK_INVALID"); | |
1903 | else { | |
1904 | irc_mark(victim, mark); | |
1905 | reply("OSMSG_MARK_SET"); | |
1906 | return 1; | |
1907 | } | |
1908 | return 0; | |
1909 | } | |
1910 | ||
d76ed9a9 | 1911 | static MODCMD_FUNC(cmd_op) |
1912 | { | |
1913 | struct mod_chanmode *change; | |
1914 | unsigned int arg, count; | |
1915 | ||
1916 | change = mod_chanmode_alloc(argc-1); | |
1917 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
1918 | struct userNode *victim; | |
1919 | struct modeNode *mn; | |
1920 | if (!(victim = GetUserH(argv[arg]))) | |
1921 | continue; | |
1922 | if (!(mn = GetUserMode(channel, victim))) | |
1923 | continue; | |
1924 | if (mn->modes & MODE_CHANOP) | |
1925 | continue; | |
1926 | change->args[count].mode = MODE_CHANOP; | |
a32da4c7 | 1927 | change->args[count++].u.member = mn; |
d76ed9a9 | 1928 | } |
1929 | if (count) { | |
1930 | change->argc = count; | |
1931 | modcmd_chanmode_announce(change); | |
1932 | } | |
1933 | mod_chanmode_free(change); | |
1934 | reply("OSMSG_OP_DONE"); | |
1935 | return 1; | |
1936 | } | |
1937 | ||
55342ce8 | 1938 | static MODCMD_FUNC(cmd_hop) |
1939 | { | |
1940 | struct mod_chanmode *change; | |
1941 | unsigned int arg, count; | |
1942 | ||
1943 | change = mod_chanmode_alloc(argc-1); | |
1944 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
1945 | struct userNode *victim; | |
1946 | struct modeNode *mn; | |
1947 | if (!(victim = GetUserH(argv[arg]))) | |
1948 | continue; | |
1949 | if (!(mn = GetUserMode(channel, victim))) | |
1950 | continue; | |
1951 | if (mn->modes & MODE_HALFOP) | |
1952 | continue; | |
1953 | change->args[count].mode = MODE_HALFOP; | |
11408ce4 | 1954 | change->args[count++].u.member = mn; |
55342ce8 | 1955 | } |
1956 | if (count) { | |
1957 | change->argc = count; | |
1958 | modcmd_chanmode_announce(change); | |
1959 | } | |
1960 | mod_chanmode_free(change); | |
1961 | reply("OSMSG_HOP_DONE"); | |
1962 | return 1; | |
1963 | } | |
1964 | ||
d76ed9a9 | 1965 | static MODCMD_FUNC(cmd_opall) |
1966 | { | |
1967 | struct mod_chanmode *change; | |
1968 | unsigned int ii, count; | |
1969 | ||
1970 | change = mod_chanmode_alloc(channel->members.used); | |
1971 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 | 1972 | struct modeNode *mn = channel->members.list[ii]; |
1973 | if (mn->modes & MODE_CHANOP) | |
d76ed9a9 | 1974 | continue; |
1975 | change->args[count].mode = MODE_CHANOP; | |
a32da4c7 | 1976 | change->args[count++].u.member = mn; |
d76ed9a9 | 1977 | } |
1978 | if (count) { | |
1979 | change->argc = count; | |
258d1427 | 1980 | modcmd_chanmode_announce(change); |
d76ed9a9 | 1981 | } |
1982 | mod_chanmode_free(change); | |
1983 | reply("OSMSG_OPALL_DONE", channel->name); | |
1984 | return 1; | |
1985 | } | |
1986 | ||
55342ce8 | 1987 | static MODCMD_FUNC(cmd_hopall) |
1988 | { | |
1989 | struct mod_chanmode *change; | |
1990 | unsigned int ii, count; | |
1991 | ||
1992 | change = mod_chanmode_alloc(channel->members.used); | |
1993 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
1994 | struct modeNode *mn = channel->members.list[ii]; | |
1995 | if (mn->modes & MODE_HALFOP) | |
1996 | continue; | |
1997 | change->args[count].mode = MODE_HALFOP; | |
11408ce4 | 1998 | change->args[count++].u.member = mn; |
55342ce8 | 1999 | } |
2000 | if (count) { | |
2001 | change->argc = count; | |
2002 | modcmd_chanmode_announce(change); | |
2003 | } | |
2004 | mod_chanmode_free(change); | |
2005 | reply("OSMSG_HOPALL_DONE", channel->name); | |
2006 | return 1; | |
2007 | } | |
2008 | ||
d76ed9a9 | 2009 | static MODCMD_FUNC(cmd_whois) |
2010 | { | |
2011 | struct userNode *target; | |
2012 | char buffer[128]; | |
2013 | int bpos, herelen; | |
2014 | ||
2015 | #ifdef WITH_PROTOCOL_P10 | |
2016 | if (argv[1][0] == '*') | |
2017 | target = GetUserN(argv[1]+1); | |
2018 | else | |
d76ed9a9 | 2019 | #endif |
1117fc5a | 2020 | target = GetUserH(argv[1]); |
d76ed9a9 | 2021 | if (!target) { |
2022 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
2023 | return 0; | |
2024 | } | |
2025 | reply("OSMSG_WHOIS_NICK", target->nick); | |
2026 | reply("OSMSG_WHOIS_HOST", target->ident, target->hostname); | |
2027 | if (IsFakeHost(target)) | |
2028 | reply("OSMSG_WHOIS_FAKEHOST", target->fakehost); | |
37ef8ee3 | 2029 | reply("OSMSG_WHOIS_CRYPT_HOST", target->crypthost); |
2030 | reply("OSMSG_WHOIS_CRYPT_IP", target->cryptip); | |
2f61d1d7 | 2031 | reply("OSMSG_WHOIS_IP", irc_ntoa(&target->ip)); |
21f6caee | 2032 | |
2033 | if (target->city) { | |
2034 | reply("OSMSG_WHOIS_COUNTRY", target->country_name); | |
2035 | reply("OSMSG_WHOIS_COUNTRY_CODE", target->country_code); | |
2036 | reply("OSMSG_WHOIS_CITY", target->city); | |
2037 | reply("OSMSG_WHOIS_REGION", target->region); | |
2038 | ||
2039 | reply("OSMSG_WHOIS_POSTAL_CODE", target->postal_code); | |
2040 | reply("OSMSG_WHOIS_LATITUDE", target->latitude); | |
2041 | reply("OSMSG_WHOIS_LONGITUDE", target->longitude); | |
1ad7ac15 | 2042 | /* Only show a map url if we have a city, latitude and longitude. |
2043 | * Theres not much point of latitude and longitude coordinates are | |
2044 | * returned but no city, the coordinates are useless. | |
2045 | */ | |
2046 | if (target->latitude && target->longitude && target->city) { | |
2047 | char map_url[MAXLEN]; | |
2048 | snprintf(map_url, sizeof(map_url), "http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=address&latlongtype=decimal&latitude=%f&longitude=%f", | |
2049 | target->latitude, target->longitude); | |
2050 | reply("OSMSG_WHOIS_MAP", map_url); | |
2051 | } | |
21f6caee | 2052 | reply("OSMSG_WHOIS_DMA_CODE", target->dma_code); |
2053 | reply("OSMSG_WHOIS_AREA_CODE", target->area_code); | |
2054 | } else if (target->country_name) { | |
2055 | reply("OSMSG_WHOIS_COUNTRY", target->country_name); | |
2056 | } | |
0e08a8e0 | 2057 | if(target->version_reply) { |
2058 | reply("OSMSG_WHOIS_VERSION", target->version_reply); | |
2059 | } | |
2c00fbc2 | 2060 | if(target->mark) { |
2061 | reply("OSMSG_WHOIS_MARK", target->mark); | |
2062 | } | |
da5b7dfc | 2063 | reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO"); |
21f6caee | 2064 | |
d76ed9a9 | 2065 | if (target->modes) { |
258d1427 | 2066 | bpos = 0; |
d76ed9a9 | 2067 | #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen) |
258d1427 | 2068 | if (IsInvisible(target)) buffer[bpos++] = 'i'; |
2069 | if (IsWallOp(target)) buffer[bpos++] = 'w'; | |
2070 | if (IsOper(target)) buffer[bpos++] = 'o'; | |
2071 | if (IsGlobal(target)) buffer[bpos++] = 'g'; | |
2072 | if (IsServNotice(target)) buffer[bpos++] = 's'; | |
0f6fe38c | 2073 | |
2074 | // sethost - reed/apples | |
2075 | // if (IsHelperIrcu(target)) buffer[bpos++] = 'h'; | |
258d1427 | 2076 | if (IsSetHost(target)) buffer[bpos++] = 'h'; |
0f6fe38c | 2077 | |
258d1427 | 2078 | if (IsService(target)) buffer[bpos++] = 'k'; |
2079 | if (IsDeaf(target)) buffer[bpos++] = 'd'; | |
b2cf3d66 | 2080 | if (target->handle_info) buffer[bpos++] = 'r'; |
d76ed9a9 | 2081 | if (IsHiddenHost(target)) buffer[bpos++] = 'x'; |
2082 | if (IsGagged(target)) buffer_cat(" (gagged)"); | |
258d1427 | 2083 | if (IsRegistering(target)) buffer_cat(" (registered account)"); |
2084 | buffer[bpos] = 0; | |
2085 | if (bpos > 0) | |
d76ed9a9 | 2086 | reply("OSMSG_WHOIS_MODES", buffer); |
2087 | } | |
2088 | reply("OSMSG_WHOIS_INFO", target->info); | |
2089 | #ifdef WITH_PROTOCOL_P10 | |
2090 | reply("OSMSG_WHOIS_NUMERIC", target->numeric); | |
2091 | #endif | |
2092 | reply("OSMSG_WHOIS_SERVER", target->uplink->name); | |
2093 | reply("OSMSG_WHOIS_ACCOUNT", (target->handle_info ? target->handle_info->handle : "Not authenticated")); | |
89d871d8 | 2094 | |
2095 | reply("OSMSG_WHOIS_PRIVS", client_report_privs(target)); | |
2096 | ||
d76ed9a9 | 2097 | intervalString(buffer, now - target->timestamp, user->handle_info); |
2098 | reply("OSMSG_WHOIS_NICK_AGE", buffer); | |
2099 | if (target->channels.used <= MAX_CHANNELS_WHOIS) | |
4b44eb0f | 2100 | opserv_ison(cmd->parent->bot, user, target, "OSMSG_WHOIS_CHANNELS"); |
d76ed9a9 | 2101 | else |
258d1427 | 2102 | reply("OSMSG_WHOIS_HIDECHANS"); |
d76ed9a9 | 2103 | return 1; |
2104 | } | |
2105 | ||
2106 | static MODCMD_FUNC(cmd_unban) | |
2107 | { | |
2108 | struct mod_chanmode change; | |
2109 | mod_chanmode_init(&change); | |
2110 | change.argc = 1; | |
2111 | change.args[0].mode = MODE_REMOVE | MODE_BAN; | |
a32da4c7 | 2112 | change.args[0].u.hostmask = argv[1]; |
d76ed9a9 | 2113 | modcmd_chanmode_announce(&change); |
2114 | reply("OSMSG_UNBAN_DONE", channel->name); | |
2115 | return 1; | |
2116 | } | |
2117 | ||
2118 | static MODCMD_FUNC(cmd_voiceall) | |
2119 | { | |
2120 | struct mod_chanmode *change; | |
2121 | unsigned int ii, count; | |
2122 | ||
2123 | change = mod_chanmode_alloc(channel->members.used); | |
2124 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 | 2125 | struct modeNode *mn = channel->members.list[ii]; |
2126 | if (mn->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) | |
d76ed9a9 | 2127 | continue; |
2128 | change->args[count].mode = MODE_VOICE; | |
a32da4c7 | 2129 | change->args[count++].u.member = mn; |
d76ed9a9 | 2130 | } |
2131 | if (count) { | |
2132 | change->argc = count; | |
258d1427 | 2133 | modcmd_chanmode_announce(change); |
d76ed9a9 | 2134 | } |
2135 | mod_chanmode_free(change); | |
2136 | reply("OSMSG_CHANNEL_VOICED", channel->name); | |
2137 | return 1; | |
2138 | } | |
2139 | ||
2140 | static MODCMD_FUNC(cmd_devoiceall) | |
2141 | { | |
2142 | struct mod_chanmode *change; | |
2143 | unsigned int ii, count; | |
2144 | ||
2145 | change = mod_chanmode_alloc(channel->members.used); | |
2146 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 | 2147 | struct modeNode *mn = channel->members.list[ii]; |
2148 | if (!(mn->modes & MODE_VOICE)) | |
d76ed9a9 | 2149 | continue; |
2150 | change->args[count].mode = MODE_REMOVE | MODE_VOICE; | |
a32da4c7 | 2151 | change->args[count++].u.member = mn; |
d76ed9a9 | 2152 | } |
2153 | if (count) { | |
2154 | change->argc = count; | |
258d1427 | 2155 | modcmd_chanmode_announce(change); |
d76ed9a9 | 2156 | } |
2157 | mod_chanmode_free(change); | |
2158 | reply("OSMSG_CHANNEL_DEVOICED", channel->name); | |
2159 | return 1; | |
2160 | } | |
2161 | ||
2162 | static MODCMD_FUNC(cmd_stats_bad) { | |
2163 | dict_iterator_t it; | |
2164 | unsigned int ii, end, here_len; | |
2165 | char buffer[400]; | |
2166 | ||
2167 | /* Show the bad word list.. */ | |
de9510bc | 2168 | /* TODO: convert nonprinting chars like bold to $b etc in a usable way */ |
d76ed9a9 | 2169 | for (ii=end=0; ii<opserv_bad_words->used; ii++) { |
2170 | here_len = strlen(opserv_bad_words->list[ii]); | |
de9510bc | 2171 | /* If the line is full output it & start again */ |
d76ed9a9 | 2172 | if ((end + here_len + 2) > sizeof(buffer)) { |
2173 | buffer[end] = 0; | |
2174 | reply("OSMSG_BADWORD_LIST", buffer); | |
2175 | end = 0; | |
2176 | } | |
2177 | memcpy(buffer+end, opserv_bad_words->list[ii], here_len); | |
2178 | end += here_len; | |
2179 | buffer[end++] = ' '; | |
2180 | } | |
2181 | buffer[end] = 0; | |
2182 | reply("OSMSG_BADWORD_LIST", buffer); | |
2183 | ||
2184 | /* Show the exemption list.. */ | |
2185 | for (it=dict_first(opserv_exempt_channels), end=0; it; it=iter_next(it)) { | |
2186 | here_len = strlen(iter_key(it)); | |
2187 | if ((end + here_len + 2) > sizeof(buffer)) { | |
2188 | buffer[end] = 0; | |
2189 | reply("OSMSG_EXEMPTED_LIST", buffer); | |
2190 | end = 0; | |
2191 | } | |
2192 | memcpy(buffer+end, iter_key(it), here_len); | |
2193 | end += here_len; | |
2194 | buffer[end++] = ' '; | |
2195 | } | |
2196 | buffer[end] = 0; | |
2197 | reply("OSMSG_EXEMPTED_LIST", buffer); | |
2198 | return 1; | |
2199 | } | |
2200 | ||
0f6fe38c | 2201 | static MODCMD_FUNC(cmd_stats_glines) { |
2202 | reply("OSMSG_GLINE_COUNT", gline_count()); | |
2203 | return 1; | |
2204 | } | |
2205 | ||
2206 | static MODCMD_FUNC(cmd_stats_shuns) { | |
2207 | reply("OSMSG_SHUN_COUNT", shun_count()); | |
2208 | return 1; | |
2209 | } | |
2210 | ||
d76ed9a9 | 2211 | static void |
2212 | trace_links(struct userNode *bot, struct userNode *user, struct server *server, unsigned int depth) { | |
2213 | unsigned int nn, pos; | |
2214 | char buffer[400]; | |
2215 | ||
2216 | for (nn=1; nn<=depth; nn<<=1) ; | |
2217 | for (pos=0, nn>>=1; nn>1; ) { | |
2218 | nn >>= 1; | |
2219 | buffer[pos++] = (depth & nn) ? ((nn == 1) ? '`' : ' ') : '|'; | |
2220 | buffer[pos++] = (nn == 1) ? '-': ' '; | |
2221 | } | |
2222 | buffer[pos] = 0; | |
2223 | send_message(user, bot, "OSMSG_LINKS_SERVER", buffer, server->name, server->clients, server->description); | |
2224 | if (!server->children.used) | |
2225 | return; | |
2226 | for (nn=0; nn<server->children.used-1; nn++) { | |
2227 | trace_links(bot, user, server->children.list[nn], depth<<1); | |
2228 | } | |
2229 | trace_links(bot, user, server->children.list[nn], (depth<<1)|1); | |
2230 | } | |
2231 | ||
2232 | static MODCMD_FUNC(cmd_stats_links) { | |
2233 | trace_links(cmd->parent->bot, user, self, 1); | |
2234 | return 1; | |
2235 | } | |
2236 | ||
2237 | ||
2238 | static MODCMD_FUNC(cmd_stats_max) { | |
2239 | reply("OSMSG_MAX_CLIENTS", max_clients, asctime(localtime(&max_clients_time))); | |
2240 | return 1; | |
2241 | } | |
2242 | ||
2243 | static MODCMD_FUNC(cmd_stats_network) { | |
2244 | struct helpfile_table tbl; | |
2245 | unsigned int nn, tot_clients; | |
2246 | dict_iterator_t it; | |
2247 | ||
2248 | tot_clients = dict_size(clients); | |
2249 | reply("OSMSG_NETWORK_INFO", tot_clients, invis_clients, curr_opers.used); | |
2250 | tbl.length = dict_size(servers)+1; | |
2251 | tbl.width = 3; | |
2252 | tbl.flags = TABLE_NO_FREE; | |
2253 | tbl.contents = calloc(tbl.length, sizeof(*tbl.contents)); | |
2254 | tbl.contents[0] = calloc(tbl.width, sizeof(**tbl.contents)); | |
2255 | tbl.contents[0][0] = "Server Name"; | |
2256 | tbl.contents[0][1] = "Clients"; | |
2257 | tbl.contents[0][2] = "Load"; | |
2258 | for (it=dict_first(servers), nn=1; it; it=iter_next(it)) { | |
2259 | struct server *server = iter_data(it); | |
2260 | char *buffer = malloc(32); | |
2261 | tbl.contents[nn] = calloc(tbl.width, sizeof(**tbl.contents)); | |
2262 | tbl.contents[nn][0] = server->name; | |
2263 | tbl.contents[nn][1] = buffer; | |
2264 | sprintf(buffer, "%u", server->clients); | |
2265 | tbl.contents[nn][2] = buffer + 16; | |
2266 | sprintf(buffer+16, "%3.3g%%", ((double)server->clients/tot_clients)*100); | |
2267 | nn++; | |
2268 | } | |
2269 | table_send(cmd->parent->bot, user->nick, 0, 0, tbl); | |
2270 | for (nn=1; nn<tbl.length; nn++) { | |
2271 | free((char*)tbl.contents[nn][1]); | |
2272 | free(tbl.contents[nn]); | |
2273 | } | |
2274 | free(tbl.contents[0]); | |
2275 | free(tbl.contents); | |
2276 | return 1; | |
2277 | } | |
2278 | ||
2279 | static MODCMD_FUNC(cmd_stats_network2) { | |
2280 | struct helpfile_table tbl; | |
2281 | unsigned int nn; | |
2282 | dict_iterator_t it; | |
2283 | ||
2284 | tbl.length = dict_size(servers)+1; | |
2285 | tbl.width = 3; | |
2286 | tbl.flags = TABLE_NO_FREE; | |
2287 | tbl.contents = calloc(tbl.length, sizeof(*tbl.contents)); | |
2288 | tbl.contents[0] = calloc(tbl.width, sizeof(**tbl.contents)); | |
2289 | tbl.contents[0][0] = "Server Name"; | |
2290 | tbl.contents[0][1] = "Numeric"; | |
2291 | tbl.contents[0][2] = "Link Time"; | |
2292 | for (it=dict_first(servers), nn=1; it; it=iter_next(it)) { | |
2293 | struct server *server = iter_data(it); | |
2294 | char *buffer = malloc(64); | |
2295 | int ofs; | |
2296 | ||
2297 | tbl.contents[nn] = calloc(tbl.width, sizeof(**tbl.contents)); | |
2298 | tbl.contents[nn][0] = server->name; | |
2299 | #ifdef WITH_PROTOCOL_P10 | |
2300 | sprintf(buffer, "%s (%ld)", server->numeric, base64toint(server->numeric, strlen(server->numeric))); | |
2301 | #else | |
2302 | buffer[0] = 0; | |
2303 | #endif | |
2304 | tbl.contents[nn][1] = buffer; | |
2305 | ofs = strlen(buffer) + 1; | |
2306 | intervalString(buffer + ofs, now - server->link, user->handle_info); | |
2307 | if (server->self_burst) | |
2308 | strcat(buffer + ofs, " Bursting"); | |
2309 | tbl.contents[nn][2] = buffer + ofs; | |
2310 | nn++; | |
2311 | } | |
2312 | table_send(cmd->parent->bot, user->nick, 0, 0, tbl); | |
2313 | for (nn=1; nn<tbl.length; nn++) { | |
2314 | free((char*)tbl.contents[nn][1]); | |
2315 | free(tbl.contents[nn]); | |
2316 | } | |
2317 | free(tbl.contents[0]); | |
2318 | free(tbl.contents); | |
2319 | return 1; | |
2320 | } | |
2321 | ||
2322 | static MODCMD_FUNC(cmd_stats_reserved) { | |
2323 | dict_iterator_t it; | |
2324 | ||
2325 | reply("OSMSG_RESERVED_LIST"); | |
2326 | for (it = dict_first(opserv_reserved_nick_dict); it; it = iter_next(it)) | |
2327 | send_message_type(4, user, cmd->parent->bot, "%s", iter_key(it)); | |
2328 | return 1; | |
2329 | } | |
2330 | ||
2331 | static MODCMD_FUNC(cmd_stats_trusted) { | |
2332 | dict_iterator_t it; | |
2333 | struct trusted_host *th; | |
2334 | char length[INTERVALLEN], issued[INTERVALLEN], limit[32]; | |
2335 | ||
de9510bc | 2336 | reply("OSMSG_TRUSTED_LIST"); |
2337 | reply("OSMSG_TRUSTED_LIST_BAR"); | |
2338 | reply("OSMSG_TRUSTED_LIST_HEADER"); | |
2339 | reply("OSMSG_TRUSTED_LIST_BAR"); | |
d76ed9a9 | 2340 | if (argc > 1) { |
2341 | th = dict_find(opserv_trusted_hosts, argv[1], NULL); | |
2342 | if (th) { | |
2343 | if (th->issued) | |
2344 | intervalString(issued, now - th->issued, user->handle_info); | |
2345 | if (th->expires) | |
2346 | intervalString(length, th->expires - now, user->handle_info); | |
2347 | if (th->limit) | |
de9510bc | 2348 | sprintf(limit, "%lu", th->limit); |
d76ed9a9 | 2349 | reply("OSMSG_HOST_IS_TRUSTED", |
2350 | th->ipaddr, | |
de9510bc | 2351 | (th->limit ? limit : "none"), |
d76ed9a9 | 2352 | (th->issuer ? th->issuer : "<unknown>"), |
de9510bc | 2353 | (th->issued ? issued : "some time"), |
2354 | (th->expires ? length : "never")); | |
2355 | reply("OSMSG_HOST_IS_TRUSTED_DESC", (th->reason ? th->reason : "<unknown>")); | |
d76ed9a9 | 2356 | } else { |
2357 | reply("OSMSG_HOST_NOT_TRUSTED", argv[1]); | |
2358 | } | |
2359 | } else { | |
d76ed9a9 | 2360 | for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) { |
2361 | th = iter_data(it); | |
2362 | if (th->issued) | |
2363 | intervalString(issued, now - th->issued, user->handle_info); | |
2364 | if (th->expires) | |
2365 | intervalString(length, th->expires - now, user->handle_info); | |
2366 | if (th->limit) | |
de9510bc | 2367 | sprintf(limit, "%lu", th->limit); |
d76ed9a9 | 2368 | reply("OSMSG_HOST_IS_TRUSTED", iter_key(it), |
de9510bc | 2369 | (th->limit ? limit : "none"), |
d76ed9a9 | 2370 | (th->issuer ? th->issuer : "<unknown>"), |
de9510bc | 2371 | (th->issued ? issued : "some time"), |
2372 | (th->expires ? length : "never")); | |
2373 | reply("OSMSG_HOST_IS_TRUSTED_DESC", (th->reason ? th->reason : "<unknown>")); | |
d76ed9a9 | 2374 | } |
2375 | } | |
de9510bc | 2376 | reply("OSMSG_TRUSTED_LIST_END"); |
d76ed9a9 | 2377 | return 1; |
2378 | } | |
2379 | ||
2380 | static MODCMD_FUNC(cmd_stats_uplink) { | |
2381 | extern struct cManagerNode cManager; | |
2382 | struct uplinkNode *uplink; | |
2383 | ||
2384 | uplink = cManager.uplink; | |
2385 | reply("OSMSG_UPLINK_START", uplink->name); | |
2386 | reply("OSMSG_UPLINK_ADDRESS", uplink->host, uplink->port); | |
2387 | return 1; | |
2388 | } | |
2389 | ||
2390 | static MODCMD_FUNC(cmd_stats_uptime) { | |
2391 | char uptime[INTERVALLEN]; | |
2392 | struct tms buf; | |
0f6fe38c | 2393 | extern time_t boot_time; |
2394 | extern int lines_processed; | |
2395 | static long clocks_per_sec; | |
d76ed9a9 | 2396 | |
2397 | if (!clocks_per_sec) { | |
2398 | #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) | |
2399 | clocks_per_sec = sysconf(_SC_CLK_TCK); | |
2400 | if (clocks_per_sec <= 0) | |
2401 | #endif | |
2402 | { | |
2403 | log_module(OS_LOG, LOG_ERROR, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong"); | |
2404 | clocks_per_sec = CLOCKS_PER_SEC; | |
2405 | } | |
2406 | } | |
ff3b058a | 2407 | intervalString(uptime, time(NULL)-boot_time, user->handle_info); |
0f6fe38c | 2408 | times(&buf); |
2409 | reply("OSMSG_UPTIME_STATS", | |
2410 | uptime, lines_processed, | |
2411 | buf.tms_utime/(double)clocks_per_sec, | |
2412 | buf.tms_stime/(double)clocks_per_sec); | |
d76ed9a9 | 2413 | return 1; |
2414 | } | |
2415 | ||
2416 | static MODCMD_FUNC(cmd_stats_alerts) { | |
2417 | dict_iterator_t it; | |
2418 | struct opserv_user_alert *alert; | |
2419 | const char *reaction; | |
eaf715f1 | 2420 | char *m = NULL; |
d76ed9a9 | 2421 | |
eaf715f1 | 2422 | if(argc > 1) |
2423 | m = unsplit_string(argv + 1, argc - 1, NULL); | |
2424 | reply("OSMSG_ALERTS_LIST", m ? m : "*"); | |
de9510bc | 2425 | reply("OSMSG_ALERTS_BAR"); |
2426 | reply("OSMSG_ALERTS_HEADER"); | |
2427 | reply("OSMSG_ALERTS_BAR"); | |
d76ed9a9 | 2428 | for (it = dict_first(opserv_user_alerts); it; it = iter_next(it)) { |
2429 | alert = iter_data(it); | |
5aef35cf | 2430 | if(m && (!match_ircglob(alert->text_discrim, m) && strcasecmp(alert->owner, m) && strcasecmp(iter_key(it), m))) |
61eb54f9 | 2431 | continue; /* not a match to requested filter */ |
d76ed9a9 | 2432 | switch (alert->reaction) { |
2433 | case REACT_NOTICE: reaction = "notice"; break; | |
2434 | case REACT_KILL: reaction = "kill"; break; | |
1c5f6697 | 2435 | // case REACT_SILENT: reaction = "silent"; break; |
d76ed9a9 | 2436 | case REACT_GLINE: reaction = "gline"; break; |
ec311f39 | 2437 | case REACT_TRACK: reaction = "track"; break; |
d914d1cb | 2438 | case REACT_SHUN: reaction = "shun"; break; |
c408f18a | 2439 | case REACT_SVSJOIN: reaction = "svsjoin"; break; |
39c1a4ef | 2440 | case REACT_SVSPART: reaction = "svspart"; break; |
0e08a8e0 | 2441 | case REACT_VERSION: reaction = "version"; break; |
d82cf2f0 | 2442 | case REACT_MARK: reaction = "mark"; break; |
d76ed9a9 | 2443 | default: reaction = "<unknown>"; break; |
2444 | } | |
de9510bc | 2445 | reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner); |
2446 | reply("OSMSG_ALERTS_DESC", alert->text_discrim); | |
d76ed9a9 | 2447 | } |
de9510bc | 2448 | reply("OSMSG_ALERT_END"); |
d76ed9a9 | 2449 | return 1; |
2450 | } | |
2451 | ||
2452 | static MODCMD_FUNC(cmd_stats_gags) { | |
2453 | struct gag_entry *gag; | |
2454 | struct helpfile_table table; | |
2455 | unsigned int nn; | |
2456 | ||
2457 | if (!gagList) { | |
258d1427 | 2458 | reply("OSMSG_NO_GAGS"); |
d76ed9a9 | 2459 | return 1; |
2460 | } | |
2461 | for (nn=0, gag=gagList; gag; nn++, gag=gag->next) ; | |
2462 | table.length = nn+1; | |
2463 | table.width = 4; | |
2464 | table.flags = TABLE_NO_FREE; | |
2465 | table.contents = calloc(table.length, sizeof(char**)); | |
2466 | table.contents[0] = calloc(table.width, sizeof(char*)); | |
2467 | table.contents[0][0] = "Mask"; | |
2468 | table.contents[0][1] = "Owner"; | |
2469 | table.contents[0][2] = "Expires"; | |
2470 | table.contents[0][3] = "Reason"; | |
2471 | for (nn=1, gag=gagList; gag; nn++, gag=gag->next) { | |
2472 | char expstr[INTERVALLEN]; | |
2473 | if (gag->expires) | |
2474 | intervalString(expstr, gag->expires - now, user->handle_info); | |
2475 | else | |
2476 | strcpy(expstr, "Never"); | |
2477 | table.contents[nn] = calloc(table.width, sizeof(char*)); | |
2478 | table.contents[nn][0] = gag->mask; | |
2479 | table.contents[nn][1] = gag->owner; | |
2480 | table.contents[nn][2] = strdup(expstr); | |
2481 | table.contents[nn][3] = gag->reason; | |
2482 | } | |
2483 | table_send(cmd->parent->bot, user->nick, 0, NULL, table); | |
2484 | for (nn=1; nn<table.length; nn++) { | |
2485 | free((char*)table.contents[nn][2]); | |
2486 | free(table.contents[nn]); | |
2487 | } | |
2488 | free(table.contents[0]); | |
2489 | free(table.contents); | |
2490 | return 1; | |
2491 | } | |
2492 | ||
2493 | static MODCMD_FUNC(cmd_stats_timeq) { | |
2494 | reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now); | |
2495 | return 1; | |
2496 | } | |
2497 | ||
de9510bc | 2498 | /* |
d76ed9a9 | 2499 | static MODCMD_FUNC(cmd_stats_warn) { |
2500 | dict_iterator_t it; | |
2501 | ||
2502 | reply("OSMSG_WARN_LISTSTART"); | |
2503 | for (it=dict_first(opserv_chan_warn); it; it=iter_next(it)) | |
2504 | reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it)); | |
2505 | reply("OSMSG_WARN_LISTEND"); | |
2506 | return 1; | |
2507 | } | |
de9510bc | 2508 | */ |
d76ed9a9 | 2509 | |
f14e4f83 | 2510 | #if defined(WITH_MALLOC_X3) |
ec1a68c8 | 2511 | static MODCMD_FUNC(cmd_stats_memory) { |
2512 | extern unsigned long alloc_count, alloc_size; | |
0d16e639 | 2513 | send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, |
2514 | "%u allocations totalling %u bytes.", | |
2515 | alloc_count, alloc_size); | |
2516 | return 1; | |
2517 | } | |
2518 | #elif defined(WITH_MALLOC_SLAB) | |
2519 | static MODCMD_FUNC(cmd_stats_memory) { | |
2520 | extern unsigned long slab_alloc_count, slab_count, slab_alloc_size; | |
2521 | extern unsigned long big_alloc_count, big_alloc_size; | |
2522 | send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, | |
2523 | "%u allocations in %u slabs totalling %u bytes.", | |
2524 | slab_alloc_count, slab_count, slab_alloc_size); | |
63c95a47 | 2525 | send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, |
0d16e639 | 2526 | "%u big allocations totalling %u bytes.", |
63c95a47 | 2527 | big_alloc_count, big_alloc_size); |
ec1a68c8 | 2528 | return 1; |
2529 | } | |
2530 | #endif | |
2531 | ||
d76ed9a9 | 2532 | static MODCMD_FUNC(cmd_dump) |
2533 | { | |
b336c8db | 2534 | char linedup[MAXLEN], original[MAXLEN]; |
d76ed9a9 | 2535 | |
b336c8db | 2536 | unsplit_string(argv+1, argc-1, original); |
d76ed9a9 | 2537 | safestrncpy(linedup, original, sizeof(linedup)); |
2538 | /* assume it's only valid IRC if we can parse it */ | |
2539 | if (parse_line(linedup, 1)) { | |
258d1427 | 2540 | irc_raw(original); |
2541 | reply("OSMSG_LINE_DUMPED"); | |
d76ed9a9 | 2542 | } else |
258d1427 | 2543 | reply("OSMSG_RAW_PARSE_ERROR"); |
d76ed9a9 | 2544 | return 1; |
2545 | } | |
2546 | ||
2547 | static MODCMD_FUNC(cmd_raw) | |
2548 | { | |
b336c8db | 2549 | char linedup[MAXLEN], original[MAXLEN]; |
d76ed9a9 | 2550 | |
b336c8db | 2551 | unsplit_string(argv+1, argc-1, original); |
d76ed9a9 | 2552 | safestrncpy(linedup, original, sizeof(linedup)); |
2553 | /* Try to parse the line before sending it; if it's too wrong, | |
2554 | * maybe it will core us instead of our uplink. */ | |
2555 | parse_line(linedup, 1); | |
2556 | irc_raw(original); | |
2557 | reply("OSMSG_LINE_DUMPED"); | |
2558 | return 1; | |
2559 | } | |
2560 | ||
2561 | static struct userNode * | |
2562 | opserv_add_reserve(struct svccmd *cmd, struct userNode *user, const char *nick, const char *ident, const char *host, const char *desc) | |
2563 | { | |
2564 | struct userNode *resv = GetUserH(nick); | |
2565 | if (resv) { | |
258d1427 | 2566 | if (IsService(resv)) { |
2567 | reply("MSG_SERVICE_IMMUNE", resv->nick); | |
2568 | return NULL; | |
2569 | } | |
2570 | if (resv->handle_info | |
2571 | && resv->handle_info->opserv_level > user->handle_info->opserv_level) { | |
2572 | reply("OSMSG_LEVEL_TOO_LOW"); | |
2573 | return NULL; | |
2574 | } | |
d76ed9a9 | 2575 | } |
0f6fe38c | 2576 | if ((resv = AddClone(nick, ident, host, desc))) { |
d76ed9a9 | 2577 | dict_insert(opserv_reserved_nick_dict, resv->nick, resv); |
2578 | } | |
2579 | return resv; | |
2580 | } | |
2581 | ||
2582 | static MODCMD_FUNC(cmd_collide) | |
2583 | { | |
2584 | struct userNode *resv; | |
2585 | ||
2586 | resv = opserv_add_reserve(cmd, user, argv[1], argv[2], argv[3], unsplit_string(argv+4, argc-4, NULL)); | |
2587 | if (resv) { | |
258d1427 | 2588 | reply("OSMSG_COLLIDED_NICK", resv->nick); |
2589 | return 1; | |
d76ed9a9 | 2590 | } else { |
2591 | reply("OSMSG_CLONE_FAILED", argv[1]); | |
258d1427 | 2592 | return 0; |
d76ed9a9 | 2593 | } |
2594 | } | |
2595 | ||
2596 | static MODCMD_FUNC(cmd_reserve) | |
2597 | { | |
2598 | struct userNode *resv; | |
2599 | ||
2600 | resv = opserv_add_reserve(cmd, user, argv[1], argv[2], argv[3], unsplit_string(argv+4, argc-4, NULL)); | |
2601 | if (resv) { | |
258d1427 | 2602 | resv->modes |= FLAGS_PERSISTENT; |
2603 | reply("OSMSG_RESERVED_NICK", resv->nick); | |
2604 | return 1; | |
d76ed9a9 | 2605 | } else { |
2606 | reply("OSMSG_CLONE_FAILED", argv[1]); | |
258d1427 | 2607 | return 0; |
d76ed9a9 | 2608 | } |
2609 | } | |
2610 | ||
2611 | static int | |
2612 | free_reserve(char *nick) | |
2613 | { | |
2614 | struct userNode *resv; | |
2615 | unsigned int rlen; | |
2616 | char *reason; | |
2617 | ||
2618 | resv = dict_find(opserv_reserved_nick_dict, nick, NULL); | |
2619 | if (!resv) | |
2620 | return 0; | |
2621 | ||
2622 | rlen = strlen(resv->nick)+strlen(OSMSG_PART_REASON); | |
2623 | reason = alloca(rlen); | |
2624 | snprintf(reason, rlen, OSMSG_PART_REASON, resv->nick); | |
2625 | DelUser(resv, NULL, 1, reason); | |
2626 | dict_remove(opserv_reserved_nick_dict, nick); | |
2627 | return 1; | |
2628 | } | |
2629 | ||
2630 | static MODCMD_FUNC(cmd_unreserve) | |
2631 | { | |
2632 | if (free_reserve(argv[1])) | |
258d1427 | 2633 | reply("OSMSG_NICK_UNRESERVED", argv[1]); |
d76ed9a9 | 2634 | else |
258d1427 | 2635 | reply("OSMSG_NOT_RESERVED", argv[1]); |
d76ed9a9 | 2636 | return 1; |
2637 | } | |
2638 | ||
2639 | static void | |
2640 | opserv_part_channel(void *data) | |
2641 | { | |
2642 | DelChannelUser(opserv, data, "Leaving.", 0); | |
2643 | } | |
2644 | ||
2645 | static int alert_check_user(const char *key, void *data, void *extra); | |
2646 | ||
2647 | static int | |
2648 | opserv_new_user_check(struct userNode *user) | |
2649 | { | |
2650 | struct opserv_hostinfo *ohi; | |
2651 | struct gag_entry *gag; | |
2f61d1d7 | 2652 | char addr[IRC_NTOP_MAX_SIZE]; |
d76ed9a9 | 2653 | |
2654 | /* Check to see if we should ignore them entirely. */ | |
2655 | if (IsLocal(user) || IsService(user)) | |
2656 | return 0; | |
2657 | ||
2658 | /* Check for alerts, and stop if we find one that kills them. */ | |
2659 | if (dict_foreach(opserv_user_alerts, alert_check_user, user)) | |
2660 | return 1; | |
2661 | ||
2662 | /* Gag them if appropriate. */ | |
2663 | for (gag = gagList; gag; gag = gag->next) { | |
2f61d1d7 | 2664 | if (user_matches_glob(user, gag->mask, MATCH_USENICK)) { |
d76ed9a9 | 2665 | gag_helper_func(user, NULL); |
2666 | break; | |
2667 | } | |
2668 | } | |
2669 | ||
2670 | /* Add to host info struct */ | |
2f61d1d7 | 2671 | irc_ntop(addr, sizeof(addr), &user->ip); |
2672 | if (!(ohi = dict_find(opserv_hostinfo_dict, addr, NULL))) { | |
d76ed9a9 | 2673 | ohi = calloc(1, sizeof(*ohi)); |
2f61d1d7 | 2674 | dict_insert(opserv_hostinfo_dict, strdup(addr), ohi); |
d76ed9a9 | 2675 | userList_init(&ohi->clients); |
2676 | } | |
2677 | userList_append(&ohi->clients, user); | |
2678 | ||
2679 | /* Only warn of new user floods outside of bursts. */ | |
2680 | if (!user->uplink->burst) { | |
2681 | if (!policer_conforms(&opserv_conf.new_user_policer, now, 10)) { | |
2682 | if (!new_user_flood) { | |
2683 | new_user_flood = 1; | |
2684 | opserv_alert("Warning: Possible new-user flood."); | |
2685 | } | |
2686 | } else { | |
2687 | new_user_flood = 0; | |
2688 | } | |
2689 | } | |
2690 | ||
08895577 | 2691 | if (checkDefCon(DEFCON_NO_NEW_CLIENTS)) { |
2692 | irc_kill(opserv, user, DefConGlineReason); | |
2693 | return 0; | |
2694 | } | |
2695 | ||
0272358e | 2696 | if ( (checkDefCon(DEFCON_GLINE_NEW_CLIENTS) || checkDefCon(DEFCON_SHUN_NEW_CLIENTS)) && !IsOper(user)) { |
2697 | char target[IRC_NTOP_MAX_SIZE + 3] = { '*', '@', '\0' }; | |
2698 | ||
2699 | strcpy(target + 2, user->hostname); | |
2700 | if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS)) | |
0f6fe38c | 2701 | gline_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1, 0); |
0272358e | 2702 | else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS)) |
0f6fe38c | 2703 | shun_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1); |
0272358e | 2704 | |
2705 | return 0; | |
2706 | } | |
2707 | ||
d76ed9a9 | 2708 | /* Only warn or G-line if there's an untrusted max and their IP is sane. */ |
2f61d1d7 | 2709 | if (opserv_conf.untrusted_max |
2710 | && irc_in_addr_is_valid(user->ip) | |
2711 | && !irc_in_addr_is_loopback(user->ip)) { | |
2712 | struct trusted_host *th = dict_find(opserv_trusted_hosts, addr, NULL); | |
d76ed9a9 | 2713 | unsigned int limit = th ? th->limit : opserv_conf.untrusted_max; |
08895577 | 2714 | |
2715 | if (checkDefCon(DEFCON_REDUCE_SESSION) && !th) | |
2716 | limit = DefConSessionLimit; | |
2717 | ||
d76ed9a9 | 2718 | if (!limit) { |
2719 | /* 0 means unlimited hosts */ | |
2720 | } else if (ohi->clients.used == limit) { | |
2721 | unsigned int nn; | |
2722 | for (nn=0; nn<ohi->clients.used; nn++) | |
2723 | send_message(ohi->clients.list[nn], opserv, "OSMSG_CLONE_WARNING"); | |
2724 | } else if (ohi->clients.used > limit) { | |
2f61d1d7 | 2725 | char target[IRC_NTOP_MAX_SIZE + 3] = { '*', '@', '\0' }; |
2726 | strcpy(target + 2, addr); | |
0f6fe38c | 2727 | gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "Excessive connections from a single host.", now, 1, 1); |
d76ed9a9 | 2728 | } |
2729 | } | |
2730 | ||
2731 | return 0; | |
2732 | } | |
2733 | ||
2734 | static void | |
2735 | opserv_user_cleanup(struct userNode *user, UNUSED_ARG(struct userNode *killer), UNUSED_ARG(const char *why)) | |
2736 | { | |
2737 | struct opserv_hostinfo *ohi; | |
2f61d1d7 | 2738 | char addr[IRC_NTOP_MAX_SIZE]; |
d76ed9a9 | 2739 | |
2740 | if (IsLocal(user)) { | |
2741 | /* Try to remove it from the reserved nick dict without | |
2742 | * calling free_reserve, because that would call DelUser(), | |
2743 | * and we'd loop back to here. */ | |
2744 | dict_remove(opserv_reserved_nick_dict, user->nick); | |
2745 | return; | |
2746 | } | |
2f61d1d7 | 2747 | irc_ntop(addr, sizeof(addr), &user->ip); |
2748 | if ((ohi = dict_find(opserv_hostinfo_dict, addr, NULL))) { | |
d76ed9a9 | 2749 | userList_remove(&ohi->clients, user); |
2f61d1d7 | 2750 | if (ohi->clients.used == 0) |
2751 | dict_remove(opserv_hostinfo_dict, addr); | |
d76ed9a9 | 2752 | } |
2753 | } | |
2754 | ||
2755 | int | |
2756 | opserv_bad_channel(const char *name) | |
2757 | { | |
2758 | unsigned int found; | |
697f4c9a | 2759 | int present; |
d76ed9a9 | 2760 | |
697f4c9a | 2761 | dict_find(opserv_exempt_channels, name, &present); |
2762 | if (present) | |
d76ed9a9 | 2763 | return 0; |
2764 | ||
2765 | if (gline_find(name)) | |
2766 | return 1; | |
2767 | ||
2768 | for (found=0; found<opserv_bad_words->used; ++found) | |
2769 | if (irccasestr(name, opserv_bad_words->list[found])) | |
2770 | return 1; | |
2771 | ||
2772 | return 0; | |
2773 | } | |
2774 | ||
2775 | static void | |
2776 | opserv_shutdown_channel(struct chanNode *channel, const char *reason) | |
2777 | { | |
2778 | struct mod_chanmode *change; | |
2779 | unsigned int nn; | |
2780 | ||
2781 | change = mod_chanmode_alloc(2); | |
2782 | change->modes_set = MODE_SECRET | MODE_INVITEONLY; | |
2783 | change->args[0].mode = MODE_CHANOP; | |
a32da4c7 | 2784 | change->args[0].u.member = AddChannelUser(opserv, channel); |
d76ed9a9 | 2785 | change->args[1].mode = MODE_BAN; |
a32da4c7 | 2786 | change->args[1].u.hostmask = "*!*@*"; |
d76ed9a9 | 2787 | mod_chanmode_announce(opserv, channel, change); |
2788 | mod_chanmode_free(change); | |
2789 | for (nn=channel->members.used; nn>0; ) { | |
2790 | struct modeNode *mNode = channel->members.list[--nn]; | |
2791 | if (IsService(mNode->user)) | |
2792 | continue; | |
2793 | KickChannelUser(mNode->user, channel, opserv, user_find_message(mNode->user, reason)); | |
2794 | } | |
2795 | timeq_add(now + opserv_conf.purge_lock_delay, opserv_part_channel, channel); | |
2796 | } | |
2797 | ||
2798 | static void | |
2799 | opserv_channel_check(struct chanNode *newchan) | |
2800 | { | |
c52666c6 | 2801 | /*char *warning; */ |
d76ed9a9 | 2802 | |
2803 | if (!newchan->join_policer.params) { | |
2804 | newchan->join_policer.last_req = now; | |
2805 | newchan->join_policer.params = opserv_conf.join_policer_params; | |
2806 | } | |
c52666c6 | 2807 | /* |
d76ed9a9 | 2808 | if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) { |
57692f5e | 2809 | global_message_args(MESSAGE_RECIPIENT_OPERS, "OSMSG_CHANNEL_ACTIVITY_WARN", newchan->name, warning); |
d76ed9a9 | 2810 | } |
c52666c6 | 2811 | */ |
d76ed9a9 | 2812 | |
c52666c6 | 2813 | /* Wait until the join check to shut channels down. */ |
d76ed9a9 | 2814 | newchan->bad_channel = opserv_bad_channel(newchan->name); |
2815 | } | |
2816 | ||
2817 | static void | |
2818 | opserv_channel_delete(struct chanNode *chan) | |
2819 | { | |
2820 | timeq_del(0, opserv_part_channel, chan, TIMEQ_IGNORE_WHEN); | |
2821 | } | |
2822 | ||
0e08a8e0 | 2823 | static void |
0f6fe38c | 2824 | opserv_notice_handler(struct userNode *user, struct userNode *bot, char *text, UNUSED_ARG(int server_qualified)) |
0e08a8e0 | 2825 | { |
2826 | char *cmd; | |
2827 | /* if its a version reply, do an alert check (only alerts with version=something) */ | |
2828 | if(bot == opserv) { | |
2829 | if(text[0] == '\001') { | |
2830 | text++; | |
0f6fe38c | 2831 | cmd = mysep(&text, " "); |
50ea69b0 | 2832 | if(cmd && !irccasecmp(cmd, "VERSION")) { |
0f6fe38c | 2833 | char *version = mysep(&text, "\n"); |
0e08a8e0 | 2834 | if(!version) |
2835 | version = ""; | |
2836 | /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */ | |
da5b7dfc | 2837 | /* user->version_reply = strdup(version); done in parse-p10.c now */ |
0e08a8e0 | 2838 | dict_foreach(opserv_user_alerts, alert_check_user, user); |
2839 | } | |
2840 | } | |
2841 | } | |
2842 | } | |
2843 | ||
d76ed9a9 | 2844 | static int |
2845 | opserv_join_check(struct modeNode *mNode) | |
2846 | { | |
2847 | struct userNode *user = mNode->user; | |
2848 | struct chanNode *channel = mNode->channel; | |
2849 | const char *msg; | |
2850 | ||
2851 | if (IsService(user)) | |
2852 | return 0; | |
2853 | ||
2854 | dict_foreach(opserv_channel_alerts, alert_check_user, user); | |
2855 | ||
2856 | if (channel->bad_channel) { | |
2857 | opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user->nick, channel->name); | |
2858 | if (channel->name[0] != '#') | |
2859 | DelUser(user, opserv, 1, "OSMSG_ILLEGAL_KILL_REASON"); | |
2860 | else if (!GetUserMode(channel, opserv)) | |
2861 | opserv_shutdown_channel(channel, "OSMSG_ILLEGAL_REASON"); | |
2862 | else { | |
2863 | send_message(user, opserv, "OSMSG_ILLEGAL_CHANNEL", channel->name); | |
2864 | msg = user_find_message(user, "OSMSG_ILLEGAL_REASON"); | |
2865 | KickChannelUser(user, channel, opserv, msg); | |
2866 | } | |
2867 | return 1; | |
2868 | } | |
2869 | ||
2870 | if (user->uplink->burst) | |
2871 | return 0; | |
2872 | if (policer_conforms(&channel->join_policer, now, 1.0)) { | |
2873 | channel->join_flooded = 0; | |
2874 | return 0; | |
2875 | } | |
2876 | if (!channel->join_flooded) { | |
2877 | /* Don't moderate the channel unless it is activated and | |
2878 | the number of users in the channel is over the threshold. */ | |
2879 | struct mod_chanmode change; | |
2880 | mod_chanmode_init(&change); | |
2881 | channel->join_flooded = 1; | |
0f6fe38c | 2882 | if (opserv_conf.join_flood_moderate && (channel->members.used > opserv_conf.join_flood_moderate_threshold)) { |
d76ed9a9 | 2883 | if (!GetUserMode(channel, opserv)) { |
2884 | /* If we aren't in the channel, join it. */ | |
2885 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 2886 | change.args[0].u.member = AddChannelUser(opserv, channel); |
d76ed9a9 | 2887 | change.argc++; |
2888 | } | |
2889 | if (!(channel->modes & MODE_MODERATED)) | |
2890 | change.modes_set |= MODE_MODERATED; | |
2891 | if (change.modes_set || change.argc) | |
2892 | mod_chanmode_announce(opserv, channel, &change); | |
2893 | send_target_message(0, channel->name, opserv, "OSMSG_FLOOD_MODERATE"); | |
2894 | opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel->name, channel->members.used); | |
2895 | } else { | |
2896 | opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel->name, channel->members.used); | |
2897 | } | |
2898 | } | |
2899 | log_module(OS_LOG, LOG_INFO, "Join to %s during flood: "IDENT_FORMAT, channel->name, IDENT_DATA(user)); | |
2900 | return 0; | |
2901 | } | |
2902 | ||
2903 | static int | |
2904 | opserv_add_bad_word(struct svccmd *cmd, struct userNode *user, const char *new_bad) { | |
2905 | unsigned int bad_idx; | |
2906 | ||
2907 | for (bad_idx = 0; bad_idx < opserv_bad_words->used; ++bad_idx) { | |
2908 | char *orig_bad = opserv_bad_words->list[bad_idx]; | |
2909 | if (irccasestr(new_bad, orig_bad)) { | |
2910 | if (user) | |
2911 | reply("OSMSG_BAD_REDUNDANT", new_bad, orig_bad); | |
2912 | return 0; | |
2913 | } else if (irccasestr(orig_bad, new_bad)) { | |
2914 | if (user) | |
2915 | reply("OSMSG_BAD_GROWING", orig_bad, new_bad); | |
2916 | free(orig_bad); | |
2917 | opserv_bad_words->list[bad_idx] = strdup(new_bad); | |
2918 | for (bad_idx++; bad_idx < opserv_bad_words->used; bad_idx++) { | |
2919 | orig_bad = opserv_bad_words->list[bad_idx]; | |
2920 | if (!irccasestr(orig_bad, new_bad)) | |
2921 | continue; | |
2922 | if (user) | |
2923 | reply("OSMSG_BAD_NUKING", orig_bad); | |
2924 | string_list_delete(opserv_bad_words, bad_idx); | |
2925 | bad_idx--; | |
2926 | free(orig_bad); | |
2927 | } | |
2928 | return 1; | |
2929 | } | |
2930 | } | |
2931 | string_list_append(opserv_bad_words, strdup(new_bad)); | |
2932 | if (user) | |
2933 | reply("OSMSG_ADDED_BAD", new_bad); | |
2934 | return 1; | |
2935 | } | |
2936 | ||
47956fc5 | 2937 | static int |
2938 | 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) | |
2939 | { | |
2940 | struct routingPlanServer *rps; | |
2941 | rps = calloc(1, sizeof(*rps)); | |
2942 | if(!rps) | |
2943 | return 0; | |
2944 | /* duplicate servers replace */ | |
2945 | rps->uplink = strdup(uplink); | |
2946 | if(second) | |
2947 | rps->secondaryuplink = strdup(second); | |
2948 | else | |
2949 | rps->secondaryuplink = NULL; | |
2950 | rps->port = port ? port : 4400; /* lame hardcodede default port. maybe get from config file somewhere? */ | |
2951 | rps->karma = karma; | |
2952 | rps->offline = offline; /* 1 = yes, 0 = no */ | |
2953 | dict_insert(rp->servers, strdup(name), rps); | |
2954 | log_module(OS_LOG, LOG_DEBUG, "Adding rp server %s with uplink %s", name, uplink); | |
2955 | return 1; | |
2956 | } | |
2957 | ||
2958 | static void | |
2959 | free_routing_plan_server(void *data) | |
2960 | { | |
2961 | struct routingPlanServer *rps = data; | |
2962 | free(rps->uplink); | |
2963 | if(rps->secondaryuplink) | |
2964 | free(rps->secondaryuplink); | |
2965 | free(rps); | |
2966 | } | |
2967 | ||
2968 | struct routingPlan* | |
2969 | opserv_add_routing_plan(const char *name) | |
2970 | { | |
2971 | struct routingPlan *rp; | |
2972 | rp = calloc(1, sizeof(*rp)); | |
2973 | if (!rp) | |
2974 | return NULL; | |
2975 | if(dict_find(opserv_routing_plans, name, NULL)) | |
2976 | return NULL; /* plan already exists */ | |
2977 | rp->servers = dict_new(); | |
2978 | dict_set_free_data(rp->servers, free_routing_plan_server); | |
2979 | ||
2980 | dict_insert(opserv_routing_plans, strdup(name), rp); | |
2981 | /* TODO: check for duplicate */ | |
2982 | return rp; | |
2983 | } | |
2984 | ||
2985 | static void | |
2986 | free_routing_plan(void *data) | |
2987 | { | |
2988 | struct routingPlan *rp = data; | |
2989 | /* delete all the servers attached to this plan */ | |
2990 | dict_delete(rp->servers); | |
2991 | /* free the plan struct */ | |
2992 | free(rp); | |
2993 | } | |
2994 | ||
47956fc5 | 2995 | /************************************************* |
2996 | * Functions to handle the active routing struct */ | |
2997 | ||
2998 | struct routeList | |
2999 | *find_routeList_server(struct route *route, const char *server) | |
3000 | { | |
3001 | struct routeList *rptr; | |
3002 | if(!server) | |
3003 | return(NULL); | |
3004 | for(rptr = route->servers;rptr;rptr=rptr->next) { | |
3005 | if(!strcasecmp(rptr->server, server)) | |
3006 | return(rptr); | |
3007 | } | |
3008 | return(NULL); | |
3009 | } | |
3010 | ||
3011 | /* Wipes out the routing structure, freeing properly. | |
3012 | * note: does NOT free itself, we just re-use it usually.*/ | |
3013 | void | |
3014 | wipe_route_list(struct route *route) { | |
3015 | struct routeList *nextptr, *rptr; | |
3016 | if(!route) | |
3017 | return; | |
3018 | for(rptr = opserv_route->servers; rptr; rptr=nextptr) | |
3019 | { | |
3020 | nextptr = rptr->next; | |
3021 | free(rptr->server); | |
3022 | if(rptr->uplink) | |
3023 | free(rptr->uplink); | |
3024 | if(rptr->secondaryuplink) | |
3025 | free(rptr->secondaryuplink); | |
3026 | free(rptr); | |
3027 | } | |
3028 | route->centered = true; | |
3029 | route->count = 0; | |
3030 | route->maxdepth = 0; | |
3031 | route->servers = NULL; | |
3032 | } | |
3033 | ||
3034 | ||
3035 | int | |
3036 | rank_outside_rec(struct route *route, char *server, int count) | |
3037 | { | |
3038 | struct routeList *rptr; | |
3039 | int n, max = 0; | |
3040 | int i = 0; | |
3041 | if(count > 256) { /* XXX: 256 becomes max # of servers this works with, whats the real #? */ | |
3042 | return -1; | |
3043 | } | |
3044 | for(rptr = route->servers; rptr; rptr = rptr->next) { | |
3045 | i++; | |
3046 | if(!strcasecmp(server, rptr->uplink)) { | |
3047 | log_module(MAIN_LOG, LOG_DEBUG, "%d:%d: rank_outside_rec(%s) calling rank_outside_rec(%s)", count, i, rptr->server, rptr->uplink); | |
3048 | n = rank_outside_rec(route, rptr->server, count +1); | |
3049 | if(n < 0) /* handle error condition */ | |
3050 | return n; | |
3051 | if(n > max) | |
3052 | max = n; | |
3053 | } | |
3054 | } | |
3055 | if((rptr = find_routeList_server(route, server))) { | |
3056 | rptr->outsideness = max; | |
3057 | return(max + 1); | |
3058 | } | |
3059 | else { | |
3c10e41e | 3060 | log_module(MAIN_LOG, LOG_WARNING, "routing struct rank_outsideness() couldnt find %s", server); |
47956fc5 | 3061 | return 0; |
3062 | } | |
3063 | } | |
3064 | ||
3065 | int | |
3066 | rank_outsideness(struct route *route) | |
3067 | { | |
3068 | log_module(MAIN_LOG, LOG_DEBUG, "rank_outsideness(): Running..."); | |
3069 | route->maxdepth = rank_outside_rec(route, self->uplink->name, 0) - 1; | |
3070 | if(route->maxdepth < 0) { /* if the rank failed, remove route */ | |
3071 | log_module(MAIN_LOG, LOG_WARNING, "The active routing plan has a loop! auto routing disabled."); | |
3072 | wipe_route_list(route); | |
3073 | return false; | |
3074 | } | |
3075 | return true; | |
3076 | } | |
3077 | ||
3078 | ||
3079 | /* Add servers to the routing structure */ | |
3080 | void | |
3081 | add_routestruct_server(struct route *route, const char *server, unsigned int port, char *uplink, char *secondary) | |
3082 | { | |
3083 | struct routeList *rptr; | |
3084 | char *hname; | |
3085 | if(find_routeList_server(route, server)) | |
3086 | { | |
3087 | log_module(MAIN_LOG, LOG_WARNING, "Routing structure add server Skipping duplicate [%s]. This should never really be possible.", server); | |
3088 | return; | |
3089 | } | |
3090 | rptr = calloc(1, sizeof(*rptr)); | |
3091 | rptr->server = strdup(server); | |
3092 | rptr->port = port; | |
3093 | if(!uplink) { | |
3094 | hname = conf_get_data("server/hostname", RECDB_QSTRING); | |
3095 | uplink = hname; | |
3096 | } | |
3097 | rptr->uplink = strdup(uplink); | |
3098 | if(secondary) | |
3099 | rptr->secondaryuplink = strdup(secondary); | |
3100 | /* tack this server on the front of the list */ | |
3101 | rptr->next = route->servers; | |
3102 | route->servers = rptr; | |
3103 | route->count++; | |
3104 | ||
3105 | #ifdef notdef /* I dont quite get this. there could be uncentered things | |
3106 | * added after our own uplink, and this function doesnt center | |
3107 | * as it adds. -Rubin */ | |
3108 | /* If the map hasnt been centered yet... */ | |
3109 | if(route->centered == false) { | |
3110 | /* AND we just added our own uplink to it... */ | |
3111 | if(!strcasecmp(server, self->uplink->name)) { | |
3112 | change_route_uplinks(route); /* recenter it, n mark it centered. */ | |
3113 | } | |
3114 | } | |
3115 | #endif | |
3116 | } | |
3117 | ||
3118 | /* Recenter the routing struct around our current uplink */ | |
3119 | int | |
3120 | change_route_uplinks(struct route *route) | |
3121 | { | |
3122 | struct routeList *rptr; | |
3123 | char lastserver[MAXLEN]; | |
3124 | char nextserver[MAXLEN]; | |
3125 | ||
3126 | if(!route->servers) | |
3127 | return false; /* no map to recenter */ | |
3128 | log_module(MAIN_LOG, LOG_DEBUG, "change_route_uplinks(): running..."); | |
3129 | char *servicename = conf_get_data("server/hostname", RECDB_QSTRING); | |
3130 | strcpy(lastserver, servicename); | |
3131 | rptr = find_routeList_server(route, self->uplink->name); | |
3132 | if(!rptr) { | |
3c10e41e | 3133 | log_module(MAIN_LOG, LOG_WARNING, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered."); |
47956fc5 | 3134 | route->centered = false; |
3135 | return false; | |
3136 | } | |
3137 | if(!strcasecmp(rptr->uplink, servicename)) { | |
3138 | log_module(MAIN_LOG, LOG_DEBUG, "Already centered"); | |
3139 | } | |
3140 | else { /* else, center it */ | |
3141 | while(rptr) { | |
3142 | strcpy(nextserver, rptr->uplink); | |
3143 | log_module(MAIN_LOG, LOG_DEBUG, "change_route_uplinks() changing %s uplink to %s.", rptr->server, lastserver); | |
3144 | free(rptr->uplink); | |
3145 | rptr->uplink = strdup(lastserver); | |
3146 | strcpy(lastserver, rptr->server); | |
3147 | rptr = find_routeList_server(route, nextserver); | |
3148 | } | |
3149 | } | |
3150 | if(rank_outsideness(route) > 0) { | |
3151 | route->centered = true; | |
3152 | return true; | |
3153 | } | |
3154 | else | |
3155 | return false; | |
3156 | } | |
3157 | ||
3158 | int | |
3159 | activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) | |
3160 | { | |
3161 | static struct routingPlan *rp; | |
3162 | dict_iterator_t it; | |
3163 | char *karma; | |
3164 | ||
3165 | if(plan_name) { /* make this the new active plan */ | |
3166 | if(!strcmp(plan_name, "*")) { | |
3167 | /* disable routing */ | |
3168 | dict_remove(opserv_routing_plan_options, "ACTIVE"); | |
3169 | plan_name = NULL; | |
3170 | } | |
3171 | else { | |
3172 | rp = dict_find(opserv_routing_plans, plan_name, NULL); | |
3173 | if(!rp) { | |
3174 | if(cmd && user) | |
3175 | reply("OSMSG_PLAN_NOT_FOUND", plan_name); | |
3176 | else { | |
3177 | /* since it doesnt exist, remove the active setting */ | |
3178 | dict_remove(opserv_routing_plan_options, plan_name); | |
3179 | } | |
3c10e41e | 3180 | log_module(MAIN_LOG, LOG_WARNING, "activate_routing() couldnt find active routing plan!"); |
47956fc5 | 3181 | return 0; |
3182 | } | |
3183 | } | |
3184 | } | |
3185 | else { /* find the active plan in settings */ | |
3186 | plan_name = dict_find(opserv_routing_plan_options, "ACTIVE", NULL); | |
3187 | } | |
3188 | if(!plan_name) { /* deactivated, or no plan was set active */ | |
3189 | /* TODO: delete routing map if it exists */ | |
3190 | wipe_route_list(opserv_route); | |
3191 | return 1; | |
3192 | } | |
3193 | ||
3194 | karma = dict_find(opserv_routing_plan_options, "KARMA", NULL); | |
3195 | ||
3196 | rp = dict_find(opserv_routing_plans, plan_name, NULL); | |
3197 | ||
3198 | /* this should really be done during opserv init */ | |
3199 | if(!opserv_route) | |
3200 | opserv_route = calloc(1, sizeof(*opserv_route)); | |
3201 | ||
3202 | /* Delete the existing active route */ | |
3203 | wipe_route_list(opserv_route); | |
3204 | ||
763de701 | 3205 | if(!rp || !rp->servers) |
3206 | return 1; | |
47956fc5 | 3207 | for(it = dict_first(rp->servers); it; it = iter_next(it)) { |
3208 | const char* servername = iter_key(it); | |
3209 | struct routingPlanServer *rps = iter_data(it), | |
3210 | *rp_uplink, *rp_second = NULL; | |
3211 | char *uplink = rps->uplink; | |
3212 | rp_uplink = dict_find(rp->servers, rps->uplink, NULL); | |
3213 | if(rps->secondaryuplink) | |
3214 | rp_second = dict_find(rp->servers, rps->secondaryuplink, NULL); | |
3215 | ||
3216 | /* If the normal uplink has bad karma, don't use it as a hub, | |
3217 | * switch to the secondary uplink. | |
3218 | */ | |
3219 | if(karma && enabled_string(karma) && rp_uplink && rp_uplink->karma < 0) { | |
3220 | if(rps->secondaryuplink) { | |
3221 | uplink = rps->secondaryuplink; | |
3222 | /* unless the secondary uplinks karma is worse than the uplink. */ | |
3223 | if((rp_second = dict_find(rp->servers, uplink, NULL)) && rp_second->karma < rp_uplink->karma) | |
3224 | uplink = rps->uplink; | |
3225 | } | |
3226 | } | |
3227 | /* | |
3228 | * If _WE_ have bad karma, don't link us to our normal uplink, maybe | |
3229 | * its a bad route. switch to secondary. Important: dont neg karma when we arnt on | |
3230 | * our primary uplink, or we'll get stuck on secondary when THAT link is worse. | |
3231 | */ | |
3232 | if(karma && enabled_string(karma) && (rps->karma < 0 || rps->offline) ) { | |
3233 | if(rps->secondaryuplink) { | |
3234 | uplink = rps->secondaryuplink; | |
3235 | } | |
3236 | } | |
3237 | log_module(MAIN_LOG, LOG_DEBUG, "activate_routing() adding %s:%d %s", servername, rps->port, uplink); | |
3238 | add_routestruct_server(opserv_route, servername, rps->port, uplink, NULL); | |
3239 | } | |
3240 | if(change_route_uplinks(opserv_route)) | |
9079d26c | 3241 | { |
47956fc5 | 3242 | return 1; |
9079d26c | 3243 | } |
47956fc5 | 3244 | else if(user) { |
3245 | reply("OSMSG_ROUTING_ACTIVATION_ERROR"); | |
3246 | activate_routing(cmd, user, "*"); | |
3247 | return 0; | |
3248 | } | |
9079d26c | 3249 | /* routing activation failed but we dont do anything? */ |
47956fc5 | 3250 | return 1; |
3251 | } | |
3252 | ||
9079d26c | 3253 | |
3254 | void routing_init() | |
3255 | { | |
3256 | activate_routing(NULL, NULL, NULL); | |
3257 | ||
3258 | /* start auto-routing system */ | |
3259 | reroute_timer_reset(0); | |
3260 | } | |
3261 | ||
47956fc5 | 3262 | /******************************************************* |
3263 | * Functions to handle online route configuration via opserv | |
3264 | */ | |
3265 | static void route_show_option(struct svccmd *cmd, struct userNode *user, char *name) | |
3266 | { | |
3267 | char *value = dict_find(opserv_routing_plan_options, name, NULL); | |
3268 | if(value) { | |
3269 | if(!strcmp("RETRY_PERIOD", name)) { /* Show as an interval */ | |
3270 | char buff[INTERVALLEN+1]; | |
3271 | reply("OSMSG_ROUTINGPLAN_OPTION", name, intervalString(buff, atoi(value), user->handle_info)); | |
3272 | } | |
3273 | else if(!strcmp("ACTIVE", name)) { | |
3274 | if(opserv_route && opserv_route->servers) | |
3275 | reply("OSMSG_ROUTINGPLAN_ACTIVE", value); | |
3276 | else | |
3277 | reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name); | |
3278 | } | |
3279 | else { | |
3280 | reply("OSMSG_ROUTINGPLAN_OPTION", name, value); | |
3281 | } | |
3282 | } | |
3283 | else { | |
3284 | reply("OSMSG_ROUTINGPLAN_OPTION_NOT_SET", name); | |
3285 | } | |
3286 | } | |
3287 | ||
3288 | static void route_show_options(struct svccmd *cmd, struct userNode *user) | |
3289 | { | |
3290 | char *options[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL}; | |
3291 | int i; | |
3292 | for(i = 0; options[i]; i++) { | |
3293 | route_show_option(cmd, user, options[i]); | |
3294 | } | |
3295 | } | |
3296 | ||
3297 | /* called from timeq */ | |
3298 | void routing_connect_timeout(void *data) | |
3299 | { | |
3300 | struct waitingConnection *wc = data; | |
3301 | struct server *target = GetServerH(wc->target); | |
3302 | if(!target) { | |
3303 | dict_remove(opserv_waiting_connections, wc->server); | |
3304 | return; /* server we wanted to connect new server to is gone, just give up */ | |
3305 | } | |
3306 | routing_handle_connect_failure(target, wc->server, "Connection timed out"); | |
3307 | /* the following invalidates server variable! */ | |
3308 | dict_remove(opserv_waiting_connections, wc->server); | |
3309 | } | |
3310 | ||
3311 | void routing_delete_connect_timer(char *server) | |
3312 | { | |
3313 | struct waitingConnection *wc = dict_find(opserv_waiting_connections, server, 0); | |
3314 | if(wc) { | |
3315 | timeq_del(0, routing_connect_timeout, wc, TIMEQ_IGNORE_WHEN); | |
3316 | dict_remove(opserv_waiting_connections, server); | |
3317 | } | |
3318 | } | |
3319 | ||
3320 | ||
3321 | void | |
3322 | routing_connect_server(char *server, int port, struct server *to) | |
3323 | { | |
3324 | struct waitingConnection *wc = calloc(sizeof(*wc), 1); | |
3325 | ||
3326 | wc->server = strdup(server); | |
3327 | wc->target = strdup(to->name); | |
e6dce34c | 3328 | /* Just to make sure there isn't one left hanging |
3329 | * if 2 connections are attempted at once.. | |
3330 | * */ | |
3331 | routing_delete_connect_timer(server); | |
47956fc5 | 3332 | dict_insert(opserv_waiting_connections, strdup(server), wc); |
3333 | timeq_add(now + ROUTING_CONNECT_TIMEOUT, routing_connect_timeout, wc); | |
3334 | ||
3335 | irc_connect(opserv, server, port, to); | |
3336 | } | |
3337 | ||
3338 | int | |
3339 | routing_connect_one(struct route *route, char *server) | |
3340 | { | |
3341 | struct routeList *rptr; | |
3342 | struct server *sptr, *suptr; | |
3343 | for(rptr = route->servers; rptr; rptr = rptr->next) { | |
3344 | if(!strcasecmp(rptr->server, server)) { | |
3345 | /* this is the one, connect it */ | |
3346 | suptr = GetServerH(rptr->uplink); | |
3347 | sptr = GetServerH(rptr->server); | |
3348 | if(sptr) | |
3349 | return 1; /* already linked */ | |
3350 | if(suptr) { | |
3351 | routing_connect_server(rptr->server, rptr->port, suptr); | |
3352 | return 1; /* attempted link */ | |
3353 | } | |
3354 | return 0; /* its uplink isnt here to link to */ | |
3355 | } | |
3356 | } | |
da0c436d | 3357 | log_module(MAIN_LOG, LOG_DEBUG, "Tried to link %s but its not in the active routing struct!", server); |
3358 | return 0; /* server wasnt found in active route struct. */ | |
47956fc5 | 3359 | } |
3360 | ||
3361 | int routing_connect_children(struct route *route, char *server) | |
3362 | { | |
3363 | struct routeList *rptr; | |
3364 | struct server *sptr, *suptr; | |
3365 | for(rptr = route->servers; rptr; rptr = rptr->next) { | |
3366 | if(!strcasecmp(rptr->uplink, server)) { | |
3367 | /* this is the one, connect it */ | |
3368 | suptr = GetServerH(rptr->uplink); | |
3369 | sptr = GetServerH(rptr->server); | |
3370 | if(sptr) | |
3371 | continue; /* already linked */ | |
3372 | if(suptr) { | |
3373 | routing_connect_server(rptr->server, rptr->port, suptr); | |
3374 | continue; /* attempted link */ | |
3375 | } | |
3376 | continue; /* its uplink isnt here to link to */ | |
3377 | } | |
3378 | } | |
3379 | return 1; /* server wasnt found in active route struct ?! */ | |
3380 | } | |
3381 | ||
3382 | int reroute(struct route *route, struct userNode *user, struct svccmd *cmd, char *directive) | |
3383 | { | |
3384 | struct routeList *rptr; | |
3385 | struct server *sptr, *suptr; | |
3386 | int connect = 0, move = 0, missing = 0, i; | |
3387 | char d = toupper(*directive); | |
3388 | ||
964abe6b | 3389 | if(!route || !route->servers) { |
3390 | reply("OSMSG_REROUTING_NOTCONFIGURED"); | |
3391 | return 0; | |
3392 | } | |
47956fc5 | 3393 | if(user) { |
3394 | if(d == 'N') { /* normal */ | |
3395 | irc_wallops("%s", "Attempting a reroute of the network according to loaded map..."); | |
3396 | reply("OSMSG_REROUTING_ACC_MAP"); | |
3397 | } | |
3398 | else if(d == 'C') { /* only connect */ | |
3399 | reply("OSMSG_CONNECTING_MISSING_ONLY"); | |
3400 | } | |
3401 | else if(d == 'T') { /* test */ | |
3402 | reply("OSMSG_TESTING_REROUTE"); | |
3403 | } | |
3404 | else | |
3405 | { | |
3406 | reply("OSMSG_INVALID_DIRECTIVE", directive); | |
3407 | return 0; | |
3408 | } | |
3409 | } | |
3410 | for(i = 0; i <= route->maxdepth-1; i++) { | |
3411 | for(rptr = route->servers; rptr; rptr = rptr->next) { | |
3412 | if(rptr->outsideness == i) { | |
3413 | /* debugging */ | |
3414 | if(user && d=='T') | |
3415 | reply("OSMSG_INSPECTING_SERVER", rptr->server); | |
3416 | suptr = GetServerH(rptr->uplink); | |
3417 | if(!suptr) { | |
3418 | if(rptr->secondaryuplink && (suptr = GetServerH(rptr->secondaryuplink))) { | |
3419 | if(user) | |
3420 | reply("OSMSG_COULDNT_FIND_SERVER", rptr->uplink, rptr->secondaryuplink, rptr->server); | |
3421 | } | |
3422 | } | |
3423 | if(suptr) { /* if the proper uplink is connected.. */ | |
3424 | sptr = GetServerH(rptr->server); | |
3425 | if(d == 'C' && sptr) { | |
3426 | continue; /* Already linked */ | |
3427 | } | |
3428 | /* If server is missing or the uplinks are not the same then... */ | |
3429 | else if(!sptr || strcasecmp(sptr->uplink->name, rptr->uplink)) { | |
3430 | if(!sptr) { | |
3431 | connect++; | |
3432 | } | |
3433 | else { /* Server is already connected somewhere */ | |
3434 | if(strcasecmp(sptr->uplink->name, rptr->uplink)) { | |
3435 | if(d != 'T') { /* do it for real */ | |
3436 | irc_squit_route(sptr, "%s issued reroute.", user ? user->nick : opserv->nick); | |
3437 | } | |
3438 | else { /* just pretend */ | |
3439 | reply("OSMSG_SQUIT", rptr->server); | |
3440 | } | |
3441 | move++; | |
3442 | } | |
3443 | } | |
3444 | if(d != 'T') /* do the real thing */ | |
3445 | routing_connect_server(rptr->server, rptr->port, suptr); | |
3446 | else /* just pretend */ | |
3447 | reply("OSMSG_CONNECT", rptr->server, rptr->port, suptr->name); | |
3448 | } | |
3449 | } | |
3450 | else { | |
3451 | log_module(MAIN_LOG, LOG_DEBUG, "server uplink %s was not found, cant connect %s", rptr->uplink, rptr->server); | |
3452 | missing++; | |
3453 | } | |
3454 | } /* outsideness = 1 */ | |
3455 | } /* rptr */ | |
3456 | } /* maxdepth */ | |
3457 | if(user) { /* report on what we did */ | |
3458 | if(!strcasecmp(directive, "C")) { | |
3459 | if(connect > 0) | |
3460 | reply("OSMSG_CONNECTING_MISSING", connect); | |
3461 | else | |
3462 | reply("OSMSG_NO_SERVERS_MISSING"); | |
3463 | } | |
3464 | else { | |
3465 | if(move+connect > 0) | |
3466 | reply("OSMSG_REROUTE_COMPLETE", move, connect, move+connect); | |
3467 | else | |
3468 | reply("OSMSG_NO_ROUTING_NECESSARY"); | |
3469 | if(missing > 0) | |
3470 | reply("OSMSG_UPLINKS_MISSING", missing); | |
3471 | } | |
3472 | } | |
3473 | return(move+connect); | |
3474 | } | |
3475 | ||
3476 | static MODCMD_FUNC(cmd_reroute) { | |
3477 | char* upper; | |
3478 | upper = argv[1]; | |
3479 | if(reroute(opserv_route, user, cmd, upper)) | |
3480 | return 1; | |
3481 | else | |
3482 | return 0; | |
3483 | } | |
3484 | ||
3485 | /* reroute_timer(run) | |
3486 | * run - if it is null, just setup the timer | |
3487 | * but dont run reroute now. otherwise reroute | |
3488 | * and setup timer. | |
3489 | */ | |
3490 | void reroute_timer(void *data) { | |
9079d26c | 3491 | /* Delete any other timers such as this one.. */ |
3492 | timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); | |
3493 | ||
47956fc5 | 3494 | if(!opserv_route || !opserv_route->servers) |
3495 | return; /* no active route */ | |
3496 | char *retry_period = dict_find(opserv_routing_plan_options, "RETRY_PERIOD", NULL); | |
3497 | if(!retry_period) | |
3498 | return; /* retry_period invalid */ | |
3499 | unsigned int freq = atoi(retry_period); | |
3500 | if(freq < 1) | |
3501 | return; /* retry_period set to 0, disable */ | |
3502 | ||
9079d26c | 3503 | /* opserv_debug("Reroute timer checking reroute"); */ |
283cfa83 | 3504 | log_module(MAIN_LOG, LOG_DEBUG, "Reroute timer checking reroute()"); |
9079d26c | 3505 | |
47956fc5 | 3506 | /* Do the reroute C attempt */ |
3507 | if(data) | |
3508 | reroute(opserv_route, NULL, NULL, "C"); | |
3509 | ||
3510 | /* Re-add ourselves to the timer queue */ | |
3511 | timeq_add(now + freq, reroute_timer, "run"); | |
3512 | } | |
3513 | ||
3514 | void routing_change_karma(struct routingPlanServer *rps, const char *server, int change) { | |
3515 | ||
3516 | int oldkarma = rps->karma; | |
3517 | rps->karma += change; | |
3518 | if(rps->karma < KARMA_MIN) | |
3519 | rps->karma = KARMA_MIN; | |
3520 | if(rps->karma > KARMA_MAX) | |
3521 | rps->karma = KARMA_MAX; | |
3522 | log_module(MAIN_LOG, LOG_DEBUG, "Changing %s karma by %d. new karma %d.", server, change, rps->karma); | |
3523 | if(oldkarma > 0 && rps->karma < 0) { | |
3524 | /* we just crossed over to negitive */ | |
3525 | log_module(MAIN_LOG, LOG_INFO, "Server %s just went negitive karma!", server); | |
3526 | activate_routing(NULL, NULL, NULL); | |
3527 | } | |
3528 | else if(oldkarma < 0 && rps->karma > 0) { | |
3529 | /* we just crossed over to positive */ | |
3530 | log_module(MAIN_LOG, LOG_INFO, "Server %s just went back positive karma.", server); | |
3531 | activate_routing(NULL, NULL, NULL); | |
3532 | } | |
3533 | } | |
3534 | ||
3535 | void routing_karma_timer(void *data) { | |
3536 | time_t next; | |
3537 | time_t timer_init = data ? atoi(data) : 0; | |
3538 | char buf[MAXLEN]; | |
3539 | ||
3540 | log_module(MAIN_LOG, LOG_DEBUG, "routing_karma_timer() is running. timer_init=%d.", (unsigned int) timer_init); | |
3541 | ||
3542 | /* If theres a time passed in, dont run unless that time is overdue. */ | |
3543 | if(!timer_init || (timer_init < now)) { | |
3544 | if(opserv_route && opserv_route->servers) { | |
3545 | char *active = dict_find(opserv_routing_plan_options, "ACTIVE", NULL); | |
3546 | struct routingPlan *rp; | |
3547 | if(active && (rp = dict_find(opserv_routing_plans, active, NULL))) { | |
3548 | dict_iterator_t it; | |
3549 | /* Walk through each server in the active routing plan.. */ | |
3550 | for(it = dict_first(rp->servers); it; it = iter_next(it)) { | |
3551 | struct routingPlanServer *rps = iter_data(it); | |
3552 | struct server *server = GetServerH(iter_key(it)); | |
3553 | /* Give everyone +KARMA_ENTROPE just for nothing */ | |
3554 | routing_change_karma(rps, iter_key(it), KARMA_ENTROPE); | |
3555 | /* give an additonal +KARMA_RELIABLE to servers that | |
3556 | * have been linked at least KARMA_TIMER seconds. */ | |
3557 | if(server && (server->link < (now - KARMA_TIMER) ) ) { | |
3558 | routing_change_karma(rps, iter_key(it), KARMA_RELIABLE); | |
3559 | } | |
3560 | } | |
3561 | } | |
3562 | } | |
3563 | } | |
3564 | if(timer_init > now) /* loading a saved value */ | |
3565 | next = timer_init; | |
3566 | else /* no scheduled timer, or we missed it. start from now */ | |
3567 | next = now + KARMA_TIMER; | |
3568 | /* Save when karma_timer should run again in case we restart before then */ | |
3569 | log_module(MAIN_LOG, LOG_DEBUG, "routing_karma_timer() scheduling self to run again at %d", (unsigned int) next); | |
3570 | sprintf(buf, "%u", (unsigned int) next); | |
3571 | dict_insert(opserv_routing_plan_options, "KARMA_TIMER", strdup(buf)); | |
3572 | /* add a timer to run this again .. */ | |
3573 | timeq_add(next, routing_karma_timer, NULL); | |
3574 | } | |
3575 | ||
3576 | void routing_handle_neg_karma(char *server, char *uplink, int change) | |
3577 | { | |
3578 | /* if server's primary uplink is uplink, OR, uplink's primary uplink is server, | |
3579 | * then whichever one, gets its karma changed. */ | |
3580 | char *active = dict_find(opserv_routing_plan_options, "ACTIVE", NULL); | |
3581 | struct routingPlan *rp; | |
3582 | struct routingPlanServer *rps; | |
3583 | if(!active) | |
3584 | return; | |
3585 | if(!(rp = dict_find(opserv_routing_plans, active, NULL))) | |
3586 | return; | |
3587 | if((rps = dict_find(rp->servers, server, NULL))) { | |
3588 | if(!strcasecmp(rps->uplink, uplink)) { | |
3589 | /* server's uplink is uplink */ | |
3590 | routing_change_karma(rps, server, change); | |
3591 | return; | |
3592 | } | |
3593 | } | |
3594 | if((rps = dict_find(rp->servers, uplink, NULL))) { | |
3595 | if(!strcasecmp(rps->uplink, server)) { | |
3596 | /* uplink's uplink is server */ | |
3597 | routing_change_karma(rps, uplink, change); | |
3598 | return; | |
3599 | } | |
3600 | } | |
3601 | } | |
3602 | ||
3603 | void | |
3604 | routing_handle_squit(char *server, char *uplink, char *message) | |
3605 | { | |
3606 | log_module(MAIN_LOG, LOG_DEBUG, "Routing_handle_squit(%s, %s)", server, message); | |
3607 | ||
3608 | char *val; | |
3609 | ||
3610 | if(match_ircglob(message, "Ping timeout")) { | |
3611 | routing_handle_neg_karma(server, uplink, KARMA_PINGOUT); | |
3612 | /* if conn_pingout is true, try to reconnect it obaying karma rules. */ | |
3613 | ||
3614 | val = dict_find(opserv_routing_plan_options, "CONN_PINGOUT", 0); | |
3615 | if(val && enabled_string(val)) | |
3616 | routing_connect_one(opserv_route, server); | |
3617 | } | |
3618 | else if(match_ircglob(message, "Read error:*")) { | |
3619 | routing_handle_neg_karma(server, uplink, KARMA_READERROR); | |
3620 | /* if conn_readerror is true, try to reconnect it obaying karma rules. */ | |
3621 | val = dict_find(opserv_routing_plan_options, "CONN_READERROR", 0); | |
3622 | if(val && enabled_string(val)) | |
3623 | routing_connect_one(opserv_route, server); | |
3624 | } | |
3625 | /* Else whats the message (an oper squit it?) dont interfere */ | |
3626 | } | |
3627 | ||
3628 | void | |
3629 | routing_handle_connect(char *server, char *uplink) | |
3630 | { | |
3631 | char *active; | |
3632 | struct routingPlan *rp; | |
3633 | struct routingPlanServer *rps; | |
3634 | dict_iterator_t it; | |
3635 | ||
3636 | log_module(MAIN_LOG, LOG_DEBUG, "routing_handle_connect(%s, %s)", server, uplink); | |
3637 | /* delete a pending connection timer, if any */ | |
3638 | routing_delete_connect_timer(server); | |
3639 | /* check if routing is active... */ | |
3640 | active = dict_find(opserv_routing_plan_options, "ACTIVE", NULL); | |
3641 | if(!active) | |
3642 | return; | |
3643 | rp = dict_find(opserv_routing_plans, active, NULL); | |
3644 | if(!rp) | |
3645 | return; | |
3646 | ||
3647 | /* If its offline, mark it online again.. */ | |
3648 | if((rps = dict_find(rp->servers, server, NULL))) { | |
3649 | if(rps->offline == true) { | |
3650 | rps->offline = false; | |
3651 | if(rps->secondaryuplink) { | |
3652 | /* re-activate to move it back to its primary */ | |
3653 | activate_routing(NULL, NULL, NULL); | |
3654 | } | |
3655 | } | |
3656 | /* if there are any servers missing who have this server as uplink try to connect them. */ | |
3657 | routing_connect_children(opserv_route, server); | |
3658 | } | |
3659 | /* foreach server x3 knows about, if the uplink is this server, call this function on the child. */ | |
3660 | for (it=dict_first(servers); it; it=iter_next(it)) { | |
3661 | struct server *sptr = iter_data(it); | |
3662 | if(sptr && sptr->uplink && !strcasecmp(server, sptr->uplink->name)) { | |
3663 | log_module(MAIN_LOG, LOG_DEBUG, "routing_handle_connect calling self on %s's leaf %s", server, sptr->name); | |
3664 | routing_handle_connect(sptr->name, sptr->uplink->name); | |
3665 | } | |
3666 | } | |
3667 | } | |
3668 | ||
3669 | /* Handle a failed attempt at connecting servers | |
3670 | * - we should only get here regarding servers X3 attempted to link, other | |
3671 | * opers link messages go to them not to us | |
3672 | */ | |
3673 | void | |
3674 | routing_handle_connect_failure(struct server *source, char *server, char *message) | |
3675 | { | |
3676 | char *active; | |
3677 | struct routingPlan *rp; | |
3678 | struct routingPlanServer *rps; | |
3c10e41e | 3679 | log_module(MAIN_LOG, LOG_WARNING, "Failed to connect %s to %s: %s", server, source->name, message); |
47956fc5 | 3680 | /* remove the waiting connection n timeq */ |
3681 | routing_delete_connect_timer(server); | |
3682 | /* check if routing is active.. */ | |
3683 | active = dict_find(opserv_routing_plan_options, "ACTIVE", NULL); | |
3684 | if(!active) | |
3685 | return; | |
3686 | rp = dict_find(opserv_routing_plans, active, NULL); | |
3687 | if(!rp) | |
3688 | return; | |
3689 | ||
3690 | if( ((rps = dict_find(rp->servers, server, NULL)) && !strcasecmp(rps->uplink, source->name))) { | |
3691 | /* failed to connect to its primary uplink */ | |
3692 | if(rps->offline == false) { | |
3693 | rps->offline = true; | |
3694 | if(rps->secondaryuplink) { | |
3695 | /* re-activate routing so the secondary | |
3696 | * becomes its uplink, and try again */ | |
3697 | activate_routing(NULL, NULL, NULL); | |
3698 | /* attempt to link it again. */ | |
3699 | routing_connect_one(opserv_route, server); | |
bf93ca8d | 3700 | /* TODO: reconnect any missing servers who |
3701 | * normally connect to server, using their backups. | |
3702 | * Probably should just issue a reroute C here. */ | |
47956fc5 | 3703 | } |
3704 | } | |
3705 | } | |
3706 | } | |
3707 | ||
3708 | /* Delete any existing timers, and start the timer again | |
3709 | * using the passed time for the first run. | |
3710 | * - this is called during a retry_period change | |
9079d26c | 3711 | * before it has saved the new value. |
3712 | * | |
3713 | * If time is 0, lookup the interval. */ | |
47956fc5 | 3714 | void reroute_timer_reset(unsigned int time) |
3715 | { | |
9079d26c | 3716 | timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); |
3717 | if(time == 0) { | |
3718 | if(!opserv_route || !opserv_route->servers) | |
3719 | return; /* no active route */ | |
3720 | char *retry_period = dict_find(opserv_routing_plan_options, "RETRY_PERIOD", NULL); | |
3721 | if(!retry_period) | |
3722 | return; /* retry_period invalid */ | |
3723 | time = atoi(retry_period); | |
3724 | if(time < 1) | |
3725 | return; /* retry_period set to 0, disable */ | |
3726 | ||
3727 | } | |
47956fc5 | 3728 | timeq_add(now + time, reroute_timer, "run"); |
3729 | } | |
3730 | ||
3731 | static MODCMD_FUNC(cmd_routing_set) | |
3732 | { | |
3733 | char *option = argv[1]; | |
3734 | char *options[] = {"ACTIVE", "RETRY_PERIOD", "CONN_PINGOUT", "CONN_READERROR", "KARMA", "DEFAULT_PORT", NULL}; | |
3735 | int i; | |
3736 | if(argc < 2) { | |
3737 | route_show_options(cmd, user); | |
3738 | } | |
3739 | else { | |
3740 | char *found_option = NULL; | |
3741 | for(i = 0; options[i]; i++) { | |
3742 | if(!strcasecmp(options[i], option)) | |
3743 | found_option = options[i]; | |
3744 | } | |
3745 | if(!found_option) { | |
3746 | reply("OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", option); | |
3747 | return 0; | |
3748 | } | |
3749 | if(argc > 2) { | |
3750 | char *value = argv[2]; | |
3751 | char buff[MAXLEN]; /* whats the max length of unsigned int as printf'd? */ | |
3752 | if(!strcmp(found_option, "ACTIVE")) { /* must be an existing route. */ | |
3753 | if(disabled_string(value) || false_string(value)) { | |
3754 | /* make none of the maps active */ | |
3755 | activate_routing(cmd, user, "*"); | |
3756 | reply("OSMSG_ROUTING_DISABLED"); | |
3757 | return 1; | |
3758 | } | |
3759 | else if(!activate_routing(cmd, user, value)) { | |
3760 | /* neg reply handled in activate_routing */ | |
3761 | return 0; | |
3762 | } | |
3763 | } | |
3764 | if(!strcmp(found_option, "CONN_READERROR") || !strcmp(found_option, "CONN_PINGOUT") || | |
3765 | !strcmp(found_option, "KARMA") ) { | |
3766 | if( enabled_string(value)) { | |
3767 | value = "ENABLED"; | |
3768 | } | |
3769 | else if( disabled_string(value) ) { | |
3770 | value = "DISABLED"; | |
3771 | } | |
3772 | else { | |
3773 | reply("MSG_INVALID_BINARY", value); | |
3774 | return 0; | |
3775 | } | |
3776 | } | |
3777 | if(!strcmp(found_option, "RETRY_PERIOD")) { | |
3778 | unsigned int duration = ParseInterval(value); | |
3779 | sprintf(buff, "%d", duration); | |
3780 | value = buff; | |
3781 | reroute_timer_reset(duration); | |
3782 | } | |
3783 | /* set the value here */ | |
3784 | dict_remove(opserv_routing_plan_options, found_option); | |
3785 | dict_insert(opserv_routing_plan_options, strdup(found_option), strdup(value)); | |
3786 | route_show_option(cmd, user, found_option); | |
3787 | } | |
3788 | else { | |
3789 | /* show the current value */ | |
3790 | route_show_option(cmd, user, found_option); | |
3791 | } | |
3792 | } | |
3793 | return 1; | |
3794 | } | |
3795 | ||
3796 | static MODCMD_FUNC(cmd_stats_routing_plans) { | |
3797 | dict_iterator_t rpit; | |
3798 | dict_iterator_t it; | |
3799 | struct routingPlan *rp; | |
5c6bff84 | 3800 | if(argc > 1) { |
3801 | reply("OSMSG_ROUTINGPLAN"); | |
3802 | reply("OSMSG_ROUTINGPLAN_BAR"); | |
3803 | for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { | |
3804 | const char* name = iter_key(rpit); | |
3805 | rp = iter_data(rpit); | |
3806 | if(match_ircglob(name, argv[1])) { | |
3807 | reply("OSMSG_ROUTINGPLAN_NAME", name); | |
3808 | for(it = dict_first(rp->servers); it; it = iter_next(it)) { | |
3809 | const char* servername = iter_key(it); | |
3810 | struct routingPlanServer *rps = iter_data(it); | |
3811 | reply("OSMSG_ROUTINGPLAN_SERVER", servername, rps->port, rps->uplink, rps->karma, rps->offline? "offline" : "online", rps->secondaryuplink ? rps->secondaryuplink : "None"); | |
3812 | } | |
3813 | } | |
47956fc5 | 3814 | |
5c6bff84 | 3815 | } |
3816 | reply("OSMSG_ROUTINGPLAN_END"); | |
3817 | } | |
3818 | else { | |
3819 | reply("OSMSG_ROUTINGPLAN_LIST_HEAD"); | |
3820 | reply("OSMSG_ROUTINGPLAN_BAR"); | |
3821 | for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { | |
3822 | const char* name = iter_key(rpit); | |
3823 | reply("OSMSG_ROUTINGPLAN_LIST", name); | |
3824 | } | |
3825 | reply("OSMSG_ROUTINGPLAN_END"); | |
3826 | route_show_options(cmd, user); | |
47956fc5 | 3827 | } |
47956fc5 | 3828 | return 1; |
3829 | } | |
3830 | ||
3831 | ||
3832 | static MODCMD_FUNC(cmd_routing_addplan) | |
3833 | { | |
3834 | char *name; | |
3835 | name = argv[1]; | |
3836 | /* dont allow things like 'off', 'false', '0' because thats how we disable routing. */ | |
3837 | if(*name && !disabled_string(name) && !false_string(name)) { | |
3838 | if(opserv_add_routing_plan(name)) { | |
3839 | reply("OSMSG_ADDPLAN_SUCCESS", name); | |
3840 | return 1; | |
3841 | } | |
3842 | else { | |
3843 | reply("OSMSG_ADDPLAN_FAILED", name); | |
3844 | return 0; | |
3845 | } | |
3846 | } | |
3847 | else | |
3848 | { | |
3849 | reply("OSMSG_INVALID_PLAN"); | |
3850 | return 0; | |
3851 | } | |
3852 | } | |
3853 | ||
3854 | static MODCMD_FUNC(cmd_routing_delplan) | |
3855 | { | |
3856 | char *name = argv[1]; | |
3857 | if( dict_remove(opserv_routing_plans, name) ) { | |
3858 | char *active = dict_find(opserv_routing_plan_options, "ACTIVE", NULL); | |
3859 | if(active && !strcasecmp(active, name)) { | |
3860 | /* if this was the active plan, disable routing */ | |
3861 | activate_routing(cmd, user, "*"); | |
3862 | reply("OSMSG_ROUTING_DISABLED"); | |
3863 | } | |
3864 | reply("OSMSG_PLAN_DELETED"); | |
3865 | return 1; | |
3866 | } | |
3867 | else { | |
3868 | reply("OSMSG_PLAN_NOT_FOUND", name); | |
3869 | return 0; | |
3870 | } | |
3871 | } | |
3872 | ||
3873 | static MODCMD_FUNC(cmd_routing_addserver) | |
3874 | { | |
3875 | char *plan; | |
3876 | char *server; | |
3877 | char *portstr; | |
3878 | char *uplink; | |
3879 | char *second; | |
3880 | unsigned int port; | |
3881 | struct routingPlan *rp; | |
3882 | ||
3883 | plan = argv[1]; | |
3884 | server = strdup(argv[2]); | |
3885 | server = strtok(server, ":"); | |
3886 | portstr = strtok(NULL, ":"); | |
3887 | if(portstr) | |
3888 | port = atoi(portstr); | |
3889 | else { | |
3890 | char *str = dict_find(opserv_routing_plan_options, "DEFAULT_PORT", NULL); | |
3891 | uplink = argv[3]; | |
3892 | port = str ? atoi(str) : 0; | |
3893 | } | |
3894 | uplink = argv[3]; | |
3895 | if(argc > 4) | |
3896 | second = argv[4]; | |
3897 | else | |
3898 | second = NULL; | |
3899 | ||
3900 | if( (rp = dict_find(opserv_routing_plans, plan, 0))) { | |
3901 | char *active; | |
3902 | opserv_routing_plan_add_server(rp, server, uplink, port, KARMA_DEFAULT, second, 0); | |
3903 | reply("OSMSG_PLAN_SERVER_ADDED", server); | |
3904 | if((active = dict_find(opserv_routing_plan_options, "ACTIVE", 0)) && !strcasecmp(plan, active)) { | |
3905 | /* re-activate routing with new info */ | |
3906 | activate_routing(cmd, user, NULL); | |
3907 | } | |
3908 | ||
3909 | free(server); | |
3910 | return 1; | |
3911 | } | |
3912 | else { | |
3913 | reply("OSMSG_PLAN_NOT_FOUND", plan); | |
3914 | free(server); | |
3915 | return 0; | |
3916 | } | |
3917 | } | |
3918 | ||
3919 | static MODCMD_FUNC(cmd_routing_delserver) | |
3920 | { | |
3921 | char *plan; | |
3922 | char *server; | |
3923 | struct routingPlan *rp; | |
3924 | plan = argv[1]; | |
3925 | server = argv[2]; | |
3926 | if( (rp = dict_find(opserv_routing_plans, plan, 0))) { | |
3927 | if(dict_remove(rp->servers, server)) { | |
3928 | char *active; | |
3929 | reply("OSMSG_PLAN_SERVER_DELETED"); | |
3930 | if((active = dict_find(opserv_routing_plan_options, "ACTIVE", 0)) && !strcasecmp(plan, active)) { | |
3931 | /* re-activate routing with new info */ | |
3932 | activate_routing(cmd, user, NULL); | |
3933 | } | |
3934 | ||
3935 | return 1; | |
3936 | } | |
3937 | else { | |
3938 | reply("OSMSG_PLAN_SERVER_NOT_FOUND", server); | |
3939 | return 0; | |
3940 | } | |
3941 | } | |
3942 | else { | |
3943 | reply("OSMSG_PLAN_NOT_FOUND", plan); | |
3944 | return 0; | |
3945 | } | |
3946 | } | |
3947 | ||
3948 | ||
3949 | /************************************************* | |
3950 | * Functions to deal with 'route map' command */ | |
3951 | ||
3952 | /* Figures out how many downlinks there are for proper | |
3953 | * drawing of the route map */ | |
3954 | int | |
3955 | num_route_downlinks(struct route *route, char *name) | |
3956 | { | |
3957 | struct routeList *rptr; | |
3958 | int num = 0; | |
3959 | rptr = route->servers; | |
3960 | while(rptr) { | |
3961 | if(!strcasecmp(rptr->uplink, name)) | |
3962 | num++; | |
3963 | rptr = rptr->next; | |
3964 | } | |
3965 | return num; | |
3966 | } | |
3967 | ||
3968 | void | |
3969 | show_route_downlinks(struct svccmd *cmd, struct route *route, struct userNode *user, char *name, char *prevpre, char *arrowchar, int reset) | |
3970 | { | |
3971 | struct routeList *servPtr; | |
3972 | struct server *sptr; | |
3973 | int j; | |
3974 | char pre[MAXLEN]; | |
3975 | char *nextpre; | |
3976 | char *status; | |
3977 | int num = 0; | |
3978 | static int depth = 0; | |
3979 | ||
3980 | if(reset) | |
3981 | depth = 0; | |
3982 | ||
3983 | nextpre = malloc(MAXLEN); | |
3984 | strcpy(pre, prevpre); | |
3985 | ||
3986 | sptr = GetServerH(name); | |
3987 | if((servPtr = find_routeList_server(route, name))) { | |
3988 | if(!sptr) | |
3989 | status = " "; | |
3990 | else if (!strcasecmp(sptr->uplink->name, servPtr->uplink)) | |
3991 | status = "X"; | |
3992 | else if(servPtr->secondaryuplink && !strcasecmp(sptr->name, servPtr->secondaryuplink)) | |
3993 | status = "/"; | |
3994 | else | |
3995 | status = "!"; | |
3996 | reply("OSMSG_DOWNLINKS_FORMAT_A", pre, arrowchar, name, status); | |
3997 | } | |
3998 | else | |
3999 | reply("OSMSG_DOWNLINKS_FORMAT_B", self->name); | |
4000 | j = num_route_downlinks(route, name); | |
4001 | servPtr = route->servers; | |
4002 | while(servPtr) { | |
4003 | if(!strcasecmp(servPtr->uplink, name)) { | |
4004 | strcpy(nextpre, pre); | |
4005 | if(depth++ > 0) { | |
4006 | if(arrowchar[0] == '`') | |
4007 | strcat(nextpre, " "); | |
4008 | else | |
4009 | strcat(nextpre, "| "); | |
4010 | } | |
4011 | if(j > ++num) { | |
4012 | show_route_downlinks(cmd, route, user, servPtr->server, nextpre, "|", 0); | |
4013 | } | |
4014 | else { | |
4015 | show_route_downlinks(cmd, route, user, servPtr->server, nextpre, "`", 0); | |
4016 | } | |
4017 | } | |
4018 | servPtr = servPtr->next; | |
4019 | } | |
4020 | free(nextpre); | |
4021 | } | |
4022 | ||
4023 | int | |
4024 | show_route_map(struct route *route, struct userNode *user, struct svccmd *cmd) | |
4025 | { | |
4026 | if(!route || !route->servers) { | |
4027 | reply("OSMSG_ROUTELIST_EMPTY"); | |
4028 | return 0; | |
4029 | } | |
4030 | ||
4031 | char *serviceName = conf_get_data("server/hostname", RECDB_QSTRING); | |
4032 | reply("OSMSG_ROUTELIST_AS_PLANNED"); | |
4033 | show_route_downlinks(cmd, route, user, serviceName, "", "`", 1); | |
4034 | reply("OSMSG_MAP_CENTERED", route->centered ? "is" : "is not", route->maxdepth); | |
4035 | return 1; | |
4036 | } | |
4037 | ||
4038 | static MODCMD_FUNC(cmd_routing_map) | |
4039 | { | |
4040 | show_route_map(opserv_route, user, cmd); | |
4041 | return 1; | |
4042 | } | |
4043 | ||
4044 | ||
4045 | ||
4046 | ||
4047 | /* End of auto routing functions * | |
4048 | *********************************/ | |
4049 | ||
d76ed9a9 | 4050 | static MODCMD_FUNC(cmd_addbad) |
4051 | { | |
4052 | unsigned int arg, count; | |
4053 | dict_iterator_t it; | |
4054 | int bad_found, exempt_found; | |
4055 | ||
4056 | /* Create the bad word if it doesn't exist. */ | |
4057 | bad_found = !opserv_add_bad_word(cmd, user, argv[1]); | |
4058 | ||
4059 | /* Look for exception modifiers. */ | |
4060 | for (arg=2; arg<argc; arg++) { | |
4061 | if (!irccasecmp(argv[arg], "except")) { | |
4062 | reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt"); | |
4063 | if (++arg > argc) { | |
4064 | reply("MSG_MISSING_PARAMS", "except"); | |
4065 | break; | |
4066 | } | |
4067 | for (count = 0; (arg < argc) && IsChannelName(argv[arg]); arg++) { | |
4068 | dict_find(opserv_exempt_channels, argv[arg], &exempt_found); | |
4069 | if (!exempt_found) { | |
4070 | dict_insert(opserv_exempt_channels, strdup(argv[arg]), NULL); | |
4071 | count++; | |
4072 | } | |
4073 | } | |
4074 | reply("OSMSG_ADDED_EXEMPTIONS", count); | |
4075 | } else { | |
4076 | reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad"); | |
4077 | reply("OSMSG_BAD_MODIFIER", argv[arg]); | |
4078 | } | |
4079 | } | |
4080 | ||
4081 | /* Scan for existing channels that match the new bad word. */ | |
4082 | if (!bad_found) { | |
4083 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
4084 | struct chanNode *channel = iter_data(it); | |
4085 | ||
4086 | if (!opserv_bad_channel(channel->name)) | |
4087 | continue; | |
4088 | channel->bad_channel = 1; | |
4089 | if (channel->name[0] == '#') | |
4090 | opserv_shutdown_channel(channel, "OSMSG_ILLEGAL_REASON"); | |
4091 | else { | |
4092 | unsigned int nn; | |
4093 | for (nn=0; nn<channel->members.used; nn++) { | |
4094 | struct userNode *user = channel->members.list[nn]->user; | |
4095 | DelUser(user, cmd->parent->bot, 1, "OSMSG_ILLEGAL_KILL_REASON"); | |
4096 | } | |
4097 | } | |
4098 | } | |
4099 | } | |
4100 | ||
4101 | return 1; | |
4102 | } | |
4103 | ||
4104 | static MODCMD_FUNC(cmd_delbad) | |
4105 | { | |
4106 | dict_iterator_t it; | |
4107 | unsigned int nn; | |
4108 | ||
4109 | for (nn=0; nn<opserv_bad_words->used; nn++) { | |
4110 | if (!irccasecmp(opserv_bad_words->list[nn], argv[1])) { | |
4111 | string_list_delete(opserv_bad_words, nn); | |
4112 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
4113 | channel = iter_data(it); | |
4114 | if (irccasestr(channel->name, argv[1]) | |
4115 | && !opserv_bad_channel(channel->name)) { | |
4116 | DelChannelUser(cmd->parent->bot, channel, "Channel name no longer contains a bad word.", 1); | |
4117 | timeq_del(0, opserv_part_channel, channel, TIMEQ_IGNORE_WHEN); | |
4118 | channel->bad_channel = 0; | |
4119 | } | |
4120 | } | |
4121 | reply("OSMSG_REMOVED_BAD", argv[1]); | |
4122 | return 1; | |
4123 | } | |
4124 | } | |
4125 | reply("OSMSG_NOT_BAD_WORD", argv[1]); | |
4126 | return 0; | |
4127 | } | |
4128 | ||
4129 | static MODCMD_FUNC(cmd_addexempt) | |
4130 | { | |
4131 | const char *chanName; | |
4132 | ||
4133 | if ((argc > 1) && IsChannelName(argv[1])) { | |
4134 | chanName = argv[1]; | |
4135 | } else { | |
4136 | reply("MSG_NOT_CHANNEL_NAME"); | |
4137 | OPSERV_SYNTAX(); | |
4138 | return 0; | |
4139 | } | |
4140 | dict_insert(opserv_exempt_channels, strdup(chanName), NULL); | |
4141 | channel = GetChannel(chanName); | |
4142 | if (channel) { | |
4143 | if (channel->bad_channel) { | |
4144 | DelChannelUser(cmd->parent->bot, channel, "Channel is now exempt from bad-word checking.", 1); | |
4145 | timeq_del(0, opserv_part_channel, channel, TIMEQ_IGNORE_WHEN); | |
4146 | } | |
4147 | channel->bad_channel = 0; | |
4148 | } | |
4149 | reply("OSMSG_ADDED_EXEMPTION", chanName); | |
4150 | return 1; | |
4151 | } | |
4152 | ||
4153 | static MODCMD_FUNC(cmd_delexempt) | |
4154 | { | |
4155 | const char *chanName; | |
4156 | ||
4157 | if ((argc > 1) && IsChannelName(argv[1])) { | |
4158 | chanName = argv[1]; | |
4159 | } else { | |
4160 | reply("MSG_NOT_CHANNEL_NAME"); | |
4161 | OPSERV_SYNTAX(); | |
4162 | return 0; | |
4163 | } | |
4164 | if (!dict_remove(opserv_exempt_channels, chanName)) { | |
4165 | reply("OSMSG_NOT_EXEMPT", chanName); | |
4166 | return 0; | |
4167 | } | |
4168 | reply("OSMSG_REMOVED_EXEMPTION", chanName); | |
4169 | return 1; | |
4170 | } | |
4171 | ||
4172 | static void | |
4173 | opserv_expire_trusted_host(void *data) | |
4174 | { | |
4175 | struct trusted_host *th = data; | |
4176 | dict_remove(opserv_trusted_hosts, th->ipaddr); | |
4177 | } | |
4178 | ||
4179 | static void | |
4180 | opserv_add_trusted_host(const char *ipaddr, unsigned int limit, const char *issuer, time_t issued, time_t expires, const char *reason) | |
4181 | { | |
4182 | struct trusted_host *th; | |
4183 | th = calloc(1, sizeof(*th)); | |
4184 | if (!th) | |
4185 | return; | |
4186 | th->ipaddr = strdup(ipaddr); | |
4187 | th->reason = reason ? strdup(reason) : NULL; | |
4188 | th->issuer = issuer ? strdup(issuer) : NULL; | |
4189 | th->issued = issued; | |
4190 | th->limit = limit; | |
4191 | th->expires = expires; | |
4192 | dict_insert(opserv_trusted_hosts, th->ipaddr, th); | |
4193 | if (th->expires) | |
4194 | timeq_add(th->expires, opserv_expire_trusted_host, th); | |
4195 | } | |
4196 | ||
4197 | static void | |
4198 | free_trusted_host(void *data) | |
4199 | { | |
4200 | struct trusted_host *th = data; | |
4201 | free(th->ipaddr); | |
4202 | free(th->reason); | |
4203 | free(th->issuer); | |
4204 | free(th); | |
4205 | } | |
4206 | ||
4207 | static MODCMD_FUNC(cmd_addtrust) | |
4208 | { | |
4209 | unsigned long interval; | |
4210 | char *reason, *tmp; | |
2f61d1d7 | 4211 | irc_in_addr_t tmpaddr; |
d76ed9a9 | 4212 | unsigned int count; |
4213 | ||
4214 | if (dict_find(opserv_trusted_hosts, argv[1], NULL)) { | |
4215 | reply("OSMSG_ALREADY_TRUSTED", argv[1]); | |
4216 | return 0; | |
4217 | } | |
4218 | ||
2f61d1d7 | 4219 | if (!irc_pton(&tmpaddr, NULL, argv[1])) { |
d76ed9a9 | 4220 | reply("OSMSG_BAD_IP", argv[1]); |
4221 | return 0; | |
4222 | } | |
4223 | ||
4224 | count = strtoul(argv[2], &tmp, 10); | |
4225 | if (*tmp != '\0') { | |
4226 | reply("OSMSG_BAD_NUMBER", argv[2]); | |
4227 | return 0; | |
4228 | } | |
4229 | ||
4230 | interval = ParseInterval(argv[3]); | |
4231 | if (!interval && strcmp(argv[3], "0")) { | |
4232 | reply("MSG_INVALID_DURATION", argv[3]); | |
4233 | return 0; | |
4234 | } | |
4235 | ||
4236 | reason = unsplit_string(argv+4, argc-4, NULL); | |
4237 | opserv_add_trusted_host(argv[1], count, user->handle_info->handle, now, interval ? (now + interval) : 0, reason); | |
4238 | reply("OSMSG_ADDED_TRUSTED"); | |
4239 | return 1; | |
4240 | } | |
4241 | ||
4242 | static MODCMD_FUNC(cmd_edittrust) | |
4243 | { | |
4244 | unsigned long interval; | |
4245 | struct trusted_host *th; | |
4246 | char *reason, *tmp; | |
4247 | unsigned int count; | |
4248 | ||
4249 | th = dict_find(opserv_trusted_hosts, argv[1], NULL); | |
4250 | if (!th) { | |
4251 | reply("OSMSG_NOT_TRUSTED", argv[1]); | |
4252 | return 0; | |
4253 | } | |
4254 | count = strtoul(argv[2], &tmp, 10); | |
4255 | if (!count || *tmp) { | |
4256 | reply("OSMSG_BAD_NUMBER", argv[2]); | |
4257 | return 0; | |
4258 | } | |
4259 | interval = ParseInterval(argv[3]); | |
4260 | if (!interval && strcmp(argv[3], "0")) { | |
4261 | reply("MSG_INVALID_DURATION", argv[3]); | |
4262 | return 0; | |
4263 | } | |
4264 | reason = unsplit_string(argv+4, argc-4, NULL); | |
4265 | if (th->expires) | |
4266 | timeq_del(th->expires, opserv_expire_trusted_host, th, 0); | |
4267 | ||
4268 | free(th->reason); | |
4269 | th->reason = strdup(reason); | |
4270 | free(th->issuer); | |
4271 | th->issuer = strdup(user->handle_info->handle); | |
4272 | th->issued = now; | |
4273 | th->limit = count; | |
4274 | if (interval) { | |
4275 | th->expires = now + interval; | |
4276 | timeq_add(th->expires, opserv_expire_trusted_host, th); | |
4277 | } else | |
4278 | th->expires = 0; | |
4279 | reply("OSMSG_UPDATED_TRUSTED", th->ipaddr); | |
4280 | return 1; | |
4281 | } | |
4282 | ||
4283 | static MODCMD_FUNC(cmd_deltrust) | |
4284 | { | |
4285 | unsigned int n; | |
4286 | ||
4287 | for (n=1; n<argc; n++) { | |
4288 | struct trusted_host *th = dict_find(opserv_trusted_hosts, argv[n], NULL); | |
4289 | if (!th) | |
4290 | continue; | |
4291 | if (th->expires) | |
4292 | timeq_del(th->expires, opserv_expire_trusted_host, th, 0); | |
4293 | dict_remove(opserv_trusted_hosts, argv[n]); | |
4294 | } | |
4295 | reply("OSMSG_REMOVED_TRUSTED"); | |
4296 | return 1; | |
4297 | } | |
4298 | ||
4299 | /* This doesn't use dict_t because it's a little simpler to open-code the | |
4300 | * comparisons (and simpler arg-passing for the ADD subcommand). | |
4301 | */ | |
4302 | static MODCMD_FUNC(cmd_clone) | |
4303 | { | |
4304 | int i; | |
4305 | struct userNode *clone; | |
4306 | ||
4307 | clone = GetUserH(argv[2]); | |
4308 | if (!irccasecmp(argv[1], "ADD")) { | |
4309 | char *userinfo; | |
4310 | char ident[USERLEN+1]; | |
4311 | ||
258d1427 | 4312 | if (argc < 5) { |
4313 | reply("MSG_MISSING_PARAMS", argv[1]); | |
4314 | OPSERV_SYNTAX(); | |
4315 | return 0; | |
4316 | } | |
4317 | if (clone) { | |
4318 | reply("OSMSG_CLONE_EXISTS", argv[2]); | |
4319 | return 0; | |
4320 | } | |
4321 | userinfo = unsplit_string(argv+4, argc-4, NULL); | |
4322 | for (i=0; argv[3][i] && (i<USERLEN); i++) { | |
4323 | if (argv[3][i] == '@') { | |
4324 | ident[i++] = 0; | |
4325 | break; | |
4326 | } else { | |
d76ed9a9 | 4327 | ident[i] = argv[3][i]; |
4328 | } | |
258d1427 | 4329 | } |
4330 | if (!argv[3][i] || (i==USERLEN)) { | |
4331 | reply("OSMSG_NOT_A_HOSTMASK"); | |
4332 | return 0; | |
4333 | } | |
0f6fe38c | 4334 | if (!(clone = AddClone(argv[2], ident, argv[3]+i, userinfo))) { |
d76ed9a9 | 4335 | reply("OSMSG_CLONE_FAILED", argv[2]); |
4336 | return 0; | |
4337 | } | |
4338 | reply("OSMSG_CLONE_ADDED", clone->nick); | |
258d1427 | 4339 | return 1; |
d76ed9a9 | 4340 | } |
4341 | if (!clone) { | |
258d1427 | 4342 | reply("MSG_NICK_UNKNOWN", argv[2]); |
4343 | return 0; | |
d76ed9a9 | 4344 | } |
4345 | if (clone->uplink != self || IsService(clone)) { | |
258d1427 | 4346 | reply("OSMSG_NOT_A_CLONE", clone->nick); |
4347 | return 0; | |
d76ed9a9 | 4348 | } |
4349 | if (!irccasecmp(argv[1], "REMOVE")) { | |
258d1427 | 4350 | const char *reason; |
4351 | if (argc > 3) { | |
4352 | reason = unsplit_string(argv+3, argc-3, NULL); | |
4353 | } else { | |
4354 | char *tmp; | |
4355 | tmp = alloca(strlen(clone->nick) + strlen(OSMSG_PART_REASON)); | |
4356 | sprintf(tmp, OSMSG_PART_REASON, clone->nick); | |
4357 | reason = tmp; | |
4358 | } | |
4359 | DelUser(clone, NULL, 1, reason); | |
4360 | reply("OSMSG_CLONE_REMOVED", argv[2]); | |
4361 | return 1; | |
d76ed9a9 | 4362 | } |
4363 | if (argc < 4) { | |
258d1427 | 4364 | reply("MSG_MISSING_PARAMS", argv[1]); |
4365 | OPSERV_SYNTAX(); | |
4366 | return 0; | |
d76ed9a9 | 4367 | } |
4368 | channel = GetChannel(argv[3]); | |
4369 | if (!irccasecmp(argv[1], "JOIN")) { | |
258d1427 | 4370 | if (!channel |
4371 | && !(channel = AddChannel(argv[3], now, NULL, NULL, NULL))) { | |
4372 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
4373 | return 0; | |
4374 | } | |
4375 | AddChannelUser(clone, channel); | |
4376 | reply("OSMSG_CLONE_JOINED", clone->nick, channel->name); | |
4377 | return 1; | |
d76ed9a9 | 4378 | } |
4379 | if (!irccasecmp(argv[1], "PART")) { | |
258d1427 | 4380 | if (!channel) { |
4381 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
4382 | return 0; | |
4383 | } | |
4384 | if (!GetUserMode(channel, clone)) { | |
4385 | reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); | |
4386 | return 0; | |
4387 | } | |
4388 | reply("OSMSG_CLONE_PARTED", clone->nick, channel->name); | |
4389 | DelChannelUser(clone, channel, "Leaving.", 0); | |
4390 | return 1; | |
d76ed9a9 | 4391 | } |
4392 | if (!irccasecmp(argv[1], "OP")) { | |
4393 | struct mod_chanmode change; | |
258d1427 | 4394 | if (!channel) { |
4395 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
4396 | return 0; | |
4397 | } | |
d76ed9a9 | 4398 | mod_chanmode_init(&change); |
4399 | change.argc = 1; | |
4400 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 4401 | change.args[0].u.member = GetUserMode(channel, clone); |
4402 | if (!change.args[0].u.member) { | |
d76ed9a9 | 4403 | reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); |
4404 | return 0; | |
258d1427 | 4405 | } |
d76ed9a9 | 4406 | modcmd_chanmode_announce(&change); |
258d1427 | 4407 | reply("OSMSG_OPS_GIVEN", channel->name, clone->nick); |
4408 | return 1; | |
d76ed9a9 | 4409 | } |
55342ce8 | 4410 | if (!irccasecmp(argv[1], "HOP")) { |
4411 | struct mod_chanmode change; | |
4412 | if (!channel) { | |
4413 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
4414 | return 0; | |
4415 | } | |
4416 | mod_chanmode_init(&change); | |
4417 | change.argc = 1; | |
4418 | change.args[0].mode = MODE_HALFOP; | |
11408ce4 | 4419 | change.args[0].u.member = GetUserMode(channel, clone); |
4420 | if (!change.args[0].u.member) { | |
55342ce8 | 4421 | reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); |
4422 | return 0; | |
4423 | } | |
4424 | modcmd_chanmode_announce(&change); | |
4425 | reply("OSMSG_HOPS_GIVEN", channel->name, clone->nick); | |
4426 | return 1; | |
4427 | } | |
d76ed9a9 | 4428 | if (argc < 5) { |
258d1427 | 4429 | reply("MSG_MISSING_PARAMS", argv[1]); |
4430 | OPSERV_SYNTAX(); | |
4431 | return 0; | |
d76ed9a9 | 4432 | } |
4433 | if (!irccasecmp(argv[1], "SAY")) { | |
258d1427 | 4434 | char *text = unsplit_string(argv+4, argc-4, NULL); |
4435 | irc_privmsg(clone, argv[3], text); | |
4436 | reply("OSMSG_CLONE_SAID", clone->nick, argv[3]); | |
4437 | return 1; | |
d76ed9a9 | 4438 | } |
4439 | reply("OSMSG_UNKNOWN_SUBCOMMAND", argv[1], argv[0]); | |
4440 | return 0; | |
4441 | } | |
4442 | ||
4443 | static struct helpfile_expansion | |
4444 | opserv_help_expand(const char *variable) | |
4445 | { | |
4446 | extern struct userNode *message_source; | |
4447 | struct helpfile_expansion exp; | |
4448 | struct service *service; | |
4449 | struct svccmd *cmd; | |
4450 | dict_iterator_t it; | |
4451 | int row; | |
4452 | unsigned int level; | |
4453 | ||
4454 | if (!(service = service_find(message_source->nick))) { | |
4455 | exp.type = HF_STRING; | |
4456 | exp.value.str = NULL; | |
4457 | } else if (!irccasecmp(variable, "index")) { | |
4458 | exp.type = HF_TABLE; | |
4459 | exp.value.table.length = 1; | |
4460 | exp.value.table.width = 2; | |
4461 | exp.value.table.flags = TABLE_REPEAT_HEADERS | TABLE_REPEAT_ROWS; | |
4462 | exp.value.table.contents = calloc(dict_size(service->commands)+1, sizeof(char**)); | |
4463 | exp.value.table.contents[0] = calloc(exp.value.table.width, sizeof(char*)); | |
4464 | exp.value.table.contents[0][0] = "Command"; | |
4465 | exp.value.table.contents[0][1] = "Level"; | |
4466 | for (it=dict_first(service->commands); it; it=iter_next(it)) { | |
4467 | cmd = iter_data(it); | |
4468 | row = exp.value.table.length++; | |
4469 | exp.value.table.contents[row] = calloc(exp.value.table.width, sizeof(char*)); | |
4470 | exp.value.table.contents[row][0] = iter_key(it); | |
4471 | level = cmd->min_opserv_level; | |
4472 | if (!level_strings[level]) { | |
4473 | level_strings[level] = malloc(16); | |
4474 | snprintf(level_strings[level], 16, "%3d", level); | |
4475 | } | |
4476 | exp.value.table.contents[row][1] = level_strings[level]; | |
4477 | } | |
4478 | } else if (!strncasecmp(variable, "level", 5)) { | |
4479 | cmd = dict_find(service->commands, variable+6, NULL); | |
4480 | exp.type = HF_STRING; | |
4481 | if (cmd) { | |
4482 | level = cmd->min_opserv_level; | |
4483 | exp.value.str = malloc(16); | |
4484 | snprintf(exp.value.str, 16, "%3d", level); | |
4485 | } else { | |
4486 | exp.value.str = NULL; | |
4487 | } | |
4488 | } else { | |
4489 | exp.type = HF_STRING; | |
4490 | exp.value.str = NULL; | |
4491 | } | |
4492 | return exp; | |
4493 | } | |
4494 | ||
4495 | struct modcmd * | |
4496 | opserv_define_func(const char *name, modcmd_func_t *func, int min_level, int reqchan, int min_argc) | |
4497 | { | |
4498 | char buf[16], *flags = NULL; | |
4499 | unsigned int iflags = 0; | |
4500 | sprintf(buf, "%d", min_level); | |
4501 | switch (reqchan) { | |
4502 | case 1: flags = "+acceptchan"; break; | |
4503 | case 3: flags = "+acceptpluschan"; /* fall through */ | |
4504 | case 2: iflags = MODCMD_REQUIRE_CHANNEL; break; | |
4505 | } | |
4506 | if (flags) { | |
4507 | return modcmd_register(opserv_module, name, func, min_argc, iflags, "level", buf, "flags", flags, "flags", "+oper", NULL); | |
4508 | } else { | |
4509 | return modcmd_register(opserv_module, name, func, min_argc, iflags, "level", buf, "flags", "+oper", NULL); | |
4510 | } | |
4511 | } | |
4512 | ||
4513 | int add_reserved(const char *key, void *data, void *extra) | |
4514 | { | |
7637f48f | 4515 | struct chanNode *chan; |
d76ed9a9 | 4516 | struct record_data *rd = data; |
4517 | const char *ident, *hostname, *desc; | |
7637f48f | 4518 | unsigned int i; |
d76ed9a9 | 4519 | struct userNode *reserve; |
4520 | ident = database_get_data(rd->d.object, KEY_IDENT, RECDB_QSTRING); | |
4521 | if (!ident) { | |
258d1427 | 4522 | log_module(OS_LOG, LOG_ERROR, "Missing ident for reserve of %s", key); |
4523 | return 0; | |
d76ed9a9 | 4524 | } |
4525 | hostname = database_get_data(rd->d.object, KEY_HOSTNAME, RECDB_QSTRING); | |
4526 | if (!hostname) { | |
258d1427 | 4527 | log_module(OS_LOG, LOG_ERROR, "Missing hostname for reserve of %s", key); |
4528 | return 0; | |
d76ed9a9 | 4529 | } |
4530 | desc = database_get_data(rd->d.object, KEY_DESC, RECDB_QSTRING); | |
4531 | if (!desc) { | |
258d1427 | 4532 | log_module(OS_LOG, LOG_ERROR, "Missing description for reserve of %s", key); |
4533 | return 0; | |
d76ed9a9 | 4534 | } |
0f6fe38c | 4535 | if ((reserve = AddClone(key, ident, hostname, desc))) { |
d76ed9a9 | 4536 | reserve->modes |= FLAGS_PERSISTENT; |
4537 | dict_insert(extra, reserve->nick, reserve); | |
4538 | } | |
7637f48f | 4539 | |
4540 | if (autojoin_channels && reserve) { | |
4541 | for (i = 0; i < autojoin_channels->used; i++) { | |
4542 | chan = AddChannel(autojoin_channels->list[i], now, "+nt", NULL, NULL); | |
4543 | AddChannelUser(reserve, chan)->modes |= MODE_VOICE; | |
4544 | } | |
4545 | } | |
4546 | ||
d76ed9a9 | 4547 | return 0; |
4548 | } | |
4549 | ||
4550 | static unsigned int | |
4551 | foreach_matching_user(const char *hostmask, discrim_search_func func, void *extra) | |
4552 | { | |
4553 | discrim_t discrim; | |
4554 | char *dupmask; | |
4555 | unsigned int matched; | |
4556 | ||
4557 | if (!self->uplink) return 0; | |
4558 | discrim = calloc(1, sizeof(*discrim)); | |
4559 | discrim->limit = dict_size(clients); | |
4560 | discrim->max_level = ~0; | |
4561 | discrim->max_ts = now; | |
4562 | discrim->max_channels = INT_MAX; | |
4563 | discrim->authed = -1; | |
4564 | discrim->info_space = -1; | |
63665495 | 4565 | discrim->intra_scmp = 0; |
4566 | discrim->intra_dcmp = 0; | |
27eaa617 | 4567 | discrim->use_regex = 0; |
1c5f6697 | 4568 | discrim->silent = 0; |
d76ed9a9 | 4569 | dupmask = strdup(hostmask); |
4570 | if (split_ircmask(dupmask, &discrim->mask_nick, &discrim->mask_ident, &discrim->mask_host)) { | |
2f61d1d7 | 4571 | if (!irc_pton(&discrim->ip_mask, &discrim->ip_mask_bits, discrim->mask_host)) |
4572 | discrim->ip_mask_bits = 0; | |
d76ed9a9 | 4573 | matched = opserv_discrim_search(discrim, func, extra); |
4574 | } else { | |
258d1427 | 4575 | log_module(OS_LOG, LOG_ERROR, "Couldn't split IRC mask for gag %s!", hostmask); |
d76ed9a9 | 4576 | matched = 0; |
4577 | } | |
4578 | free(discrim); | |
4579 | free(dupmask); | |
4580 | return matched; | |
4581 | } | |
4582 | ||
4583 | static unsigned int | |
4584 | gag_free(struct gag_entry *gag) | |
4585 | { | |
4586 | unsigned int ungagged; | |
4587 | ||
4588 | /* Remove from gag list */ | |
4589 | if (gagList == gag) { | |
4590 | gagList = gag->next; | |
4591 | } else { | |
4592 | struct gag_entry *prev; | |
4593 | for (prev = gagList; prev->next != gag; prev = prev->next) ; | |
4594 | prev->next = gag->next; | |
4595 | } | |
4596 | ||
4597 | ungagged = foreach_matching_user(gag->mask, ungag_helper_func, NULL); | |
4598 | ||
4599 | /* Deallocate storage */ | |
4600 | free(gag->reason); | |
4601 | free(gag->owner); | |
4602 | free(gag->mask); | |
4603 | free(gag); | |
4604 | ||
4605 | return ungagged; | |
4606 | } | |
4607 | ||
4608 | static void | |
4609 | gag_expire(void *data) | |
4610 | { | |
4611 | gag_free(data); | |
4612 | } | |
4613 | ||
4614 | unsigned int | |
4615 | gag_create(const char *mask, const char *owner, const char *reason, time_t expires) | |
4616 | { | |
4617 | struct gag_entry *gag; | |
4618 | ||
4619 | /* Create gag and put it into linked list */ | |
4620 | gag = calloc(1, sizeof(*gag)); | |
4621 | gag->mask = strdup(mask); | |
4622 | gag->owner = strdup(owner ? owner : "<unknown>"); | |
4623 | gag->reason = strdup(reason ? reason : "<unknown>"); | |
4624 | gag->expires = expires; | |
4625 | if (gag->expires) | |
4626 | timeq_add(gag->expires, gag_expire, gag); | |
4627 | gag->next = gagList; | |
4628 | gagList = gag; | |
4629 | ||
4630 | /* If we're linked, see if who the gag applies to */ | |
4631 | return foreach_matching_user(mask, gag_helper_func, gag); | |
4632 | } | |
4633 | ||
4634 | static int | |
4635 | add_gag_helper(const char *key, void *data, UNUSED_ARG(void *extra)) | |
4636 | { | |
4637 | struct record_data *rd = data; | |
4638 | char *owner, *reason, *expstr; | |
4639 | time_t expires; | |
4640 | ||
4641 | owner = database_get_data(rd->d.object, KEY_OWNER, RECDB_QSTRING); | |
4642 | reason = database_get_data(rd->d.object, KEY_REASON, RECDB_QSTRING); | |
4643 | expstr = database_get_data(rd->d.object, KEY_EXPIRES, RECDB_QSTRING); | |
4644 | expires = expstr ? strtoul(expstr, NULL, 0) : 0; | |
4645 | gag_create(key, owner, reason, expires); | |
4646 | ||
4647 | return 0; | |
4648 | } | |
4649 | ||
4650 | static struct opserv_user_alert * | |
4651 | opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_reaction reaction, const char *text_discrim) | |
4652 | { | |
4653 | unsigned int wordc; | |
4654 | char *wordv[MAXNUMPARAMS], *discrim_copy; | |
4655 | struct opserv_user_alert *alert; | |
4656 | char *name_dup; | |
4657 | ||
4658 | if (dict_find(opserv_user_alerts, name, NULL)) { | |
258d1427 | 4659 | send_message(req, opserv, "OSMSG_ALERT_EXISTS", name); |
4660 | return NULL; | |
d76ed9a9 | 4661 | } |
4662 | alert = malloc(sizeof(*alert)); | |
4663 | alert->owner = strdup(req->handle_info ? req->handle_info->handle : req->nick); | |
4664 | alert->text_discrim = strdup(text_discrim); | |
4665 | discrim_copy = strdup(text_discrim); /* save a copy of the discrim */ | |
4666 | wordc = split_line(discrim_copy, false, ArrayLength(wordv), wordv); | |
258d1427 | 4667 | alert->discrim = opserv_discrim_create(req, opserv, wordc, wordv, 0); |
d82cf2f0 | 4668 | /* Check for missing required criteria or broken records */ |
39c1a4ef | 4669 | if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget) || |
d82cf2f0 | 4670 | (reaction==REACT_SVSPART && !alert->discrim->chantarget) || |
4671 | (reaction==REACT_MARK && !alert->discrim->mark)) { | |
d76ed9a9 | 4672 | free(alert->text_discrim); |
4673 | free(discrim_copy); | |
4674 | free(alert); | |
4675 | return NULL; | |
4676 | } | |
4677 | alert->split_discrim = discrim_copy; | |
4678 | name_dup = strdup(name); | |
4679 | if (!alert->discrim->reason) | |
4680 | alert->discrim->reason = strdup(name); | |
4681 | alert->reaction = reaction; | |
4682 | dict_insert(opserv_user_alerts, name_dup, alert); | |
697f4c9a | 4683 | /* Stick the alert into the appropriate additional alert dict(s). |
4684 | * For channel alerts, we only use channels and min_channels; | |
4685 | * max_channels would have to be checked on /part, which we do not | |
4686 | * yet do, and which seems of questionable value. | |
4687 | */ | |
0f6fe38c | 4688 | if (alert->discrim->channel || alert->discrim->min_channels) |
d76ed9a9 | 4689 | dict_insert(opserv_channel_alerts, name_dup, alert); |
697f4c9a | 4690 | if (alert->discrim->mask_nick) |
d76ed9a9 | 4691 | dict_insert(opserv_nick_based_alerts, name_dup, alert); |
4692 | return alert; | |
4693 | } | |
4694 | ||
de9510bc | 4695 | /* |
d76ed9a9 | 4696 | static int |
4697 | add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra)) | |
4698 | { | |
4699 | struct record_data *rd = data; | |
4700 | char *reason = GET_RECORD_QSTRING(rd); | |
4701 | ||
de9510bc | 4702 | * i hope this can't happen * |
d76ed9a9 | 4703 | if (!reason) |
4704 | reason = "No Reason"; | |
4705 | ||
4706 | dict_insert(opserv_chan_warn, strdup(key), strdup(reason)); | |
4707 | return 0; | |
4708 | } | |
de9510bc | 4709 | */ |
d76ed9a9 | 4710 | |
47956fc5 | 4711 | |
d76ed9a9 | 4712 | static int |
4713 | add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) | |
4714 | { | |
4715 | dict_t alert_dict; | |
4716 | const char *discrim, *react, *owner; | |
4717 | opserv_alert_reaction reaction; | |
4718 | struct opserv_user_alert *alert; | |
4719 | ||
4720 | if (!(alert_dict = GET_RECORD_OBJECT((struct record_data *)data))) { | |
4721 | log_module(OS_LOG, LOG_ERROR, "Bad type (not a record) for alert %s.", key); | |
4722 | return 1; | |
4723 | } | |
4724 | discrim = database_get_data(alert_dict, KEY_DISCRIM, RECDB_QSTRING); | |
4725 | react = database_get_data(alert_dict, KEY_REACTION, RECDB_QSTRING); | |
4726 | if (!react || !irccasecmp(react, "notice")) | |
4727 | reaction = REACT_NOTICE; | |
4728 | else if (!irccasecmp(react, "kill")) | |
4729 | reaction = REACT_KILL; | |
1c5f6697 | 4730 | /* |
9a75756e | 4731 | else if (!irccasecmp(react, "silent")) |
4732 | reaction = REACT_SILENT; | |
1c5f6697 | 4733 | */ |
d76ed9a9 | 4734 | else if (!irccasecmp(react, "gline")) |
4735 | reaction = REACT_GLINE; | |
ec311f39 | 4736 | else if (!irccasecmp(react, "track")) |
4737 | reaction = REACT_TRACK; | |
d914d1cb | 4738 | else if (!irccasecmp(react, "shun")) |
4739 | reaction = REACT_SHUN; | |
c408f18a | 4740 | else if (!irccasecmp(react, "svsjoin")) |
4741 | reaction = REACT_SVSJOIN; | |
39c1a4ef | 4742 | else if (!irccasecmp(react, "svspart")) |
4743 | reaction = REACT_SVSPART; | |
0e08a8e0 | 4744 | else if (!irccasecmp(react, "version")) |
4745 | reaction = REACT_VERSION; | |
d82cf2f0 | 4746 | else if (!irccasecmp(react, "mark")) |
4747 | reaction = REACT_MARK; | |
d76ed9a9 | 4748 | else { |
4749 | log_module(OS_LOG, LOG_ERROR, "Invalid reaction %s for alert %s.", react, key); | |
4750 | return 0; | |
4751 | } | |
4752 | alert = opserv_add_user_alert(opserv, key, reaction, discrim); | |
4753 | if (!alert) { | |
4754 | log_module(OS_LOG, LOG_ERROR, "Unable to create alert %s from database.", key); | |
4755 | return 0; | |
4756 | } | |
4757 | owner = database_get_data(alert_dict, KEY_OWNER, RECDB_QSTRING); | |
4758 | free(alert->owner); | |
4759 | alert->owner = strdup(owner ? owner : "<unknown>"); | |
4760 | return 0; | |
4761 | } | |
4762 | ||
4763 | static int | |
4764 | trusted_host_read(const char *host, void *data, UNUSED_ARG(void *extra)) | |
4765 | { | |
4766 | struct record_data *rd = data; | |
4767 | const char *limit, *str, *reason, *issuer; | |
4768 | time_t issued, expires; | |
4769 | ||
4770 | if (rd->type == RECDB_QSTRING) { | |
4771 | /* old style host by itself */ | |
4772 | limit = GET_RECORD_QSTRING(rd); | |
4773 | issued = 0; | |
4774 | issuer = NULL; | |
4775 | expires = 0; | |
4776 | reason = NULL; | |
4777 | } else if (rd->type == RECDB_OBJECT) { | |
4778 | dict_t obj = GET_RECORD_OBJECT(rd); | |
4779 | /* new style structure */ | |
4780 | limit = database_get_data(obj, KEY_LIMIT, RECDB_QSTRING); | |
4781 | str = database_get_data(obj, KEY_EXPIRES, RECDB_QSTRING); | |
4782 | expires = str ? ParseInterval(str) : 0; | |
4783 | reason = database_get_data(obj, KEY_REASON, RECDB_QSTRING); | |
4784 | issuer = database_get_data(obj, KEY_ISSUER, RECDB_QSTRING); | |
4785 | str = database_get_data(obj, KEY_ISSUED, RECDB_QSTRING); | |
4786 | issued = str ? ParseInterval(str) : 0; | |
4787 | } else | |
4788 | return 0; | |
4789 | ||
4790 | if (expires && (expires < now)) | |
4791 | return 0; | |
4792 | opserv_add_trusted_host(host, (limit ? strtoul(limit, NULL, 0) : 0), issuer, issued, expires, reason); | |
4793 | return 0; | |
4794 | } | |
4795 | ||
47956fc5 | 4796 | static int |
4797 | add_routing_plan_server(const char *name, void *data, void *rp) | |
4798 | { | |
4799 | struct record_data *rd = data; | |
4800 | const char *uplink, *portstr, *karma, *second, *offline; | |
4801 | ||
4802 | dict_t obj = GET_RECORD_OBJECT(rd); | |
4803 | if(rd->type == RECDB_OBJECT) { | |
4804 | uplink = database_get_data(obj, KEY_UPLINK, RECDB_QSTRING); | |
4805 | second = database_get_data(obj, KEY_SECOND, RECDB_QSTRING); | |
4806 | portstr = database_get_data(obj, KEY_PORT, RECDB_QSTRING); | |
4807 | karma = database_get_data(obj, KEY_KARMA, RECDB_QSTRING); | |
4808 | offline = database_get_data(obj, KEY_OFFLINE, RECDB_QSTRING); | |
4809 | /* create routing plan server named key, with uplink uplink. */ | |
4810 | opserv_routing_plan_add_server(rp, name, uplink, portstr ? atoi(portstr) : 0, | |
4811 | karma ? atoi(karma) : KARMA_DEFAULT, second, | |
4812 | offline ? atoi(offline) : 0); | |
4813 | } | |
4814 | return 0; | |
4815 | ||
4816 | } | |
4817 | ||
4818 | static int | |
4819 | routing_plan_set_option(const char *name, void *data, UNUSED_ARG(void *extra)) | |
4820 | { | |
4821 | struct record_data *rd = data; | |
4822 | if(rd->type == RECDB_QSTRING) | |
4823 | { | |
4824 | char *value = GET_RECORD_QSTRING(rd); | |
4825 | dict_insert(opserv_routing_plan_options, strdup(name), strdup(value)); | |
4826 | } | |
4827 | return 0; | |
4828 | } | |
4829 | ||
4830 | static int | |
4831 | add_routing_plan(const char *name, void *data, UNUSED_ARG(void *extra)) | |
4832 | { | |
4833 | struct record_data *rd = data; | |
4834 | struct routingPlan *rp; | |
4835 | ||
4836 | if(rd->type == RECDB_OBJECT) { | |
4837 | dict_t obj = GET_RECORD_OBJECT(rd); | |
4838 | rp = opserv_add_routing_plan(name); | |
4839 | dict_foreach(obj, add_routing_plan_server, rp); | |
4840 | } | |
4841 | return 0; | |
4842 | } | |
4843 | ||
d76ed9a9 | 4844 | static int |
4845 | opserv_saxdb_read(struct dict *conf_db) | |
4846 | { | |
4847 | dict_t object; | |
4848 | struct record_data *rd; | |
4849 | dict_iterator_t it; | |
4850 | unsigned int nn; | |
4851 | ||
4852 | if ((object = database_get_data(conf_db, KEY_RESERVES, RECDB_OBJECT))) | |
4853 | dict_foreach(object, add_reserved, opserv_reserved_nick_dict); | |
4854 | if ((rd = database_get_path(conf_db, KEY_BAD_WORDS))) { | |
4855 | switch (rd->type) { | |
4856 | case RECDB_STRING_LIST: | |
4857 | /* Add words one by one just in case there are overlaps from an old DB. */ | |
4858 | for (nn=0; nn<rd->d.slist->used; ++nn) | |
4859 | opserv_add_bad_word(NULL, NULL, rd->d.slist->list[nn]); | |
4860 | break; | |
4861 | case RECDB_OBJECT: | |
4862 | for (it=dict_first(rd->d.object); it; it=iter_next(it)) { | |
4863 | opserv_add_bad_word(NULL, NULL, iter_key(it)); | |
4864 | rd = iter_data(it); | |
4865 | if (rd->type == RECDB_STRING_LIST) | |
4866 | for (nn=0; nn<rd->d.slist->used; nn++) | |
4867 | dict_insert(opserv_exempt_channels, strdup(rd->d.slist->list[nn]), NULL); | |
4868 | } | |
4869 | break; | |
4870 | default: | |
4871 | /* do nothing */; | |
4872 | } | |
4873 | } | |
4874 | if ((rd = database_get_path(conf_db, KEY_EXEMPT_CHANNELS)) | |
4875 | && (rd->type == RECDB_STRING_LIST)) { | |
4876 | for (nn=0; nn<rd->d.slist->used; ++nn) | |
4877 | dict_insert(opserv_exempt_channels, strdup(rd->d.slist->list[nn]), NULL); | |
4878 | } | |
4879 | if ((object = database_get_data(conf_db, KEY_MAX_CLIENTS, RECDB_OBJECT))) { | |
4880 | char *str; | |
4881 | if ((str = database_get_data(object, KEY_MAX, RECDB_QSTRING))) | |
4882 | max_clients = atoi(str); | |
4883 | if ((str = database_get_data(object, KEY_TIME, RECDB_QSTRING))) | |
4884 | max_clients_time = atoi(str); | |
4885 | } | |
4886 | if ((object = database_get_data(conf_db, KEY_TRUSTED_HOSTS, RECDB_OBJECT))) | |
4887 | dict_foreach(object, trusted_host_read, opserv_trusted_hosts); | |
4888 | if ((object = database_get_data(conf_db, KEY_GAGS, RECDB_OBJECT))) | |
4889 | dict_foreach(object, add_gag_helper, NULL); | |
4890 | if ((object = database_get_data(conf_db, KEY_ALERTS, RECDB_OBJECT))) | |
4891 | dict_foreach(object, add_user_alert, NULL); | |
de9510bc | 4892 | /* |
d76ed9a9 | 4893 | if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT))) |
4894 | dict_foreach(object, add_chan_warn, NULL); | |
de9510bc | 4895 | */ |
47956fc5 | 4896 | |
4897 | if ((object = database_get_data(conf_db, KEY_ROUTINGPLAN, RECDB_OBJECT))) | |
4898 | dict_foreach(object, add_routing_plan, NULL); | |
4899 | ||
4900 | if ((object = database_get_data(conf_db, KEY_ROUTINGPLAN_OPTIONS, RECDB_OBJECT))) | |
4901 | dict_foreach(object, routing_plan_set_option, NULL); | |
4902 | ||
d76ed9a9 | 4903 | return 0; |
4904 | } | |
4905 | ||
4906 | static int | |
4907 | opserv_saxdb_write(struct saxdb_context *ctx) | |
4908 | { | |
4909 | struct string_list *slist; | |
4910 | dict_iterator_t it; | |
4911 | ||
4912 | /* reserved nicks */ | |
4913 | if (dict_size(opserv_reserved_nick_dict)) { | |
4914 | saxdb_start_record(ctx, KEY_RESERVES, 1); | |
4915 | for (it = dict_first(opserv_reserved_nick_dict); it; it = iter_next(it)) { | |
4916 | struct userNode *user = iter_data(it); | |
4917 | if (!IsPersistent(user)) continue; | |
4918 | saxdb_start_record(ctx, iter_key(it), 0); | |
4919 | saxdb_write_string(ctx, KEY_IDENT, user->ident); | |
4920 | saxdb_write_string(ctx, KEY_HOSTNAME, user->hostname); | |
4921 | saxdb_write_string(ctx, KEY_DESC, user->info); | |
4922 | saxdb_end_record(ctx); | |
4923 | } | |
4924 | saxdb_end_record(ctx); | |
4925 | } | |
4926 | /* bad word set */ | |
4927 | if (opserv_bad_words->used) { | |
4928 | saxdb_write_string_list(ctx, KEY_BAD_WORDS, opserv_bad_words); | |
4929 | } | |
47956fc5 | 4930 | /* routing plan options */ |
4931 | if (dict_size(opserv_routing_plan_options)) { | |
4932 | saxdb_start_record(ctx, KEY_ROUTINGPLAN_OPTIONS, 1); | |
4933 | for(it = dict_first(opserv_routing_plan_options); it; it = iter_next(it)) { | |
4934 | saxdb_write_string(ctx, iter_key(it), iter_data(it)); | |
4935 | } | |
4936 | saxdb_end_record(ctx); | |
4937 | } | |
4938 | /* routing plans */ | |
4939 | if (dict_size(opserv_routing_plans)) { | |
4940 | dict_iterator_t svrit; | |
4941 | struct routingPlan *rp; | |
4942 | struct routingPlanServer *rps; | |
4943 | saxdb_start_record(ctx, KEY_ROUTINGPLAN, 1); | |
4944 | for (it = dict_first(opserv_routing_plans); it; it = iter_next(it)) { | |
4945 | rp = iter_data(it); | |
4946 | saxdb_start_record(ctx, iter_key(it), 0); | |
4947 | for(svrit = dict_first(rp->servers); svrit; svrit = iter_next(svrit)) { | |
4948 | char buf[MAXLEN]; | |
4949 | rps = iter_data(svrit); | |
4950 | saxdb_start_record(ctx, iter_key(svrit), 0); | |
4951 | saxdb_write_string(ctx, KEY_UPLINK, rps->uplink); | |
4952 | if(rps->secondaryuplink) | |
4953 | saxdb_write_string(ctx, KEY_SECOND, rps->secondaryuplink); | |
4954 | sprintf(buf, "%d", rps->port); | |
4955 | saxdb_write_string(ctx, KEY_PORT, buf); | |
4956 | sprintf(buf, "%d", rps->karma); | |
4957 | saxdb_write_string(ctx, KEY_KARMA, buf); | |
4958 | sprintf(buf, "%d", rps->offline); | |
4959 | saxdb_write_string(ctx, KEY_OFFLINE, buf); | |
4960 | saxdb_end_record(ctx); | |
4961 | } | |
4962 | saxdb_end_record(ctx); | |
4963 | } | |
4964 | saxdb_end_record(ctx); | |
4965 | } | |
d76ed9a9 | 4966 | /* insert exempt channel names */ |
4967 | if (dict_size(opserv_exempt_channels)) { | |
4968 | slist = alloc_string_list(dict_size(opserv_exempt_channels)); | |
4969 | for (it=dict_first(opserv_exempt_channels); it; it=iter_next(it)) { | |
4970 | string_list_append(slist, strdup(iter_key(it))); | |
4971 | } | |
4972 | saxdb_write_string_list(ctx, KEY_EXEMPT_CHANNELS, slist); | |
4973 | free_string_list(slist); | |
4974 | } | |
4975 | /* trusted hosts takes a little more work */ | |
4976 | if (dict_size(opserv_trusted_hosts)) { | |
4977 | saxdb_start_record(ctx, KEY_TRUSTED_HOSTS, 1); | |
4978 | for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) { | |
4979 | struct trusted_host *th = iter_data(it); | |
4980 | saxdb_start_record(ctx, iter_key(it), 0); | |
4981 | if (th->limit) saxdb_write_int(ctx, KEY_LIMIT, th->limit); | |
4982 | if (th->expires) saxdb_write_int(ctx, KEY_EXPIRES, th->expires); | |
4983 | if (th->issued) saxdb_write_int(ctx, KEY_ISSUED, th->issued); | |
4984 | if (th->issuer) saxdb_write_string(ctx, KEY_ISSUER, th->issuer); | |
4985 | if (th->reason) saxdb_write_string(ctx, KEY_REASON, th->reason); | |
4986 | saxdb_end_record(ctx); | |
4987 | } | |
4988 | saxdb_end_record(ctx); | |
4989 | } | |
4990 | /* gags */ | |
4991 | if (gagList) { | |
4992 | struct gag_entry *gag; | |
4993 | saxdb_start_record(ctx, KEY_GAGS, 1); | |
4994 | for (gag = gagList; gag; gag = gag->next) { | |
4995 | saxdb_start_record(ctx, gag->mask, 0); | |
4996 | saxdb_write_string(ctx, KEY_OWNER, gag->owner); | |
4997 | saxdb_write_string(ctx, KEY_REASON, gag->reason); | |
4998 | if (gag->expires) saxdb_write_int(ctx, KEY_EXPIRES, gag->expires); | |
4999 | saxdb_end_record(ctx); | |
5000 | } | |
5001 | saxdb_end_record(ctx); | |
5002 | } | |
5003 | /* channel warnings */ | |
de9510bc | 5004 | /* |
d76ed9a9 | 5005 | if (dict_size(opserv_chan_warn)) { |
5006 | saxdb_start_record(ctx, KEY_WARN, 0); | |
5007 | for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) { | |
5008 | saxdb_write_string(ctx, iter_key(it), iter_data(it)); | |
5009 | } | |
5010 | saxdb_end_record(ctx); | |
5011 | } | |
de9510bc | 5012 | */ |
d76ed9a9 | 5013 | /* alerts */ |
5014 | if (dict_size(opserv_user_alerts)) { | |
5015 | saxdb_start_record(ctx, KEY_ALERTS, 1); | |
5016 | for (it = dict_first(opserv_user_alerts); it; it = iter_next(it)) { | |
5017 | struct opserv_user_alert *alert = iter_data(it); | |
5018 | const char *reaction; | |
5019 | saxdb_start_record(ctx, iter_key(it), 0); | |
5020 | saxdb_write_string(ctx, KEY_DISCRIM, alert->text_discrim); | |
5021 | saxdb_write_string(ctx, KEY_OWNER, alert->owner); | |
5022 | switch (alert->reaction) { | |
5023 | case REACT_NOTICE: reaction = "notice"; break; | |
5024 | case REACT_KILL: reaction = "kill"; break; | |
1c5f6697 | 5025 | // case REACT_SILENT: reaction = "silent"; break; |
d76ed9a9 | 5026 | case REACT_GLINE: reaction = "gline"; break; |
ec311f39 | 5027 | case REACT_TRACK: reaction = "track"; break; |
d914d1cb | 5028 | case REACT_SHUN: reaction = "shun"; break; |
c408f18a | 5029 | case REACT_SVSJOIN: reaction = "svsjoin"; break; |
39c1a4ef | 5030 | case REACT_SVSPART: reaction = "svspart"; break; |
0e08a8e0 | 5031 | case REACT_VERSION: reaction = "version"; break; |
d82cf2f0 | 5032 | case REACT_MARK: reaction = "mark"; break; |
d76ed9a9 | 5033 | default: |
5034 | reaction = NULL; | |
5035 | log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s (while writing database).", alert->reaction, iter_key(it)); | |
5036 | break; | |
5037 | } | |
5038 | if (reaction) saxdb_write_string(ctx, KEY_REACTION, reaction); | |
5039 | saxdb_end_record(ctx); | |
5040 | } | |
5041 | saxdb_end_record(ctx); | |
5042 | } | |
5043 | /* max clients */ | |
5044 | saxdb_start_record(ctx, KEY_MAX_CLIENTS, 0); | |
5045 | saxdb_write_int(ctx, KEY_MAX, max_clients); | |
5046 | saxdb_write_int(ctx, KEY_TIME, max_clients_time); | |
5047 | saxdb_end_record(ctx); | |
5048 | return 0; | |
5049 | } | |
5050 | ||
5051 | static int | |
5052 | query_keys_helper(const char *key, UNUSED_ARG(void *data), void *extra) | |
5053 | { | |
5054 | send_message_type(4, extra, opserv, "$b%s$b", key); | |
5055 | return 0; | |
5056 | } | |
5057 | ||
5058 | static MODCMD_FUNC(cmd_query) | |
5059 | { | |
5060 | struct record_data *rd; | |
5061 | unsigned int i; | |
5062 | char *nodename; | |
5063 | ||
5064 | if (argc < 2) { | |
258d1427 | 5065 | reply("OSMSG_OPTION_ROOT"); |
5066 | conf_enum_root(query_keys_helper, user); | |
5067 | return 1; | |
d76ed9a9 | 5068 | } |
5069 | ||
5070 | nodename = unsplit_string(argv+1, argc-1, NULL); | |
5071 | if (!(rd = conf_get_node(nodename))) { | |
258d1427 | 5072 | reply("OSMSG_UNKNOWN_OPTION", nodename); |
5073 | return 0; | |
d76ed9a9 | 5074 | } |
5075 | ||
5076 | if (rd->type == RECDB_QSTRING) | |
258d1427 | 5077 | reply("OSMSG_OPTION_IS", nodename, rd->d.qstring); |
d76ed9a9 | 5078 | else if (rd->type == RECDB_STRING_LIST) { |
258d1427 | 5079 | reply("OSMSG_OPTION_LIST", nodename); |
5080 | if (rd->d.slist->used) | |
5081 | for (i=0; i<rd->d.slist->used; i++) | |
5082 | send_message_type(4, user, cmd->parent->bot, "$b%s$b", rd->d.slist->list[i]); | |
5083 | else | |
5084 | reply("OSMSG_OPTION_LIST_EMPTY"); | |
d76ed9a9 | 5085 | } else if (rd->type == RECDB_OBJECT) { |
258d1427 | 5086 | reply("OSMSG_OPTION_KEYS", nodename); |
5087 | dict_foreach(rd->d.object, query_keys_helper, user); | |
d76ed9a9 | 5088 | } |
5089 | ||
5090 | return 1; | |
5091 | } | |
5092 | ||
5093 | static MODCMD_FUNC(cmd_set) | |
5094 | { | |
5095 | struct record_data *rd; | |
5096 | ||
5097 | /* I originally wanted to be able to fully manipulate the config | |
5098 | db with this, but i wussed out. feel free to fix this - you'll | |
5099 | need to handle quoted strings which have been split, and likely | |
5100 | invent a syntax for it. -Zoot */ | |
5101 | ||
5102 | if (!(rd = conf_get_node(argv[1]))) { | |
258d1427 | 5103 | reply("OSMSG_SET_NOT_SET", argv[1]); |
5104 | return 0; | |
d76ed9a9 | 5105 | } |
5106 | ||
5107 | if (rd->type != RECDB_QSTRING) { | |
258d1427 | 5108 | reply("OSMSG_SET_BAD_TYPE", argv[1]); |
5109 | return 0; | |
d76ed9a9 | 5110 | } |
5111 | ||
5112 | free(rd->d.qstring); | |
5113 | rd->d.qstring = strdup(argv[2]); | |
5114 | conf_call_reload_funcs(); | |
5115 | reply("OSMSG_SET_SUCCESS", argv[1], argv[2]); | |
5116 | return 1; | |
5117 | } | |
5118 | ||
5119 | static MODCMD_FUNC(cmd_settime) | |
5120 | { | |
5121 | const char *srv_name_mask = "*"; | |
5122 | time_t new_time = now; | |
5123 | ||
5124 | if (argc > 1) | |
5125 | srv_name_mask = argv[1]; | |
5126 | if (argc > 2) | |
5127 | new_time = time(NULL); | |
5128 | irc_settime(srv_name_mask, new_time); | |
5129 | reply("OSMSG_SETTIME_SUCCESS", srv_name_mask); | |
5130 | return 1; | |
5131 | } | |
5132 | ||
5133 | static discrim_t | |
258d1427 | 5134 | opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[], int allow_channel) |
d76ed9a9 | 5135 | { |
5136 | unsigned int i, j; | |
5137 | discrim_t discrim; | |
5138 | ||
5139 | discrim = calloc(1, sizeof(*discrim)); | |
5140 | discrim->limit = 250; | |
5141 | discrim->max_level = ~0; | |
5142 | discrim->max_ts = INT_MAX; | |
5143 | discrim->domain_depth = 2; | |
5144 | discrim->max_channels = INT_MAX; | |
5145 | discrim->authed = -1; | |
5146 | discrim->info_space = -1; | |
63665495 | 5147 | discrim->intra_dcmp = 0; |
5148 | discrim->intra_scmp = 0; | |
1c5f6697 | 5149 | discrim->use_regex = 0; |
5150 | discrim->silent = 0; | |
d76ed9a9 | 5151 | |
5152 | for (i=0; i<argc; i++) { | |
5153 | if (irccasecmp(argv[i], "log") == 0) { | |
5154 | discrim->option_log = 1; | |
5155 | continue; | |
5156 | } | |
5157 | /* Assume all other criteria require arguments. */ | |
5158 | if (i == argc - 1) { | |
258d1427 | 5159 | send_message(user, bot, "MSG_MISSING_PARAMS", argv[i]); |
d76ed9a9 | 5160 | goto fail; |
5161 | } | |
63665495 | 5162 | if (argv[i+1][0] == '&') { |
5163 | /* Looking for intra-userNode matches */ | |
5164 | char *tmp = &(argv[i+1][1]); | |
5165 | if (strcasecmp(tmp, argv[i]) != 0) { /* Don't allow "nick &nick" etc */ | |
5166 | if (!strcasecmp(tmp, "nick")) | |
5167 | discrim->intra_dcmp = 1; | |
5168 | else if (!strcasecmp(tmp, "ident")) | |
5169 | discrim->intra_dcmp = 2; | |
5170 | else if (!strcasecmp(tmp, "info")) | |
5171 | discrim->intra_dcmp = 3; | |
5172 | } | |
5173 | } | |
258d1427 | 5174 | if (irccasecmp(argv[i], "mask") == 0) { |
5175 | if (!is_ircmask(argv[++i])) { | |
5176 | send_message(user, bot, "OSMSG_INVALID_IRCMASK", argv[i]); | |
5177 | goto fail; | |
5178 | } | |
5179 | if (!split_ircmask(argv[i], | |
d76ed9a9 | 5180 | &discrim->mask_nick, |
5181 | &discrim->mask_ident, | |
5182 | &discrim->mask_host)) { | |
258d1427 | 5183 | send_message(user, bot, "OSMSG_INVALID_IRCMASK", argv[i]); |
5184 | goto fail; | |
5185 | } | |
5186 | } else if (irccasecmp(argv[i], "nick") == 0) { | |
63665495 | 5187 | i++; |
5188 | if (discrim->intra_dcmp > 0) | |
5189 | discrim->intra_scmp = 1; | |
5190 | else | |
5191 | discrim->mask_nick = argv[i]; | |
258d1427 | 5192 | } else if (irccasecmp(argv[i], "ident") == 0) { |
63665495 | 5193 | i++; |
5194 | if (discrim->intra_dcmp > 0) | |
5195 | discrim->intra_scmp = 2; | |
5196 | else | |
5197 | discrim->mask_ident = argv[i]; | |
258d1427 | 5198 | } else if (irccasecmp(argv[i], "host") == 0) { |
5199 | discrim->mask_host = argv[++i]; | |
5200 | } else if (irccasecmp(argv[i], "info") == 0) { | |
63665495 | 5201 | i++; |
5202 | if (discrim->intra_dcmp > 0) | |
5203 | discrim->intra_scmp = 3; | |
5204 | else | |
5205 | discrim->mask_info = argv[i]; | |
0e08a8e0 | 5206 | } else if (irccasecmp(argv[i], "version") == 0) { |
5207 | discrim->mask_version = argv[++i]; | |
258d1427 | 5208 | } else if (irccasecmp(argv[i], "server") == 0) { |
5209 | discrim->server = argv[++i]; | |
5210 | } else if (irccasecmp(argv[i], "ip") == 0) { | |
2f61d1d7 | 5211 | j = irc_pton(&discrim->ip_mask, &discrim->ip_mask_bits, argv[++i]); |
5212 | if (!j) { | |
c092fcad | 5213 | send_message(user, bot, "OSMSG_BAD_IP", argv[i]); |
2f61d1d7 | 5214 | goto fail; |
5215 | } | |
d76ed9a9 | 5216 | } else if (irccasecmp(argv[i], "account") == 0) { |
5217 | if (discrim->authed == 0) { | |
258d1427 | 5218 | send_message(user, bot, "OSMSG_ACCOUNTMASK_AUTHED"); |
d76ed9a9 | 5219 | goto fail; |
5220 | } | |
5221 | discrim->accountmask = argv[++i]; | |
5222 | discrim->authed = 1; | |
2c00fbc2 | 5223 | } else if (irccasecmp(argv[i], "marked") == 0) { |
5224 | discrim->mask_mark = argv[++i]; | |
c408f18a | 5225 | } else if (irccasecmp(argv[i], "chantarget") == 0) { |
5226 | if(!IsChannelName(argv[i+1])) { | |
5227 | send_message(user, bot, "MSG_NOT_CHANNEL_NAME"); | |
5228 | goto fail; | |
5229 | } | |
5230 | discrim->chantarget = argv[++i]; | |
5aa400d2 | 5231 | } else if (irccasecmp(argv[i], "checkrestrictions") == 0) { |
5232 | i++; | |
5233 | if (true_string(argv[i])) { | |
5234 | discrim->checkrestrictions = 1; | |
5235 | } else if (false_string(argv[i])) { | |
5236 | discrim->checkrestrictions = 0; | |
5237 | } else { | |
5238 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); | |
5239 | goto fail; | |
5240 | } | |
d82cf2f0 | 5241 | } else if (irccasecmp(argv[i], "mark") == 0) { |
5242 | if(!is_valid_mark(argv[i+1])) { | |
5243 | send_message(user, bot, "OSMSG_MARK_INVALID"); | |
5244 | goto fail; | |
5245 | } | |
5246 | discrim->mark = argv[++i]; | |
d76ed9a9 | 5247 | } else if (irccasecmp(argv[i], "authed") == 0) { |
5248 | i++; /* true_string and false_string are macros! */ | |
5249 | if (true_string(argv[i])) { | |
5250 | discrim->authed = 1; | |
5251 | } else if (false_string(argv[i])) { | |
5252 | if (discrim->accountmask) { | |
258d1427 | 5253 | send_message(user, bot, "OSMSG_ACCOUNTMASK_AUTHED"); |
d76ed9a9 | 5254 | goto fail; |
5255 | } | |
5256 | discrim->authed = 0; | |
5257 | } else { | |
258d1427 | 5258 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); |
d76ed9a9 | 5259 | goto fail; |
5260 | } | |
5261 | } else if (irccasecmp(argv[i], "info_space") == 0) { | |
5262 | /* XXX: A hack because you can't check explicitly for a space through | |
5263 | * any other means */ | |
5264 | i++; | |
5265 | if (true_string(argv[i])) { | |
5266 | discrim->info_space = 1; | |
5267 | } else if (false_string(argv[i])) { | |
5268 | discrim->info_space = 0; | |
5269 | } else { | |
258d1427 | 5270 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); |
d76ed9a9 | 5271 | goto fail; |
5272 | } | |
27eaa617 | 5273 | } else if (irccasecmp(argv[i], "regex") == 0) { |
5274 | i++; | |
5275 | if (true_string(argv[i])) { | |
5276 | discrim->use_regex = 1; | |
5277 | } else if (false_string(argv[i])) { | |
5278 | discrim->use_regex = 0; | |
5279 | } else { | |
c092fcad | 5280 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); |
27eaa617 | 5281 | goto fail; |
5282 | } | |
1c5f6697 | 5283 | } else if (irccasecmp(argv[i], "silent") == 0) { |
5284 | i++; | |
0c0adfe0 | 5285 | if(user != opserv && !oper_has_access(user, opserv, opserv_conf.silent_level, 0)) { |
1c5f6697 | 5286 | goto fail; |
5287 | } else if (true_string(argv[i])) { | |
5288 | discrim->silent = 1; | |
5289 | } else if (false_string(argv[i])) { | |
5290 | discrim->silent = 0; | |
5291 | } else { | |
c092fcad | 5292 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); |
1c5f6697 | 5293 | goto fail; |
5294 | } | |
d76ed9a9 | 5295 | } else if (irccasecmp(argv[i], "duration") == 0) { |
5296 | discrim->duration = ParseInterval(argv[++i]); | |
258d1427 | 5297 | } else if (irccasecmp(argv[i], "channel") == 0) { |
d76ed9a9 | 5298 | for (j=0, i++; ; j++) { |
5299 | switch (argv[i][j]) { | |
5300 | case '#': | |
5301 | goto find_channel; | |
5302 | case '-': | |
0f6fe38c | 5303 | discrim->chan_no_modes |= MODE_CHANOP | MODE_HALFOP | MODE_VOICE; |
d76ed9a9 | 5304 | break; |
5305 | case '+': | |
0f6fe38c | 5306 | discrim->chan_req_modes |= MODE_VOICE; |
5307 | discrim->chan_no_modes |= MODE_CHANOP; | |
5308 | discrim->chan_no_modes |= MODE_HALFOP; | |
55342ce8 | 5309 | break; |
5310 | case '%': | |
0f6fe38c | 5311 | discrim->chan_req_modes |= MODE_HALFOP; |
5312 | discrim->chan_no_modes |= MODE_CHANOP; | |
5313 | discrim->chan_no_modes |= MODE_VOICE; | |
d76ed9a9 | 5314 | break; |
5315 | case '@': | |
0f6fe38c | 5316 | discrim->chan_req_modes |= MODE_CHANOP; |
d76ed9a9 | 5317 | break; |
5318 | case '\0': | |
258d1427 | 5319 | send_message(user, bot, "MSG_NOT_CHANNEL_NAME"); |
d76ed9a9 | 5320 | goto fail; |
5321 | } | |
5322 | } | |
5323 | find_channel: | |
0f6fe38c | 5324 | discrim->chan_no_modes &= ~discrim->chan_req_modes; |
5325 | if (!(discrim->channel = GetChannel(argv[i]+j))) { | |
d76ed9a9 | 5326 | /* secretly "allow_channel" now means "if a channel name is |
5327 | * specified, require that it currently exist" */ | |
5328 | if (allow_channel) { | |
258d1427 | 5329 | send_message(user, bot, "MSG_CHANNEL_UNKNOWN", argv[i]); |
d76ed9a9 | 5330 | goto fail; |
5331 | } else { | |
0f6fe38c | 5332 | discrim->channel = AddChannel(argv[i]+j, now, NULL, NULL, NULL); |
d76ed9a9 | 5333 | } |
258d1427 | 5334 | } |
0f6fe38c | 5335 | LockChannel(discrim->channel); |
d76ed9a9 | 5336 | } else if (irccasecmp(argv[i], "numchannels") == 0) { |
5337 | discrim->min_channels = discrim->max_channels = strtoul(argv[++i], NULL, 10); | |
258d1427 | 5338 | } else if (irccasecmp(argv[i], "limit") == 0) { |
5339 | discrim->limit = strtoul(argv[++i], NULL, 10); | |
d76ed9a9 | 5340 | } else if (irccasecmp(argv[i], "reason") == 0) { |
5341 | discrim->reason = strdup(unsplit_string(argv+i+1, argc-i-1, NULL)); | |
5342 | i = argc; | |
5343 | } else if (irccasecmp(argv[i], "last") == 0) { | |
5344 | discrim->min_ts = now - ParseInterval(argv[++i]); | |
5345 | } else if ((irccasecmp(argv[i], "linked") == 0) | |
5346 | || (irccasecmp(argv[i], "nickage") == 0)) { | |
5347 | const char *cmp = argv[++i]; | |
5348 | if (cmp[0] == '<') { | |
5349 | if (cmp[1] == '=') { | |
5350 | discrim->min_ts = now - ParseInterval(cmp+2); | |
5351 | } else { | |
5352 | discrim->min_ts = now - (ParseInterval(cmp+1) - 1); | |
5353 | } | |
5354 | } else if (cmp[0] == '>') { | |
5355 | if (cmp[1] == '=') { | |
5356 | discrim->max_ts = now - ParseInterval(cmp+2); | |
5357 | } else { | |
5358 | discrim->max_ts = now - (ParseInterval(cmp+1) - 1); | |
5359 | } | |
5360 | } else { | |
0f6fe38c | 5361 | discrim->min_ts = now - ParseInterval(cmp+2); |
d76ed9a9 | 5362 | } |
5363 | } else if (irccasecmp(argv[i], "access") == 0) { | |
5364 | const char *cmp = argv[++i]; | |
5365 | if (cmp[0] == '<') { | |
5366 | if (discrim->min_level == 0) discrim->min_level = 1; | |
5367 | if (cmp[1] == '=') { | |
5368 | discrim->max_level = strtoul(cmp+2, NULL, 0); | |
5369 | } else { | |
5370 | discrim->max_level = strtoul(cmp+1, NULL, 0) - 1; | |
5371 | } | |
5372 | } else if (cmp[0] == '=') { | |
5373 | discrim->min_level = discrim->max_level = strtoul(cmp+1, NULL, 0); | |
5374 | } else if (cmp[0] == '>') { | |
5375 | if (cmp[1] == '=') { | |
5376 | discrim->min_level = strtoul(cmp+2, NULL, 0); | |
5377 | } else { | |
5378 | discrim->min_level = strtoul(cmp+1, NULL, 0) + 1; | |
5379 | } | |
5380 | } else { | |
0f6fe38c | 5381 | discrim->min_level = strtoul(cmp+2, NULL, 0); |
d76ed9a9 | 5382 | } |
0f6fe38c | 5383 | } else if ((irccasecmp(argv[i], "abuse") == 0) |
5384 | && (irccasecmp(argv[++i], "opers") == 0)) { | |
5385 | discrim->match_opers = 1; | |
d76ed9a9 | 5386 | } else if (irccasecmp(argv[i], "depth") == 0) { |
5387 | discrim->domain_depth = strtoul(argv[++i], NULL, 0); | |
5388 | } else if (irccasecmp(argv[i], "clones") == 0) { | |
5389 | discrim->min_clones = strtoul(argv[++i], NULL, 0); | |
5390 | } else { | |
258d1427 | 5391 | send_message(user, bot, "MSG_INVALID_CRITERIA", argv[i]); |
d76ed9a9 | 5392 | goto fail; |
5393 | } | |
5394 | } | |
5395 | ||
5396 | if (discrim->mask_nick && !strcmp(discrim->mask_nick, "*")) { | |
258d1427 | 5397 | discrim->mask_nick = 0; |
d76ed9a9 | 5398 | } |
5399 | if (discrim->mask_ident && !strcmp(discrim->mask_ident, "*")) { | |
5400 | discrim->mask_ident = 0; | |
5401 | } | |
5402 | if (discrim->mask_info && !strcmp(discrim->mask_info, "*")) { | |
258d1427 | 5403 | discrim->mask_info = 0; |
d76ed9a9 | 5404 | } |
0e08a8e0 | 5405 | if (discrim->mask_version && !strcmp(discrim->mask_version, "*")) { |
5406 | discrim->mask_version = 0; | |
5407 | } | |
d76ed9a9 | 5408 | if (discrim->mask_host && !discrim->mask_host[strspn(discrim->mask_host, "*.")]) { |
5409 | discrim->mask_host = 0; | |
5410 | } | |
27eaa617 | 5411 | |
5412 | if(discrim->use_regex) | |
5413 | { | |
5414 | if(discrim->mask_nick) | |
5415 | { | |
928e5a35 | 5416 | int err = regcomp(&discrim->regex_nick, discrim->mask_nick, REG_EXTENDED|REG_NOSUB); |
27eaa617 | 5417 | discrim->has_regex_nick = !err; |
5418 | if(err) | |
5419 | { | |
5420 | char buff[256]; | |
5421 | buff[regerror(err, &discrim->regex_nick, buff, sizeof(buff))] = 0; | |
5422 | ||
c092fcad | 5423 | send_message(user, bot, "OSMSG_INVALID_REGEX", discrim->mask_nick, buff, err); |
27eaa617 | 5424 | goto regfail; |
5425 | } | |
5426 | } | |
5427 | ||
5428 | if(discrim->mask_ident) | |
5429 | { | |
928e5a35 | 5430 | int err = regcomp(&discrim->regex_ident, discrim->mask_ident, REG_EXTENDED|REG_NOSUB); |
27eaa617 | 5431 | discrim->has_regex_ident = !err; |
5432 | if(err) | |
5433 | { | |
5434 | char buff[256]; | |
5435 | buff[regerror(err, &discrim->regex_ident, buff, sizeof(buff))] = 0; | |
5436 | ||
c092fcad | 5437 | send_message(user, bot, "OSMSG_INVALID_REGEX", discrim->mask_ident, buff, err); |
27eaa617 | 5438 | goto regfail; |
5439 | } | |
5440 | } | |
5441 | ||
5442 | if(discrim->mask_host) | |
5443 | { | |
928e5a35 | 5444 | int err = regcomp(&discrim->regex_host, discrim->mask_host, REG_EXTENDED|REG_NOSUB); |
27eaa617 | 5445 | discrim->has_regex_host = !err; |
5446 | if(err) | |
5447 | { | |
5448 | char buff[256]; | |
5449 | buff[regerror(err, &discrim->regex_host, buff, sizeof(buff))] = 0; | |
5450 | ||
c092fcad | 5451 | send_message(user, bot, "OSMSG_INVALID_REGEX", discrim->mask_host, buff, err); |
27eaa617 | 5452 | goto regfail; |
5453 | } | |
5454 | } | |
5455 | ||
5456 | if(discrim->mask_info) | |
5457 | { | |
928e5a35 | 5458 | int err = regcomp(&discrim->regex_info, discrim->mask_info, REG_EXTENDED|REG_NOSUB); |
27eaa617 | 5459 | discrim->has_regex_info = !err; |
5460 | if(err) | |
5461 | { | |
5462 | char buff[256]; | |
5463 | buff[regerror(err, &discrim->regex_info, buff, sizeof(buff))] = 0; | |
5464 | ||
c092fcad | 5465 | send_message(user, bot, "OSMSG_INVALID_REGEX", discrim->mask_info, buff, err); |
27eaa617 | 5466 | goto regfail; |
5467 | } | |
5468 | } | |
0e08a8e0 | 5469 | |
5470 | if(discrim->mask_version) | |
5471 | { | |
928e5a35 | 5472 | int err = regcomp(&discrim->regex_version, discrim->mask_version, REG_EXTENDED|REG_NOSUB); |
0e08a8e0 | 5473 | discrim->has_regex_version = !err; |
5474 | if(err) | |
5475 | { | |
5476 | char buff[256]; | |
5477 | buff[regerror(err, &discrim->regex_version, buff, sizeof(buff))] = 0; | |
5478 | ||
5479 | send_message(user, bot, "OSMSG_INVALID_REGEX", discrim->mask_version, buff, err); | |
5480 | goto regfail; | |
5481 | } | |
5482 | } | |
27eaa617 | 5483 | } |
5484 | ||
d76ed9a9 | 5485 | return discrim; |
27eaa617 | 5486 | |
d76ed9a9 | 5487 | fail: |
5488 | free(discrim); | |
5489 | return NULL; | |
27eaa617 | 5490 | |
5491 | regfail: | |
5492 | if(discrim->has_regex_nick) | |
5493 | regfree(&discrim->regex_nick); | |
5494 | if(discrim->has_regex_ident) | |
5495 | regfree(&discrim->regex_ident); | |
5496 | if(discrim->has_regex_host) | |
5497 | regfree(&discrim->regex_host); | |
5498 | if(discrim->has_regex_info) | |
5499 | regfree(&discrim->regex_info); | |
5500 | ||
5501 | free(discrim); | |
5502 | return NULL; | |
d76ed9a9 | 5503 | } |
5504 | ||
5505 | static int | |
5506 | discrim_match(discrim_t discrim, struct userNode *user) | |
5507 | { | |
0f6fe38c | 5508 | unsigned int access; |
63665495 | 5509 | char *scmp=NULL, *dcmp=NULL; |
d76ed9a9 | 5510 | |
5511 | if ((user->timestamp < discrim->min_ts) | |
5512 | || (user->timestamp > discrim->max_ts) | |
5513 | || (user->channels.used < discrim->min_channels) | |
5514 | || (user->channels.used > discrim->max_channels) | |
5515 | || (discrim->authed == 0 && user->handle_info) | |
5516 | || (discrim->authed == 1 && !user->handle_info) | |
5517 | || (discrim->info_space == 0 && user->info[0] == ' ') | |
5518 | || (discrim->info_space == 1 && user->info[0] != ' ') | |
d76ed9a9 | 5519 | || (discrim->server && !match_ircglob(user->uplink->name, discrim->server)) |
2c00fbc2 | 5520 | || (discrim->mask_mark && (!user->mark || !match_ircglob(user->mark, discrim->mask_mark))) |
d76ed9a9 | 5521 | || (discrim->accountmask && (!user->handle_info || !match_ircglob(user->handle_info->handle, discrim->accountmask))) |
2f61d1d7 | 5522 | || (discrim->ip_mask_bits && !irc_check_mask(&user->ip, &discrim->ip_mask, discrim->ip_mask_bits)) |
5523 | ) | |
5524 | return 0; | |
5525 | ||
0f6fe38c | 5526 | if (discrim->channel && !GetUserMode(discrim->channel, user)) |
5527 | return 0; | |
27eaa617 | 5528 | |
5529 | if(discrim->use_regex) | |
5530 | { | |
5531 | if((discrim->has_regex_nick && regexec(&discrim->regex_nick, user->nick, 0, 0, 0)) | |
5532 | || (discrim->has_regex_ident && regexec(&discrim->regex_ident, user->ident, 0, 0, 0)) | |
5533 | || (discrim->has_regex_host && regexec(&discrim->regex_host, user->hostname, 0, 0, 0)) | |
0e08a8e0 | 5534 | || (discrim->has_regex_info && regexec(&discrim->regex_info, user->info, 0, 0, 0)) |
5535 | || (discrim->has_regex_version && (!user->version_reply || regexec(&discrim->regex_version, user->version_reply, 0, 0, 0)))) { | |
27eaa617 | 5536 | return 0; |
5537 | } | |
5538 | } | |
5539 | else | |
5540 | { | |
5541 | if ((discrim->mask_nick && !match_ircglob(user->nick, discrim->mask_nick)) | |
5542 | || (discrim->mask_ident && !match_ircglob(user->ident, discrim->mask_ident)) | |
5543 | || (discrim->mask_host && !match_ircglob(user->hostname, discrim->mask_host)) | |
0e08a8e0 | 5544 | || (discrim->mask_info && !match_ircglob(user->info, discrim->mask_info)) |
5545 | || (discrim->mask_version && (!user->version_reply || !match_ircglob(user->version_reply, discrim->mask_version))) ) { | |
27eaa617 | 5546 | return 0; |
5547 | } | |
5548 | } | |
5549 | ||
63665495 | 5550 | if ((discrim->intra_scmp > 0 && discrim->intra_dcmp > 0)) { |
5551 | switch(discrim->intra_scmp) { | |
5552 | case 1: scmp=user->nick; break; | |
5553 | case 2: scmp=user->ident; break; | |
5554 | case 3: | |
5555 | scmp=user->info; | |
5556 | if (discrim->info_space == 1) scmp++; | |
5557 | break; | |
5558 | } | |
5559 | switch(discrim->intra_dcmp) { | |
5560 | case 1: dcmp=user->nick; break; | |
5561 | case 2: dcmp=user->ident; break; | |
5562 | case 3: /* When checking INFO, and info_space is enabled | |
5563 | * ignore the first character in a search | |
5564 | * XXX: Should we ignore ALL leading whitespace? | |
5565 | * Also, what about ignoring ~ in ident? | |
5566 | */ | |
5567 | dcmp=user->info; | |
5568 | if (discrim->info_space == 1) dcmp++; | |
5569 | break; | |
5570 | } | |
5571 | if (irccasecmp(scmp,dcmp)) | |
5572 | return 0; | |
5573 | } | |
5574 | ||
d76ed9a9 | 5575 | access = user->handle_info ? user->handle_info->opserv_level : 0; |
5576 | if ((access < discrim->min_level) | |
5577 | || (access > discrim->max_level)) { | |
5578 | return 0; | |
5579 | } | |
d76ed9a9 | 5580 | if (discrim->min_clones > 1) { |
2f61d1d7 | 5581 | struct opserv_hostinfo *ohi = dict_find(opserv_hostinfo_dict, irc_ntoa(&user->ip), NULL); |
5582 | if (!ohi || (ohi->clients.used < discrim->min_clones)) | |
5583 | return 0; | |
d76ed9a9 | 5584 | } |
5585 | return 1; | |
5586 | } | |
5587 | ||
5588 | static unsigned int | |
5589 | opserv_discrim_search(discrim_t discrim, discrim_search_func dsf, void *data) | |
5590 | { | |
0f6fe38c | 5591 | unsigned int nn, count; |
d76ed9a9 | 5592 | struct userList matched; |
5593 | ||
5594 | userList_init(&matched); | |
5595 | /* Try most optimized search methods first */ | |
0f6fe38c | 5596 | if (discrim->channel) { |
5597 | for (nn=0; | |
5598 | (nn < discrim->channel->members.used) | |
d76ed9a9 | 5599 | && (matched.used < discrim->limit); |
5600 | nn++) { | |
0f6fe38c | 5601 | struct modeNode *mn = discrim->channel->members.list[nn]; |
5602 | if (((mn->modes & discrim->chan_req_modes) != discrim->chan_req_modes) | |
5603 | || ((mn->modes & discrim->chan_no_modes) != 0)) { | |
d76ed9a9 | 5604 | continue; |
5605 | } | |
0f6fe38c | 5606 | if (discrim_match(discrim, mn->user)) { |
d76ed9a9 | 5607 | userList_append(&matched, mn->user); |
5608 | } | |
5609 | } | |
2f61d1d7 | 5610 | } else if (discrim->ip_mask_bits == 128) { |
5611 | struct opserv_hostinfo *ohi = dict_find(opserv_hostinfo_dict, irc_ntoa(&discrim->ip_mask), NULL); | |
d76ed9a9 | 5612 | if (!ohi) { |
5613 | userList_clean(&matched); | |
5614 | return 0; | |
5615 | } | |
5616 | for (nn=0; (nn<ohi->clients.used) && (matched.used < discrim->limit); nn++) { | |
5617 | if (discrim_match(discrim, ohi->clients.list[nn])) { | |
5618 | userList_append(&matched, ohi->clients.list[nn]); | |
5619 | } | |
5620 | } | |
5621 | } else { | |
5622 | dict_iterator_t it; | |
5623 | for (it=dict_first(clients); it && (matched.used < discrim->limit); it=iter_next(it)) { | |
5624 | if (discrim_match(discrim, iter_data(it))) { | |
5625 | userList_append(&matched, iter_data(it)); | |
5626 | } | |
5627 | } | |
5628 | } | |
5629 | ||
5630 | if (!matched.used) { | |
5631 | userList_clean(&matched); | |
5632 | return 0; | |
5633 | } | |
5634 | ||
5635 | if (discrim->option_log) { | |
5636 | log_module(OS_LOG, LOG_INFO, "Logging matches for search:"); | |
5637 | } | |
5638 | for (nn=0; nn<matched.used; nn++) { | |
5639 | struct userNode *user = matched.list[nn]; | |
5640 | if (discrim->option_log) { | |
5641 | log_module(OS_LOG, LOG_INFO, " %s!%s@%s", user->nick, user->ident, user->hostname); | |
5642 | } | |
5643 | if (dsf(user, data)) { | |
258d1427 | 5644 | /* If a search function returns true, it ran into a |
5645 | problem. Stop going through the list. */ | |
5646 | break; | |
5647 | } | |
d76ed9a9 | 5648 | } |
5649 | if (discrim->option_log) { | |
5650 | log_module(OS_LOG, LOG_INFO, "End of matching users."); | |
5651 | } | |
5652 | count = matched.used; | |
5653 | userList_clean(&matched); | |
5654 | return count; | |
5655 | } | |
5656 | ||
5657 | static int | |
5658 | trace_print_func(struct userNode *match, void *extra) | |
5659 | { | |
5660 | struct discrim_and_source *das = extra; | |
5661 | if (match->handle_info) { | |
258d1427 | 5662 | 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); |
d76ed9a9 | 5663 | } else { |
258d1427 | 5664 | send_message_type(4, das->source, das->destination, "%-15s\002 \002%10s\002@\002%s", match->nick, match->ident, match->hostname); |
d76ed9a9 | 5665 | } |
5666 | return 0; | |
5667 | } | |
5668 | ||
5669 | static int | |
5670 | trace_count_func(UNUSED_ARG(struct userNode *match), UNUSED_ARG(void *extra)) | |
5671 | { | |
5672 | return 0; | |
5673 | } | |
5674 | ||
5675 | static int | |
0f6fe38c | 5676 | is_oper_victim(struct userNode *user, struct userNode *target, int match_opers) |
d76ed9a9 | 5677 | { |
0f6fe38c | 5678 | return !(IsService(target) |
d76ed9a9 | 5679 | || (!match_opers && IsOper(target)) |
5680 | || (target->handle_info | |
5681 | && target->handle_info->opserv_level > user->handle_info->opserv_level)); | |
5682 | } | |
5683 | ||
5684 | static int | |
5685 | trace_gline_func(struct userNode *match, void *extra) | |
5686 | { | |
5687 | struct discrim_and_source *das = extra; | |
5688 | ||
0f6fe38c | 5689 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { |
1c5f6697 | 5690 | opserv_block(match, das->source->handle_info->handle, das->discrim->reason, das->discrim->duration, das->discrim->silent); |
d76ed9a9 | 5691 | } |
5692 | ||
5693 | return 0; | |
5694 | } | |
5695 | ||
d914d1cb | 5696 | static int |
5697 | trace_shun_func(struct userNode *match, void *extra) | |
5698 | { | |
5699 | struct discrim_and_source *das = extra; | |
5700 | ||
0f6fe38c | 5701 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { |
d914d1cb | 5702 | opserv_shun(match, das->source->handle_info->handle, das->discrim->reason, das->discrim->duration); |
5703 | } | |
5704 | ||
5705 | return 0; | |
5706 | } | |
5707 | ||
d76ed9a9 | 5708 | static int |
5709 | trace_kill_func(struct userNode *match, void *extra) | |
5710 | { | |
5711 | struct discrim_and_source *das = extra; | |
5712 | ||
0f6fe38c | 5713 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { |
258d1427 | 5714 | char *reason; |
d76ed9a9 | 5715 | if (das->discrim->reason) { |
5716 | reason = das->discrim->reason; | |
5717 | } else { | |
5718 | reason = alloca(strlen(OSMSG_KILL_REQUESTED)+strlen(das->source->nick)+1); | |
5719 | sprintf(reason, OSMSG_KILL_REQUESTED, das->source->nick); | |
5720 | } | |
5721 | DelUser(match, opserv, 1, reason); | |
5722 | } | |
5723 | ||
5724 | return 0; | |
5725 | } | |
5726 | ||
d82cf2f0 | 5727 | static int |
5728 | trace_mark_func(struct userNode *match, void *extra) | |
5729 | { | |
5730 | struct discrim_and_source *das = extra; | |
5731 | char *mark = das->discrim->mark; | |
5732 | ||
5733 | if(!mark) | |
5734 | return 1; | |
5735 | irc_mark(match, mark); | |
5736 | return 0; | |
5737 | } | |
5738 | ||
0e08a8e0 | 5739 | static int |
5740 | trace_svsjoin_func(struct userNode *match, void *extra) | |
5741 | { | |
5742 | struct discrim_and_source *das = extra; | |
5743 | ||
5744 | char *channame = das->discrim->chantarget; | |
5aa400d2 | 5745 | int checkrestrictions = das->discrim->checkrestrictions; |
0e08a8e0 | 5746 | struct chanNode *channel; |
5747 | ||
a62ba70c | 5748 | if(!channame || !IsChannelName(channame)) { |
0e08a8e0 | 5749 | //reply("MSG_NOT_CHANNEL_NAME"); |
5750 | return 1; | |
5751 | } | |
5752 | ||
5753 | if (!(channel = GetChannel(channame))) { | |
5754 | channel = AddChannel(channame, now, NULL, NULL, NULL); | |
5755 | } | |
5aa400d2 | 5756 | |
5757 | if (checkrestrictions) { | |
27fa6acf | 5758 | if (trace_check_bans(match, channel) == 1) { |
5759 | return 1; /* found on lamer list */ | |
5aa400d2 | 5760 | } |
5761 | ||
5762 | if (channel->modes & MODE_INVITEONLY) { | |
27fa6acf | 5763 | return 1; /* channel is invite only */ |
5aa400d2 | 5764 | } |
5765 | ||
1e993296 | 5766 | if (channel->limit > 0) { |
5767 | if (channel->members.used >= channel->limit) { | |
5768 | return 1; /* channel is invite on */ | |
5769 | } | |
5aa400d2 | 5770 | } |
5771 | ||
5772 | if (*channel->key) { | |
27fa6acf | 5773 | return 1; /* channel is password protected */ |
5aa400d2 | 5774 | } |
5775 | } | |
5776 | ||
0e08a8e0 | 5777 | if (GetUserMode(channel, match)) { |
5778 | // reply("OSMSG_ALREADY_THERE", channel->name); | |
5779 | return 1; | |
5780 | } | |
5781 | irc_svsjoin(opserv, match, channel); | |
5782 | // reply("OSMSG_SVSJOIN_SENT"); | |
5783 | return 0; | |
5784 | } | |
5785 | ||
39c1a4ef | 5786 | static int |
5787 | trace_svspart_func(struct userNode *match, void *extra) | |
5788 | { | |
5789 | struct discrim_and_source *das = extra; | |
39c1a4ef | 5790 | char *channame = das->discrim->chantarget; |
5791 | struct chanNode *channel; | |
5792 | ||
5793 | if(!channame || !IsChannelName(channame)) | |
5794 | return 1; | |
5795 | ||
5796 | if (!(channel = GetChannel(channame))) | |
5797 | return 1; | |
5798 | ||
5799 | if (!GetUserMode(channel, match)) | |
5800 | return 1; | |
5801 | ||
5802 | irc_svspart(opserv, match, channel); | |
5803 | return 0; | |
5804 | } | |
5805 | ||
0e08a8e0 | 5806 | static int |
5807 | trace_version_func(struct userNode *match, UNUSED_ARG(void *extra)) | |
5808 | { | |
5809 | irc_version_user(opserv, match); | |
5810 | return 0; | |
5811 | } | |
5812 | ||
d76ed9a9 | 5813 | static int |
5814 | is_gagged(char *mask) | |
5815 | { | |
5816 | struct gag_entry *gag; | |
5817 | ||
5818 | for (gag = gagList; gag; gag = gag->next) { | |
5819 | if (match_ircglobs(gag->mask, mask)) return 1; | |
5820 | } | |
5821 | return 0; | |
5822 | } | |
5823 | ||
5824 | static int | |
5825 | trace_gag_func(struct userNode *match, void *extra) | |
5826 | { | |
5827 | struct discrim_and_source *das = extra; | |
5828 | ||
0f6fe38c | 5829 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { |
d76ed9a9 | 5830 | char *reason, *mask; |
5831 | int masksize; | |
5832 | if (das->discrim->reason) { | |
5833 | reason = das->discrim->reason; | |
5834 | } else { | |
5835 | reason = alloca(strlen(OSMSG_GAG_REQUESTED)+strlen(das->source->nick)+1); | |
5836 | sprintf(reason, OSMSG_GAG_REQUESTED, das->source->nick); | |
5837 | } | |
258d1427 | 5838 | masksize = 5+strlen(match->hostname); |
5839 | mask = alloca(masksize); | |
d76ed9a9 | 5840 | snprintf(mask, masksize, "*!*@%s", match->hostname); |
258d1427 | 5841 | if (!is_gagged(mask)) { |
d76ed9a9 | 5842 | gag_create(mask, das->source->handle_info->handle, reason, |
5843 | das->discrim->duration ? (now + das->discrim->duration) : 0); | |
5844 | } | |
5845 | } | |
5846 | ||
5847 | return 0; | |
5848 | } | |
5849 | ||
5850 | static int | |
5851 | trace_domains_func(struct userNode *match, void *extra) | |
5852 | { | |
5853 | struct discrim_and_source *das = extra; | |
2f61d1d7 | 5854 | irc_in_addr_t ip; |
d76ed9a9 | 5855 | unsigned long *count; |
5856 | unsigned int depth; | |
5857 | char *hostname; | |
2f61d1d7 | 5858 | char ipmask[IRC_NTOP_MASK_MAX_SIZE]; |
d76ed9a9 | 5859 | |
2f61d1d7 | 5860 | if (irc_pton(&ip, NULL, match->hostname)) { |
5861 | if (irc_in_addr_is_ipv4(ip)) { | |
5862 | unsigned long matchip = ntohl(ip.in6_32[3]); | |
5863 | /* raw IP address.. use up to first three octets of IP */ | |
5864 | switch (das->discrim->domain_depth) { | |
5865 | default: | |
5866 | snprintf(ipmask, sizeof(ipmask), "%lu.%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255, (matchip>>8)&255); | |
5867 | break; | |
5868 | case 2: | |
5869 | snprintf(ipmask, sizeof(ipmask), "%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255); | |
5870 | break; | |
5871 | case 1: | |
5872 | snprintf(ipmask, sizeof(ipmask), "%lu.*", (matchip>>24)&255); | |
5873 | break; | |
5874 | } | |
5875 | } else if (irc_in_addr_is_ipv6(ip)) { | |
5876 | switch (das->discrim->domain_depth) { | |
5877 | case 1: depth = 16; goto ipv6_pfx; | |
5878 | case 2: depth = 24; goto ipv6_pfx; | |
5879 | case 3: depth = 32; goto ipv6_pfx; | |
5880 | default: depth = das->discrim->domain_depth; | |
5881 | ipv6_pfx: | |
5882 | irc_ntop_mask(ipmask, sizeof(ipmask), &ip, depth); | |
5883 | } | |
5884 | } else safestrncpy(ipmask, match->hostname, sizeof(ipmask)); | |
5885 | ipmask[sizeof(ipmask) - 1] = '\0'; | |
d76ed9a9 | 5886 | hostname = ipmask; |
5887 | } else { | |
5888 | hostname = match->hostname + strlen(match->hostname); | |
2f61d1d7 | 5889 | for (depth=das->discrim->domain_depth; |
d76ed9a9 | 5890 | depth && (hostname > match->hostname); |
5891 | depth--) { | |
5892 | hostname--; | |
5893 | while ((hostname > match->hostname) && (*hostname != '.')) hostname--; | |
5894 | } | |
5895 | if (*hostname == '.') hostname++; /* advance past last dot we saw */ | |
5896 | } | |
5897 | if (!(count = dict_find(das->dict, hostname, NULL))) { | |
5898 | count = calloc(1, sizeof(*count)); | |
5899 | dict_insert(das->dict, strdup(hostname), count); | |
5900 | } | |
5901 | (*count)++; | |
5902 | return 0; | |
5903 | } | |
5904 | ||
5905 | static int | |
5906 | opserv_show_hostinfo(const char *key, void *data, void *extra) | |
5907 | { | |
5908 | unsigned long *count = data; | |
5909 | struct discrim_and_source *das = extra; | |
5910 | ||
258d1427 | 5911 | send_message_type(4, das->source, das->destination, "%s %lu", key, *count); |
d76ed9a9 | 5912 | return !--das->disp_limit; |
5913 | } | |
5914 | ||
5915 | static MODCMD_FUNC(cmd_trace) | |
5916 | { | |
5917 | struct discrim_and_source das; | |
5918 | discrim_search_func action; | |
0f6fe38c | 5919 | unsigned int matches; |
d76ed9a9 | 5920 | struct svccmd *subcmd; |
5921 | char buf[MAXLEN]; | |
a62ba70c | 5922 | int ret = 1; |
d76ed9a9 | 5923 | |
5924 | sprintf(buf, "trace %s", argv[1]); | |
258d1427 | 5925 | if (!(subcmd = dict_find(opserv_service->commands, buf, NULL))) { |
5926 | reply("OSMSG_BAD_ACTION", argv[1]); | |
d76ed9a9 | 5927 | return 0; |
5928 | } | |
258d1427 | 5929 | if (!svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) |
d76ed9a9 | 5930 | return 0; |
5931 | if (!irccasecmp(argv[1], "print")) | |
5932 | action = trace_print_func; | |
5933 | else if (!irccasecmp(argv[1], "count")) | |
5934 | action = trace_count_func; | |
5935 | else if (!irccasecmp(argv[1], "domains")) | |
5936 | action = trace_domains_func; | |
5937 | else if (!irccasecmp(argv[1], "gline")) | |
5938 | action = trace_gline_func; | |
d914d1cb | 5939 | else if (!irccasecmp(argv[1], "shun")) |
5940 | action = trace_shun_func; | |
d76ed9a9 | 5941 | else if (!irccasecmp(argv[1], "kill")) |
5942 | action = trace_kill_func; | |
5943 | else if (!irccasecmp(argv[1], "gag")) | |
5944 | action = trace_gag_func; | |
0e08a8e0 | 5945 | else if (!irccasecmp(argv[1], "svsjoin")) |
5946 | action = trace_svsjoin_func; | |
39c1a4ef | 5947 | else if (!irccasecmp(argv[1], "svspart")) |
5948 | action = trace_svspart_func; | |
0e08a8e0 | 5949 | else if (!irccasecmp(argv[1], "version")) |
5950 | action = trace_version_func; | |
d82cf2f0 | 5951 | else if (!irccasecmp(argv[1], "mark")) |
5952 | action = trace_mark_func; | |
d76ed9a9 | 5953 | else { |
258d1427 | 5954 | reply("OSMSG_BAD_ACTION", argv[1]); |
5955 | return 0; | |
d76ed9a9 | 5956 | } |
5957 | ||
5958 | if (user->handle_info->opserv_level < subcmd->min_opserv_level) { | |
5959 | reply("OSMSG_LEVEL_TOO_LOW"); | |
5960 | return 0; | |
5961 | } | |
5962 | ||
5963 | das.dict = NULL; | |
5964 | das.source = user; | |
258d1427 | 5965 | das.destination = cmd->parent->bot; |
5966 | das.discrim = opserv_discrim_create(user, cmd->parent->bot, argc-2, argv+2, 1); | |
d76ed9a9 | 5967 | if (!das.discrim) |
5968 | return 0; | |
5969 | ||
5970 | if (action == trace_print_func) | |
de9510bc | 5971 | { |
8e11460f | 5972 | reply("OSMSG_USER_SEARCH_RESULTS"); |
de9510bc | 5973 | reply("OSMSG_USER_SEARCH_BAR"); |
5974 | reply("OSMSG_USER_SEARCH_HEADER"); | |
5975 | reply("OSMSG_USER_SEARCH_BAR"); | |
5976 | } | |
d76ed9a9 | 5977 | else if (action == trace_count_func) |
258d1427 | 5978 | das.discrim->limit = INT_MAX; |
d76ed9a9 | 5979 | else if ((action == trace_gline_func) && !das.discrim->duration) |
5980 | das.discrim->duration = opserv_conf.block_gline_duration; | |
d914d1cb | 5981 | else if ((action == trace_shun_func) && !das.discrim->duration) |
5982 | das.discrim->duration = opserv_conf.block_shun_duration; | |
d76ed9a9 | 5983 | else if (action == trace_domains_func) { |
5984 | das.dict = dict_new(); | |
5985 | dict_set_free_data(das.dict, free); | |
5986 | dict_set_free_keys(das.dict, free); | |
5987 | das.disp_limit = das.discrim->limit; | |
5988 | das.discrim->limit = INT_MAX; | |
5989 | } | |
d76ed9a9 | 5990 | |
a62ba70c | 5991 | if (action == trace_svsjoin_func && !das.discrim->chantarget) { |
5992 | reply("OSMSG_SVSJOIN_NO_TARGET"); | |
5993 | ret = 0; | |
5994 | } | |
39c1a4ef | 5995 | else if (action == trace_svspart_func && !das.discrim->chantarget) { |
5996 | reply("OSMSG_SVSPART_NO_TARGET"); | |
5997 | ret = 0; | |
5998 | } | |
d82cf2f0 | 5999 | else if (action == trace_mark_func && !das.discrim->mark) { |
6000 | reply("OSMSG_MARK_NO_MARK"); | |
6001 | ret = 0; | |
6002 | } | |
a62ba70c | 6003 | else { |
6004 | matches = opserv_discrim_search(das.discrim, action, &das); | |
d76ed9a9 | 6005 | |
a62ba70c | 6006 | if (action == trace_domains_func) |
6007 | dict_foreach(das.dict, opserv_show_hostinfo, &das); | |
6008 | ||
6009 | if (matches) | |
6010 | { | |
6011 | if(action == trace_print_func) | |
6012 | reply("OSMSG_USER_SEARCH_COUNT_BAR", matches); | |
6013 | else | |
6014 | reply("OSMSG_USER_SEARCH_COUNT", matches); | |
6015 | } | |
8e11460f | 6016 | else |
a62ba70c | 6017 | reply("MSG_NO_MATCHES"); |
8e11460f | 6018 | } |
d76ed9a9 | 6019 | |
0f6fe38c | 6020 | if (das.discrim->channel) |
6021 | UnlockChannel(das.discrim->channel); | |
d76ed9a9 | 6022 | free(das.discrim->reason); |
27eaa617 | 6023 | |
6024 | if(das.discrim->has_regex_nick) | |
6025 | regfree(&das.discrim->regex_nick); | |
6026 | if(das.discrim->has_regex_ident) | |
6027 | regfree(&das.discrim->regex_ident); | |
6028 | if(das.discrim->has_regex_host) | |
6029 | regfree(&das.discrim->regex_host); | |
6030 | if(das.discrim->has_regex_info) | |
6031 | regfree(&das.discrim->regex_info); | |
0e08a8e0 | 6032 | if(das.discrim->has_regex_version) |
6033 | regfree(&das.discrim->regex_version); | |
27eaa617 | 6034 | |
d76ed9a9 | 6035 | free(das.discrim); |
6036 | dict_delete(das.dict); | |
a62ba70c | 6037 | return ret; |
d76ed9a9 | 6038 | } |
6039 | ||
258d1427 | 6040 | typedef void (*cdiscrim_search_func)(struct chanNode *match, void *data, struct userNode *bot); |
d76ed9a9 | 6041 | |
6042 | typedef struct channel_discrim { | |
6043 | char *name, *topic; | |
6044 | ||
6045 | unsigned int min_users, max_users; | |
6046 | time_t min_ts, max_ts; | |
6047 | unsigned int limit; | |
6048 | } *cdiscrim_t; | |
6049 | ||
258d1427 | 6050 | static cdiscrim_t opserv_cdiscrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[]); |
6051 | static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim, cdiscrim_search_func dsf, void *data, struct userNode *bot); | |
d76ed9a9 | 6052 | |
6053 | static time_t | |
6054 | smart_parse_time(const char *str) { | |
6055 | /* If an interval-style string is given, treat as time before now. | |
6056 | * If it's all digits, treat directly as a Unix timestamp. */ | |
6057 | return str[strspn(str, "0123456789")] ? (time_t)(now - ParseInterval(str)) : (time_t)atoi(str); | |
6058 | } | |
6059 | ||
6060 | static cdiscrim_t | |
258d1427 | 6061 | opserv_cdiscrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[]) |
d76ed9a9 | 6062 | { |
6063 | cdiscrim_t discrim; | |
6064 | unsigned int i; | |
6065 | ||
6066 | discrim = calloc(1, sizeof(*discrim)); | |
6067 | discrim->limit = 25; | |
6068 | ||
6069 | for (i = 0; i < argc; i++) { | |
258d1427 | 6070 | /* Assume all criteria require arguments. */ |
6071 | if (i == (argc - 1)) { | |
6072 | send_message(user, bot, "MSG_MISSING_PARAMS", argv[i]); | |
6073 | return NULL; | |
6074 | } | |
6075 | ||
6076 | if (!irccasecmp(argv[i], "name")) | |
6077 | discrim->name = argv[++i]; | |
6078 | else if (!irccasecmp(argv[i], "topic")) | |
6079 | discrim->topic = argv[++i]; | |
6080 | else if (!irccasecmp(argv[i], "users")) { | |
6081 | const char *cmp = argv[++i]; | |
d76ed9a9 | 6082 | if (cmp[0] == '<') { |
6083 | if (cmp[1] == '=') | |
6084 | discrim->max_users = strtoul(cmp+2, NULL, 0); | |
6085 | else | |
6086 | discrim->max_users = strtoul(cmp+1, NULL, 0) - 1; | |
6087 | } else if (cmp[0] == '=') { | |
6088 | discrim->min_users = discrim->max_users = strtoul(cmp+1, NULL, 0); | |
6089 | } else if (cmp[0] == '>') { | |
6090 | if (cmp[1] == '=') | |
6091 | discrim->min_users = strtoul(cmp+2, NULL, 0); | |
6092 | else | |
6093 | discrim->min_users = strtoul(cmp+1, NULL, 0) + 1; | |
6094 | } else { | |
0f6fe38c | 6095 | discrim->min_users = strtoul(cmp+2, NULL, 0); |
d76ed9a9 | 6096 | } |
258d1427 | 6097 | } else if (!irccasecmp(argv[i], "timestamp")) { |
6098 | const char *cmp = argv[++i]; | |
d76ed9a9 | 6099 | if (cmp[0] == '<') { |
6100 | if (cmp[1] == '=') | |
6101 | discrim->max_ts = smart_parse_time(cmp+2); | |
6102 | else | |
6103 | discrim->max_ts = smart_parse_time(cmp+1)-1; | |
6104 | } else if (cmp[0] == '=') { | |
6105 | discrim->min_ts = discrim->max_ts = smart_parse_time(cmp+1); | |
6106 | } else if (cmp[0] == '>') { | |
6107 | if (cmp[1] == '=') | |
6108 | discrim->min_ts = smart_parse_time(cmp+2); | |
6109 | else | |
6110 | discrim->min_ts = smart_parse_time(cmp+1)+1; | |
6111 | } else { | |
6112 | discrim->min_ts = smart_parse_time(cmp); | |
6113 | } | |
258d1427 | 6114 | } else if (!irccasecmp(argv[i], "limit")) { |
6115 | discrim->limit = strtoul(argv[++i], NULL, 10); | |
6116 | } else { | |
6117 | send_message(user, bot, "MSG_INVALID_CRITERIA", argv[i]); | |
6118 | goto fail; | |
6119 | } | |
d76ed9a9 | 6120 | } |
6121 | ||
6122 | if (discrim->name && !strcmp(discrim->name, "*")) | |
258d1427 | 6123 | discrim->name = 0; |
d76ed9a9 | 6124 | if (discrim->topic && !strcmp(discrim->topic, "*")) |
258d1427 | 6125 | discrim->topic = 0; |
d76ed9a9 | 6126 | |
6127 | return discrim; | |
6128 | fail: | |
6129 | free(discrim); | |
6130 | return NULL; | |
6131 | } | |
6132 | ||
6133 | static int | |
6134 | cdiscrim_match(cdiscrim_t discrim, struct chanNode *chan) | |
6135 | { | |
6136 | if ((discrim->name && !match_ircglob(chan->name, discrim->name)) || | |
6137 | (discrim->topic && !match_ircglob(chan->topic, discrim->topic)) || | |
0f6fe38c | 6138 | (discrim->min_users && chan->members.used < discrim->min_users) || |
6139 | (discrim->max_users && chan->members.used > discrim->max_users) || | |
6140 | (discrim->min_ts && chan->timestamp < discrim->min_ts) || | |
6141 | (discrim->max_ts && chan->timestamp > discrim->max_ts)) { | |
258d1427 | 6142 | return 0; |
d76ed9a9 | 6143 | } |
6144 | return 1; | |
6145 | } | |
6146 | ||
258d1427 | 6147 | static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim, cdiscrim_search_func dsf, void *data, struct userNode *bot) |
d76ed9a9 | 6148 | { |
6149 | unsigned int count = 0; | |
6150 | dict_iterator_t it, next; | |
6151 | ||
6152 | for (it = dict_first(channels); it && count < discrim->limit ; it = next) { | |
258d1427 | 6153 | struct chanNode *chan = iter_data(it); |
d76ed9a9 | 6154 | |
258d1427 | 6155 | /* Hold on to the next channel in case we decide to |
6156 | add actions that destructively modify the channel. */ | |
6157 | next = iter_next(it); | |
6158 | if ((chan->members.used > 0) && cdiscrim_match(discrim, chan)) { | |
6159 | dsf(chan, data, bot); | |
6160 | count++; | |
6161 | } | |
d76ed9a9 | 6162 | } |
6163 | ||
6164 | return count; | |
6165 | } | |
6166 | ||
258d1427 | 6167 | void channel_count(UNUSED_ARG(struct chanNode *channel), UNUSED_ARG(void *data), UNUSED_ARG(struct userNode *bot)) |
d76ed9a9 | 6168 | { |
6169 | } | |
6170 | ||
258d1427 | 6171 | void channel_print(struct chanNode *channel, void *data, struct userNode *bot) |
d76ed9a9 | 6172 | { |
6173 | char modes[MAXLEN]; | |
6174 | irc_make_chanmode(channel, modes); | |
258d1427 | 6175 | send_message(data, bot, "OSMSG_CSEARCH_CHANNEL_INFO", channel->name, channel->members.used, modes, channel->topic); |
d76ed9a9 | 6176 | } |
6177 | ||
6178 | static MODCMD_FUNC(cmd_csearch) | |
6179 | { | |
6180 | cdiscrim_t discrim; | |
6181 | unsigned int matches; | |
6182 | cdiscrim_search_func action; | |
6183 | struct svccmd *subcmd; | |
6184 | char buf[MAXLEN]; | |
6185 | ||
6186 | if (!irccasecmp(argv[1], "count")) | |
258d1427 | 6187 | action = channel_count; |
d76ed9a9 | 6188 | else if (!irccasecmp(argv[1], "print")) |
258d1427 | 6189 | action = channel_print; |
d76ed9a9 | 6190 | else { |
258d1427 | 6191 | reply("OSMSG_BAD_ACTION", argv[1]); |
6192 | return 0; | |
d76ed9a9 | 6193 | } |
6194 | ||
6195 | sprintf(buf, "%s %s", argv[0], argv[0]); | |
258d1427 | 6196 | if ((subcmd = dict_find(opserv_service->commands, buf, NULL)) |
6197 | && !svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) { | |
d76ed9a9 | 6198 | return 0; |
6199 | } | |
6200 | ||
258d1427 | 6201 | discrim = opserv_cdiscrim_create(user, cmd->parent->bot, argc - 2, argv + 2); |
d76ed9a9 | 6202 | if (!discrim) |
258d1427 | 6203 | return 0; |
d76ed9a9 | 6204 | |
6205 | if (action == channel_print) | |
258d1427 | 6206 | reply("OSMSG_CHANNEL_SEARCH_RESULTS"); |
d76ed9a9 | 6207 | else if (action == channel_count) |
258d1427 | 6208 | discrim->limit = INT_MAX; |
d76ed9a9 | 6209 | |
258d1427 | 6210 | matches = opserv_cdiscrim_search(discrim, action, user, cmd->parent->bot); |
d76ed9a9 | 6211 | |
6212 | if (matches) | |
258d1427 | 6213 | reply("MSG_MATCH_COUNT", matches); |
d76ed9a9 | 6214 | else |
258d1427 | 6215 | reply("MSG_NO_MATCHES"); |
d76ed9a9 | 6216 | |
6217 | free(discrim); | |
6218 | return 1; | |
6219 | } | |
6220 | ||
6221 | static MODCMD_FUNC(cmd_gsync) | |
6222 | { | |
6223 | struct server *src; | |
6224 | if (argc > 1) { | |
6225 | src = GetServerH(argv[1]); | |
6226 | if (!src) { | |
6227 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
6228 | return 0; | |
6229 | } | |
6230 | } else { | |
6231 | src = self->uplink; | |
6232 | } | |
6233 | irc_stats(cmd->parent->bot, src, 'G'); | |
6234 | reply("OSMSG_GSYNC_RUNNING", src->name); | |
6235 | return 1; | |
6236 | } | |
6237 | ||
d914d1cb | 6238 | static MODCMD_FUNC(cmd_ssync) |
6239 | { | |
6240 | struct server *src; | |
6241 | if (argc > 1) { | |
6242 | src = GetServerH(argv[1]); | |
6243 | if (!src) { | |
6244 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
6245 | return 0; | |
6246 | } | |
6247 | } else { | |
6248 | src = self->uplink; | |
6249 | } | |
6250 | irc_stats(cmd->parent->bot, src, 'S'); | |
6251 | reply("OSMSG_SSYNC_RUNNING", src->name); | |
6252 | return 1; | |
6253 | } | |
6254 | ||
d76ed9a9 | 6255 | struct gline_extra { |
6256 | struct userNode *user; | |
6257 | struct string_list *glines; | |
258d1427 | 6258 | struct userNode *bot; |
d76ed9a9 | 6259 | }; |
6260 | ||
6261 | static void | |
6262 | gtrace_print_func(struct gline *gline, void *extra) | |
6263 | { | |
6264 | struct gline_extra *xtra = extra; | |
0f6fe38c | 6265 | char *when_text, set_text[20]; |
6266 | strftime(set_text, sizeof(set_text), "%Y-%m-%d", localtime(&gline->issued)); | |
6267 | when_text = asctime(localtime(&gline->expires)); | |
6268 | when_text[strlen(when_text)-1] = 0; /* strip lame \n */ | |
6269 | send_message(xtra->user, xtra->bot, "OSMSG_GTRACE_FORMAT", gline->target, set_text, gline->issuer, when_text, gline->reason); | |
d76ed9a9 | 6270 | } |
6271 | ||
6272 | static void | |
6273 | gtrace_count_func(UNUSED_ARG(struct gline *gline), UNUSED_ARG(void *extra)) | |
6274 | { | |
6275 | } | |
6276 | ||
6277 | static void | |
6278 | gtrace_ungline_func(struct gline *gline, void *extra) | |
6279 | { | |
6280 | struct gline_extra *xtra = extra; | |
6281 | string_list_append(xtra->glines, strdup(gline->target)); | |
6282 | } | |
6283 | ||
6284 | static MODCMD_FUNC(cmd_gtrace) | |
6285 | { | |
6286 | struct gline_discrim *discrim; | |
6287 | gline_search_func action; | |
6288 | unsigned int matches, nn; | |
6289 | struct gline_extra extra; | |
6290 | struct svccmd *subcmd; | |
6291 | char buf[MAXLEN]; | |
6292 | ||
6293 | if (!irccasecmp(argv[1], "print")) | |
6294 | action = gtrace_print_func; | |
6295 | else if (!irccasecmp(argv[1], "count")) | |
6296 | action = gtrace_count_func; | |
6297 | else if (!irccasecmp(argv[1], "ungline")) | |
6298 | action = gtrace_ungline_func; | |
6299 | else { | |
6300 | reply("OSMSG_BAD_ACTION", argv[1]); | |
6301 | return 0; | |
6302 | } | |
6303 | sprintf(buf, "%s %s", argv[0], argv[0]); | |
258d1427 | 6304 | if ((subcmd = dict_find(opserv_service->commands, buf, NULL)) |
6305 | && !svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) { | |
d76ed9a9 | 6306 | return 0; |
6307 | } | |
6308 | ||
6309 | discrim = gline_discrim_create(user, cmd->parent->bot, argc-2, argv+2); | |
6310 | if (!discrim) | |
6311 | return 0; | |
6312 | ||
6313 | if (action == gtrace_print_func) | |
6314 | reply("OSMSG_GLINE_SEARCH_RESULTS"); | |
6315 | else if (action == gtrace_count_func) | |
6316 | discrim->limit = INT_MAX; | |
6317 | ||
6318 | extra.user = user; | |
6319 | extra.glines = alloc_string_list(4); | |
258d1427 | 6320 | extra.bot = cmd->parent->bot; |
d76ed9a9 | 6321 | matches = gline_discrim_search(discrim, action, &extra); |
6322 | ||
6323 | if (action == gtrace_ungline_func) | |
6324 | for (nn=0; nn<extra.glines->used; nn++) | |
6325 | gline_remove(extra.glines->list[nn], 1); | |
6326 | free_string_list(extra.glines); | |
6327 | ||
6328 | if (matches) | |
6329 | reply("MSG_MATCH_COUNT", matches); | |
6330 | else | |
6331 | reply("MSG_NO_MATCHES"); | |
6332 | free(discrim->alt_target_mask); | |
6333 | free(discrim); | |
6334 | return 1; | |
6335 | } | |
6336 | ||
d914d1cb | 6337 | struct shun_extra { |
6338 | struct userNode *user; | |
6339 | struct string_list *shuns; | |
6340 | struct userNode *bot; | |
6341 | }; | |
6342 | ||
6343 | static void | |
6344 | strace_print_func(struct shun *shun, void *extra) | |
6345 | { | |
6346 | struct shun_extra *xtra = extra; | |
0f6fe38c | 6347 | char *when_text, set_text[20]; |
6348 | strftime(set_text, sizeof(set_text), "%Y-%m-%d", localtime(&shun->issued)); | |
6349 | when_text = asctime(localtime(&shun->expires)); | |
6350 | when_text[strlen(when_text)-1] = 0; /* strip lame \n */ | |
6351 | send_message(xtra->user, xtra->bot, "OSMSG_STRACE_FORMAT", shun->target, set_text, shun->issuer, when_text, shun->reason); | |
d914d1cb | 6352 | } |
6353 | ||
6354 | static void | |
6355 | strace_count_func(UNUSED_ARG(struct shun *shun), UNUSED_ARG(void *extra)) | |
6356 | { | |
6357 | } | |
6358 | ||
6359 | static void | |
6360 | strace_unshun_func(struct shun *shun, void *extra) | |
6361 | { | |
6362 | struct shun_extra *xtra = extra; | |
6363 | string_list_append(xtra->shuns, strdup(shun->target)); | |
6364 | } | |
6365 | ||
6366 | static MODCMD_FUNC(cmd_strace) | |
6367 | { | |
6368 | struct shun_discrim *discrim; | |
6369 | shun_search_func action; | |
6370 | unsigned int matches, nn; | |
6371 | struct shun_extra extra; | |
6372 | struct svccmd *subcmd; | |
6373 | char buf[MAXLEN]; | |
6374 | ||
6375 | if (!irccasecmp(argv[1], "print")) | |
6376 | action = strace_print_func; | |
6377 | else if (!irccasecmp(argv[1], "count")) | |
6378 | action = strace_count_func; | |
6379 | else if (!irccasecmp(argv[1], "unshun")) | |
6380 | action = strace_unshun_func; | |
6381 | else { | |
6382 | reply("OSMSG_BAD_ACTION", argv[1]); | |
6383 | return 0; | |
6384 | } | |
6385 | sprintf(buf, "%s %s", argv[0], argv[0]); | |
6386 | if ((subcmd = dict_find(opserv_service->commands, buf, NULL)) | |
6387 | && !svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) { | |
6388 | return 0; | |
6389 | } | |
6390 | ||
6391 | discrim = shun_discrim_create(user, cmd->parent->bot, argc-2, argv+2); | |
6392 | if (!discrim) | |
6393 | return 0; | |
6394 | ||
6395 | if (action == strace_print_func) | |
6396 | reply("OSMSG_SHUN_SEARCH_RESULTS"); | |
6397 | else if (action == strace_count_func) | |
6398 | discrim->limit = INT_MAX; | |
6399 | ||
6400 | extra.user = user; | |
6401 | extra.shuns = alloc_string_list(4); | |
6402 | extra.bot = cmd->parent->bot; | |
6403 | matches = shun_discrim_search(discrim, action, &extra); | |
6404 | ||
6405 | if (action == strace_unshun_func) | |
6406 | for (nn=0; nn<extra.shuns->used; nn++) | |
6407 | shun_remove(extra.shuns->list[nn], 1); | |
6408 | free_string_list(extra.shuns); | |
6409 | ||
6410 | if (matches) | |
6411 | reply("MSG_MATCH_COUNT", matches); | |
6412 | else | |
6413 | reply("MSG_NO_MATCHES"); | |
6414 | free(discrim->alt_target_mask); | |
6415 | free(discrim); | |
6416 | return 1; | |
6417 | } | |
6418 | ||
d76ed9a9 | 6419 | static int |
6420 | alert_check_user(const char *key, void *data, void *extra) | |
6421 | { | |
6422 | struct opserv_user_alert *alert = data; | |
6423 | struct userNode *user = extra; | |
6424 | ||
6425 | if (!discrim_match(alert->discrim, user)) | |
6426 | return 0; | |
6427 | ||
6428 | if ((alert->reaction != REACT_NOTICE) | |
6429 | && IsOper(user) | |
6430 | && !alert->discrim->match_opers) { | |
6431 | return 0; | |
6432 | } | |
6433 | ||
6434 | /* The user matches the alert criteria, so trigger the reaction. */ | |
6435 | if (alert->discrim->option_log) | |
6436 | 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); | |
6437 | ||
6438 | /* Return 1 to halt alert matching, such as when killing the user | |
6439 | that triggered the alert. */ | |
6440 | switch (alert->reaction) { | |
6441 | case REACT_KILL: | |
6442 | DelUser(user, opserv, 1, alert->discrim->reason); | |
6443 | return 1; | |
6444 | case REACT_GLINE: | |
1c5f6697 | 6445 | opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, alert->discrim->silent); |
d76ed9a9 | 6446 | return 1; |
d914d1cb | 6447 | case REACT_SHUN: |
6448 | opserv_shun(user, alert->owner, alert->discrim->reason, alert->discrim->duration); | |
6449 | return 1; | |
c408f18a | 6450 | case REACT_SVSJOIN: |
5aa400d2 | 6451 | opserv_svsjoin(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget, alert->discrim->checkrestrictions); |
0e08a8e0 | 6452 | break; |
39c1a4ef | 6453 | case REACT_SVSPART: |
6454 | opserv_svspart(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget); | |
6455 | break; | |
0e08a8e0 | 6456 | case REACT_VERSION: |
6457 | /* Don't auto-version a user who we already have a version on, because the version reply itself | |
6458 | * re-triggers this check... | |
6459 | * TODO: maybe safer if we didn't even check react_version type alerts for the 2nd check? | |
6460 | * sort of like we only look at channel alerts on join. -Rubin | |
6461 | */ | |
6462 | if(!user->version_reply) | |
6463 | opserv_version(user); | |
6464 | break; | |
d82cf2f0 | 6465 | case REACT_MARK: |
6466 | opserv_mark(user, alert->owner, alert->discrim->reason, alert->discrim->mark); | |
6467 | break; | |
d76ed9a9 | 6468 | default: |
6469 | log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s.", alert->reaction, key); | |
6470 | /* fall through to REACT_NOTICE case */ | |
6471 | case REACT_NOTICE: | |
0f6fe38c | 6472 | 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); |
d76ed9a9 | 6473 | break; |
ec311f39 | 6474 | case REACT_TRACK: |
6475 | #ifdef HAVE_TRACK | |
0f6fe38c | 6476 | 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); |
ec311f39 | 6477 | add_track_user(user); |
6478 | #endif | |
6479 | break; | |
d76ed9a9 | 6480 | } |
6481 | return 0; | |
6482 | } | |
6483 | ||
6484 | static void | |
6485 | opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick)) | |
6486 | { | |
6487 | struct gag_entry *gag; | |
6488 | dict_foreach(opserv_nick_based_alerts, alert_check_user, user); | |
6489 | /* Gag them if appropriate (and only if). */ | |
6490 | user->modes &= ~FLAGS_GAGGED; | |
6491 | for (gag = gagList; gag; gag = gag->next) { | |
2f61d1d7 | 6492 | if (user_matches_glob(user, gag->mask, MATCH_USENICK)) { |
d76ed9a9 | 6493 | gag_helper_func(user, NULL); |
6494 | break; | |
6495 | } | |
6496 | } | |
6497 | } | |
6498 | ||
6499 | static void | |
6500 | opserv_staff_alert(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) | |
6501 | { | |
6502 | const char *type; | |
6503 | ||
6504 | if (!opserv_conf.staff_auth_channel | |
6505 | || user->uplink->burst | |
6506 | || !user->handle_info) | |
6507 | return; | |
6508 | else if (user->handle_info->opserv_level) | |
6509 | type = "OPER"; | |
6510 | else if (IsNetworkHelper(user)) | |
6511 | type = "NETWORK HELPER"; | |
6512 | else if (IsSupportHelper(user)) | |
6513 | type = "SUPPORT HELPER"; | |
6514 | else | |
6515 | return; | |
6516 | ||
2f61d1d7 | 6517 | if (irc_in_addr_is_valid(user->ip)) |
d76ed9a9 | 6518 | send_channel_notice(opserv_conf.staff_auth_channel, opserv, IDENT_FORMAT" authed to %s account %s", IDENT_DATA(user), type, user->handle_info->handle); |
6519 | else | |
6520 | 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); | |
6521 | } | |
6522 | ||
6523 | static MODCMD_FUNC(cmd_log) | |
6524 | { | |
6525 | struct logSearch *discrim; | |
6526 | unsigned int matches; | |
6527 | struct logReport report; | |
6528 | ||
6529 | discrim = log_discrim_create(cmd->parent->bot, user, argc, argv); | |
6530 | if (!discrim) | |
6531 | return 0; | |
6532 | ||
6533 | reply("OSMSG_LOG_SEARCH_RESULTS"); | |
6534 | report.reporter = opserv; | |
6535 | report.user = user; | |
6536 | matches = log_entry_search(discrim, log_report_entry, &report); | |
6537 | ||
6538 | if (matches) | |
258d1427 | 6539 | reply("MSG_MATCH_COUNT", matches); |
d76ed9a9 | 6540 | else |
258d1427 | 6541 | reply("MSG_NO_MATCHES"); |
d76ed9a9 | 6542 | |
6543 | free(discrim); | |
6544 | return 1; | |
6545 | } | |
6546 | ||
6547 | static int | |
6548 | gag_helper_func(struct userNode *match, UNUSED_ARG(void *extra)) | |
6549 | { | |
6550 | if (IsOper(match) || IsLocal(match)) | |
6551 | return 0; | |
6552 | match->modes |= FLAGS_GAGGED; | |
6553 | return 0; | |
6554 | } | |
6555 | ||
6556 | static MODCMD_FUNC(cmd_gag) | |
6557 | { | |
6558 | struct gag_entry *gag; | |
6559 | unsigned int gagged; | |
6560 | unsigned long duration; | |
6561 | char *reason; | |
6562 | ||
6563 | reason = unsplit_string(argv + 3, argc - 3, NULL); | |
6564 | ||
6565 | if (!is_ircmask(argv[1])) { | |
258d1427 | 6566 | reply("OSMSG_INVALID_IRCMASK", argv[1]); |
d76ed9a9 | 6567 | return 0; |
6568 | } | |
6569 | ||
6570 | for (gag = gagList; gag; gag = gag->next) | |
258d1427 | 6571 | if (match_ircglobs(gag->mask, argv[1])) |
d76ed9a9 | 6572 | break; |
6573 | ||
6574 | if (gag) { | |
258d1427 | 6575 | reply("OSMSG_REDUNDANT_GAG", argv[1]); |
6576 | return 0; | |
d76ed9a9 | 6577 | } |
6578 | ||
6579 | duration = ParseInterval(argv[2]); | |
6580 | gagged = gag_create(argv[1], user->handle_info->handle, reason, (duration?now+duration:0)); | |
6581 | ||
6582 | if (gagged) | |
258d1427 | 6583 | reply("OSMSG_GAG_APPLIED", argv[1], gagged); |
d76ed9a9 | 6584 | else |
258d1427 | 6585 | reply("OSMSG_GAG_ADDED", argv[1]); |
d76ed9a9 | 6586 | return 1; |
6587 | } | |
6588 | ||
6589 | static int | |
6590 | ungag_helper_func(struct userNode *match, UNUSED_ARG(void *extra)) | |
6591 | { | |
6592 | match->modes &= ~FLAGS_GAGGED; | |
6593 | return 0; | |
6594 | } | |
6595 | ||
6596 | static MODCMD_FUNC(cmd_ungag) | |
6597 | { | |
6598 | struct gag_entry *gag; | |
6599 | unsigned int ungagged; | |
6600 | ||
6601 | for (gag = gagList; gag; gag = gag->next) | |
258d1427 | 6602 | if (!strcmp(gag->mask, argv[1])) |
d76ed9a9 | 6603 | break; |
6604 | ||
6605 | if (!gag) { | |
258d1427 | 6606 | reply("OSMSG_GAG_NOT_FOUND", argv[1]); |
6607 | return 0; | |
d76ed9a9 | 6608 | } |
6609 | ||
6610 | timeq_del(gag->expires, gag_expire, gag, 0); | |
6611 | ungagged = gag_free(gag); | |
6612 | ||
6613 | if (ungagged) | |
258d1427 | 6614 | reply("OSMSG_UNGAG_APPLIED", argv[1], ungagged); |
d76ed9a9 | 6615 | else |
258d1427 | 6616 | reply("OSMSG_UNGAG_ADDED", argv[1]); |
d76ed9a9 | 6617 | return 1; |
6618 | } | |
6619 | ||
6620 | static MODCMD_FUNC(cmd_addalert) | |
6621 | { | |
6622 | opserv_alert_reaction reaction; | |
6623 | struct svccmd *subcmd; | |
6624 | const char *name; | |
6625 | char buf[MAXLEN]; | |
6626 | ||
6627 | name = argv[1]; | |
6628 | sprintf(buf, "addalert %s", argv[2]); | |
258d1427 | 6629 | if (!(subcmd = dict_find(opserv_service->commands, buf, NULL))) { |
6630 | reply("OSMSG_UNKNOWN_REACTION", argv[2]); | |
6631 | return 0; | |
d76ed9a9 | 6632 | } |
6633 | if (!irccasecmp(argv[2], "notice")) | |
6634 | reaction = REACT_NOTICE; | |
6635 | else if (!irccasecmp(argv[2], "kill")) | |
6636 | reaction = REACT_KILL; | |
6637 | else if (!irccasecmp(argv[2], "gline")) | |
6638 | reaction = REACT_GLINE; | |
ec311f39 | 6639 | else if (!irccasecmp(argv[2], "track")) { |
6640 | #ifndef HAVE_TRACK | |
c092fcad | 6641 | reply("OSMSG_TRACK_DISABLED"); |
ec311f39 | 6642 | return 0; |
6643 | #else | |
6644 | reaction = REACT_TRACK; | |
6645 | #endif | |
6646 | } else if (!irccasecmp(argv[2], "shun")) | |
d914d1cb | 6647 | reaction = REACT_SHUN; |
c408f18a | 6648 | else if(!irccasecmp(argv[2], "svsjoin")) |
6649 | reaction = REACT_SVSJOIN; | |
39c1a4ef | 6650 | else if(!irccasecmp(argv[2], "svspart")) |
6651 | reaction = REACT_SVSPART; | |
0e08a8e0 | 6652 | else if(!irccasecmp(argv[2], "version")) |
6653 | reaction = REACT_VERSION; | |
d82cf2f0 | 6654 | else if(!irccasecmp(argv[2], "mark")) |
6655 | reaction = REACT_MARK; | |
d76ed9a9 | 6656 | else { |
258d1427 | 6657 | reply("OSMSG_UNKNOWN_REACTION", argv[2]); |
6658 | return 0; | |
d76ed9a9 | 6659 | } |
258d1427 | 6660 | if (!svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY) |
a62ba70c | 6661 | || !opserv_add_user_alert(user, name, reaction, unsplit_string(argv + 3, argc - 3, NULL))) { |
6662 | reply("OSMSG_ALERT_ADD_FAILED"); | |
d76ed9a9 | 6663 | return 0; |
a62ba70c | 6664 | } |
d76ed9a9 | 6665 | reply("OSMSG_ADDED_ALERT", name); |
6666 | return 1; | |
6667 | } | |
6668 | ||
6669 | static MODCMD_FUNC(cmd_delalert) | |
6670 | { | |
6671 | unsigned int i; | |
6672 | for (i=1; i<argc; i++) { | |
6673 | dict_remove(opserv_nick_based_alerts, argv[i]); | |
6674 | dict_remove(opserv_channel_alerts, argv[i]); | |
258d1427 | 6675 | if (dict_remove(opserv_user_alerts, argv[i])) |
6676 | reply("OSMSG_REMOVED_ALERT", argv[i]); | |
d76ed9a9 | 6677 | else |
258d1427 | 6678 | reply("OSMSG_NO_SUCH_ALERT", argv[i]); |
d76ed9a9 | 6679 | } |
6680 | return 1; | |
6681 | } | |
6682 | ||
6683 | static void | |
6684 | opserv_conf_read(void) | |
6685 | { | |
7637f48f | 6686 | struct chanNode *chan; |
6687 | unsigned int i; | |
d76ed9a9 | 6688 | struct record_data *rd; |
6689 | dict_t conf_node, child; | |
6690 | const char *str, *str2; | |
6691 | struct policer_params *pp; | |
6692 | dict_iterator_t it; | |
6693 | ||
6694 | rd = conf_get_node(OPSERV_CONF_NAME); | |
6695 | if (!rd || rd->type != RECDB_OBJECT) { | |
258d1427 | 6696 | log_module(OS_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME); |
6697 | return; | |
d76ed9a9 | 6698 | } |
6699 | conf_node = rd->d.object; | |
6700 | str = database_get_data(conf_node, KEY_DEBUG_CHANNEL, RECDB_QSTRING); | |
6701 | if (opserv && str) { | |
6702 | str2 = database_get_data(conf_node, KEY_DEBUG_CHANNEL_MODES, RECDB_QSTRING); | |
6703 | if (!str2) | |
6704 | str2 = "+tinms"; | |
258d1427 | 6705 | opserv_conf.debug_channel = AddChannel(str, now, str2, NULL, NULL); |
d76ed9a9 | 6706 | AddChannelUser(opserv, opserv_conf.debug_channel)->modes |= MODE_CHANOP; |
6707 | } else { | |
258d1427 | 6708 | opserv_conf.debug_channel = NULL; |
d76ed9a9 | 6709 | } |
6710 | str = database_get_data(conf_node, KEY_ALERT_CHANNEL, RECDB_QSTRING); | |
6711 | if (opserv && str) { | |
6712 | str2 = database_get_data(conf_node, KEY_ALERT_CHANNEL_MODES, RECDB_QSTRING); | |
6713 | if (!str2) | |
6714 | str2 = "+tns"; | |
258d1427 | 6715 | opserv_conf.alert_channel = AddChannel(str, now, str2, NULL, NULL); |
d76ed9a9 | 6716 | AddChannelUser(opserv, opserv_conf.alert_channel)->modes |= MODE_CHANOP; |
6717 | } else { | |
258d1427 | 6718 | opserv_conf.alert_channel = NULL; |
d76ed9a9 | 6719 | } |
6720 | str = database_get_data(conf_node, KEY_STAFF_AUTH_CHANNEL, RECDB_QSTRING); | |
6721 | if (opserv && str) { | |
6722 | str2 = database_get_data(conf_node, KEY_STAFF_AUTH_CHANNEL_MODES, RECDB_QSTRING); | |
6723 | if (!str2) | |
6724 | str2 = "+timns"; | |
2aef5f4b | 6725 | opserv_conf.staff_auth_channel = AddChannel(str, now, str2, NULL, NULL); |
d76ed9a9 | 6726 | AddChannelUser(opserv, opserv_conf.staff_auth_channel)->modes |= MODE_CHANOP; |
6727 | } else { | |
6728 | opserv_conf.staff_auth_channel = NULL; | |
6729 | } | |
5a1daaab | 6730 | |
6731 | str = database_get_data(conf_node, KEY_ADMIN_LEVEL, RECDB_QSTRING); | |
6732 | opserv_conf.admin_level = str ? strtoul(str, NULL, 0): 800; | |
6733 | ||
1c5f6697 | 6734 | str = database_get_data(conf_node, KEY_SILENT_LEVEL, RECDB_QSTRING); |
6735 | opserv_conf.silent_level = str ? strtoul(str, NULL, 0): 700; | |
6736 | ||
d76ed9a9 | 6737 | str = database_get_data(conf_node, KEY_UNTRUSTED_MAX, RECDB_QSTRING); |
6738 | opserv_conf.untrusted_max = str ? strtoul(str, NULL, 0) : 5; | |
6739 | str = database_get_data(conf_node, KEY_PURGE_LOCK_DELAY, RECDB_QSTRING); | |
6740 | opserv_conf.purge_lock_delay = str ? strtoul(str, NULL, 0) : 60; | |
6741 | str = database_get_data(conf_node, KEY_JOIN_FLOOD_MODERATE, RECDB_QSTRING); | |
6742 | opserv_conf.join_flood_moderate = str ? strtoul(str, NULL, 0) : 1; | |
6743 | str = database_get_data(conf_node, KEY_JOIN_FLOOD_MODERATE_THRESH, RECDB_QSTRING); | |
6744 | opserv_conf.join_flood_moderate_threshold = str ? strtoul(str, NULL, 0) : 50; | |
6745 | str = database_get_data(conf_node, KEY_NICK, RECDB_QSTRING); | |
6746 | if (opserv && str) | |
6747 | NickChange(opserv, str, 0); | |
d914d1cb | 6748 | |
d76ed9a9 | 6749 | str = database_get_data(conf_node, KEY_CLONE_GLINE_DURATION, RECDB_QSTRING); |
6750 | opserv_conf.clone_gline_duration = str ? ParseInterval(str) : 3600; | |
6751 | str = database_get_data(conf_node, KEY_BLOCK_GLINE_DURATION, RECDB_QSTRING); | |
6752 | opserv_conf.block_gline_duration = str ? ParseInterval(str) : 3600; | |
6753 | ||
7637f48f | 6754 | free_string_list(autojoin_channels); |
6755 | autojoin_channels = database_get_data(conf_node, KEY_AUTOJOIN_CHANNELS, RECDB_STRING_LIST); | |
6756 | ||
6757 | if(autojoin_channels) | |
6758 | autojoin_channels = string_list_copy(autojoin_channels); | |
6759 | ||
6760 | if (autojoin_channels && opserv) { | |
6761 | for (i = 0; i < autojoin_channels->used; i++) { | |
6762 | chan = AddChannel(autojoin_channels->list[i], now, "+nt", NULL, NULL); | |
6763 | AddChannelUser(opserv, chan)->modes |= MODE_CHANOP; | |
6764 | } | |
6765 | } | |
6766 | ||
d914d1cb | 6767 | str = database_get_data(conf_node, KEY_BLOCK_SHUN_DURATION, RECDB_QSTRING); |
6768 | opserv_conf.block_shun_duration = str ? ParseInterval(str) : 3600; | |
6769 | ||
d76ed9a9 | 6770 | if (!opserv_conf.join_policer_params) |
6771 | opserv_conf.join_policer_params = policer_params_new(); | |
6772 | policer_params_set(opserv_conf.join_policer_params, "size", "20"); | |
6773 | policer_params_set(opserv_conf.join_policer_params, "drain-rate", "1"); | |
6774 | if ((child = database_get_data(conf_node, KEY_JOIN_POLICER, RECDB_OBJECT))) | |
258d1427 | 6775 | dict_foreach(child, set_policer_param, opserv_conf.join_policer_params); |
d76ed9a9 | 6776 | |
6777 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
6778 | struct chanNode *cNode = iter_data(it); | |
6779 | cNode->join_policer.params = opserv_conf.join_policer_params; | |
6780 | } | |
6781 | ||
6782 | if (opserv_conf.new_user_policer.params) | |
6783 | pp = opserv_conf.new_user_policer.params; | |
6784 | else | |
6785 | pp = opserv_conf.new_user_policer.params = policer_params_new(); | |
6786 | policer_params_set(pp, "size", "200"); | |
6787 | policer_params_set(pp, "drain-rate", "3"); | |
6788 | if ((child = database_get_data(conf_node, KEY_NEW_USER_POLICER, RECDB_OBJECT))) | |
258d1427 | 6789 | dict_foreach(child, set_policer_param, pp); |
08895577 | 6790 | |
6791 | /* Defcon configuration */ | |
6792 | DefCon[0] = 0; | |
6793 | str = database_get_data(conf_node, KEY_DEFCON1, RECDB_QSTRING); | |
6794 | DefCon[1] = str ? atoi(str) : 415; | |
6795 | str = database_get_data(conf_node, KEY_DEFCON2, RECDB_QSTRING); | |
6796 | DefCon[2] = str ? atoi(str) : 159; | |
6797 | str = database_get_data(conf_node, KEY_DEFCON3, RECDB_QSTRING); | |
6798 | DefCon[3] = str ? atoi(str) : 31; | |
6799 | str = database_get_data(conf_node, KEY_DEFCON4, RECDB_QSTRING); | |
6800 | DefCon[4] = str? atoi(str) : 23; | |
6801 | DefCon[5] = 0; | |
6802 | ||
6803 | str = database_get_data(conf_node, KEY_DEFCON_LEVEL, RECDB_QSTRING); | |
6804 | DefConLevel = str ? atoi(str) : 5; | |
6805 | ||
6806 | str = database_get_data(conf_node, KEY_DEFCON_CHANMODES, RECDB_QSTRING); | |
6807 | DefConChanModes = str ? strdup(str) : "+r"; | |
6808 | ||
6809 | str = database_get_data(conf_node, KEY_DEFCON_SESSION_LIMIT, RECDB_QSTRING); | |
6810 | DefConSessionLimit = str ? atoi(str) : 2; | |
6811 | ||
6812 | str = database_get_data(conf_node, KEY_DEFCON_TIMEOUT, RECDB_QSTRING); | |
6813 | DefConTimeOut = str ? ParseInterval(str) : 900; | |
6814 | ||
6815 | str = database_get_data(conf_node, KEY_DEFCON_GLINE_DURATION, RECDB_QSTRING); | |
6816 | DefConGlineExpire = str ? ParseInterval(str) : 300; | |
6817 | ||
08895577 | 6818 | str = database_get_data(conf_node, KEY_DEFCON_GLOBAL, RECDB_QSTRING); |
6819 | GlobalOnDefcon = str ? atoi(str) : 0; | |
6820 | ||
6821 | str = database_get_data(conf_node, KEY_DEFCON_GLOBAL_MORE, RECDB_QSTRING); | |
6822 | GlobalOnDefconMore = str ? atoi(str) : 0; | |
6823 | ||
6824 | str = database_get_data(conf_node, KEY_DEFCON_MESSAGE, RECDB_QSTRING); | |
6825 | DefConMessage = str ? strdup(str) : "Put your message to send your users here. Dont forget to uncomment GlobalOnDefconMore"; | |
6826 | ||
6827 | str = database_get_data(conf_node, KEY_DEFCON_OFF_MESSAGE, RECDB_QSTRING); | |
6828 | DefConOffMessage = str? strdup(str) : "Services are now back to normal, sorry for any inconvenience"; | |
6829 | ||
6830 | str = database_get_data(conf_node, KEY_DEFCON_GLINE_REASON, RECDB_QSTRING); | |
6831 | DefConGlineReason = str ? strdup(str) : "This network is currently not accepting connections, please try again later"; | |
d76ed9a9 | 6832 | } |
6833 | ||
5a1daaab | 6834 | /* lame way to export opserv_conf value to nickserv.c ... */ |
6835 | unsigned int | |
6836 | opserv_conf_admin_level() | |
6837 | { | |
6838 | return(opserv_conf.admin_level); | |
6839 | } | |
6840 | ||
d76ed9a9 | 6841 | static void |
6842 | opserv_db_init(void) { | |
6843 | /* set up opserv_trusted_hosts dict */ | |
6844 | dict_delete(opserv_trusted_hosts); | |
6845 | opserv_trusted_hosts = dict_new(); | |
6846 | dict_set_free_data(opserv_trusted_hosts, free_trusted_host); | |
47956fc5 | 6847 | |
6848 | opserv_routing_plan_options = dict_new(); | |
6849 | ||
6850 | opserv_routing_plans = dict_new(); | |
6851 | dict_set_free_data(opserv_routing_plans, free_routing_plan); | |
d76ed9a9 | 6852 | /* set up opserv_chan_warn dict */ |
de9510bc | 6853 | |
6854 | /* alert trace notice channel #x replaces warnings | |
d76ed9a9 | 6855 | dict_delete(opserv_chan_warn); |
6856 | opserv_chan_warn = dict_new(); | |
6857 | dict_set_free_keys(opserv_chan_warn, free); | |
6858 | dict_set_free_data(opserv_chan_warn, free); | |
de9510bc | 6859 | */ |
d76ed9a9 | 6860 | /* set up opserv_user_alerts */ |
6861 | dict_delete(opserv_channel_alerts); | |
6862 | opserv_channel_alerts = dict_new(); | |
6863 | dict_delete(opserv_nick_based_alerts); | |
6864 | opserv_nick_based_alerts = dict_new(); | |
6865 | dict_delete(opserv_user_alerts); | |
6866 | opserv_user_alerts = dict_new(); | |
6867 | dict_set_free_keys(opserv_user_alerts, free); | |
6868 | dict_set_free_data(opserv_user_alerts, opserv_free_user_alert); | |
6869 | /* set up opserv_bad_words */ | |
6870 | free_string_list(opserv_bad_words); | |
6871 | opserv_bad_words = alloc_string_list(4); | |
6872 | /* and opserv_exempt_channels */ | |
6873 | dict_delete(opserv_exempt_channels); | |
6874 | opserv_exempt_channels = dict_new(); | |
6875 | dict_set_free_keys(opserv_exempt_channels, free); | |
6876 | } | |
6877 | ||
6878 | static void | |
6879 | opserv_db_cleanup(void) | |
6880 | { | |
6881 | unsigned int nn; | |
6882 | ||
de9510bc | 6883 | /* dict_delete(opserv_chan_warn); */ |
d76ed9a9 | 6884 | dict_delete(opserv_reserved_nick_dict); |
6885 | free_string_list(opserv_bad_words); | |
6886 | dict_delete(opserv_exempt_channels); | |
6887 | dict_delete(opserv_trusted_hosts); | |
6888 | unreg_del_user_func(opserv_user_cleanup); | |
6889 | dict_delete(opserv_hostinfo_dict); | |
6890 | dict_delete(opserv_nick_based_alerts); | |
6891 | dict_delete(opserv_channel_alerts); | |
6892 | dict_delete(opserv_user_alerts); | |
6893 | for (nn=0; nn<ArrayLength(level_strings); ++nn) | |
6894 | free(level_strings[nn]); | |
6895 | while (gagList) | |
6896 | gag_free(gagList); | |
6897 | policer_params_delete(opserv_conf.join_policer_params); | |
6898 | policer_params_delete(opserv_conf.new_user_policer.params); | |
6899 | } | |
6900 | ||
6901 | void | |
6902 | init_opserv(const char *nick) | |
6903 | { | |
6904 | OS_LOG = log_register_type("OpServ", "file:opserv.log"); | |
a32da4c7 | 6905 | if (nick) { |
6906 | const char *modes = conf_get_data("services/opserv/modes", RECDB_QSTRING); | |
0f6fe38c | 6907 | opserv = AddService(nick, modes ? modes : NULL, "Oper Services", NULL); |
a32da4c7 | 6908 | } |
d76ed9a9 | 6909 | conf_register_reload(opserv_conf_read); |
6910 | ||
6911 | memset(level_strings, 0, sizeof(level_strings)); | |
6912 | opserv_module = module_register("OpServ", OS_LOG, "opserv.help", opserv_help_expand); | |
6913 | opserv_define_func("ACCESS", cmd_access, 0, 0, 0); | |
6914 | opserv_define_func("ADDALERT", cmd_addalert, 800, 0, 4); | |
6915 | opserv_define_func("ADDALERT NOTICE", NULL, 0, 0, 0); | |
9a75756e | 6916 | opserv_define_func("ADDALERT SILENT", NULL, 900, 0, 0); |
d76ed9a9 | 6917 | opserv_define_func("ADDALERT GLINE", NULL, 900, 0, 0); |
d914d1cb | 6918 | opserv_define_func("ADDALERT SHUN", NULL, 900, 0, 0); |
ec311f39 | 6919 | opserv_define_func("ADDALERT TRACK", NULL, 900, 0, 0); |
d76ed9a9 | 6920 | opserv_define_func("ADDALERT KILL", NULL, 900, 0, 0); |
c408f18a | 6921 | opserv_define_func("ADDALERT SVSJOIN", NULL, 999, 0, 0); |
39c1a4ef | 6922 | opserv_define_func("ADDALERT SVSPART", NULL, 999, 0, 0); |
0e08a8e0 | 6923 | opserv_define_func("ADDALERT VERSION", NULL, 999, 0, 0); |
d82cf2f0 | 6924 | opserv_define_func("ADDALERT MARK", NULL, 999, 0, 0); |
d76ed9a9 | 6925 | opserv_define_func("ADDBAD", cmd_addbad, 800, 0, 2); |
6926 | opserv_define_func("ADDEXEMPT", cmd_addexempt, 800, 0, 2); | |
6927 | opserv_define_func("ADDTRUST", cmd_addtrust, 800, 0, 5); | |
6928 | opserv_define_func("BAN", cmd_ban, 100, 2, 2); | |
6929 | opserv_define_func("BLOCK", cmd_block, 100, 0, 2); | |
6930 | opserv_define_func("CHANINFO", cmd_chaninfo, 0, 3, 0); | |
6931 | opserv_define_func("CLEARBANS", cmd_clearbans, 300, 2, 0); | |
6932 | opserv_define_func("CLEARMODES", cmd_clearmodes, 400, 2, 0); | |
6933 | opserv_define_func("CLONE", cmd_clone, 999, 0, 3); | |
6934 | opserv_define_func("COLLIDE", cmd_collide, 800, 0, 5); | |
6935 | opserv_define_func("CSEARCH", cmd_csearch, 100, 0, 3); | |
6936 | opserv_define_func("CSEARCH COUNT", cmd_csearch, 0, 0, 0); | |
6937 | opserv_define_func("CSEARCH PRINT", cmd_csearch, 0, 0, 0); | |
6938 | opserv_define_func("DELALERT", cmd_delalert, 800, 0, 2); | |
6939 | opserv_define_func("DELBAD", cmd_delbad, 800, 0, 2); | |
6940 | opserv_define_func("DELEXEMPT", cmd_delexempt, 800, 0, 2); | |
6941 | opserv_define_func("DELTRUST", cmd_deltrust, 800, 0, 2); | |
6942 | opserv_define_func("DEOP", cmd_deop, 100, 2, 2); | |
6943 | opserv_define_func("DEOPALL", cmd_deopall, 400, 2, 0); | |
08895577 | 6944 | opserv_define_func("DEFCON", cmd_defcon, 900, 0, 0); |
55342ce8 | 6945 | opserv_define_func("DEHOP", cmd_dehop, 100, 2, 2); |
6946 | opserv_define_func("DEHOPALL", cmd_dehopall, 400, 2, 0); | |
d76ed9a9 | 6947 | opserv_define_func("DEVOICEALL", cmd_devoiceall, 300, 2, 0); |
6948 | opserv_define_func("DIE", cmd_die, 900, 0, 2); | |
6949 | opserv_define_func("DUMP", cmd_dump, 999, 0, 2); | |
6950 | opserv_define_func("EDITTRUST", cmd_edittrust, 800, 0, 5); | |
6951 | opserv_define_func("GAG", cmd_gag, 600, 0, 4); | |
6952 | opserv_define_func("GLINE", cmd_gline, 600, 0, 4); | |
6953 | opserv_define_func("GSYNC", cmd_gsync, 600, 0, 0); | |
6954 | opserv_define_func("GTRACE", cmd_gtrace, 100, 0, 3); | |
6955 | opserv_define_func("GTRACE COUNT", NULL, 0, 0, 0); | |
6956 | opserv_define_func("GTRACE PRINT", NULL, 0, 0, 0); | |
d914d1cb | 6957 | opserv_define_func("SBLOCK", cmd_sblock, 100, 0, 2); |
6958 | opserv_define_func("SHUN", cmd_shun, 600, 0, 4); | |
6959 | opserv_define_func("SSYNC", cmd_ssync, 600, 0, 0); | |
6960 | opserv_define_func("STRACE", cmd_strace, 100, 0, 3); | |
6961 | opserv_define_func("STRACE COUNT", NULL, 0, 0, 0); | |
6962 | opserv_define_func("STRACE PRINT", NULL, 0, 0, 0); | |
d76ed9a9 | 6963 | opserv_define_func("INVITE", cmd_invite, 100, 2, 0); |
6964 | opserv_define_func("INVITEME", cmd_inviteme, 100, 0, 0); | |
0f6fe38c | 6965 | opserv_define_func("JOIN", cmd_join, 601, 0, 2); |
964a842d | 6966 | opserv_define_func("SVSNICK", cmd_svsnick, 999, 0, 3); |
c408f18a | 6967 | opserv_define_func("SVSJOIN", cmd_svsjoin, 999, 0, 3); |
39c1a4ef | 6968 | opserv_define_func("SVSPART", cmd_svspart, 999, 0, 3); |
d76ed9a9 | 6969 | opserv_define_func("JUMP", cmd_jump, 900, 0, 2); |
6970 | opserv_define_func("JUPE", cmd_jupe, 900, 0, 4); | |
6971 | opserv_define_func("KICK", cmd_kick, 100, 2, 2); | |
6972 | opserv_define_func("KICKALL", cmd_kickall, 400, 2, 0); | |
6973 | opserv_define_func("KICKBAN", cmd_kickban, 100, 2, 2); | |
6974 | opserv_define_func("KICKBANALL", cmd_kickbanall, 450, 2, 0); | |
6975 | opserv_define_func("LOG", cmd_log, 900, 0, 2); | |
6976 | opserv_define_func("MODE", cmd_mode, 100, 2, 2); | |
d82cf2f0 | 6977 | opserv_define_func("MARK", cmd_mark, 900, 0, 3); |
d76ed9a9 | 6978 | opserv_define_func("OP", cmd_op, 100, 2, 2); |
6979 | opserv_define_func("OPALL", cmd_opall, 400, 2, 0); | |
55342ce8 | 6980 | opserv_define_func("HOP", cmd_hop, 100, 2, 2); |
6981 | opserv_define_func("HOPALL", cmd_hopall, 400, 2, 0); | |
47956fc5 | 6982 | opserv_define_func("MAP", cmd_stats_links, 0, 0, 0); |
6c34bb5a | 6983 | opserv_define_func("PRIVSET", cmd_privset, 900, 0, 3); |
0f6fe38c | 6984 | opserv_define_func("PART", cmd_part, 601, 0, 2); |
d76ed9a9 | 6985 | opserv_define_func("QUERY", cmd_query, 0, 0, 0); |
6986 | opserv_define_func("RAW", cmd_raw, 999, 0, 2); | |
6987 | opserv_define_func("RECONNECT", cmd_reconnect, 900, 0, 0); | |
6988 | opserv_define_func("REFRESHG", cmd_refreshg, 600, 0, 0); | |
d914d1cb | 6989 | opserv_define_func("REFRESHS", cmd_refreshs, 600, 0, 0); |
d76ed9a9 | 6990 | opserv_define_func("REHASH", cmd_rehash, 900, 0, 0); |
6991 | opserv_define_func("REOPEN", cmd_reopen, 900, 0, 0); | |
7637f48f | 6992 | opserv_define_func("RESETMAX", cmd_resetmax, 900, 0, 0); |
d76ed9a9 | 6993 | opserv_define_func("RESERVE", cmd_reserve, 800, 0, 5); |
6994 | opserv_define_func("RESTART", cmd_restart, 900, 0, 2); | |
47956fc5 | 6995 | opserv_define_func("ROUTING ADDPLAN", cmd_routing_addplan, 800, 0, 2); |
6996 | opserv_define_func("ROUTING DELPLAN", cmd_routing_delplan, 800, 0, 2); | |
6997 | opserv_define_func("ROUTING ADDSERVER", cmd_routing_addserver, 800, 0, 4); | |
6998 | opserv_define_func("ROUTING DELSERVER", cmd_routing_delserver, 800, 0, 3); | |
6999 | opserv_define_func("ROUTING MAP", cmd_routing_map, 800, 0, 0); | |
7000 | opserv_define_func("ROUTING SET", cmd_routing_set, 800, 0, 0); | |
7001 | opserv_define_func("REROUTE", cmd_reroute, 800, 0, 2); | |
d76ed9a9 | 7002 | opserv_define_func("SET", cmd_set, 900, 0, 3); |
7003 | opserv_define_func("SETTIME", cmd_settime, 901, 0, 0); | |
7004 | opserv_define_func("STATS ALERTS", cmd_stats_alerts, 0, 0, 0); | |
7005 | opserv_define_func("STATS BAD", cmd_stats_bad, 0, 0, 0); | |
7006 | opserv_define_func("STATS GAGS", cmd_stats_gags, 0, 0, 0); | |
7007 | opserv_define_func("STATS GLINES", cmd_stats_glines, 0, 0, 0); | |
d914d1cb | 7008 | opserv_define_func("STATS SHUNS", cmd_stats_shuns, 0, 0, 0); |
d76ed9a9 | 7009 | opserv_define_func("STATS LINKS", cmd_stats_links, 0, 0, 0); |
7010 | opserv_define_func("STATS MAX", cmd_stats_max, 0, 0, 0); | |
7011 | opserv_define_func("STATS NETWORK", cmd_stats_network, 0, 0, 0); | |
7012 | opserv_define_func("STATS NETWORK2", cmd_stats_network2, 0, 0, 0); | |
7013 | opserv_define_func("STATS RESERVED", cmd_stats_reserved, 0, 0, 0); | |
47956fc5 | 7014 | opserv_define_func("STATS ROUTING", cmd_stats_routing_plans, 0, 0, 0); |
d76ed9a9 | 7015 | opserv_define_func("STATS TIMEQ", cmd_stats_timeq, 0, 0, 0); |
7016 | opserv_define_func("STATS TRUSTED", cmd_stats_trusted, 0, 0, 0); | |
7017 | opserv_define_func("STATS UPLINK", cmd_stats_uplink, 0, 0, 0); | |
7018 | opserv_define_func("STATS UPTIME", cmd_stats_uptime, 0, 0, 0); | |
de9510bc | 7019 | /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */ |
f14e4f83 | 7020 | #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB) |
ec1a68c8 | 7021 | opserv_define_func("STATS MEMORY", cmd_stats_memory, 0, 0, 0); |
7022 | #endif | |
d76ed9a9 | 7023 | opserv_define_func("TRACE", cmd_trace, 100, 0, 3); |
7024 | opserv_define_func("TRACE PRINT", NULL, 0, 0, 0); | |
7025 | opserv_define_func("TRACE COUNT", NULL, 0, 0, 0); | |
7026 | opserv_define_func("TRACE DOMAINS", NULL, 0, 0, 0); | |
7027 | opserv_define_func("TRACE GLINE", NULL, 600, 0, 0); | |
d914d1cb | 7028 | opserv_define_func("TRACE SHUN", NULL, 600, 0, 0); |
d76ed9a9 | 7029 | opserv_define_func("TRACE GAG", NULL, 600, 0, 0); |
7030 | opserv_define_func("TRACE KILL", NULL, 600, 0, 0); | |
0e08a8e0 | 7031 | opserv_define_func("TRACE VERSION", NULL, 999, 0, 0); |
7032 | opserv_define_func("TRACE SVSJOIN", NULL, 999, 0, 0); | |
39c1a4ef | 7033 | opserv_define_func("TRACE SVSPART", NULL, 999, 0, 0); |
d82cf2f0 | 7034 | opserv_define_func("TRACE MARK", NULL, 999, 0, 0); |
d76ed9a9 | 7035 | opserv_define_func("UNBAN", cmd_unban, 100, 2, 2); |
7036 | opserv_define_func("UNGAG", cmd_ungag, 600, 0, 2); | |
7037 | opserv_define_func("UNGLINE", cmd_ungline, 600, 0, 2); | |
7038 | modcmd_register(opserv_module, "GTRACE UNGLINE", NULL, 0, 0, "template", "ungline", NULL); | |
d914d1cb | 7039 | opserv_define_func("UNSHUN", cmd_unshun, 600, 0, 2); |
7040 | modcmd_register(opserv_module, "GTRACE UNSHUN", NULL, 0, 0, "template", "unshun", NULL); | |
d76ed9a9 | 7041 | opserv_define_func("UNJUPE", cmd_unjupe, 900, 0, 2); |
7042 | opserv_define_func("UNRESERVE", cmd_unreserve, 800, 0, 2); | |
de9510bc | 7043 | /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */ |
d76ed9a9 | 7044 | opserv_define_func("VOICEALL", cmd_voiceall, 300, 2, 0); |
de9510bc | 7045 | /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */ |
d76ed9a9 | 7046 | opserv_define_func("WHOIS", cmd_whois, 0, 0, 2); |
7047 | ||
7048 | opserv_reserved_nick_dict = dict_new(); | |
7049 | opserv_hostinfo_dict = dict_new(); | |
47956fc5 | 7050 | |
d76ed9a9 | 7051 | dict_set_free_keys(opserv_hostinfo_dict, free); |
7052 | dict_set_free_data(opserv_hostinfo_dict, opserv_free_hostinfo); | |
7053 | ||
47956fc5 | 7054 | opserv_waiting_connections = dict_new(); |
7055 | dict_set_free_data(opserv_waiting_connections, opserv_free_waiting_connection); | |
7056 | ||
d76ed9a9 | 7057 | reg_new_user_func(opserv_new_user_check); |
7058 | reg_nick_change_func(opserv_alert_check_nick); | |
7059 | reg_del_user_func(opserv_user_cleanup); | |
c52666c6 | 7060 | reg_new_channel_func(opserv_channel_check); |
d76ed9a9 | 7061 | reg_del_channel_func(opserv_channel_delete); |
7062 | reg_join_func(opserv_join_check); | |
7063 | reg_auth_func(opserv_staff_alert); | |
0e08a8e0 | 7064 | reg_notice_func(opserv, opserv_notice_handler); |
d76ed9a9 | 7065 | |
7066 | opserv_db_init(); | |
7067 | saxdb_register("OpServ", opserv_saxdb_read, opserv_saxdb_write); | |
7068 | if (nick) | |
258d1427 | 7069 | { |
7070 | opserv_service = service_register(opserv); | |
7071 | opserv_service->trigger = '?'; | |
7072 | } | |
d76ed9a9 | 7073 | |
47956fc5 | 7074 | /* start auto-routing system */ |
9079d26c | 7075 | /* this cant be done here, because the routing system isnt marked active yet. */ |
7076 | /* reroute_timer(NULL); */ | |
7077 | ||
47956fc5 | 7078 | /* start the karma timer, using the saved one if available */ |
7079 | routing_karma_timer(dict_find(opserv_routing_plan_options, "KARMA_TIMER", NULL)); | |
7080 | ||
d76ed9a9 | 7081 | reg_exit_func(opserv_db_cleanup); |
7082 | message_register_table(msgtab); | |
7083 | } |