[icinga-checkins] icinga.org: icinga-web/mhein/default: * Added more config options to iframe cronk

git at icinga.org git at icinga.org
Tue Jan 18 14:01:31 CET 2011


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Jan 18 13:50:42 2011 +0100

* Added more config options to iframe cronk
* Implemented iframe url as model

---

 .../Cronks/models/System/IframeUrlModel.class.php  |   75 ++++++++++++++++++++
 app/modules/Cronks/validate/System/IframeView.xml  |   27 +++++++
 .../views/System/CronkLoaderSuccessView.class.php  |   15 ++--
 .../views/System/IframeViewSuccessView.class.php   |   33 +++++++--
 etc/sitecfg/cronks.site.xml                        |   31 ++++++++-
 5 files changed, 164 insertions(+), 17 deletions(-)

diff --git a/app/modules/Cronks/models/System/IframeUrlModel.class.php b/app/modules/Cronks/models/System/IframeUrlModel.class.php
new file mode 100755
index 0000000..d3e1369
--- /dev/null
+++ b/app/modules/Cronks/models/System/IframeUrlModel.class.php
@@ -0,0 +1,75 @@
+<?php
+
+class Cronks_System_IframeUrlModel extends CronksBaseModel {
+	
+	private $baseURl = null;
+	
+	private $user = null;
+	
+	private $pass = null;
+	
+	private $params = array ();
+	
+	/**
+	 * @var AgaviRequestDataHolder
+	 */
+	private $rd = null;
+	
+	public function setBaseUrl($baseUrl) {
+		$this->baseURl = $baseUrl;
+	}
+	
+	public function setUserPassword($user, $password) {
+		$this->user = $user;
+		$this->pass = $password;
+	}
+	
+	public function setParamMapArray(array $paramMap) {
+		$this->params = $paramMap + $this->params;
+	}
+	
+	public function setRequestDataHolder(AgaviRequestDataHolder $rd) {
+		$this->rd = $rd;
+	}
+	
+	private function glueTogether() {
+		
+		$u = (string)$this->baseURl;
+		
+		if (count($this->params)) {
+			
+			$params = array ();
+			
+			foreach ($this->params as $target=>$source) {
+				$m = array ();
+				if (preg_match('/^_(\w+)\[([^\]]+)\]$/', $source, $m)) {
+					$source = $this->rd->get(strtolower($m[1]), $m[2]);
+				}
+				
+				if ($source) {
+					$params[] = sprintf('%s=%s', $target, urlencode($source));
+				}
+			}
+			
+			if (strpos($u, '?') !== false) {
+				$u .= '&'. implode('&', $params);
+			}
+			else {
+				$u .= '?'. implode('&', $params);
+			}
+			
+		}
+		
+		if ($this->user && $this->pass) {
+			$u = str_replace('://', sprintf('://%s:%s@', $this->user, $this->pass), $u);
+		}
+		
+		return $u;
+	}
+	
+	public function __toString() {
+		return $this->glueTogether();
+	}
+}
+
+?>
\ No newline at end of file
diff --git a/app/modules/Cronks/validate/System/IframeView.xml b/app/modules/Cronks/validate/System/IframeView.xml
index 887cebb..d61ec95 100755
--- a/app/modules/Cronks/validate/System/IframeView.xml
+++ b/app/modules/Cronks/validate/System/IframeView.xml
@@ -5,6 +5,16 @@
 
 		<validators>
 
+			<validator class="string" name="parameterMap" required="false">
+				<arguments base="parameterMap[]">
+					<argument />
+				</arguments>
+
+				<errors>
+					<error>Validation of parameterMap failed!</error>
+				</errors>
+			</validator>
+
 			<validator class="string" name="url" required="true">
 				<argument>url</argument>
 
@@ -52,6 +62,23 @@
 					<error>Validation of stateuid failed!</error>
 				</errors>
 			</validator>
+			
+			<!-- HEADER VALIDATORS -->
+			<validator class="string" name="http_referer" source="headers" required="false">
+				<argument>REFERER</argument>
+				
+				<errors>
+					<error>Could not validate HTTP_REFERER</error>
+				</errors>
+			</validator>
+			
+			<validator class="string" name="http_user_agent" source="headers" required="false">
+				<argument>USER_AGENT</argument>
+				
+				<errors>
+					<error>Could not validate HTTP_USER_AGENT</error>
+				</errors>
+			</validator>
 
 		</validators>
 
