From: Paul Hänsch Date: Thu, 5 Jul 2018 13:39:33 +0000 (+0200) Subject: multiple minor improvements X-Git-Url: http://git.plutz.net/?p=serve0;a=commitdiff_plain;h=ad9ff11ccc78543cee20d00e0a0e7c9610761b0f multiple minor improvements --- diff --git a/cgilite b/cgilite index a96b0fc..6940bf7 160000 --- a/cgilite +++ b/cgilite @@ -1 +1 @@ -Subproject commit a96b0fcd8fb4afad4e169a3929270e2335cf4d0d +Subproject commit 6940bf78a6d2dd6080f8d7f720eb66c17d1a11db diff --git a/index.cgi b/index.cgi index b4339ad..7b4921a 100755 --- a/index.cgi +++ b/index.cgi @@ -10,21 +10,18 @@ FILTER="$(GET f)" SEARCH="$(GET s)" ORDER="$(GET o |grep -m1 -xE 'Date|Name|Length' || printf Name)" LISTSIZE="$(COOKIE pagesize |grep -m1 -xE '[1-9][0-9]*' || printf 50)" - -ITEM="$(printf %s "${PATH_INFO#/}" |sed -r ':X /(^|\/)\.\.($|\/)/s;(^|[^/]*/)..(/|$);;; tX;')" +ITEM="$(PATH "${PATH_INFO#/}")" case $(GET a) in setprefs) - printf 'Status: 303 See Other\r\n' SET_COOKIE +$((86400 * 90)) pagesize="$(POST pagesize |grep -m1 -xE '[1-9][0-9]*' || printf 50)" SET_COOKIE +$((86400 * 90)) mode="$(POST mode |grep -m1 -xE 'browse|index' || printf browse)" SET_COOKIE +$((86400 * 90)) fakemp4="$(POST fakemp4 |grep -m1 -xE 'yes' || printf no)" - printf 'Location: %s\r\n\r\n' "$(POST ref)" - exit 0 + REDIRECT "$(POST ref)" ;; esac -if [ "$ITEM" = "style.css" ]; then +if [ "$ITEM" = "/style.css" ]; then . "$_EXEC/cgilite/file.sh" [ -r "$_DATA/$ITEM" ] && FILE "$_DATA/$ITEM" \ || FILE "$_EXEC/style.css" diff --git a/list.sh b/list.sh index cb0e4c1..2f8e139 100644 --- a/list.sh +++ b/list.sh @@ -1,18 +1,21 @@ #!/bin/sh list_dir(){ - dir="$(HTML "$1")" + name="$(HTML "$1")" + path="$(HTML "${ITEM}/$1")" printf '[a .list .dir href="%s" %s]' \ - "$dir" "$dir" + "$path" "$name" } list_file(){ - file="$(HTML "$1")" + name="$(HTML "$1")" + path="$(HTML "$ITEM/$1")" printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \ - "$file" "$file" "$file" + "$path" "$path" "$name" } list_dirs(){ + [ "$ITEM" ] && printf '..\n' (cd "$_DATA/$ITEM"; find ./ -type d -mindepth 1 -maxdepth 1 \ -exec stat -c '%Y %n' '{}' + @@ -24,7 +27,7 @@ list_dirs(){ list_files(){ (cd "$_DATA/$ITEM"; find ./ -type f -mindepth 1 -maxdepth 1 \ - -exec stat -c '%Y %n' "${f#./}" '{}' + + -exec stat -c '%Y %n' "${f#./}" '{}' + 2>&- ) \ | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \ | cut -d/ -f2- @@ -49,7 +52,7 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' $(w_search) [input type=checkbox #t_prefs .toggle ][label for=t_prefs ⚙] $(w_prefs) - $(if [ $(COOKIE mode) = index ]; then + $(if [ "$(COOKIE mode)" = index ]; then list_tree |while read -r file; do list_file "$file"; done else list_dirs |while read -r dir; do list_dir "$dir"; done