From f6c9ca2523fed209629c3f61d6c5e5d6c8a5d8ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Thu, 27 Aug 2009 14:05:39 +0000
Subject: [PATCH] Restructured frontpage. Moved auth sourc test into core.
 Improved the portal module (started using it on the frontpage). frontpage
 hook is adjusted to fit new frontpage structure, and links updated.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1722 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/aggregator/hooks/hook_frontpage.php   |   2 +-
 modules/consentAdmin/hooks/hook_frontpage.php |   2 +-
 .../hooks/hook_frontpage.php                  |   4 +-
 .../core/dictionaries}/frontpage.php          |   0
 modules/core/hooks/hook_frontpage.php         |  33 +++
 modules/core/templates/frontpage_auth.tpl.php |  29 ++
 .../core/templates/frontpage_config.tpl.php   | 106 +++++++
 .../templates/frontpage_federation.tpl.php    | 132 +++++++++
 .../core/templates/frontpage_welcome.tpl.php  |  35 +++
 .../core/www/authenticate.php                 |   9 +-
 modules/core/www/frontpage_auth.php           |  72 +++++
 modules/core/www/frontpage_config.php         | 158 ++++++++++
 modules/core/www/frontpage_federation.php     | 152 ++++++++++
 modules/core/www/frontpage_welcome.php        |  68 +++++
 modules/cron/hooks/hook_frontpage.php         |   2 +-
 modules/ldapstatus/hooks/hook_frontpage.php   |   2 +-
 modules/logpeek/hooks/hook_frontpage.php      |   2 +-
 .../memcacheMonitor/hooks/hook_frontpage.php  |   2 +-
 modules/metaedit/hooks/hook_frontpage.php     |   2 +-
 modules/modinfo/hooks/hook_frontpage.php      |   2 +-
 modules/openid/hooks/hook_frontpage.php       |   2 +-
 .../portal/config-templates/module_portal.php |   1 +
 .../{default-disable => default-enable}       |   0
 modules/portal/hooks/hook_htmlinject.php      |  15 +-
 modules/portal/lib/Portal.php                 |   1 +
 modules/saml2debug/hooks/hook_frontpage.php   |   2 +-
 modules/sanitycheck/hooks/hook_frontpage.php  |   2 +-
 modules/sanitycheck/www/index.php             |   9 +-
 modules/statistics/hooks/hook_frontpage.php   |   4 +-
 modules/statistics/www/showstats.php          |  24 +-
 templates/frontpage.php                       |   7 +-
 templates/includes/footer.php                 |   4 +-
 templates/includes/header.php                 |  56 +++-
 www/index.php                                 | 269 +-----------------
 34 files changed, 875 insertions(+), 335 deletions(-)
 rename {dictionaries => modules/core/dictionaries}/frontpage.php (100%)
 create mode 100644 modules/core/hooks/hook_frontpage.php
 create mode 100644 modules/core/templates/frontpage_auth.tpl.php
 create mode 100644 modules/core/templates/frontpage_config.tpl.php
 create mode 100644 modules/core/templates/frontpage_federation.tpl.php
 create mode 100644 modules/core/templates/frontpage_welcome.tpl.php
 rename www/example-simple/authsource-example.php => modules/core/www/authenticate.php (87%)
 create mode 100644 modules/core/www/frontpage_auth.php
 create mode 100644 modules/core/www/frontpage_config.php
 create mode 100644 modules/core/www/frontpage_federation.php
 create mode 100644 modules/core/www/frontpage_welcome.php
 rename modules/portal/{default-disable => default-enable} (100%)

diff --git a/modules/aggregator/hooks/hook_frontpage.php b/modules/aggregator/hooks/hook_frontpage.php
index d8fa136cb..eaf8e5608 100644
--- a/modules/aggregator/hooks/hook_frontpage.php
+++ b/modules/aggregator/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function aggregator_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['federation'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('aggregator/'),
 		'text' => '{aggregator:dict:frontpage_link}',
 		);
diff --git a/modules/consentAdmin/hooks/hook_frontpage.php b/modules/consentAdmin/hooks/hook_frontpage.php
index 7bf7138f3..a87fb1e07 100644
--- a/modules/consentAdmin/hooks/hook_frontpage.php
+++ b/modules/consentAdmin/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function consentAdmin_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('consentAdmin/consentAdmin.php'),
 		'text' => '{consentAdmin:consentadmin:consentadmin_header}',
 	);
diff --git a/modules/consentSimpleAdmin/hooks/hook_frontpage.php b/modules/consentSimpleAdmin/hooks/hook_frontpage.php
index 743ef22f0..432fdcb36 100644
--- a/modules/consentSimpleAdmin/hooks/hook_frontpage.php
+++ b/modules/consentSimpleAdmin/hooks/hook_frontpage.php
@@ -8,11 +8,11 @@ function consentSimpleAdmin_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('consentSimpleAdmin/consentAdmin.php'),
 		'text' => '{consentSimpleAdmin:consentsimpleadmin:header}',
 	);
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('consentSimpleAdmin/consentStats.php'),
 		'text' => '{consentSimpleAdmin:consentsimpleadmin:headerstats}',
 	);
