From e8a0a3af0bea6729aa7fba6991d9657d808ed38a Mon Sep 17 00:00:00 2001 From: the little girl Date: Tue, 25 Jun 2013 21:14:56 +0200 Subject: ayay --- .gitignore | 1 + wiki.c | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ad00db7..006d339 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ pages +wiki.cgi diff --git a/wiki.c b/wiki.c index 90627b5..035eac8 100644 --- a/wiki.c +++ b/wiki.c @@ -10,21 +10,17 @@ #include -char *authenticate_ip() { - return getenv("REMOTE_ADDR"); -} - static char *wikititle = "a wiki"; -static char *(*authenticate)() = authenticate_ip; +static char *id = "anonymous"; static char *links[][2] = { { "home", "home" }, { "planer", "planer" }, 0 }; +static char *(*authenticate)() = NULL; static char *script; static char *base; -static char *id; static const char *badchars = "\\?%:|\"<> "; @@ -64,7 +60,7 @@ void foot(int file) { printf(""); printf("%s ", id); printf("text/plain"); - printf(""); + printf("\n"); } char *clean(char *p) { @@ -168,7 +164,7 @@ int list(char *raw, int dir) { return 0; } -int plaintext(char *path) { +int text(char *path) { FILE *fp = fopen(path, "r"); if(fp) { char buffer[sysconf(_SC_PAGESIZE)]; @@ -195,25 +191,29 @@ int view(char *path) { } int main(int argc, char **argv) { - char *page = getenv("PATH_INFO"); char *method = getenv("REQUEST_METHOD"); - char *query = getenv("QUERY_STRING"); + char *page = getenv("PATH_INFO"); + char *query = getenv("QUERY_STRING"); + + if(!method) method = "GET"; if(!script) script = getenv("SCRIPT_NAME"); - if(!script) script = "/"; + if(!script) script = ""; if(!base) base = strdup(dirname(strdup(script))); - id = "anonymous"; if(authenticate && !(id = authenticate())) return unauthorized(401); + if(!legit(page++)) return redirect("home"); setenv("MARXUP_HEADER", "2", 1); + setenv("MARXUP_PREFIX", base, 1); + chdir("pages"); - if(!legit(page)) return redirect("home"); - page++; + if(!strncmp(method, "POST", 4)) return post(page); while(query && *query) { switch(*query) { case 'e': return edit(page); - case 't': return plaintext(page); + case 't': return text(page); + // case 'p': return } query++; } -- cgit v1.0