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