From 93163fa2fd93e7592b92c013fc01d63917a27f81 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Mon, 30 Nov 2009 09:25:58 +0000
Subject: [PATCH] cron: Translations & web display of output.

Patch by pitbulk@gmail.com.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2011 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/cron/dictionaries/cron.php         | 56 ++++++++++++++++++++++
 modules/cron/templates/croninfo-result.php | 20 ++++++++
 modules/cron/templates/croninfo-tpl.php    | 22 ++++-----
 modules/cron/www/cron.php                  | 28 ++++++-----
 modules/cron/www/croninfo.php              |  4 +-
 5 files changed, 105 insertions(+), 25 deletions(-)
 create mode 100644 modules/cron/dictionaries/cron.php
 create mode 100644 modules/cron/templates/croninfo-result.php

diff --git a/modules/cron/dictionaries/cron.php b/modules/cron/dictionaries/cron.php
new file mode 100644
index 000000000..d2ea93691
--- /dev/null
+++ b/modules/cron/dictionaries/cron.php
@@ -0,0 +1,56 @@
+<?php
+
+$lang = array(
+
+	'cron_header' => array (
+		'da' => 'Cron resultat side',
+		'en' => 'Cron result page',
+		'es' => 'Página de resultado del cron',
+	),
+
+	'cron_result_title' => array (
+		'da' => 'Her er resultatet for opgaven udførelse:',
+		'en' => 'Here are the result for the cron job execution:',
+		'es' => 'Aqui están los resultados de las tareas en la ejecución del cron:',
+	),
+
+	'cron_info' => array (
+		'da' => 'Cron er en måde at køre tingene regelmæssigt på UNIX-systemer.',
+		'en' => 'Cron is a way to run things regularly on unix systems.',
+		'es' => 'Cron es una forma de ejecutar tareas periodicas en los sistemas UNIX.',
+	),
+
+	'cron_suggestion' => array (
+		'da' => 'Her er et forslag til en crontab fil:',
+		'en' => 'Here is a suggestion for a crontab file:',
+		'es' => 'He aquĂ­ una sugerencia de un archivo crontab:',
+	),
+
+	'cron_execution' => array (
+		'da' => 'Klik her for at køre cron job:',
+		'en' => 'Click here to run the cron jobs:',
+		'es' => 'Haga clic aquĂ­ para ejecutar las tareas de cron:',
+	),
+
+	'run_text' => array (
+		'da' => 'Run cron:',
+		'en' => 'Run cron:',
+		'es' => 'Ejecutar cron:',
+	),
+
+	'ran_text' => array (
+		'da' => 'Cron løb på',
+		'en' => 'Cron ran at',
+		'es' => 'Cron ejecutado el',
+	),
+
+	'cron_report_title' => array (
+		'da' => 'Cron rapport',
+		'en' => 'Cron report',
+		'es' => 'Informe del cron',
+	),
+
+);
+
+
+?>
\ No newline at end of file
diff --git a/modules/cron/templates/croninfo-result.php b/modules/cron/templates/croninfo-result.php
new file mode 100644
index 000000000..89f9d5d29
--- /dev/null
+++ b/modules/cron/templates/croninfo-result.php
@@ -0,0 +1,20 @@
+<?php
+
+$this->data['header'] = $this->t('cron_header');
+$this->includeAtTemplateBase('includes/header.php');
+?>
+		<p><?php echo $this->t('cron_result_title') ?></p>
+		<pre style="color: #444; padding: 1em; border: 1px solid #eee; margin: .4em "><code>
+		<?php
+			echo '<h1>' .$this->t('cron_report_title'). '</h1><p>' .$this->t('ran_text'). ' ' .$this->data['time'] . '</p>' .
+				'<p>URL: <tt>' . $this->data['url'] . '</tt></p>' .
+				'<p>Tag: ' . $this->data['tag'] . "</p>\n\n" .
+				'<ul><li>' . join('</li><li>', $this->data['summary']) . '</li></ul>';
+		?>
+		</code>
+		</pre>
+</div>
+
+<?php
+$this->includeAtTemplateBase('includes/footer.php');
+?>
diff --git a/modules/cron/templates/croninfo-tpl.php b/modules/cron/templates/croninfo-tpl.php
index 41843c122..c10c78302 100644
--- a/modules/cron/templates/croninfo-tpl.php
+++ b/modules/cron/templates/croninfo-tpl.php
@@ -1,36 +1,36 @@
 <?php
 
-$this->data['header'] = 'Cron information page';
+$this->data['header'] = $this->t('cron_header');
 $this->includeAtTemplateBase('includes/header.php');
 
+$run_text = $this->t('run_text');
 ?>
 
-	<p>Cron is a way to run things regularly on unix systems.</p>
-	
-	<p>Here is a suggestion for a crontab file:</p>
+	<p><?php echo $this->t('cron_info') ?></p>
+
+	<p><?php echo $this->t('cron_suggestion') ?></p>
 	<pre style="font-size: x-small; color: #444; padding: 1em; border: 1px solid #eee; margin: .4em "><code><?php
 		
 		foreach ($this->data['urls'] AS $url ) {
-			echo "# " . $url['title'] . "\n";
+			echo "# " . $run_text. ' [' .$url['tag']. ']' . "\n";
 			echo "" . $url['int'] . " curl --silent \"" . $url['href'] . "\" > /dev/null 2>&1\n";
 		}
 		
 		?>
 	</code></pre>
