]> jfr.im git - irc/quakenet/newserv.git/commitdiff
attempt to tidy P a little:
authorPaul <redacted>
Tue, 28 Oct 2008 23:40:44 +0000 (23:40 +0000)
committerPaul <redacted>
Tue, 28 Oct 2008 23:40:44 +0000 (23:40 +0000)
a) CommandTree for commands
b) instead of using 120sec's, trigger EOB hook
c) log file lives in log/
d) fix cache storage/expiry (into data/)
e) simplify the queue function - the new nick handler, checking against a node extension should actually block duplicate scans already

proxyscan/proxyscan.c
proxyscan/proxyscan.h
proxyscan/proxyscanalloc.c
proxyscan/proxyscancache.c
proxyscan/proxyscandb.c
proxyscan/proxyscanext.c
proxyscan/proxyscanhandlers.c
proxyscan/proxyscanqueue.c

index 210686486377a1e5c0d9fb4249ba35fdbbecfe63..f2a3d39fae7a7d5c3e07f465ed1471849c962f1f 100644 (file)
@@ -39,6 +39,8 @@ MODULE_VERSION("")
 
 scan *scantable[SCANHASHSIZE];
 
+CommandTree *ps_commands;
+
 int listenfd;
 int activescans;
 int maxscans;
@@ -50,6 +52,7 @@ int glinedhosts;
 time_t ps_starttime;
 int ps_cache_ext;
 int ps_extscan_ext;
+int ps_ready;
 
 int numscans; /* number of scan types currently valid */
 scantype thescans[PSCAN_MAXSCANS];
@@ -81,18 +84,27 @@ void handlescansock(int fd, short events);
 void timeoutscansock(void *arg);
 void proxyscan_newnick(int hooknum, void *arg);
 void proxyscan_lostnick(int hooknum, void *arg);
+void proxyscan_onconnect(int hooknum, void *arg);
 void proxyscanuserhandler(nick *target, int message, void **params);
 void registerproxyscannick();
 void killsock(scan *sp, int outcome);
 void killallscans();
 void proxyscanstats(int hooknum, void *arg);
 void sendlagwarning();
-void proxyscandostatus(nick *np);
-void proxyscandebug(nick *np);
 void proxyscan_newip(nick *np, unsigned long ip);
 int proxyscan_addscantype(int type, int port);
 int proxyscan_delscantype(int type, int port);
 
