7 typedef struct UserStateStruct {
24 void DestroyUserStruct(void *vUser)
26 UserStateStruct *User = (UserStateStruct*) vUser;
35 int CompareUserStruct(const void *VUser1, const void *VUser2)
37 const UserStateStruct *User1 = (UserStateStruct*) GetSearchPayload(VUser1);
38 const UserStateStruct *User2 = (UserStateStruct*) GetSearchPayload(VUser2);
40 if (User1->Idle != User2->Idle)
41 return User1->Idle > User2->Idle;
42 return strcasecmp(User1->UserName, User2->UserName);
46 int GetWholistSection(HashList *List, time_t now)
48 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
49 UserStateStruct *User, *OldUser;
51 char buf[SIZ], user[SIZ], room[SIZ], host[SIZ],
52 realroom[SIZ], realhost[SIZ];
56 serv_getln(buf, sizeof buf);
58 while (BufLen = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
61 User = (UserStateStruct*) malloc(sizeof(UserStateStruct));
62 User->Session = extract_int(buf, 0);
64 User->UserNameLen = extract_token(user, buf, 1, '|', sizeof user);
65 User->UserName = malloc(User->UserNameLen + 1);
66 memcpy(User->UserName, user, User->UserNameLen + 1);
68 User->RoomLen = extract_token(room, buf, 2, '|', sizeof room);
69 User->Room = malloc(User->RoomLen + 1);
70 memcpy(User->Room, room, User->RoomLen + 1);
72 User->HostLen = extract_token(host, buf, 3, '|', sizeof host);
73 User->Host = malloc(User->HostLen + 1);
74 memcpy(User->Host, host, User->HostLen + 1);
76 User->RealRoomLen = extract_token(realroom, buf, 9, '|', sizeof realroom);
77 User->RealRoom = malloc(User->RealRoomLen + 1);
78 memcpy(User->RealRoom, realroom, User->RealRoomLen + 1);
80 User->RealHostLen = extract_token(realhost, buf, 10, '|', sizeof realhost);
81 User->RealHost = malloc(User->RealHostLen + 1);
82 memcpy(User->RealHost, realhost, User->RealHostLen + 1);
84 User->LastActive = extract_long(buf, 5);
85 User->Idle = (now - User->LastActive) > 900L;
86 User->SessionCount = 1;
88 if (GetHash(List, User->UserName, User->UserNameLen, &VOldUser)) {
90 OldUser->SessionCount++;
92 if (User->Session == WCC->ctdl_pid)
93 OldUser->Session = User->Session;
95 OldUser->Idle = User->Idle;
96 OldUser->LastActive = User->LastActive;
98 DestroyUserStruct(User);
101 Put(List, User->UserName, User->UserNameLen, User, DestroyUserStruct);
103 SortByPayload(List, CompareUserStruct);
111 * Display inner div of Wholist
113 void who_inner_div(void) {
114 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);
143 List = NewHash(1, NULL);
145 if (GetWholistSection(List, now)) {
146 it = GetNewHashPos();
147 while (GetNextHashPos(List, it, &len, &UserName, &VUser)) {
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 %ld %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>");
234 * Display a list of users currently logged in to the system
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 } ); "
299 void terminate_session(void)
303 serv_printf("TERM %s", bstr("which_session"));
304 serv_getln(buf, sizeof buf);
310 * Change your session info (fake roomname and hostname)
316 if (havebstr("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 (havebstr("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 (havebstr("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 (havebstr("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=\"%d\">\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");
392 void wholist_section(void) {
393 UserStateStruct *User;
403 serv_getln(buf, sizeof buf);
405 now = extract_long(&buf[4], 0);
411 List = NewHash(1, NULL);
413 if (GetWholistSection(List, now)) {
414 SortByPayload(List, CompareUserStruct);
415 it = GetNewHashPos();
416 while (GetNextHashPos(List, it, &len, &UserName, &VUser)) {
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>");