--- parser3/etc/auto.p.in 2020/12/07 16:04:22 1.1
+++ parser3/etc/auto.p.in 2021/01/15 20:43:05 1.9
@@ -1,4 +1,20 @@
-#$Id: auto.p.in,v 1.1 2020/12/07 16:04:22 moko Exp $
+#$Id: auto.p.in,v 1.9 2021/01/15 20:43:05 moko Exp $
+
+@auto[]
+#source/client charsets
+$request:charset[utf-8]
+$response:charset[utf-8]
+
+$response:content-type[
+ $.value[text/html]
+ $.charset[$response:charset]
+]
+
+#$SQL.connect-string[mysql://user:pass@host/db?charset=utf8]
+#$SQL.connect-string[sqlite://db]
+#$SQL.connect-string[pgsql://user:pass@host/db]
+#$SQL.connect-string[odbc://DSN=datasource^;UID=user^;PWD=password]
+
@conf[filespec]
$confdir[^file:dirname[$filespec]]
@@ -83,11 +99,12 @@ $LIMITS[
$.post_max_size(10*0x400*0x400)
]
+#$HTTPD[
+# $.mode[threaded]
+#]
+
#$MAIL[
-# $.sendmail[your sendmail command goes here]
-# these are tried when no 'sendmail' specified:
-# /usr/sbin/sendmail -t -i -f postmaster
-# /usr/lib/sendmail -t -i -f postmaster
+# $.SMTP[localhost]
#]
@@ -146,8 +163,7 @@ $result(def $env:REMOTE_ADDR && ^env:REM
^unhandled_exception_debug[$exception;$stack]
}{
^if($exception.type eq "file.missing"){
-# ^log404[]
-# ^location[/404/]
+# $response:location[/404/]
$response:status(404)
}{
^unhandled_exception_release[$exception;$stack]
@@ -155,17 +171,92 @@ $result(def $env:REMOTE_ADDR && ^env:REM
}
-@auto[]
-#source/client charsets
-$request:charset[utf-8]
-$response:charset[utf-8]
+@CLASS
+httpd
-$response:content-type[
- $.value[text/html]
- $.charset[$response:charset]
+@include[filename]
+^use[$filename; $.main(true) ]
+^MAIN:main[]
+
+@index[dir][list]
+^fatal_error[Index of $dir;Index of $dir;
+ $list[^file:list[$dir]]
+ ^list.sort{^if($list.dir)[0;1] $list.name}
+ ^list.menu{
+ ^if($list.dir){/}$list.name
+ }
]
+$response:status(200)
-#$SQL.connect-string[mysql://user:pass@host/db?charset=utf8]
-#$SQL.connect-string[sqlite://db]
-#$SQL.connect-string[pgsql://user:pass@host/db]
-#$SQL.connect-string[odbc://DSN=datasource^;UID=user^;PWD=password]
+# option can be method, URL or text/code
+@option[option]
+$result[^if($option is junction){^option[]}(^option.match[$cfg.parser]){^include[$option]}{$option}]
+
+@file[filename]
+$result[^if(^filename.match[$cfg.parser]){^include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}]
+
+@log[filename;detail][now;line]
+$now[^date::now[]]
+$line[$env:REMOTE_ADDR [^now.sql-string[]] "$request:method $request:uri"$detail^#0A]
+^line.save[append;$filename]
+
+@404[]
+$response:status[404]
+The requested URL was not found on this server.
+
+
+@main[][basic]
+
+#$request:document-root[/website/folder]
+
+$cfg[
+ $.parser[\.(html)^$]
+ $.index[index.html]
+# $.autoindex(true)
+ $.404[$404]
+# $.404[/_doc.html]
+# $.fix-trailing-slash(true)
+# $.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[change me] $.realm[site administration] ]
+ $.deny[(/\.ht[^^/]+|\.p|\.cfg)^$]
+ $.403[Permission denied]
+ $.memory(64000)
+# $.log[/access.log]
+]
+
+$response:server[Parser$env:PARSER_VERSION]
+$response:date[^date::now[]]
+$response:connection[close]
+$uri[^request:uri.match[\?.*][]{}]
+$uri[^string:unescape[uri;$uri; $.charset[UTF-8] ]]
+
+^if(def $cfg.log){
+ ^log[$cfg.log]
+}
+^if(def $cfg.memory && $status:memory.ever_allocated_since_compact > $cfg.memory){
+ ^memory:compact[]
+}
+
+^if(def $cfg.auth.url && ^uri.match[$cfg.auth.url]){
+ $basic[$cfg.auth.login:$cfg.auth.password]
+ ^if($env:HTTP_AUTHORIZATION ne "Basic ^basic.base64[]"){
+ $response:WWW-Authenticate[Basic realm="$cfg.auth.realm"]
+ ^return[$response:status[401]]
+ }
+ $env:REMOTE_USER[$cfg.auth.login]
+}
+
+^if(def $cfg.deny && ^uri.match[$cfg.deny]){
+ $response:status[403]
+ $result[^option[$cfg.403]]
+}(def $cfg.[fix-trailing-slash] && ^uri.match[^^[^^.]+[^^/.]^$]){
+ $result[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}]]
+}(def $cfg.index && -f "$uri/$cfg.index"){
+ $result[^file[$uri/$cfg.index]]
+}($cfg.autoindex && -d "$uri"){
+ $result[^index[$uri]]
+}(-f $uri){
+ $result[^file[$uri]]
+}{
+# $form:request[^uri.mid(1)]
+ $result[^option[$cfg.404]]
+}