+int proxyscandostatus(void *sender, int cargc, char **cargv);
+int proxyscandebug(void *sender, int cargc, char **cargv);
+int proxyscandosave(void *sender, int cargc, char **cargv);
+int proxyscandospew(void *sender, int cargc, char **cargv);
+int proxyscandoshowkill(void *sender, int cargc, char **cargv);
+int proxyscandoscan(void *sender, int cargc, char **cargv);
+int proxyscandoaddscan(void *sender, int cargc, char **cargv);
+int proxyscandodelscan(void *sender, int cargc, char **cargv);
+int proxyscandoshowcommands(void *sender, int cargc, char **cargv);
+
 int proxyscan_addscantype(int type, int port) {
   /* Check we have a spare scan slot */
   
@@ -129,6 +141,8 @@ void _init(void) {
   int ipbits[4];
 
   ps_start_ts = time(NULL);
+  ps_ready = 0;
+  ps_commands = NULL;
 
   ps_cache_ext = registernodeext("proxyscancache");
   if( ps_cache_ext == -1 ) {
@@ -149,7 +163,7 @@ void _init(void) {
   warningsent=0;
   ps_starttime=time(NULL);
   glinedhosts=0;
-
   scanspermin=0;
   lastscants=time(NULL);
 
@@ -201,6 +215,8 @@ void _init(void) {
   /* Set up our nick on the network */
   scheduleoneshot(time(NULL),&registerproxyscannick,NULL);
 
+  registerhook(HOOK_SERVER_END_OF_BURST, &proxyscan_onconnect);
+
   registerhook(HOOK_NICK_NEWNICK,&proxyscan_newnick);
 
   registerhook(HOOK_CORE_STATSREQUEST,&proxyscanstats);
@@ -218,6 +234,17 @@ void _init(void) {
     brokendb=0;
   }
 
+  ps_commands = newcommandtree();
+  addcommandtotree(ps_commands, "showcommands", 0, 0, &proxyscandoshowcommands);
+  addcommandtotree(ps_commands, "status", 0, 0, &proxyscandostatus);
+  addcommandtotree(ps_commands, "listopen", 0, 0, &proxyscandolistopen);
+  addcommandtotree(ps_commands, "save", 0, 0, &proxyscandosave);
+  addcommandtotree(ps_commands, "spew", 0, 0, &proxyscandospew);
+  addcommandtotree(ps_commands, "showkill", 0, 0, &proxyscandoshowkill);
+  addcommandtotree(ps_commands, "scan", 0, 0, &proxyscandoscan);
+  addcommandtotree(ps_commands, "addscan", 0, 0, &proxyscandoaddscan);
+  addcommandtotree(ps_commands, "delscan", 0, 0, &proxyscandodelscan);
+
   /* Default scan types */
   proxyscan_addscantype(STYPE_HTTP, 8080);
   proxyscan_addscantype(STYPE_HTTP, 80);
@@ -252,11 +279,17 @@ void _init(void) {
   proxyscan_addscantype(STYPE_HTTP, 63809);
   proxyscan_addscantype(STYPE_HTTP, 63000);
   proxyscan_addscantype(STYPE_SOCKS4, 29992);
-  
   /* Schedule saves */
   schedulerecurring(time(NULL)+3600,0,3600,&dumpcachehosts,NULL);
+  ps_logfile=fopen("logs/proxyscan.log","a");
 
-  ps_logfile=fopen("proxyscan.log","a");
+  if (connected) {
+    /* if we're already connected, assume we're just reloading module (i.e. have a completed burst) */
+    ps_ready = 1;
+    startqueuedscans();
+  }
 }
 
 void registerproxyscannick(void *arg) {
@@ -292,21 +325,26 @@ void _fini(void) {
 
   deregisterlocaluser(proxyscannick,NULL);
   
-  releasenodeext(ps_cache_ext);
-  releasenodeext(ps_extscan_ext);
+  deregisterhook(HOOK_SERVER_END_OF_BURST, &proxyscan_onconnect);
 
   deregisterhook(HOOK_NICK_NEWNICK,&proxyscan_newnick);
 
   deregisterhook(HOOK_CORE_STATSREQUEST,&proxyscanstats);
 
   deleteschedule(NULL,&dumpcachehosts,NULL);
-  
+  destroycommandtree(ps_commands);
   /* Kill any scans in progress */
   killallscans();
 
   /* Dump the database - AFTER killallscans() which prunes it */
   dumpcachehosts(NULL);
 
+  /* dump any cached hosts before deleting the extensions */
+  releasenodeext(ps_cache_ext);
+  releasenodeext(ps_extscan_ext);
+
   /* free() all our structures */
   nsfreeall(POOL_PROXYSCAN);
   
@@ -323,11 +361,9 @@ void _fini(void) {
 
 void proxyscanuserhandler(nick *target, int message, void **params) {
   nick *sender;
-  char *msg;
-  int i;
-  struct irc_in_addr sin;
-  unsigned char bits;
-  patricia_node_t *node;
+  Command *ps_command;
+  char *cargv[20];
+  int cargc;
 
   switch(message) {
   case LU_KILLED:
@@ -338,93 +374,27 @@ void proxyscanuserhandler(nick *target, int message, void **params) {
   case LU_PRIVMSG:
   case LU_SECUREMSG:
     sender=(nick *)params[0];
-    msg=(char *)params[1];
     
     if (IsOper(sender)) {
-      if (!ircd_strncmp(msg,"listopen",8)) {
-       proxyscandolistopen(proxyscannick,sender,time(NULL)-rescaninterval);
-      }
-      
-      if (!ircd_strncmp(msg,"status",6)) {
-       proxyscandostatus(sender);
-      }
-      
-      if (!ircd_strncmp(msg,"save",4)) {
-       dumpcachehosts(NULL);
-       sendnoticetouser(proxyscannick,sender,"Done.");
-      }
-      
-      if (!ircd_strncmp(msg,"debug",5)) {
-       proxyscandebug(sender);
-      }
+      cargc = splitline((char *)params[1], cargv, 20, 0);
 
-      if (!ircd_strncmp(msg,"spew ",5)) {
-        /* check our database for the ip supplied */
-        unsigned long a,b,c,d;
-        if (4 != sscanf(&msg[5],"%lu.%lu.%lu.%lu",&a,&b,&c,&d)) {
-          sendnoticetouser(proxyscannick,sender,"Usage: spew x.x.x.x");
-        } else {
-          /* check db */
-          proxyscanspewip(proxyscannick,sender,a,b,c,d);
-        }
-      }
+      if ( cargc == 0 )
+        return;
 
-      if (!ircd_strncmp(msg,"showkill ",9)) {
-        /* check our database for the id supplied */
-        unsigned long a;
-        if (1 != sscanf(&msg[9],"%lu",&a)) {
-          sendnoticetouser(proxyscannick,sender,"Usage: showkill <id>");
-        } else {
-          /* check db */
-          proxyscanshowkill(proxyscannick,sender,a);
-        }
-      }
+      ps_command = findcommandintree(ps_commands, cargv[0], 1);
 
-      if (!ircd_strncmp(msg,"scan ",5)) {
-        if (0 == ipmask_parse(&msg[5],&sin, &bits)) {
-          sendnoticetouser(proxyscannick,sender,"Usage: scan <ip>");
-        } else {
-          sendnoticetouser(proxyscannick,sender,"Forcing scan of %s",IPtostr(sin));
-         // * Just queue the scans directly here.. plonk them on the priority queue * /
-          node = refnode(iptree, &sin, bits); /* node leaks node here - should only allow to scan a nick? */
-          for(i=0;i<numscans;i++) {
-           queuescan(node,thescans[i].type,thescans[i].port,SCLASS_NORMAL,time(NULL));
-         }
-        }      
+      if ( !ps_command ) {
+        sendnoticetouser(proxyscannick,sender, "Unknown command.");
+        return;
       }
 
-      if (!ircd_strncmp(msg,"addscan ",8)) {
-       unsigned int a,b;
-       if (sscanf(msg+8,"%u %u",&a,&b) != 2) {
-         sendnoticetouser(proxyscannick,sender,"Usage: addscan <type> <port>");
-       } else {
-         sendnoticetouser(proxyscannick,sender,"Added scan type %u port %u",a,b);
-         proxyscan_addscantype(a,b);
-         scanall(a,b);
-       }
+      if ( ps_command->maxparams < (cargc-1) ) {
+        rejoinline(cargv[ps_command->maxparams], cargc - (ps_command->maxparams));
+        cargc = (ps_command->maxparams) + 1;
       }
 
-      if (!ircd_strncmp(msg,"delscan ",8)) {
-       unsigned int a,b;
-       if (sscanf(msg+8,"%u %u",&a,&b) != 2) {
-         sendnoticetouser(proxyscannick,sender,"Usage: delscan <type> <port>");
-       } else {
-         sendnoticetouser(proxyscannick,sender,"Delete scan type %u port %u",a,b);
-         proxyscan_delscantype(a,b);
-       }
-      }          
-
-      if ((!ircd_strncmp(msg,"help",4)) || (!ircd_strncmp(msg,"showcommands",12))) {
-       sendnoticetouser(proxyscannick,sender,"Proxyscan commands:");
-       sendnoticetouser(proxyscannick,sender,"----------------------------------------------------------------------");
-       sendnoticetouser(proxyscannick,sender,"help              Shows this help");
-       sendnoticetouser(proxyscannick,sender,"status            Prints status information");
-       sendnoticetouser(proxyscannick,sender,"listopen          Shows open proxies found recently");
-       sendnoticetouser(proxyscannick,sender,"save              Saves the clean host database");
-       sendnoticetouser(proxyscannick,sender,"scan <ip>         Force scan of the supplied IP");
-       sendnoticetouser(proxyscannick,sender,"spew <ip>         Find <ip> in our list of open proxies");
-       sendnoticetouser(proxyscannick,sender,"showkill <id>     Shows details of a kill or gline made by the service");
-      }
+      (ps_command->handler)((void *)sender, cargc - 1, &(cargv[1]));
+      break;
     }
 
   default:
@@ -833,7 +803,8 @@ int pscansort(const void *a, const void *b) {
   return thescans[ra].hits - thescans[rb].hits;
 }
 
-void proxyscandostatus(nick *np) {
+int proxyscandostatus(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *) sender;
   int i;
   int totaldetects=0;
   int ord[PSCAN_MAXSCANS];
@@ -870,16 +841,16 @@ void proxyscandostatus(nick *np) {
                      scantostr(thescans[ord[i]].type), thescans[ord[i]].port, thescans[ord[i]].hits, ((float)thescans[ord[i]].hits*100)/totaldetects);
   
   sendnoticetouser(proxyscannick,np,"End of list.");
+  return CMD_OK;
 }
 
-void proxyscandebug(nick *np) {
+int proxyscandebug(void *sender, int cargc, char **cargv) {
   /* Dump all scans.. */
   int i;
   int activescansfound=0;
   int totalscansfound=0;
   scan *sp;
-  patricia_node_t *node;
-  cachehost *chp;
+  nick *np = (nick *)sender;
 
   sendnoticetouser(proxyscannick,np,"Active scans : %d",activescans);
   
@@ -894,13 +865,113 @@ void proxyscandebug(nick *np) {
     }
   }
 
-  PATRICIA_WALK (iptree->head, node) {
-    if ( node->exts[ps_cache_ext] ) {
-      chp = (cachehost *) node->exts[ps_cache_ext];
-      if (chp)
-        sendnoticetouser(proxyscannick,np,"node: %s , chp: %p", IPtostr(((patricia_node_t *)node)->prefix->sin), chp);
+  sendnoticetouser(proxyscannick,np,"Total %d scans actually found (%d active)",totalscansfound,activescansfound);
+  return CMD_OK;
+}
+
+void proxyscan_onconnect(int hooknum, void *arg) {
+  ps_ready = 1;
+
+  /* kick the queue.. */
+  startqueuedscans();
+}
+
+int proxyscandosave(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+
+  sendnoticetouser(proxyscannick,np,"Saving cached hosts...");
+  dumpcachehosts(NULL);
+  sendnoticetouser(proxyscannick,np,"Done.");
+  return CMD_OK;
+}
+
+int proxyscandospew(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+
+  /* check our database for the ip supplied */
+  unsigned long a,b,c,d;
+  if (4 != sscanf(cargv[0],"%lu.%lu.%lu.%lu",&a,&b,&c,&d)) {
+    sendnoticetouser(proxyscannick,np,"Usage: spew x.x.x.x");
+  } else {
+    /* check db */
+    proxyscanspewip(proxyscannick,np,a,b,c,d);
+  }
+  return CMD_OK;
+}
+
+int proxyscandoshowkill(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+
+  /* check our database for the id supplied */
+  unsigned long a;
+  if (1 != sscanf(cargv[0],"%lu",&a)) {
+    sendnoticetouser(proxyscannick,np,"Usage: showkill <id>");
+  } else {
+    /* check db */
+    proxyscanshowkill(proxyscannick,np,a);
+  }
+  return CMD_OK;
+}
+
+int proxyscandoscan(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+  patricia_node_t *node;
+  struct irc_in_addr sin;
+  unsigned char bits;
+  int i;
+
+  if (0 == ipmask_parse(cargv[0],&sin, &bits)) {
+    sendnoticetouser(proxyscannick,np,"Usage: scan <ip>");
+  } else {
+    sendnoticetouser(proxyscannick,np,"Forcing scan of %s",IPtostr(sin));
+    // * Just queue the scans directly here.. plonk them on the priority queue * /
+    node = refnode(iptree, &sin, bits); /* node leaks node here - should only allow to scan a nick? */
+    for(i=0;i<numscans;i++) {
+      /* @@@TODO: we allow a forced scan to scan the same IP multiple times atm */
+      queuescan(node,thescans[i].type,thescans[i].port,SCLASS_NORMAL,time(NULL));
     }
-  } PATRICIA_WALK_END;
+  }
+  return CMD_OK;
+}
 
-  sendnoticetouser(proxyscannick,np,"Total %d scans actually found (%d active)",totalscansfound,activescansfound);
+int proxyscandoaddscan(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+
+  unsigned int a,b;
+  if (sscanf(cargv[0],"%u %u",&a,&b) != 2) {
+    sendnoticetouser(proxyscannick,np,"Usage: addscan <type> <port>");
+  } else {
+    sendnoticetouser(proxyscannick,np,"Added scan type %u port %u",a,b);
+    proxyscan_addscantype(a,b);
+    scanall(a,b);
+  }
+  return CMD_OK;
+}
+
+int proxyscandodelscan(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+
+  unsigned int a,b;
+  if (sscanf(cargv[0],"%u %u",&a,&b) != 2) {
+    sendnoticetouser(proxyscannick,np,"Usage: delscan <type> <port>");
+  } else {
+    sendnoticetouser(proxyscannick,np,"Delete scan type %u port %u",a,b);
+    proxyscan_delscantype(a,b);
+  }
+  return CMD_OK;
+}
+
+int proxyscandoshowcommands(void *sender, int cargc, char **cargv) {
+  nick *np = (nick *)sender;
+  Command *cmdlist[100];
+  int i,n;
+
+  n=getcommandlist(ps_commands,cmdlist,100);
+
+  sendnoticetouser(proxyscannick,np,"The following commands are registered at present:");
+  for(i=0;i<n;i++) {
+    sendnoticetouser(proxyscannick,np,"%s",cmdlist[i]->command->content);
+  }
+  sendnoticetouser(proxyscannick,np,"End of list.");
+  return CMD_OK;
 }
index d3fcee9bcf4573794c2b0a49205ef798419a764d..2b7441fa2298c12a2e9d087e6412b76e63510009 100644 (file)
@@ -3,6 +3,7 @@
 #define __PROXYSCAN_H
 
 #include "../nick/nick.h"
+#include "../lib/splitline.h"
 #include <time.h>
 
 #define MAGICSTRING         "NOTICE AUTH :*** Looking up your hostname\r\n"
@@ -102,7 +103,8 @@ extern int brokendb;
 extern int ps_cache_ext;
 extern int ps_scan_ext;
 extern int ps_extscan_ext;
-
+extern int ps_ready;
+extern int rescaninterval;
 
 extern unsigned int normalqueuedscans;
 extern unsigned int prioqueuedscans;
@@ -148,7 +150,7 @@ int createconnectsocket(long ip, int socknum);
 void loggline(cachehost *chp, patricia_node_t *node);
 void proxyscandbclose();
 int proxyscandbinit();
-void proxyscandolistopen(nick *mynick, nick *usernick, time_t snce);
+int proxyscandolistopen(void *sender, int cargc, char **cargv);
 void proxyscanspewip(nick *mynick, nick *usernick, unsigned long a, unsigned long b, unsigned long c, unsigned long d);
 void proxyscanshowkill(nick *mynick, nick *usernick, unsigned long a);
 const char *scantostr(int type);
index b4baf78f1972e7c0874f106b9a43ed070c3fe216..5fb13ec3c7fb213396c00f51f81122c99d6d27a7 100644 (file)
@@ -67,12 +67,12 @@ pendingscan *getpendingscan() {
   if (!freependingscans) {
     freependingscans=(pendingscan *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT * sizeof(pendingscan));
     for (i=0;i<(ALLOCUNIT-1);i++)
-      freependingscans[i].next = freependingscans+i+1;
+      freependingscans[i].next = (pendingscan *)&(freependingscans[i+1]);
     freependingscans[ALLOCUNIT-1].next=NULL;
   }
 
   psp=freependingscans;
-  freependingscans=psp->next;
+  freependingscans=(pendingscan *)psp->next;
 
   return psp;
 }
@@ -89,12 +89,12 @@ foundproxy *getfoundproxy() {
   if (!freefoundproxies) {
     freefoundproxies=(foundproxy *)nsmalloc(POOL_PROXYSCAN,ALLOCUNIT * sizeof(foundproxy));
     for (i=0;i<(ALLOCUNIT-1);i++)
-      freefoundproxies[i].next = freefoundproxies+i+1;
+      freefoundproxies[i].next = (foundproxy *)&(freefoundproxies[i+1]);
     freefoundproxies[ALLOCUNIT-1].next=NULL;
   }
 
   fpp=freefoundproxies;
-  freefoundproxies=fpp->next;
+  freefoundproxies=(foundproxy *)fpp->next;
 
   return fpp;
 }
index 81dd5f2f5e61ab415a840fabd8da099bc9f68f91..93f0c637d2878e0e9f4b24c3d51e742eb62942d7 100644 (file)
@@ -75,21 +75,20 @@ void dumpcachehosts(void *arg) {
   foundproxy *fpp;
   patricia_node_t *node;
 
-  if ((fp=fopen("cleanhosts","w"))==NULL) {
+  if ((fp=fopen("data/cleanhosts","w"))==NULL) {
     Error("proxyscan",ERR_ERROR,"Unable to open cleanhosts file for writing!");
     return;
   }
 
-  PATRICIA_WALK (iptree->head, node) {
+  PATRICIA_WALK_CLEAR (iptree->head, node) {
     if (node->exts[ps_cache_ext] ) {
       chp = (cachehost *) node->exts[ps_cache_ext];
       if (chp) { 
         if (chp->proxies) {
           if (chp->lastscan < (now-dirtyscaninterval)) {
-            //derefnode(iptree,node); 
-           //delcachehost(chp);
-           //node->exts[ps_cache_ext] = NULL;
-            //continue;
+            derefnode(iptree,node); 
+           delcachehost(chp);
+           node->exts[ps_cache_ext] = NULL;
           } else
         
           for (fpp=chp->proxies;fpp;fpp=fpp->next) 
@@ -97,17 +96,17 @@ void dumpcachehosts(void *arg) {
         } else {
           if (chp->lastscan < (now-cleanscaninterval)) {
             /* Needs rescan anyway, so delete it */
-           //derefnode(iptree,node); 
-           //delcachehost(chp);
-            //node->exts[ps_cache_ext] = NULL;          
-            //continue;
+           derefnode(iptree,node); 
+           delcachehost(chp);
+            node->exts[ps_cache_ext] = NULL;          
           } else
           fprintf(fp,"%s %lu\n",IPtostr(node->prefix->sin),chp->lastscan);
         }
       }
     }
-  } PATRICIA_WALK_END;
-  
+  } PATRICIA_WALK_CLEAR_END;
+
+//  patricia_tidy_tree(iptree); 
 
   fclose(fp);
 }
@@ -128,8 +127,9 @@ void loadcachehosts() {
   struct irc_in_addr sin;
   unsigned char bits;
   patricia_node_t *node;
+  int i=0;
 
-  if ((fp=fopen("cleanhosts","r"))==NULL) {
+  if ((fp=fopen("data/cleanhosts","r"))==NULL) {
     Error("proxyscan",ERR_ERROR,"Unable to open cleanhosts file for reading!");
     return;
   }
@@ -151,6 +151,7 @@ void loadcachehosts() {
     } else {
       node = refnode(iptree, &sin, bits);
       if( node ) {
+        i++;
         chp=addcleanhost(timestamp);
         node->exts[ps_cache_ext] = chp;
       
@@ -165,7 +166,8 @@ void loadcachehosts() {
       }
     }
   }
-  
+  Error("proxyscan",ERR_INFO, "Loaded %d entries from cache", i); 
 }
 
 /*
index 38397aa5089cb9e607c5b837f3a04c2c3f584478..f7912357460f6a5eec887b690183c4910daa570f 100644 (file)
@@ -199,10 +199,12 @@ void proxyscandolistopen_real(DBConn *dbconn, void *arg) {
   sendnoticetouser(proxyscannick,np,"--- End of list ---");
 }
 
-void proxyscandolistopen(nick *mynick, nick *usernick, time_t snce) {
-
+int proxyscandolistopen(void *sender, int cargc, char **cargv) {
+  nick *usernick = (nick *)sender;
+   
   dbasyncquery(proxyscandolistopen_real,(void *)usernick->numeric, 
-               "SELECT IP,TS,RH FROM openproxies WHERE TS>'%lu' ORDER BY TS",snce);
+               "SELECT IP,TS,RH FROM openproxies WHERE TS>'%lu' ORDER BY TS",time(NULL)-rescaninterval);
+  return CMD_OK;
 }
 
 /*
@@ -285,7 +287,6 @@ void proxyscanshowkill_real(DBConn *dbconn, void *arg) {
   sendnoticetouser(proxyscannick,np,"--- End of list ---");
 }
 
-
 void proxyscanshowkill(nick *mynick, nick *usernick, unsigned long a) {
   dbasyncquery(proxyscanspewip_real,(void *)usernick->numeric,
                "SELECT ID,IP,TS,RH FROM openproxies WHERE ID='%lu'",a);
index 81e6871f09bfa880eb320ac140d6e9cc37560ae5..23438c235dc328fc8d37429452387548bd027d8c 100644 (file)
@@ -53,7 +53,7 @@ void loadextrascans() {
   unsigned char bits;
   patricia_node_t *node;
 
-  if ((fp=fopen("ports.txt","r"))==NULL) {
+  if ((fp=fopen("data/ports.txt","r"))==NULL) {
     Error("proxyscan",ERR_ERROR,"Unable to open ports file for reading!");
     return;
   }
index c1c70b4559c2984b39595a744560202b79a2fa3e..200b6b6164154148e5dc47e6ecc6d9af2c3fc8f5 100644 (file)
@@ -19,12 +19,14 @@ void proxyscan_newnick(int hooknum, void *arg) {
   if ((esp=findextrascan(np->ipnode))) {
     Error("proxyextra", ERR_ERROR, "connection from possible proxy %s", IPtostr(np->p_ipaddr)); 
     for (espp=esp;espp;espp=espp->nextbynode) { 
+      /* we force a scan on any hosts that may be an open proxy, even if they are:
+       * a) already in the queue, b) we've been running < 120 seconds */
       queuescan(np->ipnode, espp->type, espp->port, SCLASS_NORMAL, time(NULL));
     }
   }
 
-  /* ignore newnick for first 120s */
-  if (ps_start_ts+120 > time(NULL))
+  /* ignore newnick until initial burst complete */
+  if (!ps_ready)
     return;
 
   /*
@@ -40,7 +42,6 @@ void proxyscan_newnick(int hooknum, void *arg) {
    *
    * If they're not in the cache, we queue up their scans
    */
-
   if ((chp=findcachehost(np->ipnode))) {
     if (!chp->proxies)
       return;
@@ -84,4 +85,3 @@ void proxyscan_newnick(int hooknum, void *arg) {
       queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0);
   }
 }
-
index e37ae751bc72e99653a07c3f94a203942a0b755a..91febc841bcc697f3153df849ee2ee82c899f977 100644 (file)
@@ -19,42 +19,22 @@ unsigned long countpendingscan=0;
 void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when) {
   pendingscan *psp, *psp2;
 
-  /* check if the IP/port combo is already queued - don't queue up
-   * multiple identical scans
+  /* we can just blindly queue the scans as node extension cleanhost cache blocks duplicate scans normally.
+   * Scans may come from:
+   * a) scan <node> (from an oper)
+   * b) newnick handler - which ignores clean hosts, only scans new hosts or dirty hosts
+   * c) adding a new scan type (rare) 
    */
-  psp = ps_prioqueue;
-  while (psp != NULL)
-  {
-    if (psp->node == node && psp->type == scantype &&
-      psp->port == port && psp->class == class)
-    {
-      /* found it, ignore */
-      return;
-    }
-    psp = psp->next;
-  }
-
-  psp = ps_normalqueue;
-  while (psp != NULL)
-  {
-    if (psp->node == node && psp->type == scantype &&
-      psp->port == port && psp->class == class)
-    {
-      /* found it, ignore */
-      return;
-    }
-    psp = psp->next;
-  }
   
   /* If there are scans spare, just start it immediately.. 
    * provided we're not supposed to wait */
-  if (activescans < maxscans && when<=time(NULL) && (ps_start_ts+120 <= time(NULL))) {
+  if (activescans < maxscans && when<=time(NULL) && ps_ready) {
     startscan(node, scantype, port, class);
     return;
   }
 
   /* We have to queue it */
-  if (!(psp=(struct pendingscan *)malloc(sizeof(pendingscan))))
+  if (!(psp=getpendingscan()))
     Error("proxyscan",ERR_STOP,"Unable to allocate memory");
 
   countpendingscan++;
@@ -95,9 +75,6 @@ void queuescan(patricia_node_t *node, short scantype, unsigned short port, char
 void startqueuedscans() {
   pendingscan *psp=NULL;
 
-  if (ps_start_ts+120 > time(NULL))
-       return;
-
   while (activescans < maxscans) {
     if (ps_prioqueue && (ps_prioqueue->when <= time(NULL))) {
       psp=ps_prioqueue;
@@ -113,7 +90,7 @@ void startqueuedscans() {
     
     if (psp) {
       startscan(psp->node, psp->type, psp->port, psp->class);
-      free(psp);
+      freependingscan(psp);
       countpendingscan--;
       psp=NULL;
     } else {