Final Fixes And Clean Up

This commit is contained in:
JonatanRek 2020-04-28 11:52:14 +02:00
parent a3d911d3ec
commit e0bbc09389
18 changed files with 29 additions and 35 deletions

View File

@ -32,7 +32,7 @@ if (isset($_POST) && !empty($_POST)){
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode); AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode);
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php'))); header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
die(); die();
} else if (isset($_POST['modalFinal']) && $_POST['action'] == "edit") { } else if (isset($_POST['modalFinal']) && $_POST['action'] == "edit") {
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT); $doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
@ -70,7 +70,7 @@ if (isset($_POST) && !empty($_POST)){
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode, (isset ($_POST['automation_id']) ? $_POST['automation_id'] : "")); AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode, (isset ($_POST['automation_id']) ? $_POST['automation_id'] : ""));
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php'))); header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
die(); die();
} }
} }

View File

@ -7,7 +7,7 @@ if (isset($_POST) && !empty($_POST)){
DashboardManager::Add($subDeviceId); DashboardManager::Add($subDeviceId);
} }
} }
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php'))); header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
die(); die();
} }
?> ?>

View File

@ -78,10 +78,10 @@ if (isset($_POST) && !empty($_POST)){
echo '<pre>'; echo '<pre>';
var_dump($POST); var_dump($POST);
echo '</pre>'; echo '</pre>';
echo '<a href="' . BASEDIR . '">CONTINUE</a>'; echo '<a href="' . BASEURL . '">CONTINUE</a>';
die(); die();
} }
header('Location: ' . BASEDIR ); header('Location: ' . BASEURL );
die(); die();
} }
?> ?>

View File

@ -15,7 +15,7 @@ if (
$ota = $userManager->haveOtaEnabled($userName); $ota = $userManager->haveOtaEnabled($userName);
if ($ota == "") { if ($ota == "") {
$landingPage = $userManager->login($userName, $userPassword, $rememberMe); $landingPage = $userManager->login($userName, $userPassword, $rememberMe);
header('Location: ' . BASEDIR . $landingPage); header('Location: ' . BASEURL . $landingPage);
die(); die();
} }
@ -40,7 +40,7 @@ if (
$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) {
$landingPage = $userManager->login($userName, $userPassword, $rememberMe); $landingPage = $userManager->login($userName, $userPassword, $rememberMe);
header('Location: ' . BASEDIR . $landingPage); header('Location: ' . BASEURL . $landingPage);
echo 'OK'; echo 'OK';
} else { } else {
echo 'FAILED'; echo 'FAILED';

View File

@ -3,7 +3,7 @@
if (isset($_POST) && !empty($_POST)){ if (isset($_POST) && !empty($_POST)){
if (isset($_POST['submitFinal']) && $_POST['submitFinal'] != "") { if (isset($_POST['submitFinal']) && $_POST['submitFinal'] != "") {
SceneManager::create($_POST['sceneIcon'], $_POST['sceneName'], json_encode($_POST['devices'])); SceneManager::create($_POST['sceneIcon'], $_POST['sceneName'], json_encode($_POST['devices']));
header('Location: ' . BASEDIR . strtolower(basename(__FILE__, '.php'))); header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
die(); die();
} }
@ -12,7 +12,7 @@ if (isset($_POST) && !empty($_POST)){
echo '<pre>'; echo '<pre>';
var_dump($_POST); var_dump($_POST);
echo '</pre>'; echo '</pre>';
echo '<a href="/' . BASEDIR . strtolower(basename(__FILE__, '.php')).'">CONTINUE</a>'; echo '<a href="/' . BASEURL . strtolower(basename(__FILE__, '.php')).'">CONTINUE</a>';
die(); die();
} }
} }

View File

@ -5,13 +5,13 @@ if (isset($_POST) && !empty($_POST)){
$newPassword = $_POST['newPassword1']; $newPassword = $_POST['newPassword1'];
$newPassword2 = $_POST['newPassword2']; $newPassword2 = $_POST['newPassword2'];
UserManager::changePassword($oldPassword, $newPassword, $newPassword2); UserManager::changePassword($oldPassword, $newPassword, $newPassword2);
header('Location: ' . BASEDIR . 'logout'); header('Location: ' . BASEURL . 'logout');
die(); die();
} else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") { } else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") {
$userName = $_POST['userName']; $userName = $_POST['userName'];
$password = $_POST['userPassword']; $password = $_POST['userPassword'];
UserManager::createUser($userName, $password); UserManager::createUser($userName, $password);
header('Location: ' . BASEDIR . 'setting'); header('Location: ' . BASEURL . 'setting');
die(); die();
} else if (isset($_POST['submitEnableOta']) && $_POST['submitEnableOta'] != "") { } else if (isset($_POST['submitEnableOta']) && $_POST['submitEnableOta'] != "") {
echo $otaCode = $_POST['otaCode']; echo $otaCode = $_POST['otaCode'];
@ -23,7 +23,7 @@ if (isset($_POST) && !empty($_POST)){
if ($checkResult) { if ($checkResult) {
UserManager::setOta($otaCode, $otaSecret); UserManager::setOta($otaCode, $otaSecret);
} }
header('Location: ' . BASEDIR . 'setting'); header('Location: ' . BASEURL . 'setting');
die(); die();
} }
} }

