first commit
This commit is contained in:
		
						commit
						dc1afb2cb2
					
				
					 228 changed files with 12529 additions and 0 deletions
				
			
		
							
								
								
									
										6
									
								
								bin/contrib/rc-httpd/handlers/authorize
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								bin/contrib/rc-httpd/handlers/authorize
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| #!/bin/rc | ||||
| if(~ $REMOTE_USER ''){ | ||||
| 	extra_headers=($extra_headers 'WWW-Authenticate: Basic realm="'$"SERVER_NAME'"') | ||||
| 	error 401 | ||||
| 	exit | ||||
| } | ||||
							
								
								
									
										46
									
								
								bin/contrib/rc-httpd/handlers/cgi
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										46
									
								
								bin/contrib/rc-httpd/handlers/cgi
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| #!/bin/rc | ||||
| fn filter_headers{ | ||||
| 	response=(200 OK) | ||||
| 	lines='' | ||||
| 	done=false | ||||
| 	while(~ $done false){ | ||||
| 		line=`{getline} | ||||
| 		head=`{echo $line | awk '{print tolower($1)}'} | ||||
| 		if(~ $head status:*) | ||||
| 			response=`{echo $line | awk '{$1="" ; print}'} | ||||
| 		if not if(~ $line '') | ||||
| 			done=true | ||||
| 		if not | ||||
| 			lines=$"lines^$"line^$cr^' | ||||
| ' | ||||
| 	} | ||||
| 	echo 'HTTP/1.1' $"response^$cr | ||||
| 	echo -n $"lines | ||||
| 	do_log $response(1) | ||||
| } | ||||
| 
 | ||||
| fn run_cgi { | ||||
| 	path=$cgi_path exec $"cgi_bin $params || echo 'Status: 500' | ||||
| } | ||||
| 
 | ||||
| cgi_bin=$1 | ||||
| cgi_dir=. | ||||
| if(! ~ $#* 1) | ||||
| 	cgi_dir=$*($#*) | ||||
| if not if(~ $"cgi_bin /*){ | ||||
| 	cgi_dir=`{basename -d $"cgi_bin} | ||||
| 	cgi_dir=$"cgi_dir | ||||
| } | ||||
| if(! ~ $"cgi_bin */*) | ||||
| 	cgi_bin=./$"cgi_bin | ||||
| if(! builtin cd $"cgi_dir >[2]/dev/null || ! test -x $"cgi_bin){ | ||||
| 	error 500 | ||||
| 	exit | ||||
| } | ||||
| 
 | ||||
| run_cgi | { | ||||
| 	filter_headers | ||||
| 	emit_extra_headers | ||||
| 	echo $cr | ||||
| 	exec cat | ||||
| } | ||||
							
								
								
									
										111
									
								
								bin/contrib/rc-httpd/handlers/dir-index
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										111
									
								
								bin/contrib/rc-httpd/handlers/dir-index
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,111 @@ | |||
| #!/bin/rc | ||||
| PATH_INFO=`{echo $PATH_INFO | urldecode.awk} | ||||
| full_path=$"FS_ROOT^$"PATH_INFO | ||||
| full_path=$"full_path | ||||
| if(! test -d $full_path){ | ||||
| 	error 404 | ||||
| 	exit | ||||
| } | ||||
| if(! test -r $full_path -x $full_path){ | ||||
| 	error 503 | ||||
| 	exit | ||||
| } | ||||
| do_log 200 | ||||
| builtin cd $full_path | ||||
| if(~ $"NOINDEXFILE ^ $"NOINDEX ''){ | ||||
| 	ifile=index.htm* | ||||
| 	if(! ~ $ifile(1) *'*'){ | ||||
| 		PATH_INFO=$ifile(1) | ||||
| 		FS_ROOT='' | ||||
| 		exec serve-static | ||||
| 	} | ||||
| } | ||||
| title=`{echo $SITE_TITLE | sed s,%s,^$"PATH_INFO^,} | ||||
| title=$"title | ||||
| lso=() | ||||
| switch($2){ | ||||
| case size | ||||
| 	# ls has no option to sort by size | ||||
| 	# could pipe it through sort, I suppose | ||||
| case date | ||||
| 	lso=-t | ||||
| } | ||||
| echo 'HTTP/1.1 200 OK'^$cr | ||||
| emit_extra_headers | ||||
| echo 'Content-type: text/html'^$cr | ||||
| echo $cr | ||||
| echo '<html> | ||||
| <head> | ||||
| <title>'^$title^'</title> | ||||
| <style type="text/css"> | ||||
| 	.size { | ||||
| 		text-align: right; | ||||
| 		padding-right: 4pt; | ||||
| 	} | ||||
| 	.day { | ||||
| 		text-align: right; | ||||
| 		padding-right: 3pt; | ||||
| 	} | ||||
| 	.datetime { | ||||
| 		text-align: right; | ||||
| 	} | ||||
| 	.name { | ||||
| 		text-align: right; | ||||
| 		padding-left: 3pt; | ||||
| 	} | ||||
| </style> | ||||
| </head> | ||||
| <body>' | ||||
| echo '<h1>'^$title^'</h1>' | ||||
| if(! ~ $PATH_INFO /) | ||||
| 	echo '<a href="../">Parent directory</a>' | ||||
| echo '<table>' | ||||
| ls -lQ $lso | awk ' | ||||
| function urlencode(loc){ | ||||
| 	# very minimal encoding, just enough for our static-file purposes | ||||
| 	url=loc | ||||
| 	gsub("%", "%25", url)		# this one first! | ||||
| 	gsub("\\$", "%24", url) | ||||
| 	gsub("&", "%26", url) | ||||
| 	gsub("\\+", "%2B", url) | ||||
| 	gsub("\\?", "%3F", url) | ||||
| 	gsub(" ", "%20", url) | ||||
| 	gsub("\"", "%22", url) | ||||
| 	gsub("#", "%23", url) | ||||
| 	return url | ||||
| } | ||||
| function hrsize(size){ | ||||
| 	if(size > 1073741824) return sprintf("%.1fGB", size/1073741824) | ||||
| 	if(size > 10485760) return sprintf("%iMB", size/1048576) | ||||
| 	if(size > 1048576) return sprintf("%.1fMB", size/1048576) | ||||
| 	if(size > 10240) return sprintf("%iKB", size/1024) | ||||
| 	if(size > 1024) return sprintf("%.1fKB", size/1024) | ||||
| 	return sprintf("%iB", size) | ||||
| } | ||||
| /^(-|a)/ { | ||||
| 	print "<tr>" | ||||
| 	print "<td class=\"size\">"hrsize($6)"</td>" | ||||
| 	print "<td class=\"month\">"$7"</td>" | ||||
| 	print "<td class=\"day\">"$8"</td>" | ||||
| 	print "<td class=\"datetime\">"$9"</td>" | ||||
| 	$1="" ; $2="" ; $3="" ; $4="" ; $5="" ; $6="" ; $7="" ; $8="" ; $9="" | ||||
| 	sub("^ *?", "") | ||||
| 	print "<td><a class=\"file name\" href=\""urlencode($0)"\">"$0"</a></td>" | ||||
| 	print "</tr>" | ||||
| 	$0="" | ||||
| } | ||||
| /^d/ { | ||||
| 	print "<tr>" | ||||
| 	print "<td class=\"size\"> </td>" | ||||
| 	print "<td class=\"month\">"$7"</td>" | ||||
| 	print "<td class=\"day\">"$8"</td>" | ||||
| 	print "<td class=\"datetime\">"$9"</td>" | ||||
| 	$1="" ; $2="" ; $3="" ; $4="" ; $5="" ; $6="" ; $7="" ; $8="" ; $9="" | ||||
| 	sub("^ *?", "") | ||||
| 	print "<td><a class=\"dir name\" href=\""urlencode($0)"/\">"$0"/</a></td>" | ||||
| 	print "</tr>" | ||||
| }' | ||||
| echo '</table> | ||||
| 
 | ||||
| </body> | ||||
| </html>' | ||||
							
								
								
									
										43
									
								
								bin/contrib/rc-httpd/handlers/error
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										43
									
								
								bin/contrib/rc-httpd/handlers/error
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,43 @@ | |||
| #!/bin/rc | ||||
| # DO NOT make this script callable directly from the web! | ||||
| fn do_error{ | ||||
| 	echo 'HTTP/1.1 '^$1^$cr | ||||
| 	emit_extra_headers | ||||
| 	echo 'Content-type: text/html'^$cr | ||||
| 	echo $cr | ||||
| 	echo '<html> | ||||
| <head> | ||||
| <title>'^$1^'</title> | ||||
| </head> | ||||
| <body> | ||||
| <h1>'^$1^'</h1>' | ||||
| 	echo $2 | ||||
| 	echo '<p><i>rc-httpd at' $SERVER_NAME '</i>' | ||||
| 	echo ' | ||||
| 	</body> | ||||
| 	</html> | ||||
| 	' | ||||
| } | ||||
| 
 | ||||
| fn 401{ | ||||
| 	do_error '401 Unauthorized' \ | ||||
| 	'The requested path '^$"location^' requires authorization.' | ||||
| } | ||||
| 
 | ||||
| fn 404{ | ||||
| 	do_error '404 Not Found' \ | ||||
| 	'The requested path '^$"location^' was not found on this server.' | ||||
| } | ||||
| 
 | ||||
| fn 500{ | ||||
| 	do_error '500 Internal Server Error' \ | ||||
| 	'The server has encountered an internal misconfiguration and is unable to satisfy your request.' | ||||
| } | ||||
| 
 | ||||
| fn 503{ | ||||
| 	do_error '503 Forbidden' \ | ||||
| 	'You do not have permission to access '^$"location^' on this server.' | ||||
| } | ||||
| 
 | ||||
| do_log $1 | ||||
| $1 | ||||
							
								
								
									
										30
									
								
								bin/contrib/rc-httpd/handlers/redirect
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								bin/contrib/rc-httpd/handlers/redirect
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,30 @@ | |||
| #!/bin/rc | ||||
| if(~ $#2 0){ | ||||
| 	error 500 | ||||
| 	exit | ||||
| } | ||||
| switch($1){ | ||||
| case perm* | ||||
| 	do_log 301 | ||||
| 	echo 'HTTP/1.1 301 Moved Permanently'^$cr | ||||
| case temp* | ||||
| 	do_log 302 | ||||
| 	echo 'HTTP/1.1 302 Moved Temporarily'^$cr | ||||
| case seeother | ||||
| 	do_log 303 | ||||
| 	echo 'HTTP/1.1 303 See Other'^$cr | ||||
| case * | ||||
| 	error 500 | ||||
| 	exit | ||||
| } | ||||
| echo 'Location: ' ^ $2 ^ $cr | ||||
| emit_extra_headers | ||||
| echo 'Content-type: text/html'^$cr | ||||
| echo $cr | ||||
| echo '<html><body>' | ||||
| if(~ $#3 0) | ||||
| 	echo 'Browser did not accept redirect.' | ||||
| if not | ||||
| 	echo $3 | ||||
| echo '<a href="'^$"location^'/">Click here</a>' | ||||
| echo '</body></html>' | ||||
							
								
								
									
										43
									
								
								bin/contrib/rc-httpd/handlers/serve-static
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										43
									
								
								bin/contrib/rc-httpd/handlers/serve-static
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,43 @@ | |||
| #!/bin/rc | ||||
| full_path=`{echo $"FS_ROOT^$"PATH_INFO | urldecode.awk} | ||||
| full_path=$"full_path | ||||
| if(~ $full_path */) | ||||
| 	error 503 | ||||
| if(test -d $full_path){ | ||||
| 	redirect perm $"location^'/' \ | ||||
| 		'URL not quite right, and browser did not accept redirect.' | ||||
| 	exit | ||||
| } | ||||
| if(! test -e $full_path){ | ||||
| 	error 404 | ||||
| 	exit | ||||
| } | ||||
| if(! test -r $full_path){ | ||||
| 	error 503 | ||||
| 	exit | ||||
| } | ||||
| do_log 200 | ||||
| switch($full_path){ | ||||
| case *.html *.htm | ||||
|         type=text/html | ||||
| case *.css | ||||
|         type=text/css | ||||
| case *.txt | ||||
|         type='text/plain; charset=utf-8' | ||||
| case *.jpg *.jpeg | ||||
|         type=image/jpeg | ||||
| case *.gif | ||||
|         type=image/gif | ||||
| case *.png | ||||
|         type=image/png | ||||
| case * | ||||
| 		type=`{file -m $full_path || file -i $full_path}        # GROSS | ||||
| } | ||||
| max_age=3600	# 1 hour | ||||
| echo 'HTTP/1.1 200 OK'^$cr | ||||
| emit_extra_headers | ||||
| echo 'Content-type: '^$type^'; charset=utf-8'^$cr | ||||
| echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'} | ||||
| echo 'Cache-control: max-age='^$max_age^$cr | ||||
| echo $cr | ||||
| exec cat $full_path | ||||
							
								
								
									
										14
									
								
								bin/contrib/rc-httpd/handlers/static-or-cgi
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								bin/contrib/rc-httpd/handlers/static-or-cgi
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| #!/bin/rc | ||||
| cgiargs=$* | ||||
| 
 | ||||
| fn error{ | ||||
| 	if(~ $1 404) | ||||
| 		exec cgi $cgiargs | ||||
| 	if not | ||||
| 		$rc_httpd_dir/handlers/error $1 | ||||
| } | ||||
| 
 | ||||
| if(~ $location */) | ||||
| 	exec cgi $cgiargs | ||||
| if not | ||||
| 	exec serve-static | ||||
							
								
								
									
										5
									
								
								bin/contrib/rc-httpd/handlers/static-or-index
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										5
									
								
								bin/contrib/rc-httpd/handlers/static-or-index
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| #!/bin/rc | ||||
| if(~ $PATH_INFO */) | ||||
| 	exec dir-index $params | ||||
| if not | ||||
| 	exec serve-static | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 q
						q