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