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