bunkerweb 1.4.0

This commit is contained in:
bunkerity
2022-06-03 17:24:14 +02:00
parent 3a078326c5
commit a9f886804a
5245 changed files with 1432051 additions and 27894 deletions

69
linux/Dockerfile-centos Normal file
View File

@@ -0,0 +1,69 @@
FROM quay.io/centos/centos:stream8
ENV OS=centos
ENV NGINX_VERSION 1.20.2
# Install fpm
RUN dnf install -y epel-release && \
dnf install -y ruby ruby-devel make gcc redhat-rpm-config rpm-build && \
gem install fpm
# Copy dependencies sources folder
COPY deps /tmp/bunkerweb/deps
# Nginx
COPY linux/nginx.repo /etc/yum.repos.d/nginx.repo
RUN dnf install yum-utils -y && \
dnf install nginx-1.20.2 -y
# Compile and install dependencies
RUN dnf install -y python39-pip brotli brotli-devel gperftools-devel perl libxslt-devel libxml2 libxslt bash gd gd-devel gcc-c++ kernel-devel curl znc-modtcl libmpc-devel gmp-devel gawk mpfr-devel libtool pcre-devel automake autoconf readline-devel gcc make openssl-devel git zlib-devel libxml2-devel pkgconf libcurl-devel geoip-devel lmdb-libs && \
mkdir -p /opt/bunkerweb/deps && \
chmod +x /tmp/bunkerweb/deps/install.sh && \
bash /tmp/bunkerweb/deps/install.sh && \
mkdir /opt/bunkerweb/deps/python && \
pip3.9 install --no-cache-dir --require-hashes --target /opt/bunkerweb/deps/python -r /tmp/bunkerweb/deps/requirements.txt
# Copy BW files
# can't exclude deps from . so we are copying everything by hand
COPY api /opt/bunkerweb/api
COPY cli /opt/bunkerweb/cli
COPY confs /opt/bunkerweb/confs
COPY core /opt/bunkerweb/core
COPY gen /opt/bunkerweb/gen
COPY helpers /opt/bunkerweb/helpers
COPY job /opt/bunkerweb/job
COPY lua /opt/bunkerweb/lua
COPY misc /opt/bunkerweb/misc
COPY utils /opt/bunkerweb/utils
COPY ui /opt/bunkerweb/ui
COPY settings.json /opt/bunkerweb/settings.json
COPY VERSION /opt/bunkerweb/VERSION
# Setup BW
RUN cp /opt/bunkerweb/helpers/bwcli /usr/local/bin && \
mkdir /opt/bunkerweb/configs && \
mkdir /opt/bunkerweb/cache && \
mkdir /opt/bunkerweb/plugins && \
mkdir /opt/bunkerweb/tmp && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type f -exec chmod 0740 {} \; && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type d -exec chmod 0750 {} \; && \
chmod 770 /opt/bunkerweb/cache /opt/bunkerweb/tmp && \
chmod 750 /opt/bunkerweb/gen/main.py /opt/bunkerweb/job/main.py /opt/bunkerweb/cli/main.py /opt/bunkerweb/helpers/*.sh /usr/local/bin/bwcli /opt/bunkerweb/ui/main.py && \
find /opt/bunkerweb/core/*/jobs/* -type f -exec chmod 750 {} \; && \
pip3.9 install --no-cache-dir --target /opt/bunkerweb/deps/python -r /opt/bunkerweb/ui/requirements.txt
# Copy Linux files
COPY linux/variables.env /opt/bunkerweb/variables.env
COPY linux/bunkerweb-ui.env /opt/bunkerweb/bunkerweb-ui.env
COPY linux/scripts /opt/bunkerweb/scripts
COPY linux/fpm.sh /opt/fpm.sh
RUN chmod +x /opt/bunkerweb/scripts/*.sh /opt/fpm.sh
COPY linux/fpm-centos /opt/.fpm
COPY linux/bunkerweb.service /opt/bunkerweb.service
COPY linux/bunkerweb-ui.service /opt/bunkerweb-ui.service
# Generate RPM at startup
VOLUME /data
WORKDIR /opt
ENTRYPOINT ["/opt/fpm.sh", "rpm"]

74
linux/Dockerfile-debian Normal file
View File

@@ -0,0 +1,74 @@
FROM debian:bullseye-slim
ENV NGINX_VERSION 1.20.2
# Install fpm
RUN apt update && \
apt install -y --no-install-recommends ruby ruby-dev && \
gem install fpm
# Copy dependencies sources folder
COPY deps /tmp/bunkerweb/deps
# Nginx
RUN apt update && \
apt-get install gnupg2 ca-certificates -y && \
echo "deb https://nginx.org/packages/debian/ bullseye nginx" > /etc/apt/sources.list.d/nginx.list && \
echo "deb-src https://nginx.org/packages/debian/ bullseye nginx" >> /etc/apt/sources.list.d/nginx.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 && \
apt-get update && \
apt-get install -y --no-install-recommends nginx=${NGINX_VERSION}-1~bullseye
# Compile and install dependencies
RUN apt update && \
apt install --no-install-recommends bash python3-pip libssl-dev git libpcre++-dev zlib1g-dev libxml2-dev libyajl-dev pkgconf libcurl4-openssl-dev libgeoip-dev liblmdb-dev apt-utils bash build-essential autoconf libtool automake g++ gcc libxml2-dev make musl-dev gnupg patch libreadline-dev libpcre3-dev libgd-dev -y && \
mkdir -p /opt/bunkerweb/deps && \
chmod +x /tmp/bunkerweb/deps/install.sh && \
bash /tmp/bunkerweb/deps/install.sh && \
mkdir /opt/bunkerweb/deps/python && \
pip install --no-cache-dir --require-hashes --target /opt/bunkerweb/deps/python -r /tmp/bunkerweb/deps/requirements.txt
# Copy BW files
# can't exclude deps from . so we are copying everything by hand
COPY api /opt/bunkerweb/api
COPY cli /opt/bunkerweb/cli
COPY confs /opt/bunkerweb/confs
COPY core /opt/bunkerweb/core
COPY gen /opt/bunkerweb/gen
COPY helpers /opt/bunkerweb/helpers
COPY job /opt/bunkerweb/job
COPY lua /opt/bunkerweb/lua
COPY misc /opt/bunkerweb/misc
COPY utils /opt/bunkerweb/utils
COPY ui /opt/bunkerweb/ui
COPY settings.json /opt/bunkerweb/settings.json
COPY VERSION /opt/bunkerweb/VERSION
# Setup BW
RUN cp /opt/bunkerweb/helpers/bwcli /usr/local/bin && \
mkdir /opt/bunkerweb/configs && \
mkdir /opt/bunkerweb/cache && \
mkdir /opt/bunkerweb/plugins && \
mkdir /opt/bunkerweb/tmp && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type f -exec chmod 0740 {} \; && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type d -exec chmod 0750 {} \; && \
chmod 770 /opt/bunkerweb/cache /opt/bunkerweb/tmp && \
chmod 750 /opt/bunkerweb/gen/main.py /opt/bunkerweb/job/main.py /opt/bunkerweb/cli/main.py /opt/bunkerweb/helpers/*.sh /usr/local/bin/bwcli /opt/bunkerweb/ui/main.py && \
find /opt/bunkerweb/core/*/jobs/* -type f -exec chmod 750 {} \; && \
pip install --no-cache-dir --target /opt/bunkerweb/deps/python -r /opt/bunkerweb/ui/requirements.txt
# Copy Linux files
COPY linux/variables.env /opt/bunkerweb/variables.env
COPY linux/bunkerweb-ui.env /opt/bunkerweb/bunkerweb-ui.env
COPY linux/scripts /opt/bunkerweb/scripts
COPY linux/fpm.sh /opt/fpm.sh
RUN chmod +x /opt/bunkerweb/scripts/*.sh /opt/fpm.sh
COPY linux/fpm-debian /opt/.fpm
COPY linux/bunkerweb.service /opt/bunkerweb.service
COPY linux/bunkerweb-ui.service /opt/bunkerweb-ui.service
# Generate DEB at startup
VOLUME /data
WORKDIR /opt
ENTRYPOINT ["/opt/fpm.sh", "deb"]

68
linux/Dockerfile-fedora Normal file
View File

@@ -0,0 +1,68 @@
FROM fedora:36
ENV OS=fedora
ENV NGINX_VERSION 1.20.2
# Install fpm
RUN dnf install -y ruby ruby-devel make gcc redhat-rpm-config rpm-build && \
gem install fpm
# Nginx
RUN dnf update -y && \
dnf install -y curl gnupg2 ca-certificates redhat-lsb-core && \
dnf install nginx -y
# Copy dependencies sources folder
COPY deps /tmp/bunkerweb/deps
# Compile and install dependencies
RUN dnf install -y python3-pip brotli brotli-devel gperftools-devel perl libxslt-devel libxml2 libxslt bash gd gd-devel gcc-c++ kernel-devel curl znc-modtcl libmpc-devel gmp-devel gawk mpfr-devel libtool pcre-devel automake autoconf readline-devel gcc make openssl-devel git zlib-devel libxml2-devel pkgconf libcurl-devel geoip-devel lmdb-devel && \
mkdir -p /opt/bunkerweb/deps && \
chmod +x /tmp/bunkerweb/deps/install.sh && \
bash /tmp/bunkerweb/deps/install.sh && \
mkdir /opt/bunkerweb/deps/python && \
pip install --no-cache-dir --require-hashes --target /opt/bunkerweb/deps/python -r /tmp/bunkerweb/deps/requirements.txt
# Copy BW files
# can't exclude deps from . so we are copying everything by hand
COPY api /opt/bunkerweb/api
COPY cli /opt/bunkerweb/cli
COPY confs /opt/bunkerweb/confs
COPY core /opt/bunkerweb/core
COPY gen /opt/bunkerweb/gen
COPY helpers /opt/bunkerweb/helpers
COPY job /opt/bunkerweb/job
COPY lua /opt/bunkerweb/lua
COPY misc /opt/bunkerweb/misc
COPY utils /opt/bunkerweb/utils
COPY ui /opt/bunkerweb/ui
COPY settings.json /opt/bunkerweb/settings.json
COPY VERSION /opt/bunkerweb/VERSION
# Setup BW
RUN cp /opt/bunkerweb/helpers/bwcli /usr/local/bin && \
mkdir /opt/bunkerweb/configs && \
mkdir /opt/bunkerweb/cache && \
mkdir /opt/bunkerweb/plugins && \
mkdir /opt/bunkerweb/tmp && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type f -exec chmod 0740 {} \; && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type d -exec chmod 0750 {} \; && \
chmod 770 /opt/bunkerweb/cache /opt/bunkerweb/tmp && \
chmod 750 /opt/bunkerweb/gen/main.py /opt/bunkerweb/job/main.py /opt/bunkerweb/cli/main.py /opt/bunkerweb/helpers/*.sh /usr/local/bin/bwcli /opt/bunkerweb/ui/main.py && \
find /opt/bunkerweb/core/*/jobs/* -type f -exec chmod 750 {} \; && \
pip install --no-cache-dir --target /opt/bunkerweb/deps/python -r /opt/bunkerweb/ui/requirements.txt
# Copy Linux files
COPY linux/variables.env /opt/bunkerweb/variables.env
COPY linux/bunkerweb-ui.env /opt/bunkerweb/bunkerweb-ui.env
COPY linux/scripts /opt/bunkerweb/scripts
COPY linux/fpm.sh /opt/fpm.sh
RUN chmod +x /opt/bunkerweb/scripts/*.sh /opt/fpm.sh
COPY linux/fpm-fedora /opt/.fpm
COPY linux/bunkerweb.service /opt/bunkerweb.service
COPY linux/bunkerweb-ui.service /opt/bunkerweb-ui.service
# Generate RPM at startup
VOLUME /data
WORKDIR /opt
ENTRYPOINT ["/opt/fpm.sh", "rpm"]

73
linux/Dockerfile-ubuntu Normal file
View File

@@ -0,0 +1,73 @@
FROM ubuntu:22.04
ENV NGINX_VERSION 1.20.2
# Install fpm
RUN apt update && \
apt install -y --no-install-recommends ruby ruby-dev && \
gem install fpm
# Copy dependencies sources folder
COPY deps /tmp/bunkerweb/deps
# Nginx
RUN apt update && \
apt-get install curl gnupg2 ca-certificates lsb-release ubuntu-keyring software-properties-common -y && \
echo "deb https://nginx.org/packages/ubuntu/ jammy nginx" > /etc/apt/sources.list.d/nginx.list && \
echo "deb-src https://nginx.org/packages/ubuntu/ jammy nginx" >> /etc/apt/sources.list.d/nginx.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 && \
apt-get update && \
apt-get install -y --no-install-recommends nginx=${NGINX_VERSION}-1~jammy
# Compile and install dependencies
RUN apt update && \
apt install --no-install-recommends bash python3-pip libssl-dev git libpcre++-dev zlib1g-dev libxml2-dev libyajl-dev pkgconf libcurl4-openssl-dev libgeoip-dev liblmdb-dev apt-utils bash build-essential autoconf libtool automake g++ gcc libxml2-dev make musl-dev gnupg patch libreadline-dev libpcre3-dev libgd-dev -y && \
mkdir -p /opt/bunkerweb/deps && \
chmod +x /tmp/bunkerweb/deps/install.sh && \
bash /tmp/bunkerweb/deps/install.sh && \
mkdir /opt/bunkerweb/deps/python && \
pip install --no-cache-dir --require-hashes --target /opt/bunkerweb/deps/python -r /tmp/bunkerweb/deps/requirements.txt
# Copy BW files
# can't exclude deps from . so we are copying everything by hand
COPY api /opt/bunkerweb/api
COPY cli /opt/bunkerweb/cli
COPY confs /opt/bunkerweb/confs
COPY core /opt/bunkerweb/core
COPY gen /opt/bunkerweb/gen
COPY helpers /opt/bunkerweb/helpers
COPY job /opt/bunkerweb/job
COPY lua /opt/bunkerweb/lua
COPY misc /opt/bunkerweb/misc
COPY utils /opt/bunkerweb/utils
COPY ui /opt/bunkerweb/ui
COPY settings.json /opt/bunkerweb/settings.json
COPY VERSION /opt/bunkerweb/VERSION
# Setup BW
RUN cp /opt/bunkerweb/helpers/bwcli /usr/local/bin && \
mkdir /opt/bunkerweb/configs && \
mkdir /opt/bunkerweb/cache && \
mkdir /opt/bunkerweb/plugins && \
mkdir /opt/bunkerweb/tmp && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type f -exec chmod 0740 {} \; && \
find /opt/bunkerweb -path /opt/bunkerweb/deps -prune -o -type d -exec chmod 0750 {} \; && \
chmod 770 /opt/bunkerweb/cache /opt/bunkerweb/tmp && \
chmod 750 /opt/bunkerweb/gen/main.py /opt/bunkerweb/job/main.py /opt/bunkerweb/cli/main.py /opt/bunkerweb/helpers/*.sh /usr/local/bin/bwcli /opt/bunkerweb/ui/main.py && \
find /opt/bunkerweb/core/*/jobs/* -type f -exec chmod 750 {} \; && \
pip install --no-cache-dir --target /opt/bunkerweb/deps/python -r /opt/bunkerweb/ui/requirements.txt
# Copy Linux files
COPY linux/variables.env /opt/bunkerweb/variables.env
COPY linux/bunkerweb-ui.env /opt/bunkerweb/bunkerweb-ui.env
COPY linux/scripts /opt/bunkerweb/scripts
COPY linux/fpm.sh /opt/fpm.sh
RUN chmod +x /opt/bunkerweb/scripts/*.sh /opt/fpm.sh
COPY linux/fpm-ubuntu /opt/.fpm
COPY linux/bunkerweb.service /opt/bunkerweb.service
COPY linux/bunkerweb-ui.service /opt/bunkerweb-ui.service
# Generate DEB at startup
VOLUME /data
WORKDIR /opt
ENTRYPOINT ["/opt/fpm.sh", "deb"]

3
linux/bunkerweb-ui.env Normal file
View File

@@ -0,0 +1,3 @@
ADMIN_USERNAME=admin
ADMIN_PASSWORD=changeme
ABSOLUTE_URI=http://localhost:5000

View File

@@ -0,0 +1,19 @@
[Unit]
Description=Bunkerweb ui service
Documentation=Coming soon
After=network.target
[Service]
Restart=always
StartLimitBurst=1
User=nginx
ExecStart=/opt/bunkerweb/scripts/bunkerweb-ui.sh start
ExecStop=/opt/bunkerweb/scripts/bunkerweb-ui.sh stop
ExecReload=/opt/bunkerweb/scripts/bunkerweb-ui.sh reload
Type=simple
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=multi-user.target
Alias=bunkerweb-ui.service

20
linux/bunkerweb.service Normal file
View File

@@ -0,0 +1,20 @@
[Unit]
Description=Bunkerweb jobs services
Documentation=Coming soon
After=network.target
[Service]
Restart=always
StartLimitBurst=1
User=root
PIDFile=/opt/bunkerweb/tmp/scheduler.pid
ExecStart=/opt/bunkerweb/scripts/start.sh start
ExecStop=/opt/bunkerweb/scripts/start.sh stop
ExecReload=/opt/bunkerweb/scripts/start.sh reload
Type=simple
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=multi-user.target
Alias=bunkerweb.service

13
linux/fpm-centos Normal file
View File

@@ -0,0 +1,13 @@
-s dir
--name bunkerweb
--license agpl3
--version %VERSION%
--architecture x86_64
--depends bash --depends epel-release --depends python39 --depends 'nginx >= 1.20.2' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends GeoIP-devel --depends file-libs --depends net-tools --depends gd
--description "BunkerWeb %VERSION% for CentOS Stream 8"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"
--after-install /opt/bunkerweb/scripts/postinstall.sh
--before-remove /opt/bunkerweb/scripts/beforeRemove.sh
--after-remove /opt/bunkerweb/scripts/afterRemove.sh
/opt/bunkerweb/=/opt/bunkerweb/ bunkerweb.service=/etc/systemd/system/bunkerweb.service bunkerweb-ui.service=/etc/systemd/system/bunkerweb-ui.service

13
linux/fpm-debian Normal file
View File

@@ -0,0 +1,13 @@
-s dir
--name bunkerweb
--license agpl3
--version %VERSION%
--architecture amd64
--depends bash --depends python3 --depends python3-pip --depends 'nginx (>= 1.20.2)' --depends libcurl4 --depends libgeoip-dev --depends libxml2 --depends libyajl2 --depends libmagic1 --depends net-tools
--description "BunkerWeb %VERSION% for Debian 11"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"
--after-install /opt/bunkerweb/scripts/postinstall.sh
--before-remove /opt/bunkerweb/scripts/beforeRemove.sh
--after-remove /opt/bunkerweb/scripts/afterRemove.sh
/opt/bunkerweb/=/opt/bunkerweb/ bunkerweb.service=/etc/systemd/system/bunkerweb.service bunkerweb-ui.service=/etc/systemd/system/bunkerweb-ui.service

13
linux/fpm-fedora Normal file
View File

@@ -0,0 +1,13 @@
-s dir
--name bunkerweb
--license agpl3
--version %VERSION%
--architecture x86_64
--depends bash --depends python3 --depends 'nginx >= 1.20.2' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends geoip-devel --depends gd
--description "BunkerWeb %VERSION% for Fedora 36"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"
--after-install /opt/bunkerweb/scripts/postinstall.sh
--before-remove /opt/bunkerweb/scripts/beforeRemove.sh
--after-remove /opt/bunkerweb/scripts/afterRemove.sh
/opt/bunkerweb/=/opt/bunkerweb/ bunkerweb.service=/etc/systemd/system/bunkerweb.service bunkerweb-ui.service=/etc/systemd/system/bunkerweb-ui.service

13
linux/fpm-ubuntu Normal file
View File

@@ -0,0 +1,13 @@
-s dir
--name bunkerweb
--license agpl3
--version %VERSION%
--architecture amd64
--depends bash --depends python3 --depends python3-pip --depends 'nginx (>= 1.20.2)' --depends libcurl4 --depends libgeoip-dev --depends libxml2 --depends libyajl2 --depends libmagic1 --depends net-tools
--description "BunkerWeb %VERSION% for Ubuntu 22.04"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"
--after-install /opt/bunkerweb/scripts/postinstall.sh
--before-remove /opt/bunkerweb/scripts/beforeRemove.sh
--after-remove /opt/bunkerweb/scripts/afterRemove.sh
/opt/bunkerweb/=/opt/bunkerweb/ bunkerweb.service=/etc/systemd/system/bunkerweb.service bunkerweb-ui.service=/etc/systemd/system/bunkerweb-ui.service

6
linux/fpm.sh Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
VERSION="$(cat /opt/bunkerweb/VERSION | tr -d '\n')"
sed -i "s/%VERSION%/${VERSION}/g" .fpm
fpm -t "$1" -p "/data/bunkerweb.$1"

7
linux/nginx.repo Normal file
View File

@@ -0,0 +1,7 @@
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

View File

@@ -0,0 +1,71 @@
#!/bin/bash
#
# A shell option that causes the shell to exit immediately if a command exits with a non-zero status.
set -e
# if directory /opt/bunkerweb/ exists then remove it
if [ -d /opt/bunkerweb/ ]; then
echo "Removing /opt/bunkerweb/ ..."
rm -rf /opt/bunkerweb/
echo "Done !"
fi
# if directory /etc/systemd/system/bunkerweb.service exists then remove it
if [ -f /etc/systemd/system/bunkerweb.service ]; then
echo "Removing /etc/systemd/system/bunkerweb.service ..."
rm -f /etc/systemd/system/bunkerweb.service
echo "Done !"
fi
# if directory /etc/systemd/system/bunkerweb-ui.service exists then remove it
if [ -f /etc/systemd/system/bunkerweb-ui.service ]; then
echo "Removing /etc/systemd/system/bunkerweb-ui.service ..."
rm -f /etc/systemd/system/bunkerweb-ui.service
echo "Done !"
fi
# Detect OS between Debian, Ubuntu, CentOS, Fedora
if [ -f /etc/debian_version ]; then
# Loop to erase all the files in /etc/nginx/
for i in $( ls /etc/nginx/ ); do
echo "Removing /etc/nginx/$i ..."
rm -rf /etc/nginx/$i
echo "Done !"
done
echo "If you want to reinstall nginx, please run the following command:"
echo "sudo apt-get install nginx"
elif [ -f /etc/centos-release ]; then
# Loop to erase all the files in /etc/nginx/
for i in $( ls /etc/nginx/ ); do
echo "Removing /etc/nginx/$i ..."
rm -rf /etc/nginx/$i
echo "Done !"
done
echo "If you want to reinstall nginx, please run the following command:"
echo "sudo yum install nginx"
elif [ -f /etc/fedora-release ]; then
# Loop to erase all the files in /etc/nginx/
for i in $( ls /etc/nginx/ ); do
echo "Removing /etc/nginx/$i ..."
rm -rf /etc/nginx/$i
echo "Done !"
done
echo "If you want to reinstall nginx, please run the following command:"
echo "sudo dnf install nginx"
elif [ -f /etc/lsb-release ]; then
# Loop to erase all the files in /etc/nginx/
for i in $( ls /etc/nginx/ ); do
echo "Removing /etc/nginx/$i ..."
rm -rf /etc/nginx/$i
echo "Done !"
done
echo "If you want to reinstall nginx, please run the following command:"
echo "sudo apt-get install nginx"
else
echo "Your OS is not supported"
exit 1
fi
# if previous command was successful then restart systemd unit
if [ $? -eq 0 ]; then
echo "Restarting systemd ..."
systemctl daemon-reload
echo "Done !"
fi

View File

@@ -0,0 +1,31 @@
#!/bin/bash
#
# A shell option that causes the shell to exit immediately if a command exits with a non-zero status.
set -e
#
# function to stop bunkerweb
function stopBunker()
{
echo "Stopping Bunkerweb service ..."
# Stop bunkerweb service
systemctl stop bunkerweb
}
function stopUI()
{
echo "Stopping bunkerweb-ui service ..."
# Stop flask server
systemctl stop bunkerweb-ui
echo "Done !"
}
#
# Check if bunkerweb service is running
if systemctl is-active --quiet bunkerweb; then
# Stop bunkerweb service
stopBunker
fi
# Check if bunkerweb-ui service is running
if systemctl is-active --quiet bunkerweb-ui; then
# Stop ui service
stopUI
fi

52
linux/scripts/bunkerweb-ui.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
# function to start the UI
start_ui() {
export PYTHONPATH=/opt/bunkerweb/deps/python/
echo "Starting UI"
set -a
. /opt/bunkerweb/bunkerweb-ui.env
set +a
export FLASK_APP=/opt/bunkerweb/ui/main.py
python3 -m flask run --host=127.0.0.1 --port=7000
}
# function to stop the UI
stop_ui(){
echo "Stoping ui service ..."
# Check if pid file exist and remove it if so
PID_FILE_PATH="/opt/bunkerweb/tmp/ui.pid"
if [ -f "$PID_FILE_PATH" ];
then
var=$( cat $PID_FILE_PATH )
kill -SIGINT $var
echo "Killing : $var"
else
echo "File doesn't exist"
fi
}
# function reload the UI
reload_ui() {
stop_ui
# Wait for ui to stop
sleep 5
start_ui
# if previous command worked then exit with 0
exit 0
}
case "$1" in
start)
start_ui
;;
stop)
stop_ui
;;
reload)
reload_ui
;;
*)
echo "Usage: ./bunkerweb-ui.sh start|stop|reload"
;;
esac

View File

@@ -0,0 +1,16 @@
#!/bin/bash
# Stop nginx if it's running and remove the old config file if it exists
systemctl stop nginx
# Change the ownership of /opt/bunkerweb to nginx
chown -R nginx:nginx /opt/bunkerweb
# Change the ownership of bunkerweb.service to nginx
chown nginx:nginx /etc/systemd/system/bunkerweb.service
# Start bunkerweb service as nginx user and enable it to start on boot
systemctl enable bunkerweb
systemctl start bunkerweb
systemctl enable bunkerweb-ui
systemctl start bunkerweb-ui

19
linux/scripts/purge.sh Normal file
View File

@@ -0,0 +1,19 @@
#! /bin/sh
# A shell option that causes the shell to exit immediately if a command exits with a non-zero status.
set -e
# if purge is called, we want to remove the old config file from the system
# if it exists
if [ "$1" = "purge" ]; then
# purge bunkerweb
sudo systemctl stop bunkerweb
sudo systemctl disable bunkerweb
sudo rm -rf /opt/bunkerweb/
sudo rm -rf /etc/systemd/system/bunkerweb.service
sudo rm -rf /etc/systemd/system/bunkerweb-ui.service
# reload unit files
sudo systemctl daemon-reload
fi

234
linux/scripts/start.sh Normal file
View File

@@ -0,0 +1,234 @@
#!/bin/bash
#############################################################
# Help #
#############################################################
Help()
{
# Dispaly Help
echo "Usage of this script"
echo
echo "Syntax: start [start|stop|reload]"
echo "options:"
echo "start Create the configurations file and run all the jobs needed throught the bunkerweb service."
echo "stop Stop the bunkerweb service."
echo "reload Reload the bunkerweb service"
echo
}
export PYTHONPATH=/opt/bunkerweb/deps/python/
# Add nginx to sudoers
if [ ! -f /etc/sudoers.d/nginx ]; then
echo "Adding nginx user to sudoers file ..."
echo "nginx ALL=(ALL) NOPASSWD: /bin/systemctl restart bunkerweb" >> /etc/sudoers.d/nginx
echo "Done !"
fi
#############################################################
# Checker #
#############################################################
function check_ok() {
if [ $? -eq 0 ]; then
result="$?"
else
result="$?"
fi
}
#############################################################
# Start #
#############################################################
function start() {
#############################################
# STEP1 #
# Generate variables.env files to /tmp/ #
#############################################
printf "HTTP_PORT=80\nSERVER_NAME=example.com\nTEMP_NGINX=yes\nUSE_BUNKERNET=no" > "/tmp/variables.env"
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Generate variables.env files to /tmp/"
echo "OK !"
#############################################
# STEP2 #
# Generate first temporary config #
#############################################
/opt/bunkerweb/gen/main.py --settings /opt/bunkerweb/settings.json --templates /opt/bunkerweb/confs --output /etc/nginx --variables /tmp/variables.env
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Generate first temporary config"
echo "OK !"
#############################################
# STEP3 #
# Execute nginx #
#############################################
nginx
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Execute nginx"
echo "OK !"
#############################################
# STEP4 #
# Run jobs script #
#############################################
/opt/bunkerweb/job/main.py --variables /etc/nginx/variables.env --run
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Run jobs script"
echo "OK !"
#############################################
# STEP5 #
# Quit nginx #
#############################################
nginx -s quit
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Quit nginx"
echo "OK !"
#############################################
# STEP6 #
# Generate final confs #
#############################################
/opt/bunkerweb/gen/main.py --settings /opt/bunkerweb/settings.json --templates /opt/bunkerweb/confs --output /etc/nginx --variables /opt/bunkerweb/variables.env
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Generate final confs"
echo "OK !"
#############################################
# STEP7 #
# Run jobs infinite #
#############################################
/opt/bunkerweb/job/main.py --variables /etc/nginx/variables.env &
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Run jobs infinite"
echo "OK !"
#############################################
# STEP8 #
# Start nginx #
#############################################
nginx -g "daemon off; user nginx;"
# Test if command worked
check_ok
# Exit if failed
if [ $result -ne 0 ];
then
echo "Your command exited with non-zero status $result"
exit 1
fi
echo "Start nginx"
echo "OK !"
}
function stop()
{
echo "Stoping Bunkerweb service ..."
# Check if pid file exist and remove it if so
PID_FILE_PATH="/opt/bunkerweb/tmp/scheduler.pid"
if [ -f "$PID_FILE_PATH" ];
then
var=$( cat $PID_FILE_PATH )
kill -SIGINT $var
echo "Killing : $var"
else
echo "File doesn't exist"
fi
# Check if nginx running and if so, stop it
SERVICE="nginx"
if pgrep -x "$SERVICE" >/dev/null
then
echo "Stopping $SERVICE service"
nginx -s stop
else
echo "$SERVICE already stopped"
fi
echo "Done !"
}
function reload()
{
echo "Reloading Bunkerweb service ..."
# Check if pid file exist and remove it if so
PID_FILE_PATH="/opt/bunkerweb/tmp/scheduler.pid"
if [ -f "$PID_FILE_PATH" ];
then
var=$( cat $PID_FILE_PATH )
kill -SIGHUP $var
echo "Reloading : $var"
else
echo "File doesn't exist"
fi
# Check if nginx running and if so, reload it
SERVICE="nginx"
if pgrep -x "$SERVICE" >/dev/null
then
echo "Reloading $SERVICE service"
nginx -s reload
else
echo "$SERVICE already stopped"
fi
echo "Done !"
}
# List of differents args
case $1 in
"start")
start
;;
"stop")
stop
;;
"reload")
reload
;;
*)
echo "Invalid option!"
echo "List of option available:"
Help
esac

3
linux/variables.env Normal file
View File

@@ -0,0 +1,3 @@
HTTP_PORT=80
HTTPS_PORT=443
DNS_RESOLVERS=8.8.8.8 8.8.4.4