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);
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);