Esempio n. 1
0
// Get active nodes for a given task ID
// Query to retireve row for given ID (tidxxxxxx is stored in nodes and is generated when task is created)
$getNodesSql = "SELECT id, deviceName, deviceIpAddr, deviceUsername, devicePassword, deviceEnableMode, deviceEnablePassword, nodeCatId, deviceAccessMethodId, connPort FROM nodes WHERE taskId" . $tid . " = 1 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);
    }
    // loop over retrieved devices
    foreach ($devices as $device) {
        $deviceId = $device['id'];
        $getPathSqlLatest = $db->q("SELECT * FROM configs \n\t\t\t\t\t\t\t\t\t\tWHERE deviceId = {$deviceId}\n\t\t\t\t\t\t\t\t\t\tAND configFilename LIKE '%{$command}%'\n\t\t\t\t\t\t\t\t\t\tORDER BY configDate \n\t\t\t\t\t\t\t\t\t\tDESC LIMIT 1");
        $pathResultLatest = mysql_fetch_assoc($getPathSqlLatest);
        // append device name to report
        $report->eachComplianceDataRowDeviceName($device['deviceName']);
        // log deviceName to report
        // continue for the foreach if one of the files is not available as this compliance will be invalid
        if (empty($pathResultLatest)) {
            echo 'continue invoked for ' . $device['deviceName'];
            continue;
        }
        $pathResult_a = $pathResultLatest['configLocation'];
        $filenameResult_a = $pathResultLatest['configFilename'];
        $configFile = $pathResult_a . '/' . $filenameResult_a;
        //		$configFile = $pathResult_a . '/' . $command . '.txt';
        $tableRow = "";
        // set tableRow for later use and avoid  Undefined variable errors
        foreach ($policies as $k => $v) {
            $q = "SELECT e.elemId, cpe.elementName, cpe.singleParam1, cpe.singleLine1\n\t\t\t\t\t\t\tFROM compliancePolElemTbl as e\n\t\t\t\t\t\t\tLEFT JOIN compliancePolElem AS cpe ON e.elemId = cpe.id\n\t\t\t\t\t\t\tWHERE polId = {$v}\n\t\t\t\t\t\t\tORDER BY elementName ASC";
            $elemsRes = $db->q($q);
Esempio n. 2
0
 $snippetArr = explode("\n", $snippet);
 // explode text new lines to array
 $snippetArr = array_map('trim', $snippetArr);
 // trim whitespace from each array value
 $tableRow = "";
 foreach ($devices as $device) {
     // debugging check and action
     if ($debugOnOff === '1' || isset($cliDebugOutput)) {
         $debug->debug($device);
     }
     // ok, 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 taskID " . $tid;
         $report->eachComplianceDataRowDeviceName($device['deviceName'], $connStatusFail, $text);
         // log to report
         echo $text . " - getHostStatus() Error:(File: " . $_SERVER['PHP_SELF'] . ")\n";
         // log to console
         $log->Conn($text . " - getHostStatus() Error:(File: " . $_SERVER['PHP_SELF'] . ")");
         // logg to file
         continue;
     }
     // get the category for the device
     $catNameQ = $db->q("SELECT categoryName FROM categories WHERE id = " . $device['nodeCatId']);
     $catNameRow = mysql_fetch_row($catNameQ);
     $catName = $catNameRow[0];
     // select only first value returned
     // declare file Class based on catName and DeviceName
     $file = new file($catName, $device['deviceName'], $config_data_basedir);
     // Connect for each row returned - might want to do error checking here based on if an IP is returned or not