Development
This commit is contained in:
parent
563d82daf3
commit
70ccfe2c29
48 changed files with 549 additions and 578 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import json
|
||||
from config_utils import collect_layout_tokens, load_datasource, fmt_timestamp, fmt_bytes
|
||||
from factory import run, load_json, build_table, table_token_key, iter_table_items, PAGES_DIR
|
||||
import config_utils
|
||||
import factory
|
||||
|
||||
|
||||
def live_vpn_sessions():
|
||||
rows = []
|
||||
out = run('wg show all dump 2>/dev/null')
|
||||
out = factory.run('wg show all dump 2>/dev/null')
|
||||
for line in out.splitlines():
|
||||
parts = line.split('\t')
|
||||
if len(parts) == 9:
|
||||
|
|
@ -15,15 +15,15 @@ def live_vpn_sessions():
|
|||
'interface': interface,
|
||||
'tunnel_ip': allowed_ips.split(',')[0].split('/')[0] if allowed_ips else '-',
|
||||
'endpoint': endpoint if endpoint != '(none)' else '-',
|
||||
'last_handshake': fmt_timestamp(int(last_hs)) if last_hs.isdigit() and last_hs != '0' else 'Never',
|
||||
'rx_bytes': fmt_bytes(int(rx)) if rx.isdigit() else '-',
|
||||
'tx_bytes': fmt_bytes(int(tx)) if tx.isdigit() else '-',
|
||||
'last_handshake': config_utils.fmt_timestamp(int(last_hs)) if last_hs.isdigit() and last_hs != '0' else 'Never',
|
||||
'rx_bytes': config_utils.fmt_bytes(int(rx)) if rx.isdigit() else '-',
|
||||
'tx_bytes': config_utils.fmt_bytes(int(tx)) if tx.isdigit() else '-',
|
||||
})
|
||||
return rows
|
||||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = collect_layout_tokens(cfg)
|
||||
tokens = config_utils.collect_layout_tokens(cfg)
|
||||
vlans = cfg.get('vlans', [])
|
||||
wg_vlans_list = sorted(
|
||||
[v for v in vlans if v.get('is_vpn')],
|
||||
|
|
@ -55,9 +55,9 @@ def collect_tokens(cfg):
|
|||
tokens['VPN_DNS_SERVER'] = str(overrides.get('dns_servers', ''))
|
||||
tokens['VPN_MTU'] = str(overrides.get('mtu', ''))
|
||||
tokens['VPN_GATEWAY'] = vpn_gateway
|
||||
content = load_json(f'{PAGES_DIR}/vpn/content.json')
|
||||
for table_item in iter_table_items(content.get('items', [])):
|
||||
content = factory.load_json(f'{factory.PAGES_DIR}/vpn/content.json')
|
||||
for table_item in factory.iter_table_items(content.get('items', [])):
|
||||
ds = table_item.get('datasource', '')
|
||||
rows = live_vpn_sessions() if ds == 'live:vpn_sessions' else load_datasource(ds)
|
||||
tokens[table_token_key(ds)] = build_table(table_item, tokens, rows)
|
||||
rows = live_vpn_sessions() if ds == 'live:vpn_sessions' else config_utils.load_datasource(ds)
|
||||
tokens[factory.table_token_key(ds)] = factory.build_table(table_item, tokens, rows)
|
||||
return tokens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue