cookutils rev 893
web/cooker.cgi: work with HTTP headers "Last-Modified", "If-Modified-Since", "HTTP 304 Not Modified", "HTTP 404 Not Found". Other small improvements.
SliTaz Next Cooker is working right now with this version of cooker.cgi.
SliTaz Next Cooker is working right now with this version of cooker.cgi.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Mar 20 05:12:29 2017 +0200 (2017-03-20) |
parents | 34b05a9e92c7 |
children | 2ff4c8d701d3 |
files | web/cooker.cgi |
line diff
1.1 --- a/web/cooker.cgi Fri Mar 17 02:42:26 2017 +0200 1.2 +++ b/web/cooker.cgi Mon Mar 20 05:12:29 2017 +0200 1.3 @@ -23,16 +23,124 @@ 1.4 cooktime="$CACHE/cooktime" 1.5 wokrev="$CACHE/wokrev" 1.6 1.7 -# Path to sundown (markdown to html convertor) 1.8 -if [ -n "$(which sundown 2>/dev/null)" ]; then 1.9 - SUNDOWN=$(which sundown) 1.10 +# Path to markdown to html convertor 1.11 +if [ -n "$(which cmark 2>/dev/null)" ]; then 1.12 + md2html="$(which cmark) --smart" 1.13 +elif [ -x "./cmark" ]; then 1.14 + md2html="./cmark --smart" 1.15 +elif [ -n "$(which sundown 2>/dev/null)" ]; then 1.16 + md2html=$(which sundown) 1.17 elif [ -x "./sundown" ]; then 1.18 - SUNDOWN="./sundown" 1.19 + md2html="./sundown" 1.20 fi 1.21 1.22 # We're not logged and want time zone to display correct server date. 1.23 export TZ=$(cat /etc/TZ) 1.24 1.25 + 1.26 +# HTML page header. Pages can be customized with a separated header.html file 1.27 + 1.28 +page_header() { 1.29 + echo -e 'Content-Type: text/html; charset=UTF-8\n' 1.30 + if [ -f "header.html" ]; then 1.31 + cat header.html 1.32 + else 1.33 + cat <<EOT 1.34 +<!DOCTYPE html> 1.35 +<html lang="en"> 1.36 +<head> 1.37 + <meta charset="UTF-8"> 1.38 + <meta name="viewport" content="width=device-width, initial-scale=1.0"> 1.39 + <title>SliTaz Cooker</title> 1.40 + <link rel="shortcut icon" href="favicon.ico"> 1.41 + <link rel="stylesheet" href="style.css"> 1.42 + <script src="prism.js"></script> 1.43 + <link rel="stylesheet" href="prism.css"> 1.44 + <link rel="alternate" type="application/rss+xml" title="Cooker Feed" href="?rss"> 1.45 + <meta name="robots" content="nofollow"> 1.46 +</head> 1.47 +<body> 1.48 + 1.49 +<div id="header"> 1.50 + <div id="logo"></div> 1.51 + <h1><a href="cooker.cgi">SliTaz Cooker</a></h1> 1.52 +</div> 1.53 +EOT 1.54 + fi 1.55 +} 1.56 + 1.57 + 1.58 +# HTML page footer. Pages can be customized with a separated footer.html file 1.59 + 1.60 +page_footer() { 1.61 + if [ -f "footer.html" ]; then 1.62 + cat footer.html 1.63 + else 1.64 + cat <<EOT 1.65 +</div> 1.66 + 1.67 +<div id="footer"> 1.68 + <a href="http://www.slitaz.org/">SliTaz Website</a> 1.69 + <a href="cooker.cgi">Cooker</a> 1.70 + <a href="doc/cookutils/cookutils.html">Documentation</a> 1.71 +</div> 1.72 + 1.73 +</body> 1.74 +</html> 1.75 +EOT 1.76 + fi 1.77 +} 1.78 + 1.79 + 1.80 +not_found() { 1.81 + local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}" 1.82 + echo "HTTP/1.1 404 Not Found" 1.83 + page_header 1.84 + echo "<div id='content'><h2>Not Found</h2>" 1.85 + case $2 in 1.86 + pkg) 1.87 + echo "<p>The requested package <b>$(basename "$(dirname "$file")")</b> was not found on this server.</p>" ;; 1.88 + *) 1.89 + echo "<p>The requested file <b>$file</b> was not found on this server.</p>" ;; 1.90 + esac 1.91 + page_footer 1.92 +} 1.93 + 1.94 + 1.95 +manage_modified() { 1.96 + local file="$1" option="$2" nul day mon year time hh mm ss date_s 1.97 + if [ ! -f "$file" ]; then 1.98 + if [ "$option" == 'silently-absent' ]; then 1.99 + echo "HTTP/1.1 404 Not Found" 1.100 + return 1.101 + else 1.102 + not_found "$file" "$2" 1.103 + exit 1.104 + fi 1.105 + fi 1.106 + [ "$option" == 'no-last-modified' ] && return 1.107 + if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then 1.108 + echo "$HTTP_IF_MODIFIED_SINCE" | \ 1.109 + while read nul day mon year time nul; do 1.110 + case $mon in 1.111 + Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';; 1.112 + May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';; 1.113 + Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';; 1.114 + esac 1.115 + hh=$(echo $time | cut -d: -f1) 1.116 + mm=$(echo $time | cut -d: -f2) 1.117 + ss=$(echo $time | cut -d: -f3) 1.118 + date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s) 1.119 + if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then 1.120 + echo -e 'HTTP/1.1 304 Not Modified\n' 1.121 + exit 1.122 + fi 1.123 + done 1.124 + fi 1.125 + echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')" 1.126 +} 1.127 + 1.128 + 1.129 case "$QUERY_STRING" in 1.130 recook=*) 1.131 case "$HTTP_USER_AGENT" in 1.132 @@ -40,36 +148,39 @@ 1.133 grep -qs "^${QUERY_STRING#recook=}$" $CACHE/recook-packages || 1.134 echo ${QUERY_STRING#recook=} >> $CACHE/recook-packages 1.135 esac 1.136 - cat <<EOT 1.137 -Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}} 1.138 - 1.139 -EOT 1.140 + echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n" 1.141 exit 1.142 ;; 1.143 1.144 poke) 1.145 touch $CACHE/cooker-request 1.146 - cat <<EOT 1.147 -Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}} 1.148 - 1.149 -EOT 1.150 + echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n" 1.151 exit 1.152 ;; 1.153 1.154 src*) 1.155 file=$(busybox httpd -d "$SRC/${QUERY_STRING#*=}") 1.156 - cat <<EOT 1.157 -Content-Type: application/octet-stream 1.158 -Content-Length: $(stat -c %s "$file") 1.159 -Content-Disposition: attachment; filename="$(basename "$file")" 1.160 + manage_modified "$file" 1.161 + content_type='application/octet-stream' 1.162 + case $file in 1.163 + *.tar.gz) content_type='application/x-compressed-tar' ;; 1.164 + *.tar.bz2) content_type='application/x-bzip-compressed-tar' ;; 1.165 + *.tar.xz) content_type='application/x-xz-compressed-tar' ;; 1.166 + *.tar.lzma) content_type='application/x-lzma-compressed-tar' ;; 1.167 + *.zip) content_type='application/zip' ;; 1.168 + esac 1.169 + echo "Content-Type: $content_type" 1.170 + echo "Content-Length: $(stat -c %s "$file")" 1.171 + echo "Content-Disposition: attachment; filename=\"$(basename "$file")\"" 1.172 + echo 1.173 1.174 -EOT 1.175 cat "$file" 1.176 exit 1.177 ;; 1.178 1.179 download*) 1.180 file=$(busybox httpd -d "$PKGS/${QUERY_STRING#*=}") 1.181 + manage_modified "$file" 1.182 content_type='application/octet-stream' 1.183 case $file in 1.184 *.txt|*.conf|*/README|*/receipt) 1.185 @@ -79,17 +190,18 @@ 1.186 *.js) content_type='application/javascript; charset=UTF-8' ;; 1.187 *.desktop) content_type='application/x-desktop; charset=UTF-8' ;; 1.188 *.png) content_type='image/png' ;; 1.189 + *.gif) content_type='image/gif' ;; 1.190 *.svg) content_type='image/svg+xml' ;; 1.191 *.jpg|*.jpeg) content_type='image/jpeg' ;; 1.192 *.sh|*.cgi) content_type='application/x-shellscript' ;; 1.193 *.gz) content_type='application/gzip' ;; 1.194 *.ico) content_type='image/vnd.microsoft.icon' ;; 1.195 + *.tazpkg) content_type='application/x-tazpkg' ;; 1.196 esac 1.197 + 1.198 echo "Content-Type: $content_type" 1.199 echo "Content-Length: $(stat -c %s "$file")" 1.200 - [ "$content_type" == 'application/octet-stream' ] && 1.201 - echo "Content-Disposition: attachment; filename=\"$(basename "$file")\"" 1.202 - 1.203 + echo "Content-Disposition: inline; filename=\"$(basename "$file")\"" 1.204 echo 1.205 1.206 cat "$file" 1.207 @@ -100,8 +212,27 @@ 1.208 echo -e 'Content-Type: application/rss+xml\n' 1.209 ;; 1.210 1.211 - *) 1.212 - echo -e 'Content-Type: text/html; charset=UTF-8\n' 1.213 + stuff*) 1.214 + file="$wok/${QUERY_STRING#stuff=}" 1.215 + manage_modified "$file" 1.216 + ;; 1.217 + 1.218 + pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*) 1.219 + type=${QUERY_STRING%%=*} 1.220 + pkg=$(GET $type) 1.221 + case "$type" in 1.222 + description) 1.223 + manage_modified "$wok/$pkg/receipt" 'no-last-modified' 1.224 + manage_modified "$wok/$pkg/description.txt" 'silently-absent' 1.225 + ;; 1.226 + log) 1.227 + manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified' 1.228 + manage_modified "$LOGS/$pkg" 1.229 + ;; 1.230 + *) 1.231 + manage_modified "$wok/$pkg/receipt" pkg 1.232 + ;; 1.233 + esac 1.234 ;; 1.235 1.236 esac 1.237 @@ -170,10 +301,6 @@ 1.238 } 1.239 1.240 1.241 -htmlize() { 1.242 - sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g' 1.243 -} 1.244 - 1.245 # Put some colors in log and DB files. 1.246 1.247 syntax_highlighter() { 1.248 @@ -248,19 +375,6 @@ 1.249 s|\[0m|</span>|g;" 1.250 ;; 1.251 1.252 - receipt) 1.253 - sed -e s'|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|'g \ 1.254 - -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \ 1.255 - -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g 1.256 - ;; 1.257 - 1.258 - diff) 1.259 - sed -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \ 1.260 - -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \ 1.261 - -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \ 1.262 - -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g 1.263 - ;; 1.264 - 1.265 activity) 1.266 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g 1.267 ;; 1.268 @@ -268,6 +382,13 @@ 1.269 } 1.270 1.271 1.272 +show_code() { 1.273 + echo "<pre><code class=\"language-$1\">" 1.274 + sed 's|&|\&|g; s|<|\<|g; s|>|\>|g' 1.275 + echo '</code></pre>' 1.276 +} 1.277 + 1.278 + 1.279 # Latest build pkgs. 1.280 1.281 list_packages() { 1.282 @@ -426,45 +547,17 @@ 1.283 1.284 1.285 1.286 -# xHTML header. Pages can be customized with a separated html.header file. 1.287 - 1.288 -if [ -f "header.html" ]; then 1.289 - cat header.html 1.290 -else 1.291 - cat <<EOT 1.292 -<!DOCTYPE html> 1.293 -<html lang="en"> 1.294 -<head> 1.295 - <meta charset="UTF-8"> 1.296 - <meta name="viewport" content="width=device-width, initial-scale=1.0"> 1.297 - <title>SliTaz Cooker</title> 1.298 - <link rel="shortcut icon" href="favicon.ico"> 1.299 - <link rel="stylesheet" href="style.css"> 1.300 - <script src="prism.js"></script> 1.301 - <link rel="stylesheet" href="prism.css"> 1.302 - <link rel="alternate" type="application/rss+xml" title="Cooker Feed" href="?rss"> 1.303 - <meta name="robots" content="nofollow"> 1.304 -</head> 1.305 -<body> 1.306 - 1.307 -<div id="header"> 1.308 - <div id="logo"></div> 1.309 - <h1><a href="cooker.cgi">SliTaz Cooker</a></h1> 1.310 -</div> 1.311 -EOT 1.312 -fi 1.313 - 1.314 1.315 # 1.316 # Load requested page 1.317 # 1.318 1.319 +page_header 1.320 + 1.321 case "${QUERY_STRING}" in 1.322 pkg=*) 1.323 pkg=${QUERY_STRING#pkg=} 1.324 log=$LOGS/$pkg.log 1.325 - echo "<div id='content'>" 1.326 - echo "<h2>Package: $pkg</h2>" 1.327 1.328 # Define cook variables for syntax highlighter 1.329 if [ -s "$WOK/$pkg/receipt" ]; then 1.330 @@ -478,11 +571,15 @@ 1.331 1.332 # Package info. 1.333 if [ -f "$wok/$pkg/receipt" ]; then 1.334 + echo "<div id='content'>" 1.335 + echo "<h2>Package: $pkg</h2>" 1.336 pkg_info 1.337 else 1.338 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then 1.339 - echo "No package named: $pkg" 1.340 + echo "<div id='content'><h2>Not Found</h2>" 1.341 + echo "<p>The requested package <b>$pkg</b> was not found on this server.</p>" 1.342 else 1.343 + echo "<div id='content'>" 1.344 ls $wok/$pkg/receipt >/dev/null 2>&1 || pkg="*$pkg*" 1.345 echo '<table class="zebra" style="width:100%">' 1.346 for i in $(cd $wok ; ls $pkg/receipt); do 1.347 @@ -504,6 +601,8 @@ 1.348 1.349 # Check for a log file and display summary if it exists. 1.350 summary "$log" 1.351 + 1.352 + # Display <Recook> button only for SliTaz web browser 1.353 if [ -f "$log" ]; then 1.354 case "$HTTP_USER_AGENT" in 1.355 *SliTaz*) 1.356 @@ -571,17 +670,6 @@ 1.357 echo '</ul></div>' 1.358 ;; 1.359 1.360 - *.diff) 1.361 - diff=$CACHE/$file 1.362 - echo "<h2>Diff for: ${file%.diff}</h2>" 1.363 - [ "$file" == "installed.diff" ] && echo \ 1.364 - "<p>This is the latest diff between installed packages \ 1.365 - and installed build dependencies to cook.</p>" 1.366 - echo '<pre>' 1.367 - cat $diff | syntax_highlighter diff 1.368 - echo '</pre>' 1.369 - ;; 1.370 - 1.371 *.log) 1.372 log=$LOGS/$file 1.373 name=$(basename $log) 1.374 @@ -619,9 +707,9 @@ 1.375 done 1.376 1.377 case $file in 1.378 - *.desktop|*.theme) class="ini" ;; 1.379 + *.desktop|*.theme) class="ini" ;; 1.380 *.patch|*.diff|*.u) class="diff" ;; 1.381 - *.sh) class="bash" ;; 1.382 + *.sh) class="bash" ;; 1.383 *.conf*) 1.384 class="bash" 1.385 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini" 1.386 @@ -658,23 +746,19 @@ 1.387 ;; 1.388 esac 1.389 1.390 - # Display colored listing (also for *.svg) 1.391 + # Display colored listing for all text-based documents (also for *.svg) 1.392 case $file in 1.393 *.png|*.jpg|*.jpeg|*.ico) ;; 1.394 *) 1.395 if [ -z "$raw" ]; then 1.396 - echo -n "<pre><code class='language-$class'>" 1.397 - cat $wok/$file | sed 's|&|\&|g; s|<|\<|g; s|>|\>|g' 1.398 - echo '</code></pre>' 1.399 + cat $wok/$file | show_code $class 1.400 fi 1.401 ;; 1.402 esac 1.403 1.404 # Display hex dump for binary files 1.405 if [ -n "$raw" ]; then 1.406 - echo -n "<pre><code class='language-$class'>" 1.407 - hexdump -C $wok/$file | sed 's|&|\&|g; s|<|\<|g; s|>|\>|g' 1.408 - echo '</code></pre>' 1.409 + hexdump -C $wok/$file | show_code $class 1.410 fi 1.411 else 1.412 echo "<pre>File '$file' absent!</pre>" 1.413 @@ -684,67 +768,52 @@ 1.414 receipt=*) 1.415 echo "<div id='content'>" 1.416 pkg=${QUERY_STRING#receipt=} 1.417 - if [ -f "$wok/$pkg/receipt" ]; then 1.418 - echo "<h2>Receipt for: $pkg</h2>" 1.419 - pkg_info 1.420 - echo "<a class='button green' href='?receipt=$pkg'>receipt</a>" 1.421 - . $wok/$pkg/receipt 1.422 + echo "<h2>Receipt for: $pkg</h2>" 1.423 + pkg_info 1.424 + echo "<a class='button green' href='?receipt=$pkg'>receipt</a>" 1.425 + . $wok/$pkg/receipt 1.426 1.427 - ( cd $wok/$pkg; find stuff -type f 2> /dev/null ) | sort | \ 1.428 - while read file; do 1.429 - echo "<a class='button' href='?stuff=$pkg/$file'>$file</a>" 1.430 - done | sort 1.431 - echo -n '<pre><code class="language-bash">' 1.432 - cat $wok/$pkg/receipt | htmlize 1.433 - echo '</code></pre>' 1.434 - else 1.435 - echo "<pre>No receipt for: $pkg</pre>" 1.436 - fi 1.437 + ( cd $wok/$pkg; find stuff -type f 2> /dev/null ) | sort | \ 1.438 + while read file; do 1.439 + echo "<a class='button' href='?stuff=$pkg/$file'>$file</a>" 1.440 + done | sort 1.441 + cat $wok/$pkg/receipt | show_code bash 1.442 ;; 1.443 1.444 files=*) 1.445 echo "<div id='content'>" 1.446 pkg=${QUERY_STRING#files=} 1.447 dir=$(ls -d $WOK/$pkg/taz/$pkg-* 2>/dev/null) 1.448 - if [ -d "$dir/fs" ]; then 1.449 - size=$(du -hs $dir/fs | awk '{ print $1 }') 1.450 - echo "<h2>Files installed by the package \"$pkg\" ($size)</h2>" 1.451 - pkg_info 1.452 - #echo "<a class='button gray' href='?pkg=$pkg'>‹ back</a>" 1.453 + size=$(du -hs $dir/fs | awk '{ print $1 }') 1.454 + echo "<h2>Files installed by the package \"$pkg\" ($size)</h2>" 1.455 + pkg_info 1.456 1.457 - echo '<pre class="files">' 1.458 + echo '<pre class="files">' 1.459 1.460 - find $dir/fs -not -type d -print0 | \ 1.461 - xargs -0 ls -ld --color=always | \ 1.462 - syntax_highlighter files | \ 1.463 - sed "s|\([^/]*\)/.*\(${dir#*wok}/fs\)\([^<]*\)\(<.*\)$|\1<a href=\"?download=../wok\2\3\">\3</a>\4|" 1.464 + find $dir/fs -not -type d -print0 | sort -z | \ 1.465 + xargs -0 ls -ld --color=always | \ 1.466 + syntax_highlighter files | \ 1.467 + sed "s|\([^/]*\)/.*\(${dir#*wok}/fs\)\([^<]*\)\(<.*\)$|\1<a href=\"?download=../wok\2\3\">\3</a>\4|" 1.468 1.469 - echo '</pre>' 1.470 - else 1.471 - echo "<h2>No files list for \"$pkg\"</h2>" 1.472 - echo "<a class='button gray' href='?pkg=$pkg'>‹ back</a>" 1.473 - fi 1.474 + echo '</pre>' 1.475 ;; 1.476 1.477 description=*) 1.478 echo "<div id='content'>" 1.479 pkg=${QUERY_STRING#description=} 1.480 dir=$(ls -d $WOK/$pkg/taz/$pkg-* 2>/dev/null) 1.481 + echo "<h2>Description of $pkg</h2>" 1.482 + pkg_info 1.483 if [ -s "$dir/description.txt" ]; then 1.484 - echo "<h2>Description of $pkg</h2>" 1.485 - pkg_info 1.486 - if [ -x "$SUNDOWN" ]; then 1.487 + if [ -n "$md2html" ]; then 1.488 echo '<div id="content2">' 1.489 - $SUNDOWN $dir/description.txt 1.490 + $md2html $dir/description.txt 1.491 echo '</div>' 1.492 else 1.493 - echo '<pre><code class="language-markdown">' 1.494 - cat $dir/description.txt | \ 1.495 - sed 's/&/\&/g;s/</\</g;s/>/\>/g' 1.496 - echo '</code></pre>' 1.497 + cat $dir/description.txt | show_code markdown 1.498 fi 1.499 else 1.500 - echo "<pre>No description for: $pkg</pre>" 1.501 + echo "<pre>No description of $pkg</pre>" 1.502 fi 1.503 ;; 1.504 1.505 @@ -752,93 +821,99 @@ 1.506 echo '<div id="content">' 1.507 type=${QUERY_STRING%%=*} 1.508 pkg=$(GET $type) 1.509 - if [ -d "$wok/$pkg" ]; then 1.510 - dir=$WOK/$pkg/install/usr/share/$type 1.511 - [ -d $dir ] || dir=$WOK/$pkg/install/usr/$type 1.512 - [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/share/$type) 1.513 - [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/$type) 1.514 - page=$(GET file) 1.515 - if [ -z "$page" ]; then 1.516 - page=$(find $dir -type f | sed q) 1.517 - page=${page#$dir/} 1.518 - fi 1.519 + dir=$WOK/$pkg/install/usr/share/$type 1.520 + [ -d $dir ] || dir=$WOK/$pkg/install/usr/$type 1.521 + [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/share/$type) 1.522 + [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/$type) 1.523 + page=$(GET file) 1.524 + if [ -z "$page" ]; then 1.525 + page=$(find $dir -type f | sed q) 1.526 + page=${page#$dir/} 1.527 + fi 1.528 1.529 - echo "<h2>$(basename $page)</h2>" 1.530 + echo "<h2>$(basename $page)</h2>" 1.531 1.532 - pkg_info 1.533 - echo '<div style="max-height: 5em; overflow: auto">' 1.534 - find $dir -type f | sort | while read i ; do 1.535 - [ -s $i ] || continue 1.536 - case "$i" in 1.537 - *.jp*g|*.png|*.gif|*.svg|*.css) continue 1.538 - esac 1.539 - i=${i#$dir/} 1.540 - class=''; [ "$page" == "$i" ] && class=" plum" 1.541 - echo "<a class='button$class' href='?$type=$pkg&file=$i'>$(basename $i .gz)</a>" 1.542 - done | sort -t \> -k 2 1.543 - echo '</div>' 1.544 + pkg_info 1.545 + echo '<div style="max-height: 5em; overflow: auto">' 1.546 + find $dir -type f | sort | while read i ; do 1.547 + [ -s $i ] || continue 1.548 + case "$i" in 1.549 + *.jp*g|*.png|*.gif|*.svg|*.css) continue 1.550 + esac 1.551 + i=${i#$dir/} 1.552 + class=''; [ "$page" == "$i" ] && class=" plum" 1.553 + case "$type" in 1.554 + man) 1.555 + man=$(basename $i .gz) 1.556 + echo "<a class='button$class' href='?$type=$pkg&file=$i'>${man%.*} (${man##*.})</a>" 1.557 + ;; 1.558 + info) 1.559 + info=$(basename $i) 1.560 + echo "<a class='button$class' href='?$type=$pkg&file=$i'>${info/.info/}</a>" 1.561 + ;; 1.562 + *) 1.563 + echo "<a class='button$class' href='?$type=$pkg&file=$i'>$(basename $i .gz)</a>" 1.564 + ;; 1.565 + esac 1.566 + done 1.567 + echo '</div>' 1.568 1.569 - if [ -f "$dir/$page" ]; then 1.570 - tmp="$(mktemp)" 1.571 - docat "$dir/$page" > $tmp 1.572 - [ -s "$tmp" ] && 1.573 - case "$type" in 1.574 - info) 1.575 - echo '<div id="content2">' 1.576 - echo '<pre class="info">' 1.577 - info2html < "$tmp" 1.578 - echo '</pre></div>' 1.579 - ;; 1.580 - doc) 1.581 - case "$page" in 1.582 - *.sgml) class='xml';; 1.583 - *) class='asciidoc';; 1.584 - esac 1.585 - case "$page" in 1.586 - *.htm*) 1.587 - echo '<div id="content2">' 1.588 - cat 1.589 - echo '</div>' 1.590 - ;; 1.591 - *) 1.592 - echo "<pre><code class=\"language-$class\">" 1.593 - sed 's/&/\&/g;s/</\</g;s/>/\>/g' 1.594 - echo '</code></pre>' 1.595 - ;; 1.596 - esac < "$tmp" 1.597 - ;; 1.598 - man) 1.599 - export TEXTDOMAIN='man2html' 1.600 - echo "<div id='content2'>" 1.601 + if [ -f "$dir/$page" ]; then 1.602 + tmp="$(mktemp)" 1.603 + docat "$dir/$page" > $tmp 1.604 + [ -s "$tmp" ] && 1.605 + case "$type" in 1.606 + info) 1.607 + echo '<div id="content2">' 1.608 + echo '<pre class="info">' 1.609 + info2html < "$tmp" 1.610 + echo '</pre></div>' 1.611 + ;; 1.612 + doc) 1.613 + case "$page" in 1.614 + *.sgml) class='xml';; 1.615 + *) class='asciidoc';; 1.616 + esac 1.617 + case "$page" in 1.618 + *.htm*) 1.619 + echo '<div id="content2">' 1.620 + cat 1.621 + echo '</div>' 1.622 + ;; 1.623 + *) 1.624 + show_code $class 1.625 + ;; 1.626 + esac < "$tmp" 1.627 + ;; 1.628 + man) 1.629 + export TEXTDOMAIN='man2html' 1.630 + echo "<div id='content2'>" 1.631 1.632 - html=$(./man2html "$tmp" | sed -e '1,/<header>/d' \ 1.633 - -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \ 1.634 - -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g') 1.635 + html=$(./man2html "$tmp" | sed -e '1,/<header>/d' \ 1.636 + -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \ 1.637 + -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g') 1.638 1.639 - if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then 1.640 - # Process the pre-formatted man-cat page 1.641 - echo '<pre>' 1.642 - sed ' 1.643 - s|M-bM-^@M-^S|—|g; 1.644 - s|M-bM-^@M-^\\|<b>|g; 1.645 - s|M-bM-^@M-^]|</b>|g 1.646 - s|M-bM-^@M-^X|<u>|g; 1.647 - s|M-bM-^@M-^Y|</u>|g; 1.648 - s|M-BM-||g; 1.649 - ' "$tmp" 1.650 - echo '</pre>' 1.651 - else 1.652 - echo "$html" 1.653 - fi 1.654 - echo "</div>" 1.655 - ;; 1.656 - esac 1.657 - rm -f $tmp 1.658 - else 1.659 - echo "<pre>File '$page' not exists!</pre>" 1.660 - fi 1.661 + if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then 1.662 + # Process the pre-formatted man-cat page 1.663 + echo '<pre>' 1.664 + sed ' 1.665 + s|M-bM-^@M-^S|—|g; 1.666 + s|M-bM-^@M-^\\|<b>|g; 1.667 + s|M-bM-^@M-^]|</b>|g 1.668 + s|M-bM-^@M-^X|<u>|g; 1.669 + s|M-bM-^@M-^Y|</u>|g; 1.670 + s|M-BM-||g; 1.671 + ' "$tmp" 1.672 + echo '</pre>' 1.673 + else 1.674 + echo "$html" 1.675 + fi 1.676 + echo "</div>" 1.677 + ;; 1.678 + esac 1.679 + rm -f $tmp 1.680 else 1.681 - echo "<pre>Package '$pkg' not exists!</pre>" 1.682 + echo "<pre>File '$page' not exists!</pre>" 1.683 fi 1.684 ;; 1.685 1.686 @@ -958,19 +1033,5 @@ 1.687 esac 1.688 1.689 1.690 -# Close xHTML page 1.691 - 1.692 -cat <<EOT 1.693 -</div> 1.694 - 1.695 -<div id="footer"> 1.696 - <a href="http://www.slitaz.org/">SliTaz Website</a> 1.697 - <a href="cooker.cgi">Cooker</a> 1.698 - <a href="doc/cookutils/cookutils.html">Documentation</a> 1.699 -</div> 1.700 - 1.701 -</body> 1.702 -</html> 1.703 -EOT 1.704 - 1.705 +page_footer 1.706 exit 0