/**
 * Connects to Bitcoin daemon and retrieves information, then writes to cache
 *
 * @param string $from_cache Whether to get the data from cache or not
 *
 * @return array
 */
function getData($from_cache = false)
{
    global $config;
    global $cache_message;
    // If we're getting data from cache, do it
    if ($from_cache === true && is_file($config['cache_file'])) {
        $cache = json_decode(file_get_contents($config['cache_file']), true);
        // Only proceed if the array is a cache - invalid otherwise
        if (is_array($cache)) {
            if ($cache['config_hash'] == md5(json_encode($config))) {
                if (time() < $cache['cache_expiry']) {
                    return $cache;
                }
            } else {
                $cache_message = 'Configuration has changed, cache has been refreshed.';
            }
        }
    }
    // Include EasyBitcoin library and set up connection
    include_once './php/easybitcoin.php';
    $bitcoin = new Bitcoin($config['rpc_user'], $config['rpc_pass'], $config['rpc_host'], $config['rpc_port']);
    // Setup SSL if configured
    if ($config['rpc_ssl'] === true) {
        $bitcoin->setSSL($config['rpc_ssl_ca']);
    }
    // Get info
    $data = $bitcoin->getinfo();
    // Handle errors if they happened
    if (!$data) {
        $return_data['error'] = $bitcoin->error;
        $return_data['status'] = $bitcoin->status;
        writeToCache($return_data);
        return $return_data;
    }
    // Get free disk space
    if ($config['display_free_disk_space'] === true) {
        $data['free_disk_space'] = getFreeDiskSpace();
    }
    if (isset($config['display_ip']) && $config['display_ip'] === true) {
        // Use bitcoind IP
        if ($config['use_bitcoind_ip'] === true) {
            $net_info = $bitcoin->getnetworkinfo();
            $data['node_ip'] = $net_info['localaddresses'][0]['address'];
        } else {
            $data['node_ip'] = $_SERVER['SERVER_ADDR'];
        }
    }
    // Add peer info
    if ($config['display_peer_info'] === true) {
        $data['peers'] = parsePeers($bitcoin->getpeerinfo());
    }
    // Node geolocation
    if ($config['display_ip_location'] === true && $config['display_ip'] === true) {
        $data['ip_location'] = getGeolocation($data['node_ip'], 'all');
    }
    // Bitcoin Daemon uptime
    if ($config['display_bitcoind_uptime'] === true || strcmp(PHP_OS, "Linux") == 0) {
        $data['bitcoind_uptime'] = getProcessUptime($config['bitcoind_process_name']);
    }
    // Get max height from bitnodes.21.co
    if ($config['display_max_height'] === true) {
        $bitnodes_ch = curl_init();
        curl_setopt($bitnodes_ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($bitnodes_ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($bitnodes_ch, CURLOPT_USERAGENT, 'Bitcoin Node Status Page');
        curl_setopt($bitnodes_ch, CURLOPT_URL, "https://bitnodes.21.co/api/v1/snapshots/");
        $exec_result = json_decode(curl_exec($bitnodes_ch), true);
        // Don't close handle if we reuse it
        if ($config['display_bitnodes_info'] !== true) {
            curl_close($bitnodes_ch);
        }
        $data['max_height'] = $exec_result['results'][0]['latest_height'];
        $data['node_height_percent'] = round($data['blocks'] / $data['max_height'] * 100, 1);
    }
    // Get node info from bitnodes.21.co
    if ($config['display_bitnodes_info'] === true) {
        if ($bitnodes_ch === false) {
            $bitnodes_ch = curl_init();
            curl_setopt($bitnodes_ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($bitnodes_ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($bitnodes_ch, CURLOPT_USERAGENT, 'Bitcoin Node Status Page');
        }
        // Get node info
        curl_setopt($bitnodes_ch, CURLOPT_URL, "https://getaddr.bitnodes.21.co/api/v1/nodes/" . $data['node_ip'] . "-8333/");
        $data['bitnodes_info'] = json_decode(curl_exec($bitnodes_ch), true);
        // Get latency info
        curl_setopt($bitnodes_ch, CURLOPT_URL, "https://getaddr.bitnodes.21.co/api/v1/nodes/" . $data['node_ip'] . "-8333/latency/");
        $latency = json_decode(curl_exec($bitnodes_ch), true);
        $data['bitnodes_info']['latest_latency'] = $latency['daily_latency'][0];
    }
    // Get chart data
    if ($config['display_chart'] === true & is_file($config['stats_file'])) {
        $data['chart'] = json_decode(file_get_contents($config['stats_file']), true);
    }
    writeToCache($data);
    return $data;
}
Example #2
0
     if ($fileName != '.' && $fileName != '..' && !is_dir($config['paths']['backup'] . $fileName)) {
         $files[] = $fileName;
         $sumFiles++;
         $sumSize += filesize($config['paths']['backup'] . $fileName);
         $ft = filectime($config['paths']['backup'] . $fileName);
         if (!isset($lastBu[2]) || isset($lastBu[2]) && $ft > $lastBu[2]) {
             $lastBu[0] = $fileName;
             $lastBu[1] = date("d.m.Y H:i", $ft);
             $lastBu[2] = $ft;
         }
     }
 }
 $directoryWarnings = checkDirectories();
 $tplHome = new MSDTemplate();
 $tplHome->set_filenames(array('tplHome' => 'tpl/home/home.tpl'));
 $tplHome->assign_vars(array('ICON_EDIT' => $icon['edit'], 'ICON_DELETE' => $icon['delete'], 'ICON_SEARCH' => $icon['search'], 'THEME' => $config['theme'], 'MSD_VERSION' => MSD_VERSION . ' (' . MSD_VERSION_SUFFIX . ')', 'OS' => MSD_OS, 'OS_EXT' => MSD_OS_EXT, 'MYSQL_VERSION' => MSD_MYSQL_VERSION, 'MYSQL_CLIENT_VERSION' => $dbo->getClientInfo(), 'PHP_VERSION' => PHP_VERSION, 'MEMORY' => byteOutput($config['php_ram'] * 1024 * 1024), 'MAX_EXECUTION_TIME' => intval(@get_cfg_var('max_execution_time')), 'MAX_EXEC_USED_BY_MSD' => $config['max_execution_time'], 'PHP_EXTENSIONS' => $config['phpextensions'], 'SERVER_NAME' => $_SERVER['SERVER_NAME'], 'MSD_PATH' => $config['paths']['root'], 'DB' => $config['db_actual'], 'NR_OF_BACKUP_FILES' => $sumFiles, 'SIZE_BACKUPS' => byteOutput($sumSize), 'FREE_DISKSPACE' => getFreeDiskSpace()));
 if ($directoryWarnings > '') {
     $tplHome->assign_block_vars('DIRECTORY_WARNINGS', array('MSG' => $directoryWarnings));
 }
 if ($config['disabled'] > '') {
     $tplHome->assign_block_vars('DISABLED_FUNCTIONS', array('PHP_DISABLED_FUNCTIONS' => str_replace(',', ', ', $config['disabled'])));
 }
 // Zlib is buggy from version 4.3.0 upto 4.3.2,
 // so lets check for these versions
 if (version_compare(PHP_VERSION, '4.3.0', '>=') && version_compare(PHP_VERSION, '4.3.2', '<=')) {
     $tplHome->assign_block_vars('ZLIBBUG', array());
 }
 if (!extension_loaded('ftp')) {
     $tplHome->assign_block_vars('NO_FTP', array());
 }
 if (!$config['zlib']) {
Example #3
0
                $time = ", " . $time;
            }
            if ($days > 0) {
                $time = $days[0] . " D" . $time;
            }
        } else {
            $time = false;
        }
    } else {
        $time = false;
    }
    return $time;
}
function getUserCount()
{
    return exec("cat /etc/passwd | wc -l");
}
$finalResponse = json_encode(array("CPU_Usage" => getCPUUsage(), "RAM_Usage" => getRAMUsage(), "Uptime" => getUptime(), "Free_Disk_Space" => getFreeDiskSpace(), "ConnectionCount" => getConnectionCount(), "UserCount" => getUserCount()));
switch ($clientRequest) {
    case "status":
        echo $finalResponse;
        break;
    default:
        echo "No Request Given!";
        break;
}
?>



Example #4
0
ksort($backups['databases']);
// list summary of other backup files grouped by databases
if (count($backups['databases']) > 0) {
    $i = 0;
    foreach ($backups['databases'] as $db => $info) {
        $rowclass = $i % 2 ? 'dbrow' : 'dbrow1';
        if ($db == $dbactive) {
            $rowclass = 'dbrowsel';
        }
        $dbNameOutput = $db;
        if ($db == '~unknown') {
            $dbNameOutput = '<i>' . $lang['L_NO_MSD_BACKUPFILE'] . '</i>';
        }
        if ($db == '~converted') {
            $dbNameOutput = '<i>' . $lang['L_CONVERTED_FILES'] . '</i>';
        }
        $nrOfBackups = isset($info['backup_count']) ? $info['backup_count'] : 0;
        $latestBackup = '-';
        if (isset($info['latest_backup_timestamp'])) {
            $latestBackup = $info['latest_backup_timestamp'];
        }
        $fileSizeTotal = 0;
        if (isset($info['backup_size_total'])) {
            $fileSizeTotal = byteOutput($info['backup_size_total']);
        }
        $tplFiles->assign_block_vars('DB', array('ROWCLASS' => $rowclass, 'DB_NAME_LINK' => $db, 'DB_NAME' => $dbNameOutput, 'NR_OF_BACKUPS' => $nrOfBackups, 'LATEST_BACKUP' => $latestBackup, 'SUM_SIZE' => $fileSizeTotal));
        $i++;
    }
}
$tplFiles->assign_vars(array('SUM_SIZE' => byteOutput($backups['filesize_total']), 'FREESPACE_ON_SERVER' => getFreeDiskSpace()));