Verified Commit 9a22d836 authored by Aral Balkan's avatar Aral Balkan
Browse files

Initial add

parents
distance*
geolocate
server_location.txt
geolocate.sh
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.0] - 2020-05-03
### Changed
- Rename `down` option to `off`.
### Added
- `ls` option to show list of countries.
## [1.0.0] - 2020-05-03
Initial release.
This diff is collapsed.
The current command-line interface for using [AzireVPN](https://www.azirevpn.com/)’s excellent [Wireguard](https://www.wireguard.com/) service that I’ve been using since the early days of the beta goes something like this:
1. Memorise the codes for [the servers](https://www.azirevpn.com/docs/servers#servers) (which you can find in _/etc/wireguard_ and which look like _azirevpn-se1_ for Sweden and _azirevpn-dk1_ Denmark, etc.)
2. `wg-quick up azirevpn-se1` to connect to, say, Sweden.
3. `wg-quick down azirevpn-se1` to disconnect, say, from Sweden.
4. To query your connection status, either run `ifconfig | grep azire` or `sudo wg show`.
That’s not terrible but it’s not exactly elegant.
So today, which I designate as national yak shaving day, I wrote a tiny bash script to make it easier.
## Installation
Save the script, below, to somewhere on your path (like _/usr/local/bin_) and give it execute permissions:
```sh
chmod +x vpn
```
## Usage
### Connect to the default server
```sh
▶ vpn
```
Sample output:
```
📡 Connecting to AzireVPN in UK…
✅ Done.
```
### Connect to a specific server
```sh
▶ vpn netherlands
```
Sample output:
```
👋 Disconnecting existing connection…
📡 Connecting to AzireVPN in Netherlands…
✅ Done.
```
Currently supported countries (all lowercase): canada, denmark, spain, netherlands, norway, sweden, sweden2, thailand, uk, us.
### Disconnect
```sh
▶ vpn down
```
Sample output:
```
👋 Disconnecting from AzireVPN in Netherlands…
✅ Done.
```
### Get connection status
```sh
▶ vpn ?
```
Sample output:
```
❌ You are not connected to AzireVPN via Wireguard.
```
What I really want to do is to write a little status bar app for it that automatically connects on untrusted networks and does so to the nearest server by default but this should tide me over till then.
Hope you enjoy it!
\ No newline at end of file
#!/bin/bash
######################################################################
#
# Wireguard connection/disconnection helper for AzireVPN.
#
# Copyright © 2020 Aral Balkan, Small Technology Foundation.
# License: AGPL version 3.0 or later.
#
# Like this? Fund us! https://small-tech.org/fund-us
#
######################################################################
set -e
action='up'
currentConnection=`ifconfig | grep azirevpn- | cut -c10-12`
declare -A serverCodesToLocations
serverCodesToLocations=(
['ca1']='Canada'
['dk1']='Denmark'
['es1']='Spain'
['nl1']='Netherlands'
['no1']='Norway'
['se1']='Sweden'
['se2']='Sweden (2)'
['th1']='Thailand'
['uk1']='UK'
['us1']='US'
)
declare -A locationsToServerCodes
locationsToServerCodes=(
['canada']='ca1'
['denmark']='dk1'
['spain']='es1'
['netherlands']='nl1'
['norway']='no1'
['sweden']='se1'
['sweden2']='se2'
['thailand']='th1'
['uk']='uk1'
['us']='us1'
)
if [[ $1 == '?' ]]; then
if [[ $currentConnection == '' ]]; then
echo -e "\n ❌ You are not connected to AzireVPN via Wireguard.\n"
exit 1
fi
location="${serverCodesToLocations[${currentConnection}]}"
echo -e "\n ✅ You’re connected to AzireVPN in ${location} via Wireguard.\n"
exit 0
fi
if [[ $1 == 'down' ]]; then
action='down'
if [[ $currentConnection == '' ]]; then
echo -e "\n ❌ You are not connected to AzireVPN via Wireguard.\n"
exit 1
fi
serverCode=$currentConnection
echo -e "\n 👋 Disconnecting from AzireVPN in ${serverCodesToLocations[${currentConnection}]}…"
else
location=$1
if [[ $1 == '' ]]; then
location='uk'
fi
serverCode="${locationsToServerCodes[${location}]}"
if [[ $currentConnection != '' ]]; then
if [[ $currentConnection == $serverCode ]]; then
echo -e "\n 😁👍 You’re already connected to that VPN server.\n"
exit
fi
printf "\n 👋 Disconnecting existing connection…"
wg-quick down "azirevpn-${currentConnection}" > /dev/null 2>&1
exit
fi
echo -e "\n 📡 Connecting to AzireVPN in ${serverCodesToLocations[${serverCode}]}…"
fi
server="azirevpn-${serverCode}"
wg-quick "${action}" "${server}" > /dev/null 2>&1
echo -e " ✅ Done.\n"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment