[icinga-checkins] icinga.org: icinga-web/master: * Added command if and removed a lot of debug messages

git at icinga.org git at icinga.org
Wed Sep 29 16:23:01 CEST 2010


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

Author: jmosshammer <jannis.mosshammer at netways.com>
Date:   Wed Sep 29 16:15:46 2010 +0200

* Added command if and removed a lot of debug messages

---

 app/config/routing.xml                             |    8 ++
 .../AppKit/templates/Admin/Users/EditSuccess.php   |    2 +-
 .../AppKit/templates/Admin/Users/IndexSuccess.php  |    1 -
 app/modules/Cronks/lib/js/grid/GridPanel.js        |    1 -
 .../Web/actions/Icinga/ApiCommandAction.class.php  |  103 ++++++++++++++++++++
 app/modules/Web/validate/Icinga/ApiCommand.xml     |   37 +++++++
 .../Web/views/Icinga/ApiCommandErrorView.class.php |   19 ++++
 .../views/Icinga/ApiCommandSuccessView.class.php   |   19 ++++
 8 files changed, 187 insertions(+), 3 deletions(-)

diff --git a/app/config/routing.xml b/app/config/routing.xml
index 2ae7ad1..b5e2223 100755
--- a/app/config/routing.xml
+++ b/app/config/routing.xml
@@ -108,6 +108,12 @@
 					<route name=".json" pattern="^/json" action="Icinga.ApiSimpleDataProvider"/>
 				</route>
 				<route name=".api" pattern="^/api" action="Icinga.ApiSearch">
+					<route name=".command" stop="false" pattern="^/cmd/" output_type="json" action="Icinga.ApiCommand">
+						<route name=".cmdParam" stop="false" pattern="cmd=(command:[^/]*)/" />
+						<route name=".authkey" stop="false" pattern="authkey=(authkey:[^/]*)" />
+						<route name=".data" stop="false" pattern="data=(data:[^/]*)" />
+						<route name=".target" stop="false" pattern="target=(target:[^/]*)" />
+					</route>
 					<route name=".target" stop="false" pattern="^/(target:instance|host|service|hostgroup|servicegroup|customvariable|contact|contactgroup|timeperiod|hoststatus|servicestatus|hosttimes|servicetimes|config|program|log|host_status_summary|service_status_summary|host_status_history|service_status_history|host_parents|notifications|hostgroup_summary|servicegroup_summary|command|downtime|comment|status|host_service)/">
 						<!-- Filter will be split by AppKitUrlFilterValidator -->
 						<route name=".authkey" stop="false" pattern="authkey=(authkey:[^/]*)"/>
@@ -123,6 +129,7 @@
 							<ignore>output</ignore>
 						</ignores>
 					</route>
+
 						<!--  Define the ouput type -->
 					</route>
 					<route name=".output" stop="true" pattern="(output:json|xml)$" output_type="${output}">
@@ -130,6 +137,7 @@
 							<ignore>output</ignore>
 						</ignores>
 					</route>
+					
 				</route>
 			</route>
 			<!-- END: Icinga (Web) -->
diff --git a/app/modules/AppKit/templates/Admin/Users/EditSuccess.php b/app/modules/AppKit/templates/Admin/Users/EditSuccess.php
index 23afab0..3de87b3 100755
--- a/app/modules/AppKit/templates/Admin/Users/EditSuccess.php
+++ b/app/modules/AppKit/templates/Admin/Users/EditSuccess.php
@@ -275,7 +275,7 @@ Ext.onReady(function(){
 
 				 	this.objToForm(principalData.principal_values,values,"principal_value");
 					this.objToForm(principalData.principal_target,values,"principal_target");
-					AppKit.log(values);
+
 				}		
 			},
 			
