mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-07-01 17:46:40 +00:00
issue 12: docker setup with a python script
This commit is contained in:
parent
44348b982f
commit
fbcc815d50
3 changed files with 77 additions and 153 deletions
120
Dockerfile
120
Dockerfile
|
@ -1,120 +0,0 @@
|
|||
####################################################################################
|
||||
# Setup guide can be found here: https://forum.hackliberty.org/t/how-to-setup-darknet-lantern-on-docker/339
|
||||
# I have change this file to make the setup process tor friendly
|
||||
###################################################################################
|
||||
|
||||
# Stage 1: Builder stage to clone the Darknet Lantern repository via its onion link.
|
||||
FROM debian:bookworm-slim AS builder
|
||||
LABEL stage="builder"
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install required utilities.
|
||||
RUN apt-get update && \
|
||||
apt-get install -y tor git torsocks curl && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create a working directory.
|
||||
WORKDIR /src
|
||||
|
||||
|
||||
# Build-time ARG for the lantern repository URL.
|
||||
ARG LANTERN_REPO="http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git"
|
||||
|
||||
# Start tor, wait for bootstrap, and then clone via torsocks.
|
||||
RUN set -ex && \
|
||||
service tor start \
|
||||
sleep 10 && \
|
||||
until curl --proxy socks5h://localhost:9050 -Is https://check.torproject.org | grep "200"; do \
|
||||
echo "Waiting for Tor to bootstrap..."; \
|
||||
sleep 15; \
|
||||
done && \
|
||||
git -c remote.origin.proxy=socks5h://127.0.0.1:9050 clone --depth=1 ${LANTERN_REPO} darknet-lantern
|
||||
|
||||
# Stage 2: Final runtime image.
|
||||
FROM debian:bookworm-slim
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Note: Do not hard-code INSTANCE_DOMAIN here.
|
||||
# It should be passed via docker-compose environment variables or with docker run -e.
|
||||
# For example:
|
||||
# environment:
|
||||
# - INSTANCE_DOMAIN=lantern.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion
|
||||
|
||||
# Install runtime dependencies (including cron and git).
|
||||
RUN apt-get update &&\
|
||||
apt-get install -y \
|
||||
nginx \
|
||||
php8.2-fpm \
|
||||
python3 \
|
||||
python3-pip \
|
||||
curl \
|
||||
socat \
|
||||
git \
|
||||
cron && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the Darknet Lantern source from the builder stage.
|
||||
RUN mkdir -p /srv/darknet-lantern
|
||||
COPY --from=builder /src/darknet-lantern/ /srv/darknet-lantern/
|
||||
|
||||
# Install Requirements
|
||||
RUN pip3 install --upgrade pip --break-system-packages && \
|
||||
pip3 install --no-cache-dir --break-system-packages -r /srv/darknet-lantern/requirements.txt
|
||||
|
||||
# Configure nginx.
|
||||
COPY nginx.conf /etc/nginx/sites-available/lantern.conf
|
||||
RUN ln -sf /etc/nginx/sites-available/lantern.conf /etc/nginx/sites-enabled/ && \
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
# Create cron job file using a heredoc to avoid quoting issues.
|
||||
RUN cat <<'EOF' > /etc/cron.d/lantern-jobs
|
||||
# Update repo daily at 2:00 AM
|
||||
0 2 * * * root sh -c "cd /srv/darknet-lantern && git -c http.proxy=socks5://127.0.0.1:9050 pull origin main" >> /var/log/lantern_git_update.log 2>&
|
||||
# Run lantern.py every 3 hours, piping "4\n" as input to sync links coming from other webring participants
|
||||
0 */3 * * * root python3 /srv/darknet-lantern/scripts/lantern.py 4
|
||||
# Run uptimechecker.py every 3 hours
|
||||
0 */3 * * * root python3 /srv/darknet-lantern/scripts/uptimechecker.py >> /var/log/uptimechecker.log 2>&1
|
||||
EOF
|
||||
|
||||
# Set permissions and install the cron file.
|
||||
RUN chmod 0644 /etc/cron.d/lantern-jobs && \
|
||||
crontab /etc/cron.d/lantern-jobs
|
||||
|
||||
# Create an entrypoint script using a heredoc.
|
||||
RUN cat <<'EOS' > /usr/local/bin/docker-entrypoint.sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Ensure INSTANCE_DOMAIN environment variable is set.
|
||||
if [ -z "$INSTANCE_DOMAIN" ]; then
|
||||
echo "Error: INSTANCE_DOMAIN environment variable not set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove stale instance file so lantern.py will read from stdin.
|
||||
rm -f /root/.darknet_participant_url
|
||||
|
||||
# Run lantern.py once to generate necessary files.
|
||||
printf "%s\ny\n0\n" "$INSTANCE_DOMAIN" | python3 /srv/darknet-lantern/scripts/lantern.py
|
||||
|
||||
# Start cron in the background.
|
||||
cron &
|
||||
|
||||
# Start socat to forward traffic from 127.0.0.1:9050 to tor-proxy:9050.
|
||||
socat TCP-LISTEN:9050,reuseaddr,fork TCP:tor-proxy:9050 &
|
||||
|
||||
# Start php8.2-fpm in the background.
|
||||
service php8.2-fpm start
|
||||
|
||||
# Start nginx in the foreground to keep the container active.
|
||||
nginx -g "daemon off;"
|
||||
EOS
|
||||
|
||||
# Make the entrypoint script executable.
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Set working directory.
|
||||
WORKDIR /srv/darknet-lantern
|
||||
|
||||
# Define the entrypoint.
|
||||
ENTRYPOINT [ "/usr/local/bin/docker-entrypoint.sh" ]
|
|
@ -1,33 +0,0 @@
|
|||
networks:
|
||||
tor:
|
||||
lantern:
|
||||
|
||||
services:
|
||||
darknet-lantern:
|
||||
build: .
|
||||
container_name: darknet-lantern
|
||||
volumes:
|
||||
- ./lantern_data:/srv/darknet-lantern/www/participants # Persist Darknet Lantern application data if needed.
|
||||
networks:
|
||||
- tor
|
||||
- lantern
|
||||
restart: unless-stopped
|
||||
|
||||
tor:
|
||||
image: osminogin/tor-simple
|
||||
container_name: tor
|
||||
volumes:
|
||||
- ./tor-data:/var/lib/tor
|
||||
- ./tor-data/torrc:/etc/tor/torrc
|
||||
networks:
|
||||
- tor
|
||||
restart: unless-stopped
|
||||
|
||||
tor-proxy:
|
||||
image: osminogin/tor-simple
|
||||
container_name: tor-proxy
|
||||
volumes:
|
||||
- ./tor-proxy:/var/lib/tor
|
||||
- ./tor-proxy/torrc:/etc/tor
|
||||
networks:
|
||||
- tor
|
77
setup_docker.py
Normal file
77
setup_docker.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
#!/bin/python3
|
||||
############################################################
|
||||
# Python script to setup docker containers on debian machines.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
import subprocess
|
||||
from string import Template
|
||||
from typing import Optional
|
||||
|
||||
# Constants
|
||||
dep_install = ["php-gd", "php8.2-fpm", "nginx"]
|
||||
lantern_dep = ["python3-pandas", "python3-requests", "python3-socks", "python3-dotenv", "python3-pip"]
|
||||
shell = "python3 -c 'import pty; pty.spawn(\"/bin/sh\")'"
|
||||
nginx_conf = Template("""server {
|
||||
listen 4443;
|
||||
listen [::]:4443;
|
||||
server_name lantern.$onion_domain;
|
||||
|
||||
root /srv/darknet-lantern/www/;
|
||||
location ~ \\.php$ {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
|
||||
}
|
||||
index index.php;
|
||||
}""")
|
||||
|
||||
tor_conf = """
|
||||
HiddenServiceDir /var/lib/tor/lantern/
|
||||
HiddenServicePort 80 127.0.0.1:4443
|
||||
SocksPort 127.0.0.1:9050
|
||||
"""
|
||||
|
||||
def update_and_install(to_be_installed: Optional[list]) -> None:
|
||||
""" APT Update and Install
|
||||
|
||||
This function handles all updates and installs needed in this script.
|
||||
Args:
|
||||
|
||||
to_be_installed -> a list of string(packages) that will be installed
|
||||
|
||||
return -> None
|
||||
"""
|
||||
packages = to_be_installed
|
||||
subprocess.run(["torsocks","apt-get","update"])
|
||||
if packages is None:
|
||||
return
|
||||
else:
|
||||
print(f"Installing {len(packages)} package(s)")
|
||||
for package in packages:
|
||||
subprocess.run(["torsocks","apt-get", "install", package])
|
||||
|
||||
def main():
|
||||
|
||||
# Install dependencies
|
||||
update_and_install(to_be_installed=dep_install)
|
||||
|
||||
# Change tor conf file
|
||||
subprocess.run(["rm", "/etc/tor/torrc"])
|
||||
subprocess.run(["cp","torrc", "/etc/tor/torrc"])
|
||||
subprocess.run(["service", "tor", "restart"])
|
||||
domain = subprocess.run(["cat", "/var/lib/tor/lantern/hostname"], capture=True)
|
||||
nginx_conf.safe_substitute(onion_domain=domain)
|
||||
subprocess.run(["service", "tor", "restart"])
|
||||
|
||||
subprocess(["ln","-s","/etc/nginx/sites-available/lantern.conf","/etc/nginx/sites-enabled/"])
|
||||
subprocess(["nginx", "-s", "reload"])
|
||||
|
||||
update_and_install(to_be_installed=lantern_dep)
|
||||
|
||||
print(f"Here i {domain}")
|
||||
|
||||
|
||||
main()
|
||||
print(shell)
|
||||
print()
|
Loading…
Add table
Add a link
Reference in a new issue