Parcourir la source

* Finished up release version of cmd_conf

svn: 989
Bryan Drewery il y a 22 ans
Parent
commit
17542dc650
5 fichiers modifiés avec 159 ajouts et 31 suppressions
  1. 1 0
      doc/UPDATES
  2. 33 0
      misc/help.txt
  3. 69 18
      src/cmds.c
  4. 52 13
      src/conf.c
  5. 4 0
      src/conf.h

+ 1 - 0
doc/UPDATES

@@ -29,6 +29,7 @@ This is a summary of ChangeLog basically.
 24.Fixed a problem with my chmod() function.
 24.Fixed a problem with my chmod() function.
 25.Fixed many various somewhat random bugs.
 25.Fixed many various somewhat random bugs.
 26.Hubs weren't setting their link socket to encrypt early enough.
 26.Hubs weren't setting their link socket to encrypt early enough.
+27.Added cmd_conf for modifying the bot's shell conf via dcc.
 
 
 1.1.5
 1.1.5
 
 

+ 33 - 0
misc/help.txt

@@ -664,6 +664,39 @@ See also: echo, page, strip
    Creates or changes the comment field for a user. The comment field can only
    Creates or changes the comment field for a user. The comment field can only
    be seen via 'whois' or 'match'. Non-masters cannot see the comment field.
    be seen via 'whois' or 'match'. Non-masters cannot see the comment field.
    Using the comment 'none' will clear a user's comment.
    Using the comment 'none' will clear a user's comment.
+::conf:
+###  %bconf%b <add|del|list|set> [options]
+ 
+   This command is used to modify the bot's local shell config. Only
+   the first bot listed will be able to perform this command. Using the cmd
+   on a non-'localhub' will result in an error similar to:
+ 
+   [16:42] #bryan# botcmd wtest2 conf ...
+   [wtest2] Please use 'wtest' for this login/shell.
+ 
+   Simple use the command on the bot specified.
+   
+    'add' uses the same syntax as the conf file:
+      add <bot> [<ip|.> <[+]host|.> [ipv6-ip]]
+      ip/host/ipv6-ip are all optional and/or can be replaced with '.'
+     Newly added bots will start immediately, don't forget to 'newleaf'.
+ 
+    'del' syntax is simply:
+      del <bot>
+    Deleted bots that are running will be killed.
+  
+    'list' shows all the bots currently in the config.
+ 
+    'set' allows changing some variables in the config.
+      Using with no parameters will show all changable options.
+      Simply specifiy the option and new setting as follows:
+      set <what> [option]
+      WARNING: Options changed MAY OR MAY not affect bots already running,
+               it is a good idea to restart all bots on the shell
+               if you change any of the following: 
+    %bhomedir%b, %bbinpath%b, %bbinname%b, %bportmin%b, %bportmax%b, %bpscloak%b
+ 
+See also: newleaf
 :hub:config:
 :hub:config:
 ###  %bconfig%b [name [value|-]]
 ###  %bconfig%b [name [value|-]]
    Sets various config options. Type alone to see all config entries. To set
    Sets various config options. Type alone to see all config entries. To set

+ 69 - 18
src/cmds.c

