From 7fd1632044bc615a75bc815f79e927cda27f5f9c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 5 Sep 2025 05:06:40 +0000 Subject: [PATCH] fifrst commit --- .gitignore | 1 + Dockerfile | 40 ++++++++++++++++++++++++++++ entrypoint.sh | 51 ++++++++++++++++++++++++++++++++++++ ngircd.conf.template | 15 +++++++++++ ngircd.motd | 6 +++++ thelounge-config.js.template | 51 ++++++++++++++++++++++++++++++++++++ torrc | 4 +++ 7 files changed, 168 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100644 ngircd.conf.template create mode 100644 ngircd.motd create mode 100644 thelounge-config.js.template create mode 100644 torrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..52cf4f5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM alpine:edge + +# enable edge repos including testing +RUN printf '%s\n' \ + "https://dl-cdn.alpinelinux.org/alpine/edge/main" \ + "https://dl-cdn.alpinelinux.org/alpine/edge/community" \ + "https://dl-cdn.alpinelinux.org/alpine/edge/testing" \ + > /etc/apk/repositories + +RUN apk update && apk add --no-cache \ + openssl \ + openssl-libs-static \ + nodejs \ + npm \ + thelounge \ + ngircd \ + tor \ + su-exec \ + bash \ + tini + +RUN addgroup -S app && adduser -S -G app app + +ENV DATA_DIR=/data +ENV TOR_DIR=${DATA_DIR}/tor +ENV THELOUNGE_DIR=${DATA_DIR}/thelounge +ENV NGIRCD_DIR=${DATA_DIR}/ngircd + +RUN mkdir -p ${TOR_DIR} ${THELOUNGE_DIR} ${NGIRCD_DIR} + +COPY entrypoint.sh /usr/local/bin/ +COPY ngircd.conf.template /etc/ngircd/ +COPY ngircd.motd /etc/ngircd/ +COPY torrc /etc/tor/ +COPY thelounge-config.js.template / +RUN chmod +x /usr/local/bin/entrypoint.sh + +EXPOSE 9000 +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"] +CMD ["bash"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..cdfb5a4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +DATA_DIR=/data +TOR_DIR=${DATA_DIR}/tor +THELOUNGE_DIR=${DATA_DIR}/thelounge +NGIRCD_DIR=${DATA_DIR}/ngircd + +mkdir -p "${TOR_DIR}" "${THELOUNGE_DIR}" "${NGIRCD_DIR}" +chown -R app:app "${DATA_DIR}" + +# Start tor (uses DataDirectory as set in torrc) +su-exec app tor -f /etc/tor/torrc & +TORPID=$! + +# Wait for hidden service hostname (give Tor up to 20s) +for i in $(seq 1 20); do + if [ -f "${TOR_DIR}/hidden_service/hostname" ]; then + break + fi + sleep 1 +done +HS_NAME=`cat ${TOR_DIR}/hidden_service/hostname` + +# Start ngircd (listening on 127.0.0.1:6667) +NGIRCD_CFG=${NGIRCD_DIR}/ngircd.conf +if [ ! -f "${NGIRCD_CFG}" ]; then + sed "s|%HS_NAME%|${HS_NAME}|g" "/etc/ngircd/ngircd.conf.template" > "${NGIRCD_CFG}" + mv /etc/ngircd/ngircd.motd ${NGIRCD_DIR}/ngircd.motd + chown -R app:app "${NGIRCD_DIR}/" +fi +ngircd -f ${NGIRCD_CFG} & + +# Prepare The Lounge config from template if missing +THELOUNGE_CFG=${THELOUNGE_DIR}/config.js +if [ ! -f "${THELOUNGE_CFG}" ]; then + #THELOUNGE_NICK=${THELOUNGE_NICK:-DuckUser} + sed "s|%HS_NAME%|${HS_NAME}|g" "/thelounge-config.js.template" > "${THELOUNGE_CFG}" + chown app:app "${THELOUNGE_CFG}" +fi + +echo "" +echo "Connect to http://${HS_NAME} on a Tor enabled browser, and don't forget to enable javascript." +echo "" + +# Start The Lounge as non-root +export THELOUNGE_HOME=${THELOUNGE_DIR} +su-exec app /usr/bin/thelounge start + + +wait -n diff --git a/ngircd.conf.template b/ngircd.conf.template new file mode 100644 index 0000000..742a73f --- /dev/null +++ b/ngircd.conf.template @@ -0,0 +1,15 @@ +[Global] + Name = %HS_NAME% + Listen = ::,0.0.0.0 + MotdFile = /data/ngircd/ngircd.motd +[Limits] +[Options] + CloakHost = cloaked.host + DNS = no + MorePrivacy = yes + PAMIsOptional = yes +[Operator] +[Server] +[Channel] + Name = #chat + Autojoin = yes diff --git a/ngircd.motd b/ngircd.motd new file mode 100644 index 0000000..6f5cd22 --- /dev/null +++ b/ngircd.motd @@ -0,0 +1,6 @@ +███████╗███████╗██╗██████╗ ██████╗ +██╔════╝╚══███╔╝██║██╔══██╗██╔════╝ +█████╗ ███╔╝ ██║██████╔╝██║ +██╔══╝ ███╔╝ ██║██╔══██╗██║ +███████╗███████╗██║██║ ██║╚██████╗ +╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ ╚═════╝ diff --git a/thelounge-config.js.template b/thelounge-config.js.template new file mode 100644 index 0000000..e9d5967 --- /dev/null +++ b/thelounge-config.js.template @@ -0,0 +1,51 @@ +"use strict"; +module.exports = { + public: true, + host: undefined, + port: 9000, + bind: undefined, + reverseProxy: false, + maxHistory: 100000, + https: { + enable: false, + }, + theme: "morning", + prefetch: true, + disableMediaPreview: false, + prefetchStorage: true, + prefetchMaxImageSize: 6144, + prefetchMaxSearchSize: 50, + prefetchTimeout: 10000, + fileUpload: { + enable: true, + maxFileSize: 51200, + baseUrl: "http://%HS_NAME%/uploads/", + }, + transports: ["polling", "websocket"], + leaveMessage: "https://chat.hackfreedom.org", + defaults: { + name: "EZIRC", + host: "127.0.0.1", + port: 6667, + password: "", + tls: false, + rejectUnauthorized: true, + nick: "anon%%", + username: "", + realname: "", + join: "#chat", + leaveMessage: "", + }, + lockNetwork: true, + messageStorage: ["sqlite"], + storagePolicy: { + enabled: false, + maxAgeDays: 1, + deletionPolicy: "everything", + }, + useHexIp: false, + debug: { + ircFramework: false, + raw: false, + }, +}; diff --git a/torrc b/torrc new file mode 100644 index 0000000..fb78a1e --- /dev/null +++ b/torrc @@ -0,0 +1,4 @@ +RunAsDaemon 0 +DataDirectory /data/tor +HiddenServiceDir /data/tor/hidden_service +HiddenServicePort 80 127.0.0.1:9000