From afffd9f74d08e02f458c26d139827b18a6d1601d Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Fri, 8 Jan 2021 14:26:33 +0100 Subject: [PATCH] Added monit to backend CMS --- CMS/Backend/apache-siteBackend-unconfigured | 12 +++++++ CMS/Backend/conf.sh | 3 +- CMS/Backend/nginx-siteBackend-unconfigured | 5 +++ CoreModules/apache/conf.sh | 11 ++++-- CoreModules/nginx/conf.sh | 12 +++++++ Scripts/toggles/toggle-Monit_APACHE.sh | 39 +++++++++++++++++++++ Scripts/toggles/toggle-Monit_NGINX.sh | 39 +++++++++++++++++++++ 7 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 Scripts/toggles/toggle-Monit_APACHE.sh create mode 100644 Scripts/toggles/toggle-Monit_NGINX.sh diff --git a/CMS/Backend/apache-siteBackend-unconfigured b/CMS/Backend/apache-siteBackend-unconfigured index 435201a..275680c 100644 --- a/CMS/Backend/apache-siteBackend-unconfigured +++ b/CMS/Backend/apache-siteBackend-unconfigured @@ -20,4 +20,16 @@ Alias /backend/database /usr/share/phpmyadmin + + RewriteEngine on + RewriteRule /monit /monit/$1 [R] + + + #enables/disables monit-websocket + deny from all + ProxyPass unix:/var/run/monit/monit.sock|http://127.0.0.1/ + ProxyPassReverse unix:/var/run/monit/monit.sock|http://127.0.0.1/ + + + #endConf diff --git a/CMS/Backend/conf.sh b/CMS/Backend/conf.sh index 10662aa..cacae23 100644 --- a/CMS/Backend/conf.sh +++ b/CMS/Backend/conf.sh @@ -11,4 +11,5 @@ chown Backend:Backend -R /var/log/PhpMyAdmin systemctl reload "$phpFPMService" #Auto disable backends at night echo "0 0 * * * root bash /opt/toggle/toggle-Netdata.sh -d > >/dev/null 2>&1" >> /etc/cron.d/autodisablebackend -echo "0 0 * * * root bash /opt/toggle/toggle-PhpMyAdmin.sh -d > >/dev/null 2>&1" >> /etc/cron.d/autodisablebackend \ No newline at end of file +echo "0 0 * * * root bash /opt/toggle/toggle-PhpMyAdmin.sh -d > >/dev/null 2>&1" >> /etc/cron.d/autodisablebackend +echo "0 0 * * * root bash /opt/toggle/toggle-MonitWebui.sh -d > >/dev/null 2>&1" >> /etc/cron.d/autodisablebackend \ No newline at end of file diff --git a/CMS/Backend/nginx-siteBackend-unconfigured b/CMS/Backend/nginx-siteBackend-unconfigured index cdaaebb..644b72b 100644 --- a/CMS/Backend/nginx-siteBackend-unconfigured +++ b/CMS/Backend/nginx-siteBackend-unconfigured @@ -34,6 +34,11 @@ location = /backend/netdata { } } + location /backend/monit/ { + deny all; #enables/disables monit-websocket + proxypass http://unix:/var/run/monit/monit.sock:/; + } + location ~ /\.ht { deny all; } diff --git a/CoreModules/apache/conf.sh b/CoreModules/apache/conf.sh index a46ec9b..d6dacb2 100644 --- a/CoreModules/apache/conf.sh +++ b/CoreModules/apache/conf.sh @@ -9,6 +9,7 @@ if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist a2dismod mpm_prefork > $OUTPUT 2>&1 a2enmod actions fcgid alias proxy_fcgi ssl headers http2 setenvif socache_shmcb > $OUTPUT 2>&1 mkdir -p "$apacheConfDir"/snippets/ + monitconf=/etc/monit/monitrc elif [ "$shortdist" = "el8" ]; then echo 'IncludeOptional conf-enabled/*.conf' >>/etc/httpd/conf/httpd.conf echo 'IncludeOptional sites-enabled/*.conf' >>/etc/httpd/conf/httpd.conf @@ -18,6 +19,7 @@ elif [ "$shortdist" = "el8" ]; then mkdir -p /etc/httpd/{sites-available,sites-enabled,conf-enabled,conf-available,snippets} #getting aditional apache config for centos curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/CoreModules/apache/config/apache2/conf-httpd-custom.conf -o "$apacheConfDir"/conf-enabled/zzz-Httpd-custom.conf + monitconf=/etc/monitrc fi curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/CoreModules/apache/config/apache2/snippets-ssl.conf -o "$apacheConfDir"/snippets/apa-ssl.conf @@ -54,12 +56,15 @@ ln -s "$apacheConfDir"/sites-available/Backend_nossl.conf "$apacheConfDir"/sites curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/CoreModules/apache/config/apache2/site_ssl-unconfigured >> "$apacheConfDir"/sites-available/Backend_ssl.conf sed -i -e 's/DOMAINname/'$hostname'/g' "$apacheConfDir"/sites-available/Backend_ssl.conf - +#BackendToggle mkdir -p /opt/toggle +##Phpmyadmin curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/toggles/toggle-PhpMyAdmin_APACHE.sh -o /opt/toggle/toggle-PhpMyAdmin.sh sed -i -e 's/APASRV/'$apacheService'/' -e 's#APADIR#'$apacheConfDir'#' /opt/toggle/toggle-PhpMyAdmin.sh - - +##monit +curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/toggles/toggle-Monit_APACHE.sh -o /opt/toggle/toggle-MonitWebui.sh +sed -i -e 's/MONITCONF/'$monitconf'/' -e 's/APASRV/'$apacheService'/' -e 's#APADIR#'$apacheConfDir'#' /opt/toggle/toggle-MonitWebui.sh +unset monitconf # custom Welcome page diff --git a/CoreModules/nginx/conf.sh b/CoreModules/nginx/conf.sh index 627fd53..3e397cd 100644 --- a/CoreModules/nginx/conf.sh +++ b/CoreModules/nginx/conf.sh @@ -36,9 +36,21 @@ ln -s /etc/nginx/sites-available/Backend_nossl /etc/nginx/sites-enabled/Backend curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/CoreModules/nginx/config/nginx/site_ssl-unconfigured >> /etc/nginx/sites-available/Backend_ssl sed -i -e 's/DOMAINname/'$hostname'/g' /etc/nginx/sites-available/Backend_ssl +#toggles mkdir -p /opt/toggle +##phpmyadmin toggle curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/toggles/toggle-Netdata_NGINX.sh -o /opt/toggle/toggle-Netdata.sh curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/toggles/toggle-PhpMyAdmin_NGINX.sh -o /opt/toggle/toggle-PhpMyAdmin.sh +##monit toggle +if [ "$shortdist" = "ubu1804" ] || [ "$shortdist" = "ubu2004" ] || [ "$shortdist" = "deb10" ] ; then + monitconf=/etc/monit/monitrc +elif [ "$shortdist" = "el8" ]; then + monitconf=/etc/monitrc +fi +curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/Scripts/toggles/toggle-Monit_NGINX.sh -o /opt/toggle/toggle-MonitWebui.sh +sed -i -e 's/MONITCONF/'$monitconf'/' /opt/toggle/toggle-MonitWebui.sh +unset monitconf + # custom Welcome page echo "$webserv is functioning normally" > /usr/share/nginx/html/index.html diff --git a/Scripts/toggles/toggle-Monit_APACHE.sh b/Scripts/toggles/toggle-Monit_APACHE.sh new file mode 100644 index 0000000..122b4b4 --- /dev/null +++ b/Scripts/toggles/toggle-Monit_APACHE.sh @@ -0,0 +1,39 @@ +function usage { + echo "Usage: $0 [option...]" >&2 + echo + echo " -e, Enable MonitWebui" + echo " -d, Disable MonitWebui" + echo " -h, Shows this information" + echo +} +if [ -n "$1" ]; then + if [[ ! -f /etc/ICTM/toggle.conf ]]; then + echo "Creating File" + touch /etc/ICTM/toggle.conf + fi + source /etc/ICTM/toggle.conf + if [ -z "$MonitWeb" ]; then + echo "Creating Var" + echo "MonitWeb=3" >> /etc/ICTM/toggle.conf + MonitWeb=3 + fi + if [[ "$1" = "-d" && "$MonitWeb" != 0 ]]; then + echo "Disable MonitWebui" + sed -i '/MonitWeb=/c\MonitWeb=0' /etc/ICTM/toggle.conf + sed -i --follow-symlinks '/#enables\/disables monit-websocket/!b;n;cdeny from all' /APADIR/sites-enabled/010-Backend.conf + sed -i '/#enables\/disables monit-websocket/ s/^#*/#/' MONITCONF + systemctl reload APASRV monit + elif [[ "$1" = "-e" && "$MonitWeb" != 1 ]]; then + echo "Enable MonitWebui" + sed -i '/MonitWeb=/c\MonitWeb=1' /etc/ICTM/toggle.conf + sed -i --follow-symlinks '/#enables\/disables monit-websocket/!b;n;c#deny from all' /APADIR/sites-enabled/010-Backend.conf + sed -i '/#enables\/disables monit-websocket/ s/^.//' MONITCONF + systemctl reload APASRV monit + elif [[ "$1" = "-h" ]]; then + usage + else + echo "Oopsie!" + fi +else + usage +fi \ No newline at end of file diff --git a/Scripts/toggles/toggle-Monit_NGINX.sh b/Scripts/toggles/toggle-Monit_NGINX.sh new file mode 100644 index 0000000..4091ad4 --- /dev/null +++ b/Scripts/toggles/toggle-Monit_NGINX.sh @@ -0,0 +1,39 @@ +function usage { + echo "Usage: $0 [option...]" >&2 + echo + echo " -e, Enable MonitWebui" + echo " -d, Disable MonitWebui" + echo " -h, Shows this information" + echo +} +if [ -n "$1" ]; then + if [[ ! -f /etc/ICTM/toggle.conf ]]; then + echo "Creating File" + touch /etc/ICTM/toggle.conf + fi + source /etc/ICTM/toggle.conf + if [ -z "$MonitWeb" ]; then + echo "Creating Var" + echo "MonitWeb=3" >> /etc/ICTM/toggle.conf + MonitWeb=3 + fi + if [[ "$1" = "-d" && "$MonitWeb" != 0 ]]; then + echo "Disable MonitWebui" + sed -i '/MonitWeb=/c\MonitWeb=0' /etc/ICTM/toggle.conf + sed -i --follow-symlinks '/deny all; #enables\/disables monit-websocket/c\ deny all; #enables\/disables monit-websocket' /etc/nginx/sites-enabled/Backend + sed -i '/#enables\/disables monit-websocket/ s/^#*/#/' MONITCONF + systemctl reload nginx monit + elif [[ "$1" = "-e" && "$MonitWeb" != 1 ]]; then + echo "Enable MonitWebui" + sed -i '/MonitWeb=/c\MonitWeb=1' /etc/ICTM/toggle.conf + sed -i --follow-symlinks '/deny all; #enables\/disables monit-websocket/c\ #deny all; #enables\/disables monit-websocket' /etc/nginx/sites-enabled/Backend + sed -i '/#enables\/disables monit-websocket/ s/^.//' MONITCONF + systemctl reload nginx monit + elif [[ "$1" = "-h" ]]; then + usage + else + echo "Oopsie!" + fi +else + usage +fi \ No newline at end of file