* wildmat.c, braindamage.c: added
[citadel.git] / webcit / userlist.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <signal.h>
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <string.h>
8 #include <time.h>
9 #include "webcit.h"
10 #include "child.h"
11
12 struct namelist {
13         struct namelist *next;
14         char name[32];
15 };
16
17 /*
18  * display the userlist
19  */
20 void userlist(void)
21 {
22         char buf[256];
23         char fl[256];
24         struct tm *tmbuf;
25         long lc;
26         struct namelist *bio = NULL;
27         struct namelist *bptr;
28         int has_bio;
29
30         serv_puts("LBIO");
31         serv_gets(buf);
32         if (buf[0] == '1')
33                 while (serv_gets(buf), strcmp(buf, "000")) {
34                         bptr = (struct namelist *) malloc(sizeof(struct namelist));
35                         bptr->next = bio;
36                         strcpy(bptr->name, buf);
37                         bio = bptr;
38                 }
39         printf("HTTP/1.0 200 OK\n");
40         output_headers(1, "bottom");
41
42         serv_puts("LIST");
43         serv_gets(buf);
44         if (buf[0] != '1') {
45                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
46                 goto DONE;
47         }
48         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
49         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
50         wprintf("<B>User list for ");
51         escputs(serv_info.serv_humannode);
52         wprintf("</B></FONT></TD></TR></TABLE>\n");
53
54         wprintf("<CENTER><TABLE border>");
55         wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
56         wprintf("<TH>Last Call</TH><TH>Total Calls</TH><TH>Total Posts</TH></TR>\n");
57
58         while (serv_gets(buf), strcmp(buf, "000")) {
59                 extract(fl, buf, 0);
60                 has_bio = 0;
61                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
62                         if (!strcasecmp(fl, bptr->name))
63                                 has_bio = 1;
64                 }
65                 wprintf("<TR><TD>");
66                 if (has_bio) {
67                         wprintf("<A HREF=\"/showuser&who=");
68                         urlescputs(fl);
69                         wprintf("\">");
70                         escputs(fl);
71                         wprintf("</A>");
72                 } else {
73                         escputs(fl);
74                 }
75                 wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
76                         extract_long(buf, 2),
77                         extract_int(buf, 1));
78                 lc = extract_long(buf, 3);
79                 tmbuf = (struct tm *) localtime(&lc);
80                 wprintf("%02d/%02d/%04d ",
81                         (tmbuf->tm_mon + 1),
82                         tmbuf->tm_mday,
83                         (tmbuf->tm_year + 1900));
84
85
86                 wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
87                         extract_long(buf, 4), extract_long(buf, 5));
88
89         }
90         wprintf("</TABLE></CENTER>\n");
91       DONE:wDumpContent(1);
92 }
93
94
95 /*
96  * Display (non confidential) information about a particular user
97  */
98 void showuser(void)
99 {
100         char who[256];
101         char buf[256];
102         int have_pic;
103
104         printf("HTTP/1.0 200 OK\n");
105         output_headers(1, "bottom");
106
107
108         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
109         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>User profile");
110         wprintf("</B></FONT></TD></TR></TABLE>\n");
111
112         strcpy(who, bstr("who"));
113         serv_printf("OIMG _userpic_|%s", who);
114         serv_gets(buf);
115         if (buf[0] == '2') {
116                 have_pic = 1;
117                 serv_puts("CLOS");
118                 serv_gets(buf);
119         } else {
120                 have_pic = 0;
121         }
122
123         wprintf("<CENTER><TABLE><TR><TD>");
124         if (have_pic == 1) {
125                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
126                 urlescputs(who);
127                 wprintf("\">");
128         }
129         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
130         serv_printf("RBIO %s", who);
131         serv_gets(buf);
132         if (buf[0] == '1')
133                 fmout(NULL);
134         wDumpContent(1);
135 }