-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.js
More file actions
351 lines (280 loc) · 12.9 KB
/
system.js
File metadata and controls
351 lines (280 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
(function(window, document) {
'use strict';
const GGLCT_SYSTEM_CONFIG = {
version: '2.1.0',
securityServiceUrl: 'https://gglguard.ir/app/security.php',
adPlaceholderSelector: '#gglct-ad-placeholder',
clientIdentifierHeaderName: 'X-GGLCT-Client-Request',
clientIdentifierHeaderValue: 'GGLCT-PowerScript-Client/1.0',
nonceHeaderName: 'X-GGLCT-Nonce',
sharedSecretKeyForVerification: 'zFI4 Iihv 0DvJ OHIf vX7F lLzI',
checkInterval: 30000,
maxRetries: 3,
retryDelay: 5000,
debugMode: false
};
let systemState = {
initialized: false,
retryCount: 0,
tokenPayload: null,
signature: null,
verificationTimer: null,
adRendered: false
};
function gglctLog(message, type = 'info') {
if (GGLCT_SYSTEM_CONFIG.debugMode || type === 'error' || type === 'warn') {
console[type]('[GGLCT System]', message);
}
}
async function gglctGenerateHmacSha256(dataObject, secret) {
const sortedKeys = Object.keys(dataObject).sort();
let queryString = '';
for (const key of sortedKeys) {
if (key === 'ad_html') continue;
if (queryString !== '') {
queryString += '&';
}
queryString += `${encodeURIComponent(key)}=${encodeURIComponent(dataObject[key])}`;
}
const encoder = new TextEncoder();
const key = await crypto.subtle.importKey(
"raw",
encoder.encode(secret),
{ name: "HMAC", hash: "SHA-256" },
false,
["sign"]
);
const signatureBuffer = await crypto.subtle.sign(
"HMAC",
key,
encoder.encode(queryString)
);
return Array.from(new Uint8Array(signatureBuffer))
.map(b => b.toString(16).padStart(2, '0'))
.join('');
}
function gglctGenerateNonce(length = 32) {
const array = new Uint8Array(length);
window.crypto.getRandomValues(array);
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
}
function gglctDecodeBase64(base64String) {
try {
return window.atob(base64String);
} catch (e) {
gglctLog('Error decoding base64 content: ' + e.message, 'error');
return '<p>Error displaying content.</p>';
}
}
async function gglctFetchAdData() {
gglctLog('Fetching advertising and security data...');
const nonce = gglctGenerateNonce();
const headers = new Headers();
headers.append('Accept', 'application/json');
headers.append(GGLCT_SYSTEM_CONFIG.clientIdentifierHeaderName, GGLCT_SYSTEM_CONFIG.clientIdentifierHeaderValue);
headers.append(GGLCT_SYSTEM_CONFIG.nonceHeaderName, nonce);
try {
const response = await fetch(GGLCT_SYSTEM_CONFIG.securityServiceUrl, {
method: 'GET',
headers: headers,
cache: 'no-store'
});
if (!response.ok) {
const errorText = await response.text();
gglctLog(`Server error: ${response.status}. Response: ${errorText}`, 'error');
return null;
}
const data = await response.json();
if (!data || data.status !== 'success' || !data.payload || !data.signature) {
gglctLog('Invalid data structure received from security service', 'error');
return null;
}
if (data.payload.nonce !== nonce) {
gglctLog('Nonce mismatch in response. Security risk detected.', 'error');
return null;
}
if (data.payload.exp < Math.floor(Date.now() / 1000)) {
gglctLog('Received expired security token', 'warn');
return null;
}
const calculatedSignature = await gglctGenerateHmacSha256(
data.payload,
GGLCT_SYSTEM_CONFIG.sharedSecretKeyForVerification
);
if (calculatedSignature !== data.signature) {
gglctLog('Signature verification failed. Data may have been tampered.', 'error');
return null;
}
gglctLog('Security verification passed successfully');
systemState.tokenPayload = data.payload;
systemState.signature = data.signature;
return data.payload;
} catch (error) {
gglctLog('Network or processing error: ' + error.message, 'error');
return null;
}
}
function gglctRenderAd(payload) {
if (!payload || !payload.ad_html) {
gglctLog('No advertisement content to render', 'error');
return false;
}
const adPlaceholder = document.querySelector(GGLCT_SYSTEM_CONFIG.adPlaceholderSelector);
if (!adPlaceholder) {
gglctLog(`Ad placeholder "${GGLCT_SYSTEM_CONFIG.adPlaceholderSelector}" not found in DOM`, 'error');
return false;
}
const adHtml = gglctDecodeBase64(payload.ad_html);
adPlaceholder.innerHTML = adHtml;
const adElement = document.getElementById(payload.ad_id);
if (!adElement) {
gglctLog('Ad element not found after rendering', 'error');
return false;
}
setTimeout(() => {
adElement.style.opacity = '1';
adElement.style.transform = 'translateY(0)';
}, 100);
systemState.adRendered = true;
gglctLog('Advertisement rendered successfully');
return true;
}
function gglctLockSystem(message, errorCode = 'INTEGRITY_VIOLATION') {
gglctLog(`System locked: ${message} (Code: ${errorCode})`, 'error');
if (systemState.verificationTimer) {
clearInterval(systemState.verificationTimer);
systemState.verificationTimer = null;
}
systemState.initialized = false;
document.body.innerHTML = `
<div style="position:fixed; top:0; left:0; width:100%; height:100%; background-color:rgba(15, 23, 42, 0.98); color:#ef4444; display:flex; flex-direction:column; justify-content:center; align-items:center; z-index:9999999; text-align:center; padding:30px; font-family: Arial, sans-serif; box-sizing: border-box;">
<div style="font-size: 4.5em; margin-bottom: 25px;">⚠️</div>
<h3 style="color:#ef4444; margin-bottom:15px; font-size:2em; text-shadow:0 0 10px #ef4444;">خطای یکپارچگی سیستم</h3>
<p style="margin-bottom:10px; line-height:1.7; color:#e2e8f0; font-size: 1.2em;">${message}</p>
<p style="margin-bottom:10px; line-height:1.7; color:#e2e8f0; font-size: 1.2em;">برای استفاده از این ابزار، لطفاً از نسخه اصلی و دستکارینشده استفاده نمایید یا با پشتیبانی تماس بگیرید.</p>
<small style="font-size:0.8em; color:#94a3b8; margin-top:15px;">GGLCT Security Module. Ref: ${errorCode}</small>
</div>
`;
document.body.style.overflow = 'hidden';
const errorEvent = new CustomEvent('gglctSystemError', {
detail: {
message: message,
code: errorCode
}
});
document.dispatchEvent(errorEvent);
if (typeof window.stop === 'function') {
window.stop();
} else if (typeof document.execCommand === 'function') {
try { document.execCommand('Stop'); } catch(e) {}
}
}
async function gglctVerifyIntegrity() {
if (!systemState.initialized || !systemState.tokenPayload) {
gglctLog('System not fully initialized for integrity check', 'warn');
return false;
}
if (!systemState.adRendered) {
gglctLog('Advertisement not rendered yet', 'warn');
return false;
}
const payload = systemState.tokenPayload;
const adElement = document.getElementById(payload.ad_id);
if (!adElement) {
gglctLog('Ad element missing from DOM during integrity check', 'error');
return false;
}
const titleElement = adElement.querySelector('.' + payload.wm_class + '-title');
if (!titleElement) {
gglctLog('Ad title element missing during integrity check', 'error');
return false;
}
const imageElement = adElement.querySelector('.' + payload.wm_class + '-img');
if (!imageElement || imageElement.src !== payload.ad_image_src) {
gglctLog('Ad image missing or modified during integrity check', 'error');
return false;
}
return true;
}
async function gglctRunIntegrityVerification() {
const isIntact = await gglctVerifyIntegrity();
if (!isIntact) {
gglctLockSystem('یکپارچگی سیستم در بررسی دورهای رد شد. محتوای ضروری دستکاری شده یا حذف شده است.', 'INTEGRITY_FAIL_PERIODIC');
return false;
}
return true;
}
async function gglctFetchWithRetries() {
let payload = null;
systemState.retryCount = 0;
while (systemState.retryCount < GGLCT_SYSTEM_CONFIG.maxRetries && !payload) {
payload = await gglctFetchAdData();
if (payload) return payload;
systemState.retryCount++;
if (systemState.retryCount < GGLCT_SYSTEM_CONFIG.maxRetries) {
const delay = GGLCT_SYSTEM_CONFIG.retryDelay * systemState.retryCount;
gglctLog(`Retrying data fetch (${systemState.retryCount}/${GGLCT_SYSTEM_CONFIG.maxRetries}) in ${delay/1000}s...`, 'warn');
await new Promise(resolve => setTimeout(resolve, delay));
}
}
return null;
}
async function gglctInitializeSystem() {
gglctLog(`Initializing GGLCT System v${GGLCT_SYSTEM_CONFIG.version}...`);
const adData = await gglctFetchWithRetries();
if (!adData) {
gglctLockSystem('عدم امکان برقراری ارتباط با سرویس امنیتی یا دریافت دادههای نامعتبر.', 'SERVICE_UNREACHABLE');
return;
}
const renderSuccess = gglctRenderAd(adData);
if (!renderSuccess) {
gglctLockSystem('خطا در نمایش بخشهای ضروری سیستم.', 'RENDER_FAILURE');
return;
}
const integrityPassed = await gglctVerifyIntegrity();
if (!integrityPassed) {
gglctLockSystem('یکپارچگی سیستم تایید نشد. محتوای ضروری دستکاری شده یا حذف شده است.', 'INTEGRITY_FAIL_INITIAL');
return;
}
systemState.initialized = true;
gglctLog('GGLCT System initialized successfully');
const randomJitter = Math.floor(Math.random() * 5000);
systemState.verificationTimer = setInterval(
gglctRunIntegrityVerification,
GGLCT_SYSTEM_CONFIG.checkInterval + randomJitter
);
const readyEvent = new CustomEvent('gglctSystemReady', {
detail: {
payload: systemState.tokenPayload,
signature: systemState.signature
}
});
document.dispatchEvent(readyEvent);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', gglctInitializeSystem);
} else {
gglctInitializeSystem();
}
window.GGLCT_System = {
version: GGLCT_SYSTEM_CONFIG.version,
isInitialized: () => systemState.initialized,
getCurrentPayload: () => systemState.tokenPayload ? {...systemState.tokenPayload} : null,
getSecurityToken: () => {
if (systemState.initialized &&
systemState.tokenPayload &&
systemState.tokenPayload.exp > Math.floor(Date.now() / 1000)) {
return systemState.tokenPayload.security_token || null;
}
return null;
},
forceIntegrityCheck: async () => {
if (!systemState.initialized) return false;
const intact = await gglctVerifyIntegrity();
if (!intact) {
gglctLockSystem('یکپارچگی سیستم در بررسی دستی رد شد.', 'INTEGRITY_FAIL_MANUAL');
}
return intact;
}
};
})(window, document);