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(); + ?> +