コード例 #1
0
ファイル: regexp.inc.php プロジェクト: jbfavre/debian-zabbix
function validateRegexp($expressions)
{
    $validator = new CRegexValidator(['messageInvalid' => _('Regular expression must be a string'), 'messageRegex' => _('Incorrect regular expression "%1$s": "%2$s"')]);
    foreach ($expressions as $expression) {
        switch ($expression['expression_type']) {
            case EXPRESSION_TYPE_TRUE:
            case EXPRESSION_TYPE_FALSE:
                if (!$validator->validate($expression['expression'])) {
                    throw new Exception($validator->getError());
                }
                break;
            case EXPRESSION_TYPE_INCLUDED:
            case EXPRESSION_TYPE_NOT_INCLUDED:
                if ($expression['expression'] === '') {
                    throw new Exception(_('Expression cannot be empty'));
                }
                break;
            case EXPRESSION_TYPE_ANY_INCLUDED:
                foreach (explode($expression['exp_delimiter'], $expression['expression']) as $string) {
                    if ($expression['expression'] === '') {
                        throw new Exception(_('Expression cannot be empty'));
                    }
                }
                break;
        }
    }
}
コード例 #2
0
ファイル: adm.regexps.php プロジェクト: jbfavre/debian-zabbix
/*
 * Ajax
 */
if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'ajax') {
    $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)) {
コード例 #3
0
ファイル: regexp.inc.php プロジェクト: TonywalkerCN/Zabbix
function validateRegexp($expressions)
{
    $validator = new CRegexValidator(array('messageInvalid' => _('Regular expression must be a string'), 'messageRegex' => _('Incorrect regular expression "%1$s": "%2$s"')));
    foreach ($expressions as $expression) {
        if ($expression['expression_type'] == EXPRESSION_TYPE_TRUE || $expression['expression_type'] == EXPRESSION_TYPE_FALSE) {
            if (!$validator->validate($expression['expression'])) {
                throw new \Exception($validator->getError());
            }
        }
    }
}