You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
368 lines
11 KiB
368 lines
11 KiB
// ============================================
|
|
// SYSTÈME DE VALIDATION DE LICENCE
|
|
// ============================================
|
|
|
|
const LICENSE_STORAGE_KEY = 'git_pusher_license';
|
|
|
|
function initializeLicense() {
|
|
console.log("Initializing license system...");
|
|
|
|
// Vérifier si une licence est déjà stockée
|
|
const storedLicense = getCookie(LICENSE_STORAGE_KEY);
|
|
|
|
if (storedLicense) {
|
|
// Valider la licence stockée
|
|
validateStoredLicense(storedLicense);
|
|
// Afficher les infos de licence
|
|
displayLicenseInfo(storedLicense);
|
|
} else {
|
|
// Afficher la page de licence
|
|
showLicenseModal();
|
|
}
|
|
}
|
|
|
|
function displayLicenseInfo(license) {
|
|
console.log("Displaying license info...");
|
|
|
|
// Chercher le container du badge
|
|
const container = document.getElementById('license-badge-container');
|
|
if (!container) {
|
|
console.error("license-badge-container not found");
|
|
return;
|
|
}
|
|
|
|
// Créer le badge
|
|
const badge = document.createElement('div');
|
|
badge.id = 'license-badge';
|
|
badge.style.cssText = `
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 12px 20px;
|
|
border-radius: 8px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
text-align: center;
|
|
min-width: 200px;
|
|
`;
|
|
|
|
let badgeText = '✓ Licence Activée';
|
|
|
|
// Si c'est une licence d'essai
|
|
if (license.startsWith('TRIAL-')) {
|
|
const daysRemaining = getTrialDaysRemaining(license);
|
|
|
|
if (daysRemaining <= 0) {
|
|
badgeText = '⏱️ Essai expiré';
|
|
badge.style.background = 'linear-gradient(135deg, #f44336 0%, #da190b 100%)';
|
|
} else if (daysRemaining <= 2) {
|
|
badgeText = `⚠️ ${daysRemaining} jour${daysRemaining > 1 ? 's' : ''} restant${daysRemaining > 1 ? 's' : ''}`;
|
|
badge.style.background = 'linear-gradient(135deg, #ff9800 0%, #f57c00 100%)';
|
|
} else {
|
|
badgeText = `⏱️ Essai: ${daysRemaining} jours`;
|
|
}
|
|
}
|
|
|
|
badge.textContent = badgeText;
|
|
badge.onclick = function() {
|
|
alert('Licence: ' + license.substring(0, 50) + '...\n\nClique sur le logo pour gérer ta licence.');
|
|
};
|
|
|
|
container.appendChild(badge);
|
|
|
|
// Ajouter un hover effect
|
|
badge.addEventListener('mouseenter', function() {
|
|
this.style.transform = 'translateY(-3px)';
|
|
this.style.boxShadow = '0 6px 25px rgba(102, 126, 234, 0.5)';
|
|
});
|
|
|
|
badge.addEventListener('mouseleave', function() {
|
|
this.style.transform = 'translateY(0)';
|
|
this.style.boxShadow = '0 4px 15px rgba(102, 126, 234, 0.3)';
|
|
});
|
|
}
|
|
|
|
function getTrialDaysRemaining(trialLicense) {
|
|
// Extraire le timestamp du license (format: TRIAL-timestamp)
|
|
const parts = trialLicense.split('-');
|
|
if (parts.length !== 2) return 0;
|
|
|
|
const timestamp = parseInt(parts[1]);
|
|
if (isNaN(timestamp)) return 0;
|
|
|
|
// Créer la date de création
|
|
const createdDate = new Date(timestamp);
|
|
|
|
// Ajouter 7 jours
|
|
const expirationDate = new Date(createdDate.getTime() + (7 * 24 * 60 * 60 * 1000));
|
|
|
|
// Calculer les jours restants
|
|
const now = new Date();
|
|
const daysRemaining = Math.ceil((expirationDate - now) / (1000 * 60 * 60 * 24));
|
|
|
|
console.log("Trial created:", createdDate);
|
|
console.log("Trial expires:", expirationDate);
|
|
console.log("Days remaining:", daysRemaining);
|
|
|
|
return Math.max(0, daysRemaining);
|
|
}
|
|
|
|
function showLicenseModal() {
|
|
console.log("Showing license modal");
|
|
|
|
// Créer le modal HTML
|
|
const modal = document.createElement('div');
|
|
modal.id = 'license-modal';
|
|
modal.style.cssText = `
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0, 0, 0, 0.7);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
z-index: 10000;
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
`;
|
|
|
|
const content = document.createElement('div');
|
|
content.style.cssText = `
|
|
background: white;
|
|
border-radius: 16px;
|
|
padding: 40px;
|
|
max-width: 500px;
|
|
width: 90%;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
`;
|
|
|
|
content.innerHTML = `
|
|
<div style="text-align: center; margin-bottom: 30px;">
|
|
<h1 style="font-size: 32px; margin: 0 0 10px 0; color: #333;">🔐 Git Pusher</h1>
|
|
<p style="color: #666; margin: 0; font-size: 14px;">Activation de licence requise</p>
|
|
</div>
|
|
|
|
<div style="background: #f5f7ff; padding: 15px; border-radius: 8px; margin-bottom: 25px; border-left: 4px solid #667eea;">
|
|
<p style="margin: 0; color: #667eea; font-weight: 500; font-size: 13px;">
|
|
📋 <strong>Hostname détecté:</strong> <span id="detected-hostname">Chargement...</span>
|
|
</p>
|
|
</div>
|
|
|
|
<div style="margin-bottom: 20px;">
|
|
<label style="display: block; font-weight: 600; color: #333; margin-bottom: 8px;">
|
|
Entrez votre clé de licence
|
|
</label>
|
|
<textarea id="license-input" placeholder="Collez votre clé de licence ici..." style="
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 8px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 12px;
|
|
resize: vertical;
|
|
min-height: 100px;
|
|
box-sizing: border-box;
|
|
"></textarea>
|
|
<small style="color: #999; display: block; margin-top: 8px;">
|
|
Vous n'avez pas de licence? <a href="#" onclick="showGeneratorInfo(); return false;" style="color: #667eea; text-decoration: none;">Cliquez ici</a>
|
|
</small>
|
|
</div>
|
|
|
|
<div id="license-message" style="display: none; padding: 12px; border-radius: 8px; margin-bottom: 20px; font-size: 14px;"></div>
|
|
|
|
<div style="display: flex; gap: 10px;">
|
|
<button onclick="validateLicenseInput()" style="
|
|
flex: 1;
|
|
padding: 12px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
transition: all 0.3s ease;
|
|
">Activer la licence</button>
|
|
<button onclick="skipLicense()" style="
|
|
flex: 1;
|
|
padding: 12px;
|
|
background: #f5f7ff;
|
|
color: #667eea;
|
|
border: 2px solid #667eea;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
transition: all 0.3s ease;
|
|
">Essai gratuit (7 jours)</button>
|
|
</div>
|
|
`;
|
|
|
|
modal.appendChild(content);
|
|
document.body.appendChild(modal);
|
|
|
|
// Afficher le hostname
|
|
getHostname().then(hostname => {
|
|
document.getElementById('detected-hostname').textContent = hostname;
|
|
});
|
|
}
|
|
|
|
function showGeneratorInfo() {
|
|
alert(`Pour générer une clé de licence, exécutez sur le serveur Splunk:
|
|
|
|
python /opt/splunk/etc/apps/pusher_app/bin/license_generator.py
|
|
|
|
Cela générera une clé basée sur votre hostname.`);
|
|
}
|
|
|
|
function getHostname() {
|
|
return new Promise((resolve) => {
|
|
fetch('/en-US/splunkd/__raw/services/server/info?output_mode=json')
|
|
.then(r => r.json())
|
|
.then(d => {
|
|
const hostname = d.entry?.[0]?.content?.host || 'unknown';
|
|
resolve(hostname);
|
|
})
|
|
.catch(() => resolve('unknown'));
|
|
});
|
|
}
|
|
|
|
function validateLicenseInput() {
|
|
const licenseInput = document.getElementById('license-input').value.trim();
|
|
|
|
if (!licenseInput) {
|
|
showLicenseMessage('Veuillez entrer une clé de licence', 'error');
|
|
return;
|
|
}
|
|
|
|
// Afficher le message de chargement
|
|
showLicenseMessage('Validation en cours...', 'info');
|
|
|
|
// Simuler la validation (en production, faire un appel à un serveur)
|
|
// Pour l'instant, on accepte juste n'importe quelle licence
|
|
if (licenseInput.length > 20) {
|
|
// Stocker la licence
|
|
setCookie(LICENSE_STORAGE_KEY, licenseInput, 365);
|
|
|
|
showLicenseMessage('✓ Licence activée avec succès!', 'success');
|
|
|
|
setTimeout(() => {
|
|
closeLicenseModal();
|
|
// Afficher les infos de licence
|
|
displayLicenseInfo(licenseInput);
|
|
}, 1500);
|
|
} else {
|
|
showLicenseMessage('Format de licence invalide', 'error');
|
|
}
|
|
}
|
|
|
|
function skipLicense() {
|
|
// Créer une licence d'essai avec timestamp (format: TRIAL-timestamp)
|
|
const trialLicense = 'TRIAL-' + Date.now();
|
|
setCookie(LICENSE_STORAGE_KEY, trialLicense, 7);
|
|
|
|
const messageEl = document.getElementById('license-message');
|
|
messageEl.style.display = 'block';
|
|
messageEl.style.background = '#fff3cd';
|
|
messageEl.style.color = '#856404';
|
|
messageEl.style.border = '1px solid #ffeaa7';
|
|
messageEl.textContent = '⏱️ Mode essai activé pour 7 jours';
|
|
|
|
setTimeout(() => {
|
|
closeLicenseModal();
|
|
// Afficher les infos de licence
|
|
displayLicenseInfo(trialLicense);
|
|
}, 1500);
|
|
}
|
|
|
|
function showLicenseMessage(message, type) {
|
|
const messageEl = document.getElementById('license-message');
|
|
messageEl.style.display = 'block';
|
|
messageEl.textContent = message;
|
|
|
|
if (type === 'success') {
|
|
messageEl.style.background = '#d4edda';
|
|
messageEl.style.color = '#155724';
|
|
messageEl.style.border = '1px solid #c3e6cb';
|
|
} else if (type === 'error') {
|
|
messageEl.style.background = '#f8d7da';
|
|
messageEl.style.color = '#721c24';
|
|
messageEl.style.border = '1px solid #f5c6cb';
|
|
} else if (type === 'info') {
|
|
messageEl.style.background = '#d1ecf1';
|
|
messageEl.style.color = '#0c5460';
|
|
messageEl.style.border = '1px solid #bee5eb';
|
|
}
|
|
}
|
|
|
|
function validateStoredLicense(license) {
|
|
console.log("Validating stored license...");
|
|
|
|
// Pour l'instant, accepter simplement la licence stockée
|
|
// En production, faire une validation serveur
|
|
if (license && license.length > 5) {
|
|
console.log("License is valid");
|
|
return true;
|
|
}
|
|
|
|
// Si invalide, afficher le modal à nouveau
|
|
showLicenseModal();
|
|
return false;
|
|
}
|
|
|
|
function closeLicenseModal() {
|
|
const modal = document.getElementById('license-modal');
|
|
if (modal) {
|
|
modal.remove();
|
|
}
|
|
}
|
|
|
|
function checkLicenseBeforePush() {
|
|
const license = getCookie(LICENSE_STORAGE_KEY);
|
|
|
|
if (!license) {
|
|
alert('Veuillez d\'abord activer une licence');
|
|
showLicenseModal();
|
|
return false;
|
|
}
|
|
|
|
// Vérifier si c'est une licence d'essai expirée
|
|
if (license.startsWith('TRIAL-')) {
|
|
// À implémenter : vérifier la date
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// ============================================
|
|
// FONCTIONS UTILITAIRES DE COOKIE
|
|
// ============================================
|
|
|
|
function setCookie(name, value, days) {
|
|
const d = new Date();
|
|
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
const expires = "expires=" + d.toUTCString();
|
|
document.cookie = name + "=" + encodeURIComponent(value) + ";" + expires + ";path=/";
|
|
console.log("Cookie set: " + name);
|
|
}
|
|
|
|
function getCookie(name) {
|
|
const nameEQ = name + "=";
|
|
const ca = document.cookie.split(';');
|
|
for (let i = 0; i < ca.length; i++) {
|
|
let c = ca[i].trim();
|
|
if (c.indexOf(nameEQ) === 0) {
|
|
return decodeURIComponent(c.substring(nameEQ.length));
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function deleteCookie(name) {
|
|
setCookie(name, "", -1);
|
|
console.log("Cookie deleted: " + name);
|
|
} |