summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-11-27 03:10:16 -0600
committerEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-11-27 03:10:16 -0600
commit59bcef5c27540527fc4ca1007e9cfea5783ba233 (patch)
tree583c651dcd7d6fff34db26805b4606fa45a90aac
parent8b1c2f7e40f9c7ae77d3afb9f3eec21886c8f060 (diff)
downloadmisc-59bcef5c27540527fc4ca1007e9cfea5783ba233.tar.gz
misc-59bcef5c27540527fc4ca1007e9cfea5783ba233.zip
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.
-rwxr-xr-xnocompile/bin/mime-type4
-rwxr-xr-xnocompile/bin/rdns2
-rwxr-xr-xnocompile/libexec/gopherd.sh2
-rwxr-xr-xrebuild.sh1
-rw-r--r--src/bin/rrd.c3
-rw-r--r--src/libexec/httpd.c34
6 files changed, 37 insertions, 9 deletions
diff --git a/nocompile/bin/mime-type b/nocompile/bin/mime-type
index 71982d9..2b1bad0 100755
--- a/nocompile/bin/mime-type
+++ b/nocompile/bin/mime-type
@@ -4,10 +4,10 @@ MAIN="$(echo "${TYPE}" | cut -d/ -f1)"
SUB="$(echo "${TYPE}" | cut -d/ -f2)"
if [ "_${MAIN}" = "_inode" ];then
printf "text/plain\r\n"
- printf "this is a directory or symlink! wtf?!?"
+# printf "this is a directory or symlink! wtf?!?" #ssssshhhhh
TYPE="text/plain"
fi
-if [ "_${MAIN}" = "_text" -a "_${SUB}" != "_html"];then
+if [ "_${MAIN}" = "_text" -a "_${SUB}" != "_html" ];then
TYPE="text/plain"
fi
printf "%s\r\n" "$TYPE"
diff --git a/nocompile/bin/rdns b/nocompile/bin/rdns
new file mode 100755
index 0000000..347e416
--- /dev/null
+++ b/nocompile/bin/rdns
@@ -0,0 +1,2 @@
+#!/bin/sh
+dig +short -x "$1" | head -n1 | rev | tail -c+2 | rev
diff --git a/nocompile/libexec/gopherd.sh b/nocompile/libexec/gopherd.sh
index 768d02b..0b87223 100755
--- a/nocompile/libexec/gopherd.sh
+++ b/nocompile/libexec/gopherd.sh
@@ -10,7 +10,7 @@ if grep -v "^${base}" <<< "${realpath}" > /dev/null;then
exit 1
fi
myIP=$(/usr/local/bin/hop0 $(/usr/local/libexec/peerip))
-hostname=$(dig -x ${myIP} +short | head -n1 | rev | tail -c+2 | rev )
+hostname=$(rdns ${myIP})
if [ ! "${hostname}" ]; then
hostname=${myIP}
else
diff --git a/rebuild.sh b/rebuild.sh
index 62380e3..4c0d77c 100755
--- a/rebuild.sh
+++ b/rebuild.sh
@@ -1,4 +1,5 @@
#!/bin/sh -vq
+cd $(dirname $0)
rm bin/*
rm libexec/*
for i in src/*;do
diff --git a/src/bin/rrd.c b/src/bin/rrd.c
index bbb907d..1b43426 100644
--- a/src/bin/rrd.c
+++ b/src/bin/rrd.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <sys/sysctl.h>
#include <net/route.h>
@@ -43,7 +44,7 @@ void print_sa6(struct sockaddr *sa) {
}
void p_rtentry(struct rt_msghdr *rtm) {
- struct sockadrr *sa = (struct sockaddr *)(rtm+1);
+ struct sockadrr *sa = (rtm+1);
struct sockaddr *rti_info[RTAX_MAX];
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
struct in6_addr *in6 = &sa6->sin6_addr;
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 <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
-#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] == '/') {