utils/filtron.sh: add option to debug filtron requests

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2020-01-31 17:25:38 +01:00
parent 91a55e159e
commit 0bb8847087
2 changed files with 73 additions and 13 deletions

View File

@ -61,6 +61,7 @@ usage:
$(basename "$0") activate [service] $(basename "$0") activate [service]
$(basename "$0") deactivate [service] $(basename "$0") deactivate [service]
$(basename "$0") inspect [service] $(basename "$0") inspect [service]
$(basename "$0") option [debug-on|debug-off]
$(basename "$0") apache [install|remove] $(basename "$0") apache [install|remove]
@ -77,6 +78,8 @@ deactivate service
stop and deactivate service daemon (systemd unit) stop and deactivate service daemon (systemd unit)
inspect service inspect service
show service status and log show service status and log
option
set one of the available options
apache apache
install: apache site with a reverse proxy (ProxyPass) install: apache site with a reverse proxy (ProxyPass)
remove: apache site ${APACHE_FILTRON_SITE} remove: apache site ${APACHE_FILTRON_SITE}
@ -155,6 +158,13 @@ main() {
remove) remove_apache_site ;; remove) remove_apache_site ;;
*) usage "$_usage"; exit 42;; *) usage "$_usage"; exit 42;;
esac ;; esac ;;
option)
sudo_or_exit
case $2 in
debug-on) echo; enable_debug ;;
debug-off) echo; disable_debug ;;
*) usage "$_usage"; exit 42;;
esac ;;
*) usage "ERROR: unknown or missing command $1"; exit 42;; *) usage "ERROR: unknown or missing command $1"; exit 42;;
esac esac
@ -378,7 +388,12 @@ EOF
err_msg "Public service at ${PUBLIC_URL} is not available!" err_msg "Public service at ${PUBLIC_URL} is not available!"
fi fi
wait_key local _debug_on
if ask_yn "Enable filtron debug mode?"; then
enable_debug
_debug_on=1
fi
echo echo
systemctl --no-pager -l status filtron.service systemctl --no-pager -l status filtron.service
echo echo
@ -388,9 +403,66 @@ EOF
trap break 2 trap break 2
journalctl -f -u filtron journalctl -f -u filtron
done done
if [[ $_debug_on == 1 ]]; then
disable_debug
fi
return 0 return 0
} }
enable_debug() {
info_msg "try to enable debug mode ..."
python <<EOF
import sys, json
debug = {
u'name': u'debug request'
, u'filters': []
, u'interval': 0
, u'limit': 0
, u'actions': [{u'name': u'log'}]
}
with open('$FILTRON_RULES') as rules:
j = json.load(rules)
pos = None
for i in range(len(j)):
if j[i].get('name') == 'debug request':
pos = i
break
if pos is not None:
j[pos] = debug
else:
j.append(debug)
with open('$FILTRON_RULES', 'w') as rules:
json.dump(j, rules, indent=2, sort_keys=True)
EOF
systemctl restart "${SERVICE_NAME}.service"
}
disable_debug() {
info_msg "try to disable debug mode ..."
python <<EOF
import sys, json
with open('$FILTRON_RULES') as rules:
j = json.load(rules)
pos = None
for i in range(len(j)):
if j[i].get('name') == 'debug request':
pos = i
break
if pos is not None:
del j[pos]
with open('$FILTRON_RULES', 'w') as rules:
json.dump(j, rules, indent=2, sort_keys=True)
EOF
systemctl restart "${SERVICE_NAME}.service"
}
install_apache_site() { install_apache_site() {
rst_title "Install Apache site $APACHE_FILTRON_SITE" rst_title "Install Apache site $APACHE_FILTRON_SITE"

View File

@ -1,16 +1,4 @@
[{ [{
"name":"suspiciously frequent queries",
"filters":[
"Param:q",
"Path=^(/|/search)$"
],
"interval":120,
"limit":9,
"actions":[
{"name":"log"}
]
},
{
"name":"search request", "name":"search request",
"filters":[ "filters":[
"Param:q", "Param:q",