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