Annotation of parser3/etc/auto.p.in, revision 1.21
1.21 ! moko 1: #$Id: auto.p.in,v 1.20 2026/10/10 21:52:20 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:
1.20 moko 24: #$CHARSETS[
1.1 moko 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]
1.20 moko 33: #]
1.1 moko 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:
1.21 ! moko 45: $LIMITS[
! 46: $.post_max_size(64*0x400*0x400)
! 47: # $.max_file_size(512*0x400*0x400)
! 48: # $.max_loop(100000)
! 49: # $.max_array_size(1000000)
! 50: # $.max_recursion(1000)
! 51: ]
! 52:
! 53: #$HTTPD[
! 54: # $.mode[threaded]
! 55: #]
! 56:
! 57: #$MAIL[
! 58: # $.SMTP[localhost]
! 59: #]
! 60:
1.1 moko 61: #for ^file::load[name;user-name] mime-type autodetection
1.21 ! moko 62: @mime-types[]
! 63: $result[^table::create{ext mime-type
1.1 moko 64: 7z application/x-7z-compressed
65: avi video/x-msvideo
1.21 ! moko 66: avif image/avif
1.1 moko 67: bmp image/bmp
68: css text/css
1.21 ! moko 69: csv text/csv
1.1 moko 70: doc application/msword
71: docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
72: dtd application/xml-dtd
73: gif image/gif
74: gz application/x-gzip
75: htm text/html
76: html text/html
77: ico image/x-icon
78: jpeg image/jpeg
79: jpg image/jpeg
80: js application/javascript
81: json application/json
82: log text/plain
83: mov video/quicktime
84: mp3 audio/mpeg
85: mp4 video/mp4
86: mpg video/mpeg
87: mpeg video/mpeg
88: mts application/metastream
89: otf font/otf
90: pdf application/pdf
91: png image/png
92: ppt application/powerpoint
93: rar application/vnd.rar
94: rdf application/rdf+xml
95: rss application/rss+xml
96: rtf application/rtf
97: svg image/svg+xml
98: tar application/x-tar
99: tgz application/x-gzip
100: tif image/tiff
101: tiff image/tiff
102: ttf font/ttf
103: txt text/plain
1.21 ! moko 104: wasm application/wasm
1.1 moko 105: wav audio/x-wav
106: xls application/vnd.ms-excel
107: xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
108: xml text/xml
109: xsl text/xml
110: webm video/webm
1.21 ! moko 111: webmanifest application/manifest+json
1.1 moko 112: webp image/webp
113: woff font/woff
114: woff2 font/woff2
115: zip application/zip
116: }]
117:
118: @fatal_error[title;subtitle;body]
119: $response:status(500)
120: $response:content-type[
121: $.value[text/html]
122: $.charset[$response:charset]
123: ]
124: <html>
125: <head><title>$title</title></head>
126: <body>
127: <h1>^if(def $subtitle){$subtitle;$title}</h1>
128: $body
129: #for [x] MSIE friendly
130: ^for[i](0;512/8){<!-- -->}
131: </body>
132: </html>
133:
134:
135: @unhandled_exception_debug[exception;stack]
136: ^fatal_error[Unhandled Exception^if(def $exception.type){ ($exception.type)};$exception.source;
137: <pre>^untaint[html]{$exception.comment}</pre>
138: ^if(def $exception.file){
139: ^untaint[html]{<tt>$exception.file^(${exception.lineno}:$exception.colno^)</tt>}
140: }
141: ^if($stack){
142: <hr/>
143: <table>
144: ^stack.menu{
145: <tr><td>$stack.name</td><td><tt>$stack.file^(${stack.lineno}:$stack.colno^)</tt></td></tr>
146: }
147: </table>
148: }
149: ]
150:
151:
152: @unhandled_exception_release[exception;stack]
153: ^fatal_error[Unhandled Exception;;
154:
155: <p>The server encountered an unhandled exception and was unable to complete your request.</p>
156: <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>
157: <p>More information about this error may be available in the Parser error log or in debug version of unhandled_exception.</p>
158:
159: ]
160:
161:
162: @is_developer[]
163: #change mask to your ip address
164: $result(def $env:REMOTE_ADDR && ^env:REMOTE_ADDR.match[^^127\.0\.0\.1^$])
165:
166:
167: @unhandled_exception[exception;stack]
168: #developer? use debug version to see problem details
169: ^if(^is_developer[]){
170: ^unhandled_exception_debug[$exception;$stack]
171: }{
172: ^if($exception.type eq "file.missing"){
1.8 moko 173: # $response:location[/404/]
1.15 moko 174: ^httpd:404[]
1.1 moko 175: }{
176: ^unhandled_exception_release[$exception;$stack]
177: }
178: }
179:
1.9 moko 180:
1.5 moko 181: @CLASS
182: httpd
1.1 moko 183:
1.10 moko 184: @OPTIONS
185: partial
186:
187: @auto[]
188: ^if(-f "/httpd.p"){
189: ^use[/httpd.p]
190: }
191:
1.5 moko 192: @include[filename]
1.2 moko 193: ^use[$filename; $.main(true) ]
1.7 moko 194: ^MAIN:main[]
1.2 moko 195:
1.5 moko 196: @index[dir][list]
1.2 moko 197: ^fatal_error[Index of $dir;Index of $dir;
198: $list[^file:list[$dir]]
199: ^list.sort{^if($list.dir)[0;1] $list.name}
200: ^list.menu{
201: <a href="$list.name^if($list.dir){/}">^if($list.dir){/}$list.name</a><br/>
202: }
203: ]
204: $response:status(200)
205:
1.5 moko 206: # option can be method, URL or text/code
207: @option[option]
1.6 moko 208: $result[^if($option is junction){^option[]}(^option.match[$cfg.parser]){^include[$option]}{$option}]
1.2 moko 209:
1.5 moko 210: @file[filename]
1.6 moko 211: $result[^if(^filename.match[$cfg.parser]){^include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}]
1.2 moko 212:
1.5 moko 213: @log[filename;detail][now;line]
1.2 moko 214: $now[^date::now[]]
215: $line[$env:REMOTE_ADDR [^now.sql-string[]] "$request:method $request:uri"$detail^#0A]
216: ^line.save[append;$filename]
217:
1.5 moko 218: @404[]
1.3 moko 219: $response:status[404]
1.2 moko 220: The requested URL was not found on this server.
221:
1.11 moko 222: @config[result]
223:
1.10 moko 224: @preprocess[return]
1.2 moko 225:
1.10 moko 226:
227: @main[result][basic]
1.2 moko 228:
1.5 moko 229: #$request:document-root[/website/folder]
230:
1.11 moko 231: $cfg[^config[
1.5 moko 232: $.parser[\.(html)^$]
1.2 moko 233: $.index[index.html]
234: # $.autoindex(true)
1.5 moko 235: $.404[$404]
1.10 moko 236: # $.404[/404.html]
1.4 moko 237: # $.fix-trailing-slash(true)
238: # $.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[change me] $.realm[site administration] ]
1.2 moko 239: $.deny[(/\.ht[^^/]+|\.p|\.cfg)^$]
240: $.403[Permission denied]
241: $.memory(64000)
1.4 moko 242: # $.log[/access.log]
1.11 moko 243: ]]
1.2 moko 244:
245: $response:server[Parser$env:PARSER_VERSION]
246: $response:date[^date::now[]]
247: $response:connection[close]
1.18 moko 248: $uri[$request:path]
1.2 moko 249:
1.5 moko 250: ^if(def $cfg.log){
251: ^log[$cfg.log]
1.2 moko 252: }
1.5 moko 253: ^if(def $cfg.memory && $status:memory.ever_allocated_since_compact > $cfg.memory){
1.2 moko 254: ^memory:compact[]
255: }
256:
1.5 moko 257: ^if(def $cfg.auth.url && ^uri.match[$cfg.auth.url]){
258: $basic[$cfg.auth.login:$cfg.auth.password]
1.2 moko 259: ^if($env:HTTP_AUTHORIZATION ne "Basic ^basic.base64[]"){
1.5 moko 260: $response:WWW-Authenticate[Basic realm="$cfg.auth.realm"]
1.10 moko 261: $response:status[401]
262: ^return[Authorization Required]
1.2 moko 263: }
1.5 moko 264: $env:REMOTE_USER[$cfg.auth.login]
1.2 moko 265: }
266:
1.5 moko 267: ^if(def $cfg.deny && ^uri.match[$cfg.deny]){
1.3 moko 268: $response:status[403]
1.10 moko 269: ^return[^option[$cfg.403]]
1.6 moko 270: }(def $cfg.[fix-trailing-slash] && ^uri.match[^^[^^.]+[^^/.]^$]){
1.10 moko 271: ^return[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}]]
272: }
273:
274: ^preprocess{^return[]}
275:
276: ^if(def $cfg.index && -f "$uri/$cfg.index"){
1.5 moko 277: $result[^file[$uri/$cfg.index]]
278: }($cfg.autoindex && -d "$uri"){
279: $result[^index[$uri]]
1.2 moko 280: }(-f $uri){
1.5 moko 281: $result[^file[$uri]]
1.2 moko 282: }{
1.5 moko 283: $result[^option[$cfg.404]]
1.2 moko 284: }
E-mail: