Compare commits
73 Commits
38cc436f4d
...
remasterin
Author | SHA1 | Date | |
---|---|---|---|
|
0045bdeb84 | ||
|
9c565d90fa | ||
|
f80b9a6b43 | ||
|
49f2354908 | ||
|
541ea0002f | ||
|
135dfcb666 | ||
|
04e83dccf6 | ||
|
4ab70a1c2d | ||
|
5f03295ad3 | ||
|
66dc2a3670 | ||
|
b9a967642a | ||
|
fe1247fdaf | ||
|
9d9304d30e | ||
|
c6f57a3661 | ||
|
adfb564ccc | ||
|
a3eaf16fd6 | ||
8b32ecc619 | |||
7ea4a90980 | |||
38b29a2a4a | |||
821c0926e8 | |||
3d3b073131 | |||
|
485709d61f | ||
|
1d44bd62e2 | ||
|
75dab33c9a | ||
2410441b88 | |||
|
1f49391b36 | ||
|
c17e3090a8 | ||
dc77534bad | |||
|
cb45cf9e22 | ||
|
47a5f71d9b | ||
|
1642ece7f4 | ||
696ff07987 | |||
|
1415c0cf2d | ||
|
d9952a59fb | ||
|
b5b2bb95a7 | ||
bad58f82e2 | |||
|
64b50ead9f | ||
|
a3a87d39d2 | ||
|
c4f36235ab | ||
daa0e0a2c5 | |||
|
464f229a16 | ||
|
fe72097d75 | ||
|
98efb779b1 | ||
30045b9f65 | |||
f21293bc01 | |||
bf79e9cee7 | |||
cf30a1280d | |||
e11023d1c9 | |||
cfcfefefd8 | |||
09d78192b6 | |||
158220700b | |||
|
76e036181a | ||
|
39f44c8d03 | ||
|
ee0ebff76a | ||
42443c8b58 | |||
e95435a707 | |||
74f6779c63 | |||
181a65a99b | |||
|
ff2c51d505 | ||
|
879a63948f | ||
|
52688a5e70 | ||
|
3181c9dc72 | ||
|
ac43bdaf64 | ||
|
e65b046d47 | ||
|
50a0d3036c | ||
|
fffaf0e237 | ||
|
e9b8e0a453 | ||
|
0e3f571a0d | ||
|
5ad11cbb10 | ||
|
a4cdb250b9 | ||
|
72e6f475d7 | ||
|
4b94ef29c1 | ||
|
8a00190850 |
@@ -1,6 +0,0 @@
|
|||||||
.git
|
|
||||||
_FIRMWARE
|
|
||||||
_INSTALATION
|
|
||||||
_README_IMG
|
|
||||||
README.md
|
|
||||||
.todo
|
|
7
.gitignore
vendored
7
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
.ftpconfig
|
.ftpconfig
|
||||||
.ftpconfig2
|
.ftpconfig2
|
||||||
*.log
|
*.log
|
||||||
|
*.bin
|
||||||
config.php
|
config.php
|
||||||
|
|
||||||
_nemazat/index.html
|
_nemazat/index.html
|
||||||
@@ -12,6 +13,8 @@ _nemazat/css/font-awesome.min.css
|
|||||||
.vscode/
|
.vscode/
|
||||||
.vscode/sftp.json
|
.vscode/sftp.json
|
||||||
|
|
||||||
app/updater/*.bin
|
vendor/
|
||||||
app/logs/*.log
|
|
||||||
|
logs/*.log
|
||||||
|
updater/*.bin
|
||||||
backup/*.zip
|
backup/*.zip
|
||||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule ".docker"]
|
||||||
|
path = .docker
|
||||||
|
url = https://github.com/GamerClassN7/Docker-Xamp-Server.git
|
@@ -18,5 +18,6 @@ RewriteRule (.*) ./public/$1 [L]
|
|||||||
|
|
||||||
# serve all other request as query parameters
|
# serve all other request as query parameters
|
||||||
RewriteRule (.*) ./public/index.php?url=$1 [L,QSA]
|
RewriteRule (.*) ./public/index.php?url=$1 [L,QSA]
|
||||||
|
#RewriteRule ^(.*?\.php)/([^/]*)/([^/]*)(/.+)? ./public/index.php?url=$1&$2&$3 [NC,N,QSA]
|
||||||
|
|
||||||
AddType application/x-httpd-php .php .phtml
|
AddType application/x-httpd-php .php .phtml
|
||||||
|
1
.todo
1
.todo
@@ -11,3 +11,4 @@
|
|||||||
//TODO: Fix Default Room selection
|
//TODO: Fix Default Room selection
|
||||||
//TODO: Fix User Delete button
|
//TODO: Fix User Delete button
|
||||||
//TODO: Fix new add email form
|
//TODO: Fix new add email form
|
||||||
|
//BUG: API RETURN ERROR VHEN NO ROOM IS PRESENT
|
||||||
|
@@ -1,255 +0,0 @@
|
|||||||
<pre>
|
|
||||||
<?php
|
|
||||||
var_dump($_POST);
|
|
||||||
var_dump(file_exists("./app/updater/" . "3C71BF22FDCF" . ".bin"));
|
|
||||||
?>
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<form class="" action="" method="post">
|
|
||||||
<label for="operator">Typ podmínky</label>
|
|
||||||
<select class="" name="operator">
|
|
||||||
<option value="or">OR</option>
|
|
||||||
<option value="and">AND</option>
|
|
||||||
</select>
|
|
||||||
<div class="variableArea">
|
|
||||||
|
|
||||||
<button name="addButton" id="addButton">+</button>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<label for="resetOperator">Typ podmínky</label>
|
|
||||||
<select class="" name="resetOperator">
|
|
||||||
<option value="or">OR</option>
|
|
||||||
<option value="and">AND</option>
|
|
||||||
</select>
|
|
||||||
<div class="resetvariableArea">
|
|
||||||
|
|
||||||
<button name="restartaAddButton" id="restartAddButton">+</button>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<button type="submit" name="button">Odeslat</button>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
function foo(element){
|
|
||||||
var id = element.attr("name").match(/\d+/)[0]
|
|
||||||
$("[name='variable["+id+"][value]']").remove();
|
|
||||||
$("[name='variable["+id+"][equaler]']").remove();
|
|
||||||
|
|
||||||
if (element.val() == "atDeviceValue") {
|
|
||||||
var arrVarOperator = [
|
|
||||||
{val : '>', text: '>'},
|
|
||||||
{val : '<', text: '<'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varOperator = $('<select name="variable['+id+'][equaler]">');
|
|
||||||
$(arrVarOperator).each(function() {
|
|
||||||
varOperator.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
element.parent().append(varOperator);
|
|
||||||
|
|
||||||
|
|
||||||
var input = $("<input/>");
|
|
||||||
input.attr("type","text");
|
|
||||||
input.attr("name","variable["+id+"][value]");
|
|
||||||
element.parent().append(input);
|
|
||||||
} else if (element.val() == "time") {
|
|
||||||
var arrVarOperator = [
|
|
||||||
{val : '>', text: '>'},
|
|
||||||
{val : '<', text: '<'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varOperator = $('<select name="variable['+id+'][equaler]">');
|
|
||||||
$(arrVarOperator).each(function() {
|
|
||||||
varOperator.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
element.parent().append(varOperator);
|
|
||||||
|
|
||||||
var input = $("<input/>");
|
|
||||||
input.attr("type","time");
|
|
||||||
input.attr("name","variable["+id+"][value]");
|
|
||||||
element.parent().append(input);
|
|
||||||
}else {
|
|
||||||
var arrVarOperator = [
|
|
||||||
{val : '=', text: '=='},
|
|
||||||
{val : '!=', text: '!='},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varOperator = $('<select name="variable['+id+'][equaler]">');
|
|
||||||
$(arrVarOperator).each(function() {
|
|
||||||
varOperator.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
element.parent().append(varOperator);
|
|
||||||
|
|
||||||
var arrVarValue = [
|
|
||||||
{val : 'true', text: 'True'},
|
|
||||||
{val : 'false', text: 'False'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varValue = $('<select name="variable['+id+'][value]">');
|
|
||||||
$(arrVarValue).each(function() {
|
|
||||||
varValue.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
element.parent().append(varValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$("#addButton,#restartAddButton").click( function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
var numItems = $('.var').length
|
|
||||||
var arrVarSelect = [
|
|
||||||
{val : 'sunSet', text: 'Západ Slunce'},
|
|
||||||
{val : 'sunRise', text: 'Východ Slunce'},
|
|
||||||
{val : 'inHome', text: 'Příchod'},
|
|
||||||
{val : 'outHome', text: 'Odchod'},
|
|
||||||
{val : 'time', text: 'Čas'},
|
|
||||||
{val : 'atDeviceValue', text: 'Při hodnotě zařízení'},
|
|
||||||
{val : 'sunRise', text: 'Východ Slunce'},
|
|
||||||
{val : 'noOneHome', text: 'Nikdo Doma'},
|
|
||||||
{val : 'someOneHome', text: 'Nekdo Doma'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varSelect = $('<select name="variable['+numItems+'][what]">');
|
|
||||||
$(arrVarSelect).each(function() {
|
|
||||||
varSelect.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
varSelect.attr("onchange", "foo($(this))");
|
|
||||||
|
|
||||||
/*onchange = function(e) {
|
|
||||||
console.log(this.value);
|
|
||||||
if (this.value == 'atDeviceValue') {
|
|
||||||
alert("ok");
|
|
||||||
}
|
|
||||||
};*/
|
|
||||||
|
|
||||||
var arrVarOperator = [
|
|
||||||
{val : '>', text: '>'},
|
|
||||||
{val : '<', text: '<'},
|
|
||||||
{val : '=', text: '=='},
|
|
||||||
{val : '!=', text: '!='},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varOperator = $('<select name="variable['+numItems+'][equaler]">');
|
|
||||||
$(arrVarOperator).each(function() {
|
|
||||||
varOperator.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
var arrVarValue = [
|
|
||||||
{val : 'true', text: 'True'},
|
|
||||||
{val : 'false', text: 'False'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varValue = $('<select name="variable['+numItems+'][value]">');
|
|
||||||
$(arrVarValue).each(function() {
|
|
||||||
varValue.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
var newDiv = $("<div class=var>").append(varSelect);
|
|
||||||
newDiv = newDiv.append(varOperator);
|
|
||||||
newDiv = newDiv.append(varValue);
|
|
||||||
$(this).parent().append(newDiv);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/*var arrVarSelect = [
|
|
||||||
{val : 'sunSet', text: 'Západ Slunce'},
|
|
||||||
{val : 'sunRise', text: 'Východ Slunce'},
|
|
||||||
{val : 'inHome', text: 'Příchod'},
|
|
||||||
{val : 'outHome', text: 'Odchod'},
|
|
||||||
{val : 'time', text: 'Čas'},
|
|
||||||
{val : 'atDeviceValue', text: 'Při hodnotě zařízení'},
|
|
||||||
{val : 'sunRise', text: 'Východ Slunce'},
|
|
||||||
{val : 'noOneHome', text: 'Nikdo Doma'},
|
|
||||||
{val : 'someOneHome', text: 'Nekdo Doma'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varSelect = $('<select name="variable['+numItems+'][]">');
|
|
||||||
$(arrVarSelect).each(function() {
|
|
||||||
varSelect.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
var arrVarOperator = [
|
|
||||||
{val : '>', text: '>'},
|
|
||||||
{val : '<', text: '<'},
|
|
||||||
{val : '=', text: '=='},
|
|
||||||
{val : '!=', text: '!='},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varOperator = $('<select name="variable['+numItems+'][]">');
|
|
||||||
$(arrVarOperator).each(function() {
|
|
||||||
varOperator.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
var arrVarValue = [
|
|
||||||
{val : 'true', text: 'True'},
|
|
||||||
{val : 'false', text: 'False'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varValue = $('<select name="variable['+numItems+'][]">');
|
|
||||||
$(arrVarValue).each(function() {
|
|
||||||
varValue.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO změna výstupní proměné na základě vstupu date,num etc
|
|
||||||
var newDiv = $("<div class=var>").append(varSelect);/*.change(
|
|
||||||
function (subEvent) {
|
|
||||||
alert(subEvent);
|
|
||||||
}
|
|
||||||
);*/
|
|
||||||
/*newDiv = newDiv.append(varOperator);
|
|
||||||
newDiv = newDiv.append(varValue);
|
|
||||||
$(".restartaAddButton")append(newDiv);*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
var arrVarSelect = [
|
|
||||||
{val : 'sunSet', text: 'Západ Slunce'},
|
|
||||||
{val : 'sunRise', text: 'Východ Slunce'},
|
|
||||||
{val : 'inHome', text: 'Příchod'},
|
|
||||||
{val : 'outHome', text: 'Odchod'},
|
|
||||||
{val : 'time', text: 'Čas'},
|
|
||||||
{val : 'atDeviceValue', text: 'Při hodnotě zařízení'},
|
|
||||||
{val : 'sunRise', text: 'Východ Slunce'},
|
|
||||||
{val : 'noOneHome', text: 'Nikdo Doma'},
|
|
||||||
{val : 'someOneHome', text: 'Nekdo Doma'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varSelect = $('<select name="variable['+numItems+'][]">');
|
|
||||||
$(arrVarSelect).each(function() {
|
|
||||||
varSelect.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
var arrVarOperator = [
|
|
||||||
{val : '>', text: '>'},
|
|
||||||
{val : '<', text: '<'},
|
|
||||||
{val : '=', text: '=='},
|
|
||||||
{val : '!=', text: '!='},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varOperator = $('<select name="variable['+numItems+'][]">');
|
|
||||||
$(arrVarOperator).each(function() {
|
|
||||||
varOperator.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
var arrVarValue = [
|
|
||||||
{val : 'true', text: 'True'},
|
|
||||||
{val : 'false', text: 'False'},
|
|
||||||
];
|
|
||||||
|
|
||||||
var varValue = $('<select name="variable['+numItems+'][]">');
|
|
||||||
$(arrVarValue).each(function() {
|
|
||||||
varValue.append($('<option>').attr('value',this.val).text(this.text));
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO změna výstupní proměné na základě vstupu date,num etc
|
|
||||||
var newDiv = $("<div class=var>").append(varSelect);/*.change(
|
|
||||||
function (subEvent) {
|
|
||||||
alert(subEvent);
|
|
||||||
}
|
|
||||||
);*/
|
|
||||||
/* newDiv = newDiv.append(varOperator);
|
|
||||||
newDiv = newDiv.append(varValue);
|
|
||||||
$(".variableArea").parent().append(newDiv);*/
|
|
||||||
|
|
||||||
</script>
|
|
11
README.md
11
README.md
@@ -136,6 +136,17 @@ Distributed under the MIT License. See `LICENSE` for more information.
|
|||||||
Project Link: [https://github.com/GamerClassN7/Smart_Home/](https://github.com/GamerClassN7/Smart_Home/) <br> <br>
|
Project Link: [https://github.com/GamerClassN7/Smart_Home/](https://github.com/GamerClassN7/Smart_Home/) <br> <br>
|
||||||
<sup><sub>Tags (ignore): ESP32 ESP12 ESP08 ESP01 ESP Smart Home Automation System PWA PHP HTML JS DHT11 DHT22
|
<sup><sub>Tags (ignore): ESP32 ESP12 ESP08 ESP01 ESP Smart Home Automation System PWA PHP HTML JS DHT11 DHT22
|
||||||
|
|
||||||
|
## Code Statistics
|
||||||
|
Type | Files | Lines
|
||||||
|
-----|-------|-----------
|
||||||
|
php | 2 | 2298 (89%)
|
||||||
|
md | 1 | 171 (7%)
|
||||||
|
js | 1 | 64 (2%)
|
||||||
|
sh | 1 | 34 (1%)
|
||||||
|
json | 1 | 10 (0.4%)
|
||||||
|
-----|-------|-----------
|
||||||
|
All | 6 | 2577
|
||||||
|
|
||||||
## Folder structure
|
## Folder structure
|
||||||
```
|
```
|
||||||
- /app # app specific files
|
- /app # app specific files
|
||||||
|
2044
adminer.php
2044
adminer.php
File diff suppressed because one or more lines are too long
@@ -3,13 +3,24 @@
|
|||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set( 'display_errors','1');
|
ini_set( 'display_errors','1');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//setup
|
//setup
|
||||||
parse_str($_SERVER['QUERY_STRING'], $params);
|
parse_str($_SERVER['QUERY_STRING'], $params);
|
||||||
$urlSes = str_replace((!empty ($params['url']) ? $params['url'] : ""), "", str_replace('https://' . $_SERVER['HTTP_HOST'], "", $_SERVER['REQUEST_URI']));
|
if (defined ("BASEDIR")) {
|
||||||
|
$urlSes = BASEDIR;
|
||||||
|
} else {
|
||||||
|
$urlSes = str_replace((!empty ($params['url']) ? $params['url'] : ""), "", str_replace('https://' . $_SERVER['HTTP_HOST'], "", $_SERVER['REQUEST_URI']));
|
||||||
|
}
|
||||||
|
if (defined ("BASEDIR") && defined ("BASEURL")) {
|
||||||
|
$domain = str_replace("http://", "", str_replace("https://", "", str_replace(BASEDIR, "", BASEURL)));
|
||||||
|
} else {
|
||||||
|
$domain = str_replace("/var/www/", "", $_SERVER['DOCUMENT_ROOT']);
|
||||||
|
}
|
||||||
session_set_cookie_params(
|
session_set_cookie_params(
|
||||||
1209600,
|
1209600,
|
||||||
$urlSes,
|
$urlSes,
|
||||||
str_replace("/var/www/", "", $_SERVER['DOCUMENT_ROOT']),
|
$domain,
|
||||||
true,
|
true,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@@ -96,10 +107,8 @@ $apiLogManager->write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRI
|
|||||||
$apiLogManager->write("[API] POST body\n" . json_encode($_POST, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API] POST body\n" . json_encode($_POST, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
$apiLogManager->write("[API] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Debugger::flag('dbconnect');
|
Debugger::flag('dbconnect');
|
||||||
//D B Conector
|
//DB Conector
|
||||||
Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
|
Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
|
||||||
|
|
||||||
Debugger::flag('routes');
|
Debugger::flag('routes');
|
||||||
|
@@ -10,6 +10,7 @@ $router->setDefault(function(){
|
|||||||
unset($logManager);
|
unset($logManager);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//Pages
|
//Pages
|
||||||
$router->any('/', 'Log');
|
$router->any('/', 'Log');
|
||||||
$router->any('/log', 'Log');
|
$router->any('/log', 'Log');
|
||||||
@@ -19,35 +20,64 @@ $router->any('/logout', 'Logout');
|
|||||||
$router->any('/automation', 'Automation');
|
$router->any('/automation', 'Automation');
|
||||||
$router->any('/setting', 'Setting');
|
$router->any('/setting', 'Setting');
|
||||||
$router->any('/device', 'Device');
|
$router->any('/device', 'Device');
|
||||||
|
$router->any('/device/{sortBy}/{sortType}', 'Device');
|
||||||
$router->any('/plugins', 'Plugins');
|
$router->any('/plugins', 'Plugins');
|
||||||
$router->any('/ajax', 'Ajax');
|
$router->any('/ajax', 'Ajax');
|
||||||
$router->any('/oauth', 'Oauth');
|
$router->any('/oauth', 'Oauth');
|
||||||
|
|
||||||
//Vue APP
|
//Vue APP - Authentication
|
||||||
$router->post('/api/login', 'AuthApi@login');
|
$router->post('/api/login', 'AuthApi@login');
|
||||||
$router->post('/api/logout', 'AuthApi@logout');
|
$router->post('/api/logout', 'AuthApi@logout');
|
||||||
|
|
||||||
|
//Vue APP - Rooms
|
||||||
$router->get('/api/rooms', 'RoomsApi@default');
|
$router->get('/api/rooms', 'RoomsApi@default');
|
||||||
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
||||||
|
|
||||||
$router->get('/api/devices', 'DevicesApi@default');
|
$router->get('/api/devices', 'DevicesApi@default');
|
||||||
|
|
||||||
$router->get('/api/plugins', 'PluginsApi@default');
|
$router->get('/api/plugins', 'PluginsApi@default');
|
||||||
|
|
||||||
$router->get('/api/users', 'UsersApi@default');
|
$router->get('/api/users', 'UsersApi@default');
|
||||||
|
|
||||||
|
//Vue APP - Server Info
|
||||||
$router->get('/api/server', 'ServerApi@default');
|
$router->get('/api/server', 'ServerApi@default');
|
||||||
$router->get('/api/server/log', 'ServerApi@logStatus');
|
$router->get('/api/server/log', 'ServerApi@logStatus');
|
||||||
|
|
||||||
|
//Vue APP - Widgets
|
||||||
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
||||||
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
||||||
|
$router->get('/api/widgets/{widgetId}/detail/{period}', 'WidgetApi@detail');
|
||||||
|
$router->post('/api/widgets/{widgetId}/edit', 'WidgetApi@edit');
|
||||||
|
|
||||||
|
//Vue APP - Automations Endpoints
|
||||||
|
$router->get('/api/automations', 'AutomationsApi@default');
|
||||||
|
$router->get('/api/automations/{automationId}/detail', 'AutomationsApi@detail');
|
||||||
|
$router->post('/api/automations/create', 'AutomationsApi@create');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//cron
|
//cron
|
||||||
$router->post('/cron/clean', 'CronApi@clean');
|
$router->post('/cron/clean', 'CronApi@clean');
|
||||||
$router->post('/cron/fetch', 'CronApi@fetch');
|
$router->post('/cron/fetch', 'CronApi@fetch');
|
||||||
|
$router->post('/cron/automations', 'CronApi@automations');
|
||||||
|
|
||||||
|
|
||||||
//Google Home - API
|
//Google Home - API
|
||||||
$router->any('/api/HA/auth', 'Oauth');
|
$router->any('/api/HA/auth', 'Oauth@default');
|
||||||
|
$router->any('/api/HA/token', 'Oauth@token');
|
||||||
$router->any('/api/HA', 'GoogleHomeApi@response');
|
$router->any('/api/HA', 'GoogleHomeApi@response');
|
||||||
|
$router->any('/api/HA/', 'GoogleHomeApi@response');
|
||||||
|
|
||||||
|
|
||||||
//Endpoints API
|
//Endpoints API
|
||||||
$router->post('/api/endpoint/', 'EndpointsApi@default');
|
$router->post('/api/endpoint/', 'EndpointsApi@default');
|
||||||
$router->any('/api/update/', 'UpdatesApi@default');
|
$router->any('/api/update/', 'UpdatesApi@default');
|
||||||
$router->any('/api/users/status', 'UsersApi@status');
|
$router->any('/api/users/status', 'UsersApi@status');
|
||||||
|
$router->any('/api/users/subscribe', 'UsersApi@subscribe');
|
||||||
|
|
||||||
|
//Endpoints API - V2
|
||||||
|
$router->post('/api/v2/endpoint/', 'EndpointsApi@default_v2');
|
||||||
|
$router->post('/api/v2/endpoint/cofiguration', 'EndpointsApi@cofiguration_v2');
|
||||||
|
|
||||||
// examples
|
// examples
|
||||||
$router->any('/api/example', 'ExampleApi@example');
|
$router->any('/api/example', 'ExampleApi@example');
|
||||||
|
44
app/api/AutomationsApi.php
Normal file
44
app/api/AutomationsApi.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class AutomationsApi extends ApiController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function default()
|
||||||
|
{
|
||||||
|
//$this->requireAuth();
|
||||||
|
$response = [];
|
||||||
|
$response = AutomationManager::getAll(["automation_id","name","enabled"]);
|
||||||
|
|
||||||
|
$this->response($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function detail($automationId)
|
||||||
|
{
|
||||||
|
//$this->requireAuth();
|
||||||
|
$response = [];
|
||||||
|
$response = AutomationManager::getById($automationId, ["automation_id", "last_execution_time", "owner_id", "conditions", "tasks"]);
|
||||||
|
|
||||||
|
$this->response($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$this->requireAuth();
|
||||||
|
$obj = $this->input;
|
||||||
|
|
||||||
|
if (
|
||||||
|
empty($obj['name']) ||
|
||||||
|
!isset($obj['name']) ||
|
||||||
|
!isset($obj['conditions']) ||
|
||||||
|
!isset($obj['tasks']) ||
|
||||||
|
!isset($obj['days'])
|
||||||
|
) {
|
||||||
|
throw new Exception("Invalid request payload", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [];
|
||||||
|
$response = AutomationManager::create($obj['name'],json_encode($obj['days']), json_encode($obj['tasks']), json_encode($obj['conditions']));
|
||||||
|
|
||||||
|
$this->response(['value'=>'OK']);
|
||||||
|
}
|
||||||
|
}
|
@@ -12,11 +12,15 @@ class CronApi extends ApiController
|
|||||||
$backupWorker = new DatabaseBackup();
|
$backupWorker = new DatabaseBackup();
|
||||||
$backupWorker->purge(5);
|
$backupWorker->purge(5);
|
||||||
|
|
||||||
|
//Old Records Cleanup
|
||||||
|
foreach (SubDeviceManager::getAllSubDevices() as $key => $value) {
|
||||||
|
RecordManager::setHistory($value['subdevice_id']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->response(['Value' => 'OK']);
|
$this->response(['Value' => 'OK']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch()
|
public function fetch(){
|
||||||
{
|
|
||||||
//Run Plugins
|
//Run Plugins
|
||||||
$result = [];
|
$result = [];
|
||||||
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/';
|
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/';
|
||||||
@@ -55,4 +59,9 @@ class CronApi extends ApiController
|
|||||||
//Print Result
|
//Print Result
|
||||||
$this->response($result);
|
$this->response($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function automations(){
|
||||||
|
AutomationManager:executeAll();
|
||||||
|
$this->response(['Value' => 'OK']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,9 @@ class DevicesApi extends ApiController{
|
|||||||
$response = [];
|
$response = [];
|
||||||
|
|
||||||
// TODO: process the request
|
// TODO: process the request
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDevicesByRoom($roomId){
|
public function getDevicesByRoom($roomId){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class EndpointsApi extends ApiController{
|
class EndpointsApi extends ApiController
|
||||||
public function default(){
|
{
|
||||||
|
public function default()
|
||||||
|
{
|
||||||
// $this->requireAuth();
|
// $this->requireAuth();
|
||||||
$obj = $this->input;
|
$obj = $this->input;
|
||||||
|
|
||||||
@@ -8,7 +10,7 @@ class EndpointsApi extends ApiController{
|
|||||||
$command = "null";
|
$command = "null";
|
||||||
|
|
||||||
//Log
|
//Log
|
||||||
$logManager = new LogManager('../logs/api/'. date("Y-m-d").'.log');
|
$logManager = new LogManager('../logs/api/' . date("Y-m-d") . '.log');
|
||||||
$logManager->setLevel(LOGLEVEL);
|
$logManager->setLevel(LOGLEVEL);
|
||||||
|
|
||||||
//Token Checks
|
//Token Checks
|
||||||
@@ -62,27 +64,25 @@ class EndpointsApi extends ApiController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$device = DeviceManager::getDeviceByToken($obj['token']);
|
$device = DeviceManager::getDeviceByToken($obj['token']);
|
||||||
|
DeviceManager::setHeartbeat($device['device_id']);
|
||||||
|
|
||||||
//Diagnostic
|
//Diagnostic
|
||||||
if (isset($obj['settings'])){
|
if (isset($obj['settings'])) {
|
||||||
$data = ['mac' => $obj['settings']["network"]["mac"], 'ip_address' => $obj['settings']["network"]["ip"]];
|
$data = ['mac' => $obj['settings']["network"]["mac"], 'ip_address' => $obj['settings']["network"]["ip"]];
|
||||||
if (array_key_exists("firmware_hash", $obj['settings'])) {
|
if (array_key_exists("firmware_hash", $obj['settings'])) {
|
||||||
$data['firmware_hash'] = $obj['settings']["firmware_hash"];
|
$data['firmware_hash'] = $obj['settings']["firmware_hash"];
|
||||||
}
|
}
|
||||||
DeviceManager::editByToken($obj['token'], $data);
|
DeviceManager::editByToken($obj['token'], $data);
|
||||||
$this->response([
|
|
||||||
'state' => 'succes',
|
|
||||||
'command' => $command,
|
|
||||||
], 200);
|
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log Data Save
|
//Log Data Save
|
||||||
if (isset($obj['logs'])){
|
if (isset($obj['logs'])) {
|
||||||
foreach ($obj['logs'] as $log) {
|
foreach ($obj['logs'] as $log) {
|
||||||
$deviceLogManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log');
|
$deviceLogManager = new LogManager('../logs/devices/' . date("Y-m-d") . '.log');
|
||||||
$deviceLogManager->setLevel(LOGLEVEL);
|
$deviceLogManager->setLevel(LOGLEVEL);
|
||||||
$deviceLogManager->write("[Device Log Msg] Device_ID " . $device['device_id'] . "->" . $log, LogRecordTypes::ERROR);
|
if ($log != 'HTTP_UPDATE_FAILD code-102 messageFile Not Found (404)') {
|
||||||
|
$deviceLogManager->write("[Device Log Msg] Device_ID " . $device['device_id'] . "->" . $log, LogRecordTypes::ERROR);
|
||||||
|
}
|
||||||
unset($deviceLogManager);
|
unset($deviceLogManager);
|
||||||
}
|
}
|
||||||
$this->response([
|
$this->response([
|
||||||
@@ -93,13 +93,12 @@ class EndpointsApi extends ApiController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Issuing command
|
// Issuing command
|
||||||
if ($command == "null"){
|
if ($command == "null") {
|
||||||
$deviceCommand = $device["command"];
|
$deviceCommand = $device["command"];
|
||||||
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null")
|
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null") {
|
||||||
{
|
|
||||||
$command = $deviceCommand;
|
$command = $deviceCommand;
|
||||||
$data = [
|
$data = [
|
||||||
'command'=>'null'
|
'command' => 'null'
|
||||||
];
|
];
|
||||||
DeviceManager::editByToken($obj['token'], $data);
|
DeviceManager::editByToken($obj['token'], $data);
|
||||||
$logManager->write("[API] Device_ID " . $device['device_id'] . " executing command " . $command, LogRecordTypes::INFO);
|
$logManager->write("[API] Device_ID " . $device['device_id'] . " executing command " . $command, LogRecordTypes::INFO);
|
||||||
@@ -115,8 +114,9 @@ class EndpointsApi extends ApiController{
|
|||||||
if (!SubDeviceManager::getSubDeviceByMaster($device['device_id'], $key)) {
|
if (!SubDeviceManager::getSubDeviceByMaster($device['device_id'], $key)) {
|
||||||
SubDeviceManager::create($device['device_id'], $key, UNITS[$key]);
|
SubDeviceManager::create($device['device_id'], $key, UNITS[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$subDeviceLastReordValue[$key] = $value['value'];
|
$subDeviceLastReordValue[$key] = $value['value'];
|
||||||
RecordManager::create($device['device_id'], $key, round($value['value'],3));
|
RecordManager::create($device['device_id'], $key, round($value['value'], 3), 'device');
|
||||||
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
|
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
|
||||||
|
|
||||||
//notification
|
//notification
|
||||||
@@ -128,20 +128,20 @@ class EndpointsApi extends ApiController{
|
|||||||
case 'door':
|
case 'door':
|
||||||
$notificationData = [
|
$notificationData = [
|
||||||
'title' => 'Info',
|
'title' => 'Info',
|
||||||
'body' => 'Someone just open up '.$device['name'],
|
'body' => 'Someone just open up ' . $device['name'],
|
||||||
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
|
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
|
||||||
];
|
];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'water':
|
case 'water':
|
||||||
$notificationData = [
|
$notificationData = [
|
||||||
'title' => 'Alert',
|
'title' => 'Alert',
|
||||||
'body' => 'Wather leak detected by '.$device['name'],
|
'body' => 'Wather leak detected by ' . $device['name'],
|
||||||
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
|
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (DEBUGMOD) $notificationData['body'] .= ' value='.$value['value'];
|
if (DEBUGMOD) $notificationData['body'] .= ' value=' . $value['value'];
|
||||||
if ($notificationData != []) {
|
if ($notificationData != []) {
|
||||||
$subscribers = $notificationMng::getSubscription();
|
$subscribers = $notificationMng::getSubscription();
|
||||||
foreach ($subscribers as $key => $subscriber) {
|
foreach ($subscribers as $key => $subscriber) {
|
||||||
@@ -170,11 +170,12 @@ class EndpointsApi extends ApiController{
|
|||||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||||
$subDeviceId = $subDeviceData['subdevice_id'];
|
$subDeviceId = $subDeviceData['subdevice_id'];
|
||||||
$subDeviceLastReord = RecordManager::getLastRecord($subDeviceId);
|
$subDeviceLastReord = RecordManager::getLastRecord($subDeviceId);
|
||||||
$subDeviceLastReordValue[$subDeviceData['type']] = $subDeviceLastReord['value'];
|
if (!empty($subDeviceLastReord)) {
|
||||||
|
$subDeviceLastReordValue[$subDeviceData['type']] = $subDeviceLastReord['value'];
|
||||||
if ($subDeviceLastReord['execuded'] == 0){
|
if ($subDeviceLastReord['execuded'] == 0) {
|
||||||
$logManager->write("[API] subDevice_ID ".$subDeviceId . " executed comand with value " . json_encode($subDeviceLastReordValue) ." executed " . $subDeviceLastReord['execuded'], LogRecordTypes::INFO);
|
$logManager->write("[API] subDevice_ID " . $subDeviceId . " executed comand with value " . json_encode($subDeviceLastReordValue) . " executed " . $subDeviceLastReord['execuded'], LogRecordTypes::INFO);
|
||||||
RecordManager::setExecuted($subDeviceLastReord['record_id']);
|
RecordManager::setExecuted($subDeviceLastReord['record_id']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,4 +194,77 @@ class EndpointsApi extends ApiController{
|
|||||||
//unset($logManager); //TODO: Opravit
|
//unset($logManager); //TODO: Opravit
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function requireAuth()
|
||||||
|
{
|
||||||
|
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||||
|
// TODO: call appropriate class/method
|
||||||
|
$deviceManager = new DeviceManager();
|
||||||
|
list($type, $hash) = explode(' ', $_SERVER['HTTP_AUTHORIZATION']);
|
||||||
|
$this->authenticated = $deviceManager->approved($hash);
|
||||||
|
return $hash;
|
||||||
|
if (!$this->authenticated) {
|
||||||
|
throw new Exception("Authorization required", 401);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception("Authorization required", 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function default_v2()
|
||||||
|
{
|
||||||
|
$token = $this->requireAuth();
|
||||||
|
$obj = $this->input;
|
||||||
|
$response = [];
|
||||||
|
|
||||||
|
$device = DeviceManager::getDeviceByToken($token);
|
||||||
|
DeviceManager::setHeartbeat($device['device_id']);
|
||||||
|
|
||||||
|
// Issue command
|
||||||
|
$deviceCommand = $device["command"];
|
||||||
|
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null") {
|
||||||
|
$response['command'] = $deviceCommand;
|
||||||
|
DeviceManager::editByToken($obj['token'], ['command' => 'null']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$subDevicesData = SubDeviceManager::getAllSubDevices($device['device_id']);
|
||||||
|
if (count($subDevicesData) > 0) {
|
||||||
|
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||||
|
$subDeviceId = $subDeviceData['subdevice_id'];
|
||||||
|
$subDeviceLastReord = RecordManager::getLastRecord($subDeviceId);
|
||||||
|
if (!empty($subDeviceLastReord)) {
|
||||||
|
$response['values'][$subDeviceData['type']] = $subDeviceLastReord['value'];
|
||||||
|
if ($subDeviceLastReord['execuded'] == 0) {
|
||||||
|
RecordManager::setExecuted($subDeviceLastReord['record_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cofiguration_v2()
|
||||||
|
{
|
||||||
|
$token = $this->requireAuth();
|
||||||
|
$response = [];
|
||||||
|
|
||||||
|
$device = DeviceManager::getDeviceByToken($token);
|
||||||
|
DeviceManager::setHeartbeat($device['device_id']);
|
||||||
|
|
||||||
|
if (!empty($device["name"]) && isset($device["name"])) $response["nettwork"]['hostname'] = $this->nameToHostname($device["name"]);
|
||||||
|
if (!empty($device["ip_address"]) && isset($device["ip_address"])) $response["nettwork"]['ip'] = $device["ip_address"];
|
||||||
|
if (!empty($device["gateway"]) && isset($device["gateway"])) $response["nettwork"]['gateway'] = $device["gateway"];
|
||||||
|
if (!empty($device["dns"]) && isset($device["dns"])) $response["nettwork"]['dns'] = $device["dns"];
|
||||||
|
if (!empty($device["sleep_time"]) && isset($device["sleep_time"])) $response["sleep"] = $device["sleep_time"];
|
||||||
|
|
||||||
|
$this->response($response, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function nameToHostname(string $name = null)
|
||||||
|
{
|
||||||
|
$hostname = "";
|
||||||
|
$hostname = strtolower($name);
|
||||||
|
return str_replace(' ', '_', $hostname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,7 @@
|
|||||||
class RoomsApi extends ApiController
|
class RoomsApi extends ApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function
|
public function default()
|
||||||
default()
|
|
||||||
{
|
{
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
$response = [];
|
$response = [];
|
||||||
@@ -19,38 +18,57 @@ class RoomsApi extends ApiController
|
|||||||
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
||||||
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
||||||
foreach ($subDevice as $key => $value) {
|
foreach ($subDevice as $key => $value) {
|
||||||
|
//Type Handling
|
||||||
$type = null;
|
$type = null;
|
||||||
if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
|
if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
|
||||||
$type = $subDevicesData[$subDeviceKey][$key]['type'];
|
$type = $subDevicesData[$subDeviceKey][$key]['type'];
|
||||||
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
|
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
|
||||||
$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'];
|
$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'];
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Connection Error Creation
|
||||||
|
$connectionError = true;
|
||||||
|
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['heartbeat']);
|
||||||
|
$interval = $LastRecordTime->diff(new DateTime());
|
||||||
|
|
||||||
|
|
||||||
|
$lastSeen = $interval->days * 24 * 60;
|
||||||
|
$lastSeen += $interval->h * 60;
|
||||||
|
$lastSeen += $interval->i;
|
||||||
|
|
||||||
|
|
||||||
|
//$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i'));
|
||||||
|
|
||||||
|
if ($lastSeen < ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 ? 15 : $subDevicesData[$subDeviceKey][$key]['sleep_time'])) {
|
||||||
|
$connectionError = false;
|
||||||
|
}
|
||||||
|
$subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError;
|
||||||
|
|
||||||
|
//Record Translation
|
||||||
$cammelCaseClass = "";
|
$cammelCaseClass = "";
|
||||||
foreach (explode('-', $type) as $word) {
|
foreach (explode('-', $type) as $word) {
|
||||||
$cammelCaseClass .= ucfirst($word);
|
$cammelCaseClass .= ucfirst($word);
|
||||||
}
|
}
|
||||||
if (!class_exists($cammelCaseClass)) {
|
if (class_exists($cammelCaseClass)) {
|
||||||
continue;
|
$deviceClass = new $cammelCaseClass;
|
||||||
|
if (method_exists($deviceClass, 'translate')) {
|
||||||
|
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$deviceClass = new $cammelCaseClass;
|
|
||||||
if (!method_exists($deviceClass, 'translate')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($roomsData as $roomKey => $roomData) {
|
foreach ($roomsData as $roomKey => $roomData) {
|
||||||
if ($roomData['device_count'] == 0) continue;
|
if ($roomData['device_count'] == 0) continue;
|
||||||
|
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : [];
|
||||||
|
if (count($subDevicesSorted) == 0) continue;
|
||||||
$response[] = [
|
$response[] = [
|
||||||
'room_id' => $roomData['room_id'],
|
'room_id' => $roomData['room_id'],
|
||||||
'name' => $roomData['name'],
|
'name' => $roomData['name'],
|
||||||
'widgets' => isset($subDevicesData[$roomData['room_id']]) ? $subDevicesData[$roomData['room_id']] : [],
|
'widgets' => $subDevicesSorted,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,16 +12,24 @@ class ServerApi extends ApiController {
|
|||||||
return $meminfo;
|
return $meminfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getProcessorUsage(){
|
||||||
|
$loads=sys_getloadavg();
|
||||||
|
$core_nums=trim(shell_exec("grep -P '^physical id' /proc/cpuinfo|wc -l"));
|
||||||
|
$load = round($loads[0]/($core_nums + 1)*100, 2);
|
||||||
|
return $load;
|
||||||
|
}
|
||||||
|
|
||||||
public function default(){
|
public function default(){
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
$response = [
|
$response = [
|
||||||
"cpu_load" => sys_getloadavg()[0],
|
"cpu_load" => $this->getProcessorUsage(),
|
||||||
"uptime" => shell_exec('uptime -p'),
|
"uptime" => shell_exec('uptime -p'),
|
||||||
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
||||||
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
||||||
"diskFree" => disk_free_space("/"),
|
"diskFree" => disk_free_space("/"),
|
||||||
"diskTotal" => disk_total_space("/"),
|
"diskTotal" => disk_total_space("/"),
|
||||||
"serverTime" => date('m. d. Y H:i:s - e'),
|
"serverTime" => date('m. d. Y H:i:s'),
|
||||||
|
"serverTimeZone" => date('e'),
|
||||||
];
|
];
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
@@ -34,4 +34,14 @@ class UsersApi extends ApiController{
|
|||||||
}
|
}
|
||||||
$this->response(['value'=>'OK']);
|
$this->response(['value'=>'OK']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function subscribe(){
|
||||||
|
//$this->requireAuth();
|
||||||
|
$bearer = $_SERVER['HTTP_AUTHORIZATION'];
|
||||||
|
$authManager = new AuthManager();
|
||||||
|
$userId = $authManager->getUserId($bearer);
|
||||||
|
|
||||||
|
NotificationManager::addSubscriber($userId, $this->input['pushtoken']);
|
||||||
|
$this->response(['value'=>'OK']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ class WidgetApi extends ApiController
|
|||||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||||
if ($subDeviceData['type'] == 'on/off') {
|
if ($subDeviceData['type'] == 'on/off') {
|
||||||
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
|
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
|
||||||
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue);
|
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue, "vue-app");
|
||||||
$response = !$lastValue;
|
$response = !$lastValue;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Bad Request", 403);
|
throw new Exception("Bad Request", 403);
|
||||||
@@ -32,38 +32,37 @@ class WidgetApi extends ApiController
|
|||||||
$this->response(['value' => $response]);
|
$this->response(['value' => $response]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail($subDeviceId)
|
public function detail($subDeviceId, $period = "day")
|
||||||
{
|
{
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
$response = null;
|
|
||||||
$connectionError = true;
|
|
||||||
|
|
||||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
$groupBy = [
|
||||||
$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
|
"year" => "month",
|
||||||
|
"month" => "day",
|
||||||
|
"day" => "hour",
|
||||||
|
"hout" => "minute",
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = null;
|
||||||
|
$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
|
||||||
|
|
||||||
|
|
||||||
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
||||||
$events = RecordManager::getAllRecordForGraph($subDeviceId);
|
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
||||||
if ( count($events) == 0){
|
if ( count($events) == 0){
|
||||||
throw new Exception("No Records", 404);
|
throw new Exception("No Records", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Striping executed value from dataset if pasiv device such as Senzor ETC
|
||||||
|
if ($subDeviceData['type'] != "on/off") {
|
||||||
|
foreach ($events as $key => $event) {
|
||||||
|
unset($events[$key]['execuded']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$LastRecordTime = new DateTime(reset($events)['time']);
|
$LastRecordTime = new DateTime(reset($events)['time']);
|
||||||
$niceTime = Utilities::ago($LastRecordTime);
|
$niceTime = Utilities::ago($LastRecordTime);
|
||||||
|
|
||||||
$interval = $LastRecordTime->diff(new DateTime());
|
|
||||||
$hours = $interval->format('%h');
|
|
||||||
$minutes = $interval->format('%i');
|
|
||||||
$lastSeen = ($hours * 60 + $minutes);
|
|
||||||
|
|
||||||
if (
|
|
||||||
$lastSeen < $deviceData['sleep_time'] ||
|
|
||||||
$subDeviceData['type'] == "on/off" ||
|
|
||||||
$subDeviceData['type'] == "door" ||
|
|
||||||
$subDeviceData['type'] == "wather"
|
|
||||||
) {
|
|
||||||
$connectionError = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$labels = [];
|
$labels = [];
|
||||||
$values = [];
|
$values = [];
|
||||||
foreach ($events as $key => $event) {
|
foreach ($events as $key => $event) {
|
||||||
@@ -80,6 +79,9 @@ class WidgetApi extends ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response = [
|
$response = [
|
||||||
|
'room_id' => $subDeviceData['room_id'],
|
||||||
|
'device_id' => $subDeviceData['device_id'],
|
||||||
|
'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
|
||||||
'records' => $events,
|
'records' => $events,
|
||||||
'graph' => [
|
'graph' => [
|
||||||
'type' => $this->getDeviceConfig($subDeviceData['type'])['graph'],
|
'type' => $this->getDeviceConfig($subDeviceData['type'])['graph'],
|
||||||
@@ -109,13 +111,12 @@ class WidgetApi extends ApiController
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'comError' => $connectionError,
|
|
||||||
'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
//TODO: Make Cleaner
|
//TODO: Make Cleaner
|
||||||
if (isset(RANGES[$subDeviceData['type']])){
|
if (isset(RANGES[$subDeviceData['type']])){
|
||||||
$response['graph']['options']['options']['scales']['yAxes'] = [[
|
$response['graph']['options']['scales']['yAxes'] = [[
|
||||||
'ticks' => [
|
'ticks' => [
|
||||||
'min' => RANGES[$subDeviceData['type']]['min'],
|
'min' => RANGES[$subDeviceData['type']]['min'],
|
||||||
'max' => RANGES[$subDeviceData['type']]['max'],
|
'max' => RANGES[$subDeviceData['type']]['max'],
|
||||||
@@ -123,7 +124,7 @@ class WidgetApi extends ApiController
|
|||||||
]
|
]
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,4 +134,30 @@ class WidgetApi extends ApiController
|
|||||||
}
|
}
|
||||||
return RANGES[''];
|
return RANGES[''];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function edit($subDeviceId)
|
||||||
|
{
|
||||||
|
$this->requireAuth();
|
||||||
|
$allow = ["icon", "name"];
|
||||||
|
|
||||||
|
$response = null;
|
||||||
|
$obj = $this->input;
|
||||||
|
|
||||||
|
foreach ($obj as $key => $value) {
|
||||||
|
if (!in_array($key, $allow)){
|
||||||
|
unset($obj[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $subDeviceId;
|
||||||
|
echo SubDeviceManager::edit($subDeviceId, $obj);
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"value" => "OK"
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->response($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
if (!empty ($_POST)){
|
if (!empty ($_POST)){
|
||||||
$deviceManager = new DeviceManager ();
|
$deviceManager = new DeviceManager ();
|
||||||
|
$subDeviceManager = new SubDeviceManager ();
|
||||||
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
|
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
|
||||||
$file = $_FILES['deviceFirmware'];
|
$file = $_FILES['deviceFirmware'];
|
||||||
$deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac'];
|
$deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac'];
|
||||||
@@ -27,6 +28,12 @@ if (!empty ($_POST)){
|
|||||||
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
|
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
|
||||||
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
|
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
|
||||||
}
|
}
|
||||||
header('Location: ./device');
|
if (!empty ($_POST['deviceApproved']) && !empty ($_POST['deviceId'])) {
|
||||||
|
$deviceManager->edit ($_POST['deviceId'], array ('approved' => $_POST['deviceApproved']));
|
||||||
|
}
|
||||||
|
if (isset ($_POST['deviceHistory']) && !empty ($_POST['deviceId'])) {
|
||||||
|
$subDeviceManager->editSubDevicesByDevice($_POST['deviceId'], array ('history' => $_POST['deviceHistory']));
|
||||||
|
}
|
||||||
|
header('Location: ' . BASEURL . str_replace(BASEDIR, "", $_SERVER['REQUEST_URI']));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@@ -14,19 +14,33 @@ if (
|
|||||||
$state = $_POST["state"];
|
$state = $_POST["state"];
|
||||||
$clientId = $_POST["clientId"];
|
$clientId = $_POST["clientId"];
|
||||||
$ota = $userManager->haveOtaEnabled($userName);
|
$ota = $userManager->haveOtaEnabled($userName);
|
||||||
|
|
||||||
if ($ota == "") {
|
if ($ota == "") {
|
||||||
$token = (new AuthManager)->getToken($userName,$userPassword, $clientId);
|
$token = (new AuthManager)->getToken($userName,$userPassword, $clientId);
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
throw new Exception("Auth failed", 401);
|
throw new Exception("Auth failed", 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$get = [
|
$get=[];
|
||||||
"access_token"=>$token,
|
if ($_POST['response_type'] = 'code') {
|
||||||
"token_type"=>"Bearer",
|
$get = [
|
||||||
"state"=>$state,
|
"state"=>$state,
|
||||||
];
|
"code"=>$token,
|
||||||
|
"state"=>$state,
|
||||||
header('Location: ' . $_POST["redirectUrl"] . '#' . http_build_query($get));
|
];
|
||||||
|
} else {
|
||||||
|
$get = [
|
||||||
|
"access_token"=>$token,
|
||||||
|
"token_type"=>"Bearer",
|
||||||
|
"state"=>$state,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
//Log
|
||||||
|
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
|
||||||
|
$logManager->setLevel(LOGLEVEL);
|
||||||
|
$logManager->write("[OAUTH] Response " . $_POST["redirectUrl"] . '?' . http_build_query($get), LogRecordTypes::WARNING);
|
||||||
|
header('Location: ' . $_POST["redirectUrl"] . '?' . http_build_query($get));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
if (isset($_POST) && !empty($_POST)){
|
if (isset($_POST) && !empty($_POST)){
|
||||||
$userManager = new UserManager();
|
$userManager = new UserManager();
|
||||||
|
$roomManager = new RoomManager();
|
||||||
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
|
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
|
||||||
$oldPassword = $_POST['oldPassword'];
|
$oldPassword = $_POST['oldPassword'];
|
||||||
$newPassword = $_POST['newPassword1'];
|
$newPassword = $_POST['newPassword1'];
|
||||||
@@ -21,13 +22,28 @@ if (isset($_POST) && !empty($_POST)){
|
|||||||
|
|
||||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||||
if ($checkResult) {
|
if ($checkResult) {
|
||||||
$userManager->setOta($otaCode, $otaSecret);
|
$userManager->setOta($otaCode, $otaSecret);
|
||||||
}
|
}
|
||||||
header('Location: ' . BASEURL . 'setting');
|
header('Location: ' . BASEURL . 'setting');
|
||||||
die();
|
die();
|
||||||
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
|
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
|
||||||
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
|
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
|
||||||
|
header('Location: ' . BASEURL . 'setting');
|
||||||
|
die();
|
||||||
|
} if (isset ($_POST['roomName']) && !empty ($_POST['roomId'])) {
|
||||||
|
$roomManager->edit($_POST['roomId'], array("name" => $_POST['roomName']));
|
||||||
|
header('Location: ' . BASEURL . 'setting');
|
||||||
|
die();
|
||||||
|
} else {
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
if ($key == 'submit') continue;
|
||||||
|
$settingMng = new SettingsManager();
|
||||||
|
if ($settingMng->getByName($key)) {
|
||||||
|
$settingMng->update($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
header('Location: ' . BASEURL . 'setting');
|
header('Location: ' . BASEURL . 'setting');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@@ -112,7 +112,7 @@ class Form {
|
|||||||
* [render function whitch dysplay generated form]
|
* [render function whitch dysplay generated form]
|
||||||
*/
|
*/
|
||||||
function render(){
|
function render(){
|
||||||
self::addInput(InputTypes::SUBMIT, 'formSubmit', '', 'Submit', 'Submit');
|
self::addInput(InputTypes::SUBMIT, 'formSubmit', '', '', 'Submit');
|
||||||
$form = '<form '.$this->formName.$this->formId.$this->method.$this->action.'">';
|
$form = '<form '.$this->formName.$this->formId.$this->method.$this->action.'">';
|
||||||
$form .= $this->formContent;
|
$form .= $this->formContent;
|
||||||
$form .= '</form>';
|
$form .= '</form>';
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
class GoogleHome {
|
https://console.cloud.google.com/logs/query;cursorTimestamp=2021-04-11T07:51:16.567357750Z?project=simple-home-79188
|
||||||
static function sync($requestId){
|
class GoogleHome
|
||||||
|
{
|
||||||
|
static function sync($requestId)
|
||||||
|
{
|
||||||
$devices = [];
|
$devices = [];
|
||||||
$roomsData = RoomManager::getAllRooms();
|
$roomsData = RoomManager::getAllRooms();
|
||||||
foreach ($roomsData as $roomKey => $roomData) {
|
foreach ($roomsData as $roomKey => $roomData) {
|
||||||
@@ -26,6 +29,10 @@ class GoogleHome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($traids < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$tempDevice = [
|
$tempDevice = [
|
||||||
'id' => (string) $deviceData['device_id'],
|
'id' => (string) $deviceData['device_id'],
|
||||||
'type' => $actionType,
|
'type' => $actionType,
|
||||||
@@ -36,7 +43,10 @@ class GoogleHome {
|
|||||||
],
|
],
|
||||||
|
|
||||||
'willReportState' => false,
|
'willReportState' => false,
|
||||||
'roomHint' => $roomData['name']
|
'roomHint' => $roomData['name'],
|
||||||
|
"otherDeviceIds" => [
|
||||||
|
["deviceId" => "SH#".(string) $deviceData['device_id']]
|
||||||
|
]
|
||||||
];
|
];
|
||||||
if ($tempDevice['attributes'] == null) unset($tempDevice['attributes']);
|
if ($tempDevice['attributes'] == null) unset($tempDevice['attributes']);
|
||||||
|
|
||||||
@@ -49,428 +59,444 @@ class GoogleHome {
|
|||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
'payload' => [
|
'payload' => [
|
||||||
'agentUserId'=>'651351531531',
|
'agentUserId' => '651351531531',
|
||||||
'devices' => array_values( $devices ),
|
'devices' => array_values($devices),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function query($requestId, $payload){
|
static function query($requestId, $payload)
|
||||||
|
{
|
||||||
$devices = [];
|
$devices = [];
|
||||||
$num = 0;
|
$num = 0;
|
||||||
foreach ($payload['devices'] as $deviceId) {
|
foreach ($payload['devices'] as $deviceId) {
|
||||||
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id']);
|
|
||||||
|
|
||||||
$tempDevice[$deviceId['id']] = [
|
$tempDevice[$deviceId['id']] = [
|
||||||
'online' => false,
|
'online' => false,
|
||||||
'status' => 'OFFLINE',
|
'status' => 'OFFLINE',
|
||||||
];
|
];
|
||||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
|
||||||
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
if ($subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id'])) {
|
||||||
if ($lastRecord['execuded'] == 1){
|
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
||||||
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
if ($lastRecord != false && $lastRecord['execuded'] == 1) {
|
||||||
} else {
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
$executed = 0;
|
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
||||||
$waiting = 0;
|
} else {
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
$executed = 0;
|
||||||
if ($value['execuded'] == 1){
|
$waiting = 0;
|
||||||
$executed++;
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
} else {
|
if ($value['execuded'] == 1) {
|
||||||
$waiting++;
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($waiting < $executed) {
|
||||||
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
switch ($subDeviceData['type']) {
|
||||||
|
case 'temp_cont':
|
||||||
|
$tempDevice[$deviceId['id']]['thermostatMode'] = 'off';
|
||||||
|
if ($lastRecord['value'] != 0) {
|
||||||
|
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
|
||||||
|
}
|
||||||
|
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = $lastRecord['value'];
|
||||||
|
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = $lastRecord['value'];
|
||||||
|
break;
|
||||||
|
case 'vol_cont':
|
||||||
|
$tempDevice[$deviceId['id']]['currentVolume'] = $lastRecord['value'];
|
||||||
|
break;
|
||||||
|
case 'media_apps':
|
||||||
|
$tempDevice[$deviceId['id']]['currentApplication'] = "kodi";
|
||||||
|
break;
|
||||||
|
case 'media_input':
|
||||||
|
$tempDevice[$deviceId['id']]['currentInput'] = "pc";
|
||||||
|
break;
|
||||||
|
case 'media_status':
|
||||||
|
$tempDevice[$deviceId['id']]['activityState'] = "ACTIVE";
|
||||||
|
$tempDevice[$deviceId['id']]['playbackState'] = "PLAYING";
|
||||||
|
break;
|
||||||
|
case 'on/off':
|
||||||
|
$tempDevice[$deviceId['id']]['on'] = ($lastRecord['value'] == 1 ? true : false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $lastRecord = RecordManager::getLastRecord($deviceId['id']);
|
||||||
|
// //var_dump($lastRecord);
|
||||||
|
// if ($lastRecord['execuded'] == 1) {
|
||||||
|
// $online = true;
|
||||||
|
// $status = 'SUCCESS';
|
||||||
|
// } else {
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1) {
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($subDeviceData['type']) {
|
if ($waiting < $executed) {
|
||||||
case 'temp_cont':
|
$status = "PENDING";
|
||||||
$tempDevice[$deviceId['id']]['thermostatMode'] = 'off';
|
$online = true;
|
||||||
if ($lastRecord['value'] != 0) {
|
}
|
||||||
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
|
// }
|
||||||
}
|
$devices = $tempDevice;
|
||||||
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = $lastRecord['value'];
|
if (count($devices)> 1){
|
||||||
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = $lastRecord['value'];
|
$devices[] = $tempDevice;
|
||||||
break;
|
}
|
||||||
case 'vol_cont':
|
}
|
||||||
$tempDevice[$deviceId['id']]['currentVolume'] = $lastRecord['value'];
|
$response = [
|
||||||
break;
|
'requestId' => $requestId,
|
||||||
case 'media_apps':
|
'payload' => [
|
||||||
$tempDevice[$deviceId['id']]['currentApplication'] = "kodi";
|
'devices' => $devices,
|
||||||
break;
|
],
|
||||||
case 'media_input':
|
];
|
||||||
$tempDevice[$deviceId['id']]['currentInput'] = "pc";
|
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
||||||
break;
|
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
case 'media_status':
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
$tempDevice[$deviceId['id']]['activityState'] = "ACTIVE";
|
echo json_encode($response);
|
||||||
$tempDevice[$deviceId['id']]['playbackState'] = "PLAYING";
|
}
|
||||||
break;
|
|
||||||
case 'on/off':
|
static function execute($requestId, $payload)
|
||||||
$tempDevice[$deviceId['id']]['on'] = ($lastRecord['value'] == 1 ? true : false);
|
{
|
||||||
break;
|
$commands = [];
|
||||||
|
foreach ($payload['commands'] as $key => $command) {
|
||||||
|
foreach ($command['devices'] as $key2 => $device) {
|
||||||
|
$executionCommand = $command['execution'][0];
|
||||||
|
if (isset($command['execution'][$key])) {
|
||||||
|
$executionCommand = $command['execution'][$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
||||||
|
if ($subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)) {
|
||||||
|
$subDeviceId = $subDeviceId['subdevice_id'];
|
||||||
|
switch ($executionCommand['command']) {
|
||||||
|
case 'action.devices.commands.OnOff':
|
||||||
|
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.ThermostatTemperatureSetpoint':
|
||||||
|
$commands[] = self::executeTermostatValue($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.ThermostatSetMode':
|
||||||
|
$commands[] = self::executeTermostatMode($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.setVolume':
|
||||||
|
$commands[] = self::executeVolume($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.appSelect':
|
||||||
|
$commands[] = self::executeApp($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.SetInput':
|
||||||
|
$commands[] = self::executeInput($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaNext':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaPrevious':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaPause':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaResume':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaStop':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$response = [
|
||||||
|
'requestId' => $requestId,
|
||||||
|
'payload' => [
|
||||||
|
'commands' => $commands,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
||||||
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
|
$apiLogManager->write("[API][EXECUTE][$requestId]\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeSwitch($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
|
$value = 0;
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
if ($executionCommand['params']['on']) $value = 1;
|
||||||
|
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1) {
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lastRecord['execuded'] == 1){
|
if ($waiting < $executed) {
|
||||||
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
$status = 'SUCCESS';
|
}
|
||||||
} else {
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'on' => $executionCommand['params']['on'],
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeTermostatValue($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
|
$value = 0;
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) {
|
||||||
|
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $lastValue) {
|
||||||
|
if ($lastValue['execuded'] == 1) {
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($waiting < $executed) {
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;;
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'thermostatMode' => 'heat',
|
||||||
|
'thermostatTemperatureSetpoint' => $value,
|
||||||
|
'thermostatTemperatureAmbient' => $value,
|
||||||
|
'online' => $online,
|
||||||
|
//ambient z dalšího zenzoru v roomu
|
||||||
|
],
|
||||||
|
];
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeTermostatMode($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
|
$mode = "off";
|
||||||
|
$value = 0;
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['thermostatMode']) && $executionCommand['params']['thermostatMode'] != 'off') {
|
||||||
|
$mode = $executionCommand['params']['thermostatMode'];
|
||||||
|
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1) {
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($waiting < $executed) {
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'thermostatMode' => $mode,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeVolume($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
|
//echo $executionCommand['params']['volumeLevel'];
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
$currentVolume = RecordManager::getLastRecord($subDeviceId)['value'];
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['volumeLevel'])) {
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['volumeLevel']);
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
|
$currentVolume = $executionCommand['params']['volumeLevel'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$devices = $tempDevice;
|
|
||||||
/*if (count($devices)> 1){
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
$devices[] = $tempDevice;
|
$commandTemp = [
|
||||||
}*/
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'currentVolume' => $currentVolume,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
$response = [
|
|
||||||
'requestId' => $requestId,
|
|
||||||
'payload' => [
|
|
||||||
'devices' => $devices,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
|
||||||
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
|
||||||
echo json_encode($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function execute($requestId, $payload){
|
static function executeApp($subDeviceId, $executionCommand)
|
||||||
$commands = [];
|
{
|
||||||
foreach ($payload['commands'] as $key => $command) {
|
//echo $executionCommand['params']['newApplication'];
|
||||||
foreach ($command['devices'] as $key2 => $device) {
|
$status = 'OFFLINE';
|
||||||
$executionCommand = $command['execution'][0];
|
$online = false;
|
||||||
if (isset($command['execution'][$key])) {
|
|
||||||
$executionCommand = $command['execution'][$key];
|
$currentApplication = RecordManager::getLastRecord($subDeviceId)['value'];
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['newApplication'])) {
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newApplication']);
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1) {
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if ($waiting < $executed) {
|
||||||
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
$status = "PENDING";
|
||||||
$subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)['subdevice_id'];
|
$online = true;
|
||||||
switch ($executionCommand['command']) {
|
$currentApplication = $executionCommand['params']['newApplication'];
|
||||||
case 'action.devices.commands.OnOff':
|
|
||||||
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.ThermostatTemperatureSetpoint':
|
|
||||||
$commands[] = self::executeTermostatValue($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.ThermostatSetMode':
|
|
||||||
$commands[] = self::executeTermostatMode($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.setVolume':
|
|
||||||
$commands[] = self::executeVolume($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.appSelect':
|
|
||||||
$commands[] = self::executeApp($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.SetInput':
|
|
||||||
$commands[] = self::executeInput($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaNext':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaPrevious':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaPause':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaResume':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaStop':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'currentApplication' => $currentApplication,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
$response = [
|
|
||||||
'requestId' => $requestId,
|
|
||||||
'payload' => [
|
|
||||||
'commands' => $commands,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
static function executeInput($subDeviceId, $executionCommand)
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
{
|
||||||
$apiLogManager->write("[API][EXECUTE][$requestId]\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
//echo $executionCommand['params']['newInput'];
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
echo json_encode($response);
|
$currentInput = RecordManager::getLastRecord($subDeviceId)['value'];
|
||||||
}
|
|
||||||
|
|
||||||
static function executeSwitch($subDeviceId, $executionCommand){
|
if (isset($executionCommand['params']['newInput'])) {
|
||||||
$value = 0;
|
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newInput']);
|
||||||
$status = 'OFFLINE';
|
$executed = 0;
|
||||||
$online = false;
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($executionCommand['params']['on']) $value = 1;
|
if ($value['execuded'] == 1) {
|
||||||
|
$executed++;
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
} else {
|
||||||
|
$waiting++;
|
||||||
$executed = 0;
|
}
|
||||||
$waiting = 0;
|
}
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
if ($waiting < $executed) {
|
||||||
if ($value['execuded'] == 1){
|
$status = "PENDING";
|
||||||
$executed++;
|
$online = true;
|
||||||
} else {
|
$currentInput = $executionCommand['params']['newInput'];
|
||||||
$waiting++;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'currentInput' => $currentInput,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waiting < $executed){
|
static function executeMediaCont($subDeviceId, $executionCommand)
|
||||||
$status = "PENDING";
|
{
|
||||||
|
$status = 'SUCCESS';
|
||||||
$online = true;
|
$online = true;
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
$commandTemp = [
|
$commandTemp = [
|
||||||
'ids' => [(string) $deviceId],
|
'ids' => [(string) $deviceId],
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'states' => [
|
'states' => [
|
||||||
'on' => $executionCommand['params']['on'],
|
'online' => $online,
|
||||||
'online' => $online,
|
],
|
||||||
],
|
];
|
||||||
];
|
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeTermostatValue($subDeviceId, $executionCommand){
|
|
||||||
$value = 0;
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) {
|
|
||||||
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
|
||||||
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $lastValue) {
|
|
||||||
if ($lastValue['execuded'] == 1){
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($waiting < $executed){
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;;
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'thermostatMode' => 'heat',
|
|
||||||
'thermostatTemperatureSetpoint' => $value,
|
|
||||||
'thermostatTemperatureAmbient' => $value,
|
|
||||||
'online' => $online,
|
|
||||||
//ambient z dalšího zenzoru v roomu
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeTermostatMode($subDeviceId, $executionCommand){
|
|
||||||
$mode = "off";
|
|
||||||
$value = 0;
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['thermostatMode']) && $executionCommand['params']['thermostatMode'] != 'off') {
|
|
||||||
$mode = $executionCommand['params']['thermostatMode'];
|
|
||||||
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
|
||||||
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1){
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($waiting < $executed){
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'thermostatMode' => $mode,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeVolume($subDeviceId, $executionCommand){
|
|
||||||
//echo $executionCommand['params']['volumeLevel'];
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
$currentVolume = RecordManager::getLastRecord($subDeviceId)['value'];
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['volumeLevel'])) {
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['volumeLevel']);
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1){
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($waiting < $executed){
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
$currentVolume = $executionCommand['params']['volumeLevel'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'currentVolume' => $currentVolume,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeApp($subDeviceId, $executionCommand){
|
|
||||||
//echo $executionCommand['params']['newApplication'];
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
$currentApplication = RecordManager::getLastRecord($subDeviceId)['value'];
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['newApplication'])) {
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newApplication']);
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1){
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($waiting < $executed){
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
$currentApplication = $executionCommand['params']['newApplication'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'currentApplication' => $currentApplication,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeInput($subDeviceId, $executionCommand){
|
|
||||||
//echo $executionCommand['params']['newInput'];
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
$currentInput = RecordManager::getLastRecord($subDeviceId)['value'];
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['newInput'])) {
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newInput']);
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1){
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($waiting < $executed){
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
$currentInput = $executionCommand['params']['newInput'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'currentInput' => $currentInput,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeMediaCont($subDeviceId, $executionCommand){
|
|
||||||
$status = 'SUCCESS';
|
|
||||||
$online = true;
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -178,4 +178,40 @@ class Utilities
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort Array by keys
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param [type] $key
|
||||||
|
* @param string $operator ('asc'/'desc')
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
static function sortArrayByKey($data = [], $key, $operator = "asc")
|
||||||
|
{
|
||||||
|
if ($operator == "asc") {
|
||||||
|
uasort($data, function ($a, $b) use ($key) {
|
||||||
|
$SortA = $a[$key];
|
||||||
|
$SortB = $b[$key];
|
||||||
|
if ($key == "room_id") {
|
||||||
|
$SortA = RoomManager::getRoomName($SortA);
|
||||||
|
$SortB = RoomManager::getRoomName($SortB);
|
||||||
|
}
|
||||||
|
if ($SortA == $SortB) return 0;
|
||||||
|
return ($SortA < $SortB) ? -1 : 1;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
uasort($data, function ($a, $b) use ($key) {
|
||||||
|
$SortA = $a[$key];
|
||||||
|
$SortB = $b[$key];
|
||||||
|
if ($key == "room_id") {
|
||||||
|
$SortA = RoomManager::getRoomName($SortA);
|
||||||
|
$SortB = RoomManager::getRoomName($SortB);
|
||||||
|
}
|
||||||
|
if ($SortA == $SortB) return 0;
|
||||||
|
return ($SortA > $SortB) ? -1 : 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -61,4 +61,10 @@ class AuthManager {
|
|||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUserId($bearer){
|
||||||
|
$token = explode(' ', $bearer)[1];
|
||||||
|
$userid = Db::loadOne('SELECT user_id FROM tokens WHERE token = ? AND expire >= CURRENT_TIMESTAMP AND blocked = 0;', array($token))['user_id'];
|
||||||
|
return $userid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,23 +8,23 @@ class AutomationManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function deactive($automationId) {
|
public static function deactive($automationId) {
|
||||||
$automation = Db::loadOne ("SELECT * FROM automation WHERE automation_id=?" , array ($automationId));
|
$automation = self::getById($automationId,["enabled"]);
|
||||||
$flipedValue = ($automation['active'] == 1 ? 0 : 1);
|
$flipedValue = ($automation['enabled'] == 1 ? 0 : 1);
|
||||||
return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
return Db::command ('UPDATE automation SET enabled = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function restart($automationId) {
|
public static function restart($automationId) {
|
||||||
return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId));
|
return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($name, $onDays, $doCode, $ifCode, $automationId = "") {
|
public static function create ($name, $onDays, $doCode, $ifCode, $userId = 1, $automationId = "") {
|
||||||
$userId = UserManager::getUserData('user_id');
|
$userId = UserManager::getUserData('user_id', $userId);
|
||||||
$scene = array (
|
$scene = array (
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'owner_id' => $userId,
|
'owner_id' => $userId,
|
||||||
'on_days' => $onDays,
|
'on_days' => $onDays,
|
||||||
'if_something' => $ifCode,
|
'conditions' => $ifCode,
|
||||||
'do_something' => $doCode,
|
'tasks' => $doCode,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
if ($automationId == "") {
|
if ($automationId == "") {
|
||||||
@@ -34,19 +34,24 @@ class AutomationManager{
|
|||||||
}
|
}
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
|
return false;
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAll(){
|
public static function getAll($collums = ['*']){
|
||||||
return Db::loadAll ("SELECT * FROM automation");
|
return Db::loadAll ("SELECT ". implode("," , $collums)." FROM automation");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($automationId, $collums = ['*']){
|
||||||
|
return Db::loadOne("SELECT ". implode("," , $collums)." FROM automation WHERE automation_id = ?", [$automationId]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function executeAll(){
|
public static function executeAll(){
|
||||||
global $logManager;
|
global $logManager;
|
||||||
|
|
||||||
$automations = Db::loadAll ("SELECT * FROM automation");
|
/*$automations = Db::loadAll ("SELECT * FROM automation");
|
||||||
$dayNameNow = strtolower (date('D', time()));
|
$dayNameNow = strtolower (date('D', time()));
|
||||||
|
|
||||||
foreach ($automations as $automation) {
|
foreach ($automations as $automation) {
|
||||||
@@ -170,6 +175,6 @@ class AutomationManager{
|
|||||||
Db::edit('automation', array('locked' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
|
Db::edit('automation', array('locked' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,14 @@ class DeviceManager{
|
|||||||
public static $devices;
|
public static $devices;
|
||||||
|
|
||||||
static function getAllDevices () {
|
static function getAllDevices () {
|
||||||
return Db::loadAll ("SELECT devices.* FROM devices
|
return Db::loadAll ("SELECT * FROM devices
|
||||||
WHERE approved != ?", Array(2));
|
WHERE approved != ?", Array(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function setHeartbeat($deviceId){
|
||||||
|
self::edit($deviceId, ['heartbeat' => date("Y-m-d H:i:s", time())]);
|
||||||
|
}
|
||||||
|
|
||||||
static function getAllDevicesInRoom ($roomId = "") {
|
static function getAllDevicesInRoom ($roomId = "") {
|
||||||
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
|
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
class LogManager
|
class LogManager
|
||||||
{
|
{
|
||||||
private $logFile;
|
private $logFile;
|
||||||
|
private $filePath = null;
|
||||||
private $logLevel = 1;
|
private $logLevel = 1;
|
||||||
|
|
||||||
public function __construct($fileName = "")
|
public function __construct($fileName = "")
|
||||||
@@ -15,12 +16,13 @@ class LogManager
|
|||||||
if ($fileName == ""){
|
if ($fileName == ""){
|
||||||
$fileName = '../logs/'. date("Y-m-d").'.log';
|
$fileName = '../logs/'. date("Y-m-d").'.log';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_dir("../logs/"))
|
if(!is_dir("../logs/"))
|
||||||
{
|
{
|
||||||
mkdir("../logs/");
|
mkdir("../logs/");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
|
$this->filePath = $fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLevel($type = LogRecordTypess::WARNING){
|
public function setLevel($type = LogRecordTypess::WARNING){
|
||||||
@@ -28,6 +30,10 @@ class LogManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function write($value, $type = LogRecordTypess::ERROR){
|
public function write($value, $type = LogRecordTypess::ERROR){
|
||||||
|
if ($this->logFile == null) {
|
||||||
|
$this->logFile = fopen($this->filePath, "a") or die("Unable to open file!");
|
||||||
|
}
|
||||||
|
|
||||||
if ($type['level'] <= $this->logLevel) {
|
if ($type['level'] <= $this->logLevel) {
|
||||||
$record = "[".date("H:m:s")."][".$type['identifier']."]" . $value . "\n";
|
$record = "[".date("H:m:s")."][".$type['identifier']."]" . $value . "\n";
|
||||||
fwrite($this->logFile, $record);
|
fwrite($this->logFile, $record);
|
||||||
|
29
app/models/managers/Pluginmanager.php
Normal file
29
app/models/managers/Pluginmanager.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
class PluginManager
|
||||||
|
{
|
||||||
|
public function load(){
|
||||||
|
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . '/backup/';
|
||||||
|
|
||||||
|
$pluginsFiles = scandir ($dir);
|
||||||
|
foreach ($pluginsFiles as $key => $pluginFile) {
|
||||||
|
$className = str_replace(".zip", "", $pluginsFiles);
|
||||||
|
if(class_exists($className)){
|
||||||
|
(new $className)->make();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sleepTime = DeviceManager::getDeviceById($deviceId)['sleep_time'];
|
||||||
|
|
||||||
|
$LastRecordTime = new DateTime(RecordManager::getLastRecord($subDeviceId, 1)['time']);
|
||||||
|
$interval = $LastRecordTime->diff(new DateTime());
|
||||||
|
$hours = $interval->format('%h');
|
||||||
|
$minutes = $interval->format('%i');
|
||||||
|
$lastSeen = ($hours * 60 + $minutes);
|
||||||
|
|
||||||
|
if ($lastSeen > $sleepTime || $sleepTime == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -2,16 +2,21 @@
|
|||||||
class RecordManager{
|
class RecordManager{
|
||||||
public static $records;
|
public static $records;
|
||||||
|
|
||||||
public static function createWithSubId ($subDeviceId, $value) {
|
public static function createWithSubId ($subDeviceId, $value, $origin = false) {
|
||||||
try {
|
try {
|
||||||
$record = [
|
$record = [
|
||||||
'execuded' => 1,
|
'execuded' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
||||||
$record = array (
|
$record = array (
|
||||||
'subdevice_id' => $subDeviceId,
|
'subdevice_id' => $subDeviceId,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($origin != false)
|
||||||
|
$record['Origin'] = $origin;
|
||||||
|
|
||||||
return Db::add ('records', $record);
|
return Db::add ('records', $record);
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
@@ -19,17 +24,18 @@ class RecordManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($deviceId, $type, $value) {
|
public static function create ($deviceId, $type, $value, $origin = false) {
|
||||||
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
||||||
if ($subDeviceId == '') {
|
if ($subDeviceId == '') {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
||||||
if (self::getLastRecord($subDeviceId, 1)['value'] === $value){
|
$lastRecord = self::getLastRecord($subDeviceId, 1);
|
||||||
|
|
||||||
|
if (isset($lastRecord['value']) && $lastRecord['value'] == $value){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$record = [
|
$record = [
|
||||||
@@ -41,6 +47,10 @@ class RecordManager{
|
|||||||
'subdevice_id' => $subDeviceId,
|
'subdevice_id' => $subDeviceId,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($origin != false)
|
||||||
|
$record['Origin'] = $origin;
|
||||||
|
|
||||||
return Db::add ('records', $record);
|
return Db::add ('records', $record);
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
@@ -86,7 +96,7 @@ class RecordManager{
|
|||||||
$dateTime = $dateTime->modify($periodLocal);
|
$dateTime = $dateTime->modify($periodLocal);
|
||||||
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
||||||
$groupBy = strtoupper($groupBy).'(time)';
|
$groupBy = strtoupper($groupBy).'(time)';
|
||||||
$sql = 'SELECT value, time FROM records
|
$sql = 'SELECT value, time, execuded, origin FROM records
|
||||||
WHERE
|
WHERE
|
||||||
subdevice_id = ?
|
subdevice_id = ?
|
||||||
AND
|
AND
|
||||||
@@ -101,7 +111,7 @@ class RecordManager{
|
|||||||
|
|
||||||
public static function clean ($day) {
|
public static function clean ($day) {
|
||||||
if (isset($day)) {
|
if (isset($day)) {
|
||||||
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL -? DAY);', array($day));
|
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL ? DAY);', array($day));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,5 +119,10 @@ class RecordManager{
|
|||||||
public static function cleanSubdeviceRecords ($subDeviceId) {
|
public static function cleanSubdeviceRecords ($subDeviceId) {
|
||||||
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
|
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function setHistory($subDeviceId){
|
||||||
|
$history = SubDeviceManager::getSubDevice($subDeviceId)['history'];
|
||||||
|
if ($history > 0) self::clean(-abs($history));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@@ -19,6 +19,12 @@ class RoomManager{
|
|||||||
return $allRoom;
|
return $allRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getRoomName ($room_id) {
|
||||||
|
//TODO: ignore Widgets withoud data
|
||||||
|
$allRoom = Db::loadAlone ("SELECT name FROM rooms WHERE room_id=?", array ($room_id));
|
||||||
|
return $allRoom;
|
||||||
|
}
|
||||||
|
|
||||||
public static function create ($name) {
|
public static function create ($name) {
|
||||||
$room = array (
|
$room = array (
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
@@ -31,6 +37,15 @@ class RoomManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function edit ($roomId, $values = []) {
|
||||||
|
try {
|
||||||
|
Db::edit ('rooms', $values, 'WHERE room_id = ?', array($roomId));
|
||||||
|
} catch(PDOException $error) {
|
||||||
|
echo $error->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function delete ($roomId) {
|
public static function delete ($roomId) {
|
||||||
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
|
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
|
||||||
}
|
}
|
||||||
|
@@ -4,29 +4,43 @@ class SettingsManager{
|
|||||||
return Db::loadAll ("SELECT * FROM settings");
|
return Db::loadAll ("SELECT * FROM settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getByName($settingName) {
|
static function getByName($settingName, $type = '') {
|
||||||
|
if ($type != '') return Db::loadOne("SELECT * FROM settings WHERE name = ? AND type = ?", array($settingName, $type));
|
||||||
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
|
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($name, $value) {
|
static function getSettingGroup($type) {
|
||||||
$setting = array (
|
return Db::loadAll("SELECT * FROM settings WHERE type=?", array($type));
|
||||||
'name' => $name,
|
}
|
||||||
'value' => $value,
|
|
||||||
);
|
public static function create ($name, $value, $type = '') {
|
||||||
try {
|
if (!self::getByName($name)){
|
||||||
Db::add ('settings', $setting);
|
$setting = array (
|
||||||
} catch(PDOException $error) {
|
'name' => $name,
|
||||||
echo $error->getMessage();
|
'value' => $value,
|
||||||
die();
|
'type' => $type,
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
Db::add ('settings', $setting);
|
||||||
|
} catch(PDOException $error) {
|
||||||
|
echo $error->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update ($name, $value) {
|
public static function update ($name, $value, $type = '') {
|
||||||
try {
|
if (!self::getByName($name)){
|
||||||
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name));
|
self::create($name, $value, $type);
|
||||||
} catch(PDOException $error) {
|
} else {
|
||||||
echo $error->getMessage();
|
try {
|
||||||
die();
|
Db::edit ('settings', [
|
||||||
|
'value' => $value
|
||||||
|
], 'WHERE name = ?', array($name));
|
||||||
|
} catch(PDOException $error) {
|
||||||
|
echo $error->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ class SubDeviceManager
|
|||||||
|
|
||||||
public static function getAllSubDevices($deviceId = null)
|
public static function getAllSubDevices($deviceId = null)
|
||||||
{
|
{
|
||||||
if ($deviceId == null){
|
if ($deviceId == null) {
|
||||||
return Db::loadAll("SELECT * FROM subdevices");
|
return Db::loadAll("SELECT * FROM subdevices");
|
||||||
}
|
}
|
||||||
return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId));
|
return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId));
|
||||||
@@ -50,7 +50,7 @@ class SubDeviceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check if dubdevice exist
|
//check if dubdevice exist
|
||||||
|
//Add History to be set in Creation
|
||||||
public static function create($deviceId, $type, $unit)
|
public static function create($deviceId, $type, $unit)
|
||||||
{
|
{
|
||||||
$record = array(
|
$record = array(
|
||||||
@@ -66,21 +66,37 @@ class SubDeviceManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function edit($subDeviceId, $values)
|
||||||
|
{
|
||||||
|
$record = [];
|
||||||
|
foreach ($values as $key => $value) {
|
||||||
|
$record[$key] = $value;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Db::edit('subdevices', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
echo $error->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function remove($subDeviceId)
|
public static function remove($subDeviceId)
|
||||||
{
|
{
|
||||||
RecordManager::cleanSubdeviceRecords($subDeviceId);
|
RecordManager::cleanSubdeviceRecords($subDeviceId);
|
||||||
return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId));
|
return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSubdevicesByRoomIds($roomIds = NULL) {
|
public static function getSubdevicesByRoomIds($roomIds = NULL)
|
||||||
if(empty($roomIds)) return NULL;
|
{
|
||||||
|
if (empty($roomIds)) return NULL;
|
||||||
|
|
||||||
//TODO: @Patrik Check line 89
|
//TODO: @Patrik Check line 89
|
||||||
$rows = Db::loadAll("
|
$rows = Db::loadAll("
|
||||||
SELECT d.room_id, sd.subdevice_id, sd.device_id, d.name, sd.type, sd.unit, r.value FROM subdevices sd
|
SELECT d.room_id, d.sleep_time, d.heartbeat, sd.subdevice_id, sd.device_id, COALESCE(sd.icon, d.icon) AS icon, COALESCE(sd.name, d.name) AS name, sd.type, sd.unit, r.value, r.time FROM subdevices sd
|
||||||
JOIN devices d ON sd.device_id = d.device_id
|
JOIN devices d ON sd.device_id = d.device_id
|
||||||
JOIN records r ON r.subdevice_id = sd.subdevice_id
|
JOIN records r ON r.subdevice_id = sd.subdevice_id
|
||||||
WHERE d.room_id IN (".str_repeat("?,", count($roomIds)-1)."?)
|
WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?)
|
||||||
|
/*AND value != '999'*/
|
||||||
AND r.record_id IN (
|
AND r.record_id IN (
|
||||||
SELECT MAX(record_id)
|
SELECT MAX(record_id)
|
||||||
FROM records
|
FROM records
|
||||||
@@ -91,10 +107,21 @@ class SubDeviceManager
|
|||||||
", $roomIds);
|
", $roomIds);
|
||||||
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
foreach($rows as $row){
|
foreach ($rows as $row) {
|
||||||
$ret[$row['room_id']][] = $row;
|
$ret[$row['room_id']][] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getSubdeviceDetailById($subDeviceId){
|
||||||
|
if (empty($subDeviceId)) return NULL;
|
||||||
|
|
||||||
|
$rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd
|
||||||
|
JOIN devices d ON sd.device_id = d.device_id
|
||||||
|
WHERE sd.subdevice_id = ? ", [$subDeviceId]);
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
class GoogleHomeDeviceTypes {
|
class GoogleHomeDeviceTypes
|
||||||
|
{
|
||||||
/*const AirConditioningUnit = 'action.devices.types.AC_UNIT';
|
/*const AirConditioningUnit = 'action.devices.types.AC_UNIT';
|
||||||
const AirFreshener = 'action.devices.types.AIRFRESHENER';
|
const AirFreshener = 'action.devices.types.AIRFRESHENER';
|
||||||
const AirPurifier = 'action.devices.types.AIRPURIFIER';
|
const AirPurifier = 'action.devices.types.AIRPURIFIER';
|
||||||
@@ -75,7 +76,7 @@ class GoogleHomeDeviceTypes {
|
|||||||
'control-light' => 'action.devices.types.LIGHT',
|
'control-light' => 'action.devices.types.LIGHT',
|
||||||
'control-socket' => 'action.devices.types.OUTLET',
|
'control-socket' => 'action.devices.types.OUTLET',
|
||||||
'control-temp' => 'action.devices.types.THERMOSTAT',
|
'control-temp' => 'action.devices.types.THERMOSTAT',
|
||||||
'control-media' => 'action.devices.types.REMOTECONTROL',
|
'control-media' => 'action.devices.types.REMOTECONTROL',
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $traidWordBook = [
|
private static $traidWordBook = [
|
||||||
@@ -107,7 +108,7 @@ class GoogleHomeDeviceTypes {
|
|||||||
'commandOnlyOnOff' => false,
|
'commandOnlyOnOff' => false,
|
||||||
],
|
],
|
||||||
'temp_cont' => [
|
'temp_cont' => [
|
||||||
'availableThermostatModes' => 'off,heat',
|
'availableThermostatModes' => ['off', 'heat'],
|
||||||
'thermostatTemperatureUnit' => 'C',
|
'thermostatTemperatureUnit' => 'C',
|
||||||
],
|
],
|
||||||
'vol_cont' => [
|
'vol_cont' => [
|
||||||
@@ -117,7 +118,7 @@ class GoogleHomeDeviceTypes {
|
|||||||
'levelStepSize' => 2,
|
'levelStepSize' => 2,
|
||||||
'commandOnlyVolume' => false,
|
'commandOnlyVolume' => false,
|
||||||
],
|
],
|
||||||
'media_cont'=> [
|
'media_cont' => [
|
||||||
'transportControlSupportedCommands' => [
|
'transportControlSupportedCommands' => [
|
||||||
"NEXT",
|
"NEXT",
|
||||||
"PREVIOUS",
|
"PREVIOUS",
|
||||||
@@ -127,7 +128,7 @@ class GoogleHomeDeviceTypes {
|
|||||||
"CAPTION_CONTROL"
|
"CAPTION_CONTROL"
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'media_status'=> [
|
'media_status' => [
|
||||||
'supportActivityState' => true,
|
'supportActivityState' => true,
|
||||||
'supportPlaybackState' => true,
|
'supportPlaybackState' => true,
|
||||||
],
|
],
|
||||||
@@ -159,27 +160,32 @@ class GoogleHomeDeviceTypes {
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
static function getAction($deviceType){
|
static function getAction($deviceType)
|
||||||
|
{
|
||||||
if (!isset(self::$actionWordBook[$deviceType])) return;
|
if (!isset(self::$actionWordBook[$deviceType])) return;
|
||||||
return self::$actionWordBook[$deviceType];
|
return self::$actionWordBook[$deviceType];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getTraid($subDeviceType){
|
static function getTraid($subDeviceType)
|
||||||
|
{
|
||||||
if (!isset(self::$traidWordBook[$subDeviceType])) return;
|
if (!isset(self::$traidWordBook[$subDeviceType])) return;
|
||||||
return self::$traidWordBook[$subDeviceType];
|
return self::$traidWordBook[$subDeviceType];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getType($subDeviceCommand){
|
static function getType($subDeviceCommand)
|
||||||
|
{
|
||||||
if (!isset(self::$commandWordBook[$subDeviceCommand])) return;
|
if (!isset(self::$commandWordBook[$subDeviceCommand])) return;
|
||||||
return self::$commandWordBook[$subDeviceCommand];
|
return self::$commandWordBook[$subDeviceCommand];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getAttribute($subDeviceType){
|
static function getAttribute($subDeviceType)
|
||||||
|
{
|
||||||
if (!isset(self::$attributeWordBook[$subDeviceType])) return;
|
if (!isset(self::$attributeWordBook[$subDeviceType])) return;
|
||||||
return self::$attributeWordBook[$subDeviceType];
|
return self::$attributeWordBook[$subDeviceType];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getQueryJson($deviceType, $type){
|
static function getQueryJson($deviceType, $type)
|
||||||
|
{
|
||||||
return self::$wordBook[$type];
|
return self::$wordBook[$type];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
|
|
||||||
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
|
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi'], 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
11
app/plugins/!ExamplePlugin.php
Normal file
11
app/plugins/!ExamplePlugin.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
class ExamplePlugin extends VirtualDeviceManager
|
||||||
|
{
|
||||||
|
function make(){
|
||||||
|
//Getting Data
|
||||||
|
}
|
||||||
|
|
||||||
|
function translate($value){
|
||||||
|
//Translation of numeric values
|
||||||
|
}
|
||||||
|
}
|
39
app/plugins/!_Covid.php
Normal file
39
app/plugins/!_Covid.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
class Covid extends VirtualDeviceManager
|
||||||
|
{
|
||||||
|
private $country_sluig = "czech-republic";
|
||||||
|
private $api_uri = 'https://api.covid19api.com/live/country/%s/status/confirmed'; // Your redirect uri
|
||||||
|
private $virtual_device_name = "Covid";
|
||||||
|
|
||||||
|
function make()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (DeviceManager::registeret($this->virtual_device_name)) {
|
||||||
|
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
||||||
|
$dataItems = ['Confirmed', 'Deaths', 'Recovered', 'Active'];
|
||||||
|
foreach ($dataItems as $dataItem) {
|
||||||
|
if (!$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($dataItem))) {
|
||||||
|
SubDeviceManager::create($deviceId, strtolower($dataItem), $dataItem);
|
||||||
|
sleep(1);
|
||||||
|
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($dataItem));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->fetchEnabled($deviceId, $subDevice['subdevice_id'])) die();
|
||||||
|
|
||||||
|
$finalUrl = sprintf($this->api_uri, $this->country_sluig);
|
||||||
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
||||||
|
|
||||||
|
foreach ($dataItems as $dataItem) {
|
||||||
|
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$dataItem]);
|
||||||
|
}
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -17,12 +17,12 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
||||||
|
|
||||||
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
|
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi'], 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
@@ -31,7 +31,7 @@ class CovidV2 extends VirtualDeviceManager
|
|||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true)['data'];
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true)['data'];
|
||||||
|
|
||||||
foreach ($dataItems as $dataItem) {
|
foreach ($dataItems as $dataItem) {
|
||||||
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]]);
|
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]], 'plugin');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, strtolower($this->virtual_device_name));
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, strtolower($this->virtual_device_name));
|
||||||
|
85
app/plugins/DameJidlo.php
Normal file
85
app/plugins/DameJidlo.php
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
class DameJidlo extends VirtualDeviceManager
|
||||||
|
{
|
||||||
|
private $virtual_device_name = "Dáme Jídlo";
|
||||||
|
private $device_type = "virtual-device";
|
||||||
|
private $subdevice_type = "dame-jidlo";
|
||||||
|
|
||||||
|
public function deliveryTime($token)
|
||||||
|
{
|
||||||
|
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://cz.fd-api.com/api/v5/tracking/active-orders?time_variation=Variation2');
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||||
|
|
||||||
|
$headers = array();
|
||||||
|
$headers[] = 'Authority: cz.fd-api.com';
|
||||||
|
$headers[] = 'Sec-Ch-Ua: \"Chromium\";v=\"88\", \"Google Chrome\";v=\"88\", \";Not A Brand\";v=\"99\"';
|
||||||
|
$headers[] = 'Accept: application/json, text/plain, */*';
|
||||||
|
$headers[] = 'Authorization: Bearer ' . $token;
|
||||||
|
$headers[] = 'X-Pd-Language-Id: 2';
|
||||||
|
$headers[] = 'Sec-Ch-Ua-Mobile: ?0';
|
||||||
|
$headers[] = 'X-Fp-Api-Key: volo';
|
||||||
|
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36';
|
||||||
|
$headers[] = 'Origin: https://www.damejidlo.cz';
|
||||||
|
$headers[] = 'Sec-Fetch-Site: cross-site';
|
||||||
|
$headers[] = 'Sec-Fetch-Mode: cors';
|
||||||
|
$headers[] = 'Sec-Fetch-Dest: empty';
|
||||||
|
$headers[] = 'Referer: https://www.damejidlo.cz/';
|
||||||
|
$headers[] = 'Accept-Language: en-US,en;q=0.9,cs-CZ;q=0.8,cs;q=0.7';
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
echo 'Error:' . curl_error($ch);
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
var_dump(isset(json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta']) ? json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta'] : 0);
|
||||||
|
return (isset(json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta']) ? json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta'] : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function make()
|
||||||
|
{
|
||||||
|
//Register the settings
|
||||||
|
$settingMng = new SettingsManager();
|
||||||
|
if (!($settingField = $settingMng->getByName("damejidlo_token","damejidlo"))) {
|
||||||
|
$settingMng->create("damejidlo_token", "", "damejidlo");
|
||||||
|
} else {
|
||||||
|
$bearer = $settingField['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
RecordManager::create($deviceId, $this->subdevice_type, $this->deliveryTime($bearer), 'plugin');
|
||||||
|
} 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 == 0) {
|
||||||
|
return " Delivered";
|
||||||
|
} else if ($value <= 1) {
|
||||||
|
return "less " . $value;
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
@@ -3,12 +3,25 @@ class DatabaseBackup
|
|||||||
{
|
{
|
||||||
public function make()
|
public function make()
|
||||||
{
|
{
|
||||||
|
//Register the settings
|
||||||
|
$time = '00:00';
|
||||||
|
$settingMng = new SettingsManager();
|
||||||
|
if (!($settingField = $settingMng->getByName("backup_time","db_backup"))) {
|
||||||
|
$settingMng->create("backup_time", $time, "db_backup");
|
||||||
|
} else {
|
||||||
|
$time = $settingField['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//Time to Backup ?
|
||||||
|
if (date("H:i",time()) != $time)
|
||||||
|
return 'pending';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$filenames = [];
|
$filenames = [];
|
||||||
$backupWorker = new DatabaseBackup;
|
$backupWorker = new DatabaseBackup;
|
||||||
$filenames[] = $backupWorker->scheme(); //Backup Database scheme
|
$filenames[] = $backupWorker->scheme(); //Backup Database scheme
|
||||||
$filenames[] = $backupWorker->data(); //Backup Database Data
|
$filenames[] = $backupWorker->data(); //Backup Database Data
|
||||||
$filenames[] = $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'; //Backup Configuration File
|
//$filenames[] = $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'; //Backup Configuration File
|
||||||
$backupWorker->compress($_SERVER['DOCUMENT_ROOT'] . BASEDIR . '/backup/' . date("Y-m-d", time()) . '.zip', $filenames);
|
$backupWorker->compress($_SERVER['DOCUMENT_ROOT'] . BASEDIR . '/backup/' . date("Y-m-d", time()) . '.zip', $filenames);
|
||||||
return 'sucessful';
|
return 'sucessful';
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -16,17 +29,19 @@ class DatabaseBackup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function scheme()
|
private function data()
|
||||||
{
|
{
|
||||||
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql';
|
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql';
|
||||||
|
if (file_exists($backupfile)) return null;
|
||||||
$command = "mysqldump --skip-comments --no-create-info -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
$command = "mysqldump --skip-comments --no-create-info -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
||||||
$this->executeCommand($command);
|
$this->executeCommand($command);
|
||||||
return $backupfile;
|
return $backupfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function data()
|
private function scheme()
|
||||||
{
|
{
|
||||||
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql';
|
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql';
|
||||||
|
if (file_exists($backupfile)) return null;
|
||||||
$command = "mysqldump --skip-comments --no-data -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
$command = "mysqldump --skip-comments --no-data -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
||||||
$this->executeCommand($command);
|
$this->executeCommand($command);
|
||||||
return $backupfile;
|
return $backupfile;
|
||||||
|
42
app/plugins/N7day.php
Normal file
42
app/plugins/N7day.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
class N7Day extends VirtualDeviceManager
|
||||||
|
{
|
||||||
|
private $virtual_device_name = "N7 Day";
|
||||||
|
private $device_type = "day-count";
|
||||||
|
private $subdevice_type = "day-count";
|
||||||
|
|
||||||
|
|
||||||
|
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, 'days');
|
||||||
|
sleep(1);
|
||||||
|
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
||||||
|
|
||||||
|
//Days Until N7 day
|
||||||
|
$now = time(); // or your date as well
|
||||||
|
if (strtotime(date("Y") . "-11-07") < $now){
|
||||||
|
$your_date = strtotime((date("Y") + 1) . "-11-07");
|
||||||
|
} else {
|
||||||
|
$your_date = strtotime(date("Y") . "-11-07");
|
||||||
|
}
|
||||||
|
$datediff = $now - $your_date;
|
||||||
|
$daysUntilN7Day = round($datediff / (60 * 60 * 24));
|
||||||
|
|
||||||
|
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day, 'plugin');
|
||||||
|
} else {
|
||||||
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, $this->device_type);
|
||||||
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
}
|
||||||
|
return 'sucessful';
|
||||||
|
} catch(Exception $e) {
|
||||||
|
return 'exception: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -23,7 +23,39 @@ class OpenWeatherMap extends VirtualDeviceManager
|
|||||||
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
||||||
|
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $json['weather'][0]['id']);
|
|
||||||
|
//Notification data setup
|
||||||
|
$notificationMng = new NotificationManager;
|
||||||
|
if ($json['weather'][0]['id'] >= 500 && $json['weather'][0]['id'] < 600) {
|
||||||
|
// $notificationData = [
|
||||||
|
// 'title' => 'Weather',
|
||||||
|
// 'body' => 'It Will be rainy outhere, Take Umbrela :)',
|
||||||
|
// 'icon' => 'http://dev.steelants.cz/projekty/simplehome-client/img/icons/favicon-16x16.png',
|
||||||
|
// ];
|
||||||
|
// //Notification for newly added Device
|
||||||
|
// if ($notificationData != []) {
|
||||||
|
// $subscribers = $notificationMng::getSubscription();
|
||||||
|
// foreach ($subscribers as $key => $subscriber) {
|
||||||
|
// $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
} else if ($json['weather'][0]['id'] >= 600 && $json['weather'][0]['id'] < 700) {
|
||||||
|
// $notificationData = [
|
||||||
|
// 'title' => 'Weather',
|
||||||
|
// 'body' => 'It is white out there :)',
|
||||||
|
// 'icon' => 'http://dev.steelants.cz/projekty/simplehome-client/img/icons/favicon-16x16.png',
|
||||||
|
// ];
|
||||||
|
// //Notification for newly added Device
|
||||||
|
// if ($notificationData != []) {
|
||||||
|
// $subscribers = $notificationMng::getSubscription();
|
||||||
|
// foreach ($subscribers as $key => $subscriber) {
|
||||||
|
// $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RecordManager::create($deviceId, $this->subdevice_type, $json['weather'][0]['id'], 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
@@ -33,4 +65,8 @@ class OpenWeatherMap extends VirtualDeviceManager
|
|||||||
return 'exception: ' . $e->getMessage();
|
return 'exception: ' . $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enable(){
|
||||||
|
(new SettingsManager)->create('open_weather_api_token', '', 'open_weather');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,7 @@ class UsaElection extends VirtualDeviceManager
|
|||||||
$OnePercent = ($Trump + $Biden + $Unknown) / 100;
|
$OnePercent = ($Trump + $Biden + $Unknown) / 100;
|
||||||
|
|
||||||
foreach ($dataItems as $Category) {
|
foreach ($dataItems as $Category) {
|
||||||
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)));
|
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)), 'plugin');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
|
@@ -53,6 +53,7 @@ class Automation extends Template
|
|||||||
|
|
||||||
$template = new Template('automation');
|
$template = new Template('automation');
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('debugMod', DEBUGMOD);
|
$template->prepare('debugMod', DEBUGMOD);
|
||||||
$template->prepare('title', 'Automation');
|
$template->prepare('title', 'Automation');
|
||||||
$template->prepare('langMng', $langMng);
|
$template->prepare('langMng', $langMng);
|
||||||
|
@@ -3,91 +3,94 @@
|
|||||||
|
|
||||||
class Device extends Template
|
class Device extends Template
|
||||||
{
|
{
|
||||||
function __construct () {
|
function __construct($sortBy = null, $sortType = null)
|
||||||
$userManager = new UserManager ();
|
{
|
||||||
$deviceManager = new DeviceManager ();
|
// //Notification data setup
|
||||||
$subDeviceManager = new SubDeviceManager ();
|
// $notificationMng = new NotificationManager;
|
||||||
$recordManager = new RecordManager ();
|
// $notificationData = [
|
||||||
$roomManager = new RoomManager ();
|
// 'title' => 'Info',
|
||||||
$langMng = new LanguageManager ('en');
|
// 'body' => 'New device Detected Found',
|
||||||
|
// 'icon' => 'http://dev.steelants.cz/projekty/simplehome-client/img/icons/favicon-16x16.png',
|
||||||
|
// ];
|
||||||
|
// //Notification for newly added Device
|
||||||
|
// if ($notificationData != []) {
|
||||||
|
// $subscribers = $notificationMng::getSubscription();
|
||||||
|
// foreach ($subscribers as $key => $subscriber) {
|
||||||
|
// $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if (!$userManager->isLogin()){
|
$userManager = new UserManager();
|
||||||
|
$deviceManager = new DeviceManager();
|
||||||
|
$subDeviceManager = new SubDeviceManager();
|
||||||
|
$recordManager = new RecordManager();
|
||||||
|
$roomManager = new RoomManager();
|
||||||
|
$langMng = new LanguageManager('en');
|
||||||
|
|
||||||
|
if (!$userManager->isLogin()) {
|
||||||
header('Location: ' . BASEURL . 'login');
|
header('Location: ' . BASEURL . 'login');
|
||||||
}
|
}
|
||||||
|
|
||||||
$template = new Template ('device');
|
$template = new Template('device');
|
||||||
$template->prepare ('title', $langMng->get ("m_devices"));
|
$template->prepare('title', $langMng->get("m_devices"));
|
||||||
|
|
||||||
if (!empty ($_GET['sort']) && !empty ($_SESSION['sort']) && $_SESSION['sort'] != $_GET['sort']) {
|
$sortWordBook = [
|
||||||
unset($_SESSION['sort']);
|
"id" => "device_id",
|
||||||
header('Location: device?sort=' . $_GET["sort"] . "&sortType=ASC");
|
"name" => "name",
|
||||||
die();
|
"room" => "room_id",
|
||||||
}
|
"ip" => "ip_address",
|
||||||
|
"mac" => "mac",
|
||||||
|
"token" => "token",
|
||||||
|
"signal" => "signal",
|
||||||
|
"firmware" => "firmware_hash",
|
||||||
|
"icon" => "icon",
|
||||||
|
"history" => "history",
|
||||||
|
];
|
||||||
|
|
||||||
if (isset ($_GET['sortType'])) {
|
$sortIcons = [
|
||||||
switch ($_GET['sortType']) {
|
"ASC" => "",
|
||||||
case "DESC":
|
"DESC" => "",
|
||||||
$sortType = "";
|
];
|
||||||
$sortIcon = "";
|
|
||||||
break;
|
|
||||||
case "ASC":
|
|
||||||
$sortType = "DESC";
|
|
||||||
$sortIcon = "";
|
|
||||||
break;
|
|
||||||
case "":
|
|
||||||
unset($_GET["sort"]);
|
|
||||||
unset($_GET["sortType"]);
|
|
||||||
header('Location: device');
|
|
||||||
die();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$sortType = "ASC";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty ($_GET['sort']) && !empty ($_GET['sortType'])) {
|
$nextSort = [
|
||||||
$template->prepare ('sortIcon', array ($_GET['sort'] => $sortIcon));
|
"ASC" => "DESC",
|
||||||
$actualSort = "devices.device_id";
|
"DESC" => "ASC",
|
||||||
switch ($_GET['sort']) {
|
];
|
||||||
case "name":
|
|
||||||
$actualSort = "devices.name";
|
|
||||||
break;
|
|
||||||
case "room":
|
|
||||||
$actualSort = "rooms.name";
|
|
||||||
break;
|
|
||||||
case "ip":
|
|
||||||
$actualSort = "devices.ip_address";
|
|
||||||
break;
|
|
||||||
case "mac":
|
|
||||||
$actualSort = "devices.mac";
|
|
||||||
break;
|
|
||||||
case "token":
|
|
||||||
$actualSort = "devices.token";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$devices = $deviceManager->getAllDevicesSorted ($actualSort, $_GET['sortType']);
|
|
||||||
} else {
|
|
||||||
$devices = $deviceManager->getAllDevices ();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty ($_GET['sort'])) {
|
$devices = $deviceManager->getAllDevices();
|
||||||
$_SESSION['sort'] = $_GET['sort'];
|
|
||||||
|
if (empty($sortBy) && empty($sortType)) {
|
||||||
|
$sortBy = "id";
|
||||||
|
$sortType = "DESC";
|
||||||
}
|
}
|
||||||
|
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
|
||||||
|
|
||||||
foreach ($devices as $key => $device) {
|
foreach ($devices as $key => $device) {
|
||||||
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType ($device['device_id'], "wifi");
|
//Signal Stenght
|
||||||
if (!empty ($subdevice['subdevice_id'])) {
|
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi");
|
||||||
|
$subdeviceLocal = $subDeviceManager->getSubDeviceByMaster($device['device_id']);
|
||||||
|
if (!empty($subdeviceLocal)) {
|
||||||
|
$devices[$key]['history'] = (!empty($subdeviceLocal['history']) ? $subdeviceLocal['history'] : 0);
|
||||||
|
} else {
|
||||||
|
$devices[$key]['history'] = "null";
|
||||||
|
}
|
||||||
|
$devices[$key]['signal'] = "";
|
||||||
|
if (!empty($subdevice['subdevice_id'])) {
|
||||||
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
|
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
|
||||||
if (!empty ($record)) {
|
if (!empty($record)) {
|
||||||
$devices[$key]['signal'] = $record['value'] . " " . $subdevice['unit'];
|
$devices[$key]['signal'] = $record['value'] . " " . $subdevice['unit'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty ($devices[$key]['signal'])) {
|
|
||||||
$devices[$key]['signal'] = "";
|
//Firmware Status
|
||||||
|
if (empty($devices[$key]['mac'])) {
|
||||||
|
$devices[$key]['firmware_hash'] = "";
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
$localBinary = "../updater/" . str_replace (':', '', $device['mac']) . ".bin";
|
$localBinary = "../updater/" . str_replace(':', '', $device['mac']) . ".bin";
|
||||||
if (file_exists ($localBinary)) {
|
$devices[$key]['firmware_hash'] = "";
|
||||||
$hash = md5_file ($localBinary);
|
if (file_exists($localBinary)) {
|
||||||
|
$hash = md5_file($localBinary);
|
||||||
if ($hash == $device['firmware_hash']) {
|
if ($hash == $device['firmware_hash']) {
|
||||||
$devices[$key]['firmware_hash'] = "true";
|
$devices[$key]['firmware_hash'] = "true";
|
||||||
} else {
|
} else {
|
||||||
@@ -96,43 +99,22 @@ class Device extends Template
|
|||||||
} else {
|
} else {
|
||||||
$devices[$key]['firmware_hash'] = "false";
|
$devices[$key]['firmware_hash'] = "false";
|
||||||
}
|
}
|
||||||
if (empty ($device['mac'])) {
|
|
||||||
$devices[$key]['firmware_hash'] = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "firmware") {
|
$devices = Utilities::sortArrayByKey($devices, $sortWordBook[$sortBy], strtolower($sortType));
|
||||||
if ($_GET['sortType'] == "DESC") {
|
|
||||||
usort($devices, function($a, $b) {
|
|
||||||
return $a['firmware_hash'] <=> $b['firmware_hash'];
|
|
||||||
});
|
|
||||||
} else if ($_GET['sortType'] == "ASC") {
|
|
||||||
usort($devices, function($a, $b) {
|
|
||||||
return $b['firmware_hash'] <=> $a['firmware_hash'];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "signal") {
|
|
||||||
if ($_GET['sortType'] == "DESC") {
|
|
||||||
usort($devices, function($a, $b) {
|
|
||||||
return $a['signal'] <=> $b['signal'];
|
|
||||||
});
|
|
||||||
} else if ($_GET['sortType'] == "ASC") {
|
|
||||||
usort($devices, function($a, $b) {
|
|
||||||
return $b['signal'] <=> $a['signal'];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$rooms = $roomManager->getAllRooms();
|
$rooms = $roomManager->getAllRooms();
|
||||||
|
|
||||||
$template->prepare ('baseDir', BASEDIR);
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare ('debugMod', DEBUGMOD);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
$template->prepare ('logToLiveTime', LOGTIMOUT);
|
|
||||||
$template->prepare ('rooms', $rooms);
|
|
||||||
$template->prepare ('sortType', $sortType);
|
|
||||||
$template->prepare ('devices', $devices);
|
|
||||||
$template->prepare ('langMng', $langMng);
|
|
||||||
|
|
||||||
$template->render ();
|
$template->prepare('debugMod', DEBUGMOD);
|
||||||
|
$template->prepare('logToLiveTime', LOGTIMOUT);
|
||||||
|
$template->prepare('rooms', $rooms);
|
||||||
|
$template->prepare('sortType', $nextSort[$sortType]);
|
||||||
|
$template->prepare('devices', $devices);
|
||||||
|
$template->prepare('langMng', $langMng);
|
||||||
|
|
||||||
|
$template->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ class Log extends Template
|
|||||||
$result = $this->logFinder ('../logs/', $result);
|
$result = $this->logFinder ('../logs/', $result);
|
||||||
|
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('debugMod', DEBUGMOD);
|
$template->prepare('debugMod', DEBUGMOD);
|
||||||
$template->prepare('logToLiveTime', LOGTIMOUT);
|
$template->prepare('logToLiveTime', LOGTIMOUT);
|
||||||
$template->prepare('title', 'Logy');
|
$template->prepare('title', 'Logy');
|
||||||
|
@@ -4,7 +4,7 @@ class Login extends Template
|
|||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
$userManager = new UserManager();
|
$userManager = new UserManager();
|
||||||
|
|
||||||
|
|
||||||
if ($userManager->isLogin()){
|
if ($userManager->isLogin()){
|
||||||
header('Location: ' . BASEURL);
|
header('Location: ' . BASEURL);
|
||||||
@@ -12,6 +12,7 @@ class Login extends Template
|
|||||||
|
|
||||||
$template = new Template('login');
|
$template = new Template('login');
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('title', 'Home');
|
$template->prepare('title', 'Home');
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,27 +1,76 @@
|
|||||||
<?php
|
<?php
|
||||||
class Oauth extends Template
|
//https://developers.google.com/oauthplayground/
|
||||||
|
//https://developer.okta.com/blog/2018/04/10/oauth-authorization-code-grant-type
|
||||||
|
|
||||||
|
class Oauth
|
||||||
{
|
{
|
||||||
function __construct()
|
function default()
|
||||||
{
|
{
|
||||||
$userManager = new UserManager ();
|
//Log
|
||||||
|
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
|
||||||
|
$logManager->setLevel(LOGLEVEL);
|
||||||
|
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
|
||||||
|
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
|
||||||
|
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
|
||||||
|
|
||||||
|
$userManager = new UserManager();
|
||||||
$langMng = new LanguageManager('en');
|
$langMng = new LanguageManager('en');
|
||||||
|
|
||||||
$template = new Template('oauth');
|
$template = new Template('oauth');
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('title', 'Simple Home - Oauth');
|
$template->prepare('title', 'Simple Home - Oauth');
|
||||||
|
|
||||||
if (isset($_GET['redirect_uri'])) {
|
if (isset($_GET['response_type']) && $_GET['response_type'] == 'code') {
|
||||||
$template->prepare('responseType', $_GET['response_type']);
|
$template->prepare('responseType', $_GET['response_type']);
|
||||||
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
||||||
$template->prepare('clientId', $_GET['client_id']);
|
$template->prepare('clientId', $_GET['client_id']);
|
||||||
|
$template->prepare('scope', $_GET['scope']);
|
||||||
$template->prepare('state', $_GET['state']);
|
$template->prepare('state', $_GET['state']);
|
||||||
} else {
|
} else {
|
||||||
$template->prepare('responseType', $_POST['responseType']);
|
if (isset($_GET['redirect_uri'])) {
|
||||||
$template->prepare('redirectUrl', $_POST['redirectUrl']);
|
$template->prepare('responseType', $_GET['response_type']);
|
||||||
$template->prepare('clientId', $_POST['clientId']);
|
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
||||||
$template->prepare('state', $_POST['state']);
|
$template->prepare('clientId', $_GET['client_id']);
|
||||||
|
$template->prepare('state', $_GET['state']);
|
||||||
|
} else {
|
||||||
|
$template->prepare('responseType', $_POST['responseType']);
|
||||||
|
$template->prepare('redirectUrl', $_POST['redirectUrl']);
|
||||||
|
$template->prepare('clientId', $_POST['clientId']);
|
||||||
|
$template->prepare('state', $_POST['state']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$template->render();
|
$template->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function token()
|
||||||
|
{
|
||||||
|
//Log
|
||||||
|
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
|
||||||
|
$logManager->setLevel(LOGLEVEL);
|
||||||
|
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
|
||||||
|
$logManager->write("[OAUTH] POST " . json_encode($_POST), LogRecordTypes::WARNING);
|
||||||
|
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
|
||||||
|
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
|
||||||
|
|
||||||
|
// $template = new Template('oauth');
|
||||||
|
// $template->prepare('baseDir', BASEDIR);
|
||||||
|
// $template->prepare('baseUrl', BASEURL);
|
||||||
|
// $template->prepare('title', 'Simple Home - Oauth');
|
||||||
|
// $template->render();
|
||||||
|
|
||||||
|
$token = $_POST["code"];
|
||||||
|
$get = [
|
||||||
|
"access_token" => $token,
|
||||||
|
"token_type" => "Bearer",
|
||||||
|
"refresh_token" => $token,
|
||||||
|
"scope" => 'user',
|
||||||
|
//"expires_in" => 63113851,
|
||||||
|
];
|
||||||
|
|
||||||
|
$logManager->write("[OAUTH] Response " . json_encode($get), LogRecordTypes::WARNING);
|
||||||
|
echo json_encode($get);
|
||||||
|
die();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,10 +21,11 @@ class Plugins extends Template
|
|||||||
$plugins[$key]['status'] = $status;
|
$plugins[$key]['status'] = $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
sort($plugins);
|
$plugins = Utilities::sortArrayByKey($plugins, 'status', "desc");
|
||||||
|
|
||||||
$template = new Template('plugins');
|
$template = new Template('plugins');
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('debugMod', DEBUGMOD);
|
$template->prepare('debugMod', DEBUGMOD);
|
||||||
$template->prepare('title', 'Plugins');
|
$template->prepare('title', 'Plugins');
|
||||||
$template->prepare('langMng', $langMng);
|
$template->prepare('langMng', $langMng);
|
||||||
|
@@ -22,9 +22,9 @@ class Server extends Template
|
|||||||
$load = round($loads[0]/($core_nums + 1)*100, 2);
|
$load = round($loads[0]/($core_nums + 1)*100, 2);
|
||||||
return $load;
|
return $load;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
$userManager = new UserManager();
|
$userManager = new UserManager();
|
||||||
$langMng = new LanguageManager('en');
|
$langMng = new LanguageManager('en');
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@ class Server extends Template
|
|||||||
$template->prepare('title', 'Server');
|
$template->prepare('title', 'Server');
|
||||||
|
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('debugMod', DEBUGMOD);
|
$template->prepare('debugMod', DEBUGMOD);
|
||||||
$template->prepare('langMng', $langMng);
|
$template->prepare('langMng', $langMng);
|
||||||
|
|
||||||
|
@@ -10,23 +10,12 @@ class Setting extends Template
|
|||||||
header('Location: ' . BASEURL . 'login');
|
header('Location: ' . BASEURL . 'login');
|
||||||
}
|
}
|
||||||
|
|
||||||
$automations = [];
|
|
||||||
$automationsData = AutomationManager::getAll();
|
|
||||||
foreach ($automationsData as $automationKey => $automationData) {
|
|
||||||
$automations[$automationData['automation_id']] = [
|
|
||||||
'name' => '',
|
|
||||||
'onDays' => $automationData['on_days'],
|
|
||||||
'ifSomething' => $automationData['if_something'],
|
|
||||||
'doSomething' => $automationData['do_something'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$template = new Template('setting');
|
$template = new Template('setting');
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
$template->prepare('baseUrl', BASEURL);
|
||||||
$template->prepare('debugMod', DEBUGMOD);
|
$template->prepare('debugMod', DEBUGMOD);
|
||||||
$template->prepare('title', 'Automation');
|
$template->prepare('title', 'Settings');
|
||||||
$template->prepare('langMng', $langMng);
|
$template->prepare('langMng', $langMng);
|
||||||
$template->prepare('automations', $automations);
|
|
||||||
|
|
||||||
$users = $userManager->getUsers();
|
$users = $userManager->getUsers();
|
||||||
foreach ($users as $key => $value) {
|
foreach ($users as $key => $value) {
|
||||||
@@ -55,7 +44,29 @@ class Setting extends Template
|
|||||||
$rooms = RoomManager::getAllRooms();
|
$rooms = RoomManager::getAllRooms();
|
||||||
$template->prepare('rooms', $rooms);
|
$template->prepare('rooms', $rooms);
|
||||||
|
|
||||||
|
$settingsManager = new SettingsManager();
|
||||||
|
$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);
|
||||||
|
if ($status) {
|
||||||
|
$plugins[$key]['name'] = str_replace ("!", "", str_replace (".php", "", $pluginFile));
|
||||||
|
$plugins[$key]['slug'] = strtolower ($plugins[$key]['name']);
|
||||||
|
$result = $settingsManager->getSettingGroup($plugins[$key]['slug']);
|
||||||
|
if (count ($result) > 0) {
|
||||||
|
$plugins[$key]['settings'] = $result;
|
||||||
|
} else {
|
||||||
|
unset($plugins[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugins = Utilities::sortArrayByKey($plugins, 'slug', "desc");
|
||||||
|
|
||||||
|
$template->prepare('pluginsSettings', $plugins);
|
||||||
|
|
||||||
$template->render();
|
$template->render();
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir', $BASEDIR);
|
$partial->prepare('baseDir', $BASEDIR);
|
||||||
|
$partial->prepare('baseUrl', $BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
@@ -23,7 +24,15 @@
|
|||||||
<div class="col-md-9 main-body">
|
<div class="col-md-9 main-body">
|
||||||
<a class="button is-primary m-1" onClick="$('#modal').removeClass('modal-container-hiden').show();"><?php $LANGMNG->echo('t_createAutomation'); ?></a>
|
<a class="button is-primary m-1" onClick="$('#modal').removeClass('modal-container-hiden').show();"><?php $LANGMNG->echo('t_createAutomation'); ?></a>
|
||||||
<div class="row no-gutters">
|
<div class="row no-gutters">
|
||||||
<?php foreach ($AUTOMATIONS as $automationId => $automationData) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach ($AUTOMATIONS as $automationId => $automationData) {
|
||||||
//BUTTON
|
//BUTTON
|
||||||
$partial = new Partial('automationButton');
|
$partial = new Partial('automationButton');
|
||||||
$partial->prepare('langMng',$LANGMNG);
|
$partial->prepare('langMng',$LANGMNG);
|
||||||
@@ -56,6 +65,28 @@
|
|||||||
|
|
||||||
$partial->prepare('subDevices',$SUBDEVICES);
|
$partial->prepare('subDevices',$SUBDEVICES);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
|
|
||||||
|
$form = new Form('Automation', 'automation-1', 'POST', '');
|
||||||
|
$form->addInput('text','name', 'name', '', true, true);
|
||||||
|
$form->addSelect('run-condition', 'run-condition', 'l_run_condition', [
|
||||||
|
'test' => 'test',
|
||||||
|
'test1' => 'test',
|
||||||
|
'test2' => 'test',
|
||||||
|
'test3' => 'test',
|
||||||
|
'test4' => 'test',
|
||||||
|
'test5' => 'test',
|
||||||
|
|
||||||
|
], true, true, true);
|
||||||
|
$form->addInput('button','add-condition', 'add-condition', 'l_condition', true, true);
|
||||||
|
$form->addSelect('active-time', 'active-time', 'l_run_schedule', [
|
||||||
|
'all' => 'l_all',
|
||||||
|
'day' => 'l_day',
|
||||||
|
'night' => 'l_night',
|
||||||
|
'custome' => 'l_custome',
|
||||||
|
], true, true, true);
|
||||||
|
|
||||||
|
$form->render();
|
||||||
|
|
||||||
}?>
|
}?>
|
||||||
<script src="./app/templates/js/automation.js"></script>
|
<script src="./app/templates/js/automation.js"></script>
|
||||||
<?php
|
<?php
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir', $BASEDIR);
|
$partial->prepare('baseDir', $BASEDIR);
|
||||||
|
$partial->prepare('baseUrl', $BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
@@ -25,16 +26,17 @@
|
|||||||
<div class="col-md-9 main-body">
|
<div class="col-md-9 main-body">
|
||||||
<table class="table is-fluid">
|
<table class="table is-fluid">
|
||||||
<tr>
|
<tr>
|
||||||
<th><a href="device">#</a></th>
|
<th><a href="device/icon/<?php echo $SORTTYPE; ?>">#</a><i class="fa"><?php echo (!empty($SORTICON['icon']) ? $SORTICON['icon'] : ""); ?></i></th>
|
||||||
<th><a href="device?sort=name&sortType=<?php echo $SORTTYPE; ?>">Name</a><i class="fa"><?php echo (!empty($SORTICON['name']) ? $SORTICON['name'] : ""); ?></i></th>
|
<th><a href="device/name/<?php echo $SORTTYPE; ?>">Name</a><i class="fa"><?php echo (!empty($SORTICON['name']) ? $SORTICON['name'] : ""); ?></i></th>
|
||||||
<th><a href="device?sort=room&sortType=<?php echo $SORTTYPE; ?>">Room</a><i class="fa"><?php echo (!empty($SORTICON['room']) ? $SORTICON['room'] : ""); ?></i></th>
|
<th><a href="device/room/<?php echo $SORTTYPE; ?>">Room</a><i class="fa"><?php echo (!empty($SORTICON['room']) ? $SORTICON['room'] : ""); ?></i></th>
|
||||||
<th><a href="device?sort=signal&sortType=<?php echo $SORTTYPE; ?>">Signal</a><i class="fa"><?php echo (!empty($SORTICON['signal']) ? $SORTICON['signal'] : ""); ?></i></th>
|
<th><a href="device/signal/<?php echo $SORTTYPE; ?>">Signal</a><i class="fa"><?php echo (!empty($SORTICON['signal']) ? $SORTICON['signal'] : ""); ?></i></th>
|
||||||
<th><a href="device?sort=firmware&sortType=<?php echo $SORTTYPE; ?>">Firmware</a><i class="fa"><?php echo (!empty($SORTICON['firmware']) ? $SORTICON['firmware'] : ""); ?></i></th>
|
<th><a href="device/firmware/<?php echo $SORTTYPE; ?>">Firmware</a><i class="fa"><?php echo (!empty($SORTICON['firmware']) ? $SORTICON['firmware'] : ""); ?></i></th>
|
||||||
<th>
|
<th>
|
||||||
<a href="device?sort=ip&sortType=<?php echo $SORTTYPE; ?>">IP Address</a><i class="fa"><?php echo (!empty($SORTICON['ip']) ? $SORTICON['ip'] : ""); ?></i><br>
|
<a href="device/ip/<?php echo $SORTTYPE; ?>">IP Address</a><i class="fa"><?php echo (!empty($SORTICON['ip']) ? $SORTICON['ip'] : ""); ?></i><br>
|
||||||
<a href="device?sort=mac&sortType=<?php echo $SORTTYPE; ?>">(Mac)</a><i class="fa"><?php echo (!empty($SORTICON['mac']) ? $SORTICON['mac'] : ""); ?></i><br>
|
<a href="device/mac/<?php echo $SORTTYPE; ?>">(Mac)</a><i class="fa"><?php echo (!empty($SORTICON['mac']) ? $SORTICON['mac'] : ""); ?></i><br>
|
||||||
<a href="device?sort=token&sortType=<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i>
|
<a href="device/token/<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i>
|
||||||
</th>
|
</th>
|
||||||
|
<th><a href="device/history/<?php echo $SORTTYPE; ?>">Historie</a><i class="fa"><?php echo (!empty($SORTICON['history']) ? $SORTICON['history'] : ""); ?></i></th>
|
||||||
<th>Action
|
<th>Action
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b></b></button>
|
<button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b></b></button>
|
||||||
@@ -45,7 +47,7 @@
|
|||||||
<?php if (!empty($DEVICES)) : ?>
|
<?php if (!empty($DEVICES)) : ?>
|
||||||
<?php foreach ($DEVICES as $device) : ?>
|
<?php foreach ($DEVICES as $device) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><i class="fa">&#x<?php echo (!empty($device['icon']) ? $device['icon'] : ""); ?></i></td>
|
<td><i class="fa <?php echo (!empty($device['icon']) ? $device['icon'] : ""); ?>"></i></td>
|
||||||
<td>
|
<td>
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
||||||
@@ -87,24 +89,38 @@
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<i class="fa <?php echo $icon; ?>" style="color: <?php echo $color; ?>;"></i>
|
<i class="fa <?php echo $icon; ?>" style="color: <?php echo $color; ?>;"></i>
|
||||||
<?php echo $device['firmware_hash'] ?>
|
|
||||||
<button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php echo $device['device_id'] ?>').click();"></button>
|
<button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php echo $device['device_id'] ?>').click();"></button>
|
||||||
<form style="display: none;" method="POST" action="" enctype="multipart/form-data">
|
<form style="display: none;" method="POST" action="" enctype="multipart/form-data">
|
||||||
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
||||||
<input type="file" onchange="this.form.submit();" name="deviceFirmware" id="deviceFirmware-<?php echo $device['device_id'] ?>" value="">
|
<input type="file" onchange="this.form.submit();" name="deviceFirmware" id="deviceFirmware-<?php echo $device['device_id'] ?>" value="">
|
||||||
</form>
|
</form>
|
||||||
|
<!--<button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php //echo $device['device_id'] ?>').click();"></button>-->
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div type="float: clear;"></div>
|
<div type="float: clear;"></div>
|
||||||
</td>
|
</td>
|
||||||
<td><?php echo (!empty($device['mac']) ? $device['mac'] : ""); ?><br>
|
<td><?php echo (!empty($device['mac']) ? $device['mac'] : ""); ?><br>
|
||||||
<?php echo (!empty($device['ip_address']) ? $device['ip_address'] : ""); ?><br>
|
<?php echo (!empty($device['ip_address']) ? $device['ip_address'] : ""); ?><br>
|
||||||
<?php echo (!empty($device['token']) ? $device['token'] : ""); ?></td>
|
<?php echo (!empty($device['token']) ? $device['token'] : ""); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php if (isset($device['history']) && $device['history'] != "null"): ?>
|
||||||
|
<form method="post" action="">
|
||||||
|
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
||||||
|
<input class="input" type="number" onchange="this.form.submit();" name="deviceHistory" value="<?php echo (!empty($device['history']) ? $device['history'] : 0); ?>">
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?php if (!empty($device['mac'])) : ?>
|
<?php if (!empty($device['mac'])) : ?>
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
||||||
<button class="fa custom-file-input" <?php echo (!empty($device['command']) && $device['command'] == "reset" ? "style=\"color:red;\"" : ""); ?> type="submit" name="deviceCommand" value="reset" title="Reset"></button>
|
<button class="fa custom-file-input" <?php echo (!empty($device['command']) && $device['command'] == "reset" ? "style=\"color:red;\"" : ""); ?> type="submit" name="deviceCommand" value="reset" title="Reset"></button>
|
||||||
<button class="fa custom-file-input" <?php echo (!empty($device['command']) && $device['command'] == "config" ? "style=\"color:red;\"" : ""); ?> type="submit" name="deviceCommand" value="config" title="Config"></button>
|
<button class="fa custom-file-input" <?php echo (!empty($device['command']) && $device['command'] == "config" ? "style=\"color:red;\"" : ""); ?> type="submit" name="deviceCommand" value="config" title="Config"></button>
|
||||||
|
<?php if (isset($device['approved']) && $device['approved'] == 0) : ?>
|
||||||
|
<button class="fas fa custom-file-input" type="submit" name="deviceApproved" value="1" title="Approved"></button>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (isset($device['approved']) && $device['approved'] < 2) : ?>
|
||||||
|
<button class="fas fa custom-file-input" type="submit" name="deviceApproved" value="2" title="Blocked"></button>
|
||||||
|
<?php endif; ?>
|
||||||
<div style="float: clear;"></div>
|
<div style="float: clear;"></div>
|
||||||
</form>
|
</form>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -121,12 +137,6 @@
|
|||||||
$partial->render();
|
$partial->render();
|
||||||
//TODO js do main.js
|
//TODO js do main.js
|
||||||
?>
|
?>
|
||||||
<script>
|
|
||||||
$(function() {
|
|
||||||
$("#sortable").sortable();
|
|
||||||
$("#sortable").disableSelection();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir', $BASEDIR);
|
$partial->prepare('baseDir', $BASEDIR);
|
||||||
|
$partial->prepare('baseUrl', $BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir',$BASEDIR);
|
$partial->prepare('baseDir',$BASEDIR);
|
||||||
|
$partial->prepare('baseUrl',$BASEURL);
|
||||||
|
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir',$BASEDIR);
|
$partial->prepare('baseDir',$BASEDIR);
|
||||||
|
$partial->prepare('baseUrl',$BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
|
@@ -8,60 +8,26 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<input class="input" type="text" name="name" required/>
|
<input class="input" type="text" name="name" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="label"><?php $LANGMNG->echo('l_runAt')?></div>
|
|
||||||
<div class="field">
|
|
||||||
<select class="input" name="atSelector" id="valueSelector" required>
|
|
||||||
<option value="sunSet"><?php $LANGMNG->echo('l_sunSet')?></option>
|
|
||||||
<option value="sunRise"><?php $LANGMNG->echo('l_sunRice')?></option>
|
|
||||||
<option value="inHome"><?php $LANGMNG->echo('l_inHome')?></option>
|
|
||||||
<option value="outHome"><?php $LANGMNG->echo('l_outHome')?></option>
|
|
||||||
<option value="time"><?php $LANGMNG->echo('l_time')?></option>
|
|
||||||
<option value="atDeviceValue"><?php $LANGMNG->echo('l_deviceValue');?></option>
|
|
||||||
<option value="noOneHome"><?php $LANGMNG->echo('w_noOne') . ' ' . $LANGMNG->get('w_neni') . ' ' . $LANGMNG->get('w_home');?></option>
|
|
||||||
<option value="someOneHome"><?php $LANGMNG->echo('w_someOne') . ' ' . $LANGMNG->get('w_is') . ' ' . $LANGMNG->get('w_home');?></option>
|
|
||||||
</select>
|
|
||||||
<input class="input" type="time" name="atTime" id="atTime" disabled/>
|
|
||||||
<select class="input" name="atDeviceValue" id="atDeviceValue" disabled>
|
|
||||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){ ?>
|
|
||||||
<option value="<?php echo $subDeviceKey; ?>"><?php echo $subDeviceValue['name']; ?>[<?php echo $subDeviceValue['type']; ?>]</option>
|
|
||||||
<?php } ?>
|
|
||||||
</select>
|
|
||||||
=
|
|
||||||
<input class="input" type="num" name="atDeviceValueInt" id="atDeviceValueInt" required disabled/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="label"><?php $LANGMNG->echo('l_affectedDevices')?></div>
|
<div class="label"><?php $LANGMNG->echo('l_runCondition')?></div>
|
||||||
<div class="field">
|
<select class="input" name="condOper" id="valueSelector" required>
|
||||||
<select class="input" name="devices[]" multiple>
|
<option value="or"><?php $LANGMNG->echo('l_oneNeedToBeWaild')?></option>
|
||||||
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){
|
<option value="and"><?php $LANGMNG->echo('l_allNeedToBeWalid')?></option>
|
||||||
if ($subDeviceValue['type'] != 'on/off') continue;?>
|
</select>
|
||||||
<option value="<?php echo $subDeviceValue['masterDevice']; ?>"><?php echo $subDeviceValue['name']; ?></option>
|
<input type="button" class="button" name="addCondition" value="<?php $LANGMNG->echo('b_add')?>"/>
|
||||||
<?php } ?>
|
|
||||||
</select>
|
|
||||||
|
<div class="label"><?php $LANGMNG->echo('l_runTask')?></div>
|
||||||
|
<input type="button" class="button" name="addTask" value="<?php $LANGMNG->echo('b_add')?>"/>
|
||||||
|
|
||||||
|
<div class="label"><?php $LANGMNG->echo('l_activeTime')?></div>
|
||||||
|
<select class="input" name="condOper" id="valueSelector" required>
|
||||||
|
<option value="allday"><?php $LANGMNG->echo('l_all')?></option>
|
||||||
|
<option value="daytime"><?php $LANGMNG->echo('l_day')?></option>
|
||||||
|
<option value="night"><?php $LANGMNG->echo('l_night')?></option>
|
||||||
|
<option value="custom"><?php $LANGMNG->echo('l_custome')?></option>
|
||||||
|
</select>
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="label"><?php $LANGMNG->echo('l_atDays')?></div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="mon"/> <?php $LANGMNG->echo('d_monday'); ?>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="tue"/> <?php $LANGMNG->echo('d_tuesday'); ?>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="wed"/> <?php $LANGMNG->echo('d_wednesday'); ?>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="thu"/> <?php $LANGMNG->echo('d_thursday'); ?>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="fri"/> <?php $LANGMNG->echo('d_friday'); ?>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="sat"/> <?php $LANGMNG->echo('d_saturday'); ?>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<input type="checkbox" name="day[]" value="sun"/> <?php $LANGMNG->echo('d_sunday'); ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" class="button" name="modalNext" value="<?php $LANGMNG->echo('b_next')?>"/>
|
<input type="submit" class="button" name="modalNext" value="<?php $LANGMNG->echo('b_next')?>"/>
|
||||||
</form>
|
</form>
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
|
|
||||||
|
<base href="<?php echo $BASEURL; ?>">
|
||||||
|
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="application-name" content="Home">
|
<meta name="application-name" content="Home">
|
||||||
@@ -18,6 +20,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
|
||||||
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/main.css?v2">
|
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/main.css?v2">
|
||||||
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/font-awesome.min.css">
|
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/font-awesome.min.css">
|
||||||
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/modal.css">
|
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/modal.css">
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
<input class="" type="checkbox" name="remember" value="true"/>
|
<input class="" type="checkbox" name="remember" value="true"/>
|
||||||
</div>
|
</div>
|
||||||
<?php if (!empty ($_SESSION['msg'])): ?>
|
<?php if (!empty ($_SESSION['msg'])): ?>
|
||||||
<label class="message"><?php echo $_SESSION['msg']; ?></label><br/><br/>
|
<label class="alert"><?php echo $_SESSION['msg']; ?></label><br/><br/>
|
||||||
<?php unset ($_SESSION['msg']); ?>
|
<?php unset ($_SESSION['msg']); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<input type="submit" class="button" name="login" value="Login"/>
|
<input type="submit" class="button" name="login" value="Login"/>
|
||||||
|
69
app/views/templates/part/newAutomationCreate.phtml
Normal file
69
app/views/templates/part/newAutomationCreate.phtml
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<div class="modal-container modal-container-hiden" id="modal">
|
||||||
|
<div class="modal">
|
||||||
|
<a href=""><i class="fa fa-times close"></i></a>
|
||||||
|
<h4 class="mb-4"><?php $LANGMNG->echo('t_createAutomation')?></h4>
|
||||||
|
<form method="post" action="" >
|
||||||
|
<div class="field">
|
||||||
|
<div class="label"><?php $LANGMNG->echo('l_nameAt')?></div>
|
||||||
|
<div class="field">
|
||||||
|
<input class="input" type="text" name="name" required/>
|
||||||
|
</div>
|
||||||
|
<div class="label"><?php $LANGMNG->echo('l_runAt')?></div>
|
||||||
|
<div class="field">
|
||||||
|
<select class="input" name="atSelector" id="valueSelector" required>
|
||||||
|
<option value="sunSet"><?php $LANGMNG->echo('l_sunSet')?></option>
|
||||||
|
<option value="sunRise"><?php $LANGMNG->echo('l_sunRice')?></option>
|
||||||
|
<option value="inHome"><?php $LANGMNG->echo('l_inHome')?></option>
|
||||||
|
<option value="outHome"><?php $LANGMNG->echo('l_outHome')?></option>
|
||||||
|
<option value="time"><?php $LANGMNG->echo('l_time')?></option>
|
||||||
|
<option value="atDeviceValue"><?php $LANGMNG->echo('l_deviceValue');?></option>
|
||||||
|
<option value="noOneHome"><?php $LANGMNG->echo('w_noOne') . ' ' . $LANGMNG->get('w_neni') . ' ' . $LANGMNG->get('w_home');?></option>
|
||||||
|
<option value="someOneHome"><?php $LANGMNG->echo('w_someOne') . ' ' . $LANGMNG->get('w_is') . ' ' . $LANGMNG->get('w_home');?></option>
|
||||||
|
</select>
|
||||||
|
<input class="input" type="time" name="atTime" id="atTime" disabled/>
|
||||||
|
<select class="input" name="atDeviceValue" id="atDeviceValue" disabled>
|
||||||
|
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){ ?>
|
||||||
|
<option value="<?php echo $subDeviceKey; ?>"><?php echo $subDeviceValue['name']; ?>[<?php echo $subDeviceValue['type']; ?>]</option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
=
|
||||||
|
<input class="input" type="num" name="atDeviceValueInt" id="atDeviceValueInt" required disabled/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="label"><?php $LANGMNG->echo('l_affectedDevices')?></div>
|
||||||
|
<div class="field">
|
||||||
|
<select class="input" name="devices[]" multiple>
|
||||||
|
<?php foreach ($SUBDEVICES as $subDeviceKey => $subDeviceValue){
|
||||||
|
if ($subDeviceValue['type'] != 'on/off') continue;?>
|
||||||
|
<option value="<?php echo $subDeviceValue['masterDevice']; ?>"><?php echo $subDeviceValue['name']; ?></option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="label"><?php $LANGMNG->echo('l_atDays')?></div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="mon"/> <?php $LANGMNG->echo('d_monday'); ?>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="tue"/> <?php $LANGMNG->echo('d_tuesday'); ?>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="wed"/> <?php $LANGMNG->echo('d_wednesday'); ?>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="thu"/> <?php $LANGMNG->echo('d_thursday'); ?>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="fri"/> <?php $LANGMNG->echo('d_friday'); ?>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="sat"/> <?php $LANGMNG->echo('d_saturday'); ?>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input type="checkbox" name="day[]" value="sun"/> <?php $LANGMNG->echo('d_sunday'); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="submit" class="button" name="modalNext" value="<?php $LANGMNG->echo('b_next')?>"/>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
@@ -2,8 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir', $BASEDIR);
|
$partial->prepare('baseDir', $BASEDIR);
|
||||||
|
$partial->prepare('baseUrl', $BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir', $BASEDIR);
|
$partial->prepare('baseDir', $BASEDIR);
|
||||||
|
$partial->prepare('baseUrl', $BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
@@ -23,23 +24,23 @@
|
|||||||
<div class="col-md-9 main-body">
|
<div class="col-md-9 main-body">
|
||||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||||
<h1><?php echo $LANGMNG->get('t_ServerStats'); ?></h1>
|
<h1><?php echo $LANGMNG->get('t_ServerStats'); ?></h1>
|
||||||
<hr>
|
<hr>
|
||||||
<label>UPTIME: <?php echo $UPTIME;?></label></br>
|
<label>UPTIME: <?php echo $UPTIME;?></label></br>
|
||||||
<label>SERVER TIME: <?php echo $SERVERTIME;?></label></br>
|
<label>SERVER TIME: <?php echo $SERVERTIME;?></label></br>
|
||||||
<label>SERVER NAME: <?php echo $NAME;?></label></br>
|
<label>SERVER NAME: <?php echo $NAME;?></label></br>
|
||||||
<label>SERVER ADDRESS: <?php echo $IP;?></label></br>
|
<label>SERVER ADDRESS: <?php echo $IP;?></label></br>
|
||||||
<hr>
|
<hr>
|
||||||
<label>CPU: <?php echo $CPU;?></label></br>
|
<label>CPU: <?php echo $CPU;?></label></br>
|
||||||
<label>CPU Usage: </label><progress value="<?php echo $CPU;?>" max="100"> <?php echo $RAMFREE;?> </progress></br>
|
<label>CPU Usage: </label><progress value="<?php echo $CPU;?>" max="100"> <?php echo $RAMFREE;?> </progress></br>
|
||||||
<hr>
|
<hr>
|
||||||
<label>RAM TOTAL: <?php echo $RAMTOTAL;?></label></br>
|
<label>RAM TOTAL: <?php echo $RAMTOTAL;?></label></br>
|
||||||
<label>RAM FREE: <?php echo $RAMFREE;?></label></br>
|
<label>RAM FREE: <?php echo $RAMFREE;?></label></br>
|
||||||
<label>RAM Usage: </label><progress value="<?php echo explode(" ", $RAMTOTAL)[0] - explode(" ", $RAMFREE)[0];?>" max="<?php echo explode(" ", $RAMTOTAL)[0];?>"> <?php echo $RAMFREE;?> </progress></br>
|
<label>RAM Usage: </label><progress value="<?php echo explode(" ", $RAMTOTAL)[0] - explode(" ", $RAMFREE)[0];?>" max="<?php echo explode(" ", $RAMTOTAL)[0];?>"> <?php echo $RAMFREE;?> </progress></br>
|
||||||
<hr>
|
<hr>
|
||||||
<label>DISK TOTAL: <?php echo $DISKTOTAL;?> bytes</label></br>
|
<label>DISK TOTAL: <?php echo $DISKTOTAL;?> bytes</label></br>
|
||||||
<label>DISK FREE: <?php echo $DISKFREE;?> bytes</label></br>
|
<label>DISK FREE: <?php echo $DISKFREE;?> bytes</label></br>
|
||||||
<label>DISK Usage: </label><progress value="<?php echo explode(" ", $DISKTOTAL)[0] - explode(" ", $DISKFREE)[0];?>" max="<?php echo explode(" ", $DISKTOTAL)[0];?>"> <?php echo $DISKFREE;?> </progress></br>
|
<label>DISK Usage: </label><progress value="<?php echo explode(" ", $DISKTOTAL)[0] - explode(" ", $DISKFREE)[0];?>" max="<?php echo explode(" ", $DISKTOTAL)[0];?>"> <?php echo $DISKFREE;?> </progress></br>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -49,6 +50,6 @@
|
|||||||
$partial->render();
|
$partial->render();
|
||||||
//TODO js do main.js
|
//TODO js do main.js
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<?php
|
<?php
|
||||||
$partial = new Partial('head');
|
$partial = new Partial('head');
|
||||||
$partial->prepare('baseDir', $BASEDIR);
|
$partial->prepare('baseDir', $BASEDIR);
|
||||||
|
$partial->prepare('baseUrl', $BASEURL);
|
||||||
$partial->render();
|
$partial->render();
|
||||||
?>
|
?>
|
||||||
<title><?php echo $TITLE ?></title>
|
<title><?php echo $TITLE ?></title>
|
||||||
@@ -176,7 +177,12 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($ROOMS as $key => $room) { ?>
|
<?php foreach ($ROOMS as $key => $room) { ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo $room['name']; ?></td>
|
<td>
|
||||||
|
<form method="post" action="">
|
||||||
|
<input type="hidden" name="roomId" value="<?php echo (!empty($room['room_id']) ? $room['room_id'] : ""); ?>">
|
||||||
|
<input class="input" type="text" onchange="this.form.submit();" name="roomName" value="<?php echo (!empty($room['name']) ? $room['name'] : ""); ?>">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button name="deleteRoom" type="button" class="button is-danger fa"></button>
|
<button name="deleteRoom" type="button" class="button is-danger fa"></button>
|
||||||
<button name="defaultRoom" type="button" class="button fa" <?php echo ($room['default'] ? 'disabled' : ''); ?>></button>
|
<button name="defaultRoom" type="button" class="button fa" <?php echo ($room['default'] ? 'disabled' : ''); ?>></button>
|
||||||
@@ -201,7 +207,23 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!--Plugins Settings-->
|
||||||
|
<?php foreach ($PLUGINSSETTINGS as $key => $pluginSeting) { ?>
|
||||||
|
<div class="col-12 col-sm-9 mx-auto mt-4">
|
||||||
|
<h4 class="mb-4"><?php echo $pluginSeting['name'] ?></h4>
|
||||||
|
<form method="post">
|
||||||
|
<?php foreach ($pluginSeting['settings'] as $key => $pluginSetingField) { ?>
|
||||||
|
<div class="field">
|
||||||
|
<div class="label"><?php echo $pluginSetingField['name'] ?>:</div>
|
||||||
|
<input type="text" class="input" name="<?php echo $pluginSetingField['name'] ?>" value="<?php echo $pluginSetingField['value'] ?>">
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<div class="field">
|
||||||
|
<input type="submit" name="submitPlugins<?php echo $pluginSeting['name'] ?>Settings" class="button" value="<?php $LANGMNG->echo('b_save') ?>">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title><?php echo $this->title ?></title>
|
<title><?php echo $this->title; ?></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php echo $this->content(); ?>
|
<?php echo $this->content(); ?>
|
||||||
|
10
composer.json
Normal file
10
composer.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Core\\": "core/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/container": "^8.18"
|
||||||
|
}
|
||||||
|
}
|
207
composer.lock
generated
Normal file
207
composer.lock
generated
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "c3305b3f3f6089062c2031140866dab7",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "illuminate/container",
|
||||||
|
"version": "v8.18.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/illuminate/container.git",
|
||||||
|
"reference": "657cac2aa601aa0223afe0ed8627d0cb443f6a22"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/illuminate/container/zipball/657cac2aa601aa0223afe0ed8627d0cb443f6a22",
|
||||||
|
"reference": "657cac2aa601aa0223afe0ed8627d0cb443f6a22",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/contracts": "^8.0",
|
||||||
|
"php": "^7.3|^8.0",
|
||||||
|
"psr/container": "^1.0"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"psr/container-implementation": "1.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "8.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Illuminate\\Container\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Taylor Otwell",
|
||||||
|
"email": "taylor@laravel.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "The Illuminate Container package.",
|
||||||
|
"homepage": "https://laravel.com",
|
||||||
|
"time": "2020-12-01T14:31:29+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "illuminate/contracts",
|
||||||
|
"version": "v8.18.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/illuminate/contracts.git",
|
||||||
|
"reference": "a73835aad399da42e88217bdbb5e1e4c1e668807"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/illuminate/contracts/zipball/a73835aad399da42e88217bdbb5e1e4c1e668807",
|
||||||
|
"reference": "a73835aad399da42e88217bdbb5e1e4c1e668807",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.3|^8.0",
|
||||||
|
"psr/container": "^1.0",
|
||||||
|
"psr/simple-cache": "^1.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "8.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Illuminate\\Contracts\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Taylor Otwell",
|
||||||
|
"email": "taylor@laravel.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "The Illuminate Contracts package.",
|
||||||
|
"homepage": "https://laravel.com",
|
||||||
|
"time": "2020-11-18T13:57:08+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/container",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/container.git",
|
||||||
|
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
|
||||||
|
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\Container\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "http://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common Container Interface (PHP FIG PSR-11)",
|
||||||
|
"homepage": "https://github.com/php-fig/container",
|
||||||
|
"keywords": [
|
||||||
|
"PSR-11",
|
||||||
|
"container",
|
||||||
|
"container-interface",
|
||||||
|
"container-interop",
|
||||||
|
"psr"
|
||||||
|
],
|
||||||
|
"time": "2017-02-14T16:28:37+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/simple-cache",
|
||||||
|
"version": "1.0.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/simple-cache.git",
|
||||||
|
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
|
||||||
|
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\SimpleCache\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "http://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common interfaces for simple caching",
|
||||||
|
"keywords": [
|
||||||
|
"cache",
|
||||||
|
"caching",
|
||||||
|
"psr",
|
||||||
|
"psr-16",
|
||||||
|
"simple-cache"
|
||||||
|
],
|
||||||
|
"time": "2017-10-23T01:57:42+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": [],
|
||||||
|
"platform-dev": [],
|
||||||
|
"plugin-api-version": "1.1.0"
|
||||||
|
}
|
5
config/application.php
Normal file
5
config/application.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'providers' => []
|
||||||
|
];
|
@@ -60,7 +60,6 @@ const UNITS = [
|
|||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
define('SERVERKEY','');
|
define('SERVERKEY','');
|
||||||
define('SERVERVAIPKEY','');
|
|
||||||
|
|
||||||
//TODO: Po registraci vzít výchozí hodnoty
|
//TODO: Po registraci vzít výchozí hodnoty
|
||||||
//Default network Setting
|
//Default network Setting
|
||||||
|
26
core/Application/Application.php
Normal file
26
core/Application/Application.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Core\Application;
|
||||||
|
|
||||||
|
use Core\Configuration\Configurations;
|
||||||
|
use Illuminate\Container\Container;
|
||||||
|
|
||||||
|
class Application
|
||||||
|
{
|
||||||
|
/** @var Container $container */
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
/** @var Configurations */
|
||||||
|
private $configurations;
|
||||||
|
|
||||||
|
public function __construct(Container $container, Configurations $configurations)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
$this->configurations = $configurations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
//todo: implement run logic.
|
||||||
|
}
|
||||||
|
}
|
11
core/Configuration/Configurations.php
Normal file
11
core/Configuration/Configurations.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Core\Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Configurations
|
||||||
|
* @package Core\Configuration
|
||||||
|
* @author Romano Schoonheim https://github.com/romano1996
|
||||||
|
*/
|
||||||
|
class Configurations
|
||||||
|
{}
|
2
git-stats.ps1
Normal file
2
git-stats.ps1
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
$lines = (ls -r|sls '^\s*(#|$)' -a -n).Count
|
||||||
|
write-host $lines" of code"
|
@@ -7,10 +7,12 @@ class Template{
|
|||||||
|
|
||||||
function __construct($path = "", $debug = false) {
|
function __construct($path = "", $debug = false) {
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
if (!empty('../app/views/templates/' . $path . '.phtml') && file_exists('../app/views/templates/' . $path . '.phtml')) {
|
|
||||||
|
if (!empty(__DIR__ . '/../app/views/templates/' . $path . '.phtml') && file_exists(__DIR__ . '/../app/views/templates/' . $path . '.phtml')) {
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
} else {
|
} else {
|
||||||
echo '<pre>';
|
echo '<pre>';
|
||||||
|
echo __DIR__ . '/../app/views/templates/' . $path . '.phtml</br>';
|
||||||
echo 'PHTML: Template File ' . $path . ' not found';
|
echo 'PHTML: Template File ' . $path . ' not found';
|
||||||
echo '</pre>';
|
echo '</pre>';
|
||||||
die();
|
die();
|
||||||
@@ -26,9 +28,9 @@ class Template{
|
|||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
extract($this->assignedValues);
|
extract($this->assignedValues);
|
||||||
if (!empty('../app/controllers/' . $this->path . 'Controller.php') && file_exists('../app/controllers/' . $this->path . 'Controller.php')) {
|
if (!empty(__DIR__ . '/../app/controllers/' . $this->path . 'Controller.php') && file_exists(__DIR__ . '/../app/controllers/' . $this->path . 'Controller.php')) {
|
||||||
include('../app/controllers/' . $this->path . 'Controller.php');
|
include(__DIR__ . '/../app/controllers/' . $this->path . 'Controller.php');
|
||||||
}
|
}
|
||||||
require_once('../app/views/templates/' . $this->path . '.phtml');
|
require_once(__DIR__ . '/../app/views/templates/' . $this->path . '.phtml');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,8 @@ RewriteRule (.*) ./index.php?url=$1 [QSA,L]
|
|||||||
RewriteCond %{HTTP:Authorization} ^(.*)
|
RewriteCond %{HTTP:Authorization} ^(.*)
|
||||||
RewriteRule . - [e=HTTP_AUTHORIZATION:%1]
|
RewriteRule . - [e=HTTP_AUTHORIZATION:%1]
|
||||||
|
|
||||||
RewriteCond %{HTTPS} off
|
#RewriteCond %{HTTPS} off
|
||||||
RewriteCond %{REQUEST_URI} !^/api/update
|
#RewriteCond %{REQUEST_URI} !^/api/update
|
||||||
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
||||||
|
|
||||||
AddType application/x-httpd-php .php .phtml
|
AddType application/x-httpd-php .php .phtml
|
||||||
|
@@ -2660,19 +2660,19 @@ html {
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Metropolis';
|
font-family: 'Metropolis';
|
||||||
src: url("../fonts/Metropolis-Regular.ttf");
|
/*src: url("../fonts/Metropolis-Regular.ttf");*/
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Metropolis';
|
font-family: 'Metropolis';
|
||||||
src: url("../fonts/Metropolis-Medium.ttf");
|
/*src: url("../fonts/Metropolis-Medium.ttf");*/
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Metropolis';
|
font-family: 'Metropolis';
|
||||||
src: url("../fonts/Metropolis-SemiBold.ttf");
|
/*src: url("../fonts/Metropolis-SemiBold.ttf");*/
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../app/Bootstrap.php';
|
require_once __DIR__ . '/../app/Bootstrap.php';
|
@@ -1,64 +0,0 @@
|
|||||||
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) {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
Reference in New Issue
Block a user