]>
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) { | |
22 | queuescan(np->ipnode, espp->type, espp->port, SCLASS_NORMAL, time(NULL)); | |
23 | } | |
24 | } | |
bc78ddf6 P |
25 | |
26 | /* ignore newnick for first 120s */ | |
27 | if (ps_start_ts+120 > time(NULL)) | |
28 | return; | |
29 | ||
905c2ba2 | 30 | /* |
31 | * Logic for connecting hosts: | |
32 | * | |
33 | * If they're in the cache and clean, return. | |
34 | * If they're in the cache, dirty, and last scanned < 30 | |
35 | * mins ago, return (they will probably go away in a minute) | |
36 | * If they're in the cache and dirty: | |
37 | * - gline them | |
38 | * - trigger the "check" scans on the known proxies | |
39 | * - trigger normal scans as for the case below.. | |
40 | * | |
41 | * If they're not in the cache, we queue up their scans | |
42 | */ | |
43 | ||
557c8cb2 | 44 | if ((chp=findcachehost(np->ipnode))) { |
905c2ba2 | 45 | if (!chp->proxies) |
46 | return; | |
47 | ||
48 | if (time(NULL) < (chp->lastscan + 1800)) | |
49 | return; | |
50 | ||
51 | /* Queue up all the normal scans - on the normal queue */ | |
52 | for (i=0;i<numscans;i++) { | |
53 | /* If this port is open DON'T queue the scan - we'll start it later in the CHECK class */ | |
54 | for (fpp=chp->proxies;fpp;fpp=fpp->next) { | |
55 | if (fpp->type == thescans[i].type && fpp->port == thescans[i].port) | |
56 | break; | |
57 | ||
58 | if (!fpp) | |
557c8cb2 | 59 | queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0); |
905c2ba2 | 60 | } |
61 | } | |
62 | ||
63 | /* We want these scans to start around now, so we put them at the front of the priority queue */ | |
64 | for (fpp=chp->proxies;fpp;fpp=nfpp) { | |
65 | nfpp=fpp->next; | |
557c8cb2 | 66 | queuescan(np->ipnode, fpp->type, fpp->port, SCLASS_CHECK, time(NULL)); |
905c2ba2 | 67 | freefoundproxy(fpp); |
68 | } | |
69 | ||
70 | /* set a SHORT gline - if they really have an open proxy the gline will be re-set, with a new ID */ | |
71 | irc_send("%s GL * +*@%s 600 :Open Proxy, see http://www.quakenet.org/openproxies.html - ID: %d", | |
c9db668b | 72 | mynumeric->content,IPtostr(np->p_ipaddr),chp->glineid); |
905c2ba2 | 73 | |
74 | chp->lastscan=time(NULL); | |
75 | chp->proxies=NULL; | |
76 | chp->glineid=0; | |
77 | } else { | |
557c8cb2 | 78 | chp=addcleanhost(time(NULL)); |
a8ba1373 | 79 | np->ipnode->exts[ps_cache_ext] = chp; |
557c8cb2 | 80 | patricia_ref_prefix(np->ipnode->prefix); |
905c2ba2 | 81 | |
82 | /* Queue up all the normal scans - on the normal queue */ | |
83 | for (i=0;i<numscans;i++) | |
557c8cb2 | 84 | queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0); |
905c2ba2 | 85 | } |
86 | } | |
87 |