]> code.citadel.org Git - citadel.git/blob - citadel/readlog.c
Fixed a bug
[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 (buf);
48           strcpy (buf, index (buf, '|'));
49           LogType = atoi (buf);
50           strcpy (buf, index (buf, '|'));
51           strcpy (LogName, buf);
52
53
54           if (LogType != 0)
55             {
56               strcpy (aaa, "");
57               if (LogType & CL_CONNECT)
58                 strcpy (aaa, "Connect");
59               if (LogType & CL_LOGIN)
60                 strcpy (aaa, "Login");
61               if (LogType & CL_NEWUSER)
62                 strcpy (aaa, "New User");
63               if (LogType & CL_BADPW)
64                 strcpy (aaa, "Bad PW Attempt");
65               if (LogType & CL_TERMINATE)
66                 strcpy (aaa, "Terminate");
67               if (LogType & CL_DROPCARR)
68                 strcpy (aaa, "Dropped Carrier");
69               if (LogType & CL_SLEEPING)
70                 strcpy (aaa, "Sleeping");
71               if (LogType & CL_PWCHANGE)
72                 strcpy (aaa, "Changed Passwd");
73               tm = (struct tm *) localtime (&LogTime);
74               tstring = (char *) asctime (tm);
75               printf ("%30s %20s %s", LogName, aaa, tstring);
76             }
77         }
78     }
79   fclose(logfp);
80   exit (0);
81 }