31 Commits

Author SHA1 Message Date
a7380841cf Move concerns to right places 2020-12-15 22:02:02 +01:00
28dd69e3a5 Write concerns 2020-12-15 21:55:39 +01:00
f21293bc01 Remove test code 2020-12-15 21:50:42 +01:00
bf79e9cee7 Introduced configurations and application object (test code) 2020-12-15 21:46:46 +01:00
cf30a1280d Really basic application object. 2020-12-15 21:10:42 +01:00
e11023d1c9 Merge pull request 'feature/composer' (#1) from feature/composer into remastering
Reviewed-on: #1
2020-12-15 16:10:30 +00:00
cfcfefefd8 Bootstrap installed 2020-12-15 16:59:08 +01:00
09d78192b6 Use composer autoload.php instead of custom boostrap.php 2020-12-15 16:56:12 +01:00
158220700b Create composer.json, ignore vendor/ folder. 2020-12-15 16:54:29 +01:00
GamerClassN7
76e036181a Docker submodule fixed 2020-12-15 09:13:23 +01:00
GamerClassN7
39f44c8d03 api tweeks 2020-12-15 09:07:47 +01:00
Haitem
ee0ebff76a first part of plugin setting 2020-12-09 14:30:41 +01:00
42443c8b58 Fix 2020-12-09 12:42:26 +01:00
e95435a707 Better settings Manager 2020-12-09 12:36:57 +01:00
74f6779c63 Fix 2020-12-09 12:28:31 +01:00
181a65a99b Bug Fixes 2020-12-09 12:19:19 +01:00
GamerClassN7
ff2c51d505 Minor Tweeks 2020-12-07 20:21:27 +01:00
GamerClassN7
879a63948f Bugfix 2020-11-30 12:37:44 +01:00
GamerClassN7
52688a5e70 Maybe filter out Error Values 2020-11-18 22:09:02 +01:00
GamerClassN7
3181c9dc72 Sort by Firmware Fix 2020-11-18 21:57:58 +01:00
GamerClassN7
ac43bdaf64 API Device Log Fix 2020-11-18 21:42:48 +01:00
GamerClassN7
e65b046d47 Loggin Form Error Message Fix 2020-11-18 21:42:02 +01:00
GamerClassN7
50a0d3036c basedir Additiona Fix of Automation page 2020-11-18 21:41:45 +01:00
GamerClassN7
fffaf0e237 Record Manager Bugfix 2020-11-18 21:41:11 +01:00
GamerClassN7
e9b8e0a453 Base Url Tweek <html> 2020-11-18 21:40:52 +01:00
GamerClassN7
0e3f571a0d Device Sorting Fix 2020-11-18 21:40:13 +01:00
GamerClassN7
5ad11cbb10 Little Tweeks + Sort Function for array 2020-11-03 16:29:10 +01:00
GamerClassN7
a4cdb250b9 N7 Day Plugin 2020-11-01 21:33:02 +01:00
GamerClassN7
72e6f475d7 Database Backup Plugin Fix + Record Fix 2020-11-01 21:20:05 +01:00
GamerClassN7
4b94ef29c1 Merge branch 'remastering' of https://gitea.steelants.cz/SH/PHP_SMART_HOME_V3 into remastering 2020-10-31 21:37:46 +01:00
GamerClassN7
8a00190850 Minor Tweeks 2020-10-31 21:37:29 +01:00
41 changed files with 674 additions and 211 deletions

3
.gitignore vendored
View File

@@ -15,3 +15,6 @@ _nemazat/css/font-awesome.min.css
app/updater/*.bin app/updater/*.bin
app/logs/*.log app/logs/*.log
backup/*.zip backup/*.zip
vendor/

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule ".docker"]
path = .docker
url = https://github.com/GamerClassN7/Docker-Xamp-Server.git

View File

@@ -5,11 +5,20 @@ 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
); );

View File

@@ -19,6 +19,7 @@ $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->get('/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');
@@ -28,13 +29,17 @@ $router->post('/api/login', 'AuthApi@login');
$router->post('/api/logout', 'AuthApi@logout'); $router->post('/api/logout', 'AuthApi@logout');
$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');
$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');
$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');
//cron //cron
$router->post('/cron/clean', 'CronApi@clean'); $router->post('/cron/clean', 'CronApi@clean');

View File

@@ -70,11 +70,6 @@ class EndpointsApi extends ApiController{
$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
@@ -115,6 +110,7 @@ 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));
$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);
@@ -170,14 +166,15 @@ 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);
if (!empty ($subDeviceLastReord)) {
$subDeviceLastReordValue[$subDeviceData['type']] = $subDeviceLastReord['value']; $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']);
} }
} }
} }
}
$hostname = ""; $hostname = "";
$hostname = strtolower($device['name']); $hostname = strtolower($device['name']);

View File

@@ -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,49 @@ 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]['time']);
$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']) {
$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; $deviceClass = new $cammelCaseClass;
if (!method_exists($deviceClass, 'translate')) { if (method_exists($deviceClass, 'translate')) {
continue;
}
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']); $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') : [];
$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);
} }

View File

@@ -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);
} }

View File

@@ -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'],

View File

@@ -26,6 +26,10 @@ class GoogleHome {
} }
} }
if ($traids < 0){
continue;
}
$tempDevice = [ $tempDevice = [
'id' => (string) $deviceData['device_id'], 'id' => (string) $deviceData['device_id'],
'type' => $actionType, 'type' => $actionType,

View File

@@ -178,4 +178,29 @@ 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){
if ($a[$key] == $b[$key]) return 0;
return ($a[$key] < $b[$key]) ? -1 : 1;
});
} else{
uasort($data, function($a, $b) use ($key){
if ($a[$key] == $b[$key]) return 0;
return ($a[$key] > $b[$key]) ? -1 : 1;
});
}
return $data;
}
} }

View File

@@ -3,10 +3,12 @@ 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 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));
} }

View File

@@ -26,11 +26,12 @@ class RecordManager{
}; };
//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 ($lastRecord['value'] == $value){
return false; return false;
} }
try { try {
$record = [ $record = [
'execuded' => 1, 'execuded' => 1,
@@ -86,7 +87,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 FROM records
WHERE WHERE
subdevice_id = ? subdevice_id = ?
AND AND

View File

@@ -4,14 +4,20 @@ 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) {
return Db::loadAll("SELECT * FROM settings WHERE type=?", array($type));
}
public static function create ($name, $value, $type = '') {
$setting = array ( $setting = array (
'name' => $name, 'name' => $name,
'value' => $value, 'value' => $value,
'type' => $type,
); );
try { try {
Db::add ('settings', $setting); Db::add ('settings', $setting);
@@ -21,13 +27,19 @@ class SettingsManager{
} }
} }
public static function update ($name, $value) { public static function update ($name, $value, $type = '') {
if (self::getByName($name)){
self::create($name, $value, $type);
} else {
try { try {
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name)); Db::edit ('settings', [
'value' => $value
], 'WHERE name = ?', array($name));
} catch(PDOException $error) { } catch(PDOException $error) {
echo $error->getMessage(); echo $error->getMessage();
die(); die();
} }
} }
}
} }
?> ?>

View File

@@ -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));
@@ -72,15 +72,17 @@ class SubDeviceManager
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, sd.subdevice_id, sd.device_id, d.icon, d.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 +93,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;
}
} }

View File

@@ -8,8 +8,8 @@ class DatabaseBackup
$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) {
return 'exception: ' . $e->getMessage(); return 'exception: ' . $e->getMessage();
@@ -18,7 +18,7 @@ class DatabaseBackup
private function scheme() private function scheme()
{ {
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql'; $backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql';
$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;
@@ -26,7 +26,7 @@ class DatabaseBackup
private function data() private function data()
{ {
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql'; $backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql';
$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;
@@ -43,7 +43,9 @@ class DatabaseBackup
$zip = new ZipArchive(); $zip = new ZipArchive();
if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) { if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
foreach ($files as $file) { foreach ($files as $file) {
$zip->addFile($file); $filename = explode('/', $file);
$filename = end($filename);
$zip->addFile($file, $filename);
} }
$zip->close(); $zip->close();
foreach ($files as $file) { foreach ($files as $file) {

42
app/plugins/N7day.php Normal file
View 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);
} 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();
}
}
}

View File

@@ -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);

View File

@@ -3,91 +3,73 @@
class Device extends Template class Device extends Template
{ {
function __construct () { function __construct($sortBy = null, $sortType = null)
$userManager = new UserManager (); {
$deviceManager = new DeviceManager (); $userManager = new UserManager();
$subDeviceManager = new SubDeviceManager (); $deviceManager = new DeviceManager();
$recordManager = new RecordManager (); $subDeviceManager = new SubDeviceManager();
$roomManager = new RoomManager (); $recordManager = new RecordManager();
$langMng = new LanguageManager ('en'); $roomManager = new RoomManager();
$langMng = new LanguageManager('en');
if (!$userManager->isLogin()){ 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"
];
if (isset ($_GET['sortType'])) { $sortIcons = [
switch ($_GET['sortType']) { "ASC" => "&#xf0de",
case "DESC": "DESC" => "&#xf0dd",
$sortType = ""; ];
$sortIcon = "&#xf0dd";
break; $nextSort = [
case "ASC": "ASC" => "DESC",
"DESC" => "ASC",
];
$devices = $deviceManager->getAllDevices();
if (empty($sortBy) && empty($sortType)) {
$sortBy = "id";
$sortType = "DESC"; $sortType = "DESC";
$sortIcon = "&#xf0de";
break;
case "":
unset($_GET["sort"]);
unset($_GET["sortType"]);
header('Location: device');
die();
break;
}
} else {
$sortType = "ASC";
} }
if (!empty ($_GET['sort']) && !empty ($_GET['sortType'])) { $template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
$template->prepare ('sortIcon', array ($_GET['sort'] => $sortIcon));
$actualSort = "devices.device_id";
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'])) {
$_SESSION['sort'] = $_GET['sort'];
}
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");
$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 +78,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();
} }
} }

View File

@@ -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');

View File

@@ -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');

View File

@@ -8,6 +8,7 @@ class Oauth extends Template
$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['redirect_uri'])) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -23,6 +23,7 @@ class Setting extends Template
$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', 'Automation');
$template->prepare('langMng', $langMng); $template->prepare('langMng', $langMng);
@@ -55,7 +56,27 @@ 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;
}
}
}
$plugins = Utilities::sortArrayByKey($plugins, 'slug', "desc");
$template->prepare('pluginsSettings', $plugins);
$template->render(); $template->render();
} }

View File

@@ -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>

View File

@@ -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,15 +26,15 @@
<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>Action <th>Action
<form method="post" action=""> <form method="post" action="">
@@ -45,7 +46,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,12 +88,12 @@
?> ?>
<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();">&#xf0ee;</button> <button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php echo $device['device_id'] ?>').click();">&#xf0ee;</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();">&#xf1f8;</button>-->
<?php endif; ?> <?php endif; ?>
<div type="float: clear;"></div> <div type="float: clear;"></div>
</td> </td>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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">

View File

@@ -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"/>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

10
composer.json Normal file
View File

@@ -0,0 +1,10 @@
{
"autoload": {
"psr-4": {
"Core\\": "core/"
}
},
"require": {
"illuminate/container": "^8.18"
}
}

207
composer.lock generated Normal file
View 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
View File

@@ -0,0 +1,5 @@
<?php
return [
'providers' => []
];

View 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.
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Core\Configuration;
class ConfigurationLoader
{
private const CONFIGURATIONS_DIRECTORY = __DIR__ . DIRECTORY_SEPARATOR
. '..' . DIRECTORY_SEPARATOR
. '..' . DIRECTORY_SEPARATOR . 'config'
. DIRECTORY_SEPARATOR;
public function load(): array
{
return [];
}
/**
* Concerns
* -> Loading configuration files
* - Scan directory for files.
* - Filtering none config / php files.
* - Creating assoc array.
*/
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Core\Configuration;
/**
* Class Configurations
* @package Core\Configuration
* @author Romano Schoonheim https://github.com/romano1996
*/
class Configurations
{
/** @var array */
private $configurations;
public function __construct(ConfigurationLoader $configurationLoader)
{
// Concern: Storing assoc array to this object.
$this->configurations = $configurationLoader->load();
}
public function get(string $path)
{
// Concern: Accessing configurations based on "paths" application.something For example.
}
}

View File

@@ -1,3 +1,33 @@
<?php <?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'; require_once __DIR__ . '/../app/Bootstrap.php';