[icinga-checkins] icinga.org: icinga-web/master: * Authority objects for object search

git at icinga.org git at icinga.org
Mon Jan 11 13:48:16 CET 2010


Module: icinga-web
Branch: master
Commit: a0c38968f629d0075b98b99ab775b89b60dc99d5
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=a0c38968f629d0075b98b99ab775b89b60dc99d5

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Dec 29 17:31:49 2009 +0100

* Authority objects for object search

---

 .../principal/IcingaPrincipalTargetTool.class.php  |   11 ++++--
 .../AppKit/models/PrincipalAdminModel.class.php    |    8 +++--
 .../System/ObjectSearchResultModel.class.php       |   35 +++++++++++++++++---
 doc/CHANGELOG                                      |    5 ++-
 4 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/app/lib/icinga/principal/IcingaPrincipalTargetTool.class.php b/app/lib/icinga/principal/IcingaPrincipalTargetTool.class.php
index ae5038c..dedd5a8 100644
--- a/app/lib/icinga/principal/IcingaPrincipalTargetTool.class.php
+++ b/app/lib/icinga/principal/IcingaPrincipalTargetTool.class.php
@@ -6,12 +6,10 @@ class IcingaPrincipalTargetTool {
 		$user = AgaviContext::getInstance()->getUser()->getNsmUser();
 		
 		$sarr = $user->getTargetValuesArray();
-		
 		$parts = array ();
 		foreach ($models as $model) {
 			if (isset($sarr[$model])) {
 				$to = $user->getTarget($model)->getTargetObject();
-				
 				if (count($sarr[$model]) > 0) {
 					foreach ($sarr[$model] as $vdata) {
 						$parts[] = $to->getMapArray($vdata);
@@ -27,9 +25,14 @@ class IcingaPrincipalTargetTool {
 			}
 		}
 		
-		$query = join(' OR ', $parts);
+		if (count($parts) > 0) {
+			$query = join(' OR ', $parts);
+			$search->setSearchFilterAppendix($query, IcingaApi::SEARCH_AND);
+			
+			return true;
+		}
 		
-		$search->setSearchFilterAppendix($query, IcingaApi::SEARCH_AND);
+		return false;
 	}
 	
 }
diff --git a/app/modules/AppKit/models/PrincipalAdminModel.class.php b/app/modules/AppKit/models/PrincipalAdminModel.class.php
index 4232888..2461c7e 100644
--- a/app/modules/AppKit/models/PrincipalAdminModel.class.php
+++ b/app/modules/AppKit/models/PrincipalAdminModel.class.php
@@ -57,6 +57,9 @@ class AppKit_PrincipalAdminModel extends ICINGAAppKitBaseModel
 	public function updatePrincipalValueData(NsmPrincipal &$p, array $pt, array $pv) {
 		
 		// First delete all entries we create new ones
+		/*
+		 * @todo This is not really pretty
+		 */
 		$this->deleteAllPrincipalTargetEntries($p);
 		
 		// var_dump(array($pt, $pv));
@@ -80,15 +83,12 @@ class AppKit_PrincipalAdminModel extends ICINGAAppKitBaseModel
 									$pv_val = $pv_data[$aid];
 								}
 								
-								
-								
 								$target_value = new NsmTargetValue();
 								$target_value->tv_key = $pv_key;
 								$target_value->tv_val = $pv_val;
 								
 								$principal_target->NsmTargetValue[] = $target_value;
 								
-								
 							}
 						}
 						
@@ -100,6 +100,7 @@ class AppKit_PrincipalAdminModel extends ICINGAAppKitBaseModel
 	}
 	
 	private function deleteAllPrincipalTargetEntries(NsmPrincipal &$p) {
+		
 		Doctrine_Manager::connection()->beginTransaction();
 		
 		foreach ($p->NsmPrincipalTarget as $pt) {
@@ -109,6 +110,7 @@ class AppKit_PrincipalAdminModel extends ICINGAAppKitBaseModel
 				
 		Doctrine_Manager::connection()->commit();
 		
+		return true;
 	}
 	
 }
