on master help sign in
utils/filtron.sh: add option to debug filtron requests
0bb8847Markus Heiser
utils/filtron.sh+73−1
@@ -61,6 +61,7 @@ usage:
61 $(basename "$0") activate [service]
61 $(basename "$0") activate [service]
62 $(basename "$0") deactivate [service]
62 $(basename "$0") deactivate [service]
63 $(basename "$0") inspect [service]
63 $(basename "$0") inspect [service]
64+ $(basename "$0") option [debug-on|debug-off]
64 $(basename "$0") apache [install|remove]
65 $(basename "$0") apache [install|remove]
65
66
66
67
@@ -77,6 +78,8 @@ deactivate service
77 stop and deactivate service daemon (systemd unit)
78 stop and deactivate service daemon (systemd unit)
78inspect service
79inspect service
79 show service status and log
80 show service status and log
81+option
82+ set one of the available options
80apache
83apache
81 install: apache site with a reverse proxy (ProxyPass)
84 install: apache site with a reverse proxy (ProxyPass)
82 remove: apache site ${APACHE_FILTRON_SITE}
85 remove: apache site ${APACHE_FILTRON_SITE}
@@ -155,6 +158,13 @@ main() {
155 remove) remove_apache_site ;;
158 remove) remove_apache_site ;;
156 *) usage "$_usage"; exit 42;;
159 *) usage "$_usage"; exit 42;;
157 esac ;;
160 esac ;;
161+ option)
162+ sudo_or_exit
163+ case $2 in
164+ debug-on) echo; enable_debug ;;
165+ debug-off) echo; disable_debug ;;
166+ *) usage "$_usage"; exit 42;;
167+ esac ;;
158
168
159 *) usage "ERROR: unknown or missing command $1"; exit 42;;
169 *) usage "ERROR: unknown or missing command $1"; exit 42;;
160 esac
170 esac
@@ -378,7 +388,12 @@ EOF
378 err_msg "Public service at ${PUBLIC_URL} is not available!"
388 err_msg "Public service at ${PUBLIC_URL} is not available!"
379 fi
389 fi
380
390
381− wait_key
391+ local _debug_on
392+ if ask_yn "Enable filtron debug mode?"; then
393+ enable_debug
394+ _debug_on=1
395+ fi
396+
382 echo
397 echo
383 systemctl --no-pager -l status filtron.service
398 systemctl --no-pager -l status filtron.service
384 echo
399 echo
@@ -388,9 +403,66 @@ EOF
388 trap break 2
403 trap break 2
389 journalctl -f -u filtron
404 journalctl -f -u filtron
390 done
405 done
406+
407+ if [[ $_debug_on == 1 ]]; then
408+ disable_debug
409+ fi
391 return 0
410 return 0
392}
411}
393
412
413+
414+enable_debug() {
415+ info_msg "try to enable debug mode ..."
416+ python <<EOF
417+import sys, json
418+
419+debug = {
420+ u'name': u'debug request'
421+ , u'filters': []
422+ , u'interval': 0
423+ , u'limit': 0
424+ , u'actions': [{u'name': u'log'}]
425+}
426+
427+with open('$FILTRON_RULES') as rules:
428+ j = json.load(rules)
429+
430+pos = None
431+for i in range(len(j)):
432+ if j[i].get('name') == 'debug request':
433+ pos = i
434+ break
435+if pos is not None:
436+ j[pos] = debug
437+else:
438+ j.append(debug)
439+with open('$FILTRON_RULES', 'w') as rules:
440+ json.dump(j, rules, indent=2, sort_keys=True)
441+
442+EOF
443+ systemctl restart "${SERVICE_NAME}.service"
444+}
445+
446+disable_debug() {
447+ info_msg "try to disable debug mode ..."
448+ python <<EOF
449+import sys, json
450+with open('$FILTRON_RULES') as rules:
451+ j = json.load(rules)
452+
453+pos = None
454+for i in range(len(j)):
455+ if j[i].get('name') == 'debug request':
456+ pos = i
457+ break
458+if pos is not None:
459+ del j[pos]
460+ with open('$FILTRON_RULES', 'w') as rules:
461+ json.dump(j, rules, indent=2, sort_keys=True)
462+EOF
463+ systemctl restart "${SERVICE_NAME}.service"
464+}
465+
394install_apache_site() {
466install_apache_site() {
395
467
396 rst_title "Install Apache site $APACHE_FILTRON_SITE"
468 rst_title "Install Apache site $APACHE_FILTRON_SITE"
utils/templates/etc/filtron/rules.json−12
@@ -1,16 +1,4 @@
1[{
1[{
2− "name":"suspiciously frequent queries",
3− "filters":[
4− "Param:q",
5− "Path=^(/|/search)$"
6− ],
7− "interval":120,
8− "limit":9,
9− "actions":[
10− {"name":"log"}
11− ]
12− },
13− {
14 "name":"search request",
2 "name":"search request",
15 "filters":[
3 "filters":[
16 "Param:q",
4 "Param:q",