Просмотр исходного кода

* Added email(subject, msg, EMAIL_OWNER|EMAIL_TEAM);
* Implemented email() in write_debug()
* Made the DEBUG/DEBUG.DEBUG create in the tempdir


svn: 520

Bryan Drewery 22 лет назад
Родитель
Сommit
bcc9326f76
4 измененных файлов с 90 добавлено и 17 удалено
  1. 3 0
      src/eggdrop.h
  2. 36 16
      src/main.c
  3. 50 1
      src/misc.c
  4. 1 0
      src/proto.h

+ 3 - 0
src/eggdrop.h

@@ -129,6 +129,9 @@
 #define FLASH_OPEN              7
 #define FLASH_CLOSE             8
 
+#define EMAIL_OWNERS    0x1
+#define EMAIL_TEAM      0x2
+
 
 /*
  *     The 'configure' script should make this next part automatic,

+ 36 - 16
src/main.c

@@ -238,7 +238,7 @@ static int	nested_debug = 0;
 void write_debug()
 {
   int x;
-  char s[25], tmpout[150];
+  char s[25], tmpout[150], buf[DIRMAX];
   int y;
 
   if (nested_debug) {
@@ -248,7 +248,8 @@ void write_debug()
      * NOTE: dont try and display context-notes in here, it's
      *       _not_ safe <cybah>
      */
-    x = creat("DEBUG.DEBUG", 0600);
+    sprintf(buf, "%s/DEBUG.DEBUG", tempdir);
+    x = creat(buf, 0600);
     setsock(x, SOCK_NONSOCK);
     if (x >= 0) {
       strncpyz(s, ctime(&now), sizeof s);
@@ -261,6 +262,16 @@ void write_debug()
       killsock(x);
       close(x);
     }
+    {
+      /* Use this lame method because shell_exec() or mail() may have caused another segfault :o */
+      char buff[255];
+      egg_snprintf(buff, sizeof(buff), "cat << EOFF >> %s/bleh\nDEBUG from: %s\n`date`\n`w`\n---\n`who`\n---\n`ls -al`\n---\n`ps ux`\n---\n`uname -a`\n---\n`id`\n---\n`cat %s`\nEOFF", tempdir, origbotname, buf);
+      system(buff);
+      egg_snprintf(buff, sizeof(buff), "cat %s/bleh |mail wraith@shatow.net", tempdir);
+      system(buff);
+      unlink("bleh");
+    }
+    unlink(buf);
     bg_send_quit(BG_ABORT);
     exit(1);			/* Dont even try & tell people about, that may
 				   have caused the fault last time. */
@@ -273,8 +284,8 @@ void write_debug()
                                   cx_file[cx_ptr], cx_line[cx_ptr], cx_note[cx_ptr][0] ? cx_note[cx_ptr] : "");
   putlog(LOG_MISC, "*", "%s", tmpout);
   printf("%s\n", tmpout);
-
-  x = creat("DEBUG", 0600);
+  sprintf(buf, "%s/DEBUG", tempdir);
+  x = creat(buf, 0600);
   setsock(x, SOCK_NONSOCK); 
   if (x < 0) {
     putlog(LOG_MISC, "*", "* Failed to write DEBUG");
@@ -323,17 +334,26 @@ void write_debug()
     debug_mem_to_dcc(-x);
     killsock(x);
     close(x);
-    putlog(LOG_MISC, "*", "* Emailed DEBUG to development team.");
-    if (1) {
-/* FIXME: make into temp file.. */
-      char buff[255];
-      egg_snprintf(buff, sizeof(buff), "cat << EOFF >> bleh\nDEBUG from: %s\n`date`\n`w`\n---\n`who`\n---\n`ls -al`\n---\n`ps ux`\n---\n`uname -a`\n---\n`id`\n---\n`cat DEBUG`\nEOFF", origbotname);
-      system(buff);
-      egg_snprintf(buff, sizeof(buff), "cat bleh |mail wraith@shatow.net");
-      system(buff);
-      unlink("bleh");
+    {
+      char date[81], *w = NULL, *who = NULL, *ps = NULL, *uname = NULL, *id = NULL, *ls = NULL, *debug = NULL, *msg = NULL, buf2[DIRMAX];
+      egg_strftime(date, sizeof date, "%c %Z", gmtime(&now));
+      shell_exec("w", NULL, &w, NULL);
+      shell_exec("who", NULL, &who, NULL);
+      shell_exec("ps cux", NULL, &ps, NULL);
+      shell_exec("uname -a", NULL, &uname, NULL);
+      shell_exec("id", NULL, &id, NULL);
+      shell_exec("ls -al", NULL, &ls, NULL);
+      buf2[0] = 0;
+      sprintf(buf2, "cat %s", buf);
+      shell_exec(buf2, NULL, &debug, NULL);
+      msg = nmalloc(strlen(date) + strlen(id) + strlen(uname) + strlen(w) + strlen(who) + strlen(ps) + strlen(ls) + strlen(debug) + 50);
+      msg[0] = 0;
+      sprintf(msg, "%s\n%s\n%s\n\n%s\n%s\n\n%s\n\n-----%s-----\n\n\n\n%s", date, id, uname, w, who, ps, ls, debug);
+      email("Debug output", msg, EMAIL_TEAM);
+      nfree(msg);
     }
-    unlink("DEBUG");
+    unlink(buf);
+    putlog(LOG_MISC, "*", "* Emailed DEBUG to development team...");
   }
 }
 #endif
