From 24a1a00d376e6a703fd2edb82cdeb2b6b1110f36 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 14 Oct 2019 12:11:16 +0200 Subject: [PATCH 01/79] Refactoring + WireGuard support --- auto_install/install.sh | 2384 ++++++++++++++++++--------------------- pivpn | 106 -- scripts/backup.sh | 31 - scripts/bash-completion | 22 - scripts/clientStat.sh | 35 - scripts/listOVPN.sh | 27 - scripts/makeOVPN.sh | 415 ------- scripts/pivpnDebug.sh | 230 ---- scripts/removeOVPN.sh | 123 -- scripts/uninstall.sh | 153 --- scripts/update.sh | 99 -- 11 files changed, 1103 insertions(+), 2522 deletions(-) delete mode 100644 pivpn delete mode 100755 scripts/backup.sh delete mode 100644 scripts/bash-completion delete mode 100755 scripts/clientStat.sh delete mode 100755 scripts/listOVPN.sh delete mode 100755 scripts/makeOVPN.sh delete mode 100755 scripts/pivpnDebug.sh delete mode 100755 scripts/removeOVPN.sh delete mode 100755 scripts/uninstall.sh delete mode 100755 scripts/update.sh diff --git a/auto_install/install.sh b/auto_install/install.sh index ac2e190..653b017 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# PiVPN: Trivial OpenVPN setup and configuration -# Easiest setup and mangement of OpenVPN on Raspberry Pi +# PiVPN: Trivial OpenVPN or WireGUard setup and configuration +# Easiest setup and mangement of OpenVPN or WireGuard on Raspberry Pi # http://pivpn.io # Heavily adapted from the pi-hole.net project and... # https://github.com/StarshipEngineer/OpenVPN-Setup/ @@ -9,11 +9,10 @@ # # curl -L https://install.pivpn.io | bash # Make sure you have `curl` installed -set -e ######## VARIABLES ######### setupVars=/etc/pivpn/setupVars.conf -useUpdateVars=false +pivpnFilesDir="/etc/.pivpn" ### PKG Vars ### PKG_MANAGER="apt-get" @@ -21,19 +20,19 @@ PKG_CACHE="/var/lib/apt/lists/" UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" -PIVPN_DEPS=(openvpn git tar wget grep iptables-persistent dnsutils expect whiptail net-tools grepcidr jq) +BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools dhcpcd5) -### ### - -pivpnGitUrl="https://github.com/pivpn/pivpn.git" -pivpnFilesDir="/etc/.pivpn" +pivpnGitUrl="https://github.com/orazioedoardo/pivpn.git" easyrsaVer="3.0.6" easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer}/EasyRSA-unix-v${easyrsaVer}.tgz" # Raspbian's unattended-upgrades package downloads Debian's config, so this is the link for the proper config -UNATTUPG_RELEASE="1.9" +UNATTUPG_RELEASE="1.14" UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_RELEASE}.tar.gz" +WG_SNAPSHOT="0.0.20190913" +WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" + # Find the rows and columns. Will default to 80x24 if it can not be detected. screen_size=$(stty size 2>/dev/null || echo 24 80) rows=$(echo $screen_size | awk '{print $1}') @@ -46,13 +45,7 @@ c=$(( columns / 2 )) r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) -######## Undocumented Flags. Shhh ######## -skipSpaceCheck=false -reconfigure=false -runUnattended=false - # Find IP used to route to outside world - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') IPv4addr=$(ip route get 8.8.8.8| awk '{print $7}') IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') @@ -61,1076 +54,1034 @@ availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d': dhcpcdFile=/etc/dhcpcd.conf # Next see if we are on a tested and supported OS -function noOS_Support() { - whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS. -Currently this installer supports Raspbian and Debian (Jessie and Stretch), Devuan (Jessie) and Ubuntu from 14.04 (trusty) to 17.04 (zesty). +noOSSupport(){ + whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS. +Currently this installer supports Raspbian (Buster). If you think you received this message in error, you can post an issue on the GitHub at https://github.com/pivpn/pivpn/issues." ${r} ${c} - exit 1 + exit 1 } -function maybeOS_Support() { - if (whiptail --backtitle "Not Supported OS" --title "Not Supported OS" --yesno "You are on an OS that we have not tested but MAY work. -Currently suppoerted: - Raspbian, Debian, Devuan (Jessie, strech, buster) - Ubuntu from 14.04 (trusty) to 18.04 (zesty). - +maybeOSSupport(){ + if (whiptail --backtitle "Not Supported OS" --title "Not Supported OS" --yesno "You are on an OS that we have not tested but MAY work. +Currently this installer supports Raspbian (Buster). Would you like to continue anyway?" ${r} ${c}) then - echo "::: Did not detect perfectly supported OS but," - echo "::: Continuing installation at user's own risk..." - else - echo "::: Exiting due to unsupported OS" - exit 1 - fi + echo "::: Did not detect perfectly supported OS but," + echo "::: Continuing installation at user's own risk..." + else + echo "::: Exiting due to unsupported OS" + exit 1 + fi } # Compatibility -distro_check() { - # if lsb_release command is on their system - if hash lsb_release 2>/dev/null; then +distroCheck(){ + # if lsb_release command is on their system + if hash lsb_release 2>/dev/null; then - PLAT=$(lsb_release -si) - OSCN=$(lsb_release -sc) # We want this to be trusty xenial, jessie, stretch, buster + PLAT=$(lsb_release -si) + OSCN=$(lsb_release -sc) # We want this to be trusty xenial or jessie - else # else get info from os-release + else # else get info from os-release - source /etc/os-release - PLAT=$(awk '{print $1}' <<< "$NAME") - VER="$VERSION_ID" - declare -A VER_MAP=(["10"]="buster" ["9"]="stretch" ["8"]="jessie" ["18.04"]="bionic" ["16.04"]="xenial" ["14.04"]="trusty") - OSCN=${VER_MAP["${VER}"]} - fi + source /etc/os-release + PLAT=$(awk '{print $1}' <<< "$NAME") + VER="$VERSION_ID" + declare -A VER_MAP=(["10"]="buster") + OSCN=${VER_MAP["${VER}"]} + fi - if [[ ${OSCN} != "bionic" ]]; then - PIVPN_DEPS+=(dhcpcd5) + case ${PLAT} in + Raspbian) + case ${OSCN} in + buster) + ;; + *) + maybeOS_Support + ;; + esac + ;; + *) + noOS_Support + ;; + esac - fi + echo "PLAT=${PLAT}" > /tmp/setupVars.conf + echo "OSCN=${OSCN}" >> /tmp/setupVars.conf +} - case ${PLAT} in - Ubuntu|Raspbian|Debian|Devuan) - case ${OSCN} in - trusty|xenial|jessie|stretch|buster|bionic) - ;; - *) - maybeOS_Support - ;; - esac - ;; - *) - noOS_Support - ;; - esac - - echo "${PLAT}" > /tmp/DET_PLATFORM +checkHostname(){ +###Checks for hostname size + host_name=$(hostname -s) + if [[ ! ${#host_name} -le 28 ]]; then + until [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; do + host_name=$(whiptail --inputbox "Your hostname is too long.\nEnter new hostname with less then 28 characters\nNo special characters allowed." \ + --title "Hostname too long" ${r} ${c} 3>&1 1>&2 2>&3) + $SUDO hostnamectl set-hostname "${host_name}" + if [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; then + echo "::: Hostname valid and length OK, proceeding..." + fi + done + else + echo "::: Hostname length OK" + fi } ####### FUNCTIONS ########## -spinner() -{ - local pid=$1 - local delay=0.50 - local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do - local temp=${spinstr#?} - printf " [%c] " "${spinstr}" - local spinstr=${temp}${spinstr%"$temp"} - sleep ${delay} - printf "\b\b\b\b\b\b" - done - printf " \b\b\b\b" +spinner(){ + local pid=$1 + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do + local temp=${spinstr#?} + printf " [%c] " "${spinstr}" + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" } -welcomeDialogs() { - # Display the welcome dialog - whiptail --msgbox --backtitle "Welcome" --title "PiVPN Automated Installer" "This installer will transform your Raspberry Pi into an OpenVPN server!" ${r} ${c} +verifyFreeDiskSpace(){ + # If user installs unattended-upgrades we'd need about 60MB so will check for 75MB free + echo "::: Verifying free disk space..." + local required_free_kilobytes=76800 + local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') - # Explain the need for a static address - whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed" "The PiVPN is a SERVER so it needs a STATIC IP ADDRESS to function properly. + # - Unknown free disk space , not a integer + if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then + echo "::: Unknown free disk space!" + echo "::: We were unable to determine available free disk space on this system." + echo "::: You may continue with the installation, however, it is not recommended." + read -r -p "::: If you are sure you want to continue, type YES and press enter :: " response + case $response in + [Y][E][S]) + ;; + *) + echo "::: Confirmation not received, exiting..." + exit 1 + ;; + esac + # - Insufficient free disk space + elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then + echo "::: Insufficient Disk Space!" + echo "::: Your system appears to be low on disk space. PiVPN recommends a minimum of $required_free_kilobytes KiloBytes." + echo "::: You only have ${existing_free_kilobytes} KiloBytes free." + echo "::: If this is a new install on a Raspberry Pi you may need to expand your disk." + echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'" + echo "::: After rebooting, run this installation again. (curl -L https://install.pivpn.io | bash)" + + echo "Insufficient free space, exiting..." + exit 1 + fi +} + +updatePackageCache(){ + #Running apt-get update/upgrade with minimal output can cause some issues with + #requiring user input + + #Check to see if apt-get update has already been run today + #it needs to have been run at least once on new installs! + timestamp=$(stat -c %Y ${PKG_CACHE}) + timestampAsDate=$(date -d @"${timestamp}" "+%b %e") + today=$(date "+%b %e") + + + if [ ! "${today}" == "${timestampAsDate}" ]; then + #update package lists + echo ":::" + echo -ne "::: ${PKG_MANAGER} update has not been run today. Running now...\n" + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + echo " done!" + fi +} + +notifyPackageUpdatesAvailable(){ + # Let user know if they have outdated packages on their system and + # advise them to run a package update at soonest possible. + echo ":::" + echo -n "::: Checking ${PKG_MANAGER} for upgraded packages...." + updatesToInstall=$(eval "${PKG_COUNT}") + echo " done!" + echo ":::" + if [[ ${updatesToInstall} -eq "0" ]]; then + echo "::: Your system is up to date! Continuing with PiVPN installation..." + else + echo "::: There are ${updatesToInstall} updates available for your system!" + echo "::: We recommend you update your OS after installing PiVPN! " + echo ":::" + fi +} + +packageCheckInstall(){ + dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" +} + +preconfigurePackages(){ + # Add support for https repositories if there are any that use it otherwise the installation will silently fail + if grep -q https /etc/apt/sources.list; then + BASE_DEPS+=("apt-transport-https") + fi + + if [[ ${OSCN} == "buster" ]]; then + $SUDO update-alternatives --set iptables /usr/sbin/iptables-legacy + $SUDO update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy + fi + + echo iptables-persistent iptables-persistent/autosave_v4 boolean true | $SUDO debconf-set-selections + echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections +} + +installDependentPackages(){ + # Install packages passed in via argument array + # No spinner - conflicts with set -e + declare -a argArray1=("${!1}") + + if command -v debconf-apt-progress &> /dev/null; then + $SUDO debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" + else + for i in "${argArray1[@]}"; do + echo -n "::: Checking for $i..." + $SUDO packageCheckInstall "${i}" &> /dev/null + echo " installed!" + done + fi +} + +welcomeDialogs(){ + # Display the welcome dialog + whiptail --msgbox --backtitle "Welcome" --title "PiVPN Automated Installer" "This installer will transform your Raspberry Pi into an OpenVPN or WireGuard server!" ${r} ${c} + + # Explain the need for a static address + whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed" "The PiVPN is a SERVER so it needs a STATIC IP ADDRESS to function properly. In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." ${r} ${c} } -chooseUser() { - # Explain the local user - whiptail --msgbox --backtitle "Parsing User List" --title "Local Users" "Choose a local user that will hold your ovpn configurations." ${r} ${c} - # First, let's check if there is a user available. - numUsers=$(awk -F':' 'BEGIN {count=0} $3>=1000 && $3<=60000 { count++ } END{ print count }' /etc/passwd) - if [ "$numUsers" -eq 0 ] - then - # We don't have a user, let's ask to add one. - if userToAdd=$(whiptail --title "Choose A User" --inputbox "No non-root user account was found. Please type a new username." ${r} ${c} 3>&1 1>&2 2>&3) - then - # See http://askubuntu.com/a/667842/459815 - PASSWORD=$(whiptail --title "password dialog" --passwordbox "Please enter the new user password" ${r} ${c} 3>&1 1>&2 2>&3) - CRYPT=$(perl -e 'printf("%s\n", crypt($ARGV[0], "password"))' "${PASSWORD}") - $SUDO useradd -m -p "${CRYPT}" -s /bin/bash "${userToAdd}" - if [[ $? = 0 ]]; then - echo "Succeeded" - ((numUsers+=1)) - else - exit 1 - fi - else - exit 1 - fi - fi - availableUsers=$(awk -F':' '$3>=1000 && $3<=60000 {print $1}' /etc/passwd) - local userArray=() - local firstloop=1 +chooseInterface(){ + # Turn the available interfaces into an array so it can be used with a whiptail dialog + local interfacesArray=() + # Number of available interfaces + local interfaceCount + # Whiptail variable storage + local chooseInterfaceCmd + # Temporary Whiptail options storage + local chooseInterfaceOptions + # Loop sentinel variable + local firstloop=1 - while read -r line - do - mode="OFF" - if [[ $firstloop -eq 1 ]]; then - firstloop=0 - mode="ON" - fi - userArray+=("${line}" "" "${mode}") - done <<< "${availableUsers}" - chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist "Choose (press space to select):" ${r} ${c} ${numUsers}) - chooseUserOptions=$("${chooseUserCmd[@]}" "${userArray[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]]; then - for desiredUser in ${chooseUserOptions}; do - INSTALL_USER=${desiredUser} - echo "::: Using User: $INSTALL_USER" - echo "${INSTALL_USER}" > /tmp/INSTALL_USER - done - else - echo "::: Cancel selected, exiting...." - exit 1 - fi -} + if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then + PHYS_INT="${availableInterfaces}" + echo "PHYS_INT=${PHYS_INT}" >> /tmp/setupVars.conf + return + fi -verifyFreeDiskSpace() { - # If user installs unattended-upgrades we'd need about 60MB so will check for 75MB free - echo "::: Verifying free disk space..." - local required_free_kilobytes=76800 - local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') + while read -r line; do + mode="OFF" + if [[ ${firstloop} -eq 1 ]]; then + firstloop=0 + mode="ON" + fi + interfacesArray+=("${line}" "available" "${mode}") + done <<< "${availableInterfaces}" - # - Unknown free disk space , not a integer - if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then - echo "::: Unknown free disk space!" - echo "::: We were unable to determine available free disk space on this system." - echo "::: You may continue with the installation, however, it is not recommended." - read -r -p "::: If you are sure you want to continue, type YES and press enter :: " response - case $response in - [Y][E][S]) - ;; - *) - echo "::: Confirmation not received, exiting..." - exit 1 - ;; - esac - # - Insufficient free disk space - elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then - echo "::: Insufficient Disk Space!" - echo "::: Your system appears to be low on disk space. PiVPN recommends a minimum of $required_free_kilobytes KiloBytes." - echo "::: You only have ${existing_free_kilobytes} KiloBytes free." - echo "::: If this is a new install on a Raspberry Pi you may need to expand your disk." - echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'" - echo "::: After rebooting, run this installation again. (curl -L https://install.pivpn.io | bash)" - - echo "Insufficient free space, exiting..." - exit 1 - fi -} - - -chooseInterface() { - # Turn the available interfaces into an array so it can be used with a whiptail dialog - local interfacesArray=() - # Number of available interfaces - local interfaceCount - # Whiptail variable storage - local chooseInterfaceCmd - # Temporary Whiptail options storage - local chooseInterfaceOptions - # Loop sentinel variable - local firstloop=1 - - if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then - pivpnInterface="${availableInterfaces}" - echo "${pivpnInterface}" > /tmp/pivpnINT - return - fi - - while read -r line; do - mode="OFF" - if [[ ${firstloop} -eq 1 ]]; then - firstloop=0 - mode="ON" - fi - interfacesArray+=("${line}" "available" "${mode}") - done <<< "${availableInterfaces}" - - # Find out how many interfaces are available to choose from - interfaceCount=$(echo "${availableInterfaces}" | wc -l) - chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select):" ${r} ${c} ${interfaceCount}) - chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]]; then - for desiredInterface in ${chooseInterfaceOptions}; do - pivpnInterface=${desiredInterface} - echo "::: Using interface: $pivpnInterface" - echo "${pivpnInterface}" > /tmp/pivpnINT - done - else - echo "::: Cancel selected, exiting...." - exit 1 - fi -} - -avoidStaticIPv4Ubuntu() { - # If we are in Ubuntu then they need to have previously set their network, so just use what you have. - whiptail --msgbox --backtitle "IP Information" --title "IP Information" "Since we think you are not using Raspbian, we will not configure a static IP for you. -If you are in Amazon then you can not configure a static IP anyway. Just ensure before this installer started you had set an elastic IP on your instance." ${r} ${c} + # Find out how many interfaces are available to choose from + interfaceCount=$(echo "${availableInterfaces}" | wc -l) + chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select):" ${r} ${c} ${interfaceCount}) + chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) + if [[ $? = 0 ]]; then + for desiredInterface in ${chooseInterfaceOptions}; do + PHYS_INT=${desiredInterface} + echo "::: Using interface: $PHYS_INT" + echo "PHYS_INT=${PHYS_INT}" >> /tmp/setupVars.conf + done + else + echo "::: Cancel selected, exiting...." + exit 1 + fi } getStaticIPv4Settings() { - local ipSettingsCorrect - # Grab their current DNS Server - IPv4dns=$(nslookup 127.0.0.1 | grep Server: | awk '{print $2}') - # Ask if the user wants to use DHCP settings as their static IP - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? - IP address: ${IPv4addr} - Gateway: ${IPv4gw}" ${r} ${c}); then - # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. - whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. + local ipSettingsCorrect + # Grab their current DNS Server + IPv4dns=$(nslookup 127.0.0.1 | grep Server: | awk '{print $2}') + # Ask if the user wants to use DHCP settings as their static IP + if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? + IP address: ${IPv4addr} + Gateway: ${IPv4gw}" ${r} ${c}); then + # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. + whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." ${r} ${c} - # Nothing else to do since the variables are already set above - else - # Otherwise, we need to ask the user to input their desired settings. - # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) - # Start a loop to let the user enter their information with the chance to go back and edit it if necessary - until [[ ${ipSettingsCorrect} = True ]]; do - # Ask for the IPv4 address - IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4addr}" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]]; then - echo "::: Your static IPv4 address: ${IPv4addr}" - # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]]; then - echo "::: Your static IPv4 gateway: ${IPv4gw}" - # Give the user a chance to review their settings before moving on - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? - IP address: ${IPv4addr} - Gateway: ${IPv4gw}" ${r} ${c}); then - # If the settings are correct, then we need to set the pivpnIP - echo "${IPv4addr%/*}" > /tmp/pivpnIP - echo "$pivpnInterface" > /tmp/pivpnINT - # After that's done, the loop ends and we move on - ipSettingsCorrect=True - else - # If the settings are wrong, the loop continues - ipSettingsCorrect=False - fi - else - # Cancelling gateway settings window - ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 - fi - else - # Cancelling IPv4 settings window - ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 - fi - done - # End the if statement for DHCP vs. static - fi + # Nothing else to do since the variables are already set above + else + # Otherwise, we need to ask the user to input their desired settings. + # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) + # Start a loop to let the user enter their information with the chance to go back and edit it if necessary + until [[ ${ipSettingsCorrect} = True ]]; do + # Ask for the IPv4 address + IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4addr}" 3>&1 1>&2 2>&3) + if [[ $? = 0 ]]; then + echo "::: Your static IPv4 address: ${IPv4addr}" + # Ask for the gateway + IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) + if [[ $? = 0 ]]; then + echo "::: Your static IPv4 gateway: ${IPv4gw}" + # Give the user a chance to review their settings before moving on + if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? + IP address: ${IPv4addr} + Gateway: ${IPv4gw}" ${r} ${c}); then + # If the settings are correct, then we need to set the pivpnIP + echo "pivpnIP=${IPv4addr%/*}" >> /tmp/setupVars.conf + # After that's done, the loop ends and we move on + ipSettingsCorrect=True + else + # If the settings are wrong, the loop continues + ipSettingsCorrect=False + fi + else + # Cancelling gateway settings window + ipSettingsCorrect=False + echo "::: Cancel selected. Exiting..." + exit 1 + fi + else + # Cancelling IPv4 settings window + ipSettingsCorrect=False + echo "::: Cancel selected. Exiting..." + exit 1 + fi + done + # End the if statement for DHCP vs. static + fi } -setDHCPCD() { - # Append these lines to dhcpcd.conf to enable a static IP - echo "interface ${pivpnInterface} - static ip_address=${IPv4addr} - static routers=${IPv4gw} - static domain_name_servers=${IPv4dns}" | $SUDO tee -a ${dhcpcdFile} >/dev/null +setDHCPCD(){ + # Append these lines to dhcpcd.conf to enable a static IP + echo "interface ${PHYS_INT} + static ip_address=${IPv4addr} + static routers=${IPv4gw} + static domain_name_servers=${IPv4dns}" | $SUDO tee -a ${dhcpcdFile} >/dev/null } -setStaticIPv4() { - # Tries to set the IPv4 address - if [[ -f /etc/dhcpcd.conf ]]; then - if grep -q "${IPv4addr}" ${dhcpcdFile}; then - echo "::: Static IP already configured." - else - setDHCPCD - $SUDO ip addr replace dev "${pivpnInterface}" "${IPv4addr}" - echo ":::" - echo "::: Setting IP to ${IPv4addr}. You may need to restart after the install is complete." - echo ":::" - fi - else - echo "::: Critical: Unable to locate configuration file to set static IPv4 address!" - exit 1 - fi +setStaticIPv4(){ + # Tries to set the IPv4 address + if [[ -f /etc/dhcpcd.conf ]]; then + if grep -q "${IPv4addr}" ${dhcpcdFile}; then + echo "::: Static IP already configured." + else + setDHCPCD + $SUDO ip addr replace dev "${PHYS_INT}" "${IPv4addr}" + echo ":::" + echo "::: Setting IP to ${IPv4addr}. You may need to restart after the install is complete." + echo ":::" + fi + else + echo "::: Critical: Unable to locate configuration file to set static IPv4 address!" + exit 1 + fi } -function valid_ip() -{ - local ip=$1 - local stat=1 +chooseUser(){ + # Explain the local user + whiptail --msgbox --backtitle "Parsing User List" --title "Local Users" "Choose a local user that will hold your ovpn configurations." ${r} ${c} + # First, let's check if there is a user available. + numUsers=$(awk -F':' 'BEGIN {count=0} $3>=1000 && $3<=60000 { count++ } END{ print count }' /etc/passwd) + if [ "$numUsers" -eq 0 ] + then + # We don't have a user, let's ask to add one. + if userToAdd=$(whiptail --title "Choose A User" --inputbox "No non-root user account was found. Please type a new username." ${r} ${c} 3>&1 1>&2 2>&3) + then + # See http://askubuntu.com/a/667842/459815 + PASSWORD=$(whiptail --title "password dialog" --passwordbox "Please enter the new user password" ${r} ${c} 3>&1 1>&2 2>&3) + CRYPT=$(perl -e 'printf("%s\n", crypt($ARGV[0], "password"))' "${PASSWORD}") + $SUDO useradd -m -p "${CRYPT}" -s /bin/bash "${userToAdd}" + if [[ $? = 0 ]]; then + echo "Succeeded" + ((numUsers+=1)) + else + exit 1 + fi + else + exit 1 + fi + fi + availableUsers=$(awk -F':' '$3>=1000 && $3<=60000 {print $1}' /etc/passwd) + local userArray=() + local firstloop=1 - if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - OIFS=$IFS - IFS='.' - ip=($ip) - IFS=$OIFS - [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ - && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] - stat=$? - fi - return $stat + while read -r line + do + mode="OFF" + if [[ $firstloop -eq 1 ]]; then + firstloop=0 + mode="ON" + fi + userArray+=("${line}" "" "${mode}") + done <<< "${availableUsers}" + chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist "Choose (press space to select):" ${r} ${c} ${numUsers}) + chooseUserOptions=$("${chooseUserCmd[@]}" "${userArray[@]}" 2>&1 >/dev/tty) + if [[ $? = 0 ]]; then + for desiredUser in ${chooseUserOptions}; do + install_user=${desiredUser} + echo "::: Using User: $install_user" + install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6) + install_home=${install_home%/} # remove possible trailing slash + echo "install_user=${install_user}" >> /tmp/setupVars.conf + echo "install_home=${install_home}" >> /tmp/setupVars.conf + done + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + + +} + +isRepo(){ + # If the directory does not have a .git folder it is not a repo + echo -n "::: Checking $1 is a repo..." + cd "${1}" &> /dev/null || return 1 + $SUDO git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 +} + +updateRepo(){ + # Pull the latest commits + echo -n "::: Updating repo in $1..." + $SUDO rm -rf "${1}" + # Go back to /etc otherwhise git will complain when the current working + # directory has just been deleted (/etc/.pivpn). + cd /etc + $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + cd "${1}" || exit 1 + if [ -z "${TESTING}" ]; then + : + elif [ "${TESTING}" = "test" ]; then + ${SUDOE} git checkout test + elif [ "${TESTING}" = "test-wireguard" ]; then + ${SUDOE} git checkout test-wireguard + fi + echo " done!" +} + +makeRepo(){ + # Remove the non-repos interface and clone the interface + echo -n "::: Cloning $2 into $1..." + $SUDO rm -rf "${1}" + $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + if [ -z "${TESTING}" ]; then + : + elif [ "${TESTING}" = "test" ]; then + ${SUDOE} git checkout test + elif [ "${TESTING}" = "test-wireguard" ]; then + ${SUDOE} git checkout test-wireguard + fi + echo " done!" +} + +getGitFiles(){ + # Setup git repos for base files + echo ":::" + echo "::: Checking for existing base files..." + if isRepo "${1}"; then + updateRepo "${1}" "${2}" + else + makeRepo "${1}" "${2}" + fi +} + +cloneOrUpdateRepos(){ + # Get Git files + getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \ + { echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \ + exit 1; \ +} +} + +askWhichVPN(){ + if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard of 'No' to use OpenVPN." ${r} ${c}); + then + VPN="WireGuard" + pivpnINT="wg0" + else + VPN="OpenVPN" + pivpnINT="tun0" + fi + + echo "VPN=${VPN}" >> /tmp/setupVars.conf + echo "pivpnINT=${pivpnINT}" >> /tmp/setupVars.conf +} + +installOpenVPN(){ + echo "::: Installing OpenVPN from Debian package... " + # grepcidr is used to redact IPs in the debug log, whereas expect is used + # to feed easy-rsa with passwords + PIVPN_DEPS=(openvpn grepcidr expect) + installDependentPackages PIVPN_DEPS[@] +} + +installWireGuard(){ + # If this Raspberry Pi uses armv7l we can use the package from the repo + # https://lists.zx2c4.com/pipermail/wireguard/2017-November/001885.html + # Otherwhise compile and build the kernel module via DKMS (so it will + # be recompiled on kernel upgrades) + if [ "$(uname -m)" = "armv7l" ]; then + echo "::: Installing WireGuard from Debian package... " + # dirmngr is used to download repository keys, whereas qrencode is used to generate qrcodes + # from config file, for use with mobile clients + PIVPN_DEPS=(dirmngr qrencode) + installDependentPackages PIVPN_DEPS[@] + # Do not upgrade packages from the unstable repository except for wireguard + echo "::: Adding Debian repository... " + echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee -a /etc/apt/sources.list.d/unstable.list > /dev/null + echo "Package: * +Pin: release a=unstable +Pin-Priority: 1 + +Package: wireguard wireguard-dkms wireguard-tools +Pin: release a=unstable +Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/null + + $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + PIVPN_DEPS=(wireguard) + installDependentPackages PIVPN_DEPS[@] + elif [ "$(uname -m)" = "armv6l" ]; then + echo "::: Installing WireGuard from source... " + PIVPN_DEPS=(libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode) + installDependentPackages PIVPN_DEPS[@] + + # Delete any leftover code + $SUDO rm -rf /usr/src/wireguard-* + + echo -n "::: Downloading source code... " + wget -O- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src + echo "done!" + + cd /usr/src + $SUDO mv WireGuard-"${WG_SNAPSHOT}" wireguard-"${WG_SNAPSHOT}" + cd wireguard-"${WG_SNAPSHOT}" + $SUDO mv src/* . + $SUDO rmdir src + + # We install the userspace tools manually since DKMS only compiles and + # installs the kernel module + echo -n "::: Compiling WireGuard tools... " + if $SUDO make tools; then + echo "done!" + else + echo "failed!" + exit 1 + fi + + echo -n "::: Installing WireGuard tools... " + if $SUDO make install tools; then + echo "done!" + else + echo "failed!" + exit 1 + fi + + echo -n "::: Adding WireGuard modules via DKMS... " + if $SUDO dkms add wireguard/"${WG_SNAPSHOT}"; then + echo "done!" + else + echo "failed!" + $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + exit 1 + fi + + echo -n "::: Compiling WireGuard modules via DKMS... " + if $SUDO dkms build wireguard/"${WG_SNAPSHOT}"; then + echo "done!" + else + echo "failed!" + $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + exit 1 + fi + + echo -n "::: Installing WireGuard modules via DKMS... " + if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then + echo "done!" + else + echo "failed!" + $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + exit 1 + fi + fi +} + +validIP(){ + local ip=$1 + local stat=1 + + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ + && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + stat=$? + fi + return $stat } #Call this function to use a regex to check user input for a valid custom domain -function valid_domain() -{ - local domain=$1 - local stat=1 +validDomain(){ + local domain=$1 + local stat=1 - - if [[ $domain =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}\.[a-zA-Z]{2,}$ ]]; then - stat=$? - fi + if [[ $domain =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}\.[a-zA-Z]{2,}$ ]]; then + stat=$? + fi return $stat } -installScripts() { - # Install the scripts from /etc/.pivpn to their various locations - $SUDO echo ":::" - $SUDO echo -n "::: Installing scripts to /opt/pivpn..." - if [ ! -d /opt/pivpn ]; then - $SUDO mkdir /opt/pivpn - $SUDO chown "$INSTALL_USER":root /opt/pivpn - $SUDO chmod 0755 /opt/pivpn - fi - $SUDO cp /etc/.pivpn/scripts/*.sh /opt/pivpn/ - $SUDO chmod 0755 /opt/pivpn/*.sh - $SUDO cp /etc/.pivpn/pivpn /usr/local/bin/pivpn - $SUDO chmod 0755 /usr/local/bin/pivpn - $SUDO cp /etc/.pivpn/scripts/bash-completion /etc/bash_completion.d/pivpn - . /etc/bash_completion.d/pivpn - # Copy interface setting for debug - $SUDO cp /tmp/pivpnINT /etc/pivpn/pivpnINTERFACE - - $SUDO echo " done." +askCustomProto(){ + # Set the available protocols into an array so it can be used with a whiptail dialog + if protocol=$(whiptail --title "Protocol" --radiolist \ + "Choose a protocol (press space to select). Please only choose TCP if you know why you need TCP." ${r} ${c} 2 \ + "UDP" "" ON \ + "TCP" "" OFF 3>&1 1>&2 2>&3) + then + # Convert option into lowercase (UDP->udp) + pivpnPROTO="${protocol,,}" + echo "::: Using protocol: $pivpnPROTO" + echo "pivpnPROTO=${pivpnPROTO}" >> /tmp/setupVars.conf + else + echo "::: Cancel selected, exiting...." + exit 1 + fi } -package_check_install() { - dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" +askCustomPort(){ + until [[ $PORTNumCorrect = True ]] + do + portInvalid="Invalid" + + if [ "$VPN" = "WireGuard" ]; then + DEFAULT_PORT=51820 + elif [ "$VPN" = "OpenVPN" ]; then + if [ "$pivpnPROTO" = "udp" ]; then + DEFAULT_PORT=1194 + else + DEFAULT_PORT=443 + fi + fi + + if pivpnPORT=$(whiptail --title "Default $VPN Port" --inputbox "You can modify the default $VPN port. \nEnter a new value or hit 'Enter' to retain the default" ${r} ${c} $DEFAULT_PORT 3>&1 1>&2 2>&3) + then + if [[ "$pivpnPORT" =~ ^[0-9]+$ ]] && [ "$pivpnPORT" -ge 1 ] && [ "$pivpnPORT" -le 65535 ]; then + : + else + pivpnPORT=$portInvalid + fi + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + + if [[ $pivpnPORT == "$portInvalid" ]]; then + whiptail --msgbox --backtitle "Invalid Port" --title "Invalid Port" "You entered an invalid Port number.\n Please enter a number from 1 - 65535.\n If you are not sure, please just keep the default." ${r} ${c} + PORTNumCorrect=False + else + if (whiptail --backtitle "Specify Custom Port" --title "Confirm Custom Port Number" --yesno "Are these settings correct?\n PORT: $pivpnPORT" ${r} ${c}) then + PORTNumCorrect=True + else + # If the settings are wrong, the loop continues + PORTNumCorrect=False + fi + fi + done + # write out the port + echo "pivpnPORT=${pivpnPORT}" >> /tmp/setupVars.conf } -addSoftwareRepo() { - # Add the official OpenVPN repo for distros that don't have the latest version in their default repos - case ${PLAT} in - Ubuntu|Debian|Devuan) - case ${OSCN} in - trusty|xenial|wheezy|jessie) - wget -qO- https://swupdate.openvpn.net/repos/repo-public.gpg | $SUDO apt-key add - - echo "deb http://build.openvpn.net/debian/openvpn/stable $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null - echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." - $SUDO $PKG_MANAGER -qq update & spinner $! - echo " done!" - ;; - esac - ;; - esac -} +askClientDNS() { + DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients (press space to select). To use your own, select Custom." ${r} ${c} 6) + DNSChooseOptions=(Google "" on + OpenDNS "" off + Level3 "" off + DNS.WATCH "" off + Norton "" off + FamilyShield "" off + CloudFlare "" off + Custom "" off) -update_package_cache() { - #Running apt-get update/upgrade with minimal output can cause some issues with - #requiring user input + if DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) + then - #Check to see if apt-get update has already been run today - #it needs to have been run at least once on new installs! - timestamp=$(stat -c %Y ${PKG_CACHE}) - timestampAsDate=$(date -d @"${timestamp}" "+%b %e") - today=$(date "+%b %e") + if [[ ${DNSchoices} != "Custom" ]]; then + echo "::: Using ${DNSchoices} servers." + declare -A DNS_MAP=(["Google"]="8.8.8.8 8.8.4.4" + ["OpenDNS"]="208.67.222.222 208.67.220.220" + ["Level3"]="209.244.0.3 209.244.0.4" + ["DNS.WATCH"]="84.200.69.80 84.200.70.40" + ["Norton"]="199.85.126.10 199.85.127.10" + ["FamilyShield"]="208.67.222.123 208.67.220.123" + ["CloudFlare"]="1.1.1.1 1.0.0.1") - if [ ! "${today}" == "${timestampAsDate}" ]; then - #update package lists - echo ":::" - echo -ne "::: ${PKG_MANAGER} update has not been run today. Running now...\n" - $SUDO ${UPDATE_PKG_CACHE} &> /dev/null - echo " done!" - fi -} + pivpnDNS1=$(awk '{print $1}' <<< "${DNS_MAP["${DNSchoices}"]}") + pivpnDNS2=$(awk '{print $2}' <<< "${DNS_MAP["${DNSchoices}"]}") -notify_package_updates_available() { - # Let user know if they have outdated packages on their system and - # advise them to run a package update at soonest possible. - echo ":::" - echo -n "::: Checking ${PKG_MANAGER} for upgraded packages...." - updatesToInstall=$(eval "${PKG_COUNT}") - echo " done!" - echo ":::" - if [[ ${updatesToInstall} -eq "0" ]]; then - echo "::: Your system is up to date! Continuing with PiVPN installation..." - else - echo "::: There are ${updatesToInstall} updates available for your system!" - echo "::: We recommend you update your OS after installing PiVPN! " - echo ":::" - fi -} + else -install_dependent_packages() { - # Install packages passed in via argument array - # No spinner - conflicts with set -e - declare -a argArray1=("${!1}") + until [[ $DNSSettingsCorrect = True ]]; do + strInvalid="Invalid" - if [[ ${OSCN} == "buster" ]]; then - $SUDO update-alternatives --set iptables /usr/sbin/iptables-legacy - $SUDO update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy - fi - echo iptables-persistent iptables-persistent/autosave_v4 boolean true | $SUDO debconf-set-selections - echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections + if pivpnDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "" 3>&1 1>&2 2>&3) + then + pivpnDNS1=$(echo "$pivpnDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') + pivpnDNS2=$(echo "$pivpnDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') + if ! validIP "$pivpnDNS1" || [ ! "$pivpnDNS1" ]; then + pivpnDNS1=$strInvalid + fi + if ! validIP "$pivpnDNS2" && [ "$pivpnDNS2" ]; then + pivpnDNS2=$strInvalid + fi + else + echo "::: Cancel selected, exiting...." + exit 1 + fi - # Add support for https repositories if there are any that use it otherwise the installation will silently fail - if grep -q https /etc/apt/sources.list; then - PIVPN_DEPS+=("apt-transport-https") - fi + if [[ $pivpnDNS1 == "$strInvalid" ]] || [[ $pivpnDNS2 == "$strInvalid" ]]; then + whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $pivpnDNS1\n DNS Server 2: $pivpnDNS2" ${r} ${c} + if [[ $pivpnDNS1 == "$strInvalid" ]]; then + pivpnDNS1="" + fi + if [[ $pivpnDNS2 == "$strInvalid" ]]; then + pivpnDNS2="" + fi + DNSSettingsCorrect=False + else + if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $pivpnDNS1\n DNS Server 2: $pivpnDNS2" ${r} ${c}) then + DNSSettingsCorrect=True + else + # If the settings are wrong, the loop continues + DNSSettingsCorrect=False + fi + fi + done + fi - if command -v debconf-apt-progress &> /dev/null; then - $SUDO debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" - else - for i in "${argArray1[@]}"; do - echo -n "::: Checking for $i..." - $SUDO package_check_install "${i}" &> /dev/null - echo " installed!" - done - fi -} + else + echo "::: Cancel selected. Exiting..." + exit 1 + fi -unattendedUpgrades() { - whiptail --msgbox --backtitle "Security Updates" --title "Unattended Upgrades" "Since this server will have at least one port open to the internet, it is recommended you enable unattended-upgrades.\nThis feature will check daily for security package updates only and apply them when necessary.\nIt will NOT automatically reboot the server so to fully apply some updates you should periodically reboot." ${r} ${c} - - if (whiptail --backtitle "Security Updates" --title "Unattended Upgrades" --yesno "Do you want to enable unattended upgrades of security patches to this server?" ${r} ${c}) then - UNATTUPG="unattended-upgrades" - else - UNATTUPG="" - fi -} - -stopServices() { - # Stop openvpn - $SUDO echo ":::" - $SUDO echo -n "::: Stopping OpenVPN service..." - case ${PLAT} in - Ubuntu|Debian|*vuan) - $SUDO service openvpn stop || true - ;; - *) - $SUDO systemctl stop openvpn.service || true - ;; - esac - $SUDO echo " done." -} - -getGitFiles() { - # Setup git repos for base files - echo ":::" - echo "::: Checking for existing base files..." - if is_repo "${1}"; then - update_repo "${1}" "${2}" - else - make_repo "${1}" "${2}" - fi -} - -is_repo() { - # If the directory does not have a .git folder it is not a repo - echo -n "::: Checking $1 is a repo..." - cd "${1}" &> /dev/null || return 1 - $SUDO git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 -} - -make_repo() { - # Remove the non-repos interface and clone the interface - echo -n "::: Cloning $2 into $1..." - $SUDO rm -rf "${1}" - $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! - if [ -z "${TESTING+x}" ]; then - : - else - $SUDO git -C "${1}" checkout test - fi - echo " done!" -} - -update_repo() { - if [[ "${reconfigure}" == true ]]; then - echo "::: --reconfigure passed to install script. Not downloading/updating local repos" - else - # Pull the latest commits - echo -n "::: Updating repo in $1..." - $SUDO rm -rf "${1}" - # Go back to /etc otherwhise git will complain when the current working directory has - # just been deleted (/etc/.pivpn). - cd /etc - $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! - cd "${1}" || exit 1 - if [ -z "${TESTING+x}" ]; then - : - else - ${SUDOE} git checkout test - fi - echo " done!" - fi -} - -setCustomProto() { - # Set the available protocols into an array so it can be used with a whiptail dialog - if protocol=$(whiptail --title "Protocol" --radiolist \ - "Choose a protocol (press space to select). Please only choose TCP if you know why you need TCP." ${r} ${c} 2 \ - "UDP" "" ON \ - "TCP" "" OFF 3>&1 1>&2 2>&3) - then - # Convert option into lowercase (UDP->udp) - pivpnProto="${protocol,,}" - echo "::: Using protocol: $pivpnProto" - echo "${pivpnProto}" > /tmp/pivpnPROTO - else - echo "::: Cancel selected, exiting...." - exit 1 - fi - # write out the PROTO - PROTO=$pivpnProto - $SUDO cp /tmp/pivpnPROTO /etc/pivpn/INSTALL_PROTO -} - - -setCustomPort() { - until [[ $PORTNumCorrect = True ]] - do - portInvalid="Invalid" - - PROTO=$(cat /etc/pivpn/INSTALL_PROTO) - if [ "$PROTO" = "udp" ]; then - DEFAULT_PORT=1194 - else - DEFAULT_PORT=443 - fi - if PORT=$(whiptail --title "Default OpenVPN Port" --inputbox "You can modify the default OpenVPN port. \nEnter a new value or hit 'Enter' to retain the default" ${r} ${c} $DEFAULT_PORT 3>&1 1>&2 2>&3) - then - if [[ "$PORT" =~ ^[0-9]+$ ]] && [ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ]; then - : - else - PORT=$portInvalid - fi - else - echo "::: Cancel selected, exiting...." - exit 1 - fi - - if [[ $PORT == "$portInvalid" ]]; then - whiptail --msgbox --backtitle "Invalid Port" --title "Invalid Port" "You entered an invalid Port number.\n Please enter a number from 1 - 65535.\n If you are not sure, please just keep the default." ${r} ${c} - PORTNumCorrect=False - else - if (whiptail --backtitle "Specify Custom Port" --title "Confirm Custom Port Number" --yesno "Are these settings correct?\n PORT: $PORT" ${r} ${c}) then - PORTNumCorrect=True - else - # If the settings are wrong, the loop continues - PORTNumCorrect=False - fi - fi - done - # write out the port - echo ${PORT} > /tmp/INSTALL_PORT - $SUDO cp /tmp/INSTALL_PORT /etc/pivpn/INSTALL_PORT -} - -setClientDNS() { - DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients (press space to select). To use your own, select Custom." ${r} ${c} 6) - DNSChooseOptions=(Google "" on - OpenDNS "" off - Level3 "" off - DNS.WATCH "" off - Norton "" off - FamilyShield "" off - CloudFlare "" off - Custom "" off) - - if DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) - then - - if [[ ${DNSchoices} != "Custom" ]]; then - - echo "::: Using ${DNSchoices} servers." - declare -A DNS_MAP=(["Google"]="8.8.8.8 8.8.4.4" ["OpenDNS"]="208.67.222.222 208.67.220.220" ["Level3"]="209.244.0.3 209.244.0.4" ["DNS.WATCH"]="84.200.69.80 84.200.70.40" ["Norton"]="199.85.126.10 199.85.127.10" ["FamilyShield"]="208.67.222.123 208.67.220.123" ["CloudFlare"]="1.1.1.1 1.0.0.1") - - OVPNDNS1=$(awk '{print $1}' <<< "${DNS_MAP["${DNSchoices}"]}") - OVPNDNS2=$(awk '{print $2}' <<< "${DNS_MAP["${DNSchoices}"]}") - - $SUDO sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${OVPNDNS1}'\"/' /etc/openvpn/server.conf - $SUDO sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${OVPNDNS2}'\"/' /etc/openvpn/server.conf - - else - - until [[ $DNSSettingsCorrect = True ]] - do - strInvalid="Invalid" - - if OVPNDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "" 3>&1 1>&2 2>&3) - then - OVPNDNS1=$(echo "$OVPNDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') - OVPNDNS2=$(echo "$OVPNDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') - if ! valid_ip "$OVPNDNS1" || [ ! "$OVPNDNS1" ]; then - OVPNDNS1=$strInvalid - fi - if ! valid_ip "$OVPNDNS2" && [ "$OVPNDNS2" ]; then - OVPNDNS2=$strInvalid - fi - else - echo "::: Cancel selected, exiting...." - exit 1 - fi - if [[ $OVPNDNS1 == "$strInvalid" ]] || [[ $OVPNDNS2 == "$strInvalid" ]]; then - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $OVPNDNS1\n DNS Server 2: $OVPNDNS2" ${r} ${c} - if [[ $OVPNDNS1 == "$strInvalid" ]]; then - OVPNDNS1="" - fi - if [[ $OVPNDNS2 == "$strInvalid" ]]; then - OVPNDNS2="" - fi - DNSSettingsCorrect=False - else - if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $OVPNDNS1\n DNS Server 2: $OVPNDNS2" ${r} ${c}) then - DNSSettingsCorrect=True - $SUDO sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${OVPNDNS1}'\"/' /etc/openvpn/server.conf - if [ -z ${OVPNDNS2} ]; then - $SUDO sed -i '/\(dhcp-option DNS \)/{n;N;d}' /etc/openvpn/server.conf - else - $SUDO sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${OVPNDNS2}'\"/' /etc/openvpn/server.conf - fi - else - # If the settings are wrong, the loop continues - DNSSettingsCorrect=False - fi - fi - done - fi - - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi + echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf + echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf } #This procedure allows a user to specify a custom search domain if they have one. -setCustomDomain() { - DomainSettingsCorrect=False +askCustomDomain(){ + DomainSettingsCorrect=False - if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Would you like to add a custom search domain? \n (This is only for advanced users who have their own domain)\n" ${r} ${c}); then + if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Would you like to add a custom search domain? \n (This is only for advanced users who have their own domain)\n" ${r} ${c}); then - until [[ $DomainSettingsCorrect = True ]] - do - if CUSTOMDomain=$(whiptail --inputbox "Enter Custom Domain\nFormat: mydomain.com" ${r} ${c} --title "Custom Domain" 3>&1 1>&2 2>&3); then - if valid_domain "$CUSTOMDomain"; then - if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\n Custom Search Domain: $CUSTOMDomain" ${r} ${c}); then - DomainSettingsCorrect=True + until [[ $DomainSettingsCorrect = True ]] + do + if pivpnDOMAIN=$(whiptail --inputbox "Enter Custom Domain\nFormat: mydomain.com" ${r} ${c} --title "Custom Domain" 3>&1 1>&2 2>&3); then + if validDomain "$pivpnDOMAIN"; then + if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\n Custom Search Domain: $pivpnDOMAIN" ${r} ${c}); then + DomainSettingsCorrect=True + echo "pivpnDOMAIN=${pivpnDOMAIN}" >> /tmp/setupVars.conf + else + # If the settings are wrong, the loop continues + DomainSettingsCorrect=False + fi + else + whiptail --msgbox --backtitle "Invalid Domain" --title "Invalid Domain" "Domain is invalid. Please try again.\n\n DOMAIN: $pivpnDOMAIN\n" ${r} ${c} + DomainSettingsCorrect=False + fi + else + echo "::: Cancel selected. Exiting..." + exit 1 + fi + done - $SUDO sed -i '0,/\(.*dhcp-option.*\)/s//\push "dhcp-option DOMAIN '${CUSTOMDomain}'" \n&/' /etc/openvpn/server.conf - - else - # If the settings are wrong, the loop continues - DomainSettingsCorrect=False - fi - else - whiptail --msgbox --backtitle "Invalid Domain" --title "Invalid Domain" "Domain is invalid. Please try again.\n\n DOMAIN: $CUSTOMDomain\n" ${r} ${c} - DomainSettingsCorrect=False - fi - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi - done - - else - echo sleep 0.1 - fi + else + echo sleep 0.1 + fi } -confOpenVPN() { - # Grab the existing Hostname - host_name=$(hostname -s) - # Generate a random UUID for this server so that we can use verify-x509-name later that is unique for this server installation. - NEW_UUID=$(&1 1>&2 2>&3) - if [[ ${useUpdateVars} == false ]]; then - # Ask user for desired level of encryption + exitstatus=$? + if [ $exitstatus != 0 ]; then + echo "::: Cancel selected. Exiting..." + exit 1 + fi - if [[ ${useUpdateVars} == false ]]; then + if [ "$METH" == "$IPv4pub" ]; then + pivpnHOST="${IPv4pub}" + else + until [[ $publicDNSCorrect = True ]] + do + PUBLICDNS=$(whiptail --title "PiVPN Setup" --inputbox "What is the public DNS name of this Server?" ${r} ${c} 3>&1 1>&2 2>&3) + exitstatus=$? + if [ $exitstatus != 0 ]; then + echo "::: Cancel selected. Exiting..." + exit 1 + fi + if (whiptail --backtitle "Confirm DNS Name" --title "Confirm DNS Name" --yesno "Is this correct?\n\n Public DNS Name: $PUBLICDNS" ${r} ${c}) then + publicDNSCorrect=True + pivpnHOST="${PUBLICDNS}" + else + publicDNSCorrect=False + fi + done + fi - if [[ ${PLAT} == "Raspbian" ]] && [[ ${OSCN} != "stretch" ]] && [[ ${OSCN} != "buster" ]] ; then + echo "pivpnHOST=${pivpnHOST}" >> /tmp/setupVars.conf +} - APPLY_TWO_POINT_FOUR=false - else - if (whiptail --backtitle "Setup OpenVPN" --title "Installation mode" --yesno "OpenVPN 2.4 brings support for stronger authentication and key exchange using Elliptic Curves, along with encrypted control channel.\n\nIf your clients do run OpenVPN 2.4 or later you can enable these features, otherwise choose 'No' for best compatibility.\n\nNOTE: Current mobile app, that is OpenVPN connect, is supported." ${r} ${c}); then - APPLY_TWO_POINT_FOUR=true - $SUDO touch /etc/pivpn/TWO_POINT_FOUR - else - APPLY_TWO_POINT_FOUR=false - fi - fi - fi +askEncryption(){ + pivpnENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "RSA certificate size" --radiolist \ + "Choose the desired size of your certificate (press space to select):\nThis is a certificate that will be generated on your system. The larger the certificate, the more time this will take. For most applications, it is recommended to use 2048 bits. If you are paranoid about ... things... then grab a cup of joe and pick 4096 bits." ${r} ${c} 3 \ + "2048" "Use a 2048-bit certificate (recommended level)" ON \ + "3072" "Use a 3072-bit certificate " OFF \ + "4096" "Use a 4096-bit certificate (paranoid level)" OFF 3>&1 1>&2 2>&3) - if [[ ${runUnattended} == true ]] && [[ ${APPLY_TWO_POINT_FOUR} == true ]]; then - $SUDO touch /etc/pivpn/TWO_POINT_FOUR - fi + exitstatus=$? + if [ $exitstatus != 0 ]; then + echo "::: Cancel selected. Exiting..." + exit 1 + fi - if [[ ${APPLY_TWO_POINT_FOUR} == false ]]; then + if ([ "$pivpnENCRYPT" -ge "3072" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\n\nGenerating DH parameters for a $pivpnENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from their database.\nMore information about this service can be found here: https://2ton.com.au/safeprimes/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}); then + DOWNLOAD_DH_PARAM=true + else + DOWNLOAD_DH_PARAM=false + fi - ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "RSA certificate size" --radiolist \ - "Choose the desired size of your certificate (press space to select):\n This is a certificate that will be generated on your system. The larger the certificate, the more time this will take. For most applications, it is recommended to use 2048 bits. If you are testing, you can use 1024 bits to speed things up, but do not use this for normal use! If you are paranoid about ... things... then grab a cup of joe and pick 4096 bits." ${r} ${c} 3 \ - "1024" "Use a 1024-bit certificate (testing only)" OFF \ - "2048" "Use a 2048-bit certificate (recommended level)" ON \ - "4096" "Use a 4096-bit certificate (paranoid level)" OFF 3>&1 1>&2 2>&3) + echo "pivpnENCRYPT=${pivpnENCRYPT}" >> /tmp/setupVars.conf + echo "DOWNLOAD_DH_PARAM=${DOWNLOAD_DH_PARAM}" >> /tmp/setupVars.conf +} - else +confOpenVPN(){ + # Grab the existing Hostname + host_name=$(hostname -s) + # Generate a random UUID for this server so that we can use verify-x509-name later that is unique for this server installation. + NEW_UUID=$(&1 1>&2 2>&3) + # If easy-rsa exists, remove it + if [[ -d /etc/openvpn/easy-rsa/ ]]; then + $SUDO rm -rf /etc/openvpn/easy-rsa/ + fi - fi + # Get easy-rsa + wget -q -O - "${easyrsaRel}" | $SUDO tar xz -C /etc/openvpn && $SUDO mv /etc/openvpn/EasyRSA-v${easyrsaVer} /etc/openvpn/easy-rsa + # fix ownership + $SUDO chown -R root:root /etc/openvpn/easy-rsa + $SUDO mkdir /etc/openvpn/easy-rsa/pki - exitstatus=$? - if [ $exitstatus != 0 ]; then - echo "::: Cancel selected. Exiting..." - exit 1 - fi - fi + cd /etc/openvpn/easy-rsa || exit - # If easy-rsa exists, remove it - if [[ -d /etc/openvpn/easy-rsa/ ]]; then - $SUDO rm -rf /etc/openvpn/easy-rsa/ - fi - - - # Get easy-rsa - wget -q -O - "${easyrsaRel}" | $SUDO tar xz -C /etc/openvpn && $SUDO mv /etc/openvpn/EasyRSA-v${easyrsaVer} /etc/openvpn/easy-rsa - # fix ownership - $SUDO chown -R root:root /etc/openvpn/easy-rsa - $SUDO mkdir /etc/openvpn/easy-rsa/pki - - cd /etc/openvpn/easy-rsa || exit - - # Write out new vars file - set +e - IFS= read -d '' String <<"EOF" -if [ -z "$EASYRSA_CALLER" ]; then - echo "Nope." >&2 - return 1 + # Write out new vars file + echo "if [ -z \"\$EASYRSA_CALLER\" ]; then + echo \"Nope.\" >&2 + return 1 fi -set_var EASYRSA "/etc/openvpn/easy-rsa" -set_var EASYRSA_PKI "$EASYRSA/pki" +set_var EASYRSA \"/etc/openvpn/easy-rsa\" +set_var EASYRSA_PKI \"\$EASYRSA/pki\" set_var EASYRSA_CRL_DAYS 3650 -EOF - echo "${String}" | $SUDO tee vars >/dev/null - set -e +set_var EASYRSA_ALGO rsa +set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null - # Set certificate type - if [[ ${APPLY_TWO_POINT_FOUR} == false ]]; then - echo "set_var EASYRSA_ALGO rsa" | $SUDO tee -a vars - echo "set_var EASYRSA_KEY_SIZE ${ENCRYPT}" | $SUDO tee -a vars - else - echo "set_var EASYRSA_ALGO ec" | $SUDO tee -a vars - echo "set_var EASYRSA_CURVE ${ECDSA_MAP["${ENCRYPT}"]}" | $SUDO tee -a vars - fi + # Remove any previous keys + ${SUDOE} ./easyrsa --batch init-pki - # Remove any previous keys - ${SUDOE} ./easyrsa --batch init-pki + # Build the certificate authority + printf "::: Building CA...\n" + ${SUDOE} ./easyrsa --batch build-ca nopass + printf "\n::: CA Complete.\n" - # Build the certificate authority - printf "::: Building CA...\n" - ${SUDOE} ./easyrsa --batch build-ca nopass - printf "\n::: CA Complete.\n" + whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman parameters, and HMAC key will now be generated." ${r} ${c} - if [[ ${useUpdateVars} == false ]]; then - if [[ ${APPLY_TWO_POINT_FOUR} == false ]]; then - whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman parameters, and HMAC key will now be generated." ${r} ${c} - fi - fi + # Build the server + EASYRSA_CERT_EXPIRE=3650 ${SUDOE} ./easyrsa build-server-full ${SERVER_NAME} nopass - # Build the server - EASYRSA_CERT_EXPIRE=3650 ${SUDOE} ./easyrsa build-server-full ${SERVER_NAME} nopass + if [[ ${DOWNLOAD_DH_PARAM} == true ]]; then + # Downloading parameters + ${SUDOE} curl "https://2ton.com.au/getprimes/random/dhparam/${pivpnENCRYPT}" -o "/etc/openvpn/easy-rsa/pki/dh${pivpnENCRYPT}.pem" + else + # Generate Diffie-Hellman key exchange + ${SUDOE} ./easyrsa gen-dh + ${SUDOE} mv pki/dh.pem pki/dh${pivpnENCRYPT}.pem + fi - if [[ ${useUpdateVars} == false ]]; then - if [[ ${APPLY_TWO_POINT_FOUR} == false ]]; then - if ([ "$ENCRYPT" -ge "4096" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\n\nGenerating DH parameters for a $ENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from their database.\nMore information about this service can be found here: https://2ton.com.au/safeprimes/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}); then - DOWNLOAD_DH_PARAM=true - else - DOWNLOAD_DH_PARAM=false - fi - else - DOWNLOAD_DH_PARAM=false - fi - fi + # Generate static HMAC key to defend against DDoS + ${SUDOE} openvpn --genkey --secret pki/ta.key - if [[ ${APPLY_TWO_POINT_FOUR} == false ]]; then - if [ "$ENCRYPT" -ge "4096" ] && [[ ${DOWNLOAD_DH_PARAM} == true ]]; then - # Downloading parameters - ${SUDOE} curl "https://2ton.com.au/getprimes/random/dhparam/${ENCRYPT}" -o "/etc/openvpn/easy-rsa/pki/dh${ENCRYPT}.pem" - else - # Generate Diffie-Hellman key exchange - ${SUDOE} ./easyrsa gen-dh - ${SUDOE} mv pki/dh.pem pki/dh${ENCRYPT}.pem - fi - fi + # Generate an empty Certificate Revocation List + ${SUDOE} ./easyrsa gen-crl + ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem + ${SUDOE} chown nobody:nogroup /etc/openvpn/crl.pem - # Generate static HMAC key to defend against DDoS - ${SUDOE} openvpn --genkey --secret pki/ta.key + # Write config file for server using the template.txt file + $SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf - # Generate an empty Certificate Revocation List - ${SUDOE} ./easyrsa gen-crl - ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem - ${SUDOE} chown nobody:nogroup /etc/openvpn/crl.pem + # Apply client DNS settings + ${SUDOE} sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${pivpnDNS1}'\"/' /etc/openvpn/server.conf - # Write config file for server using the template.txt file - $SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf + if [ -z ${pivpnDNS2} ]; then + ${SUDOE} sed -i '/\(dhcp-option DNS \)/{n;N;d}' /etc/openvpn/server.conf + else + ${SUDOE} sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${pivpnDNS2}'\"/' /etc/openvpn/server.conf + fi - if [[ ${APPLY_TWO_POINT_FOUR} == true ]]; then - #If they enabled 2.4 use tls-crypt instead of tls-auth to encrypt control channel - $SUDO sed -i "s/tls-auth \/etc\/openvpn\/easy-rsa\/pki\/ta.key 0/tls-crypt \/etc\/openvpn\/easy-rsa\/pki\/ta.key/" /etc/openvpn/server.conf - fi + # Set the user encryption key size + $SUDO sed -i "s/\(dh \/etc\/openvpn\/easy-rsa\/pki\/dh\).*/\1${pivpnENCRYPT}.pem/" /etc/openvpn/server.conf - if [[ ${APPLY_TWO_POINT_FOUR} == true ]]; then - #If they enabled 2.4 disable dh parameters since the key exchange will use the matching curve from the ECDSA certificate - $SUDO sed -i "s/\(dh \/etc\/openvpn\/easy-rsa\/pki\/dh\).*/dh none/" /etc/openvpn/server.conf - else - # Otherwise set the user encryption key size - $SUDO sed -i "s/\(dh \/etc\/openvpn\/easy-rsa\/pki\/dh\).*/\1${ENCRYPT}.pem/" /etc/openvpn/server.conf - fi + # if they modified port put value in server.conf + if [ "$pivpnPORT" != 1194 ]; then + $SUDO sed -i "s/1194/${pivpnPORT}/g" /etc/openvpn/server.conf + fi - # if they modified port put value in server.conf - if [ $PORT != 1194 ]; then - $SUDO sed -i "s/1194/${PORT}/g" /etc/openvpn/server.conf - fi + # if they modified protocol put value in server.conf + if [ "$pivpnPROTO" != "udp" ]; then + $SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf + fi - # if they modified protocol put value in server.conf - if [ "$PROTO" != "udp" ]; then - $SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf - fi - - # write out server certs to conf file - $SUDO sed -i "s/\(key \/etc\/openvpn\/easy-rsa\/pki\/private\/\).*/\1${SERVER_NAME}.key/" /etc/openvpn/server.conf - $SUDO sed -i "s/\(cert \/etc\/openvpn\/easy-rsa\/pki\/issued\/\).*/\1${SERVER_NAME}.crt/" /etc/openvpn/server.conf + # write out server certs to conf file + $SUDO sed -i "s/\(key \/etc\/openvpn\/easy-rsa\/pki\/private\/\).*/\1${SERVER_NAME}.key/" /etc/openvpn/server.conf + $SUDO sed -i "s/\(cert \/etc\/openvpn\/easy-rsa\/pki\/issued\/\).*/\1${SERVER_NAME}.crt/" /etc/openvpn/server.conf } -confUnattendedUpgrades() { - cd /etc/apt/apt.conf.d +confOVPN(){ + $SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt - if [[ $UNATTUPG == "unattended-upgrades" ]]; then - $SUDO $PKG_MANAGER --yes --quiet --no-install-recommends install "$UNATTUPG" > /dev/null & spinner $! - if [[ $PLAT == "Ubuntu" ]]; then - # Ubuntu 50unattended-upgrades should already just have security enabled - # so we just need to configure the 10periodic file - cat << EOT | $SUDO tee 10periodic >/dev/null - APT::Periodic::Update-Package-Lists "1"; - APT::Periodic::Download-Upgradeable-Packages "1"; - APT::Periodic::AutocleanInterval "5"; - APT::Periodic::Unattended-Upgrade "1"; -EOT - else - # Fix Raspbian config - if [[ $PLAT == "Raspbian" ]]; then - wget -q -O - "$UNATTUPG_CONFIG" | $SUDO tar xz - $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades - $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" - fi + $SUDO sed -i 's/IPv4pub/'"$pivpnHOST"'/' /etc/openvpn/easy-rsa/pki/Default.txt - # Add the remaining settings for all other distributions - cat << EOT | $SUDO tee 02periodic >/dev/null - APT::Periodic::Enable "1"; - APT::Periodic::Update-Package-Lists "1"; - APT::Periodic::Download-Upgradeable-Packages "1"; - APT::Periodic::Unattended-Upgrade "1"; - APT::Periodic::AutocleanInterval "7"; - APT::Periodic::Verbose "0"; -EOT - fi - fi + # if they modified port put value in Default.txt for clients to use + if [ "$pivpnPORT" != 1194 ]; then + $SUDO sed -i -e "s/1194/${pivpnPORT}/g" /etc/openvpn/easy-rsa/pki/Default.txt + fi + # if they modified protocol put value in Default.txt for clients to use + if [ "$pivpnPROTO" != "udp" ]; then + $SUDO sed -i -e "s/proto udp/proto tcp/g" /etc/openvpn/easy-rsa/pki/Default.txt + fi + + # verify server name to strengthen security + $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt + + if [ ! -d "$install_home/ovpns" ]; then + $SUDO mkdir "$install_home/ovpns" + fi + $SUDO chmod 0750 "$install_home/ovpns" + $SUDO chown $install_user:$install_user "$install_home/ovpns" } -confNetwork() { - # Enable forwarding of internet traffic - $SUDO sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf - $SUDO sysctl -p +confWireGuard(){ + whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" + $SUDO mkdir /etc/wireguard/configs + $SUDO touch /etc/wireguard/configs/clients.txt + $SUDO mkdir /etc/wireguard/keys - # if ufw enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example) - if $SUDO bash -c 'hash ufw' 2>/dev/null; then - if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive - then - noUFW=1 - else - echo "::: Detected UFW is enabled." - echo "::: Adding UFW rules..." - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules - # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) - $SUDO ufw insert 1 allow "$PORT"/"$PROTO" >/dev/null + # Generate private key and derive public key from it + wg genkey | $SUDO tee /etc/wireguard/keys/server_priv &> /dev/null + wg genpsk | $SUDO tee /etc/wireguard/keys/psk &> /dev/null + $SUDO cat /etc/wireguard/keys/server_priv | wg pubkey | $SUDO tee /etc/wireguard/keys/server_pub &> /dev/null - # https://askubuntu.com/a/712202 - INSTALLED_UFW=$(dpkg-query --showformat='${Version}' --show ufw) - MINIMUM_UFW=0.34 + echo "::: Server Keys and Pre-Shared Key have been generated." - if $SUDO dpkg --compare-versions "$INSTALLED_UFW" ge "$MINIMUM_UFW"; then - # Don't forward everything, just the traffic originated from the VPN subnet - $SUDO ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any >/dev/null - echo 0 > /tmp/OLD_UFW - else - # This ufw version does not support route command, fallback to policy change - $SUDO sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw - echo 1 > /tmp/OLD_UFW - fi - - $SUDO ufw reload >/dev/null - echo "::: UFW configuration completed." - fi - else - noUFW=1 - fi - # else configure iptables - if [[ $noUFW -eq 1 ]]; then - echo 1 > /tmp/noUFW - - # Now some checks to detect which rules we need to add. On a newly installed system all policies - # should be ACCEPT, so the only required rule would be the MASQUERADE one. - - $SUDO iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "$IPv4dev" -j MASQUERADE - - # Count how many rules are in the INPUT and FORWARD chain. When parsing input from - # iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found - # installed but not enabled). - - # Grep returns non 0 exit code where there are no matches, however that would make the script exit, - # for this reasons we use '|| true' to force exit code 0 - INPUT_RULES_COUNT="$($SUDO iptables -S INPUT | grep -vcE '(^-P|ufw-)' || true)" - FORWARD_RULES_COUNT="$($SUDO iptables -S FORWARD | grep -vcE '(^-P|ufw-)' || true)" - - INPUT_POLICY="$($SUDO iptables -S INPUT | grep '^-P' | awk '{print $3}')" - FORWARD_POLICY="$($SUDO iptables -S FORWARD | grep '^-P' | awk '{print $3}')" - - # If rules count is not zero, we assume we need to explicitly allow traffic. Same conclusion if - # there are no rules and the policy is not ACCEPT. Note that rules are being added to the top of the - # chain (using -I). - - if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I INPUT 1 -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT - INPUT_CHAIN_EDITED=1 - else - INPUT_CHAIN_EDITED=0 - fi - - if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - $SUDO iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT - FORWARD_CHAIN_EDITED=1 - else - FORWARD_CHAIN_EDITED=0 - fi - - case ${PLAT} in - Ubuntu|Debian|Devuan) - $SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null - ;; - *) - $SUDO netfilter-persistent save - ;; - esac - else - echo 0 > /tmp/noUFW - fi - - echo "$INPUT_CHAIN_EDITED" > /tmp/INPUT_CHAIN_EDITED - echo "$FORWARD_CHAIN_EDITED" > /tmp/FORWARD_CHAIN_EDITED - - $SUDO cp /tmp/noUFW /etc/pivpn/NO_UFW - $SUDO cp /tmp/OLD_UFW /etc/pivpn/OLD_UFW - $SUDO cp /tmp/INPUT_CHAIN_EDITED /etc/pivpn/INPUT_CHAIN_EDITED - $SUDO cp /tmp/FORWARD_CHAIN_EDITED /etc/pivpn/FORWARD_CHAIN_EDITED + echo "[Interface] +PrivateKey = $($SUDO cat /etc/wireguard/keys/server_priv) +Address = 10.6.0.1/24 +ListenPort = ${pivpnPORT}" | $SUDO tee /etc/wireguard/wg0.conf &> /dev/null + echo "::: Server config generated." } -confOVPN() { - if ! IPv4pub=$(dig +short myip.opendns.com @208.67.222.222) || ! valid_ip "$IPv4pub"; then - echo "dig failed, now trying to curl checkip.amazonaws.com" - if ! IPv4pub=$(curl -s https://checkip.amazonaws.com) || ! valid_ip "$IPv4pub"; then - echo "checkip.amazonaws.com failed, please check your internet connection/DNS" - exit 1 - fi - fi - $SUDO cp /tmp/INSTALL_USER /etc/pivpn/INSTALL_USER - $SUDO cp /tmp/DET_PLATFORM /etc/pivpn/DET_PLATFORM +confNetwork(){ + # Enable forwarding of internet traffic + $SUDO sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf + $SUDO sysctl -p - $SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt + # if ufw enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example) + if $SUDO bash -c 'hash ufw' 2>/dev/null; then + if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive + then + USING_UFW=0 + else + USING_UFW=1 + echo "::: Detected UFW is enabled." + echo "::: Adding UFW rules..." + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $PHYS_INT -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) + $SUDO ufw insert 1 allow "$PORT"/"$PROTO" >/dev/null + $SUDO ufw route insert 1 allow in on "$pivpnINT" from 10.8.0.0/24 out on "$PHYS_INT" to any >/dev/null - if [[ ${APPLY_TWO_POINT_FOUR} == true ]]; then - #If they enabled 2.4 remove key-direction options since it's not required - $SUDO sed -i "/key-direction 1/d" /etc/openvpn/easy-rsa/pki/Default.txt - fi + $SUDO ufw reload >/dev/null + echo "::: UFW configuration completed." + fi + else + USING_UFW=0 + fi + # else configure iptables + if [[ $USING_UFW -eq 0 ]]; then + # Now some checks to detect which rules we need to add. On a newly installed system all policies + # should be ACCEPT, so the only required rule would be the MASQUERADE one. - if [[ ${useUpdateVars} == false ]]; then - METH=$(whiptail --title "Public IP or DNS" --radiolist "Will clients use a Public IP or DNS Name to connect to your server (press space to select)?" ${r} ${c} 2 \ - "$IPv4pub" "Use this public IP" "ON" \ - "DNS Entry" "Use a public DNS" "OFF" 3>&1 1>&2 2>&3) + $SUDO iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "$PHYS_INT" -j MASQUERADE - exitstatus=$? - if [ $exitstatus != 0 ]; then - echo "::: Cancel selected. Exiting..." - exit 1 - fi + # Count how many rules are in the INPUT and FORWARD chain. When parsing input from + # iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found + # installed but not enabled). - if [ "$METH" == "$IPv4pub" ]; then - $SUDO sed -i 's/IPv4pub/'"$IPv4pub"'/' /etc/openvpn/easy-rsa/pki/Default.txt - else - until [[ $publicDNSCorrect = True ]] - do - PUBLICDNS=$(whiptail --title "PiVPN Setup" --inputbox "What is the public DNS name of this Server?" ${r} ${c} 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus != 0 ]; then - echo "::: Cancel selected. Exiting..." - exit 1 - fi - if (whiptail --backtitle "Confirm DNS Name" --title "Confirm DNS Name" --yesno "Is this correct?\n\n Public DNS Name: $PUBLICDNS" ${r} ${c}) then - publicDNSCorrect=True - $SUDO sed -i 's/IPv4pub/'"$PUBLICDNS"'/' /etc/openvpn/easy-rsa/pki/Default.txt - else - publicDNSCorrect=False - fi - done - fi - else - $SUDO sed -i 's/IPv4pub/'"$PUBLICDNS"'/' /etc/openvpn/easy-rsa/pki/Default.txt - fi + # Grep returns non 0 exit code where there are no matches, however that would make the script exit, + # for this reasons we use '|| true' to force exit code 0 + INPUT_RULES_COUNT="$($SUDO iptables -S INPUT | grep -vcE '(^-P|ufw-)')" + FORWARD_RULES_COUNT="$($SUDO iptables -S FORWARD | grep -vcE '(^-P|ufw-)')" - # if they modified port put value in Default.txt for clients to use - if [ $PORT != 1194 ]; then - $SUDO sed -i -e "s/1194/${PORT}/g" /etc/openvpn/easy-rsa/pki/Default.txt - fi + INPUT_POLICY="$($SUDO iptables -S INPUT | grep '^-P' | awk '{print $3}')" + FORWARD_POLICY="$($SUDO iptables -S FORWARD | grep '^-P' | awk '{print $3}')" - # if they modified protocol put value in Default.txt for clients to use - if [ "$PROTO" != "udp" ]; then - $SUDO sed -i -e "s/proto udp/proto tcp/g" /etc/openvpn/easy-rsa/pki/Default.txt - fi + # If rules count is not zero, we assume we need to explicitly allow traffic. Same conclusion if + # there are no rules and the policy is not ACCEPT. Note that rules are being added to the top of the + # chain (using -I). - # verify server name to strengthen security - $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt + if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then + $SUDO iptables -I INPUT 1 -i "$PHYS_INT" -p "$PROTO" --dport "$PORT" -j ACCEPT + INPUT_CHAIN_EDITED=1 + else + INPUT_CHAIN_EDITED=0 + fi - INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6) - INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash - if [ ! -d "$INSTALL_HOME/ovpns" ]; then - $SUDO mkdir "$INSTALL_HOME/ovpns" - fi - $SUDO chmod 0750 "$INSTALL_HOME/ovpns" - $SUDO chown $INSTALL_USER:$INSTALL_USER "$INSTALL_HOME/ovpns" + if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then + $SUDO iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$PHYS_INT" -o "$pivpnINT" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + $SUDO iptables -I FORWARD 2 -s 10.8.0.0/24 -i "$pivpnINT" -o "$PHYS_INT" -j ACCEPT + FORWARD_CHAIN_EDITED=1 + else + FORWARD_CHAIN_EDITED=0 + fi + + case ${PLAT} in + Raspbian) + $SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null + ;; + esac + + echo "INPUT_CHAIN_EDITED=${INPUT_CHAIN_EDITED}" >> /tmp/setupVars.conf + echo "FORWARD_CHAIN_EDITED=${FORWARD_CHAIN_EDITED}" >> /tmp/setupVars.conf + fi + + echo "USING_UFW=${USING_UFW}" >> /tmp/setupVars.conf } confLogging() { @@ -1139,361 +1090,232 @@ if \$programname == 'ovpn-server' then stop" | $SUDO tee /etc/rsyslog.d/30-openv echo "/var/log/openvpn.log { - rotate 4 - weekly - missingok - notifempty - compress - delaycompress - sharedscripts - postrotate - invoke-rc.d rsyslog rotate >/dev/null 2>&1 || true - endscript + rotate 4 + weekly + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + invoke-rc.d rsyslog rotate >/dev/null 2>&1 || true + endscript }" | $SUDO tee /etc/logrotate.d/openvpn > /dev/null # Restart the logging service - case ${PLAT} in - Ubuntu|Debian|*vuan) - $SUDO service rsyslog restart || true - ;; - *) - $SUDO systemctl restart rsyslog.service || true - ;; - esac + case ${PLAT} in + Raspbian) + $SUDO systemctl restart rsyslog.service || true + ;; + esac } -finalExports() { - # Update variables in setupVars.conf file - if [ -e "${setupVars}" ]; then - $SUDO sed -i.update.bak '/INSTALL_USER/d;/UNATTUPG/d;/pivpnInterface/d;/IPv4dns/d;/IPv4addr/d;/IPv4gw/d;/pivpnProto/d;/PORT/d;/ENCRYPT/d;/DOWNLOAD_DH_PARAM/d;/PUBLICDNS/d;/OVPNDNS1/d;/OVPNDNS2/d;' "${setupVars}" - fi - { - echo "INSTALL_USER=${INSTALL_USER}" - echo "UNATTUPG=${UNATTUPG}" - echo "pivpnInterface=${pivpnInterface}" - echo "IPv4dns=${IPv4dns}" - echo "IPv4addr=${IPv4addr}" - echo "IPv4gw=${IPv4gw}" - echo "pivpnProto=${pivpnProto}" - echo "PORT=${PORT}" - echo "ENCRYPT=${ENCRYPT}" - echo "APPLY_TWO_POINT_FOUR=${APPLY_TWO_POINT_FOUR}" - echo "DOWNLOAD_DH_PARAM=${DOWNLOAD_DH_PARAM}" - echo "PUBLICDNS=${PUBLICDNS}" - echo "OVPNDNS1=${OVPNDNS1}" - echo "OVPNDNS2=${OVPNDNS2}" - } | $SUDO tee "${setupVars}" > /dev/null +installPiVPN(){ + $SUDO mkdir -p /etc/pivpn/ + askWhichVPN + + if [ "$VPN" = "OpenVPN" ]; then + installOpenVPN + askCustomProto + askCustomPort + askClientDNS + askCustomDomain + askPublicIPOrDNS + askEncryption + confOpenVPN + confOVPN + confNetwork + confLogging + elif [ "$VPN" = "WireGuard" ]; then + installWireGuard + askCustomPort + askClientDNS + askPublicIPOrDNS + confWireGuard + confNetwork + fi } +askUnattendedUpgrades(){ + whiptail --msgbox --backtitle "Security Updates" --title "Unattended Upgrades" "Since this server will have at least one port open to the internet, it is recommended you enable unattended-upgrades.\nThis feature will check daily for security package updates only and apply them when necessary.\nIt will NOT automatically reboot the server so to fully apply some updates you should periodically reboot." ${r} ${c} -# I suggest replacing some of these names. + if (whiptail --backtitle "Security Updates" --title "Unattended Upgrades" --yesno "Do you want to enable unattended upgrades of security patches to this server?" ${r} ${c}); then + UNATTUPG=1 + PIVPN_DEPS=(unattended-upgrades) + installDependentPackages PIVPN_DEPS[@] + else + UNATTUPG=0 + fi -#accountForRefactor() { -# # At some point in the future this list can be pruned, for now we'll need it to ensure updates don't break. -# -# # Refactoring of install script has changed the name of a couple of variables. Sort them out here. -# sed -i 's/INSTALL_USER/PIVPN_USER/g' ${setupVars} -# #sed -i 's/UNATTUPG/UNATTUPG/g' ${setupVars} -# sed -i 's/pivpnInterface/PIVPN_INTERFACE/g' ${setupVars} -# sed -i 's/IPv4dns/IPV4_DNS/g' ${setupVars} -# sed -i 's/IPv4addr/IPV4_ADDRESS/g' ${setupVars} -# sed -i 's/IPv4gw/IPV4_GATEWAY/g' ${setupVars} -# sed -i 's/pivpnProto/TRANSPORT_LAYER/g' ${setupVars} -# #sed -i 's/PORT/PORT/g' ${setupVars} -# #sed -i 's/ENCRYPT/ENCRYPT/g' ${setupVars} -# #sed -i 's/DOWNLOAD_DH_PARAM/DOWNLOAD_DH_PARAM/g' ${setupVars} -# sed -i 's/PUBLICDNS/PUBLIC_DNS/g' ${setupVars} -# sed -i 's/OVPNDNS1/OVPN_DNS_1/g' ${setupVars} -# sed -i 's/OVPNDNS2/OVPN_DNS_2/g' ${setupVars} -#} - -installPiVPN() { - stopServices - $SUDO mkdir -p /etc/pivpn/ - confUnattendedUpgrades - installScripts - setCustomProto - setCustomPort - confOpenVPN - confNetwork - confOVPN - setClientDNS - setCustomDomain - confLogging - finalExports + echo "UNATTUPG=${UNATTUPG}" >> /tmp/setupVars.conf } -updatePiVPN() { - #accountForRefactor - stopServices - confUnattendedUpgrades - installScripts +confUnattendedUpgrades(){ + cd /etc/apt/apt.conf.d - # setCustomProto - # write out the PROTO - PROTO=$pivpnProto - $SUDO cp /tmp/pivpnPROTO /etc/pivpn/INSTALL_PROTO + wget -q -O- "$UNATTUPG_CONFIG" | $SUDO tar xz + $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades + $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" - #setCustomPort - # write out the port - $SUDO cp /tmp/INSTALL_PORT /etc/pivpn/INSTALL_PORT + if [ "$VPN" = "WireGuard" ] && [ "$(uname -m)" = "armv7l" ]; then + sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades + fi - confOpenVPN - confNetwork - confOVPN - - # ?? Is this always OK? Also if you only select one DNS server ?? - $SUDO sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${OVPNDNS1}'\"/' /etc/openvpn/server.conf - $SUDO sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${OVPNDNS2}'\"/' /etc/openvpn/server.conf - - finalExports #re-export setupVars.conf to account for any new vars added in new versions + # Add the remaining settings for all other distributions + echo "APT::Periodic::Enable \"1\"; + APT::Periodic::Update-Package-Lists \"1\"; + APT::Periodic::Download-Upgradeable-Packages \"1\"; + APT::Periodic::Unattended-Upgrade \"1\"; + APT::Periodic::AutocleanInterval \"7\"; + APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null } +installScripts() { + # Install the scripts from /etc/.pivpn to their various locations + echo ":::" + echo -n "::: Installing scripts to /opt/pivpn..." + if [ ! -d /opt/pivpn ]; then + $SUDO mkdir /opt/pivpn + $SUDO chown root:root /opt/pivpn + $SUDO chmod 0755 /opt/pivpn + fi -displayFinalMessage() { - # Final completion message to user - whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles. + FOLDER=$(tr '[:upper:]' '[:lower:]' <<< "$VPN") + $SUDO cp /etc/.pivpn/scripts/$FOLDER/*.sh /opt/pivpn/ + $SUDO chmod 0755 /opt/pivpn/*.sh + $SUDO cp /etc/.pivpn/$FOLDER/pivpn /usr/local/bin/pivpn + $SUDO chmod 0755 /usr/local/bin/pivpn + $SUDO cp /etc/.pivpn/scripts/$FOLDER/bash-completion /etc/bash_completion.d/pivpn + . /etc/bash_completion.d/pivpn + echo " done." +} + +displayFinalMessage(){ + # Final completion message to user + whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles. Run 'pivpn help' to see what else you can do!\n\nIf you run into any issue, please read all our documentation carefully. All incomplete posts or bug reports will be ignored or deleted.\n\nThank you for using PiVPN." ${r} ${c} - if (whiptail --title "Reboot" --yesno --defaultno "It is strongly recommended you reboot after installation. Would you like to reboot now?" ${r} ${c}); then - whiptail --title "Rebooting" --msgbox "The system will now reboot." ${r} ${c} - jkkprintf "\nRebooting system...\n" - $SUDO sleep 3 - $SUDO shutdown -r now - fi + if (whiptail --title "Reboot" --yesno --defaultno "It is strongly recommended you reboot after installation. Would you like to reboot now?" ${r} ${c}); then + whiptail --title "Rebooting" --msgbox "The system will now reboot." ${r} ${c} + printf "\nRebooting system...\n" + $SUDO sleep 3 + $SUDO shutdown -r now + fi } -update_dialogs() { - # reconfigure - if [ "${reconfigure}" = true ]; then - opt1a="Repair" - opt1b="This will retain existing settings" - strAdd="You will remain on the same version" - else - opt1a="Update" - opt1b="This will retain existing settings." - strAdd="You will be updated to the latest version." - fi - opt2a="Reconfigure" - opt2b="This will allow you to enter new settings" - - UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \ - "${opt1a}" "${opt1b}" \ - "${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) || \ - { echo "::: Cancel selected. Exiting"; exit 1; } - - case ${UpdateCmd} in - ${opt1a}) - echo "::: ${opt1a} option selected." - useUpdateVars=true - ;; - ${opt2a}) - echo "::: ${opt2a} option selected" - useUpdateVars=false - ;; - esac -} - -clone_or_update_repos() { - if [[ "${reconfigure}" == true ]]; then - echo "::: --reconfigure passed to install script. Not downloading/updating local repos" - else - # Get Git files - getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \ - { echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \ - exit 1; \ - } - fi -} - -checkhostname(){ -###Checks for hostnamesize - host_name=$(hostname -s) - if [[ ! ${#host_name} -le 28 ]]; then - until [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; do - host_name=$(whiptail --inputbox "Your hostname is too long.\nEnter new hostname with less then 28 characters\nNo special characters allowed." \ - --title "Hostname too long" ${r} ${c} 3>&1 1>&2 2>&3) - $SUDO hostnamectl set-hostname "${host_name}" - if [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; then - echo "::: Hostname valid and length OK, proceeding..." - fi - - done - else - echo "::: Hostname length OK" - fi - -} - - ######## SCRIPT ############ -main() { +main(){ - ######## FIRST CHECK ######## - # Must be root to install - echo ":::" - if [[ $EUID -eq 0 ]];then - echo "::: You are root." - else - echo "::: sudo will be used for the install." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - export SUDO="sudo" - export SUDOE="sudo -E" - else - echo "::: Please install sudo or run this as root." - exit 1 - fi - fi + ######## FIRST CHECK ######## + # Must be root to install + echo ":::" + if [[ $EUID -eq 0 ]];then + echo "::: You are root." + else + echo "::: sudo will be used for the install." + # Check if it is actually installed + # If it isn't, exit because the install cannot complete + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + export SUDOE="sudo -E" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi + fi + # Check for supported distribution + distroCheck - # Check for supported distribution - distro_check + # Checks for hostname Length + checkHostname - # Checks for hostname Length - checkhostname + # Check arguments for the undocumented flags + for var in "$@"; do + case "$var" in + "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; + "--unattended" ) runUnattended=true;; + esac + done - # Check arguments for the undocumented flags - for var in "$@"; do - case "$var" in - "--reconfigure" ) reconfigure=true;; - "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; - "--unattended" ) runUnattended=true;; - esac - done + if [[ "${runUnattended}" == true ]]; then + echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" + fi - if [[ -f ${setupVars} ]]; then - if [[ "${runUnattended}" == true ]]; then - echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" - useUpdateVars=true - else - update_dialogs - fi - fi + # Start the installer + # Verify there is enough disk space for the install + if [[ "${skipSpaceCheck}" == true ]]; then + echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" + else + verifyFreeDiskSpace + fi - # Start the installer - # Verify there is enough disk space for the install - if [[ "${skipSpaceCheck}" == true ]]; then - echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" - else - verifyFreeDiskSpace - fi + updatePackageCache - # Install the packages (we do this first because we need whiptail) - addSoftwareRepo + # Notify user of package availability + notifyPackageUpdatesAvailable - update_package_cache + # Install packages used by this installation script + preconfigurePackages + installDependentPackages BASE_DEPS[@] - # Notify user of package availability - notify_package_updates_available + # Display welcome dialogs + welcomeDialogs + # Find interfaces and let the user choose one + chooseInterface - # Install packages used by this installation script - install_dependent_packages PIVPN_DEPS[@] + getStaticIPv4Settings + setStaticIPv4 - if [[ ${useUpdateVars} == false ]]; then - # Display welcome dialogs - welcomeDialogs + # Choose the user for the ovpns + chooseUser - # Find interfaces and let the user choose one - chooseInterface + # Clone/Update the repos + cloneOrUpdateRepos - # Only try to set static on Raspbian, otherwise let user do it - if [[ $PLAT != "Raspbian" ]]; then - avoidStaticIPv4Ubuntu - else - getStaticIPv4Settings - setStaticIPv4 - fi + # Install + if installPiVPN; then + echo "::: Install Complete..." + else + exit 1 + fi - # Choose the user for the ovpns - chooseUser + echo "::: Restarting services..." + # Start services + case ${PLAT} in + Raspbian) + if [ "$VPN" = "OpenVPN" ]; then + $SUDO systemctl enable openvpn.service + $SUDO systemctl start openvpn.service + elif [ "$VPN" = "WireGuard" ]; then + $SUDO systemctl enable wg-quick@wg0.service + $SUDO systemctl start wg-quick@wg0.service + fi + ;; + esac - # Ask if unattended-upgrades will be enabled - unattendedUpgrades + # Ask if unattended-upgrades will be enabled + askUnattendedUpgrades + confUnattendedUpgrades - # Clone/Update the repos - clone_or_update_repos + $SUDO cp /tmp/setupVars.conf /etc/pivpn/setupVars.conf + installScripts - # Install - if installPiVPN; then - echo "::: Install Complete..." - else - exit 1 - fi - else - # Source ${setupVars} for use in the rest of the functions. - source ${setupVars} + # Ensure that cached writes reach persistent storage + echo "::: Flushing writes to disk..." + sync + echo "::: done." - echo "::: Using IP address: $IPv4addr" - echo "${IPv4addr%/*}" > /tmp/pivpnIP - echo "::: Using interface: $pivpnInterface" - echo "${pivpnInterface}" > /tmp/pivpnINT - echo "::: Using User: $INSTALL_USER" - echo "${INSTALL_USER}" > /tmp/INSTALL_USER - echo "::: Using protocol: $pivpnProto" - echo "${pivpnProto}" > /tmp/pivpnPROTO - echo "::: Using port: $PORT" - echo ${PORT} > /tmp/INSTALL_PORT - echo ":::" + displayFinalMessage - # Only try to set static on Raspbian - case ${PLAT} in - Rasp*) - setStaticIPv4 # This might be a problem if a user tries to modify the ip in the config file and then runs an update because of the way we check for previous configuration in /etc/dhcpcd.conf - ;; - *) - echo "::: IP Information" - echo "::: Since we think you are not using Raspbian, we will not configure a static IP for you." - echo "::: If you are in Amazon then you can not configure a static IP anyway." - echo "::: Just ensure before this installer started you had set an elastic IP on your instance." - ;; - esac - - # Clone/Update the repos - clone_or_update_repos - - - updatePiVPN - fi - - echo "::: Restarting services..." - # Start services - case ${PLAT} in - Ubuntu|Debian|*vuan) - $SUDO service openvpn start - ;; - *) - $SUDO systemctl enable openvpn.service - $SUDO systemctl start openvpn.service - ;; - esac - - # Ensure that cached writes reach persistent storage - echo "::: Flushing writes to disk..." - sync - - echo "::: done." - - if [[ "${useUpdateVars}" == false ]]; then - displayFinalMessage - fi - - echo ":::" - if [[ "${useUpdateVars}" == false ]]; then - echo "::: Installation Complete!" - echo "::: Now run 'pivpn add' to create an ovpn profile for each of your devices." - echo "::: Run 'pivpn help' to see what else you can do!" - echo "::: It is strongly recommended you reboot after installation." - else - echo "::: Update complete!" - fi - - echo ":::" + echo ":::" + echo "::: Installation Complete!" + echo "::: Now run 'pivpn add' to create an ovpn profile for each of your devices." + echo "::: Run 'pivpn help' to see what else you can do!" + echo "::: It is strongly recommended you reboot after installation." + echo ":::" } -if [[ "${PIVPN_TEST}" != true ]] ; then - main "$@" -fi +main "$@" diff --git a/pivpn b/pivpn deleted file mode 100644 index de55586..0000000 --- a/pivpn +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -# Must be root to use this tool -if [[ ! $EUID -eq 0 ]];then - if [[ $(dpkg-query -s sudo) ]];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 0 - fi -fi - -function makeOVPNFunc { - shift - $SUDO /opt/pivpn/makeOVPN.sh "$@" - exit 0 -} - -function listClientsFunc { - $SUDO /opt/pivpn/clientStat.sh - exit 0 -} - -function listOVPNFunc { - $SUDO /opt/pivpn/listOVPN.sh - exit 0 -} - -function debugFunc { - echo "::: Generating Debug Output" - $SUDO /opt/pivpn/pivpnDebug.sh | tee /tmp/debug.txt - echo "::: " - echo "::: Debug output completed above." - echo "::: Copy saved to /tmp/debug.txt" - echo "::: " - exit 0 -} - -function removeOVPNFunc { - shift - $SUDO /opt/pivpn/removeOVPN.sh "$@" - exit 0 -} - -function uninstallFunc { - $SUDO /opt/pivpn/uninstall.sh - exit 0 -} - -function versionFunc { - printf "\e[1mVersion 1.9\e[0m\n" -} - -function update { - - shift - $SUDO /opt/pivpn/update.sh "$@" - exit 0 - - -} - -function backup { - - $SUDO /opt/pivpn/backup.sh - exit 0 - -} - - -function helpFunc { - echo "::: Control all PiVPN specific functions!" - echo ":::" - echo "::: Usage: pivpn [option]" - echo ":::" - echo "::: Commands:" - echo "::: -a, add [nopass] Create a client ovpn profile, optional nopass" - echo "::: -c, clients List any connected clients to the server" - echo "::: -d, debug Start a debugging session if having trouble" - echo "::: -l, list List all valid and revoked certificates" - echo "::: -r, revoke Revoke a client ovpn profile" - echo "::: -h, help Show this help dialog" - echo "::: -u, uninstall Uninstall PiVPN from your system!" - echo "::: -up, update Updates PiVPN Scripts" - echo "::: -bk, backup Backup Openvpn and ovpns dir" - exit 0 -} - -if [[ $# = 0 ]]; then - helpFunc -fi - -# Handle redirecting to specific functions based on arguments -case "$1" in -"-a" | "add" ) makeOVPNFunc "$@";; -"-c" | "clients" ) listClientsFunc;; -"-d" | "debug" ) debugFunc;; -"-l" | "list" ) listOVPNFunc;; -"-r" | "revoke" ) removeOVPNFunc "$@";; -"-h" | "help" ) helpFunc;; -"-u" | "uninstall" ) uninstallFunc;; -"-v" ) versionFunc;; -"-up"| "update" ) update "$@" ;; -"-bk"| "backup" ) backup;; -* ) helpFunc;; -esac diff --git a/scripts/backup.sh b/scripts/backup.sh deleted file mode 100755 index 61cc6cf..0000000 --- a/scripts/backup.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -install_user=$(1 - backupzip=$date-pivpnbackup.tgz - tar -czf $backupzip -C ${install_home} $backupdir 2&>1 - echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" -} - - -if [[ ! $EUID -eq 0 ]];then - if [[ $(dpkg-query -s sudo) ]];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 0 - fi -fi - -backup_openvpn - diff --git a/scripts/bash-completion b/scripts/bash-completion deleted file mode 100644 index f317bc4..0000000 --- a/scripts/bash-completion +++ /dev/null @@ -1,22 +0,0 @@ -_pivpn() -{ - local cur prev opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -r -h -u -up" - opts="debug add clients list revoke uninstall help update" - if [ "${#COMP_WORDS[@]}" -eq 2 ] - then - if [[ ${cur} == -* ]] ; then - COMPREPLY=( $(compgen -W "${dashopts}" -- "${cur}") ) - else - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - fi - elif [[ ( "$prev" == "add" || "$prev" == "-a" ) && "${#COMP_WORDS[@]}" -eq 3 ]] - then - COMPREPLY=( $(compgen -W "nopass" -- "${cur}") ) - fi - return 0 -} -complete -F _pivpn pivpn diff --git a/scripts/clientStat.sh b/scripts/clientStat.sh deleted file mode 100755 index 2af420f..0000000 --- a/scripts/clientStat.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# PiVPN: client status script - -STATUS_LOG="/var/log/openvpn-status.log" - -function hr() { - numfmt --to=iec-i --suffix=B "$1" -} - -printf "\n" -if [ ! -f "${STATUS_LOG}" ]; then - echo "The file: $STATUS_LOG was not found!" - exit 1 -fi - -printf ": NOTE : The output below is NOT real-time!\n" -printf ": : It may be off by a few minutes.\n" -printf "\n" -printf "\e[1m::: Client Status List :::\e[0m\n" -printf "\t\t\t\t\t\t\t\tBytes\t\tBytes\t\n" -printf "\e[4mName\e[0m\t\t\t\e[4mRemote IP\e[0m\t\t\e[4mVirtual IP\e[0m\t\e[4mReceived\e[0m\t\e[4mSent\e[0m\t\t\e[4mConnected Since\e[0m \n" -if grep -q "^CLIENT_LIST" "${STATUS_LOG}"; then - if [ -n "$(type -t numfmt)" ]; then - while read -r line; do - read -r -a array <<< $line - [[ ${array[0]} = CLIENT_LIST ]] || continue - printf "%s\t\t%s\t%s\t%s\t\t%s\t\t%s %s %s - %s\n" ${array[1]} ${array[2]} ${array[3]} $(hr ${array[4]}) $(hr ${array[5]}) ${array[7]} ${array[8]} ${array[10]} ${array[9]} - done <$STATUS_LOG - else - awk -F' ' -v s='CLIENT_LIST' '$1 == s {print $2"\t\t"$3"\t"$4"\t"$5"\t\t"$6"\t\t"$8" "$9" "$11" - "$10"\n"}' ${STATUS_LOG} - fi -else - printf "\nNo Clients Connected!\n" -fi -printf "\n" diff --git a/scripts/listOVPN.sh b/scripts/listOVPN.sh deleted file mode 100755 index ec0ffd7..0000000 --- a/scripts/listOVPN.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# PiVPN: list clients script - -INDEX="/etc/openvpn/easy-rsa/pki/index.txt" -printf "\n" -if [ ! -f "${INDEX}" ]; then - echo "The file: $INDEX was not found!" - exit 1 -fi - -printf ": NOTE : The first entry should always be your valid server!\n" -printf "\n" -printf "\e[1m::: Certificate Status List :::\e[0m\n" -printf " ::\e[4m Status \e[0m||\e[4m Name \e[0m:: \n" - -while read -r line || [ -n "$line" ]; do - STATUS=$(echo "$line" | awk '{print $1}') - NAME=$(echo "$line" | sed -e 's:.*/CN=::') - if [ "${STATUS}" == "V" ]; then - printf " Valid :: %s\n" "$NAME" - elif [ "${STATUS}" == "R" ]; then - printf " Revoked :: %s\n" "$NAME" - else - printf " Unknown :: %s\n" "$NAME" - fi -done <${INDEX} -printf "\n" diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh deleted file mode 100755 index 406aff0..0000000 --- a/scripts/makeOVPN.sh +++ /dev/null @@ -1,415 +0,0 @@ -#!/bin/bash -# Create OVPN Client -# Default Variable Declarations -DEFAULT="Default.txt" -FILEEXT=".ovpn" -CRT=".crt" -KEY=".key" -CA="ca.crt" -TA="ta.key" -INDEX="/etc/openvpn/easy-rsa/pki/index.txt" -INSTALL_USER=$( [-n|--name ] [-p|--password ]|[nopass] [-d|--days ] [-b|--bitwarden] [-i|--iOS] [-h|--help]" - echo ":::" - echo "::: Commands:" - echo "::: [none] Interactive mode" - echo "::: nopass Create a client without a password" - echo "::: -n,--name Name for the Client (default: '"$(hostname)"')" - echo "::: -p,--password Password for the Client (no default)" - echo "::: -d,--days Expire the certificate after specified number of days (default: 1080)" - echo "::: -b,--bitwarden Create and save a client through Bitwarden" - echo "::: -i,--iOS Generate a certificate that leverages iOS keychain" - echo "::: -h,--help Show this help dialog" -} - -if [ ! -f /etc/pivpn/HELP_SHOWN ]; then - helpFunc - echo - touch /etc/pivpn/HELP_SHOWN -fi - -# Parse input arguments -while test $# -gt 0 -do - _key="$1" - case "$_key" in - -n|--name|--name=*) - _val="${_key##--name=}" - if test "$_val" = "$_key" - then - test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1 - _val="$2" - shift - fi - NAME="$_val" - ;; - -p|--password|--password=*) - _val="${_key##--password=}" - if test "$_val" = "$_key" - then - test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1 - _val="$2" - shift - fi - PASSWD="$_val" - ;; - -d|--days|--days=*) - _val="${_key##--days=}" - if test "$_val" = "$_key" - then - test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1 - _val="$2" - shift - fi - DAYS="$_val" - ;; - -i|--iOS) - iOS=1 - ;; - -h|--help) - helpFunc - exit 0 - ;; - nopass) - NO_PASS="1" - ;; - -b|--bitwarden) - if which bw; then - BITWARDEN="2" - else - echo "Bitwarden not found, please install bitwarden" - exit 1 - fi - - ;; - *) - echo "Error: Got an unexpected argument '$1'" - helpFunc - exit 1 - ;; - esac - shift -done - -# Functions def - -function keynoPASS() { - - #Build the client key - expect << EOF - set timeout -1 - set env(EASYRSA_CERT_EXPIRE) "${DAYS}" - spawn ./easyrsa build-client-full "${NAME}" nopass - expect eof -EOF - - cd pki || exit - -} - -function useBitwarden() { - - # login and unlock vault - printf "****Bitwarden Login****" - printf "\n" - SESSION_KEY=`bw login --raw` - export BW_SESSION=$SESSION_KEY - printf "Successfully Logged in!" - printf "\n" - - # ask user for username - printf "Enter the username: " - read -r NAME - - # check name - until [[ "$NAME" =~ ^[a-zA-Z0-9.@_-]+$ && ${NAME::1} != "." && ${NAME::1} != "-" ]] - do - echo "Name can only contain alphanumeric characters and these characters (.-@_). The name also cannot start with a dot (.) or a dash (-). Please try again." - # ask user for username again - printf "Enter the username: " - read -r NAME - done - - - # ask user for length of password - printf "Please enter the length of characters you want your password to be (minimum 12): " - read -r LENGTH - - # check length - until [[ "$LENGTH" -gt 11 && "$LENGTH" -lt 129 ]] - do - echo "Password must be between from 12 to 128 characters, please try again." - # ask user for length of password - printf "Enter the length of characters you want your password to be (minimum 12): " - read -r LENGTH - done - - printf "Creating a PiVPN item for your vault..." - printf "\n" - # create a new item for your PiVPN Password - PASSWD=`bw generate -usln --length $LENGTH` - bw get template item | jq '.login.type = "1"'| jq '.name = "PiVPN"' | jq -r --arg NAME "$NAME" '.login.username = $NAME' | jq -r --arg PASSWD "$PASSWD" '.login.password = $PASSWD' | bw encode | bw create item - bw logout - -} - -function keyPASS() { - - if [[ -z "${PASSWD}" ]]; then - stty -echo - while true - do - printf "Enter the password for the client: " - read -r PASSWD - printf "\n" - printf "Enter the password again to verify: " - read -r PASSWD2 - printf "\n" - [ "${PASSWD}" = "${PASSWD2}" ] && break - printf "Passwords do not match! Please try again.\n" - done - stty echo - if [[ -z "${PASSWD}" ]]; then - echo "You left the password blank" - echo "If you don't want a password, please run:" - echo "pivpn add nopass" - exit 1 - fi - fi - if [ ${#PASSWD} -lt 4 ] || [ ${#PASSWD} -gt 1024 ] - then - echo "Password must be between from 4 to 1024 characters" - exit 1 - fi - - #Escape chars in PASSWD - PASSWD=$(echo -n ${PASSWD} | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/\$/\\\$/g' -e 's/!/\\!/g' -e 's/\./\\\./g' -e "s/'/\\\'/g" -e 's/"/\\"/g' -e 's/\*/\\\*/g' -e 's/\@/\\\@/g' -e 's/\#/\\\#/g' -e 's/£/\\£/g' -e 's/%/\\%/g' -e 's/\^/\\\^/g' -e 's/\&/\\\&/g' -e 's/(/\\(/g' -e 's/)/\\)/g' -e 's/-/\\-/g' -e 's/_/\\_/g' -e 's/\+/\\\+/g' -e 's/=/\\=/g' -e 's/\[/\\\[/g' -e 's/\]/\\\]/g' -e 's/;/\\;/g' -e 's/:/\\:/g' -e 's/|/\\|/g' -e 's//\\>/g' -e 's/,/\\,/g' -e 's/?/\\?/g' -e 's/~/\\~/g' -e 's/{/\\{/g' -e 's/}/\\}/g') - - #Build the client key and then encrypt the key - - expect << EOF - set timeout -1 - set env(EASYRSA_CERT_EXPIRE) "${DAYS}" - spawn ./easyrsa build-client-full "${NAME}" - expect "Enter PEM pass phrase" { send -- "${PASSWD}\r" } - expect "Verifying - Enter PEM pass phrase" { send -- "${PASSWD}\r" } - expect eof -EOF - cd pki || exit - -} - -#make sure ovpns dir exists -if [ ! -d "$INSTALL_HOME/ovpns" ]; then - mkdir "$INSTALL_HOME/ovpns" - chmod 0750 "$INSTALL_HOME/ovpns" -fi - -#bitWarden -if [[ "${BITWARDEN}" =~ "2" ]]; then - useBitwarden -fi - -if [ -z "${NAME}" ]; then - printf "Enter a Name for the Client: " - read -r NAME -fi - -if [[ ${NAME::1} == "." ]] || [[ ${NAME::1} == "-" ]]; then - echo "Names cannot start with a dot (.) or a dash (-)." - exit 1 -fi - -if [[ "${NAME}" =~ [^a-zA-Z0-9.@_-] ]]; then - echo "Name can only contain alphanumeric characters and these characters (.-@_)." - exit 1 -fi - -if [[ -z "${NAME}" ]]; then - echo "You cannot leave the name blank." - exit 1 -fi - -# Check if name is already in use -while read -r line || [ -n "${line}" ]; do - STATUS=$(echo "$line" | awk '{print $1}') - - if [ "${STATUS}" == "V" ]; then - CERT=$(echo "$line" | sed -e 's:.*/CN=::') - if [ "${CERT}" == "${NAME}" ]; then - INUSE="1" - break - fi - fi -done <${INDEX} - -if [ "${INUSE}" == "1" ]; then - printf "\n!! This name is already in use by a Valid Certificate." - printf "\nPlease choose another name or revoke this certificate first.\n" - exit 1 -fi - -# Check if name is reserved -if [ "${NAME}" == "ta" ] || [ "${NAME}" == "server" ] || [ "${NAME}" == "ca" ]; then - echo "Sorry, this is in use by the server and cannot be used by clients." - exit 1 -fi - -#As of EasyRSA 3.0.6, by default certificates last 1080 days, see https://github.com/OpenVPN/easy-rsa/blob/6b7b6bf1f0d3c9362b5618ad18c66677351cacd1/easyrsa3/vars.example -if [ -z "${DAYS}" ]; then - read -r -e -p "How many days should the certificate last? " -i 1080 DAYS -fi - -if [[ ! "$DAYS" =~ ^[0-9]+$ ]] || [ "$DAYS" -lt 1 ] || [ "$DAYS" -gt 3650 ]; then - #The CRL lasts 3650 days so it doesn't make much sense that certificates would last longer - echo "Please input a valid number of days, between 1 and 3650 inclusive." - exit 1 - -fi - -cd /etc/openvpn/easy-rsa || exit - -if [[ "${NO_PASS}" =~ "1" ]]; then - if [[ -n "${PASSWD}" ]]; then - echo "Both nopass and password arguments passed to the script. Please use either one." - exit 1 - else - keynoPASS - fi -else - keyPASS -fi - -#1st Verify that clients Public Key Exists -if [ ! -f "issued/${NAME}${CRT}" ]; then - echo "[ERROR]: Client Public Key Certificate not found: $NAME$CRT" - exit -fi -echo "Client's cert found: $NAME$CRT" - -#Then, verify that there is a private key for that client -if [ ! -f "private/${NAME}${KEY}" ]; then - echo "[ERROR]: Client Private Key not found: $NAME$KEY" - exit -fi -echo "Client's Private Key found: $NAME$KEY" - -#Confirm the CA public key exists -if [ ! -f "${CA}" ]; then - echo "[ERROR]: CA Public Key not found: $CA" - exit -fi -echo "CA public Key found: $CA" - -#Confirm the tls key file exists -if [ ! -f "${TA}" ]; then - echo "[ERROR]: tls Private Key not found: $TA" - exit -fi -echo "tls Private Key found: $TA" - - -## Added new step to create an .ovpn12 file that can be stored on iOS keychain -## This step is more secure method and does not require the end-user to keep entering passwords, or storing the client private cert where it can be easily tampered -## https://openvpn.net/faq/how-do-i-use-a-client-certificate-and-private-key-from-the-ios-keychain/ -if [ "$iOS" = "1" ]; then - #Generates the .ovpn file WITHOUT the client private key - { - # Start by populating with the default file - cat "${DEFAULT}" - - #Now, append the CA Public Cert - echo "" - cat "${CA}" - echo "" - - #Next append the client Public Cert - echo "" - sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' < "issued/${NAME}${CRT}" - echo "" - - #Finally, append the TA Private Key - if [ -f /etc/pivpn/TWO_POINT_FOUR ]; then - echo "" - cat "${TA}" - echo "" - else - echo "" - cat "${TA}" - echo "" - fi - - } > "${NAME}${FILEEXT}" - - # Copy the .ovpn profile to the home directory for convenient remote access - - printf "========================================================\n" - printf "Generating an .ovpn12 file for use with iOS devices\n" - printf "Please remember the export password\n" - printf "as you will need this import the certificate on your iOS device\n" - printf "========================================================\n" - openssl pkcs12 -passin pass:"$PASSWD" -export -in "issued/${NAME}${CRT}" -inkey "private/${NAME}${KEY}" -certfile ${CA} -name "${NAME}" -out "/home/$INSTALL_USER/ovpns/$NAME.ovpn12" - chown "$INSTALL_USER" "/home/$INSTALL_USER/ovpns/$NAME.ovpn12" - chmod 600 "/home/$INSTALL_USER/ovpns/$NAME.ovpn12" - printf "========================================================\n" - printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME.ovpn12" - printf "You will need to transfer both the .ovpn and .ovpn12 files\n" - printf "to your iOS device.\n" - printf "========================================================\n\n" -else - #This is the standard non-iOS configuration -#Ready to make a new .ovpn file - { - # Start by populating with the default file - cat "${DEFAULT}" - - #Now, append the CA Public Cert - echo "" - cat "${CA}" - echo "" - - #Next append the client Public Cert - echo "" - sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' < "issued/${NAME}${CRT}" - echo "" - - #Then, append the client Private Key - echo "" - cat "private/${NAME}${KEY}" - echo "" - - #Finally, append the tls Private Key - if [ -f /etc/pivpn/TWO_POINT_FOUR ]; then - echo "" - cat "${TA}" - echo "" - else - echo "" - cat "${TA}" - echo "" - fi - - } > "${NAME}${FILEEXT}" - -fi - - -# Copy the .ovpn profile to the home directory for convenient remote access -cp "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" "$INSTALL_HOME/ovpns/$NAME$FILEEXT" -chown "$INSTALL_USER" "$INSTALL_HOME/ovpns/$NAME$FILEEXT" -chmod 640 "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" -chmod 640 "$INSTALL_HOME/ovpns/$NAME$FILEEXT" -printf "\n\n" -printf "========================================================\n" -printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME$FILEEXT" -printf "%s was copied to:\n" "$NAME$FILEEXT" -printf " %s/ovpns\n" "$INSTALL_HOME" -printf "for easy transfer. Please use this profile only on one\n" -printf "device and create additional profiles for other devices.\n" -printf "========================================================\n\n" diff --git a/scripts/pivpnDebug.sh b/scripts/pivpnDebug.sh deleted file mode 100755 index 25a4bf1..0000000 --- a/scripts/pivpnDebug.sh +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/env bash -# This scripts runs as root - -PORT=$(cat /etc/pivpn/INSTALL_PORT) -PROTO=$(cat /etc/pivpn/INSTALL_PROTO) -IPv4dev="$(cat /etc/pivpn/pivpnINTERFACE)" -REMOTE="$(grep 'remote ' /etc/openvpn/easy-rsa/pki/Default.txt | awk '{print $2}')" -NO_UFW=$(cat /etc/pivpn/NO_UFW) -OLD_UFW=$(cat /etc/pivpn/NO_UFW) -INPUT_CHAIN_EDITED="$(cat /etc/pivpn/INPUT_CHAIN_EDITED)" -FORWARD_CHAIN_EDITED="$(cat /etc/pivpn/FORWARD_CHAIN_EDITED)" -ERR=0 - -echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::" -printf "=============================================\n" -echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::" -git --git-dir /etc/.pivpn/.git log -n 1 -printf "=============================================\n" -echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::" -# Use the wildcard so setupVars.conf.update.bak from the previous install is not shown -for filename in /etc/pivpn/*; do - if [[ "$filename" != "/etc/pivpn/setupVars.conf"* ]]; then - echo "$filename -> $(cat "$filename")" - fi -done -printf "=============================================\n" -echo -e "::::\t\e[4msetupVars file shown below\e[0m\t ::::" -sed "s/$REMOTE/REMOTE/" < /etc/pivpn/setupVars.conf -printf "=============================================\n" -echo -e ":::: \e[4mServer configuration shown below\e[0m ::::" -cat /etc/openvpn/server.conf -printf "=============================================\n" -echo -e ":::: \e[4mClient template file shown below\e[0m ::::" -sed "s/$REMOTE/REMOTE/" < /etc/openvpn/easy-rsa/pki/Default.txt -printf "=============================================\n" -echo -e ":::: \t\e[4mRecursive list of files in\e[0m\t ::::\n::: \e[4m/etc/openvpn/easy-rsa/pki shows below\e[0m :::" -ls -LR /etc/openvpn/easy-rsa/pki/ -Ireqs -Icerts_by_serial -printf "=============================================\n" -echo -e "::::\t\t\e[4mSelf check\e[0m\t\t ::::" - -if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then - echo ":: [OK] IP forwarding is enabled" -else - ERR=1 - read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf - sysctl -p - echo "Done" - fi -fi - -if [ "$NO_UFW" -eq 1 ]; then - - if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then - echo ":: [OK] Iptables MASQUERADE rule set" - else - ERR=1 - read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - iptables -t nat -F - iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE - iptables-save > /etc/iptables/rules.v4 - echo "Done" - fi - fi - - - if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then - - if iptables -C INPUT -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT &> /dev/null; then - echo ":: [OK] Iptables INPUT rule set" - else - ERR=1 - read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - iptables -I INPUT 1 -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT - iptables-save > /etc/iptables/rules.v4 - echo "Done" - fi - fi - fi - - if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - - if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT &> /dev/null; then - echo ":: [OK] Iptables FORWARD rule set" - else - ERR=1 - read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT - iptables-save > /etc/iptables/rules.v4 - echo "Done" - fi - fi - fi - -else - - if LANG="en_US.UTF-8" ufw status | grep -qw 'active'; then - echo ":: [OK] Ufw is enabled" - else - ERR=1 - read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - ufw enable - fi - fi - - if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then - echo ":: [OK] Iptables MASQUERADE rule set" - else - ERR=1 - read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules - ufw reload - echo "Done" - fi - fi - - if iptables -C ufw-user-input -p "${PROTO}" --dport "${PORT}" -j ACCEPT &> /dev/null; then - echo ":: [OK] Ufw input rule set" - else - ERR=1 - read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - ufw insert 1 allow "$PORT"/"$PROTO" - ufw reload - echo "Done" - fi - fi - - if [ "$OLD_UFW" -eq 1 ]; then - FORWARD_POLICY="$(iptables -S FORWARD | grep '^-P' | awk '{print $3}')" - if [ "$FORWARD_POLICY" = "ACCEPT" ]; then - echo ":: [OK] Ufw forwarding policy is accept" - else - ERR=1 - read -r -p ":: [ERR] Ufw forwarding policy is not 'ACCEPT', attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw - ufw reload > /dev/null - echo "Done" - fi - fi - else - if iptables -C ufw-user-forward -i tun0 -o "${IPv4dev}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then - echo ":: [OK] Ufw forwarding rule set" - else - ERR=1 - read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any - ufw reload - echo "Done" - fi - fi - fi - -fi - -if systemctl is-active -q openvpn; then - echo ":: [OK] OpenVPN is running" -else - ERR=1 - read -r -p ":: [ERR] OpenVPN is not running, try to start now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - systemctl start openvpn - echo "Done" - fi -fi - -if systemctl is-enabled -q openvpn; then - echo ":: [OK] OpenVPN is enabled (it will automatically start on reboot)" -else - ERR=1 - read -r -p ":: [ERR] OpenVPN is not enabled, try to enable now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - systemctl enable openvpn - echo "Done" - fi -fi - -# grep -w (whole word) is used so port 111940 with now match when looking for 1194 -if netstat -uanpt | grep openvpn | grep -w "${PORT}" | grep -q "${PROTO}"; then - echo ":: [OK] OpenVPN is listening on port ${PORT}/${PROTO}" -else - ERR=1 - read -r -p ":: [ERR] OpenVPN is not listening, try to restart now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - systemctl restart openvpn - echo "Done" - fi -fi - -if [ "$ERR" -eq 1 ]; then - echo -e "[INFO] Run \e[1mpivpn -d\e[0m again to see if we detect issues" -fi - -printf "=============================================\n" -echo -e ":::: \e[4mSnippet of the server log\e[0m ::::" -tail -20 /var/log/openvpn.log > /tmp/snippet - -# Regular expession taken from https://superuser.com/a/202835, it will match invalid IPs -# like 123.456.789.012 but it's fine because the log only contains valid ones. -declare -a IPS_TO_HIDE=($(grepcidr -v 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 /tmp/snippet | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | uniq)) -for IP in "${IPS_TO_HIDE[@]}"; do - sed -i "s/$IP/REDACTED/g" /tmp/snippet -done - -cat /tmp/snippet -rm /tmp/snippet -printf "=============================================\n" -echo -e "::::\t\t\e[4mDebug complete\e[0m\t\t ::::" - -# Telekom Hybrid Check -wget -O /tmp/hybcheck http://speedport.ip &>/dev/null -if grep -Fq "Speedport Pro" /tmp/hybcheck || grep -Fq "Speedport Hybrid" /tmp/hybcheck -then - printf ":::\t\t\t\t\t:::\n::\tTelekom Hybrid Check\t\t ::\n:::\t\t\t\t\t:::\n" - echo "Are you using Telekom Hybrid (found a hybrid compatible router)?" - echo "If yes and you have problems with the connections you can test the following:" - echo "Add 'tun-mtu 1316' in /etc/openvpn/easy-rsa/pki/Default.txt to set a hybrid compatible MTU size (new .ovpn files)." - echo "For already existing .ovpn files 'tun-mtu 1316' can also be inserted there manually." - echo "With Telekom hybrid connections, you may have to experiment a little with MTU (tun-mtu, link-mtu and mssfix)." -fi -rm /tmp/hybcheck diff --git a/scripts/removeOVPN.sh b/scripts/removeOVPN.sh deleted file mode 100755 index b2d726f..0000000 --- a/scripts/removeOVPN.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env bash -# PiVPN: revoke client script - -INSTALL_USER=$( [-h|--help] [] ... [] ..." - echo ":::" - echo "::: Commands:" - echo "::: [none] Interactive mode" - echo "::: Client(s) to to revoke" - echo "::: -h,--help Show this help dialog" -} - -# Parse input arguments -while test $# -gt 0 -do - _key="$1" - case "$_key" in - -h|--help) - helpFunc - exit 0 - ;; - *) - CERTS_TO_REVOKE+=("$1") - ;; - esac - shift -done - -if [ ! -f "${INDEX}" ]; then - printf "The file: %s was not found\n" "$INDEX" - exit 1 -fi - -if [[ -z "${CERTS_TO_REVOKE}" ]]; then - printf "\n" - printf " ::\e[4m Certificate List \e[0m:: \n" - - i=0 - while read -r line || [ -n "$line" ]; do - STATUS=$(echo "$line" | awk '{print $1}') - if [[ "${STATUS}" = "V" ]]; then - NAME=$(echo "$line" | sed -e 's:.*/CN=::') - CERTS[$i]=${NAME} - if [ "$i" != 0 ]; then - # Prevent printing "server" certificate - printf " %s\n" "$NAME" - fi - let i=i+1 - fi - done <${INDEX} - printf "\n" - - echo "::: Please enter the Name of the client to be revoked from the list above:" - read -r NAME - - if [[ -z "${NAME}" ]]; then - echo "You can not leave this blank!" - exit 1 - fi - - for((x=1;x<=i;++x)); do - if [ "${CERTS[$x]}" = "${NAME}" ]; then - VALID=1 - fi - done - - if [ -z "${VALID}" ]; then - printf "You didn't enter a valid cert name!\n" - exit 1 - fi - - CERTS_TO_REVOKE=( "${NAME}" ) -else - i=0 - while read -r line || [ -n "$line" ]; do - STATUS=$(echo "$line" | awk '{print $1}') - if [[ "${STATUS}" = "V" ]]; then - NAME=$(echo "$line" | sed -e 's:.*/CN=::') - CERTS[$i]=${NAME} - let i=i+1 - fi - done <${INDEX} - - for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do - VALID=0 - for((x=1;x<=i;++x)); do - if [ "${CERTS[$x]}" = "${CERTS_TO_REVOKE[ii]}" ]; then - VALID=1 - fi - done - - if [ "${VALID}" != 1 ]; then - printf "You passed an invalid cert name: '"%s"'!\n" "${CERTS_TO_REVOKE[ii]}" - exit 1 - fi - done -fi - -cd /etc/openvpn/easy-rsa || exit - -INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6) -INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash -for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do - printf "\n::: Revoking certificate '"%s"'.\n" "${CERTS_TO_REVOKE[ii]}" - ./easyrsa --batch revoke "${CERTS_TO_REVOKE[ii]}" - ./easyrsa gen-crl - printf "\n::: Certificate revoked, and CRL file updated.\n" - printf "::: Removing certs and client configuration for this profile.\n" - rm -rf "pki/reqs/${CERTS_TO_REVOKE[ii]}.req" - rm -rf "pki/private/${CERTS_TO_REVOKE[ii]}.key" - rm -rf "pki/issued/${CERTS_TO_REVOKE[ii]}.crt" - - rm -rf "${INSTALL_HOME}/ovpns/${CERTS_TO_REVOKE[ii]}.ovpn" - rm -rf "/etc/openvpn/easy-rsa/pki/${CERTS_TO_REVOKE[ii]}.ovpn" - cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem -done -printf "::: Completed!\n" diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh deleted file mode 100755 index b06aaa4..0000000 --- a/scripts/uninstall.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env bash -# PiVPN: Uninstall Script - -PKG_MANAGER="apt-get" -INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) -INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6) -INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash -PLAT=$(cat /etc/pivpn/DET_PLATFORM) -NO_UFW=$(cat /etc/pivpn/NO_UFW) -OLD_UFW=$(cat /etc/pivpn/NO_UFW) -PORT=$(cat /etc/pivpn/INSTALL_PORT) -PROTO=$(cat /etc/pivpn/INSTALL_PROTO) -IPv4dev="$(cat /etc/pivpn/pivpnINTERFACE)" -INPUT_CHAIN_EDITED="$(cat /etc/pivpn/INPUT_CHAIN_EDITED)" -FORWARD_CHAIN_EDITED="$(cat /etc/pivpn/FORWARD_CHAIN_EDITED)" - -# Find the rows and columns. Will default to 80x24 if it can not be detected. -screen_size=$(stty size 2>/dev/null || echo 24 80) -rows=$(echo $screen_size | awk '{print $1}') -columns=$(echo $screen_size | awk '{print $2}') - -# Divide by two so the dialogs take up half of the screen, which looks nice. -r=$(( rows / 2 )) -c=$(( columns / 2 )) -# Unless the screen is tiny -r=$(( r < 20 ? 20 : r )) -c=$(( c < 70 ? 70 : c )) - -spinner() -{ - local pid=$1 - local delay=0.50 - local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do - local temp=${spinstr#?} - printf " [%c] " "$spinstr" - local spinstr=$temp${spinstr%"$temp"} - sleep $delay - printf "\b\b\b\b\b\b" - done - printf " \b\b\b\b" -} - -function removeAll { - # Purge dependencies -echo ":::" - dependencies=( openvpn easy-rsa git iptables-persistent dnsutils expect unattended-upgrades ) - for i in "${dependencies[@]}"; do - if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then - while true; do - read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn - case $yn in - [Yy]* ) printf ":::\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\n"; - if [ "$i" == "openvpn" ]; then UINST_OVPN=1 ; fi - if [ "$i" == "unattended-upgrades" ]; then UINST_UNATTUPG=1 ; fi - break;; - [Nn]* ) printf ":::\tSkipping %s\n" "$i"; break;; - * ) printf "::: You must answer yes or no!\n";; - esac - done - else - printf ":::\tPackage %s not installed... Not removing.\n" "$i" - fi - done - - # Take care of any additional package cleaning - printf "::: Auto removing remaining dependencies..." - $PKG_MANAGER -y autoremove &> /dev/null & spinner $!; printf "done!\n"; - printf "::: Auto cleaning remaining dependencies..." - $PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\n"; - - echo ":::" - # Removing pivpn files - echo "::: Removing pivpn system files..." - - $SUDO rm -rf /opt/pivpn &> /dev/null - $SUDO rm -rf /etc/.pivpn &> /dev/null - $SUDO rm -rf $INSTALL_HOME/ovpns &> /dev/null - - rm -rf /var/log/*pivpn* &> /dev/null - rm -rf /var/log/*openvpn* &> /dev/null - if [[ $UINST_OVPN = 1 ]]; then - rm -rf /etc/openvpn &> /dev/null - if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - printf "::: Removing openvpn apt source..." - rm -rf /etc/apt/sources.list.d/swupdate.openvpn.net.list &> /dev/null - $PKG_MANAGER -qq update & spinner $!; printf "done!\n"; - fi - fi - if [[ $UINST_UNATTUPG = 1 ]]; then - rm -rf /var/log/unattended-upgrades - rm -rf /etc/apt/apt.conf.d/*periodic - fi - rm -rf /etc/pivpn &> /dev/null - rm /usr/local/bin/pivpn &> /dev/null - rm /etc/bash_completion.d/pivpn - - # Disable IPv4 forwarding - sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf - sysctl -p - - if [[ $NO_UFW -eq 0 ]]; then - - sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s 10.8.0.0\/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules - ufw delete allow "$PORT"/"$PROTO" >/dev/null - if [ "$OLD_UFW" -eq 1 ]; then - sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"DROP\"/" /etc/default/ufw - else - ufw route delete allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any >/dev/null - fi - ufw reload >/dev/null - else - iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE - - if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then - iptables -D INPUT -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT - fi - - if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - iptables -D FORWARD -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -D FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT - fi - - iptables-save > /etc/iptables/rules.v4 - fi - - echo ":::" - printf "::: Finished removing PiVPN from your system.\n" - printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L https://install.pivpn.io | bash\n:::\n::: at any time!\n:::\n" -} - -function askreboot() { - printf "It is \e[1mstrongly\e[0m recommended to reboot after un-installation.\n" - read -p "Would you like to reboot now? [y/n]: " -n 1 -r - echo - if [[ ${REPLY} =~ ^[Yy]$ ]]; then - printf "\nRebooting system...\n" - sleep 3 - shutdown -r now - fi -} - -######### SCRIPT ########### -echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system." -echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" -while true; do - read -rp "::: Do you wish to completely remove PiVPN configuration and installed packages from your system? (You will be prompted for each package) [y/n]: " yn - case $yn in - [Yy]* ) removeAll; askreboot; break;; - - [Nn]* ) printf "::: Not removing anything, exiting...\n"; break;; - esac -done diff --git a/scripts/update.sh b/scripts/update.sh deleted file mode 100755 index fb74450..0000000 --- a/scripts/update.sh +++ /dev/null @@ -1,99 +0,0 @@ -#/bin/bash - -###Updates pivpn scripts (Not PiVPN) -###Main Vars -pivpnrepo="https://github.com/pivpn/pivpn.git" -pivpnlocalpath="/etc/.pivpn" -pivpnscripts="/opt/pivpn/scripts" -bashcompletiondir="/etc/bash_completion.d/pivpn" - - -###Functions -##Updates scripts -updatepivpnscripts(){ - ##We don't know what sort of changes users have made. - ##Lets remove first /etc/.pivpn dir then clone it back again - echo "going do update PiVPN Scripts" - if [[ -d $pivpnlocalpath ]]; then - - sudo rm -rf $pivpnlocalpath - cloneandupdate - - else - cloneandupdate - fi - echo "PiVPN Scripts have been updated" -} - -##Updates scripts using test branch -updatefromtest(){ - ##We don't know what sort of changes users have made. - ##Lets remove first /etc/.pivpn dir then clone it back again - echo "PiVPN Scripts updating from test branch" - if [[ -d /etc/.pivpn ]]; then - - rm -rf /etc/.pivpn - cloneupdttest - - else - - cloneupdttest - - fi - echo "PiVPN Scripts updated have been updated from test branch" - } - -##Clone and copy pivpn scripts to /op/ -cloneandupdate(){ - - sudo git clone $pivpnrepo $pivpnlocalpath - sudo cp -r $pivpnlocalpath/scripts $pivpnscripts - sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir - -} - -##same as cloneandupdate() but from test branch -##and falls back to master branch again after updating -cloneupdttest(){ - - sudo git clone $pivpnrepo $pivpnlocalpath - sudo git -C $pivpnlocalpath checkout test - sudo git -C $pivpnlocalpath pull origin test - sudo cp -r $pivpnlocalpath/scripts $pivpnscripts - sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir - sudo git -C $pivpnlocalpath checkout master - -} - -scriptusage(){ - echo -e "Updates pivpn scripts,\n - Usage: - pivpn update | updates from master branch - pivpn update -t or --test | updates from test branch" - -} - -## SCRIPT - -if [[ $# -eq 0 ]]; then - updatepivpnscripts - -else - while true; do - case "$1" in - -t | --test | test ) - updatefromtest - exit 0 - ;; - -h | --help | help ) - scriptusage - exit 0 - ;; - * ) - updatepivpnscripts - exit 0 - ;; - esac - done -fi - From 5e16322f9edefd49609fee9686a0d33029836bcd Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 14 Oct 2019 12:27:28 +0200 Subject: [PATCH 02/79] Added missing script folder --- scripts/openvpn/backup.sh | 36 +++ scripts/openvpn/bash-completion | 22 ++ scripts/openvpn/clientStat.sh | 35 +++ scripts/openvpn/listOVPN.sh | 27 +++ scripts/openvpn/makeOVPN.sh | 414 ++++++++++++++++++++++++++++++++ scripts/openvpn/pivpn | 106 ++++++++ scripts/openvpn/pivpnDebug.sh | 230 ++++++++++++++++++ scripts/openvpn/removeOVPN.sh | 123 ++++++++++ scripts/openvpn/update.sh | 99 ++++++++ scripts/wireguard/listCONF.sh | 23 ++ scripts/wireguard/makeCONF.sh | 130 ++++++++++ scripts/wireguard/pivpn | 83 +++++++ scripts/wireguard/pivpnDEBUG.sh | 173 +++++++++++++ scripts/wireguard/qrcodeCONF.sh | 63 +++++ scripts/wireguard/removeCONF.sh | 117 +++++++++ 15 files changed, 1681 insertions(+) create mode 100755 scripts/openvpn/backup.sh create mode 100644 scripts/openvpn/bash-completion create mode 100755 scripts/openvpn/clientStat.sh create mode 100755 scripts/openvpn/listOVPN.sh create mode 100755 scripts/openvpn/makeOVPN.sh create mode 100755 scripts/openvpn/pivpn create mode 100755 scripts/openvpn/pivpnDebug.sh create mode 100755 scripts/openvpn/removeOVPN.sh create mode 100755 scripts/openvpn/update.sh create mode 100755 scripts/wireguard/listCONF.sh create mode 100755 scripts/wireguard/makeCONF.sh create mode 100755 scripts/wireguard/pivpn create mode 100755 scripts/wireguard/pivpnDEBUG.sh create mode 100755 scripts/wireguard/qrcodeCONF.sh create mode 100755 scripts/wireguard/removeCONF.sh diff --git a/scripts/openvpn/backup.sh b/scripts/openvpn/backup.sh new file mode 100755 index 0000000..8ef6006 --- /dev/null +++ b/scripts/openvpn/backup.sh @@ -0,0 +1,36 @@ +#!/bin/bash +setupVars="/etc/pivpn/setupVars.conf" +backupdir=pivpnbackup +openvpndir=/etc/openvpn +ovpnsdir=${install_home}/ovpns +date=$(date +%Y-%m-%d-%H%M%S) + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +backup_openvpn(){ + if [[ ! -d $install_home/$backupdir ]]; then + mkdir $install_home/$backupdir + fi + cp -r $openvpndir $ovpnsdir $backupdir 2&>1 + backupzip=$date-pivpnbackup.tgz + tar -czf $backupzip -C ${install_home} $backupdir 2&>1 + echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" +} + + +if [[ ! $EUID -eq 0 ]];then + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 0 + fi +fi + +backup_openvpn + diff --git a/scripts/openvpn/bash-completion b/scripts/openvpn/bash-completion new file mode 100644 index 0000000..f317bc4 --- /dev/null +++ b/scripts/openvpn/bash-completion @@ -0,0 +1,22 @@ +_pivpn() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + dashopts="-a -c -d -l -r -h -u -up" + opts="debug add clients list revoke uninstall help update" + if [ "${#COMP_WORDS[@]}" -eq 2 ] + then + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${dashopts}" -- "${cur}") ) + else + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + fi + elif [[ ( "$prev" == "add" || "$prev" == "-a" ) && "${#COMP_WORDS[@]}" -eq 3 ]] + then + COMPREPLY=( $(compgen -W "nopass" -- "${cur}") ) + fi + return 0 +} +complete -F _pivpn pivpn diff --git a/scripts/openvpn/clientStat.sh b/scripts/openvpn/clientStat.sh new file mode 100755 index 0000000..2af420f --- /dev/null +++ b/scripts/openvpn/clientStat.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# PiVPN: client status script + +STATUS_LOG="/var/log/openvpn-status.log" + +function hr() { + numfmt --to=iec-i --suffix=B "$1" +} + +printf "\n" +if [ ! -f "${STATUS_LOG}" ]; then + echo "The file: $STATUS_LOG was not found!" + exit 1 +fi + +printf ": NOTE : The output below is NOT real-time!\n" +printf ": : It may be off by a few minutes.\n" +printf "\n" +printf "\e[1m::: Client Status List :::\e[0m\n" +printf "\t\t\t\t\t\t\t\tBytes\t\tBytes\t\n" +printf "\e[4mName\e[0m\t\t\t\e[4mRemote IP\e[0m\t\t\e[4mVirtual IP\e[0m\t\e[4mReceived\e[0m\t\e[4mSent\e[0m\t\t\e[4mConnected Since\e[0m \n" +if grep -q "^CLIENT_LIST" "${STATUS_LOG}"; then + if [ -n "$(type -t numfmt)" ]; then + while read -r line; do + read -r -a array <<< $line + [[ ${array[0]} = CLIENT_LIST ]] || continue + printf "%s\t\t%s\t%s\t%s\t\t%s\t\t%s %s %s - %s\n" ${array[1]} ${array[2]} ${array[3]} $(hr ${array[4]}) $(hr ${array[5]}) ${array[7]} ${array[8]} ${array[10]} ${array[9]} + done <$STATUS_LOG + else + awk -F' ' -v s='CLIENT_LIST' '$1 == s {print $2"\t\t"$3"\t"$4"\t"$5"\t\t"$6"\t\t"$8" "$9" "$11" - "$10"\n"}' ${STATUS_LOG} + fi +else + printf "\nNo Clients Connected!\n" +fi +printf "\n" diff --git a/scripts/openvpn/listOVPN.sh b/scripts/openvpn/listOVPN.sh new file mode 100755 index 0000000..ec0ffd7 --- /dev/null +++ b/scripts/openvpn/listOVPN.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# PiVPN: list clients script + +INDEX="/etc/openvpn/easy-rsa/pki/index.txt" +printf "\n" +if [ ! -f "${INDEX}" ]; then + echo "The file: $INDEX was not found!" + exit 1 +fi + +printf ": NOTE : The first entry should always be your valid server!\n" +printf "\n" +printf "\e[1m::: Certificate Status List :::\e[0m\n" +printf " ::\e[4m Status \e[0m||\e[4m Name \e[0m:: \n" + +while read -r line || [ -n "$line" ]; do + STATUS=$(echo "$line" | awk '{print $1}') + NAME=$(echo "$line" | sed -e 's:.*/CN=::') + if [ "${STATUS}" == "V" ]; then + printf " Valid :: %s\n" "$NAME" + elif [ "${STATUS}" == "R" ]; then + printf " Revoked :: %s\n" "$NAME" + else + printf " Unknown :: %s\n" "$NAME" + fi +done <${INDEX} +printf "\n" diff --git a/scripts/openvpn/makeOVPN.sh b/scripts/openvpn/makeOVPN.sh new file mode 100755 index 0000000..e0c8891 --- /dev/null +++ b/scripts/openvpn/makeOVPN.sh @@ -0,0 +1,414 @@ +#!/bin/bash +# Create OVPN Client +# Default Variable Declarations +setupVars="/etc/pivpn/setupVars.conf" +DEFAULT="Default.txt" +FILEEXT=".ovpn" +CRT=".crt" +KEY=".key" +CA="ca.crt" +TA="ta.key" +INDEX="/etc/openvpn/easy-rsa/pki/index.txt" + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +helpFunc() { + echo "::: Create a client ovpn profile, optional nopass" + echo ":::" + echo "::: Usage: pivpn <-a|add> [-n|--name ] [-p|--password ]|[nopass] [-d|--days ] [-b|--bitwarden] [-i|--iOS] [-h|--help]" + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: nopass Create a client without a password" + echo "::: -n,--name Name for the Client (default: '"$(hostname)"')" + echo "::: -p,--password Password for the Client (no default)" + echo "::: -d,--days Expire the certificate after specified number of days (default: 1080)" + echo "::: -b,--bitwarden Create and save a client through Bitwarden" + echo "::: -i,--iOS Generate a certificate that leverages iOS keychain" + echo "::: -h,--help Show this help dialog" +} + +if [ -z "$HELP_SHOWN" ]; then + helpFunc + echo + echo "HELP_SHOWN=1" >> "$setupVars" +fi + +# Parse input arguments +while test $# -gt 0 +do + _key="$1" + case "$_key" in + -n|--name|--name=*) + _val="${_key##--name=}" + if test "$_val" = "$_key" + then + test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1 + _val="$2" + shift + fi + NAME="$_val" + ;; + -p|--password|--password=*) + _val="${_key##--password=}" + if test "$_val" = "$_key" + then + test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1 + _val="$2" + shift + fi + PASSWD="$_val" + ;; + -d|--days|--days=*) + _val="${_key##--days=}" + if test "$_val" = "$_key" + then + test $# -lt 2 && echo "Missing value for the optional argument '$_key'." && exit 1 + _val="$2" + shift + fi + DAYS="$_val" + ;; + -i|--iOS) + iOS=1 + ;; + -h|--help) + helpFunc + exit 0 + ;; + nopass) + NO_PASS="1" + ;; + -b|--bitwarden) + if which bw; then + BITWARDEN="2" + else + echo "Bitwarden not found, please install bitwarden" + exit 1 + fi + + ;; + *) + echo "Error: Got an unexpected argument '$1'" + helpFunc + exit 1 + ;; + esac + shift +done + +# Functions def + +function keynoPASS() { + + #Build the client key + expect << EOF + set timeout -1 + set env(EASYRSA_CERT_EXPIRE) "${DAYS}" + spawn ./easyrsa build-client-full "${NAME}" nopass + expect eof +EOF + + cd pki || exit + +} + +function useBitwarden() { + + # login and unlock vault + printf "****Bitwarden Login****" + printf "\n" + SESSION_KEY=`bw login --raw` + export BW_SESSION=$SESSION_KEY + printf "Successfully Logged in!" + printf "\n" + + # ask user for username + printf "Enter the username: " + read -r NAME + + # check name + until [[ "$NAME" =~ ^[a-zA-Z0-9.@_-]+$ && ${NAME::1} != "." && ${NAME::1} != "-" ]] + do + echo "Name can only contain alphanumeric characters and these characters (.-@_). The name also cannot start with a dot (.) or a dash (-). Please try again." + # ask user for username again + printf "Enter the username: " + read -r NAME + done + + + # ask user for length of password + printf "Please enter the length of characters you want your password to be (minimum 12): " + read -r LENGTH + + # check length + until [[ "$LENGTH" -gt 11 && "$LENGTH" -lt 129 ]] + do + echo "Password must be between from 12 to 128 characters, please try again." + # ask user for length of password + printf "Enter the length of characters you want your password to be (minimum 12): " + read -r LENGTH + done + + printf "Creating a PiVPN item for your vault..." + printf "\n" + # create a new item for your PiVPN Password + PASSWD=`bw generate -usln --length $LENGTH` + bw get template item | jq '.login.type = "1"'| jq '.name = "PiVPN"' | jq -r --arg NAME "$NAME" '.login.username = $NAME' | jq -r --arg PASSWD "$PASSWD" '.login.password = $PASSWD' | bw encode | bw create item + bw logout + +} + +function keyPASS() { + + if [[ -z "${PASSWD}" ]]; then + stty -echo + while true + do + printf "Enter the password for the client: " + read -r PASSWD + printf "\n" + printf "Enter the password again to verify: " + read -r PASSWD2 + printf "\n" + [ "${PASSWD}" = "${PASSWD2}" ] && break + printf "Passwords do not match! Please try again.\n" + done + stty echo + if [[ -z "${PASSWD}" ]]; then + echo "You left the password blank" + echo "If you don't want a password, please run:" + echo "pivpn add nopass" + exit 1 + fi + fi + if [ ${#PASSWD} -lt 4 ] || [ ${#PASSWD} -gt 1024 ] + then + echo "Password must be between from 4 to 1024 characters" + exit 1 + fi + + #Escape chars in PASSWD + PASSWD=$(echo -n ${PASSWD} | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/\$/\\\$/g' -e 's/!/\\!/g' -e 's/\./\\\./g' -e "s/'/\\\'/g" -e 's/"/\\"/g' -e 's/\*/\\\*/g' -e 's/\@/\\\@/g' -e 's/\#/\\\#/g' -e 's/£/\\£/g' -e 's/%/\\%/g' -e 's/\^/\\\^/g' -e 's/\&/\\\&/g' -e 's/(/\\(/g' -e 's/)/\\)/g' -e 's/-/\\-/g' -e 's/_/\\_/g' -e 's/\+/\\\+/g' -e 's/=/\\=/g' -e 's/\[/\\\[/g' -e 's/\]/\\\]/g' -e 's/;/\\;/g' -e 's/:/\\:/g' -e 's/|/\\|/g' -e 's//\\>/g' -e 's/,/\\,/g' -e 's/?/\\?/g' -e 's/~/\\~/g' -e 's/{/\\{/g' -e 's/}/\\}/g') + + #Build the client key and then encrypt the key + + expect << EOF + set timeout -1 + set env(EASYRSA_CERT_EXPIRE) "${DAYS}" + spawn ./easyrsa build-client-full "${NAME}" + expect "Enter PEM pass phrase" { send -- "${PASSWD}\r" } + expect "Verifying - Enter PEM pass phrase" { send -- "${PASSWD}\r" } + expect eof +EOF + cd pki || exit + +} + +#make sure ovpns dir exists +if [ ! -d "$install_home/ovpns" ]; then + mkdir "$install_home/ovpns" + chmod 0750 "$install_home/ovpns" +fi + +#bitWarden +if [[ "${BITWARDEN}" =~ "2" ]]; then + useBitwarden +fi + +if [ -z "${NAME}" ]; then + printf "Enter a Name for the Client: " + read -r NAME +fi + +if [[ ${NAME::1} == "." ]] || [[ ${NAME::1} == "-" ]]; then + echo "Names cannot start with a dot (.) or a dash (-)." + exit 1 +fi + +if [[ "${NAME}" =~ [^a-zA-Z0-9.@_-] ]]; then + echo "Name can only contain alphanumeric characters and these characters (.-@_)." + exit 1 +fi + +if [[ -z "${NAME}" ]]; then + echo "You cannot leave the name blank." + exit 1 +fi + +# Check if name is already in use +while read -r line || [ -n "${line}" ]; do + STATUS=$(echo "$line" | awk '{print $1}') + + if [ "${STATUS}" == "V" ]; then + CERT=$(echo "$line" | sed -e 's:.*/CN=::') + if [ "${CERT}" == "${NAME}" ]; then + INUSE="1" + break + fi + fi +done <${INDEX} + +if [ "${INUSE}" == "1" ]; then + printf "\n!! This name is already in use by a Valid Certificate." + printf "\nPlease choose another name or revoke this certificate first.\n" + exit 1 +fi + +# Check if name is reserved +if [ "${NAME}" == "ta" ] || [ "${NAME}" == "server" ] || [ "${NAME}" == "ca" ]; then + echo "Sorry, this is in use by the server and cannot be used by clients." + exit 1 +fi + +#As of EasyRSA 3.0.6, by default certificates last 1080 days, see https://github.com/OpenVPN/easy-rsa/blob/6b7b6bf1f0d3c9362b5618ad18c66677351cacd1/easyrsa3/vars.example +if [ -z "${DAYS}" ]; then + read -r -e -p "How many days should the certificate last? " -i 1080 DAYS +fi + +if [[ ! "$DAYS" =~ ^[0-9]+$ ]] || [ "$DAYS" -lt 1 ] || [ "$DAYS" -gt 3650 ]; then + #The CRL lasts 3650 days so it doesn't make much sense that certificates would last longer + echo "Please input a valid number of days, between 1 and 3650 inclusive." + exit 1 + +fi + +cd /etc/openvpn/easy-rsa || exit + +if [[ "${NO_PASS}" =~ "1" ]]; then + if [[ -n "${PASSWD}" ]]; then + echo "Both nopass and password arguments passed to the script. Please use either one." + exit 1 + else + keynoPASS + fi +else + keyPASS +fi + +#1st Verify that clients Public Key Exists +if [ ! -f "issued/${NAME}${CRT}" ]; then + echo "[ERROR]: Client Public Key Certificate not found: $NAME$CRT" + exit +fi +echo "Client's cert found: $NAME$CRT" + +#Then, verify that there is a private key for that client +if [ ! -f "private/${NAME}${KEY}" ]; then + echo "[ERROR]: Client Private Key not found: $NAME$KEY" + exit +fi +echo "Client's Private Key found: $NAME$KEY" + +#Confirm the CA public key exists +if [ ! -f "${CA}" ]; then + echo "[ERROR]: CA Public Key not found: $CA" + exit +fi +echo "CA public Key found: $CA" + +#Confirm the tls key file exists +if [ ! -f "${TA}" ]; then + echo "[ERROR]: tls Private Key not found: $TA" + exit +fi +echo "tls Private Key found: $TA" + + +## Added new step to create an .ovpn12 file that can be stored on iOS keychain +## This step is more secure method and does not require the end-user to keep entering passwords, or storing the client private cert where it can be easily tampered +## https://openvpn.net/faq/how-do-i-use-a-client-certificate-and-private-key-from-the-ios-keychain/ +if [ "$iOS" = "1" ]; then + #Generates the .ovpn file WITHOUT the client private key + { + # Start by populating with the default file + cat "${DEFAULT}" + + #Now, append the CA Public Cert + echo "" + cat "${CA}" + echo "" + + #Next append the client Public Cert + echo "" + sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' < "issued/${NAME}${CRT}" + echo "" + + #Finally, append the TA Private Key + if [ -f /etc/pivpn/TWO_POINT_FOUR ]; then + echo "" + cat "${TA}" + echo "" + else + echo "" + cat "${TA}" + echo "" + fi + + } > "${NAME}${FILEEXT}" + + # Copy the .ovpn profile to the home directory for convenient remote access + + printf "========================================================\n" + printf "Generating an .ovpn12 file for use with iOS devices\n" + printf "Please remember the export password\n" + printf "as you will need this import the certificate on your iOS device\n" + printf "========================================================\n" + openssl pkcs12 -passin pass:"$PASSWD" -export -in "issued/${NAME}${CRT}" -inkey "private/${NAME}${KEY}" -certfile ${CA} -name "${NAME}" -out "$install_home/ovpns/$NAME.ovpn12" + chown "$install_user" "$install_home/ovpns/$NAME.ovpn12" + chmod 600 "$install_home/ovpns/$NAME.ovpn12" + printf "========================================================\n" + printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME.ovpn12" + printf "You will need to transfer both the .ovpn and .ovpn12 files\n" + printf "to your iOS device.\n" + printf "========================================================\n\n" +else + #This is the standard non-iOS configuration +#Ready to make a new .ovpn file + { + # Start by populating with the default file + cat "${DEFAULT}" + + #Now, append the CA Public Cert + echo "" + cat "${CA}" + echo "" + + #Next append the client Public Cert + echo "" + sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' < "issued/${NAME}${CRT}" + echo "" + + #Then, append the client Private Key + echo "" + cat "private/${NAME}${KEY}" + echo "" + + #Finally, append the tls Private Key + echo "" + cat "${TA}" + echo "" + + } > "${NAME}${FILEEXT}" + +fi + + +# Copy the .ovpn profile to the home directory for convenient remote access +cp "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" "$install_home/ovpns/$NAME$FILEEXT" +chown "$install_user" "$install_home/ovpns/$NAME$FILEEXT" +chmod 640 "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" +chmod 640 "$install_home/ovpns/$NAME$FILEEXT" +printf "\n\n" +printf "========================================================\n" +printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME$FILEEXT" +printf "%s was copied to:\n" "$NAME$FILEEXT" +printf " %s/ovpns\n" "$install_home" +printf "for easy transfer. Please use this profile only on one\n" +printf "device and create additional profiles for other devices.\n" +printf "========================================================\n\n" diff --git a/scripts/openvpn/pivpn b/scripts/openvpn/pivpn new file mode 100755 index 0000000..de55586 --- /dev/null +++ b/scripts/openvpn/pivpn @@ -0,0 +1,106 @@ +#!/bin/bash + +# Must be root to use this tool +if [[ ! $EUID -eq 0 ]];then + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 0 + fi +fi + +function makeOVPNFunc { + shift + $SUDO /opt/pivpn/makeOVPN.sh "$@" + exit 0 +} + +function listClientsFunc { + $SUDO /opt/pivpn/clientStat.sh + exit 0 +} + +function listOVPNFunc { + $SUDO /opt/pivpn/listOVPN.sh + exit 0 +} + +function debugFunc { + echo "::: Generating Debug Output" + $SUDO /opt/pivpn/pivpnDebug.sh | tee /tmp/debug.txt + echo "::: " + echo "::: Debug output completed above." + echo "::: Copy saved to /tmp/debug.txt" + echo "::: " + exit 0 +} + +function removeOVPNFunc { + shift + $SUDO /opt/pivpn/removeOVPN.sh "$@" + exit 0 +} + +function uninstallFunc { + $SUDO /opt/pivpn/uninstall.sh + exit 0 +} + +function versionFunc { + printf "\e[1mVersion 1.9\e[0m\n" +} + +function update { + + shift + $SUDO /opt/pivpn/update.sh "$@" + exit 0 + + +} + +function backup { + + $SUDO /opt/pivpn/backup.sh + exit 0 + +} + + +function helpFunc { + echo "::: Control all PiVPN specific functions!" + echo ":::" + echo "::: Usage: pivpn [option]" + echo ":::" + echo "::: Commands:" + echo "::: -a, add [nopass] Create a client ovpn profile, optional nopass" + echo "::: -c, clients List any connected clients to the server" + echo "::: -d, debug Start a debugging session if having trouble" + echo "::: -l, list List all valid and revoked certificates" + echo "::: -r, revoke Revoke a client ovpn profile" + echo "::: -h, help Show this help dialog" + echo "::: -u, uninstall Uninstall PiVPN from your system!" + echo "::: -up, update Updates PiVPN Scripts" + echo "::: -bk, backup Backup Openvpn and ovpns dir" + exit 0 +} + +if [[ $# = 0 ]]; then + helpFunc +fi + +# Handle redirecting to specific functions based on arguments +case "$1" in +"-a" | "add" ) makeOVPNFunc "$@";; +"-c" | "clients" ) listClientsFunc;; +"-d" | "debug" ) debugFunc;; +"-l" | "list" ) listOVPNFunc;; +"-r" | "revoke" ) removeOVPNFunc "$@";; +"-h" | "help" ) helpFunc;; +"-u" | "uninstall" ) uninstallFunc;; +"-v" ) versionFunc;; +"-up"| "update" ) update "$@" ;; +"-bk"| "backup" ) backup;; +* ) helpFunc;; +esac diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh new file mode 100755 index 0000000..847bcdc --- /dev/null +++ b/scripts/openvpn/pivpnDebug.sh @@ -0,0 +1,230 @@ +#!/usr/bin/env bash +# This scripts runs as root + +setupVars="/etc/pivpn/setupVars.conf" +ERR=0 + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::" +printf "=============================================\n" +echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::" +git --git-dir /etc/.pivpn/.git log -n 1 +printf "=============================================\n" +echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::" +# Use the wildcard so setupVars.conf.update.bak from the previous install is not shown +for filename in /etc/pivpn/*; do + if [[ "$filename" != "/etc/pivpn/setupVars.conf"* ]]; then + echo "$filename -> $(cat "$filename")" + fi +done +printf "=============================================\n" +echo -e "::::\t\e[4msetupVars file shown below\e[0m\t ::::" +sed "s/$pivpnHOST/REDACTED/" < /etc/pivpn/setupVars.conf +printf "=============================================\n" +echo -e ":::: \e[4mServer configuration shown below\e[0m ::::" +cat /etc/openvpn/server.conf +printf "=============================================\n" +echo -e ":::: \e[4mClient template file shown below\e[0m ::::" +sed "s/$pivpnHOST/REDACTED/" < /etc/openvpn/easy-rsa/pki/Default.txt +printf "=============================================\n" +echo -e ":::: \t\e[4mRecursive list of files in\e[0m\t ::::\n::: \e[4m/etc/openvpn/easy-rsa/pki shows below\e[0m :::" +ls -LR /etc/openvpn/easy-rsa/pki/ -Ireqs -Icerts_by_serial +printf "=============================================\n" +echo -e "::::\t\t\e[4mSelf check\e[0m\t\t ::::" + +if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then + echo ":: [OK] IP forwarding is enabled" +else + ERR=1 + read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf + sysctl -p + echo "Done" + fi +fi + +if [ "$USING_UFW" -eq 0 ]; then + + if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + echo ":: [OK] Iptables MASQUERADE rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + iptables -t nat -F + iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${PHYS_INT}" -j MASQUERADE + iptables-save > /etc/iptables/rules.v4 + echo "Done" + fi + fi + + + if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then + + if iptables -C INPUT -i "$PHYS_INT" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT &> /dev/null; then + echo ":: [OK] Iptables INPUT rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + iptables -I INPUT 1 -i "$PHYS_INT" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT + iptables-save > /etc/iptables/rules.v4 + echo "Done" + fi + fi + fi + + if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then + + if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$PHYS_INT" -j ACCEPT &> /dev/null; then + echo ":: [OK] Iptables FORWARD rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$PHYS_INT" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$PHYS_INT" -j ACCEPT + iptables-save > /etc/iptables/rules.v4 + echo "Done" + fi + fi + fi + +else + + if LANG="en_US.UTF-8" ufw status | grep -qw 'active'; then + echo ":: [OK] Ufw is enabled" + else + ERR=1 + read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + ufw enable + fi + fi + + if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + echo ":: [OK] Iptables MASQUERADE rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $PHYS_INT -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + ufw reload + echo "Done" + fi + fi + + if iptables -C ufw-user-input -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT &> /dev/null; then + echo ":: [OK] Ufw input rule set" + else + ERR=1 + read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + ufw insert 1 allow "$pivpnPORT"/"$pivpnPROTO" + ufw reload + echo "Done" + fi + fi + + if [ "$OLD_UFW" -eq 1 ]; then + FORWARD_POLICY="$(iptables -S FORWARD | grep '^-P' | awk '{print $3}')" + if [ "$FORWARD_POLICY" = "ACCEPT" ]; then + echo ":: [OK] Ufw forwarding policy is accept" + else + ERR=1 + read -r -p ":: [ERR] Ufw forwarding policy is not 'ACCEPT', attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw + ufw reload > /dev/null + echo "Done" + fi + fi + else + if iptables -C ufw-user-forward -i tun0 -o "${PHYS_INT}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then + echo ":: [OK] Ufw forwarding rule set" + else + ERR=1 + read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$PHYS_INT" to any + ufw reload + echo "Done" + fi + fi + fi + +fi + +if systemctl is-active -q openvpn; then + echo ":: [OK] OpenVPN is running" +else + ERR=1 + read -r -p ":: [ERR] OpenVPN is not running, try to start now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + systemctl start openvpn + echo "Done" + fi +fi + +if systemctl is-enabled -q openvpn; then + echo ":: [OK] OpenVPN is enabled (it will automatically start on reboot)" +else + ERR=1 + read -r -p ":: [ERR] OpenVPN is not enabled, try to enable now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + systemctl enable openvpn + echo "Done" + fi +fi + +# grep -w (whole word) is used so port 111940 with now match when looking for 1194 +if netstat -uanpt | grep openvpn | grep -w "${pivpnPORT}" | grep -q "${pivpnPROTO}"; then + echo ":: [OK] OpenVPN is listening on port ${pivpnPORT}/${pivpnPROTO}" +else + ERR=1 + read -r -p ":: [ERR] OpenVPN is not listening, try to restart now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + systemctl restart openvpn + echo "Done" + fi +fi + +if [ "$ERR" -eq 1 ]; then + echo -e "[INFO] Run \e[1mpivpn -d\e[0m again to see if we detect issues" +fi + +printf "=============================================\n" +echo -e ":::: \e[4mSnippet of the server log\e[0m ::::" +tail -20 /var/log/openvpn.log > /tmp/snippet + +# Regular expession taken from https://superuser.com/a/202835, it will match invalid IPs +# like 123.456.789.012 but it's fine because the log only contains valid ones. +declare -a IPS_TO_HIDE=($(grepcidr -v 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 /tmp/snippet | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | uniq)) +for IP in "${IPS_TO_HIDE[@]}"; do + sed -i "s/$IP/REDACTED/g" /tmp/snippet +done + +cat /tmp/snippet +rm /tmp/snippet +printf "=============================================\n" +echo -e "::::\t\t\e[4mDebug complete\e[0m\t\t ::::" + +# Telekom Hybrid Check +wget -O /tmp/hybcheck http://speedport.ip &>/dev/null +if grep -Fq "Speedport Pro" /tmp/hybcheck || grep -Fq "Speedport Hybrid" /tmp/hybcheck +then + printf ":::\t\t\t\t\t:::\n::\tTelekom Hybrid Check\t\t ::\n:::\t\t\t\t\t:::\n" + echo "Are you using Telekom Hybrid (found a hybrid compatible router)?" + echo "If yes and you have problems with the connections you can test the following:" + echo "Add 'tun-mtu 1316' in /etc/openvpn/easy-rsa/pki/Default.txt to set a hybrid compatible MTU size (new .ovpn files)." + echo "For already existing .ovpn files 'tun-mtu 1316' can also be inserted there manually." + echo "With Telekom hybrid connections, you may have to experiment a little with MTU (tun-mtu, link-mtu and mssfix)." +fi +rm /tmp/hybcheck diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh new file mode 100755 index 0000000..0d79eaf --- /dev/null +++ b/scripts/openvpn/removeOVPN.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +# PiVPN: revoke client script + +install_user=$( [-h|--help] [] ... [] ..." + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: Client(s) to to revoke" + echo "::: -h,--help Show this help dialog" +} + +# Parse input arguments +while test $# -gt 0 +do + _key="$1" + case "$_key" in + -h|--help) + helpFunc + exit 0 + ;; + *) + CERTS_TO_REVOKE+=("$1") + ;; + esac + shift +done + +if [ ! -f "${INDEX}" ]; then + printf "The file: %s was not found\n" "$INDEX" + exit 1 +fi + +if [[ -z "${CERTS_TO_REVOKE}" ]]; then + printf "\n" + printf " ::\e[4m Certificate List \e[0m:: \n" + + i=0 + while read -r line || [ -n "$line" ]; do + STATUS=$(echo "$line" | awk '{print $1}') + if [[ "${STATUS}" = "V" ]]; then + NAME=$(echo "$line" | sed -e 's:.*/CN=::') + CERTS[$i]=${NAME} + if [ "$i" != 0 ]; then + # Prevent printing "server" certificate + printf " %s\n" "$NAME" + fi + let i=i+1 + fi + done <${INDEX} + printf "\n" + + echo "::: Please enter the Name of the client to be revoked from the list above:" + read -r NAME + + if [[ -z "${NAME}" ]]; then + echo "You can not leave this blank!" + exit 1 + fi + + for((x=1;x<=i;++x)); do + if [ "${CERTS[$x]}" = "${NAME}" ]; then + VALID=1 + fi + done + + if [ -z "${VALID}" ]; then + printf "You didn't enter a valid cert name!\n" + exit 1 + fi + + CERTS_TO_REVOKE=( "${NAME}" ) +else + i=0 + while read -r line || [ -n "$line" ]; do + STATUS=$(echo "$line" | awk '{print $1}') + if [[ "${STATUS}" = "V" ]]; then + NAME=$(echo "$line" | sed -e 's:.*/CN=::') + CERTS[$i]=${NAME} + let i=i+1 + fi + done <${INDEX} + + for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do + VALID=0 + for((x=1;x<=i;++x)); do + if [ "${CERTS[$x]}" = "${CERTS_TO_REVOKE[ii]}" ]; then + VALID=1 + fi + done + + if [ "${VALID}" != 1 ]; then + printf "You passed an invalid cert name: '"%s"'!\n" "${CERTS_TO_REVOKE[ii]}" + exit 1 + fi + done +fi + +cd /etc/openvpn/easy-rsa || exit + +install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6) +install_home=${install_home%/} # remove possible trailing slash +for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do + printf "\n::: Revoking certificate '"%s"'.\n" "${CERTS_TO_REVOKE[ii]}" + ./easyrsa --batch revoke "${CERTS_TO_REVOKE[ii]}" + ./easyrsa gen-crl + printf "\n::: Certificate revoked, and CRL file updated.\n" + printf "::: Removing certs and client configuration for this profile.\n" + rm -rf "pki/reqs/${CERTS_TO_REVOKE[ii]}.req" + rm -rf "pki/private/${CERTS_TO_REVOKE[ii]}.key" + rm -rf "pki/issued/${CERTS_TO_REVOKE[ii]}.crt" + + rm -rf "${install_home}/ovpns/${CERTS_TO_REVOKE[ii]}.ovpn" + rm -rf "/etc/openvpn/easy-rsa/pki/${CERTS_TO_REVOKE[ii]}.ovpn" + cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem +done +printf "::: Completed!\n" diff --git a/scripts/openvpn/update.sh b/scripts/openvpn/update.sh new file mode 100755 index 0000000..fb74450 --- /dev/null +++ b/scripts/openvpn/update.sh @@ -0,0 +1,99 @@ +#/bin/bash + +###Updates pivpn scripts (Not PiVPN) +###Main Vars +pivpnrepo="https://github.com/pivpn/pivpn.git" +pivpnlocalpath="/etc/.pivpn" +pivpnscripts="/opt/pivpn/scripts" +bashcompletiondir="/etc/bash_completion.d/pivpn" + + +###Functions +##Updates scripts +updatepivpnscripts(){ + ##We don't know what sort of changes users have made. + ##Lets remove first /etc/.pivpn dir then clone it back again + echo "going do update PiVPN Scripts" + if [[ -d $pivpnlocalpath ]]; then + + sudo rm -rf $pivpnlocalpath + cloneandupdate + + else + cloneandupdate + fi + echo "PiVPN Scripts have been updated" +} + +##Updates scripts using test branch +updatefromtest(){ + ##We don't know what sort of changes users have made. + ##Lets remove first /etc/.pivpn dir then clone it back again + echo "PiVPN Scripts updating from test branch" + if [[ -d /etc/.pivpn ]]; then + + rm -rf /etc/.pivpn + cloneupdttest + + else + + cloneupdttest + + fi + echo "PiVPN Scripts updated have been updated from test branch" + } + +##Clone and copy pivpn scripts to /op/ +cloneandupdate(){ + + sudo git clone $pivpnrepo $pivpnlocalpath + sudo cp -r $pivpnlocalpath/scripts $pivpnscripts + sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir + +} + +##same as cloneandupdate() but from test branch +##and falls back to master branch again after updating +cloneupdttest(){ + + sudo git clone $pivpnrepo $pivpnlocalpath + sudo git -C $pivpnlocalpath checkout test + sudo git -C $pivpnlocalpath pull origin test + sudo cp -r $pivpnlocalpath/scripts $pivpnscripts + sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir + sudo git -C $pivpnlocalpath checkout master + +} + +scriptusage(){ + echo -e "Updates pivpn scripts,\n + Usage: + pivpn update | updates from master branch + pivpn update -t or --test | updates from test branch" + +} + +## SCRIPT + +if [[ $# -eq 0 ]]; then + updatepivpnscripts + +else + while true; do + case "$1" in + -t | --test | test ) + updatefromtest + exit 0 + ;; + -h | --help | help ) + scriptusage + exit 0 + ;; + * ) + updatepivpnscripts + exit 0 + ;; + esac + done +fi + diff --git a/scripts/wireguard/listCONF.sh b/scripts/wireguard/listCONF.sh new file mode 100755 index 0000000..02e5224 --- /dev/null +++ b/scripts/wireguard/listCONF.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +cd /etc/wireguard/configs +if [ ! -s clients.txt ]; then + echo "::: There are no clients to list" + exit 1 +fi + +# Present the user with a summary of the clients, fetching info from dates. +FORMATTED+=": \e[4mClient\e[0m&\e[4mCreation date\e[0m :\n" + +while read -r LINE; do + CLIENT_NAME="$(awk '{print $1}' <<< "$LINE")" + + CREATION_DATE="$(awk '{print $2}' <<< "$LINE")" + + # Dates are converted from UNIX time to human readable. + CD_FORMAT="$(date -d @"$CREATION_DATE" +'%d %b %Y, %H:%M, %Z')" + + FORMATTED+="• $CLIENT_NAME&$CD_FORMAT\n" +done < clients.txt + +echo -e "$FORMATTED" | column -t -s '&' \ No newline at end of file diff --git a/scripts/wireguard/makeCONF.sh b/scripts/wireguard/makeCONF.sh new file mode 100755 index 0000000..cbfd9b4 --- /dev/null +++ b/scripts/wireguard/makeCONF.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +setupVars="/etc/pivpn/setupVars.conf" + +helpFunc(){ + echo "::: Create a client conf profile" + echo ":::" + echo "::: Usage: pivpn <-a|add> [-n|--name ] [-h|--help]" + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: -n,--name Name for the Client (default: '$HOSTNAME')" + echo "::: -h,--help Show this help dialog" +} + +# Parse input arguments +while test $# -gt 0; do + _key="$1" + case "$_key" in + -n|--name|--name=*) + _val="${_key##--name=}" + if test "$_val" = "$_key"; then + test $# -lt 2 && echo "::: Missing value for the optional argument '$_key'." && exit 1 + _val="$2" + shift + fi + CLIENT_NAME="$_val" + ;; + -h|--help) + helpFunc + exit 0 + ;; + *) + echo "::: Error: Got an unexpected argument '$1'" + helpFunc + exit 1 + ;; + esac + shift +done + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +# The home folder variable was sourced from the settings file. +if [ ! -d "${install_home}/configs" ]; then + mkdir "${install_home}/configs" + chown "${install_user}":"${install_user}" "${install_home}/configs" +fi + +cd /etc/wireguard + +if [ -z "${CLIENT_NAME}" ]; then + read -r -p "Enter a Name for the Client: " CLIENT_NAME +fi + +if [[ "${CLIENT_NAME}" =~ [^a-zA-Z0-9.@_-] ]]; then + echo "Name can only contain alphanumeric characters and these characters (.-@_)." + exit 1 +fi + +if [ -z "${CLIENT_NAME}" ]; then + echo "::: You cannot leave the name blank." + exit 1 +fi + +if [ -f "configs/${CLIENT_NAME}.conf" ]; then + echo "::: A client with this name already exists" + exit 1 +fi + +wg genkey | tee "keys/${CLIENT_NAME}_priv" | wg pubkey > "keys/${CLIENT_NAME}_pub" +echo "::: Client Keys generated" + +# Find an unused number for the last octet of the client IP +for i in {2..254}; do + if ! grep -q " $i" configs/clients.txt; then + COUNT="$i" + echo "${CLIENT_NAME} $(date +%s) ${COUNT}" >> configs/clients.txt + break + fi +done + +echo -n "[Interface] +PrivateKey = $(cat "keys/${CLIENT_NAME}_priv") +Address = 10.6.0.${COUNT}/24 +DNS = ${pivpnDNS1}" > "configs/${CLIENT_NAME}.conf" + +if [ -n "${pivpnDNS2}" ]; then + echo ", ${pivpnDNS2}" >> "configs/${CLIENT_NAME}.conf" +else + echo >> "configs/${CLIENT_NAME}.conf" +fi +echo >> "configs/${CLIENT_NAME}.conf" + +echo "[Peer] +PublicKey = $(cat keys/server_pub) +PresharedKey = $(cat keys/psk) +Endpoint = ${pivpnHOST}:${pivpnPORT} +AllowedIPs = 0.0.0.0/0" >> "configs/${CLIENT_NAME}.conf" +echo "::: Client config generated" + +echo "# begin ${CLIENT_NAME} +[Peer] +PublicKey = $(cat "keys/${CLIENT_NAME}_pub") +PresharedKey = $(cat keys/psk) +AllowedIPs = 10.6.0.${COUNT}/32 +# end ${CLIENT_NAME}" >> wg0.conf +echo "::: Updated server config" + +if systemctl restart wg-quick@wg0; then + echo "::: WireGuard restarted" +else + echo "::: Failed to restart WireGuard" +fi + +cp "configs/${CLIENT_NAME}.conf" "${install_home}/configs/${CLIENT_NAME}.conf" +chown "${install_user}":"${install_user}" "${install_home}/configs/${CLIENT_NAME}.conf" + +echo "======================================================================" +echo -e "::: Done! \e[1m${CLIENT_NAME}.conf successfully created!\e[0m" +echo "::: ${CLIENT_NAME}.conf was copied to ${install_home}/configs for easy transfer." +echo "::: Please use this profile only on one device and create additional" +echo -e "::: profiles for other devices. You can also use \e[1mpivpn -qr\e[0m" +echo "::: to generate a QR Code you can scan with the mobile app." +echo "======================================================================" diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn new file mode 100755 index 0000000..f4bcfd9 --- /dev/null +++ b/scripts/wireguard/pivpn @@ -0,0 +1,83 @@ +#!/bin/bash + +# Must be root to use this tool +if [ $EUID -ne 0 ];then + if dpkg-query -s sudo &> /dev/null; then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi +fi + +makeConf(){ + shift + $SUDO /opt/pivpn/makeCONF.sh "$@" + exit 1 +} + +listConnected(){ + $SUDO wg show + exit 1 +} + +debug(){ + $SUDO /opt/pivpn/pivpnDEBUG.sh + exit 1 +} + +listClients(){ + $SUDO /opt/pivpn/listCONF.sh + exit 1 +} + +showQrcode(){ + shift + $SUDO /opt/pivpn/qrcodeCONF.sh "$@" + exit 1 +} + +removeClient(){ + shift + $SUDO /opt/pivpn/removeCONF.sh "$@" + exit 1 +} + +uninstallServer(){ + $SUDO /opt/pivpn/uninstall.sh + exit 1 +} + +showHelp(){ + echo "::: Control all PiVPN specific functions!" + echo ":::" + echo "::: Usage: pivpn [option]" + echo ":::" + echo "::: Commands:" + echo "::: -a, add Create a client conf profile" + echo "::: -c, clients List any connected clients to the server" + echo "::: -d, debug Start a debugging session if having trouble" + echo "::: -l, list List all clients" + echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app" + echo "::: -r, remove Remove a client" + echo "::: -h, help Show this help dialog" + echo "::: -u, uninstall Uninstall pivpn from your system!" + exit 1 +} + +if [ $# = 0 ]; then + showHelp +fi + +# Handle redirecting to specific functions based on arguments +case "$1" in +"-a" | "add" ) makeConf "$@";; +"-c" | "clients" ) listConnected;; +"-d" | "debug" ) debug;; +"-l" | "list" ) listClients;; +"-qr" | "qrcode" ) showQrcode "$@";; +"-r" | "remove" ) removeClient "$@";; +"-h" | "help" ) showHelp;; +"-u" | "uninstall" ) uninstallServer;; +* ) showHelp;; +esac diff --git a/scripts/wireguard/pivpnDEBUG.sh b/scripts/wireguard/pivpnDEBUG.sh new file mode 100755 index 0000000..761cc49 --- /dev/null +++ b/scripts/wireguard/pivpnDEBUG.sh @@ -0,0 +1,173 @@ +#!/usr/bin/env bash +# This scripts runs as root + +setupVars="/etc/pivpn/setupVars.conf" + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +EXAMPLE="$(head -1 /etc/wireguard/configs/clients.txt | awk '{print $1}')" +ERR=0 + +echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::" +printf "=============================================\n" +echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::" +git --git-dir /etc/.pivpn/.git log -n 1 +printf "=============================================\n" +echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::" +sed "s/$pivpnHOST/REDACTED/" < /etc/pivpn/setupVars.conf +printf "=============================================\n" +echo -e ":::: \e[4mServer configuration shown below\e[0m ::::" +cd /etc/wireguard/keys +cp ../wg0.conf ../wg0.tmp +for k in *; do + sed "s#$(cat "$k")#$k#" -i ../wg0.tmp +done +cat ../wg0.tmp +rm ../wg0.tmp +printf "=============================================\n" +echo -e ":::: \e[4mClient configuration shown below\e[0m ::::" +if [ -n "$EXAMPLE" ]; then + cp ../configs/"$EXAMPLE".conf ../configs/"$EXAMPLE".tmp + for k in *; do + sed "s#$(cat "$k")#$k#" -i ../configs/"$EXAMPLE".tmp + done + sed "s/$pivpnHOST/REDACTED/" < ../configs/"$EXAMPLE".tmp + rm ../configs/"$EXAMPLE".tmp +else + echo "::: There are no clients yet" +fi + +printf "=============================================\n" +echo -e ":::: \t\e[4mRecursive list of files in\e[0m\t ::::\n::::\e\t[4m/etc/wireguard shown below\e[0m\t ::::" +ls -LR /etc/wireguard +printf "=============================================\n" +echo -e "::::\t\t\e[4mSelf check\e[0m\t\t ::::" + +if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then + echo ":: [OK] IP forwarding is enabled" +else + ERR=1 + read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf + sysctl -p + echo "Done" + fi +fi + +if [ "$USING_UFW" -eq 0 ]; then + + if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + echo ":: [OK] Iptables MASQUERADE rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + iptables -t nat -F + iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${PHYS_INT}" -j MASQUERADE + iptables-save > /etc/iptables/rules.v4 + iptables-restore < /etc/iptables/rules.v4 + echo "Done" + fi + fi + +else + + if LANG="en_US.UTF-8" ufw status | grep -qw 'active'; then + echo ":: [OK] Ufw is enabled" + else + ERR=1 + read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + ufw enable + fi + fi + + if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + echo ":: [OK] Iptables MASQUERADE rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $PHYS_INT -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + ufw reload + echo "Done" + fi + fi + + if iptables -C ufw-user-input -p udp --dport "${pivpnPORT}" -j ACCEPT &> /dev/null; then + echo ":: [OK] Ufw input rule set" + else + ERR=1 + read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + ufw insert 1 allow "$pivpnPORT"/udp + ufw reload + echo "Done" + fi + fi + + if iptables -C ufw-user-forward -i wg0 -o "${PHYS_INT}" -s 10.6.0.0/24 -j ACCEPT &> /dev/null; then + echo ":: [OK] Ufw forwarding rule set" + else + ERR=1 + read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + ufw route insert 1 allow in on wg0 from 10.6.0.0/24 out on "$PHYS_INT" to any + ufw reload + echo "Done" + fi + fi + +fi + +if systemctl is-active -q wg-quick@wg0; then + echo ":: [OK] WireGuard is running" +else + ERR=1 + read -r -p ":: [ERR] WireGuard is not running, try to start now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + systemctl start wg-quick@wg0 + echo "Done" + fi +fi + +if systemctl is-enabled -q wg-quick@wg0; then + echo ":: [OK] WireGuard is enabled (it will automatically start on reboot)" +else + ERR=1 + read -r -p ":: [ERR] WireGuard is not enabled, try to enable now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + systemctl enable wg-quick@wg0 + echo "Done" + fi +fi + +# grep -w (whole word) is used so port 111940 with now match when looking for 1194 +if netstat -uanp | grep -w "${pivpnPORT}" | grep -q 'udp'; then + echo ":: [OK] WireGuard is listening on port ${pivpnPORT}/udp" +else + ERR=1 + read -r -p ":: [ERR] WireGuard is not listening, try to restart now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + systemctl restart wg-quick@wg0 + echo "Done" + fi +fi + +if [ "$ERR" -eq 1 ]; then + echo -e "[INFO] Run \e[1mpivpn -d\e[0m again to see if we detect issues" +fi +printf "=============================================\n" +echo -e ":::: \e[1mWARNING\e[0m: This script should have automatically masked sensitive ::::" +echo -e ":::: information, however, still make sure that \e[4mPrivateKey\e[0m, \e[4mPublicKey\e[0m ::::" +echo -e ":::: and \e[4mPresharedKey\e[0m are masked before reporting an issue. An example key ::::" +echo ":::: that you should NOT see in this log looks like this: ::::" +echo ":::: WJhKKx+Uk1l1TxaH2KcEGeBdPBTp/k/Qy4EpBig5UnI= ::::" +printf "=============================================\n" +echo -e "::::\t\t\e[4mDebug complete\e[0m\t\t ::::" diff --git a/scripts/wireguard/qrcodeCONF.sh b/scripts/wireguard/qrcodeCONF.sh new file mode 100755 index 0000000..40fce8f --- /dev/null +++ b/scripts/wireguard/qrcodeCONF.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +helpFunc(){ + echo "::: Show the qrcode of a client for use with the mobile app" + echo ":::" + echo "::: Usage: pivpn <-qr|qrcode> [-h|--help] [] ... [] ..." + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: Client(s) to show" + echo "::: -h,--help Show this help dialog" +} + +# Parse input arguments +while test $# -gt 0 +do + _key="$1" + case "$_key" in + -h|--help) + helpFunc + exit 0 + ;; + *) + CLIENTS_TO_SHOW+=("$1") + ;; + esac + shift +done + +cd /etc/wireguard/configs +if [ ! -s clients.txt ]; then + echo "::: There are no clients to remove" + exit 1 +fi + +if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then + + echo -e "::\e[4m Client list \e[0m::" + LIST=($(awk '{print $1}' clients.txt)) + COUNTER=1 + while [ $COUNTER -le ${#LIST[@]} ]; do + echo "• ${LIST[(($COUNTER-1))]}" + ((COUNTER++)) + done + + read -r -p "Please enter the Name of the Client to show: " CLIENTS_TO_SHOW + + if [ -z "${CLIENTS_TO_SHOW}" ]; then + echo "::: You can not leave this blank!" + exit 1 + fi +fi + +for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do + if grep -qw "${CLIENT_NAME}" clients.txt; then + echo -e "::: Showing client \e[1m${CLIENT_NAME}\e[0m below" + echo "=====================================================================" + qrencode -t ansiutf8 < "${CLIENT_NAME}.conf" + echo "=====================================================================" + else + echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" + fi +done \ No newline at end of file diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh new file mode 100755 index 0000000..403da3c --- /dev/null +++ b/scripts/wireguard/removeCONF.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +setupVars="/etc/pivpn/setupVars.conf" + +helpFunc(){ + echo "::: Remove a client conf profile" + echo ":::" + echo "::: Usage: pivpn <-r|remove> [-h|--help] [] ... [] ..." + echo ":::" + echo "::: Commands:" + echo "::: [none] Interactive mode" + echo "::: Client(s) to remove" + echo "::: -h,--help Show this help dialog" +} + +# Parse input arguments +while test $# -gt 0 +do + _key="$1" + case "$_key" in + -h|--help) + helpFunc + exit 0 + ;; + *) + CLIENTS_TO_REMOVE+=("$1") + ;; + esac + shift +done + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +cd /etc/wireguard +if [ ! -s configs/clients.txt ]; then + echo "::: There are no clients to remove" + exit 1 +fi + +if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then + + echo -e "::\e[4m Client list \e[0m::" + LIST=($(awk '{print $1}' configs/clients.txt)) + COUNTER=1 + while [ $COUNTER -le ${#LIST[@]} ]; do + echo "• ${LIST[(($COUNTER-1))]}" + ((COUNTER++)) + done + + read -r -p "Please enter the Name of the Client to be removed from the list above: " CLIENTS_TO_REMOVE + + if [ -z "${CLIENTS_TO_REMOVE}" ]; then + echo "::: You can not leave this blank!" + exit 1 + fi +fi + +DELETED_COUNT=0 + +for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do + + if ! grep -qw "${CLIENT_NAME}" configs/clients.txt; then + echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist" + else + REQUESTED="$(sha256sum "configs/${CLIENT_NAME}.conf" | cut -c 1-64)" + read -r -p "Do you really want to delete $CLIENT_NAME? [Y/n] " + + if [[ $REPLY =~ ^[Yy]$ ]]; then + + # Grab the least significant octed of the client IP address + COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $3}') + # And the creation date of the client + CREATION_DATE="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $2}')" + + # Then remove the client matching the variables above + sed "/${CLIENT_NAME} ${CREATION_DATE} ${COUNT}/d" -i configs/clients.txt + + # Remove the peer section from the server config + sed "/# begin ${CLIENT_NAME}/,/# end ${CLIENT_NAME}/d" -i wg0.conf + echo "::: Updated server config" + + rm "configs/${CLIENT_NAME}.conf" + echo "::: Client config for ${CLIENT_NAME} removed" + + rm "keys/${CLIENT_NAME}_priv" + rm "keys/${CLIENT_NAME}_pub" + echo "::: Client Keys for ${CLIENT_NAME} removed" + + # Find all .conf files in the home folder of the user matching the checksum of the + # config and delete them. '-maxdepth 3' is used to avoid traversing too many folders. + find "${install_home}" -maxdepth 3 -type f -name '*.conf' -print0 | while IFS= read -r -d '' CONFIG; do + if sha256sum -c <<< "${REQUESTED} ${CONFIG}" &> /dev/null; then + rm "${CONFIG}" + fi + done + + echo "::: Successfully deleted ${CLIENT_NAME}" + + ((DELETED_COUNT++)) + fi + fi + +done + +# Restart WireGuard only if some clients were actually deleted +if [ "${DELETED_COUNT}" -gt 0 ]; then + if systemctl restart wg-quick@wg0; then + echo "::: WireGuard restarted" + else + echo "::: Failed to restart WireGuard" + fi +fi From 1777d5c2390bbb2f66943d5175407f9a466ab9c2 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 14 Oct 2019 15:06:34 +0200 Subject: [PATCH 03/79] Added back Debian 10 support --- auto_install/install.sh | 73 ++++++++++++++++++++++----------- scripts/openvpn/removeOVPN.sh | 14 ++++--- scripts/wireguard/pivpnDEBUG.sh | 3 +- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 653b017..079cd1f 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -91,7 +91,7 @@ distroCheck(){ fi case ${PLAT} in - Raspbian) + Debian|Raspbian) case ${OSCN} in buster) ;; @@ -120,7 +120,7 @@ checkHostname(){ if [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; then echo "::: Hostname valid and length OK, proceeding..." fi - done + done else echo "::: Hostname length OK" fi @@ -525,6 +525,7 @@ installWireGuard(){ # Otherwhise compile and build the kernel module via DKMS (so it will # be recompiled on kernel upgrades) if [ "$(uname -m)" = "armv7l" ]; then + echo "::: Installing WireGuard from Debian package... " # dirmngr is used to download repository keys, whereas qrencode is used to generate qrcodes # from config file, for use with mobile clients @@ -532,20 +533,22 @@ installWireGuard(){ installDependentPackages PIVPN_DEPS[@] # Do not upgrade packages from the unstable repository except for wireguard echo "::: Adding Debian repository... " - echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee -a /etc/apt/sources.list.d/unstable.list > /dev/null + echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null echo "Package: * Pin: release a=unstable Pin-Priority: 1 Package: wireguard wireguard-dkms wireguard-tools Pin: release a=unstable -Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/null +Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(wireguard) installDependentPackages PIVPN_DEPS[@] + elif [ "$(uname -m)" = "armv6l" ]; then + echo "::: Installing WireGuard from source... " PIVPN_DEPS=(libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode) installDependentPackages PIVPN_DEPS[@] @@ -553,8 +556,8 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n # Delete any leftover code $SUDO rm -rf /usr/src/wireguard-* - echo -n "::: Downloading source code... " - wget -O- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src + echo "::: Downloading source code... " + wget -qO- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src echo "done!" cd /usr/src @@ -565,7 +568,7 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n # We install the userspace tools manually since DKMS only compiles and # installs the kernel module - echo -n "::: Compiling WireGuard tools... " + echo "::: Compiling WireGuard tools... " if $SUDO make tools; then echo "done!" else @@ -573,7 +576,7 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n exit 1 fi - echo -n "::: Installing WireGuard tools... " + echo "::: Installing WireGuard tools... " if $SUDO make install tools; then echo "done!" else @@ -581,7 +584,7 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n exit 1 fi - echo -n "::: Adding WireGuard modules via DKMS... " + echo "::: Adding WireGuard modules via DKMS... " if $SUDO dkms add wireguard/"${WG_SNAPSHOT}"; then echo "done!" else @@ -590,7 +593,7 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n exit 1 fi - echo -n "::: Compiling WireGuard modules via DKMS... " + echo "::: Compiling WireGuard modules via DKMS... " if $SUDO dkms build wireguard/"${WG_SNAPSHOT}"; then echo "done!" else @@ -599,7 +602,7 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n exit 1 fi - echo -n "::: Installing WireGuard modules via DKMS... " + echo "::: Installing WireGuard modules via DKMS... " if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then echo "done!" else @@ -607,6 +610,17 @@ Pin-Priority: 500" | $SUDO tee -a /etc/apt/preferences.d/limit-unstable > /dev/n $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all exit 1 fi + + elif [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "i686" ]; then + + echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null + echo "Package: * +Pin: release a=unstable +Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + PIVPN_DEPS=(qrencode wireguard) + installDependentPackages PIVPN_DEPS[@] + fi } @@ -862,9 +876,9 @@ askEncryption(){ fi if ([ "$pivpnENCRYPT" -ge "3072" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\n\nGenerating DH parameters for a $pivpnENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from their database.\nMore information about this service can be found here: https://2ton.com.au/safeprimes/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}); then - DOWNLOAD_DH_PARAM=true + DOWNLOAD_DH_PARAM=1 else - DOWNLOAD_DH_PARAM=false + DOWNLOAD_DH_PARAM=0 fi echo "pivpnENCRYPT=${pivpnENCRYPT}" >> /tmp/setupVars.conf @@ -885,7 +899,7 @@ confOpenVPN(){ fi # Get easy-rsa - wget -q -O - "${easyrsaRel}" | $SUDO tar xz -C /etc/openvpn && $SUDO mv /etc/openvpn/EasyRSA-v${easyrsaVer} /etc/openvpn/easy-rsa + wget -qO- "${easyrsaRel}" | $SUDO tar xz -C /etc/openvpn && $SUDO mv /etc/openvpn/EasyRSA-v${easyrsaVer} /etc/openvpn/easy-rsa # fix ownership $SUDO chown -R root:root /etc/openvpn/easy-rsa $SUDO mkdir /etc/openvpn/easy-rsa/pki @@ -916,9 +930,9 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null # Build the server EASYRSA_CERT_EXPIRE=3650 ${SUDOE} ./easyrsa build-server-full ${SERVER_NAME} nopass - if [[ ${DOWNLOAD_DH_PARAM} == true ]]; then + if [ ${DOWNLOAD_DH_PARAM} -eq 1 ]; then # Downloading parameters - ${SUDOE} curl "https://2ton.com.au/getprimes/random/dhparam/${pivpnENCRYPT}" -o "/etc/openvpn/easy-rsa/pki/dh${pivpnENCRYPT}.pem" + ${SUDOE} curl -s "https://2ton.com.au/getprimes/random/dhparam/${pivpnENCRYPT}" -o "/etc/openvpn/easy-rsa/pki/dh${pivpnENCRYPT}.pem" else # Generate Diffie-Hellman key exchange ${SUDOE} ./easyrsa gen-dh @@ -989,6 +1003,13 @@ confOVPN(){ } confWireGuard(){ + if [ -d /etc/wireguard ]; then + $SUDO rm -r /etc/wireguard + $SUDO mkdir /etc/wireguard + $SUDO chown root:root /etc/wireguard + $SUDO chmod 700 /etc/wireguard + fi + whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" $SUDO mkdir /etc/wireguard/configs $SUDO touch /etc/wireguard/configs/clients.txt @@ -1072,7 +1093,7 @@ confNetwork(){ fi case ${PLAT} in - Raspbian) + Debian|Raspbian) $SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null ;; esac @@ -1104,7 +1125,7 @@ if \$programname == 'ovpn-server' then stop" | $SUDO tee /etc/rsyslog.d/30-openv # Restart the logging service case ${PLAT} in - Raspbian) + Debian|Raspbian) $SUDO systemctl restart rsyslog.service || true ;; esac @@ -1153,11 +1174,15 @@ askUnattendedUpgrades(){ confUnattendedUpgrades(){ cd /etc/apt/apt.conf.d - wget -q -O- "$UNATTUPG_CONFIG" | $SUDO tar xz - $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades - $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" + if [ "$PLAT" = "Raspbian" ]; then + wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz + $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades + $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" + fi - if [ "$VPN" = "WireGuard" ] && [ "$(uname -m)" = "armv7l" ]; then + # On architectures different from armv6l, where we install wireguard from source, enable + # automatic updates via the unstable repository + if [ "$VPN" = "WireGuard" ] && [ "$(uname -m)" != "armv6l" ]; then sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades fi @@ -1183,7 +1208,7 @@ installScripts() { FOLDER=$(tr '[:upper:]' '[:lower:]' <<< "$VPN") $SUDO cp /etc/.pivpn/scripts/$FOLDER/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh - $SUDO cp /etc/.pivpn/$FOLDER/pivpn /usr/local/bin/pivpn + $SUDO cp /etc/.pivpn/$FOLDER/scripts/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn $SUDO cp /etc/.pivpn/scripts/$FOLDER/bash-completion /etc/bash_completion.d/pivpn . /etc/bash_completion.d/pivpn @@ -1285,7 +1310,7 @@ main(){ echo "::: Restarting services..." # Start services case ${PLAT} in - Raspbian) + Debian|Raspbian) if [ "$VPN" = "OpenVPN" ]; then $SUDO systemctl enable openvpn.service $SUDO systemctl start openvpn.service diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index 0d79eaf..86457c2 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -1,10 +1,16 @@ #!/usr/bin/env bash # PiVPN: revoke client script -install_user=$( Date: Mon, 14 Oct 2019 16:51:43 +0200 Subject: [PATCH 04/79] Bugfixes --- auto_install/install.sh | 26 ++++++++++++++++++++------ scripts/wireguard/makeCONF.sh | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 079cd1f..de5ec6e 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -300,6 +300,12 @@ chooseInterface(){ fi } +avoidStaticIPv4Ubuntu() { + # If we are in Ubuntu then they need to have previously set their network, so just use what you have. + whiptail --msgbox --backtitle "IP Information" --title "IP Information" "Since we think you are not using Raspbian, we will not configure a static IP for you. +If you are in Amazon then you can not configure a static IP anyway. Just ensure before this installer started you had set an elastic IP on your instance." ${r} ${c} +} + getStaticIPv4Settings() { local ipSettingsCorrect # Grab their current DNS Server @@ -467,7 +473,11 @@ makeRepo(){ # Remove the non-repos interface and clone the interface echo -n "::: Cloning $2 into $1..." $SUDO rm -rf "${1}" + # Go back to /etc otherwhise git will complain when the current working + # directory has just been deleted (/etc/.pivpn). + cd /etc $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + cd "${1}" || exit 1 if [ -z "${TESTING}" ]; then : elif [ "${TESTING}" = "test" ]; then @@ -618,7 +628,7 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null Pin: release a=unstable Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO ${UPDATE_PKG_CACHE} &> /dev/null - PIVPN_DEPS=(qrencode wireguard) + PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard) installDependentPackages PIVPN_DEPS[@] fi @@ -1183,7 +1193,7 @@ confUnattendedUpgrades(){ # On architectures different from armv6l, where we install wireguard from source, enable # automatic updates via the unstable repository if [ "$VPN" = "WireGuard" ] && [ "$(uname -m)" != "armv6l" ]; then - sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades + $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades fi # Add the remaining settings for all other distributions @@ -1195,7 +1205,7 @@ confUnattendedUpgrades(){ APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null } -installScripts() { +installScripts(){ # Install the scripts from /etc/.pivpn to their various locations echo ":::" echo -n "::: Installing scripts to /opt/pivpn..." @@ -1208,7 +1218,7 @@ installScripts() { FOLDER=$(tr '[:upper:]' '[:lower:]' <<< "$VPN") $SUDO cp /etc/.pivpn/scripts/$FOLDER/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh - $SUDO cp /etc/.pivpn/$FOLDER/scripts/pivpn /usr/local/bin/pivpn + $SUDO cp /etc/.pivpn/scripts/$FOLDER/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn $SUDO cp /etc/.pivpn/scripts/$FOLDER/bash-completion /etc/bash_completion.d/pivpn . /etc/bash_completion.d/pivpn @@ -1291,8 +1301,12 @@ main(){ # Find interfaces and let the user choose one chooseInterface - getStaticIPv4Settings - setStaticIPv4 + if [ "$PLAT" != "Raspbian" ]; then + avoidStaticIPv4Ubuntu + else + getStaticIPv4Settings + setStaticIPv4 + fi # Choose the user for the ovpns chooseUser diff --git a/scripts/wireguard/makeCONF.sh b/scripts/wireguard/makeCONF.sh index cbfd9b4..e0378cd 100755 --- a/scripts/wireguard/makeCONF.sh +++ b/scripts/wireguard/makeCONF.sh @@ -50,6 +50,7 @@ source "${setupVars}" if [ ! -d "${install_home}/configs" ]; then mkdir "${install_home}/configs" chown "${install_user}":"${install_user}" "${install_home}/configs" + chmod 0750 "${install_home}/configs" fi cd /etc/wireguard @@ -120,6 +121,7 @@ fi cp "configs/${CLIENT_NAME}.conf" "${install_home}/configs/${CLIENT_NAME}.conf" chown "${install_user}":"${install_user}" "${install_home}/configs/${CLIENT_NAME}.conf" +chmod 640 "${install_home}/configs/${CLIENT_NAME}.conf" echo "======================================================================" echo -e "::: Done! \e[1m${CLIENT_NAME}.conf successfully created!\e[0m" From 5c97221d3f5f7191abd73b16e89fd3e54b89194a Mon Sep 17 00:00:00 2001 From: Orazio Date: Wed, 16 Oct 2019 12:01:50 +0200 Subject: [PATCH 05/79] Revert some variable names and fix iptables rules --- auto_install/install.sh | 39 +++++++++++++++++++-------------- scripts/openvpn/pivpnDebug.sh | 22 +++++++++---------- scripts/wireguard/pivpnDEBUG.sh | 12 +++++----- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index de5ec6e..458815d 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -270,8 +270,8 @@ chooseInterface(){ local firstloop=1 if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then - PHYS_INT="${availableInterfaces}" - echo "PHYS_INT=${PHYS_INT}" >> /tmp/setupVars.conf + IPv4dev="${availableInterfaces}" + echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf return fi @@ -290,9 +290,9 @@ chooseInterface(){ chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) if [[ $? = 0 ]]; then for desiredInterface in ${chooseInterfaceOptions}; do - PHYS_INT=${desiredInterface} - echo "::: Using interface: $PHYS_INT" - echo "PHYS_INT=${PHYS_INT}" >> /tmp/setupVars.conf + IPv4dev=${desiredInterface} + echo "::: Using interface: $IPv4dev" + echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf done else echo "::: Cancel selected, exiting...." @@ -314,6 +314,9 @@ getStaticIPv4Settings() { if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? IP address: ${IPv4addr} Gateway: ${IPv4gw}" ${r} ${c}); then + + echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. @@ -337,7 +340,8 @@ It is also possible to use a DHCP reservation, but if you are going to do that, IP address: ${IPv4addr} Gateway: ${IPv4gw}" ${r} ${c}); then # If the settings are correct, then we need to set the pivpnIP - echo "pivpnIP=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf # After that's done, the loop ends and we move on ipSettingsCorrect=True else @@ -363,7 +367,7 @@ It is also possible to use a DHCP reservation, but if you are going to do that, setDHCPCD(){ # Append these lines to dhcpcd.conf to enable a static IP - echo "interface ${PHYS_INT} + echo "interface ${IPv4dev} static ip_address=${IPv4addr} static routers=${IPv4gw} static domain_name_servers=${IPv4dns}" | $SUDO tee -a ${dhcpcdFile} >/dev/null @@ -376,7 +380,7 @@ setStaticIPv4(){ echo "::: Static IP already configured." else setDHCPCD - $SUDO ip addr replace dev "${PHYS_INT}" "${IPv4addr}" + $SUDO ip addr replace dev "${IPv4dev}" "${IPv4addr}" echo ":::" echo "::: Setting IP to ${IPv4addr}. You may need to restart after the install is complete." echo ":::" @@ -511,14 +515,15 @@ askWhichVPN(){ if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard of 'No' to use OpenVPN." ${r} ${c}); then VPN="WireGuard" - pivpnINT="wg0" + pivpnDEV="wg0" + pivpnNET="10.6.0.0/24" else VPN="OpenVPN" - pivpnINT="tun0" + pivpnDEV="tun0" + pivpnNET="10.8.0.0/24" fi echo "VPN=${VPN}" >> /tmp/setupVars.conf - echo "pivpnINT=${pivpnINT}" >> /tmp/setupVars.conf } installOpenVPN(){ @@ -1053,10 +1058,10 @@ confNetwork(){ USING_UFW=1 echo "::: Detected UFW is enabled." echo "::: Adding UFW rules..." - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $PHYS_INT -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s $pivpnNET -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) $SUDO ufw insert 1 allow "$PORT"/"$PROTO" >/dev/null - $SUDO ufw route insert 1 allow in on "$pivpnINT" from 10.8.0.0/24 out on "$PHYS_INT" to any >/dev/null + $SUDO ufw route insert 1 allow in on "$pivpnDEV" from "$pivpnNET" out on "$IPv4dev" to any >/dev/null $SUDO ufw reload >/dev/null echo "::: UFW configuration completed." @@ -1069,7 +1074,7 @@ confNetwork(){ # Now some checks to detect which rules we need to add. On a newly installed system all policies # should be ACCEPT, so the only required rule would be the MASQUERADE one. - $SUDO iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "$PHYS_INT" -j MASQUERADE + $SUDO iptables -t nat -I POSTROUTING -s "$pivpnNET" -o "$IPv4dev" -j MASQUERADE # Count how many rules are in the INPUT and FORWARD chain. When parsing input from # iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found @@ -1088,15 +1093,15 @@ confNetwork(){ # chain (using -I). if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I INPUT 1 -i "$PHYS_INT" -p "$PROTO" --dport "$PORT" -j ACCEPT + $SUDO iptables -I INPUT 1 -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT INPUT_CHAIN_EDITED=1 else INPUT_CHAIN_EDITED=0 fi if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$PHYS_INT" -o "$pivpnINT" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - $SUDO iptables -I FORWARD 2 -s 10.8.0.0/24 -i "$pivpnINT" -o "$PHYS_INT" -j ACCEPT + $SUDO iptables -I FORWARD 1 -d "$pivpnNET" -i "$IPv4dev" -o "$pivpnDEV" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + $SUDO iptables -I FORWARD 2 -s "$pivpnNET" -i "$pivpnDEV" -o "$IPv4dev" -j ACCEPT FORWARD_CHAIN_EDITED=1 else FORWARD_CHAIN_EDITED=0 diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index 847bcdc..348e7de 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -52,14 +52,14 @@ fi if [ "$USING_UFW" -eq 0 ]; then - if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then iptables -t nat -F - iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${PHYS_INT}" -j MASQUERADE + iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE iptables-save > /etc/iptables/rules.v4 echo "Done" fi @@ -68,13 +68,13 @@ if [ "$USING_UFW" -eq 0 ]; then if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then - if iptables -C INPUT -i "$PHYS_INT" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT &> /dev/null; then + if iptables -C INPUT -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT &> /dev/null; then echo ":: [OK] Iptables INPUT rule set" else ERR=1 read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then - iptables -I INPUT 1 -i "$PHYS_INT" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT + iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT iptables-save > /etc/iptables/rules.v4 echo "Done" fi @@ -83,14 +83,14 @@ if [ "$USING_UFW" -eq 0 ]; then if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$PHYS_INT" -j ACCEPT &> /dev/null; then + if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT &> /dev/null; then echo ":: [OK] Iptables FORWARD rule set" else ERR=1 read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then - iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$PHYS_INT" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$PHYS_INT" -j ACCEPT + iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT iptables-save > /etc/iptables/rules.v4 echo "Done" fi @@ -109,13 +109,13 @@ else fi fi - if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then - sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $PHYS_INT -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules ufw reload echo "Done" fi @@ -147,13 +147,13 @@ else fi fi else - if iptables -C ufw-user-forward -i tun0 -o "${PHYS_INT}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then + if iptables -C ufw-user-forward -i tun0 -o "${IPv4dev}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then echo ":: [OK] Ufw forwarding rule set" else ERR=1 read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then - ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$PHYS_INT" to any + ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any ufw reload echo "Done" fi diff --git a/scripts/wireguard/pivpnDEBUG.sh b/scripts/wireguard/pivpnDEBUG.sh index d339c39..bdd7f3e 100755 --- a/scripts/wireguard/pivpnDEBUG.sh +++ b/scripts/wireguard/pivpnDEBUG.sh @@ -63,14 +63,14 @@ fi if [ "$USING_UFW" -eq 0 ]; then - if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then iptables -t nat -F - iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${PHYS_INT}" -j MASQUERADE + iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE iptables-save > /etc/iptables/rules.v4 iptables-restore < /etc/iptables/rules.v4 echo "Done" @@ -89,13 +89,13 @@ else fi fi - if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${PHYS_INT}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then - sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $PHYS_INT -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules ufw reload echo "Done" fi @@ -113,13 +113,13 @@ else fi fi - if iptables -C ufw-user-forward -i wg0 -o "${PHYS_INT}" -s 10.6.0.0/24 -j ACCEPT &> /dev/null; then + if iptables -C ufw-user-forward -i wg0 -o "${IPv4dev}" -s 10.6.0.0/24 -j ACCEPT &> /dev/null; then echo ":: [OK] Ufw forwarding rule set" else ERR=1 read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]]; then - ufw route insert 1 allow in on wg0 from 10.6.0.0/24 out on "$PHYS_INT" to any + ufw route insert 1 allow in on wg0 from 10.6.0.0/24 out on "$IPv4dev" to any ufw reload echo "Done" fi From e77f668021e1dbd9ef6c064bb5b3fc075754c749 Mon Sep 17 00:00:00 2001 From: Orazio Date: Wed, 16 Oct 2019 18:17:16 +0200 Subject: [PATCH 06/79] Kernel headers are required when installing from package too --- auto_install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 458815d..ff9200c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -559,7 +559,7 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null - PIVPN_DEPS=(wireguard) + PIVPN_DEPS=(raspberrypi-kernel-headers wireguard) installDependentPackages PIVPN_DEPS[@] elif [ "$(uname -m)" = "armv6l" ]; then @@ -1344,7 +1344,7 @@ main(){ askUnattendedUpgrades confUnattendedUpgrades - $SUDO cp /tmp/setupVars.conf /etc/pivpn/setupVars.conf + $SUDO cp /tmp/setupVars.conf "$setupVars" installScripts # Ensure that cached writes reach persistent storage From 84f90b00a490f3f5d42182e19ed0ab35fb59f72a Mon Sep 17 00:00:00 2001 From: Orazio Date: Thu, 7 Nov 2019 17:29:21 +0100 Subject: [PATCH 07/79] Added uninstall and Pi-hole detection --- auto_install/install.sh | 72 +++++++++--- scripts/openvpn/backup.sh | 2 +- scripts/openvpn/makeOVPN.sh | 6 +- scripts/openvpn/pivpn | 2 +- scripts/openvpn/removeOVPN.sh | 16 +-- scripts/openvpn/update.sh | 12 +- scripts/uninstall.sh | 197 ++++++++++++++++++++++++++++++++ scripts/wireguard/qrcodeCONF.sh | 2 +- scripts/wireguard/removeCONF.sh | 8 +- 9 files changed, 275 insertions(+), 42 deletions(-) create mode 100755 scripts/uninstall.sh diff --git a/auto_install/install.sh b/auto_install/install.sh index ff9200c..7d00f54 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# PiVPN: Trivial OpenVPN or WireGUard setup and configuration +# PiVPN: Trivial OpenVPN or WireGuard setup and configuration # Easiest setup and mangement of OpenVPN or WireGuard on Raspberry Pi # http://pivpn.io # Heavily adapted from the pi-hole.net project and... @@ -20,7 +20,12 @@ PKG_CACHE="/var/lib/apt/lists/" UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" +# Dependencies that are required by the script, regardless of the VPN protocol chosen BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools dhcpcd5) +# Dependencies that where actually installed by the script. For example if the script requires +# grep and dnsutils but dnsutils is already installed, we save grep here. This way when uninstalling +# PiVPN we won't prompt to remove packages that may have been installed by the user for other reasons +TO_INSTALL=() pivpnGitUrl="https://github.com/orazioedoardo/pivpn.git" easyrsaVer="3.0.6" @@ -30,7 +35,7 @@ easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer} UNATTUPG_RELEASE="1.14" UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_RELEASE}.tar.gz" -WG_SNAPSHOT="0.0.20190913" +WG_SNAPSHOT="0.0.20191012" WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" # Find the rows and columns. Will default to 80x24 if it can not be detected. @@ -212,10 +217,6 @@ notifyPackageUpdatesAvailable(){ fi } -packageCheckInstall(){ - dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" -} - preconfigurePackages(){ # Add support for https repositories if there are any that use it otherwise the installation will silently fail if grep -q https /etc/apt/sources.list; then @@ -236,14 +237,20 @@ installDependentPackages(){ # No spinner - conflicts with set -e declare -a argArray1=("${!1}") + for i in "${argArray1[@]}"; do + echo -n "::: Checking for $i..." + if dpkg-query -W -f='${Status}' "${i}" 2>/dev/null | grep -q "ok installed"; then + echo " installed!" + else + TO_INSTALL+=("${i}") + echo " not installed!" + fi + done + if command -v debconf-apt-progress &> /dev/null; then $SUDO debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" else - for i in "${argArray1[@]}"; do - echo -n "::: Checking for $i..." - $SUDO packageCheckInstall "${i}" &> /dev/null - echo " installed!" - done + ${PKG_INSTALL} "${argArray1[@]}" fi } @@ -301,8 +308,8 @@ chooseInterface(){ } avoidStaticIPv4Ubuntu() { - # If we are in Ubuntu then they need to have previously set their network, so just use what you have. - whiptail --msgbox --backtitle "IP Information" --title "IP Information" "Since we think you are not using Raspbian, we will not configure a static IP for you. + # If we are in Ubuntu then they need to have previously set their network, so just use what you have. + whiptail --msgbox --backtitle "IP Information" --title "IP Information" "Since we think you are not using Raspbian, we will not configure a static IP for you. If you are in Amazon then you can not configure a static IP anyway. Just ensure before this installer started you had set an elastic IP on your instance." ${r} ${c} } @@ -559,13 +566,13 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null - PIVPN_DEPS=(raspberrypi-kernel-headers wireguard) + PIVPN_DEPS=(raspberrypi-kernel-headers wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] elif [ "$(uname -m)" = "armv6l" ]; then echo "::: Installing WireGuard from source... " - PIVPN_DEPS=(libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode) + PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode) installDependentPackages PIVPN_DEPS[@] # Delete any leftover code @@ -591,8 +598,12 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null exit 1 fi + # Use checkinstall to install userspace tools so if the user wants to uninstall + # PiVPN we can just do apt remove wireguard-tools, instead of manually removing + # files from the file system echo "::: Installing WireGuard tools... " - if $SUDO make install tools; then + if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_SNAPSHOT}" -y make tools-install; then + TO_INSTALL+=("wireguard-tools") echo "done!" else echo "failed!" @@ -619,6 +630,7 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null echo "::: Installing WireGuard modules via DKMS... " if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then + TO_INSTALL+=("wireguard-dkms") echo "done!" else echo "failed!" @@ -628,12 +640,14 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null elif [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "i686" ]; then + echo "::: Installing WireGuard from Debian package... " + echo "::: Adding Debian repository... " echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null echo "Package: * Pin: release a=unstable Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO ${UPDATE_PKG_CACHE} &> /dev/null - PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard) + PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] fi @@ -726,7 +740,25 @@ askCustomPort(){ echo "pivpnPORT=${pivpnPORT}" >> /tmp/setupVars.conf } -askClientDNS() { +askClientDNS(){ + + # Detect and offer to use Pi-hole + if command -v pihole &>/dev/null; then + if (whiptail --backtitle "Setup PiVPN" --title "Pi-hole" --yesno "We have detected a Pi-hole installation, do you want to use it as the DNS server for the VPN, so you get ad blocking on the go?" ${r} ${c}); then + if [ "$VPN" = "WireGuard" ]; then + pivpnDEV="wg0" + elif [ "$VPN" = "OpenVPN" ]; then + pivpnDEV="tun0" + fi + + pivpnDNS1="$IPv4addr" + echo "interface=$pivpnDNS" | $SUDO tee /etc/dnsmasq.d/02-pivpn.conf > /dev/null + $SUDO pihole restartdns + echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf + return + fi + fi + DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients (press space to select). To use your own, select Custom." ${r} ${c} 6) DNSChooseOptions=(Google "" on OpenDNS "" off @@ -799,6 +831,7 @@ askClientDNS() { exit 1 fi + echo "USING_PIHOLE=${USING_PIHOLE}" >> /tmp/setupVars.conf echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf } @@ -1221,6 +1254,7 @@ installScripts(){ fi FOLDER=$(tr '[:upper:]' '[:lower:]' <<< "$VPN") + $SUDO cp /etc/.pivpn/scripts/uninstall.sh /opt/pivpn/ $SUDO cp /etc/.pivpn/scripts/$FOLDER/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh $SUDO cp /etc/.pivpn/scripts/$FOLDER/pivpn /usr/local/bin/pivpn @@ -1344,6 +1378,8 @@ main(){ askUnattendedUpgrades confUnattendedUpgrades + echo "TO_INSTALL=(${TO_INSTALL[*]})" >> /tmp/setupVars.conf + $SUDO cp /tmp/setupVars.conf "$setupVars" installScripts diff --git a/scripts/openvpn/backup.sh b/scripts/openvpn/backup.sh index 8ef6006..2bed93c 100755 --- a/scripts/openvpn/backup.sh +++ b/scripts/openvpn/backup.sh @@ -19,7 +19,7 @@ backup_openvpn(){ cp -r $openvpndir $ovpnsdir $backupdir 2&>1 backupzip=$date-pivpnbackup.tgz tar -czf $backupzip -C ${install_home} $backupdir 2&>1 - echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" + echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" } diff --git a/scripts/openvpn/makeOVPN.sh b/scripts/openvpn/makeOVPN.sh index e0c8891..d37769c 100755 --- a/scripts/openvpn/makeOVPN.sh +++ b/scripts/openvpn/makeOVPN.sh @@ -36,7 +36,7 @@ helpFunc() { if [ -z "$HELP_SHOWN" ]; then helpFunc echo - echo "HELP_SHOWN=1" >> "$setupVars" + echo "HELP_SHOWN=1" >> "$setupVars" fi # Parse input arguments @@ -351,9 +351,9 @@ if [ "$iOS" = "1" ]; then fi } > "${NAME}${FILEEXT}" - + # Copy the .ovpn profile to the home directory for convenient remote access - + printf "========================================================\n" printf "Generating an .ovpn12 file for use with iOS devices\n" printf "Please remember the export password\n" diff --git a/scripts/openvpn/pivpn b/scripts/openvpn/pivpn index de55586..4d2317c 100755 --- a/scripts/openvpn/pivpn +++ b/scripts/openvpn/pivpn @@ -62,7 +62,7 @@ function update { function backup { - $SUDO /opt/pivpn/backup.sh + $SUDO /opt/pivpn/backup.sh exit 0 } diff --git a/scripts/openvpn/removeOVPN.sh b/scripts/openvpn/removeOVPN.sh index 86457c2..f191eab 100755 --- a/scripts/openvpn/removeOVPN.sh +++ b/scripts/openvpn/removeOVPN.sh @@ -46,7 +46,7 @@ fi if [[ -z "${CERTS_TO_REVOKE}" ]]; then printf "\n" printf " ::\e[4m Certificate List \e[0m:: \n" - + i=0 while read -r line || [ -n "$line" ]; do STATUS=$(echo "$line" | awk '{print $1}') @@ -61,26 +61,26 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then fi done <${INDEX} printf "\n" - + echo -n "::: Please enter the Name of the client to be revoked from the list above: " read -r NAME - + if [[ -z "${NAME}" ]]; then echo "You can not leave this blank!" exit 1 fi - + for((x=1;x<=i;++x)); do if [ "${CERTS[$x]}" = "${NAME}" ]; then VALID=1 fi done - + if [ -z "${VALID}" ]; then printf "You didn't enter a valid cert name!\n" exit 1 fi - + CERTS_TO_REVOKE=( "${NAME}" ) else i=0 @@ -92,7 +92,7 @@ else let i=i+1 fi done <${INDEX} - + for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do VALID=0 for((x=1;x<=i;++x)); do @@ -100,7 +100,7 @@ else VALID=1 fi done - + if [ "${VALID}" != 1 ]; then printf "You passed an invalid cert name: '"%s"'!\n" "${CERTS_TO_REVOKE[ii]}" exit 1 diff --git a/scripts/openvpn/update.sh b/scripts/openvpn/update.sh index fb74450..eac73d5 100755 --- a/scripts/openvpn/update.sh +++ b/scripts/openvpn/update.sh @@ -1,4 +1,4 @@ -#/bin/bash +#!/bin/bash ###Updates pivpn scripts (Not PiVPN) ###Main Vars @@ -11,7 +11,7 @@ bashcompletiondir="/etc/bash_completion.d/pivpn" ###Functions ##Updates scripts updatepivpnscripts(){ - ##We don't know what sort of changes users have made. + ##We don't know what sort of changes users have made. ##Lets remove first /etc/.pivpn dir then clone it back again echo "going do update PiVPN Scripts" if [[ -d $pivpnlocalpath ]]; then @@ -25,9 +25,9 @@ updatepivpnscripts(){ echo "PiVPN Scripts have been updated" } -##Updates scripts using test branch +##Updates scripts using test branch updatefromtest(){ - ##We don't know what sort of changes users have made. + ##We don't know what sort of changes users have made. ##Lets remove first /etc/.pivpn dir then clone it back again echo "PiVPN Scripts updating from test branch" if [[ -d /etc/.pivpn ]]; then @@ -89,8 +89,8 @@ else scriptusage exit 0 ;; - * ) - updatepivpnscripts + * ) + updatepivpnscripts exit 0 ;; esac diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh new file mode 100755 index 0000000..d5fc1a6 --- /dev/null +++ b/scripts/uninstall.sh @@ -0,0 +1,197 @@ +#!/usr/bin/env bash +# PiVPN: Uninstall Script + +PKG_MANAGER="apt-get" +WG_SNAPSHOT="0.0.20191012" +setupVars="/etc/pivpn/setupVars.conf" + +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" + +# Find the rows and columns. Will default to 80x24 if it can not be detected. +screen_size=$(stty size 2>/dev/null || echo 24 80) +rows=$(echo $screen_size | awk '{print $1}') +columns=$(echo $screen_size | awk '{print $2}') + +# Divide by two so the dialogs take up half of the screen, which looks nice. +r=$(( rows / 2 )) +c=$(( columns / 2 )) +# Unless the screen is tiny +r=$(( r < 20 ? 20 : r )) +c=$(( c < 70 ? 70 : c )) + +spinner(){ + local pid=$1 + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" +} + +removeAll(){ + # Stopping and disabling services + echo "::: Stopping and disabling services..." + + if [ "$VPN" = "WireGuard" ]; then + systemctl stop wg-quick@wg0 + systemctl disable wg-quick@wg0 &> /dev/null + elif [ "$VPN" = "OpenVPN" ]; then + systemctl stop openvpn + systemctl disable openvpn &> /dev/null + fi + + # Removing firewall rules. + echo "::: Removing firewall rules..." + + if [ "$VPN" = "WireGuard" ]; then + pivpnDEV="wg0" + pivpnNET="10.6.0.0/24" + elif [ "$VPN" = "OpenVPN" ]; then + pivpnDEV="tun0" + pivpnNET="10.8.0.0/24" + fi + + if [ "$USING_UFW" -eq 1 ]; then + + ufw delete allow "${pivpnPORT}"/udp > /dev/null + ufw route delete allow in on "$pivpnDEV" from "$pivpnNET" out on "${IPv4dev}" to any > /dev/null + sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s 10.6.0.0\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules + ufw reload &> /dev/null + + elif [ "$USING_UFW" -eq 0 ]; then + + if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then + iptables -D INPUT -i "${IPv4dev}" -p udp --dport "${pivpnPORT}" -j ACCEPT + fi + + if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then + iptables -D FORWARD -d "$pivpnNET" -i "${IPv4dev}" -o "$pivpnDEV" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -D FORWARD -s "$pivpnNET" -i "$pivpnDEV" -o "${IPv4dev}" -j ACCEPT + fi + + iptables -t nat -D POSTROUTING -s "$pivpnNET" -o "${IPv4dev}" -j MASQUERADE + iptables-save > /etc/iptables/rules.v4 + + fi + + # Disable IPv4 forwarding + sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf + sysctl -p + + # Purge dependencies + echo "::: Purge dependencies..." + + for i in "${TO_INSTALL[@]}"; do + while true; do + read -rp "::: Do you wish to remove $i from your system? [Y/n]: " yn + case $yn in + [Yy]* ) if [ "${i}" = "wireguard" ]; then + + if [ "$(uname -m)" = "armv7l" ] || [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "i686" ]; then + rm /etc/apt/sources.list.d/unstable.list + rm /etc/apt/preferences.d/limit-unstable + $PKG_MANAGER update &> /dev/null + fi + rm -rf /etc/wireguard + rm -rf $install_home/configs + + elif [ "${i}" = "wireguard-dkms" ]; then + + # If we installed wireguard-dkms and we are on armv6l, then we manually need + # to remove the kernel module and skip the apt uninstallation (since it's not an + # actual package) + if [ "$(uname -m)" = "armv6l" ]; then + dkms remove wireguard/"${WG_SNAPSHOT}" --all + rm -rf /usr/src/wireguard-* + break + fi + + elif [ "${i}" = "dirmngr" ]; then + + # If dirmngr was installed, then we had previously installed wireguard on armv7l + # so we remove the repository keys + apt-key remove E1CF20DDFFE4B89E802658F1E0B11894F66AEC98 80D15823B7FD1561F9F7BCDDDC30D7C23CBBABEE &> /dev/null + + elif [ "${i}" = "openvpn" ]; then + + rm -rf /var/log/*openvpn* + rm -rf /etc/openvpn + rm -rf $install_home/ovpns + + elif [ "${i}" = "unattended-upgrades" ]; then + + rm -rf /var/log/unattended-upgrades + rm -rf /etc/apt/apt.conf.d/*periodic + rm -rf /etc/apt/apt.conf.d/*unattended-upgrades + + fi + printf ":::\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\n"; + break + ;; + [Nn]* ) printf ":::\tSkipping %s\n" "$i"; + break + ;; + * ) printf "::: You must answer yes or no!\n";; + esac + done + done + + # Take care of any additional package cleaning + printf "::: Auto removing remaining dependencies..." + $PKG_MANAGER -y autoremove &> /dev/null & spinner $!; printf "done!\n"; + printf "::: Auto cleaning remaining dependencies..." + $PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\n"; + + echo ":::" + # Removing pivpn files + echo "::: Removing pivpn system files..." + + if [ -f /etc/dnsmasq.d/02-pivpn.conf ]; then + rm /etc/dnsmasq.d/02-pivpn.conf + pihole restartdns + fi + + rm -rf /opt/pivpn + rm -rf /etc/.pivpn + rm -rf /etc/pivpn + rm -rf /var/log/*pivpn* + rm /usr/local/bin/pivpn + rm /etc/bash_completion.d/pivpn + + echo ":::" + printf "::: Finished removing PiVPN from your system.\n" + printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L https://install.pivpn.io | bash\n:::\n::: at any time!\n:::\n" +} + +askreboot(){ + printf "It is \e[1mstrongly\e[0m recommended to reboot after un-installation.\n" + read -p "Would you like to reboot now? [y/n]: " -n 1 -r + echo + if [[ ${REPLY} =~ ^[Yy]$ ]]; then + printf "\nRebooting system...\n" + sleep 3 + shutdown -r now + fi +} + +######### SCRIPT ########### +echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system." +echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" +while true; do + read -rp "::: Do you wish to completely remove PiVPN configuration and installed packages from your system? (You will be prompted for each package) [y/n]: " yn + case $yn in + [Yy]* ) removeAll; askreboot; break;; + + [Nn]* ) printf "::: Not removing anything, exiting...\n"; break;; + esac +done diff --git a/scripts/wireguard/qrcodeCONF.sh b/scripts/wireguard/qrcodeCONF.sh index 40fce8f..0420eb5 100755 --- a/scripts/wireguard/qrcodeCONF.sh +++ b/scripts/wireguard/qrcodeCONF.sh @@ -29,7 +29,7 @@ done cd /etc/wireguard/configs if [ ! -s clients.txt ]; then - echo "::: There are no clients to remove" + echo "::: There are no clients to show" exit 1 fi diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 403da3c..263fde3 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -79,18 +79,18 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do # Then remove the client matching the variables above sed "/${CLIENT_NAME} ${CREATION_DATE} ${COUNT}/d" -i configs/clients.txt - + # Remove the peer section from the server config sed "/# begin ${CLIENT_NAME}/,/# end ${CLIENT_NAME}/d" -i wg0.conf echo "::: Updated server config" - + rm "configs/${CLIENT_NAME}.conf" echo "::: Client config for ${CLIENT_NAME} removed" rm "keys/${CLIENT_NAME}_priv" rm "keys/${CLIENT_NAME}_pub" echo "::: Client Keys for ${CLIENT_NAME} removed" - + # Find all .conf files in the home folder of the user matching the checksum of the # config and delete them. '-maxdepth 3' is used to avoid traversing too many folders. find "${install_home}" -maxdepth 3 -type f -name '*.conf' -print0 | while IFS= read -r -d '' CONFIG; do @@ -108,7 +108,7 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do done # Restart WireGuard only if some clients were actually deleted -if [ "${DELETED_COUNT}" -gt 0 ]; then +if [ "${DELETED_COUNT}" -gt 0 ]; then if systemctl restart wg-quick@wg0; then echo "::: WireGuard restarted" else From 6bd0beeb94af608c5d71aaf4c663cb9a568f248b Mon Sep 17 00:00:00 2001 From: Orazio Date: Thu, 7 Nov 2019 18:12:06 +0100 Subject: [PATCH 08/79] Fixed missing protocol variable --- auto_install/install.sh | 6 +++--- scripts/uninstall.sh | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 7d00f54..b9087cc 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -522,6 +522,7 @@ askWhichVPN(){ if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard of 'No' to use OpenVPN." ${r} ${c}); then VPN="WireGuard" + pivpnPROTO="udp" pivpnDEV="wg0" pivpnNET="10.6.0.0/24" else @@ -831,7 +832,6 @@ askClientDNS(){ exit 1 fi - echo "USING_PIHOLE=${USING_PIHOLE}" >> /tmp/setupVars.conf echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf } @@ -1093,7 +1093,7 @@ confNetwork(){ echo "::: Adding UFW rules..." $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s $pivpnNET -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) - $SUDO ufw insert 1 allow "$PORT"/"$PROTO" >/dev/null + $SUDO ufw insert 1 allow "$pivpnPORT"/"$pivpnPROTO" >/dev/null $SUDO ufw route insert 1 allow in on "$pivpnDEV" from "$pivpnNET" out on "$IPv4dev" to any >/dev/null $SUDO ufw reload >/dev/null @@ -1126,7 +1126,7 @@ confNetwork(){ # chain (using -I). if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I INPUT 1 -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT + $SUDO iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT INPUT_CHAIN_EDITED=1 else INPUT_CHAIN_EDITED=0 diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index d5fc1a6..7027c65 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -56,6 +56,7 @@ removeAll(){ if [ "$VPN" = "WireGuard" ]; then pivpnDEV="wg0" pivpnNET="10.6.0.0/24" + pivpnPROTO="udp" elif [ "$VPN" = "OpenVPN" ]; then pivpnDEV="tun0" pivpnNET="10.8.0.0/24" @@ -63,15 +64,15 @@ removeAll(){ if [ "$USING_UFW" -eq 1 ]; then - ufw delete allow "${pivpnPORT}"/udp > /dev/null + ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null ufw route delete allow in on "$pivpnDEV" from "$pivpnNET" out on "${IPv4dev}" to any > /dev/null - sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s 10.6.0.0\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules + sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules ufw reload &> /dev/null elif [ "$USING_UFW" -eq 0 ]; then if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then - iptables -D INPUT -i "${IPv4dev}" -p udp --dport "${pivpnPORT}" -j ACCEPT + iptables -D INPUT -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT fi if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then From 07abfc97e9ab0c08d630df6dcad8e7d7c8a40135 Mon Sep 17 00:00:00 2001 From: Orazio Date: Thu, 14 Nov 2019 15:07:01 +0100 Subject: [PATCH 09/79] Added unattended installation, fixed some variables --- auto_install/install.sh | 509 ++++++++++++++++++++++++++++++++-------- scripts/uninstall.sh | 22 +- 2 files changed, 418 insertions(+), 113 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index b9087cc..da71a58 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -20,8 +20,10 @@ PKG_CACHE="/var/lib/apt/lists/" UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" + # Dependencies that are required by the script, regardless of the VPN protocol chosen BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools dhcpcd5) + # Dependencies that where actually installed by the script. For example if the script requires # grep and dnsutils but dnsutils is already installed, we save grep here. This way when uninstalling # PiVPN we won't prompt to remove packages that may have been installed by the user for other reasons @@ -43,6 +45,8 @@ screen_size=$(stty size 2>/dev/null || echo 24 80) rows=$(echo $screen_size | awk '{print $1}') columns=$(echo $screen_size | awk '{print $2}') +runUnattended=false + # Divide by two so the dialogs take up half of the screen, which looks nice. r=$(( rows / 2 )) c=$(( columns / 2 )) @@ -51,7 +55,6 @@ r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) # Find IP used to route to outside world -IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') IPv4addr=$(ip route get 8.8.8.8| awk '{print $7}') IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') @@ -60,13 +63,26 @@ dhcpcdFile=/etc/dhcpcd.conf # Next see if we are on a tested and supported OS noOSSupport(){ + if [ "${runUnattended}" = 'true' ]; then + echo "::: Invalid OS detected" + echo "::: We have not been able to detect a supported OS." + echo "::: Currently this installer supports Raspbian (Buster) and Debian (Buster)." + exit 1 + fi + whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS. -Currently this installer supports Raspbian (Buster). +Currently this installer supports Raspbian (Buster) and Debian (Buster). If you think you received this message in error, you can post an issue on the GitHub at https://github.com/pivpn/pivpn/issues." ${r} ${c} exit 1 } maybeOSSupport(){ + if [ "${runUnattended}" = 'true' ]; then + echo "::: Not Supported OS" + echo "::: You are on an OS that we have not tested but MAY work, continuing anyway..." + return + fi + if (whiptail --backtitle "Not Supported OS" --title "Not Supported OS" --yesno "You are on an OS that we have not tested but MAY work. Currently this installer supports Raspbian (Buster). Would you like to continue anyway?" ${r} ${c}) then @@ -118,6 +134,12 @@ checkHostname(){ ###Checks for hostname size host_name=$(hostname -s) if [[ ! ${#host_name} -le 28 ]]; then + if [ "${runUnattended}" = 'true' ]; then + echo "::: Your hostname is too long." + echo "::: Use 'hostnamectl set-hostname YOURHOSTNAME' to set a new hostname" + echo "::: It must be less then 28 characters long and it must not use special characters" + exit 1 + fi until [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; do host_name=$(whiptail --inputbox "Your hostname is too long.\nEnter new hostname with less then 28 characters\nNo special characters allowed." \ --title "Hostname too long" ${r} ${c} 3>&1 1>&2 2>&3) @@ -156,6 +178,9 @@ verifyFreeDiskSpace(){ if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then echo "::: Unknown free disk space!" echo "::: We were unable to determine available free disk space on this system." + if [ "${runUnattended}" = 'true' ]; then + exit 1 + fi echo "::: You may continue with the installation, however, it is not recommended." read -r -p "::: If you are sure you want to continue, type YES and press enter :: " response case $response in @@ -255,6 +280,13 @@ installDependentPackages(){ } welcomeDialogs(){ + if [ "${runUnattended}" = 'true' ]; then + echo "::: PiVPN Automated Installer" + echo "::: This installer will transform your Raspberry Pi into an OpenVPN or WireGuard server!" + echo "::: Initiating network interface" + return + fi + # Display the welcome dialog whiptail --msgbox --backtitle "Welcome" --title "PiVPN Automated Installer" "This installer will transform your Raspberry Pi into an OpenVPN or WireGuard server!" ${r} ${c} @@ -265,6 +297,27 @@ In the next section, you can choose to use your current network settings (DHCP) } chooseInterface(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$IPv4dev" ]; then + if [ "$(echo "${availableInterfaces}" | wc -l)" -eq 1 ]; then + IPv4dev="${availableInterfaces}" + echo "::: No interface specified, but only ${IPv4dev} is available, using it" + else + echo "::: No interface specified" + exit 1 + fi + else + if ip -o link | grep -qw "${IPv4dev}"; then + echo "::: Using interface: ${IPv4dev}" + else + echo "::: Interface ${IPv4dev} does not exist" + exit 1 + fi + fi + echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + return + fi + # Turn the available interfaces into an array so it can be used with a whiptail dialog local interfacesArray=() # Number of available interfaces @@ -308,15 +361,82 @@ chooseInterface(){ } avoidStaticIPv4Ubuntu() { + if [ "${runUnattended}" = 'true' ]; then + echo "::: Since we think you are not using Raspbian, we will not configure a static IP for you." + return + fi + # If we are in Ubuntu then they need to have previously set their network, so just use what you have. whiptail --msgbox --backtitle "IP Information" --title "IP Information" "Since we think you are not using Raspbian, we will not configure a static IP for you. If you are in Amazon then you can not configure a static IP anyway. Just ensure before this installer started you had set an elastic IP on your instance." ${r} ${c} + +} + +validIP(){ + local ip=$1 + local stat=1 + + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ + && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + stat=$? + fi + return $stat } getStaticIPv4Settings() { - local ipSettingsCorrect # Grab their current DNS Server - IPv4dns=$(nslookup 127.0.0.1 | grep Server: | awk '{print $2}') + IPv4dns=$(grep nameserver /etc/resolv.conf | awk '{print $2}' | xargs) + + if [ "${runUnattended}" = 'true' ]; then + + local INVALID_STATIC_IPV4_SETTINGS=0 + + if [ -z "$IPv4addr" ]; then + echo "::: Missing static IP address" + INVALID_STATIC_IPV4_SETTINGS=1 + fi + + if [ -z "$IPv4gw" ]; then + echo "::: Missing static IP gateway" + INVALID_STATIC_IPV4_SETTINGS=1 + fi + + if [ "$INVALID_STATIC_IPV4_SETTINGS" -eq 1 ]; then + echo "::: Incomplete static IP settings" + exit 1 + fi + + if [ -z "$IPv4addr" ] && [ -z "$IPv4gw" ]; then + echo "::: No static IP settings, using current settings" + echo "::: Your static IPv4 address: ${IPv4addr}" + echo "::: Your static IPv4 gateway: ${IPv4gw}" + else + if validIP "${IPv4addr%/*}"; then + echo "::: Your static IPv4 address: ${IPv4addr}" + else + echo "::: ${IPv4addr%/*} is not a valid IP address" + exit 1 + fi + + if validIP "${IPv4gw}"; then + echo "::: Your static IPv4 gateway: ${IPv4gw}" + else + echo "::: ${IPv4gw} is not a valid IP address" + exit 1 + fi + fi + + echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + return + fi + + local ipSettingsCorrect # Ask if the user wants to use DHCP settings as their static IP if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? IP address: ${IPv4addr} @@ -399,6 +519,30 @@ setStaticIPv4(){ } chooseUser(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$install_user" ]; then + if [ "$(awk -F':' 'BEGIN {count=0} $3>=1000 && $3<=60000 { count++ } END{ print count }' /etc/passwd)" -eq 1 ]; then + install_user="$(awk -F':' '$3>=1000 && $3<=60000 {print $1}' /etc/passwd)" + echo "::: No user specified, but only ${install_user} is available, using it" + else + echo "::: No user specified" + exit 1 + fi + else + if awk -F':' '$3>=1000 && $3<=60000 {print $1}' /etc/passwd | grep -qw "${install_user}"; then + echo "::: ${install_user} will hold your ovpn configurations." + else + echo "::: User ${install_user} does not exist" + exit 1 + fi + fi + install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6) + install_home=${install_home%/} + echo "install_user=${install_user}" >> /tmp/setupVars.conf + echo "install_home=${install_home}" >> /tmp/setupVars.conf + return + fi + # Explain the local user whiptail --msgbox --backtitle "Parsing User List" --title "Local Users" "Choose a local user that will hold your ovpn configurations." ${r} ${c} # First, let's check if there is a user available. @@ -519,16 +663,37 @@ cloneOrUpdateRepos(){ } askWhichVPN(){ - if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard of 'No' to use OpenVPN." ${r} ${c}); - then - VPN="WireGuard" + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$VPN" ]; then + echo ":: No VPN protocol specified, using WireGuard" + VPN="wireguard" + else + VPN="${VPN,,}" + if [ "$VPN" = "wireguard" ]; then + echo "::: WireGuard will be installed" + elif [ "$VPN" = "openvpn" ]; then + echo "::: OpenVPN will be installed" + else + echo ":: $VPN is not a supported VPN protocol, please specify 'wireguard' or 'openvpn'" + exit 1 + fi + fi + else + if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard of 'No' to use OpenVPN." ${r} ${c}); + then + VPN="wireguard" + else + VPN="openvpn" + fi + fi + + if [ "$VPN" = "wireguard" ]; then pivpnPROTO="udp" pivpnDEV="wg0" - pivpnNET="10.6.0.0/24" - else - VPN="OpenVPN" + pivpnNET="10.6.0.0" + elif [ "$VPN" = "openvpn" ]; then pivpnDEV="tun0" - pivpnNET="10.8.0.0/24" + pivpnNET="10.8.0.0" fi echo "VPN=${VPN}" >> /tmp/setupVars.conf @@ -654,42 +819,32 @@ Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null fi } -validIP(){ - local ip=$1 - local stat=1 - - if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - OIFS=$IFS - IFS='.' - ip=($ip) - IFS=$OIFS - [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ - && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] - stat=$? - fi - return $stat -} - -#Call this function to use a regex to check user input for a valid custom domain -validDomain(){ - local domain=$1 - local stat=1 - - if [[ $domain =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}\.[a-zA-Z]{2,}$ ]]; then - stat=$? - fi - return $stat -} - askCustomProto(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$pivpnPROTO" ]; then + echo "::: No TCP/IP protocol specified, using the default protocol udp" + pivpnPROTO="udp" + else + pivpnPROTO="${pivpnPROTO,,}" + if [ "$pivpnPROTO" = "udp" ] || [ "$pivpnPROTO" = "tcp" ]; then + echo "::: Using the $pivpnPROTO protocol" + else + echo ":: $pivpnPROTO is not a supported TCP/IP protocol, please specify 'udp' or 'tcp'" + exit 1 + fi + fi + echo "pivpnPROTO=${pivpnPROTO}" >> /tmp/setupVars.conf + return + fi + # Set the available protocols into an array so it can be used with a whiptail dialog - if protocol=$(whiptail --title "Protocol" --radiolist \ + if pivpnPROTO=$(whiptail --title "Protocol" --radiolist \ "Choose a protocol (press space to select). Please only choose TCP if you know why you need TCP." ${r} ${c} 2 \ "UDP" "" ON \ "TCP" "" OFF 3>&1 1>&2 2>&3) then # Convert option into lowercase (UDP->udp) - pivpnPROTO="${protocol,,}" + pivpnPROTO="${pivpnPROTO,,}" echo "::: Using protocol: $pivpnPROTO" echo "pivpnPROTO=${pivpnPROTO}" >> /tmp/setupVars.conf else @@ -699,13 +854,39 @@ askCustomProto(){ } askCustomPort(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$pivpnPORT" ]; then + if [ "$VPN" = "wireguard" ]; then + echo "::: No port specified, using the default port 51820" + pivpnPORT=51820 + elif [ "$VPN" = "openvpn" ]; then + if [ "$pivpnPROTO" = "udp" ]; then + echo "::: No port specified, using the default port 1194" + pivpnPORT=1194 + elif [ "$pivpnPROTO" = "tcp" ]; then + echo "::: No port specified, using the default port 443" + pivpnPORT=443 + fi + fi + else + if [[ "$pivpnPORT" =~ ^[0-9]+$ ]] && [ "$pivpnPORT" -ge 1 ] && [ "$pivpnPORT" -le 65535 ]; then + echo "::: Using port $pivpnPORT" + else + echo "::: $pivpnPORT is not a valid port, use a port within the range [1,65535] (inclusive)" + exit 1 + fi + fi + echo "pivpnPORT=${pivpnPORT}" >> /tmp/setupVars.conf + return + fi + until [[ $PORTNumCorrect = True ]] do portInvalid="Invalid" - if [ "$VPN" = "WireGuard" ]; then + if [ "$VPN" = "wireguard" ]; then DEFAULT_PORT=51820 - elif [ "$VPN" = "OpenVPN" ]; then + elif [ "$VPN" = "openvpn" ]; then if [ "$pivpnPROTO" = "udp" ]; then DEFAULT_PORT=1194 else @@ -742,20 +923,48 @@ askCustomPort(){ } askClientDNS(){ + if [ "${runUnattended}" = 'true' ]; then + + if [ -z "$pivpnDNS1" ] && [ -n "$pivpnDNS2" ]; then + pivpnDNS1="$pivpnDNS2" + unset pivpnDNS2 + elif [ -z "$pivpnDNS1" ] && [ -z "$pivpnDNS2" ]; then + pivpnDNS1="8.8.8.8" + pivpnDNS2="8.8.4.4" + echo "::: No DNS provider specified, using Google DNS ($pivpnDNS1 $pivpnDNS2)" + fi + + local INVALID_DNS_SETTINGS=0 + + if ! validIP "$pivpnDNS1"; then + INVALID_DNS_SETTINGS=1 + echo "::: Invalid DNS $pivpnDNS1" + fi + + if [ -n "$pivpnDNS2" ] && ! validIP "$pivpnDNS2"; then + INVALID_DNS_SETTINGS=1 + echo "::: Invalid DNS $pivpnDNS2" + fi + + if [ "$INVALID_DNS_SETTINGS" -eq 0 ]; then + echo "::: Using DNS $pivpnDNS1 $pivpnDNS2" + else + exit 1 + fi + + echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf + echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf + return + fi # Detect and offer to use Pi-hole if command -v pihole &>/dev/null; then if (whiptail --backtitle "Setup PiVPN" --title "Pi-hole" --yesno "We have detected a Pi-hole installation, do you want to use it as the DNS server for the VPN, so you get ad blocking on the go?" ${r} ${c}); then - if [ "$VPN" = "WireGuard" ]; then - pivpnDEV="wg0" - elif [ "$VPN" = "OpenVPN" ]; then - pivpnDEV="tun0" - fi - pivpnDNS1="$IPv4addr" - echo "interface=$pivpnDNS" | $SUDO tee /etc/dnsmasq.d/02-pivpn.conf > /dev/null + echo "interface=$pivpnDEV" | $SUDO tee /etc/dnsmasq.d/02-pivpn.conf > /dev/null $SUDO pihole restartdns echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf + echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf return fi fi @@ -836,8 +1045,34 @@ askClientDNS(){ echo "pivpnDNS2=${pivpnDNS2}" >> /tmp/setupVars.conf } +#Call this function to use a regex to check user input for a valid custom domain +validDomain(){ + local domain=$1 + local stat=1 + + if [[ $domain =~ ^(([a-zA-Z0-9]{1,63}|([a-zA-Z0-9]{1,60}[-a-zA-Z0-9()]{0,2}[a-zA-Z0-9]{1,60}))\.){1,6}([a-zA-Z]{2,})$ ]]; then + stat=$? + fi + return $stat +} + #This procedure allows a user to specify a custom search domain if they have one. askCustomDomain(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -n "$pivpnDOMAIN" ]; then + if validDomain "$pivpnDOMAIN"; then + echo "::: Using custom domain $pivpnDOMAIN" + else + echo "::: Custom domain $pivpnDOMAIN is not valid" + exit 1 + fi + else + echo "::: Skipping custom domain" + fi + echo "pivpnDOMAIN=${pivpnDOMAIN}" >> /tmp/setupVars.conf + return + fi + DomainSettingsCorrect=False if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Would you like to add a custom search domain? \n (This is only for advanced users who have their own domain)\n" ${r} ${c}); then @@ -848,7 +1083,6 @@ askCustomDomain(){ if validDomain "$pivpnDOMAIN"; then if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\n Custom Search Domain: $pivpnDOMAIN" ${r} ${c}); then DomainSettingsCorrect=True - echo "pivpnDOMAIN=${pivpnDOMAIN}" >> /tmp/setupVars.conf else # If the settings are wrong, the loop continues DomainSettingsCorrect=False @@ -862,10 +1096,9 @@ askCustomDomain(){ exit 1 fi done - - else - echo sleep 0.1 fi + + echo "pivpnDOMAIN=${pivpnDOMAIN}" >> /tmp/setupVars.conf } askPublicIPOrDNS(){ @@ -877,6 +1110,24 @@ askPublicIPOrDNS(){ fi fi + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$pivpnHOST" ]; then + echo "::: No IP or domain name specified, using public IP $IPv4pub" + pivpnHOST="$IPv4pub" + else + if validIP "$pivpnHOST"; then + echo "::: Using public IP $pivpnHOST" + elif validDomain "$pivpnHOST"; then + echo "::: Using domain name $pivpnHOST" + else + echo "::: $pivpnHOST is not a valid IP or domain name" + exit 1 + fi + fi + echo "pivpnHOST=${pivpnHOST}" >> /tmp/setupVars.conf + return + fi + METH=$(whiptail --title "Public IP or DNS" --radiolist "Will clients use a Public IP or DNS Name to connect to your server (press space to select)?" ${r} ${c} 2 \ "$IPv4pub" "Use this public IP" "ON" \ "DNS Entry" "Use a public DNS" "OFF" 3>&1 1>&2 2>&3) @@ -911,6 +1162,28 @@ askPublicIPOrDNS(){ } askEncryption(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$pivpnENCRYPT" ]; then + pivpnENCRYPT=2048 + echo "::: Using a 2048 bit certificate" + else + if [ "$pivpnENCRYPT" -eq 2048 ] || [ "$pivpnENCRYPT" -eq 3072 ] || [ "$pivpnENCRYPT" -eq 4096 ]; then + echo "::: Using a ${pivpnENCRYPT}-bit certificate" + else + echo "::: ${pivpnENCRYPT} is not a valid certificate size, use 2048, 3072, or 4096" + exit 1 + fi + fi + + if [ -n "$DOWNLOAD_DH_PARAM" ]; then + echo "::: DH parameters will be downloaded from \"2 Ton Digital\"" + fi + + echo "pivpnENCRYPT=${pivpnENCRYPT}" >> /tmp/setupVars.conf + echo "DOWNLOAD_DH_PARAM=${DOWNLOAD_DH_PARAM}" >> /tmp/setupVars.conf + return + fi + pivpnENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "RSA certificate size" --radiolist \ "Choose the desired size of your certificate (press space to select):\nThis is a certificate that will be generated on your system. The larger the certificate, the more time this will take. For most applications, it is recommended to use 2048 bits. If you are paranoid about ... things... then grab a cup of joe and pick 4096 bits." ${r} ${c} 3 \ "2048" "Use a 2048-bit certificate (recommended level)" ON \ @@ -1020,6 +1293,10 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null $SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf fi + if [ -z "$pivpnDOMAIN" ]; then + $SUDO sed -i "0,/\(.*dhcp-option.*\)/s//\push \"dhcp-option DOMAIN ${pivpnDOMAIN}\" \n&/" /etc/openvpn/server.conf + fi + # write out server certs to conf file $SUDO sed -i "s/\(key \/etc\/openvpn\/easy-rsa\/pki\/private\/\).*/\1${SERVER_NAME}.key/" /etc/openvpn/server.conf $SUDO sed -i "s/\(cert \/etc\/openvpn\/easy-rsa\/pki\/issued\/\).*/\1${SERVER_NAME}.crt/" /etc/openvpn/server.conf @@ -1058,7 +1335,10 @@ confWireGuard(){ $SUDO chmod 700 /etc/wireguard fi - whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" + if [ "${runUnattended}" = 'false' ]; then + whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" + return + fi $SUDO mkdir /etc/wireguard/configs $SUDO touch /etc/wireguard/configs/clients.txt $SUDO mkdir /etc/wireguard/keys @@ -1091,10 +1371,10 @@ confNetwork(){ USING_UFW=1 echo "::: Detected UFW is enabled." echo "::: Adding UFW rules..." - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s $pivpnNET -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) - $SUDO ufw insert 1 allow "$pivpnPORT"/"$pivpnPROTO" >/dev/null - $SUDO ufw route insert 1 allow in on "$pivpnDEV" from "$pivpnNET" out on "$IPv4dev" to any >/dev/null + $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null + $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any >/dev/null $SUDO ufw reload >/dev/null echo "::: UFW configuration completed." @@ -1107,7 +1387,7 @@ confNetwork(){ # Now some checks to detect which rules we need to add. On a newly installed system all policies # should be ACCEPT, so the only required rule would be the MASQUERADE one. - $SUDO iptables -t nat -I POSTROUTING -s "$pivpnNET" -o "$IPv4dev" -j MASQUERADE + $SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE # Count how many rules are in the INPUT and FORWARD chain. When parsing input from # iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found @@ -1126,15 +1406,15 @@ confNetwork(){ # chain (using -I). if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT + $SUDO iptables -I INPUT 1 -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT INPUT_CHAIN_EDITED=1 else INPUT_CHAIN_EDITED=0 fi if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I FORWARD 1 -d "$pivpnNET" -i "$IPv4dev" -o "$pivpnDEV" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - $SUDO iptables -I FORWARD 2 -s "$pivpnNET" -i "$pivpnDEV" -o "$IPv4dev" -j ACCEPT + $SUDO iptables -I FORWARD 1 -d "${pivpnNET}/24" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + $SUDO iptables -I FORWARD 2 -s "${pivpnNET}/24" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT FORWARD_CHAIN_EDITED=1 else FORWARD_CHAIN_EDITED=0 @@ -1183,7 +1463,7 @@ installPiVPN(){ $SUDO mkdir -p /etc/pivpn/ askWhichVPN - if [ "$VPN" = "OpenVPN" ]; then + if [ "$VPN" = "openvpn" ]; then installOpenVPN askCustomProto askCustomPort @@ -1195,7 +1475,7 @@ installPiVPN(){ confOVPN confNetwork confLogging - elif [ "$VPN" = "WireGuard" ]; then + elif [ "$VPN" = "wireguard" ]; then installWireGuard askCustomPort askClientDNS @@ -1206,12 +1486,25 @@ installPiVPN(){ } askUnattendedUpgrades(){ + if [ "${runUnattended}" = 'true' ]; then + if [ -z "$UNATTUPG" ]; then + UNATTUPG=1 + echo "::: No preference regarding unattended upgrades, assuming yes" + else + if [ "$UNATTUPG" -eq 1 ]; then + echo "::: Enabling unattended upgrades" + else + echo "::: Skipping unattended upgrades" + fi + fi + echo "UNATTUPG=${UNATTUPG}" >> /tmp/setupVars.conf + return + fi + whiptail --msgbox --backtitle "Security Updates" --title "Unattended Upgrades" "Since this server will have at least one port open to the internet, it is recommended you enable unattended-upgrades.\nThis feature will check daily for security package updates only and apply them when necessary.\nIt will NOT automatically reboot the server so to fully apply some updates you should periodically reboot." ${r} ${c} if (whiptail --backtitle "Security Updates" --title "Unattended Upgrades" --yesno "Do you want to enable unattended upgrades of security patches to this server?" ${r} ${c}); then UNATTUPG=1 - PIVPN_DEPS=(unattended-upgrades) - installDependentPackages PIVPN_DEPS[@] else UNATTUPG=0 fi @@ -1220,27 +1513,32 @@ askUnattendedUpgrades(){ } confUnattendedUpgrades(){ - cd /etc/apt/apt.conf.d + if [ "$UNATTUPG" -eq 1 ]; then + PIVPN_DEPS=(unattended-upgrades) + installDependentPackages PIVPN_DEPS[@] - if [ "$PLAT" = "Raspbian" ]; then - wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz - $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades - $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" + cd /etc/apt/apt.conf.d + + if [ "$PLAT" = "Raspbian" ]; then + wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz + $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades + $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" + fi + + # On architectures different from armv6l, where we install wireguard from source, enable + # automatic updates via the unstable repository + if [ "$VPN" = "wireguard" ] && [ "$(uname -m)" != "armv6l" ]; then + $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades + fi + + # Add the remaining settings for all other distributions + echo "APT::Periodic::Enable \"1\"; + APT::Periodic::Update-Package-Lists \"1\"; + APT::Periodic::Download-Upgradeable-Packages \"1\"; + APT::Periodic::Unattended-Upgrade \"1\"; + APT::Periodic::AutocleanInterval \"7\"; + APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null fi - - # On architectures different from armv6l, where we install wireguard from source, enable - # automatic updates via the unstable repository - if [ "$VPN" = "WireGuard" ] && [ "$(uname -m)" != "armv6l" ]; then - $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades - fi - - # Add the remaining settings for all other distributions - echo "APT::Periodic::Enable \"1\"; - APT::Periodic::Update-Package-Lists \"1\"; - APT::Periodic::Download-Upgradeable-Packages \"1\"; - APT::Periodic::Unattended-Upgrade \"1\"; - APT::Periodic::AutocleanInterval \"7\"; - APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null } installScripts(){ @@ -1253,18 +1551,26 @@ installScripts(){ $SUDO chmod 0755 /opt/pivpn fi - FOLDER=$(tr '[:upper:]' '[:lower:]' <<< "$VPN") $SUDO cp /etc/.pivpn/scripts/uninstall.sh /opt/pivpn/ - $SUDO cp /etc/.pivpn/scripts/$FOLDER/*.sh /opt/pivpn/ + $SUDO cp /etc/.pivpn/scripts/$VPN/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh - $SUDO cp /etc/.pivpn/scripts/$FOLDER/pivpn /usr/local/bin/pivpn + $SUDO cp /etc/.pivpn/scripts/$VPN/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn - $SUDO cp /etc/.pivpn/scripts/$FOLDER/bash-completion /etc/bash_completion.d/pivpn + $SUDO cp /etc/.pivpn/scripts/$VPN/bash-completion /etc/bash_completion.d/pivpn . /etc/bash_completion.d/pivpn echo " done." } displayFinalMessage(){ + if [ "${runUnattended}" = 'true' ]; then + echo "::: Installation Complete!" + echo "::: Now run 'pivpn add' to create the ovpn profiles. +Run 'pivpn help' to see what else you can do!\n\nIf you run into any issue, please read all our documentation carefully. +All incomplete posts or bug reports will be ignored or deleted.\n\nThank you for using PiVPN." + echo "::: It is strongly recommended you reboot after installation." + return + fi + # Final completion message to user whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles. Run 'pivpn help' to see what else you can do!\n\nIf you run into any issue, please read all our documentation carefully. @@ -1299,12 +1605,6 @@ main(){ fi fi - # Check for supported distribution - distroCheck - - # Checks for hostname Length - checkHostname - # Check arguments for the undocumented flags for var in "$@"; do case "$var" in @@ -1313,8 +1613,19 @@ main(){ esac done + # Check for supported distribution + distroCheck + + # Checks for hostname Length + checkHostname + if [[ "${runUnattended}" == true ]]; then echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" + if [ -r "$1" ]; then + source "$1" + else + echo "::: Warning: can't open $1, using default settings..." + fi fi # Start the installer @@ -1364,10 +1675,10 @@ main(){ # Start services case ${PLAT} in Debian|Raspbian) - if [ "$VPN" = "OpenVPN" ]; then + if [ "$VPN" = "openvpn" ]; then $SUDO systemctl enable openvpn.service $SUDO systemctl start openvpn.service - elif [ "$VPN" = "WireGuard" ]; then + elif [ "$VPN" = "wireguard" ]; then $SUDO systemctl enable wg-quick@wg0.service $SUDO systemctl start wg-quick@wg0.service fi @@ -1389,12 +1700,6 @@ main(){ echo "::: done." displayFinalMessage - - echo ":::" - echo "::: Installation Complete!" - echo "::: Now run 'pivpn add' to create an ovpn profile for each of your devices." - echo "::: Run 'pivpn help' to see what else you can do!" - echo "::: It is strongly recommended you reboot after installation." echo ":::" } diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 7027c65..1381192 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -42,10 +42,10 @@ removeAll(){ # Stopping and disabling services echo "::: Stopping and disabling services..." - if [ "$VPN" = "WireGuard" ]; then + if [ "$VPN" = "wireguard" ]; then systemctl stop wg-quick@wg0 systemctl disable wg-quick@wg0 &> /dev/null - elif [ "$VPN" = "OpenVPN" ]; then + elif [ "$VPN" = "openvpn" ]; then systemctl stop openvpn systemctl disable openvpn &> /dev/null fi @@ -53,19 +53,19 @@ removeAll(){ # Removing firewall rules. echo "::: Removing firewall rules..." - if [ "$VPN" = "WireGuard" ]; then - pivpnDEV="wg0" - pivpnNET="10.6.0.0/24" + if [ "$VPN" = "wireguard" ]; then pivpnPROTO="udp" - elif [ "$VPN" = "OpenVPN" ]; then + pivpnDEV="wg0" + pivpnNET="10.6.0.0" + elif [ "$VPN" = "openvpn" ]; then pivpnDEV="tun0" - pivpnNET="10.8.0.0/24" + pivpnNET="10.8.0.0" fi if [ "$USING_UFW" -eq 1 ]; then ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null - ufw route delete allow in on "$pivpnDEV" from "$pivpnNET" out on "${IPv4dev}" to any > /dev/null + ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any > /dev/null sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules ufw reload &> /dev/null @@ -76,11 +76,11 @@ removeAll(){ fi if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - iptables -D FORWARD -d "$pivpnNET" -i "${IPv4dev}" -o "$pivpnDEV" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -D FORWARD -s "$pivpnNET" -i "$pivpnDEV" -o "${IPv4dev}" -j ACCEPT + iptables -D FORWARD -d "${pivpnNET}/24" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -D FORWARD -s "${pivpnNET}/24" -i "${pivpnDEV}/24" -o "${IPv4dev}" -j ACCEPT fi - iptables -t nat -D POSTROUTING -s "$pivpnNET" -o "${IPv4dev}" -j MASQUERADE + iptables -t nat -D POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE iptables-save > /etc/iptables/rules.v4 fi From 5cb8a053177205be796c9b46435e16ad8e45a55a Mon Sep 17 00:00:00 2001 From: Orazio Date: Thu, 14 Nov 2019 17:42:56 +0100 Subject: [PATCH 10/79] Minor unattended fixes, adjusted openvpn settings --- Default.txt | 2 -- auto_install/install.sh | 37 +++++++++++++++++++++++++++---------- server_config.txt | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Default.txt b/Default.txt index d3a01c1..cb733db 100644 --- a/Default.txt +++ b/Default.txt @@ -4,8 +4,6 @@ proto udp remote IPv4pub 1194 resolv-retry infinite nobind -persist-key -persist-tun key-direction 1 remote-cert-tls server tls-version-min 1.2 diff --git a/auto_install/install.sh b/auto_install/install.sh index da71a58..827c599 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1175,7 +1175,10 @@ askEncryption(){ fi fi - if [ -n "$DOWNLOAD_DH_PARAM" ]; then + if [ -z "$DOWNLOAD_DH_PARAM" ] || [ "$DOWNLOAD_DH_PARAM" -ne 1 ]; then + DOWNLOAD_DH_PARAM=0 + echo "::: DH parameters will be generated locally" + else echo "::: DH parameters will be downloaded from \"2 Ton Digital\"" fi @@ -1246,7 +1249,11 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} ./easyrsa --batch build-ca nopass printf "\n::: CA Complete.\n" - whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman parameters, and HMAC key will now be generated." ${r} ${c} + if [ "${runUnattended}" = 'true' ]; then + echo "::: The server key, Diffie-Hellman parameters, and HMAC key will now be generated." + else + whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman parameters, and HMAC key will now be generated." ${r} ${c} + fi # Build the server EASYRSA_CERT_EXPIRE=3650 ${SUDOE} ./easyrsa build-server-full ${SERVER_NAME} nopass @@ -1335,9 +1342,10 @@ confWireGuard(){ $SUDO chmod 700 /etc/wireguard fi - if [ "${runUnattended}" = 'false' ]; then + if [ "${runUnattended}" = 'true' ]; then + echo "::: The Server Keys and Pre-Shared key will now be generated." + else whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" - return fi $SUDO mkdir /etc/wireguard/configs $SUDO touch /etc/wireguard/configs/clients.txt @@ -1564,9 +1572,13 @@ installScripts(){ displayFinalMessage(){ if [ "${runUnattended}" = 'true' ]; then echo "::: Installation Complete!" - echo "::: Now run 'pivpn add' to create the ovpn profiles. -Run 'pivpn help' to see what else you can do!\n\nIf you run into any issue, please read all our documentation carefully. -All incomplete posts or bug reports will be ignored or deleted.\n\nThank you for using PiVPN." + echo "::: Now run 'pivpn add' to create the ovpn profiles." + echo "::: Run 'pivpn help' to see what else you can do!" + echo + echo "::: If you run into any issue, please read all our documentation carefully." + echo "::: All incomplete posts or bug reports will be ignored or deleted." + echo + echo "::: Thank you for using PiVPN." echo "::: It is strongly recommended you reboot after installation." return fi @@ -1621,10 +1633,15 @@ main(){ if [[ "${runUnattended}" == true ]]; then echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" - if [ -r "$1" ]; then - source "$1" + if [ -z "$2" ]; then + echo "::: No configuration file passed, using default settings..." else - echo "::: Warning: can't open $1, using default settings..." + if [ -r "$2" ]; then + source "$2" + else + echo "::: Can't open $2" + exit 1 + fi fi fi diff --git a/server_config.txt b/server_config.txt index 93143b1..9ca16a4 100644 --- a/server_config.txt +++ b/server_config.txt @@ -17,7 +17,7 @@ push "block-outside-dns" # overriding but not wiping out the original default gateway. push "redirect-gateway def1" client-to-client -keepalive 1800 3600 +keepalive 15 120 remote-cert-tls client tls-version-min 1.2 tls-auth /etc/openvpn/easy-rsa/pki/ta.key 0 From d7ebb4cca99f10c8a707b3ecf5a0b531045d3de7 Mon Sep 17 00:00:00 2001 From: Orazio Date: Sat, 16 Nov 2019 14:58:58 +0100 Subject: [PATCH 11/79] Unattended installation --- auto_install/install.sh | 101 +++++++++++++++++------------- scripts/openvpn/makeOVPN.sh | 17 ++--- scripts/openvpn/pivpnDebug.sh | 2 +- scripts/uninstall.sh | 33 ++++++---- scripts/wireguard/pivpnDEBUG.sh | 2 +- unattended_openvpn_example.conf | 12 ++++ unattended_wireguard_example.conf | 8 +++ 7 files changed, 108 insertions(+), 67 deletions(-) create mode 100644 unattended_openvpn_example.conf create mode 100644 unattended_wireguard_example.conf diff --git a/auto_install/install.sh b/auto_install/install.sh index 827c599..5e5f80a 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -679,7 +679,7 @@ askWhichVPN(){ fi fi else - if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard of 'No' to use OpenVPN." ${r} ${c}); + if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); then VPN="wireguard" else @@ -1075,7 +1075,7 @@ askCustomDomain(){ DomainSettingsCorrect=False - if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Would you like to add a custom search domain? \n (This is only for advanced users who have their own domain)\n" ${r} ${c}); then + if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno --defaultno "Would you like to add a custom search domain? \n (This is only for advanced users who have their own domain)\n" ${r} ${c}); then until [[ $DomainSettingsCorrect = True ]] do @@ -1217,16 +1217,27 @@ confOpenVPN(){ # Create a unique server name using the host name and UUID SERVER_NAME="${host_name}_${NEW_UUID}" + # Backup the openvpn folder + OPENVPN_BACKUP="openvpn_$(date +%Y-%m-%d-%H%M%S).tar.gz" + echo "::: Backing up the openvpn folder to /etc/${OPENVPN_BACKUP}" + $SUDO tar czf "/etc/${OPENVPN_BACKUP}" /etc/openvpn + + if [ -f /etc/openvpn/server.conf ]; then + $SUDO rm /etc/openvpn/server.conf + fi + # If easy-rsa exists, remove it if [[ -d /etc/openvpn/easy-rsa/ ]]; then $SUDO rm -rf /etc/openvpn/easy-rsa/ fi # Get easy-rsa - wget -qO- "${easyrsaRel}" | $SUDO tar xz -C /etc/openvpn && $SUDO mv /etc/openvpn/EasyRSA-v${easyrsaVer} /etc/openvpn/easy-rsa + wget -qO- "${easyrsaRel}" | $SUDO tar xz -C /etc/openvpn + $SUDO mv /etc/openvpn/EasyRSA-v${easyrsaVer} /etc/openvpn/easy-rsa # fix ownership $SUDO chown -R root:root /etc/openvpn/easy-rsa $SUDO mkdir /etc/openvpn/easy-rsa/pki + $SUDO chmod 700 /etc/openvpn/easy-rsa/pki cd /etc/openvpn/easy-rsa || exit @@ -1300,7 +1311,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null $SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf fi - if [ -z "$pivpnDOMAIN" ]; then + if [ -n "$pivpnDOMAIN" ]; then $SUDO sed -i "0,/\(.*dhcp-option.*\)/s//\push \"dhcp-option DOMAIN ${pivpnDOMAIN}\" \n&/" /etc/openvpn/server.conf fi @@ -1326,30 +1337,35 @@ confOVPN(){ # verify server name to strengthen security $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt - - if [ ! -d "$install_home/ovpns" ]; then - $SUDO mkdir "$install_home/ovpns" - fi - $SUDO chmod 0750 "$install_home/ovpns" - $SUDO chown $install_user:$install_user "$install_home/ovpns" } confWireGuard(){ if [ -d /etc/wireguard ]; then - $SUDO rm -r /etc/wireguard + # Backup the wireguard folder + WIREGUARD_BACKUP="wireguard_$(date +%Y-%m-%d-%H%M%S).tar.gz" + echo "::: Backing up the wireguard folder to /etc/${WIREGUARD_BACKUP}" + $SUDO tar czf "/etc/${WIREGUARD_BACKUP}" /etc/wireguard + + if [ -f /etc/wireguard/wg0.conf ]; then + $SUDO rm /etc/wireguard/wg0.conf + fi + else + # If compiled from source, the wireguard folder is not being created $SUDO mkdir /etc/wireguard - $SUDO chown root:root /etc/wireguard - $SUDO chmod 700 /etc/wireguard fi + # Ensure that only root is able to enter the wireguard folder + $SUDO chown root:root /etc/wireguard + $SUDO chmod 700 /etc/wireguard + if [ "${runUnattended}" = 'true' ]; then echo "::: The Server Keys and Pre-Shared key will now be generated." else whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" fi - $SUDO mkdir /etc/wireguard/configs + $SUDO mkdir -p /etc/wireguard/configs $SUDO touch /etc/wireguard/configs/clients.txt - $SUDO mkdir /etc/wireguard/keys + $SUDO mkdir -p /etc/wireguard/keys # Generate private key and derive public key from it wg genkey | $SUDO tee /etc/wireguard/keys/server_priv &> /dev/null @@ -1442,7 +1458,7 @@ confNetwork(){ } confLogging() { - echo "if \$programname == 'ovpn-server' then /var/log/openvpn.log + echo "if \$programname == 'ovpn-server' then /var/log/openvpn.log if \$programname == 'ovpn-server' then stop" | $SUDO tee /etc/rsyslog.d/30-openvpn.conf > /dev/null echo "/var/log/openvpn.log @@ -1459,7 +1475,7 @@ if \$programname == 'ovpn-server' then stop" | $SUDO tee /etc/rsyslog.d/30-openv endscript }" | $SUDO tee /etc/logrotate.d/openvpn > /dev/null - # Restart the logging service + # Restart the logging service case ${PLAT} in Debian|Raspbian) $SUDO systemctl restart rsyslog.service || true @@ -1521,32 +1537,29 @@ askUnattendedUpgrades(){ } confUnattendedUpgrades(){ - if [ "$UNATTUPG" -eq 1 ]; then - PIVPN_DEPS=(unattended-upgrades) - installDependentPackages PIVPN_DEPS[@] + PIVPN_DEPS=(unattended-upgrades) + installDependentPackages PIVPN_DEPS[@] - cd /etc/apt/apt.conf.d + cd /etc/apt/apt.conf.d - if [ "$PLAT" = "Raspbian" ]; then - wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz - $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades - $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" - fi - - # On architectures different from armv6l, where we install wireguard from source, enable - # automatic updates via the unstable repository - if [ "$VPN" = "wireguard" ] && [ "$(uname -m)" != "armv6l" ]; then - $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades - fi - - # Add the remaining settings for all other distributions - echo "APT::Periodic::Enable \"1\"; - APT::Periodic::Update-Package-Lists \"1\"; - APT::Periodic::Download-Upgradeable-Packages \"1\"; - APT::Periodic::Unattended-Upgrade \"1\"; - APT::Periodic::AutocleanInterval \"7\"; - APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null + if [ "$PLAT" = "Raspbian" ]; then + wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz + $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades + $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" fi + + # Enable automatic updates via the unstable repository when installing from debian package + if [ "$VPN" = "wireguard" ] && [ "$(uname -m)" != "armv6l" ]; then + $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades + fi + + # Add the remaining settings for all other distributions + echo "APT::Periodic::Enable \"1\"; + APT::Periodic::Update-Package-Lists \"1\"; + APT::Periodic::Download-Upgradeable-Packages \"1\"; + APT::Periodic::Unattended-Upgrade \"1\"; + APT::Periodic::AutocleanInterval \"7\"; + APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null } installScripts(){ @@ -1704,11 +1717,15 @@ main(){ # Ask if unattended-upgrades will be enabled askUnattendedUpgrades - confUnattendedUpgrades + if [ "$UNATTUPG" -eq 1 ]; then + confUnattendedUpgrades + fi + + # Save installation setting to the final location echo "TO_INSTALL=(${TO_INSTALL[*]})" >> /tmp/setupVars.conf - $SUDO cp /tmp/setupVars.conf "$setupVars" + installScripts # Ensure that cached writes reach persistent storage diff --git a/scripts/openvpn/makeOVPN.sh b/scripts/openvpn/makeOVPN.sh index d37769c..674732f 100755 --- a/scripts/openvpn/makeOVPN.sh +++ b/scripts/openvpn/makeOVPN.sh @@ -213,6 +213,7 @@ EOF #make sure ovpns dir exists if [ ! -d "$install_home/ovpns" ]; then mkdir "$install_home/ovpns" + chown "$install_user":"$install_user" "$install_home/ovpns" chmod 0750 "$install_home/ovpns" fi @@ -339,16 +340,10 @@ if [ "$iOS" = "1" ]; then sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' < "issued/${NAME}${CRT}" echo "" - #Finally, append the TA Private Key - if [ -f /etc/pivpn/TWO_POINT_FOUR ]; then - echo "" - cat "${TA}" - echo "" - else - echo "" - cat "${TA}" - echo "" - fi + #Finally, append the tls Private Key + echo "" + cat "${TA}" + echo "" } > "${NAME}${FILEEXT}" @@ -401,7 +396,7 @@ fi # Copy the .ovpn profile to the home directory for convenient remote access cp "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" "$install_home/ovpns/$NAME$FILEEXT" -chown "$install_user" "$install_home/ovpns/$NAME$FILEEXT" +chown "$install_user":"$install_user" "$install_home/ovpns/$NAME$FILEEXT" chmod 640 "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" chmod 640 "$install_home/ovpns/$NAME$FILEEXT" printf "\n\n" diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index 348e7de..a205ba0 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -205,7 +205,7 @@ echo -e ":::: \e[4mSnippet of the server log\e[0m ::::" tail -20 /var/log/openvpn.log > /tmp/snippet # Regular expession taken from https://superuser.com/a/202835, it will match invalid IPs -# like 123.456.789.012 but it's fine because the log only contains valid ones. +# like 123.456.789.012 but it's fine since the log only contains valid ones. declare -a IPS_TO_HIDE=($(grepcidr -v 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 /tmp/snippet | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | uniq)) for IP in "${IPS_TO_HIDE[@]}"; do sed -i "s/$IP/REDACTED/g" /tmp/snippet diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 1381192..646de20 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -67,6 +67,7 @@ removeAll(){ ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any > /dev/null sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules + iptables -t nat -D POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE ufw reload &> /dev/null elif [ "$USING_UFW" -eq 0 ]; then @@ -77,7 +78,7 @@ removeAll(){ if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then iptables -D FORWARD -d "${pivpnNET}/24" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -D FORWARD -s "${pivpnNET}/24" -i "${pivpnDEV}/24" -o "${IPv4dev}" -j ACCEPT + iptables -D FORWARD -s "${pivpnNET}/24" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT fi iptables -t nat -D POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE @@ -103,8 +104,6 @@ removeAll(){ rm /etc/apt/preferences.d/limit-unstable $PKG_MANAGER update &> /dev/null fi - rm -rf /etc/wireguard - rm -rf $install_home/configs elif [ "${i}" = "wireguard-dkms" ]; then @@ -123,12 +122,6 @@ removeAll(){ # so we remove the repository keys apt-key remove E1CF20DDFFE4B89E802658F1E0B11894F66AEC98 80D15823B7FD1561F9F7BCDDDC30D7C23CBBABEE &> /dev/null - elif [ "${i}" = "openvpn" ]; then - - rm -rf /var/log/*openvpn* - rm -rf /etc/openvpn - rm -rf $install_home/ovpns - elif [ "${i}" = "unattended-upgrades" ]; then rm -rf /var/log/unattended-upgrades @@ -158,7 +151,7 @@ removeAll(){ echo "::: Removing pivpn system files..." if [ -f /etc/dnsmasq.d/02-pivpn.conf ]; then - rm /etc/dnsmasq.d/02-pivpn.conf + rm -f /etc/dnsmasq.d/02-pivpn.conf pihole restartdns fi @@ -166,8 +159,24 @@ removeAll(){ rm -rf /etc/.pivpn rm -rf /etc/pivpn rm -rf /var/log/*pivpn* - rm /usr/local/bin/pivpn - rm /etc/bash_completion.d/pivpn + rm -f /usr/local/bin/pivpn + rm -f /etc/bash_completion.d/pivpn + + echo ":::" + echo "::: Removing VPN configuration files..." + + if [ "$VPN" = "wireguard" ]; then + rm -f /etc/wireguard/wg0.conf + rm -rf /etc/wireguard/configs + rm -rf /etc/wireguard/keys + rm -rf $install_home/configs + elif [ "$VPN" = "openvpn" ]; then + rm -rf /var/log/*openvpn* + rm -f /etc/openvpn/server.conf + rm -f /etc/openvpn/crl.pem + rm -rf /etc/openvpn/easy-rsa + rm -rf $install_home/ovpns + fi echo ":::" printf "::: Finished removing PiVPN from your system.\n" diff --git a/scripts/wireguard/pivpnDEBUG.sh b/scripts/wireguard/pivpnDEBUG.sh index bdd7f3e..b7c0311 100755 --- a/scripts/wireguard/pivpnDEBUG.sh +++ b/scripts/wireguard/pivpnDEBUG.sh @@ -24,7 +24,7 @@ printf "=============================================\n" echo -e ":::: \e[4mServer configuration shown below\e[0m ::::" cd /etc/wireguard/keys cp ../wg0.conf ../wg0.tmp -# Replace every key in the server configuration with just it's file name +# Replace every key in the server configuration with just its file name for k in *; do sed "s#$(cat "$k")#$k#" -i ../wg0.tmp done diff --git a/unattended_openvpn_example.conf b/unattended_openvpn_example.conf new file mode 100644 index 0000000..6f96a74 --- /dev/null +++ b/unattended_openvpn_example.conf @@ -0,0 +1,12 @@ +IPv4dev=eth0 +install_user=pi +VPN=openvpn +pivpnPROTO=udp +pivpnPORT=1194 +pivpnDNS1=8.8.8.8 +pivpnDNS2=8.8.4.4 +pivpnHOST=pivpn.example.com +pivpnENCRYPT=2048 +pivpnDOMAIN=domain.example.com +DOWNLOAD_DH_PARAM=0 +UNATTUPG=1 diff --git a/unattended_wireguard_example.conf b/unattended_wireguard_example.conf new file mode 100644 index 0000000..4ed1752 --- /dev/null +++ b/unattended_wireguard_example.conf @@ -0,0 +1,8 @@ +IPv4dev=eth0 +install_user=pi +VPN=wireguard +pivpnPORT=51820 +pivpnDNS1=8.8.8.8 +pivpnDNS2=8.8.4.4 +pivpnHOST=pivpn.example.com +UNATTUPG=1 From 8ab71601ffda62ec8fc575a6f76b824f83739762 Mon Sep 17 00:00:00 2001 From: Orazio Date: Sat, 16 Nov 2019 17:02:15 +0100 Subject: [PATCH 12/79] Automatically fetch latest WireGuard snapshot --- auto_install/install.sh | 10 ++++++---- scripts/uninstall.sh | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 5e5f80a..50bf3af 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -37,9 +37,6 @@ easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer} UNATTUPG_RELEASE="1.14" UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_RELEASE}.tar.gz" -WG_SNAPSHOT="0.0.20191012" -WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" - # Find the rows and columns. Will default to 80x24 if it can not be detected. screen_size=$(stty size 2>/dev/null || echo 24 80) rows=$(echo $screen_size | awk '{print $1}') @@ -738,9 +735,12 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null elif [ "$(uname -m)" = "armv6l" ]; then echo "::: Installing WireGuard from source... " - PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode) + PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq) installDependentPackages PIVPN_DEPS[@] + WG_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-kmodtools"."version"')" + WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" + # Delete any leftover code $SUDO rm -rf /usr/src/wireguard-* @@ -804,6 +804,8 @@ Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null exit 1 fi + echo "WG_SNAPSHOT=${WG_SNAPSHOT}" >> /tmp/setupVars.conf + elif [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "i686" ]; then echo "::: Installing WireGuard from Debian package... " diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 646de20..56ffbe7 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -2,7 +2,6 @@ # PiVPN: Uninstall Script PKG_MANAGER="apt-get" -WG_SNAPSHOT="0.0.20191012" setupVars="/etc/pivpn/setupVars.conf" if [ ! -f "${setupVars}" ]; then From 34c10a81f3bf0c9dbde852075e7335145341bc7e Mon Sep 17 00:00:00 2001 From: Orazio Date: Sat, 16 Nov 2019 21:25:34 +0100 Subject: [PATCH 13/79] Renamed pivpnDOMAIN to pivpnSEARCHDOMAIN --- auto_install/install.sh | 24 ++++++++++++------------ unattended_openvpn_example.conf | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 50bf3af..234ffe1 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1061,17 +1061,17 @@ validDomain(){ #This procedure allows a user to specify a custom search domain if they have one. askCustomDomain(){ if [ "${runUnattended}" = 'true' ]; then - if [ -n "$pivpnDOMAIN" ]; then - if validDomain "$pivpnDOMAIN"; then - echo "::: Using custom domain $pivpnDOMAIN" + if [ -n "$pivpnSEARCHDOMAIN" ]; then + if validDomain "$pivpnSEARCHDOMAIN"; then + echo "::: Using custom domain $pivpnSEARCHDOMAIN" else - echo "::: Custom domain $pivpnDOMAIN is not valid" + echo "::: Custom domain $pivpnSEARCHDOMAIN is not valid" exit 1 fi else echo "::: Skipping custom domain" fi - echo "pivpnDOMAIN=${pivpnDOMAIN}" >> /tmp/setupVars.conf + echo "pivpnSEARCHDOMAIN=${pivpnSEARCHDOMAIN}" >> /tmp/setupVars.conf return fi @@ -1081,16 +1081,16 @@ askCustomDomain(){ until [[ $DomainSettingsCorrect = True ]] do - if pivpnDOMAIN=$(whiptail --inputbox "Enter Custom Domain\nFormat: mydomain.com" ${r} ${c} --title "Custom Domain" 3>&1 1>&2 2>&3); then - if validDomain "$pivpnDOMAIN"; then - if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\n Custom Search Domain: $pivpnDOMAIN" ${r} ${c}); then + if pivpnSEARCHDOMAIN=$(whiptail --inputbox "Enter Custom Domain\nFormat: mydomain.com" ${r} ${c} --title "Custom Domain" 3>&1 1>&2 2>&3); then + if validDomain "$pivpnSEARCHDOMAIN"; then + if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\n Custom Search Domain: $pivpnSEARCHDOMAIN" ${r} ${c}); then DomainSettingsCorrect=True else # If the settings are wrong, the loop continues DomainSettingsCorrect=False fi else - whiptail --msgbox --backtitle "Invalid Domain" --title "Invalid Domain" "Domain is invalid. Please try again.\n\n DOMAIN: $pivpnDOMAIN\n" ${r} ${c} + whiptail --msgbox --backtitle "Invalid Domain" --title "Invalid Domain" "Domain is invalid. Please try again.\n\n DOMAIN: $pivpnSEARCHDOMAIN\n" ${r} ${c} DomainSettingsCorrect=False fi else @@ -1100,7 +1100,7 @@ askCustomDomain(){ done fi - echo "pivpnDOMAIN=${pivpnDOMAIN}" >> /tmp/setupVars.conf + echo "pivpnSEARCHDOMAIN=${pivpnSEARCHDOMAIN}" >> /tmp/setupVars.conf } askPublicIPOrDNS(){ @@ -1313,8 +1313,8 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null $SUDO sed -i "s/proto udp/proto tcp/g" /etc/openvpn/server.conf fi - if [ -n "$pivpnDOMAIN" ]; then - $SUDO sed -i "0,/\(.*dhcp-option.*\)/s//\push \"dhcp-option DOMAIN ${pivpnDOMAIN}\" \n&/" /etc/openvpn/server.conf + if [ -n "$pivpnSEARCHDOMAIN" ]; then + $SUDO sed -i "0,/\(.*dhcp-option.*\)/s//\push \"dhcp-option DOMAIN ${pivpnSEARCHDOMAIN}\" \n&/" /etc/openvpn/server.conf fi # write out server certs to conf file diff --git a/unattended_openvpn_example.conf b/unattended_openvpn_example.conf index 6f96a74..2885d65 100644 --- a/unattended_openvpn_example.conf +++ b/unattended_openvpn_example.conf @@ -7,6 +7,6 @@ pivpnDNS1=8.8.8.8 pivpnDNS2=8.8.4.4 pivpnHOST=pivpn.example.com pivpnENCRYPT=2048 -pivpnDOMAIN=domain.example.com +pivpnSEARCHDOMAIN=searchdomain.example.com DOWNLOAD_DH_PARAM=0 UNATTUPG=1 From 1ff6f7e9e89a2f3e449325d457011aa013ed05ef Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 18 Nov 2019 12:42:04 +0100 Subject: [PATCH 14/79] Removed trivial command output --- auto_install/install.sh | 10 +++++----- scripts/openvpn/pivpnDebug.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 234ffe1..7f898e7 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1222,7 +1222,7 @@ confOpenVPN(){ # Backup the openvpn folder OPENVPN_BACKUP="openvpn_$(date +%Y-%m-%d-%H%M%S).tar.gz" echo "::: Backing up the openvpn folder to /etc/${OPENVPN_BACKUP}" - $SUDO tar czf "/etc/${OPENVPN_BACKUP}" /etc/openvpn + $SUDO tar czf "/etc/${OPENVPN_BACKUP}" /etc/openvpn &> /dev/null if [ -f /etc/openvpn/server.conf ]; then $SUDO rm /etc/openvpn/server.conf @@ -1346,7 +1346,7 @@ confWireGuard(){ # Backup the wireguard folder WIREGUARD_BACKUP="wireguard_$(date +%Y-%m-%d-%H%M%S).tar.gz" echo "::: Backing up the wireguard folder to /etc/${WIREGUARD_BACKUP}" - $SUDO tar czf "/etc/${WIREGUARD_BACKUP}" /etc/wireguard + $SUDO tar czf "/etc/${WIREGUARD_BACKUP}" /etc/wireguard &> /dev/null if [ -f /etc/wireguard/wg0.conf ]; then $SUDO rm /etc/wireguard/wg0.conf @@ -1386,7 +1386,7 @@ ListenPort = ${pivpnPORT}" | $SUDO tee /etc/wireguard/wg0.conf &> /dev/null confNetwork(){ # Enable forwarding of internet traffic $SUDO sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf - $SUDO sysctl -p + $SUDO sysctl -p > /dev/null # if ufw enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example) if $SUDO bash -c 'hash ufw' 2>/dev/null; then @@ -1708,10 +1708,10 @@ main(){ case ${PLAT} in Debian|Raspbian) if [ "$VPN" = "openvpn" ]; then - $SUDO systemctl enable openvpn.service + $SUDO systemctl enable openvpn.service &> /dev/null $SUDO systemctl start openvpn.service elif [ "$VPN" = "wireguard" ]; then - $SUDO systemctl enable wg-quick@wg0.service + $SUDO systemctl enable wg-quick@wg0.service &> /dev/null $SUDO systemctl start wg-quick@wg0.service fi ;; diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index a205ba0..c3ce10d 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -184,7 +184,7 @@ else fi fi -# grep -w (whole word) is used so port 111940 with now match when looking for 1194 +# grep -w (whole word) is used so port 11940 won't match when looking for 1194 if netstat -uanpt | grep openvpn | grep -w "${pivpnPORT}" | grep -q "${pivpnPROTO}"; then echo ":: [OK] OpenVPN is listening on port ${pivpnPORT}/${pivpnPROTO}" else From b9c6c0f31479de274153955d7c997ebd9a2e933e Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 19 Nov 2019 13:28:51 +0100 Subject: [PATCH 15/79] Fix exit codes --- scripts/openvpn/pivpn | 2 +- scripts/wireguard/pivpn | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/openvpn/pivpn b/scripts/openvpn/pivpn index 4d2317c..c18049f 100755 --- a/scripts/openvpn/pivpn +++ b/scripts/openvpn/pivpn @@ -6,7 +6,7 @@ if [[ ! $EUID -eq 0 ]];then export SUDO="sudo" else echo "::: Please install sudo or run this as root." - exit 0 + exit 1 fi fi diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn index f4bcfd9..bd89d43 100755 --- a/scripts/wireguard/pivpn +++ b/scripts/wireguard/pivpn @@ -13,39 +13,39 @@ fi makeConf(){ shift $SUDO /opt/pivpn/makeCONF.sh "$@" - exit 1 + exit 0 } listConnected(){ $SUDO wg show - exit 1 + exit 0 } debug(){ $SUDO /opt/pivpn/pivpnDEBUG.sh - exit 1 + exit 0 } listClients(){ $SUDO /opt/pivpn/listCONF.sh - exit 1 + exit 0 } showQrcode(){ shift $SUDO /opt/pivpn/qrcodeCONF.sh "$@" - exit 1 + exit 0 } removeClient(){ shift $SUDO /opt/pivpn/removeCONF.sh "$@" - exit 1 + exit 0 } uninstallServer(){ $SUDO /opt/pivpn/uninstall.sh - exit 1 + exit 0 } showHelp(){ @@ -62,7 +62,7 @@ showHelp(){ echo "::: -r, remove Remove a client" echo "::: -h, help Show this help dialog" echo "::: -u, uninstall Uninstall pivpn from your system!" - exit 1 + exit 0 } if [ $# = 0 ]; then From e2da52b1a7be472eb94ffdfdf13e6b644d3bafc8 Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 19 Nov 2019 17:29:41 +0100 Subject: [PATCH 16/79] Added Ubuntu Bionic support --- auto_install/install.sh | 262 ++++++++++++++++++++++------------------ scripts/uninstall.sh | 15 ++- 2 files changed, 156 insertions(+), 121 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 7f898e7..d303520 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -22,14 +22,14 @@ PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" # Dependencies that are required by the script, regardless of the VPN protocol chosen -BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools dhcpcd5) +BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools) # Dependencies that where actually installed by the script. For example if the script requires # grep and dnsutils but dnsutils is already installed, we save grep here. This way when uninstalling # PiVPN we won't prompt to remove packages that may have been installed by the user for other reasons TO_INSTALL=() -pivpnGitUrl="https://github.com/orazioedoardo/pivpn.git" +pivpnGitUrl="https://github.com/pivpn/pivpn.git" easyrsaVer="3.0.6" easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer}/EasyRSA-unix-v${easyrsaVer}.tgz" @@ -63,12 +63,12 @@ noOSSupport(){ if [ "${runUnattended}" = 'true' ]; then echo "::: Invalid OS detected" echo "::: We have not been able to detect a supported OS." - echo "::: Currently this installer supports Raspbian (Buster) and Debian (Buster)." + echo "::: Currently this installer supports Raspbian (Buster), Debian (Buster) and Ubuntu (Bionic)." exit 1 fi whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS. -Currently this installer supports Raspbian (Buster) and Debian (Buster). +Currently this installer supports Raspbian (Buster), Debian (Buster) and Ubuntu (Bionic). If you think you received this message in error, you can post an issue on the GitHub at https://github.com/pivpn/pivpn/issues." ${r} ${c} exit 1 } @@ -97,32 +97,36 @@ distroCheck(){ if hash lsb_release 2>/dev/null; then PLAT=$(lsb_release -si) - OSCN=$(lsb_release -sc) # We want this to be trusty xenial or jessie + OSCN=$(lsb_release -sc) else # else get info from os-release source /etc/os-release PLAT=$(awk '{print $1}' <<< "$NAME") VER="$VERSION_ID" - declare -A VER_MAP=(["10"]="buster") + declare -A VER_MAP=(["10"]="buster" ["18.04"]="bionic") OSCN=${VER_MAP["${VER}"]} fi case ${PLAT} in - Debian|Raspbian) + Debian|Raspbian|Ubuntu) case ${OSCN} in - buster) + buster|bionic) ;; *) - maybeOS_Support + maybeOSSupport ;; esac ;; *) - noOS_Support + noOSSupport ;; esac + if [ "$PLAT" = "Raspbian" ]; then + BASE_DEPS+=(dhcpcd5) + fi + echo "PLAT=${PLAT}" > /tmp/setupVars.conf echo "OSCN=${OSCN}" >> /tmp/setupVars.conf } @@ -705,119 +709,131 @@ installOpenVPN(){ } installWireGuard(){ - # If this Raspberry Pi uses armv7l we can use the package from the repo - # https://lists.zx2c4.com/pipermail/wireguard/2017-November/001885.html - # Otherwhise compile and build the kernel module via DKMS (so it will - # be recompiled on kernel upgrades) - if [ "$(uname -m)" = "armv7l" ]; then + if [ "$PLAT" = "Raspbian" ]; then - echo "::: Installing WireGuard from Debian package... " - # dirmngr is used to download repository keys, whereas qrencode is used to generate qrcodes - # from config file, for use with mobile clients - PIVPN_DEPS=(dirmngr qrencode) - installDependentPackages PIVPN_DEPS[@] - # Do not upgrade packages from the unstable repository except for wireguard - echo "::: Adding Debian repository... " - echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null - echo "Package: * -Pin: release a=unstable -Pin-Priority: 1 + # If this Raspberry Pi uses armv7l we can use the package from the repo + # https://lists.zx2c4.com/pipermail/wireguard/2017-November/001885.html + # Otherwhise compile and build the kernel module via DKMS (so it will + # be recompiled on kernel upgrades) -Package: wireguard wireguard-dkms wireguard-tools -Pin: release a=unstable -Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + if [ "$(uname -m)" = "armv7l" ]; then - $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 - $SUDO ${UPDATE_PKG_CACHE} &> /dev/null - PIVPN_DEPS=(raspberrypi-kernel-headers wireguard wireguard-tools wireguard-dkms) - installDependentPackages PIVPN_DEPS[@] + echo "::: Installing WireGuard from Debian package... " + # dirmngr is used to download repository keys, whereas qrencode is used to generate qrcodes + # from config file, for use with mobile clients + PIVPN_DEPS=(dirmngr qrencode) + installDependentPackages PIVPN_DEPS[@] + # Do not upgrade packages from the unstable repository except for wireguard + echo "::: Adding Debian repository... " + echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null + echo "Package: * + Pin: release a=unstable + Pin-Priority: 1 - elif [ "$(uname -m)" = "armv6l" ]; then + Package: wireguard wireguard-dkms wireguard-tools + Pin: release a=unstable + Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null - echo "::: Installing WireGuard from source... " - PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq) - installDependentPackages PIVPN_DEPS[@] + $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + PIVPN_DEPS=(raspberrypi-kernel-headers wireguard wireguard-tools wireguard-dkms) + installDependentPackages PIVPN_DEPS[@] - WG_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-kmodtools"."version"')" - WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" + elif [ "$(uname -m)" = "armv6l" ]; then - # Delete any leftover code - $SUDO rm -rf /usr/src/wireguard-* + echo "::: Installing WireGuard from source... " + PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq) + installDependentPackages PIVPN_DEPS[@] - echo "::: Downloading source code... " - wget -qO- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src - echo "done!" + WG_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-kmodtools"."version"')" + WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" - cd /usr/src - $SUDO mv WireGuard-"${WG_SNAPSHOT}" wireguard-"${WG_SNAPSHOT}" - cd wireguard-"${WG_SNAPSHOT}" - $SUDO mv src/* . - $SUDO rmdir src + # Delete any leftover code + $SUDO rm -rf /usr/src/wireguard-* - # We install the userspace tools manually since DKMS only compiles and - # installs the kernel module - echo "::: Compiling WireGuard tools... " - if $SUDO make tools; then + echo "::: Downloading source code... " + wget -qO- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src echo "done!" - else - echo "failed!" - exit 1 + + cd /usr/src + $SUDO mv WireGuard-"${WG_SNAPSHOT}" wireguard-"${WG_SNAPSHOT}" + cd wireguard-"${WG_SNAPSHOT}" + $SUDO mv src/* . + $SUDO rmdir src + + # We install the userspace tools manually since DKMS only compiles and + # installs the kernel module + echo "::: Compiling WireGuard tools... " + if $SUDO make tools; then + echo "done!" + else + echo "failed!" + exit 1 + fi + + # Use checkinstall to install userspace tools so if the user wants to uninstall + # PiVPN we can just do apt remove wireguard-tools, instead of manually removing + # files from the file system + echo "::: Installing WireGuard tools... " + if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_SNAPSHOT}" -y make tools-install; then + TO_INSTALL+=("wireguard-tools") + echo "done!" + else + echo "failed!" + exit 1 + fi + + echo "::: Adding WireGuard modules via DKMS... " + if $SUDO dkms add wireguard/"${WG_SNAPSHOT}"; then + echo "done!" + else + echo "failed!" + $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + exit 1 + fi + + echo "::: Compiling WireGuard modules via DKMS... " + if $SUDO dkms build wireguard/"${WG_SNAPSHOT}"; then + echo "done!" + else + echo "failed!" + $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + exit 1 + fi + + echo "::: Installing WireGuard modules via DKMS... " + if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then + TO_INSTALL+=("wireguard-dkms") + echo "done!" + else + echo "failed!" + $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + exit 1 + fi + + echo "WG_SNAPSHOT=${WG_SNAPSHOT}" >> /tmp/setupVars.conf + fi - # Use checkinstall to install userspace tools so if the user wants to uninstall - # PiVPN we can just do apt remove wireguard-tools, instead of manually removing - # files from the file system - echo "::: Installing WireGuard tools... " - if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_SNAPSHOT}" -y make tools-install; then - TO_INSTALL+=("wireguard-tools") - echo "done!" - else - echo "failed!" - exit 1 - fi - - echo "::: Adding WireGuard modules via DKMS... " - if $SUDO dkms add wireguard/"${WG_SNAPSHOT}"; then - echo "done!" - else - echo "failed!" - $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all - exit 1 - fi - - echo "::: Compiling WireGuard modules via DKMS... " - if $SUDO dkms build wireguard/"${WG_SNAPSHOT}"; then - echo "done!" - else - echo "failed!" - $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all - exit 1 - fi - - echo "::: Installing WireGuard modules via DKMS... " - if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then - TO_INSTALL+=("wireguard-dkms") - echo "done!" - else - echo "failed!" - $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all - exit 1 - fi - - echo "WG_SNAPSHOT=${WG_SNAPSHOT}" >> /tmp/setupVars.conf - - elif [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "i686" ]; then + elif [ "$PLAT" = "Debian" ]; then echo "::: Installing WireGuard from Debian package... " echo "::: Adding Debian repository... " echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null echo "Package: * -Pin: release a=unstable -Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + Pin: release a=unstable + Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] + elif [ "$PLAT" = "Ubuntu" ]; then + + echo "::: Installing WireGuard from PPA... " + $SUDO add-apt-repository ppa:wireguard/wireguard -y + PIVPN_DEPS=(qrencode wireguard wireguard-tools wireguard-dkms) + installDependentPackages PIVPN_DEPS[@] + fi } @@ -1447,7 +1463,7 @@ confNetwork(){ fi case ${PLAT} in - Debian|Raspbian) + Debian|Raspbian|Ubuntu) $SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null ;; esac @@ -1479,7 +1495,7 @@ if \$programname == 'ovpn-server' then stop" | $SUDO tee /etc/rsyslog.d/30-openv # Restart the logging service case ${PLAT} in - Debian|Raspbian) + Debian|Raspbian|Ubuntu) $SUDO systemctl restart rsyslog.service || true ;; esac @@ -1544,24 +1560,40 @@ confUnattendedUpgrades(){ cd /etc/apt/apt.conf.d - if [ "$PLAT" = "Raspbian" ]; then - wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz - $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades - $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" - fi + if [ "$PLAT" = "Ubuntu" ]; then - # Enable automatic updates via the unstable repository when installing from debian package - if [ "$VPN" = "wireguard" ] && [ "$(uname -m)" != "armv6l" ]; then - $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades - fi + # Ubuntu 50unattended-upgrades should already just have security enabled + # so we just need to configure the 10periodic file + echo "APT::Periodic::Update-Package-Lists \"1\"; + APT::Periodic::Download-Upgradeable-Packages \"1\"; + APT::Periodic::AutocleanInterval \"5\"; + APT::Periodic::Unattended-Upgrade \"1\";" | $SUDO tee 10periodic > /dev/null - # Add the remaining settings for all other distributions - echo "APT::Periodic::Enable \"1\"; + else + + # Fix Raspbian config + if [ "$PLAT" = "Raspbian" ]; then + wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz + $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades + $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" + fi + + # Add the remaining settings for all other distributions + echo "APT::Periodic::Enable \"1\"; APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Download-Upgradeable-Packages \"1\"; APT::Periodic::Unattended-Upgrade \"1\"; APT::Periodic::AutocleanInterval \"7\"; APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null + + fi + + # Enable automatic updates via the unstable repository when installing from debian package + if [ "$VPN" = "wireguard" ] && [ "$PLAT" != "Ubuntu" ] && [ "$(uname -m)" != "armv6l" ]; then + if ! grep -q '"o=Debian,a=unstable";' 50unattended-upgrades; + $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades + fi + fi } installScripts(){ @@ -1706,7 +1738,7 @@ main(){ echo "::: Restarting services..." # Start services case ${PLAT} in - Debian|Raspbian) + Debian|Raspbian|Ubuntu) if [ "$VPN" = "openvpn" ]; then $SUDO systemctl enable openvpn.service &> /dev/null $SUDO systemctl start openvpn.service diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 56ffbe7..6de5842 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -98,18 +98,21 @@ removeAll(){ case $yn in [Yy]* ) if [ "${i}" = "wireguard" ]; then - if [ "$(uname -m)" = "armv7l" ] || [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "i686" ]; then + # On Debian and armv7l Raspbian, remove the unstable repo (on armv6l Raspbian + # there is no wireguard package). On Ubuntu, remove the PPA. + if [ "$PLAT" = "Debian" ] || { [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv7l" ]; }; then rm /etc/apt/sources.list.d/unstable.list rm /etc/apt/preferences.d/limit-unstable $PKG_MANAGER update &> /dev/null + elif [ "$PLAT" = "Ubuntu" ]; then + add-apt-repository ppa:wireguard/wireguard -r -y fi elif [ "${i}" = "wireguard-dkms" ]; then - # If we installed wireguard-dkms and we are on armv6l, then we manually need - # to remove the kernel module and skip the apt uninstallation (since it's not an - # actual package) - if [ "$(uname -m)" = "armv6l" ]; then + # On armv6l Raspbian we manually remove the kernel module and skip the apt + # uninstallation (since it's not an actual package). + if [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv6l" ]; then dkms remove wireguard/"${WG_SNAPSHOT}" --all rm -rf /usr/src/wireguard-* break @@ -117,7 +120,7 @@ removeAll(){ elif [ "${i}" = "dirmngr" ]; then - # If dirmngr was installed, then we had previously installed wireguard on armv7l + # If dirmngr was installed, then we had previously installed wireguard on armv7l Raspbian # so we remove the repository keys apt-key remove E1CF20DDFFE4B89E802658F1E0B11894F66AEC98 80D15823B7FD1561F9F7BCDDDC30D7C23CBBABEE &> /dev/null From a03d4e1be2588fc710eb08dfad3589f4b1fec011 Mon Sep 17 00:00:00 2001 From: Orazio Date: Wed, 20 Nov 2019 18:50:57 +0100 Subject: [PATCH 17/79] Fix typo --- auto_install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index d303520..0c092a4 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1590,7 +1590,7 @@ confUnattendedUpgrades(){ # Enable automatic updates via the unstable repository when installing from debian package if [ "$VPN" = "wireguard" ] && [ "$PLAT" != "Ubuntu" ] && [ "$(uname -m)" != "armv6l" ]; then - if ! grep -q '"o=Debian,a=unstable";' 50unattended-upgrades; + if ! grep -q '"o=Debian,a=unstable";' 50unattended-upgrades; then $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades fi fi From d34577329e47bff4151de82daf715a1ca6e8de48 Mon Sep 17 00:00:00 2001 From: Orazio Date: Wed, 27 Nov 2019 11:59:53 +0100 Subject: [PATCH 18/79] Removed reference to deleted branch --- auto_install/install.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 0c092a4..95a3a81 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -615,12 +615,10 @@ updateRepo(){ cd /etc $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! cd "${1}" || exit 1 - if [ -z "${TESTING}" ]; then + if [ -z "${TESTING+x}" ]; then : - elif [ "${TESTING}" = "test" ]; then + else ${SUDOE} git checkout test - elif [ "${TESTING}" = "test-wireguard" ]; then - ${SUDOE} git checkout test-wireguard fi echo " done!" } @@ -634,12 +632,10 @@ makeRepo(){ cd /etc $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! cd "${1}" || exit 1 - if [ -z "${TESTING}" ]; then + if [ -z "${TESTING+x}" ]; then : - elif [ "${TESTING}" = "test" ]; then + else ${SUDOE} git checkout test - elif [ "${TESTING}" = "test-wireguard" ]; then - ${SUDOE} git checkout test-wireguard fi echo " done!" } From e2941f8faef50f05db7650d016d902edd496d306 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 2 Dec 2019 17:00:39 +0100 Subject: [PATCH 19/79] Properly avoid pulling unwanted packages from unstable repo Currently apt pulls all packages from the unstable repo because the script intendation created the file 'limit-unstable' with tabs in it. Fixed using printf to create a multiline file (which is the way wireguard.com/install suggests). --- auto_install/install.sh | 12 ++---------- scripts/wireguard/bash-completion | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 scripts/wireguard/bash-completion diff --git a/auto_install/install.sh b/auto_install/install.sh index 95a3a81..35a86cf 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -722,13 +722,7 @@ installWireGuard(){ # Do not upgrade packages from the unstable repository except for wireguard echo "::: Adding Debian repository... " echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null - echo "Package: * - Pin: release a=unstable - Pin-Priority: 1 - - Package: wireguard wireguard-dkms wireguard-tools - Pin: release a=unstable - Pin-Priority: 500" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null @@ -816,9 +810,7 @@ installWireGuard(){ echo "::: Installing WireGuard from Debian package... " echo "::: Adding Debian repository... " echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null - echo "Package: * - Pin: release a=unstable - Pin-Priority: 90" | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion new file mode 100644 index 0000000..9eb591e --- /dev/null +++ b/scripts/wireguard/bash-completion @@ -0,0 +1,19 @@ +_pivpn() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + dashopts="-a -c -d -l -qr -r -h -u" + opts="add clients debug list qrcode remove help uninstall" + if [ "${#COMP_WORDS[@]}" -eq 2 ] + then + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${dashopts}" -- "${cur}") ) + else + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + fi + fi + return 0 +} +complete -F _pivpn pivpn From 580e1b128e485cdafd8fefd30548e2dfe8c742da Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 2 Dec 2019 18:58:29 +0100 Subject: [PATCH 20/79] Accept debug fixes using just the enter key --- scripts/openvpn/pivpnDebug.sh | 24 ++++++++++++------------ scripts/wireguard/pivpnDEBUG.sh | 18 +++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index c3ce10d..f5cc4bb 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -43,7 +43,7 @@ if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then else ERR=1 read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf sysctl -p echo "Done" @@ -57,7 +57,7 @@ if [ "$USING_UFW" -eq 0 ]; then else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then iptables -t nat -F iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE iptables-save > /etc/iptables/rules.v4 @@ -73,7 +73,7 @@ if [ "$USING_UFW" -eq 0 ]; then else ERR=1 read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT iptables-save > /etc/iptables/rules.v4 echo "Done" @@ -88,7 +88,7 @@ if [ "$USING_UFW" -eq 0 ]; then else ERR=1 read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT iptables-save > /etc/iptables/rules.v4 @@ -104,7 +104,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then ufw enable fi fi @@ -114,7 +114,7 @@ else else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules ufw reload echo "Done" @@ -126,7 +126,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then ufw insert 1 allow "$pivpnPORT"/"$pivpnPROTO" ufw reload echo "Done" @@ -140,7 +140,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw forwarding policy is not 'ACCEPT', attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw ufw reload > /dev/null echo "Done" @@ -152,7 +152,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any ufw reload echo "Done" @@ -167,7 +167,7 @@ if systemctl is-active -q openvpn; then else ERR=1 read -r -p ":: [ERR] OpenVPN is not running, try to start now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then systemctl start openvpn echo "Done" fi @@ -178,7 +178,7 @@ if systemctl is-enabled -q openvpn; then else ERR=1 read -r -p ":: [ERR] OpenVPN is not enabled, try to enable now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then systemctl enable openvpn echo "Done" fi @@ -190,7 +190,7 @@ if netstat -uanpt | grep openvpn | grep -w "${pivpnPORT}" | grep -q "${pivpnPROT else ERR=1 read -r -p ":: [ERR] OpenVPN is not listening, try to restart now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then systemctl restart openvpn echo "Done" fi diff --git a/scripts/wireguard/pivpnDEBUG.sh b/scripts/wireguard/pivpnDEBUG.sh index b7c0311..682dd98 100755 --- a/scripts/wireguard/pivpnDEBUG.sh +++ b/scripts/wireguard/pivpnDEBUG.sh @@ -54,7 +54,7 @@ if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then else ERR=1 read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf sysctl -p echo "Done" @@ -68,7 +68,7 @@ if [ "$USING_UFW" -eq 0 ]; then else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then iptables -t nat -F iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE iptables-save > /etc/iptables/rules.v4 @@ -84,7 +84,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then ufw enable fi fi @@ -94,7 +94,7 @@ else else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules ufw reload echo "Done" @@ -106,7 +106,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then ufw insert 1 allow "$pivpnPORT"/udp ufw reload echo "Done" @@ -118,7 +118,7 @@ else else ERR=1 read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then ufw route insert 1 allow in on wg0 from 10.6.0.0/24 out on "$IPv4dev" to any ufw reload echo "Done" @@ -132,7 +132,7 @@ if systemctl is-active -q wg-quick@wg0; then else ERR=1 read -r -p ":: [ERR] WireGuard is not running, try to start now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then systemctl start wg-quick@wg0 echo "Done" fi @@ -143,7 +143,7 @@ if systemctl is-enabled -q wg-quick@wg0; then else ERR=1 read -r -p ":: [ERR] WireGuard is not enabled, try to enable now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then systemctl enable wg-quick@wg0 echo "Done" fi @@ -155,7 +155,7 @@ if netstat -uanp | grep -w "${pivpnPORT}" | grep -q 'udp'; then else ERR=1 read -r -p ":: [ERR] WireGuard is not listening, try to restart now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]]; then + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then systemctl restart wg-quick@wg0 echo "Done" fi From 4466f1503c9797808d49d8cb55063bec5a79deed Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 3 Dec 2019 17:59:27 +0100 Subject: [PATCH 21/79] Better client stats formatting --- auto_install/install.sh | 6 +++--- scripts/openvpn/clientStat.sh | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 35a86cf..2305458 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -698,9 +698,9 @@ askWhichVPN(){ installOpenVPN(){ echo "::: Installing OpenVPN from Debian package... " - # grepcidr is used to redact IPs in the debug log, whereas expect is used - # to feed easy-rsa with passwords - PIVPN_DEPS=(openvpn grepcidr expect) + # grepcidr is used to redact IPs in the debug log, expect is used to feed easy-rsa + # with passwords, bsdmainutils provides column to format the terminal output + PIVPN_DEPS=(openvpn grepcidr expect bsdmainutils) installDependentPackages PIVPN_DEPS[@] } diff --git a/scripts/openvpn/clientStat.sh b/scripts/openvpn/clientStat.sh index 2af420f..ef04114 100755 --- a/scripts/openvpn/clientStat.sh +++ b/scripts/openvpn/clientStat.sh @@ -17,15 +17,17 @@ printf ": NOTE : The output below is NOT real-time!\n" printf ": : It may be off by a few minutes.\n" printf "\n" printf "\e[1m::: Client Status List :::\e[0m\n" -printf "\t\t\t\t\t\t\t\tBytes\t\tBytes\t\n" -printf "\e[4mName\e[0m\t\t\t\e[4mRemote IP\e[0m\t\t\e[4mVirtual IP\e[0m\t\e[4mReceived\e[0m\t\e[4mSent\e[0m\t\t\e[4mConnected Since\e[0m \n" + +{ +printf "\e[4mName\e[0m \t \e[4mRemote IP\e[0m \t \e[4mVirtual IP\e[0m \t \e[4mBytes Received\e[0m \t \e[4mBytes Sent\e[0m \t \e[4mConnected Since\e[0m\n" + if grep -q "^CLIENT_LIST" "${STATUS_LOG}"; then if [ -n "$(type -t numfmt)" ]; then while read -r line; do read -r -a array <<< $line [[ ${array[0]} = CLIENT_LIST ]] || continue - printf "%s\t\t%s\t%s\t%s\t\t%s\t\t%s %s %s - %s\n" ${array[1]} ${array[2]} ${array[3]} $(hr ${array[4]}) $(hr ${array[5]}) ${array[7]} ${array[8]} ${array[10]} ${array[9]} - done <$STATUS_LOG + printf "%s \t %s \t %s \t %s \t %s \t %s %s %s - %s\n" ${array[1]} ${array[2]} ${array[3]} $(hr ${array[4]}) $(hr ${array[5]}) ${array[7]} ${array[8]} ${array[10]} ${array[9]} + done <$STATUS_LOG else awk -F' ' -v s='CLIENT_LIST' '$1 == s {print $2"\t\t"$3"\t"$4"\t"$5"\t\t"$6"\t\t"$8" "$9" "$11" - "$10"\n"}' ${STATUS_LOG} fi @@ -33,3 +35,4 @@ else printf "\nNo Clients Connected!\n" fi printf "\n" +} | column -t -s $'\t' \ No newline at end of file From 93044d6f6d9c4d2a0c086ab4605402937c801792 Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 16:13:26 +0100 Subject: [PATCH 22/79] add local resolver as DNS option. Signed-off-by: corbolais --- auto_install/install.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 2305458..9e96e95 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -975,7 +975,11 @@ askClientDNS(){ fi fi - DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients (press space to select). To use your own, select Custom." ${r} ${c} 6) + DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider + for your VPN Clients (press space to select). To use your own, select + Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select + \"PiVPN-is-local-DNS\" and make sure your resolver is listening on + 10.8.0.1, allowing requests from 10.8.0.1/8" ${r} ${c} 6) DNSChooseOptions=(Google "" on OpenDNS "" off Level3 "" off @@ -983,6 +987,7 @@ askClientDNS(){ Norton "" off FamilyShield "" off CloudFlare "" off + PiVPN-is-local-DNS "" off Custom "" off) if DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) @@ -997,7 +1002,8 @@ askClientDNS(){ ["DNS.WATCH"]="84.200.69.80 84.200.70.40" ["Norton"]="199.85.126.10 199.85.127.10" ["FamilyShield"]="208.67.222.123 208.67.220.123" - ["CloudFlare"]="1.1.1.1 1.0.0.1") + ["CloudFlare"]="1.1.1.1 1.0.0.1" + ["PiVPN-is-local-DNS"]="10.8.0.1") pivpnDNS1=$(awk '{print $1}' <<< "${DNS_MAP["${DNSchoices}"]}") pivpnDNS2=$(awk '{print $2}' <<< "${DNS_MAP["${DNSchoices}"]}") From 8affc9a3133d0ef2634b1dd17b8d81cfd5ba74e7 Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 16:39:46 +0100 Subject: [PATCH 23/79] debian openvpn has dedicated user and group, so rather use those than nobody:nogroup (as do _many_ other packages and thus all having access to such owned files). Signed-off-by: corbolais --- auto_install/install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 2305458..47f08bb 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -14,6 +14,8 @@ setupVars=/etc/pivpn/setupVars.conf pivpnFilesDir="/etc/.pivpn" +debianOvpnUserGroup="openvpn:openvpn" + ### PKG Vars ### PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" @@ -1290,7 +1292,11 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null # Generate an empty Certificate Revocation List ${SUDOE} ./easyrsa gen-crl ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem - ${SUDOE} chown nobody:nogroup /etc/openvpn/crl.pem + if test "${PLAT}" = "Debian"; then + ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem + else + ${SUDOE} chown nobody:nogroup /etc/openvpn/crl.pem + fi # Write config file for server using the template.txt file $SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf From 9c62fe09914e50ce1d0d0136c0e1a917558d20cb Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 17:18:08 +0100 Subject: [PATCH 24/79] take care of /etc/ufw/before.rules nat section. safeguard against accidentally killing the file. Signed-off-by: corbolais --- auto_install/install.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 2305458..2a44295 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1401,7 +1401,20 @@ confNetwork(){ USING_UFW=1 echo "::: Detected UFW is enabled." echo "::: Adding UFW rules..." - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + ### Basic safeguard: if file is empty, there's been something weird going on. + ### Note: no safeguard against imcomplete content as a result of previous failures. + if test -s /etc/ufw/before.rules; then + $SUDO cp -f /etc/ufw/before.rules /etc/ufw/before.rules.pre-pivpn + else + echo "$0: ERR: Sorry, won't touch empty file \"/etc/ufw/before.rules\"."; + exit 1; + fi + ### If there is already a "*nat" section just add our POSTROUTING MASQUERADE + if grep -q "*nat" /etc/ufw/before.rules; then + $SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE/}" -i /etc/ufw/before.rules + else + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + fi # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any >/dev/null From 6e763e024053aa04be666929fd6b713de1d5f05e Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 17:34:57 +0100 Subject: [PATCH 25/79] Debian: add openvpn user/group if missing. Signed-off-by: corbolais --- auto_install/install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/auto_install/install.sh b/auto_install/install.sh index 47f08bb..e5d6bbb 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1293,6 +1293,9 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} ./easyrsa gen-crl ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem if test "${PLAT}" = "Debian"; then + if ! getent passwd openvpn; then + ${SUDOE} adduser --system --home /etc/openvpn/ --no-create-home --group ${debianOvpnUserGroup%:*} + fi ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem else ${SUDOE} chown nobody:nogroup /etc/openvpn/crl.pem From 1aa6472b726e579e48cba2196f535ceda7e2ad32 Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 17:40:30 +0100 Subject: [PATCH 26/79] chg: openvpn-user home, shell. Signed-off-by: corbolais --- auto_install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index e5d6bbb..1d02f7c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1294,7 +1294,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem if test "${PLAT}" = "Debian"; then if ! getent passwd openvpn; then - ${SUDOE} adduser --system --home /etc/openvpn/ --no-create-home --group ${debianOvpnUserGroup%:*} + ${SUDOE} adduser --system --home /var/lib/openvpn/ --no-create-home --group --disabled-login ${debianOvpnUserGroup%:*} fi ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem else From 47c84e6a45a9142800f4669cf4a5e72ac0c36122 Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 17:55:43 +0100 Subject: [PATCH 27/79] add missing bang to shebang. correct usage of cp. correct wrong copy target dir. safeguard sudo-rm-rf. safeguard against variable expansion into IFS chars. clean up whitespace. Signed-off-by: corbolais --- scripts/openvpn/update.sh | 57 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/scripts/openvpn/update.sh b/scripts/openvpn/update.sh index eac73d5..5203b65 100755 --- a/scripts/openvpn/update.sh +++ b/scripts/openvpn/update.sh @@ -4,8 +4,8 @@ ###Main Vars pivpnrepo="https://github.com/pivpn/pivpn.git" pivpnlocalpath="/etc/.pivpn" -pivpnscripts="/opt/pivpn/scripts" -bashcompletiondir="/etc/bash_completion.d/pivpn" +pivpnscripts="/opt/pivpn/" +bashcompletiondir="/etc/bash_completion.d/" ###Functions @@ -14,13 +14,13 @@ updatepivpnscripts(){ ##We don't know what sort of changes users have made. ##Lets remove first /etc/.pivpn dir then clone it back again echo "going do update PiVPN Scripts" - if [[ -d $pivpnlocalpath ]]; then - - sudo rm -rf $pivpnlocalpath + if [[ -d "$pivpnlocalpath" ]]; then + if [[ -n "$pivpnlocalpath" ]]; then + sudo rm -rf "${pivpnlocalpath}/../.pivpn" cloneandupdate - + fi else - cloneandupdate + cloneandupdate fi echo "PiVPN Scripts have been updated" } @@ -30,62 +30,55 @@ updatefromtest(){ ##We don't know what sort of changes users have made. ##Lets remove first /etc/.pivpn dir then clone it back again echo "PiVPN Scripts updating from test branch" - if [[ -d /etc/.pivpn ]]; then - - rm -rf /etc/.pivpn + if [[ -d "$pivpnlocalpath" ]]; then + if [[ -n "$pivpnlocalpath" ]]; then + rm -rf "{$pivpnlocalpath}/../.pivpn" cloneupdttest - + fi else - - cloneupdttest - + cloneupdttest fi echo "PiVPN Scripts updated have been updated from test branch" } ##Clone and copy pivpn scripts to /op/ cloneandupdate(){ - - sudo git clone $pivpnrepo $pivpnlocalpath - sudo cp -r $pivpnlocalpath/scripts $pivpnscripts - sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir - + sudo git clone "$pivpnrepo" "$pivpnlocalpath" + sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" + sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" } ##same as cloneandupdate() but from test branch ##and falls back to master branch again after updating cloneupdttest(){ - - sudo git clone $pivpnrepo $pivpnlocalpath - sudo git -C $pivpnlocalpath checkout test - sudo git -C $pivpnlocalpath pull origin test - sudo cp -r $pivpnlocalpath/scripts $pivpnscripts - sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir - sudo git -C $pivpnlocalpath checkout master - + sudo git clone "$pivpnrepo" "$pivpnlocalpath" + sudo git -C "$pivpnlocalpath" checkout test + sudo git -C "$pivpnlocalpath" pull origin test + sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" + sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" + sudo git -C "$pivpnlocalpath" checkout master } scriptusage(){ - echo -e "Updates pivpn scripts,\n + echo -e "Updates pivpn scripts, + Usage: pivpn update | updates from master branch pivpn update -t or --test | updates from test branch" - } ## SCRIPT if [[ $# -eq 0 ]]; then updatepivpnscripts - else while true; do case "$1" in - -t | --test | test ) + -t|--test|test) updatefromtest exit 0 ;; - -h | --help | help ) + -h|--help|help) scriptusage exit 0 ;; From a05754ea192c33c9c65660aee4ad42788e07765d Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 20:14:23 +0100 Subject: [PATCH 28/79] shellcheck install.sh. render into sound bashing. correct sed call. Signed-off-by: corbolais --- auto_install/install.sh | 149 +++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 72 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 2305458..bd7abad 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -39,8 +39,8 @@ UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_ # Find the rows and columns. Will default to 80x24 if it can not be detected. screen_size=$(stty size 2>/dev/null || echo 24 80) -rows=$(echo $screen_size | awk '{print $1}') -columns=$(echo $screen_size | awk '{print $2}') +rows=$(echo "$screen_size" | awk '{print $1}') +columns=$(echo "$screen_size" | awk '{print $2}') runUnattended=false @@ -101,6 +101,7 @@ distroCheck(){ else # else get info from os-release + # shellcheck disable=SC1091 source /etc/os-release PLAT=$(awk '{print $1}' <<< "$NAME") VER="$VERSION_ID" @@ -142,7 +143,7 @@ checkHostname(){ exit 1 fi until [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; do - host_name=$(whiptail --inputbox "Your hostname is too long.\nEnter new hostname with less then 28 characters\nNo special characters allowed." \ + host_name=$(whiptail --inputbox "Your hostname is too long.\\nEnter new hostname with less then 28 characters\\nNo special characters allowed." \ --title "Hostname too long" ${r} ${c} 3>&1 1>&2 2>&3) $SUDO hostnamectl set-hostname "${host_name}" if [[ ${#host_name} -le 28 && $host_name =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{1,28}$ ]]; then @@ -159,21 +160,22 @@ spinner(){ local pid=$1 local delay=0.50 local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do + while ps a | awk '{print $1}' | grep "${pid}"; do local temp=${spinstr#?} printf " [%c] " "${spinstr}" local spinstr=${temp}${spinstr%"$temp"} sleep ${delay} - printf "\b\b\b\b\b\b" + printf "\\b\\b\\b\\b\\b\\b" done - printf " \b\b\b\b" + printf " \\b\\b\\b\\b" } verifyFreeDiskSpace(){ # If user installs unattended-upgrades we'd need about 60MB so will check for 75MB free echo "::: Verifying free disk space..." local required_free_kilobytes=76800 - local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') + local existing_free_kilobytes + existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') # - Unknown free disk space , not a integer if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then @@ -220,8 +222,8 @@ updatePackageCache(){ if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists echo ":::" - echo -ne "::: ${PKG_MANAGER} update has not been run today. Running now...\n" - $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + echo -ne "::: ${PKG_MANAGER} update has not been run today. Running now...\\n" + $SUDO "${UPDATE_PKG_CACHE}" &> /dev/null echo " done!" fi } @@ -274,7 +276,7 @@ installDependentPackages(){ done if command -v debconf-apt-progress &> /dev/null; then - $SUDO debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" + $SUDO debconf-apt-progress -- "${PKG_INSTALL}" "${argArray1[@]}" else ${PKG_INSTALL} "${argArray1[@]}" fi @@ -347,9 +349,9 @@ chooseInterface(){ # Find out how many interfaces are available to choose from interfaceCount=$(echo "${availableInterfaces}" | wc -l) - chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select):" ${r} ${c} ${interfaceCount}) - chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]]; then + chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An + Interface (press space to select):" "${r}" "${c}" "${interfaceCount}") + if chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) ; then for desiredInterface in ${chooseInterfaceOptions}; do IPv4dev=${desiredInterface} echo "::: Using interface: $IPv4dev" @@ -380,7 +382,7 @@ validIP(){ if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS IFS='.' - ip=($ip) + read -r -a ip <<< "$ip" IFS=$OIFS [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] @@ -456,12 +458,10 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Start a loop to let the user enter their information with the chance to go back and edit it if necessary until [[ ${ipSettingsCorrect} = True ]]; do # Ask for the IPv4 address - IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4addr}" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]]; then + if IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4addr}" 3>&1 1>&2 2>&3) ; then echo "::: Your static IPv4 address: ${IPv4addr}" # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]]; then + if IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) ; then echo "::: Your static IPv4 gateway: ${IPv4gw}" # Give the user a chance to review their settings before moving on if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? @@ -556,8 +556,7 @@ chooseUser(){ # See http://askubuntu.com/a/667842/459815 PASSWORD=$(whiptail --title "password dialog" --passwordbox "Please enter the new user password" ${r} ${c} 3>&1 1>&2 2>&3) CRYPT=$(perl -e 'printf("%s\n", crypt($ARGV[0], "password"))' "${PASSWORD}") - $SUDO useradd -m -p "${CRYPT}" -s /bin/bash "${userToAdd}" - if [[ $? = 0 ]]; then + if $SUDO useradd -m -p "${CRYPT}" -s /bin/bash "${userToAdd}" ; then echo "Succeeded" ((numUsers+=1)) else @@ -580,9 +579,9 @@ chooseUser(){ fi userArray+=("${line}" "" "${mode}") done <<< "${availableUsers}" - chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist "Choose (press space to select):" ${r} ${c} ${numUsers}) - chooseUserOptions=$("${chooseUserCmd[@]}" "${userArray[@]}" 2>&1 >/dev/tty) - if [[ $? = 0 ]]; then + chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist + "Choose (press space to select):" "${r}" "${c}" "${numUsers}") + if chooseUserOptions=$("${chooseUserCmd[@]}" "${userArray[@]}" 2>&1 >/dev/tty) ; then for desiredUser in ${chooseUserOptions}; do install_user=${desiredUser} echo "::: Using User: $install_user" @@ -610,10 +609,10 @@ updateRepo(){ # Pull the latest commits echo -n "::: Updating repo in $1..." $SUDO rm -rf "${1}" - # Go back to /etc otherwhise git will complain when the current working + # Go back to /etc otherwise git will complain when the current working # directory has just been deleted (/etc/.pivpn). - cd /etc - $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + cd /etc && \ + $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! cd "${1}" || exit 1 if [ -z "${TESTING+x}" ]; then : @@ -629,8 +628,8 @@ makeRepo(){ $SUDO rm -rf "${1}" # Go back to /etc otherwhise git will complain when the current working # directory has just been deleted (/etc/.pivpn). - cd /etc - $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + cd /etc && \ + $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! cd "${1}" || exit 1 if [ -z "${TESTING+x}" ]; then : @@ -676,7 +675,7 @@ askWhichVPN(){ fi fi else - if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\n\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\n\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\n\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); + if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); then VPN="wireguard" else @@ -700,6 +699,7 @@ installOpenVPN(){ echo "::: Installing OpenVPN from Debian package... " # grepcidr is used to redact IPs in the debug log, expect is used to feed easy-rsa # with passwords, bsdmainutils provides column to format the terminal output + local PIVPN_DEPS PIVPN_DEPS=(openvpn grepcidr expect bsdmainutils) installDependentPackages PIVPN_DEPS[@] } @@ -725,7 +725,7 @@ installWireGuard(){ printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 - $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + $SUDO "${UPDATE_PKG_CACHE}" &> /dev/null PIVPN_DEPS=(raspberrypi-kernel-headers wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] @@ -745,11 +745,11 @@ installWireGuard(){ wget -qO- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src echo "done!" - cd /usr/src + cd /usr/src && \ $SUDO mv WireGuard-"${WG_SNAPSHOT}" wireguard-"${WG_SNAPSHOT}" - cd wireguard-"${WG_SNAPSHOT}" - $SUDO mv src/* . - $SUDO rmdir src + cd wireguard-"${WG_SNAPSHOT}" && \ + $SUDO mv src/* . && \ + $SUDO rmdir src # We install the userspace tools manually since DKMS only compiles and # installs the kernel module @@ -811,7 +811,7 @@ installWireGuard(){ echo "::: Adding Debian repository... " echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null - $SUDO ${UPDATE_PKG_CACHE} &> /dev/null + $SUDO "${UPDATE_PKG_CACHE}" &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] @@ -900,7 +900,7 @@ askCustomPort(){ fi fi - if pivpnPORT=$(whiptail --title "Default $VPN Port" --inputbox "You can modify the default $VPN port. \nEnter a new value or hit 'Enter' to retain the default" ${r} ${c} $DEFAULT_PORT 3>&1 1>&2 2>&3) + if pivpnPORT=$(whiptail --title "Default $VPN Port" --inputbox "You can modify the default $VPN port. \\nEnter a new value or hit 'Enter' to retain the default" ${r} ${c} $DEFAULT_PORT 3>&1 1>&2 2>&3) then if [[ "$pivpnPORT" =~ ^[0-9]+$ ]] && [ "$pivpnPORT" -ge 1 ] && [ "$pivpnPORT" -le 65535 ]; then : @@ -913,10 +913,10 @@ askCustomPort(){ fi if [[ $pivpnPORT == "$portInvalid" ]]; then - whiptail --msgbox --backtitle "Invalid Port" --title "Invalid Port" "You entered an invalid Port number.\n Please enter a number from 1 - 65535.\n If you are not sure, please just keep the default." ${r} ${c} + whiptail --msgbox --backtitle "Invalid Port" --title "Invalid Port" "You entered an invalid Port number.\\n Please enter a number from 1 - 65535.\\n If you are not sure, please just keep the default." ${r} ${c} PORTNumCorrect=False else - if (whiptail --backtitle "Specify Custom Port" --title "Confirm Custom Port Number" --yesno "Are these settings correct?\n PORT: $pivpnPORT" ${r} ${c}) then + if (whiptail --backtitle "Specify Custom Port" --title "Confirm Custom Port Number" --yesno "Are these settings correct?\\n PORT: $pivpnPORT" ${r} ${c}) then PORTNumCorrect=True else # If the settings are wrong, the loop continues @@ -975,7 +975,9 @@ askClientDNS(){ fi fi - DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients (press space to select). To use your own, select Custom." ${r} ${c} 6) + DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider + for your VPN Clients (press space to select). To use your own, select Custom." + "${r}" "${c}" 6) DNSChooseOptions=(Google "" on OpenDNS "" off Level3 "" off @@ -1007,7 +1009,7 @@ askClientDNS(){ until [[ $DNSSettingsCorrect = True ]]; do strInvalid="Invalid" - if pivpnDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "" 3>&1 1>&2 2>&3) + if pivpnDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\\n\\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "" 3>&1 1>&2 2>&3) then pivpnDNS1=$(echo "$pivpnDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') pivpnDNS2=$(echo "$pivpnDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') @@ -1023,7 +1025,7 @@ askClientDNS(){ fi if [[ $pivpnDNS1 == "$strInvalid" ]] || [[ $pivpnDNS2 == "$strInvalid" ]]; then - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $pivpnDNS1\n DNS Server 2: $pivpnDNS2" ${r} ${c} + whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\\n\\n DNS Server 1: $pivpnDNS1\\n DNS Server 2: $pivpnDNS2" ${r} ${c} if [[ $pivpnDNS1 == "$strInvalid" ]]; then pivpnDNS1="" fi @@ -1032,7 +1034,7 @@ askClientDNS(){ fi DNSSettingsCorrect=False else - if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $pivpnDNS1\n DNS Server 2: $pivpnDNS2" ${r} ${c}) then + if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\\n DNS Server 1: $pivpnDNS1\\n DNS Server 2: $pivpnDNS2" ${r} ${c}) then DNSSettingsCorrect=True else # If the settings are wrong, the loop continues @@ -1081,20 +1083,20 @@ askCustomDomain(){ DomainSettingsCorrect=False - if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno --defaultno "Would you like to add a custom search domain? \n (This is only for advanced users who have their own domain)\n" ${r} ${c}); then + if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno --defaultno "Would you like to add a custom search domain? \\n (This is only for advanced users who have their own domain)\\n" ${r} ${c}); then until [[ $DomainSettingsCorrect = True ]] do - if pivpnSEARCHDOMAIN=$(whiptail --inputbox "Enter Custom Domain\nFormat: mydomain.com" ${r} ${c} --title "Custom Domain" 3>&1 1>&2 2>&3); then + if pivpnSEARCHDOMAIN=$(whiptail --inputbox "Enter Custom Domain\\nFormat: mydomain.com" ${r} ${c} --title "Custom Domain" 3>&1 1>&2 2>&3); then if validDomain "$pivpnSEARCHDOMAIN"; then - if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\n Custom Search Domain: $pivpnSEARCHDOMAIN" ${r} ${c}); then + if (whiptail --backtitle "Custom Search Domain" --title "Custom Search Domain" --yesno "Are these settings correct?\\n Custom Search Domain: $pivpnSEARCHDOMAIN" ${r} ${c}); then DomainSettingsCorrect=True else # If the settings are wrong, the loop continues DomainSettingsCorrect=False fi else - whiptail --msgbox --backtitle "Invalid Domain" --title "Invalid Domain" "Domain is invalid. Please try again.\n\n DOMAIN: $pivpnSEARCHDOMAIN\n" ${r} ${c} + whiptail --msgbox --backtitle "Invalid Domain" --title "Invalid Domain" "Domain is invalid. Please try again.\\n\\n DOMAIN: $pivpnSEARCHDOMAIN\\n" ${r} ${c} DomainSettingsCorrect=False fi else @@ -1155,7 +1157,7 @@ askPublicIPOrDNS(){ echo "::: Cancel selected. Exiting..." exit 1 fi - if (whiptail --backtitle "Confirm DNS Name" --title "Confirm DNS Name" --yesno "Is this correct?\n\n Public DNS Name: $PUBLICDNS" ${r} ${c}) then + if (whiptail --backtitle "Confirm DNS Name" --title "Confirm DNS Name" --yesno "Is this correct?\\n\\n Public DNS Name: $PUBLICDNS" ${r} ${c}) then publicDNSCorrect=True pivpnHOST="${PUBLICDNS}" else @@ -1194,7 +1196,7 @@ askEncryption(){ fi pivpnENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "RSA certificate size" --radiolist \ - "Choose the desired size of your certificate (press space to select):\nThis is a certificate that will be generated on your system. The larger the certificate, the more time this will take. For most applications, it is recommended to use 2048 bits. If you are paranoid about ... things... then grab a cup of joe and pick 4096 bits." ${r} ${c} 3 \ + "Choose the desired size of your certificate (press space to select):\\nThis is a certificate that will be generated on your system. The larger the certificate, the more time this will take. For most applications, it is recommended to use 2048 bits. If you are paranoid about ... things... then grab a cup of joe and pick 4096 bits." ${r} ${c} 3 \ "2048" "Use a 2048-bit certificate (recommended level)" ON \ "3072" "Use a 3072-bit certificate " OFF \ "4096" "Use a 4096-bit certificate (paranoid level)" OFF 3>&1 1>&2 2>&3) @@ -1205,7 +1207,7 @@ askEncryption(){ exit 1 fi - if ([ "$pivpnENCRYPT" -ge "3072" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\n\nGenerating DH parameters for a $pivpnENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from their database.\nMore information about this service can be found here: https://2ton.com.au/safeprimes/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}); then + if ([ "$pivpnENCRYPT" -ge "3072" ] && whiptail --backtitle "Setup OpenVPN" --title "Download Diffie-Hellman Parameters" --yesno --defaultno "Download Diffie-Hellman parameters from a public DH parameter generation service?\\n\\nGenerating DH parameters for a $pivpnENCRYPT-bit key can take many hours on a Raspberry Pi. You can instead download DH parameters from \"2 Ton Digital\" that are generated at regular intervals as part of a public service. Downloaded DH parameters will be randomly selected from their database.\\nMore information about this service can be found here: https://2ton.com.au/safeprimes/\\n\\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}); then DOWNLOAD_DH_PARAM=1 else DOWNLOAD_DH_PARAM=0 @@ -1262,9 +1264,9 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} ./easyrsa --batch init-pki # Build the certificate authority - printf "::: Building CA...\n" + printf "::: Building CA...\\n" ${SUDOE} ./easyrsa --batch build-ca nopass - printf "\n::: CA Complete.\n" + printf "\\n::: CA Complete.\\n" if [ "${runUnattended}" = 'true' ]; then echo "::: The server key, Diffie-Hellman parameters, and HMAC key will now be generated." @@ -1273,7 +1275,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null fi # Build the server - EASYRSA_CERT_EXPIRE=3650 ${SUDOE} ./easyrsa build-server-full ${SERVER_NAME} nopass + EASYRSA_CERT_EXPIRE=3650 ${SUDOE} ./easyrsa build-server-full "${SERVER_NAME}" nopass if [ ${DOWNLOAD_DH_PARAM} -eq 1 ]; then # Downloading parameters @@ -1281,7 +1283,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null else # Generate Diffie-Hellman key exchange ${SUDOE} ./easyrsa gen-dh - ${SUDOE} mv pki/dh.pem pki/dh${pivpnENCRYPT}.pem + ${SUDOE} mv "pki/dh.pem pki/dh${pivpnENCRYPT}.pem" fi # Generate static HMAC key to defend against DDoS @@ -1305,7 +1307,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null fi # Set the user encryption key size - $SUDO sed -i "s/\(dh \/etc\/openvpn\/easy-rsa\/pki\/dh\).*/\1${pivpnENCRYPT}.pem/" /etc/openvpn/server.conf + $SUDO sed -i "s#\\(dh /etc/openvpn/easy-rsa/pki/dh\\).*#\\1${pivpnENCRYPT}.pem#" /etc/openvpn/server.conf # if they modified port put value in server.conf if [ "$pivpnPORT" != 1194 ]; then @@ -1318,12 +1320,12 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null fi if [ -n "$pivpnSEARCHDOMAIN" ]; then - $SUDO sed -i "0,/\(.*dhcp-option.*\)/s//\push \"dhcp-option DOMAIN ${pivpnSEARCHDOMAIN}\" \n&/" /etc/openvpn/server.conf + $SUDO sed -i "0,/\\(.*dhcp-option.*\\)/s//push \"dhcp-option DOMAIN ${pivpnSEARCHDOMAIN}\" \\n&/" /etc/openvpn/server.conf fi # write out server certs to conf file - $SUDO sed -i "s/\(key \/etc\/openvpn\/easy-rsa\/pki\/private\/\).*/\1${SERVER_NAME}.key/" /etc/openvpn/server.conf - $SUDO sed -i "s/\(cert \/etc\/openvpn\/easy-rsa\/pki\/issued\/\).*/\1${SERVER_NAME}.crt/" /etc/openvpn/server.conf + $SUDO sed -i "s#\\(key /etc/openvpn/easy-rsa/pki/private/\\).*#\\1${SERVER_NAME}.key#" /etc/openvpn/server.conf + $SUDO sed -i "s#\\(cert /etc/openvpn/easy-rsa/pki/issued/\\).*#\\1${SERVER_NAME}.crt#" /etc/openvpn/server.conf } confOVPN(){ @@ -1401,7 +1403,7 @@ confNetwork(){ USING_UFW=1 echo "::: Detected UFW is enabled." echo "::: Adding UFW rules..." - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + $SUDO sed "/delete these required/i *nat\\n:POSTROUTING ACCEPT [0:0]\\n-I POSTROUTING -s ${pivpnNET}\\/24 -o ${IPv4dev} -j MASQUERADE\\nCOMMIT\\n" -i /etc/ufw/before.rules # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any >/dev/null @@ -1531,7 +1533,7 @@ askUnattendedUpgrades(){ return fi - whiptail --msgbox --backtitle "Security Updates" --title "Unattended Upgrades" "Since this server will have at least one port open to the internet, it is recommended you enable unattended-upgrades.\nThis feature will check daily for security package updates only and apply them when necessary.\nIt will NOT automatically reboot the server so to fully apply some updates you should periodically reboot." ${r} ${c} + whiptail --msgbox --backtitle "Security Updates" --title "Unattended Upgrades" "Since this server will have at least one port open to the internet, it is recommended you enable unattended-upgrades.\\nThis feature will check daily for security package updates only and apply them when necessary.\\nIt will NOT automatically reboot the server so to fully apply some updates you should periodically reboot." ${r} ${c} if (whiptail --backtitle "Security Updates" --title "Unattended Upgrades" --yesno "Do you want to enable unattended upgrades of security patches to this server?" ${r} ${c}); then UNATTUPG=1 @@ -1543,10 +1545,10 @@ askUnattendedUpgrades(){ } confUnattendedUpgrades(){ - PIVPN_DEPS=(unattended-upgrades) + local PIVPN_DEPS + PIVPN_DEPS+=(unattended-upgrades) installDependentPackages PIVPN_DEPS[@] - - cd /etc/apt/apt.conf.d + aptConfDir="/etc/apt/apt.conf.d" if [ "$PLAT" = "Ubuntu" ]; then @@ -1555,15 +1557,16 @@ confUnattendedUpgrades(){ echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Download-Upgradeable-Packages \"1\"; APT::Periodic::AutocleanInterval \"5\"; - APT::Periodic::Unattended-Upgrade \"1\";" | $SUDO tee 10periodic > /dev/null + APT::Periodic::Unattended-Upgrade \"1\";" | $SUDO tee "${aptConfDir}/10periodic" > /dev/null else # Fix Raspbian config if [ "$PLAT" = "Raspbian" ]; then - wget -qO- "$UNATTUPG_CONFIG" | $SUDO tar xz - $SUDO cp "unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" 50unattended-upgrades - $SUDO rm -rf "unattended-upgrades-$UNATTUPG_RELEASE" + wget -q -O "/tmp/${UNATTUPG_RELEASE}.tar.gz" "$UNATTUPG_CONFIG" + cd /tmp/ && $SUDO tar xzf "/tmp/${UNATTUPG_RELEASE}.tar.gz" + $SUDO cp /tmp/"unattended-upgrades-$UNATTUPG_RELEASE/data/50unattended-upgrades.Raspbian" "${aptConfDir}/50unattended-upgrades" + $SUDO rm -rf "/tmp/unattended-upgrades-$UNATTUPG_RELEASE" fi # Add the remaining settings for all other distributions @@ -1572,14 +1575,14 @@ confUnattendedUpgrades(){ APT::Periodic::Download-Upgradeable-Packages \"1\"; APT::Periodic::Unattended-Upgrade \"1\"; APT::Periodic::AutocleanInterval \"7\"; - APT::Periodic::Verbose \"0\";" | $SUDO tee 02periodic > /dev/null + APT::Periodic::Verbose \"0\";" | $SUDO tee "${aptConfDir}/02periodic" > /dev/null fi # Enable automatic updates via the unstable repository when installing from debian package if [ "$VPN" = "wireguard" ] && [ "$PLAT" != "Ubuntu" ] && [ "$(uname -m)" != "armv6l" ]; then - if ! grep -q '"o=Debian,a=unstable";' 50unattended-upgrades; then - $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' 50unattended-upgrades + if ! grep -q '"o=Debian,a=unstable";' "${aptConfDir}/50unattended-upgrades"; then + $SUDO sed -i '/Unattended-Upgrade::Origins-Pattern {/a"o=Debian,a=unstable";' "${aptConfDir}/50unattended-upgrades" fi fi } @@ -1600,6 +1603,7 @@ installScripts(){ $SUDO cp /etc/.pivpn/scripts/$VPN/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn $SUDO cp /etc/.pivpn/scripts/$VPN/bash-completion /etc/bash_completion.d/pivpn + # shellcheck disable=SC1091 . /etc/bash_completion.d/pivpn echo " done." } @@ -1620,11 +1624,11 @@ displayFinalMessage(){ # Final completion message to user whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles. -Run 'pivpn help' to see what else you can do!\n\nIf you run into any issue, please read all our documentation carefully. -All incomplete posts or bug reports will be ignored or deleted.\n\nThank you for using PiVPN." ${r} ${c} +Run 'pivpn help' to see what else you can do!\\n\\nIf you run into any issue, please read all our documentation carefully. +All incomplete posts or bug reports will be ignored or deleted.\\n\\nThank you for using PiVPN." ${r} ${c} if (whiptail --title "Reboot" --yesno --defaultno "It is strongly recommended you reboot after installation. Would you like to reboot now?" ${r} ${c}); then whiptail --title "Rebooting" --msgbox "The system will now reboot." ${r} ${c} - printf "\nRebooting system...\n" + printf "\\nRebooting system...\\n" $SUDO sleep 3 $SUDO shutdown -r now fi @@ -1672,6 +1676,7 @@ main(){ echo "::: No configuration file passed, using default settings..." else if [ -r "$2" ]; then + # shellcheck disable=SC1090 source "$2" else echo "::: Can't open $2" From 3c280e0a94cd5aedee19fd729a15bad876c685fa Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 20:35:41 +0100 Subject: [PATCH 29/79] Mostly bug fixes. Mostly harmless. Signed-off-by: corbolais --- auto_install/install.sh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index bd7abad..4e9dded 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -75,12 +75,12 @@ If you think you received this message in error, you can post an issue on the Gi maybeOSSupport(){ if [ "${runUnattended}" = 'true' ]; then - echo "::: Not Supported OS" + echo "::: OS Not Supported" echo "::: You are on an OS that we have not tested but MAY work, continuing anyway..." return fi - if (whiptail --backtitle "Not Supported OS" --title "Not Supported OS" --yesno "You are on an OS that we have not tested but MAY work. + if (whiptail --backtitle "OS Not Supported" --title "OS Not Supported" --yesno "You are on an OS that we have not tested but MAY work. Currently this installer supports Raspbian (Buster). Would you like to continue anyway?" ${r} ${c}) then echo "::: Did not detect perfectly supported OS but," @@ -247,9 +247,11 @@ notifyPackageUpdatesAvailable(){ preconfigurePackages(){ # Add support for https repositories if there are any that use it otherwise the installation will silently fail - if grep -q https /etc/apt/sources.list; then - BASE_DEPS+=("apt-transport-https") - fi + if [[ -f /etc/apt/sources.list ]]; then + if grep -q https /etc/apt/sources.list; then + BASE_DEPS+=("apt-transport-https") + fi + fi if [[ ${OSCN} == "buster" ]]; then $SUDO update-alternatives --set iptables /usr/sbin/iptables-legacy @@ -276,7 +278,16 @@ installDependentPackages(){ done if command -v debconf-apt-progress &> /dev/null; then + set +e $SUDO debconf-apt-progress -- "${PKG_INSTALL}" "${argArray1[@]}" + res="$?"; + set -e + ### apt-get install above returns 100 after an otherwise successfull installation of iptables-persistent, + ### everything else was aready installed. + ### Prevent from exiting the installation script in this case, exit for any other error code. + if [[ "$res" -ne 100 ]]; then + exit "$res"; + fi; else ${PKG_INSTALL} "${argArray1[@]}" fi @@ -285,7 +296,7 @@ installDependentPackages(){ welcomeDialogs(){ if [ "${runUnattended}" = 'true' ]; then echo "::: PiVPN Automated Installer" - echo "::: This installer will transform your Raspberry Pi into an OpenVPN or WireGuard server!" + echo "::: This installer will transform your ${PLAT} host into an OpenVPN or WireGuard server!" echo "::: Initiating network interface" return fi @@ -625,7 +636,11 @@ updateRepo(){ makeRepo(){ # Remove the non-repos interface and clone the interface echo -n "::: Cloning $2 into $1..." - $SUDO rm -rf "${1}" + ### FIXME: Never call rm -rf with a plain variable. Never again as SU! + #$SUDO rm -rf "${1}" + if test -n "$1"; then + $SUDO rm -rf "$(dirname "$1")/.pivpn" + fi # Go back to /etc otherwhise git will complain when the current working # directory has just been deleted (/etc/.pivpn). cd /etc && \ @@ -1603,6 +1618,7 @@ installScripts(){ $SUDO cp /etc/.pivpn/scripts/$VPN/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn $SUDO cp /etc/.pivpn/scripts/$VPN/bash-completion /etc/bash_completion.d/pivpn + $SUDO chmod 0644 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 . /etc/bash_completion.d/pivpn echo " done." From e72786e8def5983b50b4265d7e06e174f76ed80b Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 20:37:41 +0100 Subject: [PATCH 30/79] W/space Signed-off-by: corbolais --- auto_install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 4e9dded..9555d60 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -639,7 +639,7 @@ makeRepo(){ ### FIXME: Never call rm -rf with a plain variable. Never again as SU! #$SUDO rm -rf "${1}" if test -n "$1"; then - $SUDO rm -rf "$(dirname "$1")/.pivpn" + $SUDO rm -rf "$(dirname "$1")/.pivpn" fi # Go back to /etc otherwhise git will complain when the current working # directory has just been deleted (/etc/.pivpn). From 55dc52d3e0f953d6c88dfce8e645439246eadc77 Mon Sep 17 00:00:00 2001 From: corbolais Date: Sun, 8 Dec 2019 20:41:11 +0100 Subject: [PATCH 31/79] use openvpn:openvpn user/group ownership unconditionally. Signed-off-by: corbolais --- auto_install/install.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 1d02f7c..8749870 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1292,14 +1292,10 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null # Generate an empty Certificate Revocation List ${SUDOE} ./easyrsa gen-crl ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem - if test "${PLAT}" = "Debian"; then - if ! getent passwd openvpn; then - ${SUDOE} adduser --system --home /var/lib/openvpn/ --no-create-home --group --disabled-login ${debianOvpnUserGroup%:*} - fi - ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem - else - ${SUDOE} chown nobody:nogroup /etc/openvpn/crl.pem + if ! getent passwd openvpn; then + ${SUDOE} adduser --system --home /var/lib/openvpn/ --no-create-home --group --disabled-login ${debianOvpnUserGroup%:*} fi + ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem # Write config file for server using the template.txt file $SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf From e76f3755aba453adde3c4d9153708d1dcc865369 Mon Sep 17 00:00:00 2001 From: corbolais Date: Mon, 9 Dec 2019 12:41:40 +0100 Subject: [PATCH 32/79] consistent use of pivpnNET, subnetClass and vpnGw. Signed-off-by: corbolais --- auto_install/install.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 9e96e95..9b0af3f 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -33,6 +33,8 @@ pivpnGitUrl="https://github.com/pivpn/pivpn.git" easyrsaVer="3.0.6" easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer}/EasyRSA-unix-v${easyrsaVer}.tgz" +subnetClass="24" + # Raspbian's unattended-upgrades package downloads Debian's config, so this is the link for the proper config UNATTUPG_RELEASE="1.14" UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_RELEASE}.tar.gz" @@ -692,6 +694,7 @@ askWhichVPN(){ pivpnDEV="tun0" pivpnNET="10.8.0.0" fi + vpnGw="${pivpnNET/.0/.1}" echo "VPN=${VPN}" >> /tmp/setupVars.conf } @@ -979,7 +982,7 @@ askClientDNS(){ for your VPN Clients (press space to select). To use your own, select Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select \"PiVPN-is-local-DNS\" and make sure your resolver is listening on - 10.8.0.1, allowing requests from 10.8.0.1/8" ${r} ${c} 6) + \"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6) DNSChooseOptions=(Google "" on OpenDNS "" off Level3 "" off @@ -1003,7 +1006,7 @@ askClientDNS(){ ["Norton"]="199.85.126.10 199.85.127.10" ["FamilyShield"]="208.67.222.123 208.67.220.123" ["CloudFlare"]="1.1.1.1 1.0.0.1" - ["PiVPN-is-local-DNS"]="10.8.0.1") + ["PiVPN-is-local-DNS"]="$vpnGw") pivpnDNS1=$(awk '{print $1}' <<< "${DNS_MAP["${DNSchoices}"]}") pivpnDNS2=$(awk '{print $2}' <<< "${DNS_MAP["${DNSchoices}"]}") @@ -1388,7 +1391,7 @@ confWireGuard(){ echo "[Interface] PrivateKey = $($SUDO cat /etc/wireguard/keys/server_priv) -Address = 10.6.0.1/24 +Address = ${vpnGw}/${subnetClass} ListenPort = ${pivpnPORT}" | $SUDO tee /etc/wireguard/wg0.conf &> /dev/null echo "::: Server config generated." } @@ -1407,10 +1410,10 @@ confNetwork(){ USING_UFW=1 echo "::: Detected UFW is enabled." echo "::: Adding UFW rules..." - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null - $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any >/dev/null + $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any >/dev/null $SUDO ufw reload >/dev/null echo "::: UFW configuration completed." @@ -1423,7 +1426,7 @@ confNetwork(){ # Now some checks to detect which rules we need to add. On a newly installed system all policies # should be ACCEPT, so the only required rule would be the MASQUERADE one. - $SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE + $SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE # Count how many rules are in the INPUT and FORWARD chain. When parsing input from # iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found @@ -1449,8 +1452,8 @@ confNetwork(){ fi if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I FORWARD 1 -d "${pivpnNET}/24" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - $SUDO iptables -I FORWARD 2 -s "${pivpnNET}/24" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT + $SUDO iptables -I FORWARD 1 -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + $SUDO iptables -I FORWARD 2 -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT FORWARD_CHAIN_EDITED=1 else FORWARD_CHAIN_EDITED=0 From 729674595bb9071fcbf06d4384c72fc456b4dcd4 Mon Sep 17 00:00:00 2001 From: corbolais Date: Mon, 9 Dec 2019 13:34:25 +0100 Subject: [PATCH 33/79] rm openvpn:openvpn user/group iff openvpn pkg is removed. shellcheck cleanup. preliminary fixes. add (global) FIXMEs. Signed-off-by: corbolais --- scripts/uninstall.sh | 59 +++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 6de5842..1647531 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash # PiVPN: Uninstall Script +### FIXME: global: config storage, refactor all scripts to adhere to the storage +### FIXME: use variables where appropriate, reduce magic numbers by 99.9%, at least. + PKG_MANAGER="apt-get" setupVars="/etc/pivpn/setupVars.conf" @@ -9,12 +12,13 @@ if [ ! -f "${setupVars}" ]; then exit 1 fi +# shellcheck disable=SC1090 source "${setupVars}" # Find the rows and columns. Will default to 80x24 if it can not be detected. screen_size=$(stty size 2>/dev/null || echo 24 80) -rows=$(echo $screen_size | awk '{print $1}') -columns=$(echo $screen_size | awk '{print $2}') +rows=$(echo "$screen_size" | awk '{print $1}') +columns=$(echo "$screen_size" | awk '{print $2}') # Divide by two so the dialogs take up half of the screen, which looks nice. r=$(( rows / 2 )) @@ -23,18 +27,19 @@ c=$(( columns / 2 )) r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) +### FIXME: introduce global lib spinner(){ local pid=$1 local delay=0.50 local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + while ps a | awk '{print $1}' | grep "$pid"; do local temp=${spinstr#?} printf " [%c] " "$spinstr" local spinstr=$temp${spinstr%"$temp"} sleep $delay - printf "\b\b\b\b\b\b" + printf "\\b\\b\\b\\b\\b\\b" done - printf " \b\b\b\b" + printf " \\b\\b\\b\\b" } removeAll(){ @@ -52,6 +57,7 @@ removeAll(){ # Removing firewall rules. echo "::: Removing firewall rules..." + ### FIXME: introduce global config space! if [ "$VPN" = "wireguard" ]; then pivpnPROTO="udp" pivpnDEV="wg0" @@ -63,9 +69,11 @@ removeAll(){ if [ "$USING_UFW" -eq 1 ]; then + ### FIXME: SC2154 ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null + ### FIXME: SC2154 ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any > /dev/null - sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules + sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/24 -o ${IPv4dev} -j MASQUERADE\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules iptables -t nat -D POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE ufw reload &> /dev/null @@ -100,6 +108,7 @@ removeAll(){ # On Debian and armv7l Raspbian, remove the unstable repo (on armv6l Raspbian # there is no wireguard package). On Ubuntu, remove the PPA. + ### FIXME: unconditionally rm'ing unstable.list isn't a good idea, it appears. What if someone else put it there manually? if [ "$PLAT" = "Debian" ] || { [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv7l" ]; }; then rm /etc/apt/sources.list.d/unstable.list rm /etc/apt/preferences.d/limit-unstable @@ -126,27 +135,30 @@ removeAll(){ elif [ "${i}" = "unattended-upgrades" ]; then + ### REALLY??? rm -rf /var/log/unattended-upgrades rm -rf /etc/apt/apt.conf.d/*periodic rm -rf /etc/apt/apt.conf.d/*unattended-upgrades + elif [ "${i}" = "openvpn" ]; then + deluser openvpn fi - printf ":::\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\n"; + printf ":::\\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\\n"; break ;; - [Nn]* ) printf ":::\tSkipping %s\n" "$i"; + [Nn]* ) printf ":::\\tSkipping %s\\n" "$i"; break ;; - * ) printf "::: You must answer yes or no!\n";; + * ) printf "::: You must answer yes or no!\\n";; esac done done # Take care of any additional package cleaning printf "::: Auto removing remaining dependencies..." - $PKG_MANAGER -y autoremove &> /dev/null & spinner $!; printf "done!\n"; + $PKG_MANAGER -y autoremove &> /dev/null & spinner $!; printf "done!\\n"; printf "::: Auto cleaning remaining dependencies..." - $PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\n"; + $PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\\n"; echo ":::" # Removing pivpn files @@ -160,7 +172,7 @@ removeAll(){ rm -rf /opt/pivpn rm -rf /etc/.pivpn rm -rf /etc/pivpn - rm -rf /var/log/*pivpn* + rm -f /var/log/*pivpn* rm -f /usr/local/bin/pivpn rm -f /etc/bash_completion.d/pivpn @@ -169,28 +181,29 @@ removeAll(){ if [ "$VPN" = "wireguard" ]; then rm -f /etc/wireguard/wg0.conf - rm -rf /etc/wireguard/configs - rm -rf /etc/wireguard/keys - rm -rf $install_home/configs + rm -f /etc/wireguard/configs + rm -f /etc/wireguard/keys + ### FIXME SC2154 + rm -f "$install_home/configs" elif [ "$VPN" = "openvpn" ]; then - rm -rf /var/log/*openvpn* + rm -f /var/log/*openvpn* rm -f /etc/openvpn/server.conf rm -f /etc/openvpn/crl.pem - rm -rf /etc/openvpn/easy-rsa - rm -rf $install_home/ovpns + rm -f /etc/openvpn/easy-rsa + rm -f "$install_home/ovpns" fi echo ":::" - printf "::: Finished removing PiVPN from your system.\n" - printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L https://install.pivpn.io | bash\n:::\n::: at any time!\n:::\n" + printf "::: Finished removing PiVPN from your system.\\n" + printf "::: Reinstall by simpling running\\n:::\\n:::\\tcurl -L https://install.pivpn.io | bash\\n:::\\n::: at any time!\\n:::\\n" } askreboot(){ - printf "It is \e[1mstrongly\e[0m recommended to reboot after un-installation.\n" + printf "It is \\e[1mstrongly\\e[0m recommended to reboot after un-installation.\\n" read -p "Would you like to reboot now? [y/n]: " -n 1 -r echo if [[ ${REPLY} =~ ^[Yy]$ ]]; then - printf "\nRebooting system...\n" + printf "\\nRebooting system...\\n" sleep 3 shutdown -r now fi @@ -204,6 +217,6 @@ while true; do case $yn in [Yy]* ) removeAll; askreboot; break;; - [Nn]* ) printf "::: Not removing anything, exiting...\n"; break;; + [Nn]* ) printf "::: Not removing anything, exiting...\\n"; break;; esac done From cd1b8fbf7faf657aaca58f4cbf8f31f175f5c962 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 9 Dec 2019 17:05:34 +0100 Subject: [PATCH 34/79] Use printf with column in the listCONF.sh script --- auto_install/install.sh | 8 ++++---- scripts/openvpn/clientStat.sh | 2 +- scripts/wireguard/listCONF.sh | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 2305458..2239ebc 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -22,7 +22,7 @@ PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" # Dependencies that are required by the script, regardless of the VPN protocol chosen -BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools) +BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools bsdmainutils) # Dependencies that where actually installed by the script. For example if the script requires # grep and dnsutils but dnsutils is already installed, we save grep here. This way when uninstalling @@ -698,9 +698,9 @@ askWhichVPN(){ installOpenVPN(){ echo "::: Installing OpenVPN from Debian package... " - # grepcidr is used to redact IPs in the debug log, expect is used to feed easy-rsa - # with passwords, bsdmainutils provides column to format the terminal output - PIVPN_DEPS=(openvpn grepcidr expect bsdmainutils) + # grepcidr is used to redact IPs in the debug log whereas expect is used + # to feed easy-rsa with passwords + PIVPN_DEPS=(openvpn grepcidr expect) installDependentPackages PIVPN_DEPS[@] } diff --git a/scripts/openvpn/clientStat.sh b/scripts/openvpn/clientStat.sh index ef04114..bf2c208 100755 --- a/scripts/openvpn/clientStat.sh +++ b/scripts/openvpn/clientStat.sh @@ -35,4 +35,4 @@ else printf "\nNo Clients Connected!\n" fi printf "\n" -} | column -t -s $'\t' \ No newline at end of file +} | column -t -s $'\t' diff --git a/scripts/wireguard/listCONF.sh b/scripts/wireguard/listCONF.sh index 02e5224..fd808fe 100755 --- a/scripts/wireguard/listCONF.sh +++ b/scripts/wireguard/listCONF.sh @@ -6,8 +6,9 @@ if [ ! -s clients.txt ]; then exit 1 fi +{ # Present the user with a summary of the clients, fetching info from dates. -FORMATTED+=": \e[4mClient\e[0m&\e[4mCreation date\e[0m :\n" +printf ": \e[4mClient\e[0m \t \e[4mCreation date\e[0m :\n" while read -r LINE; do CLIENT_NAME="$(awk '{print $1}' <<< "$LINE")" @@ -17,7 +18,8 @@ while read -r LINE; do # Dates are converted from UNIX time to human readable. CD_FORMAT="$(date -d @"$CREATION_DATE" +'%d %b %Y, %H:%M, %Z')" - FORMATTED+="• $CLIENT_NAME&$CD_FORMAT\n" + printf "• $CLIENT_NAME \t $CD_FORMAT\n" done < clients.txt -echo -e "$FORMATTED" | column -t -s '&' \ No newline at end of file +printf "\n" +} | column -t -s $'\t' From da988f6cf4fa60e4a886df318251dd10fc97570c Mon Sep 17 00:00:00 2001 From: corbolais Date: Mon, 9 Dec 2019 21:48:08 +0100 Subject: [PATCH 35/79] add gitignore, add unbound config for recursive verifying resolver (increased privacy). Signed-off-by: corbolais --- .gitignore | 1 + .../recursive_verifying_resolver.conf | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 files/etc/unbound/unbound.conf.d/recursive_verifying_resolver.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a5eb7f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.diff diff --git a/files/etc/unbound/unbound.conf.d/recursive_verifying_resolver.conf b/files/etc/unbound/unbound.conf.d/recursive_verifying_resolver.conf new file mode 100644 index 0000000..d40a2bd --- /dev/null +++ b/files/etc/unbound/unbound.conf.d/recursive_verifying_resolver.conf @@ -0,0 +1,59 @@ +server: + # If no logfile is specified, syslog is used + logfile: "/var/log/unbound/unbound.log" + verbosity: 0 + #interface: 127.0.0.1 + interface: 10.8.0.1 + access-control: 127.0.0.0/8 allow +### FIXME: once config storage is up, use pivpnNet + access-control: 10.6.0.0/8 allow + access-control: 10.8.0.0/8 allow + + #port: 53 + do-ip4: yes + do-udp: yes + do-tcp: yes + + # May be set to yes if you have IPv6 connectivity + do-ip6: no + + # Use this only when you downloaded the list of primary root servers! + # Download: + # wget https://www.internic.net/domain/named.root -O /var/lib/unbound/root.hints + # curl https://www.internic.net/domain/named.root -o /var/lib/unbound/root.hints + root-hints: "/var/lib/unbound/root.hints" + + # Trust glue only if it is within the servers authority + harden-glue: yes + + # Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS + harden-dnssec-stripped: yes + + # Don't use Capitalization randomization as it is known to cause DNSSEC issues sometimes + # see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details + use-caps-for-id: no + + # Reduce EDNS reassembly buffer size. + # Suggested by the unbound man page to reduce fragmentation reassembly problems + edns-buffer-size: 1472 + + # Perform prefetching of close to expired message cache entries + # This only applies to domains that have been frequently queried + prefetch: yes + + # One thread should be sufficient, can be increased on beefy machines. In reality for most users running on small networks or on a single machine it should be unnecessary to seek performance enhancement by increasing num-threads above 1. + num-threads: 1 + + # Ensure kernel buffer is large enough to not lose messages in traffic spikes + so-rcvbuf: 1m + + # Ensure privacy of local IP ranges + private-address: 192.168.0.0/16 + private-address: 169.254.0.0/16 + private-address: 172.16.0.0/12 + private-address: 10.0.0.0/8 + private-address: fd00::/8 + private-address: fe80::/10 + +### EOF +### vim:tw=256:et:sts=2:st=2:sw=2:com+=b\:###:fo+=cqtr:tags=ctags: From d022cafa254ac8a74e558e24758dfb6bd5f2a783 Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 10 Dec 2019 16:06:28 +0100 Subject: [PATCH 36/79] Revert some minor changes --- auto_install/install.sh | 22 +++++++--------------- scripts/openvpn/pivpnDebug.sh | 31 ++++++++----------------------- scripts/uninstall.sh | 10 +++++----- server_config.txt | 4 ++-- 4 files changed, 22 insertions(+), 45 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 5b989f6..323b7b6 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -227,7 +227,7 @@ updatePackageCache(){ #update package lists echo ":::" echo -ne "::: ${PKG_MANAGER} update has not been run today. Running now...\\n" - $SUDO "${UPDATE_PKG_CACHE}" &> /dev/null + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null echo " done!" fi } @@ -282,16 +282,7 @@ installDependentPackages(){ done if command -v debconf-apt-progress &> /dev/null; then - set +e - $SUDO debconf-apt-progress -- "${PKG_INSTALL}" "${argArray1[@]}" - res="$?"; - set -e - ### apt-get install above returns 100 after an otherwise successfull installation of iptables-persistent, - ### everything else was aready installed. - ### Prevent from exiting the installation script in this case, exit for any other error code. - if [[ "$res" -ne 100 ]]; then - exit "$res"; - fi; + $SUDO debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" else ${PKG_INSTALL} "${argArray1[@]}" fi @@ -710,7 +701,7 @@ askWhichVPN(){ pivpnDEV="tun0" pivpnNET="10.8.0.0" fi - vpnGw="${pivpnNET/.0/.1}" + vpnGw="${pivpnNET/.0.0/.0.1}" echo "VPN=${VPN}" >> /tmp/setupVars.conf } @@ -745,7 +736,7 @@ installWireGuard(){ printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 - $SUDO "${UPDATE_PKG_CACHE}" &> /dev/null + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(raspberrypi-kernel-headers wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] @@ -831,7 +822,7 @@ installWireGuard(){ echo "::: Adding Debian repository... " echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null - $SUDO "${UPDATE_PKG_CACHE}" &> /dev/null + $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] @@ -1317,6 +1308,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} ./easyrsa gen-crl ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem if ! getent passwd openvpn; then + mkdir -p /var/lib/openvpn ${SUDOE} adduser --system --home /var/lib/openvpn/ --no-create-home --group --disabled-login ${debianOvpnUserGroup%:*} fi ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem @@ -1439,7 +1431,7 @@ confNetwork(){ exit 1; fi ### If there is already a "*nat" section just add our POSTROUTING MASQUERADE - if grep -q "*nat" /etc/ufw/before.rules; then + if $SUDO grep -q "*nat" /etc/ufw/before.rules; then $SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE/}" -i /etc/ufw/before.rules else $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index f5cc4bb..bc14f8f 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -133,30 +133,15 @@ else fi fi - if [ "$OLD_UFW" -eq 1 ]; then - FORWARD_POLICY="$(iptables -S FORWARD | grep '^-P' | awk '{print $3}')" - if [ "$FORWARD_POLICY" = "ACCEPT" ]; then - echo ":: [OK] Ufw forwarding policy is accept" - else - ERR=1 - read -r -p ":: [ERR] Ufw forwarding policy is not 'ACCEPT', attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw - ufw reload > /dev/null - echo "Done" - fi - fi + if iptables -C ufw-user-forward -i tun0 -o "${IPv4dev}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then + echo ":: [OK] Ufw forwarding rule set" else - if iptables -C ufw-user-forward -i tun0 -o "${IPv4dev}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then - echo ":: [OK] Ufw forwarding rule set" - else - ERR=1 - read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY - if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any - ufw reload - echo "Done" - fi + ERR=1 + read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then + ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any + ufw reload + echo "Done" fi fi diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 1647531..f4f6eb5 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -181,16 +181,16 @@ removeAll(){ if [ "$VPN" = "wireguard" ]; then rm -f /etc/wireguard/wg0.conf - rm -f /etc/wireguard/configs - rm -f /etc/wireguard/keys + rm -rf /etc/wireguard/configs + rm -rf /etc/wireguard/keys ### FIXME SC2154 - rm -f "$install_home/configs" + rm -rf "$install_home/configs" elif [ "$VPN" = "openvpn" ]; then rm -f /var/log/*openvpn* rm -f /etc/openvpn/server.conf rm -f /etc/openvpn/crl.pem - rm -f /etc/openvpn/easy-rsa - rm -f "$install_home/ovpns" + rm -rf /etc/openvpn/easy-rsa + rm -rf "$install_home/ovpns" fi echo ":::" diff --git a/server_config.txt b/server_config.txt index 9ca16a4..71da0c8 100644 --- a/server_config.txt +++ b/server_config.txt @@ -23,8 +23,8 @@ tls-version-min 1.2 tls-auth /etc/openvpn/easy-rsa/pki/ta.key 0 cipher AES-256-CBC auth SHA256 -user nobody -group nogroup +user openvpn +group openvpn persist-key persist-tun crl-verify /etc/openvpn/crl.pem From c20e7d21502044c2dc80e80504405c98e78668b5 Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 10 Dec 2019 16:49:40 +0100 Subject: [PATCH 37/79] Use ${pivpnNET} and ${subnetClass} when adding ufw nat rules --- auto_install/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 323b7b6..738f544 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1432,10 +1432,10 @@ confNetwork(){ fi ### If there is already a "*nat" section just add our POSTROUTING MASQUERADE if $SUDO grep -q "*nat" /etc/ufw/before.rules; then - $SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/24 -o ${IPv4dev} -j MASQUERADE/}" -i /etc/ufw/before.rules + $SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE/}" -i /etc/ufw/before.rules else - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules - fi + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + fi # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any >/dev/null From 5f82a0740e384b58a311f785c0ad11ed3ae644f6 Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 10 Dec 2019 19:07:08 +0100 Subject: [PATCH 38/79] Use variable, create openvpn home, add shellcheck reminder --- auto_install/install.sh | 4 ++-- scripts/uninstall.sh | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 738f544..f348939 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -19,6 +19,7 @@ debianOvpnUserGroup="openvpn:openvpn" ### PKG Vars ### PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" +### FIXME: quoting UPDATE_PKG_CACHE and PKG_INSTALL hangs the script, shellcheck SC2086 UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" @@ -1308,8 +1309,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} ./easyrsa gen-crl ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem if ! getent passwd openvpn; then - mkdir -p /var/lib/openvpn - ${SUDOE} adduser --system --home /var/lib/openvpn/ --no-create-home --group --disabled-login ${debianOvpnUserGroup%:*} + ${SUDOE} adduser --system --home /var/lib/openvpn/ --group --disabled-login ${debianOvpnUserGroup%:*} fi ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index f4f6eb5..bcfbf94 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -5,6 +5,7 @@ ### FIXME: use variables where appropriate, reduce magic numbers by 99.9%, at least. PKG_MANAGER="apt-get" +subnetClass="24" setupVars="/etc/pivpn/setupVars.conf" if [ ! -f "${setupVars}" ]; then @@ -72,9 +73,9 @@ removeAll(){ ### FIXME: SC2154 ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null ### FIXME: SC2154 - ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/24" out on "${IPv4dev}" to any > /dev/null - sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/24 -o ${IPv4dev} -j MASQUERADE\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules - iptables -t nat -D POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE + ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any > /dev/null + sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules + iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE ufw reload &> /dev/null elif [ "$USING_UFW" -eq 0 ]; then @@ -84,11 +85,11 @@ removeAll(){ fi if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - iptables -D FORWARD -d "${pivpnNET}/24" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -D FORWARD -s "${pivpnNET}/24" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT + iptables -D FORWARD -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -D FORWARD -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT fi - iptables -t nat -D POSTROUTING -s "${pivpnNET}/24" -o "${IPv4dev}" -j MASQUERADE + iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE iptables-save > /etc/iptables/rules.v4 fi From 248f9cc3fa3af312d3e1693ebd64716818d79bea Mon Sep 17 00:00:00 2001 From: 4s3ti Date: Fri, 20 Dec 2019 23:16:35 +0100 Subject: [PATCH 39/79] s/pivpn.io/pivpn.dev Changed Readme files to pivpn.dev --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bee626b..437b6c2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ About ----- -Visit the [PiVPN](http://pivpn.io) site for more information. +Visit the [PiVPN](http://pivpn.dev) site for more information. This is a set of shell scripts developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM) into a VPN server using the free, open-source [OpenVPN](https://openvpn.net) software. @@ -40,7 +40,7 @@ Installation ```shell -curl -L https://install.pivpn.io | bash +curl -L https://install.pivpn.dev | bash ``` The script will first update your APT repositories, upgrade packages, and install OpenVPN, From 33b2b2468d823ea1ab192eefa0ef2599efcf9b31 Mon Sep 17 00:00:00 2001 From: 4s3ti Date: Fri, 20 Dec 2019 23:30:00 +0100 Subject: [PATCH 40/79] pivpn.io to pivpn.dev, http to https Changed all appearances of pivpn.io to pivpn.dev Changed all appearances of http to https --- CONTRIBUTING.md | 4 ++-- ISSUE_TEMPLATE.md | 6 +++--- README.md | 2 +- auto_install/install.sh | 12 ++++++------ scripts/uninstall.sh | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64de879..cc581d4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. -Please report unacceptable behavior to [0.kaladin@gmail.com](mailto:0.kaladin@gmail.com). +Please report unacceptable behavior to any project maintainer. ### Contributing @@ -24,7 +24,7 @@ Please report unacceptable behavior to [0.kaladin@gmail.com](mailto:0.kaladin@gm ### **PiVPN.io Website** -* Yes the site is open source as well! You can find and contribute to [pivpn.io](https://github.com/pivpn/pivpn.github.io) directly. +* Yes the site is open source as well! You can find and contribute to [pivpn.dev](https://github.com/pivpn/pivpn.github.io) directly.
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index dcc2b68..6842947 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -6,7 +6,7 @@ Any Issue opened that doesn't follow this template will be removed. Hi, you are about to open a new issue, Please provide us with all the info required below, incomplete issues will decrease our effectiveness to troubleshoot your issue and increase the time we need to spend helping you out, or with your issue closed even if it is a legitimate issue. Please remember we do not have any super power that makes us guess exactly what your issue is without any decent details! -For any output requested below, you may alternatively post it on http://pastebin.com and provide the Pastebin URL in its place +For any output requested below, you may alternatively post it on https://pastebin.com and provide the Pastebin URL in its place --> ## In raising this issue, I confirm the following: @@ -21,7 +21,7 @@ For any output requested below, you may alternatively post it on http://pastebin - + ### Issue @@ -31,7 +31,7 @@ For any output requested below, you may alternatively post it on http://pastebin (yes/no / which issues?) -### Console output of `curl -L install.pivpn.io | bash` +### Console output of `curl -L install.pivpn.dev | bash` ``` Output Here ``` diff --git a/README.md b/README.md index 437b6c2..46a65d3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ About ----- -Visit the [PiVPN](http://pivpn.dev) site for more information. +Visit the [PiVPN](https://pivpn.dev) site for more information. This is a set of shell scripts developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM) into a VPN server using the free, open-source [OpenVPN](https://openvpn.net) software. diff --git a/auto_install/install.sh b/auto_install/install.sh index f348939..cdbd8f5 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # PiVPN: Trivial OpenVPN or WireGuard setup and configuration # Easiest setup and mangement of OpenVPN or WireGuard on Raspberry Pi -# http://pivpn.io +# https://pivpn.dev # Heavily adapted from the pi-hole.net project and... # https://github.com/StarshipEngineer/OpenVPN-Setup/ # # Install with this command (from your Pi): # -# curl -L https://install.pivpn.io | bash +# curl -L https://install.pivpn.dev | bash # Make sure you have `curl` installed ######## VARIABLES ######### @@ -206,7 +206,7 @@ verifyFreeDiskSpace(){ echo "::: You only have ${existing_free_kilobytes} KiloBytes free." echo "::: If this is a new install on a Raspberry Pi you may need to expand your disk." echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'" - echo "::: After rebooting, run this installation again. (curl -L https://install.pivpn.io | bash)" + echo "::: After rebooting, run this installation again. (curl -L https://install.pivpn.dev | bash)" echo "Insufficient free space, exiting..." exit 1 @@ -560,7 +560,7 @@ chooseUser(){ # We don't have a user, let's ask to add one. if userToAdd=$(whiptail --title "Choose A User" --inputbox "No non-root user account was found. Please type a new username." ${r} ${c} 3>&1 1>&2 2>&3) then - # See http://askubuntu.com/a/667842/459815 + # See https://askubuntu.com/a/667842/459815 PASSWORD=$(whiptail --title "password dialog" --passwordbox "Please enter the new user password" ${r} ${c} 3>&1 1>&2 2>&3) CRYPT=$(perl -e 'printf("%s\n", crypt($ARGV[0], "password"))' "${PASSWORD}") if $SUDO useradd -m -p "${CRYPT}" -s /bin/bash "${userToAdd}" ; then @@ -733,7 +733,7 @@ installWireGuard(){ installDependentPackages PIVPN_DEPS[@] # Do not upgrade packages from the unstable repository except for wireguard echo "::: Adding Debian repository... " - echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null + echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 @@ -821,7 +821,7 @@ installWireGuard(){ echo "::: Installing WireGuard from Debian package... " echo "::: Adding Debian repository... " - echo "deb http://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null + echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index bcfbf94..552fecc 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -196,7 +196,7 @@ removeAll(){ echo ":::" printf "::: Finished removing PiVPN from your system.\\n" - printf "::: Reinstall by simpling running\\n:::\\n:::\\tcurl -L https://install.pivpn.io | bash\\n:::\\n::: at any time!\\n:::\\n" + printf "::: Reinstall by simpling running\\n:::\\n:::\\tcurl -L https://install.pivpn.dev | bash\\n:::\\n::: at any time!\\n:::\\n" } askreboot(){ From 37b9250c2eb8e7f44673b7f2776cb584cd3b0c3d Mon Sep 17 00:00:00 2001 From: 4s3ti Date: Sun, 22 Dec 2019 18:52:03 +0100 Subject: [PATCH 41/79] Issue templates from master --- .github/ISSUE_TEMPLATE/bug_report.md | 47 +++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++ .github/ISSUE_TEMPLATE/support-request.md | 61 +++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/support-request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..05c4b02 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,47 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG] " +labels: Needs Investigation +assignees: '' + +--- + +## In raising this issue, I confirm the following: + +`{please fill the checkboxes, e.g: [X]}` + +- [] I have read and understood the [contributors guide](https://github.com/pivpn/pivpn/blob/master/CONTRIBUTING.md). +- [] The issue I am reporting can be *replicated*. +- [] The issue I am reporting can be *is* directly related to the pivpn installer script. +- [] The issue I am reporting isn't a duplicate (see [FAQs](https://github.com/pivpn/pivpn/wiki/FAQ), [closed issues](https://github.com/pivpn/pivpn/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed), and [open issues](https://github.com/pivpn/pivpn/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aopen)). + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - VPN Protocol + - OS: [e.g. iOS] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - VPN Protocol + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..b1cdb91 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FR] " +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/support-request.md b/.github/ISSUE_TEMPLATE/support-request.md new file mode 100644 index 0000000..9f71483 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/support-request.md @@ -0,0 +1,61 @@ +--- +name: Support Request +about: Request support from PiVPN comunity +title: "[Support] " +labels: '' +assignees: '' + +--- + + + +## In raising this issue, I confirm the following: + +`{please fill the checkboxes, e.g: [X]}` + +- [] I have read and understood the [contributors guide](https://github.com/pivpn/pivpn/blob/master/CONTRIBUTING.md). +- [] The issue I am reporting can be *replicated*. +- [] The issue I am reporting can be *is* directly related to the pivpn installer script. +- [] The issue I am reporting isn't a duplicate (see [FAQs](https://github.com/pivpn/pivpn/wiki/FAQ), [closed issues](https://github.com/pivpn/pivpn/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed), and [open issues](https://github.com/pivpn/pivpn/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aopen)). + + + + + + + +### Issue + + +### Have you searched for similar issues and solutions? + (yes/no / which issues?) + + +### Console output of `curl -L install.pivpn.dev | bash` +``` + Output Here +``` + + +### Console output of `pivpn add` or `pivpn add nopass` +``` + Output Here +``` + +### Console output of `pivpn debug` +``` + Output Here +``` +### Have you taken any steps towards solving your issue? +``` + which? +``` From 8b00c131bdef713a038b8a32048c331c64c0423c Mon Sep 17 00:00:00 2001 From: 4s3ti Date: Sun, 22 Dec 2019 18:52:58 +0100 Subject: [PATCH 42/79] Deleted Old Issue Template --- ISSUE_TEMPLATE.md | 52 ----------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 ISSUE_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md deleted file mode 100644 index 6842947..0000000 --- a/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,52 +0,0 @@ - - -## In raising this issue, I confirm the following: - -`{please fill the checkboxes, e.g: [X]}` - -- [] I have read and understood the [contributors guide](https://github.com/pivpn/pivpn/blob/master/CONTRIBUTING.md). -- [] The issue I am reporting can be *replicated*. -- [] The issue I am reporting can be *is* directly related to the pivpn installer script. -- [] The issue I am reporting isn't a duplicate (see [FAQs](https://github.com/pivpn/pivpn/wiki/FAQ), [closed issues](https://github.com/pivpn/pivpn/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed), and [open issues](https://github.com/pivpn/pivpn/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aopen)). - - - - - - - -### Issue - - -### Have you searched for similar issues and solutions? - (yes/no / which issues?) - - -### Console output of `curl -L install.pivpn.dev | bash` -``` - Output Here -``` - - -### Console output of `pivpn add` or `pivpn add nopass` -``` - Output Here -``` - -### Console output of `pivpn debug` -``` - Output Here -``` -### Have you taken any steps towards solving your issue? -``` - which? -``` From 05b189486d0a8b8c1c1bae1000fdd3c2e44644ce Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Sun, 22 Dec 2019 20:16:02 +0100 Subject: [PATCH 43/79] README.md update readme file is slightly outdated, updated it to better represet the current state of the project. --- README.md | 86 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 46a65d3..0df15c2 100644 --- a/README.md +++ b/README.md @@ -2,51 +2,83 @@ About ----- Visit the [PiVPN](https://pivpn.dev) site for more information. -This is a set of shell scripts developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM) -into a VPN server using the free, open-source [OpenVPN](https://openvpn.net) software. +This is a set of shell scripts initially developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM) +into a VPN server using two free, open-source protocols: + * [Wireguard](https://www.wireguard.com/) + * [OpenVPN](https://openvpn.net) -Have you been looking for a good guide or tutorial for installing openvpn on a raspberry pi or ubuntu based server? Run this script and you don't need a guide or tutorial, this will do it all for you, in a fraction of the time and with hardened security settings in place by default. +Have you been looking for a good guide or tutorial for installing openvpn on a raspberry pi or ubuntu based server? +Run this script and you don't need a guide or tutorial, this will do it all for you, in a fraction of the time and with hardened security settings in place by default. -The master branch of this script installs and configures OpenVPN on Raspbian -Jessie, Stretch, Devuan and has been tested on Ubuntu 14.04 and 16.04 running from an Amazon AWS image. -We recommend using the Stretch or Jessie Lite image on a raspberry pi in your home so you can VPN into your home from unsecure remote locations and safely use the internet. However, the scripts do try to detect different distributions and make adjustments accordingly. They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables. +The master branch of this script installs and configures either Wireguard or OpenVPN on Raspbian, Debian or Ubuntu and it as been tested to run not only on Raspberry pi but also in any Cloud Provider VPS. +We recommend using the Latest Raspbian lite image on a raspberry pi in your home so you can VPN into your home from a unsecure remote locations and safely use the internet. +However, the scripts do try to detect different distributions and make adjustments accordingly. +They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables. -This scripts primary mission in life is to allow a user to have a home VPN for as cost effective as possible and without being a technical wizard. Hence the design of pivpn to work on a Raspberry Pi ($35) and then one command installer. Followed by easy management of the VPN thereafter with the 'pivpn' command. That being said... +This scripts primary mission in life is to allow a user to have a home VPN for as cost effective as possible and without being a technical wizard. +Hence the design of pivpn to work on a Raspberry Pi ($35) and then one command installer. +Followed by easy management of the VPN thereafter with the 'pivpn' command. +That being said... -> This will also work on a free-tier Amazon AWS server using Ubuntu 14.04 - 16.04. I don't want to support every scenario there but getting it to run and install successfully on a free server in the cloud was also important. Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the amazon infrastructure. +> This will also work on a free-tier Amazon AWS server using Ubuntu or Debian. I don't want to support every scenario there but getting it to run and install successfully on a free server in the cloud was also important. +Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the amazon infrastructure. Prerequisites ------------- -To follow this guide and use the script to setup OpenVPN, you will need to have -a Raspberry Pi Model B or later with an ethernet port, an SD or microSD card -(depending on the model) with Raspbian installed, a power adapter appropriate to - the power needs of your model, and an ethernet cable or wifi adapter to connect your Pi to your -router or gateway. It is recommended that you use a fresh image of Raspbian -Stretch Lite from https://raspberrypi.org/downloads, but if you don't, -be sure to make a backup image of your existing installation before proceeding. -You should also setup your Pi with a static IP address (see either source - 1 or 2 at the bottom of this Readme) but it is not required as the script can do this for you. - You will need to have your router forward UDP port 1194 (or whatever custom port you may have chose in the installer) - (varies by model & manufacturer; consult your router manufacturer's - documentation to do this). - Enabling SSH on your Pi is also highly recommended, so that - you can run a very compact headless server without a monitor or keyboard and - be able to access it even more conveniently (This is also covered by source 2). +To follow this guide and use the script to setup a VPN, you will need to have +a Raspberry Pi Model B or later with, an SD or microSD card with Raspbian installed, +a power adapter appropriate to the power needs of your model, and an ethernet cable or wifi +adapter to connect your Pi to your router or gateway. +It is recommended that you use a fresh image of the latest Raspbian Lite from +https://raspberrypi.org/downloads, but if you don't, be sure to make a backup +image of your existing installation before proceeding. +You should also setup your Pi with a static IP address +(see either source 1 or 2 at the bottom of this Readme) +but it is not required as the script can do this for you. +You will need to have your router forwarding UDP port 1194 or whatever custom +port you may have chose in the installer +(varies by model & manufacturer; consult your router manufacturer's documentation to do this). +Enabling SSH on your Pi is also highly recommended, so that you can run a very +compact headless server without a monitor or keyboard and be able to access it +even more conveniently (This is also covered by source 2). Installation ----------------- +**Method 1** ```shell curl -L https://install.pivpn.dev | bash ``` +**Method 2** +```Shell +curl -L https://install.pivpn.dev > pivpn.sh +sudo sh pivpn.sh +``` + +**Method 3** +```Shell +git clone https://github.com/pivpn/pivpn.git +sudo sh pivpn/auto_install/install.sh +``` + +**OBS:** +in alternative to install.pivpn.dev you can use the raw github link: +https://raw.githubusercontent.com/pivpn/pivpn/master/auto_install/install.sh + +**To install from Test/Development branch** + +Check our [Wiki Page](https://github.com/pivpn/pivpn/wiki#testing) + + The script will first update your APT repositories, upgrade packages, and install OpenVPN, which will take some time. It will ask which authentication method you wish the guts of your server to use, 1024-bit, 2048-bit, or 4096-bit. If you're unsure or don't have a convincing reason one way or the other I'd use 2048 today. From the OpenVPN site: + > For asymmetric keys, general wisdom is that 1024-bit keys are no longer sufficient to protect against well-equipped adversaries. Use of 2048-bit is a good minimum. It is wise to ensure all keys across your active PKI (including the CA root keypair) are using at least 2048-bit keys. > Up to 4096-bit is accepted by nearly all RSA systems (including OpenVPN), but use of keys this large will dramatically increase generation time, TLS handshake delays, and CPU usage for TLS operations; the benefit beyond 2048-bit keys is small enough not to be of great use at the current time. It is often a larger benefit to consider lower validity times than more bits past 2048, but that is for you to decide. @@ -65,7 +97,7 @@ exchange. If you chose 1024-bit encryption, this will just take a few minutes, b chose 2048-bit, it will take much longer (anywhere from 40 minutes to several hours on a Model B+). -NOTE: Diffie-Hellman parameters are NOT generated if you choose not to use OpenVPN 2.4. +**NOTE: Diffie-Hellman parameters are NOT generated if you choose not to use OpenVPN 2.4.** The script will also make some changes to your system to allow it to forward internet traffic and allow VPN connections through the Pi's firewall. When the script @@ -140,7 +172,7 @@ Please be respectful and be aware that this is maintained with our free time! for community support or general questions. Feel free to post on our subreddit -You can also join #pivpn on freenode in IRC +You can also join #pivpn on freenode in IRC For code related issues, code contributions, feature requests, feel free to open an issue here at github. We will classify the issues the best we can to keep things sorted. @@ -175,6 +207,8 @@ sources. 3. Of course there is [OpenVPN](https://openvpn.net) -4. And as always the ever vigilant [EFF](https://www.eff.org/) +4. Also [Wireguard](https://www.wireguard.com/) + +5. And as always the ever vigilant [EFF](https://www.eff.org/) PiVPN is not taking donations at this time but if you want to show your appreciation, then contribute or leave feedback on suggestions or improvements. From e01089945ea5ca0e6798518aa7c33a1dfb401699 Mon Sep 17 00:00:00 2001 From: h-town <29696865+h-town@users.noreply.github.com> Date: Tue, 24 Dec 2019 03:18:11 -0600 Subject: [PATCH 44/79] Remove Google DNS Remove Google DNS for privacy purposes, replace with Quad9 --- auto_install/install.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index cdbd8f5..4787fa4 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -57,8 +57,8 @@ r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) # Find IP used to route to outside world -IPv4addr=$(ip route get 8.8.8.8| awk '{print $7}') -IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') +IPv4addr=$(ip route get 9.9.9.9 | awk '{print $7}') +IPv4gw=$(ip route get 9.9.9.9 | awk '{print $3}') availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) dhcpcdFile=/etc/dhcpcd.conf @@ -947,8 +947,8 @@ askClientDNS(){ pivpnDNS1="$pivpnDNS2" unset pivpnDNS2 elif [ -z "$pivpnDNS1" ] && [ -z "$pivpnDNS2" ]; then - pivpnDNS1="8.8.8.8" - pivpnDNS2="8.8.4.4" + pivpnDNS1="9.9.9.9" + pivpnDNS2="149.112.112.112" echo "::: No DNS provider specified, using Google DNS ($pivpnDNS1 $pivpnDNS2)" fi @@ -992,13 +992,14 @@ askClientDNS(){ Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select \"PiVPN-is-local-DNS\" and make sure your resolver is listening on \"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6) - DNSChooseOptions=(Google "" on + DNSChooseOptions=(Quad9 "" on OpenDNS "" off Level3 "" off DNS.WATCH "" off Norton "" off FamilyShield "" off CloudFlare "" off + Google "" off PiVPN-is-local-DNS "" off Custom "" off) @@ -1008,13 +1009,14 @@ askClientDNS(){ if [[ ${DNSchoices} != "Custom" ]]; then echo "::: Using ${DNSchoices} servers." - declare -A DNS_MAP=(["Google"]="8.8.8.8 8.8.4.4" + declare -A DNS_MAP=(["Quad9"]="9.9.9.9 149.112.112.112" ["OpenDNS"]="208.67.222.222 208.67.220.220" ["Level3"]="209.244.0.3 209.244.0.4" ["DNS.WATCH"]="84.200.69.80 84.200.70.40" ["Norton"]="199.85.126.10 199.85.127.10" ["FamilyShield"]="208.67.222.123 208.67.220.123" ["CloudFlare"]="1.1.1.1 1.0.0.1" + ["Google"]="8.8.8.8 8.8.4.4" ["PiVPN-is-local-DNS"]="$vpnGw") pivpnDNS1=$(awk '{print $1}' <<< "${DNS_MAP["${DNSchoices}"]}") @@ -1025,7 +1027,7 @@ askClientDNS(){ until [[ $DNSSettingsCorrect = True ]]; do strInvalid="Invalid" - if pivpnDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\\n\\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "" 3>&1 1>&2 2>&3) + if pivpnDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\\n\\nFor example '1.1.1.1, 9.9.9.9'" ${r} ${c} "" 3>&1 1>&2 2>&3) then pivpnDNS1=$(echo "$pivpnDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') pivpnDNS2=$(echo "$pivpnDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') From 4257ba76c23bd11e4571f294b621da18e0f1857e Mon Sep 17 00:00:00 2001 From: h-town <29696865+h-town@users.noreply.github.com> Date: Tue, 24 Dec 2019 03:23:21 -0600 Subject: [PATCH 45/79] Remove Google DNS Remove Google DNS for privacy purposes, replace with Quad9 --- server_config.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server_config.txt b/server_config.txt index 71da0c8..5032a12 100644 --- a/server_config.txt +++ b/server_config.txt @@ -8,8 +8,8 @@ dh /etc/openvpn/easy-rsa/pki/dh2048.pem topology subnet server 10.8.0.0 255.255.255.0 # Set your primary domain name server address for clients -push "dhcp-option DNS 8.8.8.8" -push "dhcp-option DNS 8.8.4.4" +push "dhcp-option DNS 9.9.9.9" +push "dhcp-option DNS 149.112.112.112" # Prevent DNS leaks on Windows push "block-outside-dns" # Override the Client default gateway by using 0.0.0.0/1 and From d17d381049dac5245e3f107bb75f95cbce5414ef Mon Sep 17 00:00:00 2001 From: Orazio Date: Fri, 27 Dec 2019 15:48:42 +0100 Subject: [PATCH 46/79] - When suggesting to use Pi-hole, use the VPN server IP instead of the LAN IP to allow DNS resolution even if the user does not route the local network through the tunnel. - Format listCONF in a similar way as listOVPN - Specifically look for a free octet in the last word of clients.txt and not just any word. Necessary otherwhise public keys starting with a number will match against an octet. Example: if line is 'name 5abcdefgh 4', then looking for ' 5' will match but '5$' will not (correctly). - 'pivpn -c' will show the Connected Clients List for WireGuard too --- auto_install/install.sh | 2 +- scripts/wireguard/clientSTAT.sh | 39 +++++++++++++++++++++++++++++++++ scripts/wireguard/listCONF.sh | 13 +++++++---- scripts/wireguard/makeCONF.sh | 4 ++-- scripts/wireguard/pivpn | 2 +- scripts/wireguard/removeCONF.sh | 10 +++++---- 6 files changed, 58 insertions(+), 12 deletions(-) create mode 100755 scripts/wireguard/clientSTAT.sh diff --git a/auto_install/install.sh b/auto_install/install.sh index cdbd8f5..34a72f5 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -978,7 +978,7 @@ askClientDNS(){ # Detect and offer to use Pi-hole if command -v pihole &>/dev/null; then if (whiptail --backtitle "Setup PiVPN" --title "Pi-hole" --yesno "We have detected a Pi-hole installation, do you want to use it as the DNS server for the VPN, so you get ad blocking on the go?" ${r} ${c}); then - pivpnDNS1="$IPv4addr" + pivpnDNS1="$vpnGw" echo "interface=$pivpnDEV" | $SUDO tee /etc/dnsmasq.d/02-pivpn.conf > /dev/null $SUDO pihole restartdns echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf diff --git a/scripts/wireguard/clientSTAT.sh b/scripts/wireguard/clientSTAT.sh new file mode 100755 index 0000000..d8c94cd --- /dev/null +++ b/scripts/wireguard/clientSTAT.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +cd /etc/wireguard/configs +if [ ! -s clients.txt ]; then + echo "::: There are no clients to list" + exit 1 +fi + +hr(){ + numfmt --to=iec-i --suffix=B "$1" +} + +DUMP="$(wg show wg0 dump | tail -n +2)" + +printf "\e[1m::: Connected Clients List :::\e[0m\n" + +{ +printf "\e[4mName\e[0m \t \e[4mRemote IP\e[0m \t \e[4mVirtual IP\e[0m \t \e[4mBytes Received\e[0m \t \e[4mBytes Sent\e[0m \t \e[4mLast Seen\e[0m\n" + +while IFS= read -r LINE; do + + PUBLIC_KEY="$(awk '{ print $1 }' <<< "$LINE")" + REMOTE_IP="$(awk '{ print $3 }' <<< "$LINE")" + VIRTUAL_IP="$(awk '{ print $4 }' <<< "$LINE")" + BYTES_RECEIVED="$(awk '{ print $6 }' <<< "$LINE")" + BYTES_SENT="$(awk '{ print $7 }' <<< "$LINE")" + LAST_SEEN="$(awk '{ print $5 }' <<< "$LINE")" + CLIENT_NAME="$(grep "$PUBLIC_KEY" clients.txt | awk '{ print $1 }')" + + if [ "$LAST_SEEN" -ne 0 ]; then + printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "$(date -d @"$LAST_SEEN" '+%b %m %Y - %T')" + else + printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "(not yet)" + fi + +done <<< "$DUMP" + +printf "\n" +} | column -t -s $'\t' \ No newline at end of file diff --git a/scripts/wireguard/listCONF.sh b/scripts/wireguard/listCONF.sh index 02e5224..6f8e198 100755 --- a/scripts/wireguard/listCONF.sh +++ b/scripts/wireguard/listCONF.sh @@ -6,18 +6,23 @@ if [ ! -s clients.txt ]; then exit 1 fi +printf "\e[1m::: Clients Summary :::\e[0m\n" + # Present the user with a summary of the clients, fetching info from dates. -FORMATTED+=": \e[4mClient\e[0m&\e[4mCreation date\e[0m :\n" +{ +echo -e "\e[4mClient\e[0m \t \e[4mPublic key\e[0m \t \e[4mCreation date\e[0m" while read -r LINE; do CLIENT_NAME="$(awk '{print $1}' <<< "$LINE")" - CREATION_DATE="$(awk '{print $2}' <<< "$LINE")" + PUBLIC_KEY="$(awk '{print $2}' <<< "$LINE")" + + CREATION_DATE="$(awk '{print $3}' <<< "$LINE")" # Dates are converted from UNIX time to human readable. CD_FORMAT="$(date -d @"$CREATION_DATE" +'%d %b %Y, %H:%M, %Z')" - FORMATTED+="• $CLIENT_NAME&$CD_FORMAT\n" + echo -e "$CLIENT_NAME \t $PUBLIC_KEY \t $CD_FORMAT" done < clients.txt -echo -e "$FORMATTED" | column -t -s '&' \ No newline at end of file +} | column -t -s $'\t' \ No newline at end of file diff --git a/scripts/wireguard/makeCONF.sh b/scripts/wireguard/makeCONF.sh index e0378cd..561aa69 100755 --- a/scripts/wireguard/makeCONF.sh +++ b/scripts/wireguard/makeCONF.sh @@ -79,9 +79,9 @@ echo "::: Client Keys generated" # Find an unused number for the last octet of the client IP for i in {2..254}; do - if ! grep -q " $i" configs/clients.txt; then + if ! grep -q " $i$" configs/clients.txt; then COUNT="$i" - echo "${CLIENT_NAME} $(date +%s) ${COUNT}" >> configs/clients.txt + echo "${CLIENT_NAME} $(> configs/clients.txt break fi done diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn index bd89d43..3f96004 100755 --- a/scripts/wireguard/pivpn +++ b/scripts/wireguard/pivpn @@ -17,7 +17,7 @@ makeConf(){ } listConnected(){ - $SUDO wg show + $SUDO /opt/pivpn/clientSTAT.sh exit 0 } diff --git a/scripts/wireguard/removeCONF.sh b/scripts/wireguard/removeCONF.sh index 263fde3..b00deb6 100755 --- a/scripts/wireguard/removeCONF.sh +++ b/scripts/wireguard/removeCONF.sh @@ -73,12 +73,14 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do if [[ $REPLY =~ ^[Yy]$ ]]; then # Grab the least significant octed of the client IP address - COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $3}') - # And the creation date of the client - CREATION_DATE="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $2}')" + COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $4}') + # The creation date of the client + CREATION_DATE="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $3}')" + # And its public key + PUBLIC_KEY="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $2}')" # Then remove the client matching the variables above - sed "/${CLIENT_NAME} ${CREATION_DATE} ${COUNT}/d" -i configs/clients.txt + sed "\#${CLIENT_NAME} ${PUBLIC_KEY} ${CREATION_DATE} ${COUNT}#d" -i configs/clients.txt # Remove the peer section from the server config sed "/# begin ${CLIENT_NAME}/,/# end ${CLIENT_NAME}/d" -i wg0.conf From a561607272226ac50cd9bc687d37f5701e0b3550 Mon Sep 17 00:00:00 2001 From: Orazio Date: Sun, 29 Dec 2019 18:25:35 +0100 Subject: [PATCH 47/79] Mostly changes to the install script, see below Handle running the install script over an existing installation (as the script already did before branching to test-wireguard), providing: - Update, downloads latest scripts from git repo - Repair, reinstall PiVPN while keeping existing settings - Reconfigure, start over overwriting the existing settings Tag iptables rules as an attempt to make sure that the uninstall script only removes PiVPN rules Change the armv6l installation to reflect the split of WireGuard snapshots into wireguard-linux-compat and wireguard-tools --- auto_install/install.sh | 534 +++++++++++++++++++------------- scripts/openvpn/pivpnDebug.sh | 20 +- scripts/uninstall.sh | 24 +- scripts/wireguard/pivpnDEBUG.sh | 41 ++- 4 files changed, 371 insertions(+), 248 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 34a72f5..4d37ddf 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -11,11 +11,10 @@ # Make sure you have `curl` installed ######## VARIABLES ######### -setupVars=/etc/pivpn/setupVars.conf +pivpnGitUrl="https://github.com/pivpn/pivpn.git" +setupVars="/etc/pivpn/setupVars.conf" pivpnFilesDir="/etc/.pivpn" -debianOvpnUserGroup="openvpn:openvpn" - ### PKG Vars ### PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" @@ -25,21 +24,22 @@ PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" # Dependencies that are required by the script, regardless of the VPN protocol chosen -BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools bsdmainutils) +BASE_DEPS=(git tar wget grep dnsutils whiptail net-tools bsdmainutils) # Dependencies that where actually installed by the script. For example if the script requires # grep and dnsutils but dnsutils is already installed, we save grep here. This way when uninstalling # PiVPN we won't prompt to remove packages that may have been installed by the user for other reasons TO_INSTALL=() -pivpnGitUrl="https://github.com/pivpn/pivpn.git" easyrsaVer="3.0.6" easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer}/EasyRSA-unix-v${easyrsaVer}.tgz" subnetClass="24" +dhcpcdFile="/etc/dhcpcd.conf" +debianOvpnUserGroup="openvpn:openvpn" # Raspbian's unattended-upgrades package downloads Debian's config, so this is the link for the proper config -UNATTUPG_RELEASE="1.14" +UNATTUPG_RELEASE="1.16" UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_RELEASE}.tar.gz" # Find the rows and columns. Will default to 80x24 if it can not be detected. @@ -47,7 +47,10 @@ screen_size=$(stty size 2>/dev/null || echo 24 80) rows=$(echo "$screen_size" | awk '{print $1}') columns=$(echo "$screen_size" | awk '{print $2}') +######## Undocumented Flags. Shhh ######## runUnattended=false +skipSpaceCheck=false +reconfigure=false # Divide by two so the dialogs take up half of the screen, which looks nice. r=$(( rows / 2 )) @@ -57,11 +60,170 @@ r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) # Find IP used to route to outside world -IPv4addr=$(ip route get 8.8.8.8| awk '{print $7}') +IPv4addr=$(ip route get 8.8.8.8 | awk '{print $7}') IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') - availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) -dhcpcdFile=/etc/dhcpcd.conf + +######## SCRIPT ############ + +main(){ + + ######## FIRST CHECK ######## + # Must be root to install + echo ":::" + if [[ $EUID -eq 0 ]];then + echo "::: You are root." + else + echo "::: sudo will be used for the install." + # Check if it is actually installed + # If it isn't, exit because the install cannot complete + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + export SUDOE="sudo -E" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi + fi + + # Check arguments for the undocumented flags + for var in "$@"; do + case "$var" in + "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; + "--unattended" ) runUnattended=true;; + "--reconfigure" ) reconfigure=true;; + esac + done + + if [[ "${runUnattended}" == true ]]; then + echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" + if [ -z "$2" ]; then + echo "::: No configuration file passed, using default settings..." + else + if [ -r "$2" ]; then + # shellcheck disable=SC1090 + source "$2" + else + echo "::: Can't open $2" + exit 1 + fi + fi + fi + + if [ -r "$setupVars" ]; then + if [[ "${reconfigure}" == true ]]; then + echo "::: --reconfigure passed to install script, will reinstall PiVPN overwriting existing settings" + UpdateCmd="Reconfigure" + elif [[ "${runUnattended}" == true ]]; then + ### What should the script do when passing --unattended to an existing installation? + UpdateCmd="Reconfigure" + else + askAboutExistingInstall + fi + fi + + if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then + : + elif [ "$UpdateCmd" = "Update" ]; then + ### To do: test the update script and implement update for WireGuard as well + $SUDO /opt/pivpn/update.sh + elif [ "$UpdateCmd" = "Repair" ]; then + source "$setupVars" + runUnattended=true + fi + + # Check for supported distribution + distroCheck + + # Checks for hostname Length + checkHostname + + # Start the installer + # Verify there is enough disk space for the install + if [[ "${skipSpaceCheck}" == true ]]; then + echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" + else + verifyFreeDiskSpace + fi + + updatePackageCache + + # Notify user of package availability + notifyPackageUpdatesAvailable + + # Install packages used by this installation script + preconfigurePackages + installDependentPackages BASE_DEPS[@] + + # Display welcome dialogs + welcomeDialogs + + # Find interfaces and let the user choose one + chooseInterface + + if [ "$PLAT" != "Raspbian" ]; then + avoidStaticIPv4Ubuntu + else + getStaticIPv4Settings + setStaticIPv4 + fi + + # Choose the user for the ovpns + chooseUser + + # Clone/Update the repos + cloneOrUpdateRepos + + # Install + if installPiVPN; then + echo "::: Install Complete..." + else + exit 1 + fi + + # Start services + restartServices + + # Ask if unattended-upgrades will be enabled + askUnattendedUpgrades + + if [ "$UNATTUPG" -eq 1 ]; then + confUnattendedUpgrades + fi + + # Save installation setting to the final location + echo "TO_INSTALL=(${TO_INSTALL[*]})" >> /tmp/setupVars.conf + $SUDO cp /tmp/setupVars.conf "$setupVars" + + installScripts + + # Ensure that cached writes reach persistent storage + echo "::: Flushing writes to disk..." + sync + echo "::: done." + + displayFinalMessage + echo ":::" +} + +askAboutExistingInstall(){ + opt1a="Update" + opt1b="Get the latest PiVPN scripts" + + opt2a="Repair" + opt2b="Reinstall PiVPN using existing settings" + + opt3a="Reconfigure" + opt3b="Reinstall PiVPN with new settings" + + UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\nWe have detected an existing install.\n\nPlease choose from the following options:" ${r} ${c} 3 \ + "${opt1a}" "${opt1b}" \ + "${opt2a}" "${opt2b}" \ + "${opt3a}" "${opt3b}" 3>&2 2>&1 1>&3) || \ + { echo "::: Cancel selected. Exiting"; exit 1; } + + echo "::: ${opt1a} option selected." +} # Next see if we are on a tested and supported OS noOSSupport(){ @@ -253,9 +415,9 @@ notifyPackageUpdatesAvailable(){ preconfigurePackages(){ # Add support for https repositories if there are any that use it otherwise the installation will silently fail if [[ -f /etc/apt/sources.list ]]; then - if grep -q https /etc/apt/sources.list; then - BASE_DEPS+=("apt-transport-https") - fi + if grep -q https /etc/apt/sources.list; then + BASE_DEPS+=("apt-transport-https") + fi fi if [[ ${OSCN} == "buster" ]]; then @@ -263,8 +425,24 @@ preconfigurePackages(){ $SUDO update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy fi - echo iptables-persistent iptables-persistent/autosave_v4 boolean true | $SUDO debconf-set-selections - echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections + # if ufw is enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example) + if $SUDO bash -c 'hash ufw' 2>/dev/null; then + if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive; then + USING_UFW=0 + else + USING_UFW=1 + fi + else + USING_UFW=0 + fi + + if [ "$USING_UFW" -eq 0 ]; then + BASE_DEPS+=(iptables-persistent) + echo iptables-persistent iptables-persistent/autosave_v4 boolean true | $SUDO debconf-set-selections + echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections + fi + + echo "USING_UFW=${USING_UFW}" >> /tmp/setupVars.conf } installDependentPackages(){ @@ -389,7 +567,7 @@ validIP(){ if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS IFS='.' - read -r -a ip <<< "$ip" + read -r -a ip <<< "$ip" IFS=$OIFS [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] @@ -613,20 +791,24 @@ isRepo(){ } updateRepo(){ - # Pull the latest commits - echo -n "::: Updating repo in $1..." - $SUDO rm -rf "${1}" - # Go back to /etc otherwise git will complain when the current working - # directory has just been deleted (/etc/.pivpn). - cd /etc && \ - $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! - cd "${1}" || exit 1 - if [ -z "${TESTING+x}" ]; then - : + if [ "${UpdateCmd}" = "Repair" ]; then + echo "::: Repairing an existing installation, not downloading/updating local repos" else - ${SUDOE} git checkout test + # Pull the latest commits + echo -n "::: Updating repo in $1..." + $SUDO rm -rf "${1}" + # Go back to /etc otherwise git will complain when the current working + # directory has just been deleted (/etc/.pivpn). + cd /etc && \ + $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + cd "${1}" || exit 1 + if [ -z "${TESTING+x}" ]; then + : + else + ${SUDOE} git checkout test + fi + echo " done!" fi - echo " done!" } makeRepo(){ @@ -640,7 +822,7 @@ makeRepo(){ # Go back to /etc otherwhise git will complain when the current working # directory has just been deleted (/etc/.pivpn). cd /etc && \ - $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! + $SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $! cd "${1}" || exit 1 if [ -z "${TESTING+x}" ]; then : @@ -744,29 +926,25 @@ installWireGuard(){ elif [ "$(uname -m)" = "armv6l" ]; then echo "::: Installing WireGuard from source... " - PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq) + PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq bc) installDependentPackages PIVPN_DEPS[@] - WG_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-kmodtools"."version"')" - WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz" - # Delete any leftover code $SUDO rm -rf /usr/src/wireguard-* - echo "::: Downloading source code... " - wget -qO- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src + WG_TOOLS_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-tools"."version"')" + WG_TOOLS_SOURCE="https://git.zx2c4.com/wireguard-tools/snapshot/wireguard-tools-${WG_TOOLS_SNAPSHOT}.tar.xz" + + echo "::: Downloading wireguard-tools source code... " + wget -qO- "${WG_TOOLS_SOURCE}" | $SUDO tar Jxf - --directory /usr/src echo "done!" - cd /usr/src && \ - $SUDO mv WireGuard-"${WG_SNAPSHOT}" wireguard-"${WG_SNAPSHOT}" - cd wireguard-"${WG_SNAPSHOT}" && \ - $SUDO mv src/* . && \ - $SUDO rmdir src + cd /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}/src" # We install the userspace tools manually since DKMS only compiles and # installs the kernel module echo "::: Compiling WireGuard tools... " - if $SUDO make tools; then + if $SUDO make; then echo "done!" else echo "failed!" @@ -777,7 +955,7 @@ installWireGuard(){ # PiVPN we can just do apt remove wireguard-tools, instead of manually removing # files from the file system echo "::: Installing WireGuard tools... " - if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_SNAPSHOT}" -y make tools-install; then + if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_TOOLS_SNAPSHOT}" -y; then TO_INSTALL+=("wireguard-tools") echo "done!" else @@ -785,35 +963,52 @@ installWireGuard(){ exit 1 fi + echo "WG_TOOLS_SNAPSHOT=${WG_TOOLS_SNAPSHOT}" >> /tmp/setupVars.conf + + WG_MODULE_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-linuxcompat"."version"')" + WG_MODULE_SOURCE="https://git.zx2c4.com/wireguard-linux-compat/snapshot/wireguard-linux-compat-${WG_MODULE_SNAPSHOT}.tar.xz" + + echo "::: Downloading wireguard-linux-compat source code... " + wget -qO- "${WG_MODULE_SOURCE}" | $SUDO tar Jxf - --directory /usr/src + echo "done!" + + # Rename wireguard-linux-compat folder and move the source code to the parent folder + # such that dkms picks up the module when referencing wireguard/"${WG_MODULE_SNAPSHOT}" + cd /usr/src && \ + $SUDO mv wireguard-linux-compat-"${WG_MODULE_SNAPSHOT}" wireguard-"${WG_MODULE_SNAPSHOT}" + cd wireguard-"${WG_MODULE_SNAPSHOT}" && \ + $SUDO mv src/* . && \ + $SUDO rmdir src + echo "::: Adding WireGuard modules via DKMS... " - if $SUDO dkms add wireguard/"${WG_SNAPSHOT}"; then + if $SUDO dkms add wireguard/"${WG_MODULE_SNAPSHOT}"; then echo "done!" else echo "failed!" - $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + $SUDO dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all exit 1 fi echo "::: Compiling WireGuard modules via DKMS... " - if $SUDO dkms build wireguard/"${WG_SNAPSHOT}"; then + if $SUDO dkms build wireguard/"${WG_MODULE_SNAPSHOT}"; then echo "done!" else echo "failed!" - $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + $SUDO dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all exit 1 fi echo "::: Installing WireGuard modules via DKMS... " - if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then + if $SUDO dkms install wireguard/"${WG_MODULE_SNAPSHOT}"; then TO_INSTALL+=("wireguard-dkms") echo "done!" else echo "failed!" - $SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all + $SUDO dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all exit 1 fi - echo "WG_SNAPSHOT=${WG_SNAPSHOT}" >> /tmp/setupVars.conf + echo "WG_MODULE_SNAPSHOT=${WG_MODULE_SNAPSHOT}" >> /tmp/setupVars.conf fi @@ -989,9 +1184,9 @@ askClientDNS(){ DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients (press space to select). To use your own, select - Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select - \"PiVPN-is-local-DNS\" and make sure your resolver is listening on - \"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6) + Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select + \"PiVPN-is-local-DNS\" and make sure your resolver is listening on + \"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6) DNSChooseOptions=(Google "" on OpenDNS "" off Level3 "" off @@ -1075,7 +1270,7 @@ validDomain(){ local stat=1 if [[ $domain =~ ^(([a-zA-Z0-9]{1,63}|([a-zA-Z0-9]{1,60}[-a-zA-Z0-9()]{0,2}[a-zA-Z0-9]{1,60}))\.){1,6}([a-zA-Z]{2,})$ ]]; then - stat=$? + stat=$? fi return $stat } @@ -1309,7 +1504,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} ./easyrsa gen-crl ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem if ! getent passwd openvpn; then - ${SUDOE} adduser --system --home /var/lib/openvpn/ --group --disabled-login ${debianOvpnUserGroup%:*} + ${SUDOE} adduser --system --home /var/lib/openvpn/ --group --disabled-login ${debianOvpnUserGroup%:*} fi ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem @@ -1390,6 +1585,12 @@ confWireGuard(){ else whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}" fi + + # Remove configs and keys folders to make space for a new server when using 'Repair' or 'Reconfigure' + # over an existing installation + $SUDO rm -rf /etc/wireguard/configs + $SUDO rm -rf /etc/wireguard/keys + $SUDO mkdir -p /etc/wireguard/configs $SUDO touch /etc/wireguard/configs/clients.txt $SUDO mkdir -p /etc/wireguard/keys @@ -1413,45 +1614,42 @@ confNetwork(){ $SUDO sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf $SUDO sysctl -p > /dev/null - # if ufw enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example) - if $SUDO bash -c 'hash ufw' 2>/dev/null; then - if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive - then - USING_UFW=0 - else - USING_UFW=1 - echo "::: Detected UFW is enabled." - echo "::: Adding UFW rules..." - ### Basic safeguard: if file is empty, there's been something weird going on. - ### Note: no safeguard against imcomplete content as a result of previous failures. - if test -s /etc/ufw/before.rules; then - $SUDO cp -f /etc/ufw/before.rules /etc/ufw/before.rules.pre-pivpn - else - echo "$0: ERR: Sorry, won't touch empty file \"/etc/ufw/before.rules\"."; - exit 1; - fi - ### If there is already a "*nat" section just add our POSTROUTING MASQUERADE - if $SUDO grep -q "*nat" /etc/ufw/before.rules; then - $SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE/}" -i /etc/ufw/before.rules - else - $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules - fi - # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) - $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null - $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any >/dev/null + if [ "$USING_UFW" -eq 1 ]; then - $SUDO ufw reload >/dev/null - echo "::: UFW configuration completed." + echo "::: Detected UFW is enabled." + echo "::: Adding UFW rules..." + ### Basic safeguard: if file is empty, there's been something weird going on. + ### Note: no safeguard against imcomplete content as a result of previous failures. + if test -s /etc/ufw/before.rules; then + $SUDO cp -f /etc/ufw/before.rules /etc/ufw/before.rules.pre-pivpn + else + echo "$0: ERR: Sorry, won't touch empty file \"/etc/ufw/before.rules\"."; + exit 1; fi - else - USING_UFW=0 - fi - # else configure iptables - if [[ $USING_UFW -eq 0 ]]; then + ### If there is already a "*nat" section just add our POSTROUTING MASQUERADE + if $SUDO grep -q "*nat" /etc/ufw/before.rules; then + ### Onyl add the NAT rule if it isn't already there + if ! $SUDO grep -q "${VPN}-nat-rule" /etc/ufw/before.rules; then + $SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE -m comment --comment ${VPN}-nat-rule/}" -i /etc/ufw/before.rules + fi + else + $SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules + fi + # Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic) + $SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null + $SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any >/dev/null + + $SUDO ufw reload >/dev/null + echo "::: UFW configuration completed." + + elif [ "$USING_UFW" -eq 0 ]; then + # Now some checks to detect which rules we need to add. On a newly installed system all policies # should be ACCEPT, so the only required rule would be the MASQUERADE one. - $SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE + if ! $SUDO iptables -t nat -S | grep -q "${VPN}-nat-rule"; then + $SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" + fi # Count how many rules are in the INPUT and FORWARD chain. When parsing input from # iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found @@ -1470,15 +1668,23 @@ confNetwork(){ # chain (using -I). if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I INPUT 1 -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT + if $SUDO iptables -t nat -S | grep -q "${VPN}-input-rule"; then + INPUT_CHAIN_EDITED=0 + else + $SUDO iptables -I INPUT 1 -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT -m comment --comment "${VPN}-input-rule" + fi INPUT_CHAIN_EDITED=1 else INPUT_CHAIN_EDITED=0 fi if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then - $SUDO iptables -I FORWARD 1 -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - $SUDO iptables -I FORWARD 2 -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT + if $SUDO iptables -t nat -S | grep -q "${VPN}-forward-rule"; then + FORWARD_CHAIN_EDITED=0 + else + $SUDO iptables -I FORWARD 1 -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule" + $SUDO iptables -I FORWARD 2 -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT -m comment --comment "${VPN}-forward-rule" + fi FORWARD_CHAIN_EDITED=1 else FORWARD_CHAIN_EDITED=0 @@ -1492,9 +1698,8 @@ confNetwork(){ echo "INPUT_CHAIN_EDITED=${INPUT_CHAIN_EDITED}" >> /tmp/setupVars.conf echo "FORWARD_CHAIN_EDITED=${FORWARD_CHAIN_EDITED}" >> /tmp/setupVars.conf - fi - echo "USING_UFW=${USING_UFW}" >> /tmp/setupVars.conf + fi } confLogging() { @@ -1549,6 +1754,21 @@ installPiVPN(){ fi } +restartServices(){ + echo "::: Restarting services..." + case ${PLAT} in + Debian|Raspbian|Ubuntu) + if [ "$VPN" = "openvpn" ]; then + $SUDO systemctl enable openvpn.service &> /dev/null + $SUDO systemctl restart openvpn.service + elif [ "$VPN" = "wireguard" ]; then + $SUDO systemctl enable wg-quick@wg0.service &> /dev/null + $SUDO systemctl restart wg-quick@wg0.service + fi + ;; + esac +} + askUnattendedUpgrades(){ if [ "${runUnattended}" = 'true' ]; then if [ -z "$UNATTUPG" ]; then @@ -1667,134 +1887,4 @@ All incomplete posts or bug reports will be ignored or deleted.\\n\\nThank you f fi } -######## SCRIPT ############ - -main(){ - - ######## FIRST CHECK ######## - # Must be root to install - echo ":::" - if [[ $EUID -eq 0 ]];then - echo "::: You are root." - else - echo "::: sudo will be used for the install." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [[ $(dpkg-query -s sudo) ]];then - export SUDO="sudo" - export SUDOE="sudo -E" - else - echo "::: Please install sudo or run this as root." - exit 1 - fi - fi - - # Check arguments for the undocumented flags - for var in "$@"; do - case "$var" in - "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; - "--unattended" ) runUnattended=true;; - esac - done - - # Check for supported distribution - distroCheck - - # Checks for hostname Length - checkHostname - - if [[ "${runUnattended}" == true ]]; then - echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" - if [ -z "$2" ]; then - echo "::: No configuration file passed, using default settings..." - else - if [ -r "$2" ]; then - # shellcheck disable=SC1090 - source "$2" - else - echo "::: Can't open $2" - exit 1 - fi - fi - fi - - # Start the installer - # Verify there is enough disk space for the install - if [[ "${skipSpaceCheck}" == true ]]; then - echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" - else - verifyFreeDiskSpace - fi - - updatePackageCache - - # Notify user of package availability - notifyPackageUpdatesAvailable - - # Install packages used by this installation script - preconfigurePackages - installDependentPackages BASE_DEPS[@] - - # Display welcome dialogs - welcomeDialogs - - # Find interfaces and let the user choose one - chooseInterface - - if [ "$PLAT" != "Raspbian" ]; then - avoidStaticIPv4Ubuntu - else - getStaticIPv4Settings - setStaticIPv4 - fi - - # Choose the user for the ovpns - chooseUser - - # Clone/Update the repos - cloneOrUpdateRepos - - # Install - if installPiVPN; then - echo "::: Install Complete..." - else - exit 1 - fi - - echo "::: Restarting services..." - # Start services - case ${PLAT} in - Debian|Raspbian|Ubuntu) - if [ "$VPN" = "openvpn" ]; then - $SUDO systemctl enable openvpn.service &> /dev/null - $SUDO systemctl start openvpn.service - elif [ "$VPN" = "wireguard" ]; then - $SUDO systemctl enable wg-quick@wg0.service &> /dev/null - $SUDO systemctl start wg-quick@wg0.service - fi - ;; - esac - - # Ask if unattended-upgrades will be enabled - askUnattendedUpgrades - - if [ "$UNATTUPG" -eq 1 ]; then - confUnattendedUpgrades - fi - - # Save installation setting to the final location - echo "TO_INSTALL=(${TO_INSTALL[*]})" >> /tmp/setupVars.conf - $SUDO cp /tmp/setupVars.conf "$setupVars" - - installScripts - - # Ensure that cached writes reach persistent storage - echo "::: Flushing writes to disk..." - sync - echo "::: done." - - displayFinalMessage - echo ":::" -} - main "$@" diff --git a/scripts/openvpn/pivpnDebug.sh b/scripts/openvpn/pivpnDebug.sh index bc14f8f..df4e938 100755 --- a/scripts/openvpn/pivpnDebug.sh +++ b/scripts/openvpn/pivpnDebug.sh @@ -52,29 +52,27 @@ fi if [ "$USING_UFW" -eq 0 ]; then - if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - iptables -t nat -F - iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE + iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" iptables-save > /etc/iptables/rules.v4 echo "Done" fi fi - if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then - if iptables -C INPUT -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT &> /dev/null; then + if iptables -C INPUT -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule" &> /dev/null; then echo ":: [OK] Iptables INPUT rule set" else ERR=1 read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT + iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule" iptables-save > /etc/iptables/rules.v4 echo "Done" fi @@ -83,14 +81,14 @@ if [ "$USING_UFW" -eq 0 ]; then if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT &> /dev/null; then + if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule" &> /dev/null; then echo ":: [OK] Iptables FORWARD rule set" else ERR=1 read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT + iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule" + iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule" iptables-save > /etc/iptables/rules.v4 echo "Done" fi @@ -109,13 +107,13 @@ else fi fi - if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules ufw reload echo "Done" fi diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 552fecc..203aaa0 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -74,22 +74,22 @@ removeAll(){ ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null ### FIXME: SC2154 ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any > /dev/null - sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules - iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE + sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/${subnetClass} -o ${IPv4dev} -j MASQUERADE -m comment --comment ${VPN}-nat-rule\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules + iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" ufw reload &> /dev/null elif [ "$USING_UFW" -eq 0 ]; then if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then - iptables -D INPUT -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT + iptables -D INPUT -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT -m comment --comment "${VPN}-input-rule" fi if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then - iptables -D FORWARD -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - iptables -D FORWARD -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT + iptables -D FORWARD -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule" + iptables -D FORWARD -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT -m comment --comment "${VPN}-forward-rule" fi - iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE + iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" iptables-save > /etc/iptables/rules.v4 fi @@ -123,11 +123,17 @@ removeAll(){ # On armv6l Raspbian we manually remove the kernel module and skip the apt # uninstallation (since it's not an actual package). if [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv6l" ]; then - dkms remove wireguard/"${WG_SNAPSHOT}" --all - rm -rf /usr/src/wireguard-* + dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all + rm -rf /usr/src/wireguard-"${WG_MODULE_SNAPSHOT}" break fi + elif [ "${i}" = "wireguard-tools" ]; then + + if [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv6l" ]; then + rm -rf /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}" + fi + elif [ "${i}" = "dirmngr" ]; then # If dirmngr was installed, then we had previously installed wireguard on armv7l Raspbian @@ -187,7 +193,7 @@ removeAll(){ ### FIXME SC2154 rm -rf "$install_home/configs" elif [ "$VPN" = "openvpn" ]; then - rm -f /var/log/*openvpn* + rm -rf /var/log/*openvpn* rm -f /etc/openvpn/server.conf rm -f /etc/openvpn/crl.pem rm -rf /etc/openvpn/easy-rsa diff --git a/scripts/wireguard/pivpnDEBUG.sh b/scripts/wireguard/pivpnDEBUG.sh index 682dd98..56d9bd5 100755 --- a/scripts/wireguard/pivpnDEBUG.sh +++ b/scripts/wireguard/pivpnDEBUG.sh @@ -63,20 +63,49 @@ fi if [ "$USING_UFW" -eq 0 ]; then - if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - iptables -t nat -F - iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE + iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" iptables-save > /etc/iptables/rules.v4 - iptables-restore < /etc/iptables/rules.v4 echo "Done" fi fi + if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then + + if iptables -C INPUT -i "$IPv4dev" -p udp --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule" &> /dev/null; then + echo ":: [OK] Iptables INPUT rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then + iptables -I INPUT 1 -i "$IPv4dev" -p udp --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule" + iptables-save > /etc/iptables/rules.v4 + echo "Done" + fi + fi + fi + + if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then + + if iptables -C FORWARD -s 10.6.0.0/24 -i wg0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule" &> /dev/null; then + echo ":: [OK] Iptables FORWARD rule set" + else + ERR=1 + read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY + if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then + iptables -I FORWARD 1 -d 10.6.0.0/24 -i "$IPv4dev" -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule" + iptables -I FORWARD 2 -s 10.6.0.0/24 -i wg0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule" + iptables-save > /etc/iptables/rules.v4 + echo "Done" + fi + fi + fi + else if LANG="en_US.UTF-8" ufw status | grep -qw 'active'; then @@ -89,13 +118,13 @@ else fi fi - if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then + if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then echo ":: [OK] Iptables MASQUERADE rule set" else ERR=1 read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then - sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules + sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $IPv4dev -j MASQUERADE -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules ufw reload echo "Done" fi From a6087f8bda4429d02f5f6189a63568b8296bb28d Mon Sep 17 00:00:00 2001 From: Orazio Date: Sun, 29 Dec 2019 18:35:37 +0100 Subject: [PATCH 48/79] bc is not actually required when installing via DKMS --- auto_install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 4d37ddf..0379e82 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -926,7 +926,7 @@ installWireGuard(){ elif [ "$(uname -m)" = "armv6l" ]; then echo "::: Installing WireGuard from source... " - PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq bc) + PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq) installDependentPackages PIVPN_DEPS[@] # Delete any leftover code From 41984e5f40e076feb3a896209ee3c1ac23c398a4 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 30 Dec 2019 11:44:33 +0100 Subject: [PATCH 49/79] Fix update scripts from test branch --- auto_install/install.sh | 4 ++-- scripts/{openvpn => }/update.sh | 32 +++++++++++++++++++------------ scripts/wireguard/bash-completion | 4 ++-- scripts/wireguard/pivpn | 8 ++++++++ 4 files changed, 32 insertions(+), 16 deletions(-) rename scripts/{openvpn => }/update.sh (68%) diff --git a/auto_install/install.sh b/auto_install/install.sh index 0379e82..166b501 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -125,8 +125,8 @@ main(){ if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then : elif [ "$UpdateCmd" = "Update" ]; then - ### To do: test the update script and implement update for WireGuard as well - $SUDO /opt/pivpn/update.sh + $SUDO /opt/pivpn/update.sh "$@" + exit 0 elif [ "$UpdateCmd" = "Repair" ]; then source "$setupVars" runUnattended=true diff --git a/scripts/openvpn/update.sh b/scripts/update.sh similarity index 68% rename from scripts/openvpn/update.sh rename to scripts/update.sh index 5203b65..3f63c2a 100755 --- a/scripts/openvpn/update.sh +++ b/scripts/update.sh @@ -6,7 +6,14 @@ pivpnrepo="https://github.com/pivpn/pivpn.git" pivpnlocalpath="/etc/.pivpn" pivpnscripts="/opt/pivpn/" bashcompletiondir="/etc/bash_completion.d/" +setupVars="/etc/pivpn/setupVars.conf" +if [ ! -f "${setupVars}" ]; then + echo "::: Missing setup vars file!" + exit 1 +fi + +source "${setupVars}" ###Functions ##Updates scripts @@ -16,7 +23,7 @@ updatepivpnscripts(){ echo "going do update PiVPN Scripts" if [[ -d "$pivpnlocalpath" ]]; then if [[ -n "$pivpnlocalpath" ]]; then - sudo rm -rf "${pivpnlocalpath}/../.pivpn" + rm -rf "${pivpnlocalpath}/../.pivpn" cloneandupdate fi else @@ -32,7 +39,7 @@ updatefromtest(){ echo "PiVPN Scripts updating from test branch" if [[ -d "$pivpnlocalpath" ]]; then if [[ -n "$pivpnlocalpath" ]]; then - rm -rf "{$pivpnlocalpath}/../.pivpn" + rm -rf "${pivpnlocalpath}/../.pivpn" cloneupdttest fi else @@ -41,22 +48,23 @@ updatefromtest(){ echo "PiVPN Scripts updated have been updated from test branch" } -##Clone and copy pivpn scripts to /op/ +##Clone and copy pivpn scripts to /opt/pivpn cloneandupdate(){ - sudo git clone "$pivpnrepo" "$pivpnlocalpath" - sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" - sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" + git clone "$pivpnrepo" "$pivpnlocalpath" + cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" + cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" } ##same as cloneandupdate() but from test branch ##and falls back to master branch again after updating cloneupdttest(){ - sudo git clone "$pivpnrepo" "$pivpnlocalpath" - sudo git -C "$pivpnlocalpath" checkout test - sudo git -C "$pivpnlocalpath" pull origin test - sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" - sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" - sudo git -C "$pivpnlocalpath" checkout master + git clone "$pivpnrepo" "$pivpnlocalpath" + git -C "$pivpnlocalpath" checkout test + git -C "$pivpnlocalpath" pull origin test + cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" + cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts" + cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir" + git -C "$pivpnlocalpath" checkout master } scriptusage(){ diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion index 9eb591e..ff434c3 100644 --- a/scripts/wireguard/bash-completion +++ b/scripts/wireguard/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -qr -r -h -u" - opts="add clients debug list qrcode remove help uninstall" + dashopts="-a -c -d -l -qr -r -h -u -up" + opts="add clients debug list qrcode remove help uninstall update" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn index 3f96004..f3a14c9 100755 --- a/scripts/wireguard/pivpn +++ b/scripts/wireguard/pivpn @@ -48,6 +48,12 @@ uninstallServer(){ exit 0 } +updateScripts(){ + shift + $SUDO /opt/pivpn/update.sh "$@" + exit 0 +} + showHelp(){ echo "::: Control all PiVPN specific functions!" echo ":::" @@ -62,6 +68,7 @@ showHelp(){ echo "::: -r, remove Remove a client" echo "::: -h, help Show this help dialog" echo "::: -u, uninstall Uninstall pivpn from your system!" + echo "::: -up, update Updates PiVPN Scripts" exit 0 } @@ -79,5 +86,6 @@ case "$1" in "-r" | "remove" ) removeClient "$@";; "-h" | "help" ) showHelp;; "-u" | "uninstall" ) uninstallServer;; +"-up" | "update" ) updateScripts "$@" ;; * ) showHelp;; esac From fdb512d7d6f79ce12494e3912429e14ccf08be80 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 30 Dec 2019 21:55:37 +0100 Subject: [PATCH 50/79] Update README.md --- README.md | 153 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 0df15c2..e70a8c7 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ About Visit the [PiVPN](https://pivpn.dev) site for more information. This is a set of shell scripts initially developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM) into a VPN server using two free, open-source protocols: - * [Wireguard](https://www.wireguard.com/) + * [WireGuard](https://www.wireguard.com/) * [OpenVPN](https://openvpn.net) -Have you been looking for a good guide or tutorial for installing openvpn on a raspberry pi or ubuntu based server? +Have you been looking for a good guide or tutorial for setting up a VPN server on a Raspberry Pi or Ubuntu based server? Run this script and you don't need a guide or tutorial, this will do it all for you, in a fraction of the time and with hardened security settings in place by default. -The master branch of this script installs and configures either Wireguard or OpenVPN on Raspbian, Debian or Ubuntu and it as been tested to run not only on Raspberry pi but also in any Cloud Provider VPS. -We recommend using the Latest Raspbian lite image on a raspberry pi in your home so you can VPN into your home from a unsecure remote locations and safely use the internet. +The master branch of this script installs and configures either WireGuard or OpenVPN on Raspbian, Debian or Ubuntu and it as been tested to run not only on Raspberry Pi but also in any Cloud Provider VPS. +We recommend using the latest Raspbian Lite image on a Raspberry Pi in your home so you can VPN into your home from a unsecure remote locations and safely use the internet. However, the scripts do try to detect different distributions and make adjustments accordingly. They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables. @@ -21,7 +21,7 @@ Followed by easy management of the VPN thereafter with the 'pivpn' command. That being said... > This will also work on a free-tier Amazon AWS server using Ubuntu or Debian. I don't want to support every scenario there but getting it to run and install successfully on a free server in the cloud was also important. -Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the amazon infrastructure. +Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the Amazon infrastructure. Prerequisites ------------- @@ -66,51 +66,57 @@ sudo sh pivpn/auto_install/install.sh ``` **OBS:** -in alternative to install.pivpn.dev you can use the raw github link: +In alternative to install.pivpn.dev you can use the raw github link: https://raw.githubusercontent.com/pivpn/pivpn/master/auto_install/install.sh **To install from Test/Development branch** Check our [Wiki Page](https://github.com/pivpn/pivpn/wiki#testing) +**How it works** -The script will first update your APT repositories, upgrade packages, and install OpenVPN, -which will take some time. -It will ask which authentication method you wish the guts of your server to use, 1024-bit, 2048-bit, or 4096-bit. -If you're unsure or don't have a convincing reason one way or the other I'd use 2048 today. From the OpenVPN site: +The script will first update your APT repositories, upgrade packages, and install WireGuard (default) or OpenVPN, which will take some time. + +It will ask which authentication method you wish the guts of your server to use. If you go for WireGuard, you don't get to choose: you will use a Curve25519 public key, which provides 128-bit security. On the other end, if you prefer OpenVPN, you can choose between a 2048-bit, 3072-bit, or 4096-bit RSA certificate. If you're unsure or don't have a convincing reason one way or the other I'd use 2048 today (provides 112-bit security). + +From the OpenVPN site: > For asymmetric keys, general wisdom is that 1024-bit keys are no longer sufficient to protect against well-equipped adversaries. Use of 2048-bit is a good minimum. It is wise to ensure all keys across your active PKI (including the CA root keypair) are using at least 2048-bit keys. > Up to 4096-bit is accepted by nearly all RSA systems (including OpenVPN), but use of keys this large will dramatically increase generation time, TLS handshake delays, and CPU usage for TLS operations; the benefit beyond 2048-bit keys is small enough not to be of great use at the current time. It is often a larger benefit to consider lower validity times than more bits past 2048, but that is for you to decide. -Luckily, OpenVPN 2.4 supports ECDSA certificates, which are based on Elliptic Curves, allowing much smaller keys while providing an equivalent security level (256 bit long, equivalent to 3072 bit RSA). For this reason, PiVPN now uses ECDSA certs if you choose to enable OpenVPN 2.4 features. If not, the usual RSA certificates are generated in case the user has clients running an older version of OpenVPN. +After this, the script will go back to the command line as it builds the server's own certificate authority (OpenVPN only). The script will ask you if you'd like to change the default port, protocol, client's DNS server, etc. If you know you want to change these things, feel free, and the script will put all the information where it needs to go in the various config files. -After this, the script will go back to the command line as it builds the server's own -certificate authority. The script will ask you if you'd like to change the certificate fields, -the default port, client's DNS server, etc. If you know you want to change these things, feel free, -and the script will put all the information where it needs to go in the various config files. -If you aren't sure, it has been designed that you can simply hit 'Enter' through all the questions -and have a working configuration at the end. +If you aren't sure, it has been designed that you can simply hit 'Enter' through all the questions and have a working configuration at the end. -Finally, the script will take some time to build the server's Diffie-Hellman key -exchange. If you chose 1024-bit encryption, this will just take a few minutes, but if you -chose 2048-bit, it will take much longer (anywhere from 40 minutes to several hours on a -Model B+). +Finally, the script will take some time to build the server's Diffie-Hellman key exchange (OpenVPN only). If you chose 2048-bit encryption, it will take about 40 minutes on a Model B+, and several hours if you choose a larger size. -**NOTE: Diffie-Hellman parameters are NOT generated if you choose not to use OpenVPN 2.4.** +The script will also make some changes to your system to allow it to forward internet traffic and allow VPN connections through the Pi's firewall. When the script informs you that it has finished configuring PiVPN, it will ask if you want to reboot. I have it where you do not need to reboot when done but it also can't hurt. -The script will also make some changes to your system to allow it to forward -internet traffic and allow VPN connections through the Pi's firewall. When the script -informs you that it has finished configuring OpenVPN, it will ask if you want to reboot. -I have it where you do not need to reboot when done but it also can't hurt. +After the installation is complete you can use the command `pivpn` to manage the server. The commands below are just to get started, run `pivpn -h` to see the full list of options. - -Managing the PiVPN +Managing the PiVPN (WireGuard) ---------------------- -After the installation is complete you can use the command 'pivpn' to manage the server. +`pivpn add` +You will be prompted to enter a name for your client. Pick anything you like and hit 'enter'. +The script will assemble the client .conf file and place it in the directory 'configs' within your +home directory. -"pivpn add" +`pivpn remove` +Asks you for the name of the client to remove. Once you remove a client, it will no longer allow you to use +the given client config (specifically its public key) to connect. This is useful for many reasons but some ex: +You have a profile on a mobile phone and it was lost or stolen. Remove its key and generate a new +one for your new phone. Or even if you suspect that a key may have been compromised in any way, +just revoke it and generate a new one. + +`pivpn list` +If you add more than a few clients, this gives you a nice list of their names and associated keys. + +Managing the PiVPN (OpenVPN) +---------------------- + +`pivpn add` You will be prompted to enter a name for your client. Pick anything you like and hit 'enter'. You will be asked to enter a pass phrase for the client key; make sure it's one you'll remember. The script will assemble the client .ovpn file and place it in the directory 'ovpns' within your @@ -119,48 +125,82 @@ home directory. If you need to create a client certificate that is not password protected (IE for use on a router), then you can use the 'pivpn add nopass' option to generate that. -"pivpn revoke" +`pivpn revoke` Asks you for the name of the client to revoke. Once you revoke a client, it will no longer allow you to use the given client certificate (ovpn config) to connect. This is useful for many reasons but some ex: You have a profile on a mobile phone and it was lost or stolen. Revoke its cert and generate a new one for your new phone. Or even if you suspect that a cert may have been compromised in any way, just revoke it and generate a new one. -"pivpn list" +`pivpn list` If you add more than a few clients, this gives you a nice list of their names and whether their certificate is still valid or has been revoked. Great way to keep track of what you did with 'pivpn add' and 'pivpn revoke'. -You can run just 'pivpn' to see all the options. - -Importing .ovpn Profiles on Client Machines +Importing Profiles on Client Machines -------------------------------------------- -To move a client .ovpn profile to Windows, use a program like WinSCP or Cyberduck. Note that -you may need administrator permission to move files to some folders on your Windows machine, -so if you have trouble transferring the profile to a particular folder with your chosen file -transfer program, try moving it to your desktop. To move a profile to Android, you can either -retrieve it on PC and then move it to your device via USB, or you can use an app like Turbo -FTP & SFTP client to retrieve it directly from your Android device. +**Windows**: Use a program like WinSCP or Cyberduck. Note that you may need administrator permission to move files to some folders on your Windows machine, so if you have trouble transferring the profile to a particular folder with your chosen file transfer program, try moving it to your desktop. -To import the profile to OpenVPN on Windows, download the OpenVPN GUI from the community downloads -section of openvpn.net, install it, and place the profile in the 'config' folder of your OpenVPN -directory, i.e., in 'C:\Program Files\OpenVPN\config'. To import the profile on Android, install -the OpenVPN Connect app, select 'Import' from the drop-down menu in the upper right corner of the -main screen, choose the directory on your device where you stored the .ovpn file, and select the -file. +**Mac/Linux**: Open the Terminal app and connect to the Raspberry Pi using `sftp your-user@ip-of-your-raspberry`. Download the config using `get /home/your-user/configs/whatever.conf` (if using WireGuard) or `get /home/your-user/ovpns/whatever.ovpn` (if using OpenVPN). The file will be downloaded in the current working directory, which usually is the home folder of your PC. -After importing, connect to the VPN server on Windows by running the OpenVPN GUI with -administrator permissions, right-clicking on the icon in the system tray, and clicking 'Connect', -or on Android by selecting the profile under 'OpenVPN Profile' and pressing 'Connect'. You'll be -asked to enter the pass phrase you chose. Do so, and you're in! Enjoy your ~$50 USD private VPN. +**Android/iOS** (WireGuard only): Just skip to _Connecting to the PiVPN server (WireGuard)_ + +**Android**: You can either retrieve it on PC and then move it to your device via USB, or you can use an app like Turbo FTP & SFTP client to retrieve it directly from your Android device. + +**iOS**: You can use an app that supports SFTP like Documents by Readdle to retrieve it directly from your iOS device. + +Connecting to the PiVPN server (WireGuard) +-------------------------------------------- + +**Windows/Mac**: Download the [WireGuard GUI app](https://www.wireguard.com/install/), import the configuration and activate the tunnel. + +**Linux**: Install [WireGuard](https://www.wireguard.com/install/) following the instructions for your distribution. Now, create the /etc/wireguard folder and prevent anyone but root to enter it (you only need to do this the first time): +``` +# mkdir /etc/wireguard +# chown root:root /etc/wireguard +# chmod 700 /etc/wireguard +``` +Move the config and activate the tunnel: +``` +# mv whatever.conf /etc/wireguard/ +# wg-quick up whatever +[...] +# +``` +Use `wg-quick down whatever` to deactivate the tunnel. + +**Android/iOS:** Run `pivpn -qr` to generate a QR code of your config, download the Wireguard app [Android link](https://play.google.com/store/apps/details?id=com.wireguard.android) / [iOS link](https://apps.apple.com/it/app/wireguard/id1441195209), click the '+' sign and scan the QR code with your phone's camera. Flip the switch to activate the tunnel. + +Connecting to the PiVPN server (OpenVPN) +-------------------------------------------- + +**Windows**: Download the [OpenVPN GUI](https://openvpn.net/community-downloads/), install it, and place the profile in the 'config' folder of your OpenVPN directory, i.e., in 'C:\Program Files\OpenVPN\config'. After importing, connect to the VPN server on Windows by running the OpenVPN GUI with administrator permissions, right-clicking on the icon in the system tray, and clicking 'Connect'. + +**Android**: Install the [OpenVPN Connect app](https://play.google.com/store/apps/details?id=net.openvpn.openvpn), select 'Import' from the drop-down menu in the upper right corner of the main screen, choose the directory on your device where you stored the .ovpn file, and select the file. Connect by selecting the profile under 'OpenVPN Profile' and pressing 'Connect'. + +**Linux**: Install OpenVPN using your package manager (APT in this example). Now, create the /etc/openvpn/client folder and prevent anyone but root to enter it (you only need to do this the first time): +``` +# apt install openvpn +# mkdir -p /etc/openvpn/client +# chown root:root /etc/openvpn/client +# chmod 700 /etc/openvpn/client +``` +Move the config and connect: +``` +# mv whatever.ovpn /etc/openvpn/client/ +# openvpn /etc/openvpn/client/whatever.ovpn +[...] +``` +Press CTRL-C to disconnect. + +**iOS**: Install the [OpenVPN Connect app](https://apps.apple.com/it/app/openvpn-connect/id590379981). Then go to the app where you copied the .ovpn file to, select the file, find an icon or button to 'Share' or 'Open with', and choose to open with the OpenVPN app. + +**Mac**: You can use an OpenVPN client like [Tunnelblick](https://tunnelblick.net/downloads.html). Here's a [guide](https://tunnelblick.net/czUsing.html) to import the configuration. Removing PiVPN ---------------- -If at any point you wish to remove OpenVPN from your Pi and revert it to a -pre-installation state, such as if you want to undo a failed installation to try again or -you want to remove OpenVPN without installing a fresh Raspbian image, just run -'pivpn uninstall' +If at any point you wish to remove PiVPN from your Pi and revert it to a pre-installation state, such as if you want to undo a failed installation to try again or you want to remove PiVPN without installing a fresh Raspbian image, just run `pivpn uninstall`. Feedback & Support -------- @@ -189,6 +229,9 @@ A secure docker container that sets up PiVPN and SSH. [OpenVPN](https://openvpn.net) The foundation for all open-source VPN projects. +[WireGuard](https://www.wireguard.com/) +*An extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography.* + Contributions ------------- From 66e4156fb1148e65b4a6f81638989bce71ae966e Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 30 Dec 2019 22:00:41 +0100 Subject: [PATCH 51/79] Add logo --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e70a8c7..84a36ba 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![WireGuard + OpenVPN logo](logos.jpg) + About ----- From 3e1126ac1aedba8b6a934d57075141205a8c7185 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 30 Dec 2019 22:02:23 +0100 Subject: [PATCH 52/79] Add logo (2) --- logos.jpg | Bin 0 -> 74614 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 logos.jpg diff --git a/logos.jpg b/logos.jpg new file mode 100644 index 0000000000000000000000000000000000000000..890fec994bc3af8d6a6f4c15e45419e69341c042 GIT binary patch literal 74614 zcmeFYc{tSX-#0v>l#*1EEK?yORFVjjgbG!+t>-v4a*YzC7b3e~<|8d{Xbso++jyXS{Ii2tGe6O$f`{WLA zYazlrdG_x-&C7EfvQ3zWSD1&}0D(dvJllEx(IEfUc((EKZQsGabCl8Mt8>n^E>>CV`p~k*EQ$A^W?zsvmrYVUXIHss@o;4dV?x**RxaLkj%MpS=t}c{z2LQGr~gu zUs3k&g#8Cy!w@~lwtqC8%{6`b`x3=dWZSS8Z^zV%e zPQnAu!NUVygVQ?@d`s=5H>3_N*?mx{lE7Bl)wDf7|X85BA@jfF4WV3SJH}Mq97ne3qU3&i{`f*EtCc%p4 zvV>=z1++)Sxe#$X$Di+ZT;z*iob(;p|8<6j-_r{l%YpH@6>cw#$zDhpLI@Tf@6$I4KC}ob^Vb0(hEv~=k}^!oSi`B@<^=$ z=cencpr=g<=Ir7P6`_oj1}3 zS8R%iP|cFKknIxeH06(nhK3&w@om-1E`>S6iSb?5)&3^*Y<4=!!(2;yqUO92;&7BJ zx`}#@f|eRhy0)1Mb_k&glVc))Pe$Hgx1B2w;T~y?kA7$?Z0ZIka>RbhvnCL zKAvWK?8k+1m7ye#;YBEOM>7|a_3`}!0P9d)Wm1evXemEd{z7jbvp8+Ia%PmU#*Rl{ zK&ERs7}h!}e+ycI8$GihcF-7+DH{&eY#SLAOWNaUqptN57ox@~a9m^V!?fP-gDq}< z!i8j8l`49%YGi05mP)I?s;#MlMpBy_bxzUb zVoIxU!a%Wk%FUj_fszEXsR8Dmb>1%$0<@y7YFFl$UR(|p8?jMTWb@Ku@*{nj3uz6& zWg-q^#nFept{*MVmajad4X%q_vO>sdZGv)mElB z{(kT#aO(BgDSA0IAg&T?F#d{}Co)Ga#x~&vP-3);^XW=d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*E zI{1I<*I@ol0GWdI7&yL~x#GEaLqoMTW*AcO{Zr!06q~osEmY{MDBHjZi;Xmoh{$mdRfADwEKgR#hNc`LEp-c9OMMCD*HU{uXa;5q{J2%n=4+3W! zT>ZD~lRzB_c B1c?9u literal 0 HcmV?d00001 From ed46588900e607fc3a6dc1c62aed0ce8c7ec5bbd Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 31 Dec 2019 10:43:10 +0100 Subject: [PATCH 53/79] Add rm safeguard to updateRepo(), update README --- README.md | 47 +++++++++++++++++++---------------------- auto_install/install.sh | 6 +++++- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 84a36ba..3e2a174 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Asks you for the name of the client to remove. Once you remove a client, it wil the given client config (specifically its public key) to connect. This is useful for many reasons but some ex: You have a profile on a mobile phone and it was lost or stolen. Remove its key and generate a new one for your new phone. Or even if you suspect that a key may have been compromised in any way, -just revoke it and generate a new one. +just remove it and generate a new one. `pivpn list` If you add more than a few clients, this gives you a nice list of their names and associated keys. @@ -143,7 +143,7 @@ Importing Profiles on Client Machines **Windows**: Use a program like WinSCP or Cyberduck. Note that you may need administrator permission to move files to some folders on your Windows machine, so if you have trouble transferring the profile to a particular folder with your chosen file transfer program, try moving it to your desktop. -**Mac/Linux**: Open the Terminal app and connect to the Raspberry Pi using `sftp your-user@ip-of-your-raspberry`. Download the config using `get /home/your-user/configs/whatever.conf` (if using WireGuard) or `get /home/your-user/ovpns/whatever.ovpn` (if using OpenVPN). The file will be downloaded in the current working directory, which usually is the home folder of your PC. +**Mac/Linux**: Open the Terminal app and copy the config from the Raspberry Pi using `scp pi-user@ip-of-your-raspberry:configs/whatever.conf .` (if using WireGuard) or `scp pi-user@ip-of-your-raspberry:ovpns/whatever.ovpn .` (if using OpenVPN). The file will be downloaded in the current working directory, which usually is the home folder of your PC. **Android/iOS** (WireGuard only): Just skip to _Connecting to the PiVPN server (WireGuard)_ @@ -156,20 +156,18 @@ Connecting to the PiVPN server (WireGuard) **Windows/Mac**: Download the [WireGuard GUI app](https://www.wireguard.com/install/), import the configuration and activate the tunnel. -**Linux**: Install [WireGuard](https://www.wireguard.com/install/) following the instructions for your distribution. Now, create the /etc/wireguard folder and prevent anyone but root to enter it (you only need to do this the first time): +**Linux**: Install [WireGuard](https://www.wireguard.com/install/) following the instructions for your distribution. Now, as root user, create the /etc/wireguard folder and prevent anyone but root to enter it (you only need to do this the first time): ``` -# mkdir /etc/wireguard -# chown root:root /etc/wireguard -# chmod 700 /etc/wireguard +mkdir -p /etc/wireguard +chown root:root /etc/wireguard +chmod 700 /etc/wireguard ``` Move the config and activate the tunnel: ``` -# mv whatever.conf /etc/wireguard/ -# wg-quick up whatever -[...] -# +mv whatever.conf /etc/wireguard/ +systemctl start wg-quick@whatever ``` -Use `wg-quick down whatever` to deactivate the tunnel. +Run `systemctl stop wg-quick@whatever` to deactivate the tunnel. **Android/iOS:** Run `pivpn -qr` to generate a QR code of your config, download the Wireguard app [Android link](https://play.google.com/store/apps/details?id=com.wireguard.android) / [iOS link](https://apps.apple.com/it/app/wireguard/id1441195209), click the '+' sign and scan the QR code with your phone's camera. Flip the switch to activate the tunnel. @@ -178,27 +176,26 @@ Connecting to the PiVPN server (OpenVPN) **Windows**: Download the [OpenVPN GUI](https://openvpn.net/community-downloads/), install it, and place the profile in the 'config' folder of your OpenVPN directory, i.e., in 'C:\Program Files\OpenVPN\config'. After importing, connect to the VPN server on Windows by running the OpenVPN GUI with administrator permissions, right-clicking on the icon in the system tray, and clicking 'Connect'. -**Android**: Install the [OpenVPN Connect app](https://play.google.com/store/apps/details?id=net.openvpn.openvpn), select 'Import' from the drop-down menu in the upper right corner of the main screen, choose the directory on your device where you stored the .ovpn file, and select the file. Connect by selecting the profile under 'OpenVPN Profile' and pressing 'Connect'. - -**Linux**: Install OpenVPN using your package manager (APT in this example). Now, create the /etc/openvpn/client folder and prevent anyone but root to enter it (you only need to do this the first time): +**Linux**: Install OpenVPN using your package manager (APT in this example). Now, as root user, create the /etc/openvpn/client folder and prevent anyone but root to enter it (you only need to do this the first time): ``` -# apt install openvpn -# mkdir -p /etc/openvpn/client -# chown root:root /etc/openvpn/client -# chmod 700 /etc/openvpn/client +apt install openvpn +mkdir -p /etc/openvpn/client +chown root:root /etc/openvpn/client +chmod 700 /etc/openvpn/client ``` Move the config and connect: ``` -# mv whatever.ovpn /etc/openvpn/client/ -# openvpn /etc/openvpn/client/whatever.ovpn -[...] +mv whatever.ovpn /etc/openvpn/client/whatever.conf +systemctl start openvpn-client@whatever ``` -Press CTRL-C to disconnect. - -**iOS**: Install the [OpenVPN Connect app](https://apps.apple.com/it/app/openvpn-connect/id590379981). Then go to the app where you copied the .ovpn file to, select the file, find an icon or button to 'Share' or 'Open with', and choose to open with the OpenVPN app. +Run `systemctl stop openvpn-client@whatever` to disconnect. **Mac**: You can use an OpenVPN client like [Tunnelblick](https://tunnelblick.net/downloads.html). Here's a [guide](https://tunnelblick.net/czUsing.html) to import the configuration. +**Android**: Install the [OpenVPN Connect app](https://play.google.com/store/apps/details?id=net.openvpn.openvpn), select 'Import' from the drop-down menu in the upper right corner of the main screen, choose the directory on your device where you stored the .ovpn file, and select the file. Connect by selecting the profile under 'OpenVPN Profile' and pressing 'Connect'. + +**iOS**: Install the [OpenVPN Connect app](https://apps.apple.com/it/app/openvpn-connect/id590379981). Then go to the app where you copied the .ovpn file to, select the file, find an icon or button to 'Share' or 'Open with', and choose to open with the OpenVPN app. + Removing PiVPN ---------------- @@ -252,7 +249,7 @@ sources. 3. Of course there is [OpenVPN](https://openvpn.net) -4. Also [Wireguard](https://www.wireguard.com/) +4. Also [WireGuard](https://www.wireguard.com/) 5. And as always the ever vigilant [EFF](https://www.eff.org/) diff --git a/auto_install/install.sh b/auto_install/install.sh index 166b501..3625e70 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -796,7 +796,11 @@ updateRepo(){ else # Pull the latest commits echo -n "::: Updating repo in $1..." - $SUDO rm -rf "${1}" + ### FIXME: Never call rm -rf with a plain variable. Never again as SU! + #$SUDO rm -rf "${1}" + if test -n "$1"; then + $SUDO rm -rf "$(dirname "$1")/.pivpn" + fi # Go back to /etc otherwise git will complain when the current working # directory has just been deleted (/etc/.pivpn). cd /etc && \ From a9f5e7346fa596f021bcf8a043b749dc14b86986 Mon Sep 17 00:00:00 2001 From: Orazio Date: Tue, 31 Dec 2019 12:28:26 +0100 Subject: [PATCH 54/79] Revert to more portable commands --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3e2a174..276892a 100644 --- a/README.md +++ b/README.md @@ -165,11 +165,11 @@ chmod 700 /etc/wireguard Move the config and activate the tunnel: ``` mv whatever.conf /etc/wireguard/ -systemctl start wg-quick@whatever +wg-quick up whatever ``` -Run `systemctl stop wg-quick@whatever` to deactivate the tunnel. +Run `wg-quick down whatever` to deactivate the tunnel. -**Android/iOS:** Run `pivpn -qr` to generate a QR code of your config, download the Wireguard app [Android link](https://play.google.com/store/apps/details?id=com.wireguard.android) / [iOS link](https://apps.apple.com/it/app/wireguard/id1441195209), click the '+' sign and scan the QR code with your phone's camera. Flip the switch to activate the tunnel. +**Android/iOS:** Run `pivpn -qr` on the PiVPN server to generate a QR code of your config, download the Wireguard app [Android link](https://play.google.com/store/apps/details?id=com.wireguard.android) / [iOS link](https://apps.apple.com/it/app/wireguard/id1441195209), click the '+' sign and scan the QR code with your phone's camera. Flip the switch to activate the tunnel. Connecting to the PiVPN server (OpenVPN) -------------------------------------------- @@ -183,12 +183,12 @@ mkdir -p /etc/openvpn/client chown root:root /etc/openvpn/client chmod 700 /etc/openvpn/client ``` -Move the config and connect: +Move the config and connect (input the pass phrase if you set one): ``` -mv whatever.ovpn /etc/openvpn/client/whatever.conf -systemctl start openvpn-client@whatever +mv whatever.ovpn /etc/openvpn/client/ +openvpn /etc/openvpn/client/whatever.ovpn ``` -Run `systemctl stop openvpn-client@whatever` to disconnect. +Press CTRL-C to disconnect. **Mac**: You can use an OpenVPN client like [Tunnelblick](https://tunnelblick.net/downloads.html). Here's a [guide](https://tunnelblick.net/czUsing.html) to import the configuration. From ef6e84419e6e7e0e10937c42c0ff8210d42a4a3d Mon Sep 17 00:00:00 2001 From: Orazio Date: Thu, 2 Jan 2020 18:50:12 +0100 Subject: [PATCH 55/79] Fix typo and mv command --- auto_install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 3625e70..d9fc07f 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -872,7 +872,7 @@ askWhichVPN(){ fi fi else - if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); + if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choice expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); then VPN="wireguard" else @@ -1498,7 +1498,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null else # Generate Diffie-Hellman key exchange ${SUDOE} ./easyrsa gen-dh - ${SUDOE} mv "pki/dh.pem pki/dh${pivpnENCRYPT}.pem" + ${SUDOE} mv "pki/dh.pem" "pki/dh${pivpnENCRYPT}.pem" fi # Generate static HMAC key to defend against DDoS From 78a6f14742a515425a01e272b22425f455c81138 Mon Sep 17 00:00:00 2001 From: h-town <29696865+h-town@users.noreply.github.com> Date: Fri, 3 Jan 2020 10:43:23 -0600 Subject: [PATCH 56/79] Replace mention of 'Google' with 'Quad9' --- auto_install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 4787fa4..247016a 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -949,7 +949,7 @@ askClientDNS(){ elif [ -z "$pivpnDNS1" ] && [ -z "$pivpnDNS2" ]; then pivpnDNS1="9.9.9.9" pivpnDNS2="149.112.112.112" - echo "::: No DNS provider specified, using Google DNS ($pivpnDNS1 $pivpnDNS2)" + echo "::: No DNS provider specified, using Quad9 DNS ($pivpnDNS1 $pivpnDNS2)" fi local INVALID_DNS_SETTINGS=0 From 465d157a194528f2052ba7b22c0042750cd7aa73 Mon Sep 17 00:00:00 2001 From: h-town <29696865+h-town@users.noreply.github.com> Date: Fri, 3 Jan 2020 10:56:28 -0600 Subject: [PATCH 57/79] Revise route query for IP & GW selection from Quad9 to TEST-NET-1 --- auto_install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 247016a..047b4e0 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -57,8 +57,8 @@ r=$(( r < 20 ? 20 : r )) c=$(( c < 70 ? 70 : c )) # Find IP used to route to outside world -IPv4addr=$(ip route get 9.9.9.9 | awk '{print $7}') -IPv4gw=$(ip route get 9.9.9.9 | awk '{print $3}') +IPv4addr=$(ip route get 192.0.2.1 | awk '{print $7}') +IPv4gw=$(ip route get 192.0.2.2 | awk '{print $3}') availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) dhcpcdFile=/etc/dhcpcd.conf From 5cea5bddf80d9138b946a21d01ad5513dfd3cbbb Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Mon, 6 Jan 2020 02:06:47 +0100 Subject: [PATCH 58/79] Code Review: Improvements & Bug Fixes * Removed Unecessary pipe on availableInterfaces * Changed OS Support messages accross the script - Removed OS Version names from the script, this avoids having to change the code everytime a new OS Version is Released, instead we update the wiki with propper information. * Changed MaybeOSSupport whiptail tiltes and messages to make it more clear. - Messages and titles could cause confusion to users and specially developers * Moved Funcions Comment to correct place. * DistroCheck Function: - Moved up before other functions so it better refflects the order they are called. - changed Case identation to make it easier to read. - Added info to # compatibility Comment, Removed unecessary comments - added break to exit out of case, easier to understand that the script should move on. * Added Shellcheck ignores, * chooseinterface Function: - Changed function Logic and cleaned it up - Fixed Issue #906 - Added exit code if no interfaces are found * Updated LatestUpdate.md --- LatestUpdate.md | 35 +++++-- auto_install/install.sh | 221 +++++++++++++++++++++------------------- 2 files changed, 144 insertions(+), 112 deletions(-) diff --git a/LatestUpdate.md b/LatestUpdate.md index dacab55..c96709f 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -1,9 +1,30 @@ # Information of Latest updates This file has the objective of describing the major changes for each merge from test to master in a similar way as a -patch release notes. +patch release notes. + +Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged. + +##Jan 6th 2020 + +* Removed Unecessary pipe on availableInterfaces +* Changed OS Support messages accross the script + - Removed OS Version names from the script, this avoids having to change the code everytime a new OS Version is Released, instead we update the wiki with propper information. +* Changed MaybeOSSupport whiptail tiltes and messages to make it more clear. + - Messages and titles could cause confusion to users and specially developers +* Moved Funcions Comment to correct place. +* DistroCheck Function: + - Moved up before other functions so it better refflects the order they are called. + - changed Case identation to make it easier to read. + - Added info to # compatibility Comment, Removed unecessary comments + - added break to exit out of case, easier to understand that the script should move on. +* Added Shellcheck ignores, +* chooseinterface Function: + - Changed function Logic and cleaned it up + - Fixed Issue #906 + - Added exit code if no interfaces are found +* Updated LatestUpdate.md -Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged. ## Oct 12th 2019 @@ -12,11 +33,11 @@ Everytime Test branch is merged into master, a new entry should be created with * added backup script to backup openvpn and pivpn generated certificates * added update script to update /opt/pivpn scripts, -t | --test | test update from test branch * Fixed hostname length issue #831 - - the script now checks for hostname length right at the beginning and prompts for a new one. - - HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only. + - the script now checks for hostname length right at the beginning and prompts for a new one. + - HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only. * fixed ubuntu 18.04 being detected as not supported OS, now fully supported and tested. * changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all *.sh files making it easier to manage when adding new scripts/features -* Changed how supported OS are presented when maybeOS_Support() is called. +* Changed how supported OS are presented when maybeOS_Support() is called. ## Sept 1st 2019 @@ -31,14 +52,14 @@ Everytime Test branch is merged into master, a new entry should be created with * bugfixes and typos * permissions hardening and writing uniformization * improved pivpn user and ovpns dirs handling -* Changes variable and file naming in `install.sh` +* Changes variable and file naming in `install.sh` - $pivPNUser renamed to $INSTALL_USER - /tmp/pivpnUSR renamed to INSTALL_USER ### Merge Patch, Sept 2nd 2019 * Bitwarden integration: - - Bitwarden Installation removed from script, users that whish to use it should install it manually. + - Bitwarden Installation removed from script, users that whish to use it should install it manually. - bugfixes with pivpn add - pivpn add -b will fail if bitwarden is not found diff --git a/auto_install/install.sh b/auto_install/install.sh index 2a42226..c37a30c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -62,7 +62,7 @@ c=$(( c < 70 ? 70 : c )) # Find IP used to route to outside world IPv4addr=$(ip route get 192.0.2.1 | awk '{print $7}') IPv4gw=$(ip route get 192.0.2.1 | awk '{print $3}') -availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) +availableInterfaces=$(ip -o link | awk '/state UP/ {print $2}' | cut -d':' -f1 | cut -d'@' -f1) ######## SCRIPT ############ @@ -128,6 +128,7 @@ main(){ $SUDO /opt/pivpn/update.sh "$@" exit 0 elif [ "$UpdateCmd" = "Repair" ]; then + # shellcheck disable=SC1090 source "$setupVars" runUnattended=true fi @@ -206,6 +207,8 @@ main(){ echo ":::" } +####### FUNCTIONS ########## + askAboutExistingInstall(){ opt1a="Update" opt1b="Get the latest PiVPN scripts" @@ -225,40 +228,9 @@ askAboutExistingInstall(){ echo "::: ${opt1a} option selected." } -# Next see if we are on a tested and supported OS -noOSSupport(){ - if [ "${runUnattended}" = 'true' ]; then - echo "::: Invalid OS detected" - echo "::: We have not been able to detect a supported OS." - echo "::: Currently this installer supports Raspbian (Buster), Debian (Buster) and Ubuntu (Bionic)." - exit 1 - fi - whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS. -Currently this installer supports Raspbian (Buster), Debian (Buster) and Ubuntu (Bionic). -If you think you received this message in error, you can post an issue on the GitHub at https://github.com/pivpn/pivpn/issues." ${r} ${c} - exit 1 -} - -maybeOSSupport(){ - if [ "${runUnattended}" = 'true' ]; then - echo "::: OS Not Supported" - echo "::: You are on an OS that we have not tested but MAY work, continuing anyway..." - return - fi - - if (whiptail --backtitle "OS Not Supported" --title "OS Not Supported" --yesno "You are on an OS that we have not tested but MAY work. -Currently this installer supports Raspbian (Buster). -Would you like to continue anyway?" ${r} ${c}) then - echo "::: Did not detect perfectly supported OS but," - echo "::: Continuing installation at user's own risk..." - else - echo "::: Exiting due to unsupported OS" - exit 1 - fi -} - -# Compatibility +# Compatibility, functions to check for supported OS +# distroCheck, maybeOSSupport, noOSSupport distroCheck(){ # if lsb_release command is on their system if hash lsb_release 2>/dev/null; then @@ -278,13 +250,15 @@ distroCheck(){ case ${PLAT} in Debian|Raspbian|Ubuntu) - case ${OSCN} in - buster|bionic) - ;; - *) - maybeOSSupport - ;; - esac + case ${OSCN} in + buster|bionic) + # shellcheck disable=SC2104 + break + ;; + *) + maybeOSSupport + ;; + esac ;; *) noOSSupport @@ -299,6 +273,40 @@ distroCheck(){ echo "OSCN=${OSCN}" >> /tmp/setupVars.conf } +noOSSupport(){ + if [ "${runUnattended}" = 'true' ]; then + echo "::: Invalid OS detected" + echo "::: We have not been able to detect a supported OS." + echo "::: Currently this installer supports Raspbian, Debian and Ubuntu." + exit 1 + fi + + whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS. +Currently this installer supports Raspbian, Debian and Ubuntu. +For more details, check our documentation at https://github.com/pivpn/pivpn/wiki " ${r} ${c} + exit 1 +} + +maybeOSSupport(){ + if [ "${runUnattended}" = 'true' ]; then + echo "::: OS Not Supported" + echo "::: You are on an OS that we have not tested but MAY work, continuing anyway..." + return + fi + + if (whiptail --backtitle "Untested OS" --title "Untested OS" --yesno "You are on an OS that we have not tested but MAY work. +Currently this installer supports Raspbian, Debian and Ubuntu. +For more details about supported OS please check our documentation at https://github.com/pivpn/pivpn/wiki +Would you like to continue anyway?" ${r} ${c}) then + echo "::: Did not detect perfectly supported OS but," + echo "::: Continuing installation at user's own risk..." + else + echo "::: Exiting due to untested OS" + exit 1 + fi +} + + checkHostname(){ ###Checks for hostname size host_name=$(hostname -s) @@ -322,7 +330,6 @@ checkHostname(){ fi } -####### FUNCTIONS ########## spinner(){ local pid=$1 local delay=0.50 @@ -415,9 +422,9 @@ notifyPackageUpdatesAvailable(){ preconfigurePackages(){ # Add support for https repositories if there are any that use it otherwise the installation will silently fail if [[ -f /etc/apt/sources.list ]]; then - if grep -q https /etc/apt/sources.list; then - BASE_DEPS+=("apt-transport-https") - fi + if grep -q https /etc/apt/sources.list; then + BASE_DEPS+=("apt-transport-https") + fi fi if [[ ${OSCN} == "buster" ]]; then @@ -425,7 +432,8 @@ preconfigurePackages(){ $SUDO update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy fi - # if ufw is enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example) + # if ufw is enabled, configure that. + # running as root because sometimes the executable is not in the user's $PATH if $SUDO bash -c 'hash ufw' 2>/dev/null; then if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive; then USING_UFW=0 @@ -485,67 +493,70 @@ In the next section, you can choose to use your current network settings (DHCP) } chooseInterface(){ - if [ "${runUnattended}" = 'true' ]; then - if [ -z "$IPv4dev" ]; then - if [ "$(echo "${availableInterfaces}" | wc -l)" -eq 1 ]; then - IPv4dev="${availableInterfaces}" - echo "::: No interface specified, but only ${IPv4dev} is available, using it" - else - echo "::: No interface specified" - exit 1 - fi - else - if ip -o link | grep -qw "${IPv4dev}"; then - echo "::: Using interface: ${IPv4dev}" - else - echo "::: Interface ${IPv4dev} does not exist" - exit 1 - fi - fi - echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf - return - fi +# Turn the available interfaces into an array so it can be used with a whiptail dialog +local interfacesArray=() +# Number of available interfaces +local interfaceCount +# Whiptail variable storage +local chooseInterfaceCmd +# Temporary Whiptail options storage +local chooseInterfaceOptions +# Loop sentinel variable +local firstloop=1 - # Turn the available interfaces into an array so it can be used with a whiptail dialog - local interfacesArray=() - # Number of available interfaces - local interfaceCount - # Whiptail variable storage - local chooseInterfaceCmd - # Temporary Whiptail options storage - local chooseInterfaceOptions - # Loop sentinel variable - local firstloop=1 +if [ -z "$availableInterfaces" ]; then + echo "::: Could not find any active network interface, exiting" + exit 1 +else + while read -r line; do + mode="OFF" + if [[ ${firstloop} -eq 1 ]]; then + firstloop=0 + mode="ON" + fi + interfacesArray+=("${line}" "available" "${mode}") + ((interfaceCount++)) + done <<< "${availableInterfaces}" +fi - if [[ $(echo "${availableInterfaces}" | wc -l) -eq 1 ]]; then - IPv4dev="${availableInterfaces}" - echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf - return - fi +if [ "${runUnattended}" = 'true' ]; then + if [ -z "$IPv4dev" ]; then + if [ $interfaceCount -eq 1 ]; then + IPv4dev="${availableInterfaces}" + echo "::: No interface specified, but only ${IPv4dev} is available, using it" + else + echo "::: No interface specified and failed to determine one" + exit 1 + fi + else + if ip -o link | grep -qw "${IPv4dev}"; then + echo "::: Using interface: ${IPv4dev}" + else + echo "::: Interface ${IPv4dev} does not exist" + exit 1 + fi + fi + echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + return +else + if [ "$interfaceCount" -eq 1 ]; then + IPv4dev="${availableInterfaces}" + echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + return + fi +fi - while read -r line; do - mode="OFF" - if [[ ${firstloop} -eq 1 ]]; then - firstloop=0 - mode="ON" - fi - interfacesArray+=("${line}" "available" "${mode}") - done <<< "${availableInterfaces}" - - # Find out how many interfaces are available to choose from - interfaceCount=$(echo "${availableInterfaces}" | wc -l) - chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An - Interface (press space to select):" "${r}" "${c}" "${interfaceCount}") - if chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) ; then - for desiredInterface in ${chooseInterfaceOptions}; do - IPv4dev=${desiredInterface} - echo "::: Using interface: $IPv4dev" - echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf - done - else - echo "::: Cancel selected, exiting...." - exit 1 - fi +chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An interface (press space to select):" "${r}" "${c}" "${interfaceCount}") +if chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) ; then + for desiredInterface in ${chooseInterfaceOptions}; do + IPv4dev=${desiredInterface} + echo "::: Using interface: $IPv4dev" + echo "IPv4dev=${IPv4dev}" >> /tmp/setupVars.conf + done +else + echo "::: Cancel selected, exiting...." + exit 1 +fi } avoidStaticIPv4Ubuntu() { @@ -1848,7 +1859,7 @@ confUnattendedUpgrades(){ installScripts(){ # Install the scripts from /etc/.pivpn to their various locations echo ":::" - echo -n "::: Installing scripts to /opt/pivpn..." + echo -n -e "::: Installing scripts to /opt/pivpn...\n" if [ ! -d /opt/pivpn ]; then $SUDO mkdir /opt/pivpn $SUDO chown root:root /opt/pivpn From 800fd91353a18fd17d4113e38a4835691fd1962e Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 6 Jan 2020 11:53:29 +0100 Subject: [PATCH 59/79] Use radiolist to select a VPN --- auto_install/install.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index c37a30c..7a77fbc 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -225,7 +225,7 @@ askAboutExistingInstall(){ "${opt3a}" "${opt3b}" 3>&2 2>&1 1>&3) || \ { echo "::: Cancel selected. Exiting"; exit 1; } - echo "::: ${opt1a} option selected." + echo "::: ${UpdateCmd} option selected." } @@ -252,8 +252,7 @@ distroCheck(){ Debian|Raspbian|Ubuntu) case ${OSCN} in buster|bionic) - # shellcheck disable=SC2104 - break + : ;; *) maybeOSSupport @@ -883,11 +882,16 @@ askWhichVPN(){ fi fi else - if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choice expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); - then - VPN="wireguard" + chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choice expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose a VPN (press space to select):" "${r}" "${c}" 2) + VPNChooseOptions=(WireGuard "" on + OpenVPN "" off) + + if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then + echo "::: Using VPN: $VPN" + VPN="${VPN,,}" else - VPN="openvpn" + echo "::: Cancel selected, exiting...." + exit 1 fi fi From b9f237fe92bdf08847d24f26cc2aedd6e0802b91 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Tue, 7 Jan 2020 01:30:17 +0100 Subject: [PATCH 60/79] Changes for FR #897 Support For DHCP IP Reservation Main: - added If statement to skipp SetStaticIPv4 if dhcpRserv=1 getStaticIPv4Settings: - Added Whiptail asking if user wants to use DHCP reservation Settings, this will add dhcpReserv and skip setStaticIPv4 while still logging everything. ConfigExample files: - Added staticReserv=0 to config examples. so it can be used with Unattended install * 0 means static ip will be setup. * 1 means DHCP Reservation will be used and no chage will be made to the interfaces --- LatestUpdate.md | 23 +++++++- auto_install/install.sh | 95 +++++++++++++++++++------------ unattended_openvpn_example.conf | 1 + unattended_wireguard_example.conf | 1 + 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/LatestUpdate.md b/LatestUpdate.md index c96709f..2134a6f 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -5,7 +5,26 @@ patch release notes. Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged. -##Jan 6th 2020 +## Jan 7th 2020 + +Changes for FR #897 +Support For DHCP IP Reservation + +Main: + - added If statement to skipp SetStaticIPv4 if dhcpRserv=1 + +getStaticIPv4Settings: + - Added Whiptail asking if user wants to use DHCP reservation Settings, this will add dhcpReserv and + skip setStaticIPv4 while still logging everything. +ConfigExample files: + - Added staticReserv=0 to config examples. so it can be used with Unattended install + * 0 means static ip will be setup. + * 1 means DHCP Reservation will be used and no chage will be made to the interfaces + + +Updated LatestChanges + +## Jan 6th 2020 * Removed Unecessary pipe on availableInterfaces * Changed OS Support messages accross the script @@ -36,7 +55,7 @@ Everytime Test branch is merged into master, a new entry should be created with - the script now checks for hostname length right at the beginning and prompts for a new one. - HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only. * fixed ubuntu 18.04 being detected as not supported OS, now fully supported and tested. -* changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all *.sh files making it easier to manage when adding new scripts/features +* changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all `*.sh` files making it easier to manage when adding new scripts/features * Changed how supported OS are presented when maybeOS_Support() is called. ## Sept 1st 2019 diff --git a/auto_install/install.sh b/auto_install/install.sh index c37a30c..14bff99 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -166,7 +166,9 @@ main(){ avoidStaticIPv4Ubuntu else getStaticIPv4Settings - setStaticIPv4 + if [ $dhcpReserv -ne 1 ] || [ -z $dhcpReserv ]; then + setStaticIPv4 + fi fi # Choose the user for the ovpns @@ -636,56 +638,75 @@ getStaticIPv4Settings() { fi local ipSettingsCorrect - # Ask if the user wants to use DHCP settings as their static IP - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? + # Some users reserve IP addresses on another DHCP Server or on their routers, + # Lets ask them if they want to make any changes to their interfaces. + if (whiptail --backtitle "Calibrating network interface" --title "DHCP Reservation" --yesno \ + "Are you Using DHCP Reservation on your Router/DHCP Server? +These are your current Network Settings: + + IP address: ${IPv4addr} + Gateway: ${IPv4gw} + +Yes: Keep using DHCP reservation +No: Setup static IP address +Don't know what DHCP Reservation is? Answer No." ${r} ${c}); then + dhcpReserv=1 + echo "dhcpReserv=${dhcpReserv}" >> /tmp/setupVars.conf + echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + else + # Ask if the user wants to use DHCP settings as their static IP + if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? IP address: ${IPv4addr} Gateway: ${IPv4gw}" ${r} ${c}); then - echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf - echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf - # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. - whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. + echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. + whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." ${r} ${c} # Nothing else to do since the variables are already set above - else + else # Otherwise, we need to ask the user to input their desired settings. # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) # Start a loop to let the user enter their information with the chance to go back and edit it if necessary - until [[ ${ipSettingsCorrect} = True ]]; do + until [[ ${ipSettingsCorrect} = True ]]; do # Ask for the IPv4 address - if IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4addr}" 3>&1 1>&2 2>&3) ; then - echo "::: Your static IPv4 address: ${IPv4addr}" - # Ask for the gateway - if IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) ; then - echo "::: Your static IPv4 gateway: ${IPv4gw}" - # Give the user a chance to review their settings before moving on - if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? - IP address: ${IPv4addr} - Gateway: ${IPv4gw}" ${r} ${c}); then - # If the settings are correct, then we need to set the pivpnIP - echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf - echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf - # After that's done, the loop ends and we move on - ipSettingsCorrect=True + if IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4addr}" 3>&1 1>&2 2>&3) ; then + echo "::: Your static IPv4 address: ${IPv4addr}" + # Ask for the gateway + if IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) ; then + echo "::: Your static IPv4 gateway: ${IPv4gw}" + # Give the user a chance to review their settings before moving on + if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? + IP address: ${IPv4addr} + Gateway: ${IPv4gw}" ${r} ${c}); then + # If the settings are correct, then we need to set the pivpnIP + echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf + echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf + # After that's done, the loop ends and we move on + ipSettingsCorrect=True + else + # If the settings are wrong, the loop continues + ipSettingsCorrect=False + fi + else + # Cancelling gateway settings window + ipSettingsCorrect=False + echo "::: Cancel selected. Exiting..." + exit 1 + fi else - # If the settings are wrong, the loop continues + # Cancelling IPv4 settings window ipSettingsCorrect=False + echo "::: Cancel selected. Exiting..." + exit 1 fi - else - # Cancelling gateway settings window - ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 - fi - else - # Cancelling IPv4 settings window - ipSettingsCorrect=False - echo "::: Cancel selected. Exiting..." - exit 1 + done + # End the if statement for DHCP vs. static fi - done - # End the if statement for DHCP vs. static + # End of If Statement for DCHCP Reservation fi } diff --git a/unattended_openvpn_example.conf b/unattended_openvpn_example.conf index 2885d65..92a6e40 100644 --- a/unattended_openvpn_example.conf +++ b/unattended_openvpn_example.conf @@ -1,4 +1,5 @@ IPv4dev=eth0 +staticReserv=0 install_user=pi VPN=openvpn pivpnPROTO=udp diff --git a/unattended_wireguard_example.conf b/unattended_wireguard_example.conf index 4ed1752..8040e0e 100644 --- a/unattended_wireguard_example.conf +++ b/unattended_wireguard_example.conf @@ -1,4 +1,5 @@ IPv4dev=eth0 +staticReserv=0 install_user=pi VPN=wireguard pivpnPORT=51820 From 1d0c66a9701fd82ef6d2e262bfca8c3a112a34a9 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 6 Jan 2020 11:53:29 +0100 Subject: [PATCH 61/79] Use radiolist to select a VPN --- auto_install/install.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 14bff99..9ed4bc0 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -227,7 +227,7 @@ askAboutExistingInstall(){ "${opt3a}" "${opt3b}" 3>&2 2>&1 1>&3) || \ { echo "::: Cancel selected. Exiting"; exit 1; } - echo "::: ${opt1a} option selected." + echo "::: ${UpdateCmd} option selected." } @@ -254,8 +254,7 @@ distroCheck(){ Debian|Raspbian|Ubuntu) case ${OSCN} in buster|bionic) - # shellcheck disable=SC2104 - break + : ;; *) maybeOSSupport @@ -904,11 +903,16 @@ askWhichVPN(){ fi fi else - if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choice expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c}); - then - VPN="wireguard" + chooseVPNCmd=(whiptail --backtitle "Setup PiVPN" --title "Installation mode" --separate-output --radiolist "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choice expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose a VPN (press space to select):" "${r}" "${c}" 2) + VPNChooseOptions=(WireGuard "" on + OpenVPN "" off) + + if VPN=$("${chooseVPNCmd[@]}" "${VPNChooseOptions[@]}" 2>&1 >/dev/tty) ; then + echo "::: Using VPN: $VPN" + VPN="${VPN,,}" else - VPN="openvpn" + echo "::: Cancel selected, exiting...." + exit 1 fi fi From e6fdfd29b7e1d93157e027b41debcccc97839daf Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Tue, 7 Jan 2020 20:27:19 +0100 Subject: [PATCH 62/79] Code review, Cleanup. Moved installPiVPN up, to better match the order when it is called. Added Some cuotes to make shellcheck happy. Added exit codes and error messages in case cd fails to not exit silently. --- auto_install/install.sh | 61 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 9ed4bc0..9b00593 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -886,6 +886,32 @@ cloneOrUpdateRepos(){ } } +installPiVPN(){ + $SUDO mkdir -p /etc/pivpn/ + askWhichVPN + + if [ "$VPN" = "openvpn" ]; then + installOpenVPN + askCustomProto + askCustomPort + askClientDNS + askCustomDomain + askPublicIPOrDNS + askEncryption + confOpenVPN + confOVPN + confNetwork + confLogging + elif [ "$VPN" = "wireguard" ]; then + installWireGuard + askCustomPort + askClientDNS + askPublicIPOrDNS + confWireGuard + confNetwork + fi +} + askWhichVPN(){ if [ "${runUnattended}" = 'true' ]; then if [ -z "$VPN" ]; then @@ -979,7 +1005,10 @@ installWireGuard(){ wget -qO- "${WG_TOOLS_SOURCE}" | $SUDO tar Jxf - --directory /usr/src echo "done!" - cd /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}/src" + ## || exits if cd fails. + cd /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}/src" || \ + echo "::: Installation Failed could not cd into /usr/src/wireguard-tools"; \ + exit 1 # We install the userspace tools manually since DKMS only compiles and # installs the kernel module @@ -1226,7 +1255,7 @@ askClientDNS(){ for your VPN Clients (press space to select). To use your own, select Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select \"PiVPN-is-local-DNS\" and make sure your resolver is listening on - \"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6) + \"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." "${r}" "${c}" 6) DNSChooseOptions=(Quad9 "" on OpenDNS "" off Level3 "" off @@ -1500,7 +1529,8 @@ confOpenVPN(){ $SUDO mkdir /etc/openvpn/easy-rsa/pki $SUDO chmod 700 /etc/openvpn/easy-rsa/pki - cd /etc/openvpn/easy-rsa || exit + cd /etc/openvpn/easy-rsa || \ + echo "::: Error, Could not cd /etc/openvpn/easy-rsa"; exit 1 # Write out new vars file echo "if [ -z \"\$EASYRSA_CALLER\" ]; then @@ -1770,31 +1800,6 @@ if \$programname == 'ovpn-server' then stop" | $SUDO tee /etc/rsyslog.d/30-openv esac } -installPiVPN(){ - $SUDO mkdir -p /etc/pivpn/ - askWhichVPN - - if [ "$VPN" = "openvpn" ]; then - installOpenVPN - askCustomProto - askCustomPort - askClientDNS - askCustomDomain - askPublicIPOrDNS - askEncryption - confOpenVPN - confOVPN - confNetwork - confLogging - elif [ "$VPN" = "wireguard" ]; then - installWireGuard - askCustomPort - askClientDNS - askPublicIPOrDNS - confWireGuard - confNetwork - fi -} restartServices(){ echo "::: Restarting services..." From 92381fc2a6f8be2591057d252571fe4398102f6e Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Wed, 8 Jan 2020 02:12:13 +0100 Subject: [PATCH 63/79] Removed echos Removed echos i have introduced before exits, for the *dumb* obvious reasons were causing script to exit. --- auto_install/install.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 9b00593..a12b2d0 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1006,9 +1006,7 @@ installWireGuard(){ echo "done!" ## || exits if cd fails. - cd /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}/src" || \ - echo "::: Installation Failed could not cd into /usr/src/wireguard-tools"; \ - exit 1 + cd /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}/src" || exit 1 # We install the userspace tools manually since DKMS only compiles and # installs the kernel module @@ -1529,8 +1527,7 @@ confOpenVPN(){ $SUDO mkdir /etc/openvpn/easy-rsa/pki $SUDO chmod 700 /etc/openvpn/easy-rsa/pki - cd /etc/openvpn/easy-rsa || \ - echo "::: Error, Could not cd /etc/openvpn/easy-rsa"; exit 1 + cd /etc/openvpn/easy-rsa || exit 1 # Write out new vars file echo "if [ -z \"\$EASYRSA_CALLER\" ]; then From 412c8e83ac94ff47cb532495deba3638d7645ae0 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Wed, 8 Jan 2020 13:16:01 +0100 Subject: [PATCH 64/79] Issue #607 InstallScripts function: Added -p flag on mkdir, this fixes script silently exiting if /opt does not exist (Issue #607) --- auto_install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index a12b2d0..b1f441c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1888,7 +1888,7 @@ installScripts(){ echo ":::" echo -n -e "::: Installing scripts to /opt/pivpn...\n" if [ ! -d /opt/pivpn ]; then - $SUDO mkdir /opt/pivpn + $SUDO mkdir -p /opt/pivpn $SUDO chown root:root /opt/pivpn $SUDO chmod 0755 /opt/pivpn fi From 8096af7ad02ab33a626614205c40acf2538ed607 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Wed, 8 Jan 2020 19:37:46 +0100 Subject: [PATCH 65/79] Updates and improvements install.sh installScripts function: update script not being copied over to /opt therefore update funcion was probably broken. changed script to copy all .sh scripts from .pivpn/scripts directory. Issue #871: fix backup script I was probably very drunk when i first wrote this backup script. fixed it, now works with new code refactoring, loads vars from setupVars Added backup for wireguard Moved script to global pivpnscripts. Added backup script to bash-completion Added backup script to pivpn script update.sh Commented the update from master branch to avoid users trying to update test from master. Updated LatestChages.md --- scripts/backup.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/backup.sh diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100755 index 0000000..a8e6a1d --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# shellcheck disable=SC1091 +source /etc/pivpn/setupVars.conf +# shellcheck disable=SC1090 +backupdir=pivpnbackup +date=$(date +%Y%m%d-%H%M%S) + +checkbackupdir(){ + + if [[ ! -d $install_home/$backupdir ]]; then + mkdir -p "$install_home"/"$backupdir" + fi + +} + +backup_openvpn(){ + + openvpndir=/etc/openvpn + ovpnsdir=${install_home}/ovpns + checkbackupdir + backupzip=$date-pivpnovpnbackup.tgz + # shellcheck disable=SC2210 + tar czpf "$install_home"/"$backupdir"/"$backupzip" "$openvpndir" "$ovpnsdir" > /dev/null 2>&1 + echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" + +} + +backup_wireguard(){ + + wireguarddir=/etc/wireguard + configsdir=${install_home}/configs + checkbackupdir + backupzip=$date-pivpnwgbackup.tgz + tar czpf "$install_home"/"$backupdir"/"$backupzip" "$wireguarddir" "$configsdir" > /dev/null 2>&1 + echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" + +} + +if [[ ! $EUID -eq 0 ]];then + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 0 + fi +fi + +if [[ "${VPN}" == "wireguard" ]]; then + backup_wireguard +else + backup_openvpn +fi From dd6bb069f05559fb626ee9b1bb398df07ff45206 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Wed, 8 Jan 2020 19:38:38 +0100 Subject: [PATCH 66/79] Updates and improvements install.sh installScripts function: update script not being copied over to /opt therefore update funcion was probably broken. changed script to copy all .sh scripts from .pivpn/scripts directory. Issue #871: fix backup script I was probably very drunk when i first wrote this backup script. fixed it, now works with new code refactoring, loads vars from setupVars Added backup for wireguard Moved script to global pivpnscripts. Added backup script to bash-completion Added backup script to pivpn script update.sh Commented the update from master branch to avoid users trying to update test from master. Updated LatestChages.md --- LatestUpdate.md | 25 +++++++++++++++++++++ auto_install/install.sh | 2 +- scripts/openvpn/backup.sh | 36 ------------------------------- scripts/update.sh | 16 ++++++++++---- scripts/wireguard/bash-completion | 4 ++-- scripts/wireguard/pivpn | 6 ++++++ 6 files changed, 46 insertions(+), 43 deletions(-) delete mode 100755 scripts/openvpn/backup.sh diff --git a/LatestUpdate.md b/LatestUpdate.md index 2134a6f..77d9513 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -5,6 +5,31 @@ patch release notes. Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged. +## Jan 8th 2020 + +Updates and improvements +Issue #871: fix backup script + +install.sh + installScripts function: + update script not being copied over to /opt therefore update funcion was probably broken. + changed script to copy all .sh scripts from .pivpn/scripts directory. + +Issue #871: fix backup script + I was probably very drunk when i first wrote this backup script. + fixed it, now works with new code refactoring, + loads vars from setupVars + Added backup for wireguard + Moved script to global pivpnscripts. + Added backup script to bash-completion + Added backup script to pivpn script + +update.sh + Commented the update from master branch to avoid users trying to update test from master. + + +Updated LatestChages.md + ## Jan 7th 2020 Changes for FR #897 diff --git a/auto_install/install.sh b/auto_install/install.sh index b1f441c..f1267e7 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1893,7 +1893,7 @@ installScripts(){ $SUDO chmod 0755 /opt/pivpn fi - $SUDO cp /etc/.pivpn/scripts/uninstall.sh /opt/pivpn/ + $SUDO cp /etc/.pivpn/scripts/*.sh /opt/pivpn/ $SUDO cp /etc/.pivpn/scripts/$VPN/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh $SUDO cp /etc/.pivpn/scripts/$VPN/pivpn /usr/local/bin/pivpn diff --git a/scripts/openvpn/backup.sh b/scripts/openvpn/backup.sh deleted file mode 100755 index 2bed93c..0000000 --- a/scripts/openvpn/backup.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -setupVars="/etc/pivpn/setupVars.conf" -backupdir=pivpnbackup -openvpndir=/etc/openvpn -ovpnsdir=${install_home}/ovpns -date=$(date +%Y-%m-%d-%H%M%S) - -if [ ! -f "${setupVars}" ]; then - echo "::: Missing setup vars file!" - exit 1 -fi - -source "${setupVars}" - -backup_openvpn(){ - if [[ ! -d $install_home/$backupdir ]]; then - mkdir $install_home/$backupdir - fi - cp -r $openvpndir $ovpnsdir $backupdir 2&>1 - backupzip=$date-pivpnbackup.tgz - tar -czf $backupzip -C ${install_home} $backupdir 2&>1 - echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance" -} - - -if [[ ! $EUID -eq 0 ]];then - if [[ $(dpkg-query -s sudo) ]];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 0 - fi -fi - -backup_openvpn - diff --git a/scripts/update.sh b/scripts/update.sh index 3f63c2a..fd20052 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -50,9 +50,18 @@ updatefromtest(){ ##Clone and copy pivpn scripts to /opt/pivpn cloneandupdate(){ - git clone "$pivpnrepo" "$pivpnlocalpath" - cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" - cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir" + ##This is to be removed after merge. + ##Alert for users trying to update from master. + if [ $VPN == "wireguard" ]; then + echo "ERROR: You have installed pivpn from test branch." + echo "Wireguard not yet available on master, please use -t flag" + exit 1 + fi + ## Remove Above and uncomment below when test is moved to master +# git clone "$pivpnrepo" "$pivpnlocalpath" +# cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" +# cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts" +# cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir" } ##same as cloneandupdate() but from test branch @@ -97,4 +106,3 @@ else esac done fi - diff --git a/scripts/wireguard/bash-completion b/scripts/wireguard/bash-completion index ff434c3..a971696 100644 --- a/scripts/wireguard/bash-completion +++ b/scripts/wireguard/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -qr -r -h -u -up" - opts="add clients debug list qrcode remove help uninstall update" + dashopts="-a -c -d -l -qr -r -h -u -up -bk" + opts="add clients debug list qrcode remove help uninstall update backup" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then diff --git a/scripts/wireguard/pivpn b/scripts/wireguard/pivpn index f3a14c9..4400a3f 100755 --- a/scripts/wireguard/pivpn +++ b/scripts/wireguard/pivpn @@ -54,6 +54,10 @@ updateScripts(){ exit 0 } +backup(){ + $SUDO /opt/pivpn/backup.sh +} + showHelp(){ echo "::: Control all PiVPN specific functions!" echo ":::" @@ -69,6 +73,7 @@ showHelp(){ echo "::: -h, help Show this help dialog" echo "::: -u, uninstall Uninstall pivpn from your system!" echo "::: -up, update Updates PiVPN Scripts" + echo "::: -bk, Backup Backup vpn configs and user profiles" exit 0 } @@ -87,5 +92,6 @@ case "$1" in "-h" | "help" ) showHelp;; "-u" | "uninstall" ) uninstallServer;; "-up" | "update" ) updateScripts "$@" ;; +"-bk" | "backup" ) backup ;; * ) showHelp;; esac From 0c79cc9e428a382be8813e62e8a6aef49c2629e7 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Wed, 8 Jan 2020 19:56:40 +0100 Subject: [PATCH 67/79] Missing backup on bash-completion Added backup option on openvpn bash-completion --- scripts/openvpn/bash-completion | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/openvpn/bash-completion b/scripts/openvpn/bash-completion index f317bc4..1b9ef7e 100644 --- a/scripts/openvpn/bash-completion +++ b/scripts/openvpn/bash-completion @@ -4,8 +4,8 @@ _pivpn() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - dashopts="-a -c -d -l -r -h -u -up" - opts="debug add clients list revoke uninstall help update" + dashopts="-a -c -d -l -r -h -u -up -bk" + opts="debug add clients list revoke uninstall help update backup" if [ "${#COMP_WORDS[@]}" -eq 2 ] then if [[ ${cur} == -* ]] ; then From 047eccc19da23cd7e2b8f1bb2e2519a64fb11897 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Wed, 8 Jan 2020 20:02:34 +0100 Subject: [PATCH 68/79] Update script: Removed IF statement Removed if statement from update script, was making no sense to have it there. --- scripts/update.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index fd20052..9481c4a 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -52,11 +52,9 @@ updatefromtest(){ cloneandupdate(){ ##This is to be removed after merge. ##Alert for users trying to update from master. - if [ $VPN == "wireguard" ]; then echo "ERROR: You have installed pivpn from test branch." echo "Wireguard not yet available on master, please use -t flag" exit 1 - fi ## Remove Above and uncomment below when test is moved to master # git clone "$pivpnrepo" "$pivpnlocalpath" # cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts" From e2eea482d0bacb8ef2fe43d8341fd4c198cf958e Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Thu, 9 Jan 2020 00:22:15 +0100 Subject: [PATCH 69/79] Replace /etc/.pivpn/ with $pivpnFilesDir /etc/.pivpn/ is refferenced multiple times trough the script, Replaced all of them with $pivpnFilesDir Quoted some unquoted vars --- auto_install/install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index f1267e7..4a0a74b 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1578,7 +1578,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null ${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem # Write config file for server using the template.txt file - $SUDO cp /etc/.pivpn/server_config.txt /etc/openvpn/server.conf + $SUDO cp $pivpnFilesDir/server_config.txt /etc/openvpn/server.conf # Apply client DNS settings ${SUDOE} sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${pivpnDNS1}'\"/' /etc/openvpn/server.conf @@ -1612,7 +1612,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null } confOVPN(){ - $SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt + $SUDO cp $pivpnFilesDir/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt $SUDO sed -i 's/IPv4pub/'"$pivpnHOST"'/' /etc/openvpn/easy-rsa/pki/Default.txt @@ -1893,12 +1893,12 @@ installScripts(){ $SUDO chmod 0755 /opt/pivpn fi - $SUDO cp /etc/.pivpn/scripts/*.sh /opt/pivpn/ - $SUDO cp /etc/.pivpn/scripts/$VPN/*.sh /opt/pivpn/ + $SUDO cp $pivpnFilesDir/scripts/*.sh /opt/pivpn/ + $SUDO cp $pivpnFilesDir/scripts/$VPN/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh - $SUDO cp /etc/.pivpn/scripts/$VPN/pivpn /usr/local/bin/pivpn + $SUDO cp $pivpnFilesDir/scripts/$VPN/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn - $SUDO cp /etc/.pivpn/scripts/$VPN/bash-completion /etc/bash_completion.d/pivpn + $SUDO cp $pivpnFilesDir/scripts/$VPN/bash-completion /etc/bash_completion.d/pivpn $SUDO chmod 0644 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 . /etc/bash_completion.d/pivpn From e0d45db7629d4dc5535d53143a435508d437ada4 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Thu, 9 Jan 2020 00:45:04 +0100 Subject: [PATCH 70/79] Variable Quoting Quoted variables, Added shellcheck disables. --- auto_install/install.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 4a0a74b..c6c1004 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -166,7 +166,7 @@ main(){ avoidStaticIPv4Ubuntu else getStaticIPv4Settings - if [ $dhcpReserv -ne 1 ] || [ -z $dhcpReserv ]; then + if [ "$dhcpReserv" -ne 1 ] || [ -z "$dhcpReserv" ]; then setStaticIPv4 fi fi @@ -398,6 +398,7 @@ updatePackageCache(){ #update package lists echo ":::" echo -ne "::: ${PKG_MANAGER} update has not been run today. Running now...\\n" + # shellcheck disable=SC2086 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null echo " done!" fi @@ -470,6 +471,7 @@ installDependentPackages(){ done if command -v debconf-apt-progress &> /dev/null; then + # shellcheck disable=SC2086 $SUDO debconf-apt-progress -- ${PKG_INSTALL} "${argArray1[@]}" else ${PKG_INSTALL} "${argArray1[@]}" @@ -650,6 +652,7 @@ Yes: Keep using DHCP reservation No: Setup static IP address Don't know what DHCP Reservation is? Answer No." ${r} ${c}); then dhcpReserv=1 + # shellcheck disable=SC2129 echo "dhcpReserv=${dhcpReserv}" >> /tmp/setupVars.conf echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf @@ -985,6 +988,7 @@ installWireGuard(){ printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 + # shellcheck disable=SC2086 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(raspberrypi-kernel-headers wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] @@ -1085,6 +1089,7 @@ installWireGuard(){ echo "::: Adding Debian repository... " echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + # shellcheck disable=SC2086 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) installDependentPackages PIVPN_DEPS[@] @@ -1893,12 +1898,12 @@ installScripts(){ $SUDO chmod 0755 /opt/pivpn fi - $SUDO cp $pivpnFilesDir/scripts/*.sh /opt/pivpn/ - $SUDO cp $pivpnFilesDir/scripts/$VPN/*.sh /opt/pivpn/ + $SUDO cp "$pivpnFilesDir"/scripts/*.sh /opt/pivpn/ + $SUDO cp "$pivpnFilesDir"/scripts/"$VPN"/*.sh /opt/pivpn/ $SUDO chmod 0755 /opt/pivpn/*.sh - $SUDO cp $pivpnFilesDir/scripts/$VPN/pivpn /usr/local/bin/pivpn + $SUDO cp "$pivpnFilesDir"/scripts/"$VPN"/pivpn /usr/local/bin/pivpn $SUDO chmod 0755 /usr/local/bin/pivpn - $SUDO cp $pivpnFilesDir/scripts/$VPN/bash-completion /etc/bash_completion.d/pivpn + $SUDO cp "$pivpnFilesDir"/scripts/"$VPN"/bash-completion /etc/bash_completion.d/pivpn $SUDO chmod 0644 /etc/bash_completion.d/pivpn # shellcheck disable=SC1091 . /etc/bash_completion.d/pivpn From e08903fa8a11948b7375395144abd7b374da1cd1 Mon Sep 17 00:00:00 2001 From: Orazio Date: Wed, 15 Jan 2020 14:45:29 +0100 Subject: [PATCH 71/79] Update LatestUpdate.md --- LatestUpdate.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/LatestUpdate.md b/LatestUpdate.md index 77d9513..2d8a942 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -68,7 +68,100 @@ Updated LatestChanges - Fixed Issue #906 - Added exit code if no interfaces are found * Updated LatestUpdate.md +* Use radiolist to select a VPN +## Jan 3rd 2020 + +- Revise route query for IP & GW selection from Quad9 to TEST-NET-1 +- Replace mention of 'Google' with 'Quad9' + +## Jan 2nd 2020 + +- Fix mv command when copying the DH parameters to final destination + +## Dec 30th 2019 + +- Fix paths inside the update script +- Use the wireguard script for WireGuard as well +- Updated the README in accordance to changes in the test branch + +## Dec 29th 2019 + +* Handle running the install script over an existing installation (as the script already did before branching to test-wireguard), providing: + - Update, downloads latest scripts from git repo + - Repair, reinstall PiVPN while keeping existing settings + - Reconfigure, start over overwriting the existing settings +* Tag iptables rules as an attempt to make sure that the uninstall script only removes PiVPN rules +* Change the armv6l installation to reflect the split of WireGuard snapshots into wireguard-linux-compat and wireguard-tools + +## Dec 27th 2019 + + - When suggesting to use Pi-hole, use the VPN server IP instead of the LAN IP to allow DNS resolution even if the user does not route the local network through the tunnel. +- Format listCONF in a similar way as listOVPN +- Specifically look for a free octet in the last word of clients.txt and not just any word. + Necessary otherwhise public keys starting with a number will match against an octet. + Example: if line is 'name 5abcdefgh 4', then looking for ' 5' will match but '5$' will + not (correctly). +- 'pivpn -c' will show the Connected Clients List for WireGuard too + +## Dec 10th 2019 + +- Use dedicated openvpn user and group for increased security +- Added basic safeguards to avoid wrecking /etc/ufw/before.rules +- Applied some Shellcheck suggested changes. +- Added safeguards to rm -rf when downloading the git repo. +- Use more variables instead of hardcoding data +- Add local resolver as DNS option + +## Dec 3rd 2019 + +- Better client stats formatting + +## Dec 2nd 2019 + +* Properly avoid pulling unwanted packages from unstable repo: + - Currently apt pulls all packages from the unstable repo because the script intendation created the file 'limit-unstable' with tabs in it. Fixed using printf to create a multiline file. +- Accept debug fixes using just the enter key + +## Nov 19th 2019 + +- Added Ubuntu Bionic support + +## Nov 16th 2019 + +- Added back unattended installation: as expected, the user can call the install script with --unattended followed by a config file and PiVPN will be installed non-interactively. +- Removed persist-key and persist-tun from the client config. +- Reverted keepalive setting on the server to smaller values. +- See @TinCanTech's posts for the reasons of the above two: #864 (comment) +- Copied validDomain() function from the test branch. +- Removed 1024 bit certificate options, since on Buster OpenVPN does not start with such small certificates (It's related to OpenSSL 1.1.1). +- Backup /etc/openvpn and /etc/wireguard before installing. +- Always remove VPN configuration when uninstalling, but do not wipe the folder, just remove what PiVPN added. +- Fetch latest WireGuard snapshot instead of hardcoding it into the script. + +## Nov 7th 2019 + +- Add back the uninstall script +- Only uninstall packages that were not already installed when running the PiVPN install script. +- Detect and offer to use Pi-hole +- Use checkinstall to install wireguard-tools for easy uninstallation +- Added missing dkms dependency + +## Oct 19th 2019 + +- MakeOVPN has been updated to include the -i iOS function to allow users to create an OVPN12 format file that can be used with the iOS keychain. +- Check if -i iOS can be used (can't be used with ECDSA certificates). +- Fixed the issues with special characters in OVPN12 files. + +## Oct 17th 2019 + +- Allow subdomain in custom DNS search list. +- Unified PiVPN configuration into the single /etc/pivpn/setupVars.conf file. +- Functions that ask the user for the port, protocol, dns, domain don't apply the setting anymore, they only save the variable on disk. Settings are applied in confOpenVPN, confOVPN, confWireGuard. +- Support and use WireGuard by default with an initial set of scripts matching current PiVPN scripts (list, create, remove clients). +- Removed OpenVPN ECDSA option. +- Renamed some variables (see pull request 849). +- Refactored several functions. ## Oct 12th 2019 From 1884be8afb2b86565932c9e89105f07232732449 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Sat, 18 Jan 2020 20:01:39 +0100 Subject: [PATCH 72/79] Distro Support, Bug Fixes, Unattended install Tested and added Support on Debian 9 tested and added support on Ubuntu 16.04 & 18.08 * Fixed wireguard not installing, added pkg cache update after adding ppa * added kernel headers to dependencies as its requred for wireguard-dkms unattended install * When user is provided and doest exist, it will create one without password set --- auto_install/install.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index c6c1004..3ceb9af 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -246,14 +246,14 @@ distroCheck(){ source /etc/os-release PLAT=$(awk '{print $1}' <<< "$NAME") VER="$VERSION_ID" - declare -A VER_MAP=(["10"]="buster" ["18.04"]="bionic") + declare -A VER_MAP=(["9"]="stretch" ["10"]="buster" ["16.04"]="xenial" ["18.04"]="bionic") OSCN=${VER_MAP["${VER}"]} fi case ${PLAT} in Debian|Raspbian|Ubuntu) case ${OSCN} in - buster|bionic) + buster|xenial|bionic|stretch) : ;; *) @@ -752,8 +752,9 @@ chooseUser(){ if awk -F':' '$3>=1000 && $3<=60000 {print $1}' /etc/passwd | grep -qw "${install_user}"; then echo "::: ${install_user} will hold your ovpn configurations." else - echo "::: User ${install_user} does not exist" - exit 1 + echo "::: User ${install_user} does not exist, creating..." + $SUDO useradd -m -s /bin/bash "${install_user}" + echo "::: User created without a password, please do sudo passwd $install_user to create one" fi fi install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6) @@ -1098,7 +1099,8 @@ installWireGuard(){ echo "::: Installing WireGuard from PPA... " $SUDO add-apt-repository ppa:wireguard/wireguard -y - PIVPN_DEPS=(qrencode wireguard wireguard-tools wireguard-dkms) + $SUDO ${UPDATE_PKG_CACHE} + PIVPN_DEPS=(qrencode wireguard wireguard-tools wireguard-dkms linux-headers-$(uname -r)) installDependentPackages PIVPN_DEPS[@] fi From 66cf44e7741de6126e92f319259c7fe085a89a38 Mon Sep 17 00:00:00 2001 From: 4s3ti <4s3ti@protonmail.com> Date: Sat, 18 Jan 2020 20:10:28 +0100 Subject: [PATCH 73/79] Updated: LatestUpdate.md --- LatestUpdate.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/LatestUpdate.md b/LatestUpdate.md index 2d8a942..6dab38c 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -5,6 +5,18 @@ patch release notes. Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged. +## Jan 18th 2020 + +Distro Support, Bug Fixes, Unattended install + +Tested and added Support on Debian 9 +tested and added support on Ubuntu 16.04 & 18.08 + * Fixed wireguard not installing, added pkg cache update after adding ppa + * added kernel headers to dependencies as its requred for wireguard-dkms +unattended install + * When user is provided and doest exist, it will create one without password set + + ## Jan 8th 2020 Updates and improvements From fc9a9f5ab781a94c36eb3cba6b35a366393925ea Mon Sep 17 00:00:00 2001 From: Orazio Date: Sat, 18 Jan 2020 22:04:18 +0100 Subject: [PATCH 74/79] Use metapackage to install kernel headers on Ubuntu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ‘linux-headers-generic’ package is preferred over the version-specific headers package as the generic will be automatically updated with the kernel, whereas the other will not. --- auto_install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 3ceb9af..0f91ab3 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -246,7 +246,7 @@ distroCheck(){ source /etc/os-release PLAT=$(awk '{print $1}' <<< "$NAME") VER="$VERSION_ID" - declare -A VER_MAP=(["9"]="stretch" ["10"]="buster" ["16.04"]="xenial" ["18.04"]="bionic") + declare -A VER_MAP=(["9"]="stretch" ["10"]="buster" ["16.04"]="xenial" ["18.04"]="bionic") OSCN=${VER_MAP["${VER}"]} fi @@ -1100,7 +1100,7 @@ installWireGuard(){ echo "::: Installing WireGuard from PPA... " $SUDO add-apt-repository ppa:wireguard/wireguard -y $SUDO ${UPDATE_PKG_CACHE} - PIVPN_DEPS=(qrencode wireguard wireguard-tools wireguard-dkms linux-headers-$(uname -r)) + PIVPN_DEPS=(qrencode wireguard wireguard-tools wireguard-dkms linux-headers-generic) installDependentPackages PIVPN_DEPS[@] fi From 69606f7207087a6458f74d6918e40c28cdaf5838 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 20 Jan 2020 09:34:43 +0100 Subject: [PATCH 75/79] - Allow setting DHCP reservation preference with --unattended - Flip condition check on $dhcpReserv: first check if empty, and if not, check if it's not 1. Doing it the other way (first check if not 1) would give a shell error if $dhcpReserv was empty. --- auto_install/install.sh | 59 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 0f91ab3..4f0b15f 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -166,7 +166,7 @@ main(){ avoidStaticIPv4Ubuntu else getStaticIPv4Settings - if [ "$dhcpReserv" -ne 1 ] || [ -z "$dhcpReserv" ]; then + if [ -z "$dhcpReserv" ] || [ "$dhcpReserv" -ne 1 ]; then setStaticIPv4 fi fi @@ -596,43 +596,48 @@ getStaticIPv4Settings() { if [ "${runUnattended}" = 'true' ]; then - local INVALID_STATIC_IPV4_SETTINGS=0 + if [ -z "$dhcpReserv" ] || [ "$dhcpReserv" -ne 1 ]; then + local INVALID_STATIC_IPV4_SETTINGS=0 - if [ -z "$IPv4addr" ]; then - echo "::: Missing static IP address" - INVALID_STATIC_IPV4_SETTINGS=1 - fi + if [ -z "$IPv4addr" ]; then + echo "::: Missing static IP address" + INVALID_STATIC_IPV4_SETTINGS=1 + fi - if [ -z "$IPv4gw" ]; then - echo "::: Missing static IP gateway" - INVALID_STATIC_IPV4_SETTINGS=1 - fi + if [ -z "$IPv4gw" ]; then + echo "::: Missing static IP gateway" + INVALID_STATIC_IPV4_SETTINGS=1 + fi - if [ "$INVALID_STATIC_IPV4_SETTINGS" -eq 1 ]; then - echo "::: Incomplete static IP settings" - exit 1 - fi - - if [ -z "$IPv4addr" ] && [ -z "$IPv4gw" ]; then - echo "::: No static IP settings, using current settings" - echo "::: Your static IPv4 address: ${IPv4addr}" - echo "::: Your static IPv4 gateway: ${IPv4gw}" - else - if validIP "${IPv4addr%/*}"; then - echo "::: Your static IPv4 address: ${IPv4addr}" - else - echo "::: ${IPv4addr%/*} is not a valid IP address" + if [ "$INVALID_STATIC_IPV4_SETTINGS" -eq 1 ]; then + echo "::: Incomplete static IP settings" exit 1 fi - if validIP "${IPv4gw}"; then + if [ -z "$IPv4addr" ] && [ -z "$IPv4gw" ]; then + echo "::: No static IP settings, using current settings" + echo "::: Your static IPv4 address: ${IPv4addr}" echo "::: Your static IPv4 gateway: ${IPv4gw}" else - echo "::: ${IPv4gw} is not a valid IP address" - exit 1 + if validIP "${IPv4addr%/*}"; then + echo "::: Your static IPv4 address: ${IPv4addr}" + else + echo "::: ${IPv4addr%/*} is not a valid IP address" + exit 1 + fi + + if validIP "${IPv4gw}"; then + echo "::: Your static IPv4 gateway: ${IPv4gw}" + else + echo "::: ${IPv4gw} is not a valid IP address" + exit 1 + fi fi + else + echo "::: Skipping setting static IP address" fi + echo "dhcpReserv=${dhcpReserv}" >> /tmp/setupVars.conf echo "IPv4addr=${IPv4addr%/*}" >> /tmp/setupVars.conf echo "IPv4gw=${IPv4gw}" >> /tmp/setupVars.conf return From dba3e6ad3e1da74a56ea8914f4e089df7d7d519a Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 20 Jan 2020 09:56:07 +0100 Subject: [PATCH 76/79] - Prepend 'pivpn-' to unstable repo files to limit naming conflicts - Update variables inside unattended examples - Remove openvpn logging setting when uninstalling the package - Run 'apt-get update' after removing the WireGuard PPA --- auto_install/install.sh | 6 +++--- scripts/uninstall.sh | 11 ++++++++--- unattended_openvpn_example.conf | 6 +++--- unattended_wireguard_example.conf | 6 +++--- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 4f0b15f..4236a21 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -990,7 +990,7 @@ installWireGuard(){ installDependentPackages PIVPN_DEPS[@] # Do not upgrade packages from the unstable repository except for wireguard echo "::: Adding Debian repository... " - echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null + echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/pivpn-unstable.list > /dev/null printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 @@ -1093,8 +1093,8 @@ installWireGuard(){ echo "::: Installing WireGuard from Debian package... " echo "::: Adding Debian repository... " - echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/unstable.list > /dev/null - printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/pivpn-unstable.list > /dev/null + printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' | $SUDO tee /etc/apt/preferences.d/pivpn-limit-unstable > /dev/null # shellcheck disable=SC2086 $SUDO ${UPDATE_PKG_CACHE} &> /dev/null PIVPN_DEPS=(linux-headers-amd64 qrencode wireguard wireguard-tools wireguard-dkms) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 203aaa0..766f78d 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -111,11 +111,12 @@ removeAll(){ # there is no wireguard package). On Ubuntu, remove the PPA. ### FIXME: unconditionally rm'ing unstable.list isn't a good idea, it appears. What if someone else put it there manually? if [ "$PLAT" = "Debian" ] || { [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv7l" ]; }; then - rm /etc/apt/sources.list.d/unstable.list - rm /etc/apt/preferences.d/limit-unstable + rm -f /etc/apt/sources.list.d/pivpn-unstable.list + rm -f /etc/apt/preferences.d/pivpn-limit-unstable $PKG_MANAGER update &> /dev/null elif [ "$PLAT" = "Ubuntu" ]; then add-apt-repository ppa:wireguard/wireguard -r -y + $PKG_MANAGER update &> /dev/null fi elif [ "${i}" = "wireguard-dkms" ]; then @@ -148,7 +149,11 @@ removeAll(){ rm -rf /etc/apt/apt.conf.d/*unattended-upgrades elif [ "${i}" = "openvpn" ]; then - deluser openvpn + + deluser openvpn + rm -f /etc/rsyslog.d/30-openvpn.conf + rm -f /etc/logrotate.d/openvpn + fi printf ":::\\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\\n"; break diff --git a/unattended_openvpn_example.conf b/unattended_openvpn_example.conf index 92a6e40..ae9d9b7 100644 --- a/unattended_openvpn_example.conf +++ b/unattended_openvpn_example.conf @@ -1,11 +1,11 @@ IPv4dev=eth0 -staticReserv=0 +dhcpReserv=0 install_user=pi VPN=openvpn pivpnPROTO=udp pivpnPORT=1194 -pivpnDNS1=8.8.8.8 -pivpnDNS2=8.8.4.4 +pivpnDNS1=9.9.9.9 +pivpnDNS2=149.112.112.112 pivpnHOST=pivpn.example.com pivpnENCRYPT=2048 pivpnSEARCHDOMAIN=searchdomain.example.com diff --git a/unattended_wireguard_example.conf b/unattended_wireguard_example.conf index 8040e0e..196d4d5 100644 --- a/unattended_wireguard_example.conf +++ b/unattended_wireguard_example.conf @@ -1,9 +1,9 @@ IPv4dev=eth0 -staticReserv=0 +dhcpReserv=0 install_user=pi VPN=wireguard pivpnPORT=51820 -pivpnDNS1=8.8.8.8 -pivpnDNS2=8.8.4.4 +pivpnDNS1=9.9.9.9 +pivpnDNS2=149.112.112.112 pivpnHOST=pivpn.example.com UNATTUPG=1 From db293c3093a49a3273858de4dfb6366dac13aed5 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 20 Jan 2020 10:03:20 +0100 Subject: [PATCH 77/79] Update LatestUpdate.md --- LatestUpdate.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/LatestUpdate.md b/LatestUpdate.md index 6dab38c..a0ba13d 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -5,6 +5,16 @@ patch release notes. Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged. +## Jan 20th 2020 + +- Allow setting DHCP reservation preference with --unattended +- Flip condition check on $dhcpReserv: first check if empty, and if not, check if it's not 1. + Doing it the other way (first check if not 1) would give a shell error if $dhcpReserv was empty. +- Prepend 'pivpn-' to unstable repo files to limit naming conflicts +- Update variables inside unattended examples +- Remove openvpn logging setting when uninstalling the package +- Run 'apt-get update' after removing the WireGuard PPA + ## Jan 18th 2020 Distro Support, Bug Fixes, Unattended install @@ -15,6 +25,7 @@ tested and added support on Ubuntu 16.04 & 18.08 * added kernel headers to dependencies as its requred for wireguard-dkms unattended install * When user is provided and doest exist, it will create one without password set + * Use metapackage to install kernel headers on Ubuntu ## Jan 8th 2020 From affad0a7b0e002ea5241a53933cf3fa841d36aeb Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 20 Jan 2020 10:55:29 +0100 Subject: [PATCH 78/79] Resolved merge conflicts --- LatestUpdate.md | 49 +++++++++++++++++++++++-------------- README.md | 3 +-- scripts/openvpn/makeOVPN.sh | 7 +++--- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/LatestUpdate.md b/LatestUpdate.md index a0ba13d..0d33980 100644 --- a/LatestUpdate.md +++ b/LatestUpdate.md @@ -146,6 +146,19 @@ Updated LatestChanges - Currently apt pulls all packages from the unstable repo because the script intendation created the file 'limit-unstable' with tabs in it. Fixed using printf to create a multiline file. - Accept debug fixes using just the enter key +## Nov 25th 2019 - On Master + +* Changed pivpn command exit codes from 1 to 0 + - exit code 1 means general error hence should not be used for exiting successfully +* added backup script to backup openvpn and pivpn generated certificates +* added update script to update /opt/pivpn scripts, -t | --test | test update from test branch +* Fixed hostname length issue #831 + - the script now checks for hostname length right at the beginning and prompts for a new one. + - HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only. +* fixed ubuntu 18.04 being detected as not supported OS, now fully supported and tested. +* changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all `*.sh` files making it easier to manage when adding new scripts/features +* Changed how supported OS are presented when maybeOS_Support() is called. + ## Nov 19th 2019 - Added Ubuntu Bionic support @@ -186,7 +199,7 @@ Updated LatestChanges - Renamed some variables (see pull request 849). - Refactored several functions. -## Oct 12th 2019 +## Oct 12th 2019 - On test * Changed pivpn command exit codes from 1 to 0 - exit code 1 means general error hence should not be used for exiting successfully @@ -199,23 +212,6 @@ Updated LatestChanges * changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all `*.sh` files making it easier to manage when adding new scripts/features * Changed how supported OS are presented when maybeOS_Support() is called. -## Sept 1st 2019 - -* Added support for Buster -* .ovpn12 files making use of iOS keychain -* Leverage the Hostname of the Server to generate server uuid -* integrated support to bitwarden password manager into pivpn -* Recreate ovpn folder if deleted -* Handle older UFW version from Jessie -* Only use iptables-legacy if platform is Buster -* improved Buester and Jessie IPtables / ufw handling -* bugfixes and typos -* permissions hardening and writing uniformization -* improved pivpn user and ovpns dirs handling -* Changes variable and file naming in `install.sh` - - $pivPNUser renamed to $INSTALL_USER - - /tmp/pivpnUSR renamed to INSTALL_USER - ### Merge Patch, Sept 2nd 2019 * Bitwarden integration: @@ -232,4 +228,19 @@ Updated LatestChanges * General improvments: - when runing updates, sudo password prompt now shows up in a new line ----- +## Sept 1st 2019 + +* Added support for Buster +* .ovpn12 files making use of iOS keychain +* Leverage the Hostname of the Server to generate server uuid +* integrated support to bitwarden password manager into pivpn +* Recreate ovpn folder if deleted +* Handle older UFW version from Jessie +* Only use iptables-legacy if platform is Buster +* improved Buester and Jessie IPtables / ufw handling +* bugfixes and typos +* permissions hardening and writing uniformization +* improved pivpn user and ovpns dirs handling +* Changes variable and file naming in `install.sh` + - $pivPNUser renamed to $INSTALL_USER + - /tmp/pivpnUSR renamed to INSTALL_USER diff --git a/README.md b/README.md index 276892a..2261afd 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,7 @@ Installation ----------------- **Method 1** - -```shell +```Shell curl -L https://install.pivpn.dev | bash ``` diff --git a/scripts/openvpn/makeOVPN.sh b/scripts/openvpn/makeOVPN.sh index 674732f..7459164 100755 --- a/scripts/openvpn/makeOVPN.sh +++ b/scripts/openvpn/makeOVPN.sh @@ -194,6 +194,7 @@ function keyPASS() { fi #Escape chars in PASSWD + PASSWD_UNESCAPED="${PASSWD}" PASSWD=$(echo -n ${PASSWD} | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/\$/\\\$/g' -e 's/!/\\!/g' -e 's/\./\\\./g' -e "s/'/\\\'/g" -e 's/"/\\"/g' -e 's/\*/\\\*/g' -e 's/\@/\\\@/g' -e 's/\#/\\\#/g' -e 's/£/\\£/g' -e 's/%/\\%/g' -e 's/\^/\\\^/g' -e 's/\&/\\\&/g' -e 's/(/\\(/g' -e 's/)/\\)/g' -e 's/-/\\-/g' -e 's/_/\\_/g' -e 's/\+/\\\+/g' -e 's/=/\\=/g' -e 's/\[/\\\[/g' -e 's/\]/\\\]/g' -e 's/;/\\;/g' -e 's/:/\\:/g' -e 's/|/\\|/g' -e 's//\\>/g' -e 's/,/\\,/g' -e 's/?/\\?/g' -e 's/~/\\~/g' -e 's/{/\\{/g' -e 's/}/\\}/g') #Build the client key and then encrypt the key @@ -354,9 +355,9 @@ if [ "$iOS" = "1" ]; then printf "Please remember the export password\n" printf "as you will need this import the certificate on your iOS device\n" printf "========================================================\n" - openssl pkcs12 -passin pass:"$PASSWD" -export -in "issued/${NAME}${CRT}" -inkey "private/${NAME}${KEY}" -certfile ${CA} -name "${NAME}" -out "$install_home/ovpns/$NAME.ovpn12" - chown "$install_user" "$install_home/ovpns/$NAME.ovpn12" - chmod 600 "$install_home/ovpns/$NAME.ovpn12" + openssl pkcs12 -passin pass:"$PASSWD_UNESCAPED" -export -in "issued/${NAME}${CRT}" -inkey "private/${NAME}${KEY}" -certfile ${CA} -name "${NAME}" -out "$install_home/ovpns/$NAME.ovpn12" + chown "$install_user":"$install_user" "$install_home/ovpns/$NAME.ovpn12" + chmod 640 "$install_home/ovpns/$NAME.ovpn12" printf "========================================================\n" printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME.ovpn12" printf "You will need to transfer both the .ovpn and .ovpn12 files\n" From 038473c6c50a9dc6fc20c86da1bde15f8f722c25 Mon Sep 17 00:00:00 2001 From: Orazio Date: Mon, 20 Jan 2020 11:46:17 +0100 Subject: [PATCH 79/79] Rename 'limit-unstable' to 'pivpn-limit-unstable' --- auto_install/install.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 202b469..1e5f7d6 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -818,8 +818,6 @@ chooseUser(){ echo "::: Cancel selected, exiting...." exit 1 fi - - } isRepo(){ @@ -990,7 +988,7 @@ installWireGuard(){ # Do not upgrade packages from the unstable repository except for wireguard echo "::: Adding Debian repository... " echo "deb https://deb.debian.org/debian/ unstable main" | $SUDO tee /etc/apt/sources.list.d/pivpn-unstable.list > /dev/null - printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/limit-unstable > /dev/null + printf 'Package: *\nPin: release a=unstable\nPin-Priority: 1\n\nPackage: wireguard wireguard-dkms wireguard-tools\nPin: release a=unstable\nPin-Priority: 500\n' | $SUDO tee /etc/apt/preferences.d/pivpn-limit-unstable > /dev/null $SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138 # shellcheck disable=SC2086