mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 10:37:42 -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
|
@ -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