Simplified the logout javascript
authorArt Cancro <ajc@citadel.org>
Sat, 15 Jan 2022 20:28:54 +0000 (15:28 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 15 Jan 2022 20:28:54 +0000 (15:28 -0500)
webcit-ng/admin_functions.c
webcit-ng/api.txt
webcit-ng/ctdlclient.c
webcit-ng/static/js/login.js

index 3be8546a80fe6f0571e65a487d3c77bfc177227b..196fe52863003b8ac55bf6b1526577b268c90318 100644 (file)
@@ -1,4 +1,3 @@
-//
 // Admin functions
 //
 // Copyright (c) 1996-2022 by the citadel.org team
index 64da3c2de92285283c74ab13d1c680a5badf5f0f..eacedd3e01c356f17b1987fda922ff565de87861 100644 (file)
@@ -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)
index 3ef786707be723c70f0a917c71c97ca43f2206a5..00d0ca4f89a6528648bec2c14900ff1b457ca86e 100644 (file)
@@ -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) {
index f48f964e0064d4627f3f9a51773f503b952e77ef..ccf1936d2558404b0c6b10c88caec35d76d12173 100644 (file)
 // 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 =
                  "<div class=\"w3-modal-content\">"
-               + "  <div class=\"w3-panel w3-border w3-border-blue w3-topbar w3-bottombar w3-leftbar w3-rightbar\"><center>"
-
-               + "<p>Put the login screen here, dummy</p>"
+               + "<div class=\"w3-panel w3-border w3-border-blue w3-topbar w3-bottombar w3-leftbar w3-rightbar\"><center>"
+               + "<p>FIXME put a login banner here, dummy</p>"
                + "<p>" + any_message + "</p>"
                + "<table border=0><tr><td>"
                + _("User name:") + "</td><td><input type=\"text\" id=\"username\"></td></tr><tr><td>"
@@ -25,21 +26,17 @@ function display_login_screen(any_message) {
                + "<p>"
                + "<button class=\"w3-button w3-blue\" onClick=\"javascript:login_button()\">" + _("Log in") + "</button>"
                + "</p>"
-
-               + "  </center></div>"
+               + "</center></div>"
                + "</div>";
        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();
 }