Compare commits
31 Commits
38cc436f4d
...
feature/co
Author | SHA1 | Date | |
---|---|---|---|
a7380841cf | |||
28dd69e3a5 | |||
f21293bc01 | |||
bf79e9cee7 | |||
cf30a1280d | |||
e11023d1c9 | |||
cfcfefefd8 | |||
09d78192b6 | |||
158220700b | |||
|
76e036181a | ||
|
39f44c8d03 | ||
|
ee0ebff76a | ||
42443c8b58 | |||
e95435a707 | |||
74f6779c63 | |||
181a65a99b | |||
|
ff2c51d505 | ||
|
879a63948f | ||
|
52688a5e70 | ||
|
3181c9dc72 | ||
|
ac43bdaf64 | ||
|
e65b046d47 | ||
|
50a0d3036c | ||
|
fffaf0e237 | ||
|
e9b8e0a453 | ||
|
0e3f571a0d | ||
|
5ad11cbb10 | ||
|
a4cdb250b9 | ||
|
72e6f475d7 | ||
|
4b94ef29c1 | ||
|
8a00190850 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,3 +15,6 @@ _nemazat/css/font-awesome.min.css
|
||||
app/updater/*.bin
|
||||
app/logs/*.log
|
||||
backup/*.zip
|
||||
|
||||
|
||||
vendor/
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule ".docker"]
|
||||
path = .docker
|
||||
url = https://github.com/GamerClassN7/Docker-Xamp-Server.git
|
@@ -5,11 +5,20 @@ ini_set( 'display_errors','1');
|
||||
|
||||
//setup
|
||||
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(
|
||||
1209600,
|
||||
$urlSes,
|
||||
str_replace("/var/www/", "", $_SERVER['DOCUMENT_ROOT']),
|
||||
$domain,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
@@ -19,6 +19,7 @@ $router->any('/logout', 'Logout');
|
||||
$router->any('/automation', 'Automation');
|
||||
$router->any('/setting', 'Setting');
|
||||
$router->any('/device', 'Device');
|
||||
$router->get('/device/{sortBy}/{sortType}', 'Device');
|
||||
$router->any('/plugins', 'Plugins');
|
||||
$router->any('/ajax', 'Ajax');
|
||||
$router->any('/oauth', 'Oauth');
|
||||
@@ -28,13 +29,17 @@ $router->post('/api/login', 'AuthApi@login');
|
||||
$router->post('/api/logout', 'AuthApi@logout');
|
||||
$router->get('/api/rooms', 'RoomsApi@default');
|
||||
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
||||
|
||||
$router->get('/api/devices', 'DevicesApi@default');
|
||||
$router->get('/api/plugins', 'PluginsApi@default');
|
||||
$router->get('/api/users', 'UsersApi@default');
|
||||
$router->get('/api/server', 'ServerApi@default');
|
||||
$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');
|
||||
|
||||
|
||||
//cron
|
||||
$router->post('/cron/clean', 'CronApi@clean');
|
||||
|
@@ -70,11 +70,6 @@ class EndpointsApi extends ApiController{
|
||||
$data['firmware_hash'] = $obj['settings']["firmware_hash"];
|
||||
}
|
||||
DeviceManager::editByToken($obj['token'], $data);
|
||||
$this->response([
|
||||
'state' => 'succes',
|
||||
'command' => $command,
|
||||
], 200);
|
||||
die();
|
||||
}
|
||||
|
||||
//Log Data Save
|
||||
@@ -115,6 +110,7 @@ class EndpointsApi extends ApiController{
|
||||
if (!SubDeviceManager::getSubDeviceByMaster($device['device_id'], $key)) {
|
||||
SubDeviceManager::create($device['device_id'], $key, UNITS[$key]);
|
||||
}
|
||||
|
||||
$subDeviceLastReordValue[$key] = $value['value'];
|
||||
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);
|
||||
@@ -170,14 +166,15 @@ class EndpointsApi extends ApiController{
|
||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||
$subDeviceId = $subDeviceData['subdevice_id'];
|
||||
$subDeviceLastReord = RecordManager::getLastRecord($subDeviceId);
|
||||
if (!empty ($subDeviceLastReord)) {
|
||||
$subDeviceLastReordValue[$subDeviceData['type']] = $subDeviceLastReord['value'];
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hostname = "";
|
||||
$hostname = strtolower($device['name']);
|
||||
|
@@ -3,8 +3,7 @@
|
||||
class RoomsApi extends ApiController
|
||||
{
|
||||
|
||||
public function
|
||||
default()
|
||||
public function default()
|
||||
{
|
||||
//$this->requireAuth();
|
||||
$response = [];
|
||||
@@ -19,38 +18,49 @@ class RoomsApi extends ApiController
|
||||
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
||||
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
||||
foreach ($subDevice as $key => $value) {
|
||||
//Type Handling
|
||||
$type = null;
|
||||
if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
|
||||
$type = $subDevicesData[$subDeviceKey][$key]['type'];
|
||||
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
|
||||
$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 = "";
|
||||
foreach (explode('-', $type) as $word) {
|
||||
$cammelCaseClass .= ucfirst($word);
|
||||
}
|
||||
if (!class_exists($cammelCaseClass)) {
|
||||
continue;
|
||||
}
|
||||
if (class_exists($cammelCaseClass)) {
|
||||
$deviceClass = new $cammelCaseClass;
|
||||
if (!method_exists($deviceClass, 'translate')) {
|
||||
continue;
|
||||
}
|
||||
if (method_exists($deviceClass, 'translate')) {
|
||||
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($roomsData as $roomKey => $roomData) {
|
||||
if ($roomData['device_count'] == 0) continue;
|
||||
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : [];
|
||||
$response[] = [
|
||||
'room_id' => $roomData['room_id'],
|
||||
'name' => $roomData['name'],
|
||||
'widgets' => isset($subDevicesData[$roomData['room_id']]) ? $subDevicesData[$roomData['room_id']] : [],
|
||||
'widgets' => $subDevicesSorted,
|
||||
];
|
||||
}
|
||||
|
||||
$this->response($response);
|
||||
}
|
||||
|
||||
|
@@ -12,16 +12,24 @@ class ServerApi extends ApiController {
|
||||
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(){
|
||||
//$this->requireAuth();
|
||||
$response = [
|
||||
"cpu_load" => sys_getloadavg()[0],
|
||||
"cpu_load" => $this->getProcessorUsage(),
|
||||
"uptime" => shell_exec('uptime -p'),
|
||||
"ramFree" => $this->getSystemMemInfo()["MemFree"],
|
||||
"ramTotal" => $this->getSystemMemInfo()["MemTotal"],
|
||||
"diskFree" => disk_free_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);
|
||||
}
|
||||
|
@@ -32,38 +32,37 @@ class WidgetApi extends ApiController
|
||||
$this->response(['value' => $response]);
|
||||
}
|
||||
|
||||
public function detail($subDeviceId)
|
||||
public function detail($subDeviceId, $period = "day")
|
||||
{
|
||||
//$this->requireAuth();
|
||||
$response = null;
|
||||
$connectionError = true;
|
||||
|
||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
|
||||
$groupBy = [
|
||||
"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 ?
|
||||
$events = RecordManager::getAllRecordForGraph($subDeviceId);
|
||||
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
||||
if ( count($events) == 0){
|
||||
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']);
|
||||
$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 = [];
|
||||
$values = [];
|
||||
foreach ($events as $key => $event) {
|
||||
@@ -80,6 +79,9 @@ class WidgetApi extends ApiController
|
||||
}
|
||||
|
||||
$response = [
|
||||
'room_id' => $subDeviceData['room_id'],
|
||||
'device_id' => $subDeviceData['device_id'],
|
||||
'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
|
||||
'records' => $events,
|
||||
'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
|
||||
if (isset(RANGES[$subDeviceData['type']])){
|
||||
$response['graph']['options']['options']['scales']['yAxes'] = [[
|
||||
$response['graph']['options']['scales']['yAxes'] = [[
|
||||
'ticks' => [
|
||||
'min' => RANGES[$subDeviceData['type']]['min'],
|
||||
'max' => RANGES[$subDeviceData['type']]['max'],
|
||||
|
@@ -26,6 +26,10 @@ class GoogleHome {
|
||||
}
|
||||
}
|
||||
|
||||
if ($traids < 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
$tempDevice = [
|
||||
'id' => (string) $deviceData['device_id'],
|
||||
'type' => $actionType,
|
||||
|
@@ -178,4 +178,29 @@ class Utilities
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,12 @@ class DeviceManager{
|
||||
public static $devices;
|
||||
|
||||
static function getAllDevices () {
|
||||
return Db::loadAll ("SELECT devices.* FROM devices
|
||||
return Db::loadAll ("SELECT * FROM devices
|
||||
WHERE approved != ?", Array(2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static function getAllDevicesInRoom ($roomId = "") {
|
||||
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
|
||||
}
|
||||
|
@@ -26,11 +26,12 @@ class RecordManager{
|
||||
};
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$record = [
|
||||
'execuded' => 1,
|
||||
@@ -86,7 +87,7 @@ class RecordManager{
|
||||
$dateTime = $dateTime->modify($periodLocal);
|
||||
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
||||
$groupBy = strtoupper($groupBy).'(time)';
|
||||
$sql = 'SELECT value, time FROM records
|
||||
$sql = 'SELECT value, time, execuded FROM records
|
||||
WHERE
|
||||
subdevice_id = ?
|
||||
AND
|
||||
|
@@ -4,14 +4,20 @@ class SettingsManager{
|
||||
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));
|
||||
}
|
||||
|
||||
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 (
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
'type' => $type,
|
||||
);
|
||||
try {
|
||||
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 {
|
||||
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name));
|
||||
Db::edit ('settings', [
|
||||
'value' => $value
|
||||
], 'WHERE name = ?', array($name));
|
||||
} catch(PDOException $error) {
|
||||
echo $error->getMessage();
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -5,7 +5,7 @@ class SubDeviceManager
|
||||
|
||||
public static function getAllSubDevices($deviceId = null)
|
||||
{
|
||||
if ($deviceId == null){
|
||||
if ($deviceId == null) {
|
||||
return Db::loadAll("SELECT * FROM subdevices");
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
public static function getSubdevicesByRoomIds($roomIds = NULL) {
|
||||
if(empty($roomIds)) return NULL;
|
||||
public static function getSubdevicesByRoomIds($roomIds = NULL)
|
||||
{
|
||||
if (empty($roomIds)) return NULL;
|
||||
|
||||
//TODO: @Patrik Check line 89
|
||||
$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 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 (
|
||||
SELECT MAX(record_id)
|
||||
FROM records
|
||||
@@ -91,10 +93,21 @@ class SubDeviceManager
|
||||
", $roomIds);
|
||||
|
||||
$ret = [];
|
||||
foreach($rows as $row){
|
||||
foreach ($rows as $row) {
|
||||
$ret[$row['room_id']][] = $row;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -8,8 +8,8 @@ class DatabaseBackup
|
||||
$backupWorker = new DatabaseBackup;
|
||||
$filenames[] = $backupWorker->scheme(); //Backup Database scheme
|
||||
$filenames[] = $backupWorker->data(); //Backup Database Data
|
||||
$filenames[] = $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'; //Backup Configuration File
|
||||
$backupWorker->compress($_SERVER['DOCUMENT_ROOT'] . BASEDIR . '/backup/' . date("Y-m-d", time()) . '.zip', $filenames);
|
||||
//$filenames[] = $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'; //Backup Configuration File
|
||||
$backupWorker->compress($_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'backup/' . date("Y-m-d", time()) . '.zip', $filenames);
|
||||
return 'sucessful';
|
||||
} catch (Exception $e) {
|
||||
return 'exception: ' . $e->getMessage();
|
||||
@@ -18,7 +18,7 @@ class DatabaseBackup
|
||||
|
||||
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";
|
||||
$this->executeCommand($command);
|
||||
return $backupfile;
|
||||
@@ -26,7 +26,7 @@ class DatabaseBackup
|
||||
|
||||
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";
|
||||
$this->executeCommand($command);
|
||||
return $backupfile;
|
||||
@@ -43,7 +43,9 @@ class DatabaseBackup
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
||||
foreach ($files as $file) {
|
||||
$zip->addFile($file);
|
||||
$filename = explode('/', $file);
|
||||
$filename = end($filename);
|
||||
$zip->addFile($file, $filename);
|
||||
}
|
||||
$zip->close();
|
||||
foreach ($files as $file) {
|
||||
|
42
app/plugins/N7day.php
Normal file
42
app/plugins/N7day.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
class N7Day extends VirtualDeviceManager
|
||||
{
|
||||
private $virtual_device_name = "N7 Day";
|
||||
private $device_type = "day-count";
|
||||
private $subdevice_type = "day-count";
|
||||
|
||||
|
||||
function make()
|
||||
{
|
||||
try {
|
||||
if (DeviceManager::registeret($this->virtual_device_name)) {
|
||||
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
||||
if (!$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, $this->subdevice_type)) {
|
||||
SubDeviceManager::create($deviceId, $this->subdevice_type, 'days');
|
||||
sleep(1);
|
||||
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
||||
}
|
||||
|
||||
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
||||
|
||||
//Days Until N7 day
|
||||
$now = time(); // or your date as well
|
||||
if (strtotime(date("Y") . "-11-07") < $now){
|
||||
$your_date = strtotime((date("Y") + 1) . "-11-07");
|
||||
} else {
|
||||
$your_date = strtotime(date("Y") . "-11-07");
|
||||
}
|
||||
$datediff = $now - $your_date;
|
||||
$daysUntilN7Day = round($datediff / (60 * 60 * 24));
|
||||
|
||||
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -53,6 +53,7 @@ class Automation extends Template
|
||||
|
||||
$template = new Template('automation');
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('title', 'Automation');
|
||||
$template->prepare('langMng', $langMng);
|
||||
|
@@ -3,91 +3,73 @@
|
||||
|
||||
class Device extends Template
|
||||
{
|
||||
function __construct () {
|
||||
$userManager = new UserManager ();
|
||||
$deviceManager = new DeviceManager ();
|
||||
$subDeviceManager = new SubDeviceManager ();
|
||||
$recordManager = new RecordManager ();
|
||||
$roomManager = new RoomManager ();
|
||||
$langMng = new LanguageManager ('en');
|
||||
function __construct($sortBy = null, $sortType = null)
|
||||
{
|
||||
$userManager = new UserManager();
|
||||
$deviceManager = new DeviceManager();
|
||||
$subDeviceManager = new SubDeviceManager();
|
||||
$recordManager = new RecordManager();
|
||||
$roomManager = new RoomManager();
|
||||
$langMng = new LanguageManager('en');
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
if (!$userManager->isLogin()) {
|
||||
header('Location: ' . BASEURL . 'login');
|
||||
}
|
||||
|
||||
$template = new Template ('device');
|
||||
$template->prepare ('title', $langMng->get ("m_devices"));
|
||||
$template = new Template('device');
|
||||
$template->prepare('title', $langMng->get("m_devices"));
|
||||
|
||||
if (!empty ($_GET['sort']) && !empty ($_SESSION['sort']) && $_SESSION['sort'] != $_GET['sort']) {
|
||||
unset($_SESSION['sort']);
|
||||
header('Location: device?sort=' . $_GET["sort"] . "&sortType=ASC");
|
||||
die();
|
||||
}
|
||||
$sortWordBook = [
|
||||
"id" => "device_id",
|
||||
"name" => "name",
|
||||
"room" => "room_id",
|
||||
"ip" => "ip_address",
|
||||
"mac" => "mac",
|
||||
"token" => "token",
|
||||
"signal" => "signal",
|
||||
"firmware" => "firmware_hash",
|
||||
"icon" => "icon"
|
||||
];
|
||||
|
||||
if (isset ($_GET['sortType'])) {
|
||||
switch ($_GET['sortType']) {
|
||||
case "DESC":
|
||||
$sortType = "";
|
||||
$sortIcon = "";
|
||||
break;
|
||||
case "ASC":
|
||||
$sortIcons = [
|
||||
"ASC" => "",
|
||||
"DESC" => "",
|
||||
];
|
||||
|
||||
$nextSort = [
|
||||
"ASC" => "DESC",
|
||||
"DESC" => "ASC",
|
||||
];
|
||||
|
||||
$devices = $deviceManager->getAllDevices();
|
||||
|
||||
if (empty($sortBy) && empty($sortType)) {
|
||||
$sortBy = "id";
|
||||
$sortType = "DESC";
|
||||
$sortIcon = "";
|
||||
break;
|
||||
case "":
|
||||
unset($_GET["sort"]);
|
||||
unset($_GET["sortType"]);
|
||||
header('Location: device');
|
||||
die();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$sortType = "ASC";
|
||||
}
|
||||
|
||||
if (!empty ($_GET['sort']) && !empty ($_GET['sortType'])) {
|
||||
$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'];
|
||||
}
|
||||
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
|
||||
|
||||
foreach ($devices as $key => $device) {
|
||||
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType ($device['device_id'], "wifi");
|
||||
if (!empty ($subdevice['subdevice_id'])) {
|
||||
//Signal Stenght
|
||||
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi");
|
||||
$devices[$key]['signal'] = "";
|
||||
if (!empty($subdevice['subdevice_id'])) {
|
||||
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
|
||||
if (!empty ($record)) {
|
||||
if (!empty($record)) {
|
||||
$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";
|
||||
if (file_exists ($localBinary)) {
|
||||
$hash = md5_file ($localBinary);
|
||||
$localBinary = "../updater/" . str_replace(':', '', $device['mac']) . ".bin";
|
||||
$devices[$key]['firmware_hash'] = "";
|
||||
if (file_exists($localBinary)) {
|
||||
$hash = md5_file($localBinary);
|
||||
if ($hash == $device['firmware_hash']) {
|
||||
$devices[$key]['firmware_hash'] = "true";
|
||||
} else {
|
||||
@@ -96,43 +78,22 @@ class Device extends Template
|
||||
} else {
|
||||
$devices[$key]['firmware_hash'] = "false";
|
||||
}
|
||||
if (empty ($device['mac'])) {
|
||||
$devices[$key]['firmware_hash'] = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "firmware") {
|
||||
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'];
|
||||
});
|
||||
}
|
||||
}
|
||||
$devices = Utilities::sortArrayByKey($devices, $sortWordBook[$sortBy], strtolower($sortType));
|
||||
|
||||
$rooms = $roomManager->getAllRooms();
|
||||
|
||||
$template->prepare ('baseDir', BASEDIR);
|
||||
$template->prepare ('debugMod', DEBUGMOD);
|
||||
$template->prepare ('logToLiveTime', LOGTIMOUT);
|
||||
$template->prepare ('rooms', $rooms);
|
||||
$template->prepare ('sortType', $sortType);
|
||||
$template->prepare ('devices', $devices);
|
||||
$template->prepare ('langMng', $langMng);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
|
||||
$template->render ();
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('logToLiveTime', LOGTIMOUT);
|
||||
$template->prepare('rooms', $rooms);
|
||||
$template->prepare('sortType', $nextSort[$sortType]);
|
||||
$template->prepare('devices', $devices);
|
||||
$template->prepare('langMng', $langMng);
|
||||
|
||||
$template->render();
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ class Log extends Template
|
||||
$result = $this->logFinder ('../logs/', $result);
|
||||
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('logToLiveTime', LOGTIMOUT);
|
||||
$template->prepare('title', 'Logy');
|
||||
|
@@ -12,6 +12,7 @@ class Login extends Template
|
||||
|
||||
$template = new Template('login');
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('title', 'Home');
|
||||
|
||||
|
||||
|
@@ -8,6 +8,7 @@ class Oauth extends Template
|
||||
|
||||
$template = new Template('oauth');
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('title', 'Simple Home - Oauth');
|
||||
|
||||
if (isset($_GET['redirect_uri'])) {
|
||||
|
@@ -21,10 +21,11 @@ class Plugins extends Template
|
||||
$plugins[$key]['status'] = $status;
|
||||
}
|
||||
|
||||
sort($plugins);
|
||||
$plugins = Utilities::sortArrayByKey($plugins, 'status', "desc");
|
||||
|
||||
$template = new Template('plugins');
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('title', 'Plugins');
|
||||
$template->prepare('langMng', $langMng);
|
||||
|
@@ -36,6 +36,7 @@ class Server extends Template
|
||||
$template->prepare('title', 'Server');
|
||||
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('langMng', $langMng);
|
||||
|
||||
|
@@ -23,6 +23,7 @@ class Setting extends Template
|
||||
|
||||
$template = new Template('setting');
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('baseUrl', BASEURL);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('title', 'Automation');
|
||||
$template->prepare('langMng', $langMng);
|
||||
@@ -55,7 +56,27 @@ class Setting extends Template
|
||||
$rooms = RoomManager::getAllRooms();
|
||||
$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();
|
||||
}
|
||||
|
@@ -2,8 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->prepare('baseUrl', $BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->prepare('baseUrl', $BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
@@ -25,15 +26,15 @@
|
||||
<div class="col-md-9 main-body">
|
||||
<table class="table is-fluid">
|
||||
<tr>
|
||||
<th><a href="device">#</a></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?sort=room&sortType=<?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?sort=firmware&sortType=<?php echo $SORTTYPE; ?>">Firmware</a><i class="fa"><?php echo (!empty($SORTICON['firmware']) ? $SORTICON['firmware'] : ""); ?></i></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/name/<?php echo $SORTTYPE; ?>">Name</a><i class="fa"><?php echo (!empty($SORTICON['name']) ? $SORTICON['name'] : ""); ?></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/signal/<?php echo $SORTTYPE; ?>">Signal</a><i class="fa"><?php echo (!empty($SORTICON['signal']) ? $SORTICON['signal'] : ""); ?></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>
|
||||
<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?sort=mac&sortType=<?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/ip/<?php echo $SORTTYPE; ?>">IP Address</a><i class="fa"><?php echo (!empty($SORTICON['ip']) ? $SORTICON['ip'] : ""); ?></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/token/<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i>
|
||||
</th>
|
||||
<th>Action
|
||||
<form method="post" action="">
|
||||
@@ -45,7 +46,7 @@
|
||||
<?php if (!empty($DEVICES)) : ?>
|
||||
<?php foreach ($DEVICES as $device) : ?>
|
||||
<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>
|
||||
<form method="post" action="">
|
||||
<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>
|
||||
<?php echo $device['firmware_hash'] ?>
|
||||
<button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php echo $device['device_id'] ?>').click();"></button>
|
||||
<form style="display: none;" method="POST" action="" enctype="multipart/form-data">
|
||||
<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="">
|
||||
</form>
|
||||
<!--<button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php //echo $device['device_id'] ?>').click();"></button>-->
|
||||
<?php endif; ?>
|
||||
<div type="float: clear;"></div>
|
||||
</td>
|
||||
|
@@ -2,8 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->prepare('baseUrl', $BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
@@ -4,6 +4,8 @@
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir',$BASEDIR);
|
||||
$partial->prepare('baseUrl',$BASEURL);
|
||||
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<link rel="manifest" href="manifest.json">
|
||||
|
||||
<base href="<?php echo $BASEURL; ?>">
|
||||
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="application-name" content="Home">
|
||||
@@ -18,6 +20,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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/font-awesome.min.css">
|
||||
<link rel="stylesheet" href="<?php echo $BASEDIR; ?>css/modal.css">
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<input class="" type="checkbox" name="remember" value="true"/>
|
||||
</div>
|
||||
<?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 endif; ?>
|
||||
<input type="submit" class="button" name="login" value="Login"/>
|
||||
|
@@ -2,8 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->prepare('baseUrl', $BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->prepare('baseUrl', $BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
@@ -2,8 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php
|
||||
$partial = new Partial('head');
|
||||
$partial = new Partial('head');
|
||||
$partial->prepare('baseDir', $BASEDIR);
|
||||
$partial->prepare('baseUrl', $BASEURL);
|
||||
$partial->render();
|
||||
?>
|
||||
<title><?php echo $TITLE ?></title>
|
||||
|
10
composer.json
Normal file
10
composer.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Core\\": "core/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"illuminate/container": "^8.18"
|
||||
}
|
||||
}
|
207
composer.lock
generated
Normal file
207
composer.lock
generated
Normal file
@@ -0,0 +1,207 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c3305b3f3f6089062c2031140866dab7",
|
||||
"packages": [
|
||||
{
|
||||
"name": "illuminate/container",
|
||||
"version": "v8.18.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/container.git",
|
||||
"reference": "657cac2aa601aa0223afe0ed8627d0cb443f6a22"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/container/zipball/657cac2aa601aa0223afe0ed8627d0cb443f6a22",
|
||||
"reference": "657cac2aa601aa0223afe0ed8627d0cb443f6a22",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/contracts": "^8.0",
|
||||
"php": "^7.3|^8.0",
|
||||
"psr/container": "^1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/container-implementation": "1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "8.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Container\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "The Illuminate Container package.",
|
||||
"homepage": "https://laravel.com",
|
||||
"time": "2020-12-01T14:31:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/contracts",
|
||||
"version": "v8.18.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/contracts.git",
|
||||
"reference": "a73835aad399da42e88217bdbb5e1e4c1e668807"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/contracts/zipball/a73835aad399da42e88217bdbb5e1e4c1e668807",
|
||||
"reference": "a73835aad399da42e88217bdbb5e1e4c1e668807",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.3|^8.0",
|
||||
"psr/container": "^1.0",
|
||||
"psr/simple-cache": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "8.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Contracts\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "The Illuminate Contracts package.",
|
||||
"homepage": "https://laravel.com",
|
||||
"time": "2020-11-18T13:57:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/container.git",
|
||||
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
|
||||
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Container\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common Container Interface (PHP FIG PSR-11)",
|
||||
"homepage": "https://github.com/php-fig/container",
|
||||
"keywords": [
|
||||
"PSR-11",
|
||||
"container",
|
||||
"container-interface",
|
||||
"container-interop",
|
||||
"psr"
|
||||
],
|
||||
"time": "2017-02-14T16:28:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/simple-cache",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/simple-cache.git",
|
||||
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
|
||||
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\SimpleCache\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interfaces for simple caching",
|
||||
"keywords": [
|
||||
"cache",
|
||||
"caching",
|
||||
"psr",
|
||||
"psr-16",
|
||||
"simple-cache"
|
||||
],
|
||||
"time": "2017-10-23T01:57:42+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "1.1.0"
|
||||
}
|
5
config/application.php
Normal file
5
config/application.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'providers' => []
|
||||
];
|
26
core/Application/Application.php
Normal file
26
core/Application/Application.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Core\Application;
|
||||
|
||||
use Core\Configuration\Configurations;
|
||||
use Illuminate\Container\Container;
|
||||
|
||||
class Application
|
||||
{
|
||||
/** @var Container $container */
|
||||
private $container;
|
||||
|
||||
/** @var Configurations */
|
||||
private $configurations;
|
||||
|
||||
public function __construct(Container $container, Configurations $configurations)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->configurations = $configurations;
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
//todo: implement run logic.
|
||||
}
|
||||
}
|
24
core/Configuration/ConfigurationLoader.php
Normal file
24
core/Configuration/ConfigurationLoader.php
Normal 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.
|
||||
*/
|
||||
}
|
25
core/Configuration/Configurations.php
Normal file
25
core/Configuration/Configurations.php
Normal 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.
|
||||
}
|
||||
}
|
@@ -1,3 +1,33 @@
|
||||
<?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';
|
Reference in New Issue
Block a user