File: auto.p.in

package info (click to toggle)
parser 3.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,520 kB
  • sloc: cpp: 35,302; sh: 15,643; ansic: 10,375; yacc: 1,378; makefile: 242
file content (281 lines) | stat: -rw-r--r-- 6,769 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#$Id: auto.p.in,v 1.18 2024/12/28 14:00:52 moko Exp $

@auto[]
#source/client charsets
$request:charset[utf-8]
$response:charset[utf-8]

$response:content-type[
	$.value[text/html]
	$.charset[$response:charset]
]

#$SQL.connect-string[mysql://user:pass@host/db?charset=utf8]
#$SQL.connect-string[sqlite://db]
#$SQL.connect-string[pgsql://user:pass@host/db]
#$SQL.connect-string[odbc://DSN=datasource^;UID=user^;PWD=password]


@conf[filespec]
$confdir[^file:dirname[$filespec]]
$charsetsdir[@datarootdir@/charsets]
$sqldriversdir[@libdir@]

$CHARSETS[
#	$.cp866[$charsetsdir/cp866.cfg]
#	$.koi8-r[$charsetsdir/koi8-r.cfg]
#	$.koi8-u[$charsetsdir/koi8-u.cfg]
#	$.windows-1250[$charsetsdir/windows-1250.cfg]
#	$.windows-1251[$charsetsdir/windows-1251.cfg]
#	$.windows-1254[$charsetsdir/windows-1254.cfg]
#	$.windows-1257[$charsetsdir/windows-1257.cfg]
#	$.x-mac-cyrillic[$charsetsdir/x-mac-cyrillic.cfg]
]

#change your client libraries paths to those on your system
$SQL[
	$.drivers[^table::create{protocol	driver	client
mysql	$sqldriversdir/libparser3mysql.@dll_extension@	libmysqlclient.@dll_extension@
#sqlite	$sqldriversdir/libparser3sqlite.@dll_extension@	libsqlite3.@dll_extension@
#pgsql	$sqldriversdir/libparser3pgsql.@dll_extension@	libpq.@dll_extension@
#oracle	$sqldriversdir/libparser3oracle.@dll_extension@	libclntsh.@dll_extension@
}]
]

#for ^file::load[name;user-name] mime-type autodetection
$MIME-TYPES[^table::create{ext	mime-type
7z	application/x-7z-compressed
avi	video/x-msvideo
bmp	image/bmp
css	text/css
cvs	text/csv
doc	application/msword
docx	application/vnd.openxmlformats-officedocument.wordprocessingml.document
dtd	application/xml-dtd
gif	image/gif
gz	application/x-gzip
htm	text/html
html	text/html
ico	image/x-icon
jpeg	image/jpeg
jpg	image/jpeg
js	application/javascript
json	application/json
log	text/plain
mov	video/quicktime
mp3	audio/mpeg
mp4	video/mp4
mpg	video/mpeg
mpeg	video/mpeg
mts	application/metastream
otf	font/otf
pdf	application/pdf
png	image/png
ppt	application/powerpoint
rar	application/vnd.rar
rdf	application/rdf+xml
rss	application/rss+xml
rtf	application/rtf
svg	image/svg+xml
tar	application/x-tar
tgz	application/x-gzip
tif	image/tiff
tiff	image/tiff
ttf	font/ttf
txt	text/plain
wav	audio/x-wav
xls	application/vnd.ms-excel
xlsx	application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xml	text/xml
xsl	text/xml
webm	video/webm
webp	image/webp
woff	font/woff
woff2	font/woff2
zip	application/zip
}]

$LIMITS[
	$.post_max_size(64*0x400*0x400)
#	$.max_file_size(512*0x400*0x400)
#	$.max_loop(100000)
#	$.max_array(1000000)
#	$.max_recursion(1000)
]

#$HTTPD[
#	$.mode[threaded]
#]

#$MAIL[
#	$.SMTP[localhost]
#]


@fatal_error[title;subtitle;body]
$response:status(500)
$response:content-type[
	$.value[text/html]
	$.charset[$response:charset]
]
<html>
<head><title>$title</title></head>
<body>
<h1>^if(def $subtitle){$subtitle;$title}</h1>
$body
#for [x] MSIE friendly
^for[i](0;512/8){<!-- -->}
</body>
</html>


