project structure refactoring
This commit is contained in:
77
app/controllers/automation.php
Normal file
77
app/controllers/automation.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['modalFinal']) && $_POST['action'] == "add") {
|
||||
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
|
||||
|
||||
$value = $_POST['atSelector'];
|
||||
if ($_POST['atSelector'] == 'time'){
|
||||
$value = $_POST['atSelectorValue'];
|
||||
} else if ($_POST['atSelector'] == 'atDeviceValue') {
|
||||
$value = json_decode($_POST['atSelectorValue']);
|
||||
} else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') {
|
||||
$value = UserManager::getUserData('user_id');
|
||||
}
|
||||
|
||||
|
||||
$ifCode = json_encode([
|
||||
"type" => $_POST['atSelector'],
|
||||
"value" => $value,
|
||||
], JSON_PRETTY_PRINT);
|
||||
$onDays = $_POST['atDays'];
|
||||
|
||||
//Debug
|
||||
// if (DEBUGMOD == 1) {
|
||||
// echo '<pre>';
|
||||
// echo $permissionsInJson;
|
||||
// echo $deviceId;
|
||||
// var_dump(json_decode ($permissionsInJson));
|
||||
// echo '</pre>';
|
||||
// echo '<a href="' . BASEDIR .'">CONTINUE</a>';
|
||||
// die();
|
||||
// }
|
||||
|
||||
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode);
|
||||
|
||||
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php')));
|
||||
die();
|
||||
} else if (isset($_POST['modalFinal']) && $_POST['action'] == "edit") {
|
||||
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
|
||||
|
||||
if (isset ($_POST['atDeviceValue'])) {
|
||||
$subDeviceId = $_POST['atDeviceValue'];
|
||||
$subDeviceValue = $_POST['atDeviceValueInt'];
|
||||
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$subDeviceMaster = SubDeviceManager::getSubDeviceMaster($subDeviceId,$subDevice['type']);
|
||||
|
||||
$device = [
|
||||
'deviceID' => $subDeviceMaster['device_id'],
|
||||
'type'=> $subDevice['type'],
|
||||
'value'=> $subDeviceValue,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$value = $_POST['atSelector'];
|
||||
if (isset($_POST['atTime'])){
|
||||
$value = $_POST['atTime'];
|
||||
} else if (isset($_POST['atDeviceValue'])) {
|
||||
$value = $device;
|
||||
} else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') {
|
||||
//TODO: opravit edit aby vkládal id původního uživatele
|
||||
$value = UserManager::getUserData('user_id');
|
||||
}
|
||||
|
||||
$value = (isset($_POST['atTime']) ? $_POST['atTime'] : (isset($_POST['atDeviceValue']) ? $device : $_POST['atSelector']));
|
||||
$ifCode = json_encode([
|
||||
"type" => $_POST['atSelector'],
|
||||
"value" => $value,
|
||||
], JSON_PRETTY_PRINT);
|
||||
$onDays = ($_POST['day'] != '' ? json_encode($_POST['day']) : '');
|
||||
|
||||
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode, (isset ($_POST['automation_id']) ? $_POST['automation_id'] : ""));
|
||||
|
||||
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php')));
|
||||
die();
|
||||
}
|
||||
}
|
||||
?>
|
13
app/controllers/dashboard.php
Normal file
13
app/controllers/dashboard.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
|
||||
if (isset($_POST['modalFinal']) && $_POST['modalFinal'] != "") {
|
||||
$subDeviceIds = $_POST['devices'];
|
||||
foreach ($subDeviceIds as $subDeviceId) {
|
||||
DashboardManager::Add($subDeviceId);
|
||||
}
|
||||
}
|
||||
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php')));
|
||||
die();
|
||||
}
|
||||
?>
|
87
app/controllers/home.php
Normal file
87
app/controllers/home.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['saveDevice']) && $_POST['saveDevice'] != "") {
|
||||
$deviceId = $_POST['deviceId'];
|
||||
$deviceName = $_POST['deviceName'];
|
||||
$deviceIcon = $_POST['deviceIcon'];
|
||||
$sleepTime = 0;
|
||||
if (isset($_FILES['deviceFirmware']) && isset($_FILES['deviceFirmware']['tmp_name']) && $_FILES['deviceFirmware']['tmp_name'] != "") {
|
||||
$file = $_FILES['deviceFirmware'];
|
||||
$deviceMac = DeviceManager::getDeviceById($deviceId)['mac'];
|
||||
$fileName = (isset ($deviceMac) && $deviceMac != "" ? str_replace(":", "", $deviceMac) . ".bin" : "");
|
||||
if ($fileName != "" && file_exists("./app/updater/" . $fileName)) {
|
||||
unlink("./app/updater/" . $fileName);
|
||||
}
|
||||
if ($fileName != "") {
|
||||
copy($file['tmp_name'], "./app/updater/" . $fileName);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['sleepTime'])) {
|
||||
$sleepTime = $_POST['sleepTime'];
|
||||
}
|
||||
//TODO: if device isnt on off
|
||||
$permissionsInJson = json_encode([
|
||||
(int) $_POST['permissionOwner'],
|
||||
(int) $_POST['permissionOther'],
|
||||
]);
|
||||
|
||||
|
||||
$deviceOwnerUserId = $_POST['deviceOwnerUserId'];
|
||||
$deviceOwnerRoomId = $_POST['deviceOwnerId'];
|
||||
|
||||
try {
|
||||
$args = array(
|
||||
'owner' => $deviceOwnerUserId,
|
||||
'name' => $deviceName,
|
||||
'icon' => $deviceIcon,
|
||||
'permission' => $permissionsInJson,
|
||||
'sleep_time' => $sleepTime,
|
||||
'room_id' => $deviceOwnerRoomId,
|
||||
);
|
||||
DeviceManager::edit($deviceId, $args);
|
||||
} catch (\Exception $e) {
|
||||
echo $e->message();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Debug
|
||||
if (DEBUGMOD == 1) {
|
||||
echo '<pre>';
|
||||
echo $permissionsInJson;
|
||||
echo $deviceId;
|
||||
var_dump(json_decode ($permissionsInJson));
|
||||
echo '</pre>';
|
||||
echo '<a href="' . BASEDIR .'">CONTINUE</a>';
|
||||
die();
|
||||
}
|
||||
} else if (isset($_POST['approveDevice'])) {
|
||||
$deviceId = $_POST['deviceId'];
|
||||
$args = array(
|
||||
'approved' => 1,
|
||||
);
|
||||
DeviceManager::edit($deviceId, $args);
|
||||
} else if (isset($_POST['disableDevice'])) {
|
||||
$deviceId = $_POST['deviceId'];
|
||||
$args = array(
|
||||
'approved' => 2,
|
||||
);
|
||||
DeviceManager::edit($deviceId, $args);
|
||||
}
|
||||
|
||||
//Debug
|
||||
if (DEBUGMOD == 1) {
|
||||
echo '<pre>';
|
||||
var_dump($POST);
|
||||
echo '</pre>';
|
||||
echo '<a href="' . BASEDIR . '">CONTINUE</a>';
|
||||
die();
|
||||
}
|
||||
header('Location: ' . BASEDIR );
|
||||
die();
|
||||
}
|
||||
?>
|
51
app/controllers/login.php
Normal file
51
app/controllers/login.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
global $userManager;
|
||||
|
||||
|
||||
if (
|
||||
isset($_POST['username']) &&
|
||||
$_POST['username'] != '' &&
|
||||
isset($_POST['password']) &&
|
||||
$_POST['password'] != ''
|
||||
){
|
||||
$ota = false;
|
||||
$userName = $_POST['username'];
|
||||
$userPassword = $_POST['password'];
|
||||
$rememberMe = (isset ($_POST['remember']) ? $_POST['remember'] : "");
|
||||
$ota = $userManager->haveOtaEnabled($userName);
|
||||
if ($ota == "") {
|
||||
$landingPage = $userManager->login($userName, $userPassword, $rememberMe);
|
||||
header('Location: ' . BASEDIR . $landingPage);
|
||||
die();
|
||||
}
|
||||
|
||||
$_SESSION['USERNAME'] = $userName;
|
||||
$_SESSION['PASSWORD'] = $userPassword;
|
||||
$_SESSION['REMEMBER'] = $rememberMe;
|
||||
$_SESSION['OTA'] = $ota;
|
||||
} else if (
|
||||
isset($_POST['otaCode']) &&
|
||||
$_POST['otaCode'] != ''
|
||||
) {
|
||||
|
||||
$otaCode = $_POST['otaCode'];
|
||||
$otaSecret = $_POST['otaSecret'];
|
||||
|
||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||
$ota = $_SESSION['OTA'];
|
||||
$userName = $_SESSION['USERNAME'];
|
||||
$userPassword = $_SESSION['PASSWORD'];
|
||||
$rememberMe = $_SESSION['REMEMBER'];
|
||||
unset($_SESSION['OTA']);
|
||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
$landingPage = $userManager->login($userName, $userPassword, $rememberMe);
|
||||
header('Location: ' . BASEDIR . $landingPage);
|
||||
echo 'OK';
|
||||
} else {
|
||||
echo 'FAILED';
|
||||
}
|
||||
//TODO: upravi a ověřit jeslti ja zabezpečené
|
||||
//TODO:
|
||||
die();
|
||||
}
|
18
app/controllers/scene.php
Normal file
18
app/controllers/scene.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['submitFinal']) && $_POST['submitFinal'] != "") {
|
||||
SceneManager::create($_POST['sceneIcon'], $_POST['sceneName'], json_encode($_POST['devices']));
|
||||
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php')));
|
||||
die();
|
||||
}
|
||||
|
||||
//Debug
|
||||
if (DEBUGMOD == 1) {
|
||||
echo '<pre>';
|
||||
var_dump($_POST);
|
||||
echo '</pre>';
|
||||
echo '<a href="/' . BASEDIR . strtolower(basename(__FILE__, '.php')).'">CONTINUE</a>';
|
||||
die();
|
||||
}
|
||||
}
|
29
app/controllers/setting.php
Normal file
29
app/controllers/setting.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
|
||||
$oldPassword = $_POST['oldPassword'];
|
||||
$newPassword = $_POST['newPassword1'];
|
||||
$newPassword2 = $_POST['newPassword2'];
|
||||
UserManager::changePassword($oldPassword, $newPassword, $newPassword2);
|
||||
header('Location: ' . BASEDIR . 'logout');
|
||||
die();
|
||||
} else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") {
|
||||
$userName = $_POST['userName'];
|
||||
$password = $_POST['userPassword'];
|
||||
UserManager::createUser($userName, $password);
|
||||
header('Location: ' . BASEDIR . 'setting');
|
||||
die();
|
||||
} else if (isset($_POST['submitEnableOta']) && $_POST['submitEnableOta'] != "") {
|
||||
echo $otaCode = $_POST['otaCode'];
|
||||
echo $otaSecret = $_POST['otaSecret'];
|
||||
|
||||
|
||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
UserManager::setOta($otaCode, $otaSecret);
|
||||
}
|
||||
header('Location: ' . BASEDIR . 'setting');
|
||||
die();
|
||||
}
|
||||
}
|
17
app/controllers/settings.php
Normal file
17
app/controllers/settings.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
|
||||
$oldPassword = $_POST['oldPassword'];
|
||||
$newPassword = $_POST['newPassword1'];
|
||||
$newPassword2 = $_POST['newPassword2'];
|
||||
UserManager::changePassword($oldPassword, $newPassword, $newPassword2);
|
||||
header('Location: ' . BASEDIR . 'logout');
|
||||
die();
|
||||
} else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") {
|
||||
$userName = $_POST['userName'];
|
||||
$password = $_POST['userPassword'];
|
||||
UserManager::createUser($userName, $password);
|
||||
header('Location: ' . BASEDIR . 'setting');
|
||||
die();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user