From c900601806163f50ed28d68a5af44fec48bc144a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Tue, 3 Feb 2009 12:34:15 +0000
Subject: [PATCH] Reporting more errors in certcheck

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1231 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/certcheck/templates/certcheck.php | 38 ++++++++++++++++-------
 modules/certcheck/www/index.php           | 14 +++++++--
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/modules/certcheck/templates/certcheck.php b/modules/certcheck/templates/certcheck.php
index 41d1d373f..83fa3111e 100644
--- a/modules/certcheck/templates/certcheck.php
+++ b/modules/certcheck/templates/certcheck.php
@@ -22,22 +22,36 @@ $classes = array('odd', 'even');
 foreach($this->data['results'] as $orgkey => $org) {
 	echo('<tr class="' . ($classes[($i++ % 2)]) . '">');
 	
-	echo '<td>' . $orgkey . '</td><td>' . $org . ' days</td><td>';
 	
-	if ($org < 30) {
-		echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" />';
+	if (array_key_exists('error', $this->data['resultsm'][$orgkey])) {
+	
+		
+		echo '<td colspan="2">' . $orgkey . '</td><td>';
+		echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" /></td>';
+		echo '<td colspan="2">' . $this->data['resultsm'][$orgkey]['error'];
+		echo '</td>';
+
+	
 	} else {
-		echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" />';
-	}
-	echo '</td>';
-	echo '<td>';
-	if (array_key_exists('expire', $this->data['resultsm'][$orgkey])) echo $this->data['resultsm'][$orgkey]['expire'];
-	echo '</td>';
-	echo '<td>';
-	if (array_key_exists('issuer', $this->data['resultsm'][$orgkey])) echo $this->data['resultsm'][$orgkey]['issuer'];
-	echo '</td>';
+		
+		echo '<td>' . $orgkey . '</td><td>' . $org . ' days</td><td>';
+		
+		if ($org < 30) {
+			echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/delete.png" />';
+		} else {
+			echo '<img src="/' . $this->data['baseurlpath'] . 'resources/icons/accept.png" />';
+		}
+		echo '</td>';
+		echo '<td>';
+		if (array_key_exists('expire', $this->data['resultsm'][$orgkey])) echo $this->data['resultsm'][$orgkey]['expire'];
+		echo '</td>';
+		echo '<td>';
+		if (array_key_exists('issuer', $this->data['resultsm'][$orgkey])) echo $this->data['resultsm'][$orgkey]['issuer'];
+		echo '</td>';
 
+	}
 	echo('</tr>');
+	
 }
 ?>
 </table>
diff --git a/modules/certcheck/www/index.php b/modules/certcheck/www/index.php
index 9764ba531..329bf9525 100644
--- a/modules/certcheck/www/index.php
+++ b/modules/certcheck/www/index.php
@@ -59,7 +59,11 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 	
 #	echo 'pinging ' . $host . ' port ' . $port;
 	$ping = phpping($host, $port);
-	if ($ping[0] === FALSE) continue;
+	if ($ping[0] === FALSE) {
+		$results[$host] = 0;
+		$resultsm[$host]['error'] = 'No connectivity (ping) [' . $host . ':' . $port . ']';
+		continue;
+	}
 	
 	
 	$cmd = 'echo "" | openssl s_client -connect ' . $host . ':' . $port . ' 2> /dev/null | openssl x509 -enddate -noout';
@@ -72,7 +76,14 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 // 		echo $output; exit;
 		if (preg_match('/issuer=(.{0,40})/', $output2, $matches) ) {
 			$resultsm[$host]['issuer'] = $matches[1];
+		} else {
+			$results[$host] = 0;
+			$resultsm[$host]['error'] = 'Did not find Issuer in response [' . $host . ':' . $port . ']';
+
 		}
+	} else {
+		$results[$host] = 0;
+		$resultsm[$host]['error'] = 'Empty output from s_client -connect [' . $host . ':' . $port . ']';
 	}
 
 	if (preg_match('/notAfter=(.*)/', $output, $matches) ) {
@@ -85,7 +96,6 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 		
 		$results[$host] = $days;
 		$resultsm[$host]['expire'] = date('jS F Y', strtotime($rawdate));		
-
 	}
 	
 }
-- 
GitLab