diff --git a/jilo-web.conf b/jilo-web.conf
deleted file mode 100644
index e69de29..0000000
diff --git a/jilo-web.conf.php b/jilo-web.conf.php
new file mode 100644
index 0000000..65d1fe9
--- /dev/null
+++ b/jilo-web.conf.php
@@ -0,0 +1,9 @@
+ 'localhost',
+ 'folder' => '/jilo-web/',
+ 'database' => '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.db',
+];
+
+?>
diff --git a/public_html/index.php b/public_html/index.php
index 1ea534d..90f044b 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -1,30 +1,18 @@
Error: $error";
-}
+/**
+ * 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
+ * Version: 0.1
+ */
+// list of available pages
+// edit accordingly, add 'pages/PAGE.php'
$allowed_urls = [
'front',
'login',
@@ -34,14 +22,77 @@ $allowed_urls = [
'config',
];
-include 'templates/header.php';
-
-if (in_array($page, $allowed_urls)) {
- include "pages/{$page}.php";
+// cnfig file
+$config_file = '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.conf.php';
+if (file_exists($config_file)) {
+ require_once $config_file;
} else {
- include 'pages/front.php';
+ die('Config file not found');
}
+session_start();
+
+if (isset($_GET['page'])) {
+ $page = $_GET['page'];
+} elseif (isset($_POST['page'])) {
+ $page = $_POST['page'];
+} else {
+ $page = 'front';
+}
+
+// logged in username
+if ( isset($_SESSION['username']) ) {
+ $user = htmlspecialchars($_SESSION['username']);
+}
+
+// redirect to login
+if ( !isset($_SESSION['user_id']) && ($page !== 'login' && $page !== 'register') ) {
+ header('Location: index.php?page=login');
+ exit();
+}
+
+// we use 'notice' for all non-critical messages and 'error' for errors
+if (isset($_SESSION['notice'])) {
+ $notice = $_SESSION['notice'];
+}
+if (isset($_SESSION['error'])) {
+ $error = $_SESSION['error'];
+}
+
+// page building
+if (in_array($page, $allowed_urls)) {
+ // logout is a special case, as we can't use session vars for notices
+ if ($page == 'logout') {
+
+ // clean up session
+ session_unset();
+ session_destroy();
+
+ $notice = "You were logged out.
You can log in again.";
+ include 'templates/header.php';
+ include 'templates/menu.php';
+ include 'templates/message.php';
+ include 'pages/login.php';
+
+ // all other normal pages
+ } else {
+ include 'templates/header.php';
+ include 'templates/menu.php';
+ include 'templates/message.php';
+ include "pages/{$page}.php";
+ }
+
+// the page is not in allowed urls, loading front page
+} else {
+ include 'templates/header.php';
+ include 'templates/menu.php';
+ include 'templates/message.php';
+ include 'pages/front.php';
+}
include 'templates/footer.php';
+// clear errors and notices before next page just in case
+unset($_SESSION['error']);
+unset($_SESSION['notice']);
+
?>
diff --git a/public_html/pages/login.php b/public_html/pages/login.php
index 3106994..a41d6be 100644
--- a/public_html/pages/login.php
+++ b/public_html/pages/login.php
@@ -2,10 +2,12 @@
require_once 'classes/database.php';
require 'classes/user.php';
+
+// clear the global error var before login
unset($error);
try {
- $db = new Database('./jilo-web.db');
+ $db = new Database($config['database']);
$user = new User($db);
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
@@ -34,16 +36,19 @@ try {
'samesite' => 'Strict',
'httponly' => true,
'secure' => isset($_SERVER['HTTPS']),
- 'domain' => $domain,
- 'path' => '/jilo-web/'
+ 'domain' => $config['domain'],
+ 'path' => $config['folder']
]);
// redirect to index
+ $_SESSION['notice'] = "Login successful";
header('Location: index.php');
exit();
// login failed
} else {
- $error = "Login failed.";
+ $_SESSION['error'] = "Login failed.";
+ header('Location: index.php');
+ exit();
}
}
} catch (Exception $e) {
diff --git a/public_html/pages/logout.php b/public_html/pages/logout.php
deleted file mode 100644
index a38ffd0..0000000
--- a/public_html/pages/logout.php
+++ /dev/null
@@ -1,10 +0,0 @@
-
\ No newline at end of file
diff --git a/public_html/pages/register.php b/public_html/pages/register.php
index fd983ee..aae29c7 100644
--- a/public_html/pages/register.php
+++ b/public_html/pages/register.php
@@ -5,17 +5,23 @@ require 'classes/user.php';
unset($error);
try {
- $db = new Database('./jilo-web.db');
+ $db = new Database($config['database']);
$user = new User($db);
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$username = $_POST['username'];
$password = $_POST['password'];
+ // redirect to login
if ( $user->register($username, $password) ) {
- echo "Registration successful.";
+ $_SESSION['notice'] = "Registration successful.
You can log in now.";
+ header('Location: index.php');
+ exit();
+ // registration fail, redirect to login
} else {
- echo "Registration failed.";
+ $_SESSION['error'] = "Registration failed.";
+ header('Location: index.php');
+ exit();
}
}
} catch (Exception $e) {
diff --git a/public_html/static/all.css b/public_html/static/all.css
index 6bd8b2f..8d498e8 100644
--- a/public_html/static/all.css
+++ b/public_html/static/all.css
@@ -44,6 +44,7 @@
background-color: #eee;
border: 1px solid #333;
font-weight: bold;
+ font-size: 0.85em;
}
.notice {
@@ -53,4 +54,26 @@
background-color: #eee;
border: 1px solid #333;
font-weight: bold;
+ font-size: 0.85em;
+}
+
+#main {
+ width: 100%;
+}
+
+#footer {
+ position: absolute;
+ left: 0px;
+ bottom: 0px;
+ height: 30px;
+ width: 100%;
+ background-color: #777;
+ color: white;
+ text-align: center;
+ font-size: 0.85em;
+ line-height: 30px;
+}
+
+#footer a {
+ color: white;
}
diff --git a/public_html/templates/footer.php b/public_html/templates/footer.php
index 8dd310c..7e59374 100644
--- a/public_html/templates/footer.php
+++ b/public_html/templates/footer.php
@@ -1,5 +1,7 @@
-