1 /* mod-snoop.c - User surveillance module (per pomac's spec)
2 * Copyright 2002-2004 srvx Development Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email srvx-maintainers@srvx.net.
19 /* Adds new section to srvx.conf:
22 * // Where to send snoop messages?
23 * "channel" "#wherever";
26 * // Show new users and joins from net joins? (off by default)
36 #ifdef HAVE_NETINET_IN_H
37 #include <netinet/in.h>
39 #ifdef HAVE_ARPA_INET_H
40 #include <arpa/inet.h>
45 struct chanNode *channel;
47 unsigned int show_bursts : 1;
48 unsigned int enabled : 1;
50 static char timestamp[16];
51 const char *snoop_module_deps[] = { NULL };
54 int snoop_finalize(void);
56 #define SNOOP(FORMAT, ARGS...) send_channel_message(snoop_cfg.channel, snoop_cfg.bot, "%s "FORMAT, timestamp , ## ARGS)
57 #define UPDATE_TIMESTAMP() strftime(timestamp, sizeof(timestamp), "[%H:%M:%S]", localtime(&now))
60 snoop_nick_change(struct userNode *user, const char *old_nick) {
61 if (!snoop_cfg.enabled) return;
63 SNOOP("$bNICK$b change %s -> %s", old_nick, user->nick);
67 snoop_join(struct modeNode *mNode) {
68 struct userNode *user = mNode->user;
69 struct chanNode *chan = mNode->channel;
70 if (!snoop_cfg.enabled) return 0;
71 if (user->uplink->burst && !snoop_cfg.show_bursts) return 0;
73 if (chan->members.used == 1) {
74 SNOOP("$bCREATE$b %s by %s", chan->name, user->nick);
76 SNOOP("$bJOIN$b %s by %s", chan->name, user->nick);
82 snoop_part(struct userNode *user, struct chanNode *chan, const char *reason) {
83 if (!snoop_cfg.enabled) return;
84 if (user->dead) return;
86 SNOOP("$bPART$b %s by %s (%s)", chan->name, user->nick, reason ? reason : "");
90 snoop_kick(struct userNode *kicker, struct userNode *victim, struct chanNode *chan) {
91 if (!snoop_cfg.enabled) return;
93 SNOOP("$bKICK$b %s from %s by %s", victim->nick, chan->name, (kicker ? kicker->nick : "some server"));
97 snoop_new_user(struct userNode *user) {
98 if (!snoop_cfg.enabled) return 0;
99 if (user->uplink->burst && !snoop_cfg.show_bursts) return 0;
101 SNOOP("$bNICK$b %s %s@%s [%s] on %s", user->nick, user->ident, user->hostname, inet_ntoa(user->ip), user->uplink->name);
106 snoop_del_user(struct userNode *user, struct userNode *killer, const char *why) {
107 if (!snoop_cfg.enabled) return;
110 SNOOP("$bKILL$b %s (%s@%s, on %s) by %s (%s)", user->nick, user->ident, user->hostname, user->uplink->name, killer->nick, why);
112 SNOOP("$bQUIT$b %s (%s@%s, on %s) (%s)", user->nick, user->ident, user->hostname, user->uplink->name, why);
117 snoop_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) {
118 if (!snoop_cfg.enabled) return;
119 if (user->uplink->burst && !snoop_cfg.show_bursts) return;
120 if (user->handle_info) {
122 SNOOP("$bAUTH$b %s as %s", user->nick, user->handle_info->handle);
127 snoop_conf_read(void) {
131 node = conf_get_data("modules/snoop", RECDB_OBJECT);
134 str = database_get_data(node, "channel", RECDB_QSTRING);
137 snoop_cfg.channel = AddChannel(str, now, "+sntim", NULL);
138 if (!snoop_cfg.channel)
140 str = database_get_data(node, "show_bursts", RECDB_QSTRING);
141 snoop_cfg.show_bursts = str ? enabled_string(str) : 0;
142 snoop_cfg.enabled = 1;
148 snoop_cleanup(void) {
149 snoop_cfg.enabled = 0;
150 unreg_del_user_func(snoop_del_user);
155 reg_exit_func(snoop_cleanup);
156 conf_register_reload(snoop_conf_read);
157 reg_nick_change_func(snoop_nick_change);
158 reg_join_func(snoop_join);
159 reg_part_func(snoop_part);
160 reg_kick_func(snoop_kick);
161 reg_new_user_func(snoop_new_user);
162 reg_del_user_func(snoop_del_user);
163 reg_auth_func(snoop_auth);
164 /* Not implemented since hooks don't exist or lack data desired:
165 * chanmode (issuing user not listed)
172 snoop_finalize(void) {
173 struct mod_chanmode change;
178 node = conf_get_data("modules/snoop", RECDB_OBJECT);
181 str = database_get_data(node, "bot", RECDB_QSTRING);
184 snoop_cfg.bot = GetUserH(str);
187 change.modes_set = change.modes_clear = 0;
189 change.args[0].mode = MODE_CHANOP;
190 change.args[0].member = AddChannelUser(snoop_cfg.bot, snoop_cfg.channel);
191 mod_chanmode_announce(snoop_cfg.bot, snoop_cfg.channel, &change);