]> code.citadel.org Git - citadel.git/blob - citadel/readlog.c
2bd217e4a152c910808690c4bf31aca45db58afa
[citadel.git] / citadel / readlog.c
1 /* 
2  * readlog.c
3  * v1.5
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 ();
16 struct config config;
17
18 void 
19 main (argc, argv)
20      int argc;
21      char *argv[];
22 {
23   time_t LogTime;
24   unsigned int LogType;
25   char LogName[256];
26
27   char buf[256];
28   char aaa[100];
29   struct tm *tm;
30   char *tstring;
31   FILE *logfp;
32
33   get_config ();
34
35   logfp = fopen ("citadel.log", "r");
36   if (logfp == NULL)
37     {
38       perror ("Could not open citadel.log");
39       exit (errno);
40     }
41   else
42     {
43       while (fgets (buf, 256, logfp) != NULL)
44         {
45           buf[strlen (buf) - 1] = 0;
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 }