From: nishi Date: Sat, 20 Apr 2024 01:21:44 +0000 (+0000) Subject: authentication is pain X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=afe82d95fd0c766df32aefc55399676b93fdfe7f;p=mandshurica.git authentication is pain git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@48 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Module/cookie.c b/Module/cookie.c index 629a718..a07312b 100644 --- a/Module/cookie.c +++ b/Module/cookie.c @@ -39,6 +39,8 @@ const char mod_type[] = MS_MOD_AUTH; const char mod_auth_type[] = "Cookie"; +const char mod_http_path[] = "/cookie-login"; + struct mandshurica_config* config; int mod_init(struct mandshurica_config* _config) { diff --git a/Module/http.c b/Module/http.c index f8d2413..28aa416 100644 --- a/Module/http.c +++ b/Module/http.c @@ -153,12 +153,19 @@ void http_handler(int sock) { free(headers); headers = NULL; } + unsigned long long conlen = 0; while(true) { int len = recv(sock, buf, BUFFER_SIZE, 0); if(len <= 0) goto goquit; int i; for(i = 0; i < len; i++) { cbuf[0] = buf[i]; + if(conlen > 0){ + conlen--; + printf("%c", cbuf[0]); + fflush(stdout); + continue; + } if(state == 0) { if(buf[i] == ' ') { state = 1; @@ -185,7 +192,30 @@ void http_handler(int sock) { } else if(buf[i] == '\n') { count++; if(count == 2) { - if(strcmp(method, "GET") == 0) { + if(strcmp(method, "POST") == 0) { + if(headers != NULL){ + int j; + bool haslen = false; + for(j = 0; headers[j] != NULL; j += 2){ + if(mandshurica_strcaseequ(headers[j], "Content-Length")){ + haslen = true; + conlen = atoll(headers[j + 1]); + break; + } + } + if(!haslen){ + send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 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); + } + }else{ + send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 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); + } + }else if(strcmp(method, "GET") == 0) { char* chpath = mandshurica_strcat(webroot, path); struct stat st2; if(stat(chpath, &st2) != 0) { diff --git a/Webroot/index.html.tmpl b/Webroot/index.html.tmpl index f16732b..531ecbb 100644 --- a/Webroot/index.html.tmpl +++ b/Webroot/index.html.tmpl @@ -1,13 +1,9 @@ - - - - - - -

Mandshurica

-
- - +@include head-start.html@ +Mandshurica +@include body-start.html@ +

Mandshurica

+@include bar.html@ +@include end.html@