|
|
|
|
|
// Git Pusher License Module v2.1
|
|
|
// (c) 2026 - Proprietary Software
|
|
|
|
|
|
function _d(a,k){return a.map(function(c){return String.fromCharCode(c^k)}).join('')}
|
|
|
|
|
|
var _uvQJmWQj='9AFwcZcRbBeXaJqKQLeqZcWcSEyEkGhu';
|
|
|
var _rIioLjQm='tiWiFVaEItxAFuYv1tgMjnQ84wQKrKs3';
|
|
|
var _jCFopnuP='0kIsCpE5TFRM4gQxNtJOe1ZAKklHltin';
|
|
|
var _RPzUZFtx='U6pxCxKo055c5gnUwZpoI9GVyFme2Q2J';
|
|
|
var _jqqIIADg='cayEoU4uUplCxipTjpvqwFvkxnPcOmsB';
|
|
|
var _VqTudlrn='hNEfSUIXujr6nEyyJqw6bKYNfhrrop3r';
|
|
|
var _UpWCTgAQ='ApCX9Dnof3CkyN6RZJBBXokYM1yC3Pkk';
|
|
|
var _XvSLaAUB='jAkILnmpmYfxNfNEUNezcnfsRinRXWZJ';
|
|
|
var _MlAcKWHL='NeRhzYoqcPgqj1kAPCKgwQLUPdsThKEF';
|
|
|
var _NuAcwBOZ='lef3hcLBzEUVO1gCTy53Rl7KyFZclckn';
|
|
|
|
|
|
function _KBqzPUPr(a,b){
|
|
|
var c=a^b;var d=c.toString(16);
|
|
|
return d.split('').reverse().join('');
|
|
|
}
|
|
|
|
|
|
|
|
|
function _exdqMhKG(a,b){
|
|
|
var c=a^b;var d=c.toString(16);
|
|
|
return d.split('').reverse().join('');
|
|
|
}
|
|
|
|
|
|
|
|
|
function _grhEQBqb(a,b){
|
|
|
var c=a^b;var d=c.toString(16);
|
|
|
return d.split('').reverse().join('');
|
|
|
}
|
|
|
|
|
|
|
|
|
function _fzlnBGMH(a,b){
|
|
|
var c=a^b;var d=c.toString(16);
|
|
|
return d.split('').reverse().join('');
|
|
|
}
|
|
|
|
|
|
|
|
|
function _MBYSySgW(a,b){
|
|
|
var c=a^b;var d=c.toString(16);
|
|
|
return d.split('').reverse().join('');
|
|
|
}
|
|
|
|
|
|
var _rVbYrxGd=_d([136,136,136,136,136,231,224,226,236,235,133,245,240,231,233,236,230,133,238,224,252,136,136,136,136,136,175],165);
|
|
|
var _VDYYzLxu=_d([215,211,211,217,211,240,219,212,216,253,241,235,242,241,243,221,163,237,170,216,219,203,223,220,219,219,213,217,219,253,162,219,215,211,211,217,217,253,209,217,219,253,223,219,173,210,162,236,168,174,169,202,209,234,227,174,192,249,221,207,211],154);
|
|
|
var _MVLYDniA=_d([212,190,191,162,142,166,189,134,172,204,177,144,176,180,163,158,144,164,144,165,168,170,168,173,165,166,210,148,139,176,136,149,183,208,223,132,170,162,215,133,174,151,143,149,169,181,145,179,139,166,222,159,151,146,136,215,134,204,223,177,204],231);
|
|
|
var _UAySmvNT=_d([168,184,179,156,205,213,171,137,199,191,150,186,138,139,180,181,172,183,187,153,137,180,151,134,147,209,147,149,181,157,156,148,137,143,173,182,174,147,144,135,188,188,182,174,188,188,166,201,146,177,209,143,204,137,141,187,166,206,135,205,177],254);
|
|
|
var _lvnLtxEJ=_d([181,212,239,240,216,227,235,249,169,254,204,233,216,170,204,204,242,215,220,208,247,253,227,200,169,254,204,227,172,192,203,211,206,253,223,239,181,212,221,233,163,236,181,240,207,249,175,211,206,171,195,224,204,247,213,217,249,214,162,216,192],154);
|
|
|
var _zcAMxLBG=_d([80,72,78,101,75,100,18,99,122,71,113,17,13,119,26,73,74,83,21,85,103,90,23,109,75,78,74,122,97,21,75,26,85,20,87,80,70,27,65,22,102,72,72,69,23,26,17,117,81,101,86,102,105,73,18,67,120,20,90,84,76],34);
|
|
|
var _dGFpAAtk=_d([55,8,33,60,54,55,5,43,48,23,24,35,4,58,2,48,55,5,41,51,50,11,96,57,97,31,98,61,31,104,28,19,39,48,29,51,54,16,36,56,100,3,54,53,61,51,27,61,51,22,34,54,61,98,36,16,48,104,3,104,41],81);
|
|
|
var _cerkuvwZ=_d([196,245,181,236,239,202,246,166,200,220,210,200,239,181,213,201,171,215,255,168,255,199,209,200,234,251,236,203,248,172,246,228,177,246,203,245,208,244,211,166,204,241,242,232,170,177,173,206,207,198,174,243,217,235,168,248,255,170,248,233,241],158);
|
|
|
var _qLGpjZls=_d([145,132,131,133,186,188,172,191,145,191,175,129,222,189,141,170,172,198,190,161,131,218,130,168,166,144,139,179,177,190,163,135,158,154,198,194,194,156,155,152,128,131,185,220,186,132,176,145,144,170,136,191,133,176,168,134,156,157,141,190,132],233);
|
|
|
var _WGewijsJ=_d([135,204,137,169,143,174,165,178,149,202,201,140,143,146,136,207,138,139,206,190,197,185,144,146,197,158,158,171,135,147,188,149,153,149,181,158,171,142,202,176,174,145,196,172,159,132,138,204,155,142,148,204,204,204,202,170,148,154,168,186,150],253);
|
|
|
var _gcFTsAUK=_d([71,82,34,84,111,125,123,101,123,47,82,116,85,70,112,36,80,34,111,46,38,82,69,46,34,93,90,88,39,68,125,110,127,83,117,120,101,67,60,120,90,102,46,46,35,32,77,91,36,34,65,123,123,109,124,92,117,85,82,91,117],23);
|
|
|
var _rfVsSsnX=_d([13,33,11,10,2,61,8,33,40,23,44,86,44,15,84,48,39,8,38,17,54,42,63,31,42,41,13,28,45,33,35,8,34,3,80,36,39,84,41,50,7,29,6,2,23,31,42,40,6,49,41,10,36,45,1,16,4,33,4,9,63],101);
|
|
|
var _VlChvXbg=_d([44,21,2,56,91,56,11,57,91,92,94,92,44,30,10,14,24,42,9,30,37,57,5,87,45,37,68,95,57,42,41,11,13,61,43,4,91,53,21,39,31,32,14,40,46,26,44,37,5,33,92,46,26,23,32,87,44,46,24,42,46,46,62,82,82],111);
|
|
|
var _CkJWebLK=_d([156,187,187,187,187,187,211,216,210,182,198,195,212,218,223,213,182,221,211,207,187,187,187,187,187],150);
|
|
|
var _EnyGSGDD=_rVbYrxGd+_VDYYzLxu+_MVLYDniA+_UAySmvNT+_lvnLtxEJ+_zcAMxLBG+_dGFpAAtk+_cerkuvwZ+_qLGpjZls+_WGewijsJ+_gcFTsAUK+_rfVsSsnX+_VlChvXbg+_CkJWebLK;
|
|
|
var PUBLIC_KEY_PEM=_EnyGSGDD;
|
|
|
|
|
|
const DEFAULT_APP_CONFIG = {
|
|
|
api: {
|
|
|
url: '',
|
|
|
port: 9999,
|
|
|
useProxy: true
|
|
|
}
|
|
|
};
|
|
|
function loadAppConfigForLicense() {
|
|
|
try {
|
|
|
const stored = localStorage.getItem('git_pusher_config');
|
|
|
if (stored) {
|
|
|
return JSON.parse(stored);
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.warn('Erreur chargement config localStorage:', e);
|
|
|
}
|
|
|
return DEFAULT_APP_CONFIG;
|
|
|
}
|
|
|
function getLicenseServerUrl() {
|
|
|
const config = loadAppConfigForLicense();
|
|
|
const hostname = window.location.hostname;
|
|
|
const protocol = window.location.protocol;
|
|
|
if (config.api && config.api.url) {
|
|
|
let url = config.api.url;
|
|
|
if (!config.api.useProxy && config.api.port) {
|
|
|
url = url.replace(/\/$/, '') + ':' + config.api.port;
|
|
|
}
|
|
|
return url;
|
|
|
}
|
|
|
if (/^(\d{1,3}\.){3}\d{1,3}$/.test(hostname) || hostname === 'localhost') {
|
|
|
return protocol + '//' + hostname + ':9999';
|
|
|
}
|
|
|
const parts = hostname.split('.');
|
|
|
if (parts.length >= 2) {
|
|
|
parts[0] = parts[0] + '-api';
|
|
|
return protocol + '//' + parts.join('.');
|
|
|
}
|
|
|
return protocol + '//' + hostname + ':9999';
|
|
|
}
|
|
|
const LICENSE_CONFIG = {
|
|
|
storageKey: 'git_pusher_license',
|
|
|
usageKey: 'git_pusher_usage',
|
|
|
version: '2.1.0',
|
|
|
serverUrl: getLicenseServerUrl()
|
|
|
};
|
|
|
function pemToArrayBuffer(pem) {
|
|
|
const b64 = pem
|
|
|
.replace(/-----BEGIN PUBLIC KEY-----/, '')
|
|
|
.replace(/-----END PUBLIC KEY-----/, '')
|
|
|
.replace(/\s/g, '');
|
|
|
const binary = atob(b64);
|
|
|
const bytes = new Uint8Array(binary.length);
|
|
|
for (let i = 0; i < binary.length; i++) {
|
|
|
bytes[i] = binary.charCodeAt(i);
|
|
|
}
|
|
|
return bytes.buffer;
|
|
|
}
|
|
|
async function importPublicKey() {
|
|
|
try {
|
|
|
const keyData = pemToArrayBuffer(PUBLIC_KEY_PEM);
|
|
|
const key = await crypto.subtle.importKey(
|
|
|
'spki',
|
|
|
keyData,
|
|
|
{
|
|
|
name: 'RSASSA-PKCS1-v1_5',
|
|
|
hash: 'SHA-256'
|
|
|
},
|
|
|
false,
|
|
|
['verify']
|
|
|
);
|
|
|
return key;
|
|
|
} catch (error) {
|
|
|
console.error('Erreur import clé publique:', error);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
async function verifySignature(data, signatureB64, publicKey) {
|
|
|
try {
|
|
|
const signature = Uint8Array.from(atob(signatureB64), c => c.charCodeAt(0));
|
|
|
const dataBuffer = new TextEncoder().encode(data);
|
|
|
const isValid = await crypto.subtle.verify(
|
|
|
'RSASSA-PKCS1-v1_5',
|
|
|
publicKey,
|
|
|
signature,
|
|
|
dataBuffer
|
|
|
);
|
|
|
return isValid;
|
|
|
} catch (error) {
|
|
|
console.error('Erreur vérification signature:', error);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
function base64Decode(str) {
|
|
|
try {
|
|
|
return decodeURIComponent(atob(str).split('').map(function(c) {
|
|
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
|
}).join(''));
|
|
|
} catch (e) {
|
|
|
return atob(str);
|
|
|
}
|
|
|
}
|
|
|
function getCurrentHostname() {
|
|
|
return window.location.hostname.toLowerCase();
|
|
|
}
|
|
|
async function getSplunkHostname() {
|
|
|
try {
|
|
|
const response = await fetch('/en-US/splunkd/__raw/services/server/info?output_mode=json', {
|
|
|
credentials: 'include'
|
|
|
});
|
|
|
if (response.ok) {
|
|
|
const data = await response.json();
|
|
|
const serverName = data.entry?.[0]?.content?.serverName;
|
|
|
if (serverName) {
|
|
|
console.log('Hostname Splunk (server/info):', serverName);
|
|
|
return serverName.toLowerCase();
|
|
|
}
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.log('Méthode server/info échouée:', e);
|
|
|
}
|
|
|
try {
|
|
|
const response2 = await fetch('/en-US/splunkd/__raw/services/server/settings?output_mode=json', {
|
|
|
credentials: 'include'
|
|
|
});
|
|
|
if (response2.ok) {
|
|
|
const data2 = await response2.json();
|
|
|
const serverName = data2.entry?.[0]?.content?.serverName;
|
|
|
if (serverName) {
|
|
|
console.log('Hostname Splunk (server/settings):', serverName);
|
|
|
return serverName.toLowerCase();
|
|
|
}
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.log('Méthode server/settings échouée:', e);
|
|
|
}
|
|
|
console.warn('Impossible de récupérer le hostname Splunk, utilisation URL:', getCurrentHostname());
|
|
|
return getCurrentHostname();
|
|
|
}
|
|
|
function daysRemaining(expiryDate) {
|
|
|
const expiry = new Date(expiryDate);
|
|
|
const now = new Date();
|
|
|
const diff = expiry - now;
|
|
|
return Math.ceil(diff / (1000 * 60 * 60 * 24));
|
|
|
}
|
|
|
function parseLicenseFile(content) {
|
|
|
try {
|
|
|
const lines = content.trim().split('\n');
|
|
|
let payloadB64 = null;
|
|
|
for (const line of lines) {
|
|
|
const trimmed = line.trim();
|
|
|
if (trimmed && !trimmed.startsWith('#')) {
|
|
|
payloadB64 = trimmed;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!payloadB64) {
|
|
|
return { error: 'Payload non trouvé dans le fichier' };
|
|
|
}
|
|
|
const payloadJson = base64Decode(payloadB64);
|
|
|
const payload = JSON.parse(payloadJson);
|
|
|
if (!payload.license || !payload.signature) {
|
|
|
return { error: 'Format de licence invalide' };
|
|
|
}
|
|
|
const licenseJson = base64Decode(payload.license);
|
|
|
const licenseData = JSON.parse(licenseJson);
|
|
|
return {
|
|
|
success: true,
|
|
|
licenseJson: licenseJson,
|
|
|
licenseData: licenseData,
|
|
|
signatureB64: payload.signature,
|
|
|
rawPayload: payloadB64
|
|
|
};
|
|
|
} catch (error) {
|
|
|
console.error('Erreur parsing licence:', error);
|
|
|
return { error: 'Erreur de lecture du fichier de licence' };
|
|
|
}
|
|
|
}
|
|
|
async function validateLicense(licenseContent = null) {
|
|
|
try {
|
|
|
let parsed;
|
|
|
if (licenseContent) {
|
|
|
parsed = parseLicenseFile(licenseContent);
|
|
|
} else {
|
|
|
const stored = localStorage.getItem(LICENSE_CONFIG.storageKey);
|
|
|
if (!stored) {
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: 'Aucune licence installée',
|
|
|
error_code: 'NO_LICENSE'
|
|
|
};
|
|
|
}
|
|
|
parsed = JSON.parse(stored);
|
|
|
}
|
|
|
if (parsed.error) {
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: parsed.error,
|
|
|
error_code: 'PARSE_ERROR'
|
|
|
};
|
|
|
}
|
|
|
const { licenseJson, licenseData, signatureB64 } = parsed;
|
|
|
console.log('=== DEBUG VALIDATION LICENCE ===');
|
|
|
console.log('License JSON:', licenseJson);
|
|
|
console.log('License JSON length:', licenseJson.length);
|
|
|
console.log('Signature B64:', signatureB64.substring(0, 50) + '...');
|
|
|
console.log('Signature B64 length:', signatureB64.length);
|
|
|
console.log('Vérification de la signature RSA...');
|
|
|
const publicKey = await importPublicKey();
|
|
|
if (!publicKey) {
|
|
|
console.error('Échec import clé publique');
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: 'Impossible de charger la clé publique',
|
|
|
error_code: 'KEY_ERROR'
|
|
|
};
|
|
|
}
|
|
|
console.log('Clé publique importée avec succès');
|
|
|
const signatureValid = await verifySignature(licenseJson, signatureB64, publicKey);
|
|
|
console.log('Résultat vérification signature:', signatureValid);
|
|
|
if (!signatureValid) {
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: 'Signature de licence invalide',
|
|
|
error_code: 'INVALID_SIGNATURE'
|
|
|
};
|
|
|
}
|
|
|
console.log('✓ Signature RSA valide');
|
|
|
const expectedHostname = (licenseData.hostname || '').toLowerCase();
|
|
|
const currentHostname = await getSplunkHostname();
|
|
|
console.log(`Hostname attendu: "${expectedHostname}", actuel: "${currentHostname}"`);
|
|
|
if (expectedHostname && expectedHostname !== currentHostname) {
|
|
|
if (!currentHostname.includes(expectedHostname) && !expectedHostname.includes(currentHostname)) {
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: `Licence non valide pour ce serveur. Attendu: ${expectedHostname}, Actuel: ${currentHostname}`,
|
|
|
error_code: 'HOSTNAME_MISMATCH',
|
|
|
expected_hostname: expectedHostname,
|
|
|
current_hostname: currentHostname
|
|
|
};
|
|
|
}
|
|
|
console.log('✓ Hostname valide (correspondance partielle)');
|
|
|
} else {
|
|
|
console.log('✓ Hostname valide (exact)');
|
|
|
}
|
|
|
const expiryDate = licenseData.expires;
|
|
|
if (expiryDate) {
|
|
|
const days = daysRemaining(expiryDate);
|
|
|
if (days < 0) {
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: `Licence expirée le ${expiryDate}`,
|
|
|
error_code: 'LICENSE_EXPIRED',
|
|
|
expires: expiryDate
|
|
|
};
|
|
|
}
|
|
|
console.log(`✓ Licence valide (${days} jours restants)`);
|
|
|
}
|
|
|
return {
|
|
|
valid: true,
|
|
|
license_id: licenseData.license_id,
|
|
|
type: licenseData.type,
|
|
|
type_name: licenseData.type_name,
|
|
|
customer: licenseData.customer,
|
|
|
hostname: expectedHostname,
|
|
|
issued: licenseData.issued,
|
|
|
expires: expiryDate,
|
|
|
days_remaining: daysRemaining(expiryDate),
|
|
|
limits: licenseData.limits || {},
|
|
|
features: licenseData.features || []
|
|
|
};
|
|
|
} catch (error) {
|
|
|
console.error('Erreur validation licence:', error);
|
|
|
return {
|
|
|
valid: false,
|
|
|
error: error.message,
|
|
|
error_code: 'VALIDATION_ERROR'
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
async function hasFeature(featureName) {
|
|
|
const validation = await validateLicense();
|
|
|
if (!validation.valid) return false;
|
|
|
return validation.features.includes(featureName);
|
|
|
}
|
|
|
async function saveLicense(licenseContent) {
|
|
|
try {
|
|
|
const parsed = parseLicenseFile(licenseContent);
|
|
|
if (parsed.error) {
|
|
|
return {
|
|
|
success: false,
|
|
|
error: parsed.error
|
|
|
};
|
|
|
}
|
|
|
const validation = await validateLicense(licenseContent);
|
|
|
if (!validation.valid) {
|
|
|
return {
|
|
|
success: false,
|
|
|
error: validation.error,
|
|
|
error_code: validation.error_code
|
|
|
};
|
|
|
}
|
|
|
localStorage.setItem(LICENSE_CONFIG.storageKey, JSON.stringify(parsed));
|
|
|
console.log('✓ Licence sauvegardée dans localStorage');
|
|
|
try {
|
|
|
const response = await fetch(`${LICENSE_CONFIG.serverUrl}/license/save`, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json'
|
|
|
},
|
|
|
body: JSON.stringify({
|
|
|
license_content: licenseContent
|
|
|
})
|
|
|
});
|
|
|
const serverResult = await response.json();
|
|
|
if (serverResult.success) {
|
|
|
console.log('✓ Licence sauvegardée sur le serveur');
|
|
|
} else {
|
|
|
console.warn('⚠ Échec sauvegarde serveur:', serverResult.error);
|
|
|
}
|
|
|
} catch (serverError) {
|
|
|
console.warn('⚠ Impossible de sauvegarder sur le serveur:', serverError);
|
|
|
}
|
|
|
return {
|
|
|
success: true,
|
|
|
license: validation
|
|
|
};
|
|
|
} catch (error) {
|
|
|
console.error('Erreur sauvegarde licence:', error);
|
|
|
return {
|
|
|
success: false,
|
|
|
error: error.message
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
async function loadLicenseFromServer() {
|
|
|
try {
|
|
|
const response = await fetch(`${LICENSE_CONFIG.serverUrl}/license/file`, {
|
|
|
method: 'GET',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json'
|
|
|
}
|
|
|
});
|
|
|
const result = await response.json();
|
|
|
if (result.success && result.content) {
|
|
|
console.log('Licence trouvée sur le serveur, validation en cours...');
|
|
|
const parsed = parseLicenseFile(result.content);
|
|
|
if (parsed.error) {
|
|
|
console.warn('Erreur parsing licence serveur:', parsed.error);
|
|
|
return false;
|
|
|
}
|
|
|
const validation = await validateLicense(result.content);
|
|
|
if (validation.valid) {
|
|
|
localStorage.setItem(LICENSE_CONFIG.storageKey, JSON.stringify(parsed));
|
|
|
console.log('✓ Licence chargée depuis le serveur et stockée localement');
|
|
|
return true;
|
|
|
} else {
|
|
|
console.warn('Licence serveur invalide:', validation.error);
|
|
|
return false;
|
|
|
}
|
|
|
} else {
|
|
|
console.log('Aucune licence sur le serveur');
|
|
|
return false;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log('Impossible de charger la licence depuis le serveur:', error.message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
async function removeLicense() {
|
|
|
localStorage.removeItem(LICENSE_CONFIG.storageKey);
|
|
|
localStorage.removeItem(LICENSE_CONFIG.usageKey);
|
|
|
try {
|
|
|
await fetch(`${LICENSE_CONFIG.serverUrl}/license/delete`, {
|
|
|
method: 'POST'
|
|
|
});
|
|
|
console.log('Licence supprimée du serveur');
|
|
|
} catch (e) {
|
|
|
console.warn('Impossible de supprimer la licence du serveur:', e);
|
|
|
}
|
|
|
console.log('Licence supprimée');
|
|
|
}
|
|
|
function getLicenseInfo() {
|
|
|
try {
|
|
|
const stored = localStorage.getItem(LICENSE_CONFIG.storageKey);
|
|
|
if (!stored) return null;
|
|
|
const parsed = JSON.parse(stored);
|
|
|
return parsed.licenseData;
|
|
|
} catch {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
function getUsageStats() {
|
|
|
try {
|
|
|
const stored = localStorage.getItem(LICENSE_CONFIG.usageKey);
|
|
|
if (stored) {
|
|
|
return JSON.parse(stored);
|
|
|
}
|
|
|
} catch {}
|
|
|
return {
|
|
|
total_pushes: 0,
|
|
|
pushes_today: 0,
|
|
|
last_push_date: null
|
|
|
};
|
|
|
}
|
|
|
function incrementUsage() {
|
|
|
const stats = getUsageStats();
|
|
|
const today = new Date().toISOString().split('T')[0];
|
|
|
if (stats.last_push_date !== today) {
|
|
|
stats.pushes_today = 0;
|
|
|
stats.last_push_date = today;
|
|
|
}
|
|
|
stats.total_pushes = (stats.total_pushes || 0) + 1;
|
|
|
stats.pushes_today = (stats.pushes_today || 0) + 1;
|
|
|
localStorage.setItem(LICENSE_CONFIG.usageKey, JSON.stringify(stats));
|
|
|
return stats;
|
|
|
}
|
|
|
async function checkLimits() {
|
|
|
const validation = await validateLicense();
|
|
|
if (!validation.valid) {
|
|
|
return {
|
|
|
allowed: false,
|
|
|
error: validation.error,
|
|
|
error_code: validation.error_code
|
|
|
};
|
|
|
}
|
|
|
const limits = validation.limits || {};
|
|
|
const maxPushes = limits.max_pushes_per_day || -1;
|
|
|
if (maxPushes > 0) {
|
|
|
const stats = getUsageStats();
|
|
|
const today = new Date().toISOString().split('T')[0];
|
|
|
let pushesToday = stats.pushes_today || 0;
|
|
|
if (stats.last_push_date !== today) {
|
|
|
pushesToday = 0;
|
|
|
}
|
|
|
if (pushesToday >= maxPushes) {
|
|
|
return {
|
|
|
allowed: false,
|
|
|
error: `Limite quotidienne atteinte (${maxPushes} pushes/jour)`,
|
|
|
error_code: 'DAILY_LIMIT_REACHED'
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
allowed: true,
|
|
|
license_type: validation.type_name,
|
|
|
remaining_today: maxPushes > 0 ? maxPushes - getUsageStats().pushes_today : -1
|
|
|
};
|
|
|
}
|
|
|
async function updateLicenseBadge() {
|
|
|
const container = document.getElementById('license-badge-container');
|
|
|
if (!container) return;
|
|
|
const validation = await validateLicense();
|
|
|
let badgeHtml = '';
|
|
|
if (validation.valid) {
|
|
|
const daysLeft = validation.days_remaining;
|
|
|
let badgeClass = 'license-badge-valid';
|
|
|
let icon = '✓';
|
|
|
if (daysLeft <= 7) {
|
|
|
badgeClass = 'license-badge-expiring';
|
|
|
icon = '⚠️';
|
|
|
} else if (daysLeft <= 30) {
|
|
|
badgeClass = 'license-badge-warning';
|
|
|
icon = '⏳';
|
|
|
}
|
|
|
badgeHtml = `
|
|
|
<div class="license-badge ${badgeClass}" onclick="showLicenseDetails()">
|
|
|
<span class="license-icon">${icon}</span>
|
|
|
<span class="license-type">${validation.type_name}</span>
|
|
|
<span class="license-days">${daysLeft}j</span>
|
|
|
</div>
|
|
|
`;
|
|
|
} else {
|
|
|
badgeHtml = `
|
|
|
<div class="license-badge license-badge-invalid" onclick="showLicenseModal()">
|
|
|
<span class="license-icon">🔐</span>
|
|
|
<span class="license-type">Activer</span>
|
|
|
</div>
|
|
|
`;
|
|
|
}
|
|
|
container.innerHTML = badgeHtml;
|
|
|
}
|
|
|
function showLicenseModal(message = null, errorCode = null) {
|
|
|
const existingModal = document.getElementById('license-modal');
|
|
|
if (existingModal) existingModal.remove();
|
|
|
const modal = document.createElement('div');
|
|
|
modal.id = 'license-modal';
|
|
|
modal.className = 'license-modal-overlay';
|
|
|
let errorMessage = '';
|
|
|
if (message) {
|
|
|
errorMessage = `<div class="license-error-message">${message}</div>`;
|
|
|
}
|
|
|
modal.innerHTML = `
|
|
|
<div class="license-modal">
|
|
|
<div class="license-modal-header">
|
|
|
<h2>🔐 Activation de Licence</h2>
|
|
|
<button class="license-modal-close" onclick="closeLicenseModal()">×</button>
|
|
|
</div>
|
|
|
<div class="license-modal-body">
|
|
|
${errorMessage}
|
|
|
<div class="license-upload-zone" id="license-upload-zone">
|
|
|
<div class="license-upload-icon">📄</div>
|
|
|
<div class="license-upload-text">
|
|
|
Glissez-déposez votre fichier <strong>.lic</strong> ici
|
|
|
<br><small>ou cliquez pour sélectionner</small>
|
|
|
</div>
|
|
|
<input type="file" id="license-file-input" accept=".lic" style="display: none;">
|
|
|
</div>
|
|
|
<div class="license-hostname-info">
|
|
|
<strong>Hostname du serveur:</strong>
|
|
|
<code id="current-hostname-display">Chargement...</code>
|
|
|
<br><small>Communiquez ce hostname pour obtenir votre licence</small>
|
|
|
</div>
|
|
|
<div id="license-validation-result"></div>
|
|
|
</div>
|
|
|
<div class="license-modal-footer">
|
|
|
<button class="btn btn-secondary" onclick="closeLicenseModal()">Fermer</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
`;
|
|
|
document.body.appendChild(modal);
|
|
|
getSplunkHostname().then(hostname => {
|
|
|
const hostnameDisplay = document.getElementById('current-hostname-display');
|
|
|
if (hostnameDisplay) {
|
|
|
hostnameDisplay.textContent = hostname;
|
|
|
}
|
|
|
});
|
|
|
setupLicenseUpload();
|
|
|
}
|
|
|
function setupLicenseUpload() {
|
|
|
const dropZone = document.getElementById('license-upload-zone');
|
|
|
const fileInput = document.getElementById('license-file-input');
|
|
|
if (!dropZone || !fileInput) return;
|
|
|
dropZone.addEventListener('click', () => fileInput.click());
|
|
|
dropZone.addEventListener('dragover', (e) => {
|
|
|
e.preventDefault();
|
|
|
dropZone.classList.add('dragover');
|
|
|
});
|
|
|
dropZone.addEventListener('dragleave', () => {
|
|
|
dropZone.classList.remove('dragover');
|
|
|
});
|
|
|
dropZone.addEventListener('drop', (e) => {
|
|
|
e.preventDefault();
|
|
|
dropZone.classList.remove('dragover');
|
|
|
const files = e.dataTransfer.files;
|
|
|
if (files.length > 0) {
|
|
|
handleLicenseFile(files[0]);
|
|
|
}
|
|
|
});
|
|
|
fileInput.addEventListener('change', (e) => {
|
|
|
if (e.target.files.length > 0) {
|
|
|
handleLicenseFile(e.target.files[0]);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
async function handleLicenseFile(file) {
|
|
|
const resultDiv = document.getElementById('license-validation-result');
|
|
|
if (!resultDiv) return;
|
|
|
if (!file.name.endsWith('.lic')) {
|
|
|
resultDiv.innerHTML = `
|
|
|
<div class="license-result error">
|
|
|
❌ Le fichier doit avoir l'extension .lic
|
|
|
</div>
|
|
|
`;
|
|
|
return;
|
|
|
}
|
|
|
resultDiv.innerHTML = `
|
|
|
<div class="license-result loading">
|
|
|
⏳ Validation en cours...
|
|
|
</div>
|
|
|
`;
|
|
|
try {
|
|
|
const content = await file.text();
|
|
|
const result = await saveLicense(content);
|
|
|
if (result.success) {
|
|
|
const license = result.license;
|
|
|
resultDiv.innerHTML = `
|
|
|
<div class="license-result success">
|
|
|
<div class="license-success-icon">✅</div>
|
|
|
<div class="license-success-text">
|
|
|
<strong>Licence activée avec succès !</strong><br>
|
|
|
Type: ${license.type_name}<br>
|
|
|
Expire: ${license.expires} (${license.days_remaining} jours)<br>
|
|
|
Client: ${license.customer?.name || 'N/A'}
|
|
|
</div>
|
|
|
</div>
|
|
|
`;
|
|
|
updateLicenseBadge();
|
|
|
setTimeout(() => {
|
|
|
closeLicenseModal();
|
|
|
}, 3000);
|
|
|
} else {
|
|
|
resultDiv.innerHTML = `
|
|
|
<div class="license-result error">
|
|
|
❌ ${result.error}
|
|
|
</div>
|
|
|
`;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
resultDiv.innerHTML = `
|
|
|
<div class="license-result error">
|
|
|
❌ Erreur: ${error.message}
|
|
|
</div>
|
|
|
`;
|
|
|
}
|
|
|
}
|
|
|
function closeLicenseModal() {
|
|
|
const modal = document.getElementById('license-modal');
|
|
|
if (modal) modal.remove();
|
|
|
}
|
|
|
async function showLicenseDetails() {
|
|
|
const validation = await validateLicense();
|
|
|
if (!validation.valid) {
|
|
|
showLicenseModal(validation.error, validation.error_code);
|
|
|
return;
|
|
|
}
|
|
|
const existingModal = document.getElementById('license-details-modal');
|
|
|
if (existingModal) existingModal.remove();
|
|
|
const modal = document.createElement('div');
|
|
|
modal.id = 'license-details-modal';
|
|
|
modal.className = 'license-modal-overlay';
|
|
|
const features = validation.features.map(f => `<span class="feature-tag">${f}</span>`).join(' ');
|
|
|
const limits = validation.limits;
|
|
|
const maxApps = limits.max_apps === -1 ? '∞' : limits.max_apps;
|
|
|
const maxPushes = limits.max_pushes_per_day === -1 ? '∞' : limits.max_pushes_per_day;
|
|
|
const usage = getUsageStats();
|
|
|
modal.innerHTML = `
|
|
|
<div class="license-modal">
|
|
|
<div class="license-modal-header">
|
|
|
<h2>📋 Détails de la Licence</h2>
|
|
|
<button class="license-modal-close" onclick="this.closest('.license-modal-overlay').remove()">×</button>
|
|
|
</div>
|
|
|
<div class="license-modal-body">
|
|
|
<table class="license-details-table">
|
|
|
<tr><td><strong>ID</strong></td><td>${validation.license_id}</td></tr>
|
|
|
<tr><td><strong>Type</strong></td><td>${validation.type_name}</td></tr>
|
|
|
<tr><td><strong>Client</strong></td><td>${validation.customer?.name || 'N/A'}</td></tr>
|
|
|
<tr><td><strong>Email</strong></td><td>${validation.customer?.email || 'N/A'}</td></tr>
|
|
|
<tr><td><strong>Hostname</strong></td><td>${validation.hostname}</td></tr>
|
|
|
<tr><td><strong>Émise le</strong></td><td>${validation.issued}</td></tr>
|
|
|
<tr><td><strong>Expire le</strong></td><td>${validation.expires}</td></tr>
|
|
|
<tr><td><strong>Jours restants</strong></td><td>${validation.days_remaining}</td></tr>
|
|
|
<tr><td><strong>Apps max</strong></td><td>${maxApps}</td></tr>
|
|
|
<tr><td><strong>Pushes/jour</strong></td><td>${maxPushes}</td></tr>
|
|
|
</table>
|
|
|
<div style="margin-top: 15px;">
|
|
|
<strong>Fonctionnalités:</strong><br>
|
|
|
<div style="margin-top: 8px;">${features}</div>
|
|
|
</div>
|
|
|
<div style="margin-top: 15px; padding-top: 15px; border-top: 1px solid #e0e0e0;">
|
|
|
<strong>Utilisation:</strong><br>
|
|
|
<small>Total pushes: ${usage.total_pushes} | Aujourd'hui: ${usage.pushes_today}</small>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="license-modal-footer">
|
|
|
<button class="btn btn-secondary" onclick="this.closest('.license-modal-overlay').remove()">Fermer</button>
|
|
|
<button class="btn btn-danger" onclick="confirmRemoveLicense()">Supprimer la licence</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
`;
|
|
|
document.body.appendChild(modal);
|
|
|
}
|
|
|
function confirmRemoveLicense() {
|
|
|
if (confirm('Êtes-vous sûr de vouloir supprimer cette licence ?')) {
|
|
|
removeLicense();
|
|
|
const detailsModal = document.getElementById('license-details-modal');
|
|
|
if (detailsModal) detailsModal.remove();
|
|
|
updateLicenseBadge();
|
|
|
alert('Licence supprimée.');
|
|
|
}
|
|
|
}
|
|
|
async function checkLicenseBeforePush() {
|
|
|
const result = await checkLimits();
|
|
|
if (!result.allowed) {
|
|
|
showLicenseModal(result.error, result.error_code);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
const licenseStyles = `
|
|
|
<style>
|
|
|
.license-badge {
|
|
|
display: inline-flex;
|
|
|
align-items: center;
|
|
|
gap: 8px;
|
|
|
padding: 8px 16px;
|
|
|
border-radius: 20px;
|
|
|
font-size: 13px;
|
|
|
font-weight: 600;
|
|
|
cursor: pointer;
|
|
|
transition: all 0.3s ease;
|
|
|
}
|
|
|
.license-badge:hover {
|
|
|
transform: scale(1.05);
|
|
|
}
|
|
|
.license-badge-valid {
|
|
|
background: linear-gradient(135deg, #4CAF50, #45a049);
|
|
|
color: white;
|
|
|
}
|
|
|
.license-badge-warning {
|
|
|
background: linear-gradient(135deg, #FF9800, #F57C00);
|
|
|
color: white;
|
|
|
}
|
|
|
.license-badge-expiring {
|
|
|
background: linear-gradient(135deg, #f44336, #d32f2f);
|
|
|
color: white;
|
|
|
animation: pulse 2s infinite;
|
|
|
}
|
|
|
.license-badge-invalid {
|
|
|
background: linear-gradient(135deg, #9e9e9e, #757575);
|
|
|
color: white;
|
|
|
}
|
|
|
@keyframes pulse {
|
|
|
0%, 100% { opacity: 1; }
|
|
|
50% { opacity: 0.7; }
|
|
|
}
|
|
|
.license-modal-overlay {
|
|
|
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;
|
|
|
}
|
|
|
.license-modal {
|
|
|
background: white;
|
|
|
border-radius: 16px;
|
|
|
max-width: 500px;
|
|
|
width: 90%;
|
|
|
max-height: 90vh;
|
|
|
overflow-y: auto;
|
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
|
}
|
|
|
.license-modal-header {
|
|
|
display: flex;
|
|
|
justify-content: space-between;
|
|
|
align-items: center;
|
|
|
padding: 20px 25px;
|
|
|
border-bottom: 1px solid #e0e0e0;
|
|
|
}
|
|
|
.license-modal-header h2 {
|
|
|
margin: 0;
|
|
|
font-size: 20px;
|
|
|
color: #333;
|
|
|
}
|
|
|
.license-modal-close {
|
|
|
background: none;
|
|
|
border: none;
|
|
|
font-size: 28px;
|
|
|
cursor: pointer;
|
|
|
color: #999;
|
|
|
line-height: 1;
|
|
|
}
|
|
|
.license-modal-close:hover {
|
|
|
color: #333;
|
|
|
}
|
|
|
.license-modal-body {
|
|
|
padding: 25px;
|
|
|
}
|
|
|
.license-modal-footer {
|
|
|
display: flex;
|
|
|
justify-content: flex-end;
|
|
|
gap: 10px;
|
|
|
padding: 15px 25px;
|
|
|
border-top: 1px solid #e0e0e0;
|
|
|
}
|
|
|
.license-upload-zone {
|
|
|
border: 2px dashed #ccc;
|
|
|
border-radius: 12px;
|
|
|
padding: 40px 20px;
|
|
|
text-align: center;
|
|
|
cursor: pointer;
|
|
|
transition: all 0.3s ease;
|
|
|
margin-bottom: 20px;
|
|
|
}
|
|
|
.license-upload-zone:hover,
|
|
|
.license-upload-zone.dragover {
|
|
|
border-color: #667eea;
|
|
|
background: #f8f9ff;
|
|
|
}
|
|
|
.license-upload-icon {
|
|
|
font-size: 48px;
|
|
|
margin-bottom: 10px;
|
|
|
}
|
|
|
.license-upload-text {
|
|
|
color: #666;
|
|
|
}
|
|
|
.license-hostname-info {
|
|
|
background: #f5f5f5;
|
|
|
padding: 15px;
|
|
|
border-radius: 8px;
|
|
|
margin-bottom: 20px;
|
|
|
}
|
|
|
.license-hostname-info code {
|
|
|
background: #e0e0e0;
|
|
|
padding: 2px 8px;
|
|
|
border-radius: 4px;
|
|
|
font-family: monospace;
|
|
|
}
|
|
|
.license-result {
|
|
|
padding: 15px;
|
|
|
border-radius: 8px;
|
|
|
margin-top: 15px;
|
|
|
}
|
|
|
.license-result.loading {
|
|
|
background: #e3f2fd;
|
|
|
color: #1565c0;
|
|
|
}
|
|
|
.license-result.success {
|
|
|
background: #e8f5e9;
|
|
|
color: #2e7d32;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
gap: 15px;
|
|
|
}
|
|
|
.license-result.error {
|
|
|
background: #ffebee;
|
|
|
color: #c62828;
|
|
|
}
|
|
|
.license-success-icon {
|
|
|
font-size: 32px;
|
|
|
}
|
|
|
.license-error-message {
|
|
|
background: #ffebee;
|
|
|
color: #c62828;
|
|
|
padding: 12px 15px;
|
|
|
border-radius: 8px;
|
|
|
margin-bottom: 20px;
|
|
|
border-left: 4px solid #c62828;
|
|
|
}
|
|
|
.license-details-table {
|
|
|
width: 100%;
|
|
|
border-collapse: collapse;
|
|
|
}
|
|
|
.license-details-table td {
|
|
|
padding: 8px 12px;
|
|
|
border-bottom: 1px solid #eee;
|
|
|
}
|
|
|
.license-details-table td:first-child {
|
|
|
width: 40%;
|
|
|
color: #666;
|
|
|
}
|
|
|
.feature-tag {
|
|
|
display: inline-block;
|
|
|
background: #e3f2fd;
|
|
|
color: #1565c0;
|
|
|
padding: 4px 10px;
|
|
|
border-radius: 12px;
|
|
|
font-size: 12px;
|
|
|
margin: 2px;
|
|
|
}
|
|
|
.btn-danger {
|
|
|
background: #f44336 !important;
|
|
|
color: white !important;
|
|
|
}
|
|
|
.btn-danger:hover {
|
|
|
background: #d32f2f !important;
|
|
|
}
|
|
|
</style>
|
|
|
`;
|
|
|
async function initializeLicense() {
|
|
|
console.log('Git Pusher License System v' + LICENSE_CONFIG.version + ' (RSA)');
|
|
|
if (!document.getElementById('license-styles')) {
|
|
|
const styleEl = document.createElement('div');
|
|
|
styleEl.id = 'license-styles';
|
|
|
styleEl.innerHTML = licenseStyles;
|
|
|
document.head.appendChild(styleEl);
|
|
|
}
|
|
|
const stored = localStorage.getItem(LICENSE_CONFIG.storageKey);
|
|
|
if (!stored) {
|
|
|
console.log('Aucune licence en cache, tentative de chargement depuis le serveur...');
|
|
|
const loadedFromServer = await loadLicenseFromServer();
|
|
|
if (loadedFromServer) {
|
|
|
console.log('✓ Licence restaurée depuis le serveur');
|
|
|
} else {
|
|
|
console.log('Aucune licence disponible');
|
|
|
}
|
|
|
} else {
|
|
|
console.log('Licence trouvée dans le cache local');
|
|
|
}
|
|
|
updateLicenseBadge();
|
|
|
}
|
|
|
window.initializeLicense = initializeLicense;
|
|
|
window.validateLicense = validateLicense;
|
|
|
window.saveLicense = saveLicense;
|
|
|
window.removeLicense = removeLicense;
|
|
|
window.loadLicenseFromServer = loadLicenseFromServer;
|
|
|
window.checkLicenseBeforePush = checkLicenseBeforePush;
|
|
|
window.showLicenseModal = showLicenseModal;
|
|
|
window.closeLicenseModal = closeLicenseModal;
|
|
|
window.showLicenseDetails = showLicenseDetails;
|
|
|
window.confirmRemoveLicense = confirmRemoveLicense;
|
|
|
window.updateLicenseBadge = updateLicenseBadge;
|
|
|
window.hasFeature = hasFeature;
|
|
|
window.incrementUsage = incrementUsage;
|
|
|
window.getUsageStats = getUsageStats;
|
|
|
window.getLicenseInfo = getLicenseInfo;
|
|
|
if (document.readyState === 'complete') {
|
|
|
setTimeout(initializeLicense, 100);
|
|
|
} else {
|
|
|
window.addEventListener('load', function() {
|
|
|
setTimeout(initializeLicense, 100);
|
|
|
});
|
|
|
}
|