* Cleaned up the rcs/cvs Id tags and leading comments at the top of some files
[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, 0, 0, 0, 0, 0);
58
59         serv_puts("LIST");
60         serv_gets(buf);
61         if (buf[0] != '1') {
62                 wprintf("<EM>%s</EM><br />\n", &buf[4]);
63                 goto DONE;
64         }
65
66         svprintf("BOXTITLE", WCS_STRING, "User list for %s",
67                         serv_info.serv_humannode);
68
69         do_template("beginbox");
70         wprintf("<CENTER>");
71         wprintf("<TABLE border=0 width=100%%>");
72         wprintf("<TR><TH>User Name</TH><TH>Number</TH><TH>Access Level</TH>");
73         wprintf("<TH>Last Login</TH><TH>Total Logins</TH><TH>Total Posts</TH></TR>\n");
74
75         while (serv_gets(buf), strcmp(buf, "000")) {
76                 extract(fl, buf, 0);
77                 has_bio = 0;
78                 for (bptr = bio; bptr != NULL; bptr = bptr->next) {
79                         if (!strcasecmp(fl, bptr->name))
80                                 has_bio = 1;
81                 }
82                 bg = 1 - bg;
83                 wprintf("<TR BGCOLOR=\"#%s\"><TD>",
84                         (bg ? "DDDDDD" : "FFFFFF")
85                 );
86                 if (has_bio) {
87                         wprintf("<A HREF=\"/showuser&who=");
88                         urlescputs(fl);
89                         wprintf("\">");
90                         escputs(fl);
91                         wprintf("</A>");
92                 } else {
93                         escputs(fl);
94                 }
95                 wprintf("</TD><TD>%ld</TD><TD>%d</TD><TD>",
96                         extract_long(buf, 2),
97                         extract_int(buf, 1));
98                 lc = extract_long(buf, 3);
99                 tmbuf = (struct tm *) localtime(&lc);
100                 wprintf("%02d/%02d/%04d ",
101                         (tmbuf->tm_mon + 1),
102                         tmbuf->tm_mday,
103                         (tmbuf->tm_year + 1900));
104
105
106                 wprintf("</TD><TD>%ld</TD><TD>%5ld</TD></TR>\n",
107                         extract_long(buf, 4), extract_long(buf, 5));
108
109         }
110         wprintf("</TABLE>");
111         wprintf("</CENTER>\n");
112         do_template("endbox");
113 DONE:   wDumpContent(1);
114 }
115
116
117 /*
118  * Display (non confidential) information about a particular user
119  */
120 void showuser(void)
121 {
122         char who[SIZ];
123         char buf[SIZ];
124         int have_pic;
125
126         output_headers(1, 1, 0, 0, 0, 0, 0);
127
128         svprintf("BOXTITLE", WCS_STRING, "User profile");
129         do_template("beginbox");
130
131         strcpy(who, bstr("who"));
132         serv_printf("OIMG _userpic_|%s", who);
133         serv_gets(buf);
134         if (buf[0] == '2') {
135                 have_pic = 1;
136                 serv_puts("CLOS");
137                 serv_gets(buf);
138         } else {
139                 have_pic = 0;
140         }
141
142         wprintf("<CENTER><TABLE><TR><TD>");
143         if (have_pic == 1) {
144                 wprintf("<IMG SRC=\"/image&name=_userpic_&parm=");
145                 urlescputs(who);
146                 wprintf("\">");
147         }
148         wprintf("</TD><TD><H1>%s</H1></TD></TR></TABLE></CENTER>\n", who);
149         serv_printf("RBIO %s", who);
150         serv_gets(buf);
151         if (buf[0] == '1') {
152                 fmout(NULL, "JUSTIFY");
153         }
154         wprintf("<br /><A HREF=\"/display_page&recp=");
155         urlescputs(who);
156         wprintf("\">"
157                 "<IMG SRC=\"/static/page.gif\" ALIGN=MIDDLE BORDER=0>"
158                 "&nbsp;&nbsp;"
159                 "Click here to page this user (send an instant message)"
160                 "</A>\n");
161
162         do_template("endbox");
163         wDumpContent(1);
164 }