a54a24d7150043923d3847dec30181e455959e61
[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 ();
15 struct config config;
16
17 void 
18 main (argc, argv)
19      int argc;
20      char *argv[];
21 {
22   time_t LogTime;
23   unsigned int LogType;
24   char LogName[256];
25
26   char buf[256];
27   char aaa[100];
28   struct tm *tm;
29   char *tstring;
30   FILE *logfp;
31
32   get_config ();
33
34   logfp = fopen ("citadel.log", "r");
35   if (logfp == NULL)
36     {
37       perror ("Could not open citadel.log");
38       exit (errno);
39     }
40   else
41     {
42       while (fgets (buf, 256, logfp) != NULL)
43         {
44           buf[strlen (buf) - 1] = 0;
45
46           LogTime = atol (strtok(buf, "|"));
47           LogType = atol (strtok(NULL, "|"));
48           strcpy(LogName, strtok(NULL, "|"));
49
50           if (LogType != 0)
51             {
52               strcpy (aaa, "");
53               if (LogType & CL_CONNECT)
54                 strcpy (aaa, "Connect");
55               if (LogType & CL_LOGIN)
56                 strcpy (aaa, "Login");
57               if (LogType & CL_NEWUSER)
58                 strcpy (aaa, "New User");
59               if (LogType & CL_BADPW)
60                 strcpy (aaa, "Bad PW Attempt");
61               if (LogType & CL_TERMINATE)
62                 strcpy (aaa, "Terminate");
63               if (LogType & CL_DROPCARR)
64                 strcpy (aaa, "Dropped Carrier");
65               if (LogType & CL_SLEEPING)
66                 strcpy (aaa, "Sleeping");
67               if (LogType & CL_PWCHANGE)
68                 strcpy (aaa, "Changed Passwd");
69               tm = (struct tm *) localtime (&LogTime);
70               tstring = (char *) asctime (tm);
71               printf ("%30s %20s %s", LogName, aaa, tstring);
72             }
73         }
74     }
75   fclose(logfp);
76   exit (0);
77 }