* 'idle' icon
[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("<FONT SIZE=+1 COLOR=\"FFFFFF\">&nbsp;&nbsp;<B>Users currently on ");
51         escputs(serv_info.serv_humannode);
52         wprintf("</B></FONT></TD><TD>");
53         offer_start_page();
54         wprintf("</TD></TR></TABLE>\n");
55
56         wprintf("<CENTER><TABLE BORDER=1 WIDTH=100%%>\n<TR>\n");
57         wprintf("<TH>Session ID</TH>\n");
58         wprintf("<TH>User Name</TH>\n");
59         wprintf("<TH>Room</TH>");
60         wprintf("<TH>From host</TH>\n</TR>\n");
61
62         serv_puts("TIME");
63         serv_gets(buf);
64         if (buf[0] == '2') {
65                 now = extract_long(&buf[4], 0);
66         }
67         else {
68                 now = time(NULL);
69         }
70
71         serv_puts("RWHO");
72         serv_gets(buf);
73         if (buf[0] == '1') {
74                 while (serv_gets(buf), strcmp(buf, "000")) {
75                         sess = extract_int(buf, 0);
76                         extract(user, buf, 1);
77                         extract(room, buf, 2);
78                         extract(host, buf, 3);
79                         extract(realroom, buf, 9);
80                         extract(realhost, buf, 10);
81                         last_activity = extract_long(buf, 5);
82
83                         wprintf("<TR>\n\t<TD ALIGN=center>%d", sess);
84                         if ((WC->is_aide) &&
85                             (sess != serv_info.serv_pid)) {
86                                 wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", sess);
87                                 urlescputs(user);
88                                 wprintf("\" onClick=\"return ConfirmKill();\" "
89                                 ">(kill)</A>");
90                         }
91                         if (sess == serv_info.serv_pid) {
92                                 wprintf(" <A HREF=\"/edit_me\" "
93                                         ">(edit)</A>");
94                         }
95                         wprintf("</TD>\n\t<TD>");
96
97                         /* (link to page this user) */
98                         wprintf("<A HREF=\"/display_page&recp=");
99                         urlescputs(user);
100                         wprintf("\">"
101                                 "<IMG ALIGN=MIDDLE WIDTH=20 HEIGHT=15 "
102                                 "SRC=\"/static/page.gif\" "
103                                 "ALT=\"(p)\""
104                                 " BORDER=0></A>&nbsp;");
105
106
107                         /* username (link to user bio/photo page) */
108                         wprintf("<A HREF=\"/showuser&who=");
109                         urlescputs(user);
110                         wprintf("\">");
111                         escputs(user);
112                         wprintf("</A>");
113
114                         if ((now - last_activity) > 900L) {
115                                 wprintf("&nbsp;"
116                                         "<IMG ALIGN=MIDDLE "
117                                         "SRC=\"/static/idle.gif\" "
118                                         "ALT=\"[idle]\" BORDER=0>");
119                         }
120
121                         /* room */
122                         wprintf("</TD>\n\t<TD>");
123                         escputs(room);
124                         if (strlen(realroom) > 0) {
125                                 wprintf("<BR><I>");
126                                 escputs(realroom);
127                                 wprintf("</I>");
128                         }
129                         wprintf("</TD>\n\t<TD>");
130
131                         /* hostname */
132                         escputs(host);
133                         if (strlen(realhost) > 0) {
134                                 wprintf("<BR><I>");
135                                 escputs(realhost);
136                                 wprintf("</I>");
137                         }
138                         wprintf("</TD>\n</TR>");
139                 }
140         }
141         wprintf("</TABLE>\n"
142                 "Click on a name to read user info.  Click on "
143                 "<IMG ALIGN=MIDDLE SRC=\"/static/page.gif\" ALT=\"(p)\" "
144                 "BORDER=0> to send "
145                 "a page (instant message) to that user.<BR></CENTER>\n");
146         wDumpContent(1);
147 }
148
149
150 void terminate_session(void)
151 {
152         char buf[SIZ];
153
154         serv_printf("TERM %s", bstr("which_session"));
155         serv_gets(buf);
156         whobbs();
157 }
158
159
160 /*
161  * Change your session info (fake roomname and hostname)
162  */
163 void edit_me(void)
164 {
165         char buf[SIZ];
166
167         if (!strcasecmp(bstr("sc"), "Change room name")) {
168                 serv_printf("RCHG %s", bstr("fake_roomname"));
169                 serv_gets(buf);
170                 http_redirect("/whobbs");
171         } else if (!strcasecmp(bstr("sc"), "Change host name")) {
172                 serv_printf("HCHG %s", bstr("fake_hostname"));
173                 serv_gets(buf);
174                 http_redirect("/whobbs");
175         } else if (!strcasecmp(bstr("sc"), "Change user name")) {
176                 serv_printf("UCHG %s", bstr("fake_username"));
177                 serv_gets(buf);
178                 http_redirect("/whobbs");
179         } else if (!strcasecmp(bstr("sc"), "Cancel")) {
180                 http_redirect("/whobbs");
181         } else {
182
183                 output_headers(3);
184
185                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
186                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
187                 wprintf("Edit your session display");
188                 wprintf("</B></FONT></TD></TR></TABLE>\n");
189                 wprintf("This screen allows you to change the way your\n");
190                 wprintf("session appears in the 'Who is online' listing.\n");
191                 wprintf("To turn off any 'fake' name you've previously\n");
192                 wprintf("set, simply click the appropriate 'change' button\n");
193                 wprintf("without typing anything in the corresponding box.\n");
194                 wprintf("<BR>\n");
195
196                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
197
198                 wprintf("<TABLE border=0 width=100%%>\n");
199
200                 wprintf("<TR><TD><B>Room name:</B></TD>\n<TD>");
201                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
202                 wprintf("</TD>\n<TD ALIGN=center>");
203                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
204                 wprintf("</TD>\n</TR>\n");
205
206                 wprintf("<TR><TD><B>Host name:</B></TD><TD>");
207                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
208                 wprintf("</TD>\n<TD ALIGN=center>");
209                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
210                 wprintf("</TD>\n</TR>\n");
211
212                 if (WC->is_aide) {
213                         wprintf("<TR><TD><B>User name:</B></TD><TD>");
214                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
215                         wprintf("</TD>\n<TD ALIGN=center>");
216                         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
217                         wprintf("</TD>\n</TR>\n");
218                 }
219                 wprintf("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD ALIGN=center>");
220                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
221                 wprintf("</TD></TR></TABLE>\n");
222
223                 wprintf("</FORM></CENTER>\n");
224                 wDumpContent(1);
225         }
226 }