Module: nagvis
Branch: master
Commit: 1860288c98efc319d4f58d7929093adc09a37fd3
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=1860288c98efc319d4f58d7929093adc09a37fd3

Author: Lars Michelsen <[email protected]>
Date:   Thu Sep 30 19:58:39 2010 +0200

Also added the new permissions to MySQL auth module and added the update code 
to MYSQL auth module

---

 share/server/core/classes/CoreMySQLHandler.php  |   85 +++++++++++++++++------
 share/server/core/classes/CoreSQLiteHandler.php |   13 +---
 share/server/core/classes/GlobalCore.php        |   17 +++++
 3 files changed, 82 insertions(+), 33 deletions(-)

diff --git a/share/server/core/classes/CoreMySQLHandler.php 
b/share/server/core/classes/CoreMySQLHandler.php
index 794aeb5..2adf348 100644
--- a/share/server/core/classes/CoreMySQLHandler.php
+++ b/share/server/core/classes/CoreMySQLHandler.php
@@ -187,35 +187,53 @@ class CoreMySQLHandler {
        }
 
        public function updateDb() {
-               if(!$this->tableExist('version')) {
-                       // Perform pre b4 updates
-                       $this->updateDb15b4();
-               }
-       }
+               // Read the current version from db
+               $dbVersion = 
GlobalCore::getInstance()->versionToTag($this->getDbVersion());
 
-       private function updateDb15b4() {
-               if(DEBUG&&DEBUGLEVEL&2) debug('MySQLHandler: Performing update 
to 1.5b4 scheme');
-               
-               $this->createVersionTable();
+               // Now perform the update for pre 1.5.3
+               if($dbVersion < 1050300)
+                       $this->updateDb1050300();
+       }
 
-               // Add addModify permission
-               $RES = $this->query('SELECT obj FROM perms WHERE `mod`=\'Map\' 
AND `act`=\'view\'');
-               while($data = $this->fetchAssoc($RES)) {
-                       if(DEBUG&&DEBUGLEVEL&2) debug('MySQLHandler: Adding new 
addModify perms for map '.$data['obj']);
-                       $this->query('INSERT INTO perms (`mod`, `act`, obj) 
VALUES (\'Map\', \'addModify\', '.$this->escape($data['obj']).')');
-               }
+       private function updateDb1050300() {
+               // Create permissions for WUI management pages
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'manage\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'view\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'doCreate\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'doUpload\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'doDelete\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'manage\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'view\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'doUpload\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'doDelete\', \'*\')');
 
-               // Assign the addModify permission to the managers
+               // Assign the new permission to the managers
                $RES = $this->query('SELECT roleId FROM roles WHERE 
name=\'Managers\'');
                while($data = $this->fetchAssoc($RES)) {
-                       if(DEBUG&&DEBUGLEVEL&2) debug('MySQLHandler: Assigning 
addModify perms to Managers role');
-                       $this->addRolePerm($data['roleId'], 'Map', 'addModify', 
'*');
+                       $this->addRolePerm($data['roleId'], 
'ManageBackgrounds', 'manage', '*');
+                       $this->addRolePerm($data['roleId'], 
'ManageBackgrounds', 'view', '*');
+                       $this->addRolePerm($data['roleId'], 
'ManageBackgrounds', 'doCreate', '*');
+                       $this->addRolePerm($data['roleId'], 
'ManageBackgrounds', 'doUpload', '*');
+                       $this->addRolePerm($data['roleId'], 
'ManageBackgrounds', 'doDelete', '*');
+                       $this->addRolePerm($data['roleId'], 'ManageShapes', 
'manage', '*');
+                       $this->addRolePerm($data['roleId'], 'ManageShapes', 
'view', '*');
+                       $this->addRolePerm($data['roleId'], 'ManageShapes', 
'doUpload', '*');
+                       $this->addRolePerm($data['roleId'], 'ManageShapes', 
'doDelete', '*');
                }
+
+               // Only apply the new version when this is the real release or 
newer
+               // (While development the version string remains on the old 
value)
+               if(GlobalCore::getInstance()->versionToTag(CONST_VERSION) >= 
1050300)
+                       $this->updateDbVersion();
        }
 
-       private function createVersionTable() {
-               $this->query('CREATE TABLE version (version VARCHAR(100), 
PRIMARY KEY(version))');
-               $this->query('INSERT INTO version (version) VALUES 
(\''.CONST_VERSION.'\')');
+       private function getDbVersion() {
+               $data = $this->fetchAssoc($this->query('SELECT version FROM 
version'));
+               return $data['version'];
+       }
+
+       private function updateDbVersion() {
+               $this->query('UPDATE version SET version=\'' . CONST_VERSION . 
'\'');
        }
        
        public function createInitialDb() {
@@ -225,7 +243,8 @@ class CoreMySQLHandler {
                $this->query('CREATE TABLE users2roles (userId INTEGER, roleId 
INTEGER, PRIMARY KEY(userId, roleId))');
                $this->query('CREATE TABLE roles2perms (roleId INTEGER, permId 
INTEGER, PRIMARY KEY(roleId, permId))');
 
-               $this->createVersionTable();
+               $this->query('CREATE TABLE version (version VARCHAR(100), 
PRIMARY KEY(version))');
+               $this->query('INSERT INTO version (version) VALUES 
(\''.CONST_VERSION.'\')');
                
                $this->query('INSERT INTO users (userId, name, password) VALUES 
(1, \'nagiosadmin\', \'7f09c620da83db16ef9b69abfb8edd6b849d2d2b\')');
                $this->query('INSERT INTO users (userId, name, password) VALUES 
(2, \'guest\', \'7f09c620da83db16ef9b69abfb8edd6b849d2d2b\')');
@@ -300,6 +319,17 @@ class CoreMySQLHandler {
                $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'RoleMgmt\', \'doAdd\', \'*\')');
                $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'RoleMgmt\', \'doEdit\', \'*\')');
                $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'RoleMgmt\', \'doDelete\', \'*\')');
+
+               // Access control: WUI Management pages
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'manage\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'view\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'doCreate\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'doUpload\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageBackgrounds\', \'doDelete\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'manage\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'view\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'doUpload\', \'*\')');
+               $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'ManageShapes\', \'doDelete\', \'*\')');
                
                // Access controll: Edit/Delete maps and automaps
                $this->query('INSERT INTO perms (`mod`, `act`, obj) VALUES 
(\'Map\', \'add\', \'*\')');
@@ -359,6 +389,17 @@ class CoreMySQLHandler {
                // Access assignment: Managers => Allowed to create automaps
                $this->addRolePerm($data['roleId'], 'AutoMap', 'add', '*');
                $this->addRolePerm($data['roleId'], 'AutoMap', 'doAdd', '*');
+
+               // Access assignment: Managers => Allowed to manage backgrounds 
and shapes
+               $this->addRolePerm($data['roleId'], 'ManageBackgrounds', 
'manage', '*');
+               $this->addRolePerm($data['roleId'], 'ManageBackgrounds', 
'view', '*');
+               $this->addRolePerm($data['roleId'], 'ManageBackgrounds', 
'doCreate', '*');
+               $this->addRolePerm($data['roleId'], 'ManageBackgrounds', 
'doUpload', '*');
+               $this->addRolePerm($data['roleId'], 'ManageBackgrounds', 
'doDelete', '*');
+               $this->addRolePerm($data['roleId'], 'ManageShapes', 'manage', 
'*');
+               $this->addRolePerm($data['roleId'], 'ManageShapes', 'view', 
'*');
+               $this->addRolePerm($data['roleId'], 'ManageShapes', 'doUpload', 
'*');
+               $this->addRolePerm($data['roleId'], 'ManageShapes', 'doDelete', 
'*');
                
                // Access assignment: Managers => Allowed to view the overview
                $this->addRolePerm($data['roleId'], 'Overview', 'view', '*');
diff --git a/share/server/core/classes/CoreSQLiteHandler.php 
b/share/server/core/classes/CoreSQLiteHandler.php
index 9a7a4d0..660c43a 100644
--- a/share/server/core/classes/CoreSQLiteHandler.php
+++ b/share/server/core/classes/CoreSQLiteHandler.php
@@ -180,22 +180,13 @@ class CoreSQLiteHandler {
                $this->DB->query('INSERT INTO roles2perms (roleId, permId) 
VALUES ('.$roleId.', (SELECT permId FROM perms WHERE mod=\''.$mod.'\' AND 
act=\''.$act.'\' AND obj=\''.$obj.'\'))');
        }
 
-       private function versionToTag($s) {
-               $s = str_replace('a', '.0.0', str_replace('b', '.0.2', 
str_replace('rc', '.0.4', $s)));
-               $parts = explode('.', $s);
-               $tag = '';
-               foreach($parts AS $part)
-                       $tag .= sprintf("%02s", $part);
-               return (int) sprintf("%-08s", $tag);
-       }
-
        public function updateDb() {
                // Perform pre 1.5b4 updates
                if(!$this->tableExist('version'))
                        $this->updateDd1050024();
 
                // Read the current version from db
-               $dbVersion = $this->versionToTag($this->getDbVersion());
+               $dbVersion = 
GlobalCore::getInstance()->versionToTag($this->getDbVersion());
 
                // Now perform the update for pre 1.5.3
                if($dbVersion < 1050300)
@@ -230,7 +221,7 @@ class CoreSQLiteHandler {
 
                // Only apply the new version when this is the real release or 
newer
                // (While development the version string remains on the old 
value)
-               if($this->versionToTag(CONST_VERSION) >= 1050300)
+               if(GlobalCore::getInstance()->versionToTag(CONST_VERSION) >= 
1050300)
                        $this->updateDbVersion();
        }
 
diff --git a/share/server/core/classes/GlobalCore.php 
b/share/server/core/classes/GlobalCore.php
index db2f194..101f19f 100644
--- a/share/server/core/classes/GlobalCore.php
+++ b/share/server/core/classes/GlobalCore.php
@@ -482,5 +482,22 @@ class GlobalCore {
        public function checkSharedVarFolderWriteable($printErr) {
                return 
$this->checkWriteable(substr(self::getMainCfg()->getValue('paths', 
'sharedvar'),0,-1), $printErr);
        }
+
+       /**
+        * Transforms a NagVis version to integer which can be used
+        * for comparing different versions.
+        *
+        * @param         String    Version string
+        * @return  Integer   Version as integer
+        * @author  Lars Michelsen <[email protected]>
+        */
+       public function versionToTag($s) {
+               $s = str_replace('a', '.0.0', str_replace('b', '.0.2', 
str_replace('rc', '.0.4', $s)));
+               $parts = explode('.', $s);
+               $tag = '';
+               foreach($parts AS $part)
+                       $tag .= sprintf("%02s", $part);
+               return (int) sprintf("%-08s", $tag);
+       }
 }
 ?>


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to