]> code.citadel.org Git - citadel.git/blob - citadel/readlog.c
Changed logging mechanism from a circular binary file to a text file. The
[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 "citadel.h"
12
13 void get_config ();
14 struct config config;
15
16 void 
17 main (argc, argv)
18      int argc;
19      char *argv[];
20 {
21   time_t LogTime;
22   unsigned int LogType;
23   char LogName[256];
24
25   char buf[256];
26   int a, b;
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   if (argc >= 2)
41     {
42       if (!strcmp (argv[1], "-t"))
43         last20 (file, (long) pos);
44       else
45         fprintf (stderr, "%s: usage: %s [-t]\n", argv[0], argv[0]);
46       close (file);
47       exit (0);
48     }
49   else
50     {
51       while (fgets (buf, 256, logfp) != NULL)
52         {
53           buf[strlen (buf) - 1] = 0;
54
55           LogTime = atol (buf);
56           strcpy (buf, index (buf, '|'));
57           LogType = atoi (buf);
58           strcpy (buf, index (buf, '|'));
59           strcpy (LogName, buf);
60
61
62           if (LogType != 0)
63             {
64               strcpy (aaa, "");
65               if (LogType & CL_CONNECT)
66                 strcpy (aaa, "Connect");
67               if (LogType & CL_LOGIN)
68                 strcpy (aaa, "Login");
69               if (LogType & CL_NEWUSER)
70                 strcpy (aaa, "New User");
71               if (LogType & CL_BADPW)
72                 strcpy (aaa, "Bad PW Attempt");
73               if (LogType & CL_TERMINATE)
74                 strcpy (aaa, "Terminate");
75               if (LogType & CL_DROPCARR)
76                 strcpy (aaa, "Dropped Carrier");
77               if (LogType & CL_SLEEPING)
78                 strcpy (aaa, "Sleeping");
79               if (LogType & CL_PWCHANGE)
80                 strcpy (aaa, "Changed Passwd");
81               tm = (struct tm *) localtime (&LogTime);
82               tstring = (char *) asctime (tm);
83               printf ("%30s %20s %s", LogName, aaa, tstring);
84             }
85         }
86     }
87   fclose(logfp);
88   exit (0);
89 }