diff --git a/docker/routlin-dash/app/pages/dnsblocking/action.py b/docker/routlin-dash/app/pages/dnsblocking/action.py index d7b526b..4c43657 100644 --- a/docker/routlin-dash/app/pages/dnsblocking/action.py +++ b/docker/routlin-dash/app/pages/dnsblocking/action.py @@ -73,8 +73,13 @@ def _parse_fields(): @bp.route('/api/dnsblocking/search', methods=['GET']) @auth.require_level('viewer') def api_blocklist_search(): - term = request.args.get('term', '').strip() - match = request.args.get('match', 'partial') + term = request.args.get('term', '').strip() + match = request.args.get('match', 'partial') + blocklist = request.args.get('blocklist', '').strip() + try: + limit = max(1, min(5000, int(request.args.get('limit', 500)))) + except (ValueError, TypeError): + limit = 500 if not term: return jsonify({'results': [], 'count': 0, 'truncated': False}) if match not in ('exact', 'starts_with', 'ends_with', 'partial'): @@ -97,16 +102,19 @@ def api_blocklist_search(): db_path = str(Path(config_utils.BLOCKLISTS_DIR) / 'domains.db') try: con = sqlite3.connect(db_path) + bl_filter = "AND b.name = ?" if blocklist else "" + sql_params = (param, blocklist) if blocklist else (param,) rows = con.execute(f""" SELECT d.domain, GROUP_CONCAT(b.name, '|') FROM domains d JOIN blocklists b ON b.id = d.blocklist_id {sql_where} + {bl_filter} GROUP BY d.domain ORDER BY d.domain - LIMIT 501 - """, (param,)).fetchall() - capped_rows = rows[:500] + LIMIT ? + """, sql_params + (limit + 1,)).fetchall() + capped_rows = rows[:limit] domain_list = [r[0] for r in capped_rows] phs = ','.join('?' * len(domain_list)) overridden = set( @@ -124,7 +132,7 @@ def api_blocklist_search(): for bl_name in vlan.get('use_blocklists', []): bl_vlans.setdefault(bl_name, []).append(vlan['name']) - truncated = len(rows) > 500 + truncated = len(rows) > limit results = [] for domain, bl_str in capped_rows: diff --git a/docker/routlin-dash/app/pages/dnsblocking/content.json b/docker/routlin-dash/app/pages/dnsblocking/content.json index 25e83df..418c5e8 100644 --- a/docker/routlin-dash/app/pages/dnsblocking/content.json +++ b/docker/routlin-dash/app/pages/dnsblocking/content.json @@ -20,7 +20,7 @@ "items": [ { "type": "raw_html", - "html": "
" + "html": "%BLOCKLIST_SEARCH_HTML%" } ] }, diff --git a/docker/routlin-dash/app/pages/dnsblocking/view.py b/docker/routlin-dash/app/pages/dnsblocking/view.py index 099811e..7fb7807 100644 --- a/docker/routlin-dash/app/pages/dnsblocking/view.py +++ b/docker/routlin-dash/app/pages/dnsblocking/view.py @@ -121,6 +121,42 @@ def collect_tokens(cfg): tokens['DNS_LOG_TAIL'], tokens['DNS_LOG_SUMMARY'] = _dnsblocking_log_tail(cfg) blocklists = cfg.get('dns_blocking', {}).get('blocklists', []) tokens['BLOCKLIST_EXISTING_NAMES_JS'] = json.dumps([bl.get('name', '') for bl in blocklists]) + bl_options = ''.join( + f'' + for bl in blocklists if bl.get('name') + ) + tokens['BLOCKLIST_SEARCH_HTML'] = ( + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '
' + '
' + '
' + ) vlans = cfg.get('vlans', []) vlan_checkboxes = ''.join( f'