Skip to content

Commit

Permalink
Fixed storage check issue with directory permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
chiqovani committed May 4, 2023
1 parent 6e6e1d9 commit 04ede6f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
30 changes: 30 additions & 0 deletions scripts/check_dir_permission.sh
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 15 additions & 7 deletions www/ajax/storagecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand All @@ -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;
}
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 04ede6f

Please sign in to comment.