function check_field(&$fields, &$field, $checks) { if (!isset($checks[5])) { $checks[5] = $field; } list($type, $opt, $flags, $validation, $exception, $caption) = $checks; if ($flags & P_UNSET_EMPTY && isset($_REQUEST[$field]) && $_REQUEST[$field] == '') { unset_request($field); } $except = !is_null($exception) ? calc_exp($fields, $field, $exception) : false; if ($except) { if ($opt == O_MAND) { $opt = O_NO; } elseif ($opt == O_OPT) { $opt = O_MAND; } elseif ($opt == O_NO) { $opt = O_MAND; } } if ($opt == O_MAND) { if (!isset($_REQUEST[$field])) { info(_s('Field "%1$s" is mandatory.', $caption)); return $flags & P_SYS ? ZBX_VALID_ERROR : ZBX_VALID_WARNING; } } elseif ($opt == O_NO) { if (!isset($_REQUEST[$field])) { return ZBX_VALID_OK; } unset_request($field); info(_s('Field "%1$s" must be missing.', $caption)); return $flags & P_SYS ? ZBX_VALID_ERROR : ZBX_VALID_WARNING; } elseif ($opt == O_OPT) { if (!isset($_REQUEST[$field])) { return ZBX_VALID_OK; } elseif ($flags & P_ACT) { if (!isset($_REQUEST['sid']) || isset($_COOKIE['zbx_sessionid']) && $_REQUEST['sid'] != substr($_COOKIE['zbx_sessionid'], 16, 16)) { info(_('Operation cannot be performed due to unauthorized request.')); return ZBX_VALID_ERROR; } } } if (!($flags & P_NO_TRIM)) { check_trim($_REQUEST[$field]); } $err = check_type($field, $flags, $_REQUEST[$field], $type, $caption); if ($err != ZBX_VALID_OK) { return $err; } if ((is_null($exception) || $except) && $validation && !calc_exp($fields, $field, $validation)) { if ($validation == NOT_EMPTY) { info(_s('Incorrect value for field "%1$s": cannot be empty.', $caption)); } elseif (preg_match('/\\(\\{\\}\\>=([0-9]*)\\&\\&\\{\\}\\<=([0-9]*)\\)\\&\\&/', $validation, $result)) { info(_s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $_REQUEST[$field], $caption, $result[1], $result[2])); } else { info(_s('Incorrect value "%1$s" for "%2$s" field.', $_REQUEST[$field], $caption)); } return $flags & P_SYS ? ZBX_VALID_ERROR : ZBX_VALID_WARNING; } return ZBX_VALID_OK; }
function check_field(&$fields, &$field, $checks) { list($type, $opt, $flags, $validation, $exception) = $checks; if ($flags & P_UNSET_EMPTY && isset($_REQUEST[$field]) && $_REQUEST[$field] == '') { unset_request($field, 'P_UNSET_EMPTY'); } //echo "Field: $field<br>"; if ($exception == NULL) { $except = FALSE; } else { $except = calc_exp($fields, $field, $exception); } if ($opt == O_MAND && $except) { $opt = O_NO; } else { if ($opt == O_OPT && $except) { $opt = O_MAND; } else { if ($opt == O_NO && $except) { $opt = O_MAND; } } } if ($opt == O_MAND) { if (!isset($_REQUEST[$field])) { if ($flags & P_SYS) { info("Critical error. Field [" . $field . "] is mandatory"); return ZBX_VALID_ERROR; } else { info("Warning. Field [" . $field . "] is mandatory"); return ZBX_VALID_WARNING; } } } else { if ($opt == O_NO) { if (!isset($_REQUEST[$field])) { return ZBX_VALID_OK; } unset_request($field, 'O_NO'); if ($flags & P_SYS) { info("Critical error. Field [" . $field . "] must be missing"); return ZBX_VALID_ERROR; } else { info("Warning. Field [" . $field . "] must be missing"); return ZBX_VALID_WARNING; } } else { if ($opt == O_OPT) { if (!isset($_REQUEST[$field])) { return ZBX_VALID_OK; } else { if ($flags & P_ACT) { if (!isset($_REQUEST['sid'])) { return ZBX_VALID_ERROR; } else { if (isset($_COOKIE['zbx_sessionid']) && $_REQUEST['sid'] != substr($_COOKIE['zbx_sessionid'], 16, 16)) { return ZBX_VALID_ERROR; } } } } } } } check_trim($_REQUEST[$field]); $err = check_type($field, $flags, $_REQUEST[$field], $type); if ($err != ZBX_VALID_OK) { return $err; } if ($exception == NULL || $except == TRUE) { if (!$validation) { $valid = TRUE; } else { $valid = calc_exp($fields, $field, $validation); } if (!$valid) { if ($flags & P_SYS) { info("Critical error. Incorrect value for [" . $field . "] = '" . $_REQUEST[$field] . "'"); return ZBX_VALID_ERROR; } else { info("Warning. Incorrect value for [" . $field . "]"); return ZBX_VALID_WARNING; } } } return ZBX_VALID_OK; }
function check_field(&$fields, &$field, $checks) { if (!isset($checks[5])) { $checks[5] = $field; } list($type, $opt, $flags, $validation, $exception, $caption) = $checks; if ($flags & P_UNSET_EMPTY && isset($_REQUEST[$field]) && $_REQUEST[$field] == '') { unset_request($field, 'P_UNSET_EMPTY'); } //SDI("Field: $field"); if ($exception == NULL) { $except = FALSE; } else { $except = calc_exp($fields, $field, $exception); } if ($opt == O_MAND && $except) { $opt = O_NO; } else { if ($opt == O_OPT && $except) { $opt = O_MAND; } else { if ($opt == O_NO && $except) { $opt = O_MAND; } } } if ($opt == O_MAND) { if (!isset($_REQUEST[$field])) { if ($flags & P_SYS) { info(S_CRITICAL_ERROR . '.' . SPACE . S_FIELD . SPACE . '[' . $caption . ']' . SPACE . S_IS_MANDATORY_SMALL); return ZBX_VALID_ERROR; } else { info(S_WARNING . '.' . SPACE . S_FIELD . SPACE . '[' . $caption . ']' . SPACE . S_IS_MANDATORY_SMALL); return ZBX_VALID_WARNING; } } } else { if ($opt == O_NO) { if (!isset($_REQUEST[$field])) { return ZBX_VALID_OK; } unset_request($field, 'O_NO'); if ($flags & P_SYS) { info(S_CRITICAL_ERROR . '.' . SPACE . S_FIELD . SPACE . '[' . $caption . ']' . SPACE . S_MUST_BE_MISSING_SMALL); return ZBX_VALID_ERROR; } else { info(S_WARNING . '.' . SPACE . S_FIELD . SPACE . '[' . $caption . ']' . SPACE . S_MUST_BE_MISSING_SMALL); return ZBX_VALID_WARNING; } } else { if ($opt == O_OPT) { if (!isset($_REQUEST[$field])) { return ZBX_VALID_OK; } else { if ($flags & P_ACT) { if (!isset($_REQUEST['sid'])) { info(S_OPERATION_CANNOT_PERFORMED_UNAUTH_REQUEST); return ZBX_VALID_ERROR; } else { if (isset($_COOKIE['zbx_sessionid']) && $_REQUEST['sid'] != substr($_COOKIE['zbx_sessionid'], 16, 16)) { info(S_OPERATION_CANNOT_PERFORMED_UNAUTH_REQUEST); return ZBX_VALID_ERROR; } } } } } } } check_trim($_REQUEST[$field]); $err = check_type($field, $flags, $_REQUEST[$field], $type); if ($err != ZBX_VALID_OK) { return $err; } //sdi($field. '| exception ='.$exception.' | except ='.$except.' | validation= '.$validation); if (is_null($exception) || $except == true) { if (!$validation) { $valid = TRUE; } else { $valid = calc_exp($fields, $field, $validation); } if (!$valid) { if ($flags & P_SYS) { info(S_CRITICAL_ERROR . '.' . SPACE . S_INCORRECT_VALUE_FOR . SPACE . '[' . $caption . '] = "' . $_REQUEST[$field] . '"'); return ZBX_VALID_ERROR; } else { info(S_WARNING . '.' . SPACE . S_INCORRECT_VALUE_FOR . SPACE . '[' . $caption . ']'); return ZBX_VALID_WARNING; } } } return ZBX_VALID_OK; }