]> jfr.im git - irc/blitzed-org/bopm.git/commitdiff
Merged patch from Sotiris Tsimbonis <stsimb@irc.gr> with minor changes.
authorandy <redacted>
Thu, 24 Jan 2002 06:07:48 +0000 (06:07 +0000)
committerandy <redacted>
Thu, 24 Jan 2002 06:07:48 +0000 (06:07 +0000)
Adds a -c command line argument which tells bopm to use a different name
for log, pid and config files.  i.e. ./bopm -c myserver will use
myserver.conf, myserver.log, myserver.pid.

The patch also makes bopm set umode -h on itself after opering, in order
to prevent the bot appearing in /stats p output (shows opers available to
help).

bopchecker now takes the -c option also, in the same way as bopm.

INSTALL
README
bopchecker.c
extern.h
irc.c
main.c
options.h

diff --git a/INSTALL b/INSTALL
index d783e84121e04318bba12f3e4cb99d83f88ec247..eb73ca06002fe9f6c0da3634118738610112c59c 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -17,9 +17,19 @@ Execution
 connect to the IRC server immediately.  Any errors and debug information can be
 found in bopm.log.
 
+    You can tell bopm to use a different config file with the -c argument,
+this works the same way that wgmon's -c argument does, just give the name of
+the config file not including the ".conf".  This also affects the log and PID
+files i.e. ./bopm -c myserver will read from myserver.conf, log to myserver.log
+and write PID to myserver.pid.  If you do not use -c, the files bopm.conf,
+bopm.log and bopm.pid will be used by default.  This can be altered in
+options.h.
+
     Further debugging can be enabled by using one or more -d switches.  One or
 more -d switches will cause the bot to not fork on startup, and it will send
 all log messages to stederr (i.e., your terminal) instead of its logfile.  It
 will also cause extra debugging information that is not normally of interest to
 be sent to stderr.  Two or more -d switches will enable logging of all IRC
 traffic received and sent.
+
+    The -c and -d arguments may appear in any order.
diff --git a/README b/README
index 733120214f972b2d42eec23a8903f51bfd4c7f17..847e5fa68d1de3b1a72f4d9ddf7d84f4ccfde725 100644 (file)
--- a/README
+++ b/README
@@ -37,16 +37,22 @@ Credits
 -------
 
    Erik Fears <strtok@blitzed.org>
-         Main Developer.
+         Main Developer.
 
    Andy Smith <grifferz@blitzed.org>
-         Developed operator interface, interface to DNSbl, makefile
-         trickery, poking people with sticks until they did things,
-         debugging.
+         - Developed operator interface
+         - Interface to DNSbl
+         - Makefile trickery
+         - Poking people with sticks until they did things
+         - Debugging
+         - Evil bopchecker hack
  
    David Leadbeater <dg@blitzed.org> 
-         Developed perl script (see proxy-tools in Blitzed CVS repository)
-         to test BOPM's support for scanning many clients at once.
+        - Developed perl script (see proxy-tools in Blitzed CVS repository) to
+          test BOPM's support for scanning many clients at once
 
+   Sotiris Tsimbonis <stsimb@irc.gr>
+         - Added -c command line argument
+         - Idea to make bopm set umode -h on oper
 
    For support, irc.blitzed.org #blitzed before emailing a developer. Thank you.
index cb2d3eb32b0d0f34dcfa8cef8823f634c8cfc85f..69fb0a711909aebdff4e3baa92ec85b8f2c30696 100644 (file)
@@ -41,56 +41,85 @@ along with this program; if not, write to the Free Software
 extern struct scan_struct *CONNECTIONS;
 
 int OPT_DEBUG = 1;
