blob: 650aeb5bc8cbc7eafa1737a78aac56aca0cccaea [file] [log] [blame]
yuezonghec78e2ef2025-02-13 17:57:46 -08001
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 target.hasUpnp = config.HAS_UPNP;
1913 }
1914
1915 function initialize() {
1916 var fwVm = new FirewallVM();
1917 bindingContainer(fwVm);
1918 }
1919 function bindingContainer(fwVm)
1920 {
1921 var container = $('#container');
1922 ko.cleanNode(container[0]);
1923 ko.applyBindings(fwVm, container[0]);
1924 }
1925 return {
1926 init : initialize
1927 };
1928});
1929
1930define("ddns","underscore jquery knockout set service".split(" "), function (_, $, ko, config, service) {
1931 var ddnsSetModes = _.map(config.DDNSSetMode, newOption);
1932 var ddnsProviderList = _.map(config.DDNSDDP, newOption);
1933 var ddns_mode_select = _.map(config.ddns_Modeselect, newOption);
1934 function newOption(optItem) {
1935 return new Option(optItem.name, optItem.value);
1936 }
1937 function DdnsViewModel() {
1938 var target = this;
1939 target.hasUssd = config.HAS_USSD;
1940 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1941 var data = service.getDdnsParams();
1942 target.ddnsSetModes = ko.observableArray(ddnsSetModes);
1943 target.ddnsProviderList = ko.observableArray(ddnsProviderList);
1944 target.ddns_mode_select = ko.observableArray(ddns_mode_select);
1945 target.currentMode = ko.observable(data.DDNS_Enable);
1946 target.currentModeselect = ko.observable(data.DDNS_Mode);
1947 target.currentProviderList = ko.observable("dyndns.org");
1948 $.each(config.DDNSDDP, function (i, n) {
1949 if (data.DDNSProvider == n.value) {
1950 target.currentProviderList(data.DDNSProvider);
1951 }
1952 });
1953 target.DDNSaccount = ko.observable(data.DDNSAccount);
1954 target.DDNSpasswd = ko.observable(data.DDNSPassword);
1955 target.DDNSname = ko.observable(data.DDNS);
1956 target.DDNS_HashValue = ko.observable(data.DDNS_Hash_Value);
1957 target.isddnsStatusTrans = ko.observable();
1958 target.isEnableSet = ko.observable();
1959 target.isHashValue = ko.observable();
1960 target.isddnsaccount = ko.observable();
1961 target.isddnspasswd = ko.observable();
1962 target.isDDNSStatus = ko.observable();
1963 target.isddnsdomainName = ko.observable();
1964 target.isNone = ko.observable();
1965 target.onStates = ko.observable();
1966 target.showPassword_ddns = ko.observable(false);
1967 target.showPasswordHandler_ddns = showPasswordHandler_ddns;
1968 changeddnsProviderList();
1969 target.changeDdnsProvider = changeDdnsProviderFunc;
1970 changeSetDdnsMode();
1971 target.changeSetDdnsMode = changeSetDdnsModeFunc;
1972 updateScanDdnsStatus();
1973 target.apply = applyFunc;
1974 function updateScanDdnsStatus() {
1975 var trans = "";
1976 $.getJSON("/reqproc/proc_get", {
1977 cmd: "getddns_status",
1978 "_": new Date().getTime()
1979 }, function (data) {
1980 if (data.getddns_status == "0") {
1981 trans = "register successful";
1982 target.onStates(true);
1983 } else if (data.getddns_status == "1") {
1984 trans = "login error";
1985 target.onStates(true);
1986 } else if (data.getddns_status == "2") {
1987 trans = "network error";
1988 target.onStates(true);
1989 } else if (data.getddns_status == "3") {
1990 trans = "registering";
1991 target.onStates(true);
1992 } else if (data.getddns_status == "4") {
1993 trans = "not registered";
1994 target.onStates(true);
1995 } else if (data.getddns_status == "5") {
1996 trans = "error registering";
1997 target.onStates(true);
1998 } else if (data.getddns_status == "-1") {
1999 trans = "";
2000 target.onStates(true);
2001 }
2002 target.isddnsStatusTrans($.i18n.prop(trans));
2003 addTimeout(updateScanDdnsStatus, 2000);
2004 });
2005 }
2006 function changeSetDdnsMode() {
2007 if (target.currentMode() != "1") {
2008 target.isEnableSet(false);
2009 } else {
2010 target.isEnableSet(true);
2011 }
2012 return true;
2013 }
2014 function changeSetDdnsModeFunc() {
2015 changeSetDdnsMode();
2016 }
2017 function showPasswordHandler_ddns() {
2018 $("#ddns_secretcode_input").parent().find(".error").hide();
2019 var checkbox = $("#showPassword_ddns:checked");
2020 if (checkbox && checkbox.length == 0) {
2021 target.showPassword_ddns(true);
2022 } else {
2023 target.showPassword_ddns(false);
2024 }
2025 }
2026 function changeDdnsProviderFunc() {
2027 if (data.DDNSProvider != target.currentProviderList()) {
2028 target.DDNSaccount("");
2029 target.DDNSpasswd("");
2030 target.DDNSname("");
2031 } else {
2032 target.DDNSaccount(data.DDNSAccount);
2033 target.DDNSpasswd(data.DDNSPassword);
2034 target.DDNSname(data.DDNS);
2035 }
2036 changeddnsProviderList();
2037 }
2038 function changeddnsProviderList() {
2039 if (target.currentProviderList() != "none") {
2040 target.isddnsaccount(true);
2041 target.isddnspasswd(true);
2042 target.isddnsdomainName(true);
2043 target.isHashValue(true);
2044 target.isDDNSStatus(true);
2045 } else {
2046 target.isddnsaccount(false);
2047 target.isddnspasswd(false);
2048 target.isddnsdomainName(false);
2049 target.isHashValue(false);
2050 target.isDDNSStatus(false);
2051 }
2052 if (target.currentProviderList() != "freedns.afraid.org") {
2053 target.isHashValue(false);
2054 } else {
2055 target.isHashValue(true);
2056 }
2057 return true;
2058 }
2059 function applyFunc() {
2060 showLoading();
2061 var params = {};
2062 params.goformId = "DDNS";
2063 params.DDNS_Enable = target.currentMode();
2064 if (target.currentMode() == "1") {
2065 params.DDNS_Mode = target.currentModeselect();
2066 params.DDNSProvider = target.currentProviderList();
2067 if (target.currentProviderList() != "none") {
2068 params.DDNS = target.DDNSname();
2069 params.DDNSPassword = target.DDNSpasswd();
2070 params.DDNSAccount = target.DDNSaccount();
2071 }
2072 if (target.currentProviderList() == "freedns.afraid.org") {
2073 params.DDNS_Hash_Value = target.DDNS_HashValue();
2074 }
2075 }
2076 service.setDDNSForward(params, function (result) {
2077 if (result.result == "success") {
2078 successOverlay();
2079 data = service.getDdnsParams();
2080 } else {
2081 errorOverlay();
2082 }
2083 });
2084 }
2085 }
2086 function initialize() {
2087 var container = $('#container');
2088 ko.cleanNode(container[0]);
2089 var vm = new DdnsViewModel();
2090 ko.applyBindings(vm, container[0]);
2091 $("#ddnsForm").validate({
2092 submitHandler: function () {
2093 vm.apply();
2094 },
2095 rules: {
2096 ddns_secretcode_input: "secretcode_check",
2097 DDNS_Hash_Value: "ddns_hashvalue_check",
2098 ddns_secretcode_inputshow: "secretcode_check"
2099 },
2100 errorPlacement: function (error, element) {
2101 var id = element.attr("id");
2102 if (id == "ddns_secretcode_input" || id == "ddns_secretcode_inputshow") {
2103 error.insertAfter("#lblShowPassword");
2104 } else {
2105 error.insertAfter(element);
2106 }
2107 }
2108 });
2109 }
2110 return {
2111 init: initialize
2112 };
2113});
2114
2115
2116//选网模块
2117
2118define("network_net_select","underscore jquery knockout set service".split(" "),
2119 function (_, $, ko, config, service) {
2120
2121 var selectModes = _.map(config.AUTO_MODES, function (item) {
2122 return new Option(item.name, item.value);
2123 });
2124
2125 //选网功能view model
2126
2127 function NetSelectVM() {
2128 var target = this;
2129
2130 target.networkList = ko.observableArray([]);
2131 target.selectNetwork = ko.observable('');
2132 target.enableFlag = ko.observable(true);
2133 target.types = ko.observableArray(selectModes);
2134 target.selectedType = ko.observable();
2135 target.selectMode = ko.observable();
2136
2137 target.networkText = networkTextFunc;
2138
2139 target.networkStatusId = networkStatusIdFunc;
2140
2141 target.networkStatus = networkStatusFunc;
2142
2143 target.subnetworkType = subnetworkTypeFunc;
2144
2145 target.networkType = networkTypeFunc;
2146
2147 target.operatorName = operatorNameFunc;
2148
2149 target.networkValue = networkValueFunc;
2150
2151 target.networkTypeId = networkTypeIdFunc;
2152
2153 target.subnetTypeId = subnetTypeIdFunc;
2154 //手动搜网.
2155
2156 target.search = searchFunc;
2157
2158 //自动选网时设置网络模式.
2159
2160 target.save = saveFunc;
2161
2162 target.checkEnable = checkEnableFunc;
2163
2164 //注册选择的网络.
2165
2166 target.register = registerFunc;
2167
2168 //init data
2169 target.checkEnable();
2170 var info = getNetSelectInfo();
2171 if ("manual_select" == info.net_select_mode || "manual_select" == info.m_netselect_save) {
2172 target.selectMode("manual_select");
2173 } else {
2174 target.selectMode("auto_select");
2175 }
2176
2177 target.selectedType(info.net_select);
2178
2179 //注册选择的网络.
2180 function registerFunc() {
2181 showLoading('registering_net');
2182 var networkToSet = target.selectNetwork().split(',');
2183 service.setNetwork(networkToSet[0], parseInt(networkToSet[1]), parseInt(networkToSet[2]), function (result) {
2184 if (result) {
2185 target.networkList([]);
2186 var autoType = getNetSelectInfo();
2187 target.selectedType(autoType.net_select);
2188 successOverlay();
2189 } else {
2190 errorOverlay();
2191 }
2192 });
2193 }
2194
2195 function checkEnableFunc() {
2196 var status = service.getStatusInfo();
2197 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
2198 target.enableFlag(false);
2199 } else {
2200 target.enableFlag(true);
2201 }
2202 }
2203
2204 //自动选网时设置网络模式.
2205 function saveFunc() {
2206 showLoading();
2207
2208 //AutoSelect call SetBearerPreference
2209 var params = {};
2210 params.strBearerPreference = target.selectedType();
2211 service.setBearerPreference(params, function (result) {
2212 if (result.result == "success") {
2213 target.networkList([]);
2214 successOverlay();
2215 } else {
2216 errorOverlay();
2217 }
2218 });
2219 }
2220
2221 //手动搜网.
2222 function searchFunc() {
2223 showLoading('searching_net');
2224 service.scanForNetwork(function (result, networkList) {
2225 hideLoading();
2226 if (result) {
2227 target.networkList(networkList);
2228 for (var i = 0; i < networkList.length; i++) {
2229 var n = networkList[i];
2230 if (n.nState == '2') {
2231 target.selectNetwork(n.strNumeric + ',' + n.nRat + ',' + n.SubAct);
2232 return;
2233 }
2234 }
2235 } else {
2236 errorOverlay();
2237 target.networkList([]);
2238 }
2239 });
2240 }
2241
2242 function subnetTypeIdFunc(data) {
2243 return getSubNetworkTypeTog(data.nRat, data.SubAct);
2244 }
2245
2246 function networkTypeIdFunc(data) {
2247 return getNetworkType(data.nRat);
2248 }
2249
2250 function networkValueFunc(data) {
2251 var result = [];
2252 result.push(data.strNumeric); //strNumeric
2253 result.push(data.nRat); //nRat
2254 result.push(data.SubAct);
2255 return result.join(',');
2256 }
2257
2258 function operatorNameFunc(data) {
2259 return data.strShortName;
2260 }
2261
2262 function networkTypeFunc(data) {
2263 var result = getNetworkType(data.nRat);
2264 if (result == "auto")
2265 result = $.i18n.prop("auto");
2266 return result;
2267 }
2268
2269 function subnetworkTypeFunc(data) {
2270 var result = getSubNetworkTypeTog(data.nRat, data.SubAct);
2271 return result;
2272 }
2273
2274 function networkStatusFunc(data) {
2275 return $.i18n.prop(getNetworkStatusTog(data.nState));
2276 }
2277
2278 function networkStatusIdFunc(data) {
2279 return getNetworkStatusTog(data.nState);
2280 }
2281
2282 function networkTextFunc(data) {
2283 return data.strNumeric;
2284 }
2285
2286 }
2287
2288 //获取网络选择信息.
2289
2290 function getNetSelectInfo() {
2291 return service.getNetSelectInfo();
2292 }
2293
2294 //搜网结果中的状态转换为对应的语言项.
2295
2296 function getNetworkStatusTog(status) {
2297 if ("3" == status) {
2298 return "forbidden";
2299 } else if ("2" == status) {
2300 return "current";
2301 } else if ("1" == status) {
2302 return "available";
2303 }else if ("0" == status) {
2304 return "unknown";
2305 }
2306 }
2307 //子网络类型转换.
2308
2309 function getSubNetworkTypeTog(type, subtype) {
2310 var type_3g = [2, 4, 5, 6, 8];
2311 if ("1" == subtype) {
2312 if ("7" == type) {
2313 subtype = "FDD-LTE";
2314 } else if ($.inArray(type, type_3g) != -1) {
2315 subtype = "WCDMA";
2316 }else {
2317 subtype = "GSM";
2318 }
2319 } else if ("0" == subtype) {
2320 if ("7" == type) {
2321 subtype = "TD-LTE";
2322 } else if ($.inArray(type, type_3g) != -1) {
2323 subtype = "TD-SCDMA";
2324 } else {
2325 subtype = "GSM";
2326 }
2327 } else {
2328 subtype = "";
2329 }
2330 return subtype;
2331 }
2332 //网络类型转换.
2333
2334 function getNetworkType(type) {
2335 if ("7" == type) {
2336 return "4G";
2337 } else if ("2" == type) {
2338 return "3G";
2339 } else if ("0" == type) {
2340 return "2G";
2341 } else {
2342 return "auto";
2343 }
2344 }
2345
2346 function bindContainer(vm){
2347
2348 var container = $('#container');
2349 ko.cleanNode(container[0]);
2350 ko.applyBindings(vm, container[0]);
2351 }
2352
2353 //初始化选网功能view model.
2354
2355 function initialize() {
2356 var vm = new NetSelectVM();
2357 bindContainer(vm);
2358 addInterval(vm.checkEnable, 1000);
2359 }
2360
2361 return {
2362 init: initialize
2363 };
2364});
2365define("locknet","jquery knockout service jquery set main".split(" "),
2366 function ($, ko, service, config, home) {
2367
2368 function initialize() {
2369 var container = $('#container')[0];
2370 ko.cleanNode(container);
2371 var vm = new locknetViewMode();
2372 ko.applyBindings(vm, container);
2373
2374 $("#frmNetworkLock").validate({
2375 submitHandler: function () {
2376 vm.unlock();
2377 },
2378 rules: {
2379 txtLockNumber: "unlock_code_check"
2380 }
2381 });
2382 }
2383
2384 function locknetViewMode() {
2385 var target = this;
2386 var curCableMode = false;
2387 target.isCPE = config.PRODUCT_TYPE == 'CPE';
2388 target.hasRj45 = config.RJ45_SUPPORT;
2389 target.hasSms = config.HAS_SMS;
2390 target.hasPhonebook = config.HAS_PHONEBOOK;
2391 target.isSupportSD = config.SD_CARD_SUPPORT;
2392 target.hasUssd = config.HAS_USSD;
2393 if (config.WIFI_SUPPORT_QR_SWITCH == false) {
2394 target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
2395 } else {
2396 var wifiInfo = service.getWifiBasic();
2397 target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
2398 }
2399 if(config.WIFI_SUPPORT_QR_CODE){
2400 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2401 } else {
2402 target.qrcodeSrc = './pic/res_blacktrans.png';
2403 }
2404 target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
2405 target.deviceInfo = ko.observable([]);
2406 target.isHomePage = ko.observable(false);
2407 if (window.location.hash == "#main") {
2408 target.isHomePage(true);
2409 }
2410
2411 target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
2412 target.unlockCode = ko.observable();
2413
2414 var info = service.getNetworkUnlockTimes();
2415 target.times = ko.observable(info.unlock_nck_time);
2416
2417 //显示工作模式设置窗口
2418 target.showOpModeWindow = showOpModeWindowFunc;
2419
2420 target.isLoggedIn = ko.observable(false);
2421 target.enableFlag = ko.observable(false);
2422 //解锁
2423 target.unlock = unlockFunc;
2424
2425 //更新工作模式状态
2426 target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
2427
2428 //定时检查工作模式状态
2429 if (target.hasRj45) {
2430 target.refreshOpmodeInfo();
2431 addInterval(function () {
2432 target.refreshOpmodeInfo();
2433 }, 1000);
2434 }
2435
2436 //更新工作模式状态
2437 function refreshOpmodeInfoFunc() {
2438 var obj = service.getStatusInfo();
2439 target.isLoggedIn(obj.isLoggedIn);
2440
2441 if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
2442 window.location.reload();
2443 return;
2444 }
2445
2446 curCableMode = checkCableMode(obj.blc_wan_mode);
2447 target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
2448 if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
2449 target.enableFlag(true);
2450 } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
2451 target.enableFlag(false);
2452 } else {
2453 target.enableFlag(true);
2454 }
2455 var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
2456 var currMode = "";
2457 switch (getMode) {
2458 case "PPP":
2459 currMode = "opmode_gateway";
2460 break;
2461 case "PPPOE":
2462 currMode = "opmode_cable";
2463 break;
2464 case "AUTO":
2465 currMode = "opmode_auto";
2466 break;
2467 default:
2468 break;
2469 }
2470 $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
2471 }
2472
2473 //解锁
2474 function unlockFunc() {
2475 showLoading();
2476 service.unlockNetwork({
2477 unlock_network_code: target.unlockCode()
2478 }, function (data) {
2479 target.unlockCode("");
2480 if (data && data.result == "success") {
2481 successOverlay();
2482 if (window.location.hash == "#main") {
2483 setTimeout(function () {
2484 window.location.reload();
2485 }, 500);
2486 } else {
2487 window.location.hash = "#main";
2488 }
2489 } else {
2490 var info = service.getNetworkUnlockTimes();
2491 target.times(info.unlock_nck_time);
2492 errorOverlay();
2493 }
2494 })
2495 }
2496
2497 //显示工作模式设置窗口
2498 function showOpModeWindowFunc() {
2499 showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
2500 }
2501 }
2502
2503 return {
2504 init: initialize
2505 };
2506});
2507
2508// RJ45联网设置模块
2509
2510define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
2511function(_, $, ko, config, service) {
2512 var dialActions = _.map(config.dialActions, function(elem){
2513 return new Option(elem.name, elem.value);
2514 });
2515
2516 var dialModes = _.map(config.pppoeModes, function(elem) {
2517 return new Option(elem.name, elem.value);
2518 });
2519
2520 var checkStatusTimer = 0;
2521 var checkConCounter = 0;
2522 var timeoutTipShowed = false;
2523
2524 // 联网设置view model.
2525
2526 function PPPoEViewModel() {
2527 var pppObj = service.getPppoeParams();
2528 var ethParams = pppObj;
2529 var target = this;
2530
2531 target.staticNoticeShow = ko.observable();
2532 target.dhcpNoticeShow = ko.observable();
2533 target.pppoeNoticeShow = ko.observable();
2534 target.autoNoticeShow = ko.observable();
2535 target.staticNotice = ko.observable();
2536 target.dhcpNotice = ko.observable();
2537 target.pppoeNotice = ko.observable();
2538 target.autoNotice = ko.observable();
2539 target.dhcpNoticeText = ko.observable();
2540 target.staticNoticeText = ko.observable();
2541 target.pppoeNoticeText = ko.observable();
2542 target.autoNoticeText = ko.observable();
2543 target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
2544 target.showPassword = ko.observable(false);
2545 target.modes = ko.observableArray(dialModes);
2546 target.isPppoeMode = ko.observable(false);
2547 target.isStaticMode = ko.observable(false);
2548 target.isAutoMode = ko.observable(false);
2549 target.action = ko.observable();
2550 target.btnTrans = ko.observable();
2551 target.enableFlag = ko.observable();
2552 target.isShowDisbtn = ko.observable();
2553 target.isShowCancelbtn = ko.observable();
2554
2555 if(pppObj.rj45_state == "dead"){
2556 checkRj45DeadTip();
2557 } else if(pppObj.rj45_state == "connect"){
2558 timeoutTipShowed = true;
2559 setRj45CheckTimer("connect");
2560 } else if(pppObj.rj45_state == "working"){
2561 setRj45WorkingTip();
2562 }
2563
2564 target.user = ko.observable(pppObj.pppoe_username);
2565 target.password = ko.observable(pppObj.pppoe_cc);
2566 target.autoUser = ko.observable(pppObj.pppoe_username);
2567 target.autoPassword = ko.observable(pppObj.pppoe_cc);
2568 target.pppMode = ko.observable(pppObj.ethwan_dialmode);
2569 initContronler();
2570
2571
2572 //下拉框选择改变下面DIV模块
2573 target.changeModeDiv = changeModeDivFunc;
2574
2575 target.radioHandler = radioHandlerFunc;
2576
2577 target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
2578 target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
2579 target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
2580 target.subnetMask = ko.observable(pppObj.static_wan_netmask);
2581 target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
2582
2583 addInterval(function(){
2584 ethParams = service.getPppoeParams();
2585 pppObj.rj45_state = ethParams.rj45_state;
2586 initContronler();
2587 }, 1000);
2588
2589 // 取消连接按钮事件.
2590
2591 target.cancelConnect = cancelConnectFunc;
2592
2593 // 应用按钮事件.
2594
2595 target.save = saveFunc;
2596
2597 //密码显示事件
2598 target.showPasswordHandler = function () {
2599 var checkbox = $("#showPassword:checked");
2600 if (checkbox && checkbox.length == 0) {
2601 target.showPassword(true);
2602 } else {
2603 target.showPassword(false);
2604 }
2605 };
2606
2607 // 更新当前界面状态、按钮、提示语等.
2608
2609 function initContronler() {
2610 checkRj45DeadTip();
2611 if(target.currentMode() == "PPPOE"){
2612 target.isPppoeMode(true);
2613 target.isStaticMode(false);
2614 target.isAutoMode(false);
2615 target.staticNoticeShow(false);
2616 target.dhcpNoticeShow(false);
2617 target.autoNoticeShow(false);
2618 } else if(target.currentMode() == "AUTO"){
2619 target.isStaticMode(false);
2620 target.isPppoeMode(false);
2621 target.isAutoMode(true);
2622 target.dhcpNoticeShow(false);
2623 target.pppoeNoticeShow(false);
2624 target.staticNoticeShow(false);
2625 } else if(target.currentMode() == "STATIC"){
2626 target.isStaticMode(true);
2627 target.isPppoeMode(false);
2628 target.isAutoMode(false);
2629 target.dhcpNoticeShow(false);
2630 target.pppoeNoticeShow(false);
2631 target.autoNoticeShow(false);
2632 } else{
2633 target.isStaticMode(false);
2634 target.isPppoeMode(false);
2635 target.isAutoMode(false);
2636 target.staticNoticeShow(false);
2637 target.pppoeNoticeShow(false);
2638 target.autoNoticeShow(false);
2639 }
2640 if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
2641 target.enableFlag(false);
2642 } else {
2643 target.enableFlag(true);
2644 }
2645 if(pppObj.rj45_state == "connect"){
2646 if(target.pppMode() == "auto_dial"){
2647 target.action("connect");
2648 }else{
2649 target.action("disconnect");
2650 }
2651 } else if(pppObj.rj45_state == "working"){
2652 target.action("disconnect");
2653 }else{
2654 target.action("connect");
2655 }
2656 //应用/连接按钮
2657 if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
2658 target.btnTrans("connect");
2659 } else{
2660 target.btnTrans("apply");
2661 }
2662 if(pppObj.rj45_state != "idle"){
2663 $("#pppoeApply").attr("disabled", true);
2664 }else {
2665 $("#pppoeApply").attr("disabled", false);
2666 }
2667
2668 //取消/断开按钮
2669 target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
2670 target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
2671
2672 $("#pppoeApply").translate();
2673 }
2674 // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
2675
2676 function setRj45CheckTimer(action){
2677 checkStatusTimer && window.clearInterval(checkStatusTimer);
2678 if("connect" != action){
2679 checkStatusTimer = addInterval(function () {
2680 checkDisconnectStatus();
2681 }, 2000);
2682 }else{
2683 if(target.currentMode() == "PPPOE"){
2684 target.pppoeNoticeShow(true);
2685 target.pppoeNotice("pppoe_processing");
2686 target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
2687 } else if(target.currentMode() == "STATIC"){
2688 target.staticNoticeShow(true);
2689 target.staticNotice("static_processing");
2690 target.staticNoticeText($.i18n.prop("static_processing"));
2691 } else if(target.currentMode() == "DHCP"){
2692 target.dhcpNoticeShow(true);
2693 target.dhcpNotice("dyn_processing");
2694 target.dhcpNoticeText($.i18n.prop("dyn_processing"));
2695 }else{
2696 target.autoNoticeShow(true);
2697 target.autoNotice("auto_processing");
2698 target.autoNoticeText($.i18n.prop("auto_processing"));
2699 }
2700 checkStatusTimer = addInterval(function () {
2701 checkConnectionStatus();
2702 }, 2000);
2703 }
2704 }
2705 // 设置后通过定时检查rj45_state状态,判断连接操作结果.
2706
2707 function checkConnectionStatus(){
2708 if(checkConCounter < 1){
2709 checkConCounter++;
2710 return;
2711 }
2712 if(pppObj.rj45_state == "connect"){
2713 if(target.currentMode() != ethParams.ethwan_mode){
2714 if(target.currentMode() == "AUTO"){
2715 target.autoNoticeShow(true);
2716 }else if(target.currentMode() == "PPPOE"){
2717 target.pppoeNoticeShow(true);
2718 }else if(target.currentMode() == "STATIC"){
2719 target.staticNoticeShow(true);
2720 }else if(target.currentMode() == "DHCP"){
2721 target.dhcpNoticeShow(true);
2722 }
2723 }
2724 if(checkConCounter > 6){
2725 if(timeoutTipShowed == false){
2726 timeoutTipShowed = true;
2727 showAlert("ussd_operation_timeout");
2728 }
2729 }
2730 checkConCounter++;
2731 } else if (pppObj.rj45_state == "working") {
2732 hideLoading();
2733 setRj45WorkingTip();
2734 window.clearInterval(checkStatusTimer);
2735 } else if (pppObj.rj45_state == "dead") {
2736 hideLoading();
2737 checkRj45DeadTip();
2738 window.clearInterval(checkStatusTimer);
2739 } else if(pppObj.rj45_state == "idle"){
2740 hideLoading();
2741 if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
2742 timeoutTipShowed == false && target.dhcpNoticeShow(true);
2743 target.dhcpNotice("dyn_fail");
2744 target.dhcpNoticeText($.i18n.prop("dyn_fail"));
2745 }
2746 if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
2747 timeoutTipShowed == false && target.staticNoticeShow(true);
2748 target.staticNotice("static_fail");
2749 target.staticNoticeText($.i18n.prop("static_fail"));
2750 }
2751 if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
2752 timeoutTipShowed == false && target.pppoeNoticeShow(true);
2753 target.pppoeNotice("pppoe_fail");
2754 target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
2755 }
2756 if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
2757 timeoutTipShowed == false && target.autoNoticeShow(true);
2758 target.autoNotice("auto_fail");
2759 target.autoNoticeText($.i18n.prop("auto_fail"));
2760 }
2761 window.clearInterval(checkStatusTimer);
2762 } else{
2763 hideLoading();
2764 window.clearInterval(checkStatusTimer);
2765 }
2766 }
2767 // 设置连接成功时提示语状态.
2768
2769 function setRj45WorkingTip(){
2770 if(target.currentMode() == ethParams.ethwan_mode){
2771 if(target.currentMode() == "AUTO") {
2772 target.autoNoticeShow(true);
2773 target.autoNotice("auto_success");
2774 target.autoNoticeText($.i18n.prop("auto_success"));
2775 }else if(target.currentMode() == "PPPOE") {
2776 target.pppoeNoticeShow(true);
2777 target.pppoeNotice("pppoe_success");
2778 target.pppoeNoticeText($.i18n.prop("pppoe_success"));
2779 }else if(target.currentMode() == "STATIC") {
2780 target.staticNoticeShow(true);
2781 target.staticNotice("static_success");
2782 target.staticNoticeText($.i18n.prop("static_success"));
2783 }else if(target.currentMode() == "DHCP" ) {
2784 target.dhcpNoticeShow(true);
2785 target.dhcpNotice("dyn_success");
2786 target.dhcpNoticeText($.i18n.prop("dyn_success"));
2787 }
2788 }
2789 }
2790
2791 // 设置网线断开提示语状态.
2792
2793 function checkRj45DeadTip(){
2794 if(pppObj.rj45_state != "dead"){
2795 if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
2796 target.autoNoticeShow(false);
2797 }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
2798 target.pppoeNoticeShow(false);
2799 }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
2800 target.staticNoticeShow(false);
2801 }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
2802 target.dhcpNoticeShow(false);
2803 }
2804
2805 } else{
2806 target.dhcpNotice("pppoe_msg");
2807 target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
2808 target.staticNotice("pppoe_msg");
2809 target.staticNoticeText($.i18n.prop("pppoe_msg"));
2810 target.pppoeNotice("pppoe_msg");
2811 target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
2812 target.autoNotice("pppoe_msg");
2813 target.autoNoticeText($.i18n.prop("pppoe_msg"));
2814 if(target.currentMode() == "AUTO") {
2815 target.autoNoticeShow(true);
2816 }else if(target.currentMode() == "PPPOE") {
2817 target.pppoeNoticeShow(true);
2818 }else if(target.currentMode() == "STATIC") {
2819 target.staticNoticeShow(true);
2820 }else if(target.currentMode() == "DHCP") {
2821 target.dhcpNoticeShow(true);
2822 }
2823 }
2824 }
2825 // 设置后通过定时检查rj45_state状态,判断断开操作结果.
2826
2827 function checkDisconnectStatus(){
2828 if(checkConCounter < 1){
2829 checkConCounter++;
2830 } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
2831 target.dhcpNoticeShow(false);
2832 target.staticNoticeShow(false);
2833 target.pppoeNoticeShow(false);
2834 target.autoNoticeShow(false);
2835 window.clearInterval(checkStatusTimer);
2836 successOverlay();
2837 } else if(checkConCounter > 6){
2838 if(timeoutTipShowed == false){
2839 timeoutTipShowed = true;
2840 showAlert("ussd_operation_timeout");
2841 }
2842 window.clearInterval(checkStatusTimer);
2843 } else if(checkConCounter < 7) {
2844 checkConCounter++;
2845 } else {
2846 hideLoading();
2847 window.clearInterval(checkStatusTimer);
2848 }
2849 }
2850
2851 //应用按钮事件.
2852 function saveFunc(){
2853 target.dhcpNoticeShow(false);
2854 target.staticNoticeShow(false);
2855 target.pppoeNoticeShow(false);
2856 target.autoNoticeShow(false);
2857 if(pppObj.rj45_state == "dead"){
2858 showAlert("pppoe_msg");
2859 return;
2860 }
2861 var requestParams = {};
2862 if($("#pppoe_mode").val() == "PPPOE") {
2863 requestParams = $.extend({}, {
2864 goformId: "WAN_GATEWAYMODE_PPPOE",
2865 pppoe_username: target.user(),
2866 pppoe_cc: target.password()
2867 });
2868 } else if($("#pppoe_mode").val() == "AUTO") {
2869 requestParams = $.extend({}, {
2870 goformId: "WAN_GATEWAYMODE_AUTO",
2871 pppoe_username: target.autoUser(),
2872 pppoe_cc: target.autoPassword()
2873 });
2874 } else if($("#pppoe_mode").val() == "STATIC") {
2875 if(target.ipAddress() == target.defaultGateway()){
2876 showAlert("ip_gate_not_same");
2877 return;
2878 }
2879 if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
2880 showAlert("ip_innergate_not_same");
2881 return;
2882 }
2883 requestParams = $.extend({}, {
2884 goformId: "WAN_GATEWAYMODE_STATIC",
2885 static_wan_ipaddr: target.ipAddress(),
2886 static_wan_netmask: target.subnetMask(),
2887 static_wan_gateway: target.defaultGateway(),
2888 static_wan_primary_dns: target.primaryDNS(),
2889 static_wan_secondary_dns: target.secondaryDNS(),
2890 WAN_MODE: "STATIC"
2891 });
2892 } else {
2893 requestParams = $.extend({}, {
2894 goformId: "WAN_GATEWAYMODE_DHCP"
2895 });
2896 }
2897 requestParams.action_link = "connect";
2898 requestParams.dial_mode = target.pppMode();
2899 showLoading("waiting");
2900
2901 service.setPppoeDialMode(requestParams, function(data){
2902 if(data.result){
2903 target.currentMode($("#pppoe_mode").val());
2904 pppObj = service.getPppoeParams();
2905 checkConCounter = 0;
2906 timeoutTipShowed = false;
2907 setRj45CheckTimer("connect");
2908 $("#pppoeApply").translate();
2909 } else {
2910 errorOverlay("pppoe_message_send_fail");
2911 }
2912 });
2913
2914 }
2915
2916 //取消连接按钮事件.
2917 function cancelConnectFunc(){
2918 target.dhcpNoticeShow(false);
2919 target.staticNoticeShow(false);
2920 target.pppoeNoticeShow(false);
2921 target.autoNoticeShow(false);
2922 if(pppObj.rj45_state == "dead"){
2923 showAlert("pppoe_msg");
2924 return;
2925 }
2926 var requestParams = {
2927 dial_mode: target.pppMode(),
2928 action_link: "disconnect"
2929 };
2930 if(pppObj.ethwan_mode == "PPPOE") {
2931 requestParams = $.extend(requestParams, {
2932 goformId: "WAN_GATEWAYMODE_PPPOE",
2933 pppoe_username: pppObj.pppoe_username,
2934 pppoe_cc: pppObj.pppoe_cc
2935 });
2936 }else if(pppObj.ethwan_mode == "AUTO") {
2937 requestParams = $.extend(requestParams, {
2938 goformId: "WAN_GATEWAYMODE_AUTO",
2939 pppoe_username: pppObj.pppoe_username,
2940 pppoe_cc: pppObj.pppoe_cc
2941 });
2942 }else if(pppObj.ethwan_mode == "STATIC") {
2943 requestParams = $.extend(requestParams, {
2944 goformId: "WAN_GATEWAYMODE_STATIC",
2945 static_wan_ipaddr: pppObj.static_wan_ipaddr,
2946 static_wan_netmask: pppObj.static_wan_netmask,
2947 static_wan_gateway: pppObj.static_wan_gateway,
2948 static_wan_primary_dns: pppObj.static_wan_primary_dns,
2949 static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
2950 WAN_MODE: "STATIC"
2951 });
2952 }else {
2953 requestParams = $.extend(requestParams, {
2954 goformId: "WAN_GATEWAYMODE_DHCP"
2955 });
2956 }
2957 showLoading("waiting");
2958 service.setPppoeDialMode(requestParams, function(data){
2959 if(data.result){
2960 checkConCounter = 0;
2961 timeoutTipShowed = false;
2962 setRj45CheckTimer("disconnect");
2963 $("#pppoeApply").translate();
2964 } else {
2965 errorOverlay("pppoe_message_send_fail");
2966 }
2967 });
2968
2969 }
2970
2971 function radioHandlerFunc(){
2972 initContronler();
2973 return true;
2974 }
2975
2976 function changeModeDivFunc(){
2977 initContronler();
2978 }
2979
2980 }
2981
2982 function bindContainer(vm){
2983 var container = $('#container');
2984 ko.cleanNode(container[0]);
2985 ko.applyBindings(vm, container[0]);
2986
2987 }
2988 // 联网设置初始化.
2989
2990 function initialize() {
2991 var vm = new PPPoEViewModel();
2992 bindContainer(vm);
2993
2994 $("#pppoeApply").translate();
2995
2996 $('#pppoeForm').validate({
2997 submitHandler : function() {
2998 vm.save();
2999 },
3000 rules: {
3001 txtPin: "wps_pin_check",
3002 txtIpAddress: "dmz_ip_check",
3003 txtSubnetMask: {
3004 ipv4: true,
3005 subnetmask_check: true
3006 },
3007 txtDefaultGateway: {
3008 ipv4: true,
3009 gateway_check: true
3010 },
3011 txtPrimaryDNS: {
3012 ipv4: true,
3013 dns_check:true
3014 },
3015 txtSecondaryDNS: {
3016 ipv4: true,
3017 dns_check:true
3018 }
3019 }
3020 });
3021 }
3022
3023
3024//from 4.0
3025 // 有效DNS检查.
3026
3027function validateDns(dns){
3028 if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
3029 return false;
3030 }
3031 return true;
3032}
3033 // 联网设置初始化.
3034
3035function isStaticIPValid(ip, lanip, lanmask){
3036 if(!ip || !lanip || !lanmask){//各参数不能为空
3037 return false;
3038 }
3039 if(ip == lanip){// 与内网IP相等
3040 return true;
3041 }
3042 var res1 = [], res2 = [], mask = [];
3043 addr1 = ip.split(".");
3044 addr2 = lanip.split(".");
3045 mask = lanmask.split(".");
3046 for(var i = 0; i < addr1.length; i += 1){
3047 res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
3048 res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
3049 }
3050 if(res1.join(".") == res2.join(".")){//在同一个网段
3051 return true;
3052 }else{//不在同一个网段
3053 return false;
3054 }
3055}
3056
3057// 有效子网掩码验证.
3058
3059function isNetmaskIPValid(ip) {
3060 if (ip == 255 || ip == 254 || ip == 252 || ip == 248
3061 || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
3062 {
3063 return true;
3064 }
3065 else
3066 {
3067 return false;
3068 }
3069}
3070 // 有效子网掩码检查.
3071
3072function validateNetmask(netmask) {
3073 var array = new Array();
3074 array = netmask.split(".");
3075
3076 if (array.length != 4) {
3077 return false;
3078 }
3079
3080 array[0] = parseInt(array[0]);
3081 array[1] = parseInt(array[1]);
3082 array[2] = parseInt(array[2]);
3083 array[3] = parseInt(array[3]);
3084
3085 if (array[3] != 0) {
3086 if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
3087 return false;
3088 } else {
3089 if (!isNetmaskIPValid(array[3])) {
3090 return false;
3091 }
3092 }
3093 }
3094
3095 if (array[2] != 0) {
3096 if (array[1] != 255 || array[0] != 255) {
3097 return false;
3098 } else {
3099 if (!isNetmaskIPValid(array[2])) {
3100 return false;
3101 }
3102 }
3103 }
3104
3105 if (array[1] != 0) {
3106 if (array[0] != 255) {
3107 return false;
3108 } else{
3109 if (!isNetmaskIPValid(array[1])) {
3110 return false;
3111 }
3112 }
3113 }
3114 if(array[0]!=255) {
3115 return false;
3116 }
3117 if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
3118 return false;
3119 }
3120 return true;
3121}
3122
3123 // subnetmask_check校验规则
3124
3125jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
3126 var result = validateNetmask(value);
3127 return this.optional(element) || result;
3128});
3129 // dns_check校验规则
3130
3131jQuery.validator.addMethod("dns_check", function (value, element, param) {
3132 var result = validateDns(value);
3133 return this.optional(element) || result;
3134});
3135 // 有效网关检查.
3136
3137function validateGateway(wanIp, netmaskIp, gatewayIp) {
3138 if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
3139 return true;
3140 } else {
3141 return false;
3142 }
3143}
3144 // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
3145
3146function myConcat(ip1,ip2){
3147 var result = [];
3148 var iplArr = ip1.split(".");
3149 var ip2Arr = ip2.split(".");
3150 for(var i = 0; i < iplArr.length;i++){
3151 result[i] = (iplArr[i] & ip2Arr[i]);
3152 }
3153 return result.join(".");
3154}
3155 // gateway_check校验规则
3156
3157jQuery.validator.addMethod("gateway_check", function (value, element, param) {
3158 var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
3159 return this.optional(element) || result;
3160});
3161
3162 return {
3163 init: initialize
3164 };
3165});
3166//联网设置模块
3167define("network_dial_set","underscore jquery knockout set service".split(" "),
3168function(_, $, ko, config, service) {
3169
3170 //联网设置view model
3171 function DialVM() {
3172 var dialMode = service.getConnectionMode();
3173 var target = this;
3174
3175 target.selectMode = ko.observable(dialMode.connectionMode);
3176 target.enableFlag = ko.observable(true);
3177 target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
3178 var originalRoaming = dialMode.isAllowedRoaming;
3179
3180 target.setAllowedRoaming = setAllowedRoamingFunc;
3181
3182 var checkboxFlag = $(".checkboxToggle");
3183 target.checkEnable = checkEnableFunc;
3184
3185 //修改联网模式
3186 target.save = saveFunc;
3187
3188 function saveFunc() {
3189 showLoading();
3190 var connMode = target.selectMode();
3191 //当选择自动时,下发原先的勾选状态
3192 if (connMode == 'auto_dial') {
3193 originalRoaming = target.isAllowedRoaming();
3194 } else {
3195 target.isAllowedRoaming(originalRoaming);
3196 }
3197 service.setConnectionMode({
3198 connectionMode: connMode,
3199 isAllowedRoaming: target.isAllowedRoaming()
3200 }, function (result) {
3201 if (result.result == "success") {
3202 successOverlay();
3203 } else {
3204 errorOverlay();
3205 }
3206 });
3207 }
3208
3209 function setAllowedRoamingFunc() {
3210 if(!$("#roamBtn").hasClass("disable")){
3211 var checkbox = $("#isAllowedRoaming:checked");
3212 if(checkbox && checkbox.length == 0 ){
3213 target.isAllowedRoaming("on");
3214 }else{
3215 target.isAllowedRoaming("off");
3216 }
3217 }
3218 }
3219
3220 function checkEnableFunc() {
3221 var status = service.getStatusInfo();
3222
3223 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
3224 target.enableFlag(false);
3225 disableCheckbox(checkboxFlag);
3226 }
3227 else {
3228 target.enableFlag(true);
3229 enableCheckbox(checkboxFlag);
3230 }
3231 }
3232
3233 }
3234
3235 //联网设置初始化.
3236 function initialize() {
3237 var vm = new DialVM();
3238 bindContainer(vm);
3239
3240 vm.checkEnable();
3241 addInterval( vm.checkEnable, 1000);
3242 }
3243
3244 function bindContainer(vm){
3245 var container = $('#container');
3246 ko.cleanNode(container[0]);
3247 ko.applyBindings(vm, container[0]);
3248
3249 }
3250
3251 return {
3252 init: initialize
3253 };
3254});
3255// APN Setting 模块
3256define("network_apn_set","underscore jquery knockout set service".split(" "),
3257 function (_, $, ko, config, service) {
3258
3259 //获取鉴权方式
3260
3261 function getAuthModes() {
3262 return _.map(config.APN_AUTH_MODES, function (item) {
3263 return new Option(item.name, item.value);
3264 });
3265 }
3266
3267 function getApnPdpTypes() {
3268 var pdpTypesArray = [new Option('IPv4', 'IP')];
3269 if (config.IPV6_SUPPORT) {
3270 pdpTypesArray.push(new Option('IPv6', 'IPv6'));
3271 if (config.IPV4V6_SUPPORT) {
3272 pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
3273 }
3274 if (config.IPV4_AND_V6_SUPPORT) {
3275 pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
3276 }
3277 }
3278 return pdpTypesArray;
3279 }
3280
3281 //获取apn相关信息
3282
3283 function getApnSet() {
3284 var apnInfo = service.getApnSettings();
3285 apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
3286 apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
3287 apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
3288 return apnInfo;
3289 }
3290 var apnConfigs = {};
3291 var ipv6ApnConfigs = {};
3292 var autoApnConfigs = {};
3293
3294 //解析自动apn信息
3295
3296 function getAutoApnsConfig(autoApnV4, autoApnV6) {
3297 var autoApnsV4 = [];
3298 var autoApnsV6 = [];
3299
3300 if (autoApnV4 && autoApnV4.length > 5) {
3301 var apnArr = autoApnV4.split("||");
3302 for (var ki = 0; ki < apnArr.length; ki++) {
3303 if (apnArr[ki] != "") {
3304 var apnItem = parseApnItem(apnArr[ki], false);
3305 autoApnsV4.push(apnItem);
3306 }
3307 }
3308 }
3309 if (autoApnV6 && autoApnV6.length > 5) {
3310 var apnArr = autoApnV6.split("||");
3311 for (var ki = 0; ki < apnArr.length; ki++) {
3312 if (apnArr[ki] != "") {
3313 var apnItem = parseApnItem(apnArr[ki], false);
3314 autoApnsV6.push(apnItem);
3315 }
3316 }
3317 }
3318 return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
3319 }
3320 //解析apn信息
3321
3322 function getApnConfigs(apnsStr, isIpv6) {
3323 var apnCfgs = [];
3324 var theApnConfigs = {};
3325 if (apnsStr && apnsStr.length > 10) {
3326 var apnArr = apnsStr.split("||");
3327 for (var ki = 0; ki < apnArr.length; ki++) {
3328 if (apnArr[ki] != "") {
3329 var apnItem = parseApnItem(apnArr[ki], isIpv6);
3330 apnCfgs.push(apnItem);
3331 theApnConfigs[apnItem.profileName] = apnItem;
3332 }
3333 }
3334 }
3335 if (isIpv6 == false) {
3336 apnConfigs = theApnConfigs;
3337 } else {
3338 ipv6ApnConfigs = theApnConfigs;
3339 }
3340 return apnCfgs;
3341 }
3342
3343 //解析单条apn信息
3344
3345 function parseApnItem(apnStr, isIpv6) {
3346 var apnItem = {};
3347 var items = apnStr.split("($)");
3348 for (var ki = 0; ki < items.length; ki++) {
3349 apnItem.profileName = items[0];
3350 apnItem.pdpType = items[7];
3351 if (isIpv6 == false) {
3352 apnItem.dnsMode = items[10];
3353 apnItem.dns1 = items[11];
3354 apnItem.dns2 = items[12];
3355 apnItem.wanApn = items[1];
3356 apnItem.authMode = items[4].toLowerCase();
3357 apnItem.username = items[5];
3358 apnItem.password = items[6];
3359 } else {
3360 apnItem.dnsModeV6 = items[10];
3361 apnItem.dns1V6 = items[11];
3362 apnItem.dns2V6 = items[12];
3363 apnItem.wanApnV6 = items[1];
3364 apnItem.authModeV6 = items[4].toLowerCase();
3365 apnItem.usernameV6 = items[5];
3366 apnItem.passwordV6 = items[6];
3367 }
3368 }
3369 return apnItem;
3370 }
3371 //合并V4\V6自动apn信息
3372
3373 function dealAutoApnsV4V6(v4, v6) {
3374 autoApnConfigs = {};
3375 var autoApns = [];
3376 for (var ki = 0; ki < v4.length; ki++) {
3377 var apnElem = v4[ki];
3378 var itemsV6 = v6[ki];
3379 if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
3380 apnElem.usernameV6 = itemsV6.username;
3381 apnElem.passwordV6 = itemsV6.password;
3382 apnElem.dns1V6 = itemsV6.dns1;
3383 apnElem.dns2V6 = itemsV6.dns2;
3384 apnElem.wanApnV6 = itemsV6.wanApn;
3385 apnElem.authModeV6 = itemsV6.authMode;
3386 apnElem.dnsModeV6 = itemsV6.dnsMode;
3387 }
3388 autoApns.push(apnElem);
3389 autoApnConfigs[apnElem.profileName] = apnElem;
3390 }
3391 return autoApns;
3392 }
3393
3394 function getProfileOptions(apns) {
3395 return _.map(apns, function (item) {
3396 return new Option(item.profileName, item.profileName);
3397 });
3398 }
3399
3400 //APNViewModel
3401
3402 function APNViewModel() {
3403 var target = this;
3404 var apnSettings = getApnSet();
3405 if (apnSettings.apnNumPreset) {
3406 config.maxApnNumber = apnSettings.apnNumPreset;
3407 }
3408
3409 target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
3410 target.apnMode = ko.observable(apnSettings.apnMode);
3411 target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
3412 target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
3413 target.wanDial = ko.observable(apnSettings.wanDial);
3414
3415 target.showApnDns = ko.observable(config.SHOW_APN_DNS);
3416 target.index = ko.observable(apnSettings.currIndex);
3417 target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
3418 target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
3419
3420 target.apn = ko.observable(apnSettings.wanApn);
3421 target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
3422 target.dns1 = ko.observable(apnSettings.dns1);
3423 target.dns2 = ko.observable(apnSettings.dns2);
3424 target.authModes = ko.observableArray(getAuthModes());
3425 target.username = ko.observable(apnSettings.username);
3426 target.password = ko.observable(apnSettings.password);
3427
3428 target.pdpTypes = ko.observableArray(getApnPdpTypes());
3429 target.selectedPdpType = ko.observable(apnSettings.pdpType);
3430 target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
3431 target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
3432 target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
3433
3434 target.showPassword = ko.observable(false);
3435
3436 target.apnV6 = ko.observable(apnSettings.wanApnV6);
3437 target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
3438 target.dns1V6 = ko.observable(apnSettings.dns1V6);
3439 target.dns2V6 = ko.observable(apnSettings.dns2V6);
3440 target.authModesV6 = ko.observableArray(getAuthModes());
3441 target.usernameV6 = ko.observable(apnSettings.usernameV6);
3442 target.passwordV6 = ko.observable(apnSettings.passwordV6);
3443 target.pdpTypeNote = ko.observable(true);
3444 if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
3445 target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
3446 } else {
3447 target.selectedAutoProfile = ko.observable();
3448 }
3449
3450 if (config.EMPTY_APN_SUPPORT == false) {
3451 $("#apn_ipv4_apn").addClass("required");
3452 $("#apn_ipv6_apn").addClass("required");
3453 } else {
3454 $("#apn_ipv4_apn").removeClass("required");
3455 $("#apn_ipv6_apn").removeClass("required");
3456 }
3457
3458 target.disableProfile = ko.observable(false); //表示处于新增页面
3459 target.addApnHide = ko.observable(true);
3460 target.defaultCfg = ko.observable(true); //当前选中的是默认APN
3461 target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
3462
3463 target.selectedAuthentication = ko.observable(apnSettings.authMode);
3464 target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
3465
3466
3467 target.transApnV6 = ko.observable('apn');
3468 target.transDnsModeV6 = ko.observable('apn_dns_mode');
3469 target.transDns1V6 = ko.observable('apn_dns1');
3470 target.transDns2V6 = ko.observable('apn_dns2');
3471 target.transAuthV6 = ko.observable('apn_authentication');
3472 target.transUserNameV6 = ko.observable('apn_user_name');
3473 target.transPasswordV6 = ko.observable('apn_password');
3474
3475 target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
3476 target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
3477 target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
3478 target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
3479 target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
3480 target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
3481 target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
3482
3483 target.setDefaultVisible = ko.observable(!isConnectedNetWork());
3484
3485 target.tmp1 = ko.computed(function () {
3486 if (target.selectedPdpType() == "IPv6") {
3487 target.transApnV6('apn');
3488 target.transDnsModeV6('apn_dns_mode');
3489 target.transDns1V6('apn_dns1');
3490 target.transDns2V6('apn_dns2');
3491 target.transAuthV6('apn_authentication');
3492 target.transUserNameV6('apn_user_name');
3493 target.transPasswordV6('apn_password');
3494 } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3495 target.transApn('apn_ipv4_apn');
3496 target.transDnsMode('apn_dns_mode_ipv4');
3497 target.transDns1('apn_dns1_ipv4');
3498 target.transDns2('apn_dns2_ipv4');
3499 target.transAuth('apn_authentication_ipv4');
3500 target.transUserName('apn_user_name_ipv4');
3501 target.transPassword('apn_password_ipv4');
3502
3503 target.transApnV6('apn_ipv6_apn');
3504 target.transDnsModeV6('apn_dns_mode_ipv6');
3505 target.transDns1V6('apn_dns1_ipv6');
3506 target.transDns2V6('apn_dns2_ipv6');
3507 target.transAuthV6('apn_authentication_ipv6');
3508 target.transUserNameV6('apn_user_name_ipv6');
3509 target.transPasswordV6('apn_password_ipv6');
3510 } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
3511 target.transApn('apn');
3512 target.transDnsMode('apn_dns_mode');
3513 target.transDns1('apn_dns1');
3514 target.transDns2('apn_dns2');
3515 target.transAuth('apn_authentication');
3516 target.transUserName('apn_user_name');
3517 target.transPassword('apn_password');
3518 } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
3519 target.transApn('apn');
3520 target.transDnsMode('apn_dns_mode');
3521 target.transDns1('apn_dns1');
3522 target.transDns2('apn_dns2');
3523 target.transAuth('apn_authentication');
3524 target.transUserName('apn_user_name');
3525 target.transPassword('apn_password');
3526 }
3527 $("#apn_setting_form").translate();
3528 });
3529
3530 target.autoApnChecked = ko.computed(function () {
3531 return target.apnMode() == "auto";
3532 });
3533
3534 target.hasCapacity = ko.computed(function () {
3535 if (target.profiles().length < config.maxApnNumber) {
3536 return true;
3537 } else {
3538 return false;
3539 }
3540 });
3541
3542 target.showDnsV6 = ko.computed(function () {
3543 return target.dnsModeV6() == "manual";
3544 });
3545
3546 target.showDns = ko.computed(function () {
3547 return target.dnsMode() == "manual";
3548 });
3549
3550
3551 checkDefaultProfileStatus();
3552 target.checkInputDisable = ko.computed(function () {
3553 if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
3554 return false;
3555 }
3556 if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
3557 return true;
3558 }
3559 if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
3560 return false;
3561 }
3562 return false;
3563 });
3564
3565 var data = service.getDeviceInfo();
3566 target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
3567
3568
3569 target.showAutoApnDetail = ko.computed(function () {
3570 if (target.apnMode() != "auto") {
3571 return true;
3572 } else {
3573 return target.autoProfiles().length > 0;
3574 }
3575 });
3576 //密码显示事件
3577 target.showPasswordHandler = function () {
3578 var checkbox = $("#showPassword:checked");
3579 if (checkbox && checkbox.length == 0) {
3580 target.showPassword(true);
3581 } else {
3582 target.showPassword(false);
3583 }
3584 };
3585 //auto apn profile change 事件处理
3586
3587 target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
3588
3589
3590 //profile change 事件处理
3591
3592 target.profileChangeHandler = profileChangeHandlerFunc;
3593
3594
3595 //切换profile时重置下面的显示项
3596 target.setUIData = setUIDataFunc;
3597
3598
3599 //设置默认apn状态
3600
3601 function checkDefaultProfileStatus() {
3602 var index = getApnIndex();
3603 //默认apn不允许编辑
3604 if (target.apnMode() != "auto") { //当前选中与实际不一致的话
3605 if (target.selectedProfile() != target.defApn()) {
3606 target.defaultCfg(false);
3607 } else {
3608 target.defaultCfg(true); //默认APN
3609 }
3610 } else {
3611 if (target.selectedAutoProfile() != target.defApn()) {
3612 target.defaultCfg(false);
3613 } else {
3614 target.defaultCfg(true); //默认APN
3615 }
3616 }
3617
3618 if (index >= config.defaultApnSize) {
3619 target.predeterminedCfg(false);
3620 } else {
3621 target.predeterminedCfg(true); //预置APN
3622 }
3623 }
3624
3625
3626 //设置为默认apn
3627
3628 target.setDefaultAct = setDefaultActFunc;
3629
3630
3631
3632 //APN mode change 事件处理
3633
3634 target.apnModeChangeHandler = apnModeChangeHandlerFunc;
3635
3636
3637 function doSetDefaultAct() {
3638 var index = 0;
3639 if (target.apnMode() != 'auto') {
3640 index = getApnIndex();
3641 target.selectedProfile($("#profile").val());
3642 } else {
3643 index = getAutoApnIndex();
3644 target.selectedAutoProfile($("#autoProfile").val());
3645 }
3646 var selectedProfileDetail = target.getSelectedManualProfile();
3647 service.setDefaultApn({
3648 index: index,
3649 apnMode: target.apnMode(),
3650 pdpType: selectedProfileDetail.pdpType,
3651
3652 profileName: selectedProfileDetail.profileName,
3653 wanApn: selectedProfileDetail.wanApn,
3654 authMode: selectedProfileDetail.authMode,
3655 username: selectedProfileDetail.username,
3656 password: selectedProfileDetail.password,
3657 dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
3658 dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
3659 dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
3660 }, function (data) {
3661 if (data.result) {
3662 //showLoading("apn_alert_restart");
3663 //restartDevice(service);
3664 addTimeout(function () {
3665 initialize(true);
3666 target.apnModeChangeHandler();
3667 successOverlay();
3668 }, 500);
3669 } else {
3670 errorOverlay();
3671 }
3672 }, function (data) {
3673 errorOverlay();
3674 });
3675 }
3676
3677 target.getSelectedManualProfile = getSelectedManualProfileFunc;
3678
3679
3680 //获取自动apn索引
3681
3682 function getAutoApnIndex() {
3683 var configs = $("#autoProfile option");
3684 for (var ki = 0; ki < configs.length; ki++) {
3685 if (configs[ki].value == target.selectedAutoProfile()) {
3686 return ki;
3687 }
3688 }
3689 return configs.length - 1;
3690 }
3691
3692 //获取apn索引
3693
3694 function getApnIndex() {
3695 var configs = $("#profile option");
3696 if (configs.length == 0) {
3697 configs = target.profiles();
3698 }
3699 var ki = 0;
3700 for (; ki < configs.length; ki++) {
3701 if (configs[ki].value == target.selectedProfile()) {
3702 break;
3703 }
3704 }
3705 return ki;
3706 }
3707
3708 //保存APN设置信息
3709
3710 target.saveAct = saveActFunc;
3711
3712 //编辑APN信息
3713
3714 function editApnSetting(preAct) { //默认设置按钮触发为TRUE
3715 showLoading();
3716 var apnIndex = getApnIndex();
3717 var sameInfo = false;
3718 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3719 sameInfo = true;
3720 }
3721 var needDoDefault = false;
3722 if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
3723 needDoDefault = true;
3724 }
3725 service.addOrEditApn({
3726 profileName: target.profileName(),
3727 pdpType: target.selectedPdpType(),
3728 index: apnIndex,
3729
3730 wanApn: target.apn(),
3731 authMode: target.selectedAuthentication(),
3732 username: target.username(),
3733 password: target.password(),
3734 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3735 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3736 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3737
3738 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3739 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3740 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3741 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3742 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3743 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3744 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3745 }, function (data) {
3746 if (data.result) {
3747 apnSettings = getApnSet();
3748 if (target.profileName() != target.selectedProfile()) {
3749 var newProfileName = target.profileName();
3750 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3751 $('#profile').val(newProfileName).trigger('change');
3752 }
3753 if (needDoDefault == false) {
3754 successOverlay();
3755 } else {
3756 doSetDefaultAct();
3757 }
3758 } else {
3759 errorOverlay();
3760 }
3761 }, function (data) {
3762 errorOverlay();
3763 });
3764 }
3765
3766 //新增APN信息
3767
3768 function addNewApnSetting() {
3769 showLoading("waiting");
3770 var optionLen = $("option", "#profile").length;
3771 if (optionLen < config.defaultApnSize) {
3772 errorOverlay();
3773 return;
3774 }
3775 // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
3776 // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
3777 var sameInfo = false;
3778 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3779 sameInfo = true;
3780 }
3781
3782 service.addOrEditApn({
3783 profileName: target.profileName(),
3784 pdpType: target.selectedPdpType(),
3785 index: optionLen,
3786
3787 wanApn: target.apn(),
3788 authMode: target.selectedAuthentication(),
3789 username: target.username(),
3790 password: target.password(),
3791 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3792 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3793 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3794
3795 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3796 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3797 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3798 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3799 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3800 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3801 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3802 }, function (data) {
3803 if (data.result) {
3804 apnSettings = getApnSet();
3805 if (target.profileName() != target.selectedProfile()) {
3806 var newProfileName = target.profileName();
3807 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3808 $('#profile').val(newProfileName).trigger('change');
3809 }
3810 doSetDefaultAct();
3811 } else {
3812 errorOverlay();
3813 }
3814 }, function (data) {
3815 errorOverlay();
3816 });
3817 }
3818
3819
3820
3821 var tempApn = {};
3822 //删除APN
3823
3824 target.deleteAct = deleteActFunc;
3825
3826 //取消新增APN
3827
3828 target.cancelAddAct = cancelAddActFunc;
3829
3830 //进入新增APN页面
3831
3832 target.addAct = addActFunc;
3833 //进入新增APN页面
3834 function addActFunc() {
3835 clearValidateMsg('#apn_setting_form');
3836 target.pdpTypeNote(true);
3837 target.disableProfile(true);
3838 target.addApnHide(true);
3839 tempApn = {
3840 profileName: target.profileName(),
3841 selectedPdpType: target.selectedPdpType(),
3842
3843 wanApnV6: target.apnV6(),
3844 dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
3845 dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
3846 dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
3847 authModeV6: target.selectedAuthenticationV6(),
3848 usernameV6: target.usernameV6(),
3849 passwordV6: target.passwordV6(),
3850
3851 wanApn: target.apn(),
3852 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3853 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3854 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3855 authMode: target.selectedAuthentication(),
3856 username: target.username(),
3857 password: target.password(),
3858
3859 };
3860 target.profileName("");
3861 target.selectedPdpType("IP");
3862 target.selectedPdpTypeTmp("IP");
3863
3864 target.apnV6("");
3865 target.dnsModeV6("auto");
3866 target.dns1V6("");
3867 target.dns2V6("");
3868 target.selectedAuthenticationV6("none");
3869 target.usernameV6("");
3870 target.passwordV6("");
3871
3872 target.apn("");
3873 target.dnsMode("auto");
3874 target.dns1("");
3875 target.dns2("");
3876 target.selectedAuthentication("none");
3877 target.username("");
3878 target.password("");
3879
3880 }
3881
3882 //取消新增APN
3883 function cancelAddActFunc() {
3884 clearValidateMsg('#apn_setting_form');
3885 target.pdpTypeNote(false);
3886 target.disableProfile(false);
3887 target.addApnHide(false);
3888 target.profileName(tempApn.profileName);
3889 target.selectedPdpType(tempApn.selectedPdpType);
3890 target.selectedPdpTypeTmp(tempApn.selectedPdpType);
3891
3892 target.apnV6(tempApn.wanApnV6);
3893 target.dnsModeV6(tempApn.dnsModeV6);
3894 target.dns1V6(tempApn.dns1V6);
3895 target.dns2V6(tempApn.dns2V6);
3896 target.selectedAuthenticationV6(tempApn.authModeV6);
3897 target.usernameV6(tempApn.usernameV6);
3898 target.passwordV6(tempApn.passwordV6);
3899
3900 target.apn(tempApn.wanApn);
3901 target.dnsMode(tempApn.dnsMode);
3902 target.dns1(tempApn.dns1);
3903 target.dns2(tempApn.dns2);
3904 target.selectedAuthentication(tempApn.authMode);
3905 target.username(tempApn.username);
3906 target.password(tempApn.password);
3907
3908 }
3909
3910 //删除APN
3911 function deleteActFunc() {
3912 if (!target.selectedProfile()) {
3913 showAlert("apn_no_select_alert");
3914 return false;
3915 }
3916 if (target.predeterminedCfg()) { //预置的apn不允许删除
3917 errorOverlay("apn_delete_cant_delete_default");
3918 return false;
3919 }
3920 if (getApnSet().profileName == target.profileName()) {
3921 errorOverlay("apn_cant_delete_current");
3922 return false;
3923 }
3924
3925 showConfirm("apn_delete_confirm", function () {
3926 showLoading('deleting');
3927 service.deleteApn({
3928 index: getApnIndex()
3929 }, function (data) {
3930 if (data.result) {
3931 target.profiles(getProfileOptions(getApnSet().apnConfigs));
3932 target.selectedProfile(target.defApn());
3933 target.profileChangeHandler();
3934 successOverlay();
3935 } else {
3936 errorOverlay();
3937 }
3938 }, function (data) {
3939 errorOverlay();
3940 });
3941 });
3942 }
3943
3944 //保存APN设置信息
3945 function saveActFunc() {
3946 if (!$('#apn_setting_form').valid()) {
3947 return false;
3948 }
3949 if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
3950 showAlert("apn_no_select_alert");
3951 return false;
3952 }
3953 var exist = false;
3954 $.each(target.profiles(), function (i, e) {
3955 if (e.value == target.profileName()) {
3956 exist = true;
3957 }
3958 });
3959
3960 if (target.disableProfile() == false) {
3961 if (exist && target.selectedProfile() != target.profileName()) {
3962 showInfo("apn_save_profile_exist");
3963 return false;
3964 }
3965 if (target.predeterminedCfg()) { //预置的APN不可以修改
3966 errorOverlay();
3967 return false;
3968 }
3969 if (target.predeterminedCfg() || target.defaultCfg()) {
3970 //showConfirm("apn_alert", function () {
3971 editApnSetting(false);
3972 //});
3973 } else {
3974 editApnSetting(false);
3975 }
3976 } else {
3977
3978 if ($("#profile option").length >= config.maxApnNumber) {
3979 showInfo({
3980 msg: "apn_profile_full",
3981 params: [config.maxApnNumber]
3982 });
3983 return false;
3984 }
3985 if (exist) {
3986 showInfo("apn_save_profile_exist");
3987 return false;
3988 }
3989 var info = service.getStatusInfo();
3990 if (info.connectStatus != "ppp_connected") {
3991 //showConfirm("apn_alert", function () {
3992 addNewApnSetting();
3993 //});
3994
3995 } else {
3996 showConfirm("apn_diconneted_network_confirm", function () {
3997 showLoading('disconnecting');
3998 service.disconnect({}, function (data) {
3999 if (data.result) {
4000 config.connect_flag = true;
4001 addNewApnSetting();
4002 } else {
4003 errorOverlay();
4004 }
4005 });
4006 });
4007 }
4008 }
4009 }
4010
4011 function getSelectedManualProfileFunc() {
4012 var cfg = {};
4013 var profileVal = $("#profile").val();
4014 if (typeof target.selectedProfile() == 'undefined') {
4015 target.selectedProfile(profileVal);
4016 }
4017 var cfgV4 = apnConfigs[profileVal];
4018 var cfgV6 = ipv6ApnConfigs[profileVal];
4019 if (cfgV4 && !cfgV6) {
4020 $.extend(cfg, cfgV4);
4021 } else if (cfgV4 && cfgV6) {
4022 if (!!cfgV4.pdpType) {
4023 $.extend(cfg, cfgV6);
4024 $.extend(cfg, cfgV4);
4025 } else {
4026 $.extend(cfg, cfgV4);
4027 $.extend(cfg, cfgV6);
4028 }
4029 }
4030 return cfg;
4031 }
4032
4033 //APN mode change 事件处理
4034 function apnModeChangeHandlerFunc(data, event) {
4035 if (target.apnMode() != 'auto') {
4036 target.profileChangeHandler();
4037 } else {
4038 if (target.showAutoApnDetail()) {
4039 target.autoProfileChangeHandler();
4040 }
4041 }
4042 return true;
4043 }
4044
4045 //设置为默认apn
4046 function setDefaultActFunc() {
4047 if (!target.selectedProfile()) {
4048 showAlert("apn_no_select_alert");
4049 return false;
4050 }
4051 var connectStatus = service.getConnectionInfo().connectStatus;
4052 if (connectStatus == "ppp_connecting") {
4053 showAlert({
4054 msg: "apn_cant_modify_status",
4055 params: [$.i18n.prop("connecting").toLowerCase()]
4056 });
4057 return false;
4058 } else if (connectStatus == "ppp_disconnecting") {
4059 showAlert({
4060 msg: "apn_cant_modify_status",
4061 params: [$.i18n.prop("disconnecting").toLowerCase()]
4062 });
4063 return false;
4064 } else if (connectStatus == "ppp_connected") {
4065 showAlert({
4066 msg: "apn_cant_modify_status",
4067 params: [$.i18n.prop("connected").toLowerCase()]
4068 });
4069 return false;
4070 }
4071 if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
4072 //showConfirm("apn_alert", function () {
4073 showLoading("waiting");
4074 doSetDefaultAct();
4075 //});
4076 } else {
4077 if ($('#apn_setting_form').valid() == false) {
4078 $(".error:first", "#apn_setting_form").focus();
4079 } else {
4080 var exist = false;
4081 $.each(target.profiles(), function (i, e) {
4082 if (e.value == target.profileName()) {
4083 exist = true;
4084 }
4085 });
4086 if (exist && target.selectedProfile() != target.profileName()) {
4087 showInfo("apn_save_profile_exist");
4088 return false;
4089 }
4090 //showLoading("waiting");
4091 //showConfirm("apn_alert", function () {
4092 editApnSetting(true);
4093 //});
4094 }
4095 }
4096 }
4097
4098 //切换profile时重置下面的显示项
4099 function setUIDataFunc(data) {
4100 clearValidateMsg('#apn_setting_form');
4101 if (!data) {
4102 return;
4103 }
4104 target.selectedPdpType(data.pdpType || 'IP');
4105 target.selectedPdpTypeTmp(data.pdpType || 'IP');
4106 target.profileName(data.profileName);
4107
4108 target.apn(data.wanApn);
4109 target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
4110 target.dns1(data.dns1);
4111 target.dns2(data.dns2);
4112 target.username(data.username);
4113 target.password(data.password);
4114 target.selectedAuthentication(data.authMode || 'none');
4115
4116 target.apnV6(data.wanApnV6);
4117 target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
4118 target.dns1V6(data.dns1V6);
4119 target.dns2V6(data.dns2V6);
4120 target.usernameV6(data.usernameV6);
4121 target.passwordV6(data.passwordV6);
4122 target.selectedAuthenticationV6(data.authModeV6 || 'none');
4123 }
4124
4125 //profile change 事件处理
4126 function profileChangeHandlerFunc(data, event) {
4127 target.pdpTypeNote(true);
4128 if (target.apnMode() != 'manual') {
4129 return true;
4130 }
4131 var cfg = target.getSelectedManualProfile();
4132 target.setUIData(cfg);
4133 checkDefaultProfileStatus();
4134 return true;
4135 }
4136
4137 //auto apn profile change 事件处理
4138 function autoProfileChangeHandlerFunc(data, event) {
4139 if (target.apnMode() != 'auto') {
4140 return true;
4141 }
4142 var cfg = autoApnConfigs[target.selectedAutoProfile()];
4143 target.setUIData(cfg);
4144 checkDefaultProfileStatus();
4145 return true;
4146 }
4147
4148 function pdpTypeChangeAlertFunc() {
4149 if (target.pdpTypeNote()) {
4150 showAlert({
4151 msg: "apn_pdptype_change_note",
4152 params: [data.lanDomain, data.ipAddress]
4153 });
4154 }
4155 if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
4156 if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
4157 if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
4158 target.apn(target.apnV6());
4159 target.dnsMode(target.dnsModeV6());
4160 target.dns1(target.dns1V6());
4161 target.dns2(target.dns2V6());
4162 target.username(target.usernameV6());
4163 target.password(target.passwordV6());
4164 target.selectedAuthentication(target.selectedAuthenticationV6());
4165 } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
4166 target.apnV6(target.apn());
4167 target.dnsModeV6(target.dnsMode());
4168 target.dns1V6(target.dns1());
4169 target.dns2V6(target.dns2());
4170 target.usernameV6(target.username());
4171 target.passwordV6(target.password());
4172 target.selectedAuthenticationV6(target.selectedAuthentication());
4173 }
4174 }
4175 }
4176 target.selectedPdpTypeTmp(target.selectedPdpType());
4177 }
4178
4179
4180 }
4181
4182 //是否已联网
4183
4184 function isConnectedNetWork() {
4185 var info = service.getConnectionInfo();
4186 return info.connectStatus == "ppp_connected";
4187 }
4188
4189 function initVar() {
4190 apnConfigs = {};
4191 ipv6ApnConfigs = {};
4192 autoApnConfigs = {};
4193 }
4194 function bindContainer(vm){
4195 var container = $('#container');
4196 ko.cleanNode(container[0]);
4197 ko.applyBindings(vm, container[0]);
4198 }
4199 //初始化ViewModel
4200
4201 function initialize(formInit) {
4202 initVar();
4203
4204 var vm = new APNViewModel();
4205 bindContainer(vm);
4206
4207 if (!formInit) {
4208 addInterval(function () {
4209 vm.setDefaultVisible(!isConnectedNetWork());
4210 }, 1000);
4211 }
4212 $('#apn_setting_form').validate({
4213 submitHandler: function () {
4214 vm.saveAct();
4215 },
4216 rules: {
4217 profile_name: 'apn_profile_name_check',
4218 apn_ipv4_apn: 'apn_check',
4219 apn_dns1_ipv4: "ipv4",
4220 apn_dns2_ipv4: "ipv4",
4221 apn_ipv6_apn: 'apn_check',
4222 apn_dns1_ipv6: "ipv6",
4223 apn_dns2_ipv6: "ipv6",
4224 apn_user_name_ipv4: 'ppp_username_check',
4225 apn_secretcode_ipv4: 'ppp_secretcode_check',
4226 apn_user_name_ipv6: 'ppp_username_check',
4227 apn_secretcode_ipv6: 'ppp_secretcode_check'
4228 }
4229 });
4230 }
4231
4232 return {
4233 init: initialize
4234 };
4235});
4236define("network_info","underscore jquery knockout set service".split(" "),
4237 function (_, $, ko, config, service) {
4238
4239 function NetInfoVM() {
4240 var target = this;
4241 var network_status = service.getNetworkStatus();
4242
4243 target.pci = ko.observable(network_status.pci);
4244 target.sinr = ko.observable(network_status.sinr);
4245 target.rsrp = ko.observable(network_status.rsrp);
4246 target.rsrq = ko.observable(network_status.rsrq);
4247 target.plmn = ko.observable(network_status.plmn);
4248 target.cellid = ko.observable(network_status.cellid);
4249 target.band = ko.observable(network_status.band);
4250 }
4251
4252 function initialize() {
4253 var container = $('#container');
4254 ko.cleanNode(container[0]);
4255 var imVm = new NetInfoVM();
4256 ko.applyBindings(imVm, container[0]);
4257 }
4258
4259 return {
4260 init: initialize
4261 };
4262});