Skip to content

Added crowdsec openresty bouncer support #2677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7705728
Added crowdsec to Nginx-Proxy-Manager
LePresidente Apr 26, 2023
6a035ea
Removed file not required.
LePresidente Apr 26, 2023
4245e62
made script executable.
LePresidente Apr 30, 2023
cd882b0
Changed permissions on script.sh
LePresidente May 17, 2023
ca6d112
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente May 17, 2023
9827c0b
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Aug 28, 2023
a108a5d
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Jan 15, 2024
8fa3069
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Jan 20, 2024
2d490b0
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Jan 25, 2024
58ae5a1
Make sure script.sh is set to be executable.
LePresidente Jan 27, 2024
c56e64b
added support to use environment variables instead of set file in dat…
LePresidente Feb 29, 2024
82d2476
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente May 3, 2024
3a22a0c
Fix environment variable for setting crowdsec bouncer, was broken due…
LePresidente May 9, 2024
e1698a9
Don't try copy templates if we are using environment variables for th…
LePresidente May 10, 2024
ee03105
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Jul 12, 2024
3e80393
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Oct 22, 2024
0fc86ea
Merge branch 'NginxProxyManager:develop' into develop-crowdsec
LePresidente Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docker/rootfs/etc/s6-overlay/s6-rc.d/cs-crowdsec-bouncer/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/command/with-contenv bash

set -e # Exit immediately if a command exits with a non-zero status.

function set_properties() {
sed -i "s,^$1=.*,$1=$2,g" "${3}"
}

echo "Deploy Crowdsec Openresty Bouncer.."
if [ -n "${CROWDSEC_OPENRESTY_BOUNCER}" ]; then
while IFS= read -r line
do
if ! [[ "$line" != "^#" ]] || [[ "$line" != "^\n" ]]; then
name=$(echo "$line" | cut -d "=" -f1)
value=$(echo "$line" | cut -d "=" -f2)
if grep -q "${name}" /defaults/crowdsec/crowdsec-openresty-bouncer.conf ; then
set_properties "${name}" "${value}" "/defaults/crowdsec/crowdsec-openresty-bouncer.conf"
fi
fi
done <<< "${CROWDSEC_OPENRESTY_BOUNCER}"
else
mkdir -p /data/crowdsec/templates
sed -i 's|/defaults/crowdsec|/data/crowdsec|' /etc/nginx/conf.d/crowdsec_openresty.conf

if [ -f /data/crowdsec/crowdsec-openresty-bouncer.conf ]; then
echo "Patch crowdsec-openresty-bouncer.conf .."
sed "s/=.*//g" /data/crowdsec/crowdsec-openresty-bouncer.conf > /tmp/crowdsec.conf.raw
sed "s/=.*//g" /defaults/crowdsec/crowdsec-openresty-bouncer.conf > /tmp/crowdsec-openresty-bouncer.conf.raw
if grep -vf /tmp/crowdsec.conf.raw /tmp/crowdsec-openresty-bouncer.conf.raw ; then
grep -vf /tmp/crowdsec.conf.raw /tmp/crowdsec-openresty-bouncer.conf.raw > /tmp/config.newvals
cp /data/crowdsec/crowdsec-openresty-bouncer.conf /data/crowdsec/crowdsec-openresty-bouncer.conf.bak
grep -f /tmp/config.newvals /defaults/crowdsec/crowdsec-openresty-bouncer.conf >> /data/crowdsec/crowdsec-openresty-bouncer.conf
fi
else
echo "Deploy new crowdsec-openresty-bouncer.conf .."
cp /defaults/crowdsec/crowdsec-openresty-bouncer.conf /data/crowdsec/crowdsec-openresty-bouncer.conf
fi
#Make sure the config location is where we get the config from instead of /default/
sed -i 's|/defaults/crowdsec|/data/crowdsec|' /data/crowdsec/crowdsec-openresty-bouncer.conf
fi


#Make sure we only copy files that don't exist in /data/crowdsec.
if [ -d "/data/crowdsec/templates" ]; then
echo "Deploy Crowdsec Templates .."
cd /defaults/crowdsec/templates/
for file in *.html
do
if [ ! -e "/data/crowdsec/templates/${file}" ]
then
cp -r "/defaults/crowdsec/templates/${file}" "/data/crowdsec/templates/"
fi
done
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
2 changes: 2 additions & 0 deletions docker/rootfs/etc/s6-overlay/s6-rc.d/cs-crowdsec-bouncer/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# shellcheck shell=bash
/etc/s6-overlay/s6-rc.d/cs-crowdsec-bouncer/script.sh