├── .github ├── release-drafter.yml └── workflows │ ├── build_package.yaml │ └── release-drafter.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── debian ├── changelog ├── compat ├── control ├── files ├── patches │ ├── crowdsec_nginx_fix.conf │ └── series ├── postinst ├── postrm ├── prerm └── rules ├── docs └── assets │ └── crowdsec_nginx.svg ├── install.sh ├── nginx └── crowdsec_nginx.conf ├── uninstall.sh └── upgrade.sh /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | template: | 2 | ## What’s Changed 3 | 4 | $CHANGES -------------------------------------------------------------------------------- /.github/workflows/build_package.yaml: -------------------------------------------------------------------------------- 1 | # .github/workflows/build-docker-image.yml 2 | name: release-package 3 | 4 | on: 5 | release: 6 | types: prereleased 7 | 8 | jobs: 9 | release-package: 10 | name: Upload release package 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: make the package 15 | run: make release 16 | - name: Upload to release 17 | uses: JasonEtco/upload-to-release@master 18 | with: 19 | args: crowdsec-nginx-bouncer.tgz application/x-gzip 20 | env: 21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | # branches to consider in the event; optional, defaults to all 6 | branches: 7 | - main 8 | 9 | jobs: 10 | update_release_draft: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # Drafts your next Release notes as Pull Requests are merged into "master" 14 | - uses: release-drafter/release-drafter@v5 15 | with: 16 | config-name: release-drafter.yml 17 | # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml 18 | # config-name: my-config.yml 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Lua sources 2 | luac.out 3 | 4 | # luarocks build files 5 | *.src.rock 6 | *.zip 7 | *.tar.gz 8 | 9 | # Object files 10 | *.o 11 | *.os 12 | *.ko 13 | *.obj 14 | *.elf 15 | 16 | # Precompiled Headers 17 | *.gch 18 | *.pch 19 | 20 | # Libraries 21 | *.lib 22 | *.a 23 | *.la 24 | *.lo 25 | *.def 26 | *.exp 27 | 28 | # Shared objects (inc. Windows DLLs) 29 | *.dll 30 | *.so 31 | *.so.* 32 | *.dylib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | *.i*86 39 | *.x86_64 40 | *.hex 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2021 Crowdsec 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BUILD_VERSION?="$(shell git for-each-ref --sort=-v:refname --count=1 --format '%(refname)' | cut -d '/' -f3)" 2 | OUTDIR="crowdsec-nginx-bouncer-${BUILD_VERSION}/" 3 | LUA_MOD_DIR="${OUTDIR}lua-mod" 4 | CONFIG_DIR="${OUTDIR}config" 5 | OUT_ARCHIVE="crowdsec-nginx-bouncer.tgz" 6 | LUA_BOUNCER_BRANCH?=v1.0.6 7 | default: release 8 | release: 9 | git clone -b "${LUA_BOUNCER_BRANCH}" https://github.com/crowdsecurity/lua-cs-bouncer.git 10 | mkdir -p ${LUA_MOD_DIR} 11 | cp -r lua-cs-bouncer/* "${LUA_MOD_DIR}"/ 12 | 13 | cp install.sh ${OUTDIR} 14 | chmod +x ${OUTDIR}install.sh 15 | 16 | cp uninstall.sh ${OUTDIR} 17 | chmod +x ${OUTDIR}uninstall.sh 18 | 19 | cp upgrade.sh ${OUTDIR} 20 | chmod +x ${OUTDIR}upgrade.sh 21 | 22 | cp -r ./nginx/ ${OUTDIR} 23 | tar cvzf ${OUT_ARCHIVE} ${OUTDIR} 24 | rm -rf ${OUTDIR} 25 | rm -rf "lua-cs-bouncer/" 26 | 27 | clean: 28 | rm -rf "${OUTDIR}" 29 | rm -rf "${OUT_ARCHIVE}" 30 | rm -rf "lua-cs-bouncer/" 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | CrowdSec 3 |

4 |

5 | 6 | 7 |

8 |

9 | 📚 Documentation 10 | 💠 Hub 11 | 💬 Discourse 12 |

