]> code.citadel.org Git - citadel.git/blob - webcit/who.c
* Added a "kill session" link to each line of the wholist when
[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);
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                                 wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", wlist->sessionnum);
91                                 urlescputs(wlist->username);
92                                 wprintf("\">(kill)</A>");
93                                 }
94                         wprintf("</TD><TD>");
95                         escputs(wlist->username);
96                         wprintf("</TD><TD>");
97                         escputs(wlist->roomname);
98                         wprintf("</TD><TD>");
99                         escputs(wlist->hostname);
100                         wprintf("</TD></TR>\n");
101                         wptr = wlist->next;
102                         free(wlist);
103                         wlist = wptr;
104                         }
105                 }
106         wprintf("</TABLE>\n");
107         wprintf("<A HREF=\"/whobbs\">Refresh</A>\n");
108         wprintf("</CENTER></BODY></HTML>\n");
109         wDumpContent();
110         }
111
112
113 void terminate_session(void) {
114         char buf[256];
115
116         if (!strcasecmp(bstr("confirm"), "Yes")) {
117                 serv_printf("TERM %s", bstr("which_session"));
118                 serv_gets(buf);
119                 if (buf[0]=='2') {
120                         whobbs();
121                         }
122                 else {
123                         display_error(&buf[4]);
124                         }
125                 }
126
127         else {
128                 printf("HTTP/1.0 200 OK\n");
129                 output_headers(1);
130                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
131                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Confirm session termination");
132                 wprintf("</B></FONT></TD></TR></TABLE>\n");
133         
134                 wprintf("Are you sure you want to terminate session %s",
135                         bstr("which_session"));
136                 if (strlen(bstr("session_owner"))>0) {
137                         wprintf(" (");
138                         escputs(bstr("session_owner"));
139                         wprintf(")");
140                         }
141                 wprintf("?<BR><BR>\n");
142         
143                 wprintf("<A HREF=\"/terminate_session&which_session=%s&confirm=yes\">",
144                         bstr("which_session"));
145                 wprintf("Yes</A>&nbsp;&nbsp;&nbsp;");
146                 wprintf("<A HREF=\"/whobbs\">No</A>");
147                 wprintf("</BODY></HTML>\n");
148                 wDumpContent();
149                 }
150
151         }