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