aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe little girl <bie@blekksprut.net>2013-06-25 21:14:56 +0200
committerthe little girl <bie@blekksprut.net>2013-06-25 21:14:56 +0200
commite8a0a3af0bea6729aa7fba6991d9657d808ed38a (patch)
treebedb543388d35d8a759679bdb70aa2d57e636a0a
parent18487df36bc687e8e716e36aa94f5c26b4aef5ef (diff)
downloadukulele-e8a0a3af0bea6729aa7fba6991d9657d808ed38a.tar.xz
ayay
-rw-r--r--.gitignore1
-rw-r--r--wiki.c30
2 files changed, 16 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index ad00db7..006d339 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
pages
+wiki.cgi
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++;
}