class="php"><?php ini_set('memory_limit', '1024M'); // Use 1G // /usr/bin/php /opt/lampp/htdocs/CAP_1000/get_request_multi.php date_default_timezone_set('America/Denver'); include "conn.php"; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $current_time=time(); $time_less_day=time() - 24*60*60; $date = date("D M d g:i:s T o"); $result = pg_query($con2,"SELECT * FROM eb_devices WHERE device_modelid = '9'"); while ($row = pg_fetch_array($result)){ $cap_ip = trim($row[3]); // $cap_ip = '172.30.209.74'; echo "Trying " . $cap_ip . "\n"; $check_for_ip_result=pg_query($con2, "SELECT * FROM lb_cap_status WHERE cap_ip = '$cap_ip'"); $check_for_ip_row = pg_fetch_array($check_for_ip_result); if($check_for_ip_row == ''){ $insert_offline=pg_query($con2, "INSERT INTO lb_cap_status (cap_ip, online, mode, cpr_state) VALUES ('$cap_ip', '0', '0', '0')"); } //make the connection with curl $cl = curl_init($cap_ip); curl_setopt($cl,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($cl,CURLOPT_HEADER,true); curl_setopt($cl,CURLOPT_NOBODY,true); curl_setopt($cl,CURLOPT_RETURNTRANSFER,true); //get response $response = curl_exec($cl); curl_close($cl); if (!$response) { // echo $cap_ip . " is offline.\n"; // echo "----------\n"; $update_offline=pg_query($con2, "UPDATE lb_cap_status SET cap_ip='$cap_ip', online='0', active_cap_ip='0' WHERE cap_ip = '$cap_ip'"); }else{ /////////Test login attempt//////// $login_xml_data ='<?xml version="1.0" encoding="UTF-8"?> <request id="G1000" origin="gui" destination="device" command="add" category="login" time="'.$date.'" protocol-version="4.0" platform-name="CAP-1000" type="push"> <user name="APIUser" password="APIP@$$w0rd" authentication="embedded" /> </request>'; $URL = "http://".$cap_ip.":80/xmlrq"; $headers = array(); array_push($headers, "Content-Type: text/xml"); array_push($headers, "Accept: text/xml"); $ch = curl_init($URL); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $login_xml_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $login_output = curl_exec($ch); curl_close($ch); $login_xml = simplexml_load_string($login_output); if(strpos($login_xml->reason, 'XML messaging protocol mismatch.') === false){ $proto = '4.0'; }else{ $proto = '3.0'; } // echo $cap_ip . "|"; // echo $proto . "<br>"; /////////Test login attempt//////// /////////Login with correct protocol//////// $login_xml_data ='<?xml version="1.0" encoding="UTF-8"?> <request id="G1000" origin="gui" destination="device" command="add" category="login" time="'.$date.'" protocol-version="'.$proto.'" platform-name="CAP-1000" type="push"> <user name="APIUser" password="APIP@$$w0rd" authentication="embedded" /> </request>'; $URL = "http://".$cap_ip.":80/xmlrq"; $headers = array(); array_push($headers, "Content-Type: text/xml"); array_push($headers, "Accept: text/xml"); $ch = curl_init($URL); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $login_xml_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $login_output = curl_exec($ch); curl_close($ch); $login_xml2 = simplexml_load_string($login_output); $session_id = $login_xml2->session['sid']; $xml_sid = $login_xml2->session['sid']; $manager_id=$login_xml2->session['manager-id']; //echo "<hr>"; //print_r($login_xml2); //echo "<hr>"; // echo $manager_id . "\n"; // echo "----------\n"; //////////////////////////////////*End of login*////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// $update_xml_config_data = '<?xml version="1.0" encoding="UTF-8"?> <request id="G1020" origin="gui" destination="device" command="get" category="users" time="'.$date.'" protocol-version="'.$proto.'" platform-name="CAP-1000" sid="'.$xml_sid.'"> <path> <manager id="'.$manager_id.'" /> <farmer id="'.$manager_id.'" /> </path> <users /> </request> '; $headers = array(); array_push($headers, "Content-Type: text/xml"); array_push($headers, "Accept: text/xml"); $ch = curl_init($URL); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $update_xml_config_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $config_output = curl_exec($ch); curl_close($ch); $get_xml_config = simplexml_load_string($config_output); if ($get_xml_config->reason != ''){ echo "<b>" . $cap_ip . " Failed " . $date . "\n"; $insert_offline=pg_query($con2, "INSERT INTO lb_failed_login (cap_ip, proto, account, checked) VALUES ('$cap_ip', '$proto', 'radius', '0')"); mail('lane.brunson@charter.com', 'CAP Admin account failed', "\n\r" . $cap_ip . "\nRadius login failed. Proto = " .$proto , null, '-fadmin@lanebrunson.com'); }else{ echo $cap_ip . " Passed " . $date . "\n"; } ////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////*Beginning of logout*/////////////////////////// $logout_xml_data ='<?xml version="1.0" encoding="UTF-8"?> <request id="G1057" origin="gui" destination="device" command="remove" category="login" protocol-version="'.$proto.'" platform-name="CAP-1000" sid="'.$login_xml->session['sid'].'" /> '; // print $logout_xml_data; $URL = "http://".$cap_ip.":80/xmlrq"; $headers = array(); array_push($headers, "Content-Type: text/xml"); array_push($headers, "Accept: text/xml"); $ch = curl_init($URL); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $logout_xml_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $logout_output = curl_exec($ch); curl_close($ch); /*End of logout*/ } } ?>