Update rtorrent and privoxy to proton community cli

This commit is contained in:
Manuel Thalmann 2024-12-04 16:50:29 +01:00
parent a335b5aaef
commit 4f11e64205
3 changed files with 91 additions and 91 deletions

View file

@ -58,7 +58,11 @@ services:
LOG_HTML: "false"
CAPTCHA_SOLVER: none
privoxy:
image: walt3rl/proton-privoxy
build:
context: .
dockerfile_inline: |
FROM walt3rl/proton-privoxy
RUN apk --update add ip6tables
restart: unless-stopped
volumes:
- /etc/localtime:/etc/localtime:ro

View file

@ -1,25 +1,36 @@
from argparse import ArgumentParser
from os import environ
from os import chmod, environ
from os.path import dirname
from random import choice
from re import M
import shlex
import subprocess
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):
exit(
subprocess.run(
["pipenv", "run", "proton"],
["proton"],
cwd="/app",
env=dict(
environ,
PIPENV_VENV_IN_PROJECT=f"{1}",
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:]
@ -29,7 +40,7 @@ if not args:
parser = ArgumentParser(exit_on_error=False)
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"])
for aliases in [
@ -50,56 +61,40 @@ try:
except:
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.")
if parsedArgs is not None and (
len(
list(
filter(
lambda item: item[1] not in [False, None],
vars(parsedArgs).items()))) > 1):
environ["PVPN_USERNAME"] = session.vpn_username + \
(environ.get("PVPN_TAGS") or "")
environ["PVPN_PASSWORD"] = session.vpn_password
environ["PVPN_TIER"] = f"{session.vpn_tier}"
def match(server):
features = list()
if parsedArgs is not None and (
len(
list(
filter(
lambda item: item[1] not in [False, None],
vars(parsedArgs).items()))) > 1):
country = protonvpn.get_country()
if parsedArgs.streaming:
pass
if parsedArgs.sc:
pass
if parsedArgs.p2p:
pass
if parsedArgs.tor:
pass
def match(server):
features = list()
return (parsedArgs.cc is None or server.exit_country.lower() == parsedArgs.cc.lower()) and (
all(feature in server.features for feature in features))
if parsedArgs.streaming:
features.append(FeatureEnum.STREAMING)
if parsedArgs.sc:
features.append(FeatureEnum.SECURE_CORE)
if parsedArgs.p2p:
features.append(FeatureEnum.P2P)
if parsedArgs.tor:
features.append(FeatureEnum.TOR)
pull_server_data(force=True)
servers = list(filter(lambda server: match(server), get_servers()))
return (parsedArgs.cc is None or server.exit_country.lower() == parsedArgs.cc.lower()) and (
all(feature in server.features for feature in features))
servers = session.servers.filter(match)
if len(servers) > 0:
if parsedArgs.fastest or not parsedArgs.random:
server = servers.get_fastest_server()
else:
server = servers.get_random_server()
run_proton(["connect", server.name])
if len(servers) > 0:
if parsedArgs.fastest or not parsedArgs.random:
server = get_fastest_server(servers)
else:
raise Exception(
f"Unable to find a server matching the specified criteria {args[1:]}!")
server = choice(servers)
run_proton(["connect", server["Name"]])
else:
run_proton(args)
raise Exception(
f"Unable to find a server matching the specified criteria {args[1:]}!")
else:
run_proton(args)

View file

@ -5,8 +5,13 @@ FROM debian
ARG PVPN_CLI_VER=2.2.12
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_TAGS="+pmp" \
PVPN_CMD_ARGS="connect --p2p --random" \
PVPN_DEBUG= \
HOST_NETWORK= \
@ -20,9 +25,28 @@ ENV PVPN_TAGS="+pmp" \
WORKDIR /root
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
COPY --from=proton /root/.pvpn-cli /root/.pvpn-cli
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 \
sed -i \
@ -32,43 +56,7 @@ RUN \
&& install -t /usr/local/bin /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" \
"#!/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 \
&& install -Dm 755 ./pvpn-cli /usr/local/bin \
&& rm ./pvpn-cli
@ -77,7 +65,20 @@ RUN printf "%s\n" \
"#!/bin/bash" \
"groupadd --gid \$PGID ${USERNAME} > /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="$@"' \
'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" \
'ip link show proton0 > /dev/null 2>&1 || exit' \
'fallback="$(expr ${NATPMP_TIMEOUT} \* 3 / 4)"' \