-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.js
228 lines (216 loc) · 9.18 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
if (!sessionStorage.popup) {
sessionStorage.popup = true
Swal.fire({
type: 'info',
title: '回復營運聲明',
width:'90%',
html: '<p>親愛的使用者:</p><p>先前,本專案因持續受到政府與企業單位關切,原專案發起人不堪其擾,而移轉至香港商 Starlight Systems Company 公司(後更名至 Eons Data Communications Limited,下稱本公司)。</p><p>然為落實專案發起人承諾之個人資料安全主張,實現「個資不離地」,且顧及當前香港情勢,本公司決定於今日起將台灣區訂閱之個人資料轉交予 台灣數位串流有限公司(下稱合作公司) 負責。基於促進公眾利益之出發點,本站將持續提供免費無償之查詢服務。</p><p>為了保障各位使用者的個人資料安全,本次轉移遵循「資料庫不移轉」的方針,包括但不限於訂閱名單的所有資料庫內容,皆不會移轉至新服務內。</p><p>此外,我們在此聲明,後續服務中,供大眾查詢之內容皆為本公司所判斷、查核、新增至系統,概與舊有團隊與合作公司無關,敬請各位使用者繼續支持本專案。</p><p>此致</p><p>Eons Data Communications Limited 專案營運經理<br>台灣數位串流有限公司 專案營運經理</p><p>2020 年 08 月 01 日</p>'
});
}
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_hash(sha1(form.fullname.value + form.nid.value));
}
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.fullname.value + form.nid.value));
}
function search_func(form) {
search_by_hash(form.hash.value, true);
}
async function search_by_hash(hash, hashed = false) {
$('#search').attr('disabled', true);
if (!hashed) {
$('#search')[0].blur(); // HTMLElement API
$('#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);
// 清除 swal
Swal.close();
$('#search').text('送出').removeAttr('disabled');
await delay(100);
// 列出結果
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: '真是太糟糕了',
html: `發現個資洩漏情形<br/><br/><h4>已發現項目</h4>${breach.join('<br/>')}`,
footer: '<a href="/subscribe.php">訂閱外洩事件</a>|<a href="/breaches.php">外洩事件列表 & 解釋</a>|<a href="/faq.php#what-should-i-do-if-leaked">我應該怎麼做?</a>'
});
} else {
Swal.fire({
type: 'success',
title: '搜尋完畢',
html: '您的個資目前未在大規模洩漏中找到,不過可能只是未被本網站發現<br/>再接再厲,繼續保持。',
footer: '<a href="/subscribe.php">訂閱外洩事件</a>'
});
}
} else {
Swal.fire({
type: 'error',
title: '伺服器錯誤',
text: res.error
});
}
});
});
}
function subscribe_func(form) {
$('#subscribe').attr('disabled', true);
let hash = sha1(form.subscribe_form_fullname.value + form.subscribe_form_nid.value);
grecaptcha.execute(RECAPTCHA_SITE_KEY, {
action: 'subscribe'
}).then(function (token) {
let param = new URLSearchParams({
"hash": hash,
"email": form.subscribe_form_email.value,
"name": form.subscribe_form_fullname.value,
"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: '訂閱完成',
html: '雖已發現個資洩漏情形,但在未來進一步的個資洩漏時還是會通知您。'
});
} else {
Swal.fire({
type: 'success',
title: '訂閱完成',
html: '未在資料庫中發現個資洩漏情形,已新增訂閱資訊至系統,未來發現大規模個資外洩時會即時通知您。'
});
}
} else {
Swal.fire({
type: 'error',
title: '伺服器錯誤',
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: '查詢結果',
html: '此 E-mail 已訂閱洩漏訊息,但尚未驗證 E-mail,請前往您的電子郵箱確認。'
});
} else if (res.result == 'subscribed') {
$('.searchForm').hide();
$('.unSubForm').show();
$('#unsubscribe_form_email').val(form.email.value);
}
} else {
Swal.fire({
type: 'error',
title: '發生錯誤',
text: res.error
});
}
});
});
}
function unsubscribe_func(form) {
$('#unsubscribe').attr('disabled', true);
let hash = sha1(form.unsubscribe_form_fullname.value + form.unsubscribe_form_nid.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: '取消訂閱成功',
html: '已取消訂閱洩漏訊息。'
});
} else {
Swal.fire({
type: 'error',
title: '發生錯誤',
text: res.error
});
}
});
});
}
function showToast(title, type = "info") {
Swal.fire({
type: type,
title: title,
toast: true,
position: 'top-end',
showConfirmButton: false
});
}