X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwho.c;h=62b84388db34a02c07981f5dbc796cfbc7a31198;hb=aa8ca3b0af3efdabd8559b886efb3164319bdce1;hp=a1b2ca13b538a3c8629a4ade68eec20dde1b9310;hpb=a1b04c57eca8827bf0ef3875265a6a356107091e;p=citadel.git diff --git a/webcit/who.c b/webcit/who.c index a1b2ca13b..62b84388d 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -1,127 +1,219 @@ -/* $Id$ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "webcit.h" - - +/* + * $Id$ + * + * Display a list of all users currently logged on to the Citadel server. + */ +#include "webcit.h" /* - * who is on? + * Display inner div of Wholist */ -void whobbs(void) -{ - char buf[SIZ], sess, user[SIZ], room[SIZ], host[SIZ], +void who_inner_div(void) { + char buf[SIZ], user[SIZ], room[SIZ], host[SIZ], realroom[SIZ], realhost[SIZ]; + int sess; + time_t last_activity; + time_t now; + int bg = 0; - output_headers(7); + wprintf("" + "\n"); + wprintf("\n"); + wprintf("\n"); + wprintf(""); + wprintf("\n\n"); - wprintf("\n" - ); - - wprintf("
User NameRoomFrom host
"); - wprintf("\""); - wprintf("  Users currently on "); - escputs(serv_info.serv_humannode); - wprintf(""); - offer_start_page(); - wprintf("
\n"); + serv_puts("TIME"); + serv_getln(buf, sizeof buf); + if (buf[0] == '2') { + now = extract_long(&buf[4], 0); + } + else { + now = time(NULL); + } - wprintf("
\n\n"); - wprintf("\n"); - wprintf("\n"); - wprintf(""); - wprintf("\n\n"); serv_puts("RWHO"); - serv_gets(buf); + serv_getln(buf, sizeof buf); if (buf[0] == '1') { - while (serv_gets(buf), strcmp(buf, "000")) { + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { sess = extract_int(buf, 0); - extract(user, buf, 1); - extract(room, buf, 2); - extract(host, buf, 3); - extract(realroom, buf, 9); - extract(realhost, buf, 10); + extract_token(user, buf, 1, '|', sizeof user); + extract_token(room, buf, 2, '|', sizeof room); + extract_token(host, buf, 3, '|', sizeof host); + extract_token(realroom, buf, 9, '|', sizeof realroom); + extract_token(realhost, buf, 10, '|', sizeof realhost); + last_activity = extract_long(buf, 5); + + bg = 1 - bg; + wprintf("", + (bg ? "DDDDDD" : "FFFFFF") + ); + - wprintf("\n\t\n\t"); /* (link to page this user) */ - wprintf("" - " "); + " "); + wprintf(""); + + /* (idle flag) */ + wprintf("\n\n\t\n\t\n\t\n\t\n"); + wprintf("\n"); } } - wprintf("
Session IDUser NameRoomFrom host
%d", sess); + wprintf(""); if ((WC->is_aide) && - (sess != serv_info.serv_pid)) { - wprintf(" ctdl_pid)) { + wprintf(" (kill)"); + ">[kill]"); } - if (sess == serv_info.serv_pid) { - wprintf(" (edit)"); + if (sess == WC->ctdl_pid) { + wprintf(" [edit]"); } - wprintf(""); + wprintf(""); + if ((now - last_activity) > 900L) { + wprintf(" " + ""); + } + else { + wprintf(" " + ""); + } + wprintf(""); + /* username (link to user bio/photo page) */ - wprintf(""); escputs(user); - wprintf(""); + wprintf(""); /* room */ - wprintf(""); + wprintf(""); escputs(room); if (strlen(realroom) > 0) { - wprintf("
"); + wprintf("
"); escputs(realroom); - wprintf(""); + wprintf("
"); } - wprintf("
"); + wprintf(""); /* hostname */ escputs(host); if (strlen(realhost) > 0) { - wprintf("
"); + wprintf("
"); escputs(realhost); - wprintf(""); + wprintf("
"); } - wprintf("
\n" + wprintf(""); +} + + +/* + * XML-encapsulated version of wholist inner html + */ +void who_inner_html(void) { + output_headers(0, 0, 0, 0, 0, 0, 0); + + wprintf("Content-type: text/xml;charset=UTF-8\r\n" + "Server: %s\r\n" + "Connection: close\r\n" + "Pragma: no-cache\r\n" + "Cache-Control: no-store\r\n", + SERVER); + begin_burst(); + + wprintf("" + "\r\n" + "\r\n" + ); + + who_inner_div(); + + wprintf("\r\n" + "\r\n" + "\r\n" + ); + + wDumpContent(0); +} + + +/* + * who is on? + */ +void who(void) +{ + /* + output_headers(1, 1, 2, 0, 1, 0, 0); old refresh30 version + */ + output_headers(1, 1, 2, 0, 0, 0, 0); + + wprintf("\n" + ); + + wprintf("
\n"); + wprintf("
"); + wprintf("\""); + /* "onLoad=\"javascript:bodyOnLoad()\" " */ + wprintf(" Users currently on "); + escputs(serv_info.serv_humannode); + wprintf(""); + offer_start_page(); + wprintf("
\n"); + wprintf("
\n"); + + wprintf("
\n"); + + wprintf("
"); + who_inner_div(); /* Actual data handled by another function */ + wprintf("
\n"); + + wprintf("
" "Click on a name to read user info. Click on " - "\"(p)\" to send " - "a page (instant message) to that user.
\n"); + "" + " to send an instant message to that user.\n"); + + /* JavaScript to make the ajax refresh happen: + * 1. Register the request 'getWholist' which calls the WebCit action 'who_inner_html' + * 2. Register the 'fix_scrollbar_bug' div as one we're interested in ajaxifying + * 3. setInterval to make the ajax refresh happen every 30 seconds. The random number + * in the request is there to prevent IE from caching the XML even though it's been + * told not to. Die, Microsoft, Die. + */ + wprintf( +" \n" +" \n" + ); + + wDumpContent(1); } @@ -131,8 +223,8 @@ void terminate_session(void) char buf[SIZ]; serv_printf("TERM %s", bstr("which_session")); - serv_gets(buf); - whobbs(); + serv_getln(buf, sizeof buf); + who(); } @@ -145,32 +237,35 @@ void edit_me(void) if (!strcasecmp(bstr("sc"), "Change room name")) { serv_printf("RCHG %s", bstr("fake_roomname")); - serv_gets(buf); - http_redirect("/whobbs"); + serv_getln(buf, sizeof buf); + http_redirect("/who"); } else if (!strcasecmp(bstr("sc"), "Change host name")) { serv_printf("HCHG %s", bstr("fake_hostname")); - serv_gets(buf); - http_redirect("/whobbs"); + serv_getln(buf, sizeof buf); + http_redirect("/who"); } else if (!strcasecmp(bstr("sc"), "Change user name")) { serv_printf("UCHG %s", bstr("fake_username")); - serv_gets(buf); - http_redirect("/whobbs"); + serv_getln(buf, sizeof buf); + http_redirect("/who"); } else if (!strcasecmp(bstr("sc"), "Cancel")) { - http_redirect("/whobbs"); + http_redirect("/who"); } else { - output_headers(3); + output_headers(1, 1, 0, 0, 0, 0, 0); - wprintf("
"); - wprintf(""); + wprintf("
\n"); + wprintf("
"); + wprintf(""); wprintf("Edit your session display"); - wprintf("
\n"); + wprintf("
\n"); + wprintf("\n
\n"); + wprintf("This screen allows you to change the way your\n"); wprintf("session appears in the 'Who is online' listing.\n"); wprintf("To turn off any 'fake' name you've previously\n"); wprintf("set, simply click the appropriate 'change' button\n"); wprintf("without typing anything in the corresponding box.\n"); - wprintf("
\n"); + wprintf("
\n"); wprintf("
\n"); @@ -195,10 +290,9 @@ void edit_me(void) wprintf(""); wprintf("\n\n"); } - wprintf("  "); + wprintf(" "); wprintf(""); wprintf("\n"); - wprintf("
\n"); wDumpContent(1); }