Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Add core container

aapanel.coma4111684f4a6
diff --git a/Dockerfiles/core/Dockerfile b/Dockerfiles/core/Dockerfile
new file mode 100644
index 00000000..794e1880
--- /dev/null
+++ b/Dockerfiles/core/Dockerfile
@@ -0,0 +1,35 @@
+FROM alpine:3.20
+
+# Set environment variables
+ENV LANG=C.UTF-8
+ENV LC_ALL=C.UTF-8
+
+# Copy file
+# COPY repositories /etc/apk/repositories
+COPY stop-supervisor.sh /stop-supervisor.sh
+COPY core.sh /core.sh
+
+# Install dependencies (using Alpine's apk package manager)
+RUN apk add --no-cache \
+ bash \
+ ca-certificates \
+ curl \
+ supervisor \
+ rsyslog \
+ tzdata \
+ busybox-extras \
+ postgresql-client \
+ fail2ban \
+ iptables \
+ ipset \
+ && rm -rf /var/cache/apk/* \
+ && chmod +x /stop-supervisor.sh /core.sh
+
+# Copy file
+
+COPY supervisord.conf /etc/supervisor/supervisord.conf
+COPY fail2ban.conf /etc/fail2ban/fail2ban.conf
+
+
+ENTRYPOINT ["/core.sh"]
+CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
\ No newline at end of file
diff --git a/Dockerfiles/core/core.sh b/Dockerfiles/core/core.sh
new file mode 100644
index 00000000..1deefdd3
--- /dev/null
+++ b/Dockerfiles/core/core.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+if [ -f "/opt/billionmail/.env" ]; then
+ if ! grep -q "ADMIN_USERNAME" /opt/billionmail/.env; then
+ ADMIN_USERNAME=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 8)
+
+ # Default administrator account password
+ echo "ADMIN_USERNAME=${ADMIN_USERNAME}" >> /opt/billionmail/.env
+ fi
+
+ if ! grep -q "ADMIN_PASSWORD" /opt/billionmail/.env; then
+ ADMIN_PASSWORD=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 8)
+ # Default administrator account password
+ echo "ADMIN_PASSWORD=${ADMIN_PASSWORD}" >> /opt/billionmail/.env
+ fi
+fi
+
+# Generate DH params
+if [ ! -f "/etc/ssl/mail/dh.pem" ]; then
+ cp -d -n /etc/ssl/ssl-self-signed/* /etc/ssl/mail/
+fi
+
+# # Generate DH params
+# if [ ! -f "/etc/ssl/mail/dh.pem" ]; then
+# openssl dhparam -out /etc/ssl/mail/dh.pem 2048
+# fi
+
+# Remove defaults-debian.conf
+if [ -f "/etc/fail2ban/jail.d/defaults-debian.conf" ]; then
+ rm -f /etc/fail2ban/jail.d/defaults-debian.conf
+fi
+
+
+## Initialize fail2ban when y, otherwise delete the rule
+# Enable fail2ban Access restrictions, specify that the IP exceeds the access limit
+if [[ ${FAIL2BAN_INIT} == "y" ]]; then
+ ## Copy fail2ban Jail
+ if [ ! -f "/etc/fail2ban/jail.d/core-accesslimit.conf" ]; then
+ cp -f /opt/billionmail/conf/core/fail2ban_init/jail.d/core-accesslimit.conf /etc/fail2ban/jail.d/core-accesslimit.conf
+ fi
+
+ if [ ! -f "/etc/fail2ban/jail.d/roundcube-accesslimit.conf" ]; then
+ cp -f /opt/billionmail/conf/core/fail2ban_init/jail.d/roundcube-accesslimit.conf /etc/fail2ban/jail.d/roundcube-accesslimit.conf
+ fi
+else
+ rm -f /etc/fail2ban/jail.d/core-accesslimit.conf
+ rm -f /etc/fail2ban/jail.d/roundcube-accesslimit.conf
+ echo -e "fail2ban: delete the rule"
+fi
+
+## Copy fail2ban Filter
+# if [ ! -f "/etc/fail2ban/filter.d/core-limit-filter.conf" ]; then
+# cp -f /opt/billionmail/conf/core/fail2ban_init/filter.d/core-limit-filter.conf /etc/fail2ban/filter.d/core-limit-filter.conf
+# fi
+cp -rf /opt/billionmail/conf/core/fail2ban_init/filter.d/*.conf /etc/fail2ban/filter.d/
+
+if [ ! -d "/opt/billionmail/core/public/" ]; then
+ mkdir -p /opt/billionmail/core/public/dist
+ mkdir -p /opt/billionmail/core/public/html
+fi
+
+if [ ! -d "/opt/billionmail/core/logs/" ]; then
+ mkdir -p /opt/billionmail/core/logs
+ touch /opt/billionmail/core/logs/access-test.log
+fi
+
+chmod +x /opt/billionmail/core/billionmail
+
+exec "$@"
\ No newline at end of file
diff --git a/Dockerfiles/core/fail2ban.conf b/Dockerfiles/core/fail2ban.conf
new file mode 100644
index 00000000..173de0da
--- /dev/null
+++ b/Dockerfiles/core/fail2ban.conf
@@ -0,0 +1,92 @@
+# Fail2Ban main configuration file
+#
+# Comments: use '#' for comment lines and ';' (following a space) for inline comments
+#
+# Changes: in most of the cases you should not modify this
+# file, but provide customizations in fail2ban.local file, e.g.:
+#
+# [DEFAULT]
+# loglevel = DEBUG
+#
+
+[DEFAULT]
+
+# Option: loglevel
+# Notes.: Set the log level output.
+# CRITICAL
+# ERROR
+# WARNING
+# NOTICE
+# INFO
+# DEBUG
+# Values: [ LEVEL ] Default: INFO
+#
+loglevel = INFO
+
+# Option: logtarget
+# Notes.: Set the log target. This could be a file, SYSTEMD-JOURNAL, SYSLOG, STDERR or STDOUT.
+# Only one log target can be specified.
+# If you change logtarget from the default value and you are
+# using logrotate -- also adjust or disable rotation in the
+# corresponding configuration file
+# (e.g. /etc/logrotate.d/fail2ban on Debian systems)
+# Values: [ STDOUT | STDERR | SYSLOG | SYSOUT | SYSTEMD-JOURNAL | FILE ] Default: STDERR
+#
+logtarget = /var/log/fail2ban/fail2ban.log
+
+# Option: syslogsocket
+# Notes: Set the syslog socket file. Only used when logtarget is SYSLOG
+# auto uses platform.system() to determine predefined paths
+# Values: [ auto | FILE ] Default: auto
+syslogsocket = auto
+
+# Option: socket
+# Notes.: Set the socket file. This is used to communicate with the daemon. Do
+# not remove this file when Fail2ban runs. It will not be possible to
+# communicate with the server afterwards.
+# Values: [ FILE ] Default: /var/run/fail2ban/fail2ban.sock
+#
+socket = /var/run/fail2ban/fail2ban.sock
+
+# Option: pidfile
+# Notes.: Set the PID file. This is used to store the process ID of the
+# fail2ban server.
+# Values: [ FILE ] Default: /var/run/fail2ban/fail2ban.pid
+#
+pidfile = /var/run/fail2ban/fail2ban.pid
+
+# Option: allowipv6
+# Notes.: Allows IPv6 interface:
+# Default: auto
+# Values: [ auto yes (on, true, 1) no (off, false, 0) ] Default: auto
+#allowipv6 = auto
+
+# Options: dbfile
+# Notes.: Set the file for the fail2ban persistent data to be stored.
+# A value of ":memory:" means database is only stored in memory
+# and data is lost when fail2ban is stopped.
+# A value of "None" disables the database.
+# Values: [ None :memory: FILE ] Default: /var/lib/fail2ban/fail2ban.sqlite3
+dbfile = /var/lib/fail2ban/fail2ban.sqlite3
+
+# Options: dbpurgeage
+# Notes.: Sets age at which bans should be purged from the database
+# Values: [ SECONDS ] Default: 86400 (24hours)
+dbpurgeage = 1d
+
+# Options: dbmaxmatches
+# Notes.: Number of matches stored in database per ticket (resolvable via
+# tags <ipmatches>/<ipjailmatches> in actions)
+# Values: [ INT ] Default: 10
+dbmaxmatches = 10
+
+[Definition]
+
+
+[Thread]
+
+# Options: stacksize
+# Notes.: Specifies the stack size (in KiB) to be used for subsequently created threads,
+# and must be 0 or a positive integer value of at least 32.
+# Values: [ SIZE ] Default: 0 (use platform or configured default)
+#stacksize = 0
diff --git a/Dockerfiles/core/repositories b/Dockerfiles/core/repositories
new file mode 100644
index 00000000..fd5d2f6d
--- /dev/null
+++ b/Dockerfiles/core/repositories
@@ -0,0 +1,2 @@
+https://mirrors.ustc.edu.cn/alpine/v3.20/main
+https://mirrors.ustc.edu.cn/alpine/v3.20/community
\ No newline at end of file
diff --git a/Dockerfiles/core/stop-supervisor.sh b/Dockerfiles/core/stop-supervisor.sh
new file mode 100644
index 00000000..effb2a1e
--- /dev/null
+++ b/Dockerfiles/core/stop-supervisor.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+printf "Start\n";
+
+while read line; do
+ echo "PROCESS event: $line" >&2;
+ kill -3 $(cat "/var/run/supervisord.pid")
+done < /dev/stdin
diff --git a/Dockerfiles/core/supervisord.conf b/Dockerfiles/core/supervisord.conf
new file mode 100644
index 00000000..39b8b750
--- /dev/null
+++ b/Dockerfiles/core/supervisord.conf
@@ -0,0 +1,37 @@
+[supervisord]
+nodaemon=true
+logfile=/dev/stdout
+logfile_maxbytes=0
+pidfile=/var/run/supervisord.pid
+user=root
+
+[program:core]
+command=/opt/billionmail/core/billionmail
+directory=/opt/billionmail/core/
+autostart=true
+autorestart=true
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+user=root
+startsecs=10
+priority=100
+
+[program:fail2ban]
+command=/usr/bin/fail2ban-server -xf start
+autostart=true
+autorestart=true
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+user=root
+startsecs=10
+priority=200
+
+
+
+[eventlistener:processes]
+command=/stop-supervisor.sh
+events=PROCESS_STATE_STOPPED, PROCESS_STATE_EXITED, PROCESS_STATE_FATAL
\ No newline at end of file
diff --git a/conf/core/fail2ban_init/filter.d/core-limit-filter.conf b/conf/core/fail2ban_init/filter.d/core-limit-filter.conf
new file mode 100644
index 00000000..5dec84ea
--- /dev/null
+++ b/conf/core/fail2ban_init/filter.d/core-limit-filter.conf
@@ -0,0 +1,4 @@
+[Definition]
+failregex = ^.*?\{[^\}]+\} \d+ "(GET|POST|HEAD|PUT|DELETE|PATCH|OPTIONS|CONNECT|TRACE) http [^ ]+ \S+ HTTP.*" [^,]+, <HOST>, ".*?", ".*?"$
+
+ignoreregex = .*/roundcube.*
diff --git a/conf/core/fail2ban_init/filter.d/roundcube-limit-filter.conf b/conf/core/fail2ban_init/filter.d/roundcube-limit-filter.conf
new file mode 100644
index 00000000..427f6f50
--- /dev/null
+++ b/conf/core/fail2ban_init/filter.d/roundcube-limit-filter.conf
@@ -0,0 +1,4 @@
+[Definition]
+# Only match roundcube logs
+failregex = ^.*?\{[^\}]+\} \d+ "(GET|POST|HEAD|PUT|DELETE|PATCH|OPTIONS|CONNECT|TRACE) http [^ ]+ /roundcube(?:/\S*)? HTTP.*" [^,]+, <HOST>, ".*?", ".*?"$
+ignoreregex =
\ No newline at end of file
diff --git a/conf/core/fail2ban_init/jail.d/core-accesslimit.conf b/conf/core/fail2ban_init/jail.d/core-accesslimit.conf
new file mode 100644
index 00000000..94c76ae2
--- /dev/null
+++ b/conf/core/fail2ban_init/jail.d/core-accesslimit.conf
@@ -0,0 +1,10 @@
+[core-accesslimit]
+ignoreip = 127.0.0.1/8
+enabled = true
+port = 80,443
+filter = core-limit-filter
+logpath = /opt/billionmail/core/logs/access-*.log
+maxretry = 1000
+findtime = 60
+bantime = 60
+action = %(action_)s
diff --git a/conf/core/fail2ban_init/jail.d/roundcube-accesslimit.conf b/conf/core/fail2ban_init/jail.d/roundcube-accesslimit.conf
new file mode 100644
index 00000000..d8df4246
--- /dev/null
+++ b/conf/core/fail2ban_init/jail.d/roundcube-accesslimit.conf
@@ -0,0 +1,10 @@
+[roundcube-accesslimit]
+ignoreip = 127.0.0.1/8
+enabled = true
+port = 80,443
+filter = roundcube-limit-filter
+logpath = /opt/billionmail/core/logs/access-*.log
+maxretry = 600
+findtime = 60
+bantime = 60
+action = %(action_)s
\ No newline at end of file
diff --git a/ssl-self-signed/dh.pem b/ssl-self-signed/dh.pem
new file mode 100644
index 00000000..088f9673
--- /dev/null
+++ b/ssl-self-signed/dh.pem
@@ -0,0 +1,8 @@
+-----BEGIN DH PARAMETERS-----
+MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
+87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
+YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
+7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
+ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
+-----END DH PARAMETERS-----
\ No newline at end of file