@@ -61,6 +61,7 @@ usage:
6161 $(basename "$0") activate [service]
6262 $(basename "$0") deactivate [service]
6363 $(basename "$0") inspect [service]
64+ $(basename "$0") option [debug-on|debug-off]
6465 $(basename "$0") apache [install|remove]
6566
6667
@@ -77,6 +78,8 @@ deactivate service
7778 stop and deactivate service daemon (systemd unit)
7879inspect service
7980 show service status and log
81+option
82+ set one of the available options
8083apache
8184 install: apache site with a reverse proxy (ProxyPass)
8285 remove: apache site ${APACHE_FILTRON_SITE}
@@ -155,6 +158,13 @@ main() {
155158 remove) remove_apache_site ;;
156159 *) usage "$_usage"; exit 42;;
157160 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 ;;
158168
159169 *) usage "ERROR: unknown or missing command $1"; exit 42;;
160170 esac
@@ -378,7 +388,12 @@ EOF
378388 err_msg "Public service at ${PUBLIC_URL} is not available!"
379389 fi
380390
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+
382397 echo
383398 systemctl --no-pager -l status filtron.service
384399 echo
@@ -388,9 +403,66 @@ EOF
388403 trap break 2
389404 journalctl -f -u filtron
390405 done
406+
407+ if [[ $_debug_on == 1 ]]; then
408+ disable_debug
409+ fi
391410 return 0
392411}
393412
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+
394466install_apache_site() {
395467
396468 rst_title "Install Apache site $APACHE_FILTRON_SITE"