]> jfr.im git - irc/quakenet/newserv.git/blame - proxyscan/proxyscanhandlers.c
Merge default.
[irc/quakenet/newserv.git] / proxyscan / proxyscanhandlers.c
CommitLineData
a473a1be 1#include <stdio.h>
905c2ba2 2#include "proxyscan.h"
3#include "../irc/irc.h"
4#include "../lib/irc_string.h"
557c8cb2 5#include "../core/error.h"
a473a1be 6#include "../glines/glines.h"
905c2ba2 7
8void proxyscan_newnick(int hooknum, void *arg) {
9 nick *np=(nick *)arg;
10 cachehost *chp;
11 foundproxy *fpp, *nfpp;
557c8cb2 12 extrascan *esp, *espp;
a473a1be 13 char reason[200];
557c8cb2 14
905c2ba2 15 int i;
16
17 /* Skip 127.* and 0.* hosts */
3e986f5e 18 if (irc_in_addr_is_loopback(&np->p_ipaddr))
905c2ba2 19 return;
20
d410047e 21 /* slug: why is this here? why isn't it with the other queuing stuff? */
c1136881
CP
22 /* we're given a list of ip/subnets and port pairs which someone else has
23 seen a proxy on in the past, so we scan these very aggressively
24 (even ignoring the cache)
25 */
26 /* disabled as the list is hopelessly out of date */
a060bb2e
CP
27 if ((esp=findextrascan(np->ipnode))) {
28 Error("proxyextra", ERR_ERROR, "connection from possible proxy %s", IPtostr(np->p_ipaddr));
29 for (espp=esp;espp;espp=espp->nextbynode) {
30 /* we force a scan on any hosts that may be an open proxy, even if they are:
31 * a) already in the queue, b) we've been running < 120 seconds */
32 queuescan(np->ipnode, espp->type, espp->port, SCLASS_NORMAL, time(NULL));
33 }
34 }
bc78ddf6 35
d410047e
CP
36/* slug: this BREAKS all of P's design assumptions, do NOT REENABLE THIS UNDER ANY CIRCUMSTANCES */
37/* ignore newnick until initial burst complete */
38/* if (!ps_ready)
bc78ddf6 39 return;
d410047e 40*/
bc78ddf6 41
905c2ba2 42 /*
43 * Logic for connecting hosts:
44 *
45 * If they're in the cache and clean, return.
46 * If they're in the cache, dirty, and last scanned < 30
47 * mins ago, return (they will probably go away in a minute)
48 * If they're in the cache and dirty:
49 * - gline them
50 * - trigger the "check" scans on the known proxies
51 * - trigger normal scans as for the case below..
52 *
53 * If they're not in the cache, we queue up their scans
54 */
557c8cb2 55 if ((chp=findcachehost(np->ipnode))) {
905c2ba2 56 if (!chp->proxies)
57 return;
58
59 if (time(NULL) < (chp->lastscan + 1800))
60 return;
61
62 /* Queue up all the normal scans - on the normal queue */
63 for (i=0;i<numscans;i++) {
64 /* If this port is open DON'T queue the scan - we'll start it later in the CHECK class */
65 for (fpp=chp->proxies;fpp;fpp=fpp->next) {
66 if (fpp->type == thescans[i].type && fpp->port == thescans[i].port)
67 break;
68
69 if (!fpp)
557c8cb2 70 queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
905c2ba2 71 }
72 }
73
74 /* We want these scans to start around now, so we put them at the front of the priority queue */
75 for (fpp=chp->proxies;fpp;fpp=nfpp) {
76 nfpp=fpp->next;
557c8cb2 77 queuescan(np->ipnode, fpp->type, fpp->port, SCLASS_CHECK, time(NULL));
905c2ba2 78 freefoundproxy(fpp);
79 }
80
81 /* set a SHORT gline - if they really have an open proxy the gline will be re-set, with a new ID */
a473a1be 82 snprintf(reason, sizeof(reason), "Open Proxy, see http://www.quakenet.org/openproxies.html - ID: %d", chp->glineid);
3c5c26a8 83 glinebynick(np, 600, reason, GLINE_IGNORE_TRUST, "proxyscan");
905c2ba2 84
85 chp->lastscan=time(NULL);
86 chp->proxies=NULL;
87 chp->glineid=0;
88 } else {
557c8cb2 89 chp=addcleanhost(time(NULL));
a8ba1373 90 np->ipnode->exts[ps_cache_ext] = chp;
557c8cb2 91 patricia_ref_prefix(np->ipnode->prefix);
905c2ba2 92
93 /* Queue up all the normal scans - on the normal queue */
94 for (i=0;i<numscans;i++)
557c8cb2 95 queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
905c2ba2 96 }
97}