blob: b6ffb2f47bd7d1bb250a522bb9ae30cc77aa841e [file] [log] [blame]
zw.wangcbf6f772025-04-08 16:16:24 +08001define("wifi_advance","underscore jquery knockout set service jqui".split(" "),
2 function (_, $, ko, config, service, jqui) {
3 var $sliderRange = null;
4 //当前是否WiFi连接
5 var viaWifi = false;
6
7 function paintRateOption(data) {
8 var opts = [];
9 for (var i = 0; i < data.length; i++) {
10 var rate = data[i].rate == 0 ? "Auto" : data[i].rate + " Mbps";
11 opts.push(new Option(rate, data[i].index));
12 }
13 return opts;
14 }
15
16 //wifi传输速率
17 var transpeed = [0, 1, 2, 5.5, 6, 6.5, 9, 11, 12, 13, 18, 19.5, 24, 26, 36, 39, 48, 52, 54, 58.5, 65];
18
19 function rateSort(a, b) {
20 return a.rate - b.rate;
21 }
22 //删除重复速率值
23 function unionRate(rateTable) {
24 var rates = [],
25 result = [];
26 for (var i = 0; i < rateTable.length; i++) {
27 for (var j = 0; j < rateTable[i].length; j++) {
28 if (ko.utils.arrayIndexOf(rates, rateTable[i][j]) == -1) {
29 rates.push(rateTable[i][j]);
30 result.push({
31 index: rateTable[i][j],
32 rate: transpeed[rateTable[i][j]]
33 });
34 }
35 }
36 }
37 result.sort(rateSort);
38 return result;
39 }
40
41 //根据模式生成速率选项
42 function modeRateOption(wifimode) {
43 var wifimodeN = [0, 5, 9, 11, 13, 15, 17, 19, 20];
44 var wifimodeG = [0, 4, 6, 8, 10, 12, 14, 16, 18];
45 var wifimodeB = [0, 1, 2, 3, 7];
46 var rate = [];
47
48 switch (wifimode) {
49 //--wifimode
50 case '5':
51 rate.push(wifimodeN);
52 rate.push(wifimodeG);
53 rate.push(wifimodeB);
54 break;
55 case '4':
56 rate.push(wifimodeN);
57 rate.push(wifimodeG);
58 rate.push(wifimodeB);
59 break;
60 case '3':
61 rate.push(wifimodeG);
62 rate.push(wifimodeB);
63 break;
64 case '2':
65 rate.push(wifimodeN);
66 break;
67 case '1':
68 rate.push(wifimodeG);
69 break;
70 case '0':
71 rate.push(wifimodeB);
72 break;
73
74 default:
75 rate.push(wifimodeN);
76 break;
77 }
78 var union = unionRate(rate);
79 return paintRateOption(union);
80 }
81
82 function getCountryCode(country) {
83 var countryCodeArr = config.countryCode;
84 var type = '';
85 for (key in countryCodeArr) {
86 var codes = countryCodeArr[key];
87 if ($.inArray(country, codes) != -1) {
88 type = key;
89 break;
90 }
91 }
92 var typeCode = config.countryCodeType[type];
93 return typeCode ? typeCode : "0";
94 }
95
96 function channelOption(country) {
97 var showOption = [new Option('Auto', '0')];
98 var type = getCountryCode(country) + '';
99 switch (type) {
100 //--type
101 case '9':
102 generateChannelOption(showOption, 2307, 13);
103 break;
104 case '7':
105 generateChannelOption(showOption, 2307, 13);
106 generateChannelOption(showOption, 2407, 11);
107 generateChannelOption(showOption, 2462, 2);
108 break;
109 case '3':
110 generateChannelOption(showOption, 2407, 11);
111 generateChannelOption(showOption, 2462, 2);
112 break;
113 //--type
114 case '2':
115 generateChannelOption(showOption, 2307, 13);
116 generateChannelOption(showOption, 2407, 11);
117 break;
118 case '1':
119 generateChannelOption(showOption, 2407, 11);
120 break;
121 default:
122 generateChannelOption(showOption, 2407, 11);
123 }
124 return showOption;
125 }
126 function generateChannelOption(showOption, start, count) {
127 for (var i = 1; i <= count; i++) {
128 var txt = start + i * 5 + "MHz (Channel " + showOption.length + ")";
129 showOption.push(new Option(txt, showOption.length + "_" + (start + i * 5)));
130 }
131 }
132
133 function channelOption5g(country) {
134 for (key in config.countryCode_5g) {
135 var item = config.countryCode_5g[key];
136 if ($.inArray(country, item.codes) != -1) {
137 return generate5gChannelOption(item.channels);
138 }
139 }
140 return [new Option('Auto', '0')];
141 }
142 function generate5gChannelOption(channels) {
143 var showOption = [new Option('Auto', '0')];
144 for (var i = 0; i < channels.length; i++) {
145 var channel = channels[i];
146 var mhz = channel * 5 + 5000;
147 var txt = mhz + "MHz (Channel " + channel + ")";
148 showOption.push(new Option(txt, channel + "_" + (mhz)));
149 }
150 return showOption;
151 }
152
153 function getBandOptions() {
154 var showOption = [];
155 if (!config.WIFI_HAS_5G) {
156 showOption.push(new Option('2.4GHz', 'b'));
157 } else {
158 showOption.push(new Option('5GHz', 'a'));
159 showOption.push(new Option('2.4GHz', 'b'));
160 }
161 return showOption;
162 }
163
164 function getChannelBandwidthsOptions(wifiBand) {
165 var showOption = [];
166 showOption.push(new Option('20MHz', '0'));
167 if (config.WIFI_BANDWIDTH_SUPPORT_40MHZ) {
168 showOption.push(new Option('20MHz/40MHz', '1'));
169 }
170 if (config.WIFI_HAS_5G && wifiBand == 'a') {
171 if (config.WIFI_BANDWIDTH_SUPPORT_80MHZ) {
172 showOption.push(new Option('20MHz/40MHz/80MHz', '4'));
173 }
174 }
175 return showOption;
176 }
177
178 function countryCodeOption() {
179 var countries;
180 if (config.WIFI_HAS_5G) {
181 countries = config.countries_5g;
182 } else {
183 countries = config.countries;
184 }
185 var showOption = [];
186 for (key in countries) {
187 showOption.push(new Option(countries[key], key));
188 }
189 showOption = _.sortBy(showOption, function (opt) {
190 return opt.text;
191 });
192 return showOption;
193 }
194
195 function getWifiAdvance() {
196 return service.getWifiAdvance();
197 }
198
199 function getWpsState() {
200 return service.getWpsInfo();
201 }
202
203 function getModeOption(wifiBand) {
204 var modes = wifiBand == 'a' ? config.NETWORK_MODES_BAND : config.NETWORK_MODES;
205 if (modes.length == 1) {
206 $("#mode").hide();
207 $("#modeFor5HZ").hide();
208 } else {
209 if (wifiBand == 'a') {
210 $("#mode").hide();
211 $("#modeFor5HZ").show();
212 } else {
213 $("#mode").show();
214 $("#modeFor5HZ").hide();
215 }
216 }
217 if (wifiBand == 'a') {
218 $("#modeLabel").attr('for', 'modeFor5HZ');
219 } else {
220 $("#modeLabel").attr('for', 'mode');
221 }
222 var modeOptions = [];
223 for (var i = 0; i < modes.length; i++) {
224 modeOptions.push(new Option(modes[i].name, modes[i].value));
225 }
226 return modeOptions;
227 }
228
229 function getSelectedRateV(rate, rates) {
230 for (var i = 0; i < rates.length; i++) {
231 var opt = rates[i];
232 if (opt.text == rate + " Mbps") {
233 return opt.value;
234 }
235 }
236 return '0';
237 }
238 //获取所选的信道对应的value值
239 function getSelectedChannelV(channel, channels) {
240 for (var i = 0; i < channels.length; i++) {
241 var opt = $(channels[i]);
242 if (opt.val().split("_")[0] == channel) {
243 return opt.val();
244 }
245 }
246 return '0';
247 }
248
249 function WifiAdvanceViewModel() {
250 // Data
251 var target = this;
252
253 var wifiInfo = service.getWifiAdvance();
254 target.origin_ap_station_enable = wifiInfo.ap_station_enable;
255 target.modes = ko.observableArray(getModeOption(wifiInfo.wifiBand));
256 target.bands = ko.observableArray(getBandOptions());
257
258 var countryOpts = countryCodeOption();
259 target.countries = ko.observableArray(countryOpts);
260 target.channels = ko.observableArray(wifiInfo.wifiBand == 'a' ? channelOption5g(wifiInfo.countryCode) : channelOption(wifiInfo.countryCode));
261 target.rates = ko.observableArray(modeRateOption(wifiInfo.mode));
262
263 target.hasAPStation = config.AP_STATION_SUPPORT;
264 target.hasWifiSwitch = config.WIFI_SWITCH_SUPPORT;
265 target.hasMultiSSID = config.HAS_MULTI_SSID;
266 target.hasWlanMacfilter = config.HAS_BLACK_AND_WHITE_FILTER;
267 target.hasWifiBand = ko.observable(config.WIFI_BAND_SUPPORT);
268 target.hasBandwidth = ko.observable(config.WIFI_BANDWIDTH_SUPPORT);
269
270 target.selectedMode = ko.observable(wifiInfo.mode);
271 target.selectedChannel = ko.observable(getSelectedChannelV(wifiInfo.channel, target.channels()));
272 target.selectedChannelBandwidth = ko.observable(wifiInfo.bandwidth); //5:a, 2.5:b
273 target.selectedCountry = ko.observable(wifiInfo.countryCode.toUpperCase());
274 target.selectedBand = ko.observable(wifiInfo.wifiBand); //5:a, 2.5:b
275 target.selectedRate = ko.observable(getSelectedRateV(wifiInfo.rate, target.rates()));
276
277 var baseInfo = service.getWifiBasic();
278 target.wifi_enable = ko.observable(baseInfo.wifi_enable);
279 if (config.HAS_MULTI_SSID && ((baseInfo.m_AuthMode == "OPEN" && baseInfo.m_encryptType == "WEP") || (baseInfo.m_AuthMode == "SHARED" && baseInfo.m_encryptType == "WEP") || baseInfo.m_encryptType == "TKIP")) {
280 target.isF = ko.observable(true);
281 } else if ((baseInfo.AuthMode == "OPEN" && baseInfo.encryptType == "WEP") || (baseInfo.AuthMode == "SHARED" && baseInfo.encryptType == "WEP") || baseInfo.encryptType == "TKIP") {
282 target.isF = ko.observable(true);
283 } else {
284 target.isF = ko.observable(false);
285 }
286 target.isShowSSIDInfoDiv = ko.observable(false);
287 if (config.WIFI_SWITCH_SUPPORT) {
288 if (baseInfo.wifi_enable == "1") {
289 target.isShowSSIDInfoDiv(true);
290 } else {
291 target.isShowSSIDInfoDiv(false);
292 }
293 } else {
294 target.isShowSSIDInfoDiv(true);
295 }
296 target.multi_ssid_enable = ko.observable(baseInfo.multi_ssid_enable);
297 target.origin_multi_ssid_enable = baseInfo.multi_ssid_enable;
298 target.maxStationNumber = ko.observable(wifiInfo.MAX_Station_num);
299 target.selectedStation = ko.observable(wifiInfo.MAX_Access_num);
300 target.selectedStationM = ko.observable(wifiInfo.m_MAX_Access_num);
301
302 target.oneBandTrans = ko.observable(wifiInfo.wifiBand == 'a' ? '5G' : '2.4G');
303 target.oneModeTrans = ko.observable((wifiInfo.wifiBand == 'a' ? 'network_modes_band_select_' : 'network_mode_select_') + wifiInfo.mode);
304 target.oneModeText = ko.observable("");
305 target.oneModeText($.i18n.prop(target.oneModeTrans()));
306
307 target.channelBandwidths = ko.computed(function () {
308 return getChannelBandwidthsOptions(target.selectedBand());
309 });
310
311 wifiInfo = $.extend(wifiInfo, target);
312
313 //Event Handler 频段切换时更新对应的国家/地区码、信道和网络模式选项
314 target.bandChangeHandler = function () {
315 if (target.selectedBand() == 'a') { //5g
316 //802.11a only 802.11n only 802.11a/n
317 target.modes(getModeOption(target.selectedBand()));
318 target.countries(countryCodeOption());
319 target.oneModeTrans('network_modes_band_select_' + target.selectedMode());
320 } else { // 2.4g
321 //802.11 n only 802.11 b/g/n
322 target.modes(getModeOption(target.selectedBand()));
323 target.countries(countryCodeOption());
324 target.oneModeTrans('network_mode_select_' + target.selectedMode());
325 }
326 target.oneModeText($.i18n.prop(target.oneModeTrans()));
327 var currChannelBandwidths = target.channelBandwidths();
328 target.selectedChannelBandwidth(currChannelBandwidths[currChannelBandwidths.length - 1].value);
329 target.selectedCountry('0');
330 target.channels(target.generateChannelOption());
331 target.selectedChannel('0');
332 };
333
334 target.countryChangeHandler = function (data, event) {
335 var opts = target.generateChannelOption();
336 target.channels(opts);
337 target.selectedChannel('0');
338 };
339
340 target.modeChangeHandler = function (data, event) {
341 var opts = modeRateOption(target.selectedMode());
342 target.rates(opts);
343 target.selectedRate('0');
344 };
345
346 target.generateChannelOption = function () {
347 if (target.selectedBand() == 'a') {
348 return channelOption5g(target.selectedCountry());
349 } else {
350 return channelOption(target.selectedCountry());
351 }
352 };
353
354 target.save = function () {
355 var status = getWpsState();
356 if (status.wpsFlag == '1') {
357 showAlert('wps_on_info', function() {
358 window.location.reload();
359 });
360 return;
361 }
362 var selectedRateTxt = $("#rate option:selected").text();
363 var rateVal = null;
364 if (selectedRateTxt != $.i18n.prop('rate_0')) {
365 rateVal = $.trim(selectedRateTxt.replace('Mbps', ''));
366 } else {
367 rateVal = 0;
368 }
369 var wifiParam = {};
370 wifiParam.countryCode = target.selectedCountry();
371 wifiParam.mode = target.selectedMode();
372 var selectedChannel = target.selectedChannel();
373 wifiParam.channel = selectedChannel == '0' ? '0' : selectedChannel.split("_")[0];
374 wifiParam.rate = rateVal;
375 wifiParam.wifiBand = target.selectedBand();
376 if (config.WIFI_BANDWIDTH_SUPPORT) {
377 wifiParam.bandwidth = target.selectedChannelBandwidth();
378 }
379 wifiParam.station = target.selectedStation();
380 wifiParam.m_station = target.selectedStationM();
381 showConfirm('wifi_disconnect_confirm', function () {
382 showLoading('waiting');
383 service.setWifiAdvance(wifiParam, function (result) {
384 if (result.result == "success") {
385 if (viaWifi) {
386 setTimeout(advanceReloadVarWifi, 15000);
387 } else {
388 addInterval(advanceReload, 1000);
389 }
390 } else {
391 errorOverlay();
392 }
393 });
394 });
395 };
396
397 target.checkSettings = function (ssid) {
398 var status = getWpsState();
399 if (status.wpsFlag == '1') {
400 showAlert('wps_on_info', function() {
401 window.location.reload();
402 });
403 return true;
404 }
405 if (config.HAS_MULTI_SSID && baseInfo.multi_ssid_enable == "1") {
406 if ((ssid == "ssid1" && parseInt(target.selectedStation()) + parseInt(baseInfo.m_MAX_Access_num) > baseInfo.MAX_Station_num)
407 || (ssid == "ssid2" && parseInt(target.m_selectedStation()) + parseInt(baseInfo.MAX_Access_num) > baseInfo.MAX_Station_num)) {
408 showAlert({
409 msg: 'multi_ssid_max_access_number_alert',
410 wifiParam: baseInfo.MAX_Station_num
411 });
412 return true;
413 }
414 }
415
416 return false;
417 };
418
419 target.setMultiSSIDSwitch = function () {
420 if (target.checkSettings("switch")) {
421 return;
422 }
423
424 var setSwitch = function () {
425 showLoading('waiting');
426 var wifiParam = {};
427 wifiParam.m_ssid_enable = target.multi_ssid_enable();
428 if (config.WIFI_SWITCH_SUPPORT) {
429 wifiParam.wifiEnabled = target.wifi_enable();
430 }
431 service.setWifiBasicMultiSSIDSwitch(wifiParam, function (result) {
432 if (result.result == "success") {
433 if (viaWifi) {
434 setTimeout(hasApReloadVarWifi, 15000);
435 } else {
436 addInterval(hasApReload, 1000);
437 }
438 } else {
439 errorOverlay();
440 }
441 });
442 };
443
444 var baseInfo = service.getStatusInfo();
445 if (config.HAS_MULTI_SSID && target.wifi_enable() == "1") {
446 if (target.multi_ssid_enable() == "1" && config.AP_STATION_SUPPORT && target.origin_ap_station_enable == "1") {
447 if (!baseInfo.wifiStatus) {
448 showConfirm("multi_ssid_enable_confirm", function () {
449 setSwitch();
450 });
451 } else {
452 showConfirm("multi_ssid_enable_confirm2", function () {
453 setSwitch();
454 });
455 }
456 } else {
457 if (!baseInfo.wifiStatus) {
458 setSwitch();
459 } else {
460 showConfirm("wifi_disconnect_confirm2", function () {
461 setSwitch();
462 });
463 }
464 }
465 } else {
466 setSwitch();
467 }
468
469 function hasApReloadVarWifi() {
470 successOverlay();
471 setTimeout(function () {
472 window.location.reload();
473 }, 1000);
474 clearTimer();
475 clearValidateMsg();
476 service.refreshAPStationStatus();
477 initialize();
478 }
479 function hasApReload() {
480 var baseInfo = service.getWifiBasic();
481 if (baseInfo.wifi_enable == target.wifi_enable()) {
482 successOverlay();
483 clearTimer();
484 clearValidateMsg();
485 service.refreshAPStationStatus();
486 initialize();
487 }
488 }
489
490 };
491
492 }
493
494 function checkAccessMode() {
495 service.getParams({
496 nv: 'user_ip_addr'
497 }, function (dataIp) {
498 service.getParams({
499 nv: 'station_list'
500 }, function (dataList) {
501 viaWifi = isWifiConnected(dataIp.user_ip_addr, dataList.station_list);
502 });
503 });
504 }
505
506 function advanceReloadVarWifi() {
507 successOverlay();
508 setTimeout(function () {
509 window.location.reload();
510 }, 1000);
511 }
512
513 function advanceReload() {
514 var baseInfo = service.getWifiBasic();
515 if (baseInfo.wifi_enable == "1") {
516 successOverlay();
517 clearTimer();
518 clearValidateMsg();
519 initialize();
520 }
521 }
522
523 function initialize() {
524 var container = $('#container');
525 ko.cleanNode(container[0]);
526 var vm = new WifiAdvanceViewModel();
527 ko.applyBindings(vm, container[0]);
528 addTimeout(function () {
529 checkAccessMode();
530 }, 600);
531
532 if (config.WDS_SUPPORT) {
533 checkWifiStatusUseWDS();
534 } else if (config.AP_STATION_SUPPORT) {
535 checkWifiStatus();
536 }
537
538 $('#wifi_advance_form').validate({
539 submitHandler: function () {
540 vm.save();
541 }
542 });
543
544 $('#frmWifiSwitch').validate({
545 submitHandler: function () {
546 vm.setMultiSSIDSwitch();
547 }
548 });
549 }
550
551 function checkWifiStatusUseWDS() {
552 var baseInfo = service.getWdsInfo();
553 if (baseInfo.currentMode == "0") {
554 $(':input', '#frmWifiSwitch,#wifi_advance_form').each(function () {
555 $(this).prop("disabled", false);
556 });
557 } else {
558 $(':input', '#frmWifiSwitch,#wifi_advance_form').each(function () {
559 $(this).prop("disabled", true);
560 });
561 }
562 }
563
564 function checkWifiStatus() {
565 var baseInfo = service.getAPStationBasic();
566 if (baseInfo.ap_station_enable != "1") {
567 $(':input', '#wifi_advance_form').each(function () {
568 $(this).prop("disabled", false);
569 });
570 } else {
571 $(':input', '#wifi_advance_form').each(function () {
572 $(this).prop("disabled", true);
573 });
574 }
575 }
576
577 return {
578 init: initialize
579 };
580});
581
582define("wifi_ap_station","underscore jquery knockout set service".split(" "),
583 function (_, $, ko, config, service) {
584 var viaWifi = false;
585 function checkAccessMode() {
586 service.getParams({
587 nv: 'user_ip_addr'
588 }, function (dataIp) {
589 service.getParams({
590 nv: 'station_list'
591 }, function (dataList) {
592 viaWifi = isWifiConnected(dataIp.user_ip_addr, dataList.station_list);
593 });
594 });
595 }
596
597 function apStationViewMode() {
598 var target = this;
599 var ssid_ex = "";
600 target.hasMultiSSID = config.HAS_MULTI_SSID;
601 target.hasAPStation = config.AP_STATION_SUPPORT;
602 target.hasWifiSwitch = config.WIFI_SWITCH_SUPPORT;
603 target.hasWlanMacfilter = config.HAS_BLACK_AND_WHITE_FILTER;
604
605 var securityModes = _.map(config.AUTH_MODES_ALL, function (item) {
606 return new Option(item.name, item.value);
607 });
608 //当前页面标识 list列表页 add添加页面 edit编辑页面
609 target.page = {
610 list: 1,
611 add: 2,
612 edit: 3
613 };
614 //WiFi热点列表列的配置项
615 var gridColumn = [{
616 columnType: "radio",
617 headerTextTrans: "option",
618 rowText: "profileName",
619 width: "10%"
620 }, {
621 headerTextTrans: "ssid_title",
622 rowText: "ssid",
623 width: "30%"
624 }, {
625 columnType: "image",
626 headerTextTrans: "signal",
627 rowText: "imgSignal",
628 width: "30%"
629 }, {
630 headerTextTrans: "security_mode",
631 rowText: "authMode_show",
632 width: "30%"
633 }
634 ];
635 //搜索到的WiFi热点列表列的配置项
636 var searchGridColumn = [{
637 columnType: "radio",
638 rowText: "index",
639 width: "10%"
640 }, {
641 headerTextTrans: "ssid_title",
642 rowText: "ssid",
643 width: "30%"
644 }, {
645 columnType: "image",
646 headerTextTrans: "signal",
647 rowText: "imgSignal",
648 width: "30%"
649 }, {
650 headerTextTrans: "security_mode",
651 rowText: "authMode_show",
652 width: "30%"
653 }
654 ];
655
656 target.pageState = ko.observable(target.page.list);
657
658 var info = service.getAPStationBasic();
659
660 target.origin_ap_station_enable = info.ap_station_enable;
661 target.ap_station_enable = ko.observable(info.ap_station_enable);
662 target.apList = ko.observable([]);
663 if (target.origin_ap_station_enable == "1") {
664 var apList = service.getHotspotList();
665 target.apList(fixHotspotList(apList.hotspotList));
666 }
667
668 target.apSearchList = ko.observable([]);
669
670 target.connectButtonStatus = ko.observable("disable");
671 target.hasSelectFromUser = ko.observable();
672 target.showPassword = ko.observable(false);
673
674 target.isCableMode = ko.observable();
675
676 var infoBasic = service.getWifiBasic();
677 target.wifi_enable = ko.observable(infoBasic.wifi_enable);
678
679 target.isShowSSIDInfoDiv = ko.observable(false);
680 if (config.WIFI_SWITCH_SUPPORT) {
681 if (infoBasic.wifi_enable == "1") {
682 target.isShowSSIDInfoDiv(true);
683 } else {
684 target.isShowSSIDInfoDiv(false);
685 }
686 } else {
687 target.isShowSSIDInfoDiv(true);
688 }
689 target.multi_ssid_enable = ko.observable(infoBasic.multi_ssid_enable);
690
691 //密码显示事件
692 target.showPasswordHandler = function () {
693 $("#codeWPAKey").parent().find(".error").hide();
694 $("#pwdWepKey").parent().find(".error").hide();
695 var checkbox = $("#showPassword:checked");
696 if (checkbox && checkbox.length == 0) {
697 target.showPassword(true);
698 } else {
699 target.showPassword(false);
700 }
701 };
702
703 target.showWPAPasswordHandler = function () {
704 $("#codeWPAKey").parent().find(".error").hide();
705 $("#pwdWepKey").parent().find(".error").hide();
706 if ($("#showWPAPassword").is(":checked")) {
707 target.showPassword(true);
708 } else {
709 target.showPassword(false);
710 }
711 };
712
713 //列表模板创建
714 target.apGrid = new ko.simpleGrid.viewModel({
715 idName: "profileName",
716 data: target.apList(),
717 tmplType: 'list',
718 pageSize: 100,
719 columns: gridColumn,
720 primaryColumn: "fromProvider",
721 radioClickHandler: function () {
722 computeButtonState();
723 }
724 });
725 //热点搜索结果列表模板创建
726 target.apSearchGrid = new ko.simpleGrid.viewModel({
727 data: target.apSearchList(),
728 idName: "index",
729 tmplType: 'list',
730 pageSize: 100,
731 columns: searchGridColumn,
732 radioClickHandler: function () {
733 var index = target.apSearchGrid.radioSelectValue();
734 var aplist = target.apSearchList();
735 for (var i = 0; i < aplist.length; i++) {
736 var list_item = aplist[i];
737 if (list_item.index == index) {
738 target.profileName("");
739 target.ssid(list_item.ssid);
740 ssid_ex = list_item.ssid;
741 target.signal(list_item.signal);
742 target.authMode(list_item.authMode);
743 target.password(list_item.password);
744 target.mac(list_item.mac);
745 if (list_item.authMode == "WPAPSKWPA2PSK" || list_item.authMode == "WPA2PSK" || list_item.authMode == "WPAPSK" || list_item.authMode == "WPA3Personal" || list_item.authMode == "WPA2WPA3") {
746 target.encryptType_WPA(list_item.encryptType);
747 } else {
748 target.encryptType(list_item.encryptType);
749 }
750 target.keyID(list_item.keyID);
751 renderCustomElement($("#cipherGroup"));
752 break;
753 }
754 }
755 }
756 });
757
758 //计算并设置当前连接和按钮的状态
759 target.computeConnectStatus = function () {
760 computeButtonState();
761
762 var networkStatus = target.connectStatus();
763 if (networkStatus == "ppp_connected") {
764 target.current_status_trans("ap_station_wan_connected");
765 target.current_status_text($.i18n.prop("ap_station_wan_connected"));
766 return;
767 }
768
769 var ssid = target.connectWifiSSID();
770 var wifiStatus = target.connectWifiStatus();
771 if (ssid && wifiStatus == "connect") {
772 target.current_status_trans("ap_station_wlan_connected");
773 target.current_status_text($.i18n.prop("ap_station_wlan_connected"));
774 return;
775 }
776
777 target.current_status_trans("ap_station_no_connection");
778 target.current_status_text($.i18n.prop("ap_station_no_connection"));
779 };
780 //计算并设置按钮的状态
781 function computeButtonState() {
782 var profileName = target.apGrid.radioSelectValue();
783 if (!profileName) {
784 target.hasSelectFromUser(false);
785 target.connectButtonStatus("disable");
786 return;
787 }
788
789 var status = "";
790 var fromProvider = "";
791 for (var i = 0; i < target.apList().length; i++) {
792 var list_item = target.apList()[i];
793 if (list_item.profileName == profileName) {
794 status = list_item.connectStatus;
795 fromProvider = list_item.fromProvider;
796 break;
797 }
798 }
799
800 if (status == "1") {
801 target.connectButtonStatus("hide");
802 target.hasSelectFromUser(false);
803 } else {
804 target.connectButtonStatus("show");
805 target.hasSelectFromUser(fromProvider == "0");
806 }
807 }
808 var statusInfo = service.getStatusInfo();
809 target.networkType = ko.observable(statusInfo.networkType);
810 target.networkOperator = ko.observable(statusInfo.networkOperator);
811 target.connectStatus = ko.observable(statusInfo.connectStatus);
812 target.connectWifiStatus = ko.observable(statusInfo.connectWifiStatus);
813 target.connectWifiProfile = ko.observable(statusInfo.connectWifiProfile);
814 target.connectWifiSSID = ko.observable(statusInfo.connectWifiSSID);
815
816 target.current_status_trans = ko.observable("");
817 target.current_status_text = ko.observable("");
818 target.current_status = ko.computed(function () {
819 target.computeConnectStatus()
820 });
821
822 target.modes = securityModes;
823 target.profileName = ko.observable("");
824 target.ssid = ko.observable();
825 target.signal = ko.observable("0");
826 target.authMode = ko.observable();
827 target.password = ko.observable();
828 target.encryptType = ko.observable();
829 target.encryptType_WPA = ko.observable("TKIPCCMP");
830 target.keyID = ko.observable("0");
831 target.mac = ko.observable();
832
833 target.openAddPage = function () {
834 if (wifiIsClosed()) {
835 return;
836 }
837 if (wpsIsOn()) {
838 return;
839 }
840 target.clear();
841 getSearchHotspot();
842 };
843
844 //打开基本设置页面
845 target.openListPage = function () {
846 if (wifiIsClosed()) {
847 return;
848 }
849 if (wpsIsOn()) {
850 return;
851 }
852 target.clear();
853 target.pageState(target.page.list);
854 target.apGrid.data(target.apList());
855 v.computeConnectStatus();
856 };
857
858 target.addHotspot = function () {
859 if (wifiIsClosed()) {
860 return;
861 }
862 if (wpsIsOn()) {
863 return;
864 }
865 if (target.pageState() == target.page.add && target.apList().length >= config.AP_STATION_LIST_LENGTH) {
866 showAlert({
867 msg: "ap_station_exceed_list_max",
868 params: config.AP_STATION_LIST_LENGTH
869 });
870 return;
871 }
872 showLoading('waiting');
873 var wifi_para = {};
874 var profileName = target.apGrid.radioSelectValue();
875 wifi_para.profileName = target.profileName();
876 wifi_para.ssid = target.ssid();
877 wifi_para.signal = target.signal();
878 wifi_para.authMode = target.authMode();
879 wifi_para.password = target.password();
880 if (wifi_para.authMode == "SHARED") {
881 wifi_para.encryptType = "WEP";
882 } else if (wifi_para.authMode == "WPAPSKWPA2PSK" || wifi_para.authMode == "WPA2PSK" || wifi_para.authMode == "WPAPSK" || wifi_para.authMode == "WPA3Personal" || wifi_para.authMode == "WPA2WPA3") {
883 wifi_para.encryptType = target.encryptType_WPA();
884 } else {
885 wifi_para.encryptType = target.encryptType();
886 }
887 wifi_para.keyID = target.keyID();
888 wifi_para.mac = (target.mac() == "" || target.ssid() != ssid_ex) ? "0F:00:00:00:00:00" : target.mac();
889 wifi_para.apList = target.apList();
890 service.saveHotspot(wifi_para, function (data) {
891 target.callback(data, true);
892 });
893 };
894
895 target.deleteHotspot = function () {
896 if (wifiIsClosed()) {
897 return;
898 }
899 if (wpsIsOn()) {
900 return;
901 }
902 showConfirm("confirm_data_delete", function () {
903 var wifi_para = {};
904 wifi_para.profileName = target.apGrid.radioSelectValue();
905 wifi_para.apList = target.apList();
906 showLoading('waiting');
907 service.deleteHotspot(wifi_para, function (data) {
908 target.callback(data, true);
909 });
910 });
911 };
912
913 target.openEditPage = function () {
914 if (wifiIsClosed()) {
915 return;
916 }
917 if (wpsIsOn()) {
918 return;
919 }
920 var profileName = target.apGrid.radioSelectValue();
921 var aplist = target.apList();
922 for (var i = 0; i < aplist.length; i++) {
923 var list_item = aplist[i];
924 if (list_item.profileName == profileName) {
925 target.profileName(profileName);
926 target.ssid(list_item.ssid);
927 target.signal(list_item.signal);
928 target.authMode(list_item.authMode);
929 target.password(list_item.password);
930 target.mac(list_item.mac);
931 if (list_item.authMode == "WPAPSKWPA2PSK" || list_item.authMode == "WPA2PSK" || list_item.authMode == "WPAPSK" || list_item.authMode == "WPA3Personal" || list_item.authMode == "WPA2WPA3") {
932 target.encryptType_WPA(list_item.encryptType);
933 } else {
934 target.encryptType(list_item.encryptType);
935 }
936 target.keyID(list_item.keyID);
937 }
938 }
939 target.pageState(target.page.edit);
940 };
941
942 target.connectHotspot = function () {
943 if (wifiIsClosed()) {
944 return;
945 }
946 if (wpsIsOn()) {
947 return;
948 }
949 var profileName = target.apGrid.radioSelectValue();
950 var apList = target.apList();
951
952 function connect() {
953 showLoading("connecting");
954 var wifi_para = {};
955 var connectIndex = -1;
956 var ssid = "";
957 for (var i = 0; i < apList.length; i++) {
958 if (apList[i].profileName == profileName) {
959
960 wifi_para.EX_SSID1 = apList[i].ssid;
961 wifi_para.EX_AuthMode = apList[i].authMode;
962 wifi_para.EX_EncrypType = apList[i].encryptType;
963 wifi_para.EX_DefaultKeyID = apList[i].keyID;
964 wifi_para.EX_WEPKEY = apList[i].password;
965 wifi_para.EX_WPAPSK1 = apList[i].password;
966 wifi_para.EX_wifi_profile = apList[i].profileName;
967 wifi_para.EX_mac = apList[i].mac;
968 connectIndex = i;
969 ssid = apList[i].ssid;
970 break;
971 }
972 }
973
974 target.connectWifiSSID(ssid);
975 target.connectWifiStatus("connecting");
976 target.apGrid.setRadioSelect(profileName);
977 target.connectButtonStatus("disable");
978
979 service.connectHotspot(wifi_para, function (data) {
980 if (data && data.result == "success") {
981 target.connectButtonStatus("disable");
982 //延迟检测 确保取得的状态是最新的
983 addTimeout(checkWifiStatus, 3000);
984 } else if (data && data.result == "processing") {
985 showAlert("ap_station_processing");
986 } else {
987 var apList = target.apList(); // cov_2
988 apList[connectIndex].connectStatus = "0";
989 target.connectWifiStatus("disconnect");
990 target.connectButtonStatus("show");
991 hideLoading();
992 errorOverlay();
993 }
994 var apList = service.getHotspotList();
995 target.apList(fixHotspotList(apList.hotspotList));
996 target.connectWifiProfile(profileName);
997 target.connectWifiSSID(ssid);
998 target.apGrid.data([]);
999 target.apGrid.data(target.apList());
1000 target.apGrid.setRadioSelect(profileName);
1001 });
1002 }
1003
1004 //将用户选中的profile排在运营商定制profile后的第一位
1005 function refreshApList(profile, aplist) {
1006 var apListLeft = [];
1007 var apListPre = [];
1008 for (var i = 0; i < aplist.length; i++) {
1009 if (aplist[i].fromProvider != "1") {
1010 if (aplist[i].profileName == profile) {
1011 apListPre.push(apList[i]);
1012 } else {
1013 apListLeft.push(apList[i]);
1014 }
1015 } else {
1016 apListPre.push(apList[i]);
1017 }
1018 }
1019 var apListNew = apListPre.concat(apListLeft);
1020 service.saveHotspot({
1021 apList: apListNew
1022 }, function (data) {
1023 if (data && data.result == "success") {
1024 apList = apListNew;
1025 target.apList(fixHotspotList(apList));
1026 }
1027 });
1028 }
1029
1030 var check_count = 0;
1031 var connectStatus = false;
1032
1033 var status = service.getStatusInfo();
1034 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
1035 showConfirm("ap_station_connect_change_alert", function () {
1036 showLoading();
1037 connect();
1038 });
1039 } else {
1040 connect();
1041 }
1042
1043 function checkWifiStatus() {
1044 check_count = check_count + 1;
1045 if (check_count > 60) {
1046 hideLoading();
1047 errorOverlay();
1048 return;
1049 }
1050 if (!connectStatus) {
1051 var status = service.getStatusInfo();
1052 if (status.connectWifiStatus != "connect") {
1053 addTimeout(checkWifiStatus, 1000);
1054 } else {
1055 connectStatus = true;
1056 }
1057 }
1058 if (connectStatus) {
1059 //继续判断profile中连接状态是否为1
1060 service.getHotspotList({}, function (data) {
1061 for (var i = 0, len = data.hotspotList.length; i < len; i++) {
1062 var list_item = data.hotspotList[i];
1063 if (list_item.profileName == profileName) {
1064 if (list_item.connectStatus == "1") {
1065 hideLoading();
1066 return;
1067 } else {
1068 var errorMsg = {
1069 msg: 'ap_connect_error',
1070 params: [list_item.ssid]
1071 };
1072 showAlert(errorMsg);
1073 return;
1074 }
1075 break;
1076 }
1077 }
1078 addTimeout(checkWifiStatus, 1000);
1079 });
1080 }
1081 }
1082
1083 };
1084
1085 target.disconnectHotspot = function () {
1086 if (wpsIsOn()) {
1087 return;
1088 }
1089 showLoading('disconnecting');
1090 service.disconnectHotspot({}, function (data) {
1091 target.callback(data, true);
1092 })
1093 };
1094
1095 function getSearchHotspot() {
1096 var check_count = 0;
1097
1098 function search() {
1099 var result = service.getSearchHotspotList();
1100 if (result.scan_finish == "0") {
1101 if (check_count <= 60) {
1102 check_count = check_count + 1;
1103 addTimeout(search, 1000);
1104 } else {
1105 hideLoading();
1106 showAlert("ap_station_search_hotspot_fail");
1107 }
1108 } else {
1109 if ("2" == result.scan_finish) {
1110 hideLoading();
1111 showAlert("ap_station_processing");
1112 } else {
1113 target.apSearchList(fixHotspotList(result.hotspotList));
1114 target.apSearchGrid.data(target.apSearchList());
1115 hideLoading();
1116 }
1117 }
1118 }
1119
1120 showLoading('scanning');
1121 service.searchHotspot({}, function (data) {
1122 if (data && data.result == "processing") {
1123 hideLoading();
1124 showAlert("ap_station_processing");
1125 } else if (data && data.result == "success") {
1126 if (target.pageState() != target.page.add) {
1127 target.pageState(target.page.add);
1128 }
1129 search();
1130 } else {
1131 if (target.pageState() != target.page.add) {
1132 target.pageState(target.page.add);
1133 }
1134 hideLoading();
1135 showAlert("ap_station_search_hotspot_fail");
1136 }
1137 });
1138 }
1139
1140 //清除编辑页面的信息
1141 target.clear = function () {
1142 target.apSearchGrid.clearRadioSelect();
1143 target.profileName("");
1144 target.ssid("");
1145 target.signal("0");
1146 target.authMode("OPEN");
1147 target.password("");
1148 target.encryptType("NONE");
1149 target.encryptType_WPA("TKIPCCMP");
1150 target.keyID("0");
1151 target.mac("");
1152 };
1153
1154 target.apply = function () {
1155 if (wifiIsClosed()) {
1156 return;
1157 }
1158 if (wpsIsOn()) {
1159 return;
1160 }
1161
1162 function setBasic() {
1163 showLoading('waiting');
1164 var wifi_para = {};
1165 wifi_para.ap_station_enable = target.ap_station_enable();
1166 service.setAPStationBasic(wifi_para, function (data) {
1167 if (target.origin_ap_station_enable == target.ap_station_enable()) {
1168 target.callback(data, true);
1169 } else {
1170 target.callback2(data, true);
1171 }
1172 });
1173 service.refreshAPStationStatus();
1174 }
1175 if (!config.HAS_MULTI_SSID) {
1176 setBasic();
1177 } else {
1178 var infoBasic = service.getWifiBasic();
1179 if (target.ap_station_enable() == "1" && infoBasic.multi_ssid_enable == "1") {
1180 showConfirm("ap_station_enable_confirm", setBasic);
1181 } else {
1182 setBasic();
1183 }
1184 }
1185 };
1186 //刷新搜到的热点列表
1187 target.searchHotspot = function () {
1188 if (wifiIsClosed()) {
1189 return;
1190 }
1191 if (wpsIsOn()) {
1192 return;
1193 }
1194 getSearchHotspot();
1195 };
1196 //和webserver交互时的回调,wifi不重启的情况
1197 target.callback = function (data, isInitPage) {
1198 if (data) {
1199 if (isInitPage) {
1200 initialize();
1201 $("#apList").translate();
1202 }
1203 if (data.result == "processing") {
1204 showAlert("ap_station_processing");
1205 } else if (data.result == "spot_connected" || data.result == "spot_connecting") {
1206 showAlert("ap_station_update_fail");
1207 } else if (data.result == "success") {
1208 successOverlay();
1209 } else if (data.result == "exist") {
1210 showAlert("ap_station_exist");
1211 } else {
1212 errorOverlay();
1213 }
1214 } else {
1215 errorOverlay();
1216 }
1217 }
1218
1219 //和webserver交互时的回调,wifi会重启的情况
1220 target.callback2 = function (data, isInitPage) {
1221 if (data) {
1222 if (!viaWifi) { //通过wifi登录webui
1223 addInterval(function () {
1224 var info = service.getWifiBasic();
1225 if (info.wifi_enable == "1") {
1226 clearTimer();
1227 clearValidateMsg();
1228 initialize();
1229 $("#apList").translate();
1230 if (data.result == "spot_connected" || data.result == "spot_connecting") {
1231 showAlert("ap_station_update_fail");
1232 } else if (data.result == "success") {
1233 successOverlay();
1234 } else {
1235 errorOverlay();
1236 }
1237 }
1238 }, 1000);
1239 } else {
1240 setTimeout(function () {
1241 if (data.result == "processing") {
1242 showAlert("ap_station_processing");
1243 } else if (data.result == "spot_connecting" || data.result == "spot_connected") {
1244 showAlert("ap_station_update_fail");
1245 } else if (data.result == "success") {
1246 successOverlay();
1247 setTimeout(function () {
1248 window.location.reload();
1249 }, 1000);
1250 clearTimer();
1251 clearValidateMsg();
1252 initialize();
1253 } else {
1254 errorOverlay();
1255 }
1256 }, 15000);
1257 }
1258 } else {
1259 errorOverlay();
1260 }
1261 };
1262
1263 target.checkSettings = function (ssid) {
1264 var status = service.getWpsInfo();
1265 if (status.wpsFlag == '1') {
1266 showAlert('wps_on_info', function() {
1267 window.location.reload();
1268 });
1269 return true;
1270 }
1271 if (config.HAS_MULTI_SSID && info.multi_ssid_enable == "1") {
1272 if ((ssid == "ssid1" && parseInt(target.selectedStation()) + parseInt(info.m_MAX_Access_num) > info.MAX_Station_num)
1273 || (ssid == "ssid2" && parseInt(target.m_selectedStation()) + parseInt(info.MAX_Access_num) > info.MAX_Station_num)) {
1274 showAlert({
1275 msg: 'multi_ssid_max_access_number_alert',
1276 params: info.MAX_Station_num
1277 });
1278 return true;
1279 }
1280 }
1281
1282 return false;
1283 };
1284
1285 target.setMultiSSIDSwitch = function () {
1286 if (target.checkSettings("switch")) {
1287 return;
1288 }
1289
1290 var setSwitch = function () {
1291 showLoading('waiting');
1292 var params = {};
1293 params.m_ssid_enable = target.multi_ssid_enable();
1294 if (config.WIFI_SWITCH_SUPPORT) {
1295 params.wifiEnabled = target.wifi_enable();
1296 }
1297 service.setWifiBasicMultiSSIDSwitch(params, function (result) {
1298 if (result.result == "success") {
1299 if (!viaWifi) {
1300 addInterval(function () {
1301 var info = service.getWifiBasic();
1302 if (info.wifi_enable == target.wifi_enable()) {
1303 successOverlay();
1304 clearTimer();
1305 clearValidateMsg();
1306 service.refreshAPStationStatus();
1307 initialize();
1308 }
1309 }, 1000);
1310 } else {
1311 setTimeout(function () {
1312 successOverlay();
1313 setTimeout(function () {
1314 window.location.reload();
1315 }, 1000);
1316 clearTimer();
1317 clearValidateMsg();
1318 service.refreshAPStationStatus();
1319 initialize();
1320 }, 15000);
1321 }
1322 } else {
1323 errorOverlay();
1324 }
1325 });
1326 };
1327
1328 var info = service.getStatusInfo();
1329 if (config.HAS_MULTI_SSID && target.wifi_enable() == "1") {
1330 if (target.multi_ssid_enable() == "1" && config.AP_STATION_SUPPORT && target.origin_ap_station_enable == "1") {
1331 if (!info.wifiStatus) {
1332 showConfirm("multi_ssid_enable_confirm", function () {
1333 setSwitch();
1334 });
1335 } else {
1336 showConfirm("multi_ssid_enable_confirm2", function () {
1337 setSwitch();
1338 });
1339 }
1340 } else {
1341 if (!info.wifiStatus) {
1342 setSwitch();
1343 } else {
1344 showConfirm("wifi_disconnect_confirm2", function () {
1345 setSwitch();
1346 });
1347 }
1348 }
1349 } else {
1350 setSwitch();
1351 }
1352 };
1353
1354 }
1355
1356 function wpsIsOn() {
1357 var wifi_info = service.getWpsInfo();
1358 if (wifi_info.wpsFlag == '1') {
1359 showAlert('wps_on_info', function() {
1360 window.location.reload();
1361 });
1362 return true;
1363 }
1364 }
1365
1366 //处理热点列表内容,以便在表格显示
1367 function fixHotspotList(list) {
1368 var fixedList = [];
1369 for (var ii = 0; ii < list.length; ii++) {
1370 list[ii].index = ii;
1371 var url_image = "";
1372 if (list[ii].connectStatus != "1") {
1373 if (list[ii].encryptType.toLowerCase() == "none" && list[ii].authMode.toLowerCase() == "open") {
1374 url_image = "pic/wlan_signal_" + list[ii].signal + ".png";
1375 } else {
1376 url_image = "pic/wlan_lock_signal_" + list[ii].signal + ".png";
1377 }
1378 } else {
1379 if (list[ii].encryptType.toLowerCase() == "none" && list[ii].authMode.toLowerCase() == "open") {
1380 url_image = "pic/wlan_connected.png";
1381 } else {
1382 url_image = "pic/wlan_lock_connected.png";
1383 }
1384 }
1385 list[ii].imgSignal = url_image;
1386 list[ii].authMode_show = $.i18n.prop("ap_station_security_mode_" + list[ii].authMode);
1387 }
1388 return list;
1389 }
1390
1391 function wifiIsClosed() {
1392 var wifi_info = service.getWpsInfo();
1393 if (wifi_info.radioFlag == "0") {
1394 showAlert('wps_wifi_off');
1395 return true;
1396 }
1397 }
1398
1399 function event_bind(aps_vm) {
1400 $("#showWPAPassword").change(function () {
1401 aps_vm.showWPAPasswordHandler();
1402 });
1403 $("#showPassword").change(function () {
1404 aps_vm.showPasswordHandler();
1405 });
1406 }
1407
1408 function initialize() {
1409 var aps_vm = new apStationViewMode();
1410 var container = $('#container')[0];
1411 ko.cleanNode(container);
1412 ko.applyBindings(aps_vm, container);
1413 event_bind(aps_vm);
1414
1415 aps_refresh(true);
1416 clearTimer();
1417 addInterval(function () {
1418 aps_refresh(false);
1419 checkAccessMode();
1420 }, 1000);
1421
1422 $('#frmWifiSwitch').validate({
1423 submitHandler: function () {
1424 aps_vm.setMultiSSIDSwitch();
1425 }
1426 });
1427
1428 $("#frmAPStation").validate({
1429 submitHandler: function () {
1430 aps_vm.addHotspot();
1431 },
1432 rules: {
1433 txtSSID: "ssid_ap"
1434 },
1435 errorPlacement: function (error, element) {
1436 var id = element.attr("id");
1437 if (id == "txtWPAKey" || id == "codeWPAKey") {
1438 error.insertAfter("#lblshowWPAPassword");
1439 } else if (id == "txtWepKey" || id == "pwdWepKey") {
1440 error.insertAfter("#lblShowPassword");
1441 } else {
1442 error.insertAfter(element);
1443 }
1444 }
1445 });
1446
1447 function aps_refresh(initPage) {
1448 var info = service.getStatusInfo();
1449 if (info.multi_ssid_enable != "1") {
1450 aps_vm.isCableMode(checkCableMode(info.blc_wan_mode));
1451 aps_vm.connectWifiProfile(info.connectWifiProfile);
1452 aps_vm.connectWifiSSID(info.connectWifiSSID);
1453 aps_vm.connectWifiStatus(info.connectWifiStatus);
1454 aps_vm.networkType(info.networkType);
1455 aps_vm.connectStatus(info.connectStatus);
1456 aps_vm.computeConnectStatus();
1457
1458 service.getHotspotList({}, function (data) {
1459 var list = fixHotspotList(data.hotspotList);
1460 aps_vm.apList(list);
1461 var gripList = aps_vm.apGrid.data();
1462 if (list.length > 0 && list[0].profileName != gripList[0].profileName && list[0].connectStatus == "1") {
1463 aps_vm.apGrid.data([]);
1464 aps_vm.apGrid.data(aps_vm.apList());
1465 aps_vm.apGrid.setRadioSelect(list[0].profileName);
1466 }
1467 renderCustomElement($("#apList"));
1468 var radios = $("input[type='radio']", "#apList").each(function () {
1469 for (var i = 0, len = list.length; i < len; i++) {
1470 if (list[i].profileName == $(this).val()) {
1471 var img = $(this).parent().parent().find("img")[0];
1472 img.src = list[i].imgSignal;
1473 if (initPage) {
1474 if (list[i].connectStatus == "1") {
1475 aps_vm.hasSelectFromUser(false);
1476 aps_vm.connectButtonStatus("disable");
1477 }
1478 }
1479 }
1480 }
1481 });
1482 });
1483 } else {
1484 //to do
1485 }
1486 }
1487
1488 }
1489
1490 return {
1491 init: initialize
1492 }
1493});
1494
1495define("wifi_guest","underscore jquery knockout set service CryptoJS".split(" "),
1496
1497 function (_, $, ko, config, service, CryptoJS) {
1498
1499 var viaWifi = false;
1500 function checkAccessMode() {
1501 service.getParams({
1502 nv: 'user_ip_addr'
1503 }, function (dataIp) {
1504 service.getParams({
1505 nv: 'station_list'
1506 }, function (dataList) {
1507 viaWifi = isWifiConnected(dataIp.user_ip_addr, dataList.station_list);
1508 });
1509 });
1510 }
1511
1512 var securityModes = _.map(config.WIFI_WEP_SUPPORT ? config.AUTH_MODES_WEP : config.AUTH_MODES, function (item) {
1513 return new Option(item.name, item.value);
1514 });
1515
1516 function maxStationAccess(max) {
1517 var showOption = [];
1518 for (var i = 1; i <= max; i++) {
1519 showOption.push(new Option(i, i));
1520 }
1521 return showOption;
1522 }
1523
1524 function wifiGuestVM() {
1525 var target = this;
1526 var info = service.getWifiBasic();
1527
1528 target.hasWifiSwitch = config.WIFI_SWITCH_SUPPORT;
1529 target.hasMultiSSID = config.HAS_MULTI_SSID;
1530 target.showIsolated = config.SHOW_WIFI_AP_ISOLATED;
1531 target.hasAPStation = config.AP_STATION_SUPPORT;
1532 target.hasWlanMacfilter = config.HAS_BLACK_AND_WHITE_FILTER;
1533 target.hasWifiWep = config.WIFI_WEP_SUPPORT;
1534 target.hasWifiWpa3 = config.WIFI_WAP3_SUPPORT;
1535 target.hasWifiWpa23 = config.WIFI_WPA2_WAP3_SUPPORT;
1536
1537 var advanceInfo = service.getWifiAdvance();
1538 target.adBand = ko.observable(advanceInfo.wifiBand);
1539 target.adMode = ko.observable(advanceInfo.mode);
1540
1541 target.showQRSwitch = config.WIFI_SUPPORT_QR_CODE && config.WIFI_SUPPORT_QR_SWITCH;
1542 target.showQR = ko.observable(info.m_show_qrcode_flag);
1543 if (config.WIFI_SUPPORT_QR_SWITCH) {
1544 target.showQRCode = ko.observable(config.WIFI_SUPPORT_QR_CODE && target.showQR());
1545 } else {
1546 target.showQRCode = ko.observable(config.WIFI_SUPPORT_QR_CODE);
1547 }
1548 if(config.WIFI_SUPPORT_QR_CODE){
1549 target.qrcodeSrc = './pic/qrcode_multi_ssid_wifikey.png?_=' + $.now();
1550 } else {
1551 target.qrcodeSrc = './pic/res_blacktrans.png';
1552 }
1553 target.origin_ap_station_enable = info.ap_station_enable;
1554 target.wifi_enable = ko.observable(info.wifi_enable);
1555 target.isShowSSIDInfoDiv = ko.observable(false);
1556 if (config.WIFI_SWITCH_SUPPORT) {
1557 if (info.wifi_enable == "1") {
1558 target.isShowSSIDInfoDiv(true);
1559 } else {
1560 target.isShowSSIDInfoDiv(false);
1561 }
1562 } else {
1563 target.isShowSSIDInfoDiv(true);
1564 }
1565
1566 target.multi_ssid_enable = ko.observable(info.multi_ssid_enable);
1567 target.origin_multi_ssid_enable = info.multi_ssid_enable;
1568
1569 target.maxStationNumber = ko.computed(function () {
1570 return config.MAX_STATION_NUMBER;
1571 });
1572
1573 target.modes = ko.observableArray(securityModes);
1574 target.selectedMode = ko.observable(info.AuthMode);
1575 target.passPhrase = ko.observable(info.passPhrase);
1576 target.showPassword = ko.observable(false);
1577 target.ssid = ko.observable(info.SSID);
1578 target.broadcast = ko.observable(info.broadcast == '1' ? '1' : '0');
1579 target.apIsolation = ko.observable(info.apIsolation == '1' ? '1' : '0');
1580 target.cipher = info.cipher;
1581 target.selectedStation = ko.observable(info.MAX_Access_num);
1582 target.maxStations = ko.observableArray(maxStationAccess(info.MAX_Station_num));
1583
1584 target.m_modes = ko.observableArray(securityModes);
1585 target.m_selectedMode = ko.observable(info.m_AuthMode);
1586 target.m_passPhrase = ko.observable(info.m_passPhrase);
1587 target.m_showPassword = ko.observable(false);
1588 target.m_ssid = ko.observable(info.m_SSID);
1589 target.m_broadcast = ko.observable(info.m_broadcast == '1' ? '1' : '0');
1590 target.m_apIsolation = ko.observable(info.m_apIsolation == '1' ? '1' : '0');
1591 target.m_cipher = info.m_cipher;
1592 target.m_selectedStation = ko.observable(info.m_MAX_Access_num);
1593 target.m_maxStations = ko.observableArray(maxStationAccess(info.MAX_Station_num));
1594 target.m_encryptType = ko.observable(info.m_encryptType);
1595 target.m_keyID = ko.observable(info.m_keyID);
1596 target.m_wepPassword = ko.observable("");
1597
1598 //刷新界面状态值显示
1599 target.clear = function (option) {
1600 if (option == "switch") {
1601 target.multi_ssid_enable(info.multi_ssid_enable);
1602 target.wifi_enable(info.wifi_enable);
1603 } else if (option == "ssid1") {
1604 target.selectedMode(info.AuthMode);
1605 target.passPhrase(info.passPhrase);
1606 target.ssid(info.SSID);
1607 target.broadcast(info.broadcast == '1' ? '1' : '0');
1608 target.cipher = info.cipher;
1609 target.selectedStation(info.MAX_Access_num);
1610 target.apIsolation(info.apIsolation == '1' ? '1' : '0');
1611 } else if (option == "ssid2") {
1612 target.m_selectedMode(info.m_AuthMode);
1613 target.m_passPhrase(info.m_passPhrase);
1614 target.m_ssid(info.m_SSID);
1615 target.m_broadcast(info.m_broadcast == '1' ? '1' : '0');
1616 target.m_cipher = info.m_cipher;
1617 target.m_selectedStation(info.m_MAX_Access_num);
1618 target.m_apIsolation(info.m_apIsolation == '1' ? '1' : '0');
1619 if (config.WIFI_WEP_SUPPORT) {
1620 target.m_encryptType(info.m_encryptType);
1621 target.m_keyID(info.m_keyID);
1622 target.m_wepPassword(target.getWepPassword());
1623 }
1624 } else {
1625 clearTimer();
1626 clearValidateMsg();
1627 initialize();
1628 service.refreshAPStationStatus();
1629 }
1630 };
1631
1632 target.getWepPassword = function () {
1633 return target.m_keyID() == '3' ? info.m_Key4Str1 : (target.m_keyID() == '2' ? info.m_Key3Str1 : target.m_keyID() == '1' ? info.m_Key2Str1 : info.m_Key1Str1);
1634 }
1635 target.m_wepPassword(target.getWepPassword());
1636 //WEP加密模式下网络秘钥切换事件
1637 target.profileChangeHandler = function (data, event) {
1638 $("#pwdWepKey").parent().find("label[class='error']").hide();
1639 target.m_wepPassword(target.getWepPassword());
1640 return true;
1641 };
1642
1643 target.saveSSID1 = function () {
1644 if (target.checkSettings("ssid1")) {
1645 return;
1646 }
1647 showConfirm('wifi_disconnect_confirm', function () {
1648 target.saveSSID1Action();
1649 });
1650 };
1651 target.saveSSID1Action = function () {
1652 showLoading('waiting');
1653 target.broadcast($("#broadcastCheckbox:checked").length > 0 ? '0' : '1');
1654 target.apIsolation($("#apisolatedCheckbox:checked").length);
1655 var params = {};
1656 params.AuthMode = target.selectedMode();
1657 params.passPhrase = target.passPhrase();
1658 params.SSID = target.ssid();
1659 params.broadcast = target.broadcast();
1660 params.station = target.selectedStation();
1661 params.cipher = target.selectedMode() == "WPA2PSK" ? 1 : 2;
1662 if (params.AuthMode == "WPA3Personal" || params.AuthMode == "WPA2WPA3") {
1663 params.cipher = 1;
1664 }
1665 params.NoForwarding = target.apIsolation();
1666 params.show_qrcode_flag = target.showQR() == true ? 1 : 0;
1667 service.setWifiBasic(params, function (result) {
1668 if (result.result == "success") {
1669 if (viaWifi) {
1670 setTimeout(guestReloadVarWifi, 15000);
1671 } else {
1672 addInterval(guestReload, 1000);
1673 }
1674 } else {
1675 errorOverlay();
1676 }
1677 });
1678 };
1679
1680 target.saveSSID2 = function () {
1681 if (target.checkSettings("ssid2")) {
1682 return;
1683 }
1684 if (!config.PASSWORD_ENCODE) {
1685 var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,32}');
1686 if (!pwdRegex.test(target.m_passPhrase())) {
1687 showConfirm("password_note_too_low", function () {
1688 showConfirm('wifi_disconnect_confirm', function () {
1689 target.saveSSID2Action();
1690 return;
1691 });
1692 return;
1693 });
1694 return;
1695 }
1696 }
1697 showConfirm('wifi_disconnect_confirm', function () {
1698 target.saveSSID2Action();
1699 });
1700 };
1701 target.saveSSID2Action = function () {
1702 showLoading('waiting');
1703 target.m_broadcast($("#mBroadcastCheckbox:checked").length > 0 ? '0' : '1');
1704 target.m_apIsolation($("#mApIsolatedCheckbox:checked").length);
1705 var ciphertext = "";
1706 if (config.PASSWORD_ENCODE) {
1707 ciphertext = target.m_passPhrase();
1708 } else {
1709 var kparam = service.getDeviceInfoLow();
1710 var tkey = CryptoJS.enc.Latin1.parse(kparam.skey);
1711 var tiv = CryptoJS.enc.Latin1.parse(kparam.siv);
1712 ciphertext = CryptoJS.AES.encrypt(target.m_passPhrase(), tkey, {
1713 iv: tiv,
1714 mode: CryptoJS.mode.CBC,
1715 padding: CryptoJS.pad.ZeroPadding
1716 }).toString();
1717 }
1718 var params = {};
1719 params.m_AuthMode = target.m_selectedMode();
1720 params.m_passPhrase = ciphertext;
1721 params.m_SSID = target.m_ssid();
1722 params.m_broadcast = target.m_broadcast();
1723 params.m_station = target.m_selectedStation();
1724 params.m_cipher = target.m_selectedMode() == "WPA2PSK" ? 1 : 2;
1725 if (params.m_AuthMode == "WPA3Personal" || params.m_AuthMode == "WPA2WPA3") {
1726 params.m_cipher = 1;
1727 }
1728 params.m_NoForwarding = target.m_apIsolation();
1729 params.m_show_qrcode_flag = target.showQR() == true ? 1 : 0;
1730
1731 if (config.WIFI_WEP_SUPPORT) {
1732 if (params.m_AuthMode == "SHARED") {
1733 params.m_encryptType = "WEP";
1734 } else if (params.m_AuthMode == "WPAPSKWPA2PSK" || params.m_AuthMode == "WPA2PSK" || params.m_AuthMode == "WPAPSK" || params.m_AuthMode == "WPA3Personal" || params.m_AuthMode == "WPA2WPA3") {
1735 //params.m_encryptType = target.m_encryptType_WPA();
1736 } else {
1737 params.m_encryptType = target.m_encryptType();
1738 }
1739 params.m_wep_default_key = target.m_keyID();
1740 params.m_wep_key_4 = info.m_Key4Str1;
1741 params.m_wep_key_3 = info.m_Key3Str1;
1742 params.m_wep_key_2 = info.m_Key2Str1;
1743 params.m_wep_key_1 = info.m_Key1Str1;
1744 var mWEPSelect = '0';
1745 if (target.m_wepPassword().length == '13' || target.m_wepPassword().length == '5') {
1746 mWEPSelect = '1';
1747 } else {
1748 mWEPSelect = '0';
1749 }
1750 if (target.m_keyID() == '3') {
1751 params.m_wep_key_4 = target.m_wepPassword();
1752 params.m_WEP4Select = mWEPSelect;
1753 } else if (target.m_keyID() == '2') {
1754 params.m_wep_key_3 = target.m_wepPassword();
1755 params.m_WEP3Select = mWEPSelect;
1756 } else if (target.m_keyID() == '1') {
1757 params.m_wep_key_2 = target.m_wepPassword();
1758 params.m_WEP2Select = mWEPSelect;
1759 } else {
1760 params.m_wep_key_1 = target.m_wepPassword();
1761 params.m_WEP1Select = mWEPSelect;
1762 }
1763 }
1764
1765 service.setWifiBasic4SSID2(params, function (result) {
1766 if (result.result == "success") {
1767 if (viaWifi) {
1768 setTimeout(ssid2ReloadVarWifi, 15000);
1769 } else {
1770 addInterval(ssid2Reload, 1000);
1771 }
1772 } else {
1773 errorOverlay();
1774 }
1775 });
1776 };
1777
1778 function guestReloadVarWifi() {
1779 successOverlay();
1780 setTimeout(function () {
1781 window.location.reload();
1782 }, 1000);
1783 target.clear();
1784 }
1785 function guestReload() {
1786 var info = getWifiMain();
1787 if (info.wifi_enable == "1") {
1788 successOverlay();
1789 target.clear();
1790 }
1791 }
1792 function ssid2ReloadVarWifi() {
1793 successOverlay();
1794 setTimeout(function () {
1795 window.location.reload();
1796 }, 1000);
1797 target.clear();
1798 }
1799 function ssid2Reload() {
1800 var info = getWifiMain();
1801 if (info.wifi_enable == "1") {
1802 successOverlay();
1803 target.clear();
1804 }
1805 }
1806
1807 target.checkSettings = function (ssid) {
1808 var status = getWpsState();
1809
1810 if (config.HAS_MULTI_SSID) {
1811 if (ssid == "ssid1" || ssid == "ssid2") {
1812 if (ssid == "ssid2") {
1813 var accessDevice = service.getStatusInfo().ssid2AttachedNum;
1814 if (parseInt(target.m_selectedStation()) < accessDevice) {
1815 showAlert('Extend_accessDevice');
1816 return true;
1817 }
1818 } else {
1819 var accessDevice = service.getStatusInfo().ssid1AttachedNum;
1820 if (parseInt(target.selectedStation()) < accessDevice) {
1821 showAlert('Extend_accessDevice');
1822 return true;
1823 }
1824 }
1825 }
1826 }
1827
1828 if (status.wpsFlag == '1') {
1829 showAlert('wps_on_info', function() {
1830 window.location.reload();
1831 });
1832 return true;
1833 }
1834 if (config.HAS_MULTI_SSID && info.multi_ssid_enable == "1") {
1835 if ((ssid == "ssid1" && parseInt(target.selectedStation()) + parseInt(info.m_MAX_Access_num) > info.MAX_Station_num)
1836 || (ssid == "ssid2" && parseInt(target.m_selectedStation()) + parseInt(info.MAX_Access_num) > info.MAX_Station_num)) {
1837 showAlert({
1838 msg: 'multi_ssid_max_access_number_alert',
1839 params: info.MAX_Station_num
1840 });
1841 return true;
1842 }
1843 }
1844
1845 return false;
1846 };
1847
1848 target.setMultiSSIDSwitch = function () {
1849 if (target.checkSettings("switch")) {
1850 return;
1851 }
1852
1853 var setSwitch = function () {
1854 showLoading('waiting');
1855 var params = {};
1856 params.m_ssid_enable = target.multi_ssid_enable();
1857 if (config.WIFI_SWITCH_SUPPORT) {
1858 params.wifiEnabled = target.wifi_enable();
1859 }
1860 service.setWifiBasicMultiSSIDSwitch(params, function (result) {
1861 if (result.result == "success") {
1862 if (viaWifi) {
1863 setTimeout(multiReloadViaWifi, 15000);
1864 } else {
1865 addInterval(multiReload, 1000);
1866 }
1867 } else {
1868 errorOverlay();
1869 }
1870 });
1871 };
1872 function multiReloadViaWifi() {
1873 successOverlay();
1874 setTimeout(function () {
1875 window.location.reload();
1876 }, 1000);
1877 target.clear();
1878 }
1879 function multiReload() {
1880 var info = getWifiMain();
1881 if (info.wifi_enable == target.wifi_enable()) {
1882 successOverlay();
1883 target.clear();
1884 }
1885 }
1886 var info = service.getStatusInfo();
1887 if (config.HAS_MULTI_SSID && target.wifi_enable() == "1") {
1888 if (config.AP_STATION_SUPPORT && target.multi_ssid_enable() == "1" && target.origin_ap_station_enable == "1") {
1889 if (!info.wifiStatus) {
1890 showConfirm("multi_ssid_enable_confirm", function () {
1891 setSwitch();
1892 });
1893 } else {
1894 showConfirm("multi_ssid_enable_confirm2", function () {
1895 setSwitch();
1896 });
1897 }
1898 } else {
1899 if (!info.wifiStatus) {
1900 setSwitch();
1901 } else {
1902 showConfirm("wifi_disconnect_confirm2", function () {
1903 setSwitch();
1904 });
1905 }
1906 }
1907 } else {
1908 setSwitch();
1909 }
1910 };
1911 target.showQRHandler = function () {
1912 var checkbox = $("#showQR:checked");
1913 if (checkbox && checkbox.length == 0) {
1914 target.showQR(true);
1915 } else {
1916 target.showQR(false);
1917 }
1918 target.showQRCode(config.WIFI_SUPPORT_QR_CODE && target.showQR());
1919 };
1920
1921 target.showPasswordHandler = guestShowPassword;
1922
1923 target.m_showPasswordHandler = m_guestShowPassword;
1924
1925 function guestShowPassword() {
1926 $("#passShow").parent().find(".error").hide();
1927 var checkbox = $("#showPassword:checked");
1928 if (checkbox && checkbox.length == 0) {
1929 target.showPassword(true);
1930 } else {
1931 target.showPassword(false);
1932 }
1933 }
1934 function m_guestShowPassword() {
1935 $("#m_passShow").parent().find(".error").hide();
1936 $("#m_pwdWepKey").parent().find(".error").hide();
1937 var checkbox = $("#m_showPassword:checked");
1938 if (checkbox && checkbox.length == 0) {
1939 target.m_showPassword(true);
1940 } else {
1941 target.m_showPassword(false);
1942 }
1943 }
1944
1945 }
1946
1947 function getWifiMain() {
1948 return service.getWifiBasic();
1949 }
1950
1951 function initialize() {
1952 var container = $('#container');
1953 ko.cleanNode(container[0]);
1954 var vm = new wifiGuestVM();
1955 ko.applyBindings(vm, container[0]);
1956 addTimeout(function () {
1957 checkAccessMode();
1958 }, 600);
1959
1960 function checkWifiStatus() {
1961 var info = service.getAPStationBasic();
1962 if (info.ap_station_enable != "1") {
1963 $('#frmMultiSSID :input').each(function () {
1964 $(this).attr("disabled", false);
1965 });
1966 } else {
1967 $('#frmMultiSSID :input').each(function () {
1968 $(this).attr("disabled", true);
1969 });
1970 }
1971 }
1972
1973 function checkWifiStatusAccordingToWDS() {
1974 var info = service.getWdsInfo();
1975 if (info.currentMode == "0") {
1976 $('#frmWifiSwitch :input').each(function () {
1977 $(this).attr("disabled", false);
1978 });
1979 $('#frmSSID2 :input').each(function () {
1980 $(this).attr("disabled", false);
1981 });
1982 $('#frmSSID1 :input').each(function () {
1983 $(this).attr("disabled", false);
1984 });
1985 } else {
1986 $('#frmWifiSwitch :input').each(function () {
1987 $(this).attr("disabled", true);
1988 });
1989 $('#frmSSID2 :input').each(function () {
1990 $(this).attr("disabled", true);
1991 });
1992 $('#frmSSID1 :input').each(function () {
1993 $(this).attr("disabled", true);
1994 });
1995 }
1996 }
1997
1998 if (config.WDS_SUPPORT) {
1999 checkWifiStatusAccordingToWDS();
2000 } else if (config.AP_STATION_SUPPORT) {
2001 checkWifiStatus();
2002 }
2003
2004 $('#frmMultiSSID').validate({
2005 submitHandler: function () {
2006 vm.setMultiSSIDSwitch();
2007 }
2008 });
2009 $('#frmWifiSwitch').validate({
2010 submitHandler: function () {
2011 vm.setMultiSSIDSwitch();
2012 }
2013 });
2014 $('#frmSSID2').validate({
2015 submitHandler: function () {
2016 vm.saveSSID2();
2017 },
2018 rules: {
2019 m_ssid: 'ssid',
2020 m_pwdWepKey: {
2021 wifi_wep_password_check: true,
2022 wifi_password_check: true
2023 },
2024 m_txtWepKey: {
2025 wifi_wep_password_check: true,
2026 wifi_password_check: true
2027 },
2028 m_pass: 'wifi_password_check',
2029 m_passShow: 'wifi_password_check'
2030 },
2031 errorPlacement: function (error, element) {
2032 var id = element.attr("id");
2033 if (id == "m_passShow" || id == "m_pass") {
2034 error.insertAfter("#m_lblShowPassword");
2035 } else if (id == "m_txtWepKey" || id == "m_pwdWepKey") {
2036 error.insertAfter("#m_lblShowWepPassword");
2037 } else {
2038 error.insertAfter(element);
2039 }
2040 }
2041 });
2042 $('#frmSSID1').validate({
2043 submitHandler: function () {
2044 vm.saveSSID1();
2045 },
2046 rules: {
2047 pass: 'wifi_password_check',
2048 ssid: 'ssid',
2049 passShow: 'wifi_password_check'
2050 },
2051 errorPlacement: function (error, element) {
2052 var id = element.attr("id");
2053 if (id == "passShow" || id == "pass") {
2054 error.insertAfter("#lblShowPassword");
2055 } else {
2056 error.insertAfter(element);
2057 }
2058 }
2059 });
2060
2061 }
2062
2063 function getWpsState() {
2064 return service.getWpsInfo();
2065 }
2066
2067 return {
2068 init: initialize
2069 };
2070});
2071
2072define("wifi_mac_filter","underscore jquery knockout set service".split(" "),
2073 function (_, $, ko, config, service) {
2074
2075 var viaWifi = false;
2076 function checkAccessMode() {
2077 service.getParams({
2078 nv: 'user_ip_addr'
2079 }, function (dataIp) {
2080 service.getParams({
2081 nv: 'station_list'
2082 }, function (dataList) {
2083 viaWifi = isWifiConnected(dataIp.user_ip_addr, dataList.station_list);
2084 });
2085 });
2086 }
2087
2088 function macFilterViewModel() {
2089 var target = this;
2090 target.hasAPStation = config.AP_STATION_SUPPORT;
2091 target.hasWifiSwitch = config.WIFI_SWITCH_SUPPORT;
2092 target.hasMultiSSID = config.HAS_MULTI_SSID;
2093 target.showIsolated = config.SHOW_WIFI_AP_ISOLATED;
2094
2095 var info = service.getMacFilterInfo();
2096 var wifiBaseInfo = service.getWifiBasic();
2097 target.multi_ssid_enable = ko.observable(wifiBaseInfo.multi_ssid_enable);
2098 target.origin_ap_station_enable = wifiBaseInfo.ap_station_enable;
2099 target.wifi_enable = ko.observable(wifiBaseInfo.wifi_enable);
2100
2101 target.isShowSSIDInfoDiv = ko.observable(false);
2102 if (config.WIFI_SWITCH_SUPPORT) {
2103 if (wifiBaseInfo.wifi_enable == "1") {
2104 target.isShowSSIDInfoDiv(true);
2105 } else {
2106 target.isShowSSIDInfoDiv(false);
2107 }
2108 } else {
2109 target.isShowSSIDInfoDiv(true);
2110 }
2111
2112 target.selectedAction = ko.observable(info.ACL_mode);
2113 target.mac1 = ko.observable("");
2114 target.mac2 = ko.observable("");
2115 target.mac3 = ko.observable("");
2116 target.mac4 = ko.observable("");
2117 target.mac5 = ko.observable("");
2118 target.mac6 = ko.observable("");
2119 target.mac7 = ko.observable("");
2120 target.mac8 = ko.observable("");
2121 target.mac9 = ko.observable("");
2122 target.mac10 = ko.observable("");
2123 if (info.ACL_mode == "1") {
2124 macInfoWhite = info.wifi_mac_white_list.split(";");
2125 target.mac1 = ko.observable(macInfoWhite[0]);
2126 target.mac2 = ko.observable(macInfoWhite[1]);
2127 target.mac3 = ko.observable(macInfoWhite[2]);
2128 target.mac4 = ko.observable(macInfoWhite[3]);
2129 target.mac5 = ko.observable(macInfoWhite[4]);
2130 target.mac6 = ko.observable(macInfoWhite[5]);
2131 target.mac7 = ko.observable(macInfoWhite[6]);
2132 target.mac8 = ko.observable(macInfoWhite[7]);
2133 target.mac9 = ko.observable(macInfoWhite[8]);
2134 target.mac10 = ko.observable(macInfoWhite[9]);
2135 } else if (info.ACL_mode == "2") {
2136 macInfoBlack = info.wifi_mac_black_list.split(";");
2137 target.mac1 = ko.observable(macInfoBlack[0]);
2138 target.mac2 = ko.observable(macInfoBlack[1]);
2139 target.mac3 = ko.observable(macInfoBlack[2]);
2140 target.mac4 = ko.observable(macInfoBlack[3]);
2141 target.mac5 = ko.observable(macInfoBlack[4]);
2142 target.mac6 = ko.observable(macInfoBlack[5]);
2143 target.mac7 = ko.observable(macInfoBlack[6]);
2144 target.mac8 = ko.observable(macInfoBlack[7]);
2145 target.mac9 = ko.observable(macInfoBlack[8]);
2146 target.mac10 = ko.observable(macInfoBlack[9]);
2147 }
2148
2149 target.save = filter_save;
2150 //切换MAC过滤规则事件
2151 target.ChangeHandler = function () {
2152 $("#mac_filter_form").find(".error").hide();
2153 $("#mac_filter_form").find("input[type=text]").show();
2154 var info = service.getMacFilterInfo();
2155 if (target.selectedAction() == "1") {
2156 macInfoWhite = info.wifi_mac_white_list.split(";");
2157 target.mac1(macInfoWhite[0]);
2158 target.mac2(macInfoWhite[1]);
2159 target.mac3(macInfoWhite[2]);
2160 target.mac4(macInfoWhite[3]);
2161 target.mac5(macInfoWhite[4]);
2162 target.mac6(macInfoWhite[5]);
2163 target.mac7(macInfoWhite[6]);
2164 target.mac8(macInfoWhite[7]);
2165 target.mac9(macInfoWhite[8]);
2166 target.mac10(macInfoWhite[9]);
2167 } else if (target.selectedAction() == "2") {
2168 macInfoBlack = info.wifi_mac_black_list.split(";");
2169 target.mac1(macInfoBlack[0]);
2170 target.mac2(macInfoBlack[1]);
2171 target.mac3(macInfoBlack[2]);
2172 target.mac4(macInfoBlack[3]);
2173 target.mac5(macInfoBlack[4]);
2174 target.mac6(macInfoBlack[5]);
2175 target.mac7(macInfoBlack[6]);
2176 target.mac8(macInfoBlack[7]);
2177 target.mac9(macInfoBlack[8]);
2178 target.mac10(macInfoBlack[9]);
2179 } else {
2180 target.mac1("");
2181 target.mac2("");
2182 target.mac3("");
2183 target.mac4("");
2184 target.mac5("");
2185 target.mac6("");
2186 target.mac7("");
2187 target.mac8("");
2188 target.mac9("");
2189 target.mac10("");
2190 }
2191 }
2192 //检查WPS状态
2193 target.checkSettings = function (ssid) {
2194 var wifi_status = service.getWpsInfo();
2195 if (wifi_status.wpsFlag == '1') {
2196 showAlert('wps_on_info', function() {
2197 window.location.reload();
2198 });
2199 return true;
2200 }
2201 return false;
2202 };
2203
2204 //设置多SSID开关
2205 target.setMultiSSIDSwitch = function () {
2206 if (target.checkSettings("switch")) {
2207 return;
2208 }
2209
2210 var setSwitch = setFilterSwitch;
2211
2212 var info = service.getStatusInfo();
2213 if (config.HAS_MULTI_SSID && target.wifi_enable() == "1") {
2214 if (target.multi_ssid_enable() == "1" && config.AP_STATION_SUPPORT && target.origin_ap_station_enable == "1") {
2215 if (!info.wifiStatus) {
2216 showConfirm("multi_ssid_enable_confirm", function () {
2217 setSwitch();
2218 });
2219 } else {
2220 showConfirm("multi_ssid_enable_confirm2", function () {
2221 setSwitch();
2222 });
2223 }
2224 } else {
2225 if (!info.wifiStatus) {
2226 setSwitch();
2227 } else {
2228 showConfirm("wifi_disconnect_confirm2", function () {
2229 setSwitch();
2230 });
2231 }
2232 }
2233 } else {
2234 setSwitch();
2235 }
2236
2237 function setFilterSwitch() {
2238 showLoading('waiting');
2239 var filter_param = {};
2240 filter_param.m_ssid_enable = target.multi_ssid_enable();
2241 if (config.WIFI_SWITCH_SUPPORT) {
2242 filter_param.wifiEnabled = target.wifi_enable();
2243 }
2244 service.setWifiBasicMultiSSIDSwitch(filter_param, function (result) {
2245 if (result.result == "success") {
2246 if (!viaWifi) {
2247 addInterval(function () {
2248 var info = service.getWifiBasic();
2249 service.refreshAPStationStatus();
2250 if (info.wifi_enable == target.wifi_enable()) {
2251 successOverlay();
2252 clearTimer();
2253 clearValidateMsg();
2254 service.refreshAPStationStatus();
2255 initialize();
2256 }
2257 }, 1000);
2258 } else {
2259 setTimeout(function () {
2260 successOverlay();
2261 setTimeout(function () {
2262 window.location.reload();
2263 }, 1000);
2264 clearTimer();
2265 clearValidateMsg();
2266 service.refreshAPStationStatus();
2267 initialize();
2268 }, 15000);
2269 }
2270 } else {
2271 errorOverlay();
2272 }
2273 });
2274 }
2275 };
2276
2277 function filter_save() {
2278 var wifi_status = service.getWpsInfo();
2279 if (wifi_status.wpsFlag == '1') {
2280 showAlert('wps_on_info', function() {
2281 window.location.reload();
2282 });
2283 return true;
2284 }
2285
2286 if (target.mac1() == undefined || target.mac1().indexOf(" ") >= 0) {
2287 target.mac1("")
2288 }
2289 if (target.mac2() == undefined || target.mac2().indexOf(" ") >= 0) {
2290 target.mac2("")
2291 }
2292 if (target.mac3() == undefined || target.mac3().indexOf(" ") >= 0) {
2293 target.mac3("")
2294 }
2295 if (target.mac4() == undefined || target.mac4().indexOf(" ") >= 0) {
2296 target.mac4("")
2297 }
2298 if (target.mac5() == undefined || target.mac5().indexOf(" ") >= 0) {
2299 target.mac5("")
2300 }
2301 if (target.mac6() == undefined || target.mac6().indexOf(" ") >= 0) {
2302 target.mac6("")
2303 }
2304 if (target.mac7() == undefined || target.mac7().indexOf(" ") >= 0) {
2305 target.mac7("")
2306 }
2307 if (target.mac8() == undefined || target.mac8().indexOf(" ") >= 0) {
2308 target.mac8("")
2309 }
2310 if (target.mac9() == undefined || target.mac9().indexOf(" ") >= 0) {
2311 target.mac9("")
2312 }
2313 if (target.mac10() == undefined || target.mac10().indexOf(" ") >= 0) {
2314 target.mac10("")
2315 }
2316
2317 var mac_list = new Array(target.mac1(), target.mac2(), target.mac3(), target.mac4(), target.mac5(),
2318 target.mac6(), target.mac7(), target.mac8(), target.mac9(), target.mac10());
2319 if (target.selectedAction() == "2" && info.client_mac_address != "" && $.inArray(info.client_mac_address, mac_list) != -1) {
2320 showAlert('black_yourself_tip');
2321 return false;
2322 }
2323 var list_sort = mac_list.sort(); //排序
2324 for (var i = 0; i < list_sort.length - 1; i++) {
2325 if (list_sort[i] != "" && list_sort[i] == list_sort[i + 1]) {
2326 showAlert('mac_repeat_tip');
2327 return false;
2328 }
2329 }
2330 var string_maclist = "";
2331 for (var i = 0; i < 10; i++) {
2332 if (string_maclist == "") {
2333 string_maclist = mac_list[i];
2334 } else {
2335 if (mac_list[i]) {
2336 string_maclist = string_maclist + ";" + mac_list[i];
2337 }
2338 }
2339 }
2340 var filter_param = {};
2341 filter_param.ACL_mode = target.selectedAction();
2342 if (target.selectedAction() == "2") {
2343 filter_param.wifi_mac_black_list = string_maclist;
2344 } else if (target.selectedAction() == "1") {
2345 filter_param.wifi_mac_white_list = string_maclist;
2346 }
2347 showLoading('waiting');
2348 service.setMacFilter(filter_param, function (result) {
2349 if (result.result == "success") {
2350 successOverlay();
2351 } else {
2352 errorOverlay();
2353 }
2354 });
2355 }
2356 }
2357
2358 function bindContainer(filter_vm) {
2359 var container = $('#container');
2360 ko.cleanNode(container[0]);
2361 ko.applyBindings(filter_vm, container[0]);
2362
2363 $('#frmWifiSwitch').validate({
2364 submitHandler: function () {
2365 filter_vm.setMultiSSIDSwitch();
2366 }
2367 });
2368 $('#mac_filter_form').validate({
2369 submitHandler: function () {
2370 filter_vm.save();
2371 },
2372 rules: {
2373 mac_1: 'mac_check',
2374 mac_2: 'mac_check',
2375 mac_3: 'mac_check',
2376 mac_4: 'mac_check',
2377 mac_5: 'mac_check',
2378 mac_6: 'mac_check',
2379 mac_7: 'mac_check',
2380 mac_8: 'mac_check',
2381 mac_9: 'mac_check',
2382 mac_10: 'mac_check'
2383 }
2384 });
2385 }
2386 function initialize() {
2387 var filter_vm = new macFilterViewModel();
2388 bindContainer(filter_vm);
2389
2390 addTimeout(function () {
2391 checkAccessMode();
2392 }, 600);
2393 }
2394
2395 return {
2396 init: initialize
2397 };
2398});
2399
2400define("wifi_main","underscore jquery knockout set service CryptoJS".split(" "),
2401 function (_, $, ko, config, service, CryptoJS) {
2402
2403 var securityModes = _.map(config.WIFI_WEP_SUPPORT ? config.AUTH_MODES_WEP : config.AUTH_MODES, function (item) {
2404 return new Option(item.name, item.value);
2405 });
2406
2407 function maxStationAccess(max) {
2408 var showOption = [];
2409 for (var i = 1; i <= max; i++) {
2410 showOption.push(new Option(i, i));
2411 }
2412 return showOption;
2413 }
2414 //是否通过wifi接入
2415 var viaWifi = false;
2416 function checkAccessMode() {
2417 service.getParams({
2418 nv: 'user_ip_addr'
2419 }, function (dataIp) {
2420 service.getParams({
2421 nv: 'station_list'
2422 }, function (dataList) {
2423 viaWifi = isWifiConnected(dataIp.user_ip_addr, dataList.station_list);
2424 });
2425 });
2426 }
2427
2428 function WifiMainVM() {
2429 var target = this;
2430 var info = getWifiMain();
2431
2432 target.hasWifiSwitch = config.WIFI_SWITCH_SUPPORT;
2433 target.hasMultiSSID = config.HAS_MULTI_SSID;
2434 target.showIsolated = config.SHOW_WIFI_AP_ISOLATED;
2435 target.hasAPStation = config.AP_STATION_SUPPORT;
2436 target.hasWlanMacfilter = config.HAS_BLACK_AND_WHITE_FILTER;
2437 target.hasWifiWep = config.WIFI_WEP_SUPPORT;
2438 target.hasWifiWpa3 = config.WIFI_WAP3_SUPPORT;
2439 target.hasWifiWpa23 = config.WIFI_WPA2_WAP3_SUPPORT;
2440
2441 var advanceInfo = service.getWifiAdvance();
2442 target.adBand = ko.observable(advanceInfo.wifiBand);
2443 target.adMode = ko.observable(advanceInfo.mode);
2444 target.showQRSwitch = config.WIFI_SUPPORT_QR_CODE && config.WIFI_SUPPORT_QR_SWITCH;
2445 target.showQR = ko.observable(info.show_qrcode_flag);
2446 if (config.WIFI_SUPPORT_QR_SWITCH) {
2447 target.showQRCode = ko.observable(config.WIFI_SUPPORT_QR_CODE && target.showQR());
2448 } else {
2449 target.showQRCode = ko.observable(config.WIFI_SUPPORT_QR_CODE);
2450 }
2451 if(config.WIFI_SUPPORT_QR_CODE){
2452 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2453 } else {
2454 target.qrcodeSrc = './pic/res_blacktrans.png';
2455 }
2456 target.origin_ap_station_enable = info.ap_station_enable;
2457 target.wifi_enable = ko.observable(info.wifi_enable);
2458
2459 target.isShowSSIDInfoDiv = ko.observable(false);
2460 if (config.WIFI_SWITCH_SUPPORT) {
2461 if (info.wifi_enable == "1") {
2462 target.isShowSSIDInfoDiv(true);
2463 } else {
2464 target.isShowSSIDInfoDiv(false);
2465 }
2466 } else {
2467 target.isShowSSIDInfoDiv(true);
2468 }
2469
2470 target.multi_ssid_enable = ko.observable(info.multi_ssid_enable);
2471 target.origin_multi_ssid_enable = info.multi_ssid_enable;
2472
2473 target.maxStationNumber = ko.computed(function () {
2474 return config.MAX_STATION_NUMBER;
2475 });
2476
2477 target.modes = ko.observableArray(securityModes);
2478 target.selectedMode = ko.observable(info.AuthMode);
2479 target.passPhrase = ko.observable(info.passPhrase);
2480 target.showPassword = ko.observable(false);
2481 target.ssid = ko.observable(info.SSID);
2482 target.broadcast = ko.observable(info.broadcast == '1' ? '1' : '0');
2483 target.apIsolation = ko.observable(info.apIsolation == '1' ? '1' : '0');
2484 target.cipher = info.cipher;
2485 target.selectedStation = ko.observable(info.MAX_Access_num);
2486 target.maxStations = ko.observableArray(maxStationAccess(info.MAX_Station_num));
2487 target.encryptType = ko.observable(info.encryptType);
2488 target.keyID = ko.observable(info.keyID);
2489 target.wepPassword = ko.observable("");
2490
2491 target.m_modes = ko.observableArray(securityModes);
2492 target.m_selectedMode = ko.observable(info.m_AuthMode);
2493 target.m_passPhrase = ko.observable(info.m_passPhrase);
2494 target.m_showPassword = ko.observable(false);
2495 target.m_ssid = ko.observable(info.m_SSID);
2496 target.m_broadcast = ko.observable(info.m_broadcast == '1' ? '1' : '0');
2497 target.m_apIsolation = ko.observable(info.m_apIsolation == '1' ? '1' : '0');
2498 target.m_cipher = info.m_cipher;
2499 target.m_selectedStation = ko.observable(info.m_MAX_Access_num);
2500 target.m_maxStations = ko.observableArray(maxStationAccess(info.MAX_Station_num));
2501
2502 target.getWepPassword = function () {
2503 return target.keyID() == '3' ? info.Key4Str1 : (target.keyID() == '2' ? info.Key3Str1 : target.keyID() == '1' ? info.Key2Str1 : info.Key1Str1);
2504 }
2505 target.wepPassword(target.getWepPassword());
2506 target.profileChangeHandler = function (data, event) {
2507 $("#pwdWepKey").parent().find("label[class='error']").hide();
2508 target.wepPassword(target.getWepPassword());
2509 return true;
2510 };
2511
2512 target.clear = function (option) {
2513 if (option == "switch") {
2514 target.multi_ssid_enable(info.multi_ssid_enable);
2515 target.wifi_enable(info.wifi_enable);
2516 } else if (option == "ssid2") {
2517 target.m_selectedMode(info.m_AuthMode);
2518 target.m_passPhrase(info.m_passPhrase);
2519 target.m_ssid(info.m_SSID);
2520 target.m_broadcast(info.m_broadcast == '1' ? '1' : '0');
2521 target.m_cipher = info.m_cipher;
2522 target.m_selectedStation(info.m_MAX_Access_num);
2523 target.m_apIsolation(info.m_apIsolation == '1' ? '1' : '0');
2524 } else if (option == "ssid1") {
2525 target.selectedMode(info.AuthMode);
2526 target.passPhrase(info.passPhrase);
2527 target.ssid(info.SSID);
2528 target.broadcast(info.broadcast == '1' ? '1' : '0');
2529 target.cipher = info.cipher;
2530 target.selectedStation(info.MAX_Access_num);
2531 target.apIsolation(info.apIsolation == '1' ? '1' : '0');
2532 if (config.WIFI_WEP_SUPPORT) {
2533 target.encryptType(info.encryptType);
2534 target.keyID(info.keyID);
2535 target.wepPassword(target.getWepPassword());
2536 }
2537 } else {
2538 clearTimer();
2539 clearValidateMsg();
2540 initialize();
2541 }
2542 };
2543
2544 target.saveSSID1 = function () {
2545 if (target.checkSettings("ssid1")) {
2546 return;
2547 }
2548 if (!config.PASSWORD_ENCODE) {
2549 var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,32}');
2550 if (!pwdRegex.test(target.passPhrase())) {
2551 showConfirm("password_note_too_low", function () {
2552 showConfirm('wifi_disconnect_confirm', function () {
2553 target.saveSSID1Action();
2554 return;
2555 });
2556 return;
2557 });
2558 return;
2559 }
2560 }
2561 showConfirm('wifi_disconnect_confirm', function () {
2562 target.saveSSID1Action();
2563 });
2564 };
2565
2566 target.saveSSID1Action = getSSID1Action;
2567
2568 target.saveSSID2 = function () {
2569 if (target.checkSettings("ssid2")) {
2570 return;
2571 }
2572 showConfirm('wifi_disconnect_confirm', function () {
2573 target.saveSSID2Action();
2574 });
2575 };
2576
2577 target.saveSSID2Action = getSSID2Action;
2578
2579 //检测wps\最大接入数
2580 target.checkSettings = function (ssid) {
2581 var status = getWpsState();
2582 if (ssid == "ssid1" || ssid == "ssid2") {
2583 if (ssid == "ssid2") {
2584 var accessDevice = service.getStatusInfo().ssid2AttachedNum;
2585 if (parseInt(target.m_selectedStation()) < accessDevice) {
2586 showAlert('Extend_accessDevice');
2587 return true;
2588 }
2589 } else {
2590 var accessDevice = service.getStatusInfo().ssid1AttachedNum;
2591 if (parseInt(target.selectedStation()) < accessDevice) {
2592 showAlert('Extend_accessDevice');
2593 return true;
2594 }
2595 }
2596 }
2597
2598 if (status.wpsFlag == '1') {
2599 showAlert('wps_on_info', function() {
2600 window.location.reload();
2601 });
2602 return true;
2603 }
2604
2605 if (info.multi_ssid_enable == "1" && config.HAS_MULTI_SSID) {
2606 if ((ssid == "ssid2" && parseInt(target.m_selectedStation()) + parseInt(info.MAX_Access_num) > info.MAX_Station_num)
2607 || (ssid == "ssid1" && parseInt(target.selectedStation()) + parseInt(info.m_MAX_Access_num) > info.MAX_Station_num)) {
2608 showAlert({
2609 msg: 'multi_ssid_max_access_number_alert',
2610 params: info.MAX_Station_num
2611 });
2612 return true;
2613 }
2614 }
2615
2616 return false;
2617 };
2618
2619 target.setMultiSSIDSwitch = function () {
2620 if (target.checkSettings("switch")) {
2621 return;
2622 }
2623
2624 var setSwitch = function () {
2625 showLoading('waiting');
2626 var params = {};
2627 params.m_ssid_enable = target.multi_ssid_enable();
2628 if (config.WIFI_SWITCH_SUPPORT) {
2629 params.wifiEnabled = target.wifi_enable();
2630 }
2631 service.setWifiBasicMultiSSIDSwitch(params, function (result) {
2632 if (result.result == "success") {
2633 if (viaWifi) {
2634 setTimeout(hasApReloadVarWifi, 15000);
2635 } else {
2636 addInterval(hasApReload, 1000);
2637 }
2638 } else {
2639 errorOverlay();
2640 }
2641 });
2642 };
2643
2644 function hasApReloadVarWifi() {
2645 successOverlay();
2646 setTimeout(function () {
2647 window.location.reload();
2648 }, 1000);
2649 service.refreshAPStationStatus();
2650 target.clear();
2651 }
2652 function hasApReload() {
2653 var info = getWifiMain();
2654 service.refreshAPStationStatus();
2655 if (info.wifi_enable == target.wifi_enable()) {
2656 successOverlay();
2657 target.clear();
2658 }
2659 }
2660
2661 var info = service.getStatusInfo();
2662 if (config.HAS_MULTI_SSID && target.wifi_enable() == "1") {
2663 if (target.multi_ssid_enable() == "1" && config.AP_STATION_SUPPORT && target.origin_ap_station_enable == "1") {
2664 if (!info.wifiStatus) {
2665 showConfirm("multi_ssid_enable_confirm", function () {
2666 setSwitch();
2667 });
2668 } else {
2669 showConfirm("multi_ssid_enable_confirm2", function () {
2670 setSwitch();
2671 });
2672 }
2673 } else {
2674 if (!info.wifiStatus) {
2675 setSwitch();
2676 } else {
2677 showConfirm("wifi_disconnect_confirm2", function () {
2678 setSwitch();
2679 });
2680 }
2681 }
2682 } else {
2683 setSwitch();
2684 }
2685 };
2686
2687 //二维码显示事件
2688 target.showQRHandler = function () {
2689 var checkbox = $("#showQR:checked");
2690 if (checkbox && checkbox.length == 0) {
2691 target.showQR(true);
2692 } else {
2693 target.showQR(false);
2694 }
2695 target.showQRCode(config.WIFI_SUPPORT_QR_CODE && target.showQR());
2696 };
2697
2698 //SSID2
2699 target.m_showPasswordHandler = function () {
2700 $("#m_passShow").parent().find(".error").hide();
2701 var checkbox = $("#m_showPassword:checked");
2702 if (checkbox && checkbox.length == 0) {
2703 target.m_showPassword(true);
2704 } else {
2705 target.m_showPassword(false);
2706 }
2707 };
2708 target.showPasswordHandler = function () {
2709 $("#codeWPAKey").parent().find(".error").hide();
2710 $("#pwdWepKey").parent().find(".error").hide();
2711 var checkbox = $("#showPassword:checked");
2712 if (checkbox && checkbox.length == 0) {
2713 target.showPassword(true);
2714 } else {
2715 target.showPassword(false);
2716 }
2717 };
2718
2719 function getSSID2Action() {
2720 showLoading('waiting');
2721 var params = {};
2722 params.m_AuthMode = target.m_selectedMode();
2723 params.m_passPhrase = target.m_passPhrase();
2724 params.m_SSID = target.m_ssid();
2725 params.m_broadcast = target.m_broadcast();
2726 params.m_station = target.m_selectedStation();
2727 params.m_cipher = target.m_selectedMode() == "WPA2PSK" ? 1 : 2;
2728 if (params.m_AuthMode == "WPA3Personal" || params.m_AuthMode == "WPA2WPA3") {
2729 params.m_cipher = 1;
2730 }
2731 params.m_NoForwarding = target.m_apIsolation();
2732 params.m_show_qrcode_flag = target.showQR() == true ? 1 : 0;
2733 service.setWifiBasic4SSID2(params, function (result) {
2734 if (result.result == "success") {
2735 if (viaWifi) {
2736 setTimeout(ssid2ReloadVarWifi, 15000);
2737 } else {
2738 addInterval(ssid2Reload, 1000);
2739 }
2740 } else {
2741 errorOverlay();
2742 }
2743 });
2744 }
2745 function ssid2ReloadVarWifi() {
2746 successOverlay();
2747 setTimeout(function () {
2748 window.location.reload();
2749 }, 1000);
2750 target.clear();
2751 }
2752 function ssid2Reload() {
2753 var info = getWifiMain();
2754 if (info.wifi_enable == "1") {
2755 successOverlay();
2756 target.clear();
2757 }
2758 }
2759
2760 function getSSID1Action() {
2761
2762 showLoading('waiting');
2763 target.broadcast($("#broadcastCheckbox:checked").length > 0 ? '0' : '1');
2764 target.apIsolation($("#apisolatedCheckbox:checked").length);
2765 var ciphertext = "";
2766 if (config.PASSWORD_ENCODE) {
2767 ciphertext = target.passPhrase();
2768 } else {
2769 var kparam = service.getDeviceInfoLow();
2770 var tkey = CryptoJS.enc.Latin1.parse(kparam.skey);
2771 var tiv = CryptoJS.enc.Latin1.parse(kparam.siv);
2772 ciphertext = CryptoJS.AES.encrypt(target.passPhrase(), tkey, {
2773 iv: tiv,
2774 mode: CryptoJS.mode.CBC,
2775 padding: CryptoJS.pad.ZeroPadding
2776 }).toString();
2777 }
2778 var params = {};
2779 params.AuthMode = target.selectedMode();
2780 params.passPhrase = ciphertext;
2781 params.SSID = target.ssid();
2782 params.broadcast = target.broadcast();
2783 params.station = target.selectedStation();
2784 params.cipher = target.selectedMode() == "WPA2PSK" ? 1 : 2;
2785 if (params.AuthMode == "WPA3Personal" || params.AuthMode == "WPA2WPA3") {
2786 params.cipher = 1;
2787 }
2788 params.NoForwarding = target.apIsolation();
2789 params.show_qrcode_flag = target.showQR() == true ? 1 : 0;
2790 if (config.WIFI_WEP_SUPPORT) {
2791 if (params.AuthMode == "WPAPSK" || params.AuthMode == "WPA2PSK" || params.AuthMode == "WPAPSKWPA2PSK" || params.AuthMode == "WPA3Personal" || params.AuthMode == "WPA2WPA3") {}
2792 else if (params.AuthMode == "SHARED") {
2793 params.encryptType = "WEP";
2794 } else {
2795 params.encryptType = target.encryptType();
2796 }
2797 params.wep_default_key = target.keyID();
2798 params.wep_key_1 = info.Key1Str1;
2799 params.wep_key_2 = info.Key2Str1;
2800 params.wep_key_3 = info.Key3Str1;
2801 params.wep_key_4 = info.Key4Str1;
2802 var WEPSelect = '0';
2803 if (target.wepPassword().length == '5' || target.wepPassword().length == '13') {
2804 WEPSelect = '1';
2805 } else {
2806 WEPSelect = '0';
2807 }
2808 if (target.keyID() == '3') {
2809 params.wep_key_4 = target.wepPassword();
2810 params.WEP4Select = WEPSelect;
2811 } else if (target.keyID() == '2') {
2812 params.wep_key_3 = target.wepPassword();
2813 params.WEP3Select = WEPSelect;
2814 } else if (target.keyID() == '1') {
2815 params.wep_key_2 = target.wepPassword();
2816 params.WEP2Select = WEPSelect;
2817 } else {
2818 params.wep_key_1 = target.wepPassword();
2819 params.WEP1Select = WEPSelect;
2820 }
2821 }
2822
2823 service.setWifiBasic(params, function (result) {
2824 if (result.result == "success") {
2825 if (viaWifi) {
2826 setTimeout(ssid1ReloadVarWifi, 15000);
2827 } else {
2828 addInterval(ssid1Reload, 1000);
2829 }
2830 } else {
2831 errorOverlay();
2832 }
2833 });
2834 }
2835 function ssid1ReloadVarWifi() {
2836 successOverlay();
2837 setTimeout(function () {
2838 window.location.reload();
2839 }, 1000);
2840 target.clear();
2841 }
2842 function ssid1Reload() {
2843 var info = getWifiMain();
2844 if (info.wifi_enable == "1") {
2845 successOverlay();
2846 target.clear();
2847 }
2848 }
2849
2850 }
2851
2852 function getWpsState() {
2853 return service.getWpsInfo();
2854 }
2855
2856 function getWifiMain() {
2857 return service.getWifiBasic();
2858 }
2859
2860 function initialize() {
2861 var container = $('#container');
2862 ko.cleanNode(container[0]);
2863 var vm = new WifiMainVM();
2864 ko.applyBindings(vm, container[0]);
2865 addTimeout(function () {
2866 checkAccessMode();
2867 }, 600);
2868
2869 if (config.WDS_SUPPORT) {
2870 checkWifiStatusAccordingToWDS();
2871 } else if (config.AP_STATION_SUPPORT) {
2872 checkWifiStatus();
2873 }
2874
2875 $('#frmSSID1').validate({
2876 submitHandler: function () {
2877 vm.saveSSID1();
2878 },
2879 rules: {
2880 ssid: 'ssid',
2881 pwdWepKey: {
2882 wifi_wep_password_check: true,
2883 wifi_password_check: true
2884 },
2885 txtWepKey: {
2886 wifi_wep_password_check: true,
2887 wifi_password_check: true
2888 },
2889 codeWPAKey: 'wifi_password_check',
2890 txtWPAKey: 'wifi_password_check'
2891 },
2892 errorPlacement: function (error, element) {
2893 var id = element.attr("id");
2894 if (id == "codeWPAKey" || id == "txtWPAKey") {
2895 error.insertAfter("#lblshowWPAPassword");
2896 } else if (id == "pwdWepKey" || id == "txtWepKey") {
2897 error.insertAfter("#lblShowWepPassword");
2898 } else {
2899 error.insertAfter(element);
2900 }
2901 }
2902 });
2903 $('#frmSSID2').validate({
2904 submitHandler: function () {
2905 vm.saveSSID2();
2906 },
2907 rules: {
2908 m_ssid: 'ssid',
2909 m_pass: 'wifi_password_check',
2910 m_passShow: 'wifi_password_check'
2911 },
2912 errorPlacement: function (error, element) {
2913 var id = element.attr("id");
2914 if (id == "m_pass" || id == "m_passShow") {
2915 error.insertAfter("#m_lblShowPassword");
2916 } else if (id == "pass" || id == "passShow") {
2917 error.insertAfter("#lblShowPassword");
2918 } else {
2919 error.insertAfter(element);
2920 }
2921 }
2922 });
2923 //表单提交函数、校验规则配置
2924 $('#frmWifiSwitch').validate({
2925 submitHandler: function () {
2926 vm.setMultiSSIDSwitch();
2927 }
2928 });
2929
2930 $('#frmMultiSSID').validate({
2931 submitHandler: function () {
2932 vm.setMultiSSIDSwitch();
2933 }
2934 });
2935
2936 }
2937
2938 function checkWifiStatusAccordingToWDS() {
2939 var info = service.getWdsInfo();
2940 if (info.currentMode == "0") {
2941 $('#frmWifiSwitch :input').each(function () {
2942 $(this).prop("disabled", false);
2943 });
2944 $('#frmSSID1 :input').each(function () {
2945 $(this).prop("disabled", false);
2946 });
2947 $('#frmSSID2 :input').each(function () {
2948 $(this).prop("disabled", false);
2949 });
2950 } else {
2951 $('#frmWifiSwitch :input').each(function () {
2952 $(this).prop("disabled", true);
2953 });
2954 $('#frmSSID1 :input').each(function () {
2955 $(this).prop("disabled", true);
2956 });
2957 $('#frmSSID2 :input').each(function () {
2958 $(this).prop("disabled", true);
2959 });
2960 }
2961 }
2962 function checkWifiStatus() {
2963 var info = service.getAPStationBasic();
2964 if (info.ap_station_enable == "1") {
2965 $('#frmMultiSSID :input').each(function () {
2966 $(this).prop("disabled", true);
2967 });
2968 } else {
2969 $('#frmMultiSSID :input').each(function () {
2970 $(this).prop("disabled", false);
2971 });
2972 }
2973 }
2974
2975 return {
2976 init: initialize
2977 };
2978});
2979
2980define("wifi_sleep_mode","underscore jquery knockout set service".split(" "),
2981 function (_, $, ko, config, service) {
2982
2983 //休眠方式
2984 function getSleepMode() {
2985 return service.getSleepMode();
2986 }
2987
2988 //覆盖范围
2989 function getWifiRange() {
2990 return service.getWifiRange();
2991 }
2992
2993 var sleepTime = _.map(config.SLEEP_MODES, function (item) {
2994 return new Option(item.name, item.value);
2995 });
2996
2997 function SleepModeViewMode() {
2998 var target = this;
2999
3000 target.isCPE = config.PRODUCT_TYPE == 'CPE';
3001 target.showTSWDiv = config.TSW_SUPPORT;
3002 target.showSleepDiv = config.WIFI_SLEEP_SUPPORT;
3003 target.hasUssd = config.HAS_USSD;
3004 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
3005 target.hasDdns = config.DDNS_SUPPORT;
3006
3007 target.modes = ko.observableArray(sleepTime);
3008
3009 var smInfo = getSleepMode();
3010 target.selectedMode = ko.observable(smInfo.sleepMode);
3011
3012 var wifiRangeInfo = getWifiRange();
3013 target.wifiRangeMode = ko.observable(wifiRangeInfo.wifiRangeMode);
3014
3015 target.setWifiRange = smSetWifiRange;
3016
3017 target.setWifiRangeAct = smSetWifiRangeAct;
3018
3019 target.setSleepMode = smSetSleepMode;
3020
3021 target.setSleepModeAct = smSetSleepModeAct;
3022
3023 var tsw = service.getTsw();
3024 target.openEnable = ko.observable(tsw.openEnable == "" ? '0' : tsw.openEnable);
3025 target.openH = ko.observable(tsw.openH);
3026 target.openM = ko.observable(tsw.openM);
3027 target.closeH = ko.observable(tsw.closeH);
3028 target.closeM = ko.observable(tsw.closeM);
3029 //定时休眠唤醒
3030 target.saveTsw = smSaveTsw;
3031
3032 function smSetWifiRange() {
3033 service.getWpsInfo({}, function (smInfo) {
3034 if (smInfo.wpsFlag == '1') {
3035 showAlert('wps_on_info', function() {
3036 window.location.reload();
3037 });
3038 } else if (smInfo.radioFlag == '0') {
3039 showAlert('wps_wifi_off');
3040 } else {
3041 showConfirm('wifi_sleep_confirm', function () {
3042 showLoading('waiting');
3043 target.setWifiRangeAct();
3044 });
3045
3046 }
3047 });
3048 }
3049 function smSetSleepModeAct() {
3050 var params = {};
3051 params.sleepMode = target.selectedMode();
3052 service.setSleepMode(params, function (result) {
3053 if (result.result != "success") {
3054 errorOverlay();
3055 } else {
3056 successOverlay();
3057 }
3058 });
3059 }
3060
3061 function smSetWifiRangeAct() {
3062 var params = {};
3063 params.wifiRangeMode = target.wifiRangeMode();
3064 service.setWifiRange(params, function (result) {
3065 if (result.result != "success") {
3066 errorOverlay();
3067 } else {
3068 successOverlay();
3069 }
3070 });
3071 }
3072
3073 function smSetSleepMode() {
3074 showLoading('waiting');
3075 service.getWpsInfo({}, function (info) {
3076 if (info.wpsFlag == '1') {
3077 showAlert('wps_on_info', function() {
3078 window.location.reload();
3079 });
3080 } else if (info.radioFlag == '0') {
3081 showAlert('wps_wifi_off');
3082 } else {
3083 target.setSleepModeAct();
3084 }
3085 });
3086 }
3087 function smSaveTsw() {
3088 if (target.openEnable() == '1') {
3089 if (Math.abs((target.openH() * 60 + parseInt(target.openM(), 10)) - (target.closeH() * 60 + parseInt(target.closeM(), 10))) < 10) {
3090 showAlert('tsw_time_interval_alert');
3091 return false;
3092 }
3093 showLoading('waiting');
3094 service.saveTsw({
3095 openEnable: target.openEnable(),
3096 closeEnable: target.openEnable(),
3097 openTime: leftInsert(target.openH(), 2, '0') + ':' + leftInsert(target.openM(), 2, '0'),
3098 closeTime: leftInsert(target.closeH(), 2, '0') + ':' + leftInsert(target.closeM(), 2, '0')
3099 }, smShowRes, $.noop);
3100 } else {
3101 showLoading('waiting');
3102 service.saveTsw({
3103 openEnable: target.openEnable(),
3104 closeEnable: target.openEnable()
3105 }, smShowRes, $.noop);
3106 }
3107
3108 }
3109
3110 }
3111 function bindContainer(smVm) {
3112 var container = $('#container');
3113 ko.cleanNode(container[0]);
3114 ko.applyBindings(smVm, container[0]);
3115
3116 $('#frmTsw').validate({
3117 submitHandler: function () {
3118 smVm.saveTsw();
3119 },
3120 errorPlacement: function (error, element) {
3121 if (element.attr("name") == "closeM" || element.attr("name") == "closeH") {
3122 $("#closeErrorDiv").html(error);
3123 } else if (element.attr("name") == "openM" || element.attr("name") == "openH") {
3124 $("#openErrorDiv").html(error);
3125 } else {
3126 error.insertAfter(element);
3127 }
3128 }
3129 });
3130
3131 $('#sleepModeForm').validate({
3132 submitHandler: function () {
3133 smVm.setSleepMode();
3134 }
3135 });
3136
3137 $('#wifiRangeForm').validate({
3138 submitHandler: function () {
3139 smVm.setWifiRange();
3140 }
3141 });
3142
3143 }
3144 function initialize() {
3145 var smVm = new SleepModeViewMode();
3146 bindContainer(smVm);
3147 }
3148 function smShowRes(data) {
3149 if (data && data.result == "success") {
3150 successOverlay();
3151 } else {
3152 errorOverlay();
3153 }
3154 }
3155
3156 return {
3157 init: initialize
3158 };
3159});
3160
3161define("wifi_station_info","underscore jquery knockout set service menu".split(" "),
3162 function (_, $, ko, config, service, menu) {
3163
3164 var stationUtil = {
3165 dealElement: function (showEdit, idx) {
3166 if (idx != "all") {
3167 if (!showEdit) {
3168 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).show();
3169 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).hide();
3170 } else {
3171 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).hide();
3172 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).show();
3173 }
3174 } else {
3175 $("input[id^='hostname_txt_'],a[id^='edit_btn_']").show();
3176 $("input[id^='hostname_input_'],a[id^='cancel_btn_'],a[id^='save_btn_']").hide();
3177 }
3178 },
3179 //根据MAC匹配主机名
3180 getHostName: function (hostName, mac, hostNameList) {
3181 var element_data = _.find(hostNameList, function (element_data) {
3182 return element_data.mac == mac;
3183 });
3184 return element_data ? element_data.hostname : hostName;
3185 },
3186 //匹配黑名单列表和主机名
3187 parseBlackString: function (macStr, hostnameStr) {
3188 if (macStr == "") {
3189 return [];
3190 }
3191 var tempMac = macStr.split(';');
3192 var tempHostName = hostnameStr.split(';');
3193 var result = [];
3194 for (var i = 0; i < tempMac.length; i++) {
3195 //var obj = {};
3196 //obj.hostName = tempHostName[i];
3197 //obj.macAddress = tempMac[i];
3198 result.push({
3199 hostName: tempHostName[i],
3200 macAddress: tempMac[i]
3201 });
3202 }
3203 return result;
3204 }
3205 };
3206
3207 function staInfoViewMode() {
3208 var target = this;
3209 var originalData = {
3210 user_ip: '',
3211 macList: '',
3212 ACL_mode: 2, //黑白名单
3213 hostnameList: ''
3214 };
3215 target.showCableDiv = config.PRODUCT_TYPE == 'CPE' && config.RJ45_SUPPORT;
3216 target.supportBlock = config.STATION_BLOCK_SUPPORT;
3217 var pcMenu = menu.findMenu('#parental_control');
3218 target.showPCLink = pcMenu && pcMenu.length > 0 && config.HAS_PARENTAL_CONTROL;
3219
3220 target.deviceInfo = ko.observableArray([]);
3221 target.cableDeviceInfo = ko.observableArray([]);
3222 target.blackDevices = ko.observableArray([]);
3223 target.blackDevicesMac = ko.computed(function () {
3224 return _.map(target.blackDevices(), function (element_data) {
3225 return element_data.macAddress;
3226 });
3227 });
3228 target.showBlackDiv = ko.observable(config.HAS_BLACK_AND_WHITE_FILTER ? (originalData.ACL_mode == '2' ? true : false) : config.STATION_BLOCK_SUPPORT);
3229
3230 ko.computed(function () {
3231 target.deviceInfo();
3232 target.cableDeviceInfo();
3233 target.blackDevices();
3234 $("#station_info_div").translate();
3235 }).extend({
3236 notify: 'always',
3237 throttle: 300
3238 });
3239
3240 var hostNameList = service.getHostNameList({}).devices;
3241 //获取WiFi已连接设备
3242 target.fetchAttachedDevices = function (cb) {
3243 service.getCurrentlyAttachedDevicesInfo({}, function (data) {
3244 if (editingHostname) {
3245 return false;
3246 }
3247 target.deviceInfo(_.map(data.attachedDevices, function (element_data, idx) {
3248 element_data.idx = _.uniqueId('wireless_');
3249 element_data.type = 1;
3250 element_data.inBlackGroup = config.HAS_BLACK_AND_WHITE_FILTER && originalData.ACL_mode != '2' ? false : _.contains(target.blackDevicesMac(), element_data.macAddress);
3251 element_data.hostName = stationUtil.getHostName(element_data.hostName, element_data.macAddress, hostNameList);
3252 element_data.disableFlag = (config.HAS_BLACK_AND_WHITE_FILTER && originalData.ACL_mode != '2') || element_data.inBlackGroup || editingHostname;
3253 return element_data;
3254 }));
3255 if (_.isFunction(cb)) {
3256 cb.apply(this);
3257 }
3258 });
3259 };
3260 //获取RJ45已连接设备
3261 target.fetchAttachedCableDevices = function (cb) {
3262 service.getAttachedCableDevices({}, function (data) {
3263 if (editingHostname) {
3264 return false;
3265 }
3266 target.cableDeviceInfo(_.map(data.attachedDevices, function (element_data, idx) {
3267 element_data.idx = _.uniqueId('cable_');
3268 element_data.hostName = stationUtil.getHostName(element_data.hostName, element_data.macAddress, hostNameList);
3269 element_data.type = 2;
3270 return element_data;
3271 }));
3272 if (_.isFunction(cb)) {
3273 cb.apply(this);
3274 }
3275 });
3276 };
3277
3278 target.fetchBlacklist = function (cb) {
3279 service.getMacFilterInfo({}, function (data) {
3280 originalData.ACL_mode = data.ACL_mode;
3281 originalData.user_ip = data.user_ip_addr;
3282 originalData.hostnameList = data.wifi_hostname_black_list;
3283 originalData.macList = data.wifi_mac_black_list;
3284 target.showBlackDiv(config.HAS_BLACK_AND_WHITE_FILTER ? (originalData.ACL_mode == '2' ? true : false) : config.STATION_BLOCK_SUPPORT);
3285 var blackDevices = stationUtil.parseBlackString(data.wifi_mac_black_list, data.wifi_hostname_black_list);
3286 target.blackDevices(_.map(blackDevices, function (element_data, idx) {
3287 element_data.idx = _.uniqueId('black_');
3288 element_data.type = 3;
3289 element_data.hostName = stationUtil.getHostName(element_data.hostName, element_data.macAddress, hostNameList);
3290 return element_data;
3291 }));
3292 if (_.isFunction(cb)) {
3293 cb.apply(this);
3294 }
3295 }, $.noop);
3296 };
3297 target.fetchBlacklist();
3298 target.fetchAttachedDevices();
3299 if (target.showCableDiv) {
3300 target.fetchAttachedCableDevices();
3301 }
3302
3303 var editingHostname = 0;
3304 addInterval(function () {
3305 if (editingHostname == 0) {
3306 target.fetchAttachedDevices();
3307 }
3308 }, 3000);
3309
3310 if (target.showCableDiv) {
3311 addInterval(function () {
3312 if (editingHostname == 0) {
3313 target.fetchAttachedCableDevices();
3314 }
3315 }, 5000);
3316 }
3317 //WiFi已连接设备列表中屏蔽按钮事件 入黑名单
3318 target.wirelessBlockHandler = stationBlockEvent;
3319 //保存主机名事件
3320 target.saveHostNameHandler = saveHostNameEvent;
3321 //主机名修改按钮点击事件
3322 target.editHostNameHandler = function (element_data) {
3323 editingHostname++;
3324 $("#hostname_input_" + element_data.idx).val(element_data.hostName);
3325 stationUtil.dealElement(true, element_data.idx);
3326 return false;
3327 };
3328 //取消编辑主机名事件
3329 target.cancelEditHostNameHandler = function (element_data) {
3330 stationUtil.dealElement(false, element_data.idx);
3331 editingHostname--;
3332 };
3333 target.cancelAllEditHostNameHandler = function () {
3334 stationUtil.dealElement(false, "all");
3335 editingHostname = 0;
3336 };
3337 //从黑名单列表中移除
3338 target.blacklistRemoveHandler = function (element_data) {
3339 if (originalData.macList.indexOf(element_data.macAddress) == -1) {
3340 return false;
3341 }
3342 if (editingHostname) {
3343 target.cancelAllEditHostNameHandler();
3344 }
3345 showLoading('waiting');
3346 var macArr = [];
3347 var hostnameArr = [];
3348 $.each(target.blackDevices(), function (i, n) {
3349 if (n.macAddress != element_data.macAddress) {
3350 macArr.push(n.macAddress);
3351 hostnameArr.push(n.hostName);
3352 }
3353 });
3354 var params = {
3355 ACL_mode: '2', //originalData.ACL_mode
3356 macFilteringMode: '2', //originalData.ACL_mode
3357 wifi_hostname_black_list: hostnameArr.join(';'),
3358 wifi_mac_black_list: macArr.join(';')
3359 };
3360 target.updateMacFilterList(params);
3361 };
3362 target.updateMacFilterList = function (params) {
3363 service.setMacFilter(params, function (data) {
3364 if (data.result == "success") {
3365 target.blackDevices([]);
3366 target.fetchBlacklist(function () {
3367 target.fetchAttachedDevices(function () {
3368 successOverlay();
3369 });
3370 });
3371 }
3372 }, function () {
3373 errorOverlay();
3374 });
3375 };
3376
3377 function saveHostNameEvent(element_data) {
3378 var $input = $("#hostname_input_" + element_data.idx);
3379 var newHostname = $input.val();
3380 if (newHostname.indexOf(" ") == 0 || newHostname.lastIndexOf(" ") == (newHostname.length - 1) || /[\*\$\[&:,;<>'"\\`\]¥]{1,32}/.test(newHostname)) {
3381 showAlert('device_rename');
3382 return false;
3383 } else if (newHostname == '') {
3384 $(".promptErrorLabel", "#confirm-message-container").text($.i18n.prop("required"));
3385 var $closestTD = $input.closest('td').addClass('has-error');
3386 addTimeout(function () {
3387 $closestTD.removeClass('has-error');
3388 }, 5000);
3389 showAlert('required');
3390 return false;
3391 }
3392 showLoading('waiting');
3393 element_data.hostName = newHostname;
3394 service.editHostName({
3395 hostname: element_data.hostName,
3396 mac: element_data.macAddress
3397 }, function () {
3398 editingHostname = 0;
3399 service.getHostNameList({}, function (data) {
3400 hostNameList = data.devices;
3401 if (element_data.type == 3) {
3402 target.fetchBlacklist(function () {
3403 hideLoading();
3404 successOverlay();
3405 });
3406 } else if (element_data.type == 2) {
3407 target.fetchAttachedCableDevices(function () {
3408 hideLoading();
3409 successOverlay();
3410 });
3411 } else if (element_data.type == 1) {
3412 target.fetchAttachedDevices(function () {
3413 hideLoading();
3414 successOverlay();
3415 });
3416 }
3417 });
3418 }, function () {
3419 errorOverlay();
3420 });
3421 }
3422
3423 function stationBlockEvent(element_data) {
3424 if (config.HAS_BLACK_AND_WHITE_FILTER && originalData.ACL_mode != '2') {
3425 return false;
3426 }
3427 if (originalData.macList.split(';').length == 10) {
3428 showAlert('black_list_max');
3429 return false;
3430 }
3431 if (originalData.macList.indexOf(element_data.macAddress) != -1) {
3432 return false;
3433 }
3434 if (element_data.ipAddress == originalData.user_ip) {
3435 showAlert('black_yourself_tip');
3436 return false;
3437 }
3438 if (editingHostname) {
3439 target.cancelAllEditHostNameHandler();
3440 }
3441 showLoading('waiting');
3442 var newHostnameList = originalData.hostnameList == '' ? element_data.hostName : element_data.hostName + ';' + originalData.hostnameList;
3443 var newMacList = originalData.macList == '' ? element_data.macAddress : element_data.macAddress + ';' + originalData.macList;
3444 var params = {
3445 ACL_mode: '2',
3446 wifi_hostname_black_list: newHostnameList,
3447 wifi_mac_black_list: newMacList
3448 };
3449 target.updateMacFilterList(params);
3450 }
3451
3452 }
3453
3454 function bindContainer(ws_vm) {
3455 var container = $('#container')[0];
3456 ko.cleanNode(container);
3457 ko.applyBindings(ws_vm, container);
3458 }
3459 function initialize() {
3460 var ws_vm = new staInfoViewMode();
3461 bindContainer(ws_vm);
3462 }
3463
3464 return {
3465 init: initialize
3466 };
3467});
3468
3469define("wifi_wps","underscore jquery knockout set service".split(" "),
3470 function (_, $, ko, config, service) {
3471
3472 var viaWifi = false;
3473
3474 function WpsViewMode() {
3475 var target = this;
3476 target.hasMultiSSID = config.HAS_MULTI_SSID;
3477 target.hasAPStation = config.AP_STATION_SUPPORT;
3478 target.hasWifiSwitch = config.WIFI_SWITCH_SUPPORT;
3479 target.hasWlanMacfilter = config.HAS_BLACK_AND_WHITE_FILTER;
3480
3481 target.wpsType = ko.observable('');
3482 target.wpsPin = ko.observable('');
3483
3484 var state = getWpsState();
3485 target.origin_ap_station_enable = state.ap_station_enable;
3486
3487 target.wpsFlag = ko.observable(state.wpsFlag);
3488 target.authMode = ko.observable(state.authMode);
3489
3490 target.radioFlag = ko.observable(state.radioFlag);
3491 target.encrypType = ko.observable(state.encrypType);
3492
3493 target.mulOption = ko.observable(paintSSIDOption(state));
3494 target.wpsSSID = ko.observable(getSSIDCurrWps(state));
3495
3496 var infoBasic = service.getWifiBasic();
3497 target.wifi_enable = ko.observable(infoBasic.wifi_enable);
3498
3499 target.isShowSSIDInfoDiv = ko.observable(false);
3500 if (config.WIFI_SWITCH_SUPPORT) { //软开关
3501 if (infoBasic.wifi_enable == "1") {
3502 target.isShowSSIDInfoDiv(true);
3503 } else {
3504 target.isShowSSIDInfoDiv(false);
3505 }
3506 } else {
3507 target.isShowSSIDInfoDiv(true);
3508 }
3509 target.multi_ssid_enable = ko.observable(infoBasic.multi_ssid_enable);
3510 target.origin_multi_ssid_enable = infoBasic.multi_ssid_enable;
3511
3512 target.save = wpa_save;
3513
3514 // if (state.wpsFlag != '0') {
3515 // target.wpsType(state.wpsType == 'PIN' ? 'PIN' : 'PBC');
3516 // } else {
3517 // target.wpsType('');
3518 // }
3519 target.wpsType(state.wpsType == 'PIN' ? 'PIN' : 'PBC');
3520
3521 target.setMultiSSIDSwitch = function () {
3522 if (target.checkSettings("switch")) {
3523 return;
3524 }
3525
3526 function wpsSetSwitch() {
3527 showLoading('waiting');
3528 var wps_param = {};
3529 wps_param.m_ssid_enable = target.multi_ssid_enable();
3530 if (config.WIFI_SWITCH_SUPPORT) {
3531 wps_param.wifiEnabled = target.wifi_enable();
3532 }
3533 service.setWifiBasicMultiSSIDSwitch(wps_param, function (result) {
3534 if (result.result == "success") {
3535 if (!viaWifi) {
3536 addInterval(wpsReload, 1000);
3537 } else {
3538 setTimeout(wpsReloadViaWifi, 15000);
3539 }
3540 } else {
3541 errorOverlay();
3542 }
3543 });
3544 }
3545
3546 var setSwitch = wpsSetSwitch;
3547 var state = service.getStatusInfo();
3548 if (target.wifi_enable() == "1" && config.HAS_MULTI_SSID) {
3549 if (target.multi_ssid_enable() == "1" && config.AP_STATION_SUPPORT && target.origin_ap_station_enable == "1") {
3550 if (!state.wifiStatus) {
3551 showConfirm("multi_ssid_enable_confirm", function () {
3552 setSwitch();
3553 });
3554 } else {
3555 showConfirm("multi_ssid_enable_confirm2", function () {
3556 setSwitch();
3557 });
3558 }
3559 } else {
3560 if (!state.wifiStatus) {
3561 setSwitch();
3562 } else {
3563 showConfirm("wifi_disconnect_confirm2", function () {
3564 setSwitch();
3565 });
3566 }
3567 }
3568 } else {
3569 setSwitch();
3570 }
3571
3572 function wpsReload() {
3573 var state = service.getWifiBasic();
3574 if (state.wifi_enable == target.wifi_enable()) {
3575 successOverlay();
3576 clearTimer();
3577 clearValidateMsg();
3578 service.refreshAPStationStatus();
3579 initialize();
3580 }
3581 }
3582 function wpsReloadViaWifi() {
3583 successOverlay();
3584 setTimeout(function () {
3585 window.location.reload();
3586 }, 1000);
3587 clearTimer();
3588 clearValidateMsg();
3589 service.refreshAPStationStatus();
3590 initialize();
3591 }
3592
3593 };
3594
3595 target.checkSettings = function (ssid) {
3596 var state = getWpsState();
3597 if (state.wpsFlag == '1') {
3598 showAlert('wps_on_info', function() {
3599 window.location.reload();
3600 });
3601 return true;
3602 }
3603 return false;
3604 };
3605
3606 function wpa_save() {
3607 var state = getWpsState();
3608
3609 if (state.radioFlag == '0') {
3610 showAlert('wps_wifi_off');
3611 return;
3612 }
3613
3614 if (state.wpsFlag == '1') {
3615 showAlert('wps_on_info', function() {
3616 window.location.reload();
3617 });
3618 return true;
3619 }
3620
3621 if (target.wpsSSID() == "SSID1") {
3622 var res = (state.AuthMode == "OPEN" && state.encrypType == "WEP")
3623 || (state.AuthMode == "SHARED" && state.encrypType == "WEP")
3624 || (state.AuthMode == "WPAPSK" && state.encrypType == "TKIP")
3625 || (state.AuthMode == "WPAPSK" && state.encrypType == "TKIPCCMP")
3626 || (state.AuthMode == "WPAPSK" && state.encrypType == "AES")
3627 || (state.AuthMode == "WPA2PSK" && state.encrypType == "TKIP")
3628 || (state.AuthMode == "WPAPSKWPA2PSK" && state.encrypType == "TKIP")
3629 || (state.AuthMode == "WPA3Personal")
3630 || (state.AuthMode == "WPA2WPA3");
3631 if (res) {
3632 showAlert('wps_auth_open');
3633 return;
3634 }
3635 } else {
3636 var resm = (state.m_AuthMode == "OPEN" && state.m_encrypType == "WEP")
3637 || (state.m_AuthMode == "SHARED" && state.m_encrypType == "WEP")
3638 || (state.m_AuthMode == "WPAPSK" && state.m_encrypType == "TKIP")
3639 || (state.m_AuthMode == "WPAPSK" && state.m_encrypType == "TKIPCCMP")
3640 || (state.m_AuthMode == "WPAPSK" && state.m_encrypType == "AES")
3641 || (state.m_AuthMode == "WPA2PSK" && state.m_encrypType == "TKIP")
3642 || (state.m_AuthMode == "WPAPSKWPA2PSK" && state.m_encrypType == "TKIP")
3643 || (state.m_AuthMode == "WPA3Personal")
3644 || (state.m_AuthMode == "WPA2WPA3");
3645 if (resm) {
3646 showAlert('wps_auth_open');
3647 return;
3648 }
3649 }
3650
3651 var wpsSSID;
3652 var wpsIndex;
3653 if (target.wpsSSID() != "SSID1") {
3654 wpsSSID = state.multiSSID;
3655 wpsIndex = 2;
3656 } else {
3657 wpsSSID = state.ssid;
3658 wpsIndex = 1;
3659 }
3660
3661 var basic = service.getWifiBasic();
3662 if (wpsSSID == basic.m_SSID && wpsIndex == 2) {
3663 if (basic.m_broadcast == '1') {
3664 showAlert('wps_ssid_broadcast_disable');
3665 return;
3666 }
3667 } else if (wpsSSID == basic.SSID && wpsIndex == 1) {
3668 if (basic.broadcast == '1') {
3669 showAlert('wps_ssid_broadcast_disable');
3670 return;
3671 }
3672 }
3673
3674 showLoading('waiting');
3675 var wps_param = {};
3676 wps_param.wpsType = target.wpsType();
3677 wps_param.wpsSSID = wpsSSID;
3678 wps_param.wpsIndex = wpsIndex;
3679 wps_param.wpsPin = getWpsPin(target.wpsPin());
3680
3681 service.openWps(wps_param, function (result) {
3682 if (result.result != "success") {
3683 errorOverlay();
3684 } else {
3685 target.wpsPin('');
3686 clearValidateMsg();
3687 successOverlay();
3688 }
3689 });
3690 }
3691
3692 }
3693
3694 function getWpsPin(value) {
3695 if (value.length != 9) {
3696 return value;
3697 } else {
3698 return value.substring(0, 4) + value.substring(5);
3699 }
3700 }
3701
3702 function getWpsState() {
3703 return service.getWpsInfo();
3704 }
3705
3706 function paintSSIDOption(info) {
3707 var show_opt = [];
3708 show_opt.push(new Option(info.ssid, "SSID1"));
3709 if (info.ssidEnable == "1") {
3710 show_opt.push(new Option(info.multiSSID, "SSID2"));
3711 }
3712 return show_opt;
3713 }
3714
3715 //检查当前是否通过wifi登录webui
3716 function checkAccessMode() {
3717 service.getParams({
3718 nv: 'user_ip_addr'
3719 }, function (dataIp) {
3720 service.getParams({
3721 nv: 'station_list'
3722 }, function (dataList) {
3723 viaWifi = isWifiConnected(dataIp.user_ip_addr, dataList.station_list);
3724 });
3725 });
3726 }
3727 function bindContainer(wpsVm) {
3728 var container = $('#container');
3729 ko.cleanNode(container[0]);
3730 ko.applyBindings(wpsVm, container[0]);
3731
3732 addTimeout(function () {
3733 checkAccessMode();
3734 }, 600);
3735
3736 $('#wpsForm').validate({
3737 submitHandler: function () {
3738 wpsVm.save();
3739 },
3740 rules: {
3741 txtPin: {
3742 "wps_pin_validator": true
3743 }
3744 }
3745 });
3746
3747 $('#frmWifiSwitch').validate({
3748 submitHandler: function () {
3749 wpsVm.setMultiSSIDSwitch();
3750 }
3751 });
3752 }
3753 function getSSIDCurrWps(info) {
3754 if (info.ssid != info.multiSSID) {
3755 return info.wpsSSID == info.multiSSID ? "SSID2" : "SSID1";
3756 } else {
3757 if (info.wifi_wps_index == '2') {
3758 return "SSID2";
3759 } else {
3760 return "SSID1";
3761 }
3762 }
3763 }
3764 //视图初始化
3765 function initialize() {
3766 var wpsVm = new WpsViewMode();
3767 bindContainer(wpsVm);
3768 }
3769
3770 return {
3771 init: initialize
3772 };
3773});
3774