]> jfr.im git - irc/quakenet/newserv.git/blame - proxyscan/proxyscanhandlers.c
merge
[irc/quakenet/newserv.git] / proxyscan / proxyscanhandlers.c
CommitLineData
905c2ba2 1#include "proxyscan.h"
2#include "../irc/irc.h"
3#include "../lib/irc_string.h"
4
5void proxyscan_newnick(int hooknum, void *arg) {
6 nick *np=(nick *)arg;
7 cachehost *chp;
8 foundproxy *fpp, *nfpp;
9 int i;
10
11 /* Skip 127.* and 0.* hosts */
c9db668b 12 if (irc_in_addr_is_loopback(&np->p_ipaddr) || !irc_in_addr_is_ipv4(&np->p_ipaddr))
905c2ba2 13 return;
14
c9db668b
P
15 unsigned int ip = irc_in_addr_v4_to_int(&np->p_ipaddr);
16
905c2ba2 17 /*
18 * Logic for connecting hosts:
19 *
20 * If they're in the cache and clean, return.
21 * If they're in the cache, dirty, and last scanned < 30
22 * mins ago, return (they will probably go away in a minute)
23 * If they're in the cache and dirty:
24 * - gline them
25 * - trigger the "check" scans on the known proxies
26 * - trigger normal scans as for the case below..
27 *
28 * If they're not in the cache, we queue up their scans
29 */
30
c9db668b 31 if ((chp=findcachehost(ip))) {
905c2ba2 32 if (!chp->proxies)
33 return;
34
35 if (time(NULL) < (chp->lastscan + 1800))
36 return;
37
38 /* Queue up all the normal scans - on the normal queue */
39 for (i=0;i<numscans;i++) {
40 /* If this port is open DON'T queue the scan - we'll start it later in the CHECK class */
41 for (fpp=chp->proxies;fpp;fpp=fpp->next) {
42 if (fpp->type == thescans[i].type && fpp->port == thescans[i].port)
43 break;
44
45 if (!fpp)
c9db668b 46 queuescan(ip, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
905c2ba2 47 }
48 }
49
50 /* We want these scans to start around now, so we put them at the front of the priority queue */
51 for (fpp=chp->proxies;fpp;fpp=nfpp) {
52 nfpp=fpp->next;
c9db668b 53 queuescan(ip, fpp->type, fpp->port, SCLASS_CHECK, time(NULL));
905c2ba2 54 freefoundproxy(fpp);
55 }
56
57 /* set a SHORT gline - if they really have an open proxy the gline will be re-set, with a new ID */
58 irc_send("%s GL * +*@%s 600 :Open Proxy, see http://www.quakenet.org/openproxies.html - ID: %d",
c9db668b 59 mynumeric->content,IPtostr(np->p_ipaddr),chp->glineid);
905c2ba2 60
61 chp->lastscan=time(NULL);
62 chp->proxies=NULL;
63 chp->glineid=0;
64 } else {
c9db668b 65 chp=addcleanhost(ip, time(NULL));
905c2ba2 66
67 /* Queue up all the normal scans - on the normal queue */
68 for (i=0;i<numscans;i++)
c9db668b 69 queuescan(ip, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
905c2ba2 70 }
71}
72