aboutsummaryrefslogtreecommitdiff
path: root/wiki.c
diff options
context:
space:
mode:
Diffstat (limited to 'wiki.c')
-rw-r--r--wiki.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/wiki.c b/wiki.c
index 90627b5..035eac8 100644
--- a/wiki.c
+++ b/wiki.c
@@ -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++;
}