Compare commits
14 Commits
adfb564ccc
...
remasterin
Author | SHA1 | Date | |
---|---|---|---|
|
0045bdeb84 | ||
|
9c565d90fa | ||
|
f80b9a6b43 | ||
|
49f2354908 | ||
|
541ea0002f | ||
|
135dfcb666 | ||
|
04e83dccf6 | ||
|
4ab70a1c2d | ||
|
5f03295ad3 | ||
|
66dc2a3670 | ||
|
b9a967642a | ||
|
fe1247fdaf | ||
|
9d9304d30e | ||
|
c6f57a3661 |
@@ -1,6 +0,0 @@
|
||||
.git
|
||||
_FIRMWARE
|
||||
_INSTALATION
|
||||
_README_IMG
|
||||
README.md
|
||||
.todo
|
9
.gitignore
vendored
9
.gitignore
vendored
@@ -13,9 +13,8 @@ _nemazat/css/font-awesome.min.css
|
||||
.vscode/
|
||||
.vscode/sftp.json
|
||||
|
||||
app/updater/*.bin
|
||||
app/logs/*.log
|
||||
backup/*.zip
|
||||
|
||||
|
||||
vendor/
|
||||
|
||||
logs/*.log
|
||||
updater/*.bin
|
||||
backup/*.zip
|
||||
|
@@ -18,5 +18,6 @@ RewriteRule (.*) ./public/$1 [L]
|
||||
|
||||
# serve all other request as query parameters
|
||||
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
|
||||
|
1
.todo
1
.todo
@@ -11,3 +11,4 @@
|
||||
//TODO: Fix Default Room selection
|
||||
//TODO: Fix User Delete button
|
||||
//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>
|
2044
adminer.php
2044
adminer.php
File diff suppressed because one or more lines are too long
@@ -3,6 +3,8 @@
|
||||
error_reporting(E_ALL);
|
||||
ini_set( 'display_errors','1');
|
||||
|
||||
|
||||
|
||||
//setup
|
||||
parse_str($_SERVER['QUERY_STRING'], $params);
|
||||
if (defined ("BASEDIR")) {
|
||||
@@ -105,8 +107,6 @@ $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] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||
|
||||
|
||||
|
||||
Debugger::flag('dbconnect');
|
||||
//DB Conector
|
||||
Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
|
||||
|
@@ -10,6 +10,7 @@ $router->setDefault(function(){
|
||||
unset($logManager);
|
||||
});
|
||||
|
||||
|
||||
//Pages
|
||||
$router->any('/', 'Log');
|
||||
$router->any('/log', 'Log');
|
||||
@@ -46,6 +47,7 @@ $router->get('/api/server/log', 'ServerApi@logStatus');
|
||||
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
||||
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
||||
$router->get('/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');
|
||||
@@ -61,8 +63,10 @@ $router->post('/cron/automations', 'CronApi@automations');
|
||||
|
||||
|
||||
//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');
|
||||
|
||||
|
||||
//Endpoints API
|
||||
@@ -71,6 +75,9 @@ $router->any('/api/update/', 'UpdatesApi@default');
|
||||
$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
|
||||
$router->any('/api/example', 'ExampleApi@example');
|
||||
|
@@ -26,8 +26,18 @@ class AutomationsApi extends ApiController
|
||||
$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'],$obj['days'], $obj['tasks'], $obj['conditions']);
|
||||
$response = AutomationManager::create($obj['name'],json_encode($obj['days']), json_encode($obj['tasks']), json_encode($obj['conditions']));
|
||||
|
||||
$this->response(['value'=>'OK']);
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
class EndpointsApi extends ApiController{
|
||||
public function default(){
|
||||
class EndpointsApi extends ApiController
|
||||
{
|
||||
public function default()
|
||||
{
|
||||
// $this->requireAuth();
|
||||
$obj = $this->input;
|
||||
|
||||
@@ -93,8 +95,7 @@ class EndpointsApi extends ApiController{
|
||||
// Issuing command
|
||||
if ($command == "null") {
|
||||
$deviceCommand = $device["command"];
|
||||
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null")
|
||||
{
|
||||
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null") {
|
||||
$command = $deviceCommand;
|
||||
$data = [
|
||||
'command' => 'null'
|
||||
@@ -193,4 +194,77 @@ class EndpointsApi extends ApiController{
|
||||
//unset($logManager); //TODO: Opravit
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -28,11 +28,18 @@ class RoomsApi extends ApiController
|
||||
|
||||
//Connection Error Creation
|
||||
$connectionError = true;
|
||||
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['time']);
|
||||
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['heartbeat']);
|
||||
$interval = $LastRecordTime->diff(new DateTime());
|
||||
$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i'));
|
||||
|
||||
if ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == NULL || $subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 || $lastSeen < $subDevicesData[$subDeviceKey][$key]['sleep_time']) {
|
||||
|
||||
$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;
|
||||
|
@@ -134,4 +134,30 @@ class WidgetApi extends ApiController
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -28,6 +28,9 @@ if (!empty ($_POST)){
|
||||
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
|
||||
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
|
||||
}
|
||||
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']));
|
||||
}
|
||||
|
@@ -14,19 +14,33 @@ if (
|
||||
$state = $_POST["state"];
|
||||
$clientId = $_POST["clientId"];
|
||||
$ota = $userManager->haveOtaEnabled($userName);
|
||||
|
||||
if ($ota == "") {
|
||||
$token = (new AuthManager)->getToken($userName,$userPassword, $clientId);
|
||||
if (!$token) {
|
||||
throw new Exception("Auth failed", 401);
|
||||
}
|
||||
|
||||
$get=[];
|
||||
if ($_POST['response_type'] = 'code') {
|
||||
$get = [
|
||||
"state"=>$state,
|
||||
"code"=>$token,
|
||||
"state"=>$state,
|
||||
];
|
||||
} else {
|
||||
$get = [
|
||||
"access_token"=>$token,
|
||||
"token_type"=>"Bearer",
|
||||
"state"=>$state,
|
||||
];
|
||||
}
|
||||
|
||||
header('Location: ' . $_POST["redirectUrl"] . '#' . http_build_query($get));
|
||||
//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();
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
$userManager = new UserManager();
|
||||
$roomManager = new RoomManager();
|
||||
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
|
||||
$oldPassword = $_POST['oldPassword'];
|
||||
$newPassword = $_POST['newPassword1'];
|
||||
@@ -30,6 +31,10 @@ if (isset($_POST) && !empty($_POST)){
|
||||
$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;
|
||||
|
@@ -112,7 +112,7 @@ class Form {
|
||||
* [render function whitch dysplay generated form]
|
||||
*/
|
||||
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 .= $this->formContent;
|
||||
$form .= '</form>';
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
https://console.cloud.google.com/logs/query;cursorTimestamp=2021-04-11T07:51:16.567357750Z?project=simple-home-79188
|
||||
class GoogleHome
|
||||
{
|
||||
static function sync($requestId)
|
||||
@@ -42,7 +43,10 @@ class GoogleHome
|
||||
],
|
||||
|
||||
'willReportState' => false,
|
||||
'roomHint' => $roomData['name']
|
||||
'roomHint' => $roomData['name'],
|
||||
"otherDeviceIds" => [
|
||||
["deviceId" => "SH#".(string) $deviceData['device_id']]
|
||||
]
|
||||
];
|
||||
if ($tempDevice['attributes'] == null) unset($tempDevice['attributes']);
|
||||
|
||||
|
@@ -17,14 +17,14 @@ class AutomationManager{
|
||||
return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId));
|
||||
}
|
||||
|
||||
public static function create ($name, $onDays, $doCode, $ifCode, $automationId = "") {
|
||||
$userId = UserManager::getUserData('user_id');
|
||||
public static function create ($name, $onDays, $doCode, $ifCode, $userId = 1, $automationId = "") {
|
||||
$userId = UserManager::getUserData('user_id', $userId);
|
||||
$scene = array (
|
||||
'name' => $name,
|
||||
'owner_id' => $userId,
|
||||
'on_days' => $onDays,
|
||||
'if_something' => $ifCode,
|
||||
'do_something' => $doCode,
|
||||
'conditions' => $ifCode,
|
||||
'tasks' => $doCode,
|
||||
);
|
||||
try {
|
||||
if ($automationId == "") {
|
||||
|
@@ -8,6 +8,7 @@
|
||||
class LogManager
|
||||
{
|
||||
private $logFile;
|
||||
private $filePath = null;
|
||||
private $logLevel = 1;
|
||||
|
||||
public function __construct($fileName = "")
|
||||
@@ -15,12 +16,13 @@ class LogManager
|
||||
if ($fileName == ""){
|
||||
$fileName = '../logs/'. date("Y-m-d").'.log';
|
||||
}
|
||||
|
||||
if(!is_dir("../logs/"))
|
||||
{
|
||||
mkdir("../logs/");
|
||||
}
|
||||
|
||||
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
|
||||
$this->filePath = $fileName;
|
||||
}
|
||||
|
||||
public function setLevel($type = LogRecordTypess::WARNING){
|
||||
@@ -28,6 +30,10 @@ class LogManager
|
||||
}
|
||||
|
||||
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) {
|
||||
$record = "[".date("H:m:s")."][".$type['identifier']."]" . $value . "\n";
|
||||
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;
|
||||
}
|
||||
}
|
@@ -37,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) {
|
||||
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ class SettingsManager{
|
||||
}
|
||||
|
||||
public static function create ($name, $value, $type = '') {
|
||||
//if (!self::getByName($name)){
|
||||
if (!self::getByName($name)){
|
||||
$setting = array (
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
@@ -26,7 +26,7 @@ class SettingsManager{
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public static function update ($name, $value, $type = '') {
|
||||
|
@@ -66,8 +66,18 @@ class SubDeviceManager
|
||||
}
|
||||
}
|
||||
|
||||
public static function editSubDevicesByDevice ($deviceId, $subDeviceParameters) {
|
||||
DB::edit('subdevices', $subDeviceParameters, 'WHERE device_id=?', array ($deviceId));
|
||||
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)
|
||||
@@ -82,7 +92,7 @@ class SubDeviceManager
|
||||
|
||||
//TODO: @Patrik Check line 89
|
||||
$rows = Db::loadAll("
|
||||
SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.device_id, d.icon, d.name, sd.type, sd.unit, r.value, r.time 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 records r ON r.subdevice_id = sd.subdevice_id
|
||||
WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
class GoogleHomeDeviceTypes {
|
||||
class GoogleHomeDeviceTypes
|
||||
{
|
||||
/*const AirConditioningUnit = 'action.devices.types.AC_UNIT';
|
||||
const AirFreshener = 'action.devices.types.AIRFRESHENER';
|
||||
const AirPurifier = 'action.devices.types.AIRPURIFIER';
|
||||
@@ -107,7 +108,7 @@ class GoogleHomeDeviceTypes {
|
||||
'commandOnlyOnOff' => false,
|
||||
],
|
||||
'temp_cont' => [
|
||||
'availableThermostatModes' => 'off,heat',
|
||||
'availableThermostatModes' => ['off', 'heat'],
|
||||
'thermostatTemperatureUnit' => 'C',
|
||||
],
|
||||
'vol_cont' => [
|
||||
@@ -159,27 +160,32 @@ class GoogleHomeDeviceTypes {
|
||||
],
|
||||
];
|
||||
|
||||
static function getAction($deviceType){
|
||||
static function getAction($deviceType)
|
||||
{
|
||||
if (!isset(self::$actionWordBook[$deviceType])) return;
|
||||
return self::$actionWordBook[$deviceType];
|
||||
}
|
||||
|
||||
static function getTraid($subDeviceType){
|
||||
static function getTraid($subDeviceType)
|
||||
{
|
||||
if (!isset(self::$traidWordBook[$subDeviceType])) return;
|
||||
return self::$traidWordBook[$subDeviceType];
|
||||
}
|
||||
|
||||
static function getType($subDeviceCommand){
|
||||
static function getType($subDeviceCommand)
|
||||
{
|
||||
if (!isset(self::$commandWordBook[$subDeviceCommand])) return;
|
||||
return self::$commandWordBook[$subDeviceCommand];
|
||||
}
|
||||
|
||||
static function getAttribute($subDeviceType){
|
||||
static function getAttribute($subDeviceType)
|
||||
{
|
||||
if (!isset(self::$attributeWordBook[$subDeviceType])) return;
|
||||
return self::$attributeWordBook[$subDeviceType];
|
||||
}
|
||||
|
||||
static function getQueryJson($deviceType, $type){
|
||||
static function getQueryJson($deviceType, $type)
|
||||
{
|
||||
return self::$wordBook[$type];
|
||||
}
|
||||
}
|
||||
|
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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,14 +9,6 @@ class AirQuality extends VirtualDeviceManager
|
||||
|
||||
function make()
|
||||
{
|
||||
//Register the settings
|
||||
$settingMng = new SettingsManager();
|
||||
if (!($settingField = $settingMng->getByName("airquality"))) {
|
||||
$settingMng->create("token", "", "airquality");
|
||||
} else {
|
||||
$app_id = $settingField['value'];
|
||||
}
|
||||
|
||||
try {
|
||||
if (DeviceManager::registeret($this->virtual_device_name)) {
|
||||
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
||||
|
@@ -38,7 +38,7 @@ class DameJidlo extends VirtualDeviceManager
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -80,6 +80,6 @@ class DameJidlo extends VirtualDeviceManager
|
||||
} else if ($value <= 1) {
|
||||
return "less " . $value;
|
||||
}
|
||||
return '';
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,18 @@
|
||||
<?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()
|
||||
{
|
||||
//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');
|
||||
|
||||
@@ -11,6 +21,13 @@ class Oauth extends Template
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('title', 'Simple Home - Oauth');
|
||||
|
||||
if (isset($_GET['response_type']) && $_GET['response_type'] == 'code') {
|
||||
$template->prepare('responseType', $_GET['response_type']);
|
||||
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
||||
$template->prepare('clientId', $_GET['client_id']);
|
||||
$template->prepare('scope', $_GET['scope']);
|
||||
$template->prepare('state', $_GET['state']);
|
||||
} else {
|
||||
if (isset($_GET['redirect_uri'])) {
|
||||
$template->prepare('responseType', $_GET['response_type']);
|
||||
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
||||
@@ -22,7 +39,38 @@ class Oauth extends Template
|
||||
$template->prepare('clientId', $_POST['clientId']);
|
||||
$template->prepare('state', $_POST['state']);
|
||||
}
|
||||
}
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
@@ -10,24 +10,12 @@ class Setting extends Template
|
||||
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->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('title', 'Automation');
|
||||
$template->prepare('title', 'Settings');
|
||||
$template->prepare('langMng', $langMng);
|
||||
$template->prepare('automations', $automations);
|
||||
|
||||
$users = $userManager->getUsers();
|
||||
foreach ($users as $key => $value) {
|
||||
|
@@ -24,7 +24,15 @@ $partial = new Partial('head');
|
||||
<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>
|
||||
<div class="row no-gutters">
|
||||
<?php foreach ($AUTOMATIONS as $automationId => $automationData) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
foreach ($AUTOMATIONS as $automationId => $automationData) {
|
||||
//BUTTON
|
||||
$partial = new Partial('automationButton');
|
||||
$partial->prepare('langMng',$LANGMNG);
|
||||
@@ -57,6 +65,28 @@ $partial = new Partial('head');
|
||||
|
||||
$partial->prepare('subDevices',$SUBDEVICES);
|
||||
$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>
|
||||
<?php
|
||||
|
@@ -115,6 +115,12 @@
|
||||
<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'] == "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>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir',$BASEDIR);
|
||||
$partial->prepare('baseUrl',$BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
@@ -8,61 +8,27 @@
|
||||
<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 } ?>
|
||||
<div class="label"><?php $LANGMNG->echo('l_runCondition')?></div>
|
||||
<select class="input" name="condOper" id="valueSelector" required>
|
||||
<option value="or"><?php $LANGMNG->echo('l_oneNeedToBeWaild')?></option>
|
||||
<option value="and"><?php $LANGMNG->echo('l_allNeedToBeWalid')?></option>
|
||||
</select>
|
||||
<input type="button" class="button" name="addCondition" value="<?php $LANGMNG->echo('b_add')?>"/>
|
||||
|
||||
|
||||
<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>
|
||||
<input type="submit" class="button" name="modalNext" value="<?php $LANGMNG->echo('b_next')?>"/>
|
||||
</form>
|
||||
</div>
|
||||
|
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>
|
@@ -177,7 +177,12 @@ $partial = new Partial('head');
|
||||
<tbody>
|
||||
<?php foreach ($ROOMS as $key => $room) { ?>
|
||||
<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>
|
||||
<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>
|
||||
|
@@ -7,10 +7,12 @@ class Template{
|
||||
|
||||
function __construct($path = "", $debug = false) {
|
||||
$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;
|
||||
} else {
|
||||
echo '<pre>';
|
||||
echo __DIR__ . '/../app/views/templates/' . $path . '.phtml</br>';
|
||||
echo 'PHTML: Template File ' . $path . ' not found';
|
||||
echo '</pre>';
|
||||
die();
|
||||
@@ -26,9 +28,9 @@ class Template{
|
||||
|
||||
function render() {
|
||||
extract($this->assignedValues);
|
||||
if (!empty('../app/controllers/' . $this->path . 'Controller.php') && file_exists('../app/controllers/' . $this->path . 'Controller.php')) {
|
||||
include('../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(__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} ^(.*)
|
||||
RewriteRule . - [e=HTTP_AUTHORIZATION:%1]
|
||||
|
||||
RewriteCond %{HTTPS} off
|
||||
RewriteCond %{REQUEST_URI} !^/api/update
|
||||
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
||||
#RewriteCond %{HTTPS} off
|
||||
#RewriteCond %{REQUEST_URI} !^/api/update
|
||||
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
||||
|
||||
AddType application/x-httpd-php .php .phtml
|
||||
|
@@ -1,33 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Composer autoload
|
||||
*/
|
||||
|
||||
use Core\Application\Application;
|
||||
use Core\Configuration\Configurations;
|
||||
use Illuminate\Container\Container;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$container = new Container();
|
||||
|
||||
$container->singleton(
|
||||
Configurations::class,
|
||||
Configurations::class
|
||||
);
|
||||
|
||||
/**
|
||||
* Create application & run
|
||||
*/
|
||||
$application = new Application(
|
||||
$container,
|
||||
$container->make(Configurations::class)
|
||||
);
|
||||
$application->run();
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrap v1.0
|
||||
*/
|
||||
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