Tue Aug 18 00:42:33 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
[citadel.git] / citadel / readlog.c
1 /* 
2  * readlog.c  (a simple program to parse citadel.log)
3  */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <stdio.h>
9 #include <time.h>
10 #include <string.h>
11 #include <errno.h>
12 #include "citadel.h"
13
14 void get_config (void);
15 struct config config;
16
17 void 
18 main (int argc, char **argv)
19 {
20   time_t LogTime;
21   unsigned int LogType;
22   char LogName[256];
23
24   char buf[256];
25   char aaa[100];
26   struct tm *tm;
27   char *tstring;
28   FILE *logfp;
29
30   get_config ();
31
32   logfp = fopen ("citadel.log", "r");
33   if (logfp == NULL)
34     {
35       perror ("Could not open citadel.log");
36       exit (errno);
37     }
38   else
39     {
40       while (fgets (buf, 256, logfp) != NULL)
41         {
42           buf[strlen (buf) - 1] = 0;
43
44           LogTime = atol (strtok(buf, "|"));
45           LogType = atol (strtok(NULL, "|"));
46           strcpy(LogName, strtok(NULL, "|"));
47
48           if (LogType != 0)
49             {
50               strcpy (aaa, "");
51               if (LogType & CL_CONNECT)
52                 strcpy (aaa, "Connect");
53               if (LogType & CL_LOGIN)
54                 strcpy (aaa, "Login");
55               if (LogType & CL_NEWUSER)
56                 strcpy (aaa, "New User");
57               if (LogType & CL_BADPW)
58                 strcpy (aaa, "Bad PW Attempt");
59               if (LogType & CL_TERMINATE)
60                 strcpy (aaa, "Terminate");
61               if (LogType & CL_DROPCARR)
62                 strcpy (aaa, "Dropped Carrier");
63               if (LogType & CL_SLEEPING)
64                 strcpy (aaa, "Sleeping");
65               if (LogType & CL_PWCHANGE)
66                 strcpy (aaa, "Changed Passwd");
67               tm = (struct tm *) localtime (&LogTime);
68               tstring = (char *) asctime (tm);
69               printf ("%30s %20s %s", LogName, aaa, tstring);
70             }
71         }
72     }
73   fclose(logfp);
74   exit (0);
75 }