blob: fb1a2eb74a46f99842885380aa524a14697b462e [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;
2393 if (config.WIFI_SUPPORT_QR_SWITCH == false) {
2394 target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
2395 } else {
2396 var wifiInfo = service.getWifiBasic();
2397 target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
2398 }
2399 if(config.WIFI_SUPPORT_QR_CODE){
2400 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2401 } else {
2402 target.qrcodeSrc = './pic/res_blacktrans.png';
2403 }
2404 target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
2405 target.deviceInfo = ko.observable([]);
2406 target.isHomePage = ko.observable(false);
2407 if (window.location.hash == "#main") {
2408 target.isHomePage(true);
2409 }
2410
2411 target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
2412 target.unlockCode = ko.observable();
2413
2414 var info = service.getNetworkUnlockTimes();
2415 target.times = ko.observable(info.unlock_nck_time);
2416
2417 //显示工作模式设置窗口
2418 target.showOpModeWindow = showOpModeWindowFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002419
qumengjiaca65ef52024-11-06 15:42:21 +08002420 target.isLoggedIn = ko.observable(false);
2421 target.enableFlag = ko.observable(false);
2422 //解锁
2423 target.unlock = unlockFunc;
2424
2425 //更新工作模式状态
2426 target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002427
qumengjiaca65ef52024-11-06 15:42:21 +08002428 //定时检查工作模式状态
2429 if (target.hasRj45) {
2430 target.refreshOpmodeInfo();
2431 addInterval(function () {
2432 target.refreshOpmodeInfo();
2433 }, 1000);
2434 }
mj.qu11d28a82024-12-17 18:09:17 -08002435
qumengjiaca65ef52024-11-06 15:42:21 +08002436 //更新工作模式状态
2437 function refreshOpmodeInfoFunc() {
2438 var obj = service.getStatusInfo();
2439 target.isLoggedIn(obj.isLoggedIn);
2440
2441 if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
2442 window.location.reload();
2443 return;
2444 }
2445
2446 curCableMode = checkCableMode(obj.blc_wan_mode);
2447 target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
2448 if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
2449 target.enableFlag(true);
2450 } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
2451 target.enableFlag(false);
2452 } else {
2453 target.enableFlag(true);
2454 }
2455 var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
2456 var currMode = "";
2457 switch (getMode) {
2458 case "PPP":
2459 currMode = "opmode_gateway";
2460 break;
2461 case "PPPOE":
2462 currMode = "opmode_cable";
2463 break;
2464 case "AUTO":
2465 currMode = "opmode_auto";
2466 break;
2467 default:
2468 break;
2469 }
2470 $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
2471 }
mj.qu11d28a82024-12-17 18:09:17 -08002472
qumengjiaca65ef52024-11-06 15:42:21 +08002473 //解锁
2474 function unlockFunc() {
2475 showLoading();
2476 service.unlockNetwork({
2477 unlock_network_code: target.unlockCode()
2478 }, function (data) {
2479 target.unlockCode("");
2480 if (data && data.result == "success") {
2481 successOverlay();
2482 if (window.location.hash == "#main") {
2483 setTimeout(function () {
2484 window.location.reload();
2485 }, 500);
2486 } else {
2487 window.location.hash = "#main";
2488 }
2489 } else {
2490 var info = service.getNetworkUnlockTimes();
2491 target.times(info.unlock_nck_time);
2492 errorOverlay();
2493 }
2494 })
2495 }
mj.qu11d28a82024-12-17 18:09:17 -08002496
qumengjiaca65ef52024-11-06 15:42:21 +08002497 //显示工作模式设置窗口
2498 function showOpModeWindowFunc() {
2499 showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
2500 }
2501 }
2502
2503 return {
2504 init: initialize
2505 };
2506});
2507
2508// RJ45联网设置模块
mj.qu11d28a82024-12-17 18:09:17 -08002509
qumengjiaca65ef52024-11-06 15:42:21 +08002510define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
2511function(_, $, ko, config, service) {
2512 var dialActions = _.map(config.dialActions, function(elem){
2513 return new Option(elem.name, elem.value);
2514 });
mj.qu11d28a82024-12-17 18:09:17 -08002515
qumengjiaca65ef52024-11-06 15:42:21 +08002516 var dialModes = _.map(config.pppoeModes, function(elem) {
2517 return new Option(elem.name, elem.value);
2518 });
mj.qu11d28a82024-12-17 18:09:17 -08002519
qumengjiaca65ef52024-11-06 15:42:21 +08002520 var checkStatusTimer = 0;
2521 var checkConCounter = 0;
2522 var timeoutTipShowed = false;
2523
2524 // 联网设置view model.
mj.qu11d28a82024-12-17 18:09:17 -08002525
qumengjiaca65ef52024-11-06 15:42:21 +08002526 function PPPoEViewModel() {
2527 var pppObj = service.getPppoeParams();
2528 var ethParams = pppObj;
2529 var target = this;
mj.qu11d28a82024-12-17 18:09:17 -08002530
qumengjiaca65ef52024-11-06 15:42:21 +08002531 target.staticNoticeShow = ko.observable();
2532 target.dhcpNoticeShow = ko.observable();
2533 target.pppoeNoticeShow = ko.observable();
2534 target.autoNoticeShow = ko.observable();
2535 target.staticNotice = ko.observable();
2536 target.dhcpNotice = ko.observable();
2537 target.pppoeNotice = ko.observable();
2538 target.autoNotice = ko.observable();
2539 target.dhcpNoticeText = ko.observable();
2540 target.staticNoticeText = ko.observable();
2541 target.pppoeNoticeText = ko.observable();
2542 target.autoNoticeText = ko.observable();
2543 target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
2544 target.showPassword = ko.observable(false);
2545 target.modes = ko.observableArray(dialModes);
2546 target.isPppoeMode = ko.observable(false);
2547 target.isStaticMode = ko.observable(false);
2548 target.isAutoMode = ko.observable(false);
2549 target.action = ko.observable();
2550 target.btnTrans = ko.observable();
2551 target.enableFlag = ko.observable();
2552 target.isShowDisbtn = ko.observable();
2553 target.isShowCancelbtn = ko.observable();
mj.qu11d28a82024-12-17 18:09:17 -08002554
qumengjiaca65ef52024-11-06 15:42:21 +08002555 if(pppObj.rj45_state == "dead"){
2556 checkRj45DeadTip();
2557 } else if(pppObj.rj45_state == "connect"){
2558 timeoutTipShowed = true;
2559 setRj45CheckTimer("connect");
2560 } else if(pppObj.rj45_state == "working"){
2561 setRj45WorkingTip();
2562 }
mj.qu11d28a82024-12-17 18:09:17 -08002563
qumengjiaca65ef52024-11-06 15:42:21 +08002564 target.user = ko.observable(pppObj.pppoe_username);
2565 target.password = ko.observable(pppObj.pppoe_cc);
2566 target.autoUser = ko.observable(pppObj.pppoe_username);
2567 target.autoPassword = ko.observable(pppObj.pppoe_cc);
2568 target.pppMode = ko.observable(pppObj.ethwan_dialmode);
2569 initContronler();
mj.qu11d28a82024-12-17 18:09:17 -08002570
qumengjiaca65ef52024-11-06 15:42:21 +08002571
2572 //下拉框选择改变下面DIV模块
2573 target.changeModeDiv = changeModeDivFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002574
qumengjiaca65ef52024-11-06 15:42:21 +08002575 target.radioHandler = radioHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002576
qumengjiaca65ef52024-11-06 15:42:21 +08002577 target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
2578 target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
2579 target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
2580 target.subnetMask = ko.observable(pppObj.static_wan_netmask);
2581 target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
mj.qu11d28a82024-12-17 18:09:17 -08002582
qumengjiaca65ef52024-11-06 15:42:21 +08002583 addInterval(function(){
2584 ethParams = service.getPppoeParams();
2585 pppObj.rj45_state = ethParams.rj45_state;
2586 initContronler();
2587 }, 1000);
mj.qu11d28a82024-12-17 18:09:17 -08002588
qumengjiaca65ef52024-11-06 15:42:21 +08002589 // 取消连接按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002590
qumengjiaca65ef52024-11-06 15:42:21 +08002591 target.cancelConnect = cancelConnectFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002592
qumengjiaca65ef52024-11-06 15:42:21 +08002593 // 应用按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002594
qumengjiaca65ef52024-11-06 15:42:21 +08002595 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002596
qumengjiaca65ef52024-11-06 15:42:21 +08002597 //密码显示事件
2598 target.showPasswordHandler = function () {
2599 var checkbox = $("#showPassword:checked");
2600 if (checkbox && checkbox.length == 0) {
2601 target.showPassword(true);
2602 } else {
2603 target.showPassword(false);
2604 }
2605 };
mj.qu11d28a82024-12-17 18:09:17 -08002606
qumengjiaca65ef52024-11-06 15:42:21 +08002607 // 更新当前界面状态、按钮、提示语等.
mj.qu11d28a82024-12-17 18:09:17 -08002608
qumengjiaca65ef52024-11-06 15:42:21 +08002609 function initContronler() {
2610 checkRj45DeadTip();
2611 if(target.currentMode() == "PPPOE"){
2612 target.isPppoeMode(true);
2613 target.isStaticMode(false);
2614 target.isAutoMode(false);
2615 target.staticNoticeShow(false);
2616 target.dhcpNoticeShow(false);
2617 target.autoNoticeShow(false);
2618 } else if(target.currentMode() == "AUTO"){
2619 target.isStaticMode(false);
2620 target.isPppoeMode(false);
2621 target.isAutoMode(true);
2622 target.dhcpNoticeShow(false);
2623 target.pppoeNoticeShow(false);
2624 target.staticNoticeShow(false);
2625 } else if(target.currentMode() == "STATIC"){
2626 target.isStaticMode(true);
2627 target.isPppoeMode(false);
2628 target.isAutoMode(false);
2629 target.dhcpNoticeShow(false);
2630 target.pppoeNoticeShow(false);
2631 target.autoNoticeShow(false);
2632 } else{
2633 target.isStaticMode(false);
2634 target.isPppoeMode(false);
2635 target.isAutoMode(false);
2636 target.staticNoticeShow(false);
2637 target.pppoeNoticeShow(false);
2638 target.autoNoticeShow(false);
2639 }
2640 if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
2641 target.enableFlag(false);
2642 } else {
2643 target.enableFlag(true);
2644 }
2645 if(pppObj.rj45_state == "connect"){
2646 if(target.pppMode() == "auto_dial"){
2647 target.action("connect");
2648 }else{
2649 target.action("disconnect");
2650 }
2651 } else if(pppObj.rj45_state == "working"){
2652 target.action("disconnect");
2653 }else{
2654 target.action("connect");
2655 }
2656 //应用/连接按钮
2657 if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
2658 target.btnTrans("connect");
2659 } else{
2660 target.btnTrans("apply");
2661 }
2662 if(pppObj.rj45_state != "idle"){
2663 $("#pppoeApply").attr("disabled", true);
2664 }else {
2665 $("#pppoeApply").attr("disabled", false);
2666 }
mj.qu11d28a82024-12-17 18:09:17 -08002667
qumengjiaca65ef52024-11-06 15:42:21 +08002668 //取消/断开按钮
2669 target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
2670 target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
mj.qu11d28a82024-12-17 18:09:17 -08002671
qumengjiaca65ef52024-11-06 15:42:21 +08002672 $("#pppoeApply").translate();
2673 }
2674 // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002675
qumengjiaca65ef52024-11-06 15:42:21 +08002676 function setRj45CheckTimer(action){
2677 checkStatusTimer && window.clearInterval(checkStatusTimer);
2678 if("connect" != action){
2679 checkStatusTimer = addInterval(function () {
2680 checkDisconnectStatus();
2681 }, 2000);
2682 }else{
2683 if(target.currentMode() == "PPPOE"){
2684 target.pppoeNoticeShow(true);
2685 target.pppoeNotice("pppoe_processing");
2686 target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
2687 } else if(target.currentMode() == "STATIC"){
2688 target.staticNoticeShow(true);
2689 target.staticNotice("static_processing");
2690 target.staticNoticeText($.i18n.prop("static_processing"));
2691 } else if(target.currentMode() == "DHCP"){
2692 target.dhcpNoticeShow(true);
2693 target.dhcpNotice("dyn_processing");
2694 target.dhcpNoticeText($.i18n.prop("dyn_processing"));
2695 }else{
2696 target.autoNoticeShow(true);
2697 target.autoNotice("auto_processing");
2698 target.autoNoticeText($.i18n.prop("auto_processing"));
2699 }
2700 checkStatusTimer = addInterval(function () {
2701 checkConnectionStatus();
2702 }, 2000);
2703 }
2704 }
2705 // 设置后通过定时检查rj45_state状态,判断连接操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002706
qumengjiaca65ef52024-11-06 15:42:21 +08002707 function checkConnectionStatus(){
2708 if(checkConCounter < 1){
2709 checkConCounter++;
2710 return;
2711 }
2712 if(pppObj.rj45_state == "connect"){
2713 if(target.currentMode() != ethParams.ethwan_mode){
2714 if(target.currentMode() == "AUTO"){
2715 target.autoNoticeShow(true);
2716 }else if(target.currentMode() == "PPPOE"){
2717 target.pppoeNoticeShow(true);
2718 }else if(target.currentMode() == "STATIC"){
2719 target.staticNoticeShow(true);
2720 }else if(target.currentMode() == "DHCP"){
2721 target.dhcpNoticeShow(true);
2722 }
2723 }
2724 if(checkConCounter > 6){
2725 if(timeoutTipShowed == false){
2726 timeoutTipShowed = true;
2727 showAlert("ussd_operation_timeout");
2728 }
2729 }
2730 checkConCounter++;
2731 } else if (pppObj.rj45_state == "working") {
2732 hideLoading();
2733 setRj45WorkingTip();
2734 window.clearInterval(checkStatusTimer);
2735 } else if (pppObj.rj45_state == "dead") {
2736 hideLoading();
2737 checkRj45DeadTip();
2738 window.clearInterval(checkStatusTimer);
2739 } else if(pppObj.rj45_state == "idle"){
2740 hideLoading();
2741 if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
2742 timeoutTipShowed == false && target.dhcpNoticeShow(true);
2743 target.dhcpNotice("dyn_fail");
2744 target.dhcpNoticeText($.i18n.prop("dyn_fail"));
2745 }
2746 if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
2747 timeoutTipShowed == false && target.staticNoticeShow(true);
2748 target.staticNotice("static_fail");
2749 target.staticNoticeText($.i18n.prop("static_fail"));
2750 }
2751 if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
2752 timeoutTipShowed == false && target.pppoeNoticeShow(true);
2753 target.pppoeNotice("pppoe_fail");
2754 target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
2755 }
2756 if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
2757 timeoutTipShowed == false && target.autoNoticeShow(true);
2758 target.autoNotice("auto_fail");
2759 target.autoNoticeText($.i18n.prop("auto_fail"));
2760 }
2761 window.clearInterval(checkStatusTimer);
2762 } else{
2763 hideLoading();
2764 window.clearInterval(checkStatusTimer);
2765 }
2766 }
2767 // 设置连接成功时提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002768
qumengjiaca65ef52024-11-06 15:42:21 +08002769 function setRj45WorkingTip(){
2770 if(target.currentMode() == ethParams.ethwan_mode){
2771 if(target.currentMode() == "AUTO") {
2772 target.autoNoticeShow(true);
2773 target.autoNotice("auto_success");
2774 target.autoNoticeText($.i18n.prop("auto_success"));
2775 }else if(target.currentMode() == "PPPOE") {
2776 target.pppoeNoticeShow(true);
2777 target.pppoeNotice("pppoe_success");
2778 target.pppoeNoticeText($.i18n.prop("pppoe_success"));
2779 }else if(target.currentMode() == "STATIC") {
2780 target.staticNoticeShow(true);
2781 target.staticNotice("static_success");
2782 target.staticNoticeText($.i18n.prop("static_success"));
2783 }else if(target.currentMode() == "DHCP" ) {
2784 target.dhcpNoticeShow(true);
2785 target.dhcpNotice("dyn_success");
2786 target.dhcpNoticeText($.i18n.prop("dyn_success"));
2787 }
2788 }
2789 }
mj.qu11d28a82024-12-17 18:09:17 -08002790
qumengjiaca65ef52024-11-06 15:42:21 +08002791 // 设置网线断开提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002792
qumengjiaca65ef52024-11-06 15:42:21 +08002793 function checkRj45DeadTip(){
2794 if(pppObj.rj45_state != "dead"){
2795 if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
2796 target.autoNoticeShow(false);
2797 }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
2798 target.pppoeNoticeShow(false);
2799 }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
2800 target.staticNoticeShow(false);
2801 }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
2802 target.dhcpNoticeShow(false);
2803 }
mj.qu11d28a82024-12-17 18:09:17 -08002804
qumengjiaca65ef52024-11-06 15:42:21 +08002805 } else{
2806 target.dhcpNotice("pppoe_msg");
2807 target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
2808 target.staticNotice("pppoe_msg");
2809 target.staticNoticeText($.i18n.prop("pppoe_msg"));
2810 target.pppoeNotice("pppoe_msg");
2811 target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
2812 target.autoNotice("pppoe_msg");
2813 target.autoNoticeText($.i18n.prop("pppoe_msg"));
2814 if(target.currentMode() == "AUTO") {
2815 target.autoNoticeShow(true);
2816 }else if(target.currentMode() == "PPPOE") {
2817 target.pppoeNoticeShow(true);
2818 }else if(target.currentMode() == "STATIC") {
2819 target.staticNoticeShow(true);
2820 }else if(target.currentMode() == "DHCP") {
2821 target.dhcpNoticeShow(true);
2822 }
2823 }
2824 }
2825 // 设置后通过定时检查rj45_state状态,判断断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002826
qumengjiaca65ef52024-11-06 15:42:21 +08002827 function checkDisconnectStatus(){
2828 if(checkConCounter < 1){
2829 checkConCounter++;
2830 } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
2831 target.dhcpNoticeShow(false);
2832 target.staticNoticeShow(false);
2833 target.pppoeNoticeShow(false);
2834 target.autoNoticeShow(false);
2835 window.clearInterval(checkStatusTimer);
2836 successOverlay();
2837 } else if(checkConCounter > 6){
2838 if(timeoutTipShowed == false){
2839 timeoutTipShowed = true;
2840 showAlert("ussd_operation_timeout");
2841 }
2842 window.clearInterval(checkStatusTimer);
2843 } else if(checkConCounter < 7) {
2844 checkConCounter++;
2845 } else {
2846 hideLoading();
2847 window.clearInterval(checkStatusTimer);
2848 }
2849 }
mj.qu11d28a82024-12-17 18:09:17 -08002850
qumengjiaca65ef52024-11-06 15:42:21 +08002851 //应用按钮事件.
2852 function saveFunc(){
2853 target.dhcpNoticeShow(false);
2854 target.staticNoticeShow(false);
2855 target.pppoeNoticeShow(false);
2856 target.autoNoticeShow(false);
2857 if(pppObj.rj45_state == "dead"){
2858 showAlert("pppoe_msg");
2859 return;
2860 }
2861 var requestParams = {};
2862 if($("#pppoe_mode").val() == "PPPOE") {
2863 requestParams = $.extend({}, {
2864 goformId: "WAN_GATEWAYMODE_PPPOE",
2865 pppoe_username: target.user(),
2866 pppoe_cc: target.password()
2867 });
2868 } else if($("#pppoe_mode").val() == "AUTO") {
2869 requestParams = $.extend({}, {
2870 goformId: "WAN_GATEWAYMODE_AUTO",
2871 pppoe_username: target.autoUser(),
2872 pppoe_cc: target.autoPassword()
2873 });
2874 } else if($("#pppoe_mode").val() == "STATIC") {
2875 if(target.ipAddress() == target.defaultGateway()){
2876 showAlert("ip_gate_not_same");
2877 return;
2878 }
2879 if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
2880 showAlert("ip_innergate_not_same");
2881 return;
2882 }
2883 requestParams = $.extend({}, {
2884 goformId: "WAN_GATEWAYMODE_STATIC",
2885 static_wan_ipaddr: target.ipAddress(),
2886 static_wan_netmask: target.subnetMask(),
2887 static_wan_gateway: target.defaultGateway(),
2888 static_wan_primary_dns: target.primaryDNS(),
2889 static_wan_secondary_dns: target.secondaryDNS(),
2890 WAN_MODE: "STATIC"
2891 });
2892 } else {
2893 requestParams = $.extend({}, {
2894 goformId: "WAN_GATEWAYMODE_DHCP"
2895 });
2896 }
2897 requestParams.action_link = "connect";
2898 requestParams.dial_mode = target.pppMode();
2899 showLoading("waiting");
mj.qu11d28a82024-12-17 18:09:17 -08002900
qumengjiaca65ef52024-11-06 15:42:21 +08002901 service.setPppoeDialMode(requestParams, function(data){
2902 if(data.result){
2903 target.currentMode($("#pppoe_mode").val());
2904 pppObj = service.getPppoeParams();
2905 checkConCounter = 0;
2906 timeoutTipShowed = false;
2907 setRj45CheckTimer("connect");
2908 $("#pppoeApply").translate();
2909 } else {
2910 errorOverlay("pppoe_message_send_fail");
2911 }
2912 });
mj.qu11d28a82024-12-17 18:09:17 -08002913
qumengjiaca65ef52024-11-06 15:42:21 +08002914 }
mj.qu11d28a82024-12-17 18:09:17 -08002915
qumengjiaca65ef52024-11-06 15:42:21 +08002916 //取消连接按钮事件.
2917 function cancelConnectFunc(){
2918 target.dhcpNoticeShow(false);
2919 target.staticNoticeShow(false);
2920 target.pppoeNoticeShow(false);
2921 target.autoNoticeShow(false);
2922 if(pppObj.rj45_state == "dead"){
2923 showAlert("pppoe_msg");
2924 return;
2925 }
2926 var requestParams = {
2927 dial_mode: target.pppMode(),
2928 action_link: "disconnect"
2929 };
2930 if(pppObj.ethwan_mode == "PPPOE") {
2931 requestParams = $.extend(requestParams, {
2932 goformId: "WAN_GATEWAYMODE_PPPOE",
2933 pppoe_username: pppObj.pppoe_username,
2934 pppoe_cc: pppObj.pppoe_cc
2935 });
2936 }else if(pppObj.ethwan_mode == "AUTO") {
2937 requestParams = $.extend(requestParams, {
2938 goformId: "WAN_GATEWAYMODE_AUTO",
2939 pppoe_username: pppObj.pppoe_username,
2940 pppoe_cc: pppObj.pppoe_cc
2941 });
2942 }else if(pppObj.ethwan_mode == "STATIC") {
2943 requestParams = $.extend(requestParams, {
2944 goformId: "WAN_GATEWAYMODE_STATIC",
2945 static_wan_ipaddr: pppObj.static_wan_ipaddr,
2946 static_wan_netmask: pppObj.static_wan_netmask,
2947 static_wan_gateway: pppObj.static_wan_gateway,
2948 static_wan_primary_dns: pppObj.static_wan_primary_dns,
2949 static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
2950 WAN_MODE: "STATIC"
2951 });
2952 }else {
2953 requestParams = $.extend(requestParams, {
2954 goformId: "WAN_GATEWAYMODE_DHCP"
2955 });
2956 }
2957 showLoading("waiting");
2958 service.setPppoeDialMode(requestParams, function(data){
2959 if(data.result){
2960 checkConCounter = 0;
2961 timeoutTipShowed = false;
2962 setRj45CheckTimer("disconnect");
2963 $("#pppoeApply").translate();
2964 } else {
2965 errorOverlay("pppoe_message_send_fail");
2966 }
2967 });
mj.qu11d28a82024-12-17 18:09:17 -08002968
qumengjiaca65ef52024-11-06 15:42:21 +08002969 }
mj.qu11d28a82024-12-17 18:09:17 -08002970
qumengjiaca65ef52024-11-06 15:42:21 +08002971 function radioHandlerFunc(){
2972 initContronler();
2973 return true;
2974 }
mj.qu11d28a82024-12-17 18:09:17 -08002975
qumengjiaca65ef52024-11-06 15:42:21 +08002976 function changeModeDivFunc(){
2977 initContronler();
2978 }
mj.qu11d28a82024-12-17 18:09:17 -08002979
qumengjiaca65ef52024-11-06 15:42:21 +08002980 }
2981
2982 function bindContainer(vm){
2983 var container = $('#container');
2984 ko.cleanNode(container[0]);
2985 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08002986
qumengjiaca65ef52024-11-06 15:42:21 +08002987 }
2988 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08002989
qumengjiaca65ef52024-11-06 15:42:21 +08002990 function initialize() {
2991 var vm = new PPPoEViewModel();
2992 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08002993
qumengjiaca65ef52024-11-06 15:42:21 +08002994 $("#pppoeApply").translate();
mj.qu11d28a82024-12-17 18:09:17 -08002995
qumengjiaca65ef52024-11-06 15:42:21 +08002996 $('#pppoeForm').validate({
2997 submitHandler : function() {
2998 vm.save();
2999 },
3000 rules: {
3001 txtPin: "wps_pin_check",
3002 txtIpAddress: "dmz_ip_check",
3003 txtSubnetMask: {
3004 ipv4: true,
3005 subnetmask_check: true
3006 },
3007 txtDefaultGateway: {
3008 ipv4: true,
3009 gateway_check: true
3010 },
3011 txtPrimaryDNS: {
3012 ipv4: true,
3013 dns_check:true
3014 },
3015 txtSecondaryDNS: {
3016 ipv4: true,
3017 dns_check:true
3018 }
3019 }
3020 });
3021 }
mj.qu11d28a82024-12-17 18:09:17 -08003022
3023
qumengjiaca65ef52024-11-06 15:42:21 +08003024//from 4.0
3025 // 有效DNS检查.
mj.qu11d28a82024-12-17 18:09:17 -08003026
qumengjiaca65ef52024-11-06 15:42:21 +08003027function validateDns(dns){
3028 if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
3029 return false;
3030 }
3031 return true;
3032}
3033 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08003034
qumengjiaca65ef52024-11-06 15:42:21 +08003035function isStaticIPValid(ip, lanip, lanmask){
3036 if(!ip || !lanip || !lanmask){//各参数不能为空
3037 return false;
3038 }
3039 if(ip == lanip){// 与内网IP相等
3040 return true;
3041 }
3042 var res1 = [], res2 = [], mask = [];
3043 addr1 = ip.split(".");
3044 addr2 = lanip.split(".");
3045 mask = lanmask.split(".");
3046 for(var i = 0; i < addr1.length; i += 1){
3047 res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
3048 res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
3049 }
3050 if(res1.join(".") == res2.join(".")){//在同一个网段
3051 return true;
3052 }else{//不在同一个网段
3053 return false;
3054 }
3055}
3056
3057// 有效子网掩码验证.
mj.qu11d28a82024-12-17 18:09:17 -08003058
qumengjiaca65ef52024-11-06 15:42:21 +08003059function isNetmaskIPValid(ip) {
3060 if (ip == 255 || ip == 254 || ip == 252 || ip == 248
3061 || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
3062 {
3063 return true;
3064 }
3065 else
3066 {
3067 return false;
3068 }
3069}
3070 // 有效子网掩码检查.
mj.qu11d28a82024-12-17 18:09:17 -08003071
qumengjiaca65ef52024-11-06 15:42:21 +08003072function validateNetmask(netmask) {
3073 var array = new Array();
3074 array = netmask.split(".");
3075
3076 if (array.length != 4) {
3077 return false;
3078 }
3079
3080 array[0] = parseInt(array[0]);
3081 array[1] = parseInt(array[1]);
3082 array[2] = parseInt(array[2]);
3083 array[3] = parseInt(array[3]);
3084
3085 if (array[3] != 0) {
3086 if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
3087 return false;
3088 } else {
3089 if (!isNetmaskIPValid(array[3])) {
3090 return false;
3091 }
3092 }
3093 }
3094
3095 if (array[2] != 0) {
3096 if (array[1] != 255 || array[0] != 255) {
3097 return false;
3098 } else {
3099 if (!isNetmaskIPValid(array[2])) {
3100 return false;
3101 }
3102 }
3103 }
3104
3105 if (array[1] != 0) {
3106 if (array[0] != 255) {
3107 return false;
3108 } else{
3109 if (!isNetmaskIPValid(array[1])) {
3110 return false;
3111 }
3112 }
3113 }
3114 if(array[0]!=255) {
3115 return false;
3116 }
3117 if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
3118 return false;
3119 }
3120 return true;
3121}
mj.qu11d28a82024-12-17 18:09:17 -08003122
qumengjiaca65ef52024-11-06 15:42:21 +08003123 // subnetmask_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003124
qumengjiaca65ef52024-11-06 15:42:21 +08003125jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
3126 var result = validateNetmask(value);
3127 return this.optional(element) || result;
3128});
3129 // dns_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003130
qumengjiaca65ef52024-11-06 15:42:21 +08003131jQuery.validator.addMethod("dns_check", function (value, element, param) {
3132 var result = validateDns(value);
3133 return this.optional(element) || result;
3134});
3135 // 有效网关检查.
mj.qu11d28a82024-12-17 18:09:17 -08003136
qumengjiaca65ef52024-11-06 15:42:21 +08003137function validateGateway(wanIp, netmaskIp, gatewayIp) {
3138 if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
3139 return true;
3140 } else {
3141 return false;
3142 }
3143}
3144 // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
mj.qu11d28a82024-12-17 18:09:17 -08003145
qumengjiaca65ef52024-11-06 15:42:21 +08003146function myConcat(ip1,ip2){
3147 var result = [];
3148 var iplArr = ip1.split(".");
3149 var ip2Arr = ip2.split(".");
3150 for(var i = 0; i < iplArr.length;i++){
3151 result[i] = (iplArr[i] & ip2Arr[i]);
3152 }
3153 return result.join(".");
3154}
3155 // gateway_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003156
qumengjiaca65ef52024-11-06 15:42:21 +08003157jQuery.validator.addMethod("gateway_check", function (value, element, param) {
3158 var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
3159 return this.optional(element) || result;
3160});
mj.qu11d28a82024-12-17 18:09:17 -08003161
qumengjiaca65ef52024-11-06 15:42:21 +08003162 return {
3163 init: initialize
3164 };
3165});
3166//联网设置模块
3167define("network_dial_set","underscore jquery knockout set service".split(" "),
3168function(_, $, ko, config, service) {
3169
3170 //联网设置view model
3171 function DialVM() {
3172 var dialMode = service.getConnectionMode();
3173 var target = this;
3174
3175 target.selectMode = ko.observable(dialMode.connectionMode);
3176 target.enableFlag = ko.observable(true);
3177 target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
3178 var originalRoaming = dialMode.isAllowedRoaming;
3179
3180 target.setAllowedRoaming = setAllowedRoamingFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003181
qumengjiaca65ef52024-11-06 15:42:21 +08003182 var checkboxFlag = $(".checkboxToggle");
3183 target.checkEnable = checkEnableFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003184
qumengjiaca65ef52024-11-06 15:42:21 +08003185 //修改联网模式
3186 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003187
qumengjiaca65ef52024-11-06 15:42:21 +08003188 function saveFunc() {
3189 showLoading();
3190 var connMode = target.selectMode();
3191 //当选择自动时,下发原先的勾选状态
3192 if (connMode == 'auto_dial') {
3193 originalRoaming = target.isAllowedRoaming();
3194 } else {
3195 target.isAllowedRoaming(originalRoaming);
3196 }
3197 service.setConnectionMode({
3198 connectionMode: connMode,
3199 isAllowedRoaming: target.isAllowedRoaming()
3200 }, function (result) {
3201 if (result.result == "success") {
3202 successOverlay();
3203 } else {
3204 errorOverlay();
3205 }
3206 });
3207 }
mj.qu11d28a82024-12-17 18:09:17 -08003208
qumengjiaca65ef52024-11-06 15:42:21 +08003209 function setAllowedRoamingFunc() {
3210 if(!$("#roamBtn").hasClass("disable")){
3211 var checkbox = $("#isAllowedRoaming:checked");
3212 if(checkbox && checkbox.length == 0 ){
3213 target.isAllowedRoaming("on");
3214 }else{
3215 target.isAllowedRoaming("off");
3216 }
3217 }
3218 }
mj.qu11d28a82024-12-17 18:09:17 -08003219
qumengjiaca65ef52024-11-06 15:42:21 +08003220 function checkEnableFunc() {
3221 var status = service.getStatusInfo();
3222
3223 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
3224 target.enableFlag(false);
3225 disableCheckbox(checkboxFlag);
3226 }
3227 else {
3228 target.enableFlag(true);
3229 enableCheckbox(checkboxFlag);
3230 }
3231 }
3232
3233 }
3234
3235 //联网设置初始化.
3236 function initialize() {
3237 var vm = new DialVM();
3238 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08003239
qumengjiaca65ef52024-11-06 15:42:21 +08003240 vm.checkEnable();
3241 addInterval( vm.checkEnable, 1000);
3242 }
mj.qu11d28a82024-12-17 18:09:17 -08003243
qumengjiaca65ef52024-11-06 15:42:21 +08003244 function bindContainer(vm){
3245 var container = $('#container');
3246 ko.cleanNode(container[0]);
3247 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08003248
qumengjiaca65ef52024-11-06 15:42:21 +08003249 }
mj.qu11d28a82024-12-17 18:09:17 -08003250
qumengjiaca65ef52024-11-06 15:42:21 +08003251 return {
3252 init: initialize
3253 };
3254});
3255// APN Setting 模块
3256define("network_apn_set","underscore jquery knockout set service".split(" "),
3257 function (_, $, ko, config, service) {
3258
3259 //获取鉴权方式
mj.qu11d28a82024-12-17 18:09:17 -08003260
qumengjiaca65ef52024-11-06 15:42:21 +08003261 function getAuthModes() {
3262 return _.map(config.APN_AUTH_MODES, function (item) {
3263 return new Option(item.name, item.value);
3264 });
3265 }
3266
3267 function getApnPdpTypes() {
3268 var pdpTypesArray = [new Option('IPv4', 'IP')];
3269 if (config.IPV6_SUPPORT) {
3270 pdpTypesArray.push(new Option('IPv6', 'IPv6'));
3271 if (config.IPV4V6_SUPPORT) {
3272 pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
3273 }
3274 if (config.IPV4_AND_V6_SUPPORT) {
3275 pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
3276 }
3277 }
3278 return pdpTypesArray;
3279 }
3280
3281 //获取apn相关信息
mj.qu11d28a82024-12-17 18:09:17 -08003282
qumengjiaca65ef52024-11-06 15:42:21 +08003283 function getApnSet() {
3284 var apnInfo = service.getApnSettings();
3285 apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
3286 apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
3287 apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
3288 return apnInfo;
3289 }
3290 var apnConfigs = {};
3291 var ipv6ApnConfigs = {};
3292 var autoApnConfigs = {};
3293
3294 //解析自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003295
qumengjiaca65ef52024-11-06 15:42:21 +08003296 function getAutoApnsConfig(autoApnV4, autoApnV6) {
3297 var autoApnsV4 = [];
3298 var autoApnsV6 = [];
3299
3300 if (autoApnV4 && autoApnV4.length > 5) {
3301 var apnArr = autoApnV4.split("||");
3302 for (var ki = 0; ki < apnArr.length; ki++) {
3303 if (apnArr[ki] != "") {
3304 var apnItem = parseApnItem(apnArr[ki], false);
3305 autoApnsV4.push(apnItem);
3306 }
3307 }
3308 }
3309 if (autoApnV6 && autoApnV6.length > 5) {
3310 var apnArr = autoApnV6.split("||");
3311 for (var ki = 0; ki < apnArr.length; ki++) {
3312 if (apnArr[ki] != "") {
3313 var apnItem = parseApnItem(apnArr[ki], false);
3314 autoApnsV6.push(apnItem);
3315 }
3316 }
3317 }
3318 return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
3319 }
3320 //解析apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003321
qumengjiaca65ef52024-11-06 15:42:21 +08003322 function getApnConfigs(apnsStr, isIpv6) {
3323 var apnCfgs = [];
3324 var theApnConfigs = {};
3325 if (apnsStr && apnsStr.length > 10) {
3326 var apnArr = apnsStr.split("||");
3327 for (var ki = 0; ki < apnArr.length; ki++) {
3328 if (apnArr[ki] != "") {
3329 var apnItem = parseApnItem(apnArr[ki], isIpv6);
3330 apnCfgs.push(apnItem);
3331 theApnConfigs[apnItem.profileName] = apnItem;
3332 }
3333 }
3334 }
3335 if (isIpv6 == false) {
3336 apnConfigs = theApnConfigs;
3337 } else {
3338 ipv6ApnConfigs = theApnConfigs;
3339 }
3340 return apnCfgs;
3341 }
3342
3343 //解析单条apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003344
qumengjiaca65ef52024-11-06 15:42:21 +08003345 function parseApnItem(apnStr, isIpv6) {
3346 var apnItem = {};
3347 var items = apnStr.split("($)");
3348 for (var ki = 0; ki < items.length; ki++) {
3349 apnItem.profileName = items[0];
3350 apnItem.pdpType = items[7];
3351 if (isIpv6 == false) {
3352 apnItem.dnsMode = items[10];
3353 apnItem.dns1 = items[11];
3354 apnItem.dns2 = items[12];
3355 apnItem.wanApn = items[1];
3356 apnItem.authMode = items[4].toLowerCase();
3357 apnItem.username = items[5];
3358 apnItem.password = items[6];
3359 } else {
3360 apnItem.dnsModeV6 = items[10];
3361 apnItem.dns1V6 = items[11];
3362 apnItem.dns2V6 = items[12];
3363 apnItem.wanApnV6 = items[1];
3364 apnItem.authModeV6 = items[4].toLowerCase();
3365 apnItem.usernameV6 = items[5];
3366 apnItem.passwordV6 = items[6];
3367 }
3368 }
3369 return apnItem;
3370 }
3371 //合并V4\V6自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003372
qumengjiaca65ef52024-11-06 15:42:21 +08003373 function dealAutoApnsV4V6(v4, v6) {
3374 autoApnConfigs = {};
3375 var autoApns = [];
3376 for (var ki = 0; ki < v4.length; ki++) {
3377 var apnElem = v4[ki];
3378 var itemsV6 = v6[ki];
3379 if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
3380 apnElem.usernameV6 = itemsV6.username;
3381 apnElem.passwordV6 = itemsV6.password;
3382 apnElem.dns1V6 = itemsV6.dns1;
3383 apnElem.dns2V6 = itemsV6.dns2;
3384 apnElem.wanApnV6 = itemsV6.wanApn;
3385 apnElem.authModeV6 = itemsV6.authMode;
3386 apnElem.dnsModeV6 = itemsV6.dnsMode;
3387 }
3388 autoApns.push(apnElem);
3389 autoApnConfigs[apnElem.profileName] = apnElem;
3390 }
3391 return autoApns;
3392 }
3393
3394 function getProfileOptions(apns) {
3395 return _.map(apns, function (item) {
3396 return new Option(item.profileName, item.profileName);
3397 });
3398 }
3399
3400 //APNViewModel
mj.qu11d28a82024-12-17 18:09:17 -08003401
qumengjiaca65ef52024-11-06 15:42:21 +08003402 function APNViewModel() {
3403 var target = this;
3404 var apnSettings = getApnSet();
3405 if (apnSettings.apnNumPreset) {
3406 config.maxApnNumber = apnSettings.apnNumPreset;
3407 }
3408
3409 target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
3410 target.apnMode = ko.observable(apnSettings.apnMode);
3411 target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
3412 target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
3413 target.wanDial = ko.observable(apnSettings.wanDial);
mj.qu11d28a82024-12-17 18:09:17 -08003414
qumengjiaca65ef52024-11-06 15:42:21 +08003415 target.showApnDns = ko.observable(config.SHOW_APN_DNS);
3416 target.index = ko.observable(apnSettings.currIndex);
3417 target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
3418 target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
3419
3420 target.apn = ko.observable(apnSettings.wanApn);
3421 target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
3422 target.dns1 = ko.observable(apnSettings.dns1);
3423 target.dns2 = ko.observable(apnSettings.dns2);
3424 target.authModes = ko.observableArray(getAuthModes());
3425 target.username = ko.observable(apnSettings.username);
3426 target.password = ko.observable(apnSettings.password);
mj.qu11d28a82024-12-17 18:09:17 -08003427
qumengjiaca65ef52024-11-06 15:42:21 +08003428 target.pdpTypes = ko.observableArray(getApnPdpTypes());
3429 target.selectedPdpType = ko.observable(apnSettings.pdpType);
3430 target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
3431 target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
3432 target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
3433
3434 target.showPassword = ko.observable(false);
3435
3436 target.apnV6 = ko.observable(apnSettings.wanApnV6);
3437 target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
3438 target.dns1V6 = ko.observable(apnSettings.dns1V6);
3439 target.dns2V6 = ko.observable(apnSettings.dns2V6);
3440 target.authModesV6 = ko.observableArray(getAuthModes());
3441 target.usernameV6 = ko.observable(apnSettings.usernameV6);
3442 target.passwordV6 = ko.observable(apnSettings.passwordV6);
3443 target.pdpTypeNote = ko.observable(true);
3444 if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
3445 target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
3446 } else {
3447 target.selectedAutoProfile = ko.observable();
3448 }
3449
3450 if (config.EMPTY_APN_SUPPORT == false) {
3451 $("#apn_ipv4_apn").addClass("required");
3452 $("#apn_ipv6_apn").addClass("required");
3453 } else {
3454 $("#apn_ipv4_apn").removeClass("required");
3455 $("#apn_ipv6_apn").removeClass("required");
3456 }
mj.qu11d28a82024-12-17 18:09:17 -08003457
qumengjiaca65ef52024-11-06 15:42:21 +08003458 target.disableProfile = ko.observable(false); //表示处于新增页面
3459 target.addApnHide = ko.observable(true);
3460 target.defaultCfg = ko.observable(true); //当前选中的是默认APN
3461 target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
mj.qu11d28a82024-12-17 18:09:17 -08003462
qumengjiaca65ef52024-11-06 15:42:21 +08003463 target.selectedAuthentication = ko.observable(apnSettings.authMode);
3464 target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
3465
3466
3467 target.transApnV6 = ko.observable('apn');
3468 target.transDnsModeV6 = ko.observable('apn_dns_mode');
3469 target.transDns1V6 = ko.observable('apn_dns1');
3470 target.transDns2V6 = ko.observable('apn_dns2');
3471 target.transAuthV6 = ko.observable('apn_authentication');
3472 target.transUserNameV6 = ko.observable('apn_user_name');
3473 target.transPasswordV6 = ko.observable('apn_password');
mj.qu11d28a82024-12-17 18:09:17 -08003474
qumengjiaca65ef52024-11-06 15:42:21 +08003475 target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
3476 target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
3477 target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
3478 target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
3479 target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
3480 target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
3481 target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
3482
3483 target.setDefaultVisible = ko.observable(!isConnectedNetWork());
3484
3485 target.tmp1 = ko.computed(function () {
3486 if (target.selectedPdpType() == "IPv6") {
3487 target.transApnV6('apn');
3488 target.transDnsModeV6('apn_dns_mode');
3489 target.transDns1V6('apn_dns1');
3490 target.transDns2V6('apn_dns2');
3491 target.transAuthV6('apn_authentication');
3492 target.transUserNameV6('apn_user_name');
3493 target.transPasswordV6('apn_password');
3494 } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3495 target.transApn('apn_ipv4_apn');
3496 target.transDnsMode('apn_dns_mode_ipv4');
3497 target.transDns1('apn_dns1_ipv4');
3498 target.transDns2('apn_dns2_ipv4');
3499 target.transAuth('apn_authentication_ipv4');
3500 target.transUserName('apn_user_name_ipv4');
3501 target.transPassword('apn_password_ipv4');
3502
3503 target.transApnV6('apn_ipv6_apn');
3504 target.transDnsModeV6('apn_dns_mode_ipv6');
3505 target.transDns1V6('apn_dns1_ipv6');
3506 target.transDns2V6('apn_dns2_ipv6');
3507 target.transAuthV6('apn_authentication_ipv6');
3508 target.transUserNameV6('apn_user_name_ipv6');
3509 target.transPasswordV6('apn_password_ipv6');
3510 } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
3511 target.transApn('apn');
3512 target.transDnsMode('apn_dns_mode');
3513 target.transDns1('apn_dns1');
3514 target.transDns2('apn_dns2');
3515 target.transAuth('apn_authentication');
3516 target.transUserName('apn_user_name');
3517 target.transPassword('apn_password');
3518 } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
3519 target.transApn('apn');
3520 target.transDnsMode('apn_dns_mode');
3521 target.transDns1('apn_dns1');
3522 target.transDns2('apn_dns2');
3523 target.transAuth('apn_authentication');
3524 target.transUserName('apn_user_name');
3525 target.transPassword('apn_password');
3526 }
3527 $("#apn_setting_form").translate();
3528 });
3529
3530 target.autoApnChecked = ko.computed(function () {
3531 return target.apnMode() == "auto";
3532 });
mj.qu11d28a82024-12-17 18:09:17 -08003533
qumengjiaca65ef52024-11-06 15:42:21 +08003534 target.hasCapacity = ko.computed(function () {
3535 if (target.profiles().length < config.maxApnNumber) {
3536 return true;
3537 } else {
3538 return false;
3539 }
3540 });
3541
3542 target.showDnsV6 = ko.computed(function () {
3543 return target.dnsModeV6() == "manual";
3544 });
mj.qu11d28a82024-12-17 18:09:17 -08003545
qumengjiaca65ef52024-11-06 15:42:21 +08003546 target.showDns = ko.computed(function () {
3547 return target.dnsMode() == "manual";
3548 });
3549
3550
3551 checkDefaultProfileStatus();
3552 target.checkInputDisable = ko.computed(function () {
3553 if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
3554 return false;
3555 }
3556 if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
3557 return true;
3558 }
3559 if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
3560 return false;
3561 }
3562 return false;
3563 });
3564
3565 var data = service.getDeviceInfo();
3566 target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003567
qumengjiaca65ef52024-11-06 15:42:21 +08003568
3569 target.showAutoApnDetail = ko.computed(function () {
3570 if (target.apnMode() != "auto") {
3571 return true;
3572 } else {
3573 return target.autoProfiles().length > 0;
3574 }
3575 });
3576 //密码显示事件
3577 target.showPasswordHandler = function () {
3578 var checkbox = $("#showPassword:checked");
3579 if (checkbox && checkbox.length == 0) {
3580 target.showPassword(true);
3581 } else {
3582 target.showPassword(false);
3583 }
3584 };
3585 //auto apn profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003586
qumengjiaca65ef52024-11-06 15:42:21 +08003587 target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003588
3589
qumengjiaca65ef52024-11-06 15:42:21 +08003590 //profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003591
qumengjiaca65ef52024-11-06 15:42:21 +08003592 target.profileChangeHandler = profileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003593
3594
qumengjiaca65ef52024-11-06 15:42:21 +08003595 //切换profile时重置下面的显示项
3596 target.setUIData = setUIDataFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003597
qumengjiaca65ef52024-11-06 15:42:21 +08003598
3599 //设置默认apn状态
mj.qu11d28a82024-12-17 18:09:17 -08003600
qumengjiaca65ef52024-11-06 15:42:21 +08003601 function checkDefaultProfileStatus() {
3602 var index = getApnIndex();
3603 //默认apn不允许编辑
3604 if (target.apnMode() != "auto") { //当前选中与实际不一致的话
3605 if (target.selectedProfile() != target.defApn()) {
3606 target.defaultCfg(false);
3607 } else {
3608 target.defaultCfg(true); //默认APN
3609 }
3610 } else {
3611 if (target.selectedAutoProfile() != target.defApn()) {
3612 target.defaultCfg(false);
3613 } else {
3614 target.defaultCfg(true); //默认APN
3615 }
3616 }
3617
3618 if (index >= config.defaultApnSize) {
3619 target.predeterminedCfg(false);
3620 } else {
3621 target.predeterminedCfg(true); //预置APN
3622 }
3623 }
3624
3625
3626 //设置为默认apn
qumengjiaca65ef52024-11-06 15:42:21 +08003627
mj.qu11d28a82024-12-17 18:09:17 -08003628 target.setDefaultAct = setDefaultActFunc;
3629
3630
3631
qumengjiaca65ef52024-11-06 15:42:21 +08003632 //APN mode change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003633
qumengjiaca65ef52024-11-06 15:42:21 +08003634 target.apnModeChangeHandler = apnModeChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003635
3636
qumengjiaca65ef52024-11-06 15:42:21 +08003637 function doSetDefaultAct() {
3638 var index = 0;
3639 if (target.apnMode() != 'auto') {
3640 index = getApnIndex();
3641 target.selectedProfile($("#profile").val());
3642 } else {
3643 index = getAutoApnIndex();
3644 target.selectedAutoProfile($("#autoProfile").val());
3645 }
3646 var selectedProfileDetail = target.getSelectedManualProfile();
3647 service.setDefaultApn({
3648 index: index,
3649 apnMode: target.apnMode(),
3650 pdpType: selectedProfileDetail.pdpType,
3651
3652 profileName: selectedProfileDetail.profileName,
3653 wanApn: selectedProfileDetail.wanApn,
3654 authMode: selectedProfileDetail.authMode,
3655 username: selectedProfileDetail.username,
3656 password: selectedProfileDetail.password,
3657 dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
3658 dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
3659 dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
3660 }, function (data) {
3661 if (data.result) {
3662 //showLoading("apn_alert_restart");
3663 //restartDevice(service);
3664 addTimeout(function () {
3665 initialize(true);
3666 target.apnModeChangeHandler();
3667 successOverlay();
3668 }, 500);
3669 } else {
3670 errorOverlay();
3671 }
3672 }, function (data) {
3673 errorOverlay();
3674 });
3675 }
3676
3677 target.getSelectedManualProfile = getSelectedManualProfileFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003678
qumengjiaca65ef52024-11-06 15:42:21 +08003679
3680 //获取自动apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003681
qumengjiaca65ef52024-11-06 15:42:21 +08003682 function getAutoApnIndex() {
3683 var configs = $("#autoProfile option");
3684 for (var ki = 0; ki < configs.length; ki++) {
3685 if (configs[ki].value == target.selectedAutoProfile()) {
3686 return ki;
3687 }
3688 }
3689 return configs.length - 1;
3690 }
mj.qu11d28a82024-12-17 18:09:17 -08003691
qumengjiaca65ef52024-11-06 15:42:21 +08003692 //获取apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003693
qumengjiaca65ef52024-11-06 15:42:21 +08003694 function getApnIndex() {
3695 var configs = $("#profile option");
3696 if (configs.length == 0) {
3697 configs = target.profiles();
3698 }
3699 var ki = 0;
3700 for (; ki < configs.length; ki++) {
3701 if (configs[ki].value == target.selectedProfile()) {
3702 break;
3703 }
3704 }
3705 return ki;
3706 }
3707
3708 //保存APN设置信息
mj.qu11d28a82024-12-17 18:09:17 -08003709
qumengjiaca65ef52024-11-06 15:42:21 +08003710 target.saveAct = saveActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003711
qumengjiaca65ef52024-11-06 15:42:21 +08003712 //编辑APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003713
qumengjiaca65ef52024-11-06 15:42:21 +08003714 function editApnSetting(preAct) { //默认设置按钮触发为TRUE
3715 showLoading();
3716 var apnIndex = getApnIndex();
3717 var sameInfo = false;
3718 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3719 sameInfo = true;
3720 }
3721 var needDoDefault = false;
3722 if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
3723 needDoDefault = true;
3724 }
3725 service.addOrEditApn({
3726 profileName: target.profileName(),
3727 pdpType: target.selectedPdpType(),
3728 index: apnIndex,
3729
3730 wanApn: target.apn(),
3731 authMode: target.selectedAuthentication(),
3732 username: target.username(),
3733 password: target.password(),
3734 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3735 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3736 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3737
3738 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3739 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3740 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3741 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3742 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3743 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3744 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3745 }, function (data) {
3746 if (data.result) {
3747 apnSettings = getApnSet();
3748 if (target.profileName() != target.selectedProfile()) {
3749 var newProfileName = target.profileName();
3750 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3751 $('#profile').val(newProfileName).trigger('change');
3752 }
3753 if (needDoDefault == false) {
3754 successOverlay();
3755 } else {
3756 doSetDefaultAct();
3757 }
3758 } else {
3759 errorOverlay();
3760 }
3761 }, function (data) {
3762 errorOverlay();
3763 });
3764 }
mj.qu11d28a82024-12-17 18:09:17 -08003765
qumengjiaca65ef52024-11-06 15:42:21 +08003766 //新增APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003767
qumengjiaca65ef52024-11-06 15:42:21 +08003768 function addNewApnSetting() {
3769 showLoading("waiting");
3770 var optionLen = $("option", "#profile").length;
3771 if (optionLen < config.defaultApnSize) {
3772 errorOverlay();
3773 return;
3774 }
3775 // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
3776 // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
3777 var sameInfo = false;
3778 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3779 sameInfo = true;
3780 }
3781
3782 service.addOrEditApn({
3783 profileName: target.profileName(),
3784 pdpType: target.selectedPdpType(),
3785 index: optionLen,
3786
3787 wanApn: target.apn(),
3788 authMode: target.selectedAuthentication(),
3789 username: target.username(),
3790 password: target.password(),
3791 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3792 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3793 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3794
3795 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3796 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3797 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3798 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3799 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3800 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3801 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3802 }, function (data) {
3803 if (data.result) {
3804 apnSettings = getApnSet();
3805 if (target.profileName() != target.selectedProfile()) {
3806 var newProfileName = target.profileName();
3807 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3808 $('#profile').val(newProfileName).trigger('change');
3809 }
3810 doSetDefaultAct();
3811 } else {
3812 errorOverlay();
3813 }
3814 }, function (data) {
3815 errorOverlay();
3816 });
3817 }
3818
mj.qu11d28a82024-12-17 18:09:17 -08003819
qumengjiaca65ef52024-11-06 15:42:21 +08003820
3821 var tempApn = {};
3822 //删除APN
mj.qu11d28a82024-12-17 18:09:17 -08003823
qumengjiaca65ef52024-11-06 15:42:21 +08003824 target.deleteAct = deleteActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003825
qumengjiaca65ef52024-11-06 15:42:21 +08003826 //取消新增APN
mj.qu11d28a82024-12-17 18:09:17 -08003827
qumengjiaca65ef52024-11-06 15:42:21 +08003828 target.cancelAddAct = cancelAddActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003829
qumengjiaca65ef52024-11-06 15:42:21 +08003830 //进入新增APN页面
mj.qu11d28a82024-12-17 18:09:17 -08003831
qumengjiaca65ef52024-11-06 15:42:21 +08003832 target.addAct = addActFunc;
3833 //进入新增APN页面
3834 function addActFunc() {
3835 clearValidateMsg('#apn_setting_form');
3836 target.pdpTypeNote(true);
3837 target.disableProfile(true);
3838 target.addApnHide(true);
3839 tempApn = {
3840 profileName: target.profileName(),
3841 selectedPdpType: target.selectedPdpType(),
3842
3843 wanApnV6: target.apnV6(),
3844 dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
3845 dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
3846 dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
3847 authModeV6: target.selectedAuthenticationV6(),
3848 usernameV6: target.usernameV6(),
3849 passwordV6: target.passwordV6(),
mj.qu11d28a82024-12-17 18:09:17 -08003850
qumengjiaca65ef52024-11-06 15:42:21 +08003851 wanApn: target.apn(),
3852 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3853 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3854 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3855 authMode: target.selectedAuthentication(),
3856 username: target.username(),
3857 password: target.password(),
3858
3859 };
3860 target.profileName("");
3861 target.selectedPdpType("IP");
3862 target.selectedPdpTypeTmp("IP");
3863
3864 target.apnV6("");
3865 target.dnsModeV6("auto");
3866 target.dns1V6("");
3867 target.dns2V6("");
3868 target.selectedAuthenticationV6("none");
3869 target.usernameV6("");
3870 target.passwordV6("");
mj.qu11d28a82024-12-17 18:09:17 -08003871
qumengjiaca65ef52024-11-06 15:42:21 +08003872 target.apn("");
3873 target.dnsMode("auto");
3874 target.dns1("");
3875 target.dns2("");
3876 target.selectedAuthentication("none");
3877 target.username("");
3878 target.password("");
3879
3880 }
mj.qu11d28a82024-12-17 18:09:17 -08003881
qumengjiaca65ef52024-11-06 15:42:21 +08003882 //取消新增APN
3883 function cancelAddActFunc() {
3884 clearValidateMsg('#apn_setting_form');
3885 target.pdpTypeNote(false);
3886 target.disableProfile(false);
3887 target.addApnHide(false);
3888 target.profileName(tempApn.profileName);
3889 target.selectedPdpType(tempApn.selectedPdpType);
3890 target.selectedPdpTypeTmp(tempApn.selectedPdpType);
3891
3892 target.apnV6(tempApn.wanApnV6);
3893 target.dnsModeV6(tempApn.dnsModeV6);
3894 target.dns1V6(tempApn.dns1V6);
3895 target.dns2V6(tempApn.dns2V6);
3896 target.selectedAuthenticationV6(tempApn.authModeV6);
3897 target.usernameV6(tempApn.usernameV6);
3898 target.passwordV6(tempApn.passwordV6);
mj.qu11d28a82024-12-17 18:09:17 -08003899
qumengjiaca65ef52024-11-06 15:42:21 +08003900 target.apn(tempApn.wanApn);
3901 target.dnsMode(tempApn.dnsMode);
3902 target.dns1(tempApn.dns1);
3903 target.dns2(tempApn.dns2);
3904 target.selectedAuthentication(tempApn.authMode);
3905 target.username(tempApn.username);
3906 target.password(tempApn.password);
3907
3908 }
mj.qu11d28a82024-12-17 18:09:17 -08003909
qumengjiaca65ef52024-11-06 15:42:21 +08003910 //删除APN
3911 function deleteActFunc() {
3912 if (!target.selectedProfile()) {
3913 showAlert("apn_no_select_alert");
3914 return false;
3915 }
3916 if (target.predeterminedCfg()) { //预置的apn不允许删除
3917 errorOverlay("apn_delete_cant_delete_default");
3918 return false;
3919 }
3920 if (getApnSet().profileName == target.profileName()) {
3921 errorOverlay("apn_cant_delete_current");
3922 return false;
3923 }
3924
3925 showConfirm("apn_delete_confirm", function () {
3926 showLoading('deleting');
3927 service.deleteApn({
3928 index: getApnIndex()
3929 }, function (data) {
3930 if (data.result) {
3931 target.profiles(getProfileOptions(getApnSet().apnConfigs));
3932 target.selectedProfile(target.defApn());
3933 target.profileChangeHandler();
3934 successOverlay();
3935 } else {
3936 errorOverlay();
3937 }
3938 }, function (data) {
3939 errorOverlay();
3940 });
3941 });
3942 }
mj.qu11d28a82024-12-17 18:09:17 -08003943
qumengjiaca65ef52024-11-06 15:42:21 +08003944 //保存APN设置信息
3945 function saveActFunc() {
3946 if (!$('#apn_setting_form').valid()) {
3947 return false;
3948 }
3949 if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
3950 showAlert("apn_no_select_alert");
3951 return false;
3952 }
3953 var exist = false;
3954 $.each(target.profiles(), function (i, e) {
3955 if (e.value == target.profileName()) {
3956 exist = true;
3957 }
3958 });
3959
3960 if (target.disableProfile() == false) {
3961 if (exist && target.selectedProfile() != target.profileName()) {
3962 showInfo("apn_save_profile_exist");
3963 return false;
3964 }
3965 if (target.predeterminedCfg()) { //预置的APN不可以修改
3966 errorOverlay();
3967 return false;
3968 }
3969 if (target.predeterminedCfg() || target.defaultCfg()) {
3970 //showConfirm("apn_alert", function () {
3971 editApnSetting(false);
3972 //});
3973 } else {
3974 editApnSetting(false);
3975 }
3976 } else {
mj.qu11d28a82024-12-17 18:09:17 -08003977
qumengjiaca65ef52024-11-06 15:42:21 +08003978 if ($("#profile option").length >= config.maxApnNumber) {
3979 showInfo({
3980 msg: "apn_profile_full",
3981 params: [config.maxApnNumber]
3982 });
3983 return false;
3984 }
3985 if (exist) {
3986 showInfo("apn_save_profile_exist");
3987 return false;
3988 }
3989 var info = service.getStatusInfo();
3990 if (info.connectStatus != "ppp_connected") {
3991 //showConfirm("apn_alert", function () {
3992 addNewApnSetting();
3993 //});
mj.qu11d28a82024-12-17 18:09:17 -08003994
qumengjiaca65ef52024-11-06 15:42:21 +08003995 } else {
3996 showConfirm("apn_diconneted_network_confirm", function () {
3997 showLoading('disconnecting');
3998 service.disconnect({}, function (data) {
3999 if (data.result) {
4000 config.connect_flag = true;
4001 addNewApnSetting();
4002 } else {
4003 errorOverlay();
4004 }
4005 });
4006 });
4007 }
4008 }
4009 }
mj.qu11d28a82024-12-17 18:09:17 -08004010
qumengjiaca65ef52024-11-06 15:42:21 +08004011 function getSelectedManualProfileFunc() {
4012 var cfg = {};
4013 var profileVal = $("#profile").val();
4014 if (typeof target.selectedProfile() == 'undefined') {
4015 target.selectedProfile(profileVal);
4016 }
4017 var cfgV4 = apnConfigs[profileVal];
4018 var cfgV6 = ipv6ApnConfigs[profileVal];
4019 if (cfgV4 && !cfgV6) {
4020 $.extend(cfg, cfgV4);
4021 } else if (cfgV4 && cfgV6) {
4022 if (!!cfgV4.pdpType) {
4023 $.extend(cfg, cfgV6);
4024 $.extend(cfg, cfgV4);
4025 } else {
4026 $.extend(cfg, cfgV4);
4027 $.extend(cfg, cfgV6);
4028 }
4029 }
4030 return cfg;
4031 }
mj.qu11d28a82024-12-17 18:09:17 -08004032
qumengjiaca65ef52024-11-06 15:42:21 +08004033 //APN mode change 事件处理
4034 function apnModeChangeHandlerFunc(data, event) {
4035 if (target.apnMode() != 'auto') {
4036 target.profileChangeHandler();
4037 } else {
4038 if (target.showAutoApnDetail()) {
4039 target.autoProfileChangeHandler();
4040 }
4041 }
4042 return true;
4043 }
mj.qu11d28a82024-12-17 18:09:17 -08004044
qumengjiaca65ef52024-11-06 15:42:21 +08004045 //设置为默认apn
4046 function setDefaultActFunc() {
4047 if (!target.selectedProfile()) {
4048 showAlert("apn_no_select_alert");
4049 return false;
4050 }
4051 var connectStatus = service.getConnectionInfo().connectStatus;
4052 if (connectStatus == "ppp_connecting") {
4053 showAlert({
4054 msg: "apn_cant_modify_status",
4055 params: [$.i18n.prop("connecting").toLowerCase()]
4056 });
4057 return false;
4058 } else if (connectStatus == "ppp_disconnecting") {
4059 showAlert({
4060 msg: "apn_cant_modify_status",
4061 params: [$.i18n.prop("disconnecting").toLowerCase()]
4062 });
4063 return false;
4064 } else if (connectStatus == "ppp_connected") {
4065 showAlert({
4066 msg: "apn_cant_modify_status",
4067 params: [$.i18n.prop("connected").toLowerCase()]
4068 });
4069 return false;
4070 }
4071 if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
4072 //showConfirm("apn_alert", function () {
4073 showLoading("waiting");
4074 doSetDefaultAct();
4075 //});
4076 } else {
4077 if ($('#apn_setting_form').valid() == false) {
4078 $(".error:first", "#apn_setting_form").focus();
4079 } else {
4080 var exist = false;
4081 $.each(target.profiles(), function (i, e) {
4082 if (e.value == target.profileName()) {
4083 exist = true;
4084 }
4085 });
4086 if (exist && target.selectedProfile() != target.profileName()) {
4087 showInfo("apn_save_profile_exist");
4088 return false;
4089 }
4090 //showLoading("waiting");
4091 //showConfirm("apn_alert", function () {
4092 editApnSetting(true);
4093 //});
4094 }
4095 }
4096 }
mj.qu11d28a82024-12-17 18:09:17 -08004097
qumengjiaca65ef52024-11-06 15:42:21 +08004098 //切换profile时重置下面的显示项
4099 function setUIDataFunc(data) {
4100 clearValidateMsg('#apn_setting_form');
4101 if (!data) {
4102 return;
4103 }
4104 target.selectedPdpType(data.pdpType || 'IP');
4105 target.selectedPdpTypeTmp(data.pdpType || 'IP');
4106 target.profileName(data.profileName);
4107
4108 target.apn(data.wanApn);
4109 target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
4110 target.dns1(data.dns1);
4111 target.dns2(data.dns2);
4112 target.username(data.username);
4113 target.password(data.password);
4114 target.selectedAuthentication(data.authMode || 'none');
4115
4116 target.apnV6(data.wanApnV6);
4117 target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
4118 target.dns1V6(data.dns1V6);
4119 target.dns2V6(data.dns2V6);
4120 target.usernameV6(data.usernameV6);
4121 target.passwordV6(data.passwordV6);
4122 target.selectedAuthenticationV6(data.authModeV6 || 'none');
4123 }
mj.qu11d28a82024-12-17 18:09:17 -08004124
qumengjiaca65ef52024-11-06 15:42:21 +08004125 //profile change 事件处理
4126 function profileChangeHandlerFunc(data, event) {
4127 target.pdpTypeNote(true);
4128 if (target.apnMode() != 'manual') {
4129 return true;
4130 }
4131 var cfg = target.getSelectedManualProfile();
4132 target.setUIData(cfg);
4133 checkDefaultProfileStatus();
4134 return true;
4135 }
mj.qu11d28a82024-12-17 18:09:17 -08004136
qumengjiaca65ef52024-11-06 15:42:21 +08004137 //auto apn profile change 事件处理
4138 function autoProfileChangeHandlerFunc(data, event) {
4139 if (target.apnMode() != 'auto') {
4140 return true;
4141 }
4142 var cfg = autoApnConfigs[target.selectedAutoProfile()];
4143 target.setUIData(cfg);
4144 checkDefaultProfileStatus();
4145 return true;
4146 }
mj.qu11d28a82024-12-17 18:09:17 -08004147
qumengjiaca65ef52024-11-06 15:42:21 +08004148 function pdpTypeChangeAlertFunc() {
4149 if (target.pdpTypeNote()) {
4150 showAlert({
4151 msg: "apn_pdptype_change_note",
4152 params: [data.lanDomain, data.ipAddress]
4153 });
4154 }
4155 if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
4156 if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
4157 if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
4158 target.apn(target.apnV6());
4159 target.dnsMode(target.dnsModeV6());
4160 target.dns1(target.dns1V6());
4161 target.dns2(target.dns2V6());
4162 target.username(target.usernameV6());
4163 target.password(target.passwordV6());
4164 target.selectedAuthentication(target.selectedAuthenticationV6());
4165 } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
4166 target.apnV6(target.apn());
4167 target.dnsModeV6(target.dnsMode());
4168 target.dns1V6(target.dns1());
4169 target.dns2V6(target.dns2());
4170 target.usernameV6(target.username());
4171 target.passwordV6(target.password());
4172 target.selectedAuthenticationV6(target.selectedAuthentication());
4173 }
4174 }
4175 }
4176 target.selectedPdpTypeTmp(target.selectedPdpType());
4177 }
mj.qu11d28a82024-12-17 18:09:17 -08004178
qumengjiaca65ef52024-11-06 15:42:21 +08004179
4180 }
4181
4182 //是否已联网
mj.qu11d28a82024-12-17 18:09:17 -08004183
qumengjiaca65ef52024-11-06 15:42:21 +08004184 function isConnectedNetWork() {
4185 var info = service.getConnectionInfo();
4186 return info.connectStatus == "ppp_connected";
4187 }
4188
4189 function initVar() {
4190 apnConfigs = {};
4191 ipv6ApnConfigs = {};
4192 autoApnConfigs = {};
4193 }
4194 function bindContainer(vm){
4195 var container = $('#container');
4196 ko.cleanNode(container[0]);
4197 ko.applyBindings(vm, container[0]);
4198 }
4199 //初始化ViewModel
mj.qu11d28a82024-12-17 18:09:17 -08004200
qumengjiaca65ef52024-11-06 15:42:21 +08004201 function initialize(formInit) {
4202 initVar();
mj.qu11d28a82024-12-17 18:09:17 -08004203
qumengjiaca65ef52024-11-06 15:42:21 +08004204 var vm = new APNViewModel();
4205 bindContainer(vm);
4206
4207 if (!formInit) {
4208 addInterval(function () {
4209 vm.setDefaultVisible(!isConnectedNetWork());
4210 }, 1000);
4211 }
4212 $('#apn_setting_form').validate({
4213 submitHandler: function () {
4214 vm.saveAct();
4215 },
4216 rules: {
4217 profile_name: 'apn_profile_name_check',
4218 apn_ipv4_apn: 'apn_check',
4219 apn_dns1_ipv4: "ipv4",
4220 apn_dns2_ipv4: "ipv4",
4221 apn_ipv6_apn: 'apn_check',
4222 apn_dns1_ipv6: "ipv6",
4223 apn_dns2_ipv6: "ipv6",
4224 apn_user_name_ipv4: 'ppp_username_check',
4225 apn_secretcode_ipv4: 'ppp_secretcode_check',
4226 apn_user_name_ipv6: 'ppp_username_check',
4227 apn_secretcode_ipv6: 'ppp_secretcode_check'
4228 }
4229 });
4230 }
4231
4232 return {
4233 init: initialize
4234 };
mj.qu11d28a82024-12-17 18:09:17 -08004235});
4236define("network_info","underscore jquery knockout set service".split(" "),
4237 function (_, $, ko, config, service) {
4238
4239 function NetInfoVM() {
4240 var target = this;
4241 var network_status = service.getNetworkStatus();
4242
4243 target.pci = ko.observable(network_status.pci);
4244 target.sinr = ko.observable(network_status.sinr);
4245 target.rsrp = ko.observable(network_status.rsrp);
4246 target.rsrq = ko.observable(network_status.rsrq);
4247 target.plmn = ko.observable(network_status.plmn);
4248 target.cellid = ko.observable(network_status.cellid);
w.dengbcaf3a52024-12-30 17:43:27 +08004249 target.band = ko.observable(network_status.band);
mj.qu11d28a82024-12-17 18:09:17 -08004250 }
4251
4252 function initialize() {
4253 var container = $('#container');
4254 ko.cleanNode(container[0]);
4255 var imVm = new NetInfoVM();
4256 ko.applyBindings(imVm, container[0]);
4257 }
4258
4259 return {
4260 init: initialize
4261 };
4262});