From 59bcef5c27540527fc4ca1007e9cfea5783ba233 Mon Sep 17 00:00:00 2001 From: Epoch Qwert Date: Thu, 27 Nov 2014 03:10:16 -0600 Subject: updated httpd.c to use different dirs for sites and vhosts updated gopherd.sh to use the new rdns script rdns script just wraps dig -x and outputs a real hostname instead of one ending with a '.' rebuild.sh got a cd added to the top so it can be run from somewhere else mime-type got an error line commented out. --- src/libexec/httpd.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/libexec') diff --git a/src/libexec/httpd.c b/src/libexec/httpd.c index 9da149f..cd44446 100644 --- a/src/libexec/httpd.c +++ b/src/libexec/httpd.c @@ -1,10 +1,12 @@ #include +#include #include #include #include #include -#define VHOST_ROOT "/var/www" +#define VHOST_ROOT "/var/www/vhosts" +#define SITES_ROOT "/var/www/sites" #define CGI "cgi-bin" #define SERVER "epochttpd/2.0 (Unix)" @@ -45,7 +47,7 @@ int main(int argc,char *argv[]) { if((get_param=strchr(page,'?'))) { *get_param=0; get_param++; - setenv("QUERY_STRING",get_param); + setenv("QUERY_STRING",get_param,1); } } while(fgets(line,sizeof(line)-1,stdin)) { @@ -58,15 +60,37 @@ int main(int argc,char *argv[]) { } if(strchr(line,'\r')) *strchr(line,'\r')=0; if(!strncasecmp(line,"Host: ",6)) { - setenv("HTTP_HOST",line+6); + setenv("HTTP_HOST",line+6,1); } if(!strcmp(line,"")) { break; } } //TODO: sanitize this. - chdir(VHOST_ROOT); - chdir((char*)getenv("HTTP_HOST")); + if(chdir(VHOST_ROOT) == -1) { + printf("HTTP/1.1 500 Internal Server Error\r\n"); + standard_headers(); + printf("Content-type: text/html\r\n\r\ncouldn't chdir(\"%s\");",VHOST_ROOT); + exit(3); + } + if(chdir((char*)getenv("HTTP_HOST")) == -1) { + if(chdir(SITES_ROOT) != -1) { + if(chdir("default") == -1) { + //no backup site to show people. fuck. shit happens. + printf("HTTP/1.1 500 Internal Server Error\r\n"); + standard_headers(); + printf("Content-type: text/html\r\n\r\nfuck"); + exit(1); + } + //we're good. + } else { + printf("HTTP/1.1 500 Internal Server Error\r\n"); + standard_headers(); + printf("Content-type: text/html\r\n\r\ncouldn't chdir(\"%s\");",SITES_ROOT); + //wtf? not sites dir??? + exit(2); + } + } if(strncmp(page,"/cgi-bin/",9)) { for(;*page == '/';page++); if(page[strlen(page)-1] == '/') { -- cgit v1.2.3