@@ -1841,6 +1841,9 @@ static void cmd_sha1(struct userrec *u, int idx, char *par)
 static void cmd_conf(struct userrec *u, int idx, char *par)
 static void cmd_conf(struct userrec *u, int idx, char *par)
 {
 {
   char *cmd = NULL;
   char *cmd = NULL;
+#ifdef LEAF
+  char *listbot = NULL;
+#endif /* LEAF */
   int save = 0;
   int save = 0;
 
 
   if (!localhub) {
   if (!localhub) {
@@ -1854,28 +1857,51 @@ static void cmd_conf(struct userrec *u, int idx, char *par)
   /* del/change should restart the specified bot ;) */
   /* del/change should restart the specified bot ;) */
 
 
   if (!cmd) {
   if (!cmd) {
-    dprintf(idx, "Usage: conf <add|del|list|change|set> [options]\n");
+#ifdef LEAF
+    dprintf(idx, "Usage: conf <add|del|list|set> [options]\n");
+#endif /* LEAF */
+#ifdef HUB
+    dprintf(idx, "Usage: conf <set> [options]\n");
+#endif /* HUB */
     return;
     return;
   }
   }
   
   
   putlog(LOG_CMDS, "*", "#%s# conf %s %s", dcc[idx].nick, cmd, par[0] ? par : "");
   putlog(LOG_CMDS, "*", "#%s# conf %s %s", dcc[idx].nick, cmd, par[0] ? par : "");
+#ifdef LEAF
+  if (!egg_strcasecmp(cmd, "add")) {
+    char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
 
 
-  if (!egg_strcasecmp(cmd, "list")) {
-    conf_bot *bot = NULL;
-    unsigned int i = 0;
+    nick = newsplit(&par);
+    if (!nick || (nick && !nick[0])) {
+      dprintf(idx, "Usage: conf add <bot> [<ip|.> <[+]host|.> [ipv6-ip]]\n");
+      return;
+    }
 
 
-    for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
-      i++;
-      dprintf(idx, "%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
-                    bot->nick,
-                    bot->ip ? bot->ip : "",
-                    bot->host ? bot->host : "",
-                    bot->ip6 ? bot->ip6 : "",
-                    bot->host6 ? bot->host6 : "",
-                    bot->pid);
+    if (par[0])
+      ip = newsplit(&par);
+    if (par[0])
+      host = newsplit(&par);
+    if (par[0])
+      ipsix = newsplit(&par);
+
+    conf_addbot(nick, ip, host, ipsix);
+    dprintf(idx, "Added bot: %s\n", nick);
+    listbot = strdup(nick);
+    save++;
+  } else if (!egg_strcasecmp(cmd, "del")) {
+    if (!par[0]) {
+      dprintf(idx, "Usage: conf del <bot>\n");
+      return;
     }
     }
-#ifndef CYGWIN_HACKS
-  } else if (!egg_strcasecmp(cmd, "set")) {
+    if (!conf_delbot(par)) {
+      dprintf(idx, "Deleted bot: %s\n", par);
+      save++;
+    } else
+      dprintf(idx, "Error trying to remove bot '%s'\n", par);
+  }
+#endif /* LEAF */
+#if !defined(CYGWIN_HACKS) || defined(HUB)
+  if (!egg_strcasecmp(cmd, "set")) {
     char *what = NULL;
     char *what = NULL;
     int show = 1, set = 0;
     int show = 1, set = 0;
 
 
@@ -1920,11 +1946,36 @@ static void cmd_conf(struct userrec *u, int idx, char *par)
       if (!what || !egg_strcasecmp(what, "autocron"))   dprintf(idx, "%sautocron: %d\n", ss, conffile.autocron);
       if (!what || !egg_strcasecmp(what, "autocron"))   dprintf(idx, "%sautocron: %d\n", ss, conffile.autocron);
       if (!what || !egg_strcasecmp(what, "autouname"))  dprintf(idx, "%sautouname: %d\n", ss, conffile.autouname);
       if (!what || !egg_strcasecmp(what, "autouname"))  dprintf(idx, "%sautouname: %d\n", ss, conffile.autouname);
     }
     }
-#endif /* !CYGWIN_HACKS */
   }
   }
-  if (save)
+#endif /* !CYGWIN_HACKS || HUB */
+
+#ifdef LEAF
+  if (listbot || !egg_strcasecmp(cmd, "list")) {
+    conf_bot *bot = NULL;
+    unsigned int i = 0;
+
+    for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+      i++;
+      if (!listbot || (listbot && !strcmp(listbot, bot->nick)))
+        dprintf(idx, "%d: %s IP: %s HOST: %s IP6: %s HOST6: %s PID: %d\n", i,
+                      bot->nick,
+                      bot->ip ? bot->ip : "",
+                      bot->host ? bot->host : "",
+                      bot->ip6 ? bot->ip6 : "",
+                      bot->host6 ? bot->host6 : "",
+                      bot->pid);
+    }
+  }
+  if (listbot)
+    free(listbot);
+#endif /* LEAF */
+
+  if (save) {
     writeconf(cfile, NULL, CONF_ENC);
     writeconf(cfile, NULL, CONF_ENC);
-  /* showconf(idx); */
+#ifdef LEAF
+    spawnbots();			/* parse conffile struct and spawn/kill as needed */
+#endif /* LEAF */
+  }
 }
 }
 
 
 static void cmd_encrypt(struct userrec *u, int idx, char *par)
 static void cmd_encrypt(struct userrec *u, int idx, char *par)