+char *CONFNAME = DEFAULTNAME;
+char *CONFFILE;
 
 int main(int argc, char **argv)
 {
        struct hostent *he;
-       char *ip;
+       char *ip, *host;
        struct scan_struct *ss;
-       
-       if (argc != 2) {
+       int len, c;
+
+       while (1) {
+               c = getopt(argc, argv, "+c:");
+
+               if (c == -1)
+                       break;
+
+               switch (c) {
+                       case 'c':
+                               CONFNAME = strdup(optarg);
+                               break;
+                       case '?':
+                       default:
+                               /* unknown arg, just do nothing */
+                               break;
+               }
+       }
+
+       if (argc - optind != 1) {
                usage(argv);
                return(EXIT_FAILURE);
        }
 
        signal(SIGPIPE, SIG_IGN);
 
-       config_load(LOGFILE);
+       len = strlen(CONFNAME) + strlen(CONFEXT) + 2;
+       CONFFILE = (char *) malloc(len * sizeof(char));
+       snprintf(CONFFILE, len, "%s.%s", CONFNAME, CONFEXT);
+
+       config_load(CONFFILE);
        do_scan_init();
 
-       if(!(he = gethostbyname(argv[1]))) {
+       if (optind > 0)
+               host = argv[optind];
+       else
+               host = argv[1];
+
+       if(!(he = gethostbyname(host))) {
                switch(h_errno) {
                        case HOST_NOT_FOUND:
-                               fprintf(stderr, "Host '%s' is unknown.",
-                                       argv[1]);
+                               fprintf(stderr, "Host '%s' is unknown.\n",
+                                       host);
                                return(1);
                        case NO_ADDRESS:
                                fprintf(stderr, "The specified name '%s' "
-                                       "exists, but has no address.",
-                                       argv[1]);
+                                       "exists, but has no address.\n",
+                                       host);
                                return(1);
                        case NO_RECOVERY:
                                fprintf(stderr, "An unrecoverable error "
-                                       "occured whilst resolving '%s'.",
-                                       argv[1]);
+                                       "occured whilst resolving '%s'.\n",
+                                       host);
                                return(1);
                        case TRY_AGAIN:
                                fprintf(stderr, "A temporary error "
                                        "occurred on an authoritative name "
-                                       "server.");
+                                       "server.\n");
                                return(1);
                        default:
                                fprintf(stderr, "Unknown error resolving "
-                                       "'%s'.", argv[1]);
+                                       "'%s'.\n", host);
                                return(EXIT_FAILURE);
                }
        }
 
        ip = inet_ntoa(*((struct in_addr *) he->h_addr));
 
-       fprintf(stderr, "Checking %s [%s] for open proxies\n", argv[1], ip);
+       fprintf(stderr, "Checking %s [%s] for open proxies\n", host, ip);
 
