Skip to content

Commit

Permalink
Update storage.php
Browse files Browse the repository at this point in the history
  • Loading branch information
curtishall authored Jan 1, 2024
1 parent 0e3d7b8 commit 867023a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions www/ajax/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,55 @@ public function postData()
data::responseJSON($status);
}
}


root@7007cams:/usr/share/bluecherry/www/ajax# cat storagecheck.php
<?php

class storagecheck extends Controller {

public function __construct()
{
parent::__construct();
$this->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);
}
}

}

0 comments on commit 867023a

Please sign in to comment.