diff --git a/scripts/check_dir_permission.sh b/scripts/check_dir_permission.sh new file mode 100755 index 00000000..62ab2d1f --- /dev/null +++ b/scripts/check_dir_permission.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# script to change permission of file + +# File variable to store location + +FILE="$1" + +#if [[ ! -e "${FILE}" ]]; then +# mkdir -p "${FILE}" +## echo "creating directory..." +#elif [[ ! -d "${FILE}" ]]; then +# echo "FILE already exists but is not a directory" +#fi + +## to remove write permission of other and group of file +#chmod 770 "${FILE}" +#chown -R bluecherry:bluecherry "${FILE}" + +#to check if the permission are removed +#ls -la "${FILE}" + +# 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" + + + +# to check the file we want to change +## exists or not +#if [[ ! -e "${FILE}" ]] +#then +# echo "creating ${FILE} file" +# touch file.txt +#fi \ No newline at end of file diff --git a/www/ajax/storagecheck.php b/www/ajax/storagecheck.php index 1f29f4e1..76f062d3 100644 --- a/www/ajax/storagecheck.php +++ b/www/ajax/storagecheck.php @@ -34,6 +34,10 @@ public function directory_status($path, $type = '') return array('F', str_replace('%PATH%', $path, DIR_DOES_NOT_EXIST_OR_NOT_READABLE)); } + $dir = shell_exec("/usr/share/bluecherry/scripts/check_dir_permission.sh $path"); + if(!strpos($dir, 'wr')){ + 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,6 +49,10 @@ 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)); } 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.');