From 01c182b6689cfd48b9a1f72d90ccf10a5c41863e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 24 Sep 2017 23:37:41 +0100 Subject: [PATCH] Backup and restore vpn keys --- src/freedombone-app-vpn | 50 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/freedombone-app-vpn b/src/freedombone-app-vpn index f915febf..3a138060 100755 --- a/src/freedombone-app-vpn +++ b/src/freedombone-app-vpn @@ -64,19 +64,61 @@ function upgrade_vpn { } function backup_local_vpn { - echo -n '' + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [ -f /home/$USERNAME/$OPENVPN_KEY_FILENAME ]; then + cp /home/$USERNAME/$OPENVPN_KEY_FILENAME /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} + fi + done + + function_check backup_directory_to_usb + backup_directory_to_usb /etc/openvpn/easy-rsa/keys vpn } function restore_local_vpn { - echo -n '' + temp_restore_dir=/root/tempvpn + restore_directory_from_usb $temp_restore_dir vpn + if [ -d ${temp_restore_dir} ]; then + cp -r ${temp_restore_dir}/* /etc/openvpn/easy-rsa/keys + rm -rf ${temp_restore_dir} + + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [ -f /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} ]; then + cp /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} /home/$USERNAME/$OPENVPN_KEY_FILENAME + chown $USERNAME:$USERNAME /home/$USERNAME/$OPENVPN_KEY_FILENAME + fi + done + fi } function backup_remote_vpn { - echo -n '' + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [ -f /home/$USERNAME/$OPENVPN_KEY_FILENAME ]; then + cp /home/$USERNAME/$OPENVPN_KEY_FILENAME /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} + fi + done + + function_check backup_directory_to_friend + backup_directory_to_friend /etc/openvpn/easy-rsa/keys vpn } function restore_remote_vpn { - echo -n '' + temp_restore_dir=/root/tempvpn + restore_directory_from_friend $temp_restore_dir vpn + if [ -d ${temp_restore_dir} ]; then + cp -r ${temp_restore_dir}/* /etc/openvpn/easy-rsa/keys + rm -rf ${temp_restore_dir} + + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [ -f /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} ]; then + cp /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} /home/$USERNAME/$OPENVPN_KEY_FILENAME + chown $USERNAME:$USERNAME /home/$USERNAME/$OPENVPN_KEY_FILENAME + fi + done + fi } function remove_vpn {