Browse Source

ADD: FindBoxCoreSystem::GetAllESLStatus($force) -> get status of all label with API 4.0.0 and force status if $force = true

Giancarlo Voci 7 years ago
parent
commit
3c9bc8b13c

+ 5 - 1
src/OpenMind/Admin/Pages.php

@@ -7,7 +7,9 @@
 
 
 namespace OpenMind\Admin;
 namespace OpenMind\Admin;
 
 
+use OpenMind\FindBox\FindBoxCoreSystem;
 use OpenMind\Web\Controller;
 use OpenMind\Web\Controller;
+use Template;
 
 
 class Pages extends Controller
 class Pages extends Controller
 {
 {
@@ -21,6 +23,8 @@ class Pages extends Controller
 
 
 	public function Admin($f3)
 	public function Admin($f3)
 	{
 	{
-		echo \Template::instance()->render('masterpage.tpl');
+		$fbc = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
+		$fbc->GetAllESLStatus();
+		echo Template::instance()->render('masterpage.tpl');
 	}
 	}
 }
 }

+ 31 - 0
src/OpenMind/Admin/ui/errors.tpl

@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="it">
+<head>
+	<meta charset="UTF-8">
+	<meta content="width=device-width, initial-scale=1" name="viewport">
+	<title>{{@SITENAME}} error page</title>
+	<link href="{{@BASEURL}}/bundle.css" rel="stylesheet" type="text/css"/>
+</head>
+<body class="bg-light error_body">
+
+<div class="container-fluid">
+	<div class="row">
+		<div class="col-md-6 mx-auto">
+			<div class="card bg-white m-1 p-2">
+				<h1 class="text-center text-info">{{@ERROR.code}} {{@ERROR.status}}</h1>
+				<br/>
+				<h3 class="text-success">Dettaglio errore:</h3>
+				<p style="color: black">{{@ERROR.text | raw}}</p>
+				<h3 class="text-success">Debug Trace:</h3>
+				<pre style="font-size: 0.8rem">{{@ERROR.trace | raw}}</pre>
+				<br/>
+				<a class="text-uppercase" href="{{@BASEURL}}">Torna alla pagina principale.</a>
+			</div>
+		</div>
+	</div>
+</div>
+
+<script src="{{@BASEURL}}/bundle.js"></script>
+
+</body>
+</html>

+ 1 - 4
src/OpenMind/Admin/ui/masterpage.tpl

@@ -28,10 +28,7 @@
 		<script>
 		<script>
 			setTimeout(() => {
 			setTimeout(() => {
 				window.location.href = "{{@BASEURL}}/{{@REQ_REDIRECT}}";
 				window.location.href = "{{@BASEURL}}/{{@REQ_REDIRECT}}";
-			}, {;
-			{@REQ_REDIRECT_MS
-			}
-			})
+			}, {;{@REQ_REDIRECT_MS}})
 
 
 		</script>
 		</script>
 	</true>
 	</true>

+ 50 - 5
src/OpenMind/FindBox/FindBoxCoreSystem.php

@@ -1,15 +1,16 @@
 <?php
 <?php
 /**
 /**
- * @author Open Mind
- * @date 28/03/2018
- * @time 09:13
  * @param array $array
  * @param array $array
  * @param array $keysToExtract
  * @param array $keysToExtract
  * @return array
  * @return array
+ * @author Open Mind
+ * @date 28/03/2018
+ * @time 09:13
  */
  */
 
 
 namespace OpenMind\FindBox;
 namespace OpenMind\FindBox;
 
 
+use Exception;
 use OpenMind\System\System;
 use OpenMind\System\System;
 
 
 function array_filter_keys(array $array, array $keysToExtract)
 function array_filter_keys(array $array, array $keysToExtract)
@@ -32,7 +33,7 @@ class FindBoxCoreSystem
 	 * @param int $port
 	 * @param int $port
 	 * @param string $APIKey
 	 * @param string $APIKey
 	 * @param string $Password
 	 * @param string $Password
-	 * @throws \Exception
+	 * @throws Exception
 	 */
 	 */
 	public function __construct(string $host, int $port, string $APIKey, string $Password)
 	public function __construct(string $host, int $port, string $APIKey, string $Password)
 	{
 	{
@@ -50,7 +51,7 @@ class FindBoxCoreSystem
 			$ret = $this->CallAPI($URI, "");
 			$ret = $this->CallAPI($URI, "");
 
 
 			if ($ret['err'] != 0)
 			if ($ret['err'] != 0)
-				throw new \Exception("Can't connect to FindBox server:<br/><br/>{$ret['value']}");
+				throw new Exception("Can't connect to FindBox server:<br/><br/>{$ret['value']}");
 
 
 			if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
 			if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
 				$details = $ret['value']['value'];
 				$details = $ret['value']['value'];
@@ -194,4 +195,48 @@ class FindBoxCoreSystem
 
 
 		return $fbOS_Response['value']['value'];
 		return $fbOS_Response['value']['value'];
 	}
 	}
+
+	/**
+	 * Request all label status to FindBox core.
+	 *
+	 * @param bool $force true = ask status directly to ESL and not from FindBox Core Cache
+	 *
+	 * @return null|array return array with labelID => status_struct
+	 */
+	public function GetAllESLStatus(bool $force = false): ?array
+	{
+		// Get all offline labels
+		$URI = '/1.0.0/index.php/smartesl.getstatus/4.0.0/[[],false]';
+		$ret = $this->CallAPI($URI, "");
+		if ($ret['err'] != 0)
+			return null;
+
+		$fbOSResponse = $this->getLabelsFromResponse($ret);
+		if (!$fbOSResponse) {
+			$this->log->write($ret['value']['value'], 'd/m/Y H:i:s');
+			return null;
+		}
+
+		$labels = $fbOSResponse;
+
+		if ($force)
+			return $labels;
+
+		$eslStatus = [];
+		foreach($labels as $labelID => $status) {
+			// Get only ONLINE labels
+			$labelStatus = strtoupper($status['data']['esl_state']);
+			if (!$force && in_array($labelStatus, ['OFFLINE', 'BLOCKED,FC']))
+				continue;
+
+			// Force get status from label
+			$URI = "/1.0.0/index.php/smartesl.getstatus/4.0.0/[[\"{$labelID}\"],true]";
+			$fbOSResponse = $this->getLabelsFromResponse($this->CallAPI($URI, ""));
+			if ($fbOSResponse != null)
+				$eslStatus[] = $fbOSResponse;
+
+		}
+
+		return $eslStatus;
+	}
 }
 }