diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c2e4d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.log +*.log.* +jilo.db +jilo-web.db +packaging/deb-package/ +packaging/rpm-package/ diff --git a/README.md b/README.md index dee7dc3..0d286df 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ -# jilo-web +# Jilo Web +## 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 diff --git a/config.apache b/config.apache new file mode 100644 index 0000000..e69de29 diff --git a/config.nginx b/config.nginx new file mode 100644 index 0000000..e69de29 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..e0389f5 --- /dev/null +++ b/install.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo 'todo install script' diff --git a/jilo-web.conf b/jilo-web.conf new file mode 100644 index 0000000..e69de29 diff --git a/jilo-web.schema b/jilo-web.schema new file mode 100644 index 0000000..d932839 --- /dev/null +++ b/jilo-web.schema @@ -0,0 +1,5 @@ +CREATE TABLE users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT NOT NULL UNIQUE, + password TEXT NOT NULL +); diff --git a/public_html/classes/database.php b/public_html/classes/database.php new file mode 100644 index 0000000..065902f --- /dev/null +++ b/public_html/classes/database.php @@ -0,0 +1,25 @@ +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; + } + +} + +?> diff --git a/public_html/classes/user.php b/public_html/classes/user.php new file mode 100644 index 0000000..4debec9 --- /dev/null +++ b/public_html/classes/user.php @@ -0,0 +1,37 @@ +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; + } + } + +} + +?> diff --git a/public_html/index.php b/public_html/index.php new file mode 100644 index 0000000..683243a --- /dev/null +++ b/public_html/index.php @@ -0,0 +1,47 @@ +Error: $error

"; +} + +$allowed_urls = [ + 'front', + 'login', + 'logout', + 'register', + 'profile', + 'config', +]; + +include 'templates/header.php'; + +if (in_array($page, $allowed_urls)) { + include "pages/{$page}.php"; +} else { + include 'pages/front.php'; +} + +include 'templates/footer.php'; + +?> diff --git a/public_html/pages/config.php b/public_html/pages/config.php new file mode 100644 index 0000000..7ccbe49 --- /dev/null +++ b/public_html/pages/config.php @@ -0,0 +1 @@ + diff --git a/public_html/pages/login.php b/public_html/pages/login.php new file mode 100644 index 0000000..7a32cae --- /dev/null +++ b/public_html/pages/login.php @@ -0,0 +1,28 @@ +login($username, $password) ) { + header('Location: index.php'); + exit(); + } else { + echo "Login failed."; + } + } +} catch (Exception $e) { + $error = $e->getMessage(); +} + +include 'templates/form-login.php'; + +?> diff --git a/public_html/pages/logout.php b/public_html/pages/logout.php new file mode 100644 index 0000000..a38ffd0 --- /dev/null +++ b/public_html/pages/logout.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/public_html/pages/profile.php b/public_html/pages/profile.php new file mode 100644 index 0000000..5a5e5f5 --- /dev/null +++ b/public_html/pages/profile.php @@ -0,0 +1,3 @@ + + +profile of \ No newline at end of file diff --git a/public_html/pages/register.php b/public_html/pages/register.php new file mode 100644 index 0000000..fd983ee --- /dev/null +++ b/public_html/pages/register.php @@ -0,0 +1,27 @@ +register($username, $password) ) { + echo "Registration successful."; + } else { + echo "Registration failed."; + } + } +} catch (Exception $e) { + $error = $e->getMessage(); +} + +include 'templates/form-register.php'; + +?> diff --git a/public_html/static/all.css b/public_html/static/all.css new file mode 100644 index 0000000..60407d4 --- /dev/null +++ b/public_html/static/all.css @@ -0,0 +1,38 @@ +.menu-container { + display: flex; + justify-content: space-between; + align-items: center; + list-style: none; + padding: 0; + margin: 0; + margin-bottom: 10px; + background-color: #777; +} + +.menu-left, .menu-right { + display: flex; + list-style: none; + padding: 0; + margin: 0; +} + +.menu-left li, .menu-right li { + margin: 0 10px; +} + +.menu-left a, .menu-right a { + text-decoration: none; + color: white; +} + +.menu-left li a, .menu-right li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.menu-left li a:hover, .menu-right li a:hover { + background-color: #111; +} diff --git a/public_html/templates/footer.php b/public_html/templates/footer.php new file mode 100644 index 0000000..8dd310c --- /dev/null +++ b/public_html/templates/footer.php @@ -0,0 +1,6 @@ + + + + + + diff --git a/public_html/templates/form-login.php b/public_html/templates/form-login.php new file mode 100644 index 0000000..ebfb4ad --- /dev/null +++ b/public_html/templates/form-login.php @@ -0,0 +1,6 @@ + +
+ + + +
diff --git a/public_html/templates/form-register.php b/public_html/templates/form-register.php new file mode 100644 index 0000000..19f180d --- /dev/null +++ b/public_html/templates/form-register.php @@ -0,0 +1,6 @@ + +
+ + + +
diff --git a/public_html/templates/header.php b/public_html/templates/header.php new file mode 100644 index 0000000..d6ac58d --- /dev/null +++ b/public_html/templates/header.php @@ -0,0 +1,28 @@ + + + + + + Jilo Web + + + + +