]> jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscanhandlers.c
exts rework (mainly)
[irc/quakenet/newserv.git] / proxyscan / proxyscanhandlers.c
1 #include "proxyscan.h"
2 #include "../irc/irc.h"
3 #include "../lib/irc_string.h"
4 #include "../core/error.h"
5
6 void proxyscan_newnick(int hooknum, void *arg) {
7 nick *np=(nick *)arg;
8 cachehost *chp;
9 foundproxy *fpp, *nfpp;
10 extrascan *esp, *espp;
11
12 int i;
13
14 /* Skip 127.* and 0.* hosts */
15 if (irc_in_addr_is_loopback(&np->p_ipaddr) || !irc_in_addr_is_ipv4(&np->p_ipaddr))
16 return;
17
18 unsigned int ip = irc_in_addr_v4_to_int(&np->p_ipaddr);
19
20 /* before we look at a normal host, see if we think we have an open proxy */
21 if ((esp=findextrascan(np->ipnode))) {
22 Error("proxyextra", ERR_ERROR, "connection from possible proxy %s", IPtostr(np->p_ipaddr));
23 for (espp=esp;espp;espp=espp->nextbynode) {
24 queuescan(np->ipnode, espp->type, espp->port, SCLASS_NORMAL, time(NULL));
25 }
26 }
27
28 /* ignore newnick for first 120s */
29 if (ps_start_ts+120 > time(NULL))
30 return;
31
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 */
45
46 if ((chp=findcachehost(np->ipnode))) {
47 if (!chp->proxies)
48 return;
49
50 if (time(NULL) < (chp->lastscan + 1800))
51 return;
52
53 /* Queue up all the normal scans - on the normal queue */
54 for (i=0;i<numscans;i++) {
55 /* If this port is open DON'T queue the scan - we'll start it later in the CHECK class */
56 for (fpp=chp->proxies;fpp;fpp=fpp->next) {
57 if (fpp->type == thescans[i].type && fpp->port == thescans[i].port)
58 break;
59
60 if (!fpp)
61 queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
62 }
63 }
64
65 /* We want these scans to start around now, so we put them at the front of the priority queue */
66 for (fpp=chp->proxies;fpp;fpp=nfpp) {
67 nfpp=fpp->next;
68 queuescan(np->ipnode, fpp->type, fpp->port, SCLASS_CHECK, time(NULL));
69 freefoundproxy(fpp);
70 }
71
72 /* set a SHORT gline - if they really have an open proxy the gline will be re-set, with a new ID */
73 irc_send("%s GL * +*@%s 600 :Open Proxy, see http://www.quakenet.org/openproxies.html - ID: %d",
74 mynumeric->content,IPtostr(np->p_ipaddr),chp->glineid);
75
76 chp->lastscan=time(NULL);
77 chp->proxies=NULL;
78 chp->glineid=0;
79 } else {
80 chp=addcleanhost(time(NULL));
81 np->ipnode->exts[ps_cache_ext] = chp;
82 patricia_ref_prefix(np->ipnode->prefix);
83
84 /* Queue up all the normal scans - on the normal queue */
85 for (i=0;i<numscans;i++)
86 queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
87 }
88 }
89