Nofu/public/index.php
2024-09-12 16:21:52 +02:00

113 lines
2.9 KiB
PHP

<?php
session_start();
require '../vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
use KTH\App;
use KTH\HTMLGenerator\HTMLGenerator;
use Login\Login;
use Utils\CsrfToken;
/*
#############################################################
################ DO NOT EDIT THIS FILE ######################
################ USE data/config.yaml ######################
################ OR USE CONFIG PAGE ######################
#############################################################
*/
$defConfig['title'] = 'KT-HomePage';
$defConfig['desc'] = 'Dashboard de Knah Tsaeb';
$defConfig['favicon'] = 'assets/favicons/favicon-96x96.png';
$defConfig['noAuth'] = ['128.0.0.1'];
$defConfig['visibility'] = 'private';
$defConfig['colorScheme'] = 'dark';
$defConfig['view'] = 'full';
$breadcrumbs = '';
$KTH = new App();
$config = $KTH->getConfig($defConfig);
if (isset($_GET['logout'])) {
$logout = Login::logOut();
exit();
}
if ($config['visibility'] === 'private') {
if (!$KTH->canByPassAuth($defConfig['noAuth'])) {
if (!Login::isLogged()) {
if (file_exists('../data/users.yaml')) {
require('../template/default/login.php');
} else {
require('../template/default/register.php');
}
exit();
}
}
}
if (isset($_POST['settings'])) {
if (CsrfToken::validateToken($_POST['token'])) {
$KTH->saveUserConfig();
header("Location: /");
} else {
session_destroy();
header("Location: /");
}
exit();
}
if (isset($_POST['edit'])) {
if (CsrfToken::validateToken($_POST['token'])) {
$status = $KTH->saveServices();
if ($status['status'] === 'error') {
$error = $status['message'];
$content = $status['content'];
//header("Location: ?edit=1");
$_GET['edit']=1;
} else {
header("Location: /");
}
} else {
session_destroy();
header("Location: /");
}
}
if (isset($_GET['settings'])) {
require('../template/default/settings.php');
exit();
}
if (isset($_GET['edit'])) {
$services = $KTH->getServices();
require('../template/default/edit.php');
exit();
}
if (isset($_GET['editImg'])) {
require('../template/default/editImg.php');
exit();
}
if ($KTH->cacheExist()) {
echo file_get_contents('../cache/index.html');
} else {
$services = $KTH->getServices();
$generator = new HTMLGenerator($services);
$userDoc = $generator->genUserDoc();
$menuData = $KTH->makeMenu($services);
ob_start();
require('../template/default/header.php');
require('../template/default/titleBar.php');
require('../template/default/nav.php');
require('../template/default/content.php');
require('../template/default/footer.php');
$out = ob_get_contents();
file_put_contents('../cache/index.html', $out);
}