Parcourir la source

fixed ping URLs that were incorrect
fixed checking of tab name if changing casing only
updated prettyPrint function to include red error
added setErrorResponse to organizr class
added setAPIErrorResponse to api response
added formatPingHost function to fix incorrectly saved ping URLs

CauseFX il y a 4 ans
Parent
commit
bbd434cf4d
5 fichiers modifiés avec 71 ajouts et 16 suppressions
  1. 55 13
      api/classes/organizr.class.php
  2. 11 2
      api/functions/normal-functions.php
  3. 2 0
      api/v2/index.php
  4. 3 1
      js/custom.js
  5. 0 0
      js/custom.min.js

+ 55 - 13
api/classes/organizr.class.php

@@ -97,7 +97,9 @@ class Organizr
 
 
 	public function __construct($updating = false)
 	public function __construct($updating = false)
 	{
 	{
-		// First Check PHP Version
+		// Set custom Error handler
+		set_error_handler([$this, 'setErrorResponse']);
+		// Next Check PHP Version
 		$this->checkPHP();
 		$this->checkPHP();
 		// Check Disk Space
 		// Check Disk Space
 		$this->checkDiskSpace();
 		$this->checkDiskSpace();
@@ -748,6 +750,34 @@ class Organizr
 		}
 		}
 	}
 	}
 
 
+	public function setAPIErrorResponse($number, $message, $file, $line)
+	{
+		$GLOBALS['api']['response']['errors'][] = [
+			'error' => $number,
+			'message' => $message,
+			'file' => $file,
+			'line' => $line
+		];
+		$this->handleError($number, $message, $file, $line);
+	}
+
+	public function setErrorResponse($number, $message, $file, $line)
+	{
+		$error = [
+			'error' => $number,
+			'message' => $message,
+			'file' => $file,
+			'line' => $line
+		];
+		$this->handleError($number, $message, $file, $line);
+		$this->prettyPrint($error, true);
+	}
+
+	public function handleError($number, $message, $file, $line)
+	{
+		error_log(sprintf('PHP %s:  %s in %s on line %d', $number, $message, $file, $line));
+	}
+
 	public function checkRoute($request)
 	public function checkRoute($request)
 	{
 	{
 		$route = '/api/v2/' . explode('api/v2/', $request->getUri()->getPath())[1];
 		$route = '/api/v2/' . explode('api/v2/', $request->getUri()->getPath())[1];
@@ -1869,6 +1899,22 @@ class Organizr
 		}
 		}
 	}
 	}
 
 
