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

1.19    ! moko        1: #$Id: auto.p.in,v 1.18 2024/12/28 14:00:52 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]]
1.13      moko       21: $charsetsdir[@datarootdir@/charsets]
                     22: $sqldriversdir[@libdir@]
1.1       moko       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
1.17      moko       38: mysql  $sqldriversdir/libparser3mysql.@dll_extension@  libmysqlclient.@dll_extension@
1.1       moko       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[
1.12      moko       99:        $.post_max_size(64*0x400*0x400)
1.14      moko      100: #      $.max_file_size(512*0x400*0x400)
                    101: #      $.max_loop(100000)
1.19    ! moko      102: #      $.max_array_size(1000000)
1.14      moko      103: #      $.max_recursion(1000)
1.1       moko      104: ]
                    105: 
1.4       moko      106: #$HTTPD[
                    107: #      $.mode[threaded]
                    108: #]
                    109: 
1.1       moko      110: #$MAIL[
1.4       moko      111: #      $.SMTP[localhost]
1.1       moko      112: #]
                    113: 
                    114: 
                    115: @fatal_error[title;subtitle;body]
                    116: $response:status(500)
                    117: $response:content-type[
                    118:        $.value[text/html]
                    119:        $.charset[$response:charset]
                    120: ]
                    121: <html>
                    122: <head><title>$title</title></head>
                    123: <body>
                    124: <h1>^if(def $subtitle){$subtitle;$title}</h1>
                    125: $body
                    126: #for [x] MSIE friendly
                    127: ^for[i](0;512/8){<!-- -->}
                    128: </body>
                    129: </html>
                    130: 
                    131: 
                    132: @unhandled_exception_debug[exception;stack]
                    133: ^fatal_error[Unhandled Exception^if(def $exception.type){ ($exception.type)};$exception.source;
                    134: <pre>^untaint[html]{$exception.comment}</pre>
                    135: ^if(def $exception.file){
                    136:        ^untaint[html]{<tt>$exception.file^(${exception.lineno}:$exception.colno^)</tt>}
                    137: }
                    138: ^if($stack){
                    139:        <hr/>
                    140:        <table>
                    141:        ^stack.menu{
                    142:                <tr><td>$stack.name</td><td><tt>$stack.file^(${stack.lineno}:$stack.colno^)</tt></td></tr>
                    143:        }
                    144:        </table>
                    145: }
                    146: ]
                    147: 
                    148: 
                    149: @unhandled_exception_release[exception;stack]
                    150: ^fatal_error[Unhandled Exception;;
                    151: 
                    152: <p>The server encountered an unhandled exception and was unable to complete your request.</p>
                    153: <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>
                    154: <p>More information about this error may be available in the Parser error log or in debug version of unhandled_exception.</p>
                    155: 
                    156: ]
                    157: 
                    158: 
                    159: @is_developer[]
                    160: #change mask to your ip address
                    161: $result(def $env:REMOTE_ADDR && ^env:REMOTE_ADDR.match[^^127\.0\.0\.1^$])
                    162: 
                    163: 
                    164: @unhandled_exception[exception;stack]
                    165: #developer? use debug version to see problem details
                    166: ^if(^is_developer[]){
                    167:        ^unhandled_exception_debug[$exception;$stack]
                    168: }{
                    169:        ^if($exception.type eq "file.missing"){
1.8       moko      170: #              $response:location[/404/]
1.15      moko      171:                ^httpd:404[]
1.1       moko      172:        }{
                    173:                ^unhandled_exception_release[$exception;$stack]
                    174:        }
                    175: }
                    176: 
1.9       moko      177: 
1.5       moko      178: @CLASS
                    179: httpd
1.1       moko      180: 
1.10      moko      181: @OPTIONS
                    182: partial
                    183: 
                    184: @auto[]
                    185: ^if(-f "/httpd.p"){
                    186:        ^use[/httpd.p]
                    187: }
                    188: 
1.5       moko      189: @include[filename]
1.2       moko      190: ^use[$filename; $.main(true) ]
1.7       moko      191: ^MAIN:main[]
1.2       moko      192: 
1.5       moko      193: @index[dir][list]
1.2       moko      194: ^fatal_error[Index of $dir;Index of $dir;
                    195:        $list[^file:list[$dir]]
                    196:        ^list.sort{^if($list.dir)[0;1] $list.name}
                    197:        ^list.menu{
                    198:                <a href="$list.name^if($list.dir){/}">^if($list.dir){/}$list.name</a><br/>
                    199:        }
                    200: ]
                    201: $response:status(200)
                    202: 
