Add docker container definition
Change-Id: If32020e6b8e8bb816eb54533554b18cc5302b5c9
diff --git a/.editorconfig b/.editorconfig
index 538ba2b..108a3b1 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -3,3 +3,7 @@
[*]
indent_style = tab
indent_size = 2
+
+[*.yml]
+indent_style = space
+indent_size = 2
diff --git a/.env.sample b/.env.sample
new file mode 100644
index 0000000..0e442e9
--- /dev/null
+++ b/.env.sample
@@ -0,0 +1,7 @@
+DB_SERVERNAME=db
+DB_USERNAME=root
+DB_PASSWORD=
+DB_NAME=pastanaga
+DB_USERS_DB=pastanaga
+DB_MORTS_DB=pastanaga_morts
+ADMIN_TOKEN=longRandomStringForTheAdminPages
diff --git a/.gitignore b/.gitignore
index 9672757..2bb202b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-credentials.php
+docker-compose.yml
+.env
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..1de3b54
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,4 @@
+FROM php:8.1-apache
+RUN docker-php-ext-install mysqli
+RUN docker-php-ext-enable mysqli
+COPY ./ /var/www/html/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b066708
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+MUTABLE_VERSION ?= latest
+VERSION ?= $(shell git rev-parse --short HEAD)
+
+IMAGE_PROD := avm99963/fisipastanagapp
+
+docker-prod: Dockerfile
+ docker build --force-rm -f Dockerfile --tag=$(IMAGE_PROD):$(VERSION) .
+ docker tag $(IMAGE_PROD):$(VERSION) $(IMAGE_PROD):$(MUTABLE_VERSION)
+
+push-prod: docker-prod
+ docker push $(IMAGE_PROD):$(VERSION)
diff --git a/admin/createtable.php b/admin/createtable.php
index 07ad979..9db621e 100644
--- a/admin/createtable.php
+++ b/admin/createtable.php
@@ -3,7 +3,7 @@
require '../php/utils.php';
$credentials = new Credentials();
- if ($credentials->adminToken != ($_GET["token"] ?? "")) {
+ if ($credentials->adminToken() != ($_GET["token"] ?? "")) {
exit();
}
@@ -28,6 +28,14 @@
`curs` tinyint(1) NOT NULL,
`grau` tinyint(1) NOT NULL,
`data` timestamp NOT NULL DEFAULT current_timestamp()
+ )",
+ "CREATE TABLE IF NOT EXISTS `missatges` (
+ `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ `sender_id` int(11) NOT NULL,
+ `receiver_id` int(11) NOT NULL,
+ `timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
+ `content` text NOT NULL,
+ `seen` tinyint(1) DEFAULT 0
)"];
foreach ($queries as $query) if (!query($query)) die('An error ocurred. ' . $query);
diff --git a/admin/insert.php b/admin/insert.php
index 9f5abb2..3a22ca4 100644
--- a/admin/insert.php
+++ b/admin/insert.php
@@ -3,7 +3,7 @@
require '../php/utils.php';
$credentials = new Credentials();
- if ($credentials->adminToken != ($_POST["token"] ?? "")) {
+ if ($credentials->adminToken() != ($_POST["token"] ?? "")) {
exit();
}
diff --git a/credentials.php b/credentials.php
new file mode 100644
index 0000000..600bfa5
--- /dev/null
+++ b/credentials.php
@@ -0,0 +1,31 @@
+<?php
+
+class Credentials {
+ public static function servername() {
+ return getenv('DB_SERVERNAME');
+ }
+
+ public static function username() {
+ return getenv('DB_USERNAME');
+ }
+
+ public static function password() {
+ return getenv('DB_PASSWORD');
+ }
+
+ public static function dbname() {
+ return getenv('DB_NAME');
+ }
+
+ public static function usersdb() {
+ return getenv('DB_USERS_DB');
+ }
+
+ public static function mortsdb() {
+ return getenv('DB_MORTS_DB');
+ }
+
+ public static function adminToken() {
+ return getenv('ADMIN_TOKEN');
+ }
+};
diff --git a/credentials.sample.php b/credentials.sample.php
deleted file mode 100644
index 7bd7010..0000000
--- a/credentials.sample.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-class Credentials {
- public $servername = "";
- public $username = "";
- public $password = "";
- public $dbname = "pastanaga";
- public $usersdb = "pastanaga";
- public $mortsdb = "pastanaga_morts";
- public $adminToken = "longRandomStringForTheAdminPages";
-};
diff --git a/docker-compose.sample.yml b/docker-compose.sample.yml
new file mode 100644
index 0000000..6f8dc16
--- /dev/null
+++ b/docker-compose.sample.yml
@@ -0,0 +1,24 @@
+version: "3.5"
+
+services:
+ pastanagapp:
+ image: avm99963/fisipastanagapp
+ env_file: .env
+ ports:
+ - "8080:80"
+ depends_on:
+ - db
+ networks:
+ - backend
+ restart: unless-stopped
+ db:
+ image: mariadb
+ environment:
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
+ MARIADB_DATABASE: ${DB_NAME}
+ networks:
+ - backend
+ restart: unless-stopped
+
+networks:
+ backend:
diff --git a/php/change_password.php b/php/change_password.php
index 17d64bd..26cb709 100644
--- a/php/change_password.php
+++ b/php/change_password.php
@@ -6,7 +6,7 @@
Security::checkIsSignedIn();
$credentials = new Credentials();
- $usersdb = $credentials->usersdb;
+ $usersdb = $credentials->usersdb();
date_default_timezone_set("Europe/Madrid");
diff --git a/php/db.php b/php/db.php
index 2043b87..1291b10 100644
--- a/php/db.php
+++ b/php/db.php
@@ -3,7 +3,7 @@
// Create connection
$credentials = new Credentials();
-$conn = new mysqli($credentials->servername, $credentials->username, $credentials->password, $credentials->dbname);
+$conn = new mysqli($credentials->servername(), $credentials->username(), $credentials->password(), $credentials->dbname());
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
$conn->set_charset("utf8");
diff --git a/php/login.php b/php/login.php
index f86aa68..c06149e 100644
--- a/php/login.php
+++ b/php/login.php
@@ -4,7 +4,7 @@
require_once("security.php");
$credentials = new Credentials();
- $usersdb = $credentials->usersdb;
+ $usersdb = $credentials->usersdb();
date_default_timezone_set("Europe/Madrid");
diff --git a/php/request.php b/php/request.php
index ac2c8cf..39f17dd 100644
--- a/php/request.php
+++ b/php/request.php
@@ -3,8 +3,8 @@
require 'utils.php';
$credentials = new Credentials();
- $usersdb = $credentials->usersdb;
- $mortsdb = $credentials->mortsdb;
+ $usersdb = $credentials->usersdb();
+ $mortsdb = $credentials->mortsdb();
// Do the query
$queries = [""];
diff --git a/php/security.php b/php/security.php
index 9842f3b..7f441ca 100644
--- a/php/security.php
+++ b/php/security.php
@@ -30,7 +30,7 @@
$credentials = new Credentials();
- $query = $conn->prepare("SELECT id, password FROM ".$credentials->usersdb." WHERE id = ?");
+ $query = $conn->prepare("SELECT id, password FROM ".$credentials->usersdb()." WHERE id = ?");
$query->bind_param("i", $id);
$query->execute();
diff --git a/php/send_thread.php b/php/send_thread.php
index 131627d..5e03843 100644
--- a/php/send_thread.php
+++ b/php/send_thread.php
@@ -3,6 +3,7 @@
require 'utils.php';
require_once("security.php");
+ // Yup, this is a f*ature, not a b*g. Please be responsible when exploit*ng this :) Have fun with it, but please don't cross the line!
$victimid = (int)$_POST["victim-id"];
$killerid = (int)$_POST["killer-id"];
$msgcontent = mysqli_real_escape_string($conn, $_POST["msg-content"]);
diff --git a/php/utils.php b/php/utils.php
index 1c41567..80c5d84 100644
--- a/php/utils.php
+++ b/php/utils.php
@@ -55,8 +55,8 @@
$users = [];
$credentials = new Credentials();
- $usersdb = $credentials->usersdb;
- $mortsdb = $credentials->mortsdb;
+ $usersdb = $credentials->usersdb();
+ $mortsdb = $credentials->mortsdb();
// Prepare the query
$query = "SELECT * FROM $usersdb";
diff --git a/ranking.php b/ranking.php
index c447b80..c682d64 100644
--- a/ranking.php
+++ b/ranking.php
@@ -12,8 +12,8 @@
require './php/utils.php';
$credentials = new Credentials();
- $usersdb = $credentials->usersdb;
- $mortsdb = $credentials->mortsdb;
+ $usersdb = $credentials->usersdb();
+ $mortsdb = $credentials->mortsdb();
// Mateix grau i curs => 100, Mateix grau diferent curs => 150, Diferent grau => 200
$getranking = "SELECT $mortsdb.assassi AS id, $usersdb.nom, $usersdb.grau, $usersdb.curs, count($mortsdb.assassi) AS kills,