summaryrefslogtreecommitdiffstats
path: root/frontends/php
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-12-07 13:45:29 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-12-07 13:45:29 +0000
commit9d01e6f52cd54727a3337df573e7043ad779fb06 (patch)
treebd25db58eab3f97e4415c33085024cc31341b141 /frontends/php
parentb93508c7b63e89efd30a1a6c304f2eea27388244 (diff)
downloadzabbix-9d01e6f52cd54727a3337df573e7043ad779fb06.tar.gz
zabbix-9d01e6f52cd54727a3337df573e7043ad779fb06.tar.xz
zabbix-9d01e6f52cd54727a3337df573e7043ad779fb06.zip
- improved sqlite3 supporting for zabbix frontend (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3573 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
-rw-r--r--frontends/php/exp_imp.php2
-rw-r--r--frontends/php/include/db.inc.php54
-rw-r--r--frontends/php/include/forms.inc.php13
-rw-r--r--frontends/php/include/page_header.php91
-rw-r--r--frontends/php/include/perm.inc.php2
-rw-r--r--frontends/php/popup_right.php33
-rw-r--r--frontends/php/users.php2
-rw-r--r--frontends/php/vtext.php2
8 files changed, 134 insertions, 65 deletions
diff --git a/frontends/php/exp_imp.php b/frontends/php/exp_imp.php
index b9705e1a..2dc6ccd2 100644
--- a/frontends/php/exp_imp.php
+++ b/frontends/php/exp_imp.php
@@ -94,7 +94,7 @@ include_once "include/page_header.php";
$graphs = get_request('graphs', array());
$triggers = get_request('triggers', array());
- function &zbx_array_val_inc(&$arr, $inc_size = 1)
+ function &zbx_array_val_inc($arr, $inc_size = 1)
{
foreach($arr as $id => $val)
{
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 03c3e82d..d4552616 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -68,12 +68,39 @@
}
break;
case "SQLITE3":
+ function init_db_access()
+ {
+ global $ZBX_CONFIGURATION_FILE, $ZBX_SEM_ID;
+
+ $ZBX_SEM_ID = false;
+ if(function_exists('ftok') && function_exists('sem_get'))
+ $ZBX_SEM_ID = sem_get(ftok($ZBX_CONFIGURATION_FILE, 'z'), 1);
+ }
+
+ function lock_db_access()
+ {
+ global $ZBX_SEM_ID;
+
+ if($ZBX_SEM_ID && function_exists('sem_acquire'))
+ sem_acquire($ZBX_SEM_ID);
+ }
+
+ function unlock_db_access()
+ {
+ global $ZBX_SEM_ID;
+
+ if($ZBX_SEM_ID && function_exists('sem_release'))
+ sem_release($ZBX_SEM_ID);
+ }
+
$DB = sqlite3_open($DB_DATABASE);
if(!$DB)
{
$error = "Error connecting to database";
$result = false;
}
+
+ init_db_access();
break;
default:
$error = "Unsupported database";
@@ -96,7 +123,10 @@
case "MYSQL": $result = mysql_close($DB); break;
case "POSTGRESQL": $result = pg_close($DB); break;
case "ORACLE": $result = ociclose($DB); break;
- case "SQLITE3": $result = true; sqlite3_close($DB); break;
+ case "SQLITE3":
+ $result = true;
+ sqlite3_close($DB);
+ break;
default: break;
}
}
@@ -146,6 +176,7 @@
function DBstart()
{
/* TODO *//* start transaction */
+ // lock_db_access(); /* check DBselect & DBexecute */
}
function DBend($result)
@@ -160,6 +191,7 @@
{ // FAIL
/* rollback TODO */
}
+ // unlock_db_access(); /* check DBselect & DBexecute */
}
/* NOTE:
@@ -229,6 +261,7 @@ COpt::savesqlrequest($query);
}
break;
case "SQLITE3":
+ lock_db_access();
if(!($result = sqlite3_query($DB,$query)))
{
error("Error in query [$query] [".sqlite3_error($DB)."]");
@@ -253,6 +286,7 @@ COpt::savesqlrequest($query);
$result = &$data;
}
+ unlock_db_access();
break;
}
@@ -289,11 +323,13 @@ COpt::savesqlrequest($query);
}
break;
case "SQLITE3":
+ lock_db_access();
$result = sqlite3_exec($DB, $query);
if(!$result)
{
error("Error in query [$query] [".sqlite3_error($DB)."]");
}
+ unlock_db_access();
break;
}
@@ -347,6 +383,19 @@ if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
}
}
+ function zbx_dbconcat($params)
+ {
+ global $DB_TYPE;
+
+ switch($DB_TYPE)
+ {
+ case "SQLITE3":
+ return implode(' || ',$params);
+ default:
+ return 'CONCAT('.implode(',',$params).')';
+ }
+ }
+
function DBid2nodeid($id_name)
{
global $DB_TYPE;
@@ -365,8 +414,7 @@ if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
{
global $ZBX_CURNODEID;
- $result=DBselect("select max($field) as id from $table where ".DBid2nodeid($field)." in (".$ZBX_CURNODEID.")");
- $row=DBfetch($result);
+ $row=DBfetch(DBselect("select max($field) as id from $table where ".DBid2nodeid($field)." in (".$ZBX_CURNODEID.")"));
if($row && !is_null($row["id"]))
{
return bcadd($row["id"],1);
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index fa28d98b..48401b9c 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -463,18 +463,21 @@
$group_rights = array();
$sqls = array(
- 'select r.*i,n.name as name from rights r, nodes n where r.groupid='.$_REQUEST["usrgrpid"].
+ 'select r.*,n.name as name from rights r, nodes n where r.groupid='.$_REQUEST["usrgrpid"].
' and r.type='.RESOURCE_TYPE_NODE.' and r.id=n.nodeid',
- 'select r.*i, CONCAT(n.name,":",g.name) as name from rights r, groups g, nodes n'.
- ' where r.groupid='.$_REQUEST["usrgrpid"].' and n.nodeid='.DBid2nodeid('g.groupid').
- ' and r.type='.RESOURCE_TYPE_GROUP.' and r.id=g.groupid',
-
+ 'select r.*, n.name as node_name, g.name as name from groups g '.
+ ' left join rights r on r.type='.RESOURCE_TYPE_GROUP.' and r.id=g.groupid '.
+ ' left join nodes n on n.nodeid='.DBid2nodeid('g.groupid').
+ ' where r.groupid='.$_REQUEST["usrgrpid"],
);
foreach($sqls as $sql)
{
$db_rights = DBselect($sql);
while($db_right = DBfetch($db_rights))
{
+ if(isset($db_right['node_name']))
+ $db_right['name'] = $db_right['node_name'].':'.$db_right['name'];
+
$group_rights[$db_right['name']] = array(
'type' => $db_right['type'],
'permission' => $db_right['permission'],
diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php
index 8bd598e1..9e799dac 100644
--- a/frontends/php/include/page_header.php
+++ b/frontends/php/include/page_header.php
@@ -43,11 +43,23 @@ COpt::profiling_start("page");
include_once "include/locales/".$USER_DETAILS["lang"].".inc.php";
process_locales();
}
+ else
+ {
+ $USER_DETAILS = array(
+ "alias" =>"guest",
+ "userid"=>0,
+ "lang" =>"en_gb",
+ "type" =>"0",
+ "node" =>array(
+ "name" =>'- uncnown -',
+ "nodeid"=>0));
+ }
+
include_once "include/locales/en_gb.inc.php";
process_locales();
/* Init CURRENT NODE ID */
- if(ZBX_DISTRIBUTED)
+ if(!defined('ZBX_PAGE_NO_AUTHERIZATION') && ZBX_DISTRIBUTED)
{
$ZBX_CURNODEID = get_cookie('current_nodeid', $ZBX_LOCALNODEID); // Selected node
if(isset($_REQUEST['switch_node']))
@@ -227,20 +239,6 @@ COpt::profiling_start("page");
)
);
-
- $help = new CLink(S_HELP, "http://www.zabbix.com/manual/v1.1/index.php", "small_font");
- $help->SetTarget('_blank');
- $page_header_r_col = array($help,
- ($USER_DETAILS["alias"] != "guest") ?
- array("|", new CLink(S_PROFILE, "profile.php", "small_font")) :
- null
- );
- $logo = new CLink(new CImg("images/general/zabbix.png","ZABBIX"),"http://www.zabbix.com");
- $logo->SetTarget('_blank');
-
- $top_page_row = array(new CCol($logo, "page_header_l"), new CCol($page_header_r_col, "page_header_r"));
- unset($logo, $page_header_r_col, $help);
-
$main_menu_row = array();
$sub_menu_row = array();
@@ -248,30 +246,33 @@ COpt::profiling_start("page");
{
// Check permissions
unset($deny);
- if($label!='login' && !isset($USER_DETAILS['type']))
- {
- $deny = true;
- }
- elseif($label=='admin' && (!in_array($USER_DETAILS['type'], array(USER_TYPE_SUPER_ADMIN)) ||
- !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
- $USER_DETAILS,PERM_READ_WRITE,null,
- PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))))
- {
- $deny = true;
- }
- elseif($label=='config' && (
- !in_array($USER_DETAILS['type'], array(USER_TYPE_SUPER_ADMIN, USER_TYPE_ZABBIX_ADMIN)) ||
- !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
- $USER_DETAILS,PERM_READ_LIST,null,
- PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))))
+ if(!defined('ZBX_PAGE_NO_AUTHERIZATION'))
{
- $deny = true;
- }
- elseif(!in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
- $USER_DETAILS,PERM_READ_LIST,null,
- PERM_RES_IDS_ARRAY,$ZBX_CURNODEID)))
- {
- $deny = true;
+ if($label!='login' && !isset($USER_DETAILS['type']))
+ {
+ $deny = true;
+ }
+ elseif($label=='admin' && (!in_array($USER_DETAILS['type'], array(USER_TYPE_SUPER_ADMIN)) ||
+ !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
+ $USER_DETAILS,PERM_READ_WRITE,null,
+ PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))))
+ {
+ $deny = true;
+ }
+ elseif($label=='config' && (
+ !in_array($USER_DETAILS['type'], array(USER_TYPE_SUPER_ADMIN, USER_TYPE_ZABBIX_ADMIN)) ||
+ !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
+ $USER_DETAILS,PERM_READ_LIST,null,
+ PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))))
+ {
+ $deny = true;
+ }
+ elseif(!in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
+ $USER_DETAILS,PERM_READ_LIST,null,
+ PERM_RES_IDS_ARRAY,$ZBX_CURNODEID)))
+ {
+ $deny = true;
+ }
}
// End of check permissions
@@ -344,9 +345,21 @@ COpt::profiling_start("page");
if(!defined('ZBX_PAGE_NO_MENU'))
{
-
COpt::compare_files_with_menu($ZBX_MENU);
+ $help = new CLink(S_HELP, "http://www.zabbix.com/manual/v1.1/index.php", "small_font");
+ $help->SetTarget('_blank');
+ $page_header_r_col = array($help,
+ ($USER_DETAILS["alias"] != "guest") ?
+ array("|", new CLink(S_PROFILE, "profile.php", "small_font")) :
+ null
+ );
+ $logo = new CLink(new CImg("images/general/zabbix.png","ZABBIX"),"http://www.zabbix.com");
+ $logo->SetTarget('_blank');
+
+ $top_page_row = array(new CCol($logo, "page_header_l"), new CCol($page_header_r_col, "page_header_r"));
+ unset($logo, $page_header_r_col, $help);
+
$table = new CTable(NULL,"page_header");
$table->SetCellSpacing(0);
$table->SetCellPadding(5);
diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php
index fda4a822..9c3f468e 100644
--- a/frontends/php/include/perm.inc.php
+++ b/frontends/php/include/perm.inc.php
@@ -91,7 +91,7 @@
else
{
$USER_DETAILS = array(
- "alias" =>"- unknown -",
+ "alias" =>"guest",
"userid"=>0,
"lang" =>"en_gb",
"type" =>"0",
diff --git a/frontends/php/popup_right.php b/frontends/php/popup_right.php
index 17dcbc11..70a69166 100644
--- a/frontends/php/popup_right.php
+++ b/frontends/php/popup_right.php
@@ -35,7 +35,7 @@ include_once "include/page_header.php";
$fields=array(
"dstfrm"=> array(T_ZBX_STR, O_MAND,P_SYS, NOT_EMPTY, NULL),
"permission"=> array(T_ZBX_INT, O_MAND,P_SYS, IN(PERM_DENY.','.PERM_READ_ONLY.','.PERM_READ_WRITE), NULL),
- "type"=> array(T_ZBX_INT, O_OPT, P_SYS, IN(RESOURCE_TYPE_NODE.','.RESOURCE_TYPE_GROUP), NULL)
+ "type"=> array(T_ZBX_INT, O_OPT, P_SYS, IN(RESOURCE_TYPE_GROUP.(ZBX_DISTRIBUTED ? RESOURCE_TYPE_NODE.',' : '')), NULL)
);
check_fields($fields);
@@ -84,12 +84,15 @@ function add_right(formname,type,id,permission,name)
$frmTitle = new CForm();
$frmTitle->AddVar('dstfrm',$dstfrm);
$frmTitle->AddVar('permission', $permission);
- $cmbResourceType = new CComboBox('type',$type,'submit();');
- $cmbResourceType->AddItem(RESOURCE_TYPE_NODE, S_NODES);
- $cmbResourceType->AddItem(RESOURCE_TYPE_GROUP, S_HOST_GROUPS);
- $frmTitle->AddItem(array(
- S_RESOURCE_TYPE, SPACE,
- $cmbResourceType));
+ if(ZBX_DISTRIBUTED)
+ {
+ $cmbResourceType = new CComboBox('type',$type,'submit();');
+ $cmbResourceType->AddItem(RESOURCE_TYPE_NODE, S_NODES);
+ $cmbResourceType->AddItem(RESOURCE_TYPE_GROUP, S_HOST_GROUPS);
+ $frmTitle->AddItem(array(
+ S_RESOURCE_TYPE, SPACE,
+ $cmbResourceType));
+ }
show_table_header(permission2str($permission),$frmTitle);
$table = new CTableInfo(S_NO_RESOURCES_DEFINED);
@@ -97,26 +100,26 @@ function add_right(formname,type,id,permission,name)
$db_resources = null;
- if($type == RESOURCE_TYPE_NODE)
+ if(ZBX_DISTRIBUTED && $type == RESOURCE_TYPE_NODE)
{
$db_resources = DBselect('select n.name as name, n.nodeid as id from nodes n order by n.name');
}
elseif($type == RESOURCE_TYPE_GROUP)
{
- $db_resources = DBselect('select CONCAT(n.name,":",g.name) as name, g.groupid as id from groups g, nodes n '.
- ' where '.DBid2nodeid('g.groupid').'=n.nodeid order by n.name, g.name');
-
-
+ $db_resources = DBselect('select n.name as node_name, g.name as name, g.groupid as id'.
+ ' from groups g left join nodes n on '.DBid2nodeid('g.groupid').'=n.nodeid '.
+ ' order by n.name, g.name');
}
while($db_resource = DBfetch($db_resources))
{
+ if(isset($db_resource['node_name']))
+ $db_resource['name'] = $db_resource['node_name'].':'.$db_resource['name'];
+
$name = new CLink($db_resource['name'],'#','action');
$name->SetAction("return add_right('".$dstfrm."',".$type.",".$db_resource['id'].",".$permission.",'".$db_resource['name']."');");
- $table->AddRow(array(
- $name
- ));
+ $table->AddRow(array($name));
}
$table->Show();
diff --git a/frontends/php/users.php b/frontends/php/users.php
index 78a4c7d4..dd582a16 100644
--- a/frontends/php/users.php
+++ b/frontends/php/users.php
@@ -365,7 +365,7 @@ include_once "include/page_header.php";
}
else
{
- $form = new CForm();
+ $form = new CForm(null,'post');
$form->SetName('users');
show_table_header(S_USERS_BIG);
diff --git a/frontends/php/vtext.php b/frontends/php/vtext.php
index 5da4c61a..5d0fc70f 100644
--- a/frontends/php/vtext.php
+++ b/frontends/php/vtext.php
@@ -23,6 +23,8 @@
$page['file'] = 'vtext.php';
$page['type'] = PAGE_TYPE_IMAGE;
+
+ define('ZBX_PAGE_NO_AUTHERIZATION', 1);
include_once "include/page_header.php";