mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	refactor: validate.php improvements (#6973)
Always output header (may be missing mysql data) Improve version display, now looks like '1.28-129-g74e6c3edf' <tag>-<commits since tag>-<shortag> Add mysqli to the list of required extensions, check extensions before init Add dbIsConnected() function, used to check if we have db in version_info() Do not die on IPv4 and IPv6 so validate can print errors. Move git checks so they are output together fix rrdtool 1.7.0 reports version as 1.7.01.7.0
This commit is contained in:
		
				
					committed by
					
						
						Neil Lathwood
					
				
			
			
				
	
			
			
			
						parent
						
							97828eceba
						
					
				
				
					commit
					1e77d4b3ea
				
			@@ -659,10 +659,31 @@ function c_echo($string, $enabled = true)
 | 
			
		||||
    if (!$enabled) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    global $console_color;
 | 
			
		||||
 | 
			
		||||
    if ($console_color) {
 | 
			
		||||
        echo $console_color->convert($string);
 | 
			
		||||
    if (isCli()) {
 | 
			
		||||
        global $console_color;
 | 
			
		||||
        if ($console_color) {
 | 
			
		||||
            echo $console_color->convert($string);
 | 
			
		||||
        } else {
 | 
			
		||||
            // limited functionality for validate.php
 | 
			
		||||
            $search = array(
 | 
			
		||||
                '/%n/',
 | 
			
		||||
                '/%g/',
 | 
			
		||||
                '/%R/',
 | 
			
		||||
                '/%Y/',
 | 
			
		||||
                '/%B/',
 | 
			
		||||
                '/%((%)|.)/' // anything left over replace with empty string
 | 
			
		||||
            );
 | 
			
		||||
            $replace = array(
 | 
			
		||||
                "\e[0m",
 | 
			
		||||
                "\e[32m",
 | 
			
		||||
                "\e[1;31m",
 | 
			
		||||
                "\e[1;33m",
 | 
			
		||||
                "\e[1;34m",
 | 
			
		||||
                ""
 | 
			
		||||
            );
 | 
			
		||||
            echo preg_replace($search, $replace, $string);
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        echo preg_replace('/%((%)|.)/', '', $string);
 | 
			
		||||
    }
 | 
			
		||||
@@ -1097,15 +1118,20 @@ function version_info($remote = true)
 | 
			
		||||
            $output['github'] = json_decode(curl_exec($api), true);
 | 
			
		||||
        }
 | 
			
		||||
        list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`));
 | 
			
		||||
        $output['local_ver']    = rtrim(`git describe --tags`);
 | 
			
		||||
        $output['local_sha']    = $local_sha;
 | 
			
		||||
        $output['local_date']   = $local_date;
 | 
			
		||||
        $output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`);
 | 
			
		||||
    }
 | 
			
		||||
    $output['db_schema']   = get_db_schema();
 | 
			
		||||
    $output['db_schema']   = get_db_schema() ?: '?';
 | 
			
		||||
    $output['php_ver']     = phpversion();
 | 
			
		||||
    $output['mysql_ver']   = dbFetchCell('SELECT version()');
 | 
			
		||||
    $output['rrdtool_ver'] = implode(' ', array_slice(explode(' ', shell_exec($config['rrdtool'].' --version |head -n1')), 1, 1));
 | 
			
		||||
    $output['netsnmp_ver'] = str_replace('version: ', '', rtrim(shell_exec($config['snmpget'].' --version 2>&1')));
 | 
			
		||||
    $output['mysql_ver']   = dbIsConnected() ? dbFetchCell('SELECT version()') : '?';
 | 
			
		||||
    $output['rrdtool_ver'] = str_replace('1.7.01.7.0', '1.7.0', implode(' ', array_slice(explode(' ', shell_exec(
 | 
			
		||||
        ($config['rrdtool'] ?: 'rrdtool') . ' --version |head -n1'
 | 
			
		||||
    )), 1, 1)));
 | 
			
		||||
    $output['netsnmp_ver'] = str_replace('version: ', '', rtrim(shell_exec(
 | 
			
		||||
        ($config['snmpget'] ?: 'snmpget').' --version 2>&1'
 | 
			
		||||
    )));
 | 
			
		||||
 | 
			
		||||
    return $output;
 | 
			
		||||
}//end version_info()
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,16 @@
 | 
			
		||||
 | 
			
		||||
use LibreNMS\Exceptions\DatabaseConnectException;
 | 
			
		||||
 | 
			
		||||
function dbIsConnected()
 | 
			
		||||
{
 | 
			
		||||
    global $database_link;
 | 
			
		||||
    if (empty($database_link)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return mysqli_ping($database_link);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Connect to the database.
 | 
			
		||||
 * Will use global $config variables if they are not sent: db_host, db_user, db_pass, db_name, db_port, db_socket
 | 
			
		||||
@@ -35,6 +45,11 @@ use LibreNMS\Exceptions\DatabaseConnectException;
 | 
			
		||||
function dbConnect($host = null, $user = '', $password = '', $database = '', $port = null, $socket = null)
 | 
			
		||||
{
 | 
			
		||||
    global $config, $database_link;
 | 
			
		||||
 | 
			
		||||
    if (dbIsConnected()) {
 | 
			
		||||
        return $database_link;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $host = empty($host) ? $config['db_host'] : $host;
 | 
			
		||||
    $user = empty($user) ? $config['db_user'] : $user;
 | 
			
		||||
    $password = empty($password) ? $config['db_pass'] : $password;
 | 
			
		||||
 
 | 
			
		||||
@@ -34,8 +34,8 @@ $config['install_dir'] = $install_dir;
 | 
			
		||||
chdir($install_dir);
 | 
			
		||||
 | 
			
		||||
if (!getenv('TRAVIS')) {
 | 
			
		||||
    require_once 'Net/IPv4.php';
 | 
			
		||||
    require_once 'Net/IPv6.php';
 | 
			
		||||
    include_once 'Net/IPv4.php';
 | 
			
		||||
    include_once 'Net/IPv6.php';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# composer autoload
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user