]> Nishi Git Mirror - mandshurica.git/commitdiff
works
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 08:52:46 +0000 (08:52 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 08:52:46 +0000 (08:52 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@54 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Module/http.c
Webroot/bar.html
Webroot/login-success/index.html.tmpl [new file with mode: 0644]

index 9550b6c395255e55642c8bab3fac7cf9fe0400c3..860f13ab179247d98a5f06acc26783374790ca43 100644 (file)
@@ -199,6 +199,59 @@ void http_handler(int sock) {
                                                                                                if(usr != NULL && pwd != NULL) {
                                                                                                        int res = mod_auth(usr, pwd);
                                                                                                        if(res == MS_AUTH_OK) {
+                                                                                                               char* type;
+                                                                                                               uint64_t len;
+                                                                                                               char* data = NULL;
+                                                                                                               char* s;
+
+                                                                                                               struct stat st;
+                                                                                                               char* lastmod = NULL;
+                                                                                                               const char* pth = mandshurica_strcat(webroot, "/login-success/");
+                                                                                                               if(stat(pth, &st) == 0) {
+                                                                                                                       if(S_ISDIR(st.st_mode)) {
+                                                                                                                               if(data == NULL) {
+                                                                                                                                       s = mandshurica_strcat(pth, "/index.html.tmpl");
+                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                                                       free(s);
+                                                                                                                               }
+                                                                                                                               if(data == NULL) {
+                                                                                                                                       s = mandshurica_strcat(pth, "/index.html");
+                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                                                       free(s);
+                                                                                                                               }
+                                                                                                                       } else {
+                                                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len);
+                                                                                                                       }
+                                                                                                               }
+                                                                                                               if(data != NULL) {
+                                                                                                                       send(sock, "HTTP/1.1 200 OK\r\n", 9 + 8, 0);
+                                                                                                                       send(sock, "Connection: keep-alive\r\n", 24, 0);
+                                                                                                                       send(sock, "Content-Type: ", 14, 0);
+                                                                                                                       send(sock, type, strlen(type), 0);
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                                       if(lastmod != NULL) {
+                                                                                                                               send(sock, "Last-Modified: ", 15, 0);
+                                                                                                                               send(sock, lastmod, strlen(lastmod), 0);
+                                                                                                                               send(sock, "\r\n", 2, 0);
+                                                                                                                               free(lastmod);
+                                                                                                                       }
+                                                                                                                       send(sock, "Content-Length: ", 16, 0);
+
+                                                                                                                       char* lenstr = malloc(513);
+                                                                                                                       sprintf(lenstr, "%llu", len);
+                                                                                                                       send(sock, lenstr, strlen(lenstr), 0);
+                                                                                                                       free(lenstr);
+
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                                       send(sock, data, len, 0);
+                                                                                                                       free(type);
+                                                                                                               } else {
+                                                                                                                       send(sock, "HTTP/1.1 200 OK\r\n", 9 + 8, 0);
+                                                                                                                       send(sock, "Connection: keep-alive\r\n", 24, 0);
+                                                                                                                       send(sock, "Content-Length: 0\r\n", 19, 0);
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                               }
                                                                                                        } else if(res == MS_AUTH_ERROR) {
                                                                                                                send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
                                                                                                                send(sock, "Connection: keep-alive\r\n", 24, 0);
@@ -229,10 +282,35 @@ void http_handler(int sock) {
                                                                                                                                data = config->mandshurica_load(pth, &type, &lastmod, &len);
                                                                                                                        }
                                                                                                                }
-                                                                                                               send(sock, "HTTP/1.1 403 Forbidden\r\n", 15 + 9, 0);
-                                                                                                               send(sock, "Connection: keep-alive\r\n", 24, 0);
-                                                                                                               send(sock, "Content-Length: 0\r\n", 19, 0);
-                                                                                                               send(sock, "\r\n", 2, 0);
+                                                                                                               if(data != NULL) {
+                                                                                                                       send(sock, "HTTP/1.1 403 Forbidden\r\n", 24, 0);
+                                                                                                                       send(sock, "Connection: keep-alive\r\n", 24, 0);
+                                                                                                                       send(sock, "Content-Type: ", 14, 0);
+                                                                                                                       send(sock, type, strlen(type), 0);
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                                       if(lastmod != NULL) {
+                                                                                                                               send(sock, "Last-Modified: ", 15, 0);
+                                                                                                                               send(sock, lastmod, strlen(lastmod), 0);
+                                                                                                                               send(sock, "\r\n", 2, 0);
+                                                                                                                               free(lastmod);
+                                                                                                                       }
+                                                                                                                       send(sock, "Content-Length: ", 16, 0);
+
+                                                                                                                       char* lenstr = malloc(513);
+                                                                                                                       sprintf(lenstr, "%llu", len);
+                                                                                                                       send(sock, lenstr, strlen(lenstr), 0);
+                                                                                                                       free(lenstr);
+
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                                       send(sock, data, len, 0);
+                                                                                                                       free(type);
+                                                                                                               } else {
+                                                                                                                       send(sock, "HTTP/1.1 403 Forbidden\r\n", 24, 0);
+                                                                                                                       send(sock, "Connection: keep-alive\r\n", 24, 0);
+                                                                                                                       send(sock, "Content-Length: 0\r\n", 19, 0);
+                                                                                                                       send(sock, "\r\n", 2, 0);
+                                                                                                               }
                                                                                                        }
                                                                                                } else {
                                                                                                        send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
index 08c3f66fbb246661b0f6706de5baef39fa35fd65..cadeedb448d55eb1b2594a82d94f53b40c8b0f44 100644 (file)
@@ -1,3 +1,3 @@
 <hr>
-<a href="/">Home</a> @ifnot login@<a href="/login">Login</a>@endif@
+<a href="/">Home</a>@ifnot login@ <a href="/login">Login</a>@endif@@if login@ <a href="/logout">Logout</a>@endif@
 <hr>
diff --git a/Webroot/login-success/index.html.tmpl b/Webroot/login-success/index.html.tmpl
new file mode 100644 (file)
index 0000000..7da3637
--- /dev/null
@@ -0,0 +1,10 @@
+<!--@chdir_webroot@
+vim: syntax=html
+-->
+@include head-start.html@
+<title>Mandshurica - Login successful</title>
+@include body-start.html@
+<h1>Mandshurica - Login successful</h1>
+@include bar.html@
+Welcome back
+@include end.html@