diff --git a/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php b/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php
index bdd454c..e7d3f4d 100755
--- a/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php
+++ b/app/modules/AppKit/templates/Admin/Users/IndexSuccess.php
@@ -169,7 +169,6 @@ Ext.onReady(function() {
 		
 		listeners: {
 			rowdblclick: function(grid,index,_e) {
-				AppKit.log(index, grid.getStore().getAt(index).get("user_id"));
 				var id = grid.getStore().getAt(index).get("user_id");
 				wnd_userEditPanel.editUser(id);											
 			},
diff --git a/app/modules/Cronks/lib/js/grid/GridPanel.js b/app/modules/Cronks/lib/js/grid/GridPanel.js
index be028ff..05fe3bf 100755
--- a/app/modules/Cronks/lib/js/grid/GridPanel.js
+++ b/app/modules/Cronks/lib/js/grid/GridPanel.js
@@ -80,7 +80,6 @@ Cronk.grid.GridPanel = Ext.extend(Ext.grid.GridPanel, {
 					if(autoRefreshDefault) {
 						this.trefresh = AppKit.getTr().start({
 							run: function() {
-								AppKit.log("!");
 								this.getStore().reload();
 							},
 							interval: (autoRefresh*1000),
diff --git a/app/modules/Web/actions/Icinga/ApiCommandAction.class.php b/app/modules/Web/actions/Icinga/ApiCommandAction.class.php
new file mode 100755
index 0000000..2dc639a
--- /dev/null
+++ b/app/modules/Web/actions/Icinga/ApiCommandAction.class.php
@@ -0,0 +1,103 @@
+<?php
+
+class Web_Icinga_ApiCommandAction extends IcingaWebBaseAction
+{
+	/**
+	 * Returns the default view if the action does not serve the request
+	 * method used.
+	 *
+	 * @return     mixed <ul>
+	 *                     <li>A string containing the view name associated
+	 *                     with this action; or</li>
+	 *                     <li>An array with two indices: the parent module
+	 *                     of the view to be executed and the view to be
+	 *                     executed.</li>
+	 *                   </ul>
+	 */
+
+	public function getDefaultViewName()
+	{
+		return 'Success';
+	}
+
+	public function checkAuth(AgaviRequestDataHolder $rd) {
+		$user = $this->getContext()->getUser();
+		$authKey = $rd->getParameter("authkey");
+		$validation = $this->getContainer()->getValidationManager();
+
+		if(!$user->isAuthenticated() && $authKey) {
+			try {
+				$user->doAuthKeyLogin($authKey);
+			} catch(Exception $e) {
+				$validation->setError("Login error","Invalid Auth key!");
+				return false;
+			}
+		}
+
+		if(!$user->isAuthenticated()) {
+			$validation->setError("Login error","Not logged in!");
+			return false;
+		}
+
+		if($user->hasCredential("appkit.api.access") || $user->hasCredential("appkit.user"))
+			return true;
+
+		$validation->setError("Error","Invalid credentials for api access!");
+		return false;
+	}
+	
+	
+	
+	public function executeRead(AgaviRequestDataHolder $rd) {
+		$this->executeWrite($rd);
+		
+	}
+
+	public function executeWrite(AgaviRequestDataHolder $rd) {
+        if(!$this->checkAuth($rd))
+			return "Error";
+		$command = $rd->getParameter("command");
+
+		$targets = json_decode($rd->getParameter("target"),true);
+		$data = json_decode($rd->getParameter("data"),true);
+	
+		if(!is_array($targets))
+			$targets = array($targets);
+		$api = $this->getContext()->getModel("Icinga.ApiContainer","Web");
+
+		$commands = $this->buildCommandArray($command,$targets,$data);
+
+		// send it
+		try {
+			$api->dispatchCommandArray($commands);
+			$this->setAttribute("success",true);
+		} catch(IcingaApiCommandException $e) {
+			$str= "";
+			foreach($api->getLastErrors() as $err) {
+				$str .= $err->getMessage()."\n";
+			}	
+			$this->setAttribute("error",$str);
+		}
+		return 'Success';
+	}
+
+	private function buildCommandArray($command,array $targets, $data) {
+		$commands = array();
+		foreach($targets as $target)	{
+			$cmd = IcingaApi::getCommandObject();
+			$cmd->setCommand($command);
+			foreach($target as $field=>$value) {
+				
+				$cmd->setTarget($field,$value);
+			}
+			foreach($data as $field=>$value) {
+				
+				$cmd->setTarget($field,$value);
+			}
+			$commands[] = $cmd;
+		}
+		return $commands;
+	}
+}
+
+?>
diff --git a/app/modules/Web/templates/Icinga/ApiCommandError.php b/app/modules/Web/templates/Icinga/ApiCommandError.php
new file mode 100644
index 0000000..e69de29
diff --git a/app/modules/Web/templates/Icinga/ApiCommandSuccess.php b/app/modules/Web/templates/Icinga/ApiCommandSuccess.php
new file mode 100755
index 0000000..e69de29
diff --git a/app/modules/Web/validate/Icinga/ApiCommand.xml b/app/modules/Web/validate/Icinga/ApiCommand.xml
new file mode 100755
index 0000000..e505d0b
--- /dev/null
+++ b/app/modules/Web/validate/Icinga/ApiCommand.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ae:configurations
+	xmlns="http://agavi.org/agavi/config/parts/validators/1.0"
+	xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"
+	parent="%core.module_dir%/Web/config/validators.xml"
+>
+	<ae:configuration>
+		
+		<validators>
+			<validator name="command" class="string" required="true">
+				<argument>command</argument>
+				<errors>
+					<error>Command parameter is required</error>
+				</errors>
+			</validator>
+			<validator name="target" class="string" required="true">
+				<argument>target</argument>
+				<errors>
+					<error>Target parameter is required</error>
+				</errors>
+			</validator>
+			<validator name="data" class="string" required="true">
+				<argument>data</argument>
+				<errors>
+					<error>Data parameter is required</error>
+				</errors>
+			</validator>
+                        <validator name="authkey" class="string" required="false">
+				<argument>authkey</argument>
+				<errors>
+					<error>Validation of authkey failed!</error>
+				</errors>
+			</validator>
+		</validators>
+		
+	</ae:configuration>
+</ae:configurations>
diff --git a/app/modules/Web/views/Icinga/ApiCommandErrorView.class.php b/app/modules/Web/views/Icinga/ApiCommandErrorView.class.php
new file mode 100644
index 0000000..057a127
--- /dev/null
+++ b/app/modules/Web/views/Icinga/ApiCommandErrorView.class.php
@@ -0,0 +1,19 @@
+<?php
+
+class Web_Icinga_ApiCommandSuccessView extends IcingaWebBaseView
+{
+	public function executeHtml(AgaviRequestDataHolder $rd)
+	{
+		$this->setupHtml($rd);
+
+		$this->setAttribute('_title', 'Icinga.ApiCommand');
+	}
+
+	public function executeJson(AgaviRequestDataHolder $rd)
+	{
+		return json_encode(array("success"=>false));
+
+	}
+}
+
+?>
\ No newline at end of file
diff --git a/app/modules/Web/views/Icinga/ApiCommandSuccessView.class.php b/app/modules/Web/views/Icinga/ApiCommandSuccessView.class.php
new file mode 100755
index 0000000..3a50e9c
--- /dev/null
+++ b/app/modules/Web/views/Icinga/ApiCommandSuccessView.class.php
@@ -0,0 +1,19 @@
+<?php
+
+class Web_Icinga_ApiCommandSuccessView extends IcingaWebBaseView
+{
+	public function executeHtml(AgaviRequestDataHolder $rd)
+	{
+		$this->setupHtml($rd);
+
+		$this->setAttribute('_title', 'Icinga.ApiCommand');
+	}
+
+	public function executeJson(AgaviRequestDataHolder $rd)
+	{
+
+
+	}
+}
+
+?>
\ No newline at end of file





More information about the icinga-checkins mailing list