+
+int parselog(char *LogLine, struct userNode *user, struct chanNode *cptr, char *chan, char *nuh, char *command, char *rest)
+{
+ struct svccmd *svccmd;
+ struct svccmd *cmd;
+ struct service *service;
+ const char *info;
+ char serv[NICKLEN+1];
+ char buf[MAXLEN];
+ char myservc[MAXLEN];
+ char* mychan;
+ char* mynuh;
+ char* mycommand;
+ char* myrest;
+ char* datestr;
+ char* mywho;
+ char *myserv;
+ char* myserva;
+ char* mychana;
+ unsigned int pos;
+ int p = 0;
+
+ datestr = (char *) mysep(&LogLine, "]");
+ mywho = (char *) mysep(&LogLine, " ");
+ mynuh = (char *) mysep(&LogLine, " ");
+ mycommand = (char *) mysep(&LogLine, " ");
+ myrest = (char *) mysep(&LogLine, "\0");
+ myserva = (char *) mysep(&mywho, ":");
+ mychana = (char *) mysep(&mywho, ":");
+ myserv = (char *) mysep(&myserva, "(");
+ mychan = (char *) mysep(&mychana, ")");
+
+ if(!mycommand)
+ return 0;
+
+ if(cptr)
+ chan = cptr->name;
+
+ if (!mychan)
+ mychan = "";
+
+ if(!chan)
+ chan = "";
+
+ if(!nuh)
+ nuh = "";
+ if(!command)
+ command = "";
+ if(!rest)
+ rest = "";
+ if(*chan && strcasecmp(mychan, chan))
+ return 0;
+ if(!myrest)
+ myrest = "";
+
+ info = conf_get_data("services/opserv/nick", RECDB_QSTRING);
+
+ if (!myserv)
+ myserv = "";
+ else
+ strcpy(myservc, myserv);
+
+
+ if (!strcmp(myserv, info)) {
+ if (!IsOper(user))
+ return 0;
+ else {
+ if ((service = service_find(myserv))) {
+ if (!(cmd = dict_find(service->commands, mycommand, NULL)))
+ return 0;
+
+ if (!(svccmd = svccmd_resolve_name(cmd, mycommand)))
+ return 0;
+
+ pos = snprintf(buf, sizeof(buf), "%s.%s", svccmd->command->parent->name, svccmd->command->name);
+
+ if (svccmd->alias.used) {
+ buf[pos++] = ' ';
+ unsplit_string((char**)svccmd->alias.list+1, svccmd->alias.used-1, buf+pos);
+ }
+ }
+ }
+
+ if (!(strcmp(buf+0, "OpServ.OP")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.DEOP")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.VOICE")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.DEVOICE")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.KICK")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.KICKBAN")))
+ p = 1;
+
+ if (!(strcmp(buf+0, "OpServ.OPALL")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.DEOPALL")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.VOICEALL")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.DEVOICEALL")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.KICKALL")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.KICKBANALL")))
+ p = 1;
+
+
+ if (!(strcmp(buf+0, "OpServ.INVITE")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.INVITEME")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.CLEARBANS")))
+ p = 1;
+ if (!(strcmp(buf+0, "OpServ.CLEARMODES")))
+ p = 1;
+
+ if (p == 1)
+ send_message(user, chanserv, "LAST_RESULTS", datestr, myserv, mynuh, mycommand, myrest);
+
+ p = 0;
+ } else {
+ sprintf(serv, "%s", "");
+ send_message(user, chanserv, "LAST_RESULTS", datestr, serv, mynuh, mycommand, myrest);
+ }
+
+ return 1;
+
+}
+
+int ShowLog(struct userNode *user, struct chanNode *cptr, char *chan, char *nuh, char *command, char *rest, int maxlines)
+{
+ FILE *TheFile;
+ int i, s, Last = 0, filelen, first;
+ int line = 0, searchline = 0;
+ int FilePosition;
+
+ char Buff[Block+1] = "", PrevBuff[Block+1] = "";
+ char LogLine[(Block+1)*2] = ""; /* To hold our exported results. */
+
+ if(!(TheFile = fopen(AccountingLog, "r")))
+ {
+ send_message(user, chanserv, "LAST_ERROR", AccountingLog, strerror(errno));
+ return 0;
+ }
+ s = fseek(TheFile, 0, SEEK_END); /* Start at the end. */
+ filelen = ftell(TheFile); /* Find out the length. */
+ FilePosition = 0; /* (from the bottom) */
+ send_message(user, chanserv, "LAST_COMMAND_LOG", cptr->name);
+ send_message(user, chanserv, "LAST_LINE");
+ while(Last == 0)
+ {
+ FilePosition += Block;
+ if(FilePosition > filelen)
+ {
+ FilePosition = filelen;
+ Last = 1;
+ }
+ if((s = fseek(TheFile, filelen-FilePosition, SEEK_SET)) < 0)
+ {
+ send_message(user, chanserv, "LAST_ERROR", AccountingLog, strerror(errno));
+ fclose(TheFile);
+ return 0;
+ }
+ s = fread(Buff, 1, Block, TheFile);
+ Buff[Block] = '\0';
+ if(ferror(TheFile))
+ {
+ send_message(user, chanserv, "LAST_ERROR", AccountingLog, strerror(errno));
+ fclose(TheFile);
+ return 0;
+ }
+ first = 1;
+ for(i = s-1; i >= 0; i--)
+ {
+ if(Buff[i] == '\n')
+ {
+ Buff[i] = '\0';
+ strcpy(LogLine, &Buff[i+1]);
+ if(first)
+ strcat(LogLine, PrevBuff);
+ first = 0;
+ searchline++;
+ if(parselog(LogLine, user, cptr, chan, nuh, command, rest))
+ line++;
+ if(line >= maxlines)
+ {
+ send_message(user, chanserv, "LAST_STOPPING_AT", maxlines);
+ return 1;
+ }
+ if( searchline >= MAXLOGSEARCHLENGTH )
+ {
+ send_message(user, chanserv, "LAST_MAX_AGE");
+ fclose(TheFile);
+ return 1;
+ }
+
+ }
+ }
+ strcpy(PrevBuff, Buff); /* Save the remaining bit. */
+ }
+ send_message(user, chanserv, "LAST_END_OF_LOG", line);
+ fclose(TheFile);
+ return 1;
+}