blob: b4866ce0d7751e42579f1b9b8433d3431bedd88d [file] [log] [blame]
qumengjiaca65ef52024-11-06 15:42:21 +08001
2define("firewall_url_filter","underscore jquery knockout set service".split(" "),
3 function (_, $, ko, config, service) {
4
5 //system url filter setting VM
mj.qu11d28a82024-12-17 18:09:17 -08006
qumengjiaca65ef52024-11-06 15:42:21 +08007 function UrlFilterSettingVM() {
8 var target = this;
9 var urlFltInfo = service.getUrlFilterList();
10 var columnsTmpl = [{
11 columnType: "checkbox",
12 rowText: "index",
13 width: "30%"
14 }, {
15 headerTextTrans: "url",
16 rowText: "url",
17 width: "70%"
18 }
19 ];
20 target.rules = ko.observableArray(urlFltInfo.urlFilterRules);
21
22 target.gridTemplate = new ko.simpleGrid.viewModel({
23 data: target.rules(),
24 idName: "index",
25 columns: columnsTmpl,
26 tmplType: 'list',
27 pageSize: 10
28 });
29
30 target.clear = clearFunc;
mj.qu11d28a82024-12-17 18:09:17 -080031
qumengjiaca65ef52024-11-06 15:42:21 +080032 target.callback = callbackFunc;
33 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -080034
qumengjiaca65ef52024-11-06 15:42:21 +080035 target.deleteRule = deleteRuleFunc;
mj.qu11d28a82024-12-17 18:09:17 -080036
qumengjiaca65ef52024-11-06 15:42:21 +080037 //添加规则
mj.qu11d28a82024-12-17 18:09:17 -080038
qumengjiaca65ef52024-11-06 15:42:21 +080039 target.addRule = addRuleFunc;
40 function callbackFunc(elem) {
41 if (elem.result != "success") {
42 errorOverlay();
43 } else {
44 target.clear();
45 initialize(target);
46 successOverlay();
47 $("#urlFilters").translate();
48 }
49 }
mj.qu11d28a82024-12-17 18:09:17 -080050
qumengjiaca65ef52024-11-06 15:42:21 +080051 //添加规则
52 function addRuleFunc() {
53 if (target.rules().length >= config.urlFilterMax) {
54 showAlert({
55 msg: "url_filter_max",
56 params: config.urlFilterMax
57 });
58 return false;
59 }
60 var tmpArr = [];
61 for (var idx = 0; idx < target.rules().length; idx++) {
62 tmpArr.push(target.rules()[idx].url);
63 }
64 if ($.inArray($("#addURLFilter").val(), tmpArr) != -1) {
65 showAlert("url_repeated");
66 return false;
67 }
68
69 showLoading();
70 var urlFltParams = {
71 goformId: "URL_FILTER_ADD",
72 addURLFilter: $("#addURLFilter").val()
73 };
74 service.addUrlFilterRule(urlFltParams, target.callback);
75 }
76 //删除规则
77 function deleteRuleFunc() {
78 showConfirm('confirm_data_delete', function () {
79 showLoading();
80 var urlFltParams = {
81 goformId: "URL_FILTER_DELETE",
82 url_filter_delete_id: target.gridTemplate.selectedIds().join(";") + ";"
83 };
84 service.deleteSelectedRules(urlFltParams, target.callback);
85 });
86 }
mj.qu11d28a82024-12-17 18:09:17 -080087
qumengjiaca65ef52024-11-06 15:42:21 +080088 }
mj.qu11d28a82024-12-17 18:09:17 -080089
qumengjiaca65ef52024-11-06 15:42:21 +080090 function clearFunc() {
91 $("#addURLFilter").val("");
92 }
mj.qu11d28a82024-12-17 18:09:17 -080093
qumengjiaca65ef52024-11-06 15:42:21 +080094 //页面初始化
mj.qu11d28a82024-12-17 18:09:17 -080095
qumengjiaca65ef52024-11-06 15:42:21 +080096 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -080097
qumengjiaca65ef52024-11-06 15:42:21 +080098 var vm = new UrlFilterSettingVM();
99 bindContainer(vm);
100 }
101 function bindContainer(vm){
102 var container = $('#container');
103 ko.cleanNode(container[0]);
104 ko.applyBindings(vm, container[0]);
105 $('#urlFilterForm').validate({
106 submitHandler: function () {
107 vm.addRule();
108 },
109 rules: {
110 addURLFilter: 'url_filter_check'
111 }
112 });
113
114 $("#urlFilterListForm").validate({
115 submitHandler: function () {
116 vm.deleteRule();
117 }
118 });
119 }
120
121 return {
122 init: initialize
123 };
124});
125
126define("firewall_upnp_set","underscore jquery knockout set service".split(" "),
127 function (_, $, ko, config, service) {
128
129 //system upnp setting VM
mj.qu11d28a82024-12-17 18:09:17 -0800130
qumengjiaca65ef52024-11-06 15:42:21 +0800131 function UpnpSettingVM() {
132 var target = this;
133 var upnpInfo = getUpnpSetting();
134
135 target.upnpSetting = ko.observable(upnpInfo.upnpSetting);
136
137 target.save = saveFunc;
138 function saveFunc() {
139 showLoading();
140 var upnpParams = {};
141 upnpParams.upnpSetting = target.upnpSetting();
142 service.setUpnpSetting(upnpParams, function (rlt) {
143 if (rlt.result == "success") {
144 successOverlay();
145 } else {
146 errorOverlay();
147 }
148 });
149
150 }
151 }
mj.qu11d28a82024-12-17 18:09:17 -0800152
153
qumengjiaca65ef52024-11-06 15:42:21 +0800154 //获取upnp 信息
mj.qu11d28a82024-12-17 18:09:17 -0800155
qumengjiaca65ef52024-11-06 15:42:21 +0800156 function getUpnpSetting() {
157 return service.getUpnpSetting();
158 }
159
160 //初始化UpnpSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -0800161
qumengjiaca65ef52024-11-06 15:42:21 +0800162 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -0800163
qumengjiaca65ef52024-11-06 15:42:21 +0800164 var vm = new UpnpSettingVM();
165 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -0800166
qumengjiaca65ef52024-11-06 15:42:21 +0800167 }
168 function bindContainer(vm) {
169 var container = $('#container');
170 ko.cleanNode(container[0]);
171 ko.applyBindings(vm, container[0]);
172 $('#upnpSettingForm').validate({
173 submitHandler: function () {
174 vm.save();
175 }
176 });
177 }
178
179 return {
180 init: initialize
181 };
182});
183
184define("firewall_upnp_set","underscore jquery knockout set service".split(" "),
185 function (_, $, ko, config, service) {
186
187 //system upnp setting VM
mj.qu11d28a82024-12-17 18:09:17 -0800188
qumengjiaca65ef52024-11-06 15:42:21 +0800189 function UpnpSettingVM() {
190 var target = this;
191 var upnpInfo = getUpnpSetting();
192
193 target.upnpSetting = ko.observable(upnpInfo.upnpSetting);
194
195 target.save = saveFunc;
196 function saveFunc() {
197 showLoading();
198 var upnpParams = {};
199 upnpParams.upnpSetting = target.upnpSetting();
200 service.setUpnpSetting(upnpParams, function (rlt) {
201 if (rlt.result == "success") {
202 successOverlay();
203 } else {
204 errorOverlay();
205 }
206 });
207
208 }
209 }
mj.qu11d28a82024-12-17 18:09:17 -0800210
211
qumengjiaca65ef52024-11-06 15:42:21 +0800212 //获取upnp 信息
mj.qu11d28a82024-12-17 18:09:17 -0800213
qumengjiaca65ef52024-11-06 15:42:21 +0800214 function getUpnpSetting() {
215 return service.getUpnpSetting();
216 }
217
218 //初始化UpnpSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -0800219
qumengjiaca65ef52024-11-06 15:42:21 +0800220 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -0800221
qumengjiaca65ef52024-11-06 15:42:21 +0800222 var vm = new UpnpSettingVM();
223 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -0800224
qumengjiaca65ef52024-11-06 15:42:21 +0800225 }
226 function bindContainer(vm) {
227 var container = $('#container');
228 ko.cleanNode(container[0]);
229 ko.applyBindings(vm, container[0]);
230 $('#upnpSettingForm').validate({
231 submitHandler: function () {
232 vm.save();
233 }
234 });
235 }
236
237 return {
238 init: initialize
239 };
240});
241
242//端口映射
mj.qu11d28a82024-12-17 18:09:17 -0800243
qumengjiaca65ef52024-11-06 15:42:21 +0800244define("firewall_port_map","underscore jquery knockout set service".split(" "),
245 function (_, $, ko, config, service) {
246
247 var protocolModes = _.map(config.MAP_PROTOCOL_MODES, function (ele) {
248 return new Option(ele.name, ele.value);
249 });
250
251 var columnsTmpl = [{
252 columnType: "checkbox",
253 rowText: "index",
254 width: "8%"
255 }, {
256 headerTextTrans: "source_port",
257 rowText: "sourcePort",
258 width: "20%"
259 }, {
260 headerTextTrans: "dest_ip_address",
261 rowText: "destIpAddress",
262 width: "20%"
263 }, {
264 headerTextTrans: "dest_port",
265 rowText: "destPort",
266 width: "20%"
267 }, {
268 headerTextTrans: "protocol",
269 rowText: "protocol",
270 width: "12%"
271 }, {
272 headerTextTrans: "comment",
273 rowText: "comment",
274 width: "20%"
275 }
276 ];
277
278 //prot_map VM
mj.qu11d28a82024-12-17 18:09:17 -0800279
qumengjiaca65ef52024-11-06 15:42:21 +0800280 function PortMapVM() {
281 var target = this;
282 var mapInfo = getPortMap();
283
284 target.oriPortMapEnable = ko.observable(mapInfo.portMapEnable);
285 target.rules = ko.observableArray(mapInfo.portMapRules);
286 target.portMapEnable = ko.observable(mapInfo.portMapEnable);
287
mj.qu11d28a82024-12-17 18:09:17 -0800288
qumengjiaca65ef52024-11-06 15:42:21 +0800289 target.comment = ko.observable('');
290 target.selectedMode = ko.observable('TCP&UDP');
291 target.modes = ko.observableArray(protocolModes);
mj.qu11d28a82024-12-17 18:09:17 -0800292
qumengjiaca65ef52024-11-06 15:42:21 +0800293 target.destPort = ko.observable('');
294 target.destIpAddress = ko.observable('');
295 target.sourcePort = ko.observable('');
296
297
298
299 target.gridTemplate = new ko.simpleGrid.viewModel({
300 data: target.rules(),
301 idName: "index",
302 columns: columnsTmpl,
303 tmplType: 'list',
304 pageSize: 10
305 });
306
307 //设定,新增,删除回调函数
mj.qu11d28a82024-12-17 18:09:17 -0800308
qumengjiaca65ef52024-11-06 15:42:21 +0800309 target.callback = callbackFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800310
qumengjiaca65ef52024-11-06 15:42:21 +0800311 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -0800312
qumengjiaca65ef52024-11-06 15:42:21 +0800313 target.deleteMapRules = deleteMapRulesFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800314
qumengjiaca65ef52024-11-06 15:42:21 +0800315 //检查新增规则是否已经存在
mj.qu11d28a82024-12-17 18:09:17 -0800316
qumengjiaca65ef52024-11-06 15:42:21 +0800317 target.checkExist = checkExistFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800318
qumengjiaca65ef52024-11-06 15:42:21 +0800319 //设定端口映射
mj.qu11d28a82024-12-17 18:09:17 -0800320
qumengjiaca65ef52024-11-06 15:42:21 +0800321 target.enablePortMap = enablePortMapFunc;
322
323 //保存规则
mj.qu11d28a82024-12-17 18:09:17 -0800324
qumengjiaca65ef52024-11-06 15:42:21 +0800325 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800326
qumengjiaca65ef52024-11-06 15:42:21 +0800327 //保存规则
328 function saveFunc() {
329 if (target.rules().length >= config.portForwardMax) {
330 showAlert({
331 msg: "rules_max",
332 params: config.portForwardMax
333 });
334 return;
335 }
336
337 if (target.checkExist()) {
338 showAlert("rule_exist");
339 return;
340 }
341
342 showLoading();
343 var mapParams = {};
344 mapParams.portMapEnable = target.portMapEnable();
345 mapParams.sourcePort = target.sourcePort();
346 mapParams.destIpAddress = target.destIpAddress();
347 mapParams.destPort = target.destPort();
348 mapParams.protocol = target.selectedMode();
349 mapParams.comment = target.comment();
350 service.setPortMap(mapParams, target.callback);
351 }
mj.qu11d28a82024-12-17 18:09:17 -0800352
qumengjiaca65ef52024-11-06 15:42:21 +0800353 //检查新增规则是否已经存在
354 function checkExistFunc() {
355 var newMapRule = {
356 sourcePort: target.sourcePort(),
357 destIpAddress: target.destIpAddress(),
358 destPort: target.destPort(),
359 protocol: transProtocolValue(target.selectedMode())
360 };
361
362 var oldMapRule;
363 var mapRules = target.rules();
364 for (var idx = 0; idx < mapRules.length; idx++) {
365 oldMapRule = {
366 sourcePort: mapRules[idx].sourcePort,
367 destIpAddress: mapRules[idx].destIpAddress,
368 destPort: mapRules[idx].destPort,
369 protocol: mapRules[idx].protocol
370 };
371
372 if (_.isEqual(newMapRule, oldMapRule)) {
373 return true;
374 }
375 }
376 return false;
377 }
mj.qu11d28a82024-12-17 18:09:17 -0800378
qumengjiaca65ef52024-11-06 15:42:21 +0800379 //设定端口映射
380 function enablePortMapFunc() {
381 showLoading();
382 var mapParams = {};
383 mapParams.portMapEnable = target.portMapEnable();
384 service.enablePortMap(mapParams, target.callback);
385 }
mj.qu11d28a82024-12-17 18:09:17 -0800386
qumengjiaca65ef52024-11-06 15:42:21 +0800387 //删除规则
388 function deleteMapRulesFunc() {
389 var ids = target.gridTemplate.selectedIds();
390 if (ids.length == 0) {
391 showAlert("no_data_selected");
392 return;
393 }
394
395 showConfirm("confirm_data_delete", function () {
396 showLoading();
397 var mapParams = {};
398 mapParams.indexs = ids;
399 service.deleteMapRules(mapParams, target.callback);
400 });
401 }
mj.qu11d28a82024-12-17 18:09:17 -0800402
qumengjiaca65ef52024-11-06 15:42:21 +0800403 //设定,新增,删除回调函数
404 function callbackFunc(ret) {
405 if (ret.result == "success") {
406 clear();
407 initialize(target);
408 successOverlay();
409 } else {
410 errorOverlay();
411 }
412 }
413
414 //情况添加规则输入
mj.qu11d28a82024-12-17 18:09:17 -0800415
qumengjiaca65ef52024-11-06 15:42:21 +0800416 function clear() {
417 target.sourcePort('');
418 target.destIpAddress('');
419 target.destPort('');
420 target.selectedMode('TCP&UDP');
421 target.comment('');
422 }
423 }
424
425 //获取port map信息
mj.qu11d28a82024-12-17 18:09:17 -0800426
qumengjiaca65ef52024-11-06 15:42:21 +0800427 function getPortMap() {
428 return service.getPortMap();
429 }
430
431 function bindingContainer(vm){
432 var container = $('#container');
433 ko.cleanNode(container[0]);
434 ko.applyBindings(vm, container[0]);
435
436 }
437 //初始化port map view model
mj.qu11d28a82024-12-17 18:09:17 -0800438
qumengjiaca65ef52024-11-06 15:42:21 +0800439 function initialize(viewModel) {
440 var vm;
441 if (viewModel) {
442 vm = viewModel;
443 var mapInfo = getPortMap();
444 vm.portMapEnable(mapInfo.portMapEnable);
445 vm.oriPortMapEnable(mapInfo.portMapEnable);
446 vm.rules(mapInfo.portMapRules);
447 vm.gridTemplate.clearAllChecked();
448 vm.gridTemplate.data(mapInfo.portMapRules);
449 refreshTableHeight();
450 renderCheckbox();
451 return;
452 }
453
454 vm = new PortMapVM();
455 bindingContainer(vm);
456 fixTableHeight();
457
458 $('#mapBasicForm').validate({
459 submitHandler: function () {
460 vm.enablePortMap();
461 }
462 });
463
464 $('#portMapListForm').validate({
465 submitHandler: function () {
466 vm.deleteMapRules();
467 }
468 });
469
470 $('#portMapForm').validate({
471 submitHandler: function () {
472 vm.save();
473 },
474 rules: {
475 txtDestIpAddress: {
476 ip_check: true
477 },
478 txtSourcePort: {
479 digits: true,
480 range_except: [1, 65000]
481 },
482 txtDestPort: {
483 digits: true,
484 range_except: [1, 65000]
485 },
486 txtComment: {
487 comment_check: true
488 }
489 },
490 errorPlacement: function (error, element) {
491 if (element.attr("name") == "txtDestIpAddress") {
492 error.appendTo("#txtDestIpAddressErrorDiv");
493 } else if (element.attr("name") == "txtSourcePort") {
494 error.appendTo("#txtSourcePortErrorDiv");
495 } else if (element.attr("name") == "txtDestPort") {
496 error.appendTo("#txtDestPortErrorDiv");
497 } else
498 error.insertAfter(element);
499 }
500 });
501 }
502
503 return {
504 init: initialize
505 };
506});
507
508//端口转发
mj.qu11d28a82024-12-17 18:09:17 -0800509
qumengjiaca65ef52024-11-06 15:42:21 +0800510define("firewall_port_forward","underscore jquery knockout set service".split(" "),
511 function (_, $, ko, config, service) {
512
513 var protocolModes = _.map(config.FORWARD_PROTOCOL_MODES, function (ele) {
514 return new Option(ele.name, ele.value);
515 });
516 //列表模板的columns项
mj.qu11d28a82024-12-17 18:09:17 -0800517
qumengjiaca65ef52024-11-06 15:42:21 +0800518 var columnsTmpl = [{
519 columnType: "checkbox",
520 rowText: "index",
521 width: "8%"
522 }, {
523 headerTextTrans: "ip_address",
524 rowText: "ipAddress",
525 width: "23%"
526 }, {
527 headerTextTrans: "port_range",
528 rowText: "portRange",
529 width: "23%"
530 }, {
531 headerTextTrans: "protocol",
532 rowText: "protocol",
533 width: "23%"
534 }, {
535 headerTextTrans: "comment",
536 rowText: "comment",
537 width: "23%"
538 }
539 ];
540
541 //prot_forward VM
mj.qu11d28a82024-12-17 18:09:17 -0800542
qumengjiaca65ef52024-11-06 15:42:21 +0800543 function PortForwardVM() {
544 var target = this;
545 var fwdinfo = getPortForward();
546
547 target.portForwardEnable = ko.observable(fwdinfo.portForwardEnable);
548 target.oriPortForwardEnable = ko.observable(fwdinfo.portForwardEnable);
mj.qu11d28a82024-12-17 18:09:17 -0800549
qumengjiaca65ef52024-11-06 15:42:21 +0800550 target.portEnd = ko.observable('');
551 target.portStart = ko.observable('');
552 target.ipAddress = ko.observable('');
mj.qu11d28a82024-12-17 18:09:17 -0800553
qumengjiaca65ef52024-11-06 15:42:21 +0800554 target.comment = ko.observable('');
555 target.selectedMode = ko.observable('3');
556 target.modes = ko.observableArray(protocolModes);
557
558 target.rules = ko.observableArray(fwdinfo.portForwardRules);
mj.qu11d28a82024-12-17 18:09:17 -0800559
qumengjiaca65ef52024-11-06 15:42:21 +0800560 //设定,新增,删除回调函数
mj.qu11d28a82024-12-17 18:09:17 -0800561
qumengjiaca65ef52024-11-06 15:42:21 +0800562 target.callback = callbackFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800563
qumengjiaca65ef52024-11-06 15:42:21 +0800564 //创建列表模板
mj.qu11d28a82024-12-17 18:09:17 -0800565
qumengjiaca65ef52024-11-06 15:42:21 +0800566 target.gridTemplate = new ko.simpleGrid.viewModel({
567 data: target.rules(),
568 idName: "index",
569 columns: columnsTmpl,
570 tmplType: 'list',
571 pageSize: 10
572 });
573
574 //检查新增规则是否已经存在
mj.qu11d28a82024-12-17 18:09:17 -0800575
qumengjiaca65ef52024-11-06 15:42:21 +0800576 target.checkExist = checkExistFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800577
qumengjiaca65ef52024-11-06 15:42:21 +0800578 //保存规则
mj.qu11d28a82024-12-17 18:09:17 -0800579
qumengjiaca65ef52024-11-06 15:42:21 +0800580 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800581
qumengjiaca65ef52024-11-06 15:42:21 +0800582 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -0800583
qumengjiaca65ef52024-11-06 15:42:21 +0800584 target.deleteForwardRules = deleteForwardRulesFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800585
qumengjiaca65ef52024-11-06 15:42:21 +0800586 //设定虚拟服务器
mj.qu11d28a82024-12-17 18:09:17 -0800587
qumengjiaca65ef52024-11-06 15:42:21 +0800588 target.enableVirtualServer = enableVirtualServerFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800589
qumengjiaca65ef52024-11-06 15:42:21 +0800590 //设定虚拟服务器
591 function enableVirtualServerFunc() {
592 showLoading();
593 var fwdParams = {};
594 fwdParams.portForwardEnable = target.portForwardEnable();
595 service.enableVirtualServer(fwdParams, target.callback);
596 }
mj.qu11d28a82024-12-17 18:09:17 -0800597
qumengjiaca65ef52024-11-06 15:42:21 +0800598 //删除规则
599 function deleteForwardRulesFunc() {
600 var ids = target.gridTemplate.selectedIds();
601 if (ids.length == 0) {
602 showAlert("no_data_selected");
603 return;
604 }
605
606 showConfirm("confirm_data_delete", function () {
607 showLoading('deleting');
608 var fwdParams = {};
609 fwdParams.indexs = ids;
610 service.deleteForwardRules(fwdParams, target.callback);
611 });
612 }
mj.qu11d28a82024-12-17 18:09:17 -0800613
qumengjiaca65ef52024-11-06 15:42:21 +0800614 //保存规则
615 function saveFunc() {
616 if (target.rules().length >= config.portForwardMax) {
617 showAlert({
618 msg: "rules_max",
619 params: config.portForwardMax
620 });
621 return;
622 }
623
624 if (target.checkExist()) {
625 showAlert("rule_exist");
626 return;
627 }
628
629 showLoading();
630 var fwdParams = {};
631 fwdParams.comment = target.comment();
632 fwdParams.protocol = target.selectedMode();
633 fwdParams.portEnd = target.portEnd();
634 fwdParams.portStart = target.portStart();
635 fwdParams.ipAddress = target.ipAddress();
636 service.setPortForward(fwdParams, target.callback);
637 }
638 //情况添加规则输入
639 function clear() {
640 target.ipAddress('');
641 target.portStart('');
642 target.portEnd('');
643 target.selectedMode('TCP&UDP');
644 target.comment('');
645 }
mj.qu11d28a82024-12-17 18:09:17 -0800646
qumengjiaca65ef52024-11-06 15:42:21 +0800647 //设定,新增,删除回调函数
648 function callbackFunc(ret) {
649 if (ret.result == "success") {
650 clear();
651 initialize(target);
652 successOverlay();
653 } else {
654 errorOverlay();
655 }
656 }
657
658 //检查新增规则是否已经存在
659 function checkExistFunc() {
660 var newRule = {
661 ipAddress: target.ipAddress(),
662 portRange: target.portStart() + ' - ' + target.portEnd(),
663 protocol: transProtocolValue(target.selectedMode())
664 };
665
666 var oldRule;
667 var fwdrules = target.rules();
668 for (var ki = 0; ki < fwdrules.length; ki++) {
669 oldRule = {
670 ipAddress: fwdrules[ki].ipAddress,
671 portRange: fwdrules[ki].portRange,
672 protocol: fwdrules[ki].protocol
673 };
674
675 if (_.isEqual(newRule, oldRule)) {
676 return true;
677 }
678 }
679 return false;
680 }
681 }
682
683 //获取port forward信息
mj.qu11d28a82024-12-17 18:09:17 -0800684
qumengjiaca65ef52024-11-06 15:42:21 +0800685 function getPortForward() {
686 return service.getPortForward();
687 }
688
689 //初始化port forward view model
mj.qu11d28a82024-12-17 18:09:17 -0800690
qumengjiaca65ef52024-11-06 15:42:21 +0800691 function initialize(viewModel) {
692 var vm;
693 if (viewModel) {
694 vm = viewModel;
695 var fwdinfo = getPortForward();
696 vm.gridTemplate.clearAllChecked();
697 vm.gridTemplate.data(fwdinfo.portForwardRules);
698 vm.rules(fwdinfo.portForwardRules);
699 vm.portForwardEnable(fwdinfo.portForwardEnable);
700 vm.oriPortForwardEnable(fwdinfo.portForwardEnable);
701 refreshTableHeight();
702 return;
703 }
704
705 vm = new PortForwardVM();
706 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -0800707
qumengjiaca65ef52024-11-06 15:42:21 +0800708 fixTableHeight();
709 renderCheckbox();
710
711 $('#virtualServerForm').validate({
712 submitHandler: function () {
713 vm.enableVirtualServer();
714 }
715 });
716
717 $('#portForwardListForm').validate({
718 submitHandler: function () {
719 vm.deleteForwardRules();
720 }
721 });
722
723 $('#portForwardForm').validate({
724 submitHandler: function () {
725 vm.save();
726 },
727 rules: {
728 txtIpAddress: {
729 ip_check: true
730 },
731 txtPortStart: {
732 digits: true,
733 range: [1, 65535],
734 portCompare: "#txtPortEnd"
735 },
736 txtPortEnd: {
737 digits: true,
738 range: [1, 65535],
739 portCompare: "#txtPortStart"
740 },
741 txtComment: {
742 comment_check: true
743 }
744 },
745 groups: {
746 range: "txtPortStart txtPortEnd"
747 },
748 errorPlacement: function (error, element) {
749 if (element.attr("name") == "txtIpAddress") {
750 error.appendTo("#ipErrorDiv");
751 } else if (element.attr("name") == "txtPortStart" || element.attr("name") == "txtPortEnd") {
752 error.appendTo("#portRangeErrorDiv");
753 } else
754 error.insertAfter(element);
755 }
756 });
757 }
mj.qu11d28a82024-12-17 18:09:17 -0800758
qumengjiaca65ef52024-11-06 15:42:21 +0800759 function bindContainer(vm){
760 var container = $('#container');
761 ko.cleanNode(container[0]);
762 ko.applyBindings(vm, container[0]);
763
764 }
mj.qu11d28a82024-12-17 18:09:17 -0800765
qumengjiaca65ef52024-11-06 15:42:21 +0800766
767 return {
768 init: initialize
769 };
770});
771
772define("firewall_port_filter","underscore jquery knockout set service".split(" "),
773 function (_, $, ko, config, service) {
774
775 var PROTOCOLS = {
776 ICMP: 'ICMP',
777 NONE: 'None'
778 };
779
780 var columnsTmpl = [{
781 columnType: "checkbox",
782 rowText: "index",
783 width: "4%"
784 }, {
785 headerTextTrans: "mac_address",
786 rowText: "macAddress",
787 width: "12%"
788 }, {
789 headerTextTrans: "ip_type",
790 rowText: "ipType",
791 width: "5%",
792 display: config.IPV6_SUPPORT
793 }, {
794 headerTextTrans: "source_ip_address",
795 rowText: "sourceIpAddress",
796 width: "12%"
797 }, {
798 headerTextTrans: "dest_ip_address",
799 rowText: "destIpAddress",
800 width: "12%"
801 }, {
802 headerTextTrans: "protocol",
803 rowText: "protocol",
804 width: "12%",
805 needTrans: true
806 }, {
807 headerTextTrans: "source_port_range",
808 rowText: "sourcePortRange",
809 width: "12%"
810 }, {
811 headerTextTrans: "dest_port_range",
812 rowText: "destPortRange",
813 width: "12%"
814 }, {
815 headerTextTrans: "port_filter_action",
816 rowText: "action",
817 width: "12%",
818 needTrans: true
819 }, {
820 headerTextTrans: "comment",
821 rowText: "comment",
822 width: "12%"
823 }
824 ];
825
826 var protocolModes = _.map(config.FILTER_PROTOCOL_MODES, function (elem) {
827 return new Option(elem.name, elem.value);
828 });
829 //prot_filter VM
mj.qu11d28a82024-12-17 18:09:17 -0800830
qumengjiaca65ef52024-11-06 15:42:21 +0800831 function PortFilterVM() {
832 var target = this;
833 var info = getPortFilter();
mj.qu11d28a82024-12-17 18:09:17 -0800834
qumengjiaca65ef52024-11-06 15:42:21 +0800835 target.oriDefaultPolicy = ko.observable(info.defaultPolicy);
836 target.defaultPolicy = ko.observable(info.defaultPolicy);
837 target.oriPortFilterEnable = ko.observable(info.portFilterEnable);
838 target.portFilterEnable = ko.observable(info.portFilterEnable);
839 target.rules = ko.observableArray(info.portFilterRules);
mj.qu11d28a82024-12-17 18:09:17 -0800840
qumengjiaca65ef52024-11-06 15:42:21 +0800841 target.ipv6Support = ko.observable(config.IPV6_SUPPORT);
842 target.comment = ko.observable('');
843 target.selectedMode = ko.observable('5');
844 target.modes = ko.observableArray(protocolModes);
845 target.sourcePortEnd = ko.observable('');
846 target.sourcePortStart = ko.observable('');
847 target.destPortEnd = ko.observable('');
848 target.destPortStart = ko.observable('');
849 target.destIpv6Address = ko.observable('');
850 target.sourceIpv6Address = ko.observable('');
851 target.sourceIpAddress = ko.observable('');
852 target.destIpAddress = ko.observable('');
853 target.macAddress = ko.observable('');
854 target.portFilterAction = ko.observable('');
855
856 target.ipType = ko.observable('ipv4');
857
858 //设定,新增,删除回调函数
mj.qu11d28a82024-12-17 18:09:17 -0800859
qumengjiaca65ef52024-11-06 15:42:21 +0800860 target.callback = callbackFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800861
qumengjiaca65ef52024-11-06 15:42:21 +0800862 //创建列表模板
mj.qu11d28a82024-12-17 18:09:17 -0800863
qumengjiaca65ef52024-11-06 15:42:21 +0800864 target.gridTemplate = new ko.simpleGrid.viewModel({
865 data: target.rules(),
866 idName: "index",
867 columns: columnsTmpl,
868 tmplType: 'list',
869 pageSize: 20
870 });
871 //default policy change handler
mj.qu11d28a82024-12-17 18:09:17 -0800872
qumengjiaca65ef52024-11-06 15:42:21 +0800873 target.policyChangeHandler = policyChangeHandlerFunc;
874
875 //保存规则
mj.qu11d28a82024-12-17 18:09:17 -0800876
qumengjiaca65ef52024-11-06 15:42:21 +0800877 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800878
qumengjiaca65ef52024-11-06 15:42:21 +0800879 //设定过滤基本信息
mj.qu11d28a82024-12-17 18:09:17 -0800880
qumengjiaca65ef52024-11-06 15:42:21 +0800881 target.setPortFilterBasic = setPortFilterBasicFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800882
qumengjiaca65ef52024-11-06 15:42:21 +0800883 //清空添加规则输入
mj.qu11d28a82024-12-17 18:09:17 -0800884
qumengjiaca65ef52024-11-06 15:42:21 +0800885 target.clear = clearFunc;
886
887 //检查新增规则是否已经存在
mj.qu11d28a82024-12-17 18:09:17 -0800888
qumengjiaca65ef52024-11-06 15:42:21 +0800889 target.checkExist = checkExistFunc;
890
891 //ip类型变化事件监听
mj.qu11d28a82024-12-17 18:09:17 -0800892
qumengjiaca65ef52024-11-06 15:42:21 +0800893 target.ipTypeChangeHandler = ipTypeChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -0800894
qumengjiaca65ef52024-11-06 15:42:21 +0800895 //协议变化事件监听
mj.qu11d28a82024-12-17 18:09:17 -0800896
qumengjiaca65ef52024-11-06 15:42:21 +0800897 target.protocolChangeHandler = protocolChangeHandlerFunc;
898
899 //删除规则
mj.qu11d28a82024-12-17 18:09:17 -0800900
qumengjiaca65ef52024-11-06 15:42:21 +0800901 target.deleteFilterRules = deleteFilterRulesFunc;
902
903 //init to call
904 target.policyChangeHandler();
mj.qu11d28a82024-12-17 18:09:17 -0800905
qumengjiaca65ef52024-11-06 15:42:21 +0800906 //设定,新增,删除回调函数
907 function callbackFunc(ret) {
908 if (ret.result != "success") {
909 errorOverlay();
910 } else {
911 target.clear();
912 initialize(target);
913 successOverlay();
914 }
915 }
916 //default policy change handler
917 function policyChangeHandlerFunc() {
918 var action = target.defaultPolicy() != "1" ? "Drop" : "Accept";
919 target.portFilterAction(action);
920 return true;
921 }
mj.qu11d28a82024-12-17 18:09:17 -0800922
qumengjiaca65ef52024-11-06 15:42:21 +0800923 //保存规则
924 function saveFunc() {
925 target.sourceIpAddress(target.sourceIpAddress().replace(/\s+/g, ''));
926 target.destIpAddress(target.destIpAddress().replace(/\s+/g, ''));
927 target.sourceIpv6Address(target.sourceIpv6Address().replace(/\s+/g, ''));
928 target.destIpv6Address(target.destIpv6Address().replace(/\s+/g, ''));
929 target.macAddress(target.macAddress().replace(/\s+/g, ''));
930 if (target.ipv6Support() == false) {
931 if (target.rules().length >= config.portForwardMax) {
932 showAlert({
933 msg: "rules_max",
934 params: config.portForwardMax
935 });
936 return;
937 }
938
939 if (target.checkExist()) {
940 showAlert("rule_exist");
941 return;
942 }
943
944 } else {
945 var type = target.ipType() == "ipv4" ? "IPv4" : "IPv6";
946 var oldRules = _.filter(target.rules(), function (item) {
947 return item.ipType == type;
948 });
949
950 if (oldRules.length >= config.portForwardMax) {
951 showAlert({
952 msg: "rules_max_v4v6",
953 params: [type, config.portForwardMax]
954 });
955 return;
956 }
957
958 if (target.checkExist()) {
959 showAlert({
960 msg: "rule_exist_v4v6",
961 params: type
962 });
963 return;
964 }
965 }
966 showConfirm("confirm_data_effect", function () {
967 showLoading();
968 var fltParams = {};
969 fltParams.macAddress = target.macAddress();
970
971 if (target.ipv6Support() && target.ipType() != 'ipv6') {
972 fltParams.destIpAddress = target.destIpAddress();
973 fltParams.sourceIpAddress = target.sourceIpAddress();
974 } else {
975 fltParams.destIpAddress = target.destIpv6Address();
976 fltParams.sourceIpAddress = target.sourceIpv6Address();
977 }
mj.qu11d28a82024-12-17 18:09:17 -0800978
qumengjiaca65ef52024-11-06 15:42:21 +0800979 fltParams.ipType = target.ipType();
980 fltParams.comment = target.comment();
981 fltParams.protocol = target.selectedMode();
982 fltParams.action = target.portFilterAction();
983 fltParams.sourcePortEnd = target.sourcePortEnd();
984 fltParams.sourcePortStart = target.sourcePortStart();
985 fltParams.destPortEnd = target.destPortEnd();
986 fltParams.destPortStart = target.destPortStart();
987 service.setPortFilter(fltParams, target.callback);
988 });
989 }
mj.qu11d28a82024-12-17 18:09:17 -0800990
qumengjiaca65ef52024-11-06 15:42:21 +0800991 //设定过滤基本信息
992 function setPortFilterBasicFunc() {
993 showLoading();
994 var elems = {};
995 elems.defaultPolicy = target.defaultPolicy();
996 elems.portFilterEnable = target.portFilterEnable();
997 service.setPortFilterBasic(elems, target.callback);
998 }
999 //清空添加规则输入
1000 function clearFunc() {
1001 target.comment('');
1002 target.selectedMode('None');
1003 target.sourcePortEnd('0');
1004 target.sourcePortStart('0');
1005 target.destPortEnd('0');
1006 target.destPortStart('0');
1007 target.sourceIpv6Address('');
1008 target.sourceIpAddress('');
1009 target.destIpv6Address('');
1010 target.destIpAddress('');
1011 target.macAddress('');
1012 clearValidateMsg();
1013 }
mj.qu11d28a82024-12-17 18:09:17 -08001014
qumengjiaca65ef52024-11-06 15:42:21 +08001015 //检查新增规则是否已经存在
1016 function checkExistFunc() {
1017 target.macAddress(target.macAddress().toUpperCase());
1018 var currIpType = target.ipType().toUpperCase();
1019 var newRule = {
1020 macAddress: target.macAddress(),
1021 destIpAddress: currIpType == "IPV4" ? target.destIpAddress() : target.destIpv6Address(),
1022 sourceIpAddress: currIpType == "IPV4" ? target.sourceIpAddress() : target.sourceIpv6Address(),
1023 destPortRange: target.destPortStart() == '0' ? '' : target.destPortStart() + ' - ' + target.destPortEnd(),
1024 sourcePortRange: target.sourcePortStart() == '0' ? '' : target.sourcePortStart() + ' - ' + target.sourcePortEnd(),
1025 action: target.portFilterAction() == "Drop" ? "filter_drop" : "filter_accept",
1026 protocol: transProtocolValue(target.selectedMode()),
1027 ipType: currIpType
1028 };
1029
1030 var oldRule;
1031 var rules = target.rules();
1032 for (var ki = 0; ki < rules.length; ki++) {
1033 oldRule = {
1034 macAddress: rules[ki].macAddress,
1035 destIpAddress: rules[ki].destIpAddress,
1036 sourceIpAddress: rules[ki].sourceIpAddress,
1037 destPortRange: rules[ki].destPortRange,
1038 sourcePortRange: rules[ki].sourcePortRange,
1039 action: rules[ki].action,
1040 protocol: rules[ki].protocol,
1041 ipType: rules[ki].ipType.toUpperCase()
1042 };
1043
1044 if (_.isEqual(newRule, oldRule)) {
1045 return true;
1046 }
1047 }
1048 return false;
1049 }
mj.qu11d28a82024-12-17 18:09:17 -08001050
qumengjiaca65ef52024-11-06 15:42:21 +08001051 //协议变化事件监听
1052 function protocolChangeHandlerFunc() {
1053 if (target.selectedMode() == PROTOCOLS.ICMP || target.selectedMode() == PROTOCOLS.NONE) {
1054 target.sourcePortEnd('0');
1055 target.sourcePortStart('0');
1056 target.destPortEnd('0');
1057 target.destPortStart('0');
1058 clearValidateMsg('#portRangeArea');
1059 } else {
1060 target.sourcePortEnd('65535');
1061 target.sourcePortStart('1');
1062 target.destPortEnd('65535');
1063 target.destPortStart('1');
1064 }
1065 return true;
1066 }
mj.qu11d28a82024-12-17 18:09:17 -08001067
qumengjiaca65ef52024-11-06 15:42:21 +08001068 //删除规则
1069 function deleteFilterRulesFunc() {
1070 var ids = target.gridTemplate.selectedIds();
1071 if (ids.length == 0) {
1072 showAlert("no_data_selected");
1073 return;
1074 }
1075
1076 showConfirm("confirm_data_effect", function () {
1077 showLoading('deleting');
1078 var rules = {};
1079 rules.indexs = ids;
1080 service.deleteFilterRules(rules, target.callback);
1081 });
1082 }
mj.qu11d28a82024-12-17 18:09:17 -08001083
qumengjiaca65ef52024-11-06 15:42:21 +08001084 }
1085
1086 //获取port filter信息
mj.qu11d28a82024-12-17 18:09:17 -08001087
qumengjiaca65ef52024-11-06 15:42:21 +08001088 function getPortFilter() {
1089 return service.getPortFilter();
1090 }
mj.qu11d28a82024-12-17 18:09:17 -08001091
qumengjiaca65ef52024-11-06 15:42:21 +08001092 //ip类型变化事件监听
1093 function ipTypeChangeHandlerFunc() {
1094 clearValidateMsg();
1095 return true;
1096 }
mj.qu11d28a82024-12-17 18:09:17 -08001097
qumengjiaca65ef52024-11-06 15:42:21 +08001098 //初始化port filter view model
mj.qu11d28a82024-12-17 18:09:17 -08001099
qumengjiaca65ef52024-11-06 15:42:21 +08001100 function initialize(viewModel) {
1101 var vm;
1102 if (viewModel) {
1103 vm = viewModel;
1104 var fltinfo = getPortFilter();
1105 vm.gridTemplate.clearAllChecked();
1106 vm.gridTemplate.data(fltinfo.portFilterRules);
1107 vm.defaultPolicy(fltinfo.defaultPolicy);
1108 vm.oriDefaultPolicy(fltinfo.defaultPolicy);
1109 vm.portFilterEnable(fltinfo.portFilterEnable);
1110 vm.oriPortFilterEnable(fltinfo.portFilterEnable);
1111 vm.rules(fltinfo.portFilterRules);
1112 refreshTableHeight();
1113 $('#portFilters').find('tbody').translate();
1114 renderCheckbox();
1115 $('.notes-content').translate();
1116 return;
1117 }
1118
1119 vm = new PortFilterVM();
1120 var container = $('#container');
1121 ko.cleanNode(container[0]);
1122 ko.applyBindings(vm, container[0]);
1123
1124 fixTableHeight();
1125
1126 $('#filterBasicForm').validate({
1127 submitHandler: function () {
1128 showConfirm("confirm_data_effect", function () {
1129 vm.setPortFilterBasic();
1130 });
1131 }
1132 });
1133
1134 $('#portFilterListForm').validate({
1135 submitHandler: function () {
1136 vm.deleteFilterRules();
1137 }
1138 });
1139
1140 $('#portFilterForm').validate({
1141 submitHandler: function () {
1142 vm.save();
1143 },
1144 rules: {
1145 txtMacAddress: {
1146 filter_optional: true,
1147 mac_check: true
1148 },
1149 txtDestIpAddress: {
1150 ip_check: true
1151 },
1152 txtSourceIpAddress: {
1153 ip_check: true
1154 },
1155 txtSourceIpv6Address: {
1156 ipv6: true
1157 },
1158 txtDestIpv6Address: {
1159 ipv6: true
1160 },
1161 txtDestPortStart: {
1162 digits: true,
1163 range: [1, 65535],
1164 portCompare: "#txtDestPortEnd"
1165 },
1166 txtDestPortEnd: {
1167 digits: true,
1168 range: [1, 65535],
1169 portCompare: "#txtDestPortStart"
1170 },
1171 txtSourcePortStart: {
1172 digits: true,
1173 range: [1, 65535],
1174 portCompare: "#txtSourcePortEnd"
1175 },
1176 txtSourcePortEnd: {
1177 digits: true,
1178 range: [1, 65535],
1179 portCompare: "#txtSourcePortStart"
1180 },
1181
1182 txtComment: {
1183 comment_check: true
1184 }
1185 },
1186 groups: {
1187 destPort: "txtDestPortStart txtDestPortEnd",
1188 sourcePort: "txtSourcePortStart txtSourcePortEnd"
1189 },
1190 errorPlacement: function (error, element) {
1191 if (element.attr("name") == "txtMacAddress") {
1192 error.appendTo("#macErrorDiv");
1193 } else if (element.attr("name") == "txtDestPortStart" || element.attr("name") == "txtDestPortEnd") {
1194 error.appendTo("#destPortErrorDiv");
1195 } else if (element.attr("name") == "txtSourcePortStart" || element.attr("name") == "txtSourcePortEnd") {
1196 error.appendTo("#sourcePortErrorDiv");
1197 } else
1198 error.insertAfter(element);
1199 }
1200 });
1201 }
1202
1203 $.validator.addMethod("filter_optional", function (value, element, param) {
1204 var result = _.any(['#txtMacAddress', '#txtDestIpAddress', '#txtSourceIpAddress', '#txtSourceIpv6Address', '#txtDestIpv6Address'],
1205 function (item) {
1206 var tmp = $(item).val().replace(/\s+/g, '');
1207 return $(item + ':visible').length > 0 && tmp != '';
1208 });
1209
1210 var portResult = _.any(['#txtDestPortStart', '#txtDestPortEnd', '#txtSourcePortStart', '#txtSourcePortEnd'],
1211 function (item) {
1212 return $(item).val() != '0';
1213 });
1214
1215 return result || portResult;
1216 });
1217
1218 return {
1219 init: initialize
1220 };
1221});
1222
1223//家长控制
mj.qu11d28a82024-12-17 18:09:17 -08001224
qumengjiaca65ef52024-11-06 15:42:21 +08001225define("firewall_parental_control","underscore jquery knockout set service".split(" "),
1226 function (_, $, ko, config, service) {
1227
1228 var maxItem = 10;
1229 var pcVm = null;
1230 var PAGES = {
1231 MAIN: 0,
1232 MANAGE: 1,
1233 RULE: 2
1234 };
mj.qu11d28a82024-12-17 18:09:17 -08001235
1236
qumengjiaca65ef52024-11-06 15:42:21 +08001237 function ParentalControlVM() {
1238 var target = this;
1239 var hostNameList = service.getHostNameList({}).devices;
1240 target.currentPage = ko.observable(PAGES.MAIN);
1241 target.pages = PAGES;
1242
1243
1244 target.childGroupList = ko.observable([]);
1245 target.childGroupMac = ko.computed(function () {
1246 return _.map(target.childGroupList(), function (data) {
1247 return data.mac;
1248 });
1249 });
mj.qu11d28a82024-12-17 18:09:17 -08001250
qumengjiaca65ef52024-11-06 15:42:21 +08001251 target.currentUserInChildGroup = ko.observable(true);
1252 //获取儿童组设备列表
mj.qu11d28a82024-12-17 18:09:17 -08001253
qumengjiaca65ef52024-11-06 15:42:21 +08001254 target.fetchChildGroupList = fetchChildGroupListFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001255
qumengjiaca65ef52024-11-06 15:42:21 +08001256 target.fetchChildGroupList();
1257
1258 target.manageHandler = manageHandlerFunc;
1259 function manageHandlerFunc() {
1260 target.currentPage(PAGES.MANAGE);
1261 target.fetchAttachedDevices();
1262 }
1263 target.attachedDevices = ko.observable([]);
1264 //获取已连接设备列表
mj.qu11d28a82024-12-17 18:09:17 -08001265
qumengjiaca65ef52024-11-06 15:42:21 +08001266 target.fetchAttachedDevices = fetchAttachedDevicesFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001267
qumengjiaca65ef52024-11-06 15:42:21 +08001268
1269 //儿童组设备 标签按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001270
qumengjiaca65ef52024-11-06 15:42:21 +08001271 target.backToMainHandler = backToMainHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001272
1273
qumengjiaca65ef52024-11-06 15:42:21 +08001274 ko.computed(function () {
1275 target.attachedDevices();
1276 target.childGroupList();
1277 $("#pc_children_group_form").translate();
1278 }).extend({
1279 notify: 'always',
1280 throttle: 300
1281 });
mj.qu11d28a82024-12-17 18:09:17 -08001282
qumengjiaca65ef52024-11-06 15:42:21 +08001283 //添加至儿童组
mj.qu11d28a82024-12-17 18:09:17 -08001284
qumengjiaca65ef52024-11-06 15:42:21 +08001285 function addChildGroupFun(flag, eleData) {
1286 showLoading();
1287 service.addChildGroup(eleData, function (data) {
1288 target.fetchChildGroupList(function () {
1289 target.fetchAttachedDevices(function () {
1290 hideLoading();
1291 if (flag) {
1292 service.logout({}, function () {
1293 window.location = 'index.html';
1294 });
1295 }
1296 });
1297 });
1298 }, function (data) {
1299 errorOverlay();
1300 });
1301 }
mj.qu11d28a82024-12-17 18:09:17 -08001302
qumengjiaca65ef52024-11-06 15:42:21 +08001303 //移除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001304
qumengjiaca65ef52024-11-06 15:42:21 +08001305 target.removeChildGroupHandler = removeChildGroupHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001306
1307
qumengjiaca65ef52024-11-06 15:42:21 +08001308 //添加按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001309
qumengjiaca65ef52024-11-06 15:42:21 +08001310 target.addChildGroupHandler = addChildGroupHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001311
qumengjiaca65ef52024-11-06 15:42:21 +08001312
1313 target.dealElement = dealElementFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001314
1315
1316
qumengjiaca65ef52024-11-06 15:42:21 +08001317 //取消编辑主机名按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001318
qumengjiaca65ef52024-11-06 15:42:21 +08001319 target.cancelEditHostNameHandler = cancelEditHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001320
qumengjiaca65ef52024-11-06 15:42:21 +08001321 //主机名编辑保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001322
qumengjiaca65ef52024-11-06 15:42:21 +08001323 target.saveHostNameHandler = saveHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001324
qumengjiaca65ef52024-11-06 15:42:21 +08001325 //主机名编辑按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001326
qumengjiaca65ef52024-11-06 15:42:21 +08001327 target.editHostNameHandler = editHostNameHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001328
1329
qumengjiaca65ef52024-11-06 15:42:21 +08001330 target.selectedIds = ko.observableArray([]);
1331 target.siteList = ko.observable([]);
1332 /////////////////////////////////////////////////////////////////
1333 target.disableAdd = ko.computed(function () {
1334 return target.siteList().length == maxItem;
1335 });
mj.qu11d28a82024-12-17 18:09:17 -08001336
qumengjiaca65ef52024-11-06 15:42:21 +08001337 ko.computed(function () {
1338 target.siteList();
1339 target.selectedIds();
1340 setTimeout(function () {
1341 renderCheckbox();
1342 }, 100);
1343 $("#pc_site_white_list_form").translate();
1344 });
mj.qu11d28a82024-12-17 18:09:17 -08001345
qumengjiaca65ef52024-11-06 15:42:21 +08001346 //网站白名单添加按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001347
qumengjiaca65ef52024-11-06 15:42:21 +08001348 target.openAddSitePopoverHandler = openAddSitePopoverHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001349
qumengjiaca65ef52024-11-06 15:42:21 +08001350 //网站白名单列表选择框点击事件
mj.qu11d28a82024-12-17 18:09:17 -08001351
qumengjiaca65ef52024-11-06 15:42:21 +08001352 target.checkboxClickHandler = checkboxClickHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001353
qumengjiaca65ef52024-11-06 15:42:21 +08001354 //获取网站白名单列表
mj.qu11d28a82024-12-17 18:09:17 -08001355
qumengjiaca65ef52024-11-06 15:42:21 +08001356 target.fetchSiteWhiteList = fetchSiteWhiteListFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001357
qumengjiaca65ef52024-11-06 15:42:21 +08001358 //网站白名单删除函数
mj.qu11d28a82024-12-17 18:09:17 -08001359
qumengjiaca65ef52024-11-06 15:42:21 +08001360 function removeSiteWhiteItem(ids) {
1361 showConfirm('confirm_data_delete', function () {
1362 showLoading();
1363 service.removeSiteWhite({
1364 ids: ids
1365 }, function (data) {
1366 target.fetchSiteWhiteList(function () {
1367 successOverlay();
1368 });
1369 }, function (data) {
1370 target.fetchSiteWhiteList(function () {
1371 errorOverlay();
1372 });
1373 });
1374 });
1375 }
1376 //网站白名单删除所有按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001377
qumengjiaca65ef52024-11-06 15:42:21 +08001378 target.removeAllWhiteSite = removeAllWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001379
qumengjiaca65ef52024-11-06 15:42:21 +08001380 //网站白名单删除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001381
qumengjiaca65ef52024-11-06 15:42:21 +08001382 target.removeSelectedWhiteSite = removeSelectedWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001383
qumengjiaca65ef52024-11-06 15:42:21 +08001384 //网站白名单移除按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001385
qumengjiaca65ef52024-11-06 15:42:21 +08001386 target.removeWhiteSite = removeWhiteSiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001387
1388
1389
qumengjiaca65ef52024-11-06 15:42:21 +08001390 //网站白名单添加框保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001391
qumengjiaca65ef52024-11-06 15:42:21 +08001392 target.saveSiteWhite = saveSiteWhiteFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001393
qumengjiaca65ef52024-11-06 15:42:21 +08001394 //////////////////////////////////////////////////////////////////
1395 target.notSave = ko.observable(false);
1396 //获取时间限制信息
mj.qu11d28a82024-12-17 18:09:17 -08001397
qumengjiaca65ef52024-11-06 15:42:21 +08001398 target.fetchTimeLimited = fetchTimeLimitedFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001399
1400
qumengjiaca65ef52024-11-06 15:42:21 +08001401 //上网时间设置时间表格事件绑定
mj.qu11d28a82024-12-17 18:09:17 -08001402
qumengjiaca65ef52024-11-06 15:42:21 +08001403 target.bindEvent = bindEventFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001404
qumengjiaca65ef52024-11-06 15:42:21 +08001405 //上网时间设置保存按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001406
qumengjiaca65ef52024-11-06 15:42:21 +08001407 target.saveTimeLimitedHandler = saveTimeLimitedHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001408
qumengjiaca65ef52024-11-06 15:42:21 +08001409 //////////////////////////////////////////////////////////////////
1410 var isBinded = false;
1411 //上网规则标签点击事件
mj.qu11d28a82024-12-17 18:09:17 -08001412
qumengjiaca65ef52024-11-06 15:42:21 +08001413 target.openRulePage = openRulePageFunc;
1414 function openRulePageFunc() {
1415 if (target.currentPage() == PAGES.RULE) {
1416 return;
1417 }
1418 target.currentPage(PAGES.RULE);
1419 target.currentUserInChildGroup(service.checkCurrentUserInChildGroup().result);
1420 initTableData();
1421 if (!isBinded) {
1422 if (!target.currentUserInChildGroup()) {
1423 target.bindEvent();
1424 }
1425 isBinded = true;
1426 }
1427 showLoading();
1428 target.fetchTimeLimited();
1429 target.fetchSiteWhiteList(function () {
1430 hideLoading();
1431 });
1432 }
mj.qu11d28a82024-12-17 18:09:17 -08001433
qumengjiaca65ef52024-11-06 15:42:21 +08001434 //获取儿童组设备列表
1435 function fetchChildGroupListFunc(cb) {
1436 service.childGroupList({}, function (data) {
1437 target.currentUserInChildGroup(service.checkCurrentUserInChildGroup(data.devices).result);
1438 target.childGroupList([]);
1439 _.map(data.devices, function (elem, idx) {
1440 elem.idx = idx;
1441 elem.hostname = pcUtil.getHostName(elem.hostname, elem.mac, hostNameList);
1442 });
1443 target.childGroupList(data.devices);
1444 if (_.isFunction(cb)) {
1445 cb.apply(this);
1446 }
1447 });
1448 }
mj.qu11d28a82024-12-17 18:09:17 -08001449
qumengjiaca65ef52024-11-06 15:42:21 +08001450 //获取已连接设备列表
1451 function fetchAttachedDevicesFunc(cb) {
1452 target.attachedDevices([]);
1453 var counter = 0;
1454 var currDevices = [];
1455 //RJ45 已连接设备
1456 service.getAttachedCableDevices({}, function (data) {
1457 counter++;
1458 var devs = _.map(data.attachedDevices, function (elem) {
1459 elem.idx = _.uniqueId('wireless_');
1460 elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
1461 elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
1462 return elem;
1463 });
1464 if (counter != 1) {
1465 target.attachedDevices(_.flatten([currDevices, devs]));
1466 if (_.isFunction(cb)) {
1467 cb.apply(this);
1468 }
1469 } else {
1470 currDevices = devs;
1471 }
1472 });
mj.qu11d28a82024-12-17 18:09:17 -08001473
qumengjiaca65ef52024-11-06 15:42:21 +08001474 //wifi 已连接设备
1475 service.getCurrentlyAttachedDevicesInfo({}, function (data) {
1476 counter++;
1477 var devs = _.map(data.attachedDevices, function (elem) {
1478 elem.idx = _.uniqueId('wireless_');
1479 elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
1480 elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
1481 return elem;
1482 });
1483 if (counter != 1) {
1484 target.attachedDevices(_.flatten([currDevices, devs]));
1485 if (_.isFunction(cb)) {
1486 cb.apply(this);
1487 }
1488 } else {
1489 currDevices = devs;
1490 }
1491 });
1492 }
1493 //儿童组设备 标签按钮事件
1494 function backToMainHandlerFunc() {
1495 target.currentPage(PAGES.MAIN);
1496 }
mj.qu11d28a82024-12-17 18:09:17 -08001497
qumengjiaca65ef52024-11-06 15:42:21 +08001498 //移除按钮事件
1499 function removeChildGroupHandlerFunc(ele) {
1500 showLoading();
1501 service.removeChildGroup(ele, function (data) {
1502 target.fetchChildGroupList(function () {
1503 target.fetchAttachedDevices(function () {
1504 hideLoading();
1505 });
1506 });
1507 }, function (data) {
1508 errorOverlay();
1509 });
1510 }
mj.qu11d28a82024-12-17 18:09:17 -08001511
qumengjiaca65ef52024-11-06 15:42:21 +08001512 //添加按钮事件
1513 function addChildGroupHandlerFunc(data) {
1514 var uMacAddr = service.getCurretnMAC();
1515 if (uMacAddr != data.macAddress) {
1516 addChildGroupFun(false, data);
1517 } else {
1518 showConfirm("parental_add_self", function () {
1519 addChildGroupFun(true, data);
1520 })
1521 }
1522 }
mj.qu11d28a82024-12-17 18:09:17 -08001523
qumengjiaca65ef52024-11-06 15:42:21 +08001524 //取消编辑主机名按钮事件
1525 function cancelEditHostNameHandlerFunc(eleData) {
1526 target.dealElement(false, eleData.idx);
1527 }
mj.qu11d28a82024-12-17 18:09:17 -08001528
qumengjiaca65ef52024-11-06 15:42:21 +08001529 //主机名编辑保存按钮事件
1530 function saveHostNameHandlerFunc(ele) {
1531 var $hostInput = $("#hostname_input_" + ele.idx);
1532 var hostname = $.trim($hostInput.val());
1533 if (hostname.indexOf(" ") == 0 || hostname.lastIndexOf(" ") == (hostname.length - 1) || /[\*\+\$\[&:,;<>'"\\`\]¥]{1,32}/.test(hostname)) {
1534 showAlert('modify_hostname_invalid');
1535 return false;
1536 }else if (hostname == '') {
1537 $(".promptErrorLabel", "#confirm-message-container").text($.i18n.prop("required"));
1538 var $closestTD = $hostInput.closest('td').addClass('has-error');
1539 addTimeout(function () {
1540 $closestTD.removeClass('has-error');
1541 }, 5000);
1542 showAlert('required');
1543 return false;
1544 }
1545 showLoading();
1546 ele.hostname = hostname;
1547 service.editHostName(ele, function () {
1548 service.getHostNameList({}, function (hostNameData) {
1549 hostNameList = hostNameData.devices;
1550 target.fetchChildGroupList(function () {
1551 hideLoading();
1552 });
1553 target.fetchAttachedDevices();
1554 });
1555 }, function () {
1556 errorOverlay();
1557 });
1558 }
mj.qu11d28a82024-12-17 18:09:17 -08001559
qumengjiaca65ef52024-11-06 15:42:21 +08001560 //主机名编辑按钮事件
1561 function editHostNameHandlerFunc(ele) {
1562 $("#hostname_input_" + ele.idx).val(ele.hostname);
1563 target.dealElement(true, ele.idx);
1564 return false;
1565 }
1566 //网站白名单添加按钮事件
1567 function openAddSitePopoverHandlerFunc() {
1568 var addNewSiteTmpl = $("#addNewSiteTmpl").html();
1569 popover.open({
1570 target: $("#openAddSiteBtn"),
1571 html: addNewSiteTmpl,
1572 width: "300px",
1573 validation: addValidation
1574 });
1575 }
mj.qu11d28a82024-12-17 18:09:17 -08001576
qumengjiaca65ef52024-11-06 15:42:21 +08001577 //网站白名单列表选择框点击事件
1578 function checkboxClickHandlerFunc(eleData, evt) {
1579 addTimeout(function () {
1580 target.selectedIds(getSelectedValues());
1581 }, 100);
1582 }
1583 //获取网站白名单列表
1584 function fetchSiteWhiteListFunc(cb) {
1585 service.getSiteWhiteList({}, function (eledata) {
1586 target.selectedIds([]);
1587 target.siteList(eledata.siteList);
1588 _.isFunction(cb) && cb.apply(this);
1589 }, function () {
1590 target.siteList([]);
1591 _.isFunction(cb) && cb.apply(this);
1592 });
1593 }
mj.qu11d28a82024-12-17 18:09:17 -08001594
qumengjiaca65ef52024-11-06 15:42:21 +08001595 //网站白名单删除所有按钮事件
1596 function removeAllWhiteSiteFunc() {
1597 removeSiteWhiteItem(getAllCheckboxValues());
1598 }
1599 //网站白名单删除按钮事件
1600 function removeSelectedWhiteSiteFunc() {
1601 removeSiteWhiteItem(getSelectedValues());
1602 }
1603 //网站白名单移除按钮事件
1604 function removeWhiteSiteFunc(ele, evt) {
1605 removeSiteWhiteItem([ele.id]);
1606 }
mj.qu11d28a82024-12-17 18:09:17 -08001607
qumengjiaca65ef52024-11-06 15:42:21 +08001608 //网站白名单添加框保存按钮事件
1609 function saveSiteWhiteFunc(name, site) {
1610 popover.hide();
1611 var matched = _.find(target.siteList(), function (one) {
1612 return one.site == site;
1613 });
1614 if (matched) {
1615 showAlert("pc_link_exist", function () {
1616 setTimeout(function () {
1617 popover.show();
1618 }, 200);
1619 });
1620 return false;
1621 }
1622
1623 showLoading();
1624 service.saveSiteWhite({
1625 name: name,
1626 site: site
1627 }, function () {
1628 target.fetchSiteWhiteList(function () {
1629 popover.close();
1630 successOverlay();
1631 });
1632 }, function () {
1633 target.fetchSiteWhiteList(function () {
1634 errorOverlay();
1635 popover.show();
1636 });
1637 });
1638 }
mj.qu11d28a82024-12-17 18:09:17 -08001639
qumengjiaca65ef52024-11-06 15:42:21 +08001640 //上网时间设置时间表格事件绑定
1641 function bindEventFunc() {
1642 $("td:not('.col-head')", "#pc_time_limited_tbody").addClass('cursorhand').die().click(function () {
1643 target.notSave(true);
1644 $(this).toggleClass('active');
1645 }).hover(function () {
1646 var $this = $(this);
1647 var w = $this.data('week');
1648 var h = $this.data('hour');
1649 $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").addClass('time_td_hover');
1650 $("#col_" + h).addClass('time_td_hover');
1651 if ($this.not('.active')) {
1652 $this.addClass('time_td_hover');
1653 }
1654 }, function () {
1655 var $this = $(this);
1656 var w = $this.data('week');
1657 var h = $this.data('hour');
1658 $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").removeClass('time_td_hover');
1659 $("#col_" + h).removeClass('time_td_hover');
1660 $this.removeClass('time_td_hover');
1661 });
1662 }
mj.qu11d28a82024-12-17 18:09:17 -08001663
qumengjiaca65ef52024-11-06 15:42:21 +08001664 //上网时间设置保存按钮事件
1665 function saveTimeLimitedHandlerFunc() {
1666 showLoading();
1667 var tds = getSelectedTds();
1668 var timeStr = getSavedData(tds);
1669 service.saveTimeLimited({
1670 time: timeStr
1671 }, function () {
1672 target.notSave(false);
1673 successOverlay();
1674 }, function () {
1675 errorOverlay();
1676 });
1677 }
mj.qu11d28a82024-12-17 18:09:17 -08001678
qumengjiaca65ef52024-11-06 15:42:21 +08001679 }
mj.qu11d28a82024-12-17 18:09:17 -08001680
qumengjiaca65ef52024-11-06 15:42:21 +08001681 function dealElementFunc(flag, idx) {
1682 if (flag == false) {
1683 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).show();
1684 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).hide();
1685 } else {
1686 $("#edit_btn_" + idx + ",#hostname_txt_" + idx).hide();
1687 $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).show();
1688 }
1689 }
1690
1691 //获取时间限制信息
1692 function fetchTimeLimitedFunc() {
1693 service.getTimeLimited({}, function (ele) {
1694 for (var ki in ele) {
1695 for (var idx = 0; idx < ele[ki].length; idx++) {
1696 var id = 'td_' + ki + '_' + ele[ki][idx];
1697 $("#" + id).addClass('active');
1698 }
1699 }
1700 }, function () {});
1701 }
1702
1703 var pcUtil = {
1704 getHostName: function (hostName, mac, hostNameList) {
1705 var ele = _.find(hostNameList, function (ele) {
1706 return ele.mac == mac;
1707 });
1708 return ele ? ele.hostname : hostName;
1709 }
1710 };
1711 function getCheckboxValues(flag) {
1712 var selectedValues = [];
1713 $(":checkbox" + (flag ? ":checked" : ""), "#pb_white_list").each(function (i, n) {
1714 selectedValues.push(n.value)
1715 });
1716 return selectedValues;
1717 }
1718 //获取列表中被选中项的value值
mj.qu11d28a82024-12-17 18:09:17 -08001719
qumengjiaca65ef52024-11-06 15:42:21 +08001720 function getSelectedValues() {
1721 return getCheckboxValues(true);
1722 }
1723 function getAllCheckboxValues() {
1724 return getCheckboxValues(false);
1725 }
mj.qu11d28a82024-12-17 18:09:17 -08001726
qumengjiaca65ef52024-11-06 15:42:21 +08001727 //增加网站白名单表单提交函数绑定和校验规则设置
mj.qu11d28a82024-12-17 18:09:17 -08001728
qumengjiaca65ef52024-11-06 15:42:21 +08001729 function addValidation() {
1730 $('#whiteSiteAddForm').validate({
1731 submitHandler: function () {
1732 var name = $("#siteName").val();
1733 var site = $("#siteLink").val();
1734 pcVm.saveSiteWhite(name, site);
1735 },
1736 rules: {
1737 siteName: 'siteName_check',
1738 siteLink: 'siteLink_check'
1739 }
1740 });
1741 }
mj.qu11d28a82024-12-17 18:09:17 -08001742
qumengjiaca65ef52024-11-06 15:42:21 +08001743 function getSavedData(timeDatas) {
1744 var ret = '';
1745 for (var ki in timeDatas) {
1746 var hours = _.sortBy(timeDatas[ki], function (n) {
1747 return n;
1748 });
1749 if (timeDatas[ki].length) {
1750 ret += ki + '+';
1751 ret += hours.join(',');
1752 ret += ';'
1753 }
1754 }
1755 return ret.substring(0, ret.length - 1);
1756 }
1757 //获取时间表格选中的时间
mj.qu11d28a82024-12-17 18:09:17 -08001758
qumengjiaca65ef52024-11-06 15:42:21 +08001759 function getSelectedTds() {
1760 var defaultValue = {
1761 '0': [],
1762 '1': [],
1763 '2': [],
1764 '3': [],
1765 '4': [],
1766 '5': [],
1767 '6': []
1768 };
1769 $("td.active", "#pc_time_limited_tbody").each(function (i, n) {
1770 var $this = $(n);
1771 var week = $this.data('week');
1772 var hour = $this.data('hour');
1773 defaultValue[week].push(hour);
1774 });
1775 return defaultValue;
1776 }
1777
1778 function convertHour(hour) {
1779 if (hour <= 16) {
1780 return hour + 7;
1781 } else {
1782 return hour - 17;
1783 }
1784 }
1785 //初始化时间表格
mj.qu11d28a82024-12-17 18:09:17 -08001786
qumengjiaca65ef52024-11-06 15:42:21 +08001787 function initTableData() {
1788 $("tr", "#pc_time_limited_tbody").each(function (idx, n) {
1789 var $tr = $(n);
1790 $("td:not(:first)", $tr).each(function (j, m) {
1791 var $td = $(m);
1792 var hour = convertHour(j);
1793 $td.attr({
1794 id: 'td_' + idx + '_' + hour
1795 }).data({
1796 week: idx,
1797 hour: hour
1798 });
1799 });
1800 });
1801 $("td.active", "#pc_time_limited_tbody").removeClass("active");
1802 $("thead td:not(:first)", "#pc_time_limited_form").each(function (idx, n) {
1803 var hour = convertHour(idx);
1804 $(n).attr({
1805 id: 'col_' + hour
1806 });
1807 });
1808 pcVm.notSave(false);
1809 }
1810
mj.qu11d28a82024-12-17 18:09:17 -08001811
qumengjiaca65ef52024-11-06 15:42:21 +08001812 //页面初始化
mj.qu11d28a82024-12-17 18:09:17 -08001813
qumengjiaca65ef52024-11-06 15:42:21 +08001814 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -08001815
qumengjiaca65ef52024-11-06 15:42:21 +08001816 pcVm = new ParentalControlVM();
1817 bindContainer(pcVm);
1818 }
1819 function bindContainer(pcVm)
1820 {
1821 var container = $('#container');
1822 ko.cleanNode(container[0]);
1823 ko.applyBindings(pcVm, container[0]);
1824 }
1825
1826 return {
1827 init: initialize
1828 };
1829});
1830
1831define("firewall_dmz_set","underscore jquery knockout set service".split(" "),
1832 function ( _, $, ko, config, service) {
1833
1834 //system dmz setting VM
mj.qu11d28a82024-12-17 18:09:17 -08001835
qumengjiaca65ef52024-11-06 15:42:21 +08001836 function DmzSettingVM() {
1837 var target = this;
1838 var dmzInfo = getDmzSetting();
1839 target.dmzSetting = ko.observable(dmzInfo.dmzSetting);
1840 target.ipAddress = ko.observable(dmzInfo.ipAddress);
1841 target.isDataCard = config.PRODUCT_TYPE == 'DATACARD';
1842
1843 target.clear = clearFunc;
1844 //应用按钮事件
mj.qu11d28a82024-12-17 18:09:17 -08001845
qumengjiaca65ef52024-11-06 15:42:21 +08001846 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08001847
qumengjiaca65ef52024-11-06 15:42:21 +08001848 function saveFunc() {
1849 showLoading();
1850 var params = {};
1851 params.dmzSetting = target.dmzSetting();
1852 params.ipAddress = target.ipAddress();
1853 service.setDmzSetting(params, function (result) {
1854 if (result.result != "success") {
1855 errorOverlay();
1856 } else {
1857 target.clear();
1858 successOverlay();
1859 }
1860 });
1861 }
mj.qu11d28a82024-12-17 18:09:17 -08001862
qumengjiaca65ef52024-11-06 15:42:21 +08001863 }
mj.qu11d28a82024-12-17 18:09:17 -08001864
qumengjiaca65ef52024-11-06 15:42:21 +08001865 function clearFunc() {
1866 initialize();
1867 }
mj.qu11d28a82024-12-17 18:09:17 -08001868
1869
qumengjiaca65ef52024-11-06 15:42:21 +08001870 //获取dmz 信息
mj.qu11d28a82024-12-17 18:09:17 -08001871
qumengjiaca65ef52024-11-06 15:42:21 +08001872 function getDmzSetting() {
1873 return service.getDmzSetting();
1874 }
1875
1876 //初始化DmzSettingVM model
mj.qu11d28a82024-12-17 18:09:17 -08001877
qumengjiaca65ef52024-11-06 15:42:21 +08001878 function initialize() {
mj.qu11d28a82024-12-17 18:09:17 -08001879
qumengjiaca65ef52024-11-06 15:42:21 +08001880 var dmzVm = new DmzSettingVM();
1881 bindContainer(dmzVm);
1882 }
1883 function bindContainer(dmzVm){
1884 var container = $('#container');
1885 ko.cleanNode(container[0]);
1886 ko.applyBindings(dmzVm, container[0]);
1887 $('#dmzSettingForm').validate({
1888 submitHandler: function () {
1889 dmzVm.save();
1890 },
1891 rules: {
1892 txtIpAddress: 'dmz_ip_check'
1893 }
1894 });
1895 }
1896
1897 return {
1898 init: initialize
1899 };
1900});
1901
1902define("firewall","underscore jquery knockout set service".split(" "),
1903
1904function(_, $, ko, config, service) {
1905
1906 function FirewallVM() {
1907 var target = this;
1908 target.hasDdns = config.DDNS_SUPPORT;
1909 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1910 target.hasUrlFilter = config.HAS_URL;
1911 target.hasUssd = config.HAS_USSD;
1912 target.hasUpnp = config.HAS_UPNP;
1913 }
1914
1915 function initialize() {
1916 var fwVm = new FirewallVM();
1917 bindingContainer(fwVm);
1918 }
1919 function bindingContainer(fwVm)
1920 {
1921 var container = $('#container');
1922 ko.cleanNode(container[0]);
1923 ko.applyBindings(fwVm, container[0]);
1924 }
1925 return {
1926 init : initialize
1927 };
1928});
1929
1930define("ddns","underscore jquery knockout set service".split(" "), function (_, $, ko, config, service) {
1931 var ddnsSetModes = _.map(config.DDNSSetMode, newOption);
1932 var ddnsProviderList = _.map(config.DDNSDDP, newOption);
1933 var ddns_mode_select = _.map(config.ddns_Modeselect, newOption);
1934 function newOption(optItem) {
1935 return new Option(optItem.name, optItem.value);
1936 }
1937 function DdnsViewModel() {
1938 var target = this;
1939 target.hasUssd = config.HAS_USSD;
1940 target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
1941 var data = service.getDdnsParams();
1942 target.ddnsSetModes = ko.observableArray(ddnsSetModes);
1943 target.ddnsProviderList = ko.observableArray(ddnsProviderList);
1944 target.ddns_mode_select = ko.observableArray(ddns_mode_select);
1945 target.currentMode = ko.observable(data.DDNS_Enable);
1946 target.currentModeselect = ko.observable(data.DDNS_Mode);
1947 target.currentProviderList = ko.observable("dyndns.org");
1948 $.each(config.DDNSDDP, function (i, n) {
1949 if (data.DDNSProvider == n.value) {
1950 target.currentProviderList(data.DDNSProvider);
1951 }
1952 });
1953 target.DDNSaccount = ko.observable(data.DDNSAccount);
1954 target.DDNSpasswd = ko.observable(data.DDNSPassword);
1955 target.DDNSname = ko.observable(data.DDNS);
1956 target.DDNS_HashValue = ko.observable(data.DDNS_Hash_Value);
1957 target.isddnsStatusTrans = ko.observable();
1958 target.isEnableSet = ko.observable();
1959 target.isHashValue = ko.observable();
1960 target.isddnsaccount = ko.observable();
1961 target.isddnspasswd = ko.observable();
1962 target.isDDNSStatus = ko.observable();
1963 target.isddnsdomainName = ko.observable();
1964 target.isNone = ko.observable();
1965 target.onStates = ko.observable();
1966 target.showPassword_ddns = ko.observable(false);
1967 target.showPasswordHandler_ddns = showPasswordHandler_ddns;
1968 changeddnsProviderList();
1969 target.changeDdnsProvider = changeDdnsProviderFunc;
1970 changeSetDdnsMode();
1971 target.changeSetDdnsMode = changeSetDdnsModeFunc;
1972 updateScanDdnsStatus();
1973 target.apply = applyFunc;
1974 function updateScanDdnsStatus() {
1975 var trans = "";
1976 $.getJSON("/reqproc/proc_get", {
1977 cmd: "getddns_status",
1978 "_": new Date().getTime()
1979 }, function (data) {
1980 if (data.getddns_status == "0") {
1981 trans = "register successful";
1982 target.onStates(true);
1983 } else if (data.getddns_status == "1") {
1984 trans = "login error";
1985 target.onStates(true);
1986 } else if (data.getddns_status == "2") {
1987 trans = "network error";
1988 target.onStates(true);
1989 } else if (data.getddns_status == "3") {
1990 trans = "registering";
1991 target.onStates(true);
1992 } else if (data.getddns_status == "4") {
1993 trans = "not registered";
1994 target.onStates(true);
1995 } else if (data.getddns_status == "5") {
1996 trans = "error registering";
1997 target.onStates(true);
1998 } else if (data.getddns_status == "-1") {
1999 trans = "";
2000 target.onStates(true);
2001 }
2002 target.isddnsStatusTrans($.i18n.prop(trans));
2003 addTimeout(updateScanDdnsStatus, 2000);
2004 });
2005 }
2006 function changeSetDdnsMode() {
2007 if (target.currentMode() != "1") {
2008 target.isEnableSet(false);
2009 } else {
2010 target.isEnableSet(true);
2011 }
2012 return true;
2013 }
2014 function changeSetDdnsModeFunc() {
2015 changeSetDdnsMode();
2016 }
2017 function showPasswordHandler_ddns() {
2018 $("#ddns_secretcode_input").parent().find(".error").hide();
2019 var checkbox = $("#showPassword_ddns:checked");
2020 if (checkbox && checkbox.length == 0) {
2021 target.showPassword_ddns(true);
2022 } else {
2023 target.showPassword_ddns(false);
2024 }
2025 }
2026 function changeDdnsProviderFunc() {
2027 if (data.DDNSProvider != target.currentProviderList()) {
2028 target.DDNSaccount("");
2029 target.DDNSpasswd("");
2030 target.DDNSname("");
2031 } else {
2032 target.DDNSaccount(data.DDNSAccount);
2033 target.DDNSpasswd(data.DDNSPassword);
2034 target.DDNSname(data.DDNS);
2035 }
2036 changeddnsProviderList();
2037 }
2038 function changeddnsProviderList() {
2039 if (target.currentProviderList() != "none") {
2040 target.isddnsaccount(true);
2041 target.isddnspasswd(true);
2042 target.isddnsdomainName(true);
2043 target.isHashValue(true);
2044 target.isDDNSStatus(true);
2045 } else {
2046 target.isddnsaccount(false);
2047 target.isddnspasswd(false);
2048 target.isddnsdomainName(false);
2049 target.isHashValue(false);
2050 target.isDDNSStatus(false);
2051 }
2052 if (target.currentProviderList() != "freedns.afraid.org") {
2053 target.isHashValue(false);
2054 } else {
2055 target.isHashValue(true);
2056 }
2057 return true;
2058 }
2059 function applyFunc() {
2060 showLoading();
2061 var params = {};
2062 params.goformId = "DDNS";
2063 params.DDNS_Enable = target.currentMode();
2064 if (target.currentMode() == "1") {
2065 params.DDNS_Mode = target.currentModeselect();
2066 params.DDNSProvider = target.currentProviderList();
2067 if (target.currentProviderList() != "none") {
2068 params.DDNS = target.DDNSname();
2069 params.DDNSPassword = target.DDNSpasswd();
2070 params.DDNSAccount = target.DDNSaccount();
2071 }
2072 if (target.currentProviderList() == "freedns.afraid.org") {
2073 params.DDNS_Hash_Value = target.DDNS_HashValue();
2074 }
2075 }
2076 service.setDDNSForward(params, function (result) {
2077 if (result.result == "success") {
2078 successOverlay();
2079 data = service.getDdnsParams();
2080 } else {
2081 errorOverlay();
2082 }
2083 });
2084 }
2085 }
2086 function initialize() {
2087 var container = $('#container');
2088 ko.cleanNode(container[0]);
2089 var vm = new DdnsViewModel();
2090 ko.applyBindings(vm, container[0]);
2091 $("#ddnsForm").validate({
2092 submitHandler: function () {
2093 vm.apply();
2094 },
2095 rules: {
2096 ddns_secretcode_input: "secretcode_check",
2097 DDNS_Hash_Value: "ddns_hashvalue_check",
2098 ddns_secretcode_inputshow: "secretcode_check"
2099 },
2100 errorPlacement: function (error, element) {
2101 var id = element.attr("id");
2102 if (id == "ddns_secretcode_input" || id == "ddns_secretcode_inputshow") {
2103 error.insertAfter("#lblShowPassword");
2104 } else {
2105 error.insertAfter(element);
2106 }
2107 }
2108 });
2109 }
2110 return {
2111 init: initialize
2112 };
2113});
2114
2115
2116//选网模块
mj.qu11d28a82024-12-17 18:09:17 -08002117
qumengjiaca65ef52024-11-06 15:42:21 +08002118define("network_net_select","underscore jquery knockout set service".split(" "),
2119 function (_, $, ko, config, service) {
2120
2121 var selectModes = _.map(config.AUTO_MODES, function (item) {
2122 return new Option(item.name, item.value);
2123 });
2124
2125 //选网功能view model
mj.qu11d28a82024-12-17 18:09:17 -08002126
qumengjiaca65ef52024-11-06 15:42:21 +08002127 function NetSelectVM() {
2128 var target = this;
2129
2130 target.networkList = ko.observableArray([]);
2131 target.selectNetwork = ko.observable('');
2132 target.enableFlag = ko.observable(true);
2133 target.types = ko.observableArray(selectModes);
2134 target.selectedType = ko.observable();
2135 target.selectMode = ko.observable();
2136
2137 target.networkText = networkTextFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002138
qumengjiaca65ef52024-11-06 15:42:21 +08002139 target.networkStatusId = networkStatusIdFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002140
qumengjiaca65ef52024-11-06 15:42:21 +08002141 target.networkStatus = networkStatusFunc;
2142
2143 target.subnetworkType = subnetworkTypeFunc;
2144
2145 target.networkType = networkTypeFunc;
2146
2147 target.operatorName = operatorNameFunc;
2148
2149 target.networkValue = networkValueFunc;
2150
2151 target.networkTypeId = networkTypeIdFunc;
2152
2153 target.subnetTypeId = subnetTypeIdFunc;
2154 //手动搜网.
mj.qu11d28a82024-12-17 18:09:17 -08002155
qumengjiaca65ef52024-11-06 15:42:21 +08002156 target.search = searchFunc;
2157
2158 //自动选网时设置网络模式.
mj.qu11d28a82024-12-17 18:09:17 -08002159
qumengjiaca65ef52024-11-06 15:42:21 +08002160 target.save = saveFunc;
2161
2162 target.checkEnable = checkEnableFunc;
2163
2164 //注册选择的网络.
mj.qu11d28a82024-12-17 18:09:17 -08002165
qumengjiaca65ef52024-11-06 15:42:21 +08002166 target.register = registerFunc;
2167
2168 //init data
2169 target.checkEnable();
2170 var info = getNetSelectInfo();
2171 if ("manual_select" == info.net_select_mode || "manual_select" == info.m_netselect_save) {
2172 target.selectMode("manual_select");
2173 } else {
2174 target.selectMode("auto_select");
2175 }
2176
2177 target.selectedType(info.net_select);
mj.qu11d28a82024-12-17 18:09:17 -08002178
qumengjiaca65ef52024-11-06 15:42:21 +08002179 //注册选择的网络.
2180 function registerFunc() {
2181 showLoading('registering_net');
2182 var networkToSet = target.selectNetwork().split(',');
2183 service.setNetwork(networkToSet[0], parseInt(networkToSet[1]), parseInt(networkToSet[2]), function (result) {
2184 if (result) {
2185 target.networkList([]);
2186 var autoType = getNetSelectInfo();
2187 target.selectedType(autoType.net_select);
2188 successOverlay();
2189 } else {
2190 errorOverlay();
2191 }
2192 });
2193 }
mj.qu11d28a82024-12-17 18:09:17 -08002194
qumengjiaca65ef52024-11-06 15:42:21 +08002195 function checkEnableFunc() {
2196 var status = service.getStatusInfo();
2197 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
2198 target.enableFlag(false);
2199 } else {
2200 target.enableFlag(true);
2201 }
2202 }
mj.qu11d28a82024-12-17 18:09:17 -08002203
qumengjiaca65ef52024-11-06 15:42:21 +08002204 //自动选网时设置网络模式.
2205 function saveFunc() {
2206 showLoading();
2207
2208 //AutoSelect call SetBearerPreference
2209 var params = {};
2210 params.strBearerPreference = target.selectedType();
2211 service.setBearerPreference(params, function (result) {
2212 if (result.result == "success") {
2213 target.networkList([]);
2214 successOverlay();
2215 } else {
2216 errorOverlay();
2217 }
2218 });
2219 }
mj.qu11d28a82024-12-17 18:09:17 -08002220
qumengjiaca65ef52024-11-06 15:42:21 +08002221 //手动搜网.
2222 function searchFunc() {
2223 showLoading('searching_net');
2224 service.scanForNetwork(function (result, networkList) {
2225 hideLoading();
2226 if (result) {
2227 target.networkList(networkList);
2228 for (var i = 0; i < networkList.length; i++) {
2229 var n = networkList[i];
2230 if (n.nState == '2') {
2231 target.selectNetwork(n.strNumeric + ',' + n.nRat + ',' + n.SubAct);
2232 return;
2233 }
2234 }
2235 } else {
mj.qu825d1ec2024-12-29 22:54:09 -08002236 errorOverlay();
qumengjiaca65ef52024-11-06 15:42:21 +08002237 target.networkList([]);
2238 }
2239 });
2240 }
mj.qu11d28a82024-12-17 18:09:17 -08002241
qumengjiaca65ef52024-11-06 15:42:21 +08002242 function subnetTypeIdFunc(data) {
2243 return getSubNetworkTypeTog(data.nRat, data.SubAct);
2244 }
mj.qu11d28a82024-12-17 18:09:17 -08002245
qumengjiaca65ef52024-11-06 15:42:21 +08002246 function networkTypeIdFunc(data) {
2247 return getNetworkType(data.nRat);
2248 }
mj.qu11d28a82024-12-17 18:09:17 -08002249
qumengjiaca65ef52024-11-06 15:42:21 +08002250 function networkValueFunc(data) {
2251 var result = [];
2252 result.push(data.strNumeric); //strNumeric
2253 result.push(data.nRat); //nRat
2254 result.push(data.SubAct);
2255 return result.join(',');
2256 }
mj.qu11d28a82024-12-17 18:09:17 -08002257
qumengjiaca65ef52024-11-06 15:42:21 +08002258 function operatorNameFunc(data) {
2259 return data.strShortName;
2260 }
mj.qu11d28a82024-12-17 18:09:17 -08002261
qumengjiaca65ef52024-11-06 15:42:21 +08002262 function networkTypeFunc(data) {
2263 var result = getNetworkType(data.nRat);
2264 if (result == "auto")
2265 result = $.i18n.prop("auto");
2266 return result;
2267 }
mj.qu11d28a82024-12-17 18:09:17 -08002268
qumengjiaca65ef52024-11-06 15:42:21 +08002269 function subnetworkTypeFunc(data) {
2270 var result = getSubNetworkTypeTog(data.nRat, data.SubAct);
2271 return result;
2272 }
mj.qu11d28a82024-12-17 18:09:17 -08002273
qumengjiaca65ef52024-11-06 15:42:21 +08002274 function networkStatusFunc(data) {
2275 return $.i18n.prop(getNetworkStatusTog(data.nState));
2276 }
mj.qu11d28a82024-12-17 18:09:17 -08002277
qumengjiaca65ef52024-11-06 15:42:21 +08002278 function networkStatusIdFunc(data) {
2279 return getNetworkStatusTog(data.nState);
2280 }
mj.qu11d28a82024-12-17 18:09:17 -08002281
qumengjiaca65ef52024-11-06 15:42:21 +08002282 function networkTextFunc(data) {
2283 return data.strNumeric;
2284 }
2285
2286 }
2287
2288 //获取网络选择信息.
mj.qu11d28a82024-12-17 18:09:17 -08002289
qumengjiaca65ef52024-11-06 15:42:21 +08002290 function getNetSelectInfo() {
2291 return service.getNetSelectInfo();
2292 }
2293
2294 //搜网结果中的状态转换为对应的语言项.
mj.qu11d28a82024-12-17 18:09:17 -08002295
qumengjiaca65ef52024-11-06 15:42:21 +08002296 function getNetworkStatusTog(status) {
2297 if ("3" == status) {
2298 return "forbidden";
2299 } else if ("2" == status) {
2300 return "current";
2301 } else if ("1" == status) {
2302 return "available";
2303 }else if ("0" == status) {
2304 return "unknown";
2305 }
2306 }
2307 //子网络类型转换.
mj.qu11d28a82024-12-17 18:09:17 -08002308
qumengjiaca65ef52024-11-06 15:42:21 +08002309 function getSubNetworkTypeTog(type, subtype) {
2310 var type_3g = [2, 4, 5, 6, 8];
2311 if ("1" == subtype) {
2312 if ("7" == type) {
2313 subtype = "FDD-LTE";
2314 } else if ($.inArray(type, type_3g) != -1) {
2315 subtype = "WCDMA";
2316 }else {
2317 subtype = "GSM";
2318 }
2319 } else if ("0" == subtype) {
2320 if ("7" == type) {
2321 subtype = "TD-LTE";
2322 } else if ($.inArray(type, type_3g) != -1) {
2323 subtype = "TD-SCDMA";
2324 } else {
2325 subtype = "GSM";
2326 }
2327 } else {
2328 subtype = "";
2329 }
2330 return subtype;
2331 }
2332 //网络类型转换.
mj.qu11d28a82024-12-17 18:09:17 -08002333
qumengjiaca65ef52024-11-06 15:42:21 +08002334 function getNetworkType(type) {
2335 if ("7" == type) {
2336 return "4G";
2337 } else if ("2" == type) {
2338 return "3G";
2339 } else if ("0" == type) {
2340 return "2G";
2341 } else {
2342 return "auto";
2343 }
2344 }
2345
2346 function bindContainer(vm){
mj.qu11d28a82024-12-17 18:09:17 -08002347
qumengjiaca65ef52024-11-06 15:42:21 +08002348 var container = $('#container');
2349 ko.cleanNode(container[0]);
2350 ko.applyBindings(vm, container[0]);
2351 }
2352
2353 //初始化选网功能view model.
mj.qu11d28a82024-12-17 18:09:17 -08002354
qumengjiaca65ef52024-11-06 15:42:21 +08002355 function initialize() {
2356 var vm = new NetSelectVM();
2357 bindContainer(vm);
2358 addInterval(vm.checkEnable, 1000);
2359 }
2360
2361 return {
2362 init: initialize
2363 };
2364});
2365define("locknet","jquery knockout service jquery set main".split(" "),
2366 function ($, ko, service, config, home) {
2367
2368 function initialize() {
2369 var container = $('#container')[0];
2370 ko.cleanNode(container);
2371 var vm = new locknetViewMode();
2372 ko.applyBindings(vm, container);
2373
2374 $("#frmNetworkLock").validate({
2375 submitHandler: function () {
2376 vm.unlock();
2377 },
2378 rules: {
2379 txtLockNumber: "unlock_code_check"
2380 }
2381 });
2382 }
2383
2384 function locknetViewMode() {
2385 var target = this;
2386 var curCableMode = false;
2387 target.isCPE = config.PRODUCT_TYPE == 'CPE';
2388 target.hasRj45 = config.RJ45_SUPPORT;
2389 target.hasSms = config.HAS_SMS;
2390 target.hasPhonebook = config.HAS_PHONEBOOK;
2391 target.isSupportSD = config.SD_CARD_SUPPORT;
2392 if (config.WIFI_SUPPORT_QR_SWITCH == false) {
2393 target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
2394 } else {
2395 var wifiInfo = service.getWifiBasic();
2396 target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
2397 }
2398 if(config.WIFI_SUPPORT_QR_CODE){
2399 target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
2400 } else {
2401 target.qrcodeSrc = './pic/res_blacktrans.png';
2402 }
2403 target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
2404 target.deviceInfo = ko.observable([]);
2405 target.isHomePage = ko.observable(false);
2406 if (window.location.hash == "#main") {
2407 target.isHomePage(true);
2408 }
2409
2410 target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
2411 target.unlockCode = ko.observable();
2412
2413 var info = service.getNetworkUnlockTimes();
2414 target.times = ko.observable(info.unlock_nck_time);
2415
2416 //显示工作模式设置窗口
2417 target.showOpModeWindow = showOpModeWindowFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002418
qumengjiaca65ef52024-11-06 15:42:21 +08002419 target.isLoggedIn = ko.observable(false);
2420 target.enableFlag = ko.observable(false);
2421 //解锁
2422 target.unlock = unlockFunc;
2423
2424 //更新工作模式状态
2425 target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002426
qumengjiaca65ef52024-11-06 15:42:21 +08002427 //定时检查工作模式状态
2428 if (target.hasRj45) {
2429 target.refreshOpmodeInfo();
2430 addInterval(function () {
2431 target.refreshOpmodeInfo();
2432 }, 1000);
2433 }
mj.qu11d28a82024-12-17 18:09:17 -08002434
qumengjiaca65ef52024-11-06 15:42:21 +08002435 //更新工作模式状态
2436 function refreshOpmodeInfoFunc() {
2437 var obj = service.getStatusInfo();
2438 target.isLoggedIn(obj.isLoggedIn);
2439
2440 if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
2441 window.location.reload();
2442 return;
2443 }
2444
2445 curCableMode = checkCableMode(obj.blc_wan_mode);
2446 target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
2447 if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
2448 target.enableFlag(true);
2449 } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
2450 target.enableFlag(false);
2451 } else {
2452 target.enableFlag(true);
2453 }
2454 var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
2455 var currMode = "";
2456 switch (getMode) {
2457 case "PPP":
2458 currMode = "opmode_gateway";
2459 break;
2460 case "PPPOE":
2461 currMode = "opmode_cable";
2462 break;
2463 case "AUTO":
2464 currMode = "opmode_auto";
2465 break;
2466 default:
2467 break;
2468 }
2469 $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
2470 }
mj.qu11d28a82024-12-17 18:09:17 -08002471
qumengjiaca65ef52024-11-06 15:42:21 +08002472 //解锁
2473 function unlockFunc() {
2474 showLoading();
2475 service.unlockNetwork({
2476 unlock_network_code: target.unlockCode()
2477 }, function (data) {
2478 target.unlockCode("");
2479 if (data && data.result == "success") {
2480 successOverlay();
2481 if (window.location.hash == "#main") {
2482 setTimeout(function () {
2483 window.location.reload();
2484 }, 500);
2485 } else {
2486 window.location.hash = "#main";
2487 }
2488 } else {
2489 var info = service.getNetworkUnlockTimes();
2490 target.times(info.unlock_nck_time);
2491 errorOverlay();
2492 }
2493 })
2494 }
mj.qu11d28a82024-12-17 18:09:17 -08002495
qumengjiaca65ef52024-11-06 15:42:21 +08002496 //显示工作模式设置窗口
2497 function showOpModeWindowFunc() {
2498 showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
2499 }
2500 }
2501
2502 return {
2503 init: initialize
2504 };
2505});
2506
2507// RJ45联网设置模块
mj.qu11d28a82024-12-17 18:09:17 -08002508
qumengjiaca65ef52024-11-06 15:42:21 +08002509define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
2510function(_, $, ko, config, service) {
2511 var dialActions = _.map(config.dialActions, function(elem){
2512 return new Option(elem.name, elem.value);
2513 });
mj.qu11d28a82024-12-17 18:09:17 -08002514
qumengjiaca65ef52024-11-06 15:42:21 +08002515 var dialModes = _.map(config.pppoeModes, function(elem) {
2516 return new Option(elem.name, elem.value);
2517 });
mj.qu11d28a82024-12-17 18:09:17 -08002518
qumengjiaca65ef52024-11-06 15:42:21 +08002519 var checkStatusTimer = 0;
2520 var checkConCounter = 0;
2521 var timeoutTipShowed = false;
2522
2523 // 联网设置view model.
mj.qu11d28a82024-12-17 18:09:17 -08002524
qumengjiaca65ef52024-11-06 15:42:21 +08002525 function PPPoEViewModel() {
2526 var pppObj = service.getPppoeParams();
2527 var ethParams = pppObj;
2528 var target = this;
mj.qu11d28a82024-12-17 18:09:17 -08002529
qumengjiaca65ef52024-11-06 15:42:21 +08002530 target.staticNoticeShow = ko.observable();
2531 target.dhcpNoticeShow = ko.observable();
2532 target.pppoeNoticeShow = ko.observable();
2533 target.autoNoticeShow = ko.observable();
2534 target.staticNotice = ko.observable();
2535 target.dhcpNotice = ko.observable();
2536 target.pppoeNotice = ko.observable();
2537 target.autoNotice = ko.observable();
2538 target.dhcpNoticeText = ko.observable();
2539 target.staticNoticeText = ko.observable();
2540 target.pppoeNoticeText = ko.observable();
2541 target.autoNoticeText = ko.observable();
2542 target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
2543 target.showPassword = ko.observable(false);
2544 target.modes = ko.observableArray(dialModes);
2545 target.isPppoeMode = ko.observable(false);
2546 target.isStaticMode = ko.observable(false);
2547 target.isAutoMode = ko.observable(false);
2548 target.action = ko.observable();
2549 target.btnTrans = ko.observable();
2550 target.enableFlag = ko.observable();
2551 target.isShowDisbtn = ko.observable();
2552 target.isShowCancelbtn = ko.observable();
mj.qu11d28a82024-12-17 18:09:17 -08002553
qumengjiaca65ef52024-11-06 15:42:21 +08002554 if(pppObj.rj45_state == "dead"){
2555 checkRj45DeadTip();
2556 } else if(pppObj.rj45_state == "connect"){
2557 timeoutTipShowed = true;
2558 setRj45CheckTimer("connect");
2559 } else if(pppObj.rj45_state == "working"){
2560 setRj45WorkingTip();
2561 }
mj.qu11d28a82024-12-17 18:09:17 -08002562
qumengjiaca65ef52024-11-06 15:42:21 +08002563 target.user = ko.observable(pppObj.pppoe_username);
2564 target.password = ko.observable(pppObj.pppoe_cc);
2565 target.autoUser = ko.observable(pppObj.pppoe_username);
2566 target.autoPassword = ko.observable(pppObj.pppoe_cc);
2567 target.pppMode = ko.observable(pppObj.ethwan_dialmode);
2568 initContronler();
mj.qu11d28a82024-12-17 18:09:17 -08002569
qumengjiaca65ef52024-11-06 15:42:21 +08002570
2571 //下拉框选择改变下面DIV模块
2572 target.changeModeDiv = changeModeDivFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002573
qumengjiaca65ef52024-11-06 15:42:21 +08002574 target.radioHandler = radioHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002575
qumengjiaca65ef52024-11-06 15:42:21 +08002576 target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
2577 target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
2578 target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
2579 target.subnetMask = ko.observable(pppObj.static_wan_netmask);
2580 target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
mj.qu11d28a82024-12-17 18:09:17 -08002581
qumengjiaca65ef52024-11-06 15:42:21 +08002582 addInterval(function(){
2583 ethParams = service.getPppoeParams();
2584 pppObj.rj45_state = ethParams.rj45_state;
2585 initContronler();
2586 }, 1000);
mj.qu11d28a82024-12-17 18:09:17 -08002587
qumengjiaca65ef52024-11-06 15:42:21 +08002588 // 取消连接按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002589
qumengjiaca65ef52024-11-06 15:42:21 +08002590 target.cancelConnect = cancelConnectFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002591
qumengjiaca65ef52024-11-06 15:42:21 +08002592 // 应用按钮事件.
mj.qu11d28a82024-12-17 18:09:17 -08002593
qumengjiaca65ef52024-11-06 15:42:21 +08002594 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08002595
qumengjiaca65ef52024-11-06 15:42:21 +08002596 //密码显示事件
2597 target.showPasswordHandler = function () {
2598 var checkbox = $("#showPassword:checked");
2599 if (checkbox && checkbox.length == 0) {
2600 target.showPassword(true);
2601 } else {
2602 target.showPassword(false);
2603 }
2604 };
mj.qu11d28a82024-12-17 18:09:17 -08002605
qumengjiaca65ef52024-11-06 15:42:21 +08002606 // 更新当前界面状态、按钮、提示语等.
mj.qu11d28a82024-12-17 18:09:17 -08002607
qumengjiaca65ef52024-11-06 15:42:21 +08002608 function initContronler() {
2609 checkRj45DeadTip();
2610 if(target.currentMode() == "PPPOE"){
2611 target.isPppoeMode(true);
2612 target.isStaticMode(false);
2613 target.isAutoMode(false);
2614 target.staticNoticeShow(false);
2615 target.dhcpNoticeShow(false);
2616 target.autoNoticeShow(false);
2617 } else if(target.currentMode() == "AUTO"){
2618 target.isStaticMode(false);
2619 target.isPppoeMode(false);
2620 target.isAutoMode(true);
2621 target.dhcpNoticeShow(false);
2622 target.pppoeNoticeShow(false);
2623 target.staticNoticeShow(false);
2624 } else if(target.currentMode() == "STATIC"){
2625 target.isStaticMode(true);
2626 target.isPppoeMode(false);
2627 target.isAutoMode(false);
2628 target.dhcpNoticeShow(false);
2629 target.pppoeNoticeShow(false);
2630 target.autoNoticeShow(false);
2631 } else{
2632 target.isStaticMode(false);
2633 target.isPppoeMode(false);
2634 target.isAutoMode(false);
2635 target.staticNoticeShow(false);
2636 target.pppoeNoticeShow(false);
2637 target.autoNoticeShow(false);
2638 }
2639 if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
2640 target.enableFlag(false);
2641 } else {
2642 target.enableFlag(true);
2643 }
2644 if(pppObj.rj45_state == "connect"){
2645 if(target.pppMode() == "auto_dial"){
2646 target.action("connect");
2647 }else{
2648 target.action("disconnect");
2649 }
2650 } else if(pppObj.rj45_state == "working"){
2651 target.action("disconnect");
2652 }else{
2653 target.action("connect");
2654 }
2655 //应用/连接按钮
2656 if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
2657 target.btnTrans("connect");
2658 } else{
2659 target.btnTrans("apply");
2660 }
2661 if(pppObj.rj45_state != "idle"){
2662 $("#pppoeApply").attr("disabled", true);
2663 }else {
2664 $("#pppoeApply").attr("disabled", false);
2665 }
mj.qu11d28a82024-12-17 18:09:17 -08002666
qumengjiaca65ef52024-11-06 15:42:21 +08002667 //取消/断开按钮
2668 target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
2669 target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
mj.qu11d28a82024-12-17 18:09:17 -08002670
qumengjiaca65ef52024-11-06 15:42:21 +08002671 $("#pppoeApply").translate();
2672 }
2673 // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002674
qumengjiaca65ef52024-11-06 15:42:21 +08002675 function setRj45CheckTimer(action){
2676 checkStatusTimer && window.clearInterval(checkStatusTimer);
2677 if("connect" != action){
2678 checkStatusTimer = addInterval(function () {
2679 checkDisconnectStatus();
2680 }, 2000);
2681 }else{
2682 if(target.currentMode() == "PPPOE"){
2683 target.pppoeNoticeShow(true);
2684 target.pppoeNotice("pppoe_processing");
2685 target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
2686 } else if(target.currentMode() == "STATIC"){
2687 target.staticNoticeShow(true);
2688 target.staticNotice("static_processing");
2689 target.staticNoticeText($.i18n.prop("static_processing"));
2690 } else if(target.currentMode() == "DHCP"){
2691 target.dhcpNoticeShow(true);
2692 target.dhcpNotice("dyn_processing");
2693 target.dhcpNoticeText($.i18n.prop("dyn_processing"));
2694 }else{
2695 target.autoNoticeShow(true);
2696 target.autoNotice("auto_processing");
2697 target.autoNoticeText($.i18n.prop("auto_processing"));
2698 }
2699 checkStatusTimer = addInterval(function () {
2700 checkConnectionStatus();
2701 }, 2000);
2702 }
2703 }
2704 // 设置后通过定时检查rj45_state状态,判断连接操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002705
qumengjiaca65ef52024-11-06 15:42:21 +08002706 function checkConnectionStatus(){
2707 if(checkConCounter < 1){
2708 checkConCounter++;
2709 return;
2710 }
2711 if(pppObj.rj45_state == "connect"){
2712 if(target.currentMode() != ethParams.ethwan_mode){
2713 if(target.currentMode() == "AUTO"){
2714 target.autoNoticeShow(true);
2715 }else if(target.currentMode() == "PPPOE"){
2716 target.pppoeNoticeShow(true);
2717 }else if(target.currentMode() == "STATIC"){
2718 target.staticNoticeShow(true);
2719 }else if(target.currentMode() == "DHCP"){
2720 target.dhcpNoticeShow(true);
2721 }
2722 }
2723 if(checkConCounter > 6){
2724 if(timeoutTipShowed == false){
2725 timeoutTipShowed = true;
2726 showAlert("ussd_operation_timeout");
2727 }
2728 }
2729 checkConCounter++;
2730 } else if (pppObj.rj45_state == "working") {
2731 hideLoading();
2732 setRj45WorkingTip();
2733 window.clearInterval(checkStatusTimer);
2734 } else if (pppObj.rj45_state == "dead") {
2735 hideLoading();
2736 checkRj45DeadTip();
2737 window.clearInterval(checkStatusTimer);
2738 } else if(pppObj.rj45_state == "idle"){
2739 hideLoading();
2740 if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
2741 timeoutTipShowed == false && target.dhcpNoticeShow(true);
2742 target.dhcpNotice("dyn_fail");
2743 target.dhcpNoticeText($.i18n.prop("dyn_fail"));
2744 }
2745 if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
2746 timeoutTipShowed == false && target.staticNoticeShow(true);
2747 target.staticNotice("static_fail");
2748 target.staticNoticeText($.i18n.prop("static_fail"));
2749 }
2750 if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
2751 timeoutTipShowed == false && target.pppoeNoticeShow(true);
2752 target.pppoeNotice("pppoe_fail");
2753 target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
2754 }
2755 if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
2756 timeoutTipShowed == false && target.autoNoticeShow(true);
2757 target.autoNotice("auto_fail");
2758 target.autoNoticeText($.i18n.prop("auto_fail"));
2759 }
2760 window.clearInterval(checkStatusTimer);
2761 } else{
2762 hideLoading();
2763 window.clearInterval(checkStatusTimer);
2764 }
2765 }
2766 // 设置连接成功时提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002767
qumengjiaca65ef52024-11-06 15:42:21 +08002768 function setRj45WorkingTip(){
2769 if(target.currentMode() == ethParams.ethwan_mode){
2770 if(target.currentMode() == "AUTO") {
2771 target.autoNoticeShow(true);
2772 target.autoNotice("auto_success");
2773 target.autoNoticeText($.i18n.prop("auto_success"));
2774 }else if(target.currentMode() == "PPPOE") {
2775 target.pppoeNoticeShow(true);
2776 target.pppoeNotice("pppoe_success");
2777 target.pppoeNoticeText($.i18n.prop("pppoe_success"));
2778 }else if(target.currentMode() == "STATIC") {
2779 target.staticNoticeShow(true);
2780 target.staticNotice("static_success");
2781 target.staticNoticeText($.i18n.prop("static_success"));
2782 }else if(target.currentMode() == "DHCP" ) {
2783 target.dhcpNoticeShow(true);
2784 target.dhcpNotice("dyn_success");
2785 target.dhcpNoticeText($.i18n.prop("dyn_success"));
2786 }
2787 }
2788 }
mj.qu11d28a82024-12-17 18:09:17 -08002789
qumengjiaca65ef52024-11-06 15:42:21 +08002790 // 设置网线断开提示语状态.
mj.qu11d28a82024-12-17 18:09:17 -08002791
qumengjiaca65ef52024-11-06 15:42:21 +08002792 function checkRj45DeadTip(){
2793 if(pppObj.rj45_state != "dead"){
2794 if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
2795 target.autoNoticeShow(false);
2796 }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
2797 target.pppoeNoticeShow(false);
2798 }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
2799 target.staticNoticeShow(false);
2800 }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
2801 target.dhcpNoticeShow(false);
2802 }
mj.qu11d28a82024-12-17 18:09:17 -08002803
qumengjiaca65ef52024-11-06 15:42:21 +08002804 } else{
2805 target.dhcpNotice("pppoe_msg");
2806 target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
2807 target.staticNotice("pppoe_msg");
2808 target.staticNoticeText($.i18n.prop("pppoe_msg"));
2809 target.pppoeNotice("pppoe_msg");
2810 target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
2811 target.autoNotice("pppoe_msg");
2812 target.autoNoticeText($.i18n.prop("pppoe_msg"));
2813 if(target.currentMode() == "AUTO") {
2814 target.autoNoticeShow(true);
2815 }else if(target.currentMode() == "PPPOE") {
2816 target.pppoeNoticeShow(true);
2817 }else if(target.currentMode() == "STATIC") {
2818 target.staticNoticeShow(true);
2819 }else if(target.currentMode() == "DHCP") {
2820 target.dhcpNoticeShow(true);
2821 }
2822 }
2823 }
2824 // 设置后通过定时检查rj45_state状态,判断断开操作结果.
mj.qu11d28a82024-12-17 18:09:17 -08002825
qumengjiaca65ef52024-11-06 15:42:21 +08002826 function checkDisconnectStatus(){
2827 if(checkConCounter < 1){
2828 checkConCounter++;
2829 } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
2830 target.dhcpNoticeShow(false);
2831 target.staticNoticeShow(false);
2832 target.pppoeNoticeShow(false);
2833 target.autoNoticeShow(false);
2834 window.clearInterval(checkStatusTimer);
2835 successOverlay();
2836 } else if(checkConCounter > 6){
2837 if(timeoutTipShowed == false){
2838 timeoutTipShowed = true;
2839 showAlert("ussd_operation_timeout");
2840 }
2841 window.clearInterval(checkStatusTimer);
2842 } else if(checkConCounter < 7) {
2843 checkConCounter++;
2844 } else {
2845 hideLoading();
2846 window.clearInterval(checkStatusTimer);
2847 }
2848 }
mj.qu11d28a82024-12-17 18:09:17 -08002849
qumengjiaca65ef52024-11-06 15:42:21 +08002850 //应用按钮事件.
2851 function saveFunc(){
2852 target.dhcpNoticeShow(false);
2853 target.staticNoticeShow(false);
2854 target.pppoeNoticeShow(false);
2855 target.autoNoticeShow(false);
2856 if(pppObj.rj45_state == "dead"){
2857 showAlert("pppoe_msg");
2858 return;
2859 }
2860 var requestParams = {};
2861 if($("#pppoe_mode").val() == "PPPOE") {
2862 requestParams = $.extend({}, {
2863 goformId: "WAN_GATEWAYMODE_PPPOE",
2864 pppoe_username: target.user(),
2865 pppoe_cc: target.password()
2866 });
2867 } else if($("#pppoe_mode").val() == "AUTO") {
2868 requestParams = $.extend({}, {
2869 goformId: "WAN_GATEWAYMODE_AUTO",
2870 pppoe_username: target.autoUser(),
2871 pppoe_cc: target.autoPassword()
2872 });
2873 } else if($("#pppoe_mode").val() == "STATIC") {
2874 if(target.ipAddress() == target.defaultGateway()){
2875 showAlert("ip_gate_not_same");
2876 return;
2877 }
2878 if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
2879 showAlert("ip_innergate_not_same");
2880 return;
2881 }
2882 requestParams = $.extend({}, {
2883 goformId: "WAN_GATEWAYMODE_STATIC",
2884 static_wan_ipaddr: target.ipAddress(),
2885 static_wan_netmask: target.subnetMask(),
2886 static_wan_gateway: target.defaultGateway(),
2887 static_wan_primary_dns: target.primaryDNS(),
2888 static_wan_secondary_dns: target.secondaryDNS(),
2889 WAN_MODE: "STATIC"
2890 });
2891 } else {
2892 requestParams = $.extend({}, {
2893 goformId: "WAN_GATEWAYMODE_DHCP"
2894 });
2895 }
2896 requestParams.action_link = "connect";
2897 requestParams.dial_mode = target.pppMode();
2898 showLoading("waiting");
mj.qu11d28a82024-12-17 18:09:17 -08002899
qumengjiaca65ef52024-11-06 15:42:21 +08002900 service.setPppoeDialMode(requestParams, function(data){
2901 if(data.result){
2902 target.currentMode($("#pppoe_mode").val());
2903 pppObj = service.getPppoeParams();
2904 checkConCounter = 0;
2905 timeoutTipShowed = false;
2906 setRj45CheckTimer("connect");
2907 $("#pppoeApply").translate();
2908 } else {
2909 errorOverlay("pppoe_message_send_fail");
2910 }
2911 });
mj.qu11d28a82024-12-17 18:09:17 -08002912
qumengjiaca65ef52024-11-06 15:42:21 +08002913 }
mj.qu11d28a82024-12-17 18:09:17 -08002914
qumengjiaca65ef52024-11-06 15:42:21 +08002915 //取消连接按钮事件.
2916 function cancelConnectFunc(){
2917 target.dhcpNoticeShow(false);
2918 target.staticNoticeShow(false);
2919 target.pppoeNoticeShow(false);
2920 target.autoNoticeShow(false);
2921 if(pppObj.rj45_state == "dead"){
2922 showAlert("pppoe_msg");
2923 return;
2924 }
2925 var requestParams = {
2926 dial_mode: target.pppMode(),
2927 action_link: "disconnect"
2928 };
2929 if(pppObj.ethwan_mode == "PPPOE") {
2930 requestParams = $.extend(requestParams, {
2931 goformId: "WAN_GATEWAYMODE_PPPOE",
2932 pppoe_username: pppObj.pppoe_username,
2933 pppoe_cc: pppObj.pppoe_cc
2934 });
2935 }else if(pppObj.ethwan_mode == "AUTO") {
2936 requestParams = $.extend(requestParams, {
2937 goformId: "WAN_GATEWAYMODE_AUTO",
2938 pppoe_username: pppObj.pppoe_username,
2939 pppoe_cc: pppObj.pppoe_cc
2940 });
2941 }else if(pppObj.ethwan_mode == "STATIC") {
2942 requestParams = $.extend(requestParams, {
2943 goformId: "WAN_GATEWAYMODE_STATIC",
2944 static_wan_ipaddr: pppObj.static_wan_ipaddr,
2945 static_wan_netmask: pppObj.static_wan_netmask,
2946 static_wan_gateway: pppObj.static_wan_gateway,
2947 static_wan_primary_dns: pppObj.static_wan_primary_dns,
2948 static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
2949 WAN_MODE: "STATIC"
2950 });
2951 }else {
2952 requestParams = $.extend(requestParams, {
2953 goformId: "WAN_GATEWAYMODE_DHCP"
2954 });
2955 }
2956 showLoading("waiting");
2957 service.setPppoeDialMode(requestParams, function(data){
2958 if(data.result){
2959 checkConCounter = 0;
2960 timeoutTipShowed = false;
2961 setRj45CheckTimer("disconnect");
2962 $("#pppoeApply").translate();
2963 } else {
2964 errorOverlay("pppoe_message_send_fail");
2965 }
2966 });
mj.qu11d28a82024-12-17 18:09:17 -08002967
qumengjiaca65ef52024-11-06 15:42:21 +08002968 }
mj.qu11d28a82024-12-17 18:09:17 -08002969
qumengjiaca65ef52024-11-06 15:42:21 +08002970 function radioHandlerFunc(){
2971 initContronler();
2972 return true;
2973 }
mj.qu11d28a82024-12-17 18:09:17 -08002974
qumengjiaca65ef52024-11-06 15:42:21 +08002975 function changeModeDivFunc(){
2976 initContronler();
2977 }
mj.qu11d28a82024-12-17 18:09:17 -08002978
qumengjiaca65ef52024-11-06 15:42:21 +08002979 }
2980
2981 function bindContainer(vm){
2982 var container = $('#container');
2983 ko.cleanNode(container[0]);
2984 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08002985
qumengjiaca65ef52024-11-06 15:42:21 +08002986 }
2987 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08002988
qumengjiaca65ef52024-11-06 15:42:21 +08002989 function initialize() {
2990 var vm = new PPPoEViewModel();
2991 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08002992
qumengjiaca65ef52024-11-06 15:42:21 +08002993 $("#pppoeApply").translate();
mj.qu11d28a82024-12-17 18:09:17 -08002994
qumengjiaca65ef52024-11-06 15:42:21 +08002995 $('#pppoeForm').validate({
2996 submitHandler : function() {
2997 vm.save();
2998 },
2999 rules: {
3000 txtPin: "wps_pin_check",
3001 txtIpAddress: "dmz_ip_check",
3002 txtSubnetMask: {
3003 ipv4: true,
3004 subnetmask_check: true
3005 },
3006 txtDefaultGateway: {
3007 ipv4: true,
3008 gateway_check: true
3009 },
3010 txtPrimaryDNS: {
3011 ipv4: true,
3012 dns_check:true
3013 },
3014 txtSecondaryDNS: {
3015 ipv4: true,
3016 dns_check:true
3017 }
3018 }
3019 });
3020 }
mj.qu11d28a82024-12-17 18:09:17 -08003021
3022
qumengjiaca65ef52024-11-06 15:42:21 +08003023//from 4.0
3024 // 有效DNS检查.
mj.qu11d28a82024-12-17 18:09:17 -08003025
qumengjiaca65ef52024-11-06 15:42:21 +08003026function validateDns(dns){
3027 if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
3028 return false;
3029 }
3030 return true;
3031}
3032 // 联网设置初始化.
mj.qu11d28a82024-12-17 18:09:17 -08003033
qumengjiaca65ef52024-11-06 15:42:21 +08003034function isStaticIPValid(ip, lanip, lanmask){
3035 if(!ip || !lanip || !lanmask){//各参数不能为空
3036 return false;
3037 }
3038 if(ip == lanip){// 与内网IP相等
3039 return true;
3040 }
3041 var res1 = [], res2 = [], mask = [];
3042 addr1 = ip.split(".");
3043 addr2 = lanip.split(".");
3044 mask = lanmask.split(".");
3045 for(var i = 0; i < addr1.length; i += 1){
3046 res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
3047 res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
3048 }
3049 if(res1.join(".") == res2.join(".")){//在同一个网段
3050 return true;
3051 }else{//不在同一个网段
3052 return false;
3053 }
3054}
3055
3056// 有效子网掩码验证.
mj.qu11d28a82024-12-17 18:09:17 -08003057
qumengjiaca65ef52024-11-06 15:42:21 +08003058function isNetmaskIPValid(ip) {
3059 if (ip == 255 || ip == 254 || ip == 252 || ip == 248
3060 || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
3061 {
3062 return true;
3063 }
3064 else
3065 {
3066 return false;
3067 }
3068}
3069 // 有效子网掩码检查.
mj.qu11d28a82024-12-17 18:09:17 -08003070
qumengjiaca65ef52024-11-06 15:42:21 +08003071function validateNetmask(netmask) {
3072 var array = new Array();
3073 array = netmask.split(".");
3074
3075 if (array.length != 4) {
3076 return false;
3077 }
3078
3079 array[0] = parseInt(array[0]);
3080 array[1] = parseInt(array[1]);
3081 array[2] = parseInt(array[2]);
3082 array[3] = parseInt(array[3]);
3083
3084 if (array[3] != 0) {
3085 if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
3086 return false;
3087 } else {
3088 if (!isNetmaskIPValid(array[3])) {
3089 return false;
3090 }
3091 }
3092 }
3093
3094 if (array[2] != 0) {
3095 if (array[1] != 255 || array[0] != 255) {
3096 return false;
3097 } else {
3098 if (!isNetmaskIPValid(array[2])) {
3099 return false;
3100 }
3101 }
3102 }
3103
3104 if (array[1] != 0) {
3105 if (array[0] != 255) {
3106 return false;
3107 } else{
3108 if (!isNetmaskIPValid(array[1])) {
3109 return false;
3110 }
3111 }
3112 }
3113 if(array[0]!=255) {
3114 return false;
3115 }
3116 if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
3117 return false;
3118 }
3119 return true;
3120}
mj.qu11d28a82024-12-17 18:09:17 -08003121
qumengjiaca65ef52024-11-06 15:42:21 +08003122 // subnetmask_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003123
qumengjiaca65ef52024-11-06 15:42:21 +08003124jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
3125 var result = validateNetmask(value);
3126 return this.optional(element) || result;
3127});
3128 // dns_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003129
qumengjiaca65ef52024-11-06 15:42:21 +08003130jQuery.validator.addMethod("dns_check", function (value, element, param) {
3131 var result = validateDns(value);
3132 return this.optional(element) || result;
3133});
3134 // 有效网关检查.
mj.qu11d28a82024-12-17 18:09:17 -08003135
qumengjiaca65ef52024-11-06 15:42:21 +08003136function validateGateway(wanIp, netmaskIp, gatewayIp) {
3137 if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
3138 return true;
3139 } else {
3140 return false;
3141 }
3142}
3143 // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
mj.qu11d28a82024-12-17 18:09:17 -08003144
qumengjiaca65ef52024-11-06 15:42:21 +08003145function myConcat(ip1,ip2){
3146 var result = [];
3147 var iplArr = ip1.split(".");
3148 var ip2Arr = ip2.split(".");
3149 for(var i = 0; i < iplArr.length;i++){
3150 result[i] = (iplArr[i] & ip2Arr[i]);
3151 }
3152 return result.join(".");
3153}
3154 // gateway_check校验规则
mj.qu11d28a82024-12-17 18:09:17 -08003155
qumengjiaca65ef52024-11-06 15:42:21 +08003156jQuery.validator.addMethod("gateway_check", function (value, element, param) {
3157 var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
3158 return this.optional(element) || result;
3159});
mj.qu11d28a82024-12-17 18:09:17 -08003160
qumengjiaca65ef52024-11-06 15:42:21 +08003161 return {
3162 init: initialize
3163 };
3164});
3165//联网设置模块
3166define("network_dial_set","underscore jquery knockout set service".split(" "),
3167function(_, $, ko, config, service) {
3168
3169 //联网设置view model
3170 function DialVM() {
3171 var dialMode = service.getConnectionMode();
3172 var target = this;
3173
3174 target.selectMode = ko.observable(dialMode.connectionMode);
3175 target.enableFlag = ko.observable(true);
3176 target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
3177 var originalRoaming = dialMode.isAllowedRoaming;
3178
3179 target.setAllowedRoaming = setAllowedRoamingFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003180
qumengjiaca65ef52024-11-06 15:42:21 +08003181 var checkboxFlag = $(".checkboxToggle");
3182 target.checkEnable = checkEnableFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003183
qumengjiaca65ef52024-11-06 15:42:21 +08003184 //修改联网模式
3185 target.save = saveFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003186
qumengjiaca65ef52024-11-06 15:42:21 +08003187 function saveFunc() {
3188 showLoading();
3189 var connMode = target.selectMode();
3190 //当选择自动时,下发原先的勾选状态
3191 if (connMode == 'auto_dial') {
3192 originalRoaming = target.isAllowedRoaming();
3193 } else {
3194 target.isAllowedRoaming(originalRoaming);
3195 }
3196 service.setConnectionMode({
3197 connectionMode: connMode,
3198 isAllowedRoaming: target.isAllowedRoaming()
3199 }, function (result) {
3200 if (result.result == "success") {
3201 successOverlay();
3202 } else {
3203 errorOverlay();
3204 }
3205 });
3206 }
mj.qu11d28a82024-12-17 18:09:17 -08003207
qumengjiaca65ef52024-11-06 15:42:21 +08003208 function setAllowedRoamingFunc() {
3209 if(!$("#roamBtn").hasClass("disable")){
3210 var checkbox = $("#isAllowedRoaming:checked");
3211 if(checkbox && checkbox.length == 0 ){
3212 target.isAllowedRoaming("on");
3213 }else{
3214 target.isAllowedRoaming("off");
3215 }
3216 }
3217 }
mj.qu11d28a82024-12-17 18:09:17 -08003218
qumengjiaca65ef52024-11-06 15:42:21 +08003219 function checkEnableFunc() {
3220 var status = service.getStatusInfo();
3221
3222 if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
3223 target.enableFlag(false);
3224 disableCheckbox(checkboxFlag);
3225 }
3226 else {
3227 target.enableFlag(true);
3228 enableCheckbox(checkboxFlag);
3229 }
3230 }
3231
3232 }
3233
3234 //联网设置初始化.
3235 function initialize() {
3236 var vm = new DialVM();
3237 bindContainer(vm);
mj.qu11d28a82024-12-17 18:09:17 -08003238
qumengjiaca65ef52024-11-06 15:42:21 +08003239 vm.checkEnable();
3240 addInterval( vm.checkEnable, 1000);
3241 }
mj.qu11d28a82024-12-17 18:09:17 -08003242
qumengjiaca65ef52024-11-06 15:42:21 +08003243 function bindContainer(vm){
3244 var container = $('#container');
3245 ko.cleanNode(container[0]);
3246 ko.applyBindings(vm, container[0]);
mj.qu11d28a82024-12-17 18:09:17 -08003247
qumengjiaca65ef52024-11-06 15:42:21 +08003248 }
mj.qu11d28a82024-12-17 18:09:17 -08003249
qumengjiaca65ef52024-11-06 15:42:21 +08003250 return {
3251 init: initialize
3252 };
3253});
3254// APN Setting 模块
3255define("network_apn_set","underscore jquery knockout set service".split(" "),
3256 function (_, $, ko, config, service) {
3257
3258 //获取鉴权方式
mj.qu11d28a82024-12-17 18:09:17 -08003259
qumengjiaca65ef52024-11-06 15:42:21 +08003260 function getAuthModes() {
3261 return _.map(config.APN_AUTH_MODES, function (item) {
3262 return new Option(item.name, item.value);
3263 });
3264 }
3265
3266 function getApnPdpTypes() {
3267 var pdpTypesArray = [new Option('IPv4', 'IP')];
3268 if (config.IPV6_SUPPORT) {
3269 pdpTypesArray.push(new Option('IPv6', 'IPv6'));
3270 if (config.IPV4V6_SUPPORT) {
3271 pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
3272 }
3273 if (config.IPV4_AND_V6_SUPPORT) {
3274 pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
3275 }
3276 }
3277 return pdpTypesArray;
3278 }
3279
3280 //获取apn相关信息
mj.qu11d28a82024-12-17 18:09:17 -08003281
qumengjiaca65ef52024-11-06 15:42:21 +08003282 function getApnSet() {
3283 var apnInfo = service.getApnSettings();
3284 apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
3285 apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
3286 apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
3287 return apnInfo;
3288 }
3289 var apnConfigs = {};
3290 var ipv6ApnConfigs = {};
3291 var autoApnConfigs = {};
3292
3293 //解析自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003294
qumengjiaca65ef52024-11-06 15:42:21 +08003295 function getAutoApnsConfig(autoApnV4, autoApnV6) {
3296 var autoApnsV4 = [];
3297 var autoApnsV6 = [];
3298
3299 if (autoApnV4 && autoApnV4.length > 5) {
3300 var apnArr = autoApnV4.split("||");
3301 for (var ki = 0; ki < apnArr.length; ki++) {
3302 if (apnArr[ki] != "") {
3303 var apnItem = parseApnItem(apnArr[ki], false);
3304 autoApnsV4.push(apnItem);
3305 }
3306 }
3307 }
3308 if (autoApnV6 && autoApnV6.length > 5) {
3309 var apnArr = autoApnV6.split("||");
3310 for (var ki = 0; ki < apnArr.length; ki++) {
3311 if (apnArr[ki] != "") {
3312 var apnItem = parseApnItem(apnArr[ki], false);
3313 autoApnsV6.push(apnItem);
3314 }
3315 }
3316 }
3317 return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
3318 }
3319 //解析apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003320
qumengjiaca65ef52024-11-06 15:42:21 +08003321 function getApnConfigs(apnsStr, isIpv6) {
3322 var apnCfgs = [];
3323 var theApnConfigs = {};
3324 if (apnsStr && apnsStr.length > 10) {
3325 var apnArr = apnsStr.split("||");
3326 for (var ki = 0; ki < apnArr.length; ki++) {
3327 if (apnArr[ki] != "") {
3328 var apnItem = parseApnItem(apnArr[ki], isIpv6);
3329 apnCfgs.push(apnItem);
3330 theApnConfigs[apnItem.profileName] = apnItem;
3331 }
3332 }
3333 }
3334 if (isIpv6 == false) {
3335 apnConfigs = theApnConfigs;
3336 } else {
3337 ipv6ApnConfigs = theApnConfigs;
3338 }
3339 return apnCfgs;
3340 }
3341
3342 //解析单条apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003343
qumengjiaca65ef52024-11-06 15:42:21 +08003344 function parseApnItem(apnStr, isIpv6) {
3345 var apnItem = {};
3346 var items = apnStr.split("($)");
3347 for (var ki = 0; ki < items.length; ki++) {
3348 apnItem.profileName = items[0];
3349 apnItem.pdpType = items[7];
3350 if (isIpv6 == false) {
3351 apnItem.dnsMode = items[10];
3352 apnItem.dns1 = items[11];
3353 apnItem.dns2 = items[12];
3354 apnItem.wanApn = items[1];
3355 apnItem.authMode = items[4].toLowerCase();
3356 apnItem.username = items[5];
3357 apnItem.password = items[6];
3358 } else {
3359 apnItem.dnsModeV6 = items[10];
3360 apnItem.dns1V6 = items[11];
3361 apnItem.dns2V6 = items[12];
3362 apnItem.wanApnV6 = items[1];
3363 apnItem.authModeV6 = items[4].toLowerCase();
3364 apnItem.usernameV6 = items[5];
3365 apnItem.passwordV6 = items[6];
3366 }
3367 }
3368 return apnItem;
3369 }
3370 //合并V4\V6自动apn信息
mj.qu11d28a82024-12-17 18:09:17 -08003371
qumengjiaca65ef52024-11-06 15:42:21 +08003372 function dealAutoApnsV4V6(v4, v6) {
3373 autoApnConfigs = {};
3374 var autoApns = [];
3375 for (var ki = 0; ki < v4.length; ki++) {
3376 var apnElem = v4[ki];
3377 var itemsV6 = v6[ki];
3378 if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
3379 apnElem.usernameV6 = itemsV6.username;
3380 apnElem.passwordV6 = itemsV6.password;
3381 apnElem.dns1V6 = itemsV6.dns1;
3382 apnElem.dns2V6 = itemsV6.dns2;
3383 apnElem.wanApnV6 = itemsV6.wanApn;
3384 apnElem.authModeV6 = itemsV6.authMode;
3385 apnElem.dnsModeV6 = itemsV6.dnsMode;
3386 }
3387 autoApns.push(apnElem);
3388 autoApnConfigs[apnElem.profileName] = apnElem;
3389 }
3390 return autoApns;
3391 }
3392
3393 function getProfileOptions(apns) {
3394 return _.map(apns, function (item) {
3395 return new Option(item.profileName, item.profileName);
3396 });
3397 }
3398
3399 //APNViewModel
mj.qu11d28a82024-12-17 18:09:17 -08003400
qumengjiaca65ef52024-11-06 15:42:21 +08003401 function APNViewModel() {
3402 var target = this;
3403 var apnSettings = getApnSet();
3404 if (apnSettings.apnNumPreset) {
3405 config.maxApnNumber = apnSettings.apnNumPreset;
3406 }
3407
3408 target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
3409 target.apnMode = ko.observable(apnSettings.apnMode);
3410 target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
3411 target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
3412 target.wanDial = ko.observable(apnSettings.wanDial);
mj.qu11d28a82024-12-17 18:09:17 -08003413
qumengjiaca65ef52024-11-06 15:42:21 +08003414 target.showApnDns = ko.observable(config.SHOW_APN_DNS);
3415 target.index = ko.observable(apnSettings.currIndex);
3416 target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
3417 target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
3418
3419 target.apn = ko.observable(apnSettings.wanApn);
3420 target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
3421 target.dns1 = ko.observable(apnSettings.dns1);
3422 target.dns2 = ko.observable(apnSettings.dns2);
3423 target.authModes = ko.observableArray(getAuthModes());
3424 target.username = ko.observable(apnSettings.username);
3425 target.password = ko.observable(apnSettings.password);
mj.qu11d28a82024-12-17 18:09:17 -08003426
qumengjiaca65ef52024-11-06 15:42:21 +08003427 target.pdpTypes = ko.observableArray(getApnPdpTypes());
3428 target.selectedPdpType = ko.observable(apnSettings.pdpType);
3429 target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
3430 target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
3431 target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
3432
3433 target.showPassword = ko.observable(false);
3434
3435 target.apnV6 = ko.observable(apnSettings.wanApnV6);
3436 target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
3437 target.dns1V6 = ko.observable(apnSettings.dns1V6);
3438 target.dns2V6 = ko.observable(apnSettings.dns2V6);
3439 target.authModesV6 = ko.observableArray(getAuthModes());
3440 target.usernameV6 = ko.observable(apnSettings.usernameV6);
3441 target.passwordV6 = ko.observable(apnSettings.passwordV6);
3442 target.pdpTypeNote = ko.observable(true);
3443 if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
3444 target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
3445 } else {
3446 target.selectedAutoProfile = ko.observable();
3447 }
3448
3449 if (config.EMPTY_APN_SUPPORT == false) {
3450 $("#apn_ipv4_apn").addClass("required");
3451 $("#apn_ipv6_apn").addClass("required");
3452 } else {
3453 $("#apn_ipv4_apn").removeClass("required");
3454 $("#apn_ipv6_apn").removeClass("required");
3455 }
mj.qu11d28a82024-12-17 18:09:17 -08003456
qumengjiaca65ef52024-11-06 15:42:21 +08003457 target.disableProfile = ko.observable(false); //表示处于新增页面
3458 target.addApnHide = ko.observable(true);
3459 target.defaultCfg = ko.observable(true); //当前选中的是默认APN
3460 target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
mj.qu11d28a82024-12-17 18:09:17 -08003461
qumengjiaca65ef52024-11-06 15:42:21 +08003462 target.selectedAuthentication = ko.observable(apnSettings.authMode);
3463 target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
3464
3465
3466 target.transApnV6 = ko.observable('apn');
3467 target.transDnsModeV6 = ko.observable('apn_dns_mode');
3468 target.transDns1V6 = ko.observable('apn_dns1');
3469 target.transDns2V6 = ko.observable('apn_dns2');
3470 target.transAuthV6 = ko.observable('apn_authentication');
3471 target.transUserNameV6 = ko.observable('apn_user_name');
3472 target.transPasswordV6 = ko.observable('apn_password');
mj.qu11d28a82024-12-17 18:09:17 -08003473
qumengjiaca65ef52024-11-06 15:42:21 +08003474 target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
3475 target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
3476 target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
3477 target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
3478 target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
3479 target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
3480 target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
3481
3482 target.setDefaultVisible = ko.observable(!isConnectedNetWork());
3483
3484 target.tmp1 = ko.computed(function () {
3485 if (target.selectedPdpType() == "IPv6") {
3486 target.transApnV6('apn');
3487 target.transDnsModeV6('apn_dns_mode');
3488 target.transDns1V6('apn_dns1');
3489 target.transDns2V6('apn_dns2');
3490 target.transAuthV6('apn_authentication');
3491 target.transUserNameV6('apn_user_name');
3492 target.transPasswordV6('apn_password');
3493 } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3494 target.transApn('apn_ipv4_apn');
3495 target.transDnsMode('apn_dns_mode_ipv4');
3496 target.transDns1('apn_dns1_ipv4');
3497 target.transDns2('apn_dns2_ipv4');
3498 target.transAuth('apn_authentication_ipv4');
3499 target.transUserName('apn_user_name_ipv4');
3500 target.transPassword('apn_password_ipv4');
3501
3502 target.transApnV6('apn_ipv6_apn');
3503 target.transDnsModeV6('apn_dns_mode_ipv6');
3504 target.transDns1V6('apn_dns1_ipv6');
3505 target.transDns2V6('apn_dns2_ipv6');
3506 target.transAuthV6('apn_authentication_ipv6');
3507 target.transUserNameV6('apn_user_name_ipv6');
3508 target.transPasswordV6('apn_password_ipv6');
3509 } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
3510 target.transApn('apn');
3511 target.transDnsMode('apn_dns_mode');
3512 target.transDns1('apn_dns1');
3513 target.transDns2('apn_dns2');
3514 target.transAuth('apn_authentication');
3515 target.transUserName('apn_user_name');
3516 target.transPassword('apn_password');
3517 } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
3518 target.transApn('apn');
3519 target.transDnsMode('apn_dns_mode');
3520 target.transDns1('apn_dns1');
3521 target.transDns2('apn_dns2');
3522 target.transAuth('apn_authentication');
3523 target.transUserName('apn_user_name');
3524 target.transPassword('apn_password');
3525 }
3526 $("#apn_setting_form").translate();
3527 });
3528
3529 target.autoApnChecked = ko.computed(function () {
3530 return target.apnMode() == "auto";
3531 });
mj.qu11d28a82024-12-17 18:09:17 -08003532
qumengjiaca65ef52024-11-06 15:42:21 +08003533 target.hasCapacity = ko.computed(function () {
3534 if (target.profiles().length < config.maxApnNumber) {
3535 return true;
3536 } else {
3537 return false;
3538 }
3539 });
3540
3541 target.showDnsV6 = ko.computed(function () {
3542 return target.dnsModeV6() == "manual";
3543 });
mj.qu11d28a82024-12-17 18:09:17 -08003544
qumengjiaca65ef52024-11-06 15:42:21 +08003545 target.showDns = ko.computed(function () {
3546 return target.dnsMode() == "manual";
3547 });
3548
3549
3550 checkDefaultProfileStatus();
3551 target.checkInputDisable = ko.computed(function () {
3552 if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
3553 return false;
3554 }
3555 if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
3556 return true;
3557 }
3558 if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
3559 return false;
3560 }
3561 return false;
3562 });
3563
3564 var data = service.getDeviceInfo();
3565 target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003566
qumengjiaca65ef52024-11-06 15:42:21 +08003567
3568 target.showAutoApnDetail = ko.computed(function () {
3569 if (target.apnMode() != "auto") {
3570 return true;
3571 } else {
3572 return target.autoProfiles().length > 0;
3573 }
3574 });
3575 //密码显示事件
3576 target.showPasswordHandler = function () {
3577 var checkbox = $("#showPassword:checked");
3578 if (checkbox && checkbox.length == 0) {
3579 target.showPassword(true);
3580 } else {
3581 target.showPassword(false);
3582 }
3583 };
3584 //auto apn profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003585
qumengjiaca65ef52024-11-06 15:42:21 +08003586 target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003587
3588
qumengjiaca65ef52024-11-06 15:42:21 +08003589 //profile change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003590
qumengjiaca65ef52024-11-06 15:42:21 +08003591 target.profileChangeHandler = profileChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003592
3593
qumengjiaca65ef52024-11-06 15:42:21 +08003594 //切换profile时重置下面的显示项
3595 target.setUIData = setUIDataFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003596
qumengjiaca65ef52024-11-06 15:42:21 +08003597
3598 //设置默认apn状态
mj.qu11d28a82024-12-17 18:09:17 -08003599
qumengjiaca65ef52024-11-06 15:42:21 +08003600 function checkDefaultProfileStatus() {
3601 var index = getApnIndex();
3602 //默认apn不允许编辑
3603 if (target.apnMode() != "auto") { //当前选中与实际不一致的话
3604 if (target.selectedProfile() != target.defApn()) {
3605 target.defaultCfg(false);
3606 } else {
3607 target.defaultCfg(true); //默认APN
3608 }
3609 } else {
3610 if (target.selectedAutoProfile() != target.defApn()) {
3611 target.defaultCfg(false);
3612 } else {
3613 target.defaultCfg(true); //默认APN
3614 }
3615 }
3616
3617 if (index >= config.defaultApnSize) {
3618 target.predeterminedCfg(false);
3619 } else {
3620 target.predeterminedCfg(true); //预置APN
3621 }
3622 }
3623
3624
3625 //设置为默认apn
qumengjiaca65ef52024-11-06 15:42:21 +08003626
mj.qu11d28a82024-12-17 18:09:17 -08003627 target.setDefaultAct = setDefaultActFunc;
3628
3629
3630
qumengjiaca65ef52024-11-06 15:42:21 +08003631 //APN mode change 事件处理
mj.qu11d28a82024-12-17 18:09:17 -08003632
qumengjiaca65ef52024-11-06 15:42:21 +08003633 target.apnModeChangeHandler = apnModeChangeHandlerFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003634
3635
qumengjiaca65ef52024-11-06 15:42:21 +08003636 function doSetDefaultAct() {
3637 var index = 0;
3638 if (target.apnMode() != 'auto') {
3639 index = getApnIndex();
3640 target.selectedProfile($("#profile").val());
3641 } else {
3642 index = getAutoApnIndex();
3643 target.selectedAutoProfile($("#autoProfile").val());
3644 }
3645 var selectedProfileDetail = target.getSelectedManualProfile();
3646 service.setDefaultApn({
3647 index: index,
3648 apnMode: target.apnMode(),
3649 pdpType: selectedProfileDetail.pdpType,
3650
3651 profileName: selectedProfileDetail.profileName,
3652 wanApn: selectedProfileDetail.wanApn,
3653 authMode: selectedProfileDetail.authMode,
3654 username: selectedProfileDetail.username,
3655 password: selectedProfileDetail.password,
3656 dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
3657 dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
3658 dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
3659 }, function (data) {
3660 if (data.result) {
3661 //showLoading("apn_alert_restart");
3662 //restartDevice(service);
3663 addTimeout(function () {
3664 initialize(true);
3665 target.apnModeChangeHandler();
3666 successOverlay();
3667 }, 500);
3668 } else {
3669 errorOverlay();
3670 }
3671 }, function (data) {
3672 errorOverlay();
3673 });
3674 }
3675
3676 target.getSelectedManualProfile = getSelectedManualProfileFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003677
qumengjiaca65ef52024-11-06 15:42:21 +08003678
3679 //获取自动apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003680
qumengjiaca65ef52024-11-06 15:42:21 +08003681 function getAutoApnIndex() {
3682 var configs = $("#autoProfile option");
3683 for (var ki = 0; ki < configs.length; ki++) {
3684 if (configs[ki].value == target.selectedAutoProfile()) {
3685 return ki;
3686 }
3687 }
3688 return configs.length - 1;
3689 }
mj.qu11d28a82024-12-17 18:09:17 -08003690
qumengjiaca65ef52024-11-06 15:42:21 +08003691 //获取apn索引
mj.qu11d28a82024-12-17 18:09:17 -08003692
qumengjiaca65ef52024-11-06 15:42:21 +08003693 function getApnIndex() {
3694 var configs = $("#profile option");
3695 if (configs.length == 0) {
3696 configs = target.profiles();
3697 }
3698 var ki = 0;
3699 for (; ki < configs.length; ki++) {
3700 if (configs[ki].value == target.selectedProfile()) {
3701 break;
3702 }
3703 }
3704 return ki;
3705 }
3706
3707 //保存APN设置信息
mj.qu11d28a82024-12-17 18:09:17 -08003708
qumengjiaca65ef52024-11-06 15:42:21 +08003709 target.saveAct = saveActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003710
qumengjiaca65ef52024-11-06 15:42:21 +08003711 //编辑APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003712
qumengjiaca65ef52024-11-06 15:42:21 +08003713 function editApnSetting(preAct) { //默认设置按钮触发为TRUE
3714 showLoading();
3715 var apnIndex = getApnIndex();
3716 var sameInfo = false;
3717 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3718 sameInfo = true;
3719 }
3720 var needDoDefault = false;
3721 if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
3722 needDoDefault = true;
3723 }
3724 service.addOrEditApn({
3725 profileName: target.profileName(),
3726 pdpType: target.selectedPdpType(),
3727 index: apnIndex,
3728
3729 wanApn: target.apn(),
3730 authMode: target.selectedAuthentication(),
3731 username: target.username(),
3732 password: target.password(),
3733 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3734 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3735 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3736
3737 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3738 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3739 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3740 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3741 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3742 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3743 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3744 }, function (data) {
3745 if (data.result) {
3746 apnSettings = getApnSet();
3747 if (target.profileName() != target.selectedProfile()) {
3748 var newProfileName = target.profileName();
3749 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3750 $('#profile').val(newProfileName).trigger('change');
3751 }
3752 if (needDoDefault == false) {
3753 successOverlay();
3754 } else {
3755 doSetDefaultAct();
3756 }
3757 } else {
3758 errorOverlay();
3759 }
3760 }, function (data) {
3761 errorOverlay();
3762 });
3763 }
mj.qu11d28a82024-12-17 18:09:17 -08003764
qumengjiaca65ef52024-11-06 15:42:21 +08003765 //新增APN信息
mj.qu11d28a82024-12-17 18:09:17 -08003766
qumengjiaca65ef52024-11-06 15:42:21 +08003767 function addNewApnSetting() {
3768 showLoading("waiting");
3769 var optionLen = $("option", "#profile").length;
3770 if (optionLen < config.defaultApnSize) {
3771 errorOverlay();
3772 return;
3773 }
3774 // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
3775 // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
3776 var sameInfo = false;
3777 if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
3778 sameInfo = true;
3779 }
3780
3781 service.addOrEditApn({
3782 profileName: target.profileName(),
3783 pdpType: target.selectedPdpType(),
3784 index: optionLen,
3785
3786 wanApn: target.apn(),
3787 authMode: target.selectedAuthentication(),
3788 username: target.username(),
3789 password: target.password(),
3790 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3791 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3792 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3793
3794 wanApnV6: sameInfo ? target.apn() : target.apnV6(),
3795 authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
3796 usernameV6: sameInfo ? target.username() : target.usernameV6(),
3797 passwordV6: sameInfo ? target.password() : target.passwordV6(),
3798 dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
3799 dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
3800 dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
3801 }, function (data) {
3802 if (data.result) {
3803 apnSettings = getApnSet();
3804 if (target.profileName() != target.selectedProfile()) {
3805 var newProfileName = target.profileName();
3806 target.profiles(getProfileOptions(apnSettings.apnConfigs));
3807 $('#profile').val(newProfileName).trigger('change');
3808 }
3809 doSetDefaultAct();
3810 } else {
3811 errorOverlay();
3812 }
3813 }, function (data) {
3814 errorOverlay();
3815 });
3816 }
3817
mj.qu11d28a82024-12-17 18:09:17 -08003818
qumengjiaca65ef52024-11-06 15:42:21 +08003819
3820 var tempApn = {};
3821 //删除APN
mj.qu11d28a82024-12-17 18:09:17 -08003822
qumengjiaca65ef52024-11-06 15:42:21 +08003823 target.deleteAct = deleteActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003824
qumengjiaca65ef52024-11-06 15:42:21 +08003825 //取消新增APN
mj.qu11d28a82024-12-17 18:09:17 -08003826
qumengjiaca65ef52024-11-06 15:42:21 +08003827 target.cancelAddAct = cancelAddActFunc;
mj.qu11d28a82024-12-17 18:09:17 -08003828
qumengjiaca65ef52024-11-06 15:42:21 +08003829 //进入新增APN页面
mj.qu11d28a82024-12-17 18:09:17 -08003830
qumengjiaca65ef52024-11-06 15:42:21 +08003831 target.addAct = addActFunc;
3832 //进入新增APN页面
3833 function addActFunc() {
3834 clearValidateMsg('#apn_setting_form');
3835 target.pdpTypeNote(true);
3836 target.disableProfile(true);
3837 target.addApnHide(true);
3838 tempApn = {
3839 profileName: target.profileName(),
3840 selectedPdpType: target.selectedPdpType(),
3841
3842 wanApnV6: target.apnV6(),
3843 dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
3844 dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
3845 dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
3846 authModeV6: target.selectedAuthenticationV6(),
3847 usernameV6: target.usernameV6(),
3848 passwordV6: target.passwordV6(),
mj.qu11d28a82024-12-17 18:09:17 -08003849
qumengjiaca65ef52024-11-06 15:42:21 +08003850 wanApn: target.apn(),
3851 dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
3852 dns1: config.SHOW_APN_DNS ? target.dns1() : '',
3853 dns2: config.SHOW_APN_DNS ? target.dns2() : '',
3854 authMode: target.selectedAuthentication(),
3855 username: target.username(),
3856 password: target.password(),
3857
3858 };
3859 target.profileName("");
3860 target.selectedPdpType("IP");
3861 target.selectedPdpTypeTmp("IP");
3862
3863 target.apnV6("");
3864 target.dnsModeV6("auto");
3865 target.dns1V6("");
3866 target.dns2V6("");
3867 target.selectedAuthenticationV6("none");
3868 target.usernameV6("");
3869 target.passwordV6("");
mj.qu11d28a82024-12-17 18:09:17 -08003870
qumengjiaca65ef52024-11-06 15:42:21 +08003871 target.apn("");
3872 target.dnsMode("auto");
3873 target.dns1("");
3874 target.dns2("");
3875 target.selectedAuthentication("none");
3876 target.username("");
3877 target.password("");
3878
3879 }
mj.qu11d28a82024-12-17 18:09:17 -08003880
qumengjiaca65ef52024-11-06 15:42:21 +08003881 //取消新增APN
3882 function cancelAddActFunc() {
3883 clearValidateMsg('#apn_setting_form');
3884 target.pdpTypeNote(false);
3885 target.disableProfile(false);
3886 target.addApnHide(false);
3887 target.profileName(tempApn.profileName);
3888 target.selectedPdpType(tempApn.selectedPdpType);
3889 target.selectedPdpTypeTmp(tempApn.selectedPdpType);
3890
3891 target.apnV6(tempApn.wanApnV6);
3892 target.dnsModeV6(tempApn.dnsModeV6);
3893 target.dns1V6(tempApn.dns1V6);
3894 target.dns2V6(tempApn.dns2V6);
3895 target.selectedAuthenticationV6(tempApn.authModeV6);
3896 target.usernameV6(tempApn.usernameV6);
3897 target.passwordV6(tempApn.passwordV6);
mj.qu11d28a82024-12-17 18:09:17 -08003898
qumengjiaca65ef52024-11-06 15:42:21 +08003899 target.apn(tempApn.wanApn);
3900 target.dnsMode(tempApn.dnsMode);
3901 target.dns1(tempApn.dns1);
3902 target.dns2(tempApn.dns2);
3903 target.selectedAuthentication(tempApn.authMode);
3904 target.username(tempApn.username);
3905 target.password(tempApn.password);
3906
3907 }
mj.qu11d28a82024-12-17 18:09:17 -08003908
qumengjiaca65ef52024-11-06 15:42:21 +08003909 //删除APN
3910 function deleteActFunc() {
3911 if (!target.selectedProfile()) {
3912 showAlert("apn_no_select_alert");
3913 return false;
3914 }
3915 if (target.predeterminedCfg()) { //预置的apn不允许删除
3916 errorOverlay("apn_delete_cant_delete_default");
3917 return false;
3918 }
3919 if (getApnSet().profileName == target.profileName()) {
3920 errorOverlay("apn_cant_delete_current");
3921 return false;
3922 }
3923
3924 showConfirm("apn_delete_confirm", function () {
3925 showLoading('deleting');
3926 service.deleteApn({
3927 index: getApnIndex()
3928 }, function (data) {
3929 if (data.result) {
3930 target.profiles(getProfileOptions(getApnSet().apnConfigs));
3931 target.selectedProfile(target.defApn());
3932 target.profileChangeHandler();
3933 successOverlay();
3934 } else {
3935 errorOverlay();
3936 }
3937 }, function (data) {
3938 errorOverlay();
3939 });
3940 });
3941 }
mj.qu11d28a82024-12-17 18:09:17 -08003942
qumengjiaca65ef52024-11-06 15:42:21 +08003943 //保存APN设置信息
3944 function saveActFunc() {
3945 if (!$('#apn_setting_form').valid()) {
3946 return false;
3947 }
3948 if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
3949 showAlert("apn_no_select_alert");
3950 return false;
3951 }
3952 var exist = false;
3953 $.each(target.profiles(), function (i, e) {
3954 if (e.value == target.profileName()) {
3955 exist = true;
3956 }
3957 });
3958
3959 if (target.disableProfile() == false) {
3960 if (exist && target.selectedProfile() != target.profileName()) {
3961 showInfo("apn_save_profile_exist");
3962 return false;
3963 }
3964 if (target.predeterminedCfg()) { //预置的APN不可以修改
3965 errorOverlay();
3966 return false;
3967 }
3968 if (target.predeterminedCfg() || target.defaultCfg()) {
3969 //showConfirm("apn_alert", function () {
3970 editApnSetting(false);
3971 //});
3972 } else {
3973 editApnSetting(false);
3974 }
3975 } else {
mj.qu11d28a82024-12-17 18:09:17 -08003976
qumengjiaca65ef52024-11-06 15:42:21 +08003977 if ($("#profile option").length >= config.maxApnNumber) {
3978 showInfo({
3979 msg: "apn_profile_full",
3980 params: [config.maxApnNumber]
3981 });
3982 return false;
3983 }
3984 if (exist) {
3985 showInfo("apn_save_profile_exist");
3986 return false;
3987 }
3988 var info = service.getStatusInfo();
3989 if (info.connectStatus != "ppp_connected") {
3990 //showConfirm("apn_alert", function () {
3991 addNewApnSetting();
3992 //});
mj.qu11d28a82024-12-17 18:09:17 -08003993
qumengjiaca65ef52024-11-06 15:42:21 +08003994 } else {
3995 showConfirm("apn_diconneted_network_confirm", function () {
3996 showLoading('disconnecting');
3997 service.disconnect({}, function (data) {
3998 if (data.result) {
3999 config.connect_flag = true;
4000 addNewApnSetting();
4001 } else {
4002 errorOverlay();
4003 }
4004 });
4005 });
4006 }
4007 }
4008 }
mj.qu11d28a82024-12-17 18:09:17 -08004009
qumengjiaca65ef52024-11-06 15:42:21 +08004010 function getSelectedManualProfileFunc() {
4011 var cfg = {};
4012 var profileVal = $("#profile").val();
4013 if (typeof target.selectedProfile() == 'undefined') {
4014 target.selectedProfile(profileVal);
4015 }
4016 var cfgV4 = apnConfigs[profileVal];
4017 var cfgV6 = ipv6ApnConfigs[profileVal];
4018 if (cfgV4 && !cfgV6) {
4019 $.extend(cfg, cfgV4);
4020 } else if (cfgV4 && cfgV6) {
4021 if (!!cfgV4.pdpType) {
4022 $.extend(cfg, cfgV6);
4023 $.extend(cfg, cfgV4);
4024 } else {
4025 $.extend(cfg, cfgV4);
4026 $.extend(cfg, cfgV6);
4027 }
4028 }
4029 return cfg;
4030 }
mj.qu11d28a82024-12-17 18:09:17 -08004031
qumengjiaca65ef52024-11-06 15:42:21 +08004032 //APN mode change 事件处理
4033 function apnModeChangeHandlerFunc(data, event) {
4034 if (target.apnMode() != 'auto') {
4035 target.profileChangeHandler();
4036 } else {
4037 if (target.showAutoApnDetail()) {
4038 target.autoProfileChangeHandler();
4039 }
4040 }
4041 return true;
4042 }
mj.qu11d28a82024-12-17 18:09:17 -08004043
qumengjiaca65ef52024-11-06 15:42:21 +08004044 //设置为默认apn
4045 function setDefaultActFunc() {
4046 if (!target.selectedProfile()) {
4047 showAlert("apn_no_select_alert");
4048 return false;
4049 }
4050 var connectStatus = service.getConnectionInfo().connectStatus;
4051 if (connectStatus == "ppp_connecting") {
4052 showAlert({
4053 msg: "apn_cant_modify_status",
4054 params: [$.i18n.prop("connecting").toLowerCase()]
4055 });
4056 return false;
4057 } else if (connectStatus == "ppp_disconnecting") {
4058 showAlert({
4059 msg: "apn_cant_modify_status",
4060 params: [$.i18n.prop("disconnecting").toLowerCase()]
4061 });
4062 return false;
4063 } else if (connectStatus == "ppp_connected") {
4064 showAlert({
4065 msg: "apn_cant_modify_status",
4066 params: [$.i18n.prop("connected").toLowerCase()]
4067 });
4068 return false;
4069 }
4070 if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
4071 //showConfirm("apn_alert", function () {
4072 showLoading("waiting");
4073 doSetDefaultAct();
4074 //});
4075 } else {
4076 if ($('#apn_setting_form').valid() == false) {
4077 $(".error:first", "#apn_setting_form").focus();
4078 } else {
4079 var exist = false;
4080 $.each(target.profiles(), function (i, e) {
4081 if (e.value == target.profileName()) {
4082 exist = true;
4083 }
4084 });
4085 if (exist && target.selectedProfile() != target.profileName()) {
4086 showInfo("apn_save_profile_exist");
4087 return false;
4088 }
4089 //showLoading("waiting");
4090 //showConfirm("apn_alert", function () {
4091 editApnSetting(true);
4092 //});
4093 }
4094 }
4095 }
mj.qu11d28a82024-12-17 18:09:17 -08004096
qumengjiaca65ef52024-11-06 15:42:21 +08004097 //切换profile时重置下面的显示项
4098 function setUIDataFunc(data) {
4099 clearValidateMsg('#apn_setting_form');
4100 if (!data) {
4101 return;
4102 }
4103 target.selectedPdpType(data.pdpType || 'IP');
4104 target.selectedPdpTypeTmp(data.pdpType || 'IP');
4105 target.profileName(data.profileName);
4106
4107 target.apn(data.wanApn);
4108 target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
4109 target.dns1(data.dns1);
4110 target.dns2(data.dns2);
4111 target.username(data.username);
4112 target.password(data.password);
4113 target.selectedAuthentication(data.authMode || 'none');
4114
4115 target.apnV6(data.wanApnV6);
4116 target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
4117 target.dns1V6(data.dns1V6);
4118 target.dns2V6(data.dns2V6);
4119 target.usernameV6(data.usernameV6);
4120 target.passwordV6(data.passwordV6);
4121 target.selectedAuthenticationV6(data.authModeV6 || 'none');
4122 }
mj.qu11d28a82024-12-17 18:09:17 -08004123
qumengjiaca65ef52024-11-06 15:42:21 +08004124 //profile change 事件处理
4125 function profileChangeHandlerFunc(data, event) {
4126 target.pdpTypeNote(true);
4127 if (target.apnMode() != 'manual') {
4128 return true;
4129 }
4130 var cfg = target.getSelectedManualProfile();
4131 target.setUIData(cfg);
4132 checkDefaultProfileStatus();
4133 return true;
4134 }
mj.qu11d28a82024-12-17 18:09:17 -08004135
qumengjiaca65ef52024-11-06 15:42:21 +08004136 //auto apn profile change 事件处理
4137 function autoProfileChangeHandlerFunc(data, event) {
4138 if (target.apnMode() != 'auto') {
4139 return true;
4140 }
4141 var cfg = autoApnConfigs[target.selectedAutoProfile()];
4142 target.setUIData(cfg);
4143 checkDefaultProfileStatus();
4144 return true;
4145 }
mj.qu11d28a82024-12-17 18:09:17 -08004146
qumengjiaca65ef52024-11-06 15:42:21 +08004147 function pdpTypeChangeAlertFunc() {
4148 if (target.pdpTypeNote()) {
4149 showAlert({
4150 msg: "apn_pdptype_change_note",
4151 params: [data.lanDomain, data.ipAddress]
4152 });
4153 }
4154 if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
4155 if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
4156 if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
4157 target.apn(target.apnV6());
4158 target.dnsMode(target.dnsModeV6());
4159 target.dns1(target.dns1V6());
4160 target.dns2(target.dns2V6());
4161 target.username(target.usernameV6());
4162 target.password(target.passwordV6());
4163 target.selectedAuthentication(target.selectedAuthenticationV6());
4164 } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
4165 target.apnV6(target.apn());
4166 target.dnsModeV6(target.dnsMode());
4167 target.dns1V6(target.dns1());
4168 target.dns2V6(target.dns2());
4169 target.usernameV6(target.username());
4170 target.passwordV6(target.password());
4171 target.selectedAuthenticationV6(target.selectedAuthentication());
4172 }
4173 }
4174 }
4175 target.selectedPdpTypeTmp(target.selectedPdpType());
4176 }
mj.qu11d28a82024-12-17 18:09:17 -08004177
qumengjiaca65ef52024-11-06 15:42:21 +08004178
4179 }
4180
4181 //是否已联网
mj.qu11d28a82024-12-17 18:09:17 -08004182
qumengjiaca65ef52024-11-06 15:42:21 +08004183 function isConnectedNetWork() {
4184 var info = service.getConnectionInfo();
4185 return info.connectStatus == "ppp_connected";
4186 }
4187
4188 function initVar() {
4189 apnConfigs = {};
4190 ipv6ApnConfigs = {};
4191 autoApnConfigs = {};
4192 }
4193 function bindContainer(vm){
4194 var container = $('#container');
4195 ko.cleanNode(container[0]);
4196 ko.applyBindings(vm, container[0]);
4197 }
4198 //初始化ViewModel
mj.qu11d28a82024-12-17 18:09:17 -08004199
qumengjiaca65ef52024-11-06 15:42:21 +08004200 function initialize(formInit) {
4201 initVar();
mj.qu11d28a82024-12-17 18:09:17 -08004202
qumengjiaca65ef52024-11-06 15:42:21 +08004203 var vm = new APNViewModel();
4204 bindContainer(vm);
4205
4206 if (!formInit) {
4207 addInterval(function () {
4208 vm.setDefaultVisible(!isConnectedNetWork());
4209 }, 1000);
4210 }
4211 $('#apn_setting_form').validate({
4212 submitHandler: function () {
4213 vm.saveAct();
4214 },
4215 rules: {
4216 profile_name: 'apn_profile_name_check',
4217 apn_ipv4_apn: 'apn_check',
4218 apn_dns1_ipv4: "ipv4",
4219 apn_dns2_ipv4: "ipv4",
4220 apn_ipv6_apn: 'apn_check',
4221 apn_dns1_ipv6: "ipv6",
4222 apn_dns2_ipv6: "ipv6",
4223 apn_user_name_ipv4: 'ppp_username_check',
4224 apn_secretcode_ipv4: 'ppp_secretcode_check',
4225 apn_user_name_ipv6: 'ppp_username_check',
4226 apn_secretcode_ipv6: 'ppp_secretcode_check'
4227 }
4228 });
4229 }
4230
4231 return {
4232 init: initialize
4233 };
mj.qu11d28a82024-12-17 18:09:17 -08004234});
4235define("network_info","underscore jquery knockout set service".split(" "),
4236 function (_, $, ko, config, service) {
4237
4238 function NetInfoVM() {
4239 var target = this;
4240 var network_status = service.getNetworkStatus();
4241
4242 target.pci = ko.observable(network_status.pci);
4243 target.sinr = ko.observable(network_status.sinr);
4244 target.rsrp = ko.observable(network_status.rsrp);
4245 target.rsrq = ko.observable(network_status.rsrq);
4246 target.plmn = ko.observable(network_status.plmn);
4247 target.cellid = ko.observable(network_status.cellid);
w.dengbcaf3a52024-12-30 17:43:27 +08004248 target.band = ko.observable(network_status.band);
mj.qu11d28a82024-12-17 18:09:17 -08004249 }
4250
4251 function initialize() {
4252 var container = $('#container');
4253 ko.cleanNode(container[0]);
4254 var imVm = new NetInfoVM();
4255 ko.applyBindings(imVm, container[0]);
4256 }
4257
4258 return {
4259 init: initialize
4260 };
4261});