From 23321bd300406d0363700489bdd9fe4c068482a7 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Fri, 17 Nov 2023 17:56:28 +0000 Subject: [PATCH 1/5] Fix SyntaxWarning: invalid escape sequence --- greet.py | 2 +- plugins/FilePack/FilePackPlugin.py | 10 +++++----- src/Crypt/ed25519.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/greet.py b/greet.py index d918bd6c..5f72dca2 100644 --- a/greet.py +++ b/greet.py @@ -18,7 +18,7 @@ def grad(n): def fancy_greet(version): from rich.console import Console from rich.text import Text - zc_msg = f''' + zc_msg = fr''' ||| . . _ _._|_ _. . . _ .__ _.. _. . __.. _ __. . ||| //\|/ |/_| | == / / \|/ |( /_||/ | | __||/ |/ \_| ||| \_/| |\_ |. \__\_/| |_) \_ | \/ |__|| |\__ _/ diff --git a/plugins/FilePack/FilePackPlugin.py b/plugins/FilePack/FilePackPlugin.py index a095c6d4..1c931316 100644 --- a/plugins/FilePack/FilePackPlugin.py +++ b/plugins/FilePack/FilePackPlugin.py @@ -45,7 +45,7 @@ class UiRequestPlugin(object): file_obj = None path_parts = self.parsePath(path) file_path = "%s/%s/%s" % (config.data_dir, path_parts["address"], path_parts["inner_path"]) - match = re.match("^(.*\.(?:tar.gz|zip))/(.*)", file_path) + match = re.match(r"^(.*\.(?:tar.gz|zip))/(.*)", file_path) archive_path, path_within = match.groups() if archive_path not in archive_cache: site = self.server.site_manager.get(path_parts["address"]) @@ -99,7 +99,7 @@ class UiRequestPlugin(object): class SiteStoragePlugin(object): def isFile(self, inner_path): if ".zip/" in inner_path or ".tar.gz/" in inner_path: - match = re.match("^(.*\.(?:tar.gz|zip))/(.*)", inner_path) + match = re.match(r"^(.*\.(?:tar.gz|zip))/(.*)", inner_path) archive_inner_path, path_within = match.groups() return super(SiteStoragePlugin, self).isFile(archive_inner_path) else: @@ -127,7 +127,7 @@ class SiteStoragePlugin(object): def walk(self, inner_path, *args, **kwags): if ".zip" in inner_path or ".tar.gz" in inner_path: - match = re.match("^(.*\.(?:tar.gz|zip))(.*)", inner_path) + match = re.match(r"^(.*\.(?:tar.gz|zip))(.*)", inner_path) archive_inner_path, path_within = match.groups() archive = self.openArchive(archive_inner_path) path_within = path_within.lstrip("/") @@ -151,7 +151,7 @@ class SiteStoragePlugin(object): def list(self, inner_path, *args, **kwags): if ".zip" in inner_path or ".tar.gz" in inner_path: - match = re.match("^(.*\.(?:tar.gz|zip))(.*)", inner_path) + match = re.match(r"^(.*\.(?:tar.gz|zip))(.*)", inner_path) archive_inner_path, path_within = match.groups() archive = self.openArchive(archive_inner_path) path_within = path_within.lstrip("/") @@ -178,7 +178,7 @@ class SiteStoragePlugin(object): def read(self, inner_path, mode="rb", **kwargs): if ".zip/" in inner_path or ".tar.gz/" in inner_path: - match = re.match("^(.*\.(?:tar.gz|zip))(.*)", inner_path) + match = re.match(r"^(.*\.(?:tar.gz|zip))(.*)", inner_path) archive_inner_path, path_within = match.groups() archive = self.openArchive(archive_inner_path) path_within = path_within.lstrip("/") diff --git a/src/Crypt/ed25519.py b/src/Crypt/ed25519.py index 7c0161dc..8bd4ab86 100644 --- a/src/Crypt/ed25519.py +++ b/src/Crypt/ed25519.py @@ -64,7 +64,7 @@ def pow2(x, p): def inv(z): - """$= z^{-1} \mod q$, for z != 0""" + r"""$= z^{-1} \mod q$, for z != 0""" # Adapted from curve25519_athlon.c in djb's Curve25519. z2 = z * z % q # 2 z9 = pow2(z2, 2) * z % q # 9 From 47db0898e25874da9c25062acdaf0fc3798b7854 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Fri, 17 Nov 2023 17:57:25 +0000 Subject: [PATCH 2/5] Rewrite untitialized directory detection --- src/main.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main.py b/src/main.py index 5c69c884..67480aaf 100644 --- a/src/main.py +++ b/src/main.py @@ -74,28 +74,30 @@ def importBundle(bundle): def init_dirs(): data_dir = config.data_dir - if not os.path.isdir(data_dir): + has_data_dir = os.path.isdir(data_dir) + need_bootstrap = not config.disable_bootstrap and (not has_data_dir or not os.path.isfile(f'{data_dir}/sites.json')) and not config.offline + + if not has_data_dir: os.mkdir(data_dir) try: os.chmod(data_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) except Exception as err: startupError(f"Can't change permission of {data_dir}: {err}") - # download latest bootstrap bundle - if not config.disable_bootstrap and not config.offline: - import requests - from io import BytesIO + if need_bootstrap: + import requests + from io import BytesIO - print(f'fetching {config.bootstrap_url}') - response = requests.get(config.bootstrap_url) - if response.status_code != 200: - startupError(f"Cannot load bootstrap bundle (response status: {response.status_code})") - url = response.text - print(f'got {url}') - response = requests.get(url) - if response.status_code < 200 or response.status_code >= 300: - startupError(f"Cannot load boostrap bundle (response status: {response.status_code})") - importBundle(BytesIO(response.content)) + print(f'fetching {config.bootstrap_url}') + response = requests.get(config.bootstrap_url) + if response.status_code != 200: + startupError(f"Cannot load bootstrap bundle (response status: {response.status_code})") + url = response.text + print(f'got {url}') + response = requests.get(url) + if response.status_code < 200 or response.status_code >= 300: + startupError(f"Cannot load boostrap bundle (response status: {response.status_code})") + importBundle(BytesIO(response.content)) sites_json = f"{data_dir}/sites.json" if not os.path.isfile(sites_json): From 92eb6c8ca1fca9d2d3691b754cf8102dd83408fd Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Fri, 17 Nov 2023 23:39:17 +0000 Subject: [PATCH 3/5] Update/rewrite docker files --- .dockerignore | 4 ++- .gitignore | 1 + Dockerfile | 17 ---------- Dockerfile.integrated_tor | 18 ----------- Dockerfile.tor | 10 ------ docker/Dockerfile | 25 +++++++++++++++ docker/debian.Dockerfile | 26 ++++++++++++++++ .../docker-compose.yml | 29 +++++++++-------- docker/tor.Dockerfile | 9 ++++++ docker/znctor.Dockerfile | 31 +++++++++++++++++++ 10 files changed, 111 insertions(+), 59 deletions(-) delete mode 100644 Dockerfile delete mode 100644 Dockerfile.integrated_tor delete mode 100644 Dockerfile.tor create mode 100644 docker/Dockerfile create mode 100644 docker/debian.Dockerfile rename docker-compose.yml => docker/docker-compose.yml (60%) create mode 100644 docker/tor.Dockerfile create mode 100644 docker/znctor.Dockerfile diff --git a/.dockerignore b/.dockerignore index 06de9748..620039c9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ venv -Dockerfile* +docker data +__pycahce__ +log diff --git a/.gitignore b/.gitignore index 35e7c766..2fce8187 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ __pycache__/ # Data dir data/* +docker/data/ *.db # Virtualenv diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 955ce752..00000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM python:3.10.4-alpine - -RUN apk --update --no-cache --no-progress add gcc libffi-dev musl-dev make openssl g++ - -WORKDIR /app -COPY . . - -RUN python3 -m venv venv \ - && source venv/bin/activate \ - && python3 -m pip install -r requirements.txt - -CMD source venv/bin/activate \ - && python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \ - --tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \ - --tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD main - -EXPOSE 43110 26552 diff --git a/Dockerfile.integrated_tor b/Dockerfile.integrated_tor deleted file mode 100644 index 20c4425a..00000000 --- a/Dockerfile.integrated_tor +++ /dev/null @@ -1,18 +0,0 @@ -FROM python:3.10.4-alpine - -RUN apk --update --no-cache --no-progress add tor gcc libffi-dev musl-dev make openssl g++ \ - && echo "ControlPort 9051" >> /etc/tor/torrc \ - && echo "CookieAuthentication 1" >> /etc/tor/torrc - -WORKDIR /app -COPY . . - -RUN python3 -m venv venv \ - && source venv/bin/activate \ - && python3 -m pip install -r requirements.txt - -CMD (tor&) \ - && source venv/bin/activate \ - && python3 zeronet.py --ui_ip "*" --fileserver_port 26552 - -EXPOSE 43110 26552 diff --git a/Dockerfile.tor b/Dockerfile.tor deleted file mode 100644 index b085747f..00000000 --- a/Dockerfile.tor +++ /dev/null @@ -1,10 +0,0 @@ -FROM alpine:3.16.0 - -RUN apk --update --no-cache --no-progress add tor - -CMD hashed_control_password=$(tor --quiet --hash-password $TOR_CONTROL_PASSWD) \ - && tor --SocksPort 0.0.0.0:$TOR_SOCKS_PORT \ - --ControlPort 0.0.0.0:$TOR_CONTROL_PORT \ - --HashedControlPassword $hashed_control_password - -EXPOSE $TOR_SOCKS_PORT $TOR_CONTROL_PORT diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..71613800 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.12-alpine + +RUN apk --update --no-cache --no-progress add git gcc libffi-dev musl-dev make openssl g++ autoconf automake libtool + +RUN adduser -u 1600 -D service-0net + +USER service-0net:service-0net + +WORKDIR /home/service-0net + +COPY requirements.txt . + +RUN python3 -m pip install -r requirements.txt + +# the part below is updated with source updates + +COPY . . + +ENTRYPOINT python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \ + --tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \ + --tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD + +CMD main + +EXPOSE 43110 26552 diff --git a/docker/debian.Dockerfile b/docker/debian.Dockerfile new file mode 100644 index 00000000..8507914b --- /dev/null +++ b/docker/debian.Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.12-slim-bookworm + +RUN apt-get update +RUN apt-get -y install git openssl pkg-config libffi-dev python3-pip python3-dev build-essential libtool + +RUN useradd -u 1600 -m service-0net + +USER service-0net:service-0net + +WORKDIR /home/service-0net + +COPY requirements.txt . + +RUN python3 -m pip install -r requirements.txt + +# the part below is updated with source updates + +COPY . . + +ENTRYPOINT python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \ + --tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \ + --tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD + +CMD main + +EXPOSE 43110 26552 diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 60% rename from docker-compose.yml rename to docker/docker-compose.yml index 5da1fc26..b953699f 100644 --- a/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,29 +1,31 @@ version: '3' + services: tor: tty: true stdin_open: true build: - context: . - dockerfile: Dockerfile.tor + context: .. + dockerfile: docker/tor.Dockerfile networks: - 0net-network - ports: - - "9050:9050" - - "9051:9051" environment: &tor-environments + # since we are using tor internally, password doesn't really matter TOR_CONTROL_PASSWD: some_password TOR_SOCKS_PORT: 9050 TOR_CONTROL_PORT: 9051 - 0net: + + 0net-conservancy: tty: true stdin_open: true build: - context: . + context: .. + dockerfile: docker/Dockerfile networks: - 0net-network volumes: - - 0net-data:/app/data + # NOTE: this refers to docker/data.. + - ./data:/home/service-0net/data ports: - "26552:26552" - "43110:43110" @@ -32,20 +34,21 @@ services: environment: TOR_ENABLED: enable <<: *tor-environments + 0net-tor: tty: true stdin_open: true build: - context: . - dockerfile: Dockerfile.integrated_tor + context: .. + dockerfile: docker/znctor.Dockerfile networks: - 0net-network volumes: - - 0net-data:/app/data + # NOTE: this refers to docker/data.. + - ./data:/home/service-0net/data ports: - "26552:26552" - "43110:43110" -volumes: - 0net-data: + networks: 0net-network: diff --git a/docker/tor.Dockerfile b/docker/tor.Dockerfile new file mode 100644 index 00000000..77fa00e5 --- /dev/null +++ b/docker/tor.Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.18 + +RUN apk --update --no-cache --no-progress add tor + +USER tor + +CMD tor --SocksPort 0.0.0.0:${TOR_SOCKS_PORT} --ControlPort 0.0.0.0:${TOR_CONTROL_PORT} --HashedControlPassword $(tor --quiet --hash-password $TOR_CONTROL_PASSWD) + +EXPOSE $TOR_SOCKS_PORT $TOR_CONTROL_PORT diff --git a/docker/znctor.Dockerfile b/docker/znctor.Dockerfile new file mode 100644 index 00000000..152bca70 --- /dev/null +++ b/docker/znctor.Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.12-alpine + +RUN apk --update --no-cache --no-progress add git gcc libffi-dev musl-dev make openssl g++ autoconf automake libtool +RUN apk add tor + +RUN echo "ControlPort 9051" >> /etc/tor/torrc +RUN echo "CookieAuthentication 1" >> /etc/tor/torrc + +RUN adduser -u 1600 -D service-0net + +USER service-0net:service-0net + +WORKDIR /home/service-0net + +COPY requirements.txt . + +RUN python3 -m pip install -r requirements.txt + +RUN echo "tor &" > start.sh +RUN echo "python3 zeronet.py --ui_ip '*' --fileserver_port 26552" >> start.sh +RUN chmod +x start.sh + +# the part below is updated with source updates + +COPY . . + +ENTRYPOINT ./start.sh + +CMD main + +EXPOSE 43110 26552 From 1945f5a0b7ff00610fc27abf33eaf042b7ccaa93 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Sun, 19 Nov 2023 17:26:33 +0000 Subject: [PATCH 4/5] Fix docker compose setup exposing ports to outside world by default --- docker/docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index b953699f..78a6908e 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -28,13 +28,14 @@ services: - ./data:/home/service-0net/data ports: - "26552:26552" - - "43110:43110" + - "127.0.0.1:43110:43110" depends_on: - tor environment: TOR_ENABLED: enable <<: *tor-environments + # integrated container with tor 0net-tor: tty: true stdin_open: true @@ -48,7 +49,7 @@ services: - ./data:/home/service-0net/data ports: - "26552:26552" - - "43110:43110" + - "127.0.0.1:43110:43110" networks: 0net-network: From 61f0b839ca8a4e5d66cf5b15bdc2830ce2b09a60 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Sun, 19 Nov 2023 22:29:03 +0000 Subject: [PATCH 5/5] REAMDE apt dependencies --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59fa72f0..9f1cdb43 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Install autoconf and other basic development tools, python3 and pip, then procee ##### Apt-based (debian, ubuntu, etc) - `sudo apt update` - - `sudo apt install pkg-config libffi-dev python3-pip python3-venv python3-dev build-essential` + - `sudo apt install git pkg-config libffi-dev python3-pip python3-venv python3-dev build-essential libtool` ##### Red Hat and Fedora based - `yum install epel-release -y 2>/dev/null`