diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-01-18 15:53:39 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-01-18 15:53:39 +0000 |
| commit | 274354c2aff78c8d96f78a36a654b215bd6232fa (patch) | |
| tree | cb9c0d9e87d73dbe98a07fc8f03c4d4eb9644d98 /frontends/php/include | |
| parent | 3c99a2e8c2dd141362ccc16ed2e2bd0fb2c60192 (diff) | |
Forntend improvements.
git-svn-id: svn://svn.zabbix.com/trunk@2538 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/defines.inc.php | 5 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/validate.inc.php | 110 |
3 files changed, 64 insertions, 53 deletions
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index c07d8341..4310f8f8 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -28,6 +28,11 @@ define("O_OPT", 1); define("O_NO", 2); + define("P_SYS", 1); + define("P_USR", 2); + define("P_GET", 4); + define("P_POST", 8); + // MISC PARAMETERS define("MAP_OUTPUT_FORMAT", "DEFAULT"); # define("MAP_OUTPUT_FORMAT", "JPG"); diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 9d295c5a..e7247de8 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -1365,7 +1365,7 @@ $smtp_email=@iif(isset($_REQUEST["smtp_email"]),$_REQUEST["smtp_email"],"zabbix@localhost"); $exec_path=@iif(isset($_REQUEST["exec_path"]),$_REQUEST["exec_path"],""); - if(isset($_REQUEST["register"]) && ($_REQUEST["register"] == "change")) + if(isset($_REQUEST["mediatypeid"])) { $result=DBselect("select mediatypeid,type,description,smtp_server,smtp_helo,smtp_email,exec_path from media_type where mediatypeid=".$_REQUEST["mediatypeid"]); $row=DBfetch($result); diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php index b69d0ec8..659935bc 100644 --- a/frontends/php/include/validate.inc.php +++ b/frontends/php/include/validate.inc.php @@ -19,79 +19,73 @@ **/ ?> <?php - function check_var($var,$checks) + function calc_exp($fields,$field,$expression) { - global $_REQUEST; - - $ret = 1; + global $_REQUEST; - foreach($checks as $field=>$check) + if(strstr($expression,"{}")) { - if(is_int($key)) - { - $op=$check[0]; - $val=$check[$op]; - - echo "ZZZ"; - echo isset($check["min"]); - } - else + if(!isset($_REQUEST[$field])) return FALSE; + } + $expression = str_replace("{}",'$_REQUEST["'.$field.'"]',$expression); + foreach($fields as $f => $checks) + { + // If an unset variable used in expression, return FALSE + if(strstr($expression,'{'.$f.'}')&&!isset($_REQUEST[$f])) { - if(isset($_REQUEST[$var])) - { - if(($check == T_ZBX_INT)&&(!is_int($_REQUEST[$var]))) - break; - if( ($check == T_ZBX_FLOAT)&&(!is_float($_REQUEST[$var]))) - break; - if($check == T_ZBX_PERIOD) - break; - if( ($check == V_NOT_EMPTY)&&($_REQUEST[$var]=="")) - break; - } +// info("Variable is not set. $expression is FALSE"); + return FALSE; } +// echo $f,":",$expression,"<br>"; + $expression = str_replace('{'.$f.'}','$_REQUEST["'.$f.'"]',$expression); } - - return $ret; + $expression=rtrim($expression,"&"); + if($expression[strlen($expression)-1]=='&') $expression[strlen($expression)-1]=0; + if($expression[strlen($expression)-1]=='&') $expression[strlen($expression)-1]=0; + $exec = "return ".$expression.";"; +// info($exec); + return eval($exec); } - function calc_exp($field,$expression) + function unset_all(&$fields) { - global $_REQUEST; - - if(strstr($expression,"{}")) + foreach($_REQUEST as $key => $val) { - if(!isset($_REQUEST[$field])) return FALSE; + if(!isset($fields[$key])) + { +// info("Unset:".$key); + unset($_REQUEST[$key]); + } } - $exec = str_replace("{}",'$_REQUEST["'.$field.'"]',$expression); - $exec = "return ".$exec.'1;'; -// echo $exec,"<br>"; - return eval($exec); } - function check_fields($fields) + function check_fields(&$fields) { global $_REQUEST; - $ret = 1; + $ret = TRUE; foreach($fields as $field => $checks) { - list($type,$opt,$table,$column,$validation,$exception)=$checks; + list($type,$opt,$flags,$validation,$exception)=$checks; +// info("Field: $field"); if($exception==NULL) $except=FALSE; - else $except=calc_exp($field,$exception); + 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 && $exception) $opt = O_NO; - else if($opt == O_OPT && $exception) $opt = O_MAND; - else if($opt == O_NO && $exception) $opt = O_MAND; if($opt == O_MAND) { if(!isset($_REQUEST[$field])) { - info("Field [".$field."] is mandatory"); $ret = 0; continue; + info("Field [".$field."] is mandatory"); + $ret = FALSE; + continue; } } @@ -99,7 +93,9 @@ { if(isset($_REQUEST[$field])) { - info("Field [".$field."] must be missing"); $ret = 0; continue; + info("Field [".$field."] must be missing"); + $ret = FALSE; + continue; } else continue; } @@ -111,21 +107,31 @@ if( ($type == T_ZBX_INT) && !is_numeric($_REQUEST[$field])) { - info("Field [".$field."] is not integer"); $ret = 0; continue; + info("Field [".$field."] is not integer"); + $ret = FALSE; + continue; } if( ($type == T_ZBX_DBL) && !is_numeric($_REQUEST[$field])) { - info("Field [".$field."] is not double"); $ret = 0; continue; + info("Field [".$field."] is not double"); + $ret = FALSE; + continue; } - if($validation==NULL) $valid=TRUE; - else $valid=calc_exp($field,$validation); - - if(!$valid) + if(($exception==NULL)||($except==TRUE)) { - info("Field [".$field."] is invalid"); $ret = 0; continue; + if(!$validation) $valid=TRUE; + else $valid=calc_exp($fields,$field,$validation); + + if(!$valid) + { + info("Incorrect value for [".$field."]"); + $ret = FALSE; + continue; + } } } + unset_all($fields); return $ret; } ?> |
