e8876e2b396100e4d46bba3a7de9bacdf69ec9a2
[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         time_t 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_getln(buf, sizeof buf);
50         if (buf[0] == '1')
51                 while (serv_getln(buf, sizeof 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_getln(buf, sizeof 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_getln(buf, sizeof buf), strcmp(buf, "000")) {
80                 extract_token(fl, buf, 0, '|', sizeof fl);
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                 localtime_r(&lc, &tmbuf);
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>"
133                 "<TD><IMG SRC=\"/static/usermanag_48x.gif\"></TD>"
134                 "<td align=left><SPAN CLASS=\"titlebar\">User profile</SPAN>"
135                 "</TD></TR></TABLE>\n"
136                 "</div>\n<div id=\"content\">\n"
137         );
138
139         wprintf("<div id=\"fix_scrollbar_bug\">"
140                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
141
142         serv_printf("OIMG _userpic_|%s", who);
143         serv_getln(buf, sizeof buf);
144         if (buf[0] == '2') {
145                 have_pic = 1;
146                 serv_puts("CLOS");
147                 serv_getln(buf, sizeof buf);
148         } else {
149                 have_pic = 0;
150         }
151
152         wprintf("<CENTER><TABLE><TR><TD>");
153         if (have_pic == 1) {
154                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
155                 urlescputs(who);
156                 wprintf("\">");
157         }
158         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
159         serv_printf("RBIO %s", who);
160         serv_getln(buf, sizeof buf);
161         if (buf[0] == '1') {
162                 fmout(NULL, "JUSTIFY");
163         }
164         wprintf("<br /><A HREF=\"/display_page?recp=");
165         urlescputs(who);
166         wprintf("\">"
167                 "<IMG SRC=\"/static/citadelchat_24x.gif\" "
168                 "ALIGN=MIDDLE BORDER=0>&nbsp;&nbsp;"
169                 "Click here to send an instant message to ");
170         escputs(who);
171         wprintf("</A>\n");
172
173         wprintf("</td></tr></table></div>\n");
174         wDumpContent(1);
175 }