Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate.php: Updated file permissions check #9218

Merged
merged 3 commits into from Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 24 additions & 17 deletions LibreNMS/Validations/User.php
Expand Up @@ -63,6 +63,12 @@ public function validate(Validator $validator)
// Let's test the user configured if we have it
if (Config::has('user')) {
$dir = Config::get('install_dir');

// generic fix
$fix = "sudo chown -R $lnms_username:$lnms_groupname $dir\n" .
"sudo setfacl -d -m g::rwx $dir/rrd $dir/logs $dir/bootstrap/cache/ $dir/storage/\n" .
"sudo chmod -R ug=rwX $dir/rrd $dir/logs $dir/bootstrap/cache/ $dir/storage/\n";

$find_result = rtrim(`find $dir \! -user $lnms_username -o \! -group $lnms_groupname 2> /dev/null`);
if (!empty($find_result)) {
// Ignore files created by the webserver
Expand Down Expand Up @@ -90,31 +96,32 @@ public function validate(Validator $validator)
"We have found some files that are owned by a different user than $lnms_username, this " .
'will stop you updating automatically and / or rrd files being updated causing graphs to fail.'
)
->setFix("chown -R $lnms_username:$lnms_groupname $dir")
->setFix($fix)
->setList('Files', $files);

$validator->result($result);
return;
}
}
} else {
$validator->warn("You don't have \$config['user'] set, this most likely needs to be set to librenms");
}

// check permissions
$folders = [
'rrd' => Config::get('rrd_dir'),
'log' => Config::get('log_dir'),
'bootstrap' => "$dir/bootstrap/cache/",
'storage' => "$dir/storage/",
'cache' => "$dir/storage/framework/cache/",
'sessions' => "$dir/storage/framework/sessions/",
'views' => "$dir/storage/framework/views/",
];
// check folder permissions
$folders = [
'rrd' => Config::get('rrd_dir'),
'log' => Config::get('log_dir'),
'bootstrap' => "$dir/bootstrap/cache/",
'storage' => "$dir/storage/",
'cache' => "$dir/storage/framework/cache/",
'sessions' => "$dir/storage/framework/sessions/",
'views' => "$dir/storage/framework/views/",
];

foreach ($folders as $name => $folder) {
if (!check_file_permissions($folder, '660')) {
$validator->fail("The $name folder has improper permissions.", "chmod ug+rw $folder");
$folders_string = implode(' ', $folders);
$incorrect = exec("find $folders_string -group $lnms_groupname ! -perm -g=w");
if (!empty($incorrect)) {
$validator->fail("Some folders have incorrect file permissions", $fix);
}
} else {
$validator->warn("You don't have \$config['user'] set, this most likely needs to be set to librenms");
}
}
}
Empty file modified logs/.gitignore 100644 → 100755
Empty file.
Empty file modified rrd/.gitignore 100644 → 100755
Empty file.