// Query to retrieve row for given ID (tidxxxxxx is stored in nodes and is generated when task is created) $getNodesSql = "SELECT \n\t\t\t\t\tid, \n\t\t\t\t\tdeviceName, \n\t\t\t\t\tdeviceIpAddr, \n\t\t\t\t\tdevicePrompt, \n\t\t\t\t\tdeviceUsername, \n\t\t\t\t\tdevicePassword, \n\t\t\t\t\tdeviceEnableMode, \n\t\t\t\t\tdeviceEnablePassword, \n\t\t\t\t\tnodeCatId, \n\t\t\t\t\tdeviceAccessMethodId, \n\t\t\t\t\tconnPort\n\t\t\t\t\tFROM nodes WHERE id = " . $rid . " AND status = 1"; if ($result = $db->q($getNodesSql)) { // push rows to $devices array $devices = array(); while ($row = mysql_fetch_assoc($result)) { array_push($devices, $row); } // create cliOutputArray $cliOutputArray = array(); foreach ($devices as $device) { // iterate over each device - in this scripts case, there will only be a single device // set prompt for SSH conns $prompt = $device['devicePrompt']; // verification of host reachability based on fsockopen to host port i.e. 22 or 23. If fails, continue to next foreach iteration $status = getHostStatus($device['deviceIpAddr'], $device['connPort']); // getHostStatus() from functions.php if ($status === "<font color=red>Unavailable</font>") { $text = "Failure: Unable to connect to " . $device['deviceName'] . " - " . $device['deviceIpAddr'] . " when running Router ID " . $rid; $jsonArray['connFailMsg'] = $text; $log->Conn($text . " - getHostStatus() Error:(File: " . $_SERVER['PHP_SELF'] . ")"); // logg to file echo json_encode($jsonArray); continue; } if (!empty($providedUsername) && !empty($providedPassword) && $providedUsername != "0" && $providedPassword != "0") { $conn = new Connection($device['deviceIpAddr'], $providedUsername, $providedPassword, $device['deviceEnableMode'], $providedPassword, $device['connPort'], $timeout); } else { // create the connection by calling the connection class $conn = new Connection($device['deviceIpAddr'], $device['deviceUsername'], $device['devicePassword'], $device['deviceEnableMode'], $device['deviceEnablePassword'], $device['connPort'], $timeout); }
<?php $deviceIpAddr = $_GET['deviceIpAddr']; $connPort = $_GET['connPort']; require_once "../../../config/config.inc.php"; require_once "../../../config/functions.inc.php"; echo getHostStatus($deviceIpAddr, $connPort); //func in functions.inc.php;