mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-14 18:49:17 -07:00
API backend for Web File Manager
This commit is contained in:
parent
edcd549e4c
commit
75374e264a
11 changed files with 431 additions and 42 deletions
37
bin/v-add-fs-directory
Executable file
37
bin/v-add-fs-directory
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
# info: add directory
|
||||
# options: USER DIRECTORY
|
||||
#
|
||||
# The function creates new directory on the file system
|
||||
|
||||
user=$1
|
||||
dst_dir=$2
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_dir" ]; then
|
||||
echo "Usage: USER DIRECTORY"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_dir")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Adding directory
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
|
||||
# Extiging
|
||||
exit $?
|
37
bin/v-add-fs-file
Executable file
37
bin/v-add-fs-file
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
# info: add file
|
||||
# options: USER FILE
|
||||
#
|
||||
# The function creates new files on file system
|
||||
|
||||
user=$1
|
||||
dst_file=$2
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_file" ]; then
|
||||
echo "Usage: USER FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Creating file
|
||||
sudo -u $user touch $dst_file >/dev/null 2>&1
|
||||
|
||||
# Exiting
|
||||
exit $?
|
43
bin/v-change-fs-file-permission
Executable file
43
bin/v-change-fs-file-permission
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!/bin/bash
|
||||
# info: change file permission
|
||||
# options: USER FILE PERMISSIONS
|
||||
#
|
||||
# The function changes file access permissions on the file system
|
||||
|
||||
user=$1
|
||||
src_file=$2
|
||||
permissions=$3
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$permissions" ]; then
|
||||
echo "Usage: USER FILE PERMISSIONS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source file
|
||||
if [ ! -f "$src_file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source path
|
||||
rpath=$(readlink -f "$src_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Changing file permissions
|
||||
sudo -u $user chmod $permisions $src_file >/dev/null 2>&1
|
||||
|
||||
# Exiting
|
||||
exit $?
|
49
bin/v-copy-fs-directory
Executable file
49
bin/v-copy-fs-directory
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/bin/bash
|
||||
# info: copy directory
|
||||
# options: USER SRC_DIRECTORY DST_DIRECTORY
|
||||
#
|
||||
# The function copies directory on the file system
|
||||
|
||||
user=$1
|
||||
src_dir=$2
|
||||
dst_dir=$3
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_dir" ]; then
|
||||
echo "Usage: USER SRC_DIRECTORY DST_DIRECTORY"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source dir
|
||||
if [ ! -e "$src_dir" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source path
|
||||
rpath=$(readlink -f "$src_dir")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_dir")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copying directory
|
||||
sudo -u $user cp -r $src_dir $dst_dir >/dev/null 2>&1
|
||||
|
||||
# Exiting
|
||||
exit $?
|
|
@ -1,58 +1,49 @@
|
|||
#!/bin/bash
|
||||
# File copier
|
||||
# info: copy file
|
||||
# options: USER SRC_FILE DST_FLE
|
||||
#
|
||||
# The function copies file on the file system
|
||||
|
||||
user=$1
|
||||
file_src=$2
|
||||
file_dst=$3
|
||||
src_file=$2
|
||||
dst_file=$3
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$file_dst" ]; then
|
||||
if [ -z "$dst_file" ]; then
|
||||
echo "Usage: USER SRC_FILE DST_FILE"
|
||||
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
|
||||
fi
|
||||
|
||||
# Checking source file
|
||||
if [ ! -e "$file_src" ]; then
|
||||
if [ ! -f "$src_file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source path
|
||||
rpath=$(readlink -f "$file_src")
|
||||
if [ -z "$(echo $rpath |grep ^/tmp)" ]; then
|
||||
rpath=$(readlink -f "$src_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$file_dst")
|
||||
if [ -z "$(echo $rpath |grep ^$homedir)" ]; then
|
||||
rpath=$(readlink -f "$dst_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking dst file permission
|
||||
if [ -e "$file_dst" ]; then
|
||||
perms=$(stat --format '%a' $file_dst)
|
||||
fi
|
||||
|
||||
# Copying file
|
||||
cp $file_src $file_dst
|
||||
sudo -u $user cp $src_file $dst_file >/dev/null 2>&1
|
||||
|
||||
# Changing ownership
|
||||
chown $user:$user $file_dst
|
||||
|
||||
# Changin permissions
|
||||
if [ ! -z "$perms" ]; then
|
||||
chmod $perms $file_dst
|
||||
fi
|
||||
|
||||
exit
|
||||
# Exiting
|
||||
exit $?
|
||||
|
|
38
bin/v-delete-fs-dir
Executable file
38
bin/v-delete-fs-dir
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
# info: delete directory
|
||||
# options: USER DIRECTORY
|
||||
#
|
||||
# The function deletes directory on the file system
|
||||
|
||||
|
||||
user=$1
|
||||
dst_dir=$2
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_dir" ]; then
|
||||
echo "Usage: USER DIRECTORY"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_dir")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Deleting directory
|
||||
sudo -u $user rm -rf $dst_dir >/dev/null 2>&1
|
||||
|
||||
# Exiting
|
||||
exit $?
|
38
bin/v-delete-fs-file
Executable file
38
bin/v-delete-fs-file
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
# info: delete file
|
||||
# options: USER FILE
|
||||
#
|
||||
# The function deletes file on the file system
|
||||
|
||||
|
||||
user=$1
|
||||
dst_file=$2
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_file" ]; then
|
||||
echo "Usage: USER FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Deleting file
|
||||
sudo -u $user rm -f $dst_file >/dev/null 2>&1
|
||||
|
||||
# Exiting
|
||||
exit $?
|
100
bin/v-extract-fs-archive
Executable file
100
bin/v-extract-fs-archive
Executable file
|
@ -0,0 +1,100 @@
|
|||
#!/bin/bash
|
||||
# info: archive to directory
|
||||
# options: USER ARCHIVE DIRECTORY
|
||||
#
|
||||
# The function extracts archive into directory on the file system
|
||||
|
||||
user=$1
|
||||
src_file=$2
|
||||
dst_dir=$3
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_dir" ]; then
|
||||
echo "Usage: USER ARCHIVE DIRECTORY"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source dir
|
||||
if [ ! -e "$src_file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source path
|
||||
rpath=$(readlink -f "$src_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_dir")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extracting gziped archive
|
||||
if [ ! -z "$(echo $src_file |egrep -i '.tgz|.tar.gz')" ]; then
|
||||
x='yes'
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user tar -xzf $src_file -C $dst_dir >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Extracting bziped archive
|
||||
if [ ! -z "$(echo $src_file |egrep -i '.tbz|.tar.bz')" ]; then
|
||||
x='yes'
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user tar -xjf $src_file -C $dst_dir >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Extracting gziped file
|
||||
if [ ! -z "$(echo $src_file |grep -i '.gz')" ] && [ -z "$x" ]; then
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user mv $src_file $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user gzip -d $dst_dir/$(basename $src_file) >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Extracting bziped file
|
||||
if [ ! -z "$(echo $src_file |grep -i '.bz')" ] && [ -z "$x" ]; then
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user mv $src_file $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user bzip2 -d $dst_dir/$(basename $src_file) >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Extracting ziped archive
|
||||
if [ ! -z "$(echo $src_file |grep -i '.zip')" ]; then
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user unzip $src_file -d $dst_dir >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Extracting tared archive
|
||||
if [ ! -z "$(echo $src_file |grep -i '.tar')" ] && [ -z "$x" ]; then
|
||||
x='yes'
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user tar -xf $src_file -C $dst_dir >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Extracting rared archive
|
||||
if [ ! -z "$(echo $src_file |grep -i '.rar')" ]; then
|
||||
sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1
|
||||
sudo -u $user unrar $src_file $dst_dir >/dev/null 2>&1
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
# Exiting
|
||||
exit $rc
|
|
@ -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 $?
|
||||
|
|
50
bin/v-move-fs-file
Executable file
50
bin/v-move-fs-file
Executable file
|
@ -0,0 +1,50 @@
|
|||
#!/bin/bash
|
||||
# info: move file
|
||||
# options: USER SRC_FILE DST_FLE
|
||||
#
|
||||
# The function moved file or directory on the file system. This function
|
||||
# can also be used to rename files just like normal mv command.
|
||||
|
||||
user=$1
|
||||
src_file=$2
|
||||
dst_file=$3
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$dst_file" ]; then
|
||||
echo "Usage: USER SRC_FILE DST_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking vesta user
|
||||
if [ ! -e "$VESTA/data/users/$user" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking user homedir
|
||||
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
|
||||
if [ -z $homedir ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source file
|
||||
if [ ! -f "$src_file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking source path
|
||||
rpath=$(readlink -f "$src_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Checking destination path
|
||||
rpath=$(readlink -f "$dst_file")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copying file
|
||||
sudo -u $user mv $src_file $dst_file >/dev/null 2>&1
|
||||
|
||||
# Exiting
|
||||
exit $?
|
|
@ -1,5 +1,8 @@
|
|||
#!/bin/bash
|
||||
# File reader
|
||||
# info: open file
|
||||
# options: USER FILE
|
||||
#
|
||||
# The function opens/reads files on the file system
|
||||
|
||||
user=$1
|
||||
path=$2
|
||||
|
@ -10,12 +13,12 @@ if [ -z "$path" ]; 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,14 +26,14 @@ fi
|
|||
|
||||
# Checking path
|
||||
if [ ! -z "$path" ]; then
|
||||
# Validating absolute path
|
||||
rpath=$(readlink -f "$path")
|
||||
if [ -z "$(echo $rpath |grep $homedir)" ]; then
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cat "$path"
|
||||
|
||||
exit
|
||||
# Reading file
|
||||
sudo -u $user cat "$path"
|
||||
|
||||
# Exiting
|
||||
exit $?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue