removed generate qrcodes that i struggled settin up

This commit is contained in:
iTakinn
2025-10-12 18:58:08 -03:00
parent 662b1e58ee
commit d5a38398f7
2 changed files with 332 additions and 504 deletions
+98 -186
View File
@@ -106,187 +106,47 @@
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/build/qrcode.min.js" onload="initQRCode()" onerror="loadQRCodeFallback()"></script>
<script>
var qrCodeLibraryLoaded = false;
var configForQR = null;
<script src="https://api.qrserver.com/v1/create-qr-code/?size=250x250&format=svg&data=test" style="display:none;"></script>
<script>
var configForQR = null;
function initQRCode() {
qrCodeLibraryLoaded = true;
console.log('QRCode library loaded successfully');
if (configForQR) {
generateQRCode(configForQR);
}
}
function loadQRCodeFallback() {
console.log('Primary QRCode library failed, trying fallback...');
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js';
script.onload = function() {
console.log('Fallback QRCode library loaded');
qrCodeLibraryLoaded = true;
if (configForQR) {
generateQRCodeFallback(configForQR);
}
};
script.onerror = function() {
console.error('Both QRCode libraries failed to load');
function generateQRCode(configText) {
var qrCodeElement = document.getElementById('qrcode');
if (qrCodeElement) {
qrCodeElement.innerHTML = '<p class="text-danger">Unable to load QR Code library</p>';
}
};
document.head.appendChild(script);
}
function generateQRCode(configText) {
var qrCodeElement = document.getElementById('qrcode');
console.log('Generating QR Code with qrcode.js...');
console.log('Config text length:', configText.length);
if (qrCodeElement && configText && configText.trim() !== '') {
// Check if QRCode library is loaded
if (typeof QRCode === 'undefined') {
console.error('Biblioteca QRCode não disponível, tentando fallback');
generateQRCodeFallback(configText);
return;
}
try {
QRCode.toCanvas(qrCodeElement, configText, {
width: 250,
margin: 3,
color: {
dark: '#000000',
light: '#FFFFFF'
}
}, function(error) {
if (error) {
console.error('Falha na geração do QR Code:', error);
qrCodeElement.innerHTML = '<p class="text-danger">Falha na geração do QR Code: ' + error.message + '</p>';
} else {
console.log('QR Code gerado com sucesso');
}
});
} catch (e) {
console.error('Exceção durante a geração do QR code:', e);
qrCodeElement.innerHTML = '<p class="text-danger">Erro na geração do QR Code: ' + e.message + '</p>';
}
} else {
console.error('Falha na geração do QR Code: elemento ou configuração ausente');
if (qrCodeElement) {
qrCodeElement.innerHTML = '<p class="text-warning">Configuração não disponível para QR code</p>';
}
}
}
function generateQRCodeFallback(configText) {
var qrCodeElement = document.getElementById('qrcode');
console.log('Trying fallback QR code generation...');
if (qrCodeElement && configText) {
try {
// Create QR code using online service as fallback
var qrUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=250x250&data=' + encodeURIComponent(configText);
var img = document.createElement('img');
img.src = qrUrl;
img.alt = 'WireGuard QR Code';
img.style.border = '3px solid #ddd';
img.style.borderRadius = '4px';
img.onload = function() {
console.log('Fallback QR code loaded successfully');
};
img.onerror = function() {
qrCodeElement.innerHTML = '<p class="text-danger">Falha ao gerar código QR</p>';
};
qrCodeElement.innerHTML = '';
qrCodeElement.appendChild(img);
} catch (e) {
console.error('Falha na geração do QR code de fallback:', e);
qrCodeElement.innerHTML = '<p class="text-danger">Falha na geração do código QR</p>';
}
}
}
// Generate QR Code if formatted config is available
{if $formatted_config}
document.addEventListener('DOMContentLoaded', function() {
configForQR = {$formatted_config|json_encode};
if (qrCodeLibraryLoaded) {
generateQRCode(configForQR);
} else {
console.log('Waiting for QRCode library to load...');
// Timeout fallback
setTimeout(function() {
if (!qrCodeLibraryLoaded && configForQR) {
console.log('Timeout reached, using fallback QR generation');
generateQRCodeFallback(configForQR);
if (qrCodeElement && configText && configText.trim() !== '') {
try {
var qrUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=250x250&data=' + encodeURIComponent(configText);
var img = document.createElement('img');
img.src = qrUrl;
img.alt = 'WireGuard QR Code';
img.style.border = '3px solid #ddd';
img.style.borderRadius = '4px';
img.onerror = function() {
qrCodeElement.innerHTML = '<p class="text-danger">Failed to generate QR code</p>';
};
qrCodeElement.innerHTML = '';
qrCodeElement.appendChild(img);
} catch (e) {
console.error('QR code generation failed:', e);
qrCodeElement.innerHTML = '<p class="text-danger">Failed to generate QR code</p>';
}
}, 3000);
}
});
{else}
console.log('No formatted config available for QR code');
{/if}
function downloadFormattedConfig() {
{if $formatted_config}
var config = {$formatted_config|json_encode};
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(config));
element.setAttribute('download', '{$peer_name|default:"wireguard"}.conf');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
{/if}
}
function copyFormattedConfig() {
{if $formatted_config}
var config = {$formatted_config|json_encode};
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(config).then(function() {
alert('Configuração copiada para a área de transferência!');
}).catch(function(err) {
fallbackCopyTextToClipboard(config);
});
} else {
fallbackCopyTextToClipboard(config);
}
{/if}
}
function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
if (successful) {
alert('Configuração copiada para a área de transferência!');
} else {
alert('Falha ao copiar configuração. Por favor, copie manualmente.');
if (qrCodeElement) {
qrCodeElement.innerHTML = '<p class="text-warning">Configuration not available for QR code</p>';
}
}
} catch (err) {
alert('Falha ao copiar configuração. Por favor, copie manualmente.');
}
document.body.removeChild(textArea);
}
// Legacy functions for backward compatibility
function downloadConfig() {
var textarea = document.querySelector('textarea');
if (textarea) {
var config = textarea.value;
{if $formatted_config}
document.addEventListener('DOMContentLoaded', function() {
configForQR = {$formatted_config|json_encode};
generateQRCode(configForQR);
});
{/if}
function downloadFormattedConfig() {
{if $formatted_config}
var config = {$formatted_config|json_encode};
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(config));
element.setAttribute('download', '{$peer_name|default:"wireguard"}.conf');
@@ -294,26 +154,78 @@ function downloadConfig() {
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
{/if}
}
}
function copyConfig() {
var textarea = document.querySelector('textarea');
if (textarea) {
textarea.select();
function copyFormattedConfig() {
{if $formatted_config}
var config = {$formatted_config|json_encode};
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(config).then(function() {
alert('Configuration copied to clipboard!');
}).catch(function(err) {
fallbackCopyTextToClipboard(config);
});
} else {
fallbackCopyTextToClipboard(config);
}
{/if}
}
function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
alert('Configuração copiada para a área de transferência!');
var successful = document.execCommand('copy');
if (successful) {
alert('Configuration copied to clipboard!');
} else {
alert('Failed to copy configuration. Please copy manually.');
}
} catch (err) {
alert('Falha ao copiar configuração. Por favor, selecione e copie manualmente.');
alert('Failed to copy configuration. Please copy manually.');
}
document.body.removeChild(textArea);
}
// Legacy functions for backward compatibility
function downloadConfig() {
var textarea = document.querySelector('textarea');
if (textarea) {
var config = textarea.value;
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(config));
element.setAttribute('download', '{$peer_name|default:"wireguard"}.conf');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
}
}
function showInstructions() {
$('#instructionsModal').modal('show');
}
</script>
function copyConfig() {
var textarea = document.querySelector('textarea');
if (textarea) {
textarea.select();
try {
document.execCommand('copy');
alert('Configuration copied to clipboard!');
} catch (err) {
alert('Failed to copy configuration. Please select and copy manually.');
}
}
}
function showInstructions() {
$('#instructionsModal').modal('show');
}
</script>
<style>
.panel-heading .fa {