* Started changing some of the top-level tables from 100% width to 99%
[citadel.git] / webcit / who.c
1 /*
2  * $Id$
3  *
4  * Display a list of all users currently logged on to the Citadel server.
5  */
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15 #include <sys/socket.h>
16 #include <sys/time.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27
28
29
30
31
32
33 /*
34  * who is on?
35  */
36 void whobbs(void)
37 {
38         char buf[SIZ], sess, user[SIZ], room[SIZ], host[SIZ],
39                 realroom[SIZ], realhost[SIZ];
40         time_t last_activity;
41         time_t now;
42         int bg = 0;
43
44         output_headers(1, 1, 2, 0, 1, 0, 0);
45
46         wprintf("<script type=\"text/javascript\">\n"
47                 "function ConfirmKill() { \n"
48                 "return confirm('Do you really want to kill this session?');\n"
49                 "}\n"
50                 "</script>\n"
51         );
52
53         wprintf("<div id=\"banner\">\n");
54         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
55         wprintf("<IMG SRC=\"/static/users-icon.gif\" ALT=\" \" ALIGN=MIDDLE>");
56         wprintf("<SPAN CLASS=\"titlebar\">&nbsp;Users currently on ");
57         escputs(serv_info.serv_humannode);
58         wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
59         offer_start_page();
60         wprintf("</TD></TR></TABLE>\n");
61         wprintf("</div>\n"
62                 "<div id=\"content\">\n");
63
64         wprintf("<center>"
65                 "<table border=0 cellspacing=0 width=99%% bgcolor=\"#FFFFFF\">"
66                 "<tr>\n");
67         wprintf("<TH COLSPAN=4>Session ID</TH>\n");
68         wprintf("<TH>User Name</TH>\n");
69         wprintf("<TH>Room</TH>");
70         wprintf("<TH>From host</TH>\n</TR>\n");
71
72         serv_puts("TIME");
73         serv_gets(buf);
74         if (buf[0] == '2') {
75                 now = extract_long(&buf[4], 0);
76         }
77         else {
78                 now = time(NULL);
79         }
80
81         serv_puts("RWHO");
82         serv_gets(buf);
83         if (buf[0] == '1') {
84                 while (serv_gets(buf), strcmp(buf, "000")) {
85                         sess = extract_int(buf, 0);
86                         extract(user, buf, 1);
87                         extract(room, buf, 2);
88                         extract(host, buf, 3);
89                         extract(realroom, buf, 9);
90                         extract(realhost, buf, 10);
91                         last_activity = extract_long(buf, 5);
92
93                         bg = 1 - bg;
94                         wprintf("<TR BGCOLOR=\"#%s\">",
95                                 (bg ? "DDDDDD" : "FFFFFF")
96                         );
97
98
99                         wprintf("<TD>%d</TD><TD>", sess);
100                         if ((WC->is_aide) &&
101                             (sess != WC->ctdl_pid)) {
102                                 wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", sess);
103                                 urlescputs(user);
104                                 wprintf("\" onClick=\"return ConfirmKill();\" "
105                                 ">(kill)</A>");
106                         }
107                         if (sess == WC->ctdl_pid) {
108                                 wprintf(" <A HREF=\"/edit_me\" "
109                                         ">(edit)</A>");
110                         }
111                         wprintf("</TD>");
112
113                         /* (link to page this user) */
114                         wprintf("<TD><A HREF=\"/display_page&recp=");
115                         urlescputs(user);
116                         wprintf("\">"
117                                 "<IMG ALIGN=MIDDLE WIDTH=20 HEIGHT=15 "
118                                 "SRC=\"/static/page.gif\" "
119                                 "ALT=\"(p)\""
120                                 " BORDER=0></A>&nbsp;");
121                         wprintf("</TD>");
122
123                         /* (idle flag) */
124                         wprintf("<TD>");
125                         if ((now - last_activity) > 900L) {
126                                 wprintf("&nbsp;"
127                                         "<IMG ALIGN=MIDDLE "
128                                         "SRC=\"/static/idle.gif\" "
129                                         "ALT=\"[idle]\" BORDER=0>");
130                         }
131                         wprintf("</TD>\n\t<TD>");
132
133
134
135                         /* username (link to user bio/photo page) */
136                         wprintf("<A HREF=\"/showuser&who=");
137                         urlescputs(user);
138                         wprintf("\">");
139                         escputs(user);
140                         wprintf("</A>");
141
142                         /* room */
143                         wprintf("</TD>\n\t<TD>");
144                         escputs(room);
145                         if (strlen(realroom) > 0) {
146                                 wprintf("<br /><I>");
147                                 escputs(realroom);
148                                 wprintf("</I>");
149                         }
150                         wprintf("</TD>\n\t<TD>");
151
152                         /* hostname */
153                         escputs(host);
154                         if (strlen(realhost) > 0) {
155                                 wprintf("<br /><I>");
156                                 escputs(realhost);
157                                 wprintf("</I>");
158                         }
159                         wprintf("</TD>\n</TR>");
160                 }
161         }
162         wprintf("</TABLE>\n"
163                 "Click on a name to read user info.  Click on "
164                 "<IMG ALIGN=MIDDLE SRC=\"/static/page.gif\" ALT=\"(p)\" "
165                 "BORDER=0> to send "
166                 "a page (instant message) to that user.<br /></CENTER>\n");
167         wDumpContent(1);
168 }
169
170
171 void terminate_session(void)
172 {
173         char buf[SIZ];
174
175         serv_printf("TERM %s", bstr("which_session"));
176         serv_gets(buf);
177         whobbs();
178 }
179
180
181 /*
182  * Change your session info (fake roomname and hostname)
183  */
184 void edit_me(void)
185 {
186         char buf[SIZ];
187
188         if (!strcasecmp(bstr("sc"), "Change room name")) {
189                 serv_printf("RCHG %s", bstr("fake_roomname"));
190                 serv_gets(buf);
191                 http_redirect("/whobbs");
192         } else if (!strcasecmp(bstr("sc"), "Change host name")) {
193                 serv_printf("HCHG %s", bstr("fake_hostname"));
194                 serv_gets(buf);
195                 http_redirect("/whobbs");
196         } else if (!strcasecmp(bstr("sc"), "Change user name")) {
197                 serv_printf("UCHG %s", bstr("fake_username"));
198                 serv_gets(buf);
199                 http_redirect("/whobbs");
200         } else if (!strcasecmp(bstr("sc"), "Cancel")) {
201                 http_redirect("/whobbs");
202         } else {
203
204                 output_headers(1, 1, 0, 0, 0, 0, 0);
205
206                 wprintf("<div id=\"banner\">\n");
207                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
208                 wprintf("<SPAN CLASS=\"titlebar\">");
209                 wprintf("Edit your session display");
210                 wprintf("</SPAN></TD></TR></TABLE>\n");
211                 wprintf("</div>\n<div id=\"content\">\n");
212
213                 wprintf("This screen allows you to change the way your\n");
214                 wprintf("session appears in the 'Who is online' listing.\n");
215                 wprintf("To turn off any 'fake' name you've previously\n");
216                 wprintf("set, simply click the appropriate 'change' button\n");
217                 wprintf("without typing anything in the corresponding box.\n");
218                 wprintf("<br />\n");
219
220                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
221
222                 wprintf("<TABLE border=0 width=100%%>\n");
223
224                 wprintf("<TR><TD><B>Room name:</B></TD>\n<TD>");
225                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
226                 wprintf("</TD>\n<TD ALIGN=center>");
227                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
228                 wprintf("</TD>\n</TR>\n");
229
230                 wprintf("<TR><TD><B>Host name:</B></TD><TD>");
231                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
232                 wprintf("</TD>\n<TD ALIGN=center>");
233                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
234                 wprintf("</TD>\n</TR>\n");
235
236                 if (WC->is_aide) {
237                         wprintf("<TR><TD><B>User name:</B></TD><TD>");
238                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
239                         wprintf("</TD>\n<TD ALIGN=center>");
240                         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
241                         wprintf("</TD>\n</TR>\n");
242                 }
243                 wprintf("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD ALIGN=center>");
244                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
245                 wprintf("</TD></TR></TABLE>\n");
246
247                 wprintf("</FORM></CENTER>\n");
248                 wDumpContent(1);
249         }
250 }