]> jfr.im git - irc/quakenet/newserv.git/blobdiff - glines/glines_buf.c
CHANSERV: remove accidental sendemail from SETEMAIL command.
[irc/quakenet/newserv.git] / glines / glines_buf.c
index 3c16eae936860c56517478a6a5ddf5702600a731..01b85c6b958897b49257936a7a071524c811aee8 100644 (file)
@@ -54,9 +54,9 @@ gline *glinebufadd(glinebuf *gbuf, const char *mask, const char *creator, const
   return gl;
 }
 
-void glinebufaddbyip(glinebuf *gbuf, const char *user, struct irc_in_addr *ip, unsigned char bits, int flags, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime) {
+char *glinebufaddbyip(glinebuf *gbuf, const char *user, struct irc_in_addr *ip, unsigned char bits, int flags, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime) {
   trusthost *th, *oth;
-  char mask[512];
+  static char mask[512];
   unsigned char nodebits;
 
   nodebits = getnodebits(ip);
@@ -68,7 +68,8 @@ void glinebufaddbyip(glinebuf *gbuf, const char *user, struct irc_in_addr *ip, u
       for (oth = th->group->hosts; oth; oth = oth->next)
         glinebufaddbyip(gbuf, user, &oth->ip, oth->bits, flags | GLINE_ALWAYS_USER | GLINE_IGNORE_TRUST, creator, reason, expire, lastmod, lifetime);
 
-      return;
+      snprintf(mask, sizeof(mask), "%s@%s/tg%u", user, (bits == 128) ? IPtostr(*ip) : CIDRtostr(*ip, bits), th->group->id);
+      return mask;
     }
   }
 
@@ -79,18 +80,32 @@ void glinebufaddbyip(glinebuf *gbuf, const char *user, struct irc_in_addr *ip, u
   if (nodebits < bits)
     bits = nodebits;
 
-  snprintf(mask, sizeof(mask), "%s@%s", user, trusts_cidr2str(ip, bits));
+  snprintf(mask, sizeof(mask), "%s@%s", user, (bits == 128) ? IPtostr(*ip) : CIDRtostr(*ip, bits));
 
   glinebufadd(gbuf, mask, creator, reason, expire, lastmod, lifetime);
+  return mask;
 }
 
-void glinebufaddbynick(glinebuf *gbuf, nick *np, int flags, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime) {
+char *glinebufaddbynick(glinebuf *gbuf, nick *np, int flags, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime) {
+  if (flags & GLINE_ALWAYS_NICK) {
+    static char mask[512];
+    snprintf(mask, sizeof(mask), "%s!*@*", np->nick);
+    glinebufadd(gbuf, mask, creator, reason, expire, lastmod, lifetime);
+    return mask;
+  } else {
+    return glinebufaddbyip(gbuf, np->ident, &np->ipaddress, 128, flags, creator, reason, expire, lastmod, lifetime);
+  }
+}
+
+void glinebufaddbywhowas(glinebuf *gbuf, whowas *ww, int flags, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime) {
+  nick *np = &ww->nick;
+
   if (flags & GLINE_ALWAYS_NICK) {
     char mask[512];
     snprintf(mask, sizeof(mask), "%s!*@*", np->nick);
     glinebufadd(gbuf, mask, creator, reason, expire, lastmod, lifetime);
   } else {
-    glinebufaddbyip(gbuf, np->ident, &np->p_ipaddr, 128, flags, creator, reason, expire, lastmod, lifetime);
+    glinebufaddbyip(gbuf, np->ident, &np->ipaddress, 128, flags, creator, reason, expire, lastmod, lifetime);
   }
 }
 
@@ -211,7 +226,7 @@ int glinebufchecksane(glinebuf *gbuf, nick *spewto, int overridesanity, int over
 void glinebufspew(glinebuf *gbuf, nick *spewto) {
   gline *gl;
   int i;
-  char timebuf[30];
+  char timebuf[30], lastmod[30];
 
   if (!gbuf->hitsvalid)
     glinebufcounthits(gbuf, NULL, NULL);
@@ -230,14 +245,20 @@ void glinebufspew(glinebuf *gbuf, nick *spewto) {
 
   if (gbuf->amend) {
     strftime(timebuf, sizeof(timebuf), "%d/%m/%y %H:%M:%S", localtime(&gbuf->amend));
-    controlreply(spewto, "Ammended at: %s", timebuf);
+    controlreply(spewto, "Amended at: %s", timebuf);
   }
 
-  controlreply(spewto, "Mask                                     Duration             Last modified        Creator              Reason");
+  controlreply(spewto, "Mask                                     Expiry               Last modified        Creator                   Reason");
   
   for (gl = gbuf->glines; gl; gl = gl->next) {
-    strftime(timebuf, sizeof(timebuf), "%d/%m/%y %H:%M:%S", localtime(&gl->lastmod));
-    controlreply(spewto, "%-40s %-20s %-20s %-20s %s", glinetostring(gl), longtoduration(gl->expire - gl->lastmod, 0), timebuf, gl->creator->content, gl->reason->content);
+    strftime(timebuf, sizeof(timebuf), "%d/%m/%y %H:%M:%S", localtime(&gl->expire));
+    if (gl->lastmod == 0)
+      strncpy(lastmod, "<ulined>", sizeof(lastmod));
+    else
+      strftime(lastmod, sizeof(lastmod), "%d/%m/%y %H:%M:%S", localtime(&gl->lastmod));
+
+    controlreply(spewto, "%-40s %-20s %-20s %-25s %s", glinetostring(gl), timebuf, lastmod, gl->creator->content, gl->reason ? gl->reason->content : "");
   }
 
   controlreply(spewto, "Hits");
@@ -292,7 +313,7 @@ int glinebufcommit(glinebuf *gbuf, int propagate) {
   glinebufcounthits(gbuf, &users, &channels);
 
   if (propagate && (users > MAXGLINEUSERHITS || channels > MAXGLINECHANNELHITS)) {
-    controlwall(NO_OPER, NL_GLINES, "G-Line buffer would hit %d users/%d channels. Not setting G-Lines.");
+    controlwall(NO_OPER, NL_GLINES_AUTO, "G-Line buffer would hit %d users/%d channels. Not setting G-Lines.");
     glinebufabort(gbuf);
     return 0;
   }
@@ -484,7 +505,7 @@ int glinebufwritelog(glinebuf *gbuf, int propagating) {
   }
 
   /* Make a new glinebuf for the log */
-  if (!gbl && gbuf->id == 0) {
+  if (!gbl) {
     gbl = malloc(sizeof(glinebuf));
     glinebufinit(gbl, (gbuf->id == 0) ? nextglinebufid++ : gbuf->id);
 
@@ -493,7 +514,7 @@ int glinebufwritelog(glinebuf *gbuf, int propagating) {
     if (gbuf->comment)
       glinebufcommentf(gbl, "%s", gbuf->comment->content);
     else if (!propagating)
-      glinebufcommentf(gbl, "Remote G-Lines set by %s", gbuf->glines->creator->content);
+      glinebufcommentf(gbl, "G-Lines set by %s", gbuf->glines->creator->content);
 
     gbl->commit = gbuf->commit;
   }
@@ -524,7 +545,7 @@ int glinebufwritelog(glinebuf *gbuf, int propagating) {
   if (glinebuflog[glinebuflogoffset])
     glinebufabort(glinebuflog[glinebuflogoffset]);
 
-  glinebuflog[glinebuflogoffset]= gbl;
+  glinebuflog[glinebuflogoffset] = gbl;
 
   return gbl->id;
-}
\ No newline at end of file
+}