diff --git a/scripts/check_dir_permission.sh b/scripts/check_dir_permission.sh new file mode 100644 index 00000000..17599939 --- /dev/null +++ b/scripts/check_dir_permission.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# script to change permission of file + +# File variable to store location + +FILE="$1" + +if [[ ! -e "${FILE}" ]]; then + # creating directory... + mkdir -p "${FILE}" + # write permission of other and group of file + chmod 770 "${FILE}" + chown -R bluecherry:bluecherry "${FILE}" +elif [[ ! -d "${FILE}" ]]; then + echo "FILE already exists but is not a directory" +fi + +# find out if file has write permission or not +#[ -w $FILE ] && W="Write = yes" || W="Write = No" +[ -w $FILE ] && W=w || W='-' + +# find out if file has excute permission or not +[ -x $FILE ] && X=x || X='-' + +# find out if file has read permission or not +[ -r $FILE ] && R=r || R='-' + +#echo "$FILE permissions" +echo "-$W$R$X" \ No newline at end of file diff --git a/www/ajax/storagecheck.php b/www/ajax/storagecheck.php index 1f29f4e1..8f6303bf 100644 --- a/www/ajax/storagecheck.php +++ b/www/ajax/storagecheck.php @@ -29,11 +29,15 @@ private function initProc() // path -- path to storage dir, type -- new or existing, existing are not checked for existing files public function directory_status($path, $type = '') { - #if file - if (!file_exists($path)){ - return array('F', str_replace('%PATH%', $path, DIR_DOES_NOT_EXIST_OR_NOT_READABLE)); - } + $dir = shell_exec("sudo /usr/share/bluecherry/scripts/check_dir_permission.sh $path"); + if (!file_exists($path)){ + return array('F', str_replace('%PATH%', $path, DIR_DOES_NOT_EXIST_OR_NOT_READABLE)); + } + + if(!substr_count($dir, '-wrx')){ + return array('F', str_replace('%PATH%', $path, DIR_NOT_WRITABLE)); + } $file_group = posix_getgrgid(filegroup($path)); $allowed_group = array('bluecherry', 'www-data'); if ((!isset($file_group['name'])) || (isset($file_group['name']) && (!in_array($file_group['name'], $allowed_group)))) { @@ -45,13 +49,17 @@ public function directory_status($path, $type = '') return array('F', str_replace('%PATH%', $path, DIR_NOT_READABLE)); } + if (!is_writable($path)) { + return array('F', str_replace('%PATH%', $path, DIR_NOT_WRITABLE)); + } + if (!is_readable($path)) { return array('F', str_replace('%PATH%', $path, DIR_NOT_READABLE)); } - if ($type == 'new'){ - return (count(scandir($path)) == 2) ? array('OK', DIR_OK) : array('INFO', str_replace('%PATH%', $path, DIR_NOT_EMPTY)); - } + if ($type == 'new'){ + return (count(scandir($path)) == 2) ? array('OK', DIR_OK) : array('INFO', str_replace('%PATH%', $path, DIR_NOT_EMPTY)); + } return false; } diff --git a/www/lib/lang.php b/www/lib/lang.php index 0d54d2fc..a0560005 100644 --- a/www/lib/lang.php +++ b/www/lib/lang.php @@ -462,6 +462,7 @@ define('STORAGE_INFO_MESSAGE', 'Please note that if you add a new storage location, you need to make sure that:
- folder exists
- folder is empty
- folder belongs to user bluecherry, group bluecherry.'); define('DIR_DOES_NOT_EXIST_OR_NOT_READABLE', 'Server could not open the specified directory "%PATH%". See Note 2. '); +define('DIR_NOT_WRITABLE', 'Specified directory "%PATH%" exists, but is not writable See Note 2.'); define('DIR_NOT_READABLE', 'Specified directory "%PATH%" exists, but is not readable. See Note 2. '); define('DIR_NOT_EMPTY', 'Specified directory is not empty, all contents will be deleted after it is added.');