Initial revision
[citadel.git] / citadel / readlog.c
1 /* 
2  * readlog.c
3  * v1.4
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 last20(file,pos)
17 int file;
18 long pos;
19         {
20         int a,count;
21         long aa;
22         struct calllog calllog;
23         struct calllog listing[20];
24         struct tm *tm;
25         char *tstring;
26         
27         count=0;
28         for (a=0; a<20; ++a) {
29                 listing[a].CLfullname[0]=0;
30                 listing[a].CLtime=0L;
31                 listing[a].CLflags=0;
32                 }
33         aa=pos-1;
34         while(count<20) {
35                 if (aa<0L) aa=CALLLOG;
36                 lseek(file,(aa*sizeof(struct calllog)),0);
37                 a=read(file,(char *)&calllog,sizeof(struct calllog));
38                 if (calllog.CLflags==CL_LOGIN) {
39                         strcpy(listing[count].CLfullname,calllog.CLfullname);
40                         listing[count].CLtime=calllog.CLtime;
41                         listing[count].CLflags=calllog.CLflags;
42                         ++count;
43                         }
44                 if (aa==pos) break;
45                 aa=aa-1;
46                 }
47         for (a=19; a>=0; --a) {
48                 tm=(struct tm *)localtime(&listing[a].CLtime);
49                 tstring=(char *)asctime(tm);
50                 printf("%30s %s",listing[a].CLfullname,tstring);
51                 }
52         }
53
54 void main(argc,argv)
55 int argc;
56 char *argv[]; {
57         struct calllog calllog;
58         int file,pos,a,b;
59         char aaa[100];
60         struct tm *tm;
61         char *tstring;
62
63         get_config();
64         file=open("calllog.pos",O_RDONLY);
65         a=read(file,(char *)&pos,sizeof(int));
66         close(file);
67
68         file=open("calllog",O_RDONLY);
69         if (argc>=2) {
70                 if (!strcmp(argv[1],"-t")) last20(file,(long)pos);
71                 else fprintf(stderr,"%s: usage: %s [-t]\n",argv[0],argv[0]);
72                 close(file);
73                 exit(0);
74                 }
75 else {
76         lseek(file,(long)(pos*sizeof(struct calllog)),0);
77         for (a=0; a<CALLLOG; ++a) {
78                 if ((a+pos)==CALLLOG) lseek(file,0L,0);
79                 b=read(file,(char *)&calllog,sizeof(struct calllog));
80         if (calllog.CLflags!=0) {
81                 strcpy(aaa,"");
82                 if (calllog.CLflags&CL_CONNECT) strcpy(aaa,"Connect");
83                 if (calllog.CLflags&CL_LOGIN)   strcpy(aaa,"Login");
84                 if (calllog.CLflags&CL_NEWUSER) strcpy(aaa,"New User");
85                 if (calllog.CLflags&CL_BADPW)   strcpy(aaa,"Bad PW Attempt");
86                 if (calllog.CLflags&CL_TERMINATE) strcpy(aaa,"Terminate");
87                 if (calllog.CLflags&CL_DROPCARR) strcpy(aaa,"Dropped Carrier");
88                 if (calllog.CLflags&CL_SLEEPING) strcpy(aaa,"Sleeping");
89                 if (calllog.CLflags&CL_PWCHANGE) strcpy(aaa,"Changed Passwd");
90                 tm=(struct tm *)localtime(&calllog.CLtime);
91                 tstring=(char *)asctime(tm);
92                 printf("%30s %20s %s",calllog.CLfullname,aaa,tstring);
93                 }
94                 }
95         }
96         close(file);
97         exit(0);
98 }
99