typedef struct glinebuf {
int id;
sstring *comment;
- time_t flush;
+ time_t commit;
+ time_t ammend;
- int merge;
gline *glines;
int userhits;
void glineunsetmask(const char *mask);
/* glines_buf.c */
-void glinebufinit(glinebuf *gbuf, int merge);
+void glinebufinit(glinebuf *gbuf, int id);
gline *glinebufadd(glinebuf *gbuf, const char *mask, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime);
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);
void glinebufaddbynick(glinebuf *gbuf, nick *, int flags, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime);
void glinebufcounthits(glinebuf *gbuf, int *users, int *channels, nick *spewto);
int glinebufchecksane(glinebuf *gbuf, nick *spewto, int overridesanity, int overridelimit, int spewhits);
void glinebufspew(glinebuf *gbuf, nick *spewto);
+void glinebufmerge(glinebuf *gbuf);
void glinebufcommit(glinebuf *gbuf, int propagate);
void glinebufabort(glinebuf *gbuf);
int glinebufundo(int id);
glinebuf *glinebuflog[MAXGLINELOG] = {};
int glinebuflogoffset = 0;
-void glinebufinit(glinebuf *gbuf, int merge) {
- gbuf->id = 0;
+void glinebufinit(glinebuf *gbuf, int id) {
+ gbuf->id = id;
gbuf->comment = NULL;
gbuf->glines = NULL;
- gbuf->merge = merge;
gbuf->userhits = 0;
gbuf->channelhits = 0;
array_init(&gbuf->hits, sizeof(sstring *));
}
gline *glinebufadd(glinebuf *gbuf, const char *mask, const char *creator, const char *reason, time_t expire, time_t lastmod, time_t lifetime) {
- gline *gl, *sgl, **pnext;
+ gline *gl;
gl = makegline(mask); /* sets up nick,user,host,node and flags */
return 0;
}
- if (gbuf->merge) {
- /* Check if an existing gline supercedes this mask */
- for (sgl = gbuf->glines; sgl; sgl = sgl->next) {
- if (gline_match_mask(sgl, gl)) {
- freegline(gl);
- return sgl;
- }
- }
-
- /* Remove older glines this gline matches */
- for (pnext = &gbuf->glines; *pnext; pnext = &((*pnext)->next)) {
- sgl = *pnext;
-
- if (gline_match_mask(gl, sgl)) {
- *pnext = sgl->next;
- freegline(sgl);
-
- if (!*pnext)
- break;
- }
- }
- }
-
gl->creator = getsstring(creator, 255);
/* it's not unreasonable to assume gline is active, if we're adding a deactivated gline, we can remove this later */
void glinebufspew(glinebuf *gbuf, nick *spewto) {
gline *gl;
- time_t ref;
int i;
+ char timebuf[30];
- ref = (gbuf->flush) ? gbuf->flush : getnettime();
-
- controlreply(spewto, "Mask Duration Creator Reason");
+ controlreply(spewto, "Mask Duration Last modified Creator Reason");
- for (gl = gbuf->glines; gl; gl = gl->next)
- controlreply(spewto, "%-40s %-20s %-20s %s", glinetostring(gl), longtoduration(gl->expire - ref, 0), gl->creator->content, gl->reason->content);
+ 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);
+ }
controlreply(spewto, "Hit");
controlreply(spewto, "%s", ((sstring **)gbuf->hits.content)[i]->content);
}
+void glinebufmerge(glinebuf *gbuf) {
+ /* TODO: reimplement */
+
+/*
+ if (gbuf->merge) {
+ /-* Check if an existing gline supercedes this mask *-/
+ for (sgl = gbuf->glines; sgl; sgl = sgl->next) {
+ if (gline_match_mask(sgl, gl)) {
+ freegline(gl);
+ return sgl;
+ }
+ }
+
+ /-* Remove older glines this gline matches *-/
+ for (pnext = &gbuf->glines; *pnext; pnext = &((*pnext)->next)) {
+ sgl = *pnext;
+
+ if (gline_match_mask(gl, sgl)) {
+ *pnext = sgl->next;
+ freegline(sgl);
+
+ if (!*pnext)
+ break;
+ }
+ }
+ }
+*/
+}
+
void glinebufcommit(glinebuf *gbuf, int propagate) {
gline *gl, *next, *sgl;
glinebuf *gbl;
return;
}
- time(&gbuf->flush);
+ time(&gbuf->commit);
if (propagate) {
- /* Make a copy of the glinebuf for the log */
- gbl = malloc(sizeof(glinebuf));
- gbl->id = nextglinebufid++;
- gbl->comment = (gbuf->comment) ? getsstring(gbuf->comment->content, 512) : NULL;
- gbl->flush = gbuf->flush;
- gbl->merge = gbuf->merge;
- gbl->glines = NULL; /* going to set this later */
- gbl->userhits = gbuf->userhits;
- gbl->channelhits = gbuf->channelhits;
-
- array_init(&gbl->hits, sizeof(sstring *));
+ gbl = NULL;
+
+ /* Find an existing log buffer */
+ if (gbuf->id != 0) {
+ for (i = 0; i < MAXGLINELOG; i++) {
+ if (!glinebuflog[i])
+ continue;
+
+ if (glinebuflog[i]->id == gbuf->id) {
+ gbl = glinebuflog[i];
+ gbl->ammend = gbuf->commit;
+
+ /* We're going to re-insert this glinebuf, so remove it for now */
+ glinebuflog[i] = NULL;
+
+ break;
+ }
+ }
+ }
+
+ /* Make a new glinebuf for the log */
+ if (gbuf->id == 0 || !gbl) {
+ gbl = malloc(sizeof(glinebuf));
+ gbl->id = (gbuf->id == 0) ? nextglinebufid++ : gbuf->id;
+ gbl->comment = (gbuf->comment) ? getsstring(gbuf->comment->content, 512) : NULL;
+ gbl->glines = NULL; /* going to set this later */
+ gbl->userhits = 0;
+ gbl->channelhits = 0;
+ gbl->commit = gbuf->commit;
+ gbl->ammend = 0;
+
+ array_init(&gbl->hits, sizeof(sstring *));
+ }
+
+ gbl->userhits += gbuf->userhits;
+ gbl->channelhits += gbuf->channelhits;
for (i = 0; i < gbuf->hits.cursi; i++) {
slot = array_getfreeslot(&gbl->hits);
}
}
- /* We've moved all glines to the gline list. Clear glines link in the glinebuf. */
+ /* We've moved all glines to the global gline list. Clear glines link in the glinebuf. */
gbuf->glines = NULL;
if (propagate && gbl->glines) {
else
strncpy(creator, controlid(sender), sizeof(creator));
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufcommentv(&gbuf, "BLOCK", cargc + coff - 1, cargv);
glinebufaddbynick(&gbuf, target, 0, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration);
else
strncpy(creator, controlid(sender), sizeof(creator));
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufcommentv(&gbuf, "GLINE", cargc + coff - 1, cargv);
if (!glinebufadd(&gbuf, mask, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration)) {
else
strncpy(creator, controlid(sender), sizeof(creator));
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufcommentv(&gbuf, "SMARTGLINE", cargc + coff - 1, cargv);
glinebufaddbyip(&gbuf, user, &ip, 128, 0, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration);
else
strncpy(creator, controlid(sender), sizeof(creator));
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufcommentv(&gbuf, "CLEARCHAN", cargc + coff - 1, cargv);
for (i = 0; i < victims.cursi; i++) {
return CMD_ERROR;
}
+ glinebufmerge(&gbuf);
glinebufcounthits(&gbuf, &hits, NULL, NULL);
glinebufcommit(&gbuf, 1);
for (gl = gbl->glines; gl; gl = gl->next)
count++;
- strftime(timebuf, sizeof(timebuf), "%d/%m/%y %H:%M:%S", localtime(&gbl->flush));
+ strftime(timebuf, sizeof(timebuf), "%d/%m/%y %H:%M:%S", localtime((gbl->ammend) ? &gbl->ammend : &gbl->commit));
+ strncat(timebuf, (gbl->ammend) ? "*" : " ", sizeof(timebuf));
controlreply(sender, "%-20s %-10d %-10d %-15d %-15d %s", timebuf, gbl->id, count, gbl->userhits, gbl->channelhits, gbl->comment ? gbl->comment->content : "no comment");
}
glinebuf gbuf;
int hits;
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufcommentf(&gbuf, "on IP mask %s@%s, set by %s", user, trusts_cidr2str(ip, bits), creator);
glinebufaddbyip(&gbuf, user, ip, bits, flags, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration);
glinebuf gbuf;
int hits;
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufcommentf(&gbuf, "on nick %s!%s@%s, set by %s", np->nick, np->ident, np->host->name->content, creator);
glinebufaddbynick(&gbuf, np, flags, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration);
#include "../irc/irc.h" /* irc_send() */
#include "../lib/irc_string.h" /* IPtostr(), longtoduration(), durationtolong() */
#include "../lib/strlfunc.h"
+#include "../glines/glines.h"
/* used for *_free functions that need to warn users of certain things
i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */
return (void *)1;
}
-static int glineuser(nick *np, struct gline_localdata *localdata, time_t ti) {
+static int glineuser(glinebuf *gbuf, nick *np, struct gline_localdata *localdata, time_t ti) {
char msgbuf[512];
if (!IsOper(np) && !IsService(np) && !IsXOper(np)) {
nssnprintf(msgbuf, sizeof(msgbuf), localdata->reason, np);
- glinebynick(np, localdata->duration, msgbuf, 0, "newsearch");
+ glinebufaddbynick(gbuf, np, 0, "newsearch", msgbuf, getnettime() + localdata->duration, getnettime(), getnettime() + localdata->duration);
return 1;
}
struct gline_localdata *localdata;
nick *np, *nnp;
chanindex *cip, *ncip;
- int i, j, safe=0;
+ int i, j, hits, safe=0;
time_t ti = time(NULL);
+ glinebuf gbuf;
localdata = thenode->localdata;
return;
}
+ glinebufinit(&gbuf, 0);
+
if (ctx->searchcmd == reg_chansearch) {
for (i=0;i<CHANNELHASHSIZE;i++) {
for (cip=chantable[i];cip;cip=ncip) {
continue;
if ((np=getnickbynumeric(cip->channel->users->content[j]))) {
- if(!glineuser(np, localdata, ti))
+ if(!glineuser(&gbuf, np, localdata, ti))
safe++;
}
}
for (np=nicktable[i];np;np=nnp) {
nnp = np->next;
if (np->marker == localdata->marker) {
- if(!glineuser(np, localdata, ti))
+ if(!glineuser(&gbuf, np, localdata, ti))
safe++;
}
}
}
}
+
+ glinebufcounthits(&gbuf, &hits, NULL, NULL);
+ glinebufcommit(&gbuf, 1);
+
if (safe)
ctx->reply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe);
/* notify opers of the action */
snprintf(creator, sizeof(creator), "#%s", sender->authname);
- glinebufinit(&gbuf, 1);
+ glinebufinit(&gbuf, 0);
glinebufaddbyip(&gbuf, user, &ip, 128, 0, creator, "Simulate", getnettime(), getnettime(), getnettime());
glinebufcounthits(&gbuf, &count, NULL, NULL);
glinebufspew(&gbuf, sender);