jilo-web/public_html/index.php

176 lines
4.5 KiB
PHP
Raw Permalink Normal View History

<?php
2024-07-01 09:45:07 +00:00
/**
* Jilo web logs observer
*
* Description: A web interface to Jilo (JItsi Logs Observer), written in PHP
* Author: Yasen Pramatarov
* License: GPLv2
* Project URL: https://lindeas.com/jilo
* Year: 2024
2024-10-17 09:03:13 +00:00
* Version: 0.2.1
2024-07-01 09:45:07 +00:00
*/
2024-08-19 10:25:09 +00:00
// we start output buffering and.
// flush it later only when there is no redirect
ob_start();
2024-10-04 11:18:28 +00:00
// sanitize all input vars that may end up in URLs or forms
2024-10-04 08:36:45 +00:00
require '../app/helpers/sanitize.php';
require '../app/helpers/errors.php';
// error reporting, comment out in production
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
2024-07-01 09:45:07 +00:00
// list of available pages
// edit accordingly, add 'pages/PAGE.php'
$allowed_urls = [
2024-09-13 11:02:59 +00:00
'dashboard',
'conferences',
'participants',
2024-07-08 09:17:35 +00:00
'components',
2024-09-13 11:02:59 +00:00
2024-10-08 10:23:38 +00:00
'graphs',
'latest',
2024-09-13 11:02:59 +00:00
'agents',
'profile',
'config',
'logs',
2024-10-07 07:00:15 +00:00
'help',
2024-09-13 11:02:59 +00:00
'login',
'logout',
'register',
2024-07-01 09:45:07 +00:00
];
// cnfig file
2024-08-01 08:20:31 +00:00
// possible locations, in order of preference
$config_file_locations = [
2024-08-12 11:12:24 +00:00
__DIR__ . '/../app/config/jilo-web.conf.php',
2024-08-01 08:20:31 +00:00
__DIR__ . '/../jilo-web.conf.php',
'/srv/jilo-web/jilo-web.conf.php',
'/opt/jilo-web/jilo-web.conf.php'
];
$config_file = null;
// try to find the config file
foreach ($config_file_locations as $location) {
if (file_exists($location)) {
$config_file = $location;
break;
}
}
// if found, use it
if ($config_file) {
2024-08-13 14:53:52 +00:00
$config = require $config_file;
2024-07-01 09:45:07 +00:00
} else {
die('Config file not found');
}
2024-10-04 15:13:55 +00:00
$app_root = $config['folder'];
2024-08-10 18:42:44 +00:00
session_name('jilo');
2024-07-01 09:45:07 +00:00
session_start();
2024-07-03 06:37:35 +00:00
// check if logged in
unset($currentUser);
2024-07-03 06:37:35 +00:00
if (isset($_COOKIE['username'])) {
if ( !isset($_SESSION['username']) ) {
$_SESSION['username'] = $_COOKIE['username'];
}
$currentUser = htmlspecialchars($_SESSION['username']);
2024-07-01 09:45:07 +00:00
}
2024-07-01 09:45:07 +00:00
// redirect to login
2024-07-03 15:15:32 +00:00
if ( !isset($_COOKIE['username']) && ($page !== 'login' && $page !== 'register') ) {
header('Location: index.php?page=login');
exit();
}
// connect to db of Jilo Web
require '../app/classes/database.php';
require '../app/helpers/database.php';
$dbWeb = connectDB($config);
2024-09-16 14:09:37 +00:00
// start logging
require '../app/classes/log.php';
2024-09-17 11:22:43 +00:00
include '../app/helpers/logs.php';
2024-09-16 14:09:37 +00:00
$logObject = new Log($dbWeb);
2024-09-17 11:22:43 +00:00
$user_IP = getUserIP();
2024-09-16 14:09:37 +00:00
// get platforms details
require '../app/classes/platform.php';
$platformObject = new Platform($dbWeb);
$platformsAll = $platformObject->getPlatformDetails();
2024-08-17 08:20:08 +00:00
// by default we connect ot the first configured platform
2024-10-04 08:36:45 +00:00
if ($platform_id == '') {
$platform_id = $platformsAll[0]['id'];
}
$platformDetails = $platformObject->getPlatformDetails($platform_id);
2024-08-17 08:20:08 +00:00
2024-09-16 16:08:03 +00:00
// init user functions
require '../app/classes/user.php';
include '../app/helpers/profile.php';
$userObject = new User($dbWeb);
// logout is a special case, as we can't use session vars for notices
if ($page == 'logout') {
// clean up session
session_unset();
session_destroy();
setcookie('username', "", time() - 100, $config['folder'], $config['domain'], isset($_SERVER['HTTPS']), true);
2024-09-30 09:52:06 +00:00
$notice = "You were logged out.<br />You can log in again.";
$user_id = $userObject->getUserId($currentUser)[0]['id'];
$logObject->insertLog($user_id, "Logout: User \"$currentUser\" logged out. IP: $user_IP", 'user');
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
include '../app/templates/block-message.php';
include '../app/pages/login.php';
} else {
// if user is logged in, we need user details and rights
2024-09-13 10:49:17 +00:00
if (isset($currentUser)) {
$user_id = $userObject->getUserId($currentUser)[0]['id'];
$userDetails = $userObject->getUserDetails($user_id);
$userRights = $userObject->getUserRights($user_id);
$userTimezone = isset($userDetails[0]['timezone']) ? $userDetails[0]['timezone'] : 'UTC'; // Default to UTC if no timezone is set
}
// page building
2024-09-13 11:02:59 +00:00
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
include '../app/templates/block-message.php';
if (isset($currentUser)) {
include '../app/templates/page-sidebar.php';
}
if (in_array($page, $allowed_urls)) {
// all normal pages
include "../app/pages/{$page}.php";
2024-07-01 09:45:07 +00:00
} else {
2024-09-13 11:02:59 +00:00
// the page is not in allowed urls, loading "not found" page
include '../app/templates/error-notfound.php';
2024-08-06 07:40:52 +00:00
}
}
// end with the footer
2024-08-12 11:12:24 +00:00
include '../app/templates/page-footer.php';
2024-08-19 10:25:09 +00:00
// flush the output buffer and show the page
ob_end_flush();
2024-07-01 09:45:07 +00:00
// clear errors and notices before next page just in case
unset($_SESSION['error']);
unset($_SESSION['notice']);
?>