-Subproject commit 3a5f8da6c094474cb5de33d40fc94e4497450a25
+Subproject commit a96b0fcd8fb4afad4e169a3929270e2335cf4d0d
#!/bin/sh
-[ -z "${_EXEC%/}" ] && _EXEC=. || _EXEC="${_DATA%/}"
+[ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
[ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
. "$_EXEC/cgilite/cgilite.sh"
. "$_EXEC/widgets.sh"
-filter="$(GET f)"
-search="$(GET s)"
-order="$(GET o |grep -m1 -xE 'Date|Name|Length' || printf Name)"
-pagesize="$(COOKIE pagesize |grep -m1 -xE '[1-9][0-9]*' || printf 50)"
+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="$(printf %s "${PATH_INFO#/}" |sed -r ':X /(^|\/)\.\.($|\/)/s;(^|[^/]*/)..(/|$);;; tX;')"
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
;;
esac
-if [ "$item" = "/style.css" ]; then
+if [ "$ITEM" = "style.css" ]; then
. "$_EXEC/cgilite/file.sh"
- [ -r "$_DATA/$item" ] && FILE "$_DATA/$item" \
+ [ -r "$_DATA/$ITEM" ] && FILE "$_DATA/$ITEM" \
|| FILE "$_EXEC/style.css"
-elif [ -f "$_DATA/$item" ]; then
+elif [ -f "$_DATA/$ITEM" ]; then
case $(GET a) in
tag)
;;
thumbnail)
+ printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'
;;
delete)
;;
*) . "$_EXEC/cgilite/file.sh"
- FILE "$_DATA/$item"
+ FILE "$_DATA/$ITEM"
;;
esac
-elif [ -d "$_DATA/$item" ]; then
+elif [ -d "$_DATA/$ITEM" ]; then
case $(GET a) in
multitag)
;;
;;
esac
else
- printf 'Status: 404 Not Found\r\n\r\n'
- exit 0
+ printf 'Status: 404 Not Found\r\nContent-Length 0:\r\n\r\n'
fi
#!/bin/sh
+list_dir(){
+ dir="$(HTML "$1")"
+ printf '[a .list .dir href="%s" %s]' \
+ "$dir" "$dir"
+}
+
+list_file(){
+ file="$(HTML "$1")"
+ printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \
+ "$file" "$file" "$file"
+}
+
+list_dirs(){
+ (cd "$_DATA/$ITEM";
+ find ./ -type d -mindepth 1 -maxdepth 1 \
+ -exec stat -c '%Y %n' '{}' +
+ ) \
+ | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
+ | cut -d/ -f2-
+}
+
+list_files(){
+ (cd "$_DATA/$ITEM";
+ find ./ -type f -mindepth 1 -maxdepth 1 \
+ -exec stat -c '%Y %n' "${f#./}" '{}' +
+ ) \
+ | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
+ | cut -d/ -f2-
+}
+
+list_tree(){
+ (cd "$_DATA/$ITEM";
+ find ./ -type f \
+ -exec stat -c '%Y %n' '{}' +
+ ) \
+ | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
+ | cut -d/ -f2-
+}
+
printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
"$_EXEC/cgilite/html-sh.sed" <<-EOF
$(w_search)
[input type=checkbox #t_prefs .toggle ][label for=t_prefs ⚙]
$(w_prefs)
+ $(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
+ printf '[br]'
+ list_files |while read -r file; do list_file "$file"; done
+ fi)
] ]
EOF
+* {
+ box-sizing: border-box;
+}
+
body {
color: white;
background-color: black;
#prefs button {
margin-top: 1em;
}
+#prefs input { vertical-align: top; }
+#prefs input[type=radio] + label,
+#prefs input[type=checkbox] + label {
+ display: inline-block;
+ margin-bottom: .5em;
+ max-width: 85%;
+}
+
+.list {
+ position: relative;
+ display: inline-block;
+ width: 25%;
+ min-width: 250px;
+ padding: .5em 1em;
+ margin: 0;
+ overflow: none;
+ word-wrap: break-word;
+ vertical-align: top;
+}
+.list, .list a { color: black; }
+.list:before {
+ position: absolute;
+ top: .25em; left: .25em;
+ bottom: .25em; right: .25em;
+ z-index: -2;
+ content: '';
+}
+.list.dir:before { background-color: #CCF; }
+.list.file:before { background-color: #FDD; }
+
+.list.file img {
+ display: block;
+ width: 100%;
+}
[input name=s placeholder=Search value="%s"]
]
' \
- "$(HTML "$search")"
+ "$(HTML "$SEARCH")"
}
w_prefs(){
+ fakemp4="$(COOKIE fakemp4)"
+ mode="$(COOKIE mode)"
printf '
[form #prefs method="POST" action="?a=setprefs"
[hidden "ref" "%s"]
[label for=prefs_ps Pagesize]
[input #prefs_ps type=number name=pagesize value="%s"][br]
+ [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br]
+ [radio "mode" "index" %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br]
[checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br]
[submit "store" "store" Set Cookie]
]
' \
- "$(HTML "$REQUEST_URI")" \
- "$(COOKIE pagesize |grep -m1 -xE '[0-9]+' || printf 50)" \
- "$(COOKIE fakemp4 |grep -m1 -qx yes && printf checked)"
+ "$(HTML "$REQUEST_URI")" "$LISTSIZE" \
+ "$([ "$mode" = index ] || printf checked)" \
+ "$([ "$mode" = index ] && printf checked)" \
+ "$([ "$fakemp4" = yes ] && printf checked)"
}