Make plugins list and switcher
This commit is contained in:
@@ -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');
|
||||
|
@@ -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
|
||||
|
12
app/api/PluginsApi.php
Normal file
12
app/api/PluginsApi.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
class PluginsApi extends ApiController{
|
||||
|
||||
public function default(){
|
||||
$this->requireAuth();
|
||||
$response = [];
|
||||
|
||||
// TODO: process the request
|
||||
|
||||
$this->response($response);
|
||||
}
|
||||
}
|
16
app/controllers/pluginsController.php
Normal file
16
app/controllers/pluginsController.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
if (!empty ($_POST)){
|
||||
if (
|
||||
isset($_POST['name']) &&
|
||||
$_POST['name'] != '' &&
|
||||
isset($_POST['actualStatus'])
|
||||
){
|
||||
if ($_POST['actualStatus']) {
|
||||
rename($_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/' . $_POST['name'] . ".php", $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/!' . $_POST['name'] . ".php");
|
||||
} else {
|
||||
rename($_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/!' . $_POST['name'] . ".php", $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/' . $_POST['name'] . ".php");
|
||||
}
|
||||
header('Location: ./plugins');
|
||||
die();
|
||||
}
|
||||
}
|
52
app/plugins/!AirQuality.php
Normal file
52
app/plugins/!AirQuality.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
class AirQuality extends VirtualDeviceManager
|
||||
{
|
||||
private $city_sluig = "prague";
|
||||
private $app_id = "53ccbc353bb0bd0b05515169a593b96c38d57c48";
|
||||
private $api_uri = 'http://api.waqi.info/feed/%s/?token=%s'; // Your redirect uri
|
||||
private $virtual_device_name = "Air Quality";
|
||||
private $subdevice_type = "air-quality";
|
||||
|
||||
function make()
|
||||
{
|
||||
try {
|
||||
if (DeviceManager::registeret($this->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 '';
|
||||
}
|
||||
}
|
@@ -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');
|
||||
|
38
app/views/Plugins.php
Normal file
38
app/views/Plugins.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class Plugins extends Template
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
$userManager = new UserManager();
|
||||
$langMng = new LanguageManager('en');
|
||||
|
||||
|
||||
if (!$userManager->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();
|
||||
}
|
||||
}
|
@@ -6,6 +6,11 @@
|
||||
'lngKey' => 'devices',
|
||||
'path' => 'device',
|
||||
],
|
||||
'fas fa-plug' => [
|
||||
'slug' => 'plugins',
|
||||
'lngKey' => 'plugins',
|
||||
'path' => 'plugins',
|
||||
],
|
||||
'fa-wrench' => [
|
||||
'slug' => 'setting',
|
||||
'lngKey' => 'settings',
|
||||
|
54
app/views/templates/plugins.phtml
Normal file
54
app/views/templates/plugins.phtml
Normal file
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
</head>
|
||||
<body class="no-transitions">
|
||||
<div class="row no-gutters main">
|
||||
<div class="col-md-3 d-sm-none"></div>
|
||||
<div class="col-md-3 nav-container">
|
||||
<?php
|
||||
$partial = new Partial('menu');
|
||||
$partial->prepare('item', 'plugins');
|
||||
$partial->prepare('langMng',$LANGMNG);
|
||||
$partial->prepare('debugMod',$DEBUGMOD);
|
||||
$partial->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-9 main-body">
|
||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||
<h1><?php echo $LANGMNG->get('t_Plugins'); ?></h1>
|
||||
|
||||
<div class="row mb-4">
|
||||
<?php if ($PLUGINS): ?>
|
||||
<?php foreach ($PLUGINS as $plugin): ?>
|
||||
<div class="content">
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="name" value="<?php echo $plugin['name']; ?>"/>
|
||||
<input type="hidden" name="actualStatus" value="<?php echo $plugin['status']; ?>"/>
|
||||
<a onclick="$(this).closest('form').submit();">
|
||||
<div class="panel box content <?php echo ($plugin['status'] ? '' : 'disabled '); ?>p-4">
|
||||
<h5><?php echo $plugin['name']; ?></h5>
|
||||
</div>
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$partial = new Partial('footer');
|
||||
$partial->prepare('baseDir', BASEDIR);
|
||||
$partial->render();
|
||||
//TODO js do main.js
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user