Skip to content

Commit

Permalink
Update file install mechanism
Browse files Browse the repository at this point in the history
The configuration files will now be installed into the virtuel-env into
'<venv>/share/openvpnclient'. This location is used in the run.sh script.
  • Loading branch information
larsklitzke committed Apr 1, 2019
1 parent 410097e commit 7c9641b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 6 additions & 3 deletions openvpnclient/backend/app.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -46,5 +48,6 @@ def upload():
return jsonify({'message': 'File {} saved'.format(file.filename)}), 200


if __name__ == '__main__':
def run():
application.run()

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Flask
Flask
uwsgi
20 changes: 15 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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}

}

Expand Down Expand Up @@ -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
cd ${CLIENT_CONFIG_LOCATION} && openvpn --config client.ovpn

0 comments on commit 7c9641b

Please sign in to comment.