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