4a221b4d8649d02314ae2faa8fe29a017d9c7fe4
[citadel.git] / citadel / readlog.c
1 /* 
2  * $Id$
3  *
4  * A simple program to parse citadel.log
5  */
6
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10 #include <stdio.h>
11 #include <time.h>
12 #include <string.h>
13 #include <errno.h>
14 #include "citadel.h"
15
16 void get_config (void);
17 struct config config;
18
19 int 
20 main (int argc, char **argv)
21 {
22   time_t LogTime;
23   unsigned int LogType;
24   char LogName[SIZ];
25
26   char buf[SIZ];
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, sizeof buf, logfp) != NULL)
43         {
44           buf[strlen (buf) - 1] = 0;
45           strcat(buf, " ");
46
47           LogTime = atol (strtok(buf, "|"));
48           LogType = atol (strtok(NULL, "|"));
49           strcpy(LogName, strtok(NULL, "|"));
50
51           if (LogType != 0)
52             {
53               strcpy (aaa, "");
54               if (LogType & CL_CONNECT)
55                 strcpy (aaa, "Connect");
56               if (LogType & CL_LOGIN)
57                 strcpy (aaa, "Login");
58               if (LogType & CL_NEWUSER)
59                 strcpy (aaa, "New User");
60               if (LogType & CL_BADPW)
61                 strcpy (aaa, "Bad PW Attempt");
62               if (LogType & CL_TERMINATE)
63                 strcpy (aaa, "Terminate");
64               if (LogType & CL_DROPCARR)
65                 strcpy (aaa, "Dropped Carrier");
66               if (LogType & CL_SLEEPING)
67                 strcpy (aaa, "Sleeping");
68               if (LogType & CL_PWCHANGE)
69                 strcpy (aaa, "Changed Passwd");
70               tm = (struct tm *) localtime (&LogTime);
71               tstring = (char *) asctime (tm);
72               printf ("%30s %20s %s", LogName, aaa, tstring);
73             }
74         }
75     }
76   fclose(logfp);
77   exit (0);
78 }