API backend for Web File Manager

This commit is contained in:
Serghey Rodin 2015-07-16 02:21:22 +03:00
commit 75374e264a
11 changed files with 431 additions and 42 deletions

View file

@ -1,5 +1,8 @@
#!/bin/bash
# File list wrapper
# info: list directory
# options: USER DIRECTORY
#
# The function lists directory on the file system
user=$1
path=$2
@ -10,12 +13,12 @@ if [ -z "$user" ]; then
exit 1
fi
# Checking users
# Checking vesta user
if [ ! -e "$VESTA/data/users/$user" ]; then
exit 1
fi
# Checking homedir
# Checking user homedir
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
if [ -z $homedir ]; then
exit 1
@ -23,7 +26,6 @@ fi
# Checking path
if [ ! -z "$path" ]; then
# Validating absolute path
rpath=$(readlink -f "$path")
if [ -z "$(echo $rpath |grep $homedir)" ]; then
exit 1
@ -32,8 +34,9 @@ else
path=$homedir
fi
# Listing files
find "$path" -maxdepth 1 -printf "%y|%m|%TY-%Tm-%Td|%TH:%TM:%TS|%u|%g|%s|%P\n"
# Listing directory
sudo -u $user find "$path" -maxdepth 1 \
-printf "%y|%m|%TY-%Tm-%Td|%TH:%TM:%TS|%u|%g|%s|%P\n" 2>/dev/null
exit
# Exiting
exit $?