Annotation of parser3/etc/auto.p.in, revision 1.10

1.10    ! moko        1: #$Id: auto.p.in,v 1.9 2021/01/15 20:43:05 moko Exp $
1.4       moko        2: 
                      3: @auto[]
                      4: #source/client charsets
                      5: $request:charset[utf-8]
                      6: $response:charset[utf-8]
                      7: 
                      8: $response:content-type[
                      9:        $.value[text/html]
                     10:        $.charset[$response:charset]
                     11: ]
                     12: 
                     13: #$SQL.connect-string[mysql://user:pass@host/db?charset=utf8]
                     14: #$SQL.connect-string[sqlite://db]
                     15: #$SQL.connect-string[pgsql://user:pass@host/db]
                     16: #$SQL.connect-string[odbc://DSN=datasource^;UID=user^;PWD=password]
                     17: 
1.1       moko       18: 
                     19: @conf[filespec]
                     20: $confdir[^file:dirname[$filespec]]
                     21: $charsetsdir[$confdir/charsets]
                     22: $sqldriversdir[$confdir/lib]
                     23: 
                     24: $CHARSETS[
                     25: #      $.cp866[$charsetsdir/cp866.cfg]
                     26: #      $.koi8-r[$charsetsdir/koi8-r.cfg]
                     27: #      $.koi8-u[$charsetsdir/koi8-u.cfg]
                     28: #      $.windows-1250[$charsetsdir/windows-1250.cfg]
                     29: #      $.windows-1251[$charsetsdir/windows-1251.cfg]
                     30: #      $.windows-1254[$charsetsdir/windows-1254.cfg]
                     31: #      $.windows-1257[$charsetsdir/windows-1257.cfg]
                     32: #      $.x-mac-cyrillic[$charsetsdir/x-mac-cyrillic.cfg]
                     33: ]
                     34: 
                     35: #change your client libraries paths to those on your system
                     36: $SQL[
                     37:        $.drivers[^table::create{protocol       driver  client
                     38: mysql  $sqldriversdir/libparser3mysql.@dll_extension@  libmysqlclient.@dll_extension@
                     39: #sqlite        $sqldriversdir/libparser3sqlite.@dll_extension@ libsqlite3.@dll_extension@
                     40: #pgsql $sqldriversdir/libparser3pgsql.@dll_extension@  libpq.@dll_extension@
                     41: #oracle        $sqldriversdir/libparser3oracle.@dll_extension@ libclntsh.@dll_extension@
                     42: }]
                     43: ]
                     44: 
                     45: #for ^file::load[name;user-name] mime-type autodetection
                     46: $MIME-TYPES[^table::create{ext mime-type
                     47: 7z     application/x-7z-compressed
                     48: avi    video/x-msvideo
                     49: bmp    image/bmp
                     50: css    text/css
                     51: cvs    text/csv
                     52: doc    application/msword
                     53: docx   application/vnd.openxmlformats-officedocument.wordprocessingml.document
                     54: dtd    application/xml-dtd
                     55: gif    image/gif
                     56: gz     application/x-gzip
                     57: htm    text/html
                     58: html   text/html
                     59: ico    image/x-icon
                     60: jpeg   image/jpeg
                     61: jpg    image/jpeg
                     62: js     application/javascript
                     63: json   application/json
                     64: log    text/plain
                     65: mov    video/quicktime
                     66: mp3    audio/mpeg
                     67: mp4    video/mp4
                     68: mpg    video/mpeg
                     69: mpeg   video/mpeg
                     70: mts    application/metastream
                     71: otf    font/otf
                     72: pdf    application/pdf
                     73: png    image/png
                     74: ppt    application/powerpoint
                     75: rar    application/vnd.rar
                     76: rdf    application/rdf+xml
                     77: rss    application/rss+xml
                     78: rtf    application/rtf
                     79: svg    image/svg+xml
                     80: tar    application/x-tar
                     81: tgz    application/x-gzip
                     82: tif    image/tiff
                     83: tiff   image/tiff
                     84: ttf    font/ttf
                     85: txt    text/plain
                     86: wav    audio/x-wav
                     87: xls    application/vnd.ms-excel
                     88: xlsx   application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                     89: xml    text/xml
                     90: xsl    text/xml
                     91: webm   video/webm
                     92: webp   image/webp
                     93: woff   font/woff
                     94: woff2  font/woff2
                     95: zip    application/zip
                     96: }]
                     97: 
                     98: $LIMITS[
                     99:        $.post_max_size(10*0x400*0x400)
                    100: ]
                    101: 
