]>
jfr.im git - irc/evilnet/x3.git/blob - src/mod-snoop.c
1 /* mod-snoop.c - User surveillance module (per pomac's spec)
2 * Copyright 2002-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 /* Adds new section to srvx.conf:
24 * // Where to send snoop messages?
25 * "channel" "#wherever";
28 * // Show new users and joins from net joins? (off by default)
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
41 #ifdef HAVE_ARPA_INET_H
42 #include <arpa/inet.h>
47 struct chanNode
*channel
;
49 unsigned int show_bursts
: 1;
50 unsigned int enabled
: 1;
52 static char timestamp
[16];
53 const char *snoop_module_deps
[] = { NULL
};
56 int snoop_finalize(void);
58 #if defined(GCC_VARMACROS)
59 # define SNOOP(FORMAT, ARGS...) send_channel_message(snoop_cfg.channel, snoop_cfg.bot, "%s "FORMAT, timestamp, ARGS)
60 #elif defined(C99_VARMACROS)
61 # define SNOOP(FORMAT, ...) send_channel_message(snoop_cfg.channel, snoop_cfg.bot, "%s "FORMAT, timestamp, __VA_ARGS__)
63 #define UPDATE_TIMESTAMP() strftime(timestamp, sizeof(timestamp), "[%H:%M:%S]", localtime(&now))
66 snoop_nick_change(struct userNode
*user
, const char *old_nick
) {
67 if (!snoop_cfg
.enabled
) return;
69 SNOOP("$bNICK$b change %s -> %s", old_nick
, user
->nick
);
73 snoop_join(struct modeNode
*mNode
) {
74 struct userNode
*user
= mNode
->user
;
75 struct chanNode
*chan
= mNode
->channel
;
76 if (!snoop_cfg
.enabled
) return 0;
77 if (user
->uplink
->burst
&& !snoop_cfg
.show_bursts
) return 0;
79 if (chan
->members
.used
== 1) {
80 SNOOP("$bCREATE$b %s by %s", chan
->name
, user
->nick
);
82 SNOOP("$bJOIN$b %s by %s", chan
->name
, user
->nick
);
88 snoop_part(struct modeNode
*mn
, const char *reason
) {
89 if (!snoop_cfg
.enabled
) return;
90 if (mn
->user
->dead
) return;
92 SNOOP("$bPART$b %s by %s (%s)", mn
->channel
->name
, mn
->user
->nick
, reason
? reason
: "");
96 snoop_kick(struct userNode
*kicker
, struct userNode
*victim
, struct chanNode
*chan
) {
97 if (!snoop_cfg
.enabled
) return;
99 SNOOP("$bKICK$b %s from %s by %s", victim
->nick
, chan
->name
, (kicker
? kicker
->nick
: "some server"));
103 snoop_new_user(struct userNode
*user
) {
104 if (!snoop_cfg
.enabled
) return 0;
105 if (user
->uplink
->burst
&& !snoop_cfg
.show_bursts
) return 0;
107 SNOOP("$bNICK$b %s %s@%s (%s) [%s] on %s", user
->nick
, user
->ident
, user
->hostname
, user
->handle_info
?user
->handle_info
->handle
:"", irc_ntoa(&user
->ip
), user
->uplink
->name
);
112 snoop_del_user(struct userNode
*user
, struct userNode
*killer
, const char *why
) {
113 if (!snoop_cfg
.enabled
) return;
116 SNOOP("$bKILL$b %s (%s@%s, on %s) by %s (%s)", user
->nick
, user
->ident
, user
->hostname
, user
->uplink
->name
, killer
->nick
, why
);
118 SNOOP("$bQUIT$b %s (%s@%s, on %s) (%s)", user
->nick
, user
->ident
, user
->hostname
, user
->uplink
->name
, why
);
123 snoop_auth(struct userNode
*user
, UNUSED_ARG(struct handle_info
*old_handle
)) {
124 if (!snoop_cfg
.enabled
) return;
125 if (user
->uplink
->burst
&& !snoop_cfg
.show_bursts
) return;
126 if (user
->handle_info
) {
128 /* TODO: show old_handle info -> new handle info if they
129 * re-authed or something.
131 SNOOP("$bAUTH$b %s as %s", user
->nick
, user
->handle_info
->handle
);
136 snoop_user_mode(struct userNode
*user
, const char *mode_change
) {
137 if (!snoop_cfg
.enabled
) return;
138 if (user
->uplink
->burst
&& !snoop_cfg
.show_bursts
) return;
139 if (!mode_change
[1]) return; /* warning there has to be atleast one char in the buffer */
141 SNOOP("$bUMODE$b %s %s", user
->nick
, mode_change
);
145 snoop_oper(struct userNode
*user
) {
146 if (!snoop_cfg
.enabled
) return;
147 if (user
->uplink
->burst
&& !snoop_cfg
.show_bursts
) return;
149 SNOOP("$bOPER$b %s!%s@%s [%s] on %s", user
->nick
, user
->ident
, user
->hostname
, irc_ntoa(&user
->ip
), user
->uplink
->name
);
153 snoop_channel_mode(struct userNode
*who
, struct chanNode
*channel
, char **modes
, unsigned int argc
)
155 if (!snoop_cfg
.enabled
) return;
157 if (who
->uplink
->burst
&& !snoop_cfg
.show_bursts
) {
161 return; /* Dont show X3 etc modes */
164 static char targets
[MAXLEN
], string
[MAXLEN
];
165 struct userNode
*un
= NULL
;
166 char *tmp
= NULL
, *tg
= NULL
, *md
= NULL
;
173 unsplit_string(modes
, argc
, string
);
175 strcpy(string
, *modes
);
177 if((tg
= strchr(string
, ' ')))
180 for(md
= string
; *md
; md
++)
196 strcat(targets
, " ");
197 if ((tmp
= strchr(tg
, ' ')))
208 strcat(targets
, " ");
209 if ((tmp
= strchr(tg
, ' ')))
219 strcat(targets
, " ");
220 if ((tmp
= strchr(tg
, ' ')))
229 strcat(targets
, " ");
230 if ((tmp
= strchr(tg
, ' ')))
239 strcat(targets
, " ");
240 if ((tmp
= strchr(tg
, ' ')))
242 if((un
= GetUserN(tg
)))
243 strcat(targets
, un
->nick
);
252 strcat(targets
, " ");
253 if ((tmp
= strchr(tg
, ' ')))
255 if((un
= GetUserN(tg
)))
256 strcat(targets
, un
->nick
);
265 strcat(targets
, " ");
266 if ((tmp
= strchr(tg
, ' ')))
268 if((un
= GetUserN(tg
)))
269 strcat(targets
, un
->nick
);
281 SNOOP("$bMODE$b %s %s%s by %s", channel
->name
, string
, targets
, who
->nick
);
283 SNOOP("$bMODE$b %s %s%s", channel
->name
, string
, targets
);
287 snoop_conf_read(void) {
291 node
= conf_get_data("modules/snoop", RECDB_OBJECT
);
294 str
= database_get_data(node
, "channel", RECDB_QSTRING
);
297 snoop_cfg
.channel
= AddChannel(str
, now
, "+sntim", NULL
, NULL
);
298 if (!snoop_cfg
.channel
)
300 str
= database_get_data(node
, "show_bursts", RECDB_QSTRING
);
301 snoop_cfg
.show_bursts
= str
? enabled_string(str
) : 0;
302 snoop_cfg
.enabled
= 1;
308 snoop_cleanup(void) {
309 snoop_cfg
.enabled
= 0;
310 unreg_del_user_func(snoop_del_user
);
315 reg_exit_func(snoop_cleanup
);
316 conf_register_reload(snoop_conf_read
);
317 reg_nick_change_func(snoop_nick_change
);
318 reg_join_func(snoop_join
);
319 reg_part_func(snoop_part
);
320 reg_kick_func(snoop_kick
);
321 reg_new_user_func(snoop_new_user
);
322 reg_del_user_func(snoop_del_user
);
323 reg_auth_func(snoop_auth
);
324 reg_channel_mode_func(snoop_channel_mode
);
325 reg_user_mode_func(snoop_user_mode
);
326 reg_oper_func(snoop_oper
);
332 snoop_finalize(void) {
333 struct mod_chanmode change
;
338 node
= conf_get_data("modules/snoop", RECDB_OBJECT
);
341 str
= database_get_data(node
, "bot", RECDB_QSTRING
);
344 snoop_cfg
.bot
= GetUserH(str
);
347 mod_chanmode_init(&change
);
349 change
.args
[0].mode
= MODE_CHANOP
;
350 change
.args
[0].u
.member
= AddChannelUser(snoop_cfg
.bot
, snoop_cfg
.channel
);
351 mod_chanmode_announce(snoop_cfg
.bot
, snoop_cfg
.channel
, &change
);