From 5db23185fd8d5e50aea6ca86f4116159771c6a0d Mon Sep 17 00:00:00 2001 From: EWouters Date: Mon, 13 Mar 2017 17:00:28 +1300 Subject: [PATCH 01/37] Added pi-hole's undocumented flags UNTESTED! --- auto_install/install.sh | 425 ++++++++++++++++++++++++++++------------ 1 file changed, 304 insertions(+), 121 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 85575c4..ebf6bfb 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -10,11 +10,13 @@ # curl -L https://install.pivpn.io | bash # Make sure you have `curl` installed - +set -e ######## VARIABLES ######### tmpLog="/tmp/pivpn-install.log" instalLogLoc="/etc/pivpn/install.log" +setupVars=/etc/pivpn/setupVars.conf +useUpdateVars=false ### PKG Vars ### PKG_MANAGER="apt-get" @@ -42,6 +44,11 @@ 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)}') @@ -51,24 +58,6 @@ 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 -######## 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 - # 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. @@ -79,44 +68,47 @@ If you think you received this message in error, you can post an issue on the Gi 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 this installer supports Raspbian jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). - 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 +Currently this installer supports Raspbian jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +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 } -# 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 or jessie - - if [[ $PLAT == "Ubuntu" || $PLAT == "Raspbian" || $PLAT == "Debian" ]]; then - if [[ $OSCN != "trusty" && $OSCN != "xenial" && $OSCN != "jessie" ]]; then - maybeOS_Support - fi - else - noOS_Support - fi -# else get info from os-release -elif grep -q debian /etc/os-release; then - if grep -q jessie /etc/os-release; then - PLAT="Raspbian" - OSCN="jessie" - else - PLAT="Ubuntu" - OSCN="unknown" - maybeOS_Support - fi -# else we prob don't want to install -else - noOS_Support -fi - -echo "${PLAT}" > /tmp/DET_PLATFORM +# Compatibility +distro_check() { + # 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 or jessie + + if [[ $PLAT == "Ubuntu" || $PLAT == "Raspbian" || $PLAT == "Debian" ]]; then + if [[ $OSCN != "trusty" && $OSCN != "xenial" && $OSCN != "jessie" ]]; then + maybeOS_Support + fi + else + noOS_Support + fi + # else get info from os-release + elif grep -q debian /etc/os-release; then + if grep -q jessie /etc/os-release; then + PLAT="Raspbian" + OSCN="jessie" + else + PLAT="Ubuntu" + OSCN="unknown" + maybeOS_Support + fi + # else we prob don't want to install + else + noOS_Support + fi + + echo "${PLAT}" > /tmp/DET_PLATFORM +} ####### FUNCTIONS ########## spinner() @@ -280,6 +272,7 @@ If you are in Amazon then you can not configure a static IP anyway. Just ensure } 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 @@ -347,7 +340,6 @@ setStaticIPv4() { 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}" @@ -604,17 +596,21 @@ make_repo() { } update_repo() { - # Pull the latest commits - echo -n "::: Updating repo in $1..." - cd "${1}" || exit 1 - $SUDO git stash -q > /dev/null & spinner $! - $SUDO git pull -q > /dev/null & spinner $! - if [ -z "${TESTING+x}" ]; then - : + if [[ "${reconfigure}" == true ]]; then + echo "::: --reconfigure passed to install script. Not downloading/updating local repos" else - ${SUDOE} git checkout test + # Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + $SUDO git stash -q > /dev/null & spinner $! + $SUDO git pull -q > /dev/null & spinner $! + if [ -z "${TESTING+x}" ]; then + : + else + ${SUDOE} git checkout test + fi + echo " done!" fi - echo " done!" } setCustomProto() { @@ -816,7 +812,7 @@ set_var EASYRSA_ALGO rsa set_var EASYRSA_CURVE secp384r1 EOF -echo "${String}" | $SUDO tee /etc/openvpn/easy-rsa/vars >/dev/null + echo "${String}" | $SUDO tee /etc/openvpn/easy-rsa/vars >/dev/null # Edit the KEY_SIZE variable in the vars file to set user chosen key size cd /etc/openvpn/easy-rsa || exit @@ -836,15 +832,15 @@ echo "${String}" | $SUDO tee /etc/openvpn/easy-rsa/vars >/dev/null ${SUDOE} ./easyrsa build-server-full server nopass 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 a pool of the last 128 generated.\nMore information about this service can be found here: https://2ton.com.au/dhtool/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}) -then - # Downloading parameters - RANDOM_INDEX=$(( RANDOM % 128 )) - ${SUDOE} curl "https://2ton.com.au/dhparam/${ENCRYPT}/${RANDOM_INDEX}" -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 + then + # Downloading parameters + RANDOM_INDEX=$(( RANDOM % 128 )) + ${SUDOE} curl "https://2ton.com.au/dhparam/${ENCRYPT}/${RANDOM_INDEX}" -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 # Generate static HMAC key to defend against DDoS ${SUDOE} openvpn --genkey --secret pki/ta.key @@ -1007,11 +1003,41 @@ confOVPN() { $SUDO chmod 0777 -R "/home/$pivpnUser/ovpns" } +finalExports() { + # Update variables in setupVars.conf file + if [ -e "${setupVars}" ]; then + sed -i.update.bak '/pivpnInterface/d;/IPv4dns/d;/IPv4addr/d;/IPv4gw/d;/pivpnUser/d;/UNATTUPG/d;' "${setupVars}" + fi + { + echo "pivpnInterface=${pivpnInterface}" + echo "IPv4dns=${IPv4dns}" + echo "IPv4addr=${IPv4addr}" + echo "IPv4gw=${IPv4gw}" + echo "pivpnUser=${pivpnUser}" + echo "UNATTUPG=${UNATTUPG}" + }>> "${setupVars}" +} + + +# I suggest replacing these names. + +#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/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/pivpnUser/PIVPN_USER/g' ${setupVars} +# sed -i 's/IPv4dns/IPV4_DNS/g' ${setupVars} +# #sed -i 's/UNATTUPG/UNATTUPG/g' ${setupVars} +#} + installPiVPN() { stopServices - confUnattendedUpgrades $SUDO mkdir -p /etc/pivpn/ - getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} + confUnattendedUpgrades installScripts setCustomProto setCustomPort @@ -1019,17 +1045,26 @@ installPiVPN() { confNetwork confOVPN setClientDNS + finalExports } +updatePiVPN() { # Could be replaced by installPiVPN, but keep structure close to pi-hole + #accountForRefactor + stopServices + confUnattendedUpgrades + installScripts + setCustomProto + setCustomPort + confOpenVPN + confNetwork + confOVPN + setClientDNS + finalExports #re-export setupVars.conf to account for any new vars added in new versions +} + + displayFinalMessage() { # Final completion message to user - if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - $SUDO service openvpn start - else - $SUDO systemctl enable openvpn.service - $SUDO systemctl start openvpn.service - fi - 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! The install log is in /etc/pivpn." ${r} ${c} @@ -1041,46 +1076,194 @@ The install log is in /etc/pivpn." ${r} ${c} 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 +} + ######## SCRIPT ############ -# Verify there is enough disk space for the install -verifyFreeDiskSpace -# Install the packages (we do this first because we need whiptail) -#checkForDependencies -update_package_cache +main() { -notify_package_updates_available + ######## 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 + distro_check -install_dependent_packages PIVPN_DEPS[@] + # 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 [[ -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 + + # Install the packages (we do this first because we need whiptail) + #checkForDependencies + update_package_cache + + # Notify user of package availability + notify_package_updates_available + + # Install packages used by this installation script + install_dependent_packages PIVPN_DEPS[@] + + if [[ ${useUpdateVars} == false ]]; then + # Display welcome dialogs + welcomeDialogs + + # Find interfaces and let the user choose one + chooseInterface + + # Only try to set static on Raspbian, otherwise let user do it + if [[ $PLAT != "Raspbian" ]]; then + avoidStaticIPv4Ubuntu + else + getStaticIPv4Settings + setStaticIPv4 + fi + + # Set the Network IP and Mask correctly + setNetwork + + # Choose the user for the ovpns + chooseUser + + # Ask if unattended-upgrades will be enabled + unattendedUpgrades + + # Clone/Update the repos + clone_or_update_repos + + # Install and log everything to a file + installPiVPN | tee ${tmpLog} + + echo "::: Install Complete..." + else + # Only try to set static on Raspbian + if [[ $PLAT != "Raspbian" ]]; then + 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." + else + 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 + fi + + # Clone/Update the repos + clone_or_update_repos + + # Source ${setupVars} for use in the rest of the functions. + source ${setupVars} + + + updatePiVPN | tee ${tmpLog} + fi + + #Move the install log into /etc/pivpn for storage + $SUDO mv ${tmpLog} ${instalLogLoc} + + echo "::: Restarting services..." + # Start services + if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then + $SUDO service openvpn start + else + $SUDO systemctl enable openvpn.service + $SUDO systemctl start openvpn.service + fi + + echo "::: done." + + if [[ "${useUpdateVars}" == false ]]; then + displayFinalMessage + fi + + echo ":::" + if [[ "${useUpdateVars}" == false ]]; then + echo "::: Installation Complete!" + echo "::: Now run 'pivpn add' to create the ovpn profiles." + 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 "::: The install log is located at: ${instalLogLoc}" +} -# Start the installer -welcomeDialogs - -# Find interfaces and let the user choose one -chooseInterface - -# Only try to set static on Raspbian, otherwise let user do it -if [[ $PLAT != "Raspbian" ]]; then - avoidStaticIPv4Ubuntu -else - getStaticIPv4Settings - setStaticIPv4 +if [[ "${PVPN_TEST}" != true ]] ; then + main "$@" fi - -setNetwork - -# Choose the user for the ovpns -chooseUser - -# Ask if unattended-upgrades will be enabled -unattendedUpgrades - -# Install -installPiVPN | tee ${tmpLog} - -#Move the install log into /etc/pivpn for storage -$SUDO mv ${tmpLog} ${instalLogLoc} - -displayFinalMessage - -echo "::: Install Complete..." From 71021d6ffa5f4c068999f576077e650e929081ec Mon Sep 17 00:00:00 2001 From: EWouters Date: Mon, 13 Mar 2017 19:44:29 +1300 Subject: [PATCH 02/37] Added all parameters, initial testing done --- auto_install/install.sh | 165 +++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 61 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index ebf6bfb..dfe775c 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -480,7 +480,6 @@ unattendedUpgrades() { 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" - $SUDO apt-get --yes --quiet --no-install-recommends install "$UNATTUPG" > /dev/null & spinner $! else UNATTUPG="" fi @@ -772,20 +771,19 @@ setClientDNS() { } confOpenVPN() { - # Ask user if want to modify default port - SERVER_NAME="server" - - # Ask user for desired level of encryption - ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ - "Choose your desired level of encryption:\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing or just want to get through it quicker you can use 1024. If you are paranoid about ... things... then grab a cup of joe and pick 4096." ${r} ${c} 3 \ - "2048" "Use 2048-bit encryption. Recommended level." ON \ - "1024" "Use 1024-bit encryption. Test level." OFF \ - "4096" "Use 4096-bit encryption. Paranoid level." OFF 3>&1 1>&2 2>&3) - - exitstatus=$? - if [ $exitstatus != 0 ]; then - echo "::: Cancel selected. Exiting..." - exit 1 + if [[ ${useUpdateVars} == false ]]; then + # Ask user for desired level of encryption + ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ + "Choose your desired level of encryption:\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing or just want to get through it quicker you can use 1024. If you are paranoid about ... things... then grab a cup of joe and pick 4096." ${r} ${c} 3 \ + "2048" "Use 2048-bit encryption. Recommended level." ON \ + "1024" "Use 1024-bit encryption. Test level." OFF \ + "4096" "Use 4096-bit encryption. Paranoid level." OFF 3>&1 1>&2 2>&3) + + exitstatus=$? + if [ $exitstatus != 0 ]; then + echo "::: Cancel selected. Exiting..." + exit 1 + fi fi # If easy-rsa exists, remove it @@ -826,12 +824,23 @@ EOF ${SUDOE} ./easyrsa --batch build-ca nopass printf "\n::: CA Complete.\n" - whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman key, and HMAC key will now be generated." ${r} ${c} - + if [[ ${useUpdateVars} == false ]]; then + whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman key, and HMAC key will now be generated." ${r} ${c} + fi + # Build the server ${SUDOE} ./easyrsa build-server-full server nopass - 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 a pool of the last 128 generated.\nMore information about this service can be found here: https://2ton.com.au/dhtool/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}) + if [[ ${useUpdateVars} == 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 a pool of the last 128 generated.\nMore information about this service can be found here: https://2ton.com.au/dhtool/\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 + fi + + if [ "$ENCRYPT" -ge "4096" ] && [[ ${DOWNLOAD_DH_PARAM} == true ]] then # Downloading parameters RANDOM_INDEX=$(( RANDOM % 128 )) @@ -871,6 +880,7 @@ EOF confUnattendedUpgrades() { if [[ $UNATTUPG == "unattended-upgrades" ]]; then + $SUDO apt-get --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 @@ -953,37 +963,40 @@ confOVPN() { echo 0 > /tmp/REVOKE_STATUS $SUDO cp /tmp/REVOKE_STATUS /etc/pivpn/REVOKE_STATUS - METH=$(whiptail --title "Public IP or DNS" --radiolist "Will clients use a Public IP or DNS Name to connect to your server?" ${r} ${c} 2 \ - "$IPv4pub" "Use this public IP" "ON" \ - "DNS Entry" "Use a public DNS" "OFF" 3>&1 1>&2 2>&3) - - exitstatus=$? - if [ $exitstatus != 0 ]; then - echo "::: Cancel selected. Exiting..." - exit 1 - fi - $SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt - 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 + 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?" ${r} ${c} 2 \ + "$IPv4pub" "Use this public IP" "ON" \ + "DNS Entry" "Use a public DNS" "OFF" 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 + + 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 # if they modified port put value in Default.txt for clients to use @@ -1006,32 +1019,47 @@ confOVPN() { finalExports() { # Update variables in setupVars.conf file if [ -e "${setupVars}" ]; then - sed -i.update.bak '/pivpnInterface/d;/IPv4dns/d;/IPv4addr/d;/IPv4gw/d;/pivpnUser/d;/UNATTUPG/d;' "${setupVars}" + sed -i.update.bak '/pivpnUser/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;SERVER_NAME/d;' "${setupVars}" fi { + echo "pivpnUser=${pivpnUser}" + echo "UNATTUPG=${UNATTUPG}" echo "pivpnInterface=${pivpnInterface}" echo "IPv4dns=${IPv4dns}" echo "IPv4addr=${IPv4addr}" echo "IPv4gw=${IPv4gw}" - echo "pivpnUser=${pivpnUser}" - echo "UNATTUPG=${UNATTUPG}" + echo "pivpnProto=${pivpnProto}" + echo "PORT=${PORT}" + echo "ENCRYPT=${ENCRYPT}" + echo "DOWNLOAD_DH_PARAM=${DOWNLOAD_DH_PARAM}" + echo "PUBLICDNS=${PUBLICDNS}" + echo "OVPNDNS1=${OVPNDNS1}" + echo "OVPNDNS2=${OVPNDNS2}" + echo "SERVER_NAME=${SERVER_NAME}" }>> "${setupVars}" } -# I suggest replacing these names. +# I suggest replacing some of these names. #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/pivpnUser/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/pivpnUser/PIVPN_USER/g' ${setupVars} -# sed -i 's/IPv4dns/IPV4_DNS/g' ${setupVars} -# #sed -i 's/UNATTUPG/UNATTUPG/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/PUBLICDNS/g' ${setupVars} +# #sed -i 's/OVPNDNS1/OVPNDNS1/g' ${setupVars} +# #sed -i 's/OVPNDNS2/OVPNDNS2/g' ${setupVars} +# #sed -i 's/SERVER_NAME/SERVER_NAME/g' ${setupVars} #} installPiVPN() { @@ -1043,22 +1071,37 @@ installPiVPN() { setCustomPort confOpenVPN confNetwork + SERVER_NAME="server" confOVPN setClientDNS finalExports } -updatePiVPN() { # Could be replaced by installPiVPN, but keep structure close to pi-hole +updatePiVPN() { #accountForRefactor stopServices confUnattendedUpgrades installScripts - setCustomProto - setCustomPort + + # setCustomProto + echo "${pivpnProto}" > /tmp/pivpnPROTO + # write out the PROTO + PROTO=$pivpnProto + $SUDO cp /tmp/pivpnPROTO /etc/pivpn/INSTALL_PROTO + + #setCustomPort + # write out the port + echo ${PORT} > /tmp/INSTALL_PORT + $SUDO cp /tmp/INSTALL_PORT /etc/pivpn/INSTALL_PORT + confOpenVPN confNetwork confOVPN - setClientDNS + + # ?? 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 } @@ -1143,7 +1186,7 @@ main() { # Check for supported distribution distro_check - + # Check arguments for the undocumented flags for var in "$@"; do case "$var" in @@ -1212,6 +1255,9 @@ main() { echo "::: Install Complete..." else + # Source ${setupVars} for use in the rest of the functions. + source ${setupVars} + # Only try to set static on Raspbian if [[ $PLAT != "Raspbian" ]]; then echo "::: IP Information" @@ -1225,13 +1271,10 @@ main() { # Clone/Update the repos clone_or_update_repos - # Source ${setupVars} for use in the rest of the functions. - source ${setupVars} - updatePiVPN | tee ${tmpLog} fi - + #Move the install log into /etc/pivpn for storage $SUDO mv ${tmpLog} ${instalLogLoc} From 2a639e753e49a7faac3bc6cf5a4d38c6c8842df3 Mon Sep 17 00:00:00 2001 From: EWouters Date: Tue, 14 Mar 2017 10:48:16 +1300 Subject: [PATCH 03/37] Fixed sed command and mkdir if folder exists --- auto_install/install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index dfe775c..008b429 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1012,14 +1012,14 @@ confOVPN() { # verify server name to strengthen security $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt - $SUDO mkdir "/home/$pivpnUser/ovpns" + $SUDO mkdir -p "/home/$pivpnUser/ovpns" $SUDO chmod 0777 -R "/home/$pivpnUser/ovpns" } finalExports() { # Update variables in setupVars.conf file if [ -e "${setupVars}" ]; then - sed -i.update.bak '/pivpnUser/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;SERVER_NAME/d;' "${setupVars}" + sed -i.update.bak '/pivpnUser/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;/SERVER_NAME/d;' "${setupVars}" fi { echo "pivpnUser=${pivpnUser}" @@ -1056,9 +1056,9 @@ finalExports() { # #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/PUBLICDNS/g' ${setupVars} -# #sed -i 's/OVPNDNS1/OVPNDNS1/g' ${setupVars} -# #sed -i 's/OVPNDNS2/OVPNDNS2/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} # #sed -i 's/SERVER_NAME/SERVER_NAME/g' ${setupVars} #} From 5b5129f1bcf4818804a3d8e0e2a9ce2a51066b45 Mon Sep 17 00:00:00 2001 From: EWouters Date: Tue, 14 Mar 2017 14:26:22 +1300 Subject: [PATCH 04/37] =?UTF-8?q?fix:=20cp:=20cannot=20stat=20=E2=80=98/tm?= =?UTF-8?q?p/pivpnINT=E2=80=99:=20No=20such=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_install/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/auto_install/install.sh b/auto_install/install.sh index 008b429..7dfcf30 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1258,6 +1258,8 @@ main() { # Source ${setupVars} for use in the rest of the functions. source ${setupVars} + echo "${pivpnInterface}" > /tmp/pivpnINT + # Only try to set static on Raspbian if [[ $PLAT != "Raspbian" ]]; then echo "::: IP Information" From 7315353179a8bca7b337e90d9a6f10412c26d0c1 Mon Sep 17 00:00:00 2001 From: EWouters Date: Tue, 14 Mar 2017 15:25:39 +1300 Subject: [PATCH 05/37] Moved echo to file statements to front, add missing fixed a typo replaced tabs with spaces --- auto_install/install.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 7dfcf30..0d7cf15 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1084,21 +1084,19 @@ updatePiVPN() { installScripts # setCustomProto - echo "${pivpnProto}" > /tmp/pivpnPROTO # write out the PROTO PROTO=$pivpnProto $SUDO cp /tmp/pivpnPROTO /etc/pivpn/INSTALL_PROTO #setCustomPort # write out the port - echo ${PORT} > /tmp/INSTALL_PORT $SUDO cp /tmp/INSTALL_PORT /etc/pivpn/INSTALL_PORT confOpenVPN confNetwork confOVPN - # ?? Is this always OK? Also if you only select one DNS server ?? + # ?? 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 @@ -1258,8 +1256,17 @@ main() { # Source ${setupVars} for use in the rest of the functions. source ${setupVars} - echo "${pivpnInterface}" > /tmp/pivpnINT - + echo "::: Using IP address: $IPv4addr" + echo "${IPv4addr%/*}" > /tmp/pivpnIP + echo "::: Using interface: $pivpnInterface" + echo "${pivpnInterface}" > /tmp/pivpnINT + echo "::: Using User: $pivpnUser" + echo "${pivpnUser}" > /tmp/pivpnUSR + echo "::: Using protocol: $pivpnProto" + echo "${pivpnProto}" > /tmp/pivpnPROTO + echo "::: Using port: $PORT" + echo ${PORT} > /tmp/INSTALL_PORT + # Only try to set static on Raspbian if [[ $PLAT != "Raspbian" ]]; then echo "::: IP Information" @@ -1309,6 +1316,6 @@ main() { echo "::: The install log is located at: ${instalLogLoc}" } -if [[ "${PVPN_TEST}" != true ]] ; then +if [[ "${PIVPN_TEST}" != true ]] ; then main "$@" fi From 097145392c4fd4c80022315571ef3e01fbcf5b3b Mon Sep 17 00:00:00 2001 From: EWouters Date: Tue, 14 Mar 2017 15:39:07 +1300 Subject: [PATCH 06/37] set -e and set +e around line 800 to 815 I am not sure why this statement does not work with -e. We can also remove the set -e statement altogether. --- auto_install/install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/auto_install/install.sh b/auto_install/install.sh index 0d7cf15..6a22ad7 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -798,6 +798,7 @@ confOpenVPN() { $SUDO mkdir /etc/openvpn/easy-rsa/pki # Write out new vars file + set +e IFS= read -d '' String <<"EOF" if [ -z "$EASYRSA_CALLER" ]; then echo "Nope." >&2 @@ -811,6 +812,7 @@ set_var EASYRSA_CURVE secp384r1 EOF echo "${String}" | $SUDO tee /etc/openvpn/easy-rsa/vars >/dev/null + set -e # Edit the KEY_SIZE variable in the vars file to set user chosen key size cd /etc/openvpn/easy-rsa || exit @@ -1266,6 +1268,7 @@ main() { echo "${pivpnProto}" > /tmp/pivpnPROTO echo "::: Using port: $PORT" echo ${PORT} > /tmp/INSTALL_PORT + echo ":::" # Only try to set static on Raspbian if [[ $PLAT != "Raspbian" ]]; then From 277a212a8f77b2968edd3fd9798afa32fcbf5849 Mon Sep 17 00:00:00 2001 From: EWouters Date: Tue, 14 Mar 2017 15:39:53 +1300 Subject: [PATCH 07/37] tabs to spaces --- 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 6a22ad7..ca7f2b9 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -798,7 +798,7 @@ confOpenVPN() { $SUDO mkdir /etc/openvpn/easy-rsa/pki # Write out new vars file - set +e + set +e IFS= read -d '' String <<"EOF" if [ -z "$EASYRSA_CALLER" ]; then echo "Nope." >&2 @@ -812,7 +812,7 @@ set_var EASYRSA_CURVE secp384r1 EOF echo "${String}" | $SUDO tee /etc/openvpn/easy-rsa/vars >/dev/null - set -e + set -e # Edit the KEY_SIZE variable in the vars file to set user chosen key size cd /etc/openvpn/easy-rsa || exit From 7a65f083c4e552f61b38b118394f29c89b92691e Mon Sep 17 00:00:00 2001 From: EWouters Date: Wed, 15 Mar 2017 00:49:25 +1300 Subject: [PATCH 08/37] added -n and -p options to pivpn add ::: Create a client ovpn profile, optional nopass ::: ::: Usage: pivpn <-a|add> [-n|--name ] [-p|--password ]|[nopass] [-h|--help] ::: ::: Commands: ::: nopass Create a client without a password ::: -n,--name Name for the Client (default: 'raspberrypi') ::: -p,--password Password for the Client (no default) ::: -h,--help Show this help dialog --- scripts/makeOVPN.sh | 102 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index db15efe..1d501bd 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -10,6 +10,59 @@ TA="ta.key" INDEX="/etc/openvpn/easy-rsa/pki/index.txt" INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) +helpFunc() { + echo "::: Create a client ovpn profile, optional nopass" + echo ":::" + echo "::: Usage: pivpn <-a|add> [-n|--name ] [-p|--password ]|[nopass] [-h|--help]" + echo ":::" + echo "::: Commands:" + 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 "::: -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 + 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" + ;; + -h|--help) + helpFunc + exit 0 + ;; + nopass) + NO_PASS="1" + ;; + *) + echo "Error: Got an unexpected argument '$1'" + helpFunc + exit 1 + ;; + esac + shift +done + # Functions def function keynoPASS() { @@ -27,25 +80,27 @@ EOF function keyPASS() { - 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 + 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" @@ -69,8 +124,10 @@ EOF } -printf "Enter a Name for the Client: " -read -r NAME +if [ -z "${NAME}" ]; then + printf "Enter a Name for the Client: " + read -r NAME +fi if [[ "${NAME}" =~ [^a-zA-Z0-9] ]]; then echo "Name can only contain alphanumeric characters." @@ -109,8 +166,11 @@ fi cd /etc/openvpn/easy-rsa || exit -if [[ "$@" =~ "nopass" ]]; then +if [[ "${NO_PASS}" =~ "1" ]]; then keynoPASS +elif [[ -n "${PASSWD}" ]]; then + echo "Both nopass and password arguments passed to the script. Please use either one." + exit 1 else keyPASS fi From 56f24aa37218568a3828af43a987646af92b82fa Mon Sep 17 00:00:00 2001 From: EWouters Date: Wed, 15 Mar 2017 02:36:12 +1300 Subject: [PATCH 09/37] added command line option to (batch) remove certs ::: Revoke a client ovpn profile ::: ::: Usage: pivpn <-r|revoke> [-h|--help] [] ... [] ... ::: ::: Commands: ::: [none] Interactive mode ::: Client(s) to to revoke ::: -h,--help Show this help dialog --- pivpn | 5 +- scripts/makeOVPN.sh | 95 ++++++++++++------------- scripts/removeOVPN.sh | 158 +++++++++++++++++++++++++++++------------- 3 files changed, 159 insertions(+), 99 deletions(-) diff --git a/pivpn b/pivpn index fca88c2..4b191c0 100644 --- a/pivpn +++ b/pivpn @@ -55,7 +55,8 @@ function debugFunc { } function removeOVPNFunc { - $SUDO /opt/pivpn/removeOVPN.sh + shift + $SUDO /opt/pivpn/removeOVPN.sh "$@" exit 1 } @@ -94,7 +95,7 @@ case "$1" in "-c" | "clients" ) listClientsFunc;; "-d" | "debug" ) debugFunc;; "-l" | "list" ) listOVPNFunc;; -"-r" | "revoke" ) removeOVPNFunc;; +"-r" | "revoke" ) removeOVPNFunc "$@";; "-h" | "help" ) helpFunc;; "-u" | "uninstall" ) uninstallFunc;; "-v" ) versionFunc;; diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index 1d501bd..a42454a 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -11,56 +11,57 @@ INDEX="/etc/openvpn/easy-rsa/pki/index.txt" INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) helpFunc() { - echo "::: Create a client ovpn profile, optional nopass" - echo ":::" - echo "::: Usage: pivpn <-a|add> [-n|--name ] [-p|--password ]|[nopass] [-h|--help]" - echo ":::" - echo "::: Commands:" - 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 "::: -h,--help Show this help dialog" + echo "::: Create a client ovpn profile, optional nopass" + echo ":::" + echo "::: Usage: pivpn <-a|add> [-n|--name ] [-p|--password ]|[nopass] [-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 "::: -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 - 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" - ;; - -h|--help) - helpFunc - exit 0 - ;; - nopass) - NO_PASS="1" - ;; - *) - echo "Error: Got an unexpected argument '$1'" - helpFunc - exit 1 - ;; - esac - shift + _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" + ;; + -h|--help) + helpFunc + exit 0 + ;; + nopass) + NO_PASS="1" + ;; + *) + echo "Error: Got an unexpected argument '$1'" + helpFunc + exit 1 + ;; + esac + shift done # Functions def @@ -100,7 +101,7 @@ function keyPASS() { echo "pivpn add nopass" exit 1 fi - fi + fi if [ ${#PASSWD} -lt 4 ] || [ ${#PASSWD} -gt 1024 ] then echo "Password must be between from 4 to 1024 characters" @@ -170,7 +171,7 @@ if [[ "${NO_PASS}" =~ "1" ]]; then keynoPASS elif [[ -n "${PASSWD}" ]]; then echo "Both nopass and password arguments passed to the script. Please use either one." - exit 1 + exit 1 else keyPASS fi diff --git a/scripts/removeOVPN.sh b/scripts/removeOVPN.sh index 8f5773d..4e3515c 100644 --- a/scripts/removeOVPN.sh +++ b/scripts/removeOVPN.sh @@ -6,73 +6,131 @@ REVOKE_STATUS=$(cat /etc/pivpn/REVOKE_STATUS) PLAT=$(cat /etc/pivpn/DET_PLATFORM) INDEX="/etc/openvpn/easy-rsa/pki/index.txt" +helpFunc() { + echo "::: Revoke a client ovpn profile" + echo ":::" + echo "::: Usage: pivpn <-r|revoke> [-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 -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" +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 - let i=i+1 + 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 -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 + + 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 -done - -if [ -z "${VALID}" ]; then - printf "::: You didn't enter a valid cert name!\n" - exit 1 + + 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 if [ "${REVOKE_STATUS}" == 0 ]; then - echo 1 > /etc/pivpn/REVOKE_STATUS - printf "\nThis seems to be the first time you have revoked a cert.\n" + echo 1 > /etc/pivpn/REVOKE_STATUS + printf "\nThis seems to be the first time you have revoked a cert.\n" printf "First we need to initialize the Certificate Revocation List.\n" - printf "Then add the CRL to your server config and restart openvpn.\n" + printf "Then add the CRL to your server config and restart openvpn.\n" ./easyrsa gen-crl cp pki/crl.pem /etc/openvpn/crl.pem chown nobody:nogroup /etc/openvpn/crl.pem - sed -i '/#crl-verify/c\crl-verify /etc/openvpn/crl.pem' /etc/openvpn/server.conf - if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then - service openvpn restart - else - systemctl restart openvpn.service - fi + sed -i '/#crl-verify/c\crl-verify /etc/openvpn/crl.pem' /etc/openvpn/server.conf + if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then + service openvpn restart + else + systemctl restart openvpn.service + fi fi -./easyrsa --batch revoke "${NAME}" -./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/${NAME}.req" -rm -rf "pki/private/${NAME}.key" -rm -rf "pki/issued/${NAME}.crt" -rm -rf "/home/${INSTALL_USER}/ovpns/${NAME}.ovpn" -cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem +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 "/home/${INSTALL_USER}/ovpns/${CERTS_TO_REVOKE[ii]}.ovpn" + cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem +done printf "::: Completed!\n" From 75b7995a878affefc3fa4a4b044c7723c16267a3 Mon Sep 17 00:00:00 2001 From: EWouters Date: Wed, 15 Mar 2017 02:40:39 +1300 Subject: [PATCH 10/37] Removed SERVER_NAME parameter because it is hardcoded as "server" in other scripts --- auto_install/install.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index ca7f2b9..f75d8c0 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -771,6 +771,8 @@ setClientDNS() { } confOpenVPN() { + SERVER_NAME="server" + if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ @@ -1021,7 +1023,7 @@ confOVPN() { finalExports() { # Update variables in setupVars.conf file if [ -e "${setupVars}" ]; then - sed -i.update.bak '/pivpnUser/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;/SERVER_NAME/d;' "${setupVars}" + sed -i.update.bak '/pivpnUser/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 "pivpnUser=${pivpnUser}" @@ -1037,7 +1039,6 @@ finalExports() { echo "PUBLICDNS=${PUBLICDNS}" echo "OVPNDNS1=${OVPNDNS1}" echo "OVPNDNS2=${OVPNDNS2}" - echo "SERVER_NAME=${SERVER_NAME}" }>> "${setupVars}" } @@ -1061,7 +1062,6 @@ finalExports() { # 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} -# #sed -i 's/SERVER_NAME/SERVER_NAME/g' ${setupVars} #} installPiVPN() { @@ -1073,7 +1073,6 @@ installPiVPN() { setCustomPort confOpenVPN confNetwork - SERVER_NAME="server" confOVPN setClientDNS finalExports From 27c34aa297d233c895c1fc7975e7e808aa883cfd Mon Sep 17 00:00:00 2001 From: EWouters Date: Wed, 15 Mar 2017 17:24:42 +1300 Subject: [PATCH 11/37] Removed -p flag to create home dir As described in #165 ( fc14664) it is not desirable. --- 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 f75d8c0..5890c41 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1016,7 +1016,7 @@ confOVPN() { # verify server name to strengthen security $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt - $SUDO mkdir -p "/home/$pivpnUser/ovpns" + $SUDO mkdir "/home/$pivpnUser/ovpns" $SUDO chmod 0777 -R "/home/$pivpnUser/ovpns" } From cd4d13691d3a4376b26f53415a25781c36b8c915 Mon Sep 17 00:00:00 2001 From: EWouters Date: Thu, 16 Mar 2017 22:25:17 +1300 Subject: [PATCH 12/37] fixed check for when both nopass and a password argument are passed to the script --- auto_install/install.sh | 2 +- scripts/makeOVPN.sh | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 5890c41..bdb09d2 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -772,7 +772,7 @@ setClientDNS() { confOpenVPN() { SERVER_NAME="server" - + if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index a42454a..00c59a7 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -168,10 +168,11 @@ fi cd /etc/openvpn/easy-rsa || exit if [[ "${NO_PASS}" =~ "1" ]]; then - keynoPASS -elif [[ -n "${PASSWD}" ]]; then - echo "Both nopass and password arguments passed to the script. Please use either one." - exit 1 + if [[ -n "${PASSWD}" ]]; then + echo "Both nopass and password arguments passed to the script. Please use either one." + exit 1 + else + keynoPASS else keyPASS fi From cb482d6697877e4d046c3da1104f511be1a1c3e2 Mon Sep 17 00:00:00 2001 From: EWouters Date: Thu, 16 Mar 2017 22:28:50 +1300 Subject: [PATCH 13/37] added fi to if-statement --- scripts/makeOVPN.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index 00c59a7..f1308f1 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -173,6 +173,7 @@ if [[ "${NO_PASS}" =~ "1" ]]; then exit 1 else keynoPASS + fi else keyPASS fi From ff97f40ecfcb52f3e6be4538e331fa43dd5e9d38 Mon Sep 17 00:00:00 2001 From: EWouters Date: Wed, 22 Mar 2017 13:47:55 +1300 Subject: [PATCH 14/37] =?UTF-8?q?Fix:=20mkdir:=20cannot=20create=20directo?= =?UTF-8?q?ry=20=E2=80=98/home/$pivpnUser/ovpns=E2=80=99:=20File=20exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_install/install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index bdb09d2..21367c1 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1016,7 +1016,9 @@ confOVPN() { # verify server name to strengthen security $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt - $SUDO mkdir "/home/$pivpnUser/ovpns" + if [ ! -d "/home/$pivpnUser/ovpns" ]; then + $SUDO mkdir "/home/$pivpnUser/ovpns" + fi $SUDO chmod 0777 -R "/home/$pivpnUser/ovpns" } From d5f0a81f80ee7f5ea7ebc877cb2be1a82ab08552 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Mon, 17 Apr 2017 15:49:52 +0200 Subject: [PATCH 15/37] Clearly indicate that a user selects a list item with the space bar. --- 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 21367c1..9707d16 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -173,7 +173,7 @@ chooseUser() { fi userArray+=("${line}" "" "${mode}") done <<< "${availableUsers}" - chooseUserCmd=(whiptail --title "Choose A User" --separate-output --radiolist "Choose:" ${r} ${c} ${numUsers}) + 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 @@ -251,7 +251,7 @@ 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}) + 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 @@ -615,7 +615,7 @@ update_repo() { 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. Please only choose TCP if you know why you need TCP." ${r} ${c} 2 \ + "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 @@ -674,7 +674,7 @@ setCustomPort() { } setClientDNS() { - DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider for your VPN Clients. 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 @@ -776,7 +776,7 @@ confOpenVPN() { if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ - "Choose your desired level of encryption:\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing or just want to get through it quicker you can use 1024. If you are paranoid about ... things... then grab a cup of joe and pick 4096." ${r} ${c} 3 \ + "Choose your desired level of encryption (press space to select):\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing or just want to get through it quicker you can use 1024. If you are paranoid about ... things... then grab a cup of joe and pick 4096." ${r} ${c} 3 \ "2048" "Use 2048-bit encryption. Recommended level." ON \ "1024" "Use 1024-bit encryption. Test level." OFF \ "4096" "Use 4096-bit encryption. Paranoid level." OFF 3>&1 1>&2 2>&3) @@ -970,7 +970,7 @@ confOVPN() { $SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt 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?" ${r} ${c} 2 \ + 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) From 2eb11cad0ced98482eaeccc042aa8d5f291ffb57 Mon Sep 17 00:00:00 2001 From: David Quattlebaum Date: Sun, 4 Jun 2017 16:18:26 -0400 Subject: [PATCH 16/37] changes for devuan - To simplify further additions to PLAT or OSCN, use the case command for checking - Treat Devuan as Debian - Add /sbin:/usr/sbin to PATH before calling ifconfig - Ensure net-tools is installed so we have ifconfig --- auto_install/install.sh | 195 ++++++++++++++++++++++------------------ 1 file changed, 110 insertions(+), 85 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 9707d16..35c809f 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -61,14 +61,14 @@ 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 jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +Currently this installer supports Raspbian (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). 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 } 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 this installer supports Raspbian jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +Currently this installer supports Raspbian (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). 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..." @@ -84,16 +84,23 @@ distro_check() { 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 - - if [[ $PLAT == "Ubuntu" || $PLAT == "Raspbian" || $PLAT == "Debian" ]]; then - if [[ $OSCN != "trusty" && $OSCN != "xenial" && $OSCN != "jessie" ]]; then - maybeOS_Support - fi - else + + case ${PLAT} in + Ubuntu|Raspbian|Debian|Devuan) + case ${OSCN} in + trusty|xenial|jessie) + ;; + *) + maybeOS_Support + ;; + esac + ;; + *) noOS_Support - fi + ;; + esac # else get info from os-release - elif grep -q debian /etc/os-release; then + elif grep -q -e debian -e devuan /etc/os-release; then if grep -q jessie /etc/os-release; then PLAT="Raspbian" OSCN="jessie" @@ -106,7 +113,7 @@ distro_check() { else noOS_Support fi - + echo "${PLAT}" > /tmp/DET_PLATFORM } @@ -355,6 +362,7 @@ setStaticIPv4() { setNetwork() { # Sets the Network IP and Mask correctly + export PATH=${PATH}:/sbin:/usr/sbin LOCALMASK=$(ifconfig "${pivpnInterface}" | awk '/Mask:/{ print $4;} ' | cut -c6-) LOCALIP=$(ifconfig "${pivpnInterface}" | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*') IFS=. read -r i1 i2 i3 i4 <<< "$LOCALIP" @@ -420,15 +428,19 @@ update_package_cache() { timestampAsDate=$(date -d @"${timestamp}" "+%b %e") today=$(date "+%b %e") - if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then - if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then - wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null - echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." - $SUDO apt-get -qq update & spinner $! - echo " done!" - fi - fi + case ${PLAT} in + Ubuntu|Debian|Devuan) + case ${OSCN} in + trusty|jessie|wheezy) + wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - + echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null + echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." + $SUDO apt-get -qq update & spinner $! + echo " done!" + ;; + esac + ;; + esac if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists @@ -489,11 +501,14 @@ stopServices() { # Stop openvpn $SUDO echo ":::" $SUDO echo -n "::: Stopping OpenVPN service..." - if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - $SUDO service openvpn stop || true - else - $SUDO systemctl stop openvpn.service || true - fi + case ${PLAT} in + Ubuntu|Debian|Devuan) + $SUDO service openvpn stop || true + ;; + *) + $SUDO systemctl stop openvpn.service || true + ;; + esac $SUDO echo " done." } @@ -509,15 +524,19 @@ checkForDependencies() { timestampAsDate=$(date -d @"$timestamp" "+%b %e") today=$(date "+%b %e") - if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" ]]; then - wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null - echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." - $SUDO apt-get -qq update & spinner $! - echo " done!" - fi - fi + case ${PLAT} in + Ubuntu|Debian|Devuan) + case ${OSCN} in + trusty|jessie|wheezy) + wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - + echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null + echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." + $SUDO apt-get -qq update & spinner $! + echo " done!" + ;; + esac + ;; + esac if [ ! "$today" == "$timestampAsDate" ]; then #update package lists @@ -541,7 +560,7 @@ checkForDependencies() { echo ":::" echo "::: Checking dependencies:" - dependencies=( openvpn git dhcpcd5 tar wget grep iptables-persistent dnsutils expect whiptail ) + dependencies=( openvpn git dhcpcd5 tar wget grep iptables-persistent dnsutils expect whiptail net-tools) for i in "${dependencies[@]}"; do echo -n "::: Checking for $i..." if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then @@ -772,7 +791,7 @@ setClientDNS() { confOpenVPN() { SERVER_NAME="server" - + if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ @@ -780,7 +799,7 @@ confOpenVPN() { "2048" "Use 2048-bit encryption. Recommended level." ON \ "1024" "Use 1024-bit encryption. Test level." OFF \ "4096" "Use 4096-bit encryption. Paranoid level." OFF 3>&1 1>&2 2>&3) - + exitstatus=$? if [ $exitstatus != 0 ]; then echo "::: Cancel selected. Exiting..." @@ -831,7 +850,7 @@ EOF if [[ ${useUpdateVars} == false ]]; then whiptail --msgbox --backtitle "Setup OpenVPN" --title "Server Information" "The server key, Diffie-Hellman key, and HMAC key will now be generated." ${r} ${c} fi - + # Build the server ${SUDOE} ./easyrsa build-server-full server nopass @@ -843,7 +862,7 @@ EOF DOWNLOAD_DH_PARAM=false fi fi - + if [ "$ENCRYPT" -ge "4096" ] && [[ ${DOWNLOAD_DH_PARAM} == true ]] then # Downloading parameters @@ -938,11 +957,14 @@ confNetwork() { if [[ $noUFW -eq 1 ]]; then echo 1 > /tmp/noUFW $SUDO iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o "$IPv4dev" -j MASQUERADE - if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - $SUDO iptables-save | $SUDO tee /etc/iptables/rules.v4 > /dev/null - else - $SUDO netfilter-persistent save - 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 @@ -973,13 +995,13 @@ confOVPN() { 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) - + exitstatus=$? if [ $exitstatus != 0 ]; then echo "::: Cancel selected. Exiting..." exit 1 fi - + if [ "$METH" == "$IPv4pub" ]; then $SUDO sed -i 's/IPv4pub/'"$IPv4pub"'/' /etc/openvpn/easy-rsa/pki/Default.txt else @@ -1085,20 +1107,20 @@ updatePiVPN() { stopServices confUnattendedUpgrades installScripts - + # setCustomProto # write out the PROTO PROTO=$pivpnProto $SUDO cp /tmp/pivpnPROTO /etc/pivpn/INSTALL_PROTO - + #setCustomPort # write out the port $SUDO cp /tmp/INSTALL_PORT /etc/pivpn/INSTALL_PORT - + 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 @@ -1133,12 +1155,12 @@ update_dialogs() { 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." @@ -1184,10 +1206,10 @@ main() { exit 1 fi fi - + # Check for supported distribution distro_check - + # Check arguments for the undocumented flags for var in "$@"; do case "$var" in @@ -1196,7 +1218,7 @@ main() { "--unattended" ) runUnattended=true;; esac done - + if [[ -f ${setupVars} ]]; then if [[ "${runUnattended}" == true ]]; then echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" @@ -1205,7 +1227,7 @@ main() { update_dialogs fi fi - + # Start the installer # Verify there is enough disk space for the install if [[ "${skipSpaceCheck}" == true ]]; then @@ -1213,24 +1235,24 @@ main() { else verifyFreeDiskSpace fi - + # Install the packages (we do this first because we need whiptail) #checkForDependencies update_package_cache - + # Notify user of package availability notify_package_updates_available - + # Install packages used by this installation script install_dependent_packages PIVPN_DEPS[@] - + if [[ ${useUpdateVars} == false ]]; then # Display welcome dialogs welcomeDialogs - + # Find interfaces and let the user choose one chooseInterface - + # Only try to set static on Raspbian, otherwise let user do it if [[ $PLAT != "Raspbian" ]]; then avoidStaticIPv4Ubuntu @@ -1238,27 +1260,27 @@ main() { getStaticIPv4Settings setStaticIPv4 fi - + # Set the Network IP and Mask correctly setNetwork - + # Choose the user for the ovpns chooseUser - + # Ask if unattended-upgrades will be enabled unattendedUpgrades - + # Clone/Update the repos clone_or_update_repos - + # Install and log everything to a file installPiVPN | tee ${tmpLog} - + echo "::: Install Complete..." else # Source ${setupVars} for use in the rest of the functions. source ${setupVars} - + echo "::: Using IP address: $IPv4addr" echo "${IPv4addr%/*}" > /tmp/pivpnIP echo "::: Using interface: $pivpnInterface" @@ -1270,7 +1292,7 @@ main() { echo "::: Using port: $PORT" echo ${PORT} > /tmp/INSTALL_PORT echo ":::" - + # Only try to set static on Raspbian if [[ $PLAT != "Raspbian" ]]; then echo "::: IP Information" @@ -1280,32 +1302,35 @@ main() { else 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 fi - + # Clone/Update the repos clone_or_update_repos - - + + updatePiVPN | tee ${tmpLog} fi - + #Move the install log into /etc/pivpn for storage $SUDO mv ${tmpLog} ${instalLogLoc} - + echo "::: Restarting services..." # Start services - if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - $SUDO service openvpn start - else - $SUDO systemctl enable openvpn.service - $SUDO systemctl start openvpn.service - fi - + case ${PLAT} in + Ubuntu|Debian|Devuan) + $SUDO service openvpn start + ;; + *) + $SUDO systemctl enable openvpn.service + $SUDO systemctl start openvpn.service + ;; + esac + echo "::: done." - + if [[ "${useUpdateVars}" == false ]]; then displayFinalMessage fi - + echo ":::" if [[ "${useUpdateVars}" == false ]]; then echo "::: Installation Complete!" @@ -1315,7 +1340,7 @@ main() { else echo "::: Update complete!" fi - + echo ":::" echo "::: The install log is located at: ${instalLogLoc}" } From 5c4a51b69548ac96f9171baef5a7fba46f718bae Mon Sep 17 00:00:00 2001 From: David Quattlebaum Date: Tue, 6 Jun 2017 18:27:23 -0400 Subject: [PATCH 17/37] Final testing passed Changes: - Document that Devuan is supported. - Use special PLAT name, Raspvuan for Pi version - Use service command for any *vuan PLAT, systemd is no on any Devuan. - add net-tools to PIVPN_DEPS --- auto_install/install.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 35c809f..33ca2a4 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -24,7 +24,7 @@ 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 dhcpcd5 tar wget grep iptables-persistent dnsutils expect whiptail ) +PIVPN_DEPS=( openvpn git dhcpcd5 tar wget grep iptables-persistent dnsutils expect whiptail net-tools) ### ### pivpnGitUrl="https://github.com/pivpn/pivpn.git" @@ -100,7 +100,14 @@ distro_check() { ;; esac # else get info from os-release - elif grep -q -e debian -e devuan /etc/os-release; then + elif grep -q devuan /etc/os-release; then + if grep -q jessie /etc/os-release; then + PLAT="Raspvuan" + OSCN="jessie" + else + noOS_Support + fi + elif grep -q debian /etc/os-release; then if grep -q jessie /etc/os-release; then PLAT="Raspbian" OSCN="jessie" @@ -502,7 +509,7 @@ stopServices() { $SUDO echo ":::" $SUDO echo -n "::: Stopping OpenVPN service..." case ${PLAT} in - Ubuntu|Debian|Devuan) + Ubuntu|Debian|*vuan) $SUDO service openvpn stop || true ;; *) @@ -1294,14 +1301,17 @@ main() { echo ":::" # Only try to set static on Raspbian - if [[ $PLAT != "Raspbian" ]]; then + 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." - else - 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 - fi + ;; + esac # Clone/Update the repos clone_or_update_repos @@ -1316,7 +1326,7 @@ main() { echo "::: Restarting services..." # Start services case ${PLAT} in - Ubuntu|Debian|Devuan) + Ubuntu|Debian|*vuan) $SUDO service openvpn start ;; *) From 5ff6f2315367bd3d20ff590eaadbaf8fe06c6d98 Mon Sep 17 00:00:00 2001 From: Erich Ellsworth Date: Sat, 22 Jul 2017 19:25:18 -0500 Subject: [PATCH 18/37] Fixed links in README.md on lines 156 and 158 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d290393..3f3f023 100644 --- a/README.md +++ b/README.md @@ -153,9 +153,9 @@ sources. 2. And the code at [pi-hole.net](https://github.com/pi-hole/pi-hole) -3. Of course there is [OpenVPN] (https://openvpn.net) +3. Of course there is [OpenVPN](https://openvpn.net) -4. And as always the ever vigilant [EFF] (https://www.eff.org/) +4. And as always the ever vigilant [EFF](https://www.eff.org/) I don't take donations at this time but if you want to show your appreciation to me, then contribute or leave feedback on suggestions or improvements. From da9e082f431bcb13198bea656b70b6f6ed6add20 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Wed, 20 Sep 2017 22:42:29 -0500 Subject: [PATCH 19/37] Changed the default length of the Diffie-Hellman parameters to 2048 bits. This is the default everywhere else, both in documentation as well as menu selections and other scripts in this project. This change has no real impact aside from setting the right example. --- server_config.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_config.txt b/server_config.txt index 70625e7..602dea7 100644 --- a/server_config.txt +++ b/server_config.txt @@ -4,7 +4,7 @@ port 1194 ca /etc/openvpn/easy-rsa/pki/ca.crt cert /etc/openvpn/easy-rsa/pki/issued/server.crt key /etc/openvpn/easy-rsa/pki/private/server.key -dh /etc/openvpn/easy-rsa/pki/dh1024.pem +dh /etc/openvpn/easy-rsa/pki/dh2048.pem topology subnet server 10.8.0.0 255.255.255.0 # server and remote endpoints From 7cf5c19789cd1eae2f52023b0f041be89ee6e47e Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Wed, 20 Sep 2017 23:24:57 -0500 Subject: [PATCH 20/37] Changed the display order of the DH options (default value is still 2048 bits) and added a warning for 1024 bits. --- auto_install/install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 33ca2a4..8460db8 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -802,10 +802,10 @@ confOpenVPN() { if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ - "Choose your desired level of encryption (press space to select):\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing or just want to get through it quicker you can use 1024. If you are paranoid about ... things... then grab a cup of joe and pick 4096." ${r} ${c} 3 \ - "2048" "Use 2048-bit encryption. Recommended level." ON \ - "1024" "Use 1024-bit encryption. Test level." OFF \ - "4096" "Use 4096-bit encryption. Paranoid level." OFF 3>&1 1>&2 2>&3) + "Choose your desired level of encryption (press space to select):\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing, you can use 1024 bit 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." ${r} ${c} 3 \ + "1024" "Use 1024-bit encryption (testing only)." OFF \ + "2048" "Use 2048-bit encryption (recommended level)." ON \ + "4096" "Use 4096-bit encryption (paranoid level)." OFF 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus != 0 ]; then From d1652a03b139496ce565dddd5e979e69ec523903 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Thu, 21 Sep 2017 14:39:16 -0500 Subject: [PATCH 21/37] The SERVER_NAME variable is used in a 'verify-x509-name' check to allow the client to verify it is talking to the correct server. However, its value was always equal to 'server'. This wasn't unique for each installation and therefore provided no additional safety check. So I've modified it to be random for each installation of PiVPN. Additionally, the variable is now actually being used when specifying the server name in the build-server-full command. Source for obtaining a random UUID (thank you): Earthgecko (https://gist.github.com/earthgecko/3089509) --- auto_install/install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 33ca2a4..1554923 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -797,7 +797,9 @@ setClientDNS() { } confOpenVPN() { - SERVER_NAME="server" + # Generate a random, alphanumeric identifier of 16 characters for this server so that we can use verify-x509-name later that is unique for this server installation. Source: Earthgecko (https://gist.github.com/earthgecko/3089509) + NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) + SERVER_NAME="server_${NEW_UUID}" if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption @@ -859,7 +861,7 @@ EOF fi # Build the server - ${SUDOE} ./easyrsa build-server-full server nopass + ${SUDOE} ./easyrsa build-server-full ${SERVER_NAME} nopass if [[ ${useUpdateVars} == 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 a pool of the last 128 generated.\nMore information about this service can be found here: https://2ton.com.au/dhtool/\n\nIf you're paranoid, choose 'No' and Diffie-Hellman parameters will be generated on your device." ${r} ${c}) From 05c6a3715261070ea8db8b9407256a12f37125dd Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Thu, 21 Sep 2017 23:06:02 -0500 Subject: [PATCH 22/37] Removed the duplicate-cn option so every device/connection must use a unique certificate. --- server_config.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/server_config.txt b/server_config.txt index 70625e7..0f36d38 100644 --- a/server_config.txt +++ b/server_config.txt @@ -23,7 +23,6 @@ push "dhcp-option DNS 8.8.4.4" # overriding but not wiping out the original default gateway. push "redirect-gateway def1" client-to-client -duplicate-cn keepalive 10 120 tls-version-min 1.2 tls-auth /etc/openvpn/easy-rsa/pki/ta.key 0 From 8910545d909703fc7d5e8c68c1f8b6a9e3848327 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Fri, 22 Sep 2017 02:17:53 -0500 Subject: [PATCH 23/37] Fixed a couple of typos. --- 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 8460db8..23122e5 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -801,8 +801,8 @@ confOpenVPN() { if [[ ${useUpdateVars} == false ]]; then # Ask user for desired level of encryption - ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption Strength" --radiolist \ - "Choose your desired level of encryption (press space to select):\n This is an encryption key that will be generated on your system. The larger the key, the more time this will take. For most applications it is recommended to use 2048 bit. If you are testing, you can use 1024 bit 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." ${r} ${c} 3 \ + ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption strength" --radiolist \ + "Choose your desired level of encryption (press space to select):\n This is an encryption key that will be generated on your system. The larger the key, 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 1024-bit encryption (testing only)." OFF \ "2048" "Use 2048-bit encryption (recommended level)." ON \ "4096" "Use 4096-bit encryption (paranoid level)." OFF 3>&1 1>&2 2>&3) From 30920115b3d3f7df3b60a9cdc3826c83176ebaa9 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Fri, 22 Sep 2017 02:46:52 -0500 Subject: [PATCH 24/37] Implemented that a Certificate Revocation List is generated during installation after generation of other Public Key Infrastructure. Enabled this CRL in the server config. The added benefit of this is that whenever the user now revokes a client, the change is instant. Whereas before, the first time a client was revoked, the OpenVPN server had to be restarted to enabled the then-newly-generated CRL. This change also makes the file /etc/pivpn/REVOKE_STATUS obsolete. Documentation: https://openvpn.net/index.php/open-source/documentation/howto.html#revoke --- auto_install/install.sh | 9 +++++---- scripts/removeOVPN.sh | 16 ---------------- server_config.txt | 2 +- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 33ca2a4..7783986 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -884,6 +884,11 @@ EOF # Generate static HMAC key to defend against DDoS ${SUDOE} openvpn --genkey --secret pki/ta.key + # Generate an empty Certificate Revocation List + ${SUDOE} ./easyrsa gen-crl + cp pki/crl.pem /etc/openvpn/crl.pem + chown nobody:nogroup /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 @@ -992,10 +997,6 @@ confOVPN() { $SUDO cp /tmp/pivpnUSR /etc/pivpn/INSTALL_USER $SUDO cp /tmp/DET_PLATFORM /etc/pivpn/DET_PLATFORM - # Set status that no certs have been revoked - echo 0 > /tmp/REVOKE_STATUS - $SUDO cp /tmp/REVOKE_STATUS /etc/pivpn/REVOKE_STATUS - $SUDO cp /etc/.pivpn/Default.txt /etc/openvpn/easy-rsa/pki/Default.txt if [[ ${useUpdateVars} == false ]]; then diff --git a/scripts/removeOVPN.sh b/scripts/removeOVPN.sh index 4e3515c..3200a55 100644 --- a/scripts/removeOVPN.sh +++ b/scripts/removeOVPN.sh @@ -105,22 +105,6 @@ fi cd /etc/openvpn/easy-rsa || exit -if [ "${REVOKE_STATUS}" == 0 ]; then - echo 1 > /etc/pivpn/REVOKE_STATUS - printf "\nThis seems to be the first time you have revoked a cert.\n" - printf "First we need to initialize the Certificate Revocation List.\n" - printf "Then add the CRL to your server config and restart openvpn.\n" - ./easyrsa gen-crl - cp pki/crl.pem /etc/openvpn/crl.pem - chown nobody:nogroup /etc/openvpn/crl.pem - sed -i '/#crl-verify/c\crl-verify /etc/openvpn/crl.pem' /etc/openvpn/server.conf - if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then - service openvpn restart - else - systemctl restart openvpn.service - fi -fi - 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]}" diff --git a/server_config.txt b/server_config.txt index 70625e7..035a3ed 100644 --- a/server_config.txt +++ b/server_config.txt @@ -34,7 +34,7 @@ user nobody group nogroup persist-key persist-tun -#crl-verify /etc/openvpn/crl.pem +crl-verify /etc/openvpn/crl.pem status /var/log/openvpn-status.log 20 status-version 3 log /var/log/openvpn.log From a6058a1d14160dfd038fed90bd355865bf1b27b8 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Fri, 22 Sep 2017 03:30:14 -0500 Subject: [PATCH 25/37] The client config contains the remote-cert-tls option to check for appropriate key usage, let's do this for the server config too. --- server_config.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/server_config.txt b/server_config.txt index 70625e7..dd56b71 100644 --- a/server_config.txt +++ b/server_config.txt @@ -25,6 +25,7 @@ push "redirect-gateway def1" client-to-client duplicate-cn keepalive 10 120 +remote-cert-tls client tls-version-min 1.2 tls-auth /etc/openvpn/easy-rsa/pki/ta.key 0 cipher AES-256-CBC From 7b6a35877907a4c24441234d3adefd89528fd407 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Fri, 22 Sep 2017 14:11:23 -0500 Subject: [PATCH 26/37] Modified the messages when PiVPN installation completes and client profiles are generated, so the user knows to generate a client profile per each device he/she wants to connect to the VPN with. --- auto_install/install.sh | 2 +- scripts/makeOVPN.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 33ca2a4..24d2877 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1344,7 +1344,7 @@ main() { echo ":::" if [[ "${useUpdateVars}" == false ]]; then echo "::: Installation Complete!" - echo "::: Now run 'pivpn add' to create the ovpn profiles." + 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 diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index f1308f1..d9101f3 100644 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -240,5 +240,6 @@ printf "========================================================\n" printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME$FILEEXT" printf "%s was copied to:\n" "$NAME$FILEEXT" printf " /home/%s/ovpns\n" "$INSTALL_USER" -printf "for easy transfer.\n" +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" From 077996cfb48dd23fe00415fd800c31889c61233c Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Sat, 23 Sep 2017 11:21:26 -0500 Subject: [PATCH 27/37] Removed an obsolete variable. --- scripts/removeOVPN.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/removeOVPN.sh b/scripts/removeOVPN.sh index 3200a55..6bf0610 100644 --- a/scripts/removeOVPN.sh +++ b/scripts/removeOVPN.sh @@ -2,7 +2,6 @@ # PiVPN: revoke client script INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) -REVOKE_STATUS=$(cat /etc/pivpn/REVOKE_STATUS) PLAT=$(cat /etc/pivpn/DET_PLATFORM) INDEX="/etc/openvpn/easy-rsa/pki/index.txt" From f5c05715de2e1a6bd389cac56b63ad91ad9c8e39 Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Sat, 23 Sep 2017 14:35:46 -0500 Subject: [PATCH 28/37] Added sudo -E. --- 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 7783986..4ecf624 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -886,8 +886,8 @@ EOF # Generate an empty Certificate Revocation List ${SUDOE} ./easyrsa gen-crl - cp pki/crl.pem /etc/openvpn/crl.pem - chown nobody:nogroup /etc/openvpn/crl.pem + ${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem + ${SUDOE} chown nobody:nogroup /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 c81e793c6ce780b06984168b7db244684ab73c1f Mon Sep 17 00:00:00 2001 From: Jelle Dekker Date: Sat, 23 Sep 2017 15:16:06 -0500 Subject: [PATCH 29/37] Removed punctuation in list items. --- 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 23122e5..cb41800 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -803,9 +803,9 @@ confOpenVPN() { # Ask user for desired level of encryption ENCRYPT=$(whiptail --backtitle "Setup OpenVPN" --title "Encryption strength" --radiolist \ "Choose your desired level of encryption (press space to select):\n This is an encryption key that will be generated on your system. The larger the key, 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 1024-bit encryption (testing only)." OFF \ - "2048" "Use 2048-bit encryption (recommended level)." ON \ - "4096" "Use 4096-bit encryption (paranoid level)." OFF 3>&1 1>&2 2>&3) + "1024" "Use 1024-bit encryption (testing only)" OFF \ + "2048" "Use 2048-bit encryption (recommended level)" ON \ + "4096" "Use 4096-bit encryption (paranoid level)" OFF 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus != 0 ]; then From 2626127be18fca41802fa009453877cb6d0544e6 Mon Sep 17 00:00:00 2001 From: cfcolaco Date: Sun, 8 Oct 2017 12:54:24 +0100 Subject: [PATCH 30/37] Added support to Stretch, Fixed some texts, Removed some lines for testing pruposes --- auto_install/install.sh | 68 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 9c580a0..fcfde96 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -61,14 +61,14 @@ 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 (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +Currently this installer supports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). 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 } 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 this installer supports Raspbian (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +Currently this installer ssupports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). 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..." @@ -88,7 +88,7 @@ distro_check() { case ${PLAT} in Ubuntu|Raspbian|Debian|Devuan) case ${OSCN} in - trusty|xenial|jessie) + trusty|xenial|jessie|stretch) ;; *) maybeOS_Support @@ -111,6 +111,9 @@ distro_check() { if grep -q jessie /etc/os-release; then PLAT="Raspbian" OSCN="jessie" + elif grep -q stretch /etc/os-release; then + PLAT="Raspbian" + OSCN="stretch" else PLAT="Ubuntu" OSCN="unknown" @@ -435,31 +438,33 @@ update_package_cache() { timestampAsDate=$(date -d @"${timestamp}" "+%b %e") today=$(date "+%b %e") -<<<<<<< HEAD - case ${PLAT} in - Ubuntu|Debian|Devuan) - case ${OSCN} in - trusty|jessie|wheezy) - wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null - echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." - $SUDO apt-get -qq update & spinner $! - echo " done!" - ;; - esac - ;; - esac -======= - if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then - if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then - wget -O - 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 apt-get -qq update & spinner $! - echo " done!" - fi - fi ->>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a +#### REMOVE IF TESTING WORKS ##### +#<<<<<<< HEAD +# case ${PLAT} in +# Ubuntu|Debian|Devuan) +# case ${OSCN} in +# trusty|jessie|wheezy) +# wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - +# echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null +# echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." +# $SUDO apt-get -qq update & spinner $! +# echo " done!" +# ;; +# esac +# ;; +# esac +#======= +# if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then +# if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then +# wget -O - 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 apt-get -qq update & spinner $! +# echo " done!" +# fi +# fi +#>>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a +##### REMOVE UNTIL THIS POINT###### if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists @@ -543,11 +548,10 @@ checkForDependencies() { timestampAsDate=$(date -d @"$timestamp" "+%b %e") today=$(date "+%b %e") -<<<<<<< HEAD case ${PLAT} in Ubuntu|Debian|Devuan) case ${OSCN} in - trusty|jessie|wheezy) + trusty|jessie|wheezy|stretch) wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." @@ -557,9 +561,8 @@ checkForDependencies() { esac ;; esac -======= if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" ]]; then + if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" || $OSCN == "stretch" ]]; then wget -O - 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 ..." @@ -567,7 +570,6 @@ checkForDependencies() { echo " done!" fi fi ->>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a if [ ! "$today" == "$timestampAsDate" ]; then #update package lists From 6e8d6d24b51c1bc8a7316428ca81fcd59e960803 Mon Sep 17 00:00:00 2001 From: cfcolaco Date: Sun, 8 Oct 2017 13:08:57 +0100 Subject: [PATCH 31/37] Revert "Added support to Stretch, Fixed some texts, Removed some lines for testing pruposes" This reverts commit 2626127be18fca41802fa009453877cb6d0544e6. --- auto_install/install.sh | 68 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index fcfde96..9c580a0 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -61,14 +61,14 @@ 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, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). +Currently this installer supports Raspbian (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). 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 } 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 this installer ssupports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). +Currently this installer supports Raspbian (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). 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..." @@ -88,7 +88,7 @@ distro_check() { case ${PLAT} in Ubuntu|Raspbian|Debian|Devuan) case ${OSCN} in - trusty|xenial|jessie|stretch) + trusty|xenial|jessie) ;; *) maybeOS_Support @@ -111,9 +111,6 @@ distro_check() { if grep -q jessie /etc/os-release; then PLAT="Raspbian" OSCN="jessie" - elif grep -q stretch /etc/os-release; then - PLAT="Raspbian" - OSCN="stretch" else PLAT="Ubuntu" OSCN="unknown" @@ -438,33 +435,31 @@ update_package_cache() { timestampAsDate=$(date -d @"${timestamp}" "+%b %e") today=$(date "+%b %e") -#### REMOVE IF TESTING WORKS ##### -#<<<<<<< HEAD -# case ${PLAT} in -# Ubuntu|Debian|Devuan) -# case ${OSCN} in -# trusty|jessie|wheezy) -# wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - -# echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null -# echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." -# $SUDO apt-get -qq update & spinner $! -# echo " done!" -# ;; -# esac -# ;; -# esac -#======= -# if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then -# if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then -# wget -O - 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 apt-get -qq update & spinner $! -# echo " done!" -# fi -# fi -#>>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a -##### REMOVE UNTIL THIS POINT###### +<<<<<<< HEAD + case ${PLAT} in + Ubuntu|Debian|Devuan) + case ${OSCN} in + trusty|jessie|wheezy) + wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - + echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null + echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." + $SUDO apt-get -qq update & spinner $! + echo " done!" + ;; + esac + ;; + esac +======= + if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then + if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then + wget -O - 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 apt-get -qq update & spinner $! + echo " done!" + fi + fi +>>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists @@ -548,10 +543,11 @@ checkForDependencies() { timestampAsDate=$(date -d @"$timestamp" "+%b %e") today=$(date "+%b %e") +<<<<<<< HEAD case ${PLAT} in Ubuntu|Debian|Devuan) case ${OSCN} in - trusty|jessie|wheezy|stretch) + trusty|jessie|wheezy) wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." @@ -561,8 +557,9 @@ checkForDependencies() { esac ;; esac +======= if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" || $OSCN == "stretch" ]]; then + if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" ]]; then wget -O - 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 ..." @@ -570,6 +567,7 @@ checkForDependencies() { echo " done!" fi fi +>>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a if [ ! "$today" == "$timestampAsDate" ]; then #update package lists From 29a5dbb22b773f8093497126d13a86d7e1bbfbe1 Mon Sep 17 00:00:00 2001 From: cfcolaco Date: Sun, 8 Oct 2017 13:19:01 +0100 Subject: [PATCH 32/37] Revert "Revert "Added support to Stretch, Fixed some texts, Removed some lines for testing pruposes"" This reverts commit 6e8d6d24b51c1bc8a7316428ca81fcd59e960803. --- auto_install/install.sh | 68 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index 9c580a0..fcfde96 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -61,14 +61,14 @@ 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 (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +Currently this installer supports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). 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 } 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 this installer supports Raspbian (or Devuan) jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial). +Currently this installer ssupports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). 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..." @@ -88,7 +88,7 @@ distro_check() { case ${PLAT} in Ubuntu|Raspbian|Debian|Devuan) case ${OSCN} in - trusty|xenial|jessie) + trusty|xenial|jessie|stretch) ;; *) maybeOS_Support @@ -111,6 +111,9 @@ distro_check() { if grep -q jessie /etc/os-release; then PLAT="Raspbian" OSCN="jessie" + elif grep -q stretch /etc/os-release; then + PLAT="Raspbian" + OSCN="stretch" else PLAT="Ubuntu" OSCN="unknown" @@ -435,31 +438,33 @@ update_package_cache() { timestampAsDate=$(date -d @"${timestamp}" "+%b %e") today=$(date "+%b %e") -<<<<<<< HEAD - case ${PLAT} in - Ubuntu|Debian|Devuan) - case ${OSCN} in - trusty|jessie|wheezy) - wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null - echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." - $SUDO apt-get -qq update & spinner $! - echo " done!" - ;; - esac - ;; - esac -======= - if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then - if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then - wget -O - 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 apt-get -qq update & spinner $! - echo " done!" - fi - fi ->>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a +#### REMOVE IF TESTING WORKS ##### +#<<<<<<< HEAD +# case ${PLAT} in +# Ubuntu|Debian|Devuan) +# case ${OSCN} in +# trusty|jessie|wheezy) +# wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - +# echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null +# echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." +# $SUDO apt-get -qq update & spinner $! +# echo " done!" +# ;; +# esac +# ;; +# esac +#======= +# if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then +# if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then +# wget -O - 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 apt-get -qq update & spinner $! +# echo " done!" +# fi +# fi +#>>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a +##### REMOVE UNTIL THIS POINT###### if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists @@ -543,11 +548,10 @@ checkForDependencies() { timestampAsDate=$(date -d @"$timestamp" "+%b %e") today=$(date "+%b %e") -<<<<<<< HEAD case ${PLAT} in Ubuntu|Debian|Devuan) case ${OSCN} in - trusty|jessie|wheezy) + trusty|jessie|wheezy|stretch) wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." @@ -557,9 +561,8 @@ checkForDependencies() { esac ;; esac -======= if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then - if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" ]]; then + if [[ $OSCN == "trusty" || $OSCN == "jessie" || $OSCN == "wheezy" || $OSCN == "stretch" ]]; then wget -O - 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 ..." @@ -567,7 +570,6 @@ checkForDependencies() { echo " done!" fi fi ->>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a if [ ! "$today" == "$timestampAsDate" ]; then #update package lists From c1918417d60881391fee52fff1546e55d2f6ca1a Mon Sep 17 00:00:00 2001 From: cfcolaco Date: Sun, 8 Oct 2017 18:27:43 +0100 Subject: [PATCH 33/37] added support to Stretch, removed useless code, added info about stretch support --- auto_install/install.sh | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index fcfde96..95d3187 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -438,33 +438,6 @@ update_package_cache() { timestampAsDate=$(date -d @"${timestamp}" "+%b %e") today=$(date "+%b %e") -#### REMOVE IF TESTING WORKS ##### -#<<<<<<< HEAD -# case ${PLAT} in -# Ubuntu|Debian|Devuan) -# case ${OSCN} in -# trusty|jessie|wheezy) -# wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - -# echo "deb http://swupdate.openvpn.net/apt $OSCN main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null -# echo -n "::: Adding OpenVPN repo for $PLAT $OSCN ..." -# $SUDO apt-get -qq update & spinner $! -# echo " done!" -# ;; -# esac -# ;; -# esac -#======= -# if [[ ${PLAT} == "Ubuntu" || ${PLAT} == "Debian" ]]; then -# if [[ ${OSCN} == "trusty" || ${OSCN} == "jessie" || ${OSCN} == "wheezy" ]]; then -# wget -O - 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 apt-get -qq update & spinner $! -# echo " done!" -# fi -# fi -#>>>>>>> 454b755116d8cad6b67b56ac15a7235ceac02b5a -##### REMOVE UNTIL THIS POINT###### if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists From 664087bf92e6c631e9c009ad15e6960a8d041863 Mon Sep 17 00:00:00 2001 From: cfcolaco Date: Sun, 8 Oct 2017 19:47:30 +0100 Subject: [PATCH 34/37] fixed 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 95d3187..0238527 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -68,7 +68,7 @@ If you think you received this message in error, you can post an issue on the Gi 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 this installer ssupports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). +Currently this installer supports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). 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..." From 89a928e7c411e3a1b8e1a7e76f0207ee1efb30ef Mon Sep 17 00:00:00 2001 From: cfcolaco Date: Sun, 8 Oct 2017 20:10:57 +0100 Subject: [PATCH 35/37] fixed (more) Typos and sentences --- 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 0238527..7d32278 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -61,14 +61,14 @@ 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, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). +Currently this installer supports Raspbian and Debian (Jessie and Stretch), Devuan (Jessie) and Ubuntu from 14.04 (trusty) to 17.04 (zesty). 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 } 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 this installer supports Raspbian, Debian or Devuan jessie and stretch and Ubuntu from 14.04 (trusty) to 17.04 (zetsy). +Currently this installer supports Raspbian and Debian (Jessie and Stretch), Devuan (Jessie) and Ubuntu from 14.04 (trusty) to 17.04 (zesty). 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..." From 862cb41d60f9fdf3e4ca8b05f6627d5f2fb3fc4b Mon Sep 17 00:00:00 2001 From: azlux Date: Mon, 9 Oct 2017 16:45:32 +0200 Subject: [PATCH 36/37] Add humain readable values --- scripts/clientStat.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/clientStat.sh b/scripts/clientStat.sh index 834b0dd..c14e030 100644 --- a/scripts/clientStat.sh +++ b/scripts/clientStat.sh @@ -15,7 +15,15 @@ printf "\e[1m::: Client Status List :::\e[0m\n" printf "\t\t\t\t\t\t\tBytes\t\tBytes\t\n" printf "\e[4mName\e[0m\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 - 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}' ${STATUS_LOG} + 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" ${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}' ${STATUS_LOG} + fi else printf "\nNo Clients Connected!\n" fi From b0d208599650a00fdd14d92e53cfe13d4050fdb3 Mon Sep 17 00:00:00 2001 From: azlux Date: Tue, 10 Oct 2017 01:15:03 +0200 Subject: [PATCH 37/37] make the humain-readable a function I forgot the function ! --- scripts/clientStat.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/clientStat.sh b/scripts/clientStat.sh index c14e030..6a5ff97 100644 --- a/scripts/clientStat.sh +++ b/scripts/clientStat.sh @@ -2,6 +2,11 @@ # 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!"