mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Run git as the configured user when ./validate.php is run as root
Move the modified files check out of the get_version function
This commit is contained in:
@@ -1039,10 +1039,6 @@ function version_info($remote=true) {
|
||||
$output['local_sha'] = rtrim(`git rev-parse HEAD`);
|
||||
$output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`);
|
||||
|
||||
exec('git diff --name-only --exit-code', $cmdoutput, $code);
|
||||
$output['git_modified'] = ($code !== 0);
|
||||
$output['git_modified_files'] = $cmdoutput;
|
||||
|
||||
$output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema');
|
||||
$output['php_ver'] = phpversion();
|
||||
$output['mysql_ver'] = dbFetchCell('SELECT version()');
|
||||
|
||||
11
validate.php
11
validate.php
@@ -36,7 +36,7 @@ if (isset($options['h'])) {
|
||||
if (strstr(`php -ln config.php`, 'No syntax errors detected')) {
|
||||
$first_line = `head -n1 config.php`;
|
||||
$last_lines = explode(PHP_EOL, `tail -n2 config.php`);
|
||||
if (strstr($first_line, '\<\?php')) {
|
||||
if (substr($first_line, 0, 5) !== '<?php') {
|
||||
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
|
||||
}
|
||||
else if ($last_lines[0] == '?>' && $last_lines[1] == '') {
|
||||
@@ -84,9 +84,14 @@ else {
|
||||
if($versions['local_branch'] != 'master') {
|
||||
print_warn("Your local git branch is not master, this will prevent automatic updates.");
|
||||
}
|
||||
if($versions['git_modified'] === true) {
|
||||
|
||||
$modifiedcmd = 'git diff --name-only --exit-code';
|
||||
if($username === 'root') {
|
||||
$modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"';
|
||||
}
|
||||
if(exec($modifiedcmd, $cmdoutput, $code) !== 0) {
|
||||
print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:");
|
||||
echo(implode("\n", $versions['git_modified_files']) . "\n");
|
||||
echo(implode("\n", $cmdoutput) . "\n");
|
||||
}
|
||||
|
||||
echo "DB Schema: ".$versions['db_schema']."\n";
|
||||
|
||||
Reference in New Issue
Block a user