13 | 14 | 15 | 16 | # CrowdSec NGINX Bouncer 17 | 18 | A lua bouncer for nginx. 19 | 20 | ## How does it work ? 21 | 22 | This bouncer leverages nginx lua's API, namely `access_by_lua_file`. 23 | 24 | New/unknown IP are checked against crowdsec API, and if request should be blocked, a **403** is returned to the user, and put in cache. 25 | 26 | At the back, this bouncer uses [crowdsec lua lib](https://github.com/crowdsecurity/lua-cs-bouncer/). 27 | 28 | # Installation 29 | 30 | Please follow the [official documentation](https://doc.crowdsec.net/docs/bouncers/nginx). 31 | 32 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | crowdsec-nginx-bouncer (1.0.12) UNRELEASED; urgency=medium 2 | 3 | * debian package 4 | 5 | -- Crowdsec Team Mon, 08 Feb 2021 09:38:06 +0100 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 11 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: crowdsec-nginx-bouncer 2 | Maintainer: Crowdsec Team 3 | Build-Depends: debhelper, bash 4 | 5 | Package: crowdsec-nginx-bouncer 6 | Provides: crowdsec-nginx-bouncer 7 | Description: lua-based nginx bouncer for Crowdsec 8 | Architecture: all 9 | Depends: nginx, lua5.1, libnginx-mod-http-lua, luarocks, gettext-base 10 | Breaks: nginx (<< 1.20), libnginx-mod-http-lua (<< 1.20) 11 | -------------------------------------------------------------------------------- /debian/files: -------------------------------------------------------------------------------- 1 | crowdsec-nginx-bouncer_1.0.12_all.buildinfo unknown optional 2 | crowdsec-nginx-bouncer_1.0.12_all.deb unknown optional 3 | -------------------------------------------------------------------------------- /debian/patches/crowdsec_nginx_fix.conf: -------------------------------------------------------------------------------- 1 | update path in config file 2 | --- a/nginx/crowdsec_nginx.conf 3 | +++ b/nginx/crowdsec_nginx.conf 4 | @@ -1,3 +1,3 @@ 5 | -lua_package_path '/usr/local/lua/crowdsec/?.lua;;'; 6 | +lua_package_path '/usr/lib/crowdsec/lua/?.lua;;'; 7 | lua_shared_dict crowdsec_cache 50m; 8 | lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt; 9 | -------------------------------------------------------------------------------- /debian/patches/series: -------------------------------------------------------------------------------- 1 | crowdsec_nginx_fix.conf 2 | -------------------------------------------------------------------------------- /debian/postinst: -------------------------------------------------------------------------------- 1 | 2 | systemctl daemon-reload 3 | 4 | luarocks install lua-resty-http 0.17.1-0 5 | luarocks install lua-cjson 2.1.0.10-1 6 | 7 | API_KEY_REQUIRED=true 8 | BOUNCER_CONFIG_PATH="/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf" 9 | API_KEY="" 10 | CROWDSEC_LAPI_URL="" 11 | LAPI_DEFAULT_PORT="8080" 12 | 13 | if [ "$1" = "configure" ]; then 14 | 15 | type cscli 16 | 17 | if [ "$?" -eq "0" ] ; then 18 | # Check if it's an upgrade 19 | if [ "$2" != "" ] ; then 20 | echo "Upgrading, check if there is bouncer configuration" 21 | if [ -f "${BOUNCER_CONFIG_PATH}" ] ; then 22 | API_KEY_REQUIRED=false 23 | fi 24 | fi 25 | API=$(cscli config show --key "Config.API.Server") 26 | if [ "$API" = "nil" ] || [ "$API" = "" ] ; then 27 | API_KEY_REQUIRED=false 28 | fi 29 | if [ ${API_KEY_REQUIRED} = true ] ; then 30 | echo "cscli/crowdsec is present, generating API key" 31 | unique=$(date +%s) 32 | API_KEY=$(cscli -oraw bouncers add crowdsec-nginx-bouncer-"${unique}") 33 | PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2) 34 | if [ ! -z "$PORT" ]; then 35 | LAPI_DEFAULT_PORT=${PORT} 36 | fi 37 | CROWDSEC_LAPI_URL="http://127.0.0.1:${LAPI_DEFAULT_PORT}" 38 | if [ $? -eq 1 ] ; then 39 | echo "failed to create API key." 40 | API_KEY_REQUIRED=true 41 | API_KEY="" 42 | else 43 | API_KEY_REQUIRED=false 44 | echo "API Key : ${API_KEY}" 45 | TMP=$(mktemp -p /tmp/) 46 | cp ${BOUNCER_CONFIG_PATH} "${TMP}" 47 | API_KEY="${API_KEY}" CROWDSEC_LAPI_URL="${CROWDSEC_LAPI_URL}" envsubst '$API_KEY $CROWDSEC_LAPI_URL' < "${TMP}" > ${BOUNCER_CONFIG_PATH} 48 | rm "${TMP}" 49 | fi 50 | fi 51 | fi 52 | 53 | mkdir -p /etc/nginx/conf.d/ 54 | cp /usr/share/crowdsec-nginx-bouncer/crowdsec_nginx.conf /etc/nginx/conf.d/crowdsec_nginx.conf 55 | 56 | else 57 | API_KEY_REQUIRED=false 58 | fi 59 | 60 | if [ ${API_KEY_REQUIRED} = true ] ; then 61 | echo "Can't generate an API key for the bouncer. Please do it manually" 62 | fi 63 | 64 | echo "Restart nginx to enable the crowdsec bouncer : sudo systemctl restart nginx" 65 | echo "" 66 | echo "If you want to setup captcha remediation, follow official documentation : " 67 | echo "https://docs.crowdsec.net/docs/bouncers/nginx#when-using-captcha-remediation" 68 | -------------------------------------------------------------------------------- /debian/postrm: -------------------------------------------------------------------------------- 1 | if [ "$1" = "remove" ]; then 2 | rm /etc/nginx/conf.d/crowdsec_nginx.conf || echo "Unable to remove file '/etc/nginx/conf.d/crowdsec_nginx.conf'. Remove it manually or your NGINX service will not be able to restart." 3 | fi -------------------------------------------------------------------------------- /debian/prerm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crowdsecurity/cs-nginx-bouncer/c3820efc42eba4a0ce772206e3a48ce7d353447e/debian/prerm -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | export DEB_VERSION=$(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ') 4 | export BUILD_VERSION=v${DEB_VERSION}-debian-pragmatic 5 | export LUA_BOUNCER_BRANCH?=v1.0.6 6 | 7 | %: 8 | dh $@ 9 | 10 | override_dh_systemd_start: 11 | echo "Not running dh_systemd_start" 12 | override_dh_auto_clean: 13 | rm -rf lua-cs-bouncer 14 | override_dh_auto_test: 15 | override_dh_auto_build: 16 | override_dh_auto_install: 17 | mkdir -p debian/crowdsec-nginx-bouncer/usr/share/crowdsec-nginx-bouncer/ 18 | cp nginx/crowdsec_nginx.conf debian/crowdsec-nginx-bouncer/usr/share/crowdsec-nginx-bouncer/ 19 | 20 | git clone -b "${LUA_BOUNCER_BRANCH}" https://github.com/crowdsecurity/lua-cs-bouncer.git 21 | 22 | mkdir -p debian/crowdsec-nginx-bouncer/usr/lib/crowdsec/lua/ 23 | mkdir -p debian/crowdsec-nginx-bouncer/var/lib/crowdsec/lua/templates/ 24 | 25 | cp -r lua-cs-bouncer/lib/* debian/crowdsec-nginx-bouncer/usr/lib/crowdsec/lua/ 26 | cp -r lua-cs-bouncer/templates/* debian/crowdsec-nginx-bouncer/var/lib/crowdsec/lua/templates/ 27 | 28 | mkdir -p debian/crowdsec-nginx-bouncer/etc/crowdsec/bouncers/ 29 | cp lua-cs-bouncer/config_example.conf debian/crowdsec-nginx-bouncer/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf 30 | 31 | -------------------------------------------------------------------------------- /docs/assets/crowdsec_nginx.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LUA_MOD_DIR="./lua-mod" 4 | NGINX_CONF="crowdsec_nginx.conf" 5 | NGINX_CONF_DIR="/etc/nginx/conf.d/" 6 | ACCESS_FILE="access.lua" 7 | LIB_PATH="/usr/local/lua/crowdsec/" 8 | CONFIG_PATH="/etc/crowdsec/bouncers/" 9 | DATA_PATH="/var/lib/crowdsec/lua/" 10 | LAPI_DEFAULT_PORT="8080" 11 | SILENT="false" 12 | 13 | usage() { 14 | echo "Usage:" 15 | echo " ./install.sh -h Display this help message." 16 | echo " ./install.sh Install the bouncer in interactive mode" 17 | echo " ./install.sh -y Install the bouncer and accept everything" 18 | exit 0 19 | } 20 | 21 | 22 | #Accept cmdline arguments to overwrite options. 23 | while [[ $# -gt 0 ]] 24 | do 25 | case $1 in 26 | -y|--yes) 27 | SILENT="true" 28 | shift 29 | ;; 30 | -h|--help) 31 | usage 32 | ;; 33 | esac 34 | shift 35 | done 36 | 37 | 38 | gen_apikey() { 39 | 40 | type cscli > /dev/null 41 | 42 | if [ "$?" -eq "0" ] ; then 43 | SUFFIX=`tr -dc A-Za-z0-9 /dev/null 56 | } 57 | 58 | check_nginx_dependency() { 59 | DEPENDENCY=( 60 | "libnginx-mod-http-lua" 61 | "luarocks" 62 | "lua5.1" 63 | "gettext-base" 64 | ) 65 | for dep in ${DEPENDENCY[@]}; 66 | do 67 | dpkg -l | grep ${dep} > /dev/null 68 | if [[ $? != 0 ]]; then 69 | if [[ ${SILENT} == "true" ]]; then 70 | sudo apt-get install -y -qq ${dep} > /dev/null && echo "${dep} successfully installed" 71 | else 72 | echo "${dep} not found, do you want to install it (Y/n)? " 73 | read answer 74 | if [[ ${answer} == "" ]]; then 75 | answer="y" 76 | fi 77 | if [ "$answer" != "${answer#[Yy]}" ] ;then 78 | sudo apt-get install -y -qq ${dep} > /dev/null && echo "${dep} successfully installed" 79 | else 80 | echo "unable to continue without ${dep}. Exiting" && exit 1 81 | fi 82 | fi 83 | fi 84 | done 85 | } 86 | 87 | 88 | install() { 89 | sudo mkdir -p ${LIB_PATH}/plugins/crowdsec/ 90 | sudo mkdir -p ${DATA_PATH}/templates/ 91 | 92 | sudo cp nginx/${NGINX_CONF} ${NGINX_CONF_DIR}/${NGINX_CONF} 93 | sudo cp -r ${LUA_MOD_DIR}/lib/* ${LIB_PATH}/ 94 | sudo cp -r ${LUA_MOD_DIR}/templates/* ${DATA_PATH}/templates/ 95 | 96 | sudo luarocks install lua-resty-http 0.17.1-0 97 | sudo luarocks install lua-cjson 2.1.0.10-1 98 | } 99 | 100 | 101 | check_nginx_dependency 102 | gen_apikey 103 | install 104 | 105 | 106 | echo "crowdsec-nginx-bouncer installed successfully" 107 | -------------------------------------------------------------------------------- /nginx/crowdsec_nginx.conf: -------------------------------------------------------------------------------- 1 | lua_package_path '/usr/local/lua/crowdsec/?.lua;;'; 2 | lua_shared_dict crowdsec_cache 50m; 3 | lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt; 4 | init_by_lua_block { 5 | cs = require "crowdsec" 6 | local ok, err = cs.init("/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf", "crowdsec-nginx-bouncer/v1.1.1") 7 | if ok == nil then 8 | ngx.log(ngx.ERR, "[Crowdsec] " .. err) 9 | error() 10 | end 11 | ngx.log(ngx.ALERT, "[Crowdsec] Initialisation done") 12 | } 13 | 14 | map $server_addr $unix { 15 | default 0; 16 | "~unix:" 1; 17 | } 18 | 19 | access_by_lua_block { 20 | local cs = require "crowdsec" 21 | if ngx.var.unix == "1" then 22 | ngx.log(ngx.DEBUG, "[Crowdsec] Unix socket request ignoring...") 23 | else 24 | cs.Allow(ngx.var.remote_addr) 25 | end 26 | } 27 | 28 | init_worker_by_lua_block { 29 | cs = require "crowdsec" 30 | local mode = cs.get_mode() 31 | if string.lower(mode) == "stream" then 32 | ngx.log(ngx.INFO, "Initializing stream mode for worker " .. tostring(ngx.worker.id())) 33 | cs.SetupStream() 34 | end 35 | 36 | if ngx.worker.id() == 0 then 37 | ngx.log(ngx.INFO, "Initializing metrics for worker " .. tostring(ngx.worker.id())) 38 | cs.SetupMetrics() 39 | end 40 | } 41 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | REQUIRE_SCRIPT="./lua-mod/uninstall.sh" 4 | NGINX_CONF="crowdsec_nginx.conf" 5 | NGINX_CONF_DIR="/etc/nginx/conf.d/" 6 | ACCESS_FILE="access.lua" 7 | LIB_PATH="/usr/local/lua/crowdsec/" 8 | DATA_PATH="/var/lib/crowdsec/lua/" 9 | SILENT="false" 10 | 11 | usage() { 12 | echo "Usage:" 13 | echo " ./uninstall.sh -h Display this help message." 14 | echo " ./uninstall.sh Uninstall the bouncer in interactive mode" 15 | echo " ./uninstall.sh -y Uninstall the bouncer and accept everything" 16 | exit 0 17 | } 18 | 19 | #Accept cmdline arguments to overwrite options. 20 | while [[ $# -gt 0 ]] 21 | do 22 | case $1 in 23 | -y|--yes) 24 | SILENT="true" 25 | shift 26 | ;; 27 | -h|--help) 28 | usage 29 | ;; 30 | esac 31 | shift 32 | done 33 | 34 | 35 | requirement() { 36 | if [ -f "$REQUIRE_SCRIPT" ]; then 37 | bash $REQUIRE_SCRIPT 38 | fi 39 | } 40 | 41 | 42 | remove_nginx_dependency() { 43 | DEPENDENCY=( 44 | "libnginx-mod-http-lua" 45 | "luarocks" 46 | "lua5.1" 47 | "gettext-base" 48 | ) 49 | for dep in ${DEPENDENCY[@]}; 50 | do 51 | dpkg -l | grep ${dep} > /dev/null 52 | if [[ $? == 0 ]]; then 53 | if [[ ${SILENT} == "true" ]]; then 54 | sudo apt-get install -y -qq ${dep} > /dev/null && echo "${dep} successfully removed" 55 | else 56 | echo "${dep} found, do you want to remove it (Y/n)? " 57 | read answer 58 | if [[ ${answer} == "" ]]; then 59 | answer="y" 60 | fi 61 | if [ "$answer" != "${answer#[Yy]}" ] ;then 62 | apt-get remove --purge -y -qq ${dep} > /dev/null && echo "${dep} successfully removed" 63 | fi 64 | fi 65 | fi 66 | done 67 | } 68 | 69 | 70 | uninstall() { 71 | rm ${NGINX_CONF_DIR}/${NGINX_CONF} 72 | rm -rf ${DATA_PATH} 73 | rm -rf ${LIB_PATH} 74 | } 75 | 76 | if ! [ $(id -u) = 0 ]; then 77 | log_err "Please run the uninstall script as root or with sudo" 78 | exit 1 79 | fi 80 | requirement 81 | remove_nginx_dependency 82 | uninstall 83 | echo "crowdsec-nginx-bouncer uninstalled successfully" -------------------------------------------------------------------------------- /upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LUA_MOD_DIR="./lua-mod" 4 | NGINX_CONF="crowdsec_nginx.conf" 5 | NGINX_CONF_DIR="/etc/nginx/conf.d/" 6 | ACCESS_FILE="access.lua" 7 | LIB_PATH="/usr/local/lua/crowdsec/" 8 | CONFIG_PATH="/etc/crowdsec/bouncers/" 9 | CONFIG_FILE="${CONFIG_PATH}crowdsec-nginx-bouncer.conf" 10 | OLD_CONFIG_FILE="/etc/crowdsec/crowdsec-nginx-bouncer.conf" 11 | DATA_PATH="/var/lib/crowdsec/lua/" 12 | 13 | install() { 14 | mkdir -p ${LIB_PATH}/plugins/crowdsec/ 15 | mkdir -p ${DATA_PATH}/templates/ 16 | 17 | cp nginx/${NGINX_CONF} ${NGINX_CONF_DIR}/${NGINX_CONF} 18 | cp -r ${LUA_MOD_DIR}/lib/* ${LIB_PATH}/ 19 | cp -r ${LUA_MOD_DIR}/templates/* ${DATA_PATH}/templates/ 20 | } 21 | 22 | migrate_conf() { 23 | if [ -f "$CONFIG_FILE" ]; then 24 | return 25 | fi 26 | if [ ! -f "$OLD_CONFIG_FILE" ]; then 27 | return 28 | fi 29 | echo "Found $OLD_CONFIG_FILE, but no $CONFIG_FILE. Migrating it." 30 | mv "$OLD_CONFIG_FILE" "$CONFIG_FILE" 31 | } 32 | 33 | if ! [ $(id -u) = 0 ]; then 34 | log_err "Please run the upgrade script as root or with sudo" 35 | exit 1 36 | fi 37 | 38 | if [ ! -d "${CONFIG_PATH}" ]; then 39 | echo "crowdsec-nginx-bouncer is not installed, please run the ./install.sh script" 40 | exit 1 41 | fi 42 | 43 | install 44 | migrate_conf 45 | echo "crowdsec-nginx-bouncer upgraded successfully" --------------------------------------------------------------------------------