]> code.citadel.org Git - citadel.git/blob - webcit/who.c
* Added paging icon and right-justified it
[citadel.git] / webcit / who.c
1 /* $Id$ */
2
3
4 #include <ctype.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/socket.h>
13 #include <sys/time.h>
14 #include <limits.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25
26
27
28
29
30
31 struct whouser {
32         struct whouser *next;
33         int sessionnum;
34         char username[256];
35         char roomname[256];
36         char hostname[256];
37         char clientsoftware[256];
38 };
39
40 /*
41  * who is on?
42  */
43 void whobbs(void)
44 {
45         struct whouser *wlist = NULL;
46         struct whouser *wptr = NULL;
47         char buf[256], sess, user[256], room[256], host[256];
48         int foundit;
49
50         output_headers(7);
51
52
53         wprintf("<SCRIPT LANGUAGE=\"JavaScript\">\n"
54                 "function ConfirmKill() { \n"
55                 "return confirm('Do you really want to kill this session?');\n"
56                 "}\n"
57                 "</SCRIPT>\n"
58         );
59
60         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
61         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
62         escputs(serv_info.serv_humannode);
63         wprintf("</B></FONT></TD></TR></TABLE>\n");
64
65         wprintf("<CENTER>\n"
66                 "Click on a name to read user info.  Click on "
67                 "<IMG SRC=\"/static/page.gif\" ALT=\"(p)\" BORDER=0> to send "
68                 "a page (instant message) to that user.<BR>"
69                 "<TABLE BORDER=1 WIDTH=100%%>\n<TR>\n");
70         wprintf("<TH>Session ID</TH>\n");
71         wprintf("<TH>User Name</TH>\n");
72         wprintf("<TH>Room</TH>");
73         wprintf("<TH>From host</TH>\n</TR>\n");
74         serv_puts("RWHO");
75         serv_gets(buf);
76         if (buf[0] == '1') {
77                 while (serv_gets(buf), strcmp(buf, "000")) {
78                         sess = extract_int(buf, 0);
79                         extract(user, buf, 1);
80                         extract(room, buf, 2);
81                         extract(host, buf, 3);
82
83                         foundit = 0;
84                         for (wptr = wlist; wptr != NULL; wptr = wptr->next) {
85                                 if (wptr->sessionnum == sess) {
86                                         foundit = 1;
87                                         if (strcasecmp(user, wptr->username)) {
88                                                 sprintf(buf, "%cBR%c%s",
89                                                         LB, RB, user);
90                                                 strcat(wptr->username, buf);
91                                         }
92                                         if (strcasecmp(room, wptr->roomname)) {
93                                                 sprintf(buf, "%cBR%c%s",
94                                                         LB, RB, room);
95                                                 strcat(wptr->roomname, buf);
96                                         }
97                                         if (strcasecmp(host, wptr->hostname)) {
98                                                 sprintf(buf, "%cBR%c%s",
99                                                         LB, RB, host);
100                                                 strcat(wptr->hostname, buf);
101                                         }
102                                 }
103                         }
104
105                         if (foundit == 0) {
106                                 wptr = (struct whouser *)
107                                     malloc(sizeof(struct whouser));
108                                 wptr->next = wlist;
109                                 wlist = wptr;
110                                 strcpy(wlist->username, user);
111                                 strcpy(wlist->roomname, room);
112                                 strcpy(wlist->hostname, host);
113                                 wlist->sessionnum = sess;
114                         }
115                 }
116
117                 while (wlist != NULL) {
118                         wprintf("<TR>\n\t<TD ALIGN=center>%d", wlist->sessionnum);
119                         if ((WC->is_aide) &&
120                             (wlist->sessionnum != serv_info.serv_pid)) {
121                                 wprintf(" <A HREF=\"/terminate_session&which_session=%d&session_owner=", wlist->sessionnum);
122                                 urlescputs(wlist->username);
123                                 wprintf("\" onClick=\"return ConfirmKill();\" "
124                                 ">(kill)</A>");
125                         }
126                         if (wlist->sessionnum == serv_info.serv_pid) {
127                                 wprintf(" <A HREF=\"/edit_me\" "
128                                         ">(edit)</A>");
129                         }
130                         wprintf("</TD>\n\t<TD>");
131
132
133                         /* username (link to user bio/photo page) */
134                         wprintf("<A HREF=\"/showuser&who=");
135                         urlescputs(wlist->username);
136                         wprintf("\">");
137                         escputs(wlist->username);
138                         wprintf("</A>");
139
140                         /* (link to page this user) */
141                         wprintf("<DIV ALIGN=RIGHT>"
142                                 "<A HREF=\"/whobbs\" "
143                                 " onClick=\"return window.open('/display_page&recp=");
144                         urlescputs(wlist->username);
145                         wprintf("', 'CitaPageWin', 'toolbar=no,location=no,copyhistory=no,status=no,scrollbars=yes,resizable=no,height=400,width=400');\">"
146                                 "<IMG SRC=\"/static/page.gif\" ALT=\"(p)\""
147                                 " BORDER=0></A></DIV>");
148
149                         /* room */
150                         wprintf("</TD>\n\t<TD>");
151                         escputs(wlist->roomname);
152                         wprintf("</TD>\n\t<TD>");
153                         /* hostname */
154                         escputs(wlist->hostname);
155                         wprintf("</TD>\n</TR>");
156                         wptr = wlist->next;
157                         free(wlist);
158                         wlist = wptr;
159                 }
160         }
161         wprintf("</TABLE></CENTER>\n");
162         wDumpContent(1);
163 }
164
165
166 void terminate_session(void)
167 {
168         char buf[256];
169
170         serv_printf("TERM %s", bstr("which_session"));
171         serv_gets(buf);
172         whobbs();
173 }
174
175
176 /*
177  * Change your session info (fake roomname and hostname)
178  */
179 void edit_me(void)
180 {
181         char buf[256];
182
183         if (!strcasecmp(bstr("sc"), "Change room name")) {
184                 serv_printf("RCHG %s", bstr("fake_roomname"));
185                 serv_gets(buf);
186                 http_redirect("/whobbs");
187         } else if (!strcasecmp(bstr("sc"), "Change host name")) {
188                 serv_printf("HCHG %s", bstr("fake_hostname"));
189                 serv_gets(buf);
190                 http_redirect("/whobbs");
191         } else if (!strcasecmp(bstr("sc"), "Change user name")) {
192                 serv_printf("UCHG %s", bstr("fake_username"));
193                 serv_gets(buf);
194                 http_redirect("/whobbs");
195         } else if (!strcasecmp(bstr("sc"), "Cancel")) {
196                 http_redirect("/whobbs");
197         } else {
198
199                 output_headers(3);
200
201                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
202                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
203                 wprintf("Edit your session display");
204                 wprintf("</B></FONT></TD></TR></TABLE>\n");
205                 wprintf("This screen allows you to change the way your\n");
206                 wprintf("session appears in the 'Who is online' listing.\n");
207                 wprintf("To turn off any 'fake' name you've previously\n");
208                 wprintf("set, simply click the appropriate 'change' button\n");
209                 wprintf("without typing anything in the corresponding box.\n");
210                 wprintf("<BR>\n");
211
212                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
213
214                 wprintf("<TABLE border=0 width=100%%>\n");
215
216                 wprintf("<TR><TD><B>Room name:</B></TD>\n<TD>");
217                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
218                 wprintf("</TD>\n<TD ALIGN=center>");
219                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change room name\">");
220                 wprintf("</TD>\n</TR>\n");
221
222                 wprintf("<TR><TD><B>Host name:</B></TD><TD>");
223                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
224                 wprintf("</TD>\n<TD ALIGN=center>");
225                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change host name\">");
226                 wprintf("</TD>\n</TR>\n");
227
228                 if (WC->is_aide) {
229                         wprintf("<TR><TD><B>User name:</B></TD><TD>");
230                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
231                         wprintf("</TD>\n<TD ALIGN=center>");
232                         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Change user name\">");
233                         wprintf("</TD>\n</TR>\n");
234                 }
235                 wprintf("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD ALIGN=center>");
236                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
237                 wprintf("</TD></TR></TABLE>\n");
238
239                 wprintf("</FORM></CENTER>\n");
240                 wDumpContent(1);
241         }
242 }