blob: 32b29ed5366a49440a1d5cc13265a0e3f36cebcd [file] [log] [blame]
qumengjiaca65ef52024-11-06 15:42:21 +08001
2define("firewall_url_filter","underscore jquery knockout set service".split(" "),
3 function (_, $, ko, config, service) {
4
5 //system url filter setting VM
mj.qu11d28a82024-12-17 18:09:17 -08006
qumengjiaca65ef52024-11-06 15:42:21 +08007 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;
mj.qu11d28a82024-12-17 18:09:17 -080031
qumengjiaca65ef52024-11-06 15:42:21 +080032 target.callback = callbackFunc;
33 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -080034
qumengjiaca65ef52024-11-06 15:42:21 +080035 target.deleteRule = deleteRuleFunc;
mj.qu11d28a82024-12-17 18:09:17 -080036
qumengjiaca65ef52024-11-06 15:42:21 +080037 //添加规则
mj.qu11d28a82024-12-17 18:09:17 -080038
qumengjiaca65ef52024-11-06 15:42:21 +080039 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 }
mj.qu11d28a82024-12-17 18:09:17 -080050
qumengjiaca65ef52024-11-06 15:42:21 +080051 //添加规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -080087
qumengjiaca65ef52024-11-06 15:42:21 +080088 }
mj.qu11d28a82024-12-17 18:09:17 -080089
qumengjiaca65ef52024-11-06 15:42:21 +080090 function clearFunc() {
91 $("#addURLFilter").val("");
92 }
mj.qu11d28a82024-12-17 18:09:17 -080093
qumengjiaca65ef52024-11-06 15:42:21 +080094 //页面初始化
mj.qu11d28a82024-12-17 18:09:17 -080095
qumengjiaca65ef52024-11-06 15:42:21 +080096 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -080097
qumengjiaca65ef52024-11-06 15:42:21 +080098 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
mj.qu11d28a82024-12-17 18:09:17 -0800130
qumengjiaca65ef52024-11-06 15:42:21 +0800131 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 }
mj.qu11d28a82024-12-17 18:09:17 -0800152
153
qumengjiaca65ef52024-11-06 15:42:21 +0800154 //获取upnp 信息
mj.qu11d28a82024-12-17 18:09:17 -0800155
qumengjiaca65ef52024-11-06 15:42:21 +0800156 function getUpnpSetting() {
157 return service.getUpnpSetting();
158 }
159
160 //初始化UpnpSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -0800161
qumengjiaca65ef52024-11-06 15:42:21 +0800162 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -0800163
qumengjiaca65ef52024-11-06 15:42:21 +0800164 var vm = new UpnpSettingVM();
165 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -0800166
qumengjiaca65ef52024-11-06 15:42:21 +0800167 }
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
mj.qu11d28a82024-12-17 18:09:17 -0800188
qumengjiaca65ef52024-11-06 15:42:21 +0800189 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 }
mj.qu11d28a82024-12-17 18:09:17 -0800210
211
qumengjiaca65ef52024-11-06 15:42:21 +0800212 //获取upnp 信息
mj.qu11d28a82024-12-17 18:09:17 -0800213
qumengjiaca65ef52024-11-06 15:42:21 +0800214 function getUpnpSetting() {
215 return service.getUpnpSetting();
216 }
217
218 //初始化UpnpSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -0800219
qumengjiaca65ef52024-11-06 15:42:21 +0800220 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -0800221
qumengjiaca65ef52024-11-06 15:42:21 +0800222 var vm = new UpnpSettingVM();
223 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -0800224
qumengjiaca65ef52024-11-06 15:42:21 +0800225 }
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//端口映射
mj.qu11d28a82024-12-17 18:09:17 -0800243
qumengjiaca65ef52024-11-06 15:42:21 +0800244define("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
mj.qu11d28a82024-12-17 18:09:17 -0800279
qumengjiaca65ef52024-11-06 15:42:21 +0800280 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
mj.qu11d28a82024-12-17 18:09:17 -0800288
qumengjiaca65ef52024-11-06 15:42:21 +0800289 target.comment = ko.observable('');
290 target.selectedMode = ko.observable('TCP&UDP');
291 target.modes = ko.observableArray(protocolModes);
mj.qu11d28a82024-12-17 18:09:17 -0800292
qumengjiaca65ef52024-11-06 15:42:21 +0800293 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 //设定,新增,删除回调函数
mj.qu11d28a82024-12-17 18:09:17 -0800308
qumengjiaca65ef52024-11-06 15:42:21 +0800309 target.callback = callbackFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800310
qumengjiaca65ef52024-11-06 15:42:21 +0800311 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -0800312
qumengjiaca65ef52024-11-06 15:42:21 +0800313 target.deleteMapRules = deleteMapRulesFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800314
qumengjiaca65ef52024-11-06 15:42:21 +0800315 //检查新增规则是否已经存在
mj.qu11d28a82024-12-17 18:09:17 -0800316
qumengjiaca65ef52024-11-06 15:42:21 +0800317 target.checkExist = checkExistFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800318
qumengjiaca65ef52024-11-06 15:42:21 +0800319 //设定端口映射
mj.qu11d28a82024-12-17 18:09:17 -0800320
qumengjiaca65ef52024-11-06 15:42:21 +0800321 target.enablePortMap = enablePortMapFunc;
322
323 //保存规则
mj.qu11d28a82024-12-17 18:09:17 -0800324
qumengjiaca65ef52024-11-06 15:42:21 +0800325 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800326
qumengjiaca65ef52024-11-06 15:42:21 +0800327 //保存规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800352
qumengjiaca65ef52024-11-06 15:42:21 +0800353 //检查新增规则是否已经存在
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800378
qumengjiaca65ef52024-11-06 15:42:21 +0800379 //设定端口映射
380 function enablePortMapFunc() {
381 showLoading();
382 var mapParams = {};
383 mapParams.portMapEnable = target.portMapEnable();
384 service.enablePortMap(mapParams, target.callback);
385 }
mj.qu11d28a82024-12-17 18:09:17 -0800386
qumengjiaca65ef52024-11-06 15:42:21 +0800387 //删除规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800402
qumengjiaca65ef52024-11-06 15:42:21 +0800403 //设定,新增,删除回调函数
404 function callbackFunc(ret) {
405 if (ret.result == "success") {
406 clear();
407 initialize(target);
408 successOverlay();
409 } else {
410 errorOverlay();
411 }
412 }
413
414 //情况添加规则输入
mj.qu11d28a82024-12-17 18:09:17 -0800415
qumengjiaca65ef52024-11-06 15:42:21 +0800416 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信息
mj.qu11d28a82024-12-17 18:09:17 -0800426
qumengjiaca65ef52024-11-06 15:42:21 +0800427 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
mj.qu11d28a82024-12-17 18:09:17 -0800438
qumengjiaca65ef52024-11-06 15:42:21 +0800439 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//端口转发
mj.qu11d28a82024-12-17 18:09:17 -0800509
qumengjiaca65ef52024-11-06 15:42:21 +0800510define("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项
mj.qu11d28a82024-12-17 18:09:17 -0800517
qumengjiaca65ef52024-11-06 15:42:21 +0800518 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
mj.qu11d28a82024-12-17 18:09:17 -0800542
qumengjiaca65ef52024-11-06 15:42:21 +0800543 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);
mj.qu11d28a82024-12-17 18:09:17 -0800549
qumengjiaca65ef52024-11-06 15:42:21 +0800550 target.portEnd = ko.observable('');
551 target.portStart = ko.observable('');
552 target.ipAddress = ko.observable('');
mj.qu11d28a82024-12-17 18:09:17 -0800553
qumengjiaca65ef52024-11-06 15:42:21 +0800554 target.comment = ko.observable('');
555 target.selectedMode = ko.observable('3');
556 target.modes = ko.observableArray(protocolModes);
557
558 target.rules = ko.observableArray(fwdinfo.portForwardRules);
mj.qu11d28a82024-12-17 18:09:17 -0800559
qumengjiaca65ef52024-11-06 15:42:21 +0800560 //设定,新增,删除回调函数
mj.qu11d28a82024-12-17 18:09:17 -0800561
qumengjiaca65ef52024-11-06 15:42:21 +0800562 target.callback = callbackFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800563
qumengjiaca65ef52024-11-06 15:42:21 +0800564 //创建列表模板
mj.qu11d28a82024-12-17 18:09:17 -0800565
qumengjiaca65ef52024-11-06 15:42:21 +0800566 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 //检查新增规则是否已经存在
mj.qu11d28a82024-12-17 18:09:17 -0800575
qumengjiaca65ef52024-11-06 15:42:21 +0800576 target.checkExist = checkExistFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800577
qumengjiaca65ef52024-11-06 15:42:21 +0800578 //保存规则
mj.qu11d28a82024-12-17 18:09:17 -0800579
qumengjiaca65ef52024-11-06 15:42:21 +0800580 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800581
qumengjiaca65ef52024-11-06 15:42:21 +0800582 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -0800583
qumengjiaca65ef52024-11-06 15:42:21 +0800584 target.deleteForwardRules = deleteForwardRulesFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800585
qumengjiaca65ef52024-11-06 15:42:21 +0800586 //设定虚拟服务器
mj.qu11d28a82024-12-17 18:09:17 -0800587
qumengjiaca65ef52024-11-06 15:42:21 +0800588 target.enableVirtualServer = enableVirtualServerFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800589
qumengjiaca65ef52024-11-06 15:42:21 +0800590 //设定虚拟服务器
591 function enableVirtualServerFunc() {
592 showLoading();
593 var fwdParams = {};
594 fwdParams.portForwardEnable = target.portForwardEnable();
595 service.enableVirtualServer(fwdParams, target.callback);
596 }
mj.qu11d28a82024-12-17 18:09:17 -0800597
qumengjiaca65ef52024-11-06 15:42:21 +0800598 //删除规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800613
qumengjiaca65ef52024-11-06 15:42:21 +0800614 //保存规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800646
qumengjiaca65ef52024-11-06 15:42:21 +0800647 //设定,新增,删除回调函数
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信息
mj.qu11d28a82024-12-17 18:09:17 -0800684
qumengjiaca65ef52024-11-06 15:42:21 +0800685 function getPortForward() {
686 return service.getPortForward();
687 }
688
689 //初始化port forward view model
mj.qu11d28a82024-12-17 18:09:17 -0800690
qumengjiaca65ef52024-11-06 15:42:21 +0800691 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);
mj.qu11d28a82024-12-17 18:09:17 -0800707
qumengjiaca65ef52024-11-06 15:42:21 +0800708 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 }
mj.qu11d28a82024-12-17 18:09:17 -0800758
qumengjiaca65ef52024-11-06 15:42:21 +0800759 function bindContainer(vm){
760 var container = $('#container');
761 ko.cleanNode(container[0]);
762 ko.applyBindings(vm, container[0]);
763
764 }
mj.qu11d28a82024-12-17 18:09:17 -0800765
qumengjiaca65ef52024-11-06 15:42:21 +0800766
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
mj.qu11d28a82024-12-17 18:09:17 -0800830
qumengjiaca65ef52024-11-06 15:42:21 +0800831 function PortFilterVM() {
832 var target = this;
833 var info = getPortFilter();
mj.qu11d28a82024-12-17 18:09:17 -0800834
qumengjiaca65ef52024-11-06 15:42:21 +0800835 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);
mj.qu11d28a82024-12-17 18:09:17 -0800840
qumengjiaca65ef52024-11-06 15:42:21 +0800841 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 //设定,新增,删除回调函数
mj.qu11d28a82024-12-17 18:09:17 -0800859
qumengjiaca65ef52024-11-06 15:42:21 +0800860 target.callback = callbackFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800861
qumengjiaca65ef52024-11-06 15:42:21 +0800862 //创建列表模板
mj.qu11d28a82024-12-17 18:09:17 -0800863
qumengjiaca65ef52024-11-06 15:42:21 +0800864 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
mj.qu11d28a82024-12-17 18:09:17 -0800872
qumengjiaca65ef52024-11-06 15:42:21 +0800873 target.policyChangeHandler = policyChangeHandlerFunc;
874
875 //保存规则
mj.qu11d28a82024-12-17 18:09:17 -0800876
qumengjiaca65ef52024-11-06 15:42:21 +0800877 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800878
qumengjiaca65ef52024-11-06 15:42:21 +0800879 //设定过滤基本信息
mj.qu11d28a82024-12-17 18:09:17 -0800880
qumengjiaca65ef52024-11-06 15:42:21 +0800881 target.setPortFilterBasic = setPortFilterBasicFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800882
qumengjiaca65ef52024-11-06 15:42:21 +0800883 //清空添加规则输入
mj.qu11d28a82024-12-17 18:09:17 -0800884
qumengjiaca65ef52024-11-06 15:42:21 +0800885 target.clear = clearFunc;
886
887 //检查新增规则是否已经存在
mj.qu11d28a82024-12-17 18:09:17 -0800888
qumengjiaca65ef52024-11-06 15:42:21 +0800889 target.checkExist = checkExistFunc;
890
891 //ip类型变化事件监听
mj.qu11d28a82024-12-17 18:09:17 -0800892
qumengjiaca65ef52024-11-06 15:42:21 +0800893 target.ipTypeChangeHandler = ipTypeChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800894
qumengjiaca65ef52024-11-06 15:42:21 +0800895 //协议变化事件监听
mj.qu11d28a82024-12-17 18:09:17 -0800896
qumengjiaca65ef52024-11-06 15:42:21 +0800897 target.protocolChangeHandler = protocolChangeHandlerFunc;
898
899 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -0800900
qumengjiaca65ef52024-11-06 15:42:21 +0800901 target.deleteFilterRules = deleteFilterRulesFunc;
902
903 //init to call
904 target.policyChangeHandler();
mj.qu11d28a82024-12-17 18:09:17 -0800905
qumengjiaca65ef52024-11-06 15:42:21 +0800906 //设定,新增,删除回调函数
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800922
qumengjiaca65ef52024-11-06 15:42:21 +0800923 //保存规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -0800978
qumengjiaca65ef52024-11-06 15:42:21 +0800979 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 }
mj.qu11d28a82024-12-17 18:09:17 -0800990
qumengjiaca65ef52024-11-06 15:42:21 +0800991 //设定过滤基本信息
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001014
qumengjiaca65ef52024-11-06 15:42:21 +08001015 //检查新增规则是否已经存在
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001050
qumengjiaca65ef52024-11-06 15:42:21 +08001051 //协议变化事件监听
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001067
qumengjiaca65ef52024-11-06 15:42:21 +08001068 //删除规则
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001083
qumengjiaca65ef52024-11-06 15:42:21 +08001084 }
1085
1086 //获取port filter信息
mj.qu11d28a82024-12-17 18:09:17 -08001087
qumengjiaca65ef52024-11-06 15:42:21 +08001088 function getPortFilter() {
1089 return service.getPortFilter();
1090 }
mj.qu11d28a82024-12-17 18:09:17 -08001091
qumengjiaca65ef52024-11-06 15:42:21 +08001092 //ip类型变化事件监听
1093 function ipTypeChangeHandlerFunc() {
1094 clearValidateMsg();
1095 return true;
1096 }
mj.qu11d28a82024-12-17 18:09:17 -08001097
qumengjiaca65ef52024-11-06 15:42:21 +08001098 //初始化port filter view model
mj.qu11d28a82024-12-17 18:09:17 -08001099
qumengjiaca65ef52024-11-06 15:42:21 +08001100 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//家长控制
mj.qu11d28a82024-12-17 18:09:17 -08001224
qumengjiaca65ef52024-11-06 15:42:21 +08001225define("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 };
mj.qu11d28a82024-12-17 18:09:17 -08001235
1236
qumengjiaca65ef52024-11-06 15:42:21 +08001237 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 });
mj.qu11d28a82024-12-17 18:09:17 -08001250
qumengjiaca65ef52024-11-06 15:42:21 +08001251 target.currentUserInChildGroup = ko.observable(true);
1252 //获取儿童组设备列表
mj.qu11d28a82024-12-17 18:09:17 -08001253
qumengjiaca65ef52024-11-06 15:42:21 +08001254 target.fetchChildGroupList = fetchChildGroupListFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001255
qumengjiaca65ef52024-11-06 15:42:21 +08001256 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 //获取已连接设备列表
mj.qu11d28a82024-12-17 18:09:17 -08001265
qumengjiaca65ef52024-11-06 15:42:21 +08001266 target.fetchAttachedDevices = fetchAttachedDevicesFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001267
qumengjiaca65ef52024-11-06 15:42:21 +08001268
1269 //儿童组设备 标签按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001270
qumengjiaca65ef52024-11-06 15:42:21 +08001271 target.backToMainHandler = backToMainHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001272
1273
qumengjiaca65ef52024-11-06 15:42:21 +08001274 ko.computed(function () {
1275 target.attachedDevices();
1276 target.childGroupList();
1277 $("#pc_children_group_form").translate();
1278 }).extend({
1279 notify: 'always',
1280 throttle: 300
1281 });
mj.qu11d28a82024-12-17 18:09:17 -08001282
qumengjiaca65ef52024-11-06 15:42:21 +08001283 //添加至儿童组
mj.qu11d28a82024-12-17 18:09:17 -08001284
qumengjiaca65ef52024-11-06 15:42:21 +08001285 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 }
mj.qu11d28a82024-12-17 18:09:17 -08001302
qumengjiaca65ef52024-11-06 15:42:21 +08001303 //移除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001304
qumengjiaca65ef52024-11-06 15:42:21 +08001305 target.removeChildGroupHandler = removeChildGroupHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001306
1307
qumengjiaca65ef52024-11-06 15:42:21 +08001308 //添加按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001309
qumengjiaca65ef52024-11-06 15:42:21 +08001310 target.addChildGroupHandler = addChildGroupHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001311
qumengjiaca65ef52024-11-06 15:42:21 +08001312
1313 target.dealElement = dealElementFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001314
1315
1316
qumengjiaca65ef52024-11-06 15:42:21 +08001317 //取消编辑主机名按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001318
qumengjiaca65ef52024-11-06 15:42:21 +08001319 target.cancelEditHostNameHandler = cancelEditHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001320
qumengjiaca65ef52024-11-06 15:42:21 +08001321 //主机名编辑保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001322
qumengjiaca65ef52024-11-06 15:42:21 +08001323 target.saveHostNameHandler = saveHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001324
qumengjiaca65ef52024-11-06 15:42:21 +08001325 //主机名编辑按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001326
qumengjiaca65ef52024-11-06 15:42:21 +08001327 target.editHostNameHandler = editHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001328
1329
qumengjiaca65ef52024-11-06 15:42:21 +08001330 target.selectedIds = ko.observableArray([]);
1331 target.siteList = ko.observable([]);
1332 /////////////////////////////////////////////////////////////////
1333 target.disableAdd = ko.computed(function () {
1334 return target.siteList().length == maxItem;
1335 });
mj.qu11d28a82024-12-17 18:09:17 -08001336
qumengjiaca65ef52024-11-06 15:42:21 +08001337 ko.computed(function () {
1338 target.siteList();
1339 target.selectedIds();
1340 setTimeout(function () {
1341 renderCheckbox();
1342 }, 100);
1343 $("#pc_site_white_list_form").translate();
1344 });
mj.qu11d28a82024-12-17 18:09:17 -08001345
qumengjiaca65ef52024-11-06 15:42:21 +08001346 //网站白名单添加按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001347
qumengjiaca65ef52024-11-06 15:42:21 +08001348 target.openAddSitePopoverHandler = openAddSitePopoverHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001349
qumengjiaca65ef52024-11-06 15:42:21 +08001350 //网站白名单列表选择框点击事件
mj.qu11d28a82024-12-17 18:09:17 -08001351
qumengjiaca65ef52024-11-06 15:42:21 +08001352 target.checkboxClickHandler = checkboxClickHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001353
qumengjiaca65ef52024-11-06 15:42:21 +08001354 //获取网站白名单列表
mj.qu11d28a82024-12-17 18:09:17 -08001355
qumengjiaca65ef52024-11-06 15:42:21 +08001356 target.fetchSiteWhiteList = fetchSiteWhiteListFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001357
qumengjiaca65ef52024-11-06 15:42:21 +08001358 //网站白名单删除函数
mj.qu11d28a82024-12-17 18:09:17 -08001359
qumengjiaca65ef52024-11-06 15:42:21 +08001360 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 //网站白名单删除所有按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001377
qumengjiaca65ef52024-11-06 15:42:21 +08001378 target.removeAllWhiteSite = removeAllWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001379
qumengjiaca65ef52024-11-06 15:42:21 +08001380 //网站白名单删除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001381
qumengjiaca65ef52024-11-06 15:42:21 +08001382 target.removeSelectedWhiteSite = removeSelectedWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001383
qumengjiaca65ef52024-11-06 15:42:21 +08001384 //网站白名单移除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001385
qumengjiaca65ef52024-11-06 15:42:21 +08001386 target.removeWhiteSite = removeWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001387
1388
1389
qumengjiaca65ef52024-11-06 15:42:21 +08001390 //网站白名单添加框保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001391
qumengjiaca65ef52024-11-06 15:42:21 +08001392 target.saveSiteWhite = saveSiteWhiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001393
qumengjiaca65ef52024-11-06 15:42:21 +08001394 //////////////////////////////////////////////////////////////////
1395 target.notSave = ko.observable(false);
1396 //获取时间限制信息
mj.qu11d28a82024-12-17 18:09:17 -08001397
qumengjiaca65ef52024-11-06 15:42:21 +08001398 target.fetchTimeLimited = fetchTimeLimitedFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001399
1400
qumengjiaca65ef52024-11-06 15:42:21 +08001401 //上网时间设置时间表格事件绑定
mj.qu11d28a82024-12-17 18:09:17 -08001402
qumengjiaca65ef52024-11-06 15:42:21 +08001403 target.bindEvent = bindEventFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001404
qumengjiaca65ef52024-11-06 15:42:21 +08001405 //上网时间设置保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001406
qumengjiaca65ef52024-11-06 15:42:21 +08001407 target.saveTimeLimitedHandler = saveTimeLimitedHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001408
qumengjiaca65ef52024-11-06 15:42:21 +08001409 //////////////////////////////////////////////////////////////////
1410 var isBinded = false;
1411 //上网规则标签点击事件
mj.qu11d28a82024-12-17 18:09:17 -08001412
qumengjiaca65ef52024-11-06 15:42:21 +08001413 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 }
mj.qu11d28a82024-12-17 18:09:17 -08001433
qumengjiaca65ef52024-11-06 15:42:21 +08001434 //获取儿童组设备列表
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001449
qumengjiaca65ef52024-11-06 15:42:21 +08001450 //获取已连接设备列表
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 });
mj.qu11d28a82024-12-17 18:09:17 -08001473
qumengjiaca65ef52024-11-06 15:42:21 +08001474 //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 }
mj.qu11d28a82024-12-17 18:09:17 -08001497
qumengjiaca65ef52024-11-06 15:42:21 +08001498 //移除按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001511
qumengjiaca65ef52024-11-06 15:42:21 +08001512 //添加按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001523
qumengjiaca65ef52024-11-06 15:42:21 +08001524 //取消编辑主机名按钮事件
1525 function cancelEditHostNameHandlerFunc(eleData) {
1526 target.dealElement(false, eleData.idx);
1527 }
mj.qu11d28a82024-12-17 18:09:17 -08001528
qumengjiaca65ef52024-11-06 15:42:21 +08001529 //主机名编辑保存按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001559
qumengjiaca65ef52024-11-06 15:42:21 +08001560 //主机名编辑按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001576
qumengjiaca65ef52024-11-06 15:42:21 +08001577 //网站白名单列表选择框点击事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001594
qumengjiaca65ef52024-11-06 15:42:21 +08001595 //网站白名单删除所有按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001607
qumengjiaca65ef52024-11-06 15:42:21 +08001608 //网站白名单添加框保存按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001639
qumengjiaca65ef52024-11-06 15:42:21 +08001640 //上网时间设置时间表格事件绑定
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001663
qumengjiaca65ef52024-11-06 15:42:21 +08001664 //上网时间设置保存按钮事件
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 }
mj.qu11d28a82024-12-17 18:09:17 -08001678
qumengjiaca65ef52024-11-06 15:42:21 +08001679 }
mj.qu11d28a82024-12-17 18:09:17 -08001680
qumengjiaca65ef52024-11-06 15:42:21 +08001681 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值
mj.qu11d28a82024-12-17 18:09:17 -08001719
qumengjiaca65ef52024-11-06 15:42:21 +08001720 function getSelectedValues() {
1721 return getCheckboxValues(true);
1722 }
1723 function getAllCheckboxValues() {
1724 return getCheckboxValues(false);
1725 }
mj.qu11d28a82024-12-17 18:09:17 -08001726
qumengjiaca65ef52024-11-06 15:42:21 +08001727 //增加网站白名单表单提交函数绑定和校验规则设置
mj.qu11d28a82024-12-17 18:09:17 -08001728
qumengjiaca65ef52024-11-06 15:42:21 +08001729 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 }
mj.qu11d28a82024-12-17 18:09:17 -08001742
qumengjiaca65ef52024-11-06 15:42:21 +08001743 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 //获取时间表格选中的时间
mj.qu11d28a82024-12-17 18:09:17 -08001758
qumengjiaca65ef52024-11-06 15:42:21 +08001759 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 //初始化时间表格
mj.qu11d28a82024-12-17 18:09:17 -08001786
qumengjiaca65ef52024-11-06 15:42:21 +08001787 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
mj.qu11d28a82024-12-17 18:09:17 -08001811
qumengjiaca65ef52024-11-06 15:42:21 +08001812 //页面初始化
mj.qu11d28a82024-12-17 18:09:17 -08001813
qumengjiaca65ef52024-11-06 15:42:21 +08001814 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -08001815
qumengjiaca65ef52024-11-06 15:42:21 +08001816 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
mj.qu11d28a82024-12-17 18:09:17 -08001835
qumengjiaca65ef52024-11-06 15:42:21 +08001836 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 //应用按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001845
qumengjiaca65ef52024-11-06 15:42:21 +08001846 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001847
qumengjiaca65ef52024-11-06 15:42:21 +08001848 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 }
mj.qu11d28a82024-12-17 18:09:17 -08001862
qumengjiaca65ef52024-11-06 15:42:21 +08001863 }
mj.qu11d28a82024-12-17 18:09:17 -08001864
qumengjiaca65ef52024-11-06 15:42:21 +08001865 function clearFunc() {
1866 initialize();
1867 }
mj.qu11d28a82024-12-17 18:09:17 -08001868
1869
qumengjiaca65ef52024-11-06 15:42:21 +08001870 //获取dmz 信息
mj.qu11d28a82024-12-17 18:09:17 -08001871
qumengjiaca65ef52024-11-06 15:42:21 +08001872 function getDmzSetting() {
1873 return service.getDmzSetting();
1874 }
1875
1876 //初始化DmzSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -08001877
qumengjiaca65ef52024-11-06 15:42:21 +08001878 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -08001879
qumengjiaca65ef52024-11-06 15:42:21 +08001880 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//选网模块
mj.qu11d28a82024-12-17 18:09:17 -08002117
qumengjiaca65ef52024-11-06 15:42:21 +08002118define("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
mj.qu11d28a82024-12-17 18:09:17 -08002126
qumengjiaca65ef52024-11-06 15:42:21 +08002127 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;
mj.qu11d28a82024-12-17 18:09:17 -08002138
qumengjiaca65ef52024-11-06 15:42:21 +08002139 target.networkStatusId = networkStatusIdFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002140
qumengjiaca65ef52024-11-06 15:42:21 +08002141 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 //手动搜网.
mj.qu11d28a82024-12-17 18:09:17 -08002155
qumengjiaca65ef52024-11-06 15:42:21 +08002156 target.search = searchFunc;
2157
2158 //自动选网时设置网络模式.
mj.qu11d28a82024-12-17 18:09:17 -08002159
qumengjiaca65ef52024-11-06 15:42:21 +08002160 target.save = saveFunc;
2161
2162 target.checkEnable = checkEnableFunc;
2163
2164 //注册选择的网络.
mj.qu11d28a82024-12-17 18:09:17 -08002165
qumengjiaca65ef52024-11-06 15:42:21 +08002166 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);
mj.qu11d28a82024-12-17 18:09:17 -08002178
qumengjiaca65ef52024-11-06 15:42:21 +08002179 //注册选择的网络.
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 }
mj.qu11d28a82024-12-17 18:09:17 -08002194
qumengjiaca65ef52024-11-06 15:42:21 +08002195 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 }
mj.qu11d28a82024-12-17 18:09:17 -08002203
qumengjiaca65ef52024-11-06 15:42:21 +08002204 //自动选网时设置网络模式.
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 }
mj.qu11d28a82024-12-17 18:09:17 -08002220
qumengjiaca65ef52024-11-06 15:42:21 +08002221 //手动搜网.
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 target.networkList([]);
2237 }
2238 });
2239 }
mj.qu11d28a82024-12-17 18:09:17 -08002240
qumengjiaca65ef52024-11-06 15:42:21 +08002241 function subnetTypeIdFunc(data) {
2242 return getSubNetworkTypeTog(data.nRat, data.SubAct);
2243 }
mj.qu11d28a82024-12-17 18:09:17 -08002244
qumengjiaca65ef52024-11-06 15:42:21 +08002245 function networkTypeIdFunc(data) {
2246 return getNetworkType(data.nRat);
2247 }
mj.qu11d28a82024-12-17 18:09:17 -08002248
qumengjiaca65ef52024-11-06 15:42:21 +08002249 function networkValueFunc(data) {
2250 var result = [];
2251 result.push(data.strNumeric); //strNumeric
2252 result.push(data.nRat); //nRat
2253 result.push(data.SubAct);
2254 return result.join(',');
2255 }
mj.qu11d28a82024-12-17 18:09:17 -08002256
qumengjiaca65ef52024-11-06 15:42:21 +08002257 function operatorNameFunc(data) {
2258 return data.strShortName;
2259 }
mj.qu11d28a82024-12-17 18:09:17 -08002260
qumengjiaca65ef52024-11-06 15:42:21 +08002261 function networkTypeFunc(data) {
2262 var result = getNetworkType(data.nRat);
2263 if (result == "auto")
2264 result = $.i18n.prop("auto");
2265 return result;
2266 }
mj.qu11d28a82024-12-17 18:09:17 -08002267
qumengjiaca65ef52024-11-06 15:42:21 +08002268 function subnetworkTypeFunc(data) {
2269 var result = getSubNetworkTypeTog(data.nRat, data.SubAct);
2270 return result;
2271 }
mj.qu11d28a82024-12-17 18:09:17 -08002272
qumengjiaca65ef52024-11-06 15:42:21 +08002273 function networkStatusFunc(data) {
2274 return $.i18n.prop(getNetworkStatusTog(data.nState));
2275 }
mj.qu11d28a82024-12-17 18:09:17 -08002276
qumengjiaca65ef52024-11-06 15:42:21 +08002277 function networkStatusIdFunc(data) {
2278 return getNetworkStatusTog(data.nState);
2279 }
mj.qu11d28a82024-12-17 18:09:17 -08002280
qumengjiaca65ef52024-11-06 15:42:21 +08002281 function networkTextFunc(data) {
2282 return data.strNumeric;
2283 }
2284
2285 }
2286
2287 //获取网络选择信息.
mj.qu11d28a82024-12-17 18:09:17 -08002288
qumengjiaca65ef52024-11-06 15:42:21 +08002289 function getNetSelectInfo() {
2290 return service.getNetSelectInfo();
2291 }
2292
2293 //搜网结果中的状态转换为对应的语言项.
mj.qu11d28a82024-12-17 18:09:17 -08002294
qumengjiaca65ef52024-11-06 15:42:21 +08002295 function getNetworkStatusTog(status) {
2296 if ("3" == status) {
2297 return "forbidden";
2298 } else if ("2" == status) {
2299 return "current";
2300 } else if ("1" == status) {
2301 return "available";
2302 }else if ("0" == status) {
2303 return "unknown";
2304 }
2305 }
2306 //子网络类型转换.
mj.qu11d28a82024-12-17 18:09:17 -08002307
qumengjiaca65ef52024-11-06 15:42:21 +08002308 function getSubNetworkTypeTog(type, subtype) {
2309 var type_3g = [2, 4, 5, 6, 8];
2310 if ("1" == subtype) {
2311 if ("7" == type) {
2312 subtype = "FDD-LTE";
2313 } else if ($.inArray(type, type_3g) != -1) {
2314 subtype = "WCDMA";
2315 }else {
2316 subtype = "GSM";
2317 }
2318 } else if ("0" == subtype) {
2319 if ("7" == type) {
2320 subtype = "TD-LTE";
2321 } else if ($.inArray(type, type_3g) != -1) {
2322 subtype = "TD-SCDMA";
2323 } else {
2324 subtype = "GSM";
2325 }
2326 } else {
2327 subtype = "";
2328 }
2329 return subtype;
2330 }
2331 //网络类型转换.
mj.qu11d28a82024-12-17 18:09:17 -08002332
qumengjiaca65ef52024-11-06 15:42:21 +08002333 function getNetworkType(type) {
2334 if ("7" == type) {
2335 return "4G";
2336 } else if ("2" == type) {
2337 return "3G";
2338 } else if ("0" == type) {
2339 return "2G";
2340 } else {
2341 return "auto";
2342 }
2343 }
2344
2345 function bindContainer(vm){
mj.qu11d28a82024-12-17 18:09:17 -08002346
qumengjiaca65ef52024-11-06 15:42:21 +08002347 var container = $('#container');
2348 ko.cleanNode(container[0]);
2349 ko.applyBindings(vm, container[0]);
2350 }
2351
2352 //初始化选网功能view model.
mj.qu11d28a82024-12-17 18:09:17 -08002353
qumengjiaca65ef52024-11-06 15:42:21 +08002354 function initialize() {
2355 var vm = new NetSelectVM();
2356 bindContainer(vm);
2357 addInterval(vm.checkEnable, 1000);
2358 }
2359
2360 return {
2361 init: initialize
2362 };
2363});
2364define("locknet","jquery knockout service jquery set main".split(" "),
2365 function ($, ko, service, config, home) {
2366
2367 function initialize() {
2368 var container = $('#container')[0];
2369 ko.cleanNode(container);
2370 var vm = new locknetViewMode();
2371 ko.applyBindings(vm, container);
2372
2373 $("#frmNetworkLock").validate({
2374 submitHandler: function () {
2375 vm.unlock();
2376 },
2377 rules: {
2378 txtLockNumber: "unlock_code_check"
2379 }
2380 });
2381 }
2382
2383 function locknetViewMode() {
2384 var target = this;
2385 var curCableMode = false;
2386 target.isCPE = config.PRODUCT_TYPE == 'CPE';
2387 target.hasRj45 = config.RJ45_SUPPORT;
2388 target.hasSms = config.HAS_SMS;
2389 target.hasPhonebook = config.HAS_PHONEBOOK;
2390 target.isSupportSD = config.SD_CARD_SUPPORT;
2391 if (config.WIFI_SUPPORT_QR_SWITCH == false) {
2392 target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
2393 } else {
2394 var wifiInfo = service.getWifiBasic();
2395 target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
2396 }
2397 if(config.WIFI_SUPPORT_QR_CODE){
2398 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2399 } else {
2400 target.qrcodeSrc = './pic/res_blacktrans.png';
2401 }
2402 target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
2403 target.deviceInfo = ko.observable([]);
2404 target.isHomePage = ko.observable(false);
2405 if (window.location.hash == "#main") {
2406 target.isHomePage(true);
2407 }
2408
2409 target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
2410 target.unlockCode = ko.observable();
2411
2412 var info = service.getNetworkUnlockTimes();
2413 target.times = ko.observable(info.unlock_nck_time);
2414
2415 //显示工作模式设置窗口
2416 target.showOpModeWindow = showOpModeWindowFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002417
qumengjiaca65ef52024-11-06 15:42:21 +08002418 target.isLoggedIn = ko.observable(false);
2419 target.enableFlag = ko.observable(false);
2420 //解锁
2421 target.unlock = unlockFunc;
2422
2423 //更新工作模式状态
2424 target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002425
qumengjiaca65ef52024-11-06 15:42:21 +08002426 //定时检查工作模式状态
2427 if (target.hasRj45) {
2428 target.refreshOpmodeInfo();
2429 addInterval(function () {
2430 target.refreshOpmodeInfo();
2431 }, 1000);
2432 }
mj.qu11d28a82024-12-17 18:09:17 -08002433
qumengjiaca65ef52024-11-06 15:42:21 +08002434 //更新工作模式状态
2435 function refreshOpmodeInfoFunc() {
2436 var obj = service.getStatusInfo();
2437 target.isLoggedIn(obj.isLoggedIn);
2438
2439 if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
2440 window.location.reload();
2441 return;
2442 }
2443
2444 curCableMode = checkCableMode(obj.blc_wan_mode);
2445 target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
2446 if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
2447 target.enableFlag(true);
2448 } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
2449 target.enableFlag(false);
2450 } else {
2451 target.enableFlag(true);
2452 }
2453 var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
2454 var currMode = "";
2455 switch (getMode) {
2456 case "PPP":
2457 currMode = "opmode_gateway";
2458 break;
2459 case "PPPOE":
2460 currMode = "opmode_cable";
2461 break;
2462 case "AUTO":
2463 currMode = "opmode_auto";
2464 break;
2465 default:
2466 break;
2467 }
2468 $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
2469 }
mj.qu11d28a82024-12-17 18:09:17 -08002470
qumengjiaca65ef52024-11-06 15:42:21 +08002471 //解锁
2472 function unlockFunc() {
2473 showLoading();
2474 service.unlockNetwork({
2475 unlock_network_code: target.unlockCode()
2476 }, function (data) {
2477 target.unlockCode("");
2478 if (data && data.result == "success") {
2479 successOverlay();
2480 if (window.location.hash == "#main") {
2481 setTimeout(function () {
2482 window.location.reload();
2483 }, 500);
2484 } else {
2485 window.location.hash = "#main";
2486 }
2487 } else {
2488 var info = service.getNetworkUnlockTimes();
2489 target.times(info.unlock_nck_time);
2490 errorOverlay();
2491 }
2492 })
2493 }
mj.qu11d28a82024-12-17 18:09:17 -08002494
qumengjiaca65ef52024-11-06 15:42:21 +08002495 //显示工作模式设置窗口
2496 function showOpModeWindowFunc() {
2497 showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
2498 }
2499 }
2500
2501 return {
2502 init: initialize
2503 };
2504});
2505
2506// RJ45联网设置模块
mj.qu11d28a82024-12-17 18:09:17 -08002507
qumengjiaca65ef52024-11-06 15:42:21 +08002508define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
2509function(_, $, ko, config, service) {
2510 var dialActions = _.map(config.dialActions, function(elem){
2511 return new Option(elem.name, elem.value);
2512 });
mj.qu11d28a82024-12-17 18:09:17 -08002513
qumengjiaca65ef52024-11-06 15:42:21 +08002514 var dialModes = _.map(config.pppoeModes, function(elem) {
2515 return new Option(elem.name, elem.value);
2516 });
mj.qu11d28a82024-12-17 18:09:17 -08002517
qumengjiaca65ef52024-11-06 15:42:21 +08002518 var checkStatusTimer = 0;
2519 var checkConCounter = 0;
2520 var timeoutTipShowed = false;
2521
2522 // 联网设置view model.
mj.qu11d28a82024-12-17 18:09:17 -08002523
qumengjiaca65ef52024-11-06 15:42:21 +08002524 function PPPoEViewModel() {
2525 var pppObj = service.getPppoeParams();
2526 var ethParams = pppObj;
2527 var target = this;
mj.qu11d28a82024-12-17 18:09:17 -08002528
qumengjiaca65ef52024-11-06 15:42:21 +08002529 target.staticNoticeShow = ko.observable();
2530 target.dhcpNoticeShow = ko.observable();
2531 target.pppoeNoticeShow = ko.observable();
2532 target.autoNoticeShow = ko.observable();
2533 target.staticNotice = ko.observable();
2534 target.dhcpNotice = ko.observable();
2535 target.pppoeNotice = ko.observable();
2536 target.autoNotice = ko.observable();
2537 target.dhcpNoticeText = ko.observable();
2538 target.staticNoticeText = ko.observable();
2539 target.pppoeNoticeText = ko.observable();
2540 target.autoNoticeText = ko.observable();
2541 target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
2542 target.showPassword = ko.observable(false);
2543 target.modes = ko.observableArray(dialModes);
2544 target.isPppoeMode = ko.observable(false);
2545 target.isStaticMode = ko.observable(false);
2546 target.isAutoMode = ko.observable(false);
2547 target.action = ko.observable();
2548 target.btnTrans = ko.observable();
2549 target.enableFlag = ko.observable();
2550 target.isShowDisbtn = ko.observable();
2551 target.isShowCancelbtn = ko.observable();
mj.qu11d28a82024-12-17 18:09:17 -08002552
qumengjiaca65ef52024-11-06 15:42:21 +08002553 if(pppObj.rj45_state == "dead"){
2554 checkRj45DeadTip();
2555 } else if(pppObj.rj45_state == "connect"){
2556 timeoutTipShowed = true;
2557 setRj45CheckTimer("connect");
2558 } else if(pppObj.rj45_state == "working"){
2559 setRj45WorkingTip();
2560 }
mj.qu11d28a82024-12-17 18:09:17 -08002561
qumengjiaca65ef52024-11-06 15:42:21 +08002562 target.user = ko.observable(pppObj.pppoe_username);
2563 target.password = ko.observable(pppObj.pppoe_cc);
2564 target.autoUser = ko.observable(pppObj.pppoe_username);
2565 target.autoPassword = ko.observable(pppObj.pppoe_cc);
2566 target.pppMode = ko.observable(pppObj.ethwan_dialmode);
2567 initContronler();
mj.qu11d28a82024-12-17 18:09:17 -08002568
qumengjiaca65ef52024-11-06 15:42:21 +08002569
2570 //下拉框选择改变下面DIV模块
2571 target.changeModeDiv = changeModeDivFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002572
qumengjiaca65ef52024-11-06 15:42:21 +08002573 target.radioHandler = radioHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002574
qumengjiaca65ef52024-11-06 15:42:21 +08002575 target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
2576 target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
2577 target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
2578 target.subnetMask = ko.observable(pppObj.static_wan_netmask);
2579 target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
mj.qu11d28a82024-12-17 18:09:17 -08002580
qumengjiaca65ef52024-11-06 15:42:21 +08002581 addInterval(function(){
2582 ethParams = service.getPppoeParams();
2583 pppObj.rj45_state = ethParams.rj45_state;
2584 initContronler();
2585 }, 1000);
mj.qu11d28a82024-12-17 18:09:17 -08002586
qumengjiaca65ef52024-11-06 15:42:21 +08002587 // 取消连接按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002588
qumengjiaca65ef52024-11-06 15:42:21 +08002589 target.cancelConnect = cancelConnectFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002590
qumengjiaca65ef52024-11-06 15:42:21 +08002591 // 应用按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002592
qumengjiaca65ef52024-11-06 15:42:21 +08002593 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002594
qumengjiaca65ef52024-11-06 15:42:21 +08002595 //密码显示事件
2596 target.showPasswordHandler = function () {
2597 var checkbox = $("#showPassword:checked");
2598 if (checkbox && checkbox.length == 0) {
2599 target.showPassword(true);
2600 } else {
2601 target.showPassword(false);
2602 }
2603 };
mj.qu11d28a82024-12-17 18:09:17 -08002604
qumengjiaca65ef52024-11-06 15:42:21 +08002605 // 更新当前界面状态、按钮、提示语等.
mj.qu11d28a82024-12-17 18:09:17 -08002606
qumengjiaca65ef52024-11-06 15:42:21 +08002607 function initContronler() {
2608 checkRj45DeadTip();
2609 if(target.currentMode() == "PPPOE"){
2610 target.isPppoeMode(true);
2611 target.isStaticMode(false);
2612 target.isAutoMode(false);
2613 target.staticNoticeShow(false);
2614 target.dhcpNoticeShow(false);
2615 target.autoNoticeShow(false);
2616 } else if(target.currentMode() == "AUTO"){
2617 target.isStaticMode(false);
2618 target.isPppoeMode(false);
2619 target.isAutoMode(true);
2620 target.dhcpNoticeShow(false);
2621 target.pppoeNoticeShow(false);
2622 target.staticNoticeShow(false);
2623 } else if(target.currentMode() == "STATIC"){
2624 target.isStaticMode(true);
2625 target.isPppoeMode(false);
2626 target.isAutoMode(false);
2627 target.dhcpNoticeShow(false);
2628 target.pppoeNoticeShow(false);
2629 target.autoNoticeShow(false);
2630 } else{
2631 target.isStaticMode(false);
2632 target.isPppoeMode(false);
2633 target.isAutoMode(false);
2634 target.staticNoticeShow(false);
2635 target.pppoeNoticeShow(false);
2636 target.autoNoticeShow(false);
2637 }
2638 if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
2639 target.enableFlag(false);
2640 } else {
2641 target.enableFlag(true);
2642 }
2643 if(pppObj.rj45_state == "connect"){
2644 if(target.pppMode() == "auto_dial"){
2645 target.action("connect");
2646 }else{
2647 target.action("disconnect");
2648 }
2649 } else if(pppObj.rj45_state == "working"){
2650 target.action("disconnect");
2651 }else{
2652 target.action("connect");
2653 }
2654 //应用/连接按钮
2655 if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
2656 target.btnTrans("connect");
2657 } else{
2658 target.btnTrans("apply");
2659 }
2660 if(pppObj.rj45_state != "idle"){
2661 $("#pppoeApply").attr("disabled", true);
2662 }else {
2663 $("#pppoeApply").attr("disabled", false);
2664 }
mj.qu11d28a82024-12-17 18:09:17 -08002665
qumengjiaca65ef52024-11-06 15:42:21 +08002666 //取消/断开按钮
2667 target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
2668 target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
mj.qu11d28a82024-12-17 18:09:17 -08002669
qumengjiaca65ef52024-11-06 15:42:21 +08002670 $("#pppoeApply").translate();
2671 }
2672 // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002673
qumengjiaca65ef52024-11-06 15:42:21 +08002674 function setRj45CheckTimer(action){
2675 checkStatusTimer && window.clearInterval(checkStatusTimer);
2676 if("connect" != action){
2677 checkStatusTimer = addInterval(function () {
2678 checkDisconnectStatus();
2679 }, 2000);
2680 }else{
2681 if(target.currentMode() == "PPPOE"){
2682 target.pppoeNoticeShow(true);
2683 target.pppoeNotice("pppoe_processing");
2684 target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
2685 } else if(target.currentMode() == "STATIC"){
2686 target.staticNoticeShow(true);
2687 target.staticNotice("static_processing");
2688 target.staticNoticeText($.i18n.prop("static_processing"));
2689 } else if(target.currentMode() == "DHCP"){
2690 target.dhcpNoticeShow(true);
2691 target.dhcpNotice("dyn_processing");
2692 target.dhcpNoticeText($.i18n.prop("dyn_processing"));
2693 }else{
2694 target.autoNoticeShow(true);
2695 target.autoNotice("auto_processing");
2696 target.autoNoticeText($.i18n.prop("auto_processing"));
2697 }
2698 checkStatusTimer = addInterval(function () {
2699 checkConnectionStatus();
2700 }, 2000);
2701 }
2702 }
2703 // 设置后通过定时检查rj45_state状态,判断连接操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002704
qumengjiaca65ef52024-11-06 15:42:21 +08002705 function checkConnectionStatus(){
2706 if(checkConCounter < 1){
2707 checkConCounter++;
2708 return;
2709 }
2710 if(pppObj.rj45_state == "connect"){
2711 if(target.currentMode() != ethParams.ethwan_mode){
2712 if(target.currentMode() == "AUTO"){
2713 target.autoNoticeShow(true);
2714 }else if(target.currentMode() == "PPPOE"){
2715 target.pppoeNoticeShow(true);
2716 }else if(target.currentMode() == "STATIC"){
2717 target.staticNoticeShow(true);
2718 }else if(target.currentMode() == "DHCP"){
2719 target.dhcpNoticeShow(true);
2720 }
2721 }
2722 if(checkConCounter > 6){
2723 if(timeoutTipShowed == false){
2724 timeoutTipShowed = true;
2725 showAlert("ussd_operation_timeout");
2726 }
2727 }
2728 checkConCounter++;
2729 } else if (pppObj.rj45_state == "working") {
2730 hideLoading();
2731 setRj45WorkingTip();
2732 window.clearInterval(checkStatusTimer);
2733 } else if (pppObj.rj45_state == "dead") {
2734 hideLoading();
2735 checkRj45DeadTip();
2736 window.clearInterval(checkStatusTimer);
2737 } else if(pppObj.rj45_state == "idle"){
2738 hideLoading();
2739 if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
2740 timeoutTipShowed == false && target.dhcpNoticeShow(true);
2741 target.dhcpNotice("dyn_fail");
2742 target.dhcpNoticeText($.i18n.prop("dyn_fail"));
2743 }
2744 if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
2745 timeoutTipShowed == false && target.staticNoticeShow(true);
2746 target.staticNotice("static_fail");
2747 target.staticNoticeText($.i18n.prop("static_fail"));
2748 }
2749 if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
2750 timeoutTipShowed == false && target.pppoeNoticeShow(true);
2751 target.pppoeNotice("pppoe_fail");
2752 target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
2753 }
2754 if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
2755 timeoutTipShowed == false && target.autoNoticeShow(true);
2756 target.autoNotice("auto_fail");
2757 target.autoNoticeText($.i18n.prop("auto_fail"));
2758 }
2759 window.clearInterval(checkStatusTimer);
2760 } else{
2761 hideLoading();
2762 window.clearInterval(checkStatusTimer);
2763 }
2764 }
2765 // 设置连接成功时提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002766
qumengjiaca65ef52024-11-06 15:42:21 +08002767 function setRj45WorkingTip(){
2768 if(target.currentMode() == ethParams.ethwan_mode){
2769 if(target.currentMode() == "AUTO") {
2770 target.autoNoticeShow(true);
2771 target.autoNotice("auto_success");
2772 target.autoNoticeText($.i18n.prop("auto_success"));
2773 }else if(target.currentMode() == "PPPOE") {
2774 target.pppoeNoticeShow(true);
2775 target.pppoeNotice("pppoe_success");
2776 target.pppoeNoticeText($.i18n.prop("pppoe_success"));
2777 }else if(target.currentMode() == "STATIC") {
2778 target.staticNoticeShow(true);
2779 target.staticNotice("static_success");
2780 target.staticNoticeText($.i18n.prop("static_success"));
2781 }else if(target.currentMode() == "DHCP" ) {
2782 target.dhcpNoticeShow(true);
2783 target.dhcpNotice("dyn_success");
2784 target.dhcpNoticeText($.i18n.prop("dyn_success"));
2785 }
2786 }
2787 }
mj.qu11d28a82024-12-17 18:09:17 -08002788
qumengjiaca65ef52024-11-06 15:42:21 +08002789 // 设置网线断开提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002790
qumengjiaca65ef52024-11-06 15:42:21 +08002791 function checkRj45DeadTip(){
2792 if(pppObj.rj45_state != "dead"){
2793 if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
2794 target.autoNoticeShow(false);
2795 }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
2796 target.pppoeNoticeShow(false);
2797 }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
2798 target.staticNoticeShow(false);
2799 }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
2800 target.dhcpNoticeShow(false);
2801 }
mj.qu11d28a82024-12-17 18:09:17 -08002802
qumengjiaca65ef52024-11-06 15:42:21 +08002803 } else{
2804 target.dhcpNotice("pppoe_msg");
2805 target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
2806 target.staticNotice("pppoe_msg");
2807 target.staticNoticeText($.i18n.prop("pppoe_msg"));
2808 target.pppoeNotice("pppoe_msg");
2809 target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
2810 target.autoNotice("pppoe_msg");
2811 target.autoNoticeText($.i18n.prop("pppoe_msg"));
2812 if(target.currentMode() == "AUTO") {
2813 target.autoNoticeShow(true);
2814 }else if(target.currentMode() == "PPPOE") {
2815 target.pppoeNoticeShow(true);
2816 }else if(target.currentMode() == "STATIC") {
2817 target.staticNoticeShow(true);
2818 }else if(target.currentMode() == "DHCP") {
2819 target.dhcpNoticeShow(true);
2820 }
2821 }
2822 }
2823 // 设置后通过定时检查rj45_state状态,判断断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002824
qumengjiaca65ef52024-11-06 15:42:21 +08002825 function checkDisconnectStatus(){
2826 if(checkConCounter < 1){
2827 checkConCounter++;
2828 } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
2829 target.dhcpNoticeShow(false);
2830 target.staticNoticeShow(false);
2831 target.pppoeNoticeShow(false);
2832 target.autoNoticeShow(false);
2833 window.clearInterval(checkStatusTimer);
2834 successOverlay();
2835 } else if(checkConCounter > 6){
2836 if(timeoutTipShowed == false){
2837 timeoutTipShowed = true;
2838 showAlert("ussd_operation_timeout");
2839 }
2840 window.clearInterval(checkStatusTimer);
2841 } else if(checkConCounter < 7) {
2842 checkConCounter++;
2843 } else {
2844 hideLoading();
2845 window.clearInterval(checkStatusTimer);
2846 }
2847 }
mj.qu11d28a82024-12-17 18:09:17 -08002848
qumengjiaca65ef52024-11-06 15:42:21 +08002849 //应用按钮事件.
2850 function saveFunc(){
2851 target.dhcpNoticeShow(false);
2852 target.staticNoticeShow(false);
2853 target.pppoeNoticeShow(false);
2854 target.autoNoticeShow(false);
2855 if(pppObj.rj45_state == "dead"){
2856 showAlert("pppoe_msg");
2857 return;
2858 }
2859 var requestParams = {};
2860 if($("#pppoe_mode").val() == "PPPOE") {
2861 requestParams = $.extend({}, {
2862 goformId: "WAN_GATEWAYMODE_PPPOE",
2863 pppoe_username: target.user(),
2864 pppoe_cc: target.password()
2865 });
2866 } else if($("#pppoe_mode").val() == "AUTO") {
2867 requestParams = $.extend({}, {
2868 goformId: "WAN_GATEWAYMODE_AUTO",
2869 pppoe_username: target.autoUser(),
2870 pppoe_cc: target.autoPassword()
2871 });
2872 } else if($("#pppoe_mode").val() == "STATIC") {
2873 if(target.ipAddress() == target.defaultGateway()){
2874 showAlert("ip_gate_not_same");
2875 return;
2876 }
2877 if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
2878 showAlert("ip_innergate_not_same");
2879 return;
2880 }
2881 requestParams = $.extend({}, {
2882 goformId: "WAN_GATEWAYMODE_STATIC",
2883 static_wan_ipaddr: target.ipAddress(),
2884 static_wan_netmask: target.subnetMask(),
2885 static_wan_gateway: target.defaultGateway(),
2886 static_wan_primary_dns: target.primaryDNS(),
2887 static_wan_secondary_dns: target.secondaryDNS(),
2888 WAN_MODE: "STATIC"
2889 });
2890 } else {
2891 requestParams = $.extend({}, {
2892 goformId: "WAN_GATEWAYMODE_DHCP"
2893 });
2894 }
2895 requestParams.action_link = "connect";
2896 requestParams.dial_mode = target.pppMode();
2897 showLoading("waiting");
mj.qu11d28a82024-12-17 18:09:17 -08002898
qumengjiaca65ef52024-11-06 15:42:21 +08002899 service.setPppoeDialMode(requestParams, function(data){
2900 if(data.result){
2901 target.currentMode($("#pppoe_mode").val());
2902 pppObj = service.getPppoeParams();
2903 checkConCounter = 0;
2904 timeoutTipShowed = false;
2905 setRj45CheckTimer("connect");
2906 $("#pppoeApply").translate();
2907 } else {
2908 errorOverlay("pppoe_message_send_fail");
2909 }
2910 });
mj.qu11d28a82024-12-17 18:09:17 -08002911
qumengjiaca65ef52024-11-06 15:42:21 +08002912 }
mj.qu11d28a82024-12-17 18:09:17 -08002913
qumengjiaca65ef52024-11-06 15:42:21 +08002914 //取消连接按钮事件.
2915 function cancelConnectFunc(){
2916 target.dhcpNoticeShow(false);
2917 target.staticNoticeShow(false);
2918 target.pppoeNoticeShow(false);
2919 target.autoNoticeShow(false);
2920 if(pppObj.rj45_state == "dead"){
2921 showAlert("pppoe_msg");
2922 return;
2923 }
2924 var requestParams = {
2925 dial_mode: target.pppMode(),
2926 action_link: "disconnect"
2927 };
2928 if(pppObj.ethwan_mode == "PPPOE") {
2929 requestParams = $.extend(requestParams, {
2930 goformId: "WAN_GATEWAYMODE_PPPOE",
2931 pppoe_username: pppObj.pppoe_username,
2932 pppoe_cc: pppObj.pppoe_cc
2933 });
2934 }else if(pppObj.ethwan_mode == "AUTO") {
2935 requestParams = $.extend(requestParams, {
2936 goformId: "WAN_GATEWAYMODE_AUTO",
2937 pppoe_username: pppObj.pppoe_username,
2938 pppoe_cc: pppObj.pppoe_cc
2939 });
2940 }else if(pppObj.ethwan_mode == "STATIC") {
2941 requestParams = $.extend(requestParams, {
2942 goformId: "WAN_GATEWAYMODE_STATIC",
2943 static_wan_ipaddr: pppObj.static_wan_ipaddr,
2944 static_wan_netmask: pppObj.static_wan_netmask,
2945 static_wan_gateway: pppObj.static_wan_gateway,
2946 static_wan_primary_dns: pppObj.static_wan_primary_dns,
2947 static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
2948 WAN_MODE: "STATIC"
2949 });
2950 }else {
2951 requestParams = $.extend(requestParams, {
2952 goformId: "WAN_GATEWAYMODE_DHCP"
2953 });
2954 }
2955 showLoading("waiting");
2956 service.setPppoeDialMode(requestParams, function(data){
2957 if(data.result){
2958 checkConCounter = 0;
2959 timeoutTipShowed = false;
2960 setRj45CheckTimer("disconnect");
2961 $("#pppoeApply").translate();
2962 } else {
2963 errorOverlay("pppoe_message_send_fail");
2964 }
2965 });
mj.qu11d28a82024-12-17 18:09:17 -08002966
qumengjiaca65ef52024-11-06 15:42:21 +08002967 }
mj.qu11d28a82024-12-17 18:09:17 -08002968
qumengjiaca65ef52024-11-06 15:42:21 +08002969 function radioHandlerFunc(){
2970 initContronler();
2971 return true;
2972 }
mj.qu11d28a82024-12-17 18:09:17 -08002973
qumengjiaca65ef52024-11-06 15:42:21 +08002974 function changeModeDivFunc(){
2975 initContronler();
2976 }
mj.qu11d28a82024-12-17 18:09:17 -08002977
qumengjiaca65ef52024-11-06 15:42:21 +08002978 }
2979
2980 function bindContainer(vm){
2981 var container = $('#container');
2982 ko.cleanNode(container[0]);
2983 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08002984
qumengjiaca65ef52024-11-06 15:42:21 +08002985 }
2986 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08002987
qumengjiaca65ef52024-11-06 15:42:21 +08002988 function initialize() {
2989 var vm = new PPPoEViewModel();
2990 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08002991
qumengjiaca65ef52024-11-06 15:42:21 +08002992 $("#pppoeApply").translate();
mj.qu11d28a82024-12-17 18:09:17 -08002993
qumengjiaca65ef52024-11-06 15:42:21 +08002994 $('#pppoeForm').validate({
2995 submitHandler : function() {
2996 vm.save();
2997 },
2998 rules: {
2999 txtPin: "wps_pin_check",
3000 txtIpAddress: "dmz_ip_check",
3001 txtSubnetMask: {
3002 ipv4: true,
3003 subnetmask_check: true
3004 },
3005 txtDefaultGateway: {
3006 ipv4: true,
3007 gateway_check: true
3008 },
3009 txtPrimaryDNS: {
3010 ipv4: true,
3011 dns_check:true
3012 },
3013 txtSecondaryDNS: {
3014 ipv4: true,
3015 dns_check:true
3016 }
3017 }
3018 });
3019 }
mj.qu11d28a82024-12-17 18:09:17 -08003020
3021
qumengjiaca65ef52024-11-06 15:42:21 +08003022//from 4.0
3023 // 有效DNS检查.
mj.qu11d28a82024-12-17 18:09:17 -08003024
qumengjiaca65ef52024-11-06 15:42:21 +08003025function validateDns(dns){
3026 if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
3027 return false;
3028 }
3029 return true;
3030}
3031 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08003032
qumengjiaca65ef52024-11-06 15:42:21 +08003033function isStaticIPValid(ip, lanip, lanmask){
3034 if(!ip || !lanip || !lanmask){//各参数不能为空
3035 return false;
3036 }
3037 if(ip == lanip){// 与内网IP相等
3038 return true;
3039 }
3040 var res1 = [], res2 = [], mask = [];
3041 addr1 = ip.split(".");
3042 addr2 = lanip.split(".");
3043 mask = lanmask.split(".");
3044 for(var i = 0; i < addr1.length; i += 1){
3045 res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
3046 res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
3047 }
3048 if(res1.join(".") == res2.join(".")){//在同一个网段
3049 return true;
3050 }else{//不在同一个网段
3051 return false;
3052 }
3053}
3054
3055// 有效子网掩码验证.
mj.qu11d28a82024-12-17 18:09:17 -08003056
qumengjiaca65ef52024-11-06 15:42:21 +08003057function isNetmaskIPValid(ip) {
3058 if (ip == 255 || ip == 254 || ip == 252 || ip == 248
3059 || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
3060 {
3061 return true;
3062 }
3063 else
3064 {
3065 return false;
3066 }
3067}
3068 // 有效子网掩码检查.
mj.qu11d28a82024-12-17 18:09:17 -08003069
qumengjiaca65ef52024-11-06 15:42:21 +08003070function validateNetmask(netmask) {
3071 var array = new Array();
3072 array = netmask.split(".");
3073
3074 if (array.length != 4) {
3075 return false;
3076 }
3077
3078 array[0] = parseInt(array[0]);
3079 array[1] = parseInt(array[1]);
3080 array[2] = parseInt(array[2]);
3081 array[3] = parseInt(array[3]);
3082
3083 if (array[3] != 0) {
3084 if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
3085 return false;
3086 } else {
3087 if (!isNetmaskIPValid(array[3])) {
3088 return false;
3089 }
3090 }
3091 }
3092
3093 if (array[2] != 0) {
3094 if (array[1] != 255 || array[0] != 255) {
3095 return false;
3096 } else {
3097 if (!isNetmaskIPValid(array[2])) {
3098 return false;
3099 }
3100 }
3101 }
3102
3103 if (array[1] != 0) {
3104 if (array[0] != 255) {
3105 return false;
3106 } else{
3107 if (!isNetmaskIPValid(array[1])) {
3108 return false;
3109 }
3110 }
3111 }
3112 if(array[0]!=255) {
3113 return false;
3114 }
3115 if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
3116 return false;
3117 }
3118 return true;
3119}
mj.qu11d28a82024-12-17 18:09:17 -08003120
qumengjiaca65ef52024-11-06 15:42:21 +08003121 // subnetmask_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003122
qumengjiaca65ef52024-11-06 15:42:21 +08003123jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
3124 var result = validateNetmask(value);
3125 return this.optional(element) || result;
3126});
3127 // dns_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003128
qumengjiaca65ef52024-11-06 15:42:21 +08003129jQuery.validator.addMethod("dns_check", function (value, element, param) {
3130 var result = validateDns(value);
3131 return this.optional(element) || result;
3132});
3133 // 有效网关检查.
mj.qu11d28a82024-12-17 18:09:17 -08003134
qumengjiaca65ef52024-11-06 15:42:21 +08003135function validateGateway(wanIp, netmaskIp, gatewayIp) {
3136 if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
3137 return true;
3138 } else {
3139 return false;
3140 }
3141}
3142 // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
mj.qu11d28a82024-12-17 18:09:17 -08003143
qumengjiaca65ef52024-11-06 15:42:21 +08003144function myConcat(ip1,ip2){
3145 var result = [];
3146 var iplArr = ip1.split(".");
3147 var ip2Arr = ip2.split(".");
3148 for(var i = 0; i < iplArr.length;i++){
3149 result[i] = (iplArr[i] & ip2Arr[i]);
3150 }
3151 return result.join(".");
3152}
3153 // gateway_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003154
qumengjiaca65ef52024-11-06 15:42:21 +08003155jQuery.validator.addMethod("gateway_check", function (value, element, param) {
3156 var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
3157 return this.optional(element) || result;
3158});
mj.qu11d28a82024-12-17 18:09:17 -08003159
qumengjiaca65ef52024-11-06 15:42:21 +08003160 return {
3161 init: initialize
3162 };
3163});
3164//联网设置模块
3165define("network_dial_set","underscore jquery knockout set service".split(" "),
3166function(_, $, ko, config, service) {
3167
3168 //联网设置view model
3169 function DialVM() {
3170 var dialMode = service.getConnectionMode();
3171 var target = this;
3172
3173 target.selectMode = ko.observable(dialMode.connectionMode);
3174 target.enableFlag = ko.observable(true);
3175 target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
3176 var originalRoaming = dialMode.isAllowedRoaming;
3177
3178 target.setAllowedRoaming = setAllowedRoamingFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003179
qumengjiaca65ef52024-11-06 15:42:21 +08003180 var checkboxFlag = $(".checkboxToggle");
3181 target.checkEnable = checkEnableFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003182
qumengjiaca65ef52024-11-06 15:42:21 +08003183 //修改联网模式
3184 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003185
qumengjiaca65ef52024-11-06 15:42:21 +08003186 function saveFunc() {
3187 showLoading();
3188 var connMode = target.selectMode();
3189 //当选择自动时,下发原先的勾选状态
3190 if (connMode == 'auto_dial') {
3191 originalRoaming = target.isAllowedRoaming();
3192 } else {
3193 target.isAllowedRoaming(originalRoaming);
3194 }
3195 service.setConnectionMode({
3196 connectionMode: connMode,
3197 isAllowedRoaming: target.isAllowedRoaming()
3198 }, function (result) {
3199 if (result.result == "success") {
3200 successOverlay();
3201 } else {
3202 errorOverlay();
3203 }
3204 });
3205 }
mj.qu11d28a82024-12-17 18:09:17 -08003206
qumengjiaca65ef52024-11-06 15:42:21 +08003207 function setAllowedRoamingFunc() {
3208 if(!$("#roamBtn").hasClass("disable")){
3209 var checkbox = $("#isAllowedRoaming:checked");
3210 if(checkbox && checkbox.length == 0 ){
3211 target.isAllowedRoaming("on");
3212 }else{
3213 target.isAllowedRoaming("off");
3214 }
3215 }
3216 }
mj.qu11d28a82024-12-17 18:09:17 -08003217
qumengjiaca65ef52024-11-06 15:42:21 +08003218 function checkEnableFunc() {
3219 var status = service.getStatusInfo();
3220
3221 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
3222 target.enableFlag(false);
3223 disableCheckbox(checkboxFlag);
3224 }
3225 else {
3226 target.enableFlag(true);
3227 enableCheckbox(checkboxFlag);
3228 }
3229 }
3230
3231 }
3232
3233 //联网设置初始化.
3234 function initialize() {
3235 var vm = new DialVM();
3236 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08003237
qumengjiaca65ef52024-11-06 15:42:21 +08003238 vm.checkEnable();
3239 addInterval( vm.checkEnable, 1000);
3240 }
mj.qu11d28a82024-12-17 18:09:17 -08003241
qumengjiaca65ef52024-11-06 15:42:21 +08003242 function bindContainer(vm){
3243 var container = $('#container');
3244 ko.cleanNode(container[0]);
3245 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08003246
qumengjiaca65ef52024-11-06 15:42:21 +08003247 }
mj.qu11d28a82024-12-17 18:09:17 -08003248
qumengjiaca65ef52024-11-06 15:42:21 +08003249 return {
3250 init: initialize
3251 };
3252});
3253// APN Setting 模块
3254define("network_apn_set","underscore jquery knockout set service".split(" "),
3255 function (_, $, ko, config, service) {
3256
3257 //获取鉴权方式
mj.qu11d28a82024-12-17 18:09:17 -08003258
qumengjiaca65ef52024-11-06 15:42:21 +08003259 function getAuthModes() {
3260 return _.map(config.APN_AUTH_MODES, function (item) {
3261 return new Option(item.name, item.value);
3262 });
3263 }
3264
3265 function getApnPdpTypes() {
3266 var pdpTypesArray = [new Option('IPv4', 'IP')];
3267 if (config.IPV6_SUPPORT) {
3268 pdpTypesArray.push(new Option('IPv6', 'IPv6'));
3269 if (config.IPV4V6_SUPPORT) {
3270 pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
3271 }
3272 if (config.IPV4_AND_V6_SUPPORT) {
3273 pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
3274 }
3275 }
3276 return pdpTypesArray;
3277 }
3278
3279 //获取apn相关信息
mj.qu11d28a82024-12-17 18:09:17 -08003280
qumengjiaca65ef52024-11-06 15:42:21 +08003281 function getApnSet() {
3282 var apnInfo = service.getApnSettings();
3283 apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
3284 apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
3285 apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
3286 return apnInfo;
3287 }
3288 var apnConfigs = {};
3289 var ipv6ApnConfigs = {};
3290 var autoApnConfigs = {};
3291
3292 //解析自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003293
qumengjiaca65ef52024-11-06 15:42:21 +08003294 function getAutoApnsConfig(autoApnV4, autoApnV6) {
3295 var autoApnsV4 = [];
3296 var autoApnsV6 = [];
3297
3298 if (autoApnV4 && autoApnV4.length > 5) {
3299 var apnArr = autoApnV4.split("||");
3300 for (var ki = 0; ki < apnArr.length; ki++) {
3301 if (apnArr[ki] != "") {
3302 var apnItem = parseApnItem(apnArr[ki], false);
3303 autoApnsV4.push(apnItem);
3304 }
3305 }
3306 }
3307 if (autoApnV6 && autoApnV6.length > 5) {
3308 var apnArr = autoApnV6.split("||");
3309 for (var ki = 0; ki < apnArr.length; ki++) {
3310 if (apnArr[ki] != "") {
3311 var apnItem = parseApnItem(apnArr[ki], false);
3312 autoApnsV6.push(apnItem);
3313 }
3314 }
3315 }
3316 return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
3317 }
3318 //解析apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003319
qumengjiaca65ef52024-11-06 15:42:21 +08003320 function getApnConfigs(apnsStr, isIpv6) {
3321 var apnCfgs = [];
3322 var theApnConfigs = {};
3323 if (apnsStr && apnsStr.length > 10) {
3324 var apnArr = apnsStr.split("||");
3325 for (var ki = 0; ki < apnArr.length; ki++) {
3326 if (apnArr[ki] != "") {
3327 var apnItem = parseApnItem(apnArr[ki], isIpv6);
3328 apnCfgs.push(apnItem);
3329 theApnConfigs[apnItem.profileName] = apnItem;
3330 }
3331 }
3332 }
3333 if (isIpv6 == false) {
3334 apnConfigs = theApnConfigs;
3335 } else {
3336 ipv6ApnConfigs = theApnConfigs;
3337 }
3338 return apnCfgs;
3339 }
3340
3341 //解析单条apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003342
qumengjiaca65ef52024-11-06 15:42:21 +08003343 function parseApnItem(apnStr, isIpv6) {
3344 var apnItem = {};
3345 var items = apnStr.split("($)");
3346 for (var ki = 0; ki < items.length; ki++) {
3347 apnItem.profileName = items[0];
3348 apnItem.pdpType = items[7];
3349 if (isIpv6 == false) {
3350 apnItem.dnsMode = items[10];
3351 apnItem.dns1 = items[11];
3352 apnItem.dns2 = items[12];
3353 apnItem.wanApn = items[1];
3354 apnItem.authMode = items[4].toLowerCase();
3355 apnItem.username = items[5];
3356 apnItem.password = items[6];
3357 } else {
3358 apnItem.dnsModeV6 = items[10];
3359 apnItem.dns1V6 = items[11];
3360 apnItem.dns2V6 = items[12];
3361 apnItem.wanApnV6 = items[1];
3362 apnItem.authModeV6 = items[4].toLowerCase();
3363 apnItem.usernameV6 = items[5];
3364 apnItem.passwordV6 = items[6];
3365 }
3366 }
3367 return apnItem;
3368 }
3369 //合并V4\V6自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003370
qumengjiaca65ef52024-11-06 15:42:21 +08003371 function dealAutoApnsV4V6(v4, v6) {
3372 autoApnConfigs = {};
3373 var autoApns = [];
3374 for (var ki = 0; ki < v4.length; ki++) {
3375 var apnElem = v4[ki];
3376 var itemsV6 = v6[ki];
3377 if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
3378 apnElem.usernameV6 = itemsV6.username;
3379 apnElem.passwordV6 = itemsV6.password;
3380 apnElem.dns1V6 = itemsV6.dns1;
3381 apnElem.dns2V6 = itemsV6.dns2;
3382 apnElem.wanApnV6 = itemsV6.wanApn;
3383 apnElem.authModeV6 = itemsV6.authMode;
3384 apnElem.dnsModeV6 = itemsV6.dnsMode;
3385 }
3386 autoApns.push(apnElem);
3387 autoApnConfigs[apnElem.profileName] = apnElem;
3388 }
3389 return autoApns;
3390 }
3391
3392 function getProfileOptions(apns) {
3393 return _.map(apns, function (item) {
3394 return new Option(item.profileName, item.profileName);
3395 });
3396 }
3397
3398 //APNViewModel
mj.qu11d28a82024-12-17 18:09:17 -08003399
qumengjiaca65ef52024-11-06 15:42:21 +08003400 function APNViewModel() {
3401 var target = this;
3402 var apnSettings = getApnSet();
3403 if (apnSettings.apnNumPreset) {
3404 config.maxApnNumber = apnSettings.apnNumPreset;
3405 }
3406
3407 target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
3408 target.apnMode = ko.observable(apnSettings.apnMode);
3409 target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
3410 target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
3411 target.wanDial = ko.observable(apnSettings.wanDial);
mj.qu11d28a82024-12-17 18:09:17 -08003412
qumengjiaca65ef52024-11-06 15:42:21 +08003413 target.showApnDns = ko.observable(config.SHOW_APN_DNS);
3414 target.index = ko.observable(apnSettings.currIndex);
3415 target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
3416 target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
3417
3418 target.apn = ko.observable(apnSettings.wanApn);
3419 target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
3420 target.dns1 = ko.observable(apnSettings.dns1);
3421 target.dns2 = ko.observable(apnSettings.dns2);
3422 target.authModes = ko.observableArray(getAuthModes());
3423 target.username = ko.observable(apnSettings.username);
3424 target.password = ko.observable(apnSettings.password);
mj.qu11d28a82024-12-17 18:09:17 -08003425
qumengjiaca65ef52024-11-06 15:42:21 +08003426 target.pdpTypes = ko.observableArray(getApnPdpTypes());
3427 target.selectedPdpType = ko.observable(apnSettings.pdpType);
3428 target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
3429 target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
3430 target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
3431
3432 target.showPassword = ko.observable(false);
3433
3434 target.apnV6 = ko.observable(apnSettings.wanApnV6);
3435 target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
3436 target.dns1V6 = ko.observable(apnSettings.dns1V6);
3437 target.dns2V6 = ko.observable(apnSettings.dns2V6);
3438 target.authModesV6 = ko.observableArray(getAuthModes());
3439 target.usernameV6 = ko.observable(apnSettings.usernameV6);
3440 target.passwordV6 = ko.observable(apnSettings.passwordV6);
3441 target.pdpTypeNote = ko.observable(true);
3442 if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
3443 target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
3444 } else {
3445 target.selectedAutoProfile = ko.observable();
3446 }
3447
3448 if (config.EMPTY_APN_SUPPORT == false) {
3449 $("#apn_ipv4_apn").addClass("required");
3450 $("#apn_ipv6_apn").addClass("required");
3451 } else {
3452 $("#apn_ipv4_apn").removeClass("required");
3453 $("#apn_ipv6_apn").removeClass("required");
3454 }
mj.qu11d28a82024-12-17 18:09:17 -08003455
qumengjiaca65ef52024-11-06 15:42:21 +08003456 target.disableProfile = ko.observable(false); //表示处于新增页面
3457 target.addApnHide = ko.observable(true);
3458 target.defaultCfg = ko.observable(true); //当前选中的是默认APN
3459 target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
mj.qu11d28a82024-12-17 18:09:17 -08003460
qumengjiaca65ef52024-11-06 15:42:21 +08003461 target.selectedAuthentication = ko.observable(apnSettings.authMode);
3462 target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
3463
3464
3465 target.transApnV6 = ko.observable('apn');
3466 target.transDnsModeV6 = ko.observable('apn_dns_mode');
3467 target.transDns1V6 = ko.observable('apn_dns1');
3468 target.transDns2V6 = ko.observable('apn_dns2');
3469 target.transAuthV6 = ko.observable('apn_authentication');
3470 target.transUserNameV6 = ko.observable('apn_user_name');
3471 target.transPasswordV6 = ko.observable('apn_password');
mj.qu11d28a82024-12-17 18:09:17 -08003472
qumengjiaca65ef52024-11-06 15:42:21 +08003473 target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
3474 target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
3475 target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
3476 target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
3477 target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
3478 target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
3479 target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
3480
3481 target.setDefaultVisible = ko.observable(!isConnectedNetWork());
3482
3483 target.tmp1 = ko.computed(function () {
3484 if (target.selectedPdpType() == "IPv6") {
3485 target.transApnV6('apn');
3486 target.transDnsModeV6('apn_dns_mode');
3487 target.transDns1V6('apn_dns1');
3488 target.transDns2V6('apn_dns2');
3489 target.transAuthV6('apn_authentication');
3490 target.transUserNameV6('apn_user_name');
3491 target.transPasswordV6('apn_password');
3492 } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3493 target.transApn('apn_ipv4_apn');
3494 target.transDnsMode('apn_dns_mode_ipv4');
3495 target.transDns1('apn_dns1_ipv4');
3496 target.transDns2('apn_dns2_ipv4');
3497 target.transAuth('apn_authentication_ipv4');
3498 target.transUserName('apn_user_name_ipv4');
3499 target.transPassword('apn_password_ipv4');
3500
3501 target.transApnV6('apn_ipv6_apn');
3502 target.transDnsModeV6('apn_dns_mode_ipv6');
3503 target.transDns1V6('apn_dns1_ipv6');
3504 target.transDns2V6('apn_dns2_ipv6');
3505 target.transAuthV6('apn_authentication_ipv6');
3506 target.transUserNameV6('apn_user_name_ipv6');
3507 target.transPasswordV6('apn_password_ipv6');
3508 } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
3509 target.transApn('apn');
3510 target.transDnsMode('apn_dns_mode');
3511 target.transDns1('apn_dns1');
3512 target.transDns2('apn_dns2');
3513 target.transAuth('apn_authentication');
3514 target.transUserName('apn_user_name');
3515 target.transPassword('apn_password');
3516 } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
3517 target.transApn('apn');
3518 target.transDnsMode('apn_dns_mode');
3519 target.transDns1('apn_dns1');
3520 target.transDns2('apn_dns2');
3521 target.transAuth('apn_authentication');
3522 target.transUserName('apn_user_name');
3523 target.transPassword('apn_password');
3524 }
3525 $("#apn_setting_form").translate();
3526 });
3527
3528 target.autoApnChecked = ko.computed(function () {
3529 return target.apnMode() == "auto";
3530 });
mj.qu11d28a82024-12-17 18:09:17 -08003531
qumengjiaca65ef52024-11-06 15:42:21 +08003532 target.hasCapacity = ko.computed(function () {
3533 if (target.profiles().length < config.maxApnNumber) {
3534 return true;
3535 } else {
3536 return false;
3537 }
3538 });
3539
3540 target.showDnsV6 = ko.computed(function () {
3541 return target.dnsModeV6() == "manual";
3542 });
mj.qu11d28a82024-12-17 18:09:17 -08003543
qumengjiaca65ef52024-11-06 15:42:21 +08003544 target.showDns = ko.computed(function () {
3545 return target.dnsMode() == "manual";
3546 });
3547
3548
3549 checkDefaultProfileStatus();
3550 target.checkInputDisable = ko.computed(function () {
3551 if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
3552 return false;
3553 }
3554 if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
3555 return true;
3556 }
3557 if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
3558 return false;
3559 }
3560 return false;
3561 });
3562
3563 var data = service.getDeviceInfo();
3564 target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003565
qumengjiaca65ef52024-11-06 15:42:21 +08003566
3567 target.showAutoApnDetail = ko.computed(function () {
3568 if (target.apnMode() != "auto") {
3569 return true;
3570 } else {
3571 return target.autoProfiles().length > 0;
3572 }
3573 });
3574 //密码显示事件
3575 target.showPasswordHandler = function () {
3576 var checkbox = $("#showPassword:checked");
3577 if (checkbox && checkbox.length == 0) {
3578 target.showPassword(true);
3579 } else {
3580 target.showPassword(false);
3581 }
3582 };
3583 //auto apn profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003584
qumengjiaca65ef52024-11-06 15:42:21 +08003585 target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003586
3587
qumengjiaca65ef52024-11-06 15:42:21 +08003588 //profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003589
qumengjiaca65ef52024-11-06 15:42:21 +08003590 target.profileChangeHandler = profileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003591
3592
qumengjiaca65ef52024-11-06 15:42:21 +08003593 //切换profile时重置下面的显示项
3594 target.setUIData = setUIDataFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003595
qumengjiaca65ef52024-11-06 15:42:21 +08003596
3597 //设置默认apn状态
mj.qu11d28a82024-12-17 18:09:17 -08003598
qumengjiaca65ef52024-11-06 15:42:21 +08003599 function checkDefaultProfileStatus() {
3600 var index = getApnIndex();
3601 //默认apn不允许编辑
3602 if (target.apnMode() != "auto") { //当前选中与实际不一致的话
3603 if (target.selectedProfile() != target.defApn()) {
3604 target.defaultCfg(false);
3605 } else {
3606 target.defaultCfg(true); //默认APN
3607 }
3608 } else {
3609 if (target.selectedAutoProfile() != target.defApn()) {
3610 target.defaultCfg(false);
3611 } else {
3612 target.defaultCfg(true); //默认APN
3613 }
3614 }
3615
3616 if (index >= config.defaultApnSize) {
3617 target.predeterminedCfg(false);
3618 } else {
3619 target.predeterminedCfg(true); //预置APN
3620 }
3621 }
3622
3623
3624 //设置为默认apn
qumengjiaca65ef52024-11-06 15:42:21 +08003625
mj.qu11d28a82024-12-17 18:09:17 -08003626 target.setDefaultAct = setDefaultActFunc;
3627
3628
3629
qumengjiaca65ef52024-11-06 15:42:21 +08003630 //APN mode change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003631
qumengjiaca65ef52024-11-06 15:42:21 +08003632 target.apnModeChangeHandler = apnModeChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003633
3634
qumengjiaca65ef52024-11-06 15:42:21 +08003635 function doSetDefaultAct() {
3636 var index = 0;
3637 if (target.apnMode() != 'auto') {
3638 index = getApnIndex();
3639 target.selectedProfile($("#profile").val());
3640 } else {
3641 index = getAutoApnIndex();
3642 target.selectedAutoProfile($("#autoProfile").val());
3643 }
3644 var selectedProfileDetail = target.getSelectedManualProfile();
3645 service.setDefaultApn({
3646 index: index,
3647 apnMode: target.apnMode(),
3648 pdpType: selectedProfileDetail.pdpType,
3649
3650 profileName: selectedProfileDetail.profileName,
3651 wanApn: selectedProfileDetail.wanApn,
3652 authMode: selectedProfileDetail.authMode,
3653 username: selectedProfileDetail.username,
3654 password: selectedProfileDetail.password,
3655 dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
3656 dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
3657 dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
3658 }, function (data) {
3659 if (data.result) {
3660 //showLoading("apn_alert_restart");
3661 //restartDevice(service);
3662 addTimeout(function () {
3663 initialize(true);
3664 target.apnModeChangeHandler();
3665 successOverlay();
3666 }, 500);
3667 } else {
3668 errorOverlay();
3669 }
3670 }, function (data) {
3671 errorOverlay();
3672 });
3673 }
3674
3675 target.getSelectedManualProfile = getSelectedManualProfileFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003676
qumengjiaca65ef52024-11-06 15:42:21 +08003677
3678 //获取自动apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003679
qumengjiaca65ef52024-11-06 15:42:21 +08003680 function getAutoApnIndex() {
3681 var configs = $("#autoProfile option");
3682 for (var ki = 0; ki < configs.length; ki++) {
3683 if (configs[ki].value == target.selectedAutoProfile()) {
3684 return ki;
3685 }
3686 }
3687 return configs.length - 1;
3688 }
mj.qu11d28a82024-12-17 18:09:17 -08003689
qumengjiaca65ef52024-11-06 15:42:21 +08003690 //获取apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003691
qumengjiaca65ef52024-11-06 15:42:21 +08003692 function getApnIndex() {
3693 var configs = $("#profile option");
3694 if (configs.length == 0) {
3695 configs = target.profiles();
3696 }
3697 var ki = 0;
3698 for (; ki < configs.length; ki++) {
3699 if (configs[ki].value == target.selectedProfile()) {
3700 break;
3701 }
3702 }
3703 return ki;
3704 }
3705
3706 //保存APN设置信息
mj.qu11d28a82024-12-17 18:09:17 -08003707
qumengjiaca65ef52024-11-06 15:42:21 +08003708 target.saveAct = saveActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003709
qumengjiaca65ef52024-11-06 15:42:21 +08003710 //编辑APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003711
qumengjiaca65ef52024-11-06 15:42:21 +08003712 function editApnSetting(preAct) { //默认设置按钮触发为TRUE
3713 showLoading();
3714 var apnIndex = getApnIndex();
3715 var sameInfo = false;
3716 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3717 sameInfo = true;
3718 }
3719 var needDoDefault = false;
3720 if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
3721 needDoDefault = true;
3722 }
3723 service.addOrEditApn({
3724 profileName: target.profileName(),
3725 pdpType: target.selectedPdpType(),
3726 index: apnIndex,
3727
3728 wanApn: target.apn(),
3729 authMode: target.selectedAuthentication(),
3730 username: target.username(),
3731 password: target.password(),
3732 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3733 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3734 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3735
3736 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3737 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3738 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3739 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3740 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3741 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3742 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3743 }, function (data) {
3744 if (data.result) {
3745 apnSettings = getApnSet();
3746 if (target.profileName() != target.selectedProfile()) {
3747 var newProfileName = target.profileName();
3748 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3749 $('#profile').val(newProfileName).trigger('change');
3750 }
3751 if (needDoDefault == false) {
3752 successOverlay();
3753 } else {
3754 doSetDefaultAct();
3755 }
3756 } else {
3757 errorOverlay();
3758 }
3759 }, function (data) {
3760 errorOverlay();
3761 });
3762 }
mj.qu11d28a82024-12-17 18:09:17 -08003763
qumengjiaca65ef52024-11-06 15:42:21 +08003764 //新增APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003765
qumengjiaca65ef52024-11-06 15:42:21 +08003766 function addNewApnSetting() {
3767 showLoading("waiting");
3768 var optionLen = $("option", "#profile").length;
3769 if (optionLen < config.defaultApnSize) {
3770 errorOverlay();
3771 return;
3772 }
3773 // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
3774 // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
3775 var sameInfo = false;
3776 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3777 sameInfo = true;
3778 }
3779
3780 service.addOrEditApn({
3781 profileName: target.profileName(),
3782 pdpType: target.selectedPdpType(),
3783 index: optionLen,
3784
3785 wanApn: target.apn(),
3786 authMode: target.selectedAuthentication(),
3787 username: target.username(),
3788 password: target.password(),
3789 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3790 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3791 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3792
3793 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3794 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3795 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3796 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3797 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3798 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3799 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3800 }, function (data) {
3801 if (data.result) {
3802 apnSettings = getApnSet();
3803 if (target.profileName() != target.selectedProfile()) {
3804 var newProfileName = target.profileName();
3805 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3806 $('#profile').val(newProfileName).trigger('change');
3807 }
3808 doSetDefaultAct();
3809 } else {
3810 errorOverlay();
3811 }
3812 }, function (data) {
3813 errorOverlay();
3814 });
3815 }
3816
mj.qu11d28a82024-12-17 18:09:17 -08003817
qumengjiaca65ef52024-11-06 15:42:21 +08003818
3819 var tempApn = {};
3820 //删除APN
mj.qu11d28a82024-12-17 18:09:17 -08003821
qumengjiaca65ef52024-11-06 15:42:21 +08003822 target.deleteAct = deleteActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003823
qumengjiaca65ef52024-11-06 15:42:21 +08003824 //取消新增APN
mj.qu11d28a82024-12-17 18:09:17 -08003825
qumengjiaca65ef52024-11-06 15:42:21 +08003826 target.cancelAddAct = cancelAddActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003827
qumengjiaca65ef52024-11-06 15:42:21 +08003828 //进入新增APN页面
mj.qu11d28a82024-12-17 18:09:17 -08003829
qumengjiaca65ef52024-11-06 15:42:21 +08003830 target.addAct = addActFunc;
3831 //进入新增APN页面
3832 function addActFunc() {
3833 clearValidateMsg('#apn_setting_form');
3834 target.pdpTypeNote(true);
3835 target.disableProfile(true);
3836 target.addApnHide(true);
3837 tempApn = {
3838 profileName: target.profileName(),
3839 selectedPdpType: target.selectedPdpType(),
3840
3841 wanApnV6: target.apnV6(),
3842 dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
3843 dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
3844 dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
3845 authModeV6: target.selectedAuthenticationV6(),
3846 usernameV6: target.usernameV6(),
3847 passwordV6: target.passwordV6(),
mj.qu11d28a82024-12-17 18:09:17 -08003848
qumengjiaca65ef52024-11-06 15:42:21 +08003849 wanApn: target.apn(),
3850 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3851 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3852 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3853 authMode: target.selectedAuthentication(),
3854 username: target.username(),
3855 password: target.password(),
3856
3857 };
3858 target.profileName("");
3859 target.selectedPdpType("IP");
3860 target.selectedPdpTypeTmp("IP");
3861
3862 target.apnV6("");
3863 target.dnsModeV6("auto");
3864 target.dns1V6("");
3865 target.dns2V6("");
3866 target.selectedAuthenticationV6("none");
3867 target.usernameV6("");
3868 target.passwordV6("");
mj.qu11d28a82024-12-17 18:09:17 -08003869
qumengjiaca65ef52024-11-06 15:42:21 +08003870 target.apn("");
3871 target.dnsMode("auto");
3872 target.dns1("");
3873 target.dns2("");
3874 target.selectedAuthentication("none");
3875 target.username("");
3876 target.password("");
3877
3878 }
mj.qu11d28a82024-12-17 18:09:17 -08003879
qumengjiaca65ef52024-11-06 15:42:21 +08003880 //取消新增APN
3881 function cancelAddActFunc() {
3882 clearValidateMsg('#apn_setting_form');
3883 target.pdpTypeNote(false);
3884 target.disableProfile(false);
3885 target.addApnHide(false);
3886 target.profileName(tempApn.profileName);
3887 target.selectedPdpType(tempApn.selectedPdpType);
3888 target.selectedPdpTypeTmp(tempApn.selectedPdpType);
3889
3890 target.apnV6(tempApn.wanApnV6);
3891 target.dnsModeV6(tempApn.dnsModeV6);
3892 target.dns1V6(tempApn.dns1V6);
3893 target.dns2V6(tempApn.dns2V6);
3894 target.selectedAuthenticationV6(tempApn.authModeV6);
3895 target.usernameV6(tempApn.usernameV6);
3896 target.passwordV6(tempApn.passwordV6);
mj.qu11d28a82024-12-17 18:09:17 -08003897
qumengjiaca65ef52024-11-06 15:42:21 +08003898 target.apn(tempApn.wanApn);
3899 target.dnsMode(tempApn.dnsMode);
3900 target.dns1(tempApn.dns1);
3901 target.dns2(tempApn.dns2);
3902 target.selectedAuthentication(tempApn.authMode);
3903 target.username(tempApn.username);
3904 target.password(tempApn.password);
3905
3906 }
mj.qu11d28a82024-12-17 18:09:17 -08003907
qumengjiaca65ef52024-11-06 15:42:21 +08003908 //删除APN
3909 function deleteActFunc() {
3910 if (!target.selectedProfile()) {
3911 showAlert("apn_no_select_alert");
3912 return false;
3913 }
3914 if (target.predeterminedCfg()) { //预置的apn不允许删除
3915 errorOverlay("apn_delete_cant_delete_default");
3916 return false;
3917 }
3918 if (getApnSet().profileName == target.profileName()) {
3919 errorOverlay("apn_cant_delete_current");
3920 return false;
3921 }
3922
3923 showConfirm("apn_delete_confirm", function () {
3924 showLoading('deleting');
3925 service.deleteApn({
3926 index: getApnIndex()
3927 }, function (data) {
3928 if (data.result) {
3929 target.profiles(getProfileOptions(getApnSet().apnConfigs));
3930 target.selectedProfile(target.defApn());
3931 target.profileChangeHandler();
3932 successOverlay();
3933 } else {
3934 errorOverlay();
3935 }
3936 }, function (data) {
3937 errorOverlay();
3938 });
3939 });
3940 }
mj.qu11d28a82024-12-17 18:09:17 -08003941
qumengjiaca65ef52024-11-06 15:42:21 +08003942 //保存APN设置信息
3943 function saveActFunc() {
3944 if (!$('#apn_setting_form').valid()) {
3945 return false;
3946 }
3947 if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
3948 showAlert("apn_no_select_alert");
3949 return false;
3950 }
3951 var exist = false;
3952 $.each(target.profiles(), function (i, e) {
3953 if (e.value == target.profileName()) {
3954 exist = true;
3955 }
3956 });
3957
3958 if (target.disableProfile() == false) {
3959 if (exist && target.selectedProfile() != target.profileName()) {
3960 showInfo("apn_save_profile_exist");
3961 return false;
3962 }
3963 if (target.predeterminedCfg()) { //预置的APN不可以修改
3964 errorOverlay();
3965 return false;
3966 }
3967 if (target.predeterminedCfg() || target.defaultCfg()) {
3968 //showConfirm("apn_alert", function () {
3969 editApnSetting(false);
3970 //});
3971 } else {
3972 editApnSetting(false);
3973 }
3974 } else {
mj.qu11d28a82024-12-17 18:09:17 -08003975
qumengjiaca65ef52024-11-06 15:42:21 +08003976 if ($("#profile option").length >= config.maxApnNumber) {
3977 showInfo({
3978 msg: "apn_profile_full",
3979 params: [config.maxApnNumber]
3980 });
3981 return false;
3982 }
3983 if (exist) {
3984 showInfo("apn_save_profile_exist");
3985 return false;
3986 }
3987 var info = service.getStatusInfo();
3988 if (info.connectStatus != "ppp_connected") {
3989 //showConfirm("apn_alert", function () {
3990 addNewApnSetting();
3991 //});
mj.qu11d28a82024-12-17 18:09:17 -08003992
qumengjiaca65ef52024-11-06 15:42:21 +08003993 } else {
3994 showConfirm("apn_diconneted_network_confirm", function () {
3995 showLoading('disconnecting');
3996 service.disconnect({}, function (data) {
3997 if (data.result) {
3998 config.connect_flag = true;
3999 addNewApnSetting();
4000 } else {
4001 errorOverlay();
4002 }
4003 });
4004 });
4005 }
4006 }
4007 }
mj.qu11d28a82024-12-17 18:09:17 -08004008
qumengjiaca65ef52024-11-06 15:42:21 +08004009 function getSelectedManualProfileFunc() {
4010 var cfg = {};
4011 var profileVal = $("#profile").val();
4012 if (typeof target.selectedProfile() == 'undefined') {
4013 target.selectedProfile(profileVal);
4014 }
4015 var cfgV4 = apnConfigs[profileVal];
4016 var cfgV6 = ipv6ApnConfigs[profileVal];
4017 if (cfgV4 && !cfgV6) {
4018 $.extend(cfg, cfgV4);
4019 } else if (cfgV4 && cfgV6) {
4020 if (!!cfgV4.pdpType) {
4021 $.extend(cfg, cfgV6);
4022 $.extend(cfg, cfgV4);
4023 } else {
4024 $.extend(cfg, cfgV4);
4025 $.extend(cfg, cfgV6);
4026 }
4027 }
4028 return cfg;
4029 }
mj.qu11d28a82024-12-17 18:09:17 -08004030
qumengjiaca65ef52024-11-06 15:42:21 +08004031 //APN mode change 事件处理
4032 function apnModeChangeHandlerFunc(data, event) {
4033 if (target.apnMode() != 'auto') {
4034 target.profileChangeHandler();
4035 } else {
4036 if (target.showAutoApnDetail()) {
4037 target.autoProfileChangeHandler();
4038 }
4039 }
4040 return true;
4041 }
mj.qu11d28a82024-12-17 18:09:17 -08004042
qumengjiaca65ef52024-11-06 15:42:21 +08004043 //设置为默认apn
4044 function setDefaultActFunc() {
4045 if (!target.selectedProfile()) {
4046 showAlert("apn_no_select_alert");
4047 return false;
4048 }
4049 var connectStatus = service.getConnectionInfo().connectStatus;
4050 if (connectStatus == "ppp_connecting") {
4051 showAlert({
4052 msg: "apn_cant_modify_status",
4053 params: [$.i18n.prop("connecting").toLowerCase()]
4054 });
4055 return false;
4056 } else if (connectStatus == "ppp_disconnecting") {
4057 showAlert({
4058 msg: "apn_cant_modify_status",
4059 params: [$.i18n.prop("disconnecting").toLowerCase()]
4060 });
4061 return false;
4062 } else if (connectStatus == "ppp_connected") {
4063 showAlert({
4064 msg: "apn_cant_modify_status",
4065 params: [$.i18n.prop("connected").toLowerCase()]
4066 });
4067 return false;
4068 }
4069 if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
4070 //showConfirm("apn_alert", function () {
4071 showLoading("waiting");
4072 doSetDefaultAct();
4073 //});
4074 } else {
4075 if ($('#apn_setting_form').valid() == false) {
4076 $(".error:first", "#apn_setting_form").focus();
4077 } else {
4078 var exist = false;
4079 $.each(target.profiles(), function (i, e) {
4080 if (e.value == target.profileName()) {
4081 exist = true;
4082 }
4083 });
4084 if (exist && target.selectedProfile() != target.profileName()) {
4085 showInfo("apn_save_profile_exist");
4086 return false;
4087 }
4088 //showLoading("waiting");
4089 //showConfirm("apn_alert", function () {
4090 editApnSetting(true);
4091 //});
4092 }
4093 }
4094 }
mj.qu11d28a82024-12-17 18:09:17 -08004095
qumengjiaca65ef52024-11-06 15:42:21 +08004096 //切换profile时重置下面的显示项
4097 function setUIDataFunc(data) {
4098 clearValidateMsg('#apn_setting_form');
4099 if (!data) {
4100 return;
4101 }
4102 target.selectedPdpType(data.pdpType || 'IP');
4103 target.selectedPdpTypeTmp(data.pdpType || 'IP');
4104 target.profileName(data.profileName);
4105
4106 target.apn(data.wanApn);
4107 target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
4108 target.dns1(data.dns1);
4109 target.dns2(data.dns2);
4110 target.username(data.username);
4111 target.password(data.password);
4112 target.selectedAuthentication(data.authMode || 'none');
4113
4114 target.apnV6(data.wanApnV6);
4115 target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
4116 target.dns1V6(data.dns1V6);
4117 target.dns2V6(data.dns2V6);
4118 target.usernameV6(data.usernameV6);
4119 target.passwordV6(data.passwordV6);
4120 target.selectedAuthenticationV6(data.authModeV6 || 'none');
4121 }
mj.qu11d28a82024-12-17 18:09:17 -08004122
qumengjiaca65ef52024-11-06 15:42:21 +08004123 //profile change 事件处理
4124 function profileChangeHandlerFunc(data, event) {
4125 target.pdpTypeNote(true);
4126 if (target.apnMode() != 'manual') {
4127 return true;
4128 }
4129 var cfg = target.getSelectedManualProfile();
4130 target.setUIData(cfg);
4131 checkDefaultProfileStatus();
4132 return true;
4133 }
mj.qu11d28a82024-12-17 18:09:17 -08004134
qumengjiaca65ef52024-11-06 15:42:21 +08004135 //auto apn profile change 事件处理
4136 function autoProfileChangeHandlerFunc(data, event) {
4137 if (target.apnMode() != 'auto') {
4138 return true;
4139 }
4140 var cfg = autoApnConfigs[target.selectedAutoProfile()];
4141 target.setUIData(cfg);
4142 checkDefaultProfileStatus();
4143 return true;
4144 }
mj.qu11d28a82024-12-17 18:09:17 -08004145
qumengjiaca65ef52024-11-06 15:42:21 +08004146 function pdpTypeChangeAlertFunc() {
4147 if (target.pdpTypeNote()) {
4148 showAlert({
4149 msg: "apn_pdptype_change_note",
4150 params: [data.lanDomain, data.ipAddress]
4151 });
4152 }
4153 if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
4154 if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
4155 if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
4156 target.apn(target.apnV6());
4157 target.dnsMode(target.dnsModeV6());
4158 target.dns1(target.dns1V6());
4159 target.dns2(target.dns2V6());
4160 target.username(target.usernameV6());
4161 target.password(target.passwordV6());
4162 target.selectedAuthentication(target.selectedAuthenticationV6());
4163 } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
4164 target.apnV6(target.apn());
4165 target.dnsModeV6(target.dnsMode());
4166 target.dns1V6(target.dns1());
4167 target.dns2V6(target.dns2());
4168 target.usernameV6(target.username());
4169 target.passwordV6(target.password());
4170 target.selectedAuthenticationV6(target.selectedAuthentication());
4171 }
4172 }
4173 }
4174 target.selectedPdpTypeTmp(target.selectedPdpType());
4175 }
mj.qu11d28a82024-12-17 18:09:17 -08004176
qumengjiaca65ef52024-11-06 15:42:21 +08004177
4178 }
4179
4180 //是否已联网
mj.qu11d28a82024-12-17 18:09:17 -08004181
qumengjiaca65ef52024-11-06 15:42:21 +08004182 function isConnectedNetWork() {
4183 var info = service.getConnectionInfo();
4184 return info.connectStatus == "ppp_connected";
4185 }
4186
4187 function initVar() {
4188 apnConfigs = {};
4189 ipv6ApnConfigs = {};
4190 autoApnConfigs = {};
4191 }
4192 function bindContainer(vm){
4193 var container = $('#container');
4194 ko.cleanNode(container[0]);
4195 ko.applyBindings(vm, container[0]);
4196 }
4197 //初始化ViewModel
mj.qu11d28a82024-12-17 18:09:17 -08004198
qumengjiaca65ef52024-11-06 15:42:21 +08004199 function initialize(formInit) {
4200 initVar();
mj.qu11d28a82024-12-17 18:09:17 -08004201
qumengjiaca65ef52024-11-06 15:42:21 +08004202 var vm = new APNViewModel();
4203 bindContainer(vm);
4204
4205 if (!formInit) {
4206 addInterval(function () {
4207 vm.setDefaultVisible(!isConnectedNetWork());
4208 }, 1000);
4209 }
4210 $('#apn_setting_form').validate({
4211 submitHandler: function () {
4212 vm.saveAct();
4213 },
4214 rules: {
4215 profile_name: 'apn_profile_name_check',
4216 apn_ipv4_apn: 'apn_check',
4217 apn_dns1_ipv4: "ipv4",
4218 apn_dns2_ipv4: "ipv4",
4219 apn_ipv6_apn: 'apn_check',
4220 apn_dns1_ipv6: "ipv6",
4221 apn_dns2_ipv6: "ipv6",
4222 apn_user_name_ipv4: 'ppp_username_check',
4223 apn_secretcode_ipv4: 'ppp_secretcode_check',
4224 apn_user_name_ipv6: 'ppp_username_check',
4225 apn_secretcode_ipv6: 'ppp_secretcode_check'
4226 }
4227 });
4228 }
4229
4230 return {
4231 init: initialize
4232 };
mj.qu11d28a82024-12-17 18:09:17 -08004233});
4234define("network_info","underscore jquery knockout set service".split(" "),
4235 function (_, $, ko, config, service) {
4236
4237 function NetInfoVM() {
4238 var target = this;
4239 var network_status = service.getNetworkStatus();
4240
4241 target.pci = ko.observable(network_status.pci);
4242 target.sinr = ko.observable(network_status.sinr);
4243 target.rsrp = ko.observable(network_status.rsrp);
4244 target.rsrq = ko.observable(network_status.rsrq);
4245 target.plmn = ko.observable(network_status.plmn);
4246 target.cellid = ko.observable(network_status.cellid);
4247 }
4248
4249 function initialize() {
4250 var container = $('#container');
4251 ko.cleanNode(container[0]);
4252 var imVm = new NetInfoVM();
4253 ko.applyBindings(imVm, container[0]);
4254 }
4255
4256 return {
4257 init: initialize
4258 };
4259});