From a484c4e818bef249a8af571a0f0725bd9d128ff9 Mon Sep 17 00:00:00 2001 From: the little girl Date: Fri, 5 Sep 2014 20:29:17 +0900 Subject: fikse litt og litt --- config.def.h | 2 ++ wiki.c | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/config.def.h b/config.def.h index d83e046..12dd086 100644 --- a/config.def.h +++ b/config.def.h @@ -7,6 +7,8 @@ static char *home = "home"; static char *pages = "pages"; static char *loft = ".loft"; +static char *realm = "wiki"; + static char *links[][2] = { { "home", "home" }, { "planer", "planer" }, diff --git a/wiki.c b/wiki.c index f30c6c3..bfb384a 100644 --- a/wiki.c +++ b/wiki.c @@ -39,12 +39,14 @@ void head(char *page, char *link, char *what) { printf("%s · %s\n", title, page); printf("\n", base); printf("\n", base); + printf("

"); if(link && what && !strcmp(what, "rediger")) - printf("

%s

\n", what, link, page); + printf("%s", what, link, page); else if(link && what) - printf("

%s

\n", what, base, link, page); + printf("%s", what, base, link, page); else - printf("

%s

\n", page); + printf("%s", page); + printf("\n"); } void foot(int file) { @@ -57,18 +59,14 @@ void foot(int file) { printf("%s ", script, links[i][1], links[i][0]); } if(!file) return; - printf(""); - printf("%s ", id); - printf("text/plain"); - printf("\n"); + printf("%s text/plain\n", id); } char *clean(char *p) { char *dup = strdup(basename(p)); char *x = dup; while(*x) { - if(*x == '-') - *x = ' '; + if(*x == '-') *x = ' '; x++; } return dup; @@ -79,6 +77,7 @@ int legit(char *page) { if(!strcmp(page, "/")) return 0; if(strstr(page, "..")) return 0; if(strcspn(page, badchars) < strlen(page)) return 0; + // strlen(page) return 1; } @@ -91,17 +90,18 @@ int problem(int status, char *message) { int redirect(char *path) { printf("Status: 303\n"); - if(*path == '?') - printf("Location: %s\n\n", path); - else - printf("Location: %s/%s\n\n", script, path); + switch(*path) { + case '?': printf("Location: %s\n\n", path); break; + // case '#': + default: printf("Location: %s/%s\n\n", script, path); break; + } return 0; } int unauthorized(int status) { printf("Status: %d\n", status); if(status == 401) - printf("WWW-Authenticate: Basic realm='Kya'\n"); + printf("WWW-Authenticate: Basic realm='%s'\n", realm); printf("Content-Type: text/plain; charset=utf-8\n\n"); printf("No.\n"); return 1; @@ -128,17 +128,17 @@ int edit(char *path) { return 0; } +// v fæl int store(char *raw, int len) { char *dir = dirname(strdup(raw)); char *id = basename(strdup(raw)); if(chdir(dir)) return problem(404, "Not found"); char path[strlen(id) + strlen(loft) + 256]; - time_t epoch = time(NULL); - snprintf(path, 512, "%s/%s.%d", loft, id, (int) epoch); + int epoch = time(NULL); + snprintf(path, strlen(id) + strlen(loft) + 256, "%s/%s.%d", loft, id, epoch); FILE *fp = fopen(path, "w"); - if(!fp) return redirect("FFFF"); - + if(!fp) return redirect("#"); int pos = 0; unsigned int decoded; char buffer[3] = { 0 }; -- cgit v1.0