public function view_dynamic_matches()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('ngnt_error');
     $regex = $this->getParam('regex');
     if ($regex === false) {
         $viewData->header = $this->getErrorHeader('ngnt_error');
         $viewData->error = 'Unable to detect regex specified in post params';
         $this->sendError('generic_error', $viewData);
     }
     $nregex = $this->getParam('nregex');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $hosts = RevDeploy::getDeploymentHosts($deployment);
     $globalnegate = RevDeploy::getDeploymentGlobalNegate($deployment);
     $resulthosts = array();
     foreach ($hosts as $host => $hArray) {
         if ($globalnegate !== false && preg_match("/{$globalnegate}/", $host)) {
             continue;
         }
         if (preg_match("/{$regex}/", $host)) {
             if ($nregex !== false) {
                 if (!preg_match("/{$nregex}/", $host)) {
                     array_push($resulthosts, $host);
                 }
             } else {
                 array_push($resulthosts, $host);
             }
         }
     }
     sort($resulthosts);
     $viewData = $resulthosts;
     $this->sendResponse('ngnt_view_dynamic_matches', $viewData);
 }
Exemple #2
0
// License: BSD 2-Clause
//
/*
 * Saigon API - Matrix Node Mapper Routes
 */
$app->get('/sapi/matrix/:deployment/gethosts', function ($deployment) use($app) {
    check_deployment_exists($app, $deployment);
    $request = $app->request();
    $regex = $request->get('regex');
    $nregex = $request->get('nregex');
    $hosts = RevDeploy::getDeploymentHosts($deployment);
    if (empty($hosts)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect or retrieve hosts, empty results set detected");
        $app->halt(404, $apiResponse->returnJson());
    }
    $globalnegate = RevDeploy::getDeploymentGlobalNegate($deployment);
    $resulthosts = array();
    if (isset($regex) && !empty($regex)) {
        foreach ($hosts as $host => $hArray) {
            if ($globalnegate !== false && preg_match("/{$globalnegate}/", $host)) {
                continue;
            }
            if (preg_match("/{$regex}/", $host)) {
                if (isset($nregex) && !empty($nregex)) {
                    if (!preg_match("/{$nregex}/", $host)) {
                        array_push($resulthosts, $host);
                    }
                } else {
                    array_push($resulthosts, $host);
                }
            }