ad828db6de242f8ad5e15a7a3a5c1ad8245cde1b
[citadel.git] / webcit / userlist.c
1 /*
2  * $Id$
3  *
4  * Display a list of all accounts on a Citadel system.
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <sys/time.h>
18 #include <limits.h>
19 #include <netinet/in.h>
20 #include <netdb.h>
21 #include <string.h>
22 #include <pwd.h>
23 #include <errno.h>
24 #include <stdarg.h>
25 #include <pthread.h>
26 #include <signal.h>
27 #include "webcit.h"
28
29 struct namelist {
30         struct namelist *next;
31         char name[32];
32 };
33
34 /*
35  * display the userlist
36  */
37 void userlist(void)
38 {
39         char buf[SIZ];
40         char fl[SIZ];
41         struct tm *tmbuf;
42         long lc;
43         struct namelist *bio = NULL;
44         struct namelist *bptr;
45         int has_bio;
46         int bg = 0;
47
48         serv_puts("LBIO");
49         serv_gets(buf);
50         if (buf[0] == '1')
51                 while (serv_gets(buf), strcmp(buf, "000")) {
52                         bptr = (struct namelist *) malloc(sizeof(struct namelist));
53                         bptr->next = bio;
54                         strcpy(bptr->name, buf);
55                         bio = bptr;
56                 }
57         output_headers(1, 1, 2, 0, 0, 0, 0);
58         wprintf("<div id=\"banner\">\n"
59                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
60                 "<SPAN CLASS=\"titlebar\">User list for ");
61         escputs(serv_info.serv_humannode);
62         wprintf("</SPAN>"
63                 "</TD></TR></TABLE>\n"
64                 "</div>\n<div id=\"content\">\n"
65         );
66
67         serv_puts("LIST");
68         serv_gets(buf);
69         if (buf[0] != '1') {
70                 wprintf("<EM>%s</EM><br />\n", &buf[4]);
71                 goto DONE;
72         }
73
74         wprintf("<div id=\"fix_scrollbar_bug\">"
75                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
76         wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
77         wprintf("<TH>Last Login</TH><TH>Total Logins</TH><TH>Total Posts</TH></TR>\n");
78
79         while (serv_gets(buf), strcmp(buf, "000")) {
80                 extract(fl, buf, 0);
81                 has_bio = 0;
82                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
83                         if (!strcasecmp(fl, bptr->name))
84                                 has_bio = 1;
85                 }
86                 bg = 1 - bg;
87                 wprintf("<TR BGCOLOR=\"#%s\"><TD>",
88                         (bg ? "DDDDDD" : "FFFFFF")
89                 );
90                 if (has_bio) {
91                         wprintf("<A HREF=\"/showuser&who=");
92                         urlescputs(fl);
93                         wprintf("\">");
94                         escputs(fl);
95                         wprintf("</A>");
96                 } else {
97                         escputs(fl);
98                 }
99                 wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
100                         extract_long(buf, 2),
101                         extract_int(buf, 1));
102                 lc = extract_long(buf, 3);
103                 tmbuf = (struct tm *) localtime(&lc);
104                 wprintf("%02d/%02d/%04d ",
105                         (tmbuf->tm_mon + 1),
106                         tmbuf->tm_mday,
107                         (tmbuf->tm_year + 1900));
108
109
110                 wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
111                         extract_long(buf, 4), extract_long(buf, 5));
112
113         }
114         wprintf("</table></div>\n");
115 DONE:   wDumpContent(1);
116 }
117
118
119 /*
120  * Display (non confidential) information about a particular user
121  */
122 void showuser(void)
123 {
124         char who[SIZ];
125         char buf[SIZ];
126         int have_pic;
127
128         strcpy(who, bstr("who"));
129
130         output_headers(1, 1, 2, 0, 0, 0, 0);
131         wprintf("<div id=\"banner\">\n"
132                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
133                 "<SPAN CLASS=\"titlebar\">User profile</SPAN>"
134                 "</TD></TR></TABLE>\n"
135                 "</div>\n<div id=\"content\">\n"
136         );
137
138         wprintf("<div id=\"fix_scrollbar_bug\">"
139                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
140
141         serv_printf("OIMG _userpic_|%s", who);
142         serv_gets(buf);
143         if (buf[0] == '2') {
144                 have_pic = 1;
145                 serv_puts("CLOS");
146                 serv_gets(buf);
147         } else {
148                 have_pic = 0;
149         }
150
151         wprintf("<CENTER><TABLE><TR><TD>");
152         if (have_pic == 1) {
153                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
154                 urlescputs(who);
155                 wprintf("\">");
156         }
157         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
158         serv_printf("RBIO %s", who);
159         serv_gets(buf);
160         if (buf[0] == '1') {
161                 fmout(NULL, "JUSTIFY");
162         }
163         wprintf("<br /><A HREF=\"/display_page&recp=");
164         urlescputs(who);
165         wprintf("\">"
166                 "<IMG SRC=\"/static/page.gif\" ALIGN=MIDDLE BORDER=0>"
167                 "&nbsp;&nbsp;"
168                 "Click here to send an instant message to ");
169         escputs(who);
170         wprintf("</A>\n");
171
172         wprintf("</td></tr></table></div>\n");
173         wDumpContent(1);
174 }