diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c749362..df52caf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,32 @@ -Datepicker -======= -Install libjs-jquery -Install libjs-jquery-ui -Install libjs-jquery-timepicker -Install libjs-bootstrap -Install (if not) javascript-common -Enable (if not) javascript-common conf +## MR 160: Datepicker + +Install libjs-jquery libjs-jquery-ui libjs-jquery-timepicker libjs-bootstrap javascript-common +``` +apt-get -y install \ + libjs-jquery \ + libjs-jquery-ui \ + libjs-jquery-timepicker \ + libjs-bootstrap \ + javascript-common +``` +Enable javascript-common conf +``` +a2enconf javascript-common +``` Delete old jquery files : - rm -rf static_files/js/jquery-ui-* - rm -rf static_files/js/jquery-2.2.4.min.js - static/css/jquery-ui-timepicker-addon.css +``` +rm -r static_files/js/jquery-ui-* +rm static_files/js/jquery-2.2.4.min.js +rm static/css/jquery-ui-timepicker-addon.css +``` + + +## MR 163: Fix install re2o + +Refactored install_re2o.sh script. +* There are more tools available with it but some fucntion have changed, report to [the dedicated wiki page](for more informations) or run: +``` +install_re2o.sh help +``` +* The installation templates (LDIF files and `re2o/settings_locale.example.py`) have been changed to use `example.net` instead of `example.org` (more neutral and generic) diff --git a/README.md b/README.md index a99a76f2..d3de9163 100644 --- a/README.md +++ b/README.md @@ -18,165 +18,10 @@ le réseau (adhérent à jour de cotisation). # Installation -## Installation des dépendances +Un tutoriel pour installer le projet est disponible [sur le wiki](https://gitlab.federez.net/federez/re2o/wikis/User%20Documentation/Quick%20Start). -L'installation comporte 3 partie : le serveur web où se trouve le depot re2o -ainsi que toutes ses dépendances, le serveur bdd (mysql ou pgsql) et le -serveur ldap. Ces 3 serveurs peuvent en réalité être la même machine, ou séparés -(recommandé en production). -Le serveur web sera nommé serveur A, le serveur bdd serveur B et le serveur ldap -serveur C. - -### Prérequis sur le serveur A - -Voici la liste des dépendances à installer sur le serveur principal (A). - -### Avec apt : - -#### Sous debian 9 - -Paquets obligatoires: - * python3-django (1.10, stretch) - * python3-dateutil (stretch) - * texlive-latex-base (stretch) - * texlive-fonts-recommended (strech) - * python3-djangorestframework (stretch) - * python3-django-reversion (stretch) - * python3-pip (stretch) - -Paquet recommandés: - * python3-django-extensions (stretch) - - -### Autres dépendances : - -Paquets préalables à installer avec apt : - * libsasl2-dev (stable) - * libldap2-dev (stable) - * libssl-dev (stable) - -Avec pip3 (pip3 install): - * django-bootstrap3 - * django-ldapdb - * django-macaddress - -Moteur de db conseillé (mysql), postgresql fonctionne également. -Pour mysql, il faut installer : - * python3-mysqldb - * mysql-client - -### Prérequis sur le serveur B - -Sur le serveur B, installer mysql ou postgresql, dans la version stretch. - * mysql-server (stretch) ou postgresql (stretch) - -### Prérequis sur le serveur C -Sur le serveur C (ldap), avec apt : - * slapd (stretch) - -### Installation sur le serveur principal A - -Cloner le dépot re2o à partir du gitlab, par exemple dans /var/www/re2o. -Ensuite, il faut créer le fichier settings_local.py dans le sous dossier re2o, -un settings_local.example.py est présent. Les options sont commentées, et des -options par défaut existent. - -En particulier, il est nécessaire de générer un login/mdp admin pour le ldap et -un login/mdp pour l'utilisateur sql (cf ci-dessous), à mettre dans -settings_local.py - -### Installation du serveur mysql/postgresql sur B - -Sur le serveur mysql ou postgresl, il est nécessaire de créer une base de -donnée re2o, ainsi qu'un user re2o et un mot de passe associé. -Ne pas oublier de faire écouter le serveur mysql ou postgresql avec les acl -nécessaire pour que A puisse l'utiliser. - -#### Mysql -Voici les étapes à éxecuter pour mysql : - * CREATE DATABASE re2o collate='utf8_general_ci'; - * CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; - * GRANT ALL PRIVILEGES ON re2o.* TO 'newuser'@'localhost'; - * FLUSH PRIVILEGES; - -#### Postgresql - * CREATE DATABASE re2o ENCODING 'UTF8' LC_COLLATE='fr_FR.UTF-8' -LC_CTYPE='fr_FR.UTF-8'; - * CREATE USER newuser with password 'password'; - * ALTER DATABASE re2o owner to newuser; - -Si les serveurs A et B ne sont pas la même machine, il est nécessaire de -remplacer localhost par l'ip avec laquelle A contacte B dans les commandes -du dessus. -Une fois ces commandes effectuées, ne pas oublier de vérifier que newuser et -password sont présents dans settings_local.py - -### Installation du serveur ldap sur le serveur C - -Ceci se fait en plusieurs étapes : - * générer un login/mdp administrateur (par example mkpasswd sous debian) - * Copier depuis re2o/install_utils (dans le dépot re2o) les fichiers db.ldiff -et schema.ldiff (normalement sur le serveur A) sur le serveur C -(par ex dans /tmp) - * Hasher le mot de passe généré en utilisant la commande slappasswd -(installée par slapd) - * Remplacer toutes les sections FILL_IN par le hash dans schema.ldiff et -db.ldiff - * Remplacer dans schema.ldiff et db.ldiff 'dc=example,dc=org' par le -suffixe de l'organisation - * Arréter slapd - * Supprimer les données existantes : '''rm -rf /etc/ldap/slapd.d/*''' et -'''rm -rf /var/lib/ldap/*''' - * Injecter le nouveau schéma : -'''slapadd -n 0 -l schema.ldiff -F /etc/ldap/slapd.d/''' et -'''slapadd -n 1 -l db.ldiff''' - * Réparer les permissions (chown -R openldap:openldap /etc/ldap/slapd.d et -chown -R openldap:openldap /var/lib/ldap) puis relancer slapd - -Pour visualiser et éditer le ldap, l'utilisation de shelldap est fortement -recommandée, en utilisant en binddn et basedn tous deux égaux à 'cn=config' et -binddpw le mot de passe admin. - -Rajouter (exemple de chemin de fichier avec un certif LE): -`olcTLSCertificateKeyFile: /etc/letsencrypt/live/HOSTNAME/privkey.pem -olcTLSCACertificateFile: /etc/letsencrypt/live/HOSTNAME/chain.pem -olcTLSCertificateFile: /etc/letsencrypt/live/HOSTNAME/cert.pem ` - -Mettre à jour la partie ldap du `settings_local.py` (mettre 'TLS' à True -si besoin, user cn=config,dc=example,dc=org et mot de passe -ldap choisi précédemment). - -## Configuration initiale - -Normalement à cette étape, le ldap et la bdd sql sont configurées correctement. - -Il faut alors lancer dans le dépot re2o '''python3 manage.py migrate''' qui -va structurer initialement la base de données. -Les migrations sont normalement comitées au fur et à mesure, néanmoins cette -étape peut crasher, merci de reporter les bugs. - -## Démarer le site web - -Il faut utiliser un moteur pour servir le site web. Nginx ou apache2 sont -recommandés. -Pour apache2 : - * apt install apache2 - * apt install libapache2-mod-wsgi-py3 (pour le module wsgi) - -Un example de site apache2 se trouve dans install_utils ( re2o.conf) -re2o/wsgi.py permet de fonctionner avec apache2 en production - -## Configuration avancée - -Une fois démaré, le site web devrait être accessible. -Pour créer un premier user, faire '''python3 manage.py createsuperuser''' -qui va alors créer un user admin. -Il est conseillé de créer un user portant le nom de -l'association/organisation, qui possedera l'ensemble des machines, à indiquer -dans le menu reglages sur l'interface. - -## Installations Optionnelles -### Générer le schéma des dépendances +# Installations Optionnelles +## Générer le schéma des dépendances Pour cela : * apt install python3-django-extensions diff --git a/apt_requirements.txt b/apt_requirements.txt new file mode 100644 index 00000000..18f81b78 --- /dev/null +++ b/apt_requirements.txt @@ -0,0 +1,16 @@ +python3-django +python3-dateutil +texlive-latex-base +texlive-fonts-recommended +python3-djangorestframework +python3-django-reversion +python3-pip +libsasl2-dev libldap2-dev +libssl-dev +python3-crypto +python3-git +javascript-common +libjs-jquery +libjs-jquery-ui +libjs-jquery-timepicker +libjs-bootstrap diff --git a/install_re2o.sh b/install_re2o.sh index d755eb05..6168ec08 100755 --- a/install_re2o.sh +++ b/install_re2o.sh @@ -1,456 +1,847 @@ #!/bin/bash -setup_ldap() { - apt-get -y install slapd +SETTINGS_LOCAL_FILE='re2o/settings_local.py' +SETTINGS_EXAMPLE_FILE='re2o/settings_local.example.py' - echo "Hashage du mot de passe ldap..." - hashed_ldap_passwd=$(slappasswd -s $1) +APT_REQ_FILE="apt_requirements.txt" +PIP_REQ_FILE="pip_requirements.txt" - echo $hashed_ldap_passwd - echo "Formatage des fichiers de config ldap" - sed 's|dc=example,dc=org|'"$2"'|g' install_utils/db.ldiff | sed 's|FILL_IT|'"$hashed_ldap_passwd"'|g' > /tmp/db - sed 's|dc=example,dc=org|'"$2"'|g' install_utils/schema.ldiff | sed 's|FILL_IT|'"$hashed_ldap_passwd"'|g' > /tmp/schema +LDIF_DB_FILE="install_utils/db.ldiff" +LDIF_SCHEMA_FILE="install_utils/schema.ldiff" - echo "Destruction config ldap existante" - service slapd stop - rm -rf /etc/ldap/slapd.d/* - rm -rf /var/lib/ldap/* - echo "Ecriture de la configuration actuelle" - slapadd -n 0 -l /tmp/schema -F /etc/ldap/slapd.d/ - slapadd -n 1 -l /tmp/db +VALUE= # global value used to return values by some functions - echo "Reparation des permissions et redémarage de slapd" - chown -R openldap:openldap /etc/ldap/slapd.d - chown -R openldap:openldap /var/lib/ldap - service slapd start +_ask_value() { + ### Usage _ask_value [ [ ... ] ] + # + # This function is a utility function to force a user to enter a value + # available in a set of options. + # + # Parameters: + # * text: The text to display + # * option#: A possible option for the user. If no option is specifed, + # all inputs are considered valid + # + # Echo: The value entered by the user. Should be one of the choices if + # not ommited + ### + + shopt -s extglob + + input_text="$1" + shift + if [ "$#" -ne 0 ]; then + choices="(" + while [ "$#" -ne 1 ]; do + choices+="$1|" + shift + done + choices+="$1)" + input_text+=" $choices: " + choices="@$choices" + else + input_text+=": " + choices="@(*)" + fi + + while true; do + read -p "$input_text" choice + case "$choice" in + $choices ) break;; + * ) echo "Invalid option";; + esac + done + + VALUE="$choice" } -install_re2o_server() { -echo "Installation de Re2o ! -Cet utilitaire va procéder à l'installation initiale de re2o. Le serveur présent doit être vierge. -Preconfiguration..." -export DEBIAN_FRONTEND=noninteractive +install_requirements() { + ### Usage: install_requirements + # + # This function will install the required packages from APT repository + # and Pypi repository. Those packages are all required for Re2o to work + # properly. + ### -apt-get -y install sudo dialog - -HEIGHT=15 -WIDTH=40 -init=$(dialog --clear \ - --title "Installation de Re2o !" \ - --msgbox "Cet utilitaire va procéder à l'installation initiale de re2o. Le serveur présent doit être vierge de préférence. Preconfiguration..." \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) - - -HEIGHT=15 -WIDTH=40 -CHOICE_HEIGHT=4 -BACKTITLE="Preconfiguration re2o" -MENU="Choisir une option" - -TITLE="Choix du moteur bdd" -OPTIONS=(1 "mysql" - 2 "postgresql") - -sql_bdd_type=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) - -clear - - -TITLE="Extension locale (ex : example.org)" - -extension_locale=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear - -IFS='.' read -a extension_locale_array <<< $extension_locale - - -for i in "${extension_locale_array[@]}" -do - ldap_dn+="dc=$i," -done -ldap_dn=${ldap_dn::-1} -echo $ldap_dn - -TITLE="Emplacement de la bdd" -OPTIONS=(1 "Local" - 2 "Distant") - -sql_is_local=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) - -clear - -TITLE="Mot de passe sql" - -sql_password=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear - - -if [ $sql_is_local == 2 ] -then -TITLE="Login sql" -sql_login=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -TITLE="Nom de la bdd sql" -sql_name=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -TITLE="Hote de la base de donnée" -sql_host=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -else -sql_name="re2o" -sql_login="re2o" -sql_host="localhost" -fi - -mysql_command="CREATE DATABASE $sql_name collate='utf8_general_ci'; -CREATE USER '$sql_login'@'localhost' IDENTIFIED BY '$sql_password'; -GRANT ALL PRIVILEGES ON $sql_name.* TO '$sql_login'@'localhost'; -FLUSH PRIVILEGES;" - -pgsql_command1="CREATE DATABASE $sql_name ENCODING 'UTF8' LC_COLLATE='fr_FR.UTF-8' LC_CTYPE='fr_FR.UTF-8';" -pgsql_command2="CREATE USER $sql_login with password '$sql_password';" -pgsql_command3="ALTER DATABASE $sql_name owner to $sql_login;" - -TITLE="Emplacement du ldap" -OPTIONS=(1 "Local" - 2 "Distant") - -ldap_is_local=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) - - -HEIGHT=15 -WIDTH=40 -instal_ldap=$(dialog --clear \ - --title "Installation de Re2o !" \ - --msgbox "Vous devrez fournir un login/host dans le cas où le ldap est non local" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) - -TITLE="Mot de passe ldap" -ldap_password=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -if [ $ldap_is_local == 2 ] -then -TITLE="Cn ldap admin" -ldap_cn=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -TITLE="Hote ldap" -ldap_host=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -else -ldap_cn="cn=admin," -ldap_cn+=$ldap_dn -ldap_host="localhost" -fi - - -TITLE="Hôte pour l'envoi de mail" -email_host=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) - -TITLE="Port du serveur mail" -OPTIONS=(25 "25 (SMTP)" - 465 "465 (SMTPS)" - 587 "587 (Submission)") - -email_port=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) -clear -if [ $ldap_is_local == 2 ] -then -TITLE="Cn ldap admin" -ldap_cn=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -TITLE="Hote ldap" -ldap_host=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear -else -ldap_cn="cn=admin," -ldap_cn+=$ldap_dn -ldap_host="localhost" -fi - -HEIGHT=15 -WIDTH=40 -install_base=$(dialog --clear \ - --title "Installation de Re2o !" \ - --msgbox "Installation des paquets de base" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) - -echo "Installation des paquets de base" -apt-get -y install python3-django python3-dateutil texlive-latex-base texlive-fonts-recommended python3-djangorestframework python3-django-reversion python3-pip libsasl2-dev libldap2-dev libssl-dev python3-crypto python3-git -pip3 install django-bootstrap3 -pip3 install django-ldapdb -pip3 install django-macaddress - -if [ $sql_bdd_type == 1 ] -then - apt-get -y install python3-mysqldb mysql-client - if [ $sql_is_local == 1 ] - then - apt-get -y install mysql-server - mysql -u root --execute="$mysql_command" - else - echo "Veuillez saisir la commande suivante sur le serveur sql distant, puis validez" - echo $mysql_command - while true; do - read -p "Continue (y/n)?" choice - case "$choice" in - y|Y ) break;; - n|N ) exit;; - * ) echo "invalid";; - esac - done - fi -else - apt-get -y install postgresql-client - apt-get -y install python3-psycopg2 - if [ $sql_is_local == 1 ] - then - apt-get -y install postgresql - sudo -u postgres psql --command="$pgsql_command1" - sudo -u postgres psql --command="$pgsql_command2" - sudo -u postgres psql --command="$pgsql_command3" - else - echo "Veuillez saisir la commande suivante sur le serveur sql distant, puis validez" - echo sudo -u postgres psql $pgsql_command1 - echo sudo -u postgres psql $pgsql_command2 - echo sudo -u postgres psql $pgsql_command3 - while true; do - read -p "Continue (y/n)?" choice - case "$choice" in - y|Y ) break;; - n|N ) exit;; - * ) echo "invalid";; - esac - done - fi -fi - -if [ $ldap_is_local == 1 ] -then - -setup_ldap $ldap_password $ldap_dn - -else - -HEIGHT=15 -WIDTH=40 -ldap_setup=$(dialog --clear \ - --title "Setup ldap" \ - --msgbox "Vous devrez manuellement effectuer les opérations de setup de la base ldap sur le serveurs distant. Lancez la commande : ./install_re2o.sh ldap $ldap_password $ldap_dn" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -fi - -echo "Ecriture de settings_local" - -django_secret_key=$(python -c "import random; print(''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%=+') for i in range(50)]))") -aes_key=$(python -c "import random; print(''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%=+') for i in range(32)]))") - -cp re2o/settings_local.example.py re2o/settings_local.py -if [ $sql_bdd_type == 1 ] -then - sed -i 's/db_engine/django.db.backends.mysql/g' re2o/settings_local.py -else - sed -i 's/db_engine/django.db.backends.postgresql_psycopg2/g' re2o/settings_local.py -fi -sed -i 's/SUPER_SECRET_KEY/'"$django_secret_key"'/g' re2o/settings_local.py -sed -i 's/THE_AES_KEY/'"$aes_key"'/g' re2o/settings_local.py -sed -i 's/SUPER_SECRET_DB/'"$sql_password"'/g' re2o/settings_local.py -sed -i 's/db_name_value/'"$sql_name"'/g' re2o/settings_local.py -sed -i 's/db_user_value/'"$sql_login"'/g' re2o/settings_local.py -sed -i 's/db_host_value/'"$sql_host"'/g' re2o/settings_local.py -sed -i 's/ldap_dn/'"$ldap_cn"'/g' re2o/settings_local.py -sed -i 's/SUPER_SECRET_LDAP/'"$ldap_password"'/g' re2o/settings_local.py -sed -i 's/ldap_host_ip/'"$ldap_host"'/g' re2o/settings_local.py -sed -i 's/dc=example,dc=org/'"$ldap_dn"'/g' re2o/settings_local.py -sed -i 's/example.org/'"$extension_locale"'/g' re2o/settings_local.py -sed -i 's/MY_EMAIL_HOST/'"$email_host"'/g' re2o/settings_local.py -sed -i 's/MY_EMAIL_PORT/'"$email_port"'/g' re2o/settings_local.py - -HEIGHT=15 -WIDTH=40 -migrations=$(dialog --clear \ - --title "Setup django" \ - --msgbox "Application des migrations" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -python3 manage.py migrate - -HEIGHT=15 -WIDTH=40 -static=$(dialog --clear \ - --title "Setup django" \ - --msgbox "Collecte des statiques" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -python3 manage.py collectstatic - -BACKTITLE="Fin de l'installation" -TITLE="Serveur web à utiliser" -OPTIONS=(1 "apache2" - 2 "nginx") - -web_serveur=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) - -clear - -TITLE="Url où servir le serveur web (ex : re2o.example.org). Assurez-vous que ce tld existe bien et répond auprès du DNS" -url_server=$(dialog --title "$TITLE" \ - --backtitle "$BACKTITLE" \ - --inputbox "$TITLE" $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) -clear - -TITLE="Utiliser tls et générer automatiquement le certificat LE ?" -OPTIONS=(1 "Oui" - 2 "Non") - -is_tls=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) - -clear - -sed -i 's/URL_SERVER/'"$url_server"'/g' re2o/settings_local.py - - -if [ $web_serveur == 1 ] -then -apt-get -y install apache2 libapache2-mod-wsgi-py3 -a2enmod ssl -a2enmod wsgi -if [ $is_tls == 1 ] -then -cp install_utils/apache2/re2o-tls.conf /etc/apache2/sites-available/re2o.conf -apt-get -y install certbot -apt-get -y install python-certbot-apache -certbot certonly --rsa-key-size 4096 --apache -d $url_server -sed -i 's/LE_PATH/'"$url_server"'/g' /etc/apache2/sites-available/re2o.conf -else -cp install_utils/apache2/re2o.conf /etc/apache2/sites-available/re2o.conf -fi -rm /etc/apache2/sites-enabled/000-default.conf -sed -i 's|URL_SERVER|'"$url_server"'|g' /etc/apache2/sites-available/re2o.conf -current_path=$(pwd) -sed -i 's|PATH|'"$current_path"'|g' /etc/apache2/sites-available/re2o.conf -a2ensite re2o -service apache2 reload -else -HEIGHT=15 -WIDTH=40 -web_server=$(dialog --clear \ - --title "Setup serveur web" \ - --msgbox "Nginx non supporté, vous devrez installer manuellement" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) - -fi - -python3 manage.py createsuperuser - -HEIGHT=15 -WIDTH=40 -end=$(dialog --clear \ - --title "Installation terminée" \ - --msgbox "Vous pouvez à présent vous rendre sur $url_server, et vous connecter. Votre utilisateur dispose des privilèges superuser" \ - $HEIGHT $WIDTH \ - 2>&1 >/dev/tty) + echo "Setting up the required packages ..." + cat $APT_REQ_FILE | xargs apt-get -y install + pip3 install -r $PIP_REQ_FILE + echo "Setting up the required packages: Done" } -apt install libjs-jquery -apt install libjs-jquery-ui -apt install libjs-jquery-timepicker -apt install libjs-bootstrap + + +install_database() { + ### Usage: install_database + # + # This function will install the database by downloading the correct APT packages + # and initiating the database schema. + # + # Parameters: + # * engine_type: The DB engine to use. + # 1 = mysql + # 2 = postgresql + # * local_setup: Should the database be installed locally + # 1 = yes + # 2 = no + # * db_name: The name of the database itself + # * username: The username to access the database + # * password: The password of the user to access the database + ### + + echo "Setting up the database ..." + + engine_type="$1" + local_setup="$2" + db_name="$3" + username="$4" + password="$5" + + if [ "$engine_type" == 1 ]; then + + echo "Installing MySQL client ..." + apt-get -y install python3-mysqldb mysql-client + echo "Installing MySQL client: Done" + + mysql_command="CREATE DATABASE $db_name collate='utf8_general_ci'; + CREATE USER '$username'@'localhost' IDENTIFIED BY '$password'; + GRANT ALL PRIVILEGES ON $db_name.* TO '$username'@'localhost'; + FLUSH PRIVILEGES;" + + if [ "$local_setup" == 1 ]; then + echo "Setting up local MySQL server ..." + apt-get -y install mysql-server + mysql -u root --execute="$mysql_command" + echo "Setting up local MySQL server: Done" + else + echo "Please execute the following command on the remote SQL server and then continue" + echo "$mysql_command" + _ask_value "Continue" "yes" "no"; if [ "$VALUE" == "no" ]; then exit; fi + fi + + else + + echo "Installing PostgreSQL client ..." + apt-get -y install postgresql-client python3-psycopg2 + echo "Installing PostgreSQL client: Done" + + pgsql_command1="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='fr_FR.UTF-8' LC_CTYPE='fr_FR.UTF-8';" + pgsql_command2="CREATE USER $username with password '$password';" + pgsql_command3="ALTER DATABASE $db_name owner to $username;" + + if [ "$local_setup" == 1 ]; then + echo "Setting up local PostgreSQL server ..." + apt-get -y install postgresql + sudo -u postgres psql --command="$pgsql_command1" + sudo -u postgres psql --command="$pgsql_command2" + sudo -u postgres psql --command="$pgsql_command3" + echo "Setting up local PostgreSQL server: Done" + else + echo "Please execute the following commands on the remote SQL server and then continue" + echo "sudo -u postgres psql $pgsql_command1" + echo "sudo -u postgres psql $pgsql_command2" + echo "sudo -u postgres psql $pgsql_command3" + _ask_value "Continue" "yes" "no"; if [ "$VALUE" == "no" ]; then exit; fi + fi + + fi + + echo "Setting up the database: Done" +} + + + +install_ldap() { + ### Usage: install_ldap + # + # This function will install the LDAP + # + # Parameters: + # * local_setup: Should the LDAP be installed locally ? + # 1 = yes + # 2 = no + # * password: the clear password for the admin user of the LDAP + # * domain: the domain extension to use for the LDAP structure in LDAP notation + ### + + echo "Setting up the LDAP ..." + + local_setup="$1" + password="$2" + domain="$3" + + if [ "$local_setup" == 1 ]; then + + echo "Installing slapd package ..." + apt-get -y install slapd + echo "Installing slapd package: Done" + + echo "Hashing the LDAP password ..." + hashed_ldap_passwd="$(slappasswd -s $password)" + echo "Hash of the password: $hashed_ldap_passwd" + + echo "Building the LDAP config files ..." + sed 's|dc=example,dc=net|'"$domain"'|g' $LDIF_DB_FILE | sed 's|FILL_IT|'"$hashed_ldap_passwd"'|g' > /tmp/db + sed 's|dc=example,dc=net|'"$domain"'|g' $LDIF_SCHEMA_FILE | sed 's|FILL_IT|'"$hashed_ldap_passwd"'|g' > /tmp/schema + echo "Building the LDAP config files: Done" + + echo "Stopping slapd service ..." + service slapd stop + echo "Stopping slapd service: Done" + + echo "Deleting exisitng LDAP configuration ..." + rm -rf /etc/ldap/slapd.d/* + rm -rf /var/lib/ldap/* + echo "Deleting existing LDAP configuration: Done" + + echo "Setting up the new LDAP configuration ..." + slapadd -n 0 -l /tmp/schema -F /etc/ldap/slapd.d/ + slapadd -n 1 -l /tmp/db + echo "Setting up the new LDAP configuration: Done" + + echo "Fixing the LDAP files permissions ..." + chown -R openldap:openldap /etc/ldap/slapd.d + chown -R openldap:openldap /var/lib/ldap + echo "Fixing the LDAP files permissions: Done" + + echo "Starting slapd service ..." + service slapd start + echo "Starting slapd service: Done" + + else + + echo "Please execute the following command on the remote LDAP server and then continue" + echo "./install_re2o.sh setup-ldap $password $domain" + _ask_value "Continue" "yes" "no"; if [ "$VALUE" == "no" ]; then exit; fi + + fi + + echo "Setting up the LDAP: Done" +} + + + +write_settings_file() { + ### Usage: write_settings_file + # + # + # + # This function will write a clean local settings file based on the example. + # + # Parameters: + # * db_engine_type: The engine for the database + # 1 = MySQL + # 2 = PostgreSQL + # * sql_hostname: The hostname for contacting the database + # * sql_db_name: The name of the database itself + # * sql_username: The user to use to access the database + # * sql_password: The password to use to access the database + # * ldap_cn: The CN entry for the LDAP admin in LDAP notation + # * ldap_tls: Should the TLS be activated to contact the LDAP + # 1 = yes + # 2 = no + # * ldap_password: The password to use to connect to the LDAP + # * ldap_hostname: The hostname for contacting the LDAP + # * ldap_domain: The local domain for the LDAP in LDAP notation + # * email_hostname: The hostname for contacting the mail server + # * email_port: The port for contacting the mail server + # * extension: The extension to use + # * url: The main URL to use for Re2o + ### + + echo "Writing of the settings_local.py file ..." + + db_engine_type="$1" + sql_hostname="$2" + sql_db_name="$3" + sql_username="$4" + sql_password="$5" + ldap_cn="$6" + ldap_tls="$7" + ldap_password="$8" + ldap_hostname="$9" + ldap_domain="${10}" + email_hostname="${11}" + email_port="${12}" + extension="${13}" + url="${14}" + + cp "$SETTINGS_EXAMPLE_FILE" "$SETTINGS_LOCAL_FILE" + + django_secret_key="$(python -c "import random; print(''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%=+') for i in range(50)]))")" + aes_key="$(python -c "import random; print(''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%=+') for i in range(32)]))")" + + if [ "$db_engine_type" == 1 ]; then + sed -i 's/db_engine/django.db.backends.mysql/g' "$SETTINGS_LOCAL_FILE" + else + sed -i 's/db_engine/django.db.backends.postgresql_psycopg2/g' "$SETTINGS_LOCAL_FILE" + fi + sed -i 's/SUPER_SECRET_KEY/'"$django_secret_key"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/SUPER_SECRET_DB/'"$sql_password"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/A_SECRET_AES_KEY/'"$aes_key"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/db_name_value/'"$sql_db_name"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/db_user_value/'"$sql_username"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/db_host_value/'"$sql_hostname"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/ldap_dn/'"$ldap_cn"'/g' "$SETTINGS_LOCAL_FILE" + if [ $ldap_tls == 2 ]; then + sed -i "s/'TLS': True,/# 'TLS': True,/g" "$SETTINGS_LOCAL_FILE" + fi + sed -i 's/SUPER_SECRET_LDAP/'"$ldap_password"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/ldap_host_ip/'"$ldap_hostname"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/dc=example,dc=net/'"$ldap_domain"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/example.net/'"$extension"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/MY_EMAIL_HOST/'"$email_hostname"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/MY_EMAIL_PORT/'"$email_port"'/g' "$SETTINGS_LOCAL_FILE" + sed -i 's/URL_SERVER/'"$url"'/g' "$SETTINGS_LOCAL_FILE" + + echo "Writing of the settings_local.py file: Done" +} + + + +update_django() { + ### Usage: update_django + # + # This function will update the Django project by applying the migrations + # and collecting the statics + ### + + echo "Applying Django migrations ..." + python3 manage.py migrate + echo "Applying Django migrations: Done" + + echo "Collecting web frontend statics ..." + python3 manage.py collectstatic --noinput + echo "Collecting web frontend statics: Done" +} + + + +create_superuser() { + ### Usage: create_superuser + # + # This will create a user with the superuser rights for the project. + + echo "Creating a superuser ..." + python3 manage.py createsuperuser + echo "Creating a superuser: Done" +} + + + +install_webserver() { + ### Usage: install_webserver + # + # This function will install the web server by installing the correct APT packages + # and configure it + # + # Parameters: + # * engine_type: The engine to use as a web server + # 1 = Apache2 + # 2 = NginX + # * tls: Should the TLS (with LE) be generated and activated + # 1 = yes + # 2 = no + # * url: The url to access Re2o. This parameter is only used if TLS is activated + # for generating the certifcate with the right domain name + ### + + echo "Setting up web server ..." + + engine_type="$1" + tls="$2" + url="$3" + + if [ "$engine_type" == 1 ]; then + + echo "Setting up Apache2 web server ..." + + apt-get -y install apache2 libapache2-mod-wsgi-py3 + a2enmod ssl + a2enmod wsgi + a2enconf javascript-common + + if [ "$tls" == 1 ]; then + echo "Setting up TLS with LE for Apache2 web server ..." + cp install_utils/apache2/re2o-tls.conf /etc/apache2/sites-available/re2o.conf + apt-get -y install certbot + apt-get -y install python-certbot-apache + certbot certonly --rsa-key-size 4096 --apache -d "$url" + sed -i 's/LE_PATH/'"$url"'/g' /etc/apache2/sites-available/re2o.conf + echo "Setting up TLS with LE for Apache2 web server: Done" + else + cp install_utils/apache2/re2o.conf /etc/apache2/sites-available/re2o.conf + fi + + rm /etc/apache2/sites-enabled/000-default.conf + sed -i 's|URL_SERVER|'"$url"'|g' /etc/apache2/sites-available/re2o.conf + sed -i 's|PATH|'"$(pwd)"'|g' /etc/apache2/sites-available/re2o.conf + a2ensite re2o + + echo "Setting up Apache2 web server: Done" + + echo "Reloading Apache2 service ..." + service apache2 reload + echo "Reloading Apache2 service: Done" + + else + + echo "Nginx automatic setup is not supported. Please configure it manually." + echo "Please confirm you have acknowledged this message." + _ask_value "Acknowledged" "yes" + + fi + + echo "Setting up web server: Done" +} + + + +interactive_guide() { + ### Usage: interactive_guide + # + # This function will guide through the automated setup of Re2o by asking + # the user for some informations and some installation choices. It will + # then proceed to setup and configuration of the required tools according + # to the user choices. + ### + + echo "Re2o setup !" + echo "This tool will help you setup re2o. It is highly recommended to use a Debian clean server for this operation." + + echo "Installing basic packages required for this script to work ..." + apt-get -y install sudo dialog + echo "Installing basic packages required for this script to work: Done" + + # Common setup for the dialog prompts + export DEBIAN_FRONTEND=noninteractive + HEIGHT=20 + WIDTH=60 + CHOICE_HEIGHT=4 + + + + ############# + ## Welcome ## + ############# + + BACKTITLE="Re2o setup" + + # Welcome prompt + TITLE="Welcome" + MSGBOX="This tool will help you setup re2o. It is highly recommended to use a Debian clean server for this operation." + init="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --msgbox "$MSGBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + + + ###################### + ## Database options ## + ###################### + + BACKTITLE="Re2o setup - configuration of the database" + + # Prompt for choosing the database engine + TITLE="Database engine" + MENU="Which engine should be used as the database ?" + OPTIONS=(1 "mysql" + 2 "postgresql") + sql_bdd_type="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + # Prompt for choosing the database location + TITLE="SQL location" + MENU="Where to install the SQL database ? + * 'Local' will setup everything automatically but is not recommended for production + * 'Remote' will ask you to manually perform some setup commands on the remote server" + OPTIONS=(1 "Local" + 2 "Remote") + sql_is_local="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + if [ $sql_is_local == 2 ]; then + # Prompt to enter the remote database hostname + TITLE="SQL hostname" + INPUTBOX="The hostname of the remote SQL database" + sql_host="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + # Prompt to enter the remote database name + TITLE="SQL database name" + INPUTBOX="The name of the remote SQL database" + sql_name="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + # Prompt to enter the remote database username + TITLE="SQL username" + INPUTBOX="The username to access the remote SQL database" + sql_login="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + clear + else + # Use of default values for local setup + sql_name="re2o" + sql_login="re2o" + sql_host="localhost" + fi + + # Prompt to enter the database password + TITLE="SQL password" + INPUTBOX="The password to access the SQL database" + sql_password="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + + + ################## + ## LDAP options ## + ################## + + BACKTITLE="Re2o setup - configuration of the LDAP" + + # Prompt to choose the LDAP location + TITLE="LDAP location" + MENU="Where would you like to install the LDAP ? + * 'Local' will setup everything automatically but is not recommended for production + * 'Remote' will ask you to manually perform some setup commands on the remote server" + OPTIONS=(1 "Local" + 2 "Remote") + ldap_is_local="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + # Prompt to enter the LDAP domain extension + TITLE="Domain extension" + INPUTBOX="The local domain extension to use (e.g. 'example.net'). This is used in the LDAP configuration." + extension_locale="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + # Building the DN of the LDAP from the extension + IFS='.' read -a extension_locale_array <<< $extension_locale + for i in "${extension_locale_array[@]}" + do + ldap_dn+="dc=$i," + done + ldap_dn="${ldap_dn::-1}" + + if [ "$ldap_is_local" == 2 ]; then + # Prompt to enter the remote LDAP hostname + TITLE="LDAP hostname" + INPUTBOX="The hostname of the remote LDAP" + ldap_host="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + # Prompt to choose if TLS should be activated or not for the LDAP + TITLE="TLS on LDAP" + MENU="Would you like to activate TLS for communicating with the remote LDAP ?" + OPTIONS=(1 "Yes" + 2 "No") + ldap_tls="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --MENU "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + # Prompt to enter the admin's CN of the remote LDAP + TITLE="CN of amdin user" + INPUTBOX="The CN entry for the admin user of the remote LDAP" + ldap_cn="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + else + ldap_cn="cn=admin," + ldap_cn+="$ldap_dn" + ldap_host="localhost" + ldap_tls=2 + fi + + # Prompt to enter the LDAP password + TITLE="LDAP password" + INPUTBOX="The password to access the LDAP" + ldap_password="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + + + ######################### + ## Mail server options ## + ######################### + + BACKTITLE="Re2o setup - configuration of the mail server" + + # Prompt to enter the hostname of the mail server + TITLE="Mail server hostname" + INPUTBOX="The hostname of the mail server to use" + email_host="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$TITLE" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + # Prompt to choose the port of the mail server + TITLE="Mail server port" + MENU="Which port (thus which protocol) to use to contact the mail server" + OPTIONS=(25 "SMTP" + 465 "SMTPS" + 587 "Submission") + email_port="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + + + ######################## + ## Web server options ## + ######################## + + BACKTITLE="Re2o setup - configuration of the web server" + + # Prompt to choose the web server + TITLE="Web server to use" + MENU="Which web server to install for accessing Re2o web frontend (automatic setup of nginx is not supported) ?" + OPTIONS=(1 "apache2" + 2 "nginx") + web_serveur="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + # Prompt to enter the requested URL for the web frontend + TITLE="Web URL" + INPUTBOX="URL for accessing the web server (e.g. re2o.example.net). Be sure that this URL is accessible and correspond to a DNS entry (if applicable)." + url_server="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --inputbox "$INPUTBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + # Prompt to choose if the TLS should be setup or not for the web server + TITLE="TLS on web server" + MENU="Would you like to activate the TLS (with Let'Encrypt) on the web server ?" + OPTIONS=(1 "Yes" + 2 "No") + is_tls="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT "${OPTIONS[@]}" 2>&1 >/dev/tty)" + + + + ############################### + ## End of configuration step ## + ############################### + + BACKTITLE="Re2o setup" + + # Prompt to inform the config setup is over + TITLE="End of configuration step" + MSGBOX="The configuration step is now finished. The script will now perform the following actions: + * Install the required packages + * Install and setup the requested database if 'local' has been selected + * Install and setup the ldap if 'local' has been selected + * Write a local version of 'settings_local.py' file with the previously given informations + * Apply the Django migrations for the project + * Collect the statics for the web interface + * Install and setup the requested web server + * Install and setup a TLS certificate for the web server if requested" + end_config="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --msgbox "$MSGBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" + + clear + + + + ################################ + ## Perform the actual actions ## + ################################ + + install_requirements + + install_database "$sql_bdd_type" "$sql_is_local" "$sql_name" "$sql_login" "$sql_password" + + install_ldap "$ldap_is_local" "$ldap_password" "$ldap_dn" + + + write_settings_file "$sql_bdd_type" "$sql_host" "$sql_name" "$sql_login" "$sql_password" \ + "$ldap_cn" "$ldap_tls" "$ldap_password" "$ldap_host" "$ldap_dn" \ + "$email_host" "$email_port" "$extension_locale" "$url_server" + + update_django + + create_superuser + + install_webserver "$web_serveur" "$is_tls" "$url_server" + + + + ########################### + ## End of the setup step ## + ########################### + + BACKTITLE="Re2o setup" + + # Prompt to inform the installation process is over + TITLE="End of the setup" + MSGBOX="You can now visit $url_server and connect with the credentials you just entered. This user has the superuser rights, meaning he can access and do everything." + end="$(dialog --clear --backtitle "$BACKTITLE" \ + --title "$TITLE" --msgbox "$MSGBOX" \ + $HEIGHT $WIDTH 2>&1 >/dev/tty)" +} + + + + +interactive_update_settings() { + ### Usage: interactvie_update_settings + # + # This function will take the parameters in the example settings file, retrieve the + # existing parameters from the local settings file and ask the user for the missing parameters + ### + _ask_value "Database engine" "mysql" "postgresql"; if [ "$VALUE" == "mysql" ]; then db_engine_type=1; else db_engine_type=2; fi + _ask_value "Database hostname"; sql_hostname="$VALUE" + _ask_value "Database name"; sql_db_name="$VALUE" + _ask_value "Database username"; sql_username="$VALUE" + _ask_value "Database password"; sql_password="$VALUE" + _ask_value "LDAP hostname"; ldap_hostname="$VALUE" + _ask_value "Activate TLS on LDAP" "yes" "no"; if [ "$VALUE" == "mysql" ]; then ldap_tls=1; else ldap_tls=2; fi + _ask_value "LDAP domain (e.g. 'dc=example,dc=net')"; ldap_domain="$VALUE" + _ask_value "LDAP admin CN entry (e.g. 'cn=admin,dc=example,dc=net')"; ldap_cn="$VALUE" + _ask_value "LDAP password"; ldap_password="$VALUE" + _ask_value "Mail server hostname"; email_hostname="$VALUE" + _ask_value "Mail server port" "25" "465" "587"; email_port="$VALUE" + _ask_value "Extension de domain (e.g. 'example.net')"; extension="$VALUE" + _ask_value "Main URL"; url="$VALUE" + write_settings_file "$db_engine_type" "$sql_hostname" "$sql_db_name" "$sql_username" "$sql_password" \ + "$ldap_cn" "$ldap_tls" "$ldap_password" "$ldap_hostname" "$ldap_domain" \ + "$email_hostname" "$email_port" "$extension" "$url" + +} + + main_function() { -if [ ! -z "$1" ] -then -if [ $1 == ldap ] -then -if [ ! -z "$2" ] -then -echo Installation du ldap -setup_ldap $2 $3 -else -echo Arguments invalides ! -exit -fi -fi -else -install_re2o_server -fi + ### Usage: main_function [subcommand [options]] + # + # This function will parse the arguments to determine which part of the tool to start. + # Refer to the help message below for the details of the parameters + ### + + if [ -z "$1" ] || [ "$1" == "help" ]; then + echo "" + echo "Usage: install_re2o [subcommand [options]]" + echo "" + echo "The 'install_re2o' script is a utility script to setup, configure, reset and update" + echo "some components of re2o. Please refer to the following details for more." + echo "" + echo "Sub-commands:" + echo " * [no subcommand] - Display this quick usage documentation" + echo " * {help} ---------- Display this quick usage documentation" + echo " * {setup} --------- Launch the full interactive guide to setup entirely" + echo " re2o from scratch" + echo " * {update} -------- Collect frontend statics, install the missing APT" + echo " and pip packages and apply the migrations to the DB" + echo " * {update-django} - Apply Django migration and collect frontend statics" + echo " * {update-packages} Install the missing APT and pip packages" + echo " * {update-settings} Interactively rewrite the settings file" + echo " * {reset-db} ------ Erase the previous local database, setup a new empty" + echo " one and apply the Django migrations on it and collect" + echo " Django statics." + echo " Parameters:" + echo " * -- the clear-text password to connect to the database" + echo " * [db_engine_type] the SQL engine to use ('mysql' or 'postgresql')." + echo " Default is 'mysql'." + echo " * [db_name] ------ the name of the database itself." + echo " Default is 're2o'." + echo " * [db_username] -- the username to connect to the database." + echo " Default is 're2o'." + echo " * {reset-ldap} ---- Erase the previous local LDAP and setup a new empty one" + echo " Parameters:" + echo " * the clear-text password for the admin user of the" + echo " LDAP" + echo " * the domain extension to use for the LDAP structure" + echo " in LDAP notation" + echo "" + else + subcmd="$1" + + case "$subcmd" in + + setup ) + interactive_guide + ;; + + update ) + install_requirements + update_django + ;; + + update-django ) + update_django + ;; + + update-packages ) + install_requirements + ;; + + update-settings ) + interactive_update_settings + ;; + + reset-db ) + if [ ! -z "$2" ]; then + db_password="$2" + case "$3" in + mysql ) + db_engine_type=1;; + postresql ) + db_engine_type=2;; + * ) + db_engine_type=1;; + esac + if [ ! -z "$4" ]; then + db_name="$4" + else + db_name="re2o" + fi + if [ ! -z "$5" ]; then + db_username="$5" + else + db_username="re2o" + fi + install_database "$db_engine_type" 1 "$db_name" "$db_username" "$db_password" + update-django + else + echo "Invalid arguments !" + echo "Usage: install_re2o setup-db [] [] []" + echo "See 'install_re2o help' for further help" + fi + ;; + + reset-ldap ) + if [ ! -z "$2" ] && [ ! -z "$3" ]; then + ldap_password="$2" + local_domain="$3" + install_ldap 1 "$ldap_password" "$local_domain" + else + echo "Invalid arguments !" + echo "Usage: install_re2o setup-ldap " + echo "See 'install_re2o help' for further help" + fi + ;; + + * ) + echo "Unknown subcommand: $subcmd" + echo "Use 'install_re2o help' to display some help" + ;; + + esac + fi } -main_function $1 $2 $3 +main_function "$@" diff --git a/install_utils/db.ldiff b/install_utils/db.ldiff index f73c029e..ed265811 100644 --- a/install_utils/db.ldiff +++ b/install_utils/db.ldiff @@ -1,38 +1,38 @@ -dn: dc=example,dc=org +dn: dc=example,dc=net o: rezo structuralObjectClass: organization entryUUID: fc97a0fe-514b-1034-9e4d-59675b32507b -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20150225150906Z description: ldap objectClass: top objectClass: dcObject objectClass: organization entryCSN: 20151003212702.245118Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20151003212702Z contextCSN: 20161004233332.689769Z#000000#000#000000 -dn: cn=admin,dc=example,dc=org +dn: cn=admin,dc=example,dc=net objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin structuralObjectClass: organizationalRole entryUUID: fc97fa72-514b-1034-9e4e-59675b32507b -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20150225150906Z description:: TERBUCBhZG1pbmlzdHJhdG9yDQo= userPassword: FILL_IT entryCSN: 20160604005945.576566Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160604005945Z -dn: cn=Utilisateurs,dc=example,dc=org +dn: cn=Utilisateurs,dc=example,dc=net gidNumber: 500 cn: Utilisateurs structuralObjectClass: posixGroup entryUUID: 5d53854e-5204-1034-8c61-8da535cabdfc -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20150226130856Z sambaSID: 500 uid: Users @@ -41,143 +41,143 @@ objectClass: top objectClass: sambaSamAccount objectClass: radiusprofile entryCSN: 20150226130950.194154Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20150226130950Z -dn: ou=groups,dc=example,dc=org +dn: ou=groups,dc=example,dc=net objectClass: organizationalUnit description: Groupes d'utilisateurs ou: groups structuralObjectClass: organizationalUnit entryUUID: 986aa1b6-bb86-1035-9a4c-2ff0c800ec24 -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160531142039Z entryCSN: 20160531142039.780151Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160531142039Z -dn: ou=services,ou=groups,dc=example,dc=org +dn: ou=services,ou=groups,dc=example,dc=net objectClass: organizationalUnit description: Groupes de comptes techniques ou: services structuralObjectClass: organizationalUnit entryUUID: cbb56904-bc6a-1035-9fbb-3dc3850d88ba -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160601173411Z entryCSN: 20160601173411.088359Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160601173411Z -dn: ou=service-users,dc=example,dc=org +dn: ou=service-users,dc=example,dc=net objectClass: organizationalUnit description: Utilisateurs techniques de l'annuaire ou: service-users structuralObjectClass: organizationalUnit entryUUID: 0e397270-bc6b-1035-9fbd-3dc3850d88ba -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160601173602Z entryCSN: 20160601173602.683304Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160601173602Z -dn: cn=freeradius,ou=service-users,dc=example,dc=org +dn: cn=freeradius,ou=service-users,dc=example,dc=net objectClass: applicationProcess objectClass: simpleSecurityObject cn: freeradius userPassword: FILL_IT structuralObjectClass: applicationProcess entryUUID: 8596e4ec-bc6b-1035-9fbf-3dc3850d88ba -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160601173922Z entryCSN: 20160601173922.944598Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160601173922Z -dn: cn=nssauth,ou=service-users,dc=example,dc=org +dn: cn=nssauth,ou=service-users,dc=example,dc=net objectClass: applicationProcess objectClass: simpleSecurityObject cn: nssauth structuralObjectClass: applicationProcess entryUUID: cfbdadc6-bc6b-1035-9fc4-3dc3850d88ba -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160601174127Z userPassword: FILL_IT entryCSN: 20160603093724.770069Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160603093724Z -dn: cn=auth,ou=services,ou=groups,dc=example,dc=org +dn: cn=auth,ou=services,ou=groups,dc=example,dc=net objectClass: groupOfNames cn: auth -member: cn=nssauth,ou=service-users,dc=example,dc=org +member: cn=nssauth,ou=service-users,dc=example,dc=net structuralObjectClass: groupOfNames entryUUID: 98524836-bc6d-1035-9fc7-3dc3850d88ba -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160601175413Z entryCSN: 20160620005705.309928Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160620005705Z -dn: ou=posix,ou=groups,dc=example,dc=org +dn: ou=posix,ou=groups,dc=example,dc=net objectClass: organizationalUnit description: Groupes de comptes POSIX ou: posix structuralObjectClass: organizationalUnit entryUUID: fbd89c4a-bdb5-1035-9045-d5a09894d93e -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160603090455Z entryCSN: 20160603090455.267192Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160603090455Z -dn: cn=wifi,ou=service-users,dc=example,dc=org +dn: cn=wifi,ou=service-users,dc=example,dc=net objectClass: applicationProcess objectClass: simpleSecurityObject cn: wifi structuralObjectClass: applicationProcess entryUUID: 8cc2d1a6-bdc2-1035-9051-d5a09894d93e -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160603103452Z userPassword: FILL_IT entryCSN: 20160603103638.682210Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160603103638Z -dn: cn=usermgmt,ou=services,ou=groups,dc=example,dc=org +dn: cn=usermgmt,ou=services,ou=groups,dc=example,dc=net objectClass: groupOfNames cn: usermgmt structuralObjectClass: groupOfNames entryUUID: ec01e206-bdc2-1035-9054-d5a09894d93e -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160603103732Z -member: cn=wifi,ou=service-users,dc=example,dc=org +member: cn=wifi,ou=service-users,dc=example,dc=net entryCSN: 20160603103746.897151Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160603103746Z -dn: cn=replica,ou=service-users,dc=example,dc=org +dn: cn=replica,ou=service-users,dc=example,dc=net objectClass: applicationProcess objectClass: simpleSecurityObject cn: replica structuralObjectClass: applicationProcess entryUUID: caef5c54-c0e4-1035-948f-dfe369fe3d4f -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160607101733Z userPassword: FILL_IT entryCSN: 20160607101829.424643Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160607101829Z -dn: cn=readonly,ou=services,ou=groups,dc=example,dc=org +dn: cn=readonly,ou=services,ou=groups,dc=example,dc=net objectClass: groupOfNames cn: readonly structuralObjectClass: groupOfNames entryUUID: f6bd2366-c0e4-1035-9492-dfe369fe3d4f -creatorsName: cn=admin,dc=example,dc=org +creatorsName: cn=admin,dc=example,dc=net createTimestamp: 20160607101846Z -member: cn=replica,ou=service-users,dc=example,dc=org -member: cn=freeradius,ou=service-users,dc=example,dc=org +member: cn=replica,ou=service-users,dc=example,dc=net +member: cn=freeradius,ou=service-users,dc=example,dc=net entryCSN: 20160619214628.287369Z#000000#000#000000 -modifiersName: cn=admin,dc=example,dc=org +modifiersName: cn=admin,dc=example,dc=net modifyTimestamp: 20160619214628Z diff --git a/install_utils/schema.ldiff b/install_utils/schema.ldiff index e8b934aa..e2b0e35f 100644 --- a/install_utils/schema.ldiff +++ b/install_utils/schema.ldiff @@ -1108,35 +1108,35 @@ objectClass: olcDatabaseConfig objectClass: olcHdbConfig olcDatabase: {1}hdb olcDbDirectory: /var/lib/ldap -olcSuffix: dc=example,dc=org +olcSuffix: dc=example,dc=net olcAccess: {0}to attrs=userPassword,sambaNTPassword,mail by self write by an - onymous auth by dn="cn=admin,dc=example,dc=org" write by group="cn - =readonly,ou=services,ou=groups,dc=example,dc=org" read by group=" - cn=usermgmt,ou=services,ou=groups,dc=example,dc=org" write by * no + onymous auth by dn="cn=admin,dc=example,dc=net" write by group="cn + =readonly,ou=services,ou=groups,dc=example,dc=net" read by group=" + cn=usermgmt,ou=services,ou=groups,dc=example,dc=net" write by * no ne olcAccess: {1}to attrs=shadowLastChange,gecos,loginShell by self write by an - onymous auth by dn="cn=admin,dc=example,dc=org" write by group="cn - =readonly,ou=services,ou=groups,dc=example,dc=org" read by group=" - cn=auth,ou=services,ou=groups,dc=example,dc=org" read by group="cn - =usermgmt,ou=services,ou=groups,dc=example,dc=org" write by * none + onymous auth by dn="cn=admin,dc=example,dc=net" write by group="cn + =readonly,ou=services,ou=groups,dc=example,dc=net" read by group=" + cn=auth,ou=services,ou=groups,dc=example,dc=net" read by group="cn + =usermgmt,ou=services,ou=groups,dc=example,dc=net" write by * none olcAccess: {2}to dn.base="" by * read -olcAccess: {3}to dn.sub="ou=groups,dc=example,dc=org" by group="cn= - auth,ou=services,ou=groups,dc=example,dc=org" read by group="cn=re - adonly,ou=services,ou=groups,dc=example,dc=org" read -olcAccess: {4}to dn.sub="cn=Utilisateurs,dc=example,dc=org" by grou - p="cn=auth,ou=services,ou=groups,dc=example,dc=org" read by self r - ead by group="cn=readonly,ou=services,ou=groups,dc=example,dc=org" +olcAccess: {3}to dn.sub="ou=groups,dc=example,dc=net" by group="cn= + auth,ou=services,ou=groups,dc=example,dc=net" read by group="cn=re + adonly,ou=services,ou=groups,dc=example,dc=net" read +olcAccess: {4}to dn.sub="cn=Utilisateurs,dc=example,dc=net" by grou + p="cn=auth,ou=services,ou=groups,dc=example,dc=net" read by self r + ead by group="cn=readonly,ou=services,ou=groups,dc=example,dc=net" read by group="cn=usermgmt,ou=services,ou=groups,dc=example,dc=or g" write -olcAccess: {5}to dn.sub="ou=service-users,dc=example,dc=org" by gro - up="cn=auth,ou=services,ou=groups,dc=example,dc=org" read by group - ="cn=readonly,ou=services,ou=groups,dc=example,dc=org" read -olcAccess: {6}to dn.base="dc=example,dc=org" by * read -olcAccess: {7}to * by dn="cn=admin,dc=example,dc=org" write by self +olcAccess: {5}to dn.sub="ou=service-users,dc=example,dc=net" by gro + up="cn=auth,ou=services,ou=groups,dc=example,dc=net" read by group + ="cn=readonly,ou=services,ou=groups,dc=example,dc=net" read +olcAccess: {6}to dn.base="dc=example,dc=net" by * read +olcAccess: {7}to * by dn="cn=admin,dc=example,dc=net" write by self read by group="cn=readonly,ou=services,ou=groups,dc=example,dc=or g" read olcLastMod: TRUE -olcRootDN: cn=admin,dc=example,dc=org +olcRootDN: cn=admin,dc=example,dc=net olcRootPW: FILL_IT olcDbCheckpoint: 512 30 olcDbConfig: {0}set_cachesize 0 2097152 0 diff --git a/machines/migrations/0063_auto_20171020_0040.py b/machines/migrations/0063_auto_20171020_0040.py index d2f9afd9..0e049881 100644 --- a/machines/migrations/0063_auto_20171020_0040.py +++ b/machines/migrations/0063_auto_20171020_0040.py @@ -11,6 +11,7 @@ class Migration(migrations.Migration): dependencies = [ ('machines', '0062_extension_origin_v6'), + ('reversion', '0001_squashed_0004_auto_20160611_1202') ] operations = [ diff --git a/machines/migrations/0081_auto_20180515_2034.py b/machines/migrations/0081_auto_20180515_2034.py new file mode 100644 index 00000000..c812a310 --- /dev/null +++ b/machines/migrations/0081_auto_20180515_2034.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-05-15 18:34 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0080_auto_20180502_2334'), + ] + + operations = [ + migrations.AlterField( + model_name='extension', + name='soa', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.SOA'), + ), + ] diff --git a/requirements.txt b/pip_requirements.txt similarity index 59% rename from requirements.txt rename to pip_requirements.txt index 32957784..0960c796 100644 --- a/requirements.txt +++ b/pip_requirements.txt @@ -1,4 +1,3 @@ django-bootstrap3 +django-ldapdb==0.9.0 django-macaddress -python-dateutil -pycrypto diff --git a/re2o/settings_local.example.py b/re2o/settings_local.example.py index ef017c5d..e15455df 100644 --- a/re2o/settings_local.example.py +++ b/re2o/settings_local.example.py @@ -19,9 +19,8 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""re2o.settings_locale.example -The example settings_locale.py file with all the available -options for a locale configuration of re2o +"""re2o.settings_locale +The file with all the available options for a locale configuration of re2o """ from __future__ import unicode_literals @@ -41,7 +40,7 @@ AES_KEY = 'A_SECRET_AES_KEY' DEBUG = False # A list of admins of the services. Receive mails when an error occurs -ADMINS = [('Example', 'rezo-admin@example.org')] +ADMINS = [('Example', 'admin@example.net')] # The list of hostname the server will respond to. ALLOWED_HOSTS = ['URL_SERVER'] @@ -81,16 +80,16 @@ SESSION_COOKIE_AGE = 60 * 60 * 3 LOGO_PATH = "static_files/logo.png" # The mail configuration for Re2o to send mails -SERVER_EMAIL = 'no-reply@example.org' # The mail address to use +SERVER_EMAIL = 'no-reply@example.net' # The mail address to use EMAIL_HOST = 'MY_EMAIL_HOST' # The host to use EMAIL_PORT = MY_EMAIL_PORT # The port to use # Settings of the LDAP structure LDAP = { - 'base_user_dn': 'cn=Utilisateurs,dc=example,dc=org', - 'base_userservice_dn': 'ou=service-users,dc=example,dc=org', - 'base_usergroup_dn': 'ou=posix,ou=groups,dc=example,dc=org', - 'base_userservicegroup_dn': 'ou=services,ou=groups,dc=example,dc=org', + 'base_user_dn': 'cn=Utilisateurs,dc=example,dc=net', + 'base_userservice_dn': 'ou=service-users,dc=example,dc=net', + 'base_usergroup_dn': 'ou=posix,ou=groups,dc=example,dc=net', + 'base_userservicegroup_dn': 'ou=services,ou=groups,dc=example,dc=net', 'user_gid': 500, }