diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-01-30 15:58:48 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-01-30 15:58:48 +0000 |
| commit | e3693c12ab9e2bf934e1cb8194c1be5fe3650d86 (patch) | |
| tree | 6d3ce9d0adf5ff71f0d4f4415a4a9854651840d8 /frontends/php/include | |
| parent | 042eb9179036479789a63b7eda13c84734a741e7 (diff) | |
- fixed permissions for triggers (Eugene)
- developed 'mass update' functionality for items (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3772 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/classes/ccheckbox.inc.php | 104 | ||||
| -rw-r--r-- | frontends/php/include/classes/cformtable.inc.php | 4 | ||||
| -rw-r--r-- | frontends/php/include/classes/ctextbox.inc.php | 5 | ||||
| -rw-r--r-- | frontends/php/include/config.inc.php | 45 | ||||
| -rw-r--r-- | frontends/php/include/defines.inc.php | 7 | ||||
| -rw-r--r-- | frontends/php/include/events.inc.php | 5 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 490 | ||||
| -rw-r--r-- | frontends/php/include/hosts.inc.php | 11 | ||||
| -rw-r--r-- | frontends/php/include/items.inc.php | 57 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 12 | ||||
| -rw-r--r-- | frontends/php/include/page_footer.php | 24 | ||||
| -rw-r--r-- | frontends/php/include/page_header.php | 27 | ||||
| -rw-r--r-- | frontends/php/include/perm.inc.php | 50 | ||||
| -rw-r--r-- | frontends/php/include/triggers.inc.php | 66 | ||||
| -rw-r--r-- | frontends/php/include/validate.inc.php | 5 |
15 files changed, 809 insertions, 103 deletions
diff --git a/frontends/php/include/classes/ccheckbox.inc.php b/frontends/php/include/classes/ccheckbox.inc.php index 2b0a7874..526ceedf 100644 --- a/frontends/php/include/classes/ccheckbox.inc.php +++ b/frontends/php/include/classes/ccheckbox.inc.php @@ -22,7 +22,7 @@ class CCheckBox extends CTag { /* public */ - function CCheckBox($name='checkbox',$checked='no',$action=NULL,$value='yes') + function CCheckBox($name='checkbox',$checked='no',$action=null,$value='yes') { parent::CTag('input','no'); $this->tag_body_start = ''; @@ -52,4 +52,106 @@ $this->options[$event] = $value; } } + + class CVisibilityBox extends CCheckBox + { + function CVisibilityBox($name='visibilitybox', $value='yes', $object_name=null, $replace_to=null) + { + $action = ''; + if(!is_array($object_name)) $object_name = array($object_name); + + $this->object_name = $object_name; + $this->replace_to = unpack_object($replace_to); + + foreach($this->object_name as $obj_name) + { + if(empty($obj_name)) continue; + $action .= 'visibility_status_changeds(this.checked, \''.$obj_name.'\','. + ' \''.zbx_jsstr($this->replace_to).'\'); '; + } + + parent::CCheckBox($name, $value, $action, '1'); + + $this->ShowJavascript(); + } + + function ToString($destroy=true) + { + global $ZBX_PAGE_POST_JS; + + if(!isset($this->options['checked'])) + { + foreach($this->object_name as $obj_name) + { + if(empty($obj_name)) continue; + zbx_add_post_js('visibility_status_changeds(false, "'.$obj_name.'", "'. + zbx_jsstr($this->replace_to).'");'); + } + } + + return parent::ToString($destroy); + } + + function ShowJavascript() + { + if(defined('CVISIBILITYBOX_JAVASCRIPT_INSERTED')) return; + define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); + +?> +<script language="JavaScript" type="text/javascript"> +<!-- + function visibility_status_changeds(value, obj_name, replace_to) + { + var obj = document.getElementsByName(obj_name); + + if(obj.length <= 0) throw "Can't find objects with name [" + obj_name +"]"; + + for(i = obj.length-1; i>=0; i--) + { + if(replace_to && replace_to != "") + { + if(obj[i].originalObject) + { + var old_obj = obj[i].originalObject; + old_obj.originalObject = obj[i]; + obj[i].parentNode.replaceChild(old_obj, obj[i]); + } + else if(!value) + { + var new_obj = null; + try { + new_obj = document.createElement("<a name='" + obj[i].name + "'>"); + } + catch(err) + { + new_obj = document.createElement("a"); + new_obj.name = obj[i].name; + } + + if(!new_obj) throw "Can't create new element"; + + new_obj.style.textDecoration = "none"; + new_obj.innerHTML = replace_to; + new_obj.originalObject = obj[i]; + obj[i].parentNode.replaceChild(new_obj, obj[i]); + } + else + { + throw "Missed originalObject for restoring"; + } + } + else + { + value = value ? 'visible' : 'hidden'; + obj[i].style.visibility = value; + } + } + + + } +--> +</script> +<?php + } + } ?> diff --git a/frontends/php/include/classes/cformtable.inc.php b/frontends/php/include/classes/cformtable.inc.php index cf203ef6..256ba583 100644 --- a/frontends/php/include/classes/cformtable.inc.php +++ b/frontends/php/include/classes/cformtable.inc.php @@ -96,11 +96,13 @@ unset($this->title); return 0; } - elseif(!is_string($value)) +/* elseif(!is_string($value)) { return $this->error("Incorrect value for SetTitle [$value]"); } $this->title = nbsp($value); + */ + $this->title = unpack_object($value); } function SetHelp($value=NULL) { diff --git a/frontends/php/include/classes/ctextbox.inc.php b/frontends/php/include/classes/ctextbox.inc.php index a61e4364..c1bd3134 100644 --- a/frontends/php/include/classes/ctextbox.inc.php +++ b/frontends/php/include/classes/ctextbox.inc.php @@ -65,7 +65,7 @@ class CNumericBox extends CTextBox { - function CNumericBox($name='password',$value='',$size=20,$readonly="no") + function CNumericBox($name='number',$value='0',$size=20,$readonly="no",$allowempty=false) { parent::CTextBox($name,$value,$size,$readonly); $this->AddOption('MaxLength', $size); @@ -74,7 +74,8 @@ ' var c = (window.event) ? event.keyCode : event.which;'. ' if(event.ctrlKey || c <= 31 || (c >= 48 && c <= 57)) return true; else return false; '); $this->AddOption('OnChange', - 'if(isNaN(parseInt(this.value))) this.value = 0; '. + ($allowempty ? ' if(this.value.length==0 || this.value==null) this.value = \'\'; else ' : ''). + ' if(isNaN(parseInt(this.value))) this.value = 0; '. ' else this.value = parseInt(this.value);' ); } diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 8f898817..96ec5ef0 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -147,6 +147,7 @@ function VDP($var, $msg=null) { echo "DEBUG DUMP: "; if(isset($msg)) echo '"'.$m function init_nodes() { /* Init CURRENT NODE ID */ + global $USER_DETAILS; global $ZBX_LOCALNODEID, $ZBX_LOCMASTERID; global $ZBX_CURNODEID, $ZBX_CURMASTERID; @@ -192,6 +193,36 @@ function VDP($var, $msg=null) { echo "DEBUG DUMP: "; if(isset($msg)) echo '"'.$m include_once "include/page_footer.php"; } + + /* function: + * zbx_jsstr + * + * description: + * convert PHP string variable to string + * for using in JavaScrip block. + * + * author: Eugene Grigorjev + */ + function zbx_jsstr($str) + { + return htmlspecialchars(str_replace("\n", '\n', str_replace("\r", '', $str))); + } + + /* function: + * zbx_add_post_js + * + * description: + * add JavaScript for calling after page loaging. + * + * author: Eugene Grigorjev + */ + function zbx_add_post_js($script) + { + global $ZBX_PAGE_POST_JS; + + $ZBX_PAGE_POST_JS[] = $script; + } + function zbx_stripslashes($value){ if(is_array($value)){ foreach($value as $id => $data) @@ -203,7 +234,7 @@ function VDP($var, $msg=null) { echo "DEBUG DUMP: "; if(isset($msg)) echo '"'.$m return $value; } - function get_request($name, $def){ + function get_request($name, $def=NULL){ global $_REQUEST; if(isset($_REQUEST[$name])) return $_REQUEST[$name]; @@ -520,7 +551,9 @@ else { global $page, $ZBX_MESSAGES; - if(!isset($page["type"])) $page["type"] = PAGE_TYPE_HTML; + if (! defined('PAGE_HEADER_LOADED')) return; + + if (!isset($page["type"])) $page["type"] = PAGE_TYPE_HTML; $message = array(); $width = 0; @@ -1265,7 +1298,13 @@ else return ($var == "" ? 0 : 1); } - function get_profile($idx,$default_value,$type=PROFILE_TYPE_UNCNOWN) + function empty2null($var) + { + return empty($var) ? null : $var; + } + + + function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNCNOWN) { global $USER_DETAILS; diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index e95d19ec..1c5898ad 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -53,9 +53,10 @@ define("O_NO", 2); define("P_SYS", 1); - define("P_USR", 2); - define("P_GET", 4); - define("P_POST", 8); + define("P_UNSET_EMPTY", 2); +// define("P_USR", 2); +// define("P_GET", 4); +// define("P_POST", 8); define("P_ACT", 16); define("P_NZERO", 32); diff --git a/frontends/php/include/events.inc.php b/frontends/php/include/events.inc.php index 6334725b..4a203249 100644 --- a/frontends/php/include/events.inc.php +++ b/frontends/php/include/events.inc.php @@ -44,7 +44,6 @@ " where ".DBid2nodeid("t.triggerid")."=".$nodeid. " and e.triggerid=t.triggerid and t.triggerid=f.triggerid and f.itemid=i.itemid ". " and i.hostid=h.hostid ".$sql_cond." and h.status=".HOST_STATUS_MONITORED. - " and h.hostid not in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE, PERM_MODE_LT).") ". " order by e.clock desc,h.host,t.priority,t.description,t.triggerid ", 10*($start+$num) ); @@ -53,9 +52,13 @@ $table->SetHeader(array(S_TIME, $hostid == 0 ? S_HOST : null, S_DESCRIPTION, S_VALUE, S_SEVERITY)); $col=0; + $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY); + $skip = $start; while(($row=DBfetch($result))&&($col<$num)) { + if(!check_right_on_trigger_by_triggerid(null, $row['triggerid'], $accessible_hosts)) continue; + if($skip > 0) { $skip--; diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 9d0f08b5..579938e9 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -60,8 +60,8 @@ $form = new CFormTable(S_SCENARIO, null, 'post'); $form->SetHelp("web.webmon.httpconf.php"); - if(isset($_request["groupid"])) - $form->addvar("groupid",$_request["groupid"]); + if(isset($_REQUEST["groupid"])) + $form->AddVar("groupid",$_REQUEST["groupid"]); $form->AddVar("hostid",$_REQUEST["hostid"]); @@ -879,6 +879,284 @@ return $table; } + function insert_item_selection_form() + { + global $ZBX_CURNODEID; + + if(isset($_REQUEST['form_refresh']) && isset($_REQUEST['select'])) + { + $selection_mode = get_request("selection_mode" ,0); + + $with_node = empty2null(get_request("with_node")); + $with_group = empty2null(get_request("with_group")); + $with_host = empty2null(get_request("with_host")); + $with_application = empty2null(get_request("with_application")); + $with_description = empty2null(get_request("with_description")); + $with_type = get_request("with_type" ,-1); + $with_key = empty2null(get_request("with_key")); + $with_snmp_community = empty2null(get_request("with_snmp_community")); + $with_snmp_oid = empty2null(get_request("with_snmp_oid")); + $with_snmp_port = empty2null(get_request("with_snmp_port")); + $with_snmpv3_securityname = empty2null(get_request("with_snmpv3_securityname")); + $with_snmpv3_securitylevel = get_request("with_snmpv3_securitylevel" ,-1); + $with_snmpv3_authpassphrase = empty2null(get_request("with_snmpv3_authpassphrase")); + $with_snmpv3_privpassphrase = empty2null(get_request("with_snmpv3_privpassphrase")); + $with_value_type = get_request("with_value_type" ,-1); + $with_units = empty2null(get_request("with_units")); + $with_formula = empty2null(get_request("with_formula")); + $with_delay = empty2null(get_request("with_delay")); + $with_history = empty2null(get_request("with_history")); + $with_trends = empty2null(get_request("with_trends")); + $with_status = empty2null(get_request("with_status")); + $with_logtimefmt = empty2null(get_request("with_logtimefmt")); + $with_delta = empty2null(get_request("with_delta")); + $with_trapper_hosts = empty2null(get_request("with_trapper_hosts")); + } + else + { + $selection_mode = get_request("selection_mode" ,get_profile("selection_mode", 0)); + + $with_node = empty2null(get_request("with_node" ,get_profile("with_node"))); + $with_group = empty2null(get_request("with_group" ,get_profile("with_group"))); + $with_host = empty2null(get_request("with_host" ,get_profile("with_host"))); + $with_application = empty2null(get_request("with_application" ,get_profile("with_application"))); + $with_description = empty2null(get_request("with_description" ,get_profile("with_description"))); + $with_type = get_request("with_type" ,get_profile("with_type", -1)); + $with_key = empty2null(get_request("with_key" ,get_profile("with_key"))); + $with_snmp_community = empty2null(get_request("with_snmp_community" ,get_profile("with_snmp_community"))); + $with_snmp_oid = empty2null(get_request("with_snmp_oid" ,get_profile("with_snmp_oid"))); + $with_snmp_port = empty2null(get_request("with_snmp_port" ,get_profile("with_snmp_port"))); + $with_snmpv3_securityname = empty2null(get_request("with_snmpv3_securityname" ,get_profile("with_snmpv3_securityname"))); + $with_snmpv3_securitylevel = get_request("with_snmpv3_securitylevel" ,get_profile("with_snmpv3_securitylevel", -1)); + $with_snmpv3_authpassphrase = empty2null(get_request("with_snmpv3_authpassphrase",get_profile("with_snmpv3_authpassphrase"))); + $with_snmpv3_privpassphrase = empty2null(get_request("with_snmpv3_privpassphrase",get_profile("with_snmpv3_privpassphrase"))); + $with_value_type = get_request("with_value_type" ,get_profile("with_value_type", -1)); + $with_units = empty2null(get_request("with_units" ,get_profile("with_units"))); + $with_formula = empty2null(get_request("with_formula" ,get_profile("with_formula"))); + $with_delay = empty2null(get_request("with_delay" ,get_profile("with_delay"))); + $with_history = empty2null(get_request("with_history" ,get_profile("with_history"))); + $with_trends = empty2null(get_request("with_trends" ,get_profile("with_trends"))); + $with_status = empty2null(get_request("with_status" ,get_profile("with_status"))); + $with_logtimefmt = empty2null(get_request("with_logtimefmt" ,get_profile("with_logtimefmt"))); + $with_delta = empty2null(get_request("with_delta" ,get_profile("with_delta"))); + $with_trapper_hosts = empty2null(get_request("with_trapper_hosts" ,get_profile("with_trapper_hosts"))); + } + + if($selection_mode == 0) + { + $with_node = null; + $with_group = null; + //$with_host = null; + $with_application = null; + //$with_description = null; + $with_type = -1; + //$with_key = null; + $with_snmp_community = null; + $with_snmp_oid = null; + $with_snmp_port = null; + $with_snmpv3_securityname = null; + $with_snmpv3_securitylevel = -1; + $with_snmpv3_authpassphrase = null; + $with_snmpv3_privpassphrase = null; + $with_value_type = -1; + $with_units = null; + $with_formula = null; + $with_delay = null; + $with_history = null; + $with_trends = null; + $with_status = null; + $with_logtimefmt = null; + $with_delta = null; + $with_trapper_hosts = null; + } + + update_profile("selection_mode" , $_REQUEST['selection_mode'] = $selection_mode); + + update_profile("with_node" , $_REQUEST['with_node'] = $with_node); + update_profile("with_group" , $_REQUEST['with_group'] = $with_group); + update_profile("with_host" , $_REQUEST['with_host'] = $with_host); + update_profile("with_application" , $_REQUEST['with_application'] = $with_application); + update_profile("with_description" , $_REQUEST['with_description'] = $with_description); + update_profile("with_type" , $_REQUEST['with_type'] = $with_type); + update_profile("with_key" , $_REQUEST['with_key'] = $with_key); + update_profile("with_snmp_community" , $_REQUEST['with_snmp_community'] = $with_snmp_community); + update_profile("with_snmp_oid" , $_REQUEST['with_snmp_oid'] = $with_snmp_oid); + update_profile("with_snmp_port" , $_REQUEST['with_snmp_port'] = $with_snmp_port); + update_profile("with_snmpv3_securityname" , $_REQUEST['with_snmpv3_securityname'] = $with_snmpv3_securityname); + update_profile("with_snmpv3_securitylevel" , $_REQUEST['with_snmpv3_securitylevel'] = $with_snmpv3_securitylevel); + update_profile("with_snmpv3_authpassphrase", $_REQUEST['with_snmpv3_authpassphrase'] = $with_snmpv3_authpassphrase); + update_profile("with_snmpv3_privpassphrase", $_REQUEST['with_snmpv3_privpassphrase'] = $with_snmpv3_privpassphrase); + update_profile("with_value_type" , $_REQUEST['with_value_type'] = $with_value_type); + update_profile("with_units" , $_REQUEST['with_units'] = $with_units); + update_profile("with_formula" , $_REQUEST['with_formula'] = $with_formula); + update_profile("with_delay" , $_REQUEST['with_delay'] = $with_delay); + update_profile("with_history" , $_REQUEST['with_history'] = $with_history); + update_profile("with_trends" , $_REQUEST['with_trends'] = $with_trends); + update_profile("with_status" , $_REQUEST['with_status'] = $with_status); + update_profile("with_logtimefmt" , $_REQUEST['with_logtimefmt'] = $with_logtimefmt); + update_profile("with_delta" , $_REQUEST['with_delta'] = $with_delta); + update_profile("with_trapper_hosts" , $_REQUEST['with_trapper_hosts'] = $with_trapper_hosts); + + $form = new CFormTable(S_ITEM_SELECTION); + $form->SetName('frmselection'); + + $form->AddVar('hostid',get_request('hostid')); + $form->AddVar('external_filter', 1); + + $form->SetTitle(S_ITEM_SELECTION,SPACE); + + $form->AddVar('selection_mode', $selection_mode); + + $modeLink = new CLink($selection_mode == 0 ? S_ADVENCED : S_SIMPLE, '#','action'); + $modeLink->SetAction('create_var(\''.$form->GetName().'\',\'selection_mode\','.($selection_mode == 0 ? 1 : 0).',true)'); + $form->AddRow(S_SELECTION_MODE,$modeLink); + + if(ZBX_DISTRIBUTED && $selection_mode) + { + $form->AddRow('from '.bold(S_NODE).' like', array( + new CTextBox('with_node',$with_node,32), + new CButton("btn_node",S_SELECT,"return PopUp('popup.php?dstfrm=".$form->GetName(). + "&dstfld1=with_node&srctbl=nodes&srcfld1=name',450,450);", + "G") + )); + } + + if($selection_mode) + { + $form->AddRow('from '.bold(S_HOST_GROUP).' like', array( + new CTextBox('with_group',$with_group,32), + new CButton("btn_group",S_SELECT,"return PopUp('popup.php?dstfrm=".$form->GetName(). + "&dstfld1=with_group&srctbl=host_group&srcfld1=name',450,450);", + "G") + )); + } + + $form->AddRow('from '.bold(S_HOST).' like',array( + new CTextBox('with_host',$with_host,32), + new CButton("btn_host",S_SELECT, + "return PopUp('popup.php?dstfrm=".$form->GetName(). + "&dstfld1=with_host&dstfld2=hostid&srctbl=hosts&srcfld1=host&srcfld2=hostid',450,450);", + 'H') + )); + + if($selection_mode) + { + $form->AddRow('from '.bold(S_APPLICATION).' like',array( + new CTextBox('with_application', $with_application, 32), + new CButton('btn_app',S_SELECT, + 'return PopUp("popup.php?dstfrm='.$form->GetName(). + '&dstfld1=with_application&srctbl=applications'. + '&srcfld1=name",400,300,"application");', + 'A') + )); + } + + $form->AddRow('with '.bold(S_DESCRIPTION).' like', new CTextBox("with_description",$with_description,40)); + + if($selection_mode) + { + $cmbType = new CComboBox("with_type",$with_type, "submit()"); + $cmbType->AddItem(-1, S_ALL); + foreach(array(ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, + ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_TRAPPER, + ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_HTTPTEST) as $it) + $cmbType->AddItem($it, item_type2str($it)); + $form->AddRow('with '.bold(S_TYPE), $cmbType); + } + + $form->AddRow('with '.bold(S_KEY).' like', array(new CTextBox("with_key",$with_key,40))); + + if($selection_mode) + { + if(($with_type==ITEM_TYPE_SNMPV1)||($with_type==ITEM_TYPE_SNMPV2C)||$with_type==ITEM_TYPE_SNMPV3) + { + $form->AddRow('with '.bold(S_SNMP_COMMUNITY).' like', + new CTextBox("with_snmp_community",$with_snmp_community,16)); + $form->AddRow('with '.bold(S_SNMP_OID).' like', + new CTextBox("with_snmp_oid",$with_snmp_oid,40)); + $form->AddRow('with '.bold(S_SNMP_PORT).' like', + new CNumericBox("with_snmp_port",$with_snmp_port,5,null,true)); + } + + if($with_type==ITEM_TYPE_SNMPV3) + { + $form->AddRow('with '.bold(S_SNMPV3_SECURITY_NAME).' like', + new CTextBox("with_snmpv3_securityname",$with_snmpv3_securityname,64)); + + $cmbSecLevel = new CComboBox("with_snmpv3_securitylevel",$with_snmpv3_securitylevel); + $cmbSecLevel->AddItem(-1,S_ALL); + $cmbSecLevel->AddItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV,"NoAuthPriv"); + $cmbSecLevel->AddItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV,"AuthNoPriv"); + $cmbSecLevel->AddItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV,"AuthPriv"); + $form->AddRow('with '.bold(S_SNMPV3_SECURITY_LEVEL), $cmbSecLevel); + + $form->AddRow('with '.bold(S_SNMPV3_AUTH_PASSPHRASE).' like', + new CTextBox("with_snmpv3_authpassphrase",$with_snmpv3_authpassphrase,64)); + + $form->AddRow('with '.bold(S_SNMPV3_PRIV_PASSPHRASE).' like', + new CTextBox("with_snmpv3_privpassphrase",$with_snmpv3_privpassphrase,64)); + } + + + $cmbValType = new CComboBox("with_value_type",$with_value_type,"submit()"); + $cmbValType->AddItem(-1, S_ALL); + $cmbValType->AddItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UINT64); + $cmbValType->AddItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT); + $cmbValType->AddItem(ITEM_VALUE_TYPE_STR, S_CHARACTER); + $cmbValType->AddItem(ITEM_VALUE_TYPE_LOG, S_LOG); + $cmbValType->AddItem(ITEM_VALUE_TYPE_TEXT, S_TEXT); + $form->AddRow('with '.bold(S_TYPE_OF_INFORMATION),$cmbValType); + + if( ($with_value_type==ITEM_VALUE_TYPE_FLOAT) || ($with_value_type==ITEM_VALUE_TYPE_UINT64)) + { + $form->AddRow('with '.bold(S_UNITS), new CTextBox("with_units",$with_units,40)); + $form->AddRow('with '.bold(S_CUSTOM_MULTIPLIER).' like', new CTextBox("with_formula",$with_formula,40)); + } + + if($with_type != ITEM_TYPE_TRAPPER && $with_type != ITEM_TYPE_HTTPTEST) + { + $form->AddRow('with '.bold(S_UPDATE_INTERVAL_IN_SEC), + new CNumericBox("with_delay",$with_delay,5,null,true)); + } + + $form->AddRow('with '.bold(S_KEEP_HISTORY_IN_DAYS), + new CNumericBox("with_history",$with_history,8,null,true)); + + $form->AddRow('with '.bold(S_KEEP_TRENDS_IN_DAYS), new CNumericBox("with_trends",$with_trends,8,null,true)); + + $cmbStatus = new CComboBox("with_status",$with_status); + $cmbStatus->AddItem(-1,S_ALL); + foreach(array(ITEM_STATUS_ACTIVE,ITEM_STATUS_DISABLED,ITEM_STATUS_NOTSUPPORTED) as $st) + $cmbStatus->AddItem($st,item_status2str($st)); + $form->AddRow('with '.bold(S_STATUS),$cmbStatus); + + if($with_value_type==ITEM_VALUE_TYPE_LOG) + { + $form->AddRow('with '.bold(S_LOG_TIME_FORMAT), new CTextBox("with_logtimefmt",$with_logtimefmt,16)); + } + + if( ($with_value_type==ITEM_VALUE_TYPE_FLOAT) || ($with_value_type==ITEM_VALUE_TYPE_UINT64)) + { + $cmbDelta= new CComboBox("with_delta",$with_delta); + $cmbDelta->AddItem(-1,S_ALL); + $cmbDelta->AddItem(0,S_AS_IS); + $cmbDelta->AddItem(1,S_DELTA_SPEED_PER_SECOND); + $cmbDelta->AddItem(2,S_DELTA_SIMPLE_CHANGE); + $form->AddRow('with '.bold(S_STORE_VALUE),$cmbDelta); + } + + if($with_type==ITEM_TYPE_TRAPPER) + { + $form->AddRow('with '.bold(S_ALLOWED_HOSTS).' like', new CTextBox("with_trapper_hosts",$with_trapper_hosts,40)); + } + } + + $form->AddItemToBottomRow(array( + new CButton('select',S_SEARCH), + new CButton('cancel',S_CANCEL))); + + $form->Show(); + } # Insert form for Item information function insert_item_form() @@ -887,12 +1165,12 @@ global $USER_DETAILS; global $ZBX_CURNODEID; - $frmItem = new CFormTable(S_ITEM,"items.php"); + $frmItem = new CFormTable(S_ITEM); $frmItem->SetHelp("web.items.item.php"); $frmItem->AddVar("config",get_request("config",0)); - if(isset($_request["groupid"])) - $frmitem->addvar("groupid",$_request["groupid"]); + if(isset($_REQUEST["groupid"])) + $frmItem->AddVar("groupid",$_REQUEST["groupid"]); $frmItem->AddVar("hostid",$_REQUEST["hostid"]); @@ -1332,6 +1610,208 @@ $frmItem->Show(); } + function insert_mass_update_item_form($elements_array_name) + { + global $_REQUEST; + global $USER_DETAILS; + global $ZBX_CURNODEID; + + $frmItem = new CFormTable(S_ITEM,null,'post'); + $frmItem->SetHelp("web.items.item.php"); + $frmItem->SetTitle(S_MASS_UPDATE); + + $frmItem->AddVar("form_mass_update",1); + + $frmItem->AddVar("group_itemid",get_request("group_itemid",array())); + $frmItem->AddVar("config",get_request("config",0)); + if(isset($_REQUEST["groupid"])) + $frmItem->AddVar("groupid",$_REQUEST["groupid"]); + + $frmItem->AddVar("hostid",$_REQUEST["hostid"]); + + $description = get_request("description" ,""); + $key = get_request("key" ,""); + $host = get_request("host", null); + $delay = get_request("delay" ,30); + $history = get_request("history" ,90); + $status = get_request("status" ,0); + $type = get_request("type" ,0); + $snmp_community = get_request("snmp_community" ,"public"); + $snmp_oid = get_request("snmp_oid" ,"interfaces.ifTable.ifEntry.ifInOctets.1"); + $snmp_port = get_request("snmp_port" ,161); + $value_type = get_request("value_type" ,ITEM_VALUE_TYPE_UINT64); + $trapper_hosts = get_request("trapper_hosts" ,""); + $units = get_request("units" ,''); + $valuemapid = get_request("valuemapid" ,0); + $multiplier = get_request("multiplier" ,0); + $delta = get_request("delta" ,0); + $trends = get_request("trends" ,365); + $applications = get_request("applications" ,array()); + $delay_flex = get_request("delay_flex" ,array()); + + $snmpv3_securityname = get_request("snmpv3_securityname" ,""); + $snmpv3_securitylevel = get_request("snmpv3_securitylevel" ,0); + $snmpv3_authpassphrase = get_request("snmpv3_authpassphrase" ,""); + $snmpv3_privpassphrase = get_request("snmpv3_privpassphrase" ,""); + + $formula = get_request("formula" ,"1"); + $logtimefmt = get_request("logtimefmt" ,""); + + $add_groupid = get_request("add_groupid" ,get_request("groupid",0)); + + $delay_flex_el = array(); + + $i = 0; + foreach($delay_flex as $val) + { + if(!isset($val["delay"]) && !isset($val["period"])) continue; + + array_push($delay_flex_el, + array( + new CCheckBox("rem_delay_flex[]", 'no', null,$i), + $val["delay"], + " sec at ", + $val["period"] + ), + BR); + $frmItem->AddVar("delay_flex[".$i."][delay]", $val['delay']); + $frmItem->AddVar("delay_flex[".$i."][period]", $val['period']); + $i++; + if($i >= 7) break; /* limit count of intervals + * 7 intervals by 30 symbols = 210 characters + * db storage field is 256 + */ + } + + if(count($delay_flex_el)==0) + array_push($delay_flex_el, "No flexible intervals"); + else + array_push($delay_flex_el, new CButton('del_delay_flex','delete selected')); + + if(count($applications)==0) array_push($applications,0); + + $cmbType = new CComboBox('type',$type); + $cmbType->AddItem(ITEM_TYPE_ZABBIX,S_ZABBIX_AGENT); + $cmbType->AddItem(ITEM_TYPE_ZABBIX_ACTIVE,S_ZABBIX_AGENT_ACTIVE); + $cmbType->AddItem(ITEM_TYPE_SIMPLE,S_SIMPLE_CHECK); + $cmbType->AddItem(ITEM_TYPE_SNMPV1,S_SNMPV1_AGENT); + $cmbType->AddItem(ITEM_TYPE_SNMPV2C,S_SNMPV2_AGENT); + $cmbType->AddItem(ITEM_TYPE_SNMPV3,S_SNMPV3_AGENT); + $cmbType->AddItem(ITEM_TYPE_TRAPPER,S_ZABBIX_TRAPPER); + $cmbType->AddItem(ITEM_TYPE_INTERNAL,S_ZABBIX_INTERNAL); + $cmbType->AddItem(ITEM_TYPE_AGGREGATE,S_ZABBIX_AGGREGATE); + $frmItem->AddRow(array( new CVisibilityBox('type_visible', get_request('type_visible'), 'type', S_ORIGINAL), + S_TYPE), $cmbType); + + $frmItem->AddRow(array( new CVisibilityBox('community_visible', get_request('community_visible'), 'snmp_community', S_ORIGINAL), + S_SNMP_COMMUNITY), new CTextBox('snmp_community',$snmp_community,16)); + + $frmItem->AddRow(array( new CVisibilityBox('securityname_visible', get_request('securityname_visible'), 'snmpv3_securityname', + S_ORIGINAL), S_SNMPV3_SECURITY_NAME), new CTextBox('snmpv3_securityname',$snmpv3_securityname,64)); + + $cmbSecLevel = new CComboBox('snmpv3_securitylevel',$snmpv3_securitylevel); + $cmbSecLevel->AddItem(ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV,"NoAuthPriv"); + $cmbSecLevel->AddItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV,"AuthNoPriv"); + $cmbSecLevel->AddItem(ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV,"AuthPriv"); + $frmItem->AddRow(array( new CVisibilityBox('securitylevel_visible', get_request('securitylevel_visible'), 'snmpv3_securitylevel', + S_ORIGINAL), S_SNMPV3_SECURITY_LEVEL), $cmbSecLevel); + $frmItem->AddRow(array( new CVisibilityBox('authpassphrase_visible', get_request('authpassphrase_visible'), + 'snmpv3_authpassphrase', S_ORIGINAL), S_SNMPV3_AUTH_PASSPHRASE), + new CTextBox('snmpv3_authpassphrase',$snmpv3_authpassphrase,64)); + + $frmItem->AddRow(array( new CVisibilityBox('privpassphras_visible', get_request('privpassphras_visible'), 'snmpv3_privpassphrase', + S_ORIGINAL), S_SNMPV3_PRIV_PASSPHRASE), new CTextBox('snmpv3_privpassphrase',$snmpv3_privpassphrase,64)); + + $frmItem->AddRow(array( new CVisibilityBox('port_visible', get_request('port_visible'), 'snmp_port', S_ORIGINAL), S_SNMP_PORT), + new CNumericBox('snmp_port',$snmp_port,5)); + + $cmbValType = new CComboBox('value_type',$value_type); + $cmbValType->AddItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UINT64); + $cmbValType->AddItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT); + $cmbValType->AddItem(ITEM_VALUE_TYPE_STR, S_CHARACTER); + $cmbValType->AddItem(ITEM_VALUE_TYPE_LOG, S_LOG); + $cmbValType->AddItem(ITEM_VALUE_TYPE_TEXT, S_TEXT); + $frmItem->AddRow(array( new CVisibilityBox('value_type_visible', get_request('value_type_visible'), 'value_type', S_ORIGINAL), + S_TYPE_OF_INFORMATION), $cmbValType); + + $frmItem->AddRow(array( new CVisibilityBox('units_visible', get_request('units_visible'), 'units', S_ORIGINAL), S_UNITS), + new CTextBox('units',$units,40)); + + $frmItem->AddRow(array( new CVisibilityBox('formula_visible', get_request('formula_visible'), 'formula', S_ORIGINAL), + S_CUSTOM_MULTIPLIER), new CTextBox('formula',$formula,40)); + + $frmItem->AddRow(array( new CVisibilityBox('delay_visible', get_request('delay_visible'), 'delay', S_ORIGINAL), + S_UPDATE_INTERVAL_IN_SEC), new CNumericBox('delay',$delay,5)); + + $delay_flex_el = new CTag('a', 'yes', $delay_flex_el); + $delay_flex_el->AddOption('name', 'delay_flex_list'); + $delay_flex_el->AddOption('style', 'text-decoration: none'); + $frmItem->AddRow(array( new CVisibilityBox('delay_flex_visible', get_request('delay_flex_visible'), + array('delay_flex_list', 'new_delay_flex_el'), S_ORIGINAL), S_FLEXIBLE_INTERVALS), $delay_flex_el); + $new_delay_flex_el = new CTag('a', 'yes', + array( + S_DELAY, SPACE, + new CNumericBox("new_delay_flex[delay]","50",5), + S_PERIOD, SPACE, + new CTextBox("new_delay_flex[period]","1-7,00:00-23:59",27), BR, + new CButton("add_delay_flex",S_ADD) + )); + $new_delay_flex_el->AddOption('name', 'new_delay_flex_el'); + $new_delay_flex_el->AddOption('style', 'text-decoration: none'); + $frmItem->AddRow(S_NEW_FLEXIBLE_INTERVAL, $new_delay_flex_el); + + $frmItem->AddRow(array( new CVisibilityBox('history_visible', get_request('history_visible'), 'history', S_ORIGINAL), + S_KEEP_HISTORY_IN_DAYS), new CNumericBox('history',$history,8)); + $frmItem->AddRow(array( new CVisibilityBox('trends_visible', get_request('trends_visible'), 'trends', S_ORIGINAL), + S_KEEP_TRENDS_IN_DAYS), new CNumericBox('trends',$trends,8)); + + $cmbStatus = new CComboBox('status',$status); + foreach(array(ITEM_STATUS_ACTIVE,ITEM_STATUS_DISABLED,ITEM_STATUS_NOTSUPPORTED) as $st) + $cmbStatus->AddItem($st,item_status2str($st)); + $frmItem->AddRow(array( new CVisibilityBox('status_visible', get_request('status_visible'), 'status', S_ORIGINAL), S_STATUS), + $cmbStatus); + + $frmItem->AddRow(array( new CVisibilityBox('logtimefmt_visible', get_request('logtimefmt_visible'), 'logtimefmt', S_ORIGINAL), + S_LOG_TIME_FORMAT), new CTextBox("logtimefmt",$logtimefmt,16)); + + $cmbDelta= new CComboBox('delta',$delta); + $cmbDelta->AddItem(0,S_AS_IS); + $cmbDelta->AddItem(1,S_DELTA_SPEED_PER_SECOND); + $cmbDelta->AddItem(2,S_DELTA_SIMPLE_CHANGE); + $frmItem->AddRow(array( new CVisibilityBox('delta_visible', get_request('delta_visible'), 'delta', S_ORIGINAL), + S_STORE_VALUE),$cmbDelta); + + $cmbMap = new CComboBox('valuemapid',$valuemapid); + $cmbMap->AddItem(0,S_AS_IS); + $db_valuemaps = DBselect("select * from valuemaps where ".DBid2nodeid("valuemapid")."=".$ZBX_CURNODEID); + while($db_valuemap = DBfetch($db_valuemaps)) + $cmbMap->AddItem($db_valuemap["valuemapid"],$db_valuemap["name"]); + + $link = new CLink("throw map","config.php?config=6","action"); + $link->AddOption("target","_blank"); + $frmItem->AddRow(array( new CVisibilityBox('valuemapid_visible', get_request('valuemapid_visible'), 'valuemapid', S_ORIGINAL), + S_SHOW_VALUE, SPACE, $link),$cmbMap); + + $frmItem->AddRow(array( new CVisibilityBox('trapper_hosts_visible', get_request('trapper_hosts_visible'), 'trapper_hosts', + S_ORIGINAL), S_ALLOWED_HOSTS), new CTextBox('trapper_hosts',$trapper_hosts,40)); + + $cmbApps = new CListBox('applications[]',$applications,6); + $cmbApps->AddItem(0,"-".S_NONE."-"); + $db_applications = DBselect("select distinct applicationid,name from applications". + " where hostid=".$_REQUEST["hostid"]." order by name"); + while($db_app = DBfetch($db_applications)) + { + $cmbApps->AddItem($db_app["applicationid"],$db_app["name"]); + } + $frmItem->AddRow(array( new CVisibilityBox('applications_visible', get_request('applications_visible'), 'applications[]', + S_ORIGINAL), S_APPLICATIONS),$cmbApps); + + $frmItem->AddItemToBottomRow(array(new CButton("update",S_UPDATE), + SPACE, new CButtonCancel(url_param("groupid").url_param("hostid").url_param("config")))); + + $frmItem->Show(); + } + function insert_copy_elements_to_forms($elements_array_name) { diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index bb1f503d..4bcd8f2a 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -548,10 +548,13 @@ require_once "include/items.inc.php"; if($_REQUEST["groupid"] == -1) { - if($_REQUEST["hostid"] > 0) - $_REQUEST["groupid"] = 0; - else - $_REQUEST["groupid"] = get_profile($group_var,0); + $_REQUEST["groupid"] = get_profile($group_var,0); + + if ($_REQUEST["hostid"] > 0 && !DBfetch(DBselect('select groupid from hosts_groups '. + ' where hostid='.$_REQUEST["hostid"].' and groupid='.$_REQUEST["groupid"]))) + { + $_REQUEST["groupid"] = 0; + } } // SDI("ig:".$_REQUEST["groupid"]); diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 4f880ed1..65128904 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -382,6 +382,63 @@ return $result; } + function smart_update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type, + $snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta, + $snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase, + $formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications) + { + $restore_rules= array( + "description" => array(), + "key" => array( 'db_varname' => 'key_' ), + "hostid" => array(), + "delay" => array('template' => 1), + "history" => array('template' => 1 , 'httptest' => 1), + "status" => array('template' => 1 , 'httptest' => 1), + "type" => array(), + "snmp_community" => array(), + "snmp_oid" => array(), + "value_type" => array(), + "trapper_hosts" => array(), + "snmp_port" => array(), + "units" => array(), + "multiplier" => array(), + "delta" => array('template' => 1 , 'httptest' => 1), + "snmpv3_securityname" => array(), + "snmpv3_securitylevel" => array(), + "snmpv3_authpassphrase" => array(), + "snmpv3_privpassphrase" => array(), + "formula" => array(), + "trends" => array('template' => 1 , 'httptest' => 1), + "logtimefmt" => array(), + "valuemapid" => array('httptest' => 1), + "delay_flex" => array()); + + $item_data = get_item_by_itemid($itemid); + + foreach($restore_rules as $var_name => $info) + { + if (!isset($info['db_varname'])) $info['db_varname'] = $var_name; + + if ($item_data['type'] == ITEM_TYPE_HTTPTEST && !isset($info['httptest'])) + $$var_name = $item_data[$info['db_varname']]; + if (0 !=$item_data['templateid'] && !isset($info['template'])) + $$var_name = $item_data[$info['db_varname']]; + if(!isset($$var_name)) + $$var_name = $item_data[$info['db_varname']]; + } + + return update_item($itemid, + $description,$key,$hostid,$delay, + $history,$status,$type, + $snmp_community,$snmp_oid,$value_type, + $trapper_hosts,$snmp_port,$units, + $multiplier,$delta,$snmpv3_securityname, + $snmpv3_securitylevel,$snmpv3_authpassphrase, + $snmpv3_privpassphrase,$formula,$trends, + $logtimefmt,$valuemapid,$delay_flex,$applications, + $item_data['templateid']); + } + function delete_template_items($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $db_items = get_items_by_hostid($hostid); diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index a6ccb103..e629475f 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -121,6 +121,7 @@ "S_CANNOT_ADD_NODE"=> "Cannot add node", "S_NODE_DELETED"=> "Node deleted", "S_CANNOT_DELETE_NODE"=> "Cannot delete node", + "S_CURRENT_NODE"=> "Current node", // acknow.php "S_ACKNOWLEDGES"=> "Acknowledges", @@ -393,6 +394,7 @@ "S_CONFIGURATION_OF_GRAPH_BIG"=> "CONFIGURATION OF GRAPH", "S_ITEM_ADDED"=> "Item added", "S_ITEM_UPDATED"=> "Item updated", + "S_ITEMS_UPDATED"=> "Items updated", "S_SORT_ORDER_UPDATED"=> "Sort order updated", "S_CANNOT_UPDATE_SORT_ORDER"=> "Cannot update sort order", "S_DISPLAYED_PARAMETERS_BIG"=> "DISPLAYED PARAMETERS", @@ -663,6 +665,16 @@ "S_SHOW_DISABLED_ITEMS"=> "Show disabled items", "S_HIDE_DISABLED_ITEMS"=> "Hide disabled items", "S_HISTORY_CLEANING_CAN_TAKE_A_LONG_TIME_CONTINUE_Q" => "History cleaning can take a long time. Continue?", + "S_ITEM_SELECTION"=> "Item selection", + "S_SELECTION_MODE"=> "Selection mode", + "S_ADVENCED"=> "Advenced", + "S_SIMPLE"=> "Simple", + "S_MASS_UPDATE"=> "Mass update", + "S_SEARCH"=> "Search", + "S_EXTERNAL_FILER"=> "External filer", + "S_ORIGINAL"=> "Original", + "S_NEW_FLEXIBLE_INTERVAL"=> "New flexible interval", + "S_FLEXIBLE_INTERVALS"=> "Flexible intervals (sec)", // events.php "S_LATEST_EVENTS"=> "Latest events", diff --git a/frontends/php/include/page_footer.php b/frontends/php/include/page_footer.php index 055ef415..dc4df95f 100644 --- a/frontends/php/include/page_footer.php +++ b/frontends/php/include/page_footer.php @@ -23,11 +23,35 @@ global $USER_DETAILS; global $page; + global $ZBX_PAGE_POST_JS; + + if(!defined('PAGE_HEADER_LOADED')) + { + define ('PAGE_HEADER_LOADED', 1); + } show_messages(); if($page['type'] == PAGE_TYPE_HTML) { +?> +<script language="JavaScript" type="text/javascript"> +<!-- +function zbxCallPostScripts() +{ +<?php + if(isset($ZBX_PAGE_POST_JS)) + { + foreach($ZBX_PAGE_POST_JS as $script) + { + echo $script."\n"; + } + } +?> +} +--> +</script> +<?php if(!defined('ZBX_PAGE_NO_MENU') && !defined('ZBX_PAGE_NO_FOOTER')) { diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php index e2928025..297223cc 100644 --- a/frontends/php/include/page_header.php +++ b/frontends/php/include/page_header.php @@ -240,7 +240,7 @@ COpt::profiling_start("page"); { $deny = true; } - elseif(!in_array($ZBX_CURNODEID, get_accessible_nodes_by_user( + elseif($label!='login' && !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user( $USER_DETAILS,PERM_READ_LIST,null, PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))) { @@ -335,10 +335,12 @@ COpt::profiling_start("page"); <link rel="stylesheet" href="css.css"> <meta name="Author" content="ZABBIX SIA"> </head> -<body> +<body onLoad="zbxCallPostScripts();"> <?php } + define ('PAGE_HEADER_LOADED', 1); + if(!defined('ZBX_PAGE_NO_MENU')) { COpt::compare_files_with_menu($ZBX_MENU); @@ -367,6 +369,8 @@ COpt::compare_files_with_menu($ZBX_MENU); $menu_table->SetCellPadding(5); $menu_table->AddRow($main_menu_row); + $node_form = null; + if(ZBX_DISTRIBUTED) { $lst_nodes = new CComboBox('switch_node', $ZBX_CURNODEID); @@ -378,15 +382,14 @@ COpt::compare_files_with_menu($ZBX_MENU); $lst_nodes->AddItem($node_data['nodeid'],$node_data['name']); } - $node_form = new CForm(); - $node_form->AddItem('Current node ['.$ZBX_CURNODEID.'] '); - $node_form->AddItem($lst_nodes); - unset($lst_nodes); - $node_form->AddItem(new CButton('submit',S_SWITCH)); - } - else - { - $node_form = null; + if($lst_nodes->ItemsCount()) + { + $node_form = new CForm(); + $node_form->AddItem(S_CURRENT_NODE.' ['.$ZBX_CURNODEID.'] '); + $node_form->AddItem($lst_nodes); + unset($lst_nodes); + $node_form->AddItem(new CButton('submit',S_SWITCH)); + } } $table = new CTable(); @@ -429,4 +432,6 @@ COpt::compare_files_with_menu($ZBX_MENU); } unset($tmezone); } + + show_messages(); ?> diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php index 69fd38e8..f90dd714 100644 --- a/frontends/php/include/perm.inc.php +++ b/frontends/php/include/perm.inc.php @@ -165,24 +165,14 @@ COpt::counter_up('perm'); if(count($where)) $where = ' where '.implode(' and ',$where); else $where = ''; - /*$db_hosts = DBselect('select distinct n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission '. - ' from users_groups ug '. - ' left join rights r on r.groupid=ug.usrgrpid and r.type='.RESOURCE_TYPE_GROUP.' and ug.userid='.$userid. - ' right join groups g on r.id=g.groupid '. - ' left join hosts_groups hg on g.groupid=hg.groupid '. - ' right join hosts h on hg.hostid=h.hostid '. - ' left join nodes n on '.DBid2nodeid('h.hostid').'=n.nodeid '. - $where.' group by h.hostid'. - ' order by n.name,n.nodeid, g.name, h.host');*/ - - $db_hosts = DBselect('select distinct n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission '. + $db_hosts = DBselect('select distinct n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission,ug.userid '. ' from hosts h left join hosts_groups hg on hg.hostid=h.hostid '. ' left join groups g on g.groupid=hg.groupid '. ' left join rights r on r.id=g.groupid and r.type='.RESOURCE_TYPE_GROUP. ' left join users_groups ug on ug.userid='.$userid. ' left join nodes n on '.DBid2nodeid('h.hostid').'=n.nodeid '. - $where.' group by h.hostid,n.nodeid,n.name,h.host '. - ' order by n.name,n.nodeid, h.host'); + $where.' group by h.hostid,n.nodeid,n.name,h.host,ug.userid '. + ' order by n.name,n.nodeid, h.host, permission desc'); while($host_data = DBfetch($db_hosts)) { @@ -191,7 +181,7 @@ COpt::counter_up('perm'); if(is_null($host_data['nodeid'])) $host_data['nodeid'] = id2nodeid($host_data['hostid']); /* if no rights defined used node rights */ - if(is_null($host_data['permission'])) + if(is_null($host_data['permission']) || is_null($host_data['userid'])) { if(!isset($nodes)) { @@ -251,33 +241,26 @@ COpt::counter_up('perm'); else $where = ''; /* if no rights defined used node rights */ - /*$db_groups = DBselect('select n.nodeid,n.name as node_name,hg.groupid,hg.name, min(r.permission) as permission '. - ' from users_groups g '. - ' left join rights r on r.groupid=g.usrgrpid and r.type='.RESOURCE_TYPE_GROUP.' and g.userid='.$userid. - ' right join groups hg on r.id=hg.groupid '. - ' left join nodes n on '.DBid2nodeid('hg.groupid').'=n.nodeid '. - $where.' group by hg.groupid, hg.name, g.userid '. - ' order by n.name, hg.name');*/ - - $db_groups = DBselect('select n.nodeid as nodeid,n.name as node_name,hg.groupid,hg.name, min(r.permission) as permission '. + $db_groups = DBselect('select n.nodeid as nodeid,n.name as node_name,hg.groupid,hg.name,min(r.permission) as permission,g.userid'. ' from groups hg left join rights r on r.id=hg.groupid and r.type='.RESOURCE_TYPE_GROUP. ' left join users_groups g on r.groupid=g.usrgrpid and g.userid='.$userid. ' left join nodes n on '.DBid2nodeid('hg.groupid').'=n.nodeid '. - $where.' group by n.nodeid, n.name, hg.groupid, hg.name, g.userid '. - ' order by n.name, hg.name'); + $where.' group by n.nodeid, n.name, hg.groupid, hg.name, g.userid, g.userid '. + ' order by n.name, hg.name, permission desc'); while($group_data = DBfetch($db_groups)) { if(is_null($group_data['nodeid'])) $group_data['nodeid'] = id2nodeid($group_data['groupid']); /* deny if no rights defined */ - if(is_null($group_data['permission'])) + if(is_null($group_data['permission']) || is_null($group_data['userid'])) { if(!isset($nodes)) { $nodes = get_accessible_nodes_by_user($user_data, PERM_DENY,PERM_MODE_GE,PERM_RES_DATA_ARRAY); } + if(!isset($nodes[$group_data['nodeid']])) $group_data['permission'] = PERM_DENY; else @@ -327,16 +310,11 @@ COpt::counter_up('perm'); else if(is_array($nodeid)) $where_nodeid = ' where n.nodeid in ('.implode(',', $nodeid).') '; else $where_nodeid = ' where n.nodeid in ('.$nodeid.') '; - /*$db_nodes = DBselect('select n.nodeid,n.name,min(r.permission) as permission'. - ' from users_groups g left join rights r on r.groupid=g.usrgrpid and'. - ' r.type='.RESOURCE_TYPE_NODE.' and g.userid='.$userid. - ' right join nodes n on r.id=n.nodeid'.$where_nodeid. - ' group by n.nodeid');*/ - $db_nodes = DBselect('select n.nodeid,min(r.permission) as permission'. + $db_nodes = DBselect('select n.nodeid,min(r.permission) as permission, g.userid'. ' from nodes n left join rights r on r.id=n.nodeid and r.type='.RESOURCE_TYPE_NODE. ' left join users_groups g on r.groupid=g.usrgrpid and g.userid='.$userid. - $where_nodeid.' group by n.nodeid'); + $where_nodeid.' group by n.nodeid, g.userid order by nodeid desc, userid desc, permission desc'); while(($node_data = DBfetch($db_nodes)) || (!isset($do_break) && !ZBX_DISTRIBUTED)) { @@ -345,6 +323,8 @@ COpt::counter_up('perm'); $node_data += DBfetch(DBselect('select * from nodes where nodeid='.$node_data['nodeid'])); } + if($node_data && isset($processed_nodeids[$node_data["nodeid"]])) continue; + if(!ZBX_DISTRIBUTED) { if(!$node_data) @@ -366,8 +346,10 @@ COpt::counter_up('perm'); } } + $processed_nodeids[$node_data["nodeid"]] = $node_data["nodeid"]; + /* deny if no rights defined (for local node read/write)*/ - if(is_null($node_data['permission'])) + if(is_null($node_data['permission']) || is_null($node_data['userid'])) { if($user_type == USER_TYPE_SUPER_ADMIN) $node_data['permission'] = PERM_READ_WRITE; diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 7b605bf8..c43ef729 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -122,35 +122,12 @@ $state='HOST'; continue; } - - if($expression[$i] == '}' && $state=="") - { - $state=''; - $hosts[$host] = '\''.$host.'\''; - continue; - } - if($expression[$i] == '(' && $state == "FUNCTION") - { - $state='PARAMETER'; - continue; - } - - if($expression[$i] == ')' && $state == "PARAMETER") - { - $state=''; - continue; - } - if($expression[$i] == ':' && $state == "HOST") { - $state="KEY"; - continue; - } - - if($expression[$i] == '.' && ($state == "KEY" || $state == "FUNCTION")) - { - $state="FUNCTION"; + $state=""; + $hosts[$host] = '\''.$host.'\''; + $host = ''; continue; } @@ -159,11 +136,9 @@ $host .= $expression[$i]; continue; } - if($state == "KEY" || $state == "FUNCTION" || $state == "PARAMETER") - continue; } - if(count($hosts) == 0) $hosts = array(''); + if(count($hosts) == 0) $hosts = array('0'); return DBselect('select distinct * from hosts where '.DBid2nodeid('hostid').'='.$ZBX_CURNODEID. ' and host in ('.implode(',',$hosts).')'); @@ -891,16 +866,31 @@ return $result; } - function check_right_on_trigger($permission,$triggerid) /* TODO */ + function check_right_on_trigger_by_triggerid($permission,$triggerid,$accessible_hosts=null) { - /* - $result=DBselect("select distinct h.hostid from functions f,items i,hosts h". - " where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid"); - while($row=DBfetch($result)) - if(check_right("Host",$permission,$row["hostid"])) - return 1; - */ - return 0; + $trigger_data = DBfetch(DBselect('select expression from triggers where triggerid='.$triggerid)); + + if(!$trigger_data) return false; + + return check_right_on_trigger_by_expression($permission, explode_exp($trigger_data['expression'], 0), $accessible_hosts); + } + + function check_right_on_trigger_by_expression($permission,$expression,$accessible_hosts=null) + { + if(is_null($accessible_hosts)) + { + global $USER_DETAILS; + $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, $permission, null, PERM_RES_IDS_ARRAY); + } + if(!is_array($accessible_hosts)) $accessible_hosts = explode(',', $accessible_hosts); + + $db_hosts = get_hosts_by_expression($expression); + while($host_data = DBfetch($db_hosts)) + { + if(!in_array($host_data['hostid'], $accessible_hosts)) return false; + } + + return true; } function delete_dependencies_by_triggerid($triggerid) diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php index 51587261..b5a7ba3f 100644 --- a/frontends/php/include/validate.inc.php +++ b/frontends/php/include/validate.inc.php @@ -266,6 +266,11 @@ if($type == T_ZBX_IP) $validation = BETWEEN(0,255); + 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; |
