]> code.citadel.org Git - citadel.git/blob - webcit/who.c
* Added "page user" button in wholist
[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
130
131                         /* username (link to user bio/photo page) */
132                         wprintf("<A HREF=\"/showuser&who=");
133                         urlescputs(wlist->username);
134                         wprintf("\">");
135                         escputs(wlist->username);
136                         wprintf("</A>");
137
138                         /* (link to page this user) */
139                         wprintf("<A HREF=\"/display_page&recp=");
140                         urlescputs(wlist->username);
141                         wprintf("\">(p)</A>");
142
143                         /* room */
144                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
145                         escputs(wlist->roomname);
146                         wprintf("</FONT></TD>\n\t<TD><FONT SIZE=-1>");
147                         /* hostname */
148                         escputs(wlist->hostname);
149                         wprintf("</FONT></TD>\n</TR>");
150                         wptr = wlist->next;
151                         free(wlist);
152                         wlist = wptr;
153                 }
154         }
155         wprintf("</TABLE></CENTER>\n");
156         wDumpContent(1);
157 }
158
159
160 void terminate_session(void)
161 {
162         char buf[256];
163
164         serv_printf("TERM %s", bstr("which_session"));
165         serv_gets(buf);
166         whobbs();
167 }
168
169
170 /*
171  * Change your session info (fake roomname and hostname)
172  */
173 void edit_me(void)
174 {
175         char buf[256];
176
177         if (!strcasecmp(bstr("sc"), "Change room name")) {
178                 serv_printf("RCHG %s", bstr("fake_roomname"));
179                 serv_gets(buf);
180                 http_redirect("/whobbs");
181         } else if (!strcasecmp(bstr("sc"), "Change host name")) {
182                 serv_printf("HCHG %s", bstr("fake_hostname"));
183                 serv_gets(buf);
184                 http_redirect("/whobbs");
185         } else if (!strcasecmp(bstr("sc"), "Change user name")) {
186                 serv_printf("UCHG %s", bstr("fake_username"));
187                 serv_gets(buf);
188                 http_redirect("/whobbs");
189         } else if (!strcasecmp(bstr("sc"), "Cancel")) {
190                 http_redirect("/whobbs");
191         } else {
192
193                 output_headers(3);
194
195                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
196                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
197                 wprintf("Edit your session display");
198                 wprintf("</B></FONT></TD></TR></TABLE>\n");
199                 wprintf("This screen allows you to change the way your\n");
200                 wprintf("session appears in the 'Who is online' listing.\n");
201                 wprintf("To turn off any 'fake' name you've previously\n");
202                 wprintf("set, simply click the appropriate 'change' button\n");
203                 wprintf("without typing anything in the corresponding box.\n");
204                 wprintf("<BR>\n");
205
206                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
207
208                 wprintf("<TABLE border=0 width=100%%>\n");
209
210                 wprintf("<TR><TD><B>Room name:</B></TD>\n<TD>");
211                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
212                 wprintf("</TD>\n<TD ALIGN=center>");
213                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
214                 wprintf("</TD>\n</TR>\n");
215
216                 wprintf("<TR><TD><B>Host name:</B></TD><TD>");
217                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
218                 wprintf("</TD>\n<TD ALIGN=center>");
219                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
220                 wprintf("</TD>\n</TR>\n");
221
222                 if (WC->is_aide) {
223                         wprintf("<TR><TD><B>User name:</B></TD><TD>");
224                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
225                         wprintf("</TD>\n<TD ALIGN=center>");
226                         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
227                         wprintf("</TD>\n</TR>\n");
228                 }
229                 wprintf("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD ALIGN=center>");
230                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
231                 wprintf("</TD></TR></TABLE>\n");
232
233                 wprintf("</FORM></CENTER>\n");
234                 wDumpContent(1);
235         }
236 }