コード例 #1
0
            $apiResponse->setExtraResponseData('deleted', $results);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect dynamic host information specified in the data store");
            $app->halt(404, $apiResponse->returnJson());
        }
    } elseif ($type == 'static') {
        if (!isset($hostInfo['host']) || empty($hostInfo['host'])) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect host parameter (expecting hostname or fqdn)");
            $app->halt(404, $apiResponse->returnJson());
        } elseif (!isset($hostInfo['ip']) || empty($hostInfo['ip'])) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect ip parameter (expecting to match /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/)");
            $app->halt(404, $apiResponse->returnJson());
        } elseif (!preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/", $hostInfo['ip'])) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to use ip parameter (expecting to match /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/)");
            $app->halt(404, $apiResponse->returnJson());
        }
        $results = RevDeploy::delDeploymentStaticHost($deployment, NagMisc::encodeIP($hostInfo['ip']));
        if (!empty($results)) {
            $apiResponse = new APIViewData(0, $deployment, false);
            $apiResponse->setExtraResponseData('deleted', $results);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect static host information specified in the data store");
            $app->halt(404, $apiResponse->returnJson());
        }
    } else {
        $apiResponse = new APIViewData(1, $deployment, "Unsure of how you got here, as a higher route should have blocked you, check your host type for processing");
        $app->halt(404, $apiResponse->returnJson());
    }
})->name('saigon-api-deployment-delete-host')->conditions(array('type' => '(dynamic|static)'));
コード例 #2
0
 public static function delDeploymentStaticHost($deployment, $ip)
 {
     if (self::$init === false) {
         self::init();
     }
     $hostInfo = array();
     if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $ip)) {
         $ip = NagMisc::encodeIP($ip);
     }
     $staticHosts = NagRedis::get(md5('deployment:' . $deployment) . ':statichosts');
     $staticHosts = json_decode($staticHosts, true);
     if (isset($staticHosts[$ip]) && !empty($staticHosts[$ip])) {
         $hostInfo = $staticHosts[$ip];
         unset($staticHosts[$ip]);
         NagRedis::set(md5('deployment:' . $deployment) . ':statichosts', json_encode($staticHosts));
         $hostData = new DeploymentHostData($deployment, 'del', 'static', $hostInfo);
         self::$log->addToLog($hostData);
     }
     return $hostInfo;
 }
コード例 #3
0
 /**
  * add_static_host_csv - add static hosts via csv inject 
  * 
  * @access public
  * @return void
  */
 public function add_static_host_csv()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('deployment_error');
     $contents = $this->fetchUploadedFile('staticcsvfile');
     if ($contents === false) {
         $this->sendResponse('deployment_search_window_static', $viewData);
     }
     $lines = explode("\n", $contents);
     if (!isset($_SESSION[$deployment]['static-deployments']) || !is_array($_SESSION[$deployment]['static-deployments'])) {
         $_SESSION[$deployment]['static-deployments'] = array();
     }
     foreach ($lines as $line) {
         if (empty($line)) {
             continue;
         }
         $tmpArray = preg_split('/,\\s?/', $line);
         $encIP = NagMisc::encodeIP($tmpArray[1]);
         $_SESSION[$deployment]['static-deployments'][$encIP]['host'] = $tmpArray[0];
         $_SESSION[$deployment]['static-deployments'][$encIP]['ip'] = $tmpArray[1];
     }
     $viewData->deployment = $deployment;
     $this->sendResponse('deployment_search_window_static', $viewData);
 }