e7b286ed6016be8baddf51f660b757e2f0773cb5
[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 int 
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           strcat(buf, " ");
44
45           LogTime = atol (strtok(buf, "|"));
46           LogType = atol (strtok(NULL, "|"));
47           strcpy(LogName, strtok(NULL, "|"));
48
49           if (LogType != 0)
50             {
51               strcpy (aaa, "");
52               if (LogType & CL_CONNECT)
53                 strcpy (aaa, "Connect");
54               if (LogType & CL_LOGIN)
55                 strcpy (aaa, "Login");
56               if (LogType & CL_NEWUSER)
57                 strcpy (aaa, "New User");
58               if (LogType & CL_BADPW)
59                 strcpy (aaa, "Bad PW Attempt");
60               if (LogType & CL_TERMINATE)
61                 strcpy (aaa, "Terminate");
62               if (LogType & CL_DROPCARR)
63                 strcpy (aaa, "Dropped Carrier");
64               if (LogType & CL_SLEEPING)
65                 strcpy (aaa, "Sleeping");
66               if (LogType & CL_PWCHANGE)
67                 strcpy (aaa, "Changed Passwd");
68               tm = (struct tm *) localtime (&LogTime);
69               tstring = (char *) asctime (tm);
70               printf ("%30s %20s %s", LogName, aaa, tstring);
71             }
72         }
73     }
74   fclose(logfp);
75   exit (0);
76 }