1.5       moko      203: # option can be method, URL or text/code
                    204: @option[option]
1.6       moko      205: $result[^if($option is junction){^option[]}(^option.match[$cfg.parser]){^include[$option]}{$option}]
1.2       moko      206: 
1.5       moko      207: @file[filename]
1.6       moko      208: $result[^if(^filename.match[$cfg.parser]){^include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}]
1.2       moko      209: 
1.5       moko      210: @log[filename;detail][now;line]
1.2       moko      211: $now[^date::now[]]
                    212: $line[$env:REMOTE_ADDR [^now.sql-string[]] "$request:method $request:uri"$detail^#0A]
                    213: ^line.save[append;$filename]
                    214: 
1.5       moko      215: @404[]
1.3       moko      216: $response:status[404]
1.2       moko      217: The requested URL was not found on this server.
                    218: 
1.11      moko      219: @config[result]
                    220: 
1.10      moko      221: @preprocess[return]
1.2       moko      222: 
1.10      moko      223: 
                    224: @main[result][basic]
1.2       moko      225: 
1.5       moko      226: #$request:document-root[/website/folder]
                    227: 
1.11      moko      228: $cfg[^config[
1.5       moko      229:        $.parser[\.(html)^$]
1.2       moko      230:        $.index[index.html]
                    231: #      $.autoindex(true)
1.5       moko      232:        $.404[$404]
1.10      moko      233: #      $.404[/404.html]
1.4       moko      234: #      $.fix-trailing-slash(true)
                    235: #      $.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[change me] $.realm[site administration] ]
1.2       moko      236:        $.deny[(/\.ht[^^/]+|\.p|\.cfg)^$]
                    237:        $.403[Permission denied]
                    238:        $.memory(64000)
1.4       moko      239: #      $.log[/access.log]
1.11      moko      240: ]]
1.2       moko      241: 
                    242: $response:server[Parser$env:PARSER_VERSION]
                    243: $response:date[^date::now[]]
                    244: $response:connection[close]
1.18      moko      245: $uri[$request:path]
1.2       moko      246: 
1.5       moko      247: ^if(def $cfg.log){
                    248:        ^log[$cfg.log]
1.2       moko      249: }
1.5       moko      250: ^if(def $cfg.memory && $status:memory.ever_allocated_since_compact > $cfg.memory){
1.2       moko      251:        ^memory:compact[]
                    252: }
                    253: 
1.5       moko      254: ^if(def $cfg.auth.url && ^uri.match[$cfg.auth.url]){
                    255:        $basic[$cfg.auth.login:$cfg.auth.password]
1.2       moko      256:        ^if($env:HTTP_AUTHORIZATION ne "Basic ^basic.base64[]"){
1.5       moko      257:                $response:WWW-Authenticate[Basic realm="$cfg.auth.realm"]
1.10      moko      258:                $response:status[401]
                    259:                ^return[Authorization Required]
1.2       moko      260:        }
1.5       moko      261:        $env:REMOTE_USER[$cfg.auth.login]
1.2       moko      262: }
                    263: 
1.5       moko      264: ^if(def $cfg.deny && ^uri.match[$cfg.deny]){
1.3       moko      265:        $response:status[403]
1.10      moko      266:        ^return[^option[$cfg.403]]
1.6       moko      267: }(def $cfg.[fix-trailing-slash] && ^uri.match[^^[^^.]+[^^/.]^$]){
1.10      moko      268:        ^return[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}]]
                    269: }
                    270: 
                    271: ^preprocess{^return[]}
                    272: 
                    273: ^if(def $cfg.index && -f "$uri/$cfg.index"){
1.5       moko      274:        $result[^file[$uri/$cfg.index]]
                    275: }($cfg.autoindex && -d "$uri"){
                    276:        $result[^index[$uri]]
1.2       moko      277: }(-f $uri){
1.5       moko      278:        $result[^file[$uri]]
1.2       moko      279: }{
1.5       moko      280:        $result[^option[$cfg.404]]
1.2       moko      281: }

E-mail: