예제 #1
0
파일: basic.php 프로젝트: amrX2K/PIA-Tunnel
/**
 * method to display the current network info for all interfaces to the user and console
 * @param string $output='html' specifies return of the function, may be either html or array
 * @global type $CONF
 */
function VM_get_status($output = 'html')
{
    global $_settings;
    global $_pia;
    global $_services;
    $settings = $_settings->get_settings();
    $ret_arr = array('vpn_public_lbl1' => '', 'vpn_public_lbl2' => '', 'vpn_public_ip' => '', 'vpn_port' => '', 'forwarding_lbl' => '', 'forwarding_port' => '', 'SOCKS_EXT_ENABLED' => '');
    $sysload = get_system_load();
    $ret_arr['system_load'] = $sysload['load'];
    $ret_arr['system_mem'] = $sysload['mem'];
    $ret_arr['system_swap'] = $sysload['swap'];
    $up = $_pia->get_update_status();
    if (is_int($up) === true && $up == 0) {
        $up_txt = '<a href="./?page=tools&amp;cid=tools&amp;cmd=update_software_client">latest release</a>';
    } elseif ($up > 0) {
        $s = $up > 1 ? 's' : '';
        $up_txt = '<a href="/?page=tools&amp;cid=tools&amp;cmd=update_software_client">' . "{$up} update{$s} available</a>";
    } else {
        $up_txt = $up;
    }
    $ret_arr['software_update'] = $up_txt;
    if ($_pia->status_pia_daemon() === 'running') {
        $ret_arr['daemon_status'] = "running (autostart:{$settings['DAEMON_ENABLED']})";
    } else {
        $ret_arr['daemon_status'] = "not running (autostart:{$settings['DAEMON_ENABLED']})";
    }
    //check session.log if for current status
    $ret_arr['vpn_lbl'] = '';
    $session_status = VPN_sessionlog_status();
    switch ($session_status[0]) {
        case 'connected':
            $_SESSION['connecting2'] = $_SESSION['connecting2'] != '' ? $_SESSION['connecting2'] : 'ERROR 5642';
            $ret_arr['vpn_status'] = "Connected to {$_SESSION['connecting2']}";
            $_SESSION['connecting2'] = '';
            $ret_arr['forwarding_lbl'] = 'Forwarding';
            $ret_arr['vpn_public_lbl1'] = '';
            $ret_arr['vpn_public_lbl2'] = '';
            $vpn_port = VPN_get_port();
            $vpn_ip = VPN_get_IP();
            if ($vpn_ip !== false) {
                $ret_arr['vpn_lbl'] = 'Public VPN';
                $ret_arr['vpn_public_lbl1'] = 'IP';
                $ret_arr['vpn_public_ip'] = $vpn_ip;
                $ret_arr['vpn_port'] = $vpn_port != '' ? "{$vpn_port}" : '';
                $ret_arr['vpn_public_lbl2'] = $vpn_port != '' ? 'Port' : '';
                $fw_forward_state = $_pia->check_forward_state();
                if ($fw_forward_state === true && $vpn_port != '') {
                    if ($settings['FORWARD_PORT_ENABLED'] == 'yes') {
                        $ret_arr['forwarding_port'] = "{$vpn_ip}:{$vpn_port} &lt;=&gt; {$settings['FORWARD_IP']}";
                    } else {
                        $ret_arr['forwarding_lbl'] = '';
                        $ret_arr['forwarding_port'] = '';
                    }
                } else {
                    if ($settings['FORWARD_PORT_ENABLED'] == 'yes' && VPN_provider_connected() === 'pia') {
                        $ret_arr['forwarding_port'] = "currently disabled";
                    } elseif ($settings['FORWARD_PORT_ENABLED'] == 'yes') {
                        $ret_arr['forwarding_port'] = "not supported by VPN provider";
                    } else {
                        $ret_arr['forwarding_lbl'] = '';
                        $ret_arr['forwarding_port'] = '';
                    }
                }
            }
            unset($vpn_pub);
            break;
        case 'connecting':
            $_SESSION['connecting2'] = $_SESSION['connecting2'] != '' ? $_SESSION['connecting2'] : 'ERROR 5643';
            $ret_arr['vpn_status'] = "Connecting to {$_SESSION['connecting2']}";
            break;
        case 'disconnected':
            $ret_arr['vpn_status'] = "VPN Disconnected";
            $_SESSION['connecting2'] = '';
            break;
        case 'error':
            $ret_arr['vpn_status'] = "Error: {$session_status['1']}";
            $_SESSION['connecting2'] = 'error';
            break;
        default:
            var_dump($session_status);
    }
    //had some trouble reading status.txt right after VPN was established to I am doing it in PHP
    $ret = array();
    exec('/sbin/ip addr show ' . $settings['IF_EXT'] . ' | grep -w "inet" | gawk -F" " \'{print $2}\' | cut -d/ -f1', $ret);
    $ret_arr['public_ip'] = $ret[0];
    unset($ret);
    $fw_forward_state = $_pia->check_forward_state($settings['IF_EXT']);
    if ($fw_forward_state === true || $settings['FORWARD_PUBLIC_LAN'] === 'yes') {
        $ret_arr['public_gw'] = $fw_forward_state === true ? 'VPN Gateway enabled' : 'VPN Gateway disabled';
    } else {
        $ret_arr['public_gw'] = '';
    }
    if ($settings['SOCKS_EXT_ENABLED'] == 'yes') {
        if ($_services->socks_status() === 'running') {
            $ret_arr['SOCKS_EXT_ENABLED'] = "SOCKS5 Proxy on port {$settings['SOCKS_EXT_PORT']}";
        } else {
            $ret_arr['SOCKS_EXT_ENABLED'] = "SOCKS5 Proxy NOT running";
        }
    }
    $ret_arr['vpn_gw'] = '';
    $ret = array();
    exec('/sbin/ip addr show ' . $settings['IF_INT'] . ' | grep -w "inet" | gawk -F" " \'{print $2}\' | cut -d/ -f1', $ret);
    if (array_key_exists('0', $ret)) {
        $ret_arr['private_ip'] = $ret[0];
        $fw_forward_state = $_pia->check_forward_state($settings['IF_INT']);
        if ($fw_forward_state === true || $settings['FORWARD_VM_LAN'] === 'yes') {
            $ret_arr['vpn_gw'] = $fw_forward_state === true ? 'VPN Gateway enabled' : 'VPN Gateway disabled';
        }
        if ($settings['SOCKS_INT_ENABLED'] == 'yes') {
            if ($_services->socks_status() === 'running') {
                $ret_arr['SOCKS_INT_ENABLED'] = "SOCKS5 Proxy on port {$settings['SOCKS_INT_PORT']}";
            } else {
                $ret_arr['SOCKS_INT_ENABLED'] = "SOCKS5 Proxy NOT running";
            }
        } else {
            $ret_arr['SOCKS_INT_ENABLED'] = '';
        }
        $ret_arr['private_ip'] = $ret[0];
    } else {
        $ret_arr['SOCKS_INT_ENABLED'] = '';
        $ret_arr['private_ip'] = 'interface missing';
    }
    unset($ret);
    if ($output !== 'array') {
        $table = "<table border=\"0\" id=\"vm_status\"><tbody>\n";
        $table .= "<tr><td style=\"width:7em\">System</td><td>system load <span id=\"system_load\">{$sysload['load']}</span></td></tr>\n";
        $table .= "<tr><td></td><td>Mem <span id=\"system_mem\">{$sysload['mem']}</span> SWAP <span id=\"system_swap\">{$sysload['swap']}</span></td></tr>\n";
        $table .= '<tr><td>Software</td><td id="software_update">' . $up_txt . '</td></tr>';
        $table .= "<tr><td>PIA Daemon</td><td id=\"daemon_status\">{$ret_arr['daemon_status']}</td></tr>\n";
        $table .= "<tr><td>VPN Status</td><td id=\"vpn_status\">{$ret_arr['vpn_status']}</td></tr>\n";
        $table .= "<tr><td>&nbsp;</td><td></td></tr>\n";
        $table .= "<tr><td id=\"vpn_lbl\" style=\"vertical-align: top;\">{$ret_arr['vpn_lbl']}</td><td><span id=\"vpn_public_lbl1\">{$ret_arr['vpn_public_lbl1']}</span> <span id=\"vpn_public_ip\">{$ret_arr['vpn_public_ip']}</span> <span id=\"vpn_public_lbl2\">{$ret_arr['vpn_public_lbl2']}</span> <span id=\"vpn_port\">{$ret_arr['vpn_port']}</span></td></tr>\n";
        $table .= "<tr><td id=\"forwarding_lbl\" style=\"vertical-align: top;\">{$ret_arr['forwarding_lbl']}</td><td id=\"forwarding_port\">{$ret_arr['forwarding_port']}</td></tr>\n";
        $table .= "<tr><td>&nbsp;</td><td></td></tr>\n";
        $table .= "<tr><td style=\"vertical-align: top;\">Public LAN</td><td>IP <span id=\"public_ip\">{$ret_arr['public_ip']}</span></td></tr>\n";
        $table .= "<tr><td></td><td id=\"public_gw\">{$ret_arr['public_gw']}</td></tr>\n";
        $table .= "<tr><td></td><td id=\"SOCKS_EXT_ENABLED\">{$ret_arr['SOCKS_EXT_ENABLED']}</td></tr>\n";
        $table .= "<tr><td>&nbsp;</td><td></td></tr>\n";
        $table .= "<tr><td style=\"vertical-align: top;\">VM LAN</td><td>IP <span id=\"private_ip\">{$ret_arr['private_ip']}</span></td></tr>\n";
        $table .= "<tr><td></td><td id=\"vpn_gw\">{$ret_arr['vpn_gw']}</td></tr>\n";
        $table .= "<tr><td></td><td id=\"SOCKS_INT_ENABLED\">{$ret_arr['SOCKS_INT_ENABLED']}</td></tr>\n";
        $table .= "</tbody></table>\n";
    }
    if ($output === 'array') {
        return $ret_arr;
    } else {
        return $table;
    }
}
<?php 
echo "<h3>General Information</h3>";
?>

<table class='summarySection'>
  <tr>
    <td class='summaryKey'> Uptime </td>
    <td class='summaryValue'><span class='sleft'><?php 
echo uptime();
?>
</span> </td>
  </tr>
  <tr>
    <td class='summaryKey'> System Load </td>
    <td class='summaryValue'><span class='sleft'><?php 
echo get_system_load();
?>
</span> </td>
  </tr>
  <tr>
    <td class='summaryKey'> Hostname </td>
    <td class='summaryValue'><span class='sleft'><?php 
echo get_hostname();
?>
</span> </td>
  </tr>
  <tr>
    <td class='summaryKey'> Current Date </td>
    <td class='summaryValue'><span class='sleft'><?php 
echo get_datetime();
?>