Created
May 11, 2017 18:17
-
-
Save nikos-glikis/2c2e1379bcd0d6377c21d8eb8beaaa5e to your computer and use it in GitHub Desktop.
Directadmin - reset user files and folders permissions + restrict php files.
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
<?php | |
//this: https://help.directadmin.com/item.php?id=589 | |
$dirs = scandir('/home/'); | |
shuffle($dirs); | |
$ignoreDirs = [ | |
'.', | |
'..', | |
'tmp', | |
'ftp', | |
'mockbuild', | |
'temp', | |
]; | |
foreach ($dirs as $user) { | |
if (!in_array($user, $ignoreDirs)) { | |
printLine("User: " . $user); | |
printLine("---------------"); | |
$domains = scandir('/home/' . $user . '/domains/'); | |
foreach ($domains as $domain) { | |
if (!in_array($domain, $ignoreDirs)) { | |
$fullDir = '/home/' . $user . '/domains/' . $domain . '/public_html/'; | |
if (is_dir($fullDir)) { | |
$fileCommand = 'find ' . $fullDir . ' -type f -exec chmod 0644 {} \;'; | |
$dirCommand = 'find ' . $fullDir . ' -type d -exec chmod 0755 {} \;'; | |
$phpCommand = 'find ' . $fullDir . ' -type f -name \'*.php\' -exec chmod 600 {} \;'; | |
printLine($fullDir); | |
printLine($fileCommand); | |
printLine($dirCommand); | |
printLine($phpCommand); | |
system($dirCommand); | |
system($fileCommand); | |
system($phpCommand); | |
//die(); | |
printLine(); | |
} | |
} | |
} | |
} | |
printLine(); | |
} | |
printLine("Normal Exit."); | |
function printLine($text = "") | |
{ | |
print $text . PHP_EOL; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment