-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.js
391 lines (362 loc) · 15.6 KB
/
main.js
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/*
Author: Leakfa Team
Author URI: https://leakfa.com
Version: 3.3.3
*/
function setCookie(cname, cvalue, exdays) {
try {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
} catch (error) {
console.error('Error setting cookie:', error);
}
}
function getCookie(cname) {
try {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
} catch (error) {
console.error('Error getting cookie:', error);
return "";
}
}
function checkPopupDisplayed() {
var popupDisplayed = getCookie("popupDisplayed");
return popupDisplayed === "true";
}
function displayPopup() {
setCookie("popupDisplayed", "true", 30); // Expire in 30 days
Swal.fire({
type: 'info',
title: 'نکته مهم:',
confirmButtonText: "باشه",
width:'90%',
html: '<p>هنگام وارد کردن شماره تلفن همراه از کیبورد اعداد انگلیسی و هنگام وارد کردن آدرس ایمیل از حروف کوچک برای نگارش استفاده کنید، در غیر این صورت هش متفاوتی تولید شده و نتیجه دیگری به شما نمایش داده میشود.</p>'
});
}
if (!checkPopupDisplayed()) {
displayPopup();
}
const delay = s => {
return new Promise(function (resolve, reject) {
setTimeout(resolve, s);
});
};
Object.size = function (obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function one_step(form) {
search_by_core(sha1(form.phone.value));
}
function incrementSearchCount() {
var searchCount = parseInt(getCookie("searchCount")) || 0;
searchCount++;
setCookie("searchCount", searchCount, 1); // Expire in 1 day
}
function checkSearchLimit() {
var searchCount = parseInt(getCookie("searchCount")) || 0;
if (searchCount >= 20) { // Search limit
showToast("شما به حد مجاز استفاده از جستجوی نشت رسیدهاید، لطفاً کمی صبر کنید و یا از API استفاده کنید.");
return true;
}
return false;
}
async function search_by_core(hash, hashed = false) {
if (checkSearchLimit()) {
return;
}
incrementSearchCount();
$('#search').attr('disabled', true);
if (!hashed) {
$('#search')[0].blur();
$('#search').text('درحال کدگذاری...')[0];
showToast('درحال کدگذاری...');
await delay(700);
Swal.close();
}
showToast('درحال جستجو...');
$('#search').text('در حال جستجو...');
grecaptcha.execute(RECAPTCHA_SITE_KEY, {
action: 'search'
}).then(function (token) {
let param = new URLSearchParams({
"mode": "recaptcha",
"hash": hash,
"token": token
});
fetch('/api/search.php?' + param.toString())
.then(res => res.json())
.then(async res => {
await delay(700);
// Clear toast
Swal.close();
$('#search').text('جستجو').removeAttr('disabled');
await delay(100);
// Populate search results
let searchResultsDiv = document.getElementById('searchResults');
if (res.status == 0) {
if (Object.size(res.result) > 0) {
let breach = [];
for (source in res.result) breach.push(source + ': ' + res.result[source].join('، '));
let iconHTML = '<div><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="80" height="80" class="error-icon"><path fill="red" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/></svg></div>';
let footerLinks = '<div class="swal2-footer" style="display: flex;"><a href="/notify">باخبرم کن</a>|<a href="/leaks">فهرست نشت های عمده</a>|<a href="/faq#what-should-i-do-if-leaked">باید چکار کنم؟</a></div>';
let resultsHTML = `
<div class="search-results" style="text-align: center;">
<br>
${iconHTML}
<h2 style="display: inline-block;">اوه نه، یه خبر بد</h2>
<p style="text-align: center;">ما نشتی از اطلاعات شما پیدا کردیم!</p>
<br>
<h3 style="text-align: right;">موارد افشا شده:</h3>
<ul>
${breach.map(item => `<li style="text-align: justify;">${item}</li><br>`).join('')}
</ul>
${footerLinks}
<br>
</div>`;
searchResultsDiv.innerHTML = resultsHTML;
searchResultsDiv.scrollIntoView({ behavior: 'smooth', block: 'start' });
} else {
let iconHTML = '<div><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="80" height="80" class="success-icon"><path fill="green" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm5 9l-5 5-5-5 1.41-1.41L12 13.17l3.59-3.58L17 11z"/></svg></div>';
let footerLinks = '<div class="swal2-footer" style="display: flex;"><a href="/notify">وقتی نشتی پیدا شد باخبرم کن!</a></div>';
let resultsHTML = `
<div class="search-results" style="text-align: center;">
<br>
${iconHTML}
<h2 style="display: inline-block;">یه خبر خوب!</h2>
<p style="text-align: center;">ما هیچ نشتی از اطلاعات شما پیدا نکردیم، اما ممکن است در آینده ای نزدیک اینطور نباشد!<br/>پس با دقت زیادی از داده های خود مراقبت کنید :)</p>
${footerLinks}
<br>
</div>`;
searchResultsDiv.innerHTML = resultsHTML;
searchResultsDiv.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
} else {
showToast('خطای سرور: ' + res.error, 'error');
}
});
});
}
async function gen_sha1(form) {
$('#hash').val("");
$('#genhash').text('درحال کدگذاری...').attr('disabled', true);
showToast('درحال کدگذاری...');
await delay(700);
Swal.close();
$('#genhash').text('تولید کردن').removeAttr('disabled');
$('#hash').val(sha1(form.phone.value));
}
function two_step(form) {
search_by_hash(form.hash.value, true);
}
async function search_by_hash(hash, hashed = false) {
if (checkSearchLimit()) {
return;
}
incrementSearchCount();
$('#search').attr('disabled', true);
if (!hashed) {
$('#search')[0].blur();
$('#search').text('درحال کدگذاری...')[0];
showToast('درحال کدگذاری...');
await delay(700);
Swal.close();
}
showToast('درحال جستجو...');
$('#search').text('در حال جستجو...');
grecaptcha.execute(RECAPTCHA_SITE_KEY, {
action: 'search'
}).then(function (token) {
let param = new URLSearchParams({
"mode": "recaptcha",
"hash": hash,
"token": token
});
fetch('/api/search.php?' + param.toString())
.then(res => res.json())
.then(async res => {
await delay(700);
// Clear swal
Swal.close();
$('#search').text('جستجو').removeAttr('disabled');
await delay(100);
// List results
if (res.status == 0) {
if (Object.size(res.result) > 0) {
let breach = [];
for (source in res.result) breach.push(source + ': ' + res.result[source].join('، '));
Swal.fire({
type: 'error',
title: 'اوه نه، یه خبر بد',
confirmButtonText: "باشه",
html: `ما نشتی از اطلاعات شما پیدا کردیم!<br/><br/><h4>موارد افشا شده</h4>${breach.join('<br/>')}`,
footer: '<a href="/notify">باخبرم کن</a>|<a href="/leaks">فهرست نشت های عمده</a>|<a href="/faq#what-should-i-do-if-leaked">باید چکار کنم؟</a>'
});
} else {
Swal.fire({
type: 'success',
title: 'یه خبر خوب!',
confirmButtonText: "باشه",
html: 'ما هیچ نشتی از اطلاعات شما پیدا نکردیم، اما ممکن است در آینده ای نزدیک اینطور نباشد!<br/>پس با دقت زیادی از داده های خود مراقبت کنید :) ',
footer: '<a href="/notify">وقتی نشتی پیدا شد باخبرم کن!</a>'
});
}
} else {
Swal.fire({
type: 'error',
title: 'خطای سرور',
confirmButtonText: "باشه",
text: res.error
});
}
});
});
}
function subscribe_func(form) {
$('#subscribe').attr('disabled', true);
let hash = sha1(form.subscribe_form_phone.value);
grecaptcha.execute(RECAPTCHA_SITE_KEY, {
action: 'subscribe'
}).then(function (token) {
let param = new URLSearchParams({
"hash": hash,
"email": form.subscribe_form_email.value,
"name": $('<div>').text(form.subscribe_form_fullname.value).html(),
"token": token
});
fetch('/api/subscribe.php?' + param.toString())
.then(function (response) {
return response.json();
})
.then(function (res) {
$('#subscribe').removeAttr('disabled');
if (res.status == 0) {
if (Object.size(res.result) > 0) {
Swal.fire({
type: 'success',
title: 'ثبت اشتراک انجام شد',
confirmButtonText: "باشه",
html: 'یک لینک تایید به ایمیل شما ارسال شد، لطفا با مراجعه به صندوق ورودی (Inbox) و بازکردن لینک ارسال شده، آدرس خود را تایید کنید. اگرچه نشتی از اطلاعات شخصی شما پیدا شده اما در صورت پیدا شدن نشتی جدید در مقیاس بزرگ، بلافاصله به شما اطلاع داده می شود.'
});
} else {
Swal.fire({
type: 'success',
title: 'ثبت اشتراک انجام شد',
confirmButtonText: "باشه",
html: 'یک لینک تایید به ایمیل شما ارسال شد، لطفا با مراجعه به صندوق ورودی (Inbox) و بازکردن لینک ارسال شده، آدرس خود را تایید کنید. در حال حاضر هیچ نشتی از اطلاعات شخصی شما پیدا نشد، در صورت کشف نشتی جدید در مقیاس بزرگ، بلافاصله به شما اطلاع داده می شود.'
});
}
} else {
Swal.fire({
type: 'error',
title: 'Server error',
confirmButtonText: "باشه",
text: res.error
});
}
});
});
}
function subscription_status_func(form) {
$('#query').attr('disabled', true);
grecaptcha.execute(RECAPTCHA_SITE_KEY, {
action: 'query_subscription_status'
}).then(function (token) {
let param = new URLSearchParams({
"email": form.email.value,
"token": token
});
fetch('/api/subscription_status.php?' + param.toString())
.then(function (res) {
return res.json();
}).then(function (res) {
$('#query').removeAttr('disabled');
if (res.status == 0) {
if (res.result == 'not_subscribed') {
$('.searchForm').hide();
$('.subForm').show();
$('#subscribe_form_email').val(form.email.value);
} else if (res.result == 'verification_pending') {
Swal.fire({
type: 'info',
title: 'آدرس تایید نشده',
confirmButtonText: "باشه",
html: 'این آدرس ایمیل در سامانه باخبرم کن ثبت شده اما هنوز تایید نشده است، لطفا با مراجعه به صندوق ورودی (Inbox) و بازکردن لینک ارسال شده، آدرس خود را تایید کنید.'
});
} else if (res.result == 'subscribed') {
$('.searchForm').hide();
$('.unSubForm').show();
$('#unsubscribe_form_email').val(form.email.value);
}
} else {
Swal.fire({
type: 'error',
title: 'خطایی روی داد',
confirmButtonText: "باشه",
text: res.error
});
}
});
});
}
function unsubscribe_func(form) {
$('#unsubscribe').attr('disabled', true);
let hash = sha1(form.unsubscribe_form_phone.value);
grecaptcha.execute(RECAPTCHA_SITE_KEY, {
action: 'unsubscribe'
}).then(function (token) {
let param = new URLSearchParams({
"hash": hash,
"email": form.unsubscribe_form_email.value,
"token": token
});
fetch('/api/unsubscribe.php?' + param.toString())
.then(function (res) {
return res.json();
}).then(function (res) {
$('#unsubscribe').removeAttr('disabled');
if (res.status == 0) {
Swal.fire({
type: 'success',
title: 'لغو اشتراک انجام شد',
confirmButtonText: "باشه",
html: 'شما با موفقیت اشتراک خود را از سامانه باخبرم کن لغو کردید. '
});
} else {
Swal.fire({
type: 'error',
title: 'خطایی روی داد',
confirmButtonText: "باشه",
text: res.error
});
}
});
});
}
function showToast(title, type = "info") {
Swal.fire({
type: type,
title: title,
toast: true,
position: 'top-end',
showConfirmButton: false
});
}