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