Development
This commit is contained in:
parent
563d82daf3
commit
70ccfe2c29
48 changed files with 549 additions and 578 deletions
|
|
@ -1,10 +1,8 @@
|
|||
import json
|
||||
import re
|
||||
import os
|
||||
from config_utils import (
|
||||
collect_layout_tokens, load_datasource, CONFIGS_DIR, relative_time,
|
||||
)
|
||||
from factory import load_ddns, load_json, build_table, table_token_key, iter_table_items, PAGES_DIR
|
||||
import config_utils
|
||||
import factory
|
||||
import mod_validation as validate
|
||||
|
||||
|
||||
|
|
@ -20,9 +18,9 @@ def _parse_interval_to_seconds(s):
|
|||
|
||||
|
||||
def _ddns_log_tail():
|
||||
log_path = f'{CONFIGS_DIR}/ddns.log'
|
||||
log_path = f'{config_utils.CONFIGS_DIR}/ddns.log'
|
||||
try:
|
||||
log_max_kb = load_ddns().get('general', {}).get('log_max_kb', 1024)
|
||||
log_max_kb = factory.load_ddns().get('general', {}).get('log_max_kb', 1024)
|
||||
size_kb = os.path.getsize(log_path) / 1024
|
||||
with open(log_path) as f:
|
||||
lines = f.readlines()
|
||||
|
|
@ -49,9 +47,9 @@ def _ddns_log_tail():
|
|||
def _read_cached_ip():
|
||||
try:
|
||||
best_ip, best_mtime = '', 0.0
|
||||
for fname in os.listdir(CONFIGS_DIR):
|
||||
for fname in os.listdir(config_utils.CONFIGS_DIR):
|
||||
if fname.startswith('.ddns-last-ip-'):
|
||||
path = f'{CONFIGS_DIR}/{fname}'
|
||||
path = f'{config_utils.CONFIGS_DIR}/{fname}'
|
||||
mtime = os.path.getmtime(path)
|
||||
if mtime > best_mtime:
|
||||
ip = open(path).read().strip()
|
||||
|
|
@ -70,7 +68,7 @@ def public_ip_info(ddns_cfg):
|
|||
all_hosts.extend(p.get('hostnames', p.get('subdomains', [])))
|
||||
domains_sub = ', '.join(all_hosts)
|
||||
ip, mtime = _read_cached_ip()
|
||||
last_obtained = f'Obtained: {relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago' if mtime else ''
|
||||
last_obtained = f'Obtained: {config_utils.relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago' if mtime else ''
|
||||
if ip:
|
||||
return ip, domains_sub, last_obtained
|
||||
return 'Offline', domains_sub, ''
|
||||
|
|
@ -79,15 +77,15 @@ def public_ip_info(ddns_cfg):
|
|||
def ddns_last_checked():
|
||||
from datetime import datetime, timezone
|
||||
try:
|
||||
mtime = os.path.getmtime(f'{CONFIGS_DIR}/.ddns-last-service')
|
||||
return f'Last checked: {relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago'
|
||||
mtime = os.path.getmtime(f'{config_utils.CONFIGS_DIR}/.ddns-last-service')
|
||||
return f'Last checked: {config_utils.relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago'
|
||||
except OSError:
|
||||
return 'Last checked: ---'
|
||||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = collect_layout_tokens(cfg)
|
||||
ddns = load_ddns()
|
||||
tokens = config_utils.collect_layout_tokens(cfg)
|
||||
ddns = factory.load_ddns()
|
||||
ddns_gen = ddns.get('general', {})
|
||||
tokens['DDNS_TIMER_INTERVAL'] = ddns_gen.get('timer_interval', '-')
|
||||
interval_secs = _parse_interval_to_seconds(ddns_gen.get('timer_interval', '')) or 600
|
||||
|
|
@ -111,8 +109,8 @@ def collect_tokens(cfg):
|
|||
tokens['STAT_PUBLIC_IP_LAST_OBTAINED'] = last_obtained
|
||||
tokens['STAT_PUBLIC_IP_LAST_CHECKED'] = ddns_last_checked()
|
||||
tokens['DDNS_LOG_TAIL'], tokens['DDNS_LOG_SUMMARY'] = _ddns_log_tail()
|
||||
content = load_json(f'{PAGES_DIR}/ddns/content.json')
|
||||
for table_item in iter_table_items(content.get('items', [])):
|
||||
content = factory.load_json(f'{factory.PAGES_DIR}/ddns/content.json')
|
||||
for table_item in factory.iter_table_items(content.get('items', [])):
|
||||
ds = table_item.get('datasource', '')
|
||||
tokens[table_token_key(ds)] = build_table(table_item, tokens, load_datasource(ds))
|
||||
tokens[factory.table_token_key(ds)] = factory.build_table(table_item, tokens, config_utils.load_datasource(ds))
|
||||
return tokens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue