]> git.plutz.net Git - serve0/blobdiff - pages/tree.sh
new folder browse section
[serve0] / pages / tree.sh
diff --git a/pages/tree.sh b/pages/tree.sh
new file mode 100755 (executable)
index 0000000..40a50cc
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/zsh
+
+# Copyright 2014, 2015 Paul Hänsch
+#
+# This file is part of Serve0.
+# 
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0.  If not, see <http://www.gnu.org/licenses/>. 
+
+. $_EXEC/pages/common.sh
+
+directory="$(invalidate "${_GET[d]}" '(.*/)?\.\.(/.*)?|' /)"
+
+filelist(){
+  debug "Filelist with dir = $directory"
+
+  [ -n "${directory#/}" ] && printf %s "<a class='file directory' href='?p=tree&d=$(urlsafe "${directory%/*}")'>..</a>"
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type d \
+  | sort \
+  | while read dir; do
+    name="${dir##*/}"
+    printf %s "<a class='file directory' href='?p=tree&d=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>"
+  done
+
+  find -L "${treeroot%/}/${directory#/}" -mindepth 1 -maxdepth 1 -type f \
+  | sort \
+  | while read file; do
+    name="${file##*/}"
+    printf %s\\n "$name" |egrep -q "$file_pattern" && \
+       printf %s "<a class='file video' href='?action=watch&l=$(urlsafe "${directory%/}/$name")'>$(htmlsafe "$name")</a>" \
+    || printf %s "<span class='file plain'>$(htmlsafe "$name")</span>"
+  done
+}
+