/**
  * write - write resource config information to datastore 
  * 
  * @access public
  * @return void
  */
 public function write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('resource_cfg_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cfgDelete = $this->getParam('delete');
     if ($cfgDelete == 1) {
         RevDeploy::deleteDeploymentResourceCfg($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $this->sendResponse('resource_cfg_delete', $viewData);
     }
     $resources = array();
     for ($i = 1; $i <= 32; $i++) {
         $key = "USER" . $i;
         $value = $this->getParam($key);
         if ($value !== false) {
             $resources[$key] = base64_encode($value);
         }
     }
     RevDeploy::writeDeploymentResourceCfg($deployment, $resources, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('resource_cfg_write', $viewData);
 }
Exemplo n.º 2
0
function check_revision_status($deployment)
{
    $currRev = RevDeploy::getDeploymentRev($deployment);
    $nextRev = RevDeploy::getDeploymentNextRev($deployment);
    if ($currRev == $nextRev) {
        $incrRev = RevDeploy::incrDeploymentNextRev($deployment);
        CopyDeploy::copyDeploymentRevision($deployment, $currRev, $incrRev);
    }
    return true;
}
Exemplo n.º 3
0
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('svc_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $svcName = $this->getParam('svcName');
     $svcInfo = $this->fetchSvcInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentSvc($deployment, $svcName, $modrevision) === true) {
         $viewData->error = 'Service template information exists for ' . $svcName . ' into ' . $deployment . ' Deployment';
         $viewData->action = 'copy_write';
         $viewData->deployment = $deployment;
         $viewData->svctemplates = RevDeploy::getCommonMergedDeploymentSvcTemplates($deployment, $modrevision);
         $viewData->svcgroups = RevDeploy::getCommonMergedDeploymentSvcGroups($deployment, $modrevision);
         $viewData->svcchkcmds = RevDeploy::getCommonMergedDeploymentCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
         $viewData->contactgroups = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $modrevision);
         $viewData->svcInfo = $svcInfo;
         $this->sendResponse('svc_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentSvc($deployment, $svcName, $svcInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('svc_error');
         $viewData->error = 'Unable to write service tempalte information for ' . $svcName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->svc = $svcName;
     $this->sendResponse('svc_write', $viewData);
 }
Exemplo n.º 4
0
 /**
  * write - issue cgi config write to datastore 
  * 
  * @access public
  * @return void
  */
 public function write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('cgi_cfg_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cfgDelete = $this->getParam('delete');
     if ($cfgDelete == 1) {
         RevDeploy::deleteDeploymentCgiCfg($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $this->sendResponse('cgi_cfg_delete', $viewData);
     }
     $cfgInfo = $this->_fetchConfigInfo($deployment, $modrevision);
     ksort($cfgInfo);
     RevDeploy::writeDeploymentCgiCfg($deployment, $cfgInfo, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('cgi_cfg_write', $viewData);
 }
 public function write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('nagios_cfg_error');
     $this->checkGroupAuth(SUPERMEN);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cfgDelete = $this->getParam('delete');
     if ($cfgDelete == 1) {
         RevDeploy::deleteDeploymentNagiosCfg($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $this->sendResponse('nagios_cfg_delete', $viewData);
     }
     $cfgInfo = $this->fetchConfigInfo($deployment);
     if (isset($_SESSION[$deployment]['brokermods']) && is_array($_SESSION[$deployment]['brokermods'])) {
         $i = 0;
         foreach ($_SESSION[$deployment]['brokermods'] as $md5 => $b64) {
             $cfgInfo['broker_module_' . $i] = $b64;
             $i++;
         }
     }
     RevDeploy::writeDeploymentNagiosCfg($deployment, $cfgInfo, $modrevision);
     unset($_SESSION[$deployment]['brokermods']);
     $viewData->deployment = $deployment;
     $this->sendResponse('nagios_cfg_write', $viewData);
 }
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('timeperiod_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $timeName = $this->getParam('tpName');
     $tpArray = $_SESSION[$deployment]['timeperiods'];
     $timeInfo = $this->fetchTimeperiodInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentTimeperiod($deployment, $timeName, $modrevision) === true) {
         $viewData->error = 'Timeperiod information exists for ' . $timeName . ' in ' . $deployment . ' Deployment';
         $viewData->timeInfo = $timeInfo;
         $viewData->action = 'copy_write';
         $this->sendResponse('timeperiod_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentTimeperiod($deployment, $timeName, $timeInfo, $tpArray, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('timeperiod_error');
         $viewData->error = 'Unable to write timeperiod information for ' . $timeName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     unset($_SESSION[$deployment]['timeperiods']);
     $viewData->deployment = $deployment;
     $viewData->timeperiod = $timeName;
     $this->sendResponse('timeperiod_write', $viewData);
 }
 public function sup_import_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('sup_nrpe_cfg_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $filelocation = $this->getParam('location');
     if ($filelocation === false) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
         $viewData->error = 'Unable to read file location, please ensure file location was specified';
         $this->sendError('generic_error', $viewData);
     }
     $filecontents = $this->fetchUploadedFile('file');
     if ($filecontents === false) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
         $viewData->error = 'Unable to read imported file, please ensure file was appended';
         $this->sendError('generic_error', $viewData);
     }
     $filemeta = NagImport::processSupNRPECfg($filecontents);
     if (empty($filemeta)) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
         $viewData->error = 'Unable to read imported file, problem parsing command information';
         $this->sendError('generic_error', $viewData);
     }
     RevDeploy::importDeploymentSupNRPECfg($deployment, $modrevision, $filelocation, $filemeta);
     $viewData->deployment = $deployment;
     $this->sendResponse('sup_nrpe_cfg_import_write', $viewData);
 }
Exemplo n.º 8
0
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('svc_dep_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $svcDepInfo = $this->fetchSvcDepInfo($deployment, 'copy_write', $modrevision);
     $svcDepName = $svcDepInfo['name'];
     if (RevDeploy::existsDeploymentSvcDependency($deployment, $svcDepName, $modrevision) === true) {
         $viewData->error = 'Service information exists for ' . $svcDepName . ' in ' . $deployment . ' Deployment';
         $viewData->svcs = RevDeploy::getCommonMergedDeploymentSvcs($deployment, $modrevision);
         $viewData->svcDepInfo = $svcDepInfo;
         $viewData->action = 'copy_write';
         $this->sendResponse('svc_dep_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentSvcDependency($deployment, $svcDepName, $svcDepInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('svc_dep_error');
         $viewData->error = 'Unable to write service information for ' . $svcDepName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->svc = $svcDepName;
     $this->sendResponse('svc_dep_write', $viewData);
 }
 public function copy_to_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('nrpe_cmd_error');
     $nrpecmdInfo = $this->fetchNRPECmdInfo($deployment, 'copy_to_write');
     $todeployment = $this->getParam('todeployment');
     if ($todeployment === false) {
         $viewData->error = 'Unable to detect deployment to copy command to';
         $viewData->availdeployments = $this->getDeploymentsAvailToUser();
         $viewData->deployment = $deployment;
         $viewData->nrpecmdInfo = $nrpecmdInfo;
         $viewData->action = 'copy_to_write';
         $this->sendResponse('command_action_stage', $viewData);
     }
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($todeployment);
     $deployRev = RevDeploy::getDeploymentNextRev($deployment);
     $tdRev = RevDeploy::getDeploymentNextRev($todeployment);
     $nrpecmdName = $nrpecmdInfo['cmd_name'];
     $nrpecmdInfo = RevDeploy::getDeploymentNRPECmd($deployment, $nrpecmdName, $deployRev);
     if (RevDeploy::existsDeploymentNRPECmd($todeployment, $nrpecmdName, $tdRev) === true) {
         RevDeploy::modifyDeploymentNRPECmd($todeployment, $nrpecmdName, $nrpecmdInfo, $tdRev);
     } else {
         RevDeploy::createDeploymentNRPECmd($todeployment, $nrpecmdName, $nrpecmdInfo, $tdRev);
     }
     $viewData->deployment = $deployment;
     $viewData->todeployment = $todeployment;
     $viewData->command = $nrpecmdName;
     $this->sendResponse('nrpe_cmd_write', $viewData);
 }
 public function copy_to_write_sup()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('sup_nrpe_plugin_error');
     $plugin = $this->getPlugin('sup_nrpe_plugin_error');
     $todeployment = $this->getParam('todeployment');
     if ($todeployment === false) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_plugin_error');
         $viewData->error = 'Unable to detect deployment to copy plugin to';
         $this->sendResponse('generic_error', $viewData);
     }
     $this->checkGroupAuth($todeployment);
     $this->checkDeploymentRevStatus($todeployment);
     $tdRev = RevDeploy::getDeploymentNextRev($todeployment);
     $deployRev = RevDeploy::getDeploymentNextRev($deployment);
     $pluginInfo = RevDeploy::getDeploymentSupNRPEPlugin($deployment, $plugin, $deployRev);
     if (RevDeploy::existsDeploymentSupNRPEPlugin($todeployment, $plugin, $tdRev) === true) {
         RevDeploy::modifyDeploymentSupNRPEPlugin($todeployment, $plugin, $pluginInfo, $tdRev);
     } else {
         RevDeploy::createDeploymentSupNRPEPlugin($todeployment, $plugin, $pluginInfo, $tdRev);
     }
     $viewData->todeployment = $todeployment;
     $ccs = $this->getParam('ccs');
     if ($ccs == 1) {
         $viewData->deployment = $todeployment;
     } else {
         $viewData->deployment = $deployment;
     }
     $viewData->plugin = $plugin;
     $this->sendResponse('sup_nrpe_plugin_write', $viewData);
 }
Exemplo n.º 11
0
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('host_group_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $hostGrpName = $this->getParam('hostName');
     $hostGrpInfo = $this->fetchHostInfo($deployment, 'copy_write');
     if (RevDeploy::existsDeploymentHostGroup($deployment, $hostGrpName, $modrevision) === true) {
         $viewData->error = 'Host information exists for ' . $hostGrpName . ' in ' . $deployment . ' Deployment';
         $viewData->hostGrpInfo = $hostGrpInfo;
         $viewData->action = 'copy_write';
         $this->sendResponse('host_group_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentHostGroup($deployment, $hostGrpName, $hostGrpInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('host_group_error');
         $viewData->error = 'Unable to write host information for ' . $hostGrpName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->host = $hostGrpName;
     $this->sendResponse('host_group_write', $viewData);
 }
Exemplo n.º 12
0
 /**
  * checkDeploymentRevStatus 
  * 
  * @param mixed $deployment deployment we are processing 
  *
  * @access public
  * @return void
  */
 public function checkDeploymentRevStatus($deployment)
 {
     $currRev = RevDeploy::getDeploymentRev($deployment);
     $nextRev = RevDeploy::getDeploymentNextRev($deployment);
     if ($currRev === false && $nextRev === false) {
         return;
     }
     if ($currRev == $nextRev) {
         $incrRev = RevDeploy::incrDeploymentNextRev($deployment);
         CopyDeploy::copyDeploymentRevision($deployment, $currRev, $incrRev);
     }
 }
Exemplo n.º 13
0
 public function copy_to_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_error');
     $contactName = $this->getParam('contactName');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $contactInfo = $this->fetchContactInfo($deployment, 'copy_to_write', $modrevision);
     $todeployment = $this->getParam('todeployment');
     if ($todeployment === false) {
         $viewData->error = 'Unable to detect contact to copy contact to';
         $viewData->availdeployments = $this->getDeploymentsAvailToUser();
         $viewData->contactInfo = $contactInfo;
         $viewData->contacttemplates = RevDeploy::getCommonMergedDeploymentContactTemplates($deployment, $modrevision);
         $viewData->notifycmds = RevDeploy::getCommonMergedDeploymentNotifyCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $viewData->action = 'copy_to_write';
         $this->sendResponse('contact_action_stage', $viewData);
     }
     $this->checkGroupAuth($todeployment);
     $this->checkDeploymentRevStatus($todeployment);
     $tdRev = RevDeploy::getDeploymentNextRev($todeployment);
     if (RevDeploy::existsDeploymentContact($todeployment, $contactName, $tdRev) === true) {
         RevDeploy::modifyDeploymentContact($todeployment, $contactName, $contactInfo, $tdRev);
     } else {
         RevDeploy::createDeploymentContact($todeployment, $contactName, $contactInfo, $tdRev);
     }
     $viewData->deployment = $deployment;
     $viewData->todeployment = $todeployment;
     $viewData->contact = $contactName;
     $this->sendResponse('contact_write', $viewData);
 }
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_template_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $contactName = $this->getParam('contactName');
     $contactInfo = $this->fetchContactTemplateInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentContactTemplate($deployment, $contactName, $modrevision) === true) {
         $viewData->error = 'Contact template information exists for ' . $contactName . ' into ' . $deployment . ' Deployment';
         $viewData->action = 'copy_write';
         $viewData->contacttemplate = $contactName;
         $viewData->deployment = $deployment;
         $viewData->contacttemplates = RevDeploy::getCommonMergedDeploymentContactTemplates($deployment, $modrevision);
         $viewData->notifycmds = RevDeploy::getCommonMergedDeploymentNotifyCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->contactInfo = $contactInfo;
         $this->sendResponse('contact_template_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentContactTemplate($deployment, $contactName, $contactInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('contact_template_error');
         $viewData->error = 'Unable to write contact tempalte information for ' . $contactName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->contact = $contactName;
     $this->sendResponse('contact_template_write', $viewData);
 }
Exemplo n.º 15
0
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect an appropriate contact parameter, email or pager");
            $app->halt(404, $apiResponse->returnJson());
        }
    }
    $contactInfo = contact_validate($app, $deployment, $contactInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentContact($deployment, $contactInfo['contact_name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentContact($deployment, $contactInfo['contact_name'], $contactInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Contact  " . $contactInfo['contact_name']);
    } else {
        RevDeploy::createDeploymentContact($deployment, $contactInfo['contact_name'], $contactInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Contact  " . $contactInfo['contact_name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-contact');
$app->delete('/sapi/contact/:deployment/:contact', function ($deployment, $contact) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $contact)) {
        $contacts = preg_split('/\\s?,\\s?/', $contact);
        foreach ($contacts as $ctemp) {
            RevDeploy::deleteDeploymentContact($deployment, $ctemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentContact($deployment, $contact, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Contact(s): {$contact}");
    $apiResponse->printJson();
})->name('saigon-api-delete-contact');
Exemplo n.º 16
0
 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);
 }
 /**
  * reset_ftr_rev - reset future revision to match current revision information 
  * 
  * @access public
  * @return void
  */
 public function reset_ftr_rev()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('deployment_error');
     $this->checkGroupAuth($deployment);
     $currrev = RevDeploy::getDeploymentRev($deployment);
     $nextrev = RevDeploy::getDeploymentNextRev($deployment);
     if ($currrev == $nextrev) {
         $viewData->header = $this->getErrorHeader('deployment_error');
         $viewData->error = 'Unable to process request, no new revision exists to reset';
         $this->sendError('generic_error', $viewData);
     }
     CopyDeploy::resetDeploymentRevision($deployment, $currrev, $nextrev);
     $viewData->deployment = $deployment;
     $viewData->currrev = $currrev;
     $viewData->nextrev = $nextrev;
     $this->sendResponse('deployment_rfr', $viewData);
 }