4578f048190d0e9ee12d47b9544f62ead420c2c6
[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("<center><table border=0 width=99%% bgcolor=\"#ffffff\"><tr><td>\n");
75         wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
76         wprintf("<TH>Last Login</TH><TH>Total Logins</TH><TH>Total Posts</TH></TR>\n");
77
78         while (serv_gets(buf), strcmp(buf, "000")) {
79                 extract(fl, buf, 0);
80                 has_bio = 0;
81                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
82                         if (!strcasecmp(fl, bptr->name))
83                                 has_bio = 1;
84                 }
85                 bg = 1 - bg;
86                 wprintf("<TR BGCOLOR=\"#%s\"><TD>",
87                         (bg ? "DDDDDD" : "FFFFFF")
88                 );
89                 if (has_bio) {
90                         wprintf("<A HREF=\"/showuser&who=");
91                         urlescputs(fl);
92                         wprintf("\">");
93                         escputs(fl);
94                         wprintf("</A>");
95                 } else {
96                         escputs(fl);
97                 }
98                 wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
99                         extract_long(buf, 2),
100                         extract_int(buf, 1));
101                 lc = extract_long(buf, 3);
102                 tmbuf = (struct tm *) localtime(&lc);
103                 wprintf("%02d/%02d/%04d ",
104                         (tmbuf->tm_mon + 1),
105                         tmbuf->tm_mday,
106                         (tmbuf->tm_year + 1900));
107
108
109                 wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
110                         extract_long(buf, 4), extract_long(buf, 5));
111
112         }
113         wprintf("</table></center>\n");
114 DONE:   wDumpContent(1);
115 }
116
117
118 /*
119  * Display (non confidential) information about a particular user
120  */
121 void showuser(void)
122 {
123         char who[SIZ];
124         char buf[SIZ];
125         int have_pic;
126
127         strcpy(who, bstr("who"));
128
129         output_headers(1, 1, 2, 0, 0, 0, 0);
130         wprintf("<div id=\"banner\">\n"
131                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
132                 "<SPAN CLASS=\"titlebar\">User profile</SPAN>"
133                 "</TD></TR></TABLE>\n"
134                 "</div>\n<div id=\"content\">\n"
135         );
136
137         wprintf("<center><table border=0 width=99%% bgcolor=\"#ffffff\"><tr><td>\n");
138
139         serv_printf("OIMG _userpic_|%s", who);
140         serv_gets(buf);
141         if (buf[0] == '2') {
142                 have_pic = 1;
143                 serv_puts("CLOS");
144                 serv_gets(buf);
145         } else {
146                 have_pic = 0;
147         }
148
149         wprintf("<CENTER><TABLE><TR><TD>");
150         if (have_pic == 1) {
151                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
152                 urlescputs(who);
153                 wprintf("\">");
154         }
155         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
156         serv_printf("RBIO %s", who);
157         serv_gets(buf);
158         if (buf[0] == '1') {
159                 fmout(NULL, "JUSTIFY");
160         }
161         wprintf("<br /><A HREF=\"/display_page&recp=");
162         urlescputs(who);
163         wprintf("\">"
164                 "<IMG SRC=\"/static/page.gif\" ALIGN=MIDDLE BORDER=0>"
165                 "&nbsp;&nbsp;"
166                 "Click here to send an instant message to ");
167         escputs(who);
168         wprintf("</A>\n");
169
170         wprintf("</td></tr></table></center>\n");
171         wDumpContent(1);
172 }