Moves "jilo-web" to its own repo.

main
Yasen Pramatarov 2024-06-28 19:50:51 +03:00
parent 548d05e59e
commit 5ebba9021c
20 changed files with 1 additions and 249 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
*.log
*.log.*
jilo.db
jilo-web.db
packaging/deb-package/
packaging/rpm-package/

View File

@ -19,7 +19,7 @@ All notable changes to this project will be documented in this file.
- Added jvb health-check scheduled and stopped events
- Added "no operational bridges" and "no bridge available" events
- Added "jitsi-component" service level events search in jilo-cli
- Added initial version of jilo-web, PHP web interface to jilo
- Added initial version of jilo-web, PHP web interface to jilo (then moved to own repo)
### Changed

View File

@ -1,13 +0,0 @@
requirements
- web server (deb: apache | nginx)
- php support in the web server (deb: php-fpm | libapache2-mod-php)
- pdo and pdo_sqlite support in php (deb: php-db, php-sqlite3) uncomment in php.ini: ;extension=pdo_sqlite
TODO
- jilo-web.db outside web root
- jilo-web.db writable by web server user

View File

View File

View File

@ -1,3 +0,0 @@
#!/usr/bin/env bash
echo 'todo install script'

View File

View File

@ -1,5 +0,0 @@
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
);

View File

@ -1,25 +0,0 @@
<?php
class Database {
private $pdo;
public function __construct($dbFile) {
if ( !extension_loaded('pdo_sqlite') ) {
throw new Exception('PDO extension for SQLite not loaded.');
}
try {
$this->pdo = new PDO("sqlite:" . $dbFile);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
throw new Exception('DB connection failed: ' . $e->getMessage());
}
}
public function getConnection() {
return $this->pdo;
}
}
?>

View File

@ -1,37 +0,0 @@
<?php
class User {
private $db;
public function __construct($database) {
$this->db = $database->getConnection();
}
public function register($username, $password) {
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$query = $this->db->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$query->bindParam(':username', $username);
$query->bindParam(':password', $hashedPassword);
return $query->execute();
}
public function login($username, $password) {
$query = $this->db->prepare("SELECT * FROM users WHERE username = :username");
$query->bindParam(':username', $username);
$query->execute();
$user = $query->fetch(PDO::FETCH_ASSOC);
if ( $user && password_verify($password, $user['password'])) {
session_start();
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
return true;
} else {
return false;
}
}
}
?>

View File

@ -1,8 +0,0 @@
<?php
unset($error);
include 'templates/header.php';
include 'templates/body.php';
include 'templates.footer.php';
?>

View File

@ -1,30 +0,0 @@
<?php
require_once 'classes/database.php';
require 'classes/user.php';
unset($error);
try {
$db = new Database('./jilo-web.db');
$user = new User($db);
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$username = $_POST['username'];
$password = $_POST['password'];
if ( $user->login($username, $password) ) {
echo "Login successful.";
} else {
echo "Login failed.";
}
}
} catch (Exception $e) {
$error = $e->getMessage();
}
include 'templates/header.php';
include 'templates/form-login.php';
include 'templates/footer.php';
?>

View File

@ -1,14 +0,0 @@
<?php
session_start();
session_unset();
session_destroy();
unset($error);
echo "You logged out.";
include 'templates/header.php';
include 'templates/body.php';
include 'templates/footer.php';
?>

View File

@ -1,29 +0,0 @@
<?php
require_once 'classes/database.php';
require 'classes/user.php';
unset($error);
try {
$db = new Database('./jilo-web.db');
$user = new User($db);
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$username = $_POST['username'];
$password = $_POST['password'];
if ( $user->register($username, $password) ) {
echo "Registration successful.";
} else {
echo "Registration failed.";
}
}
} catch (Exception $e) {
$error = $e->getMessage();
}
include 'templates/header.php';
include 'templates/form-register.php';
include 'templates/footer.php';
?>

View File

@ -1,25 +0,0 @@
ul.menu {
list-style-type: none;
margin: 0;
margin-bottom: 10px;
padding: 0;
overflow: hidden;
background-color: #333;
}
ul.menu li {
float: right;
}
ul.menu li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
ul.menu li a:hover {
background-color: #111;
}

View File

@ -1 +0,0 @@
<?php ?>

View File

@ -1,5 +0,0 @@
<?php ?>
</body>
</html>

View File

@ -1,7 +0,0 @@
<?php ?>
<form method="POST" action="login.php">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<button type="submit">Login</button>
</form>

View File

@ -1,7 +0,0 @@
<?php ?>
<form method="POST" action="register.php">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<button type="submit">Register</button>
</form>

View File

@ -1,38 +0,0 @@
<?php
session_start();
$scriptname = basename($_SERVER['SCRIPT_NAME']);
if ( !isset($_SESSION['user_id']) && ($scriptname !== 'login.php' && $scriptname !== 'register.php') ) {
header('Location: login.php');
exit();
}
if ( isset($_SESSION['username']) ) {
echo "Welcome, " . htmlspecialchars($_SESSION['username']) . "!";
}
if (isset($error)) {
echo "<p style='color: red;'>Error: $error</p>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="templates/all.css">
<title>Jilo Web</title>
</head>
<body>
<ul class="menu">
<?php if ( !isset($_SESSION['user_id']) ) { ?>
<li><a href="login.php">login</a></li>
<li><a href="register.php">register</a></li>
<?php } else { ?>
<li><a href="logout.php">logout</a></li>
<?php } ?>
</ul>