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")) {
65 User = (UserStateStruct*) malloc(sizeof(UserStateStruct));
66 User->Session = extract_int(buf, 0);
68 User->UserNameLen = extract_token(user, buf, 1, '|', sizeof user);
69 User->UserName = malloc(User->UserNameLen + 1);
70 memcpy(User->UserName, user, User->UserNameLen + 1);
72 User->RoomLen = extract_token(room, buf, 2, '|', sizeof room);
73 User->Room = malloc(User->RoomLen + 1);
74 memcpy(User->Room, room, User->RoomLen + 1);
76 User->HostLen = extract_token(host, buf, 3, '|', sizeof host);
77 User->Host = malloc(User->HostLen + 1);
78 memcpy(User->Host, host, User->HostLen + 1);
80 User->RealRoomLen = extract_token(realroom, buf, 9, '|', sizeof realroom);
81 User->RealRoom = malloc(User->RealRoomLen + 1);
82 memcpy(User->RealRoom, realroom, User->RealRoomLen + 1);
84 User->RealHostLen = extract_token(realhost, buf, 10, '|', sizeof realhost);
85 User->RealHost = malloc(User->RealHostLen + 1);
86 memcpy(User->RealHost, realhost, User->RealHostLen + 1);
88 User->LastActive = extract_long(buf, 5);
89 User->Idle = (now - User->LastActive) > 900L;
90 User->SessionCount = 1;
92 if (GetHash(List, User->UserName, User->UserNameLen, (void**)&OldUser)) {
93 OldUser->SessionCount++;
95 if (User->Session == WCC->ctdl_pid)
96 OldUser->Session = User->Session;
98 OldUser->Idle = User->Idle;
99 OldUser->LastActive = User->LastActive;
101 DestroyUserStruct(User);
104 Put(List, User->UserName, User->UserNameLen, User, DestroyUserStruct);
106 SortByPayload(List, CompareUserStruct);
114 * \brief Display inner div of Wholist
116 void who_inner_div(void) {
117 UserStateStruct *User;
119 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
127 wprintf("<table class=\"altern\">"
129 wprintf("<th class=\"edit_col\"> </th>\n");
130 wprintf("<th colspan=\"2\"> </th>\n");
131 wprintf("<th>%s</th>\n", _("User name"));
132 wprintf("<th>%s</th>", _("Room"));
133 wprintf("<th class=\"host_col\">%s</th>\n</tr>\n", _("From host"));
136 serv_getln(buf, sizeof buf);
139 now = extract_long(&buf[4], 0);
147 if (GetWholistSection(List, now)) {
148 it = GetNewHashPos();
149 while (GetNextHashPos(List, it, &len, &UserName, (void**)&User)) {
152 wprintf("<tr class=\"%s\">",
153 (bg ? "even" : "odd")
157 wprintf("<td class=\"edit_col\">");
158 if ((WCC->is_aide) &&
159 (User->Session != WCC->ctdl_pid)) {
160 wprintf(" <a href=\"terminate_session?which_session=%d", User->Session);
161 wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
163 if (User->Session == WCC->ctdl_pid) {
164 wprintf(" <a href=\"edit_me\">%s</a>", _("(edit)"));
168 /** (link to page this user) */
169 wprintf("<td width=\"5%\"><a href=\"display_page?recp=");
170 urlescputs(User->UserName);
172 "<img align=\"middle\" "
173 "src=\"static/citadelchat_24x.gif\" "
175 " border=\"0\" /></a> ");
179 wprintf("<td width=\"5%\">");
182 "<img align=\"middle\" "
183 "src=\"static/inactiveuser_24x.gif\" "
184 "alt=\"(%s %d %s)\" border=\"0\" />",
186 (now - User->LastActive) / 60,
193 "<img align=\"middle\" "
194 "src=\"static/activeuser_24x.gif\" "
195 "alt=\"(active)\" border=\"0\" />");
197 wprintf("</td>\n<td>");
199 /** username (link to user bio/photo page) */
200 wprintf("<a href=\"showuser?who=");
201 urlescputs(User->UserName);
203 escputs(User->UserName);
204 if (User->SessionCount > 1)
205 wprintf(" [%d] ", User->SessionCount);
209 wprintf("</td>\n\t<td>");
211 if (!IsEmptyStr(User->RealRoom) ) {
212 wprintf("<br /><i>");
213 escputs(User->RealRoom);
216 wprintf("</td>\n\t<td class=\"host_col\">");
220 if (!IsEmptyStr(User->RealHost)) {
221 wprintf("<br /><i>");
222 escputs(User->RealHost);
225 wprintf("</td>\n</tr>");
242 output_headers(1, 1, 2, 0, 0, 0);
244 wprintf("<script type=\"text/javascript\">\n"
245 "function ConfirmKill() { \n"
246 "return confirm('%s');\n"
248 "</script>\n", _("Do you really want to kill this session?")
251 wprintf("<div id=\"banner\">\n");
252 wprintf("<div class=\"room_banner\">");
253 wprintf("<img src=\"static/usermanag_48x.gif\">");
255 snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
257 wprintf("</h1></div>");
258 wprintf("<ul class=\"room_actions\">\n");
259 wprintf("<li class=\"start_page\">");
261 wprintf("</li></ul>");
264 wprintf("<div id=\"content\" class=\"fix_scrollbar_bug who_is_online\">\n");
265 wprintf("<div class=\"box\">");
266 wprintf("<div class=\"boxlabel\">");
267 snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
270 wprintf("<div class=\"boxcontent\">");
271 wprintf("<div id=\"who_inner\" >");
275 wprintf("<div class=\"instructions\">");
276 wprintf(_("Click on a name to read user info. Click on %s "
277 "to send an instant message to that user."),
278 "<img align=\"middle\" src=\"static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
280 wprintf("</div></div>\n");
283 * JavaScript to make the ajax refresh happen:
284 * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater
285 * It wants: 1. The div being updated
286 * 2. The URL of the update source
287 * 3. Other flags (such as the HTTP method and the refresh frequency)
290 "<script type=\"text/javascript\"> "
291 " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html', "
292 " { method: 'get', frequency: 30 } ); "
299 * \brief end session \todo what??? does this belong here?
301 void terminate_session(void)
305 serv_printf("TERM %s", bstr("which_session"));
306 serv_getln(buf, sizeof buf);
312 * \brief Change your session info (fake roomname and hostname)
318 if (!IsEmptyStr(bstr("change_room_name_button"))) {
319 serv_printf("RCHG %s", bstr("fake_roomname"));
320 serv_getln(buf, sizeof buf);
321 http_redirect("who");
322 } else if (!IsEmptyStr(bstr("change_host_name_button"))) {
323 serv_printf("HCHG %s", bstr("fake_hostname"));
324 serv_getln(buf, sizeof buf);
325 http_redirect("who");
326 } else if (!IsEmptyStr(bstr("change_user_name_button"))) {
327 serv_printf("UCHG %s", bstr("fake_username"));
328 serv_getln(buf, sizeof buf);
329 http_redirect("who");
330 } else if (!IsEmptyStr(bstr("cancel_button"))) {
331 http_redirect("who");
333 output_headers(1, 1, 0, 0, 0, 0);
335 wprintf("<div id=\"banner\">\n");
336 wprintf("<table class=\"who_banner\"><tr><td>");
337 wprintf("<span class=\"titlebar\">");
338 wprintf(_("Edit your session display"));
339 wprintf("</span></td></tr></table>\n");
340 wprintf("</div>\n<div id=\"content\">\n");
342 wprintf(_("This screen allows you to change the way your "
343 "session appears in the 'Who is online' listing. "
344 "To turn off any 'fake' name you've previously "
345 "set, simply click the appropriate 'change' button "
346 "without typing anything in the corresponding box. "));
349 wprintf("<form method=\"POST\" action=\"edit_me\">\n");
350 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
352 wprintf("<table border=0 width=100%%>\n");
354 wprintf("<tr><td><b>");
355 wprintf(_("Room name:"));
356 wprintf("</b></td>\n<td>");
357 wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
358 wprintf("</td>\n<td align=center>");
359 wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
360 _("Change room name"));
361 wprintf("</td>\n</tr>\n");
363 wprintf("<tr><td><b>");
364 wprintf(_("Host name:"));
365 wprintf("</b></td><td>");
366 wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
367 wprintf("</td>\n<td align=center>");
368 wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
369 _("Change host name"));
370 wprintf("</td>\n</tr>\n");
373 wprintf("<tr><td><b>");
374 wprintf(_("User name:"));
375 wprintf("</b></td><td>");
376 wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
377 wprintf("</td>\n<td align=center>");
378 wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
379 _("Change user name"));
380 wprintf("</td>\n</tr>\n");
382 wprintf("<tr><td> </td><td> </td><td align=center>");
383 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
385 wprintf("</td></tr></table>\n");
386 wprintf("</form></center>\n");
392 * \brief Wholist section
394 void wholist_section(void) {
395 UserStateStruct *User;
404 serv_getln(buf, sizeof buf);
406 now = extract_long(&buf[4], 0);
414 if (GetWholistSection(List, now)) {
415 SortByPayload(List, CompareUserStruct);
416 it = GetNewHashPos();
417 while (GetNextHashPos(List, it, &len, &UserName, (void**)&User)) {
418 if (strcmp(User->UserName, NLI)) {
419 wprintf("<li class=\"");
421 wprintf("inactiveuser");
424 wprintf("activeuser");
426 wprintf("\"><a href=\"showuser?who=");
427 urlescputs(User->UserName);
429 escputs(User->UserName);
430 wprintf("</a></li>");