1 |
/* Copyright (C) 2003 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_grem.c,v 1.3 2006/09/10 22:00:27 spale Exp $" |
21 |
|
22 |
#include "irc_cmd.h" |
23 |
#include "irc_msg.h" |
24 |
#include "irc_send.h" |
25 |
|
26 |
#include "irc_network.h" |
27 |
#include "irc_numnicks.h" |
28 |
#include "scan.h" |
29 |
#include "PXServiceMsg.h" |
30 |
|
31 |
#include <peak/peak.h> |
32 |
#include <arpa/inet.h> |
33 |
#include <time.h> |
34 |
|
35 |
static void |
36 |
grem_usage(const char *dst) |
37 |
{ |
38 |
send_client_to_one(dst, "Syntax: GREM <IP>"); |
39 |
} |
40 |
|
41 |
void |
42 |
cmd_grem(struct Client *cptr, toktabptr ttab) |
43 |
{ |
44 |
const char *dst = ttab->tok[0]; |
45 |
const char *arg; |
46 |
PXSRemove4 rem_request; |
47 |
|
48 |
if (ttab->size < 5) |
49 |
{ |
50 |
grem_usage(dst); |
51 |
return; |
52 |
} |
53 |
|
54 |
arg = ttab->tok[4]; |
55 |
if ((arg[0] == '*') && (arg[1] == '@')) |
56 |
arg += 2; |
57 |
|
58 |
if (!*arg) /* "*@" ?? */ |
59 |
return; |
60 |
|
61 |
if (inet_pton(AF_INET, arg, &rem_request.addr) != 1) |
62 |
{ |
63 |
grem_usage(dst); |
64 |
return; |
65 |
} |
66 |
|
67 |
if (scan_send_command(cptr, PXYSCAND_SIG, PX_CMD_REMOVE, |
68 |
&rem_request, sizeof(rem_request)) == -1) |
69 |
send_client_to_one(dst, "/!\\ Scanner daemon not connected." |
70 |
" Can't ask it to remove IP from cache at the moment."); |
71 |
else |
72 |
cptr->flags |= CLIENT_FLAG_GREM; |
73 |
} |
74 |
|
75 |
void |
76 |
cmd_grem_reply(struct Client *cptr, PXSRemove4 *rem_reply) |
77 |
{ |
78 |
char dst[6], ipbuf[16]; |
79 |
int status; |
80 |
inttobase64(dst, cptr->nserv, 2); |
81 |
inttobase64(dst + 2, cptr->nnick, 3); |
82 |
dst[5] = '\0'; |
83 |
|
84 |
cptr->flags &= ~CLIENT_FLAG_GREM; |
85 |
|
86 |
status = ntohl(rem_reply->status) ? 1 : 0; |
87 |
|
88 |
if (inet_ntop(AF_INET, &rem_reply->addr, ipbuf, sizeof(ipbuf))) |
89 |
{ |
90 |
time_t now = time(NULL); |
91 |
if (status) |
92 |
{ |
93 |
send_client_to_one(dst, "GREM: Cache REMOVE successful for IP %s " |
94 |
"(from pxyscand)", ipbuf); |
95 |
send_client_to_one(dst, "GREM: Sending remgline to IRC network"); |
96 |
} |
97 |
else |
98 |
{ |
99 |
send_client_to_one(dst, "GREM: Cache REMOVE failed for IP %s " |
100 |
"(from pxyscand). Probably not in cache anymore", |
101 |
ipbuf); |
102 |
send_client_to_one(dst, "GREM: Sending remgline anyway"); |
103 |
} |
104 |
send_raw("%s " TOK_GLINE " * -*@%s %li %li" CRLF, gMe.yy, ipbuf, (long int)now, (long int)now); |
105 |
} |
106 |
} |