Skip to content

Commit

Permalink
feat(inventory): add functions to list DNS feeds and retrieve ad bloc…
Browse files Browse the repository at this point in the history
…k status
  • Loading branch information
stephdl committed Nov 27, 2024
1 parent 078722d commit 533a2b1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/nethsec/inventory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
import subprocess
import configparser
import json

# run a bash command and return the error code
def _run_status(cmd):
Expand Down Expand Up @@ -146,6 +147,34 @@ def fact_threat_shield(uci: EUci):
pass
return ret

def list_dns_feeds():
# Decompress and read the JSON file /etc/adblock/combined.sources.gz
sources = '/etc/adblock/combined.sources.gz'
if os.path.exists(sources) and os.path.getsize(sources) > 0:
data = subprocess.run(["gunzip", "-c", sources], capture_output=True).stdout
return json.loads(data)
else:
return {}

def fact_ad_block(uci: EUci):
ret = { 'enabled': False, 'community': 0, 'enterprise': 0 }
ret['enabled'] = uci.get('adblock', 'global', 'ts_enabled', default='0') == '1'
feeds = list_dns_feeds()
try:
enabled_feeds = list(uci.get_all('adblock', 'global', 'adb_sources'))
except:
enabled_feeds = []
for f in feeds:
feed = feeds[f]
enabled = f in enabled_feeds
if enabled: # Count only if the feed is enabled
if 'nethesis-blacklists' in feed.get('url', ''):
ret['enterprise'] += 1
else:
ret['community'] += 1
return ret


def fact_ui(uci: EUci):
ret = { 'luci': False, 'port443': False, 'port9090': False }
ret['luci'] = uci.get('ns-ui', 'config', 'luci_enable', default='0') == '1'
Expand Down

0 comments on commit 533a2b1

Please sign in to comment.