From 412eec8a5fb6208d361c033653015ff3c74ad3ab Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Thu, 11 Jul 2013 10:59:00 -0400
Subject: [PATCH] - Improved recognition of when a service (Apache, nginx, etc.) was really restarted/reloaded successfully. Checking port 80 is not enough because nginx reloads silently, ignoring faulty configuration files, but returns a value > 0. If we don't check the return value, nginx will refuse to start when someone issues a restart the next time.

---
 interface/lib/classes/functions.inc.php |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php
index 0801c1c..74f8400 100644
--- a/interface/lib/classes/functions.inc.php
+++ b/interface/lib/classes/functions.inc.php
@@ -130,10 +130,21 @@
 	}
 	
 	public function get_ispconfig_url() {
+		global $app;
+		
 		$url = (stristr($_SERVER['SERVER_PROTOCOL'],'HTTPS') || stristr($_SERVER['HTTPS'],'on'))?'https':'http';
-		$url .= '://'.$_SERVER['SERVER_NAME'];
-		if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
-			$url .= ':'.$_SERVER['SERVER_PORT'];
+		if($_SERVER['SERVER_NAME'] != '_') {
+			$url .= '://'.$_SERVER['SERVER_NAME'];
+			if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
+				$url .= ':'.$_SERVER['SERVER_PORT'];
+			}
+		} else {
+			$app->uses("getconf");
+			$server_config = $app->getconf->get_server_config(1,'server');
+			$url .= '://'.$server_config['hostname'];
+			if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
+				$url .= ':'.$_SERVER['SERVER_PORT'];
+			}
 		}
 		return $url;
 	}
@@ -303,7 +314,7 @@
 	}
 
     public function intval($string, $force_numeric = false) {
-        if(intval($string) == 2147483647) {
+        if(intval($string) == 2147483647 || ($string > 0 && intval($string) < 0)) {
             if($force_numeric == true) return floatval($string);
             elseif(preg_match('/^([-]?)[0]*([1-9][0-9]*)([^0-9].*)*$/', $string, $match)) return $match[1].$match[2];
             else return 0;

--
Gitblit v1.9.1