mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
Merge branch 'test' into test
This commit is contained in:
commit
ba3bf24d89
13 changed files with 562 additions and 331 deletions
154
README.md
154
README.md
|
@ -1,17 +1,19 @@
|
|||
![WireGuard + OpenVPN logo](logos.jpg)
|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
Visit the [PiVPN](https://pivpn.dev) site for more information.
|
||||
This is a set of shell scripts initially developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM)
|
||||
into a VPN server using two free, open-source protocols:
|
||||
* [Wireguard](https://www.wireguard.com/)
|
||||
* [WireGuard](https://www.wireguard.com/)
|
||||
* [OpenVPN](https://openvpn.net)
|
||||
|
||||
Have you been looking for a good guide or tutorial for installing openvpn on a raspberry pi or ubuntu based server?
|
||||
Have you been looking for a good guide or tutorial for setting up a VPN server on a Raspberry Pi or Ubuntu based server?
|
||||
Run this script and you don't need a guide or tutorial, this will do it all for you, in a fraction of the time and with hardened security settings in place by default.
|
||||
|
||||
The master branch of this script installs and configures either Wireguard or OpenVPN on Raspbian, Debian or Ubuntu and it as been tested to run not only on Raspberry pi but also in any Cloud Provider VPS.
|
||||
We recommend using the Latest Raspbian lite image on a raspberry pi in your home so you can VPN into your home from a unsecure remote locations and safely use the internet.
|
||||
The master branch of this script installs and configures either WireGuard or OpenVPN on Raspbian, Debian or Ubuntu and it as been tested to run not only on Raspberry Pi but also in any Cloud Provider VPS.
|
||||
We recommend using the latest Raspbian Lite image on a Raspberry Pi in your home so you can VPN into your home from a unsecure remote locations and safely use the internet.
|
||||
However, the scripts do try to detect different distributions and make adjustments accordingly.
|
||||
They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables.
|
||||
|
||||
|
@ -21,7 +23,7 @@ Followed by easy management of the VPN thereafter with the 'pivpn' command.
|
|||
That being said...
|
||||
|
||||
> This will also work on a free-tier Amazon AWS server using Ubuntu or Debian. I don't want to support every scenario there but getting it to run and install successfully on a free server in the cloud was also important.
|
||||
Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the amazon infrastructure.
|
||||
Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the Amazon infrastructure.
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
@ -66,51 +68,57 @@ sudo sh pivpn/auto_install/install.sh
|
|||
```
|
||||
|
||||
**OBS:**
|
||||
in alternative to install.pivpn.dev you can use the raw github link:
|
||||
In alternative to install.pivpn.dev you can use the raw github link:
|
||||
https://raw.githubusercontent.com/pivpn/pivpn/master/auto_install/install.sh
|
||||
|
||||
**To install from Test/Development branch**
|
||||
|
||||
Check our [Wiki Page](https://github.com/pivpn/pivpn/wiki#testing)
|
||||
|
||||
**How it works**
|
||||
|
||||
The script will first update your APT repositories, upgrade packages, and install OpenVPN,
|
||||
which will take some time.
|
||||
It will ask which authentication method you wish the guts of your server to use, 1024-bit, 2048-bit, or 4096-bit.
|
||||
If you're unsure or don't have a convincing reason one way or the other I'd use 2048 today. From the OpenVPN site:
|
||||
The script will first update your APT repositories, upgrade packages, and install WireGuard (default) or OpenVPN, which will take some time.
|
||||
|
||||
It will ask which authentication method you wish the guts of your server to use. If you go for WireGuard, you don't get to choose: you will use a Curve25519 public key, which provides 128-bit security. On the other end, if you prefer OpenVPN, you can choose between a 2048-bit, 3072-bit, or 4096-bit RSA certificate. If you're unsure or don't have a convincing reason one way or the other I'd use 2048 today (provides 112-bit security).
|
||||
|
||||
From the OpenVPN site:
|
||||
|
||||
> For asymmetric keys, general wisdom is that 1024-bit keys are no longer sufficient to protect against well-equipped adversaries. Use of 2048-bit is a good minimum. It is wise to ensure all keys across your active PKI (including the CA root keypair) are using at least 2048-bit keys.
|
||||
|
||||
> Up to 4096-bit is accepted by nearly all RSA systems (including OpenVPN), but use of keys this large will dramatically increase generation time, TLS handshake delays, and CPU usage for TLS operations; the benefit beyond 2048-bit keys is small enough not to be of great use at the current time. It is often a larger benefit to consider lower validity times than more bits past 2048, but that is for you to decide.
|
||||
|
||||
Luckily, OpenVPN 2.4 supports ECDSA certificates, which are based on Elliptic Curves, allowing much smaller keys while providing an equivalent security level (256 bit long, equivalent to 3072 bit RSA). For this reason, PiVPN now uses ECDSA certs if you choose to enable OpenVPN 2.4 features. If not, the usual RSA certificates are generated in case the user has clients running an older version of OpenVPN.
|
||||
After this, the script will go back to the command line as it builds the server's own certificate authority (OpenVPN only). The script will ask you if you'd like to change the default port, protocol, client's DNS server, etc. If you know you want to change these things, feel free, and the script will put all the information where it needs to go in the various config files.
|
||||
|
||||
After this, the script will go back to the command line as it builds the server's own
|
||||
certificate authority. The script will ask you if you'd like to change the certificate fields,
|
||||
the default port, client's DNS server, etc. If you know you want to change these things, feel free,
|
||||
and the script will put all the information where it needs to go in the various config files.
|
||||
If you aren't sure, it has been designed that you can simply hit 'Enter' through all the questions
|
||||
and have a working configuration at the end.
|
||||
If you aren't sure, it has been designed that you can simply hit 'Enter' through all the questions and have a working configuration at the end.
|
||||
|
||||
Finally, the script will take some time to build the server's Diffie-Hellman key
|
||||
exchange. If you chose 1024-bit encryption, this will just take a few minutes, but if you
|
||||
chose 2048-bit, it will take much longer (anywhere from 40 minutes to several hours on a
|
||||
Model B+).
|
||||
Finally, the script will take some time to build the server's Diffie-Hellman key exchange (OpenVPN only). If you chose 2048-bit encryption, it will take about 40 minutes on a Model B+, and several hours if you choose a larger size.
|
||||
|
||||
**NOTE: Diffie-Hellman parameters are NOT generated if you choose not to use OpenVPN 2.4.**
|
||||
The script will also make some changes to your system to allow it to forward internet traffic and allow VPN connections through the Pi's firewall. When the script informs you that it has finished configuring PiVPN, it will ask if you want to reboot. I have it where you do not need to reboot when done but it also can't hurt.
|
||||
|
||||
The script will also make some changes to your system to allow it to forward
|
||||
internet traffic and allow VPN connections through the Pi's firewall. When the script
|
||||
informs you that it has finished configuring OpenVPN, it will ask if you want to reboot.
|
||||
I have it where you do not need to reboot when done but it also can't hurt.
|
||||
After the installation is complete you can use the command `pivpn` to manage the server. The commands below are just to get started, run `pivpn -h` to see the full list of options.
|
||||
|
||||
|
||||
Managing the PiVPN
|
||||
Managing the PiVPN (WireGuard)
|
||||
----------------------
|
||||
|
||||
After the installation is complete you can use the command 'pivpn' to manage the server.
|
||||
`pivpn add`
|
||||
You will be prompted to enter a name for your client. Pick anything you like and hit 'enter'.
|
||||
The script will assemble the client .conf file and place it in the directory 'configs' within your
|
||||
home directory.
|
||||
|
||||
"pivpn add"
|
||||
`pivpn remove`
|
||||
Asks you for the name of the client to remove. Once you remove a client, it will no longer allow you to use
|
||||
the given client config (specifically its public key) to connect. This is useful for many reasons but some ex:
|
||||
You have a profile on a mobile phone and it was lost or stolen. Remove its key and generate a new
|
||||
one for your new phone. Or even if you suspect that a key may have been compromised in any way,
|
||||
just remove it and generate a new one.
|
||||
|
||||
`pivpn list`
|
||||
If you add more than a few clients, this gives you a nice list of their names and associated keys.
|
||||
|
||||
Managing the PiVPN (OpenVPN)
|
||||
----------------------
|
||||
|
||||
`pivpn add`
|
||||
You will be prompted to enter a name for your client. Pick anything you like and hit 'enter'.
|
||||
You will be asked to enter a pass phrase for the client key; make sure it's one you'll remember.
|
||||
The script will assemble the client .ovpn file and place it in the directory 'ovpns' within your
|
||||
|
@ -119,48 +127,79 @@ home directory.
|
|||
If you need to create a client certificate that is not password protected (IE for use on a router),
|
||||
then you can use the 'pivpn add nopass' option to generate that.
|
||||
|
||||
"pivpn revoke"
|
||||
`pivpn revoke`
|
||||
Asks you for the name of the client to revoke. Once you revoke a client, it will no longer allow you to use
|
||||
the given client certificate (ovpn config) to connect. This is useful for many reasons but some ex:
|
||||
You have a profile on a mobile phone and it was lost or stolen. Revoke its cert and generate a new
|
||||
one for your new phone. Or even if you suspect that a cert may have been compromised in any way,
|
||||
just revoke it and generate a new one.
|
||||
|
||||
"pivpn list"
|
||||
`pivpn list`
|
||||
If you add more than a few clients, this gives you a nice list of their names and whether their certificate
|
||||
is still valid or has been revoked. Great way to keep track of what you did with 'pivpn add' and 'pivpn revoke'.
|
||||
|
||||
You can run just 'pivpn' to see all the options.
|
||||
|
||||
Importing .ovpn Profiles on Client Machines
|
||||
Importing Profiles on Client Machines
|
||||
--------------------------------------------
|
||||
|
||||
To move a client .ovpn profile to Windows, use a program like WinSCP or Cyberduck. Note that
|
||||
you may need administrator permission to move files to some folders on your Windows machine,
|
||||
so if you have trouble transferring the profile to a particular folder with your chosen file
|
||||
transfer program, try moving it to your desktop. To move a profile to Android, you can either
|
||||
retrieve it on PC and then move it to your device via USB, or you can use an app like Turbo
|
||||
FTP & SFTP client to retrieve it directly from your Android device.
|
||||
**Windows**: Use a program like WinSCP or Cyberduck. Note that you may need administrator permission to move files to some folders on your Windows machine, so if you have trouble transferring the profile to a particular folder with your chosen file transfer program, try moving it to your desktop.
|
||||
|
||||
To import the profile to OpenVPN on Windows, download the OpenVPN GUI from the community downloads
|
||||
section of openvpn.net, install it, and place the profile in the 'config' folder of your OpenVPN
|
||||
directory, i.e., in 'C:\Program Files\OpenVPN\config'. To import the profile on Android, install
|
||||
the OpenVPN Connect app, select 'Import' from the drop-down menu in the upper right corner of the
|
||||
main screen, choose the directory on your device where you stored the .ovpn file, and select the
|
||||
file.
|
||||
**Mac/Linux**: Open the Terminal app and copy the config from the Raspberry Pi using `scp pi-user@ip-of-your-raspberry:configs/whatever.conf .` (if using WireGuard) or `scp pi-user@ip-of-your-raspberry:ovpns/whatever.ovpn .` (if using OpenVPN). The file will be downloaded in the current working directory, which usually is the home folder of your PC.
|
||||
|
||||
After importing, connect to the VPN server on Windows by running the OpenVPN GUI with
|
||||
administrator permissions, right-clicking on the icon in the system tray, and clicking 'Connect',
|
||||
or on Android by selecting the profile under 'OpenVPN Profile' and pressing 'Connect'. You'll be
|
||||
asked to enter the pass phrase you chose. Do so, and you're in! Enjoy your ~$50 USD private VPN.
|
||||
**Android/iOS** (WireGuard only): Just skip to _Connecting to the PiVPN server (WireGuard)_
|
||||
|
||||
**Android**: You can either retrieve it on PC and then move it to your device via USB, or you can use an app like Turbo FTP & SFTP client to retrieve it directly from your Android device.
|
||||
|
||||
**iOS**: You can use an app that supports SFTP like Documents by Readdle to retrieve it directly from your iOS device.
|
||||
|
||||
Connecting to the PiVPN server (WireGuard)
|
||||
--------------------------------------------
|
||||
|
||||
**Windows/Mac**: Download the [WireGuard GUI app](https://www.wireguard.com/install/), import the configuration and activate the tunnel.
|
||||
|
||||
**Linux**: Install [WireGuard](https://www.wireguard.com/install/) following the instructions for your distribution. Now, as root user, create the /etc/wireguard folder and prevent anyone but root to enter it (you only need to do this the first time):
|
||||
```
|
||||
mkdir -p /etc/wireguard
|
||||
chown root:root /etc/wireguard
|
||||
chmod 700 /etc/wireguard
|
||||
```
|
||||
Move the config and activate the tunnel:
|
||||
```
|
||||
mv whatever.conf /etc/wireguard/
|
||||
wg-quick up whatever
|
||||
```
|
||||
Run `wg-quick down whatever` to deactivate the tunnel.
|
||||
|
||||
**Android/iOS:** Run `pivpn -qr` on the PiVPN server to generate a QR code of your config, download the Wireguard app [Android link](https://play.google.com/store/apps/details?id=com.wireguard.android) / [iOS link](https://apps.apple.com/it/app/wireguard/id1441195209), click the '+' sign and scan the QR code with your phone's camera. Flip the switch to activate the tunnel.
|
||||
|
||||
Connecting to the PiVPN server (OpenVPN)
|
||||
--------------------------------------------
|
||||
|
||||
**Windows**: Download the [OpenVPN GUI](https://openvpn.net/community-downloads/), install it, and place the profile in the 'config' folder of your OpenVPN directory, i.e., in 'C:\Program Files\OpenVPN\config'. After importing, connect to the VPN server on Windows by running the OpenVPN GUI with administrator permissions, right-clicking on the icon in the system tray, and clicking 'Connect'.
|
||||
|
||||
**Linux**: Install OpenVPN using your package manager (APT in this example). Now, as root user, create the /etc/openvpn/client folder and prevent anyone but root to enter it (you only need to do this the first time):
|
||||
```
|
||||
apt install openvpn
|
||||
mkdir -p /etc/openvpn/client
|
||||
chown root:root /etc/openvpn/client
|
||||
chmod 700 /etc/openvpn/client
|
||||
```
|
||||
Move the config and connect (input the pass phrase if you set one):
|
||||
```
|
||||
mv whatever.ovpn /etc/openvpn/client/
|
||||
openvpn /etc/openvpn/client/whatever.ovpn
|
||||
```
|
||||
Press CTRL-C to disconnect.
|
||||
|
||||
**Mac**: You can use an OpenVPN client like [Tunnelblick](https://tunnelblick.net/downloads.html). Here's a [guide](https://tunnelblick.net/czUsing.html) to import the configuration.
|
||||
|
||||
**Android**: Install the [OpenVPN Connect app](https://play.google.com/store/apps/details?id=net.openvpn.openvpn), select 'Import' from the drop-down menu in the upper right corner of the main screen, choose the directory on your device where you stored the .ovpn file, and select the file. Connect by selecting the profile under 'OpenVPN Profile' and pressing 'Connect'.
|
||||
|
||||
**iOS**: Install the [OpenVPN Connect app](https://apps.apple.com/it/app/openvpn-connect/id590379981). Then go to the app where you copied the .ovpn file to, select the file, find an icon or button to 'Share' or 'Open with', and choose to open with the OpenVPN app.
|
||||
|
||||
Removing PiVPN
|
||||
----------------
|
||||
|
||||
If at any point you wish to remove OpenVPN from your Pi and revert it to a
|
||||
pre-installation state, such as if you want to undo a failed installation to try again or
|
||||
you want to remove OpenVPN without installing a fresh Raspbian image, just run
|
||||
'pivpn uninstall'
|
||||
If at any point you wish to remove PiVPN from your Pi and revert it to a pre-installation state, such as if you want to undo a failed installation to try again or you want to remove PiVPN without installing a fresh Raspbian image, just run `pivpn uninstall`.
|
||||
|
||||
Feedback & Support
|
||||
--------
|
||||
|
@ -189,6 +228,9 @@ A secure docker container that sets up PiVPN and SSH.
|
|||
[OpenVPN](https://openvpn.net)
|
||||
The foundation for all open-source VPN projects.
|
||||
|
||||
[WireGuard](https://www.wireguard.com/)
|
||||
*An extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography.*
|
||||
|
||||
Contributions
|
||||
-------------
|
||||
|
||||
|
@ -207,7 +249,7 @@ sources.
|
|||
|
||||
3. Of course there is [OpenVPN](https://openvpn.net)
|
||||
|
||||
4. Also [Wireguard](https://www.wireguard.com/)
|
||||
4. Also [WireGuard](https://www.wireguard.com/)
|
||||
|
||||
5. And as always the ever vigilant [EFF](https://www.eff.org/)
|
||||
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
# Make sure you have `curl` installed
|
||||
|
||||
######## VARIABLES #########
|
||||
setupVars=/etc/pivpn/setupVars.conf
|
||||
pivpnGitUrl="https://github.com/pivpn/pivpn.git"
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
pivpnFilesDir="/etc/.pivpn"
|
||||
|
||||
debianOvpnUserGroup="openvpn:openvpn"
|
||||
|
||||
### PKG Vars ###
|
||||
PKG_MANAGER="apt-get"
|
||||
PKG_CACHE="/var/lib/apt/lists/"
|
||||
|
@ -25,21 +24,22 @@ PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install"
|
|||
PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
|
||||
|
||||
# Dependencies that are required by the script, regardless of the VPN protocol chosen
|
||||
BASE_DEPS=(git tar wget grep iptables-persistent dnsutils whiptail net-tools bsdmainutils)
|
||||
BASE_DEPS=(git tar wget grep dnsutils whiptail net-tools bsdmainutils)
|
||||
|
||||
# Dependencies that where actually installed by the script. For example if the script requires
|
||||
# grep and dnsutils but dnsutils is already installed, we save grep here. This way when uninstalling
|
||||
# PiVPN we won't prompt to remove packages that may have been installed by the user for other reasons
|
||||
TO_INSTALL=()
|
||||
|
||||
pivpnGitUrl="https://github.com/pivpn/pivpn.git"
|
||||
easyrsaVer="3.0.6"
|
||||
easyrsaRel="https://github.com/OpenVPN/easy-rsa/releases/download/v${easyrsaVer}/EasyRSA-unix-v${easyrsaVer}.tgz"
|
||||
|
||||
subnetClass="24"
|
||||
dhcpcdFile="/etc/dhcpcd.conf"
|
||||
debianOvpnUserGroup="openvpn:openvpn"
|
||||
|
||||
# Raspbian's unattended-upgrades package downloads Debian's config, so this is the link for the proper config
|
||||
UNATTUPG_RELEASE="1.14"
|
||||
UNATTUPG_RELEASE="1.16"
|
||||
UNATTUPG_CONFIG="https://github.com/mvo5/unattended-upgrades/archive/${UNATTUPG_RELEASE}.tar.gz"
|
||||
|
||||
# Find the rows and columns. Will default to 80x24 if it can not be detected.
|
||||
|
@ -47,7 +47,10 @@ screen_size=$(stty size 2>/dev/null || echo 24 80)
|
|||
rows=$(echo "$screen_size" | awk '{print $1}')
|
||||
columns=$(echo "$screen_size" | awk '{print $2}')
|
||||
|
||||
######## Undocumented Flags. Shhh ########
|
||||
runUnattended=false
|
||||
skipSpaceCheck=false
|
||||
reconfigure=false
|
||||
|
||||
# Divide by two so the dialogs take up half of the screen, which looks nice.
|
||||
r=$(( rows / 2 ))
|
||||
|
@ -58,10 +61,169 @@ c=$(( c < 70 ? 70 : c ))
|
|||
|
||||
# Find IP used to route to outside world
|
||||
IPv4addr=$(ip route get 192.0.2.1 | awk '{print $7}')
|
||||
IPv4gw=$(ip route get 192.0.2.2 | awk '{print $3}')
|
||||
|
||||
IPv4gw=$(ip route get 192.0.2.1 | awk '{print $3}')
|
||||
availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1)
|
||||
dhcpcdFile=/etc/dhcpcd.conf
|
||||
|
||||
######## SCRIPT ############
|
||||
|
||||
main(){
|
||||
|
||||
######## FIRST CHECK ########
|
||||
# Must be root to install
|
||||
echo ":::"
|
||||
if [[ $EUID -eq 0 ]];then
|
||||
echo "::: You are root."
|
||||
else
|
||||
echo "::: sudo will be used for the install."
|
||||
# Check if it is actually installed
|
||||
# If it isn't, exit because the install cannot complete
|
||||
if [[ $(dpkg-query -s sudo) ]];then
|
||||
export SUDO="sudo"
|
||||
export SUDOE="sudo -E"
|
||||
else
|
||||
echo "::: Please install sudo or run this as root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check arguments for the undocumented flags
|
||||
for var in "$@"; do
|
||||
case "$var" in
|
||||
"--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
|
||||
"--unattended" ) runUnattended=true;;
|
||||
"--reconfigure" ) reconfigure=true;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "${runUnattended}" == true ]]; then
|
||||
echo "::: --unattended passed to install script, no whiptail dialogs will be displayed"
|
||||
if [ -z "$2" ]; then
|
||||
echo "::: No configuration file passed, using default settings..."
|
||||
else
|
||||
if [ -r "$2" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "$2"
|
||||
else
|
||||
echo "::: Can't open $2"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -r "$setupVars" ]; then
|
||||
if [[ "${reconfigure}" == true ]]; then
|
||||
echo "::: --reconfigure passed to install script, will reinstall PiVPN overwriting existing settings"
|
||||
UpdateCmd="Reconfigure"
|
||||
elif [[ "${runUnattended}" == true ]]; then
|
||||
### What should the script do when passing --unattended to an existing installation?
|
||||
UpdateCmd="Reconfigure"
|
||||
else
|
||||
askAboutExistingInstall
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$UpdateCmd" ] || [ "$UpdateCmd" = "Reconfigure" ]; then
|
||||
:
|
||||
elif [ "$UpdateCmd" = "Update" ]; then
|
||||
$SUDO /opt/pivpn/update.sh "$@"
|
||||
exit 0
|
||||
elif [ "$UpdateCmd" = "Repair" ]; then
|
||||
source "$setupVars"
|
||||
runUnattended=true
|
||||
fi
|
||||
|
||||
# Check for supported distribution
|
||||
distroCheck
|
||||
|
||||
# Checks for hostname Length
|
||||
checkHostname
|
||||
|
||||
# Start the installer
|
||||
# Verify there is enough disk space for the install
|
||||
if [[ "${skipSpaceCheck}" == true ]]; then
|
||||
echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!"
|
||||
else
|
||||
verifyFreeDiskSpace
|
||||
fi
|
||||
|
||||
updatePackageCache
|
||||
|
||||
# Notify user of package availability
|
||||
notifyPackageUpdatesAvailable
|
||||
|
||||
# Install packages used by this installation script
|
||||
preconfigurePackages
|
||||
installDependentPackages BASE_DEPS[@]
|
||||
|
||||
# Display welcome dialogs
|
||||
welcomeDialogs
|
||||
|
||||
# Find interfaces and let the user choose one
|
||||
chooseInterface
|
||||
|
||||
if [ "$PLAT" != "Raspbian" ]; then
|
||||
avoidStaticIPv4Ubuntu
|
||||
else
|
||||
getStaticIPv4Settings
|
||||
setStaticIPv4
|
||||
fi
|
||||
|
||||
# Choose the user for the ovpns
|
||||
chooseUser
|
||||
|
||||
# Clone/Update the repos
|
||||
cloneOrUpdateRepos
|
||||
|
||||
# Install
|
||||
if installPiVPN; then
|
||||
echo "::: Install Complete..."
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start services
|
||||
restartServices
|
||||
|
||||
# Ask if unattended-upgrades will be enabled
|
||||
askUnattendedUpgrades
|
||||
|
||||
if [ "$UNATTUPG" -eq 1 ]; then
|
||||
confUnattendedUpgrades
|
||||
fi
|
||||
|
||||
# Save installation setting to the final location
|
||||
echo "TO_INSTALL=(${TO_INSTALL[*]})" >> /tmp/setupVars.conf
|
||||
$SUDO cp /tmp/setupVars.conf "$setupVars"
|
||||
|
||||
installScripts
|
||||
|
||||
# Ensure that cached writes reach persistent storage
|
||||
echo "::: Flushing writes to disk..."
|
||||
sync
|
||||
echo "::: done."
|
||||
|
||||
displayFinalMessage
|
||||
echo ":::"
|
||||
}
|
||||
|
||||
askAboutExistingInstall(){
|
||||
opt1a="Update"
|
||||
opt1b="Get the latest PiVPN scripts"
|
||||
|
||||
opt2a="Repair"
|
||||
opt2b="Reinstall PiVPN using existing settings"
|
||||
|
||||
opt3a="Reconfigure"
|
||||
opt3b="Reinstall PiVPN with new settings"
|
||||
|
||||
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\nWe have detected an existing install.\n\nPlease choose from the following options:" ${r} ${c} 3 \
|
||||
"${opt1a}" "${opt1b}" \
|
||||
"${opt2a}" "${opt2b}" \
|
||||
"${opt3a}" "${opt3b}" 3>&2 2>&1 1>&3) || \
|
||||
{ echo "::: Cancel selected. Exiting"; exit 1; }
|
||||
|
||||
echo "::: ${opt1a} option selected."
|
||||
}
|
||||
|
||||
# Next see if we are on a tested and supported OS
|
||||
noOSSupport(){
|
||||
|
@ -253,9 +415,9 @@ notifyPackageUpdatesAvailable(){
|
|||
preconfigurePackages(){
|
||||
# Add support for https repositories if there are any that use it otherwise the installation will silently fail
|
||||
if [[ -f /etc/apt/sources.list ]]; then
|
||||
if grep -q https /etc/apt/sources.list; then
|
||||
BASE_DEPS+=("apt-transport-https")
|
||||
fi
|
||||
if grep -q https /etc/apt/sources.list; then
|
||||
BASE_DEPS+=("apt-transport-https")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${OSCN} == "buster" ]]; then
|
||||
|
@ -263,8 +425,24 @@ preconfigurePackages(){
|
|||
$SUDO update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
|
||||
fi
|
||||
|
||||
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | $SUDO debconf-set-selections
|
||||
echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections
|
||||
# if ufw is enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example)
|
||||
if $SUDO bash -c 'hash ufw' 2>/dev/null; then
|
||||
if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive; then
|
||||
USING_UFW=0
|
||||
else
|
||||
USING_UFW=1
|
||||
fi
|
||||
else
|
||||
USING_UFW=0
|
||||
fi
|
||||
|
||||
if [ "$USING_UFW" -eq 0 ]; then
|
||||
BASE_DEPS+=(iptables-persistent)
|
||||
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | $SUDO debconf-set-selections
|
||||
echo iptables-persistent iptables-persistent/autosave_v6 boolean false | $SUDO debconf-set-selections
|
||||
fi
|
||||
|
||||
echo "USING_UFW=${USING_UFW}" >> /tmp/setupVars.conf
|
||||
}
|
||||
|
||||
installDependentPackages(){
|
||||
|
@ -389,7 +567,7 @@ validIP(){
|
|||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
OIFS=$IFS
|
||||
IFS='.'
|
||||
read -r -a ip <<< "$ip"
|
||||
read -r -a ip <<< "$ip"
|
||||
IFS=$OIFS
|
||||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||||
|
@ -613,20 +791,28 @@ isRepo(){
|
|||
}
|
||||
|
||||
updateRepo(){
|
||||
# Pull the latest commits
|
||||
echo -n "::: Updating repo in $1..."
|
||||
$SUDO rm -rf "${1}"
|
||||
# Go back to /etc otherwise git will complain when the current working
|
||||
# directory has just been deleted (/etc/.pivpn).
|
||||
cd /etc && \
|
||||
$SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $!
|
||||
cd "${1}" || exit 1
|
||||
if [ -z "${TESTING+x}" ]; then
|
||||
:
|
||||
if [ "${UpdateCmd}" = "Repair" ]; then
|
||||
echo "::: Repairing an existing installation, not downloading/updating local repos"
|
||||
else
|
||||
${SUDOE} git checkout test
|
||||
# Pull the latest commits
|
||||
echo -n "::: Updating repo in $1..."
|
||||
### FIXME: Never call rm -rf with a plain variable. Never again as SU!
|
||||
#$SUDO rm -rf "${1}"
|
||||
if test -n "$1"; then
|
||||
$SUDO rm -rf "$(dirname "$1")/.pivpn"
|
||||
fi
|
||||
# Go back to /etc otherwise git will complain when the current working
|
||||
# directory has just been deleted (/etc/.pivpn).
|
||||
cd /etc && \
|
||||
$SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $!
|
||||
cd "${1}" || exit 1
|
||||
if [ -z "${TESTING+x}" ]; then
|
||||
:
|
||||
else
|
||||
${SUDOE} git checkout test
|
||||
fi
|
||||
echo " done!"
|
||||
fi
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
makeRepo(){
|
||||
|
@ -640,7 +826,7 @@ makeRepo(){
|
|||
# Go back to /etc otherwhise git will complain when the current working
|
||||
# directory has just been deleted (/etc/.pivpn).
|
||||
cd /etc && \
|
||||
$SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $!
|
||||
$SUDO git clone -q --depth 1 --no-single-branch "${2}" "${1}" > /dev/null & spinner $!
|
||||
cd "${1}" || exit 1
|
||||
if [ -z "${TESTING+x}" ]; then
|
||||
:
|
||||
|
@ -686,7 +872,7 @@ askWhichVPN(){
|
|||
fi
|
||||
fi
|
||||
else
|
||||
if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choise expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c});
|
||||
if (whiptail --backtitle "Setup PiVPN" --title "Installation mode" --yesno "WireGuard is a new kind of VPN that provides near-istantaneous connection speed, high performance, modern cryptography.\\n\\nIt's the recommended choice expecially if you use mobile devices where WireGuard is easier on battery than OpenVPN.\\n\\nOpenVPN is still available if you need the traditional, flexible, trusted VPN protocol. Or if you need features like TCP and custom search domain.\\n\\nChoose 'Yes' to use WireGuard or 'No' to use OpenVPN." ${r} ${c});
|
||||
then
|
||||
VPN="wireguard"
|
||||
else
|
||||
|
@ -747,26 +933,22 @@ installWireGuard(){
|
|||
PIVPN_DEPS=(checkinstall dkms libmnl-dev libelf-dev raspberrypi-kernel-headers build-essential pkg-config qrencode jq)
|
||||
installDependentPackages PIVPN_DEPS[@]
|
||||
|
||||
WG_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-kmodtools"."version"')"
|
||||
WG_SOURCE="https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${WG_SNAPSHOT}.tar.xz"
|
||||
|
||||
# Delete any leftover code
|
||||
$SUDO rm -rf /usr/src/wireguard-*
|
||||
|
||||
echo "::: Downloading source code... "
|
||||
wget -qO- "${WG_SOURCE}" | $SUDO tar Jxf - --directory /usr/src
|
||||
WG_TOOLS_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-tools"."version"')"
|
||||
WG_TOOLS_SOURCE="https://git.zx2c4.com/wireguard-tools/snapshot/wireguard-tools-${WG_TOOLS_SNAPSHOT}.tar.xz"
|
||||
|
||||
echo "::: Downloading wireguard-tools source code... "
|
||||
wget -qO- "${WG_TOOLS_SOURCE}" | $SUDO tar Jxf - --directory /usr/src
|
||||
echo "done!"
|
||||
|
||||
cd /usr/src && \
|
||||
$SUDO mv WireGuard-"${WG_SNAPSHOT}" wireguard-"${WG_SNAPSHOT}"
|
||||
cd wireguard-"${WG_SNAPSHOT}" && \
|
||||
$SUDO mv src/* . && \
|
||||
$SUDO rmdir src
|
||||
cd /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}/src"
|
||||
|
||||
# We install the userspace tools manually since DKMS only compiles and
|
||||
# installs the kernel module
|
||||
echo "::: Compiling WireGuard tools... "
|
||||
if $SUDO make tools; then
|
||||
if $SUDO make; then
|
||||
echo "done!"
|
||||
else
|
||||
echo "failed!"
|
||||
|
@ -777,7 +959,7 @@ installWireGuard(){
|
|||
# PiVPN we can just do apt remove wireguard-tools, instead of manually removing
|
||||
# files from the file system
|
||||
echo "::: Installing WireGuard tools... "
|
||||
if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_SNAPSHOT}" -y make tools-install; then
|
||||
if $SUDO checkinstall --pkgname wireguard-tools --pkgversion "${WG_TOOLS_SNAPSHOT}" -y; then
|
||||
TO_INSTALL+=("wireguard-tools")
|
||||
echo "done!"
|
||||
else
|
||||
|
@ -785,35 +967,52 @@ installWireGuard(){
|
|||
exit 1
|
||||
fi
|
||||
|
||||
echo "WG_TOOLS_SNAPSHOT=${WG_TOOLS_SNAPSHOT}" >> /tmp/setupVars.conf
|
||||
|
||||
WG_MODULE_SNAPSHOT="$(curl -s https://build.wireguard.com/distros.json | jq -r '."upstream-linuxcompat"."version"')"
|
||||
WG_MODULE_SOURCE="https://git.zx2c4.com/wireguard-linux-compat/snapshot/wireguard-linux-compat-${WG_MODULE_SNAPSHOT}.tar.xz"
|
||||
|
||||
echo "::: Downloading wireguard-linux-compat source code... "
|
||||
wget -qO- "${WG_MODULE_SOURCE}" | $SUDO tar Jxf - --directory /usr/src
|
||||
echo "done!"
|
||||
|
||||
# Rename wireguard-linux-compat folder and move the source code to the parent folder
|
||||
# such that dkms picks up the module when referencing wireguard/"${WG_MODULE_SNAPSHOT}"
|
||||
cd /usr/src && \
|
||||
$SUDO mv wireguard-linux-compat-"${WG_MODULE_SNAPSHOT}" wireguard-"${WG_MODULE_SNAPSHOT}"
|
||||
cd wireguard-"${WG_MODULE_SNAPSHOT}" && \
|
||||
$SUDO mv src/* . && \
|
||||
$SUDO rmdir src
|
||||
|
||||
echo "::: Adding WireGuard modules via DKMS... "
|
||||
if $SUDO dkms add wireguard/"${WG_SNAPSHOT}"; then
|
||||
if $SUDO dkms add wireguard/"${WG_MODULE_SNAPSHOT}"; then
|
||||
echo "done!"
|
||||
else
|
||||
echo "failed!"
|
||||
$SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all
|
||||
$SUDO dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "::: Compiling WireGuard modules via DKMS... "
|
||||
if $SUDO dkms build wireguard/"${WG_SNAPSHOT}"; then
|
||||
if $SUDO dkms build wireguard/"${WG_MODULE_SNAPSHOT}"; then
|
||||
echo "done!"
|
||||
else
|
||||
echo "failed!"
|
||||
$SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all
|
||||
$SUDO dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "::: Installing WireGuard modules via DKMS... "
|
||||
if $SUDO dkms install wireguard/"${WG_SNAPSHOT}"; then
|
||||
if $SUDO dkms install wireguard/"${WG_MODULE_SNAPSHOT}"; then
|
||||
TO_INSTALL+=("wireguard-dkms")
|
||||
echo "done!"
|
||||
else
|
||||
echo "failed!"
|
||||
$SUDO dkms remove wireguard/"${WG_SNAPSHOT}" --all
|
||||
$SUDO dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "WG_SNAPSHOT=${WG_SNAPSHOT}" >> /tmp/setupVars.conf
|
||||
echo "WG_MODULE_SNAPSHOT=${WG_MODULE_SNAPSHOT}" >> /tmp/setupVars.conf
|
||||
|
||||
fi
|
||||
|
||||
|
@ -978,7 +1177,7 @@ askClientDNS(){
|
|||
# Detect and offer to use Pi-hole
|
||||
if command -v pihole &>/dev/null; then
|
||||
if (whiptail --backtitle "Setup PiVPN" --title "Pi-hole" --yesno "We have detected a Pi-hole installation, do you want to use it as the DNS server for the VPN, so you get ad blocking on the go?" ${r} ${c}); then
|
||||
pivpnDNS1="$IPv4addr"
|
||||
pivpnDNS1="$vpnGw"
|
||||
echo "interface=$pivpnDEV" | $SUDO tee /etc/dnsmasq.d/02-pivpn.conf > /dev/null
|
||||
$SUDO pihole restartdns
|
||||
echo "pivpnDNS1=${pivpnDNS1}" >> /tmp/setupVars.conf
|
||||
|
@ -989,9 +1188,9 @@ askClientDNS(){
|
|||
|
||||
DNSChoseCmd=(whiptail --separate-output --radiolist "Select the DNS Provider
|
||||
for your VPN Clients (press space to select). To use your own, select
|
||||
Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select
|
||||
\"PiVPN-is-local-DNS\" and make sure your resolver is listening on
|
||||
\"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6)
|
||||
Custom.\\n\\nIn case you have a local resolver running, i.e. unbound, select
|
||||
\"PiVPN-is-local-DNS\" and make sure your resolver is listening on
|
||||
\"$vpnGw\", allowing requests from \"${pivpnNET}/${subnetClass}\"." ${r} ${c} 6)
|
||||
DNSChooseOptions=(Quad9 "" on
|
||||
OpenDNS "" off
|
||||
Level3 "" off
|
||||
|
@ -1077,7 +1276,7 @@ validDomain(){
|
|||
local stat=1
|
||||
|
||||
if [[ $domain =~ ^(([a-zA-Z0-9]{1,63}|([a-zA-Z0-9]{1,60}[-a-zA-Z0-9()]{0,2}[a-zA-Z0-9]{1,60}))\.){1,6}([a-zA-Z]{2,})$ ]]; then
|
||||
stat=$?
|
||||
stat=$?
|
||||
fi
|
||||
return $stat
|
||||
}
|
||||
|
@ -1301,7 +1500,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null
|
|||
else
|
||||
# Generate Diffie-Hellman key exchange
|
||||
${SUDOE} ./easyrsa gen-dh
|
||||
${SUDOE} mv "pki/dh.pem pki/dh${pivpnENCRYPT}.pem"
|
||||
${SUDOE} mv "pki/dh.pem" "pki/dh${pivpnENCRYPT}.pem"
|
||||
fi
|
||||
|
||||
# Generate static HMAC key to defend against DDoS
|
||||
|
@ -1311,7 +1510,7 @@ set_var EASYRSA_KEY_SIZE ${pivpnENCRYPT}" | $SUDO tee vars >/dev/null
|
|||
${SUDOE} ./easyrsa gen-crl
|
||||
${SUDOE} cp pki/crl.pem /etc/openvpn/crl.pem
|
||||
if ! getent passwd openvpn; then
|
||||
${SUDOE} adduser --system --home /var/lib/openvpn/ --group --disabled-login ${debianOvpnUserGroup%:*}
|
||||
${SUDOE} adduser --system --home /var/lib/openvpn/ --group --disabled-login ${debianOvpnUserGroup%:*}
|
||||
fi
|
||||
${SUDOE} chown "$debianOvpnUserGroup" /etc/openvpn/crl.pem
|
||||
|
||||
|
@ -1392,6 +1591,12 @@ confWireGuard(){
|
|||
else
|
||||
whiptail --title "Server Information" --msgbox "The Server Keys and Pre-Shared key will now be generated." "${r}" "${c}"
|
||||
fi
|
||||
|
||||
# Remove configs and keys folders to make space for a new server when using 'Repair' or 'Reconfigure'
|
||||
# over an existing installation
|
||||
$SUDO rm -rf /etc/wireguard/configs
|
||||
$SUDO rm -rf /etc/wireguard/keys
|
||||
|
||||
$SUDO mkdir -p /etc/wireguard/configs
|
||||
$SUDO touch /etc/wireguard/configs/clients.txt
|
||||
$SUDO mkdir -p /etc/wireguard/keys
|
||||
|
@ -1415,45 +1620,42 @@ confNetwork(){
|
|||
$SUDO sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf
|
||||
$SUDO sysctl -p > /dev/null
|
||||
|
||||
# if ufw enabled, configure that (running as root because sometimes the executable is not in the user's $PATH, on Debian for example)
|
||||
if $SUDO bash -c 'hash ufw' 2>/dev/null; then
|
||||
if LANG=en_US.UTF-8 $SUDO ufw status | grep -q inactive
|
||||
then
|
||||
USING_UFW=0
|
||||
else
|
||||
USING_UFW=1
|
||||
echo "::: Detected UFW is enabled."
|
||||
echo "::: Adding UFW rules..."
|
||||
### Basic safeguard: if file is empty, there's been something weird going on.
|
||||
### Note: no safeguard against imcomplete content as a result of previous failures.
|
||||
if test -s /etc/ufw/before.rules; then
|
||||
$SUDO cp -f /etc/ufw/before.rules /etc/ufw/before.rules.pre-pivpn
|
||||
else
|
||||
echo "$0: ERR: Sorry, won't touch empty file \"/etc/ufw/before.rules\".";
|
||||
exit 1;
|
||||
fi
|
||||
### If there is already a "*nat" section just add our POSTROUTING MASQUERADE
|
||||
if $SUDO grep -q "*nat" /etc/ufw/before.rules; then
|
||||
$SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE/}" -i /etc/ufw/before.rules
|
||||
else
|
||||
$SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
fi
|
||||
# Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic)
|
||||
$SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null
|
||||
$SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any >/dev/null
|
||||
if [ "$USING_UFW" -eq 1 ]; then
|
||||
|
||||
$SUDO ufw reload >/dev/null
|
||||
echo "::: UFW configuration completed."
|
||||
echo "::: Detected UFW is enabled."
|
||||
echo "::: Adding UFW rules..."
|
||||
### Basic safeguard: if file is empty, there's been something weird going on.
|
||||
### Note: no safeguard against imcomplete content as a result of previous failures.
|
||||
if test -s /etc/ufw/before.rules; then
|
||||
$SUDO cp -f /etc/ufw/before.rules /etc/ufw/before.rules.pre-pivpn
|
||||
else
|
||||
echo "$0: ERR: Sorry, won't touch empty file \"/etc/ufw/before.rules\".";
|
||||
exit 1;
|
||||
fi
|
||||
else
|
||||
USING_UFW=0
|
||||
fi
|
||||
# else configure iptables
|
||||
if [[ $USING_UFW -eq 0 ]]; then
|
||||
### If there is already a "*nat" section just add our POSTROUTING MASQUERADE
|
||||
if $SUDO grep -q "*nat" /etc/ufw/before.rules; then
|
||||
### Onyl add the NAT rule if it isn't already there
|
||||
if ! $SUDO grep -q "${VPN}-nat-rule" /etc/ufw/before.rules; then
|
||||
$SUDO sed "/^*nat/{n;s/\(:POSTROUTING ACCEPT .*\)/\1\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE -m comment --comment ${VPN}-nat-rule/}" -i /etc/ufw/before.rules
|
||||
fi
|
||||
else
|
||||
$SUDO sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s ${pivpnNET}\/${subnetClass} -o ${IPv4dev} -j MASQUERADE -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
fi
|
||||
# Insert rules at the beginning of the chain (in case there are other rules that may drop the traffic)
|
||||
$SUDO ufw insert 1 allow "${pivpnPORT}"/"${pivpnPROTO}" >/dev/null
|
||||
$SUDO ufw route insert 1 allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any >/dev/null
|
||||
|
||||
$SUDO ufw reload >/dev/null
|
||||
echo "::: UFW configuration completed."
|
||||
|
||||
elif [ "$USING_UFW" -eq 0 ]; then
|
||||
|
||||
# Now some checks to detect which rules we need to add. On a newly installed system all policies
|
||||
# should be ACCEPT, so the only required rule would be the MASQUERADE one.
|
||||
|
||||
$SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE
|
||||
if ! $SUDO iptables -t nat -S | grep -q "${VPN}-nat-rule"; then
|
||||
$SUDO iptables -t nat -I POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule"
|
||||
fi
|
||||
|
||||
# Count how many rules are in the INPUT and FORWARD chain. When parsing input from
|
||||
# iptables -S, '^-P' skips the policies and 'ufw-' skips ufw chains (in case ufw was found
|
||||
|
@ -1472,15 +1674,23 @@ confNetwork(){
|
|||
# chain (using -I).
|
||||
|
||||
if [ "$INPUT_RULES_COUNT" -ne 0 ] || [ "$INPUT_POLICY" != "ACCEPT" ]; then
|
||||
$SUDO iptables -I INPUT 1 -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT
|
||||
if $SUDO iptables -t nat -S | grep -q "${VPN}-input-rule"; then
|
||||
INPUT_CHAIN_EDITED=0
|
||||
else
|
||||
$SUDO iptables -I INPUT 1 -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT -m comment --comment "${VPN}-input-rule"
|
||||
fi
|
||||
INPUT_CHAIN_EDITED=1
|
||||
else
|
||||
INPUT_CHAIN_EDITED=0
|
||||
fi
|
||||
|
||||
if [ "$FORWARD_RULES_COUNT" -ne 0 ] || [ "$FORWARD_POLICY" != "ACCEPT" ]; then
|
||||
$SUDO iptables -I FORWARD 1 -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
$SUDO iptables -I FORWARD 2 -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT
|
||||
if $SUDO iptables -t nat -S | grep -q "${VPN}-forward-rule"; then
|
||||
FORWARD_CHAIN_EDITED=0
|
||||
else
|
||||
$SUDO iptables -I FORWARD 1 -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
$SUDO iptables -I FORWARD 2 -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
fi
|
||||
FORWARD_CHAIN_EDITED=1
|
||||
else
|
||||
FORWARD_CHAIN_EDITED=0
|
||||
|
@ -1494,9 +1704,8 @@ confNetwork(){
|
|||
|
||||
echo "INPUT_CHAIN_EDITED=${INPUT_CHAIN_EDITED}" >> /tmp/setupVars.conf
|
||||
echo "FORWARD_CHAIN_EDITED=${FORWARD_CHAIN_EDITED}" >> /tmp/setupVars.conf
|
||||
fi
|
||||
|
||||
echo "USING_UFW=${USING_UFW}" >> /tmp/setupVars.conf
|
||||
fi
|
||||
}
|
||||
|
||||
confLogging() {
|
||||
|
@ -1551,6 +1760,21 @@ installPiVPN(){
|
|||
fi
|
||||
}
|
||||
|
||||
restartServices(){
|
||||
echo "::: Restarting services..."
|
||||
case ${PLAT} in
|
||||
Debian|Raspbian|Ubuntu)
|
||||
if [ "$VPN" = "openvpn" ]; then
|
||||
$SUDO systemctl enable openvpn.service &> /dev/null
|
||||
$SUDO systemctl restart openvpn.service
|
||||
elif [ "$VPN" = "wireguard" ]; then
|
||||
$SUDO systemctl enable wg-quick@wg0.service &> /dev/null
|
||||
$SUDO systemctl restart wg-quick@wg0.service
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
askUnattendedUpgrades(){
|
||||
if [ "${runUnattended}" = 'true' ]; then
|
||||
if [ -z "$UNATTUPG" ]; then
|
||||
|
@ -1669,134 +1893,4 @@ All incomplete posts or bug reports will be ignored or deleted.\\n\\nThank you f
|
|||
fi
|
||||
}
|
||||
|
||||
######## SCRIPT ############
|
||||
|
||||
main(){
|
||||
|
||||
######## FIRST CHECK ########
|
||||
# Must be root to install
|
||||
echo ":::"
|
||||
if [[ $EUID -eq 0 ]];then
|
||||
echo "::: You are root."
|
||||
else
|
||||
echo "::: sudo will be used for the install."
|
||||
# Check if it is actually installed
|
||||
# If it isn't, exit because the install cannot complete
|
||||
if [[ $(dpkg-query -s sudo) ]];then
|
||||
export SUDO="sudo"
|
||||
export SUDOE="sudo -E"
|
||||
else
|
||||
echo "::: Please install sudo or run this as root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check arguments for the undocumented flags
|
||||
for var in "$@"; do
|
||||
case "$var" in
|
||||
"--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
|
||||
"--unattended" ) runUnattended=true;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check for supported distribution
|
||||
distroCheck
|
||||
|
||||
# Checks for hostname Length
|
||||
checkHostname
|
||||
|
||||
if [[ "${runUnattended}" == true ]]; then
|
||||
echo "::: --unattended passed to install script, no whiptail dialogs will be displayed"
|
||||
if [ -z "$2" ]; then
|
||||
echo "::: No configuration file passed, using default settings..."
|
||||
else
|
||||
if [ -r "$2" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "$2"
|
||||
else
|
||||
echo "::: Can't open $2"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start the installer
|
||||
# Verify there is enough disk space for the install
|
||||
if [[ "${skipSpaceCheck}" == true ]]; then
|
||||
echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!"
|
||||
else
|
||||
verifyFreeDiskSpace
|
||||
fi
|
||||
|
||||
updatePackageCache
|
||||
|
||||
# Notify user of package availability
|
||||
notifyPackageUpdatesAvailable
|
||||
|
||||
# Install packages used by this installation script
|
||||
preconfigurePackages
|
||||
installDependentPackages BASE_DEPS[@]
|
||||
|
||||
# Display welcome dialogs
|
||||
welcomeDialogs
|
||||
|
||||
# Find interfaces and let the user choose one
|
||||
chooseInterface
|
||||
|
||||
if [ "$PLAT" != "Raspbian" ]; then
|
||||
avoidStaticIPv4Ubuntu
|
||||
else
|
||||
getStaticIPv4Settings
|
||||
setStaticIPv4
|
||||
fi
|
||||
|
||||
# Choose the user for the ovpns
|
||||
chooseUser
|
||||
|
||||
# Clone/Update the repos
|
||||
cloneOrUpdateRepos
|
||||
|
||||
# Install
|
||||
if installPiVPN; then
|
||||
echo "::: Install Complete..."
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "::: Restarting services..."
|
||||
# Start services
|
||||
case ${PLAT} in
|
||||
Debian|Raspbian|Ubuntu)
|
||||
if [ "$VPN" = "openvpn" ]; then
|
||||
$SUDO systemctl enable openvpn.service &> /dev/null
|
||||
$SUDO systemctl start openvpn.service
|
||||
elif [ "$VPN" = "wireguard" ]; then
|
||||
$SUDO systemctl enable wg-quick@wg0.service &> /dev/null
|
||||
$SUDO systemctl start wg-quick@wg0.service
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Ask if unattended-upgrades will be enabled
|
||||
askUnattendedUpgrades
|
||||
|
||||
if [ "$UNATTUPG" -eq 1 ]; then
|
||||
confUnattendedUpgrades
|
||||
fi
|
||||
|
||||
# Save installation setting to the final location
|
||||
echo "TO_INSTALL=(${TO_INSTALL[*]})" >> /tmp/setupVars.conf
|
||||
$SUDO cp /tmp/setupVars.conf "$setupVars"
|
||||
|
||||
installScripts
|
||||
|
||||
# Ensure that cached writes reach persistent storage
|
||||
echo "::: Flushing writes to disk..."
|
||||
sync
|
||||
echo "::: done."
|
||||
|
||||
displayFinalMessage
|
||||
echo ":::"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
BIN
logos.jpg
Normal file
BIN
logos.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
|
@ -52,29 +52,27 @@ fi
|
|||
|
||||
if [ "$USING_UFW" -eq 0 ]; then
|
||||
|
||||
if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then
|
||||
if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables MASQUERADE rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
iptables -t nat -F
|
||||
iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE
|
||||
iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then
|
||||
|
||||
if iptables -C INPUT -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT &> /dev/null; then
|
||||
if iptables -C INPUT -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables INPUT rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT
|
||||
iptables -I INPUT 1 -i "$IPv4dev" -p "$pivpnPROTO" --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
echo "Done"
|
||||
fi
|
||||
|
@ -83,14 +81,14 @@ if [ "$USING_UFW" -eq 0 ]; then
|
|||
|
||||
if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then
|
||||
|
||||
if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT &> /dev/null; then
|
||||
if iptables -C FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables FORWARD rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT
|
||||
iptables -I FORWARD 1 -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
iptables -I FORWARD 2 -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
echo "Done"
|
||||
fi
|
||||
|
@ -109,13 +107,13 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then
|
||||
if iptables -t nat -C POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables MASQUERADE rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
|
|
|
@ -74,22 +74,22 @@ removeAll(){
|
|||
ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null
|
||||
### FIXME: SC2154
|
||||
ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/${subnetClass}" out on "${IPv4dev}" to any > /dev/null
|
||||
sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/${subnetClass} -o ${IPv4dev} -j MASQUERADE\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules
|
||||
iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE
|
||||
sed -z "s/*nat\\n:POSTROUTING ACCEPT \\[0:0\\]\\n-I POSTROUTING -s ${pivpnNET}\\/${subnetClass} -o ${IPv4dev} -j MASQUERADE -m comment --comment ${VPN}-nat-rule\\nCOMMIT\\n\\n//" -i /etc/ufw/before.rules
|
||||
iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule"
|
||||
ufw reload &> /dev/null
|
||||
|
||||
elif [ "$USING_UFW" -eq 0 ]; then
|
||||
|
||||
if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then
|
||||
iptables -D INPUT -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT
|
||||
iptables -D INPUT -i "${IPv4dev}" -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT -m comment --comment "${VPN}-input-rule"
|
||||
fi
|
||||
|
||||
if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then
|
||||
iptables -D FORWARD -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
iptables -D FORWARD -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT
|
||||
iptables -D FORWARD -d "${pivpnNET}/${subnetClass}" -i "${IPv4dev}" -o "${pivpnDEV}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
iptables -D FORWARD -s "${pivpnNET}/${subnetClass}" -i "${pivpnDEV}" -o "${IPv4dev}" -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
fi
|
||||
|
||||
iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE
|
||||
iptables -t nat -D POSTROUTING -s "${pivpnNET}/${subnetClass}" -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
|
||||
fi
|
||||
|
@ -123,11 +123,17 @@ removeAll(){
|
|||
# On armv6l Raspbian we manually remove the kernel module and skip the apt
|
||||
# uninstallation (since it's not an actual package).
|
||||
if [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv6l" ]; then
|
||||
dkms remove wireguard/"${WG_SNAPSHOT}" --all
|
||||
rm -rf /usr/src/wireguard-*
|
||||
dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all
|
||||
rm -rf /usr/src/wireguard-"${WG_MODULE_SNAPSHOT}"
|
||||
break
|
||||
fi
|
||||
|
||||
elif [ "${i}" = "wireguard-tools" ]; then
|
||||
|
||||
if [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv6l" ]; then
|
||||
rm -rf /usr/src/wireguard-tools-"${WG_TOOLS_SNAPSHOT}"
|
||||
fi
|
||||
|
||||
elif [ "${i}" = "dirmngr" ]; then
|
||||
|
||||
# If dirmngr was installed, then we had previously installed wireguard on armv7l Raspbian
|
||||
|
@ -187,7 +193,7 @@ removeAll(){
|
|||
### FIXME SC2154
|
||||
rm -rf "$install_home/configs"
|
||||
elif [ "$VPN" = "openvpn" ]; then
|
||||
rm -f /var/log/*openvpn*
|
||||
rm -rf /var/log/*openvpn*
|
||||
rm -f /etc/openvpn/server.conf
|
||||
rm -f /etc/openvpn/crl.pem
|
||||
rm -rf /etc/openvpn/easy-rsa
|
||||
|
|
|
@ -6,7 +6,14 @@ pivpnrepo="https://github.com/pivpn/pivpn.git"
|
|||
pivpnlocalpath="/etc/.pivpn"
|
||||
pivpnscripts="/opt/pivpn/"
|
||||
bashcompletiondir="/etc/bash_completion.d/"
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
###Functions
|
||||
##Updates scripts
|
||||
|
@ -16,7 +23,7 @@ updatepivpnscripts(){
|
|||
echo "going do update PiVPN Scripts"
|
||||
if [[ -d "$pivpnlocalpath" ]]; then
|
||||
if [[ -n "$pivpnlocalpath" ]]; then
|
||||
sudo rm -rf "${pivpnlocalpath}/../.pivpn"
|
||||
rm -rf "${pivpnlocalpath}/../.pivpn"
|
||||
cloneandupdate
|
||||
fi
|
||||
else
|
||||
|
@ -32,7 +39,7 @@ updatefromtest(){
|
|||
echo "PiVPN Scripts updating from test branch"
|
||||
if [[ -d "$pivpnlocalpath" ]]; then
|
||||
if [[ -n "$pivpnlocalpath" ]]; then
|
||||
rm -rf "{$pivpnlocalpath}/../.pivpn"
|
||||
rm -rf "${pivpnlocalpath}/../.pivpn"
|
||||
cloneupdttest
|
||||
fi
|
||||
else
|
||||
|
@ -41,22 +48,23 @@ updatefromtest(){
|
|||
echo "PiVPN Scripts updated have been updated from test branch"
|
||||
}
|
||||
|
||||
##Clone and copy pivpn scripts to /op/
|
||||
##Clone and copy pivpn scripts to /opt/pivpn
|
||||
cloneandupdate(){
|
||||
sudo git clone "$pivpnrepo" "$pivpnlocalpath"
|
||||
sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
|
||||
sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir"
|
||||
git clone "$pivpnrepo" "$pivpnlocalpath"
|
||||
cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
|
||||
cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir"
|
||||
}
|
||||
|
||||
##same as cloneandupdate() but from test branch
|
||||
##and falls back to master branch again after updating
|
||||
cloneupdttest(){
|
||||
sudo git clone "$pivpnrepo" "$pivpnlocalpath"
|
||||
sudo git -C "$pivpnlocalpath" checkout test
|
||||
sudo git -C "$pivpnlocalpath" pull origin test
|
||||
sudo cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
|
||||
sudo cp "${pivpnlocalpath}"/scripts/bash-completion "$bashcompletiondir"
|
||||
sudo git -C "$pivpnlocalpath" checkout master
|
||||
git clone "$pivpnrepo" "$pivpnlocalpath"
|
||||
git -C "$pivpnlocalpath" checkout test
|
||||
git -C "$pivpnlocalpath" pull origin test
|
||||
cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
|
||||
cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts"
|
||||
cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir"
|
||||
git -C "$pivpnlocalpath" checkout master
|
||||
}
|
||||
|
||||
scriptusage(){
|
|
@ -4,8 +4,8 @@ _pivpn()
|
|||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
dashopts="-a -c -d -l -qr -r -h -u"
|
||||
opts="add clients debug list qrcode remove help uninstall"
|
||||
dashopts="-a -c -d -l -qr -r -h -u -up"
|
||||
opts="add clients debug list qrcode remove help uninstall update"
|
||||
if [ "${#COMP_WORDS[@]}" -eq 2 ]
|
||||
then
|
||||
if [[ ${cur} == -* ]] ; then
|
||||
|
|
39
scripts/wireguard/clientSTAT.sh
Executable file
39
scripts/wireguard/clientSTAT.sh
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd /etc/wireguard/configs
|
||||
if [ ! -s clients.txt ]; then
|
||||
echo "::: There are no clients to list"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
hr(){
|
||||
numfmt --to=iec-i --suffix=B "$1"
|
||||
}
|
||||
|
||||
DUMP="$(wg show wg0 dump | tail -n +2)"
|
||||
|
||||
printf "\e[1m::: Connected Clients List :::\e[0m\n"
|
||||
|
||||
{
|
||||
printf "\e[4mName\e[0m \t \e[4mRemote IP\e[0m \t \e[4mVirtual IP\e[0m \t \e[4mBytes Received\e[0m \t \e[4mBytes Sent\e[0m \t \e[4mLast Seen\e[0m\n"
|
||||
|
||||
while IFS= read -r LINE; do
|
||||
|
||||
PUBLIC_KEY="$(awk '{ print $1 }' <<< "$LINE")"
|
||||
REMOTE_IP="$(awk '{ print $3 }' <<< "$LINE")"
|
||||
VIRTUAL_IP="$(awk '{ print $4 }' <<< "$LINE")"
|
||||
BYTES_RECEIVED="$(awk '{ print $6 }' <<< "$LINE")"
|
||||
BYTES_SENT="$(awk '{ print $7 }' <<< "$LINE")"
|
||||
LAST_SEEN="$(awk '{ print $5 }' <<< "$LINE")"
|
||||
CLIENT_NAME="$(grep "$PUBLIC_KEY" clients.txt | awk '{ print $1 }')"
|
||||
|
||||
if [ "$LAST_SEEN" -ne 0 ]; then
|
||||
printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "$(date -d @"$LAST_SEEN" '+%b %m %Y - %T')"
|
||||
else
|
||||
printf "%s \t %s \t %s \t %s \t %s \t %s\n" "$CLIENT_NAME" "$REMOTE_IP" "${VIRTUAL_IP/\/32/}" "$(hr "$BYTES_RECEIVED")" "$(hr "$BYTES_SENT")" "(not yet)"
|
||||
fi
|
||||
|
||||
done <<< "$DUMP"
|
||||
|
||||
printf "\n"
|
||||
} | column -t -s $'\t'
|
|
@ -6,18 +6,23 @@ if [ ! -s clients.txt ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
printf "\e[1m::: Clients Summary :::\e[0m\n"
|
||||
|
||||
# Present the user with a summary of the clients, fetching info from dates.
|
||||
FORMATTED+=": \e[4mClient\e[0m&\e[4mCreation date\e[0m :\n"
|
||||
{
|
||||
echo -e "\e[4mClient\e[0m \t \e[4mPublic key\e[0m \t \e[4mCreation date\e[0m"
|
||||
|
||||
while read -r LINE; do
|
||||
CLIENT_NAME="$(awk '{print $1}' <<< "$LINE")"
|
||||
|
||||
CREATION_DATE="$(awk '{print $2}' <<< "$LINE")"
|
||||
PUBLIC_KEY="$(awk '{print $2}' <<< "$LINE")"
|
||||
|
||||
CREATION_DATE="$(awk '{print $3}' <<< "$LINE")"
|
||||
|
||||
# Dates are converted from UNIX time to human readable.
|
||||
CD_FORMAT="$(date -d @"$CREATION_DATE" +'%d %b %Y, %H:%M, %Z')"
|
||||
|
||||
FORMATTED+="• $CLIENT_NAME&$CD_FORMAT\n"
|
||||
echo -e "$CLIENT_NAME \t $PUBLIC_KEY \t $CD_FORMAT"
|
||||
done < clients.txt
|
||||
|
||||
echo -e "$FORMATTED" | column -t -s '&'
|
||||
} | column -t -s $'\t'
|
|
@ -79,9 +79,9 @@ echo "::: Client Keys generated"
|
|||
|
||||
# Find an unused number for the last octet of the client IP
|
||||
for i in {2..254}; do
|
||||
if ! grep -q " $i" configs/clients.txt; then
|
||||
if ! grep -q " $i$" configs/clients.txt; then
|
||||
COUNT="$i"
|
||||
echo "${CLIENT_NAME} $(date +%s) ${COUNT}" >> configs/clients.txt
|
||||
echo "${CLIENT_NAME} $(<keys/${CLIENT_NAME}_pub) $(date +%s) ${COUNT}" >> configs/clients.txt
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
|
|
@ -17,7 +17,7 @@ makeConf(){
|
|||
}
|
||||
|
||||
listConnected(){
|
||||
$SUDO wg show
|
||||
$SUDO /opt/pivpn/clientSTAT.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,12 @@ uninstallServer(){
|
|||
exit 0
|
||||
}
|
||||
|
||||
updateScripts(){
|
||||
shift
|
||||
$SUDO /opt/pivpn/update.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
showHelp(){
|
||||
echo "::: Control all PiVPN specific functions!"
|
||||
echo ":::"
|
||||
|
@ -62,6 +68,7 @@ showHelp(){
|
|||
echo "::: -r, remove Remove a client"
|
||||
echo "::: -h, help Show this help dialog"
|
||||
echo "::: -u, uninstall Uninstall pivpn from your system!"
|
||||
echo "::: -up, update Updates PiVPN Scripts"
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
@ -79,5 +86,6 @@ case "$1" in
|
|||
"-r" | "remove" ) removeClient "$@";;
|
||||
"-h" | "help" ) showHelp;;
|
||||
"-u" | "uninstall" ) uninstallServer;;
|
||||
"-up" | "update" ) updateScripts "$@" ;;
|
||||
* ) showHelp;;
|
||||
esac
|
||||
|
|
|
@ -63,20 +63,49 @@ fi
|
|||
|
||||
if [ "$USING_UFW" -eq 0 ]; then
|
||||
|
||||
if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then
|
||||
if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables MASQUERADE rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
iptables -t nat -F
|
||||
iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE
|
||||
iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
iptables-restore < /etc/iptables/rules.v4
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then
|
||||
|
||||
if iptables -C INPUT -i "$IPv4dev" -p udp --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables INPUT rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables INPUT rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
iptables -I INPUT 1 -i "$IPv4dev" -p udp --dport "$pivpnPORT" -j ACCEPT -m comment --comment "${VPN}-input-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then
|
||||
|
||||
if iptables -C FORWARD -s 10.6.0.0/24 -i wg0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables FORWARD rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables FORWARD rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
iptables -I FORWARD 1 -d 10.6.0.0/24 -i "$IPv4dev" -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
iptables -I FORWARD 2 -s 10.6.0.0/24 -i wg0 -o "$IPv4dev" -j ACCEPT -m comment --comment "${VPN}-forward-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
if LANG="en_US.UTF-8" ufw status | grep -qw 'active'; then
|
||||
|
@ -89,13 +118,13 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE &> /dev/null; then
|
||||
if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${IPv4dev}" -j MASQUERADE -m comment --comment "${VPN}-nat-rule" &> /dev/null; then
|
||||
echo ":: [OK] Iptables MASQUERADE rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Iptables MASQUERADE rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
sed "/delete these required/i *nat\n:POSTROUTING ACCEPT [0:0]\n-I POSTROUTING -s 10.6.0.0/24 -o $IPv4dev -j MASQUERADE -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
|
|
|
@ -73,12 +73,14 @@ for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do
|
|||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
|
||||
# Grab the least significant octed of the client IP address
|
||||
COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $3}')
|
||||
# And the creation date of the client
|
||||
CREATION_DATE="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $2}')"
|
||||
COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $4}')
|
||||
# The creation date of the client
|
||||
CREATION_DATE="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $3}')"
|
||||
# And its public key
|
||||
PUBLIC_KEY="$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $2}')"
|
||||
|
||||
# Then remove the client matching the variables above
|
||||
sed "/${CLIENT_NAME} ${CREATION_DATE} ${COUNT}/d" -i configs/clients.txt
|
||||
sed "\#${CLIENT_NAME} ${PUBLIC_KEY} ${CREATION_DATE} ${COUNT}#d" -i configs/clients.txt
|
||||
|
||||
# Remove the peer section from the server config
|
||||
sed "/# begin ${CLIENT_NAME}/,/# end ${CLIENT_NAME}/d" -i wg0.conf
|
||||
|
|
Loading…
Reference in a new issue