Example #1
0
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/forms.inc.php';
require_once dirname(__FILE__) . '/include/regexp.inc.php';
$page['title'] = _('Configuration of regular expressions');
$page['file'] = 'adm.regexps.php';
$page['type'] = detect_page_type();
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = ['regexpids' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, null], 'regexpid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form}) && {form} == "update"'], 'name' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Name')], 'test_string' => [T_ZBX_STR, O_OPT, P_NO_TRIM, null, 'isset({add}) || isset({update})', _('Test string')], 'expressions' => [T_ZBX_STR, O_OPT, P_NO_TRIM, null, 'isset({add}) || isset({update})'], 'action' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, IN('"regexp.massdelete"'), null], 'add' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null], 'update' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null], 'form' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'form_refresh' => [T_ZBX_INT, O_OPT, null, null, null], 'output' => [T_ZBX_STR, O_OPT, P_ACT, null, null], 'ajaxaction' => [T_ZBX_STR, O_OPT, P_ACT, null, null], 'ajaxdata' => [T_ZBX_STR, O_OPT, P_ACT | P_NO_TRIM, null, null]];
check_fields($fields);
/*
 * 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);
Example #2
0
$fields = array('druleid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form}) && {form} == "update"'), 'name' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})'), 'proxy_hostid' => array(T_ZBX_INT, O_OPT, null, DB_ID, 'isset({add}) || isset({update})'), 'iprange' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})'), 'delay' => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, SEC_PER_WEEK), 'isset({add}) || isset({update})'), 'status' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'uniqueness_criteria' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})', _('Device uniqueness criteria')), 'g_druleid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'dchecks' => array(null, O_OPT, null, null, null), 'action' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, IN('"drule.massdelete","drule.massdisable","drule.massenable"'), null), 'add' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'update' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null), 'output' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), 'ajaxaction' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), 'ajaxdata' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), 'sort' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"name"'), null), 'sortorder' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"' . ZBX_SORT_DOWN . '","' . ZBX_SORT_UP . '"'), null));
check_fields($fields);
$_REQUEST['status'] = isset($_REQUEST['status']) ? DRULE_STATUS_ACTIVE : DRULE_STATUS_DISABLED;
$_REQUEST['dchecks'] = getRequest('dchecks', array());
/*
 * Permissions
 */
if (isset($_REQUEST['druleid'])) {
    $dbDRule = API::DRule()->get(array('druleids' => getRequest('druleid'), 'output' => array('name', 'proxy_hostid', 'iprange', 'delay', 'status'), 'selectDChecks' => array('type', 'key_', 'snmp_community', 'ports', 'snmpv3_securityname', 'snmpv3_securitylevel', 'snmpv3_authpassphrase', 'snmpv3_privpassphrase', 'uniq', 'snmpv3_authprotocol', 'snmpv3_privprotocol', 'snmpv3_contextname'), 'editable' => true));
    if (empty($dbDRule)) {
        access_deny();
    }
}
// ajax
if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'ajax') {
    $ajaxResponse = new CAjaxResponse();
    if (isset($_REQUEST['ajaxaction']) && $_REQUEST['ajaxaction'] == 'validate') {
        $ajaxData = getRequest('ajaxdata', array());
        foreach ($ajaxData as $check) {
            switch ($check['field']) {
                case 'port':
                    if (!validate_port_list($check['value'])) {
                        $ajaxResponse->error(_('Incorrect port range.'));
                    }
                    break;
                case 'itemKey':
                    $itemKey = new CItemKey($check['value']);
                    if (!$itemKey->isValid()) {
                        $ajaxResponse->error(_s('Invalid key "%1$s": %2$s.', $check['value'], $itemKey->getError()));
                    }
                    break;