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