Update rtorrent
and privoxy
to proton community cli
This commit is contained in:
parent
a335b5aaef
commit
4f11e64205
3 changed files with 91 additions and 91 deletions
|
@ -58,7 +58,11 @@ services:
|
||||||
LOG_HTML: "false"
|
LOG_HTML: "false"
|
||||||
CAPTCHA_SOLVER: none
|
CAPTCHA_SOLVER: none
|
||||||
privoxy:
|
privoxy:
|
||||||
image: walt3rl/proton-privoxy
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile_inline: |
|
||||||
|
FROM walt3rl/proton-privoxy
|
||||||
|
RUN apk --update add ip6tables
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
|
|
|
@ -1,25 +1,36 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from os import environ
|
from os import chmod, environ
|
||||||
from os.path import dirname
|
from os.path import dirname
|
||||||
|
from random import choice
|
||||||
from re import M
|
from re import M
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from protonvpn_cli.cli import FeatureEnum, protonvpn
|
from protonvpn_cli import connection
|
||||||
|
from protonvpn_cli.constants import PASSFILE
|
||||||
|
from protonvpn_cli.utils import check_init, get_fastest_server, get_servers, set_config_value, pull_server_data
|
||||||
|
|
||||||
|
|
||||||
def run_proton(args):
|
def run_proton(args):
|
||||||
exit(
|
exit(
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["pipenv", "run", "proton"],
|
["proton"],
|
||||||
cwd="/app",
|
cwd="/app",
|
||||||
env=dict(
|
env=dict(
|
||||||
environ,
|
environ,
|
||||||
PIPENV_VENV_IN_PROJECT=f"{1}",
|
|
||||||
PVPN_CMD_ARGS=" ".join(args))).returncode)
|
PVPN_CMD_ARGS=" ".join(args))).returncode)
|
||||||
|
|
||||||
|
environ["PVPN_USERNAME"] = environ["PVPN_USERNAME"] + (environ["PVPN_TAGS"] or "")
|
||||||
|
|
||||||
protonvpn.ensure_connectivity()
|
with open(PASSFILE, "w") as f:
|
||||||
|
f.write("{0}\n{1}".format(environ["PVPN_USERNAME"], environ["PVPN_PASSWORD"]))
|
||||||
|
chmod(PASSFILE, 0o600)
|
||||||
|
|
||||||
|
check_init()
|
||||||
|
set_config_value("USER", "username", environ["PVPN_USERNAME"])
|
||||||
|
set_config_value("USER", "tier", environ["PVPN_TIER"])
|
||||||
|
set_config_value("USER", "default_protocol", environ["PVPN_PROTOCOL"])
|
||||||
|
set_config_value("USER", "initialized", 1)
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
|
|
||||||
|
@ -29,7 +40,7 @@ if not args:
|
||||||
|
|
||||||
parser = ArgumentParser(exit_on_error=False)
|
parser = ArgumentParser(exit_on_error=False)
|
||||||
subParsers = parser.add_subparsers(dest="command")
|
subParsers = parser.add_subparsers(dest="command")
|
||||||
initParser = subParsers.add_parser("init", alias=["i"])
|
initParser = subParsers.add_parser("init", aliases=["i"])
|
||||||
connectParser = subParsers.add_parser("connect", aliases=["c"])
|
connectParser = subParsers.add_parser("connect", aliases=["c"])
|
||||||
|
|
||||||
for aliases in [
|
for aliases in [
|
||||||
|
@ -50,54 +61,38 @@ try:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if parsedArgs is not None and parsedArgs.command == "init":
|
|
||||||
userName = input("Enter your Proton VPN username or email: ")
|
|
||||||
subprocess.run(["protonvpn-cli", "login", userName])
|
|
||||||
else:
|
|
||||||
session = protonvpn.get_session()
|
|
||||||
try:
|
|
||||||
session.ensure_valid()
|
|
||||||
except:
|
|
||||||
raise Exception(
|
|
||||||
"Your current session is invalid. Please initialize the session using the `init` subcommand.")
|
|
||||||
|
|
||||||
environ["PVPN_USERNAME"] = session.vpn_username + \
|
|
||||||
(environ.get("PVPN_TAGS") or "")
|
|
||||||
environ["PVPN_PASSWORD"] = session.vpn_password
|
|
||||||
environ["PVPN_TIER"] = f"{session.vpn_tier}"
|
|
||||||
|
|
||||||
if parsedArgs is not None and (
|
if parsedArgs is not None and (
|
||||||
len(
|
len(
|
||||||
list(
|
list(
|
||||||
filter(
|
filter(
|
||||||
lambda item: item[1] not in [False, None],
|
lambda item: item[1] not in [False, None],
|
||||||
vars(parsedArgs).items()))) > 1):
|
vars(parsedArgs).items()))) > 1):
|
||||||
country = protonvpn.get_country()
|
|
||||||
|
|
||||||
def match(server):
|
def match(server):
|
||||||
features = list()
|
features = list()
|
||||||
|
|
||||||
if parsedArgs.streaming:
|
if parsedArgs.streaming:
|
||||||
features.append(FeatureEnum.STREAMING)
|
pass
|
||||||
if parsedArgs.sc:
|
if parsedArgs.sc:
|
||||||
features.append(FeatureEnum.SECURE_CORE)
|
pass
|
||||||
if parsedArgs.p2p:
|
if parsedArgs.p2p:
|
||||||
features.append(FeatureEnum.P2P)
|
pass
|
||||||
if parsedArgs.tor:
|
if parsedArgs.tor:
|
||||||
features.append(FeatureEnum.TOR)
|
pass
|
||||||
|
|
||||||
return (parsedArgs.cc is None or server.exit_country.lower() == parsedArgs.cc.lower()) and (
|
return (parsedArgs.cc is None or server.exit_country.lower() == parsedArgs.cc.lower()) and (
|
||||||
all(feature in server.features for feature in features))
|
all(feature in server.features for feature in features))
|
||||||
|
|
||||||
servers = session.servers.filter(match)
|
pull_server_data(force=True)
|
||||||
|
servers = list(filter(lambda server: match(server), get_servers()))
|
||||||
|
|
||||||
if len(servers) > 0:
|
if len(servers) > 0:
|
||||||
if parsedArgs.fastest or not parsedArgs.random:
|
if parsedArgs.fastest or not parsedArgs.random:
|
||||||
server = servers.get_fastest_server()
|
server = get_fastest_server(servers)
|
||||||
else:
|
else:
|
||||||
server = servers.get_random_server()
|
server = choice(servers)
|
||||||
|
|
||||||
run_proton(["connect", server.name])
|
run_proton(["connect", server["Name"]])
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Unable to find a server matching the specified criteria {args[1:]}!")
|
f"Unable to find a server matching the specified criteria {args[1:]}!")
|
||||||
|
|
|
@ -5,8 +5,13 @@ FROM debian
|
||||||
ARG PVPN_CLI_VER=2.2.12
|
ARG PVPN_CLI_VER=2.2.12
|
||||||
ARG USERNAME=proton
|
ARG USERNAME=proton
|
||||||
|
|
||||||
ENV PVPN_TAGS="+pmp" \
|
ENV PVPN_USERNAME= \
|
||||||
|
PVPN_USERNAME_FILE= \
|
||||||
|
PVPN_PASSWORD= \
|
||||||
|
PVPN_PASSWORD_FILE= \
|
||||||
|
PVPN_TIER=2 \
|
||||||
PVPN_PROTOCOL=udp \
|
PVPN_PROTOCOL=udp \
|
||||||
|
PVPN_TAGS="+pmp" \
|
||||||
PVPN_CMD_ARGS="connect --p2p --random" \
|
PVPN_CMD_ARGS="connect --p2p --random" \
|
||||||
PVPN_DEBUG= \
|
PVPN_DEBUG= \
|
||||||
HOST_NETWORK= \
|
HOST_NETWORK= \
|
||||||
|
@ -20,9 +25,28 @@ ENV PVPN_TAGS="+pmp" \
|
||||||
|
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
COPY --from=rtorrent / /
|
COPY --from=rtorrent / /
|
||||||
|
|
||||||
|
RUN apt-get update -y \
|
||||||
|
&& apt-get upgrade -y \
|
||||||
|
&& apt-get install -y \
|
||||||
|
git \
|
||||||
|
iproute2 \
|
||||||
|
iptables \
|
||||||
|
natpmpc \
|
||||||
|
openvpn \
|
||||||
|
pipenv \
|
||||||
|
procps \
|
||||||
|
python3 \
|
||||||
|
python3-pip \
|
||||||
|
python3-setuptools \
|
||||||
|
sudo \
|
||||||
|
&& rm -rf /var/lib/apt/lists
|
||||||
|
|
||||||
|
RUN pip3 install --break-system-packages git+https://github.com/Rafficer/linux-cli-community.git@v$PVPN_CLI_VER#egg=protonvpn-cli
|
||||||
|
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
COPY --from=proton /root/.pvpn-cli /root/.pvpn-cli
|
|
||||||
COPY --from=proton /app/proton-privoxy/run /app/proton
|
COPY --from=proton /app/proton-privoxy/run /app/proton
|
||||||
|
COPY --from=proton /root/.pvpn-cli/pvpn-cli.cfg.clean /root/.pvpn-cli/pvpn-cli.cfg
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
sed -i \
|
sed -i \
|
||||||
|
@ -32,43 +56,7 @@ RUN \
|
||||||
&& install -t /usr/local/bin /app/proton \
|
&& install -t /usr/local/bin /app/proton \
|
||||||
&& rm /app/proton
|
&& rm /app/proton
|
||||||
|
|
||||||
RUN apt-get update -y \
|
|
||||||
&& apt-get upgrade -y \
|
|
||||||
&& apt-get install -y \
|
|
||||||
curl \
|
|
||||||
gnupg \
|
|
||||||
&& curl https://repo.protonvpn.com/debian/dists/stable/main/binary-all/protonvpn-stable-release_1.0.3-3_all.deb -o proton.deb \
|
|
||||||
&& dpkg --install proton.deb \
|
|
||||||
&& apt-get remove -y \
|
|
||||||
curl \
|
|
||||||
&& apt-get update -y \
|
|
||||||
&& apt-get install -y protonvpn-cli \
|
|
||||||
&& rm -rf /var/lib/apt/lists
|
|
||||||
|
|
||||||
RUN apt-get update -y \
|
|
||||||
&& apt-get upgrade -y \
|
|
||||||
&& apt-get install -y \
|
|
||||||
git \
|
|
||||||
iproute2 \
|
|
||||||
iptables \
|
|
||||||
natpmpc \
|
|
||||||
pipenv \
|
|
||||||
python3-setuptools \
|
|
||||||
sudo \
|
|
||||||
&& rm -rf /var/lib/apt/lists
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
cd /app \
|
|
||||||
&& PIPENV_VENV_IN_PROJECT=1 pipenv install git+https://github.com/Rafficer/linux-cli-community.git@v$PVPN_CLI_VER#egg=protonvpn-cli
|
|
||||||
|
|
||||||
RUN printf "%s\n" \
|
RUN printf "%s\n" \
|
||||||
"#!/usr/bin/env -S dbus-run-session -- bash" \
|
|
||||||
"mkdir -p /proton/{keyrings,protonvpn}" \
|
|
||||||
"mkdir -p ~/.local/share" \
|
|
||||||
"mkdir -p ~/.config" \
|
|
||||||
"ln -Ts /proton/keyrings ~/.local/share/keyrings >/dev/null 2>&1" \
|
|
||||||
"ln -Ts /proton/protonvpn ~/.config/protonvpn >/dev/null 2>&1" \
|
|
||||||
"eval \"\$(echo -n 'root' | gnome-keyring-daemon --unlock)\"" \
|
|
||||||
"python3 /app/pvpn-cli.py \"\$@\"" > ./pvpn-cli \
|
"python3 /app/pvpn-cli.py \"\$@\"" > ./pvpn-cli \
|
||||||
&& install -Dm 755 ./pvpn-cli /usr/local/bin \
|
&& install -Dm 755 ./pvpn-cli /usr/local/bin \
|
||||||
&& rm ./pvpn-cli
|
&& rm ./pvpn-cli
|
||||||
|
@ -77,7 +65,20 @@ RUN printf "%s\n" \
|
||||||
"#!/bin/bash" \
|
"#!/bin/bash" \
|
||||||
"groupadd --gid \$PGID ${USERNAME} > /dev/null" \
|
"groupadd --gid \$PGID ${USERNAME} > /dev/null" \
|
||||||
"useradd --create-home --home-dir \$PHOME ${USERNAME} --uid \$PUID -g ${USERNAME} 2>/dev/null" \
|
"useradd --create-home --home-dir \$PHOME ${USERNAME} --uid \$PUID -g ${USERNAME} 2>/dev/null" \
|
||||||
|
"chown ${USERNAME} \$PHOME" \
|
||||||
'[ ! -z "$1" ] && [ "$1" = "init" ] && export PVPN_CMD_ARGS="$@"' \
|
'[ ! -z "$1" ] && [ "$1" = "init" ] && export PVPN_CMD_ARGS="$@"' \
|
||||||
|
'if [ -z "$PVPN_USERNAME" ] && [ -z "$PVPN_USERNAME_FILE" ]; then' \
|
||||||
|
" echo 'Error: Either env var \$PVPN_USERNAME or \$PVPN_USERNAME_FILE is required.'" \
|
||||||
|
"exit 1" \
|
||||||
|
"fi" \
|
||||||
|
"" \
|
||||||
|
'if [ -z "$PVPN_PASSWORD" ] && [ -z "$PVPN_PASSWORD_FILE" ]; then' \
|
||||||
|
"echo 'Error: Either env var \$PVPN_PASSWORD or \$PVPN_PASSWORD_FILE is required.'" \
|
||||||
|
"exit 1" \
|
||||||
|
"fi" \
|
||||||
|
"" \
|
||||||
|
'[ -f "$PVPN_USERNAME_FILE" ] && PVPN_USERNAME=$(cat "$PVPN_USERNAME_FILE")' \
|
||||||
|
'[ -f "$PVPN_PASSWORD_FILE" ] && PVPN_PASSWORD=$(cat "$PVPN_PASSWORD_FILE")' \
|
||||||
"pvpn-cli || exit" \
|
"pvpn-cli || exit" \
|
||||||
'ip link show proton0 > /dev/null 2>&1 || exit' \
|
'ip link show proton0 > /dev/null 2>&1 || exit' \
|
||||||
'fallback="$(expr ${NATPMP_TIMEOUT} \* 3 / 4)"' \
|
'fallback="$(expr ${NATPMP_TIMEOUT} \* 3 / 4)"' \
|
||||||
|
|
Loading…
Reference in a new issue