* who.c: provide links to bio/photo pages for each user in the wholist
[citadel.git] / webcit / who.c
1 /* $Id$ */
2
3
4
5
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <signal.h>
12 #include <sys/types.h>
13 #include <sys/wait.h>
14 #include <sys/socket.h>
15 #include <sys/time.h>
16 #include <limits.h>
17 #include <netinet/in.h>
18 #include <netdb.h>
19 #include <string.h>
20 #include <pwd.h>
21 #include <errno.h>
22 #include <stdarg.h>
23 #include <pthread.h>
24 #include <signal.h>
25 #include "webcit.h"
26
27
28
29
30
31
32
33 struct whouser {
34         struct whouser *next;
35         int sessionnum;
36         char username[256];
37         char roomname[256];
38         char hostname[256];
39         char clientsoftware[256];
40 };
41
42 /*
43  * who is on?
44  */
45 void whobbs(void)
46 {
47         struct whouser *wlist = NULL;
48         struct whouser *wptr = NULL;
49         char buf[256], sess, user[256], room[256], host[256];
50         int foundit;
51
52         output_headers(7);
53
54
55         wprintf("<SCRIPT LANGUAGE=\"JavaScript\">\n"
56                 "function ConfirmKill() { \n"
57                 "return confirm('Do you really want to kill this session?');\n"
58                 "}\n"
59                 "</SCRIPT>\n"
60         );
61
62         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
63         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
64         escputs(serv_info.serv_humannode);
65         wprintf("</B></FONT></TD></TR></TABLE>\n");
66
67         wprintf("<CENTER>\n<TABLE BORDER=1 WIDTH=100%%>\n<TR>\n");
68         wprintf("<TH>Session ID</TH>\n");
69         wprintf("<TH>User Name</TH>\n");
70         wprintf("<TH>Room</TH>");
71         wprintf("<TH>From host</TH>\n</TR>\n");
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
81                         foundit = 0;
82                         for (wptr = wlist; wptr != NULL; wptr = wptr->next) {
83                                 if (wptr->sessionnum == sess) {
84                                         foundit = 1;
85                                         if (strcasecmp(user, wptr->username)) {
86                                                 sprintf(buf, "%cBR%c%s",
87                                                         LB, RB, user);
88                                                 strcat(wptr->username, buf);
89                                         }
90                                         if (strcasecmp(room, wptr->roomname)) {
91                                                 sprintf(buf, "%cBR%c%s",
92                                                         LB, RB, room);
93                                                 strcat(wptr->roomname, buf);
94                                         }
95                                         if (strcasecmp(host, wptr->hostname)) {
96                                                 sprintf(buf, "%cBR%c%s",
97                                                         LB, RB, host);
98                                                 strcat(wptr->hostname, buf);
99                                         }
100                                 }
101                         }
102
103                         if (foundit == 0) {
104                                 wptr = (struct whouser *)
105                                     malloc(sizeof(struct whouser));
106                                 wptr->next = wlist;
107                                 wlist = wptr;
108                                 strcpy(wlist->username, user);
109                                 strcpy(wlist->roomname, room);
110                                 strcpy(wlist->hostname, host);
111                                 wlist->sessionnum = sess;
112                         }
113                 }
114
115                 while (wlist != NULL) {
116                         wprintf("<TR>\n\t<TD ALIGN=center><FONT SIZE=-1>%d", wlist->sessionnum);
117                         if ((WC->is_aide) &&
118                             (wlist->sessionnum != serv_info.serv_pid)) {
119                                 wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", wlist->sessionnum);
120                                 urlescputs(wlist->username);
121                                 wprintf("\" onClick=\"return ConfirmKill();\" "
122                                 ">(kill)</A>");
123                         }
124                         if (wlist->sessionnum == serv_info.serv_pid) {
125                                 wprintf(" <A HREF=\"/edit_me\" "
126                                         ">(edit)</A>");
127                         }
128                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
129
130
131                         /* username (link to user bio/photo page) */
132                         wprintf("<A HREF=\"javascript:window.opener.location='/showuser&who=");
133                         urlescputs(wlist->username);
134                         wprintf("';window.location='/whobbs'\">");
135                         escputs(wlist->username);
136                         wprintf("</A>");
137
138                         /* room */
139                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
140                         escputs(wlist->roomname);
141                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
142                         /* hostname */
143                         escputs(wlist->hostname);
144                         wprintf("</FONT></TD>\n</TR>");
145                         wptr = wlist->next;
146                         free(wlist);
147                         wlist = wptr;
148                 }
149         }
150         wprintf("</TABLE>\n<BR><BR>\n");
151         wprintf("<TABLE BORDER=0 BGCOLOR=\"#003399\">\n<TR><TD ALIGN=center VALIGN=center CELLPADING=20>\n");
152         wprintf("<B><A HREF=\"javascript:window.close()\">Close window</A></B>\n");
153         wprintf("</TD></TR>\n</TABLE></FONT>\n</CENTER>");
154
155         wDumpContent(1);
156 }
157
158
159 void terminate_session(void)
160 {
161         char buf[256];
162
163         serv_printf("TERM %s", bstr("which_session"));
164         serv_gets(buf);
165         whobbs();
166 }
167
168
169 /*
170  * Change your session info (fake roomname and hostname)
171  */
172 void edit_me(void)
173 {
174         char buf[256];
175
176         if (!strcasecmp(bstr("sc"), "Change room name")) {
177                 serv_printf("RCHG %s", bstr("fake_roomname"));
178                 serv_gets(buf);
179                 http_redirect("/whobbs");
180         } else if (!strcasecmp(bstr("sc"), "Change host name")) {
181                 serv_printf("HCHG %s", bstr("fake_hostname"));
182                 serv_gets(buf);
183                 http_redirect("/whobbs");
184         } else if (!strcasecmp(bstr("sc"), "Change user name")) {
185                 serv_printf("UCHG %s", bstr("fake_username"));
186                 serv_gets(buf);
187                 http_redirect("/whobbs");
188         } else if (!strcasecmp(bstr("sc"), "Cancel")) {
189                 http_redirect("/whobbs");
190         } else {
191
192                 output_headers(3);
193
194                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
195                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
196                 wprintf("Edit your session display");
197                 wprintf("</B></FONT></TD></TR></TABLE>\n");
198                 wprintf("This screen allows you to change the way your\n");
199                 wprintf("session appears in the 'Who is online' listing.\n");
200                 wprintf("To turn off any 'fake' name you've previously\n");
201                 wprintf("set, simply click the appropriate 'change' button\n");
202                 wprintf("without typing anything in the corresponding box.\n");
203                 wprintf("<BR>\n");
204
205                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
206
207                 wprintf("<TABLE border=0 width=100%%>\n");
208
209                 wprintf("<TR><TD><B>Room name:</B></TD>\n<TD>");
210                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
211                 wprintf("</TD>\n<TD ALIGN=center>");
212                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
213                 wprintf("</TD>\n</TR>\n");
214
215                 wprintf("<TR><TD><B>Host name:</B></TD><TD>");
216                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
217                 wprintf("</TD>\n<TD ALIGN=center>");
218                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
219                 wprintf("</TD>\n</TR>\n");
220
221                 if (WC->is_aide) {
222                         wprintf("<TR><TD><B>User name:</B></TD><TD>");
223                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
224                         wprintf("</TD>\n<TD ALIGN=center>");
225                         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
226                         wprintf("</TD>\n</TR>\n");
227                 }
228                 wprintf("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD ALIGN=center>");
229                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
230                 wprintf("</TD></TR></TABLE>\n");
231
232                 wprintf("</FORM></CENTER>\n");
233                 wDumpContent(1);
234         }
235 }