diff --git a/dictionaries/frontpage.php b/modules/core/dictionaries/frontpage.php
similarity index 100%
rename from dictionaries/frontpage.php
rename to modules/core/dictionaries/frontpage.php
diff --git a/modules/core/hooks/hook_frontpage.php b/modules/core/hooks/hook_frontpage.php
new file mode 100644
index 000000000..54ec267cc
--- /dev/null
+++ b/modules/core/hooks/hook_frontpage.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Hook to add the modinfo module to the frontpage.
+ *
+ * @param array &$links  The links on the frontpage, split into sections.
+ */
+function core_hook_frontpage(&$links) {
+	assert('is_array($links)');
+	assert('array_key_exists("links", $links)');
+
+	$links['links']['frontpage_welcome'] = array(
+		'href' => SimpleSAML_Module::getModuleURL('core/frontpage_welcome.php'),
+		'text' => '{core:frontpage:welcome}',
+		'shorttext' => '{core:frontpage:welcome}',
+	);
+	$links['links']['frontpage_config'] = array(
+		'href' => SimpleSAML_Module::getModuleURL('core/frontpage_config.php'),
+		'text' => '{core:frontpage:configuration}',
+		'shorttext' => '{core:frontpage:configuration}',
+	);
+	$links['links']['frontpage_auth'] = array(
+		'href' => SimpleSAML_Module::getModuleURL('core/frontpage_auth.php'),
+		'text' => '{core:frontpage:auth}',
+		'shorttext' => '{core:frontpage:auth}',
+	);
+	$links['links']['frontpage_federation'] = array(
+		'href' => SimpleSAML_Module::getModuleURL('core/frontpage_federation.php'),
+		'text' => '{core:frontpage:federation}',
+		'shorttext' => '{core:frontpage:federation}',
+	);
+
+}
+?>
\ No newline at end of file
diff --git a/modules/core/templates/frontpage_auth.tpl.php b/modules/core/templates/frontpage_auth.tpl.php
new file mode 100644
index 000000000..8c9764fd3
--- /dev/null
+++ b/modules/core/templates/frontpage_auth.tpl.php
@@ -0,0 +1,29 @@
+<?php 
+
+$this->includeAtTemplateBase('includes/header.php'); 
+
+?>
+
+<?php
+if ($this->data['isadmin']) {
+	echo '<p style="float: right">' . $this->t('{core:frontpage:loggedin_as_admin}') . '</p>';
+} else {
+	echo '<p style="float: right"><a href="' . $this->data['loginurl'] . '">' . $this->t('{core:frontpage:login_as_admin}') . '</a></p>';
+}
+?>
+
+
+	
+<!--	<h2><?php echo $this->t('{core:frontpage:useful_links_header}'); ?></h2> -->
+<ul>
+<?php
+	foreach ($this->data['links_auth'] AS $link) {
+		echo '<li><a href="' . htmlspecialchars($link['href']) . '">' . $this->t($link['text']) . '</a></li>';
+	}
+?>
+</ul>
+
+	
+
+		
+<?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
diff --git a/modules/core/templates/frontpage_config.tpl.php b/modules/core/templates/frontpage_config.tpl.php
new file mode 100644
index 000000000..33f702efb
--- /dev/null
+++ b/modules/core/templates/frontpage_config.tpl.php
@@ -0,0 +1,106 @@
+<?php 
+
+
+
+$this->includeAtTemplateBase('includes/header.php'); 
+	
+
+
+?>
+
+
+<!-- 
+<div id="tabdiv">
+<ul>
+	<li><a href="#welcome"><?php echo $this->t('{core:frontpage:welcome}'); ?></a></li>
+	<li><a href="#configuration"><?php echo $this->t('{core:frontpage:configuration}'); ?></a></li>
+	<li><a href="#metadata"><?php echo $this->t('{core:frontpage:metadata}'); ?></a></li>
+</ul> -->
+<?php
+if ($this->data['isadmin']) {
+	echo '<p style="float: right">' . $this->t('{core:frontpage:loggedin_as_admin}') . '</p>';
+} else {
+	echo '<p style="float: right"><a href="' . $this->data['loginurl'] . '">' . $this->t('{core:frontpage:login_as_admin}') . '</a></p>';
+}
+?>
+
+
+
+
+<div style="margin-top: 1em;">
+	<code style="background: white; background: #f5f5f5; border: 1px dotted #bbb; padding: 1em;  color: #555" ><?php 
+		echo $this->data['directory'] . ' (' . $this->data['version'] . ')'; 
+	?></code>
+</div>
+
+
+
+<div style="clear: both" class="enablebox mini">
+	<table>
+	
+	<?php
+	$icon_enabled  = '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" alt="enabled" />';
+	$icon_disabled = '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" alt="disabled" />';
+	?>
+	
+		<tr class="<?php echo $this->data['enablematrix']['saml20-sp'] ? 'enabled' : 'disabled'; ?>"><td>SAML 2.0 SP</td>
+			<td><?php echo $this->data['enablematrix']['saml20-sp'] ? $icon_enabled : $icon_disabled; ?></td></tr>
+			
+		<tr class="<?php echo $this->data['enablematrix']['saml20-idp'] ? 'enabled' : 'disabled'; ?>"><td>SAML 2.0 IdP</td>
+			<td><?php echo $this->data['enablematrix']['saml20-idp'] ? $icon_enabled : $icon_disabled; ?></td></tr>
+			
+		<tr class="<?php echo $this->data['enablematrix']['shib13-sp'] ? 'enabled' : 'disabled'; ?>"><td>Shib 1.3 SP</td>
+			<td><?php echo $this->data['enablematrix']['shib13-sp'] ? $icon_enabled : $icon_disabled; ?></td></tr>
+			
+		<tr class="<?php echo $this->data['enablematrix']['shib13-idp'] ? 'enabled' : 'disabled'; ?>"><td>Shib 1.3 IdP</td>
+			<td><?php echo $this->data['enablematrix']['shib13-idp'] ? $icon_enabled : $icon_disabled; ?></td></tr>
+		
+	</table>
+</div>
+
+
+
+<h2><?php echo $this->t('{core:frontpage:configuration}'); ?></h2>
+<ul>
+<?php
+	foreach ($this->data['links_config'] AS $link) {
+		echo '<li><a href="' . htmlspecialchars($link['href']) . '">' . $this->t($link['text']) . '</a></li>';
+	}
+?>
+</ul>
+
+
+<?php
+	if (array_key_exists('warnings', $this->data) && is_array($this->data['warnings']) && !empty($this->data['warnings'])) {
+
+		echo '<h2>' . $this->t('{core:frontpage:warnings}') . '</h2>';
+
+		foreach($this->data['warnings'] AS $warning) {
+			echo '<div class="caution">' . $this->t($warning) . '</div>';
+		}
+	}
+?>
+<?php 
+if ($this->data['isadmin']) {
+
+	echo '<h2>'. $this->t('{core:frontpage:checkphp}') . '</h2>';
+	echo '<div class="enablebox"><table>';
+	
+	
+	$icon_enabled  = '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" alt="enabled" />';
+	$icon_disabled = '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" alt="disabled" />';
+	
+	
+	foreach ($this->data['funcmatrix'] AS $func) {
+		echo '<tr class="' . ($func['enabled'] ? 'enabled' : 'disabled') . '"><td>' . ($func['enabled'] ? $icon_enabled : $icon_disabled) . '</td>
+		<td>' . $this->t('{core:frontpage:' . $func['required']. '}') . '</td><td>' . $func['descr'] . '</td></tr>';
+	}
+	echo('</table></div>');
+}
+
+?>
+	
+	
+
+		
+<?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
diff --git a/modules/core/templates/frontpage_federation.tpl.php b/modules/core/templates/frontpage_federation.tpl.php
new file mode 100644
index 000000000..ba809c07f
--- /dev/null
+++ b/modules/core/templates/frontpage_federation.tpl.php
@@ -0,0 +1,132 @@
+<?php 
+
+
+
+$this->includeAtTemplateBase('includes/header.php'); 
+	
+
+
+?>
+
+
+<!-- 
+<div id="tabdiv">
+<ul>
+	<li><a href="#welcome"><?php echo $this->t('{core:frontpage:welcome}'); ?></a></li>
+	<li><a href="#configuration"><?php echo $this->t('{core:frontpage:configuration}'); ?></a></li>
+	<li><a href="#metadata"><?php echo $this->t('{core:frontpage:metadata}'); ?></a></li>
+</ul> -->
+<?php
+if ($this->data['isadmin']) {
+	echo '<p style="float: right">' . $this->t('{core:frontpage:loggedin_as_admin}') . '</p>';
+} else {
+	echo '<p style="float: right"><a href="' . $this->data['loginurl'] . '">' . $this->t('{core:frontpage:login_as_admin}') . '</a></p>';
+}
+?>
+
+
+
+	
+
+
+
+
+
+<?php
+
+
+function mtype($set) {
+	switch($set) {
+		case 'saml20-sp-remote': return '{admin:metadata_saml20-sp}';
+		case 'saml20-sp-hosted': return '{admin:metadata_saml20-sp}';
+		case 'saml20-idp-remote': return '{admin:metadata_saml20-idp}';
+		case 'saml20-idp-hosted': return '{admin:metadata_saml20-idp}';
+		case 'shib13-sp-remote': return '{admin:metadata_shib13-sp}';
+		case 'shib13-sp-hosted': return '{admin:metadata_shib13-sp}';
+		case 'shib13-idp-remote': return '{admin:metadata_shib13-idp}';
+		case 'shib13-idp-hosted': return '{admin:metadata_shib13-idp}';
+	}
+}
+
+$now = time();
+echo '<dl>';
+if (is_array($this->data['metaentries']['hosted']) && count($this->data['metaentries']['hosted']) > 0)
+foreach ($this->data['metaentries']['hosted'] AS $hm) {
+	echo '<dt>' . $this->t(mtype($hm['metadata-set'])) . '</dt>';
+	echo '<dd>';
+	echo '<p>Entity ID: ' . $hm['entityid'];
+	if ($hm['entityid'] !== $hm['metadata-index']) 
+		echo '<br />Index: ' . $hm['metadata-index'];
+	if (array_key_exists('name', $hm))
+		echo '<br /><strong>' . $this->getTranslation(SimpleSAML_Utilities::arrayize($hm['name'], 'en')) . '</strong>';
+	if (array_key_exists('descr', $hm))
+		echo '<br /><strong>' . $this->getTranslation(SimpleSAML_Utilities::arrayize($hm['descr'], 'en')) . '</strong>';
+
+	echo '<br  />[ <a href="' . $hm['metadata-url'] . '">' . $this->t('{core:frontpage:show_metadata}') . '</a> ]';
+	
+	echo '</dd>';
+}
+echo '</dl>';
+
+if (is_array($this->data['metaentries']['remote']) && count($this->data['metaentries']['remote']) > 0)
+foreach($this->data['metaentries']['remote'] AS $setkey => $set) {
+	
+	echo '<fieldset class="fancyfieldset"><legend>' . $this->t(mtype($setkey)) . ' (Trusted)</legend>';
+	echo '<ul>';
+	foreach($set AS $entry) {
+		echo '<li>';
+		if (array_key_exists('name', $entry)) {
+			echo $this->getTranslation(SimpleSAML_Utilities::arrayize($entry['name'], 'en'));
+		} else {
+			echo $entry['entityid'];
+		}
+		
+		if (array_key_exists('expire', $entry)) {
+			if ($entry['expire'] < $now) {
+				echo('<span style="color: #500; font-weight: bold"> (expired ' . number_format(($now - $entry['expire'])/3600, 1) . ' hours ago)</span>');
+			} else {
+				echo(' (expires in ' . number_format(($entry['expire'] - $now)/3600, 1) . ' hours)');
+			}
+		}
+		echo '</li>';
+	}
+	echo '</ul>';
+	echo '</fieldset>';
+}
+
+
+
+
+?>
+
+
+
+
+
+<h2><?php echo $this->t('{core:frontpage:tools}'); ?></h2>
+<ul>
+<?php
+	foreach ($this->data['links_federation'] AS $link) {
+		echo '<li><a href="' . htmlspecialchars($link['href']) . '">' . $this->t($link['text']) . '</a></li>';
+	}
+?>
+</ul>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+	
+
+		
+<?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
diff --git a/modules/core/templates/frontpage_welcome.tpl.php b/modules/core/templates/frontpage_welcome.tpl.php
new file mode 100644
index 000000000..4d36927ad
--- /dev/null
+++ b/modules/core/templates/frontpage_welcome.tpl.php
@@ -0,0 +1,35 @@
+<?php 
+
+$this->includeAtTemplateBase('includes/header.php'); 
+
+?>
+
+
+<?php
+if ($this->data['isadmin']) {
+	echo '<p style="float: right">' . $this->t('{core:frontpage:loggedin_as_admin}') . '</p>';
+} else {
+	echo '<p style="float: right"><a href="' . $this->data['loginurl'] . '">' . $this->t('{core:frontpage:login_as_admin}') . '</a></p>';
+}
+?>
+
+<p><?php echo $this->t('{core:frontpage:intro}'); ?></p>
+
+
+<ul>
+<?php
+	foreach ($this->data['links_welcome'] AS $link) {
+		echo '<li><a href="' . htmlspecialchars($link['href']) . '">' . $this->t($link['text']) . '</a></li>';
+	}
+?>
+</ul>
+	
+	
+	
+	<h2><?php echo $this->t('{core:frontpage:about_header}'); ?></h2>
+		<p><?php echo $this->t('{core:frontpage:about_text}'); ?></p>
+
+
+
+		
+<?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
diff --git a/www/example-simple/authsource-example.php b/modules/core/www/authenticate.php
similarity index 87%
rename from www/example-simple/authsource-example.php
rename to modules/core/www/authenticate.php
index 631542d54..75d48136b 100644
--- a/www/example-simple/authsource-example.php
+++ b/modules/core/www/authenticate.php
@@ -1,10 +1,6 @@
 <?php
 