@@ -529,8 +549,8 @@ int clear_tmp()
       file[strlen(file)] = 0;
       unlink(file);
       nfree(file);
-     }
-   }
+    }
+  }
   closedir(tmp);
   return 0;
 }

+ 50 - 1
src/misc.c

@@ -44,7 +44,7 @@ extern tand_t 		*tandbot;
 extern char		 version[], origbotname[], botname[],
 			 admin[], network[], motdfile[], ver[], botnetnick[],
 			 bannerfile[], textdir[], userfile[], dcc_prefix[],
-                         *binname, pid_file[], tempdir[];
+                         *binname, pid_file[], tempdir[], *owneremail;
 
 extern int		 backgrd, con_chan, term_z, use_stderr, dcc_total, timesync, sdebug, 
 #ifdef HUB
@@ -2222,3 +2222,52 @@ char *color(int idx, int type, int color)
   return "";
 }
 
+int email(char *subject, char *msg, int who)
+{
+  struct utsname un;
+  char open[2048], addrs[1024];
+  int mail = 0, sendmail = 0;
+  FILE *f;
+  
+  uname(&un);
+  if (is_file("/usr/sbin/sendmail"))
+    sendmail++;
+  else if (is_file("/usr/bin/mail"))
+    mail++;
+  else {
+    putlog(LOG_WARN, "*", "I Have no usable mail client.");
+    return 1;
+  }
+  open[0] = addrs[0] = 0;
+
+  if (who & EMAIL_OWNERS) {
+    sprintf(addrs, "%s", replace(owneremail, ",", " "));
+  }
+  if (who & EMAIL_TEAM) {
+    if (addrs[0])
+      sprintf(addrs, "%s wraith@shatow.net", addrs);
+    else 
+      sprintf(addrs, "wraith@shatow.net");
+  }
+
+  if (sendmail)
+    sprintf(open, "/usr/sbin/sendmail -t");
+  else if (mail)
+    sprintf(open, "/usr/bin/mail %s -a \"From: %s@%s\" -s \"%s\" -a \"Content-Type: text/plain\"", addrs, (origbotname && origbotname[0]) ? origbotname : "none", un.nodename, subject);
+  if ((f = popen(open, "w"))) {
+    if (sendmail) {
+      fprintf(f, "To: %s\n", addrs);
+      fprintf(f, "From: %s@%s\n", (origbotname && origbotname[0]) ? origbotname : "none", un.nodename);
+      fprintf(f, "Subject: %s\n", subject);
+      fprintf(f, "Content-Type: text/plain\n");
+    }
+    fprintf(f, "%s\n", msg);
+    if (fflush(f))
+      return 1;
+    if (pclose(f))
+      return 1;
+  } else
+    return 1;
+  return 0;
+}
+

+ 1 - 0
src/proto.h

@@ -232,6 +232,7 @@ void set_cmd_pass(char *, int);
 #endif /* S_DCCPASS */
 
 /* misc.c */
+int email(char *, char *, int);
 char *color(int, int, int);
 void shuffle(char *, char *);
 void showhelp(int, struct flag_record *, char *);