1 |
/* Copyright (C) 2004 Stephane Thiell |
2 |
* |
3 |
* This file is part of pxyservd (from pxys) |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2 |
8 |
* of the License, or (at your option) any later version. |
9 |
* |
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. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
* |
19 |
*/ |
20 |
#define RCSID "$Id: cmd_recheck.c,v 1.1 2004/01/12 12:32:34 mbuna Exp $" |
21 |
|
22 |
#include "irc_cmd.h" |
23 |
#include "irc_msg.h" |
24 |
#include "irc_send.h" |
25 |
#include "cfgloader.h" |
26 |
|
27 |
#include "irc_membership.h" |
28 |
#include "irc_channel.h" |
29 |
#include "irc_client.h" |
30 |
#include "irc_userbase.h" |
31 |
#include "scan.h" /* scan_check_noscan() */ |
32 |
#include "PXServiceMsg.h" |
33 |
|
34 |
#include <peak/peak.h> |
35 |
|
36 |
#include <assert.h> |
37 |
#include <sys/types.h> |
38 |
#include <sys/socket.h> |
39 |
#include <netinet/in.h> |
40 |
#include <arpa/inet.h> |
41 |
|
42 |
struct _iter_pack |
43 |
{ |
44 |
struct Client *cptr; |
45 |
const char *dst; |
46 |
uint32_t noscan_cnt; |
47 |
uint32_t scan_cnt; |
48 |
}; |
49 |
|
50 |
static unsigned long |
51 |
recheck_chan_iter_cb(smat_table_t *table, smat_entry_t *e, void *extra) |
52 |
{ |
53 |
struct _iter_pack *pack = (struct _iter_pack *)extra; |
54 |
struct Client *target = se_object(e, MEMBERSHIP_LOC_CLIENT); |
55 |
PXSRemove4 rem_request; |
56 |
|
57 |
if (scan_check_noscan(target)) |
58 |
{ |
59 |
pack->noscan_cnt++; |
60 |
return 0; |
61 |
} |
62 |
|
63 |
if (!(target->flags & (CLIENT_FLAG_IPV6|CLIENT_FLAG_SCANNING))) |
64 |
{ |
65 |
rem_request.addr = target->addr.ip4; |
66 |
if (scan_send_command(pack->cptr, PXYSCAND_SIG, PX_CMD_REMOVE, |
67 |
&rem_request, sizeof(rem_request)) == -1) |
68 |
{ |
69 |
send_client_to_one(pack->dst, "/!\\ Scanner daemon not connected." |
70 |
" Can't recheck at the moment."); |
71 |
return 1; /* stop iterate */ |
72 |
} |
73 |
pack->scan_cnt++; |
74 |
scan_start(target); /* start scan */ |
75 |
} |
76 |
|
77 |
return 0; |
78 |
} |
79 |
|
80 |
static void |
81 |
recheck_chan(struct Client *cptr, const char *dst, toktabptr ttab) |
82 |
{ |
83 |
struct Channel *c; |
84 |
unsigned long err, cnt; |
85 |
|
86 |
if (!(c = irc_channel_get(ttab->tok[4]))) |
87 |
{ |
88 |
send_client_to_one(dst, "Channel not found."); |
89 |
return; |
90 |
} |
91 |
|
92 |
cnt = sh_count(&c->mhead); |
93 |
if (cnt > 0) |
94 |
{ |
95 |
struct _iter_pack pack = { cptr, dst, 0, 0 }; |
96 |
err = sh_iter(&c->mhead, NULL, recheck_chan_iter_cb, &pack, 0); |
97 |
if (err == 0) |
98 |
{ |
99 |
char ipbuf[64]; |
100 |
|
101 |
send_client_to_one(dst, "RECHECK: %s - %lu users (%lu added to ScanQ," |
102 |
" %lu in NOSCAN)", c->chname, cnt, pack.scan_cnt, |
103 |
pack.noscan_cnt); |
104 |
|
105 |
inet_ntop(cptr->flags & CLIENT_FLAG_IPV6 ? AF_INET6 : AF_INET, |
106 |
&cptr->addr, ipbuf, sizeof(ipbuf)); |
107 |
send_to_console("[%s] %s[%s] RECHECK %s", gConfig->server.id, |
108 |
cptr->nick, ipbuf, c->chname); |
109 |
} |
110 |
} |
111 |
else |
112 |
{ |
113 |
/* Channel chucked, not yet really deleted. */ |
114 |
send_client_to_one(dst, "Channel's just been deleted: no user found"); |
115 |
} |
116 |
} |
117 |
|
118 |
static void |
119 |
recheck_nick(struct Client *cptr, const char *dst, toktabptr ttab) |
120 |
{ |
121 |
struct Client *target; |
122 |
PXSRemove4 rem_request; |
123 |
char ipbuf[16]; |
124 |
|
125 |
if (!(target = irc_userbase_get_by_nick(ttab->tok[4]))) |
126 |
{ |
127 |
send_client_to_one(dst, "User not found."); |
128 |
return; |
129 |
} |
130 |
|
131 |
if (scan_check_noscan(target)) |
132 |
{ |
133 |
send_client_to_one(dst, "User's tagged as NOSCAN; can't recheck"); |
134 |
return; |
135 |
} |
136 |
|
137 |
if (target->flags & CLIENT_FLAG_IPV6) |
138 |
return; /* not supported yet */ |
139 |
|
140 |
inet_ntop(AF_INET, &target->addr, ipbuf, sizeof(ipbuf)); |
141 |
|
142 |
if (target->flags & CLIENT_FLAG_SCANNING) |
143 |
{ |
144 |
send_client_to_one(dst, "User %s (%s) is already in ScanQ" |
145 |
" (waiting or being scanned)", target->nick, ipbuf); |
146 |
return; |
147 |
} |
148 |
|
149 |
/* Passed "test"; recheck client */ |
150 |
rem_request.addr = target->addr.ip4; |
151 |
if (scan_send_command(cptr, PXYSCAND_SIG, PX_CMD_REMOVE, |
152 |
&rem_request, sizeof(rem_request)) == -1) |
153 |
{ |
154 |
send_client_to_one(dst, "/!\\ Scanner daemon not connected." |
155 |
" Can't recheck at the moment."); |
156 |
return; |
157 |
} |
158 |
scan_start(target); /* start scan */ |
159 |
send_client_to_one(dst, "User %s (%s) added to ScanQ" |
160 |
" (will be scanned ASAP)", target->nick, ipbuf); |
161 |
} |
162 |
|
163 |
void |
164 |
cmd_recheck(struct Client *cptr, toktabptr ttab) |
165 |
{ |
166 |
const char *dst = ttab->tok[0]; |
167 |
|
168 |
if (ttab->size < 5) |
169 |
{ |
170 |
send_client_to_one(dst, "Syntax: RECHECK <nickname|channel>"); |
171 |
return; |
172 |
} |
173 |
|
174 |
if (IsChannelName(ttab->tok[4])) |
175 |
recheck_chan(cptr, dst, ttab); |
176 |
else |
177 |
recheck_nick(cptr, dst, ttab); |
178 |
} |
179 |
|
180 |
void |
181 |
cmd_recheck_reply(struct Client *cptr, PXSRemove4 *rem_reply) |
182 |
{ |
183 |
/* Be quiet. */ |
184 |
} |