Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b86f29f59 | ||
|
|
12eafa0f65 | ||
|
|
7acca7bc10 | ||
|
|
5cc55c92fa |
@@ -1,2 +1,2 @@
|
||||
FROM qmcgaw/godevcontainer
|
||||
RUN apk add wireguard-tools htop
|
||||
RUN apk add wireguard-tools
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"vscode"
|
||||
],
|
||||
"shutdownAction": "stopCompose",
|
||||
"postCreateCommand": "source ~/.windows.sh && go mod download && go mod tidy",
|
||||
"postCreateCommand": "~/.windows.sh && go mod download && go mod tidy",
|
||||
"workspaceFolder": "/workspace",
|
||||
"extensions": [
|
||||
"golang.go",
|
||||
@@ -25,7 +25,6 @@
|
||||
"bajdzis.vscode-database", // Supports connections to mysql or postgres, over SSL, socked
|
||||
"IBM.output-colorizer", // Colorize your output/test logs
|
||||
"mohsen1.prettify-json", // Prettify JSON data
|
||||
"github.copilot",
|
||||
],
|
||||
"settings": {
|
||||
"files.eol": "\n",
|
||||
|
||||
@@ -3,6 +3,7 @@ version: "3.7"
|
||||
services:
|
||||
vscode:
|
||||
build: .
|
||||
image: godevcontainer
|
||||
devices:
|
||||
- /dev/net/tun:/dev/net/tun
|
||||
volumes:
|
||||
@@ -10,16 +11,16 @@ services:
|
||||
# Docker socket to access Docker server
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
# Docker configuration
|
||||
- ~/.docker:/root/.docker
|
||||
- ~/.docker:/root/.docker:z
|
||||
# SSH directory for Linux, OSX and WSL
|
||||
- ~/.ssh:/root/.ssh
|
||||
- ~/.ssh:/root/.ssh:z
|
||||
# For Windows without WSL, a copy will be made
|
||||
# from /tmp/.ssh to ~/.ssh to fix permissions
|
||||
#- ~/.ssh:/tmp/.ssh:ro
|
||||
# Shell history persistence
|
||||
- ~/.zsh_history:/root/.zsh_history
|
||||
- ~/.zsh_history:/root/.zsh_history:z
|
||||
# Git config
|
||||
- ~/.gitconfig:/root/.gitconfig
|
||||
- ~/.gitconfig:/root/.gitconfig:z
|
||||
environment:
|
||||
- TZ=
|
||||
cap_add:
|
||||
|
||||
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
@@ -96,7 +96,7 @@ body:
|
||||
attributes:
|
||||
label: Share your logs
|
||||
description: No sensitive information is logged out except when running with `LOG_LEVEL=debug`.
|
||||
render: plain text
|
||||
render: log
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
|
||||
37
.github/workflows/ci-skip.yml
vendored
37
.github/workflows/ci-skip.yml
vendored
@@ -1,37 +0,0 @@
|
||||
name: No trigger file paths
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- .github/workflows/ci.yml
|
||||
- cmd/**
|
||||
- internal/**
|
||||
- pkg/**
|
||||
- .dockerignore
|
||||
- .golangci.yml
|
||||
- Dockerfile
|
||||
- go.mod
|
||||
- go.sum
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- .github/workflows/ci.yml
|
||||
- cmd/**
|
||||
- internal/**
|
||||
- pkg/**
|
||||
- .dockerignore
|
||||
- .golangci.yml
|
||||
- Dockerfile
|
||||
- go.mod
|
||||
- go.sum
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
steps:
|
||||
- name: No trigger path triggered for required verify workflow.
|
||||
run: exit 0
|
||||
62
.github/workflows/ci.yml
vendored
62
.github/workflows/ci.yml
vendored
@@ -32,10 +32,13 @@ on:
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
# Only run if it's a push event or if it's a PR from this repository, and it is not dependabot.
|
||||
if: |
|
||||
github.actor != 'dependabot[bot]' &&
|
||||
(github.event_name == 'push' ||
|
||||
github.event_name == 'release' ||
|
||||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
env:
|
||||
DOCKER_BUILDKIT: "1"
|
||||
steps:
|
||||
@@ -49,6 +52,9 @@ jobs:
|
||||
- name: Linting
|
||||
run: docker build --target lint .
|
||||
|
||||
- name: Go mod tidy check
|
||||
run: docker build --target tidy .
|
||||
|
||||
- name: Build test image
|
||||
run: docker build --target test -t test-container .
|
||||
|
||||
@@ -59,35 +65,28 @@ jobs:
|
||||
-v "$(pwd)/coverage.txt:/tmp/gobuild/coverage.txt" \
|
||||
test-container
|
||||
|
||||
- name: Code security analysis
|
||||
uses: snyk/actions/golang@master
|
||||
env:
|
||||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
|
||||
- name: Build final image
|
||||
run: docker build -t final-image .
|
||||
|
||||
codeql:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: go
|
||||
- uses: github/codeql-action/autobuild@v2
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
# - name: Image security analysis
|
||||
# uses: snyk/actions/docker@master
|
||||
# env:
|
||||
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
||||
# with:
|
||||
# image: final-image
|
||||
|
||||
publish:
|
||||
# Only run if it's a push event or if it's a PR from this repository
|
||||
if: |
|
||||
github.repository == 'qdm12/gluetun' &&
|
||||
(
|
||||
github.event_name == 'push' ||
|
||||
github.event_name == 'release' ||
|
||||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
|
||||
)
|
||||
needs: [verify, codeql]
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
github.event_name == 'push' ||
|
||||
github.event_name == 'release' ||
|
||||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
|
||||
needs: [verify]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@@ -96,7 +95,7 @@ jobs:
|
||||
# https://github.com/docker/metadata-action
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
flavor: |
|
||||
latest=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
|
||||
@@ -104,16 +103,17 @@ jobs:
|
||||
qmcgaw/gluetun
|
||||
qmcgaw/private-internet-access
|
||||
tags: |
|
||||
type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
|
||||
type=ref,event=pr
|
||||
type=semver,pattern=v{{major}}.{{minor}}.{{patch}}
|
||||
type=semver,pattern=v{{major}}.{{minor}}
|
||||
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
|
||||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
|
||||
|
||||
- uses: docker/setup-qemu-action@v2
|
||||
- uses: docker/setup-buildx-action@v2
|
||||
- uses: docker/setup-qemu-action@v1
|
||||
- uses: docker/setup-buildx-action@v1
|
||||
|
||||
- uses: docker/login-action@v2
|
||||
- uses: docker/login-action@v1
|
||||
with:
|
||||
username: qmcgaw
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
@@ -123,7 +123,7 @@ jobs:
|
||||
run: echo "::set-output name=value::$(git rev-parse --short HEAD)"
|
||||
|
||||
- name: Build and push final image
|
||||
uses: docker/build-push-action@v3.0.0
|
||||
uses: docker/build-push-action@v2.9.0
|
||||
with:
|
||||
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7,linux/ppc64le
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
37
.github/workflows/dependabot.yml
vendored
Normal file
37
.github/workflows/dependabot.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: Dependabot
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- .github/workflows/dependabot.yml
|
||||
- cmd/**
|
||||
- internal/**
|
||||
- pkg/**
|
||||
- .dockerignore
|
||||
- .golangci.yml
|
||||
- Dockerfile
|
||||
- go.mod
|
||||
- go.sum
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOCKER_BUILDKIT: "1"
|
||||
steps:
|
||||
- uses: actions/checkout@v2.4.0
|
||||
|
||||
- name: Build test image
|
||||
run: docker build --target test -t test-container .
|
||||
|
||||
- name: Run tests in test container
|
||||
run: |
|
||||
touch coverage.txt
|
||||
docker run --rm \
|
||||
-v "$(pwd)/coverage.txt:/tmp/gobuild/coverage.txt" \
|
||||
test-container
|
||||
|
||||
- name: Build final image
|
||||
run: docker build -t final-image .
|
||||
16
.github/workflows/dockerhub-description.yml
vendored
16
.github/workflows/dockerhub-description.yml
vendored
@@ -1,22 +1,18 @@
|
||||
name: Docker Hub description
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
branches: [master]
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
jobs:
|
||||
docker-hub-description:
|
||||
if: github.repository == 'qdm12/gluetun'
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: peter-evans/dockerhub-description@v3
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.4.0
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
with:
|
||||
username: qmcgaw
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
|
||||
40
.github/workflows/fork.yml
vendored
Normal file
40
.github/workflows/fork.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Fork
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- .github/workflows/fork.yml
|
||||
- cmd/**
|
||||
- internal/**
|
||||
- pkg/**
|
||||
- .dockerignore
|
||||
- .golangci.yml
|
||||
- Dockerfile
|
||||
- go.mod
|
||||
- go.sum
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
if: github.event.pull_request.head.repo.full_name != github.repository && github.actor != 'dependabot[bot]'
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOCKER_BUILDKIT: "1"
|
||||
steps:
|
||||
- uses: actions/checkout@v2.4.0
|
||||
|
||||
- name: Linting
|
||||
run: docker build --target lint .
|
||||
|
||||
- name: Build test image
|
||||
run: docker build --target test -t test-container .
|
||||
|
||||
- name: Run tests in test container
|
||||
run: |
|
||||
touch coverage.txt
|
||||
docker run --rm \
|
||||
-v "$(pwd)/coverage.txt:/tmp/gobuild/coverage.txt" \
|
||||
test-container
|
||||
|
||||
- name: Build final image
|
||||
run: docker build -t final-image .
|
||||
4
.github/workflows/labels.yml
vendored
4
.github/workflows/labels.yml
vendored
@@ -9,7 +9,7 @@ jobs:
|
||||
labeler:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: crazy-max/ghaction-github-labeler@v4
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- uses: crazy-max/ghaction-github-labeler@v3
|
||||
with:
|
||||
yaml-file: .github/labels.yml
|
||||
|
||||
15
.github/workflows/misspell.yml
vendored
Normal file
15
.github/workflows/misspell.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: Misspells
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
push:
|
||||
branches: [master]
|
||||
jobs:
|
||||
misspell:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- uses: reviewdog/action-misspell@v1
|
||||
with:
|
||||
locale: "US"
|
||||
level: error
|
||||
@@ -7,47 +7,48 @@ issues:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- dupl
|
||||
- maligned
|
||||
- goerr113
|
||||
- containedctx
|
||||
- path: "internal\\/server\\/.+\\.go"
|
||||
- path: internal/server/
|
||||
linters:
|
||||
- dupl
|
||||
- path: "internal\\/configuration\\/settings\\/.+\\.go"
|
||||
- path: internal/configuration/
|
||||
linters:
|
||||
- dupl
|
||||
- text: "^mnd: Magic number: 0[0-9]{3}, in <argument> detected$"
|
||||
source: "^.+= os\\.OpenFile\\(.+, .+, 0[0-9]{3}\\)"
|
||||
- path: internal/constants/
|
||||
linters:
|
||||
- dupl
|
||||
- text: "exported: exported var Err*"
|
||||
linters:
|
||||
- revive
|
||||
- text: "mnd: Magic number: 0644*"
|
||||
linters:
|
||||
- gomnd
|
||||
|
||||
- text: "^mnd: Magic number: 0[0-9]{3}, in <argument> detected$"
|
||||
source: "^.+= os\\.MkdirAll\\(.+, 0[0-9]{3}\\)"
|
||||
- text: "mnd: Magic number: 0400*"
|
||||
linters:
|
||||
- gomnd
|
||||
- linters:
|
||||
- lll
|
||||
source: "^//go:generate .+$"
|
||||
- text: "returns interface \\(github\\.com\\/vishvananda\\/netlink\\.Link\\)"
|
||||
- text: "variable 'mssFix' is only used in the if-statement*"
|
||||
path: "openvpnconf.go"
|
||||
linters:
|
||||
- ireturn
|
||||
|
||||
- ifshort
|
||||
- text: "variable 'auth' is only used in the if-statement*"
|
||||
path: "openvpnconf.go"
|
||||
linters:
|
||||
- ifshort
|
||||
linters:
|
||||
enable:
|
||||
# - cyclop
|
||||
# - errorlint
|
||||
# - ireturn
|
||||
# - varnamelen
|
||||
# - wrapcheck
|
||||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
- containedctx
|
||||
- decorder
|
||||
- dogsled
|
||||
- dupl
|
||||
- durationcheck
|
||||
- errchkjson
|
||||
- errname
|
||||
- execinquery
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- forcetypeassert
|
||||
@@ -66,12 +67,9 @@ linters:
|
||||
- gomoddirectives
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- grouper
|
||||
- ifshort
|
||||
- importas
|
||||
- ireturn
|
||||
- lll
|
||||
- maintidx
|
||||
- makezero
|
||||
- misspell
|
||||
- nakedret
|
||||
@@ -80,7 +78,6 @@ linters:
|
||||
- nilnil
|
||||
- noctx
|
||||
- nolintlint
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- predeclared
|
||||
|
||||
25
.vscode/launch.json
vendored
25
.vscode/launch.json
vendored
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Update a VPN provider servers data",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"program": "cmd/gluetun/main.go",
|
||||
"args": [
|
||||
"update",
|
||||
"-enduser",
|
||||
"-providers",
|
||||
"${input:provider}"
|
||||
],
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"id": "provider",
|
||||
"type": "promptString",
|
||||
"description": "Please enter a provider (or comma separated list of providers)",
|
||||
}
|
||||
]
|
||||
}
|
||||
66
Dockerfile
66
Dockerfile
@@ -1,8 +1,8 @@
|
||||
ARG ALPINE_VERSION=3.16
|
||||
ARG GO_ALPINE_VERSION=3.16
|
||||
ARG ALPINE_VERSION=3.15
|
||||
ARG GO_ALPINE_VERSION=3.15
|
||||
ARG GO_VERSION=1.17
|
||||
ARG XCPUTRANSLATE_VERSION=v0.6.0
|
||||
ARG GOLANGCI_LINT_VERSION=v1.46.2
|
||||
ARG GOLANGCI_LINT_VERSION=v1.43.0
|
||||
ARG BUILDPLATFORM=linux/amd64
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} qmcgaw/xcputranslate:${XCPUTRANSLATE_VERSION} AS xcputranslate
|
||||
@@ -30,6 +30,15 @@ FROM --platform=${BUILDPLATFORM} base AS lint
|
||||
COPY .golangci.yml ./
|
||||
RUN golangci-lint run --timeout=10m
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} base AS tidy
|
||||
RUN git init && \
|
||||
git config user.email ci@localhost && \
|
||||
git config user.name ci && \
|
||||
git add -A && git commit -m ci && \
|
||||
sed -i '/\/\/ indirect/d' go.mod && \
|
||||
go mod tidy && \
|
||||
git diff --exit-code -- go.mod
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} base AS build
|
||||
ARG TARGETPLATFORM
|
||||
ARG VERSION=unknown
|
||||
@@ -57,12 +66,8 @@ LABEL \
|
||||
org.opencontainers.image.source="https://github.com/qdm12/gluetun" \
|
||||
org.opencontainers.image.title="VPN swiss-knife like client for multiple VPN providers" \
|
||||
org.opencontainers.image.description="VPN swiss-knife like client to tunnel to multiple VPN servers using OpenVPN, IPtables, DNS over TLS, Shadowsocks, an HTTP proxy and Alpine Linux"
|
||||
ENV VPN_SERVICE_PROVIDER=pia \
|
||||
ENV VPNSP=pia \
|
||||
VPN_TYPE=openvpn \
|
||||
# Common VPN options
|
||||
VPN_ENDPOINT_IP= \
|
||||
VPN_ENDPOINT_PORT= \
|
||||
VPN_INTERFACE=tun0 \
|
||||
# OpenVPN
|
||||
OPENVPN_PROTOCOL=udp \
|
||||
OPENVPN_USER= \
|
||||
@@ -72,35 +77,41 @@ ENV VPN_SERVICE_PROVIDER=pia \
|
||||
OPENVPN_VERSION=2.5 \
|
||||
OPENVPN_VERBOSITY=1 \
|
||||
OPENVPN_FLAGS= \
|
||||
OPENVPN_CIPHERS= \
|
||||
OPENVPN_CIPHER= \
|
||||
OPENVPN_AUTH= \
|
||||
OPENVPN_PROCESS_USER= \
|
||||
OPENVPN_ROOT=yes \
|
||||
OPENVPN_TARGET_IP= \
|
||||
OPENVPN_IPV6=off \
|
||||
OPENVPN_CUSTOM_CONFIG= \
|
||||
OPENVPN_INTERFACE=tun0 \
|
||||
OPENVPN_PORT= \
|
||||
# Wireguard
|
||||
WIREGUARD_PRIVATE_KEY= \
|
||||
WIREGUARD_PRESHARED_KEY= \
|
||||
WIREGUARD_PUBLIC_KEY= \
|
||||
WIREGUARD_ADDRESSES= \
|
||||
WIREGUARD_ADDRESS= \
|
||||
WIREGUARD_ENDPOINT_IP= \
|
||||
WIREGUARD_ENDPOINT_PORT= \
|
||||
WIREGUARD_INTERFACE=wg0 \
|
||||
# VPN server filtering
|
||||
SERVER_REGIONS= \
|
||||
SERVER_COUNTRIES= \
|
||||
SERVER_CITIES= \
|
||||
SERVER_HOSTNAMES= \
|
||||
REGION= \
|
||||
COUNTRY= \
|
||||
CITY= \
|
||||
SERVER_HOSTNAME= \
|
||||
# # Mullvad only:
|
||||
ISP= \
|
||||
OWNED_ONLY=no \
|
||||
OWNED=no \
|
||||
# # Private Internet Access only:
|
||||
PRIVATE_INTERNET_ACCESS_OPENVPN_ENCRYPTION_PRESET= \
|
||||
PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING=off \
|
||||
PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING_STATUS_FILE="/tmp/gluetun/forwarded_port" \
|
||||
PIA_ENCRYPTION= \
|
||||
PORT_FORWARDING=off \
|
||||
PORT_FORWARDING_STATUS_FILE="/tmp/gluetun/forwarded_port" \
|
||||
# # Cyberghost only:
|
||||
OPENVPN_CLIENTCRT_SECRETFILE=/run/secrets/openvpn_clientcrt \
|
||||
OPENVPN_CLIENTKEY_SECRETFILE=/run/secrets/openvpn_clientkey \
|
||||
# # Nordvpn only:
|
||||
SERVER_NUMBER= \
|
||||
# # PIA only:
|
||||
SERVER_NAMES= \
|
||||
# # PIA and ProtonVPN only:
|
||||
SERVER_NAME= \
|
||||
# # ProtonVPN only:
|
||||
FREE_ONLY= \
|
||||
# # Surfshark only:
|
||||
@@ -115,7 +126,7 @@ ENV VPN_SERVICE_PROVIDER=pia \
|
||||
LOG_LEVEL=info \
|
||||
# Health
|
||||
HEALTH_SERVER_ADDRESS=127.0.0.1:9999 \
|
||||
HEALTH_TARGET_ADDRESS=cloudflare.com:443 \
|
||||
HEALTH_TARGET_ADDRESS=github.com:443 \
|
||||
HEALTH_VPN_DURATION_INITIAL=6s \
|
||||
HEALTH_VPN_DURATION_ADDITION=5s \
|
||||
# DNS over TLS
|
||||
@@ -132,7 +143,7 @@ ENV VPN_SERVICE_PROVIDER=pia \
|
||||
BLOCK_ADS=off \
|
||||
UNBLOCK= \
|
||||
DNS_UPDATE_PERIOD=24h \
|
||||
DNS_ADDRESS=127.0.0.1 \
|
||||
DNS_PLAINTEXT_ADDRESS=127.0.0.1 \
|
||||
DNS_KEEP_NAMESERVER=off \
|
||||
# HTTP proxy
|
||||
HTTPPROXY= \
|
||||
@@ -149,20 +160,11 @@ ENV VPN_SERVICE_PROVIDER=pia \
|
||||
SHADOWSOCKS_PASSWORD= \
|
||||
SHADOWSOCKS_PASSWORD_SECRETFILE=/run/secrets/shadowsocks_password \
|
||||
SHADOWSOCKS_CIPHER=chacha20-ietf-poly1305 \
|
||||
# Control server
|
||||
HTTP_CONTROL_SERVER_ADDRESS=":8000" \
|
||||
# Server data updater
|
||||
UPDATER_PERIOD=0 \
|
||||
UPDATER_MIN_RATIO=0.8 \
|
||||
UPDATER_VPN_SERVICE_PROVIDERS= \
|
||||
# Public IP
|
||||
PUBLICIP_FILE="/tmp/gluetun/ip" \
|
||||
PUBLICIP_PERIOD=12h \
|
||||
# Pprof
|
||||
PPROF_ENABLED=no \
|
||||
PPROF_BLOCK_PROFILE_RATE=0 \
|
||||
PPROF_MUTEX_PROFILE_RATE=0 \
|
||||
PPROF_HTTP_SERVER_ADDRESS=":6060" \
|
||||
# Extras
|
||||
VERSION_INFORMATION=on \
|
||||
TZ= \
|
||||
|
||||
16
README.md
16
README.md
@@ -1,6 +1,11 @@
|
||||
# Gluetun VPN client
|
||||
|
||||
Lightweight swiss-knife-like VPN client to multiple VPN sercice providers
|
||||
*Lightweight swiss-knife-like VPN client to tunnel to Cyberghost, ExpressVPN, FastestVPN,
|
||||
HideMyAss, IPVanish, IVPN, Mullvad, NordVPN, Perfect Privacy, Privado, Private Internet Access, PrivateVPN,
|
||||
ProtonVPN, PureVPN, Surfshark, TorGuard, VPNUnlimited, VyprVPN, WeVPN and Windscribe VPN servers
|
||||
using Go, OpenVPN or Wireguard, iptables, DNS over TLS, ShadowSocks and an HTTP proxy*
|
||||
|
||||
**ANNOUNCEMENT**: Large settings refactor merged on 2022-06-01, please file issues if you find any problem!
|
||||
|
||||

|
||||
|
||||
@@ -48,7 +53,6 @@ Lightweight swiss-knife-like VPN client to multiple VPN sercice providers
|
||||
- Sponsor me on [github.com/sponsors/qdm12](https://github.com/sponsors/qdm12)
|
||||
- Donate to [paypal.me/qmcgaw](https://www.paypal.me/qmcgaw)
|
||||
- Drop me [an email](mailto:quentin.mcgaw@gmail.com)
|
||||
- **Want to add a VPN provider?** check [Development](https://github.com/qdm12/gluetun/wiki/Development) and [Add a provider](https://github.com/qdm12/gluetun/wiki/Add-a-provider)
|
||||
- Video:
|
||||
|
||||
[](https://youtu.be/0F6I03LQcI4)
|
||||
@@ -57,7 +61,7 @@ Lightweight swiss-knife-like VPN client to multiple VPN sercice providers
|
||||
|
||||
## Features
|
||||
|
||||
- Based on Alpine 3.16 for a small Docker image of 29MB
|
||||
- Based on Alpine 3.15 for a small Docker image of 29MB
|
||||
- Supports: **Cyberghost**, **ExpressVPN**, **FastestVPN**, **HideMyAss**, **IPVanish**, **IVPN**, **Mullvad**, **NordVPN**, **Perfect Privacy**, **Privado**, **Private Internet Access**, **PrivateVPN**, **ProtonVPN**, **PureVPN**, **Surfshark**, **TorGuard**, **VPNUnlimited**, **Vyprvpn**, **WeVPN**, **Windscribe** servers
|
||||
- Supports OpenVPN for all providers listed
|
||||
- Supports Wireguard both kernelspace and userspace
|
||||
@@ -98,8 +102,6 @@ services:
|
||||
# line above must be uncommented to allow external containers to connect. See https://github.com/qdm12/gluetun/wiki/Connect-a-container-to-gluetun#external-container-to-gluetun
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
devices:
|
||||
- /dev/net/tun:/dev/net/tun
|
||||
ports:
|
||||
- 8888:8888/tcp # HTTP proxy
|
||||
- 8388:8388/tcp # Shadowsocks
|
||||
@@ -108,14 +110,14 @@ services:
|
||||
- /yourpath:/gluetun
|
||||
environment:
|
||||
# See https://github.com/qdm12/gluetun/wiki
|
||||
- VPN_SERVICE_PROVIDER=ivpn
|
||||
- VPNSP=ivpn
|
||||
- VPN_TYPE=openvpn
|
||||
# OpenVPN:
|
||||
- OPENVPN_USER=
|
||||
- OPENVPN_PASSWORD=
|
||||
# Wireguard:
|
||||
# - WIREGUARD_PRIVATE_KEY=wOEI9rqqbDwnN8/Bpp22sVz48T71vJ4fYmFWujulwUU=
|
||||
# - WIREGUARD_ADDRESSES=10.64.222.21/32
|
||||
# - WIREGUARD_ADDRESS=10.64.222.21/32
|
||||
# Timezone for accurate log times
|
||||
- TZ=
|
||||
```
|
||||
|
||||
@@ -29,28 +29,22 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/netlink"
|
||||
"github.com/qdm12/gluetun/internal/openvpn"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
"github.com/qdm12/gluetun/internal/portforward"
|
||||
"github.com/qdm12/gluetun/internal/pprof"
|
||||
"github.com/qdm12/gluetun/internal/provider"
|
||||
"github.com/qdm12/gluetun/internal/publicip"
|
||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
"github.com/qdm12/gluetun/internal/routing"
|
||||
"github.com/qdm12/gluetun/internal/server"
|
||||
"github.com/qdm12/gluetun/internal/shadowsocks"
|
||||
"github.com/qdm12/gluetun/internal/storage"
|
||||
"github.com/qdm12/gluetun/internal/tun"
|
||||
updater "github.com/qdm12/gluetun/internal/updater/loop"
|
||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
"github.com/qdm12/gluetun/internal/updater"
|
||||
"github.com/qdm12/gluetun/internal/vpn"
|
||||
"github.com/qdm12/golibs/command"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"github.com/qdm12/goshutdown"
|
||||
"github.com/qdm12/goshutdown/goroutine"
|
||||
"github.com/qdm12/goshutdown/group"
|
||||
"github.com/qdm12/goshutdown/order"
|
||||
"github.com/qdm12/gosplash"
|
||||
"github.com/qdm12/log"
|
||||
"github.com/qdm12/updated/pkg/dnscrypto"
|
||||
)
|
||||
|
||||
@@ -61,6 +55,11 @@ var (
|
||||
created = "an unknown date"
|
||||
)
|
||||
|
||||
var (
|
||||
errSetupRouting = errors.New("cannot setup routing")
|
||||
errCreateUser = errors.New("cannot create user")
|
||||
)
|
||||
|
||||
func main() {
|
||||
buildInfo := models.BuildInformation{
|
||||
Version: version,
|
||||
@@ -69,11 +68,12 @@ func main() {
|
||||
}
|
||||
|
||||
background := context.Background()
|
||||
signalCh := make(chan os.Signal, 1)
|
||||
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
|
||||
signalCtx, stop := signal.NotifyContext(background, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
ctx, cancel := context.WithCancel(background)
|
||||
|
||||
logger := log.New(log.SetLevel(log.LevelInfo))
|
||||
logger := logging.New(logging.Settings{
|
||||
Level: logging.LevelInfo,
|
||||
})
|
||||
|
||||
args := os.Args
|
||||
tun := tun.New()
|
||||
@@ -92,11 +92,13 @@ func main() {
|
||||
}()
|
||||
|
||||
select {
|
||||
case signal := <-signalCh:
|
||||
case <-signalCtx.Done():
|
||||
stop()
|
||||
fmt.Println("")
|
||||
logger.Warn("Caught OS signal " + signal.String() + ", shutting down")
|
||||
logger.Warn("Caught OS signal, shutting down")
|
||||
cancel()
|
||||
case err := <-errorCh:
|
||||
stop()
|
||||
close(errorCh)
|
||||
if err == nil { // expected exit such as healthcheck
|
||||
os.Exit(0)
|
||||
@@ -115,8 +117,6 @@ func main() {
|
||||
logger.Info("Shutdown successful")
|
||||
case <-timer.C:
|
||||
logger.Warn("Shutdown timed out")
|
||||
case signal := <-signalCh:
|
||||
logger.Warn("Caught OS signal " + signal.String() + ", forcing shut down")
|
||||
}
|
||||
|
||||
os.Exit(1)
|
||||
@@ -126,11 +126,11 @@ var (
|
||||
errCommandUnknown = errors.New("command is unknown")
|
||||
)
|
||||
|
||||
//nolint:gocognit,gocyclo,maintidx
|
||||
//nolint:gocognit,gocyclo
|
||||
func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
args []string, logger log.LoggerInterface, source sources.Source,
|
||||
tun Tun, netLinker netLinker, cmder command.RunStarter,
|
||||
cli clier) error {
|
||||
args []string, logger logging.ParentLogger, source sources.Source,
|
||||
tun tun.Interface, netLinker netlink.NetLinker, cmder command.RunStarter,
|
||||
cli cli.CLIer) error {
|
||||
if len(args) > 1 { // cli operation
|
||||
switch args[1] {
|
||||
case "healthcheck":
|
||||
@@ -174,62 +174,21 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
return err
|
||||
}
|
||||
|
||||
// Note: no need to validate minimal settings for the firewall:
|
||||
// - global log level is parsed from source
|
||||
// - firewall Debug and Enabled are booleans parsed from source
|
||||
|
||||
logger.Patch(log.SetLevel(*allSettings.Log.Level))
|
||||
|
||||
routingLogger := logger.New(log.SetComponent("routing"))
|
||||
if *allSettings.Firewall.Debug { // To remove in v4
|
||||
routingLogger.Patch(log.SetLevel(log.LevelDebug))
|
||||
}
|
||||
routingConf := routing.New(netLinker, routingLogger)
|
||||
|
||||
defaultRoutes, err := routingConf.DefaultRoutes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
localNetworks, err := routingConf.LocalNetworks()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
firewallLogger := logger.New(log.SetComponent("firewall"))
|
||||
if *allSettings.Firewall.Debug { // To remove in v4
|
||||
firewallLogger.Patch(log.SetLevel(log.LevelDebug))
|
||||
}
|
||||
firewallConf, err := firewall.NewConfig(ctx, firewallLogger, cmder,
|
||||
defaultRoutes, localNetworks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if *allSettings.Firewall.Enabled {
|
||||
err = firewallConf.SetEnabled(ctx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// TODO run this in a loop or in openvpn to reload from file without restarting
|
||||
storageLogger := logger.New(log.SetComponent("storage"))
|
||||
storageLogger := logger.NewChild(logging.Settings{Prefix: "storage: "})
|
||||
storage, err := storage.New(storageLogger, constants.ServersData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = allSettings.Validate(storage)
|
||||
allServers := storage.GetServers()
|
||||
|
||||
err = allSettings.Validate(allServers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allSettings.Pprof.HTTPServer.Logger = logger.New(log.SetComponent("pprof"))
|
||||
pprofServer, err := pprof.New(allSettings.Pprof)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create Pprof server: %w", err)
|
||||
}
|
||||
logger.PatchLevel(*allSettings.Log.Level)
|
||||
|
||||
puid, pgid := int(*allSettings.System.PUID), int(*allSettings.System.PGID)
|
||||
|
||||
@@ -238,7 +197,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
// Create configurators
|
||||
alpineConf := alpine.New()
|
||||
ovpnConf := openvpn.New(
|
||||
logger.New(log.SetComponent("openvpn configurator")),
|
||||
logger.NewChild(logging.Settings{Prefix: "openvpn configurator: "}),
|
||||
cmder, puid, pgid)
|
||||
dnsCrypto := dnscrypto.New(httpClient, "", "")
|
||||
const cacertsPath = "/etc/ssl/certs/ca-certificates.crt"
|
||||
@@ -270,7 +229,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
const defaultUsername = "nonrootuser"
|
||||
nonRootUsername, err := alpineConf.CreateUser(defaultUsername, puid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create user: %w", err)
|
||||
return fmt.Errorf("%w: %s", errCreateUser, err)
|
||||
}
|
||||
if nonRootUsername != defaultUsername {
|
||||
logger.Info("using existing username " + nonRootUsername + " corresponding to user id " + fmt.Sprint(puid))
|
||||
@@ -278,22 +237,54 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
// set it for Unbound
|
||||
// TODO remove this when migrating to qdm12/dns v2
|
||||
allSettings.DNS.DoT.Unbound.Username = nonRootUsername
|
||||
allSettings.VPN.OpenVPN.ProcessUser = nonRootUsername
|
||||
allSettings.VPN.OpenVPN.ProcUser = nonRootUsername
|
||||
|
||||
if err := os.Chown("/etc/unbound", puid, pgid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
firewallLogLevel := *allSettings.Log.Level
|
||||
if *allSettings.Firewall.Debug {
|
||||
firewallLogLevel = logging.LevelDebug
|
||||
}
|
||||
routingLogger := logger.NewChild(logging.Settings{
|
||||
Prefix: "routing: ",
|
||||
Level: firewallLogLevel,
|
||||
})
|
||||
routingConf := routing.New(netLinker, routingLogger)
|
||||
|
||||
defaultInterface, defaultGateway, err := routingConf.DefaultRoute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
localNetworks, err := routingConf.LocalNetworks()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defaultIP, err := routingConf.DefaultIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
firewallLogger := logger.NewChild(logging.Settings{
|
||||
Prefix: "firewall: ",
|
||||
Level: firewallLogLevel,
|
||||
})
|
||||
firewallConf := firewall.NewConfig(firewallLogger, cmder,
|
||||
defaultInterface, defaultGateway, localNetworks, defaultIP)
|
||||
|
||||
if err := routingConf.Setup(); err != nil {
|
||||
if strings.Contains(err.Error(), "operation not permitted") {
|
||||
logger.Warn("💡 Tip: Are you passing NET_ADMIN capability to gluetun?")
|
||||
}
|
||||
return fmt.Errorf("cannot setup routing: %w", err)
|
||||
return fmt.Errorf("%w: %s", errSetupRouting, err)
|
||||
}
|
||||
defer func() {
|
||||
routingLogger.Info("routing cleanup...")
|
||||
logger.Info("routing cleanup...")
|
||||
if err := routingConf.TearDown(); err != nil {
|
||||
routingLogger.Error("cannot teardown routing: " + err.Error())
|
||||
logger.Error("cannot teardown routing: " + err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -304,21 +295,25 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
return err
|
||||
}
|
||||
|
||||
const tunDevice = "/dev/net/tun"
|
||||
if err := tun.Check(tunDevice); err != nil {
|
||||
if err := tun.Check(constants.TunnelDevice); err != nil {
|
||||
logger.Info(err.Error() + "; creating it...")
|
||||
err = tun.Create(tunDevice)
|
||||
err = tun.Create(constants.TunnelDevice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if *allSettings.Firewall.Enabled {
|
||||
err := firewallConf.SetEnabled(ctx, true) // disabled by default
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, port := range allSettings.Firewall.InputPorts {
|
||||
for _, defaultRoute := range defaultRoutes {
|
||||
err = firewallConf.SetAllowedPort(ctx, port, defaultRoute.NetInterface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = firewallConf.SetAllowedPort(ctx, port, defaultInterface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} // TODO move inside firewall?
|
||||
|
||||
@@ -339,20 +334,14 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
tickersGroupHandler := goshutdown.NewGroupHandler("tickers", defaultGroupOptions...)
|
||||
otherGroupHandler := goshutdown.NewGroupHandler("other", defaultGroupOptions...)
|
||||
|
||||
pprofReady := make(chan struct{})
|
||||
pprofHandler, pprofCtx, pprofDone := goshutdown.NewGoRoutineHandler("pprof server")
|
||||
go pprofServer.Run(pprofCtx, pprofReady, pprofDone)
|
||||
otherGroupHandler.Add(pprofHandler)
|
||||
<-pprofReady
|
||||
|
||||
portForwardLogger := logger.New(log.SetComponent("port forwarding"))
|
||||
portForwardLogger := logger.NewChild(logging.Settings{Prefix: "port forwarding: "})
|
||||
portForwardLooper := portforward.NewLoop(allSettings.VPN.Provider.PortForwarding,
|
||||
httpClient, firewallConf, portForwardLogger, puid, pgid)
|
||||
httpClient, firewallConf, portForwardLogger)
|
||||
portForwardHandler, portForwardCtx, portForwardDone := goshutdown.NewGoRoutineHandler(
|
||||
"port forwarding", goroutine.OptionTimeout(time.Second))
|
||||
go portForwardLooper.Run(portForwardCtx, portForwardDone)
|
||||
|
||||
unboundLogger := logger.New(log.SetComponent("dns over tls"))
|
||||
unboundLogger := logger.NewChild(logging.Settings{Prefix: "dns over tls: "})
|
||||
unboundLooper := dns.NewLoop(dnsConf, allSettings.DNS, httpClient,
|
||||
unboundLogger)
|
||||
dnsHandler, dnsCtx, dnsDone := goshutdown.NewGoRoutineHandler(
|
||||
@@ -366,9 +355,8 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
go unboundLooper.RunRestartTicker(dnsTickerCtx, dnsTickerDone)
|
||||
controlGroupHandler.Add(dnsTickerHandler)
|
||||
|
||||
ipFetcher := ipinfo.New(httpClient)
|
||||
publicIPLooper := publicip.NewLoop(ipFetcher,
|
||||
logger.New(log.SetComponent("ip getter")),
|
||||
publicIPLooper := publicip.NewLoop(httpClient,
|
||||
logger.NewChild(logging.Settings{Prefix: "ip getter: "}),
|
||||
allSettings.PublicIP, puid, pgid)
|
||||
pubIPHandler, pubIPCtx, pubIPDone := goshutdown.NewGoRoutineHandler(
|
||||
"public IP", goroutine.OptionTimeout(defaultShutdownTimeout))
|
||||
@@ -380,25 +368,18 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
go publicIPLooper.RunRestartTicker(pubIPTickerCtx, pubIPTickerDone)
|
||||
tickersGroupHandler.Add(pubIPTickerHandler)
|
||||
|
||||
updaterLogger := logger.New(log.SetComponent("updater"))
|
||||
|
||||
unzipper := unzip.New(httpClient)
|
||||
parallelResolver := resolver.NewParallelResolver(allSettings.Updater.DNSAddress)
|
||||
openvpnFileExtractor := extract.New()
|
||||
providers := provider.NewProviders(storage, time.Now, updaterLogger,
|
||||
httpClient, unzipper, parallelResolver, ipFetcher, openvpnFileExtractor)
|
||||
|
||||
vpnLogger := logger.New(log.SetComponent("vpn"))
|
||||
vpnLogger := logger.NewChild(logging.Settings{Prefix: "vpn: "})
|
||||
vpnLooper := vpn.NewLoop(allSettings.VPN, allSettings.Firewall.VPNInputPorts,
|
||||
providers, storage, ovpnConf, netLinker, firewallConf, routingConf, portForwardLooper,
|
||||
allServers, ovpnConf, netLinker, firewallConf, routingConf, portForwardLooper,
|
||||
cmder, publicIPLooper, unboundLooper, vpnLogger, httpClient,
|
||||
buildInfo, *allSettings.Version.Enabled)
|
||||
vpnHandler, vpnCtx, vpnDone := goshutdown.NewGoRoutineHandler(
|
||||
"vpn", goroutine.OptionTimeout(time.Second))
|
||||
go vpnLooper.Run(vpnCtx, vpnDone)
|
||||
|
||||
updaterLooper := updater.NewLoop(allSettings.Updater,
|
||||
providers, storage, httpClient, updaterLogger)
|
||||
updaterLooper := updater.NewLooper(allSettings.Updater,
|
||||
allServers, storage, vpnLooper.SetServers, httpClient,
|
||||
logger.NewChild(logging.Settings{Prefix: "updater: "}))
|
||||
updaterHandler, updaterCtx, updaterDone := goshutdown.NewGoRoutineHandler(
|
||||
"updater", goroutine.OptionTimeout(defaultShutdownTimeout))
|
||||
// wait for updaterLooper.Restart() or its ticket launched with RunRestartTicker
|
||||
@@ -411,36 +392,31 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
controlGroupHandler.Add(updaterTickerHandler)
|
||||
|
||||
httpProxyLooper := httpproxy.NewLoop(
|
||||
logger.New(log.SetComponent("http proxy")),
|
||||
logger.NewChild(logging.Settings{Prefix: "http proxy: "}),
|
||||
allSettings.HTTPProxy)
|
||||
httpProxyHandler, httpProxyCtx, httpProxyDone := goshutdown.NewGoRoutineHandler(
|
||||
"http proxy", goroutine.OptionTimeout(defaultShutdownTimeout))
|
||||
go httpProxyLooper.Run(httpProxyCtx, httpProxyDone)
|
||||
otherGroupHandler.Add(httpProxyHandler)
|
||||
|
||||
shadowsocksLooper := shadowsocks.NewLoop(allSettings.Shadowsocks,
|
||||
logger.New(log.SetComponent("shadowsocks")))
|
||||
shadowsocksLooper := shadowsocks.NewLooper(allSettings.Shadowsocks,
|
||||
logger.NewChild(logging.Settings{Prefix: "shadowsocks: "}))
|
||||
shadowsocksHandler, shadowsocksCtx, shadowsocksDone := goshutdown.NewGoRoutineHandler(
|
||||
"shadowsocks proxy", goroutine.OptionTimeout(defaultShutdownTimeout))
|
||||
go shadowsocksLooper.Run(shadowsocksCtx, shadowsocksDone)
|
||||
otherGroupHandler.Add(shadowsocksHandler)
|
||||
|
||||
controlServerAddress := *allSettings.ControlServer.Address
|
||||
controlServerAddress := fmt.Sprintf(":%d", *allSettings.ControlServer.Port)
|
||||
controlServerLogging := *allSettings.ControlServer.Log
|
||||
httpServerHandler, httpServerCtx, httpServerDone := goshutdown.NewGoRoutineHandler(
|
||||
"http server", goroutine.OptionTimeout(defaultShutdownTimeout))
|
||||
httpServer, err := server.New(httpServerCtx, controlServerAddress, controlServerLogging,
|
||||
logger.New(log.SetComponent("http server")),
|
||||
httpServer := server.New(httpServerCtx, controlServerAddress, controlServerLogging,
|
||||
logger.NewChild(logging.Settings{Prefix: "http server: "}),
|
||||
buildInfo, vpnLooper, portForwardLooper, unboundLooper, updaterLooper, publicIPLooper)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot setup control server: %w", err)
|
||||
}
|
||||
httpServerReady := make(chan struct{})
|
||||
go httpServer.Run(httpServerCtx, httpServerReady, httpServerDone)
|
||||
<-httpServerReady
|
||||
go httpServer.Run(httpServerCtx, httpServerDone)
|
||||
controlGroupHandler.Add(httpServerHandler)
|
||||
|
||||
healthLogger := logger.New(log.SetComponent("healthcheck"))
|
||||
healthLogger := logger.NewChild(logging.Settings{Prefix: "healthcheck: "})
|
||||
healthcheckServer := healthcheck.NewServer(allSettings.Health, healthLogger, vpnLooper)
|
||||
healthServerHandler, healthServerCtx, healthServerDone := goshutdown.NewGoRoutineHandler(
|
||||
"HTTP health server", goroutine.OptionTimeout(defaultShutdownTimeout))
|
||||
@@ -487,38 +463,3 @@ func printVersions(ctx context.Context, logger infoer,
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type netLinker interface {
|
||||
AddrList(link netlink.Link, family int) (
|
||||
addresses []netlink.Addr, err error)
|
||||
AddrAdd(link netlink.Link, addr *netlink.Addr) error
|
||||
IsWireguardSupported() (ok bool, err error)
|
||||
RouteList(link netlink.Link, family int) (
|
||||
routes []netlink.Route, err error)
|
||||
RouteAdd(route *netlink.Route) error
|
||||
RouteDel(route *netlink.Route) error
|
||||
RouteReplace(route *netlink.Route) error
|
||||
RuleList(family int) (rules []netlink.Rule, err error)
|
||||
RuleAdd(rule *netlink.Rule) error
|
||||
RuleDel(rule *netlink.Rule) error
|
||||
LinkList() (links []netlink.Link, err error)
|
||||
LinkByName(name string) (link netlink.Link, err error)
|
||||
LinkByIndex(index int) (link netlink.Link, err error)
|
||||
LinkAdd(link netlink.Link) (err error)
|
||||
LinkDel(link netlink.Link) (err error)
|
||||
LinkSetUp(link netlink.Link) (err error)
|
||||
LinkSetDown(link netlink.Link) (err error)
|
||||
}
|
||||
|
||||
type clier interface {
|
||||
ClientKey(args []string) error
|
||||
FormatServers(args []string) error
|
||||
OpenvpnConfig(logger cli.OpenvpnConfigLogger, source sources.Source) error
|
||||
HealthCheck(ctx context.Context, source sources.Source, warner cli.Warner) error
|
||||
Update(ctx context.Context, args []string, logger cli.UpdaterLogger) error
|
||||
}
|
||||
|
||||
type Tun interface {
|
||||
Check(tunDevice string) error
|
||||
Create(tunDevice string) error
|
||||
}
|
||||
|
||||
10
go.mod
10
go.mod
@@ -3,7 +3,7 @@ module github.com/qdm12/gluetun
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/breml/rootcerts v0.2.3
|
||||
github.com/breml/rootcerts v0.2.1
|
||||
github.com/fatih/color v1.13.0
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/qdm12/dns v1.11.0
|
||||
@@ -12,13 +12,11 @@ require (
|
||||
github.com/qdm12/gosplash v0.1.0
|
||||
github.com/qdm12/gotree v0.2.0
|
||||
github.com/qdm12/govalid v0.1.0
|
||||
github.com/qdm12/log v0.1.0
|
||||
github.com/qdm12/ss-server v0.4.0
|
||||
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e
|
||||
github.com/stretchr/testify v1.7.2
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/vishvananda/netlink v1.1.1-0.20211129163951-9ada19101fc5
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
|
||||
golang.org/x/text v0.3.7
|
||||
golang.zx2c4.com/wireguard v0.0.0-20210805125648-3957e9b9dd19
|
||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c
|
||||
inet.af/netaddr v0.0.0-20210718074554-06ca8145d722
|
||||
@@ -38,8 +36,8 @@ require (
|
||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
||||
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect
|
||||
go4.org/intern v0.0.0-20210108033219-3eb7198706b2 // indirect
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
|
||||
golang.org/x/net v0.0.0-20210504132125-bbd867fde50d // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
||||
18
go.sum
18
go.sum
@@ -4,8 +4,8 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/g
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/breml/rootcerts v0.2.3 h1:1vkYjKOiHVSyuz9Ue4AOrViEvUm8gk8phTg0vbcuU0A=
|
||||
github.com/breml/rootcerts v0.2.3/go.mod h1:24FDtzYMpqIeYC7QzaE8VPRQaFZU5TIUDlyk8qwjD88=
|
||||
github.com/breml/rootcerts v0.2.1 h1:GZMVDXOs945764NFck0vtHSjktKYubOFM0kjf5HAuwc=
|
||||
github.com/breml/rootcerts v0.2.1/go.mod h1:24FDtzYMpqIeYC7QzaE8VPRQaFZU5TIUDlyk8qwjD88=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
@@ -115,8 +115,6 @@ github.com/qdm12/gotree v0.2.0 h1:+58ltxkNLUyHtATFereAcOjBVfY6ETqRex8XK90Fb/c=
|
||||
github.com/qdm12/gotree v0.2.0/go.mod h1:1SdFaqKZuI46U1apbXIf25pDMNnrPuYLEqMF/qL4lY4=
|
||||
github.com/qdm12/govalid v0.1.0 h1:UIFVmuaAg0Q+h0GeyfcFEZ5sQ5KJPvRQwycC1/cqDN8=
|
||||
github.com/qdm12/govalid v0.1.0/go.mod h1:CyS/OEQdOvunBgrtIsW93fjd4jBkwZPBjGSpxq3NwA4=
|
||||
github.com/qdm12/log v0.1.0 h1:jYBd/xscHYpblzZAd2kjZp2YmuYHjAAfbTViJWxoPTw=
|
||||
github.com/qdm12/log v0.1.0/go.mod h1:Vchi5M8uBvHfPNIblN4mjXn/oSbiWguQIbsgF1zdQPI=
|
||||
github.com/qdm12/ss-server v0.4.0 h1:lMMYfDGc9P86Lyvd3+p8lK4hhgHUKDzjZC91FqJYkDU=
|
||||
github.com/qdm12/ss-server v0.4.0/go.mod h1:AY0p4huvPUPW+/CiWsJcDgT6sneDryk26VXSccPNCxY=
|
||||
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e h1:4q+uFLawkaQRq3yARYLsjJPZd2wYwxn4g6G/5v0xW1g=
|
||||
@@ -130,10 +128,8 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/vishvananda/netlink v1.1.1-0.20211129163951-9ada19101fc5 h1:b/k/BVWzWRS5v6AB0gf2ckFSbFsHN5jR0HoNso1pN+w=
|
||||
github.com/vishvananda/netlink v1.1.1-0.20211129163951-9ada19101fc5/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
|
||||
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae h1:4hwBBUfQCFe3Cym0ZtKyq7L16eZUtYKs+BaHDN6mAns=
|
||||
@@ -145,9 +141,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
||||
go4.org/intern v0.0.0-20210108033219-3eb7198706b2 h1:VFTf+jjIgsldaz/Mr00VaCSswHJrI2hIjQygE/W4IMg=
|
||||
go4.org/intern v0.0.0-20210108033219-3eb7198706b2/go.mod h1:vLqJ+12kCw61iCWsPto0EOHhBS+o4rO5VIucbc9g2Cc=
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222175341-b30ae309168e/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063 h1:1tk03FUNpulq2cuWpXZWj649rwJpk0d20rxWiopKRmc=
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 h1:FyBZqvoA/jbNzuAWLQE2kG820zMAkcilx6BMjGbL/E4=
|
||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@@ -224,8 +219,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
@@ -251,9 +244,8 @@ gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQb
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
inet.af/netaddr v0.0.0-20210511181906-37180328850c/go.mod h1:z0nx+Dh+7N7CC8V5ayHtHGpZpxLQZZxkIaaz6HN65Ls=
|
||||
inet.af/netaddr v0.0.0-20210718074554-06ca8145d722 h1:Qws2rZnQudC58cIagVucPQDLmMi3kAXgxscsgD0v6DU=
|
||||
inet.af/netaddr v0.0.0-20210718074554-06ca8145d722/go.mod h1:z0nx+Dh+7N7CC8V5ayHtHGpZpxLQZZxkIaaz6HN65Ls=
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
// Package alpine defines a configurator to interact with the Alpine operating system.
|
||||
package alpine
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
)
|
||||
|
||||
var _ Alpiner = (*Alpine)(nil)
|
||||
|
||||
type Alpiner interface {
|
||||
UserCreater
|
||||
VersionGetter
|
||||
}
|
||||
|
||||
type Alpine struct {
|
||||
alpineReleasePath string
|
||||
passwdPath string
|
||||
|
||||
@@ -12,6 +12,10 @@ var (
|
||||
ErrUserAlreadyExists = errors.New("user already exists")
|
||||
)
|
||||
|
||||
type UserCreater interface {
|
||||
CreateUser(username string, uid int) (createdUsername string, err error)
|
||||
}
|
||||
|
||||
// CreateUser creates a user in Alpine with the given UID.
|
||||
func (a *Alpine) CreateUser(username string, uid int) (createdUsername string, err error) {
|
||||
UIDStr := strconv.Itoa(uid)
|
||||
|
||||
@@ -7,6 +7,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type VersionGetter interface {
|
||||
Version(ctx context.Context) (version string, err error)
|
||||
}
|
||||
|
||||
func (a *Alpine) Version(ctx context.Context) (version string, err error) {
|
||||
file, err := os.OpenFile(a.alpineReleasePath, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
// Package cli defines an interface CLI to run command line operations.
|
||||
package cli
|
||||
|
||||
var _ CLIer = (*CLI)(nil)
|
||||
|
||||
type CLIer interface {
|
||||
ClientKeyFormatter
|
||||
HealthChecker
|
||||
OpenvpnConfigMaker
|
||||
Updater
|
||||
ServersFormatter
|
||||
}
|
||||
|
||||
type CLI struct {
|
||||
repoServersPath string
|
||||
}
|
||||
|
||||
@@ -7,12 +7,16 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
type ClientKeyFormatter interface {
|
||||
ClientKey(args []string) error
|
||||
}
|
||||
|
||||
func (c *CLI) ClientKey(args []string) error {
|
||||
flagSet := flag.NewFlagSet("clientkey", flag.ExitOnError)
|
||||
filepath := flagSet.String("path", files.OpenVPNClientKeyPath, "file path to the client.key file")
|
||||
filepath := flagSet.String("path", constants.ClientKey, "file path to the client.key file")
|
||||
if err := flagSet.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,44 +6,51 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/storage"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
type ServersFormatter interface {
|
||||
FormatServers(args []string) error
|
||||
}
|
||||
|
||||
var (
|
||||
ErrFormatNotRecognized = errors.New("format is not recognized")
|
||||
ErrProviderUnspecified = errors.New("VPN provider to format was not specified")
|
||||
ErrMultipleProvidersToFormat = errors.New("more than one VPN provider to format were specified")
|
||||
ErrFormatNotRecognized = errors.New("format is not recognized")
|
||||
ErrProviderUnspecified = errors.New("VPN provider to format was not specified")
|
||||
ErrOpenOutputFile = errors.New("cannot open output file")
|
||||
ErrWriteOutput = errors.New("cannot write to output file")
|
||||
ErrCloseOutputFile = errors.New("cannot close output file")
|
||||
)
|
||||
|
||||
func addProviderFlag(flagSet *flag.FlagSet, providerToFormat map[string]*bool,
|
||||
provider string, titleCaser cases.Caser) {
|
||||
boolPtr, ok := providerToFormat[provider]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("unknown provider in format map: %s", provider))
|
||||
}
|
||||
flagSet.BoolVar(boolPtr, provider, false, "Format "+titleCaser.String(provider)+" servers")
|
||||
}
|
||||
|
||||
func (c *CLI) FormatServers(args []string) error {
|
||||
var format, output string
|
||||
allProviders := providers.All()
|
||||
providersToFormat := make(map[string]*bool, len(allProviders))
|
||||
for _, provider := range allProviders {
|
||||
providersToFormat[provider] = new(bool)
|
||||
}
|
||||
var cyberghost, expressvpn, fastestvpn, hideMyAss, ipvanish, ivpn, mullvad,
|
||||
nordvpn, perfectPrivacy, pia, privado, privatevpn, protonvpn, purevpn, surfshark,
|
||||
torguard, vpnUnlimited, vyprvpn, wevpn, windscribe bool
|
||||
flagSet := flag.NewFlagSet("markdown", flag.ExitOnError)
|
||||
flagSet.StringVar(&format, "format", "markdown", "Format to use which can be: 'markdown'")
|
||||
flagSet.StringVar(&output, "output", "/dev/stdout", "Output file to write the formatted data to")
|
||||
titleCaser := cases.Title(language.English)
|
||||
for _, provider := range allProviders {
|
||||
addProviderFlag(flagSet, providersToFormat, provider, titleCaser)
|
||||
}
|
||||
flagSet.BoolVar(&cyberghost, "cyberghost", false, "Format Cyberghost servers")
|
||||
flagSet.BoolVar(&expressvpn, "expressvpn", false, "Format ExpressVPN servers")
|
||||
flagSet.BoolVar(&fastestvpn, "fastestvpn", false, "Format FastestVPN servers")
|
||||
flagSet.BoolVar(&hideMyAss, "hidemyass", false, "Format HideMyAss servers")
|
||||
flagSet.BoolVar(&ipvanish, "ipvanish", false, "Format IpVanish servers")
|
||||
flagSet.BoolVar(&ivpn, "ivpn", false, "Format IVPN servers")
|
||||
flagSet.BoolVar(&mullvad, "mullvad", false, "Format Mullvad servers")
|
||||
flagSet.BoolVar(&nordvpn, "nordvpn", false, "Format Nordvpn servers")
|
||||
flagSet.BoolVar(&perfectPrivacy, "perfectprivacy", false, "Format Perfect Privacy servers")
|
||||
flagSet.BoolVar(&pia, "pia", false, "Format Private Internet Access servers")
|
||||
flagSet.BoolVar(&privado, "privado", false, "Format Privado servers")
|
||||
flagSet.BoolVar(&privatevpn, "privatevpn", false, "Format Private VPN servers")
|
||||
flagSet.BoolVar(&protonvpn, "protonvpn", false, "Format Protonvpn servers")
|
||||
flagSet.BoolVar(&purevpn, "purevpn", false, "Format Purevpn servers")
|
||||
flagSet.BoolVar(&surfshark, "surfshark", false, "Format Surfshark servers")
|
||||
flagSet.BoolVar(&torguard, "torguard", false, "Format Torguard servers")
|
||||
flagSet.BoolVar(&vpnUnlimited, "vpnunlimited", false, "Format VPN Unlimited servers")
|
||||
flagSet.BoolVar(&vyprvpn, "vyprvpn", false, "Format Vyprvpn servers")
|
||||
flagSet.BoolVar(&wevpn, "wevpn", false, "Format WeVPN servers")
|
||||
flagSet.BoolVar(&windscribe, "windscribe", false, "Format Windscribe servers")
|
||||
if err := flagSet.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -52,47 +59,74 @@ func (c *CLI) FormatServers(args []string) error {
|
||||
return fmt.Errorf("%w: %s", ErrFormatNotRecognized, format)
|
||||
}
|
||||
|
||||
// Verify only one provider is set to be formatted.
|
||||
var providers []string
|
||||
for provider, formatPtr := range providersToFormat {
|
||||
if *formatPtr {
|
||||
providers = append(providers, provider)
|
||||
}
|
||||
}
|
||||
switch len(providers) {
|
||||
case 0:
|
||||
return ErrProviderUnspecified
|
||||
case 1:
|
||||
default:
|
||||
return fmt.Errorf("%w: %d specified: %s",
|
||||
ErrMultipleProvidersToFormat, len(providers),
|
||||
strings.Join(providers, ", "))
|
||||
}
|
||||
providerToFormat := providers[0]
|
||||
|
||||
logger := newNoopLogger()
|
||||
storage, err := storage.New(logger, constants.ServersData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create servers storage: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrNewStorage, err)
|
||||
}
|
||||
currentServers := storage.GetServers()
|
||||
|
||||
formatted := storage.FormatToMarkdown(providerToFormat)
|
||||
var formatted string
|
||||
switch {
|
||||
case cyberghost:
|
||||
formatted = currentServers.Cyberghost.ToMarkdown()
|
||||
case expressvpn:
|
||||
formatted = currentServers.Expressvpn.ToMarkdown()
|
||||
case fastestvpn:
|
||||
formatted = currentServers.Fastestvpn.ToMarkdown()
|
||||
case hideMyAss:
|
||||
formatted = currentServers.HideMyAss.ToMarkdown()
|
||||
case ipvanish:
|
||||
formatted = currentServers.Ipvanish.ToMarkdown()
|
||||
case ivpn:
|
||||
formatted = currentServers.Ivpn.ToMarkdown()
|
||||
case mullvad:
|
||||
formatted = currentServers.Mullvad.ToMarkdown()
|
||||
case nordvpn:
|
||||
formatted = currentServers.Nordvpn.ToMarkdown()
|
||||
case perfectPrivacy:
|
||||
formatted = currentServers.Perfectprivacy.ToMarkdown()
|
||||
case pia:
|
||||
formatted = currentServers.Pia.ToMarkdown()
|
||||
case privado:
|
||||
formatted = currentServers.Privado.ToMarkdown()
|
||||
case privatevpn:
|
||||
formatted = currentServers.Privatevpn.ToMarkdown()
|
||||
case protonvpn:
|
||||
formatted = currentServers.Protonvpn.ToMarkdown()
|
||||
case purevpn:
|
||||
formatted = currentServers.Purevpn.ToMarkdown()
|
||||
case surfshark:
|
||||
formatted = currentServers.Surfshark.ToMarkdown()
|
||||
case torguard:
|
||||
formatted = currentServers.Torguard.ToMarkdown()
|
||||
case vpnUnlimited:
|
||||
formatted = currentServers.VPNUnlimited.ToMarkdown()
|
||||
case vyprvpn:
|
||||
formatted = currentServers.Vyprvpn.ToMarkdown()
|
||||
case wevpn:
|
||||
formatted = currentServers.Wevpn.ToMarkdown()
|
||||
case windscribe:
|
||||
formatted = currentServers.Windscribe.ToMarkdown()
|
||||
default:
|
||||
return ErrProviderUnspecified
|
||||
}
|
||||
|
||||
output = filepath.Clean(output)
|
||||
file, err := os.OpenFile(output, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot open output file: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrOpenOutputFile, err)
|
||||
}
|
||||
|
||||
_, err = fmt.Fprint(file, formatted)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return fmt.Errorf("cannot write to output file: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrWriteOutput, err)
|
||||
}
|
||||
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot close output file: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrCloseOutputFile, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -10,6 +10,10 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/healthcheck"
|
||||
)
|
||||
|
||||
type HealthChecker interface {
|
||||
HealthCheck(ctx context.Context, source sources.Source, warner Warner) error
|
||||
}
|
||||
|
||||
func (c *CLI) HealthCheck(ctx context.Context, source sources.Source, warner Warner) error {
|
||||
// Extract the health server port from the configuration.
|
||||
config, err := source.ReadHealth()
|
||||
|
||||
@@ -1,73 +1,50 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/sources"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
"github.com/qdm12/gluetun/internal/provider"
|
||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
"github.com/qdm12/gluetun/internal/storage"
|
||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||
)
|
||||
|
||||
type OpenvpnConfigMaker interface {
|
||||
OpenvpnConfig(logger OpenvpnConfigLogger, source sources.Source) error
|
||||
}
|
||||
|
||||
type OpenvpnConfigLogger interface {
|
||||
Info(s string)
|
||||
Warn(s string)
|
||||
}
|
||||
|
||||
type Unzipper interface {
|
||||
FetchAndExtract(ctx context.Context, url string) (
|
||||
contents map[string][]byte, err error)
|
||||
}
|
||||
|
||||
type ParallelResolver interface {
|
||||
Resolve(ctx context.Context, settings resolver.ParallelSettings) (
|
||||
hostToIPs map[string][]net.IP, warnings []string, err error)
|
||||
}
|
||||
|
||||
type IPFetcher interface {
|
||||
FetchMultiInfo(ctx context.Context, ips []net.IP) (data []ipinfo.Response, err error)
|
||||
}
|
||||
|
||||
func (c *CLI) OpenvpnConfig(logger OpenvpnConfigLogger, source sources.Source) error {
|
||||
storage, err := storage.New(logger, constants.ServersData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
allServers := storage.GetServers()
|
||||
|
||||
allSettings, err := source.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = allSettings.Validate(storage); err != nil {
|
||||
if err = allSettings.Validate(allServers); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Unused by this CLI command
|
||||
unzipper := (Unzipper)(nil)
|
||||
client := (*http.Client)(nil)
|
||||
warner := (Warner)(nil)
|
||||
parallelResolver := (ParallelResolver)(nil)
|
||||
ipFetcher := (IPFetcher)(nil)
|
||||
openvpnFileExtractor := extract.New()
|
||||
|
||||
providers := provider.NewProviders(storage, time.Now, warner, client,
|
||||
unzipper, parallelResolver, ipFetcher, openvpnFileExtractor)
|
||||
providerConf := providers.Get(*allSettings.VPN.Provider.Name)
|
||||
providerConf := provider.New(*allSettings.VPN.Provider.Name, allServers, time.Now)
|
||||
connection, err := providerConf.GetConnection(allSettings.VPN.Provider.ServerSelection)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lines := providerConf.OpenVPNConfig(connection, allSettings.VPN.OpenVPN)
|
||||
lines, err := providerConf.BuildConf(connection, allSettings.VPN.OpenVPN)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(strings.Join(lines, "\n"))
|
||||
return nil
|
||||
|
||||
@@ -2,48 +2,53 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
"github.com/qdm12/gluetun/internal/provider"
|
||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/storage"
|
||||
"github.com/qdm12/gluetun/internal/updater"
|
||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrModeUnspecified = errors.New("at least one of -enduser or -maintainer must be specified")
|
||||
ErrNoProviderSpecified = errors.New("no provider was specified")
|
||||
ErrModeUnspecified = errors.New("at least one of -enduser or -maintainer must be specified")
|
||||
ErrDNSAddress = errors.New("DNS address is not valid")
|
||||
ErrNoProviderSpecified = errors.New("no provider was specified")
|
||||
ErrNewStorage = errors.New("cannot create storage")
|
||||
ErrUpdateServerInformation = errors.New("cannot update server information")
|
||||
ErrWriteToFile = errors.New("cannot write updated information to file")
|
||||
)
|
||||
|
||||
type Updater interface {
|
||||
Update(ctx context.Context, args []string, logger UpdaterLogger) error
|
||||
}
|
||||
|
||||
type UpdaterLogger interface {
|
||||
Info(s string)
|
||||
Warn(s string)
|
||||
Error(s string)
|
||||
}
|
||||
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) error {
|
||||
options := settings.Updater{}
|
||||
options := settings.Updater{CLI: boolPtr(true)}
|
||||
var endUserMode, maintainerMode, updateAll bool
|
||||
var csvProviders string
|
||||
var dnsAddress, csvProviders string
|
||||
flagSet := flag.NewFlagSet("update", flag.ExitOnError)
|
||||
flagSet.BoolVar(&endUserMode, "enduser", false, "Write results to /gluetun/servers.json (for end users)")
|
||||
flagSet.BoolVar(&maintainerMode, "maintainer", false,
|
||||
"Write results to ./internal/storage/servers.json to modify the program (for maintainers)")
|
||||
flagSet.StringVar(&options.DNSAddress, "dns", "8.8.8.8", "DNS resolver address to use")
|
||||
const defaultMinRatio = 0.8
|
||||
flagSet.Float64Var(&options.MinRatio, "minratio", defaultMinRatio,
|
||||
"Minimum ratio of servers to find for the update to succeed")
|
||||
flagSet.StringVar(&dnsAddress, "dns", "8.8.8.8", "DNS resolver address to use")
|
||||
flagSet.BoolVar(&updateAll, "all", false, "Update servers for all VPN providers")
|
||||
flagSet.StringVar(&csvProviders, "providers", "", "CSV string of VPN providers to update server data for")
|
||||
if err := flagSet.Parse(args); err != nil {
|
||||
@@ -54,8 +59,18 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e
|
||||
return ErrModeUnspecified
|
||||
}
|
||||
|
||||
options.DNSAddress = net.ParseIP(dnsAddress)
|
||||
if options.DNSAddress == nil {
|
||||
return fmt.Errorf("%w: %s", ErrDNSAddress, dnsAddress)
|
||||
}
|
||||
|
||||
if updateAll {
|
||||
options.Providers = providers.All()
|
||||
for _, provider := range constants.AllProviders() {
|
||||
if provider == constants.Custom {
|
||||
continue
|
||||
}
|
||||
options.Providers = append(options.Providers, provider)
|
||||
}
|
||||
} else {
|
||||
if csvProviders == "" {
|
||||
return ErrNoProviderSpecified
|
||||
@@ -63,40 +78,55 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e
|
||||
options.Providers = strings.Split(csvProviders, ",")
|
||||
}
|
||||
|
||||
options.SetDefaults(options.Providers[0])
|
||||
options.SetDefaults()
|
||||
|
||||
err := options.Validate()
|
||||
if err != nil {
|
||||
return fmt.Errorf("options validation failed: %w", err)
|
||||
}
|
||||
|
||||
storage, err := storage.New(logger, constants.ServersData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create servers storage: %w", err)
|
||||
}
|
||||
|
||||
const clientTimeout = 10 * time.Second
|
||||
httpClient := &http.Client{Timeout: clientTimeout}
|
||||
unzipper := unzip.New(httpClient)
|
||||
parallelResolver := resolver.NewParallelResolver(options.DNSAddress)
|
||||
ipFetcher := ipinfo.New(httpClient)
|
||||
openvpnFileExtractor := extract.New()
|
||||
|
||||
providers := provider.NewProviders(storage, time.Now, logger, httpClient,
|
||||
unzipper, parallelResolver, ipFetcher, openvpnFileExtractor)
|
||||
|
||||
updater := updater.New(httpClient, storage, providers, logger)
|
||||
err = updater.UpdateServers(ctx, options.Providers, options.MinRatio)
|
||||
storage, err := storage.New(logger, constants.ServersData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update server information: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrNewStorage, err)
|
||||
}
|
||||
currentServers := storage.GetServers()
|
||||
|
||||
updater := updater.New(options, httpClient, currentServers, logger)
|
||||
allServers, err := updater.UpdateServers(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrUpdateServerInformation, err)
|
||||
}
|
||||
|
||||
if endUserMode {
|
||||
if err := storage.FlushToFile(allServers); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrWriteToFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
if maintainerMode {
|
||||
err := storage.FlushToFile(c.repoServersPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot write servers data to embedded JSON file: %w", err)
|
||||
if err := writeToEmbeddedJSON(c.repoServersPath, allServers); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrWriteToFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeToEmbeddedJSON(repoServersPath string,
|
||||
allServers models.AllServers) error {
|
||||
const perms = 0600
|
||||
f, err := os.OpenFile(repoServersPath,
|
||||
os.O_TRUNC|os.O_WRONLY|os.O_CREATE, perms)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
encoder := json.NewEncoder(f)
|
||||
encoder.SetIndent("", " ")
|
||||
return encoder.Encode(allServers)
|
||||
}
|
||||
|
||||
@@ -6,14 +6,15 @@ var (
|
||||
ErrCityNotValid = errors.New("the city specified is not valid")
|
||||
ErrControlServerPrivilegedPort = errors.New("cannot use privileged port without running as root")
|
||||
ErrCountryNotValid = errors.New("the country specified is not valid")
|
||||
ErrFilepathMissing = errors.New("filepath is missing")
|
||||
ErrFirewallZeroPort = errors.New("cannot have a zero port to block")
|
||||
ErrHostnameNotValid = errors.New("the hostname specified is not valid")
|
||||
ErrISPNotValid = errors.New("the ISP specified is not valid")
|
||||
ErrMinRatioNotValid = errors.New("minimum ratio is not valid")
|
||||
ErrMissingValue = errors.New("missing value")
|
||||
ErrNameNotValid = errors.New("the server name specified is not valid")
|
||||
ErrOpenVPNClientCertMissing = errors.New("client certificate is missing")
|
||||
ErrOpenVPNClientCertNotValid = errors.New("client certificate is not valid")
|
||||
ErrOpenVPNClientKeyMissing = errors.New("client key is missing")
|
||||
ErrOpenVPNClientKeyNotValid = errors.New("client key is not valid")
|
||||
ErrOpenVPNConfigFile = errors.New("custom configuration file error")
|
||||
ErrOpenVPNCustomPortNotAllowed = errors.New("custom endpoint port is not allowed")
|
||||
ErrOpenVPNEncryptionPresetNotValid = errors.New("PIA encryption preset is not valid")
|
||||
ErrOpenVPNInterfaceNotValid = errors.New("interface name is not valid")
|
||||
@@ -24,13 +25,14 @@ var (
|
||||
ErrOpenVPNVerbosityIsOutOfBounds = errors.New("verbosity value is out of bounds")
|
||||
ErrOpenVPNVersionIsNotValid = errors.New("version is not valid")
|
||||
ErrPortForwardingEnabled = errors.New("port forwarding cannot be enabled")
|
||||
ErrPortForwardingFilepathNotValid = errors.New("port forwarding filepath given is not valid")
|
||||
ErrPublicIPFilepathNotValid = errors.New("public IP address file path is not valid")
|
||||
ErrPublicIPPeriodTooShort = errors.New("public IP address check period is too short")
|
||||
ErrRegionNotValid = errors.New("the region specified is not valid")
|
||||
ErrServerAddressNotValid = errors.New("server listening address is not valid")
|
||||
ErrSystemPGIDNotValid = errors.New("process group id is not valid")
|
||||
ErrSystemPUIDNotValid = errors.New("process user id is not valid")
|
||||
ErrSystemTimezoneNotValid = errors.New("timezone is not valid")
|
||||
ErrUpdaterPeriodTooSmall = errors.New("VPN server data updater period is too small")
|
||||
ErrVPNProviderNameNotValid = errors.New("VPN provider name is not valid")
|
||||
ErrVPNTypeNotValid = errors.New("VPN type is not valid")
|
||||
ErrWireguardEndpointIPNotSet = errors.New("endpoint IP is not set")
|
||||
@@ -39,7 +41,11 @@ var (
|
||||
ErrWireguardInterfaceAddressNotSet = errors.New("interface address is not set")
|
||||
ErrWireguardInterfaceNotValid = errors.New("interface name is not valid")
|
||||
ErrWireguardPreSharedKeyNotSet = errors.New("pre-shared key is not set")
|
||||
ErrWireguardPreSharedKeyNotValid = errors.New("pre-shared key is not valid")
|
||||
ErrWireguardPrivateKeyNotSet = errors.New("private key is not set")
|
||||
ErrWireguardPrivateKeyNotValid = errors.New("private key is not valid")
|
||||
ErrWireguardPublicKeyNotSet = errors.New("public key is not set")
|
||||
ErrWireguardPublicKeyNotValid = errors.New("public key is not valid")
|
||||
|
||||
ErrUpdaterPeriodTooSmall = errors.New("VPN server data updater period is too small")
|
||||
)
|
||||
|
||||
@@ -27,12 +27,13 @@ func (h Health) Validate() (err error) {
|
||||
_, err = address.Validate(h.ServerAddress,
|
||||
address.OptionListening(uid))
|
||||
if err != nil {
|
||||
return fmt.Errorf("server listening address is not valid: %w", err)
|
||||
return fmt.Errorf("%w: %s",
|
||||
ErrServerAddressNotValid, err)
|
||||
}
|
||||
|
||||
err = h.VPN.validate()
|
||||
if err != nil {
|
||||
return fmt.Errorf("health VPN settings: %w", err)
|
||||
return fmt.Errorf("health VPN settings validation failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -65,7 +66,7 @@ func (h *Health) OverrideWith(other Health) {
|
||||
|
||||
func (h *Health) SetDefaults() {
|
||||
h.ServerAddress = helpers.DefaultString(h.ServerAddress, "127.0.0.1:9999")
|
||||
h.TargetAddress = helpers.DefaultString(h.TargetAddress, "cloudflare.com:443")
|
||||
h.TargetAddress = helpers.DefaultString(h.TargetAddress, "github.com:443")
|
||||
h.VPN.setDefaults()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,9 @@ func IsOneOf(value string, choices ...string) (ok bool) {
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNoChoice = errors.New("one or more values is set but there is no possible value available")
|
||||
ErrValueNotOneOf = errors.New("value is not one of the possible choices")
|
||||
)
|
||||
var ErrValueNotOneOf = errors.New("value is not one of the possible choices")
|
||||
|
||||
func AreAllOneOf(values, choices []string) (err error) {
|
||||
if len(values) > 0 && len(choices) == 0 {
|
||||
return ErrNoChoice
|
||||
}
|
||||
|
||||
set := make(map[string]struct{}, len(choices))
|
||||
for _, choice := range choices {
|
||||
choice = strings.ToLower(choice)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
@@ -44,15 +44,6 @@ func CopyUint16Ptr(original *uint16) (copied *uint16) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyUint32Ptr(original *uint32) (copied *uint32) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
copied = new(uint32)
|
||||
*copied = *original
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIntPtr(original *int) (copied *int) {
|
||||
if original == nil {
|
||||
return nil
|
||||
@@ -71,11 +62,11 @@ func CopyDurationPtr(original *time.Duration) (copied *time.Duration) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyLogLevelPtr(original *log.Level) (copied *log.Level) {
|
||||
func CopyLogLevelPtr(original *logging.Level) (copied *logging.Level) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
copied = new(log.Level)
|
||||
copied = new(logging.Level)
|
||||
*copied = *original
|
||||
return copied
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
func DefaultInt(existing *int, defaultValue int) (
|
||||
@@ -36,15 +36,6 @@ func DefaultUint16(existing *uint16, defaultValue uint16) (
|
||||
*result = defaultValue
|
||||
return result
|
||||
}
|
||||
func DefaultUint32(existing *uint32, defaultValue uint32) (
|
||||
result *uint32) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
}
|
||||
result = new(uint32)
|
||||
*result = defaultValue
|
||||
return result
|
||||
}
|
||||
|
||||
func DefaultBool(existing *bool, defaultValue bool) (
|
||||
result *bool) {
|
||||
@@ -83,12 +74,12 @@ func DefaultDuration(existing *time.Duration,
|
||||
return result
|
||||
}
|
||||
|
||||
func DefaultLogLevel(existing *log.Level,
|
||||
defaultValue log.Level) (result *log.Level) {
|
||||
func DefaultLogLevel(existing *logging.Level,
|
||||
defaultValue logging.Level) (result *logging.Level) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
}
|
||||
result = new(log.Level)
|
||||
result = new(logging.Level)
|
||||
*result = defaultValue
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package helpers
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
@@ -27,20 +26,6 @@ func MergeWithString(existing, other string) (result string) {
|
||||
return other
|
||||
}
|
||||
|
||||
func MergeWithInt(existing, other int) (result int) {
|
||||
if existing != 0 {
|
||||
return existing
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func MergeWithFloat64(existing, other float64) (result float64) {
|
||||
if existing != 0 {
|
||||
return existing
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func MergeWithStringPtr(existing, other *string) (result *string) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
@@ -52,7 +37,7 @@ func MergeWithStringPtr(existing, other *string) (result *string) {
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeWithIntPtr(existing, other *int) (result *int) {
|
||||
func MergeWithInt(existing, other *int) (result *int) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
} else if other == nil {
|
||||
@@ -85,17 +70,6 @@ func MergeWithUint16(existing, other *uint16) (result *uint16) {
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeWithUint32(existing, other *uint32) (result *uint32) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
} else if other == nil {
|
||||
return nil
|
||||
}
|
||||
result = new(uint32)
|
||||
*result = *other
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeWithIP(existing, other net.IP) (result net.IP) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
@@ -114,24 +88,17 @@ func MergeWithDuration(existing, other *time.Duration) (result *time.Duration) {
|
||||
return other
|
||||
}
|
||||
|
||||
func MergeWithLogLevel(existing, other *log.Level) (result *log.Level) {
|
||||
func MergeWithLogLevel(existing, other *logging.Level) (result *logging.Level) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
} else if other == nil {
|
||||
return nil
|
||||
}
|
||||
result = new(log.Level)
|
||||
result = new(logging.Level)
|
||||
*result = *other
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeWithHTTPHandler(existing, other http.Handler) (result http.Handler) {
|
||||
if existing != nil {
|
||||
return existing
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func MergeStringSlices(a, b []string) (result []string) {
|
||||
if a == nil && b == nil {
|
||||
return nil
|
||||
|
||||
@@ -2,10 +2,9 @@ package helpers
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
@@ -25,20 +24,6 @@ func OverrideWithString(existing, other string) (result string) {
|
||||
return other
|
||||
}
|
||||
|
||||
func OverrideWithInt(existing, other int) (result int) {
|
||||
if other == 0 {
|
||||
return existing
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func OverrideWithFloat64(existing, other float64) (result float64) {
|
||||
if other == 0 {
|
||||
return existing
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
||||
func OverrideWithStringPtr(existing, other *string) (result *string) {
|
||||
if other == nil {
|
||||
return existing
|
||||
@@ -48,7 +33,7 @@ func OverrideWithStringPtr(existing, other *string) (result *string) {
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithIntPtr(existing, other *int) (result *int) {
|
||||
func OverrideWithInt(existing, other *int) (result *int) {
|
||||
if other == nil {
|
||||
return existing
|
||||
}
|
||||
@@ -75,15 +60,6 @@ func OverrideWithUint16(existing, other *uint16) (result *uint16) {
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithUint32(existing, other *uint32) (result *uint32) {
|
||||
if other == nil {
|
||||
return existing
|
||||
}
|
||||
result = new(uint32)
|
||||
*result = *other
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithIP(existing, other net.IP) (result net.IP) {
|
||||
if other == nil {
|
||||
return existing
|
||||
@@ -102,22 +78,15 @@ func OverrideWithDuration(existing, other *time.Duration) (result *time.Duration
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithLogLevel(existing, other *log.Level) (result *log.Level) {
|
||||
func OverrideWithLogLevel(existing, other *logging.Level) (result *logging.Level) {
|
||||
if other == nil {
|
||||
return existing
|
||||
}
|
||||
result = new(log.Level)
|
||||
result = new(logging.Level)
|
||||
*result = *other
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithHTTPHandler(existing, other http.Handler) (result http.Handler) {
|
||||
if other != nil {
|
||||
return other
|
||||
}
|
||||
return existing
|
||||
}
|
||||
|
||||
func OverrideWithStringSlice(existing, other []string) (result []string) {
|
||||
if other == nil {
|
||||
return existing
|
||||
|
||||
@@ -41,7 +41,8 @@ func (h HTTPProxy) validate() (err error) {
|
||||
uid := os.Getuid()
|
||||
_, err = address.Validate(h.ListeningAddress, address.OptionListening(uid))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrServerAddressNotValid, h.ListeningAddress)
|
||||
return fmt.Errorf("%w: %s",
|
||||
ErrServerAddressNotValid, h.ListeningAddress)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2,15 +2,15 @@ package settings
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"github.com/qdm12/gotree"
|
||||
"github.com/qdm12/log"
|
||||
)
|
||||
|
||||
// Log contains settings to configure the logger.
|
||||
type Log struct {
|
||||
// Level is the log level of the logger.
|
||||
// It cannot be nil in the internal state.
|
||||
Level *log.Level
|
||||
Level *logging.Level
|
||||
}
|
||||
|
||||
func (l Log) validate() (err error) {
|
||||
@@ -37,7 +37,7 @@ func (l *Log) overrideWith(other Log) {
|
||||
}
|
||||
|
||||
func (l *Log) setDefaults() {
|
||||
l.Level = helpers.DefaultLogLevel(l.Level, log.LevelInfo)
|
||||
l.Level = helpers.DefaultLogLevel(l.Level, logging.LevelInfo)
|
||||
}
|
||||
|
||||
func (l Log) String() string {
|
||||
|
||||
@@ -2,14 +2,11 @@ package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/openvpn"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/presets"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/parse"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -64,10 +61,15 @@ type OpenVPN struct {
|
||||
// Interface is the OpenVPN device interface name.
|
||||
// It cannot be an empty string in the internal state.
|
||||
Interface string
|
||||
// ProcessUser is the OpenVPN process OS username
|
||||
// to use. It cannot be empty in the internal state.
|
||||
// It defaults to 'root'.
|
||||
ProcessUser string
|
||||
// Root is true if OpenVPN is to be run as root,
|
||||
// and false otherwise. It cannot be nil in the
|
||||
// internal state.
|
||||
Root *bool
|
||||
// ProcUser is the OpenVPN process OS username
|
||||
// to use. It cannot be nil in the internal state.
|
||||
// This is set and injected at runtime.
|
||||
// TODO only use ProcUser and not Root field.
|
||||
ProcUser string
|
||||
// Verbosity is the OpenVPN verbosity level from 0 to 6.
|
||||
// It cannot be nil in the internal state.
|
||||
Verbosity *int
|
||||
@@ -76,44 +78,69 @@ type OpenVPN struct {
|
||||
Flags []string
|
||||
}
|
||||
|
||||
var ivpnAccountID = regexp.MustCompile(`^(i|ivpn)\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}$`)
|
||||
|
||||
func (o OpenVPN) validate(vpnProvider string) (err error) {
|
||||
// Validate version
|
||||
validVersions := []string{openvpn.Openvpn24, openvpn.Openvpn25}
|
||||
validVersions := []string{constants.Openvpn24, constants.Openvpn25}
|
||||
if !helpers.IsOneOf(o.Version, validVersions...) {
|
||||
return fmt.Errorf("%w: %q can only be one of %s",
|
||||
ErrOpenVPNVersionIsNotValid, o.Version, strings.Join(validVersions, ", "))
|
||||
}
|
||||
|
||||
isCustom := vpnProvider == providers.Custom
|
||||
isCustom := vpnProvider == constants.Custom
|
||||
|
||||
if !isCustom && o.User == "" {
|
||||
return ErrOpenVPNUserIsEmpty
|
||||
}
|
||||
|
||||
passwordRequired := !isCustom &&
|
||||
(vpnProvider != providers.Ivpn || !ivpnAccountID.MatchString(o.User))
|
||||
|
||||
if passwordRequired && o.Password == "" {
|
||||
if !isCustom && o.Password == "" {
|
||||
return ErrOpenVPNPasswordIsEmpty
|
||||
}
|
||||
|
||||
err = validateOpenVPNConfigFilepath(isCustom, *o.ConfFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("custom configuration file: %w", err)
|
||||
// Validate ConfFile
|
||||
if isCustom {
|
||||
if *o.ConfFile == "" {
|
||||
return fmt.Errorf("%w: no file path specified", ErrOpenVPNConfigFile)
|
||||
}
|
||||
err := helpers.FileExists(*o.ConfFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrOpenVPNConfigFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = validateOpenVPNClientCertificate(vpnProvider, *o.ClientCrt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("client certificate: %w", err)
|
||||
// Check client certificate
|
||||
switch vpnProvider {
|
||||
case
|
||||
constants.Cyberghost,
|
||||
constants.VPNUnlimited:
|
||||
if *o.ClientCrt == "" {
|
||||
return ErrOpenVPNClientCertMissing
|
||||
}
|
||||
}
|
||||
if *o.ClientCrt != "" {
|
||||
_, err = parse.ExtractCert([]byte(*o.ClientCrt))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrOpenVPNClientCertNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = validateOpenVPNClientKey(vpnProvider, *o.ClientKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("client key: %w", err)
|
||||
// Check client key
|
||||
switch vpnProvider {
|
||||
case
|
||||
constants.Cyberghost,
|
||||
constants.VPNUnlimited,
|
||||
constants.Wevpn:
|
||||
if *o.ClientKey == "" {
|
||||
return ErrOpenVPNClientKeyMissing
|
||||
}
|
||||
}
|
||||
if *o.ClientKey != "" {
|
||||
_, err = parse.ExtractPrivateKey([]byte(*o.ClientKey))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrOpenVPNClientKeyNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Validate MSSFix
|
||||
const maxMSSFix = 10000
|
||||
if *o.MSSFix > maxMSSFix {
|
||||
return fmt.Errorf("%w: %d is over the maximum value of %d",
|
||||
@@ -125,6 +152,7 @@ func (o OpenVPN) validate(vpnProvider string) (err error) {
|
||||
ErrOpenVPNInterfaceNotValid, o.Interface, regexpInterfaceName)
|
||||
}
|
||||
|
||||
// Validate Verbosity
|
||||
if *o.Verbosity < 0 || *o.Verbosity > 6 {
|
||||
return fmt.Errorf("%w: %d can only be between 0 and 5",
|
||||
ErrOpenVPNVerbosityIsOutOfBounds, o.Verbosity)
|
||||
@@ -133,74 +161,6 @@ func (o OpenVPN) validate(vpnProvider string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateOpenVPNConfigFilepath(isCustom bool,
|
||||
confFile string) (err error) {
|
||||
if !isCustom {
|
||||
return nil
|
||||
}
|
||||
|
||||
if confFile == "" {
|
||||
return ErrFilepathMissing
|
||||
}
|
||||
|
||||
err = helpers.FileExists(confFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
extractor := extract.New()
|
||||
_, _, err = extractor.Data(confFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed extracting information from custom configuration file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateOpenVPNClientCertificate(vpnProvider,
|
||||
clientCert string) (err error) {
|
||||
switch vpnProvider {
|
||||
case
|
||||
providers.Cyberghost,
|
||||
providers.VPNUnlimited:
|
||||
if clientCert == "" {
|
||||
return ErrMissingValue
|
||||
}
|
||||
}
|
||||
|
||||
if clientCert == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = extract.PEM([]byte(clientCert))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateOpenVPNClientKey(vpnProvider, clientKey string) (err error) {
|
||||
switch vpnProvider {
|
||||
case
|
||||
providers.Cyberghost,
|
||||
providers.VPNUnlimited,
|
||||
providers.Wevpn:
|
||||
if clientKey == "" {
|
||||
return ErrMissingValue
|
||||
}
|
||||
}
|
||||
|
||||
if clientKey == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = extract.PEM([]byte(clientKey))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *OpenVPN) copy() (copied OpenVPN) {
|
||||
return OpenVPN{
|
||||
Version: o.Version,
|
||||
@@ -215,7 +175,8 @@ func (o *OpenVPN) copy() (copied OpenVPN) {
|
||||
IPv6: helpers.CopyBoolPtr(o.IPv6),
|
||||
MSSFix: helpers.CopyUint16Ptr(o.MSSFix),
|
||||
Interface: o.Interface,
|
||||
ProcessUser: o.ProcessUser,
|
||||
Root: helpers.CopyBoolPtr(o.Root),
|
||||
ProcUser: o.ProcUser,
|
||||
Verbosity: helpers.CopyIntPtr(o.Verbosity),
|
||||
Flags: helpers.CopyStringSlice(o.Flags),
|
||||
}
|
||||
@@ -236,8 +197,9 @@ func (o *OpenVPN) mergeWith(other OpenVPN) {
|
||||
o.IPv6 = helpers.MergeWithBool(o.IPv6, other.IPv6)
|
||||
o.MSSFix = helpers.MergeWithUint16(o.MSSFix, other.MSSFix)
|
||||
o.Interface = helpers.MergeWithString(o.Interface, other.Interface)
|
||||
o.ProcessUser = helpers.MergeWithString(o.ProcessUser, other.ProcessUser)
|
||||
o.Verbosity = helpers.MergeWithIntPtr(o.Verbosity, other.Verbosity)
|
||||
o.Root = helpers.MergeWithBool(o.Root, other.Root)
|
||||
o.ProcUser = helpers.MergeWithString(o.ProcUser, other.ProcUser)
|
||||
o.Verbosity = helpers.MergeWithInt(o.Verbosity, other.Verbosity)
|
||||
o.Flags = helpers.MergeStringSlices(o.Flags, other.Flags)
|
||||
}
|
||||
|
||||
@@ -257,14 +219,15 @@ func (o *OpenVPN) overrideWith(other OpenVPN) {
|
||||
o.IPv6 = helpers.OverrideWithBool(o.IPv6, other.IPv6)
|
||||
o.MSSFix = helpers.OverrideWithUint16(o.MSSFix, other.MSSFix)
|
||||
o.Interface = helpers.OverrideWithString(o.Interface, other.Interface)
|
||||
o.ProcessUser = helpers.OverrideWithString(o.ProcessUser, other.ProcessUser)
|
||||
o.Verbosity = helpers.OverrideWithIntPtr(o.Verbosity, other.Verbosity)
|
||||
o.Root = helpers.OverrideWithBool(o.Root, other.Root)
|
||||
o.ProcUser = helpers.OverrideWithString(o.ProcUser, other.ProcUser)
|
||||
o.Verbosity = helpers.OverrideWithInt(o.Verbosity, other.Verbosity)
|
||||
o.Flags = helpers.OverrideWithStringSlice(o.Flags, other.Flags)
|
||||
}
|
||||
|
||||
func (o *OpenVPN) setDefaults(vpnProvider string) {
|
||||
o.Version = helpers.DefaultString(o.Version, openvpn.Openvpn25)
|
||||
if vpnProvider == providers.Mullvad {
|
||||
o.Version = helpers.DefaultString(o.Version, constants.Openvpn25)
|
||||
if vpnProvider == constants.Mullvad {
|
||||
o.Password = "m"
|
||||
}
|
||||
|
||||
@@ -274,15 +237,16 @@ func (o *OpenVPN) setDefaults(vpnProvider string) {
|
||||
o.ClientKey = helpers.DefaultStringPtr(o.ClientKey, "")
|
||||
|
||||
var defaultEncPreset string
|
||||
if vpnProvider == providers.PrivateInternetAccess {
|
||||
defaultEncPreset = presets.Strong
|
||||
if vpnProvider == constants.PrivateInternetAccess {
|
||||
defaultEncPreset = constants.PIAEncryptionPresetStrong
|
||||
}
|
||||
o.PIAEncPreset = helpers.DefaultStringPtr(o.PIAEncPreset, defaultEncPreset)
|
||||
|
||||
o.IPv6 = helpers.DefaultBool(o.IPv6, false)
|
||||
o.MSSFix = helpers.DefaultUint16(o.MSSFix, 0)
|
||||
o.Interface = helpers.DefaultString(o.Interface, "tun0")
|
||||
o.ProcessUser = helpers.DefaultString(o.ProcessUser, "root")
|
||||
o.Root = helpers.DefaultBool(o.Root, true)
|
||||
o.ProcUser = helpers.DefaultString(o.ProcUser, "root")
|
||||
o.Verbosity = helpers.DefaultInt(o.Verbosity, 1)
|
||||
}
|
||||
|
||||
@@ -330,7 +294,14 @@ func (o OpenVPN) toLinesNode() (node *gotree.Node) {
|
||||
node.Appendf("Network interface: %s", o.Interface)
|
||||
}
|
||||
|
||||
node.Appendf("Run OpenVPN as: %s", o.ProcessUser)
|
||||
processUser := "root"
|
||||
if !*o.Root {
|
||||
processUser = "some non root user" // TODO
|
||||
if o.ProcUser != "" {
|
||||
processUser = o.ProcUser
|
||||
}
|
||||
}
|
||||
node.Appendf("Run OpenVPN as: %s", processUser)
|
||||
|
||||
node.Appendf("Verbosity level: %d", *o.Verbosity)
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_ivpnAccountID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
s string
|
||||
match bool
|
||||
}{
|
||||
{},
|
||||
{s: "abc"},
|
||||
{s: "i"},
|
||||
{s: "ivpn"},
|
||||
{s: "ivpn-aaaa"},
|
||||
{s: "ivpn-aaaa-aaaa"},
|
||||
{s: "ivpn-aaaa-aaaa-aaa"},
|
||||
{s: "ivpn-aaaa-aaaa-aaaa", match: true},
|
||||
{s: "ivpn-aaaa-aaaa-aaaaa"},
|
||||
{s: "ivpn-a6B7-fP91-Zh6Y", match: true},
|
||||
{s: "i-aaaa"},
|
||||
{s: "i-aaaa-aaaa"},
|
||||
{s: "i-aaaa-aaaa-aaa"},
|
||||
{s: "i-aaaa-aaaa-aaaa", match: true},
|
||||
{s: "i-aaaa-aaaa-aaaaa"},
|
||||
{s: "i-a6B7-fP91-Zh6Y", match: true},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.s, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
match := ivpnAccountID.MatchString(testCase.s)
|
||||
|
||||
assert.Equal(t, testCase.match, match)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/presets"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -34,17 +33,15 @@ func (o OpenVPNSelection) validate(vpnProvider string) (err error) {
|
||||
if confFile := *o.ConfFile; confFile != "" {
|
||||
err := helpers.FileExists(confFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("configuration file: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrOpenVPNConfigFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Validate TCP
|
||||
if *o.TCP && helpers.IsOneOf(vpnProvider,
|
||||
providers.Ipvanish,
|
||||
providers.Perfectprivacy,
|
||||
providers.Privado,
|
||||
providers.VPNUnlimited,
|
||||
providers.Vyprvpn,
|
||||
constants.Perfectprivacy,
|
||||
constants.Privado,
|
||||
constants.Vyprvpn,
|
||||
) {
|
||||
return fmt.Errorf("%w: for VPN service provider %s",
|
||||
ErrOpenVPNTCPNotSupported, vpnProvider)
|
||||
@@ -54,38 +51,33 @@ func (o OpenVPNSelection) validate(vpnProvider string) (err error) {
|
||||
if *o.CustomPort != 0 {
|
||||
switch vpnProvider {
|
||||
// no restriction on port
|
||||
case providers.Cyberghost, providers.HideMyAss,
|
||||
providers.Privatevpn, providers.Torguard:
|
||||
case constants.Cyberghost, constants.HideMyAss,
|
||||
constants.PrivateInternetAccess, constants.Privatevpn,
|
||||
constants.Protonvpn, constants.Torguard:
|
||||
// no custom port allowed
|
||||
case providers.Expressvpn, providers.Fastestvpn,
|
||||
providers.Ipvanish, providers.Nordvpn,
|
||||
providers.Privado, providers.Purevpn,
|
||||
providers.Surfshark, providers.VPNUnlimited,
|
||||
providers.Vyprvpn:
|
||||
case constants.Expressvpn, constants.Fastestvpn,
|
||||
constants.Ipvanish, constants.Nordvpn,
|
||||
constants.Privado, constants.Purevpn,
|
||||
constants.Surfshark, constants.VPNUnlimited,
|
||||
constants.Vyprvpn:
|
||||
return fmt.Errorf("%w: for VPN service provider %s",
|
||||
ErrOpenVPNCustomPortNotAllowed, vpnProvider)
|
||||
default:
|
||||
var allowedTCP, allowedUDP []uint16
|
||||
switch vpnProvider {
|
||||
case providers.Ivpn:
|
||||
case constants.Ivpn:
|
||||
allowedTCP = []uint16{80, 443, 1143}
|
||||
allowedUDP = []uint16{53, 1194, 2049, 2050}
|
||||
case providers.Mullvad:
|
||||
case constants.Mullvad:
|
||||
allowedTCP = []uint16{80, 443, 1401}
|
||||
allowedUDP = []uint16{53, 1194, 1195, 1196, 1197, 1300, 1301, 1302, 1303, 1400}
|
||||
case providers.Perfectprivacy:
|
||||
case constants.Perfectprivacy:
|
||||
allowedTCP = []uint16{44, 443, 4433}
|
||||
allowedUDP = []uint16{44, 443, 4433}
|
||||
case providers.PrivateInternetAccess:
|
||||
allowedTCP = []uint16{80, 110, 443}
|
||||
allowedUDP = []uint16{53, 1194, 1197, 1198, 8080, 9201}
|
||||
case providers.Protonvpn:
|
||||
allowedTCP = []uint16{443, 5995, 8443}
|
||||
allowedUDP = []uint16{80, 443, 1194, 4569, 5060}
|
||||
case providers.Wevpn:
|
||||
case constants.Wevpn:
|
||||
allowedTCP = []uint16{53, 1195, 1199, 2018}
|
||||
allowedUDP = []uint16{80, 1194, 1198}
|
||||
case providers.Windscribe:
|
||||
case constants.Windscribe:
|
||||
allowedTCP = []uint16{21, 22, 80, 123, 143, 443, 587, 1194, 3306, 8080, 54783}
|
||||
allowedUDP = []uint16{53, 80, 123, 443, 1194, 54783}
|
||||
}
|
||||
@@ -103,11 +95,11 @@ func (o OpenVPNSelection) validate(vpnProvider string) (err error) {
|
||||
}
|
||||
|
||||
// Validate EncPreset
|
||||
if vpnProvider == providers.PrivateInternetAccess {
|
||||
if vpnProvider == constants.PrivateInternetAccess {
|
||||
validEncryptionPresets := []string{
|
||||
presets.None,
|
||||
presets.Normal,
|
||||
presets.Strong,
|
||||
constants.PIAEncryptionPresetNone,
|
||||
constants.PIAEncryptionPresetNormal,
|
||||
constants.PIAEncryptionPresetStrong,
|
||||
}
|
||||
if !helpers.IsOneOf(*o.PIAEncPreset, validEncryptionPresets...) {
|
||||
return fmt.Errorf("%w: %s; valid presets are %s",
|
||||
@@ -148,8 +140,8 @@ func (o *OpenVPNSelection) setDefaults(vpnProvider string) {
|
||||
o.CustomPort = helpers.DefaultUint16(o.CustomPort, 0)
|
||||
|
||||
var defaultEncPreset string
|
||||
if vpnProvider == providers.PrivateInternetAccess {
|
||||
defaultEncPreset = presets.Strong
|
||||
if vpnProvider == constants.PrivateInternetAccess {
|
||||
defaultEncPreset = constants.PIAEncryptionPresetStrong
|
||||
}
|
||||
o.PIAEncPreset = helpers.DefaultStringPtr(o.PIAEncPreset, defaultEncPreset)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func (p PortForwarding) validate(vpnProvider string) (err error) {
|
||||
}
|
||||
|
||||
// Validate Enabled
|
||||
validProviders := []string{providers.PrivateInternetAccess}
|
||||
validProviders := []string{constants.PrivateInternetAccess}
|
||||
if !helpers.IsOneOf(vpnProvider, validProviders...) {
|
||||
return fmt.Errorf("%w: for provider %s, it is only available for %s",
|
||||
ErrPortForwardingEnabled, vpnProvider, strings.Join(validProviders, ", "))
|
||||
@@ -38,7 +38,7 @@ func (p PortForwarding) validate(vpnProvider string) (err error) {
|
||||
if *p.Filepath != "" { // optional
|
||||
_, err := filepath.Abs(*p.Filepath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("filepath is not valid: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrPortForwardingFilepathNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -22,18 +22,18 @@ type Provider struct {
|
||||
}
|
||||
|
||||
// TODO v4 remove pointer for receiver (because of Surfshark).
|
||||
func (p *Provider) validate(vpnType string, storage Storage) (err error) {
|
||||
func (p *Provider) validate(vpnType string, allServers models.AllServers) (err error) {
|
||||
// Validate Name
|
||||
var validNames []string
|
||||
if vpnType == vpn.OpenVPN {
|
||||
validNames = providers.AllWithCustom()
|
||||
if vpnType == constants.OpenVPN {
|
||||
validNames = constants.AllProviders()
|
||||
validNames = append(validNames, "pia") // Retro-compatibility
|
||||
} else { // Wireguard
|
||||
validNames = []string{
|
||||
providers.Custom,
|
||||
providers.Ivpn,
|
||||
providers.Mullvad,
|
||||
providers.Windscribe,
|
||||
constants.Custom,
|
||||
constants.Ivpn,
|
||||
constants.Mullvad,
|
||||
constants.Windscribe,
|
||||
}
|
||||
}
|
||||
if !helpers.IsOneOf(*p.Name, validNames...) {
|
||||
@@ -41,14 +41,14 @@ func (p *Provider) validate(vpnType string, storage Storage) (err error) {
|
||||
ErrVPNProviderNameNotValid, *p.Name, helpers.ChoicesOrString(validNames))
|
||||
}
|
||||
|
||||
err = p.ServerSelection.validate(*p.Name, storage)
|
||||
err = p.ServerSelection.validate(*p.Name, allServers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("server selection: %w", err)
|
||||
return fmt.Errorf("server selection settings validation failed: %w", err)
|
||||
}
|
||||
|
||||
err = p.PortForwarding.validate(*p.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("port forwarding: %w", err)
|
||||
return fmt.Errorf("port forwarding settings validation failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -75,7 +75,7 @@ func (p *Provider) overrideWith(other Provider) {
|
||||
}
|
||||
|
||||
func (p *Provider) setDefaults() {
|
||||
p.Name = helpers.DefaultStringPtr(p.Name, providers.PrivateInternetAccess)
|
||||
p.Name = helpers.DefaultStringPtr(p.Name, constants.PrivateInternetAccess)
|
||||
p.ServerSelection.setDefaults(*p.Name)
|
||||
p.PortForwarding.setDefaults()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (p PublicIP) validate() (err error) {
|
||||
if *p.IPFilepath != "" { // optional
|
||||
_, err := filepath.Abs(*p.IPFilepath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("filepath is not valid: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrPublicIPFilepathNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@ package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gotree"
|
||||
@@ -12,30 +10,22 @@ import (
|
||||
|
||||
// ControlServer contains settings to customize the control server operation.
|
||||
type ControlServer struct {
|
||||
// Address is the listening address to use.
|
||||
// Port is the listening port to use.
|
||||
// It can be set to 0 to bind to a random port.
|
||||
// It cannot be nil in the internal state.
|
||||
Address *string
|
||||
// TODO change to address
|
||||
Port *uint16
|
||||
// Log can be true or false to enable logging on requests.
|
||||
// It cannot be nil in the internal state.
|
||||
Log *bool
|
||||
}
|
||||
|
||||
func (c ControlServer) validate() (err error) {
|
||||
_, portStr, err := net.SplitHostPort(*c.Address)
|
||||
if err != nil {
|
||||
return fmt.Errorf("listening address is not valid: %w", err)
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(portStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("listening port it not valid: %w", err)
|
||||
}
|
||||
|
||||
uid := os.Getuid()
|
||||
const maxPrivilegedPort = 1023
|
||||
if uid != 0 && port != 0 && port <= maxPrivilegedPort {
|
||||
const maxPrivilegedPort uint16 = 1023
|
||||
if uid != 0 && *c.Port <= maxPrivilegedPort {
|
||||
return fmt.Errorf("%w: %d when running with user ID %d",
|
||||
ErrControlServerPrivilegedPort, port, uid)
|
||||
ErrControlServerPrivilegedPort, *c.Port, uid)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -43,15 +33,15 @@ func (c ControlServer) validate() (err error) {
|
||||
|
||||
func (c *ControlServer) copy() (copied ControlServer) {
|
||||
return ControlServer{
|
||||
Address: helpers.CopyStringPtr(c.Address),
|
||||
Log: helpers.CopyBoolPtr(c.Log),
|
||||
Port: helpers.CopyUint16Ptr(c.Port),
|
||||
Log: helpers.CopyBoolPtr(c.Log),
|
||||
}
|
||||
}
|
||||
|
||||
// mergeWith merges the other settings into any
|
||||
// unset field of the receiver settings object.
|
||||
func (c *ControlServer) mergeWith(other ControlServer) {
|
||||
c.Address = helpers.MergeWithStringPtr(c.Address, other.Address)
|
||||
c.Port = helpers.MergeWithUint16(c.Port, other.Port)
|
||||
c.Log = helpers.MergeWithBool(c.Log, other.Log)
|
||||
}
|
||||
|
||||
@@ -59,12 +49,13 @@ func (c *ControlServer) mergeWith(other ControlServer) {
|
||||
// settings object with any field set in the other
|
||||
// settings.
|
||||
func (c *ControlServer) overrideWith(other ControlServer) {
|
||||
c.Address = helpers.OverrideWithStringPtr(c.Address, other.Address)
|
||||
c.Log = helpers.OverrideWithBool(c.Log, other.Log)
|
||||
c.Port = helpers.MergeWithUint16(c.Port, other.Port)
|
||||
c.Log = helpers.MergeWithBool(c.Log, other.Log)
|
||||
}
|
||||
|
||||
func (c *ControlServer) setDefaults() {
|
||||
c.Address = helpers.DefaultStringPtr(c.Address, ":8000")
|
||||
const defaultPort = 8000
|
||||
c.Port = helpers.DefaultUint16(c.Port, defaultPort)
|
||||
c.Log = helpers.DefaultBool(c.Log, true)
|
||||
}
|
||||
|
||||
@@ -74,7 +65,7 @@ func (c ControlServer) String() string {
|
||||
|
||||
func (c ControlServer) toLinesNode() (node *gotree.Node) {
|
||||
node = gotree.New("Control server settings:")
|
||||
node.Appendf("Listening address: %s", *c.Address)
|
||||
node.Appendf("Listening port: %d", *c.Port)
|
||||
node.Appendf("Logging: %s", helpers.BoolPtrToYesNo(c.Log))
|
||||
return node
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/validation"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
@@ -39,16 +36,16 @@ type ServerSelection struct { //nolint:maligned
|
||||
Numbers []uint16
|
||||
// Hostnames is the list of hostnames to filter VPN servers with.
|
||||
Hostnames []string
|
||||
// OwnedOnly is true if VPN provider servers that are not owned
|
||||
// OwnedOnly is true if only VPN provider owned servers
|
||||
// should be filtered. This is used with Mullvad.
|
||||
OwnedOnly *bool
|
||||
// FreeOnly is true if VPN servers that are not free should
|
||||
// be filtered. This is used with ProtonVPN and VPN Unlimited.
|
||||
// FreeOnly is true if only free VPN servers
|
||||
// should be filtered. This is used with ProtonVPN.
|
||||
FreeOnly *bool
|
||||
// StreamOnly is true if VPN servers not for streaming should
|
||||
// be filtered. This is used with VPNUnlimited.
|
||||
// FreeOnly is true if only free VPN servers
|
||||
// should be filtered. This is used with ProtonVPN.
|
||||
StreamOnly *bool
|
||||
// MultiHopOnly is true if VPN servers that are not multihop
|
||||
// MultiHopOnly is true if only multihop VPN servers
|
||||
// should be filtered. This is used with Surfshark.
|
||||
MultiHopOnly *bool
|
||||
|
||||
@@ -60,122 +57,190 @@ type ServerSelection struct { //nolint:maligned
|
||||
Wireguard WireguardSelection
|
||||
}
|
||||
|
||||
var (
|
||||
ErrOwnedOnlyNotSupported = errors.New("owned only filter is not supported")
|
||||
ErrFreeOnlyNotSupported = errors.New("free only filter is not supported")
|
||||
ErrStreamOnlyNotSupported = errors.New("stream only filter is not supported")
|
||||
ErrMultiHopOnlyNotSupported = errors.New("multi hop only filter is not supported")
|
||||
)
|
||||
|
||||
func (ss *ServerSelection) validate(vpnServiceProvider string,
|
||||
storage Storage) (err error) {
|
||||
allServers models.AllServers) (err error) {
|
||||
switch ss.VPN {
|
||||
case vpn.OpenVPN, vpn.Wireguard:
|
||||
case constants.OpenVPN, constants.Wireguard:
|
||||
default:
|
||||
return fmt.Errorf("%w: %s", ErrVPNTypeNotValid, ss.VPN)
|
||||
}
|
||||
|
||||
filterChoices, err := getLocationFilterChoices(vpnServiceProvider, ss, storage)
|
||||
if err != nil {
|
||||
return err // already wrapped error
|
||||
}
|
||||
|
||||
err = validateServerFilters(*ss, filterChoices)
|
||||
if err != nil {
|
||||
if errors.Is(err, helpers.ErrNoChoice) {
|
||||
return fmt.Errorf("for VPN service provider %s: %w", vpnServiceProvider, err)
|
||||
var countryChoices, regionChoices, cityChoices,
|
||||
ispChoices, nameChoices, hostnameChoices []string
|
||||
switch vpnServiceProvider {
|
||||
case constants.Custom:
|
||||
case constants.Cyberghost:
|
||||
servers := allServers.GetCyberghost()
|
||||
countryChoices = constants.CyberghostCountryChoices(servers)
|
||||
hostnameChoices = constants.CyberghostHostnameChoices(servers)
|
||||
case constants.Expressvpn:
|
||||
servers := allServers.GetExpressvpn()
|
||||
countryChoices = constants.ExpressvpnCountriesChoices(servers)
|
||||
cityChoices = constants.ExpressvpnCityChoices(servers)
|
||||
hostnameChoices = constants.ExpressvpnHostnameChoices(servers)
|
||||
case constants.Fastestvpn:
|
||||
servers := allServers.GetFastestvpn()
|
||||
countryChoices = constants.FastestvpnCountriesChoices(servers)
|
||||
hostnameChoices = constants.FastestvpnHostnameChoices(servers)
|
||||
case constants.HideMyAss:
|
||||
servers := allServers.GetHideMyAss()
|
||||
countryChoices = constants.HideMyAssCountryChoices(servers)
|
||||
regionChoices = constants.HideMyAssRegionChoices(servers)
|
||||
cityChoices = constants.HideMyAssCityChoices(servers)
|
||||
hostnameChoices = constants.HideMyAssHostnameChoices(servers)
|
||||
case constants.Ipvanish:
|
||||
servers := allServers.GetIpvanish()
|
||||
countryChoices = constants.IpvanishCountryChoices(servers)
|
||||
cityChoices = constants.IpvanishCityChoices(servers)
|
||||
hostnameChoices = constants.IpvanishHostnameChoices(servers)
|
||||
case constants.Ivpn:
|
||||
servers := allServers.GetIvpn()
|
||||
countryChoices = constants.IvpnCountryChoices(servers)
|
||||
cityChoices = constants.IvpnCityChoices(servers)
|
||||
ispChoices = constants.IvpnISPChoices(servers)
|
||||
hostnameChoices = constants.IvpnHostnameChoices(servers)
|
||||
case constants.Mullvad:
|
||||
servers := allServers.GetMullvad()
|
||||
countryChoices = constants.MullvadCountryChoices(servers)
|
||||
cityChoices = constants.MullvadCityChoices(servers)
|
||||
ispChoices = constants.MullvadISPChoices(servers)
|
||||
hostnameChoices = constants.MullvadHostnameChoices(servers)
|
||||
case constants.Nordvpn:
|
||||
servers := allServers.GetNordvpn()
|
||||
regionChoices = constants.NordvpnRegionChoices(servers)
|
||||
hostnameChoices = constants.NordvpnHostnameChoices(servers)
|
||||
case constants.Perfectprivacy:
|
||||
servers := allServers.GetPerfectprivacy()
|
||||
cityChoices = constants.PerfectprivacyCityChoices(servers)
|
||||
case constants.Privado:
|
||||
servers := allServers.GetPrivado()
|
||||
countryChoices = constants.PrivadoCountryChoices(servers)
|
||||
regionChoices = constants.PrivadoRegionChoices(servers)
|
||||
cityChoices = constants.PrivadoCityChoices(servers)
|
||||
hostnameChoices = constants.PrivadoHostnameChoices(servers)
|
||||
case constants.PrivateInternetAccess:
|
||||
servers := allServers.GetPia()
|
||||
regionChoices = constants.PIAGeoChoices(servers)
|
||||
hostnameChoices = constants.PIAHostnameChoices(servers)
|
||||
nameChoices = constants.PIANameChoices(servers)
|
||||
case constants.Privatevpn:
|
||||
servers := allServers.GetPrivatevpn()
|
||||
countryChoices = constants.PrivatevpnCountryChoices(servers)
|
||||
cityChoices = constants.PrivatevpnCityChoices(servers)
|
||||
hostnameChoices = constants.PrivatevpnHostnameChoices(servers)
|
||||
case constants.Protonvpn:
|
||||
servers := allServers.GetProtonvpn()
|
||||
countryChoices = constants.ProtonvpnCountryChoices(servers)
|
||||
regionChoices = constants.ProtonvpnRegionChoices(servers)
|
||||
cityChoices = constants.ProtonvpnCityChoices(servers)
|
||||
nameChoices = constants.ProtonvpnNameChoices(servers)
|
||||
hostnameChoices = constants.ProtonvpnHostnameChoices(servers)
|
||||
case constants.Purevpn:
|
||||
servers := allServers.GetPurevpn()
|
||||
countryChoices = constants.PurevpnCountryChoices(servers)
|
||||
regionChoices = constants.PurevpnRegionChoices(servers)
|
||||
cityChoices = constants.PurevpnCityChoices(servers)
|
||||
hostnameChoices = constants.PurevpnHostnameChoices(servers)
|
||||
case constants.Surfshark:
|
||||
servers := allServers.GetSurfshark()
|
||||
countryChoices = constants.SurfsharkCountryChoices(servers)
|
||||
cityChoices = constants.SurfsharkCityChoices(servers)
|
||||
hostnameChoices = constants.SurfsharkHostnameChoices(servers)
|
||||
regionChoices = constants.SurfsharkRegionChoices(servers)
|
||||
// TODO v4 remove
|
||||
regionChoices = append(regionChoices, constants.SurfsharkRetroLocChoices(servers)...)
|
||||
if err := helpers.AreAllOneOf(ss.Regions, regionChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
||||
}
|
||||
// Retro compatibility
|
||||
// TODO remove in v4
|
||||
*ss = surfsharkRetroRegion(*ss)
|
||||
case constants.Torguard:
|
||||
servers := allServers.GetTorguard()
|
||||
countryChoices = constants.TorguardCountryChoices(servers)
|
||||
cityChoices = constants.TorguardCityChoices(servers)
|
||||
hostnameChoices = constants.TorguardHostnameChoices(servers)
|
||||
case constants.VPNUnlimited:
|
||||
servers := allServers.GetVPNUnlimited()
|
||||
countryChoices = constants.VPNUnlimitedCountryChoices(servers)
|
||||
cityChoices = constants.VPNUnlimitedCityChoices(servers)
|
||||
hostnameChoices = constants.VPNUnlimitedHostnameChoices(servers)
|
||||
case constants.Vyprvpn:
|
||||
servers := allServers.GetVyprvpn()
|
||||
regionChoices = constants.VyprvpnRegionChoices(servers)
|
||||
case constants.Wevpn:
|
||||
servers := allServers.GetWevpn()
|
||||
cityChoices = constants.WevpnCityChoices(servers)
|
||||
hostnameChoices = constants.WevpnHostnameChoices(servers)
|
||||
case constants.Windscribe:
|
||||
servers := allServers.GetWindscribe()
|
||||
regionChoices = constants.WindscribeRegionChoices(servers)
|
||||
cityChoices = constants.WindscribeCityChoices(servers)
|
||||
hostnameChoices = constants.WindscribeHostnameChoices(servers)
|
||||
default:
|
||||
return fmt.Errorf("%w: %s", ErrVPNProviderNameNotValid, vpnServiceProvider)
|
||||
}
|
||||
|
||||
err = validateServerFilters(*ss, countryChoices, regionChoices, cityChoices,
|
||||
ispChoices, nameChoices, hostnameChoices)
|
||||
if err != nil {
|
||||
return err // already wrapped error
|
||||
}
|
||||
|
||||
if *ss.OwnedOnly &&
|
||||
vpnServiceProvider != providers.Mullvad {
|
||||
return fmt.Errorf("%w: for VPN service provider %s",
|
||||
ErrOwnedOnlyNotSupported, vpnServiceProvider)
|
||||
}
|
||||
|
||||
if *ss.FreeOnly &&
|
||||
!helpers.IsOneOf(vpnServiceProvider,
|
||||
providers.Protonvpn,
|
||||
providers.VPNUnlimited,
|
||||
) {
|
||||
return fmt.Errorf("%w: for VPN service provider %s",
|
||||
ErrFreeOnlyNotSupported, vpnServiceProvider)
|
||||
}
|
||||
|
||||
if *ss.StreamOnly &&
|
||||
!helpers.IsOneOf(vpnServiceProvider,
|
||||
providers.Protonvpn,
|
||||
providers.VPNUnlimited,
|
||||
) {
|
||||
return fmt.Errorf("%w: for VPN service provider %s",
|
||||
ErrStreamOnlyNotSupported, vpnServiceProvider)
|
||||
}
|
||||
|
||||
if *ss.MultiHopOnly &&
|
||||
vpnServiceProvider != providers.Surfshark {
|
||||
return fmt.Errorf("%w: for VPN service provider %s",
|
||||
ErrMultiHopOnlyNotSupported, vpnServiceProvider)
|
||||
}
|
||||
|
||||
if ss.VPN == vpn.OpenVPN {
|
||||
if ss.VPN == constants.OpenVPN {
|
||||
err = ss.OpenVPN.validate(vpnServiceProvider)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenVPN server selection settings: %w", err)
|
||||
return fmt.Errorf("OpenVPN server selection settings validation failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
err = ss.Wireguard.validate(vpnServiceProvider)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Wireguard server selection settings: %w", err)
|
||||
return fmt.Errorf("Wireguard server selection settings validation failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLocationFilterChoices(vpnServiceProvider string,
|
||||
ss *ServerSelection, storage Storage) (filterChoices models.FilterChoices,
|
||||
err error) {
|
||||
filterChoices = storage.GetFilterChoices(vpnServiceProvider)
|
||||
|
||||
if vpnServiceProvider == providers.Surfshark {
|
||||
// // Retro compatibility
|
||||
// TODO v4 remove
|
||||
filterChoices.Regions = append(filterChoices.Regions, validation.SurfsharkRetroLocChoices()...)
|
||||
if err := helpers.AreAllOneOf(ss.Regions, filterChoices.Regions); err != nil {
|
||||
return models.FilterChoices{}, fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
||||
}
|
||||
*ss = surfsharkRetroRegion(*ss)
|
||||
}
|
||||
|
||||
return filterChoices, nil
|
||||
}
|
||||
|
||||
// validateServerFilters validates filters against the choices given as arguments.
|
||||
// Set an argument to nil to pass the check for a particular filter.
|
||||
func validateServerFilters(settings ServerSelection, filterChoices models.FilterChoices) (err error) {
|
||||
if err := helpers.AreAllOneOf(settings.Countries, filterChoices.Countries); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrCountryNotValid, err)
|
||||
func validateServerFilters(settings ServerSelection,
|
||||
countryChoices, regionChoices, cityChoices, ispChoices,
|
||||
nameChoices, hostnameChoices []string) (err error) {
|
||||
if countryChoices != nil {
|
||||
if err := helpers.AreAllOneOf(settings.Countries, countryChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrCountryNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := helpers.AreAllOneOf(settings.Regions, filterChoices.Regions); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
||||
if regionChoices != nil {
|
||||
if err := helpers.AreAllOneOf(settings.Regions, regionChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := helpers.AreAllOneOf(settings.Cities, filterChoices.Cities); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrCityNotValid, err)
|
||||
if cityChoices != nil {
|
||||
if err := helpers.AreAllOneOf(settings.Cities, cityChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrCityNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := helpers.AreAllOneOf(settings.ISPs, filterChoices.ISPs); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrISPNotValid, err)
|
||||
if ispChoices != nil {
|
||||
if err := helpers.AreAllOneOf(settings.ISPs, ispChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrISPNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := helpers.AreAllOneOf(settings.Hostnames, filterChoices.Hostnames); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrHostnameNotValid, err)
|
||||
if hostnameChoices != nil {
|
||||
if err := helpers.AreAllOneOf(settings.Hostnames, hostnameChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrHostnameNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := helpers.AreAllOneOf(settings.Names, filterChoices.Names); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrNameNotValid, err)
|
||||
if nameChoices != nil {
|
||||
if err := helpers.AreAllOneOf(settings.Names, nameChoices); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrNameNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -239,7 +304,7 @@ func (ss *ServerSelection) overrideWith(other ServerSelection) {
|
||||
}
|
||||
|
||||
func (ss *ServerSelection) setDefaults(vpnProvider string) {
|
||||
ss.VPN = helpers.DefaultString(ss.VPN, vpn.OpenVPN)
|
||||
ss.VPN = helpers.DefaultString(ss.VPN, constants.OpenVPN)
|
||||
ss.TargetIP = helpers.DefaultIP(ss.TargetIP, net.IP{})
|
||||
ss.OwnedOnly = helpers.DefaultBool(ss.OwnedOnly, false)
|
||||
ss.FreeOnly = helpers.DefaultBool(ss.FreeOnly, false)
|
||||
@@ -307,7 +372,7 @@ func (ss ServerSelection) toLinesNode() (node *gotree.Node) {
|
||||
node.Appendf("Multi-hop only servers: yes")
|
||||
}
|
||||
|
||||
if ss.VPN == vpn.OpenVPN {
|
||||
if ss.VPN == constants.OpenVPN {
|
||||
node.AppendNode(ss.OpenVPN.toLinesNode())
|
||||
} else {
|
||||
node.AppendNode(ss.Wireguard.toLinesNode())
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/pprof"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -21,17 +20,12 @@ type Settings struct {
|
||||
Updater Updater
|
||||
Version Version
|
||||
VPN VPN
|
||||
Pprof pprof.Settings
|
||||
}
|
||||
|
||||
type Storage interface {
|
||||
GetFilterChoices(provider string) models.FilterChoices
|
||||
}
|
||||
|
||||
// Validate validates all the settings and returns an error
|
||||
// if one of them is not valid.
|
||||
// TODO v4 remove pointer for receiver (because of Surfshark).
|
||||
func (s *Settings) Validate(storage Storage) (err error) {
|
||||
func (s *Settings) Validate(allServers models.AllServers) (err error) {
|
||||
nameToValidation := map[string]func() error{
|
||||
"control server": s.ControlServer.validate,
|
||||
"dns": s.DNS.validate,
|
||||
@@ -44,16 +38,15 @@ func (s *Settings) Validate(storage Storage) (err error) {
|
||||
"system": s.System.validate,
|
||||
"updater": s.Updater.Validate,
|
||||
"version": s.Version.validate,
|
||||
// Pprof validation done in pprof constructor
|
||||
"VPN": func() error {
|
||||
return s.VPN.validate(storage)
|
||||
return s.VPN.validate(allServers)
|
||||
},
|
||||
}
|
||||
|
||||
for name, validation := range nameToValidation {
|
||||
err = validation()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s settings: %w", name, err)
|
||||
return fmt.Errorf("failed validating %s settings: %w", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +67,6 @@ func (s *Settings) copy() (copied Settings) {
|
||||
Updater: s.Updater.copy(),
|
||||
Version: s.Version.copy(),
|
||||
VPN: s.VPN.copy(),
|
||||
Pprof: s.Pprof.Copy(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,11 +83,10 @@ func (s *Settings) MergeWith(other Settings) {
|
||||
s.Updater.mergeWith(other.Updater)
|
||||
s.Version.mergeWith(other.Version)
|
||||
s.VPN.mergeWith(other.VPN)
|
||||
s.Pprof.MergeWith(other.Pprof)
|
||||
}
|
||||
|
||||
func (s *Settings) OverrideWith(other Settings,
|
||||
storage Storage) (err error) {
|
||||
allServers models.AllServers) (err error) {
|
||||
patchedSettings := s.copy()
|
||||
patchedSettings.ControlServer.overrideWith(other.ControlServer)
|
||||
patchedSettings.DNS.overrideWith(other.DNS)
|
||||
@@ -109,8 +100,7 @@ func (s *Settings) OverrideWith(other Settings,
|
||||
patchedSettings.Updater.overrideWith(other.Updater)
|
||||
patchedSettings.Version.overrideWith(other.Version)
|
||||
patchedSettings.VPN.overrideWith(other.VPN)
|
||||
patchedSettings.Pprof.OverrideWith(other.Pprof)
|
||||
err = patchedSettings.Validate(storage)
|
||||
err = patchedSettings.Validate(allServers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -128,10 +118,9 @@ func (s *Settings) SetDefaults() {
|
||||
s.PublicIP.setDefaults()
|
||||
s.Shadowsocks.setDefaults()
|
||||
s.System.setDefaults()
|
||||
s.Updater.SetDefaults()
|
||||
s.Version.setDefaults()
|
||||
s.VPN.setDefaults()
|
||||
s.Updater.SetDefaults(*s.VPN.Provider.Name)
|
||||
s.Pprof.SetDefaults()
|
||||
}
|
||||
|
||||
func (s Settings) String() string {
|
||||
@@ -153,7 +142,6 @@ func (s Settings) toLinesNode() (node *gotree.Node) {
|
||||
node.AppendNode(s.PublicIP.toLinesNode())
|
||||
node.AppendNode(s.Updater.toLinesNode())
|
||||
node.AppendNode(s.Version.toLinesNode())
|
||||
node.AppendNode(s.Pprof.ToLinesNode())
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func Test_Settings_String(t *testing.T) {
|
||||
| └── Log level: INFO
|
||||
├── Health settings:
|
||||
| ├── Server listening address: 127.0.0.1:9999
|
||||
| ├── Target address: cloudflare.com:443
|
||||
| ├── Target address: github.com:443
|
||||
| └── VPN wait durations:
|
||||
| ├── Initial duration: 6s
|
||||
| └── Additional duration: 5s
|
||||
@@ -75,7 +75,7 @@ func Test_Settings_String(t *testing.T) {
|
||||
├── HTTP proxy settings:
|
||||
| └── Enabled: no
|
||||
├── Control server settings:
|
||||
| ├── Listening address: :8000
|
||||
| ├── Listening port: 8000
|
||||
| └── Logging: yes
|
||||
├── OS Alpine settings:
|
||||
| ├── Process UID: 1000
|
||||
|
||||
@@ -3,14 +3,15 @@ package settings
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func surfsharkRetroRegion(selection ServerSelection) (
|
||||
updatedSelection ServerSelection) {
|
||||
locationData := servers.LocationData()
|
||||
locationData := constants.SurfsharkLocationData()
|
||||
|
||||
retroToLocation := make(map[string]servers.ServerLocation, len(locationData))
|
||||
retroToLocation := make(map[string]models.SurfsharkLocationData, len(locationData))
|
||||
for _, data := range locationData {
|
||||
if data.RetroLoc == "" {
|
||||
continue
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
// System contains settings to configure system related elements.
|
||||
type System struct {
|
||||
PUID *uint32
|
||||
PGID *uint32
|
||||
PUID *uint16
|
||||
PGID *uint16
|
||||
Timezone string
|
||||
}
|
||||
|
||||
@@ -19,28 +19,28 @@ func (s System) validate() (err error) {
|
||||
|
||||
func (s *System) copy() (copied System) {
|
||||
return System{
|
||||
PUID: helpers.CopyUint32Ptr(s.PUID),
|
||||
PGID: helpers.CopyUint32Ptr(s.PGID),
|
||||
PUID: helpers.CopyUint16Ptr(s.PUID),
|
||||
PGID: helpers.CopyUint16Ptr(s.PGID),
|
||||
Timezone: s.Timezone,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *System) mergeWith(other System) {
|
||||
s.PUID = helpers.MergeWithUint32(s.PUID, other.PUID)
|
||||
s.PGID = helpers.MergeWithUint32(s.PGID, other.PGID)
|
||||
s.PUID = helpers.MergeWithUint16(s.PUID, other.PUID)
|
||||
s.PGID = helpers.MergeWithUint16(s.PGID, other.PGID)
|
||||
s.Timezone = helpers.MergeWithString(s.Timezone, other.Timezone)
|
||||
}
|
||||
|
||||
func (s *System) overrideWith(other System) {
|
||||
s.PUID = helpers.OverrideWithUint32(s.PUID, other.PUID)
|
||||
s.PGID = helpers.OverrideWithUint32(s.PGID, other.PGID)
|
||||
s.PUID = helpers.OverrideWithUint16(s.PUID, other.PUID)
|
||||
s.PGID = helpers.OverrideWithUint16(s.PGID, other.PGID)
|
||||
s.Timezone = helpers.OverrideWithString(s.Timezone, other.Timezone)
|
||||
}
|
||||
|
||||
func (s *System) setDefaults() {
|
||||
const defaultID = 1000
|
||||
s.PUID = helpers.DefaultUint32(s.PUID, defaultID)
|
||||
s.PGID = helpers.DefaultUint32(s.PGID, defaultID)
|
||||
s.PUID = helpers.DefaultUint16(s.PUID, defaultID)
|
||||
s.PGID = helpers.DefaultUint16(s.PGID, defaultID)
|
||||
}
|
||||
|
||||
func (s System) String() string {
|
||||
|
||||
@@ -2,11 +2,12 @@ package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -20,15 +21,16 @@ type Updater struct {
|
||||
Period *time.Duration
|
||||
// DNSAddress is the DNS server address to use
|
||||
// to resolve VPN server hostnames to IP addresses.
|
||||
// It cannot be the empty string in the internal state.
|
||||
DNSAddress string
|
||||
// MinRatio is the minimum ratio of servers to
|
||||
// find per provider, compared to the total current
|
||||
// number of servers. It defaults to 0.8.
|
||||
MinRatio float64
|
||||
// It cannot be nil in the internal state.
|
||||
DNSAddress net.IP
|
||||
// Providers is the list of VPN service providers
|
||||
// to update server information for.
|
||||
Providers []string
|
||||
// CLI is to precise the updater is running in CLI
|
||||
// mode. This is set automatically and cannot be set
|
||||
// by settings sources. It cannot be nil in the
|
||||
// internal state.
|
||||
CLI *bool
|
||||
}
|
||||
|
||||
func (u Updater) Validate() (err error) {
|
||||
@@ -38,23 +40,21 @@ func (u Updater) Validate() (err error) {
|
||||
ErrUpdaterPeriodTooSmall, *u.Period, minPeriod)
|
||||
}
|
||||
|
||||
if u.MinRatio <= 0 || u.MinRatio > 1 {
|
||||
return fmt.Errorf("%w: %.2f must be between 0+ and 1",
|
||||
ErrMinRatioNotValid, u.MinRatio)
|
||||
}
|
||||
|
||||
validProviders := providers.All()
|
||||
for _, provider := range u.Providers {
|
||||
for i, provider := range u.Providers {
|
||||
valid := false
|
||||
for _, validProvider := range validProviders {
|
||||
for _, validProvider := range constants.AllProviders() {
|
||||
if validProvider == constants.Custom {
|
||||
continue
|
||||
}
|
||||
|
||||
if provider == validProvider {
|
||||
valid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !valid {
|
||||
return fmt.Errorf("%w: %q can only be one of %s",
|
||||
ErrVPNProviderNameNotValid, provider, helpers.ChoicesOrString(validProviders))
|
||||
return fmt.Errorf("%w: %s at index %d",
|
||||
ErrVPNProviderNameNotValid, provider, i)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ func (u Updater) Validate() (err error) {
|
||||
func (u *Updater) copy() (copied Updater) {
|
||||
return Updater{
|
||||
Period: helpers.CopyDurationPtr(u.Period),
|
||||
DNSAddress: u.DNSAddress,
|
||||
MinRatio: u.MinRatio,
|
||||
DNSAddress: helpers.CopyIP(u.DNSAddress),
|
||||
Providers: helpers.CopyStringSlice(u.Providers),
|
||||
CLI: u.CLI,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +74,9 @@ func (u *Updater) copy() (copied Updater) {
|
||||
// unset field of the receiver settings object.
|
||||
func (u *Updater) mergeWith(other Updater) {
|
||||
u.Period = helpers.MergeWithDuration(u.Period, other.Period)
|
||||
u.DNSAddress = helpers.MergeWithString(u.DNSAddress, other.DNSAddress)
|
||||
u.MinRatio = helpers.MergeWithFloat64(u.MinRatio, other.MinRatio)
|
||||
u.DNSAddress = helpers.MergeWithIP(u.DNSAddress, other.DNSAddress)
|
||||
u.Providers = helpers.MergeStringSlices(u.Providers, other.Providers)
|
||||
u.CLI = helpers.MergeWithBool(u.CLI, other.CLI)
|
||||
}
|
||||
|
||||
// overrideWith overrides fields of the receiver
|
||||
@@ -84,23 +84,15 @@ func (u *Updater) mergeWith(other Updater) {
|
||||
// settings.
|
||||
func (u *Updater) overrideWith(other Updater) {
|
||||
u.Period = helpers.OverrideWithDuration(u.Period, other.Period)
|
||||
u.DNSAddress = helpers.OverrideWithString(u.DNSAddress, other.DNSAddress)
|
||||
u.MinRatio = helpers.OverrideWithFloat64(u.MinRatio, other.MinRatio)
|
||||
u.DNSAddress = helpers.OverrideWithIP(u.DNSAddress, other.DNSAddress)
|
||||
u.Providers = helpers.OverrideWithStringSlice(u.Providers, other.Providers)
|
||||
u.CLI = helpers.MergeWithBool(u.CLI, other.CLI)
|
||||
}
|
||||
|
||||
func (u *Updater) SetDefaults(vpnProvider string) {
|
||||
func (u *Updater) SetDefaults() {
|
||||
u.Period = helpers.DefaultDuration(u.Period, 0)
|
||||
u.DNSAddress = helpers.DefaultString(u.DNSAddress, "1.1.1.1:53")
|
||||
|
||||
if u.MinRatio == 0 {
|
||||
const defaultMinRatio = 0.8
|
||||
u.MinRatio = defaultMinRatio
|
||||
}
|
||||
|
||||
if len(u.Providers) == 0 && vpnProvider != providers.Custom {
|
||||
u.Providers = []string{vpnProvider}
|
||||
}
|
||||
u.DNSAddress = helpers.DefaultIP(u.DNSAddress, net.IPv4(1, 1, 1, 1))
|
||||
u.CLI = helpers.DefaultBool(u.CLI, false)
|
||||
}
|
||||
|
||||
func (u Updater) String() string {
|
||||
@@ -108,15 +100,18 @@ func (u Updater) String() string {
|
||||
}
|
||||
|
||||
func (u Updater) toLinesNode() (node *gotree.Node) {
|
||||
if *u.Period == 0 || len(u.Providers) == 0 {
|
||||
if *u.Period == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
node = gotree.New("Server data updater settings:")
|
||||
node.Appendf("Update period: %s", *u.Period)
|
||||
node.Appendf("DNS address: %s", u.DNSAddress)
|
||||
node.Appendf("Minimum ratio: %.1f", u.MinRatio)
|
||||
node.Appendf("Providers to update: %s", strings.Join(u.Providers, ", "))
|
||||
|
||||
if *u.CLI {
|
||||
node.Appendf("CLI mode: enabled")
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func sortedInsert(ss []string, s string) []string {
|
||||
i := sort.SearchStrings(ss, s)
|
||||
ss = append(ss, "")
|
||||
copy(ss[i+1:], ss[i:])
|
||||
ss[i] = s
|
||||
return ss
|
||||
}
|
||||
|
||||
func ExtractCountries(servers []models.Server) (values []string) {
|
||||
seen := make(map[string]struct{}, len(servers))
|
||||
values = make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
value := server.Country
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
_, alreadySeen := seen[value]
|
||||
if alreadySeen {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
|
||||
values = sortedInsert(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func ExtractRegions(servers []models.Server) (values []string) {
|
||||
seen := make(map[string]struct{}, len(servers))
|
||||
values = make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
value := server.Region
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
_, alreadySeen := seen[value]
|
||||
if alreadySeen {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
|
||||
values = sortedInsert(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func ExtractCities(servers []models.Server) (values []string) {
|
||||
seen := make(map[string]struct{}, len(servers))
|
||||
values = make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
value := server.City
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
_, alreadySeen := seen[value]
|
||||
if alreadySeen {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
|
||||
values = sortedInsert(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func ExtractISPs(servers []models.Server) (values []string) {
|
||||
seen := make(map[string]struct{}, len(servers))
|
||||
values = make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
value := server.ISP
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
_, alreadySeen := seen[value]
|
||||
if alreadySeen {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
|
||||
values = sortedInsert(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func ExtractServerNames(servers []models.Server) (values []string) {
|
||||
seen := make(map[string]struct{}, len(servers))
|
||||
values = make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
value := server.ServerName
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
_, alreadySeen := seen[value]
|
||||
if alreadySeen {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
|
||||
values = sortedInsert(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func ExtractHostnames(servers []models.Server) (values []string) {
|
||||
seen := make(map[string]struct{}, len(servers))
|
||||
values = make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
value := server.Hostname
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
_, alreadySeen := seen[value]
|
||||
if alreadySeen {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
|
||||
values = sortedInsert(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||
)
|
||||
|
||||
// TODO remove in v4.
|
||||
func SurfsharkRetroLocChoices() (choices []string) {
|
||||
locationData := servers.LocationData()
|
||||
choices = make([]string, 0, len(locationData))
|
||||
seen := make(map[string]struct{}, len(locationData))
|
||||
for _, data := range locationData {
|
||||
if _, ok := seen[data.RetroLoc]; ok {
|
||||
continue
|
||||
}
|
||||
seen[data.RetroLoc] = struct{}{}
|
||||
choices = sortedInsert(choices, data.RetroLoc)
|
||||
}
|
||||
|
||||
return choices
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
|
||||
@@ -20,28 +21,28 @@ type VPN struct {
|
||||
}
|
||||
|
||||
// TODO v4 remove pointer for receiver (because of Surfshark).
|
||||
func (v *VPN) validate(storage Storage) (err error) {
|
||||
func (v *VPN) validate(allServers models.AllServers) (err error) {
|
||||
// Validate Type
|
||||
validVPNTypes := []string{vpn.OpenVPN, vpn.Wireguard}
|
||||
validVPNTypes := []string{constants.OpenVPN, constants.Wireguard}
|
||||
if !helpers.IsOneOf(v.Type, validVPNTypes...) {
|
||||
return fmt.Errorf("%w: %q and can only be one of %s",
|
||||
ErrVPNTypeNotValid, v.Type, strings.Join(validVPNTypes, ", "))
|
||||
}
|
||||
|
||||
err = v.Provider.validate(v.Type, storage)
|
||||
err = v.Provider.validate(v.Type, allServers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("provider settings: %w", err)
|
||||
return fmt.Errorf("provider settings validation failed: %w", err)
|
||||
}
|
||||
|
||||
if v.Type == vpn.OpenVPN {
|
||||
if v.Type == constants.OpenVPN {
|
||||
err := v.OpenVPN.validate(*v.Provider.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenVPN settings: %w", err)
|
||||
return fmt.Errorf("OpenVPN settings validation failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
err := v.Wireguard.validate(*v.Provider.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Wireguard settings: %w", err)
|
||||
return fmt.Errorf("Wireguard settings validation failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ func (v *VPN) overrideWith(other VPN) {
|
||||
}
|
||||
|
||||
func (v *VPN) setDefaults() {
|
||||
v.Type = helpers.DefaultString(v.Type, vpn.OpenVPN)
|
||||
v.Type = helpers.DefaultString(v.Type, constants.OpenVPN)
|
||||
v.Provider.setDefaults()
|
||||
v.OpenVPN.setDefaults(*v.Provider.Name)
|
||||
v.Wireguard.setDefaults()
|
||||
@@ -87,7 +88,7 @@ func (v VPN) toLinesNode() (node *gotree.Node) {
|
||||
|
||||
node.AppendNode(v.Provider.toLinesNode())
|
||||
|
||||
if v.Type == vpn.OpenVPN {
|
||||
if v.Type == constants.OpenVPN {
|
||||
node.AppendNode(v.OpenVPN.toLinesNode())
|
||||
} else {
|
||||
node.AppendNode(v.Wireguard.toLinesNode())
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gotree"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
@@ -35,10 +35,10 @@ var regexpInterfaceName = regexp.MustCompile(`^[a-zA-Z0-9_]+$`)
|
||||
// It should only be ran if the VPN type chosen is Wireguard.
|
||||
func (w Wireguard) validate(vpnProvider string) (err error) {
|
||||
if !helpers.IsOneOf(vpnProvider,
|
||||
providers.Custom,
|
||||
providers.Ivpn,
|
||||
providers.Mullvad,
|
||||
providers.Windscribe,
|
||||
constants.Custom,
|
||||
constants.Ivpn,
|
||||
constants.Mullvad,
|
||||
constants.Windscribe,
|
||||
) {
|
||||
// do not validate for VPN provider not supporting Wireguard
|
||||
return nil
|
||||
@@ -50,14 +50,14 @@ func (w Wireguard) validate(vpnProvider string) (err error) {
|
||||
}
|
||||
_, err = wgtypes.ParseKey(*w.PrivateKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("private key is not valid: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrWireguardPrivateKeyNotValid, err)
|
||||
}
|
||||
|
||||
// Validate PreSharedKey
|
||||
if *w.PreSharedKey != "" { // Note: this is optional
|
||||
_, err = wgtypes.ParseKey(*w.PreSharedKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("pre-shared key is not valid: %w", err)
|
||||
return fmt.Errorf("%w: %s", ErrWireguardPreSharedKeyNotValid, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gotree"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
@@ -36,8 +36,8 @@ type WireguardSelection struct {
|
||||
func (w WireguardSelection) validate(vpnProvider string) (err error) {
|
||||
// Validate EndpointIP
|
||||
switch vpnProvider {
|
||||
case providers.Ivpn, providers.Mullvad, providers.Windscribe: // endpoint IP addresses are baked in
|
||||
case providers.Custom:
|
||||
case constants.Ivpn, constants.Mullvad, constants.Windscribe: // endpoint IP addresses are baked in
|
||||
case constants.Custom:
|
||||
if len(w.EndpointIP) == 0 {
|
||||
return ErrWireguardEndpointIPNotSet
|
||||
}
|
||||
@@ -47,23 +47,23 @@ func (w WireguardSelection) validate(vpnProvider string) (err error) {
|
||||
// Validate EndpointPort
|
||||
switch vpnProvider {
|
||||
// EndpointPort is required
|
||||
case providers.Custom:
|
||||
case constants.Custom:
|
||||
if *w.EndpointPort == 0 {
|
||||
return ErrWireguardEndpointPortNotSet
|
||||
}
|
||||
case providers.Ivpn, providers.Mullvad, providers.Windscribe:
|
||||
case constants.Ivpn, constants.Mullvad, constants.Windscribe:
|
||||
// EndpointPort is optional and can be 0
|
||||
if *w.EndpointPort == 0 {
|
||||
break // no custom endpoint port set
|
||||
}
|
||||
if vpnProvider == providers.Mullvad {
|
||||
if vpnProvider == constants.Mullvad {
|
||||
break // no restriction on custom endpoint port value
|
||||
}
|
||||
var allowed []uint16
|
||||
switch vpnProvider {
|
||||
case providers.Ivpn:
|
||||
case constants.Ivpn:
|
||||
allowed = []uint16{2049, 2050, 53, 30587, 41893, 48574, 58237}
|
||||
case providers.Windscribe:
|
||||
case constants.Windscribe:
|
||||
allowed = []uint16{53, 80, 123, 443, 1194, 65142}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ func (w WireguardSelection) validate(vpnProvider string) (err error) {
|
||||
|
||||
// Validate PublicKey
|
||||
switch vpnProvider {
|
||||
case providers.Ivpn, providers.Mullvad, providers.Windscribe: // public keys are baked in
|
||||
case providers.Custom:
|
||||
case constants.Ivpn, constants.Mullvad, constants.Windscribe: // public keys are baked in
|
||||
case constants.Custom:
|
||||
if w.PublicKey == "" {
|
||||
return ErrWireguardPublicKeyNotSet
|
||||
}
|
||||
|
||||
9
internal/configuration/sources/env/dns.go
vendored
9
internal/configuration/sources/env/dns.go
vendored
@@ -3,6 +3,7 @@ package env
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
@@ -20,26 +21,26 @@ func (r *Reader) readDNS() (dns settings.DNS, err error) {
|
||||
|
||||
dns.DoT, err = r.readDoT()
|
||||
if err != nil {
|
||||
return dns, fmt.Errorf("DoT settings: %w", err)
|
||||
return dns, fmt.Errorf("cannot read DoT settings: %w", err)
|
||||
}
|
||||
|
||||
return dns, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readDNSServerAddress() (address net.IP, err error) {
|
||||
key, s := r.getEnvWithRetro("DNS_ADDRESS", "DNS_PLAINTEXT_ADDRESS")
|
||||
s := os.Getenv("DNS_PLAINTEXT_ADDRESS")
|
||||
if s == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
address = net.ParseIP(s)
|
||||
if address == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s", key, ErrIPAddressParse, s)
|
||||
return nil, fmt.Errorf("environment variable DNS_PLAINTEXT_ADDRESS: %w: %s", ErrIPAddressParse, s)
|
||||
}
|
||||
|
||||
// TODO remove in v4
|
||||
if !address.Equal(net.IPv4(127, 0, 0, 1)) { //nolint:gomnd
|
||||
r.warner.Warn(key + " is set to " + s +
|
||||
r.warner.Warn("DNS_PLAINTEXT_ADDRESS is set to " + s +
|
||||
" so the DNS over TLS (DoT) server will not be used." +
|
||||
" The default value changed to 127.0.0.1 so it uses the internal DoT server." +
|
||||
" If the DoT server fails to start, the IPv4 address of the first plaintext DNS server" +
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/binary"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
@@ -17,7 +16,7 @@ func (r *Reader) readDNSBlacklist() (blacklist settings.DNSBlacklist, err error)
|
||||
|
||||
blacklist.BlockSurveillance, err = r.readBlockSurveillance()
|
||||
if err != nil {
|
||||
return blacklist, err
|
||||
return blacklist, fmt.Errorf("environment variable BLOCK_MALICIOUS: %w", err)
|
||||
}
|
||||
|
||||
blacklist.BlockAds, err = envToBoolPtr("BLOCK_ADS")
|
||||
@@ -37,18 +36,22 @@ func (r *Reader) readDNSBlacklist() (blacklist settings.DNSBlacklist, err error)
|
||||
}
|
||||
|
||||
func (r *Reader) readBlockSurveillance() (blocked *bool, err error) {
|
||||
key, value := r.getEnvWithRetro("BLOCK_SURVEILLANCE", "BLOCK_NSA")
|
||||
if value == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
blocked = new(bool)
|
||||
*blocked, err = binary.Validate(value)
|
||||
blocked, err = envToBoolPtr("BLOCK_SURVEILLANCE")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
return nil, fmt.Errorf("environment variable BLOCK_SURVEILLANCE: %w", err)
|
||||
} else if blocked != nil {
|
||||
return blocked, nil
|
||||
}
|
||||
|
||||
return blocked, nil
|
||||
blocked, err = envToBoolPtr("BLOCK_NSA")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable BLOCK_NSA: %w", err)
|
||||
} else if blocked != nil {
|
||||
r.onRetroActive("BLOCK_NSA", "BLOCK_SURVEILLANCE")
|
||||
return blocked, nil
|
||||
}
|
||||
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
20
internal/configuration/sources/env/firewall.go
vendored
20
internal/configuration/sources/env/firewall.go
vendored
@@ -22,8 +22,16 @@ func (r *Reader) readFirewall() (firewall settings.Firewall, err error) {
|
||||
return firewall, fmt.Errorf("environment variable FIREWALL_INPUT_PORTS: %w", err)
|
||||
}
|
||||
|
||||
outboundSubnetsKey, _ := r.getEnvWithRetro("FIREWALL_OUTBOUND_SUBNETS", "EXTRA_SUBNETS")
|
||||
outboundSubnetsKey := "FIREWALL_OUTBOUND_SUBNETS"
|
||||
outboundSubnetStrings := envToCSV(outboundSubnetsKey)
|
||||
if len(outboundSubnetStrings) == 0 {
|
||||
// Retro-compatibility
|
||||
outboundSubnetStrings = envToCSV("EXTRA_SUBNETS")
|
||||
if len(outboundSubnetStrings) > 0 {
|
||||
outboundSubnetsKey = "EXTRA_SUBNETS"
|
||||
r.onRetroActive("EXTRA_SUBNETS", "FIREWALL_OUTBOUND_SUBNETS")
|
||||
}
|
||||
}
|
||||
firewall.OutboundSubnets, err = stringsToIPNets(outboundSubnetStrings)
|
||||
if err != nil {
|
||||
return firewall, fmt.Errorf("environment variable %s: %w", outboundSubnetsKey, err)
|
||||
@@ -55,7 +63,8 @@ func stringsToPorts(ss []string) (ports []uint16, err error) {
|
||||
for i, s := range ss {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %s: %s", ErrPortParsing, s, err)
|
||||
return nil, fmt.Errorf("%w: %s: %s",
|
||||
ErrPortParsing, s, err)
|
||||
} else if port < 1 || port > 65535 {
|
||||
return nil, fmt.Errorf("%w: must be between 1 and 65535: %d",
|
||||
ErrPortValue, port)
|
||||
@@ -65,6 +74,10 @@ func stringsToPorts(ss []string) (ports []uint16, err error) {
|
||||
return ports, nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrIPNetParsing = errors.New("cannot parse IP network")
|
||||
)
|
||||
|
||||
func stringsToIPNets(ss []string) (ipNets []net.IPNet, err error) {
|
||||
if len(ss) == 0 {
|
||||
return nil, nil
|
||||
@@ -73,7 +86,8 @@ func stringsToIPNets(ss []string) (ipNets []net.IPNet, err error) {
|
||||
for i, s := range ss {
|
||||
ip, ipNet, err := net.ParseCIDR(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse IP network %q: %w", s, err)
|
||||
return nil, fmt.Errorf("%w: %s: %s",
|
||||
ErrIPNetParsing, s, err)
|
||||
}
|
||||
ipNet.IP = ip
|
||||
ipNets[i] = *ipNet
|
||||
|
||||
23
internal/configuration/sources/env/health.go
vendored
23
internal/configuration/sources/env/health.go
vendored
@@ -2,14 +2,18 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
func (r *Reader) ReadHealth() (health settings.Health, err error) {
|
||||
health.ServerAddress = getCleanedEnv("HEALTH_SERVER_ADDRESS")
|
||||
_, health.TargetAddress = r.getEnvWithRetro("HEALTH_TARGET_ADDRESS", "HEALTH_ADDRESS_TO_PING")
|
||||
health.ServerAddress = os.Getenv("HEALTH_SERVER_ADDRESS")
|
||||
health.TargetAddress = os.Getenv("HEALTH_ADDRESS_TO_PING")
|
||||
if health.TargetAddress == "" {
|
||||
health.TargetAddress = os.Getenv("HEALTH_TARGET_ADDRESS")
|
||||
}
|
||||
|
||||
health.VPN.Initial, err = r.readDurationWithRetro(
|
||||
"HEALTH_VPN_DURATION_INITIAL",
|
||||
@@ -18,7 +22,7 @@ func (r *Reader) ReadHealth() (health settings.Health, err error) {
|
||||
return health, err
|
||||
}
|
||||
|
||||
health.VPN.Addition, err = r.readDurationWithRetro(
|
||||
health.VPN.Initial, err = r.readDurationWithRetro(
|
||||
"HEALTH_VPN_DURATION_ADDITION",
|
||||
"HEALTH_OPENVPN_DURATION_ADDITION")
|
||||
if err != nil {
|
||||
@@ -29,15 +33,22 @@ func (r *Reader) ReadHealth() (health settings.Health, err error) {
|
||||
}
|
||||
|
||||
func (r *Reader) readDurationWithRetro(envKey, retroEnvKey string) (d *time.Duration, err error) {
|
||||
envKey, s := r.getEnvWithRetro(envKey, retroEnvKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
s = os.Getenv(retroEnvKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
r.onRetroActive(envKey, retroEnvKey)
|
||||
envKey = retroEnvKey
|
||||
}
|
||||
|
||||
d = new(time.Duration)
|
||||
*d, err = time.ParseDuration(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", envKey, err)
|
||||
return nil, fmt.Errorf(
|
||||
"environment variable %s: %w",
|
||||
envKey, err)
|
||||
}
|
||||
|
||||
return d, nil
|
||||
|
||||
50
internal/configuration/sources/env/helpers.go
vendored
50
internal/configuration/sources/env/helpers.go
vendored
@@ -2,6 +2,7 @@ package env
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -12,43 +13,16 @@ import (
|
||||
"github.com/qdm12/govalid/integer"
|
||||
)
|
||||
|
||||
// getCleanedEnv returns an environment variable value with
|
||||
// surrounding spaces and trailing new line characters removed.
|
||||
func getCleanedEnv(envKey string) (value string) {
|
||||
value = os.Getenv(envKey)
|
||||
value = strings.TrimSpace(value)
|
||||
value = strings.TrimSuffix(value, "\r\n")
|
||||
value = strings.TrimSuffix(value, "\n")
|
||||
return value
|
||||
}
|
||||
|
||||
func envToCSV(envKey string) (values []string) {
|
||||
csv := getCleanedEnv(envKey)
|
||||
csv := os.Getenv(envKey)
|
||||
if csv == "" {
|
||||
return nil
|
||||
}
|
||||
return lowerAndSplit(csv)
|
||||
}
|
||||
|
||||
func envToInt(envKey string) (n int, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
if s == "" {
|
||||
return 0, nil
|
||||
}
|
||||
return strconv.Atoi(s)
|
||||
}
|
||||
|
||||
func envToFloat64(envKey string) (f float64, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
if s == "" {
|
||||
return 0, nil
|
||||
}
|
||||
const bits = 64
|
||||
return strconv.ParseFloat(s, bits)
|
||||
}
|
||||
|
||||
func envToStringPtr(envKey string) (stringPtr *string) {
|
||||
s := getCleanedEnv(envKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -56,7 +30,7 @@ func envToStringPtr(envKey string) (stringPtr *string) {
|
||||
}
|
||||
|
||||
func envToBoolPtr(envKey string) (boolPtr *bool, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -68,7 +42,7 @@ func envToBoolPtr(envKey string) (boolPtr *bool, err error) {
|
||||
}
|
||||
|
||||
func envToIntPtr(envKey string) (intPtr *int, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -80,7 +54,7 @@ func envToIntPtr(envKey string) (intPtr *int, err error) {
|
||||
}
|
||||
|
||||
func envToUint8Ptr(envKey string) (uint8Ptr *uint8, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -97,7 +71,7 @@ func envToUint8Ptr(envKey string) (uint8Ptr *uint8, err error) {
|
||||
}
|
||||
|
||||
func envToUint16Ptr(envKey string) (uint16Ptr *uint16, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -114,7 +88,7 @@ func envToUint16Ptr(envKey string) (uint16Ptr *uint16, err error) {
|
||||
}
|
||||
|
||||
func envToDurationPtr(envKey string) (durationPtr *time.Duration, err error) {
|
||||
s := getCleanedEnv(envKey)
|
||||
s := os.Getenv(envKey)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -133,11 +107,13 @@ func lowerAndSplit(csv string) (values []string) {
|
||||
return strings.Split(csv, ",")
|
||||
}
|
||||
|
||||
var ErrDecodeBase64 = errors.New("cannot decode base64 string")
|
||||
|
||||
func decodeBase64(b64String string) (decoded string, err error) {
|
||||
b, err := base64.StdEncoding.DecodeString(b64String)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot decode base64 string %q: %w",
|
||||
b64String, err)
|
||||
return "", fmt.Errorf("%w: %s: %s",
|
||||
ErrDecodeBase64, b64String, err)
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
@@ -154,5 +130,5 @@ func unsetEnvKeys(envKeys []string, err error) (newErr error) {
|
||||
}
|
||||
|
||||
func stringPtr(s string) *string { return &s }
|
||||
func uint32Ptr(n uint32) *uint32 { return &n }
|
||||
func uint16Ptr(n uint16) *uint16 { return &n }
|
||||
func boolPtr(b bool) *bool { return &b }
|
||||
|
||||
131
internal/configuration/sources/env/httproxy.go
vendored
131
internal/configuration/sources/env/httproxy.go
vendored
@@ -2,6 +2,8 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/binary"
|
||||
@@ -31,61 +33,138 @@ func (r *Reader) readHTTPProxy() (httpProxy settings.HTTPProxy, err error) {
|
||||
}
|
||||
|
||||
func (r *Reader) readHTTProxyUser() (user *string) {
|
||||
_, s := r.getEnvWithRetro("HTTPPROXY_USER", "PROXY_USER", "TINYPROXY_USER")
|
||||
s := os.Getenv("HTTPPROXY_USER")
|
||||
if s != "" {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
s = os.Getenv("TINYPROXY_USER")
|
||||
if s != "" {
|
||||
r.onRetroActive("TINYPROXY_USER", "HTTPPROXY_USER")
|
||||
return &s
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
s = os.Getenv("PROXY_USER")
|
||||
if s != "" {
|
||||
r.onRetroActive("PROXY_USER", "HTTPPROXY_USER")
|
||||
return &s
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Reader) readHTTProxyPassword() (user *string) {
|
||||
_, s := r.getEnvWithRetro("HTTPPROXY_PASSWORD", "PROXY_PASSWORD", "TINYPROXY_PASSWORD")
|
||||
s := os.Getenv("HTTPPROXY_PASSWORD")
|
||||
if s != "" {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
s = os.Getenv("TINYPROXY_PASSWORD")
|
||||
if s != "" {
|
||||
r.onRetroActive("TINYPROXY_PASSWORD", "HTTPPROXY_PASSWORD")
|
||||
return &s
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
s = os.Getenv("PROXY_PASSWORD")
|
||||
if s != "" {
|
||||
r.onRetroActive("PROXY_PASSWORD", "HTTPPROXY_PASSWORD")
|
||||
return &s
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Reader) readHTTProxyListeningAddress() (listeningAddress string) {
|
||||
key, value := r.getEnvWithRetro("HTTPPROXY_LISTENING_ADDRESS", "PROXY_PORT", "TINYPROXY_PORT", "HTTPPROXY_PORT")
|
||||
if key == "HTTPPROXY_LISTENING_ADDRESS" {
|
||||
return value
|
||||
// Retro-compatibility
|
||||
retroKeys := []string{"PROXY_PORT", "TINYPROXY_PORT", "HTTPPROXY_PORT"}
|
||||
for _, retroKey := range retroKeys {
|
||||
s := os.Getenv(retroKey)
|
||||
if s != "" {
|
||||
r.onRetroActive(retroKey, "HTTPPROXY_LISTENING_ADDRESS")
|
||||
return ":" + s
|
||||
}
|
||||
}
|
||||
return ":" + value
|
||||
|
||||
return os.Getenv("HTTPPROXY_LISTENING_ADDRESS")
|
||||
}
|
||||
|
||||
func (r *Reader) readHTTProxyEnabled() (enabled *bool, err error) {
|
||||
key, s := r.getEnvWithRetro("HTTPPROXY", "PROXY", "TINYPROXY")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
s := strings.ToLower(os.Getenv("HTTPPROXY"))
|
||||
if s != "" {
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable HTTPPROXY: %w", err)
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
// Retro-compatibility
|
||||
s = strings.ToLower(os.Getenv("TINYPROXY"))
|
||||
if s != "" {
|
||||
r.onRetroActive("TINYPROXY", "HTTPPROXY")
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable TINYPROXY: %w", err)
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
return enabled, nil
|
||||
// Retro-compatibility
|
||||
s = strings.ToLower(os.Getenv("PROXY"))
|
||||
if s != "" {
|
||||
r.onRetroActive("PROXY", "HTTPPROXY")
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable PROXY: %w", err)
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
func (r *Reader) readHTTProxyLog() (enabled *bool, err error) {
|
||||
key, s := r.getEnvWithRetro("HTTPPROXY_LOG", "PROXY_LOG_LEVEL", "TINYPROXY_LOG")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
s := strings.ToLower(os.Getenv("HTTPPROXY_LOG"))
|
||||
if s != "" {
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable HTTPPROXY_LOG: %w", err)
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
var binaryOptions []binary.Option
|
||||
if key != "HTTPROXY_LOG" {
|
||||
retroOption := binary.OptionEnabled("on", "info", "connect", "notice")
|
||||
binaryOptions = append(binaryOptions, retroOption)
|
||||
// Retro-compatibility
|
||||
retroOption := binary.OptionEnabled("on", "info", "connect", "notice")
|
||||
s = strings.ToLower(os.Getenv("TINYPROXY_LOG"))
|
||||
if s != "" {
|
||||
r.onRetroActive("TINYPROXY_LOG", "HTTPPROXY_LOG")
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s, retroOption)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable TINYPROXY_LOG: %w", err)
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s, binaryOptions...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
// Retro-compatibility
|
||||
s = strings.ToLower(os.Getenv("PROXY_LOG_LEVEL"))
|
||||
if s != "" {
|
||||
r.onRetroActive("PROXY_LOG_LEVEL", "HTTPPROXY_LOG")
|
||||
enabled = new(bool)
|
||||
*enabled, err = binary.Validate(s, retroOption)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable PROXY_LOG_LEVEL: %w", err)
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
return enabled, nil
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
21
internal/configuration/sources/env/log.go
vendored
21
internal/configuration/sources/env/log.go
vendored
@@ -3,10 +3,11 @@ package env
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/log"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
func readLog() (log settings.Log, err error) {
|
||||
@@ -18,13 +19,13 @@ func readLog() (log settings.Log, err error) {
|
||||
return log, nil
|
||||
}
|
||||
|
||||
func readLogLevel() (level *log.Level, err error) {
|
||||
s := getCleanedEnv("LOG_LEVEL")
|
||||
func readLogLevel() (level *logging.Level, err error) {
|
||||
s := os.Getenv("LOG_LEVEL")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
level = new(log.Level)
|
||||
level = new(logging.Level)
|
||||
*level, err = parseLogLevel(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable LOG_LEVEL: %w", err)
|
||||
@@ -35,19 +36,19 @@ func readLogLevel() (level *log.Level, err error) {
|
||||
|
||||
var ErrLogLevelUnknown = errors.New("log level is unknown")
|
||||
|
||||
func parseLogLevel(s string) (level log.Level, err error) {
|
||||
func parseLogLevel(s string) (level logging.Level, err error) {
|
||||
switch strings.ToLower(s) {
|
||||
case "debug":
|
||||
return log.LevelDebug, nil
|
||||
return logging.LevelDebug, nil
|
||||
case "info":
|
||||
return log.LevelInfo, nil
|
||||
return logging.LevelInfo, nil
|
||||
case "warning":
|
||||
return log.LevelWarn, nil
|
||||
return logging.LevelWarn, nil
|
||||
case "error":
|
||||
return log.LevelError, nil
|
||||
return logging.LevelError, nil
|
||||
default:
|
||||
return level, fmt.Errorf(
|
||||
"%w: %q is not valid and can be one of debug, info, warning or error",
|
||||
"%w: %s: can be one of: debug, info, warning or error",
|
||||
ErrLogLevelUnknown, s)
|
||||
}
|
||||
}
|
||||
|
||||
73
internal/configuration/sources/env/openvpn.go
vendored
73
internal/configuration/sources/env/openvpn.go
vendored
@@ -2,10 +2,10 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/binary"
|
||||
)
|
||||
|
||||
func (r *Reader) readOpenVPN() (
|
||||
@@ -14,18 +14,16 @@ func (r *Reader) readOpenVPN() (
|
||||
err = unsetEnvKeys([]string{"OPENVPN_CLIENTKEY", "OPENVPN_CLIENTCRT"}, err)
|
||||
}()
|
||||
|
||||
openVPN.Version = getCleanedEnv("OPENVPN_VERSION")
|
||||
openVPN.Version = os.Getenv("OPENVPN_VERSION")
|
||||
openVPN.User = r.readOpenVPNUser()
|
||||
openVPN.Password = r.readOpenVPNPassword()
|
||||
confFile := getCleanedEnv("OPENVPN_CUSTOM_CONFIG")
|
||||
confFile := os.Getenv("OPENVPN_CUSTOM_CONFIG")
|
||||
if confFile != "" {
|
||||
openVPN.ConfFile = &confFile
|
||||
}
|
||||
|
||||
ciphersKey, _ := r.getEnvWithRetro("OPENVPN_CIPHERS", "OPENVPN_CIPHER")
|
||||
openVPN.Ciphers = envToCSV(ciphersKey)
|
||||
|
||||
auth := getCleanedEnv("OPENVPN_AUTH")
|
||||
openVPN.Ciphers = envToCSV("OPENVPN_CIPHER")
|
||||
auth := os.Getenv("OPENVPN_AUTH")
|
||||
if auth != "" {
|
||||
openVPN.Auth = &auth
|
||||
}
|
||||
@@ -52,19 +50,21 @@ func (r *Reader) readOpenVPN() (
|
||||
return openVPN, fmt.Errorf("environment variable OPENVPN_MSSFIX: %w", err)
|
||||
}
|
||||
|
||||
_, openVPN.Interface = r.getEnvWithRetro("VPN_INTERFACE", "OPENVPN_INTERFACE")
|
||||
openVPN.Interface = os.Getenv("OPENVPN_INTERFACE")
|
||||
|
||||
openVPN.ProcessUser, err = r.readOpenVPNProcessUser()
|
||||
openVPN.Root, err = envToBoolPtr("OPENVPN_ROOT")
|
||||
if err != nil {
|
||||
return openVPN, err
|
||||
return openVPN, fmt.Errorf("environment variable OPENVPN_ROOT: %w", err)
|
||||
}
|
||||
|
||||
// TODO ProcUser once Root is deprecated.
|
||||
|
||||
openVPN.Verbosity, err = envToIntPtr("OPENVPN_VERBOSITY")
|
||||
if err != nil {
|
||||
return openVPN, fmt.Errorf("environment variable OPENVPN_VERBOSITY: %w", err)
|
||||
}
|
||||
|
||||
flagsStr := getCleanedEnv("OPENVPN_FLAGS")
|
||||
flagsStr := os.Getenv("OPENVPN_FLAGS")
|
||||
if flagsStr != "" {
|
||||
openVPN.Flags = strings.Fields(flagsStr)
|
||||
}
|
||||
@@ -73,18 +73,34 @@ func (r *Reader) readOpenVPN() (
|
||||
}
|
||||
|
||||
func (r *Reader) readOpenVPNUser() (user string) {
|
||||
_, user = r.getEnvWithRetro("OPENVPN_USER", "USER")
|
||||
user = os.Getenv("OPENVPN_USER")
|
||||
if user == "" {
|
||||
// Retro-compatibility
|
||||
user = os.Getenv("USER")
|
||||
if user != "" {
|
||||
r.onRetroActive("USER", "OPENVPN_USER")
|
||||
}
|
||||
}
|
||||
// Remove spaces in user ID to simplify user's life, thanks @JeordyR
|
||||
return strings.ReplaceAll(user, " ", "")
|
||||
}
|
||||
|
||||
func (r *Reader) readOpenVPNPassword() (password string) {
|
||||
_, password = r.getEnvWithRetro("OPENVPN_PASSWORD", "PASSWORD")
|
||||
password = os.Getenv("OPENVPN_PASSWORD")
|
||||
if password != "" {
|
||||
return password
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
password = os.Getenv("PASSWORD")
|
||||
if password != "" {
|
||||
r.onRetroActive("PASSWORD", "OPENVPN_PASSWORD")
|
||||
}
|
||||
return password
|
||||
}
|
||||
|
||||
func readBase64OrNil(envKey string) (valueOrNil *string, err error) {
|
||||
value := getCleanedEnv(envKey)
|
||||
value := os.Getenv(envKey)
|
||||
if value == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -98,32 +114,17 @@ func readBase64OrNil(envKey string) (valueOrNil *string, err error) {
|
||||
}
|
||||
|
||||
func (r *Reader) readPIAEncryptionPreset() (presetPtr *string) {
|
||||
_, preset := r.getEnvWithRetro(
|
||||
"PRIVATE_INTERNET_ACCESS_OPENVPN_ENCRYPTION_PRESET",
|
||||
"PIA_ENCRYPTION", "ENCRYPTION")
|
||||
preset := strings.ToLower(os.Getenv("PIA_ENCRYPTION"))
|
||||
if preset != "" {
|
||||
return &preset
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Reader) readOpenVPNProcessUser() (processUser string, err error) {
|
||||
key, value := r.getEnvWithRetro("OPENVPN_PROCESS_USER", "OPENVPN_ROOT")
|
||||
if key == "OPENVPN_PROCESS_USER" {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
if value == "" {
|
||||
return "", nil
|
||||
preset = strings.ToLower(os.Getenv("ENCRYPTION"))
|
||||
if preset != "" {
|
||||
r.onRetroActive("ENCRYPTION", "PIA_ENCRYPTION")
|
||||
return &preset
|
||||
}
|
||||
root, err := binary.Validate(value)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("environment variable %s: %w", key, err)
|
||||
}
|
||||
if root {
|
||||
return "root", nil
|
||||
}
|
||||
const defaultNonRootUser = "nonrootuser"
|
||||
return defaultNonRootUser, nil
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package env
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
|
||||
func (r *Reader) readOpenVPNSelection() (
|
||||
selection settings.OpenVPNSelection, err error) {
|
||||
confFile := getCleanedEnv("OPENVPN_CUSTOM_CONFIG")
|
||||
confFile := os.Getenv("OPENVPN_CUSTOM_CONFIG")
|
||||
if confFile != "" {
|
||||
selection.ConfFile = &confFile
|
||||
}
|
||||
@@ -35,9 +36,18 @@ func (r *Reader) readOpenVPNSelection() (
|
||||
var ErrOpenVPNProtocolNotValid = errors.New("OpenVPN protocol is not valid")
|
||||
|
||||
func (r *Reader) readOpenVPNProtocol() (tcp *bool, err error) {
|
||||
envKey, protocol := r.getEnvWithRetro("OPENVPN_PROTOCOL", "PROTOCOL")
|
||||
envKey := "OPENVPN_PROTOCOL"
|
||||
protocol := strings.ToLower(os.Getenv("OPENVPN_PROTOCOL"))
|
||||
if protocol == "" {
|
||||
// Retro-compatibility
|
||||
protocol = strings.ToLower(os.Getenv("PROTOCOL"))
|
||||
if protocol != "" {
|
||||
envKey = "PROTOCOL"
|
||||
r.onRetroActive("PROTOCOL", "OPENVPN_PROTOCOL")
|
||||
}
|
||||
}
|
||||
|
||||
switch strings.ToLower(protocol) {
|
||||
switch protocol {
|
||||
case "":
|
||||
return nil, nil //nolint:nilnil
|
||||
case constants.UDP:
|
||||
@@ -51,9 +61,16 @@ func (r *Reader) readOpenVPNProtocol() (tcp *bool, err error) {
|
||||
}
|
||||
|
||||
func (r *Reader) readOpenVPNCustomPort() (customPort *uint16, err error) {
|
||||
key, s := r.getEnvWithRetro("VPN_ENDPOINT_PORT", "PORT", "OPENVPN_PORT")
|
||||
key := "OPENVPN_PORT"
|
||||
s := os.Getenv(key)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
// Retro-compatibility
|
||||
key = "PORT"
|
||||
s = os.Getenv(key)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
r.onRetroActive("PORT", "OPENVPN_PORT")
|
||||
}
|
||||
|
||||
customPort = new(uint16)
|
||||
|
||||
@@ -6,22 +6,14 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
func (r *Reader) readPortForward() (
|
||||
func readPortForward() (
|
||||
portForwarding settings.PortForwarding, err error) {
|
||||
key, _ := r.getEnvWithRetro(
|
||||
"PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING",
|
||||
"PORT_FORWARDING")
|
||||
portForwarding.Enabled, err = envToBoolPtr(key)
|
||||
portForwarding.Enabled, err = envToBoolPtr("PORT_FORWARDING")
|
||||
if err != nil {
|
||||
return portForwarding, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
return portForwarding, fmt.Errorf("environment variable PORT_FORWARDING: %w", err)
|
||||
}
|
||||
|
||||
_, value := r.getEnvWithRetro(
|
||||
"PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING_STATUS_FILE",
|
||||
"PORT_FORWARDING_STATUS_FILE")
|
||||
if value != "" {
|
||||
portForwarding.Filepath = stringPtr(value)
|
||||
}
|
||||
portForwarding.Filepath = envToStringPtr("PORT_FORWARDING_STATUS_FILE")
|
||||
|
||||
return portForwarding, nil
|
||||
}
|
||||
|
||||
28
internal/configuration/sources/env/pprof.go
vendored
28
internal/configuration/sources/env/pprof.go
vendored
@@ -1,28 +0,0 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/pprof"
|
||||
)
|
||||
|
||||
func readPprof() (settings pprof.Settings, err error) {
|
||||
settings.Enabled, err = envToBoolPtr("PPROF_ENABLED")
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("environment variable PPROF_ENABLED: %w", err)
|
||||
}
|
||||
|
||||
settings.BlockProfileRate, err = envToInt("PPROF_BLOCK_PROFILE_RATE")
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("environment variable PPROF_BLOCK_PROFILE_RATE: %w", err)
|
||||
}
|
||||
|
||||
settings.MutexProfileRate, err = envToInt("PPROF_MUTEX_PROFILE_RATE")
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("environment variable PPROF_MUTEX_PROFILE_RATE: %w", err)
|
||||
}
|
||||
|
||||
settings.HTTPServer.Address = getCleanedEnv("PPROF_HTTP_SERVER_ADDRESS")
|
||||
|
||||
return settings, nil
|
||||
}
|
||||
25
internal/configuration/sources/env/provider.go
vendored
25
internal/configuration/sources/env/provider.go
vendored
@@ -2,15 +2,15 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func (r *Reader) readProvider(vpnType string) (provider settings.Provider, err error) {
|
||||
provider.Name = r.readVPNServiceProvider(vpnType)
|
||||
provider.Name = readVPNServiceProvider(vpnType)
|
||||
var providerName string
|
||||
if provider.Name != nil {
|
||||
providerName = *provider.Name
|
||||
@@ -18,28 +18,27 @@ func (r *Reader) readProvider(vpnType string) (provider settings.Provider, err e
|
||||
|
||||
provider.ServerSelection, err = r.readServerSelection(providerName, vpnType)
|
||||
if err != nil {
|
||||
return provider, fmt.Errorf("server selection: %w", err)
|
||||
return provider, fmt.Errorf("cannot read server selection settings: %w", err)
|
||||
}
|
||||
|
||||
provider.PortForwarding, err = r.readPortForward()
|
||||
provider.PortForwarding, err = readPortForward()
|
||||
if err != nil {
|
||||
return provider, fmt.Errorf("port forwarding: %w", err)
|
||||
return provider, fmt.Errorf("cannot read port forwarding settings: %w", err)
|
||||
}
|
||||
|
||||
return provider, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) {
|
||||
_, s := r.getEnvWithRetro("VPN_SERVICE_PROVIDER", "VPNSP")
|
||||
s = strings.ToLower(s)
|
||||
func readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) {
|
||||
s := strings.ToLower(os.Getenv("VPNSP"))
|
||||
switch {
|
||||
case vpnType != vpn.Wireguard &&
|
||||
getCleanedEnv("OPENVPN_CUSTOM_CONFIG") != "": // retro compatibility
|
||||
return stringPtr(providers.Custom)
|
||||
case vpnType != constants.Wireguard &&
|
||||
os.Getenv("OPENVPN_CUSTOM_CONFIG") != "": // retro compatibility
|
||||
return stringPtr(constants.Custom)
|
||||
case s == "":
|
||||
return nil
|
||||
case s == "pia": // retro compatibility
|
||||
return stringPtr(providers.PrivateInternetAccess)
|
||||
return stringPtr(constants.PrivateInternetAccess)
|
||||
}
|
||||
return stringPtr(s)
|
||||
}
|
||||
|
||||
13
internal/configuration/sources/env/publicip.go
vendored
13
internal/configuration/sources/env/publicip.go
vendored
@@ -2,6 +2,7 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -19,7 +20,7 @@ func (r *Reader) readPublicIP() (publicIP settings.PublicIP, err error) {
|
||||
}
|
||||
|
||||
func readPublicIPPeriod() (period *time.Duration, err error) {
|
||||
s := getCleanedEnv("PUBLICIP_PERIOD")
|
||||
s := os.Getenv("PUBLICIP_PERIOD")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -34,9 +35,17 @@ func readPublicIPPeriod() (period *time.Duration, err error) {
|
||||
}
|
||||
|
||||
func (r *Reader) readPublicIPFilepath() (filepath *string) {
|
||||
_, s := r.getEnvWithRetro("PUBLICIP_FILE", "IP_STATUS_FILE")
|
||||
s := os.Getenv("PUBLICIP_FILE")
|
||||
if s != "" {
|
||||
return &s
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
s = os.Getenv("IP_STATUS_FILE")
|
||||
if s != "" {
|
||||
r.onRetroActive("IP_STATUS_FILE", "PUBLICIP_FILE")
|
||||
return &s
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
30
internal/configuration/sources/env/reader.go
vendored
30
internal/configuration/sources/env/reader.go
vendored
@@ -21,8 +21,6 @@ func New(warner Warner) *Reader {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reader) String() string { return "environment variables" }
|
||||
|
||||
func (r *Reader) Read() (settings settings.Settings, err error) {
|
||||
settings.VPN, err = r.readVPN()
|
||||
if err != nil {
|
||||
@@ -79,12 +77,7 @@ func (r *Reader) Read() (settings settings.Settings, err error) {
|
||||
return settings, err
|
||||
}
|
||||
|
||||
settings.ControlServer, err = r.readControlServer()
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
|
||||
settings.Pprof, err = readPprof()
|
||||
settings.ControlServer, err = readControlServer()
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
@@ -97,24 +90,3 @@ func (r *Reader) onRetroActive(oldKey, newKey string) {
|
||||
"You are using the old environment variable " + oldKey +
|
||||
", please consider changing it to " + newKey)
|
||||
}
|
||||
|
||||
// getEnvWithRetro returns the first environment variable
|
||||
// key and corresponding non empty value from the environment
|
||||
// variable keys given. It first goes through the retroKeys
|
||||
// and end on returning the value corresponding to the currentKey.
|
||||
// Note retroKeys should be in order from oldest to most
|
||||
// recent retro-compatibility key.
|
||||
func (r *Reader) getEnvWithRetro(currentKey string,
|
||||
retroKeys ...string) (key, value string) {
|
||||
// We check retro-compatibility keys first since
|
||||
// the current key might be set in the Dockerfile.
|
||||
for _, key = range retroKeys {
|
||||
value = getCleanedEnv(key)
|
||||
if value != "" {
|
||||
r.onRetroActive(key, currentKey)
|
||||
return key, value
|
||||
}
|
||||
}
|
||||
|
||||
return currentKey, getCleanedEnv(currentKey)
|
||||
}
|
||||
|
||||
27
internal/configuration/sources/env/server.go
vendored
27
internal/configuration/sources/env/server.go
vendored
@@ -2,24 +2,29 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/binary"
|
||||
"github.com/qdm12/govalid/port"
|
||||
)
|
||||
|
||||
func (r *Reader) readControlServer() (controlServer settings.ControlServer, err error) {
|
||||
func readControlServer() (controlServer settings.ControlServer, err error) {
|
||||
controlServer.Log, err = readControlServerLog()
|
||||
if err != nil {
|
||||
return controlServer, err
|
||||
}
|
||||
|
||||
controlServer.Address = r.readControlServerAddress()
|
||||
controlServer.Port, err = readControlServerPort()
|
||||
if err != nil {
|
||||
return controlServer, err
|
||||
}
|
||||
|
||||
return controlServer, nil
|
||||
}
|
||||
|
||||
func readControlServerLog() (enabled *bool, err error) {
|
||||
s := getCleanedEnv("HTTP_CONTROL_SERVER_LOG")
|
||||
s := os.Getenv("HTTP_CONTROL_SERVER_LOG")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -32,17 +37,17 @@ func readControlServerLog() (enabled *bool, err error) {
|
||||
return &log, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readControlServerAddress() (address *string) {
|
||||
key, s := r.getEnvWithRetro("HTTP_CONTROL_SERVER_ADDRESS", "HTTP_CONTROL_SERVER_PORT")
|
||||
func readControlServerPort() (p *uint16, err error) {
|
||||
s := os.Getenv("HTTP_CONTROL_SERVER_PORT")
|
||||
if s == "" {
|
||||
return nil
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
if key == "HTTP_CONTROL_SERVER_ADDRESS" {
|
||||
return &s
|
||||
p = new(uint16)
|
||||
*p, err = port.Validate(s, port.OptionPortListening(os.Geteuid()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable HTTP_CONTROL_SERVER_PORT: %w", err)
|
||||
}
|
||||
|
||||
address = new(string)
|
||||
*address = ":" + s
|
||||
return address
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -19,36 +20,28 @@ func (r *Reader) readServerSelection(vpnProvider, vpnType string) (
|
||||
ss settings.ServerSelection, err error) {
|
||||
ss.VPN = vpnType
|
||||
|
||||
ss.TargetIP, err = r.readOpenVPNTargetIP()
|
||||
ss.TargetIP, err = readOpenVPNTargetIP()
|
||||
if err != nil {
|
||||
return ss, err
|
||||
}
|
||||
|
||||
countriesKey, _ := r.getEnvWithRetro("SERVER_COUNTRIES", "COUNTRY")
|
||||
ss.Countries = envToCSV(countriesKey)
|
||||
if vpnProvider == providers.Cyberghost && len(ss.Countries) == 0 {
|
||||
// Retro-compatibility for Cyberghost using the REGION variable
|
||||
ss.Countries = envToCSV("REGION")
|
||||
if len(ss.Countries) > 0 {
|
||||
r.onRetroActive("REGION", "SERVER_COUNTRIES")
|
||||
}
|
||||
countriesCSV := os.Getenv("COUNTRY")
|
||||
if vpnProvider == constants.Cyberghost && countriesCSV == "" {
|
||||
// Retro-compatibility
|
||||
r.onRetroActive("REGION", "COUNTRY")
|
||||
countriesCSV = os.Getenv("REGION")
|
||||
}
|
||||
if countriesCSV != "" {
|
||||
ss.Countries = lowerAndSplit(countriesCSV)
|
||||
}
|
||||
|
||||
regionsKey, _ := r.getEnvWithRetro("SERVER_REGIONS", "REGION")
|
||||
ss.Regions = envToCSV(regionsKey)
|
||||
|
||||
citiesKey, _ := r.getEnvWithRetro("SERVER_CITIES", "CITY")
|
||||
ss.Cities = envToCSV(citiesKey)
|
||||
|
||||
ss.Regions = envToCSV("REGION")
|
||||
ss.Cities = envToCSV("CITY")
|
||||
ss.ISPs = envToCSV("ISP")
|
||||
ss.Hostnames = envToCSV("SERVER_HOSTNAME")
|
||||
ss.Names = envToCSV("SERVER_NAME")
|
||||
|
||||
hostnamesKey, _ := r.getEnvWithRetro("SERVER_HOSTNAMES", "SERVER_HOSTNAME")
|
||||
ss.Hostnames = envToCSV(hostnamesKey)
|
||||
|
||||
serverNamesKey, _ := r.getEnvWithRetro("SERVER_NAMES", "SERVER_NAME")
|
||||
ss.Names = envToCSV(serverNamesKey)
|
||||
|
||||
if csv := getCleanedEnv("SERVER_NUMBER"); csv != "" {
|
||||
if csv := os.Getenv("SERVER_NUMBER"); csv != "" {
|
||||
numbersStrings := strings.Split(csv, ",")
|
||||
numbers := make([]uint16, len(numbersStrings))
|
||||
for i, numberString := range numbersStrings {
|
||||
@@ -66,9 +59,9 @@ func (r *Reader) readServerSelection(vpnProvider, vpnType string) (
|
||||
}
|
||||
|
||||
// Mullvad only
|
||||
ss.OwnedOnly, err = r.readOwnedOnly()
|
||||
ss.OwnedOnly, err = envToBoolPtr("OWNED")
|
||||
if err != nil {
|
||||
return ss, err
|
||||
return ss, fmt.Errorf("environment variable OWNED: %w", err)
|
||||
}
|
||||
|
||||
// VPNUnlimited and ProtonVPN only
|
||||
@@ -106,26 +99,17 @@ var (
|
||||
ErrInvalidIP = errors.New("invalid IP address")
|
||||
)
|
||||
|
||||
func (r *Reader) readOpenVPNTargetIP() (ip net.IP, err error) {
|
||||
envKey, s := r.getEnvWithRetro("VPN_ENDPOINT_IP", "OPENVPN_TARGET_IP")
|
||||
func readOpenVPNTargetIP() (ip net.IP, err error) {
|
||||
s := os.Getenv("OPENVPN_TARGET_IP")
|
||||
if s == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ip = net.ParseIP(s)
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s",
|
||||
envKey, ErrInvalidIP, s)
|
||||
return nil, fmt.Errorf("environment variable OPENVPN_TARGET_IP: %w: %s",
|
||||
ErrInvalidIP, s)
|
||||
}
|
||||
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readOwnedOnly() (ownedOnly *bool, err error) {
|
||||
envKey, _ := r.getEnvWithRetro("OWNED_ONLY", "OWNED")
|
||||
ownedOnly, err = envToBoolPtr(envKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", envKey, err)
|
||||
}
|
||||
return ownedOnly, nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
@@ -25,20 +25,30 @@ func (r *Reader) readShadowsocks() (shadowsocks settings.Shadowsocks, err error)
|
||||
}
|
||||
|
||||
func (r *Reader) readShadowsocksAddress() (address string) {
|
||||
key, value := r.getEnvWithRetro("SHADOWSOCKS_LISTENING_ADDRESS", "SHADOWSOCKS_PORT")
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if key == "SHADOWSOCKS_LISTENING_ADDRESS" {
|
||||
return value
|
||||
address = os.Getenv("SHADOWSOCKS_LISTENING_ADDRESS")
|
||||
if address != "" {
|
||||
return address
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
return ":" + value
|
||||
portString := os.Getenv("SHADOWSOCKS_PORT")
|
||||
if portString != "" {
|
||||
r.onRetroActive("SHADOWSOCKS_PORT", "SHADOWSOCKS_LISTENING_ADDRESS")
|
||||
return ":" + portString
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *Reader) readShadowsocksCipher() (cipher string) {
|
||||
_, cipher = r.getEnvWithRetro("SHADOWSOCKS_CIPHER", "SHADOWSOCKS_METHOD")
|
||||
return strings.ToLower(cipher)
|
||||
cipher = os.Getenv("SHADOWSOCKS_CIPHER")
|
||||
if cipher != "" {
|
||||
return cipher
|
||||
}
|
||||
// Retro-compatibility
|
||||
cipher = os.Getenv("SHADOWSOCKS_METHOD")
|
||||
if cipher != "" {
|
||||
r.onRetroActive("SHADOWSOCKS_METHOD", "SHADOWSOCKS_CIPHER")
|
||||
}
|
||||
return cipher
|
||||
}
|
||||
|
||||
34
internal/configuration/sources/env/system.go
vendored
34
internal/configuration/sources/env/system.go
vendored
@@ -3,6 +3,7 @@ package env
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -25,7 +26,7 @@ func (r *Reader) readSystem() (system settings.System, err error) {
|
||||
return system, err
|
||||
}
|
||||
|
||||
system.Timezone = getCleanedEnv("TZ")
|
||||
system.Timezone = os.Getenv("TZ")
|
||||
|
||||
return system, nil
|
||||
}
|
||||
@@ -33,23 +34,30 @@ func (r *Reader) readSystem() (system settings.System, err error) {
|
||||
var ErrSystemIDNotValid = errors.New("system ID is not valid")
|
||||
|
||||
func (r *Reader) readID(key, retroKey string) (
|
||||
id *uint32, err error) {
|
||||
idEnvKey, idString := r.getEnvWithRetro(key, retroKey)
|
||||
id *uint16, err error) {
|
||||
idEnvKey := key
|
||||
idString := os.Getenv(key)
|
||||
if idString == "" {
|
||||
// retro-compatibility
|
||||
idString = os.Getenv(retroKey)
|
||||
if idString != "" {
|
||||
idEnvKey = retroKey
|
||||
r.onRetroActive(retroKey, key)
|
||||
}
|
||||
}
|
||||
|
||||
if idString == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
const base = 10
|
||||
const bitSize = 64
|
||||
const max = uint64(^uint32(0))
|
||||
idUint64, err := strconv.ParseUint(idString, base, bitSize)
|
||||
idInt, err := strconv.Atoi(idString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s",
|
||||
idEnvKey, ErrSystemIDNotValid, err)
|
||||
} else if idUint64 > max {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %d: must be between 0 and %d",
|
||||
idEnvKey, ErrSystemIDNotValid, idUint64, max)
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s: %s",
|
||||
idEnvKey, ErrSystemIDNotValid, idString, err)
|
||||
} else if idInt < 0 || idInt > 65535 {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %d: must be between 0 and 65535",
|
||||
idEnvKey, ErrSystemIDNotValid, idInt)
|
||||
}
|
||||
|
||||
return uint32Ptr(uint32(idUint64)), nil
|
||||
return uint16Ptr(uint16(idInt)), nil
|
||||
}
|
||||
|
||||
@@ -14,51 +14,15 @@ func Test_Reader_readID(t *testing.T) {
|
||||
keyValue string
|
||||
retroKeyPrefix string
|
||||
retroValue string
|
||||
id *uint32
|
||||
id *uint16
|
||||
errWrapped error
|
||||
errMessage string
|
||||
}{
|
||||
"empty string": {
|
||||
keyPrefix: "ID",
|
||||
retroKeyPrefix: "RETRO_ID",
|
||||
},
|
||||
"invalid string": {
|
||||
keyPrefix: "ID",
|
||||
keyValue: "invalid",
|
||||
retroKeyPrefix: "RETRO_ID",
|
||||
errWrapped: ErrSystemIDNotValid,
|
||||
errMessage: `environment variable IDTest_Reader_readID/invalid_string: ` +
|
||||
`system ID is not valid: ` +
|
||||
`strconv.ParseUint: parsing "invalid": invalid syntax`,
|
||||
},
|
||||
"negative number": {
|
||||
keyPrefix: "ID",
|
||||
keyValue: "-1",
|
||||
retroKeyPrefix: "RETRO_ID",
|
||||
errWrapped: ErrSystemIDNotValid,
|
||||
errMessage: `environment variable IDTest_Reader_readID/negative_number: ` +
|
||||
`system ID is not valid: ` +
|
||||
`strconv.ParseUint: parsing "-1": invalid syntax`,
|
||||
},
|
||||
"id 1000": {
|
||||
keyPrefix: "ID",
|
||||
keyValue: "1000",
|
||||
retroKeyPrefix: "RETRO_ID",
|
||||
id: uint32Ptr(1000),
|
||||
},
|
||||
"max id": {
|
||||
keyPrefix: "ID",
|
||||
keyValue: "4294967295",
|
||||
retroKeyPrefix: "RETRO_ID",
|
||||
id: uint32Ptr(4294967295),
|
||||
},
|
||||
"above max id": {
|
||||
keyPrefix: "ID",
|
||||
keyValue: "4294967296",
|
||||
retroKeyPrefix: "RETRO_ID",
|
||||
errWrapped: ErrSystemIDNotValid,
|
||||
errMessage: `environment variable IDTest_Reader_readID/above_max_id: ` +
|
||||
`system ID is not valid: 4294967296: must be between 0 and 4294967295`,
|
||||
id: uint16Ptr(1000),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
20
internal/configuration/sources/env/updater.go
vendored
20
internal/configuration/sources/env/updater.go
vendored
@@ -2,9 +2,12 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func readUpdater() (updater settings.Updater, err error) {
|
||||
@@ -18,18 +21,19 @@ func readUpdater() (updater settings.Updater, err error) {
|
||||
return updater, err
|
||||
}
|
||||
|
||||
updater.MinRatio, err = envToFloat64("UPDATER_MIN_RATIO")
|
||||
if err != nil {
|
||||
return updater, fmt.Errorf("environment variable UPDATER_MIN_RATIO: %w", err)
|
||||
// TODO use current provider being used
|
||||
for _, provider := range constants.AllProviders() {
|
||||
if provider == constants.Custom {
|
||||
continue
|
||||
}
|
||||
updater.Providers = append(updater.Providers, provider)
|
||||
}
|
||||
|
||||
updater.Providers = envToCSV("UPDATER_VPN_SERVICE_PROVIDERS")
|
||||
|
||||
return updater, nil
|
||||
}
|
||||
|
||||
func readUpdaterPeriod() (period *time.Duration, err error) {
|
||||
s := getCleanedEnv("UPDATER_PERIOD")
|
||||
s := os.Getenv("UPDATER_PERIOD")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
@@ -41,11 +45,11 @@ func readUpdaterPeriod() (period *time.Duration, err error) {
|
||||
return period, nil
|
||||
}
|
||||
|
||||
func readUpdaterDNSAddress() (address string, err error) {
|
||||
func readUpdaterDNSAddress() (ip net.IP, err error) {
|
||||
// TODO this is currently using Cloudflare in
|
||||
// plaintext to not be blocked by DNS over TLS by default.
|
||||
// If a plaintext address is set in the DNS settings, this one will be used.
|
||||
// use custom future encrypted DNS written in Go without blocking
|
||||
// as it's too much trouble to start another parallel unbound instance for now.
|
||||
return "", nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/binary"
|
||||
@@ -17,7 +18,7 @@ func readVersion() (version settings.Version, err error) {
|
||||
}
|
||||
|
||||
func readVersionEnabled() (enabled *bool, err error) {
|
||||
s := getCleanedEnv("VERSION_INFORMATION")
|
||||
s := os.Getenv("VERSION_INFORMATION")
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
11
internal/configuration/sources/env/vpn.go
vendored
11
internal/configuration/sources/env/vpn.go
vendored
@@ -2,27 +2,28 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
func (r *Reader) readVPN() (vpn settings.VPN, err error) {
|
||||
vpn.Type = strings.ToLower(getCleanedEnv("VPN_TYPE"))
|
||||
vpn.Type = strings.ToLower(os.Getenv("VPN_TYPE"))
|
||||
|
||||
vpn.Provider, err = r.readProvider(vpn.Type)
|
||||
if err != nil {
|
||||
return vpn, fmt.Errorf("VPN provider: %w", err)
|
||||
return vpn, fmt.Errorf("cannot read provider settings: %w", err)
|
||||
}
|
||||
|
||||
vpn.OpenVPN, err = r.readOpenVPN()
|
||||
if err != nil {
|
||||
return vpn, fmt.Errorf("OpenVPN: %w", err)
|
||||
return vpn, fmt.Errorf("cannot read OpenVPN settings: %w", err)
|
||||
}
|
||||
|
||||
vpn.Wireguard, err = r.readWireguard()
|
||||
vpn.Wireguard, err = readWireguard()
|
||||
if err != nil {
|
||||
return vpn, fmt.Errorf("wireguard: %w", err)
|
||||
return vpn, fmt.Errorf("cannot read Wireguard settings: %w", err)
|
||||
}
|
||||
|
||||
return vpn, nil
|
||||
|
||||
13
internal/configuration/sources/env/wireguard.go
vendored
13
internal/configuration/sources/env/wireguard.go
vendored
@@ -3,27 +3,28 @@ package env
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
func (r *Reader) readWireguard() (wireguard settings.Wireguard, err error) {
|
||||
func readWireguard() (wireguard settings.Wireguard, err error) {
|
||||
defer func() {
|
||||
err = unsetEnvKeys([]string{"WIREGUARD_PRIVATE_KEY", "WIREGUARD_PRESHARED_KEY"}, err)
|
||||
}()
|
||||
wireguard.PrivateKey = envToStringPtr("WIREGUARD_PRIVATE_KEY")
|
||||
wireguard.PreSharedKey = envToStringPtr("WIREGUARD_PRESHARED_KEY")
|
||||
_, wireguard.Interface = r.getEnvWithRetro("VPN_INTERFACE", "WIREGUARD_INTERFACE")
|
||||
wireguard.Addresses, err = r.readWireguardAddresses()
|
||||
wireguard.Interface = os.Getenv("WIREGUARD_INTERFACE")
|
||||
wireguard.Addresses, err = readWireguardAddresses()
|
||||
if err != nil {
|
||||
return wireguard, err // already wrapped
|
||||
}
|
||||
return wireguard, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readWireguardAddresses() (addresses []net.IPNet, err error) {
|
||||
key, addressesCSV := r.getEnvWithRetro("WIREGUARD_ADDRESSES", "WIREGUARD_ADDRESS")
|
||||
func readWireguardAddresses() (addresses []net.IPNet, err error) {
|
||||
addressesCSV := os.Getenv("WIREGUARD_ADDRESS")
|
||||
if addressesCSV == "" {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -33,7 +34,7 @@ func (r *Reader) readWireguardAddresses() (addresses []net.IPNet, err error) {
|
||||
for i, addressString := range addressStrings {
|
||||
ip, ipNet, err := net.ParseCIDR(addressString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
return nil, fmt.Errorf("environment variable WIREGUARD_ADDRESS: %w", err)
|
||||
}
|
||||
ipNet.IP = ip
|
||||
addresses[i] = *ipNet
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/govalid/port"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
|
||||
func (r *Reader) readWireguardSelection() (
|
||||
selection settings.WireguardSelection, err error) {
|
||||
selection.EndpointIP, err = r.readWireguardEndpointIP()
|
||||
selection.EndpointIP, err = readWireguardEndpointIP()
|
||||
if err != nil {
|
||||
return selection, err
|
||||
}
|
||||
@@ -21,32 +22,37 @@ func (r *Reader) readWireguardSelection() (
|
||||
return selection, err
|
||||
}
|
||||
|
||||
selection.PublicKey = getCleanedEnv("WIREGUARD_PUBLIC_KEY")
|
||||
selection.PublicKey = os.Getenv("WIREGUARD_PUBLIC_KEY")
|
||||
|
||||
return selection, nil
|
||||
}
|
||||
|
||||
var ErrIPAddressParse = errors.New("cannot parse IP address")
|
||||
|
||||
func (r *Reader) readWireguardEndpointIP() (endpointIP net.IP, err error) {
|
||||
key, s := r.getEnvWithRetro("VPN_ENDPOINT_IP", "WIREGUARD_ENDPOINT_IP")
|
||||
func readWireguardEndpointIP() (endpointIP net.IP, err error) {
|
||||
s := os.Getenv("WIREGUARD_ENDPOINT_IP")
|
||||
if s == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
endpointIP = net.ParseIP(s)
|
||||
if endpointIP == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s",
|
||||
key, ErrIPAddressParse, s)
|
||||
return nil, fmt.Errorf("environment variable WIREGUARD_ENDPOINT_IP: %w: %s",
|
||||
ErrIPAddressParse, s)
|
||||
}
|
||||
|
||||
return endpointIP, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readWireguardCustomPort() (customPort *uint16, err error) {
|
||||
key, s := r.getEnvWithRetro("VPN_ENDPOINT_PORT", "WIREGUARD_ENDPOINT_PORT")
|
||||
key := "WIREGUARD_ENDPOINT_PORT"
|
||||
s := os.Getenv(key)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
// Retro-compatibility
|
||||
key = "WIREGUARD_PORT"
|
||||
s = os.Getenv(key)
|
||||
if s == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
r.onRetroActive("WIREGUARD_PORT", "WIREGUARD_ENDPOINT_PORT")
|
||||
}
|
||||
|
||||
customPort = new(uint16)
|
||||
|
||||
@@ -4,24 +4,18 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
const (
|
||||
// OpenVPNClientKeyPath is the OpenVPN client key filepath.
|
||||
OpenVPNClientKeyPath = "/gluetun/client.key"
|
||||
// OpenVPNClientCertificatePath is the OpenVPN client certificate filepath.
|
||||
OpenVPNClientCertificatePath = "/gluetun/client.crt"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func (r *Reader) readOpenVPN() (settings settings.OpenVPN, err error) {
|
||||
settings.ClientKey, err = ReadFromFile(OpenVPNClientKeyPath)
|
||||
settings.ClientKey, err = ReadFromFile(constants.ClientKey)
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("client key: %w", err)
|
||||
return settings, fmt.Errorf("cannot read client key: %w", err)
|
||||
}
|
||||
|
||||
settings.ClientCrt, err = ReadFromFile(OpenVPNClientCertificatePath)
|
||||
settings.ClientCrt, err = ReadFromFile(constants.ClientCertificate)
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("client certificate: %w", err)
|
||||
return settings, fmt.Errorf("cannot read client certificate: %w", err)
|
||||
}
|
||||
|
||||
return settings, nil
|
||||
|
||||
@@ -13,8 +13,6 @@ func New() *Reader {
|
||||
return &Reader{}
|
||||
}
|
||||
|
||||
func (r *Reader) String() string { return "files" }
|
||||
|
||||
func (r *Reader) Read() (settings settings.Settings, err error) {
|
||||
settings.VPN, err = r.readVPN()
|
||||
if err != nil {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func (r *Reader) readVPN() (vpn settings.VPN, err error) {
|
||||
vpn.OpenVPN, err = r.readOpenVPN()
|
||||
if err != nil {
|
||||
return vpn, fmt.Errorf("OpenVPN: %w", err)
|
||||
return vpn, fmt.Errorf("cannot read OpenVPN settings: %w", err)
|
||||
}
|
||||
|
||||
return vpn, nil
|
||||
|
||||
@@ -2,7 +2,6 @@ package mux
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/configuration/sources"
|
||||
@@ -20,14 +19,6 @@ func New(sources ...sources.Source) *Reader {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reader) String() string {
|
||||
sources := make([]string, len(r.sources))
|
||||
for i := range r.sources {
|
||||
sources[i] = r.sources[i].String()
|
||||
}
|
||||
return strings.Join(sources, ", ")
|
||||
}
|
||||
|
||||
// Read reads the settings for each source, merging unset fields
|
||||
// with field set by the next source.
|
||||
// It then set defaults to remaining unset fields.
|
||||
@@ -35,7 +26,7 @@ func (r *Reader) Read() (settings settings.Settings, err error) {
|
||||
for _, source := range r.sources {
|
||||
settingsFromSource, err := source.Read()
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("reading from %s: %w", source, err)
|
||||
return settings, fmt.Errorf("cannot read from source %T: %w", source, err)
|
||||
}
|
||||
settings.MergeWith(settingsFromSource)
|
||||
}
|
||||
@@ -51,7 +42,7 @@ func (r *Reader) ReadHealth() (settings settings.Health, err error) {
|
||||
for _, source := range r.sources {
|
||||
settingsFromSource, err := source.ReadHealth()
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("reading from %s: %w", source, err)
|
||||
return settings, fmt.Errorf("cannot read from source %T: %w", source, err)
|
||||
}
|
||||
settings.MergeWith(settingsFromSource)
|
||||
}
|
||||
|
||||
@@ -2,24 +2,13 @@ package secrets
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
||||
)
|
||||
|
||||
// getCleanedEnv returns an environment variable value with
|
||||
// surrounding spaces and trailing new line characters removed.
|
||||
func getCleanedEnv(envKey string) (value string) {
|
||||
value = os.Getenv(envKey)
|
||||
value = strings.TrimSpace(value)
|
||||
value = strings.TrimSuffix(value, "\r\n")
|
||||
value = strings.TrimSuffix(value, "\n")
|
||||
return value
|
||||
}
|
||||
|
||||
func readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath string) (
|
||||
stringPtr *string, err error) {
|
||||
path := getCleanedEnv(secretPathEnvKey)
|
||||
path := os.Getenv(secretPathEnvKey)
|
||||
if path == "" {
|
||||
path = defaultSecretPath
|
||||
}
|
||||
@@ -28,7 +17,7 @@ func readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath string) (
|
||||
|
||||
func readSecretFileAsString(secretPathEnvKey, defaultSecretPath string) (
|
||||
s string, err error) {
|
||||
path := getCleanedEnv(secretPathEnvKey)
|
||||
path := os.Getenv(secretPathEnvKey)
|
||||
if path == "" {
|
||||
path = defaultSecretPath
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ func New() *Reader {
|
||||
return &Reader{}
|
||||
}
|
||||
|
||||
func (r *Reader) String() string { return "secret files" }
|
||||
|
||||
func (r *Reader) Read() (settings settings.Settings, err error) {
|
||||
settings.VPN, err = readVPN()
|
||||
if err != nil {
|
||||
|
||||
@@ -5,5 +5,4 @@ import "github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
type Source interface {
|
||||
Read() (settings settings.Settings, err error)
|
||||
ReadHealth() (settings settings.Health, err error)
|
||||
String() string
|
||||
}
|
||||
|
||||
25
internal/constants/constants.go
Normal file
25
internal/constants/constants.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Package constants defines constants shared throughout the program.
|
||||
// It also defines constant maps and slices using functions.
|
||||
package constants
|
||||
|
||||
import "sort"
|
||||
|
||||
func makeChoicesUnique(choices []string) []string {
|
||||
uniqueChoices := map[string]struct{}{}
|
||||
for _, choice := range choices {
|
||||
uniqueChoices[choice] = struct{}{}
|
||||
}
|
||||
|
||||
uniqueChoicesSlice := make([]string, len(uniqueChoices))
|
||||
i := 0
|
||||
for choice := range uniqueChoices {
|
||||
uniqueChoicesSlice[i] = choice
|
||||
i++
|
||||
}
|
||||
|
||||
sort.Slice(uniqueChoicesSlice, func(i, j int) bool {
|
||||
return uniqueChoicesSlice[i] < uniqueChoicesSlice[j]
|
||||
})
|
||||
|
||||
return uniqueChoicesSlice
|
||||
}
|
||||
26
internal/constants/cyberghost.go
Normal file
26
internal/constants/cyberghost.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
CyberghostCertificate = "MIIGWjCCBEKgAwIBAgIJAJxUG61mxDS7MA0GCSqGSIb3DQEBDQUAMHsxCzAJBgNVBAYTAlJPMRIwEAYDVQQHEwlCdWNoYXJlc3QxGDAWBgNVBAoTD0N5YmVyR2hvc3QgUy5BLjEbMBkGA1UEAxMSQ3liZXJHaG9zdCBSb290IENBMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGN5YmVyZ2hvc3Qucm8wHhcNMTcwNjE5MDgxNzI1WhcNMzcwNjE0MDgxNzI1WjB7MQswCQYDVQQGEwJSTzESMBAGA1UEBxMJQnVjaGFyZXN0MRgwFgYDVQQKEw9DeWJlckdob3N0IFMuQS4xGzAZBgNVBAMTEkN5YmVyR2hvc3QgUm9vdCBDQTEhMB8GCSqGSIb3DQEJARYSaW5mb0BjeWJlcmdob3N0LnJvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA7O8+mji2FlQhJXn/G4VLrKPjGtxgQBAdjo0dZEQzKX08q14dLkslmOLgShStWKrOiLXGAvB1rPvvk613jtA0KjQLpgyLy9lIWohQKYjj5jrJYXMZMkbSHBYI9L8L7iezBEFYrjYKdDo51nq99wRFhKdbyKKjDh3e2L2SVEZLT1ogkK5gWzjvH+mjjtjUUicK+YjGwWOz6I+KKaG4Ve/D/cE6nCLbhHIMMnargZEu7sqA6BFeS4kEP/ZdCZoTSX2n43XV1q63nJt/v0KDetbZDciFVW9h9SVPG4qT44p0550N+Mom7zTX7S/ID5T9dplgU8sRGtIMrG0cIMD9zmpFgUnMusCrR7jJFr0sMAveTbgZg95LmstV6R6WKZkSFdUrE0DHl4dHoZvTFX+1LhwhH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vU37E9bdAXwP5nZriYq1s0D59Qfvz+vLXVkmyZp6ztxjKjKolemPMak0Y5c1Q4RjNF6tmQoFuy/ACSkWy14Tzu2dFp7UiVbGg1FOvKhfs48zC2/IUQv1arqmPT/9LVq3B2DVT9UKXRUXX/f/jSSsVjkz4uUe2jUyL+XHX1nSmROTPHSAJ+oKf0BLnfqUxFkEUTwLnayssP2nwGgq35b7wEbTFIXdrjHGFUVQIDeERz8UThew=="
|
||||
)
|
||||
|
||||
func CyberghostCountryChoices(servers []models.CyberghostServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func CyberghostHostnameChoices(servers []models.CyberghostServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
37
internal/constants/expressvpn.go
Normal file
37
internal/constants/expressvpn.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
ExpressvpnCert = "MIIDTjCCAregAwIBAgIDKzZvMA0GCSqGSIb3DQEBCwUAMIGFMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTATBgNVBAcTDFNhbkZyYW5jaXNjbzEVMBMGA1UEChMMRm9ydC1GdW5zdG9uMRgwFgYDVQQDEw9Gb3J0LUZ1bnN0b24gQ0ExITAfBgkqhkiG9w0BCQEWEm1lQG15aG9zdC5teWRvbWFpbjAgFw0xNjExMDMwMzA2MThaGA8yMDY2MTEwMzAzMDYxOFowgYoxCzAJBgNVBAYTAlZHMQwwCgYDVQQIDANCVkkxEzARBgNVBAoMCkV4cHJlc3NWUE4xEzARBgNVBAsMCkV4cHJlc3NWUE4xHDAaBgNVBAMME2V4cH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O1vjAbahwx8LZ0SvQPMBhYSDbV/Isr+fBacWjl/AipEEwxeQKBgQDdrAEnVlOFoCLw4sUjsPoxkLjhTAgI7CYk5NNxX67Rnj0tp+Y49+sGUhl5sCGfMKkLShiON5P2oxZa+B0aPtQjsdnsFPa1uaZkK4c++SS6AetzYRpVDLmLp7/1CulE0z3O0sBekpwiuaqLJ9ZccC81g4+2j8j6c50rIAct3hxIxw=="
|
||||
ExpressvpnTLSAuthOpenvpnStaticKeyV1 = "48d9999bd71095b10649c7cb471c1051b1afdece597cea06909b99303a18c67401597b12c04a787e98cdb619ee960d90a0165529dc650f3a5c6fbe77c91c137dcf55d863fcbe314df5f0b45dbe974d9bde33ef5b4803c3985531c6c23ca6906d6cd028efc8585d1b9e71003566bd7891b9cc9212bcba510109922eed87f5c8e66d8e59cbd82575261f02777372b2cd4ca5214c4a6513ff26dd568f574fd40d6cd450fc788160ff68434ce2bf6afb00e710a3198538f14c4d45d84ab42637872e778a6b35a124e700920879f1d003ba93dccdb953cdf32bea03f365760b0ed8002098d4ce20d045b45a83a8432cc737677aed27125592a7148d25c87fdbe0a3f6"
|
||||
ExpressvpnCA = "MIIF+DCCA+CgAwIBAgIBATANBgkqhkiG9w0BAQ0FADCBhDELMAkGA1UEBhMCVkcxDDAKBgNVBAgMA0JWSTETMBEGA1UECgwKRXhwcmVzc1ZQTjETMBEGA1UECwwKRXhwcmVzc1ZQTjEWMBQGA1UEAwwNRXhwcmVzc1ZQTiBDQTElMCMGCSqGSIb3DQEJARYWc3VwcG9ydEBleHByZXNzdnBuLmNvbTAeFw0xNTEwMjEwMDAwMDBaFw0yNjA0MDEyMTEyMDBaMIGEMQswCQYDVQQGEwJWRzEMMAoGA1UECAwDQlZJMRMwEQYDVQQKDApFeHByZXNzVlBOMRMwEQYDVQQLDApFeHByZXNzVlBOMRYwFAYDVQQDDA1FeHByZXNzVlBOIENBMSUwIwYJKoZIhvcNAQkBFhZzdXBwb3J0QGV4cHJlc3N2cG4uY29tMIICIj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l1fJDDgXal5f1UT5F5WH6/RwHmWTwX4GxuCiIVtx70CjkXqhM8yZtTp1UtHLRNYcNSIes0vrAPHPgoA5z9B8UvsOjuP+mfcjzi0LGGrY+2pJu0BKO2dRnarIZZABETIisI3FokoTszx5jpRPyxyUTuRDKWHrvi0PPtOmC8nFahfugWFUi6uBsqCaSeuex+ahnTPCq0b1l0Ozpg0YeE8CW1TL9Y92b01up2c+PP6wZOIm3JyTH+L5smDFbh80V42dKyGNdPXMg5IcJhj3YfAy4k8h/qbWY57KFcIzKx40bFsoI7PeydbGtT/dIoFLSZRLW5bleXNgG9mXZp270UeEC6CpATCS6uVl8LVT1I02uulHUpFaRmTEOrmMxsXGt6UAwYTY55K/B8uuID341xKbeC0kzhuN2gsL5UJaocBHyWK/AqwbeBttdhOCLwoaj7+nSViPxICObKrg3qavGNCvtwy/fEegK9X/wlp2e2CFlIhFbadeXOBr9Fn8ypYPP17mTqe98OJYM04="
|
||||
)
|
||||
|
||||
func ExpressvpnCountriesChoices(servers []models.ExpressvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ExpressvpnCityChoices(servers []models.ExpressvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func ExpressvpnHostnameChoices(servers []models.ExpressvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
27
internal/constants/fastestvpn.go
Normal file
27
internal/constants/fastestvpn.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||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DwEB/wQEAwIBBjAdBgNVHQ4EFgQUmVEL4x6xdCqiqu2OBLs27EA8xGYwDQYJKoZIhvcNAQEMBQADggIBABCpITvO1+R4T9v2+onHiFxU5JjtCZ0zkXqRCMp/Z0UIYbeo1p07pZCPAUjBfGPCkAaR++OiG9sysALdJf8Y6HQKcyuAcWUqQnaIhoZ2JcAP7EKq7uCqsMhcYZD/j3O/3RPtSW5UOx6ItDU+Ua0t9Edho9whNw0VQXmo1JjYoP3FzPjuKoDWTSO1q5eYlZfwcTcs55O2shNkFafPg/6cCm5j6v9nyHrM3sk4LjkrBPUXVx2m/aoz219t8O9Ha9/CdMKXsPO/8gTUzpgnzSgPnGnBmi5xr1nspVN8X4E2f3D+DKqBim3YgslD68NcuFQvJ0/BxZzWVbrr+QXoyzaiCgXuogpIDc2bB6oRXqFnHNz36d4QJmJdWdSaijiS/peQ6EOPgOZ1GuObLWlDCBZLNeQ+N6QaiJxVO4XUj/s22i1IRtwdz84TRHrbWiIpEymsqmb/Ep5r4xV5d6+791axclfOTH7tQrY/SbPtTJI4OEgNekI8YfadQifpelF82MsFFEZuaQn0lj+fvLGtE/zKh3OdLTxRc5TAgBB+0T81+JQosygNr2aFFG0hxar1eyw/gLeG8H+7Ie50pyPvXO4OgB6Key8rSExpilQXlvAT1qX0qS3/K1i/9QkSE9ftIPT6vtwLV2sVQzfyanI4IZgWC6ryhvNLsRn0NFnQclor0+aq"
|
||||
FastestvpnOpenvpnStaticKeyV1 = "697fe793b32cb5091d30f2326d5d124a9412e93d0a44ef7361395d76528fcbfc82c3859dccea70a93cfa8fae409709bff75f844cf5ff0c237f426d0c20969233db0e706edb6bdf195ec3dc11b3f76bc807a77e74662d9a800c8cd1144ebb67b7f0d3f1281d1baf522bfe03b7c3f963b1364fc0769400e413b61ca7b43ab19fac9e0f77e41efd4bda7fd77b1de2d7d7855cbbe3e620cecceac72c21a825b243e651f44d90e290e09c3ad650de8fca99c858bc7caad584bc69b11e5c9fd9381c69c505ec487a65912c672d83ed0113b5a74ddfbd3ab33b3683cec593557520a72c4d6cce46111f56f3396cc3ce7183edce553c68ea0796cf6c4375fad00aaa2a42"
|
||||
)
|
||||
|
||||
func FastestvpnCountriesChoices(servers []models.FastestvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func FastestvpnHostnameChoices(servers []models.FastestvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
44
internal/constants/hidemyass.go
Normal file
44
internal/constants/hidemyass.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
HideMyAssCA = "MIIGVjCCBD6gAwIBAgIJAOmTY3hf1Bb6MA0GCSqGSIb3DQEBCwUAMIGSMQswCQYDVQQGEwJVSzEPMA0GA1UECAwGTG9uZG9uMQ8wDQYDVQQHDAZMb25kb24xEzARBgNVBAoMClByaXZheCBMdGQxFDASBgNVBAsMC0hNQSBQcm8gVlBOMRYwFAYDVQQDDA1oaWRlbXlhc3MuY29tMR4wHAYJKoZIhvcNAQkBFg9pbmZvQHByaXZheC5jb20wHhcNMTYwOTE0MDk0MTUyWhcNMjYwOTEyMDk0MTUyWjCBkjELMAkGA1UEBhMCVUsxDzANBgNVBAgMBkxvbmRvbjEPMA0GA1UEBwwGTG9uZG9uMRMwEQYDVQQKDApQcml2YXggTHRkMRQwEgYDVQQLDAtITUEgUHJvIFZQTjEWMBQGA1UEAwwNaGlkZW15YXNzLmNvbTEeMBwGCSqGSIb3DQEJARYPaW5mb0Bwcml2YXguY29tMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxWS4+bOnwzGsEZ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|
||||
|
||||
func HideMyAssCountryChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func HideMyAssRegionChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func HideMyAssCityChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func HideMyAssHostnameChoices(servers []models.HideMyAssServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
34
internal/constants/ipvanish.go
Normal file
34
internal/constants/ipvanish.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
IpvanishCA = "MIIErTCCA5WgAwIBAgIJAMYKzSS8uPKDMA0GCSqGSIb3DQEBDQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCRkwxFDASBgNVBAcTC1dpbnRlciBQYXJrMREwDwYDVQQKEwhJUFZhbmlzaDEVMBMGA1UECxMMSVBWYW5pc2ggVlBOMRQwEgYDVQQDEwtJUFZhbmlzaCBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBpcHZhbmlzaC5jb20wHhcNMTIwMTExMTkzMjIwWhcNMjgxMTAyMTkzMjIwWjCBlTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkZMMRQwEgYDVQQHEwtXaW50ZXIgUGFyazERMA8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yKLjN2jtwH6XowUNYpg4qVtKU0CXPdOznWcd9/zSfa393HwJPeeVLbKYaFMC4IEbIUmKYtWyoJ9pJ58smU3pWsHZUg9Zc0LZZNjkNlBdQSLmUHAJ33Bd7pJS0JQeiWviC+4UTmzEWRKa7pDGnYRYNu2cUo0/voStphv8EVA=="
|
||||
)
|
||||
|
||||
func IpvanishCountryChoices(servers []models.IpvanishServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IpvanishCityChoices(servers []models.IpvanishServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IpvanishHostnameChoices(servers []models.IpvanishServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
43
internal/constants/ivpn.go
Normal file
43
internal/constants/ivpn.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
IvpnCA = "MIIGoDCCBIigAwIBAgIJAJjvUclXmxtnMA0GCSqGSIb3DQEBCwUAMIGMMQswCQYDVQQGEwJDSDEPMA0GA1UECAwGWnVyaWNoMQ8wDQYDVQQHDAZadXJpY2gxETAPBgNVBAoMCElWUE4ubmV0MQ0wCwYDVQQLDARJVlBOMRgwFgYDVQQDDA9JVlBOIFJvb3QgQ0EgdjIxHzAdBgkqhkiG9w0BCQEWEHN1cHBvcnRAaXZwbi5uZXQwHhcNMjAwMjI2MTA1MjI5WhcNNDAwMjIxMTA1MjI5WjCBjDELMAkGA1UEBhMCQ0gxDzANBgNVBAgMBlp1cmlja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wCwYDVQQLDARJVlBOMRgwFgYDVQQDDA9JVlBOIFJvb3QgQ0EgdjIxHzAdBgkqhkiG9w0BCQEWEHN1cHBvcnRAaXZwbi5uZXSCCQCY71HJV5sbZzAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAgEAABAjRMJy+mXFLezAZ8iUgxOjNtSqkCv1aU78K1XkYUzbwNNrSIVGKfP9cqOEiComXY6nniws7QEV2IWilcdPKm0x57recrr9TExGGOTVGB/WdmsFfn0g/HgmxNvXypzG3qulBk4qQTymICdsl9vIPb1l9FSjKw1KgUVuCPaYq7xiXbZ/kZdZX49xeKtoDBrXKKhXVYoWus/S+k2IS8iCxvcp599y7LQJg5DOGlbaxFhsW4R+kfGOaegyhPvpaznguv02i7NLd99XqJhpv2jTUF5F3T23Z4KkL/wTo4zxz09DKOlELrE4ai++ilCt/mXWECXNOSNXzgszpe6WAs0h9R++sH+AzJyhBfIGgPUTxHHHvxBVLj3k6VCgF7mRP2Y+rTWa6d8AGI2+RaeyV9DVVH9UeSoU0Hv2JHiZL6dRERnyg8dyzKeTCke8poLIjXF+gyvI+22/xsL8jcNHi9Kji3Vpc3i0Mxzx3gu2N+PL71CwJilgqBgxj0firr3k8sFcWVSGos6RJ3IvFvThxYx0p255WrWM01fR9TktPYEfjDT9qpIJ8OrGlNOhWhYj+a45qibXDpaDdb/uBEmf2sSXNifjSeUyqu6cKfZvMqB7pS3l/AhuAOTT80E4sXLEoDxkFD4C78swZ8wyWRKwsWGIGABGAHwXEAoDiZ/jjFrEZT0="
|
||||
IvpnOpenvpnStaticKeyV1 = "ac470c93ff9f5602a8aab37dee84a52814d10f20490ad23c47d5d82120c1bf859e93d0696b455d4a1b8d55d40c2685c41ca1d0aef29a3efd27274c4ef09020a3978fe45784b335da6df2d12db97bbb838416515f2a96f04715fd28949c6fe296a925cfada3f8b8928ed7fc963c1563272f5cf46e5e1d9c845d7703ca881497b7e6564a9d1dea9358adffd435295479f47d5298fabf5359613ff5992cb57ff081a04dfb81a26513a6b44a9b5490ad265f8a02384832a59cc3e075ad545461060b7bcab49bac815163cb80983dd51d5b1fd76170ffd904d8291071e96efc3fb777856c717b148d08a510f5687b8a8285dcffe737b98916dd15ef6235dee4266d3b"
|
||||
)
|
||||
|
||||
func IvpnCountryChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IvpnCityChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IvpnISPChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].ISP
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func IvpnHostnameChoices(servers []models.IvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
42
internal/constants/mullvad.go
Normal file
42
internal/constants/mullvad.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
MullvadCertificate = "MIIGIzCCBAugAwIBAgIJAK6BqXN9GHI0MA0GCSqGSIb3DQEBCwUAMIGfMQswCQYDVQQGEwJTRTERMA8GA1UECAwIR290YWxhbmQxEzARBgNVBAcMCkdvdGhlbmJ1cmcxFDASBgNVBAoMC0FtYWdpY29tIEFCMRAwDgYDVQQLDAdNdWxsdmFkMRswGQYDVQQDDBJNdWxsdmFkIFJvb3QgQ0EgdjIxIzAhBgkqhkiG9w0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VR0jBBgwFoAUfaEyaBpGNzsqttiSMETq+X/GJ0YwCwYDVR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBADH5izxu4V8Javal8EA4DxZxIHUsWCg5cuopB28PsyJYpyKipsBoI8+RXqbtrLLue4WQfNPZHLXlKi+A3GTrLdlnenYzXVipPd+n3vRZyofaB3Jtb03nirVWGa8FG21Xy/f4rPqwcW54lxrnnh0SA0hwuZ+b2yAWESBXPxrzVQdTWCqoFI6/aRnN8RyZn0LqRYoW7WDtKpLmfyvshBmmu4PCYSh/SYiFHgR9fsWzVcxdySDsmX8wXowuFfp8V9sFhD4TsebAaplaICOuLUgj+Yin5QzgB0F9Ci3Zh6oWwl64SL/OxxQLpzMWzr0lrWsQrS3PgC4+6JC4IpTXX5eUqfSvHPtbRKK0yLnd9hYgvZUBvvZvUFR/3/fW+mpBHbZJBu9+/1uux46M4rJ2FeaJUf9PhYCPuUj63yu0Grn0DreVKK1SkD5V6qXN0TmoxYyguhfsIPCpI1VsdaSWuNjJ+a/HIlKIU8vKp5iN/+6ZTPAg9Q7s3Ji+vfx/AhFtQyTpIYNszVzNZyobvkiMUlK+eUKGlHVQp73y6MmGIlbBbyzpEoedNU4uFu57mw4fYGHqYZmYqFaiNQv4tVrGkg6p+Ypyu1zOfIHF7eqlAOu/SyRTvZkt9VtSVEOVH7nDIGdrCC9U/g1Lqk8Td00Oj8xesyKzsG214Xd8m7/7GmJ7nXe5"
|
||||
)
|
||||
|
||||
func MullvadCountryChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Country
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func MullvadCityChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].City
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func MullvadHostnameChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func MullvadISPChoices(servers []models.MullvadServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].ISP
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
27
internal/constants/nordvpn.go
Normal file
27
internal/constants/nordvpn.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
const (
|
||||
NordvpnCertificate = "MIIFCjCCAvKgAwIBAgIBATANBgkqhkiG9w0BAQ0FADA5MQswCQYDVQQGEwJQQTEQMA4GA1UEChMHTm9yZFZQTjEYMBYGA1UEAxMPTm9yZFZQTiBSb290IENBMB4XDTE2MDEwMTAwMDAwMFoXDTM1MTIzMTIzNTk1OVowOTELMAkGA1UEBhMCUEExEDAOBgNVBAoTB05vcmRWUE4xGDAWBgNVBAMTD05vcmRWUE4gUm9vdCBDQTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMkr/BYhyo0F2upsIMXwC6QvkZps3NN2/eQFkfQIS1gql0aejsKsEnmY0Kaon8uZCTXPsRH1gQNgg5D2gixdd1mJUvV3dE3y9FJrXMoDkXdCGBodvKJyU6lcfEVF6/UxHcbBguZK9UtRHS9eJYm3rpL/5huQMCppX7kUeQ8dpCwd3iKITqwd1ZudDqsWaU0vqzC2H55IyaZ/5/TnCk31Q1UP6BksbbuRcwOVskEDsm6YoWDnn/IIzGOYnFJRzQH5jTz3j1QBvRIuQuBuvUkfhx1FEwhwZigrcxXuMP+QgM54kezgziJUaZcOM2zF3lvrwMvXDMfNeIoJABv9ljw969xQ8czQCU5lMVmA37ltv5Ec9U5hZuwk/9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OpenvpnStaticKeyV1 = "e685bdaf659a25a200e2b9e39e51ff030fc72cf1ce07232bd8b2be5e6c670143f51e937e670eee09d4f2ea5a6e4e69965db852c275351b86fc4ca892d78ae002d6f70d029bd79c4d1c26cf14e9588033cf639f8a74809f29f72b9d58f9b8f5fefc7938eade40e9fed6cb92184abb2cc10eb1a296df243b251df0643d53724cdb5a92a1d6cb817804c4a9319b57d53be580815bcfcb2df55018cc83fc43bc7ff82d51f9b88364776ee9d12fc85cc7ea5b9741c4f598c485316db066d52db4540e212e1518a9bd4828219e24b20d88f598a196c9de96012090e333519ae18d35099427e7b372d348d352dc4c85e18cd4b93f8a56ddb2e64eb67adfc9b337157ff4"
|
||||
)
|
||||
|
||||
func NordvpnRegionChoices(servers []models.NordvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Region
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
|
||||
func NordvpnHostnameChoices(servers []models.NordvpnServer) (choices []string) {
|
||||
choices = make([]string, len(servers))
|
||||
for i := range servers {
|
||||
choices[i] = servers[i].Hostname
|
||||
}
|
||||
return makeUnique(choices)
|
||||
}
|
||||
16
internal/constants/openvpn.go
Normal file
16
internal/constants/openvpn.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
AES128cbc = "aes-128-cbc"
|
||||
AES256cbc = "aes-256-cbc"
|
||||
AES128gcm = "aes-128-gcm"
|
||||
AES256gcm = "aes-256-gcm"
|
||||
SHA1 = "sha1"
|
||||
SHA256 = "sha256"
|
||||
SHA512 = "sha512"
|
||||
)
|
||||
|
||||
const (
|
||||
Openvpn24 = "2.4"
|
||||
Openvpn25 = "2.5"
|
||||
)
|
||||
@@ -1,7 +0,0 @@
|
||||
package openvpn
|
||||
|
||||
const (
|
||||
SHA1 = "sha1"
|
||||
SHA256 = "sha256"
|
||||
SHA512 = "sha512"
|
||||
)
|
||||
@@ -1,8 +0,0 @@
|
||||
package openvpn
|
||||
|
||||
const (
|
||||
AES128cbc = "aes-128-cbc"
|
||||
AES256cbc = "aes-256-cbc"
|
||||
AES128gcm = "aes-128-gcm"
|
||||
AES256gcm = "aes-256-gcm"
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
package openvpn
|
||||
|
||||
const (
|
||||
// AuthConf is the file path to the OpenVPN auth file.
|
||||
AuthConf = "/etc/openvpn/auth.conf"
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
package openvpn
|
||||
|
||||
const (
|
||||
Openvpn24 = "2.4"
|
||||
Openvpn25 = "2.5"
|
||||
)
|
||||
@@ -1,6 +1,30 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
// UnboundConf is the file path to the Unbound configuration file.
|
||||
UnboundConf string = "/etc/unbound/unbound.conf"
|
||||
// ResolvConf is the file path to the system resolv.conf file.
|
||||
ResolvConf string = "/etc/resolv.conf"
|
||||
// CACertificates is the file path to the CA certificates file.
|
||||
CACertificates string = "/etc/ssl/certs/ca-certificates.crt"
|
||||
// OpenVPNAuthConf is the file path to the OpenVPN auth file.
|
||||
OpenVPNAuthConf string = "/etc/openvpn/auth.conf"
|
||||
// OpenVPNConf is the file path to the OpenVPN client configuration file.
|
||||
OpenVPNConf string = "/etc/openvpn/target.ovpn"
|
||||
// PIAPortForward is the file path to the port forwarding JSON information for PIA servers.
|
||||
PIAPortForward string = "/gluetun/piaportforward.json"
|
||||
// TunnelDevice is the file path to tun device.
|
||||
TunnelDevice string = "/dev/net/tun"
|
||||
// NetRoute is the path to the file containing information on the network route.
|
||||
NetRoute string = "/proc/net/route"
|
||||
// RootHints is the filepath to the root.hints file used by Unbound.
|
||||
RootHints string = "/etc/unbound/root.hints"
|
||||
// RootKey is the filepath to the root.key file used by Unbound.
|
||||
RootKey string = "/etc/unbound/root.key"
|
||||
// ClientKey is the client key filepath.
|
||||
ClientKey string = "/gluetun/client.key"
|
||||
// ClientCertificate is the client certificate filepath.
|
||||
ClientCertificate string = "/gluetun/client.crt"
|
||||
// ServersData is the server information filepath.
|
||||
ServersData = "/gluetun/servers.json"
|
||||
)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user