* vcard_edit.c webcit.c webserver.c who.c : i18n
[citadel.git] / webcit / who.c
1 /*
2  * $Id$
3  *
4  * Display a list of all users currently logged on to the Citadel server.
5  */
6
7 #include "webcit.h"
8
9
10
11 /*
12  * Display inner div of Wholist
13  */
14 void who_inner_div(void) {
15         char buf[SIZ], user[SIZ], room[SIZ], host[SIZ],
16                 realroom[SIZ], realhost[SIZ];
17         int sess;
18         time_t last_activity;
19         time_t now;
20         int bg = 0;
21
22         wprintf("<table border=\"0\" cellspacing=\"0\" width=\"100%%\" bgcolor=\"#FFFFFF\">"
23                 "<tr>\n");
24         wprintf("<th colspan=\"3\"> </th>\n");
25         wprintf("<th>%s</th>\n", _("User name"));
26         wprintf("<th>%s</th>", _("Room"));
27         wprintf("<th>%s</th>\n</tr>\n", _("From host"));
28
29         serv_puts("TIME");
30         serv_getln(buf, sizeof buf);
31         if (buf[0] == '2') {
32                 now = extract_long(&buf[4], 0);
33         }
34         else {
35                 now = time(NULL);
36         }
37
38         serv_puts("RWHO");
39         serv_getln(buf, sizeof buf);
40         if (buf[0] == '1') {
41                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
42                         sess = extract_int(buf, 0);
43                         extract_token(user, buf, 1, '|', sizeof user);
44                         extract_token(room, buf, 2, '|', sizeof room);
45                         extract_token(host, buf, 3, '|', sizeof host);
46                         extract_token(realroom, buf, 9, '|', sizeof realroom);
47                         extract_token(realhost, buf, 10, '|', sizeof realhost);
48                         last_activity = extract_long(buf, 5);
49
50                         bg = 1 - bg;
51                         wprintf("<tr bgcolor=\"#%s\">",
52                                 (bg ? "DDDDDD" : "FFFFFF")
53                         );
54
55
56                         wprintf("<td>");
57                         if ((WC->is_aide) &&
58                             (sess != WC->ctdl_pid)) {
59                                 wprintf(" <a href=\"/terminate_session?which_session=%d", sess);
60                                 wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
61                         }
62                         if (sess == WC->ctdl_pid) {
63                                 wprintf(" <a href=\"/edit_me\">%s</a>", _("(edit)"));
64                         }
65                         wprintf("</td>");
66
67                         /* (link to page this user) */
68                         wprintf("<td><a href=\"/display_page?recp=");
69                         urlescputs(user);
70                         wprintf("\">"
71                                 "<img align=\"middle\" "
72                                 "src=\"/static/citadelchat_24x.gif\" "
73                                 "alt=\"(p)\""
74                                 " border=\"0\" /></a> ");
75                         wprintf("</td>");
76
77                         /* (idle flag) */
78                         wprintf("<td>");
79                         if ((now - last_activity) > 900L) {
80                                 wprintf(" "
81                                         "<img align=\"middle\" "
82                                         "src=\"/static/inactiveuser_24x.gif\" "
83                                         "alt=\"(idle)\" border=\"0\" />");
84                         }
85                         else {
86                                 wprintf(" "
87                                         "<img align=\"middle\" "
88                                         "src=\"/static/activeuser_24x.gif\" "
89                                         "alt=\"(active)\" border=\"0\" />");
90                         }
91                         wprintf("</td>\n<td>");
92
93
94
95                         /* username (link to user bio/photo page) */
96                         wprintf("<a href=\"/showuser?who=");
97                         urlescputs(user);
98                         wprintf("\">");
99                         escputs(user);
100                         wprintf("</a>");
101
102                         /* room */
103                         wprintf("</td>\n\t<td>");
104                         escputs(room);
105                         if (strlen(realroom) > 0) {
106                                 wprintf("<br /><i>");
107                                 escputs(realroom);
108                                 wprintf("</i>");
109                         }
110                         wprintf("</td>\n\t<td>");
111
112                         /* hostname */
113                         escputs(host);
114                         if (strlen(realhost) > 0) {
115                                 wprintf("<br /><i>");
116                                 escputs(realhost);
117                                 wprintf("</i>");
118                         }
119                         wprintf("</td>\n</tr>");
120                 }
121         }
122         wprintf("</table>");
123 }
124
125
126 /*
127  * XML-encapsulated version of wholist inner html
128  */
129 void who_inner_html(void) {
130         output_headers(0, 0, 0, 0, 0, 0, 0);
131
132         wprintf("Content-type: text/xml;charset=UTF-8\r\n"
133                 "Server: %s\r\n"
134                 "Connection: close\r\n"
135                 "Pragma: no-cache\r\n"
136                 "Cache-Control: no-store\r\n",
137                 SERVER);
138         begin_burst();
139
140         wprintf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
141                 "<ajax-response>\r\n"
142                 "<response type=\"element\" id=\"fix_scrollbar_bug\">\r\n"
143         );
144
145         who_inner_div();
146
147         wprintf("</response>\r\n"
148                 "</ajax-response>\r\n"
149                 "\r\n"
150         );
151
152         wDumpContent(0);
153 }
154
155
156 /*
157  * who is on?
158  */
159 void who(void)
160 {
161         char title[256];
162
163         output_headers(1, 1, 2, 0, 0, 0, 0);
164
165         wprintf("<script type=\"text/javascript\">\n"
166                 "function ConfirmKill() { \n"
167                 "return confirm('%s');\n"
168                 "}\n"
169                 "</script>\n", _("Do you really want to kill this session?")
170         );
171
172         wprintf("<div id=\"banner\">\n");
173         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
174         wprintf("<IMG SRC=\"/static/usermanag_48x.gif\" ALT=\" \" "
175                 "ALIGN=MIDDLE "
176                 ">");
177                 /* "onLoad=\"javascript:bodyOnLoad()\" " */
178         wprintf("<SPAN CLASS=\"titlebar\"> ");
179
180         snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
181         escputs(title);
182
183         wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
184         offer_start_page();
185         wprintf("</TD></TR></TABLE>\n");
186         wprintf("</div>\n");
187
188         wprintf("<div id=\"content\">\n");
189
190         wprintf("<div style=\"display:inline\" id=\"fix_scrollbar_bug\">");
191         who_inner_div();        /* Actual data handled by another function */
192         wprintf("</div>\n");
193
194         wprintf("<div id=\"instructions\" align=center>");
195         wprintf(_("Click on a name to read user info.  Click on %s "
196                 "to send an instant message to that user."),
197                 "<img align=\"middle\" src=\"/static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
198         );
199         wprintf("</div>\n");
200
201         /* JavaScript to make the ajax refresh happen:
202          * 1. Register the request 'getWholist' which calls the WebCit action 'who_inner_html'
203          * 2. Register the 'fix_scrollbar_bug' div as one we're interested in ajaxifying
204          * 3. setInterval to make the ajax refresh happen every 30 seconds.  The random number
205          *    in the request is there to prevent the eternally moronic Internet Explorer from
206          *    caching the XML even though it's been told not to.
207          */
208         wprintf(
209                 "<script type=\"text/javascript\">                                                              \n"
210                 "       ajaxEngine.registerRequest('getWholist', 'who_inner_html');                             \n"
211                 "       ajaxEngine.registerAjaxElement('fix_scrollbar_bug');                                    \n"
212                 "       setInterval(\"ajaxEngine.sendRequest('getWholist', 'junk='+Math.random());\", 30000);   \n"
213                 "</script>                                                                                      \n"
214         );
215
216         wDumpContent(1);
217 }
218
219
220 void terminate_session(void)
221 {
222         char buf[SIZ];
223
224         serv_printf("TERM %s", bstr("which_session"));
225         serv_getln(buf, sizeof buf);
226         who();
227 }
228
229
230 /*
231  * Change your session info (fake roomname and hostname)
232  */
233 void edit_me(void)
234 {
235         char buf[SIZ];
236
237         if (strlen(bstr("change_room_name_button")) > 0) {
238                 serv_printf("RCHG %s", bstr("fake_roomname"));
239                 serv_getln(buf, sizeof buf);
240                 http_redirect("/who");
241         } else if (strlen(bstr("change_host_name_button")) > 0) {
242                 serv_printf("HCHG %s", bstr("fake_hostname"));
243                 serv_getln(buf, sizeof buf);
244                 http_redirect("/who");
245         } else if (strlen(bstr("change_user_name_button")) > 0) {
246                 serv_printf("UCHG %s", bstr("fake_username"));
247                 serv_getln(buf, sizeof buf);
248                 http_redirect("/who");
249         } else if (strlen(bstr("cancel_button")) > 0) {
250                 http_redirect("/who");
251         } else {
252                 output_headers(1, 1, 0, 0, 0, 0, 0);
253
254                 wprintf("<div id=\"banner\">\n");
255                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
256                 wprintf("<SPAN CLASS=\"titlebar\">");
257                 wprintf(_("Edit your session display"));
258                 wprintf("</SPAN></TD></TR></TABLE>\n");
259                 wprintf("</div>\n<div id=\"content\">\n");
260
261                 wprintf(_("This screen allows you to change the way your "
262                         "session appears in the 'Who is online' listing. "
263                         "To turn off any 'fake' name you've previously "
264                         "set, simply click the appropriate 'change' button "
265                         "without typing anything in the corresponding box. "));
266                 wprintf("<br />\n");
267
268                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/edit_me\">\n");
269
270                 wprintf("<TABLE border=0 width=100%%>\n");
271
272                 wprintf("<TR><TD><B>");
273                 wprintf(_("Room name:"));
274                 wprintf("</B></TD>\n<TD>");
275                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_roomname\" MAXLENGTH=\"64\">\n");
276                 wprintf("</TD>\n<TD ALIGN=center>");
277                 wprintf("<INPUT TYPE=\"submit\" NAME=\"change_room_name_button\" VALUE=\"%s\">",
278                         _("Change room name"));
279                 wprintf("</TD>\n</TR>\n");
280
281                 wprintf("<TR><TD><B>");
282                 wprintf(_("Host name:"));
283                 wprintf("</B></TD><TD>");
284                 wprintf("<INPUT TYPE=\"text\" NAME=\"fake_hostname\" MAXLENGTH=\"64\">\n");
285                 wprintf("</TD>\n<TD ALIGN=center>");
286                 wprintf("<INPUT TYPE=\"submit\" NAME=\"change_host_name_button\" VALUE=\"%s\">",
287                         _("Change host name"));
288                 wprintf("</TD>\n</TR>\n");
289
290                 if (WC->is_aide) {
291                         wprintf("<TR><TD><B>");
292                         wprintf(_("User name:"));
293                         wprintf("</B></TD><TD>");
294                         wprintf("<INPUT TYPE=\"text\" NAME=\"fake_username\" MAXLENGTH=\"64\">\n");
295                         wprintf("</TD>\n<TD ALIGN=center>");
296                         wprintf("<INPUT TYPE=\"submit\" NAME=\"change_user_name_button\" VALUE=\"%s\">",
297                                 _("Change user name"));
298                         wprintf("</TD>\n</TR>\n");
299                 }
300                 wprintf("<TR><TD> </TD><TD> </TD><TD ALIGN=center>");
301                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">",
302                         _("Cancel"));
303                 wprintf("</TD></TR></TABLE>\n");
304                 wprintf("</FORM></CENTER>\n");
305                 wDumpContent(1);
306         }
307 }