From 8ee2c98c04c8093872d387871707279c2fac4153 Mon Sep 17 00:00:00 2001
From: ycharbi
Date: Sat, 15 May 2021 22:20:09 +0200
Subject: [PATCH] =?UTF-8?q?Ajout=20des=20fichiers=20de=20pr=C3=A9paration?=
=?UTF-8?q?=20de=20l'environnement=20de=20test?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Dockerfile | 6 ++++++
README.md | 5 ++++-
index.php | 25 +++++++++++++++++++++++++
outils/données.sql | 24 ++++++++++++++++++++++++
outils/genenv.sh | 12 ++++++++++++
outils/postfix.sql | 30 ++++++++++++++++++++++++++++++
outils/rundocker.sh | 3 +++
7 files changed, 104 insertions(+), 1 deletion(-)
create mode 100644 Dockerfile
create mode 100644 index.php
create mode 100644 outils/données.sql
create mode 100644 outils/genenv.sh
create mode 100644 outils/postfix.sql
create mode 100755 outils/rundocker.sh
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..9a294d0
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,6 @@
+FROM php:7.4-apache
+RUN apt update && apt install -y --no-install-recommends sqlite3 git && apt clean && rm -rf /var/lib/apt/lists/*
+RUN mkdir -p /etc/postfix/
+COPY . /var/www/html/
+RUN chmod +x /var/www/html/outils/genenv.sh
+RUN /var/www/html/outils/genenv.sh
diff --git a/README.md b/README.md
index be96edf..5a41748 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
# Courtail
-Interface WEB d'administration pour le serveur de courriel : https://doc.ycharbi.fr/index.php/Serveur_de_courriels
\ No newline at end of file
+Interface WEB d'administration pour le serveur de courriel : https://doc.ycharbi.fr/index.php/Serveur_de_courriels
+
+## Dépendances du projet
+`apt install --no-install-recommends sqlite3 php php-sqlite3 apache2 git`
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..0b26e75
--- /dev/null
+++ b/index.php
@@ -0,0 +1,25 @@
+Coucou
";
+ $db = new PDO("sqlite:/etc/postfix/postfix.sqlite");
+ $db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+ try {
+
+ $res = $db -> query('SELECT * FROM postfix_alias_vitruels;');
+
+
+ print '';
+ foreach ($res as $row) {
+
+ print '' . $row['courriel'] . ' | ' . $row['destination'] . ' |
';
+
+ }
+ print '
';
+
+ }
+ catch(PDOException $e) {
+
+ print ("exception " . $e->getMessage());
+
+ }
+?>
diff --git a/outils/données.sql b/outils/données.sql
new file mode 100644
index 0000000..9b0a4a4
--- /dev/null
+++ b/outils/données.sql
@@ -0,0 +1,24 @@
+-- Alias (ne doivent pas apparaître)
+INSERT INTO postfix_alias (alias,destination,active) VALUES ("toto","test1",1);
+INSERT INTO postfix_alias (alias,destination,active) VALUES ("tata","test2",0);
+INSERT INTO postfix_alias (alias,destination,active) VALUES ("titi","test3",1);
+
+-- Alias virtuels
+INSERT INTO postfix_alias_vitruels (courriel,destination,active) VALUES ("toto@exemple.fr","test1@exemple.fr",1);
+INSERT INTO postfix_alias_vitruels (courriel,destination,active) VALUES ("tata@exemple.fr","test2@exemple.fr",0);
+INSERT INTO postfix_alias_vitruels (courriel,destination,active) VALUES ("titi@exemple.fr","test3@exemple.fr",1);
+
+-- Domaines secondaires
+INSERT INTO postfix_domaines (domaine,active) VALUES ("toto.fr",1);
+INSERT INTO postfix_domaines (domaine,active) VALUES ("tata.fr",1);
+INSERT INTO postfix_domaines (domaine,active) VALUES ("titi.fr",0);
+
+-- Listes noires destinataires
+INSERT INTO postfix_liste_noire_destinataires (courriel,action,active) VALUES ("root@mail.exemple.fr","REJECT",1);
+INSERT INTO postfix_liste_noire_destinataires (courriel,action,active) VALUES ("git@mail.exemple.fr","REJECT",1);
+INSERT INTO postfix_liste_noire_destinataires (courriel,action,active) VALUES ("liste@mail.exemple.fr","REJECT",1);
+
+-- Listes noires expéditeurs
+INSERT INTO postfix_liste_noire_expediteurs (courriel,code_retour,message,active) VALUES ("tata@tutu.fr",554,"Parle à ma main, ma tête est malade.",0);
+INSERT INTO postfix_liste_noire_expediteurs (courriel,code_retour,message,active) VALUES ("bob@foo.com",554,"Parle à ma main, ma tête est malade.",1);
+INSERT INTO postfix_liste_noire_expediteurs (courriel,code_retour,message,active) VALUES ("roland@bar.org",554,"Parle à ma main, ma tête est malade.",1);
diff --git a/outils/genenv.sh b/outils/genenv.sh
new file mode 100644
index 0000000..4385ed0
--- /dev/null
+++ b/outils/genenv.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+chemin_script=$(dirname "$0")
+
+mkdir -p /etc/postfix/
+rm -f /etc/postfix/postfix.sqlite
+
+# Création des tables
+sqlite3 /etc/postfix/postfix.sqlite < "${chemin_script}"/postfix.sql
+
+# Création des données
+sqlite3 /etc/postfix/postfix.sqlite < "${chemin_script}"/données.sql
diff --git a/outils/postfix.sql b/outils/postfix.sql
new file mode 100644
index 0000000..6972224
--- /dev/null
+++ b/outils/postfix.sql
@@ -0,0 +1,30 @@
+CREATE TABLE IF NOT EXISTS postfix_alias (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ alias TEXT NOT NULL UNIQUE,
+ destination TEXT NOT NULL,
+ active INTEGER
+);
+CREATE TABLE IF NOT EXISTS postfix_alias_vitruels (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ courriel TEXT NOT NULL UNIQUE,
+ destination TEXT NOT NULL,
+ active INTEGER
+);
+CREATE TABLE IF NOT EXISTS postfix_domaines (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ domaine TEXT NOT NULL UNIQUE,
+ active INTEGER
+);
+CREATE TABLE IF NOT EXISTS postfix_liste_noire_destinataires (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ courriel TEXT NOT NULL UNIQUE,
+ action TEXT NOT NULL,
+ active INTEGER
+);
+CREATE TABLE IF NOT EXISTS postfix_liste_noire_expediteurs (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ courriel TEXT NOT NULL UNIQUE,
+ code_retour INTEGER NOT NULL,
+ message TEXT NOT NULL,
+ active INTEGER
+);
diff --git a/outils/rundocker.sh b/outils/rundocker.sh
new file mode 100755
index 0000000..dab684a
--- /dev/null
+++ b/outils/rundocker.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+docker build -t courtail ../
+docker run -it -p 8080:80 courtail:latest