-
Notifications
You must be signed in to change notification settings - Fork 3
341 lines (331 loc) · 14.6 KB
/
deno.yml
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
const inputVoucherCode = document.getElementById("voucherCode");
inputVoucherCode.oninput = () => {
if (inputVoucherCode.value.length > inputVoucherCode.maxLength)
inputVoucherCode.value = inputVoucherCode.value.slice(0, inputVoucherCode.maxLength);
};
inputVoucherCode.onkeyup = (e) => {
if (e.keyCode === 13 || e.keyCode === "Enter") {
e.preventDefault();
setTimeout(() => document.getElementById("button-login").click(), 1);
}
};
var Ajax = {
post: function (url, data, fn) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
fn.call(this, xhr.responseText);
}
};
xhr.send(data);
}
};
var data = {};
var globalConfig = {};
var submitUrl;
var clientMac = getQueryStringKey("clientMac");
var apMac = getQueryStringKey("apMac");
var gatewayMac = getQueryStringKey("gatewayMac") || undefined;
var ssidName = getQueryStringKey("ssidName") || undefined;
var radioId = !!getQueryStringKey("radioId")? Number(getQueryStringKey("radioId")) : undefined;
var vid = !!getQueryStringKey("vid")? Number(getQueryStringKey("vid")) : undefined;
var originUrl = getQueryStringKey("originUrl");
var previewSite = getQueryStringKey("previewSite");
var hotspotMap = {
3: "Voucher Access",
5: "Local User Access",
6: "SMS Access",
8: "RADIUS Access"
};
var errorHintMap = {
"0": "ok",
"-1": "General error.",
"-41500": "Invalid authentication type.",
"-41501": "Failed to authenticate.",
"-41502": "Voucher code is incorrect.",
"-41503": "Voucher is expired.",
"-41504": "Voucher traffic has exceeded the limit.",
"-41505": "The number of users has reached the limit.",
"-41506": "Invalid authorization information.",
"-41507": "Your authentication times out. You can get authenticated again until the next day.",
"-41508": "Local User traffic has exceeded the limit.",
"-41512": "Local User is expired.",
"-41513": "Local User is disabled.",
"-41514": "MAC address is incorrect.",
"-41515": "Local User Quota has exceeded the limit.",
"-41516": "The number of users has reached the limit.",
"-41517": "Incorrect password.",
"-41518": "This SSID does not exist.",
"-41519": "Invalid code.",
"-41520": "The code is expired.",
"-41521": "The number of users has reached the limit.",
"-41522": "Failed to validate the code.",
"-41523": "Failed to send verification code.",
"-41524": "Authentication failed because the username does not exist.",
"-41525": "Authentication failed because of wrong password.",
"-41526": "Authentication failed because the client is invalid.",
"-41527": "Authentication failed because the local user is invalid.",
"-41528": "Failed to decrypt data.",
"-41529": "Incorrect username or password.",
"-41530": "Connecting to the RADIUS server times out.",
"-41531": "Your code have reached your Wi-Fi data limit.",
"-41532": "Your account have reached your Wi-Fi data limit.",
"-41533": "Form authentication request is invalid.",
"-43408": "Invalid LDAP configuration.",
"-43409": "Invalid LDAP credentials.",
"-41538": "Voucher is not effective."
};
var facebookUrl = !!apMac? ('/portal/fbwifi/forward?clientMac='+encodeURIComponent(clientMac)+'&apMac='+encodeURIComponent(apMac)+'&ssidName='+encodeURIComponent(ssidName)+'&radioId='+encodeURIComponent(radioId)+'&originUrl='+encodeURIComponent(originUrl))
: ('/portal/fbwifi/forward?clientMac='+encodeURIComponent(clientMac)+'&gatewayMac='+encodeURIComponent(gatewayMac)+'&vid='+encodeURIComponent(vid)+'&originUrl='+encodeURIComponent(originUrl));
var isCommited;
function getQueryStringKey (key) {
return getQueryStringAsObject()[key];
}
function getQueryStringAsObject () {
var b, cv, e, k, ma, sk, v, r = {},
d = function (v) { return decodeURIComponent(v); }, //# d(ecode) the v(alue)
q = window.location.search.substring(1), //# suggested: q = decodeURIComponent(window.location.search.substring(1)),
s = /([^&;=]+)=?([^&;]*)/g //# original regex that does not allow for ; as a delimiter: /([^&=]+)=?([^&]*)/g
;
ma = function(v) {
if (typeof v != "object") {
cv = v;
v = {};
v.length = 0;
if (cv) { Array.prototype.push.call(v, cv); }
}
return v;
};
while (e = s.exec(q)) {
b = e[1].indexOf("[");
v = d(e[2]);
if (b < 0) {
k = d(e[1]);
if (r[k]) {
r[k] = ma(r[k]);
Array.prototype.push.call(r[k], v);
}
else {
r[k] = v;
}
}
else {
k = d(e[1].slice(0, b));
sk = d(e[1].slice(b + 1, e[1].indexOf("]", b)));
r[k] = ma(r[k]);
if (sk) { r[k][sk] = v; }
else { Array.prototype.push.call(r[k], v); }
}
}
return r;
}
Ajax.post(
'/portal/getPortalPageSetting',
JSON.stringify({
"clientMac": clientMac,
"apMac": apMac,
"gatewayMac": gatewayMac,
"ssidName": ssidName,
"radioId": radioId,
"vid": vid,
"originUrl": originUrl
}),
function (res) {
res = JSON.parse(res);
data = res.result;
submitUrl = "/portal/auth";
var landingUrl = data.landingUrl;
isCommited = false;
globalConfig = {
authType: data.authType,
hotspotTypes: !!data.hotspot && data.hotspot.enabledTypes || [],
error : data.error || 'ok',
countryCode : !!data.sms && data.sms.countryCode || 1
};
function pageConfigParse(){
if (res.errorCode !== 0){
document.getElementById("oper-hint").style.display = "block";
document.getElementById("oper-hint").innerHTML = errorHintMap[res.errorCode];
}
document.getElementById("hotspot-section").style.display = "none";
document.getElementById("input-voucher").style.display = "none";
document.getElementById("input-user").style.display = "none";
document.getElementById("input-password").style.display = "none";
document.getElementById("input-simple").style.display = "none";
document.getElementById("input-phone-num").style.display = "none";
document.getElementById("input-verify-code").style.display = "none";
document.getElementById("button-facebook").style.display = "none";
switch (globalConfig.authType){
case 0:
window.authType = 0;
break;
case 1:
document.getElementById("input-simple").style.display = "block";
window.authType = 1;
break;
case 2:
hotspotChang(2);
window.authType = 2;
break;
case 15:
hotspotChang(15);
window.authType = 15;
break;
case 7:
document.getElementById("button-facebook").style.display = "block";
document.getElementById("button-facebook").addEventListener("click", function () {
window.location.href = facebookUrl;
});
document.getElementById("button-login").style.display = "none";
window.authType = 7;
break;
case 11:
document.getElementById("hotspot-section").style.display = "block";
var options = "";
for (var i=0;i<globalConfig.hotspotTypes.length;i++) {
options += '<option value="'+globalConfig.hotspotTypes[i]+'">'+hotspotMap[globalConfig.hotspotTypes[i]]+'</option>';
}
document.getElementById("hotspot-selector").innerHTML = options;
hotspotChang(globalConfig.hotspotTypes[0]);
window.authType = globalConfig.hotspotTypes[0];
break;
}
}
function handleSubmit(){
var submitData = {};
submitData['authType'] = window.authType;
switch (window.authType){
case 3:
submitData['voucherCode'] = document.getElementById("voucherCode").value;
break;
case 5:
submitData['localuser'] = document.getElementById("username").value;
submitData['localuserPsw'] = document.getElementById("password").value;
break;
case 1:
submitData['simplePassword'] = document.getElementById("simplePassword").value;
break;
case 0:
break;
case 6:
submitData['phone'] = "+"+document.getElementById("country-code").value + document.getElementById("phone-number").value;
submitData['code'] = document.getElementById("verify-code").value;
break;
case 2:
case 8:
submitData['username'] = document.getElementById("username").value;
submitData['password'] = document.getElementById("password").value;
break;
case 15:
submitData['ldapUsername'] = document.getElementById("username").value;
submitData['ldapPassword'] = document.getElementById("password").value;
break;
default:
break;
}
if(isCommited == false){
submitData['clientMac'] = clientMac;
submitData['apMac'] = apMac;
submitData['gatewayMac'] = gatewayMac;
submitData['ssidName'] = ssidName;
submitData['radioId'] = radioId;
submitData['vid'] = vid;
if(window.authType == 2 || window.authType == 8 || window.authType === 15){
if(window.authType === 15) {
submitUrl = '/portal/ldap/auth';
} else {
submitUrl = "/portal/radius/auth";
}
submitData['authType'] = window.authType;
} else {
submitData['originUrl'] = originUrl;
}
function doAuth () {
Ajax.post(submitUrl, JSON.stringify(submitData).toString(), function(data){
data = JSON.parse(data);
if(!!data && data.errorCode === 0) {
isCommited = true;
window.location.href = landingUrl;
document.getElementById("oper-hint").innerHTML = errorHintMap[data.errorCode];
} else{
document.getElementById("oper-hint").innerHTML = errorHintMap[data.errorCode];
}
});
}
doAuth();
}
}
function hotspotChang (type) {
document.getElementById("input-voucher").style.display = "none";
document.getElementById("input-user").style.display = "none";
document.getElementById("input-password").style.display = "none";
document.getElementById("input-phone-num").style.display = "none";
document.getElementById("input-verify-code").style.display = "none";
document.getElementById("button-login").style.display = "block";
window.authType = Number(type);
switch (Number(type)) {
case 3:
document.getElementById("input-voucher").style.display = "block";
break;
case 5:
case 2:
case 8:
case 15:
document.getElementById("input-user").style.display = "block";
document.getElementById("input-password").style.display = "block";
break;
case 6:
document.getElementById("input-phone-num").style.display = "block";
document.getElementById("input-verify-code").style.display = "block";
break;
}
}
globalConfig.countryCode = "+" + parseInt(globalConfig.countryCode, 10);
document.getElementById("country-code").value = parseInt(globalConfig.countryCode, 10);
document.getElementById("hotspot-selector").addEventListener("change", function () {
var obj = document.getElementById("hotspot-selector");
var opt = obj.options[obj.selectedIndex];
hotspotChang(opt.value);
});
document.getElementById("button-login").addEventListener("click", handleSubmit);
document.getElementById("get-code").addEventListener("click", function(e){
e.preventDefault();
var phoneNum = document.getElementById("phone-number").value;
function sendSmsAuthCode () {
Ajax.post("/portal/sendSmsAuthCode",
JSON.stringify({
clientMac: clientMac,
apMac: apMac,
gatewayMac: gatewayMac,
ssidName: ssidName,
radioId: radioId,
vid: vid,
phone: "+" + document.getElementById("country-code").value + phoneNum
}),function(data){
data = JSON.parse(data);
if(data.errorCode !== 0){
document.getElementById("oper-hint").innerHTML = errorHintMap[data.errorCode];
} else {
document.getElementById("oper-hint").innerHTML = "SMS has been sent successfully.";
}
}
);
}
sendSmsAuthCode();
document.getElementById("oper-hint").innerHTML = "Sending Authorization Code...";
});
pageConfigParse();
}
);
document.addEventListener("contextmenu", function(event){
event.preventDefault();
alert('Nice try 😎');
}, false);
document.onkeydown = function (e) {
var e = e || event;
if (e.shiftKey === true) {
return false;
}
};