From da7bdf878c86dc587d1e3ec351d2a47ef9ba481b Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Sun, 25 Aug 2019 19:49:22 -0500 Subject: [PATCH] VPN HDD backup --- rootfs/standard/usr/bin/mynode_vpn.sh | 20 +++++++++++++++++++ .../usr/share/mynode/mynode_config.sh | 1 + rootfs/standard/var/www/mynode/vpn.py | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/rootfs/standard/usr/bin/mynode_vpn.sh b/rootfs/standard/usr/bin/mynode_vpn.sh index 97f47caf..35ca67fe 100755 --- a/rootfs/standard/usr/bin/mynode_vpn.sh +++ b/rootfs/standard/usr/bin/mynode_vpn.sh @@ -1,13 +1,33 @@ #!/bin/bash +source /usr/share/mynode/mynode_config.sh + apt -y update +mkdir -p $VPN_BACKUP_DIR + while [ true ]; do + # Check for backup files + if [ ! -f /home/pivpn/ovpns/mynode_vpn.ovpn ]; then + if [ -f $VPN_BACKUP_DIR/mynode_vpn.ovpn ]; then + cp $VPN_BACKUP_DIR/mynode_vpn.ovpn /home/pivpn/ovpns/mynode_vpn.ovpn + fi + if [ -d $VPN_BACKUP_DIR/openvpn ]; then + cp -rf $VPN_BACKUP_DIR/openvpn /etc + fi + fi + + # Generate new files if [ ! -f /home/pivpn/ovpns/mynode_vpn.ovpn ]; then /usr/bin/mynode_setup_vpn.sh mkdir -p /home/pivpn/ovpns pivpn add -n mynode_vpn nopass -d 3650 + + # Backup files to HDD + sync + cp -rf /etc/openvpn/ $VPN_BACKUP_DIR/ + cp /home/pivpn/ovpns/mynode_vpn.ovpn $VPN_BACKUP_DIR/mynode_vpn.ovpn fi systemctl enable openvpn diff --git a/rootfs/standard/usr/share/mynode/mynode_config.sh b/rootfs/standard/usr/share/mynode/mynode_config.sh index e700edf5..5c275484 100644 --- a/rootfs/standard/usr/share/mynode/mynode_config.sh +++ b/rootfs/standard/usr/share/mynode/mynode_config.sh @@ -24,6 +24,7 @@ SERIAL_NUM=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2) # Set all default / standard bash config settings MYNODE_DIR=/mnt/hdd/mynode +VPN_BACKUP_DIR=/mnt/hdd/mynode/vpn QUICKSYNC_DIR=/mnt/hdd/mynode/quicksync QUICKSYNC_CONFIG_DIR=/mnt/hdd/mynode/.config/transmission QUICKSYNC_TORRENT_URL="https://mynodebtc.com/device/blockchain.tar.gz.torrent" diff --git a/rootfs/standard/var/www/mynode/vpn.py b/rootfs/standard/var/www/mynode/vpn.py index 62ac1b36..5f1e4776 100644 --- a/rootfs/standard/var/www/mynode/vpn.py +++ b/rootfs/standard/var/www/mynode/vpn.py @@ -51,10 +51,16 @@ def page_regen_vpn(): if pw == None or p.authenticate("admin", pw) == False: return redirect(url_for(".page_vpn_info", error_message="Invalid Password")) + # Stop #os.system("rm /home/pivpn/ovpns/mynode_vpn.ovpn") os.system("pivpn -r mynode_vpn") os.system("systemctl stop openvpn") os.system("systemctl stop vpn") + + # Clean up files + os.system("rm -rf /mnt/hdd/mynode/vpn/*") + + # Restart os.system("systemctl start vpn") # Download ovpn