blob: f19fbbcb5eb71547a4cd8b49f49dcf79f0dc43a5 [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
mj.quc73c89d2025-02-20 19:44:20 -0800903 target.clear();
qumengjiaca65ef52024-11-06 15:42:21 +0800904 //init to call
905 target.policyChangeHandler();
mj.qu11d28a82024-12-17 18:09:17 -0800906
qumengjiaca65ef52024-11-06 15:42:21 +0800907 //设定,新增,删除回调函数
908 function callbackFunc(ret) {
909 if (ret.result != "success") {
910 errorOverlay();
911 } else {
912 target.clear();
913 initialize(target);
914 successOverlay();
915 }
916 }
917 //default policy change handler
918 function policyChangeHandlerFunc() {
919 var action = target.defaultPolicy() != "1" ? "Drop" : "Accept";
920 target.portFilterAction(action);
921 return true;
922 }
mj.qu11d28a82024-12-17 18:09:17 -0800923
qumengjiaca65ef52024-11-06 15:42:21 +0800924 //保存规则
925 function saveFunc() {
926 target.sourceIpAddress(target.sourceIpAddress().replace(/\s+/g, ''));
927 target.destIpAddress(target.destIpAddress().replace(/\s+/g, ''));
928 target.sourceIpv6Address(target.sourceIpv6Address().replace(/\s+/g, ''));
929 target.destIpv6Address(target.destIpv6Address().replace(/\s+/g, ''));
930 target.macAddress(target.macAddress().replace(/\s+/g, ''));
931 if (target.ipv6Support() == false) {
932 if (target.rules().length >= config.portForwardMax) {
933 showAlert({
934 msg: "rules_max",
935 params: config.portForwardMax
936 });
937 return;
938 }
939
940 if (target.checkExist()) {
941 showAlert("rule_exist");
942 return;
943 }
944
945 } else {
946 var type = target.ipType() == "ipv4" ? "IPv4" : "IPv6";
947 var oldRules = _.filter(target.rules(), function (item) {
948 return item.ipType == type;
949 });
950
951 if (oldRules.length >= config.portForwardMax) {
952 showAlert({
953 msg: "rules_max_v4v6",
954 params: [type, config.portForwardMax]
955 });
956 return;
957 }
958
959 if (target.checkExist()) {
960 showAlert({
961 msg: "rule_exist_v4v6",
962 params: type
963 });
964 return;
965 }
966 }
967 showConfirm("confirm_data_effect", function () {
968 showLoading();
969 var fltParams = {};
970 fltParams.macAddress = target.macAddress();
971
972 if (target.ipv6Support() && target.ipType() != 'ipv6') {
973 fltParams.destIpAddress = target.destIpAddress();
974 fltParams.sourceIpAddress = target.sourceIpAddress();
975 } else {
976 fltParams.destIpAddress = target.destIpv6Address();
977 fltParams.sourceIpAddress = target.sourceIpv6Address();
978 }
mj.qu11d28a82024-12-17 18:09:17 -0800979
qumengjiaca65ef52024-11-06 15:42:21 +0800980 fltParams.ipType = target.ipType();
981 fltParams.comment = target.comment();
982 fltParams.protocol = target.selectedMode();
983 fltParams.action = target.portFilterAction();
984 fltParams.sourcePortEnd = target.sourcePortEnd();
985 fltParams.sourcePortStart = target.sourcePortStart();
986 fltParams.destPortEnd = target.destPortEnd();
987 fltParams.destPortStart = target.destPortStart();
988 service.setPortFilter(fltParams, target.callback);
989 });
990 }
mj.qu11d28a82024-12-17 18:09:17 -0800991
qumengjiaca65ef52024-11-06 15:42:21 +0800992 //设定过滤基本信息
993 function setPortFilterBasicFunc() {
994 showLoading();
995 var elems = {};
996 elems.defaultPolicy = target.defaultPolicy();
997 elems.portFilterEnable = target.portFilterEnable();
998 service.setPortFilterBasic(elems, target.callback);
999 }
1000 //清空添加规则输入
1001 function clearFunc() {
1002 target.comment('');
1003 target.selectedMode('None');
1004 target.sourcePortEnd('0');
1005 target.sourcePortStart('0');
1006 target.destPortEnd('0');
1007 target.destPortStart('0');
1008 target.sourceIpv6Address('');
1009 target.sourceIpAddress('');
1010 target.destIpv6Address('');
1011 target.destIpAddress('');
1012 target.macAddress('');
1013 clearValidateMsg();
1014 }
mj.qu11d28a82024-12-17 18:09:17 -08001015
qumengjiaca65ef52024-11-06 15:42:21 +08001016 //检查新增规则是否已经存在
1017 function checkExistFunc() {
1018 target.macAddress(target.macAddress().toUpperCase());
1019 var currIpType = target.ipType().toUpperCase();
1020 var newRule = {
1021 macAddress: target.macAddress(),
1022 destIpAddress: currIpType == "IPV4" ? target.destIpAddress() : target.destIpv6Address(),
1023 sourceIpAddress: currIpType == "IPV4" ? target.sourceIpAddress() : target.sourceIpv6Address(),
1024 destPortRange: target.destPortStart() == '0' ? '' : target.destPortStart() + ' - ' + target.destPortEnd(),
1025 sourcePortRange: target.sourcePortStart() == '0' ? '' : target.sourcePortStart() + ' - ' + target.sourcePortEnd(),
1026 action: target.portFilterAction() == "Drop" ? "filter_drop" : "filter_accept",
1027 protocol: transProtocolValue(target.selectedMode()),
1028 ipType: currIpType
1029 };
1030
1031 var oldRule;
1032 var rules = target.rules();
1033 for (var ki = 0; ki < rules.length; ki++) {
1034 oldRule = {
1035 macAddress: rules[ki].macAddress,
1036 destIpAddress: rules[ki].destIpAddress,
1037 sourceIpAddress: rules[ki].sourceIpAddress,
1038 destPortRange: rules[ki].destPortRange,
1039 sourcePortRange: rules[ki].sourcePortRange,
1040 action: rules[ki].action,
1041 protocol: rules[ki].protocol,
1042 ipType: rules[ki].ipType.toUpperCase()
1043 };
1044
1045 if (_.isEqual(newRule, oldRule)) {
1046 return true;
1047 }
1048 }
1049 return false;
1050 }
mj.qu11d28a82024-12-17 18:09:17 -08001051
qumengjiaca65ef52024-11-06 15:42:21 +08001052 //协议变化事件监听
1053 function protocolChangeHandlerFunc() {
1054 if (target.selectedMode() == PROTOCOLS.ICMP || target.selectedMode() == PROTOCOLS.NONE) {
1055 target.sourcePortEnd('0');
1056 target.sourcePortStart('0');
1057 target.destPortEnd('0');
1058 target.destPortStart('0');
1059 clearValidateMsg('#portRangeArea');
1060 } else {
1061 target.sourcePortEnd('65535');
1062 target.sourcePortStart('1');
1063 target.destPortEnd('65535');
1064 target.destPortStart('1');
1065 }
1066 return true;
1067 }
mj.qu11d28a82024-12-17 18:09:17 -08001068
qumengjiaca65ef52024-11-06 15:42:21 +08001069 //删除规则
1070 function deleteFilterRulesFunc() {
1071 var ids = target.gridTemplate.selectedIds();
1072 if (ids.length == 0) {
1073 showAlert("no_data_selected");
1074 return;
1075 }
1076
1077 showConfirm("confirm_data_effect", function () {
1078 showLoading('deleting');
1079 var rules = {};
1080 rules.indexs = ids;
1081 service.deleteFilterRules(rules, target.callback);
1082 });
1083 }
mj.qu11d28a82024-12-17 18:09:17 -08001084
qumengjiaca65ef52024-11-06 15:42:21 +08001085 }
1086
1087 //获取port filter信息
mj.qu11d28a82024-12-17 18:09:17 -08001088
qumengjiaca65ef52024-11-06 15:42:21 +08001089 function getPortFilter() {
1090 return service.getPortFilter();
1091 }
mj.qu11d28a82024-12-17 18:09:17 -08001092
qumengjiaca65ef52024-11-06 15:42:21 +08001093 //ip类型变化事件监听
1094 function ipTypeChangeHandlerFunc() {
1095 clearValidateMsg();
1096 return true;
1097 }
mj.qu11d28a82024-12-17 18:09:17 -08001098
qumengjiaca65ef52024-11-06 15:42:21 +08001099 //初始化port filter view model
mj.qu11d28a82024-12-17 18:09:17 -08001100
qumengjiaca65ef52024-11-06 15:42:21 +08001101 function initialize(viewModel) {
1102 var vm;
1103 if (viewModel) {
1104 vm = viewModel;
1105 var fltinfo = getPortFilter();
1106 vm.gridTemplate.clearAllChecked();
1107 vm.gridTemplate.data(fltinfo.portFilterRules);
1108 vm.defaultPolicy(fltinfo.defaultPolicy);
1109 vm.oriDefaultPolicy(fltinfo.defaultPolicy);
1110 vm.portFilterEnable(fltinfo.portFilterEnable);
1111 vm.oriPortFilterEnable(fltinfo.portFilterEnable);
1112 vm.rules(fltinfo.portFilterRules);
1113 refreshTableHeight();
1114 $('#portFilters').find('tbody').translate();
1115 renderCheckbox();
1116 $('.notes-content').translate();
1117 return;
1118 }
1119
1120 vm = new PortFilterVM();
1121 var container = $('#container');
1122 ko.cleanNode(container[0]);
1123 ko.applyBindings(vm, container[0]);
1124
1125 fixTableHeight();
1126
1127 $('#filterBasicForm').validate({
1128 submitHandler: function () {
1129 showConfirm("confirm_data_effect", function () {
1130 vm.setPortFilterBasic();
1131 });
1132 }
1133 });
1134
1135 $('#portFilterListForm').validate({
1136 submitHandler: function () {
1137 vm.deleteFilterRules();
1138 }
1139 });
1140
1141 $('#portFilterForm').validate({
1142 submitHandler: function () {
1143 vm.save();
1144 },
1145 rules: {
1146 txtMacAddress: {
1147 filter_optional: true,
1148 mac_check: true
1149 },
1150 txtDestIpAddress: {
1151 ip_check: true
1152 },
1153 txtSourceIpAddress: {
1154 ip_check: true
1155 },
1156 txtSourceIpv6Address: {
1157 ipv6: true
1158 },
1159 txtDestIpv6Address: {
1160 ipv6: true
1161 },
1162 txtDestPortStart: {
1163 digits: true,
1164 range: [1, 65535],
1165 portCompare: "#txtDestPortEnd"
1166 },
1167 txtDestPortEnd: {
1168 digits: true,
1169 range: [1, 65535],
1170 portCompare: "#txtDestPortStart"
1171 },
1172 txtSourcePortStart: {
1173 digits: true,
1174 range: [1, 65535],
1175 portCompare: "#txtSourcePortEnd"
1176 },
1177 txtSourcePortEnd: {
1178 digits: true,
1179 range: [1, 65535],
1180 portCompare: "#txtSourcePortStart"
1181 },
1182
1183 txtComment: {
1184 comment_check: true
1185 }
1186 },
1187 groups: {
1188 destPort: "txtDestPortStart txtDestPortEnd",
1189 sourcePort: "txtSourcePortStart txtSourcePortEnd"
1190 },
1191 errorPlacement: function (error, element) {
1192 if (element.attr("name") == "txtMacAddress") {
1193 error.appendTo("#macErrorDiv");
1194 } else if (element.attr("name") == "txtDestPortStart" || element.attr("name") == "txtDestPortEnd") {
1195 error.appendTo("#destPortErrorDiv");
1196 } else if (element.attr("name") == "txtSourcePortStart" || element.attr("name") == "txtSourcePortEnd") {
1197 error.appendTo("#sourcePortErrorDiv");
1198 } else
1199 error.insertAfter(element);
1200 }
1201 });
1202 }
1203
1204 $.validator.addMethod("filter_optional", function (value, element, param) {
1205 var result = _.any(['#txtMacAddress', '#txtDestIpAddress', '#txtSourceIpAddress', '#txtSourceIpv6Address', '#txtDestIpv6Address'],
1206 function (item) {
1207 var tmp = $(item).val().replace(/\s+/g, '');
1208 return $(item + ':visible').length > 0 && tmp != '';
1209 });
1210
1211 var portResult = _.any(['#txtDestPortStart', '#txtDestPortEnd', '#txtSourcePortStart', '#txtSourcePortEnd'],
1212 function (item) {
1213 return $(item).val() != '0';
1214 });
1215
1216 return result || portResult;
1217 });
1218
1219 return {
1220 init: initialize
1221 };
1222});
1223
1224//家长控制
mj.qu11d28a82024-12-17 18:09:17 -08001225
qumengjiaca65ef52024-11-06 15:42:21 +08001226define("firewall_parental_control","underscore jquery knockout set service".split(" "),
1227 function (_, $, ko, config, service) {
1228
1229 var maxItem = 10;
1230 var pcVm = null;
1231 var PAGES = {
1232 MAIN: 0,
1233 MANAGE: 1,
1234 RULE: 2
1235 };
mj.qu11d28a82024-12-17 18:09:17 -08001236
1237
qumengjiaca65ef52024-11-06 15:42:21 +08001238 function ParentalControlVM() {
1239 var target = this;
1240 var hostNameList = service.getHostNameList({}).devices;
1241 target.currentPage = ko.observable(PAGES.MAIN);
1242 target.pages = PAGES;
1243
1244
1245 target.childGroupList = ko.observable([]);
1246 target.childGroupMac = ko.computed(function () {
1247 return _.map(target.childGroupList(), function (data) {
1248 return data.mac;
1249 });
1250 });
mj.qu11d28a82024-12-17 18:09:17 -08001251
qumengjiaca65ef52024-11-06 15:42:21 +08001252 target.currentUserInChildGroup = ko.observable(true);
1253 //获取儿童组设备列表
mj.qu11d28a82024-12-17 18:09:17 -08001254
qumengjiaca65ef52024-11-06 15:42:21 +08001255 target.fetchChildGroupList = fetchChildGroupListFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001256
qumengjiaca65ef52024-11-06 15:42:21 +08001257 target.fetchChildGroupList();
1258
1259 target.manageHandler = manageHandlerFunc;
1260 function manageHandlerFunc() {
1261 target.currentPage(PAGES.MANAGE);
1262 target.fetchAttachedDevices();
1263 }
1264 target.attachedDevices = ko.observable([]);
1265 //获取已连接设备列表
mj.qu11d28a82024-12-17 18:09:17 -08001266
qumengjiaca65ef52024-11-06 15:42:21 +08001267 target.fetchAttachedDevices = fetchAttachedDevicesFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001268
qumengjiaca65ef52024-11-06 15:42:21 +08001269
1270 //儿童组设备 标签按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001271
qumengjiaca65ef52024-11-06 15:42:21 +08001272 target.backToMainHandler = backToMainHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001273
1274
qumengjiaca65ef52024-11-06 15:42:21 +08001275 ko.computed(function () {
1276 target.attachedDevices();
1277 target.childGroupList();
1278 $("#pc_children_group_form").translate();
1279 }).extend({
1280 notify: 'always',
1281 throttle: 300
1282 });
mj.qu11d28a82024-12-17 18:09:17 -08001283
qumengjiaca65ef52024-11-06 15:42:21 +08001284 //添加至儿童组
mj.qu11d28a82024-12-17 18:09:17 -08001285
qumengjiaca65ef52024-11-06 15:42:21 +08001286 function addChildGroupFun(flag, eleData) {
1287 showLoading();
1288 service.addChildGroup(eleData, function (data) {
1289 target.fetchChildGroupList(function () {
1290 target.fetchAttachedDevices(function () {
1291 hideLoading();
1292 if (flag) {
1293 service.logout({}, function () {
1294 window.location = 'index.html';
1295 });
1296 }
1297 });
1298 });
1299 }, function (data) {
1300 errorOverlay();
1301 });
1302 }
mj.qu11d28a82024-12-17 18:09:17 -08001303
qumengjiaca65ef52024-11-06 15:42:21 +08001304 //移除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001305
qumengjiaca65ef52024-11-06 15:42:21 +08001306 target.removeChildGroupHandler = removeChildGroupHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001307
1308
qumengjiaca65ef52024-11-06 15:42:21 +08001309 //添加按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001310
qumengjiaca65ef52024-11-06 15:42:21 +08001311 target.addChildGroupHandler = addChildGroupHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001312
qumengjiaca65ef52024-11-06 15:42:21 +08001313
1314 target.dealElement = dealElementFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001315
1316
1317
qumengjiaca65ef52024-11-06 15:42:21 +08001318 //取消编辑主机名按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001319
qumengjiaca65ef52024-11-06 15:42:21 +08001320 target.cancelEditHostNameHandler = cancelEditHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001321
qumengjiaca65ef52024-11-06 15:42:21 +08001322 //主机名编辑保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001323
qumengjiaca65ef52024-11-06 15:42:21 +08001324 target.saveHostNameHandler = saveHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001325
qumengjiaca65ef52024-11-06 15:42:21 +08001326 //主机名编辑按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001327
qumengjiaca65ef52024-11-06 15:42:21 +08001328 target.editHostNameHandler = editHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001329
1330
qumengjiaca65ef52024-11-06 15:42:21 +08001331 target.selectedIds = ko.observableArray([]);
1332 target.siteList = ko.observable([]);
1333 /////////////////////////////////////////////////////////////////
1334 target.disableAdd = ko.computed(function () {
1335 return target.siteList().length == maxItem;
1336 });
mj.qu11d28a82024-12-17 18:09:17 -08001337
qumengjiaca65ef52024-11-06 15:42:21 +08001338 ko.computed(function () {
1339 target.siteList();
1340 target.selectedIds();
1341 setTimeout(function () {
1342 renderCheckbox();
1343 }, 100);
1344 $("#pc_site_white_list_form").translate();
1345 });
mj.qu11d28a82024-12-17 18:09:17 -08001346
qumengjiaca65ef52024-11-06 15:42:21 +08001347 //网站白名单添加按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001348
qumengjiaca65ef52024-11-06 15:42:21 +08001349 target.openAddSitePopoverHandler = openAddSitePopoverHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001350
qumengjiaca65ef52024-11-06 15:42:21 +08001351 //网站白名单列表选择框点击事件
mj.qu11d28a82024-12-17 18:09:17 -08001352
qumengjiaca65ef52024-11-06 15:42:21 +08001353 target.checkboxClickHandler = checkboxClickHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001354
qumengjiaca65ef52024-11-06 15:42:21 +08001355 //获取网站白名单列表
mj.qu11d28a82024-12-17 18:09:17 -08001356
qumengjiaca65ef52024-11-06 15:42:21 +08001357 target.fetchSiteWhiteList = fetchSiteWhiteListFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001358
qumengjiaca65ef52024-11-06 15:42:21 +08001359 //网站白名单删除函数
mj.qu11d28a82024-12-17 18:09:17 -08001360
qumengjiaca65ef52024-11-06 15:42:21 +08001361 function removeSiteWhiteItem(ids) {
1362 showConfirm('confirm_data_delete', function () {
1363 showLoading();
1364 service.removeSiteWhite({
1365 ids: ids
1366 }, function (data) {
1367 target.fetchSiteWhiteList(function () {
1368 successOverlay();
1369 });
1370 }, function (data) {
1371 target.fetchSiteWhiteList(function () {
1372 errorOverlay();
1373 });
1374 });
1375 });
1376 }
1377 //网站白名单删除所有按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001378
qumengjiaca65ef52024-11-06 15:42:21 +08001379 target.removeAllWhiteSite = removeAllWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001380
qumengjiaca65ef52024-11-06 15:42:21 +08001381 //网站白名单删除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001382
qumengjiaca65ef52024-11-06 15:42:21 +08001383 target.removeSelectedWhiteSite = removeSelectedWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001384
qumengjiaca65ef52024-11-06 15:42:21 +08001385 //网站白名单移除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001386
qumengjiaca65ef52024-11-06 15:42:21 +08001387 target.removeWhiteSite = removeWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001388
1389
1390
qumengjiaca65ef52024-11-06 15:42:21 +08001391 //网站白名单添加框保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001392
qumengjiaca65ef52024-11-06 15:42:21 +08001393 target.saveSiteWhite = saveSiteWhiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001394
qumengjiaca65ef52024-11-06 15:42:21 +08001395 //////////////////////////////////////////////////////////////////
1396 target.notSave = ko.observable(false);
1397 //获取时间限制信息
mj.qu11d28a82024-12-17 18:09:17 -08001398
qumengjiaca65ef52024-11-06 15:42:21 +08001399 target.fetchTimeLimited = fetchTimeLimitedFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001400
1401
qumengjiaca65ef52024-11-06 15:42:21 +08001402 //上网时间设置时间表格事件绑定
mj.qu11d28a82024-12-17 18:09:17 -08001403
qumengjiaca65ef52024-11-06 15:42:21 +08001404 target.bindEvent = bindEventFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001405
qumengjiaca65ef52024-11-06 15:42:21 +08001406 //上网时间设置保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001407
qumengjiaca65ef52024-11-06 15:42:21 +08001408 target.saveTimeLimitedHandler = saveTimeLimitedHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001409
qumengjiaca65ef52024-11-06 15:42:21 +08001410 //////////////////////////////////////////////////////////////////
1411 var isBinded = false;
1412 //上网规则标签点击事件
mj.qu11d28a82024-12-17 18:09:17 -08001413
qumengjiaca65ef52024-11-06 15:42:21 +08001414 target.openRulePage = openRulePageFunc;
1415 function openRulePageFunc() {
1416 if (target.currentPage() == PAGES.RULE) {
1417 return;
1418 }
1419 target.currentPage(PAGES.RULE);
1420 target.currentUserInChildGroup(service.checkCurrentUserInChildGroup().result);
1421 initTableData();
1422 if (!isBinded) {
1423 if (!target.currentUserInChildGroup()) {
1424 target.bindEvent();
1425 }
1426 isBinded = true;
1427 }
1428 showLoading();
1429 target.fetchTimeLimited();
1430 target.fetchSiteWhiteList(function () {
1431 hideLoading();
1432 });
1433 }
mj.qu11d28a82024-12-17 18:09:17 -08001434
qumengjiaca65ef52024-11-06 15:42:21 +08001435 //获取儿童组设备列表
1436 function fetchChildGroupListFunc(cb) {
1437 service.childGroupList({}, function (data) {
1438 target.currentUserInChildGroup(service.checkCurrentUserInChildGroup(data.devices).result);
1439 target.childGroupList([]);
1440 _.map(data.devices, function (elem, idx) {
1441 elem.idx = idx;
1442 elem.hostname = pcUtil.getHostName(elem.hostname, elem.mac, hostNameList);
1443 });
1444 target.childGroupList(data.devices);
1445 if (_.isFunction(cb)) {
1446 cb.apply(this);
1447 }
1448 });
1449 }
mj.qu11d28a82024-12-17 18:09:17 -08001450
qumengjiaca65ef52024-11-06 15:42:21 +08001451 //获取已连接设备列表
1452 function fetchAttachedDevicesFunc(cb) {
1453 target.attachedDevices([]);
1454 var counter = 0;
1455 var currDevices = [];
1456 //RJ45 已连接设备
1457 service.getAttachedCableDevices({}, function (data) {
1458 counter++;
1459 var devs = _.map(data.attachedDevices, function (elem) {
1460 elem.idx = _.uniqueId('wireless_');
1461 elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
1462 elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
1463 return elem;
1464 });
1465 if (counter != 1) {
1466 target.attachedDevices(_.flatten([currDevices, devs]));
1467 if (_.isFunction(cb)) {
1468 cb.apply(this);
1469 }
1470 } else {
1471 currDevices = devs;
1472 }
1473 });
mj.qu11d28a82024-12-17 18:09:17 -08001474
qumengjiaca65ef52024-11-06 15:42:21 +08001475 //wifi 已连接设备
1476 service.getCurrentlyAttachedDevicesInfo({}, function (data) {
1477 counter++;
1478 var devs = _.map(data.attachedDevices, function (elem) {
1479 elem.idx = _.uniqueId('wireless_');
1480 elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
1481 elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
1482 return elem;
1483 });
1484 if (counter != 1) {
1485 target.attachedDevices(_.flatten([currDevices, devs]));
1486 if (_.isFunction(cb)) {
1487 cb.apply(this);
1488 }
1489 } else {
1490 currDevices = devs;
1491 }
1492 });
1493 }
1494 //儿童组设备 标签按钮事件
1495 function backToMainHandlerFunc() {
1496 target.currentPage(PAGES.MAIN);
1497 }
mj.qu11d28a82024-12-17 18:09:17 -08001498
qumengjiaca65ef52024-11-06 15:42:21 +08001499 //移除按钮事件
1500 function removeChildGroupHandlerFunc(ele) {
1501 showLoading();
1502 service.removeChildGroup(ele, function (data) {
1503 target.fetchChildGroupList(function () {
1504 target.fetchAttachedDevices(function () {
1505 hideLoading();
1506 });
1507 });
1508 }, function (data) {
1509 errorOverlay();
1510 });
1511 }
mj.qu11d28a82024-12-17 18:09:17 -08001512
qumengjiaca65ef52024-11-06 15:42:21 +08001513 //添加按钮事件
1514 function addChildGroupHandlerFunc(data) {
1515 var uMacAddr = service.getCurretnMAC();
1516 if (uMacAddr != data.macAddress) {
1517 addChildGroupFun(false, data);
1518 } else {
1519 showConfirm("parental_add_self", function () {
1520 addChildGroupFun(true, data);
1521 })
1522 }
1523 }
mj.qu11d28a82024-12-17 18:09:17 -08001524
qumengjiaca65ef52024-11-06 15:42:21 +08001525 //取消编辑主机名按钮事件
1526 function cancelEditHostNameHandlerFunc(eleData) {
1527 target.dealElement(false, eleData.idx);
1528 }
mj.qu11d28a82024-12-17 18:09:17 -08001529
qumengjiaca65ef52024-11-06 15:42:21 +08001530 //主机名编辑保存按钮事件
1531 function saveHostNameHandlerFunc(ele) {
1532 var $hostInput = $("#hostname_input_" + ele.idx);
1533 var hostname = $.trim($hostInput.val());
1534 if (hostname.indexOf(" ") == 0 || hostname.lastIndexOf(" ") == (hostname.length - 1) || /[\*\+\$\[&:,;<>'"\\`\]¥]{1,32}/.test(hostname)) {
1535 showAlert('modify_hostname_invalid');
1536 return false;
1537 }else if (hostname == '') {
1538 $(".promptErrorLabel", "#confirm-message-container").text($.i18n.prop("required"));
1539 var $closestTD = $hostInput.closest('td').addClass('has-error');
1540 addTimeout(function () {
1541 $closestTD.removeClass('has-error');
1542 }, 5000);
1543 showAlert('required');
1544 return false;
1545 }
1546 showLoading();
1547 ele.hostname = hostname;
1548 service.editHostName(ele, function () {
1549 service.getHostNameList({}, function (hostNameData) {
1550 hostNameList = hostNameData.devices;
1551 target.fetchChildGroupList(function () {
1552 hideLoading();
1553 });
1554 target.fetchAttachedDevices();
1555 });
1556 }, function () {
1557 errorOverlay();
1558 });
1559 }
mj.qu11d28a82024-12-17 18:09:17 -08001560
qumengjiaca65ef52024-11-06 15:42:21 +08001561 //主机名编辑按钮事件
1562 function editHostNameHandlerFunc(ele) {
1563 $("#hostname_input_" + ele.idx).val(ele.hostname);
1564 target.dealElement(true, ele.idx);
1565 return false;
1566 }
1567 //网站白名单添加按钮事件
1568 function openAddSitePopoverHandlerFunc() {
1569 var addNewSiteTmpl = $("#addNewSiteTmpl").html();
1570 popover.open({
1571 target: $("#openAddSiteBtn"),
1572 html: addNewSiteTmpl,
1573 width: "300px",
1574 validation: addValidation
1575 });
1576 }
mj.qu11d28a82024-12-17 18:09:17 -08001577
qumengjiaca65ef52024-11-06 15:42:21 +08001578 //网站白名单列表选择框点击事件
1579 function checkboxClickHandlerFunc(eleData, evt) {
1580 addTimeout(function () {
1581 target.selectedIds(getSelectedValues());
1582 }, 100);
1583 }
1584 //获取网站白名单列表
1585 function fetchSiteWhiteListFunc(cb) {
1586 service.getSiteWhiteList({}, function (eledata) {
1587 target.selectedIds([]);
1588 target.siteList(eledata.siteList);
1589 _.isFunction(cb) && cb.apply(this);
1590 }, function () {
1591 target.siteList([]);
1592 _.isFunction(cb) && cb.apply(this);
1593 });
1594 }
mj.qu11d28a82024-12-17 18:09:17 -08001595
qumengjiaca65ef52024-11-06 15:42:21 +08001596 //网站白名单删除所有按钮事件
1597 function removeAllWhiteSiteFunc() {
1598 removeSiteWhiteItem(getAllCheckboxValues());
1599 }
1600 //网站白名单删除按钮事件
1601 function removeSelectedWhiteSiteFunc() {
1602 removeSiteWhiteItem(getSelectedValues());
1603 }
1604 //网站白名单移除按钮事件
1605 function removeWhiteSiteFunc(ele, evt) {
1606 removeSiteWhiteItem([ele.id]);
1607 }
mj.qu11d28a82024-12-17 18:09:17 -08001608
qumengjiaca65ef52024-11-06 15:42:21 +08001609 //网站白名单添加框保存按钮事件
1610 function saveSiteWhiteFunc(name, site) {
1611 popover.hide();
1612 var matched = _.find(target.siteList(), function (one) {
1613 return one.site == site;
1614 });
1615 if (matched) {
1616 showAlert("pc_link_exist", function () {
1617 setTimeout(function () {
1618 popover.show();
1619 }, 200);
1620 });
1621 return false;
1622 }
1623
1624 showLoading();
1625 service.saveSiteWhite({
1626 name: name,
1627 site: site
1628 }, function () {
1629 target.fetchSiteWhiteList(function () {
1630 popover.close();
1631 successOverlay();
1632 });
1633 }, function () {
1634 target.fetchSiteWhiteList(function () {
1635 errorOverlay();
1636 popover.show();
1637 });
1638 });
1639 }
mj.qu11d28a82024-12-17 18:09:17 -08001640
qumengjiaca65ef52024-11-06 15:42:21 +08001641 //上网时间设置时间表格事件绑定
1642 function bindEventFunc() {
1643 $("td:not('.col-head')", "#pc_time_limited_tbody").addClass('cursorhand').die().click(function () {
1644 target.notSave(true);
1645 $(this).toggleClass('active');
1646 }).hover(function () {
1647 var $this = $(this);
1648 var w = $this.data('week');
1649 var h = $this.data('hour');
1650 $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").addClass('time_td_hover');
1651 $("#col_" + h).addClass('time_td_hover');
1652 if ($this.not('.active')) {
1653 $this.addClass('time_td_hover');
1654 }
1655 }, function () {
1656 var $this = $(this);
1657 var w = $this.data('week');
1658 var h = $this.data('hour');
1659 $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").removeClass('time_td_hover');
1660 $("#col_" + h).removeClass('time_td_hover');
1661 $this.removeClass('time_td_hover');
1662 });
1663 }
mj.qu11d28a82024-12-17 18:09:17 -08001664
qumengjiaca65ef52024-11-06 15:42:21 +08001665 //上网时间设置保存按钮事件
1666 function saveTimeLimitedHandlerFunc() {
1667 showLoading();
1668 var tds = getSelectedTds();
1669 var timeStr = getSavedData(tds);
1670 service.saveTimeLimited({
1671 time: timeStr
1672 }, function () {
1673 target.notSave(false);
1674 successOverlay();
1675 }, function () {
1676 errorOverlay();
1677 });
1678 }
mj.qu11d28a82024-12-17 18:09:17 -08001679
qumengjiaca65ef52024-11-06 15:42:21 +08001680 }
mj.qu11d28a82024-12-17 18:09:17 -08001681
qumengjiaca65ef52024-11-06 15:42:21 +08001682 function dealElementFunc(flag, idx) {
1683 if (flag == false) {
1684 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).show();
1685 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).hide();
1686 } else {
1687 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).hide();
1688 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).show();
1689 }
1690 }
1691
1692 //获取时间限制信息
1693 function fetchTimeLimitedFunc() {
1694 service.getTimeLimited({}, function (ele) {
1695 for (var ki in ele) {
1696 for (var idx = 0; idx < ele[ki].length; idx++) {
1697 var id = 'td_' + ki + '_' + ele[ki][idx];
1698 $("#" + id).addClass('active');
1699 }
1700 }
1701 }, function () {});
1702 }
1703
1704 var pcUtil = {
1705 getHostName: function (hostName, mac, hostNameList) {
1706 var ele = _.find(hostNameList, function (ele) {
1707 return ele.mac == mac;
1708 });
1709 return ele ? ele.hostname : hostName;
1710 }
1711 };
1712 function getCheckboxValues(flag) {
1713 var selectedValues = [];
1714 $(":checkbox" + (flag ? ":checked" : ""), "#pb_white_list").each(function (i, n) {
1715 selectedValues.push(n.value)
1716 });
1717 return selectedValues;
1718 }
1719 //获取列表中被选中项的value值
mj.qu11d28a82024-12-17 18:09:17 -08001720
qumengjiaca65ef52024-11-06 15:42:21 +08001721 function getSelectedValues() {
1722 return getCheckboxValues(true);
1723 }
1724 function getAllCheckboxValues() {
1725 return getCheckboxValues(false);
1726 }
mj.qu11d28a82024-12-17 18:09:17 -08001727
qumengjiaca65ef52024-11-06 15:42:21 +08001728 //增加网站白名单表单提交函数绑定和校验规则设置
mj.qu11d28a82024-12-17 18:09:17 -08001729
qumengjiaca65ef52024-11-06 15:42:21 +08001730 function addValidation() {
1731 $('#whiteSiteAddForm').validate({
1732 submitHandler: function () {
1733 var name = $("#siteName").val();
1734 var site = $("#siteLink").val();
1735 pcVm.saveSiteWhite(name, site);
1736 },
1737 rules: {
1738 siteName: 'siteName_check',
1739 siteLink: 'siteLink_check'
1740 }
1741 });
1742 }
mj.qu11d28a82024-12-17 18:09:17 -08001743
qumengjiaca65ef52024-11-06 15:42:21 +08001744 function getSavedData(timeDatas) {
1745 var ret = '';
1746 for (var ki in timeDatas) {
1747 var hours = _.sortBy(timeDatas[ki], function (n) {
1748 return n;
1749 });
1750 if (timeDatas[ki].length) {
1751 ret += ki + '+';
1752 ret += hours.join(',');
1753 ret += ';'
1754 }
1755 }
1756 return ret.substring(0, ret.length - 1);
1757 }
1758 //获取时间表格选中的时间
mj.qu11d28a82024-12-17 18:09:17 -08001759
qumengjiaca65ef52024-11-06 15:42:21 +08001760 function getSelectedTds() {
1761 var defaultValue = {
1762 '0': [],
1763 '1': [],
1764 '2': [],
1765 '3': [],
1766 '4': [],
1767 '5': [],
1768 '6': []
1769 };
1770 $("td.active", "#pc_time_limited_tbody").each(function (i, n) {
1771 var $this = $(n);
1772 var week = $this.data('week');
1773 var hour = $this.data('hour');
1774 defaultValue[week].push(hour);
1775 });
1776 return defaultValue;
1777 }
1778
1779 function convertHour(hour) {
1780 if (hour <= 16) {
1781 return hour + 7;
1782 } else {
1783 return hour - 17;
1784 }
1785 }
1786 //初始化时间表格
mj.qu11d28a82024-12-17 18:09:17 -08001787
qumengjiaca65ef52024-11-06 15:42:21 +08001788 function initTableData() {
1789 $("tr", "#pc_time_limited_tbody").each(function (idx, n) {
1790 var $tr = $(n);
1791 $("td:not(:first)", $tr).each(function (j, m) {
1792 var $td = $(m);
1793 var hour = convertHour(j);
1794 $td.attr({
1795 id: 'td_' + idx + '_' + hour
1796 }).data({
1797 week: idx,
1798 hour: hour
1799 });
1800 });
1801 });
1802 $("td.active", "#pc_time_limited_tbody").removeClass("active");
1803 $("thead td:not(:first)", "#pc_time_limited_form").each(function (idx, n) {
1804 var hour = convertHour(idx);
1805 $(n).attr({
1806 id: 'col_' + hour
1807 });
1808 });
1809 pcVm.notSave(false);
1810 }
1811
mj.qu11d28a82024-12-17 18:09:17 -08001812
qumengjiaca65ef52024-11-06 15:42:21 +08001813 //页面初始化
mj.qu11d28a82024-12-17 18:09:17 -08001814
qumengjiaca65ef52024-11-06 15:42:21 +08001815 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -08001816
qumengjiaca65ef52024-11-06 15:42:21 +08001817 pcVm = new ParentalControlVM();
1818 bindContainer(pcVm);
1819 }
1820 function bindContainer(pcVm)
1821 {
1822 var container = $('#container');
1823 ko.cleanNode(container[0]);
1824 ko.applyBindings(pcVm, container[0]);
1825 }
1826
1827 return {
1828 init: initialize
1829 };
1830});
1831
1832define("firewall_dmz_set","underscore jquery knockout set service".split(" "),
1833 function ( _, $, ko, config, service) {
1834
1835 //system dmz setting VM
mj.qu11d28a82024-12-17 18:09:17 -08001836
qumengjiaca65ef52024-11-06 15:42:21 +08001837 function DmzSettingVM() {
1838 var target = this;
1839 var dmzInfo = getDmzSetting();
1840 target.dmzSetting = ko.observable(dmzInfo.dmzSetting);
1841 target.ipAddress = ko.observable(dmzInfo.ipAddress);
1842 target.isDataCard = config.PRODUCT_TYPE == 'DATACARD';
1843
1844 target.clear = clearFunc;
1845 //应用按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001846
qumengjiaca65ef52024-11-06 15:42:21 +08001847 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001848
qumengjiaca65ef52024-11-06 15:42:21 +08001849 function saveFunc() {
1850 showLoading();
1851 var params = {};
1852 params.dmzSetting = target.dmzSetting();
1853 params.ipAddress = target.ipAddress();
1854 service.setDmzSetting(params, function (result) {
1855 if (result.result != "success") {
1856 errorOverlay();
1857 } else {
1858 target.clear();
1859 successOverlay();
1860 }
1861 });
1862 }
mj.qu11d28a82024-12-17 18:09:17 -08001863
qumengjiaca65ef52024-11-06 15:42:21 +08001864 }
mj.qu11d28a82024-12-17 18:09:17 -08001865
qumengjiaca65ef52024-11-06 15:42:21 +08001866 function clearFunc() {
1867 initialize();
1868 }
mj.qu11d28a82024-12-17 18:09:17 -08001869
1870
qumengjiaca65ef52024-11-06 15:42:21 +08001871 //获取dmz 信息
mj.qu11d28a82024-12-17 18:09:17 -08001872
qumengjiaca65ef52024-11-06 15:42:21 +08001873 function getDmzSetting() {
1874 return service.getDmzSetting();
1875 }
1876
1877 //初始化DmzSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -08001878
qumengjiaca65ef52024-11-06 15:42:21 +08001879 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -08001880
qumengjiaca65ef52024-11-06 15:42:21 +08001881 var dmzVm = new DmzSettingVM();
1882 bindContainer(dmzVm);
1883 }
1884 function bindContainer(dmzVm){
1885 var container = $('#container');
1886 ko.cleanNode(container[0]);
1887 ko.applyBindings(dmzVm, container[0]);
1888 $('#dmzSettingForm').validate({
1889 submitHandler: function () {
1890 dmzVm.save();
1891 },
1892 rules: {
1893 txtIpAddress: 'dmz_ip_check'
1894 }
1895 });
1896 }
1897
1898 return {
1899 init: initialize
1900 };
1901});
1902
1903define("firewall","underscore jquery knockout set service".split(" "),
1904
1905function(_, $, ko, config, service) {
1906
1907 function FirewallVM() {
1908 var target = this;
1909 target.hasDdns = config.DDNS_SUPPORT;
1910 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1911 target.hasUrlFilter = config.HAS_URL;
1912 target.hasUssd = config.HAS_USSD;
1913 target.hasUpnp = config.HAS_UPNP;
1914 }
1915
1916 function initialize() {
1917 var fwVm = new FirewallVM();
1918 bindingContainer(fwVm);
1919 }
1920 function bindingContainer(fwVm)
1921 {
1922 var container = $('#container');
1923 ko.cleanNode(container[0]);
1924 ko.applyBindings(fwVm, container[0]);
1925 }
1926 return {
1927 init : initialize
1928 };
1929});
1930
1931define("ddns","underscore jquery knockout set service".split(" "), function (_, $, ko, config, service) {
1932 var ddnsSetModes = _.map(config.DDNSSetMode, newOption);
1933 var ddnsProviderList = _.map(config.DDNSDDP, newOption);
1934 var ddns_mode_select = _.map(config.ddns_Modeselect, newOption);
1935 function newOption(optItem) {
1936 return new Option(optItem.name, optItem.value);
1937 }
1938 function DdnsViewModel() {
1939 var target = this;
1940 target.hasUssd = config.HAS_USSD;
1941 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1942 var data = service.getDdnsParams();
1943 target.ddnsSetModes = ko.observableArray(ddnsSetModes);
1944 target.ddnsProviderList = ko.observableArray(ddnsProviderList);
1945 target.ddns_mode_select = ko.observableArray(ddns_mode_select);
1946 target.currentMode = ko.observable(data.DDNS_Enable);
1947 target.currentModeselect = ko.observable(data.DDNS_Mode);
1948 target.currentProviderList = ko.observable("dyndns.org");
1949 $.each(config.DDNSDDP, function (i, n) {
1950 if (data.DDNSProvider == n.value) {
1951 target.currentProviderList(data.DDNSProvider);
1952 }
1953 });
1954 target.DDNSaccount = ko.observable(data.DDNSAccount);
1955 target.DDNSpasswd = ko.observable(data.DDNSPassword);
1956 target.DDNSname = ko.observable(data.DDNS);
1957 target.DDNS_HashValue = ko.observable(data.DDNS_Hash_Value);
1958 target.isddnsStatusTrans = ko.observable();
1959 target.isEnableSet = ko.observable();
1960 target.isHashValue = ko.observable();
1961 target.isddnsaccount = ko.observable();
1962 target.isddnspasswd = ko.observable();
1963 target.isDDNSStatus = ko.observable();
1964 target.isddnsdomainName = ko.observable();
1965 target.isNone = ko.observable();
1966 target.onStates = ko.observable();
1967 target.showPassword_ddns = ko.observable(false);
1968 target.showPasswordHandler_ddns = showPasswordHandler_ddns;
1969 changeddnsProviderList();
1970 target.changeDdnsProvider = changeDdnsProviderFunc;
1971 changeSetDdnsMode();
1972 target.changeSetDdnsMode = changeSetDdnsModeFunc;
1973 updateScanDdnsStatus();
1974 target.apply = applyFunc;
1975 function updateScanDdnsStatus() {
1976 var trans = "";
1977 $.getJSON("/reqproc/proc_get", {
1978 cmd: "getddns_status",
1979 "_": new Date().getTime()
1980 }, function (data) {
1981 if (data.getddns_status == "0") {
1982 trans = "register successful";
1983 target.onStates(true);
1984 } else if (data.getddns_status == "1") {
1985 trans = "login error";
1986 target.onStates(true);
1987 } else if (data.getddns_status == "2") {
1988 trans = "network error";
1989 target.onStates(true);
1990 } else if (data.getddns_status == "3") {
1991 trans = "registering";
1992 target.onStates(true);
1993 } else if (data.getddns_status == "4") {
1994 trans = "not registered";
1995 target.onStates(true);
1996 } else if (data.getddns_status == "5") {
1997 trans = "error registering";
1998 target.onStates(true);
1999 } else if (data.getddns_status == "-1") {
2000 trans = "";
2001 target.onStates(true);
2002 }
2003 target.isddnsStatusTrans($.i18n.prop(trans));
2004 addTimeout(updateScanDdnsStatus, 2000);
2005 });
2006 }
2007 function changeSetDdnsMode() {
2008 if (target.currentMode() != "1") {
2009 target.isEnableSet(false);
2010 } else {
2011 target.isEnableSet(true);
2012 }
2013 return true;
2014 }
2015 function changeSetDdnsModeFunc() {
2016 changeSetDdnsMode();
2017 }
2018 function showPasswordHandler_ddns() {
2019 $("#ddns_secretcode_input").parent().find(".error").hide();
2020 var checkbox = $("#showPassword_ddns:checked");
2021 if (checkbox && checkbox.length == 0) {
2022 target.showPassword_ddns(true);
2023 } else {
2024 target.showPassword_ddns(false);
2025 }
2026 }
2027 function changeDdnsProviderFunc() {
2028 if (data.DDNSProvider != target.currentProviderList()) {
2029 target.DDNSaccount("");
2030 target.DDNSpasswd("");
2031 target.DDNSname("");
2032 } else {
2033 target.DDNSaccount(data.DDNSAccount);
2034 target.DDNSpasswd(data.DDNSPassword);
2035 target.DDNSname(data.DDNS);
2036 }
2037 changeddnsProviderList();
2038 }
2039 function changeddnsProviderList() {
2040 if (target.currentProviderList() != "none") {
2041 target.isddnsaccount(true);
2042 target.isddnspasswd(true);
2043 target.isddnsdomainName(true);
2044 target.isHashValue(true);
2045 target.isDDNSStatus(true);
2046 } else {
2047 target.isddnsaccount(false);
2048 target.isddnspasswd(false);
2049 target.isddnsdomainName(false);
2050 target.isHashValue(false);
2051 target.isDDNSStatus(false);
2052 }
2053 if (target.currentProviderList() != "freedns.afraid.org") {
2054 target.isHashValue(false);
2055 } else {
2056 target.isHashValue(true);
2057 }
2058 return true;
2059 }
2060 function applyFunc() {
2061 showLoading();
2062 var params = {};
2063 params.goformId = "DDNS";
2064 params.DDNS_Enable = target.currentMode();
2065 if (target.currentMode() == "1") {
2066 params.DDNS_Mode = target.currentModeselect();
2067 params.DDNSProvider = target.currentProviderList();
2068 if (target.currentProviderList() != "none") {
2069 params.DDNS = target.DDNSname();
2070 params.DDNSPassword = target.DDNSpasswd();
2071 params.DDNSAccount = target.DDNSaccount();
2072 }
2073 if (target.currentProviderList() == "freedns.afraid.org") {
2074 params.DDNS_Hash_Value = target.DDNS_HashValue();
2075 }
2076 }
2077 service.setDDNSForward(params, function (result) {
2078 if (result.result == "success") {
2079 successOverlay();
2080 data = service.getDdnsParams();
2081 } else {
2082 errorOverlay();
2083 }
2084 });
2085 }
2086 }
2087 function initialize() {
2088 var container = $('#container');
2089 ko.cleanNode(container[0]);
2090 var vm = new DdnsViewModel();
2091 ko.applyBindings(vm, container[0]);
2092 $("#ddnsForm").validate({
2093 submitHandler: function () {
2094 vm.apply();
2095 },
2096 rules: {
2097 ddns_secretcode_input: "secretcode_check",
2098 DDNS_Hash_Value: "ddns_hashvalue_check",
2099 ddns_secretcode_inputshow: "secretcode_check"
2100 },
2101 errorPlacement: function (error, element) {
2102 var id = element.attr("id");
2103 if (id == "ddns_secretcode_input" || id == "ddns_secretcode_inputshow") {
2104 error.insertAfter("#lblShowPassword");
2105 } else {
2106 error.insertAfter(element);
2107 }
2108 }
2109 });
2110 }
2111 return {
2112 init: initialize
2113 };
2114});
2115
2116
2117//选网模块
mj.qu11d28a82024-12-17 18:09:17 -08002118
qumengjiaca65ef52024-11-06 15:42:21 +08002119define("network_net_select","underscore jquery knockout set service".split(" "),
2120 function (_, $, ko, config, service) {
2121
2122 var selectModes = _.map(config.AUTO_MODES, function (item) {
2123 return new Option(item.name, item.value);
2124 });
2125
2126 //选网功能view model
mj.qu11d28a82024-12-17 18:09:17 -08002127
qumengjiaca65ef52024-11-06 15:42:21 +08002128 function NetSelectVM() {
2129 var target = this;
2130
2131 target.networkList = ko.observableArray([]);
2132 target.selectNetwork = ko.observable('');
2133 target.enableFlag = ko.observable(true);
2134 target.types = ko.observableArray(selectModes);
2135 target.selectedType = ko.observable();
2136 target.selectMode = ko.observable();
2137
2138 target.networkText = networkTextFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002139
qumengjiaca65ef52024-11-06 15:42:21 +08002140 target.networkStatusId = networkStatusIdFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002141
qumengjiaca65ef52024-11-06 15:42:21 +08002142 target.networkStatus = networkStatusFunc;
2143
2144 target.subnetworkType = subnetworkTypeFunc;
2145
2146 target.networkType = networkTypeFunc;
2147
2148 target.operatorName = operatorNameFunc;
2149
2150 target.networkValue = networkValueFunc;
2151
2152 target.networkTypeId = networkTypeIdFunc;
2153
2154 target.subnetTypeId = subnetTypeIdFunc;
2155 //手动搜网.
mj.qu11d28a82024-12-17 18:09:17 -08002156
qumengjiaca65ef52024-11-06 15:42:21 +08002157 target.search = searchFunc;
2158
2159 //自动选网时设置网络模式.
mj.qu11d28a82024-12-17 18:09:17 -08002160
qumengjiaca65ef52024-11-06 15:42:21 +08002161 target.save = saveFunc;
2162
2163 target.checkEnable = checkEnableFunc;
2164
2165 //注册选择的网络.
mj.qu11d28a82024-12-17 18:09:17 -08002166
qumengjiaca65ef52024-11-06 15:42:21 +08002167 target.register = registerFunc;
2168
2169 //init data
2170 target.checkEnable();
2171 var info = getNetSelectInfo();
2172 if ("manual_select" == info.net_select_mode || "manual_select" == info.m_netselect_save) {
2173 target.selectMode("manual_select");
2174 } else {
2175 target.selectMode("auto_select");
2176 }
2177
2178 target.selectedType(info.net_select);
mj.qu11d28a82024-12-17 18:09:17 -08002179
qumengjiaca65ef52024-11-06 15:42:21 +08002180 //注册选择的网络.
2181 function registerFunc() {
2182 showLoading('registering_net');
2183 var networkToSet = target.selectNetwork().split(',');
2184 service.setNetwork(networkToSet[0], parseInt(networkToSet[1]), parseInt(networkToSet[2]), function (result) {
2185 if (result) {
2186 target.networkList([]);
2187 var autoType = getNetSelectInfo();
2188 target.selectedType(autoType.net_select);
2189 successOverlay();
2190 } else {
2191 errorOverlay();
2192 }
2193 });
2194 }
mj.qu11d28a82024-12-17 18:09:17 -08002195
qumengjiaca65ef52024-11-06 15:42:21 +08002196 function checkEnableFunc() {
2197 var status = service.getStatusInfo();
2198 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
2199 target.enableFlag(false);
2200 } else {
2201 target.enableFlag(true);
2202 }
2203 }
mj.qu11d28a82024-12-17 18:09:17 -08002204
qumengjiaca65ef52024-11-06 15:42:21 +08002205 //自动选网时设置网络模式.
2206 function saveFunc() {
2207 showLoading();
2208
2209 //AutoSelect call SetBearerPreference
2210 var params = {};
2211 params.strBearerPreference = target.selectedType();
2212 service.setBearerPreference(params, function (result) {
2213 if (result.result == "success") {
2214 target.networkList([]);
2215 successOverlay();
2216 } else {
2217 errorOverlay();
2218 }
2219 });
2220 }
mj.qu11d28a82024-12-17 18:09:17 -08002221
qumengjiaca65ef52024-11-06 15:42:21 +08002222 //手动搜网.
2223 function searchFunc() {
2224 showLoading('searching_net');
2225 service.scanForNetwork(function (result, networkList) {
2226 hideLoading();
2227 if (result) {
2228 target.networkList(networkList);
2229 for (var i = 0; i < networkList.length; i++) {
2230 var n = networkList[i];
2231 if (n.nState == '2') {
2232 target.selectNetwork(n.strNumeric + ',' + n.nRat + ',' + n.SubAct);
2233 return;
2234 }
2235 }
2236 } else {
mj.qu825d1ec2024-12-29 22:54:09 -08002237 errorOverlay();
qumengjiaca65ef52024-11-06 15:42:21 +08002238 target.networkList([]);
2239 }
2240 });
2241 }
mj.qu11d28a82024-12-17 18:09:17 -08002242
qumengjiaca65ef52024-11-06 15:42:21 +08002243 function subnetTypeIdFunc(data) {
2244 return getSubNetworkTypeTog(data.nRat, data.SubAct);
2245 }
mj.qu11d28a82024-12-17 18:09:17 -08002246
qumengjiaca65ef52024-11-06 15:42:21 +08002247 function networkTypeIdFunc(data) {
2248 return getNetworkType(data.nRat);
2249 }
mj.qu11d28a82024-12-17 18:09:17 -08002250
qumengjiaca65ef52024-11-06 15:42:21 +08002251 function networkValueFunc(data) {
2252 var result = [];
2253 result.push(data.strNumeric); //strNumeric
2254 result.push(data.nRat); //nRat
2255 result.push(data.SubAct);
2256 return result.join(',');
2257 }
mj.qu11d28a82024-12-17 18:09:17 -08002258
qumengjiaca65ef52024-11-06 15:42:21 +08002259 function operatorNameFunc(data) {
2260 return data.strShortName;
2261 }
mj.qu11d28a82024-12-17 18:09:17 -08002262
qumengjiaca65ef52024-11-06 15:42:21 +08002263 function networkTypeFunc(data) {
2264 var result = getNetworkType(data.nRat);
2265 if (result == "auto")
2266 result = $.i18n.prop("auto");
2267 return result;
2268 }
mj.qu11d28a82024-12-17 18:09:17 -08002269
qumengjiaca65ef52024-11-06 15:42:21 +08002270 function subnetworkTypeFunc(data) {
2271 var result = getSubNetworkTypeTog(data.nRat, data.SubAct);
2272 return result;
2273 }
mj.qu11d28a82024-12-17 18:09:17 -08002274
qumengjiaca65ef52024-11-06 15:42:21 +08002275 function networkStatusFunc(data) {
2276 return $.i18n.prop(getNetworkStatusTog(data.nState));
2277 }
mj.qu11d28a82024-12-17 18:09:17 -08002278
qumengjiaca65ef52024-11-06 15:42:21 +08002279 function networkStatusIdFunc(data) {
2280 return getNetworkStatusTog(data.nState);
2281 }
mj.qu11d28a82024-12-17 18:09:17 -08002282
qumengjiaca65ef52024-11-06 15:42:21 +08002283 function networkTextFunc(data) {
2284 return data.strNumeric;
2285 }
2286
2287 }
2288
2289 //获取网络选择信息.
mj.qu11d28a82024-12-17 18:09:17 -08002290
qumengjiaca65ef52024-11-06 15:42:21 +08002291 function getNetSelectInfo() {
2292 return service.getNetSelectInfo();
2293 }
2294
2295 //搜网结果中的状态转换为对应的语言项.
mj.qu11d28a82024-12-17 18:09:17 -08002296
qumengjiaca65ef52024-11-06 15:42:21 +08002297 function getNetworkStatusTog(status) {
2298 if ("3" == status) {
2299 return "forbidden";
2300 } else if ("2" == status) {
2301 return "current";
2302 } else if ("1" == status) {
2303 return "available";
2304 }else if ("0" == status) {
2305 return "unknown";
2306 }
2307 }
2308 //子网络类型转换.
mj.qu11d28a82024-12-17 18:09:17 -08002309
qumengjiaca65ef52024-11-06 15:42:21 +08002310 function getSubNetworkTypeTog(type, subtype) {
2311 var type_3g = [2, 4, 5, 6, 8];
2312 if ("1" == subtype) {
2313 if ("7" == type) {
2314 subtype = "FDD-LTE";
2315 } else if ($.inArray(type, type_3g) != -1) {
2316 subtype = "WCDMA";
2317 }else {
2318 subtype = "GSM";
2319 }
2320 } else if ("0" == subtype) {
2321 if ("7" == type) {
2322 subtype = "TD-LTE";
2323 } else if ($.inArray(type, type_3g) != -1) {
2324 subtype = "TD-SCDMA";
2325 } else {
2326 subtype = "GSM";
2327 }
2328 } else {
2329 subtype = "";
2330 }
2331 return subtype;
2332 }
2333 //网络类型转换.
mj.qu11d28a82024-12-17 18:09:17 -08002334
qumengjiaca65ef52024-11-06 15:42:21 +08002335 function getNetworkType(type) {
2336 if ("7" == type) {
2337 return "4G";
2338 } else if ("2" == type) {
2339 return "3G";
2340 } else if ("0" == type) {
2341 return "2G";
2342 } else {
2343 return "auto";
2344 }
2345 }
2346
2347 function bindContainer(vm){
mj.qu11d28a82024-12-17 18:09:17 -08002348
qumengjiaca65ef52024-11-06 15:42:21 +08002349 var container = $('#container');
2350 ko.cleanNode(container[0]);
2351 ko.applyBindings(vm, container[0]);
2352 }
2353
2354 //初始化选网功能view model.
mj.qu11d28a82024-12-17 18:09:17 -08002355
qumengjiaca65ef52024-11-06 15:42:21 +08002356 function initialize() {
2357 var vm = new NetSelectVM();
2358 bindContainer(vm);
2359 addInterval(vm.checkEnable, 1000);
2360 }
2361
2362 return {
2363 init: initialize
2364 };
2365});
2366define("locknet","jquery knockout service jquery set main".split(" "),
2367 function ($, ko, service, config, home) {
2368
2369 function initialize() {
2370 var container = $('#container')[0];
2371 ko.cleanNode(container);
2372 var vm = new locknetViewMode();
2373 ko.applyBindings(vm, container);
2374
2375 $("#frmNetworkLock").validate({
2376 submitHandler: function () {
2377 vm.unlock();
2378 },
2379 rules: {
2380 txtLockNumber: "unlock_code_check"
2381 }
2382 });
2383 }
2384
2385 function locknetViewMode() {
2386 var target = this;
2387 var curCableMode = false;
2388 target.isCPE = config.PRODUCT_TYPE == 'CPE';
2389 target.hasRj45 = config.RJ45_SUPPORT;
2390 target.hasSms = config.HAS_SMS;
2391 target.hasPhonebook = config.HAS_PHONEBOOK;
2392 target.isSupportSD = config.SD_CARD_SUPPORT;
mj.qu9a9d8e12025-08-19 18:22:48 -07002393 target.hasUssd = config.HAS_USSD;
mj.qu1161f2f2025-08-25 23:40:56 -07002394 target.hasBuyBundle = config.HAS_BUY_BUNDLE;
qumengjiaca65ef52024-11-06 15:42:21 +08002395 if (config.WIFI_SUPPORT_QR_SWITCH == false) {
2396 target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
2397 } else {
2398 var wifiInfo = service.getWifiBasic();
2399 target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
2400 }
2401 if(config.WIFI_SUPPORT_QR_CODE){
2402 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2403 } else {
2404 target.qrcodeSrc = './pic/res_blacktrans.png';
2405 }
2406 target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
2407 target.deviceInfo = ko.observable([]);
2408 target.isHomePage = ko.observable(false);
2409 if (window.location.hash == "#main") {
2410 target.isHomePage(true);
2411 }
2412
2413 target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
2414 target.unlockCode = ko.observable();
2415
2416 var info = service.getNetworkUnlockTimes();
2417 target.times = ko.observable(info.unlock_nck_time);
2418
2419 //显示工作模式设置窗口
2420 target.showOpModeWindow = showOpModeWindowFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002421
qumengjiaca65ef52024-11-06 15:42:21 +08002422 target.isLoggedIn = ko.observable(false);
2423 target.enableFlag = ko.observable(false);
2424 //解锁
2425 target.unlock = unlockFunc;
2426
2427 //更新工作模式状态
2428 target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002429
qumengjiaca65ef52024-11-06 15:42:21 +08002430 //定时检查工作模式状态
2431 if (target.hasRj45) {
2432 target.refreshOpmodeInfo();
2433 addInterval(function () {
2434 target.refreshOpmodeInfo();
2435 }, 1000);
2436 }
mj.qu11d28a82024-12-17 18:09:17 -08002437
qumengjiaca65ef52024-11-06 15:42:21 +08002438 //更新工作模式状态
2439 function refreshOpmodeInfoFunc() {
2440 var obj = service.getStatusInfo();
2441 target.isLoggedIn(obj.isLoggedIn);
2442
2443 if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
2444 window.location.reload();
2445 return;
2446 }
2447
2448 curCableMode = checkCableMode(obj.blc_wan_mode);
2449 target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
2450 if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
2451 target.enableFlag(true);
2452 } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
2453 target.enableFlag(false);
2454 } else {
2455 target.enableFlag(true);
2456 }
2457 var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
2458 var currMode = "";
2459 switch (getMode) {
2460 case "PPP":
2461 currMode = "opmode_gateway";
2462 break;
2463 case "PPPOE":
2464 currMode = "opmode_cable";
2465 break;
2466 case "AUTO":
2467 currMode = "opmode_auto";
2468 break;
2469 default:
2470 break;
2471 }
2472 $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
2473 }
mj.qu11d28a82024-12-17 18:09:17 -08002474
qumengjiaca65ef52024-11-06 15:42:21 +08002475 //解锁
2476 function unlockFunc() {
2477 showLoading();
2478 service.unlockNetwork({
2479 unlock_network_code: target.unlockCode()
2480 }, function (data) {
2481 target.unlockCode("");
2482 if (data && data.result == "success") {
2483 successOverlay();
2484 if (window.location.hash == "#main") {
2485 setTimeout(function () {
2486 window.location.reload();
2487 }, 500);
2488 } else {
2489 window.location.hash = "#main";
2490 }
2491 } else {
2492 var info = service.getNetworkUnlockTimes();
2493 target.times(info.unlock_nck_time);
2494 errorOverlay();
2495 }
2496 })
2497 }
mj.qu11d28a82024-12-17 18:09:17 -08002498
qumengjiaca65ef52024-11-06 15:42:21 +08002499 //显示工作模式设置窗口
2500 function showOpModeWindowFunc() {
2501 showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
2502 }
2503 }
2504
2505 return {
2506 init: initialize
2507 };
2508});
2509
2510// RJ45联网设置模块
mj.qu11d28a82024-12-17 18:09:17 -08002511
qumengjiaca65ef52024-11-06 15:42:21 +08002512define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
2513function(_, $, ko, config, service) {
2514 var dialActions = _.map(config.dialActions, 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 dialModes = _.map(config.pppoeModes, function(elem) {
2519 return new Option(elem.name, elem.value);
2520 });
mj.qu11d28a82024-12-17 18:09:17 -08002521
qumengjiaca65ef52024-11-06 15:42:21 +08002522 var checkStatusTimer = 0;
2523 var checkConCounter = 0;
2524 var timeoutTipShowed = false;
2525
2526 // 联网设置view model.
mj.qu11d28a82024-12-17 18:09:17 -08002527
qumengjiaca65ef52024-11-06 15:42:21 +08002528 function PPPoEViewModel() {
2529 var pppObj = service.getPppoeParams();
2530 var ethParams = pppObj;
2531 var target = this;
mj.qu11d28a82024-12-17 18:09:17 -08002532
qumengjiaca65ef52024-11-06 15:42:21 +08002533 target.staticNoticeShow = ko.observable();
2534 target.dhcpNoticeShow = ko.observable();
2535 target.pppoeNoticeShow = ko.observable();
2536 target.autoNoticeShow = ko.observable();
2537 target.staticNotice = ko.observable();
2538 target.dhcpNotice = ko.observable();
2539 target.pppoeNotice = ko.observable();
2540 target.autoNotice = ko.observable();
2541 target.dhcpNoticeText = ko.observable();
2542 target.staticNoticeText = ko.observable();
2543 target.pppoeNoticeText = ko.observable();
2544 target.autoNoticeText = ko.observable();
2545 target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
2546 target.showPassword = ko.observable(false);
2547 target.modes = ko.observableArray(dialModes);
2548 target.isPppoeMode = ko.observable(false);
2549 target.isStaticMode = ko.observable(false);
2550 target.isAutoMode = ko.observable(false);
2551 target.action = ko.observable();
2552 target.btnTrans = ko.observable();
2553 target.enableFlag = ko.observable();
2554 target.isShowDisbtn = ko.observable();
2555 target.isShowCancelbtn = ko.observable();
mj.qu11d28a82024-12-17 18:09:17 -08002556
qumengjiaca65ef52024-11-06 15:42:21 +08002557 if(pppObj.rj45_state == "dead"){
2558 checkRj45DeadTip();
2559 } else if(pppObj.rj45_state == "connect"){
2560 timeoutTipShowed = true;
2561 setRj45CheckTimer("connect");
2562 } else if(pppObj.rj45_state == "working"){
2563 setRj45WorkingTip();
2564 }
mj.qu11d28a82024-12-17 18:09:17 -08002565
qumengjiaca65ef52024-11-06 15:42:21 +08002566 target.user = ko.observable(pppObj.pppoe_username);
2567 target.password = ko.observable(pppObj.pppoe_cc);
2568 target.autoUser = ko.observable(pppObj.pppoe_username);
2569 target.autoPassword = ko.observable(pppObj.pppoe_cc);
2570 target.pppMode = ko.observable(pppObj.ethwan_dialmode);
2571 initContronler();
mj.qu11d28a82024-12-17 18:09:17 -08002572
qumengjiaca65ef52024-11-06 15:42:21 +08002573
2574 //下拉框选择改变下面DIV模块
2575 target.changeModeDiv = changeModeDivFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002576
qumengjiaca65ef52024-11-06 15:42:21 +08002577 target.radioHandler = radioHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002578
qumengjiaca65ef52024-11-06 15:42:21 +08002579 target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
2580 target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
2581 target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
2582 target.subnetMask = ko.observable(pppObj.static_wan_netmask);
2583 target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
mj.qu11d28a82024-12-17 18:09:17 -08002584
qumengjiaca65ef52024-11-06 15:42:21 +08002585 addInterval(function(){
2586 ethParams = service.getPppoeParams();
2587 pppObj.rj45_state = ethParams.rj45_state;
2588 initContronler();
2589 }, 1000);
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.cancelConnect = cancelConnectFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002594
qumengjiaca65ef52024-11-06 15:42:21 +08002595 // 应用按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002596
qumengjiaca65ef52024-11-06 15:42:21 +08002597 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002598
qumengjiaca65ef52024-11-06 15:42:21 +08002599 //密码显示事件
2600 target.showPasswordHandler = function () {
2601 var checkbox = $("#showPassword:checked");
2602 if (checkbox && checkbox.length == 0) {
2603 target.showPassword(true);
2604 } else {
2605 target.showPassword(false);
2606 }
2607 };
mj.qu11d28a82024-12-17 18:09:17 -08002608
qumengjiaca65ef52024-11-06 15:42:21 +08002609 // 更新当前界面状态、按钮、提示语等.
mj.qu11d28a82024-12-17 18:09:17 -08002610
qumengjiaca65ef52024-11-06 15:42:21 +08002611 function initContronler() {
2612 checkRj45DeadTip();
2613 if(target.currentMode() == "PPPOE"){
2614 target.isPppoeMode(true);
2615 target.isStaticMode(false);
2616 target.isAutoMode(false);
2617 target.staticNoticeShow(false);
2618 target.dhcpNoticeShow(false);
2619 target.autoNoticeShow(false);
2620 } else if(target.currentMode() == "AUTO"){
2621 target.isStaticMode(false);
2622 target.isPppoeMode(false);
2623 target.isAutoMode(true);
2624 target.dhcpNoticeShow(false);
2625 target.pppoeNoticeShow(false);
2626 target.staticNoticeShow(false);
2627 } else if(target.currentMode() == "STATIC"){
2628 target.isStaticMode(true);
2629 target.isPppoeMode(false);
2630 target.isAutoMode(false);
2631 target.dhcpNoticeShow(false);
2632 target.pppoeNoticeShow(false);
2633 target.autoNoticeShow(false);
2634 } else{
2635 target.isStaticMode(false);
2636 target.isPppoeMode(false);
2637 target.isAutoMode(false);
2638 target.staticNoticeShow(false);
2639 target.pppoeNoticeShow(false);
2640 target.autoNoticeShow(false);
2641 }
2642 if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
2643 target.enableFlag(false);
2644 } else {
2645 target.enableFlag(true);
2646 }
2647 if(pppObj.rj45_state == "connect"){
2648 if(target.pppMode() == "auto_dial"){
2649 target.action("connect");
2650 }else{
2651 target.action("disconnect");
2652 }
2653 } else if(pppObj.rj45_state == "working"){
2654 target.action("disconnect");
2655 }else{
2656 target.action("connect");
2657 }
2658 //应用/连接按钮
2659 if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
2660 target.btnTrans("connect");
2661 } else{
2662 target.btnTrans("apply");
2663 }
2664 if(pppObj.rj45_state != "idle"){
2665 $("#pppoeApply").attr("disabled", true);
2666 }else {
2667 $("#pppoeApply").attr("disabled", false);
2668 }
mj.qu11d28a82024-12-17 18:09:17 -08002669
qumengjiaca65ef52024-11-06 15:42:21 +08002670 //取消/断开按钮
2671 target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
2672 target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
mj.qu11d28a82024-12-17 18:09:17 -08002673
qumengjiaca65ef52024-11-06 15:42:21 +08002674 $("#pppoeApply").translate();
2675 }
2676 // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002677
qumengjiaca65ef52024-11-06 15:42:21 +08002678 function setRj45CheckTimer(action){
2679 checkStatusTimer && window.clearInterval(checkStatusTimer);
2680 if("connect" != action){
2681 checkStatusTimer = addInterval(function () {
2682 checkDisconnectStatus();
2683 }, 2000);
2684 }else{
2685 if(target.currentMode() == "PPPOE"){
2686 target.pppoeNoticeShow(true);
2687 target.pppoeNotice("pppoe_processing");
2688 target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
2689 } else if(target.currentMode() == "STATIC"){
2690 target.staticNoticeShow(true);
2691 target.staticNotice("static_processing");
2692 target.staticNoticeText($.i18n.prop("static_processing"));
2693 } else if(target.currentMode() == "DHCP"){
2694 target.dhcpNoticeShow(true);
2695 target.dhcpNotice("dyn_processing");
2696 target.dhcpNoticeText($.i18n.prop("dyn_processing"));
2697 }else{
2698 target.autoNoticeShow(true);
2699 target.autoNotice("auto_processing");
2700 target.autoNoticeText($.i18n.prop("auto_processing"));
2701 }
2702 checkStatusTimer = addInterval(function () {
2703 checkConnectionStatus();
2704 }, 2000);
2705 }
2706 }
2707 // 设置后通过定时检查rj45_state状态,判断连接操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002708
qumengjiaca65ef52024-11-06 15:42:21 +08002709 function checkConnectionStatus(){
2710 if(checkConCounter < 1){
2711 checkConCounter++;
2712 return;
2713 }
2714 if(pppObj.rj45_state == "connect"){
2715 if(target.currentMode() != ethParams.ethwan_mode){
2716 if(target.currentMode() == "AUTO"){
2717 target.autoNoticeShow(true);
2718 }else if(target.currentMode() == "PPPOE"){
2719 target.pppoeNoticeShow(true);
2720 }else if(target.currentMode() == "STATIC"){
2721 target.staticNoticeShow(true);
2722 }else if(target.currentMode() == "DHCP"){
2723 target.dhcpNoticeShow(true);
2724 }
2725 }
2726 if(checkConCounter > 6){
2727 if(timeoutTipShowed == false){
2728 timeoutTipShowed = true;
2729 showAlert("ussd_operation_timeout");
2730 }
2731 }
2732 checkConCounter++;
2733 } else if (pppObj.rj45_state == "working") {
2734 hideLoading();
2735 setRj45WorkingTip();
2736 window.clearInterval(checkStatusTimer);
2737 } else if (pppObj.rj45_state == "dead") {
2738 hideLoading();
2739 checkRj45DeadTip();
2740 window.clearInterval(checkStatusTimer);
2741 } else if(pppObj.rj45_state == "idle"){
2742 hideLoading();
2743 if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
2744 timeoutTipShowed == false && target.dhcpNoticeShow(true);
2745 target.dhcpNotice("dyn_fail");
2746 target.dhcpNoticeText($.i18n.prop("dyn_fail"));
2747 }
2748 if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
2749 timeoutTipShowed == false && target.staticNoticeShow(true);
2750 target.staticNotice("static_fail");
2751 target.staticNoticeText($.i18n.prop("static_fail"));
2752 }
2753 if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
2754 timeoutTipShowed == false && target.pppoeNoticeShow(true);
2755 target.pppoeNotice("pppoe_fail");
2756 target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
2757 }
2758 if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
2759 timeoutTipShowed == false && target.autoNoticeShow(true);
2760 target.autoNotice("auto_fail");
2761 target.autoNoticeText($.i18n.prop("auto_fail"));
2762 }
2763 window.clearInterval(checkStatusTimer);
2764 } else{
2765 hideLoading();
2766 window.clearInterval(checkStatusTimer);
2767 }
2768 }
2769 // 设置连接成功时提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002770
qumengjiaca65ef52024-11-06 15:42:21 +08002771 function setRj45WorkingTip(){
2772 if(target.currentMode() == ethParams.ethwan_mode){
2773 if(target.currentMode() == "AUTO") {
2774 target.autoNoticeShow(true);
2775 target.autoNotice("auto_success");
2776 target.autoNoticeText($.i18n.prop("auto_success"));
2777 }else if(target.currentMode() == "PPPOE") {
2778 target.pppoeNoticeShow(true);
2779 target.pppoeNotice("pppoe_success");
2780 target.pppoeNoticeText($.i18n.prop("pppoe_success"));
2781 }else if(target.currentMode() == "STATIC") {
2782 target.staticNoticeShow(true);
2783 target.staticNotice("static_success");
2784 target.staticNoticeText($.i18n.prop("static_success"));
2785 }else if(target.currentMode() == "DHCP" ) {
2786 target.dhcpNoticeShow(true);
2787 target.dhcpNotice("dyn_success");
2788 target.dhcpNoticeText($.i18n.prop("dyn_success"));
2789 }
2790 }
2791 }
mj.qu11d28a82024-12-17 18:09:17 -08002792
qumengjiaca65ef52024-11-06 15:42:21 +08002793 // 设置网线断开提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002794
qumengjiaca65ef52024-11-06 15:42:21 +08002795 function checkRj45DeadTip(){
2796 if(pppObj.rj45_state != "dead"){
2797 if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
2798 target.autoNoticeShow(false);
2799 }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
2800 target.pppoeNoticeShow(false);
2801 }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
2802 target.staticNoticeShow(false);
2803 }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
2804 target.dhcpNoticeShow(false);
2805 }
mj.qu11d28a82024-12-17 18:09:17 -08002806
qumengjiaca65ef52024-11-06 15:42:21 +08002807 } else{
2808 target.dhcpNotice("pppoe_msg");
2809 target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
2810 target.staticNotice("pppoe_msg");
2811 target.staticNoticeText($.i18n.prop("pppoe_msg"));
2812 target.pppoeNotice("pppoe_msg");
2813 target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
2814 target.autoNotice("pppoe_msg");
2815 target.autoNoticeText($.i18n.prop("pppoe_msg"));
2816 if(target.currentMode() == "AUTO") {
2817 target.autoNoticeShow(true);
2818 }else if(target.currentMode() == "PPPOE") {
2819 target.pppoeNoticeShow(true);
2820 }else if(target.currentMode() == "STATIC") {
2821 target.staticNoticeShow(true);
2822 }else if(target.currentMode() == "DHCP") {
2823 target.dhcpNoticeShow(true);
2824 }
2825 }
2826 }
2827 // 设置后通过定时检查rj45_state状态,判断断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002828
qumengjiaca65ef52024-11-06 15:42:21 +08002829 function checkDisconnectStatus(){
2830 if(checkConCounter < 1){
2831 checkConCounter++;
2832 } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
2833 target.dhcpNoticeShow(false);
2834 target.staticNoticeShow(false);
2835 target.pppoeNoticeShow(false);
2836 target.autoNoticeShow(false);
2837 window.clearInterval(checkStatusTimer);
2838 successOverlay();
2839 } else if(checkConCounter > 6){
2840 if(timeoutTipShowed == false){
2841 timeoutTipShowed = true;
2842 showAlert("ussd_operation_timeout");
2843 }
2844 window.clearInterval(checkStatusTimer);
2845 } else if(checkConCounter < 7) {
2846 checkConCounter++;
2847 } else {
2848 hideLoading();
2849 window.clearInterval(checkStatusTimer);
2850 }
2851 }
mj.qu11d28a82024-12-17 18:09:17 -08002852
qumengjiaca65ef52024-11-06 15:42:21 +08002853 //应用按钮事件.
2854 function saveFunc(){
2855 target.dhcpNoticeShow(false);
2856 target.staticNoticeShow(false);
2857 target.pppoeNoticeShow(false);
2858 target.autoNoticeShow(false);
2859 if(pppObj.rj45_state == "dead"){
2860 showAlert("pppoe_msg");
2861 return;
2862 }
2863 var requestParams = {};
2864 if($("#pppoe_mode").val() == "PPPOE") {
2865 requestParams = $.extend({}, {
2866 goformId: "WAN_GATEWAYMODE_PPPOE",
2867 pppoe_username: target.user(),
2868 pppoe_cc: target.password()
2869 });
2870 } else if($("#pppoe_mode").val() == "AUTO") {
2871 requestParams = $.extend({}, {
2872 goformId: "WAN_GATEWAYMODE_AUTO",
2873 pppoe_username: target.autoUser(),
2874 pppoe_cc: target.autoPassword()
2875 });
2876 } else if($("#pppoe_mode").val() == "STATIC") {
2877 if(target.ipAddress() == target.defaultGateway()){
2878 showAlert("ip_gate_not_same");
2879 return;
2880 }
2881 if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
2882 showAlert("ip_innergate_not_same");
2883 return;
2884 }
2885 requestParams = $.extend({}, {
2886 goformId: "WAN_GATEWAYMODE_STATIC",
2887 static_wan_ipaddr: target.ipAddress(),
2888 static_wan_netmask: target.subnetMask(),
2889 static_wan_gateway: target.defaultGateway(),
2890 static_wan_primary_dns: target.primaryDNS(),
2891 static_wan_secondary_dns: target.secondaryDNS(),
2892 WAN_MODE: "STATIC"
2893 });
2894 } else {
2895 requestParams = $.extend({}, {
2896 goformId: "WAN_GATEWAYMODE_DHCP"
2897 });
2898 }
2899 requestParams.action_link = "connect";
2900 requestParams.dial_mode = target.pppMode();
2901 showLoading("waiting");
mj.qu11d28a82024-12-17 18:09:17 -08002902
qumengjiaca65ef52024-11-06 15:42:21 +08002903 service.setPppoeDialMode(requestParams, function(data){
2904 if(data.result){
2905 target.currentMode($("#pppoe_mode").val());
2906 pppObj = service.getPppoeParams();
2907 checkConCounter = 0;
2908 timeoutTipShowed = false;
2909 setRj45CheckTimer("connect");
2910 $("#pppoeApply").translate();
2911 } else {
2912 errorOverlay("pppoe_message_send_fail");
2913 }
2914 });
mj.qu11d28a82024-12-17 18:09:17 -08002915
qumengjiaca65ef52024-11-06 15:42:21 +08002916 }
mj.qu11d28a82024-12-17 18:09:17 -08002917
qumengjiaca65ef52024-11-06 15:42:21 +08002918 //取消连接按钮事件.
2919 function cancelConnectFunc(){
2920 target.dhcpNoticeShow(false);
2921 target.staticNoticeShow(false);
2922 target.pppoeNoticeShow(false);
2923 target.autoNoticeShow(false);
2924 if(pppObj.rj45_state == "dead"){
2925 showAlert("pppoe_msg");
2926 return;
2927 }
2928 var requestParams = {
2929 dial_mode: target.pppMode(),
2930 action_link: "disconnect"
2931 };
2932 if(pppObj.ethwan_mode == "PPPOE") {
2933 requestParams = $.extend(requestParams, {
2934 goformId: "WAN_GATEWAYMODE_PPPOE",
2935 pppoe_username: pppObj.pppoe_username,
2936 pppoe_cc: pppObj.pppoe_cc
2937 });
2938 }else if(pppObj.ethwan_mode == "AUTO") {
2939 requestParams = $.extend(requestParams, {
2940 goformId: "WAN_GATEWAYMODE_AUTO",
2941 pppoe_username: pppObj.pppoe_username,
2942 pppoe_cc: pppObj.pppoe_cc
2943 });
2944 }else if(pppObj.ethwan_mode == "STATIC") {
2945 requestParams = $.extend(requestParams, {
2946 goformId: "WAN_GATEWAYMODE_STATIC",
2947 static_wan_ipaddr: pppObj.static_wan_ipaddr,
2948 static_wan_netmask: pppObj.static_wan_netmask,
2949 static_wan_gateway: pppObj.static_wan_gateway,
2950 static_wan_primary_dns: pppObj.static_wan_primary_dns,
2951 static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
2952 WAN_MODE: "STATIC"
2953 });
2954 }else {
2955 requestParams = $.extend(requestParams, {
2956 goformId: "WAN_GATEWAYMODE_DHCP"
2957 });
2958 }
2959 showLoading("waiting");
2960 service.setPppoeDialMode(requestParams, function(data){
2961 if(data.result){
2962 checkConCounter = 0;
2963 timeoutTipShowed = false;
2964 setRj45CheckTimer("disconnect");
2965 $("#pppoeApply").translate();
2966 } else {
2967 errorOverlay("pppoe_message_send_fail");
2968 }
2969 });
mj.qu11d28a82024-12-17 18:09:17 -08002970
qumengjiaca65ef52024-11-06 15:42:21 +08002971 }
mj.qu11d28a82024-12-17 18:09:17 -08002972
qumengjiaca65ef52024-11-06 15:42:21 +08002973 function radioHandlerFunc(){
2974 initContronler();
2975 return true;
2976 }
mj.qu11d28a82024-12-17 18:09:17 -08002977
qumengjiaca65ef52024-11-06 15:42:21 +08002978 function changeModeDivFunc(){
2979 initContronler();
2980 }
mj.qu11d28a82024-12-17 18:09:17 -08002981
qumengjiaca65ef52024-11-06 15:42:21 +08002982 }
2983
2984 function bindContainer(vm){
2985 var container = $('#container');
2986 ko.cleanNode(container[0]);
2987 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08002988
qumengjiaca65ef52024-11-06 15:42:21 +08002989 }
2990 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08002991
qumengjiaca65ef52024-11-06 15:42:21 +08002992 function initialize() {
2993 var vm = new PPPoEViewModel();
2994 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08002995
qumengjiaca65ef52024-11-06 15:42:21 +08002996 $("#pppoeApply").translate();
mj.qu11d28a82024-12-17 18:09:17 -08002997
qumengjiaca65ef52024-11-06 15:42:21 +08002998 $('#pppoeForm').validate({
2999 submitHandler : function() {
3000 vm.save();
3001 },
3002 rules: {
3003 txtPin: "wps_pin_check",
3004 txtIpAddress: "dmz_ip_check",
3005 txtSubnetMask: {
3006 ipv4: true,
3007 subnetmask_check: true
3008 },
3009 txtDefaultGateway: {
3010 ipv4: true,
3011 gateway_check: true
3012 },
3013 txtPrimaryDNS: {
3014 ipv4: true,
3015 dns_check:true
3016 },
3017 txtSecondaryDNS: {
3018 ipv4: true,
3019 dns_check:true
3020 }
3021 }
3022 });
3023 }
mj.qu11d28a82024-12-17 18:09:17 -08003024
3025
qumengjiaca65ef52024-11-06 15:42:21 +08003026//from 4.0
3027 // 有效DNS检查.
mj.qu11d28a82024-12-17 18:09:17 -08003028
qumengjiaca65ef52024-11-06 15:42:21 +08003029function validateDns(dns){
3030 if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
3031 return false;
3032 }
3033 return true;
3034}
3035 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08003036
qumengjiaca65ef52024-11-06 15:42:21 +08003037function isStaticIPValid(ip, lanip, lanmask){
3038 if(!ip || !lanip || !lanmask){//各参数不能为空
3039 return false;
3040 }
3041 if(ip == lanip){// 与内网IP相等
3042 return true;
3043 }
3044 var res1 = [], res2 = [], mask = [];
3045 addr1 = ip.split(".");
3046 addr2 = lanip.split(".");
3047 mask = lanmask.split(".");
3048 for(var i = 0; i < addr1.length; i += 1){
3049 res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
3050 res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
3051 }
3052 if(res1.join(".") == res2.join(".")){//在同一个网段
3053 return true;
3054 }else{//不在同一个网段
3055 return false;
3056 }
3057}
3058
3059// 有效子网掩码验证.
mj.qu11d28a82024-12-17 18:09:17 -08003060
qumengjiaca65ef52024-11-06 15:42:21 +08003061function isNetmaskIPValid(ip) {
3062 if (ip == 255 || ip == 254 || ip == 252 || ip == 248
3063 || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
3064 {
3065 return true;
3066 }
3067 else
3068 {
3069 return false;
3070 }
3071}
3072 // 有效子网掩码检查.
mj.qu11d28a82024-12-17 18:09:17 -08003073
qumengjiaca65ef52024-11-06 15:42:21 +08003074function validateNetmask(netmask) {
3075 var array = new Array();
3076 array = netmask.split(".");
3077
3078 if (array.length != 4) {
3079 return false;
3080 }
3081
3082 array[0] = parseInt(array[0]);
3083 array[1] = parseInt(array[1]);
3084 array[2] = parseInt(array[2]);
3085 array[3] = parseInt(array[3]);
3086
3087 if (array[3] != 0) {
3088 if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
3089 return false;
3090 } else {
3091 if (!isNetmaskIPValid(array[3])) {
3092 return false;
3093 }
3094 }
3095 }
3096
3097 if (array[2] != 0) {
3098 if (array[1] != 255 || array[0] != 255) {
3099 return false;
3100 } else {
3101 if (!isNetmaskIPValid(array[2])) {
3102 return false;
3103 }
3104 }
3105 }
3106
3107 if (array[1] != 0) {
3108 if (array[0] != 255) {
3109 return false;
3110 } else{
3111 if (!isNetmaskIPValid(array[1])) {
3112 return false;
3113 }
3114 }
3115 }
3116 if(array[0]!=255) {
3117 return false;
3118 }
3119 if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
3120 return false;
3121 }
3122 return true;
3123}
mj.qu11d28a82024-12-17 18:09:17 -08003124
qumengjiaca65ef52024-11-06 15:42:21 +08003125 // subnetmask_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003126
qumengjiaca65ef52024-11-06 15:42:21 +08003127jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
3128 var result = validateNetmask(value);
3129 return this.optional(element) || result;
3130});
3131 // dns_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003132
qumengjiaca65ef52024-11-06 15:42:21 +08003133jQuery.validator.addMethod("dns_check", function (value, element, param) {
3134 var result = validateDns(value);
3135 return this.optional(element) || result;
3136});
3137 // 有效网关检查.
mj.qu11d28a82024-12-17 18:09:17 -08003138
qumengjiaca65ef52024-11-06 15:42:21 +08003139function validateGateway(wanIp, netmaskIp, gatewayIp) {
3140 if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
3141 return true;
3142 } else {
3143 return false;
3144 }
3145}
3146 // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
mj.qu11d28a82024-12-17 18:09:17 -08003147
qumengjiaca65ef52024-11-06 15:42:21 +08003148function myConcat(ip1,ip2){
3149 var result = [];
3150 var iplArr = ip1.split(".");
3151 var ip2Arr = ip2.split(".");
3152 for(var i = 0; i < iplArr.length;i++){
3153 result[i] = (iplArr[i] & ip2Arr[i]);
3154 }
3155 return result.join(".");
3156}
3157 // gateway_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003158
qumengjiaca65ef52024-11-06 15:42:21 +08003159jQuery.validator.addMethod("gateway_check", function (value, element, param) {
3160 var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
3161 return this.optional(element) || result;
3162});
mj.qu11d28a82024-12-17 18:09:17 -08003163
qumengjiaca65ef52024-11-06 15:42:21 +08003164 return {
3165 init: initialize
3166 };
3167});
3168//联网设置模块
3169define("network_dial_set","underscore jquery knockout set service".split(" "),
3170function(_, $, ko, config, service) {
3171
3172 //联网设置view model
3173 function DialVM() {
3174 var dialMode = service.getConnectionMode();
3175 var target = this;
3176
3177 target.selectMode = ko.observable(dialMode.connectionMode);
3178 target.enableFlag = ko.observable(true);
3179 target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
3180 var originalRoaming = dialMode.isAllowedRoaming;
3181
3182 target.setAllowedRoaming = setAllowedRoamingFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003183
qumengjiaca65ef52024-11-06 15:42:21 +08003184 var checkboxFlag = $(".checkboxToggle");
3185 target.checkEnable = checkEnableFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003186
qumengjiaca65ef52024-11-06 15:42:21 +08003187 //修改联网模式
3188 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003189
qumengjiaca65ef52024-11-06 15:42:21 +08003190 function saveFunc() {
3191 showLoading();
3192 var connMode = target.selectMode();
3193 //当选择自动时,下发原先的勾选状态
3194 if (connMode == 'auto_dial') {
3195 originalRoaming = target.isAllowedRoaming();
3196 } else {
3197 target.isAllowedRoaming(originalRoaming);
3198 }
3199 service.setConnectionMode({
3200 connectionMode: connMode,
3201 isAllowedRoaming: target.isAllowedRoaming()
3202 }, function (result) {
3203 if (result.result == "success") {
3204 successOverlay();
3205 } else {
3206 errorOverlay();
3207 }
3208 });
3209 }
mj.qu11d28a82024-12-17 18:09:17 -08003210
qumengjiaca65ef52024-11-06 15:42:21 +08003211 function setAllowedRoamingFunc() {
3212 if(!$("#roamBtn").hasClass("disable")){
3213 var checkbox = $("#isAllowedRoaming:checked");
3214 if(checkbox && checkbox.length == 0 ){
3215 target.isAllowedRoaming("on");
3216 }else{
3217 target.isAllowedRoaming("off");
3218 }
3219 }
3220 }
mj.qu11d28a82024-12-17 18:09:17 -08003221
qumengjiaca65ef52024-11-06 15:42:21 +08003222 function checkEnableFunc() {
3223 var status = service.getStatusInfo();
3224
3225 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
3226 target.enableFlag(false);
3227 disableCheckbox(checkboxFlag);
3228 }
3229 else {
3230 target.enableFlag(true);
3231 enableCheckbox(checkboxFlag);
3232 }
3233 }
3234
3235 }
3236
3237 //联网设置初始化.
3238 function initialize() {
3239 var vm = new DialVM();
3240 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08003241
qumengjiaca65ef52024-11-06 15:42:21 +08003242 vm.checkEnable();
3243 addInterval( vm.checkEnable, 1000);
3244 }
mj.qu11d28a82024-12-17 18:09:17 -08003245
qumengjiaca65ef52024-11-06 15:42:21 +08003246 function bindContainer(vm){
3247 var container = $('#container');
3248 ko.cleanNode(container[0]);
3249 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08003250
qumengjiaca65ef52024-11-06 15:42:21 +08003251 }
mj.qu11d28a82024-12-17 18:09:17 -08003252
qumengjiaca65ef52024-11-06 15:42:21 +08003253 return {
3254 init: initialize
3255 };
3256});
3257// APN Setting 模块
3258define("network_apn_set","underscore jquery knockout set service".split(" "),
3259 function (_, $, ko, config, service) {
3260
3261 //获取鉴权方式
mj.qu11d28a82024-12-17 18:09:17 -08003262
qumengjiaca65ef52024-11-06 15:42:21 +08003263 function getAuthModes() {
3264 return _.map(config.APN_AUTH_MODES, function (item) {
3265 return new Option(item.name, item.value);
3266 });
3267 }
3268
3269 function getApnPdpTypes() {
3270 var pdpTypesArray = [new Option('IPv4', 'IP')];
3271 if (config.IPV6_SUPPORT) {
3272 pdpTypesArray.push(new Option('IPv6', 'IPv6'));
3273 if (config.IPV4V6_SUPPORT) {
3274 pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
3275 }
3276 if (config.IPV4_AND_V6_SUPPORT) {
3277 pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
3278 }
3279 }
3280 return pdpTypesArray;
3281 }
3282
3283 //获取apn相关信息
mj.qu11d28a82024-12-17 18:09:17 -08003284
qumengjiaca65ef52024-11-06 15:42:21 +08003285 function getApnSet() {
3286 var apnInfo = service.getApnSettings();
3287 apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
3288 apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
3289 apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
3290 return apnInfo;
3291 }
3292 var apnConfigs = {};
3293 var ipv6ApnConfigs = {};
3294 var autoApnConfigs = {};
3295
3296 //解析自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003297
qumengjiaca65ef52024-11-06 15:42:21 +08003298 function getAutoApnsConfig(autoApnV4, autoApnV6) {
3299 var autoApnsV4 = [];
3300 var autoApnsV6 = [];
3301
3302 if (autoApnV4 && autoApnV4.length > 5) {
3303 var apnArr = autoApnV4.split("||");
3304 for (var ki = 0; ki < apnArr.length; ki++) {
3305 if (apnArr[ki] != "") {
3306 var apnItem = parseApnItem(apnArr[ki], false);
3307 autoApnsV4.push(apnItem);
3308 }
3309 }
3310 }
3311 if (autoApnV6 && autoApnV6.length > 5) {
3312 var apnArr = autoApnV6.split("||");
3313 for (var ki = 0; ki < apnArr.length; ki++) {
3314 if (apnArr[ki] != "") {
3315 var apnItem = parseApnItem(apnArr[ki], false);
3316 autoApnsV6.push(apnItem);
3317 }
3318 }
3319 }
3320 return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
3321 }
3322 //解析apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003323
qumengjiaca65ef52024-11-06 15:42:21 +08003324 function getApnConfigs(apnsStr, isIpv6) {
3325 var apnCfgs = [];
3326 var theApnConfigs = {};
3327 if (apnsStr && apnsStr.length > 10) {
3328 var apnArr = apnsStr.split("||");
3329 for (var ki = 0; ki < apnArr.length; ki++) {
3330 if (apnArr[ki] != "") {
3331 var apnItem = parseApnItem(apnArr[ki], isIpv6);
3332 apnCfgs.push(apnItem);
3333 theApnConfigs[apnItem.profileName] = apnItem;
3334 }
3335 }
3336 }
3337 if (isIpv6 == false) {
3338 apnConfigs = theApnConfigs;
3339 } else {
3340 ipv6ApnConfigs = theApnConfigs;
3341 }
3342 return apnCfgs;
3343 }
3344
3345 //解析单条apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003346
qumengjiaca65ef52024-11-06 15:42:21 +08003347 function parseApnItem(apnStr, isIpv6) {
3348 var apnItem = {};
3349 var items = apnStr.split("($)");
3350 for (var ki = 0; ki < items.length; ki++) {
3351 apnItem.profileName = items[0];
3352 apnItem.pdpType = items[7];
3353 if (isIpv6 == false) {
3354 apnItem.dnsMode = items[10];
3355 apnItem.dns1 = items[11];
3356 apnItem.dns2 = items[12];
3357 apnItem.wanApn = items[1];
3358 apnItem.authMode = items[4].toLowerCase();
3359 apnItem.username = items[5];
3360 apnItem.password = items[6];
3361 } else {
3362 apnItem.dnsModeV6 = items[10];
3363 apnItem.dns1V6 = items[11];
3364 apnItem.dns2V6 = items[12];
3365 apnItem.wanApnV6 = items[1];
3366 apnItem.authModeV6 = items[4].toLowerCase();
3367 apnItem.usernameV6 = items[5];
3368 apnItem.passwordV6 = items[6];
3369 }
3370 }
3371 return apnItem;
3372 }
3373 //合并V4\V6自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003374
qumengjiaca65ef52024-11-06 15:42:21 +08003375 function dealAutoApnsV4V6(v4, v6) {
3376 autoApnConfigs = {};
3377 var autoApns = [];
3378 for (var ki = 0; ki < v4.length; ki++) {
3379 var apnElem = v4[ki];
3380 var itemsV6 = v6[ki];
3381 if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
3382 apnElem.usernameV6 = itemsV6.username;
3383 apnElem.passwordV6 = itemsV6.password;
3384 apnElem.dns1V6 = itemsV6.dns1;
3385 apnElem.dns2V6 = itemsV6.dns2;
3386 apnElem.wanApnV6 = itemsV6.wanApn;
3387 apnElem.authModeV6 = itemsV6.authMode;
3388 apnElem.dnsModeV6 = itemsV6.dnsMode;
3389 }
3390 autoApns.push(apnElem);
3391 autoApnConfigs[apnElem.profileName] = apnElem;
3392 }
3393 return autoApns;
3394 }
3395
3396 function getProfileOptions(apns) {
3397 return _.map(apns, function (item) {
3398 return new Option(item.profileName, item.profileName);
3399 });
3400 }
3401
3402 //APNViewModel
mj.qu11d28a82024-12-17 18:09:17 -08003403
qumengjiaca65ef52024-11-06 15:42:21 +08003404 function APNViewModel() {
3405 var target = this;
3406 var apnSettings = getApnSet();
3407 if (apnSettings.apnNumPreset) {
3408 config.maxApnNumber = apnSettings.apnNumPreset;
3409 }
3410
3411 target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
3412 target.apnMode = ko.observable(apnSettings.apnMode);
3413 target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
3414 target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
3415 target.wanDial = ko.observable(apnSettings.wanDial);
mj.qu11d28a82024-12-17 18:09:17 -08003416
qumengjiaca65ef52024-11-06 15:42:21 +08003417 target.showApnDns = ko.observable(config.SHOW_APN_DNS);
3418 target.index = ko.observable(apnSettings.currIndex);
3419 target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
3420 target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
3421
3422 target.apn = ko.observable(apnSettings.wanApn);
3423 target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
3424 target.dns1 = ko.observable(apnSettings.dns1);
3425 target.dns2 = ko.observable(apnSettings.dns2);
3426 target.authModes = ko.observableArray(getAuthModes());
3427 target.username = ko.observable(apnSettings.username);
3428 target.password = ko.observable(apnSettings.password);
mj.qu11d28a82024-12-17 18:09:17 -08003429
qumengjiaca65ef52024-11-06 15:42:21 +08003430 target.pdpTypes = ko.observableArray(getApnPdpTypes());
3431 target.selectedPdpType = ko.observable(apnSettings.pdpType);
3432 target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
3433 target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
3434 target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
3435
3436 target.showPassword = ko.observable(false);
3437
3438 target.apnV6 = ko.observable(apnSettings.wanApnV6);
3439 target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
3440 target.dns1V6 = ko.observable(apnSettings.dns1V6);
3441 target.dns2V6 = ko.observable(apnSettings.dns2V6);
3442 target.authModesV6 = ko.observableArray(getAuthModes());
3443 target.usernameV6 = ko.observable(apnSettings.usernameV6);
3444 target.passwordV6 = ko.observable(apnSettings.passwordV6);
3445 target.pdpTypeNote = ko.observable(true);
3446 if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
3447 target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
3448 } else {
3449 target.selectedAutoProfile = ko.observable();
3450 }
3451
3452 if (config.EMPTY_APN_SUPPORT == false) {
3453 $("#apn_ipv4_apn").addClass("required");
3454 $("#apn_ipv6_apn").addClass("required");
3455 } else {
3456 $("#apn_ipv4_apn").removeClass("required");
3457 $("#apn_ipv6_apn").removeClass("required");
3458 }
mj.qu11d28a82024-12-17 18:09:17 -08003459
qumengjiaca65ef52024-11-06 15:42:21 +08003460 target.disableProfile = ko.observable(false); //表示处于新增页面
3461 target.addApnHide = ko.observable(true);
3462 target.defaultCfg = ko.observable(true); //当前选中的是默认APN
3463 target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
mj.qu11d28a82024-12-17 18:09:17 -08003464
qumengjiaca65ef52024-11-06 15:42:21 +08003465 target.selectedAuthentication = ko.observable(apnSettings.authMode);
3466 target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
3467
3468
3469 target.transApnV6 = ko.observable('apn');
3470 target.transDnsModeV6 = ko.observable('apn_dns_mode');
3471 target.transDns1V6 = ko.observable('apn_dns1');
3472 target.transDns2V6 = ko.observable('apn_dns2');
3473 target.transAuthV6 = ko.observable('apn_authentication');
3474 target.transUserNameV6 = ko.observable('apn_user_name');
3475 target.transPasswordV6 = ko.observable('apn_password');
mj.qu11d28a82024-12-17 18:09:17 -08003476
qumengjiaca65ef52024-11-06 15:42:21 +08003477 target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
3478 target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
3479 target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
3480 target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
3481 target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
3482 target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
3483 target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
3484
3485 target.setDefaultVisible = ko.observable(!isConnectedNetWork());
3486
3487 target.tmp1 = ko.computed(function () {
3488 if (target.selectedPdpType() == "IPv6") {
3489 target.transApnV6('apn');
3490 target.transDnsModeV6('apn_dns_mode');
3491 target.transDns1V6('apn_dns1');
3492 target.transDns2V6('apn_dns2');
3493 target.transAuthV6('apn_authentication');
3494 target.transUserNameV6('apn_user_name');
3495 target.transPasswordV6('apn_password');
3496 } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3497 target.transApn('apn_ipv4_apn');
3498 target.transDnsMode('apn_dns_mode_ipv4');
3499 target.transDns1('apn_dns1_ipv4');
3500 target.transDns2('apn_dns2_ipv4');
3501 target.transAuth('apn_authentication_ipv4');
3502 target.transUserName('apn_user_name_ipv4');
3503 target.transPassword('apn_password_ipv4');
3504
3505 target.transApnV6('apn_ipv6_apn');
3506 target.transDnsModeV6('apn_dns_mode_ipv6');
3507 target.transDns1V6('apn_dns1_ipv6');
3508 target.transDns2V6('apn_dns2_ipv6');
3509 target.transAuthV6('apn_authentication_ipv6');
3510 target.transUserNameV6('apn_user_name_ipv6');
3511 target.transPasswordV6('apn_password_ipv6');
3512 } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
3513 target.transApn('apn');
3514 target.transDnsMode('apn_dns_mode');
3515 target.transDns1('apn_dns1');
3516 target.transDns2('apn_dns2');
3517 target.transAuth('apn_authentication');
3518 target.transUserName('apn_user_name');
3519 target.transPassword('apn_password');
3520 } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
3521 target.transApn('apn');
3522 target.transDnsMode('apn_dns_mode');
3523 target.transDns1('apn_dns1');
3524 target.transDns2('apn_dns2');
3525 target.transAuth('apn_authentication');
3526 target.transUserName('apn_user_name');
3527 target.transPassword('apn_password');
3528 }
3529 $("#apn_setting_form").translate();
3530 });
3531
3532 target.autoApnChecked = ko.computed(function () {
3533 return target.apnMode() == "auto";
3534 });
mj.qu11d28a82024-12-17 18:09:17 -08003535
qumengjiaca65ef52024-11-06 15:42:21 +08003536 target.hasCapacity = ko.computed(function () {
3537 if (target.profiles().length < config.maxApnNumber) {
3538 return true;
3539 } else {
3540 return false;
3541 }
3542 });
3543
3544 target.showDnsV6 = ko.computed(function () {
3545 return target.dnsModeV6() == "manual";
3546 });
mj.qu11d28a82024-12-17 18:09:17 -08003547
qumengjiaca65ef52024-11-06 15:42:21 +08003548 target.showDns = ko.computed(function () {
3549 return target.dnsMode() == "manual";
3550 });
3551
3552
3553 checkDefaultProfileStatus();
3554 target.checkInputDisable = ko.computed(function () {
3555 if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
3556 return false;
3557 }
3558 if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
3559 return true;
3560 }
3561 if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
3562 return false;
3563 }
3564 return false;
3565 });
3566
3567 var data = service.getDeviceInfo();
3568 target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003569
qumengjiaca65ef52024-11-06 15:42:21 +08003570
3571 target.showAutoApnDetail = ko.computed(function () {
3572 if (target.apnMode() != "auto") {
3573 return true;
3574 } else {
3575 return target.autoProfiles().length > 0;
3576 }
3577 });
3578 //密码显示事件
3579 target.showPasswordHandler = function () {
3580 var checkbox = $("#showPassword:checked");
3581 if (checkbox && checkbox.length == 0) {
3582 target.showPassword(true);
3583 } else {
3584 target.showPassword(false);
3585 }
3586 };
3587 //auto apn profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003588
qumengjiaca65ef52024-11-06 15:42:21 +08003589 target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003590
3591
qumengjiaca65ef52024-11-06 15:42:21 +08003592 //profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003593
qumengjiaca65ef52024-11-06 15:42:21 +08003594 target.profileChangeHandler = profileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003595
3596
qumengjiaca65ef52024-11-06 15:42:21 +08003597 //切换profile时重置下面的显示项
3598 target.setUIData = setUIDataFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003599
qumengjiaca65ef52024-11-06 15:42:21 +08003600
3601 //设置默认apn状态
mj.qu11d28a82024-12-17 18:09:17 -08003602
qumengjiaca65ef52024-11-06 15:42:21 +08003603 function checkDefaultProfileStatus() {
3604 var index = getApnIndex();
3605 //默认apn不允许编辑
3606 if (target.apnMode() != "auto") { //当前选中与实际不一致的话
3607 if (target.selectedProfile() != target.defApn()) {
3608 target.defaultCfg(false);
3609 } else {
3610 target.defaultCfg(true); //默认APN
3611 }
3612 } else {
3613 if (target.selectedAutoProfile() != target.defApn()) {
3614 target.defaultCfg(false);
3615 } else {
3616 target.defaultCfg(true); //默认APN
3617 }
3618 }
3619
3620 if (index >= config.defaultApnSize) {
3621 target.predeterminedCfg(false);
3622 } else {
3623 target.predeterminedCfg(true); //预置APN
3624 }
3625 }
3626
3627
3628 //设置为默认apn
qumengjiaca65ef52024-11-06 15:42:21 +08003629
mj.qu11d28a82024-12-17 18:09:17 -08003630 target.setDefaultAct = setDefaultActFunc;
3631
3632
3633
qumengjiaca65ef52024-11-06 15:42:21 +08003634 //APN mode change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003635
qumengjiaca65ef52024-11-06 15:42:21 +08003636 target.apnModeChangeHandler = apnModeChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003637
3638
qumengjiaca65ef52024-11-06 15:42:21 +08003639 function doSetDefaultAct() {
3640 var index = 0;
3641 if (target.apnMode() != 'auto') {
3642 index = getApnIndex();
3643 target.selectedProfile($("#profile").val());
3644 } else {
3645 index = getAutoApnIndex();
3646 target.selectedAutoProfile($("#autoProfile").val());
3647 }
3648 var selectedProfileDetail = target.getSelectedManualProfile();
3649 service.setDefaultApn({
3650 index: index,
3651 apnMode: target.apnMode(),
3652 pdpType: selectedProfileDetail.pdpType,
3653
3654 profileName: selectedProfileDetail.profileName,
3655 wanApn: selectedProfileDetail.wanApn,
3656 authMode: selectedProfileDetail.authMode,
3657 username: selectedProfileDetail.username,
3658 password: selectedProfileDetail.password,
3659 dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
3660 dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
3661 dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
3662 }, function (data) {
3663 if (data.result) {
3664 //showLoading("apn_alert_restart");
3665 //restartDevice(service);
3666 addTimeout(function () {
3667 initialize(true);
3668 target.apnModeChangeHandler();
3669 successOverlay();
3670 }, 500);
3671 } else {
3672 errorOverlay();
3673 }
3674 }, function (data) {
3675 errorOverlay();
3676 });
3677 }
3678
3679 target.getSelectedManualProfile = getSelectedManualProfileFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003680
qumengjiaca65ef52024-11-06 15:42:21 +08003681
3682 //获取自动apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003683
qumengjiaca65ef52024-11-06 15:42:21 +08003684 function getAutoApnIndex() {
3685 var configs = $("#autoProfile option");
3686 for (var ki = 0; ki < configs.length; ki++) {
3687 if (configs[ki].value == target.selectedAutoProfile()) {
3688 return ki;
3689 }
3690 }
3691 return configs.length - 1;
3692 }
mj.qu11d28a82024-12-17 18:09:17 -08003693
qumengjiaca65ef52024-11-06 15:42:21 +08003694 //获取apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003695
qumengjiaca65ef52024-11-06 15:42:21 +08003696 function getApnIndex() {
3697 var configs = $("#profile option");
3698 if (configs.length == 0) {
3699 configs = target.profiles();
3700 }
3701 var ki = 0;
3702 for (; ki < configs.length; ki++) {
3703 if (configs[ki].value == target.selectedProfile()) {
3704 break;
3705 }
3706 }
3707 return ki;
3708 }
3709
3710 //保存APN设置信息
mj.qu11d28a82024-12-17 18:09:17 -08003711
qumengjiaca65ef52024-11-06 15:42:21 +08003712 target.saveAct = saveActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003713
qumengjiaca65ef52024-11-06 15:42:21 +08003714 //编辑APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003715
qumengjiaca65ef52024-11-06 15:42:21 +08003716 function editApnSetting(preAct) { //默认设置按钮触发为TRUE
3717 showLoading();
3718 var apnIndex = getApnIndex();
3719 var sameInfo = false;
3720 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3721 sameInfo = true;
3722 }
3723 var needDoDefault = false;
3724 if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
3725 needDoDefault = true;
3726 }
3727 service.addOrEditApn({
3728 profileName: target.profileName(),
3729 pdpType: target.selectedPdpType(),
3730 index: apnIndex,
3731
3732 wanApn: target.apn(),
3733 authMode: target.selectedAuthentication(),
3734 username: target.username(),
3735 password: target.password(),
3736 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3737 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3738 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3739
3740 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3741 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3742 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3743 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3744 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3745 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3746 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3747 }, function (data) {
3748 if (data.result) {
3749 apnSettings = getApnSet();
3750 if (target.profileName() != target.selectedProfile()) {
3751 var newProfileName = target.profileName();
3752 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3753 $('#profile').val(newProfileName).trigger('change');
3754 }
3755 if (needDoDefault == false) {
3756 successOverlay();
3757 } else {
3758 doSetDefaultAct();
3759 }
3760 } else {
3761 errorOverlay();
3762 }
3763 }, function (data) {
3764 errorOverlay();
3765 });
3766 }
mj.qu11d28a82024-12-17 18:09:17 -08003767
qumengjiaca65ef52024-11-06 15:42:21 +08003768 //新增APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003769
qumengjiaca65ef52024-11-06 15:42:21 +08003770 function addNewApnSetting() {
3771 showLoading("waiting");
3772 var optionLen = $("option", "#profile").length;
3773 if (optionLen < config.defaultApnSize) {
3774 errorOverlay();
3775 return;
3776 }
3777 // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
3778 // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
3779 var sameInfo = false;
3780 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3781 sameInfo = true;
3782 }
3783
3784 service.addOrEditApn({
3785 profileName: target.profileName(),
3786 pdpType: target.selectedPdpType(),
3787 index: optionLen,
3788
3789 wanApn: target.apn(),
3790 authMode: target.selectedAuthentication(),
3791 username: target.username(),
3792 password: target.password(),
3793 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3794 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3795 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3796
3797 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3798 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3799 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3800 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3801 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3802 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3803 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3804 }, function (data) {
3805 if (data.result) {
3806 apnSettings = getApnSet();
3807 if (target.profileName() != target.selectedProfile()) {
3808 var newProfileName = target.profileName();
3809 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3810 $('#profile').val(newProfileName).trigger('change');
3811 }
3812 doSetDefaultAct();
3813 } else {
3814 errorOverlay();
3815 }
3816 }, function (data) {
3817 errorOverlay();
3818 });
3819 }
3820
mj.qu11d28a82024-12-17 18:09:17 -08003821
qumengjiaca65ef52024-11-06 15:42:21 +08003822
3823 var tempApn = {};
3824 //删除APN
mj.qu11d28a82024-12-17 18:09:17 -08003825
qumengjiaca65ef52024-11-06 15:42:21 +08003826 target.deleteAct = deleteActFunc;
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.cancelAddAct = cancelAddActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003831
qumengjiaca65ef52024-11-06 15:42:21 +08003832 //进入新增APN页面
mj.qu11d28a82024-12-17 18:09:17 -08003833
qumengjiaca65ef52024-11-06 15:42:21 +08003834 target.addAct = addActFunc;
3835 //进入新增APN页面
3836 function addActFunc() {
3837 clearValidateMsg('#apn_setting_form');
3838 target.pdpTypeNote(true);
3839 target.disableProfile(true);
3840 target.addApnHide(true);
3841 tempApn = {
3842 profileName: target.profileName(),
3843 selectedPdpType: target.selectedPdpType(),
3844
3845 wanApnV6: target.apnV6(),
3846 dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
3847 dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
3848 dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
3849 authModeV6: target.selectedAuthenticationV6(),
3850 usernameV6: target.usernameV6(),
3851 passwordV6: target.passwordV6(),
mj.qu11d28a82024-12-17 18:09:17 -08003852
qumengjiaca65ef52024-11-06 15:42:21 +08003853 wanApn: target.apn(),
3854 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3855 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3856 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3857 authMode: target.selectedAuthentication(),
3858 username: target.username(),
3859 password: target.password(),
3860
3861 };
3862 target.profileName("");
3863 target.selectedPdpType("IP");
3864 target.selectedPdpTypeTmp("IP");
3865
3866 target.apnV6("");
3867 target.dnsModeV6("auto");
3868 target.dns1V6("");
3869 target.dns2V6("");
3870 target.selectedAuthenticationV6("none");
3871 target.usernameV6("");
3872 target.passwordV6("");
mj.qu11d28a82024-12-17 18:09:17 -08003873
qumengjiaca65ef52024-11-06 15:42:21 +08003874 target.apn("");
3875 target.dnsMode("auto");
3876 target.dns1("");
3877 target.dns2("");
3878 target.selectedAuthentication("none");
3879 target.username("");
3880 target.password("");
3881
3882 }
mj.qu11d28a82024-12-17 18:09:17 -08003883
qumengjiaca65ef52024-11-06 15:42:21 +08003884 //取消新增APN
3885 function cancelAddActFunc() {
3886 clearValidateMsg('#apn_setting_form');
3887 target.pdpTypeNote(false);
3888 target.disableProfile(false);
3889 target.addApnHide(false);
3890 target.profileName(tempApn.profileName);
3891 target.selectedPdpType(tempApn.selectedPdpType);
3892 target.selectedPdpTypeTmp(tempApn.selectedPdpType);
3893
3894 target.apnV6(tempApn.wanApnV6);
3895 target.dnsModeV6(tempApn.dnsModeV6);
3896 target.dns1V6(tempApn.dns1V6);
3897 target.dns2V6(tempApn.dns2V6);
3898 target.selectedAuthenticationV6(tempApn.authModeV6);
3899 target.usernameV6(tempApn.usernameV6);
3900 target.passwordV6(tempApn.passwordV6);
mj.qu11d28a82024-12-17 18:09:17 -08003901
qumengjiaca65ef52024-11-06 15:42:21 +08003902 target.apn(tempApn.wanApn);
3903 target.dnsMode(tempApn.dnsMode);
3904 target.dns1(tempApn.dns1);
3905 target.dns2(tempApn.dns2);
3906 target.selectedAuthentication(tempApn.authMode);
3907 target.username(tempApn.username);
3908 target.password(tempApn.password);
3909
3910 }
mj.qu11d28a82024-12-17 18:09:17 -08003911
qumengjiaca65ef52024-11-06 15:42:21 +08003912 //删除APN
3913 function deleteActFunc() {
3914 if (!target.selectedProfile()) {
3915 showAlert("apn_no_select_alert");
3916 return false;
3917 }
3918 if (target.predeterminedCfg()) { //预置的apn不允许删除
3919 errorOverlay("apn_delete_cant_delete_default");
3920 return false;
3921 }
3922 if (getApnSet().profileName == target.profileName()) {
3923 errorOverlay("apn_cant_delete_current");
3924 return false;
3925 }
3926
3927 showConfirm("apn_delete_confirm", function () {
3928 showLoading('deleting');
3929 service.deleteApn({
3930 index: getApnIndex()
3931 }, function (data) {
3932 if (data.result) {
3933 target.profiles(getProfileOptions(getApnSet().apnConfigs));
3934 target.selectedProfile(target.defApn());
3935 target.profileChangeHandler();
3936 successOverlay();
3937 } else {
3938 errorOverlay();
3939 }
3940 }, function (data) {
3941 errorOverlay();
3942 });
3943 });
3944 }
mj.qu11d28a82024-12-17 18:09:17 -08003945
qumengjiaca65ef52024-11-06 15:42:21 +08003946 //保存APN设置信息
3947 function saveActFunc() {
3948 if (!$('#apn_setting_form').valid()) {
3949 return false;
3950 }
3951 if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
3952 showAlert("apn_no_select_alert");
3953 return false;
3954 }
3955 var exist = false;
3956 $.each(target.profiles(), function (i, e) {
3957 if (e.value == target.profileName()) {
3958 exist = true;
3959 }
3960 });
3961
3962 if (target.disableProfile() == false) {
3963 if (exist && target.selectedProfile() != target.profileName()) {
3964 showInfo("apn_save_profile_exist");
3965 return false;
3966 }
3967 if (target.predeterminedCfg()) { //预置的APN不可以修改
3968 errorOverlay();
3969 return false;
3970 }
3971 if (target.predeterminedCfg() || target.defaultCfg()) {
3972 //showConfirm("apn_alert", function () {
3973 editApnSetting(false);
3974 //});
3975 } else {
3976 editApnSetting(false);
3977 }
3978 } else {
mj.qu11d28a82024-12-17 18:09:17 -08003979
qumengjiaca65ef52024-11-06 15:42:21 +08003980 if ($("#profile option").length >= config.maxApnNumber) {
3981 showInfo({
3982 msg: "apn_profile_full",
3983 params: [config.maxApnNumber]
3984 });
3985 return false;
3986 }
3987 if (exist) {
3988 showInfo("apn_save_profile_exist");
3989 return false;
3990 }
3991 var info = service.getStatusInfo();
3992 if (info.connectStatus != "ppp_connected") {
3993 //showConfirm("apn_alert", function () {
3994 addNewApnSetting();
3995 //});
mj.qu11d28a82024-12-17 18:09:17 -08003996
qumengjiaca65ef52024-11-06 15:42:21 +08003997 } else {
3998 showConfirm("apn_diconneted_network_confirm", function () {
3999 showLoading('disconnecting');
4000 service.disconnect({}, function (data) {
4001 if (data.result) {
4002 config.connect_flag = true;
4003 addNewApnSetting();
4004 } else {
4005 errorOverlay();
4006 }
4007 });
4008 });
4009 }
4010 }
4011 }
mj.qu11d28a82024-12-17 18:09:17 -08004012
qumengjiaca65ef52024-11-06 15:42:21 +08004013 function getSelectedManualProfileFunc() {
4014 var cfg = {};
4015 var profileVal = $("#profile").val();
4016 if (typeof target.selectedProfile() == 'undefined') {
4017 target.selectedProfile(profileVal);
4018 }
4019 var cfgV4 = apnConfigs[profileVal];
4020 var cfgV6 = ipv6ApnConfigs[profileVal];
4021 if (cfgV4 && !cfgV6) {
4022 $.extend(cfg, cfgV4);
4023 } else if (cfgV4 && cfgV6) {
4024 if (!!cfgV4.pdpType) {
4025 $.extend(cfg, cfgV6);
4026 $.extend(cfg, cfgV4);
4027 } else {
4028 $.extend(cfg, cfgV4);
4029 $.extend(cfg, cfgV6);
4030 }
4031 }
4032 return cfg;
4033 }
mj.qu11d28a82024-12-17 18:09:17 -08004034
qumengjiaca65ef52024-11-06 15:42:21 +08004035 //APN mode change 事件处理
4036 function apnModeChangeHandlerFunc(data, event) {
4037 if (target.apnMode() != 'auto') {
4038 target.profileChangeHandler();
4039 } else {
4040 if (target.showAutoApnDetail()) {
4041 target.autoProfileChangeHandler();
4042 }
4043 }
4044 return true;
4045 }
mj.qu11d28a82024-12-17 18:09:17 -08004046
qumengjiaca65ef52024-11-06 15:42:21 +08004047 //设置为默认apn
4048 function setDefaultActFunc() {
4049 if (!target.selectedProfile()) {
4050 showAlert("apn_no_select_alert");
4051 return false;
4052 }
4053 var connectStatus = service.getConnectionInfo().connectStatus;
4054 if (connectStatus == "ppp_connecting") {
4055 showAlert({
4056 msg: "apn_cant_modify_status",
4057 params: [$.i18n.prop("connecting").toLowerCase()]
4058 });
4059 return false;
4060 } else if (connectStatus == "ppp_disconnecting") {
4061 showAlert({
4062 msg: "apn_cant_modify_status",
4063 params: [$.i18n.prop("disconnecting").toLowerCase()]
4064 });
4065 return false;
4066 } else if (connectStatus == "ppp_connected") {
4067 showAlert({
4068 msg: "apn_cant_modify_status",
4069 params: [$.i18n.prop("connected").toLowerCase()]
4070 });
4071 return false;
4072 }
4073 if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
4074 //showConfirm("apn_alert", function () {
4075 showLoading("waiting");
4076 doSetDefaultAct();
4077 //});
4078 } else {
4079 if ($('#apn_setting_form').valid() == false) {
4080 $(".error:first", "#apn_setting_form").focus();
4081 } else {
4082 var exist = false;
4083 $.each(target.profiles(), function (i, e) {
4084 if (e.value == target.profileName()) {
4085 exist = true;
4086 }
4087 });
4088 if (exist && target.selectedProfile() != target.profileName()) {
4089 showInfo("apn_save_profile_exist");
4090 return false;
4091 }
4092 //showLoading("waiting");
4093 //showConfirm("apn_alert", function () {
4094 editApnSetting(true);
4095 //});
4096 }
4097 }
4098 }
mj.qu11d28a82024-12-17 18:09:17 -08004099
qumengjiaca65ef52024-11-06 15:42:21 +08004100 //切换profile时重置下面的显示项
4101 function setUIDataFunc(data) {
4102 clearValidateMsg('#apn_setting_form');
4103 if (!data) {
4104 return;
4105 }
4106 target.selectedPdpType(data.pdpType || 'IP');
4107 target.selectedPdpTypeTmp(data.pdpType || 'IP');
4108 target.profileName(data.profileName);
4109
4110 target.apn(data.wanApn);
4111 target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
4112 target.dns1(data.dns1);
4113 target.dns2(data.dns2);
4114 target.username(data.username);
4115 target.password(data.password);
4116 target.selectedAuthentication(data.authMode || 'none');
4117
4118 target.apnV6(data.wanApnV6);
4119 target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
4120 target.dns1V6(data.dns1V6);
4121 target.dns2V6(data.dns2V6);
4122 target.usernameV6(data.usernameV6);
4123 target.passwordV6(data.passwordV6);
4124 target.selectedAuthenticationV6(data.authModeV6 || 'none');
4125 }
mj.qu11d28a82024-12-17 18:09:17 -08004126
qumengjiaca65ef52024-11-06 15:42:21 +08004127 //profile change 事件处理
4128 function profileChangeHandlerFunc(data, event) {
4129 target.pdpTypeNote(true);
4130 if (target.apnMode() != 'manual') {
4131 return true;
4132 }
4133 var cfg = target.getSelectedManualProfile();
4134 target.setUIData(cfg);
4135 checkDefaultProfileStatus();
4136 return true;
4137 }
mj.qu11d28a82024-12-17 18:09:17 -08004138
qumengjiaca65ef52024-11-06 15:42:21 +08004139 //auto apn profile change 事件处理
4140 function autoProfileChangeHandlerFunc(data, event) {
4141 if (target.apnMode() != 'auto') {
4142 return true;
4143 }
4144 var cfg = autoApnConfigs[target.selectedAutoProfile()];
4145 target.setUIData(cfg);
4146 checkDefaultProfileStatus();
4147 return true;
4148 }
mj.qu11d28a82024-12-17 18:09:17 -08004149
qumengjiaca65ef52024-11-06 15:42:21 +08004150 function pdpTypeChangeAlertFunc() {
4151 if (target.pdpTypeNote()) {
4152 showAlert({
4153 msg: "apn_pdptype_change_note",
4154 params: [data.lanDomain, data.ipAddress]
4155 });
4156 }
4157 if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
4158 if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
4159 if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
4160 target.apn(target.apnV6());
4161 target.dnsMode(target.dnsModeV6());
4162 target.dns1(target.dns1V6());
4163 target.dns2(target.dns2V6());
4164 target.username(target.usernameV6());
4165 target.password(target.passwordV6());
4166 target.selectedAuthentication(target.selectedAuthenticationV6());
4167 } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
4168 target.apnV6(target.apn());
4169 target.dnsModeV6(target.dnsMode());
4170 target.dns1V6(target.dns1());
4171 target.dns2V6(target.dns2());
4172 target.usernameV6(target.username());
4173 target.passwordV6(target.password());
4174 target.selectedAuthenticationV6(target.selectedAuthentication());
4175 }
4176 }
4177 }
4178 target.selectedPdpTypeTmp(target.selectedPdpType());
4179 }
mj.qu11d28a82024-12-17 18:09:17 -08004180
qumengjiaca65ef52024-11-06 15:42:21 +08004181
4182 }
4183
4184 //是否已联网
mj.qu11d28a82024-12-17 18:09:17 -08004185
qumengjiaca65ef52024-11-06 15:42:21 +08004186 function isConnectedNetWork() {
4187 var info = service.getConnectionInfo();
4188 return info.connectStatus == "ppp_connected";
4189 }
4190
4191 function initVar() {
4192 apnConfigs = {};
4193 ipv6ApnConfigs = {};
4194 autoApnConfigs = {};
4195 }
4196 function bindContainer(vm){
4197 var container = $('#container');
4198 ko.cleanNode(container[0]);
4199 ko.applyBindings(vm, container[0]);
4200 }
4201 //初始化ViewModel
mj.qu11d28a82024-12-17 18:09:17 -08004202
qumengjiaca65ef52024-11-06 15:42:21 +08004203 function initialize(formInit) {
4204 initVar();
mj.qu11d28a82024-12-17 18:09:17 -08004205
qumengjiaca65ef52024-11-06 15:42:21 +08004206 var vm = new APNViewModel();
4207 bindContainer(vm);
4208
4209 if (!formInit) {
4210 addInterval(function () {
4211 vm.setDefaultVisible(!isConnectedNetWork());
4212 }, 1000);
4213 }
4214 $('#apn_setting_form').validate({
4215 submitHandler: function () {
4216 vm.saveAct();
4217 },
4218 rules: {
4219 profile_name: 'apn_profile_name_check',
4220 apn_ipv4_apn: 'apn_check',
4221 apn_dns1_ipv4: "ipv4",
4222 apn_dns2_ipv4: "ipv4",
4223 apn_ipv6_apn: 'apn_check',
4224 apn_dns1_ipv6: "ipv6",
4225 apn_dns2_ipv6: "ipv6",
4226 apn_user_name_ipv4: 'ppp_username_check',
4227 apn_secretcode_ipv4: 'ppp_secretcode_check',
4228 apn_user_name_ipv6: 'ppp_username_check',
4229 apn_secretcode_ipv6: 'ppp_secretcode_check'
4230 }
4231 });
4232 }
4233
4234 return {
4235 init: initialize
4236 };
mj.qu11d28a82024-12-17 18:09:17 -08004237});
4238define("network_info","underscore jquery knockout set service".split(" "),
4239 function (_, $, ko, config, service) {
4240
4241 function NetInfoVM() {
4242 var target = this;
4243 var network_status = service.getNetworkStatus();
4244
4245 target.pci = ko.observable(network_status.pci);
4246 target.sinr = ko.observable(network_status.sinr);
4247 target.rsrp = ko.observable(network_status.rsrp);
4248 target.rsrq = ko.observable(network_status.rsrq);
4249 target.plmn = ko.observable(network_status.plmn);
4250 target.cellid = ko.observable(network_status.cellid);
w.dengbcaf3a52024-12-30 17:43:27 +08004251 target.band = ko.observable(network_status.band);
mj.qu11d28a82024-12-17 18:09:17 -08004252 }
4253
4254 function initialize() {
4255 var container = $('#container');
4256 ko.cleanNode(container[0]);
4257 var imVm = new NetInfoVM();
4258 ko.applyBindings(imVm, container[0]);
4259 }
4260
4261 return {
4262 init: initialize
4263 };
4264});