* added RCS Id keyword strings to sources
[citadel.git] / citadel / readlog.c
1 /* 
2  * readlog.c  (a simple program to parse citadel.log)
3  * $Id$
4  */
5
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <time.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "citadel.h"
14
15 void get_config (void);
16 struct config config;
17
18 int 
19 main (int argc, char **argv)
20 {
21   time_t LogTime;
22   unsigned int LogType;
23   char LogName[256];
24
25   char buf[256];
26   char aaa[100];
27   struct tm *tm;
28   char *tstring;
29   FILE *logfp;
30
31   get_config ();
32
33   logfp = fopen ("citadel.log", "r");
34   if (logfp == NULL)
35     {
36       perror ("Could not open citadel.log");
37       exit (errno);
38     }
39   else
40     {
41       while (fgets (buf, 256, logfp) != NULL)
42         {
43           buf[strlen (buf) - 1] = 0;
44           strcat(buf, " ");
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 }