diff options
-rwxr-xr-x | nocompile/bin/XuntilY (renamed from nocompile/XuntilY) | 0 | ||||
-rwxr-xr-x | rebuild.sh | 21 | ||||
-rw-r--r-- | src/bin/dcchelper.c (renamed from src/dcchelper.c) | 0 | ||||
-rw-r--r-- | src/bin/gethostbyname.c (renamed from src/gethostbyname.c) | 0 | ||||
-rw-r--r-- | src/bin/pad.c (renamed from src/pad.c) | 0 | ||||
-rw-r--r-- | src/libexec/httpd.c | 117 |
6 files changed, 131 insertions, 7 deletions
diff --git a/nocompile/XuntilY b/nocompile/bin/XuntilY index f6cc672..f6cc672 100755 --- a/nocompile/XuntilY +++ b/nocompile/bin/XuntilY @@ -1,10 +1,17 @@ -#!/bin/sh -for i in src/*.c;do - out=$(basename $i | cut -d. -f1) - gcc -o bin/$out $i - cp bin/* /usr/local/bin/ +#!/bin/sh -v +for i in src/*;do + iout=$(basename $i) + mkdir -p $iout + for j in $i/*.c;do + jout=$(basename $j | cut -d. -f1) + gcc -o $iout/$jout $j + done + cp $iout/* /usr/local/$iout/ done for i in nocompile/*;do - out=$(basename $i) - cp $i /usr/local/bin/$out + iout=$(basename $i) + for j in nocompile/$i/* out=$(basename $i);do + jout=$(basename $j) + done + cp $i/* /usr/local/$iout/ done diff --git a/src/dcchelper.c b/src/bin/dcchelper.c index bf8f28b..bf8f28b 100644 --- a/src/dcchelper.c +++ b/src/bin/dcchelper.c diff --git a/src/gethostbyname.c b/src/bin/gethostbyname.c index 646bf0a..646bf0a 100644 --- a/src/gethostbyname.c +++ b/src/bin/gethostbyname.c diff --git a/src/pad.c b/src/bin/pad.c index 2f2ea13..2f2ea13 100644 --- a/src/pad.c +++ b/src/bin/pad.c diff --git a/src/libexec/httpd.c b/src/libexec/httpd.c new file mode 100644 index 0000000..4b14269 --- /dev/null +++ b/src/libexec/httpd.c @@ -0,0 +1,117 @@ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <unistd.h> + +#define VHOST_ROOT "/var/www" +#define CGI "cgi-bin" +#define SERVER "epochttpd/2.0 (Unix)" + +void standard_headers() { + printf("Server: %s\n",SERVER); +} + +int main(int argc,char *argv[]) { + int fd; + char *name[10]; + int s,n; + short in; + char *method; + char *page; + char *version; + char *get_param; + char line[getpagesize()]; + fgets(line,sizeof(line)-1,stdin); + if(!strchr(line,'\n')) { + printf("HTTP/1.1 413 Entity Too Large\r\n"); + standard_headers(); + printf("Content-type: text/plain\r\n\r\n"); + printf("use smaller (<%d bytes) headers.\n",getpagesize()); + return 0; + } + if(strchr(line,'\r')) *strchr(line,'\r')=0; + method=strdup(line); + if((page=strchr(method,' '))) { + *page=0; + page++; + if((version=strchr(page,' '))) { + *version=0; + version++; + } + if((get_param=strchr(page,'?'))) { + *get_param=0; + get_param++; + setenv("QUERY_STRING",get_param); + } + } + while(fgets(line,sizeof(line)-1,stdin)) { + if(!strchr(line,'\n')) { + printf("HTTP/1.1 413 Entity Too Large\r\n"); + standard_headers(); + printf("Content-type: text/plain\r\n\r\n"); + printf("use smaller (<%d bytes) headers.\n",getpagesize()); + return 0; + } + if(strchr(line,'\r')) *strchr(line,'\r')=0; + if(!strncasecmp(line,"Host: ",6)) { + setenv("HTTP_HOST",line+6); + } + if(!strcmp(line,"")) { + break; + } + } + //TODO: sanitize this. + chdir(VHOST_ROOT); + chdir((char*)getenv("HTTP_HOST")); + if(strncmp(page,"/cgi-bin/",9)) { + for(;*page == '/';page++); + if(page[strlen(page)-1] == '/') { + printf("HTTP/1.1 302 Moved Permanently\r\n"); + standard_headers(); + printf("Location: /%sindex.html\r\n\r\n",page); + return 0; + } + if(fd=open(page,O_RDONLY) != -1) {//need to check that the file isn't a directory. :P + printf("HTTP/1.1 200 OK\r\n"); + standard_headers(); + name[0]="/usr/local/bin/mime-type"; + name[1]=page; + name[2]=0; + printf("Content-type: "); + fflush(stdout); + switch(fork()) { + case 0://child + execv(name[0],name); + break; + case -1://error + printf("fork failed.\n"); + break; + default://parent + break; + } + wait(&s); + fflush(stdout); + printf("\r\n"); + while((n=read(fd,line,sizeof(line))) > 0) { + write(1,line,n); + } + } else { + printf("HTTP/1.1 404 Not Found\r\n"); + standard_headers(); + printf("Content-type: text/plain\r\n\r\n"); + printf("Can't open that page.\n"); + } + } else { + //attempt to run this bastard! + chdir(CGI); + page+=strlen("/cgi-bin/"); + for(;*page == '/';page++); + name[0]=page; + name[1]=0; + printf("HTTP/1.1 200 OK\r\n"); + standard_headers(); + fflush(stdout); + execv(name[0],name); + } + return 0; +} |