-	
-	<p>Click here to run the cron jobs:
+
+	<br><p><?php echo $this->t('cron_execution') ?></p>
 	<ul>
 		<?php
-		
+
 		foreach ($this->data['urls'] AS $url ) {
-			echo '<li><a href="' . $url['href'] . '">' . $url['title'] . '</a></li>';
+			echo '<li><a href="' . $url['href'] . '&amp;output=xhtml">' . $run_text. ' [' .$url['tag']. ']' . '</a></li>';
 		}
-		
+
 		?>
 		
 	</ul>
 
-    
 </div>
 
 <?php
diff --git a/modules/cron/www/cron.php b/modules/cron/www/cron.php
index 052757a13..0306e85cb 100644
--- a/modules/cron/www/cron.php
+++ b/modules/cron/www/cron.php
@@ -9,8 +9,6 @@ if (!is_null($cronconfig->getValue('key'))) {
 		exit;
 	}
 }
-#print_r($_REQUEST['tag']) ; exit;
-
 if (!is_null($cronconfig->getValue('allowed_tags'))) {
 	if (!in_array($_REQUEST['tag'], $cronconfig->getValue('allowed_tags'))) {
 		SimpleSAML_Logger::error('Cron - Illegal tag [' . $_REQUEST['tag'] . '].');
@@ -19,12 +17,14 @@ if (!is_null($cronconfig->getValue('allowed_tags'))) {
 }
 
 
-
 $summary = array(); 
 $croninfo = array(
 	'summary' => &$summary,
 	'tag' => $_REQUEST['tag'],
 );
+$url = SimpleSAML_Utilities::selfURL();
+$time = date(DATE_RFC822);
+
 SimpleSAML_Module::callHooks('cron', $croninfo);
 
 foreach ($summary AS $s) {
@@ -33,14 +33,13 @@ foreach ($summary AS $s) {
 
 if ($cronconfig->getValue('sendemail', TRUE) && count($summary) > 0) {
 
-	$statustext = '<ul><li>' . join('</li><li>', $summary) . '</li></ul>';
-
-	$message = '<h1>Cron report</h1><p>Cron ran at ' . date(DATE_RFC822) . '</p>' . 
-		'<p>URL: <tt>' . SimpleSAML_Utilities::selfURL() . '</tt></p>' .
-		'<p>Tag: ' . $_REQUEST['tag'] . "</p>\n\n" . $statustext;
+	$message = '<h1>Cron report</h1><p>Cron ran at ' . $time . '</p>' .
+		'<p>URL: <tt>' . $url . '</tt></p>' .
+		'<p>Tag: ' . $croninfo['tag'] . "</p>\n\n" .
+		'<ul><li>' . join('</li><li>', $summary) . '</li></ul>';
 
 	$toaddress = $config->getString('technicalcontact_email', 'na@example.org');
-	if($toaddress == 'na@example.org') {		
+	if($toaddress == 'na@example.org') {
 		SimpleSAML_Logger::error('Cron - Could not send email. [technicalcontact_email] not set in config.');
 	} else {
 		$email = new SimpleSAML_XHTML_EMail($toaddress, 'simpleSAMLphp cron report', 'no-reply@simplesamlphp.com');
@@ -50,8 +49,13 @@ if ($cronconfig->getValue('sendemail', TRUE) && count($summary) > 0) {
 	
 }
 
-#$t = new SimpleSAML_XHTML_Template($config, 'modinfo:modlist.php');
-#$t->data['modules'] = $modinfo;
-#$t->show();
+if (isset($_REQUEST['output']) && $_REQUEST['output'] == "xhtml") {
+	$t = new SimpleSAML_XHTML_Template($config, 'cron:croninfo-result.php','cron:cron');
+	$t->data['tag'] = $croninfo['tag'];
+	$t->data['time'] = $time;
+	$t->data['url'] = $url;
+	$t->data['summary'] = $summary;
+	$t->show();
+}
 
 ?>
\ No newline at end of file
diff --git a/modules/cron/www/croninfo.php b/modules/cron/www/croninfo.php
index 44a3a1ab9..1c1458eb1 100644
--- a/modules/cron/www/croninfo.php
+++ b/modules/cron/www/croninfo.php
@@ -29,14 +29,14 @@ $urls = array();
 foreach ($tags AS $tag) {
 	$urls[] = array(
 		'href' => SimpleSAML_Module::getModuleURL('cron/cron.php?key=' . $key . '&amp;tag=' . $tag),
-		'title' => 'Run cron [' . $tag . ']',
+		'tag' => $tag,
 		'int' => (array_key_exists($tag, $def) ? $def[$tag] : $def['default']),
 	);
 }
 
 
 
-$t = new SimpleSAML_XHTML_Template($config, 'cron:croninfo-tpl.php');
+$t = new SimpleSAML_XHTML_Template($config, 'cron:croninfo-tpl.php', 'cron:cron');
 $t->data['urls'] = $urls;
 $t->show();
 
-- 
GitLab