Example #1
0
    $ajaxResponse = new CAjaxResponse();
    $ajaxData = getRequest('ajaxdata', []);
    if (isset($_REQUEST['ajaxaction']) && $_REQUEST['ajaxaction'] == 'test') {
        $result = ['expressions' => [], 'errors' => [], 'final' => true];
        $validator = new CRegexValidator(['messageInvalid' => _('Regular expression must be a string'), 'messageRegex' => _('Incorrect regular expression "%1$s": "%2$s"')]);
        foreach ($ajaxData['expressions'] as $id => $expression) {
            if (!in_array($expression['expression_type'], [EXPRESSION_TYPE_FALSE, EXPRESSION_TYPE_TRUE]) || $validator->validate($expression['expression'])) {
                $match = CGlobalRegexp::matchExpression($expression, $ajaxData['testString']);
                $result['expressions'][$id] = $match;
            } else {
                $match = false;
                $result['errors'][$id] = $validator->getError();
            }
            $result['final'] = $result['final'] && $match;
        }
        $ajaxResponse->success($result);
    }
    $ajaxResponse->send();
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Permissions
 */
if (isset($_REQUEST['regexpid'])) {
    $regExp = DBfetch(DBSelect('SELECT re.regexpid FROM regexps re WHERE re.regexpid=' . zbx_dbstr(getRequest('regexpid'))));
    if (empty($regExp)) {
        access_deny();
    }
}
if (hasRequest('action') && !hasRequest('regexpid')) {