5 * \defgroup DislpayWho Display a list of all users currently logged on to the Citadel server.
6 * \ingroup WebcitDisplayItems
12 typedef struct UserStateStruct {
29 void DestroyUserStruct(void *vUser)
31 UserStateStruct *User = (UserStateStruct*) vUser;
40 int CompareUserStruct(const void *VUser1, const void *VUser2)
42 const UserStateStruct *User1 = (UserStateStruct*) GetSearchPayload(VUser1);
43 const UserStateStruct *User2 = (UserStateStruct*) GetSearchPayload(VUser2);
45 if (User1->Idle != User2->Idle)
46 return User1->Idle > User2->Idle;
47 return strcasecmp(User1->UserName, User2->UserName);
51 int GetWholistSection(HashList *List, time_t now)
53 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
54 UserStateStruct *User, *OldUser;
56 char buf[SIZ], user[SIZ], room[SIZ], host[SIZ],
57 realroom[SIZ], realhost[SIZ];
61 serv_getln(buf, sizeof buf);
63 while (BufLen = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
66 User = (UserStateStruct*) malloc(sizeof(UserStateStruct));
67 User->Session = extract_int(buf, 0);
69 User->UserNameLen = extract_token(user, buf, 1, '|', sizeof user);
70 User->UserName = malloc(User->UserNameLen + 1);
71 memcpy(User->UserName, user, User->UserNameLen + 1);
73 User->RoomLen = extract_token(room, buf, 2, '|', sizeof room);
74 User->Room = malloc(User->RoomLen + 1);
75 memcpy(User->Room, room, User->RoomLen + 1);
77 User->HostLen = extract_token(host, buf, 3, '|', sizeof host);
78 User->Host = malloc(User->HostLen + 1);
79 memcpy(User->Host, host, User->HostLen + 1);
81 User->RealRoomLen = extract_token(realroom, buf, 9, '|', sizeof realroom);
82 User->RealRoom = malloc(User->RealRoomLen + 1);
83 memcpy(User->RealRoom, realroom, User->RealRoomLen + 1);
85 User->RealHostLen = extract_token(realhost, buf, 10, '|', sizeof realhost);
86 User->RealHost = malloc(User->RealHostLen + 1);
87 memcpy(User->RealHost, realhost, User->RealHostLen + 1);
89 User->LastActive = extract_long(buf, 5);
90 User->Idle = (now - User->LastActive) > 900L;
91 User->SessionCount = 1;
93 if (GetHash(List, User->UserName, User->UserNameLen, &VOldUser)) {
95 OldUser->SessionCount++;
97 if (User->Session == WCC->ctdl_pid)
98 OldUser->Session = User->Session;
100 OldUser->Idle = User->Idle;
101 OldUser->LastActive = User->LastActive;
103 DestroyUserStruct(User);
106 Put(List, User->UserName, User->UserNameLen, User, DestroyUserStruct);
108 SortByPayload(List, CompareUserStruct);
116 * \brief Display inner div of Wholist
118 void who_inner_div(void) {
119 UserStateStruct *User;
122 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
130 wprintf("<table class=\"altern\">"
132 wprintf("<th class=\"edit_col\"> </th>\n");
133 wprintf("<th colspan=\"2\"> </th>\n");
134 wprintf("<th>%s</th>\n", _("User name"));
135 wprintf("<th>%s</th>", _("Room"));
136 wprintf("<th class=\"host_col\">%s</th>\n</tr>\n", _("From host"));
139 serv_getln(buf, sizeof buf);
142 now = extract_long(&buf[4], 0);
150 if (GetWholistSection(List, now)) {
151 it = GetNewHashPos();
152 while (GetNextHashPos(List, it, &len, &UserName, &VUser)) {
155 wprintf("<tr class=\"%s\">",
156 (bg ? "even" : "odd")
160 wprintf("<td class=\"edit_col\">");
161 if ((WCC->is_aide) &&
162 (User->Session != WCC->ctdl_pid)) {
163 wprintf(" <a href=\"terminate_session?which_session=%d", User->Session);
164 wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
166 if (User->Session == WCC->ctdl_pid) {
167 wprintf(" <a href=\"edit_me\">%s</a>", _("(edit)"));
171 /** (link to page this user) */
172 wprintf("<td width=\"5%\"><a href=\"display_page?recp=");
173 urlescputs(User->UserName);
175 "<img align=\"middle\" "
176 "src=\"static/citadelchat_24x.gif\" "
178 " border=\"0\" /></a> ");
182 wprintf("<td width=\"5%\">");
185 "<img align=\"middle\" "
186 "src=\"static/inactiveuser_24x.gif\" "
187 "alt=\"(%s %d %s)\" border=\"0\" />",
189 (now - User->LastActive) / 60,
196 "<img align=\"middle\" "
197 "src=\"static/activeuser_24x.gif\" "
198 "alt=\"(active)\" border=\"0\" />");
200 wprintf("</td>\n<td>");
202 /** username (link to user bio/photo page) */
203 wprintf("<a href=\"showuser?who=");
204 urlescputs(User->UserName);
206 escputs(User->UserName);
207 if (User->SessionCount > 1)
208 wprintf(" [%d] ", User->SessionCount);
212 wprintf("</td>\n\t<td>");
214 if (!IsEmptyStr(User->RealRoom) ) {
215 wprintf("<br /><i>");
216 escputs(User->RealRoom);
219 wprintf("</td>\n\t<td class=\"host_col\">");
223 if (!IsEmptyStr(User->RealHost)) {
224 wprintf("<br /><i>");
225 escputs(User->RealHost);
228 wprintf("</td>\n</tr>");
245 output_headers(1, 1, 2, 0, 0, 0);
247 wprintf("<script type=\"text/javascript\">\n"
248 "function ConfirmKill() { \n"
249 "return confirm('%s');\n"
251 "</script>\n", _("Do you really want to kill this session?")
254 wprintf("<div id=\"banner\">\n");
255 wprintf("<div class=\"room_banner\">");
256 wprintf("<img src=\"static/usermanag_48x.gif\">");
258 snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
260 wprintf("</h1></div>");
261 wprintf("<ul class=\"room_actions\">\n");
262 wprintf("<li class=\"start_page\">");
264 wprintf("</li></ul>");
267 wprintf("<div id=\"content\" class=\"fix_scrollbar_bug who_is_online\">\n");
268 wprintf("<div class=\"box\">");
269 wprintf("<div class=\"boxlabel\">");
270 snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
273 wprintf("<div class=\"boxcontent\">");
274 wprintf("<div id=\"who_inner\" >");
278 wprintf("<div class=\"instructions\">");
279 wprintf(_("Click on a name to read user info. Click on %s "
280 "to send an instant message to that user."),
281 "<img align=\"middle\" src=\"static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
283 wprintf("</div></div>\n");
286 * JavaScript to make the ajax refresh happen:
287 * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater
288 * It wants: 1. The div being updated
289 * 2. The URL of the update source
290 * 3. Other flags (such as the HTTP method and the refresh frequency)
293 "<script type=\"text/javascript\"> "
294 " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html', "
295 " { method: 'get', frequency: 30 } ); "
302 * \brief end session \todo what??? does this belong here?
304 void terminate_session(void)
308 serv_printf("TERM %s", bstr("which_session"));
309 serv_getln(buf, sizeof buf);
315 * \brief Change your session info (fake roomname and hostname)
321 if (havebstr("change_room_name_button")) {
322 serv_printf("RCHG %s", bstr("fake_roomname"));
323 serv_getln(buf, sizeof buf);
324 http_redirect("who");
325 } else if (havebstr("change_host_name_button")) {
326 serv_printf("HCHG %s", bstr("fake_hostname"));
327 serv_getln(buf, sizeof buf);
328 http_redirect("who");
329 } else if (havebstr("change_user_name_button")) {
330 serv_printf("UCHG %s", bstr("fake_username"));
331 serv_getln(buf, sizeof buf);
332 http_redirect("who");
333 } else if (havebstr("cancel_button")) {
334 http_redirect("who");
336 output_headers(1, 1, 0, 0, 0, 0);
338 wprintf("<div id=\"banner\">\n");
339 wprintf("<table class=\"who_banner\"><tr><td>");
340 wprintf("<span class=\"titlebar\">");
341 wprintf(_("Edit your session display"));
342 wprintf("</span></td></tr></table>\n");
343 wprintf("</div>\n<div id=\"content\">\n");
345 wprintf(_("This screen allows you to change the way your "
346 "session appears in the 'Who is online' listing. "
347 "To turn off any 'fake' name you've previously "
348 "set, simply click the appropriate 'change' button "
349 "without typing anything in the corresponding box. "));
352 wprintf("<form method=\"POST\" action=\"edit_me\">\n");
353 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
355 wprintf("<table border=0 width=100%%>\n");
357 wprintf("<tr><td><b>");
358 wprintf(_("Room name:"));
359 wprintf("</b></td>\n<td>");
360 wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
361 wprintf("</td>\n<td align=center>");
362 wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
363 _("Change room name"));
364 wprintf("</td>\n</tr>\n");
366 wprintf("<tr><td><b>");
367 wprintf(_("Host name:"));
368 wprintf("</b></td><td>");
369 wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
370 wprintf("</td>\n<td align=center>");
371 wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
372 _("Change host name"));
373 wprintf("</td>\n</tr>\n");
376 wprintf("<tr><td><b>");
377 wprintf(_("User name:"));
378 wprintf("</b></td><td>");
379 wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
380 wprintf("</td>\n<td align=center>");
381 wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
382 _("Change user name"));
383 wprintf("</td>\n</tr>\n");
385 wprintf("<tr><td> </td><td> </td><td align=center>");
386 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
388 wprintf("</td></tr></table>\n");
389 wprintf("</form></center>\n");
395 * \brief Wholist section
397 void wholist_section(void) {
398 UserStateStruct *User;
408 serv_getln(buf, sizeof buf);
410 now = extract_long(&buf[4], 0);
418 if (GetWholistSection(List, now)) {
419 SortByPayload(List, CompareUserStruct);
420 it = GetNewHashPos();
421 while (GetNextHashPos(List, it, &len, &UserName, &VUser)) {
423 if (strcmp(User->UserName, NLI)) {
424 wprintf("<li class=\"");
426 wprintf("inactiveuser");
429 wprintf("activeuser");
431 wprintf("\"><a href=\"showuser?who=");
432 urlescputs(User->UserName);
434 escputs(User->UserName);
435 wprintf("</a></li>");