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