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;
55 char buf[SIZ], user[SIZ], room[SIZ], host[SIZ],
56 realroom[SIZ], realhost[SIZ];
60 serv_getln(buf, sizeof buf);
62 while (BufLen = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
63 User = (UserStateStruct*) malloc(sizeof(UserStateStruct));
64 User->Session = extract_int(buf, 0);
66 User->UserNameLen = extract_token(user, buf, 1, '|', sizeof user);
67 User->UserName = malloc(User->UserNameLen + 1);
68 memcpy(User->UserName, user, User->UserNameLen + 1);
70 User->RoomLen = extract_token(room, buf, 2, '|', sizeof room);
71 User->Room = malloc(User->RoomLen + 1);
72 memcpy(User->Room, room, User->RoomLen + 1);
74 User->HostLen = extract_token(host, buf, 3, '|', sizeof host);
75 User->Host = malloc(User->HostLen + 1);
76 memcpy(User->Host, host, User->HostLen + 1);
78 User->RealRoomLen = extract_token(realroom, buf, 9, '|', sizeof realroom);
79 User->RealRoom = malloc(User->RealRoomLen + 1);
80 memcpy(User->RealRoom, realroom, User->RealRoomLen + 1);
82 User->RealHostLen = extract_token(realhost, buf, 10, '|', sizeof realhost);
83 User->RealHost = malloc(User->RealHostLen + 1);
84 memcpy(User->RealHost, realhost, User->RealHostLen + 1);
86 User->LastActive = extract_long(buf, 5);
87 User->Idle = (now - User->LastActive) > 900L;
88 User->SessionCount = 1;
90 if (GetHash(List, User->UserName, User->UserNameLen, (void**)&OldUser)) {
91 OldUser->SessionCount++;
93 if (User->Session == WCC->ctdl_pid)
94 OldUser->Session = User->Session;
96 OldUser->Idle = User->Idle;
97 OldUser->LastActive = User->LastActive;
99 DestroyUserStruct(User);
102 Put(List, User->UserName, User->UserNameLen, User, DestroyUserStruct);
104 SortByPayload(List, CompareUserStruct);
112 * \brief Display inner div of Wholist
114 void who_inner_div(void) {
115 UserStateStruct *User;
117 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
125 wprintf("<table class=\"altern\">"
127 wprintf("<th class=\"edit_col\"> </th>\n");
128 wprintf("<th colspan=\"2\"> </th>\n");
129 wprintf("<th>%s</th>\n", _("User name"));
130 wprintf("<th>%s</th>", _("Room"));
131 wprintf("<th class=\"host_col\">%s</th>\n</tr>\n", _("From host"));
134 serv_getln(buf, sizeof buf);
137 now = extract_long(&buf[4], 0);
145 if (GetWholistSection(List, now)) {
146 it = GetNewHashPos();
147 while (GetNextHashPos(List, it, &len, &UserName, (void**)&User)) {
150 wprintf("<tr class=\"%s\">",
151 (bg ? "even" : "odd")
155 wprintf("<td class=\"edit_col\">");
156 if ((WCC->is_aide) &&
157 (User->Session != WCC->ctdl_pid)) {
158 wprintf(" <a href=\"terminate_session?which_session=%d", User->Session);
159 wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
161 if (User->Session == WCC->ctdl_pid) {
162 wprintf(" <a href=\"edit_me\">%s</a>", _("(edit)"));
166 /** (link to page this user) */
167 wprintf("<td width=\"5%\"><a href=\"display_page?recp=");
168 urlescputs(User->UserName);
170 "<img align=\"middle\" "
171 "src=\"static/citadelchat_24x.gif\" "
173 " border=\"0\" /></a> ");
177 wprintf("<td width=\"5%\">");
180 "<img align=\"middle\" "
181 "src=\"static/inactiveuser_24x.gif\" "
182 "alt=\"(%s %d %s)\" border=\"0\" />",
184 (now - User->LastActive) / 60,
191 "<img align=\"middle\" "
192 "src=\"static/activeuser_24x.gif\" "
193 "alt=\"(active)\" border=\"0\" />");
195 wprintf("</td>\n<td>");
197 /** username (link to user bio/photo page) */
198 wprintf("<a href=\"showuser?who=");
199 urlescputs(User->UserName);
201 escputs(User->UserName);
202 if (User->SessionCount > 1)
203 wprintf(" [%d] ", User->SessionCount);
207 wprintf("</td>\n\t<td>");
209 if (!IsEmptyStr(User->RealRoom) ) {
210 wprintf("<br /><i>");
211 escputs(User->RealRoom);
214 wprintf("</td>\n\t<td class=\"host_col\">");
218 if (!IsEmptyStr(User->RealHost)) {
219 wprintf("<br /><i>");
220 escputs(User->RealHost);
223 wprintf("</td>\n</tr>");
240 output_headers(1, 1, 2, 0, 0, 0);
242 wprintf("<script type=\"text/javascript\">\n"
243 "function ConfirmKill() { \n"
244 "return confirm('%s');\n"
246 "</script>\n", _("Do you really want to kill this session?")
249 wprintf("<div id=\"banner\">\n");
250 wprintf("<div class=\"room_banner\">");
251 wprintf("<img src=\"static/usermanag_48x.gif\">");
253 snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
255 wprintf("</h1></div>");
256 wprintf("<ul class=\"room_actions\">\n");
257 wprintf("<li class=\"start_page\">");
259 wprintf("</li></ul>");
262 wprintf("<div id=\"content\" class=\"fix_scrollbar_bug who_is_online\">\n");
263 wprintf("<div class=\"box\">");
264 wprintf("<div class=\"boxlabel\">");
265 snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
268 wprintf("<div class=\"boxcontent\">");
269 wprintf("<div id=\"who_inner\" >");
273 wprintf("<div class=\"instructions\">");
274 wprintf(_("Click on a name to read user info. Click on %s "
275 "to send an instant message to that user."),
276 "<img align=\"middle\" src=\"static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
278 wprintf("</div></div>\n");
281 * JavaScript to make the ajax refresh happen:
282 * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater
283 * It wants: 1. The div being updated
284 * 2. The URL of the update source
285 * 3. Other flags (such as the HTTP method and the refresh frequency)
288 "<script type=\"text/javascript\"> "
289 " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html', "
290 " { method: 'get', frequency: 30 } ); "
297 * \brief end session \todo what??? does this belong here?
299 void terminate_session(void)
303 serv_printf("TERM %s", bstr("which_session"));
304 serv_getln(buf, sizeof buf);
310 * \brief Change your session info (fake roomname and hostname)
316 if (!IsEmptyStr(bstr("change_room_name_button"))) {
317 serv_printf("RCHG %s", bstr("fake_roomname"));
318 serv_getln(buf, sizeof buf);
319 http_redirect("who");
320 } else if (!IsEmptyStr(bstr("change_host_name_button"))) {
321 serv_printf("HCHG %s", bstr("fake_hostname"));
322 serv_getln(buf, sizeof buf);
323 http_redirect("who");
324 } else if (!IsEmptyStr(bstr("change_user_name_button"))) {
325 serv_printf("UCHG %s", bstr("fake_username"));
326 serv_getln(buf, sizeof buf);
327 http_redirect("who");
328 } else if (!IsEmptyStr(bstr("cancel_button"))) {
329 http_redirect("who");
331 output_headers(1, 1, 0, 0, 0, 0);
333 wprintf("<div id=\"banner\">\n");
334 wprintf("<table class=\"who_banner\"><tr><td>");
335 wprintf("<span class=\"titlebar\">");
336 wprintf(_("Edit your session display"));
337 wprintf("</span></td></tr></table>\n");
338 wprintf("</div>\n<div id=\"content\">\n");
340 wprintf(_("This screen allows you to change the way your "
341 "session appears in the 'Who is online' listing. "
342 "To turn off any 'fake' name you've previously "
343 "set, simply click the appropriate 'change' button "
344 "without typing anything in the corresponding box. "));
347 wprintf("<form method=\"POST\" action=\"edit_me\">\n");
348 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
350 wprintf("<table border=0 width=100%%>\n");
352 wprintf("<tr><td><b>");
353 wprintf(_("Room name:"));
354 wprintf("</b></td>\n<td>");
355 wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
356 wprintf("</td>\n<td align=center>");
357 wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
358 _("Change room name"));
359 wprintf("</td>\n</tr>\n");
361 wprintf("<tr><td><b>");
362 wprintf(_("Host name:"));
363 wprintf("</b></td><td>");
364 wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
365 wprintf("</td>\n<td align=center>");
366 wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
367 _("Change host name"));
368 wprintf("</td>\n</tr>\n");
371 wprintf("<tr><td><b>");
372 wprintf(_("User name:"));
373 wprintf("</b></td><td>");
374 wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
375 wprintf("</td>\n<td align=center>");
376 wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
377 _("Change user name"));
378 wprintf("</td>\n</tr>\n");
380 wprintf("<tr><td> </td><td> </td><td align=center>");
381 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
383 wprintf("</td></tr></table>\n");
384 wprintf("</form></center>\n");
390 * \brief Wholist section
392 void wholist_section(void) {
393 UserStateStruct *User;
402 serv_getln(buf, sizeof buf);
404 now = extract_long(&buf[4], 0);
412 if (GetWholistSection(List, now)) {
413 SortByPayload(List, CompareUserStruct);
414 it = GetNewHashPos();
415 while (GetNextHashPos(List, it, &len, &UserName, (void**)&User)) {
416 if (strcmp(User->UserName, NLI)) {
417 wprintf("<li class=\"");
419 wprintf("inactiveuser");
422 wprintf("activeuser");
424 wprintf("\"><a href=\"showuser?who=");
425 urlescputs(User->UserName);
427 escputs(User->UserName);
428 wprintf("</a></li>");