-/**
- * The _include script registers a autoloader for the simpleSAMLphp libraries. It also
- * initializes the simpleSAMLphp config class with the correct path.
- */
-require_once('../_include.php');
+
 
 $config = SimpleSAML_Configuration::getInstance();
 $session = SimpleSAML_Session::getInstance();
@@ -51,6 +47,3 @@ $t->data['logouturl'] = SimpleSAML_Utilities::selfURLNoQuery() . '?logout';
 $t->data['icon'] = 'bino.png';
 $t->show();
 
-
-
-?>
\ No newline at end of file
diff --git a/modules/core/www/frontpage_auth.php b/modules/core/www/frontpage_auth.php
new file mode 100644
index 000000000..0620fc21f
--- /dev/null
+++ b/modules/core/www/frontpage_auth.php
@@ -0,0 +1,72 @@
+<?php
+
+
+/* Load simpleSAMLphp, configuration */
+$config = SimpleSAML_Configuration::getInstance();
+$session = SimpleSAML_Session::getInstance();
+
+/* Check if valid local session exists.. */
+if ($config->getBoolean('admin.protectindexpage', false)) {
+	SimpleSAML_Utilities::requireAdmin();
+}
+$loginurl = SimpleSAML_Utilities::getAdminLoginURL();
+$isadmin = SimpleSAML_Utilities::isAdmin();
+
+
+
+
+	
+$links = array();
+$links_welcome = array();
+$links_config = array();
+$links_auth = array();
+$links_federation = array();
+
+
+$links_auth[] = array(
+	'href' => 'authenticate.php',
+	'text' => '{core:frontpage:authtest}',
+);
+
+
+if ($config->getValue('enable.saml20-sp') === true)
+	$links_auth[] = array(
+		'href' => 'example-simple/saml2-example.php', 
+		'text' => '{core:frontpage:link_saml2example}');
+
+if ($config->getValue('enable.shib13-sp') === true)
+	$links_auth[] = array(
+		'href' => 'example-simple/shib13-example.php', 
+		'text' => '{core:frontpage:link_shib13example}');
+
+
+$allLinks = array(
+	'links'      => &$links,
+	'welcome'    => &$links_welcome,
+	'config'     => &$links_config,
+	'auth'       => &$links_auth,
+	'federation' => &$links_federation,
+);
+SimpleSAML_Module::callHooks('frontpage', $allLinks);
+
+
+
+$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_auth.tpl.php');
+$t->data['pageid'] = 'frontpage_auth';
+$t->data['isadmin'] = $isadmin;
+$t->data['loginurl'] = $loginurl;
+$t->data['header'] = 'simpleSAMLphp installation page';
+$t->data['icon'] = 'compass_l.png';
+
+
+$t->data['links'] = $links;
+$t->data['links_welcome'] = $links_welcome;
+$t->data['links_config'] = $links_config;
+$t->data['links_auth'] = $links_auth;
+$t->data['links_federation'] = $links_federation;
+
+
+
+$t->show();
+
+
diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php
new file mode 100644
index 000000000..faaf2f8fb
--- /dev/null
+++ b/modules/core/www/frontpage_config.php
@@ -0,0 +1,158 @@
+<?php
+
+
+
+/* Load simpleSAMLphp, configuration */
+$config = SimpleSAML_Configuration::getInstance();
+$session = SimpleSAML_Session::getInstance();
+
+/* Check if valid local session exists.. */
+if ($config->getBoolean('admin.protectindexpage', false)) {
+	SimpleSAML_Utilities::requireAdmin();
+}
+$loginurl = SimpleSAML_Utilities::getAdminLoginURL();
+$isadmin = SimpleSAML_Utilities::isAdmin();
+
+
+$warnings = array();
+
+if (SimpleSAML_Utilities::getSelfProtocol() != 'https') {
+	$warnings[] = '{core:frontpage:warnings_https}';
+}
+
+
+
+
+
+
+$links = array();
+$links_welcome = array();
+$links_config = array();
+$links_auth = array();
+$links_federation = array();
+
+
+
+$links_config[] = array(
+	'href' => 'example-simple/hostnames.php?dummy=1', 
+	'text' => '{core:frontpage:link_diagnostics}'
+);
+
+$links_config[] = array(
+	'href' => 'admin/phpinfo.php', 
+	'text' => '{core:frontpage:link_phpinfo}'
+);
+
+$links_config[] = array(
+	'href' => 'admin/config.php',
+	'text' => '{core:frontpage:link_configcheck}',
+);
+
+
+
+
+
+$allLinks = array(
+	'links'      => &$links,
+	'welcome'    => &$links_welcome,
+	'config'     => &$links_config,
+	'auth'       => &$links_auth,
+	'federation' => &$links_federation,
+);
+SimpleSAML_Module::callHooks('frontpage', $allLinks);
+
+
+
+
+
+
+
+$enablematrix = array(
+	'saml20-sp' => $config->getBoolean('enable.saml20-sp', TRUE),
+	'saml20-idp' => $config->getBoolean('enable.saml20-idp', false),
+	'shib13-sp' => $config->getBoolean('enable.shib13-sp', false),
+	'shib13-idp' => $config->getBoolean('enable.shib13-idp', false),
+);
+
+
+$functionchecks = array(
+	'hash'             => array('required',  'Hashing function'),
+	'gzinflate'        => array('required',  'ZLib'),
+	'openssl_sign'     => array('required',  'OpenSSL'),
+	'simplexml_import_dom' => array('required', 'SimpleXML'),
+	'dom_import_simplexml' => array('required', 'XML DOM'),
+	'preg_match'       => array('required',  'RegEx support'),
+	'ldap_bind'        => array('required_ldap',  'LDAP Extension'),
+	'radius_auth_open' => array('required_radius',  'Radius Extension'),
+	'mcrypt_module_open'=> array('optional',  'MCrypt'),
+	'mysql_connect'    => array('optional',  'MySQL support'),
+);
+$funcmatrix = array();
+$funcmatrix[] = array(
+	'required' => 'required', 
+	'descr' => 'PHP Version >= 5.1.2. You run: ' . phpversion(), 
+	'enabled' => version_compare(phpversion(), '5.1.2', '>='));
+$funcmatrix[] = array(
+	'required' => 'reccomended', 
+	'descr' => 'PHP Version >= 5.2 (Required for Shibboleth 1.3 SP)', 
+	'enabled' => version_compare(phpversion(), '5.2', '>='));
+foreach ($functionchecks AS $func => $descr) {
+	$funcmatrix[] = array('descr' => $descr[1], 'required' => $descr[0], 'enabled' => function_exists($func));
+}
+
+
+/* Some basic configuration checks */
+
+if($config->getString('technicalcontact_email', 'na@example.org') === 'na@example.org') {
+	$mail_ok = FALSE;
+} else {
+	$mail_ok = TRUE;
+}
+$funcmatrix[] = array(
+	'required' => 'reccomended',
+	'descr' => 'technicalcontact_email option set',
+	'enabled' => $mail_ok
+	);
+if($config->getString('auth.adminpassword', '123') === '123') {
+	$password_ok = FALSE;
+} else {
+	$password_ok = TRUE;
+}
+$funcmatrix[] = array(
+	'required' => 'required',
+	'descr' => 'auth.adminpassword option set',
+	'enabled' => $password_ok
+);
+
+$funcmatrix[] = array(
+	'required' => 'reccomended',
+	'descr' => 'Magic Quotes should be turned off',
+	'enabled' => (get_magic_quotes_runtime() === 0)
+);
+
+
+$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_config.tpl.php');
+$t->data['pageid'] = 'frontpage_config';
+$t->data['isadmin'] = $isadmin;
+$t->data['loginurl'] = $loginurl;
+$t->data['header'] = 'simpleSAMLphp installation page';
+$t->data['icon'] = 'compass_l.png';
+$t->data['warnings'] = $warnings;
+
+
+$t->data['links'] = $links;
+$t->data['links_welcome'] = $links_welcome;
+$t->data['links_config'] = $links_config;
+$t->data['links_auth'] = $links_auth;
+$t->data['links_federation'] = $links_federation;
+
+
+
+$t->data['enablematrix'] = $enablematrix;
+$t->data['funcmatrix'] = $funcmatrix;
+$t->data['version'] = $config->getVersion();
+$t->data['directory'] = dirname(dirname(__FILE__));
+
+$t->show();
+
+
diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php
new file mode 100644
index 000000000..fd4194aaf
--- /dev/null
+++ b/modules/core/www/frontpage_federation.php
@@ -0,0 +1,152 @@
+<?php
+
+
+
+/* Load simpleSAMLphp, configuration */
+$config = SimpleSAML_Configuration::getInstance();
+$session = SimpleSAML_Session::getInstance();
+
+/* Check if valid local session exists.. */
+if ($config->getBoolean('admin.protectindexpage', false)) {
+	SimpleSAML_Utilities::requireAdmin();
+}
+$loginurl = SimpleSAML_Utilities::getAdminLoginURL();
+$isadmin = SimpleSAML_Utilities::isAdmin();
+
+
+
+
+	
+	
+	
+$links = array();
+$links_welcome = array();
+$links_config = array();
+$links_auth = array();
+$links_federation = array();
+
+
+
+
+if($config->getBoolean('idpdisco.enableremember', FALSE)) {
+	$links_federation[] = array(
+		'href' => 'cleardiscochoices.php',
+		'text' => '{core:frontpage:link_cleardiscochoices}',
+	);
+}
+
+$publishURL = $config->getString('metashare.publishurl', NULL);
+if ($publishURL !== NULL) {
+	$metadataSources = array(
+		'saml20-idp' => 'saml2/idp/metadata.php',
+		'saml20-sp' => 'saml2/sp/metadata.php',
+		'shib13-idp' => 'shib13/idp/metadata.php',
+		'shib13-sp' => 'shib13/sp/metadata.php',
+	);
+	foreach($metadataSources as $name => $url) {
+		if(!$config->getBoolean('enable.' . $name, FALSE)) continue;
+
+		$url = SimpleSAML_Utilities::resolveURL($url);
+		$linkTarget = SimpleSAML_Utilities::addURLparameter($publishURL, array('url' => $url));
+		$links_federation[] = array(
+			'href' => $linkTarget,
+			'text' => '{core:frontpage:link_publish_' . $name . '}',
+		);
+	}
+}
+
+
+$links_federation[] = array(
+	'href' => 'admin/metadata.php', 
+	'text' => '{core:frontpage:link_meta_overview}'
+);
+
+$links_federation[] = array(
+	'href' => 'admin/metadata-converter.php',
+	'text' => '{core:frontpage:link_xmlconvert}',
+);
+
+
+
+
+$allLinks = array(
+	'links'      => &$links,
+	'welcome'    => &$links_welcome,
+	'config'     => &$links_config,
+	'auth'       => &$links_auth,
+	'federation' => &$links_federation,
+);
+SimpleSAML_Module::callHooks('frontpage', $allLinks);
+
+
+
+
+
+
+
+
+
+
+
+
+$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+
+$metaentries = array('hosted' => array(), 'remote' => array() );
+if ($config->getBoolean('enable.saml20-sp', TRUE) === true) {
+	try {
+		$metaentries['hosted']['saml20-sp'] = $metadata->getMetaDataCurrent('saml20-sp-hosted');
+		$metaentries['hosted']['saml20-sp']['metadata-url'] = '/' . $config->getBaseURL() . 'saml2/sp/metadata.php?output=xhtml';
+		if ($isadmin)
+			$metaentries['remote']['saml20-idp-remote'] = $metadata->getList('saml20-idp-remote');
+	} catch(Exception $e) {}
+}
+if ($config->getBoolean('enable.saml20-idp', FALSE) === true) {
+	try {
+		$metaentries['hosted']['saml20-idp'] = $metadata->getMetaDataCurrent('saml20-idp-hosted');
+		$metaentries['hosted']['saml20-idp']['metadata-url'] = '/' . $config->getBaseURL() . 'saml2/idp/metadata.php?output=xhtml';
+		if ($isadmin)
+			$metaentries['remote']['saml20-sp-remote'] = $metadata->getList('saml20-sp-remote');
+	} catch(Exception $e) {}
+}
+if ($config->getBoolean('enable.shib13-sp', FALSE) === true) {
+	try {
+		$metaentries['hosted']['shib13-sp'] = $metadata->getMetaDataCurrent('shib13-sp-hosted');
+		$metaentries['hosted']['shib13-sp']['metadata-url'] = '/' . $config->getBaseURL() . 'shib13/sp/metadata.php?output=xhtml';
+		if ($isadmin)
+			$metaentries['remote']['shib13-idp-remote'] = $metadata->getList('shib13-idp-remote');
+	} catch(Exception $e) {}
+}
+if ($config->getBoolean('enable.shib13-idp', FALSE) === true) {
+	try {
+		$metaentries['hosted']['shib13-idp'] = $metadata->getMetaDataCurrent('shib13-idp-hosted');
+		$metaentries['hosted']['shib13-idp']['metadata-url'] = '/' . $config->getBaseURL() . 'shib13/idp/metadata.php?output=xhtml';
+		if ($isadmin)
+			$metaentries['remote']['shib13-sp-remote'] = $metadata->getList('shib13-sp-remote');
+	} catch(Exception $e) {}
+}
+
+
+
+
+
+$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_federation.tpl.php');
+$t->data['pageid'] = 'frontpage_federation';
+$t->data['isadmin'] = $isadmin;
+$t->data['loginurl'] = $loginurl;
+$t->data['header'] = 'simpleSAMLphp installation page';
+$t->data['icon'] = 'compass_l.png';
+
+
+$t->data['links'] = $links;
+$t->data['links_welcome'] = $links_welcome;
+$t->data['links_config'] = $links_config;
+$t->data['links_auth'] = $links_auth;
+$t->data['links_federation'] = $links_federation;
+
+
+
+$t->data['metaentries'] = $metaentries;
+
+
+$t->show();
+
diff --git a/modules/core/www/frontpage_welcome.php b/modules/core/www/frontpage_welcome.php
new file mode 100644
index 000000000..169f22e4b
--- /dev/null
+++ b/modules/core/www/frontpage_welcome.php
@@ -0,0 +1,68 @@
+<?php
+
+
+/* Load simpleSAMLphp, configuration */
+$config = SimpleSAML_Configuration::getInstance();
+$session = SimpleSAML_Session::getInstance();
+
+/* Check if valid local session exists.. */
+if ($config->getBoolean('admin.protectindexpage', false)) {
+	SimpleSAML_Utilities::requireAdmin();
+}
+$loginurl = SimpleSAML_Utilities::getAdminLoginURL();
+$isadmin = SimpleSAML_Utilities::isAdmin();
+
+
+
+
+
+$links = array();
+$links_welcome = array();
+$links_config = array();
+$links_auth = array();
+$links_federation = array();
+
+
+
+$allLinks = array(
+	'links'      => &$links,
+	'welcome'    => &$links_welcome,
+	'config'     => &$links_config,
+	'auth'       => &$links_auth,
+	'federation' => &$links_federation,
+);
+
+$links_welcome[] = array(
+	'href' => 'https://rnd.feide.no/view/simplesamlphpdocs',
+	'text' => '{core:frontpage:doc_header}',
+);
+
+SimpleSAML_Module::callHooks('frontpage', $allLinks);
+
+
+
+
+
+
+
+
+
+$t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_welcome.tpl.php');
+$t->data['pageid'] = 'frontpage_welcome';
+$t->data['isadmin'] = $isadmin;
+$t->data['loginurl'] = $loginurl;
+$t->data['header'] = 'simpleSAMLphp installation page';
+$t->data['icon'] = 'compass_l.png';
+
+$t->data['links'] = $links;
+$t->data['links_welcome'] = $links_welcome;
+$t->data['links_config'] = $links_config;
+$t->data['links_auth'] = $links_auth;
+$t->data['links_federation'] = $links_federation;
+
+
+
+
+$t->show();
+
+
diff --git a/modules/cron/hooks/hook_frontpage.php b/modules/cron/hooks/hook_frontpage.php
index 869019f70..76738b818 100644
--- a/modules/cron/hooks/hook_frontpage.php
+++ b/modules/cron/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function cron_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('cron/croninfo.php'),
 		'text' => array('en' => 'Cron module information page'),
 	);
