mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-19 03:10:16 +00:00
Merge pull request #914 from pivpn/test
Merge test into master PiVPN Wireguard Support, New features, Bugfixes and improvements. Check LatestUpdate.md to find out what changed.
This commit is contained in:
commit
5bfaa95e9f
28 changed files with 3293 additions and 1718 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.diff
|
|
@ -4,8 +4,6 @@ proto udp
|
|||
remote IPv4pub 1194
|
||||
resolv-retry infinite
|
||||
nobind
|
||||
persist-key
|
||||
persist-tun
|
||||
key-direction 1
|
||||
remote-cert-tls server
|
||||
tls-version-min 1.2
|
||||
|
|
227
LatestUpdate.md
227
LatestUpdate.md
|
@ -5,7 +5,147 @@ patch release notes.
|
|||
|
||||
Everytime Test branch is merged into master, a new entry should be created with the date and changes being merged.
|
||||
|
||||
## Oct 12th 2019 - On test
|
||||
## Jan 20th 2020
|
||||
|
||||
- Allow setting DHCP reservation preference with --unattended
|
||||
- Flip condition check on $dhcpReserv: first check if empty, and if not, check if it's not 1.
|
||||
Doing it the other way (first check if not 1) would give a shell error if $dhcpReserv was empty.
|
||||
- Prepend 'pivpn-' to unstable repo files to limit naming conflicts
|
||||
- Update variables inside unattended examples
|
||||
- Remove openvpn logging setting when uninstalling the package
|
||||
- Run 'apt-get update' after removing the WireGuard PPA
|
||||
|
||||
## Jan 18th 2020
|
||||
|
||||
Distro Support, Bug Fixes, Unattended install
|
||||
|
||||
Tested and added Support on Debian 9
|
||||
tested and added support on Ubuntu 16.04 & 18.08
|
||||
* Fixed wireguard not installing, added pkg cache update after adding ppa
|
||||
* added kernel headers to dependencies as its requred for wireguard-dkms
|
||||
unattended install
|
||||
* When user is provided and doest exist, it will create one without password set
|
||||
* Use metapackage to install kernel headers on Ubuntu
|
||||
|
||||
|
||||
## Jan 8th 2020
|
||||
|
||||
Updates and improvements
|
||||
Issue #871: fix backup script
|
||||
|
||||
install.sh
|
||||
installScripts function:
|
||||
update script not being copied over to /opt therefore update funcion was probably broken.
|
||||
changed script to copy all .sh scripts from .pivpn/scripts directory.
|
||||
|
||||
Issue #871: fix backup script
|
||||
I was probably very drunk when i first wrote this backup script.
|
||||
fixed it, now works with new code refactoring,
|
||||
loads vars from setupVars
|
||||
Added backup for wireguard
|
||||
Moved script to global pivpnscripts.
|
||||
Added backup script to bash-completion
|
||||
Added backup script to pivpn script
|
||||
|
||||
update.sh
|
||||
Commented the update from master branch to avoid users trying to update test from master.
|
||||
|
||||
|
||||
Updated LatestChages.md
|
||||
|
||||
## Jan 7th 2020
|
||||
|
||||
Changes for FR #897
|
||||
Support For DHCP IP Reservation
|
||||
|
||||
Main:
|
||||
- added If statement to skipp SetStaticIPv4 if dhcpRserv=1
|
||||
|
||||
getStaticIPv4Settings:
|
||||
- Added Whiptail asking if user wants to use DHCP reservation Settings, this will add dhcpReserv and
|
||||
skip setStaticIPv4 while still logging everything.
|
||||
ConfigExample files:
|
||||
- Added staticReserv=0 to config examples. so it can be used with Unattended install
|
||||
* 0 means static ip will be setup.
|
||||
* 1 means DHCP Reservation will be used and no chage will be made to the interfaces
|
||||
|
||||
|
||||
Updated LatestChanges
|
||||
|
||||
## Jan 6th 2020
|
||||
|
||||
* Removed Unecessary pipe on availableInterfaces
|
||||
* Changed OS Support messages accross the script
|
||||
- Removed OS Version names from the script, this avoids having to change the code everytime a new OS Version is Released, instead we update the wiki with propper information.
|
||||
* Changed MaybeOSSupport whiptail tiltes and messages to make it more clear.
|
||||
- Messages and titles could cause confusion to users and specially developers
|
||||
* Moved Funcions Comment to correct place.
|
||||
* DistroCheck Function:
|
||||
- Moved up before other functions so it better refflects the order they are called.
|
||||
- changed Case identation to make it easier to read.
|
||||
- Added info to # compatibility Comment, Removed unecessary comments
|
||||
- added break to exit out of case, easier to understand that the script should move on.
|
||||
* Added Shellcheck ignores,
|
||||
* chooseinterface Function:
|
||||
- Changed function Logic and cleaned it up
|
||||
- Fixed Issue #906
|
||||
- Added exit code if no interfaces are found
|
||||
* Updated LatestUpdate.md
|
||||
* Use radiolist to select a VPN
|
||||
|
||||
## Jan 3rd 2020
|
||||
|
||||
- Revise route query for IP & GW selection from Quad9 to TEST-NET-1
|
||||
- Replace mention of 'Google' with 'Quad9'
|
||||
|
||||
## Jan 2nd 2020
|
||||
|
||||
- Fix mv command when copying the DH parameters to final destination
|
||||
|
||||
## Dec 30th 2019
|
||||
|
||||
- Fix paths inside the update script
|
||||
- Use the wireguard script for WireGuard as well
|
||||
- Updated the README in accordance to changes in the test branch
|
||||
|
||||
## Dec 29th 2019
|
||||
|
||||
* Handle running the install script over an existing installation (as the script already did before branching to test-wireguard), providing:
|
||||
- Update, downloads latest scripts from git repo
|
||||
- Repair, reinstall PiVPN while keeping existing settings
|
||||
- Reconfigure, start over overwriting the existing settings
|
||||
* Tag iptables rules as an attempt to make sure that the uninstall script only removes PiVPN rules
|
||||
* Change the armv6l installation to reflect the split of WireGuard snapshots into wireguard-linux-compat and wireguard-tools
|
||||
|
||||
## Dec 27th 2019
|
||||
|
||||
- When suggesting to use Pi-hole, use the VPN server IP instead of the LAN IP to allow DNS resolution even if the user does not route the local network through the tunnel.
|
||||
- Format listCONF in a similar way as listOVPN
|
||||
- Specifically look for a free octet in the last word of clients.txt and not just any word.
|
||||
Necessary otherwhise public keys starting with a number will match against an octet.
|
||||
Example: if line is 'name 5abcdefgh 4', then looking for ' 5' will match but '5$' will
|
||||
not (correctly).
|
||||
- 'pivpn -c' will show the Connected Clients List for WireGuard too
|
||||
|
||||
## Dec 10th 2019
|
||||
|
||||
- Use dedicated openvpn user and group for increased security
|
||||
- Added basic safeguards to avoid wrecking /etc/ufw/before.rules
|
||||
- Applied some Shellcheck suggested changes.
|
||||
- Added safeguards to rm -rf when downloading the git repo.
|
||||
- Use more variables instead of hardcoding data
|
||||
- Add local resolver as DNS option
|
||||
|
||||
## Dec 3rd 2019
|
||||
|
||||
- Better client stats formatting
|
||||
|
||||
## Dec 2nd 2019
|
||||
|
||||
* Properly avoid pulling unwanted packages from unstable repo:
|
||||
- Currently apt pulls all packages from the unstable repo because the script intendation created the file 'limit-unstable' with tabs in it. Fixed using printf to create a multiline file.
|
||||
- Accept debug fixes using just the enter key
|
||||
|
||||
## Nov 25th 2019 - On Master
|
||||
|
||||
* Changed pivpn command exit codes from 1 to 0
|
||||
|
@ -16,25 +156,61 @@ Everytime Test branch is merged into master, a new entry should be created with
|
|||
- the script now checks for hostname length right at the beginning and prompts for a new one.
|
||||
- HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only.
|
||||
* fixed ubuntu 18.04 being detected as not supported OS, now fully supported and tested.
|
||||
* changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all *.sh files making it easier to manage when adding new scripts/features
|
||||
* changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all `*.sh` files making it easier to manage when adding new scripts/features
|
||||
* Changed how supported OS are presented when maybeOS_Support() is called.
|
||||
|
||||
## Sept 1st 2019
|
||||
## Nov 19th 2019
|
||||
|
||||
* Added support for Buster
|
||||
* .ovpn12 files making use of iOS keychain
|
||||
* Leverage the Hostname of the Server to generate server uuid
|
||||
* integrated support to bitwarden password manager into pivpn
|
||||
* Recreate ovpn folder if deleted
|
||||
* Handle older UFW version from Jessie
|
||||
* Only use iptables-legacy if platform is Buster
|
||||
* improved Buester and Jessie IPtables / ufw handling
|
||||
* bugfixes and typos
|
||||
* permissions hardening and writing uniformization
|
||||
* improved pivpn user and ovpns dirs handling
|
||||
* Changes variable and file naming in `install.sh`
|
||||
- $pivPNUser renamed to $INSTALL_USER
|
||||
- /tmp/pivpnUSR renamed to INSTALL_USER
|
||||
- Added Ubuntu Bionic support
|
||||
|
||||
## Nov 16th 2019
|
||||
|
||||
- Added back unattended installation: as expected, the user can call the install script with --unattended followed by a config file and PiVPN will be installed non-interactively.
|
||||
- Removed persist-key and persist-tun from the client config.
|
||||
- Reverted keepalive setting on the server to smaller values.
|
||||
- See @TinCanTech's posts for the reasons of the above two: #864 (comment)
|
||||
- Copied validDomain() function from the test branch.
|
||||
- Removed 1024 bit certificate options, since on Buster OpenVPN does not start with such small certificates (It's related to OpenSSL 1.1.1).
|
||||
- Backup /etc/openvpn and /etc/wireguard before installing.
|
||||
- Always remove VPN configuration when uninstalling, but do not wipe the folder, just remove what PiVPN added.
|
||||
- Fetch latest WireGuard snapshot instead of hardcoding it into the script.
|
||||
|
||||
## Nov 7th 2019
|
||||
|
||||
- Add back the uninstall script
|
||||
- Only uninstall packages that were not already installed when running the PiVPN install script.
|
||||
- Detect and offer to use Pi-hole
|
||||
- Use checkinstall to install wireguard-tools for easy uninstallation
|
||||
- Added missing dkms dependency
|
||||
|
||||
## Oct 19th 2019
|
||||
|
||||
- MakeOVPN has been updated to include the -i iOS function to allow users to create an OVPN12 format file that can be used with the iOS keychain.
|
||||
- Check if -i iOS can be used (can't be used with ECDSA certificates).
|
||||
- Fixed the issues with special characters in OVPN12 files.
|
||||
|
||||
## Oct 17th 2019
|
||||
|
||||
- Allow subdomain in custom DNS search list.
|
||||
- Unified PiVPN configuration into the single /etc/pivpn/setupVars.conf file.
|
||||
- Functions that ask the user for the port, protocol, dns, domain don't apply the setting anymore, they only save the variable on disk. Settings are applied in confOpenVPN, confOVPN, confWireGuard.
|
||||
- Support and use WireGuard by default with an initial set of scripts matching current PiVPN scripts (list, create, remove clients).
|
||||
- Removed OpenVPN ECDSA option.
|
||||
- Renamed some variables (see pull request 849).
|
||||
- Refactored several functions.
|
||||
|
||||
## Oct 12th 2019 - On test
|
||||
|
||||
* Changed pivpn command exit codes from 1 to 0
|
||||
- exit code 1 means general error hence should not be used for exiting successfully
|
||||
* added backup script to backup openvpn and pivpn generated certificates
|
||||
* added update script to update /opt/pivpn scripts, -t | --test | test update from test branch
|
||||
* Fixed hostname length issue #831
|
||||
- the script now checks for hostname length right at the beginning and prompts for a new one.
|
||||
- HOST_NAME to host_name, as best practice variables with capitals, should be used by system variables only.
|
||||
* fixed ubuntu 18.04 being detected as not supported OS, now fully supported and tested.
|
||||
* changed how scripts are copied to /opt/pivpn, it hat a lot of long repetitive lines, now it copies all `*.sh` files making it easier to manage when adding new scripts/features
|
||||
* Changed how supported OS are presented when maybeOS_Support() is called.
|
||||
|
||||
### Merge Patch, Sept 2nd 2019
|
||||
|
||||
|
@ -52,4 +228,19 @@ Everytime Test branch is merged into master, a new entry should be created with
|
|||
* General improvments:
|
||||
- when runing updates, sudo password prompt now shows up in a new line
|
||||
|
||||
----
|
||||
## Sept 1st 2019
|
||||
|
||||
* Added support for Buster
|
||||
* .ovpn12 files making use of iOS keychain
|
||||
* Leverage the Hostname of the Server to generate server uuid
|
||||
* integrated support to bitwarden password manager into pivpn
|
||||
* Recreate ovpn folder if deleted
|
||||
* Handle older UFW version from Jessie
|
||||
* Only use iptables-legacy if platform is Buster
|
||||
* improved Buester and Jessie IPtables / ufw handling
|
||||
* bugfixes and typos
|
||||
* permissions hardening and writing uniformization
|
||||
* improved pivpn user and ovpns dirs handling
|
||||
* Changes variable and file naming in `install.sh`
|
||||
- $pivPNUser renamed to $INSTALL_USER
|
||||
- /tmp/pivpnUSR renamed to INSTALL_USER
|
||||
|
|
225
README.md
225
README.md
|
@ -1,84 +1,123 @@
|
|||
![WireGuard + OpenVPN logo](logos.jpg)
|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
Visit the [PiVPN](https://pivpn.dev) site for more information.
|
||||
This is a set of shell scripts developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM)
|
||||
into a VPN server using the free, open-source [OpenVPN](https://openvpn.net) software.
|
||||
This is a set of shell scripts initially developed by **@0-kaladin** that serve to easily turn your Raspberry Pi (TM)
|
||||
into a VPN server using two free, open-source protocols:
|
||||
* [WireGuard](https://www.wireguard.com/)
|
||||
* [OpenVPN](https://openvpn.net)
|
||||
|
||||
Have you been looking for a good guide or tutorial for installing openvpn on a raspberry pi or ubuntu based server? Run this script and you don't need a guide or tutorial, this will do it all for you, in a fraction of the time and with hardened security settings in place by default.
|
||||
Have you been looking for a good guide or tutorial for 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 OpenVPN on Raspbian
|
||||
Jessie, Stretch, Devuan and has been tested on Ubuntu 14.04 and 16.04 running from an Amazon AWS image.
|
||||
We recommend using the Stretch or Jessie Lite image on a raspberry pi in your home so you can VPN into your home from unsecure remote locations and safely use the internet. However, the scripts do try to detect different distributions and make adjustments accordingly. They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables.
|
||||
The master branch of this script installs and configures either WireGuard or OpenVPN on Raspbian, Debian or Ubuntu and it as been tested to run not only on Raspberry Pi but also in any Cloud Provider VPS.
|
||||
We recommend using the latest Raspbian Lite image on a Raspberry Pi in your home so you can VPN into your home from a unsecure remote locations and safely use the internet.
|
||||
However, the scripts do try to detect different distributions and make adjustments accordingly.
|
||||
They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables.
|
||||
|
||||
This scripts primary mission in life is to allow a user to have a home VPN for as cost effective as possible and without being a technical wizard. Hence the design of pivpn to work on a Raspberry Pi ($35) and then one command installer. Followed by easy management of the VPN thereafter with the 'pivpn' command. That being said...
|
||||
This scripts primary mission in life is to allow a user to have a home VPN for as cost effective as possible and without being a technical wizard.
|
||||
Hence the design of pivpn to work on a Raspberry Pi ($35) and then one command installer.
|
||||
Followed by easy management of the VPN thereafter with the 'pivpn' command.
|
||||
That being said...
|
||||
|
||||
> This will also work on a free-tier Amazon AWS server using Ubuntu 14.04 - 16.04. I don't want to support every scenario there but getting it to run and install successfully on a free server in the cloud was also important. Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the amazon infrastructure.
|
||||
> This will also work on a free-tier Amazon AWS server using Ubuntu or Debian. I don't want to support every scenario there but getting it to run and install successfully on a free server in the cloud was also important.
|
||||
Many people have untrustworthy ISP's so running on a server elsewhere means you can connect to the VPN from home and your ISP will just see encrypted traffic as your traffic will now be leaving out the Amazon infrastructure.
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
To follow this guide and use the script to setup OpenVPN, you will need to have
|
||||
a Raspberry Pi Model B or later with an ethernet port, an SD or microSD card
|
||||
(depending on the model) with Raspbian installed, a power adapter appropriate to
|
||||
the power needs of your model, and an ethernet cable or wifi adapter to connect your Pi to your
|
||||
router or gateway. It is recommended that you use a fresh image of Raspbian
|
||||
Stretch Lite from https://raspberrypi.org/downloads, but if you don't,
|
||||
be sure to make a backup image of your existing installation before proceeding.
|
||||
You should also setup your Pi with a static IP address (see either source
|
||||
1 or 2 at the bottom of this Readme) but it is not required as the script can do this for you.
|
||||
You will need to have your router forward UDP port 1194 (or whatever custom port you may have chose in the installer)
|
||||
(varies by model & manufacturer; consult your router manufacturer's
|
||||
documentation to do this).
|
||||
Enabling SSH on your Pi is also highly recommended, so that
|
||||
you can run a very compact headless server without a monitor or keyboard and
|
||||
be able to access it even more conveniently (This is also covered by source 2).
|
||||
To follow this guide and use the script to setup a VPN, you will need to have
|
||||
a Raspberry Pi Model B or later with, an SD or microSD card with Raspbian installed,
|
||||
a power adapter appropriate to the power needs of your model, and an ethernet cable or wifi
|
||||
adapter to connect your Pi to your router or gateway.
|
||||
It is recommended that you use a fresh image of the latest Raspbian Lite from
|
||||
https://raspberrypi.org/downloads, but if you don't, be sure to make a backup
|
||||
image of your existing installation before proceeding.
|
||||
You should also setup your Pi with a static IP address
|
||||
(see either source 1 or 2 at the bottom of this Readme)
|
||||
but it is not required as the script can do this for you.
|
||||
You will need to have your router forwarding UDP port 1194 or whatever custom
|
||||
port you may have chose in the installer
|
||||
(varies by model & manufacturer; consult your router manufacturer's documentation to do this).
|
||||
Enabling SSH on your Pi is also highly recommended, so that you can run a very
|
||||
compact headless server without a monitor or keyboard and be able to access it
|
||||
even more conveniently (This is also covered by source 2).
|
||||
|
||||
|
||||
Installation
|
||||
-----------------
|
||||
|
||||
|
||||
```shell
|
||||
**Method 1**
|
||||
```Shell
|
||||
curl -L https://install.pivpn.dev | bash
|
||||
```
|
||||
|
||||
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:
|
||||
**Method 2**
|
||||
```Shell
|
||||
curl -L https://install.pivpn.dev > pivpn.sh
|
||||
sudo sh pivpn.sh
|
||||
```
|
||||
|
||||
**Method 3**
|
||||
```Shell
|
||||
git clone https://github.com/pivpn/pivpn.git
|
||||
sudo sh pivpn/auto_install/install.sh
|
||||
```
|
||||
|
||||
**OBS:**
|
||||
In alternative to install.pivpn.dev you can use the raw github link:
|
||||
https://raw.githubusercontent.com/pivpn/pivpn/master/auto_install/install.sh
|
||||
|
||||
**To install from Test/Development branch**
|
||||
|
||||
Check our [Wiki Page](https://github.com/pivpn/pivpn/wiki#testing)
|
||||
|
||||
**How it works**
|
||||
|
||||
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
|
||||
|
@ -87,48 +126,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
|
||||
--------
|
||||
|
@ -157,6 +227,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
|
||||
-------------
|
||||
|
||||
|
@ -175,6 +248,8 @@ sources.
|
|||
|
||||
3. Of course there is [OpenVPN](https://openvpn.net)
|
||||
|
||||
4. And as always the ever vigilant [EFF](https://www.eff.org/)
|
||||
4. Also [WireGuard](https://www.wireguard.com/)
|
||||
|
||||
5. And as always the ever vigilant [EFF](https://www.eff.org/)
|
||||
|
||||
PiVPN is not taking donations at this time but if you want to show your appreciation, then contribute or leave feedback on suggestions or improvements.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,59 @@
|
|||
server:
|
||||
# If no logfile is specified, syslog is used
|
||||
logfile: "/var/log/unbound/unbound.log"
|
||||
verbosity: 0
|
||||
#interface: 127.0.0.1
|
||||
interface: 10.8.0.1
|
||||
access-control: 127.0.0.0/8 allow
|
||||
### FIXME: once config storage is up, use pivpnNet
|
||||
access-control: 10.6.0.0/8 allow
|
||||
access-control: 10.8.0.0/8 allow
|
||||
|
||||
#port: 53
|
||||
do-ip4: yes
|
||||
do-udp: yes
|
||||
do-tcp: yes
|
||||
|
||||
# May be set to yes if you have IPv6 connectivity
|
||||
do-ip6: no
|
||||
|
||||
# Use this only when you downloaded the list of primary root servers!
|
||||
# Download:
|
||||
# wget https://www.internic.net/domain/named.root -O /var/lib/unbound/root.hints
|
||||
# curl https://www.internic.net/domain/named.root -o /var/lib/unbound/root.hints
|
||||
root-hints: "/var/lib/unbound/root.hints"
|
||||
|
||||
# Trust glue only if it is within the servers authority
|
||||
harden-glue: yes
|
||||
|
||||
# Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS
|
||||
harden-dnssec-stripped: yes
|
||||
|
||||
# Don't use Capitalization randomization as it is known to cause DNSSEC issues sometimes
|
||||
# see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details
|
||||
use-caps-for-id: no
|
||||
|
||||
# Reduce EDNS reassembly buffer size.
|
||||
# Suggested by the unbound man page to reduce fragmentation reassembly problems
|
||||
edns-buffer-size: 1472
|
||||
|
||||
# Perform prefetching of close to expired message cache entries
|
||||
# This only applies to domains that have been frequently queried
|
||||
prefetch: yes
|
||||
|
||||
# One thread should be sufficient, can be increased on beefy machines. In reality for most users running on small networks or on a single machine it should be unnecessary to seek performance enhancement by increasing num-threads above 1.
|
||||
num-threads: 1
|
||||
|
||||
# Ensure kernel buffer is large enough to not lose messages in traffic spikes
|
||||
so-rcvbuf: 1m
|
||||
|
||||
# Ensure privacy of local IP ranges
|
||||
private-address: 192.168.0.0/16
|
||||
private-address: 169.254.0.0/16
|
||||
private-address: 172.16.0.0/12
|
||||
private-address: 10.0.0.0/8
|
||||
private-address: fd00::/8
|
||||
private-address: fe80::/10
|
||||
|
||||
### EOF
|
||||
### vim:tw=256:et:sts=2:st=2:sw=2:com+=b\:###:fo+=cqtr:tags=ctags:
|
BIN
logos.jpg
Normal file
BIN
logos.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
|
@ -1,22 +1,40 @@
|
|||
#!/bin/bash
|
||||
install_user=$(</etc/pivpn/INSTALL_USER)
|
||||
install_home=$(grep -m1 "^${install_user}:" /etc/passwd | cut -d: -f6)
|
||||
install_home=${install_home%/} # remove possible trailing slash
|
||||
# shellcheck disable=SC1091
|
||||
source /etc/pivpn/setupVars.conf
|
||||
# shellcheck disable=SC1090
|
||||
backupdir=pivpnbackup
|
||||
openvpndir=/etc/openvpn
|
||||
ovpnsdir=${install_home}/ovpns
|
||||
date=$(date +%Y-%m-%d-%H%M%S)
|
||||
date=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
checkbackupdir(){
|
||||
|
||||
backup_openvpn(){
|
||||
if [[ ! -d $install_home/$backupdir ]]; then
|
||||
mkdir $install_home/$backupdir
|
||||
mkdir -p "$install_home"/"$backupdir"
|
||||
fi
|
||||
cp -r $openvpndir $ovpnsdir $backupdir 2&>1
|
||||
backupzip=$date-pivpnbackup.tgz
|
||||
tar -czf $backupzip -C ${install_home} $backupdir 2&>1
|
||||
echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
|
||||
}
|
||||
|
||||
backup_openvpn(){
|
||||
|
||||
openvpndir=/etc/openvpn
|
||||
ovpnsdir=${install_home}/ovpns
|
||||
checkbackupdir
|
||||
backupzip=$date-pivpnovpnbackup.tgz
|
||||
# shellcheck disable=SC2210
|
||||
tar czpf "$install_home"/"$backupdir"/"$backupzip" "$openvpndir" "$ovpnsdir" > /dev/null 2>&1
|
||||
echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
|
||||
}
|
||||
|
||||
backup_wireguard(){
|
||||
|
||||
wireguarddir=/etc/wireguard
|
||||
configsdir=${install_home}/configs
|
||||
checkbackupdir
|
||||
backupzip=$date-pivpnwgbackup.tgz
|
||||
tar czpf "$install_home"/"$backupdir"/"$backupzip" "$wireguarddir" "$configsdir" > /dev/null 2>&1
|
||||
echo -e "Backup crated to $install_home/$backupdir/$backupzip \nTo restore the backup, follow instructions at:\nhttps://github.com/pivpn/pivpn/wiki/FAQ#how-can-i-migrate-my-configs-to-another-pivpn-instance"
|
||||
|
||||
}
|
||||
|
||||
if [[ ! $EUID -eq 0 ]];then
|
||||
if [[ $(dpkg-query -s sudo) ]];then
|
||||
|
@ -27,5 +45,8 @@ if [[ ! $EUID -eq 0 ]];then
|
|||
fi
|
||||
fi
|
||||
|
||||
backup_openvpn
|
||||
|
||||
if [[ "${VPN}" == "wireguard" ]]; then
|
||||
backup_wireguard
|
||||
else
|
||||
backup_openvpn
|
||||
fi
|
||||
|
|
|
@ -4,8 +4,8 @@ _pivpn()
|
|||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
dashopts="-a -c -d -l -r -h -u -up"
|
||||
opts="debug add clients list revoke uninstall help update"
|
||||
dashopts="-a -c -d -l -r -h -u -up -bk"
|
||||
opts="debug add clients list revoke uninstall help update backup"
|
||||
if [ "${#COMP_WORDS[@]}" -eq 2 ]
|
||||
then
|
||||
if [[ ${cur} == -* ]] ; then
|
|
@ -17,14 +17,16 @@ printf ": NOTE : The output below is NOT real-time!\n"
|
|||
printf ": : It may be off by a few minutes.\n"
|
||||
printf "\n"
|
||||
printf "\e[1m::: Client Status List :::\e[0m\n"
|
||||
printf "\t\t\t\t\t\t\t\tBytes\t\tBytes\t\n"
|
||||
printf "\e[4mName\e[0m\t\t\t\e[4mRemote IP\e[0m\t\t\e[4mVirtual IP\e[0m\t\e[4mReceived\e[0m\t\e[4mSent\e[0m\t\t\e[4mConnected Since\e[0m \n"
|
||||
|
||||
{
|
||||
printf "\e[4mName\e[0m \t \e[4mRemote IP\e[0m \t \e[4mVirtual IP\e[0m \t \e[4mBytes Received\e[0m \t \e[4mBytes Sent\e[0m \t \e[4mConnected Since\e[0m\n"
|
||||
|
||||
if grep -q "^CLIENT_LIST" "${STATUS_LOG}"; then
|
||||
if [ -n "$(type -t numfmt)" ]; then
|
||||
while read -r line; do
|
||||
read -r -a array <<< $line
|
||||
[[ ${array[0]} = CLIENT_LIST ]] || continue
|
||||
printf "%s\t\t%s\t%s\t%s\t\t%s\t\t%s %s %s - %s\n" ${array[1]} ${array[2]} ${array[3]} $(hr ${array[4]}) $(hr ${array[5]}) ${array[7]} ${array[8]} ${array[10]} ${array[9]}
|
||||
printf "%s \t %s \t %s \t %s \t %s \t %s %s %s - %s\n" ${array[1]} ${array[2]} ${array[3]} $(hr ${array[4]}) $(hr ${array[5]}) ${array[7]} ${array[8]} ${array[10]} ${array[9]}
|
||||
done <$STATUS_LOG
|
||||
else
|
||||
awk -F' ' -v s='CLIENT_LIST' '$1 == s {print $2"\t\t"$3"\t"$4"\t"$5"\t\t"$6"\t\t"$8" "$9" "$11" - "$10"\n"}' ${STATUS_LOG}
|
||||
|
@ -33,3 +35,4 @@ else
|
|||
printf "\nNo Clients Connected!\n"
|
||||
fi
|
||||
printf "\n"
|
||||
} | column -t -s $'\t'
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
# Create OVPN Client
|
||||
# Default Variable Declarations
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
DEFAULT="Default.txt"
|
||||
FILEEXT=".ovpn"
|
||||
CRT=".crt"
|
||||
|
@ -8,9 +9,13 @@ KEY=".key"
|
|||
CA="ca.crt"
|
||||
TA="ta.key"
|
||||
INDEX="/etc/openvpn/easy-rsa/pki/index.txt"
|
||||
INSTALL_USER=$(</etc/pivpn/INSTALL_USER)
|
||||
INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6)
|
||||
INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Create a client ovpn profile, optional nopass"
|
||||
|
@ -28,10 +33,10 @@ helpFunc() {
|
|||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
if [ ! -f /etc/pivpn/HELP_SHOWN ]; then
|
||||
if [ -z "$HELP_SHOWN" ]; then
|
||||
helpFunc
|
||||
echo
|
||||
touch /etc/pivpn/HELP_SHOWN
|
||||
echo "HELP_SHOWN=1" >> "$setupVars"
|
||||
fi
|
||||
|
||||
# Parse input arguments
|
||||
|
@ -70,13 +75,7 @@ do
|
|||
DAYS="$_val"
|
||||
;;
|
||||
-i|--iOS)
|
||||
OVPN12_Compatible=$(cat /etc/pivpn/OVPN12_Compatible)
|
||||
if [[ ${OVPN12_Compatible} == "true" ]]; then
|
||||
iOS=1
|
||||
else
|
||||
echo "This function is not compatable with OVPN 2.4"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
-h|--help)
|
||||
helpFunc
|
||||
|
@ -213,9 +212,10 @@ EOF
|
|||
}
|
||||
|
||||
#make sure ovpns dir exists
|
||||
if [ ! -d "$INSTALL_HOME/ovpns" ]; then
|
||||
mkdir "$INSTALL_HOME/ovpns"
|
||||
chmod 0750 "$INSTALL_HOME/ovpns"
|
||||
if [ ! -d "$install_home/ovpns" ]; then
|
||||
mkdir "$install_home/ovpns"
|
||||
chown "$install_user":"$install_user" "$install_home/ovpns"
|
||||
chmod 0750 "$install_home/ovpns"
|
||||
fi
|
||||
|
||||
#bitWarden
|
||||
|
@ -341,16 +341,10 @@ if [ "$iOS" = "1" ]; then
|
|||
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' < "issued/${NAME}${CRT}"
|
||||
echo "</cert>"
|
||||
|
||||
#Finally, append the TA Private Key
|
||||
if [ -f /etc/pivpn/TWO_POINT_FOUR ]; then
|
||||
echo "<tls-crypt>"
|
||||
cat "${TA}"
|
||||
echo "</tls-crypt>"
|
||||
else
|
||||
#Finally, append the tls Private Key
|
||||
echo "<tls-auth>"
|
||||
cat "${TA}"
|
||||
echo "</tls-auth>"
|
||||
fi
|
||||
|
||||
} > "${NAME}${FILEEXT}"
|
||||
|
||||
|
@ -361,9 +355,9 @@ if [ "$iOS" = "1" ]; then
|
|||
printf "Please remember the export password\n"
|
||||
printf "as you will need this import the certificate on your iOS device\n"
|
||||
printf "========================================================\n"
|
||||
openssl pkcs12 -passin pass:"$PASSWD_UNESCAPED" -export -in "issued/${NAME}${CRT}" -inkey "private/${NAME}${KEY}" -certfile ${CA} -name "${NAME}" -out "/home/$INSTALL_USER/ovpns/$NAME.ovpn12"
|
||||
chown "$INSTALL_USER" "/home/$INSTALL_USER/ovpns/$NAME.ovpn12"
|
||||
chmod 600 "/home/$INSTALL_USER/ovpns/$NAME.ovpn12"
|
||||
openssl pkcs12 -passin pass:"$PASSWD_UNESCAPED" -export -in "issued/${NAME}${CRT}" -inkey "private/${NAME}${KEY}" -certfile ${CA} -name "${NAME}" -out "$install_home/ovpns/$NAME.ovpn12"
|
||||
chown "$install_user":"$install_user" "$install_home/ovpns/$NAME.ovpn12"
|
||||
chmod 640 "$install_home/ovpns/$NAME.ovpn12"
|
||||
printf "========================================================\n"
|
||||
printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME.ovpn12"
|
||||
printf "You will need to transfer both the .ovpn and .ovpn12 files\n"
|
||||
|
@ -392,15 +386,9 @@ else
|
|||
echo "</key>"
|
||||
|
||||
#Finally, append the tls Private Key
|
||||
if [ -f /etc/pivpn/TWO_POINT_FOUR ]; then
|
||||
echo "<tls-crypt>"
|
||||
cat "${TA}"
|
||||
echo "</tls-crypt>"
|
||||
else
|
||||
echo "<tls-auth>"
|
||||
cat "${TA}"
|
||||
echo "</tls-auth>"
|
||||
fi
|
||||
|
||||
} > "${NAME}${FILEEXT}"
|
||||
|
||||
|
@ -408,15 +396,15 @@ fi
|
|||
|
||||
|
||||
# Copy the .ovpn profile to the home directory for convenient remote access
|
||||
cp "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" "$INSTALL_HOME/ovpns/$NAME$FILEEXT"
|
||||
chown "$INSTALL_USER" "$INSTALL_HOME/ovpns/$NAME$FILEEXT"
|
||||
cp "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT" "$install_home/ovpns/$NAME$FILEEXT"
|
||||
chown "$install_user":"$install_user" "$install_home/ovpns/$NAME$FILEEXT"
|
||||
chmod 640 "/etc/openvpn/easy-rsa/pki/$NAME$FILEEXT"
|
||||
chmod 640 "$INSTALL_HOME/ovpns/$NAME$FILEEXT"
|
||||
chmod 640 "$install_home/ovpns/$NAME$FILEEXT"
|
||||
printf "\n\n"
|
||||
printf "========================================================\n"
|
||||
printf "\e[1mDone! %s successfully created!\e[0m \n" "$NAME$FILEEXT"
|
||||
printf "%s was copied to:\n" "$NAME$FILEEXT"
|
||||
printf " %s/ovpns\n" "$INSTALL_HOME"
|
||||
printf " %s/ovpns\n" "$install_home"
|
||||
printf "for easy transfer. Please use this profile only on one\n"
|
||||
printf "device and create additional profiles for other devices.\n"
|
||||
printf "========================================================\n\n"
|
2
pivpn → scripts/openvpn/pivpn
Normal file → Executable file
2
pivpn → scripts/openvpn/pivpn
Normal file → Executable file
|
@ -6,7 +6,7 @@ if [[ ! $EUID -eq 0 ]];then
|
|||
export SUDO="sudo"
|
||||
else
|
||||
echo "::: Please install sudo or run this as root."
|
||||
exit 0
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
# This scripts runs as root
|
||||
|
||||
PORT=$(cat /etc/pivpn/INSTALL_PORT)
|
||||
PROTO=$(cat /etc/pivpn/INSTALL_PROTO)
|
||||
IPv4dev="$(cat /etc/pivpn/pivpnINTERFACE)"
|
||||
REMOTE="$(grep 'remote ' /etc/openvpn/easy-rsa/pki/Default.txt | awk '{print $2}')"
|
||||
NO_UFW=$(cat /etc/pivpn/NO_UFW)
|
||||
OLD_UFW=$(cat /etc/pivpn/NO_UFW)
|
||||
INPUT_CHAIN_EDITED="$(cat /etc/pivpn/INPUT_CHAIN_EDITED)"
|
||||
FORWARD_CHAIN_EDITED="$(cat /etc/pivpn/FORWARD_CHAIN_EDITED)"
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
ERR=0
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::"
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
|
||||
|
@ -25,13 +25,13 @@ for filename in /etc/pivpn/*; do
|
|||
done
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\e[4msetupVars file shown below\e[0m\t ::::"
|
||||
sed "s/$REMOTE/REMOTE/" < /etc/pivpn/setupVars.conf
|
||||
sed "s/$pivpnHOST/REDACTED/" < /etc/pivpn/setupVars.conf
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \e[4mServer configuration shown below\e[0m ::::"
|
||||
cat /etc/openvpn/server.conf
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \e[4mClient template file shown below\e[0m ::::"
|
||||
sed "s/$REMOTE/REMOTE/" < /etc/openvpn/easy-rsa/pki/Default.txt
|
||||
sed "s/$pivpnHOST/REDACTED/" < /etc/openvpn/easy-rsa/pki/Default.txt
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \t\e[4mRecursive list of files in\e[0m\t ::::\n::: \e[4m/etc/openvpn/easy-rsa/pki shows below\e[0m :::"
|
||||
ls -LR /etc/openvpn/easy-rsa/pki/ -Ireqs -Icerts_by_serial
|
||||
|
@ -43,38 +43,36 @@ if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then
|
|||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf
|
||||
sysctl -p
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$NO_UFW" -eq 1 ]; then
|
||||
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]$ ]]; then
|
||||
iptables -t nat -F
|
||||
iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
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 "$PROTO" --dport "$PORT" -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]$ ]]; then
|
||||
iptables -I INPUT 1 -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
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 [ "$NO_UFW" -eq 1 ]; 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]$ ]]; 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
|
||||
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 -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
|
||||
|
@ -104,61 +102,46 @@ else
|
|||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
ufw enable
|
||||
fi
|
||||
fi
|
||||
|
||||
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]$ ]]; 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
|
||||
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 -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if iptables -C ufw-user-input -p "${PROTO}" --dport "${PORT}" -j ACCEPT &> /dev/null; then
|
||||
if iptables -C ufw-user-input -p "${pivpnPROTO}" --dport "${pivpnPORT}" -j ACCEPT &> /dev/null; then
|
||||
echo ":: [OK] Ufw input rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
ufw insert 1 allow "$PORT"/"$PROTO"
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
ufw insert 1 allow "$pivpnPORT"/"$pivpnPROTO"
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$OLD_UFW" -eq 1 ]; then
|
||||
FORWARD_POLICY="$(iptables -S FORWARD | grep '^-P' | awk '{print $3}')"
|
||||
if [ "$FORWARD_POLICY" = "ACCEPT" ]; then
|
||||
echo ":: [OK] Ufw forwarding policy is accept"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw forwarding policy is not 'ACCEPT', attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"ACCEPT\"/" /etc/default/ufw
|
||||
ufw reload > /dev/null
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if iptables -C ufw-user-forward -i tun0 -o "${IPv4dev}" -s 10.8.0.0/24 -j ACCEPT &> /dev/null; then
|
||||
echo ":: [OK] Ufw forwarding rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
ufw route insert 1 allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
@ -167,7 +150,7 @@ if systemctl is-active -q openvpn; then
|
|||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] OpenVPN is not running, try to start now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
systemctl start openvpn
|
||||
echo "Done"
|
||||
fi
|
||||
|
@ -178,19 +161,19 @@ if systemctl is-enabled -q openvpn; then
|
|||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] OpenVPN is not enabled, try to enable now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
systemctl enable openvpn
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
# grep -w (whole word) is used so port 111940 with now match when looking for 1194
|
||||
if netstat -uanpt | grep openvpn | grep -w "${PORT}" | grep -q "${PROTO}"; then
|
||||
echo ":: [OK] OpenVPN is listening on port ${PORT}/${PROTO}"
|
||||
# grep -w (whole word) is used so port 11940 won't match when looking for 1194
|
||||
if netstat -uanpt | grep openvpn | grep -w "${pivpnPORT}" | grep -q "${pivpnPROTO}"; then
|
||||
echo ":: [OK] OpenVPN is listening on port ${pivpnPORT}/${pivpnPROTO}"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] OpenVPN is not listening, try to restart now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
systemctl restart openvpn
|
||||
echo "Done"
|
||||
fi
|
||||
|
@ -205,7 +188,7 @@ echo -e ":::: \e[4mSnippet of the server log\e[0m ::::"
|
|||
tail -20 /var/log/openvpn.log > /tmp/snippet
|
||||
|
||||
# Regular expession taken from https://superuser.com/a/202835, it will match invalid IPs
|
||||
# like 123.456.789.012 but it's fine because the log only contains valid ones.
|
||||
# like 123.456.789.012 but it's fine since the log only contains valid ones.
|
||||
declare -a IPS_TO_HIDE=($(grepcidr -v 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 /tmp/snippet | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | uniq))
|
||||
for IP in "${IPS_TO_HIDE[@]}"; do
|
||||
sed -i "s/$IP/REDACTED/g" /tmp/snippet
|
|
@ -1,10 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
# PiVPN: revoke client script
|
||||
|
||||
INSTALL_USER=$(</etc/pivpn/INSTALL_USER)
|
||||
PLAT=$(</etc/pivpn/DET_PLATFORM)
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
INDEX="/etc/openvpn/easy-rsa/pki/index.txt"
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Revoke a client ovpn profile"
|
||||
echo ":::"
|
||||
|
@ -56,7 +62,7 @@ if [[ -z "${CERTS_TO_REVOKE}" ]]; then
|
|||
done <${INDEX}
|
||||
printf "\n"
|
||||
|
||||
echo "::: Please enter the Name of the client to be revoked from the list above:"
|
||||
echo -n "::: Please enter the Name of the client to be revoked from the list above: "
|
||||
read -r NAME
|
||||
|
||||
if [[ -z "${NAME}" ]]; then
|
||||
|
@ -104,8 +110,6 @@ fi
|
|||
|
||||
cd /etc/openvpn/easy-rsa || exit
|
||||
|
||||
INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6)
|
||||
INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash
|
||||
for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do
|
||||
printf "\n::: Revoking certificate '"%s"'.\n" "${CERTS_TO_REVOKE[ii]}"
|
||||
./easyrsa --batch revoke "${CERTS_TO_REVOKE[ii]}"
|
||||
|
@ -116,7 +120,7 @@ for (( ii = 0; ii < ${#CERTS_TO_REVOKE[@]}; ii++)); do
|
|||
rm -rf "pki/private/${CERTS_TO_REVOKE[ii]}.key"
|
||||
rm -rf "pki/issued/${CERTS_TO_REVOKE[ii]}.crt"
|
||||
|
||||
rm -rf "${INSTALL_HOME}/ovpns/${CERTS_TO_REVOKE[ii]}.ovpn"
|
||||
rm -rf "${install_home}/ovpns/${CERTS_TO_REVOKE[ii]}.ovpn"
|
||||
rm -rf "/etc/openvpn/easy-rsa/pki/${CERTS_TO_REVOKE[ii]}.ovpn"
|
||||
cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem
|
||||
done
|
|
@ -1,23 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
# PiVPN: Uninstall Script
|
||||
|
||||
### FIXME: global: config storage, refactor all scripts to adhere to the storage
|
||||
### FIXME: use variables where appropriate, reduce magic numbers by 99.9%, at least.
|
||||
|
||||
PKG_MANAGER="apt-get"
|
||||
INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER)
|
||||
INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6)
|
||||
INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash
|
||||
PLAT=$(cat /etc/pivpn/DET_PLATFORM)
|
||||
NO_UFW=$(cat /etc/pivpn/NO_UFW)
|
||||
OLD_UFW=$(cat /etc/pivpn/NO_UFW)
|
||||
PORT=$(cat /etc/pivpn/INSTALL_PORT)
|
||||
PROTO=$(cat /etc/pivpn/INSTALL_PROTO)
|
||||
IPv4dev="$(cat /etc/pivpn/pivpnINTERFACE)"
|
||||
INPUT_CHAIN_EDITED="$(cat /etc/pivpn/INPUT_CHAIN_EDITED)"
|
||||
FORWARD_CHAIN_EDITED="$(cat /etc/pivpn/FORWARD_CHAIN_EDITED)"
|
||||
subnetClass="24"
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${setupVars}"
|
||||
|
||||
# Find the rows and columns. Will default to 80x24 if it can not be detected.
|
||||
screen_size=$(stty size 2>/dev/null || echo 24 80)
|
||||
rows=$(echo $screen_size | awk '{print $1}')
|
||||
columns=$(echo $screen_size | awk '{print $2}')
|
||||
rows=$(echo "$screen_size" | awk '{print $1}')
|
||||
columns=$(echo "$screen_size" | awk '{print $2}')
|
||||
|
||||
# Divide by two so the dialogs take up half of the screen, which looks nice.
|
||||
r=$(( rows / 2 ))
|
||||
|
@ -26,115 +28,194 @@ c=$(( columns / 2 ))
|
|||
r=$(( r < 20 ? 20 : r ))
|
||||
c=$(( c < 70 ? 70 : c ))
|
||||
|
||||
spinner()
|
||||
{
|
||||
### FIXME: introduce global lib
|
||||
spinner(){
|
||||
local pid=$1
|
||||
local delay=0.50
|
||||
local spinstr='/-\|'
|
||||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
while ps a | awk '{print $1}' | grep "$pid"; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=$temp${spinstr%"$temp"}
|
||||
sleep $delay
|
||||
printf "\b\b\b\b\b\b"
|
||||
printf "\\b\\b\\b\\b\\b\\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
printf " \\b\\b\\b\\b"
|
||||
}
|
||||
|
||||
function removeAll {
|
||||
# Purge dependencies
|
||||
echo ":::"
|
||||
dependencies=( openvpn easy-rsa git iptables-persistent dnsutils expect unattended-upgrades )
|
||||
for i in "${dependencies[@]}"; do
|
||||
if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then
|
||||
while true; do
|
||||
read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) printf ":::\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\n";
|
||||
if [ "$i" == "openvpn" ]; then UINST_OVPN=1 ; fi
|
||||
if [ "$i" == "unattended-upgrades" ]; then UINST_UNATTUPG=1 ; fi
|
||||
break;;
|
||||
[Nn]* ) printf ":::\tSkipping %s\n" "$i"; break;;
|
||||
* ) printf "::: You must answer yes or no!\n";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
printf ":::\tPackage %s not installed... Not removing.\n" "$i"
|
||||
fi
|
||||
done
|
||||
removeAll(){
|
||||
# Stopping and disabling services
|
||||
echo "::: Stopping and disabling services..."
|
||||
|
||||
# Take care of any additional package cleaning
|
||||
printf "::: Auto removing remaining dependencies..."
|
||||
$PKG_MANAGER -y autoremove &> /dev/null & spinner $!; printf "done!\n";
|
||||
printf "::: Auto cleaning remaining dependencies..."
|
||||
$PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\n";
|
||||
|
||||
echo ":::"
|
||||
# Removing pivpn files
|
||||
echo "::: Removing pivpn system files..."
|
||||
|
||||
$SUDO rm -rf /opt/pivpn &> /dev/null
|
||||
$SUDO rm -rf /etc/.pivpn &> /dev/null
|
||||
$SUDO rm -rf $INSTALL_HOME/ovpns &> /dev/null
|
||||
|
||||
rm -rf /var/log/*pivpn* &> /dev/null
|
||||
rm -rf /var/log/*openvpn* &> /dev/null
|
||||
if [[ $UINST_OVPN = 1 ]]; then
|
||||
rm -rf /etc/openvpn &> /dev/null
|
||||
if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then
|
||||
printf "::: Removing openvpn apt source..."
|
||||
rm -rf /etc/apt/sources.list.d/swupdate.openvpn.net.list &> /dev/null
|
||||
$PKG_MANAGER -qq update & spinner $!; printf "done!\n";
|
||||
if [ "$VPN" = "wireguard" ]; then
|
||||
systemctl stop wg-quick@wg0
|
||||
systemctl disable wg-quick@wg0 &> /dev/null
|
||||
elif [ "$VPN" = "openvpn" ]; then
|
||||
systemctl stop openvpn
|
||||
systemctl disable openvpn &> /dev/null
|
||||
fi
|
||||
|
||||
# Removing firewall rules.
|
||||
echo "::: Removing firewall rules..."
|
||||
|
||||
### FIXME: introduce global config space!
|
||||
if [ "$VPN" = "wireguard" ]; then
|
||||
pivpnPROTO="udp"
|
||||
pivpnDEV="wg0"
|
||||
pivpnNET="10.6.0.0"
|
||||
elif [ "$VPN" = "openvpn" ]; then
|
||||
pivpnDEV="tun0"
|
||||
pivpnNET="10.8.0.0"
|
||||
fi
|
||||
if [[ $UINST_UNATTUPG = 1 ]]; then
|
||||
rm -rf /var/log/unattended-upgrades
|
||||
rm -rf /etc/apt/apt.conf.d/*periodic
|
||||
|
||||
if [ "$USING_UFW" -eq 1 ]; then
|
||||
|
||||
### FIXME: SC2154
|
||||
ufw delete allow "${pivpnPORT}"/"${pivpnPROTO}" > /dev/null
|
||||
### FIXME: SC2154
|
||||
ufw route delete allow in on "${pivpnDEV}" from "${pivpnNET}/${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 -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 -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 -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 -m comment --comment "${VPN}-nat-rule"
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
|
||||
fi
|
||||
rm -rf /etc/pivpn &> /dev/null
|
||||
rm /usr/local/bin/pivpn &> /dev/null
|
||||
rm /etc/bash_completion.d/pivpn
|
||||
|
||||
# Disable IPv4 forwarding
|
||||
sed -i '/net.ipv4.ip_forward=1/c\#net.ipv4.ip_forward=1' /etc/sysctl.conf
|
||||
sysctl -p
|
||||
|
||||
if [[ $NO_UFW -eq 0 ]]; then
|
||||
# Purge dependencies
|
||||
echo "::: Purge dependencies..."
|
||||
|
||||
sed -z "s/*nat\n:POSTROUTING ACCEPT \[0:0\]\n-I POSTROUTING -s 10.8.0.0\/24 -o $IPv4dev -j MASQUERADE\nCOMMIT\n\n//" -i /etc/ufw/before.rules
|
||||
ufw delete allow "$PORT"/"$PROTO" >/dev/null
|
||||
if [ "$OLD_UFW" -eq 1 ]; then
|
||||
sed -i "s/\(DEFAULT_FORWARD_POLICY=\).*/\1\"DROP\"/" /etc/default/ufw
|
||||
else
|
||||
ufw route delete allow in on tun0 from 10.8.0.0/24 out on "$IPv4dev" to any >/dev/null
|
||||
fi
|
||||
ufw reload >/dev/null
|
||||
else
|
||||
iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o "${IPv4dev}" -j MASQUERADE
|
||||
for i in "${TO_INSTALL[@]}"; do
|
||||
while true; do
|
||||
read -rp "::: Do you wish to remove $i from your system? [Y/n]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) if [ "${i}" = "wireguard" ]; then
|
||||
|
||||
if [ "$INPUT_CHAIN_EDITED" -eq 1 ]; then
|
||||
iptables -D INPUT -i "$IPv4dev" -p "$PROTO" --dport "$PORT" -j ACCEPT
|
||||
# On Debian and armv7l Raspbian, remove the unstable repo (on armv6l Raspbian
|
||||
# there is no wireguard package). On Ubuntu, remove the PPA.
|
||||
### FIXME: unconditionally rm'ing unstable.list isn't a good idea, it appears. What if someone else put it there manually?
|
||||
if [ "$PLAT" = "Debian" ] || { [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv7l" ]; }; then
|
||||
rm -f /etc/apt/sources.list.d/pivpn-unstable.list
|
||||
rm -f /etc/apt/preferences.d/pivpn-limit-unstable
|
||||
$PKG_MANAGER update &> /dev/null
|
||||
elif [ "$PLAT" = "Ubuntu" ]; then
|
||||
add-apt-repository ppa:wireguard/wireguard -r -y
|
||||
$PKG_MANAGER update &> /dev/null
|
||||
fi
|
||||
|
||||
if [ "$FORWARD_CHAIN_EDITED" -eq 1 ]; then
|
||||
iptables -D FORWARD -d 10.8.0.0/24 -i "$IPv4dev" -o tun0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
iptables -D FORWARD -s 10.8.0.0/24 -i tun0 -o "$IPv4dev" -j ACCEPT
|
||||
elif [ "${i}" = "wireguard-dkms" ]; then
|
||||
|
||||
# On armv6l Raspbian we manually remove the kernel module and skip the apt
|
||||
# uninstallation (since it's not an actual package).
|
||||
if [ "$PLAT" = "Raspbian" ] && [ "$(uname -m)" = "armv6l" ]; then
|
||||
dkms remove wireguard/"${WG_MODULE_SNAPSHOT}" --all
|
||||
rm -rf /usr/src/wireguard-"${WG_MODULE_SNAPSHOT}"
|
||||
break
|
||||
fi
|
||||
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
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
|
||||
# so we remove the repository keys
|
||||
apt-key remove E1CF20DDFFE4B89E802658F1E0B11894F66AEC98 80D15823B7FD1561F9F7BCDDDC30D7C23CBBABEE &> /dev/null
|
||||
|
||||
elif [ "${i}" = "unattended-upgrades" ]; then
|
||||
|
||||
### REALLY???
|
||||
rm -rf /var/log/unattended-upgrades
|
||||
rm -rf /etc/apt/apt.conf.d/*periodic
|
||||
rm -rf /etc/apt/apt.conf.d/*unattended-upgrades
|
||||
|
||||
elif [ "${i}" = "openvpn" ]; then
|
||||
|
||||
deluser openvpn
|
||||
rm -f /etc/rsyslog.d/30-openvpn.conf
|
||||
rm -f /etc/logrotate.d/openvpn
|
||||
|
||||
fi
|
||||
printf ":::\\tRemoving %s..." "$i"; $PKG_MANAGER -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\\n";
|
||||
break
|
||||
;;
|
||||
[Nn]* ) printf ":::\\tSkipping %s\\n" "$i";
|
||||
break
|
||||
;;
|
||||
* ) printf "::: You must answer yes or no!\\n";;
|
||||
esac
|
||||
done
|
||||
done
|
||||
|
||||
# Take care of any additional package cleaning
|
||||
printf "::: Auto removing remaining dependencies..."
|
||||
$PKG_MANAGER -y autoremove &> /dev/null & spinner $!; printf "done!\\n";
|
||||
printf "::: Auto cleaning remaining dependencies..."
|
||||
$PKG_MANAGER -y autoclean &> /dev/null & spinner $!; printf "done!\\n";
|
||||
|
||||
echo ":::"
|
||||
# Removing pivpn files
|
||||
echo "::: Removing pivpn system files..."
|
||||
|
||||
if [ -f /etc/dnsmasq.d/02-pivpn.conf ]; then
|
||||
rm -f /etc/dnsmasq.d/02-pivpn.conf
|
||||
pihole restartdns
|
||||
fi
|
||||
|
||||
rm -rf /opt/pivpn
|
||||
rm -rf /etc/.pivpn
|
||||
rm -rf /etc/pivpn
|
||||
rm -f /var/log/*pivpn*
|
||||
rm -f /usr/local/bin/pivpn
|
||||
rm -f /etc/bash_completion.d/pivpn
|
||||
|
||||
echo ":::"
|
||||
echo "::: Removing VPN configuration files..."
|
||||
|
||||
if [ "$VPN" = "wireguard" ]; then
|
||||
rm -f /etc/wireguard/wg0.conf
|
||||
rm -rf /etc/wireguard/configs
|
||||
rm -rf /etc/wireguard/keys
|
||||
### FIXME SC2154
|
||||
rm -rf "$install_home/configs"
|
||||
elif [ "$VPN" = "openvpn" ]; then
|
||||
rm -rf /var/log/*openvpn*
|
||||
rm -f /etc/openvpn/server.conf
|
||||
rm -f /etc/openvpn/crl.pem
|
||||
rm -rf /etc/openvpn/easy-rsa
|
||||
rm -rf "$install_home/ovpns"
|
||||
fi
|
||||
|
||||
echo ":::"
|
||||
printf "::: Finished removing PiVPN from your system.\n"
|
||||
printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L https://install.pivpn.io | bash\n:::\n::: at any time!\n:::\n"
|
||||
printf "::: Finished removing PiVPN from your system.\\n"
|
||||
printf "::: Reinstall by simpling running\\n:::\\n:::\\tcurl -L https://install.pivpn.dev | bash\\n:::\\n::: at any time!\\n:::\\n"
|
||||
}
|
||||
|
||||
function askreboot() {
|
||||
printf "It is \e[1mstrongly\e[0m recommended to reboot after un-installation.\n"
|
||||
askreboot(){
|
||||
printf "It is \\e[1mstrongly\\e[0m recommended to reboot after un-installation.\\n"
|
||||
read -p "Would you like to reboot now? [y/n]: " -n 1 -r
|
||||
echo
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
|
||||
printf "\nRebooting system...\n"
|
||||
printf "\\nRebooting system...\\n"
|
||||
sleep 3
|
||||
shutdown -r now
|
||||
fi
|
||||
|
@ -148,6 +229,6 @@ while true; do
|
|||
case $yn in
|
||||
[Yy]* ) removeAll; askreboot; break;;
|
||||
|
||||
[Nn]* ) printf "::: Not removing anything, exiting...\n"; break;;
|
||||
[Nn]* ) printf "::: Not removing anything, exiting...\\n"; break;;
|
||||
esac
|
||||
done
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
#/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
###Updates pivpn scripts (Not PiVPN)
|
||||
###Main Vars
|
||||
pivpnrepo="https://github.com/pivpn/pivpn.git"
|
||||
pivpnlocalpath="/etc/.pivpn"
|
||||
pivpnscripts="/opt/pivpn/scripts"
|
||||
bashcompletiondir="/etc/bash_completion.d/pivpn"
|
||||
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
|
||||
|
@ -14,11 +21,11 @@ updatepivpnscripts(){
|
|||
##We don't know what sort of changes users have made.
|
||||
##Lets remove first /etc/.pivpn dir then clone it back again
|
||||
echo "going do update PiVPN Scripts"
|
||||
if [[ -d $pivpnlocalpath ]]; then
|
||||
|
||||
sudo rm -rf $pivpnlocalpath
|
||||
if [[ -d "$pivpnlocalpath" ]]; then
|
||||
if [[ -n "$pivpnlocalpath" ]]; then
|
||||
rm -rf "${pivpnlocalpath}/../.pivpn"
|
||||
cloneandupdate
|
||||
|
||||
fi
|
||||
else
|
||||
cloneandupdate
|
||||
fi
|
||||
|
@ -30,62 +37,63 @@ updatefromtest(){
|
|||
##We don't know what sort of changes users have made.
|
||||
##Lets remove first /etc/.pivpn dir then clone it back again
|
||||
echo "PiVPN Scripts updating from test branch"
|
||||
if [[ -d /etc/.pivpn ]]; then
|
||||
|
||||
rm -rf /etc/.pivpn
|
||||
if [[ -d "$pivpnlocalpath" ]]; then
|
||||
if [[ -n "$pivpnlocalpath" ]]; then
|
||||
rm -rf "${pivpnlocalpath}/../.pivpn"
|
||||
cloneupdttest
|
||||
|
||||
fi
|
||||
else
|
||||
|
||||
cloneupdttest
|
||||
|
||||
fi
|
||||
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 -r $pivpnlocalpath/scripts $pivpnscripts
|
||||
sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir
|
||||
|
||||
##This is to be removed after merge.
|
||||
##Alert for users trying to update from master.
|
||||
echo "ERROR: You have installed pivpn from test branch."
|
||||
echo "Wireguard not yet available on master, please use -t flag"
|
||||
exit 1
|
||||
## Remove Above and uncomment below when test is moved to master
|
||||
# git clone "$pivpnrepo" "$pivpnlocalpath"
|
||||
# cp "${pivpnlocalpath}"/scripts/*.sh "$pivpnscripts"
|
||||
# cp "${pivpnlocalpath}"/scripts/$VPN/*.sh "$pivpnscripts"
|
||||
# cp "${pivpnlocalpath}"/scripts/$VPN/bash-completion "$bashcompletiondir"
|
||||
}
|
||||
|
||||
##same as cloneandupdate() but from test branch
|
||||
##and falls back to master branch again after updating
|
||||
cloneupdttest(){
|
||||
|
||||
sudo git clone $pivpnrepo $pivpnlocalpath
|
||||
sudo git -C $pivpnlocalpath checkout test
|
||||
sudo git -C $pivpnlocalpath pull origin test
|
||||
sudo cp -r $pivpnlocalpath/scripts $pivpnscripts
|
||||
sudo cp $pivpnlocalpath/scripts/bash-completion $bashcompletiondir
|
||||
sudo git -C $pivpnlocalpath checkout master
|
||||
|
||||
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(){
|
||||
echo -e "Updates pivpn scripts,\n
|
||||
echo -e "Updates pivpn scripts,
|
||||
|
||||
Usage:
|
||||
pivpn update | updates from master branch
|
||||
pivpn update -t or --test | updates from test branch"
|
||||
|
||||
}
|
||||
|
||||
## SCRIPT
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
updatepivpnscripts
|
||||
|
||||
else
|
||||
while true; do
|
||||
case "$1" in
|
||||
-t | --test | test )
|
||||
-t|--test|test)
|
||||
updatefromtest
|
||||
exit 0
|
||||
;;
|
||||
-h | --help | help )
|
||||
-h|--help|help)
|
||||
scriptusage
|
||||
exit 0
|
||||
;;
|
||||
|
@ -96,4 +104,3 @@ else
|
|||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
|
|
19
scripts/wireguard/bash-completion
Normal file
19
scripts/wireguard/bash-completion
Normal file
|
@ -0,0 +1,19 @@
|
|||
_pivpn()
|
||||
{
|
||||
local cur prev opts
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
dashopts="-a -c -d -l -qr -r -h -u -up -bk"
|
||||
opts="add clients debug list qrcode remove help uninstall update backup"
|
||||
if [ "${#COMP_WORDS[@]}" -eq 2 ]
|
||||
then
|
||||
if [[ ${cur} == -* ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${dashopts}" -- "${cur}") )
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
complete -F _pivpn pivpn
|
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'
|
28
scripts/wireguard/listCONF.sh
Executable file
28
scripts/wireguard/listCONF.sh
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd /etc/wireguard/configs
|
||||
if [ ! -s clients.txt ]; then
|
||||
echo "::: There are no clients to list"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "\e[1m::: Clients Summary :::\e[0m\n"
|
||||
|
||||
# Present the user with a summary of the clients, fetching info from dates.
|
||||
{
|
||||
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")"
|
||||
|
||||
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')"
|
||||
|
||||
echo -e "$CLIENT_NAME \t $PUBLIC_KEY \t $CD_FORMAT"
|
||||
done < clients.txt
|
||||
|
||||
} | column -t -s $'\t'
|
132
scripts/wireguard/makeCONF.sh
Executable file
132
scripts/wireguard/makeCONF.sh
Executable file
|
@ -0,0 +1,132 @@
|
|||
#!/bin/bash
|
||||
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
|
||||
helpFunc(){
|
||||
echo "::: Create a client conf profile"
|
||||
echo ":::"
|
||||
echo "::: Usage: pivpn <-a|add> [-n|--name <arg>] [-h|--help]"
|
||||
echo ":::"
|
||||
echo "::: Commands:"
|
||||
echo "::: [none] Interactive mode"
|
||||
echo "::: -n,--name Name for the Client (default: '$HOSTNAME')"
|
||||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
# Parse input arguments
|
||||
while test $# -gt 0; do
|
||||
_key="$1"
|
||||
case "$_key" in
|
||||
-n|--name|--name=*)
|
||||
_val="${_key##--name=}"
|
||||
if test "$_val" = "$_key"; then
|
||||
test $# -lt 2 && echo "::: Missing value for the optional argument '$_key'." && exit 1
|
||||
_val="$2"
|
||||
shift
|
||||
fi
|
||||
CLIENT_NAME="$_val"
|
||||
;;
|
||||
-h|--help)
|
||||
helpFunc
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "::: Error: Got an unexpected argument '$1'"
|
||||
helpFunc
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
# The home folder variable was sourced from the settings file.
|
||||
if [ ! -d "${install_home}/configs" ]; then
|
||||
mkdir "${install_home}/configs"
|
||||
chown "${install_user}":"${install_user}" "${install_home}/configs"
|
||||
chmod 0750 "${install_home}/configs"
|
||||
fi
|
||||
|
||||
cd /etc/wireguard
|
||||
|
||||
if [ -z "${CLIENT_NAME}" ]; then
|
||||
read -r -p "Enter a Name for the Client: " CLIENT_NAME
|
||||
fi
|
||||
|
||||
if [[ "${CLIENT_NAME}" =~ [^a-zA-Z0-9.@_-] ]]; then
|
||||
echo "Name can only contain alphanumeric characters and these characters (.-@_)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${CLIENT_NAME}" ]; then
|
||||
echo "::: You cannot leave the name blank."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "configs/${CLIENT_NAME}.conf" ]; then
|
||||
echo "::: A client with this name already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wg genkey | tee "keys/${CLIENT_NAME}_priv" | wg pubkey > "keys/${CLIENT_NAME}_pub"
|
||||
echo "::: Client Keys generated"
|
||||
|
||||
# Find an unused number for the last octet of the client IP
|
||||
for i in {2..254}; do
|
||||
if ! grep -q " $i$" configs/clients.txt; then
|
||||
COUNT="$i"
|
||||
echo "${CLIENT_NAME} $(<keys/${CLIENT_NAME}_pub) $(date +%s) ${COUNT}" >> configs/clients.txt
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo -n "[Interface]
|
||||
PrivateKey = $(cat "keys/${CLIENT_NAME}_priv")
|
||||
Address = 10.6.0.${COUNT}/24
|
||||
DNS = ${pivpnDNS1}" > "configs/${CLIENT_NAME}.conf"
|
||||
|
||||
if [ -n "${pivpnDNS2}" ]; then
|
||||
echo ", ${pivpnDNS2}" >> "configs/${CLIENT_NAME}.conf"
|
||||
else
|
||||
echo >> "configs/${CLIENT_NAME}.conf"
|
||||
fi
|
||||
echo >> "configs/${CLIENT_NAME}.conf"
|
||||
|
||||
echo "[Peer]
|
||||
PublicKey = $(cat keys/server_pub)
|
||||
PresharedKey = $(cat keys/psk)
|
||||
Endpoint = ${pivpnHOST}:${pivpnPORT}
|
||||
AllowedIPs = 0.0.0.0/0" >> "configs/${CLIENT_NAME}.conf"
|
||||
echo "::: Client config generated"
|
||||
|
||||
echo "# begin ${CLIENT_NAME}
|
||||
[Peer]
|
||||
PublicKey = $(cat "keys/${CLIENT_NAME}_pub")
|
||||
PresharedKey = $(cat keys/psk)
|
||||
AllowedIPs = 10.6.0.${COUNT}/32
|
||||
# end ${CLIENT_NAME}" >> wg0.conf
|
||||
echo "::: Updated server config"
|
||||
|
||||
if systemctl restart wg-quick@wg0; then
|
||||
echo "::: WireGuard restarted"
|
||||
else
|
||||
echo "::: Failed to restart WireGuard"
|
||||
fi
|
||||
|
||||
cp "configs/${CLIENT_NAME}.conf" "${install_home}/configs/${CLIENT_NAME}.conf"
|
||||
chown "${install_user}":"${install_user}" "${install_home}/configs/${CLIENT_NAME}.conf"
|
||||
chmod 640 "${install_home}/configs/${CLIENT_NAME}.conf"
|
||||
|
||||
echo "======================================================================"
|
||||
echo -e "::: Done! \e[1m${CLIENT_NAME}.conf successfully created!\e[0m"
|
||||
echo "::: ${CLIENT_NAME}.conf was copied to ${install_home}/configs for easy transfer."
|
||||
echo "::: Please use this profile only on one device and create additional"
|
||||
echo -e "::: profiles for other devices. You can also use \e[1mpivpn -qr\e[0m"
|
||||
echo "::: to generate a QR Code you can scan with the mobile app."
|
||||
echo "======================================================================"
|
97
scripts/wireguard/pivpn
Executable file
97
scripts/wireguard/pivpn
Executable file
|
@ -0,0 +1,97 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Must be root to use this tool
|
||||
if [ $EUID -ne 0 ];then
|
||||
if dpkg-query -s sudo &> /dev/null; then
|
||||
export SUDO="sudo"
|
||||
else
|
||||
echo "::: Please install sudo or run this as root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
makeConf(){
|
||||
shift
|
||||
$SUDO /opt/pivpn/makeCONF.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
listConnected(){
|
||||
$SUDO /opt/pivpn/clientSTAT.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
debug(){
|
||||
$SUDO /opt/pivpn/pivpnDEBUG.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
listClients(){
|
||||
$SUDO /opt/pivpn/listCONF.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
showQrcode(){
|
||||
shift
|
||||
$SUDO /opt/pivpn/qrcodeCONF.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
removeClient(){
|
||||
shift
|
||||
$SUDO /opt/pivpn/removeCONF.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
uninstallServer(){
|
||||
$SUDO /opt/pivpn/uninstall.sh
|
||||
exit 0
|
||||
}
|
||||
|
||||
updateScripts(){
|
||||
shift
|
||||
$SUDO /opt/pivpn/update.sh "$@"
|
||||
exit 0
|
||||
}
|
||||
|
||||
backup(){
|
||||
$SUDO /opt/pivpn/backup.sh
|
||||
}
|
||||
|
||||
showHelp(){
|
||||
echo "::: Control all PiVPN specific functions!"
|
||||
echo ":::"
|
||||
echo "::: Usage: pivpn <command> [option]"
|
||||
echo ":::"
|
||||
echo "::: Commands:"
|
||||
echo "::: -a, add Create a client conf profile"
|
||||
echo "::: -c, clients List any connected clients to the server"
|
||||
echo "::: -d, debug Start a debugging session if having trouble"
|
||||
echo "::: -l, list List all clients"
|
||||
echo "::: -qr, qrcode Show the qrcode of a client for use with the mobile app"
|
||||
echo "::: -r, remove Remove a client"
|
||||
echo "::: -h, help Show this help dialog"
|
||||
echo "::: -u, uninstall Uninstall pivpn from your system!"
|
||||
echo "::: -up, update Updates PiVPN Scripts"
|
||||
echo "::: -bk, Backup Backup vpn configs and user profiles"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if [ $# = 0 ]; then
|
||||
showHelp
|
||||
fi
|
||||
|
||||
# Handle redirecting to specific functions based on arguments
|
||||
case "$1" in
|
||||
"-a" | "add" ) makeConf "$@";;
|
||||
"-c" | "clients" ) listConnected;;
|
||||
"-d" | "debug" ) debug;;
|
||||
"-l" | "list" ) listClients;;
|
||||
"-qr" | "qrcode" ) showQrcode "$@";;
|
||||
"-r" | "remove" ) removeClient "$@";;
|
||||
"-h" | "help" ) showHelp;;
|
||||
"-u" | "uninstall" ) uninstallServer;;
|
||||
"-up" | "update" ) updateScripts "$@" ;;
|
||||
"-bk" | "backup" ) backup ;;
|
||||
* ) showHelp;;
|
||||
esac
|
203
scripts/wireguard/pivpnDEBUG.sh
Executable file
203
scripts/wireguard/pivpnDEBUG.sh
Executable file
|
@ -0,0 +1,203 @@
|
|||
#!/usr/bin/env bash
|
||||
# This scripts runs as root
|
||||
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
EXAMPLE="$(head -1 /etc/wireguard/configs/clients.txt | awk '{print $1}')"
|
||||
ERR=0
|
||||
|
||||
echo -e "::::\t\t\e[4mPiVPN debug\e[0m\t\t ::::"
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mLatest commit\e[0m\t\t ::::"
|
||||
git --git-dir /etc/.pivpn/.git log -n 1
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t \e[4mInstallation settings\e[0m \t ::::"
|
||||
sed "s/$pivpnHOST/REDACTED/" < /etc/pivpn/setupVars.conf
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \e[4mServer configuration shown below\e[0m ::::"
|
||||
cd /etc/wireguard/keys
|
||||
cp ../wg0.conf ../wg0.tmp
|
||||
# Replace every key in the server configuration with just its file name
|
||||
for k in *; do
|
||||
sed "s#$(cat "$k")#$k#" -i ../wg0.tmp
|
||||
done
|
||||
cat ../wg0.tmp
|
||||
rm ../wg0.tmp
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \e[4mClient configuration shown below\e[0m ::::"
|
||||
if [ -n "$EXAMPLE" ]; then
|
||||
cp ../configs/"$EXAMPLE".conf ../configs/"$EXAMPLE".tmp
|
||||
for k in *; do
|
||||
sed "s#$(cat "$k")#$k#" -i ../configs/"$EXAMPLE".tmp
|
||||
done
|
||||
sed "s/$pivpnHOST/REDACTED/" < ../configs/"$EXAMPLE".tmp
|
||||
rm ../configs/"$EXAMPLE".tmp
|
||||
else
|
||||
echo "::: There are no clients yet"
|
||||
fi
|
||||
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \t\e[4mRecursive list of files in\e[0m\t ::::\n::::\e\t[4m/etc/wireguard shown below\e[0m\t ::::"
|
||||
ls -LR /etc/wireguard
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mSelf check\e[0m\t\t ::::"
|
||||
|
||||
if [ "$(cat /proc/sys/net/ipv4/ip_forward)" -eq 1 ]; then
|
||||
echo ":: [OK] IP forwarding is enabled"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] IP forwarding is not enabled, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
sed -i '/net.ipv4.ip_forward=1/s/^#//g' /etc/sysctl.conf
|
||||
sysctl -p
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$USING_UFW" -eq 0 ]; then
|
||||
|
||||
if iptables -t nat -C POSTROUTING -s 10.6.0.0/24 -o "${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 -I POSTROUTING -s 10.6.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 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
|
||||
echo ":: [OK] Ufw is enabled"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw is not enabled, try to enable now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
ufw enable
|
||||
fi
|
||||
fi
|
||||
|
||||
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 -m comment --comment ${VPN}-nat-rule\nCOMMIT\n" -i /etc/ufw/before.rules
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if iptables -C ufw-user-input -p udp --dport "${pivpnPORT}" -j ACCEPT &> /dev/null; then
|
||||
echo ":: [OK] Ufw input rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw input rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
ufw insert 1 allow "$pivpnPORT"/udp
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if iptables -C ufw-user-forward -i wg0 -o "${IPv4dev}" -s 10.6.0.0/24 -j ACCEPT &> /dev/null; then
|
||||
echo ":: [OK] Ufw forwarding rule set"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] Ufw forwarding rule is not set, attempt fix now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
ufw route insert 1 allow in on wg0 from 10.6.0.0/24 out on "$IPv4dev" to any
|
||||
ufw reload
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if systemctl is-active -q wg-quick@wg0; then
|
||||
echo ":: [OK] WireGuard is running"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] WireGuard is not running, try to start now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
systemctl start wg-quick@wg0
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if systemctl is-enabled -q wg-quick@wg0; then
|
||||
echo ":: [OK] WireGuard is enabled (it will automatically start on reboot)"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] WireGuard is not enabled, try to enable now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
systemctl enable wg-quick@wg0
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
# grep -w (whole word) is used so port 11940 won't match when looking for 1194
|
||||
if netstat -uanp | grep -w "${pivpnPORT}" | grep -q 'udp'; then
|
||||
echo ":: [OK] WireGuard is listening on port ${pivpnPORT}/udp"
|
||||
else
|
||||
ERR=1
|
||||
read -r -p ":: [ERR] WireGuard is not listening, try to restart now? [Y/n] " REPLY
|
||||
if [[ ${REPLY} =~ ^[Yy]$ ]] || [[ -z ${REPLY} ]]; then
|
||||
systemctl restart wg-quick@wg0
|
||||
echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$ERR" -eq 1 ]; then
|
||||
echo -e "[INFO] Run \e[1mpivpn -d\e[0m again to see if we detect issues"
|
||||
fi
|
||||
printf "=============================================\n"
|
||||
echo -e ":::: \e[1mWARNING\e[0m: This script should have automatically masked sensitive ::::"
|
||||
echo -e ":::: information, however, still make sure that \e[4mPrivateKey\e[0m, \e[4mPublicKey\e[0m ::::"
|
||||
echo -e ":::: and \e[4mPresharedKey\e[0m are masked before reporting an issue. An example key ::::"
|
||||
echo ":::: that you should NOT see in this log looks like this: ::::"
|
||||
echo ":::: WJhKKx+Uk1l1TxaH2KcEGeBdPBTp/k/Qy4EpBig5UnI= ::::"
|
||||
printf "=============================================\n"
|
||||
echo -e "::::\t\t\e[4mDebug complete\e[0m\t\t ::::"
|
63
scripts/wireguard/qrcodeCONF.sh
Executable file
63
scripts/wireguard/qrcodeCONF.sh
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/bin/bash
|
||||
|
||||
helpFunc(){
|
||||
echo "::: Show the qrcode of a client for use with the mobile app"
|
||||
echo ":::"
|
||||
echo "::: Usage: pivpn <-qr|qrcode> [-h|--help] [<client-1>] ... [<client-n>] ..."
|
||||
echo ":::"
|
||||
echo "::: Commands:"
|
||||
echo "::: [none] Interactive mode"
|
||||
echo "::: <client> Client(s) to show"
|
||||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
# Parse input arguments
|
||||
while test $# -gt 0
|
||||
do
|
||||
_key="$1"
|
||||
case "$_key" in
|
||||
-h|--help)
|
||||
helpFunc
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
CLIENTS_TO_SHOW+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
cd /etc/wireguard/configs
|
||||
if [ ! -s clients.txt ]; then
|
||||
echo "::: There are no clients to show"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${#CLIENTS_TO_SHOW[@]}" -eq 0 ]; then
|
||||
|
||||
echo -e "::\e[4m Client list \e[0m::"
|
||||
LIST=($(awk '{print $1}' clients.txt))
|
||||
COUNTER=1
|
||||
while [ $COUNTER -le ${#LIST[@]} ]; do
|
||||
echo "• ${LIST[(($COUNTER-1))]}"
|
||||
((COUNTER++))
|
||||
done
|
||||
|
||||
read -r -p "Please enter the Name of the Client to show: " CLIENTS_TO_SHOW
|
||||
|
||||
if [ -z "${CLIENTS_TO_SHOW}" ]; then
|
||||
echo "::: You can not leave this blank!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
for CLIENT_NAME in "${CLIENTS_TO_SHOW[@]}"; do
|
||||
if grep -qw "${CLIENT_NAME}" clients.txt; then
|
||||
echo -e "::: Showing client \e[1m${CLIENT_NAME}\e[0m below"
|
||||
echo "====================================================================="
|
||||
qrencode -t ansiutf8 < "${CLIENT_NAME}.conf"
|
||||
echo "====================================================================="
|
||||
else
|
||||
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
||||
fi
|
||||
done
|
119
scripts/wireguard/removeCONF.sh
Executable file
119
scripts/wireguard/removeCONF.sh
Executable file
|
@ -0,0 +1,119 @@
|
|||
#!/bin/bash
|
||||
|
||||
setupVars="/etc/pivpn/setupVars.conf"
|
||||
|
||||
helpFunc(){
|
||||
echo "::: Remove a client conf profile"
|
||||
echo ":::"
|
||||
echo "::: Usage: pivpn <-r|remove> [-h|--help] [<client-1>] ... [<client-n>] ..."
|
||||
echo ":::"
|
||||
echo "::: Commands:"
|
||||
echo "::: [none] Interactive mode"
|
||||
echo "::: <client> Client(s) to remove"
|
||||
echo "::: -h,--help Show this help dialog"
|
||||
}
|
||||
|
||||
# Parse input arguments
|
||||
while test $# -gt 0
|
||||
do
|
||||
_key="$1"
|
||||
case "$_key" in
|
||||
-h|--help)
|
||||
helpFunc
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
CLIENTS_TO_REMOVE+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ ! -f "${setupVars}" ]; then
|
||||
echo "::: Missing setup vars file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${setupVars}"
|
||||
|
||||
cd /etc/wireguard
|
||||
if [ ! -s configs/clients.txt ]; then
|
||||
echo "::: There are no clients to remove"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${#CLIENTS_TO_REMOVE[@]}" -eq 0 ]; then
|
||||
|
||||
echo -e "::\e[4m Client list \e[0m::"
|
||||
LIST=($(awk '{print $1}' configs/clients.txt))
|
||||
COUNTER=1
|
||||
while [ $COUNTER -le ${#LIST[@]} ]; do
|
||||
echo "• ${LIST[(($COUNTER-1))]}"
|
||||
((COUNTER++))
|
||||
done
|
||||
|
||||
read -r -p "Please enter the Name of the Client to be removed from the list above: " CLIENTS_TO_REMOVE
|
||||
|
||||
if [ -z "${CLIENTS_TO_REMOVE}" ]; then
|
||||
echo "::: You can not leave this blank!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
DELETED_COUNT=0
|
||||
|
||||
for CLIENT_NAME in "${CLIENTS_TO_REMOVE[@]}"; do
|
||||
|
||||
if ! grep -qw "${CLIENT_NAME}" configs/clients.txt; then
|
||||
echo -e "::: \e[1m${CLIENT_NAME}\e[0m does not exist"
|
||||
else
|
||||
REQUESTED="$(sha256sum "configs/${CLIENT_NAME}.conf" | cut -c 1-64)"
|
||||
read -r -p "Do you really want to delete $CLIENT_NAME? [Y/n] "
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
|
||||
# Grab the least significant octed of the client IP address
|
||||
COUNT=$(grep "${CLIENT_NAME}" configs/clients.txt | awk '{print $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} ${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
|
||||
echo "::: Updated server config"
|
||||
|
||||
rm "configs/${CLIENT_NAME}.conf"
|
||||
echo "::: Client config for ${CLIENT_NAME} removed"
|
||||
|
||||
rm "keys/${CLIENT_NAME}_priv"
|
||||
rm "keys/${CLIENT_NAME}_pub"
|
||||
echo "::: Client Keys for ${CLIENT_NAME} removed"
|
||||
|
||||
# Find all .conf files in the home folder of the user matching the checksum of the
|
||||
# config and delete them. '-maxdepth 3' is used to avoid traversing too many folders.
|
||||
find "${install_home}" -maxdepth 3 -type f -name '*.conf' -print0 | while IFS= read -r -d '' CONFIG; do
|
||||
if sha256sum -c <<< "${REQUESTED} ${CONFIG}" &> /dev/null; then
|
||||
rm "${CONFIG}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "::: Successfully deleted ${CLIENT_NAME}"
|
||||
|
||||
((DELETED_COUNT++))
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Restart WireGuard only if some clients were actually deleted
|
||||
if [ "${DELETED_COUNT}" -gt 0 ]; then
|
||||
if systemctl restart wg-quick@wg0; then
|
||||
echo "::: WireGuard restarted"
|
||||
else
|
||||
echo "::: Failed to restart WireGuard"
|
||||
fi
|
||||
fi
|
|
@ -8,8 +8,8 @@ dh /etc/openvpn/easy-rsa/pki/dh2048.pem
|
|||
topology subnet
|
||||
server 10.8.0.0 255.255.255.0
|
||||
# Set your primary domain name server address for clients
|
||||
push "dhcp-option DNS 8.8.8.8"
|
||||
push "dhcp-option DNS 8.8.4.4"
|
||||
push "dhcp-option DNS 9.9.9.9"
|
||||
push "dhcp-option DNS 149.112.112.112"
|
||||
# Prevent DNS leaks on Windows
|
||||
push "block-outside-dns"
|
||||
# Override the Client default gateway by using 0.0.0.0/1 and
|
||||
|
@ -17,14 +17,14 @@ push "block-outside-dns"
|
|||
# overriding but not wiping out the original default gateway.
|
||||
push "redirect-gateway def1"
|
||||
client-to-client
|
||||
keepalive 1800 3600
|
||||
keepalive 15 120
|
||||
remote-cert-tls client
|
||||
tls-version-min 1.2
|
||||
tls-auth /etc/openvpn/easy-rsa/pki/ta.key 0
|
||||
cipher AES-256-CBC
|
||||
auth SHA256
|
||||
user nobody
|
||||
group nogroup
|
||||
user openvpn
|
||||
group openvpn
|
||||
persist-key
|
||||
persist-tun
|
||||
crl-verify /etc/openvpn/crl.pem
|
||||
|
|
13
unattended_openvpn_example.conf
Normal file
13
unattended_openvpn_example.conf
Normal file
|
@ -0,0 +1,13 @@
|
|||
IPv4dev=eth0
|
||||
dhcpReserv=0
|
||||
install_user=pi
|
||||
VPN=openvpn
|
||||
pivpnPROTO=udp
|
||||
pivpnPORT=1194
|
||||
pivpnDNS1=9.9.9.9
|
||||
pivpnDNS2=149.112.112.112
|
||||
pivpnHOST=pivpn.example.com
|
||||
pivpnENCRYPT=2048
|
||||
pivpnSEARCHDOMAIN=searchdomain.example.com
|
||||
DOWNLOAD_DH_PARAM=0
|
||||
UNATTUPG=1
|
9
unattended_wireguard_example.conf
Normal file
9
unattended_wireguard_example.conf
Normal file
|
@ -0,0 +1,9 @@
|
|||
IPv4dev=eth0
|
||||
dhcpReserv=0
|
||||
install_user=pi
|
||||
VPN=wireguard
|
||||
pivpnPORT=51820
|
||||
pivpnDNS1=9.9.9.9
|
||||
pivpnDNS2=149.112.112.112
|
||||
pivpnHOST=pivpn.example.com
|
||||
UNATTUPG=1
|
Loading…
Reference in a new issue