示例#1
0
function timeperiodBuildTimes($app, $deployment, array $timeperiodInfo, $use_enabled = false)
{
    if ($use_enabled === false) {
        if (!isset($timeperiodInfo['timeperiods']) || empty($timeperiodInfo['timeperiods'])) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect timeperiods parameter (expected array of hashes [{directive=>value,range=>value},..] )");
            $app->halt(404, $apiResponse->returnJson());
        } elseif (!is_array($timeperiodInfo['timeperiods'])) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to use timeperiods parameter (expected array of hashes [{directive=>value,range=>value},..] )");
            $app->halt(404, $apiResponse->returnJson());
        }
    } else {
        if (!isset($timeperiodInfo['timeperiods']) || empty($timeperiodInfo['timeperiods'])) {
            return array();
        } elseif (!is_array($timeperiodInfo['timeperiods'])) {
            // Not ideal, but I'll think of some way to deal with this...
            return array();
        }
    }
    $results = array();
    foreach ($timeperiodInfo['timeperiods'] as $key => $dArray) {
        if (!isset($dArray['directive']) || empty($dArray['directive'])) {
            continue;
        } elseif (!isset($dArray['range']) || empty($dArray['range'])) {
            continue;
        }
        $results[md5($dArray['directive'])] = $dArray;
    }
    return $results;
}
示例#2
0
function contact_validate($app, $deployment, $contactInfo)
{
    foreach ($contactInfo as $key => $value) {
        switch ($key) {
            case "use":
            case "host_notification_period":
            case "service_notification_period":
            case "host_notification_commands":
            case "service_notification_commands":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "retain_status_information":
            case "retain_nonstatus_information":
            case "host_notifications_enabled":
            case "service_notifications_enabled":
            case "can_submit_commands":
                validateBinary($app, $deployment, $key, $value);
                break;
            case "host_notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('d', 'u', 'r', 's', 'n'), true);
                $contactInfo[$key] = $opts;
                break;
            case "service_notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('w', 'u', 'c', 'r', 's', 'n'), true);
                $contactInfo[$key] = $opts;
                break;
            case "email":
                validateEmail($app, $deployment, $key, $value);
                break;
            case "pager":
                if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
                    if (!preg_match("/^(?[2-9][0-8][0-9])?-[2-9][0-0]{2}-[0-9]{4}\$/", $value)) {
                        $apiResponse = new APIViewData(1, $deployment, "Unable use pager number provided, the value provided doesn't match the regex for pager or email address");
                        $apiResponse->setExtraResponseData('parameter', $key);
                        $apiResponse->setExtraResponseData('parameter-value', $value);
                        $apiResponse->setExtraResponseData('parameter-pager-regex', "/^(?[2-9][0-8][0-9])?-[2-9][0-0]{2}-[0-9]{4}\$/");
                        $app->halt(404, $apiResponse->returnJson());
                    }
                }
                break;
            case "contactgroups":
                if (is_array($value)) {
                    $value = implode(',', $value);
                }
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            default:
                break;
        }
    }
    return $contactInfo;
}
示例#3
0
function validateContacts($app, $deployment, array $info)
{
    $contacts = false;
    $contact_groups = false;
    if (isset($info['contacts']) && !empty($info['contacts'])) {
        $contacts = true;
    }
    if (isset($info['contact_groups']) && !empty($info['contact_groups'])) {
        $contact_groups = true;
    }
    if ($contacts === true || $contact_groups === true) {
        return true;
    }
    $apiResponse = new APIViewData(1, $deployment, "Unable to detect either contacts or contact_group parameter");
    $app->halt(404, $apiResponse->returnJson());
}
示例#4
0
$app->post('/sapi/supnrpecfg/:deployment', function ($deployment) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    $request = $app->request();
    $contentType = $request->headers('Content-Type');
    if ($contentType == 'application/json') {
        $supNRPECfgInfo = $request->getBody();
        $supNRPECfgInfo = json_decode($supNRPECfgInfo, true);
    } elseif (preg_match("/form-(data|urlencoded)/", $contentType)) {
        $supNRPECfgInfo['location'] = $request->post('location');
        $supNRPECfgInfo['cmds'] = $request->post('cmds');
    }
    // A bit of param validation
    if (!isset($supNRPECfgInfo['location']) || empty($supNRPECfgInfo['location'])) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect location parameter (unix path including filename)");
        $app->halt(404, $apiResponse->returnJson());
    }
    // Param manipulation depending on what is detected
    if (is_array($supNRPECfgInfo['cmds'])) {
        $supNRPECfgInfo['cmds'] = implode(',', $supNRPECfgInfo['cmds']);
    }
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSupNRPECfg($deployment, $deployRev) === true) {
        RevDeploy::modifyDeploymentSupNRPECfg($deployment, $supNRPECfgInfo, $deployRev);
        $msg = "Successfully Modified NRPE Config";
    } else {
        RevDeploy::createDeploymentSupNRPECfg($deployment, $supNRPECfgInfo, $deployRev);
        $msg = "Successfully Created NRPE Config";
    }
    $supNRPECfgInfo = RevDeploy::getDeploymentNRPECfg($deployment, $deployRev);