]> jfr.im git - irc/ircd-hybrid/bopm.git/commitdiff
bopchecker.c:
authorandy <redacted>
Tue, 29 Jan 2002 00:23:21 +0000 (00:23 +0000)
committerandy <redacted>
Tue, 29 Jan 2002 00:23:21 +0000 (00:23 +0000)
Some reorganisation.

"req" field of config hash is now zero'd for all but the parameters
we need for bopchecker to operate.

Used a sleep(1) to reduce CPU usage.

bopchecker.h:
Exit values have changed again!  0 and 1 are already in use within
bopm, so now 15-255 are reserved for bopchecker.

HTTP    =  16
WinGate =  32
SOCKS4  =  64
SOCKS5  = 128

config.c:
Terminated the config hash with a zero'd entry so that it is easy
to tell where it ends.

bopchecker.c
bopchecker.h
config.c

index 20e03654274a6d033889684a58cb48ee9ec6b894..0581d4f951ca8c5b06d3dc57960a63d91bfbf4d7 100644 (file)
@@ -22,6 +22,8 @@ along with this program; if not, write to the Free Software
 
 #include <stdio.h>
 #include <stdarg.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -39,6 +41,7 @@ along with this program; if not, write to the Free Software
 #include "config.h"
 
 extern struct scan_struct *CONNECTIONS;
+extern struct config_hash hash[];
 
 int OPT_DEBUG = 1;
 char *CONFNAME = DEFAULTNAME;
@@ -50,7 +53,7 @@ int main(int argc, char **argv)
        struct hostent *he;
        char *ip, *host;
        struct scan_struct *ss;
-       int len, c;
+       int len, c, i, still_alive = 0;
 
        while (1) {
                c = getopt(argc, argv, "+c:");
@@ -80,6 +83,16 @@ int main(int argc, char **argv)
        CONFFILE = (char *) malloc(len * sizeof(char));
        snprintf(CONFFILE, len, "%s.%s", CONFNAME, CONFEXT);
 
+       /* The only things we need in a conf file are SCANIP and
+        * SCANPORT */
+       for (i = 0; hash[i].key; i++) {
+               if (strcasecmp(hash[i].key, "SCANIP") != 0 &&
+                   strcasecmp(hash[i].key, "SCANPORT") != 0) {
+                       /* nuke the required field */
+                       hash[i].req = 0;
+               }
+       }
+
        config_load(CONFFILE);
        do_scan_init();
 
@@ -123,34 +136,43 @@ int main(int argc, char **argv)
        scan_connect(ip, host, "*", "*", 1, 0);    /* Scan using verbose */
 
        do {
-               int still_alive = 0;
-               
-               scan_timer();
+               still_alive = 0;
+
                scan_cycle();
+               /* pause 1s */
+               sleep(1);
 
                for (ss = CONNECTIONS; ss; ss = ss->next) {
-                       if (ss->protocol->stat_numopen) {
-                               if (strcasecmp("http", ss->protocol->type) == 0)
-                                       RC |= PROXY_HTTP;
-                               else if (strcasecmp("socks4", ss->protocol->type) == 0)
-                                       RC |= PROXY_SOCKS4;
-                               else if (strcasecmp("socks5", ss->protocol->type) == 0)
-                                       RC |= PROXY_SOCKS5;
-                               else if (strcasecmp("wingate", ss->protocol->type) == 0)
-                                       RC |= PROXY_WINGATE;
-                               else {
-                                       fprintf(stderr, "Unknown type %s!", ss->protocol->type);
+                       if (ss->state != STATE_CLOSED) {
+                               time_t now = time(NULL);
+                               if ((now - ss->create_time) >= 30) {
+                                       /* timed out */
+                                       ss->state = STATE_CLOSED;
+                               } else {
+                                       still_alive = 1;
+                                       break;
                                }
                        }
-
-                       if (ss->state != STATE_CLOSED)
-                               still_alive++;
                }
-
-               if (!still_alive) {
-                       exit(RC);
+       } while (still_alive);
+
+       /* All connections now closed, check what we got */
+       for (ss = CONNECTIONS; ss; ss = ss->next) {
+               if (ss->protocol->stat_numopen) {
+                       if (strcasecmp("http", ss->protocol->type) == 0)
+                               RC |= PROXY_HTTP;
+                       else if (strcasecmp("socks4", ss->protocol->type) == 0)
+                               RC |= PROXY_SOCKS4;
+                       else if (strcasecmp("socks5", ss->protocol->type) == 0)
+                               RC |= PROXY_SOCKS5;
+                       else if (strcasecmp("wingate", ss->protocol->type) == 0)
+                               RC |= PROXY_WINGATE;
+                       else {
+                               fprintf(stderr, "Unknown type %s!", ss->protocol->type);
+                       }
                }
-       } while(1);
+       }
+       exit(RC);
 }
 
 void usage(char **argv)
index e60e45e16aa81e60cc3d87078bea1d71f909cf13..facdc82dd34936df200a6d9c2b8f1925ddfcef0d 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef BOPCHECKER_H
 #define BOPCHECKER_H
 
-#define PROXY_HTTP    0x1
-#define PROXY_WINGATE 0x2
-#define PROXY_SOCKS4  0x4
-#define PROXY_SOCKS5  0x8
+#define PROXY_HTTP    0x10
+#define PROXY_WINGATE 0x20
+#define PROXY_SOCKS4  0x40
+#define PROXY_SOCKS5  0x80
 
 void usage(char **argv);
 void log(char *data,...);
index bfe319f168525877fbcd5f8576223d88667e3727..fe038f8b52b395c129e8561999e3d73fbb2cb563 100644 (file)
--- a/config.c
+++ b/config.c
@@ -80,7 +80,8 @@ config_hash hash[] = {
        {"DNSBL_TO",            TYPE_STRING, 0,0,    &CONF_DNSBL_TO           },
        {"SENDMAIL",            TYPE_STRING, 0,0,    &CONF_SENDMAIL           },
        {"HELP_EMAIL",          TYPE_STRING, 1,0,    &CONF_HELP_EMAIL         },
-       {"AWAY",                TYPE_STRING, 0,0,    &CONF_AWAY               },
+       {"AWAY",                TYPE_STRING, 1,0,    &CONF_AWAY               },
+       {0,                     0,           0,0,    0                        },
 };