-
Notifications
You must be signed in to change notification settings - Fork 975
/
Copy pathfix_dirs_permissions.php
43 lines (33 loc) · 1.01 KB
/
fix_dirs_permissions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?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 $dir ".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 = [
getVideosDir(),
"{$global['systemRootPath']}Encoder/videos" . DIRECTORY_SEPARATOR
];
setPermissions($directories);
echo "Permissions have been set successfully.\n";
?>