From 10597e4506dca6e0f4abe239ff44e742d3de8a8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sat, 30 Jun 2018 20:54:12 +0200 Subject: [PATCH] frame for app rewrite --- .gitignore | 1 + .gitmodules | 3 +++ cgilite | 1 + index.cgi | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- widgets.sh | 29 +++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 160000 cgilite mode change 120000 => 100755 index.cgi create mode 100644 widgets.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01ee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/.gitmodules b/.gitmodules index bc75911..ed9b4ba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "shcgi"] path = shcgi url = https://git.plutz.net/git/shcgi +[submodule "cgilite"] + path = cgilite + url = https://git.plutz.net/git/cgilite diff --git a/cgilite b/cgilite new file mode 160000 index 0000000..3fdb8e7 --- /dev/null +++ b/cgilite @@ -0,0 +1 @@ +Subproject commit 3fdb8e7e2ed8fcf3129de33147d1dd3b4a204b21 diff --git a/index.cgi b/index.cgi deleted file mode 120000 index 410e699..0000000 --- a/index.cgi +++ /dev/null @@ -1 +0,0 @@ -shcgi/index.cgi \ No newline at end of file diff --git a/index.cgi b/index.cgi new file mode 100755 index 0000000..54841bf --- /dev/null +++ b/index.cgi @@ -0,0 +1,56 @@ +#!/bin/sh + +[ -z "${_EXEC%/}" ] && _EXEC=. || _EXEC="${_DATA%/}" +[ -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)" + +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)) fakemp4="$(POST fakemp4 |grep -m1 -xE 'yes' || printf no)" + printf 'Location: %s\r\n\r\n' "$(POST ref)" + ;; +esac + +if [ -f "$_DATA/$item" ]; then + case $(GET a) in + tag) + ;; + download) + ;; + thumbnail) + ;; + delete) + ;; + *) + ;; + esac +elif [ -d "$_DATA/$item" ]; then + case $(GET a) in + multitag) + ;; + *) printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' + "$_EXEC/cgilite/html-sh.sed" <<-EOF + [!DOCTYPE HTML] + [html [head [title Listing] + ] [body + $(w_search) $(w_prefs) + ] ] + EOF + exit 0 + ;; + esac +else + printf 'Status: 404 Not Found\r\n\r\n' + exit 0 +fi diff --git a/widgets.sh b/widgets.sh new file mode 100644 index 0000000..149a813 --- /dev/null +++ b/widgets.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +w_search(){ + printf ' + [form method=GET action=? + [select name=o size=1 + [option disabled=disabled Order By] + [option value=Name Name] + [option value=Date Date] + [option value=Length Length] + ] + [input name=s placeholder=Search value="%s"] + ] + ' \ + "$(HTML "$search")" +} + +w_prefs(){ + printf ' + [form method=POST action=?a=setprefs + [hidden "ref" "%s"] + [label for=prefs_ps Pagesize] + [input type=number name=pagesize value="%s"] + [checkbox "fakemp4" "yes" #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending] + [submit "store" "store" Set Cookie] + ] + ' \ + "$(HTML "$REQUEST_URI")" "$pagesize" +} -- 2.39.2