dadbf041c632f01ba227efa9a28427c77ffbec32
[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                         /* username */
130                         escputs(wlist->username);
131                         /* room */
132                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
133                         escputs(wlist->roomname);
134                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
135                         /* hostname */
136                         escputs(wlist->hostname);
137                         wprintf("</FONT></TD>\n</TR>");
138                         wptr = wlist->next;
139                         free(wlist);
140                         wlist = wptr;
141                 }
142         }
143         wprintf("</TABLE>\n<BR><BR>\n");
144         wprintf("<TABLE BORDER=0 BGCOLOR=\"#003399\">\n<TR><TD ALIGN=center VALIGN=center CELLPADING=20>\n");
145         wprintf("<B><A HREF=\"javascript:window.close()\">Close window</A></B>\n");
146         wprintf("</TD></TR>\n</TABLE></FONT>\n</CENTER>");
147
148         wDumpContent(1);
149 }
150
151
152 void terminate_session(void)
153 {
154         char buf[256];
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[256];
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("<FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
189                 wprintf("Edit your session display");
190                 wprintf("</B></FONT></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 }