00001 /* Readlog.c */ 00002 /* Sample procedure for parsing the logs back in and sending them */ 00003 /* Out in a format that resembles (slightly) the old formatting */ 00004 00005 /* 00006 * Copyright (c) 2001 James Hess 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the distribution. 00017 * 3. Neither the name of the authors nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 */ 00033 00034 #include <stdio.h> 00035 #include <stdlib.h> 00036 #include <time.h> 00037 00038 #define LOGF_NORMAL 0x0 00039 #define LOGF_BADPW 0x1 00040 #define LOGF_FAIL 0x2 00041 #define LOGF_OFF 0x4 00042 #define LOGF_ON 0x8 00043 #define LOGF_OPER 0x10 00044 #define LOGF_PATTERN 0x20 00045 #define LOGF_SCAN 0x40 00046 #define LOGF_OK 0x80 00047 00048 char *log_interpret(char *inbuf) 00049 { 00050 static char res[8192]; 00051 char cmd[255], sender[255], target[255], tb[255], flbuf[255] = ""; 00052 time_t ts; 00053 int fl, i, x; 00054 00055 *target = '\0'; 00056 if ( sscanf(inbuf, "%s %ld %s %d %s", cmd, &ts, sender, &fl, target) < 4 ) { 00057 printf("ERROR: INVALID LOG FORMAT\n"); 00058 return ""; 00059 } 00060 for(i = 0, x = 0; inbuf[i]; i++) 00061 if (inbuf[i] == ' ' && (++x > 4)) 00062 break; 00063 sprintf(flbuf, "%s%s%s%s%s%s", 00064 fl & LOGF_BADPW ? " (Bad PW)" : "", 00065 fl & LOGF_FAIL ? " (Failed)" : "", 00066 fl & LOGF_ON ? " (Applied)" : "", 00067 fl & LOGF_OFF ? " (Removed)" : "", 00068 fl & LOGF_OPER ? " (Oper Cmd)" : "", 00069 fl & LOGF_SCAN ? " (Listing)" : "" ); 00070 00071 strftime(tb, 254, "%d-%b-%y %H:%M", gmtime(&ts)); 00072 sprintf(res, "(%s) (%s) %s %s%s %s", tb, sender, cmd, target, flbuf, inbuf + i + 1); 00073 return res; 00074 00075 //NS_SETOP 982397116 Mysidia!root@albert2.i-55.com 0 n +! (+OokKpsSNCIGrjL!ca) 00076 } 00077 00078 void main() 00079 { 00080 FILE *fp; 00081 char buf[2048]; 00082 int i = 0; 00083 /* const char *whatlog[] = { 00084 "operserv/operserv.log", 00085 "chanserv/chanserv.log", 00086 "nickserv/nickserv.log", 00087 NULL 00088 };*/ 00089 00090 /* for(i = 0; whatlog[i]; i++)*/ 00091 { 00092 /* fp = fopen(whatlog[i], "r");*/ 00093 fp = stdin; 00094 /* if (!fp) continue;*/ 00095 00096 while(fgets(buf, 1024, fp)) { 00097 if (!isalpha(buf[0])) 00098 continue; 00099 buf[strlen(buf) - 1] = '\0'; 00100 printf("%s\n", log_interpret(buf)); 00101 } 00102 fclose(fp); 00103 } 00104 }