View File

@ -15,14 +15,14 @@ class LogKeeper
$todayFileName = date("Y-m-d").'.log'; $todayFileName = date("Y-m-d").'.log';
$seconds = $days * 86400; $seconds = $days * 86400;
$logFiles = scandir('../app/logs/'); $logFiles = scandir('../logs/');
foreach ($logFiles as $key => $file) { foreach ($logFiles as $key => $file) {
if (in_array($file,array(".","..", ".gitkeep", $todayFileName))) if (in_array($file,array(".","..", ".gitkeep", $todayFileName)))
{ {
continue; continue;
} }
if (filemtime($file) > $seconds) { if (filemtime($file) > $seconds) {
unlink('../app/logs/'.$file); unlink('../logs/'.$file);
} }
} }
} }
@ -35,11 +35,11 @@ class LogManager
function __construct($fileName = "") function __construct($fileName = "")
{ {
if ($fileName == ""){ if ($fileName == ""){
$fileName = '../app/logs/'. date("Y-m-d").'.log'; $fileName = '../logs/'. date("Y-m-d").'.log';
} }
if(!is_dir("../app/logs/")) if(!is_dir("../logs/"))
{ {
mkdir("../app/logs/"); mkdir("../logs/");
} }
$this->logFile = fopen($fileName, "a") or die("Unable to open file!"); $this->logFile = fopen($fileName, "a") or die("Unable to open file!");
} }

View File

@ -8,12 +8,12 @@ class Ajax extends Template
global $lang; global $lang;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR); header('Location: ' . BASEURL);
} }
$is_ajax = 'XMLHttpRequest' == ( $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' ); $is_ajax = 'XMLHttpRequest' == ( $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' );
if (!$is_ajax){ if (!$is_ajax){
header('Location: ' . BASEDIR); header('Location: ' . BASEURL);
} }
if ( if (

View File

@ -1,10 +1,4 @@
<?php <?php
$files = scandir('app/class/');
$files = array_diff($files, array('.', '..'));
foreach($files as $file) {
include_once 'app/class/'. $file;
}
class Automation extends Template class Automation extends Template
{ {
function __construct() function __construct()
@ -13,7 +7,7 @@ class Automation extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$automations = []; $automations = [];

View File

@ -7,7 +7,7 @@ class Dashboard extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$template = new Template('dashboard'); $template = new Template('dashboard');

View File

@ -9,7 +9,7 @@ class Home extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$template = new Template('home'); $template = new Template('home');

View File

@ -9,14 +9,14 @@ class Log extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$template = new Template('log'); $template = new Template('log');
$template->prepare('title', 'Log'); $template->prepare('title', 'Log');
$result = array(); $result = array();
$cdir = scandir('./app/logs/'); $cdir = scandir('../logs/');
foreach ($cdir as $key => $value) foreach ($cdir as $key => $value)
{ {
if (!in_array($value,array(".","..", ".gitkeep"))) if (!in_array($value,array(".","..", ".gitkeep")))

View File

@ -7,7 +7,7 @@ class Login extends Template
global $lang; global $lang;
if ($userManager->isLogin()){ if ($userManager->isLogin()){
header('Location: ' . BASEDIR); header('Location: ' . BASEURL);
} }
$template = new Template('login'); $template = new Template('login');

View File

@ -5,7 +5,7 @@ class Logout extends Template
{ {
global $userManager; global $userManager;
$userManager->logout(); $userManager->logout();
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
die(); die();
} }
} }

View File

@ -9,7 +9,7 @@ class Rooms extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$template = new Template('rooms'); $template = new Template('rooms');

View File

@ -7,7 +7,7 @@ class Scene extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$template = new Template('scene'); $template = new Template('scene');

View File

@ -8,7 +8,7 @@ class Setting extends Template
global $langMng; global $langMng;
if (!$userManager->isLogin()){ if (!$userManager->isLogin()){
header('Location: ' . BASEDIR . 'login'); header('Location: ' . BASEURL . 'login');
} }
$automations = []; $automations = [];