diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-05-09 12:18:11 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-05-09 12:18:11 +0000 |
| commit | 7524ac12a656abc42d6b83a3f7be3ae40d09d3ff (patch) | |
| tree | 475c8217064ac94dc22d7f30f578d5af3a01aae1 /frontends/php | |
| parent | a6b057c94aab1d1dd636fcce5237556164624046 (diff) | |
| download | zabbix-7524ac12a656abc42d6b83a3f7be3ae40d09d3ff.tar.gz zabbix-7524ac12a656abc42d6b83a3f7be3ae40d09d3ff.tar.xz zabbix-7524ac12a656abc42d6b83a3f7be3ae40d09d3ff.zip | |
- [DEV-149] added hosts masss update functionality (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5691 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
| -rw-r--r-- | frontends/php/hosts.php | 336 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 110 | ||||
| -rw-r--r-- | frontends/php/include/hosts.inc.php | 44 |
3 files changed, 295 insertions, 195 deletions
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php index 43b5b2ad..af6957c9 100644 --- a/frontends/php/hosts.php +++ b/frontends/php/hosts.php @@ -19,28 +19,28 @@ **/ ?> <?php - require_once "include/config.inc.php"; - require_once "include/hosts.inc.php"; - require_once "include/forms.inc.php"; + require_once 'include/config.inc.php'; + require_once 'include/hosts.inc.php'; + require_once 'include/forms.inc.php'; - $page["title"] = "S_HOSTS"; - $page["file"] = "hosts.php"; + $page['title'] = "S_HOSTS"; + $page['file'] = 'hosts.php'; $page['hist_arg'] = array('groupid','config','hostid'); -include_once "include/page_header.php"; +include_once 'include/page_header.php'; - $_REQUEST["config"] = get_request("config",get_profile("web.hosts.config",0)); + $_REQUEST['config'] = get_request('config',get_profile('web.hosts.config',0)); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY); - if(isset($_REQUEST["hostid"]) && $_REQUEST["hostid"] > 0 && !uint_in_array($_REQUEST["hostid"], $available_hosts)) { + if(isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0 && !uint_in_array($_REQUEST['hostid'], $available_hosts)) { access_deny(); } - if(isset($_REQUEST["apphostid"]) && $_REQUEST["apphostid"] > 0 && !uint_in_array($_REQUEST["apphostid"], $available_hosts)) { + if(isset($_REQUEST['apphostid']) && $_REQUEST['apphostid'] > 0 && !uint_in_array($_REQUEST['apphostid'], $available_hosts)) { access_deny(); } - if(isset($_REQUEST["groupid"]) && $_REQUEST["groupid"] > 0){ - if(!uint_in_array($_REQUEST["groupid"], get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY))){ + if(isset($_REQUEST['groupid']) && $_REQUEST['groupid'] > 0){ + if(!uint_in_array($_REQUEST['groupid'], get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY))){ access_deny(); } } @@ -49,81 +49,86 @@ include_once "include/page_header.php"; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields=array( // 0 - hosts; 1 - groups; 2 - linkages; 3 - templates; 4 - applications; 5 - Proxies; 6 - host mass update - "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2,3,4,5,6"), NULL), + 'config'=> array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3,4,5'), NULL), /* ARAYS */ - "hosts"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), - "groups"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), - "applications"=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), + 'hosts'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), + 'groups'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), + 'applications'=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), /* host */ - "hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({config})&&({config}==0||{config}==5||{config}==2)&&isset({form})&&({form}=="update")'), - "host"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==0||{config}==3||{config}==5)&&isset({save})'), - 'proxy_hostid'=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({config})&&({config}==0)&&isset({save})'), - "dns"=> array(T_ZBX_STR, O_OPT, NULL, NULL, '(isset({config})&&({config}==0))&&isset({save})'), - "useip"=> array(T_ZBX_STR, O_OPT, NULL, IN('0,1'), '(isset({config})&&({config}==0))&&isset({save})'), - "ip"=> array(T_ZBX_IP, O_OPT, NULL, NULL, '(isset({config})&&({config}==0))&&isset({save})'), - "port"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'(isset({config})&&({config}==0))&&isset({save})'), - "status"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,3"), '(isset({config})&&({config}==0))&&isset({save})'), - - "newgroup"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), - "templates"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, NULL), - "clear_templates"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), - - "useprofile"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), - "devicetype"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "name"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "os"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "serialno"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "tag"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "macaddress"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "hardware"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "software"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "contact"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "location"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "notes"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), + 'hostid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({config})&&({config}==0||{config}==5||{config}==2)&&isset({form})&&({form}=="update")'), + 'host'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==0||{config}==3||{config}==5)&&isset({save})&&!isset({massupdate})'), + 'proxy_hostid'=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({config})&&({config}==0)&&isset({save})&&!isset({massupdate})'), + 'dns'=> array(T_ZBX_STR, O_OPT, NULL, NULL, '(isset({config})&&({config}==0))&&isset({save})&&!isset({massupdate})'), + 'useip'=> array(T_ZBX_STR, O_OPT, NULL, IN('0,1'), '(isset({config})&&({config}==0))&&isset({save})&&!isset({massupdate})'), + 'ip'=> array(T_ZBX_IP, O_OPT, NULL, NULL, '(isset({config})&&({config}==0))&&isset({save})&&!isset({massupdate})'), + 'port'=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'(isset({config})&&({config}==0))&&isset({save})&&!isset({massupdate})'), + 'status'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1,3'), '(isset({config})&&({config}==0))&&isset({save})&&!isset({massupdate})'), + + 'newgroup'=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), + 'templates'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, NULL), + 'clear_templates'=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), + + 'useprofile'=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), + 'devicetype'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'name'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'os'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'serialno'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'tag'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'macaddress'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'hardware'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'software'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'contact'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'location'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + 'notes'=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), + +/* mass update*/ + 'massupdate'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), + 'visible'=> array(T_ZBX_STR, O_OPT, null, null, null), + /* group */ - "groupid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==1))&&(isset({form})&&({form}=="update"))'), - "gname"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, '(isset({config})&&({config}==1))&&isset({save})'), + 'groupid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==1))&&(isset({form})&&({form}=="update"))'), + 'gname'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, '(isset({config})&&({config}==1))&&isset({save})'), /* application */ - "applicationid"=>array(T_ZBX_INT,O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==4))&&(isset({form})&&({form}=="update"))'), - "appname"=> array(T_ZBX_STR, O_NO, NULL, NOT_EMPTY, '(isset({config})&&({config}==4))&&isset({save})'), - "apphostid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID.'{}>0', '(isset({config})&&({config}==4))&&isset({save})'), - "apptemplateid"=>array(T_ZBX_INT,O_OPT, NULL, DB_ID, NULL), + 'applicationid'=>array(T_ZBX_INT,O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==4))&&(isset({form})&&({form}=="update"))'), + 'appname'=> array(T_ZBX_STR, O_NO, NULL, NOT_EMPTY, '(isset({config})&&({config}==4))&&isset({save})'), + 'apphostid'=> array(T_ZBX_INT, O_OPT, NULL, DB_ID.'{}>0', '(isset({config})&&({config}==4))&&isset({save})'), + 'apptemplateid'=>array(T_ZBX_INT,O_OPT, NULL, DB_ID, NULL), /* host linkage form */ - "tname"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==2)&&isset({save})'), + 'tname'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==2)&&isset({save})'), /* actions */ - "activate"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "disable"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + 'activate'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + 'disable'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "add_to_group"=> array(T_ZBX_INT, O_OPT, P_SYS|P_ACT, DB_ID, NULL), - "delete_from_group"=> array(T_ZBX_INT, O_OPT, P_SYS|P_ACT, DB_ID, NULL), + 'add_to_group'=> array(T_ZBX_INT, O_OPT, P_SYS|P_ACT, DB_ID, NULL), + 'delete_from_group'=> array(T_ZBX_INT, O_OPT, P_SYS|P_ACT, DB_ID, NULL), - "unlink"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "unlink_and_clear"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + 'unlink'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + 'unlink_and_clear'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "clone"=> 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), - "delete_and_clear"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "cancel"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), + 'save'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + 'clone'=> 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), + 'delete_and_clear'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + 'cancel'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), /* other */ - "form"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), - "form_refresh"=>array(T_ZBX_STR, O_OPT, NULL, NULL, NULL) + 'form'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), + 'form_refresh'=>array(T_ZBX_STR, O_OPT, NULL, NULL, NULL) ); check_fields($fields); validate_sort_and_sortorder('h.host',ZBX_SORT_UP); - - if($_REQUEST["config"]==4) - validate_group_with_host(PERM_READ_WRITE,array("always_select_first_host","only_current_node"),'web.last.conf.groupid', 'web.last.conf.hostid'); - else if($_REQUEST["config"]==0 || $_REQUEST["config"]==3) + + if($_REQUEST['config']==4) + validate_group_with_host(PERM_READ_WRITE,array('always_select_first_host','only_current_node'),'web.last.conf.groupid', 'web.last.conf.hostid'); + else if($_REQUEST['config']==0 || $_REQUEST['config']==3) validate_group(PERM_READ_WRITE,array(),'web.last.conf.groupid'); - update_profile("web.hosts.config",$_REQUEST["config"]); + update_profile('web.hosts.config',$_REQUEST['config']); ?> <?php @@ -131,10 +136,10 @@ include_once "include/page_header.php"; // Original mod by scricca@vipsnet.net // Modified by Aly /* this code menages operations to unlink 1 template from multiple hosts */ - if ($_REQUEST["config"]==2 && (isset($_REQUEST["unlink"]))){ - $hosts = get_request("hosts",array()); - if(isset($_REQUEST["hostid"])){ - $templateid=$_REQUEST["hostid"]; + if ($_REQUEST['config']==2 && (isset($_REQUEST['unlink']))){ + $hosts = get_request('hosts',array()); + if(isset($_REQUEST['hostid'])){ + $templateid=$_REQUEST['hostid']; $result = false; // Permission check @@ -155,13 +160,13 @@ include_once "include/page_header.php"; 'Status ['.$host['status'].']'); } - unset($_REQUEST["unlink"]); - unset($_REQUEST["hostid"]); - unset($_REQUEST["form"]); + unset($_REQUEST['unlink']); + unset($_REQUEST['hostid']); + unset($_REQUEST['form']); } } /* this code menages operations to link 1 template to multiple hosts */ - if($_REQUEST["config"]==2 && (isset($_REQUEST["save"]))){ + if($_REQUEST['config']==2 && (isset($_REQUEST['save']))){ if(isset($_REQUEST['hostid'])){ $hosts = get_request('hosts',array()); $templateid=$_REQUEST['hostid']; @@ -183,11 +188,11 @@ include_once "include/page_header.php"; $host=get_host_by_hostid($hostid); $templates_tmp=get_templates_by_hostid($hostid); - $templates_tmp[$templateid]=$template_name["host"]; + $templates_tmp[$templateid]=$template_name['host']; $result=update_host($hostid, - $host["host"],$host["port"],$host["status"],$host["useip"],$host["dns"], - $host["ip"],$host['proxy_hostid'],$templates_tmp,null,$host_groups); + $host['host'],$host['port'],$host['status'],$host['useip'],$host['dns'], + $host['ip'],$host['proxy_hostid'],$templates_tmp,null,$host_groups); } $result = DBend(); @@ -200,33 +205,132 @@ include_once "include/page_header.php"; 'Status ['.$host['status'].']'); } - unset($_REQUEST["save"]); - unset($_REQUEST["hostid"]); - unset($_REQUEST["form"]); + unset($_REQUEST['save']); + unset($_REQUEST['hostid']); + unset($_REQUEST['form']); } } //--------- END MOD ------------ /* UNLINK HOST */ - else if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && (isset($_REQUEST["unlink"]) || isset($_REQUEST["unlink_and_clear"]))){ + else if(($_REQUEST['config']==0 || $_REQUEST['config']==3) && (isset($_REQUEST['unlink']) || isset($_REQUEST['unlink_and_clear']))){ $_REQUEST['clear_templates'] = get_request('clear_templates', array()); - if(isset($_REQUEST["unlink"])){ - $unlink_templates = array_keys($_REQUEST["unlink"]); + if(isset($_REQUEST['unlink'])){ + $unlink_templates = array_keys($_REQUEST['unlink']); } else{ - $unlink_templates = array_keys($_REQUEST["unlink_and_clear"]); + $unlink_templates = array_keys($_REQUEST['unlink_and_clear']); $_REQUEST['clear_templates'] = array_merge($_REQUEST['clear_templates'],$unlink_templates); } foreach($unlink_templates as $id) unset($_REQUEST['templates'][$id]); } /* CLONE HOST */ - else if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && isset($_REQUEST["clone"]) && isset($_REQUEST["hostid"])){ - unset($_REQUEST["hostid"]); - $_REQUEST["form"] = "clone"; + else if(($_REQUEST['config']==0 || $_REQUEST['config']==3) && isset($_REQUEST['clone']) && isset($_REQUEST['hostid'])){ + unset($_REQUEST['hostid']); + $_REQUEST['form'] = 'clone'; + } +/* HOST MASS UPDATE */ + else if($_REQUEST['config']==0 && isset($_REQUEST['massupdate']) && isset($_REQUEST['save'])){ + $useip = get_request('useip',0); + $hosts = get_request('hosts',array()); + $visible = get_request('visible',array()); + + $_REQUEST['groups'] = get_request('groups',array()); + + $_REQUEST['newgroup'] = get_request('newgroup',''); + + $_REQUEST['proxy_hostid'] = get_request('proxy_hostid',0); + $_REQUEST['templates'] = get_request('templates', array()); + + if(count($_REQUEST['groups']) > 0){ + $accessible_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY); + foreach($_REQUEST['groups'] as $gid){ + if(isset($accessible_groups[$gid])) continue; + access_deny(); + } + } + else{ + if(count(get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_MODE_LT,PERM_RES_IDS_ARRAY,get_current_nodeid()))) + access_deny(); + } + + DBstart(); + + foreach($hosts as $id => $hostid){ + + $db_host = get_host_by_hostid($hostid); + $db_templates = get_templates_by_hostid($hostid); + + foreach($db_host as $key){ + if(isset($visible[$key])){ + $db_host[$key] = $_REQUEST[$key]; + } + } + + if(isset($visible['groups'])){ + $db_host['groups'] = $_REQUEST['groups']; + } + else{ + $db_host['groups'] = get_groupids_by_host($hostid); + } + + if(isset($visible['template_table'])){ + foreach($db_templates as $templateid => $name){ + unlink_template($hostid, $templateid, false); + } + $db_host['templates'] = $_REQUEST['templates']; + } + else{ + $db_host['templates'] = $db_templates; + } + + $update = update_host($hostid, + $db_host['host'],$db_host['port'],$db_host['status'],$useip,$db_host['dns'], + $db_host['ip'],$db_host['proxy_hostid'],$db_host['templates'],$_REQUEST['newgroup'],$db_host['groups']); + + $msg_ok = S_HOST_UPDATED; + $msg_fail = S_CANNOT_UPDATE_HOST; + $audit_action = AUDIT_ACTION_UPDATE; + + if($update && isset($visible['useprofile'])){ + + $host_profile=DBfetch(DBselect('SELECT * FROM hosts_profiles WHERE hostid='.$hostid)); + + delete_host_profile($hostid); + + if(get_request('useprofile','no') == 'yes'){ + foreach($host_profile as $key => $value){ + if(isset($visible[$key])){ + $host_profile[$key] = $_REQUEST[$key]; + } + } + + add_host_profile($hostid, + $host_profile['devicetype'],$host_profile['name'],$host_profile['os'], + $host_profile['serialno'],$host_profile['tag'],$host_profile['macaddress'], + $host_profile['hardware'],$host_profile['software'],$host_profile['contact'], + $host_profile['location'],$host_profile['notes']); + } + } + } + + $result = DBend(); + + show_messages($result, $msg_ok, $msg_fail); + if($result){ + add_audit($audit_action,AUDIT_RESOURCE_HOST, + 'Host ['.$db_host['host'].'] IP ['.$db_host['ip'].'] '. + 'Status ['.$db_host['status'].']'); + + unset($_REQUEST['massupdate']); + unset($_REQUEST['form']); + unset($_REQUEST['hosts']); + } + unset($_REQUEST['save']); } /* SAVE HOST */ - else if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && isset($_REQUEST["save"])){ - $useip = get_request("useip",0); - $groups=get_request("groups",array()); + else if(($_REQUEST['config']==0 || $_REQUEST['config']==3) && isset($_REQUEST['save'])){ + $useip = get_request('useip',0); + $groups=get_request('groups',array()); if(count($groups) > 0){ $accessible_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY); @@ -245,29 +349,30 @@ include_once "include/page_header.php"; $_REQUEST['proxy_hostid'] = get_request('proxy_hostid',0); if(isset($_REQUEST['hostid'])){ + DBstart(); + if(isset($_REQUEST['clear_templates'])) { foreach($_REQUEST['clear_templates'] as $id){ - unlink_template($_REQUEST["hostid"], $id, false); + unlink_template($_REQUEST['hostid'], $id, false); } } - DBstart(); - update_host($_REQUEST["hostid"], - $_REQUEST["host"],$_REQUEST["port"],$_REQUEST["status"],$useip,$_REQUEST["dns"], - $_REQUEST["ip"],$_REQUEST["proxy_hostid"],$templates,$_REQUEST["newgroup"],$groups); + update_host($_REQUEST['hostid'], + $_REQUEST['host'],$_REQUEST['port'],$_REQUEST['status'],$useip,$_REQUEST['dns'], + $_REQUEST['ip'],$_REQUEST['proxy_hostid'],$templates,$_REQUEST['newgroup'],$groups); $result = DBend(); $msg_ok = S_HOST_UPDATED; $msg_fail = S_CANNOT_UPDATE_HOST; $audit_action = AUDIT_ACTION_UPDATE; - $hostid = $_REQUEST["hostid"]; + $hostid = $_REQUEST['hostid']; } else { DBstart(); $hostid = add_host( - $_REQUEST["host"],$_REQUEST["port"],$_REQUEST["status"],$useip,$_REQUEST["dns"], - $_REQUEST["ip"],$_REQUEST["proxy_hostid"],$templates,$_REQUEST["newgroup"],$groups); + $_REQUEST['host'],$_REQUEST['port'],$_REQUEST['status'],$useip,$_REQUEST['dns'], + $_REQUEST['ip'],$_REQUEST['proxy_hostid'],$templates,$_REQUEST['newgroup'],$groups); $result = DBend()?$hostid:false; $msg_ok = S_HOST_ADDED; @@ -276,17 +381,17 @@ include_once "include/page_header.php"; } if($result){ - update_profile("HOST_PORT",$_REQUEST['port']); + update_profile('HOST_PORT',$_REQUEST['port']); DBstart(); delete_host_profile($hostid); - if(get_request("useprofile","no") == "yes"){ + if(get_request('useprofile','no') == 'yes'){ add_host_profile($hostid, - $_REQUEST["devicetype"],$_REQUEST["name"],$_REQUEST["os"], - $_REQUEST["serialno"],$_REQUEST["tag"],$_REQUEST["macaddress"], - $_REQUEST["hardware"],$_REQUEST["software"],$_REQUEST["contact"], - $_REQUEST["location"],$_REQUEST["notes"]); + $_REQUEST['devicetype'],$_REQUEST['name'],$_REQUEST['os'], + $_REQUEST['serialno'],$_REQUEST['tag'],$_REQUEST['macaddress'], + $_REQUEST['hardware'],$_REQUEST['software'],$_REQUEST['contact'], + $_REQUEST['location'],$_REQUEST['notes']); } $result = DBend(); } @@ -294,13 +399,13 @@ include_once "include/page_header.php"; show_messages($result, $msg_ok, $msg_fail); if($result){ add_audit($audit_action,AUDIT_RESOURCE_HOST, - "Host [".$_REQUEST["host"]."] IP [".$_REQUEST["ip"]."] ". - "Status [".$_REQUEST["status"]."]"); + 'Host ['.$_REQUEST['host'].'] IP ['.$_REQUEST['ip'].'] '. + 'Status ['.$_REQUEST['status'].']'); - unset($_REQUEST["form"]); - unset($_REQUEST["hostid"]); + unset($_REQUEST['form']); + unset($_REQUEST['hostid']); } - unset($_REQUEST["save"]); + unset($_REQUEST['save']); } /* DELETE HOST */ @@ -774,7 +879,10 @@ include_once "include/page_header.php"; if($_REQUEST["config"]==3) $show_only_tmp = 1; - if(isset($_REQUEST["form"])){ + if(isset($_REQUEST['massupdate']) && isset($_REQUEST['hosts'])){ + insert_mass_update_host_form(); + } + else if(isset($_REQUEST["form"])){ insert_host_form($show_only_tmp); } else { @@ -994,6 +1102,8 @@ include_once "include/page_header.php"; $show_only_tmp ? NULL : new CButtonQMessage('disable',S_DISABLE_SELECTED,S_DISABLE_SELECTED_HOSTS_Q), $show_only_tmp ? NULL : SPACE, new CButtonQMessage('delete',S_DELETE_SELECTED,S_DELETE_SELECTED_HOSTS_Q), + $show_only_tmp ? NULL : SPACE, + $show_only_tmp ? NULL : new CButton('massupdate',S_MASS_UPDATE), $show_only_tmp ? SPACE : NULL, $show_only_tmp ? new CButtonQMessage('delete_and_clear',S_DELETE_SELECTED_WITH_LINKED_ELEMENTS,S_DELETE_SELECTED_HOSTS_Q) : NULL ); @@ -1006,8 +1116,8 @@ include_once "include/page_header.php"; } } else if($_REQUEST["config"]==1){ - if(isset($_REQUEST["form"])) - { + + if(isset($_REQUEST["form"])){ insert_hostgroups_form(get_request("groupid",NULL)); } else { @@ -1318,9 +1428,7 @@ include_once "include/page_header.php"; $form->Show(); } } - else if($_REQUEST["config"]==6){ /* Host Mass Update */ - insert_mass_update_host_form(); - } + ?> <?php diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index c461b2da..7cc69905 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -4099,6 +4099,8 @@ function insert_mass_update_host_form(){//$elements_array_name){ global $USER_DETAILS; + $visible = get_request('visible',array()); + $groups= get_request('groups',array()); $newgroup = get_request('newgroup',''); @@ -4139,13 +4141,16 @@ $frmHost = new CFormTable($frm_title,'hosts.php'); $frmHost->SetHelp('web.hosts.host.php'); $frmHost->AddVar('config',get_request('config',0)); + $frmHost->AddVar('massupdate',get_request('massupdate',1)); + + $hosts = $_REQUEST['hosts']; + foreach($hosts as $id => $hostid){ + $frmHost->AddVar('hosts['.$hostid.']',$hostid); + } $frmHost->AddVar('clear_templates',$clear_templates); - - if(isset($_REQUEST['hostid'])) $frmHost->AddVar('hostid',$_REQUEST['hostid']); - if(isset($_REQUEST['groupid'])) $frmHost->AddVar('groupid',$_REQUEST['groupid']); -// $frmItem->AddRow(array( new CVisibilityBox('type_visible', get_request('type_visible'), 'type', S_ORIGINAL),S_TYPE), $cmbType); +// $frmItem->AddRow(array( new CVisibilityBox('visible[type]', isset($visible['type']), 'type', S_ORIGINAL),S_TYPE), $cmbType); $frmHost->AddRow(S_NAME,S_ORIGINAL); @@ -4158,20 +4163,20 @@ while($db_group=DBfetch($db_groups)){ $grp_tb->AddItem($db_group['groupid'],$db_group['name']); } - - $frmHost->AddRow(array(new CVisibilityBox('groups_visible', get_request('groups_visible'), $grp_tb->GetName(), S_ORIGINAL),S_GROUPS), + + $frmHost->AddRow(array(new CVisibilityBox('visible[groups]', isset($visible['groups']), $grp_tb->GetName(), S_ORIGINAL),S_GROUPS), $grp_tb->Get(S_IN.SPACE.S_GROUPS,S_OTHER.SPACE.S_GROUPS) ); - $frmHost->AddRow(array(new CVisibilityBox('newgroup_visible', get_request('newgroup_visible'), 'newgroup', S_ORIGINAL),S_NEW_GROUP), + $frmHost->AddRow(array(new CVisibilityBox('visible[newgroup]', isset($visible['newgroup']), 'newgroup', S_ORIGINAL),S_NEW_GROUP), new CTextBox('newgroup',$newgroup), 'new' ); // onchange does not work on some browsers: MacOS, KDE browser - $frmHost->AddRow(array(new CVisibilityBox('dns_visible', get_request('dns_visible'), 'dns', S_ORIGINAL),S_DNS_NAME),new CTextBox('dns',$dns,'40')); + $frmHost->AddRow(array(new CVisibilityBox('visible[dns]', isset($visible['dns']), 'dns', S_ORIGINAL),S_DNS_NAME),new CTextBox('dns',$dns,'40')); - $frmHost->AddRow(array(new CVisibilityBox('ip_visible', get_request('ip_visible'), 'ip', S_ORIGINAL),S_IP_ADDRESS), + $frmHost->AddRow(array(new CVisibilityBox('visible[ip]', isset($visible['ip']), 'ip', S_ORIGINAL),S_IP_ADDRESS), new CTextBox('ip',$ip,defined('ZBX_HAVE_IPV6')?39:15) ); @@ -4179,11 +4184,11 @@ $cmbConnectBy->AddItem(0, S_DNS_NAME); $cmbConnectBy->AddItem(1, S_IP_ADDRESS); - $frmHost->AddRow(array(new CVisibilityBox('useip_visible', get_request('useip_visible'), 'useip', S_ORIGINAL),S_CONNECT_TO), + $frmHost->AddRow(array(new CVisibilityBox('visible[useip]', isset($visible['useip']), 'useip', S_ORIGINAL),S_CONNECT_TO), $cmbConnectBy ); - $frmHost->AddRow(array(new CVisibilityBox('port_visible', get_request('port_visible'), 'port', S_ORIGINAL),S_PORT), + $frmHost->AddRow(array(new CVisibilityBox('visible[port]', isset($visible['port']), 'port', S_ORIGINAL),S_PORT), new CNumericBox('port',$port,5) ); @@ -4196,7 +4201,7 @@ while ($db_proxy = DBfetch($db_proxies)) $cmbProxy->AddItem($db_proxy['hostid'], $db_proxy['host']); - $frmHost->AddRow(array(new CVisibilityBox('proxy_hostid_visible', get_request('proxy_hostid_visible'), 'proxy_hostid', S_ORIGINAL),S_MONITORED_BY_PROXY), + $frmHost->AddRow(array(new CVisibilityBox('visible[proxy_hostid]', isset($visible['proxy_hostid']), 'proxy_hostid', S_ORIGINAL),S_MONITORED_BY_PROXY), $cmbProxy ); //---------- @@ -4205,14 +4210,20 @@ $cmbStatus->AddItem(HOST_STATUS_MONITORED, S_MONITORED); $cmbStatus->AddItem(HOST_STATUS_NOT_MONITORED, S_NOT_MONITORED); - $frmHost->AddRow(array(new CVisibilityBox('status_visible', get_request('status_visible'), 'status', S_ORIGINAL),S_STATUS), + $frmHost->AddRow(array(new CVisibilityBox('visible[status]', isset($visible['status']), 'status', S_ORIGINAL),S_STATUS), $cmbStatus ); $template_table = new CTable(); + + $template_table->AddOption('name','template_table'); + $template_table->AddOption('id','template_table'); + $template_table->SetCellPadding(0); $template_table->SetCellSpacing(0); - + +// $template_table->AddOption('style','border: 1px black solid;'); + foreach($templates as $id => $temp_name){ $frmHost->AddVar('templates['.$id.']',$temp_name); $template_table->AddRow(array( @@ -4223,30 +4234,29 @@ ); } - $frmHost->AddRow(S_LINK_WITH_TEMPLATE, array($template_table, - new CButton('add_template',S_ADD, + $template_table->AddRow(new CButton('add_template',S_ADD, "return PopUp('popup.php?dstfrm=".$frmHost->GetName(). "&dstfld1=new_template&srctbl=templates&srcfld1=hostid&srcfld2=host". - url_param($templates,false,'existed_templates')."',450,450)", - 'T') - )); + url_param($templates,false,'existed_templates')."',450,450)")); + + $frmHost->AddRow(array(new CVisibilityBox('visible[template_table]', isset($visible['template_table']), 'template_table', S_ORIGINAL),S_LINK_WITH_TEMPLATE), $template_table, 'T'); - $frmHost->AddRow(array(new CVisibilityBox('useprofile_visible', get_request('useprofile_visible'), 'useprofile', S_ORIGINAL),S_USE_PROFILE), + $frmHost->AddRow(array(new CVisibilityBox('visible[useprofile]', isset($visible['useprofile']), 'useprofile', S_ORIGINAL),S_USE_PROFILE), new CCheckBox("useprofile",$useprofile,"submit()") ); if($useprofile=="yes"){ - $frmHost->AddRow(array(new CVisibilityBox('devicetype_visible', get_request('devicetype_visible'), 'devicetype', S_ORIGINAL),S_DEVICE_TYPE),new CTextBox("devicetype",$devicetype,61)); - $frmHost->AddRow(array(new CVisibilityBox('name_visible', get_request('name_visible'), 'name', S_ORIGINAL),S_NAME),new CTextBox("name",$name,61)); - $frmHost->AddRow(array(new CVisibilityBox('os_visible', get_request('os_visible'), 'os', S_ORIGINAL),S_OS),new CTextBox("os",$os,61)); - $frmHost->AddRow(array(new CVisibilityBox('serialno_visible', get_request('serialno_visible'), 'serialno', S_ORIGINAL),S_SERIALNO),new CTextBox("serialno",$serialno,61)); - $frmHost->AddRow(array(new CVisibilityBox('tag_visible', get_request('tag_visible'), 'tag', S_ORIGINAL),S_TAG),new CTextBox("tag",$tag,61)); - $frmHost->AddRow(array(new CVisibilityBox('macaddress_visible', get_request('macaddress_visible'), 'macaddress', S_ORIGINAL),S_MACADDRESS),new CTextBox("macaddress",$macaddress,61)); - $frmHost->AddRow(array(new CVisibilityBox('hardware_visible', get_request('hardware_visible'), 'hardware', S_ORIGINAL),S_HARDWARE),new CTextArea("hardware",$hardware,60,4)); - $frmHost->AddRow(array(new CVisibilityBox('software_visible', get_request('software_visible'), 'software', S_ORIGINAL),S_SOFTWARE),new CTextArea("software",$software,60,4)); - $frmHost->AddRow(array(new CVisibilityBox('contact_visible', get_request('contact_visible'), 'contact', S_ORIGINAL),S_CONTACT),new CTextArea("contact",$contact,60,4)); - $frmHost->AddRow(array(new CVisibilityBox('location_visible', get_request('location_visible'), 'location', S_ORIGINAL),S_LOCATION),new CTextArea("location",$location,60,4)); - $frmHost->AddRow(array(new CVisibilityBox('notes_visible', get_request('notes_visible'), 'notes', S_ORIGINAL),S_NOTES),new CTextArea("notes",$notes,60,4)); + $frmHost->AddRow(array(new CVisibilityBox('visible[devicetype]', isset($visible['devicetype']), 'devicetype', S_ORIGINAL),S_DEVICE_TYPE),new CTextBox("devicetype",$devicetype,61)); + $frmHost->AddRow(array(new CVisibilityBox('visible[name]', isset($visible['name']), 'name', S_ORIGINAL),S_NAME),new CTextBox("name",$name,61)); + $frmHost->AddRow(array(new CVisibilityBox('visible[os]', isset($visible['os']), 'os', S_ORIGINAL),S_OS),new CTextBox("os",$os,61)); + $frmHost->AddRow(array(new CVisibilityBox('visible[serialno]', isset($visible['serialno']), 'serialno', S_ORIGINAL),S_SERIALNO),new CTextBox("serialno",$serialno,61)); + $frmHost->AddRow(array(new CVisibilityBox('visible[tag]', isset($visible['tag']), 'tag', S_ORIGINAL),S_TAG),new CTextBox("tag",$tag,61)); + $frmHost->AddRow(array(new CVisibilityBox('visible[macaddress]', isset($visible['macaddress']), 'macaddress', S_ORIGINAL),S_MACADDRESS),new CTextBox("macaddress",$macaddress,61)); + $frmHost->AddRow(array(new CVisibilityBox('visible[hardware]', isset($visible['hardware']), 'hardware', S_ORIGINAL),S_HARDWARE),new CTextArea("hardware",$hardware,60,4)); + $frmHost->AddRow(array(new CVisibilityBox('visible[software]', isset($visible['software']), 'software', S_ORIGINAL),S_SOFTWARE),new CTextArea("software",$software,60,4)); + $frmHost->AddRow(array(new CVisibilityBox('visible[contact]', isset($visible['contact']), 'contact', S_ORIGINAL),S_CONTACT),new CTextArea("contact",$contact,60,4)); + $frmHost->AddRow(array(new CVisibilityBox('visible[location]', isset($visible['location']), 'location', S_ORIGINAL),S_LOCATION),new CTextArea("location",$location,60,4)); + $frmHost->AddRow(array(new CVisibilityBox('visible[notes]', isset($visible['notes']), 'notes', S_ORIGINAL),S_NOTES),new CTextArea("notes",$notes,60,4)); } else{ $frmHost->AddVar("devicetype", $devicetype); @@ -4262,32 +4272,7 @@ $frmHost->AddVar("notes", $notes); } - $frmHost->AddItemToBottomRow(new CButton("save",S_SAVE)); - if(isset($_REQUEST["hostid"])) - { - $frmHost->AddItemToBottomRow(SPACE); - $frmHost->AddItemToBottomRow(new CButton("clone",S_CLONE)); - $frmHost->AddItemToBottomRow(SPACE); - $frmHost->AddItemToBottomRow( - new CButtonDelete(S_DELETE_SELECTED_HOST_Q, - url_param("form").url_param("config").url_param("hostid"). - url_param("groupid") - ) - ); - - if($show_only_tmp) - { - $frmHost->AddItemToBottomRow(SPACE); - $frmHost->AddItemToBottomRow( - new CButtonQMessage('delete_and_clear', - 'Delete AND clear', - S_DELETE_SELECTED_HOSTS_Q, - url_param("form").url_param("config").url_param("hostid"). - url_param("groupid") - ) - ); - } - } + $frmHost->AddItemToBottomRow(new CButton("save",S_SAVE)); $frmHost->AddItemToBottomRow(SPACE); $frmHost->AddItemToBottomRow(new CButtonCancel(url_param("config").url_param("groupid"))); $frmHost->Show(); @@ -4687,9 +4672,7 @@ } # Insert host profile ReadOnly form - function insert_host_profile_form() - { - global $_REQUEST; + function insert_host_profile_form(){ $frmHostP = new CFormTable(S_HOST_PROFILE); $frmHostP->SetHelp("web.host_profile.php"); @@ -4697,9 +4680,7 @@ $result=DBselect("SELECT * FROM hosts_profiles WHERE hostid=".$_REQUEST["hostid"]); $row=DBfetch($result); - if($row) - { - + if($row){ $devicetype=$row["devicetype"]; $name=$row["name"]; $os=$row["os"]; @@ -4724,8 +4705,7 @@ $frmHostP->AddRow(S_LOCATION,new CTextArea("location",$location,60,4,'yes')); $frmHostP->AddRow(S_NOTES,new CTextArea("notes",$notes,60,4,'yes')); } - else - { + else{ $frmHostP->AddSpanRow("Profile for this host is missing","form_row_c"); } $frmHostP->AddItemToBottomRow(new CButtonCancel(url_param("groupid"))); diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 5364953a..b69d986b 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -484,6 +484,19 @@ require_once "include/items.inc.php"; error("No host groups with groupid=[$groupid]"); return false; } + + function get_groupids_by_host($hostid){ + $groupids = array(); + + $result=DBselect('SELECT DISTINCT hg.groupid '. + ' FROM hosts_groups hg '. + ' WHERE hg.hostid='.$hostid); + while($row=DBfetch($result)){ + $groupids[$row['groupid']] = $row['groupid']; + } + + return $groupids; + } function db_save_proxy($name,$proxyid=null){ if(!is_string($name)){ @@ -564,8 +577,8 @@ require_once "include/items.inc.php"; return false; } - function get_host_by_hostid($hostid,$no_error_message=0) - { + function get_host_by_hostid($hostid,$no_error_message=0){ + $sql="select * from hosts where hostid=$hostid"; $result=DBselect($sql); $row=DBfetch($result); @@ -578,15 +591,14 @@ require_once "include/items.inc.php"; return false; } - function get_hosts_by_templateid($templateid) - { + function get_hosts_by_templateid($templateid){ return DBselect("select h.* from hosts h, hosts_templates ht where h.hostid=ht.hostid and ht.templateid=$templateid"); } # Update Host status - function update_host_status($hostid,$status) - { + function update_host_status($hostid,$status){ + $row=DBfetch(DBselect("select status,host from hosts where hostid=$hostid")); $old_status=$row["status"]; if($status != $old_status) @@ -615,17 +627,17 @@ require_once "include/items.inc.php"; * Comments: * */ - function get_templates_by_hostid($hostid) - { - $resuilt = array(); - $db_templates = DBselect('select distinct h.hostid,h.host from hosts_templates ht '. - ' left join hosts h on h.hostid=ht.templateid '. - ' where ht.hostid='.$hostid); - while($template_data = DBfetch($db_templates)) - { - $resuilt[$template_data['hostid']] = $template_data['host']; + function get_templates_by_hostid($hostid){ + $result = array(); + $db_templates = DBselect('select distinct h.hostid,h.host '. + ' from hosts_templates ht '. + ' left join hosts h on h.hostid=ht.templateid '. + ' where ht.hostid='.$hostid); + + while($template_data = DBfetch($db_templates)){ + $result[$template_data['hostid']] = $template_data['host']; } - return $resuilt; + return $result; } /* |
