All checks were successful
continuous-integration/drone/push Build is passing
Note: We appreciate your feedback and bug reports to continue improving our platform. Thank you for your continued support!
464 lines
20 KiB
Plaintext
464 lines
20 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Parameter Admin</title>
|
|
<link rel="icon" href="/public/assets/homelab_logo.png" />
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
|
|
<style>
|
|
body {
|
|
background-image: url('<%= user.wallpaper %>');
|
|
background-size: cover;
|
|
background-position: center;
|
|
background-repeat: no-repeat;
|
|
background-attachment: fixed;
|
|
margin: 0;
|
|
min-height: 100vh;
|
|
overflow-y: auto;
|
|
}
|
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
|
|
|
|
:root {
|
|
--background: 0 0% 100%;
|
|
--foreground: 222.2 84% 4.9%;
|
|
--card: 0 0% 100%;
|
|
--card-foreground: 222.2 84% 4.9%;
|
|
--popover: 0 0% 100%;
|
|
--popover-foreground: 222.2 84% 4.9%;
|
|
--primary: 222.2 47.4% 11.2%;
|
|
--primary-foreground: 210 40% 98%;
|
|
--secondary: 210 40% 96.1%;
|
|
--secondary-foreground: 222.2 47.4% 11.2%;
|
|
--muted: 210 40% 96.1%;
|
|
--muted-foreground: 215.4 16.3% 46.9%;
|
|
--accent: 210 40% 96.1%;
|
|
--accent-foreground: 222.2 47.4% 11.2%;
|
|
--destructive: 0 84.2% 60.2%;
|
|
--destructive-foreground: 210 40% 98%;
|
|
--border: 214.3 31.8% 91.4%;
|
|
--input: 214.3 31.8% 91.4%;
|
|
--ring: 222.2 84% 4.9%;
|
|
--radius: 0.5rem;
|
|
}
|
|
|
|
.dark {
|
|
--background: 222.2 84% 4.9%;
|
|
--foreground: 210 40% 98%;
|
|
--card: 222.2 84% 4.9%;
|
|
--card-foreground: 210 40% 98%;
|
|
--popover: 222.2 84% 4.9%;
|
|
--popover-foreground: 210 40% 98%;
|
|
--primary: 210 40% 98%;
|
|
--primary-foreground: 222.2 47.4% 11.2%;
|
|
--secondary: 217.2 32.6% 17.5%;
|
|
--secondary-foreground: 210 40% 98%;
|
|
--muted: 217.2 32.6% 17.5%;
|
|
--muted-foreground: 215 20.2% 65.1%;
|
|
--accent: 217.2 32.6% 17.5%;
|
|
--accent-foreground: 210 40% 98%;
|
|
--destructive: 0 62.8% 30.6%;
|
|
--destructive-foreground: 210 40% 98%;
|
|
--border: 217.2 32.6% 17.5%;
|
|
--input: 217.2 32.6% 17.5%;
|
|
--ring: 212.7 26.8% 83.9%;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Inter', sans-serif;
|
|
background-color: hsl(var(--background));
|
|
color: hsl(var(--foreground));
|
|
transition: background-color 0.3s ease, color 0.3s ease;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1830px;
|
|
margin: 0 auto;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.form-container {
|
|
background-color: hsl(var(--card));
|
|
border: 1px solid hsl(var(--border));
|
|
border-radius: var(--radius);
|
|
padding: 2rem;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.form-control {
|
|
width: 100%;
|
|
padding: 0.5rem;
|
|
border: 1px solid hsl(var(--border));
|
|
border-radius: var(--radius);
|
|
background-color: hsl(var(--background));
|
|
color: hsl(var(--foreground));
|
|
}
|
|
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: var(--radius);
|
|
font-weight: 500;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: hsl(var(--primary));
|
|
color: hsl(var(--primary-foreground));
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background-color: hsl(var(--secondary));
|
|
color: hsl(var(--secondary-foreground));
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
#themeSwitcher {
|
|
position: fixed;
|
|
top: 1rem;
|
|
right: 1rem;
|
|
}
|
|
|
|
.animate {
|
|
animation: fadeIn 0.5s ease-out;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; }
|
|
to { opacity: 1; }
|
|
}
|
|
|
|
.switch {
|
|
position: relative;
|
|
display: inline-block;
|
|
width: 60px;
|
|
height: 34px;
|
|
}
|
|
|
|
.switch input {
|
|
opacity: 0;
|
|
width: 0;
|
|
height: 0;
|
|
}
|
|
|
|
.slider {
|
|
position: absolute;
|
|
cursor: pointer;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background-color: hsl(var(--muted));
|
|
transition: .4s;
|
|
border-radius: 34px;
|
|
}
|
|
|
|
.slider:before {
|
|
position: absolute;
|
|
content: "";
|
|
height: 26px;
|
|
width: 26px;
|
|
left: 4px;
|
|
bottom: 4px;
|
|
background-color: hsl(var(--background));
|
|
transition: .4s;
|
|
border-radius: 50%;
|
|
}
|
|
|
|
input:checked + .slider {
|
|
background-color: hsl(var(--primary));
|
|
}
|
|
|
|
input:checked + .slider:before {
|
|
transform: translateX(26px);
|
|
}
|
|
|
|
.fade-out {
|
|
animation: fadeOut 0.3s ease-out forwards;
|
|
}
|
|
|
|
@keyframes fadeOut {
|
|
from { opacity: 1; transform: translateY(0); }
|
|
to { opacity: 0; transform: translateY(-10px); }
|
|
}
|
|
|
|
.ip-error {
|
|
border-color: #ef4444 !important;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="animate">
|
|
<div id="app" class="min-h-screen flex items-center justify-center">
|
|
<div class="container mt-8">
|
|
<h1 class="text-3xl font-semibold mb-6 text-center animate">Gestion de la configuration</h1>
|
|
|
|
<div class="form-container">
|
|
<form id="setupForm" action="/api/dpanel/dashboard/admin/update-setup" method="POST" class="mb-4 animate">
|
|
<h2 class="text-2xl font-semibold mb-4">Paramètres LDAP</h2>
|
|
<div class="form-group animate flex items-center justify-between">
|
|
<label for="ldapEnabled" class="block mb-2">Activer LDAP :</label>
|
|
<label class="switch">
|
|
<input type="checkbox" id="ldapEnabled" name="ldap[enabled]" <%= setup.ldap && setup.ldap.enabled === 'on' ? 'checked' : '' %> onchange="toggleForm('ldapForm', this)">
|
|
<span class="slider"></span>
|
|
</label>
|
|
</div>
|
|
<div id="ldapForm" style="display: <%= setup.ldap && setup.ldap.enabled === 'on' ? 'block' : 'none' %>">
|
|
<div class="form-group animate">
|
|
<label for="ldapUrl" class="block mb-2">URL :</label>
|
|
<input type="text" id="ldapUrl" name="ldap[url]" class="form-control" value="<%= setup.ldap ? setup.ldap.url : '' %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="ldapBaseDN" class="block mb-2">Base DN :</label>
|
|
<input type="text" id="ldapBaseDN" name="ldap[baseDN]" class="form-control" value="<%= setup.ldap ? setup.ldap.baseDN : '' %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="ldapUsername" class="block mb-2">Nom d'utilisateur :</label>
|
|
<input type="text" id="ldapUsername" name="ldap[username]" class="form-control" value="<%= setup.ldap ? setup.ldap.username : '' %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="ldapPassword" class="block mb-2">Mot de passe :</label>
|
|
<input type="password" id="ldapPassword" name="ldap[password]" class="form-control" value="<%= setup.ldap ? setup.ldap.password : '' %>">
|
|
</div>
|
|
</div>
|
|
|
|
<h2 class="text-2xl font-semibold mb-4 mt-8">Paramètres Discord</h2>
|
|
<div class="form-group animate flex items-center justify-between">
|
|
<label for="discordEnabled" class="block mb-2">Activer Discord :</label>
|
|
<label class="switch">
|
|
<input type="checkbox" id="discordEnabled" name="discord[enabled]" <%= setup.discord && setup.discord.enabled === 'on' ? 'checked' : '' %> onchange="toggleForm('discordForm', this)">
|
|
<span class="slider"></span>
|
|
</label>
|
|
</div>
|
|
<div id="discordForm" style="<%= `display: ${setup.discord?.enabled === 'on' ? 'block' : 'none'}` %>">
|
|
<div class="form-group animate">
|
|
<label for="discordClientID" class="block mb-2">ID Client :</label>
|
|
<input type="text" id="discordClientID" name="discord[clientID]" class="form-control" value="<%= setup.discord ? setup.discord.clientID : '' %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="discordClientSecret" class="block mb-2">Secret Client :</label>
|
|
<input type="password" id="discordClientSecret" name="discord[clientSecret]" class="form-control" value="<%= setup.discord ? setup.discord.clientSecret : '' %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="discordIdentifyURL" class="block mb-2">URL d'identification :</label>
|
|
<input type="text" id="discordIdentifyURL" name="discord[identifyURL]" class="form-control" value="<%= setup.discord ? setup.discord.identifyURL : '' %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="discordAuthorizedIDs" class="block mb-2">IDs Autorisés :</label>
|
|
<input type="text" id="discordAuthorizedIDs" name="discord[authorizedIDs]" class="form-control" value="<%= setup.discord ? setup.discord.authorizedIDs : '' %>">
|
|
</div>
|
|
</div>
|
|
|
|
<h2 class="text-2xl font-semibold mb-4 mt-8">Autres Paramètres</h2>
|
|
<div class="form-group animate">
|
|
<label for="domain" class="block mb-2">Domaine :</label>
|
|
<input type="text" id="domain" name="domain" class="form-control" value="<%= setup.domain %>">
|
|
</div>
|
|
<div class="form-group animate">
|
|
<label for="webhooksDiscord" class="block mb-2">Webhooks Discord :</label>
|
|
<input type="text" id="webhooksDiscord" name="webhooks_discord" class="form-control" value="<%= setup.webhooks_discord %>">
|
|
</div>
|
|
|
|
<div class="form-group animate">
|
|
<label class="block mb-2">IPs Autorisées pour les Webhooks :</label>
|
|
<div class="space-y-2">
|
|
<div id="ipList" class="space-y-2">
|
|
<% if (setup.allowedIps && setup.allowedIps.length > 0) { %>
|
|
<% setup.allowedIps.forEach((ip, index) => { %>
|
|
<div class="flex items-center space-x-2">
|
|
<input type="text" name="allowedIps[]" class="form-control flex-1" value="<%= ip %>">
|
|
<button type="button" class="btn btn-secondary p-2" onclick="removeIpField(this)">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
<% }) %>
|
|
<% } else { %>
|
|
<div class="flex items-center space-x-2">
|
|
<input type="text" name="allowedIps[]" class="form-control flex-1"
|
|
placeholder="IPv4/IPv6 (ex: 192.168.1.1 ou 2001:db8::1 ou CIDR)">
|
|
<button type="button" class="btn btn-secondary p-2" onclick="removeIpField(this)">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
<% } %>
|
|
</div>
|
|
<button type="button" class="btn btn-secondary w-full py-2" onclick="addIpField()">
|
|
<i class="fas fa-plus mr-2"></i>
|
|
Ajouter une IP
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary w-full py-2 mt-4">
|
|
<i class="fas fa-save mr-2"></i>
|
|
Mettre à jour
|
|
</button>
|
|
</form>
|
|
|
|
<a href="/dpanel/dashboard/admin/" class="btn btn-secondary w-full py-2 mt-4 text-center">
|
|
<i class="fas fa-arrow-left mr-2"></i>
|
|
Retour au tableau de bord admin
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<button id="themeSwitcher" class="btn btn-secondary p-2">
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386l-1.591 1.591M21 12h-2.25m-.386 6.364l-1.591-1.591M12 18.75V21m-4.773-4.227l-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0z" />
|
|
</svg>
|
|
</button>
|
|
|
|
<script>
|
|
const body = document.body;
|
|
const themeSwitcher = document.getElementById('themeSwitcher');
|
|
|
|
// Gestion du thème
|
|
function setTheme(theme) {
|
|
if (theme === 'dark') {
|
|
body.classList.add('dark');
|
|
} else {
|
|
body.classList.remove('dark');
|
|
}
|
|
localStorage.setItem('theme', theme);
|
|
}
|
|
|
|
const savedTheme = localStorage.getItem('theme');
|
|
if (savedTheme) {
|
|
setTheme(savedTheme);
|
|
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
setTheme('dark');
|
|
}
|
|
|
|
themeSwitcher.addEventListener('click', function() {
|
|
if (body.classList.contains('dark')) {
|
|
setTheme('light');
|
|
} else {
|
|
setTheme('dark');
|
|
}
|
|
});
|
|
|
|
// Gestion des formulaires LDAP et Discord
|
|
function toggleForm(formId, checkbox) {
|
|
const form = document.getElementById(formId);
|
|
form.style.display = checkbox.checked ? 'block' : 'none';
|
|
}
|
|
|
|
// Fonctions pour la gestion des IPs
|
|
function addIpField() {
|
|
const ipList = document.getElementById('ipList');
|
|
const newField = document.createElement('div');
|
|
newField.className = 'flex items-center space-x-2 animate';
|
|
newField.innerHTML = `
|
|
<input type="text" name="allowedIps[]" class="form-control flex-1"
|
|
placeholder="ex: 10.20.0.34 ou 10.20.0.0/24">
|
|
<button type="button" class="btn btn-secondary p-2" onclick="removeIpField(this)">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
`;
|
|
ipList.appendChild(newField);
|
|
}
|
|
|
|
function removeIpField(button) {
|
|
const fieldContainer = button.parentElement;
|
|
fieldContainer.classList.add('fade-out');
|
|
setTimeout(() => {
|
|
fieldContainer.remove();
|
|
}, 300);
|
|
}
|
|
|
|
// Fonctions de validation IP
|
|
function validateIP(ip) {
|
|
if (!ip) return false;
|
|
|
|
// Gestion CIDR
|
|
if (ip.includes('/')) {
|
|
const [addr, bits] = ip.split('/');
|
|
const bitsNum = parseInt(bits);
|
|
|
|
if (isIPv4(addr)) {
|
|
return bitsNum >= 0 && bitsNum <= 32;
|
|
} else if (isIPv6(addr)) {
|
|
return bitsNum >= 0 && bitsNum <= 128;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// IP simple
|
|
return isIPv4(ip) || isIPv6(ip);
|
|
}
|
|
|
|
function isIPv4(ip) {
|
|
const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/;
|
|
if (!ipv4Regex.test(ip)) return false;
|
|
|
|
const parts = ip.split('.');
|
|
return parts.every(part => {
|
|
const num = parseInt(part);
|
|
return num >= 0 && num <= 255;
|
|
});
|
|
}
|
|
|
|
function isIPv6(ip) {
|
|
// Regex pour IPv6 standard et compressé
|
|
const ipv6Regex = /^(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
return ipv6Regex.test(ip);
|
|
}
|
|
|
|
// Modification de la validation du formulaire
|
|
document.getElementById('setupForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
const ipInputs = document.querySelectorAll('input[name="allowedIps[]"]');
|
|
let hasError = false;
|
|
|
|
// Réinitialiser les styles d'erreur
|
|
ipInputs.forEach(input => {
|
|
input.classList.remove('ip-error');
|
|
});
|
|
|
|
// Valider chaque IP
|
|
ipInputs.forEach(input => {
|
|
const value = input.value.trim();
|
|
if (value && !validateIP(value)) {
|
|
input.classList.add('ip-error');
|
|
hasError = true;
|
|
}
|
|
});
|
|
|
|
if (hasError) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Erreur de validation',
|
|
html: `
|
|
Veuillez vérifier le format des IPs saisies.<br><br>
|
|
Formats acceptés :<br>
|
|
- IPv4 (ex: 192.168.1.1)<br>
|
|
- IPv4 CIDR (ex: 192.168.1.0/24)<br>
|
|
- IPv6 (ex: 2001:db8::1)<br>
|
|
- IPv6 CIDR (ex: 2001:db8::/32)<br>
|
|
- IPv6 locale (ex: fe80::1)<br>
|
|
- IPv4-mapped IPv6 (ex: ::ffff:192.168.1.1)
|
|
`
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Soumettre le formulaire si tout est valide
|
|
this.submit();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |