<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(sqlerror());
mysql_select_db($dbname, $conn);
$result = mysql_query("SELECT * FROM cmum_csp_config");
$csps = array();
while ($lineCSPStatus = mysql_fetch_assoc($result)) {
    //$csps[] = $lineCSPStatus["protocol_serv"] . "://" . $lineCSPStatus["user_serv"] . ":" . $lineCSPStatus["senha_serv"] . "@" . $lineCSPStatus["ip_serv"] . ":" . $lineCSPStatus["porta_serv"] . "/xmlHandler?command=proxy-status";
$url = $lineCSPStatus["protocol_serv"] . "://" . $lineCSPStatus["ip_serv"] . ":" . $lineCSPStatus["porta_serv"] . "/xmlHandler?command=proxy-status";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD,$lineCSPStatus["user_serv"] . ":" . $lineCSPStatus["senha_serv"]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // TIME OUT is 5 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//var_dump($httpCode);
curl_close($ch);
$csps[$lineCSPStatus["desc_serv"]] = $response;
    
}
//GAMBIARRA
/*$csps = array();
$csps[] = 'http://189.1.164.33/ab5162ad5e35f0f9b11c011bf4c92792/csp/ceu_est.php';
$csps[] = 'http://189.1.164.33/ab5162ad5e35f0f9b11c011bf4c92792/csp/claro_est.php';*/
$i = 1;
foreach ($csps as $nome_csp => $csp) {   

    $xml = simplexml_load_string($csp);
    //var_dump($cspCom);
    if ($xml != "") {
        $proxystatus = "proxy-status";
        $jvm = "jvm";
        $activesessions = "active-sessions";
        $cspstate = $xml->$proxystatus->attributes()->state;
        $cspname = $xml->$proxystatus->attributes()->name;
        $cspversion = $xml->$proxystatus->attributes()->version;
        $cspbuild = str_replace("r", "", $xml->$proxystatus->attributes()->build);
        $cspstarted = $xml->$proxystatus->attributes()->started;
        $cspduration = $xml->$proxystatus->attributes()->duration;
        $cspconnectors = $xml->$proxystatus->attributes()->connectors;
        $cspactivesessions = $xml->$proxystatus->attributes()->$activesessions;
        $cspsessions = $xml->$proxystatus->attributes()->sessions;
        $jvmname = $xml->$proxystatus->$jvm->attributes()->name;
        $jvmversion = $xml->$proxystatus->$jvm->attributes()->version;
        $jvmos = $xml->$proxystatus->$jvm->attributes()->os;
        ?>
        <form name="cspinfo" action="#" method="post">
            <fieldset>
                <legend>Informa&ccedil;&otilde;es do CSP - <?php echo "({$nome_csp})"; ?></legend>
                <table valign="top" style="font-size: 8pt; background-color: #F8F8F8">
                    <tr><td width="70">Nome:</td><td width="350"><?php print($cspname); ?></td></tr>
                    <tr><td width="70">Status</td><td width="350"><?php print($cspstate); ?></td></tr>
                    <tr><td width="70">Versao CSP:</td><td width="350"><?php
        print($cspversion);
        if ($cspbuild <> "") {
            print(" (build " . $cspbuild . ")");
        }
        ?></td></tr>
                    <tr><td width="70">Inicio:</td><td width="350"><?php print($cspstarted); ?></td></tr>
                    <tr><td width="70">Logado:</td><td width="450"><?php print($cspduration); ?></td></tr>
                    <tr><td width="70">Connectores:</td><td width="350"><?php print($cspconnectors); ?></td></tr>
                    <tr><td width="70">Sessoes:</td><td width="350"><?php print($cspsessions); ?> (active: <?php print($cspactivesessions); ?>)</td></tr>
                    <tr><td width="70">&nbsp;</td><td width="350">&nbsp;</td></tr>
                    <tr><td width="70">JavaVM:</td><td width="350"><?php print($jvmname . " v" . $jvmversion); ?></td></tr>
                    <tr><td width="70">OS:</td><td width="350"><?php print($jvmos); ?></td></tr>
                </table>
            </fieldset>
        </form>
    <?php } else {
        ?>
        <fieldset>
            <legend>Informa&ccedil;&otilde;es do CSP - <?php echo "({$nome_csp}) - OFF"; ?></legend>
            <table valign="top">
                    <tr><td width="70">Nome:</td><td width="350"></td></tr>
                    <tr><td width="70">Status</td><td width="350">OFF Line ou Não cadastrado..</td></tr>
                    <tr><td width="70">Versao CSP:</td><td width="350"></td></tr>
                    <tr><td width="70">Inicio:</td><td width="350"></td></tr>
                    <tr><td width="70">Logado:</td><td width="450"></td></tr>
                    <tr><td width="70">Connectores:</td><td width="350"></td></tr>
                    <tr><td width="70">Sessoes:</td><td width="350"></td></tr>
                    <tr><td width="70">&nbsp;</td><td width="350">&nbsp;</td></tr>
                    <tr><td width="70">JavaVM:</td><td width="350"></td></tr>
                    <tr><td width="70">OS:</td><td width="350"></td></tr>
                </table>
            </fieldset>
            
        </fieldset>
        <?php
    }
    $i++;
}
?>