Skip to content
Snippets Groups Projects
Commit e9443b22 authored by CHANTREUX MARC's avatar CHANTREUX MARC
Browse files

ajout de CGI.sh

parent 27f02356
Branches
No related merge requests found
alias '[%=<<-%] lowdown'
_http_header() sed 's/$/\r/' "$@"
form_data_parse() LANG=C busybox awk \
-vRS='\r\n' -vvars='(file)?name="[^"]+"' \
-vdumpvar='%s="%s";' -vkey='name="' '
# -- is appended to the boundary at the last entry
# so we have 2 cases
# RS$(0)RS # split
# RS$(0)"--"RS # EOF
function name_from(s) {
value = substr(s, length(key) + match($0,key))
value = substr(value, 0, index(value,"\"") -1 )
return value
}
BEGIN {
getline
RS=RS$(0)"(--)?"RS }
{
id= NR-1
system("mkdir "id)
# the first empty line is the separator between header
# and data
sep = index($0,"\r\n\r\n")
header = name = substr($0,0,sep)
printf "%s", header > id"/header"
print "id="id > id"/vars"
for ( ; match( header ,vars) ;
header = substr( header, RSTART + RLENGTH ) ) {
printf "%s;", substr( header, RSTART, RLENGTH) > id"/vars"
}
name = name_from(name)
serve[name] = serve[name]" "id
gsub("\r\n","\n"id"\t",header)
printf "%s", substr($0,sep + 4 ) > id"/data"
}
END { split(accept,yes,"[ ,]+")
for ( y in yes ) {
y=yes[y]
printf dumpvar, y , substr(serve[y],2) }
}
' "$@"
HTTP_OK() <<-% _http_header
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
%
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment