diff --git a/config.json b/config.json index 318bc58..8191297 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "name": "OpenVPN Client", - "version": "0.2.6", + "version": "0.2.7", "slug": "openvpn-client", "description": "Connect Hassio to a remote VPN Server", "startup": "application", diff --git a/openvpnclient/backend/app.py b/openvpnclient/backend/app.py index 66587ae..abf2cbb 100644 --- a/openvpnclient/backend/app.py +++ b/openvpnclient/backend/app.py @@ -1,10 +1,12 @@ import os +import sys from flask import Flask, request, render_template, jsonify from werkzeug.utils import secure_filename -application = Flask(__name__, template_folder=os.path.join(os.path.dirname(os.path.dirname(__file__)), 'frontend')) -application.config['UPLOAD_FOLDER'] = '/share/openvpnclient/' +application = Flask(__name__, template_folder=os.path.abspath( + os.path.join(os.path.dirname(os.path.dirname(__file__)), 'frontend'))) +application.config['UPLOAD_FOLDER'] = os.path.join(sys.prefix, 'share', 'openvpnclient') _FILES = [ 'ca.crt', @@ -46,5 +48,6 @@ def upload(): return jsonify({'message': 'File {} saved'.format(file.filename)}), 200 -if __name__ == '__main__': +def run(): application.run() + diff --git a/requirements.txt b/requirements.txt index 2077213..cc854d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Flask \ No newline at end of file +Flask +uwsgi \ No newline at end of file diff --git a/run.sh b/run.sh index e9fb139..a61d82e 100644 --- a/run.sh +++ b/run.sh @@ -3,9 +3,19 @@ # Start the web server and setup the VPN connection declare -r REQUIRED_FILES="client.crt client.key ca.crt" -declare -r CLIENT_CONFIG_LOCATION=/share/openvpnclient declare -rx MY_NAME="$(basename $0)" +# Points to the root dir of the virtual environment +declare -rx ROOT_DIR="$(dirname $(dirname $0))" + +# points to the location of the configuration files +declare -r CLIENT_CONFIG_LOCATION=$ROOT_DIR/share/openvpnclient + +# The uwsgi configuration file +declare -r UWSGI_CONFIG_FILE=${CLIENT_CONFIG_LOCATION}/openvpnclient.ini + +declare -r OPENVPN_OPTIONS=${CLIENT_CONFIG_LOCATION}/options.json + ######################################################################################################################## # Log to stdout # Arguments: @@ -47,7 +57,7 @@ function init_tun_interface(){ function setup_openvpn_config(){ # split up the entries in the config option into lines and write to the client configuration file - cat /data/options.json | jq --raw-output '.config[]' > ${CLIENT_CONFIG_LOCATION}/client.ovpn + cat ${OPENVPN_OPTIONS} | jq --raw-output '.config[]' > ${CLIENT_CONFIG_LOCATION}/client.ovpn chmod 777 ${CLIENT_CONFIG_LOCATION}/client.ovpn @@ -65,12 +75,12 @@ function setup_openvpn_config(){ function start_webserver(){ # The python virtual environment is inside the directory defined by $NAME in / - source /${NAME}/venv/bin/activate + source $ROOT_DIR/bin/activate log "Start the web server." # now we the the entry point defined by the application - uwsgi /$NAME/app/${NAME}.ini + uwsgi ${UWSGI_CONFIG_FILE} --home ${ROOT_DIR} } @@ -130,4 +140,4 @@ wait_configuration log "Setup the VPN connection." # try to connect to the server using the used defined configuration -cd ${CLIENT_CONFIG_LOCATION} && openvpn --config client.ovpn \ No newline at end of file +cd ${CLIENT_CONFIG_LOCATION} && openvpn --config client.ovpn