From 28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89 Mon Sep 17 00:00:00 2001 From: osmiy Date: Mon, 23 Oct 2006 07:34:27 +0000 Subject: - developed group permission system (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@3371 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- frontends/php/items.php | 258 +++++++++++++++++++++++------------------------- 1 file changed, 126 insertions(+), 132 deletions(-) (limited to 'frontends/php/items.php') diff --git a/frontends/php/items.php b/frontends/php/items.php index f943244e..b551b71d 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -19,25 +19,18 @@ **/ ?> +include_once "include/page_header.php"; -".S_NO_PERMISSIONS.""); - show_page_footer(); - exit; - } + insert_confirm_javascript(); ?> - + $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,null,null,$ZBX_CURNODEID); - - [Success for '$hosts_ok']
". - "[Failed for '$hosts_notok'","Cannot add item"); - unset($_REQUEST["itemid"]); - } -*/ } elseif(isset($_REQUEST["group_task"])&&isset($_REQUEST["group_itemid"])) { if($_REQUEST["group_task"]=="Delete selected") { + $result = false; + $group_itemid = $_REQUEST["group_itemid"]; foreach($group_itemid as $id) { - $item = get_item_by_itemid($id); + if(!($item = get_item_by_itemid($id))) continue; if($item["templateid"]<>0) continue; - delete_item($id); + if(delete_item($id)) + { + $result = true; + + $host = get_host_by_hostid($item["hostid"]); + + add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ITEM, + S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."]"); + } } - show_messages(TRUE, S_ITEMS_DELETED, S_CANNOT_DELETE_ITEMS); + show_messages($result, S_ITEMS_DELETED, null); } else if($_REQUEST["group_task"]=="Activate selected") { + $result = false; + $group_itemid = $_REQUEST["group_itemid"]; foreach($group_itemid as $id) { - activate_item($id); + if(!($item = get_item_by_itemid($id))) continue; + + if(activate_item($id)) + { + $result = true; + $host = get_host_by_hostid($item["hostid"]); + add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, + S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."] ".S_ITEMS_ACTIVATED); + } } - show_messages(TRUE, S_ITEMS_ACTIVATED, S_CANNOT_ACTIVATE_ITEMS); + show_messages($result, S_ITEMS_ACTIVATED, null); } elseif($_REQUEST["group_task"]=="Disable selected") { + $result = false; + $group_itemid = $_REQUEST["group_itemid"]; foreach($group_itemid as $id) { - disable_item($id); + if(!($item = get_item_by_itemid($id))) continue; + + if(disable_item($id)) + { + $result = true; + + $host = get_host_by_hostid($item["hostid"]); + add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, + S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."] ".S_ITEMS_DISABLED); + } } - show_messages(TRUE, S_ITEMS_DISABLED, S_CANNOT_DISABLE_ITEMS); + show_messages($result, S_ITEMS_DISABLED, null); } elseif($_REQUEST["group_task"]=='Clean history selected items') { + $result = false; + $group_itemid = $_REQUEST["group_itemid"]; foreach($group_itemid as $id) { - delete_history_by_itemid($id); - DBexecute("update items set nextcheck=0,lastvalue=null,". - "lastclock=null,prevvalue=null where itemid=$id"); + if(!($item = get_item_by_itemid($id))) continue; + + if(delete_history_by_itemid($id)) + { + $result = true; + DBexecute("update items set nextcheck=0,lastvalue=null,". + "lastclock=null,prevvalue=null where itemid=$id"); + + $host = get_host_by_hostid($item["hostid"]); + add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, + S_ITEM." [".$item["key_"]."] [".$id."] ".S_HOST." [".$host['host']."] ".S_HISTORY_CLEANED); + } } - show_messages(TRUE, S_HISTORY_CLEANED, S_CANNOT_CLEAN_HISTORY); + show_messages($result, S_HISTORY_CLEANED, $result); } } ?> - AddItem(new CButton("form",S_CREATE_ITEM)); - show_header2(S_CONFIGURATION_OF_ITEMS_BIG, $form); + show_table_header(S_CONFIGURATION_OF_ITEMS_BIG, $form); echo BR; - $db_hosts=DBselect("select hostid from hosts where mod(hostid,100)=$ZBX_CURNODEID"); + $db_hosts=DBselect("select hostid from hosts where ".DBid2nodeid("hostid")."=".$ZBX_CURNODEID); if(isset($_REQUEST["form_copy_to"]) && isset($_REQUEST["group_itemid"])) { insert_copy_elements_to_forms("group_itemid"); @@ -396,33 +430,28 @@ $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit();"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); + + $result=DBselect("select distinct g.groupid,g.name from groups g,hosts_groups hg". + " where g.groupid=hg.groupid and hg.hostid in (".$accessible_hosts.") ". + " order by name"); while($row=DBfetch($result)) { - // Check if at least one host with read permission exists for this group - $result2=DBselect("select h.hostid,h.host from hosts h,hosts_groups hg". - " where hg.groupid=".$row["groupid"]." and hg.hostid=h.hostid and". - " h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host order by h.host"); - while($row2=DBfetch($result2)) - { - if(!check_right("Host","U",$row2["hostid"])) continue; - $cmbGroup->AddItem($row["groupid"],$row["name"]); - break; - } + $cmbGroup->AddItem($row["groupid"],$row["name"]); } $form->AddItem(S_GROUP.SPACE); $form->AddItem($cmbGroup); if(isset($_REQUEST["groupid"]) && $_REQUEST["groupid"]>0) { - $sql="select h.hostid,h.host from hosts h,hosts_groups hg". - " where hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid and". - " h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host order by h.host"; + $sql="select distinct h.hostid,h.host from hosts h,hosts_groups hg". + " where hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid ". + " and h.hostid in (".$accessible_hosts.") ". + " and h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host order by h.host"; } else { - $sql="select h.hostid,h.host from hosts h where h.status<>".HOST_STATUS_DELETED. - " and mod(h.hostid,100)=".$ZBX_CURNODEID. + $sql="select distinct h.hostid,h.host from hosts h where h.status<>".HOST_STATUS_DELETED. + " and h.hostid in (".$accessible_hosts.") ". " group by h.hostid,h.host order by h.host"; } @@ -431,11 +460,10 @@ $_REQUEST["hostid"] = get_request("hostid",0); $cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit();"); - $correct_hostid='no'; + unset($correct_hostid); $first_hostid = -1; while($row=DBfetch($result)) { - if(!check_right("Host","U",$row["hostid"])) continue; $cmbHosts->AddItem($row["hostid"],$row["host"]); if($_REQUEST["hostid"]!=0){ @@ -445,13 +473,13 @@ if($first_hostid <= 0) $first_hostid = $row["hostid"]; } - if($correct_hostid!='ok') + if(!isset($correct_hostid)) $_REQUEST["hostid"] = $first_hostid; $form->AddItem(SPACE.S_HOST.SPACE); $form->AddItem($cmbHosts); - show_header2(S_ITEMS_BIG, $form); + show_table_header(S_ITEMS_BIG, $form); // TABLE $form = new CForm(); @@ -464,21 +492,16 @@ $table->setHeader(array( array( new CCheckBox("all_items",NULL, "CheckAll('".$form->GetName()."','all_items');"), - S_ID), - S_DESCRIPTION,S_KEY,nbsp(S_UPDATE_INTERVAL), + S_DESCRIPTION), + S_KEY,nbsp(S_UPDATE_INTERVAL), S_HISTORY,S_TRENDS,S_TYPE,S_STATUS, $show_applications == 1 ? S_APPLICATIONS : NULL, S_ERROR)); $db_items = DBselect("select i.* from hosts h,items i where h.hostid=i.hostid and". - " h.hostid=".$_REQUEST["hostid"]." order by i.description, i.key_"); + " h.hostid=".$_REQUEST["hostid"]." order by i.templateid,i.description, i.key_"); while($db_item = DBfetch($db_items)) { - if(!check_right("Item","U",$db_item["itemid"])) - { - continue; - } - if($db_item["templateid"]==0) { $description = new CLink( @@ -497,41 +520,11 @@ ); } - switch($db_item["type"]){ - case 0: $type = S_ZABBIX_AGENT; break; - case 7: $type = S_ZABBIX_AGENT_ACTIVE; break; - case 1: $type = S_SNMPV1_AGENT; break; - case 2: $type = S_ZABBIX_TRAPPER; break; - case 3: $type = S_SIMPLE_CHECK; break; - case 4: $type = S_SNMPV2_AGENT; break; - case 6: $type = S_SNMPV3_AGENT; break; - case 5: $type = S_ZABBIX_INTERNAL; break; - case 8: $type = S_ZABBIX_AGGREGATE; break; - default:$type = S_UNKNOWN; break; - } - - switch($db_item["status"]){ - case 0: $status=new CCol(new CLink(S_ACTIVE, + $status=new CCol(new CLink(item_status2str($db_item["status"]), "items.php?group_itemid%5B%5D=".$db_item["itemid"]. "&hostid=".$_REQUEST["hostid"]. - "&group_task=Disable+selected", - "off"),"off"); - break; - case 1: $status=new CCol(new CLink(S_DISABLED, - "items.php?group_itemid%5B%5D=".$db_item["itemid"]. - "&hostid=".$_REQUEST["hostid"]. - "&group_task=Activate+selected", - "on"),"on"); - break; - case 3: $status=new CCol(new CLink(S_NOT_SUPPORTED, - "items.php?group_itemid%5B%5D=".$db_item["itemid"]. - "&hostid=".$_REQUEST["hostid"]. - "&group_task=Activate+selected", - "action") - ,"unknown"); - break; - default:$status=S_UNKNOWN; - } + "&group_task=".($db_item["status"] ? "Activate+selected" : "Disable+selected"), + item_status2style($db_item["status"]))); if($db_item["error"] == "") { @@ -552,13 +545,12 @@ $chkBox = new CCheckBox("group_itemid[]",NULL,NULL,$db_item["itemid"]); if($db_item["templateid"] > 0) $chkBox->SetEnabled(false); $table->AddRow(array( - array($chkBox, $db_item["itemid"]), - $description, + array($chkBox, $description), $db_item["key_"], $db_item["delay"], $db_item["history"], $db_item["trends"], - $type, + item_type2str($db_item['type']), $status, $show_applications == 1 ? trim($applications,", ") : NULL, $error @@ -587,5 +579,7 @@ } ?> -- cgit