APmanageur Wi-Fi V1.0

This commit is contained in:
yoannmultigaming committed 2026-11-21 03:29:09 +01:00
1 parent fe6594b964
commit ceeab6fa4a
7 files changed
+369 -6

No files matched your search

+139 -1
View File
@@ -3446,6 +3446,139 @@ def teardown_bridge(bridge_name='br0', bridge_eth=None):
if os.path.exists(CREATED_BRIDGE_FILE): os.remove(CREATED_BRIDGE_FILE)
except OSError: pass
GITEA_API_COMMITS_URL = os.environ.get(
'AP_UPDATE_CHECK_URL',
'https://gitea.yoann-nas.fr/api/v1/repos/yoannmultigaming/apmanageur/commits?limit=1'
)
GITEA_REPO_URL = os.environ.get(
'AP_UPDATE_REPO_URL',
'https://gitea.yoann-nas.fr/yoannmultigaming/apmanageur'
)
_update_lock = threading.Lock()
_update_cache = {
'time': 0,
'checking': False,
'data': {
'available': False,
'current_commit': '',
'current_commit_full': '',
'latest_commit': '',
'latest_commit_full': '',
'commit_msg': '',
'author': '',
'date': '',
'html_url': GITEA_REPO_URL,
'docker_command': 'docker compose pull && docker compose up -d',
'last_checked': '',
'error': None
}
}
def get_current_commit():
"""Récupère le SHA du commit actuel (variable AP_GIT_COMMIT, version.json ou git)."""
env_c = os.environ.get('AP_GIT_COMMIT', '').strip()
if env_c:
return env_c
for path in (
os.path.join(BASE_DIR, 'version.json'),
'/app/version.json',
'/var/www/html/version.json',
os.path.join(os.getcwd(), 'version.json'),
'version.json'
):
if os.path.isfile(path):
try:
with open(path, 'r', encoding='utf-8') as f:
vdata = json.load(f)
c = vdata.get('commit', '').strip()
if c:
return c
except Exception:
pass
try:
c = command('git', 'rev-parse', 'HEAD')
if c and len(c.strip()) >= 7:
return c.strip()
except Exception:
pass
return ''
def check_gitea_update(force_refresh=False):
"""Vérifie si une nouvelle version est disponible sur le dépôt Gitea (cache 30 min, non bloquant)."""
now = time.time()
with _update_lock:
if not force_refresh and _update_cache['time'] > 0 and (now - _update_cache['time'] < 1800):
return dict(_update_cache['data'])
if _update_cache['checking'] and not force_refresh:
return dict(_update_cache['data'])
_update_cache['checking'] = True
def _worker():
current_sha = get_current_commit()
latest_sha = ''
msg = ''
author = ''
date_str = ''
html_url = GITEA_REPO_URL
err_msg = None
available = False
try:
req = urllib.request.Request(
GITEA_API_COMMITS_URL,
headers={'User-Agent': 'AP-Manageur-Update-Checker/1.0', 'Accept': 'application/json'}
)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(req, timeout=6.0, context=ctx) as resp:
if resp.status == 200:
data = json.loads(resp.read().decode('utf-8'))
if isinstance(data, list) and len(data) > 0:
first = data[0]
latest_sha = (first.get('sha') or '').strip()
c_info = first.get('commit') or {}
msg = (c_info.get('message') or '').strip()
author = (c_info.get('author') or {}).get('name', '')
date_str = (c_info.get('author') or {}).get('date', '')
html_url = first.get('html_url') or GITEA_REPO_URL
if current_sha and latest_sha:
c_low = current_sha.lower()
l_low = latest_sha.lower()
if not l_low.startswith(c_low) and not c_low.startswith(l_low):
available = True
except Exception as e:
err_msg = str(e)
with _update_lock:
_update_cache['time'] = time.time()
_update_cache['checking'] = False
_update_cache['data'] = {
'available': available,
'current_commit': current_sha[:7] if current_sha else '',
'current_commit_full': current_sha,
'latest_commit': latest_sha[:7] if latest_sha else '',
'latest_commit_full': latest_sha,
'commit_msg': msg,
'author': author,
'date': date_str,
'html_url': html_url,
'docker_command': 'docker compose pull && docker compose up -d',
'last_checked': time.strftime('%Y-%m-%d %H:%M:%S'),
'error': err_msg
}
if force_refresh:
_worker()
with _update_lock:
return dict(_update_cache['data'])
else:
threading.Thread(target=_worker, daemon=True).start()
with _update_lock:
return dict(_update_cache['data'])
_status_cache = {'time': 0, 'data': None}
_status_cache_lock = threading.Lock()
@@ -3500,7 +3633,7 @@ def status(force_refresh=False):
except OSError: pass
b_name = master or get_pref('bridge_name', os.environ.get('AP_BRIDGE_NAME', 'br0'))
b_eth = get_pref('bridge_eth', os.environ.get('AP_BRIDGE_ETH', ''))
res = {'ssid':ssid or 'SSID inconnu','password':password,'security':sec,'autoconnect':auto,'mode':mode,'bridge_name':b_name,'bridge_eth':b_eth,'ethernet_interfaces':detect_ethernet_interfaces(),'interface':INTERFACE,'connection':name,'active':active,'configured':bool(name or db_ssid),'uptime_seconds':ap_uptime() if active else 0,'max_clients':get_max_clients(),'dns':get_dns_servers(),'is_starting':not app_startup_done,'boot_time':SERVER_BOOT_TIME}
res = {'ssid':ssid or 'SSID inconnu','password':password,'security':sec,'autoconnect':auto,'mode':mode,'bridge_name':b_name,'bridge_eth':b_eth,'ethernet_interfaces':detect_ethernet_interfaces(),'interface':INTERFACE,'connection':name,'active':active,'configured':bool(name or db_ssid),'uptime_seconds':ap_uptime() if active else 0,'max_clients':get_max_clients(),'dns':get_dns_servers(),'is_starting':not app_startup_done,'boot_time':SERVER_BOOT_TIME,'update':check_gitea_update(force_refresh=False)}
with _status_cache_lock:
_status_cache['time'] = now
_status_cache['data'] = res
@@ -10182,6 +10315,11 @@ class Handler(BaseHTTPRequestHandler):
return
if not valid_session(self): self.send_json({'error':'Authentification requise'},401); return
if path_only == '/api/status': self.send_json(status())
elif path_only == '/api/system/update':
parsed = urllib.parse.urlparse(self.path)
q = urllib.parse.parse_qs(parsed.query)
force = 'force' in q or 'refresh' in q
self.send_json(check_gitea_update(force_refresh=force))
elif path_only == '/api/clients': self.send_json(clients())
elif path_only == '/api/clients/blocked': self.send_json(blocked_list())
elif path_only == '/api/devices': self.send_json(all_devices(self.get_req_lang()))