Development
This commit is contained in:
parent
901e3b3f2d
commit
03ccf44c8c
3 changed files with 51 additions and 7 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue