cookutils diff web/cooker.cgi @ rev 894

cook: fix copy() -> cook_copy_folders() for repeated copying; web/cooker.cgi: manage packages with '+' in the name; web/style.css: get styles from mirror1.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Mar 24 17:29:16 2017 +0200 (2017-03-24)
parents eff71eaaee4f
children fe29568da760
line diff
     1.1 --- a/web/cooker.cgi	Mon Mar 20 05:12:29 2017 +0200
     1.2 +++ b/web/cooker.cgi	Fri Mar 24 17:29:16 2017 +0200
     1.3 @@ -25,9 +25,9 @@
     1.4  
     1.5  # Path to markdown to html convertor
     1.6  if [ -n "$(which cmark 2>/dev/null)" ]; then
     1.7 -	md2html="$(which cmark) --smart"
     1.8 +	md2html="$(which cmark) --smart -e table -e strikethrough -e autolink -e tagfilter"
     1.9  elif [ -x "./cmark" ]; then
    1.10 -	md2html="./cmark --smart"
    1.11 +	md2html="./cmark --smart -e table -e strikethrough -e autolink -e tagfilter"
    1.12  elif [ -n "$(which sundown 2>/dev/null)" ]; then
    1.13  	md2html=$(which sundown)
    1.14  elif [ -x "./sundown" ]; then
    1.15 @@ -131,13 +131,15 @@
    1.16  			mm=$(echo $time | cut -d: -f2)
    1.17  			ss=$(echo $time | cut -d: -f3)
    1.18  			date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
    1.19 -			if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
    1.20 -				echo -e 'HTTP/1.1 304 Not Modified\n'
    1.21 -				exit
    1.22 -			fi
    1.23 +#			if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
    1.24 +#				echo -e 'HTTP/1.1 304 Not Modified\n'
    1.25 +#				exit
    1.26 +#			fi
    1.27 +# TODO: improve caching control
    1.28  		done
    1.29  	fi
    1.30  	echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
    1.31 +	echo "Cache-Control: public, max-age=3600"
    1.32  }
    1.33  
    1.34  
    1.35 @@ -145,8 +147,8 @@
    1.36  	recook=*)
    1.37  		case "$HTTP_USER_AGENT" in
    1.38  			*SliTaz*)
    1.39 -				grep -qs "^${QUERY_STRING#recook=}$" $CACHE/recook-packages ||
    1.40 -				echo ${QUERY_STRING#recook=} >> $CACHE/recook-packages
    1.41 +				grep -qs "^$(GET recook)$" $CACHE/recook-packages ||
    1.42 +				echo "$(GET recook)" >> $CACHE/recook-packages
    1.43  		esac
    1.44  		echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
    1.45  		exit
    1.46 @@ -159,7 +161,7 @@
    1.47  		;;
    1.48  
    1.49  	src*)
    1.50 -		file=$(busybox httpd -d "$SRC/${QUERY_STRING#*=}")
    1.51 +		file=$(busybox httpd -d "$SRC/$(GET src)")
    1.52  		manage_modified "$file"
    1.53  		content_type='application/octet-stream'
    1.54  		case $file in
    1.55 @@ -171,7 +173,8 @@
    1.56  		esac
    1.57  		echo "Content-Type: $content_type"
    1.58  		echo "Content-Length: $(stat -c %s "$file")"
    1.59 -		echo "Content-Disposition: attachment; filename=\"$(basename "$file")\""
    1.60 +		filename=$(basename "$file")
    1.61 +		echo "Content-Disposition: attachment; filename=\"$filename\"" # Note, no conversion '+' -> '%2B' here
    1.62  		echo
    1.63  
    1.64  		cat "$file"
    1.65 @@ -179,7 +182,7 @@
    1.66  		;;
    1.67  
    1.68  	download*)
    1.69 -		file=$(busybox httpd -d "$PKGS/${QUERY_STRING#*=}")
    1.70 +		file="$PKGS/$(GET download)"
    1.71  		manage_modified "$file"
    1.72  		content_type='application/octet-stream'
    1.73  		case $file in
    1.74 @@ -201,7 +204,8 @@
    1.75  
    1.76  		echo "Content-Type: $content_type"
    1.77  		echo "Content-Length: $(stat -c %s "$file")"
    1.78 -		echo "Content-Disposition: inline; filename=\"$(basename "$file")\""
    1.79 +		filename=$(basename "$file")
    1.80 +		echo "Content-Disposition: inline; filename=\"$filename\"" # Note, no conversion '+' -> '%2B' here
    1.81  		echo
    1.82  
    1.83  		cat "$file"
    1.84 @@ -213,7 +217,7 @@
    1.85  		;;
    1.86  
    1.87  	stuff*)
    1.88 -		file="$wok/${QUERY_STRING#stuff=}"
    1.89 +		file="$wok/$(GET stuff)"
    1.90  		manage_modified "$file"
    1.91  		;;
    1.92  
    1.93 @@ -284,20 +288,21 @@
    1.94  
    1.95  info2html() {
    1.96  	sed \
    1.97 -		-e 's|&|\&amp;|g' -e 's|<|\&lt;|g' \
    1.98 +		-e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g' \
    1.99  		-e 's|^\* \(.*\)::|* <a href="#\1">\1</a>  |' \
   1.100  		-e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
   1.101 -		-e '/^File: /s|(dir)|Top|g' \
   1.102 -		-e '/^File: /s|Node: \([^,]*\)|Node: <a name="\1"></a><u>\1</u>|' \
   1.103 -		-e '/^File: /s|Next: \([^,]*\)|Next: <a href="#\1">\1</a>|' \
   1.104 -		-e '/^File: /s|Prev: \([^,]*\)|Prev: <a href="#\1">\1</a>|' \
   1.105 -		-e '/^File: /s|Up: \([^,]*\)|Up: <a href="#\1">\1</a>|' \
   1.106 -		-e '/^File: /s|^.*$|<i>&</i>|' \
   1.107 +		-e '/^File: / s|(dir)|Top|g' \
   1.108 +		-e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
   1.109 +		-e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
   1.110 +		-e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
   1.111 +		-e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
   1.112 +		-e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
   1.113  		-e '/^Tag Table:$/,/^End Tag Table$/d' \
   1.114  		-e '/INFO-DIR/,/^END-INFO-DIR/d' \
   1.115 -		-e "s|https*://[^>),'\"\` ]*|<a href=\"&\">&</a>|g" \
   1.116 +		-e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
   1.117  		-e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
   1.118 -		-e "s|^|</pre><pre class='info'>|"
   1.119 +		-e 's|^\* Menu:|<b>Menu:</b>|' \
   1.120 +		-e "s|^|</pre>|"
   1.121  }
   1.122  
   1.123  
   1.124 @@ -474,7 +479,7 @@
   1.125  	cmd=${QUERY_STRING%%=*}
   1.126  	echo '<div id="info">'
   1.127  	active=''; [ "$cmd" == 'receipt' -o "$cmd" == 'stuff' ] && active=' active'
   1.128 -	echo "<a class='button green$active' href='?receipt=$pkg'>receipt &amp; stuff</a>"
   1.129 +	echo "<a class='button green$active' href='?receipt=${pkg//+/%2B}'>receipt &amp; stuff</a>"
   1.130  
   1.131  	unset WEB_SITE WANTED
   1.132  	bpkg=$pkg
   1.133 @@ -487,27 +492,27 @@
   1.134  
   1.135  	if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
   1.136  		active=''; [ "$cmd" == 'files' ] && active=' active'
   1.137 -		echo "<a class='button khaki$active' href='?files=$pkg'>files</a>"
   1.138 +		echo "<a class='button khaki$active' href='?files=${pkg//+/%2B}'>files</a>"
   1.139  
   1.140  		unset EXTRAVERSION
   1.141  		. $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
   1.142  
   1.143  		if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
   1.144  			active=''; [ "$cmd" == 'description' ] && active=' active'
   1.145 -			echo "<a class='button brown$active' href='?description=$pkg'>description</a>"
   1.146 +			echo "<a class='button brown$active' href='?description=${pkg//+/%2B}'>description</a>"
   1.147  		fi
   1.148  
   1.149  		if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
   1.150 -			echo "<a class='button gold' href='?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
   1.151 +			echo "<a class='button gold' href='?download=${PACKAGE//+/%2B}-${VERSION//+/%2B}${EXTRAVERSION//+/%2B}.tazpkg'>download</a>"
   1.152  		fi
   1.153  
   1.154  		if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
   1.155 -			echo "<a class='button gold' href='?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
   1.156 +			echo "<a class='button gold' href='?download=${PACKAGE//+/%2B}-${VERSION//+/%2B}${EXTRAVERSION//+/%2B}-${ARCH//+/%2B}.tazpkg'>download</a>"
   1.157  		fi
   1.158  	fi
   1.159  
   1.160  	[ -n "$TARBALL" ] && [ -s "$SRC/$TARBALL" ] &&
   1.161 -	echo "<a class='button yellow' href='?src=$TARBALL'>source</a>"
   1.162 +	echo "<a class='button yellow' href='?src=${TARBALL//+/%2B}'>source</a>"
   1.163  
   1.164  	[ -x ./man2html ] &&
   1.165  	if [ -d $wok/$bpkg/install/usr/man ] ||
   1.166 @@ -515,7 +520,7 @@
   1.167  	   [ -d $wok/$bpkg/taz/*/fs/usr/man ] ||
   1.168  	   [ -d $wok/$bpkg/taz/*/fs/usr/share/man ]; then
   1.169  		active=''; [ "$cmd" == 'man' ] && active=' active'
   1.170 -		echo "<a class='button plum$active' href='?man=$bpkg'>man</a>"
   1.171 +		echo "<a class='button plum$active' href='?man=${bpkg//+/%2B}'>man</a>"
   1.172  	fi
   1.173  
   1.174  	if [ -d $wok/$bpkg/install/usr/doc ] ||
   1.175 @@ -523,7 +528,7 @@
   1.176  	   [ -d $wok/$bpkg/taz/*/fs/usr/doc ] ||
   1.177  	   [ -d $wok/$bpkg/taz/*/fs/usr/share/doc ]; then
   1.178  		active=''; [ "$cmd" == 'doc' ] && active=' active'
   1.179 -		echo "<a class='button plum$active' href='?doc=$bpkg'>doc</a>"
   1.180 +		echo "<a class='button plum$active' href='?doc=${bpkg//+/%2B}'>doc</a>"
   1.181  	fi
   1.182  
   1.183  	if [ -d $wok/$bpkg/install/usr/info ] ||
   1.184 @@ -531,15 +536,15 @@
   1.185  	   [ -d $wok/$bpkg/taz/*/fs/usr/info ] ||
   1.186  	   [ -d $wok/$bpkg/taz/*/fs/usr/share/info ]; then
   1.187  		active=''; [ "$cmd" == 'info' ] && active=' active'
   1.188 -		echo "<a class='button plum$active' href='?info=$bpkg'>info</a>"
   1.189 +		echo "<a class='button plum$active' href='?info=${bpkg//+/%2B}#Top'>info</a>"
   1.190  	fi
   1.191  
   1.192  	[ -n "$(echo $REQUEST_URI | sed 's|/[^/]*?pkg.*||')" ] ||
   1.193 -	echo "<a class='button' href='ftp://${HTTP_HOST%:*}/$pkg/'>browse</a>"
   1.194 +	echo "<a class='button' href='ftp://${HTTP_HOST%:*}/${pkg//+/%2B}/'>browse</a>"
   1.195  
   1.196  	if [ -s "$log" ]; then
   1.197  		active=''; [ "$cmd" == 'log' ] && active=' active'
   1.198 -		echo "<a class='button gray$active' href='?log=$pkg.log'>logs</a>"
   1.199 +		echo "<a class='button gray$active' href='?log=${pkg//+/%2B}.log'>logs</a>"
   1.200  	fi
   1.201  
   1.202  	echo '</div>'
   1.203 @@ -556,7 +561,7 @@
   1.204  
   1.205  case "${QUERY_STRING}" in
   1.206  	pkg=*)
   1.207 -		pkg=${QUERY_STRING#pkg=}
   1.208 +		pkg=$(GET pkg)
   1.209  		log=$LOGS/$pkg.log
   1.210  
   1.211  		# Define cook variables for syntax highlighter
   1.212 @@ -614,7 +619,7 @@
   1.213  		;;
   1.214  
   1.215  	log=*)
   1.216 -		log=${QUERY_STRING#log=}
   1.217 +		log=$(GET log)
   1.218  		logfile=$LOGS/$log
   1.219  		pkg=${log%.log*}
   1.220  		if [ -s "$logfile" ]; then
   1.221 @@ -629,7 +634,8 @@
   1.222  			esac
   1.223  			for i in $(ls -t $baselog $baselog.* 2>/dev/null); do
   1.224  				class=''; [ $i == $logfile ] && class=' gray'
   1.225 -				echo -n "<a class='button$class' href=\"?log=$(basename $i)\">"
   1.226 +				j=$(basename "$i")
   1.227 +				echo -n "<a class='button$class' href=\"?log=${j//+/%2B}\">"
   1.228  				echo "$(stat -c %y $i | cut -d: -f1,2)</a>"
   1.229  			done
   1.230  
   1.231 @@ -646,7 +652,7 @@
   1.232  	file=*)
   1.233  		echo "<div id='content'>"
   1.234  		# Don't allow all files on the system for security reasons.
   1.235 -		file=${QUERY_STRING#file=}
   1.236 +		file=$(GET file)
   1.237  		case "$file" in
   1.238  			activity|cooknotes|cooklist)
   1.239  				[ "$file" == "cooklist" ] && \
   1.240 @@ -693,17 +699,17 @@
   1.241  
   1.242  	stuff=*)
   1.243  		echo "<div id='content'>"
   1.244 -		file=${QUERY_STRING#stuff=}
   1.245 +		file=$(GET stuff)
   1.246  		pkg=${file%%/*}
   1.247  		if [ -f "$wok/$file" ]; then
   1.248  			echo "<h2>$file</h2>"
   1.249  			pkg_info
   1.250 -			echo "<a class='button' href='?receipt=$pkg'>receipt</a>"
   1.251 +			echo "<a class='button' href='?receipt=${pkg//+/%2B}'>receipt</a>"
   1.252  
   1.253  			( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | sort | \
   1.254  			while read i ; do
   1.255  				class=''; [ "$pkg/$i" == "$file" ] && class=" green"
   1.256 -				echo "<a class='button$class' href='?stuff=$pkg/$i'>$i</a>"
   1.257 +				echo "<a class='button$class' href='?stuff=${pkg//+/%2B}/${i//+/%2B}'>$i</a>"
   1.258  			done
   1.259  
   1.260  			case $file in
   1.261 @@ -742,7 +748,7 @@
   1.262  			# Display image
   1.263  			case $file in
   1.264  				*.png|*.svg|*.jpg|*.jpeg|*.ico)
   1.265 -					echo "<img src='?download=../wok/$file' style='display: block; max-width: 100%; margin: auto'/>"
   1.266 +					echo "<img src='?download=../wok/${file//+/%2B}' style='display: block; max-width: 100%; margin: auto'/>"
   1.267  					;;
   1.268  			esac
   1.269  
   1.270 @@ -767,22 +773,22 @@
   1.271  
   1.272  	receipt=*)
   1.273  		echo "<div id='content'>"
   1.274 -		pkg=${QUERY_STRING#receipt=}
   1.275 +		pkg=$(GET receipt)
   1.276  		echo "<h2>Receipt for: $pkg</h2>"
   1.277  		pkg_info
   1.278 -		echo "<a class='button green' href='?receipt=$pkg'>receipt</a>"
   1.279 +		echo "<a class='button green' href='?receipt=${pkg//+/%2B}'>receipt</a>"
   1.280  		. $wok/$pkg/receipt
   1.281  
   1.282  		( cd $wok/$pkg; find stuff -type f 2> /dev/null ) | sort | \
   1.283  		while read file; do
   1.284 -			echo "<a class='button' href='?stuff=$pkg/$file'>$file</a>"
   1.285 +			echo "<a class='button' href='?stuff=${pkg//+/%2B}/${file//+/%2B}'>$file</a>"
   1.286  		done | sort
   1.287  		cat $wok/$pkg/receipt | show_code bash
   1.288  		;;
   1.289  
   1.290  	files=*)
   1.291  		echo "<div id='content'>"
   1.292 -		pkg=${QUERY_STRING#files=}
   1.293 +		pkg=$(GET files)
   1.294  		dir=$(ls -d $WOK/$pkg/taz/$pkg-* 2>/dev/null)
   1.295  		size=$(du -hs $dir/fs | awk '{ print $1 }')
   1.296  		echo "<h2>Files installed by the package \"$pkg\" ($size)</h2>"
   1.297 @@ -793,14 +799,18 @@
   1.298  		find $dir/fs -not -type d -print0 | sort -z | \
   1.299  		xargs -0 ls -ld --color=always | \
   1.300  		syntax_highlighter files | \
   1.301 -		sed "s|\([^/]*\)/.*\(${dir#*wok}/fs\)\([^<]*\)\(<.*\)$|\1<a href=\"?download=../wok\2\3\">\3</a>\4|"
   1.302 +		sed "s|\([^/]*\)/.*\(${dir#*wok}/fs\)\([^<]*\)\(<.*\)$|\1<a href=\"?download=../wok\2\3\">\3</a>\4|" |\
   1.303 +		awk '
   1.304 +			BEGIN { FS="\""; }
   1.305 +			{ gsub("+", "%2B", $2); print; }
   1.306 +			'
   1.307  
   1.308  		echo '</pre>'
   1.309  		;;
   1.310  
   1.311  	description=*)
   1.312  		echo "<div id='content'>"
   1.313 -		pkg=${QUERY_STRING#description=}
   1.314 +		pkg=$(GET description)
   1.315  		dir=$(ls -d $WOK/$pkg/taz/$pkg-* 2>/dev/null)
   1.316  		echo "<h2>Description of $pkg</h2>"
   1.317  		pkg_info
   1.318 @@ -849,7 +859,7 @@
   1.319  					;;
   1.320  				info)
   1.321  					info=$(basename $i)
   1.322 -					echo "<a class='button$class' href='?$type=$pkg&amp;file=$i'>${info/.info/}</a>"
   1.323 +					echo "<a class='button$class' href='?$type=$pkg&amp;file=$i#Top'>${info/.info/}</a>"
   1.324  					;;
   1.325  				*)
   1.326  					echo "<a class='button$class' href='?$type=$pkg&amp;file=$i'>$(basename $i .gz)</a>"
   1.327 @@ -864,14 +874,14 @@
   1.328  			[ -s "$tmp" ] &&
   1.329  			case "$type" in
   1.330  				info)
   1.331 -					echo '<div id="content2">'
   1.332 -					echo '<pre class="info">'
   1.333 +					echo '<div id="content2" class="texinfo"><pre class="first">'
   1.334  					info2html < "$tmp"
   1.335  					echo '</pre></div>'
   1.336  					;;
   1.337  				doc)
   1.338  					case "$page" in
   1.339  						*.sgml) class='xml';;
   1.340 +						*.py)   class='python';; # pycurl package
   1.341  						*)      class='asciidoc';;
   1.342  					esac
   1.343  					case "$page" in
   1.344 @@ -979,7 +989,7 @@
   1.345  EOT
   1.346  
   1.347  		tac $CACHE/activity | head -n 12 | syntax_highlighter activity | \
   1.348 -		sed 's|cooker.cgi||; s|^|<li>|; s|$|</li>|'
   1.349 +		sed 's|cooker.cgi||; s|^|<li>|; s|$|</li>|;'
   1.350  
   1.351  		echo '</ul>'
   1.352  
   1.353 @@ -1024,7 +1034,8 @@
   1.354  		cat <<EOT
   1.355  <h2 id="lastcook">Latest cook</h2>
   1.356  <ul class="activity">
   1.357 -$(list_packages | sed "s|^.* :|<span class='log-date'>\0</span> <span style='white-space:nowrap'>|g; s|^|<li>|; s|$|</span></li>|")
   1.358 +$(list_packages | sed 's|.tazpkg$||' | \
   1.359 +sed "s|^.* :|<span class='log-date'>\0</span> <span style='white-space:nowrap'>|g; s|^|<li>|; s|$|</span></li>|")
   1.360  </ul>
   1.361  
   1.362  EOT