bug fixes

This commit is contained in:
Pin
2022-03-08 22:50:24 -05:00
parent 857a38d904
commit f1ae49da0c
8 changed files with 53 additions and 11 deletions

View File

@@ -24,7 +24,7 @@ int PrintLog(unsigned char *message) {
if (!strcmp(WEB_ROOT_DIR, "/var/www/html/")) {
FILE *fp;
fp = fopen("/var/log/seaweb/log", "w");
fp = fopen("/var/log/seaweb/log", "a");
fprintf(fp, "[Log] %02d/%02d/%d %02d:%02d:%02d - %s\n", (now->tm_mon + 1), now->tm_mday,
(now->tm_year + 1900), now->tm_hour, now->tm_min, now->tm_sec, message);
fclose(fp);
@@ -81,7 +81,11 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) {
putenv(conLenString);
putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
queryString = malloc(r->requestBodyLen + 24);
sprintf(queryString, "QUERY_STRING=%s", r->requestBody);
if (r->requestBodyLen != 0) {
sprintf(queryString, "QUERY_STRING=%s", r->requestBody);
} else {
sprintf(queryString, "QUERY_STRING=");
}
putenv(queryString);
// Starting fork to pipe stdin into php-cgi
@@ -99,15 +103,20 @@ char *php_cgi(char *sPath, struct HTTPRequest *r) {
} else if (pid < 0) { // Error forking
printDebug("Error in stdin php frok");
} else { // Parent fork
close(phpPipe[1]);
close(phpPipe2[1]);
dup2(phpPipe2[0], STDIN_FILENO);
execl("/usr/bin/php-cgi", "php-cgi", NULL);
}
} else {
queryString = malloc(strlen(r->requestVars) + 24);
sprintf(queryString, "QUERY_STRING=%s", r->requestVars);
putenv(queryString);
putenv("REQUEST_METHOD=GET");
if (r->requestVars != NULL) {
queryString = malloc(strlen(r->requestVars) + 24);
sprintf(queryString, "QUERY_STRING=%s", r->requestVars);
} else {
queryString = malloc(24);
sprintf(queryString, "QUERY_STRING=");
}
putenv(queryString);
execl("/usr/bin/php-cgi", "php-cgi", NULL);
}
exit(EXIT_SUCCESS);