Note: We appreciate your feedback and bug reports to continue improving our platform. Thank you for your continued support!
This commit is contained in:
@@ -1,254 +1,464 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
|
||||
<link rel="stylesheet" href="/public/css/login.css">
|
||||
<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>
|
||||
.custom-btn {
|
||||
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;
|
||||
font-family: inherit;
|
||||
border-radius: var(--radius);
|
||||
font-weight: 500;
|
||||
font-size: 14px; /* réduit la taille de la police */
|
||||
padding: 0.6em 1.2em; /* réduit le padding */
|
||||
color: white;
|
||||
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%);
|
||||
border: none;
|
||||
box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
|
||||
letter-spacing: 0.05em;
|
||||
border-radius: 15em; /* réduit le rayon de la bordure */
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
padding: 5px 15px;
|
||||
margin: 8px 0;
|
||||
box-sizing: border-box;
|
||||
border: none;
|
||||
border-bottom: 2px solid #007BFF;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.btn-primary {
|
||||
background-color: hsl(var(--primary));
|
||||
color: hsl(var(--primary-foreground));
|
||||
}
|
||||
|
||||
input[type="text"]:focus {
|
||||
border-bottom: 2px solid #555;
|
||||
}
|
||||
.btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 60px;
|
||||
height: 34px;
|
||||
}
|
||||
.btn-secondary {
|
||||
background-color: hsl(var(--secondary));
|
||||
color: hsl(var(--secondary-foreground));
|
||||
}
|
||||
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
.btn-secondary:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
#themeSwitcher {
|
||||
position: fixed;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 26px;
|
||||
width: 26px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
.animate {
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 60px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px #2196F3;
|
||||
}
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(26px);
|
||||
-ms-transform: translateX(26px);
|
||||
transform: translateX(26px);
|
||||
}
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: hsl(var(--muted));
|
||||
transition: .4s;
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
/* Rounded sliders */
|
||||
.slider.round {
|
||||
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%;
|
||||
}
|
||||
|
||||
.slider.round:before {
|
||||
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>
|
||||
|
||||
<body class="light-mode animate">
|
||||
<div class="container mt-4 table-container animate">
|
||||
<h2 class="text-center">Gestion de la configuration</h2><br>
|
||||
<div class="table-responsive">
|
||||
<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>
|
||||
|
||||
<form action="/api/dpanel/dashboard/admin/update-setup" method="POST">
|
||||
<table class="table w-100">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paramètre</th>
|
||||
<th>Valeur</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="2"><h2>LDAP Settings</h2></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Activer LDAP:</td>
|
||||
<td>
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="ldap[enabled]" <%= setup.ldap ? 'checked' : '' %>
|
||||
onchange="toggleForm('ldapForm', this)">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tbody id="ldapForm" style="display: block">
|
||||
<tr>
|
||||
<td>URL:</td>
|
||||
<td><input type="text" name="ldap[url]" value="<%= setup.ldap ? setup.ldap.url : '' %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Base DN:</td>
|
||||
<td><input type="text" name="ldap[baseDN]" value="<%= setup.ldap ? setup.ldap.baseDN : '' %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Username:</td>
|
||||
<td><input type="text" name="ldap[username]" value="<%= setup.ldap ? setup.ldap.username : '' %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password:</td>
|
||||
<td><input type="text" name="ldap[password]" value="<%= setup.ldap ? setup.ldap.password : '' %>"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<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>
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h2>Discord Settings</h2></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Activer Discord:</td>
|
||||
<td>
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="discord[enabled]" <%= setup.discord ? 'checked' : '' %>
|
||||
onchange="toggleForm('discordForm', this)">
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tbody id="discordForm" style="display: block">
|
||||
<tr>
|
||||
<td>Client ID:</td>
|
||||
<td><input type="text" name="discord[clientID]" value="<%= setup.discord ? setup.discord.clientID : '' %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Client Secret:</td>
|
||||
<td><input type="text" name="discord[clientSecret]" value="<%= setup.discord ? setup.discord.clientSecret : '' %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Identify URL:</td>
|
||||
<td><input type="text" name="discord[identifyURL]" value="<%= setup.discord ? setup.discord.identifyURL : '' %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Authorized IDs:</td>
|
||||
<td><input type="text" name="discord[authorizedIDs]" value="<%= setup.discord ? setup.discord.authorizedIDs : '' %>">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<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>
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h2>Other Settings</h2></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Domain:</td>
|
||||
<td><input type="text" name="domain" value="<%= setup.domain %>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Discord WebHooks:</td>
|
||||
<td><input type="text" name="webhooks_discord" value="<%= setup.webhooks_discord %>"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-primary custom-btn">Mettre à jour</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<a class="dropdown-item text-center text-white no-hover custom-btn" href="/dpanel/dashboard/admin/" style="max-width: 250px; padding: 10px;">
|
||||
<i class="fas fa-sign-out-alt text-white "></i> Retourner au dashboard admin
|
||||
</a>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center animate">
|
||||
<button id="themeSwitcher" class="btn btn-warning mt-3 animate ">Changer de Thème</button>
|
||||
<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>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
|
||||
<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');
|
||||
|
||||
document.getElementById('themeSwitcher').addEventListener('click', function () {
|
||||
if (body.classList.contains('dark-mode')) {
|
||||
body.classList.remove('dark-mode');
|
||||
body.classList.add('light-mode');
|
||||
} else {
|
||||
body.classList.remove('light-mode');
|
||||
body.classList.add('dark-mode');
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const darkModeSwitch = document.getElementById('darkModeSwitch');
|
||||
|
||||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
|
||||
body.classList.toggle('dark-mode', darkModeMediaQuery.matches);
|
||||
|
||||
darkModeMediaQuery.addListener(function (e) {
|
||||
body.classList.toggle('dark-mode', e.matches);
|
||||
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)
|
||||
`
|
||||
});
|
||||
});
|
||||
|
||||
function toggleForm(formId, checkbox) {
|
||||
const form = document.getElementById(formId);
|
||||
form.style.display = checkbox.checked ? 'block' : 'none';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
return;
|
||||
}
|
||||
|
||||
</html>
|
||||
// Soumettre le formulaire si tout est valide
|
||||
this.submit();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user