X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwho.c;h=e81b911e9aa52f6bcf1b09174e494731cd5cc4d2;hb=694a3ea878536e2deda1c0168e51837a31b81af7;hp=5f8937b7a1284ecad8deb30aa328bdd840108ab9;hpb=128b2597ff8c0d205b95b54d42c0886105172e05;p=citadel.git diff --git a/webcit/who.c b/webcit/who.c index 5f8937b7a..e81b911e9 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -1,109 +1,281 @@ -/* $Id$ */ - -#include -#include -#include -#include -#include -#include -#include -#include "webcit.h" -#include "child.h" - -struct whouser { - struct whouser *next; - int sessionnum; - char username[256]; - char roomname[256]; - char hostname[256]; - char clientsoftware[256]; - }; - /* - * who is on? + * $Id$ + */ +/** + * \defgroup DislpayWho Display a list of all users currently logged on to the Citadel server. + * \ingroup WebcitDisplayItems */ -void whobbs(void) { - struct whouser *wlist = NULL; - struct whouser *wptr = NULL; - char buf[256],sess,user[256],room[256],host[256]; - int foundit; +/*@{*/ +#include "webcit.h" - printf("HTTP/1.0 200 OK\n"); - output_headers(); - wprintf("Who is online?\n"); - /* Uncomment this line to cause the wholist to auto-refresh */ - /* wprintf("\n"); */ - wprintf("\n"); +/** + * \brief Display inner div of Wholist + */ +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; + + wprintf("" + "\n"); + wprintf("\n"); + wprintf("\n", _("User name")); + wprintf("", _("Room")); + wprintf("\n\n", _("From host")); - wprintf("
%s%s%s
"); - wprintf("Users currently on "); - escputs(serv_info.serv_humannode); - 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("
"); - wprintf(""); - wprintf("\n"); serv_puts("RWHO"); - serv_gets(buf); - if (buf[0]=='1') { - while(serv_gets(buf), strcmp(buf,"000")) { + serv_getln(buf, sizeof buf); + if (buf[0] == '1') { + 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); - - foundit = 0; - for (wptr = wlist; wptr != NULL; wptr = wptr -> next) { - if (wptr->sessionnum == sess) { - foundit = 1; - if (strcasecmp(user, wptr->username)) { - sprintf(buf, "%cBR%c%s", - LB, RB, user); - strcat(wptr->username, buf); - } - if (strcasecmp(room, wptr->roomname)) { - sprintf(buf, "%cBR%c%s", - LB, RB, room); - strcat(wptr->roomname, buf); - } - if (strcasecmp(host, wptr->hostname)) { - sprintf(buf, "%cBR%c%s", - LB, RB, host); - strcat(wptr->hostname, buf); - } - } - } - - if (foundit == 0) { - wptr = (struct whouser *) - malloc(sizeof(struct whouser)); - wptr->next = wlist; - wlist = wptr; - strcpy(wlist->username, user); - strcpy(wlist->roomname, room); - strcpy(wlist->hostname, host); - wlist->sessionnum = sess; - } + 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(""); + + /** (link to page this user) */ + wprintf(""); + + /** (idle flag) */ + wprintf("\n\n\t\n\t\n"); - wptr = wlist->next; - free(wlist); - wlist = wptr; + /** hostname */ + escputs(host); + if (strlen(realhost) > 0) { + wprintf("
"); + escputs(realhost); + wprintf(""); } + wprintf("\n"); + } + } + wprintf("
Session IDUser NameRoomFrom host
"); + if ((WC->is_aide) && + (sess != WC->ctdl_pid)) { + wprintf(" %s", _("(kill)")); + } + if (sess == WC->ctdl_pid) { + wprintf(" %s", _("(edit)")); + } + wprintf("" + " "); + wprintf(""); + if ((now - last_activity) > 900L) { + wprintf(" " + ""); + } + else { + wprintf(" " + ""); + } + wprintf(""); + + + + /** username (link to user bio/photo page) */ + wprintf(""); + escputs(user); + wprintf(""); + + /** room */ + wprintf(""); + escputs(room); + if (strlen(realroom) > 0) { + wprintf("
"); + escputs(realroom); + wprintf(""); } + wprintf("
"); - while (wlist != NULL) { - wprintf("
%d", wlist->sessionnum); - escputs(wlist->username); - wprintf(""); - escputs(wlist->roomname); - wprintf(""); - escputs(wlist->hostname); - wprintf("
"); +} + + +/** + * \brief who is on? + */ +void who(void) +{ + char title[256]; + + output_headers(1, 1, 2, 0, 0, 0); + + wprintf("\n", _("Do you really want to kill this session?") + ); + + wprintf("
\n"); + wprintf("
"); + wprintf("\""); + wprintf(" "); + + snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode); + escputs(title); + + wprintf(""); + offer_start_page(); + wprintf("
\n"); + wprintf("
\n"); + + wprintf("
\n"); + + wprintf("
"); + who_inner_div(); + wprintf("
\n"); + + wprintf("
"); + wprintf(_("Click on a name to read user info. Click on %s " + "to send an instant message to that user."), + "\"(p)\"" + ); + wprintf("
\n"); + + /** + * JavaScript to make the ajax refresh happen: + * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater + * It wants: 1. The div being updated + * 2. The URL of the update source + * 3. Other flags (such as the HTTP method and the refresh frequency) + */ + wprintf( + " \n" + ); + wDumpContent(1); +} + +/** + * \brief end session \todo what??? does this belong here? + */ +void terminate_session(void) +{ + char buf[SIZ]; + + serv_printf("TERM %s", bstr("which_session")); + serv_getln(buf, sizeof buf); + who(); +} + + +/** + * \brief Change your session info (fake roomname and hostname) + */ +void edit_me(void) +{ + char buf[SIZ]; + + if (strlen(bstr("change_room_name_button")) > 0) { + serv_printf("RCHG %s", bstr("fake_roomname")); + serv_getln(buf, sizeof buf); + http_redirect("who"); + } else if (strlen(bstr("change_host_name_button")) > 0) { + serv_printf("HCHG %s", bstr("fake_hostname")); + serv_getln(buf, sizeof buf); + http_redirect("who"); + } else if (strlen(bstr("change_user_name_button")) > 0) { + serv_printf("UCHG %s", bstr("fake_username")); + serv_getln(buf, sizeof buf); + http_redirect("who"); + } else if (strlen(bstr("cancel_button")) > 0) { + http_redirect("who"); + } else { + output_headers(1, 1, 0, 0, 0, 0); + + wprintf("
\n"); + wprintf("
"); + wprintf(""); + wprintf(_("Edit your session display")); + wprintf("
\n"); + wprintf("
\n
\n"); + + wprintf(_("This screen allows you to change the way your " + "session appears in the 'Who is online' listing. " + "To turn off any 'fake' name you've previously " + "set, simply click the appropriate 'change' button " + "without typing anything in the corresponding box. ")); + wprintf("
\n"); + + wprintf("
\n"); + + wprintf("\n"); + + wprintf("\n\n\n\n"); + + wprintf("\n\n\n"); + + if (WC->is_aide) { + wprintf("\n\n\n"); } - wprintf("
"); + wprintf(_("Room name:")); + wprintf(""); + wprintf("\n"); + wprintf(""); + wprintf("", + _("Change room name")); + wprintf("
"); + wprintf(_("Host name:")); + wprintf(""); + wprintf("\n"); + wprintf(""); + wprintf("", + _("Change host name")); + wprintf("
"); + wprintf(_("User name:")); + wprintf(""); + wprintf("\n"); + wprintf(""); + wprintf("", + _("Change user name")); + wprintf("
\n"); - wprintf("\n"); - wDumpContent(); + wprintf(" "); + wprintf("", + _("Cancel")); + wprintf("\n"); + wprintf("\n"); + wDumpContent(1); } +} +/*@}*/