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