diff options
author | the little girl <bie@blekksprut.net> | 2013-06-25 21:14:56 +0200 |
---|---|---|
committer | the little girl <bie@blekksprut.net> | 2013-06-25 21:14:56 +0200 |
commit | e8a0a3af0bea6729aa7fba6991d9657d808ed38a (patch) | |
tree | bedb543388d35d8a759679bdb70aa2d57e636a0a | |
parent | 18487df36bc687e8e716e36aa94f5c26b4aef5ef (diff) | |
download | ukulele-e8a0a3af0bea6729aa7fba6991d9657d808ed38a.tar.xz |
ayay
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | wiki.c | 30 |
2 files changed, 16 insertions, 15 deletions
@@ -1 +1,2 @@ pages +wiki.cgi @@ -10,21 +10,17 @@ #include <marxup.h> -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("<span style='float: right'>"); printf("%s ", id); printf("<a href='?t'>text/plain</a>"); - printf("</span>"); + printf("</span>\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++; } |