From 3887faa43c4ab622a8d752005013924fbb50f4c7 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Mon, 7 Sep 2026 22:13:43 +0200 Subject: [PATCH] init --- .gitignore | 2 ++ compose.yaml | 36 ++++++++++++++++++++++++++++++++++++ index.php | 4 ++++ php/auto/auto.php | 4 ++++ php/auto/connection.php | 17 +++++++++++++++++ php/auto/user.php | 29 +++++++++++++++++++++++++++++ sql/rules.sql | 40 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 .gitignore create mode 100644 compose.yaml create mode 100644 index.php create mode 100644 php/auto/auto.php create mode 100644 php/auto/connection.php create mode 100644 php/auto/user.php create mode 100644 sql/rules.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..682903d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +mariadb_data \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..45b556c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,36 @@ +services: + mariadb: + image: docker.io/library/mariadb:latest + container_name: mariadb-db + restart: unless-stopped + ports: + - "3306:3306" + environment: + MARIADB_ROOT_PASSWORD: secure_root_password + MARIADB_DATABASE: my_database + MARIADB_USER: db_user + MARIADB_PASSWORD: secure_user_password + volumes: + - ./mariadb_data:/var/lib/mysql:Z + networks: + - db_network + + phpmyadmin: + image: docker.io/library/phpmyadmin:latest + container_name: phpmyadmin-web + restart: unless-stopped + ports: + - "8080:80" + environment: + PMA_HOST: mariadb + PMA_PORT: 3306 + UPLOAD_LIMIT: 64M + networks: + - db_network + depends_on: + - mariadb + +networks: + db_network: + driver: bridge + diff --git a/index.php b/index.php new file mode 100644 index 0000000..eaa0b37 --- /dev/null +++ b/index.php @@ -0,0 +1,4 @@ + + + +HI diff --git a/php/auto/auto.php b/php/auto/auto.php new file mode 100644 index 0000000..a5a2189 --- /dev/null +++ b/php/auto/auto.php @@ -0,0 +1,4 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); +} catch(PDOException $e) { + echo "Connection failed: " . $e->getMessage(); +} + + diff --git a/php/auto/user.php b/php/auto/user.php new file mode 100644 index 0000000..64e797b --- /dev/null +++ b/php/auto/user.php @@ -0,0 +1,29 @@ +prepare($sql); + $stmt->execute([ + ':userId' => $userId, + ':resourceName' => $resourceName, + ':actionName' => $actionName, + ]); + + $result = $stmt->fetch(); + + return ((int) $result['permission_count']) > 0; +} diff --git a/sql/rules.sql b/sql/rules.sql new file mode 100644 index 0000000..6f34c23 --- /dev/null +++ b/sql/rules.sql @@ -0,0 +1,40 @@ +-- Active: 1788811699247@@127.0.0.1@3306@my_database +-- 1. Groups (roles) — create first since users references it +CREATE TABLE groups ( + group_id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(100) NOT NULL UNIQUE, + description VARCHAR(255) +); + +-- 2. Users — now with a direct group_id column +CREATE TABLE users ( + user_id INT PRIMARY KEY AUTO_INCREMENT, + username VARCHAR(100) NOT NULL UNIQUE, + email VARCHAR(255) NOT NULL UNIQUE, + group_id INT NULL, -- nullable if a user can exist with no group yet + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (group_id) REFERENCES groups(group_id) ON DELETE SET NULL +); + +-- 3. Resources / modules +CREATE TABLE resources ( + resource_id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(100) NOT NULL UNIQUE +); + +-- 4. Actions +CREATE TABLE actions ( + action_id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(50) NOT NULL UNIQUE +); + +-- 5. Group permissions (unchanged) +CREATE TABLE group_permissions ( + group_id INT NOT NULL, + resource_id INT NOT NULL, + action_id INT NOT NULL, + PRIMARY KEY (group_id, resource_id, action_id), + FOREIGN KEY (group_id) REFERENCES groups(group_id) ON DELETE CASCADE, + FOREIGN KEY (resource_id) REFERENCES resources(resource_id) ON DELETE CASCADE, + FOREIGN KEY (action_id) REFERENCES actions(action_id) ON DELETE CASCADE +); \ No newline at end of file