+ 52 - 13
src/conf.c

@@ -307,7 +307,10 @@ checkpid(char *nick, conf_bot * bot)
   return 0;
   return 0;
 }
 }
 
 
-static void
+#ifdef HUB
+static
+#endif /* HUB */
+void
 conf_addbot(char *nick, char *ip, char *host, char *ip6)
 conf_addbot(char *nick, char *ip, char *host, char *ip6)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
@@ -349,6 +352,53 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
   bot->pid = checkpid(nick, bot);
   bot->pid = checkpid(nick, bot);
 }
 }
 
 
+void 
+free_bot(char *botn)
+{
+  conf_bot *bot = NULL, *old = NULL;
+
+  for (bot = conffile.bots; bot && bot->nick; old = bot, bot = bot->next) {
+    if (!strcmp(botn, bot->nick)) {
+      free(bot->nick);
+      free(bot->pid_file);
+      if (bot->ip)
+        free(bot->ip);
+      if (bot->host)
+        free(bot->host);
+      if (bot->ip6)
+        free(bot->ip6);
+      if (bot->host6)
+        free(bot->host6);
+
+      if (old)
+        old->next = bot->next;
+      else
+        conffile.bots = bot->next;
+      free(bot);
+
+      break;
+    }
+  }
+}
+
+#ifdef LEAF
+int
+conf_delbot(char *botn)
+{
+  conf_bot *bot = NULL;
+  
+  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+    if (!strcmp(bot->nick, botn)) { /* found it! */
+      bot->pid = checkpid(bot->nick, bot);
+      killbot(bot->nick);
+      free_bot(bot->nick);
+      return 0;
+    }
+  }
+  return 1;
+}
+#endif /* LEAF */
+
 void
 void
 free_conf()
 free_conf()
 {
 {
@@ -356,18 +406,7 @@ free_conf()
 
 
   for (bot = conffile.bots; bot; bot = bot_n) {
   for (bot = conffile.bots; bot; bot = bot_n) {
     bot_n = bot->next;
     bot_n = bot->next;
-    free(bot->nick);
-    free(bot->pid_file);
-    if (bot->ip)
-      free(bot->ip);
-    if (bot->host)
-      free(bot->host);
-    if (bot->ip6)
-      free(bot->ip6);
-    if (bot->host6)
-      free(bot->host6);
-    /* must also free() anything malloc`d in conf_addbot() */
-    free(bot);
+    free_bot(bot->nick);
   }
   }
   free(conffile.uname);
   free(conffile.uname);
   free(conffile.username);
   free(conffile.username);

+ 4 - 0
src/conf.h

@@ -55,6 +55,10 @@ int killbot(char *);
 #ifdef S_CONFEDIT
 #ifdef S_CONFEDIT
 void confedit(char *) __attribute__((noreturn));
 void confedit(char *) __attribute__((noreturn));
 #endif /* S_CONFEDIT */
 #endif /* S_CONFEDIT */
+#ifdef LEAF
+void conf_addbot(char *, char *, char *, char *);
+int conf_delbot(char *);
+#endif /* LEAF */
 pid_t checkpid(char *, conf_bot *);
 pid_t checkpid(char *, conf_bot *);
 void init_conf();
 void init_conf();
 void free_conf();
 void free_conf();