Development
This commit is contained in:
parent
094847966a
commit
6b31c7266d
2 changed files with 42 additions and 2 deletions
|
|
@ -1,12 +1,14 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import copy
|
import copy
|
||||||
import re
|
import re
|
||||||
from flask import Blueprint, request, redirect, flash
|
from flask import Blueprint, request, redirect, flash, send_file
|
||||||
from auth import require_level
|
from auth import require_level
|
||||||
from config_utils import load_config, record_group, diff_fields, verify_config_hash, queued_msg
|
from config_utils import load_config, record_group, diff_fields, verify_config_hash, queued_msg, CONFIGS_DIR
|
||||||
import sanitize
|
import sanitize
|
||||||
import validation as validate
|
import validation as validate
|
||||||
|
|
||||||
|
DNS_LOG_FILE = Path(CONFIGS_DIR) / 'dns-blocklists.log'
|
||||||
|
|
||||||
_PAGE = Path(__file__).parent.name
|
_PAGE = Path(__file__).parent.name
|
||||||
|
|
||||||
bp = Blueprint(_PAGE, __name__)
|
bp = Blueprint(_PAGE, __name__)
|
||||||
|
|
@ -222,3 +224,23 @@ def logging_save():
|
||||||
changes = diff_fields(before, cfg['dns_blocking']['general'])
|
changes = diff_fields(before, cfg['dns_blocking']['general'])
|
||||||
flash(record_group(cfg, 'dns_blocking.general', None, None, changes, 'core apply', queue=False), 'success')
|
flash(record_group(cfg, 'dns_blocking.general', None, None, changes, 'core apply', queue=False), 'success')
|
||||||
return redirect(f'/{_PAGE}')
|
return redirect(f'/{_PAGE}')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/action/dnsblocking/logging_clear', methods=['POST'])
|
||||||
|
@require_level('administrator')
|
||||||
|
def logging_clear():
|
||||||
|
try:
|
||||||
|
DNS_LOG_FILE.write_text('')
|
||||||
|
flash('DNS blocking log cleared.', 'success')
|
||||||
|
except Exception as ex:
|
||||||
|
flash(f'Could not clear log: {ex}', 'error')
|
||||||
|
return redirect(f'/{_PAGE}')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/action/dnsblocking/logging_download', methods=['GET'])
|
||||||
|
@require_level('administrator')
|
||||||
|
def logging_download():
|
||||||
|
if not DNS_LOG_FILE.is_file():
|
||||||
|
flash('Log file not found.', 'error')
|
||||||
|
return redirect(f'/{_PAGE}')
|
||||||
|
return send_file(DNS_LOG_FILE, as_attachment=True, download_name='dns-blocklists.log', mimetype='text/plain')
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,24 @@
|
||||||
"type": "raw_html",
|
"type": "raw_html",
|
||||||
"html": "%DNS_LOG_SUMMARY%"
|
"html": "%DNS_LOG_SUMMARY%"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "button_row",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "button_ghost",
|
||||||
|
"action": "/action/dnsblocking/logging_download",
|
||||||
|
"text": "Download Log"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "button_danger",
|
||||||
|
"formaction": "/action/dnsblocking/logging_clear",
|
||||||
|
"text": "Clear Log"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hr"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "button_row",
|
"type": "button_row",
|
||||||
"items": [
|
"items": [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue