From 59e514d77c65d58098f3898d4689865f8c32a243 Mon Sep 17 00:00:00 2001
From: Chocobozzz <florian.bigard@gmail.com>
Date: Fri, 31 Jul 2015 19:02:08 +0200
Subject: [PATCH] Fix openvpn scripts connections to mysql and french comments

---
 install.sh                         |  4 ++++
 installation/scripts/config.sh     | 13 +++++--------
 installation/scripts/connect.sh    |  6 +++---
 installation/scripts/disconnect.sh |  6 +++---
 installation/scripts/login.sh      |  4 ++--
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/install.sh b/install.sh
index 61a4672..e51374b 100755
--- a/install.sh
+++ b/install.sh
@@ -183,6 +183,10 @@ printf "\n################## Setup web application ##################\n"
 cp -r "$base_path/installation/scripts" "/etc/openvpn/"
 chmod +x "/etc/openvpn/scripts/"*
 
+# Configure MySQL in openvpn scripts
+sed -i "s/\$user='';/\$user='$mysql_user';/" "/etc/openvpn/scripts/config.sh"
+sed -i "s/\$pass='';/\$pass='$mysql_pass';/" "/etc/openvpn/scripts/config.sh"
+
 # Create the directory of the web application
 mkdir "$openvpn_admin"
 cp -r "$base_path/"{index.php,sql,bower.json,.bowerrc,js,include,css,installation/client-conf} "$openvpn_admin"
diff --git a/installation/scripts/config.sh b/installation/scripts/config.sh
index 0605c0a..d2ee840 100644
--- a/installation/scripts/config.sh
+++ b/installation/scripts/config.sh
@@ -1,11 +1,8 @@
 #!/bin/bash
-# Serveur
+
+# MySQL credentials
 HOST='localhost'
-# Port (par défaut : 3306)
 PORT='3306'
-# Username
-USER='vpn_user'
-# Password
-PASS='mdp'
-# Nom de la base de données
-DB='vpn'
\ No newline at end of file
+USER=''
+PASS=''
+DB='openvpn-admin'
diff --git a/installation/scripts/connect.sh b/installation/scripts/connect.sh
index 473cb0d..9c191a6 100644
--- a/installation/scripts/connect.sh
+++ b/installation/scripts/connect.sh
@@ -1,8 +1,8 @@
 #!/bin/bash
 . /etc/openvpn/scripts/config.sh
 
-# On insert les données dans la table de log
+# We insert data in the log table
 mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "INSERT INTO log (log_id, user_id, log_trusted_ip, log_trusted_port, log_remote_ip, log_remote_port, log_start_time, log_end_time, log_received, log_send) VALUES(NULL, '$common_name','$trusted_ip', '$trusted_port','$ifconfig_pool_remote_ip', '$remote_port_1', now(),'0000-00-00 00:00:00', '$bytes_received', '$bytes_sent')"
 
-# On spécifie que l'utilisateur est en ligne
-mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "UPDATE user SET user_online=1 WHERE user_id='$common_name'"
\ No newline at end of file
+# We specify that the user is online
+mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "UPDATE user SET user_online=1 WHERE user_id='$common_name'"
diff --git a/installation/scripts/disconnect.sh b/installation/scripts/disconnect.sh
index 44efd30..963a0ea 100644
--- a/installation/scripts/disconnect.sh
+++ b/installation/scripts/disconnect.sh
@@ -1,8 +1,8 @@
 #!/bin/bash
 . /etc/openvpn/scripts/config.sh
 
-# On précise que l'utilisateur n'est plus en ligne
+# We specify the user is offline
 mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "UPDATE user SET user_online=0 WHERE user_id='$common_name'"
 
-# On insert le datetime de déconnexion
-mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "UPDATE log SET log_end_time=now(), log_received='$bytes_received', log_send='$bytes_sent' WHERE log_trusted_ip='$trusted_ip' AND log_trusted_port='$trusted_port' AND user_id='$common_name' AND log_end_time='0000-00-00 00:00:00'"
\ No newline at end of file
+# We insert the deconnection datetime
+mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "UPDATE log SET log_end_time=now(), log_received='$bytes_received', log_send='$bytes_sent' WHERE log_trusted_ip='$trusted_ip' AND log_trusted_port='$trusted_port' AND user_id='$common_name' AND log_end_time='0000-00-00 00:00:00'"
diff --git a/installation/scripts/login.sh b/installation/scripts/login.sh
index 93317e6..6bffd2a 100644
--- a/installation/scripts/login.sh
+++ b/installation/scripts/login.sh
@@ -4,5 +4,5 @@
 # Authentication
 user_id=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "SELECT user_id FROM user WHERE user_id = '$username' AND user_pass = SHA1('$password') AND user_enable=1 AND (TO_DAYS(now()) >= TO_DAYS(user_start_date) OR user_start_date='0000-00-00') AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date='0000-00-00')")
 
-# Vérification de l'utilisateur
-[ "$user_id" != '' ] && [ "$user_id" = "$username" ] && echo "user : $username" && echo 'authentication ok.' && exit 0 || echo 'authentication failed.'; exit 1
\ No newline at end of file
+# Check the user
+[ "$user_id" != '' ] && [ "$user_id" = "$username" ] && echo "user : $username" && echo 'authentication ok.' && exit 0 || echo 'authentication failed.'; exit 1