From 2b548cc2e2da98a8ae81dd4bbb6c8b95e9d82642 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 28 Jan 2018 14:13:42 +0300 Subject: [PATCH 1/7] refactoring and migration from npm+bower to npm+gulp --- .bowerrc | 3 -- .gitignore | 12 ++++- gulpfile.js | 41 ++++++++++++++++++ bower.json => package.json | 33 +++++++++----- desinstall.sh => public/desinstall.sh | 0 {include => public/include}/config.php | 0 {include => public/include}/connect.php | 0 {include => public/include}/functions.php | 0 {include => public/include}/grids.php | 0 .../include}/html/form/configuration.php | 0 .../include}/html/form/installation.php | 0 .../include}/html/form/login.php | 0 {include => public/include}/html/grids.php | 0 {include => public/include}/html/menu.php | 0 index.php => public/index.php | 12 ++--- install.sh => public/install.sh | 0 .../client-conf/gnu-linux/client.conf | 0 .../client-conf/gnu-linux/update-resolv.sh | 0 .../client-conf/osx-viscosity/client.conf | 0 .../client-conf/windows/client.ovpn | 0 .../installation}/scripts/config.sh | 0 .../installation}/scripts/connect.sh | 0 .../installation}/scripts/disconnect.sh | 0 .../installation}/scripts/functions.sh | 0 .../installation}/scripts/login.sh | 0 .../installation}/server.conf | 0 migration.php => public/migration.php | 0 {sql => public/sql}/schema-0.sql | 0 {sql => public/sql}/schema-5.sql | 0 update.sh => public/update.sh | 0 {css => resources/css}/index.css | 0 {css => resources/img}/icon.png | Bin {js => resources/js}/grids.js | 0 33 files changed, 80 insertions(+), 21 deletions(-) delete mode 100644 .bowerrc create mode 100644 gulpfile.js rename bower.json => package.json (54%) rename desinstall.sh => public/desinstall.sh (100%) rename {include => public/include}/config.php (100%) rename {include => public/include}/connect.php (100%) rename {include => public/include}/functions.php (100%) rename {include => public/include}/grids.php (100%) rename {include => public/include}/html/form/configuration.php (100%) rename {include => public/include}/html/form/installation.php (100%) rename {include => public/include}/html/form/login.php (100%) rename {include => public/include}/html/grids.php (100%) rename {include => public/include}/html/menu.php (100%) rename index.php => public/index.php (91%) rename install.sh => public/install.sh (100%) rename {installation => public/installation}/client-conf/gnu-linux/client.conf (100%) rename {installation => public/installation}/client-conf/gnu-linux/update-resolv.sh (100%) rename {installation => public/installation}/client-conf/osx-viscosity/client.conf (100%) rename {installation => public/installation}/client-conf/windows/client.ovpn (100%) rename {installation => public/installation}/scripts/config.sh (100%) rename {installation => public/installation}/scripts/connect.sh (100%) rename {installation => public/installation}/scripts/disconnect.sh (100%) rename {installation => public/installation}/scripts/functions.sh (100%) rename {installation => public/installation}/scripts/login.sh (100%) rename {installation => public/installation}/server.conf (100%) rename migration.php => public/migration.php (100%) rename {sql => public/sql}/schema-0.sql (100%) rename {sql => public/sql}/schema-5.sql (100%) rename update.sh => public/update.sh (100%) rename {css => resources/css}/index.css (100%) rename {css => resources/img}/icon.png (100%) rename {js => resources/js}/grids.js (100%) diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 6866ac2..0000000 --- a/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "vendor" -} diff --git a/.gitignore b/.gitignore index b7d6fa6..9993285 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,10 @@ -.phpintel -vendor/ +/.phpintel +/.env +/.idea/ +/vendor/ +/node_modules/ +/composer.lock +/package-lock.json +/public/css/ +/public/js/ +/public/img/ diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..b995a6c --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,41 @@ +var gulp = require('gulp'); +var copy = require('gulp-copy'); +var del = require('del'); + +gulp.task('default', ['img', 'css', 'js']); + +gulp.task('clean:img', function () { + return del(['public/img']); +}); + +gulp.task('img', ['clean:img'], function () { + return gulp.src('resources/img/**/*') + .pipe(gulp.dest('public/img')); +}); + +gulp.task('clean:css', function () { + return del(['public/css']); +}); + +gulp.task('css', ['clean:css'], function () { + gulp.src(['resources/css/**/*.css']) + .pipe(gulp.dest('public/css')); + + gulp + .src([ + 'node_modules/bootstrap/dist/css/bootstrap.min.css', + 'node_modules/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css', + 'node_modules/bootstrap-table/dist/bootstrap-table.min.css', + 'node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css' + ]) + .pipe(gulp.dest('public/css')); +}); + +gulp.task('clean:js', function () { + return del(['public/assets/js']); +}); + +gulp.task('js', ['clean:js'], function () { + gulp.src(['resources/js/**/*.js']) + .pipe(gulp.dest('public/js')); +}); diff --git a/bower.json b/package.json similarity index 54% rename from bower.json rename to package.json index fb22230..3475347 100644 --- a/bower.json +++ b/package.json @@ -2,21 +2,34 @@ "name": "openvpn-admin", "version": "0.3.2", "description": "Setup and administration of openvpn with a web interface", - "dependencies": { - "bootstrap": "^3.3.7", - "bootstrap-table": "^1.11.0", - "jquery": "^2.2.4", - "x-editable": "^1.5.1", - "bootstrap-datepicker": "^1.6.4" + "homepage": "https://github.com/EvilFreelancer/OpenVPN-Admin#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/EvilFreelancer/OpenVPN-Admin.git" }, + "authors": [ + "Florian Bigard " + ], "keywords": [ "openvpn", "admin", "setup" ], - "authors": [ - "Florian Bigard " - ], "license": "GPLv3", - "private": true + "bugs": { + "url": "https://github.com/EvilFreelancer/OpenVPN-Admin/issues" + }, + "dependencies": { + "gulp": "^3.9.0", + "gulp-copy": "^1.1.0", + "del": "^2.0.0", + "bootstrap": "^3.3.7", + "bootstrap-table": "^1.11.0", + "jquery": "^2.2.4", + "x-editable": "^1.5.1", + "bootstrap-datepicker": "^1.6.4" + }, + "scripts": { + "postinstall": "gulp" + } } diff --git a/desinstall.sh b/public/desinstall.sh similarity index 100% rename from desinstall.sh rename to public/desinstall.sh diff --git a/include/config.php b/public/include/config.php similarity index 100% rename from include/config.php rename to public/include/config.php diff --git a/include/connect.php b/public/include/connect.php similarity index 100% rename from include/connect.php rename to public/include/connect.php diff --git a/include/functions.php b/public/include/functions.php similarity index 100% rename from include/functions.php rename to public/include/functions.php diff --git a/include/grids.php b/public/include/grids.php similarity index 100% rename from include/grids.php rename to public/include/grids.php diff --git a/include/html/form/configuration.php b/public/include/html/form/configuration.php similarity index 100% rename from include/html/form/configuration.php rename to public/include/html/form/configuration.php diff --git a/include/html/form/installation.php b/public/include/html/form/installation.php similarity index 100% rename from include/html/form/installation.php rename to public/include/html/form/installation.php diff --git a/include/html/form/login.php b/public/include/html/form/login.php similarity index 100% rename from include/html/form/login.php rename to public/include/html/form/login.php diff --git a/include/html/grids.php b/public/include/html/grids.php similarity index 100% rename from include/html/grids.php rename to public/include/html/grids.php diff --git a/include/html/menu.php b/public/include/html/menu.php similarity index 100% rename from include/html/menu.php rename to public/include/html/menu.php diff --git a/index.php b/public/index.php similarity index 91% rename from index.php rename to public/index.php index 8266dd8..4418211 100644 --- a/index.php +++ b/public/index.php @@ -95,13 +95,13 @@ OpenVPN-Admin - - - - - + + + + + - + Date: Sun, 28 Jan 2018 17:03:01 +0300 Subject: [PATCH 2/7] web part refactoring, env support added, pure openvpn installation script added --- .env.example | 31 ++++ .gitignore | 1 + composer.json | 16 ++ include/config.php | 6 + include/connect.php | 5 + {public/include => include}/functions.php | 0 {public/include => include}/grids.php | 0 .../html/form/configuration.php | 0 .../html/form/installation.php | 0 .../include => include}/html/form/login.php | 0 {public/include => include}/html/grids.php | 0 {public/include => include}/html/menu.php | 0 public/include/config.php | 7 - public/include/connect.php | 6 - public/index.php | 24 +-- {public => scripts}/desinstall.sh | 0 scripts/install-openvpn.sh | 158 ++++++++++++++++++ {public => scripts}/install.sh | 0 .../client-conf/gnu-linux/client.conf | 0 .../client-conf/gnu-linux/update-resolv.sh | 0 .../client-conf/osx-viscosity/client.conf | 0 .../client-conf/windows/client.ovpn | 0 .../installation/scripts/config.sh | 0 .../installation/scripts/connect.sh | 0 .../installation/scripts/disconnect.sh | 0 .../installation/scripts/functions.sh | 0 .../installation/scripts/login.sh | 0 {public => scripts}/installation/server.conf | 0 {public => scripts}/migration.php | 0 {public => scripts}/sql/schema-0.sql | 0 {public => scripts}/sql/schema-5.sql | 0 {public => scripts}/update.sh | 0 32 files changed, 231 insertions(+), 23 deletions(-) create mode 100644 .env.example create mode 100644 composer.json create mode 100644 include/config.php create mode 100644 include/connect.php rename {public/include => include}/functions.php (100%) rename {public/include => include}/grids.php (100%) rename {public/include => include}/html/form/configuration.php (100%) rename {public/include => include}/html/form/installation.php (100%) rename {public/include => include}/html/form/login.php (100%) rename {public/include => include}/html/grids.php (100%) rename {public/include => include}/html/menu.php (100%) delete mode 100644 public/include/config.php delete mode 100644 public/include/connect.php rename {public => scripts}/desinstall.sh (100%) create mode 100755 scripts/install-openvpn.sh rename {public => scripts}/install.sh (100%) rename {public => scripts}/installation/client-conf/gnu-linux/client.conf (100%) rename {public => scripts}/installation/client-conf/gnu-linux/update-resolv.sh (100%) rename {public => scripts}/installation/client-conf/osx-viscosity/client.conf (100%) rename {public => scripts}/installation/client-conf/windows/client.ovpn (100%) rename {public => scripts}/installation/scripts/config.sh (100%) rename {public => scripts}/installation/scripts/connect.sh (100%) rename {public => scripts}/installation/scripts/disconnect.sh (100%) rename {public => scripts}/installation/scripts/functions.sh (100%) rename {public => scripts}/installation/scripts/login.sh (100%) rename {public => scripts}/installation/server.conf (100%) rename {public => scripts}/migration.php (100%) rename {public => scripts}/sql/schema-0.sql (100%) rename {public => scripts}/sql/schema-5.sql (100%) rename {public => scripts}/update.sh (100%) diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0e2e314 --- /dev/null +++ b/.env.example @@ -0,0 +1,31 @@ +# Web-application parameters +APP_PATH=/var/www/html/openvpn-admin + +# Database parameters +DB_HOST=172.17.0.1 +DB_PORT=3306 +DB_NAME=openvpn-admin +DB_USER=openvpn +DB_PASS=openvpn_pass + +# OpenVPN settings +VPN_ADDR=localhost +VPN_PORT=1194 +VPN_PROTO=tcp +VPN_GROUP=nogroup +VPN_INIF=tun0 +VPN_OUTIF=eth0 +VPN_NET=10.8.0.0/24 + +# OpenVPN key parameters +EASYRSA_KEY_SIZE=2048 +EASYRSA_CA_EXPIRE=3650 +EASYRSA_CERT_EXPIRE=3650 +EASYRSA_REQ_COUNTRY="US" +EASYRSA_REQ_PROVINCE="California" +EASYRSA_REQ_CITY="San Francisco" +EASYRSA_REQ_ORG="Copyleft Certificate Co" +EASYRSA_REQ_OU="My Organizational Unit" +EASYRSA_REQ_EMAIL=me@example.net +EASYRSA_REQ_CN=ChangeMe +EASYRSA_BATCH=true diff --git a/.gitignore b/.gitignore index 9993285..9a1fc58 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /public/css/ /public/js/ /public/img/ +/public/client-conf/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f5ff126 --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "chocobozzz/openvpn-admin", + "authors": [ + { + "name": "Florian Bigard", + "email": "florian.bigard@gmail.com" + }, + { + "name": "Paul Rock", + "email": "paul@drteam.rocks" + } + ], + "require": { + "vlucas/phpdotenv": "^2.4" + } +} diff --git a/include/config.php b/include/config.php new file mode 100644 index 0000000..f7f283c --- /dev/null +++ b/include/config.php @@ -0,0 +1,6 @@ + diff --git a/public/include/connect.php b/public/include/connect.php deleted file mode 100644 index 0add7e4..0000000 --- a/public/include/connect.php +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/public/index.php b/public/index.php index 4418211..a602a4d 100644 --- a/public/index.php +++ b/public/index.php @@ -1,8 +1,12 @@ load(); + session_start(); - require(dirname(__FILE__) . '/include/functions.php'); - require(dirname(__FILE__) . '/include/connect.php'); + require(dirname(__FILE__) . '/../include/functions.php'); + require(dirname(__FILE__) . '/../include/connect.php'); // Disconnecting ? if(isset($_GET['logout'])){ @@ -129,7 +133,7 @@ // Create the initial tables $migrations = getMigrationSchemas(); foreach ($migrations as $migration_value) { - $sql_file = dirname(__FILE__) . "/sql/schema-$migration_value.sql"; + $sql_file = dirname(__FILE__) . "/../scripts/sql/schema-$migration_value.sql"; try { $sql = file_get_contents($sql_file); $bdd->exec($sql); @@ -158,8 +162,8 @@ } // Print the installation form else { - require(dirname(__FILE__) . '/include/html/menu.php'); - require(dirname(__FILE__) . '/include/html/form/installation.php'); + require(dirname(__FILE__) . '/../include/html/menu.php'); + require(dirname(__FILE__) . '/../include/html/form/installation.php'); } exit(-1); @@ -170,8 +174,8 @@ if(isset($error) && $error == true) printError('Login error'); - require(dirname(__FILE__) . '/include/html/menu.php'); - require(dirname(__FILE__) . '/include/html/form/configuration.php'); + require(dirname(__FILE__) . '/../include/html/menu.php'); + require(dirname(__FILE__) . '/../include/html/form/configuration.php'); } @@ -180,8 +184,8 @@ if(isset($error) && $error == true) printError('Login error'); - require(dirname(__FILE__) . '/include/html/menu.php'); - require(dirname(__FILE__) . '/include/html/form/login.php'); + require(dirname(__FILE__) . '/../include/html/menu.php'); + require(dirname(__FILE__) . '/../include/html/form/login.php'); } // --------------- GRIDS --------------- @@ -201,7 +205,7 @@ diff --git a/public/desinstall.sh b/scripts/desinstall.sh similarity index 100% rename from public/desinstall.sh rename to scripts/desinstall.sh diff --git a/scripts/install-openvpn.sh b/scripts/install-openvpn.sh new file mode 100755 index 0000000..db8596a --- /dev/null +++ b/scripts/install-openvpn.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +print_error() { + echo "$1" + exit +} + +read_env() { + source "$1" +# grep -vE '^#|^$' "$1" | sed -r 's/\ /\\\ /g; s/\=/\t/g' | \ +# while read env val +# do +# env - $env="$val" +# done +} + +# Ensure to be root +if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit +fi + +base_path=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +# Read dotEnv file +read_env "$base_path/../.env" + +printf "\n################## Server informations ##################\n" + +[ ! -z "$VPN_ADDR" ] && echo "VPN_ADDR=$VPN_ADDR" +[ -z "$VPN_ADDR" ] && read -p "Server Hostname/IP: " VPN_ADDR +[ -z "$VPN_ADDR" ] && print_error "Server address is required!" + +[ ! -z "$VPN_PROTO" ] && echo "VPN_PROTO=$VPN_PROTO" +[ -z "$VPN_PROTO" ] && read -p "OpenVPN protocol (tcp or udp) [tcp]: " VPN_PROTO +[ -z "$VPN_PROTO" ] && VPN_PROTO="tcp" + +[ ! -z "$VPN_PORT" ] && echo "VPN_PORT=$VPN_PORT" +[ -z "$VPN_PORT" ] && read -p "OpenVPN port [443]: " VPN_PORT +[ -z "$VPN_PORT" ] && VPN_PORT="443" + +[ ! -z "$VPN_GROUP" ] && echo "VPN_GROUP=$VPN_GROUP" +[ -z "$VPN_GROUP" ] && read -p "OpenVPN group [nogroup]: " VPN_GROUP +[ -z "$VPN_GROUP" ] && VPN_GROUP="nogroup" + +[ ! -z "$VPN_INIF" ] && echo "VPN_INIF=$VPN_INIF" +[ -z "$VPN_INIF" ] && read -p "OpenVPN input interface [tun0]: " VPN_INIF +[ -z "$VPN_INIF" ] && VPN_INIF="tun0" + +[ ! -z "VPN_OUTIF" ] && echo "VPN_OUTIF=$VPN_OUTIF" +[ -z "$VPN_OUTIF" ] && read -p "OpenVPN output interface [eth0]: " VPN_OUTIF +[ -z "$VPN_OUTIF" ] && VPN_OUTIF="eth0" + +[ ! -z "$VPN_NET" ] && echo "VPN_NET=$VPN_NET" +[ -z "$VPN_NET" ] && read -p "OpenVPN clients subnet [10.8.0.0/24]: " VPN_NET +[ -z "$VPN_NET" ] && VPN_NET="10.8.0.0/24" + + +printf "\n################## Certificates informations ##################\n" + +[ -z "$EASYRSA_KEY_SIZE" ] && read -p "Key size (1024, 2048 or 4096) [2048]: " EASYRSA_KEY_SIZE +[ -z "$EASYRSA_CA_EXPIRE" ] && read -p "Root certificate expiration (in days) [3650]: " EASYRSA_CA_EXPIRE +[ -z "$EASYRSA_CERT_EXPIRE" ] && read -p "Certificate expiration (in days) [3650]: " EASYRSA_CERT_EXPIRE +[ -z "$EASYRSA_REQ_COUNTRY" ] && read -p "Country Name (2 letter code) [US]: " EASYRSA_REQ_COUNTRY +[ -z "$EASYRSA_REQ_PROVINCE" ] && read -p "State or Province Name (full name) [California]: " EASYRSA_REQ_PROVINCE +[ -z "$EASYRSA_REQ_CITY" ] && read -p "Locality Name (eg, city) [San Francisco]: " EASYRSA_REQ_CITY +[ -z "$EASYRSA_REQ_ORG" ] && read -p "Organization Name (eg, company) [Copyleft Certificate Co]: " EASYRSA_REQ_ORG +[ -z "$EASYRSA_REQ_OU" ] && read -p "Organizational Unit Name (eg, section) [My Organizational Unit]: " EASYRSA_REQ_OU +[ -z "$EASYRSA_REQ_EMAIL" ] && read -p "Email Address [me@example.net]: " EASYRSA_REQ_EMAIL +[ -z "$EASYRSA_REQ_CN" ] && read -p "Common Name (eg, your name or your server's hostname) [ChangeMe]: " EASYRSA_REQ_CN + + +printf "\n################## Creating the certificates ##################\n" + +EASYRSA_RELEASES=( $( + curl -s https://api.github.com/repos/OpenVPN/easy-rsa/releases | \ + grep 'tag_name' | \ + grep -E '3(\.[0-9]+)+' | \ + awk '{ print $2 }' | \ + sed 's/[,|"|v]//g' +) ) +EASYRSA_LATEST=${EASYRSA_RELEASES[0]} + +# Get the rsa keys +wget -q https://github.com/OpenVPN/easy-rsa/releases/download/v${EASYRSA_LATEST}/EasyRSA-${EASYRSA_LATEST}.tgz -O /tmp/EasyRSA-${EASYRSA_LATEST}.tgz +mkdir -p /etc/openvpn/easy-rsa +tar -xaf /tmp/EasyRSA-${EASYRSA_LATEST}.tgz -C /etc/openvpn/easy-rsa --strip-components=1 +rm -r /tmp/EasyRSA-${EASYRSA_LATEST}.tgz +cd /etc/openvpn/easy-rsa + +# Init PKI dirs and build CA certs +./easyrsa --batch init-pki +./easyrsa --batch build-ca nopass +# Generate Diffie-Hellman parameters +./easyrsa --batch gen-dh +# Generate server keypair +./easyrsa --batch build-server-full server nopass + +# Generate shared-secret for TLS Authentication +openvpn --genkey --secret pki/ta.key + + +printf "\n################## Setup OpenVPN ##################\n" + +# Copy certificates and the server configuration in the openvpn directory +cp /etc/openvpn/easy-rsa/pki/{ca.crt,ta.key,issued/server.crt,private/server.key,dh.pem} "/etc/openvpn/" +cp "$base_path/installation/server.conf" "/etc/openvpn/" +mkdir "/etc/openvpn/ccd" +sed -i "s/port 443/port $VPN_PORT/" "/etc/openvpn/server.conf" +sed -i "s/proto tcp/proto $VPN_PROTO/" "/etc/openvpn/server.conf" +sed -i "s/group nogroup/group $VPN_GROUP/" "/etc/openvpn/server.conf" + + +printf "\n################## Setup firewall ##################\n" + +# Make ip forwading and make it persistent +echo 1 > "/proc/sys/net/ipv4/ip_forward" +echo "net.ipv4.ip_forward = 1" >> "/etc/sysctl.conf" + +# Iptable rules +iptables -I FORWARD -i $VPN_INIF -j ACCEPT +iptables -I FORWARD -o $VPN_INIF -j ACCEPT +iptables -I OUTPUT -o $VPN_INIF -j ACCEPT + +iptables -A FORWARD -i $VPN_INIF -o $VPN_OUTIF -j ACCEPT +iptables -t nat -A POSTROUTING -o $VPN_OUTIF -j MASQUERADE +iptables -t nat -A POSTROUTING -s $VPN_NET -o eth0 -j MASQUERADE + + +printf "\n################## Setup web application ##################\n" + +# Copy bash scripts (which will insert row in MySQL) +cp -r "$base_path/installation/scripts" "/etc/openvpn/" +chmod +x "/etc/openvpn/scripts/"* + +# Configure MySQL in openvpn scripts +sed -i "s/USER=''/USER='$DB_USER'/" "/etc/openvpn/scripts/config.sh" +sed -i "s/PASS=''/PASS='$DB_PASS'/" "/etc/openvpn/scripts/config.sh" + +cp -r "$base_path/installation/client-conf" "$base_path/../public" +# New workspace +cd "$base_path/../public" + +# Replace in the client configurations with the ip of the server and openvpn protocol +for file in "./client-conf/gnu-linux/client.conf" "./client-conf/osx-viscosity/client.conf" "./client-conf/windows/client.ovpn"; do + sed -i "s/remote xxx\.xxx\.xxx\.xxx 443/remote $VPN_ADDR $VPN_PORT/" $file + + if [ $VPN_PROTO = "udp" ]; then + sed -i "s/proto tcp-client/proto udp/" $file + fi +done + +# Copy ta.key inside the client-conf directory +for directory in "./client-conf/gnu-linux/" "./client-conf/osx-viscosity/" "./client-conf/windows/"; do + cp "/etc/openvpn/"{ca.crt,ta.key} $directory +done + +printf "\033[1m\n#################################### Finish ####################################\n" diff --git a/public/install.sh b/scripts/install.sh similarity index 100% rename from public/install.sh rename to scripts/install.sh diff --git a/public/installation/client-conf/gnu-linux/client.conf b/scripts/installation/client-conf/gnu-linux/client.conf similarity index 100% rename from public/installation/client-conf/gnu-linux/client.conf rename to scripts/installation/client-conf/gnu-linux/client.conf diff --git a/public/installation/client-conf/gnu-linux/update-resolv.sh b/scripts/installation/client-conf/gnu-linux/update-resolv.sh similarity index 100% rename from public/installation/client-conf/gnu-linux/update-resolv.sh rename to scripts/installation/client-conf/gnu-linux/update-resolv.sh diff --git a/public/installation/client-conf/osx-viscosity/client.conf b/scripts/installation/client-conf/osx-viscosity/client.conf similarity index 100% rename from public/installation/client-conf/osx-viscosity/client.conf rename to scripts/installation/client-conf/osx-viscosity/client.conf diff --git a/public/installation/client-conf/windows/client.ovpn b/scripts/installation/client-conf/windows/client.ovpn similarity index 100% rename from public/installation/client-conf/windows/client.ovpn rename to scripts/installation/client-conf/windows/client.ovpn diff --git a/public/installation/scripts/config.sh b/scripts/installation/scripts/config.sh similarity index 100% rename from public/installation/scripts/config.sh rename to scripts/installation/scripts/config.sh diff --git a/public/installation/scripts/connect.sh b/scripts/installation/scripts/connect.sh similarity index 100% rename from public/installation/scripts/connect.sh rename to scripts/installation/scripts/connect.sh diff --git a/public/installation/scripts/disconnect.sh b/scripts/installation/scripts/disconnect.sh similarity index 100% rename from public/installation/scripts/disconnect.sh rename to scripts/installation/scripts/disconnect.sh diff --git a/public/installation/scripts/functions.sh b/scripts/installation/scripts/functions.sh similarity index 100% rename from public/installation/scripts/functions.sh rename to scripts/installation/scripts/functions.sh diff --git a/public/installation/scripts/login.sh b/scripts/installation/scripts/login.sh similarity index 100% rename from public/installation/scripts/login.sh rename to scripts/installation/scripts/login.sh diff --git a/public/installation/server.conf b/scripts/installation/server.conf similarity index 100% rename from public/installation/server.conf rename to scripts/installation/server.conf diff --git a/public/migration.php b/scripts/migration.php similarity index 100% rename from public/migration.php rename to scripts/migration.php diff --git a/public/sql/schema-0.sql b/scripts/sql/schema-0.sql similarity index 100% rename from public/sql/schema-0.sql rename to scripts/sql/schema-0.sql diff --git a/public/sql/schema-5.sql b/scripts/sql/schema-5.sql similarity index 100% rename from public/sql/schema-5.sql rename to scripts/sql/schema-5.sql diff --git a/public/update.sh b/scripts/update.sh similarity index 100% rename from public/update.sh rename to scripts/update.sh From 0f20b7a887ae01103a9431f5fb95223af9660bbc Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 28 Jan 2018 17:19:45 +0300 Subject: [PATCH 3/7] grids moved from includes --- public/grids.php | 211 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 public/grids.php diff --git a/public/grids.php b/public/grids.php new file mode 100644 index 0000000..2262410 --- /dev/null +++ b/public/grids.php @@ -0,0 +1,211 @@ +load(); + + session_start(); + + require(dirname(__FILE__) . '/../include/functions.php'); + require(dirname(__FILE__) . '/../include/connect.php'); + + // ---------------- SELECT ---------------- + if(isset($_GET['select'])){ + + // Select the users + if($_GET['select'] == "user"){ + $req = $bdd->prepare('SELECT * FROM user'); + $req->execute(); + + if($data = $req->fetch()) { + do { + $list[] = array("user_id" => $data['user_id'], + "user_pass" => $data['user_pass'], + "user_mail" => $data['user_mail'], + "user_phone" => $data['user_phone'], + "user_online" => $data['user_online'], + "user_enable" => $data['user_enable'], + "user_start_date" => $data['user_start_date'], + "user_end_date" => $data['user_end_date']); + } while($data = $req->fetch()); + + echo json_encode($list); + } + // If it is an empty answer, we need to encore an empty json object + else{ + $list = array(); + echo json_encode($list); + } + } + + // Select the logs + else if($_GET['select'] == "log" && isset($_GET['offset'], $_GET['limit'])){ + $offset = intval($_GET['offset']); + $limit = intval($_GET['limit']); + + // Creation of the LIMIT for build different pages + $page = "LIMIT $offset, $limit"; + + // Select the logs + $req_string = "SELECT *, (SELECT COUNT(*) FROM log) AS nb FROM log ORDER BY log_id DESC $page"; + $req = $bdd->prepare($req_string); + $req->execute(); + + $list = array(); + + $data = $req->fetch(); + + if($data) { + $nb = $data['nb']; + + do { + // Better in Kb or Mb + $received = ($data['log_received'] > 1000000) ? $data['log_received']/1000000 . " Mo" : $data['log_received']/1000 . " Ko"; + $sent = ($data['log_send'] > 1000000) ? $data['log_send']/1000000 . " Mo" : $data['log_send']/1000 . " Ko"; + + // We add to the array the new line of logs + array_push($list, array( + "log_id" => $data['log_id'], + "user_id" => $data['user_id'], + "log_trusted_ip" => $data['log_trusted_ip'], + "log_trusted_port" => $data['log_trusted_port'], + "log_remote_ip" => $data['log_remote_ip'], + "log_remote_port" => $data['log_remote_port'], + "log_start_time" => $data['log_start_time'], + "log_end_time" => $data['log_end_time'], + "log_received" => $received, + "log_send" => $sent)); + + + } while ($data = $req->fetch()); + } + else { + $nb = 0; + } + + // We finally print the result + $result = array('total' => intval($nb), 'rows' => $list); + + echo json_encode($result); + } + + // Select the admins + else if($_GET['select'] == "admin"){ + $req = $bdd->prepare('SELECT * FROM admin'); + $req->execute(); + + if($data = $req->fetch()) { + do{ + $list[] = array( + "admin_id" => $data['admin_id'], + "admin_pass" => $data['admin_pass'] + ); + } while($data = $req->fetch()); + + echo json_encode($list); + } + else{ + $list = array(); + echo json_encode($list); + } + } + } + + // ---------------- ADD USER ---------------- + else if(isset($_POST['add_user'], $_POST['user_id'], $_POST['user_pass'])){ + // Put some default values + $id = $_POST['user_id']; + $pass = hashPass($_POST['user_pass']); + $mail = ""; + $phone = ""; + $online = 0; + $enable = 1; + $start = NULL; + $end = NULL; + + $req = $bdd->prepare('INSERT INTO user (user_id, user_pass, user_mail, user_phone, user_online, user_enable, user_start_date, user_end_date) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)'); + $req->execute(array($id, $pass, $mail, $phone, $online, $enable, $start, $end)); + + $res = array("user_id" => $id, + "user_pass" => $pass, + "user_mail" => $mail , + "user_phone" => $phone, + "user_online" => $online, + "user_enable" => $enable, + "user_start_date" => $start, + "user_end_date" => $end + ); + + echo json_encode($res); + } + + // ---------------- UPDATE USER ---------------- + else if(isset($_POST['set_user'])){ + $valid = array("user_id", "user_pass", "user_mail", "user_phone", "user_enable", "user_start_date", "user_end_date"); + + $field = $_POST['name']; + $value = $_POST['value']; + $pk = $_POST['pk']; + + if (!isset($field) || !isset($pk) || !in_array($field, $valid)) { + return; + } + + if ($field === 'user_pass') { + $value = hashPass($value); + } + else if (($field === 'user_start_date' || $field === 'user_end_date') && $value === '') { + $value = NULL; + } + + // /!\ SQL injection: field was checked with in_array function + $req_string = 'UPDATE user SET ' . $field . ' = ? WHERE user_id = ?'; + $req = $bdd->prepare($req_string); + $req->execute(array($value, $pk)); + } + + // ---------------- REMOVE USER ---------------- + else if(isset($_POST['del_user'], $_POST['del_user_id'])){ + $req = $bdd->prepare('DELETE FROM user WHERE user_id = ?'); + $req->execute(array($_POST['del_user_id'])); + } + + // ---------------- ADD ADMIN ---------------- + else if(isset($_POST['add_admin'], $_POST['admin_id'], $_POST['admin_pass'])){ + $req = $bdd->prepare('INSERT INTO admin(admin_id, admin_pass) VALUES (?, ?)'); + $req->execute(array($_POST['admin_id'], hashPass($_POST['admin_pass']))); + } + + // ---------------- UPDATE ADMIN ---------------- + else if(isset($_POST['set_admin'])){ + $valid = array("admin_id", "admin_pass"); + + $field = $_POST['name']; + $value = $_POST['value']; + $pk = $_POST['pk']; + + if (!isset($field) || !isset($pk) || !in_array($field, $valid)) { + return; + } + + if ($field === 'admin_pass') { + $value = hashPass($value); + } + + $req_string = 'UPDATE admin SET ' . $field . ' = ? WHERE admin_id = ?'; + $req = $bdd->prepare($req_string); + $req->execute(array($value, $pk)); + } + + // ---------------- REMOVE ADMIN ---------------- + else if(isset($_POST['del_admin'], $_POST['del_admin_id'])){ + $req = $bdd->prepare('DELETE FROM admin WHERE admin_id = ?'); + $req->execute(array($_POST['del_admin_id'])); + } + +?> From 09d79a8fc4f6fda976d996e8f80954d26e0d8af1 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 28 Jan 2018 17:20:24 +0300 Subject: [PATCH 4/7] paths of js files changed, path to grids also --- include/html/grids.php | 11 ----------- public/index.php | 18 +++++++++++++----- resources/js/grids.js | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/html/grids.php b/include/html/grids.php index 5c4845f..fefcc3b 100644 --- a/include/html/grids.php +++ b/include/html/grids.php @@ -83,14 +83,3 @@ - - - - - - - - - - - diff --git a/public/index.php b/public/index.php index a602a4d..a36880e 100644 --- a/public/index.php +++ b/public/index.php @@ -1,5 +1,5 @@ load(); @@ -204,9 +204,17 @@ - + + + + + + + + + diff --git a/resources/js/grids.js b/resources/js/grids.js index 637800e..e380142 100644 --- a/resources/js/grids.js +++ b/resources/js/grids.js @@ -2,7 +2,7 @@ $(function () { "use strict"; // ------------------------- GLOBAL definitions ------------------------- - var gridsUrl = 'include/grids.php'; + var gridsUrl = 'grids.php'; function deleteFormatter() { return " Date: Sun, 28 Jan 2018 17:20:44 +0300 Subject: [PATCH 5/7] fonts task added in gulp --- .gitignore | 1 + gulpfile.js | 25 +++++- include/grids.php | 206 ---------------------------------------------- 3 files changed, 24 insertions(+), 208 deletions(-) delete mode 100644 include/grids.php diff --git a/.gitignore b/.gitignore index 9a1fc58..0b13e98 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /composer.lock /package-lock.json /public/css/ +/public/fonts/ /public/js/ /public/img/ /public/client-conf/ diff --git a/gulpfile.js b/gulpfile.js index b995a6c..f7c279e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,7 +2,7 @@ var gulp = require('gulp'); var copy = require('gulp-copy'); var del = require('del'); -gulp.task('default', ['img', 'css', 'js']); +gulp.task('default', ['img', 'css', 'font', 'js']); gulp.task('clean:img', function () { return del(['public/img']); @@ -31,11 +31,32 @@ gulp.task('css', ['clean:css'], function () { .pipe(gulp.dest('public/css')); }); +gulp.task('clean:font', function() { + return del(['public/fonts']); +}); + +gulp.task('font', ['clean:font'], function() { + return gulp.src([ + 'node_modules/bootstrap/dist/fonts/*', + ]).pipe(gulp.dest('public/fonts')); +}); + gulp.task('clean:js', function () { - return del(['public/assets/js']); + return del(['public/js']); }); gulp.task('js', ['clean:js'], function () { gulp.src(['resources/js/**/*.js']) .pipe(gulp.dest('public/js')); + + gulp + .src([ + 'node_modules/jquery/dist/jquery.min.js', + 'node_modules/bootstrap/dist/js/bootstrap.min.js', + 'node_modules/bootstrap-table/dist/bootstrap-table.min.js', + 'node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.js', + 'node_modules/bootstrap-table/dist/extensions/editable/bootstrap-table-editable.min.js', + 'node_modules/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js' + ]) + .pipe(gulp.dest('public/js')); }); diff --git a/include/grids.php b/include/grids.php deleted file mode 100644 index 68a1138..0000000 --- a/include/grids.php +++ /dev/null @@ -1,206 +0,0 @@ -prepare('SELECT * FROM user'); - $req->execute(); - - if($data = $req->fetch()) { - do { - $list[] = array("user_id" => $data['user_id'], - "user_pass" => $data['user_pass'], - "user_mail" => $data['user_mail'], - "user_phone" => $data['user_phone'], - "user_online" => $data['user_online'], - "user_enable" => $data['user_enable'], - "user_start_date" => $data['user_start_date'], - "user_end_date" => $data['user_end_date']); - } while($data = $req->fetch()); - - echo json_encode($list); - } - // If it is an empty answer, we need to encore an empty json object - else{ - $list = array(); - echo json_encode($list); - } - } - - // Select the logs - else if($_GET['select'] == "log" && isset($_GET['offset'], $_GET['limit'])){ - $offset = intval($_GET['offset']); - $limit = intval($_GET['limit']); - - // Creation of the LIMIT for build different pages - $page = "LIMIT $offset, $limit"; - - // Select the logs - $req_string = "SELECT *, (SELECT COUNT(*) FROM log) AS nb FROM log ORDER BY log_id DESC $page"; - $req = $bdd->prepare($req_string); - $req->execute(); - - $list = array(); - - $data = $req->fetch(); - - if($data) { - $nb = $data['nb']; - - do { - // Better in Kb or Mb - $received = ($data['log_received'] > 1000000) ? $data['log_received']/1000000 . " Mo" : $data['log_received']/1000 . " Ko"; - $sent = ($data['log_send'] > 1000000) ? $data['log_send']/1000000 . " Mo" : $data['log_send']/1000 . " Ko"; - - // We add to the array the new line of logs - array_push($list, array( - "log_id" => $data['log_id'], - "user_id" => $data['user_id'], - "log_trusted_ip" => $data['log_trusted_ip'], - "log_trusted_port" => $data['log_trusted_port'], - "log_remote_ip" => $data['log_remote_ip'], - "log_remote_port" => $data['log_remote_port'], - "log_start_time" => $data['log_start_time'], - "log_end_time" => $data['log_end_time'], - "log_received" => $received, - "log_send" => $sent)); - - - } while ($data = $req->fetch()); - } - else { - $nb = 0; - } - - // We finally print the result - $result = array('total' => intval($nb), 'rows' => $list); - - echo json_encode($result); - } - - // Select the admins - else if($_GET['select'] == "admin"){ - $req = $bdd->prepare('SELECT * FROM admin'); - $req->execute(); - - if($data = $req->fetch()) { - do{ - $list[] = array( - "admin_id" => $data['admin_id'], - "admin_pass" => $data['admin_pass'] - ); - } while($data = $req->fetch()); - - echo json_encode($list); - } - else{ - $list = array(); - echo json_encode($list); - } - } - } - - // ---------------- ADD USER ---------------- - else if(isset($_POST['add_user'], $_POST['user_id'], $_POST['user_pass'])){ - // Put some default values - $id = $_POST['user_id']; - $pass = hashPass($_POST['user_pass']); - $mail = ""; - $phone = ""; - $online = 0; - $enable = 1; - $start = NULL; - $end = NULL; - - $req = $bdd->prepare('INSERT INTO user (user_id, user_pass, user_mail, user_phone, user_online, user_enable, user_start_date, user_end_date) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)'); - $req->execute(array($id, $pass, $mail, $phone, $online, $enable, $start, $end)); - - $res = array("user_id" => $id, - "user_pass" => $pass, - "user_mail" => $mail , - "user_phone" => $phone, - "user_online" => $online, - "user_enable" => $enable, - "user_start_date" => $start, - "user_end_date" => $end - ); - - echo json_encode($res); - } - - // ---------------- UPDATE USER ---------------- - else if(isset($_POST['set_user'])){ - $valid = array("user_id", "user_pass", "user_mail", "user_phone", "user_enable", "user_start_date", "user_end_date"); - - $field = $_POST['name']; - $value = $_POST['value']; - $pk = $_POST['pk']; - - if (!isset($field) || !isset($pk) || !in_array($field, $valid)) { - return; - } - - if ($field === 'user_pass') { - $value = hashPass($value); - } - else if (($field === 'user_start_date' || $field === 'user_end_date') && $value === '') { - $value = NULL; - } - - // /!\ SQL injection: field was checked with in_array function - $req_string = 'UPDATE user SET ' . $field . ' = ? WHERE user_id = ?'; - $req = $bdd->prepare($req_string); - $req->execute(array($value, $pk)); - } - - // ---------------- REMOVE USER ---------------- - else if(isset($_POST['del_user'], $_POST['del_user_id'])){ - $req = $bdd->prepare('DELETE FROM user WHERE user_id = ?'); - $req->execute(array($_POST['del_user_id'])); - } - - // ---------------- ADD ADMIN ---------------- - else if(isset($_POST['add_admin'], $_POST['admin_id'], $_POST['admin_pass'])){ - $req = $bdd->prepare('INSERT INTO admin(admin_id, admin_pass) VALUES (?, ?)'); - $req->execute(array($_POST['admin_id'], hashPass($_POST['admin_pass']))); - } - - // ---------------- UPDATE ADMIN ---------------- - else if(isset($_POST['set_admin'])){ - $valid = array("admin_id", "admin_pass"); - - $field = $_POST['name']; - $value = $_POST['value']; - $pk = $_POST['pk']; - - if (!isset($field) || !isset($pk) || !in_array($field, $valid)) { - return; - } - - if ($field === 'admin_pass') { - $value = hashPass($value); - } - - $req_string = 'UPDATE admin SET ' . $field . ' = ? WHERE admin_id = ?'; - $req = $bdd->prepare($req_string); - $req->execute(array($value, $pk)); - } - - // ---------------- REMOVE ADMIN ---------------- - else if(isset($_POST['del_admin'], $_POST['del_admin_id'])){ - $req = $bdd->prepare('DELETE FROM admin WHERE admin_id = ?'); - $req->execute(array($_POST['del_admin_id'])); - } - -?> From eb64bcb15dfbbbbc46cb7eb1f63fb4c3e70adc1a Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 28 Jan 2018 17:39:48 +0300 Subject: [PATCH 6/7] readme file updated --- README.md | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 437719b..f549aa1 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,20 @@ Administrate its OpenVPN with a web interface (logs visualisations, users managi * PHP >= 5.5 with modules: * zip * pdo_mysql - * bower + * composer + * npm * unzip * wget * sed * curl +### Debian Stretch + +```` +# apt-get install openvpn nginx composer php-fpm php-mysql mysql-server php nodejs unzip git wget sed curl +# ln -s /usr/bin/nodejs /usr/bin/node +```` + ### Debian Jessie ```` @@ -46,16 +54,29 @@ Administrate its OpenVPN with a web interface (logs visualisations, users managi Only tested on Debian Jessie. Feel free to open issues. -## Installation +## Installation (full) * Setup OpenVPN and the web application: $ cd ~/my_coding_workspace $ git clone https://github.com/Chocobozzz/OpenVPN-Admin openvpn-admin $ cd openvpn-admin - # ./install.sh www_base_dir web_user web_group + $ npm install + $ composer install + +You can predefine all environment parameters, just copy example and put your changes in `.env` + + # cp .env.example .env + +If you want to make ths full installation (with preparing of MySQL, Web-server and OpenVPN) + + # ./install.sh www_base_dir web_user web_group + +If you want to configure only OpenVPN: + + # ./install-openvpn.sh - * Setup the web server (Apache, NGinx...) to serve the web application. + * Setup the web server (Apache, Nginx...) to serve the web application. * Create the admin of the web application by visiting `http://your-installation/index.php?installation` ## Usage From 6ae8a1ce93ecce5cb10a31dce2b68da0cbe74b31 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Sun, 28 Jan 2018 17:54:14 +0300 Subject: [PATCH 7/7] path of logs into openvpn config was changed --- scripts/installation/server.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/installation/server.conf b/scripts/installation/server.conf index 041de41..8ce7bc1 100644 --- a/scripts/installation/server.conf +++ b/scripts/installation/server.conf @@ -66,9 +66,9 @@ verb 3 # Max 20 messages of the same category mute 20 # Log gile where we put the clients status -status openvpn-status.log +status /var/log/openvpn/status.log # Log file -log-append /var/log/openvpn.log +log-append /var/log/openvpn/openvpn.log # Configuration directory of the clients client-config-dir ccd