]> git.plutz.net Git - serve0/commitdiff
frame for app rewrite
authorPaul Hänsch <paul@plutz.net>
Sat, 30 Jun 2018 18:54:12 +0000 (20:54 +0200)
committerPaul Hänsch <paul@plutz.net>
Sat, 30 Jun 2018 18:54:12 +0000 (20:54 +0200)
.gitignore [new file with mode: 0644]
.gitmodules
cgilite [new submodule]
index.cgi [changed from symlink to file mode: 0755]
widgets.sh [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a01ee28
--- /dev/null
@@ -0,0 +1 @@
+.*.swp
index bc75911343b5753abe035e4b0d3f7977eacb7b95..ed9b4ba55fa485e87cde3738c3b353dfeb8c1559 100644 (file)
@@ -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 (submodule)
index 0000000..3fdb8e7
--- /dev/null
+++ b/cgilite
@@ -0,0 +1 @@
+Subproject commit 3fdb8e7e2ed8fcf3129de33147d1dd3b4a204b21
deleted file mode 120000 (symlink)
index 410e699d63ab9fc7348d1ad94344a7d904bbd060..0000000000000000000000000000000000000000
--- a/index.cgi
+++ /dev/null
@@ -1 +0,0 @@
-shcgi/index.cgi
\ No newline at end of file
new file mode 100755 (executable)
index 0000000000000000000000000000000000000000..54841bf4338feab6adce565f87d6c71ad34b28b4
--- /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 (file)
index 0000000..149a813
--- /dev/null
@@ -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"
+}