Used the new SIGUSR1 hook to trigger a reopen of the chanserv log file.
Changed the name of the active logfile to "chanservlog" for better logrotate compatibility
Fixed grep to actually work and tested it with the rotating logfiles
Updated userflags & whois to use the new "printflagsornone" when displaying user flags
Fixed incorrect error message in giveowner
/* You need to either be +n or have the relevant override... */
if (!(cip=cs_checkaccess(sender, cargv[0], CA_OWNERPRIV,
- NULL, "chanlev", QPRIV_CHANGECHANLEV, 0)))
+ NULL, "giveowner", QPRIV_CHANGECHANLEV, 0)))
return CMD_ERROR;
rcp=cip->exts[chanservext];
#include <stdio.h>
#include <unistd.h>
-#define CSG_BUFSIZE 512
+#define CSG_BUFSIZE 1024
pcre *csg_curpat; /* Compiled pattern from pcre */
int csg_curfile; /* Which logfile is being searched */
unsigned long csg_curnum; /* What numeric is doing a search */
int csg_matches; /* How many lines have been returned so far */
int csg_maxmatches=0; /* How many matches are allowed */
+int csg_bytesread;
char csg_readbuf[CSG_BUFSIZE]; /* Buffer */
int csg_bytesleft; /* How much valid data there is in the buffer */
return CMD_ERROR;
}
- if ((fd=open("chanservlog.0",O_RDONLY))<0) {
+ if ((fd=open("chanservlog",O_RDONLY))<0) {
chanservsendmessage(sender, "Unable to open logfile.");
free(csg_curpat);
return CMD_ERROR;
csg_curnum=sender->numeric;
csg_curfile=0;
csg_bytesleft=0;
+ csg_bytesread=0;
registerhandler(fd, POLLIN, csg_handleevents);
chanservsendmessage(sender, "Started grep for %s...",cargv[0]);
res=read(fd, csg_readbuf+csg_bytesleft, CSG_BUFSIZE-csg_bytesleft);
if (res<=0) {
+/* chanservsendmessage(np, "Closing file: res=%d, errno=%d(%s), bytes read=%d",res,errno,sys_errlist[errno],csg_bytesread); */
/* End of file (or error) */
deregisterhandler(fd, 1);
sprintf(filename,"chanservlog.%d",++csg_curfile);
return;
}
+ csg_bytesread+=res;
+
linestart=chp=csg_readbuf;
csg_bytesleft+=res;
#include <stdarg.h>
#include <stdio.h>
#include "chanserv.h"
+#include "../core/hooks.h"
+#include "../core/error.h"
int logfd;
+/* When we get a sigusr1, reopen the logfile */
+void cs_usr1handler(int hooknum, void *arg) {
+ Error("chanserv",ERR_INFO,"Reopening logfile.");
+
+ if (logfd>=0)
+ close(logfd);
+
+ logfd=open("chanservlog",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
+}
+
void cs_initlog() {
- logfd=open("chanservlog.0",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
+ logfd=open("chanservlog",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
+ registerhook(HOOK_CORE_SIGUSR1, cs_usr1handler);
}
void cs_closelog() {
if (logfd>=0)
close(logfd);
+ deregisterhook(HOOK_CORE_SIGUSR1, cs_usr1handler);
}
void cs_log(nick *np, char *event, ... ) {
chanservstdmessage(sender, QM_COMMANDLIST);
for (i=0;i<n;i++) {
+ char cmdbuf[50];
+
if (cargc>0 && !match2strings(cargv[0],cmdlist[i]->command->content))
continue;
summary=(cmdsummary *)cmdlist[i]->ext;
+ if (cmdlist[i]->level & QCMD_DEV) {
+ sprintf(cmdbuf,"%s (+d)",cmdlist[i]->command->content);
+ } else if(cmdlist[i]->level & QCMD_ADMIN) {
+ sprintf(cmdbuf,"%s (+a)",cmdlist[i]->command->content);
+ } else if(cmdlist[i]->level & QCMD_OPER) {
+ sprintf(cmdbuf,"%s (+o)",cmdlist[i]->command->content);
+ } else if(cmdlist[i]->level & QCMD_HELPER) {
+ sprintf(cmdbuf,"%s (+h)",cmdlist[i]->command->content);
+ } else {
+ strcpy(cmdbuf, cmdlist[i]->command->content);
+ }
+
if (summary->bylang[lang]) {
message=summary->bylang[lang]->content;
} else if (summary->bylang[0]) {
message=summary->def->content;
}
- chanservsendmessage(sender, "%-20s %s",cmdlist[i]->command->content, message);
+ chanservsendmessage(sender, "%-20s %s",cmdbuf, message);
}
chanservstdmessage(sender, QM_ENDOFLIST);
* up later. For modes we use the forced modes, plus the default channel
* modes (unless any of those are explicitly denied) */
- /* By default, we set the forcemodes and the default modes, but never denymodes */
- themodes = (CHANMODE_DEFAULT | rcp->forcemodes) & ~rcp->denymodes;
+ /* By default, we set the forcemodes and the default modes, but never denymodes..
+ * OK, actually we should only set the default modes if our timestamp is older.*/
+ if (cp->timestamp > rcp->ltimestamp)
+ themodes |= CHANMODE_DEFAULT;
+ else
+ themodes=0;
+
+ themodes = (themodes | rcp->forcemodes) & ~rcp->denymodes;
/* Now, if someone has just created a channel and we are going to set +i
* or +k on it, this will kick them off. This could be construed as a
else
flagmask=QUFLAG_INFO | QUFLAG_NOTICE | QUFLAG_OPER | QUFLAG_HELPER | QUFLAG_DEV | QUFLAG_ADMIN;
- chanservstdmessage(sender, QM_CURUSERFLAGS, target->username, printflags(target->flags & flagmask, ruflags));
+ chanservstdmessage(sender, QM_CURUSERFLAGS, target->username, printflagsornone(target->flags & flagmask, ruflags));
return CMD_OK;
}
QUFLAG_ADMIN | QUFLAG_INFO | QUFLAG_NOTICE);
if (flagmask & target->flags)
- chanservstdmessage(sender, QM_WHOIS_FLAGS, printflags(flagmask & target->flags, ruflags));
+ chanservstdmessage(sender, QM_WHOIS_FLAGS, printflagsornone(flagmask & target->flags, ruflags));
if (!(anp=findauthname(target->ID)) || !anp->nicks) {
chanservstdmessage(sender, QM_WHOIS_USERS, "(none)");