diff --git a/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php b/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php
index 661d78f..8fade7f 100755
--- a/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php
+++ b/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php
@@ -22,14 +22,13 @@ class Cronks_System_CronkLoaderSuccessView extends CronksBaseView
 				
 				if (array_key_exists('ae:parameter', $cronk) && is_array($cronk['ae:parameter'])) {
 					
-					foreach($cronk['ae:parameter'] as $key=>$param) {
-						if(is_array($param) || is_object($param)) {
-							$param = json_encode($param);
-							$cronk['ae:parameter'][$key] = $param;
-							$parameters[$key] = $param;
-						}
-						
-					}
+//					foreach($cronk['ae:parameter'] as $key=>$param) {
+//						if(is_array($param) || is_object($param)) {
+//							$param = json_encode($param);
+//							$cronk['ae:parameter'][$key] = $param;
+//							$parameters[$key] = $param;
+//						}
+//					}
 
 					$parameters = (array)$cronk['ae:parameter']
 					+ $parameters
diff --git a/app/modules/Cronks/views/System/IframeViewSuccessView.class.php b/app/modules/Cronks/views/System/IframeViewSuccessView.class.php
index 6a45dda..db45ccb 100755
--- a/app/modules/Cronks/views/System/IframeViewSuccessView.class.php
+++ b/app/modules/Cronks/views/System/IframeViewSuccessView.class.php
@@ -1,20 +1,37 @@
 <?php
 
-class Cronks_System_IframeViewSuccessView extends CronksBaseView
-{
-	public function executeHtml(AgaviRequestDataHolder $rd)
-	{
+class Cronks_System_IframeViewSuccessView extends CronksBaseView {
+	
+	/**
+	 * @var Cronks_System_IframeUrlModel
+	 */
+	private $url = null;
+	
+	public function initialize(AgaviExecutionContainer $container) {
+		parent::initialize($container);
+		
+		$this->url = $this->getContext()->getModel('System.IframeUrl', 'Cronks');
+		
+	}
+	
+	public function executeHtml(AgaviRequestDataHolder $rd) {
 		$this->setupHtml($rd);
 
 		$this->setAttribute('_title', 'Icinga.Cronks.IframeView');
 		
-		$url = $rd->getParameter('url');
+		$this->url->setBaseUrl($rd->getParameter('url'));
 		
-		if ($rd->getParameter('user') && $rd->getParameter('password')) {
-			$url = preg_replace('@:\/\/@', sprintf('://%s:%s@', $rd->getParameter('user'), $rd->getParameter('password')), $url, 1);
+		if ($rd->hasParameter('user') && $rd->hasParameter('password')) {
+			$this->url->setUserPassword($rd->getParameter('user'), $rd->getParameter('password'));
 		}
 		
-		$this->setAttribute('url', $url);
+		if ($rd->hasParameter('parameterMap')) {
+			$this->url->setParamMapArray($rd->getParameter('parameterMap'));
+		}
+		
+		$this->url->setRequestDataHolder($rd);
+		
+		$this->setAttribute('url', (string)$this->url);
 	}
 }
 
diff --git a/etc/sitecfg/cronks.site.xml b/etc/sitecfg/cronks.site.xml
index eedc34b..bdfd242 100644
--- a/etc/sitecfg/cronks.site.xml
+++ b/etc/sitecfg/cronks.site.xml
@@ -9,6 +9,35 @@
 -->
 
 	<setting name="cronks">
+
+	<!--
+		<ae:parameter name="iframeViewIcingaBlog">
+			<ae:parameter name="module">Cronks</ae:parameter>
+			<ae:parameter name="action">System.IframeView</ae:parameter>
+			<ae:parameter name="hide">false</ae:parameter>
+			<ae:parameter name="description">View icinga latest news</ae:parameter>
+			<ae:parameter name="name">Icinga Blog</ae:parameter>
+			<ae:parameter name="image">cronks.world</ae:parameter>
+			<ae:parameter name="categories">my</ae:parameter>
+			<ae:parameter name="ae:parameter">
+				<ae:parameter name="url"><![CDATA[http://foo.bar/tests/phpinfo.php]]></ae:parameter>
+				
+				* Adding username and password to iframe
+				<ae:parameter name="user"></ae:parameter>
+				<ae:parameter name="password"></ae:parameter>
+
+				* Adding parameters to URL
+				<ae:parameter name="parameterMap">
+					* Arguments from request (in IframeView.xml validators)
+					<ae:parameter name="referer">_HEADERS[REFERER]</ae:parameter>
+					
+					* Simple parameters
+					<ae:parameter name="simpleargument">simplevalue</ae:parameter>
+				</ae:parameter>
+			</ae:parameter>
+		</ae:parameter>
+	-->
+	
 	<!--	
 		<ae:parameter name="iframeViewIcingaBlog">
 			<ae:parameter name="module">Cronks</ae:parameter>
@@ -36,4 +65,4 @@
 	-->
 	</setting>
 
-</settings>
\ No newline at end of file
+</settings>





More information about the icinga-checkins mailing list