]>
Commit | Line | Data |
---|---|---|
905c2ba2 | 1 | #include "proxyscan.h" |
2 | #include "../irc/irc.h" | |
3 | #include "../lib/irc_string.h" | |
557c8cb2 | 4 | #include "../core/error.h" |
905c2ba2 | 5 | |
6 | void proxyscan_newnick(int hooknum, void *arg) { | |
7 | nick *np=(nick *)arg; | |
8 | cachehost *chp; | |
9 | foundproxy *fpp, *nfpp; | |
557c8cb2 P |
10 | extrascan *esp, *espp; |
11 | ||
905c2ba2 | 12 | int i; |
13 | ||
14 | /* Skip 127.* and 0.* hosts */ | |
c9db668b | 15 | if (irc_in_addr_is_loopback(&np->p_ipaddr) || !irc_in_addr_is_ipv4(&np->p_ipaddr)) |
905c2ba2 | 16 | return; |
17 | ||
557c8cb2 P |
18 | /* before we look at a normal host, see if we think we have an open proxy */ |
19 | if ((esp=findextrascan(np->ipnode))) { | |
20 | Error("proxyextra", ERR_ERROR, "connection from possible proxy %s", IPtostr(np->p_ipaddr)); | |
21 | for (espp=esp;espp;espp=espp->nextbynode) { | |
7eb07f57 P |
22 | /* we force a scan on any hosts that may be an open proxy, even if they are: |
23 | * a) already in the queue, b) we've been running < 120 seconds */ | |
557c8cb2 P |
24 | queuescan(np->ipnode, espp->type, espp->port, SCLASS_NORMAL, time(NULL)); |
25 | } | |
26 | } | |
bc78ddf6 | 27 | |
7eb07f57 P |
28 | /* ignore newnick until initial burst complete */ |
29 | if (!ps_ready) | |
bc78ddf6 P |
30 | return; |
31 | ||
905c2ba2 | 32 | /* |
33 | * Logic for connecting hosts: | |
34 | * | |
35 | * If they're in the cache and clean, return. | |
36 | * If they're in the cache, dirty, and last scanned < 30 | |
37 | * mins ago, return (they will probably go away in a minute) | |
38 | * If they're in the cache and dirty: | |
39 | * - gline them | |
40 | * - trigger the "check" scans on the known proxies | |
41 | * - trigger normal scans as for the case below.. | |
42 | * | |
43 | * If they're not in the cache, we queue up their scans | |
44 | */ | |
557c8cb2 | 45 | if ((chp=findcachehost(np->ipnode))) { |
905c2ba2 | 46 | if (!chp->proxies) |
47 | return; | |
48 | ||
49 | if (time(NULL) < (chp->lastscan + 1800)) | |
50 | return; | |
51 | ||
52 | /* Queue up all the normal scans - on the normal queue */ | |
53 | for (i=0;i<numscans;i++) { | |
54 | /* If this port is open DON'T queue the scan - we'll start it later in the CHECK class */ | |
55 | for (fpp=chp->proxies;fpp;fpp=fpp->next) { | |
56 | if (fpp->type == thescans[i].type && fpp->port == thescans[i].port) | |
57 | break; | |
58 | ||
59 | if (!fpp) | |
557c8cb2 | 60 | queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0); |
905c2ba2 | 61 | } |
62 | } | |
63 | ||
64 | /* We want these scans to start around now, so we put them at the front of the priority queue */ | |
65 | for (fpp=chp->proxies;fpp;fpp=nfpp) { | |
66 | nfpp=fpp->next; | |
557c8cb2 | 67 | queuescan(np->ipnode, fpp->type, fpp->port, SCLASS_CHECK, time(NULL)); |
905c2ba2 | 68 | freefoundproxy(fpp); |
69 | } | |
70 | ||
71 | /* set a SHORT gline - if they really have an open proxy the gline will be re-set, with a new ID */ | |
fb3697bf P |
72 | irc_send("%s GL * +*@%s 600 %jd :Open Proxy, see http://www.quakenet.org/openproxies.html - ID: %d", |
73 | mynumeric->content,IPtostr(np->p_ipaddr),(intmax_t)getnettime(), chp->glineid); | |
905c2ba2 | 74 | |
75 | chp->lastscan=time(NULL); | |
76 | chp->proxies=NULL; | |
77 | chp->glineid=0; | |
78 | } else { | |
557c8cb2 | 79 | chp=addcleanhost(time(NULL)); |
a8ba1373 | 80 | np->ipnode->exts[ps_cache_ext] = chp; |
557c8cb2 | 81 | patricia_ref_prefix(np->ipnode->prefix); |
905c2ba2 | 82 | |
83 | /* Queue up all the normal scans - on the normal queue */ | |
84 | for (i=0;i<numscans;i++) | |
557c8cb2 | 85 | queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0); |
905c2ba2 | 86 | } |
87 | } |