blob: 22b3ff89d24f11d9070f27ffb0dfd3e86e4d5aab [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001
2define("firewall_url_filter","underscore jquery knockout set service".split(" "),
3 function (_, $, ko, config, service) {
4
5 //system url filter setting VM
6
7 function UrlFilterSettingVM() {
8 var target = this;
9 var urlFltInfo = service.getUrlFilterList();
10 var columnsTmpl = [{
11 columnType: "checkbox",
12 rowText: "index",
13 width: "30%"
14 }, {
15 headerTextTrans: "url",
16 rowText: "url",
17 width: "70%"
18 }
19 ];
20 target.rules = ko.observableArray(urlFltInfo.urlFilterRules);
21
22 target.gridTemplate = new ko.simpleGrid.viewModel({
23 data: target.rules(),
24 idName: "index",
25 columns: columnsTmpl,
26 tmplType: 'list',
27 pageSize: 10
28 });
29
30 target.clear = clearFunc;
31
32 target.callback = callbackFunc;
33 //删除规则
34
35 target.deleteRule = deleteRuleFunc;
36
37 //添加规则
38
39 target.addRule = addRuleFunc;
40 function callbackFunc(elem) {
41 if (elem.result != "success") {
42 errorOverlay();
43 } else {
44 target.clear();
45 initialize(target);
46 successOverlay();
47 $("#urlFilters").translate();
48 }
49 }
50
51 //添加规则
52 function addRuleFunc() {
53 if (target.rules().length >= config.urlFilterMax) {
54 showAlert({
55 msg: "url_filter_max",
56 params: config.urlFilterMax
57 });
58 return false;
59 }
60 var tmpArr = [];
61 for (var idx = 0; idx < target.rules().length; idx++) {
62 tmpArr.push(target.rules()[idx].url);
63 }
64 if ($.inArray($("#addURLFilter").val(), tmpArr) != -1) {
65 showAlert("url_repeated");
66 return false;
67 }
68
69 showLoading();
70 var urlFltParams = {
71 goformId: "URL_FILTER_ADD",
72 addURLFilter: $("#addURLFilter").val()
73 };
74 service.addUrlFilterRule(urlFltParams, target.callback);
75 }
76 //删除规则
77 function deleteRuleFunc() {
78 showConfirm('confirm_data_delete', function () {
79 showLoading();
80 var urlFltParams = {
81 goformId: "URL_FILTER_DELETE",
82 url_filter_delete_id: target.gridTemplate.selectedIds().join(";") + ";"
83 };
84 service.deleteSelectedRules(urlFltParams, target.callback);
85 });
86 }
87
88 }
89
90 function clearFunc() {
91 $("#addURLFilter").val("");
92 }
93
94 //页面初始化
95
96 function initialize() {
97
98 var vm = new UrlFilterSettingVM();
99 bindContainer(vm);
100 }
101 function bindContainer(vm){
102 var container = $('#container');
103 ko.cleanNode(container[0]);
104 ko.applyBindings(vm, container[0]);
105 $('#urlFilterForm').validate({
106 submitHandler: function () {
107 vm.addRule();
108 },
109 rules: {
110 addURLFilter: 'url_filter_check'
111 }
112 });
113
114 $("#urlFilterListForm").validate({
115 submitHandler: function () {
116 vm.deleteRule();
117 }
118 });
119 }
120
121 return {
122 init: initialize
123 };
124});
125
126define("firewall_upnp_set","underscore jquery knockout set service".split(" "),
127 function (_, $, ko, config, service) {
128
129 //system upnp setting VM
130
131 function UpnpSettingVM() {
132 var target = this;
133 var upnpInfo = getUpnpSetting();
134
135 target.upnpSetting = ko.observable(upnpInfo.upnpSetting);
136
137 target.save = saveFunc;
138 function saveFunc() {
139 showLoading();
140 var upnpParams = {};
141 upnpParams.upnpSetting = target.upnpSetting();
142 service.setUpnpSetting(upnpParams, function (rlt) {
143 if (rlt.result == "success") {
144 successOverlay();
145 } else {
146 errorOverlay();
147 }
148 });
149
150 }
151 }
152
153
154 //获取upnp 信息
155
156 function getUpnpSetting() {
157 return service.getUpnpSetting();
158 }
159
160 //初始化UpnpSettingVM model
161
162 function initialize() {
163
164 var vm = new UpnpSettingVM();
165 bindContainer(vm);
166
167 }
168 function bindContainer(vm) {
169 var container = $('#container');
170 ko.cleanNode(container[0]);
171 ko.applyBindings(vm, container[0]);
172 $('#upnpSettingForm').validate({
173 submitHandler: function () {
174 vm.save();
175 }
176 });
177 }
178
179 return {
180 init: initialize
181 };
182});
183
184define("firewall_upnp_set","underscore jquery knockout set service".split(" "),
185 function (_, $, ko, config, service) {
186
187 //system upnp setting VM
188
189 function UpnpSettingVM() {
190 var target = this;
191 var upnpInfo = getUpnpSetting();
192
193 target.upnpSetting = ko.observable(upnpInfo.upnpSetting);
194
195 target.save = saveFunc;
196 function saveFunc() {
197 showLoading();
198 var upnpParams = {};
199 upnpParams.upnpSetting = target.upnpSetting();
200 service.setUpnpSetting(upnpParams, function (rlt) {
201 if (rlt.result == "success") {
202 successOverlay();
203 } else {
204 errorOverlay();
205 }
206 });
207
208 }
209 }
210
211
212 //获取upnp 信息
213
214 function getUpnpSetting() {
215 return service.getUpnpSetting();
216 }
217
218 //初始化UpnpSettingVM model
219
220 function initialize() {
221
222 var vm = new UpnpSettingVM();
223 bindContainer(vm);
224
225 }
226 function bindContainer(vm) {
227 var container = $('#container');
228 ko.cleanNode(container[0]);
229 ko.applyBindings(vm, container[0]);
230 $('#upnpSettingForm').validate({
231 submitHandler: function () {
232 vm.save();
233 }
234 });
235 }
236
237 return {
238 init: initialize
239 };
240});
241
242//端口映射
243
244define("firewall_port_map","underscore jquery knockout set service".split(" "),
245 function (_, $, ko, config, service) {
246
247 var protocolModes = _.map(config.MAP_PROTOCOL_MODES, function (ele) {
248 return new Option(ele.name, ele.value);
249 });
250
251 var columnsTmpl = [{
252 columnType: "checkbox",
253 rowText: "index",
254 width: "8%"
255 }, {
256 headerTextTrans: "source_port",
257 rowText: "sourcePort",
258 width: "20%"
259 }, {
260 headerTextTrans: "dest_ip_address",
261 rowText: "destIpAddress",
262 width: "20%"
263 }, {
264 headerTextTrans: "dest_port",
265 rowText: "destPort",
266 width: "20%"
267 }, {
268 headerTextTrans: "protocol",
269 rowText: "protocol",
270 width: "12%"
271 }, {
272 headerTextTrans: "comment",
273 rowText: "comment",
274 width: "20%"
275 }
276 ];
277
278 //prot_map VM
279
280 function PortMapVM() {
281 var target = this;
282 var mapInfo = getPortMap();
283
284 target.oriPortMapEnable = ko.observable(mapInfo.portMapEnable);
285 target.rules = ko.observableArray(mapInfo.portMapRules);
286 target.portMapEnable = ko.observable(mapInfo.portMapEnable);
287
288
289 target.comment = ko.observable('');
290 target.selectedMode = ko.observable('TCP&UDP');
291 target.modes = ko.observableArray(protocolModes);
292
293 target.destPort = ko.observable('');
294 target.destIpAddress = ko.observable('');
295 target.sourcePort = ko.observable('');
296
297
298
299 target.gridTemplate = new ko.simpleGrid.viewModel({
300 data: target.rules(),
301 idName: "index",
302 columns: columnsTmpl,
303 tmplType: 'list',
304 pageSize: 10
305 });
306
307 //设定,新增,删除回调函数
308
309 target.callback = callbackFunc;
310
311 //删除规则
312
313 target.deleteMapRules = deleteMapRulesFunc;
314
315 //检查新增规则是否已经存在
316
317 target.checkExist = checkExistFunc;
318
319 //设定端口映射
320
321 target.enablePortMap = enablePortMapFunc;
322
323 //保存规则
324
325 target.save = saveFunc;
326
327 //保存规则
328 function saveFunc() {
329 if (target.rules().length >= config.portForwardMax) {
330 showAlert({
331 msg: "rules_max",
332 params: config.portForwardMax
333 });
334 return;
335 }
336
337 if (target.checkExist()) {
338 showAlert("rule_exist");
339 return;
340 }
341
342 showLoading();
343 var mapParams = {};
344 mapParams.portMapEnable = target.portMapEnable();
345 mapParams.sourcePort = target.sourcePort();
346 mapParams.destIpAddress = target.destIpAddress();
347 mapParams.destPort = target.destPort();
348 mapParams.protocol = target.selectedMode();
349 mapParams.comment = target.comment();
350 service.setPortMap(mapParams, target.callback);
351 }
352
353 //检查新增规则是否已经存在
354 function checkExistFunc() {
355 var newMapRule = {
356 sourcePort: target.sourcePort(),
357 destIpAddress: target.destIpAddress(),
358 destPort: target.destPort(),
359 protocol: transProtocolValue(target.selectedMode())
360 };
361
362 var oldMapRule;
363 var mapRules = target.rules();
364 for (var idx = 0; idx < mapRules.length; idx++) {
365 oldMapRule = {
366 sourcePort: mapRules[idx].sourcePort,
367 destIpAddress: mapRules[idx].destIpAddress,
368 destPort: mapRules[idx].destPort,
369 protocol: mapRules[idx].protocol
370 };
371
372 if (_.isEqual(newMapRule, oldMapRule)) {
373 return true;
374 }
375 }
376 return false;
377 }
378
379 //设定端口映射
380 function enablePortMapFunc() {
381 showLoading();
382 var mapParams = {};
383 mapParams.portMapEnable = target.portMapEnable();
384 service.enablePortMap(mapParams, target.callback);
385 }
386
387 //删除规则
388 function deleteMapRulesFunc() {
389 var ids = target.gridTemplate.selectedIds();
390 if (ids.length == 0) {
391 showAlert("no_data_selected");
392 return;
393 }
394
395 showConfirm("confirm_data_delete", function () {
396 showLoading();
397 var mapParams = {};
398 mapParams.indexs = ids;
399 service.deleteMapRules(mapParams, target.callback);
400 });
401 }
402
403 //设定,新增,删除回调函数
404 function callbackFunc(ret) {
405 if (ret.result == "success") {
406 clear();
407 initialize(target);
408 successOverlay();
409 } else {
410 errorOverlay();
411 }
412 }
413
414 //情况添加规则输入
415
416 function clear() {
417 target.sourcePort('');
418 target.destIpAddress('');
419 target.destPort('');
420 target.selectedMode('TCP&UDP');
421 target.comment('');
422 }
423 }
424
425 //获取port map信息
426
427 function getPortMap() {
428 return service.getPortMap();
429 }
430
431 function bindingContainer(vm){
432 var container = $('#container');
433 ko.cleanNode(container[0]);
434 ko.applyBindings(vm, container[0]);
435
436 }
437 //初始化port map view model
438
439 function initialize(viewModel) {
440 var vm;
441 if (viewModel) {
442 vm = viewModel;
443 var mapInfo = getPortMap();
444 vm.portMapEnable(mapInfo.portMapEnable);
445 vm.oriPortMapEnable(mapInfo.portMapEnable);
446 vm.rules(mapInfo.portMapRules);
447 vm.gridTemplate.clearAllChecked();
448 vm.gridTemplate.data(mapInfo.portMapRules);
449 refreshTableHeight();
450 renderCheckbox();
451 return;
452 }
453
454 vm = new PortMapVM();
455 bindingContainer(vm);
456 fixTableHeight();
457
458 $('#mapBasicForm').validate({
459 submitHandler: function () {
460 vm.enablePortMap();
461 }
462 });
463
464 $('#portMapListForm').validate({
465 submitHandler: function () {
466 vm.deleteMapRules();
467 }
468 });
469
470 $('#portMapForm').validate({
471 submitHandler: function () {
472 vm.save();
473 },
474 rules: {
475 txtDestIpAddress: {
476 ip_check: true
477 },
478 txtSourcePort: {
479 digits: true,
480 range_except: [1, 65000]
481 },
482 txtDestPort: {
483 digits: true,
484 range_except: [1, 65000]
485 },
486 txtComment: {
487 comment_check: true
488 }
489 },
490 errorPlacement: function (error, element) {
491 if (element.attr("name") == "txtDestIpAddress") {
492 error.appendTo("#txtDestIpAddressErrorDiv");
493 } else if (element.attr("name") == "txtSourcePort") {
494 error.appendTo("#txtSourcePortErrorDiv");
495 } else if (element.attr("name") == "txtDestPort") {
496 error.appendTo("#txtDestPortErrorDiv");
497 } else
498 error.insertAfter(element);
499 }
500 });
501 }
502
503 return {
504 init: initialize
505 };
506});
507
508//端口转发
509
510define("firewall_port_forward","underscore jquery knockout set service".split(" "),
511 function (_, $, ko, config, service) {
512
513 var protocolModes = _.map(config.FORWARD_PROTOCOL_MODES, function (ele) {
514 return new Option(ele.name, ele.value);
515 });
516 //列表模板的columns项
517
518 var columnsTmpl = [{
519 columnType: "checkbox",
520 rowText: "index",
521 width: "8%"
522 }, {
523 headerTextTrans: "ip_address",
524 rowText: "ipAddress",
525 width: "23%"
526 }, {
527 headerTextTrans: "port_range",
528 rowText: "portRange",
529 width: "23%"
530 }, {
531 headerTextTrans: "protocol",
532 rowText: "protocol",
533 width: "23%"
534 }, {
535 headerTextTrans: "comment",
536 rowText: "comment",
537 width: "23%"
538 }
539 ];
540
541 //prot_forward VM
542
543 function PortForwardVM() {
544 var target = this;
545 var fwdinfo = getPortForward();
546
547 target.portForwardEnable = ko.observable(fwdinfo.portForwardEnable);
548 target.oriPortForwardEnable = ko.observable(fwdinfo.portForwardEnable);
549
550 target.portEnd = ko.observable('');
551 target.portStart = ko.observable('');
552 target.ipAddress = ko.observable('');
553
554 target.comment = ko.observable('');
555 target.selectedMode = ko.observable('3');
556 target.modes = ko.observableArray(protocolModes);
557
558 target.rules = ko.observableArray(fwdinfo.portForwardRules);
559
560 //设定,新增,删除回调函数
561
562 target.callback = callbackFunc;
563
564 //创建列表模板
565
566 target.gridTemplate = new ko.simpleGrid.viewModel({
567 data: target.rules(),
568 idName: "index",
569 columns: columnsTmpl,
570 tmplType: 'list',
571 pageSize: 10
572 });
573
574 //检查新增规则是否已经存在
575
576 target.checkExist = checkExistFunc;
577
578 //保存规则
579
580 target.save = saveFunc;
581
582 //删除规则
583
584 target.deleteForwardRules = deleteForwardRulesFunc;
585
586 //设定虚拟服务器
587
588 target.enableVirtualServer = enableVirtualServerFunc;
589
590 //设定虚拟服务器
591 function enableVirtualServerFunc() {
592 showLoading();
593 var fwdParams = {};
594 fwdParams.portForwardEnable = target.portForwardEnable();
595 service.enableVirtualServer(fwdParams, target.callback);
596 }
597
598 //删除规则
599 function deleteForwardRulesFunc() {
600 var ids = target.gridTemplate.selectedIds();
601 if (ids.length == 0) {
602 showAlert("no_data_selected");
603 return;
604 }
605
606 showConfirm("confirm_data_delete", function () {
607 showLoading('deleting');
608 var fwdParams = {};
609 fwdParams.indexs = ids;
610 service.deleteForwardRules(fwdParams, target.callback);
611 });
612 }
613
614 //保存规则
615 function saveFunc() {
616 if (target.rules().length >= config.portForwardMax) {
617 showAlert({
618 msg: "rules_max",
619 params: config.portForwardMax
620 });
621 return;
622 }
623
624 if (target.checkExist()) {
625 showAlert("rule_exist");
626 return;
627 }
628
629 showLoading();
630 var fwdParams = {};
631 fwdParams.comment = target.comment();
632 fwdParams.protocol = target.selectedMode();
633 fwdParams.portEnd = target.portEnd();
634 fwdParams.portStart = target.portStart();
635 fwdParams.ipAddress = target.ipAddress();
636 service.setPortForward(fwdParams, target.callback);
637 }
638 //情况添加规则输入
639 function clear() {
640 target.ipAddress('');
641 target.portStart('');
642 target.portEnd('');
643 target.selectedMode('TCP&UDP');
644 target.comment('');
645 }
646
647 //设定,新增,删除回调函数
648 function callbackFunc(ret) {
649 if (ret.result == "success") {
650 clear();
651 initialize(target);
652 successOverlay();
653 } else {
654 errorOverlay();
655 }
656 }
657
658 //检查新增规则是否已经存在
659 function checkExistFunc() {
660 var newRule = {
661 ipAddress: target.ipAddress(),
662 portRange: target.portStart() + ' - ' + target.portEnd(),
663 protocol: transProtocolValue(target.selectedMode())
664 };
665
666 var oldRule;
667 var fwdrules = target.rules();
668 for (var ki = 0; ki < fwdrules.length; ki++) {
669 oldRule = {
670 ipAddress: fwdrules[ki].ipAddress,
671 portRange: fwdrules[ki].portRange,
672 protocol: fwdrules[ki].protocol
673 };
674
675 if (_.isEqual(newRule, oldRule)) {
676 return true;
677 }
678 }
679 return false;
680 }
681 }
682
683 //获取port forward信息
684
685 function getPortForward() {
686 return service.getPortForward();
687 }
688
689 //初始化port forward view model
690
691 function initialize(viewModel) {
692 var vm;
693 if (viewModel) {
694 vm = viewModel;
695 var fwdinfo = getPortForward();
696 vm.gridTemplate.clearAllChecked();
697 vm.gridTemplate.data(fwdinfo.portForwardRules);
698 vm.rules(fwdinfo.portForwardRules);
699 vm.portForwardEnable(fwdinfo.portForwardEnable);
700 vm.oriPortForwardEnable(fwdinfo.portForwardEnable);
701 refreshTableHeight();
702 return;
703 }
704
705 vm = new PortForwardVM();
706 bindContainer(vm);
707
708 fixTableHeight();
709 renderCheckbox();
710
711 $('#virtualServerForm').validate({
712 submitHandler: function () {
713 vm.enableVirtualServer();
714 }
715 });
716
717 $('#portForwardListForm').validate({
718 submitHandler: function () {
719 vm.deleteForwardRules();
720 }
721 });
722
723 $('#portForwardForm').validate({
724 submitHandler: function () {
725 vm.save();
726 },
727 rules: {
728 txtIpAddress: {
729 ip_check: true
730 },
731 txtPortStart: {
732 digits: true,
733 range: [1, 65535],
734 portCompare: "#txtPortEnd"
735 },
736 txtPortEnd: {
737 digits: true,
738 range: [1, 65535],
739 portCompare: "#txtPortStart"
740 },
741 txtComment: {
742 comment_check: true
743 }
744 },
745 groups: {
746 range: "txtPortStart txtPortEnd"
747 },
748 errorPlacement: function (error, element) {
749 if (element.attr("name") == "txtIpAddress") {
750 error.appendTo("#ipErrorDiv");
751 } else if (element.attr("name") == "txtPortStart" || element.attr("name") == "txtPortEnd") {
752 error.appendTo("#portRangeErrorDiv");
753 } else
754 error.insertAfter(element);
755 }
756 });
757 }
758
759 function bindContainer(vm){
760 var container = $('#container');
761 ko.cleanNode(container[0]);
762 ko.applyBindings(vm, container[0]);
763
764 }
765
766
767 return {
768 init: initialize
769 };
770});
771
772define("firewall_port_filter","underscore jquery knockout set service".split(" "),
773 function (_, $, ko, config, service) {
774
775 var PROTOCOLS = {
776 ICMP: 'ICMP',
777 NONE: 'None'
778 };
779
780 var columnsTmpl = [{
781 columnType: "checkbox",
782 rowText: "index",
783 width: "4%"
784 }, {
785 headerTextTrans: "mac_address",
786 rowText: "macAddress",
787 width: "12%"
788 }, {
789 headerTextTrans: "ip_type",
790 rowText: "ipType",
791 width: "5%",
792 display: config.IPV6_SUPPORT
793 }, {
794 headerTextTrans: "source_ip_address",
795 rowText: "sourceIpAddress",
796 width: "12%"
797 }, {
798 headerTextTrans: "dest_ip_address",
799 rowText: "destIpAddress",
800 width: "12%"
801 }, {
802 headerTextTrans: "protocol",
803 rowText: "protocol",
804 width: "12%",
805 needTrans: true
806 }, {
807 headerTextTrans: "source_port_range",
808 rowText: "sourcePortRange",
809 width: "12%"
810 }, {
811 headerTextTrans: "dest_port_range",
812 rowText: "destPortRange",
813 width: "12%"
814 }, {
815 headerTextTrans: "port_filter_action",
816 rowText: "action",
817 width: "12%",
818 needTrans: true
819 }, {
820 headerTextTrans: "comment",
821 rowText: "comment",
822 width: "12%"
823 }
824 ];
825
826 var protocolModes = _.map(config.FILTER_PROTOCOL_MODES, function (elem) {
827 return new Option(elem.name, elem.value);
828 });
829 //prot_filter VM
830
831 function PortFilterVM() {
832 var target = this;
833 var info = getPortFilter();
834
835 target.oriDefaultPolicy = ko.observable(info.defaultPolicy);
836 target.defaultPolicy = ko.observable(info.defaultPolicy);
837 target.oriPortFilterEnable = ko.observable(info.portFilterEnable);
838 target.portFilterEnable = ko.observable(info.portFilterEnable);
839 target.rules = ko.observableArray(info.portFilterRules);
840
841 target.ipv6Support = ko.observable(config.IPV6_SUPPORT);
842 target.comment = ko.observable('');
843 target.selectedMode = ko.observable('5');
844 target.modes = ko.observableArray(protocolModes);
845 target.sourcePortEnd = ko.observable('');
846 target.sourcePortStart = ko.observable('');
847 target.destPortEnd = ko.observable('');
848 target.destPortStart = ko.observable('');
849 target.destIpv6Address = ko.observable('');
850 target.sourceIpv6Address = ko.observable('');
851 target.sourceIpAddress = ko.observable('');
852 target.destIpAddress = ko.observable('');
853 target.macAddress = ko.observable('');
854 target.portFilterAction = ko.observable('');
855
856 target.ipType = ko.observable('ipv4');
857
858 //设定,新增,删除回调函数
859
860 target.callback = callbackFunc;
861
862 //创建列表模板
863
864 target.gridTemplate = new ko.simpleGrid.viewModel({
865 data: target.rules(),
866 idName: "index",
867 columns: columnsTmpl,
868 tmplType: 'list',
869 pageSize: 20
870 });
871 //default policy change handler
872
873 target.policyChangeHandler = policyChangeHandlerFunc;
874
875 //保存规则
876
877 target.save = saveFunc;
878
879 //设定过滤基本信息
880
881 target.setPortFilterBasic = setPortFilterBasicFunc;
882
883 //清空添加规则输入
884
885 target.clear = clearFunc;
886
887 //检查新增规则是否已经存在
888
889 target.checkExist = checkExistFunc;
890
891 //ip类型变化事件监听
892
893 target.ipTypeChangeHandler = ipTypeChangeHandlerFunc;
894
895 //协议变化事件监听
896
897 target.protocolChangeHandler = protocolChangeHandlerFunc;
898
899 //删除规则
900
901 target.deleteFilterRules = deleteFilterRulesFunc;
902
903 //init to call
904 target.policyChangeHandler();
905
906 //设定,新增,删除回调函数
907 function callbackFunc(ret) {
908 if (ret.result != "success") {
909 errorOverlay();
910 } else {
911 target.clear();
912 initialize(target);
913 successOverlay();
914 }
915 }
916 //default policy change handler
917 function policyChangeHandlerFunc() {
918 var action = target.defaultPolicy() != "1" ? "Drop" : "Accept";
919 target.portFilterAction(action);
920 return true;
921 }
922
923 //保存规则
924 function saveFunc() {
925 target.sourceIpAddress(target.sourceIpAddress().replace(/\s+/g, ''));
926 target.destIpAddress(target.destIpAddress().replace(/\s+/g, ''));
927 target.sourceIpv6Address(target.sourceIpv6Address().replace(/\s+/g, ''));
928 target.destIpv6Address(target.destIpv6Address().replace(/\s+/g, ''));
929 target.macAddress(target.macAddress().replace(/\s+/g, ''));
930 if (target.ipv6Support() == false) {
931 if (target.rules().length >= config.portForwardMax) {
932 showAlert({
933 msg: "rules_max",
934 params: config.portForwardMax
935 });
936 return;
937 }
938
939 if (target.checkExist()) {
940 showAlert("rule_exist");
941 return;
942 }
943
944 } else {
945 var type = target.ipType() == "ipv4" ? "IPv4" : "IPv6";
946 var oldRules = _.filter(target.rules(), function (item) {
947 return item.ipType == type;
948 });
949
950 if (oldRules.length >= config.portForwardMax) {
951 showAlert({
952 msg: "rules_max_v4v6",
953 params: [type, config.portForwardMax]
954 });
955 return;
956 }
957
958 if (target.checkExist()) {
959 showAlert({
960 msg: "rule_exist_v4v6",
961 params: type
962 });
963 return;
964 }
965 }
966 showConfirm("confirm_data_effect", function () {
967 showLoading();
968 var fltParams = {};
969 fltParams.macAddress = target.macAddress();
970
971 if (target.ipv6Support() && target.ipType() != 'ipv6') {
972 fltParams.destIpAddress = target.destIpAddress();
973 fltParams.sourceIpAddress = target.sourceIpAddress();
974 } else {
975 fltParams.destIpAddress = target.destIpv6Address();
976 fltParams.sourceIpAddress = target.sourceIpv6Address();
977 }
978
979 fltParams.ipType = target.ipType();
980 fltParams.comment = target.comment();
981 fltParams.protocol = target.selectedMode();
982 fltParams.action = target.portFilterAction();
983 fltParams.sourcePortEnd = target.sourcePortEnd();
984 fltParams.sourcePortStart = target.sourcePortStart();
985 fltParams.destPortEnd = target.destPortEnd();
986 fltParams.destPortStart = target.destPortStart();
987 service.setPortFilter(fltParams, target.callback);
988 });
989 }
990
991 //设定过滤基本信息
992 function setPortFilterBasicFunc() {
993 showLoading();
994 var elems = {};
995 elems.defaultPolicy = target.defaultPolicy();
996 elems.portFilterEnable = target.portFilterEnable();
997 service.setPortFilterBasic(elems, target.callback);
998 }
999 //清空添加规则输入
1000 function clearFunc() {
1001 target.comment('');
1002 target.selectedMode('None');
1003 target.sourcePortEnd('0');
1004 target.sourcePortStart('0');
1005 target.destPortEnd('0');
1006 target.destPortStart('0');
1007 target.sourceIpv6Address('');
1008 target.sourceIpAddress('');
1009 target.destIpv6Address('');
1010 target.destIpAddress('');
1011 target.macAddress('');
1012 clearValidateMsg();
1013 }
1014
1015 //检查新增规则是否已经存在
1016 function checkExistFunc() {
1017 target.macAddress(target.macAddress().toUpperCase());
1018 var currIpType = target.ipType().toUpperCase();
1019 var newRule = {
1020 macAddress: target.macAddress(),
1021 destIpAddress: currIpType == "IPV4" ? target.destIpAddress() : target.destIpv6Address(),
1022 sourceIpAddress: currIpType == "IPV4" ? target.sourceIpAddress() : target.sourceIpv6Address(),
1023 destPortRange: target.destPortStart() == '0' ? '' : target.destPortStart() + ' - ' + target.destPortEnd(),
1024 sourcePortRange: target.sourcePortStart() == '0' ? '' : target.sourcePortStart() + ' - ' + target.sourcePortEnd(),
1025 action: target.portFilterAction() == "Drop" ? "filter_drop" : "filter_accept",
1026 protocol: transProtocolValue(target.selectedMode()),
1027 ipType: currIpType
1028 };
1029
1030 var oldRule;
1031 var rules = target.rules();
1032 for (var ki = 0; ki < rules.length; ki++) {
1033 oldRule = {
1034 macAddress: rules[ki].macAddress,
1035 destIpAddress: rules[ki].destIpAddress,
1036 sourceIpAddress: rules[ki].sourceIpAddress,
1037 destPortRange: rules[ki].destPortRange,
1038 sourcePortRange: rules[ki].sourcePortRange,
1039 action: rules[ki].action,
1040 protocol: rules[ki].protocol,
1041 ipType: rules[ki].ipType.toUpperCase()
1042 };
1043
1044 if (_.isEqual(newRule, oldRule)) {
1045 return true;
1046 }
1047 }
1048 return false;
1049 }
1050
1051 //协议变化事件监听
1052 function protocolChangeHandlerFunc() {
1053 if (target.selectedMode() == PROTOCOLS.ICMP || target.selectedMode() == PROTOCOLS.NONE) {
1054 target.sourcePortEnd('0');
1055 target.sourcePortStart('0');
1056 target.destPortEnd('0');
1057 target.destPortStart('0');
1058 clearValidateMsg('#portRangeArea');
1059 } else {
1060 target.sourcePortEnd('65535');
1061 target.sourcePortStart('1');
1062 target.destPortEnd('65535');
1063 target.destPortStart('1');
1064 }
1065 return true;
1066 }
1067
1068 //删除规则
1069 function deleteFilterRulesFunc() {
1070 var ids = target.gridTemplate.selectedIds();
1071 if (ids.length == 0) {
1072 showAlert("no_data_selected");
1073 return;
1074 }
1075
1076 showConfirm("confirm_data_effect", function () {
1077 showLoading('deleting');
1078 var rules = {};
1079 rules.indexs = ids;
1080 service.deleteFilterRules(rules, target.callback);
1081 });
1082 }
1083
1084 }
1085
1086 //获取port filter信息
1087
1088 function getPortFilter() {
1089 return service.getPortFilter();
1090 }
1091
1092 //ip类型变化事件监听
1093 function ipTypeChangeHandlerFunc() {
1094 clearValidateMsg();
1095 return true;
1096 }
1097
1098 //初始化port filter view model
1099
1100 function initialize(viewModel) {
1101 var vm;
1102 if (viewModel) {
1103 vm = viewModel;
1104 var fltinfo = getPortFilter();
1105 vm.gridTemplate.clearAllChecked();
1106 vm.gridTemplate.data(fltinfo.portFilterRules);
1107 vm.defaultPolicy(fltinfo.defaultPolicy);
1108 vm.oriDefaultPolicy(fltinfo.defaultPolicy);
1109 vm.portFilterEnable(fltinfo.portFilterEnable);
1110 vm.oriPortFilterEnable(fltinfo.portFilterEnable);
1111 vm.rules(fltinfo.portFilterRules);
1112 refreshTableHeight();
1113 $('#portFilters').find('tbody').translate();
1114 renderCheckbox();
1115 $('.notes-content').translate();
1116 return;
1117 }
1118
1119 vm = new PortFilterVM();
1120 var container = $('#container');
1121 ko.cleanNode(container[0]);
1122 ko.applyBindings(vm, container[0]);
1123
1124 fixTableHeight();
1125
1126 $('#filterBasicForm').validate({
1127 submitHandler: function () {
1128 showConfirm("confirm_data_effect", function () {
1129 vm.setPortFilterBasic();
1130 });
1131 }
1132 });
1133
1134 $('#portFilterListForm').validate({
1135 submitHandler: function () {
1136 vm.deleteFilterRules();
1137 }
1138 });
1139
1140 $('#portFilterForm').validate({
1141 submitHandler: function () {
1142 vm.save();
1143 },
1144 rules: {
1145 txtMacAddress: {
1146 filter_optional: true,
1147 mac_check: true
1148 },
1149 txtDestIpAddress: {
1150 ip_check: true
1151 },
1152 txtSourceIpAddress: {
1153 ip_check: true
1154 },
1155 txtSourceIpv6Address: {
1156 ipv6: true
1157 },
1158 txtDestIpv6Address: {
1159 ipv6: true
1160 },
1161 txtDestPortStart: {
1162 digits: true,
1163 range: [1, 65535],
1164 portCompare: "#txtDestPortEnd"
1165 },
1166 txtDestPortEnd: {
1167 digits: true,
1168 range: [1, 65535],
1169 portCompare: "#txtDestPortStart"
1170 },
1171 txtSourcePortStart: {
1172 digits: true,
1173 range: [1, 65535],
1174 portCompare: "#txtSourcePortEnd"
1175 },
1176 txtSourcePortEnd: {
1177 digits: true,
1178 range: [1, 65535],
1179 portCompare: "#txtSourcePortStart"
1180 },
1181
1182 txtComment: {
1183 comment_check: true
1184 }
1185 },
1186 groups: {
1187 destPort: "txtDestPortStart txtDestPortEnd",
1188 sourcePort: "txtSourcePortStart txtSourcePortEnd"
1189 },
1190 errorPlacement: function (error, element) {
1191 if (element.attr("name") == "txtMacAddress") {
1192 error.appendTo("#macErrorDiv");
1193 } else if (element.attr("name") == "txtDestPortStart" || element.attr("name") == "txtDestPortEnd") {
1194 error.appendTo("#destPortErrorDiv");
1195 } else if (element.attr("name") == "txtSourcePortStart" || element.attr("name") == "txtSourcePortEnd") {
1196 error.appendTo("#sourcePortErrorDiv");
1197 } else
1198 error.insertAfter(element);
1199 }
1200 });
1201 }
1202
1203 $.validator.addMethod("filter_optional", function (value, element, param) {
1204 var result = _.any(['#txtMacAddress', '#txtDestIpAddress', '#txtSourceIpAddress', '#txtSourceIpv6Address', '#txtDestIpv6Address'],
1205 function (item) {
1206 var tmp = $(item).val().replace(/\s+/g, '');
1207 return $(item + ':visible').length > 0 && tmp != '';
1208 });
1209
1210 var portResult = _.any(['#txtDestPortStart', '#txtDestPortEnd', '#txtSourcePortStart', '#txtSourcePortEnd'],
1211 function (item) {
1212 return $(item).val() != '0';
1213 });
1214
1215 return result || portResult;
1216 });
1217
1218 return {
1219 init: initialize
1220 };
1221});
1222
1223//家长控制
1224
1225define("firewall_parental_control","underscore jquery knockout set service".split(" "),
1226 function (_, $, ko, config, service) {
1227
1228 var maxItem = 10;
1229 var pcVm = null;
1230 var PAGES = {
1231 MAIN: 0,
1232 MANAGE: 1,
1233 RULE: 2
1234 };
1235
1236
1237 function ParentalControlVM() {
1238 var target = this;
1239 var hostNameList = service.getHostNameList({}).devices;
1240 target.currentPage = ko.observable(PAGES.MAIN);
1241 target.pages = PAGES;
1242
1243
1244 target.childGroupList = ko.observable([]);
1245 target.childGroupMac = ko.computed(function () {
1246 return _.map(target.childGroupList(), function (data) {
1247 return data.mac;
1248 });
1249 });
1250
1251 target.currentUserInChildGroup = ko.observable(true);
1252 //获取儿童组设备列表
1253
1254 target.fetchChildGroupList = fetchChildGroupListFunc;
1255
1256 target.fetchChildGroupList();
1257
1258 target.manageHandler = manageHandlerFunc;
1259 function manageHandlerFunc() {
1260 target.currentPage(PAGES.MANAGE);
1261 target.fetchAttachedDevices();
1262 }
1263 target.attachedDevices = ko.observable([]);
1264 //获取已连接设备列表
1265
1266 target.fetchAttachedDevices = fetchAttachedDevicesFunc;
1267
1268
1269 //儿童组设备 标签按钮事件
1270
1271 target.backToMainHandler = backToMainHandlerFunc;
1272
1273
1274 ko.computed(function () {
1275 target.attachedDevices();
1276 target.childGroupList();
1277 $("#pc_children_group_form").translate();
1278 }).extend({
1279 notify: 'always',
1280 throttle: 300
1281 });
1282
1283 //添加至儿童组
1284
1285 function addChildGroupFun(flag, eleData) {
1286 showLoading();
1287 service.addChildGroup(eleData, function (data) {
1288 target.fetchChildGroupList(function () {
1289 target.fetchAttachedDevices(function () {
1290 hideLoading();
1291 if (flag) {
1292 service.logout({}, function () {
1293 window.location = 'index.html';
1294 });
1295 }
1296 });
1297 });
1298 }, function (data) {
1299 errorOverlay();
1300 });
1301 }
1302
1303 //移除按钮事件
1304
1305 target.removeChildGroupHandler = removeChildGroupHandlerFunc;
1306
1307
1308 //添加按钮事件
1309
1310 target.addChildGroupHandler = addChildGroupHandlerFunc;
1311
1312
1313 target.dealElement = dealElementFunc;
1314
1315
1316
1317 //取消编辑主机名按钮事件
1318
1319 target.cancelEditHostNameHandler = cancelEditHostNameHandlerFunc;
1320
1321 //主机名编辑保存按钮事件
1322
1323 target.saveHostNameHandler = saveHostNameHandlerFunc;
1324
1325 //主机名编辑按钮事件
1326
1327 target.editHostNameHandler = editHostNameHandlerFunc;
1328
1329
1330 target.selectedIds = ko.observableArray([]);
1331 target.siteList = ko.observable([]);
1332 /////////////////////////////////////////////////////////////////
1333 target.disableAdd = ko.computed(function () {
1334 return target.siteList().length == maxItem;
1335 });
1336
1337 ko.computed(function () {
1338 target.siteList();
1339 target.selectedIds();
1340 setTimeout(function () {
1341 renderCheckbox();
1342 }, 100);
1343 $("#pc_site_white_list_form").translate();
1344 });
1345
1346 //网站白名单添加按钮事件
1347
1348 target.openAddSitePopoverHandler = openAddSitePopoverHandlerFunc;
1349
1350 //网站白名单列表选择框点击事件
1351
1352 target.checkboxClickHandler = checkboxClickHandlerFunc;
1353
1354 //获取网站白名单列表
1355
1356 target.fetchSiteWhiteList = fetchSiteWhiteListFunc;
1357
1358 //网站白名单删除函数
1359
1360 function removeSiteWhiteItem(ids) {
1361 showConfirm('confirm_data_delete', function () {
1362 showLoading();
1363 service.removeSiteWhite({
1364 ids: ids
1365 }, function (data) {
1366 target.fetchSiteWhiteList(function () {
1367 successOverlay();
1368 });
1369 }, function (data) {
1370 target.fetchSiteWhiteList(function () {
1371 errorOverlay();
1372 });
1373 });
1374 });
1375 }
1376 //网站白名单删除所有按钮事件
1377
1378 target.removeAllWhiteSite = removeAllWhiteSiteFunc;
1379
1380 //网站白名单删除按钮事件
1381
1382 target.removeSelectedWhiteSite = removeSelectedWhiteSiteFunc;
1383
1384 //网站白名单移除按钮事件
1385
1386 target.removeWhiteSite = removeWhiteSiteFunc;
1387
1388
1389
1390 //网站白名单添加框保存按钮事件
1391
1392 target.saveSiteWhite = saveSiteWhiteFunc;
1393
1394 //////////////////////////////////////////////////////////////////
1395 target.notSave = ko.observable(false);
1396 //获取时间限制信息
1397
1398 target.fetchTimeLimited = fetchTimeLimitedFunc;
1399
1400
1401 //上网时间设置时间表格事件绑定
1402
1403 target.bindEvent = bindEventFunc;
1404
1405 //上网时间设置保存按钮事件
1406
1407 target.saveTimeLimitedHandler = saveTimeLimitedHandlerFunc;
1408
1409 //////////////////////////////////////////////////////////////////
1410 var isBinded = false;
1411 //上网规则标签点击事件
1412
1413 target.openRulePage = openRulePageFunc;
1414 function openRulePageFunc() {
1415 if (target.currentPage() == PAGES.RULE) {
1416 return;
1417 }
1418 target.currentPage(PAGES.RULE);
1419 target.currentUserInChildGroup(service.checkCurrentUserInChildGroup().result);
1420 initTableData();
1421 if (!isBinded) {
1422 if (!target.currentUserInChildGroup()) {
1423 target.bindEvent();
1424 }
1425 isBinded = true;
1426 }
1427 showLoading();
1428 target.fetchTimeLimited();
1429 target.fetchSiteWhiteList(function () {
1430 hideLoading();
1431 });
1432 }
1433
1434 //获取儿童组设备列表
1435 function fetchChildGroupListFunc(cb) {
1436 service.childGroupList({}, function (data) {
1437 target.currentUserInChildGroup(service.checkCurrentUserInChildGroup(data.devices).result);
1438 target.childGroupList([]);
1439 _.map(data.devices, function (elem, idx) {
1440 elem.idx = idx;
1441 elem.hostname = pcUtil.getHostName(elem.hostname, elem.mac, hostNameList);
1442 });
1443 target.childGroupList(data.devices);
1444 if (_.isFunction(cb)) {
1445 cb.apply(this);
1446 }
1447 });
1448 }
1449
1450 //获取已连接设备列表
1451 function fetchAttachedDevicesFunc(cb) {
1452 target.attachedDevices([]);
1453 var counter = 0;
1454 var currDevices = [];
1455 //RJ45 已连接设备
1456 service.getAttachedCableDevices({}, function (data) {
1457 counter++;
1458 var devs = _.map(data.attachedDevices, function (elem) {
1459 elem.idx = _.uniqueId('wireless_');
1460 elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
1461 elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
1462 return elem;
1463 });
1464 if (counter != 1) {
1465 target.attachedDevices(_.flatten([currDevices, devs]));
1466 if (_.isFunction(cb)) {
1467 cb.apply(this);
1468 }
1469 } else {
1470 currDevices = devs;
1471 }
1472 });
1473
1474 //wifi 已连接设备
1475 service.getCurrentlyAttachedDevicesInfo({}, function (data) {
1476 counter++;
1477 var devs = _.map(data.attachedDevices, function (elem) {
1478 elem.idx = _.uniqueId('wireless_');
1479 elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
1480 elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
1481 return elem;
1482 });
1483 if (counter != 1) {
1484 target.attachedDevices(_.flatten([currDevices, devs]));
1485 if (_.isFunction(cb)) {
1486 cb.apply(this);
1487 }
1488 } else {
1489 currDevices = devs;
1490 }
1491 });
1492 }
1493 //儿童组设备 标签按钮事件
1494 function backToMainHandlerFunc() {
1495 target.currentPage(PAGES.MAIN);
1496 }
1497
1498 //移除按钮事件
1499 function removeChildGroupHandlerFunc(ele) {
1500 showLoading();
1501 service.removeChildGroup(ele, function (data) {
1502 target.fetchChildGroupList(function () {
1503 target.fetchAttachedDevices(function () {
1504 hideLoading();
1505 });
1506 });
1507 }, function (data) {
1508 errorOverlay();
1509 });
1510 }
1511
1512 //添加按钮事件
1513 function addChildGroupHandlerFunc(data) {
1514 var uMacAddr = service.getCurretnMAC();
1515 if (uMacAddr != data.macAddress) {
1516 addChildGroupFun(false, data);
1517 } else {
1518 showConfirm("parental_add_self", function () {
1519 addChildGroupFun(true, data);
1520 })
1521 }
1522 }
1523
1524 //取消编辑主机名按钮事件
1525 function cancelEditHostNameHandlerFunc(eleData) {
1526 target.dealElement(false, eleData.idx);
1527 }
1528
1529 //主机名编辑保存按钮事件
1530 function saveHostNameHandlerFunc(ele) {
1531 var $hostInput = $("#hostname_input_" + ele.idx);
1532 var hostname = $.trim($hostInput.val());
1533 if (hostname.indexOf(" ") == 0 || hostname.lastIndexOf(" ") == (hostname.length - 1) || /[\*\+\$\[&:,;<>'"\\`\]¥]{1,32}/.test(hostname)) {
1534 showAlert('modify_hostname_invalid');
1535 return false;
1536 }else if (hostname == '') {
1537 $(".promptErrorLabel", "#confirm-message-container").text($.i18n.prop("required"));
1538 var $closestTD = $hostInput.closest('td').addClass('has-error');
1539 addTimeout(function () {
1540 $closestTD.removeClass('has-error');
1541 }, 5000);
1542 showAlert('required');
1543 return false;
1544 }
1545 showLoading();
1546 ele.hostname = hostname;
1547 service.editHostName(ele, function () {
1548 service.getHostNameList({}, function (hostNameData) {
1549 hostNameList = hostNameData.devices;
1550 target.fetchChildGroupList(function () {
1551 hideLoading();
1552 });
1553 target.fetchAttachedDevices();
1554 });
1555 }, function () {
1556 errorOverlay();
1557 });
1558 }
1559
1560 //主机名编辑按钮事件
1561 function editHostNameHandlerFunc(ele) {
1562 $("#hostname_input_" + ele.idx).val(ele.hostname);
1563 target.dealElement(true, ele.idx);
1564 return false;
1565 }
1566 //网站白名单添加按钮事件
1567 function openAddSitePopoverHandlerFunc() {
1568 var addNewSiteTmpl = $("#addNewSiteTmpl").html();
1569 popover.open({
1570 target: $("#openAddSiteBtn"),
1571 html: addNewSiteTmpl,
1572 width: "300px",
1573 validation: addValidation
1574 });
1575 }
1576
1577 //网站白名单列表选择框点击事件
1578 function checkboxClickHandlerFunc(eleData, evt) {
1579 addTimeout(function () {
1580 target.selectedIds(getSelectedValues());
1581 }, 100);
1582 }
1583 //获取网站白名单列表
1584 function fetchSiteWhiteListFunc(cb) {
1585 service.getSiteWhiteList({}, function (eledata) {
1586 target.selectedIds([]);
1587 target.siteList(eledata.siteList);
1588 _.isFunction(cb) && cb.apply(this);
1589 }, function () {
1590 target.siteList([]);
1591 _.isFunction(cb) && cb.apply(this);
1592 });
1593 }
1594
1595 //网站白名单删除所有按钮事件
1596 function removeAllWhiteSiteFunc() {
1597 removeSiteWhiteItem(getAllCheckboxValues());
1598 }
1599 //网站白名单删除按钮事件
1600 function removeSelectedWhiteSiteFunc() {
1601 removeSiteWhiteItem(getSelectedValues());
1602 }
1603 //网站白名单移除按钮事件
1604 function removeWhiteSiteFunc(ele, evt) {
1605 removeSiteWhiteItem([ele.id]);
1606 }
1607
1608 //网站白名单添加框保存按钮事件
1609 function saveSiteWhiteFunc(name, site) {
1610 popover.hide();
1611 var matched = _.find(target.siteList(), function (one) {
1612 return one.site == site;
1613 });
1614 if (matched) {
1615 showAlert("pc_link_exist", function () {
1616 setTimeout(function () {
1617 popover.show();
1618 }, 200);
1619 });
1620 return false;
1621 }
1622
1623 showLoading();
1624 service.saveSiteWhite({
1625 name: name,
1626 site: site
1627 }, function () {
1628 target.fetchSiteWhiteList(function () {
1629 popover.close();
1630 successOverlay();
1631 });
1632 }, function () {
1633 target.fetchSiteWhiteList(function () {
1634 errorOverlay();
1635 popover.show();
1636 });
1637 });
1638 }
1639
1640 //上网时间设置时间表格事件绑定
1641 function bindEventFunc() {
1642 $("td:not('.col-head')", "#pc_time_limited_tbody").addClass('cursorhand').die().click(function () {
1643 target.notSave(true);
1644 $(this).toggleClass('active');
1645 }).hover(function () {
1646 var $this = $(this);
1647 var w = $this.data('week');
1648 var h = $this.data('hour');
1649 $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").addClass('time_td_hover');
1650 $("#col_" + h).addClass('time_td_hover');
1651 if ($this.not('.active')) {
1652 $this.addClass('time_td_hover');
1653 }
1654 }, function () {
1655 var $this = $(this);
1656 var w = $this.data('week');
1657 var h = $this.data('hour');
1658 $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").removeClass('time_td_hover');
1659 $("#col_" + h).removeClass('time_td_hover');
1660 $this.removeClass('time_td_hover');
1661 });
1662 }
1663
1664 //上网时间设置保存按钮事件
1665 function saveTimeLimitedHandlerFunc() {
1666 showLoading();
1667 var tds = getSelectedTds();
1668 var timeStr = getSavedData(tds);
1669 service.saveTimeLimited({
1670 time: timeStr
1671 }, function () {
1672 target.notSave(false);
1673 successOverlay();
1674 }, function () {
1675 errorOverlay();
1676 });
1677 }
1678
1679 }
1680
1681 function dealElementFunc(flag, idx) {
1682 if (flag == false) {
1683 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).show();
1684 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).hide();
1685 } else {
1686 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).hide();
1687 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).show();
1688 }
1689 }
1690
1691 //获取时间限制信息
1692 function fetchTimeLimitedFunc() {
1693 service.getTimeLimited({}, function (ele) {
1694 for (var ki in ele) {
1695 for (var idx = 0; idx < ele[ki].length; idx++) {
1696 var id = 'td_' + ki + '_' + ele[ki][idx];
1697 $("#" + id).addClass('active');
1698 }
1699 }
1700 }, function () {});
1701 }
1702
1703 var pcUtil = {
1704 getHostName: function (hostName, mac, hostNameList) {
1705 var ele = _.find(hostNameList, function (ele) {
1706 return ele.mac == mac;
1707 });
1708 return ele ? ele.hostname : hostName;
1709 }
1710 };
1711 function getCheckboxValues(flag) {
1712 var selectedValues = [];
1713 $(":checkbox" + (flag ? ":checked" : ""), "#pb_white_list").each(function (i, n) {
1714 selectedValues.push(n.value)
1715 });
1716 return selectedValues;
1717 }
1718 //获取列表中被选中项的value值
1719
1720 function getSelectedValues() {
1721 return getCheckboxValues(true);
1722 }
1723 function getAllCheckboxValues() {
1724 return getCheckboxValues(false);
1725 }
1726
1727 //增加网站白名单表单提交函数绑定和校验规则设置
1728
1729 function addValidation() {
1730 $('#whiteSiteAddForm').validate({
1731 submitHandler: function () {
1732 var name = $("#siteName").val();
1733 var site = $("#siteLink").val();
1734 pcVm.saveSiteWhite(name, site);
1735 },
1736 rules: {
1737 siteName: 'siteName_check',
1738 siteLink: 'siteLink_check'
1739 }
1740 });
1741 }
1742
1743 function getSavedData(timeDatas) {
1744 var ret = '';
1745 for (var ki in timeDatas) {
1746 var hours = _.sortBy(timeDatas[ki], function (n) {
1747 return n;
1748 });
1749 if (timeDatas[ki].length) {
1750 ret += ki + '+';
1751 ret += hours.join(',');
1752 ret += ';'
1753 }
1754 }
1755 return ret.substring(0, ret.length - 1);
1756 }
1757 //获取时间表格选中的时间
1758
1759 function getSelectedTds() {
1760 var defaultValue = {
1761 '0': [],
1762 '1': [],
1763 '2': [],
1764 '3': [],
1765 '4': [],
1766 '5': [],
1767 '6': []
1768 };
1769 $("td.active", "#pc_time_limited_tbody").each(function (i, n) {
1770 var $this = $(n);
1771 var week = $this.data('week');
1772 var hour = $this.data('hour');
1773 defaultValue[week].push(hour);
1774 });
1775 return defaultValue;
1776 }
1777
1778 function convertHour(hour) {
1779 if (hour <= 16) {
1780 return hour + 7;
1781 } else {
1782 return hour - 17;
1783 }
1784 }
1785 //初始化时间表格
1786
1787 function initTableData() {
1788 $("tr", "#pc_time_limited_tbody").each(function (idx, n) {
1789 var $tr = $(n);
1790 $("td:not(:first)", $tr).each(function (j, m) {
1791 var $td = $(m);
1792 var hour = convertHour(j);
1793 $td.attr({
1794 id: 'td_' + idx + '_' + hour
1795 }).data({
1796 week: idx,
1797 hour: hour
1798 });
1799 });
1800 });
1801 $("td.active", "#pc_time_limited_tbody").removeClass("active");
1802 $("thead td:not(:first)", "#pc_time_limited_form").each(function (idx, n) {
1803 var hour = convertHour(idx);
1804 $(n).attr({
1805 id: 'col_' + hour
1806 });
1807 });
1808 pcVm.notSave(false);
1809 }
1810
1811
1812 //页面初始化
1813
1814 function initialize() {
1815
1816 pcVm = new ParentalControlVM();
1817 bindContainer(pcVm);
1818 }
1819 function bindContainer(pcVm)
1820 {
1821 var container = $('#container');
1822 ko.cleanNode(container[0]);
1823 ko.applyBindings(pcVm, container[0]);
1824 }
1825
1826 return {
1827 init: initialize
1828 };
1829});
1830
1831define("firewall_dmz_set","underscore jquery knockout set service".split(" "),
1832 function ( _, $, ko, config, service) {
1833
1834 //system dmz setting VM
1835
1836 function DmzSettingVM() {
1837 var target = this;
1838 var dmzInfo = getDmzSetting();
1839 target.dmzSetting = ko.observable(dmzInfo.dmzSetting);
1840 target.ipAddress = ko.observable(dmzInfo.ipAddress);
1841 target.isDataCard = config.PRODUCT_TYPE == 'DATACARD';
1842
1843 target.clear = clearFunc;
1844 //应用按钮事件
1845
1846 target.save = saveFunc;
1847
1848 function saveFunc() {
1849 showLoading();
1850 var params = {};
1851 params.dmzSetting = target.dmzSetting();
1852 params.ipAddress = target.ipAddress();
1853 service.setDmzSetting(params, function (result) {
1854 if (result.result != "success") {
1855 errorOverlay();
1856 } else {
1857 target.clear();
1858 successOverlay();
1859 }
1860 });
1861 }
1862
1863 }
1864
1865 function clearFunc() {
1866 initialize();
1867 }
1868
1869
1870 //获取dmz 信息
1871
1872 function getDmzSetting() {
1873 return service.getDmzSetting();
1874 }
1875
1876 //初始化DmzSettingVM model
1877
1878 function initialize() {
1879
1880 var dmzVm = new DmzSettingVM();
1881 bindContainer(dmzVm);
1882 }
1883 function bindContainer(dmzVm){
1884 var container = $('#container');
1885 ko.cleanNode(container[0]);
1886 ko.applyBindings(dmzVm, container[0]);
1887 $('#dmzSettingForm').validate({
1888 submitHandler: function () {
1889 dmzVm.save();
1890 },
1891 rules: {
1892 txtIpAddress: 'dmz_ip_check'
1893 }
1894 });
1895 }
1896
1897 return {
1898 init: initialize
1899 };
1900});
1901
1902define("firewall","underscore jquery knockout set service".split(" "),
1903
1904function(_, $, ko, config, service) {
1905
1906 function FirewallVM() {
1907 var target = this;
1908 target.hasDdns = config.DDNS_SUPPORT;
1909 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1910 target.hasUrlFilter = config.HAS_URL;
1911 target.hasUssd = config.HAS_USSD;
1912 }
1913
1914 function initialize() {
1915 var fwVm = new FirewallVM();
1916 bindingContainer(fwVm);
1917 }
1918 function bindingContainer(fwVm)
1919 {
1920 var container = $('#container');
1921 ko.cleanNode(container[0]);
1922 ko.applyBindings(fwVm, container[0]);
1923 }
1924 return {
1925 init : initialize
1926 };
1927});
1928
1929define("ddns","underscore jquery knockout set service".split(" "), function (_, $, ko, config, service) {
1930 var ddnsSetModes = _.map(config.DDNSSetMode, newOption);
1931 var ddnsProviderList = _.map(config.DDNSDDP, newOption);
1932 var ddns_mode_select = _.map(config.ddns_Modeselect, newOption);
1933 function newOption(optItem) {
1934 return new Option(optItem.name, optItem.value);
1935 }
1936 function DdnsViewModel() {
1937 var target = this;
1938 target.hasUssd = config.HAS_USSD;
1939 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1940 var data = service.getDdnsParams();
1941 target.ddnsSetModes = ko.observableArray(ddnsSetModes);
1942 target.ddnsProviderList = ko.observableArray(ddnsProviderList);
1943 target.ddns_mode_select = ko.observableArray(ddns_mode_select);
1944 target.currentMode = ko.observable(data.DDNS_Enable);
1945 target.currentModeselect = ko.observable(data.DDNS_Mode);
1946 target.currentProviderList = ko.observable("dyndns.org");
1947 $.each(config.DDNSDDP, function (i, n) {
1948 if (data.DDNSProvider == n.value) {
1949 target.currentProviderList(data.DDNSProvider);
1950 }
1951 });
1952 target.DDNSaccount = ko.observable(data.DDNSAccount);
1953 target.DDNSpasswd = ko.observable(data.DDNSPassword);
1954 target.DDNSname = ko.observable(data.DDNS);
1955 target.DDNS_HashValue = ko.observable(data.DDNS_Hash_Value);
1956 target.isddnsStatusTrans = ko.observable();
1957 target.isEnableSet = ko.observable();
1958 target.isHashValue = ko.observable();
1959 target.isddnsaccount = ko.observable();
1960 target.isddnspasswd = ko.observable();
1961 target.isDDNSStatus = ko.observable();
1962 target.isddnsdomainName = ko.observable();
1963 target.isNone = ko.observable();
1964 target.onStates = ko.observable();
1965 target.showPassword_ddns = ko.observable(false);
1966 target.showPasswordHandler_ddns = showPasswordHandler_ddns;
1967 changeddnsProviderList();
1968 target.changeDdnsProvider = changeDdnsProviderFunc;
1969 changeSetDdnsMode();
1970 target.changeSetDdnsMode = changeSetDdnsModeFunc;
1971 updateScanDdnsStatus();
1972 target.apply = applyFunc;
1973 function updateScanDdnsStatus() {
1974 var trans = "";
1975 $.getJSON("/reqproc/proc_get", {
1976 cmd: "getddns_status",
1977 "_": new Date().getTime()
1978 }, function (data) {
1979 if (data.getddns_status == "0") {
1980 trans = "register successful";
1981 target.onStates(true);
1982 } else if (data.getddns_status == "1") {
1983 trans = "login error";
1984 target.onStates(true);
1985 } else if (data.getddns_status == "2") {
1986 trans = "network error";
1987 target.onStates(true);
1988 } else if (data.getddns_status == "3") {
1989 trans = "registering";
1990 target.onStates(true);
1991 } else if (data.getddns_status == "4") {
1992 trans = "not registered";
1993 target.onStates(true);
1994 } else if (data.getddns_status == "5") {
1995 trans = "error registering";
1996 target.onStates(true);
1997 } else if (data.getddns_status == "-1") {
1998 trans = "";
1999 target.onStates(true);
2000 }
2001 target.isddnsStatusTrans($.i18n.prop(trans));
2002 addTimeout(updateScanDdnsStatus, 2000);
2003 });
2004 }
2005 function changeSetDdnsMode() {
2006 if (target.currentMode() != "1") {
2007 target.isEnableSet(false);
2008 } else {
2009 target.isEnableSet(true);
2010 }
2011 return true;
2012 }
2013 function changeSetDdnsModeFunc() {
2014 changeSetDdnsMode();
2015 }
2016 function showPasswordHandler_ddns() {
2017 $("#ddns_secretcode_input").parent().find(".error").hide();
2018 var checkbox = $("#showPassword_ddns:checked");
2019 if (checkbox && checkbox.length == 0) {
2020 target.showPassword_ddns(true);
2021 } else {
2022 target.showPassword_ddns(false);
2023 }
2024 }
2025 function changeDdnsProviderFunc() {
2026 if (data.DDNSProvider != target.currentProviderList()) {
2027 target.DDNSaccount("");
2028 target.DDNSpasswd("");
2029 target.DDNSname("");
2030 } else {
2031 target.DDNSaccount(data.DDNSAccount);
2032 target.DDNSpasswd(data.DDNSPassword);
2033 target.DDNSname(data.DDNS);
2034 }
2035 changeddnsProviderList();
2036 }
2037 function changeddnsProviderList() {
2038 if (target.currentProviderList() != "none") {
2039 target.isddnsaccount(true);
2040 target.isddnspasswd(true);
2041 target.isddnsdomainName(true);
2042 target.isHashValue(true);
2043 target.isDDNSStatus(true);
2044 } else {
2045 target.isddnsaccount(false);
2046 target.isddnspasswd(false);
2047 target.isddnsdomainName(false);
2048 target.isHashValue(false);
2049 target.isDDNSStatus(false);
2050 }
2051 if (target.currentProviderList() != "freedns.afraid.org") {
2052 target.isHashValue(false);
2053 } else {
2054 target.isHashValue(true);
2055 }
2056 return true;
2057 }
2058 function applyFunc() {
2059 showLoading();
2060 var params = {};
2061 params.goformId = "DDNS";
2062 params.DDNS_Enable = target.currentMode();
2063 if (target.currentMode() == "1") {
2064 params.DDNS_Mode = target.currentModeselect();
2065 params.DDNSProvider = target.currentProviderList();
2066 if (target.currentProviderList() != "none") {
2067 params.DDNS = target.DDNSname();
2068 params.DDNSPassword = target.DDNSpasswd();
2069 params.DDNSAccount = target.DDNSaccount();
2070 }
2071 if (target.currentProviderList() == "freedns.afraid.org") {
2072 params.DDNS_Hash_Value = target.DDNS_HashValue();
2073 }
2074 }
2075 service.setDDNSForward(params, function (result) {
2076 if (result.result == "success") {
2077 successOverlay();
2078 data = service.getDdnsParams();
2079 } else {
2080 errorOverlay();
2081 }
2082 });
2083 }
2084 }
2085 function initialize() {
2086 var container = $('#container');
2087 ko.cleanNode(container[0]);
2088 var vm = new DdnsViewModel();
2089 ko.applyBindings(vm, container[0]);
2090 $("#ddnsForm").validate({
2091 submitHandler: function () {
2092 vm.apply();
2093 },
2094 rules: {
2095 ddns_secretcode_input: "secretcode_check",
2096 DDNS_Hash_Value: "ddns_hashvalue_check",
2097 ddns_secretcode_inputshow: "secretcode_check"
2098 },
2099 errorPlacement: function (error, element) {
2100 var id = element.attr("id");
2101 if (id == "ddns_secretcode_input" || id == "ddns_secretcode_inputshow") {
2102 error.insertAfter("#lblShowPassword");
2103 } else {
2104 error.insertAfter(element);
2105 }
2106 }
2107 });
2108 }
2109 return {
2110 init: initialize
2111 };
2112});
2113
2114
2115//选网模块
2116
2117define("network_net_select","underscore jquery knockout set service".split(" "),
2118 function (_, $, ko, config, service) {
2119
2120 var selectModes = _.map(config.AUTO_MODES, function (item) {
2121 return new Option(item.name, item.value);
2122 });
2123
2124 //选网功能view model
2125
2126 function NetSelectVM() {
2127 var target = this;
2128
2129 target.networkList = ko.observableArray([]);
2130 target.selectNetwork = ko.observable('');
2131 target.enableFlag = ko.observable(true);
2132 target.types = ko.observableArray(selectModes);
2133 target.selectedType = ko.observable();
2134 target.selectMode = ko.observable();
2135
2136 target.networkText = networkTextFunc;
2137
2138 target.networkStatusId = networkStatusIdFunc;
2139
2140 target.networkStatus = networkStatusFunc;
2141
2142 target.subnetworkType = subnetworkTypeFunc;
2143
2144 target.networkType = networkTypeFunc;
2145
2146 target.operatorName = operatorNameFunc;
2147
2148 target.networkValue = networkValueFunc;
2149
2150 target.networkTypeId = networkTypeIdFunc;
2151
2152 target.subnetTypeId = subnetTypeIdFunc;
2153 //手动搜网.
2154
2155 target.search = searchFunc;
2156
2157 //自动选网时设置网络模式.
2158
2159 target.save = saveFunc;
2160
2161 target.checkEnable = checkEnableFunc;
2162
2163 //注册选择的网络.
2164
2165 target.register = registerFunc;
2166
2167 //init data
2168 target.checkEnable();
2169 var info = getNetSelectInfo();
2170 if ("manual_select" == info.net_select_mode || "manual_select" == info.m_netselect_save) {
2171 target.selectMode("manual_select");
2172 } else {
2173 target.selectMode("auto_select");
2174 }
2175
2176 target.selectedType(info.net_select);
2177
2178 //注册选择的网络.
2179 function registerFunc() {
2180 showLoading('registering_net');
2181 var networkToSet = target.selectNetwork().split(',');
2182 service.setNetwork(networkToSet[0], parseInt(networkToSet[1]), parseInt(networkToSet[2]), function (result) {
2183 if (result) {
2184 target.networkList([]);
2185 var autoType = getNetSelectInfo();
2186 target.selectedType(autoType.net_select);
2187 successOverlay();
2188 } else {
2189 errorOverlay();
2190 }
2191 });
2192 }
2193
2194 function checkEnableFunc() {
2195 var status = service.getStatusInfo();
2196 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
2197 target.enableFlag(false);
2198 } else {
2199 target.enableFlag(true);
2200 }
2201 }
2202
2203 //自动选网时设置网络模式.
2204 function saveFunc() {
2205 showLoading();
2206
2207 //AutoSelect call SetBearerPreference
2208 var params = {};
2209 params.strBearerPreference = target.selectedType();
2210 service.setBearerPreference(params, function (result) {
2211 if (result.result == "success") {
2212 target.networkList([]);
2213 successOverlay();
2214 } else {
2215 errorOverlay();
2216 }
2217 });
2218 }
2219
2220 //手动搜网.
2221 function searchFunc() {
2222 showLoading('searching_net');
2223 service.scanForNetwork(function (result, networkList) {
2224 hideLoading();
2225 if (result) {
2226 target.networkList(networkList);
2227 for (var i = 0; i < networkList.length; i++) {
2228 var n = networkList[i];
2229 if (n.nState == '2') {
2230 target.selectNetwork(n.strNumeric + ',' + n.nRat + ',' + n.SubAct);
2231 return;
2232 }
2233 }
2234 } else {
2235 target.networkList([]);
2236 }
2237 });
2238 }
2239
2240 function subnetTypeIdFunc(data) {
2241 return getSubNetworkTypeTog(data.nRat, data.SubAct);
2242 }
2243
2244 function networkTypeIdFunc(data) {
2245 return getNetworkType(data.nRat);
2246 }
2247
2248 function networkValueFunc(data) {
2249 var result = [];
2250 result.push(data.strNumeric); //strNumeric
2251 result.push(data.nRat); //nRat
2252 result.push(data.SubAct);
2253 return result.join(',');
2254 }
2255
2256 function operatorNameFunc(data) {
2257 return data.strShortName;
2258 }
2259
2260 function networkTypeFunc(data) {
2261 var result = getNetworkType(data.nRat);
2262 if (result == "auto")
2263 result = $.i18n.prop("auto");
2264 return result;
2265 }
2266
2267 function subnetworkTypeFunc(data) {
2268 var result = getSubNetworkTypeTog(data.nRat, data.SubAct);
2269 return result;
2270 }
2271
2272 function networkStatusFunc(data) {
2273 return $.i18n.prop(getNetworkStatusTog(data.nState));
2274 }
2275
2276 function networkStatusIdFunc(data) {
2277 return getNetworkStatusTog(data.nState);
2278 }
2279
2280 function networkTextFunc(data) {
2281 return data.strNumeric;
2282 }
2283
2284 }
2285
2286 //获取网络选择信息.
2287
2288 function getNetSelectInfo() {
2289 return service.getNetSelectInfo();
2290 }
2291
2292 //搜网结果中的状态转换为对应的语言项.
2293
2294 function getNetworkStatusTog(status) {
2295 if ("3" == status) {
2296 return "forbidden";
2297 } else if ("2" == status) {
2298 return "current";
2299 } else if ("1" == status) {
2300 return "available";
2301 }else if ("0" == status) {
2302 return "unknown";
2303 }
2304 }
2305 //子网络类型转换.
2306
2307 function getSubNetworkTypeTog(type, subtype) {
2308 var type_3g = [2, 4, 5, 6, 8];
2309 if ("1" == subtype) {
2310 if ("7" == type) {
2311 subtype = "FDD-LTE";
2312 } else if ($.inArray(type, type_3g) != -1) {
2313 subtype = "WCDMA";
2314 }else {
2315 subtype = "GSM";
2316 }
2317 } else if ("0" == subtype) {
2318 if ("7" == type) {
2319 subtype = "TD-LTE";
2320 } else if ($.inArray(type, type_3g) != -1) {
2321 subtype = "TD-SCDMA";
2322 } else {
2323 subtype = "GSM";
2324 }
2325 } else {
2326 subtype = "";
2327 }
2328 return subtype;
2329 }
2330 //网络类型转换.
2331
2332 function getNetworkType(type) {
2333 if ("7" == type) {
2334 return "4G";
2335 } else if ("2" == type) {
2336 return "3G";
2337 } else if ("0" == type) {
2338 return "2G";
2339 } else {
2340 return "auto";
2341 }
2342 }
2343
2344 function bindContainer(vm){
2345
2346 var container = $('#container');
2347 ko.cleanNode(container[0]);
2348 ko.applyBindings(vm, container[0]);
2349 }
2350
2351 //初始化选网功能view model.
2352
2353 function initialize() {
2354 var vm = new NetSelectVM();
2355 bindContainer(vm);
2356 addInterval(vm.checkEnable, 1000);
2357 }
2358
2359 return {
2360 init: initialize
2361 };
2362});
2363define("locknet","jquery knockout service jquery set main".split(" "),
2364 function ($, ko, service, config, home) {
2365
2366 function initialize() {
2367 var container = $('#container')[0];
2368 ko.cleanNode(container);
2369 var vm = new locknetViewMode();
2370 ko.applyBindings(vm, container);
2371
2372 $("#frmNetworkLock").validate({
2373 submitHandler: function () {
2374 vm.unlock();
2375 },
2376 rules: {
2377 txtLockNumber: "unlock_code_check"
2378 }
2379 });
2380 }
2381
2382 function locknetViewMode() {
2383 var target = this;
2384 var curCableMode = false;
2385 target.isCPE = config.PRODUCT_TYPE == 'CPE';
2386 target.hasRj45 = config.RJ45_SUPPORT;
2387 target.hasSms = config.HAS_SMS;
2388 target.hasPhonebook = config.HAS_PHONEBOOK;
2389 target.isSupportSD = config.SD_CARD_SUPPORT;
2390 if (config.WIFI_SUPPORT_QR_SWITCH == false) {
2391 target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
2392 } else {
2393 var wifiInfo = service.getWifiBasic();
2394 target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
2395 }
2396 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2397 target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
2398 target.deviceInfo = ko.observable([]);
2399 target.isHomePage = ko.observable(false);
2400 if (window.location.hash == "#main") {
2401 target.isHomePage(true);
2402 }
2403
2404 target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
2405 target.unlockCode = ko.observable();
2406
2407 var info = service.getNetworkUnlockTimes();
2408 target.times = ko.observable(info.unlock_nck_time);
2409
2410 //显示工作模式设置窗口
2411 target.showOpModeWindow = showOpModeWindowFunc;
2412
2413 target.isLoggedIn = ko.observable(false);
2414 target.enableFlag = ko.observable(false);
2415 //解锁
2416 target.unlock = unlockFunc;
2417
2418 //更新工作模式状态
2419 target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
2420
2421 //定时检查工作模式状态
2422 if (target.hasRj45) {
2423 target.refreshOpmodeInfo();
2424 addInterval(function () {
2425 target.refreshOpmodeInfo();
2426 }, 1000);
2427 }
2428
2429 //更新工作模式状态
2430 function refreshOpmodeInfoFunc() {
2431 var obj = service.getStatusInfo();
2432 target.isLoggedIn(obj.isLoggedIn);
2433
2434 if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
2435 window.location.reload();
2436 return;
2437 }
2438
2439 curCableMode = checkCableMode(obj.blc_wan_mode);
2440 target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
2441 if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
2442 target.enableFlag(true);
2443 } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
2444 target.enableFlag(false);
2445 } else {
2446 target.enableFlag(true);
2447 }
2448 var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
2449 var currMode = "";
2450 switch (getMode) {
2451 case "PPP":
2452 currMode = "opmode_gateway";
2453 break;
2454 case "PPPOE":
2455 currMode = "opmode_cable";
2456 break;
2457 case "AUTO":
2458 currMode = "opmode_auto";
2459 break;
2460 default:
2461 break;
2462 }
2463 $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
2464 }
2465
2466 //解锁
2467 function unlockFunc() {
2468 showLoading();
2469 service.unlockNetwork({
2470 unlock_network_code: target.unlockCode()
2471 }, function (data) {
2472 target.unlockCode("");
2473 if (data && data.result == "success") {
2474 successOverlay();
2475 if (window.location.hash == "#main") {
2476 setTimeout(function () {
2477 window.location.reload();
2478 }, 500);
2479 } else {
2480 window.location.hash = "#main";
2481 }
2482 } else {
2483 var info = service.getNetworkUnlockTimes();
2484 target.times(info.unlock_nck_time);
2485 errorOverlay();
2486 }
2487 })
2488 }
2489
2490 //显示工作模式设置窗口
2491 function showOpModeWindowFunc() {
2492 showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
2493 }
2494 }
2495
2496 return {
2497 init: initialize
2498 };
2499});
2500
2501// RJ45联网设置模块
2502
2503define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
2504function(_, $, ko, config, service) {
2505 var dialActions = _.map(config.dialActions, function(elem){
2506 return new Option(elem.name, elem.value);
2507 });
2508
2509 var dialModes = _.map(config.pppoeModes, function(elem) {
2510 return new Option(elem.name, elem.value);
2511 });
2512
2513 var checkStatusTimer = 0;
2514 var checkConCounter = 0;
2515 var timeoutTipShowed = false;
2516
2517 // 联网设置view model.
2518
2519 function PPPoEViewModel() {
2520 var pppObj = service.getPppoeParams();
2521 var ethParams = pppObj;
2522 var target = this;
2523
2524 target.staticNoticeShow = ko.observable();
2525 target.dhcpNoticeShow = ko.observable();
2526 target.pppoeNoticeShow = ko.observable();
2527 target.autoNoticeShow = ko.observable();
2528 target.staticNotice = ko.observable();
2529 target.dhcpNotice = ko.observable();
2530 target.pppoeNotice = ko.observable();
2531 target.autoNotice = ko.observable();
2532 target.dhcpNoticeText = ko.observable();
2533 target.staticNoticeText = ko.observable();
2534 target.pppoeNoticeText = ko.observable();
2535 target.autoNoticeText = ko.observable();
2536 target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
2537 target.showPassword = ko.observable(false);
2538 target.modes = ko.observableArray(dialModes);
2539 target.isPppoeMode = ko.observable(false);
2540 target.isStaticMode = ko.observable(false);
2541 target.isAutoMode = ko.observable(false);
2542 target.action = ko.observable();
2543 target.btnTrans = ko.observable();
2544 target.enableFlag = ko.observable();
2545 target.isShowDisbtn = ko.observable();
2546 target.isShowCancelbtn = ko.observable();
2547
2548 if(pppObj.rj45_state == "dead"){
2549 checkRj45DeadTip();
2550 } else if(pppObj.rj45_state == "connect"){
2551 timeoutTipShowed = true;
2552 setRj45CheckTimer("connect");
2553 } else if(pppObj.rj45_state == "working"){
2554 setRj45WorkingTip();
2555 }
2556
2557 target.user = ko.observable(pppObj.pppoe_username);
2558 target.password = ko.observable(pppObj.pppoe_cc);
2559 target.autoUser = ko.observable(pppObj.pppoe_username);
2560 target.autoPassword = ko.observable(pppObj.pppoe_cc);
2561 target.pppMode = ko.observable(pppObj.ethwan_dialmode);
2562 initContronler();
2563
2564
2565 //下拉框选择改变下面DIV模块
2566 target.changeModeDiv = changeModeDivFunc;
2567
2568 target.radioHandler = radioHandlerFunc;
2569
2570 target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
2571 target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
2572 target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
2573 target.subnetMask = ko.observable(pppObj.static_wan_netmask);
2574 target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
2575
2576 addInterval(function(){
2577 ethParams = service.getPppoeParams();
2578 pppObj.rj45_state = ethParams.rj45_state;
2579 initContronler();
2580 }, 1000);
2581
2582 // 取消连接按钮事件.
2583
2584 target.cancelConnect = cancelConnectFunc;
2585
2586 // 应用按钮事件.
2587
2588 target.save = saveFunc;
2589
2590 //密码显示事件
2591 target.showPasswordHandler = function () {
2592 var checkbox = $("#showPassword:checked");
2593 if (checkbox && checkbox.length == 0) {
2594 target.showPassword(true);
2595 } else {
2596 target.showPassword(false);
2597 }
2598 };
2599
2600 // 更新当前界面状态、按钮、提示语等.
2601
2602 function initContronler() {
2603 checkRj45DeadTip();
2604 if(target.currentMode() == "PPPOE"){
2605 target.isPppoeMode(true);
2606 target.isStaticMode(false);
2607 target.isAutoMode(false);
2608 target.staticNoticeShow(false);
2609 target.dhcpNoticeShow(false);
2610 target.autoNoticeShow(false);
2611 } else if(target.currentMode() == "AUTO"){
2612 target.isStaticMode(false);
2613 target.isPppoeMode(false);
2614 target.isAutoMode(true);
2615 target.dhcpNoticeShow(false);
2616 target.pppoeNoticeShow(false);
2617 target.staticNoticeShow(false);
2618 } else if(target.currentMode() == "STATIC"){
2619 target.isStaticMode(true);
2620 target.isPppoeMode(false);
2621 target.isAutoMode(false);
2622 target.dhcpNoticeShow(false);
2623 target.pppoeNoticeShow(false);
2624 target.autoNoticeShow(false);
2625 } else{
2626 target.isStaticMode(false);
2627 target.isPppoeMode(false);
2628 target.isAutoMode(false);
2629 target.staticNoticeShow(false);
2630 target.pppoeNoticeShow(false);
2631 target.autoNoticeShow(false);
2632 }
2633 if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
2634 target.enableFlag(false);
2635 } else {
2636 target.enableFlag(true);
2637 }
2638 if(pppObj.rj45_state == "connect"){
2639 if(target.pppMode() == "auto_dial"){
2640 target.action("connect");
2641 }else{
2642 target.action("disconnect");
2643 }
2644 } else if(pppObj.rj45_state == "working"){
2645 target.action("disconnect");
2646 }else{
2647 target.action("connect");
2648 }
2649 //应用/连接按钮
2650 if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
2651 target.btnTrans("connect");
2652 } else{
2653 target.btnTrans("apply");
2654 }
2655 if(pppObj.rj45_state != "idle"){
2656 $("#pppoeApply").attr("disabled", true);
2657 }else {
2658 $("#pppoeApply").attr("disabled", false);
2659 }
2660
2661 //取消/断开按钮
2662 target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
2663 target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
2664
2665 $("#pppoeApply").translate();
2666 }
2667 // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
2668
2669 function setRj45CheckTimer(action){
2670 checkStatusTimer && window.clearInterval(checkStatusTimer);
2671 if("connect" != action){
2672 checkStatusTimer = addInterval(function () {
2673 checkDisconnectStatus();
2674 }, 2000);
2675 }else{
2676 if(target.currentMode() == "PPPOE"){
2677 target.pppoeNoticeShow(true);
2678 target.pppoeNotice("pppoe_processing");
2679 target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
2680 } else if(target.currentMode() == "STATIC"){
2681 target.staticNoticeShow(true);
2682 target.staticNotice("static_processing");
2683 target.staticNoticeText($.i18n.prop("static_processing"));
2684 } else if(target.currentMode() == "DHCP"){
2685 target.dhcpNoticeShow(true);
2686 target.dhcpNotice("dyn_processing");
2687 target.dhcpNoticeText($.i18n.prop("dyn_processing"));
2688 }else{
2689 target.autoNoticeShow(true);
2690 target.autoNotice("auto_processing");
2691 target.autoNoticeText($.i18n.prop("auto_processing"));
2692 }
2693 checkStatusTimer = addInterval(function () {
2694 checkConnectionStatus();
2695 }, 2000);
2696 }
2697 }
2698 // 设置后通过定时检查rj45_state状态,判断连接操作结果.
2699
2700 function checkConnectionStatus(){
2701 if(checkConCounter < 1){
2702 checkConCounter++;
2703 return;
2704 }
2705 if(pppObj.rj45_state == "connect"){
2706 if(target.currentMode() != ethParams.ethwan_mode){
2707 if(target.currentMode() == "AUTO"){
2708 target.autoNoticeShow(true);
2709 }else if(target.currentMode() == "PPPOE"){
2710 target.pppoeNoticeShow(true);
2711 }else if(target.currentMode() == "STATIC"){
2712 target.staticNoticeShow(true);
2713 }else if(target.currentMode() == "DHCP"){
2714 target.dhcpNoticeShow(true);
2715 }
2716 }
2717 if(checkConCounter > 6){
2718 if(timeoutTipShowed == false){
2719 timeoutTipShowed = true;
2720 showAlert("ussd_operation_timeout");
2721 }
2722 }
2723 checkConCounter++;
2724 } else if (pppObj.rj45_state == "working") {
2725 hideLoading();
2726 setRj45WorkingTip();
2727 window.clearInterval(checkStatusTimer);
2728 } else if (pppObj.rj45_state == "dead") {
2729 hideLoading();
2730 checkRj45DeadTip();
2731 window.clearInterval(checkStatusTimer);
2732 } else if(pppObj.rj45_state == "idle"){
2733 hideLoading();
2734 if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
2735 timeoutTipShowed == false && target.dhcpNoticeShow(true);
2736 target.dhcpNotice("dyn_fail");
2737 target.dhcpNoticeText($.i18n.prop("dyn_fail"));
2738 }
2739 if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
2740 timeoutTipShowed == false && target.staticNoticeShow(true);
2741 target.staticNotice("static_fail");
2742 target.staticNoticeText($.i18n.prop("static_fail"));
2743 }
2744 if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
2745 timeoutTipShowed == false && target.pppoeNoticeShow(true);
2746 target.pppoeNotice("pppoe_fail");
2747 target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
2748 }
2749 if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
2750 timeoutTipShowed == false && target.autoNoticeShow(true);
2751 target.autoNotice("auto_fail");
2752 target.autoNoticeText($.i18n.prop("auto_fail"));
2753 }
2754 window.clearInterval(checkStatusTimer);
2755 } else{
2756 hideLoading();
2757 window.clearInterval(checkStatusTimer);
2758 }
2759 }
2760 // 设置连接成功时提示语状态.
2761
2762 function setRj45WorkingTip(){
2763 if(target.currentMode() == ethParams.ethwan_mode){
2764 if(target.currentMode() == "AUTO") {
2765 target.autoNoticeShow(true);
2766 target.autoNotice("auto_success");
2767 target.autoNoticeText($.i18n.prop("auto_success"));
2768 }else if(target.currentMode() == "PPPOE") {
2769 target.pppoeNoticeShow(true);
2770 target.pppoeNotice("pppoe_success");
2771 target.pppoeNoticeText($.i18n.prop("pppoe_success"));
2772 }else if(target.currentMode() == "STATIC") {
2773 target.staticNoticeShow(true);
2774 target.staticNotice("static_success");
2775 target.staticNoticeText($.i18n.prop("static_success"));
2776 }else if(target.currentMode() == "DHCP" ) {
2777 target.dhcpNoticeShow(true);
2778 target.dhcpNotice("dyn_success");
2779 target.dhcpNoticeText($.i18n.prop("dyn_success"));
2780 }
2781 }
2782 }
2783
2784 // 设置网线断开提示语状态.
2785
2786 function checkRj45DeadTip(){
2787 if(pppObj.rj45_state != "dead"){
2788 if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
2789 target.autoNoticeShow(false);
2790 }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
2791 target.pppoeNoticeShow(false);
2792 }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
2793 target.staticNoticeShow(false);
2794 }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
2795 target.dhcpNoticeShow(false);
2796 }
2797
2798 } else{
2799 target.dhcpNotice("pppoe_msg");
2800 target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
2801 target.staticNotice("pppoe_msg");
2802 target.staticNoticeText($.i18n.prop("pppoe_msg"));
2803 target.pppoeNotice("pppoe_msg");
2804 target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
2805 target.autoNotice("pppoe_msg");
2806 target.autoNoticeText($.i18n.prop("pppoe_msg"));
2807 if(target.currentMode() == "AUTO") {
2808 target.autoNoticeShow(true);
2809 }else if(target.currentMode() == "PPPOE") {
2810 target.pppoeNoticeShow(true);
2811 }else if(target.currentMode() == "STATIC") {
2812 target.staticNoticeShow(true);
2813 }else if(target.currentMode() == "DHCP") {
2814 target.dhcpNoticeShow(true);
2815 }
2816 }
2817 }
2818 // 设置后通过定时检查rj45_state状态,判断断开操作结果.
2819
2820 function checkDisconnectStatus(){
2821 if(checkConCounter < 1){
2822 checkConCounter++;
2823 } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
2824 target.dhcpNoticeShow(false);
2825 target.staticNoticeShow(false);
2826 target.pppoeNoticeShow(false);
2827 target.autoNoticeShow(false);
2828 window.clearInterval(checkStatusTimer);
2829 successOverlay();
2830 } else if(checkConCounter > 6){
2831 if(timeoutTipShowed == false){
2832 timeoutTipShowed = true;
2833 showAlert("ussd_operation_timeout");
2834 }
2835 window.clearInterval(checkStatusTimer);
2836 } else if(checkConCounter < 7) {
2837 checkConCounter++;
2838 } else {
2839 hideLoading();
2840 window.clearInterval(checkStatusTimer);
2841 }
2842 }
2843
2844 //应用按钮事件.
2845 function saveFunc(){
2846 target.dhcpNoticeShow(false);
2847 target.staticNoticeShow(false);
2848 target.pppoeNoticeShow(false);
2849 target.autoNoticeShow(false);
2850 if(pppObj.rj45_state == "dead"){
2851 showAlert("pppoe_msg");
2852 return;
2853 }
2854 var requestParams = {};
2855 if($("#pppoe_mode").val() == "PPPOE") {
2856 requestParams = $.extend({}, {
2857 goformId: "WAN_GATEWAYMODE_PPPOE",
2858 pppoe_username: target.user(),
2859 pppoe_cc: target.password()
2860 });
2861 } else if($("#pppoe_mode").val() == "AUTO") {
2862 requestParams = $.extend({}, {
2863 goformId: "WAN_GATEWAYMODE_AUTO",
2864 pppoe_username: target.autoUser(),
2865 pppoe_cc: target.autoPassword()
2866 });
2867 } else if($("#pppoe_mode").val() == "STATIC") {
2868 if(target.ipAddress() == target.defaultGateway()){
2869 showAlert("ip_gate_not_same");
2870 return;
2871 }
2872 if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
2873 showAlert("ip_innergate_not_same");
2874 return;
2875 }
2876 requestParams = $.extend({}, {
2877 goformId: "WAN_GATEWAYMODE_STATIC",
2878 static_wan_ipaddr: target.ipAddress(),
2879 static_wan_netmask: target.subnetMask(),
2880 static_wan_gateway: target.defaultGateway(),
2881 static_wan_primary_dns: target.primaryDNS(),
2882 static_wan_secondary_dns: target.secondaryDNS(),
2883 WAN_MODE: "STATIC"
2884 });
2885 } else {
2886 requestParams = $.extend({}, {
2887 goformId: "WAN_GATEWAYMODE_DHCP"
2888 });
2889 }
2890 requestParams.action_link = "connect";
2891 requestParams.dial_mode = target.pppMode();
2892 showLoading("waiting");
2893
2894 service.setPppoeDialMode(requestParams, function(data){
2895 if(data.result){
2896 target.currentMode($("#pppoe_mode").val());
2897 pppObj = service.getPppoeParams();
2898 checkConCounter = 0;
2899 timeoutTipShowed = false;
2900 setRj45CheckTimer("connect");
2901 $("#pppoeApply").translate();
2902 } else {
2903 errorOverlay("pppoe_message_send_fail");
2904 }
2905 });
2906
2907 }
2908
2909 //取消连接按钮事件.
2910 function cancelConnectFunc(){
2911 target.dhcpNoticeShow(false);
2912 target.staticNoticeShow(false);
2913 target.pppoeNoticeShow(false);
2914 target.autoNoticeShow(false);
2915 if(pppObj.rj45_state == "dead"){
2916 showAlert("pppoe_msg");
2917 return;
2918 }
2919 var requestParams = {
2920 dial_mode: target.pppMode(),
2921 action_link: "disconnect"
2922 };
2923 if(pppObj.ethwan_mode == "PPPOE") {
2924 requestParams = $.extend(requestParams, {
2925 goformId: "WAN_GATEWAYMODE_PPPOE",
2926 pppoe_username: pppObj.pppoe_username,
2927 pppoe_cc: pppObj.pppoe_cc
2928 });
2929 }else if(pppObj.ethwan_mode == "AUTO") {
2930 requestParams = $.extend(requestParams, {
2931 goformId: "WAN_GATEWAYMODE_AUTO",
2932 pppoe_username: pppObj.pppoe_username,
2933 pppoe_cc: pppObj.pppoe_cc
2934 });
2935 }else if(pppObj.ethwan_mode == "STATIC") {
2936 requestParams = $.extend(requestParams, {
2937 goformId: "WAN_GATEWAYMODE_STATIC",
2938 static_wan_ipaddr: pppObj.static_wan_ipaddr,
2939 static_wan_netmask: pppObj.static_wan_netmask,
2940 static_wan_gateway: pppObj.static_wan_gateway,
2941 static_wan_primary_dns: pppObj.static_wan_primary_dns,
2942 static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
2943 WAN_MODE: "STATIC"
2944 });
2945 }else {
2946 requestParams = $.extend(requestParams, {
2947 goformId: "WAN_GATEWAYMODE_DHCP"
2948 });
2949 }
2950 showLoading("waiting");
2951 service.setPppoeDialMode(requestParams, function(data){
2952 if(data.result){
2953 checkConCounter = 0;
2954 timeoutTipShowed = false;
2955 setRj45CheckTimer("disconnect");
2956 $("#pppoeApply").translate();
2957 } else {
2958 errorOverlay("pppoe_message_send_fail");
2959 }
2960 });
2961
2962 }
2963
2964 function radioHandlerFunc(){
2965 initContronler();
2966 return true;
2967 }
2968
2969 function changeModeDivFunc(){
2970 initContronler();
2971 }
2972
2973 }
2974
2975 function bindContainer(vm){
2976 var container = $('#container');
2977 ko.cleanNode(container[0]);
2978 ko.applyBindings(vm, container[0]);
2979
2980 }
2981 // 联网设置初始化.
2982
2983 function initialize() {
2984 var vm = new PPPoEViewModel();
2985 bindContainer(vm);
2986
2987 $("#pppoeApply").translate();
2988
2989 $('#pppoeForm').validate({
2990 submitHandler : function() {
2991 vm.save();
2992 },
2993 rules: {
2994 txtPin: "wps_pin_check",
2995 txtIpAddress: "dmz_ip_check",
2996 txtSubnetMask: {
2997 ipv4: true,
2998 subnetmask_check: true
2999 },
3000 txtDefaultGateway: {
3001 ipv4: true,
3002 gateway_check: true
3003 },
3004 txtPrimaryDNS: {
3005 ipv4: true,
3006 dns_check:true
3007 },
3008 txtSecondaryDNS: {
3009 ipv4: true,
3010 dns_check:true
3011 }
3012 }
3013 });
3014 }
3015
3016
3017//from 4.0
3018 // 有效DNS检查.
3019
3020function validateDns(dns){
3021 if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
3022 return false;
3023 }
3024 return true;
3025}
3026 // 联网设置初始化.
3027
3028function isStaticIPValid(ip, lanip, lanmask){
3029 if(!ip || !lanip || !lanmask){//各参数不能为空
3030 return false;
3031 }
3032 if(ip == lanip){// 与内网IP相等
3033 return true;
3034 }
3035 var res1 = [], res2 = [], mask = [];
3036 addr1 = ip.split(".");
3037 addr2 = lanip.split(".");
3038 mask = lanmask.split(".");
3039 for(var i = 0; i < addr1.length; i += 1){
3040 res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
3041 res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
3042 }
3043 if(res1.join(".") == res2.join(".")){//在同一个网段
3044 return true;
3045 }else{//不在同一个网段
3046 return false;
3047 }
3048}
3049
3050// 有效子网掩码验证.
3051
3052function isNetmaskIPValid(ip) {
3053 if (ip == 255 || ip == 254 || ip == 252 || ip == 248
3054 || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
3055 {
3056 return true;
3057 }
3058 else
3059 {
3060 return false;
3061 }
3062}
3063 // 有效子网掩码检查.
3064
3065function validateNetmask(netmask) {
3066 var array = new Array();
3067 array = netmask.split(".");
3068
3069 if (array.length != 4) {
3070 return false;
3071 }
3072
3073 array[0] = parseInt(array[0]);
3074 array[1] = parseInt(array[1]);
3075 array[2] = parseInt(array[2]);
3076 array[3] = parseInt(array[3]);
3077
3078 if (array[3] != 0) {
3079 if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
3080 return false;
3081 } else {
3082 if (!isNetmaskIPValid(array[3])) {
3083 return false;
3084 }
3085 }
3086 }
3087
3088 if (array[2] != 0) {
3089 if (array[1] != 255 || array[0] != 255) {
3090 return false;
3091 } else {
3092 if (!isNetmaskIPValid(array[2])) {
3093 return false;
3094 }
3095 }
3096 }
3097
3098 if (array[1] != 0) {
3099 if (array[0] != 255) {
3100 return false;
3101 } else{
3102 if (!isNetmaskIPValid(array[1])) {
3103 return false;
3104 }
3105 }
3106 }
3107 if(array[0]!=255) {
3108 return false;
3109 }
3110 if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
3111 return false;
3112 }
3113 return true;
3114}
3115
3116 // subnetmask_check校验规则
3117
3118jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
3119 var result = validateNetmask(value);
3120 return this.optional(element) || result;
3121});
3122 // dns_check校验规则
3123
3124jQuery.validator.addMethod("dns_check", function (value, element, param) {
3125 var result = validateDns(value);
3126 return this.optional(element) || result;
3127});
3128 // 有效网关检查.
3129
3130function validateGateway(wanIp, netmaskIp, gatewayIp) {
3131 if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
3132 return true;
3133 } else {
3134 return false;
3135 }
3136}
3137 // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
3138
3139function myConcat(ip1,ip2){
3140 var result = [];
3141 var iplArr = ip1.split(".");
3142 var ip2Arr = ip2.split(".");
3143 for(var i = 0; i < iplArr.length;i++){
3144 result[i] = (iplArr[i] & ip2Arr[i]);
3145 }
3146 return result.join(".");
3147}
3148 // gateway_check校验规则
3149
3150jQuery.validator.addMethod("gateway_check", function (value, element, param) {
3151 var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
3152 return this.optional(element) || result;
3153});
3154
3155 return {
3156 init: initialize
3157 };
3158});
3159//联网设置模块
3160define("network_dial_set","underscore jquery knockout set service".split(" "),
3161function(_, $, ko, config, service) {
3162
3163 //联网设置view model
3164 function DialVM() {
3165 var dialMode = service.getConnectionMode();
3166 var target = this;
3167
3168 target.selectMode = ko.observable(dialMode.connectionMode);
3169 target.enableFlag = ko.observable(true);
3170 target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
3171 var originalRoaming = dialMode.isAllowedRoaming;
3172
3173 target.setAllowedRoaming = setAllowedRoamingFunc;
3174
3175 var checkboxFlag = $(".checkboxToggle");
3176 target.checkEnable = checkEnableFunc;
3177
3178 //修改联网模式
3179 target.save = saveFunc;
3180
3181 function saveFunc() {
3182 showLoading();
3183 var connMode = target.selectMode();
3184 //当选择自动时,下发原先的勾选状态
3185 if (connMode == 'auto_dial') {
3186 originalRoaming = target.isAllowedRoaming();
3187 } else {
3188 target.isAllowedRoaming(originalRoaming);
3189 }
3190 service.setConnectionMode({
3191 connectionMode: connMode,
3192 isAllowedRoaming: target.isAllowedRoaming()
3193 }, function (result) {
3194 if (result.result == "success") {
3195 successOverlay();
3196 } else {
3197 errorOverlay();
3198 }
3199 });
3200 }
3201
3202 function setAllowedRoamingFunc() {
3203 if(!$("#roamBtn").hasClass("disable")){
3204 var checkbox = $("#isAllowedRoaming:checked");
3205 if(checkbox && checkbox.length == 0 ){
3206 target.isAllowedRoaming("on");
3207 }else{
3208 target.isAllowedRoaming("off");
3209 }
3210 }
3211 }
3212
3213 function checkEnableFunc() {
3214 var status = service.getStatusInfo();
3215
3216 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
3217 target.enableFlag(false);
3218 disableCheckbox(checkboxFlag);
3219 }
3220 else {
3221 target.enableFlag(true);
3222 enableCheckbox(checkboxFlag);
3223 }
3224 }
3225
3226 }
3227
3228 //联网设置初始化.
3229 function initialize() {
3230 var vm = new DialVM();
3231 bindContainer(vm);
3232
3233 vm.checkEnable();
3234 addInterval( vm.checkEnable, 1000);
3235 }
3236
3237 function bindContainer(vm){
3238 var container = $('#container');
3239 ko.cleanNode(container[0]);
3240 ko.applyBindings(vm, container[0]);
3241
3242 }
3243
3244 return {
3245 init: initialize
3246 };
3247});
3248// APN Setting 模块
3249define("network_apn_set","underscore jquery knockout set service".split(" "),
3250 function (_, $, ko, config, service) {
3251
3252 //获取鉴权方式
3253
3254 function getAuthModes() {
3255 return _.map(config.APN_AUTH_MODES, function (item) {
3256 return new Option(item.name, item.value);
3257 });
3258 }
3259
3260 function getApnPdpTypes() {
3261 var pdpTypesArray = [new Option('IPv4', 'IP')];
3262 if (config.IPV6_SUPPORT) {
3263 pdpTypesArray.push(new Option('IPv6', 'IPv6'));
3264 if (config.IPV4V6_SUPPORT) {
3265 pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
3266 }
3267 if (config.IPV4_AND_V6_SUPPORT) {
3268 pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
3269 }
3270 }
3271 return pdpTypesArray;
3272 }
3273
3274 //获取apn相关信息
3275
3276 function getApnSet() {
3277 var apnInfo = service.getApnSettings();
3278 apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
3279 apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
3280 apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
3281 return apnInfo;
3282 }
3283 var apnConfigs = {};
3284 var ipv6ApnConfigs = {};
3285 var autoApnConfigs = {};
3286
3287 //解析自动apn信息
3288
3289 function getAutoApnsConfig(autoApnV4, autoApnV6) {
3290 var autoApnsV4 = [];
3291 var autoApnsV6 = [];
3292
3293 if (autoApnV4 && autoApnV4.length > 5) {
3294 var apnArr = autoApnV4.split("||");
3295 for (var ki = 0; ki < apnArr.length; ki++) {
3296 if (apnArr[ki] != "") {
3297 var apnItem = parseApnItem(apnArr[ki], false);
3298 autoApnsV4.push(apnItem);
3299 }
3300 }
3301 }
3302 if (autoApnV6 && autoApnV6.length > 5) {
3303 var apnArr = autoApnV6.split("||");
3304 for (var ki = 0; ki < apnArr.length; ki++) {
3305 if (apnArr[ki] != "") {
3306 var apnItem = parseApnItem(apnArr[ki], false);
3307 autoApnsV6.push(apnItem);
3308 }
3309 }
3310 }
3311 return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
3312 }
3313 //解析apn信息
3314
3315 function getApnConfigs(apnsStr, isIpv6) {
3316 var apnCfgs = [];
3317 var theApnConfigs = {};
3318 if (apnsStr && apnsStr.length > 10) {
3319 var apnArr = apnsStr.split("||");
3320 for (var ki = 0; ki < apnArr.length; ki++) {
3321 if (apnArr[ki] != "") {
3322 var apnItem = parseApnItem(apnArr[ki], isIpv6);
3323 apnCfgs.push(apnItem);
3324 theApnConfigs[apnItem.profileName] = apnItem;
3325 }
3326 }
3327 }
3328 if (isIpv6 == false) {
3329 apnConfigs = theApnConfigs;
3330 } else {
3331 ipv6ApnConfigs = theApnConfigs;
3332 }
3333 return apnCfgs;
3334 }
3335
3336 //解析单条apn信息
3337
3338 function parseApnItem(apnStr, isIpv6) {
3339 var apnItem = {};
3340 var items = apnStr.split("($)");
3341 for (var ki = 0; ki < items.length; ki++) {
3342 apnItem.profileName = items[0];
3343 apnItem.pdpType = items[7];
3344 if (isIpv6 == false) {
3345 apnItem.dnsMode = items[10];
3346 apnItem.dns1 = items[11];
3347 apnItem.dns2 = items[12];
3348 apnItem.wanApn = items[1];
3349 apnItem.authMode = items[4].toLowerCase();
3350 apnItem.username = items[5];
3351 apnItem.password = items[6];
3352 } else {
3353 apnItem.dnsModeV6 = items[10];
3354 apnItem.dns1V6 = items[11];
3355 apnItem.dns2V6 = items[12];
3356 apnItem.wanApnV6 = items[1];
3357 apnItem.authModeV6 = items[4].toLowerCase();
3358 apnItem.usernameV6 = items[5];
3359 apnItem.passwordV6 = items[6];
3360 }
3361 }
3362 return apnItem;
3363 }
3364 //合并V4\V6自动apn信息
3365
3366 function dealAutoApnsV4V6(v4, v6) {
3367 autoApnConfigs = {};
3368 var autoApns = [];
3369 for (var ki = 0; ki < v4.length; ki++) {
3370 var apnElem = v4[ki];
3371 var itemsV6 = v6[ki];
3372 if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
3373 apnElem.usernameV6 = itemsV6.username;
3374 apnElem.passwordV6 = itemsV6.password;
3375 apnElem.dns1V6 = itemsV6.dns1;
3376 apnElem.dns2V6 = itemsV6.dns2;
3377 apnElem.wanApnV6 = itemsV6.wanApn;
3378 apnElem.authModeV6 = itemsV6.authMode;
3379 apnElem.dnsModeV6 = itemsV6.dnsMode;
3380 }
3381 autoApns.push(apnElem);
3382 autoApnConfigs[apnElem.profileName] = apnElem;
3383 }
3384 return autoApns;
3385 }
3386
3387 function getProfileOptions(apns) {
3388 return _.map(apns, function (item) {
3389 return new Option(item.profileName, item.profileName);
3390 });
3391 }
3392
3393 //APNViewModel
3394
3395 function APNViewModel() {
3396 var target = this;
3397 var apnSettings = getApnSet();
3398 if (apnSettings.apnNumPreset) {
3399 config.maxApnNumber = apnSettings.apnNumPreset;
3400 }
3401
3402 target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
3403 target.apnMode = ko.observable(apnSettings.apnMode);
3404 target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
3405 target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
3406 target.wanDial = ko.observable(apnSettings.wanDial);
3407
3408 target.showApnDns = ko.observable(config.SHOW_APN_DNS);
3409 target.index = ko.observable(apnSettings.currIndex);
3410 target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
3411 target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
3412
3413 target.apn = ko.observable(apnSettings.wanApn);
3414 target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
3415 target.dns1 = ko.observable(apnSettings.dns1);
3416 target.dns2 = ko.observable(apnSettings.dns2);
3417 target.authModes = ko.observableArray(getAuthModes());
3418 target.username = ko.observable(apnSettings.username);
3419 target.password = ko.observable(apnSettings.password);
3420
3421 target.pdpTypes = ko.observableArray(getApnPdpTypes());
3422 target.selectedPdpType = ko.observable(apnSettings.pdpType);
3423 target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
3424 target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
3425 target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
3426
3427 target.showPassword = ko.observable(false);
3428
3429 target.apnV6 = ko.observable(apnSettings.wanApnV6);
3430 target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
3431 target.dns1V6 = ko.observable(apnSettings.dns1V6);
3432 target.dns2V6 = ko.observable(apnSettings.dns2V6);
3433 target.authModesV6 = ko.observableArray(getAuthModes());
3434 target.usernameV6 = ko.observable(apnSettings.usernameV6);
3435 target.passwordV6 = ko.observable(apnSettings.passwordV6);
3436 target.pdpTypeNote = ko.observable(true);
3437 if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
3438 target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
3439 } else {
3440 target.selectedAutoProfile = ko.observable();
3441 }
3442
3443 if (config.EMPTY_APN_SUPPORT == false) {
3444 $("#apn_ipv4_apn").addClass("required");
3445 $("#apn_ipv6_apn").addClass("required");
3446 } else {
3447 $("#apn_ipv4_apn").removeClass("required");
3448 $("#apn_ipv6_apn").removeClass("required");
3449 }
3450
3451 target.disableProfile = ko.observable(false); //表示处于新增页面
3452 target.addApnHide = ko.observable(true);
3453 target.defaultCfg = ko.observable(true); //当前选中的是默认APN
3454 target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
3455
3456 target.selectedAuthentication = ko.observable(apnSettings.authMode);
3457 target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
3458
3459
3460 target.transApnV6 = ko.observable('apn');
3461 target.transDnsModeV6 = ko.observable('apn_dns_mode');
3462 target.transDns1V6 = ko.observable('apn_dns1');
3463 target.transDns2V6 = ko.observable('apn_dns2');
3464 target.transAuthV6 = ko.observable('apn_authentication');
3465 target.transUserNameV6 = ko.observable('apn_user_name');
3466 target.transPasswordV6 = ko.observable('apn_password');
3467
3468 target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
3469 target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
3470 target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
3471 target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
3472 target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
3473 target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
3474 target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
3475
3476 target.setDefaultVisible = ko.observable(!isConnectedNetWork());
3477
3478 target.tmp1 = ko.computed(function () {
3479 if (target.selectedPdpType() == "IPv6") {
3480 target.transApnV6('apn');
3481 target.transDnsModeV6('apn_dns_mode');
3482 target.transDns1V6('apn_dns1');
3483 target.transDns2V6('apn_dns2');
3484 target.transAuthV6('apn_authentication');
3485 target.transUserNameV6('apn_user_name');
3486 target.transPasswordV6('apn_password');
3487 } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3488 target.transApn('apn_ipv4_apn');
3489 target.transDnsMode('apn_dns_mode_ipv4');
3490 target.transDns1('apn_dns1_ipv4');
3491 target.transDns2('apn_dns2_ipv4');
3492 target.transAuth('apn_authentication_ipv4');
3493 target.transUserName('apn_user_name_ipv4');
3494 target.transPassword('apn_password_ipv4');
3495
3496 target.transApnV6('apn_ipv6_apn');
3497 target.transDnsModeV6('apn_dns_mode_ipv6');
3498 target.transDns1V6('apn_dns1_ipv6');
3499 target.transDns2V6('apn_dns2_ipv6');
3500 target.transAuthV6('apn_authentication_ipv6');
3501 target.transUserNameV6('apn_user_name_ipv6');
3502 target.transPasswordV6('apn_password_ipv6');
3503 } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
3504 target.transApn('apn');
3505 target.transDnsMode('apn_dns_mode');
3506 target.transDns1('apn_dns1');
3507 target.transDns2('apn_dns2');
3508 target.transAuth('apn_authentication');
3509 target.transUserName('apn_user_name');
3510 target.transPassword('apn_password');
3511 } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
3512 target.transApn('apn');
3513 target.transDnsMode('apn_dns_mode');
3514 target.transDns1('apn_dns1');
3515 target.transDns2('apn_dns2');
3516 target.transAuth('apn_authentication');
3517 target.transUserName('apn_user_name');
3518 target.transPassword('apn_password');
3519 }
3520 $("#apn_setting_form").translate();
3521 });
3522
3523 target.autoApnChecked = ko.computed(function () {
3524 return target.apnMode() == "auto";
3525 });
3526
3527 target.hasCapacity = ko.computed(function () {
3528 if (target.profiles().length < config.maxApnNumber) {
3529 return true;
3530 } else {
3531 return false;
3532 }
3533 });
3534
3535 target.showDnsV6 = ko.computed(function () {
3536 return target.dnsModeV6() == "manual";
3537 });
3538
3539 target.showDns = ko.computed(function () {
3540 return target.dnsMode() == "manual";
3541 });
3542
3543
3544 checkDefaultProfileStatus();
3545 target.checkInputDisable = ko.computed(function () {
3546 if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
3547 return false;
3548 }
3549 if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
3550 return true;
3551 }
3552 if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
3553 return false;
3554 }
3555 return false;
3556 });
3557
3558 var data = service.getDeviceInfo();
3559 target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
3560
3561
3562 target.showAutoApnDetail = ko.computed(function () {
3563 if (target.apnMode() != "auto") {
3564 return true;
3565 } else {
3566 return target.autoProfiles().length > 0;
3567 }
3568 });
3569 //密码显示事件
3570 target.showPasswordHandler = function () {
3571 var checkbox = $("#showPassword:checked");
3572 if (checkbox && checkbox.length == 0) {
3573 target.showPassword(true);
3574 } else {
3575 target.showPassword(false);
3576 }
3577 };
3578 //auto apn profile change 事件处理
3579
3580 target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
3581
3582
3583 //profile change 事件处理
3584
3585 target.profileChangeHandler = profileChangeHandlerFunc;
3586
3587
3588 //切换profile时重置下面的显示项
3589 target.setUIData = setUIDataFunc;
3590
3591
3592 //设置默认apn状态
3593
3594 function checkDefaultProfileStatus() {
3595 var index = getApnIndex();
3596 //默认apn不允许编辑
3597 if (target.apnMode() != "auto") { //当前选中与实际不一致的话
3598 if (target.selectedProfile() != target.defApn()) {
3599 target.defaultCfg(false);
3600 } else {
3601 target.defaultCfg(true); //默认APN
3602 }
3603 } else {
3604 if (target.selectedAutoProfile() != target.defApn()) {
3605 target.defaultCfg(false);
3606 } else {
3607 target.defaultCfg(true); //默认APN
3608 }
3609 }
3610
3611 if (index >= config.defaultApnSize) {
3612 target.predeterminedCfg(false);
3613 } else {
3614 target.predeterminedCfg(true); //预置APN
3615 }
3616 }
3617
3618
3619 //设置为默认apn
3620
3621 target.setDefaultAct = setDefaultActFunc;
3622
3623
3624
3625 //APN mode change 事件处理
3626
3627 target.apnModeChangeHandler = apnModeChangeHandlerFunc;
3628
3629
3630 function doSetDefaultAct() {
3631 var index = 0;
3632 if (target.apnMode() != 'auto') {
3633 index = getApnIndex();
3634 target.selectedProfile($("#profile").val());
3635 } else {
3636 index = getAutoApnIndex();
3637 target.selectedAutoProfile($("#autoProfile").val());
3638 }
3639 var selectedProfileDetail = target.getSelectedManualProfile();
3640 service.setDefaultApn({
3641 index: index,
3642 apnMode: target.apnMode(),
3643 pdpType: selectedProfileDetail.pdpType,
3644
3645 profileName: selectedProfileDetail.profileName,
3646 wanApn: selectedProfileDetail.wanApn,
3647 authMode: selectedProfileDetail.authMode,
3648 username: selectedProfileDetail.username,
3649 password: selectedProfileDetail.password,
3650 dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
3651 dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
3652 dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
3653 }, function (data) {
3654 if (data.result) {
3655 //showLoading("apn_alert_restart");
3656 //restartDevice(service);
3657 addTimeout(function () {
3658 initialize(true);
3659 target.apnModeChangeHandler();
3660 successOverlay();
3661 }, 500);
3662 } else {
3663 errorOverlay();
3664 }
3665 }, function (data) {
3666 errorOverlay();
3667 });
3668 }
3669
3670 target.getSelectedManualProfile = getSelectedManualProfileFunc;
3671
3672
3673 //获取自动apn索引
3674
3675 function getAutoApnIndex() {
3676 var configs = $("#autoProfile option");
3677 for (var ki = 0; ki < configs.length; ki++) {
3678 if (configs[ki].value == target.selectedAutoProfile()) {
3679 return ki;
3680 }
3681 }
3682 return configs.length - 1;
3683 }
3684
3685 //获取apn索引
3686
3687 function getApnIndex() {
3688 var configs = $("#profile option");
3689 if (configs.length == 0) {
3690 configs = target.profiles();
3691 }
3692 var ki = 0;
3693 for (; ki < configs.length; ki++) {
3694 if (configs[ki].value == target.selectedProfile()) {
3695 break;
3696 }
3697 }
3698 return ki;
3699 }
3700
3701 //保存APN设置信息
3702
3703 target.saveAct = saveActFunc;
3704
3705 //编辑APN信息
3706
3707 function editApnSetting(preAct) { //默认设置按钮触发为TRUE
3708 showLoading();
3709 var apnIndex = getApnIndex();
3710 var sameInfo = false;
3711 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3712 sameInfo = true;
3713 }
3714 var needDoDefault = false;
3715 if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
3716 needDoDefault = true;
3717 }
3718 service.addOrEditApn({
3719 profileName: target.profileName(),
3720 pdpType: target.selectedPdpType(),
3721 index: apnIndex,
3722
3723 wanApn: target.apn(),
3724 authMode: target.selectedAuthentication(),
3725 username: target.username(),
3726 password: target.password(),
3727 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3728 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3729 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3730
3731 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3732 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3733 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3734 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3735 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3736 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3737 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3738 }, function (data) {
3739 if (data.result) {
3740 apnSettings = getApnSet();
3741 if (target.profileName() != target.selectedProfile()) {
3742 var newProfileName = target.profileName();
3743 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3744 $('#profile').val(newProfileName).trigger('change');
3745 }
3746 if (needDoDefault == false) {
3747 successOverlay();
3748 } else {
3749 doSetDefaultAct();
3750 }
3751 } else {
3752 errorOverlay();
3753 }
3754 }, function (data) {
3755 errorOverlay();
3756 });
3757 }
3758
3759 //新增APN信息
3760
3761 function addNewApnSetting() {
3762 showLoading("waiting");
3763 var optionLen = $("option", "#profile").length;
3764 if (optionLen < config.defaultApnSize) {
3765 errorOverlay();
3766 return;
3767 }
3768 // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
3769 // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
3770 var sameInfo = false;
3771 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3772 sameInfo = true;
3773 }
3774
3775 service.addOrEditApn({
3776 profileName: target.profileName(),
3777 pdpType: target.selectedPdpType(),
3778 index: optionLen,
3779
3780 wanApn: target.apn(),
3781 authMode: target.selectedAuthentication(),
3782 username: target.username(),
3783 password: target.password(),
3784 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3785 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3786 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3787
3788 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3789 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3790 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3791 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3792 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3793 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3794 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3795 }, function (data) {
3796 if (data.result) {
3797 apnSettings = getApnSet();
3798 if (target.profileName() != target.selectedProfile()) {
3799 var newProfileName = target.profileName();
3800 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3801 $('#profile').val(newProfileName).trigger('change');
3802 }
3803 doSetDefaultAct();
3804 } else {
3805 errorOverlay();
3806 }
3807 }, function (data) {
3808 errorOverlay();
3809 });
3810 }
3811
3812
3813
3814 var tempApn = {};
3815 //删除APN
3816
3817 target.deleteAct = deleteActFunc;
3818
3819 //取消新增APN
3820
3821 target.cancelAddAct = cancelAddActFunc;
3822
3823 //进入新增APN页面
3824
3825 target.addAct = addActFunc;
3826 //进入新增APN页面
3827 function addActFunc() {
3828 clearValidateMsg('#apn_setting_form');
3829 target.pdpTypeNote(true);
3830 target.disableProfile(true);
3831 target.addApnHide(true);
3832 tempApn = {
3833 profileName: target.profileName(),
3834 selectedPdpType: target.selectedPdpType(),
3835
3836 wanApnV6: target.apnV6(),
3837 dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
3838 dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
3839 dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
3840 authModeV6: target.selectedAuthenticationV6(),
3841 usernameV6: target.usernameV6(),
3842 passwordV6: target.passwordV6(),
3843
3844 wanApn: target.apn(),
3845 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3846 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3847 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3848 authMode: target.selectedAuthentication(),
3849 username: target.username(),
3850 password: target.password(),
3851
3852 };
3853 target.profileName("");
3854 target.selectedPdpType("IP");
3855 target.selectedPdpTypeTmp("IP");
3856
3857 target.apnV6("");
3858 target.dnsModeV6("auto");
3859 target.dns1V6("");
3860 target.dns2V6("");
3861 target.selectedAuthenticationV6("none");
3862 target.usernameV6("");
3863 target.passwordV6("");
3864
3865 target.apn("");
3866 target.dnsMode("auto");
3867 target.dns1("");
3868 target.dns2("");
3869 target.selectedAuthentication("none");
3870 target.username("");
3871 target.password("");
3872
3873 }
3874
3875 //取消新增APN
3876 function cancelAddActFunc() {
3877 clearValidateMsg('#apn_setting_form');
3878 target.pdpTypeNote(false);
3879 target.disableProfile(false);
3880 target.addApnHide(false);
3881 target.profileName(tempApn.profileName);
3882 target.selectedPdpType(tempApn.selectedPdpType);
3883 target.selectedPdpTypeTmp(tempApn.selectedPdpType);
3884
3885 target.apnV6(tempApn.wanApnV6);
3886 target.dnsModeV6(tempApn.dnsModeV6);
3887 target.dns1V6(tempApn.dns1V6);
3888 target.dns2V6(tempApn.dns2V6);
3889 target.selectedAuthenticationV6(tempApn.authModeV6);
3890 target.usernameV6(tempApn.usernameV6);
3891 target.passwordV6(tempApn.passwordV6);
3892
3893 target.apn(tempApn.wanApn);
3894 target.dnsMode(tempApn.dnsMode);
3895 target.dns1(tempApn.dns1);
3896 target.dns2(tempApn.dns2);
3897 target.selectedAuthentication(tempApn.authMode);
3898 target.username(tempApn.username);
3899 target.password(tempApn.password);
3900
3901 }
3902
3903 //删除APN
3904 function deleteActFunc() {
3905 if (!target.selectedProfile()) {
3906 showAlert("apn_no_select_alert");
3907 return false;
3908 }
3909 if (target.predeterminedCfg()) { //预置的apn不允许删除
3910 errorOverlay("apn_delete_cant_delete_default");
3911 return false;
3912 }
3913 if (getApnSet().profileName == target.profileName()) {
3914 errorOverlay("apn_cant_delete_current");
3915 return false;
3916 }
3917
3918 showConfirm("apn_delete_confirm", function () {
3919 showLoading('deleting');
3920 service.deleteApn({
3921 index: getApnIndex()
3922 }, function (data) {
3923 if (data.result) {
3924 target.profiles(getProfileOptions(getApnSet().apnConfigs));
3925 target.selectedProfile(target.defApn());
3926 target.profileChangeHandler();
3927 successOverlay();
3928 } else {
3929 errorOverlay();
3930 }
3931 }, function (data) {
3932 errorOverlay();
3933 });
3934 });
3935 }
3936
3937 //保存APN设置信息
3938 function saveActFunc() {
3939 if (!$('#apn_setting_form').valid()) {
3940 return false;
3941 }
3942 if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
3943 showAlert("apn_no_select_alert");
3944 return false;
3945 }
3946 var exist = false;
3947 $.each(target.profiles(), function (i, e) {
3948 if (e.value == target.profileName()) {
3949 exist = true;
3950 }
3951 });
3952
3953 if (target.disableProfile() == false) {
3954 if (exist && target.selectedProfile() != target.profileName()) {
3955 showInfo("apn_save_profile_exist");
3956 return false;
3957 }
3958 if (target.predeterminedCfg()) { //预置的APN不可以修改
3959 errorOverlay();
3960 return false;
3961 }
3962 if (target.predeterminedCfg() || target.defaultCfg()) {
3963 //showConfirm("apn_alert", function () {
3964 editApnSetting(false);
3965 //});
3966 } else {
3967 editApnSetting(false);
3968 }
3969 } else {
3970
3971 if ($("#profile option").length >= config.maxApnNumber) {
3972 showInfo({
3973 msg: "apn_profile_full",
3974 params: [config.maxApnNumber]
3975 });
3976 return false;
3977 }
3978 if (exist) {
3979 showInfo("apn_save_profile_exist");
3980 return false;
3981 }
3982 var info = service.getStatusInfo();
3983 if (info.connectStatus != "ppp_connected") {
3984 //showConfirm("apn_alert", function () {
3985 addNewApnSetting();
3986 //});
3987
3988 } else {
3989 showConfirm("apn_diconneted_network_confirm", function () {
3990 showLoading('disconnecting');
3991 service.disconnect({}, function (data) {
3992 if (data.result) {
3993 config.connect_flag = true;
3994 addNewApnSetting();
3995 } else {
3996 errorOverlay();
3997 }
3998 });
3999 });
4000 }
4001 }
4002 }
4003
4004 function getSelectedManualProfileFunc() {
4005 var cfg = {};
4006 var profileVal = $("#profile").val();
4007 if (typeof target.selectedProfile() == 'undefined') {
4008 target.selectedProfile(profileVal);
4009 }
4010 var cfgV4 = apnConfigs[profileVal];
4011 var cfgV6 = ipv6ApnConfigs[profileVal];
4012 if (cfgV4 && !cfgV6) {
4013 $.extend(cfg, cfgV4);
4014 } else if (cfgV4 && cfgV6) {
4015 if (!!cfgV4.pdpType) {
4016 $.extend(cfg, cfgV6);
4017 $.extend(cfg, cfgV4);
4018 } else {
4019 $.extend(cfg, cfgV4);
4020 $.extend(cfg, cfgV6);
4021 }
4022 }
4023 return cfg;
4024 }
4025
4026 //APN mode change 事件处理
4027 function apnModeChangeHandlerFunc(data, event) {
4028 if (target.apnMode() != 'auto') {
4029 target.profileChangeHandler();
4030 } else {
4031 if (target.showAutoApnDetail()) {
4032 target.autoProfileChangeHandler();
4033 }
4034 }
4035 return true;
4036 }
4037
4038 //设置为默认apn
4039 function setDefaultActFunc() {
4040 if (!target.selectedProfile()) {
4041 showAlert("apn_no_select_alert");
4042 return false;
4043 }
4044 var connectStatus = service.getConnectionInfo().connectStatus;
4045 if (connectStatus == "ppp_connecting") {
4046 showAlert({
4047 msg: "apn_cant_modify_status",
4048 params: [$.i18n.prop("connecting").toLowerCase()]
4049 });
4050 return false;
4051 } else if (connectStatus == "ppp_disconnecting") {
4052 showAlert({
4053 msg: "apn_cant_modify_status",
4054 params: [$.i18n.prop("disconnecting").toLowerCase()]
4055 });
4056 return false;
4057 } else if (connectStatus == "ppp_connected") {
4058 showAlert({
4059 msg: "apn_cant_modify_status",
4060 params: [$.i18n.prop("connected").toLowerCase()]
4061 });
4062 return false;
4063 }
4064 if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
4065 //showConfirm("apn_alert", function () {
4066 showLoading("waiting");
4067 doSetDefaultAct();
4068 //});
4069 } else {
4070 if ($('#apn_setting_form').valid() == false) {
4071 $(".error:first", "#apn_setting_form").focus();
4072 } else {
4073 var exist = false;
4074 $.each(target.profiles(), function (i, e) {
4075 if (e.value == target.profileName()) {
4076 exist = true;
4077 }
4078 });
4079 if (exist && target.selectedProfile() != target.profileName()) {
4080 showInfo("apn_save_profile_exist");
4081 return false;
4082 }
4083 //showLoading("waiting");
4084 //showConfirm("apn_alert", function () {
4085 editApnSetting(true);
4086 //});
4087 }
4088 }
4089 }
4090
4091 //切换profile时重置下面的显示项
4092 function setUIDataFunc(data) {
4093 clearValidateMsg('#apn_setting_form');
4094 if (!data) {
4095 return;
4096 }
4097 target.selectedPdpType(data.pdpType || 'IP');
4098 target.selectedPdpTypeTmp(data.pdpType || 'IP');
4099 target.profileName(data.profileName);
4100
4101 target.apn(data.wanApn);
4102 target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
4103 target.dns1(data.dns1);
4104 target.dns2(data.dns2);
4105 target.username(data.username);
4106 target.password(data.password);
4107 target.selectedAuthentication(data.authMode || 'none');
4108
4109 target.apnV6(data.wanApnV6);
4110 target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
4111 target.dns1V6(data.dns1V6);
4112 target.dns2V6(data.dns2V6);
4113 target.usernameV6(data.usernameV6);
4114 target.passwordV6(data.passwordV6);
4115 target.selectedAuthenticationV6(data.authModeV6 || 'none');
4116 }
4117
4118 //profile change 事件处理
4119 function profileChangeHandlerFunc(data, event) {
4120 target.pdpTypeNote(true);
4121 if (target.apnMode() != 'manual') {
4122 return true;
4123 }
4124 var cfg = target.getSelectedManualProfile();
4125 target.setUIData(cfg);
4126 checkDefaultProfileStatus();
4127 return true;
4128 }
4129
4130 //auto apn profile change 事件处理
4131 function autoProfileChangeHandlerFunc(data, event) {
4132 if (target.apnMode() != 'auto') {
4133 return true;
4134 }
4135 var cfg = autoApnConfigs[target.selectedAutoProfile()];
4136 target.setUIData(cfg);
4137 checkDefaultProfileStatus();
4138 return true;
4139 }
4140
4141 function pdpTypeChangeAlertFunc() {
4142 if (target.pdpTypeNote()) {
4143 showAlert({
4144 msg: "apn_pdptype_change_note",
4145 params: [data.lanDomain, data.ipAddress]
4146 });
4147 }
4148 if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
4149 if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
4150 if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
4151 target.apn(target.apnV6());
4152 target.dnsMode(target.dnsModeV6());
4153 target.dns1(target.dns1V6());
4154 target.dns2(target.dns2V6());
4155 target.username(target.usernameV6());
4156 target.password(target.passwordV6());
4157 target.selectedAuthentication(target.selectedAuthenticationV6());
4158 } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
4159 target.apnV6(target.apn());
4160 target.dnsModeV6(target.dnsMode());
4161 target.dns1V6(target.dns1());
4162 target.dns2V6(target.dns2());
4163 target.usernameV6(target.username());
4164 target.passwordV6(target.password());
4165 target.selectedAuthenticationV6(target.selectedAuthentication());
4166 }
4167 }
4168 }
4169 target.selectedPdpTypeTmp(target.selectedPdpType());
4170 }
4171
4172
4173 }
4174
4175 //是否已联网
4176
4177 function isConnectedNetWork() {
4178 var info = service.getConnectionInfo();
4179 return info.connectStatus == "ppp_connected";
4180 }
4181
4182 function initVar() {
4183 apnConfigs = {};
4184 ipv6ApnConfigs = {};
4185 autoApnConfigs = {};
4186 }
4187 function bindContainer(vm){
4188 var container = $('#container');
4189 ko.cleanNode(container[0]);
4190 ko.applyBindings(vm, container[0]);
4191 }
4192 //初始化ViewModel
4193
4194 function initialize(formInit) {
4195 initVar();
4196
4197 var vm = new APNViewModel();
4198 bindContainer(vm);
4199
4200 if (!formInit) {
4201 addInterval(function () {
4202 vm.setDefaultVisible(!isConnectedNetWork());
4203 }, 1000);
4204 }
4205 $('#apn_setting_form').validate({
4206 submitHandler: function () {
4207 vm.saveAct();
4208 },
4209 rules: {
4210 profile_name: 'apn_profile_name_check',
4211 apn_ipv4_apn: 'apn_check',
4212 apn_dns1_ipv4: "ipv4",
4213 apn_dns2_ipv4: "ipv4",
4214 apn_ipv6_apn: 'apn_check',
4215 apn_dns1_ipv6: "ipv6",
4216 apn_dns2_ipv6: "ipv6",
4217 apn_user_name_ipv4: 'ppp_username_check',
4218 apn_secretcode_ipv4: 'ppp_secretcode_check',
4219 apn_user_name_ipv6: 'ppp_username_check',
4220 apn_secretcode_ipv6: 'ppp_secretcode_check'
4221 }
4222 });
4223 }
4224
4225 return {
4226 init: initialize
4227 };
4228});