From ceeab6fa4a650ce9a251236971661bc4b39c321f Mon Sep 17 00:00:00 2001 From: yoannmultigaming Date: Sat, 21 Nov 2026 03:29:09 +0100 Subject: [PATCH] APmanageur Wi-Fi V1.0 --- Dockerfile | 2 + ap.py | 140 ++++++++++++++++++++++++++++++++++++- index.html | 186 +++++++++++++++++++++++++++++++++++++++++++++++++- lang/en-gb.js | 14 +++- lang/en-us.js | 14 +++- lang/fr.js | 14 +++- version.json | 5 ++ 7 files changed, 369 insertions(+), 6 deletions(-) create mode 100644 version.json diff --git a/Dockerfile b/Dockerfile index 5f49ed9..f5c52f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,8 @@ COPY themes/ /app/themes/ COPY themes/ /var/www/html/themes/ COPY jeux/ /app/jeux/ COPY jeux/ /var/www/html/jeux/ +COPY version.json /app/version.json +COPY version.json /var/www/html/version.json # L'API n'est plus joignable que via Apache : le HTML appelle /api sur le même port (1001) RUN sed -i 's#const API_URL=[^;]*;#const API_URL="";#' /app/index.html /var/www/html/index.html /app/setup.html /var/www/html/setup.html 2>/dev/null || true COPY apache-ap.conf /etc/apache2/sites-available/000-default.conf diff --git a/ap.py b/ap.py index cb80c61..d2a94ff 100644 --- a/ap.py +++ b/ap.py @@ -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())) diff --git a/index.html b/index.html index 382e715..fa30dbd 100644 --- a/index.html +++ b/index.html @@ -130,6 +130,32 @@ line-height: 1; } + .btn-update-available { + background: rgba(16, 185, 129, 0.16) !important; + color: #10b981 !important; + border: 1px solid rgba(16, 185, 129, 0.5) !important; + box-shadow: 0 0 10px rgba(16, 185, 129, 0.2); + transition: all 0.2s ease-in-out; + cursor: pointer; + } + + .btn-update-available:hover { + background: rgba(16, 185, 129, 0.28) !important; + border-color: #10b981 !important; + box-shadow: 0 0 16px rgba(16, 185, 129, 0.45); + transform: translateY(-1px); + } + + .btn-update-available .update-arrow-svg { + animation: pulse-update-arrow 2s infinite ease-in-out; + flex-shrink: 0; + } + + @keyframes pulse-update-arrow { + 0%, 100% { transform: translateY(0); } + 50% { transform: translateY(-2.5px); } + } + nav { display: flex; gap: 8px; @@ -2014,6 +2040,10 @@ width: 100% } + .btn-update-available { + grid-column: span 2; + } + .topo-clients-grid { grid-template-columns: 1fr !important } @@ -2489,6 +2519,10 @@ + + + + + + +