f5de0ddf32a0f0302ac571a8fa9c420550e53120
[citadel.git] / webcit / who.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup DislpayWho Display a list of all users currently logged on to the Citadel server.
6  * \ingroup WebcitDisplayItems
7  */
8 /*@{*/
9 #include "webcit.h"
10
11
12
13 /**
14  * \brief Display inner div of Wholist
15  */
16 void who_inner_div(void) {
17         char buf[SIZ], user[SIZ], room[SIZ], host[SIZ],
18                 realroom[SIZ], realhost[SIZ];
19         int sess;
20         time_t last_activity;
21         time_t now;
22         int bg = 0;
23
24         wprintf("<table class=\"altern\">"
25                 "<tr>\n");
26         wprintf("<th class=\"edit_col\"> </th>\n");
27         wprintf("<th colspan=\"2\"> </th>\n");
28         wprintf("<th>%s</th>\n", _("User name"));
29         wprintf("<th>%s</th>", _("Room"));
30         wprintf("<th class=\"host_col\">%s</th>\n</tr>\n", _("From host"));
31
32         serv_puts("TIME");
33         serv_getln(buf, sizeof buf);
34         if (buf[0] == '2') {
35                 now = extract_long(&buf[4], 0);
36         }
37         else {
38                 now = time(NULL);
39         }
40
41         serv_puts("RWHO");
42         serv_getln(buf, sizeof buf);
43         if (buf[0] == '1') {
44                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
45                         sess = extract_int(buf, 0);
46                         extract_token(user, buf, 1, '|', sizeof user);
47                         extract_token(room, buf, 2, '|', sizeof room);
48                         extract_token(host, buf, 3, '|', sizeof host);
49                         extract_token(realroom, buf, 9, '|', sizeof realroom);
50                         extract_token(realhost, buf, 10, '|', sizeof realhost);
51                         last_activity = extract_long(buf, 5);
52
53                         bg = 1 - bg;
54                         wprintf("<tr class=\"%s\">",
55                                 (bg ? "even" : "odd")
56                         );
57
58
59                         wprintf("<td class=\"edit_col\">");
60                         if ((WC->is_aide) &&
61                             (sess != WC->ctdl_pid)) {
62                                 wprintf(" <a href=\"terminate_session?which_session=%d", sess);
63                                 wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
64                         }
65                         if (sess == WC->ctdl_pid) {
66                                 wprintf(" <a href=\"edit_me\">%s</a>", _("(edit)"));
67                         }
68                         wprintf("</td>");
69
70                         /** (link to page this user) */
71                         wprintf("<td width=\"5%\"><a href=\"display_page?recp=");
72                         urlescputs(user);
73                         wprintf("\">"
74                                 "<img align=\"middle\" "
75                                 "src=\"static/citadelchat_24x.gif\" "
76                                 "alt=\"(p)\""
77                                 " border=\"0\" /></a> ");
78                         wprintf("</td>");
79
80                         /** (idle flag) */
81                         wprintf("<td width=\"5%\">");
82                         if ((now - last_activity) > 900L) {
83                                 wprintf(" "
84                                         "<img align=\"middle\" "
85                                         "src=\"static/inactiveuser_24x.gif\" "
86                                         "alt=\"(idle)\" border=\"0\" />");
87                         }
88                         else {
89                                 wprintf(" "
90                                         "<img align=\"middle\" "
91                                         "src=\"static/activeuser_24x.gif\" "
92                                         "alt=\"(active)\" border=\"0\" />");
93                         }
94                         wprintf("</td>\n<td>");
95
96
97
98                         /** username (link to user bio/photo page) */
99                         wprintf("<a href=\"showuser?who=");
100                         urlescputs(user);
101                         wprintf("\">");
102                         escputs(user);
103                         wprintf("</a>");
104
105                         /** room */
106                         wprintf("</td>\n\t<td>");
107                         escputs(room);
108                         if (!IsEmptyStr(realroom) ) {
109                                 wprintf("<br /><i>");
110                                 escputs(realroom);
111                                 wprintf("</i>");
112                         }
113                         wprintf("</td>\n\t<td class=\"host_col\">");
114
115                         /** hostname */
116                         escputs(host);
117                         if (!IsEmptyStr(realhost)) {
118                                 wprintf("<br /><i>");
119                                 escputs(realhost);
120                                 wprintf("</i>");
121                         }
122                         wprintf("</td>\n</tr>");
123                 }
124         }
125         wprintf("</table>");
126 }
127
128
129 /**
130  * \brief who is on?
131  */
132 void who(void)
133 {
134         char title[256];
135
136         output_headers(1, 1, 2, 0, 0, 0);
137
138         wprintf("<script type=\"text/javascript\">\n"
139                 "function ConfirmKill() { \n"
140                 "return confirm('%s');\n"
141                 "}\n"
142                 "</script>\n", _("Do you really want to kill this session?")
143         );
144
145         wprintf("<div id=\"banner\">\n");
146         wprintf("<table class=\"who_banner\"><tr><td>");
147         wprintf("<img src=\"static/usermanag_48x.gif\" alt=\" \" "
148                 "align=middle "
149                 ">");
150         wprintf("<span class=\"titlebar\"> ");
151
152         snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
153         escputs(title);
154
155         wprintf("</span></td><td align=right>");
156         offer_start_page();
157         wprintf("</td></tr></table>\n");
158         wprintf("</div>\n");
159
160         wprintf("<div id=\"content\" class=\"who_is_online\">\n");
161
162         wprintf("<div style=\"display:inline\" id=\"fix_scrollbar_bug\">");
163         who_inner_div();
164         wprintf("</div>\n");
165
166         wprintf("<div id=\"instructions\" align=center>");
167         wprintf(_("Click on a name to read user info.  Click on %s "
168                 "to send an instant message to that user."),
169                 "<img align=\"middle\" src=\"static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
170         );
171         wprintf("</div>\n");
172
173         /**
174          * JavaScript to make the ajax refresh happen:
175          * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater
176          * It wants: 1. The div being updated
177          *           2. The URL of the update source
178          *           3. Other flags (such as the HTTP method and the refresh frequency)
179          */
180         wprintf(
181                 "<script type=\"text/javascript\">                                      "
182                 " new Ajax.PeriodicalUpdater('fix_scrollbar_bug', 'who_inner_html',     "
183                 "                            { method: 'get', frequency: 30 }  );       "
184                 "</script>                                                              \n"
185         );
186         wDumpContent(1);
187 }
188
189 /**
190  * \brief end session \todo what??? does this belong here? 
191  */
192 void terminate_session(void)
193 {
194         char buf[SIZ];
195
196         serv_printf("TERM %s", bstr("which_session"));
197         serv_getln(buf, sizeof buf);
198         who();
199 }
200
201
202 /**
203  * \brief Change your session info (fake roomname and hostname)
204  */
205 void edit_me(void)
206 {
207         char buf[SIZ];
208
209         if (!IsEmptyStr(bstr("change_room_name_button"))) {
210                 serv_printf("RCHG %s", bstr("fake_roomname"));
211                 serv_getln(buf, sizeof buf);
212                 http_redirect("who");
213         } else if (!IsEmptyStr(bstr("change_host_name_button"))) {
214                 serv_printf("HCHG %s", bstr("fake_hostname"));
215                 serv_getln(buf, sizeof buf);
216                 http_redirect("who");
217         } else if (!IsEmptyStr(bstr("change_user_name_button"))) {
218                 serv_printf("UCHG %s", bstr("fake_username"));
219                 serv_getln(buf, sizeof buf);
220                 http_redirect("who");
221         } else if (!IsEmptyStr(bstr("cancel_button"))) {
222                 http_redirect("who");
223         } else {
224                 output_headers(1, 1, 0, 0, 0, 0);
225
226                 wprintf("<div id=\"banner\">\n");
227                 wprintf("<table class=\"who_banner\"><tr><td>");
228                 wprintf("<span class=\"titlebar\">");
229                 wprintf(_("Edit your session display"));
230                 wprintf("</span></td></tr></table>\n");
231                 wprintf("</div>\n<div id=\"content\">\n");
232
233                 wprintf(_("This screen allows you to change the way your "
234                         "session appears in the 'Who is online' listing. "
235                         "To turn off any 'fake' name you've previously "
236                         "set, simply click the appropriate 'change' button "
237                         "without typing anything in the corresponding box. "));
238                 wprintf("<br />\n");
239
240                 wprintf("<form method=\"POST\" action=\"edit_me\">\n");
241                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
242
243                 wprintf("<table border=0 width=100%%>\n");
244
245                 wprintf("<tr><td><b>");
246                 wprintf(_("Room name:"));
247                 wprintf("</b></td>\n<td>");
248                 wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
249                 wprintf("</td>\n<td align=center>");
250                 wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
251                         _("Change room name"));
252                 wprintf("</td>\n</tr>\n");
253
254                 wprintf("<tr><td><b>");
255                 wprintf(_("Host name:"));
256                 wprintf("</b></td><td>");
257                 wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
258                 wprintf("</td>\n<td align=center>");
259                 wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
260                         _("Change host name"));
261                 wprintf("</td>\n</tr>\n");
262
263                 if (WC->is_aide) {
264                         wprintf("<tr><td><b>");
265                         wprintf(_("User name:"));
266                         wprintf("</b></td><td>");
267                         wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
268                         wprintf("</td>\n<td align=center>");
269                         wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
270                                 _("Change user name"));
271                         wprintf("</td>\n</tr>\n");
272                 }
273                 wprintf("<tr><td> </td><td> </td><td align=center>");
274                 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
275                         _("Cancel"));
276                 wprintf("</td></tr></table>\n");
277                 wprintf("</form></center>\n");
278                 wDumpContent(1);
279         }
280 }
281
282
283 /*@}*/