Development
This commit is contained in:
parent
59ac3c5973
commit
3d0dc265ba
31 changed files with 1093 additions and 2794 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import re
|
||||
import os
|
||||
from view_common import run, load_ddns, public_ip_info, live_dhcp_leases, fmt_timestamp, BLOCKLISTS_DIR
|
||||
from config_utils import collect_layout_tokens, fmt_timestamp, BLOCKLISTS_DIR
|
||||
from factory import run, load_ddns
|
||||
from pages.ddns.view import public_ip_info
|
||||
from pages.dhcpleases.view import live_dhcp_leases
|
||||
|
||||
|
||||
def get_dnsmasq_stats():
|
||||
|
|
@ -32,12 +35,12 @@ def get_dnsmasq_stats():
|
|||
return stats
|
||||
|
||||
|
||||
def _count_blocked_today():
|
||||
def count_blocked_today():
|
||||
out = run("journalctl -u dnsmasq --since today --no-pager 2>/dev/null | grep -c 'is NXDOMAIN'")
|
||||
return out or '0'
|
||||
|
||||
|
||||
def _count_blocked_domains():
|
||||
def count_blocked_domains():
|
||||
try:
|
||||
total = sum(
|
||||
int(run(f'wc -l < "{BLOCKLISTS_DIR}/{f}"') or 0)
|
||||
|
|
@ -48,7 +51,7 @@ def _count_blocked_domains():
|
|||
return '-'
|
||||
|
||||
|
||||
def _bl_last_update():
|
||||
def bl_last_update():
|
||||
try:
|
||||
mtime = max(
|
||||
os.path.getmtime(f'{BLOCKLISTS_DIR}/{f}')
|
||||
|
|
@ -60,6 +63,7 @@ def _bl_last_update():
|
|||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = collect_layout_tokens(cfg)
|
||||
vlans = cfg.get('vlans', [])
|
||||
non_vpn_vlans = [v for v in vlans if not v.get('is_vpn')]
|
||||
vlan_names = [v.get('name', '') for v in vlans]
|
||||
|
|
@ -69,26 +73,25 @@ def collect_tokens(cfg):
|
|||
ddns = load_ddns()
|
||||
ip_str, domains_sub, last_obtained = public_ip_info(ddns)
|
||||
|
||||
return {
|
||||
'GENERAL_WAN_INTERFACE': str(net.get('wan_interface', '-')),
|
||||
'OVERVIEW_VLAN_NAMES': ', '.join(vlan_names) or '-',
|
||||
'STAT_VLAN_COUNT': str(len(non_vpn_vlans)),
|
||||
'STAT_LEASE_COUNT': str(len(live_dhcp_leases())),
|
||||
'STAT_BANNED_IP_COUNT': str(sum(1 for b in cfg.get('banned_ips', []) if b.get('enabled', True))),
|
||||
'STAT_BLOCKLIST_COUNT': str(len(cfg.get('dns_blocking', {}).get('blocklists', []))),
|
||||
'STAT_BLOCKED_TODAY': _count_blocked_today(),
|
||||
'STAT_BLOCKED_DOMAINS': _count_blocked_domains(),
|
||||
'STAT_BL_LAST_UPDATE': _bl_last_update(),
|
||||
'STAT_UPTIME': run('uptime -p') or '-',
|
||||
'STAT_NFTABLES_STATUS': 'Active' if run('nft list tables 2>/dev/null').strip() else 'Inactive',
|
||||
'STAT_PUBLIC_IP': ip_str,
|
||||
'STAT_DDNS_HOSTNAME': domains_sub,
|
||||
'DNS_CACHE_SIZE': str(dns.get('cache_size', '-')),
|
||||
'OVERVIEW_UPSTREAM_SERVERS': ', '.join(dns.get('upstream_servers', [])) or '-',
|
||||
'DNS_STAT_QUERIES': dns_stats['queries'],
|
||||
'DNS_STAT_HITS': dns_stats['hits'],
|
||||
'DNS_STAT_HIT_RATE': dns_stats['hit_rate'],
|
||||
'DNS_STAT_FORWARDED': dns_stats['forwarded'],
|
||||
'DNS_STAT_AUTH': dns_stats['auth'],
|
||||
'DNS_STAT_TCP_PEAK': dns_stats['tcp_peak'],
|
||||
}
|
||||
tokens['GENERAL_WAN_INTERFACE'] = str(net.get('wan_interface', '-'))
|
||||
tokens['OVERVIEW_VLAN_NAMES'] = ', '.join(vlan_names) or '-'
|
||||
tokens['STAT_VLAN_COUNT'] = str(len(non_vpn_vlans))
|
||||
tokens['STAT_LEASE_COUNT'] = str(len(live_dhcp_leases()))
|
||||
tokens['STAT_BANNED_IP_COUNT'] = str(sum(1 for b in cfg.get('banned_ips', []) if b.get('enabled', True)))
|
||||
tokens['STAT_BLOCKLIST_COUNT'] = str(len(cfg.get('dns_blocking', {}).get('blocklists', [])))
|
||||
tokens['STAT_BLOCKED_TODAY'] = count_blocked_today()
|
||||
tokens['STAT_BLOCKED_DOMAINS'] = count_blocked_domains()
|
||||
tokens['STAT_BL_LAST_UPDATE'] = bl_last_update()
|
||||
tokens['STAT_UPTIME'] = run('uptime -p') or '-'
|
||||
tokens['STAT_NFTABLES_STATUS'] = 'Active' if run('nft list tables 2>/dev/null').strip() else 'Inactive'
|
||||
tokens['STAT_PUBLIC_IP'] = ip_str
|
||||
tokens['STAT_DDNS_HOSTNAME'] = domains_sub
|
||||
tokens['DNS_CACHE_SIZE'] = str(dns.get('cache_size', '-'))
|
||||
tokens['OVERVIEW_UPSTREAM_SERVERS'] = ', '.join(dns.get('upstream_servers', [])) or '-'
|
||||
tokens['DNS_STAT_QUERIES'] = dns_stats['queries']
|
||||
tokens['DNS_STAT_HITS'] = dns_stats['hits']
|
||||
tokens['DNS_STAT_HIT_RATE'] = dns_stats['hit_rate']
|
||||
tokens['DNS_STAT_FORWARDED'] = dns_stats['forwarded']
|
||||
tokens['DNS_STAT_AUTH'] = dns_stats['auth']
|
||||
tokens['DNS_STAT_TCP_PEAK'] = dns_stats['tcp_peak']
|
||||
return tokens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue