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