-       scan_connect(ip, argv[1], "*", "*", 1, 0);    /* Scan using verbose */
+       scan_connect(ip, host, "*", "*", 1, 0);    /* Scan using verbose */
 
        do {
                int still_alive = 0;
@@ -111,7 +140,7 @@ int main(int argc, char **argv)
 
 void usage(char **argv)
 {
-       fprintf(stderr, "Usage: %s <host>\n", argv[0]);
+       fprintf(stderr, "Usage: %s [-c configname] <host>\n", argv[0]);
 }
 
 void log(char *data,...)
index 1eb52b510a26c9ffa826e0f5c62e436915031282..bb07f0d3048c513d2f605c734bcfb4816aadf379 100644 (file)
--- a/extern.h
+++ b/extern.h
@@ -26,6 +26,7 @@
 
     extern int   CONF_PORT;
     extern int   CONF_SCANPORT;
+    extern int   CONF_PING;
 
     extern int   OPT_DEBUG;
  
diff --git a/irc.c b/irc.c
index 00111c3c099079b638124881d664f8f5a05c6b7f..25def574cad318804ac1c5ed861f53fac192b216 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -46,6 +46,8 @@ along with this program; if not, write to the Free Software
 #include "options.h"
 #include "version.h"
 
+extern char *CONFFILE;
+
 /* Certain variables we don't want to allocate memory for over and over again
  * so global scope is given */
 
@@ -75,7 +77,7 @@ void irc_cycle()
        
       if(IRC_FD <= 0)                 /* No socket open         */
         {
-          config_load(LOGFILE);       /* Reload config          */
+          config_load(CONFFILE);      /* Reload config          */
           irc_init();                 /* Resolve remote host    */
           irc_connect();              /* Connect to remote host */
         }
@@ -400,7 +402,7 @@ void irc_parse()
     if(!strcasecmp(token[1], "001"))
      { 
          irc_send("OPER %s", CONF_OPER);
-         irc_send("MODE %s +c", CONF_NICK);      
+         irc_send("MODE %s +c-h", CONF_NICK);      
         if(CONF_AWAY)
            irc_send("AWAY :%s (/msg %s INFO)", CONF_AWAY, CONF_NICK);
          do_perform();   
diff --git a/main.c b/main.c
index 4254029a1589d953095c8c232dce1737e336098d..c462b088a4e841bcb3c1c2ac4695ff2a92f7265c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -48,6 +48,9 @@ void do_int(int);
 int ALARMED = 0;
 
 int OPT_DEBUG = 0;
+char *CONFNAME = DEFAULTNAME;
+
+char *CONFFILE, *LOGFILE, *PIDFILE;
 
 struct sigaction ALARMACTION;
 struct sigaction INTACTION;
@@ -56,20 +59,24 @@ int main(int argc, char **argv)
 {
 
    FILE *pidout;
-   int pid, c;
+   int pid, c, lenc, lenl, lenp;
    char spid[16];
 
    do_stats_init();
    do_scan_init();
+
    while(1)
     {
-       c = getopt(argc, argv, "d");
+       c = getopt(argc, argv, "dc:");
 
        if(c == -1)
            break;
 
        switch(c)
         {
+          case 'c':
+              CONFNAME = strdup(optarg);
+              break;
            case 'd':
                OPT_DEBUG++;
                break;
@@ -80,6 +87,18 @@ int main(int argc, char **argv)
         }
     }  
 
+   lenc = strlen(CONFNAME) + strlen(CONFEXT) + 2;
+   lenl = strlen(CONFNAME) + strlen(LOGEXT) + 2;
+   lenp = strlen(CONFNAME) + strlen(PIDEXT) + 2;
+
+   CONFFILE = (char *) malloc(lenc * sizeof(char));
+   LOGFILE = (char *) malloc(lenl * sizeof(char));
+   PIDFILE = (char *) malloc(lenp * sizeof(char));
+
+   snprintf(CONFFILE, lenc, "%s.%s", CONFNAME, CONFEXT);
+   snprintf(LOGFILE, lenl, "%s.%s", CONFNAME, LOGEXT);
+   snprintf(PIDFILE, lenp, "%s.%s", CONFNAME, PIDEXT);
+
    /* Fork off */
 
    if(!OPT_DEBUG)
@@ -91,7 +110,7 @@ int main(int argc, char **argv)
        }
        else if(pid != 0)
         {
-           pidout = fopen("bopm.pid", "w");
+           pidout = fopen(PIDFILE, "w");
            snprintf(spid, 16, "%d", pid);
 
            if(pidout)         
@@ -117,7 +136,7 @@ int main(int argc, char **argv)
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
 
-       log_open("bopm.log"); 
+       log_open(LOGFILE); 
     }
    else
     {
@@ -127,7 +146,7 @@ int main(int argc, char **argv)
     log("MAIN -> BOPM %s started.", VERSION);
     log("MAIN -> Reading configuration file...");
 
-    config_load(LOGFILE);
+    config_load(CONFFILE);
 
     /* Setup alarm & int handlers */
  
index 01c21d9abc15e9874dfa626618aed32f99b3bd85..95c7a74f2de7e18f8971739d1d9ea636db8d7c22 100644 (file)
--- a/options.h
+++ b/options.h
@@ -1,9 +1,19 @@
 #ifndef OPTIONS_H
 #define OPTIONS_H
   
-      #define LOGFILE "bopm.conf"
-      /* Defines time in which bot will timeout
-       * if no data is received (default 15 min) */
-      #define NODATA_TIMEOUT 900
+/* The default name for conf, log, pid files */
+#define DEFAULTNAME "bopm"
+
+/* file extensions */
+/* config */
+#define CONFEXT "conf"
+/* log file */
+#define LOGEXT "log"
+/* PID file */
+#define PIDEXT "pid"
+
+/* Defines time in which bot will timeout * if no data is received
+ * (default 15 min) */
+#define NODATA_TIMEOUT 900
                 
 #endif