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