jilo-web/public_html/index.php

261 lines
7.6 KiB
PHP
Raw 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
2025-01-15 17:06:12 +00:00
* Year: 2024-2025
2025-04-12 14:21:34 +00:00
* Version: 0.4
2024-07-01 09:45:07 +00:00
*/
// Preparing plugins and hooks
// Initialize HookDispatcher and plugin system
require_once __DIR__ . '/../app/core/HookDispatcher.php';
require_once __DIR__ . '/../app/core/PluginManager.php';
use App\Core\HookDispatcher;
use App\Core\PluginManager;
// Hook registration and dispatch helpers
function register_hook(string $hook, callable $callback): void {
HookDispatcher::register($hook, $callback);
}
function do_hook(string $hook, array $context = []): void {
HookDispatcher::dispatch($hook, $context);
}
function filter_public_pages(array $pages): array {
return HookDispatcher::applyFilters('filter_public_pages', $pages);
}
function filter_allowed_urls(array $urls): array {
return HookDispatcher::applyFilters('filter_allowed_urls', $urls);
}
// Load enabled plugins
$plugins_dir = dirname(__DIR__) . '/plugins/';
$enabled_plugins = PluginManager::load($plugins_dir);
$GLOBALS['enabled_plugins'] = $enabled_plugins;
// Define CSRF token include path globally
if (!defined('CSRF_TOKEN_INCLUDE')) {
define('CSRF_TOKEN_INCLUDE', dirname(__DIR__) . '/app/includes/csrf_token.php');
}
// Global cnstants
require_once '../app/includes/constants.php';
// we start output buffering and
2024-08-19 10:25:09 +00:00
// flush it later only when there is no redirect
ob_start();
2025-04-13 16:34:13 +00:00
// Start session before any session-dependent code
require_once '../app/classes/session.php';
Session::startSession();
// Apply security headers
require_once '../app/includes/security_headers_middleware.php';
2024-10-04 11:18:28 +00:00
// sanitize all input vars that may end up in URLs or forms
require '../app/includes/sanitize.php';
2024-10-04 08:36:45 +00:00
2025-04-13 16:34:13 +00:00
// Check session validity
$validSession = Session::isValidSession();
2025-01-30 16:48:46 +00:00
// Get user ID early if session is valid
$userId = $validSession ? Session::getUserId() : null;
2025-02-17 12:36:00 +00:00
// Initialize feedback message system
require_once '../app/classes/feedback.php';
$system_messages = [];
require '../app/includes/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
2025-01-28 19:18:20 +00:00
'graphs',
2024-10-08 10:23:38 +00:00
'latest',
2025-01-28 19:18:20 +00:00
'livejs',
2024-10-08 10:23:38 +00:00
2024-09-13 11:02:59 +00:00
'agents',
'config',
'profile',
2025-04-07 13:21:35 +00:00
'credentials',
'settings',
'security',
2024-10-19 13:09:16 +00:00
'status',
2024-09-13 11:02:59 +00:00
'logs',
2024-10-07 07:00:15 +00:00
'help',
2024-09-13 11:02:59 +00:00
'login',
'logout',
2025-04-13 16:34:13 +00:00
'about',
2024-07-01 09:45:07 +00:00
];
// Let plugins filter/extend allowed_urls
$allowed_urls = filter_allowed_urls($allowed_urls);
require_once __DIR__ . '/../app/core/ConfigLoader.php';
use App\Core\ConfigLoader;
// Load configuration
$config = ConfigLoader::loadConfig([
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',
]);
2025-04-24 11:30:35 +00:00
// Expose config file path for pages
$config_file = ConfigLoader::getConfigPath();
$localConfigPath = str_replace(__DIR__ . '/..', '', $config_file);
2024-07-01 09:45:07 +00:00
2024-10-04 15:13:55 +00:00
$app_root = $config['folder'];
2025-04-13 16:34:13 +00:00
// List of pages that don't require authentication
2025-04-17 07:30:34 +00:00
$public_pages = ['login', 'help', 'about'];
2025-04-13 16:34:13 +00:00
// Let plugins filter/extend public_pages
$public_pages = filter_public_pages($public_pages);
// Dispatch routing and auth
require_once __DIR__ . '/../app/core/Router.php';
$currentUser = \App\Core\Router::checkAuth($config, $app_root, $public_pages, $page);
// connect to DB via DatabaseConnector
require_once __DIR__ . '/../app/core/DatabaseConnector.php';
use App\Core\DatabaseConnector;
$dbWeb = DatabaseConnector::connect($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
2025-02-23 15:48:02 +00:00
// Initialize security middleware
require_once '../app/includes/csrf_middleware.php';
require_once '../app/helpers/security.php';
$security = SecurityHelper::getInstance();
// Verify CSRF token for POST requests
applyCsrfMiddleware();
// init rate limiter
require '../app/classes/ratelimiter.php';
// 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
2025-04-13 16:34:13 +00:00
Session::destroySession();
2025-01-30 16:48:46 +00:00
// start new session for the login page
2025-04-13 16:34:13 +00:00
Session::startSession();
2025-01-30 16:48:46 +00:00
setcookie('username', "", time() - 100, $config['folder'], $config['domain'], isset($_SERVER['HTTPS']), true);
// Log successful logout
$logObject->insertLog($userId, "Logout: User \"$currentUser\" logged out. IP: $user_IP", 'user');
2024-09-30 09:52:06 +00:00
// Set success message
2025-02-16 08:18:26 +00:00
Feedback::flash('LOGIN', 'LOGOUT_SUCCESS');
2025-01-04 10:30:44 +00:00
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
include '../app/pages/login.php';
2025-02-10 17:18:15 +00:00
include '../app/templates/page-footer.php';
2025-01-04 10:30:44 +00:00
} else {
// if user is logged in, we need user details and rights
2025-04-13 16:34:13 +00:00
if ($validSession) {
2024-10-23 12:28:45 +00:00
// If by error a logged in user requests the login page
if ($page === 'login') {
header('Location: ' . htmlspecialchars($app_root));
exit();
}
$userDetails = $userObject->getUserDetails($userId);
$userRights = $userObject->getUserRights($userId);
$userTimezone = (!empty($userDetails[0]['timezone'])) ? $userDetails[0]['timezone'] : 'UTC'; // Default to UTC if no timezone is set (or is missing)
2024-10-23 12:28:45 +00:00
2024-10-23 12:13:01 +00:00
// check if the Jilo Server is running
require '../app/classes/server.php';
$serverObject = new Server($dbWeb);
$server_host = '127.0.0.1';
$server_port = '8080';
$server_endpoint = '/health';
$server_status = $serverObject->getServerStatus($server_host, $server_port, $server_endpoint);
if (!$server_status) {
2025-02-16 08:18:26 +00:00
Feedback::flash('ERROR', 'DEFAULT', 'The Jilo Server is not running. Some data may be old and incorrect.', false, true);
2024-10-23 12:13:01 +00:00
}
2024-10-18 12:41:15 +00:00
}
// --- Plugin loading logic for all enabled plugins ---
$plugin_controllers = [];
foreach ($GLOBALS['enabled_plugins'] as $plugin_name => $plugin_info) {
$controller_path = $plugin_info['path'] . '/controllers/' . $plugin_name . '.php';
if (file_exists($controller_path)) {
$plugin_controllers[$plugin_name] = $controller_path;
}
}
// page building
2024-09-13 11:02:59 +00:00
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
2025-04-13 16:34:13 +00:00
if ($validSession) {
2024-09-13 11:02:59 +00:00
include '../app/templates/page-sidebar.php';
}
if (in_array($page, $allowed_urls)) {
// all normal pages
if (isset($plugin_controllers[$page])) {
include $plugin_controllers[$page];
} else {
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
}
2025-02-10 17:18:15 +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']);