diff options
author | the little girl <bie@blekksprut.net> | 2013-06-29 08:11:13 +0200 |
---|---|---|
committer | the little girl <bie@blekksprut.net> | 2013-06-29 08:11:13 +0200 |
commit | 1ec38509b329c49476b5f9dfae4e1889899d1d52 (patch) | |
tree | 9f2e6e23a99d995290846a3bc29a6241115c6124 /wiki.c | |
parent | e8a0a3af0bea6729aa7fba6991d9657d808ed38a (diff) | |
download | ukulele-1ec38509b329c49476b5f9dfae4e1889899d1d52.tar.xz |
config.def.h, oppdatert makefile
Diffstat (limited to 'wiki.c')
-rw-r--r-- | wiki.c | 39 |
1 files changed, 19 insertions, 20 deletions
@@ -10,17 +10,8 @@ #include <marxup.h> -static char *wikititle = "a wiki"; -static char *id = "anonymous"; -static char *links[][2] = { - { "home", "home" }, - { "planer", "planer" }, - 0 -}; -static char *(*authenticate)() = NULL; - -static char *script; -static char *base; +#include "config.h" + static const char *badchars = "\\?%:|\"<> "; @@ -40,15 +31,15 @@ int writable(char *path) { return 0; } -void head(char *title, char *link, char *what) { +void head(char *page, char *link, char *what) { printf("Content-Type: text/html; charset=utf-8\n\n"); printf("<!doctype html>\n"); - printf("<title>%s · %s</title>\n", wikititle, title); + printf("<title>%s · %s</title>\n", title, page); printf("<link rel='stylesheet' href='%s/wiki.css'>\n", base); if(link && what) - printf("<h1><a data-text='%s' href='%s' >%s</a></h1>", what, link, title); + printf("<h1><a data-text='%s' href='%s' >%s</a></h1>", what, link, page); else - printf("<h1>%s</h1>", title); + printf("<h1>%s</h1>", page); } void foot(int file) { @@ -82,6 +73,13 @@ int legit(char *page) { return 1; } +int problem(int status, char *message) { + printf("Status: %d\n", status); + printf("Content-Type: text/plain\n\n"); + printf("%s\n", message); + return 1; +} + int redirect(char *path) { printf("Status: 303\n"); if(*path == '?') @@ -103,8 +101,8 @@ int unauthorized(int status) { int edit(char *path) { if(!writable(path)) return unauthorized(403); FILE *fp = fopen(path, "r"); - char *title = clean(path); - fp ? head(title, path, "vis") : head(title, NULL, NULL); + char *page = clean(path); + fp ? head(page, path, "vis") : head(page, NULL, NULL); char buffer[sysconf(_SC_PAGESIZE)]; printf("<form method='post' enctype='text/plain'>\n"); printf("<p><textarea name=text rows=24 cols=72>"); @@ -183,8 +181,8 @@ int view(char *path) { return list(path, 1); FILE *fp = fopen(path, "r"); if(!fp) return redirect("?e"); - char *title = clean(path); - writable(path) ? head(title, "?e", "rediger") : head(title, NULL, NULL); + char *page = clean(path); + writable(path) ? head(page, "?e", "rediger") : head(page, NULL, NULL); marxup(fp, stdout); foot(1); return 0; @@ -206,7 +204,8 @@ int main(int argc, char **argv) { setenv("MARXUP_HEADER", "2", 1); setenv("MARXUP_PREFIX", base, 1); - chdir("pages"); + if(chdir("pages")) + return problem(404, "Not found"); if(!strncmp(method, "POST", 4)) return post(page); while(query && *query) { |