@unhandled_exception_debug[exception;stack]
^fatal_error[Unhandled Exception^if(def $exception.type){ ($exception.type)};$exception.source;
<pre>^untaint[html]{$exception.comment}</pre>
^if(def $exception.file){
	^untaint[html]{<tt>$exception.file^(${exception.lineno}:$exception.colno^)</tt>}
}
^if($stack){
	<hr/>
	<table>
	^stack.menu{
		<tr><td>$stack.name</td><td><tt>$stack.file^(${stack.lineno}:$stack.colno^)</tt></td></tr>
	}
	</table>
}
]


@unhandled_exception_release[exception;stack]
^fatal_error[Unhandled Exception;;

<p>The server encountered an unhandled exception and was unable to complete your request.</p>
<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>
<p>More information about this error may be available in the Parser error log or in debug version of unhandled_exception.</p>

]


@is_developer[]
#change mask to your ip address
$result(def $env:REMOTE_ADDR && ^env:REMOTE_ADDR.match[^^127\.0\.0\.1^$])


@unhandled_exception[exception;stack]
#developer? use debug version to see problem details
^if(^is_developer[]){
	^unhandled_exception_debug[$exception;$stack]
}{
	^if($exception.type eq "file.missing"){
#		$response:location[/404/]
		^httpd:404[]
	}{
		^unhandled_exception_release[$exception;$stack]
	}
}


@CLASS
httpd

@OPTIONS
partial

@auto[]
^if(-f "/httpd.p"){
	^use[/httpd.p]
}

@include[filename]
^use[$filename; $.main(true) ]
^MAIN:main[]

@index[dir][list]
^fatal_error[Index of $dir;Index of $dir;
	$list[^file:list[$dir]]
	^list.sort{^if($list.dir)[0;1] $list.name}
	^list.menu{
		<a href="$list.name^if($list.dir){/}">^if($list.dir){/}$list.name</a><br/>
	}
]
$response:status(200)

# option can be method, URL or text/code
@option[option]
$result[^if($option is junction){^option[]}(^option.match[$cfg.parser]){^include[$option]}{$option}]

@file[filename]
$result[^if(^filename.match[$cfg.parser]){^include[$filename]}{$response:body[ $.file[$filename] $.name[] ]}]

@log[filename;detail][now;line]
$now[^date::now[]]
$line[$env:REMOTE_ADDR [^now.sql-string[]] "$request:method $request:uri"$detail^#0A]
^line.save[append;$filename]

@404[]
$response:status[404]
The requested URL was not found on this server.

@config[result]

@preprocess[return]


@main[result][basic]

#$request:document-root[/website/folder]

$cfg[^config[
	$.parser[\.(html)^$]
	$.index[index.html]
#	$.autoindex(true)
	$.404[$404]
#	$.404[/404.html]
#	$.fix-trailing-slash(true)
#	$.auth[ $.url[^^/\.?admin/] $.login[admin] $.password[change me] $.realm[site administration] ]
	$.deny[(/\.ht[^^/]+|\.p|\.cfg)^$]
	$.403[Permission denied]
	$.memory(64000)
#	$.log[/access.log]
]]

$response:server[Parser$env:PARSER_VERSION]
$response:date[^date::now[]]
$response:connection[close]
$uri[$request:path]

^if(def $cfg.log){
	^log[$cfg.log]
}
^if(def $cfg.memory && $status:memory.ever_allocated_since_compact > $cfg.memory){
	^memory:compact[]
}

^if(def $cfg.auth.url && ^uri.match[$cfg.auth.url]){
	$basic[$cfg.auth.login:$cfg.auth.password]
	^if($env:HTTP_AUTHORIZATION ne "Basic ^basic.base64[]"){
		$response:WWW-Authenticate[Basic realm="$cfg.auth.realm"]
		$response:status[401]
		^return[Authorization Required]
	}
	$env:REMOTE_USER[$cfg.auth.login]
}

^if(def $cfg.deny && ^uri.match[$cfg.deny]){
	$response:status[403]
	^return[^option[$cfg.403]]
}(def $cfg.[fix-trailing-slash] && ^uri.match[^^[^^.]+[^^/.]^$]){
	^return[$response:location[$uri/^if(def $request:query){?^taint[as-is;$request:query]}]]
}

^preprocess{^return[]}

^if(def $cfg.index && -f "$uri/$cfg.index"){
	$result[^file[$uri/$cfg.index]]
}($cfg.autoindex && -d "$uri"){
	$result[^index[$uri]]
}(-f $uri){
	$result[^file[$uri]]
}{
	$result[^option[$cfg.404]]
}