diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-10-22 14:26:35 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-10-22 14:26:35 +0000 |
| commit | 8586918ae51297d8be70ff360a8cac4d58f593eb (patch) | |
| tree | 0defc400008c8db04b8169b6bf7412a2afc47640 /frontends/php | |
| parent | a3881a9c2fbc9e6a58bfeadbccba819979d94937 (diff) | |
| download | zabbix-8586918ae51297d8be70ff360a8cac4d58f593eb.tar.gz zabbix-8586918ae51297d8be70ff360a8cac4d58f593eb.tar.xz zabbix-8586918ae51297d8be70ff360a8cac4d58f593eb.zip | |
- [DEV-48] merged rev. 4890:4891 of branches/1.4.j/ (Artem) [added scripts form,scripts list, script call menu]
git-svn-id: svn://svn.zabbix.com/trunk@4893 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
| -rw-r--r-- | frontends/php/include/defines.inc.php | 4 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 22 | ||||
| -rw-r--r-- | frontends/php/include/page_header.php | 3 | ||||
| -rw-r--r-- | frontends/php/include/scripts.inc.php | 80 | ||||
| -rw-r--r-- | frontends/php/js/common.js | 2 | ||||
| -rw-r--r-- | frontends/php/scripts.php | 206 | ||||
| -rw-r--r-- | frontends/php/scripts_exec.php | 69 | ||||
| -rw-r--r-- | frontends/php/tr_status.php | 31 |
8 files changed, 408 insertions, 9 deletions
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index 55bf5699..3c7658d1 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -104,6 +104,7 @@ define('AUDIT_RESOURCE_SCENARIO', 22); define('AUDIT_RESOURCE_DISCOVERY_RULE', 23); define('AUDIT_RESOURCE_SLIDESHOW', 24); + define('AUDIT_RESOURCE_SCRIPT', 25); define('CONDITION_TYPE_HOST_GROUP', 0); define('CONDITION_TYPE_HOST', 1); @@ -330,6 +331,9 @@ define('PERM_READ_ONLY', 2); define('PERM_READ_LIST', 1); define('PERM_DENY', 0); + + define('SCRIPT_HOST_ACCESS_READ', 0); + define('SCRIPT_HOST_ACCESS_WRITE', 1); define('PERM_RES_STRING_LINE', 0); /* return string of nodes id - '1,2,3,4,5' */ define('PERM_RES_IDS_ARRAY', 1); /* return array of nodes id - array(1,2,3,4) */ diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 6f1cb3af..fd6d464d 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -1287,6 +1287,27 @@ 'S_DELETE_SELECTED_USERS_Q'=> 'Delete selected users?', 'S_NO_ACCESSIBLE_RESOURCES'=> 'No accessibles resources', +//scripts.php + 'S_SCRIPTS'=> 'Scripts', + 'S_SCRIPT'=> 'Script', + 'S_COMMAND'=> 'Command', + 'S_PERMISSIONS_SMALL'=> 'permissions', + 'S_REQUIRED_HOST'=> 'Required host', + 'S_READ'=> 'Read', + 'S_WRITE'=> 'Write', + 'S_NO_SCRIPTS_DEFINED'=> 'No scripts defined', + 'S_HOST_ACCESS'=> 'Host access', + 'S_DELETE_SELECTED_SCRIPTS_Q'=> 'Delete selected scripts?', + 'S_ADD_SCRIPT'=> 'Add script', + 'S_SCRIPT_ADDED'=> 'Script added', + 'S_CANNOT_ADD_SCRIPT'=> 'Cannot add script', + 'S_SCRIPT_UPDATED'=> 'Script updated', + 'S_CANNOT_UPDATE_SCRIPT'=> 'Cannot update script', + 'S_SCRIPT_DELETED'=> 'Script deleted', + 'S_CANNOT_DELETE_SCRIPT'=> 'Cannot delete script', + 'S_TOOLS'=> 'Tools', + + // audit.php 'S_AUDIT_LOG'=> 'Audit log', 'S_AUDIT_LOG_BIG'=> 'AUDIT LOG', @@ -1300,6 +1321,7 @@ 'S_MEDIA_TYPE'=> 'Media type', 'S_GRAPH_ELEMENT'=> 'Graph element', 'S_UNKNOWN_RESOURCE'=> 'Unknown resource', + 'S_ALREADY_EXISTS_SMALL'=> 'alredy exists', // profile.php 'S_USER_PROFILE_BIG'=> 'USER PROFILE', diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php index 0a633104..bb7772b0 100644 --- a/frontends/php/include/page_header.php +++ b/frontends/php/include/page_header.php @@ -191,6 +191,9 @@ COpt::profiling_start("page"); "popup_usrgrp.php","popup_right.php","popup_users.php") ), array("url"=>"media_types.php" ,"label"=>S_MEDIA_TYPES ), + array("url"=>"scripts.php" ,"label"=>S_SCRIPTS, + "sub_pages"=> array("scripts_exec.php") + ), array("url"=>"audit.php" ,"label"=>S_AUDIT ), array("url"=>"report4.php" ,"label"=>S_NOTIFICATIONS ), array("url"=>"instal.php" ,"label"=>S_INSTALLATION , diff --git a/frontends/php/include/scripts.inc.php b/frontends/php/include/scripts.inc.php new file mode 100644 index 00000000..071b45f9 --- /dev/null +++ b/frontends/php/include/scripts.inc.php @@ -0,0 +1,80 @@ +<?php + +function get_script_by_scriptid($scriptid){ + $sql = 'SELECT * FROM scripts WHERE scriptid='.$scriptid; + + $rows = false; + if($res = DBSelect($sql)){ + $rows = DBfetch($res); + } +return $rows; +} + +function add_script($name,$command,$access){ + $scriptid = get_dbid('scripts','scriptid'); + $sql = 'INSERT INTO scripts (scriptid,name,command,host_access) '. + " VALUES ('$scriptid','$name',".zbx_dbstr($command).",$access)"; + $result = DBexecute($sql); + if($result){ + $result = $scriptid; + } +return $result; +} + +function delete_script($scriptid){ + $sql = 'DELETE FROM scripts WHERE scriptid='.$scriptid; + $result = DBexecute($sql); +return $result; +} + +function update_script($scriptid,$name,$command,$access){ + + $sql = 'UPDATE scripts SET '. + ' name='.zbx_dbstr($name). + ' ,command='.zbx_dbstr($command). + ' ,host_access='.$access. + ' WHERE scriptid='.$scriptid; + + $result = DBexecute($sql); +return $result; +} + +function execute_script($scriptid,$hostid){ +} + +function get_accessible_scripts_by_hosts($hosts){ + global $USER_DETAILS; + + if(!is_array($hosts)){ + $hosts = array('0' => hosts); + } + + $hosts_read_only = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid())); + $hosts_read_write = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,null,null,get_current_nodeid())); + + $scripts_by_host = array(); + + $sql = 'SELECT * FROM scripts '. + ' WHERE '.DBin_node('scriptid'). + ' ORDER BY scriptid ASC'; + + $res=DBselect($sql); + + while($script = DBfetch($res)){ + foreach($hosts as $id => $hostid){ + if($script['host_access'] == SCRIPT_HOST_ACCESS_WRITE){ + if(in_array($hostid,$hosts_read_write)){ + $scripts_by_host[$hostid][] = $script; + } + } + else{ + if(in_array($hostid,$hosts_read_only)){ + $scripts_by_host[$hostid][] = $script; + } + } + } + } + +return $scripts_by_host; +} +?>
\ No newline at end of file diff --git a/frontends/php/js/common.js b/frontends/php/js/common.js index a13ea971..dba4c05b 100644 --- a/frontends/php/js/common.js +++ b/frontends/php/js/common.js @@ -292,4 +292,4 @@ function getPosition(obj){ } } return pos; -}
\ No newline at end of file +} diff --git a/frontends/php/scripts.php b/frontends/php/scripts.php new file mode 100644 index 00000000..27caeac5 --- /dev/null +++ b/frontends/php/scripts.php @@ -0,0 +1,206 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2007 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + include_once "include/config.inc.php"; + require_once "include/hosts.inc.php"; + require_once "include/scripts.inc.php"; + + $page['title'] = "S_SCRIPTS"; + $page['file'] = 'scripts.php'; + + +include_once "include/page_header.php"; + +//---------------------------------- CHECKS ------------------------------------ + +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + + $fields=array( + 'scriptid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + 'scripts'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), + +// action + 'action'=> array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null), + 'save'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, null), + 'delete'=> array(T_ZBX_STR, O_OPT, P_ACT, null, null), + +// form + 'name'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})'), + 'command'=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})'), + 'access'=> array(T_ZBX_INT, O_OPT, NULL, IN('0,1'), 'isset({save})'), + + 'form'=> array(T_ZBX_STR, O_OPT, NULL, IN('0,1'), null), + 'form_refresh'=> array(T_ZBX_INT, O_OPT, NULL, NULL, null), + ); + + +check_fields($fields); + +if(isset($_REQUEST['action'])){ + + if(isset($_REQUEST['save'])){ + + $cond = (isset($_REQUEST['scriptid']))?(' AND scriptid<>'.$_REQUEST['scriptid']):(''); + + $scripts = DBfetch(DBselect('SELECT count(scriptid) as cnt FROM scripts WHERE name='.zbx_dbstr($_REQUEST['name']).$cond,1)); + + if($scripts && $scripts['cnt']>0){ + error(S_SCRIPT.SPACE.'['.htmlspecialchars($_REQUEST['name']).']'.SPACE.S_ALREADY_EXISTS_SMALL); + show_messages(null,S_ERROR,S_CANNOT_ADD_SCRIPT); + } + else{ + + if(isset($_REQUEST['scriptid'])){ + $result = update_script($_REQUEST['scriptid'],$_REQUEST['name'],$_REQUEST['command'],$_REQUEST['access']); + + show_messages($result, S_SCRIPT_UPDATED, S_CANNOT_UPDATE_SCRIPT); + $scriptid = $_REQUEST['scriptid']; + $audit_acrion = AUDIT_ACTION_UPDATE; + } + else { + $result = add_script($_REQUEST['name'],$_REQUEST['command'],$_REQUEST['access']); + + show_messages($result, S_SCRIPT_ADDED, S_CANNOT_ADD_SCRIPT); + $scriptid = $result; + $audit_acrion = AUDIT_ACTION_ADD; + } + + add_audit_if($result,$audit_acrion,AUDIT_RESOURCE_SCRIPT,' Name ['.$_REQUEST['name'].'] id ['.$scriptid.']'); + + if($result){ + unset($_REQUEST['action']); + unset($_REQUEST['form']); + unset($_REQUEST['scriptid']); + } + } + } + else if(isset($_REQUEST['delete'])){ + + if(isset($_REQUEST['scriptid'])){ + $scripts[$_REQUEST['scriptid']] = $_REQUEST['scriptid']; + } + else{ + $scripts = $_REQUEST['scripts']; + } + + $result = true; + foreach($scripts as $scriptid){ + $result &= delete_script($scriptid); + + if($result){ + add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_SCRIPT, S_SCRIPT.' ['.$scriptid.']'); + } + } + show_messages($result, S_SCRIPT_DELETED, S_CANNOT_DELETE_SCRIPT); + + if($result){ + unset($_REQUEST['form']); + unset($_REQUEST['scriptid']); + } + } +} + +if(isset($_REQUEST['form'])){ + + $frmScr = new CFormTable(S_SCRIPT,'scripts.php','POST',null,'form'); + + if(isset($_REQUEST['scriptid'])) $frmScr->AddVar('scriptid',$_REQUEST['scriptid']); + + $name = get_request('name',''); + $command = get_request('command',''); + $access = get_request('access', SCRIPT_HOST_ACCESS_READ); + + if(isset($_REQUEST['scriptid']) && !isset($_REQUEST['form_refresh'])){ + $frmScr->AddVar('form_refresh',get_request('form_refresh',1)); + + if($script = get_script_by_scriptid($_REQUEST['scriptid'])){ + $name = $script['name']; + $command = $script['command']; + $access = $script['host_access']; + } + } + + $frmScr->AddRow(S_NAME,new CTextBox('name',$name,80)); + $frmScr->AddRow(S_COMMAND,new CTextBox('command',$command,80)); + + $select_acc = new CCombobox('access'); + $select_acc->AddItem(SCRIPT_HOST_ACCESS_READ,S_READ,(($access == SCRIPT_HOST_ACCESS_READ)?'yes':'no')); + $select_acc->AddItem(SCRIPT_HOST_ACCESS_WRITE,S_WRITE,(($access == SCRIPT_HOST_ACCESS_WRITE)?'yes':'no')); + + $frmScr->AddRow(S_REQUIRED_HOST.SPACE.S_PERMISSIONS_SMALL,$select_acc); + + $frmScr->AddItemToBottomRow(new CButton('save',S_SAVE,'javascript: document.forms[0].action += \'?action=1\';')); + $frmScr->AddItemToBottomRow(SPACE); + + $frmScr->AddItemToBottomRow(new CButtonCancel()); + $frmScr->Show(); +} +else { + $form = new CForm(); + $form->SetName('scripts'); + $form->AddOption('id','scripts'); + + show_table_header(S_SCRIPTS); + + $table=new CTableInfo(S_NO_SCRIPTS_DEFINED); + $table->setHeader(array( + array(new CCheckBox('all_scripts',null,"CheckAll('".$form->GetName()."','all_scripts');"),S_NAME), + S_COMMAND, S_HOST_ACCESS + ) + ); + + $sql = 'SELECT * FROM scripts '. + ' WHERE '.DBin_node('scriptid'). + ' ORDER BY scriptid ASC'; + + $scripts=DBselect($sql); + + while($script=DBfetch($scripts)){ + + $table->addRow(array( + array( + new CCheckBox('scripts['.$script['scriptid'].']','no',NULL,$script['scriptid']), + new CLink($script['name'],'scripts.php?form=1'.'&scriptid='.$script['scriptid'].'#form','action') + ), + htmlspecialchars($script['command']), + (($script['host_access'] == SCRIPT_HOST_ACCESS_READ)?S_READ:S_WRITE) + )); + } + $qbutton = new CButtonQMessage('delete',S_DELETE_SELECTED,S_DELETE_SELECTED_SCRIPTS_Q,'1'); + $qbutton->SetAction("javascript: document.getElementById('scripts').action+='?action=1';"); + + $tr = new CCol( + array( + new CButton('form',S_ADD_SCRIPT,"javascript: Redirect('scripts.php?form=1');"), + SPACE, + $qbutton + ) + ); + + $table->SetFooter($tr); + + $form->AddItem($table); + $form->show(); +} +?> +<?php +include_once "include/page_footer.php"; +?>
\ No newline at end of file diff --git a/frontends/php/scripts_exec.php b/frontends/php/scripts_exec.php new file mode 100644 index 00000000..b96d29cd --- /dev/null +++ b/frontends/php/scripts_exec.php @@ -0,0 +1,69 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2007 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + include_once "include/config.inc.php"; + require_once "include/hosts.inc.php"; + require_once "include/scripts.inc.php"; + + $page['title'] = "S_SCRIPTS"; + $page['file'] = 'scripts_exec.php'; + + define('ZBX_PAGE_NO_MENU', 1); + +include_once "include/page_header.php"; + +//---------------------------------- CHECKS ------------------------------------ + +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + + $fields=array( + 'hostid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), + 'scriptid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), + 'execute'=> array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null), + ); + + +check_fields($fields); + +if(isset($_REQUEST['execute'])){ + if($script = get_script_by_scriptid($_REQUEST['scriptid'])){ + if($script['host_access'] == SCRIPT_HOST_ACCESS_WRITE){ + $hosts_read_write = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,null,null,get_current_nodeid())); + + if(in_array($_REQUEST['hostid'],$hosts_read_write)){ +SDI('WRITE: '.$_REQUEST['scriptid'].' : '.$_REQUEST['hostid']); + $result = execute_script($_REQUEST['scriptid'],$_REQUEST['hostid']); + } + } + else{ + $hosts_read_only = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid())); + + if(in_array($_REQUEST['hostid'],$hosts_read_only)){ +SDI('READ: '.$_REQUEST['scriptid'].' : '.$_REQUEST['hostid']); + $result = execute_script($_REQUEST['scriptid'],$_REQUEST['hostid']); + } + } + } +} +?> +<?php +include_once "include/page_footer.php"; +?>
\ No newline at end of file diff --git a/frontends/php/tr_status.php b/frontends/php/tr_status.php index ad0badf4..500700b0 100644 --- a/frontends/php/tr_status.php +++ b/frontends/php/tr_status.php @@ -24,6 +24,7 @@ require_once "include/acknow.inc.php"; require_once "include/triggers.inc.php"; require_once "include/events.inc.php"; + require_once "include/scripts.inc.php"; $page["file"] = "tr_status.php"; $page["title"] = "S_STATUS_OF_TRIGGERS"; @@ -85,7 +86,6 @@ define('ZBX_PAGE_NO_MENU', 1); include_once "include/page_header.php"; -echo '<script type="text/javascript" src="js/blink.js"></script>'; ?> <?php @@ -161,6 +161,8 @@ echo '<script type="text/javascript" src="js/blink.js"></script>'; $cmbGroup->AddItem(0,S_ALL_SMALL); $availiable_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST, null, null, get_current_nodeid()); + + $scripts_by_hosts = get_accessible_scripts_by_hosts(explode(',',$availiable_hosts)); $result=DBselect("select distinct g.groupid,g.name from groups g, hosts_groups hg, hosts h, items i, functions f, triggers t ". " where h.hostid in (".$availiable_hosts.") ". @@ -387,7 +389,7 @@ echo '<script type="text/javascript" src="js/blink.js"></script>'; } $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description, '. - ' t.expression,t.priority,t.lastchange,t.comments,t.url,t.value,h.host '. + ' t.expression,t.priority,t.lastchange,t.comments,t.url,t.value,h.host, h.hostid '. ' FROM triggers t,hosts h,items i,functions f '. ' WHERE f.itemid=i.itemid AND h.hostid=i.hostid '. ' AND t.triggerid=f.triggerid AND t.status='.TRIGGER_STATUS_ENABLED. @@ -478,10 +480,25 @@ echo '<script type="text/javascript" src="js/blink.js"></script>'; } $ack='-'; + + + $host = null; + if($_REQUEST['hostid'] < 1){ + $menus = ''; + foreach($scripts_by_hosts[$row['hostid']] as $id => $script){ + $menus.= "['".$script['name']."',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=".$row['hostid']."&scriptid=".$script['scriptid']."','".S_TOOLS."',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; + } + $menus = trim($menus,','); + if(!empty($menus)) $menus="show_popup_menu(event,[[".zbx_jsvalue(S_TOOLS).",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],".$menus."],180);"; + + $host = new CSpan($row['host']); + $host->AddOption('onclick','javascript: '.$menus); + $host->AddOption('onmouseover',"javascript: this.style.cursor = 'pointer';"); + } $table->AddRow(array( get_node_name_by_elid($row['triggerid']), - $_REQUEST['hostid'] > 0 ? null : $row['host'], + $host, SPACE, $description, $value, @@ -558,12 +575,10 @@ echo '<script type="text/javascript" src="js/blink.js"></script>'; ))); $m_form->Show(); -// $table->Show(false); - -// show_table_header(S_TOTAL.": ".$table->GetNumRows()); + + $jsmenu = new CPUMenu(null,170); + $jsmenu->InsertJavaScript(); ?> <?php - include_once "include/page_footer.php"; - ?> |