diff --git a/modules/ldapstatus/hooks/hook_frontpage.php b/modules/ldapstatus/hooks/hook_frontpage.php
index 2c27677d2..81184fc88 100644
--- a/modules/ldapstatus/hooks/hook_frontpage.php
+++ b/modules/ldapstatus/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function ldapstatus_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['auth'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('ldapstatus/'),
 		'text' => array('en' => 'LDAP Status page', 'no' => 'LDAP statusoversikt'),
 	);
diff --git a/modules/logpeek/hooks/hook_frontpage.php b/modules/logpeek/hooks/hook_frontpage.php
index 96af12acf..c92e43bee 100644
--- a/modules/logpeek/hooks/hook_frontpage.php
+++ b/modules/logpeek/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function logpeek_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('logpeek/'),
 		'text' => array('en' => 'SimpleSAMLphp logs access (Log peek)', 'no' => 'Vis simpleSAMLphp log'),
 	);
diff --git a/modules/memcacheMonitor/hooks/hook_frontpage.php b/modules/memcacheMonitor/hooks/hook_frontpage.php
index 16fb4aaae..048cc6d91 100644
--- a/modules/memcacheMonitor/hooks/hook_frontpage.php
+++ b/modules/memcacheMonitor/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function memcacheMonitor_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('memcacheMonitor/memcachestat.php'),
 		'text' => array('en' => 'MemCache Statistics'),
 	);
