+ 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;
+
+ if(cargc < 1)
+ return CMD_USAGE;
+
+ /* 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;
+
+ if(cargc < 1)
+ return CMD_USAGE;
+
+ /* 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;
+}
+
+void startnickscan(nick *np) {
+ time_t t = time(NULL);
+ int i;
+ for(i=0;i<numscans;i++) {
+ /* @@@TODO: we allow a forced scan to scan the same IP multiple times atm */
+ queuescan(np->ipnode,thescans[i].type,thescans[i].port,SCLASS_NORMAL,t);
+ }
+}
+
+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(cargc < 1)
+ return CMD_USAGE;
+
+ if (0 == ipmask_parse(cargv[0],&sin, &bits)) {
+ sendnoticetouser(proxyscannick,np,"Usage: scan <ip>");
+ } else {
+ if (bits != 128 || !irc_in_addr_is_ipv4(&sin) || irc_in_addr_is_loopback(&sin)) {
+ sendnoticetouser(proxyscannick,np,"You may only scan single IPv4 IP's");
+ return CMD_OK;
+ }
+ if (bits != 128 || irc_in_addr_is_loopback(&sin)) {
+ sendnoticetouser(proxyscannick,np,"You may only scan single IP's");
+ return CMD_OK;
+ }
+
+ time_t t;
+ 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? */
+ t = time(NULL);
+ 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,t);
+ }
+ }
+ return CMD_OK;
+}
+
+int proxyscandoscanfile(void *sender, int cargc, char **cargv) {
+ nick *np = (nick *)sender;
+ int i;
+ time_t t = time(NULL);
+ int pscantypes[PSCAN_MAXSCANS];
+ int maxtypes;
+ FILE *fp;
+ int count;
+
+ if ((fp=fopen("data/doscan.txt","r"))==NULL) {
+ sendnoticetouser(proxyscannick,np,"Unable to open file for reading!");
+ return CMD_ERROR;
+ }
+
+ {
+ int *tscantypes;
+ int maxno = -1;
+
+ for(i=0;i<numscans;i++)
+ if(thescans[i].type > maxno)
+ maxno = thescans[i].type;
+
+ tscantypes = malloc(sizeof(int) * maxno);
+ for(i=0;i<maxno;i++)
+ tscantypes[i] = 0;
+
+ for(i=0;i<numscans;i++)
+ tscantypes[thescans[i].type] = 1;
+
+ for(i=0,maxtypes=0;i<maxno;i++)
+ if(tscantypes[i])
+ pscantypes[maxtypes++] = i;
+
+ free(tscantypes);
+ }
+
+ count = 0;
+ while (!feof(fp)) {
+ patricia_node_t *node;
+ struct irc_in_addr sin;
+ unsigned char bits;
+ unsigned short port;
+ char buf[512], ip[512];
+ int res;
+
+ fgets(buf,512,fp);
+ if (feof(fp)) {
+ break;