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

1.4     ! moko        1: #$Id: auto.p.in,v 1.3 2020/12/09 15:47:00 moko Exp $
        !             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"){
                    166: #              ^log404[]
                    167: #              ^location[/404/]
                    168:                $response:status(404)
                    169:        }{
                    170:                ^unhandled_exception_release[$exception;$stack]
                    171:        }
                    172: }
                    173: 
                    174: 
1.2       moko      175: @httpd-include[filename]
                    176: ^use[$filename; $.main(true) ]
                    177: ^main[]
                    178: 
                    179: @httpd-index[dir][list]
                    180: ^fatal_error[Index of $dir;Index of $dir;
                    181:        $list[^file:list[$dir]]
                    182:        ^list.sort{^if($list.dir)[0;1] $list.name}
                    183:        ^list.menu{
                    184:                <a href="$list.name^if($list.dir){/}">^if($list.dir){/}$list.name</a><br/>
                    185:        }
                    186: ]
                    187: $response:status(200)
                    188: 
                    189: @httpd-option[option]
                    190: $result[^if($option is junction){^option[]}(^option.match[$httpd.parser]){^httpd-include[$option]}{$option}]
                    191: 
                    192: @httpd-file[filename]
                    193: $result[^if(^filename.match[$httpd.parser]){^httpd-include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}]
                    194: 
                    195: @httpd-log[filename;detail][now;line]
                    196: $now[^date::now[]]
                    197: $line[$env:REMOTE_ADDR [^now.sql-string[]] "$request:method $request:uri"$detail^#0A]
                    198: ^line.save[append;$filename]
                    199: 
                    200: @httpd-404[]
1.3       moko      201: $response:status[404]
1.2       moko      202: The requested URL was not found on this server.
                    203: 
                    204: 
                    205: @httpd-main[][uri;basic]
                    206: 
                    207: $httpd[
1.4     ! moko      208:        $.parser[\.(html|phtml)^$]
1.2       moko      209:        $.index[index.html]
                    210: #      $.autoindex(true)
                    211:        $.404[$httpd-404]
                    212: #      $.404[/_doc.html]
1.4     ! moko      213: #      $.fix-trailing-slash(true)
        !           214: #      $.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[change me] $.realm[site administration] ]
1.2       moko      215:        $.deny[(/\.ht[^^/]+|\.p|\.cfg)^$]
                    216:        $.403[Permission denied]
                    217:        $.memory(64000)
1.4     ! moko      218: #      $.log[/access.log]
1.2       moko      219: ]
                    220: 
                    221: $response:server[Parser$env:PARSER_VERSION]
                    222: $response:date[^date::now[]]
                    223: $response:connection[close]
                    224: $uri[^request:uri.match[\?.*][]{}]
                    225: $uri[^string:unescape[uri;$uri; $.charset[UTF-8] ]]
                    226: 
                    227: ^if(def $httpd.log){
                    228:        ^httpd-log[$httpd.log]
                    229: }
                    230: ^if(def $httpd.memory && $status:memory.ever_allocated_since_compact > $httpd.memory){
                    231:        ^memory:compact[]
                    232: }
                    233: 
                    234: ^if(def $httpd.auth.url && ^uri.match[$httpd.auth.url]){
                    235:        $basic[$httpd.auth.login:$httpd.auth.password]
                    236:        ^if($env:HTTP_AUTHORIZATION ne "Basic ^basic.base64[]"){
                    237:                $response:WWW-Authenticate[Basic realm="$httpd.auth.realm"]
                    238:                ^return[$response:status[401]]
                    239:        }
                    240:        $env:REMOTE_USER[$httpd.auth.login]
                    241: }
                    242: 
                    243: ^if(def $httpd.deny && ^uri.match[$httpd.deny]){
1.3       moko      244:        $response:status[403]
1.2       moko      245:        $result[^httpd-option[$httpd.403]]
1.4     ! moko      246: }(def $httpd.fix-trailing-slash && ^uri.match[^^[^^.]+[^^/.]^$]){
        !           247:        $result[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}}]]
1.2       moko      248: }(def $httpd.index && -f "$uri/$httpd.index"){
                    249:        $result[^httpd-file[$uri/$httpd.index]]
                    250: }($httpd.autoindex && -d "$uri"){
                    251:        $result[^httpd-index[$uri]]
                    252: }(-f $uri){
                    253:        $result[^httpd-file[$uri]]
                    254: }{
                    255: #      $form:request[^uri.mid(1)]
                    256:        $result[^httpd-option[$httpd.404]]
                    257: }
                    258: 

E-mail: