diff --git a/app/Routes.php b/app/Routes.php index a3d32e6..fa734ca 100644 --- a/app/Routes.php +++ b/app/Routes.php @@ -19,6 +19,7 @@ $router->any('/logout', 'Logout'); $router->any('/automation', 'Automation'); $router->any('/setting', 'Setting'); $router->any('/device', 'Device'); +$router->any('/plugins', 'Plugins'); $router->any('/ajax', 'Ajax'); $router->any('/oauth', 'Oauth'); @@ -28,12 +29,12 @@ $router->post('/api/logout', 'AuthApi@logout'); $router->get('/api/rooms', 'RoomsApi@default'); $router->get('/api/rooms/{roomId}/update', 'RoomsApi@update'); $router->get('/api/devices', 'DevicesApi@default'); +$router->get('/api/plugins', 'PluginsApi@default'); $router->get('/api/users', 'UsersApi@default'); $router->get('/api/server', 'ServerApi@default'); $router->get('/api/server/log', 'ServerApi@logStatus'); $router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run'); $router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail'); -$router->get('/adminer', 'WidgetApi@detail'); //cron $router->post('/cron/clean', 'CronApi@clean'); diff --git a/app/api/CronApi.php b/app/api/CronApi.php index 497cd3d..7464fb5 100644 --- a/app/api/CronApi.php +++ b/app/api/CronApi.php @@ -8,7 +8,7 @@ class CronApi extends ApiController $logKeeper = new LogMaintainer(); $logKeeper->purge(LOGTIMOUT); - //Database Backup Cleanup + //Database Backup Cleanup $backupWorker = new DatabaseBackup(); $backupWorker->purge(5); @@ -22,19 +22,34 @@ class CronApi extends ApiController $dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/'; $pluginsFiles = array_diff(scandir($dir), ['..', '.']); foreach ($pluginsFiles as $key => $pluginFile) { - $className = str_replace(".php", "", $pluginFile); - if (strpos($pluginFile, '_') === true) { - continue; - } - if (!class_exists($className)) { - continue; - } - $pluginMakeClass = new $className; - if (!method_exists($pluginMakeClass, 'make')) { + if (strpos($pluginFile, "!") === false) { + $className = str_replace(".php", "", $pluginFile); + if (strpos($pluginFile, '_') === true) { + continue; + } + if (!class_exists($className)) { + continue; + } + $pluginMakeClass = new $className; + if (!method_exists($pluginMakeClass, 'make')) { - continue; + continue; + } + $result[$className] = $pluginMakeClass->make(); + } else { + $className = str_replace("!", "", str_replace(".php", "", $pluginFile)); + if (strpos($pluginFile, '_') === true) { + continue; + } + if (!class_exists($className)) { + continue; + } + $pluginMakeClass = new $className; + if (!method_exists($pluginMakeClass, 'disable')) { + continue; + } + $result[$className] = $pluginMakeClass->disable(); } - $result[$className] = $pluginMakeClass->make(); } //Print Result diff --git a/app/api/PluginsApi.php b/app/api/PluginsApi.php new file mode 100644 index 0000000..cf59ad3 --- /dev/null +++ b/app/api/PluginsApi.php @@ -0,0 +1,12 @@ +requireAuth(); + $response = []; + + // TODO: process the request + + $this->response($response); + } +} diff --git a/app/controllers/pluginsController.php b/app/controllers/pluginsController.php new file mode 100644 index 0000000..c14ec9f --- /dev/null +++ b/app/controllers/pluginsController.php @@ -0,0 +1,16 @@ +virtual_device_name)) { + $deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id']; + if (!$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, $this->subdevice_type)) { + SubDeviceManager::create($deviceId, $this->subdevice_type, ''); + sleep(1); + $subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type)); + } + + //if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die(); + + $finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id); + $json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true); + RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']); + } else { + DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual'); + DeviceManager::approved($this->virtual_device_name); + } + return 'sucessful'; + } catch(Exception $e) { + return 'exception: ' . $e->getMessage(); + } + } + + function translate($value){ + if ($value < 50) { + return 'Good'; + } else if ($value > 51 && $value < 100) { + return 'Moderate'; + } else if ($value > 101 && $value < 150) { + return 'Normal'; + } else if ($value > 151 && $value < 200) { + return 'Unhealthy'; + } else if ($value > 201 && $value < 300) { + return 'Very Unhealthy'; + } else if ($value > 301 ) { + return 'Hazardous'; + } + return ''; + } +} diff --git a/app/views/Device.php b/app/views/Device.php index d2dc4a1..8b809d2 100644 --- a/app/views/Device.php +++ b/app/views/Device.php @@ -11,8 +11,8 @@ class Device extends Template $roomManager = new RoomManager (); $langMng = new LanguageManager ('en'); - if (!$userManager->isLogin ()) { - header ('Location: ' . BASEURL . 'device'); + if (!$userManager->isLogin()){ + header('Location: ' . BASEURL . 'login'); } $template = new Template ('device'); diff --git a/app/views/Plugins.php b/app/views/Plugins.php new file mode 100644 index 0000000..9bdd08e --- /dev/null +++ b/app/views/Plugins.php @@ -0,0 +1,38 @@ +isLogin()){ + header('Location: ' . BASEURL . 'login'); + } + + $dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/'; + $pluginsFiles = array_diff(scandir($dir), ['..', '.']); + + $plugins = array(); + + foreach ($pluginsFiles as $key => $pluginFile) { + $status = (strpos($pluginFile, "!") !== false ? false : true); + $plugins[$key]['name'] = str_replace("!", "", str_replace(".php", "", $pluginFile)); + $plugins[$key]['status'] = $status; + } + + sort($plugins); + + $template = new Template('plugins'); + $template->prepare('baseDir', BASEDIR); + $template->prepare('debugMod', DEBUGMOD); + $template->prepare('title', 'Plugins'); + $template->prepare('langMng', $langMng); + $template->prepare('plugins', $plugins); + + + + $template->render(); + } +} diff --git a/app/views/templates/part/menu.phtml b/app/views/templates/part/menu.phtml index c731c37..86e32ac 100644 --- a/app/views/templates/part/menu.phtml +++ b/app/views/templates/part/menu.phtml @@ -6,6 +6,11 @@ 'lngKey' => 'devices', 'path' => 'device', ], + 'fas fa-plug' => [ + 'slug' => 'plugins', + 'lngKey' => 'plugins', + 'path' => 'plugins', + ], 'fa-wrench' => [ 'slug' => 'setting', 'lngKey' => 'settings', diff --git a/app/views/templates/plugins.phtml b/app/views/templates/plugins.phtml new file mode 100644 index 0000000..3c938ef --- /dev/null +++ b/app/views/templates/plugins.phtml @@ -0,0 +1,54 @@ + + + + prepare('baseDir', $BASEDIR); + $partial->render(); + ?> + <?php echo $TITLE ?> + + +
+
+ +
+
+

get('t_Plugins'); ?>

+ +
+ + +
+
+ + + +
+
+
+
+
+
+ + +
+
+
+ + prepare('baseDir', BASEDIR); + $partial->render(); + //TODO js do main.js + ?> + + diff --git a/lang/cs.php b/lang/cs.php index b69b44c..8d360ce 100644 --- a/lang/cs.php +++ b/lang/cs.php @@ -8,6 +8,7 @@ return $lang = [ 'm_scenes' => 'Scény', 'm_log' => 'Log', 'm_devices' => 'Zařízení', + 'm_plugins' => 'Pluginy', //Buttons 'b_year' => 'Rok', @@ -88,6 +89,7 @@ return $lang = [ 't_listRooms' => 'Seznam Místností', 't_roomName' => 'Jméno Místnosti', 't_createRoom' => 'Vytvořit Místnost', + 't_Plugins' => 'Pluginy', //constants 'temp' => 'Teplota', diff --git a/lang/en.php b/lang/en.php index e39d0b2..eea7361 100644 --- a/lang/en.php +++ b/lang/en.php @@ -8,6 +8,7 @@ return $lang = [ 'm_scenes' => 'Scenes', 'm_log' => 'Log', 'm_devices' => 'Devices', + 'm_plugins' => 'Plugins', //Buttons 'b_year' => 'Year', @@ -88,6 +89,7 @@ return $lang = [ 't_listRooms' => 'Room List', 't_roomName' => 'Room Name', 't_createRoom' => 'Create Rom', + 't_Plugins' => 'Plugins', //constants 'humi' => 'Humidity', diff --git a/public/css/main.css b/public/css/main.css index 022dd04..c3f9a44 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -453,6 +453,33 @@ html { color: #735b26; } + .box { + border: 4px solid #43a329; + background-color: #d4f6cb; + color: #43a329; + padding: .75rem 1rem; + margin-bottom: 1rem; + } + + .box h5 { + color: #43a329; + } + + .box.disabled { + border: 4px solid #a32929; + background-color: #f6cbcb; + color: #a32929; + } + + .box.disabled h5 { + color: #a32929; + } + + .content { + width: fit-content; + margin: 5px; + } + .button { background-color: #d4def7; border: 0; diff --git a/serviceWorker.js b/serviceWorker.js new file mode 100644 index 0000000..cd7d70c --- /dev/null +++ b/serviceWorker.js @@ -0,0 +1,64 @@ +importScripts('https://www.gstatic.com/firebasejs/7.1.0/firebase-app.js'); +importScripts('https://www.gstatic.com/firebasejs/7.1.0/firebase-messaging.js'); + +/** +* Cache version, change name to force reload +*/ +var CACHE_VERSION = 'v1'; + +/** +* Stuff to put in the cache at install +*/ +var CACHE_FILES = [ + 'templates/automatio.phtml', + 'templates/dashboard.phtml', + 'templates/home.phtml', + 'templates/login.phtml', + 'templates/scene.phtml', + 'templates/setting.phtml', + 'views/Automation.phtml', + 'views/Dashboard.phtml', + 'views/Home.phtml', + 'views/Login.phtml', + 'views/Scene.phtml', + 'views/Setting.phtml', + 'assets/logo.svg' +]; + + +self.addEventListener('install', function(event) { + console.info('Installed'); +}); + +self.addEventListener('push', function(event) { + console.log('Received a push message', event); + if (event && event.data) { + var data = event.data.json(); + data = JSON.parse(data.data.notification); + console.log(data); + event.waitUntil(self.registration.showNotification(data.title, { + body: data.body, + icon: data.icon || null + })); + } +}); + +self.addEventListener('sync', function(event) { + console.info('Event: Sync'); +}); + +self.addEventListener('fetch', function (event) { + +}); + +self.addEventListener("online", function (event) { + +}); + +self.addEventListener("offline", function (event) { +}); + +self.addEventListener('notificationclick', function(e) { + +}); +