]>
Commit | Line | Data |
---|---|---|
d76ed9a9 AS |
1 | /* opserv.c - IRC Operator assistance service |
2 | * Copyright 2000-2004 srvx Development Team | |
3 | * | |
83ff05c3 | 4 | * This file is part of x3. |
d76ed9a9 AS |
5 | * |
6 | * srvx is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
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 | ||
21 | #include "conf.h" | |
22 | #include "gline.h" | |
23 | #include "global.h" | |
24 | #include "nickserv.h" | |
25 | #include "modcmd.h" | |
26 | #include "opserv.h" | |
27 | #include "timeq.h" | |
28 | #include "saxdb.h" | |
d914d1cb | 29 | #include "shun.h" |
d76ed9a9 AS |
30 | |
31 | #ifdef HAVE_SYS_TIMES_H | |
32 | #include <sys/times.h> | |
33 | #endif | |
34 | #ifdef HAVE_NETINET_IN_H | |
35 | #include <netinet/in.h> | |
36 | #endif | |
37 | #ifdef HAVE_ARPA_INET_H | |
38 | #include <arpa/inet.h> | |
39 | #endif | |
27eaa617 | 40 | #ifdef HAVE_REGEX_H |
41 | #include <regex.h> | |
42 | #endif | |
d76ed9a9 AS |
43 | |
44 | #define OPSERV_CONF_NAME "services/opserv" | |
45 | ||
46 | #define KEY_ALERT_CHANNEL "alert_channel" | |
47 | #define KEY_ALERT_CHANNEL_MODES "alert_channel_modes" | |
48 | #define KEY_DEBUG_CHANNEL "debug_channel" | |
49 | #define KEY_DEBUG_CHANNEL_MODES "debug_channel_modes" | |
50 | #define KEY_UNTRUSTED_MAX "untrusted_max" | |
51 | #define KEY_PURGE_LOCK_DELAY "purge_lock_delay" | |
52 | #define KEY_JOIN_FLOOD_MODERATE "join_flood_moderate" | |
53 | #define KEY_JOIN_FLOOD_MODERATE_THRESH "join_flood_moderate_threshold" | |
54 | #define KEY_NICK "nick" | |
55 | #define KEY_JOIN_POLICER "join_policer" | |
56 | #define KEY_NEW_USER_POLICER "new_user_policer" | |
57 | #define KEY_REASON "reason" | |
58 | #define KEY_RESERVES "reserves" | |
59 | #define KEY_IDENT "username" /* for compatibility with 1.0 DBs */ | |
60 | #define KEY_HOSTNAME "hostname" | |
61 | #define KEY_DESC "description" | |
62 | #define KEY_BAD_WORDS "bad" | |
63 | #define KEY_EXEMPT_CHANNELS "exempt" | |
64 | #define KEY_SECRET_WORDS "secret" | |
65 | #define KEY_TRUSTED_HOSTS "trusted" | |
66 | #define KEY_OWNER "owner" | |
67 | #define KEY_GAGS "gags" | |
68 | #define KEY_ALERTS "alerts" | |
69 | #define KEY_REACTION "reaction" | |
70 | #define KEY_DISCRIM "discrim" | |
71 | #define KEY_WARN "chanwarn" | |
72 | #define KEY_MAX "max" | |
73 | #define KEY_TIME "time" | |
74 | #define KEY_MAX_CLIENTS "max_clients" | |
75 | #define KEY_LIMIT "limit" | |
76 | #define KEY_EXPIRES "expires" | |
77 | #define KEY_STAFF_AUTH_CHANNEL "staff_auth_channel" | |
78 | #define KEY_STAFF_AUTH_CHANNEL_MODES "staff_auth_channel_modes" | |
79 | #define KEY_CLONE_GLINE_DURATION "clone_gline_duration" | |
80 | #define KEY_BLOCK_GLINE_DURATION "block_gline_duration" | |
d914d1cb | 81 | #define KEY_BLOCK_SHUN_DURATION "block_shun_duration" |
d76ed9a9 AS |
82 | #define KEY_ISSUER "issuer" |
83 | #define KEY_ISSUED "issued" | |
5a1daaab | 84 | #define KEY_ADMIN_LEVEL "admin_level" |
d76ed9a9 | 85 | |
258d1427 AS |
86 | #define IDENT_FORMAT "%s [%s@%s/%s]" |
87 | #define IDENT_DATA(user) user->nick, user->ident, user->hostname, inet_ntoa(user->ip) | |
88 | #define MAX_CHANNELS_WHOIS 50 | |
d76ed9a9 AS |
89 | #define OSMSG_PART_REASON "%s has no reason." |
90 | #define OSMSG_KICK_REQUESTED "Kick requested by %s." | |
91 | #define OSMSG_KILL_REQUESTED "Kill requested by %s." | |
92 | #define OSMSG_GAG_REQUESTED "Gag requested by %s." | |
93 | ||
94 | static const struct message_entry msgtab[] = { | |
de9510bc | 95 | { "OSMSG_BAR", "----------------------------------------" }, |
d76ed9a9 AS |
96 | { "OSMSG_USER_ACCESS_IS", "$b%s$b (account $b%s$b) has %d access." }, |
97 | { "OSMSG_LEVEL_TOO_LOW", "You lack sufficient access to use this command." }, | |
98 | { "OSMSG_NEED_CHANNEL", "You must specify a channel for $b%s$b." }, | |
99 | { "OSMSG_INVALID_IRCMASK", "$b%s$b is an invalid IRC hostmask." }, | |
100 | { "OSMSG_ADDED_BAN", "I have banned $b%s$b from $b%s$b." }, | |
d914d1cb | 101 | { "OSMSG_SHUN_ISSUED", "Shun issued for $b%s$b." }, |
102 | { "OSMSG_SHUN_REMOVED", "Shun removed for $b%s$b." }, | |
103 | { "OSMSG_SHUN_FORCE_REMOVED", "Unknown/expired Shun removed for $b%s$b." }, | |
104 | { "OSMSG_SHUN_ONE_REFRESHED", "All Shuns resent to $b%s$b." }, | |
105 | { "OSMSG_SHUN_REFRESHED", "All Shuns refreshed." }, | |
d76ed9a9 AS |
106 | { "OSMSG_GLINE_ISSUED", "G-line issued for $b%s$b." }, |
107 | { "OSMSG_GLINE_REMOVED", "G-line removed for $b%s$b." }, | |
108 | { "OSMSG_GLINE_FORCE_REMOVED", "Unknown/expired G-line removed for $b%s$b." }, | |
109 | { "OSMSG_GLINES_ONE_REFRESHED", "All G-lines resent to $b%s$b." }, | |
110 | { "OSMSG_GLINES_REFRESHED", "All G-lines refreshed." }, | |
111 | { "OSMSG_CLEARBANS_DONE", "Cleared all bans from channel $b%s$b." }, | |
112 | { "OSMSG_CLEARMODES_DONE", "Cleared all modes from channel $b%s$b." }, | |
113 | { "OSMSG_NO_CHANNEL_MODES", "Channel $b%s$b had no modes to clear." }, | |
114 | { "OSMSG_DEOP_DONE", "Deopped the requested lusers." }, | |
115 | { "OSMSG_DEOPALL_DONE", "Deopped everyone on $b%s$b." }, | |
55342ce8 | 116 | { "OSMSG_DEHOP_DONE", "Dehalfopped the requested lusers." }, |
117 | { "OSMSG_DEHOPALL_DONE", "Dehalfopped everyone on $b%s$b." }, | |
d76ed9a9 AS |
118 | { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." }, |
119 | { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." }, | |
120 | { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." }, | |
121 | { "OSMSG_JOIN_DONE", "I have joined $b%s$b." }, | |
122 | { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." }, | |
123 | { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." }, | |
124 | { "OSMSG_KICKALL_DONE", "I have cleared out %s." }, | |
125 | { "OSMSG_LEAVING", "Leaving $b%s$b." }, | |
126 | { "OSMSG_MODE_SET", "I have set the modes for $b%s$b." }, | |
127 | { "OSMSG_OP_DONE", "Opped the requested lusers." }, | |
128 | { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." }, | |
55342ce8 | 129 | { "OSMSG_HOP_DONE", "Halfopped the requested lusers." }, |
130 | { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." }, | |
d76ed9a9 AS |
131 | { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" }, |
132 | { "OSMSG_WHOIS_NICK", "Nick : %s" }, | |
133 | { "OSMSG_WHOIS_HOST", "Host : %s@%s" }, | |
134 | { "OSMSG_WHOIS_FAKEHOST", "Fakehost: %s" }, | |
135 | { "OSMSG_WHOIS_IP", "Real IP : %s" }, | |
136 | { "OSMSG_WHOIS_MODES", "Modes : +%s " }, | |
137 | { "OSMSG_WHOIS_INFO", "Info : %s" }, | |
138 | { "OSMSG_WHOIS_NUMERIC", "Numnick : %s" }, | |
139 | { "OSMSG_WHOIS_SERVER", "Server : %s" }, | |
140 | { "OSMSG_WHOIS_NICK_AGE", "Nick Age: %s" }, | |
141 | { "OSMSG_WHOIS_ACCOUNT", "Account : %s" }, | |
142 | { "OSMSG_WHOIS_CHANNELS", "Channels: %s" }, | |
143 | { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." }, | |
144 | { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." }, | |
145 | { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." }, | |
146 | { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." }, | |
147 | { "OSMSG_BAD_MODIFIER", "Unknown bad-word modifier $b%s$b." }, | |
148 | { "OSMSG_BAD_REDUNDANT", "$b%s$b is already covered by a bad word ($b%s$b)." }, | |
149 | { "OSMSG_BAD_GROWING", "Replacing bad word $b%s$b with shorter bad word $b%s$b." }, | |
150 | { "OSMSG_BAD_NUKING", " .. and removing redundant bad word $b%s$b." }, | |
151 | { "OSMSG_ADDED_BAD", "Added $b%s$b to the bad-word list." }, | |
152 | { "OSMSG_REMOVED_BAD", "Removed $b%s$b from the bad-word list." }, | |
153 | { "OSMSG_NOT_BAD_WORD", "$b%s$b is not a bad word." }, | |
154 | { "OSMSG_ADDED_EXEMPTION", "Added $b%s$b to the bad-word exemption list." }, | |
155 | { "OSMSG_ADDED_EXEMPTIONS", "Added %d exception(s) to the bad word list." }, | |
156 | { "OSMSG_REMOVED_EXEMPTION", "Removed $b%s$b from the exemption list." }, | |
157 | { "OSMSG_NOT_EXEMPT", "$b%s$b is not on the exempt list." }, | |
158 | { "OSMSG_ALREADY_TRUSTED", "Host $b%s$b is already trusted (use $bdeltrust$b and then $baddtrust$b to adjust)." }, | |
159 | { "OSMSG_NOT_TRUSTED", "Host $b%s$b is not trusted." }, | |
160 | { "OSMSG_BAD_IP", "$b%s$b is not a valid IP address" }, | |
161 | { "OSMSG_BAD_NUMBER", "$b%s$b is not a number" }, | |
162 | { "OSMSG_ADDED_TRUSTED", "Added trusted hosts to the trusted-hosts list." }, | |
163 | { "OSMSG_UPDATED_TRUSTED", "Updated trusted host $b%s$b." }, | |
164 | { "OSMSG_REMOVED_TRUSTED", "Removed trusted hosts from the trusted-hosts list." }, | |
165 | { "OSMSG_CLONE_EXISTS", "Nick $b%s$b is already in use." }, | |
166 | { "OSMSG_NOT_A_HOSTMASK", "The hostmask must be in user@host form." }, | |
167 | { "OSMSG_BADWORD_LIST", "Bad words: %s" }, | |
168 | { "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" }, | |
169 | { "OSMSG_GLINE_COUNT", "There are %d glines active on the network." }, | |
d914d1cb | 170 | { "OSMSG_SHUN_COUNT", "There are %d shuns active on the network." }, |
d76ed9a9 AS |
171 | { "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" }, |
172 | { "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" }, | |
173 | { "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" }, | |
174 | { "OSMSG_RESERVED_LIST", "List of reserved nicks:" }, | |
de9510bc AS |
175 | { "OSMSG_TRUSTED_LIST", "$bTrusted Hosts$b" }, |
176 | { "OSMSG_TRUSTED_LIST_HEADER", "IP Address Limit By Time" }, | |
177 | { "OSMSG_HOST_IS_TRUSTED", "%-15s %-5s %-10s set %s ago, expires %s" }, | |
178 | { "OSMSG_HOST_IS_TRUSTED_DESC", " Reason: %s" }, | |
179 | { "OSMSG_TRUSTED_LIST_BAR", "----------------------------------------" }, | |
180 | { "OSMSG_TRUSTED_LIST_END", "----------End of Trusted Hosts----------" }, | |
d76ed9a9 AS |
181 | { "OSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." }, |
182 | { "OSMSG_UPTIME_STATS", "Uptime: %s (%u lines processed, CPU time %.2fu/%.2fs)" }, | |
183 | { "OSMSG_LINE_DUMPED", "Raw line sent." }, | |
184 | { "OSMSG_RAW_PARSE_ERROR", "Error parsing raw line (not dumping to uplink)." }, | |
185 | { "OSMSG_COLLIDED_NICK", "Now temporarily holding nick $b%s$b." }, | |
186 | { "OSMSG_RESERVED_NICK", "Now reserving nick $b%s$b." }, | |
187 | { "OSMSG_NICK_UNRESERVED", "Nick $b%s$b is no longer reserved." }, | |
188 | { "OSMSG_NOT_RESERVED", "Nick $b%s$b is not reserved." }, | |
189 | { "OSMSG_ILLEGAL_REASON", "This channel is illegal." }, | |
190 | { "OSMSG_ILLEGAL_KILL_REASON", "Joined an illegal modeless channel - do not repeat." }, | |
191 | { "OSMSG_ILLEGAL_CHANNEL", "$b%s$b is an ILLEGAL channel. Do not re-join it." }, | |
192 | { "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." }, | |
193 | { "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." }, | |
194 | { "OSMSG_CLONE_ADDED", "Added clone $b%s$b." }, | |
195 | { "OSMSG_CLONE_FAILED", "Unable to add user $b%s$b." }, | |
196 | { "OSMSG_NOT_A_CLONE", "Har har. $b%s$b isn't a clone." }, | |
197 | { "OSMSG_CLONE_REMOVED", "Removed clone $b%s$b." }, | |
198 | { "OSMSG_CLONE_JOINED", "$b%s$b has joined $b%s$b." }, | |
199 | { "OSMSG_CLONE_PARTED", "$b%s$b has left $b%s$b." }, | |
200 | { "OSMSG_OPS_GIVEN", "I have given ops in $b%s$b to $b%s$b." }, | |
55342ce8 | 201 | { "OSMSG_HOPS_GIVEN", "I have given halfops in $b%s$b to $b%s$b." }, |
d76ed9a9 AS |
202 | { "OSMSG_CLONE_SAID", "$b%s$b has spoken to $b%s$b." }, |
203 | { "OSMSG_UNKNOWN_SUBCOMMAND", "$b%s$b is not a valid subcommand of $b%s$b." }, | |
204 | { "OSMSG_UNKNOWN_OPTION", "$b%s$b has not been set." }, | |
205 | { "OSMSG_OPTION_IS", "$b%s$b is set to $b%s$b." }, | |
206 | { "OSMSG_OPTION_ROOT", "The following keys can be queried:" }, | |
207 | { "OSMSG_OPTION_LIST", "$b%s$b contains the following values:" }, | |
208 | { "OSMSG_OPTION_KEYS", "$b%s$b contains the following keys:" }, | |
209 | { "OSMSG_OPTION_LIST_EMPTY", "Empty list." }, | |
210 | { "OSMSG_SET_NOT_SET", "$b%s$b does not exist, and cannot be set." }, | |
211 | { "OSMSG_SET_BAD_TYPE", "$b%s$b is not a string, and cannot be set." }, | |
212 | { "OSMSG_SET_SUCCESS", "$b%s$b has been set to $b%s$b." }, | |
213 | { "OSMSG_SETTIME_SUCCESS", "Set time for servers named like $b%s$b." }, | |
214 | { "OSMSG_BAD_ACTION", "Unrecognized trace action $b%s$b." }, | |
215 | { "OSMSG_USER_SEARCH_RESULTS", "The following users were found:" }, | |
de9510bc AS |
216 | { "OSMSG_USER_SEARCH_HEADER", "Nick User@Host (Account)" }, |
217 | { "OSMSG_USER_SEARCH_BAR", "-------------------------------------------" }, | |
8e11460f AS |
218 | { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" }, |
219 | { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" }, | |
d76ed9a9 AS |
220 | { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" }, |
221 | { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" }, | |
d914d1cb | 222 | { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" }, |
d76ed9a9 AS |
223 | { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" }, |
224 | { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." }, | |
d914d1cb | 225 | { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." }, |
d76ed9a9 | 226 | { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" }, |
d914d1cb | 227 | { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" }, |
d76ed9a9 AS |
228 | { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." }, |
229 | { "OSMSG_GAG_ADDED", "Gagged $b%s$b." }, | |
230 | { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." }, | |
231 | { "OSMSG_GAG_NOT_FOUND", "Could not find gag $b%s$b." }, | |
232 | { "OSMSG_NO_GAGS", "No gags have been set." }, | |
233 | { "OSMSG_UNGAG_APPLIED", "Ungagged $b%s$b, affecting %d users." }, | |
234 | { "OSMSG_UNGAG_ADDED", "Ungagged $b%s$b." }, | |
235 | { "OSMSG_TIMEQ_INFO", "%u events in timeq; next in %lu seconds." }, | |
236 | { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." }, | |
237 | { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." }, | |
238 | { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." }, | |
239 | { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." }, | |
240 | { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." }, | |
de9510bc AS |
241 | { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" }, |
242 | { "OSMSG_ALERTS_BAR", "----------------------------------------------" }, | |
243 | { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" }, | |
244 | { "OSMSG_ALERTS_DESC", " Criteria: %s" }, | |
245 | { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" }, | |
246 | { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" }, | |
d76ed9a9 AS |
247 | { "OSMSG_REHASH_COMPLETE", "Completed rehash of configuration database." }, |
248 | { "OSMSG_REHASH_FAILED", "Rehash of configuration database failed, previous configuration is intact." }, | |
249 | { "OSMSG_REOPEN_COMPLETE", "Closed and reopened all log files." }, | |
250 | { "OSMSG_RECONNECTING", "Reconnecting to my uplink." }, | |
251 | { "OSMSG_NUMERIC_COLLIDE", "Numeric %d (%s) is already in use." }, | |
252 | { "OSMSG_NAME_COLLIDE", "That name is already in use." }, | |
253 | { "OSMSG_SRV_CREATE_FAILED", "Server creation failed -- check log files." }, | |
254 | { "OSMSG_SERVER_JUPED", "Added new jupe server %s." }, | |
255 | { "OSMSG_SERVER_NOT_JUPE", "That server is not a juped server." }, | |
256 | { "OSMSG_SERVER_UNJUPED", "Server jupe removed." }, | |
c52666c6 | 257 | /* |
d76ed9a9 AS |
258 | { "OSMSG_WARN_ADDED", "Added channel activity warning for $b%s$b (%s)" }, |
259 | { "OSMSG_WARN_EXISTS", "Channel activity warning for $b%s$b already exists." }, | |
260 | { "OSMSG_WARN_DELETED", "Removed channel activity warning for $b%s$b" }, | |
261 | { "OSMSG_WARN_NOEXIST", "Channel activity warning for $b%s$b does not exist." }, | |
262 | { "OSMSG_WARN_LISTSTART", "Channel activity warnings:" }, | |
263 | { "OSMSG_WARN_LISTENTRY", "%s (%s)" }, | |
264 | { "OSMSG_WARN_LISTEND", "End of activity warning list." }, | |
c52666c6 | 265 | */ |
d76ed9a9 AS |
266 | { "OSMSG_UPLINK_CONNECTING", "Establishing connection with %s (%s:%d)." }, |
267 | { "OSMSG_CURRENT_UPLINK", "$b%s$b is already the current uplink." }, | |
268 | { "OSMSG_INVALID_UPLINK", "$b%s$b is not a valid uplink name." }, | |
269 | { "OSMSG_UPLINK_DISABLED", "$b%s$b is a disabled or unavailable uplink." }, | |
270 | { "OSMSG_UPLINK_START", "Uplink $b%s$b:" }, | |
271 | { "OSMSG_UPLINK_ADDRESS", "Address: %s:%d" }, | |
272 | { "OSMSG_STUPID_GLINE", "Gline %s? Now $bthat$b would be smooth." }, | |
d914d1cb | 273 | { "OSMSG_STUPID_SHUN", "Shun %s? Now $bthat$b would be smooth." }, |
d76ed9a9 AS |
274 | { "OSMSG_ACCOUNTMASK_AUTHED", "Invalid criteria: it is impossible to match an account mask but not be authed" }, |
275 | { "OSMSG_CHANINFO_HEADER", "%s Information" }, | |
276 | { "OSMSG_CHANINFO_TIMESTAMP", "Created on: %a %b %d %H:%M:%S %Y (%s)" }, | |
277 | { "OSMSG_CHANINFO_MODES", "Modes: %s" }, | |
278 | { "OSMSG_CHANINFO_MODES_BADWORD", "Modes: %s; bad-word channel" }, | |
279 | { "OSMSG_CHANINFO_TOPIC", "Topic (set by %%s, %a %b %d %H:%M:%S %Y): %%s" }, | |
280 | { "OSMSG_CHANINFO_TOPIC_UNKNOWN", "Topic: (none / not gathered)" }, | |
281 | { "OSMSG_CHANINFO_BAN_COUNT", "Bans (%d):" }, | |
282 | { "OSMSG_CHANINFO_BAN", "%%s by %%s (%a %b %d %H:%M:%S %Y)" }, | |
2aef5f4b | 283 | { "OSMSG_CHANINFO_EXEMPT_COUNT", "Exempts (%d):" }, |
284 | { "OSMSG_CHANINFO_EXEMPT", "%%s by %%s (%a %b %d %H:%M:%S %Y)" }, | |
d76ed9a9 AS |
285 | { "OSMSG_CHANINFO_MANY_USERS", "%d users (\"/msg $S %s %s users\" for the list)" }, |
286 | { "OSMSG_CHANINFO_USER_COUNT", "Users (%d):" }, | |
287 | { "OSMSG_CSEARCH_CHANNEL_INFO", "%s [%d users] %s %s" }, | |
27eaa617 | 288 | { "OSMSG_INVALID_REGEX", "Invalid regex: %s: %s (%d)" }, |
d76ed9a9 AS |
289 | { NULL, NULL } |
290 | }; | |
291 | ||
b1bf690d | 292 | #define OPSERV_SYNTAX() svccmd_send_help_brief(user, opserv, cmd) |
d76ed9a9 AS |
293 | |
294 | typedef int (*discrim_search_func)(struct userNode *match, void *extra); | |
295 | ||
296 | struct userNode *opserv; | |
258d1427 | 297 | static struct service *opserv_service; |
d76ed9a9 | 298 | |
de9510bc | 299 | /*static dict_t opserv_chan_warn; */ /* data is char* */ |
d76ed9a9 AS |
300 | static dict_t opserv_reserved_nick_dict; /* data is struct userNode* */ |
301 | static struct string_list *opserv_bad_words; | |
302 | static dict_t opserv_exempt_channels; /* data is not used */ | |
303 | static dict_t opserv_trusted_hosts; /* data is struct trusted_host* */ | |
304 | static dict_t opserv_hostinfo_dict; /* data is struct opserv_hostinfo* */ | |
305 | static dict_t opserv_user_alerts; /* data is struct opserv_user_alert* */ | |
306 | static dict_t opserv_nick_based_alerts; /* data is struct opserv_user_alert* */ | |
307 | static dict_t opserv_channel_alerts; /* data is struct opserv_user_alert* */ | |
308 | static struct module *opserv_module; | |
309 | static struct log_type *OS_LOG; | |
310 | static unsigned int new_user_flood; | |
311 | static char *level_strings[1001]; | |
312 | ||
313 | static struct { | |
314 | struct chanNode *debug_channel; | |
315 | struct chanNode *alert_channel; | |
316 | struct chanNode *staff_auth_channel; | |
317 | struct policer_params *join_policer_params; | |
318 | struct policer new_user_policer; | |
319 | unsigned long untrusted_max; | |
320 | unsigned long clone_gline_duration; | |
321 | unsigned long block_gline_duration; | |
d914d1cb | 322 | unsigned long block_shun_duration; |
d76ed9a9 AS |
323 | unsigned long purge_lock_delay; |
324 | unsigned long join_flood_moderate; | |
325 | unsigned long join_flood_moderate_threshold; | |
5a1daaab | 326 | unsigned long admin_level; |
d76ed9a9 AS |
327 | } opserv_conf; |
328 | ||
329 | struct trusted_host { | |
330 | char *ipaddr; | |
331 | char *issuer; | |
332 | char *reason; | |
333 | unsigned long limit; | |
334 | time_t issued; | |
335 | time_t expires; | |
336 | }; | |
337 | ||
338 | struct gag_entry { | |
339 | char *mask; | |
340 | char *owner; | |
341 | char *reason; | |
342 | time_t expires; | |
343 | struct gag_entry *next; | |
344 | }; | |
345 | ||
346 | static struct gag_entry *gagList; | |
347 | ||
348 | struct opserv_hostinfo { | |
349 | struct userList clients; | |
350 | struct trusted_host *trusted; | |
351 | }; | |
352 | ||
353 | static void | |
354 | opserv_free_hostinfo(void *data) | |
355 | { | |
356 | struct opserv_hostinfo *ohi = data; | |
357 | userList_clean(&ohi->clients); | |
358 | free(ohi); | |
359 | } | |
360 | ||
361 | typedef struct opservDiscrim { | |
362 | struct chanNode *channel; | |
363 | char *mask_nick, *mask_ident, *mask_host, *mask_info, *server, *ip_mask_str, *reason, *accountmask; | |
27eaa617 | 364 | regex_t regex_nick, regex_ident, regex_host, regex_info; |
365 | unsigned int has_regex_nick : 1, has_regex_ident : 1, has_regex_host : 1, has_regex_info : 1; | |
d76ed9a9 AS |
366 | unsigned long limit, ip_mask; |
367 | struct in_addr ip_addr; | |
368 | unsigned int min_level, max_level, domain_depth, duration, min_clones, min_channels, max_channels; | |
369 | unsigned int match_opers : 1, option_log : 1; | |
370 | unsigned int chan_req_modes : 2, chan_no_modes : 2; | |
371 | int authed : 2, info_space : 2; | |
63665495 | 372 | unsigned int intra_scmp : 2, intra_dcmp : 2; |
d76ed9a9 | 373 | time_t min_ts, max_ts; |
27eaa617 | 374 | unsigned int use_regex : 1; |
d76ed9a9 AS |
375 | } *discrim_t; |
376 | ||
377 | struct discrim_and_source { | |
378 | discrim_t discrim; | |
379 | struct userNode *source; | |
258d1427 | 380 | struct userNode *destination; |
d76ed9a9 AS |
381 | dict_t dict; |
382 | unsigned int disp_limit; | |
383 | }; | |
384 | ||
258d1427 | 385 | static discrim_t opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[], int allow_channel); |
d76ed9a9 AS |
386 | static unsigned int opserv_discrim_search(discrim_t discrim, discrim_search_func dsf, void *data); |
387 | static int gag_helper_func(struct userNode *match, void *extra); | |
388 | static int ungag_helper_func(struct userNode *match, void *extra); | |
389 | ||
390 | typedef enum { | |
391 | REACT_NOTICE, | |
392 | REACT_KILL, | |
9a75756e | 393 | REACT_SILENT, |
d914d1cb | 394 | REACT_GLINE, |
395 | REACT_SHUN | |
d76ed9a9 AS |
396 | } opserv_alert_reaction; |
397 | ||
398 | struct opserv_user_alert { | |
399 | char *owner; | |
400 | char *text_discrim, *split_discrim; | |
401 | discrim_t discrim; | |
402 | opserv_alert_reaction reaction; | |
403 | }; | |
404 | ||
405 | /* funny type to make it acceptible to dict_set_free_data, far below */ | |
406 | static void | |
407 | opserv_free_user_alert(void *data) | |
408 | { | |
409 | struct opserv_user_alert *alert = data; | |
410 | if (alert->discrim->channel) | |
411 | UnlockChannel(alert->discrim->channel); | |
412 | free(alert->owner); | |
413 | free(alert->text_discrim); | |
414 | free(alert->split_discrim); | |
27eaa617 | 415 | if(alert->discrim->has_regex_nick) |
416 | regfree(&alert->discrim->regex_nick); | |
417 | if(alert->discrim->has_regex_ident) | |
418 | regfree(&alert->discrim->regex_ident); | |
419 | if(alert->discrim->has_regex_host) | |
420 | regfree(&alert->discrim->regex_host); | |
421 | if(alert->discrim->has_regex_info) | |
422 | regfree(&alert->discrim->regex_info); | |
d76ed9a9 AS |
423 | free(alert->discrim->reason); |
424 | free(alert->discrim); | |
425 | free(alert); | |
426 | } | |
427 | ||
428 | #define opserv_debug(format...) do { if (opserv_conf.debug_channel) send_channel_notice(opserv_conf.debug_channel , opserv , ## format); } while (0) | |
429 | #define opserv_alert(format...) do { if (opserv_conf.alert_channel) send_channel_notice(opserv_conf.alert_channel , opserv , ## format); } while (0) | |
430 | ||
431 | /* A lot of these commands are very similar to what ChanServ can do, | |
432 | * but OpServ can do them even on channels that aren't registered. | |
433 | */ | |
434 | ||
435 | static MODCMD_FUNC(cmd_access) | |
436 | { | |
437 | struct handle_info *hi; | |
438 | const char *target; | |
439 | unsigned int res; | |
440 | ||
441 | target = (argc > 1) ? (const char*)argv[1] : user->nick; | |
442 | if (!irccasecmp(target, "*")) { | |
443 | nickserv_show_oper_accounts(user, cmd); | |
444 | return 1; | |
445 | } | |
446 | if (!(hi = modcmd_get_handle_info(user, target))) | |
447 | return 0; | |
258d1427 | 448 | res = (argc > 2) ? oper_try_set_access(user, opserv_service->bot, hi, strtoul(argv[2], NULL, 0)) : 0; |
d76ed9a9 AS |
449 | reply("OSMSG_USER_ACCESS_IS", target, hi->handle, hi->opserv_level); |
450 | return res; | |
451 | } | |
452 | ||
453 | static MODCMD_FUNC(cmd_ban) | |
454 | { | |
455 | struct mod_chanmode change; | |
456 | struct userNode *victim; | |
457 | ||
458 | mod_chanmode_init(&change); | |
459 | change.argc = 1; | |
460 | change.args[0].mode = MODE_BAN; | |
461 | if (is_ircmask(argv[1])) | |
a32da4c7 | 462 | change.args[0].u.hostmask = strdup(argv[1]); |
d76ed9a9 | 463 | else if ((victim = GetUserH(argv[1]))) |
a32da4c7 | 464 | change.args[0].u.hostmask = generate_hostmask(victim, 0); |
d76ed9a9 | 465 | else { |
258d1427 AS |
466 | reply("OSMSG_INVALID_IRCMASK", argv[1]); |
467 | return 0; | |
d76ed9a9 AS |
468 | } |
469 | modcmd_chanmode_announce(&change); | |
a32da4c7 | 470 | reply("OSMSG_ADDED_BAN", change.args[0].u.hostmask, channel->name); |
471 | free((char*)change.args[0].u.hostmask); | |
d76ed9a9 AS |
472 | return 1; |
473 | } | |
474 | ||
475 | static MODCMD_FUNC(cmd_chaninfo) | |
476 | { | |
477 | char buffer[MAXLEN]; | |
478 | const char *fmt; | |
479 | struct banNode *ban; | |
2aef5f4b | 480 | struct exemptNode *exempt; |
d76ed9a9 AS |
481 | struct modeNode *moden; |
482 | unsigned int n; | |
483 | ||
484 | reply("OSMSG_CHANINFO_HEADER", channel->name); | |
485 | fmt = user_find_message(user, "OSMSG_CHANINFO_TIMESTAMP"); | |
486 | strftime(buffer, sizeof(buffer), fmt, gmtime(&channel->timestamp)); | |
487 | send_message_type(4, user, cmd->parent->bot, "%s", buffer); | |
488 | irc_make_chanmode(channel, buffer); | |
489 | if (channel->bad_channel) | |
490 | reply("OSMSG_CHANINFO_MODES_BADWORD", buffer); | |
491 | else | |
492 | reply("OSMSG_CHANINFO_MODES", buffer); | |
493 | if (channel->topic_time) { | |
494 | fmt = user_find_message(user, "OSMSG_CHANINFO_TOPIC"); | |
495 | strftime(buffer, sizeof(buffer), fmt, gmtime(&channel->topic_time)); | |
496 | send_message_type(4, user, cmd->parent->bot, buffer, channel->topic_nick, channel->topic); | |
497 | } else { | |
258d1427 AS |
498 | irc_fetchtopic(cmd->parent->bot, channel->name); |
499 | reply("OSMSG_CHANINFO_TOPIC_UNKNOWN"); | |
d76ed9a9 AS |
500 | } |
501 | if (channel->banlist.used) { | |
258d1427 | 502 | reply("OSMSG_CHANINFO_BAN_COUNT", channel->banlist.used); |
d76ed9a9 | 503 | fmt = user_find_message(user, "OSMSG_CHANINFO_BAN"); |
258d1427 AS |
504 | for (n = 0; n < channel->banlist.used; n++) { |
505 | ban = channel->banlist.list[n]; | |
506 | strftime(buffer, sizeof(buffer), fmt, localtime(&ban->set)); | |
507 | send_message_type(4, user, cmd->parent->bot, buffer, ban->ban, ban->who); | |
508 | } | |
d76ed9a9 | 509 | } |
2aef5f4b | 510 | if (channel->exemptlist.used) { |
511 | reply("OSMSG_CHANINFO_EXEMPT_COUNT", channel->exemptlist.used); | |
512 | fmt = user_find_message(user, "OSMSG_CHANINFO_EXEMPT"); | |
513 | for (n = 0; n < channel->exemptlist.used; n++) { | |
514 | exempt = channel->exemptlist.list[n]; | |
515 | strftime(buffer, sizeof(buffer), fmt, localtime(&exempt->set)); | |
516 | send_message_type(4, user, cmd->parent->bot, buffer, exempt->exempt, exempt->who); | |
517 | } | |
518 | } | |
d76ed9a9 AS |
519 | if ((argc < 2) && (channel->members.used >= 50)) { |
520 | /* early out unless they ask for users */ | |
521 | reply("OSMSG_CHANINFO_MANY_USERS", channel->members.used, argv[0], channel->name); | |
522 | return 1; | |
523 | } | |
524 | reply("OSMSG_CHANINFO_USER_COUNT", channel->members.used); | |
525 | for (n=0; n<channel->members.used; n++) { | |
258d1427 AS |
526 | moden = channel->members.list[n]; |
527 | if (moden->modes & MODE_CHANOP) | |
d76ed9a9 AS |
528 | send_message_type(4, user, cmd->parent->bot, " @%s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); |
529 | } | |
55342ce8 | 530 | for (n=0; n<channel->members.used; n++) { |
531 | moden = channel->members.list[n]; | |
532 | if ((moden->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) == MODE_HALFOP) | |
533 | send_message_type(4, user, cmd->parent->bot, " %s%s (%s@%s)", "%", moden->user->nick, moden->user->ident, moden->user->hostname); | |
534 | } | |
d76ed9a9 | 535 | for (n=0; n<channel->members.used; n++) { |
258d1427 AS |
536 | moden = channel->members.list[n]; |
537 | if ((moden->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) == MODE_VOICE) | |
d76ed9a9 AS |
538 | send_message_type(4, user, cmd->parent->bot, " +%s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); |
539 | } | |
540 | for (n=0; n<channel->members.used; n++) { | |
258d1427 AS |
541 | moden = channel->members.list[n]; |
542 | if ((moden->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) == 0) | |
d76ed9a9 AS |
543 | send_message_type(4, user, cmd->parent->bot, " %s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); |
544 | } | |
545 | return 1; | |
546 | } | |
547 | ||
de9510bc AS |
548 | /* This command has been replaced by 'alert notice channel #foo' */ |
549 | /* | |
d76ed9a9 AS |
550 | static MODCMD_FUNC(cmd_warn) |
551 | { | |
552 | char *reason, *message; | |
553 | ||
554 | if (!IsChannelName(argv[1])) { | |
258d1427 AS |
555 | reply("OSMSG_NEED_CHANNEL", argv[0]); |
556 | return 0; | |
d76ed9a9 AS |
557 | } |
558 | reason = dict_find(opserv_chan_warn, argv[1], NULL); | |
559 | if (reason) { | |
560 | reply("OSMSG_WARN_EXISTS", argv[1]); | |
561 | return 0; | |
562 | } | |
563 | if (argv[2]) | |
564 | reason = strdup(unsplit_string(argv+2, argc-2, NULL)); | |
565 | else | |
566 | reason = strdup("No reason"); | |
567 | dict_insert(opserv_chan_warn, strdup(argv[1]), reason); | |
568 | reply("OSMSG_WARN_ADDED", argv[1], reason); | |
569 | if (dict_find(channels, argv[1], NULL)) { | |
570 | message = alloca(strlen(reason) + strlen(argv[1]) + 55); | |
571 | sprintf(message, "Channel activity warning for channel %s: %s", argv[1], reason); | |
572 | global_message(MESSAGE_RECIPIENT_OPERS, message); | |
573 | } | |
574 | return 1; | |
575 | } | |
576 | ||
577 | static MODCMD_FUNC(cmd_unwarn) | |
578 | { | |
579 | if ((argc < 2) || !IsChannelName(argv[1])) { | |
580 | reply("OSMSG_NEED_CHANNEL", argv[0]); | |
258d1427 | 581 | return 0; |
d76ed9a9 AS |
582 | } |
583 | if (!dict_remove(opserv_chan_warn, argv[1])) { | |
584 | reply("OSMSG_WARN_NOEXIST", argv[1]); | |
585 | return 0; | |
586 | } | |
587 | reply("OSMSG_WARN_DELETED", argv[1]); | |
588 | return 1; | |
589 | } | |
de9510bc | 590 | */ |
d76ed9a9 AS |
591 | |
592 | static MODCMD_FUNC(cmd_clearbans) | |
593 | { | |
594 | struct mod_chanmode *change; | |
595 | unsigned int ii; | |
596 | ||
597 | change = mod_chanmode_alloc(channel->banlist.used); | |
598 | for (ii=0; ii<channel->banlist.used; ii++) { | |
599 | change->args[ii].mode = MODE_REMOVE | MODE_BAN; | |
ec1a68c8 | 600 | change->args[ii].u.hostmask = strdup(channel->banlist.list[ii]->ban); |
d76ed9a9 AS |
601 | } |
602 | modcmd_chanmode_announce(change); | |
ec1a68c8 | 603 | for (ii=0; ii<change->argc; ++ii) |
604 | free((char*)change->args[ii].u.hostmask); | |
d76ed9a9 AS |
605 | mod_chanmode_free(change); |
606 | reply("OSMSG_CLEARBANS_DONE", channel->name); | |
607 | return 1; | |
608 | } | |
609 | ||
610 | static MODCMD_FUNC(cmd_clearmodes) | |
611 | { | |
612 | struct mod_chanmode change; | |
613 | ||
614 | if (!channel->modes) { | |
258d1427 | 615 | reply("OSMSG_NO_CHANNEL_MODES", channel->name); |
d76ed9a9 AS |
616 | return 0; |
617 | } | |
618 | mod_chanmode_init(&change); | |
619 | change.modes_clear = channel->modes; | |
620 | modcmd_chanmode_announce(&change); | |
621 | reply("OSMSG_CLEARMODES_DONE", channel->name); | |
622 | return 1; | |
623 | } | |
624 | ||
625 | static MODCMD_FUNC(cmd_deop) | |
626 | { | |
627 | struct mod_chanmode *change; | |
628 | unsigned int arg, count; | |
629 | ||
630 | change = mod_chanmode_alloc(argc-1); | |
631 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
632 | struct userNode *victim = GetUserH(argv[arg]); | |
633 | struct modeNode *mn; | |
258d1427 | 634 | if (!victim || IsService(victim) |
d76ed9a9 AS |
635 | || !(mn = GetUserMode(channel, victim)) |
636 | || !(mn->modes & MODE_CHANOP)) | |
637 | continue; | |
638 | change->args[count].mode = MODE_REMOVE | MODE_CHANOP; | |
a32da4c7 | 639 | change->args[count++].u.member = mn; |
d76ed9a9 AS |
640 | } |
641 | if (count) { | |
642 | change->argc = count; | |
643 | modcmd_chanmode_announce(change); | |
644 | } | |
645 | mod_chanmode_free(change); | |
646 | reply("OSMSG_DEOP_DONE"); | |
647 | return 1; | |
648 | } | |
649 | ||
55342ce8 | 650 | static MODCMD_FUNC(cmd_dehop) |
651 | { | |
652 | struct mod_chanmode *change; | |
653 | unsigned int arg, count; | |
654 | ||
655 | change = mod_chanmode_alloc(argc-1); | |
656 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
657 | struct userNode *victim = GetUserH(argv[arg]); | |
658 | struct modeNode *mn; | |
659 | if (!victim || IsService(victim) | |
660 | || !(mn = GetUserMode(channel, victim)) | |
661 | || !(mn->modes & MODE_HALFOP)) | |
662 | continue; | |
663 | change->args[count].mode = MODE_REMOVE | MODE_HALFOP; | |
11408ce4 | 664 | change->args[count++].u.member = mn; |
55342ce8 | 665 | } |
666 | if (count) { | |
667 | change->argc = count; | |
668 | modcmd_chanmode_announce(change); | |
669 | } | |
670 | mod_chanmode_free(change); | |
671 | reply("OSMSG_DEHOP_DONE"); | |
672 | return 1; | |
673 | } | |
674 | ||
d76ed9a9 AS |
675 | static MODCMD_FUNC(cmd_deopall) |
676 | { | |
677 | struct mod_chanmode *change; | |
678 | unsigned int ii, count; | |
679 | ||
680 | change = mod_chanmode_alloc(channel->members.used); | |
681 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 AS |
682 | struct modeNode *mn = channel->members.list[ii]; |
683 | if (IsService(mn->user) || !(mn->modes & MODE_CHANOP)) | |
d76ed9a9 AS |
684 | continue; |
685 | change->args[count].mode = MODE_REMOVE | MODE_CHANOP; | |
a32da4c7 | 686 | change->args[count++].u.member = mn; |
d76ed9a9 AS |
687 | } |
688 | if (count) { | |
689 | change->argc = count; | |
690 | modcmd_chanmode_announce(change); | |
691 | } | |
692 | mod_chanmode_free(change); | |
693 | reply("OSMSG_DEOPALL_DONE", channel->name); | |
694 | return 1; | |
695 | } | |
696 | ||
55342ce8 | 697 | static MODCMD_FUNC(cmd_dehopall) |
698 | { | |
699 | struct mod_chanmode *change; | |
700 | unsigned int ii, count; | |
701 | ||
702 | change = mod_chanmode_alloc(channel->members.used); | |
703 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
704 | struct modeNode *mn = channel->members.list[ii]; | |
705 | if (IsService(mn->user) || !(mn->modes & MODE_HALFOP)) | |
706 | continue; | |
707 | change->args[count].mode = MODE_REMOVE | MODE_HALFOP; | |
11408ce4 | 708 | change->args[count++].u.member = mn; |
55342ce8 | 709 | } |
710 | if (count) { | |
711 | change->argc = count; | |
712 | modcmd_chanmode_announce(change); | |
713 | } | |
714 | mod_chanmode_free(change); | |
715 | reply("OSMSG_DEHOPALL_DONE", channel->name); | |
716 | return 1; | |
717 | } | |
718 | ||
d76ed9a9 AS |
719 | static MODCMD_FUNC(cmd_rehash) |
720 | { | |
721 | extern char *services_config; | |
722 | ||
723 | if (conf_read(services_config)) | |
258d1427 | 724 | reply("OSMSG_REHASH_COMPLETE"); |
d76ed9a9 | 725 | else |
258d1427 | 726 | reply("OSMSG_REHASH_FAILED"); |
d76ed9a9 AS |
727 | return 1; |
728 | } | |
729 | ||
730 | static MODCMD_FUNC(cmd_reopen) | |
731 | { | |
732 | log_reopen(); | |
733 | reply("OSMSG_REOPEN_COMPLETE"); | |
734 | return 1; | |
735 | } | |
736 | ||
737 | static MODCMD_FUNC(cmd_reconnect) | |
738 | { | |
739 | reply("OSMSG_RECONNECTING"); | |
740 | irc_squit(self, "Reconnecting.", NULL); | |
741 | return 1; | |
742 | } | |
743 | ||
744 | static MODCMD_FUNC(cmd_jupe) | |
745 | { | |
746 | extern int force_n2k; | |
747 | struct server *newsrv; | |
748 | unsigned int num; | |
749 | char numeric[COMBO_NUMERIC_LEN+1], srvdesc[SERVERDESCRIPTMAX+1]; | |
750 | ||
751 | num = atoi(argv[2]); | |
752 | if ((num < 64) && !force_n2k) { | |
753 | inttobase64(numeric, num, 1); | |
754 | inttobase64(numeric+1, 64*64-1, 2); | |
755 | } else { | |
756 | inttobase64(numeric, num, 2); | |
757 | inttobase64(numeric+2, 64*64*64-1, 3); | |
758 | } | |
759 | #ifdef WITH_PROTOCOL_P10 | |
760 | if (GetServerN(numeric)) { | |
761 | reply("OSMSG_NUMERIC_COLLIDE", num, numeric); | |
762 | return 0; | |
763 | } | |
764 | #endif | |
765 | if (GetServerH(argv[1])) { | |
766 | reply("OSMSG_NAME_COLLIDE"); | |
767 | return 0; | |
768 | } | |
769 | snprintf(srvdesc, sizeof(srvdesc), "JUPE %s", unsplit_string(argv+3, argc-3, NULL)); | |
770 | newsrv = AddServer(self, argv[1], 1, now, now, numeric, srvdesc); | |
771 | if (!newsrv) { | |
772 | reply("OSMSG_SRV_CREATE_FAILED"); | |
773 | return 0; | |
774 | } | |
775 | irc_server(newsrv); | |
776 | reply("OSMSG_SERVER_JUPED", argv[1]); | |
777 | return 1; | |
778 | } | |
779 | ||
780 | static MODCMD_FUNC(cmd_unjupe) | |
781 | { | |
782 | struct server *srv; | |
783 | char *reason; | |
784 | ||
785 | srv = GetServerH(argv[1]); | |
786 | if (!srv) { | |
787 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
788 | return 0; | |
789 | } | |
790 | if (strncmp(srv->description, "JUPE", 4)) { | |
791 | reply("OSMSG_SERVER_NOT_JUPE"); | |
792 | return 0; | |
793 | } | |
794 | reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : "Unjuping server"; | |
795 | DelServer(srv, 1, reason); | |
796 | reply("OSMSG_SERVER_UNJUPED"); | |
797 | return 1; | |
798 | } | |
799 | ||
800 | static MODCMD_FUNC(cmd_jump) | |
801 | { | |
802 | extern struct cManagerNode cManager; | |
803 | void uplink_select(char *name); | |
804 | struct uplinkNode *uplink_find(char *name); | |
805 | struct uplinkNode *uplink; | |
806 | char *target; | |
807 | ||
808 | target = unsplit_string(argv+1, argc-1, NULL); | |
809 | ||
810 | if (!strcmp(cManager.uplink->name, target)) { | |
258d1427 AS |
811 | reply("OSMSG_CURRENT_UPLINK", cManager.uplink->name); |
812 | return 0; | |
d76ed9a9 AS |
813 | } |
814 | ||
815 | uplink = uplink_find(target); | |
816 | if (!uplink) { | |
258d1427 AS |
817 | reply("OSMSG_INVALID_UPLINK", target); |
818 | return 0; | |
d76ed9a9 AS |
819 | } |
820 | if (uplink->flags & UPLINK_UNAVAILABLE) { | |
821 | reply("OSMSG_UPLINK_DISABLED", uplink->name); | |
822 | return 0; | |
823 | } | |
824 | ||
825 | reply("OSMSG_UPLINK_CONNECTING", uplink->name, uplink->host, uplink->port); | |
826 | uplink_select(target); | |
827 | irc_squit(self, "Reconnecting.", NULL); | |
828 | return 1; | |
829 | } | |
830 | ||
831 | static MODCMD_FUNC(cmd_die) | |
832 | { | |
833 | char *reason, *text; | |
834 | ||
835 | text = unsplit_string(argv+1, argc-1, NULL); | |
836 | reason = alloca(strlen(text) + strlen(user->nick) + 20); | |
837 | sprintf(reason, "Disconnected by %s [%s]", user->nick, text); | |
838 | irc_squit(self, reason, text); | |
839 | quit_services = 1; | |
840 | return 1; | |
841 | } | |
842 | ||
843 | static MODCMD_FUNC(cmd_restart) | |
844 | { | |
845 | extern int services_argc; | |
846 | extern char **services_argv; | |
847 | char **restart_argv, *reason, *text; | |
848 | ||
849 | text = unsplit_string(argv+1, argc-1, NULL); | |
850 | reason = alloca(strlen(text) + strlen(user->nick) + 17); | |
851 | sprintf(reason, "Restarted by %s [%s]", user->nick, text); | |
852 | irc_squit(self, reason, text); | |
853 | ||
854 | /* Append a NULL to the end of argv[]. */ | |
855 | restart_argv = (char **)alloca((services_argc + 1) * sizeof(char *)); | |
856 | memcpy(restart_argv, services_argv, services_argc * sizeof(char *)); | |
857 | restart_argv[services_argc] = NULL; | |
858 | ||
859 | call_exit_funcs(); | |
860 | ||
861 | /* Don't blink. */ | |
862 | execv(services_argv[0], restart_argv); | |
863 | ||
864 | /* If we're still here, that means something went wrong. Reconnect. */ | |
865 | return 1; | |
866 | } | |
867 | ||
868 | static struct gline * | |
9a75756e | 869 | opserv_block(struct userNode *target, char *src_handle, char *reason, unsigned long duration, int silent) |
d76ed9a9 AS |
870 | { |
871 | char *mask; | |
872 | mask = alloca(MAXLEN); | |
873 | snprintf(mask, MAXLEN, "*@%s", target->hostname); | |
874 | if (!reason) { | |
875 | reason = alloca(MAXLEN); | |
876 | snprintf(reason, MAXLEN, "G-line requested by %s.", src_handle); | |
877 | } | |
878 | if (!duration) duration = opserv_conf.block_gline_duration; | |
9a75756e | 879 | return gline_add(src_handle, mask, duration, reason, now, 1, silent ? 1 : 0); |
d76ed9a9 AS |
880 | } |
881 | ||
882 | static MODCMD_FUNC(cmd_block) | |
883 | { | |
884 | struct userNode *target; | |
885 | struct gline *gline; | |
886 | char *reason; | |
887 | ||
888 | target = GetUserH(argv[1]); | |
889 | if (!target) { | |
258d1427 AS |
890 | reply("MSG_NICK_UNKNOWN", argv[1]); |
891 | return 0; | |
d76ed9a9 AS |
892 | } |
893 | if (IsService(target)) { | |
258d1427 AS |
894 | reply("MSG_SERVICE_IMMUNE", target->nick); |
895 | return 0; | |
d76ed9a9 AS |
896 | } |
897 | reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : NULL; | |
9a75756e | 898 | gline = opserv_block(target, user->handle_info->handle, reason, 0, 0); |
d76ed9a9 AS |
899 | reply("OSMSG_GLINE_ISSUED", gline->target); |
900 | return 1; | |
901 | } | |
902 | ||
903 | static MODCMD_FUNC(cmd_gline) | |
904 | { | |
905 | unsigned long duration; | |
906 | char *reason; | |
907 | struct gline *gline; | |
908 | ||
909 | reason = unsplit_string(argv+3, argc-3, NULL); | |
910 | if (!is_gline(argv[1]) && !IsChannelName(argv[1]) && (argv[1][0] != '&')) { | |
258d1427 AS |
911 | reply("MSG_INVALID_GLINE", argv[1]); |
912 | return 0; | |
d76ed9a9 AS |
913 | } |
914 | if (!argv[1][strspn(argv[1], "#&*?@.")] && (strlen(argv[1]) < 10)) { | |
915 | reply("OSMSG_STUPID_GLINE", argv[1]); | |
916 | return 0; | |
917 | } | |
918 | duration = ParseInterval(argv[2]); | |
919 | if (!duration) { | |
920 | reply("MSG_INVALID_DURATION", argv[2]); | |
921 | return 0; | |
922 | } | |
9a75756e | 923 | gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, 1, 0); |
d76ed9a9 AS |
924 | reply("OSMSG_GLINE_ISSUED", gline->target); |
925 | return 1; | |
926 | } | |
927 | ||
928 | static MODCMD_FUNC(cmd_ungline) | |
929 | { | |
930 | if (gline_remove(argv[1], 1)) | |
931 | reply("OSMSG_GLINE_REMOVED", argv[1]); | |
932 | else | |
933 | reply("OSMSG_GLINE_FORCE_REMOVED", argv[1]); | |
934 | return 1; | |
935 | } | |
936 | ||
937 | static MODCMD_FUNC(cmd_refreshg) | |
938 | { | |
939 | if (argc > 1) { | |
940 | unsigned int count; | |
941 | dict_iterator_t it; | |
942 | struct server *srv; | |
943 | ||
944 | for (it=dict_first(servers), count=0; it; it=iter_next(it)) { | |
945 | srv = iter_data(it); | |
946 | if ((srv == self) || !match_ircglob(srv->name, argv[1])) | |
947 | continue; | |
948 | gline_refresh_server(srv); | |
949 | reply("OSMSG_GLINES_ONE_REFRESHED", srv->name); | |
950 | count++; | |
951 | } | |
952 | if (!count) { | |
953 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
954 | return 0; | |
955 | } | |
956 | } else { | |
957 | gline_refresh_all(); | |
958 | reply("OSMSG_GLINES_REFRESHED"); | |
959 | } | |
960 | return 1; | |
961 | } | |
962 | ||
d914d1cb | 963 | static struct shun * |
964 | opserv_shun(struct userNode *target, char *src_handle, char *reason, unsigned long duration) | |
965 | { | |
966 | char *mask; | |
967 | mask = alloca(MAXLEN); | |
968 | snprintf(mask, MAXLEN, "*@%s", target->hostname); | |
969 | if (!reason) { | |
970 | reason = alloca(MAXLEN); | |
971 | snprintf(reason, MAXLEN, "Shun requested by %s.", src_handle); | |
972 | } | |
973 | if (!duration) duration = opserv_conf.block_shun_duration; | |
974 | return shun_add(src_handle, mask, duration, reason, now, 1); | |
975 | } | |
976 | ||
977 | static MODCMD_FUNC(cmd_sblock) | |
978 | { | |
979 | struct userNode *target; | |
980 | struct shun *shun; | |
981 | char *reason; | |
982 | ||
983 | target = GetUserH(argv[1]); | |
984 | if (!target) { | |
985 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
986 | return 0; | |
987 | } | |
988 | if (IsService(target)) { | |
989 | reply("MSG_SERVICE_IMMUNE", target->nick); | |
990 | return 0; | |
991 | } | |
992 | reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : NULL; | |
993 | shun = opserv_shun(target, user->handle_info->handle, reason, 0); | |
994 | reply("OSMSG_SHUN_ISSUED", shun->target); | |
995 | return 1; | |
996 | } | |
997 | ||
998 | static MODCMD_FUNC(cmd_shun) | |
999 | { | |
1000 | unsigned long duration; | |
1001 | char *reason; | |
1002 | struct shun *shun; | |
1003 | ||
1004 | reason = unsplit_string(argv+3, argc-3, NULL); | |
1005 | if (!is_shun(argv[1]) && !IsChannelName(argv[1]) && (argv[1][0] != '&')) { | |
1006 | reply("MSG_INVALID_SHUN", argv[1]); | |
1007 | return 0; | |
1008 | } | |
1009 | if (!argv[1][strspn(argv[1], "#&*?@.")] && (strlen(argv[1]) < 10)) { | |
1010 | reply("OSMSG_STUPID_SHUN", argv[1]); | |
1011 | return 0; | |
1012 | } | |
1013 | duration = ParseInterval(argv[2]); | |
1014 | if (!duration) { | |
1015 | reply("MSG_INVALID_DURATION", argv[2]); | |
1016 | return 0; | |
1017 | } | |
1018 | shun = shun_add(user->handle_info->handle, argv[1], duration, reason, now, 1); | |
1019 | reply("OSMSG_SHUN_ISSUED", shun->target); | |
1020 | return 1; | |
1021 | } | |
1022 | ||
1023 | static MODCMD_FUNC(cmd_unshun) | |
1024 | { | |
1025 | if (shun_remove(argv[1], 1)) | |
1026 | reply("OSMSG_SHUN_REMOVED", argv[1]); | |
1027 | else | |
1028 | reply("OSMSG_SHUN_FORCE_REMOVED", argv[1]); | |
1029 | return 1; | |
1030 | } | |
1031 | ||
1032 | static MODCMD_FUNC(cmd_refreshs) | |
1033 | { | |
1034 | if (argc > 1) { | |
1035 | unsigned int count; | |
1036 | dict_iterator_t it; | |
1037 | struct server *srv; | |
1038 | ||
1039 | for (it=dict_first(servers), count=0; it; it=iter_next(it)) { | |
1040 | srv = iter_data(it); | |
1041 | if ((srv == self) || !match_ircglob(srv->name, argv[1])) | |
1042 | continue; | |
1043 | shun_refresh_server(srv); | |
1044 | reply("OSMSG_SHUNS_ONE_REFRESHED", srv->name); | |
1045 | count++; | |
1046 | } | |
1047 | if (!count) { | |
1048 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
1049 | return 0; | |
1050 | } | |
1051 | } else { | |
1052 | shun_refresh_all(); | |
1053 | reply("OSMSG_SHUNS_REFRESHED"); | |
1054 | } | |
1055 | return 1; | |
1056 | } | |
1057 | ||
d76ed9a9 AS |
1058 | static void |
1059 | opserv_ison(struct userNode *tell, struct userNode *target, const char *message) | |
1060 | { | |
1061 | struct modeNode *mn; | |
1062 | unsigned int count, here_len, n, maxlen; | |
1063 | char buff[MAXLEN]; | |
1064 | ||
1065 | maxlen = tell->handle_info ? tell->handle_info->screen_width : 0; | |
1066 | if (!maxlen) | |
1067 | maxlen = MAX_LINE_SIZE; | |
1068 | for (n=count=0; n<target->channels.used; n++) { | |
258d1427 AS |
1069 | mn = target->channels.list[n]; |
1070 | here_len = strlen(mn->channel->name); | |
1071 | if ((count + here_len + 4) > maxlen) { | |
1072 | buff[count] = 0; | |
d76ed9a9 | 1073 | send_message(tell, opserv, message, buff); |
258d1427 AS |
1074 | count = 0; |
1075 | } | |
1076 | if (mn->modes & MODE_CHANOP) | |
d76ed9a9 | 1077 | buff[count++] = '@'; |
55342ce8 | 1078 | if (mn->modes & MODE_HALFOP) |
1079 | buff[count++] = '%'; | |
258d1427 | 1080 | if (mn->modes & MODE_VOICE) |
d76ed9a9 | 1081 | buff[count++] = '+'; |
258d1427 AS |
1082 | memcpy(buff+count, mn->channel->name, here_len); |
1083 | count += here_len; | |
1084 | buff[count++] = ' '; | |
d76ed9a9 AS |
1085 | } |
1086 | if (count) { | |
258d1427 AS |
1087 | buff[count] = 0; |
1088 | send_message(tell, opserv, message, buff); | |
d76ed9a9 AS |
1089 | } |
1090 | } | |
1091 | ||
1092 | static MODCMD_FUNC(cmd_inviteme) | |
1093 | { | |
1094 | struct userNode *target; | |
1095 | ||
1096 | if (argc < 2) { | |
258d1427 | 1097 | target = user; |
d76ed9a9 | 1098 | } else { |
258d1427 AS |
1099 | target = GetUserH(argv[1]); |
1100 | if (!target) { | |
1101 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1102 | return 0; | |
1103 | } | |
d76ed9a9 AS |
1104 | } |
1105 | if (opserv_conf.debug_channel == NULL) { | |
258d1427 AS |
1106 | reply("OSMSG_NO_DEBUG_CHANNEL"); |
1107 | return 0; | |
d76ed9a9 AS |
1108 | } |
1109 | if (GetUserMode(opserv_conf.debug_channel, user)) { | |
a32da4c7 | 1110 | reply("OSMSG_ALREADY_THERE", opserv_conf.debug_channel->name); |
d76ed9a9 AS |
1111 | return 0; |
1112 | } | |
1113 | irc_invite(cmd->parent->bot, target, opserv_conf.debug_channel); | |
1114 | if (target != user) | |
258d1427 | 1115 | reply("OSMSG_INVITE_DONE", target->nick, opserv_conf.debug_channel->name); |
d76ed9a9 AS |
1116 | return 1; |
1117 | } | |
1118 | ||
1119 | static MODCMD_FUNC(cmd_invite) | |
1120 | { | |
1121 | if (GetUserMode(channel, user)) { | |
1122 | reply("OSMSG_ALREADY_THERE", channel->name); | |
1123 | return 0; | |
1124 | } | |
1125 | irc_invite(cmd->parent->bot, user, channel); | |
1126 | return 1; | |
1127 | } | |
1128 | ||
1129 | static MODCMD_FUNC(cmd_join) | |
1130 | { | |
1131 | struct userNode *bot = cmd->parent->bot; | |
1132 | ||
1133 | if (!IsChannelName(argv[1])) { | |
1134 | reply("MSG_NOT_CHANNEL_NAME"); | |
1135 | return 0; | |
1136 | } else if (!(channel = GetChannel(argv[1]))) { | |
2aef5f4b | 1137 | channel = AddChannel(argv[1], now, NULL, NULL, NULL); |
d76ed9a9 AS |
1138 | AddChannelUser(bot, channel)->modes |= MODE_CHANOP; |
1139 | } else if (GetUserMode(channel, bot)) { | |
1140 | reply("OSMSG_ALREADY_JOINED", channel->name); | |
1141 | return 0; | |
1142 | } else { | |
1143 | struct mod_chanmode change; | |
1144 | mod_chanmode_init(&change); | |
1145 | change.argc = 1; | |
1146 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 1147 | change.args[0].u.member = AddChannelUser(bot, channel); |
d76ed9a9 AS |
1148 | modcmd_chanmode_announce(&change); |
1149 | } | |
1150 | irc_fetchtopic(bot, channel->name); | |
1151 | reply("OSMSG_JOIN_DONE", channel->name); | |
1152 | return 1; | |
1153 | } | |
1154 | ||
1155 | static MODCMD_FUNC(cmd_kick) | |
1156 | { | |
1157 | struct userNode *target; | |
1158 | char *reason; | |
1159 | ||
1160 | if (argc < 3) { | |
258d1427 AS |
1161 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1162 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1163 | } else { |
258d1427 | 1164 | reason = unsplit_string(argv+2, argc-2, NULL); |
d76ed9a9 AS |
1165 | } |
1166 | target = GetUserH(argv[1]); | |
1167 | if (!target) { | |
258d1427 AS |
1168 | reply("MSG_NICK_UNKNOWN", argv[1]); |
1169 | return 0; | |
d76ed9a9 AS |
1170 | } |
1171 | if (!GetUserMode(channel, target)) { | |
258d1427 AS |
1172 | reply("OSMSG_NOT_ON_CHANNEL", target->nick, channel->name); |
1173 | return 0; | |
d76ed9a9 AS |
1174 | } |
1175 | KickChannelUser(target, channel, cmd->parent->bot, reason); | |
1176 | return 1; | |
1177 | } | |
1178 | ||
1179 | static MODCMD_FUNC(cmd_kickall) | |
1180 | { | |
1181 | unsigned int limit, n, inchan; | |
1182 | struct modeNode *mn; | |
1183 | char *reason; | |
1184 | struct userNode *bot = cmd->parent->bot; | |
1185 | ||
1186 | /* ircu doesn't let servers KICK users, so if OpServ's not in the | |
1187 | * channel, we have to join it in temporarily. */ | |
1188 | if (!(inchan = GetUserMode(channel, bot) ? 1 : 0)) { | |
1189 | struct mod_chanmode change; | |
1190 | mod_chanmode_init(&change); | |
1191 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 1192 | change.args[0].u.member = AddChannelUser(bot, channel); |
d76ed9a9 AS |
1193 | modcmd_chanmode_announce(&change); |
1194 | } | |
1195 | if (argc < 2) { | |
258d1427 AS |
1196 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1197 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1198 | } else { |
258d1427 | 1199 | reason = unsplit_string(argv+1, argc-1, NULL); |
d76ed9a9 AS |
1200 | } |
1201 | limit = user->handle_info->opserv_level; | |
1202 | for (n=channel->members.used; n>0;) { | |
258d1427 AS |
1203 | mn = channel->members.list[--n]; |
1204 | if (IsService(mn->user) | |
1205 | || (mn->user->handle_info | |
1206 | && (mn->user->handle_info->opserv_level >= limit))) { | |
1207 | continue; | |
1208 | } | |
1209 | KickChannelUser(mn->user, channel, bot, reason); | |
d76ed9a9 AS |
1210 | } |
1211 | if (!inchan) | |
1212 | DelChannelUser(bot, channel, "My work here is done", 0); | |
1213 | reply("OSMSG_KICKALL_DONE", channel->name); | |
1214 | return 1; | |
1215 | } | |
1216 | ||
1217 | static MODCMD_FUNC(cmd_kickban) | |
1218 | { | |
1219 | struct mod_chanmode change; | |
1220 | struct userNode *target; | |
1221 | char *reason; | |
1222 | char *mask; | |
1223 | ||
1224 | if (argc == 2) { | |
258d1427 AS |
1225 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1226 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1227 | } else { |
258d1427 | 1228 | reason = unsplit_string(argv+2, argc-2, NULL); |
d76ed9a9 AS |
1229 | } |
1230 | target = GetUserH(argv[1]); | |
1231 | if (!target) { | |
258d1427 AS |
1232 | reply("MSG_NICK_UNKNOWN", argv[1]); |
1233 | return 0; | |
d76ed9a9 AS |
1234 | } |
1235 | if (!GetUserMode(channel, target)) { | |
258d1427 AS |
1236 | reply("OSMSG_NOT_ON_CHANNEL", target->nick, channel->name); |
1237 | return 0; | |
d76ed9a9 AS |
1238 | } |
1239 | mod_chanmode_init(&change); | |
1240 | change.argc = 1; | |
1241 | change.args[0].mode = MODE_BAN; | |
a32da4c7 | 1242 | change.args[0].u.hostmask = mask = generate_hostmask(target, 0); |
d76ed9a9 AS |
1243 | modcmd_chanmode_announce(&change); |
1244 | KickChannelUser(target, channel, cmd->parent->bot, reason); | |
1245 | free(mask); | |
1246 | return 1; | |
1247 | } | |
1248 | ||
1249 | static MODCMD_FUNC(cmd_kickbanall) | |
1250 | { | |
1251 | struct modeNode *mn; | |
1252 | struct userNode *bot = cmd->parent->bot; | |
1253 | struct mod_chanmode *change; | |
1254 | char *reason; | |
1255 | unsigned int limit, n, inchan; | |
1256 | ||
1257 | /* ircu doesn't let servers KICK users, so if OpServ's not in the | |
1258 | * channel, we have to join it in temporarily. */ | |
1259 | if (!(inchan = GetUserMode(channel, bot) ? 1 : 0)) { | |
1260 | change = mod_chanmode_alloc(2); | |
1261 | change->args[0].mode = MODE_CHANOP; | |
a32da4c7 | 1262 | change->args[0].u.member = AddChannelUser(bot, channel); |
d76ed9a9 | 1263 | change->args[1].mode = MODE_BAN; |
a32da4c7 | 1264 | change->args[1].u.hostmask = "*!*@*"; |
d76ed9a9 AS |
1265 | } else { |
1266 | change = mod_chanmode_alloc(1); | |
1267 | change->args[0].mode = MODE_BAN; | |
a32da4c7 | 1268 | change->args[0].u.hostmask = "*!*@*"; |
d76ed9a9 AS |
1269 | } |
1270 | modcmd_chanmode_announce(change); | |
a32da4c7 | 1271 | mod_chanmode_free(change); |
d76ed9a9 | 1272 | if (argc < 2) { |
258d1427 AS |
1273 | reason = alloca(strlen(OSMSG_KICK_REQUESTED)+strlen(user->nick)+1); |
1274 | sprintf(reason, OSMSG_KICK_REQUESTED, user->nick); | |
d76ed9a9 | 1275 | } else { |
258d1427 | 1276 | reason = unsplit_string(argv+1, argc-1, NULL); |
d76ed9a9 AS |
1277 | } |
1278 | /* now kick them */ | |
1279 | limit = user->handle_info->opserv_level; | |
1280 | for (n=channel->members.used; n>0; ) { | |
258d1427 AS |
1281 | mn = channel->members.list[--n]; |
1282 | if (IsService(mn->user) | |
1283 | || (mn->user->handle_info | |
1284 | && (mn->user->handle_info->opserv_level >= limit))) { | |
1285 | continue; | |
1286 | } | |
1287 | KickChannelUser(mn->user, channel, bot, reason); | |
d76ed9a9 AS |
1288 | } |
1289 | if (!inchan) | |
1290 | DelChannelUser(bot, channel, "My work here is done", 0); | |
1291 | reply("OSMSG_KICKALL_DONE", channel->name); | |
1292 | return 1; | |
1293 | } | |
1294 | ||
1295 | static MODCMD_FUNC(cmd_part) | |
1296 | { | |
1297 | char *reason; | |
1298 | ||
1299 | if (!IsChannelName(argv[1])) { | |
1300 | reply("MSG_NOT_CHANNEL_NAME"); | |
1301 | return 0; | |
1302 | } | |
1303 | if ((channel = GetChannel(argv[1]))) { | |
1304 | if (!GetUserMode(channel, cmd->parent->bot)) { | |
1305 | reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); | |
1306 | return 0; | |
1307 | } | |
1308 | reason = (argc < 3) ? "Leaving." : unsplit_string(argv+2, argc-2, NULL); | |
1309 | reply("OSMSG_LEAVING", channel->name); | |
1310 | DelChannelUser(cmd->parent->bot, channel, reason, 0); | |
1311 | } | |
1312 | return 1; | |
1313 | } | |
1314 | ||
1315 | static MODCMD_FUNC(cmd_mode) | |
1316 | { | |
1317 | if (!modcmd_chanmode(argv+1, argc-1, MCP_ALLOW_OVB|MCP_KEY_FREE|MC_ANNOUNCE)) { | |
1318 | reply("MSG_INVALID_MODES", unsplit_string(argv+1, argc-1, NULL)); | |
1319 | return 0; | |
1320 | } | |
1321 | reply("OSMSG_MODE_SET", channel->name); | |
1322 | return 1; | |
1323 | } | |
1324 | ||
1325 | static MODCMD_FUNC(cmd_op) | |
1326 | { | |
1327 | struct mod_chanmode *change; | |
1328 | unsigned int arg, count; | |
1329 | ||
1330 | change = mod_chanmode_alloc(argc-1); | |
1331 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
1332 | struct userNode *victim; | |
1333 | struct modeNode *mn; | |
1334 | if (!(victim = GetUserH(argv[arg]))) | |
1335 | continue; | |
1336 | if (!(mn = GetUserMode(channel, victim))) | |
1337 | continue; | |
1338 | if (mn->modes & MODE_CHANOP) | |
1339 | continue; | |
1340 | change->args[count].mode = MODE_CHANOP; | |
a32da4c7 | 1341 | change->args[count++].u.member = mn; |
d76ed9a9 AS |
1342 | } |
1343 | if (count) { | |
1344 | change->argc = count; | |
1345 | modcmd_chanmode_announce(change); | |
1346 | } | |
1347 | mod_chanmode_free(change); | |
1348 | reply("OSMSG_OP_DONE"); | |
1349 | return 1; | |
1350 | } | |
1351 | ||
55342ce8 | 1352 | static MODCMD_FUNC(cmd_hop) |
1353 | { | |
1354 | struct mod_chanmode *change; | |
1355 | unsigned int arg, count; | |
1356 | ||
1357 | change = mod_chanmode_alloc(argc-1); | |
1358 | for (arg = 1, count = 0; arg < argc; ++arg) { | |
1359 | struct userNode *victim; | |
1360 | struct modeNode *mn; | |
1361 | if (!(victim = GetUserH(argv[arg]))) | |
1362 | continue; | |
1363 | if (!(mn = GetUserMode(channel, victim))) | |
1364 | continue; | |
1365 | if (mn->modes & MODE_HALFOP) | |
1366 | continue; | |
1367 | change->args[count].mode = MODE_HALFOP; | |
11408ce4 | 1368 | change->args[count++].u.member = mn; |
55342ce8 | 1369 | } |
1370 | if (count) { | |
1371 | change->argc = count; | |
1372 | modcmd_chanmode_announce(change); | |
1373 | } | |
1374 | mod_chanmode_free(change); | |
1375 | reply("OSMSG_HOP_DONE"); | |
1376 | return 1; | |
1377 | } | |
1378 | ||
d76ed9a9 AS |
1379 | static MODCMD_FUNC(cmd_opall) |
1380 | { | |
1381 | struct mod_chanmode *change; | |
1382 | unsigned int ii, count; | |
1383 | ||
1384 | change = mod_chanmode_alloc(channel->members.used); | |
1385 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 AS |
1386 | struct modeNode *mn = channel->members.list[ii]; |
1387 | if (mn->modes & MODE_CHANOP) | |
d76ed9a9 AS |
1388 | continue; |
1389 | change->args[count].mode = MODE_CHANOP; | |
a32da4c7 | 1390 | change->args[count++].u.member = mn; |
d76ed9a9 AS |
1391 | } |
1392 | if (count) { | |
1393 | change->argc = count; | |
258d1427 | 1394 | modcmd_chanmode_announce(change); |
d76ed9a9 AS |
1395 | } |
1396 | mod_chanmode_free(change); | |
1397 | reply("OSMSG_OPALL_DONE", channel->name); | |
1398 | return 1; | |
1399 | } | |
1400 | ||
55342ce8 | 1401 | static MODCMD_FUNC(cmd_hopall) |
1402 | { | |
1403 | struct mod_chanmode *change; | |
1404 | unsigned int ii, count; | |
1405 | ||
1406 | change = mod_chanmode_alloc(channel->members.used); | |
1407 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
1408 | struct modeNode *mn = channel->members.list[ii]; | |
1409 | if (mn->modes & MODE_HALFOP) | |
1410 | continue; | |
1411 | change->args[count].mode = MODE_HALFOP; | |
11408ce4 | 1412 | change->args[count++].u.member = mn; |
55342ce8 | 1413 | } |
1414 | if (count) { | |
1415 | change->argc = count; | |
1416 | modcmd_chanmode_announce(change); | |
1417 | } | |
1418 | mod_chanmode_free(change); | |
1419 | reply("OSMSG_HOPALL_DONE", channel->name); | |
1420 | return 1; | |
1421 | } | |
1422 | ||
d76ed9a9 AS |
1423 | static MODCMD_FUNC(cmd_whois) |
1424 | { | |
1425 | struct userNode *target; | |
1426 | char buffer[128]; | |
1427 | int bpos, herelen; | |
1428 | ||
1429 | #ifdef WITH_PROTOCOL_P10 | |
1430 | if (argv[1][0] == '*') | |
1431 | target = GetUserN(argv[1]+1); | |
1432 | else | |
d76ed9a9 | 1433 | #endif |
1117fc5a | 1434 | target = GetUserH(argv[1]); |
d76ed9a9 AS |
1435 | if (!target) { |
1436 | reply("MSG_NICK_UNKNOWN", argv[1]); | |
1437 | return 0; | |
1438 | } | |
1439 | reply("OSMSG_WHOIS_NICK", target->nick); | |
1440 | reply("OSMSG_WHOIS_HOST", target->ident, target->hostname); | |
1441 | if (IsFakeHost(target)) | |
1442 | reply("OSMSG_WHOIS_FAKEHOST", target->fakehost); | |
1443 | reply("OSMSG_WHOIS_IP", inet_ntoa(target->ip)); | |
1444 | if (target->modes) { | |
258d1427 | 1445 | bpos = 0; |
d76ed9a9 | 1446 | #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen) |
258d1427 AS |
1447 | if (IsInvisible(target)) buffer[bpos++] = 'i'; |
1448 | if (IsWallOp(target)) buffer[bpos++] = 'w'; | |
1449 | if (IsOper(target)) buffer[bpos++] = 'o'; | |
1450 | if (IsGlobal(target)) buffer[bpos++] = 'g'; | |
1451 | if (IsServNotice(target)) buffer[bpos++] = 's'; | |
1452 | ||
1453 | // sethost - reed/apples | |
1454 | // if (IsHelperIrcu(target)) buffer[bpos++] = 'h'; | |
1455 | if (IsSetHost(target)) buffer[bpos++] = 'h'; | |
1456 | ||
1457 | if (IsService(target)) buffer[bpos++] = 'k'; | |
1458 | if (IsDeaf(target)) buffer[bpos++] = 'd'; | |
b2cf3d66 | 1459 | if (target->handle_info) buffer[bpos++] = 'r'; |
d76ed9a9 AS |
1460 | if (IsHiddenHost(target)) buffer[bpos++] = 'x'; |
1461 | if (IsGagged(target)) buffer_cat(" (gagged)"); | |
258d1427 AS |
1462 | if (IsRegistering(target)) buffer_cat(" (registered account)"); |
1463 | buffer[bpos] = 0; | |
1464 | if (bpos > 0) | |
d76ed9a9 AS |
1465 | reply("OSMSG_WHOIS_MODES", buffer); |
1466 | } | |
1467 | reply("OSMSG_WHOIS_INFO", target->info); | |
1468 | #ifdef WITH_PROTOCOL_P10 | |
1469 | reply("OSMSG_WHOIS_NUMERIC", target->numeric); | |
1470 | #endif | |
1471 | reply("OSMSG_WHOIS_SERVER", target->uplink->name); | |
1472 | reply("OSMSG_WHOIS_ACCOUNT", (target->handle_info ? target->handle_info->handle : "Not authenticated")); | |
1473 | intervalString(buffer, now - target->timestamp, user->handle_info); | |
1474 | reply("OSMSG_WHOIS_NICK_AGE", buffer); | |
1475 | if (target->channels.used <= MAX_CHANNELS_WHOIS) | |
258d1427 | 1476 | opserv_ison(user, target, "OSMSG_WHOIS_CHANNELS"); |
d76ed9a9 | 1477 | else |
258d1427 | 1478 | reply("OSMSG_WHOIS_HIDECHANS"); |
d76ed9a9 AS |
1479 | return 1; |
1480 | } | |
1481 | ||
1482 | static MODCMD_FUNC(cmd_unban) | |
1483 | { | |
1484 | struct mod_chanmode change; | |
1485 | mod_chanmode_init(&change); | |
1486 | change.argc = 1; | |
1487 | change.args[0].mode = MODE_REMOVE | MODE_BAN; | |
a32da4c7 | 1488 | change.args[0].u.hostmask = argv[1]; |
d76ed9a9 AS |
1489 | modcmd_chanmode_announce(&change); |
1490 | reply("OSMSG_UNBAN_DONE", channel->name); | |
1491 | return 1; | |
1492 | } | |
1493 | ||
1494 | static MODCMD_FUNC(cmd_voiceall) | |
1495 | { | |
1496 | struct mod_chanmode *change; | |
1497 | unsigned int ii, count; | |
1498 | ||
1499 | change = mod_chanmode_alloc(channel->members.used); | |
1500 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 AS |
1501 | struct modeNode *mn = channel->members.list[ii]; |
1502 | if (mn->modes & (MODE_CHANOP|MODE_HALFOP|MODE_VOICE)) | |
d76ed9a9 AS |
1503 | continue; |
1504 | change->args[count].mode = MODE_VOICE; | |
a32da4c7 | 1505 | change->args[count++].u.member = mn; |
d76ed9a9 AS |
1506 | } |
1507 | if (count) { | |
1508 | change->argc = count; | |
258d1427 | 1509 | modcmd_chanmode_announce(change); |
d76ed9a9 AS |
1510 | } |
1511 | mod_chanmode_free(change); | |
1512 | reply("OSMSG_CHANNEL_VOICED", channel->name); | |
1513 | return 1; | |
1514 | } | |
1515 | ||
1516 | static MODCMD_FUNC(cmd_devoiceall) | |
1517 | { | |
1518 | struct mod_chanmode *change; | |
1519 | unsigned int ii, count; | |
1520 | ||
1521 | change = mod_chanmode_alloc(channel->members.used); | |
1522 | for (ii = count = 0; ii < channel->members.used; ++ii) { | |
258d1427 AS |
1523 | struct modeNode *mn = channel->members.list[ii]; |
1524 | if (!(mn->modes & MODE_VOICE)) | |
d76ed9a9 AS |
1525 | continue; |
1526 | change->args[count].mode = MODE_REMOVE | MODE_VOICE; | |
a32da4c7 | 1527 | change->args[count++].u.member = mn; |
d76ed9a9 AS |
1528 | } |
1529 | if (count) { | |
1530 | change->argc = count; | |
258d1427 | 1531 | modcmd_chanmode_announce(change); |
d76ed9a9 AS |
1532 | } |
1533 | mod_chanmode_free(change); | |
1534 | reply("OSMSG_CHANNEL_DEVOICED", channel->name); | |
1535 | return 1; | |
1536 | } | |
1537 | ||
1538 | static MODCMD_FUNC(cmd_stats_bad) { | |
1539 | dict_iterator_t it; | |
1540 | unsigned int ii, end, here_len; | |
1541 | char buffer[400]; | |
1542 | ||
1543 | /* Show the bad word list.. */ | |
de9510bc | 1544 | /* TODO: convert nonprinting chars like bold to $b etc in a usable way */ |
d76ed9a9 AS |
1545 | for (ii=end=0; ii<opserv_bad_words->used; ii++) { |
1546 | here_len = strlen(opserv_bad_words->list[ii]); | |
de9510bc | 1547 | /* If the line is full output it & start again */ |
d76ed9a9 AS |
1548 | if ((end + here_len + 2) > sizeof(buffer)) { |
1549 | buffer[end] = 0; | |
1550 | reply("OSMSG_BADWORD_LIST", buffer); | |
1551 | end = 0; | |
1552 | } | |
1553 | memcpy(buffer+end, opserv_bad_words->list[ii], here_len); | |
1554 | end += here_len; | |
1555 | buffer[end++] = ' '; | |
1556 | } | |
1557 | buffer[end] = 0; | |
1558 | reply("OSMSG_BADWORD_LIST", buffer); | |
1559 | ||
1560 | /* Show the exemption list.. */ | |
1561 | for (it=dict_first(opserv_exempt_channels), end=0; it; it=iter_next(it)) { | |
1562 | here_len = strlen(iter_key(it)); | |
1563 | if ((end + here_len + 2) > sizeof(buffer)) { | |
1564 | buffer[end] = 0; | |
1565 | reply("OSMSG_EXEMPTED_LIST", buffer); | |
1566 | end = 0; | |
1567 | } | |
1568 | memcpy(buffer+end, iter_key(it), here_len); | |
1569 | end += here_len; | |
1570 | buffer[end++] = ' '; | |
1571 | } | |
1572 | buffer[end] = 0; | |
1573 | reply("OSMSG_EXEMPTED_LIST", buffer); | |
1574 | return 1; | |
1575 | } | |
1576 | ||
1577 | static MODCMD_FUNC(cmd_stats_glines) { | |
1578 | reply("OSMSG_GLINE_COUNT", gline_count()); | |
1579 | return 1; | |
1580 | } | |
1581 | ||
d914d1cb | 1582 | static MODCMD_FUNC(cmd_stats_shuns) { |
1583 | reply("OSMSG_SHUN_COUNT", shun_count()); | |
1584 | return 1; | |
1585 | } | |
1586 | ||
d76ed9a9 AS |
1587 | static void |
1588 | trace_links(struct userNode *bot, struct userNode *user, struct server *server, unsigned int depth) { | |
1589 | unsigned int nn, pos; | |
1590 | char buffer[400]; | |
1591 | ||
1592 | for (nn=1; nn<=depth; nn<<=1) ; | |
1593 | for (pos=0, nn>>=1; nn>1; ) { | |
1594 | nn >>= 1; | |
1595 | buffer[pos++] = (depth & nn) ? ((nn == 1) ? '`' : ' ') : '|'; | |
1596 | buffer[pos++] = (nn == 1) ? '-': ' '; | |
1597 | } | |
1598 | buffer[pos] = 0; | |
1599 | send_message(user, bot, "OSMSG_LINKS_SERVER", buffer, server->name, server->clients, server->description); | |
1600 | if (!server->children.used) | |
1601 | return; | |
1602 | for (nn=0; nn<server->children.used-1; nn++) { | |
1603 | trace_links(bot, user, server->children.list[nn], depth<<1); | |
1604 | } | |
1605 | trace_links(bot, user, server->children.list[nn], (depth<<1)|1); | |
1606 | } | |
1607 | ||
1608 | static MODCMD_FUNC(cmd_stats_links) { | |
1609 | trace_links(cmd->parent->bot, user, self, 1); | |
1610 | return 1; | |
1611 | } | |
1612 | ||
1613 | ||
1614 | static MODCMD_FUNC(cmd_stats_max) { | |
1615 | reply("OSMSG_MAX_CLIENTS", max_clients, asctime(localtime(&max_clients_time))); | |
1616 | return 1; | |
1617 | } | |
1618 | ||
1619 | static MODCMD_FUNC(cmd_stats_network) { | |
1620 | struct helpfile_table tbl; | |
1621 | unsigned int nn, tot_clients; | |
1622 | dict_iterator_t it; | |
1623 | ||
1624 | tot_clients = dict_size(clients); | |
1625 | reply("OSMSG_NETWORK_INFO", tot_clients, invis_clients, curr_opers.used); | |
1626 | tbl.length = dict_size(servers)+1; | |
1627 | tbl.width = 3; | |
1628 | tbl.flags = TABLE_NO_FREE; | |
1629 | tbl.contents = calloc(tbl.length, sizeof(*tbl.contents)); | |
1630 | tbl.contents[0] = calloc(tbl.width, sizeof(**tbl.contents)); | |
1631 | tbl.contents[0][0] = "Server Name"; | |
1632 | tbl.contents[0][1] = "Clients"; | |
1633 | tbl.contents[0][2] = "Load"; | |
1634 | for (it=dict_first(servers), nn=1; it; it=iter_next(it)) { | |
1635 | struct server *server = iter_data(it); | |
1636 | char *buffer = malloc(32); | |
1637 | tbl.contents[nn] = calloc(tbl.width, sizeof(**tbl.contents)); | |
1638 | tbl.contents[nn][0] = server->name; | |
1639 | tbl.contents[nn][1] = buffer; | |
1640 | sprintf(buffer, "%u", server->clients); | |
1641 | tbl.contents[nn][2] = buffer + 16; | |
1642 | sprintf(buffer+16, "%3.3g%%", ((double)server->clients/tot_clients)*100); | |
1643 | nn++; | |
1644 | } | |
1645 | table_send(cmd->parent->bot, user->nick, 0, 0, tbl); | |
1646 | for (nn=1; nn<tbl.length; nn++) { | |
1647 | free((char*)tbl.contents[nn][1]); | |
1648 | free(tbl.contents[nn]); | |
1649 | } | |
1650 | free(tbl.contents[0]); | |
1651 | free(tbl.contents); | |
1652 | return 1; | |
1653 | } | |
1654 | ||
1655 | static MODCMD_FUNC(cmd_stats_network2) { | |
1656 | struct helpfile_table tbl; | |
1657 | unsigned int nn; | |
1658 | dict_iterator_t it; | |
1659 | ||
1660 | tbl.length = dict_size(servers)+1; | |
1661 | tbl.width = 3; | |
1662 | tbl.flags = TABLE_NO_FREE; | |
1663 | tbl.contents = calloc(tbl.length, sizeof(*tbl.contents)); | |
1664 | tbl.contents[0] = calloc(tbl.width, sizeof(**tbl.contents)); | |
1665 | tbl.contents[0][0] = "Server Name"; | |
1666 | tbl.contents[0][1] = "Numeric"; | |
1667 | tbl.contents[0][2] = "Link Time"; | |
1668 | for (it=dict_first(servers), nn=1; it; it=iter_next(it)) { | |
1669 | struct server *server = iter_data(it); | |
1670 | char *buffer = malloc(64); | |
1671 | int ofs; | |
1672 | ||
1673 | tbl.contents[nn] = calloc(tbl.width, sizeof(**tbl.contents)); | |
1674 | tbl.contents[nn][0] = server->name; | |
1675 | #ifdef WITH_PROTOCOL_P10 | |
1676 | sprintf(buffer, "%s (%ld)", server->numeric, base64toint(server->numeric, strlen(server->numeric))); | |
1677 | #else | |
1678 | buffer[0] = 0; | |
1679 | #endif | |
1680 | tbl.contents[nn][1] = buffer; | |
1681 | ofs = strlen(buffer) + 1; | |
1682 | intervalString(buffer + ofs, now - server->link, user->handle_info); | |
1683 | if (server->self_burst) | |
1684 | strcat(buffer + ofs, " Bursting"); | |
1685 | tbl.contents[nn][2] = buffer + ofs; | |
1686 | nn++; | |
1687 | } | |
1688 | table_send(cmd->parent->bot, user->nick, 0, 0, tbl); | |
1689 | for (nn=1; nn<tbl.length; nn++) { | |
1690 | free((char*)tbl.contents[nn][1]); | |
1691 | free(tbl.contents[nn]); | |
1692 | } | |
1693 | free(tbl.contents[0]); | |
1694 | free(tbl.contents); | |
1695 | return 1; | |
1696 | } | |
1697 | ||
1698 | static MODCMD_FUNC(cmd_stats_reserved) { | |
1699 | dict_iterator_t it; | |
1700 | ||
1701 | reply("OSMSG_RESERVED_LIST"); | |
1702 | for (it = dict_first(opserv_reserved_nick_dict); it; it = iter_next(it)) | |
1703 | send_message_type(4, user, cmd->parent->bot, "%s", iter_key(it)); | |
1704 | return 1; | |
1705 | } | |
1706 | ||
1707 | static MODCMD_FUNC(cmd_stats_trusted) { | |
1708 | dict_iterator_t it; | |
1709 | struct trusted_host *th; | |
1710 | char length[INTERVALLEN], issued[INTERVALLEN], limit[32]; | |
1711 | ||
de9510bc AS |
1712 | reply("OSMSG_TRUSTED_LIST"); |
1713 | reply("OSMSG_TRUSTED_LIST_BAR"); | |
1714 | reply("OSMSG_TRUSTED_LIST_HEADER"); | |
1715 | reply("OSMSG_TRUSTED_LIST_BAR"); | |
d76ed9a9 AS |
1716 | if (argc > 1) { |
1717 | th = dict_find(opserv_trusted_hosts, argv[1], NULL); | |
1718 | if (th) { | |
1719 | if (th->issued) | |
1720 | intervalString(issued, now - th->issued, user->handle_info); | |
1721 | if (th->expires) | |
1722 | intervalString(length, th->expires - now, user->handle_info); | |
1723 | if (th->limit) | |
de9510bc | 1724 | sprintf(limit, "%lu", th->limit); |
d76ed9a9 AS |
1725 | reply("OSMSG_HOST_IS_TRUSTED", |
1726 | th->ipaddr, | |
de9510bc | 1727 | (th->limit ? limit : "none"), |
d76ed9a9 | 1728 | (th->issuer ? th->issuer : "<unknown>"), |
de9510bc AS |
1729 | (th->issued ? issued : "some time"), |
1730 | (th->expires ? length : "never")); | |
1731 | reply("OSMSG_HOST_IS_TRUSTED_DESC", (th->reason ? th->reason : "<unknown>")); | |
d76ed9a9 AS |
1732 | } else { |
1733 | reply("OSMSG_HOST_NOT_TRUSTED", argv[1]); | |
1734 | } | |
1735 | } else { | |
d76ed9a9 AS |
1736 | for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) { |
1737 | th = iter_data(it); | |
1738 | if (th->issued) | |
1739 | intervalString(issued, now - th->issued, user->handle_info); | |
1740 | if (th->expires) | |
1741 | intervalString(length, th->expires - now, user->handle_info); | |
1742 | if (th->limit) | |
de9510bc | 1743 | sprintf(limit, "%lu", th->limit); |
d76ed9a9 | 1744 | reply("OSMSG_HOST_IS_TRUSTED", iter_key(it), |
de9510bc | 1745 | (th->limit ? limit : "none"), |
d76ed9a9 | 1746 | (th->issuer ? th->issuer : "<unknown>"), |
de9510bc AS |
1747 | (th->issued ? issued : "some time"), |
1748 | (th->expires ? length : "never")); | |
1749 | reply("OSMSG_HOST_IS_TRUSTED_DESC", (th->reason ? th->reason : "<unknown>")); | |
d76ed9a9 AS |
1750 | } |
1751 | } | |
de9510bc | 1752 | reply("OSMSG_TRUSTED_LIST_END"); |
d76ed9a9 AS |
1753 | return 1; |
1754 | } | |
1755 | ||
1756 | static MODCMD_FUNC(cmd_stats_uplink) { | |
1757 | extern struct cManagerNode cManager; | |
1758 | struct uplinkNode *uplink; | |
1759 | ||
1760 | uplink = cManager.uplink; | |
1761 | reply("OSMSG_UPLINK_START", uplink->name); | |
1762 | reply("OSMSG_UPLINK_ADDRESS", uplink->host, uplink->port); | |
1763 | return 1; | |
1764 | } | |
1765 | ||
1766 | static MODCMD_FUNC(cmd_stats_uptime) { | |
1767 | char uptime[INTERVALLEN]; | |
1768 | struct tms buf; | |
1769 | extern time_t boot_time; | |
1770 | extern int lines_processed; | |
1771 | static long clocks_per_sec; | |
1772 | ||
1773 | if (!clocks_per_sec) { | |
1774 | #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) | |
1775 | clocks_per_sec = sysconf(_SC_CLK_TCK); | |
1776 | if (clocks_per_sec <= 0) | |
1777 | #endif | |
1778 | { | |
1779 | log_module(OS_LOG, LOG_ERROR, "Unable to query sysconf(_SC_CLK_TCK), output of 'stats uptime' will be wrong"); | |
1780 | clocks_per_sec = CLOCKS_PER_SEC; | |
1781 | } | |
1782 | } | |
1783 | intervalString(uptime, time(NULL)-boot_time, user->handle_info); | |
1784 | times(&buf); | |
1785 | reply("OSMSG_UPTIME_STATS", | |
1786 | uptime, lines_processed, | |
1787 | buf.tms_utime/(double)clocks_per_sec, | |
1788 | buf.tms_stime/(double)clocks_per_sec); | |
1789 | return 1; | |
1790 | } | |
1791 | ||
1792 | static MODCMD_FUNC(cmd_stats_alerts) { | |
1793 | dict_iterator_t it; | |
1794 | struct opserv_user_alert *alert; | |
1795 | const char *reaction; | |
1796 | ||
1797 | reply("OSMSG_ALERTS_LIST"); | |
de9510bc AS |
1798 | reply("OSMSG_ALERTS_BAR"); |
1799 | reply("OSMSG_ALERTS_HEADER"); | |
1800 | reply("OSMSG_ALERTS_BAR"); | |
d76ed9a9 AS |
1801 | for (it = dict_first(opserv_user_alerts); it; it = iter_next(it)) { |
1802 | alert = iter_data(it); | |
1803 | switch (alert->reaction) { | |
1804 | case REACT_NOTICE: reaction = "notice"; break; | |
1805 | case REACT_KILL: reaction = "kill"; break; | |
9a75756e | 1806 | case REACT_SILENT: reaction = "silent"; break; |
d76ed9a9 | 1807 | case REACT_GLINE: reaction = "gline"; break; |
d914d1cb | 1808 | case REACT_SHUN: reaction = "shun"; break; |
d76ed9a9 AS |
1809 | default: reaction = "<unknown>"; break; |
1810 | } | |
de9510bc AS |
1811 | reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner); |
1812 | reply("OSMSG_ALERTS_DESC", alert->text_discrim); | |
d76ed9a9 | 1813 | } |
de9510bc | 1814 | reply("OSMSG_ALERT_END"); |
d76ed9a9 AS |
1815 | return 1; |
1816 | } | |
1817 | ||
1818 | static MODCMD_FUNC(cmd_stats_gags) { | |
1819 | struct gag_entry *gag; | |
1820 | struct helpfile_table table; | |
1821 | unsigned int nn; | |
1822 | ||
1823 | if (!gagList) { | |
258d1427 | 1824 | reply("OSMSG_NO_GAGS"); |
d76ed9a9 AS |
1825 | return 1; |
1826 | } | |
1827 | for (nn=0, gag=gagList; gag; nn++, gag=gag->next) ; | |
1828 | table.length = nn+1; | |
1829 | table.width = 4; | |
1830 | table.flags = TABLE_NO_FREE; | |
1831 | table.contents = calloc(table.length, sizeof(char**)); | |
1832 | table.contents[0] = calloc(table.width, sizeof(char*)); | |
1833 | table.contents[0][0] = "Mask"; | |
1834 | table.contents[0][1] = "Owner"; | |
1835 | table.contents[0][2] = "Expires"; | |
1836 | table.contents[0][3] = "Reason"; | |
1837 | for (nn=1, gag=gagList; gag; nn++, gag=gag->next) { | |
1838 | char expstr[INTERVALLEN]; | |
1839 | if (gag->expires) | |
1840 | intervalString(expstr, gag->expires - now, user->handle_info); | |
1841 | else | |
1842 | strcpy(expstr, "Never"); | |
1843 | table.contents[nn] = calloc(table.width, sizeof(char*)); | |
1844 | table.contents[nn][0] = gag->mask; | |
1845 | table.contents[nn][1] = gag->owner; | |
1846 | table.contents[nn][2] = strdup(expstr); | |
1847 | table.contents[nn][3] = gag->reason; | |
1848 | } | |
1849 | table_send(cmd->parent->bot, user->nick, 0, NULL, table); | |
1850 | for (nn=1; nn<table.length; nn++) { | |
1851 | free((char*)table.contents[nn][2]); | |
1852 | free(table.contents[nn]); | |
1853 | } | |
1854 | free(table.contents[0]); | |
1855 | free(table.contents); | |
1856 | return 1; | |
1857 | } | |
1858 | ||
1859 | static MODCMD_FUNC(cmd_stats_timeq) { | |
1860 | reply("OSMSG_TIMEQ_INFO", timeq_size(), timeq_next()-now); | |
1861 | return 1; | |
1862 | } | |
1863 | ||
de9510bc | 1864 | /* |
d76ed9a9 AS |
1865 | static MODCMD_FUNC(cmd_stats_warn) { |
1866 | dict_iterator_t it; | |
1867 | ||
1868 | reply("OSMSG_WARN_LISTSTART"); | |
1869 | for (it=dict_first(opserv_chan_warn); it; it=iter_next(it)) | |
1870 | reply("OSMSG_WARN_LISTENTRY", iter_key(it), (char*)iter_data(it)); | |
1871 | reply("OSMSG_WARN_LISTEND"); | |
1872 | return 1; | |
1873 | } | |
de9510bc | 1874 | */ |
d76ed9a9 | 1875 | |
f14e4f83 | 1876 | #if defined(WITH_MALLOC_X3) |
ec1a68c8 | 1877 | static MODCMD_FUNC(cmd_stats_memory) { |
1878 | extern unsigned long alloc_count, alloc_size; | |
0d16e639 | 1879 | send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, |
1880 | "%u allocations totalling %u bytes.", | |
1881 | alloc_count, alloc_size); | |
1882 | return 1; | |
1883 | } | |
1884 | #elif defined(WITH_MALLOC_SLAB) | |
1885 | static MODCMD_FUNC(cmd_stats_memory) { | |
1886 | extern unsigned long slab_alloc_count, slab_count, slab_alloc_size; | |
1887 | extern unsigned long big_alloc_count, big_alloc_size; | |
1888 | send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, | |
1889 | "%u allocations in %u slabs totalling %u bytes.", | |
1890 | slab_alloc_count, slab_count, slab_alloc_size); | |
de9510bc | 1891 | /* send_message_type(MSG_TYPE_NOXLATE, user, cmd->parent->bot, |
0d16e639 | 1892 | "%u big allocations totalling %u bytes.", |
de9510bc | 1893 | */ |
ec1a68c8 | 1894 | return 1; |
1895 | } | |
1896 | #endif | |
1897 | ||
d76ed9a9 AS |
1898 | static MODCMD_FUNC(cmd_dump) |
1899 | { | |
b336c8db | 1900 | char linedup[MAXLEN], original[MAXLEN]; |
d76ed9a9 | 1901 | |
b336c8db | 1902 | unsplit_string(argv+1, argc-1, original); |
d76ed9a9 AS |
1903 | safestrncpy(linedup, original, sizeof(linedup)); |
1904 | /* assume it's only valid IRC if we can parse it */ | |
1905 | if (parse_line(linedup, 1)) { | |
258d1427 AS |
1906 | irc_raw(original); |
1907 | reply("OSMSG_LINE_DUMPED"); | |
d76ed9a9 | 1908 | } else |
258d1427 | 1909 | reply("OSMSG_RAW_PARSE_ERROR"); |
d76ed9a9 AS |
1910 | return 1; |
1911 | } | |
1912 | ||
1913 | static MODCMD_FUNC(cmd_raw) | |
1914 | { | |
b336c8db | 1915 | char linedup[MAXLEN], original[MAXLEN]; |
d76ed9a9 | 1916 | |
b336c8db | 1917 | unsplit_string(argv+1, argc-1, original); |
d76ed9a9 AS |
1918 | safestrncpy(linedup, original, sizeof(linedup)); |
1919 | /* Try to parse the line before sending it; if it's too wrong, | |
1920 | * maybe it will core us instead of our uplink. */ | |
1921 | parse_line(linedup, 1); | |
1922 | irc_raw(original); | |
1923 | reply("OSMSG_LINE_DUMPED"); | |
1924 | return 1; | |
1925 | } | |
1926 | ||
1927 | static struct userNode * | |
1928 | opserv_add_reserve(struct svccmd *cmd, struct userNode *user, const char *nick, const char *ident, const char *host, const char *desc) | |
1929 | { | |
1930 | struct userNode *resv = GetUserH(nick); | |
1931 | if (resv) { | |
258d1427 AS |
1932 | if (IsService(resv)) { |
1933 | reply("MSG_SERVICE_IMMUNE", resv->nick); | |
1934 | return NULL; | |
1935 | } | |
1936 | if (resv->handle_info | |
1937 | && resv->handle_info->opserv_level > user->handle_info->opserv_level) { | |
1938 | reply("OSMSG_LEVEL_TOO_LOW"); | |
1939 | return NULL; | |
1940 | } | |
d76ed9a9 AS |
1941 | } |
1942 | if ((resv = AddClone(nick, ident, host, desc))) { | |
1943 | dict_insert(opserv_reserved_nick_dict, resv->nick, resv); | |
1944 | } | |
1945 | return resv; | |
1946 | } | |
1947 | ||
1948 | static MODCMD_FUNC(cmd_collide) | |
1949 | { | |
1950 | struct userNode *resv; | |
1951 | ||
1952 | resv = opserv_add_reserve(cmd, user, argv[1], argv[2], argv[3], unsplit_string(argv+4, argc-4, NULL)); | |
1953 | if (resv) { | |
258d1427 AS |
1954 | reply("OSMSG_COLLIDED_NICK", resv->nick); |
1955 | return 1; | |
d76ed9a9 AS |
1956 | } else { |
1957 | reply("OSMSG_CLONE_FAILED", argv[1]); | |
258d1427 | 1958 | return 0; |
d76ed9a9 AS |
1959 | } |
1960 | } | |
1961 | ||
1962 | static MODCMD_FUNC(cmd_reserve) | |
1963 | { | |
1964 | struct userNode *resv; | |
1965 | ||
1966 | resv = opserv_add_reserve(cmd, user, argv[1], argv[2], argv[3], unsplit_string(argv+4, argc-4, NULL)); | |
1967 | if (resv) { | |
258d1427 AS |
1968 | resv->modes |= FLAGS_PERSISTENT; |
1969 | reply("OSMSG_RESERVED_NICK", resv->nick); | |
1970 | return 1; | |
d76ed9a9 AS |
1971 | } else { |
1972 | reply("OSMSG_CLONE_FAILED", argv[1]); | |
258d1427 | 1973 | return 0; |
d76ed9a9 AS |
1974 | } |
1975 | } | |
1976 | ||
1977 | static int | |
1978 | free_reserve(char *nick) | |
1979 | { | |
1980 | struct userNode *resv; | |
1981 | unsigned int rlen; | |
1982 | char *reason; | |
1983 | ||
1984 | resv = dict_find(opserv_reserved_nick_dict, nick, NULL); | |
1985 | if (!resv) | |
1986 | return 0; | |
1987 | ||
1988 | rlen = strlen(resv->nick)+strlen(OSMSG_PART_REASON); | |
1989 | reason = alloca(rlen); | |
1990 | snprintf(reason, rlen, OSMSG_PART_REASON, resv->nick); | |
1991 | DelUser(resv, NULL, 1, reason); | |
1992 | dict_remove(opserv_reserved_nick_dict, nick); | |
1993 | return 1; | |
1994 | } | |
1995 | ||
1996 | static MODCMD_FUNC(cmd_unreserve) | |
1997 | { | |
1998 | if (free_reserve(argv[1])) | |
258d1427 | 1999 | reply("OSMSG_NICK_UNRESERVED", argv[1]); |
d76ed9a9 | 2000 | else |
258d1427 | 2001 | reply("OSMSG_NOT_RESERVED", argv[1]); |
d76ed9a9 AS |
2002 | return 1; |
2003 | } | |
2004 | ||
2005 | static void | |
2006 | opserv_part_channel(void *data) | |
2007 | { | |
2008 | DelChannelUser(opserv, data, "Leaving.", 0); | |
2009 | } | |
2010 | ||
2011 | static int alert_check_user(const char *key, void *data, void *extra); | |
2012 | ||
2013 | static int | |
2014 | opserv_new_user_check(struct userNode *user) | |
2015 | { | |
2016 | struct opserv_hostinfo *ohi; | |
2017 | struct gag_entry *gag; | |
2018 | ||
2019 | /* Check to see if we should ignore them entirely. */ | |
2020 | if (IsLocal(user) || IsService(user)) | |
2021 | return 0; | |
2022 | ||
2023 | /* Check for alerts, and stop if we find one that kills them. */ | |
2024 | if (dict_foreach(opserv_user_alerts, alert_check_user, user)) | |
2025 | return 1; | |
2026 | ||
2027 | /* Gag them if appropriate. */ | |
2028 | for (gag = gagList; gag; gag = gag->next) { | |
2029 | if (user_matches_glob(user, gag->mask, 1)) { | |
2030 | gag_helper_func(user, NULL); | |
2031 | break; | |
2032 | } | |
2033 | } | |
2034 | ||
2035 | /* Add to host info struct */ | |
2036 | if (!(ohi = dict_find(opserv_hostinfo_dict, inet_ntoa(user->ip), NULL))) { | |
2037 | ohi = calloc(1, sizeof(*ohi)); | |
2038 | dict_insert(opserv_hostinfo_dict, strdup(inet_ntoa(user->ip)), ohi); | |
2039 | userList_init(&ohi->clients); | |
2040 | } | |
2041 | userList_append(&ohi->clients, user); | |
2042 | ||
2043 | /* Only warn of new user floods outside of bursts. */ | |
2044 | if (!user->uplink->burst) { | |
2045 | if (!policer_conforms(&opserv_conf.new_user_policer, now, 10)) { | |
2046 | if (!new_user_flood) { | |
2047 | new_user_flood = 1; | |
2048 | opserv_alert("Warning: Possible new-user flood."); | |
2049 | } | |
2050 | } else { | |
2051 | new_user_flood = 0; | |
2052 | } | |
2053 | } | |
2054 | ||
2055 | /* Only warn or G-line if there's an untrusted max and their IP is sane. */ | |
2056 | if (opserv_conf.untrusted_max && user->ip.s_addr && (ntohl(user->ip.s_addr) != INADDR_LOOPBACK)) { | |
2057 | struct trusted_host *th = dict_find(opserv_trusted_hosts, inet_ntoa(user->ip), NULL); | |
2058 | unsigned int limit = th ? th->limit : opserv_conf.untrusted_max; | |
2059 | if (!limit) { | |
2060 | /* 0 means unlimited hosts */ | |
2061 | } else if (ohi->clients.used == limit) { | |
2062 | unsigned int nn; | |
2063 | for (nn=0; nn<ohi->clients.used; nn++) | |
2064 | send_message(ohi->clients.list[nn], opserv, "OSMSG_CLONE_WARNING"); | |
2065 | } else if (ohi->clients.used > limit) { | |
2066 | char target[18]; | |
2067 | sprintf(target, "*@%s", inet_ntoa(user->ip)); | |
9a75756e | 2068 | gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "Excessive connections from a single host.", now, 1, 1); |
d76ed9a9 AS |
2069 | } |
2070 | } | |
2071 | ||
2072 | return 0; | |
2073 | } | |
2074 | ||
2075 | static void | |
2076 | opserv_user_cleanup(struct userNode *user, UNUSED_ARG(struct userNode *killer), UNUSED_ARG(const char *why)) | |
2077 | { | |
2078 | struct opserv_hostinfo *ohi; | |
2079 | ||
2080 | if (IsLocal(user)) { | |
2081 | /* Try to remove it from the reserved nick dict without | |
2082 | * calling free_reserve, because that would call DelUser(), | |
2083 | * and we'd loop back to here. */ | |
2084 | dict_remove(opserv_reserved_nick_dict, user->nick); | |
2085 | return; | |
2086 | } | |
2087 | if ((ohi = dict_find(opserv_hostinfo_dict, inet_ntoa(user->ip), NULL))) { | |
2088 | userList_remove(&ohi->clients, user); | |
2089 | if (ohi->clients.used == 0) dict_remove(opserv_hostinfo_dict, inet_ntoa(user->ip)); | |
2090 | } | |
2091 | } | |
2092 | ||
2093 | int | |
2094 | opserv_bad_channel(const char *name) | |
2095 | { | |
2096 | unsigned int found; | |
697f4c9a | 2097 | int present; |
d76ed9a9 | 2098 | |
697f4c9a | 2099 | dict_find(opserv_exempt_channels, name, &present); |
2100 | if (present) | |
d76ed9a9 AS |
2101 | return 0; |
2102 | ||
2103 | if (gline_find(name)) | |
2104 | return 1; | |
2105 | ||
2106 | for (found=0; found<opserv_bad_words->used; ++found) | |
2107 | if (irccasestr(name, opserv_bad_words->list[found])) | |
2108 | return 1; | |
2109 | ||
2110 | return 0; | |
2111 | } | |
2112 | ||
2113 | static void | |
2114 | opserv_shutdown_channel(struct chanNode *channel, const char *reason) | |
2115 | { | |
2116 | struct mod_chanmode *change; | |
2117 | unsigned int nn; | |
2118 | ||
2119 | change = mod_chanmode_alloc(2); | |
2120 | change->modes_set = MODE_SECRET | MODE_INVITEONLY; | |
2121 | change->args[0].mode = MODE_CHANOP; | |
a32da4c7 | 2122 | change->args[0].u.member = AddChannelUser(opserv, channel); |
d76ed9a9 | 2123 | change->args[1].mode = MODE_BAN; |
a32da4c7 | 2124 | change->args[1].u.hostmask = "*!*@*"; |
d76ed9a9 AS |
2125 | mod_chanmode_announce(opserv, channel, change); |
2126 | mod_chanmode_free(change); | |
2127 | for (nn=channel->members.used; nn>0; ) { | |
2128 | struct modeNode *mNode = channel->members.list[--nn]; | |
2129 | if (IsService(mNode->user)) | |
2130 | continue; | |
2131 | KickChannelUser(mNode->user, channel, opserv, user_find_message(mNode->user, reason)); | |
2132 | } | |
2133 | timeq_add(now + opserv_conf.purge_lock_delay, opserv_part_channel, channel); | |
2134 | } | |
2135 | ||
2136 | static void | |
2137 | opserv_channel_check(struct chanNode *newchan) | |
2138 | { | |
c52666c6 | 2139 | /*char *warning; */ |
d76ed9a9 AS |
2140 | |
2141 | if (!newchan->join_policer.params) { | |
2142 | newchan->join_policer.last_req = now; | |
2143 | newchan->join_policer.params = opserv_conf.join_policer_params; | |
2144 | } | |
c52666c6 | 2145 | /* |
d76ed9a9 AS |
2146 | if ((warning = dict_find(opserv_chan_warn, newchan->name, NULL))) { |
2147 | char message[MAXLEN]; | |
2148 | snprintf(message, sizeof(message), "Channel activity warning for channel %s: %s", newchan->name, warning); | |
2149 | global_message(MESSAGE_RECIPIENT_OPERS, message); | |
2150 | } | |
c52666c6 | 2151 | */ |
d76ed9a9 | 2152 | |
c52666c6 | 2153 | /* Wait until the join check to shut channels down. */ |
d76ed9a9 AS |
2154 | newchan->bad_channel = opserv_bad_channel(newchan->name); |
2155 | } | |
2156 | ||
2157 | static void | |
2158 | opserv_channel_delete(struct chanNode *chan) | |
2159 | { | |
2160 | timeq_del(0, opserv_part_channel, chan, TIMEQ_IGNORE_WHEN); | |
2161 | } | |
2162 | ||
2163 | static int | |
2164 | opserv_join_check(struct modeNode *mNode) | |
2165 | { | |
2166 | struct userNode *user = mNode->user; | |
2167 | struct chanNode *channel = mNode->channel; | |
2168 | const char *msg; | |
2169 | ||
2170 | if (IsService(user)) | |
2171 | return 0; | |
2172 | ||
2173 | dict_foreach(opserv_channel_alerts, alert_check_user, user); | |
2174 | ||
2175 | if (channel->bad_channel) { | |
2176 | opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user->nick, channel->name); | |
2177 | if (channel->name[0] != '#') | |
2178 | DelUser(user, opserv, 1, "OSMSG_ILLEGAL_KILL_REASON"); | |
2179 | else if (!GetUserMode(channel, opserv)) | |
2180 | opserv_shutdown_channel(channel, "OSMSG_ILLEGAL_REASON"); | |
2181 | else { | |
2182 | send_message(user, opserv, "OSMSG_ILLEGAL_CHANNEL", channel->name); | |
2183 | msg = user_find_message(user, "OSMSG_ILLEGAL_REASON"); | |
2184 | KickChannelUser(user, channel, opserv, msg); | |
2185 | } | |
2186 | return 1; | |
2187 | } | |
2188 | ||
2189 | if (user->uplink->burst) | |
2190 | return 0; | |
2191 | if (policer_conforms(&channel->join_policer, now, 1.0)) { | |
2192 | channel->join_flooded = 0; | |
2193 | return 0; | |
2194 | } | |
2195 | if (!channel->join_flooded) { | |
2196 | /* Don't moderate the channel unless it is activated and | |
2197 | the number of users in the channel is over the threshold. */ | |
2198 | struct mod_chanmode change; | |
2199 | mod_chanmode_init(&change); | |
2200 | channel->join_flooded = 1; | |
2201 | if (opserv_conf.join_flood_moderate && (channel->members.used > opserv_conf.join_flood_moderate_threshold)) { | |
2202 | if (!GetUserMode(channel, opserv)) { | |
2203 | /* If we aren't in the channel, join it. */ | |
2204 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 2205 | change.args[0].u.member = AddChannelUser(opserv, channel); |
d76ed9a9 AS |
2206 | change.argc++; |
2207 | } | |
2208 | if (!(channel->modes & MODE_MODERATED)) | |
2209 | change.modes_set |= MODE_MODERATED; | |
2210 | if (change.modes_set || change.argc) | |
2211 | mod_chanmode_announce(opserv, channel, &change); | |
2212 | send_target_message(0, channel->name, opserv, "OSMSG_FLOOD_MODERATE"); | |
2213 | opserv_alert("Warning: Possible join flood in %s (currently %d users; channel moderated).", channel->name, channel->members.used); | |
2214 | } else { | |
2215 | opserv_alert("Warning: Possible join flood in %s (currently %d users).", channel->name, channel->members.used); | |
2216 | } | |
2217 | } | |
2218 | log_module(OS_LOG, LOG_INFO, "Join to %s during flood: "IDENT_FORMAT, channel->name, IDENT_DATA(user)); | |
2219 | return 0; | |
2220 | } | |
2221 | ||
2222 | static int | |
2223 | opserv_add_bad_word(struct svccmd *cmd, struct userNode *user, const char *new_bad) { | |
2224 | unsigned int bad_idx; | |
2225 | ||
2226 | for (bad_idx = 0; bad_idx < opserv_bad_words->used; ++bad_idx) { | |
2227 | char *orig_bad = opserv_bad_words->list[bad_idx]; | |
2228 | if (irccasestr(new_bad, orig_bad)) { | |
2229 | if (user) | |
2230 | reply("OSMSG_BAD_REDUNDANT", new_bad, orig_bad); | |
2231 | return 0; | |
2232 | } else if (irccasestr(orig_bad, new_bad)) { | |
2233 | if (user) | |
2234 | reply("OSMSG_BAD_GROWING", orig_bad, new_bad); | |
2235 | free(orig_bad); | |
2236 | opserv_bad_words->list[bad_idx] = strdup(new_bad); | |
2237 | for (bad_idx++; bad_idx < opserv_bad_words->used; bad_idx++) { | |
2238 | orig_bad = opserv_bad_words->list[bad_idx]; | |
2239 | if (!irccasestr(orig_bad, new_bad)) | |
2240 | continue; | |
2241 | if (user) | |
2242 | reply("OSMSG_BAD_NUKING", orig_bad); | |
2243 | string_list_delete(opserv_bad_words, bad_idx); | |
2244 | bad_idx--; | |
2245 | free(orig_bad); | |
2246 | } | |
2247 | return 1; | |
2248 | } | |
2249 | } | |
2250 | string_list_append(opserv_bad_words, strdup(new_bad)); | |
2251 | if (user) | |
2252 | reply("OSMSG_ADDED_BAD", new_bad); | |
2253 | return 1; | |
2254 | } | |
2255 | ||
2256 | static MODCMD_FUNC(cmd_addbad) | |
2257 | { | |
2258 | unsigned int arg, count; | |
2259 | dict_iterator_t it; | |
2260 | int bad_found, exempt_found; | |
2261 | ||
2262 | /* Create the bad word if it doesn't exist. */ | |
2263 | bad_found = !opserv_add_bad_word(cmd, user, argv[1]); | |
2264 | ||
2265 | /* Look for exception modifiers. */ | |
2266 | for (arg=2; arg<argc; arg++) { | |
2267 | if (!irccasecmp(argv[arg], "except")) { | |
2268 | reply("MSG_DEPRECATED_COMMAND", "addbad ... except", "addexempt"); | |
2269 | if (++arg > argc) { | |
2270 | reply("MSG_MISSING_PARAMS", "except"); | |
2271 | break; | |
2272 | } | |
2273 | for (count = 0; (arg < argc) && IsChannelName(argv[arg]); arg++) { | |
2274 | dict_find(opserv_exempt_channels, argv[arg], &exempt_found); | |
2275 | if (!exempt_found) { | |
2276 | dict_insert(opserv_exempt_channels, strdup(argv[arg]), NULL); | |
2277 | count++; | |
2278 | } | |
2279 | } | |
2280 | reply("OSMSG_ADDED_EXEMPTIONS", count); | |
2281 | } else { | |
2282 | reply("MSG_DEPRECATED_COMMAND", "addbad (with modifiers)", "addbad"); | |
2283 | reply("OSMSG_BAD_MODIFIER", argv[arg]); | |
2284 | } | |
2285 | } | |
2286 | ||
2287 | /* Scan for existing channels that match the new bad word. */ | |
2288 | if (!bad_found) { | |
2289 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
2290 | struct chanNode *channel = iter_data(it); | |
2291 | ||
2292 | if (!opserv_bad_channel(channel->name)) | |
2293 | continue; | |
2294 | channel->bad_channel = 1; | |
2295 | if (channel->name[0] == '#') | |
2296 | opserv_shutdown_channel(channel, "OSMSG_ILLEGAL_REASON"); | |
2297 | else { | |
2298 | unsigned int nn; | |
2299 | for (nn=0; nn<channel->members.used; nn++) { | |
2300 | struct userNode *user = channel->members.list[nn]->user; | |
2301 | DelUser(user, cmd->parent->bot, 1, "OSMSG_ILLEGAL_KILL_REASON"); | |
2302 | } | |
2303 | } | |
2304 | } | |
2305 | } | |
2306 | ||
2307 | return 1; | |
2308 | } | |
2309 | ||
2310 | static MODCMD_FUNC(cmd_delbad) | |
2311 | { | |
2312 | dict_iterator_t it; | |
2313 | unsigned int nn; | |
2314 | ||
2315 | for (nn=0; nn<opserv_bad_words->used; nn++) { | |
2316 | if (!irccasecmp(opserv_bad_words->list[nn], argv[1])) { | |
2317 | string_list_delete(opserv_bad_words, nn); | |
2318 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
2319 | channel = iter_data(it); | |
2320 | if (irccasestr(channel->name, argv[1]) | |
2321 | && !opserv_bad_channel(channel->name)) { | |
2322 | DelChannelUser(cmd->parent->bot, channel, "Channel name no longer contains a bad word.", 1); | |
2323 | timeq_del(0, opserv_part_channel, channel, TIMEQ_IGNORE_WHEN); | |
2324 | channel->bad_channel = 0; | |
2325 | } | |
2326 | } | |
2327 | reply("OSMSG_REMOVED_BAD", argv[1]); | |
2328 | return 1; | |
2329 | } | |
2330 | } | |
2331 | reply("OSMSG_NOT_BAD_WORD", argv[1]); | |
2332 | return 0; | |
2333 | } | |
2334 | ||
2335 | static MODCMD_FUNC(cmd_addexempt) | |
2336 | { | |
2337 | const char *chanName; | |
2338 | ||
2339 | if ((argc > 1) && IsChannelName(argv[1])) { | |
2340 | chanName = argv[1]; | |
2341 | } else { | |
2342 | reply("MSG_NOT_CHANNEL_NAME"); | |
2343 | OPSERV_SYNTAX(); | |
2344 | return 0; | |
2345 | } | |
2346 | dict_insert(opserv_exempt_channels, strdup(chanName), NULL); | |
2347 | channel = GetChannel(chanName); | |
2348 | if (channel) { | |
2349 | if (channel->bad_channel) { | |
2350 | DelChannelUser(cmd->parent->bot, channel, "Channel is now exempt from bad-word checking.", 1); | |
2351 | timeq_del(0, opserv_part_channel, channel, TIMEQ_IGNORE_WHEN); | |
2352 | } | |
2353 | channel->bad_channel = 0; | |
2354 | } | |
2355 | reply("OSMSG_ADDED_EXEMPTION", chanName); | |
2356 | return 1; | |
2357 | } | |
2358 | ||
2359 | static MODCMD_FUNC(cmd_delexempt) | |
2360 | { | |
2361 | const char *chanName; | |
2362 | ||
2363 | if ((argc > 1) && IsChannelName(argv[1])) { | |
2364 | chanName = argv[1]; | |
2365 | } else { | |
2366 | reply("MSG_NOT_CHANNEL_NAME"); | |
2367 | OPSERV_SYNTAX(); | |
2368 | return 0; | |
2369 | } | |
2370 | if (!dict_remove(opserv_exempt_channels, chanName)) { | |
2371 | reply("OSMSG_NOT_EXEMPT", chanName); | |
2372 | return 0; | |
2373 | } | |
2374 | reply("OSMSG_REMOVED_EXEMPTION", chanName); | |
2375 | return 1; | |
2376 | } | |
2377 | ||
2378 | static void | |
2379 | opserv_expire_trusted_host(void *data) | |
2380 | { | |
2381 | struct trusted_host *th = data; | |
2382 | dict_remove(opserv_trusted_hosts, th->ipaddr); | |
2383 | } | |
2384 | ||
2385 | static void | |
2386 | opserv_add_trusted_host(const char *ipaddr, unsigned int limit, const char *issuer, time_t issued, time_t expires, const char *reason) | |
2387 | { | |
2388 | struct trusted_host *th; | |
2389 | th = calloc(1, sizeof(*th)); | |
2390 | if (!th) | |
2391 | return; | |
2392 | th->ipaddr = strdup(ipaddr); | |
2393 | th->reason = reason ? strdup(reason) : NULL; | |
2394 | th->issuer = issuer ? strdup(issuer) : NULL; | |
2395 | th->issued = issued; | |
2396 | th->limit = limit; | |
2397 | th->expires = expires; | |
2398 | dict_insert(opserv_trusted_hosts, th->ipaddr, th); | |
2399 | if (th->expires) | |
2400 | timeq_add(th->expires, opserv_expire_trusted_host, th); | |
2401 | } | |
2402 | ||
2403 | static void | |
2404 | free_trusted_host(void *data) | |
2405 | { | |
2406 | struct trusted_host *th = data; | |
2407 | free(th->ipaddr); | |
2408 | free(th->reason); | |
2409 | free(th->issuer); | |
2410 | free(th); | |
2411 | } | |
2412 | ||
2413 | static MODCMD_FUNC(cmd_addtrust) | |
2414 | { | |
2415 | unsigned long interval; | |
2416 | char *reason, *tmp; | |
2417 | struct in_addr tmpaddr; | |
2418 | unsigned int count; | |
2419 | ||
2420 | if (dict_find(opserv_trusted_hosts, argv[1], NULL)) { | |
2421 | reply("OSMSG_ALREADY_TRUSTED", argv[1]); | |
2422 | return 0; | |
2423 | } | |
2424 | ||
2425 | if (!inet_aton(argv[1], &tmpaddr)) { | |
2426 | reply("OSMSG_BAD_IP", argv[1]); | |
2427 | return 0; | |
2428 | } | |
2429 | ||
2430 | count = strtoul(argv[2], &tmp, 10); | |
2431 | if (*tmp != '\0') { | |
2432 | reply("OSMSG_BAD_NUMBER", argv[2]); | |
2433 | return 0; | |
2434 | } | |
2435 | ||
2436 | interval = ParseInterval(argv[3]); | |
2437 | if (!interval && strcmp(argv[3], "0")) { | |
2438 | reply("MSG_INVALID_DURATION", argv[3]); | |
2439 | return 0; | |
2440 | } | |
2441 | ||
2442 | reason = unsplit_string(argv+4, argc-4, NULL); | |
2443 | opserv_add_trusted_host(argv[1], count, user->handle_info->handle, now, interval ? (now + interval) : 0, reason); | |
2444 | reply("OSMSG_ADDED_TRUSTED"); | |
2445 | return 1; | |
2446 | } | |
2447 | ||
2448 | static MODCMD_FUNC(cmd_edittrust) | |
2449 | { | |
2450 | unsigned long interval; | |
2451 | struct trusted_host *th; | |
2452 | char *reason, *tmp; | |
2453 | unsigned int count; | |
2454 | ||
2455 | th = dict_find(opserv_trusted_hosts, argv[1], NULL); | |
2456 | if (!th) { | |
2457 | reply("OSMSG_NOT_TRUSTED", argv[1]); | |
2458 | return 0; | |
2459 | } | |
2460 | count = strtoul(argv[2], &tmp, 10); | |
2461 | if (!count || *tmp) { | |
2462 | reply("OSMSG_BAD_NUMBER", argv[2]); | |
2463 | return 0; | |
2464 | } | |
2465 | interval = ParseInterval(argv[3]); | |
2466 | if (!interval && strcmp(argv[3], "0")) { | |
2467 | reply("MSG_INVALID_DURATION", argv[3]); | |
2468 | return 0; | |
2469 | } | |
2470 | reason = unsplit_string(argv+4, argc-4, NULL); | |
2471 | if (th->expires) | |
2472 | timeq_del(th->expires, opserv_expire_trusted_host, th, 0); | |
2473 | ||
2474 | free(th->reason); | |
2475 | th->reason = strdup(reason); | |
2476 | free(th->issuer); | |
2477 | th->issuer = strdup(user->handle_info->handle); | |
2478 | th->issued = now; | |
2479 | th->limit = count; | |
2480 | if (interval) { | |
2481 | th->expires = now + interval; | |
2482 | timeq_add(th->expires, opserv_expire_trusted_host, th); | |
2483 | } else | |
2484 | th->expires = 0; | |
2485 | reply("OSMSG_UPDATED_TRUSTED", th->ipaddr); | |
2486 | return 1; | |
2487 | } | |
2488 | ||
2489 | static MODCMD_FUNC(cmd_deltrust) | |
2490 | { | |
2491 | unsigned int n; | |
2492 | ||
2493 | for (n=1; n<argc; n++) { | |
2494 | struct trusted_host *th = dict_find(opserv_trusted_hosts, argv[n], NULL); | |
2495 | if (!th) | |
2496 | continue; | |
2497 | if (th->expires) | |
2498 | timeq_del(th->expires, opserv_expire_trusted_host, th, 0); | |
2499 | dict_remove(opserv_trusted_hosts, argv[n]); | |
2500 | } | |
2501 | reply("OSMSG_REMOVED_TRUSTED"); | |
2502 | return 1; | |
2503 | } | |
2504 | ||
2505 | /* This doesn't use dict_t because it's a little simpler to open-code the | |
2506 | * comparisons (and simpler arg-passing for the ADD subcommand). | |
2507 | */ | |
2508 | static MODCMD_FUNC(cmd_clone) | |
2509 | { | |
2510 | int i; | |
2511 | struct userNode *clone; | |
2512 | ||
2513 | clone = GetUserH(argv[2]); | |
2514 | if (!irccasecmp(argv[1], "ADD")) { | |
2515 | char *userinfo; | |
2516 | char ident[USERLEN+1]; | |
2517 | ||
258d1427 AS |
2518 | if (argc < 5) { |
2519 | reply("MSG_MISSING_PARAMS", argv[1]); | |
2520 | OPSERV_SYNTAX(); | |
2521 | return 0; | |
2522 | } | |
2523 | if (clone) { | |
2524 | reply("OSMSG_CLONE_EXISTS", argv[2]); | |
2525 | return 0; | |
2526 | } | |
2527 | userinfo = unsplit_string(argv+4, argc-4, NULL); | |
2528 | for (i=0; argv[3][i] && (i<USERLEN); i++) { | |
2529 | if (argv[3][i] == '@') { | |
2530 | ident[i++] = 0; | |
2531 | break; | |
2532 | } else { | |
d76ed9a9 AS |
2533 | ident[i] = argv[3][i]; |
2534 | } | |
258d1427 AS |
2535 | } |
2536 | if (!argv[3][i] || (i==USERLEN)) { | |
2537 | reply("OSMSG_NOT_A_HOSTMASK"); | |
2538 | return 0; | |
2539 | } | |
2540 | if (!(clone = AddClone(argv[2], ident, argv[3]+i, userinfo))) { | |
d76ed9a9 AS |
2541 | reply("OSMSG_CLONE_FAILED", argv[2]); |
2542 | return 0; | |
2543 | } | |
2544 | reply("OSMSG_CLONE_ADDED", clone->nick); | |
258d1427 | 2545 | return 1; |
d76ed9a9 AS |
2546 | } |
2547 | if (!clone) { | |
258d1427 AS |
2548 | reply("MSG_NICK_UNKNOWN", argv[2]); |
2549 | return 0; | |
d76ed9a9 AS |
2550 | } |
2551 | if (clone->uplink != self || IsService(clone)) { | |
258d1427 AS |
2552 | reply("OSMSG_NOT_A_CLONE", clone->nick); |
2553 | return 0; | |
d76ed9a9 AS |
2554 | } |
2555 | if (!irccasecmp(argv[1], "REMOVE")) { | |
258d1427 AS |
2556 | const char *reason; |
2557 | if (argc > 3) { | |
2558 | reason = unsplit_string(argv+3, argc-3, NULL); | |
2559 | } else { | |
2560 | char *tmp; | |
2561 | tmp = alloca(strlen(clone->nick) + strlen(OSMSG_PART_REASON)); | |
2562 | sprintf(tmp, OSMSG_PART_REASON, clone->nick); | |
2563 | reason = tmp; | |
2564 | } | |
2565 | DelUser(clone, NULL, 1, reason); | |
2566 | reply("OSMSG_CLONE_REMOVED", argv[2]); | |
2567 | return 1; | |
d76ed9a9 AS |
2568 | } |
2569 | if (argc < 4) { | |
258d1427 AS |
2570 | reply("MSG_MISSING_PARAMS", argv[1]); |
2571 | OPSERV_SYNTAX(); | |
2572 | return 0; | |
d76ed9a9 AS |
2573 | } |
2574 | channel = GetChannel(argv[3]); | |
2575 | if (!irccasecmp(argv[1], "JOIN")) { | |
258d1427 AS |
2576 | if (!channel |
2577 | && !(channel = AddChannel(argv[3], now, NULL, NULL, NULL))) { | |
2578 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
2579 | return 0; | |
2580 | } | |
2581 | AddChannelUser(clone, channel); | |
2582 | reply("OSMSG_CLONE_JOINED", clone->nick, channel->name); | |
2583 | return 1; | |
d76ed9a9 AS |
2584 | } |
2585 | if (!irccasecmp(argv[1], "PART")) { | |
258d1427 AS |
2586 | if (!channel) { |
2587 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
2588 | return 0; | |
2589 | } | |
2590 | if (!GetUserMode(channel, clone)) { | |
2591 | reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); | |
2592 | return 0; | |
2593 | } | |
2594 | reply("OSMSG_CLONE_PARTED", clone->nick, channel->name); | |
2595 | DelChannelUser(clone, channel, "Leaving.", 0); | |
2596 | return 1; | |
d76ed9a9 AS |
2597 | } |
2598 | if (!irccasecmp(argv[1], "OP")) { | |
2599 | struct mod_chanmode change; | |
258d1427 AS |
2600 | if (!channel) { |
2601 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
2602 | return 0; | |
2603 | } | |
d76ed9a9 AS |
2604 | mod_chanmode_init(&change); |
2605 | change.argc = 1; | |
2606 | change.args[0].mode = MODE_CHANOP; | |
a32da4c7 | 2607 | change.args[0].u.member = GetUserMode(channel, clone); |
2608 | if (!change.args[0].u.member) { | |
d76ed9a9 AS |
2609 | reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); |
2610 | return 0; | |
258d1427 | 2611 | } |
d76ed9a9 | 2612 | modcmd_chanmode_announce(&change); |
258d1427 AS |
2613 | reply("OSMSG_OPS_GIVEN", channel->name, clone->nick); |
2614 | return 1; | |
d76ed9a9 | 2615 | } |
55342ce8 | 2616 | if (!irccasecmp(argv[1], "HOP")) { |
2617 | struct mod_chanmode change; | |
2618 | if (!channel) { | |
2619 | reply("MSG_CHANNEL_UNKNOWN", argv[3]); | |
2620 | return 0; | |
2621 | } | |
2622 | mod_chanmode_init(&change); | |
2623 | change.argc = 1; | |
2624 | change.args[0].mode = MODE_HALFOP; | |
11408ce4 AS |
2625 | change.args[0].u.member = GetUserMode(channel, clone); |
2626 | if (!change.args[0].u.member) { | |
55342ce8 | 2627 | reply("OSMSG_NOT_ON_CHANNEL", clone->nick, channel->name); |
2628 | return 0; | |
2629 | } | |
2630 | modcmd_chanmode_announce(&change); | |
2631 | reply("OSMSG_HOPS_GIVEN", channel->name, clone->nick); | |
2632 | return 1; | |
2633 | } | |
d76ed9a9 | 2634 | if (argc < 5) { |
258d1427 AS |
2635 | reply("MSG_MISSING_PARAMS", argv[1]); |
2636 | OPSERV_SYNTAX(); | |
2637 | return 0; | |
d76ed9a9 AS |
2638 | } |
2639 | if (!irccasecmp(argv[1], "SAY")) { | |
258d1427 AS |
2640 | char *text = unsplit_string(argv+4, argc-4, NULL); |
2641 | irc_privmsg(clone, argv[3], text); | |
2642 | reply("OSMSG_CLONE_SAID", clone->nick, argv[3]); | |
2643 | return 1; | |
d76ed9a9 AS |
2644 | } |
2645 | reply("OSMSG_UNKNOWN_SUBCOMMAND", argv[1], argv[0]); | |
2646 | return 0; | |
2647 | } | |
2648 | ||
2649 | static struct helpfile_expansion | |
2650 | opserv_help_expand(const char *variable) | |
2651 | { | |
2652 | extern struct userNode *message_source; | |
2653 | struct helpfile_expansion exp; | |
2654 | struct service *service; | |
2655 | struct svccmd *cmd; | |
2656 | dict_iterator_t it; | |
2657 | int row; | |
2658 | unsigned int level; | |
2659 | ||
2660 | if (!(service = service_find(message_source->nick))) { | |
2661 | exp.type = HF_STRING; | |
2662 | exp.value.str = NULL; | |
2663 | } else if (!irccasecmp(variable, "index")) { | |
2664 | exp.type = HF_TABLE; | |
2665 | exp.value.table.length = 1; | |
2666 | exp.value.table.width = 2; | |
2667 | exp.value.table.flags = TABLE_REPEAT_HEADERS | TABLE_REPEAT_ROWS; | |
2668 | exp.value.table.contents = calloc(dict_size(service->commands)+1, sizeof(char**)); | |
2669 | exp.value.table.contents[0] = calloc(exp.value.table.width, sizeof(char*)); | |
2670 | exp.value.table.contents[0][0] = "Command"; | |
2671 | exp.value.table.contents[0][1] = "Level"; | |
2672 | for (it=dict_first(service->commands); it; it=iter_next(it)) { | |
2673 | cmd = iter_data(it); | |
2674 | row = exp.value.table.length++; | |
2675 | exp.value.table.contents[row] = calloc(exp.value.table.width, sizeof(char*)); | |
2676 | exp.value.table.contents[row][0] = iter_key(it); | |
2677 | level = cmd->min_opserv_level; | |
2678 | if (!level_strings[level]) { | |
2679 | level_strings[level] = malloc(16); | |
2680 | snprintf(level_strings[level], 16, "%3d", level); | |
2681 | } | |
2682 | exp.value.table.contents[row][1] = level_strings[level]; | |
2683 | } | |
2684 | } else if (!strncasecmp(variable, "level", 5)) { | |
2685 | cmd = dict_find(service->commands, variable+6, NULL); | |
2686 | exp.type = HF_STRING; | |
2687 | if (cmd) { | |
2688 | level = cmd->min_opserv_level; | |
2689 | exp.value.str = malloc(16); | |
2690 | snprintf(exp.value.str, 16, "%3d", level); | |
2691 | } else { | |
2692 | exp.value.str = NULL; | |
2693 | } | |
2694 | } else { | |
2695 | exp.type = HF_STRING; | |
2696 | exp.value.str = NULL; | |
2697 | } | |
2698 | return exp; | |
2699 | } | |
2700 | ||
2701 | struct modcmd * | |
2702 | opserv_define_func(const char *name, modcmd_func_t *func, int min_level, int reqchan, int min_argc) | |
2703 | { | |
2704 | char buf[16], *flags = NULL; | |
2705 | unsigned int iflags = 0; | |
2706 | sprintf(buf, "%d", min_level); | |
2707 | switch (reqchan) { | |
2708 | case 1: flags = "+acceptchan"; break; | |
2709 | case 3: flags = "+acceptpluschan"; /* fall through */ | |
2710 | case 2: iflags = MODCMD_REQUIRE_CHANNEL; break; | |
2711 | } | |
2712 | if (flags) { | |
2713 | return modcmd_register(opserv_module, name, func, min_argc, iflags, "level", buf, "flags", flags, "flags", "+oper", NULL); | |
2714 | } else { | |
2715 | return modcmd_register(opserv_module, name, func, min_argc, iflags, "level", buf, "flags", "+oper", NULL); | |
2716 | } | |
2717 | } | |
2718 | ||
2719 | int add_reserved(const char *key, void *data, void *extra) | |
2720 | { | |
2721 | struct record_data *rd = data; | |
2722 | const char *ident, *hostname, *desc; | |
2723 | struct userNode *reserve; | |
2724 | ident = database_get_data(rd->d.object, KEY_IDENT, RECDB_QSTRING); | |
2725 | if (!ident) { | |
258d1427 AS |
2726 | log_module(OS_LOG, LOG_ERROR, "Missing ident for reserve of %s", key); |
2727 | return 0; | |
d76ed9a9 AS |
2728 | } |
2729 | hostname = database_get_data(rd->d.object, KEY_HOSTNAME, RECDB_QSTRING); | |
2730 | if (!hostname) { | |
258d1427 AS |
2731 | log_module(OS_LOG, LOG_ERROR, "Missing hostname for reserve of %s", key); |
2732 | return 0; | |
d76ed9a9 AS |
2733 | } |
2734 | desc = database_get_data(rd->d.object, KEY_DESC, RECDB_QSTRING); | |
2735 | if (!desc) { | |
258d1427 AS |
2736 | log_module(OS_LOG, LOG_ERROR, "Missing description for reserve of %s", key); |
2737 | return 0; | |
d76ed9a9 AS |
2738 | } |
2739 | if ((reserve = AddClone(key, ident, hostname, desc))) { | |
2740 | reserve->modes |= FLAGS_PERSISTENT; | |
2741 | dict_insert(extra, reserve->nick, reserve); | |
2742 | } | |
2743 | return 0; | |
2744 | } | |
2745 | ||
2746 | static unsigned int | |
2747 | foreach_matching_user(const char *hostmask, discrim_search_func func, void *extra) | |
2748 | { | |
2749 | discrim_t discrim; | |
2750 | char *dupmask; | |
2751 | unsigned int matched; | |
2752 | ||
2753 | if (!self->uplink) return 0; | |
2754 | discrim = calloc(1, sizeof(*discrim)); | |
2755 | discrim->limit = dict_size(clients); | |
2756 | discrim->max_level = ~0; | |
2757 | discrim->max_ts = now; | |
2758 | discrim->max_channels = INT_MAX; | |
2759 | discrim->authed = -1; | |
2760 | discrim->info_space = -1; | |
63665495 | 2761 | discrim->intra_scmp = 0; |
2762 | discrim->intra_dcmp = 0; | |
27eaa617 | 2763 | discrim->use_regex = 0; |
d76ed9a9 AS |
2764 | dupmask = strdup(hostmask); |
2765 | if (split_ircmask(dupmask, &discrim->mask_nick, &discrim->mask_ident, &discrim->mask_host)) { | |
2766 | if (discrim->mask_host && !discrim->mask_host[strspn(discrim->mask_host, "0123456789.?*")]) { | |
2767 | if (!parse_ipmask(discrim->mask_host, &discrim->ip_addr, &discrim->ip_mask)) { | |
2768 | log_module(OS_LOG, LOG_ERROR, "Couldn't parse %s as an IP mask!", discrim->mask_host); | |
2769 | free(discrim); | |
2770 | free(dupmask); | |
2771 | return 0; | |
2772 | } | |
2773 | discrim->mask_host = 0; | |
2774 | } | |
2775 | matched = opserv_discrim_search(discrim, func, extra); | |
2776 | } else { | |
258d1427 | 2777 | log_module(OS_LOG, LOG_ERROR, "Couldn't split IRC mask for gag %s!", hostmask); |
d76ed9a9 AS |
2778 | matched = 0; |
2779 | } | |
2780 | free(discrim); | |
2781 | free(dupmask); | |
2782 | return matched; | |
2783 | } | |
2784 | ||
2785 | static unsigned int | |
2786 | gag_free(struct gag_entry *gag) | |
2787 | { | |
2788 | unsigned int ungagged; | |
2789 | ||
2790 | /* Remove from gag list */ | |
2791 | if (gagList == gag) { | |
2792 | gagList = gag->next; | |
2793 | } else { | |
2794 | struct gag_entry *prev; | |
2795 | for (prev = gagList; prev->next != gag; prev = prev->next) ; | |
2796 | prev->next = gag->next; | |
2797 | } | |
2798 | ||
2799 | ungagged = foreach_matching_user(gag->mask, ungag_helper_func, NULL); | |
2800 | ||
2801 | /* Deallocate storage */ | |
2802 | free(gag->reason); | |
2803 | free(gag->owner); | |
2804 | free(gag->mask); | |
2805 | free(gag); | |
2806 | ||
2807 | return ungagged; | |
2808 | } | |
2809 | ||
2810 | static void | |
2811 | gag_expire(void *data) | |
2812 | { | |
2813 | gag_free(data); | |
2814 | } | |
2815 | ||
2816 | unsigned int | |
2817 | gag_create(const char *mask, const char *owner, const char *reason, time_t expires) | |
2818 | { | |
2819 | struct gag_entry *gag; | |
2820 | ||
2821 | /* Create gag and put it into linked list */ | |
2822 | gag = calloc(1, sizeof(*gag)); | |
2823 | gag->mask = strdup(mask); | |
2824 | gag->owner = strdup(owner ? owner : "<unknown>"); | |
2825 | gag->reason = strdup(reason ? reason : "<unknown>"); | |
2826 | gag->expires = expires; | |
2827 | if (gag->expires) | |
2828 | timeq_add(gag->expires, gag_expire, gag); | |
2829 | gag->next = gagList; | |
2830 | gagList = gag; | |
2831 | ||
2832 | /* If we're linked, see if who the gag applies to */ | |
2833 | return foreach_matching_user(mask, gag_helper_func, gag); | |
2834 | } | |
2835 | ||
2836 | static int | |
2837 | add_gag_helper(const char *key, void *data, UNUSED_ARG(void *extra)) | |
2838 | { | |
2839 | struct record_data *rd = data; | |
2840 | char *owner, *reason, *expstr; | |
2841 | time_t expires; | |
2842 | ||
2843 | owner = database_get_data(rd->d.object, KEY_OWNER, RECDB_QSTRING); | |
2844 | reason = database_get_data(rd->d.object, KEY_REASON, RECDB_QSTRING); | |
2845 | expstr = database_get_data(rd->d.object, KEY_EXPIRES, RECDB_QSTRING); | |
2846 | expires = expstr ? strtoul(expstr, NULL, 0) : 0; | |
2847 | gag_create(key, owner, reason, expires); | |
2848 | ||
2849 | return 0; | |
2850 | } | |
2851 | ||
2852 | static struct opserv_user_alert * | |
2853 | opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_reaction reaction, const char *text_discrim) | |
2854 | { | |
2855 | unsigned int wordc; | |
2856 | char *wordv[MAXNUMPARAMS], *discrim_copy; | |
2857 | struct opserv_user_alert *alert; | |
2858 | char *name_dup; | |
2859 | ||
2860 | if (dict_find(opserv_user_alerts, name, NULL)) { | |
258d1427 AS |
2861 | send_message(req, opserv, "OSMSG_ALERT_EXISTS", name); |
2862 | return NULL; | |
d76ed9a9 AS |
2863 | } |
2864 | alert = malloc(sizeof(*alert)); | |
2865 | alert->owner = strdup(req->handle_info ? req->handle_info->handle : req->nick); | |
2866 | alert->text_discrim = strdup(text_discrim); | |
2867 | discrim_copy = strdup(text_discrim); /* save a copy of the discrim */ | |
2868 | wordc = split_line(discrim_copy, false, ArrayLength(wordv), wordv); | |
258d1427 | 2869 | alert->discrim = opserv_discrim_create(req, opserv, wordc, wordv, 0); |
d76ed9a9 AS |
2870 | if (!alert->discrim) { |
2871 | free(alert->text_discrim); | |
2872 | free(discrim_copy); | |
2873 | free(alert); | |
2874 | return NULL; | |
2875 | } | |
2876 | alert->split_discrim = discrim_copy; | |
2877 | name_dup = strdup(name); | |
2878 | if (!alert->discrim->reason) | |
2879 | alert->discrim->reason = strdup(name); | |
2880 | alert->reaction = reaction; | |
2881 | dict_insert(opserv_user_alerts, name_dup, alert); | |
697f4c9a | 2882 | /* Stick the alert into the appropriate additional alert dict(s). |
2883 | * For channel alerts, we only use channels and min_channels; | |
2884 | * max_channels would have to be checked on /part, which we do not | |
2885 | * yet do, and which seems of questionable value. | |
2886 | */ | |
2887 | if (alert->discrim->channel || alert->discrim->min_channels) | |
d76ed9a9 | 2888 | dict_insert(opserv_channel_alerts, name_dup, alert); |
697f4c9a | 2889 | if (alert->discrim->mask_nick) |
d76ed9a9 AS |
2890 | dict_insert(opserv_nick_based_alerts, name_dup, alert); |
2891 | return alert; | |
2892 | } | |
2893 | ||
de9510bc | 2894 | /* |
d76ed9a9 AS |
2895 | static int |
2896 | add_chan_warn(const char *key, void *data, UNUSED_ARG(void *extra)) | |
2897 | { | |
2898 | struct record_data *rd = data; | |
2899 | char *reason = GET_RECORD_QSTRING(rd); | |
2900 | ||
de9510bc | 2901 | * i hope this can't happen * |
d76ed9a9 AS |
2902 | if (!reason) |
2903 | reason = "No Reason"; | |
2904 | ||
2905 | dict_insert(opserv_chan_warn, strdup(key), strdup(reason)); | |
2906 | return 0; | |
2907 | } | |
de9510bc | 2908 | */ |
d76ed9a9 AS |
2909 | |
2910 | static int | |
2911 | add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) | |
2912 | { | |
2913 | dict_t alert_dict; | |
2914 | const char *discrim, *react, *owner; | |
2915 | opserv_alert_reaction reaction; | |
2916 | struct opserv_user_alert *alert; | |
2917 | ||
2918 | if (!(alert_dict = GET_RECORD_OBJECT((struct record_data *)data))) { | |
2919 | log_module(OS_LOG, LOG_ERROR, "Bad type (not a record) for alert %s.", key); | |
2920 | return 1; | |
2921 | } | |
2922 | discrim = database_get_data(alert_dict, KEY_DISCRIM, RECDB_QSTRING); | |
2923 | react = database_get_data(alert_dict, KEY_REACTION, RECDB_QSTRING); | |
2924 | if (!react || !irccasecmp(react, "notice")) | |
2925 | reaction = REACT_NOTICE; | |
2926 | else if (!irccasecmp(react, "kill")) | |
2927 | reaction = REACT_KILL; | |
9a75756e | 2928 | else if (!irccasecmp(react, "silent")) |
2929 | reaction = REACT_SILENT; | |
d76ed9a9 AS |
2930 | else if (!irccasecmp(react, "gline")) |
2931 | reaction = REACT_GLINE; | |
d914d1cb | 2932 | else if (!irccasecmp(react, "shun")) |
2933 | reaction = REACT_SHUN; | |
d76ed9a9 AS |
2934 | else { |
2935 | log_module(OS_LOG, LOG_ERROR, "Invalid reaction %s for alert %s.", react, key); | |
2936 | return 0; | |
2937 | } | |
2938 | alert = opserv_add_user_alert(opserv, key, reaction, discrim); | |
2939 | if (!alert) { | |
2940 | log_module(OS_LOG, LOG_ERROR, "Unable to create alert %s from database.", key); | |
2941 | return 0; | |
2942 | } | |
2943 | owner = database_get_data(alert_dict, KEY_OWNER, RECDB_QSTRING); | |
2944 | free(alert->owner); | |
2945 | alert->owner = strdup(owner ? owner : "<unknown>"); | |
2946 | return 0; | |
2947 | } | |
2948 | ||
2949 | static int | |
2950 | trusted_host_read(const char *host, void *data, UNUSED_ARG(void *extra)) | |
2951 | { | |
2952 | struct record_data *rd = data; | |
2953 | const char *limit, *str, *reason, *issuer; | |
2954 | time_t issued, expires; | |
2955 | ||
2956 | if (rd->type == RECDB_QSTRING) { | |
2957 | /* old style host by itself */ | |
2958 | limit = GET_RECORD_QSTRING(rd); | |
2959 | issued = 0; | |
2960 | issuer = NULL; | |
2961 | expires = 0; | |
2962 | reason = NULL; | |
2963 | } else if (rd->type == RECDB_OBJECT) { | |
2964 | dict_t obj = GET_RECORD_OBJECT(rd); | |
2965 | /* new style structure */ | |
2966 | limit = database_get_data(obj, KEY_LIMIT, RECDB_QSTRING); | |
2967 | str = database_get_data(obj, KEY_EXPIRES, RECDB_QSTRING); | |
2968 | expires = str ? ParseInterval(str) : 0; | |
2969 | reason = database_get_data(obj, KEY_REASON, RECDB_QSTRING); | |
2970 | issuer = database_get_data(obj, KEY_ISSUER, RECDB_QSTRING); | |
2971 | str = database_get_data(obj, KEY_ISSUED, RECDB_QSTRING); | |
2972 | issued = str ? ParseInterval(str) : 0; | |
2973 | } else | |
2974 | return 0; | |
2975 | ||
2976 | if (expires && (expires < now)) | |
2977 | return 0; | |
2978 | opserv_add_trusted_host(host, (limit ? strtoul(limit, NULL, 0) : 0), issuer, issued, expires, reason); | |
2979 | return 0; | |
2980 | } | |
2981 | ||
2982 | static int | |
2983 | opserv_saxdb_read(struct dict *conf_db) | |
2984 | { | |
2985 | dict_t object; | |
2986 | struct record_data *rd; | |
2987 | dict_iterator_t it; | |
2988 | unsigned int nn; | |
2989 | ||
2990 | if ((object = database_get_data(conf_db, KEY_RESERVES, RECDB_OBJECT))) | |
2991 | dict_foreach(object, add_reserved, opserv_reserved_nick_dict); | |
2992 | if ((rd = database_get_path(conf_db, KEY_BAD_WORDS))) { | |
2993 | switch (rd->type) { | |
2994 | case RECDB_STRING_LIST: | |
2995 | /* Add words one by one just in case there are overlaps from an old DB. */ | |
2996 | for (nn=0; nn<rd->d.slist->used; ++nn) | |
2997 | opserv_add_bad_word(NULL, NULL, rd->d.slist->list[nn]); | |
2998 | break; | |
2999 | case RECDB_OBJECT: | |
3000 | for (it=dict_first(rd->d.object); it; it=iter_next(it)) { | |
3001 | opserv_add_bad_word(NULL, NULL, iter_key(it)); | |
3002 | rd = iter_data(it); | |
3003 | if (rd->type == RECDB_STRING_LIST) | |
3004 | for (nn=0; nn<rd->d.slist->used; nn++) | |
3005 | dict_insert(opserv_exempt_channels, strdup(rd->d.slist->list[nn]), NULL); | |
3006 | } | |
3007 | break; | |
3008 | default: | |
3009 | /* do nothing */; | |
3010 | } | |
3011 | } | |
3012 | if ((rd = database_get_path(conf_db, KEY_EXEMPT_CHANNELS)) | |
3013 | && (rd->type == RECDB_STRING_LIST)) { | |
3014 | for (nn=0; nn<rd->d.slist->used; ++nn) | |
3015 | dict_insert(opserv_exempt_channels, strdup(rd->d.slist->list[nn]), NULL); | |
3016 | } | |
3017 | if ((object = database_get_data(conf_db, KEY_MAX_CLIENTS, RECDB_OBJECT))) { | |
3018 | char *str; | |
3019 | if ((str = database_get_data(object, KEY_MAX, RECDB_QSTRING))) | |
3020 | max_clients = atoi(str); | |
3021 | if ((str = database_get_data(object, KEY_TIME, RECDB_QSTRING))) | |
3022 | max_clients_time = atoi(str); | |
3023 | } | |
3024 | if ((object = database_get_data(conf_db, KEY_TRUSTED_HOSTS, RECDB_OBJECT))) | |
3025 | dict_foreach(object, trusted_host_read, opserv_trusted_hosts); | |
3026 | if ((object = database_get_data(conf_db, KEY_GAGS, RECDB_OBJECT))) | |
3027 | dict_foreach(object, add_gag_helper, NULL); | |
3028 | if ((object = database_get_data(conf_db, KEY_ALERTS, RECDB_OBJECT))) | |
3029 | dict_foreach(object, add_user_alert, NULL); | |
de9510bc | 3030 | /* |
d76ed9a9 AS |
3031 | if ((object = database_get_data(conf_db, KEY_WARN, RECDB_OBJECT))) |
3032 | dict_foreach(object, add_chan_warn, NULL); | |
de9510bc | 3033 | */ |
d76ed9a9 AS |
3034 | return 0; |
3035 | } | |
3036 | ||
3037 | static int | |
3038 | opserv_saxdb_write(struct saxdb_context *ctx) | |
3039 | { | |
3040 | struct string_list *slist; | |
3041 | dict_iterator_t it; | |
3042 | ||
3043 | /* reserved nicks */ | |
3044 | if (dict_size(opserv_reserved_nick_dict)) { | |
3045 | saxdb_start_record(ctx, KEY_RESERVES, 1); | |
3046 | for (it = dict_first(opserv_reserved_nick_dict); it; it = iter_next(it)) { | |
3047 | struct userNode *user = iter_data(it); | |
3048 | if (!IsPersistent(user)) continue; | |
3049 | saxdb_start_record(ctx, iter_key(it), 0); | |
3050 | saxdb_write_string(ctx, KEY_IDENT, user->ident); | |
3051 | saxdb_write_string(ctx, KEY_HOSTNAME, user->hostname); | |
3052 | saxdb_write_string(ctx, KEY_DESC, user->info); | |
3053 | saxdb_end_record(ctx); | |
3054 | } | |
3055 | saxdb_end_record(ctx); | |
3056 | } | |
3057 | /* bad word set */ | |
3058 | if (opserv_bad_words->used) { | |
3059 | saxdb_write_string_list(ctx, KEY_BAD_WORDS, opserv_bad_words); | |
3060 | } | |
3061 | /* insert exempt channel names */ | |
3062 | if (dict_size(opserv_exempt_channels)) { | |
3063 | slist = alloc_string_list(dict_size(opserv_exempt_channels)); | |
3064 | for (it=dict_first(opserv_exempt_channels); it; it=iter_next(it)) { | |
3065 | string_list_append(slist, strdup(iter_key(it))); | |
3066 | } | |
3067 | saxdb_write_string_list(ctx, KEY_EXEMPT_CHANNELS, slist); | |
3068 | free_string_list(slist); | |
3069 | } | |
3070 | /* trusted hosts takes a little more work */ | |
3071 | if (dict_size(opserv_trusted_hosts)) { | |
3072 | saxdb_start_record(ctx, KEY_TRUSTED_HOSTS, 1); | |
3073 | for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) { | |
3074 | struct trusted_host *th = iter_data(it); | |
3075 | saxdb_start_record(ctx, iter_key(it), 0); | |
3076 | if (th->limit) saxdb_write_int(ctx, KEY_LIMIT, th->limit); | |
3077 | if (th->expires) saxdb_write_int(ctx, KEY_EXPIRES, th->expires); | |
3078 | if (th->issued) saxdb_write_int(ctx, KEY_ISSUED, th->issued); | |
3079 | if (th->issuer) saxdb_write_string(ctx, KEY_ISSUER, th->issuer); | |
3080 | if (th->reason) saxdb_write_string(ctx, KEY_REASON, th->reason); | |
3081 | saxdb_end_record(ctx); | |
3082 | } | |
3083 | saxdb_end_record(ctx); | |
3084 | } | |
3085 | /* gags */ | |
3086 | if (gagList) { | |
3087 | struct gag_entry *gag; | |
3088 | saxdb_start_record(ctx, KEY_GAGS, 1); | |
3089 | for (gag = gagList; gag; gag = gag->next) { | |
3090 | saxdb_start_record(ctx, gag->mask, 0); | |
3091 | saxdb_write_string(ctx, KEY_OWNER, gag->owner); | |
3092 | saxdb_write_string(ctx, KEY_REASON, gag->reason); | |
3093 | if (gag->expires) saxdb_write_int(ctx, KEY_EXPIRES, gag->expires); | |
3094 | saxdb_end_record(ctx); | |
3095 | } | |
3096 | saxdb_end_record(ctx); | |
3097 | } | |
3098 | /* channel warnings */ | |
de9510bc | 3099 | /* |
d76ed9a9 AS |
3100 | if (dict_size(opserv_chan_warn)) { |
3101 | saxdb_start_record(ctx, KEY_WARN, 0); | |
3102 | for (it = dict_first(opserv_chan_warn); it; it = iter_next(it)) { | |
3103 | saxdb_write_string(ctx, iter_key(it), iter_data(it)); | |
3104 | } | |
3105 | saxdb_end_record(ctx); | |
3106 | } | |
de9510bc | 3107 | */ |
d76ed9a9 AS |
3108 | /* alerts */ |
3109 | if (dict_size(opserv_user_alerts)) { | |
3110 | saxdb_start_record(ctx, KEY_ALERTS, 1); | |
3111 | for (it = dict_first(opserv_user_alerts); it; it = iter_next(it)) { | |
3112 | struct opserv_user_alert *alert = iter_data(it); | |
3113 | const char *reaction; | |
3114 | saxdb_start_record(ctx, iter_key(it), 0); | |
3115 | saxdb_write_string(ctx, KEY_DISCRIM, alert->text_discrim); | |
3116 | saxdb_write_string(ctx, KEY_OWNER, alert->owner); | |
3117 | switch (alert->reaction) { | |
3118 | case REACT_NOTICE: reaction = "notice"; break; | |
3119 | case REACT_KILL: reaction = "kill"; break; | |
9a75756e | 3120 | case REACT_SILENT: reaction = "silent"; break; |
d76ed9a9 | 3121 | case REACT_GLINE: reaction = "gline"; break; |
d914d1cb | 3122 | case REACT_SHUN: reaction = "shun"; break; |
d76ed9a9 AS |
3123 | default: |
3124 | reaction = NULL; | |
3125 | log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s (while writing database).", alert->reaction, iter_key(it)); | |
3126 | break; | |
3127 | } | |
3128 | if (reaction) saxdb_write_string(ctx, KEY_REACTION, reaction); | |
3129 | saxdb_end_record(ctx); | |
3130 | } | |
3131 | saxdb_end_record(ctx); | |
3132 | } | |
3133 | /* max clients */ | |
3134 | saxdb_start_record(ctx, KEY_MAX_CLIENTS, 0); | |
3135 | saxdb_write_int(ctx, KEY_MAX, max_clients); | |
3136 | saxdb_write_int(ctx, KEY_TIME, max_clients_time); | |
3137 | saxdb_end_record(ctx); | |
3138 | return 0; | |
3139 | } | |
3140 | ||
3141 | static int | |
3142 | query_keys_helper(const char *key, UNUSED_ARG(void *data), void *extra) | |
3143 | { | |
3144 | send_message_type(4, extra, opserv, "$b%s$b", key); | |
3145 | return 0; | |
3146 | } | |
3147 | ||
3148 | static MODCMD_FUNC(cmd_query) | |
3149 | { | |
3150 | struct record_data *rd; | |
3151 | unsigned int i; | |
3152 | char *nodename; | |
3153 | ||
3154 | if (argc < 2) { | |
258d1427 AS |
3155 | reply("OSMSG_OPTION_ROOT"); |
3156 | conf_enum_root(query_keys_helper, user); | |
3157 | return 1; | |
d76ed9a9 AS |
3158 | } |
3159 | ||
3160 | nodename = unsplit_string(argv+1, argc-1, NULL); | |
3161 | if (!(rd = conf_get_node(nodename))) { | |
258d1427 AS |
3162 | reply("OSMSG_UNKNOWN_OPTION", nodename); |
3163 | return 0; | |
d76ed9a9 AS |
3164 | } |
3165 | ||
3166 | if (rd->type == RECDB_QSTRING) | |
258d1427 | 3167 | reply("OSMSG_OPTION_IS", nodename, rd->d.qstring); |
d76ed9a9 | 3168 | else if (rd->type == RECDB_STRING_LIST) { |
258d1427 AS |
3169 | reply("OSMSG_OPTION_LIST", nodename); |
3170 | if (rd->d.slist->used) | |
3171 | for (i=0; i<rd->d.slist->used; i++) | |
3172 | send_message_type(4, user, cmd->parent->bot, "$b%s$b", rd->d.slist->list[i]); | |
3173 | else | |
3174 | reply("OSMSG_OPTION_LIST_EMPTY"); | |
d76ed9a9 | 3175 | } else if (rd->type == RECDB_OBJECT) { |
258d1427 AS |
3176 | reply("OSMSG_OPTION_KEYS", nodename); |
3177 | dict_foreach(rd->d.object, query_keys_helper, user); | |
d76ed9a9 AS |
3178 | } |
3179 | ||
3180 | return 1; | |
3181 | } | |
3182 | ||
3183 | static MODCMD_FUNC(cmd_set) | |
3184 | { | |
3185 | struct record_data *rd; | |
3186 | ||
3187 | /* I originally wanted to be able to fully manipulate the config | |
3188 | db with this, but i wussed out. feel free to fix this - you'll | |
3189 | need to handle quoted strings which have been split, and likely | |
3190 | invent a syntax for it. -Zoot */ | |
3191 | ||
3192 | if (!(rd = conf_get_node(argv[1]))) { | |
258d1427 AS |
3193 | reply("OSMSG_SET_NOT_SET", argv[1]); |
3194 | return 0; | |
d76ed9a9 AS |
3195 | } |
3196 | ||
3197 | if (rd->type != RECDB_QSTRING) { | |
258d1427 AS |
3198 | reply("OSMSG_SET_BAD_TYPE", argv[1]); |
3199 | return 0; | |
d76ed9a9 AS |
3200 | } |
3201 | ||
3202 | free(rd->d.qstring); | |
3203 | rd->d.qstring = strdup(argv[2]); | |
3204 | conf_call_reload_funcs(); | |
3205 | reply("OSMSG_SET_SUCCESS", argv[1], argv[2]); | |
3206 | return 1; | |
3207 | } | |
3208 | ||
3209 | static MODCMD_FUNC(cmd_settime) | |
3210 | { | |
3211 | const char *srv_name_mask = "*"; | |
3212 | time_t new_time = now; | |
3213 | ||
3214 | if (argc > 1) | |
3215 | srv_name_mask = argv[1]; | |
3216 | if (argc > 2) | |
3217 | new_time = time(NULL); | |
3218 | irc_settime(srv_name_mask, new_time); | |
3219 | reply("OSMSG_SETTIME_SUCCESS", srv_name_mask); | |
3220 | return 1; | |
3221 | } | |
3222 | ||
3223 | static discrim_t | |
258d1427 | 3224 | opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[], int allow_channel) |
d76ed9a9 AS |
3225 | { |
3226 | unsigned int i, j; | |
3227 | discrim_t discrim; | |
3228 | ||
3229 | discrim = calloc(1, sizeof(*discrim)); | |
3230 | discrim->limit = 250; | |
3231 | discrim->max_level = ~0; | |
3232 | discrim->max_ts = INT_MAX; | |
3233 | discrim->domain_depth = 2; | |
3234 | discrim->max_channels = INT_MAX; | |
3235 | discrim->authed = -1; | |
3236 | discrim->info_space = -1; | |
63665495 | 3237 | discrim->intra_dcmp = 0; |
3238 | discrim->intra_scmp = 0; | |
d76ed9a9 AS |
3239 | |
3240 | for (i=0; i<argc; i++) { | |
3241 | if (irccasecmp(argv[i], "log") == 0) { | |
3242 | discrim->option_log = 1; | |
3243 | continue; | |
3244 | } | |
3245 | /* Assume all other criteria require arguments. */ | |
3246 | if (i == argc - 1) { | |
258d1427 | 3247 | send_message(user, bot, "MSG_MISSING_PARAMS", argv[i]); |
d76ed9a9 AS |
3248 | goto fail; |
3249 | } | |
63665495 | 3250 | if (argv[i+1][0] == '&') { |
3251 | /* Looking for intra-userNode matches */ | |
3252 | char *tmp = &(argv[i+1][1]); | |
3253 | if (strcasecmp(tmp, argv[i]) != 0) { /* Don't allow "nick &nick" etc */ | |
3254 | if (!strcasecmp(tmp, "nick")) | |
3255 | discrim->intra_dcmp = 1; | |
3256 | else if (!strcasecmp(tmp, "ident")) | |
3257 | discrim->intra_dcmp = 2; | |
3258 | else if (!strcasecmp(tmp, "info")) | |
3259 | discrim->intra_dcmp = 3; | |
3260 | } | |
3261 | } | |
258d1427 AS |
3262 | if (irccasecmp(argv[i], "mask") == 0) { |
3263 | if (!is_ircmask(argv[++i])) { | |
3264 | send_message(user, bot, "OSMSG_INVALID_IRCMASK", argv[i]); | |
3265 | goto fail; | |
3266 | } | |
3267 | if (!split_ircmask(argv[i], | |
d76ed9a9 AS |
3268 | &discrim->mask_nick, |
3269 | &discrim->mask_ident, | |
3270 | &discrim->mask_host)) { | |
258d1427 AS |
3271 | send_message(user, bot, "OSMSG_INVALID_IRCMASK", argv[i]); |
3272 | goto fail; | |
3273 | } | |
3274 | } else if (irccasecmp(argv[i], "nick") == 0) { | |
63665495 | 3275 | i++; |
3276 | if (discrim->intra_dcmp > 0) | |
3277 | discrim->intra_scmp = 1; | |
3278 | else | |
3279 | discrim->mask_nick = argv[i]; | |
258d1427 | 3280 | } else if (irccasecmp(argv[i], "ident") == 0) { |
63665495 | 3281 | i++; |
3282 | if (discrim->intra_dcmp > 0) | |
3283 | discrim->intra_scmp = 2; | |
3284 | else | |
3285 | discrim->mask_ident = argv[i]; | |
258d1427 AS |
3286 | } else if (irccasecmp(argv[i], "host") == 0) { |
3287 | discrim->mask_host = argv[++i]; | |
3288 | } else if (irccasecmp(argv[i], "info") == 0) { | |
63665495 | 3289 | i++; |
3290 | if (discrim->intra_dcmp > 0) | |
3291 | discrim->intra_scmp = 3; | |
3292 | else | |
3293 | discrim->mask_info = argv[i]; | |
258d1427 AS |
3294 | } else if (irccasecmp(argv[i], "server") == 0) { |
3295 | discrim->server = argv[++i]; | |
3296 | } else if (irccasecmp(argv[i], "ip") == 0) { | |
3297 | j = parse_ipmask(argv[++i], &discrim->ip_addr, &discrim->ip_mask); | |
3298 | if (!j) discrim->ip_mask_str = argv[i]; | |
d76ed9a9 AS |
3299 | } else if (irccasecmp(argv[i], "account") == 0) { |
3300 | if (discrim->authed == 0) { | |
258d1427 | 3301 | send_message(user, bot, "OSMSG_ACCOUNTMASK_AUTHED"); |
d76ed9a9 AS |
3302 | goto fail; |
3303 | } | |
3304 | discrim->accountmask = argv[++i]; | |
3305 | discrim->authed = 1; | |
3306 | } else if (irccasecmp(argv[i], "authed") == 0) { | |
3307 | i++; /* true_string and false_string are macros! */ | |
3308 | if (true_string(argv[i])) { | |
3309 | discrim->authed = 1; | |
3310 | } else if (false_string(argv[i])) { | |
3311 | if (discrim->accountmask) { | |
258d1427 | 3312 | send_message(user, bot, "OSMSG_ACCOUNTMASK_AUTHED"); |
d76ed9a9 AS |
3313 | goto fail; |
3314 | } | |
3315 | discrim->authed = 0; | |
3316 | } else { | |
258d1427 | 3317 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); |
d76ed9a9 AS |
3318 | goto fail; |
3319 | } | |
3320 | } else if (irccasecmp(argv[i], "info_space") == 0) { | |
3321 | /* XXX: A hack because you can't check explicitly for a space through | |
3322 | * any other means */ | |
3323 | i++; | |
3324 | if (true_string(argv[i])) { | |
3325 | discrim->info_space = 1; | |
3326 | } else if (false_string(argv[i])) { | |
3327 | discrim->info_space = 0; | |
3328 | } else { | |
258d1427 | 3329 | send_message(user, bot, "MSG_INVALID_BINARY", argv[i]); |
d76ed9a9 AS |
3330 | goto fail; |
3331 | } | |
27eaa617 | 3332 | } else if (irccasecmp(argv[i], "regex") == 0) { |
3333 | i++; | |
3334 | if (true_string(argv[i])) { | |
3335 | discrim->use_regex = 1; | |
3336 | } else if (false_string(argv[i])) { | |
3337 | discrim->use_regex = 0; | |
3338 | } else { | |
3339 | send_message(user, opserv, "MSG_INVALID_BINARY", argv[i]); | |
3340 | goto fail; | |
3341 | } | |
d76ed9a9 AS |
3342 | } else if (irccasecmp(argv[i], "duration") == 0) { |
3343 | discrim->duration = ParseInterval(argv[++i]); | |
258d1427 | 3344 | } else if (irccasecmp(argv[i], "channel") == 0) { |
d76ed9a9 AS |
3345 | for (j=0, i++; ; j++) { |
3346 | switch (argv[i][j]) { | |
3347 | case '#': | |
3348 | goto find_channel; | |
3349 | case '-': | |
55342ce8 | 3350 | discrim->chan_no_modes |= MODE_CHANOP | MODE_HALFOP | MODE_VOICE; |
d76ed9a9 AS |
3351 | break; |
3352 | case '+': | |
3353 | discrim->chan_req_modes |= MODE_VOICE; | |
3354 | discrim->chan_no_modes |= MODE_CHANOP; | |
55342ce8 | 3355 | discrim->chan_no_modes |= MODE_HALFOP; |
3356 | break; | |
3357 | case '%': | |
3358 | discrim->chan_req_modes |= MODE_HALFOP; | |
3359 | discrim->chan_no_modes |= MODE_CHANOP; | |
3360 | discrim->chan_no_modes |= MODE_VOICE; | |
d76ed9a9 AS |
3361 | break; |
3362 | case '@': | |
3363 | discrim->chan_req_modes |= MODE_CHANOP; | |
3364 | break; | |
3365 | case '\0': | |
258d1427 | 3366 | send_message(user, bot, "MSG_NOT_CHANNEL_NAME"); |
d76ed9a9 AS |
3367 | goto fail; |
3368 | } | |
3369 | } | |
3370 | find_channel: | |
3371 | discrim->chan_no_modes &= ~discrim->chan_req_modes; | |
258d1427 | 3372 | if (!(discrim->channel = GetChannel(argv[i]+j))) { |
d76ed9a9 AS |
3373 | /* secretly "allow_channel" now means "if a channel name is |
3374 | * specified, require that it currently exist" */ | |
3375 | if (allow_channel) { | |
258d1427 | 3376 | send_message(user, bot, "MSG_CHANNEL_UNKNOWN", argv[i]); |
d76ed9a9 AS |
3377 | goto fail; |
3378 | } else { | |
2aef5f4b | 3379 | discrim->channel = AddChannel(argv[i]+j, now, NULL, NULL, NULL); |
d76ed9a9 | 3380 | } |
258d1427 | 3381 | } |
d76ed9a9 AS |
3382 | LockChannel(discrim->channel); |
3383 | } else if (irccasecmp(argv[i], "numchannels") == 0) { | |
3384 | discrim->min_channels = discrim->max_channels = strtoul(argv[++i], NULL, 10); | |
258d1427 AS |
3385 | } else if (irccasecmp(argv[i], "limit") == 0) { |
3386 | discrim->limit = strtoul(argv[++i], NULL, 10); | |
d76ed9a9 AS |
3387 | } else if (irccasecmp(argv[i], "reason") == 0) { |
3388 | discrim->reason = strdup(unsplit_string(argv+i+1, argc-i-1, NULL)); | |
3389 | i = argc; | |
3390 | } else if (irccasecmp(argv[i], "last") == 0) { | |
3391 | discrim->min_ts = now - ParseInterval(argv[++i]); | |
3392 | } else if ((irccasecmp(argv[i], "linked") == 0) | |
3393 | || (irccasecmp(argv[i], "nickage") == 0)) { | |
3394 | const char *cmp = argv[++i]; | |
3395 | if (cmp[0] == '<') { | |
3396 | if (cmp[1] == '=') { | |
3397 | discrim->min_ts = now - ParseInterval(cmp+2); | |
3398 | } else { | |
3399 | discrim->min_ts = now - (ParseInterval(cmp+1) - 1); | |
3400 | } | |
3401 | } else if (cmp[0] == '>') { | |
3402 | if (cmp[1] == '=') { | |
3403 | discrim->max_ts = now - ParseInterval(cmp+2); | |
3404 | } else { | |
3405 | discrim->max_ts = now - (ParseInterval(cmp+1) - 1); | |
3406 | } | |
3407 | } else { | |
3408 | discrim->min_ts = now - ParseInterval(cmp+2); | |
3409 | } | |
3410 | } else if (irccasecmp(argv[i], "access") == 0) { | |
3411 | const char *cmp = argv[++i]; | |
3412 | if (cmp[0] == '<') { | |
3413 | if (discrim->min_level == 0) discrim->min_level = 1; | |
3414 | if (cmp[1] == '=') { | |
3415 | discrim->max_level = strtoul(cmp+2, NULL, 0); | |
3416 | } else { | |
3417 | discrim->max_level = strtoul(cmp+1, NULL, 0) - 1; | |
3418 | } | |
3419 | } else if (cmp[0] == '=') { | |
3420 | discrim->min_level = discrim->max_level = strtoul(cmp+1, NULL, 0); | |
3421 | } else if (cmp[0] == '>') { | |
3422 | if (cmp[1] == '=') { | |
3423 | discrim->min_level = strtoul(cmp+2, NULL, 0); | |
3424 | } else { | |
3425 | discrim->min_level = strtoul(cmp+1, NULL, 0) + 1; | |
3426 | } | |
3427 | } else { | |
3428 | discrim->min_level = strtoul(cmp+2, NULL, 0); | |
3429 | } | |
3430 | } else if ((irccasecmp(argv[i], "abuse") == 0) | |
3431 | && (irccasecmp(argv[++i], "opers") == 0)) { | |
3432 | discrim->match_opers = 1; | |
3433 | } else if (irccasecmp(argv[i], "depth") == 0) { | |
3434 | discrim->domain_depth = strtoul(argv[++i], NULL, 0); | |
3435 | } else if (irccasecmp(argv[i], "clones") == 0) { | |
3436 | discrim->min_clones = strtoul(argv[++i], NULL, 0); | |
3437 | } else { | |
258d1427 | 3438 | send_message(user, bot, "MSG_INVALID_CRITERIA", argv[i]); |
d76ed9a9 AS |
3439 | goto fail; |
3440 | } | |
3441 | } | |
3442 | ||
3443 | if (discrim->mask_nick && !strcmp(discrim->mask_nick, "*")) { | |
258d1427 | 3444 | discrim->mask_nick = 0; |
d76ed9a9 AS |
3445 | } |
3446 | if (discrim->mask_ident && !strcmp(discrim->mask_ident, "*")) { | |
3447 | discrim->mask_ident = 0; | |
3448 | } | |
3449 | if (discrim->mask_info && !strcmp(discrim->mask_info, "*")) { | |
258d1427 | 3450 | discrim->mask_info = 0; |
d76ed9a9 AS |
3451 | } |
3452 | if (discrim->mask_host && !discrim->mask_host[strspn(discrim->mask_host, "*.")]) { | |
3453 | discrim->mask_host = 0; | |
3454 | } | |
27eaa617 | 3455 | |
3456 | if(discrim->use_regex) | |
3457 | { | |
3458 | if(discrim->mask_nick) | |
3459 | { | |
3460 | int err = regcomp(&discrim->regex_nick, discrim->mask_nick, REG_EXTENDED|REG_ICASE|REG_NOSUB); | |
3461 | discrim->has_regex_nick = !err; | |
3462 | if(err) | |
3463 | { | |
3464 | char buff[256]; | |
3465 | buff[regerror(err, &discrim->regex_nick, buff, sizeof(buff))] = 0; | |
3466 | ||
3467 | send_message(user, opserv, "OSMSG_INVALID_REGEX", discrim->mask_nick, buff, err); | |
3468 | goto regfail; | |
3469 | } | |
3470 | } | |
3471 | ||
3472 | if(discrim->mask_ident) | |
3473 | { | |
3474 | int err = regcomp(&discrim->regex_ident, discrim->mask_ident, REG_EXTENDED|REG_ICASE|REG_NOSUB); | |
3475 | discrim->has_regex_ident = !err; | |
3476 | if(err) | |
3477 | { | |
3478 | char buff[256]; | |
3479 | buff[regerror(err, &discrim->regex_ident, buff, sizeof(buff))] = 0; | |
3480 | ||
3481 | send_message(user, opserv, "OSMSG_INVALID_REGEX", discrim->mask_ident, buff, err); | |
3482 | goto regfail; | |
3483 | } | |
3484 | } | |
3485 | ||
3486 | if(discrim->mask_host) | |
3487 | { | |
3488 | int err = regcomp(&discrim->regex_host, discrim->mask_host, REG_EXTENDED|REG_ICASE|REG_NOSUB); | |
3489 | discrim->has_regex_host = !err; | |
3490 | if(err) | |
3491 | { | |
3492 | char buff[256]; | |
3493 | buff[regerror(err, &discrim->regex_host, buff, sizeof(buff))] = 0; | |
3494 | ||
3495 | send_message(user, opserv, "OSMSG_INVALID_REGEX", discrim->mask_host, buff, err); | |
3496 | goto regfail; | |
3497 | } | |
3498 | } | |
3499 | ||
3500 | if(discrim->mask_info) | |
3501 | { | |
3502 | int err = regcomp(&discrim->regex_info, discrim->mask_info, REG_EXTENDED|REG_ICASE|REG_NOSUB); | |
3503 | discrim->has_regex_info = !err; | |
3504 | if(err) | |
3505 | { | |
3506 | char buff[256]; | |
3507 | buff[regerror(err, &discrim->regex_info, buff, sizeof(buff))] = 0; | |
3508 | ||
3509 | send_message(user, opserv, "OSMSG_INVALID_REGEX", discrim->mask_info, buff, err); | |
3510 | goto regfail; | |
3511 | } | |
3512 | } | |
3513 | } | |
3514 | ||
d76ed9a9 | 3515 | return discrim; |
27eaa617 | 3516 | |
d76ed9a9 AS |
3517 | fail: |
3518 | free(discrim); | |
3519 | return NULL; | |
27eaa617 | 3520 | |
3521 | regfail: | |
3522 | if(discrim->has_regex_nick) | |
3523 | regfree(&discrim->regex_nick); | |
3524 | if(discrim->has_regex_ident) | |
3525 | regfree(&discrim->regex_ident); | |
3526 | if(discrim->has_regex_host) | |
3527 | regfree(&discrim->regex_host); | |
3528 | if(discrim->has_regex_info) | |
3529 | regfree(&discrim->regex_info); | |
3530 | ||
3531 | free(discrim); | |
3532 | return NULL; | |
d76ed9a9 AS |
3533 | } |
3534 | ||
3535 | static int | |
3536 | discrim_match(discrim_t discrim, struct userNode *user) | |
3537 | { | |
3538 | unsigned int access; | |
63665495 | 3539 | char *scmp=NULL, *dcmp=NULL; |
d76ed9a9 AS |
3540 | |
3541 | if ((user->timestamp < discrim->min_ts) | |
3542 | || (user->timestamp > discrim->max_ts) | |
3543 | || (user->channels.used < discrim->min_channels) | |
3544 | || (user->channels.used > discrim->max_channels) | |
3545 | || (discrim->authed == 0 && user->handle_info) | |
3546 | || (discrim->authed == 1 && !user->handle_info) | |
3547 | || (discrim->info_space == 0 && user->info[0] == ' ') | |
3548 | || (discrim->info_space == 1 && user->info[0] != ' ') | |
d76ed9a9 AS |
3549 | || (discrim->server && !match_ircglob(user->uplink->name, discrim->server)) |
3550 | || (discrim->accountmask && (!user->handle_info || !match_ircglob(user->handle_info->handle, discrim->accountmask))) | |
3551 | || (discrim->ip_mask && !MATCH_IPMASK(user->ip, discrim->ip_addr, discrim->ip_mask))) { | |
3552 | return 0; | |
3553 | } | |
27eaa617 | 3554 | |
3555 | if(discrim->use_regex) | |
3556 | { | |
3557 | if((discrim->has_regex_nick && regexec(&discrim->regex_nick, user->nick, 0, 0, 0)) | |
3558 | || (discrim->has_regex_ident && regexec(&discrim->regex_ident, user->ident, 0, 0, 0)) | |
3559 | || (discrim->has_regex_host && regexec(&discrim->regex_host, user->hostname, 0, 0, 0)) | |
3560 | || (discrim->has_regex_info && regexec(&discrim->regex_info, user->info, 0, 0, 0))) { | |
3561 | return 0; | |
3562 | } | |
3563 | } | |
3564 | else | |
3565 | { | |
3566 | if ((discrim->mask_nick && !match_ircglob(user->nick, discrim->mask_nick)) | |
3567 | || (discrim->mask_ident && !match_ircglob(user->ident, discrim->mask_ident)) | |
3568 | || (discrim->mask_host && !match_ircglob(user->hostname, discrim->mask_host)) | |
3569 | || (discrim->mask_info && !match_ircglob(user->info, discrim->mask_info))) { | |
3570 | return 0; | |
3571 | } | |
3572 | } | |
3573 | ||
63665495 | 3574 | if ((discrim->intra_scmp > 0 && discrim->intra_dcmp > 0)) { |
3575 | switch(discrim->intra_scmp) { | |
3576 | case 1: scmp=user->nick; break; | |
3577 | case 2: scmp=user->ident; break; | |
3578 | case 3: | |
3579 | scmp=user->info; | |
3580 | if (discrim->info_space == 1) scmp++; | |
3581 | break; | |
3582 | } | |
3583 | switch(discrim->intra_dcmp) { | |
3584 | case 1: dcmp=user->nick; break; | |
3585 | case 2: dcmp=user->ident; break; | |
3586 | case 3: /* When checking INFO, and info_space is enabled | |
3587 | * ignore the first character in a search | |
3588 | * XXX: Should we ignore ALL leading whitespace? | |
3589 | * Also, what about ignoring ~ in ident? | |
3590 | */ | |
3591 | dcmp=user->info; | |
3592 | if (discrim->info_space == 1) dcmp++; | |
3593 | break; | |
3594 | } | |
3595 | if (irccasecmp(scmp,dcmp)) | |
3596 | return 0; | |
3597 | } | |
3598 | ||
d76ed9a9 AS |
3599 | if (discrim->channel && !GetUserMode(discrim->channel, user)) return 0; |
3600 | access = user->handle_info ? user->handle_info->opserv_level : 0; | |
3601 | if ((access < discrim->min_level) | |
3602 | || (access > discrim->max_level)) { | |
3603 | return 0; | |
3604 | } | |
3605 | if (discrim->ip_mask_str) { | |
3606 | if (!match_ircglob(inet_ntoa(user->ip), discrim->ip_mask_str)) return 0; | |
3607 | } | |
3608 | if (discrim->min_clones > 1) { | |
3609 | struct opserv_hostinfo *ohi = dict_find(opserv_hostinfo_dict, inet_ntoa(user->ip), NULL); | |
3610 | if (!ohi || (ohi->clients.used < discrim->min_clones)) return 0; | |
3611 | } | |
3612 | return 1; | |
3613 | } | |
3614 | ||
3615 | static unsigned int | |
3616 | opserv_discrim_search(discrim_t discrim, discrim_search_func dsf, void *data) | |
3617 | { | |
3618 | unsigned int nn, count; | |
3619 | struct userList matched; | |
3620 | ||
3621 | userList_init(&matched); | |
3622 | /* Try most optimized search methods first */ | |
3623 | if (discrim->channel) { | |
3624 | for (nn=0; | |
3625 | (nn < discrim->channel->members.used) | |
3626 | && (matched.used < discrim->limit); | |
3627 | nn++) { | |
3628 | struct modeNode *mn = discrim->channel->members.list[nn]; | |
3629 | if (((mn->modes & discrim->chan_req_modes) != discrim->chan_req_modes) | |
3630 | || ((mn->modes & discrim->chan_no_modes) != 0)) { | |
3631 | continue; | |
3632 | } | |
3633 | if (discrim_match(discrim, mn->user)) { | |
3634 | userList_append(&matched, mn->user); | |
3635 | } | |
3636 | } | |
3637 | } else if (discrim->ip_mask_str && !discrim->ip_mask_str[strcspn(discrim->ip_mask_str, "?*")]) { | |
3638 | struct opserv_hostinfo *ohi = dict_find(opserv_hostinfo_dict, discrim->ip_mask_str, NULL); | |
3639 | if (!ohi) { | |
3640 | userList_clean(&matched); | |
3641 | return 0; | |
3642 | } | |
3643 | for (nn=0; (nn<ohi->clients.used) && (matched.used < discrim->limit); nn++) { | |
3644 | if (discrim_match(discrim, ohi->clients.list[nn])) { | |
3645 | userList_append(&matched, ohi->clients.list[nn]); | |
3646 | } | |
3647 | } | |
3648 | } else { | |
3649 | dict_iterator_t it; | |
3650 | for (it=dict_first(clients); it && (matched.used < discrim->limit); it=iter_next(it)) { | |
3651 | if (discrim_match(discrim, iter_data(it))) { | |
3652 | userList_append(&matched, iter_data(it)); | |
3653 | } | |
3654 | } | |
3655 | } | |
3656 | ||
3657 | if (!matched.used) { | |
3658 | userList_clean(&matched); | |
3659 | return 0; | |
3660 | } | |
3661 | ||
3662 | if (discrim->option_log) { | |
3663 | log_module(OS_LOG, LOG_INFO, "Logging matches for search:"); | |
3664 | } | |
3665 | for (nn=0; nn<matched.used; nn++) { | |
3666 | struct userNode *user = matched.list[nn]; | |
3667 | if (discrim->option_log) { | |
3668 | log_module(OS_LOG, LOG_INFO, " %s!%s@%s", user->nick, user->ident, user->hostname); | |
3669 | } | |
3670 | if (dsf(user, data)) { | |
258d1427 AS |
3671 | /* If a search function returns true, it ran into a |
3672 | problem. Stop going through the list. */ | |
3673 | break; | |
3674 | } | |
d76ed9a9 AS |
3675 | } |
3676 | if (discrim->option_log) { | |
3677 | log_module(OS_LOG, LOG_INFO, "End of matching users."); | |
3678 | } | |
3679 | count = matched.used; | |
3680 | userList_clean(&matched); | |
3681 | return count; | |
3682 | } | |
3683 | ||
3684 | static int | |
3685 | trace_print_func(struct userNode *match, void *extra) | |
3686 | { | |
3687 | struct discrim_and_source *das = extra; | |
3688 | if (match->handle_info) { | |
258d1427 | 3689 | 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 | 3690 | } else { |
258d1427 | 3691 | send_message_type(4, das->source, das->destination, "%-15s\002 \002%10s\002@\002%s", match->nick, match->ident, match->hostname); |
d76ed9a9 AS |
3692 | } |
3693 | return 0; | |
3694 | } | |
3695 | ||
3696 | static int | |
3697 | trace_count_func(UNUSED_ARG(struct userNode *match), UNUSED_ARG(void *extra)) | |
3698 | { | |
3699 | return 0; | |
3700 | } | |
3701 | ||
3702 | static int | |
3703 | is_oper_victim(struct userNode *user, struct userNode *target, int match_opers) | |
3704 | { | |
3705 | return !(IsService(target) | |
3706 | || (!match_opers && IsOper(target)) | |
3707 | || (target->handle_info | |
3708 | && target->handle_info->opserv_level > user->handle_info->opserv_level)); | |
3709 | } | |
3710 | ||
3711 | static int | |
3712 | trace_gline_func(struct userNode *match, void *extra) | |
3713 | { | |
3714 | struct discrim_and_source *das = extra; | |
3715 | ||
3716 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { | |
9a75756e | 3717 | opserv_block(match, das->source->handle_info->handle, das->discrim->reason, das->discrim->duration, 0); |
d76ed9a9 AS |
3718 | } |
3719 | ||
3720 | return 0; | |
3721 | } | |
3722 | ||
d914d1cb | 3723 | static int |
3724 | trace_shun_func(struct userNode *match, void *extra) | |
3725 | { | |
3726 | struct discrim_and_source *das = extra; | |
3727 | ||
3728 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { | |
3729 | opserv_shun(match, das->source->handle_info->handle, das->discrim->reason, das->discrim->duration); | |
3730 | } | |
3731 | ||
3732 | return 0; | |
3733 | } | |
3734 | ||
d76ed9a9 AS |
3735 | static int |
3736 | trace_kill_func(struct userNode *match, void *extra) | |
3737 | { | |
3738 | struct discrim_and_source *das = extra; | |
3739 | ||
3740 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { | |
258d1427 | 3741 | char *reason; |
d76ed9a9 AS |
3742 | if (das->discrim->reason) { |
3743 | reason = das->discrim->reason; | |
3744 | } else { | |
3745 | reason = alloca(strlen(OSMSG_KILL_REQUESTED)+strlen(das->source->nick)+1); | |
3746 | sprintf(reason, OSMSG_KILL_REQUESTED, das->source->nick); | |
3747 | } | |
3748 | DelUser(match, opserv, 1, reason); | |
3749 | } | |
3750 | ||
3751 | return 0; | |
3752 | } | |
3753 | ||
3754 | static int | |
3755 | is_gagged(char *mask) | |
3756 | { | |
3757 | struct gag_entry *gag; | |
3758 | ||
3759 | for (gag = gagList; gag; gag = gag->next) { | |
3760 | if (match_ircglobs(gag->mask, mask)) return 1; | |
3761 | } | |
3762 | return 0; | |
3763 | } | |
3764 | ||
3765 | static int | |
3766 | trace_gag_func(struct userNode *match, void *extra) | |
3767 | { | |
3768 | struct discrim_and_source *das = extra; | |
3769 | ||
3770 | if (is_oper_victim(das->source, match, das->discrim->match_opers)) { | |
3771 | char *reason, *mask; | |
3772 | int masksize; | |
3773 | if (das->discrim->reason) { | |
3774 | reason = das->discrim->reason; | |
3775 | } else { | |
3776 | reason = alloca(strlen(OSMSG_GAG_REQUESTED)+strlen(das->source->nick)+1); | |
3777 | sprintf(reason, OSMSG_GAG_REQUESTED, das->source->nick); | |
3778 | } | |
258d1427 AS |
3779 | masksize = 5+strlen(match->hostname); |
3780 | mask = alloca(masksize); | |
d76ed9a9 | 3781 | snprintf(mask, masksize, "*!*@%s", match->hostname); |
258d1427 | 3782 | if (!is_gagged(mask)) { |
d76ed9a9 AS |
3783 | gag_create(mask, das->source->handle_info->handle, reason, |
3784 | das->discrim->duration ? (now + das->discrim->duration) : 0); | |
3785 | } | |
3786 | } | |
3787 | ||
3788 | return 0; | |
3789 | } | |
3790 | ||
3791 | static int | |
3792 | trace_domains_func(struct userNode *match, void *extra) | |
3793 | { | |
3794 | struct discrim_and_source *das = extra; | |
3795 | unsigned long *count; | |
3796 | unsigned int depth; | |
3797 | char *hostname; | |
3798 | ||
3799 | if (!match->hostname[strspn(match->hostname, "0123456789.")]) { | |
3800 | char ipmask[16]; | |
3801 | unsigned long matchip = ntohl(match->ip.s_addr); | |
3802 | /* raw IP address.. use up to first three octets of IP */ | |
3803 | switch (das->discrim->domain_depth) { | |
3804 | default: | |
3805 | snprintf(ipmask, sizeof(ipmask), "%lu.%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255, (matchip>>8)&255); | |
3806 | break; | |
3807 | case 2: | |
3808 | snprintf(ipmask, sizeof(ipmask), "%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255); | |
3809 | break; | |
3810 | case 1: | |
3811 | snprintf(ipmask, sizeof(ipmask), "%lu.*", (matchip>>24)&255); | |
3812 | break; | |
3813 | } | |
3814 | hostname = ipmask; | |
3815 | } else { | |
3816 | hostname = match->hostname + strlen(match->hostname); | |
3817 | for (depth=das->discrim->domain_depth; | |
3818 | depth && (hostname > match->hostname); | |
3819 | depth--) { | |
3820 | hostname--; | |
3821 | while ((hostname > match->hostname) && (*hostname != '.')) hostname--; | |
3822 | } | |
3823 | if (*hostname == '.') hostname++; /* advance past last dot we saw */ | |
3824 | } | |
3825 | if (!(count = dict_find(das->dict, hostname, NULL))) { | |
3826 | count = calloc(1, sizeof(*count)); | |
3827 | dict_insert(das->dict, strdup(hostname), count); | |
3828 | } | |
3829 | (*count)++; | |
3830 | return 0; | |
3831 | } | |
3832 | ||
3833 | static int | |
3834 | opserv_show_hostinfo(const char *key, void *data, void *extra) | |
3835 | { | |
3836 | unsigned long *count = data; | |
3837 | struct discrim_and_source *das = extra; | |
3838 | ||
258d1427 | 3839 | send_message_type(4, das->source, das->destination, "%s %lu", key, *count); |
d76ed9a9 AS |
3840 | return !--das->disp_limit; |
3841 | } | |
3842 | ||
3843 | static MODCMD_FUNC(cmd_trace) | |
3844 | { | |
3845 | struct discrim_and_source das; | |
3846 | discrim_search_func action; | |
3847 | unsigned int matches; | |
3848 | struct svccmd *subcmd; | |
3849 | char buf[MAXLEN]; | |
3850 | ||
3851 | sprintf(buf, "trace %s", argv[1]); | |
258d1427 AS |
3852 | if (!(subcmd = dict_find(opserv_service->commands, buf, NULL))) { |
3853 | reply("OSMSG_BAD_ACTION", argv[1]); | |
d76ed9a9 AS |
3854 | return 0; |
3855 | } | |
258d1427 | 3856 | if (!svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) |
d76ed9a9 AS |
3857 | return 0; |
3858 | if (!irccasecmp(argv[1], "print")) | |
3859 | action = trace_print_func; | |
3860 | else if (!irccasecmp(argv[1], "count")) | |
3861 | action = trace_count_func; | |
3862 | else if (!irccasecmp(argv[1], "domains")) | |
3863 | action = trace_domains_func; | |
3864 | else if (!irccasecmp(argv[1], "gline")) | |
3865 | action = trace_gline_func; | |
d914d1cb | 3866 | else if (!irccasecmp(argv[1], "shun")) |
3867 | action = trace_shun_func; | |
d76ed9a9 AS |
3868 | else if (!irccasecmp(argv[1], "kill")) |
3869 | action = trace_kill_func; | |
3870 | else if (!irccasecmp(argv[1], "gag")) | |
3871 | action = trace_gag_func; | |
3872 | else { | |
258d1427 AS |
3873 | reply("OSMSG_BAD_ACTION", argv[1]); |
3874 | return 0; | |
d76ed9a9 AS |
3875 | } |
3876 | ||
3877 | if (user->handle_info->opserv_level < subcmd->min_opserv_level) { | |
3878 | reply("OSMSG_LEVEL_TOO_LOW"); | |
3879 | return 0; | |
3880 | } | |
3881 | ||
3882 | das.dict = NULL; | |
3883 | das.source = user; | |
258d1427 AS |
3884 | das.destination = cmd->parent->bot; |
3885 | das.discrim = opserv_discrim_create(user, cmd->parent->bot, argc-2, argv+2, 1); | |
d76ed9a9 AS |
3886 | if (!das.discrim) |
3887 | return 0; | |
3888 | ||
3889 | if (action == trace_print_func) | |
de9510bc | 3890 | { |
8e11460f | 3891 | reply("OSMSG_USER_SEARCH_RESULTS"); |
de9510bc AS |
3892 | reply("OSMSG_USER_SEARCH_BAR"); |
3893 | reply("OSMSG_USER_SEARCH_HEADER"); | |
3894 | reply("OSMSG_USER_SEARCH_BAR"); | |
3895 | } | |
d76ed9a9 | 3896 | else if (action == trace_count_func) |
258d1427 | 3897 | das.discrim->limit = INT_MAX; |
d76ed9a9 AS |
3898 | else if ((action == trace_gline_func) && !das.discrim->duration) |
3899 | das.discrim->duration = opserv_conf.block_gline_duration; | |
d914d1cb | 3900 | else if ((action == trace_shun_func) && !das.discrim->duration) |
3901 | das.discrim->duration = opserv_conf.block_shun_duration; | |
d76ed9a9 AS |
3902 | else if (action == trace_domains_func) { |
3903 | das.dict = dict_new(); | |
3904 | dict_set_free_data(das.dict, free); | |
3905 | dict_set_free_keys(das.dict, free); | |
3906 | das.disp_limit = das.discrim->limit; | |
3907 | das.discrim->limit = INT_MAX; | |
3908 | } | |
3909 | matches = opserv_discrim_search(das.discrim, action, &das); | |
3910 | ||
3911 | if (action == trace_domains_func) | |
3912 | dict_foreach(das.dict, opserv_show_hostinfo, &das); | |
3913 | ||
3914 | if (matches) | |
8e11460f AS |
3915 | { |
3916 | if(action == trace_print_func) | |
258d1427 | 3917 | reply("OSMSG_USER_SEARCH_COUNT_BAR", matches); |
8e11460f AS |
3918 | else |
3919 | reply("OSMSG_USER_SEARCH_COUNT", matches); | |
3920 | } | |
d76ed9a9 | 3921 | else |
258d1427 | 3922 | reply("MSG_NO_MATCHES"); |
d76ed9a9 AS |
3923 | |
3924 | if (das.discrim->channel) | |
3925 | UnlockChannel(das.discrim->channel); | |
3926 | free(das.discrim->reason); | |
27eaa617 | 3927 | |
3928 | if(das.discrim->has_regex_nick) | |
3929 | regfree(&das.discrim->regex_nick); | |
3930 | if(das.discrim->has_regex_ident) | |
3931 | regfree(&das.discrim->regex_ident); | |
3932 | if(das.discrim->has_regex_host) | |
3933 | regfree(&das.discrim->regex_host); | |
3934 | if(das.discrim->has_regex_info) | |
3935 | regfree(&das.discrim->regex_info); | |
3936 | ||
d76ed9a9 AS |
3937 | free(das.discrim); |
3938 | dict_delete(das.dict); | |
3939 | return 1; | |
3940 | } | |
3941 | ||
258d1427 | 3942 | typedef void (*cdiscrim_search_func)(struct chanNode *match, void *data, struct userNode *bot); |
d76ed9a9 AS |
3943 | |
3944 | typedef struct channel_discrim { | |
3945 | char *name, *topic; | |
3946 | ||
3947 | unsigned int min_users, max_users; | |
3948 | time_t min_ts, max_ts; | |
3949 | unsigned int limit; | |
3950 | } *cdiscrim_t; | |
3951 | ||
258d1427 AS |
3952 | static cdiscrim_t opserv_cdiscrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[]); |
3953 | static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim, cdiscrim_search_func dsf, void *data, struct userNode *bot); | |
d76ed9a9 AS |
3954 | |
3955 | static time_t | |
3956 | smart_parse_time(const char *str) { | |
3957 | /* If an interval-style string is given, treat as time before now. | |
3958 | * If it's all digits, treat directly as a Unix timestamp. */ | |
3959 | return str[strspn(str, "0123456789")] ? (time_t)(now - ParseInterval(str)) : (time_t)atoi(str); | |
3960 | } | |
3961 | ||
3962 | static cdiscrim_t | |
258d1427 | 3963 | opserv_cdiscrim_create(struct userNode *user, struct userNode *bot, unsigned int argc, char *argv[]) |
d76ed9a9 AS |
3964 | { |
3965 | cdiscrim_t discrim; | |
3966 | unsigned int i; | |
3967 | ||
3968 | discrim = calloc(1, sizeof(*discrim)); | |
3969 | discrim->limit = 25; | |
3970 | ||
3971 | for (i = 0; i < argc; i++) { | |
258d1427 AS |
3972 | /* Assume all criteria require arguments. */ |
3973 | if (i == (argc - 1)) { | |
3974 | send_message(user, bot, "MSG_MISSING_PARAMS", argv[i]); | |
3975 | return NULL; | |
3976 | } | |
3977 | ||
3978 | if (!irccasecmp(argv[i], "name")) | |
3979 | discrim->name = argv[++i]; | |
3980 | else if (!irccasecmp(argv[i], "topic")) | |
3981 | discrim->topic = argv[++i]; | |
3982 | else if (!irccasecmp(argv[i], "users")) { | |
3983 | const char *cmp = argv[++i]; | |
d76ed9a9 AS |
3984 | if (cmp[0] == '<') { |
3985 | if (cmp[1] == '=') | |
3986 | discrim->max_users = strtoul(cmp+2, NULL, 0); | |
3987 | else | |
3988 | discrim->max_users = strtoul(cmp+1, NULL, 0) - 1; | |
3989 | } else if (cmp[0] == '=') { | |
3990 | discrim->min_users = discrim->max_users = strtoul(cmp+1, NULL, 0); | |
3991 | } else if (cmp[0] == '>') { | |
3992 | if (cmp[1] == '=') | |
3993 | discrim->min_users = strtoul(cmp+2, NULL, 0); | |
3994 | else | |
3995 | discrim->min_users = strtoul(cmp+1, NULL, 0) + 1; | |
3996 | } else { | |
3997 | discrim->min_users = strtoul(cmp+2, NULL, 0); | |
3998 | } | |
258d1427 AS |
3999 | } else if (!irccasecmp(argv[i], "timestamp")) { |
4000 | const char *cmp = argv[++i]; | |
d76ed9a9 AS |
4001 | if (cmp[0] == '<') { |
4002 | if (cmp[1] == '=') | |
4003 | discrim->max_ts = smart_parse_time(cmp+2); | |
4004 | else | |
4005 | discrim->max_ts = smart_parse_time(cmp+1)-1; | |
4006 | } else if (cmp[0] == '=') { | |
4007 | discrim->min_ts = discrim->max_ts = smart_parse_time(cmp+1); | |
4008 | } else if (cmp[0] == '>') { | |
4009 | if (cmp[1] == '=') | |
4010 | discrim->min_ts = smart_parse_time(cmp+2); | |
4011 | else | |
4012 | discrim->min_ts = smart_parse_time(cmp+1)+1; | |
4013 | } else { | |
4014 | discrim->min_ts = smart_parse_time(cmp); | |
4015 | } | |
258d1427 AS |
4016 | } else if (!irccasecmp(argv[i], "limit")) { |
4017 | discrim->limit = strtoul(argv[++i], NULL, 10); | |
4018 | } else { | |
4019 | send_message(user, bot, "MSG_INVALID_CRITERIA", argv[i]); | |
4020 | goto fail; | |
4021 | } | |
d76ed9a9 AS |
4022 | } |
4023 | ||
4024 | if (discrim->name && !strcmp(discrim->name, "*")) | |
258d1427 | 4025 | discrim->name = 0; |
d76ed9a9 | 4026 | if (discrim->topic && !strcmp(discrim->topic, "*")) |
258d1427 | 4027 | discrim->topic = 0; |
d76ed9a9 AS |
4028 | |
4029 | return discrim; | |
4030 | fail: | |
4031 | free(discrim); | |
4032 | return NULL; | |
4033 | } | |
4034 | ||
4035 | static int | |
4036 | cdiscrim_match(cdiscrim_t discrim, struct chanNode *chan) | |
4037 | { | |
4038 | if ((discrim->name && !match_ircglob(chan->name, discrim->name)) || | |
4039 | (discrim->topic && !match_ircglob(chan->topic, discrim->topic)) || | |
4040 | (discrim->min_users && chan->members.used < discrim->min_users) || | |
4041 | (discrim->max_users && chan->members.used > discrim->max_users) || | |
4042 | (discrim->min_ts && chan->timestamp < discrim->min_ts) || | |
4043 | (discrim->max_ts && chan->timestamp > discrim->max_ts)) { | |
258d1427 | 4044 | return 0; |
d76ed9a9 AS |
4045 | } |
4046 | return 1; | |
4047 | } | |
4048 | ||
258d1427 | 4049 | static unsigned int opserv_cdiscrim_search(cdiscrim_t discrim, cdiscrim_search_func dsf, void *data, struct userNode *bot) |
d76ed9a9 AS |
4050 | { |
4051 | unsigned int count = 0; | |
4052 | dict_iterator_t it, next; | |
4053 | ||
4054 | for (it = dict_first(channels); it && count < discrim->limit ; it = next) { | |
258d1427 | 4055 | struct chanNode *chan = iter_data(it); |
d76ed9a9 | 4056 | |
258d1427 AS |
4057 | /* Hold on to the next channel in case we decide to |
4058 | add actions that destructively modify the channel. */ | |
4059 | next = iter_next(it); | |
4060 | if ((chan->members.used > 0) && cdiscrim_match(discrim, chan)) { | |
4061 | dsf(chan, data, bot); | |
4062 | count++; | |
4063 | } | |
d76ed9a9 AS |
4064 | } |
4065 | ||
4066 | return count; | |
4067 | } | |
4068 | ||
258d1427 | 4069 | void channel_count(UNUSED_ARG(struct chanNode *channel), UNUSED_ARG(void *data), UNUSED_ARG(struct userNode *bot)) |
d76ed9a9 AS |
4070 | { |
4071 | } | |
4072 | ||
258d1427 | 4073 | void channel_print(struct chanNode *channel, void *data, struct userNode *bot) |
d76ed9a9 AS |
4074 | { |
4075 | char modes[MAXLEN]; | |
4076 | irc_make_chanmode(channel, modes); | |
258d1427 | 4077 | send_message(data, bot, "OSMSG_CSEARCH_CHANNEL_INFO", channel->name, channel->members.used, modes, channel->topic); |
d76ed9a9 AS |
4078 | } |
4079 | ||
4080 | static MODCMD_FUNC(cmd_csearch) | |
4081 | { | |
4082 | cdiscrim_t discrim; | |
4083 | unsigned int matches; | |
4084 | cdiscrim_search_func action; | |
4085 | struct svccmd *subcmd; | |
4086 | char buf[MAXLEN]; | |
4087 | ||
4088 | if (!irccasecmp(argv[1], "count")) | |
258d1427 | 4089 | action = channel_count; |
d76ed9a9 | 4090 | else if (!irccasecmp(argv[1], "print")) |
258d1427 | 4091 | action = channel_print; |
d76ed9a9 | 4092 | else { |
258d1427 AS |
4093 | reply("OSMSG_BAD_ACTION", argv[1]); |
4094 | return 0; | |
d76ed9a9 AS |
4095 | } |
4096 | ||
4097 | sprintf(buf, "%s %s", argv[0], argv[0]); | |
258d1427 AS |
4098 | if ((subcmd = dict_find(opserv_service->commands, buf, NULL)) |
4099 | && !svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) { | |
d76ed9a9 AS |
4100 | return 0; |
4101 | } | |
4102 | ||
258d1427 | 4103 | discrim = opserv_cdiscrim_create(user, cmd->parent->bot, argc - 2, argv + 2); |
d76ed9a9 | 4104 | if (!discrim) |
258d1427 | 4105 | return 0; |
d76ed9a9 AS |
4106 | |
4107 | if (action == channel_print) | |
258d1427 | 4108 | reply("OSMSG_CHANNEL_SEARCH_RESULTS"); |
d76ed9a9 | 4109 | else if (action == channel_count) |
258d1427 | 4110 | discrim->limit = INT_MAX; |
d76ed9a9 | 4111 | |
258d1427 | 4112 | matches = opserv_cdiscrim_search(discrim, action, user, cmd->parent->bot); |
d76ed9a9 AS |
4113 | |
4114 | if (matches) | |
258d1427 | 4115 | reply("MSG_MATCH_COUNT", matches); |
d76ed9a9 | 4116 | else |
258d1427 | 4117 | reply("MSG_NO_MATCHES"); |
d76ed9a9 AS |
4118 | |
4119 | free(discrim); | |
4120 | return 1; | |
4121 | } | |
4122 | ||
4123 | static MODCMD_FUNC(cmd_gsync) | |
4124 | { | |
4125 | struct server *src; | |
4126 | if (argc > 1) { | |
4127 | src = GetServerH(argv[1]); | |
4128 | if (!src) { | |
4129 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
4130 | return 0; | |
4131 | } | |
4132 | } else { | |
4133 | src = self->uplink; | |
4134 | } | |
4135 | irc_stats(cmd->parent->bot, src, 'G'); | |
4136 | reply("OSMSG_GSYNC_RUNNING", src->name); | |
4137 | return 1; | |
4138 | } | |
4139 | ||
d914d1cb | 4140 | static MODCMD_FUNC(cmd_ssync) |
4141 | { | |
4142 | struct server *src; | |
4143 | if (argc > 1) { | |
4144 | src = GetServerH(argv[1]); | |
4145 | if (!src) { | |
4146 | reply("MSG_SERVER_UNKNOWN", argv[1]); | |
4147 | return 0; | |
4148 | } | |
4149 | } else { | |
4150 | src = self->uplink; | |
4151 | } | |
4152 | irc_stats(cmd->parent->bot, src, 'S'); | |
4153 | reply("OSMSG_SSYNC_RUNNING", src->name); | |
4154 | return 1; | |
4155 | } | |
4156 | ||
d76ed9a9 AS |
4157 | struct gline_extra { |
4158 | struct userNode *user; | |
4159 | struct string_list *glines; | |
258d1427 | 4160 | struct userNode *bot; |
d76ed9a9 AS |
4161 | }; |
4162 | ||
4163 | static void | |
4164 | gtrace_print_func(struct gline *gline, void *extra) | |
4165 | { | |
4166 | struct gline_extra *xtra = extra; | |
4167 | char *when_text, set_text[20]; | |
4168 | strftime(set_text, sizeof(set_text), "%Y-%m-%d", localtime(&gline->issued)); | |
4169 | when_text = asctime(localtime(&gline->expires)); | |
4170 | when_text[strlen(when_text)-1] = 0; /* strip lame \n */ | |
258d1427 | 4171 | send_message(xtra->user, xtra->bot, "OSMSG_GTRACE_FORMAT", gline->target, set_text, gline->issuer, when_text, gline->reason); |
d76ed9a9 AS |
4172 | } |
4173 | ||
4174 | static void | |
4175 | gtrace_count_func(UNUSED_ARG(struct gline *gline), UNUSED_ARG(void *extra)) | |
4176 | { | |
4177 | } | |
4178 | ||
4179 | static void | |
4180 | gtrace_ungline_func(struct gline *gline, void *extra) | |
4181 | { | |
4182 | struct gline_extra *xtra = extra; | |
4183 | string_list_append(xtra->glines, strdup(gline->target)); | |
4184 | } | |
4185 | ||
4186 | static MODCMD_FUNC(cmd_gtrace) | |
4187 | { | |
4188 | struct gline_discrim *discrim; | |
4189 | gline_search_func action; | |
4190 | unsigned int matches, nn; | |
4191 | struct gline_extra extra; | |
4192 | struct svccmd *subcmd; | |
4193 | char buf[MAXLEN]; | |
4194 | ||
4195 | if (!irccasecmp(argv[1], "print")) | |
4196 | action = gtrace_print_func; | |
4197 | else if (!irccasecmp(argv[1], "count")) | |
4198 | action = gtrace_count_func; | |
4199 | else if (!irccasecmp(argv[1], "ungline")) | |
4200 | action = gtrace_ungline_func; | |
4201 | else { | |
4202 | reply("OSMSG_BAD_ACTION", argv[1]); | |
4203 | return 0; | |
4204 | } | |
4205 | sprintf(buf, "%s %s", argv[0], argv[0]); | |
258d1427 AS |
4206 | if ((subcmd = dict_find(opserv_service->commands, buf, NULL)) |
4207 | && !svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) { | |
d76ed9a9 AS |
4208 | return 0; |
4209 | } | |
4210 | ||
4211 | discrim = gline_discrim_create(user, cmd->parent->bot, argc-2, argv+2); | |
4212 | if (!discrim) | |
4213 | return 0; | |
4214 | ||
4215 | if (action == gtrace_print_func) | |
4216 | reply("OSMSG_GLINE_SEARCH_RESULTS"); | |
4217 | else if (action == gtrace_count_func) | |
4218 | discrim->limit = INT_MAX; | |
4219 | ||
4220 | extra.user = user; | |
4221 | extra.glines = alloc_string_list(4); | |
258d1427 | 4222 | extra.bot = cmd->parent->bot; |
d76ed9a9 AS |
4223 | matches = gline_discrim_search(discrim, action, &extra); |
4224 | ||
4225 | if (action == gtrace_ungline_func) | |
4226 | for (nn=0; nn<extra.glines->used; nn++) | |
4227 | gline_remove(extra.glines->list[nn], 1); | |
4228 | free_string_list(extra.glines); | |
4229 | ||
4230 | if (matches) | |
4231 | reply("MSG_MATCH_COUNT", matches); | |
4232 | else | |
4233 | reply("MSG_NO_MATCHES"); | |
4234 | free(discrim->alt_target_mask); | |
4235 | free(discrim); | |
4236 | return 1; | |
4237 | } | |
4238 | ||
d914d1cb | 4239 | struct shun_extra { |
4240 | struct userNode *user; | |
4241 | struct string_list *shuns; | |
4242 | struct userNode *bot; | |
4243 | }; | |
4244 | ||
4245 | static void | |
4246 | strace_print_func(struct shun *shun, void *extra) | |
4247 | { | |
4248 | struct shun_extra *xtra = extra; | |
4249 | char *when_text, set_text[20]; | |
4250 | strftime(set_text, sizeof(set_text), "%Y-%m-%d", localtime(&shun->issued)); | |
4251 | when_text = asctime(localtime(&shun->expires)); | |
4252 | when_text[strlen(when_text)-1] = 0; /* strip lame \n */ | |
4253 | send_message(xtra->user, xtra->bot, "OSMSG_STRACE_FORMAT", shun->target, set_text, shun->issuer, when_text, shun->reason); | |
4254 | } | |
4255 | ||
4256 | static void | |
4257 | strace_count_func(UNUSED_ARG(struct shun *shun), UNUSED_ARG(void *extra)) | |
4258 | { | |
4259 | } | |
4260 | ||
4261 | static void | |
4262 | strace_unshun_func(struct shun *shun, void *extra) | |
4263 | { | |
4264 | struct shun_extra *xtra = extra; | |
4265 | string_list_append(xtra->shuns, strdup(shun->target)); | |
4266 | } | |
4267 | ||
4268 | static MODCMD_FUNC(cmd_strace) | |
4269 | { | |
4270 | struct shun_discrim *discrim; | |
4271 | shun_search_func action; | |
4272 | unsigned int matches, nn; | |
4273 | struct shun_extra extra; | |
4274 | struct svccmd *subcmd; | |
4275 | char buf[MAXLEN]; | |
4276 | ||
4277 | if (!irccasecmp(argv[1], "print")) | |
4278 | action = strace_print_func; | |
4279 | else if (!irccasecmp(argv[1], "count")) | |
4280 | action = strace_count_func; | |
4281 | else if (!irccasecmp(argv[1], "unshun")) | |
4282 | action = strace_unshun_func; | |
4283 | else { | |
4284 | reply("OSMSG_BAD_ACTION", argv[1]); | |
4285 | return 0; | |
4286 | } | |
4287 | sprintf(buf, "%s %s", argv[0], argv[0]); | |
4288 | if ((subcmd = dict_find(opserv_service->commands, buf, NULL)) | |
4289 | && !svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY)) { | |
4290 | return 0; | |
4291 | } | |
4292 | ||
4293 | discrim = shun_discrim_create(user, cmd->parent->bot, argc-2, argv+2); | |
4294 | if (!discrim) | |
4295 | return 0; | |
4296 | ||
4297 | if (action == strace_print_func) | |
4298 | reply("OSMSG_SHUN_SEARCH_RESULTS"); | |
4299 | else if (action == strace_count_func) | |
4300 | discrim->limit = INT_MAX; | |
4301 | ||
4302 | extra.user = user; | |
4303 | extra.shuns = alloc_string_list(4); | |
4304 | extra.bot = cmd->parent->bot; | |
4305 | matches = shun_discrim_search(discrim, action, &extra); | |
4306 | ||
4307 | if (action == strace_unshun_func) | |
4308 | for (nn=0; nn<extra.shuns->used; nn++) | |
4309 | shun_remove(extra.shuns->list[nn], 1); | |
4310 | free_string_list(extra.shuns); | |
4311 | ||
4312 | if (matches) | |
4313 | reply("MSG_MATCH_COUNT", matches); | |
4314 | else | |
4315 | reply("MSG_NO_MATCHES"); | |
4316 | free(discrim->alt_target_mask); | |
4317 | free(discrim); | |
4318 | return 1; | |
4319 | } | |
4320 | ||
d76ed9a9 AS |
4321 | static int |
4322 | alert_check_user(const char *key, void *data, void *extra) | |
4323 | { | |
4324 | struct opserv_user_alert *alert = data; | |
4325 | struct userNode *user = extra; | |
4326 | ||
4327 | if (!discrim_match(alert->discrim, user)) | |
4328 | return 0; | |
4329 | ||
4330 | if ((alert->reaction != REACT_NOTICE) | |
4331 | && IsOper(user) | |
4332 | && !alert->discrim->match_opers) { | |
4333 | return 0; | |
4334 | } | |
4335 | ||
4336 | /* The user matches the alert criteria, so trigger the reaction. */ | |
4337 | if (alert->discrim->option_log) | |
4338 | 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); | |
4339 | ||
4340 | /* Return 1 to halt alert matching, such as when killing the user | |
4341 | that triggered the alert. */ | |
4342 | switch (alert->reaction) { | |
4343 | case REACT_KILL: | |
4344 | DelUser(user, opserv, 1, alert->discrim->reason); | |
4345 | return 1; | |
9a75756e | 4346 | case REACT_SILENT: |
4347 | opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, 1); | |
4348 | return 1; | |
d76ed9a9 | 4349 | case REACT_GLINE: |
9a75756e | 4350 | opserv_block(user, alert->owner, alert->discrim->reason, alert->discrim->duration, 0); |
d76ed9a9 | 4351 | return 1; |
d914d1cb | 4352 | case REACT_SHUN: |
4353 | opserv_shun(user, alert->owner, alert->discrim->reason, alert->discrim->duration); | |
4354 | return 1; | |
d76ed9a9 AS |
4355 | default: |
4356 | log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s.", alert->reaction, key); | |
4357 | /* fall through to REACT_NOTICE case */ | |
4358 | case REACT_NOTICE: | |
4359 | opserv_alert("Alert $b%s$b triggered by user $b%s$b!%s@%s (%s).", key, user->nick, user->ident, user->hostname, alert->discrim->reason); | |
4360 | break; | |
4361 | } | |
4362 | return 0; | |
4363 | } | |
4364 | ||
4365 | static void | |
4366 | opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick)) | |
4367 | { | |
4368 | struct gag_entry *gag; | |
4369 | dict_foreach(opserv_nick_based_alerts, alert_check_user, user); | |
4370 | /* Gag them if appropriate (and only if). */ | |
4371 | user->modes &= ~FLAGS_GAGGED; | |
4372 | for (gag = gagList; gag; gag = gag->next) { | |
4373 | if (user_matches_glob(user, gag->mask, 1)) { | |
4374 | gag_helper_func(user, NULL); | |
4375 | break; | |
4376 | } | |
4377 | } | |
4378 | } | |
4379 | ||
4380 | static void | |
4381 | opserv_staff_alert(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) | |
4382 | { | |
4383 | const char *type; | |
4384 | ||
4385 | if (!opserv_conf.staff_auth_channel | |
4386 | || user->uplink->burst | |
4387 | || !user->handle_info) | |
4388 | return; | |
4389 | else if (user->handle_info->opserv_level) | |
4390 | type = "OPER"; | |
4391 | else if (IsNetworkHelper(user)) | |
4392 | type = "NETWORK HELPER"; | |
4393 | else if (IsSupportHelper(user)) | |
4394 | type = "SUPPORT HELPER"; | |
4395 | else | |
4396 | return; | |
4397 | ||
4398 | if (user->ip.s_addr) | |
4399 | send_channel_notice(opserv_conf.staff_auth_channel, opserv, IDENT_FORMAT" authed to %s account %s", IDENT_DATA(user), type, user->handle_info->handle); | |
4400 | else | |
4401 | 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); | |
4402 | } | |
4403 | ||
4404 | static MODCMD_FUNC(cmd_log) | |
4405 | { | |
4406 | struct logSearch *discrim; | |
4407 | unsigned int matches; | |
4408 | struct logReport report; | |
4409 | ||
4410 | discrim = log_discrim_create(cmd->parent->bot, user, argc, argv); | |
4411 | if (!discrim) | |
4412 | return 0; | |
4413 | ||
4414 | reply("OSMSG_LOG_SEARCH_RESULTS"); | |
4415 | report.reporter = opserv; | |
4416 | report.user = user; | |
4417 | matches = log_entry_search(discrim, log_report_entry, &report); | |
4418 | ||
4419 | if (matches) | |
258d1427 | 4420 | reply("MSG_MATCH_COUNT", matches); |
d76ed9a9 | 4421 | else |
258d1427 | 4422 | reply("MSG_NO_MATCHES"); |
d76ed9a9 AS |
4423 | |
4424 | free(discrim); | |
4425 | return 1; | |
4426 | } | |
4427 | ||
4428 | static int | |
4429 | gag_helper_func(struct userNode *match, UNUSED_ARG(void *extra)) | |
4430 | { | |
4431 | if (IsOper(match) || IsLocal(match)) | |
4432 | return 0; | |
4433 | match->modes |= FLAGS_GAGGED; | |
4434 | return 0; | |
4435 | } | |
4436 | ||
4437 | static MODCMD_FUNC(cmd_gag) | |
4438 | { | |
4439 | struct gag_entry *gag; | |
4440 | unsigned int gagged; | |
4441 | unsigned long duration; | |
4442 | char *reason; | |
4443 | ||
4444 | reason = unsplit_string(argv + 3, argc - 3, NULL); | |
4445 | ||
4446 | if (!is_ircmask(argv[1])) { | |
258d1427 | 4447 | reply("OSMSG_INVALID_IRCMASK", argv[1]); |
d76ed9a9 AS |
4448 | return 0; |
4449 | } | |
4450 | ||
4451 | for (gag = gagList; gag; gag = gag->next) | |
258d1427 | 4452 | if (match_ircglobs(gag->mask, argv[1])) |
d76ed9a9 AS |
4453 | break; |
4454 | ||
4455 | if (gag) { | |
258d1427 AS |
4456 | reply("OSMSG_REDUNDANT_GAG", argv[1]); |
4457 | return 0; | |
d76ed9a9 AS |
4458 | } |
4459 | ||
4460 | duration = ParseInterval(argv[2]); | |
4461 | gagged = gag_create(argv[1], user->handle_info->handle, reason, (duration?now+duration:0)); | |
4462 | ||
4463 | if (gagged) | |
258d1427 | 4464 | reply("OSMSG_GAG_APPLIED", argv[1], gagged); |
d76ed9a9 | 4465 | else |
258d1427 | 4466 | reply("OSMSG_GAG_ADDED", argv[1]); |
d76ed9a9 AS |
4467 | return 1; |
4468 | } | |
4469 | ||
4470 | static int | |
4471 | ungag_helper_func(struct userNode *match, UNUSED_ARG(void *extra)) | |
4472 | { | |
4473 | match->modes &= ~FLAGS_GAGGED; | |
4474 | return 0; | |
4475 | } | |
4476 | ||
4477 | static MODCMD_FUNC(cmd_ungag) | |
4478 | { | |
4479 | struct gag_entry *gag; | |
4480 | unsigned int ungagged; | |
4481 | ||
4482 | for (gag = gagList; gag; gag = gag->next) | |
258d1427 | 4483 | if (!strcmp(gag->mask, argv[1])) |
d76ed9a9 AS |
4484 | break; |
4485 | ||
4486 | if (!gag) { | |
258d1427 AS |
4487 | reply("OSMSG_GAG_NOT_FOUND", argv[1]); |
4488 | return 0; | |
d76ed9a9 AS |
4489 | } |
4490 | ||
4491 | timeq_del(gag->expires, gag_expire, gag, 0); | |
4492 | ungagged = gag_free(gag); | |
4493 | ||
4494 | if (ungagged) | |
258d1427 | 4495 | reply("OSMSG_UNGAG_APPLIED", argv[1], ungagged); |
d76ed9a9 | 4496 | else |
258d1427 | 4497 | reply("OSMSG_UNGAG_ADDED", argv[1]); |
d76ed9a9 AS |
4498 | return 1; |
4499 | } | |
4500 | ||
4501 | static MODCMD_FUNC(cmd_addalert) | |
4502 | { | |
4503 | opserv_alert_reaction reaction; | |
4504 | struct svccmd *subcmd; | |
4505 | const char *name; | |
4506 | char buf[MAXLEN]; | |
4507 | ||
4508 | name = argv[1]; | |
4509 | sprintf(buf, "addalert %s", argv[2]); | |
258d1427 AS |
4510 | if (!(subcmd = dict_find(opserv_service->commands, buf, NULL))) { |
4511 | reply("OSMSG_UNKNOWN_REACTION", argv[2]); | |
4512 | return 0; | |
d76ed9a9 AS |
4513 | } |
4514 | if (!irccasecmp(argv[2], "notice")) | |
4515 | reaction = REACT_NOTICE; | |
4516 | else if (!irccasecmp(argv[2], "kill")) | |
4517 | reaction = REACT_KILL; | |
9a75756e | 4518 | else if (!irccasecmp(argv[2], "silent")) |
4519 | reaction = REACT_SILENT; | |
d76ed9a9 AS |
4520 | else if (!irccasecmp(argv[2], "gline")) |
4521 | reaction = REACT_GLINE; | |
d914d1cb | 4522 | else if (!irccasecmp(argv[2], "shun")) |
4523 | reaction = REACT_SHUN; | |
d76ed9a9 | 4524 | else { |
258d1427 AS |
4525 | reply("OSMSG_UNKNOWN_REACTION", argv[2]); |
4526 | return 0; | |
d76ed9a9 | 4527 | } |
258d1427 | 4528 | if (!svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY) |
d76ed9a9 AS |
4529 | || !opserv_add_user_alert(user, name, reaction, unsplit_string(argv + 3, argc - 3, NULL))) |
4530 | return 0; | |
4531 | reply("OSMSG_ADDED_ALERT", name); | |
4532 | return 1; | |
4533 | } | |
4534 | ||
4535 | static MODCMD_FUNC(cmd_delalert) | |
4536 | { | |
4537 | unsigned int i; | |
4538 | for (i=1; i<argc; i++) { | |
4539 | dict_remove(opserv_nick_based_alerts, argv[i]); | |
4540 | dict_remove(opserv_channel_alerts, argv[i]); | |
258d1427 AS |
4541 | if (dict_remove(opserv_user_alerts, argv[i])) |
4542 | reply("OSMSG_REMOVED_ALERT", argv[i]); | |
d76ed9a9 | 4543 | else |
258d1427 | 4544 | reply("OSMSG_NO_SUCH_ALERT", argv[i]); |
d76ed9a9 AS |
4545 | } |
4546 | return 1; | |
4547 | } | |
4548 | ||
4549 | static void | |
4550 | opserv_conf_read(void) | |
4551 | { | |
4552 | struct record_data *rd; | |
4553 | dict_t conf_node, child; | |
4554 | const char *str, *str2; | |
4555 | struct policer_params *pp; | |
4556 | dict_iterator_t it; | |
4557 | ||
4558 | rd = conf_get_node(OPSERV_CONF_NAME); | |
4559 | if (!rd || rd->type != RECDB_OBJECT) { | |
258d1427 AS |
4560 | log_module(OS_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", OPSERV_CONF_NAME); |
4561 | return; | |
d76ed9a9 AS |
4562 | } |
4563 | conf_node = rd->d.object; | |
4564 | str = database_get_data(conf_node, KEY_DEBUG_CHANNEL, RECDB_QSTRING); | |
4565 | if (opserv && str) { | |
4566 | str2 = database_get_data(conf_node, KEY_DEBUG_CHANNEL_MODES, RECDB_QSTRING); | |
4567 | if (!str2) | |
4568 | str2 = "+tinms"; | |
258d1427 | 4569 | opserv_conf.debug_channel = AddChannel(str, now, str2, NULL, NULL); |
d76ed9a9 AS |
4570 | AddChannelUser(opserv, opserv_conf.debug_channel)->modes |= MODE_CHANOP; |
4571 | } else { | |
258d1427 | 4572 | opserv_conf.debug_channel = NULL; |
d76ed9a9 AS |
4573 | } |
4574 | str = database_get_data(conf_node, KEY_ALERT_CHANNEL, RECDB_QSTRING); | |
4575 | if (opserv && str) { | |
4576 | str2 = database_get_data(conf_node, KEY_ALERT_CHANNEL_MODES, RECDB_QSTRING); | |
4577 | if (!str2) | |
4578 | str2 = "+tns"; | |
258d1427 | 4579 | opserv_conf.alert_channel = AddChannel(str, now, str2, NULL, NULL); |
d76ed9a9 AS |
4580 | AddChannelUser(opserv, opserv_conf.alert_channel)->modes |= MODE_CHANOP; |
4581 | } else { | |
258d1427 | 4582 | opserv_conf.alert_channel = NULL; |
d76ed9a9 AS |
4583 | } |
4584 | str = database_get_data(conf_node, KEY_STAFF_AUTH_CHANNEL, RECDB_QSTRING); | |
4585 | if (opserv && str) { | |
4586 | str2 = database_get_data(conf_node, KEY_STAFF_AUTH_CHANNEL_MODES, RECDB_QSTRING); | |
4587 | if (!str2) | |
4588 | str2 = "+timns"; | |
2aef5f4b | 4589 | opserv_conf.staff_auth_channel = AddChannel(str, now, str2, NULL, NULL); |
d76ed9a9 AS |
4590 | AddChannelUser(opserv, opserv_conf.staff_auth_channel)->modes |= MODE_CHANOP; |
4591 | } else { | |
4592 | opserv_conf.staff_auth_channel = NULL; | |
4593 | } | |
5a1daaab AS |
4594 | |
4595 | str = database_get_data(conf_node, KEY_ADMIN_LEVEL, RECDB_QSTRING); | |
4596 | opserv_conf.admin_level = str ? strtoul(str, NULL, 0): 800; | |
4597 | ||
d76ed9a9 AS |
4598 | str = database_get_data(conf_node, KEY_UNTRUSTED_MAX, RECDB_QSTRING); |
4599 | opserv_conf.untrusted_max = str ? strtoul(str, NULL, 0) : 5; | |
4600 | str = database_get_data(conf_node, KEY_PURGE_LOCK_DELAY, RECDB_QSTRING); | |
4601 | opserv_conf.purge_lock_delay = str ? strtoul(str, NULL, 0) : 60; | |
4602 | str = database_get_data(conf_node, KEY_JOIN_FLOOD_MODERATE, RECDB_QSTRING); | |
4603 | opserv_conf.join_flood_moderate = str ? strtoul(str, NULL, 0) : 1; | |
4604 | str = database_get_data(conf_node, KEY_JOIN_FLOOD_MODERATE_THRESH, RECDB_QSTRING); | |
4605 | opserv_conf.join_flood_moderate_threshold = str ? strtoul(str, NULL, 0) : 50; | |
4606 | str = database_get_data(conf_node, KEY_NICK, RECDB_QSTRING); | |
4607 | if (opserv && str) | |
4608 | NickChange(opserv, str, 0); | |
d914d1cb | 4609 | |
d76ed9a9 AS |
4610 | str = database_get_data(conf_node, KEY_CLONE_GLINE_DURATION, RECDB_QSTRING); |
4611 | opserv_conf.clone_gline_duration = str ? ParseInterval(str) : 3600; | |
4612 | str = database_get_data(conf_node, KEY_BLOCK_GLINE_DURATION, RECDB_QSTRING); | |
4613 | opserv_conf.block_gline_duration = str ? ParseInterval(str) : 3600; | |
4614 | ||
d914d1cb | 4615 | str = database_get_data(conf_node, KEY_BLOCK_SHUN_DURATION, RECDB_QSTRING); |
4616 | opserv_conf.block_shun_duration = str ? ParseInterval(str) : 3600; | |
4617 | ||
d76ed9a9 AS |
4618 | if (!opserv_conf.join_policer_params) |
4619 | opserv_conf.join_policer_params = policer_params_new(); | |
4620 | policer_params_set(opserv_conf.join_policer_params, "size", "20"); | |
4621 | policer_params_set(opserv_conf.join_policer_params, "drain-rate", "1"); | |
4622 | if ((child = database_get_data(conf_node, KEY_JOIN_POLICER, RECDB_OBJECT))) | |
258d1427 | 4623 | dict_foreach(child, set_policer_param, opserv_conf.join_policer_params); |
d76ed9a9 AS |
4624 | |
4625 | for (it = dict_first(channels); it; it = iter_next(it)) { | |
4626 | struct chanNode *cNode = iter_data(it); | |
4627 | cNode->join_policer.params = opserv_conf.join_policer_params; | |
4628 | } | |
4629 | ||
4630 | if (opserv_conf.new_user_policer.params) | |
4631 | pp = opserv_conf.new_user_policer.params; | |
4632 | else | |
4633 | pp = opserv_conf.new_user_policer.params = policer_params_new(); | |
4634 | policer_params_set(pp, "size", "200"); | |
4635 | policer_params_set(pp, "drain-rate", "3"); | |
4636 | if ((child = database_get_data(conf_node, KEY_NEW_USER_POLICER, RECDB_OBJECT))) | |
258d1427 | 4637 | dict_foreach(child, set_policer_param, pp); |
d76ed9a9 AS |
4638 | } |
4639 | ||
5a1daaab AS |
4640 | /* lame way to export opserv_conf value to nickserv.c ... */ |
4641 | unsigned int | |
4642 | opserv_conf_admin_level() | |
4643 | { | |
4644 | return(opserv_conf.admin_level); | |
4645 | } | |
4646 | ||
d76ed9a9 AS |
4647 | static void |
4648 | opserv_db_init(void) { | |
4649 | /* set up opserv_trusted_hosts dict */ | |
4650 | dict_delete(opserv_trusted_hosts); | |
4651 | opserv_trusted_hosts = dict_new(); | |
4652 | dict_set_free_data(opserv_trusted_hosts, free_trusted_host); | |
4653 | /* set up opserv_chan_warn dict */ | |
de9510bc AS |
4654 | |
4655 | /* alert trace notice channel #x replaces warnings | |
d76ed9a9 AS |
4656 | dict_delete(opserv_chan_warn); |
4657 | opserv_chan_warn = dict_new(); | |
4658 | dict_set_free_keys(opserv_chan_warn, free); | |
4659 | dict_set_free_data(opserv_chan_warn, free); | |
de9510bc | 4660 | */ |
d76ed9a9 AS |
4661 | /* set up opserv_user_alerts */ |
4662 | dict_delete(opserv_channel_alerts); | |
4663 | opserv_channel_alerts = dict_new(); | |
4664 | dict_delete(opserv_nick_based_alerts); | |
4665 | opserv_nick_based_alerts = dict_new(); | |
4666 | dict_delete(opserv_user_alerts); | |
4667 | opserv_user_alerts = dict_new(); | |
4668 | dict_set_free_keys(opserv_user_alerts, free); | |
4669 | dict_set_free_data(opserv_user_alerts, opserv_free_user_alert); | |
4670 | /* set up opserv_bad_words */ | |
4671 | free_string_list(opserv_bad_words); | |
4672 | opserv_bad_words = alloc_string_list(4); | |
4673 | /* and opserv_exempt_channels */ | |
4674 | dict_delete(opserv_exempt_channels); | |
4675 | opserv_exempt_channels = dict_new(); | |
4676 | dict_set_free_keys(opserv_exempt_channels, free); | |
4677 | } | |
4678 | ||
4679 | static void | |
4680 | opserv_db_cleanup(void) | |
4681 | { | |
4682 | unsigned int nn; | |
4683 | ||
de9510bc | 4684 | /* dict_delete(opserv_chan_warn); */ |
d76ed9a9 AS |
4685 | dict_delete(opserv_reserved_nick_dict); |
4686 | free_string_list(opserv_bad_words); | |
4687 | dict_delete(opserv_exempt_channels); | |
4688 | dict_delete(opserv_trusted_hosts); | |
4689 | unreg_del_user_func(opserv_user_cleanup); | |
4690 | dict_delete(opserv_hostinfo_dict); | |
4691 | dict_delete(opserv_nick_based_alerts); | |
4692 | dict_delete(opserv_channel_alerts); | |
4693 | dict_delete(opserv_user_alerts); | |
4694 | for (nn=0; nn<ArrayLength(level_strings); ++nn) | |
4695 | free(level_strings[nn]); | |
4696 | while (gagList) | |
4697 | gag_free(gagList); | |
4698 | policer_params_delete(opserv_conf.join_policer_params); | |
4699 | policer_params_delete(opserv_conf.new_user_policer.params); | |
4700 | } | |
4701 | ||
4702 | void | |
4703 | init_opserv(const char *nick) | |
4704 | { | |
4705 | OS_LOG = log_register_type("OpServ", "file:opserv.log"); | |
a32da4c7 | 4706 | if (nick) { |
4707 | const char *modes = conf_get_data("services/opserv/modes", RECDB_QSTRING); | |
4708 | opserv = AddService(nick, modes ? modes : NULL, "Oper Services", NULL); | |
4709 | } | |
d76ed9a9 AS |
4710 | conf_register_reload(opserv_conf_read); |
4711 | ||
4712 | memset(level_strings, 0, sizeof(level_strings)); | |
4713 | opserv_module = module_register("OpServ", OS_LOG, "opserv.help", opserv_help_expand); | |
4714 | opserv_define_func("ACCESS", cmd_access, 0, 0, 0); | |
4715 | opserv_define_func("ADDALERT", cmd_addalert, 800, 0, 4); | |
4716 | opserv_define_func("ADDALERT NOTICE", NULL, 0, 0, 0); | |
9a75756e | 4717 | opserv_define_func("ADDALERT SILENT", NULL, 900, 0, 0); |
d76ed9a9 | 4718 | opserv_define_func("ADDALERT GLINE", NULL, 900, 0, 0); |
d914d1cb | 4719 | opserv_define_func("ADDALERT SHUN", NULL, 900, 0, 0); |
d76ed9a9 AS |
4720 | opserv_define_func("ADDALERT KILL", NULL, 900, 0, 0); |
4721 | opserv_define_func("ADDBAD", cmd_addbad, 800, 0, 2); | |
4722 | opserv_define_func("ADDEXEMPT", cmd_addexempt, 800, 0, 2); | |
4723 | opserv_define_func("ADDTRUST", cmd_addtrust, 800, 0, 5); | |
4724 | opserv_define_func("BAN", cmd_ban, 100, 2, 2); | |
4725 | opserv_define_func("BLOCK", cmd_block, 100, 0, 2); | |
4726 | opserv_define_func("CHANINFO", cmd_chaninfo, 0, 3, 0); | |
4727 | opserv_define_func("CLEARBANS", cmd_clearbans, 300, 2, 0); | |
4728 | opserv_define_func("CLEARMODES", cmd_clearmodes, 400, 2, 0); | |
4729 | opserv_define_func("CLONE", cmd_clone, 999, 0, 3); | |
4730 | opserv_define_func("COLLIDE", cmd_collide, 800, 0, 5); | |
4731 | opserv_define_func("CSEARCH", cmd_csearch, 100, 0, 3); | |
4732 | opserv_define_func("CSEARCH COUNT", cmd_csearch, 0, 0, 0); | |
4733 | opserv_define_func("CSEARCH PRINT", cmd_csearch, 0, 0, 0); | |
4734 | opserv_define_func("DELALERT", cmd_delalert, 800, 0, 2); | |
4735 | opserv_define_func("DELBAD", cmd_delbad, 800, 0, 2); | |
4736 | opserv_define_func("DELEXEMPT", cmd_delexempt, 800, 0, 2); | |
4737 | opserv_define_func("DELTRUST", cmd_deltrust, 800, 0, 2); | |
4738 | opserv_define_func("DEOP", cmd_deop, 100, 2, 2); | |
4739 | opserv_define_func("DEOPALL", cmd_deopall, 400, 2, 0); | |
55342ce8 | 4740 | opserv_define_func("DEHOP", cmd_dehop, 100, 2, 2); |
4741 | opserv_define_func("DEHOPALL", cmd_dehopall, 400, 2, 0); | |
d76ed9a9 AS |
4742 | opserv_define_func("DEVOICEALL", cmd_devoiceall, 300, 2, 0); |
4743 | opserv_define_func("DIE", cmd_die, 900, 0, 2); | |
4744 | opserv_define_func("DUMP", cmd_dump, 999, 0, 2); | |
4745 | opserv_define_func("EDITTRUST", cmd_edittrust, 800, 0, 5); | |
4746 | opserv_define_func("GAG", cmd_gag, 600, 0, 4); | |
4747 | opserv_define_func("GLINE", cmd_gline, 600, 0, 4); | |
4748 | opserv_define_func("GSYNC", cmd_gsync, 600, 0, 0); | |
4749 | opserv_define_func("GTRACE", cmd_gtrace, 100, 0, 3); | |
4750 | opserv_define_func("GTRACE COUNT", NULL, 0, 0, 0); | |
4751 | opserv_define_func("GTRACE PRINT", NULL, 0, 0, 0); | |
d914d1cb | 4752 | opserv_define_func("SBLOCK", cmd_sblock, 100, 0, 2); |
4753 | opserv_define_func("SHUN", cmd_shun, 600, 0, 4); | |
4754 | opserv_define_func("SSYNC", cmd_ssync, 600, 0, 0); | |
4755 | opserv_define_func("STRACE", cmd_strace, 100, 0, 3); | |
4756 | opserv_define_func("STRACE COUNT", NULL, 0, 0, 0); | |
4757 | opserv_define_func("STRACE PRINT", NULL, 0, 0, 0); | |
d76ed9a9 AS |
4758 | opserv_define_func("INVITE", cmd_invite, 100, 2, 0); |
4759 | opserv_define_func("INVITEME", cmd_inviteme, 100, 0, 0); | |
4760 | opserv_define_func("JOIN", cmd_join, 601, 0, 2); | |
4761 | opserv_define_func("JUMP", cmd_jump, 900, 0, 2); | |
4762 | opserv_define_func("JUPE", cmd_jupe, 900, 0, 4); | |
4763 | opserv_define_func("KICK", cmd_kick, 100, 2, 2); | |
4764 | opserv_define_func("KICKALL", cmd_kickall, 400, 2, 0); | |
4765 | opserv_define_func("KICKBAN", cmd_kickban, 100, 2, 2); | |
4766 | opserv_define_func("KICKBANALL", cmd_kickbanall, 450, 2, 0); | |
4767 | opserv_define_func("LOG", cmd_log, 900, 0, 2); | |
4768 | opserv_define_func("MODE", cmd_mode, 100, 2, 2); | |
4769 | opserv_define_func("OP", cmd_op, 100, 2, 2); | |
4770 | opserv_define_func("OPALL", cmd_opall, 400, 2, 0); | |
55342ce8 | 4771 | opserv_define_func("HOP", cmd_hop, 100, 2, 2); |
4772 | opserv_define_func("HOPALL", cmd_hopall, 400, 2, 0); | |
d76ed9a9 AS |
4773 | opserv_define_func("PART", cmd_part, 601, 0, 2); |
4774 | opserv_define_func("QUERY", cmd_query, 0, 0, 0); | |
4775 | opserv_define_func("RAW", cmd_raw, 999, 0, 2); | |
4776 | opserv_define_func("RECONNECT", cmd_reconnect, 900, 0, 0); | |
4777 | opserv_define_func("REFRESHG", cmd_refreshg, 600, 0, 0); | |
d914d1cb | 4778 | opserv_define_func("REFRESHS", cmd_refreshs, 600, 0, 0); |
d76ed9a9 AS |
4779 | opserv_define_func("REHASH", cmd_rehash, 900, 0, 0); |
4780 | opserv_define_func("REOPEN", cmd_reopen, 900, 0, 0); | |
4781 | opserv_define_func("RESERVE", cmd_reserve, 800, 0, 5); | |
4782 | opserv_define_func("RESTART", cmd_restart, 900, 0, 2); | |
4783 | opserv_define_func("SET", cmd_set, 900, 0, 3); | |
4784 | opserv_define_func("SETTIME", cmd_settime, 901, 0, 0); | |
4785 | opserv_define_func("STATS ALERTS", cmd_stats_alerts, 0, 0, 0); | |
4786 | opserv_define_func("STATS BAD", cmd_stats_bad, 0, 0, 0); | |
4787 | opserv_define_func("STATS GAGS", cmd_stats_gags, 0, 0, 0); | |
4788 | opserv_define_func("STATS GLINES", cmd_stats_glines, 0, 0, 0); | |
d914d1cb | 4789 | opserv_define_func("STATS SHUNS", cmd_stats_shuns, 0, 0, 0); |
d76ed9a9 AS |
4790 | opserv_define_func("STATS LINKS", cmd_stats_links, 0, 0, 0); |
4791 | opserv_define_func("STATS MAX", cmd_stats_max, 0, 0, 0); | |
4792 | opserv_define_func("STATS NETWORK", cmd_stats_network, 0, 0, 0); | |
4793 | opserv_define_func("STATS NETWORK2", cmd_stats_network2, 0, 0, 0); | |
4794 | opserv_define_func("STATS RESERVED", cmd_stats_reserved, 0, 0, 0); | |
4795 | opserv_define_func("STATS TIMEQ", cmd_stats_timeq, 0, 0, 0); | |
4796 | opserv_define_func("STATS TRUSTED", cmd_stats_trusted, 0, 0, 0); | |
4797 | opserv_define_func("STATS UPLINK", cmd_stats_uplink, 0, 0, 0); | |
4798 | opserv_define_func("STATS UPTIME", cmd_stats_uptime, 0, 0, 0); | |
de9510bc | 4799 | /* opserv_define_func("STATS WARN", cmd_stats_warn, 0, 0, 0); */ |
f14e4f83 | 4800 | #if defined(WITH_MALLOC_X3) || defined(WITH_MALLOC_SLAB) |
ec1a68c8 | 4801 | opserv_define_func("STATS MEMORY", cmd_stats_memory, 0, 0, 0); |
4802 | #endif | |
d76ed9a9 AS |
4803 | opserv_define_func("TRACE", cmd_trace, 100, 0, 3); |
4804 | opserv_define_func("TRACE PRINT", NULL, 0, 0, 0); | |
4805 | opserv_define_func("TRACE COUNT", NULL, 0, 0, 0); | |
4806 | opserv_define_func("TRACE DOMAINS", NULL, 0, 0, 0); | |
4807 | opserv_define_func("TRACE GLINE", NULL, 600, 0, 0); | |
d914d1cb | 4808 | opserv_define_func("TRACE SHUN", NULL, 600, 0, 0); |
d76ed9a9 AS |
4809 | opserv_define_func("TRACE GAG", NULL, 600, 0, 0); |
4810 | opserv_define_func("TRACE KILL", NULL, 600, 0, 0); | |
4811 | opserv_define_func("UNBAN", cmd_unban, 100, 2, 2); | |
4812 | opserv_define_func("UNGAG", cmd_ungag, 600, 0, 2); | |
4813 | opserv_define_func("UNGLINE", cmd_ungline, 600, 0, 2); | |
4814 | modcmd_register(opserv_module, "GTRACE UNGLINE", NULL, 0, 0, "template", "ungline", NULL); | |
d914d1cb | 4815 | opserv_define_func("UNSHUN", cmd_unshun, 600, 0, 2); |
4816 | modcmd_register(opserv_module, "GTRACE UNSHUN", NULL, 0, 0, "template", "unshun", NULL); | |
d76ed9a9 AS |
4817 | opserv_define_func("UNJUPE", cmd_unjupe, 900, 0, 2); |
4818 | opserv_define_func("UNRESERVE", cmd_unreserve, 800, 0, 2); | |
de9510bc | 4819 | /* opserv_define_func("UNWARN", cmd_unwarn, 800, 0, 0); */ |
d76ed9a9 | 4820 | opserv_define_func("VOICEALL", cmd_voiceall, 300, 2, 0); |
de9510bc | 4821 | /* opserv_define_func("WARN", cmd_warn, 800, 0, 2); */ |
d76ed9a9 AS |
4822 | opserv_define_func("WHOIS", cmd_whois, 0, 0, 2); |
4823 | ||
4824 | opserv_reserved_nick_dict = dict_new(); | |
4825 | opserv_hostinfo_dict = dict_new(); | |
4826 | dict_set_free_keys(opserv_hostinfo_dict, free); | |
4827 | dict_set_free_data(opserv_hostinfo_dict, opserv_free_hostinfo); | |
4828 | ||
4829 | reg_new_user_func(opserv_new_user_check); | |
4830 | reg_nick_change_func(opserv_alert_check_nick); | |
4831 | reg_del_user_func(opserv_user_cleanup); | |
c52666c6 | 4832 | reg_new_channel_func(opserv_channel_check); |
d76ed9a9 AS |
4833 | reg_del_channel_func(opserv_channel_delete); |
4834 | reg_join_func(opserv_join_check); | |
4835 | reg_auth_func(opserv_staff_alert); | |
4836 | ||
4837 | opserv_db_init(); | |
4838 | saxdb_register("OpServ", opserv_saxdb_read, opserv_saxdb_write); | |
4839 | if (nick) | |
258d1427 AS |
4840 | { |
4841 | opserv_service = service_register(opserv); | |
4842 | opserv_service->trigger = '?'; | |
4843 | } | |
d76ed9a9 AS |
4844 | |
4845 | reg_exit_func(opserv_db_cleanup); | |
4846 | message_register_table(msgtab); | |
4847 | } |