diff --git a/modules/metaedit/hooks/hook_frontpage.php b/modules/metaedit/hooks/hook_frontpage.php
index 21ca8be7c..9c9a6646f 100644
--- a/modules/metaedit/hooks/hook_frontpage.php
+++ b/modules/metaedit/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function metaedit_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links']['metaedit'] = array(
+	$links['federation']['metaedit'] = array(
 		'href' => SimpleSAML_Module::getModuleURL('metaedit/index.php'),
 		'text' => array('en' => 'Metadata registry', 'no' => 'Metadata registrering'),
 		'shorttext' => array('en' => 'Metadata registry', 'no' => 'Metadata registrering'),
diff --git a/modules/modinfo/hooks/hook_frontpage.php b/modules/modinfo/hooks/hook_frontpage.php
index 2f8b5ccb2..1895bcf82 100644
--- a/modules/modinfo/hooks/hook_frontpage.php
+++ b/modules/modinfo/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function modinfo_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['config'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('modinfo/'),
 		'text' => '{modinfo:dict:modlist_header}',
 		);
diff --git a/modules/openid/hooks/hook_frontpage.php b/modules/openid/hooks/hook_frontpage.php
index aec1e20c3..73303a9f8 100644
--- a/modules/openid/hooks/hook_frontpage.php
+++ b/modules/openid/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function openid_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['auth'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('openid/openidtest.php'),
 		'text' => '{openid:dictopenid:openidtestpage}',
 	);
diff --git a/modules/portal/config-templates/module_portal.php b/modules/portal/config-templates/module_portal.php
index ebcba744f..ad77d62cc 100644
--- a/modules/portal/config-templates/module_portal.php
+++ b/modules/portal/config-templates/module_portal.php
@@ -8,6 +8,7 @@
 $config = array (
 
 	'pagesets' => array(
+		array('frontpage_welcome', 'frontpage_config', 'frontpage_auth', 'frontpage_federation'),
 		array('santitycheck', 'statistics'),
 	),
 	
diff --git a/modules/portal/default-disable b/modules/portal/default-enable
similarity index 100%
rename from modules/portal/default-disable
rename to modules/portal/default-enable
diff --git a/modules/portal/hooks/hook_htmlinject.php b/modules/portal/hooks/hook_htmlinject.php
index 1e34ff693..7ea115ad0 100644
--- a/modules/portal/hooks/hook_htmlinject.php
+++ b/modules/portal/hooks/hook_htmlinject.php
@@ -16,11 +16,18 @@ function portal_hook_htmlinject(&$hookinfo) {
 
 #	echo('<pre>');	print_r($links); exit;
 
-	$portalConfig = SimpleSAML_Configuration::getConfig('module_portal.php');
+	$portalConfig = SimpleSAML_Configuration::getOptionalConfig('module_portal.php');
 	
-
-
-	$portal = new sspmod_portal_Portal($links['links'], $portalConfig->getValue('pagesets') );
+	$allLinks = array();
+	foreach($links AS $ls) {
+		$allLinks = array_merge($allLinks, $ls);
+	}
+
+	$portal = new sspmod_portal_Portal($allLinks,
+		$portalConfig->getValue('pagesets', array(
+			array('frontpage_welcome', 'frontpage_config', 'frontpage_auth', 'frontpage_federation'),
+		)) 
+	);
 	
 	if (!$portal->isPortalized($hookinfo['page'])) return;
 
diff --git a/modules/portal/lib/Portal.php b/modules/portal/lib/Portal.php
index cd2e8ffec..5177421e6 100644
--- a/modules/portal/lib/Portal.php
+++ b/modules/portal/lib/Portal.php
@@ -21,6 +21,7 @@ class sspmod_portal_Portal {
 	}
 	
 	function isPortalized($thispage) {
+		
 		foreach($this->config AS $set) {
 			if (in_array($thispage, $set)) {
 				return TRUE;
diff --git a/modules/saml2debug/hooks/hook_frontpage.php b/modules/saml2debug/hooks/hook_frontpage.php
index 581fd773f..a59ae67e7 100644
--- a/modules/saml2debug/hooks/hook_frontpage.php
+++ b/modules/saml2debug/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function saml2debug_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links'][] = array(
+	$links['federation'][] = array(
 		'href' => SimpleSAML_Module::getModuleURL('saml2debug/debug.php'),
 		'text' => array('en' => 'SAML 2.0 Debugger'),
 	);
diff --git a/modules/sanitycheck/hooks/hook_frontpage.php b/modules/sanitycheck/hooks/hook_frontpage.php
index 821761910..57b3cfce0 100644
--- a/modules/sanitycheck/hooks/hook_frontpage.php
+++ b/modules/sanitycheck/hooks/hook_frontpage.php
@@ -8,7 +8,7 @@ function sanitycheck_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links']['santitycheck'] = array(
+	$links['config']['santitycheck'] = array(
 		'href' => SimpleSAML_Module::getModuleURL('sanitycheck/index.php'),
 		'text' => array('en' => 'Sanity check of your simpleSAMLphp setup'),
 		'shorttext' => array('en' => 'SanityCheck'),
diff --git a/modules/sanitycheck/www/index.php b/modules/sanitycheck/www/index.php
index 3f94e0040..99a236f8d 100644
--- a/modules/sanitycheck/www/index.php
+++ b/modules/sanitycheck/www/index.php
@@ -23,16 +23,9 @@ if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'text') {
 	exit;
 }
 
-$htmlContentPre = array(); $htmlContentPost = array(); $htmlContentHead = array(); $jquery = array();
-$hookinfo = array('pre' => &$htmlContentPre, 'post' => &$htmlContentPost, 'head' => &$htmlContentHead, 'jquery' => &$jquery, 'page' => 'santitycheck');
-SimpleSAML_Module::callHooks('htmlinject', $hookinfo);
-
-
 $t = new SimpleSAML_XHTML_Template($config, 'sanitycheck:check-tpl.php');
+$t->data['pageid'] = 'statistics';
 $t->data['errors'] = $errors;
 $t->data['info'] = $info;
-$t->data['htmlContentPre'] = $htmlContentPre;
-$t->data['htmlContentPost'] = $htmlContentPost;
-$t->data['htmlContentHead'] = $htmlContentHead;
 $t->data['jquery'] = $jquery;
 $t->show();
diff --git a/modules/statistics/hooks/hook_frontpage.php b/modules/statistics/hooks/hook_frontpage.php
index ac58b8237..b6a2f73eb 100644
--- a/modules/statistics/hooks/hook_frontpage.php
+++ b/modules/statistics/hooks/hook_frontpage.php
@@ -8,12 +8,12 @@ function statistics_hook_frontpage(&$links) {
 	assert('is_array($links)');
 	assert('array_key_exists("links", $links)');
 
-	$links['links']['statistics'] = array(
+	$links['config']['statistics'] = array(
 		'href' => SimpleSAML_Module::getModuleURL('statistics/showstats.php'),
 		'text' => array('en' => 'Show statistics', 'no' => 'Vis statistikk'),
 		'shorttext' => array('en' => 'Statistics', 'no' => 'Statistikk'),
 	);
-	$links['links']['statisticsmeta'] = array(
+	$links['config']['statisticsmeta'] = array(
 		'href' => SimpleSAML_Module::getModuleURL('statistics/statmeta.php'),
 		'text' => array('en' => 'Show statistics metadata', 'no' => 'Vis statistikk metadata'),
 		'shorttext' => array('en' => 'Statistics metadata', 'no' => 'Statistikk metadata'),
diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php
index db434ee8d..ac8287a53 100644
--- a/modules/statistics/www/showstats.php
+++ b/modules/statistics/www/showstats.php
@@ -154,12 +154,23 @@ $dimx = $statconfig->getValue('dimension.x', 800);
 $dimy = $statconfig->getValue('dimension.y', 350);
 $grapher = new sspmod_statistics_Graph_GoogleCharts($dimx, $dimy);
 
-$htmlContentPre = array(); $htmlContentPost = array(); $htmlContentHead = array(); $jquery = array();
-$hookinfo = array('pre' => &$htmlContentPre, 'post' => &$htmlContentPost, 'head' => &$htmlContentHead, 'jquery' => &$jquery, 'page' => 'statistics');
-SimpleSAML_Module::callHooks('htmlinject', $hookinfo);
+if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] === 'csv') {
+
+	header('Content-type: text/csv');
+	header('Content-Disposition: attachment; filename="simplesamlphp-data.csv"');
+	$data = $dataset->getDebugData();
+	foreach($data AS $de) {
+		if (isset($de[1])) {
+			echo('"' . $de[0] . '",' . $de[1] . "\n");
+		}
+	}
+	exit;
+}
+
 
 
 $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php');
+$t->data['pageid'] = 'statistics';
 $t->data['header'] = 'stat';
 $t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $maxes);
 if (isset($piedata)) {
@@ -170,10 +181,7 @@ $t->data['available.times'] = $statrule->availableFileSlots($timeres);
 $t->data['available.timeres'] = $statrule->availableTimeRes();
 $t->data['available.times.prev'] = $timeNavigation['prev'];
 $t->data['available.times.next'] = $timeNavigation['next'];
-$t->data['htmlContentPre'] = $htmlContentPre;
-$t->data['htmlContentPost'] = $htmlContentPost;
-$t->data['htmlContentHead'] = $htmlContentHead;
-$t->data['jquery'] = $jquery;
+
 $t->data['selected.rule']= $rule;
 $t->data['selected.rule2']= $preferRule2;
 $t->data['selected.time'] = $fileslot;
@@ -186,8 +194,6 @@ $t->data['summaryDataset'] = $dataset->getSummary();
 $t->data['topdelimiters'] = $dataset->getTopDelimiters();
 $t->data['availdelimiters'] = $dataset->availDelimiters();
 
-
-
 $t->data['delimiterPresentation'] =  $dataset->getDelimiterPresentation();
 $t->show();
 
diff --git a/templates/frontpage.php b/templates/frontpage.php
index 054ebd674..37cfb9f71 100644
--- a/templates/frontpage.php
+++ b/templates/frontpage.php
@@ -1,15 +1,10 @@
 <?php 
-#	$this->data['icon'] = 'compass_l.png';
 
-	
-// $this->data['head']  = '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery.js"></script>';
-// $this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-ui.js"></script>';
-// $this->data['head'] .= '<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 'resources/uitheme/jquery-ui-themeroller.css" />';
+
 
 $this->data['jquery'] = array('version' => '1.6', 'core' => TRUE, 'ui' => TRUE, 'css' => TRUE);
 
 $this->data['head'] = '<script type="text/javascript">
-
 $(document).ready(function() {
 	$("#tabdiv").tabs();
 });
diff --git a/templates/includes/footer.php b/templates/includes/footer.php
index 329bc68f7..7f6fe648c 100644
--- a/templates/includes/footer.php
+++ b/templates/includes/footer.php
@@ -2,8 +2,8 @@
 
 <?php
 
-if(array_key_exists('htmlContentPost', $this->data)) {
-	foreach(array_reverse($this->data['htmlContentPost']) AS $c) {
+if(isset($htmlContentPost)) {
+	foreach($htmlContentPost AS $c) {
 		echo $c;
 	}
 }
diff --git a/templates/includes/header.php b/templates/includes/header.php
index c9c4351c0..c537af760 100644
--- a/templates/includes/header.php
+++ b/templates/includes/header.php
@@ -1,4 +1,27 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<?php
+
+
+
+/**
+ * Support the htmlinject hook, which allows modules to change header, pre and post body on all pages.
+ */
+$htmlContentPre = array(); $htmlContentPost = array(); $htmlContentHead = array(); 
+
+$jquery = array();
+if (array_key_exists('jquery', $this->data)) $jquery = $this->data['jquery'];
+
+
+if (array_key_exists('pageid', $this->data)) {
+	$hookinfo = array('pre' => &$htmlContentPre, 'post' => &$htmlContentPost, 'head' => &$htmlContentHead, 'jquery' => &$jquery, 'page' => $this->data['pageid']);
+	SimpleSAML_Module::callHooks('htmlinject', $hookinfo);	
+}
+// - o - o - o - o - o - o - o - o - o - o - o - o -
+
+
+
+
+?>
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
@@ -16,35 +39,37 @@ if(array_key_exists('header', $this->data)) {
 
 <?php
 
-if(array_key_exists('jquery', $this->data)) {
-	
+if(!empty($jquery)) {
 	$version = '1.5';
-	if (array_key_exists('version', $this->data['jquery']))
-		$version = $this->data['jquery']['version'];
+	if (array_key_exists('version', $jquery))
+		$version = $jquery['version'];
 		
 	if ($version == '1.5') {
-		if (isset($this->data['jquery']['core']) && $this->data['jquery']['core'])
+		if (isset($jquery['core']) && $jquery['core'])
 			echo('<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery.js"></script>' . "\n");
 	
-		if (isset($this->data['jquery']['ui']) && $this->data['jquery']['ui'])
+		if (isset($jquery['ui']) && $jquery['ui'])
 			echo('<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-ui.js"></script>' . "\n");
 	
-		if (isset($this->data['jquery']['css']) && $this->data['jquery']['css'])
-			echo('<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 'resources/uitheme/jquery-ui-themeroller.css" />' . "\n");	
+		if (isset($jquery['css']) && $jquery['css'])
+			echo('<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 
+				'resources/uitheme/jquery-ui-themeroller.css" />' . "\n");	
 			
 	} else if ($version == '1.6') {
-		if (isset($this->data['jquery']['core']) && $this->data['jquery']['core'])
+		if (isset($jquery['core']) && $jquery['core'])
 			echo('<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-16.js"></script>' . "\n");
 	
-		if (isset($this->data['jquery']['ui']) && $this->data['jquery']['ui'])
+		if (isset($jquery['ui']) && $jquery['ui'])
 			echo('<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'resources/jquery-ui-16.js"></script>' . "\n");
 	
-		if (isset($this->data['jquery']['css']) && $this->data['jquery']['css'])
-			echo('<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 'resources/uitheme16/ui.all.css" />' . "\n");	
+		if (isset($jquery['css']) && $jquery['css'])
+			echo('<link rel="stylesheet" media="screen" type="text/css" href="/' . $this->data['baseurlpath'] . 
+				'resources/uitheme16/ui.all.css" />' . "\n");	
 	}
-	
 }
 
+
+
 ?>
 
 	
@@ -140,8 +165,9 @@ if($onLoad !== '') {
 
 
 <?php
-if(array_key_exists('htmlContentPre', $this->data)) {
-	foreach($this->data['htmlContentPre'] AS $c) {
+
+if(isset($htmlContentPre)) {
+	foreach($htmlContentPre AS $c) {
 		echo $c;
 	}
 }
diff --git a/www/index.php b/www/index.php
index 9d88920a6..017a0d737 100644
--- a/www/index.php
+++ b/www/index.php
@@ -2,272 +2,5 @@
 
 require_once('_include.php');
 
-/* Load simpleSAMLphp, configuration */
-$config = SimpleSAML_Configuration::getInstance();
-$session = SimpleSAML_Session::getInstance();
 
-/* Check if valid local session exists.. */
-if ($config->getBoolean('admin.protectindexpage', false)) {
-	SimpleSAML_Utilities::requireAdmin();
-}
-$loginurl = SimpleSAML_Utilities::getAdminLoginURL();
-$isadmin = SimpleSAML_Utilities::isAdmin();
-
-
-$warnings = array();
-
-if (SimpleSAML_Utilities::getSelfProtocol() != 'https') {
-	$warnings[] = 'warnings_https';
-}
-
-	
-$links = array();
-
-
-if ($config->getBoolean('enable.saml20-sp', TRUE) === true)
-	$links[] = array(
-		'href' => 'example-simple/saml2-example.php', 
-		'text' => 'link_saml2example');
-
-if ($config->getBoolean('enable.shib13-sp', FALSE) === true)
-	$links[] = array(
-		'href' => 'example-simple/shib13-example.php', 
-		'text' => 'link_shib13example'
-	);
-
-if($config->getBoolean('idpdisco.enableremember', FALSE)) {
-	$links[] = array(
-		'href' => 'cleardiscochoices.php',
-		'text' => 'link_cleardiscochoices',
-	);
-}
-
-$publishURL = $config->getString('metashare.publishurl', NULL);
-if ($publishURL !== NULL) {
-	$metadataSources = array(
-		'saml20-idp' => 'saml2/idp/metadata.php',
-		'saml20-sp' => 'saml2/sp/metadata.php',
-		'shib13-idp' => 'shib13/idp/metadata.php',
-		'shib13-sp' => 'shib13/sp/metadata.php',
-	);
-	foreach($metadataSources as $name => $url) {
-		if(!$config->getBoolean('enable.' . $name, FALSE)) continue;
-
-		$url = SimpleSAML_Utilities::resolveURL($url);
-		$linkTarget = SimpleSAML_Utilities::addURLparameter($publishURL, array('url' => $url));
-		$links[] = array(
-			'href' => $linkTarget,
-			'text' => 'link_publish_' . $name,
-		);
-	}
-}
-
-
-
-$linksconf = array();
-
-$linksconf[] = array(
-	'href' => 'example-simple/hostnames.php?dummy=1', 
-	'text' => 'link_diagnostics'
-);
-
-$linksconf[] = array(
-	'href' => 'admin/phpinfo.php', 
-	'text' => 'link_phpinfo'
-);
-
-$linksconf[] = array(
-	'href' => 'admin/config.php',
-	'text' => 'link_configcheck',
-);
-
-
-
-
-
-
-$linksmeta = array();
-
-$linksmeta[] = array(
-	'href' => 'admin/metadata.php', 
-	'text' => 'link_meta_overview');
-
-$linksmeta[] = array(
-	'href' => 'admin/metadata-converter.php',
-	'text' => 'link_xmlconvert',
-	);
-
-
-$metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-
-$metaentries = array('hosted' => array(), 'remote' => array() );
-if ($config->getBoolean('enable.saml20-sp', TRUE) === true) {
-	try {
-		$metaentries['hosted']['saml20-sp'] = $metadata->getMetaDataCurrent('saml20-sp-hosted');
-		$metaentries['hosted']['saml20-sp']['metadata-url'] = '/' . $config->getBaseURL() . 'saml2/sp/metadata.php?output=xhtml';
-		if ($isadmin)
-			$metaentries['remote']['saml20-idp-remote'] = $metadata->getList('saml20-idp-remote');
-	} catch(Exception $e) {}
-}
-if ($config->getBoolean('enable.saml20-idp', FALSE) === true) {
-	try {
-		$metaentries['hosted']['saml20-idp'] = $metadata->getMetaDataCurrent('saml20-idp-hosted');
-		$metaentries['hosted']['saml20-idp']['metadata-url'] = '/' . $config->getBaseURL() . 'saml2/idp/metadata.php?output=xhtml';
-		if ($isadmin)
-			$metaentries['remote']['saml20-sp-remote'] = $metadata->getList('saml20-sp-remote');
-	} catch(Exception $e) {}
-}
-if ($config->getBoolean('enable.shib13-sp', FALSE) === true) {
-	try {
-		$metaentries['hosted']['shib13-sp'] = $metadata->getMetaDataCurrent('shib13-sp-hosted');
-		$metaentries['hosted']['shib13-sp']['metadata-url'] = '/' . $config->getBaseURL() . 'shib13/sp/metadata.php?output=xhtml';
-		if ($isadmin)
-			$metaentries['remote']['shib13-idp-remote'] = $metadata->getList('shib13-idp-remote');
-	} catch(Exception $e) {}
-}
-if ($config->getBoolean('enable.shib13-idp', FALSE) === true) {
-	try {
-		$metaentries['hosted']['shib13-idp'] = $metadata->getMetaDataCurrent('shib13-idp-hosted');
-		$metaentries['hosted']['shib13-idp']['metadata-url'] = '/' . $config->getBaseURL() . 'shib13/idp/metadata.php?output=xhtml';
-		if ($isadmin)
-			$metaentries['remote']['shib13-sp-remote'] = $metadata->getList('shib13-sp-remote');
-	} catch(Exception $e) {}
-}
-
-#echo '<pre>'; print_r($metaentries); exit;
-
-
-
-
-$linksdoc = array();
-
-$linksdoc[] = array(
-	'href' => 'http://rnd.feide.no/content/installing-simplesamlphp', 
-	'text' => 'link_doc_install');
-
-if ($config->getBoolean('enable.saml20-sp', TRUE) || $config->getBoolean('enable.shib13-sp', false))
-	$linksdoc[] = array(
-		'href' => 'http://rnd.feide.no/content/using-simplesamlphp-service-provider', 
-		'text' => 'link_doc_sp');
-
-if ($config->getBoolean('enable.saml20-idp', false ) || $config->getBoolean('enable.shib13-idp', false))
-	$linksdoc[] = array(
-		'href' => 'http://rnd.feide.no/content/using-simplesamlphp-identity-provider', 
-		'text' => 'link_doc_idp');
-
-if ($config->getBoolean('enable.shib13-idp', false))
-	$linksdoc[] = array(
-		'href' => 'http://rnd.feide.no/content/configure-shibboleth-13-sp-work-simplesamlphp-idp', 
-		'text' => 'link_doc_shibsp');
-
-if ($config->getBoolean('enable.saml20-idp', false ))
-	$linksdoc[] = array(
-		'href' => 'http://rnd.feide.no/content/simplesamlphp-idp-google-apps-education', 
-		'text' => 'link_doc_googleapps');
-
-$linksdoc[] = array(
-	'href' => 'http://rnd.feide.no/content/simplesamlphp-advanced-features', 
-	'text' => 'link_doc_advanced',
-);
-
-
-
-$linksdoc[] = array(
-	'href' => 'http://rnd.feide.no/content/simplesamlphp-maintenance-and-configuration', 
-	'text' => 'link_doc_maintenance');
-
-
-$allLinks = array(
-	'links' => &$links,
-	'metadata' => &$linksmeta,
-	'doc' => &$linksdoc,
-	);
-
-SimpleSAML_Module::callHooks('frontpage', $allLinks);
-
-$enablematrix = array(
-	'saml20-sp' => $config->getBoolean('enable.saml20-sp', TRUE),
-	'saml20-idp' => $config->getBoolean('enable.saml20-idp', false),
-	'shib13-sp' => $config->getBoolean('enable.shib13-sp', false),
-	'shib13-idp' => $config->getBoolean('enable.shib13-idp', false),
-);
-
-
-$functionchecks = array(
-	'hash'             => array('required',  'Hashing function'),
-	'gzinflate'        => array('required',  'ZLib'),
-	'openssl_sign'     => array('required',  'OpenSSL'),
-	'simplexml_import_dom' => array('required', 'SimpleXML'),
-	'dom_import_simplexml' => array('required', 'XML DOM'),
-	'preg_match'       => array('required',  'RegEx support'),
-	'ldap_bind'        => array('required_ldap',  'LDAP Extension'),
-	'radius_auth_open' => array('required_radius',  'Radius Extension'),
-	'mcrypt_module_open'=> array('optional',  'MCrypt'),
-	'mysql_connect'    => array('optional',  'MySQL support'),
-);
-$funcmatrix = array();
-$funcmatrix[] = array(
-	'required' => 'required', 
-	'descr' => 'PHP Version >= 5.1.2. You run: ' . phpversion(), 
-	'enabled' => version_compare(phpversion(), '5.1.2', '>='));
-$funcmatrix[] = array(
-	'required' => 'reccomended', 
-	'descr' => 'PHP Version >= 5.2 (Required for Shibboleth 1.3 SP)', 
-	'enabled' => version_compare(phpversion(), '5.2', '>='));
-foreach ($functionchecks AS $func => $descr) {
-	$funcmatrix[] = array('descr' => $descr[1], 'required' => $descr[0], 'enabled' => function_exists($func));
-}
-
-
-/* Some basic configuration checks */
-
-if($config->getString('technicalcontact_email', 'na@example.org') === 'na@example.org') {
-	$mail_ok = FALSE;
-} else {
-	$mail_ok = TRUE;
-}
-$funcmatrix[] = array(
-	'required' => 'reccomended',
-	'descr' => 'technicalcontact_email option set',
-	'enabled' => $mail_ok
-	);
-if($config->getString('auth.adminpassword', '123') === '123') {
-	$password_ok = FALSE;
-} else {
-	$password_ok = TRUE;
-}
-$funcmatrix[] = array(
-	'required' => 'required',
-	'descr' => 'auth.adminpassword option set',
-	'enabled' => $password_ok
-);
-
-$funcmatrix[] = array(
-	'required' => 'required',
-	'descr' => 'Magic Quotes should be turned off',
-	'enabled' => (get_magic_quotes_runtime() === 0)
-);
-
-
-$t = new SimpleSAML_XHTML_Template($config, 'frontpage.php', 'frontpage');
-$t->data['isadmin'] = $isadmin;
-$t->data['loginurl'] = $loginurl;
-$t->data['header'] = 'simpleSAMLphp installation page';
-$t->data['icon'] = 'compass_l.png';
-$t->data['warnings'] = $warnings;
-$t->data['links'] = $links;
-$t->data['links_meta'] = $linksmeta;
-$t->data['links_doc'] = $linksdoc;
-$t->data['links_conf'] = $linksconf;
-$t->data['metaentries'] = $metaentries;
-
-$t->data['enablematrix'] = $enablematrix;
-$t->data['funcmatrix'] = $funcmatrix;
-$t->data['version'] = $config->getVersion();
-$t->data['directory'] = dirname(dirname(__FILE__));
-
-$t->show();
-
-
-
-?>
\ No newline at end of file
+SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('core/frontpage_welcome.php'));
-- 
GitLab