From 45c1060ae0cc2d8683d76bf12372fe93ad0478d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Sun, 11 Jan 2009 09:03:09 +0000
Subject: [PATCH] Adding a preproduction warning module.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1126 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/preprodwarning/default-disable        |  0
 .../preprodwarning/dictionaries/warning.php   | 20 +++++++++
 .../lib/Auth/Process/Warning.php              | 40 +++++++++++++++++
 .../templates/default/warning.php             | 45 +++++++++++++++++++
 modules/preprodwarning/www/showwarning.php    | 37 +++++++++++++++
 5 files changed, 142 insertions(+)
 create mode 100644 modules/preprodwarning/default-disable
 create mode 100644 modules/preprodwarning/dictionaries/warning.php
 create mode 100644 modules/preprodwarning/lib/Auth/Process/Warning.php
 create mode 100644 modules/preprodwarning/templates/default/warning.php
 create mode 100644 modules/preprodwarning/www/showwarning.php

diff --git a/modules/preprodwarning/default-disable b/modules/preprodwarning/default-disable
new file mode 100644
index 000000000..e69de29bb
diff --git a/modules/preprodwarning/dictionaries/warning.php b/modules/preprodwarning/dictionaries/warning.php
new file mode 100644
index 000000000..f665c4460
--- /dev/null
+++ b/modules/preprodwarning/dictionaries/warning.php
@@ -0,0 +1,20 @@
+<?php
+
+$lang = array(
+	'warning' => array (
+		'no' => 'Du har nå kommet til et test-oppsett. Dette oppsettet for autentisering er kun til bruk for testing og pre-produksjon verifikasjon. Hvis noen sendte deg en link som pekte hit, og du ikke er <i>en tester</i> så fikk du nok en feil link, og <b>skulle ikke vært her</b>.',
+		'en' => 'You are now accessing a pre-production system. This authentication setup is for testing and pre-production verification only. If someone sent you a link that pointed you here, and you are not <i>a tester</i> you probably got the wrong link, and should <b>not be here</b>.',
+	),
+	'warning_header' => array (
+		'no' => 'Advarsel om at dette er et test oppsett',
+		'en' => 'Warning about accessing a pre-production system',
+	),
+	'yes' => array (
+		'no' => 'Ja, jeg holder pĂĄ ĂĄ teste innlogging, og vet dette er et test-system.',
+		'en' => 'Yes, I know I am accessing a pre-production system',
+	),
+
+);
+
+
+?>
\ No newline at end of file
diff --git a/modules/preprodwarning/lib/Auth/Process/Warning.php b/modules/preprodwarning/lib/Auth/Process/Warning.php
new file mode 100644
index 000000000..4231f8909
--- /dev/null
+++ b/modules/preprodwarning/lib/Auth/Process/Warning.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * Give a warning that the user is accessing a test system, not a production system.
+ *
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+class sspmod_preprodwarning_Auth_Process_Warning extends SimpleSAML_Auth_ProcessingFilter {
+
+
+
+	/**
+	 * Process a authentication response.
+	 *
+	 * This function saves the state, and redirects the user to the page where the user
+	 * can authorize the release of the attributes.
+	 *
+	 * @param array $state  The state of the response.
+	 */
+	public function process(&$state) {
+		assert('is_array($state)');
+		assert('array_key_exists("UserID", $state)');
+		assert('array_key_exists("Destination", $state)');
+		assert('array_key_exists("entityid", $state["Destination"])');
+		assert('array_key_exists("metadata-set", $state["Destination"])');		
+		assert('array_key_exists("entityid", $state["Source"])');
+		assert('array_key_exists("metadata-set", $state["Source"])');
+
+		/* Save state and redirect. */
+		$id = SimpleSAML_Auth_State::saveState($state, 'consent:request');
+		$url = SimpleSAML_Module::getModuleURL('preprodwarning/showwarning.php');
+		SimpleSAML_Utilities::redirect($url, array('StateId' => $id));
+	}
+	
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/modules/preprodwarning/templates/default/warning.php b/modules/preprodwarning/templates/default/warning.php
new file mode 100644
index 000000000..a5fa9b14e
--- /dev/null
+++ b/modules/preprodwarning/templates/default/warning.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Template form for giving consent.
+ *
+ * Parameters:
+ * - 'srcMetadata': Metadata/configuration for the source.
+ * - 'dstMetadata': Metadata/configuration for the destination.
+ * - 'yesTarget': Target URL for the yes-button. This URL will receive a POST request.
+ * - 'yesData': Parameters which should be included in the yes-request.
+ * - 'noTarget': Target URL for the no-button. This URL will receive a GET request.
+ * - 'noData': Parameters which should be included in the no-request.
+ * - 'attributes': The attributes which are about to be released.
+ * - 'sppp': URL to the privacy policy of the destination, or FALSE.
+ *
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+
+
+$this->data['header'] = $this->t('{preprodwarning:warning:warning_header}');
+
+$this->includeAtTemplateBase('includes/header.php');
+
+?>
+
+<form style="display: inline; margin: 0px; padding: 0px" action="<?php echo htmlspecialchars($this->data['yesTarget']); ?>">
+
+	<?php
+		// Embed hidden fields...
+		foreach ($this->data['yesData'] as $name => $value) {
+			echo('<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />');
+		}
+	?>
+	<p><?php echo $this->t('{preprodwarning:warning:warning}'); ?></p>
+
+	<input type="submit" name="yes" id="yesbutton" value="<?php echo htmlspecialchars($this->t('{preprodwarning:warning:yes}')) ?>" />
+
+</form>
+
+
+<?php
+
+$this->includeAtTemplateBase('includes/footer.php');
+?>
diff --git a/modules/preprodwarning/www/showwarning.php b/modules/preprodwarning/www/showwarning.php
new file mode 100644
index 000000000..e73be044a
--- /dev/null
+++ b/modules/preprodwarning/www/showwarning.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * This script displays a page to the user, which requests that the user
+ * authorizes the release of attributes.
+ *
+ * @package simpleSAMLphp
+ * @version $Id$
+ */
+
+SimpleSAML_Logger::info('PreProdWarning - Showing warning to user');
+
+if (!array_key_exists('StateId', $_REQUEST)) {
+	throw new SimpleSAML_Error_BadRequest('Missing required StateId query parameter.');
+}
+
+$id = $_REQUEST['StateId'];
+$state = SimpleSAML_Auth_State::loadState($id, 'consent:request');
+
+
+if (array_key_exists('yes', $_REQUEST)) {
+	/* The user has pressed the yes-button. */
+
+	SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
+}
+
+
+
+$globalConfig = SimpleSAML_Configuration::getInstance();
+
+$t = new SimpleSAML_XHTML_Template($globalConfig, 'preprodwarning:warning.php');
+$t->data['yesTarget'] = SimpleSAML_Module::getModuleURL('preprodwarning/showwarning.php');
+$t->data['yesData'] = array('StateId' => $id);
+$t->show();
+
+
+?>
\ No newline at end of file
-- 
GitLab