-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
daniel
authored and
daniel
committed
Jun 14, 2024
1 parent
5a09587
commit 90ab24a
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
require_once '../videos/configuration.php'; | ||
|
||
if (!isCommandLineInterface()) { | ||
return die('Command Line only'); | ||
} | ||
|
||
function setPermissions($directories) { | ||
foreach ($directories as $dir) { | ||
if (is_dir($dir)) { | ||
echo "Set Permission ".PHP_EOL; | ||
setPermissionsRecursively($dir); | ||
} else { | ||
echo "The path $dir is not a directory.\n"; | ||
} | ||
} | ||
} | ||
|
||
function setPermissionsRecursively($dir) { | ||
// Ensure the directory path is safe to use | ||
$safeDir = escapeshellarg($dir); | ||
|
||
// Set directory permissions to 755 | ||
exec("find $safeDir -type d -exec chmod 755 {} +"); | ||
|
||
// Set file permissions to 644 | ||
exec("find $safeDir -type f -exec chmod 644 {} +"); | ||
|
||
// Change ownership to www-data | ||
exec("chown -R www-data:www-data $safeDir"); | ||
} | ||
|
||
// Example usage | ||
$directories = [ | ||
"{$global['systemRootPath']}videos" . DIRECTORY_SEPARATOR | ||
]; | ||
|
||
setPermissions($directories); | ||
|
||
echo "Permissions have been set successfully.\n"; | ||
|
||
?> |