]> code.citadel.org Git - citadel.git/blob - webcit/who.c
* Rewrote the HTTP engine and application coupling to run in a worker thread
[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         wprintf("HTTP/1.0 200 OK\n");
53         output_headers(1);
54
55         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
56         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
57         escputs(serv_info.serv_humannode);
58         wprintf("</B></FONT></TD></TR></TABLE>\n");
59
60         wprintf("<CENTER>\n<TABLE BORDER=1>\n<TR>\n");
61         wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">Session ID</FONT></TH>\n");
62         wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">User Name</FONT></TH>\n");
63         wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">Room</FONT></TH>");
64         wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">From host</FONT></TH>\n</TR>\n");
65         serv_puts("RWHO");
66         serv_gets(buf);
67         if (buf[0] == '1') {
68                 while (serv_gets(buf), strcmp(buf, "000")) {
69                         sess = extract_int(buf, 0);
70                         extract(user, buf, 1);
71                         extract(room, buf, 2);
72                         extract(host, buf, 3);
73
74                         foundit = 0;
75                         for (wptr = wlist; wptr != NULL; wptr = wptr->next) {
76                                 if (wptr->sessionnum == sess) {
77                                         foundit = 1;
78                                         if (strcasecmp(user, wptr->username)) {
79                                                 sprintf(buf, "%cBR%c%s",
80                                                         LB, RB, user);
81                                                 strcat(wptr->username, buf);
82                                         }
83                                         if (strcasecmp(room, wptr->roomname)) {
84                                                 sprintf(buf, "%cBR%c%s",
85                                                         LB, RB, room);
86                                                 strcat(wptr->roomname, buf);
87                                         }
88                                         if (strcasecmp(host, wptr->hostname)) {
89                                                 sprintf(buf, "%cBR%c%s",
90                                                         LB, RB, host);
91                                                 strcat(wptr->hostname, buf);
92                                         }
93                                 }
94                         }
95
96                         if (foundit == 0) {
97                                 wptr = (struct whouser *)
98                                     malloc(sizeof(struct whouser));
99                                 wptr->next = wlist;
100                                 wlist = wptr;
101                                 strcpy(wlist->username, user);
102                                 strcpy(wlist->roomname, room);
103                                 strcpy(wlist->hostname, host);
104                                 wlist->sessionnum = sess;
105                         }
106                 }
107
108                 while (wlist != NULL) {
109                         wprintf("<TR>\n\t<TD ALIGN=center><FONT FACE=\"Arial,Helvetica,sans-serif\">%d", wlist->sessionnum);
110                         if ((WC->is_aide) &&
111                             (wlist->sessionnum != serv_info.serv_pid)) {
112                                 wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", wlist->sessionnum);
113                                 urlescputs(wlist->username);
114                                 wprintf("\">(kill)</A>");
115                         }
116                         if (wlist->sessionnum == serv_info.serv_pid) {
117                                 wprintf(" <A HREF=\"/edit_me\">(edit)</A>");
118                         }
119                         /* username */
120                         wprintf("</FONT></TD>\n\t<TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><A HREF=\"/showuser?who=");
121                         urlescputs(wlist->username);
122                         wprintf("\" onMouseOver=\"window.status='View profile for ");
123                         escputs(wlist->username);
124                         wprintf("'; return true\">");
125                         escputs(wlist->username);
126                         wprintf("</A>");
127                         /* room */
128                         wprintf("</FONT></TD>\n\t<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
129                         /* handle chat */
130                         if (strstr(wlist->roomname, "chat") != NULL) {
131                                 wprintf("<A HREF=\"/chat\" onMouseOver=\"window.status='Chat'; return true\">&lt;chat&gt;</A>");
132                         } else {
133                                 wprintf("<A HREF=\"/dotgoto&room=");
134                                 urlescputs(wlist->roomname);
135                                 wprintf("\" onMouseOver=\"window.status='Go to room ");
136                                 escputs(wlist->roomname);
137                                 wprintf("'; return true\">");
138                                 escputs(wlist->roomname);
139                                 wprintf("</A>");
140                         }
141                         wprintf("</FONT></TD><TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
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("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+2><B><A HREF=\"/whobbs\"><FONT COLOR=\"#FF0000\">Refresh</FONT></A></B></FONT>\n");
153         wprintf("</TD></TR>\n</TABLE>\n</CENTER>");
154         wDumpContent(1);
155 }
156
157
158 void terminate_session(void)
159 {
160         char buf[256];
161
162         if (!strcasecmp(bstr("confirm"), "Yes")) {
163                 serv_printf("TERM %s", bstr("which_session"));
164                 serv_gets(buf);
165                 if (buf[0] == '2') {
166                         whobbs();
167                 } else {
168                         display_error(&buf[4]);
169                 }
170         } else {
171                 wprintf("HTTP/1.0 200 OK\n");
172                 output_headers(1);
173                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
174                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"<B>Confirm session termination");
175                 wprintf("</B></FONT></TD></TR></TABLE>\n");
176
177                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">Are you sure you want to terminate session %s",
178                         bstr("which_session"));
179                 if (strlen(bstr("session_owner")) > 0) {
180                         wprintf(" (");
181                         escputs(bstr("session_owner"));
182                         wprintf(")");
183                 }
184                 wprintf("?<BR><BR>\n");
185
186                 wprintf("<A HREF=\"/terminate_session&which_session=%s&confirm=yes\">",
187                         bstr("which_session"));
188                 wprintf("Yes</A>&nbsp;&nbsp;&nbsp;");
189                 wprintf("<A HREF=\"/whobbs\">No</A></FONT>");
190                 wDumpContent(1);
191         }
192
193 }
194
195
196
197 /*
198  * Change your session info (fake roomname and hostname)
199  */
200 void edit_me(void)
201 {
202         char buf[256];
203
204         if (!strcasecmp(bstr("sc"), "Change room name")) {
205                 serv_printf("RCHG %s", bstr("fake_roomname"));
206                 serv_gets(buf);
207                 whobbs();
208         } else if (!strcasecmp(bstr("sc"), "Change host name")) {
209                 serv_printf("HCHG %s", bstr("fake_hostname"));
210                 serv_gets(buf);
211                 whobbs();
212         } else if (!strcasecmp(bstr("sc"), "Change user name")) {
213                 serv_printf("UCHG %s", bstr("fake_username"));
214                 serv_gets(buf);
215                 whobbs();
216         } else if (!strcasecmp(bstr("sc"), "Cancel")) {
217                 whobbs();
218         } else {
219
220                 wprintf("HTTP/1.0 200 OK\n");
221                 output_headers(1);
222
223                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
224                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"><B>");
225                 wprintf("Edit your session display");
226                 wprintf("</B></FONT></TD></TR></TABLE>\n");
227                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
228                 wprintf("This screen allows you to change the way your\n");
229                 wprintf("session appears in the 'Who is online' listing.\n");
230                 wprintf("To turn off any 'fake' name you've previously\n");
231                 wprintf("set, simply click the appropriate 'change' button\n");
232                 wprintf("without typing anything in the corresponding box.\n");
233                 wprintf("<BR>\n</FONT>\n");
234
235                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
236
237                 wprintf("<TABLE border=0 width=100%>\n");
238
239                 wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>Room name:</B></FONT></TD>\n<TD>");
240                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
241                 wprintf("</FONT></TD>\n<TD ALIGN=center>");
242                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
243                 wprintf("</FONT></TD>\n</TR>\n");
244
245                 wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>Host name:</B></FONT></TD><TD>");
246                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
247                 wprintf("</FONT></TD>\n<TD ALIGN=center>");
248                 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
249                 wprintf("</FONT></TD>\n</TR>\n");
250
251                 if (WC->is_aide) {
252                         wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\"><B>User name:</B></FONT></TD><TD>");
253                         wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
254                         wprintf("</FONT></TD>\n<TD ALIGN=center>");
255                         wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
256                         wprintf("</FONT></TD>\n</TR>\n");
257                 }
258                 wprintf("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD ALIGN=center>");
259                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
260                 wprintf("</TD></TR></TABLE>\n");
261
262                 wprintf("</FORM></CENTER>\n");
263                 wDumpContent(1);
264         }
265 }