Nofu/public/index.php

114 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2024-06-14 17:20:01 +02:00
<?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;
2024-06-14 17:20:01 +02:00
2024-09-12 16:21:52 +02:00
/*
#############################################################
################ DO NOT EDIT THIS FILE ######################
################ USE data/config.yaml ######################
################ OR USE CONFIG PAGE ######################
#############################################################
*/
2024-06-14 17:20:01 +02:00
$defConfig['title'] = 'KT-HomePage';
$defConfig['desc'] = 'Dashboard de Knah Tsaeb';
2024-06-27 11:46:09 +02:00
$defConfig['favicon'] = 'assets/favicons/favicon-96x96.png';
2024-06-14 17:20:01 +02:00
$defConfig['noAuth'] = ['128.0.0.1'];
2024-07-02 11:50:00 +02:00
$defConfig['visibility'] = 'private';
2024-06-14 17:20:01 +02:00
$defConfig['colorScheme'] = 'dark';
$defConfig['view'] = 'full';
$breadcrumbs = '';
$KTH = new App();
$config = $KTH->getConfig($defConfig);
if (isset($_GET['logout'])) {
$logout = Login::logOut();
exit();
}
2024-07-02 15:57:57 +02:00
if ($config['visibility'] === 'private') {
2024-06-14 17:20:01 +02:00
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: /");
}
}
2024-06-14 17:20:01 +02:00
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');
2024-06-14 17:20:01 +02:00
exit();
}
if ($KTH->cacheExist()) {
2024-06-17 11:48:42 +02:00
echo file_get_contents('../cache/index.html');
2024-06-14 17:20:01 +02:00
} else {
$services = $KTH->getServices();
2024-06-14 17:20:01 +02:00
$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();
2024-06-17 11:48:42 +02:00
file_put_contents('../cache/index.html', $out);
2024-06-14 17:20:01 +02:00
}