]> code.citadel.org Git - citadel.git/blob - webcit/who.c
1d3f40ee28dfaa21844dc7ceb390d9acd8b98942
[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                         /* username */
99                         wprintf("</TD><TD><A HREF=\"/static/page_user_popup.html\" onMouseOver=\"window.status='Page ");
100                         escputs(wlist->username);
101                         wprintf("'; return true\">");
102                         escputs(wlist->username);
103                         wprintf("</A>");
104                         /* room */
105                         wprintf("</TD><TD><A HREF=\"/dotgoto&room=");
106                         escputs(wlist->roomname);
107                         wprintf("\" onMouseOver=\"window.status='Go to room ");
108                         escputs(wlist->roomname);
109                         wprintf("'; return true\">");
110                         escputs(wlist->roomname);
111                         wprintf("</A>");
112                         wprintf("</TD><TD>");
113                         /* hostname */
114                         escputs(wlist->hostname);
115                         wprintf("</TD></TR>\n");
116                         wptr = wlist->next;
117                         free(wlist);
118                         wlist = wptr;
119                         }
120                 }
121         wprintf("</TABLE>\n");
122         wprintf("<A HREF=\"/whobbs\">Refresh</A>\n");
123         wprintf("</CENTER>\n");
124         wDumpContent(1);
125         }
126
127
128 void terminate_session(void) {
129         char buf[256];
130
131         if (!strcasecmp(bstr("confirm"), "Yes")) {
132                 serv_printf("TERM %s", bstr("which_session"));
133                 serv_gets(buf);
134                 if (buf[0]=='2') {
135                         whobbs();
136                         }
137                 else {
138                         display_error(&buf[4]);
139                         }
140                 }
141
142         else {
143                 printf("HTTP/1.0 200 OK\n");
144                 output_headers(1, "bottom");
145                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
146                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Confirm session termination");
147                 wprintf("</B></FONT></TD></TR></TABLE>\n");
148         
149                 wprintf("Are you sure you want to terminate session %s",
150                         bstr("which_session"));
151                 if (strlen(bstr("session_owner"))>0) {
152                         wprintf(" (");
153                         escputs(bstr("session_owner"));
154                         wprintf(")");
155                         }
156                 wprintf("?<BR><BR>\n");
157         
158                 wprintf("<A HREF=\"/terminate_session&which_session=%s&confirm=yes\">",
159                         bstr("which_session"));
160                 wprintf("Yes</A>&nbsp;&nbsp;&nbsp;");
161                 wprintf("<A HREF=\"/whobbs\">No</A>");
162                 wDumpContent(1);
163                 }
164
165         }
166
167
168
169 /*
170  * Change your session info (fake roomname and hostname)
171  */
172 void edit_me(void) {
173         char buf[256];
174
175         printf("HTTP/1.0 200 OK\n");
176         output_headers(1, "bottom");
177
178         if (!strcasecmp(bstr("sc"), "Change room name")) {
179                 serv_printf("RCHG %s", bstr("fake_roomname"));
180                 serv_gets(buf);
181                 whobbs();
182                 }
183         else if (!strcasecmp(bstr("sc"), "Change host name")) {
184                 serv_printf("HCHG %s", bstr("fake_hostname"));
185                 serv_gets(buf);
186                 whobbs();
187                 }
188         else if (!strcasecmp(bstr("sc"), "Change user name")) {
189                 serv_printf("UCHG %s", bstr("fake_username"));
190                 serv_gets(buf);
191                 whobbs();
192                 }
193         else if (!strcasecmp(bstr("sc"), "Cancel")) {
194                 whobbs();
195                 }
196         else {
197
198                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
199                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>");
200                 wprintf("Edit your session display");
201                 wprintf("</B></FONT></TD></TR></TABLE>\n");
202         
203                 wprintf("This screen allows you to change the way your\n");
204                 wprintf("session appears in the 'Who is online' listing.\n");
205                 wprintf("To turn off any 'fake' name you've previously\n");
206                 wprintf("set, simply click the appropriate 'change' button\n");
207                 wprintf("without typing anything in the corresponding box.\n");
208                 wprintf("<BR>\n");
209
210                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
211
212                 wprintf("<TABLE border=0 width=100%>\n");
213
214                 wprintf("<TR><TD>Room name:</TD><TD>");
215                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
216                 wprintf("</TD><TD>");
217                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
218                 wprintf("</TD></TR>\n");
219
220                 wprintf("<TR><TD>Host name:</TD><TD>");
221                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
222                 wprintf("</TD><TD>");
223                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
224                 wprintf("</TD></TR>\n");
225
226                 if (is_aide) {
227                         wprintf("<TR><TD>User name:</TD><TD>");
228                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
229                         wprintf("</TD><TD>");
230                         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
231                         wprintf("</TD></TR>\n");
232                         }
233
234                 wprintf("<TR><TD></TD><TD></TD><TD>");
235                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
236                 wprintf("</TD></TR></TABLE>\n");
237
238                 wprintf("</FORM></CENTER>\n");
239                 wDumpContent(1);
240                 }
241         }
242