+	public function formatPingHost($host)
+	{
+		$host = $this->qualifyURL($host, true);
+		if ($host['port'] !== '') {
+			$host['port'] = str_replace(':', '', $host['port']);
+		}
+		if ($host['host'] == '' && $host['path'] !== '') {
+			$host['host'] = $host['path'];
+			$host['path'] = '';
+			if (strpos($host['host'], '/') !== false) {
+				$host['host'] = explode('/', $host['host'])[0];
+			}
+		}
+		return $host;
+	}
+
 	public function ping($pings)
 	public function ping($pings)
 	{
 	{
 		if ($this->qualifyRequest($this->config['pingAuth'], true)) {
 		if ($this->qualifyRequest($this->config['pingAuth'], true)) {
@@ -1885,14 +1931,12 @@ class Organizr
 				case "array":
 				case "array":
 					$results = [];
 					$results = [];
 					foreach ($pings as $k => $v) {
 					foreach ($pings as $k => $v) {
-						if (strpos($v, ':') !== false) {
-							$domain = explode(':', $v)[0];
-							$port = explode(':', $v)[1];
-							$ping->setHost($domain);
-							$ping->setPort($port);
+						$pingFormatted = $this->formatPingHost($v);
+						$ping->setHost($pingFormatted['host']);
+						if ($pingFormatted['port'] !== '') {
+							$ping->setPort($pingFormatted['port']);
 							$latency = $ping->ping('fsockopen');
 							$latency = $ping->ping('fsockopen');
 						} else {
 						} else {
-							$ping->setHost($v);
 							$latency = $ping->ping();
 							$latency = $ping->ping();
 						}
 						}
 						if ($latency || $latency === 0) {
 						if ($latency || $latency === 0) {
@@ -1903,14 +1947,12 @@ class Organizr
 					}
 					}
 					break;
 					break;
 				case "string":
 				case "string":
-					if (strpos($pings, ':') !== false) {
-						$domain = explode(':', $pings)[0];
-						$port = explode(':', $pings)[1];
-						$ping->setHost($domain);
-						$ping->setPort($port);
+					$pingFormatted = $this->formatPingHost($pings);
+					$ping->setHost($pingFormatted['host']);
+					if ($pingFormatted['port'] !== '') {
+						$ping->setPort($pingFormatted['port']);
 						$latency = $ping->ping('fsockopen');
 						$latency = $ping->ping('fsockopen');
 					} else {
 					} else {
-						$ping->setHost($pings);
 						$latency = $ping->ping();
 						$latency = $ping->ping();
 					}
 					}
 					if ($latency || $latency === 0) {
 					if ($latency || $latency === 0) {

+ 11 - 2
api/functions/normal-functions.php

@@ -88,10 +88,19 @@ trait NormalFunctions
 	}
 	}
 
 
 	// Print output all purrty
 	// Print output all purrty
-	public function prettyPrint($v)
+	public function prettyPrint($v, $error = false)
 	{
 	{
+		if ($error) {
+			$background = 'red';
+			$border = 'black';
+			$text = 'white';
+		} else {
+			$background = '#f2f2f2';
+			$border = 'black';
+			$text = 'black';
+		}
 		$trace = debug_backtrace()[0];
 		$trace = debug_backtrace()[0];
-		echo '<pre style="white-space: pre; text-overflow: ellipsis; overflow: hidden; background-color: #f2f2f2; border: 2px solid black; border-radius: 5px; padding: 5px; margin: 5px;">' . $trace['file'] . ':' . $trace['line'] . ' ' . gettype($v) . "\n\n" . print_r($v, 1) . '</pre><br/>';
+		echo '<pre style="white-space: pre; text-overflow: ellipsis; overflow: hidden; color: ' . $text . '; background-color: ' . $background . '; border: 2px solid ' . $border . '; border-radius: 5px; padding: 5px; margin: 5px;">' . $trace['file'] . ':' . $trace['line'] . ' ' . gettype($v) . "\n\n" . print_r($v, 1) . '</pre><br/>';
 	}
 	}
 
 
 	public function gen_uuid()
 	public function gen_uuid()

+ 2 - 0
api/v2/index.php

@@ -87,6 +87,8 @@ $app->add(function ($request, $handler) {
 	// add the organizr to your request as [READ-ONLY]
 	// add the organizr to your request as [READ-ONLY]
 	$Organizr = new Organizr();
 	$Organizr = new Organizr();
 	$request = $request->withAttribute('Organizr', $Organizr);
 	$request = $request->withAttribute('Organizr', $Organizr);
+	// set custom error handler
+	set_error_handler([$Organizr, 'setAPIErrorResponse']);
 	return $handler->handle($request);
 	return $handler->handle($request);
 });
 });
 //$app->add(new Lowercase());
 //$app->add(new Lowercase());

+ 3 - 1
js/custom.js

@@ -858,6 +858,8 @@ function convertMinutesToMs(minutes){
 $(document).on("click", ".editTab", function () {
 $(document).on("click", ".editTab", function () {
     var originalTabName = $('#originalTabName').html();
     var originalTabName = $('#originalTabName').html();
     var tabInfo = $('#edit-tab-form').serializeToJSON();
     var tabInfo = $('#edit-tab-form').serializeToJSON();
+    let tabNameLower = tabInfo.name.toLowerCase();
+    let originalTabNameLower = originalTabName.toLowerCase();
     if (typeof tabInfo.id == 'undefined' || tabInfo.id == '') {
     if (typeof tabInfo.id == 'undefined' || tabInfo.id == '') {
         message('Edit Tab Error',' Could not get Tab ID',activeInfo.settings.notifications.position,'#FFF','error','5000');
         message('Edit Tab Error',' Could not get Tab ID',activeInfo.settings.notifications.position,'#FFF','error','5000');
 	    return false;
 	    return false;
@@ -874,7 +876,7 @@ $(document).on("click", ".editTab", function () {
         message('Edit Tab Error',' Please set a Tab URL or Local URL',activeInfo.settings.notifications.position,'#FFF','warning','5000');
         message('Edit Tab Error',' Please set a Tab URL or Local URL',activeInfo.settings.notifications.position,'#FFF','warning','5000');
 	    return false;
 	    return false;
     }
     }
-    if(checkIfTabNameExists(tabInfo.name) && originalTabName !== tabInfo.name){
+    if(checkIfTabNameExists(tabInfo.name) && originalTabNameLower !== tabNameLower){
         message('Edit Tab Error',' Tab name already used',activeInfo.settings.notifications.position,'#FFF','warning','5000');
         message('Edit Tab Error',' Tab name already used',activeInfo.settings.notifications.position,'#FFF','warning','5000');
         return false;
         return false;
     }
     }

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
js/custom.min.js


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff