Skip to content

Instantly share code, notes, and snippets.

@nikos-glikis
Created May 11, 2017 18:17
Show Gist options
  • Save nikos-glikis/2c2e1379bcd0d6377c21d8eb8beaaa5e to your computer and use it in GitHub Desktop.
Save nikos-glikis/2c2e1379bcd0d6377c21d8eb8beaaa5e to your computer and use it in GitHub Desktop.
Directadmin - reset user files and folders permissions + restrict php files.
<?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