1.4       moko      102: #$HTTPD[
                    103: #      $.mode[threaded]
                    104: #]
                    105: 
1.1       moko      106: #$MAIL[
1.4       moko      107: #      $.SMTP[localhost]
1.1       moko      108: #]
                    109: 
                    110: 
                    111: @fatal_error[title;subtitle;body]
                    112: $response:status(500)
                    113: $response:content-type[
                    114:        $.value[text/html]
                    115:        $.charset[$response:charset]
                    116: ]
                    117: <html>
                    118: <head><title>$title</title></head>
                    119: <body>
                    120: <h1>^if(def $subtitle){$subtitle;$title}</h1>
                    121: $body
                    122: #for [x] MSIE friendly
                    123: ^for[i](0;512/8){<!-- -->}
                    124: </body>
                    125: </html>
                    126: 
                    127: 
                    128: @unhandled_exception_debug[exception;stack]
                    129: ^fatal_error[Unhandled Exception^if(def $exception.type){ ($exception.type)};$exception.source;
                    130: <pre>^untaint[html]{$exception.comment}</pre>
                    131: ^if(def $exception.file){
                    132:        ^untaint[html]{<tt>$exception.file^(${exception.lineno}:$exception.colno^)</tt>}
                    133: }
                    134: ^if($stack){
                    135:        <hr/>
                    136:        <table>
                    137:        ^stack.menu{
                    138:                <tr><td>$stack.name</td><td><tt>$stack.file^(${stack.lineno}:$stack.colno^)</tt></td></tr>
                    139:        }
                    140:        </table>
                    141: }
                    142: ]
                    143: 
                    144: 
                    145: @unhandled_exception_release[exception;stack]
                    146: ^fatal_error[Unhandled Exception;;
                    147: 
                    148: <p>The server encountered an unhandled exception and was unable to complete your request.</p>
                    149: <p>Please contact the server administrator, $env:SERVER_ADMIN and inform them of the time the error occurred, and anything you might have done that may have caused the error.</p>
                    150: <p>More information about this error may be available in the Parser error log or in debug version of unhandled_exception.</p>
                    151: 
                    152: ]
                    153: 
                    154: 
                    155: @is_developer[]
                    156: #change mask to your ip address
                    157: $result(def $env:REMOTE_ADDR && ^env:REMOTE_ADDR.match[^^127\.0\.0\.1^$])
                    158: 
                    159: 
                    160: @unhandled_exception[exception;stack]
                    161: #developer? use debug version to see problem details
                    162: ^if(^is_developer[]){
                    163:        ^unhandled_exception_debug[$exception;$stack]
                    164: }{
                    165:        ^if($exception.type eq "file.missing"){
1.8       moko      166: #              $response:location[/404/]
1.1       moko      167:                $response:status(404)
                    168:        }{
                    169:                ^unhandled_exception_release[$exception;$stack]
                    170:        }
                    171: }
                    172: 
1.9       moko      173: 
1.5       moko      174: @CLASS
                    175: httpd
1.1       moko      176: 
1.10    ! moko      177: @OPTIONS
        !           178: partial
        !           179: 
        !           180: @auto[]
        !           181: ^if(-f "/httpd.p"){
        !           182:        ^use[/httpd.p]
        !           183: }
        !           184: 
1.5       moko      185: @include[filename]
1.2       moko      186: ^use[$filename; $.main(true) ]
1.7       moko      187: ^MAIN:main[]
1.2       moko      188: 
1.5       moko      189: @index[dir][list]
1.2       moko      190: ^fatal_error[Index of $dir;Index of $dir;
                    191:        $list[^file:list[$dir]]
                    192:        ^list.sort{^if($list.dir)[0;1] $list.name}
                    193:        ^list.menu{
                    194:                <a href="$list.name^if($list.dir){/}">^if($list.dir){/}$list.name</a><br/>
                    195:        }
                    196: ]
                    197: $response:status(200)
                    198: 
1.5       moko      199: # option can be method, URL or text/code
                    200: @option[option]
1.6       moko      201: $result[^if($option is junction){^option[]}(^option.match[$cfg.parser]){^include[$option]}{$option}]
1.2       moko      202: 
1.5       moko      203: @file[filename]
1.6       moko      204: $result[^if(^filename.match[$cfg.parser]){^include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}]
1.2       moko      205: 
1.5       moko      206: @log[filename;detail][now;line]
1.2       moko      207: $now[^date::now[]]
                    208: $line[$env:REMOTE_ADDR [^now.sql-string[]] "$request:method $request:uri"$detail^#0A]
                    209: ^line.save[append;$filename]
                    210: 
1.5       moko      211: @404[]
1.3       moko      212: $response:status[404]
1.2       moko      213: The requested URL was not found on this server.
                    214: 
1.10    ! moko      215: @preprocess[return]
1.2       moko      216: 
1.10    ! moko      217: 
        !           218: @main[result][basic]
1.2       moko      219: 
1.5       moko      220: #$request:document-root[/website/folder]
                    221: 
                    222: $cfg[
                    223:        $.parser[\.(html)^$]
1.2       moko      224:        $.index[index.html]
                    225: #      $.autoindex(true)
1.5       moko      226:        $.404[$404]
1.10    ! moko      227: #      $.404[/404.html]
1.4       moko      228: #      $.fix-trailing-slash(true)
                    229: #      $.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[change me] $.realm[site administration] ]
1.2       moko      230:        $.deny[(/\.ht[^^/]+|\.p|\.cfg)^$]
                    231:        $.403[Permission denied]
                    232:        $.memory(64000)
1.4       moko      233: #      $.log[/access.log]
1.2       moko      234: ]
                    235: 
                    236: $response:server[Parser$env:PARSER_VERSION]
                    237: $response:date[^date::now[]]
                    238: $response:connection[close]
                    239: $uri[^request:uri.match[\?.*][]{}]
                    240: $uri[^string:unescape[uri;$uri; $.charset[UTF-8] ]]
                    241: 
1.5       moko      242: ^if(def $cfg.log){
                    243:        ^log[$cfg.log]
1.2       moko      244: }
1.5       moko      245: ^if(def $cfg.memory && $status:memory.ever_allocated_since_compact > $cfg.memory){
1.2       moko      246:        ^memory:compact[]
                    247: }
                    248: 
1.5       moko      249: ^if(def $cfg.auth.url && ^uri.match[$cfg.auth.url]){
                    250:        $basic[$cfg.auth.login:$cfg.auth.password]
1.2       moko      251:        ^if($env:HTTP_AUTHORIZATION ne "Basic ^basic.base64[]"){
1.5       moko      252:                $response:WWW-Authenticate[Basic realm="$cfg.auth.realm"]
1.10    ! moko      253:                $response:status[401]
        !           254:                ^return[Authorization Required]
1.2       moko      255:        }
1.5       moko      256:        $env:REMOTE_USER[$cfg.auth.login]
1.2       moko      257: }
                    258: 
1.5       moko      259: ^if(def $cfg.deny && ^uri.match[$cfg.deny]){
1.3       moko      260:        $response:status[403]
1.10    ! moko      261:        ^return[^option[$cfg.403]]
1.6       moko      262: }(def $cfg.[fix-trailing-slash] && ^uri.match[^^[^^.]+[^^/.]^$]){
1.10    ! moko      263:        ^return[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}]]
        !           264: }
        !           265: 
        !           266: ^preprocess{^return[]}
        !           267: 
        !           268: ^if(def $cfg.index && -f "$uri/$cfg.index"){
1.5       moko      269:        $result[^file[$uri/$cfg.index]]
                    270: }($cfg.autoindex && -d "$uri"){
                    271:        $result[^index[$uri]]
1.2       moko      272: }(-f $uri){
1.5       moko      273:        $result[^file[$uri]]
1.2       moko      274: }{
1.5       moko      275:        $result[^option[$cfg.404]]
1.2       moko      276: }

E-mail: