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

+2
View File
@@ -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
+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()))
+184 -2
View File
@@ -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 @@
<button id="apControl" type="button" data-i18n="btn_start">Démarrer</button>
<button id="apRestart" class="secondary" type="button" data-i18n="btn_restart">Redémarrer</button>
<button id="refresh" data-i18n="btn_refresh">Actualiser</button>
<button id="btnUpdateAvailable" class="btn-update-available" type="button" style="display:none" onclick="openUpdateModal()" title="Mise à jour disponible">
<svg class="update-arrow-svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>
<span data-i18n="header_update_available">Mise à jour disponible</span>
</button>
<button id="headerLangBtn" class="secondary" type="button" onclick="openLanguageSettings()"
title="Paramètres de langue / Language settings">
<span id="headerLangFlag" style="display:inline-flex;align-items:center;line-height:1"></span>
@@ -5635,6 +5669,67 @@
</div>
</div>
<!-- Modal Mise à jour de l'application -->
<div id="modalUpdateApp" class="modal-overlay">
<div class="modal-card" style="max-width:540px">
<div class="modal-header">
<h3 style="margin:0;font-size:17px;display:flex;align-items:center;gap:8px">
<span style="color:#10b981;display:inline-flex;align-items:center">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>
</span>
<span data-i18n="update_modal_title">Mise à jour disponible</span>
</h3>
<button id="closeUpdateModal" class="secondary" type="button" style="padding:4px 10px;font-size:16px;border-radius:6px" onclick="closeUpdateModal()">✕</button>
</div>
<div class="modal-body" style="gap:16px">
<div style="background:rgba(16,185,129,0.1);border:1px solid rgba(16,185,129,0.3);border-radius:8px;padding:12px;display:flex;align-items:center;gap:12px">
<span style="font-size:24px;line-height:1">🚀</span>
<div style="font-size:13px;line-height:1.4">
<div style="font-weight:600;color:#10b981" data-i18n="update_new_version_found">Une nouvelle version de AP Manageur est prête !</div>
<div style="color:var(--text2);font-size:12px" data-i18n="update_new_version_desc">Une mise à jour plus récente de l'application est disponible sur le dépôt.</div>
</div>
</div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;font-size:13px">
<div style="background:var(--panel2);padding:10px 12px;border-radius:8px;border:1px solid var(--line)">
<div style="color:var(--text2);font-size:11px;text-transform:uppercase;font-weight:600;margin-bottom:4px" data-i18n="update_current_commit">Version actuelle</div>
<div id="updateCurrentCommit" style="font-family:monospace;font-weight:700;color:var(--text)">—</div>
</div>
<div style="background:var(--panel2);padding:10px 12px;border-radius:8px;border:1px solid var(--line)">
<div style="color:var(--text2);font-size:11px;text-transform:uppercase;font-weight:600;margin-bottom:4px" data-i18n="update_latest_commit">Dernière version (Gitea)</div>
<div id="updateLatestCommit" style="font-family:monospace;font-weight:700;color:#10b981">—</div>
</div>
</div>
<div id="updateCommitMsgBox" style="background:var(--panel2);padding:10px 12px;border-radius:8px;border:1px solid var(--line);font-size:12px">
<div style="color:var(--text2);font-size:11px;text-transform:uppercase;font-weight:600;margin-bottom:4px" data-i18n="update_commit_info">Détails du commit</div>
<div id="updateCommitMsg" style="font-style:italic;color:var(--text);margin-bottom:6px;word-break:break-word">—</div>
<div style="color:var(--text2);font-size:11px;display:flex;gap:10px;flex-wrap:wrap">
<span id="updateCommitAuthor"></span>
<span id="updateCommitDate"></span>
</div>
</div>
<div>
<label style="display:block;font-size:12px;font-weight:600;margin-bottom:6px" data-i18n="update_how_to">Pour mettre à jour votre conteneur Docker :</label>
<div style="display:flex;gap:8px;align-items:center">
<input type="text" id="updateDockerCmd" readonly value="docker compose pull && docker compose up -d" style="flex:1;background:var(--bg);font-family:monospace;font-size:12px;padding:8px 10px;border-radius:6px;border:1px solid var(--line);color:var(--text);cursor:text" onclick="this.select()">
<button type="button" class="secondary" id="btnCopyUpdateCmd" onclick="copyUpdateCommand()" style="white-space:nowrap;padding:8px 12px;font-size:12px">
<span id="btnCopyUpdateCmdText" data-i18n="btn_copy">Copier</span>
</button>
</div>
<div style="font-size:11px;color:var(--text2);margin-top:6px" data-i18n="update_cmd_hint">Exécutez cette commande dans le dossier de votre projet sur votre serveur hôte.</div>
</div>
</div>
<div class="modal-footer" style="justify-content:space-between">
<button type="button" class="secondary" id="btnCheckUpdateManual" onclick="triggerManualUpdateCheck()" style="font-size:12px">
🔄 <span data-i18n="btn_recheck">Vérifier à nouveau</span>
</button>
<button type="button" class="secondary" onclick="closeUpdateModal()" data-i18n="btn_close">Fermer</button>
</div>
</div>
</div>
<div id="topoDetailModal" class="modal-overlay">
<div class="modal-card">
<div class="modal-header">
@@ -8533,6 +8628,12 @@ ${vpnBadgeTopo}
if ($('apControl')) $('apControl').style.display = configured ? '' : 'none';
if ($('apRestart')) $('apRestart').style.display = configured && active ? '' : 'none';
if ($('refresh')) $('refresh').style.display = configured ? '' : 'none';
const updateInfo = (status && status.update) ? status.update : null;
if (updateInfo) lastUpdateData = updateInfo;
const updateAvailable = !!(updateInfo && updateInfo.available);
if ($('btnUpdateAvailable')) {
$('btnUpdateAvailable').style.display = (configured && updateAvailable) ? 'inline-flex' : 'none';
}
if (configured && $('apControl')) {
$('apControl').textContent = active ? t('btn_stop', 'Arrêter') : t('btn_start', 'Démarrer');
$('apControl').style.background = active ? 'var(--red)' : 'var(--blue)';
@@ -8540,6 +8641,77 @@ ${vpnBadgeTopo}
}
}
let lastUpdateData = null;
function openUpdateModal() {
const modal = $('modalUpdateApp');
if (!modal) return;
const u = lastUpdateData || (status && status.update) || {};
if ($('updateCurrentCommit')) $('updateCurrentCommit').textContent = u.current_commit || (u.current_commit_full ? u.current_commit_full.substring(0, 7) : '—');
if ($('updateLatestCommit')) $('updateLatestCommit').textContent = u.latest_commit || (u.latest_commit_full ? u.latest_commit_full.substring(0, 7) : '—');
if ($('updateCommitMsg')) $('updateCommitMsg').textContent = u.commit_msg || t('update_no_msg', 'Aucun message de commit');
if ($('updateCommitAuthor')) $('updateCommitAuthor').textContent = u.author ? ('Par ' + u.author) : '';
if ($('updateCommitDate')) {
let dStr = '';
if (u.date) {
try { dStr = 'le ' + new Date(u.date).toLocaleString(); } catch (_) { dStr = 'le ' + u.date; }
}
$('updateCommitDate').textContent = dStr;
}
modal.classList.add('active');
}
window.openUpdateModal = openUpdateModal;
function closeUpdateModal() {
const modal = $('modalUpdateApp');
if (modal) modal.classList.remove('active');
}
window.closeUpdateModal = closeUpdateModal;
async function copyUpdateCommand() {
const input = $('updateDockerCmd');
const btnText = $('btnCopyUpdateCmdText');
if (!input) return;
const cmd = input.value;
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
await navigator.clipboard.writeText(cmd);
} else {
input.select();
document.execCommand('copy');
}
if (btnText) {
const original = btnText.textContent;
btnText.textContent = t('update_cmd_copied', '✓ Copié !');
setTimeout(() => { if (btnText) btnText.textContent = original; }, 2000);
}
} catch (err) {
input.select();
document.execCommand('copy');
}
}
window.copyUpdateCommand = copyUpdateCommand;
async function triggerManualUpdateCheck() {
const btn = $('btnCheckUpdateManual');
if (btn) btn.disabled = true;
try {
const res = await apiFetch('/api/system/update?force=1', { cache: 'no-store' });
if (res.ok) {
const u = await res.json();
lastUpdateData = u;
if (status) status.update = u;
updateApButtons();
openUpdateModal();
}
} catch (e) {
console.warn('Erreur vérification mise à jour :', e);
} finally {
if (btn) btn.disabled = false;
}
}
window.triggerManualUpdateCheck = triggerManualUpdateCheck;
async function toggleBlock(mac, blocked) {
return runAction(async () => {
try {
@@ -8990,6 +9162,7 @@ ${vpnBadgeTopo}
const d = await res.json();
if (!res.ok) throw new Error(d.error || 'Erreur lors de la suppression');
await loadDevices();
await load();
} catch (e) {
alert(tErr(e.message));
}
@@ -9110,8 +9283,8 @@ ${vpnBadgeTopo}
function setBwPreset(downMbps, upMbps) {
if ($('inputRateDown')) $('inputRateDown').value = downMbps;
if ($('selectRateDownUnit')) $('selectRateDownUnit').value = 'Mbps';
if ($('selectQuotaUnit')) $('selectQuotaUnit').value = unit;
updateQuotaPreview();
if ($('inputRateUp')) $('inputRateUp').value = upMbps;
if ($('selectRateUpUnit')) $('selectRateUpUnit').value = 'Mbps';
}
async function onQuotaPeriodChanged() {
@@ -14596,6 +14769,10 @@ ${vpnBadgeTopo}
if (m && m.classList.contains('active')) {
closeEasterEggModal();
}
const mu = $('modalUpdateApp');
if (mu && mu.classList.contains('active')) {
closeUpdateModal();
}
}
});
if ($('modalEasterEggGames')) {
@@ -14603,6 +14780,11 @@ ${vpnBadgeTopo}
if (e.target === $('modalEasterEggGames')) closeEasterEggModal();
};
}
if ($('modalUpdateApp')) {
$('modalUpdateApp').onclick = (e) => {
if (e.target === $('modalUpdateApp')) closeUpdateModal();
};
}
</script>
</body>
+13 -1
View File
@@ -1266,5 +1266,17 @@ window.I18N['en-gb'] = {
"notif_evt_backup_success": "💾 Backup successfully created",
"notif_evt_backup_remote_success": "☁️ Backup uploaded to remote host (if configured)",
"notif_event_backup_success": "💾 Backup successfully created",
"notif_event_backup_remote_success": "☁️ Backup uploaded to remote storage"
"notif_event_backup_remote_success": "☁️ Backup uploaded to remote storage",
"header_update_available": "Update available",
"update_modal_title": "Update Available",
"update_new_version_found": "A new version of AP Manageur is ready!",
"update_new_version_desc": "A newer version of the application is available on the repository.",
"update_current_commit": "Current version",
"update_latest_commit": "Latest version (Gitea)",
"update_commit_info": "Commit details",
"update_how_to": "To update your Docker container:",
"update_cmd_hint": "Run this command in your project directory on your host server.",
"update_cmd_copied": "✓ Copied!",
"btn_recheck": "Check again",
"update_no_msg": "No commit message"
};
+13 -1
View File
@@ -1266,5 +1266,17 @@ window.I18N['en-us'] = {
"notif_evt_backup_success": "💾 Backup successfully created",
"notif_evt_backup_remote_success": "☁️ Backup uploaded to remote host (if configured)",
"notif_event_backup_success": "💾 Backup successfully created",
"notif_event_backup_remote_success": "☁️ Backup uploaded to remote storage"
"notif_event_backup_remote_success": "☁️ Backup uploaded to remote storage",
"header_update_available": "Update available",
"update_modal_title": "Update Available",
"update_new_version_found": "A new version of AP Manageur is ready!",
"update_new_version_desc": "A newer version of the application is available on the repository.",
"update_current_commit": "Current version",
"update_latest_commit": "Latest version (Gitea)",
"update_commit_info": "Commit details",
"update_how_to": "To update your Docker container:",
"update_cmd_hint": "Run this command in your project directory on your host server.",
"update_cmd_copied": "✓ Copied!",
"btn_recheck": "Check again",
"update_no_msg": "No commit message"
};
+13 -1
View File
@@ -1266,5 +1266,17 @@ window.I18N['fr'] = {
"notif_evt_backup_success": "💾 Sauvegarde créée avec succès",
"notif_evt_backup_remote_success": "☁️ Sauvegarde envoyée sur l’hôte distant (si configuré)",
"notif_event_backup_success": "💾 Sauvegarde créée avec succès",
"notif_event_backup_remote_success": "☁️ Sauvegarde téléversée sur le stockage distant"
"notif_event_backup_remote_success": "☁️ Sauvegarde téléversée sur le stockage distant",
"header_update_available": "Mise à jour disponible",
"update_modal_title": "Mise à jour disponible",
"update_new_version_found": "Une nouvelle version de AP Manageur est prête !",
"update_new_version_desc": "Une mise à jour plus récente de l'application est disponible sur le dépôt.",
"update_current_commit": "Version actuelle",
"update_latest_commit": "Dernière version (Gitea)",
"update_commit_info": "Détails du commit",
"update_how_to": "Pour mettre à jour votre conteneur Docker :",
"update_cmd_hint": "Exécutez cette commande dans le dossier de votre projet sur votre serveur hôte.",
"update_cmd_copied": "✓ Copié !",
"btn_recheck": "Vérifier à nouveau",
"update_no_msg": "Aucun message de commit"
};
+5
View File
@@ -0,0 +1,5 @@
{
"version": "V5.5",
"commit": "fe6594b964870ee466a06d90ad7acd821b50bfc7",
"build_date": "2026-11-21T02:00:00Z"
}