コード例 #1
0
ファイル: common.php プロジェクト: BillTheBest/librenms
/**
 * Returns version info
 * @return array
**/
function version_info($remote = true)
{
    global $config;
    $output = array();
    if ($remote === true && $config['update_channel'] == 'master') {
        $api = curl_init();
        set_curl_proxy($api);
        curl_setopt($api, CURLOPT_USERAGENT, 'LibreNMS');
        curl_setopt($api, CURLOPT_URL, $config['github_api'] . 'commits/master');
        curl_setopt($api, CURLOPT_RETURNTRANSFER, 1);
        $output['github'] = json_decode(curl_exec($api), true);
    }
    $output['local_sha'] = chop(`git rev-parse HEAD`);
    $output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema');
    $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'] = shell_exec($config['snmpget'] . ' --version 2>&1');
    return $output;
}
コード例 #2
0
ファイル: common.php プロジェクト: arrmo/librenms
/**
 * Returns version info
 * @return array
**/
function version_info($remote = true)
{
    global $config;
    $output = array();
    if ($remote === true && $config['update_channel'] == 'master') {
        $api = curl_init();
        set_curl_proxy($api);
        curl_setopt($api, CURLOPT_USERAGENT, 'LibreNMS');
        curl_setopt($api, CURLOPT_URL, $config['github_api'] . 'commits/master');
        curl_setopt($api, CURLOPT_RETURNTRANSFER, 1);
        $output['github'] = json_decode(curl_exec($api), true);
    }
    list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`));
    $output['local_sha'] = $local_sha;
    $output['local_date'] = $local_date;
    $output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`);
    $output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema');
    $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')));
    return $output;
}
コード例 #3
0
ファイル: functions.inc.php プロジェクト: jcbailey2/librenms
function location_to_latlng($device)
{
    global $config;
    if (function_check('curl_version') !== true) {
        d_echo("Curl support for PHP not enabled\n");
        return false;
    }
    $bad_loc = false;
    $device_location = $device['location'];
    if (!empty($device_location)) {
        $new_device_location = preg_replace("/ /", "+", $device_location);
        // We have a location string for the device.
        $loc = parse_location($device_location);
        if (!is_array($loc)) {
            $loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location));
        }
        if (is_array($loc) === false) {
            // Grab data from which ever Geocode service we use.
            switch ($config['geoloc']['engine']) {
                case "google":
                default:
                    d_echo("Google geocode engine being used\n");
                    $api_key = $config['geoloc']['api_key'];
                    if (!empty($api_key)) {
                        d_echo("Use Google API key: {$api_key}\n");
                        $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address={$new_device_location}&key={$api_key}";
                    } else {
                        $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address={$new_device_location}";
                    }
                    break;
            }
            $curl_init = curl_init($api_url);
            set_curl_proxy($curl_init);
            curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true);
            $data = json_decode(curl_exec($curl_init), true);
            // Parse the data from the specific Geocode services.
            switch ($config['geoloc']['engine']) {
                case "google":
                default:
                    if ($data['status'] == 'OK') {
                        $loc = $data['results'][0]['geometry']['location'];
                    } else {
                        $bad_loc = true;
                    }
                    break;
            }
            if ($bad_loc === true) {
                d_echo("Bad lat / lng received\n");
            } else {
                $loc['timestamp'] = array('NOW()');
                $loc['location'] = $device_location;
                if (dbInsert($loc, 'locations')) {
                    d_echo("Device lat/lng created\n");
                } else {
                    d_echo("Device lat/lng could not be created\n");
                }
            }
        } else {
            d_echo("Using cached lat/lng from other device\n");
        }
    }
}
コード例 #4
0
ファイル: callback.php プロジェクト: REAP720801/librenms
        $data = dbFetchRows($query);
        $response[$name] = $data;
    }
    $output = array('uuid' => $uuid, 'data' => $response);
    $data = json_encode($output);
    $submit = array('data' => $data);
    $fields = '';
    foreach ($submit as $key => $value) {
        $fields .= $key . '=' . $value . '&';
    }
    rtrim($fields, '&');
    $post = curl_init();
    set_curl_proxy($post);
    curl_setopt($post, CURLOPT_URL, $config['callback_post']);
    curl_setopt($post, CURLOPT_POST, count($submit));
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($post);
} elseif ($enabled == 2) {
    $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
    $fields = "uuid={$uuid}";
    $clear = curl_init();
    set_curl_proxy($clear);
    curl_setopt($clear, CURLOPT_URL, $config['callback_clear']);
    curl_setopt($clear, CURLOPT_POST, count($clear));
    curl_setopt($clear, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($clear, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($clear);
    dbDelete('callback', '`name`="uuid"', array());
    dbUpdate(array('value' => '0'), 'callback', '`name` = "enabled"', array());
}