Publishes the Python stdlib server (admin UI, upload API, repo-add compatible DB generation) with its deployed Caddyfile, install script and pacman client snippet, so the whole fws repository stack lives next to the package sources. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
485 lines
19 KiB
HTML
485 lines
19 KiB
HTML
<!doctype html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="robots" content="noindex">
|
|
<title>archrepo — publication de paquets</title>
|
|
<style>
|
|
:root {
|
|
--bg: #0d1117;
|
|
--panel: #151b24;
|
|
--panel-2: #1b2430;
|
|
--line: #263243;
|
|
--text: #e6edf3;
|
|
--muted: #8b9bb0;
|
|
--accent: #2dd4bf;
|
|
--accent-dark: #0f766e;
|
|
--danger: #f87171;
|
|
--ok: #4ade80;
|
|
--warn: #fbbf24;
|
|
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
}
|
|
* { box-sizing: border-box; }
|
|
body {
|
|
margin: 0; background: radial-gradient(1200px 600px at 20% -10%, #16303a 0%, var(--bg) 55%);
|
|
color: var(--text); min-height: 100vh; font-size: 15px; line-height: 1.5;
|
|
}
|
|
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
|
|
header {
|
|
display: flex; align-items: center; justify-content: space-between; gap: 16px;
|
|
padding: 18px 24px; border-bottom: 1px solid var(--line); background: rgba(13, 17, 23, .7);
|
|
position: sticky; top: 0; backdrop-filter: blur(8px); z-index: 5;
|
|
}
|
|
.brand { display: flex; align-items: center; gap: 12px; }
|
|
.logo { font-size: 24px; color: var(--accent); }
|
|
h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
|
|
.sub { margin: 0; color: var(--muted); font-size: 12px; }
|
|
.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
|
|
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
|
|
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(74, 222, 128, .15); }
|
|
.dot.offline { background: var(--danger); }
|
|
main { max-width: 1080px; margin: 0 auto; padding: 24px; display: grid; gap: 18px; }
|
|
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
|
|
.card h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 14px; }
|
|
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
|
|
.card-head h2 { margin: 0; }
|
|
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
|
|
input[type="password"], input[type="text"] {
|
|
flex: 1 1 240px; min-width: 180px; padding: 10px 12px; border-radius: 8px;
|
|
border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 14px;
|
|
}
|
|
input:focus { outline: 2px solid var(--accent-dark); outline-offset: 1px; border-color: var(--accent-dark); }
|
|
button {
|
|
padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer;
|
|
background: var(--panel-2); color: var(--text); font-size: 13px; font-weight: 600; font-family: inherit;
|
|
}
|
|
button:hover { border-color: var(--accent-dark); color: var(--accent); }
|
|
button.primary { background: var(--accent-dark); border-color: var(--accent-dark); color: #04221f; }
|
|
button.primary:hover { background: var(--accent); border-color: var(--accent); color: #04221f; }
|
|
button.ghost { background: transparent; }
|
|
button.danger { border-color: transparent; background: transparent; color: var(--muted); font-size: 16px; padding: 4px 8px; }
|
|
button.danger:hover { color: var(--danger); border-color: var(--danger); }
|
|
button:disabled { opacity: .5; cursor: not-allowed; }
|
|
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
|
|
.hidden { display: none !important; }
|
|
.drop {
|
|
border: 2px dashed var(--line); border-radius: 12px; padding: 28px 20px; text-align: center;
|
|
transition: border-color .15s, background .15s; cursor: pointer;
|
|
}
|
|
.drop:hover { border-color: var(--accent-dark); }
|
|
.drop.active { border-color: var(--accent); background: rgba(45, 212, 191, .07); }
|
|
.drop p { margin: 4px 0; }
|
|
.link { color: var(--accent); text-decoration: underline; cursor: pointer; }
|
|
.link input { display: none; }
|
|
.queue { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
|
|
.queue li { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
|
|
.queue .file { display: flex; justify-content: space-between; gap: 12px; }
|
|
.queue .state { color: var(--muted); font-size: 12px; }
|
|
.queue .state.done { color: var(--ok); }
|
|
.queue .state.error { color: var(--danger); }
|
|
.bar { height: 4px; border-radius: 2px; background: var(--line); margin-top: 8px; overflow: hidden; }
|
|
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
|
|
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
|
|
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 12px; color: var(--muted); }
|
|
.stat b { color: var(--text); font-size: 14px; display: block; }
|
|
.table-wrap { overflow-x: auto; }
|
|
table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
|
|
td { padding: 10px; border-bottom: 1px solid rgba(38, 50, 67, .6); vertical-align: middle; }
|
|
tr:last-child td { border-bottom: 0; }
|
|
td.filename { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }
|
|
.pill { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
|
|
.pill.current { border-color: var(--accent-dark); color: var(--accent); }
|
|
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 12.5px; margin: 0 0 12px; }
|
|
.toast {
|
|
position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px);
|
|
background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
|
|
padding: 11px 16px; border-radius: 10px; font-size: 13px; opacity: 0;
|
|
pointer-events: none; transition: opacity .2s, transform .2s; max-width: min(90vw, 640px); z-index: 20;
|
|
}
|
|
.toast.show { opacity: 1; transform: translate(-50%, 0); }
|
|
.toast.error { border-color: var(--danger); color: #fecaca; }
|
|
.toast.ok { border-color: var(--accent-dark); }
|
|
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 10px 24px 28px; }
|
|
@media (max-width: 700px) { main { padding: 14px; } header { padding: 14px; } }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<div class="brand">
|
|
<span class="logo">◧</span>
|
|
<div>
|
|
<h1 id="repo-name">archrepo</h1>
|
|
<p class="sub" id="repo-sub">dépôt pacman</p>
|
|
</div>
|
|
</div>
|
|
<div class="status"><span id="status-dot" class="dot"></span><span id="status-text">connexion…</span></div>
|
|
</header>
|
|
|
|
<main>
|
|
<section class="card">
|
|
<h2>Jeton d'accès</h2>
|
|
<div class="row">
|
|
<input id="token" type="password" placeholder="jeton d'administration" autocomplete="current-password" spellcheck="false">
|
|
<button id="save-token" class="primary">Enregistrer</button>
|
|
<button id="forget-token" class="ghost">Oublier</button>
|
|
</div>
|
|
<p class="hint">Le jeton se trouve sur le serveur dans <code>/etc/archrepo/token</code>. Il n'est conservé que dans ce navigateur.</p>
|
|
</section>
|
|
|
|
<section class="card">
|
|
<h2>Publier des paquets</h2>
|
|
<div id="drop" class="drop">
|
|
<p><strong>Déposez vos paquets ici</strong></p>
|
|
<p class="hint">*.pkg.tar.zst, *.pkg.tar.xz, *.pkg.tar.gz — ou <label class="link">parcourir les fichiers<input id="file-input" type="file" multiple accept=".zst,.xz,.gz"></label></p>
|
|
</div>
|
|
<ul id="queue" class="queue"></ul>
|
|
</section>
|
|
|
|
<section class="card">
|
|
<div class="card-head">
|
|
<h2>Paquets publiés</h2>
|
|
<div class="row">
|
|
<button id="refresh" class="ghost">Rafraîchir</button>
|
|
<button id="rebuild" class="ghost">Reconstruire la base</button>
|
|
</div>
|
|
</div>
|
|
<div class="stats" id="stats"></div>
|
|
<div class="table-wrap">
|
|
<table>
|
|
<thead>
|
|
<tr><th>Paquet</th><th>Version</th><th>Arch</th><th>Taille</th><th>Fichier</th><th></th></tr>
|
|
</thead>
|
|
<tbody id="packages"></tbody>
|
|
</table>
|
|
</div>
|
|
<p id="empty" class="hint hidden">Aucun paquet pour le moment : envoyez-en un ci-dessus.</p>
|
|
</section>
|
|
|
|
<section class="card">
|
|
<h2>Client pacman</h2>
|
|
<pre id="pacman-conf">…</pre>
|
|
<button id="copy-conf" class="ghost">Copier la configuration</button>
|
|
<p class="hint">Ajoutez ce bloc dans <code>/etc/pacman.conf</code>, puis <code>pacman -Sy</code> et <code>pacman -S nom-du-paquet</code>.</p>
|
|
</section>
|
|
</main>
|
|
|
|
<footer>archrepo — les paquets et bases sont servis par Caddy, les publications passent par cette interface.</footer>
|
|
<div id="toast" class="toast"></div>
|
|
|
|
<script>
|
|
const TOKEN_KEY = 'archrepo.token';
|
|
const state = {
|
|
token: localStorage.getItem(TOKEN_KEY) || '',
|
|
health: null,
|
|
packages: [],
|
|
stats: {},
|
|
queue: [],
|
|
uploading: false,
|
|
};
|
|
|
|
const $ = (id) => document.getElementById(id);
|
|
|
|
function toast(message, kind = 'info') {
|
|
const node = $('toast');
|
|
node.textContent = message;
|
|
node.className = `toast show ${kind}`;
|
|
clearTimeout(toast.timer);
|
|
toast.timer = setTimeout(() => { node.className = 'toast'; }, 4200);
|
|
}
|
|
|
|
function formatBytes(bytes) {
|
|
const value = Number(bytes) || 0;
|
|
if (value < 1024) return `${value} o`;
|
|
const units = ['Kio', 'Mio', 'Gio', 'Tio'];
|
|
let size = value / 1024;
|
|
let index = 0;
|
|
while (size >= 1024 && index < units.length - 1) { size /= 1024; index += 1; }
|
|
return `${size.toFixed(size >= 10 ? 0 : 1)} ${units[index]}`;
|
|
}
|
|
|
|
function formatDate(seconds) {
|
|
if (!seconds) return '—';
|
|
return new Date(seconds * 1000).toLocaleString();
|
|
}
|
|
|
|
async function request(path, options = {}) {
|
|
const headers = Object.assign({}, options.headers || {});
|
|
if (state.token) headers['Authorization'] = `Bearer ${state.token}`;
|
|
const response = await fetch(path, Object.assign({}, options, { headers }));
|
|
let data = null;
|
|
try { data = await response.json(); } catch (error) { /* réponse vide */ }
|
|
if (!response.ok) throw new Error((data && data.error) || `HTTP ${response.status}`);
|
|
return data;
|
|
}
|
|
|
|
function setStatus(text, mode) {
|
|
$('status-text').textContent = text;
|
|
$('status-dot').className = `dot ${mode}`;
|
|
}
|
|
|
|
async function loadHealth() {
|
|
try {
|
|
const health = await request('/api/health');
|
|
state.health = health;
|
|
$('repo-name').textContent = health.repo;
|
|
$('repo-sub').textContent = `dépôt pacman · ${health.arch}`;
|
|
document.title = `${health.repo} — publication de paquets`;
|
|
renderPacmanConf();
|
|
setStatus(state.token ? 'prêt' : 'jeton requis', state.token ? 'online' : '');
|
|
} catch (error) {
|
|
setStatus('serveur injoignable', 'offline');
|
|
}
|
|
}
|
|
|
|
function renderPacmanConf() {
|
|
const arch = (state.health && state.health.arch) || 'x86_64';
|
|
const repo = (state.health && state.health.repo) || 'archrepo';
|
|
const conf = `[${repo}]\nServer = ${window.location.origin}/${arch}\nSigLevel = Optional TrustAll`;
|
|
$('pacman-conf').textContent = conf;
|
|
}
|
|
|
|
function renderStats() {
|
|
const stats = state.stats || {};
|
|
const items = [
|
|
['Paquets', String(stats.count ?? 0)],
|
|
['Taille totale', formatBytes(stats.total_size)],
|
|
['Base .db', formatBytes(stats.db_size)],
|
|
['Base mise à jour', formatDate(stats.db_updated)],
|
|
];
|
|
$('stats').innerHTML = items
|
|
.map(([label, value]) => `<div class="stat">${label}<b>${value}</b></div>`)
|
|
.join('');
|
|
}
|
|
|
|
function renderPackages() {
|
|
const body = $('packages');
|
|
body.innerHTML = '';
|
|
const packages = state.packages || [];
|
|
$('empty').classList.toggle('hidden', packages.length > 0);
|
|
for (const pkg of packages) {
|
|
const tr = document.createElement('tr');
|
|
const title = pkg.desc ? `${pkg.name} — ${pkg.desc}` : pkg.name;
|
|
tr.innerHTML = `
|
|
<td title="${escapeHtml(title)}">${escapeHtml(pkg.name)}</td>
|
|
<td class="mono">${escapeHtml(pkg.version)}</td>
|
|
<td><span class="pill">${escapeHtml(pkg.arch)}</span></td>
|
|
<td>${formatBytes(pkg.csize)}</td>
|
|
<td class="filename">${escapeHtml(pkg.filename)}
|
|
${pkg.current ? '<span class="pill current">actif</span>' : ''}</td>
|
|
<td><button class="danger" title="Supprimer">✕</button></td>`;
|
|
tr.querySelector('button').addEventListener('click', () => removePackage(pkg.filename));
|
|
body.appendChild(tr);
|
|
}
|
|
}
|
|
|
|
function escapeHtml(value) {
|
|
return String(value ?? '').replace(/[&<>"']/g, (char) => (
|
|
{ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]
|
|
));
|
|
}
|
|
|
|
async function refreshPackages() {
|
|
if (!state.token) {
|
|
state.packages = [];
|
|
state.stats = {};
|
|
renderStats();
|
|
renderPackages();
|
|
setStatus('jeton requis', '');
|
|
return;
|
|
}
|
|
try {
|
|
const data = await request('/api/packages');
|
|
state.packages = data.packages || [];
|
|
state.stats = data.stats || {};
|
|
renderStats();
|
|
renderPackages();
|
|
setStatus(`${state.stats.count || 0} paquet(s) · base à jour`, 'online');
|
|
} catch (error) {
|
|
setStatus(error.message, 'offline');
|
|
if (/jeton/.test(error.message)) state.packages = [];
|
|
renderStats();
|
|
renderPackages();
|
|
}
|
|
}
|
|
|
|
async function removePackage(filename) {
|
|
if (!confirm(`Supprimer définitivement ${filename} du dépôt ?`)) return;
|
|
try {
|
|
await request(`/api/packages/${encodeURIComponent(filename)}`, { method: 'DELETE' });
|
|
toast(`${filename} supprimé`, 'ok');
|
|
await refreshPackages();
|
|
} catch (error) {
|
|
toast(error.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function rebuild() {
|
|
if (!state.token) return toast('Enregistrez d\'abord votre jeton', 'error');
|
|
const button = $('rebuild');
|
|
button.disabled = true;
|
|
try {
|
|
const data = await request('/api/rebuild', { method: 'POST' });
|
|
toast(`Base reconstruite : ${data.count} paquet(s)`, 'ok');
|
|
await refreshPackages();
|
|
} catch (error) {
|
|
toast(error.message, 'error');
|
|
} finally {
|
|
button.disabled = false;
|
|
}
|
|
}
|
|
|
|
// -- file d'attente d'envoi ------------------------------------------------
|
|
function enqueue(files) {
|
|
const accepted = Array.from(files).filter((file) => file.name.includes('.pkg.tar.'));
|
|
const rejected = files.length - accepted.length;
|
|
if (rejected > 0) toast(`${rejected} fichier(s) ignoré(s) : extension .pkg.tar.* attendue`, 'error');
|
|
if (!accepted.length) return;
|
|
if (!state.token) return toast('Enregistrez d\'abord votre jeton', 'error');
|
|
for (const file of accepted) {
|
|
state.queue.push({ name: file.name, file, progress: 0, state: 'waiting', message: 'en attente' });
|
|
}
|
|
renderQueue();
|
|
drainQueue();
|
|
}
|
|
|
|
function renderQueue() {
|
|
$('queue').innerHTML = state.queue
|
|
.map((item) => `
|
|
<li>
|
|
<div class="file">
|
|
<span class="mono">${escapeHtml(item.name)}</span>
|
|
<span class="state ${item.state}">${escapeHtml(item.message)}</span>
|
|
</div>
|
|
<div class="bar"><span style="width:${Math.round(item.progress * 100)}%"></span></div>
|
|
</li>`)
|
|
.join('');
|
|
}
|
|
|
|
function updateQueueItem(name, patch) {
|
|
const item = state.queue.find((entry) => entry.name === name && entry.state === 'sending')
|
|
|| state.queue.find((entry) => entry.name === name);
|
|
if (!item) return;
|
|
Object.assign(item, patch);
|
|
renderQueue();
|
|
}
|
|
|
|
async function drainQueue() {
|
|
if (state.uploading) return;
|
|
const next = state.queue.find((item) => item.state === 'waiting');
|
|
if (!next) return;
|
|
state.uploading = true;
|
|
next.state = 'sending';
|
|
next.progress = 0;
|
|
next.message = 'envoi…';
|
|
renderQueue();
|
|
try {
|
|
const data = await uploadFile(next.file, (fraction) => {
|
|
next.progress = fraction;
|
|
renderQueue();
|
|
});
|
|
next.state = 'done';
|
|
next.progress = 1;
|
|
next.message = `publié · ${data.count} paquet(s) dans la base`;
|
|
(data.warnings || []).forEach((warning) => toast(warning, 'error'));
|
|
await refreshPackages();
|
|
} catch (error) {
|
|
next.state = 'error';
|
|
next.message = error.message;
|
|
} finally {
|
|
state.uploading = false;
|
|
renderQueue();
|
|
drainQueue();
|
|
}
|
|
}
|
|
|
|
function uploadFile(file, onProgress) {
|
|
return new Promise((resolve, reject) => {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/packages');
|
|
xhr.setRequestHeader('Authorization', `Bearer ${state.token}`);
|
|
xhr.setRequestHeader('X-Filename', encodeURIComponent(file.name));
|
|
xhr.upload.addEventListener('progress', (event) => {
|
|
if (event.lengthComputable) onProgress(event.loaded / event.total);
|
|
});
|
|
xhr.addEventListener('load', () => {
|
|
let data = null;
|
|
try { data = JSON.parse(xhr.responseText); } catch (error) { /* ignore */ }
|
|
if (xhr.status >= 200 && xhr.status < 300) resolve(data);
|
|
else reject(new Error((data && data.error) || `HTTP ${xhr.status}`));
|
|
});
|
|
xhr.addEventListener('error', () => reject(new Error('échec réseau pendant l\'envoi')));
|
|
xhr.addEventListener('abort', () => reject(new Error('envoi annulé')));
|
|
xhr.send(file);
|
|
});
|
|
}
|
|
|
|
// -- jeton -----------------------------------------------------------------
|
|
function saveToken() {
|
|
const value = $('token').value.trim();
|
|
if (!value) return toast('Jeton vide', 'error');
|
|
state.token = value;
|
|
localStorage.setItem(TOKEN_KEY, value);
|
|
$('token').value = value;
|
|
refreshPackages();
|
|
toast('Jeton enregistré', 'ok');
|
|
}
|
|
|
|
function forgetToken() {
|
|
state.token = '';
|
|
localStorage.removeItem(TOKEN_KEY);
|
|
$('token').value = '';
|
|
refreshPackages();
|
|
toast('Jeton oublié');
|
|
}
|
|
|
|
// -- collage / glisser-déposer --------------------------------------------
|
|
function bindDropZone() {
|
|
const drop = $('drop');
|
|
['dragenter', 'dragover'].forEach((event) => drop.addEventListener(event, (e) => {
|
|
e.preventDefault();
|
|
drop.classList.add('active');
|
|
}));
|
|
['dragleave', 'drop'].forEach((event) => drop.addEventListener(event, (e) => {
|
|
e.preventDefault();
|
|
drop.classList.remove('active');
|
|
}));
|
|
drop.addEventListener('drop', (event) => {
|
|
if (event.dataTransfer) enqueue(event.dataTransfer.files);
|
|
});
|
|
$('file-input').addEventListener('change', (event) => {
|
|
enqueue(event.target.files);
|
|
event.target.value = '';
|
|
});
|
|
}
|
|
|
|
async function copyConf() {
|
|
const text = $('pacman-conf').textContent;
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
toast('Configuration copiée', 'ok');
|
|
} catch (error) {
|
|
toast('Copie impossible : sélectionnez le texte manuellement', 'error');
|
|
}
|
|
}
|
|
|
|
function init() {
|
|
$('token').value = state.token;
|
|
$('save-token').addEventListener('click', saveToken);
|
|
$('forget-token').addEventListener('click', forgetToken);
|
|
$('refresh').addEventListener('click', refreshPackages);
|
|
$('rebuild').addEventListener('click', rebuild);
|
|
$('copy-conf').addEventListener('click', copyConf);
|
|
$('token').addEventListener('keydown', (event) => {
|
|
if (event.key === 'Enter') saveToken();
|
|
});
|
|
bindDropZone();
|
|
loadHealth().then(refreshPackages);
|
|
}
|
|
|
|
init();
|
|
</script>
|
|
</body>
|
|
</html>
|