diff --git a/app/modules/Cronks/models/System/ObjectSearchResultModel.class.php b/app/modules/Cronks/models/System/ObjectSearchResultModel.class.php
index d35e763..9db6953 100644
--- a/app/modules/Cronks/models/System/ObjectSearchResultModel.class.php
+++ b/app/modules/Cronks/models/System/ObjectSearchResultModel.class.php
@@ -37,6 +37,12 @@ class Cronks_System_ObjectSearchResultModel extends ICINGACronksBaseModel
 				'description'	=> 'HOST_ALIAS',
 	
 				'data1'			=> 'HOST_ADDRESS'
+			),
+			
+			'security'		=> array(
+				'IcingaHostgroup',
+				'IcingaCustomVariablePair',
+				'IcingaContactgroup'
 			)
 		),
 		
@@ -49,6 +55,13 @@ class Cronks_System_ObjectSearchResultModel extends ICINGACronksBaseModel
 				'object_id'		=> 'SERVICE_OBJECT_ID',
 				'object_name2'	=> 'HOST_NAME',
 				'description'	=> 'SERVICE_DISPLAY_NAME'
+			),
+			
+			'security'		=> array(
+				'IcingaHostgroup',
+				'IcingaServicegroup',
+				'IcingaCustomVariablePair',
+				'IcingaContactgroup'
 			)
 		),
 		
@@ -60,6 +73,10 @@ class Cronks_System_ObjectSearchResultModel extends ICINGACronksBaseModel
 				'object_name'	=> 'HOSTGROUP_NAME',
 				'object_id'		=> 'HOSTGROUP_OBJECT_ID',
 				'description'	=> 'HOSTGROUP_ALIAS'
+			),
+			
+			'security'		=> array(
+				'IcingaHostgroup'
 			)
 		),
 		
@@ -71,6 +88,10 @@ class Cronks_System_ObjectSearchResultModel extends ICINGACronksBaseModel
 				'object_name'	=> 'SERVICEGROUP_NAME',
 				'object_id'		=> 'SERVICEGROUP_OBJECT_ID',
 				'description'	=> 'SERVICEGROUP_ALIAS'
+			),
+			
+			'security'		=> array(
+				'IcingaServicegroup'
 			)
 		),
 	);
@@ -113,20 +134,24 @@ class Cronks_System_ObjectSearchResultModel extends ICINGACronksBaseModel
 		foreach ($mappings as $mapping) {
 			$md = $this->mapping[$mapping];
 			$fields = $md['fields'];
+			$security = (isset($md['security']) && is_array($md['security'])) ? $md['security'] : array();
 			
-			$result = $this->api->createSearch()
+			$search = $this->api->createSearch()
 			->setSearchTarget($md['target'])
 			->setResultColumns(array_values($md['fields']))
 			->setSearchFilter($md['search'], $this->query, IcingaApi::MATCH_LIKE)
-			->setResultType(IcingaApi::RESULT_ARRAY)
-			->fetch();
+			->setResultType(IcingaApi::RESULT_ARRAY);
+			
+			// Limiting results for security
+			IcingaPrincipalTargetTool::applyApiSecurityPrincipals($security, $search);
+			
+			$result = $search->fetch();
 			
 			$data[ $mapping ] = array (
 				'resultSuccess'		=> true,
 				'resultCount'		=> $result->getResultCount(),
 				'resultRows'		=> $this->resultToArray($result, $fields)
 			);
-			
 		}
 		
 		return $data;
@@ -138,7 +163,7 @@ class Cronks_System_ObjectSearchResultModel extends ICINGACronksBaseModel
 			$row = $oRow->getRow();
 			$tmp = array ();
 			foreach ($fieldDef as $name=>$db) {
-				$db = strtolower($db);
+				$db = strtoupper($db);
 				if (array_key_exists($db, $row)) {
 					$tmp[$name] = $row[$db];
 				}
diff --git a/doc/CHANGELOG b/doc/CHANGELOG
index 438bc80..b28db22 100755
--- a/doc/CHANGELOG
+++ b/doc/CHANGELOG
@@ -47,4 +47,7 @@
    * 2009-12-18
      * Moved icinga lib to a new place
      * Added principal target toolkit for api search queries
-     * Finished principal target framework
\ No newline at end of file
+     * Finished principal target framework
+     
+   * 2009-12-28
+     * Added full command specification
\ No newline at end of file





More information about the icinga-checkins mailing list