From: Art Cancro Date: Sat, 15 Jan 2022 20:28:54 +0000 (-0500) Subject: Simplified the logout javascript X-Git-Tag: v950~42 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=6973136f78f394893af279bb5ebb0c4a800ca129;p=citadel.git Simplified the logout javascript --- diff --git a/webcit-ng/admin_functions.c b/webcit-ng/admin_functions.c index 3be8546a8..196fe5286 100644 --- a/webcit-ng/admin_functions.c +++ b/webcit-ng/admin_functions.c @@ -1,4 +1,3 @@ -// // Admin functions // // Copyright (c) 1996-2022 by the citadel.org team diff --git a/webcit-ng/api.txt b/webcit-ng/api.txt index 64da3c2de..eacedd3e0 100644 --- a/webcit-ng/api.txt +++ b/webcit-ng/api.txt @@ -1,14 +1,15 @@ Method URL Function ------ ------------------------------ ------------------------------------- -GET /ctdl/a/landing.html Site root redirects to here +GET / Site root will redirect to a landing page GET /ctdl/r/ returns a JSON-encoded list of accessible rooms OPTIONS /ctdl/r/ROOMNAME/ returns just what you'd expect PROPFIND /ctdl/r/ROOMNAME/ Show a bunch of crap GET /ctdl/r/ROOMNAME/ Returns information about the room (name, view, etc.) in JSON format GET /ctdl/r/ROOMNAME/msgs.all JSON array of message list in room GET /ctdl/r/ROOMNAME/msgs.new JSON array of message list in room (new messages) -GET /ctdl/r/ROOMNAME/MSGNUM Retrieve the content of an individual message (FIXME: make msg headers HTTP headers) +GET /ctdl/r/ROOMNAME/MSGNUM Retrieve the content of an individual message + (Should we output RFC822 fields as HTTP headers? Decide soon...) PUT /ctdl/r/ROOMNAME/xxx DAV operation to insert a new message into a room (The returned ETag will be the new message number) GET /ctdl/r/ROOMNAME/MSGNUM/json Retrieve an individual message in a room, encapsulated in JSON @@ -16,3 +17,5 @@ GET /ctdl/c/info Returns a JSON representation of the output of an INFO serve POST /ctdl/a/login Send it a your credentials and it will log you in GET /ctdl/a/whoami GET /ctdl/u/USERNAME/userpic Returns an image containing the photo/avatar of the specified user +GET /ctdl/s/ Static content (html, css, js, images...) +GET /.well-known/ Static content (RFC5785 compliant paths) diff --git a/webcit-ng/ctdlclient.c b/webcit-ng/ctdlclient.c index 3ef786707..00d0ca4f8 100644 --- a/webcit-ng/ctdlclient.c +++ b/webcit-ng/ctdlclient.c @@ -1,4 +1,3 @@ -// // Functions that handle communication with a Citadel Server // // Copyright (c) 1987-2022 by the citadel.org team @@ -43,8 +42,9 @@ int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes) { int len = 0; int c = 0; - if (buf == NULL) + if (buf == NULL) { return (-1); + } while (len < maxbytes) { c = read(ctdl->sock, &buf[len], 1); @@ -70,7 +70,7 @@ int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes) { // Read lines of text from the Citadel server until a 000 terminator is received. // Implemented in terms of ctdl_readline() and is therefore transparent... // Returns a newly allocated StrBuf or NULL for error. -StrBuf *ctdl_readtextmsg(struct ctdlsession * ctdl) { +StrBuf *ctdl_readtextmsg(struct ctdlsession *ctdl) { char buf[1024]; StrBuf *sj = NewStrBuf(); if (!sj) { @@ -87,7 +87,7 @@ StrBuf *ctdl_readtextmsg(struct ctdlsession * ctdl) { // Write to the Citadel server. For now we're just wrapping write() in case we // need to add anything else later. -ssize_t ctdl_write(struct ctdlsession * ctdl, const void *buf, size_t count) { +ssize_t ctdl_write(struct ctdlsession *ctdl, const void *buf, size_t count) { return write(ctdl->sock, buf, count); } @@ -135,15 +135,17 @@ int uds_connectsock(char *sockpath) { // Extract from the headers, the username and password the client is attempting to use. // This could be HTTP AUTH or it could be in the cookies. void extract_auth(struct http_transaction *h, char *authbuf, int authbuflen) { - if (authbuf == NULL) + if (authbuf == NULL) { return; - authbuf[0] = 0; + } + + memset(authbuf, 0, authbuflen); char *authheader = header_val(h, "Authorization"); if (authheader) { if (!strncasecmp(authheader, "Basic ", 6)) { safestrncpy(authbuf, &authheader[6], authbuflen); - return; // HTTP-AUTH was found -- stop here + return; // HTTP-AUTH was found -- stop here } } @@ -159,7 +161,7 @@ void extract_auth(struct http_transaction *h, char *authbuf, int authbuflen) { if (strlen(authbuf) < 3) { // impossibly small authbuf[0] = 0; } - return; // Cookie auth was found -- stop here + return; // Cookie auth was found -- stop here } } // no authorization found in headers ... this is an anonymous session @@ -228,13 +230,14 @@ struct ctdlsession *connect_to_citadel(struct http_transaction *h) { // Lock the connection pool while we claim our connection pthread_mutex_lock(&cpool_mutex); - if (cpool != NULL) + if (cpool != NULL) { for (cptr = cpool; ((cptr != NULL) && (my_session == NULL)); cptr = cptr->next) { if ((cptr->is_bound == 0) && (!strcmp(cptr->auth, auth))) { my_session = cptr; my_session->is_bound = 1; } } + } if (my_session == NULL) { syslog(LOG_DEBUG, "No qualifying sessions , starting a new one"); my_session = malloc(sizeof(struct ctdlsession)); @@ -254,7 +257,7 @@ struct ctdlsession *connect_to_citadel(struct http_transaction *h) { if (my_session->sock < 3) { is_new_session = 1; } - else { // make sure our Citadel session is still good + else { // make sure our Citadel session is still good int test_conn; test_conn = ctdl_write(my_session, HKEY("NOOP\n")); if (test_conn < 5) { diff --git a/webcit-ng/static/js/login.js b/webcit-ng/static/js/login.js index f48f964e0..ccf1936d2 100644 --- a/webcit-ng/static/js/login.js +++ b/webcit-ng/static/js/login.js @@ -11,13 +11,14 @@ // GNU General Public License for more details. +// This is where the login screen (modal) is displayed. +// It appears in the "ctdl_big_modal" div which is defined in index.html and is used for several different modals. +// If you want to change the look of the login dialog, this is where to change it. function display_login_screen(any_message) { - document.getElementById("ctdl_big_modal").innerHTML = "
" - + "
" - - + "

Put the login screen here, dummy

" + + "
" + + "

FIXME put a login banner here, dummy

" + "

" + any_message + "

" + "
" + _("User name:") + "
" @@ -25,21 +26,17 @@ function display_login_screen(any_message) { + "

" + "" + "

" - - + " " + + "" + ""; document.getElementById("ctdl_big_modal").style.display = "block"; } +// When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session. +// When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing. function logout() { - var request = new XMLHttpRequest(); - request.open("GET", "/ctdl/a/logout", true); - request.onreadystatechange = function() { - login_result(this.responseText); - }; - request.send(); - request = null; + response = await fetch("/ctdl/a/logout"); + ctdl_startup(); }