diff --git a/www/ajax/storage.php b/www/ajax/storage.php index 6525ac74..a25f91aa 100644 --- a/www/ajax/storage.php +++ b/www/ajax/storage.php @@ -59,3 +59,55 @@ public function postData() data::responseJSON($status); } } + + +root@7007cams:/usr/share/bluecherry/www/ajax# cat storagecheck.php +chAccess('admin'); + } + + public function getData() + { + $this->initProc(); + } + + public function postData() + { + $this->initProc(); + } + + private function initProc() + { + $change_status = $this->change_directory_permissions($_GET['path']); + data::responseJSON($change_status[0], $change_status[1]); + } + + // Function to call the bash script to change permissions of a directory + +public function change_directory_permissions($path) +{ + // Call the bash script to change directory permissions and ownership + // This will also handle directory creation if it doesn't exist + $output = shell_exec("sudo /usr/share/bluecherry/scripts/check_dir_permission.sh " . escapeshellarg($path)); + + // Interpret the output from the script to form the response + if (strpos($output, 'Error') !== false) { + return array('F', $output); + } elseif (strpos($output, 'Changing permissions') !== false || strpos($output, 'Modifying permissions and ownership') !== false) { + return array('OK', 'Permissions and ownership changed for ' . $path); + } elseif (strpos($output, 'already has the correct permissions and ownership') !== false) { + return array('OK', ''); + } elseif (strpos($output, 'Directory does not exist. Creating it now') !== false) { + return array('OK', 'Directory created and permissions set for ' . $path); + } else { + return array('F', 'Unexpected output from shell script: ' . $output); + } +} + +}