Skip to content

Commit

Permalink
Can't change storage settings because folder is not owned by BC, yet …
Browse files Browse the repository at this point in the history
…it can write to it #563
  • Loading branch information
divsbhalala committed Feb 20, 2023
1 parent 81d6be3 commit 3d61848
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
44 changes: 44 additions & 0 deletions scripts/check_dir_permission.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions www/ajax/storagecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand All @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions www/lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
define('STORAGE_INFO_MESSAGE', 'Please note that if you add a new storage location, you need to make sure that: <br /> - folder exists <br /> - folder is empty <br /> - folder belongs to user bluecherry, group bluecherry.');
define('DIR_DOES_NOT_EXIST_OR_NOT_READABLE', 'Server could not open the specified directory "<b>%PATH%</b>". See Note 2.
');
define('DIR_NOT_WRITABLE', 'Specified directory "<b>%PATH%</b>" exists, but is not writable See Note 2.');
define('DIR_NOT_READABLE', 'Specified directory "<b>%PATH%</b>" 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.');
Expand Down

0 comments on commit 3d61848

Please sign in to comment.