--- parser3/etc/auto.p.in 2020/12/09 15:36:45 1.2 +++ parser3/etc/auto.p.in 2021/01/20 13:44:18 1.11 @@ -1,4 +1,20 @@ -#$Id: auto.p.in,v 1.2 2020/12/09 15:36:45 moko Exp $ +#$Id: auto.p.in,v 1.11 2021/01/20 13:44:18 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,11 +171,22 @@ $result(def $env:REMOTE_ADDR && ^env:REM } -@httpd-include[filename] +@CLASS +httpd + +@OPTIONS +partial + +@auto[] +^if(-f "/httpd.p"){ + ^use[/httpd.p] +} + +@include[filename] ^use[$filename; $.main(true) ] -^main[] +^MAIN:main[] -@httpd-index[dir][list] +@index[dir][list] ^fatal_error[Index of $dir;Index of $dir; $list[^file:list[$dir]] ^list.sort{^if($list.dir)[0;1] $list.name} @@ -169,36 +196,44 @@ $result(def $env:REMOTE_ADDR && ^env:REM ] $response:status(200) -@httpd-option[option] -$result[^if($option is junction){^option[]}(^option.match[$httpd.parser]){^httpd-include[$option]}{$option}] +# option can be method, URL or text/code +@option[option] +$result[^if($option is junction){^option[]}(^option.match[$cfg.parser]){^include[$option]}{$option}] -@httpd-file[filename] -$result[^if(^filename.match[$httpd.parser]){^httpd-include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}] +@file[filename] +$result[^if(^filename.match[$cfg.parser]){^include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}] -@httpd-log[filename;detail][now;line] +@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] -@httpd-404[] -The requested URL was not found on this server. +@404[] $response:status[404] +The requested URL was not found on this server. + +@config[result] + +@preprocess[return] -@httpd-main[][uri;basic] +@main[result][basic] -$httpd[ - $.parser[(\.html^$)] +#$request:document-root[/website/folder] + +$cfg[^config[ + $.parser[\.(html)^$] $.index[index.html] # $.autoindex(true) - $.404[$httpd-404] -# $.404[/_doc.html] - $.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[test] $.realm[site administration] ] + $.404[$404] +# $.404[/404.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] -] +# $.log[/access.log] +]] $response:server[Parser$env:PARSER_VERSION] $response:date[^date::now[]] @@ -206,47 +241,38 @@ $response:connection[close] $uri[^request:uri.match[\?.*][]{}] $uri[^string:unescape[uri;$uri; $.charset[UTF-8] ]] -^if(def $httpd.log){ - ^httpd-log[$httpd.log] +^if(def $cfg.log){ + ^log[$cfg.log] } -^if(def $httpd.memory && $status:memory.ever_allocated_since_compact > $httpd.memory){ +^if(def $cfg.memory && $status:memory.ever_allocated_since_compact > $cfg.memory){ ^memory:compact[] } -^if(def $httpd.auth.url && ^uri.match[$httpd.auth.url]){ - $basic[$httpd.auth.login:$httpd.auth.password] +^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="$httpd.auth.realm"] - ^return[$response:status[401]] + $response:WWW-Authenticate[Basic realm="$cfg.auth.realm"] + $response:status[401] + ^return[Authorization Required] } - $env:REMOTE_USER[$httpd.auth.login] + $env:REMOTE_USER[$cfg.auth.login] } -^if(def $httpd.deny && ^uri.match[$httpd.deny]){ - $result[^httpd-option[$httpd.403]] -}(def $httpd.index && -f "$uri/$httpd.index"){ - $result[^httpd-file[$uri/$httpd.index]] -}($httpd.autoindex && -d "$uri"){ - $result[^httpd-index[$uri]] -}(-f $uri){ - $result[^httpd-file[$uri]] -}{ -# $form:request[^uri.mid(1)] - $result[^httpd-option[$httpd.404]] +^if(def $cfg.deny && ^uri.match[$cfg.deny]){ + $response:status[403] + ^return[^option[$cfg.403]] +}(def $cfg.[fix-trailing-slash] && ^uri.match[^^[^^.]+[^^/.]^$]){ + ^return[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}]] } +^preprocess{^return[]} -@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] +^if(def $cfg.index && -f "$uri/$cfg.index"){ + $result[^file[$uri/$cfg.index]] +}($cfg.autoindex && -d "$uri"){ + $result[^index[$uri]] +}(-f $uri){ + $result[^file[$uri]] +}{ + $result[^option[$cfg.404]] +}