From 609e5f0cfb7ca36d1d5346fe319fff4f5af53fa4 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 24 Feb 2008 17:40:58 -0600 Subject: [PATCH] Rename "doc-root" variable to doc-root, fix information leakage in source responder --- extra/webapps/cgi/cgi.factor | 2 +- extra/webapps/file/file.factor | 13 +++++++------ extra/webapps/fjsc/fjsc.factor | 4 ++-- extra/webapps/source/source.factor | 6 ++++-- 4 files changed, 14 insertions(+), 11 deletions(-) mode change 100644 => 100755 extra/webapps/cgi/cgi.factor diff --git a/extra/webapps/cgi/cgi.factor b/extra/webapps/cgi/cgi.factor old mode 100644 new mode 100755 index 967036a797..6be99088d0 --- a/extra/webapps/cgi/cgi.factor +++ b/extra/webapps/cgi/cgi.factor @@ -58,7 +58,7 @@ SYMBOL: cgi-root ] with-stream ; : serve-regular-file ( -- ) - cgi-root get "doc-root" [ file-responder ] with-variable ; + cgi-root get doc-root [ file-responder ] with-variable ; : do-cgi ( name -- ) { diff --git a/extra/webapps/file/file.factor b/extra/webapps/file/file.factor index 552f5e0977..c324561279 100755 --- a/extra/webapps/file/file.factor +++ b/extra/webapps/file/file.factor @@ -1,14 +1,15 @@ -! Copyright (C) 2004, 2007 Slava Pestov. +! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: calendar html io io.files kernel math math.parser http.server.responders http.server.templating namespaces parser sequences strings assocs hashtables debugger http.mime sorting html.elements logging ; - IN: webapps.file +SYMBOL: doc-root + : serving-path ( filename -- filename ) - "" or "doc-root" get swap path+ ; + "" or doc-root get swap path+ ; : file-http-date ( filename -- string ) file-modified unix-time>timestamp timestamp>http-string ; @@ -61,7 +62,7 @@ SYMBOL: page \ run-page DEBUG add-input-logging : include-page ( filename -- ) - "doc-root" get swap path+ run-page ; + serving-path run-page ; : serve-fhtml ( filename -- ) serving-html @@ -115,14 +116,14 @@ SYMBOL: page ] if ; : file-responder ( -- ) - "doc-root" get [ + doc-root get [ "argument" get serve-object ] [ "404 doc-root not set" httpd-error ] if ; global [ - ! Serves files from a directory stored in the "doc-root" + ! Serves files from a directory stored in the doc-root ! variable. You can set the variable in the global ! namespace, or inside the responder. "file" [ file-responder ] add-simple-responder diff --git a/extra/webapps/fjsc/fjsc.factor b/extra/webapps/fjsc/fjsc.factor index 55609c72f9..56ecb3f546 100755 --- a/extra/webapps/fjsc/fjsc.factor +++ b/extra/webapps/fjsc/fjsc.factor @@ -53,7 +53,7 @@ IN: webapps.fjsc ! the 'fjsc' responder. "fjsc-resources" [ [ - "extra/fjsc/resources/" resource-path "doc-root" set + "extra/fjsc/resources/" resource-path doc-root set file-responder ] with-scope ] add-simple-responder @@ -62,7 +62,7 @@ IN: webapps.fjsc ! 'termlib'. "fjsc-repl-resources" [ [ - "extra/webapps/fjsc/resources/" resource-path "doc-root" set + "extra/webapps/fjsc/resources/" resource-path doc-root set file-responder ] with-scope ] add-simple-responder ; diff --git a/extra/webapps/source/source.factor b/extra/webapps/source/source.factor index 4c0701c687..98fb5b8873 100755 --- a/extra/webapps/source/source.factor +++ b/extra/webapps/source/source.factor @@ -15,14 +15,16 @@ IN: webapps.source : source-responder ( path mime-type -- ) drop serving-html - [ dup htmlize-stream ] with-html-stream ; + [ + dup file-name swap htmlize-stream + ] with-html-stream ; global [ ! Serve up our own source code "source" [ "argument" get check-source-path [ [ - "" resource-path "doc-root" set + "" resource-path doc-root set [ source-responder ] serve-file-hook set file-responder ] with-scope