From a4948f0c2f837bb9191fee7524457ba2becb2be2 Mon Sep 17 00:00:00 2001 From: Jacob Parker Date: Wed, 22 Feb 2012 22:43:07 -0500 Subject: [PATCH] ported more generalized handler stuff from csc fork --- .htaccess | 2 +- src/config.d | 6 +++--- src/web.d | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.htaccess b/.htaccess index 0039b2c..7b23492 100644 --- a/.htaccess +++ b/.htaccess @@ -1,4 +1,4 @@ RewriteEngine on RewriteBase /~j3parker/ RewriteRule ^pub/(.*) - [L] -RewriteRule ^(.*) /users/j3parker/www/bin/web [L] +RewriteRule ^(.*) bin/web [L] diff --git a/src/config.d b/src/config.d index a133c26..b7f1171 100644 --- a/src/config.d +++ b/src/config.d @@ -3,9 +3,9 @@ const string url_root = "/~j3parker/"; const string site_title = "This is a Title"; const string site_subtitle = "but this is a subtitle"; -const bool nav_tree_vert = true; -const bool nav_tree_chev = true; -const bool page_container = false; +const bool nav_tree_vert = false; +const bool nav_tree_chev = false; +const bool page_container = true; string[string] handlers; diff --git a/src/web.d b/src/web.d index 5013d7d..c5ad886 100755 --- a/src/web.d +++ b/src/web.d @@ -1,5 +1,5 @@ //#!/usr/bin/rdmd -import std.stdio, std.path, std.process, std.file, std.array, std.string, std.algorithm, std.datetime; +import std.stdio, std.path, std.process, std.file, std.array, std.string, std.algorithm, std.datetime, std.ascii; import config; string dweb_root; @@ -65,9 +65,14 @@ void do_header() { html_push("
"); html_push("
"); + + html_push("
"); + html_pop("
"); + html_push("
"); html("changelog"); html_pop("
"); + html_pop("
"); html_push("
"); @@ -87,6 +92,15 @@ bool dirExists(string path) { try { if (isDir(path)) return true; else return void do_content(string url) { html_push("
"); + // first, see if we have something that wants to handle url outright + foreach (string glob, string h; handlers) { + if (globMatch(url, glob)) { + html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url)); + html_pop("
"); + return; + } + } + // if that failed, see if we can handle the file if (url == "" ? false : url[$-1] == '/') url ~= "index"; foreach (f; array(map!"a.name"(dirEntries(dirName(dweb_root ~ "/srv/" ~ url), SpanMode.shallow)))) { if (isDir(f)) continue; @@ -119,6 +133,11 @@ void do_footer() { html_pop("
\n"); } +bool evil(string s) { + foreach(char c; s) if (!isAlphaNum(c) && c != '/' && c != '-' && c != '_') return true; + return false; +} + void main(string[] args) { init_handlers(); dweb_root = getcwd()[0..$-4]; // take out bin/ @@ -128,6 +147,7 @@ void main(string[] args) { html_push("\n"); string url = getenv("SCRIPT_URL")[url_root.length..$]; + if (evil(url)) { html ("bad url."); return; } string pagename = baseName(url); if (pagename.length != 0) pagename = " - " ~ pagename;