diff options
-rw-r--r-- | config.def.h | 2 | ||||
-rw-r--r-- | 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" }, @@ -39,12 +39,14 @@ void head(char *page, char *link, char *what) { printf("<title>%s · %s</title>\n", title, page); printf("<link rel='stylesheet' type='text/css' href='%s/wiki.css'>\n", base); printf("<script src='%s/wiki.js'></script>\n", base); + printf("<h1>"); if(link && what && !strcmp(what, "rediger")) - printf("<h1><a data-text='%s' href='%s'>%s</a></h1>\n", what, link, page); + printf("<a data-text='%s' href='%s'>%s</a>", what, link, page); else if(link && what) - printf("<h1><a data-text='%s' href='%s/%s'>%s</a></h1>\n", what, base, link, page); + printf("<a data-text='%s' href='%s/%s'>%s</a>", what, base, link, page); else - printf("<h1>%s</h1>\n", page); + printf("%s", page); + printf("</h1>\n"); } void foot(int file) { @@ -57,18 +59,14 @@ void foot(int file) { printf("<a href='%s/%s'>%s</a> ", script, links[i][1], links[i][0]); } if(!file) return; - printf("<span style='float: right'>"); - printf("%s ", id); - printf("<a href='?t'>text/plain</a>"); - printf("</span>\n"); + printf("<span class='f'>%s <a href='?t'>text/plain</a></span>\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 }; |