Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca1011954f | |||
| 6932496bfc | |||
| 396682459c | |||
| 7f644b693b | |||
| c1b26ff35b | |||
| e486e1df86 | |||
| 78f4d05ceb | |||
| 0ea10c40fc | |||
| 94be253768 | |||
| 651ec2daee | |||
| ac85a43c11 | |||
| ade2ea0f9a | |||
| 28df4f4a04 | |||
| 912938e6cf | |||
| a39e5b7d16 | |||
| 212e891409 | |||
| c3b3bbb8a0 | |||
| 2ea3dadc7b | |||
| 345326d844 | |||
| 9bfbd07251 | |||
| dc35bec4fb | |||
| e11ccd3040 | |||
| 2210a55782 | |||
| 1452086c98 | |||
| 9600e18f65 | |||
| 2331a5c04e | |||
| da66d4e045 | |||
| 90db85aaf0 | |||
| ca22c0f39d | |||
| fc5efccd91 | |||
| f3bd4313df | |||
| a821dabf18 | |||
| 69eccce8eb | |||
| d4f968d799 | |||
| 5ed370013b | |||
| c9b283eca6 | |||
| df19816039 |
@@ -8,6 +8,20 @@ Ansible-роль для установки [Hysteria 2](https://v2.hysteria.netw
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Последние обновления
|
||||||
|
|
||||||
|
### 2026-07-23
|
||||||
|
|
||||||
|
- **`make status`** — краткий статус по хостам (active / not installed, PID, RAM), без длинных логов journal.
|
||||||
|
- **`make index`** — пересборка HTML всех серверов и общего `output/index.html` из локальных `server-info.yml` (без SSH), открытие в браузере.
|
||||||
|
- **Каталог `output/index.html`** — вкладки «Статистика» (по умолчанию) и серверы (`vps-db`, `vps-kz`, …): IP, доступность TCP, пользователи, матрица присутствия.
|
||||||
|
- **Страницы серверов** — сетка карточек и визуальный стиль как у главной; ссылка «← Общий каталог».
|
||||||
|
- **Lightbox QR** — крупный просмотр на высоту экрана, кнопка скачивания `<сервер>-<пользователь>.png`.
|
||||||
|
- **Скачивание файлов** — ссылки `.url` / `.txt` / `.png` / `.qr.txt` принудительно скачивают файл как `<сервер>-<пользователь>.ext`, а не открывают его во вкладке браузера.
|
||||||
|
- **`make install` / `make update` / `make export`** — в конце тот же pipeline HTML, что и у `make index`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Выбор ветки: `main` или `salamander`
|
## Выбор ветки: `main` или `salamander`
|
||||||
|
|
||||||
| | **`main`** | **`salamander` (эта ветка)** |
|
| | **`main`** | **`salamander` (эта ветка)** |
|
||||||
|
|||||||
@@ -516,8 +516,10 @@
|
|||||||
background: var(--bg-input);
|
background: var(--bg-input);
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
font: inherit;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
font-weight: 650;
|
font-weight: 650;
|
||||||
|
cursor: pointer;
|
||||||
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
||||||
}
|
}
|
||||||
.lightbox-download:hover {
|
.lightbox-download:hover {
|
||||||
@@ -625,7 +627,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="meta-item">
|
<div class="meta-item">
|
||||||
<label>Режим</label>
|
<label>Режим</label>
|
||||||
<span>{{ server.mode | default('salamander') | e }}</span>
|
<span>{{ server.mode | default('masquerade') | e }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="meta-item">
|
<div class="meta-item">
|
||||||
<label>Пользователи</label>
|
<label>Пользователи</label>
|
||||||
@@ -716,16 +718,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% set _png = namespace(b64='', data='') %}
|
||||||
{% if user.has_png | default(false) %}
|
{% if user.has_png | default(false) %}
|
||||||
|
{% set _png.b64 = lookup('pipe', 'base64 < ' ~ ((hysteria2_output_dir ~ '/' ~ server.dir ~ '/' ~ user.name ~ '.png') | quote)) | regex_replace('\\s+', '') %}
|
||||||
|
{% set _png.data = 'data:image/png;base64,' ~ _png.b64 %}
|
||||||
<div class="qr-block">
|
<div class="qr-block">
|
||||||
<img
|
<img
|
||||||
src="{{ server.dir | e }}/{{ user.name | e }}.png"
|
src="{{ _png.data }}"
|
||||||
alt="QR {{ user.name | e }}"
|
alt="QR {{ user.name | e }}"
|
||||||
width="160"
|
width="160"
|
||||||
height="160"
|
height="160"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
data-lightbox-src="{{ server.dir | e }}/{{ user.name | e }}.png"
|
data-lightbox-src="{{ _png.data }}"
|
||||||
data-lightbox-caption="{{ server.name | e }} · {{ user.name | e }}"
|
data-lightbox-caption="{{ server.name | e }} · {{ user.name | e }}"
|
||||||
data-lightbox-download="{{ server.name | e }}-{{ user.name | e }}.png"
|
data-lightbox-download="{{ server.name | e }}-{{ user.name | e }}.png"
|
||||||
aria-label="Открыть QR-код {{ user.name | e }}"
|
aria-label="Открыть QR-код {{ user.name | e }}"
|
||||||
@@ -734,12 +739,12 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<nav class="files" aria-label="Файлы">
|
<nav class="files" aria-label="Файлы">
|
||||||
<a href="{{ server.dir | e }}/{{ user.name | e }}.url" download>.url</a>
|
<a class="file-download" href="{{ server.dir | e }}/{{ user.name | e }}.url" download="{{ server.name | e }}-{{ user.name | e }}.url" data-filename="{{ server.name | e }}-{{ user.name | e }}.url" data-text="{{ (user.url ~ '\n') | e }}">.url</a>
|
||||||
<a href="{{ server.dir | e }}/{{ user.name | e }}.txt" download>.txt</a>
|
<a class="file-download" href="{{ server.dir | e }}/{{ user.name | e }}.txt" download="{{ server.name | e }}-{{ user.name | e }}.txt" data-filename="{{ server.name | e }}-{{ user.name | e }}.txt" data-text="{{ ('Server: ' ~ server.name ~ '\nDomain: ' ~ server.domain ~ ':' ~ server.port ~ '\nUser: ' ~ user.name ~ '\nPassword: ' ~ user.password ~ '\n\nURL:\n' ~ user.url ~ '\n') | e }}">.txt</a>
|
||||||
{% if user.has_png | default(false) %}
|
{% if user.has_png | default(false) and _png.b64 %}
|
||||||
<a href="{{ server.dir | e }}/{{ user.name | e }}.png" download>.png</a>
|
<a class="file-download" href="{{ server.dir | e }}/{{ user.name | e }}.png" download="{{ server.name | e }}-{{ user.name | e }}.png" data-filename="{{ server.name | e }}-{{ user.name | e }}.png" data-png-b64="{{ _png.b64 }}">.png</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ server.dir | e }}/{{ user.name | e }}.qr.txt" download>.qr.txt</a>
|
<a class="file-download" href="{{ server.dir | e }}/{{ user.name | e }}.qr.txt" download="{{ server.name | e }}-{{ user.name | e }}.qr.txt" data-filename="{{ server.name | e }}-{{ user.name | e }}.qr.txt" data-text="{{ lookup('file', hysteria2_output_dir ~ '/' ~ server.dir ~ '/' ~ user.name ~ '.qr.txt', errors='ignore') | default('URL: ' ~ user.url ~ '\n', true) | e }}">.qr.txt</a>
|
||||||
</nav>
|
</nav>
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -759,10 +764,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<p class="lightbox-caption" id="lightbox-caption"></p>
|
<p class="lightbox-caption" id="lightbox-caption"></p>
|
||||||
<div class="lightbox-actions">
|
<div class="lightbox-actions">
|
||||||
<a class="lightbox-download" id="lightbox-download" href="#" download>
|
<button type="button" class="lightbox-download" id="lightbox-download">
|
||||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
||||||
Скачать QR
|
Скачать QR
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -825,14 +830,76 @@
|
|||||||
var caption = document.getElementById('lightbox-caption');
|
var caption = document.getElementById('lightbox-caption');
|
||||||
var closeBtn = document.getElementById('lightbox-close');
|
var closeBtn = document.getElementById('lightbox-close');
|
||||||
var downloadBtn = document.getElementById('lightbox-download');
|
var downloadBtn = document.getElementById('lightbox-download');
|
||||||
|
var downloadSrc = '';
|
||||||
|
|
||||||
|
function triggerDataUrlDownload(dataUrl, filename) {
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = dataUrl;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerFileDownload(blob, filename) {
|
||||||
|
var url = URL.createObjectURL(blob);
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
setTimeout(function () { URL.revokeObjectURL(url); }, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadQrFromCanvas(filename) {
|
||||||
|
if (!img.complete || !img.naturalWidth) return false;
|
||||||
|
try {
|
||||||
|
var canvas = document.createElement('canvas');
|
||||||
|
canvas.width = img.naturalWidth;
|
||||||
|
canvas.height = img.naturalHeight;
|
||||||
|
canvas.getContext('2d').drawImage(img, 0, 0);
|
||||||
|
// toDataURL sync — download stays in the user-gesture (Safari/Chrome)
|
||||||
|
triggerDataUrlDownload(canvas.toDataURL('image/png'), filename);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadQrImage(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
var filename = downloadBtn.getAttribute('data-filename') || 'qr.png';
|
||||||
|
var src = downloadSrc || img.currentSrc || img.src;
|
||||||
|
|
||||||
|
// Embedded data: URLs work on file:// (no CORS / tainted canvas)
|
||||||
|
if (src && src.indexOf('data:') === 0) {
|
||||||
|
triggerDataUrlDownload(src, filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (downloadQrFromCanvas(filename)) return;
|
||||||
|
if (!src || location.protocol === 'file:') return;
|
||||||
|
|
||||||
|
fetch(src)
|
||||||
|
.then(function (res) {
|
||||||
|
if (!res.ok) throw new Error('fetch failed');
|
||||||
|
return res.blob();
|
||||||
|
})
|
||||||
|
.then(function (blob) { triggerFileDownload(blob, filename); })
|
||||||
|
.catch(function () { /* avoid navigating to the image URL */ });
|
||||||
|
}
|
||||||
|
|
||||||
function openLightbox(src, text, alt, filename) {
|
function openLightbox(src, text, alt, filename) {
|
||||||
|
var safeName = filename || 'qr.png';
|
||||||
img.src = src;
|
img.src = src;
|
||||||
img.alt = alt || text || 'QR';
|
img.alt = alt || text || 'QR';
|
||||||
caption.textContent = text || '';
|
caption.textContent = text || '';
|
||||||
downloadBtn.href = src;
|
downloadSrc = src;
|
||||||
downloadBtn.setAttribute('download', filename || 'qr.png');
|
downloadBtn.setAttribute('data-filename', safeName);
|
||||||
downloadBtn.setAttribute('aria-label', 'Скачать ' + (filename || 'qr.png'));
|
downloadBtn.setAttribute('aria-label', 'Скачать ' + safeName);
|
||||||
box.classList.add('open');
|
box.classList.add('open');
|
||||||
box.setAttribute('aria-hidden', 'false');
|
box.setAttribute('aria-hidden', 'false');
|
||||||
document.body.classList.add('lightbox-open');
|
document.body.classList.add('lightbox-open');
|
||||||
@@ -844,7 +911,8 @@
|
|||||||
box.setAttribute('aria-hidden', 'true');
|
box.setAttribute('aria-hidden', 'true');
|
||||||
document.body.classList.remove('lightbox-open');
|
document.body.classList.remove('lightbox-open');
|
||||||
img.removeAttribute('src');
|
img.removeAttribute('src');
|
||||||
downloadBtn.removeAttribute('href');
|
downloadSrc = '';
|
||||||
|
downloadBtn.removeAttribute('data-filename');
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll('[data-lightbox-src]').forEach(function (el) {
|
document.querySelectorAll('[data-lightbox-src]').forEach(function (el) {
|
||||||
@@ -865,6 +933,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
downloadBtn.addEventListener('click', downloadQrImage);
|
||||||
closeBtn.addEventListener('click', closeLightbox);
|
closeBtn.addEventListener('click', closeLightbox);
|
||||||
box.addEventListener('click', function (e) {
|
box.addEventListener('click', function (e) {
|
||||||
if (e.target === box) closeLightbox();
|
if (e.target === box) closeLightbox();
|
||||||
@@ -873,6 +942,84 @@
|
|||||||
if (e.key === 'Escape' && box.classList.contains('open')) closeLightbox();
|
if (e.key === 'Escape' && box.classList.contains('open')) closeLightbox();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
function triggerDataUrlDownload(dataUrl, filename) {
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = dataUrl;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerFileDownload(blob, filename) {
|
||||||
|
var url = URL.createObjectURL(blob);
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
setTimeout(function () { URL.revokeObjectURL(url); }, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pngFromCard(link, filename) {
|
||||||
|
var card = link.closest('.user-card');
|
||||||
|
var qrImg = card && card.querySelector('img[data-lightbox-src], .qr-block img');
|
||||||
|
if (!qrImg) return false;
|
||||||
|
var src = qrImg.currentSrc || qrImg.src || '';
|
||||||
|
if (src.indexOf('data:image/') === 0) {
|
||||||
|
triggerDataUrlDownload(src, filename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!qrImg.complete || !qrImg.naturalWidth) return false;
|
||||||
|
try {
|
||||||
|
var canvas = document.createElement('canvas');
|
||||||
|
canvas.width = qrImg.naturalWidth;
|
||||||
|
canvas.height = qrImg.naturalHeight;
|
||||||
|
canvas.getContext('2d').drawImage(qrImg, 0, 0);
|
||||||
|
triggerDataUrlDownload(canvas.toDataURL('image/png'), filename);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('a.file-download').forEach(function (link) {
|
||||||
|
link.addEventListener('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
var filename = link.getAttribute('data-filename') || link.getAttribute('download') || 'download';
|
||||||
|
var href = link.getAttribute('href');
|
||||||
|
var fallbackText = link.getAttribute('data-text');
|
||||||
|
var pngB64 = link.getAttribute('data-png-b64');
|
||||||
|
var isPng = /\.png$/i.test(filename);
|
||||||
|
|
||||||
|
// Sync paths first — file:// blocks fetch (CORS) and taints canvas
|
||||||
|
if (pngB64) {
|
||||||
|
triggerDataUrlDownload('data:image/png;base64,' + pngB64, filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPng && pngFromCard(link, filename)) return;
|
||||||
|
if (fallbackText !== null) {
|
||||||
|
triggerFileDownload(new Blob([fallbackText], { type: 'text/plain;charset=utf-8' }), filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!href || location.protocol === 'file:') return;
|
||||||
|
|
||||||
|
fetch(href)
|
||||||
|
.then(function (res) {
|
||||||
|
if (!res.ok) throw new Error('fetch failed');
|
||||||
|
return res.blob();
|
||||||
|
})
|
||||||
|
.then(function (blob) { triggerFileDownload(blob, filename); })
|
||||||
|
.catch(function () { /* do not navigate to the file URL */ });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -333,8 +333,10 @@
|
|||||||
background: var(--bg-input);
|
background: var(--bg-input);
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
font: inherit;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
font-weight: 650;
|
font-weight: 650;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.lightbox-download:hover {
|
.lightbox-download:hover {
|
||||||
border-color: var(--accent);
|
border-color: var(--accent);
|
||||||
@@ -422,16 +424,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% set _png = namespace(b64='', data='') %}
|
||||||
{% if user.has_png | default(false) %}
|
{% if user.has_png | default(false) %}
|
||||||
|
{% set _png.b64 = lookup('pipe', 'base64 < ' ~ ((hysteria2_output_dir ~ '/' ~ hysteria2_output_name ~ '/' ~ user.name ~ '.png') | quote)) | regex_replace('\\s+', '') %}
|
||||||
|
{% set _png.data = 'data:image/png;base64,' ~ _png.b64 %}
|
||||||
<div class="qr-block">
|
<div class="qr-block">
|
||||||
<img
|
<img
|
||||||
src="{{ user.name | e }}.png"
|
src="{{ _png.data }}"
|
||||||
alt="QR {{ user.name | e }}"
|
alt="QR {{ user.name | e }}"
|
||||||
width="160"
|
width="160"
|
||||||
height="160"
|
height="160"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
data-lightbox-src="{{ user.name | e }}.png"
|
data-lightbox-src="{{ _png.data }}"
|
||||||
data-lightbox-caption="{{ hysteria2_output_name | e }} · {{ user.name | e }}"
|
data-lightbox-caption="{{ hysteria2_output_name | e }} · {{ user.name | e }}"
|
||||||
data-lightbox-download="{{ hysteria2_output_name | e }}-{{ user.name | e }}.png"
|
data-lightbox-download="{{ hysteria2_output_name | e }}-{{ user.name | e }}.png"
|
||||||
aria-label="Открыть QR-код {{ user.name | e }}"
|
aria-label="Открыть QR-код {{ user.name | e }}"
|
||||||
@@ -440,12 +445,12 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<nav class="files" aria-label="Файлы">
|
<nav class="files" aria-label="Файлы">
|
||||||
<a href="{{ user.name | e }}.url" download>.url</a>
|
<a class="file-download" href="{{ user.name | e }}.url" download="{{ hysteria2_output_name | e }}-{{ user.name | e }}.url" data-filename="{{ hysteria2_output_name | e }}-{{ user.name | e }}.url" data-text="{{ (user.url ~ '\n') | e }}">.url</a>
|
||||||
<a href="{{ user.name | e }}.txt" download>.txt</a>
|
<a class="file-download" href="{{ user.name | e }}.txt" download="{{ hysteria2_output_name | e }}-{{ user.name | e }}.txt" data-filename="{{ hysteria2_output_name | e }}-{{ user.name | e }}.txt" data-text="{{ ('Server: ' ~ hysteria2_output_name ~ '\nDomain: ' ~ hysteria2_domain ~ ':' ~ hysteria2_listen_port ~ '\nUser: ' ~ user.name ~ '\nPassword: ' ~ user.password ~ '\n\nURL:\n' ~ user.url ~ '\n') | e }}">.txt</a>
|
||||||
{% if user.has_png | default(false) %}
|
{% if user.has_png | default(false) and _png.b64 %}
|
||||||
<a href="{{ user.name | e }}.png" download>.png</a>
|
<a class="file-download" href="{{ user.name | e }}.png" download="{{ hysteria2_output_name | e }}-{{ user.name | e }}.png" data-filename="{{ hysteria2_output_name | e }}-{{ user.name | e }}.png" data-png-b64="{{ _png.b64 }}">.png</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ user.name | e }}.qr.txt" download>.qr.txt</a>
|
<a class="file-download" href="{{ user.name | e }}.qr.txt" download="{{ hysteria2_output_name | e }}-{{ user.name | e }}.qr.txt" data-filename="{{ hysteria2_output_name | e }}-{{ user.name | e }}.qr.txt" data-text="{{ lookup('file', hysteria2_output_dir ~ '/' ~ hysteria2_output_name ~ '/' ~ user.name ~ '.qr.txt', errors='ignore') | default('URL: ' ~ user.url ~ '\n', true) | e }}">.qr.txt</a>
|
||||||
</nav>
|
</nav>
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -463,10 +468,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<p class="lightbox-caption" id="lightbox-caption"></p>
|
<p class="lightbox-caption" id="lightbox-caption"></p>
|
||||||
<div class="lightbox-actions">
|
<div class="lightbox-actions">
|
||||||
<a class="lightbox-download" id="lightbox-download" href="#" download>
|
<button type="button" class="lightbox-download" id="lightbox-download">
|
||||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
||||||
Скачать QR
|
Скачать QR
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -502,14 +507,76 @@
|
|||||||
var caption = document.getElementById('lightbox-caption');
|
var caption = document.getElementById('lightbox-caption');
|
||||||
var closeBtn = document.getElementById('lightbox-close');
|
var closeBtn = document.getElementById('lightbox-close');
|
||||||
var downloadBtn = document.getElementById('lightbox-download');
|
var downloadBtn = document.getElementById('lightbox-download');
|
||||||
|
var downloadSrc = '';
|
||||||
|
|
||||||
|
function triggerDataUrlDownload(dataUrl, filename) {
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = dataUrl;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerFileDownload(blob, filename) {
|
||||||
|
var url = URL.createObjectURL(blob);
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
setTimeout(function () { URL.revokeObjectURL(url); }, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadQrFromCanvas(filename) {
|
||||||
|
if (!img.complete || !img.naturalWidth) return false;
|
||||||
|
try {
|
||||||
|
var canvas = document.createElement('canvas');
|
||||||
|
canvas.width = img.naturalWidth;
|
||||||
|
canvas.height = img.naturalHeight;
|
||||||
|
canvas.getContext('2d').drawImage(img, 0, 0);
|
||||||
|
// toDataURL sync — download stays in the user-gesture (Safari/Chrome)
|
||||||
|
triggerDataUrlDownload(canvas.toDataURL('image/png'), filename);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadQrImage(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
var filename = downloadBtn.getAttribute('data-filename') || 'qr.png';
|
||||||
|
var src = downloadSrc || img.currentSrc || img.src;
|
||||||
|
|
||||||
|
// Embedded data: URLs work on file:// (no CORS / tainted canvas)
|
||||||
|
if (src && src.indexOf('data:') === 0) {
|
||||||
|
triggerDataUrlDownload(src, filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (downloadQrFromCanvas(filename)) return;
|
||||||
|
if (!src || location.protocol === 'file:') return;
|
||||||
|
|
||||||
|
fetch(src)
|
||||||
|
.then(function (res) {
|
||||||
|
if (!res.ok) throw new Error('fetch failed');
|
||||||
|
return res.blob();
|
||||||
|
})
|
||||||
|
.then(function (blob) { triggerFileDownload(blob, filename); })
|
||||||
|
.catch(function () { /* avoid navigating to the image URL */ });
|
||||||
|
}
|
||||||
|
|
||||||
function openLightbox(src, text, alt, filename) {
|
function openLightbox(src, text, alt, filename) {
|
||||||
|
var safeName = filename || 'qr.png';
|
||||||
img.src = src;
|
img.src = src;
|
||||||
img.alt = alt || text || 'QR';
|
img.alt = alt || text || 'QR';
|
||||||
caption.textContent = text || '';
|
caption.textContent = text || '';
|
||||||
downloadBtn.href = src;
|
downloadSrc = src;
|
||||||
downloadBtn.setAttribute('download', filename || 'qr.png');
|
downloadBtn.setAttribute('data-filename', safeName);
|
||||||
downloadBtn.setAttribute('aria-label', 'Скачать ' + (filename || 'qr.png'));
|
downloadBtn.setAttribute('aria-label', 'Скачать ' + safeName);
|
||||||
box.classList.add('open');
|
box.classList.add('open');
|
||||||
box.setAttribute('aria-hidden', 'false');
|
box.setAttribute('aria-hidden', 'false');
|
||||||
document.body.classList.add('lightbox-open');
|
document.body.classList.add('lightbox-open');
|
||||||
@@ -521,7 +588,8 @@
|
|||||||
box.setAttribute('aria-hidden', 'true');
|
box.setAttribute('aria-hidden', 'true');
|
||||||
document.body.classList.remove('lightbox-open');
|
document.body.classList.remove('lightbox-open');
|
||||||
img.removeAttribute('src');
|
img.removeAttribute('src');
|
||||||
downloadBtn.removeAttribute('href');
|
downloadSrc = '';
|
||||||
|
downloadBtn.removeAttribute('data-filename');
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll('[data-lightbox-src]').forEach(function (el) {
|
document.querySelectorAll('[data-lightbox-src]').forEach(function (el) {
|
||||||
@@ -542,6 +610,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
downloadBtn.addEventListener('click', downloadQrImage);
|
||||||
closeBtn.addEventListener('click', closeLightbox);
|
closeBtn.addEventListener('click', closeLightbox);
|
||||||
box.addEventListener('click', function (e) {
|
box.addEventListener('click', function (e) {
|
||||||
if (e.target === box) closeLightbox();
|
if (e.target === box) closeLightbox();
|
||||||
@@ -550,6 +619,84 @@
|
|||||||
if (e.key === 'Escape' && box.classList.contains('open')) closeLightbox();
|
if (e.key === 'Escape' && box.classList.contains('open')) closeLightbox();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
function triggerDataUrlDownload(dataUrl, filename) {
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = dataUrl;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerFileDownload(blob, filename) {
|
||||||
|
var url = URL.createObjectURL(blob);
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
a.rel = 'noopener';
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
setTimeout(function () { URL.revokeObjectURL(url); }, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pngFromCard(link, filename) {
|
||||||
|
var card = link.closest('.user-card');
|
||||||
|
var qrImg = card && card.querySelector('img[data-lightbox-src], .qr-block img');
|
||||||
|
if (!qrImg) return false;
|
||||||
|
var src = qrImg.currentSrc || qrImg.src || '';
|
||||||
|
if (src.indexOf('data:image/') === 0) {
|
||||||
|
triggerDataUrlDownload(src, filename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!qrImg.complete || !qrImg.naturalWidth) return false;
|
||||||
|
try {
|
||||||
|
var canvas = document.createElement('canvas');
|
||||||
|
canvas.width = qrImg.naturalWidth;
|
||||||
|
canvas.height = qrImg.naturalHeight;
|
||||||
|
canvas.getContext('2d').drawImage(qrImg, 0, 0);
|
||||||
|
triggerDataUrlDownload(canvas.toDataURL('image/png'), filename);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('a.file-download').forEach(function (link) {
|
||||||
|
link.addEventListener('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
var filename = link.getAttribute('data-filename') || link.getAttribute('download') || 'download';
|
||||||
|
var href = link.getAttribute('href');
|
||||||
|
var fallbackText = link.getAttribute('data-text');
|
||||||
|
var pngB64 = link.getAttribute('data-png-b64');
|
||||||
|
var isPng = /\.png$/i.test(filename);
|
||||||
|
|
||||||
|
// Sync paths first — file:// blocks fetch (CORS) and taints canvas
|
||||||
|
if (pngB64) {
|
||||||
|
triggerDataUrlDownload('data:image/png;base64,' + pngB64, filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPng && pngFromCard(link, filename)) return;
|
||||||
|
if (fallbackText !== null) {
|
||||||
|
triggerFileDownload(new Blob([fallbackText], { type: 'text/plain;charset=utf-8' }), filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!href || location.protocol === 'file:') return;
|
||||||
|
|
||||||
|
fetch(href)
|
||||||
|
.then(function (res) {
|
||||||
|
if (!res.ok) throw new Error('fetch failed');
|
||||||
|
return res.blob();
|
||||||
|
})
|
||||||
|
.then(function (blob) { triggerFileDownload(blob, filename); })
|
||||||
|
.catch(function () { /* do not navigate to the file URL */ });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user