lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 |
|
| 2 | define("firewall_url_filter","underscore jquery knockout set service".split(" "),
|
| 3 | function (_, $, ko, config, service) {
|
| 4 |
|
| 5 | //system url filter setting VM
|
| 6 |
|
| 7 | function UrlFilterSettingVM() {
|
| 8 | var target = this;
|
| 9 | var urlFltInfo = service.getUrlFilterList();
|
| 10 | var columnsTmpl = [{
|
| 11 | columnType: "checkbox",
|
| 12 | rowText: "index",
|
| 13 | width: "30%"
|
| 14 | }, {
|
| 15 | headerTextTrans: "url",
|
| 16 | rowText: "url",
|
| 17 | width: "70%"
|
| 18 | }
|
| 19 | ];
|
| 20 | target.rules = ko.observableArray(urlFltInfo.urlFilterRules);
|
| 21 |
|
| 22 | target.gridTemplate = new ko.simpleGrid.viewModel({
|
| 23 | data: target.rules(),
|
| 24 | idName: "index",
|
| 25 | columns: columnsTmpl,
|
| 26 | tmplType: 'list',
|
| 27 | pageSize: 10
|
| 28 | });
|
| 29 |
|
| 30 | target.clear = clearFunc;
|
| 31 |
|
| 32 | target.callback = callbackFunc;
|
| 33 | //删除规则
|
| 34 |
|
| 35 | target.deleteRule = deleteRuleFunc;
|
| 36 |
|
| 37 | //添加规则
|
| 38 |
|
| 39 | target.addRule = addRuleFunc;
|
| 40 | function callbackFunc(elem) {
|
| 41 | if (elem.result != "success") {
|
| 42 | errorOverlay();
|
| 43 | } else {
|
| 44 | target.clear();
|
| 45 | initialize(target);
|
| 46 | successOverlay();
|
| 47 | $("#urlFilters").translate();
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | //添加规则
|
| 52 | function addRuleFunc() {
|
| 53 | if (target.rules().length >= config.urlFilterMax) {
|
| 54 | showAlert({
|
| 55 | msg: "url_filter_max",
|
| 56 | params: config.urlFilterMax
|
| 57 | });
|
| 58 | return false;
|
| 59 | }
|
| 60 | var tmpArr = [];
|
| 61 | for (var idx = 0; idx < target.rules().length; idx++) {
|
| 62 | tmpArr.push(target.rules()[idx].url);
|
| 63 | }
|
| 64 | if ($.inArray($("#addURLFilter").val(), tmpArr) != -1) {
|
| 65 | showAlert("url_repeated");
|
| 66 | return false;
|
| 67 | }
|
| 68 |
|
| 69 | showLoading();
|
| 70 | var urlFltParams = {
|
| 71 | goformId: "URL_FILTER_ADD",
|
| 72 | addURLFilter: $("#addURLFilter").val()
|
| 73 | };
|
| 74 | service.addUrlFilterRule(urlFltParams, target.callback);
|
| 75 | }
|
| 76 | //删除规则
|
| 77 | function deleteRuleFunc() {
|
| 78 | showConfirm('confirm_data_delete', function () {
|
| 79 | showLoading();
|
| 80 | var urlFltParams = {
|
| 81 | goformId: "URL_FILTER_DELETE",
|
| 82 | url_filter_delete_id: target.gridTemplate.selectedIds().join(";") + ";"
|
| 83 | };
|
| 84 | service.deleteSelectedRules(urlFltParams, target.callback);
|
| 85 | });
|
| 86 | }
|
| 87 |
|
| 88 | }
|
| 89 |
|
| 90 | function clearFunc() {
|
| 91 | $("#addURLFilter").val("");
|
| 92 | }
|
| 93 |
|
| 94 | //页面初始化
|
| 95 |
|
| 96 | function initialize() {
|
| 97 |
|
| 98 | var vm = new UrlFilterSettingVM();
|
| 99 | bindContainer(vm);
|
| 100 | }
|
| 101 | function bindContainer(vm){
|
| 102 | var container = $('#container');
|
| 103 | ko.cleanNode(container[0]);
|
| 104 | ko.applyBindings(vm, container[0]);
|
| 105 | $('#urlFilterForm').validate({
|
| 106 | submitHandler: function () {
|
| 107 | vm.addRule();
|
| 108 | },
|
| 109 | rules: {
|
| 110 | addURLFilter: 'url_filter_check'
|
| 111 | }
|
| 112 | });
|
| 113 |
|
| 114 | $("#urlFilterListForm").validate({
|
| 115 | submitHandler: function () {
|
| 116 | vm.deleteRule();
|
| 117 | }
|
| 118 | });
|
| 119 | }
|
| 120 |
|
| 121 | return {
|
| 122 | init: initialize
|
| 123 | };
|
| 124 | });
|
| 125 |
|
| 126 | define("firewall_upnp_set","underscore jquery knockout set service".split(" "),
|
| 127 | function (_, $, ko, config, service) {
|
| 128 |
|
| 129 | //system upnp setting VM
|
| 130 |
|
| 131 | function UpnpSettingVM() {
|
| 132 | var target = this;
|
| 133 | var upnpInfo = getUpnpSetting();
|
| 134 |
|
| 135 | target.upnpSetting = ko.observable(upnpInfo.upnpSetting);
|
| 136 |
|
| 137 | target.save = saveFunc;
|
| 138 | function saveFunc() {
|
| 139 | showLoading();
|
| 140 | var upnpParams = {};
|
| 141 | upnpParams.upnpSetting = target.upnpSetting();
|
| 142 | service.setUpnpSetting(upnpParams, function (rlt) {
|
| 143 | if (rlt.result == "success") {
|
| 144 | successOverlay();
|
| 145 | } else {
|
| 146 | errorOverlay();
|
| 147 | }
|
| 148 | });
|
| 149 |
|
| 150 | }
|
| 151 | }
|
| 152 |
|
| 153 |
|
| 154 | //获取upnp 信息
|
| 155 |
|
| 156 | function getUpnpSetting() {
|
| 157 | return service.getUpnpSetting();
|
| 158 | }
|
| 159 |
|
| 160 | //初始化UpnpSettingVM model
|
| 161 |
|
| 162 | function initialize() {
|
| 163 |
|
| 164 | var vm = new UpnpSettingVM();
|
| 165 | bindContainer(vm);
|
| 166 |
|
| 167 | }
|
| 168 | function bindContainer(vm) {
|
| 169 | var container = $('#container');
|
| 170 | ko.cleanNode(container[0]);
|
| 171 | ko.applyBindings(vm, container[0]);
|
| 172 | $('#upnpSettingForm').validate({
|
| 173 | submitHandler: function () {
|
| 174 | vm.save();
|
| 175 | }
|
| 176 | });
|
| 177 | }
|
| 178 |
|
| 179 | return {
|
| 180 | init: initialize
|
| 181 | };
|
| 182 | });
|
| 183 |
|
| 184 | //端口映射
|
| 185 |
|
| 186 | define("firewall_port_map","underscore jquery knockout set service".split(" "),
|
| 187 | function (_, $, ko, config, service) {
|
| 188 |
|
| 189 | var protocolModes = _.map(config.MAP_PROTOCOL_MODES, function (ele) {
|
| 190 | return new Option(ele.name, ele.value);
|
| 191 | });
|
| 192 |
|
| 193 | var columnsTmpl = [{
|
| 194 | columnType: "checkbox",
|
| 195 | rowText: "index",
|
| 196 | width: "8%"
|
| 197 | }, {
|
| 198 | headerTextTrans: "source_port",
|
| 199 | rowText: "sourcePort",
|
| 200 | width: "20%"
|
| 201 | }, {
|
| 202 | headerTextTrans: "dest_ip_address",
|
| 203 | rowText: "destIpAddress",
|
| 204 | width: "20%"
|
| 205 | }, {
|
| 206 | headerTextTrans: "dest_port",
|
| 207 | rowText: "destPort",
|
| 208 | width: "20%"
|
| 209 | }, {
|
| 210 | headerTextTrans: "protocol",
|
| 211 | rowText: "protocol",
|
| 212 | width: "12%"
|
| 213 | }, {
|
| 214 | headerTextTrans: "comment",
|
| 215 | rowText: "comment",
|
| 216 | width: "20%"
|
| 217 | }
|
| 218 | ];
|
| 219 |
|
| 220 | //prot_map VM
|
| 221 |
|
| 222 | function PortMapVM() {
|
| 223 | var target = this;
|
| 224 | var mapInfo = getPortMap();
|
| 225 |
|
| 226 | target.oriPortMapEnable = ko.observable(mapInfo.portMapEnable);
|
| 227 | target.rules = ko.observableArray(mapInfo.portMapRules);
|
| 228 | target.portMapEnable = ko.observable(mapInfo.portMapEnable);
|
| 229 |
|
| 230 |
|
| 231 | target.comment = ko.observable('');
|
| 232 | target.selectedMode = ko.observable('TCP&UDP');
|
| 233 | target.modes = ko.observableArray(protocolModes);
|
| 234 |
|
| 235 | target.destPort = ko.observable('');
|
| 236 | target.destIpAddress = ko.observable('');
|
| 237 | target.sourcePort = ko.observable('');
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 | target.gridTemplate = new ko.simpleGrid.viewModel({
|
| 242 | data: target.rules(),
|
| 243 | idName: "index",
|
| 244 | columns: columnsTmpl,
|
| 245 | tmplType: 'list',
|
| 246 | pageSize: 10
|
| 247 | });
|
| 248 |
|
| 249 | //设定,新增,删除回调函数
|
| 250 |
|
| 251 | target.callback = callbackFunc;
|
| 252 |
|
| 253 | //删除规则
|
| 254 |
|
| 255 | target.deleteMapRules = deleteMapRulesFunc;
|
| 256 |
|
| 257 | //检查新增规则是否已经存在
|
| 258 |
|
| 259 | target.checkExist = checkExistFunc;
|
| 260 |
|
| 261 | //设定端口映射
|
| 262 |
|
| 263 | target.enablePortMap = enablePortMapFunc;
|
| 264 |
|
| 265 | //保存规则
|
| 266 |
|
| 267 | target.save = saveFunc;
|
| 268 |
|
| 269 | //保存规则
|
| 270 | function saveFunc() {
|
| 271 | if (target.rules().length >= config.portForwardMax) {
|
| 272 | showAlert({
|
| 273 | msg: "rules_max",
|
| 274 | params: config.portForwardMax
|
| 275 | });
|
| 276 | return;
|
| 277 | }
|
| 278 |
|
| 279 | if (target.checkExist()) {
|
| 280 | showAlert("rule_exist");
|
| 281 | return;
|
| 282 | }
|
| 283 |
|
| 284 | showLoading();
|
| 285 | var mapParams = {};
|
| 286 | mapParams.portMapEnable = target.portMapEnable();
|
| 287 | mapParams.sourcePort = target.sourcePort();
|
| 288 | mapParams.destIpAddress = target.destIpAddress();
|
| 289 | mapParams.destPort = target.destPort();
|
| 290 | mapParams.protocol = target.selectedMode();
|
| 291 | mapParams.comment = target.comment();
|
| 292 | service.setPortMap(mapParams, target.callback);
|
| 293 | }
|
| 294 |
|
| 295 | //检查新增规则是否已经存在
|
| 296 | function checkExistFunc() {
|
| 297 | var newMapRule = {
|
| 298 | sourcePort: target.sourcePort(),
|
| 299 | destIpAddress: target.destIpAddress(),
|
| 300 | destPort: target.destPort(),
|
| 301 | protocol: transProtocolValue(target.selectedMode())
|
| 302 | };
|
| 303 |
|
| 304 | var oldMapRule;
|
| 305 | var mapRules = target.rules();
|
| 306 | for (var idx = 0; idx < mapRules.length; idx++) {
|
| 307 | oldMapRule = {
|
| 308 | sourcePort: mapRules[idx].sourcePort,
|
| 309 | destIpAddress: mapRules[idx].destIpAddress,
|
| 310 | destPort: mapRules[idx].destPort,
|
| 311 | protocol: mapRules[idx].protocol
|
| 312 | };
|
| 313 |
|
| 314 | if (_.isEqual(newMapRule, oldMapRule)) {
|
| 315 | return true;
|
| 316 | }
|
| 317 | }
|
| 318 | return false;
|
| 319 | }
|
| 320 |
|
| 321 | //设定端口映射
|
| 322 | function enablePortMapFunc() {
|
| 323 | showLoading();
|
| 324 | var mapParams = {};
|
| 325 | mapParams.portMapEnable = target.portMapEnable();
|
| 326 | service.enablePortMap(mapParams, target.callback);
|
| 327 | }
|
| 328 |
|
| 329 | //删除规则
|
| 330 | function deleteMapRulesFunc() {
|
| 331 | var ids = target.gridTemplate.selectedIds();
|
| 332 | if (ids.length == 0) {
|
| 333 | showAlert("no_data_selected");
|
| 334 | return;
|
| 335 | }
|
| 336 |
|
| 337 | showConfirm("confirm_data_delete", function () {
|
| 338 | showLoading();
|
| 339 | var mapParams = {};
|
| 340 | mapParams.indexs = ids;
|
| 341 | service.deleteMapRules(mapParams, target.callback);
|
| 342 | });
|
| 343 | }
|
| 344 |
|
| 345 | //设定,新增,删除回调函数
|
| 346 | function callbackFunc(ret) {
|
| 347 | if (ret.result == "success") {
|
| 348 | clear();
|
| 349 | initialize(target);
|
| 350 | successOverlay();
|
| 351 | } else {
|
| 352 | errorOverlay();
|
| 353 | }
|
| 354 | }
|
| 355 |
|
| 356 | //情况添加规则输入
|
| 357 |
|
| 358 | function clear() {
|
| 359 | target.sourcePort('');
|
| 360 | target.destIpAddress('');
|
| 361 | target.destPort('');
|
| 362 | target.selectedMode('TCP&UDP');
|
| 363 | target.comment('');
|
| 364 | }
|
| 365 | }
|
| 366 |
|
| 367 | //获取port map信息
|
| 368 |
|
| 369 | function getPortMap() {
|
| 370 | return service.getPortMap();
|
| 371 | }
|
| 372 |
|
| 373 | function bindingContainer(vm){
|
| 374 | var container = $('#container');
|
| 375 | ko.cleanNode(container[0]);
|
| 376 | ko.applyBindings(vm, container[0]);
|
| 377 |
|
| 378 | }
|
| 379 | //初始化port map view model
|
| 380 |
|
| 381 | function initialize(viewModel) {
|
| 382 | var vm;
|
| 383 | if (viewModel) {
|
| 384 | vm = viewModel;
|
| 385 | var mapInfo = getPortMap();
|
| 386 | vm.portMapEnable(mapInfo.portMapEnable);
|
| 387 | vm.oriPortMapEnable(mapInfo.portMapEnable);
|
| 388 | vm.rules(mapInfo.portMapRules);
|
| 389 | vm.gridTemplate.clearAllChecked();
|
| 390 | vm.gridTemplate.data(mapInfo.portMapRules);
|
| 391 | refreshTableHeight();
|
| 392 | renderCheckbox();
|
| 393 | return;
|
| 394 | }
|
| 395 |
|
| 396 | vm = new PortMapVM();
|
| 397 | bindingContainer(vm);
|
| 398 | fixTableHeight();
|
| 399 |
|
| 400 | $('#mapBasicForm').validate({
|
| 401 | submitHandler: function () {
|
| 402 | vm.enablePortMap();
|
| 403 | }
|
| 404 | });
|
| 405 |
|
| 406 | $('#portMapListForm').validate({
|
| 407 | submitHandler: function () {
|
| 408 | vm.deleteMapRules();
|
| 409 | }
|
| 410 | });
|
| 411 |
|
| 412 | $('#portMapForm').validate({
|
| 413 | submitHandler: function () {
|
| 414 | vm.save();
|
| 415 | },
|
| 416 | rules: {
|
| 417 | txtDestIpAddress: {
|
| 418 | ip_check: true
|
| 419 | },
|
| 420 | txtSourcePort: {
|
| 421 | digits: true,
|
| 422 | range_except: [1, 65000]
|
| 423 | },
|
| 424 | txtDestPort: {
|
| 425 | digits: true,
|
| 426 | range_except: [1, 65000]
|
| 427 | },
|
| 428 | txtComment: {
|
| 429 | comment_check: true
|
| 430 | }
|
| 431 | },
|
| 432 | errorPlacement: function (error, element) {
|
| 433 | if (element.attr("name") == "txtDestIpAddress") {
|
| 434 | error.appendTo("#txtDestIpAddressErrorDiv");
|
| 435 | } else if (element.attr("name") == "txtSourcePort") {
|
| 436 | error.appendTo("#txtSourcePortErrorDiv");
|
| 437 | } else if (element.attr("name") == "txtDestPort") {
|
| 438 | error.appendTo("#txtDestPortErrorDiv");
|
| 439 | } else
|
| 440 | error.insertAfter(element);
|
| 441 | }
|
| 442 | });
|
| 443 | }
|
| 444 |
|
| 445 | return {
|
| 446 | init: initialize
|
| 447 | };
|
| 448 | });
|
| 449 |
|
| 450 | //端口转发
|
| 451 |
|
| 452 | define("firewall_port_forward","underscore jquery knockout set service".split(" "),
|
| 453 | function (_, $, ko, config, service) {
|
| 454 |
|
| 455 | var protocolModes = _.map(config.FORWARD_PROTOCOL_MODES, function (ele) {
|
| 456 | return new Option(ele.name, ele.value);
|
| 457 | });
|
| 458 | //列表模板的columns项
|
| 459 |
|
| 460 | var columnsTmpl = [{
|
| 461 | columnType: "checkbox",
|
| 462 | rowText: "index",
|
| 463 | width: "8%"
|
| 464 | }, {
|
| 465 | headerTextTrans: "ip_address",
|
| 466 | rowText: "ipAddress",
|
| 467 | width: "23%"
|
| 468 | }, {
|
| 469 | headerTextTrans: "port_range",
|
| 470 | rowText: "portRange",
|
| 471 | width: "23%"
|
| 472 | }, {
|
| 473 | headerTextTrans: "protocol",
|
| 474 | rowText: "protocol",
|
| 475 | width: "23%"
|
| 476 | }, {
|
| 477 | headerTextTrans: "comment",
|
| 478 | rowText: "comment",
|
| 479 | width: "23%"
|
| 480 | }
|
| 481 | ];
|
| 482 |
|
| 483 | //prot_forward VM
|
| 484 |
|
| 485 | function PortForwardVM() {
|
| 486 | var target = this;
|
| 487 | var fwdinfo = getPortForward();
|
| 488 |
|
| 489 | target.portForwardEnable = ko.observable(fwdinfo.portForwardEnable);
|
| 490 | target.oriPortForwardEnable = ko.observable(fwdinfo.portForwardEnable);
|
| 491 |
|
| 492 | target.portEnd = ko.observable('');
|
| 493 | target.portStart = ko.observable('');
|
| 494 | target.ipAddress = ko.observable('');
|
| 495 |
|
| 496 | target.comment = ko.observable('');
|
| 497 | target.selectedMode = ko.observable('3');
|
| 498 | target.modes = ko.observableArray(protocolModes);
|
| 499 |
|
| 500 | target.rules = ko.observableArray(fwdinfo.portForwardRules);
|
| 501 |
|
| 502 | //设定,新增,删除回调函数
|
| 503 |
|
| 504 | target.callback = callbackFunc;
|
| 505 |
|
| 506 | //创建列表模板
|
| 507 |
|
| 508 | target.gridTemplate = new ko.simpleGrid.viewModel({
|
| 509 | data: target.rules(),
|
| 510 | idName: "index",
|
| 511 | columns: columnsTmpl,
|
| 512 | tmplType: 'list',
|
| 513 | pageSize: 10
|
| 514 | });
|
| 515 |
|
| 516 | //检查新增规则是否已经存在
|
| 517 |
|
| 518 | target.checkExist = checkExistFunc;
|
| 519 |
|
| 520 | //保存规则
|
| 521 |
|
| 522 | target.save = saveFunc;
|
| 523 |
|
| 524 | //删除规则
|
| 525 |
|
| 526 | target.deleteForwardRules = deleteForwardRulesFunc;
|
| 527 |
|
| 528 | //设定虚拟服务器
|
| 529 |
|
| 530 | target.enableVirtualServer = enableVirtualServerFunc;
|
| 531 |
|
| 532 | //设定虚拟服务器
|
| 533 | function enableVirtualServerFunc() {
|
| 534 | showLoading();
|
| 535 | var fwdParams = {};
|
| 536 | fwdParams.portForwardEnable = target.portForwardEnable();
|
| 537 | service.enableVirtualServer(fwdParams, target.callback);
|
| 538 | }
|
| 539 |
|
| 540 | //删除规则
|
| 541 | function deleteForwardRulesFunc() {
|
| 542 | var ids = target.gridTemplate.selectedIds();
|
| 543 | if (ids.length == 0) {
|
| 544 | showAlert("no_data_selected");
|
| 545 | return;
|
| 546 | }
|
| 547 |
|
| 548 | showConfirm("confirm_data_delete", function () {
|
| 549 | showLoading('deleting');
|
| 550 | var fwdParams = {};
|
| 551 | fwdParams.indexs = ids;
|
| 552 | service.deleteForwardRules(fwdParams, target.callback);
|
| 553 | });
|
| 554 | }
|
| 555 |
|
| 556 | //保存规则
|
| 557 | function saveFunc() {
|
| 558 | if (target.rules().length >= config.portForwardMax) {
|
| 559 | showAlert({
|
| 560 | msg: "rules_max",
|
| 561 | params: config.portForwardMax
|
| 562 | });
|
| 563 | return;
|
| 564 | }
|
| 565 |
|
| 566 | if (target.checkExist()) {
|
| 567 | showAlert("rule_exist");
|
| 568 | return;
|
| 569 | }
|
| 570 |
|
| 571 | showLoading();
|
| 572 | var fwdParams = {};
|
| 573 | fwdParams.comment = target.comment();
|
| 574 | fwdParams.protocol = target.selectedMode();
|
| 575 | fwdParams.portEnd = target.portEnd();
|
| 576 | fwdParams.portStart = target.portStart();
|
| 577 | fwdParams.ipAddress = target.ipAddress();
|
| 578 | service.setPortForward(fwdParams, target.callback);
|
| 579 | }
|
| 580 | //情况添加规则输入
|
| 581 | function clear() {
|
| 582 | target.ipAddress('');
|
| 583 | target.portStart('');
|
| 584 | target.portEnd('');
|
| 585 | target.selectedMode('TCP&UDP');
|
| 586 | target.comment('');
|
| 587 | }
|
| 588 |
|
| 589 | //设定,新增,删除回调函数
|
| 590 | function callbackFunc(ret) {
|
| 591 | if (ret.result == "success") {
|
| 592 | clear();
|
| 593 | initialize(target);
|
| 594 | successOverlay();
|
| 595 | } else {
|
| 596 | errorOverlay();
|
| 597 | }
|
| 598 | }
|
| 599 |
|
| 600 | //检查新增规则是否已经存在
|
| 601 | function checkExistFunc() {
|
| 602 | var newRule = {
|
| 603 | ipAddress: target.ipAddress(),
|
| 604 | portRange: target.portStart() + ' - ' + target.portEnd(),
|
| 605 | protocol: transProtocolValue(target.selectedMode())
|
| 606 | };
|
| 607 |
|
| 608 | var oldRule;
|
| 609 | var fwdrules = target.rules();
|
| 610 | for (var ki = 0; ki < fwdrules.length; ki++) {
|
| 611 | oldRule = {
|
| 612 | ipAddress: fwdrules[ki].ipAddress,
|
| 613 | portRange: fwdrules[ki].portRange,
|
| 614 | protocol: fwdrules[ki].protocol
|
| 615 | };
|
| 616 |
|
| 617 | if (_.isEqual(newRule, oldRule)) {
|
| 618 | return true;
|
| 619 | }
|
| 620 | }
|
| 621 | return false;
|
| 622 | }
|
| 623 | }
|
| 624 |
|
| 625 | //获取port forward信息
|
| 626 |
|
| 627 | function getPortForward() {
|
| 628 | return service.getPortForward();
|
| 629 | }
|
| 630 |
|
| 631 | //初始化port forward view model
|
| 632 |
|
| 633 | function initialize(viewModel) {
|
| 634 | var vm;
|
| 635 | if (viewModel) {
|
| 636 | vm = viewModel;
|
| 637 | var fwdinfo = getPortForward();
|
| 638 | vm.gridTemplate.clearAllChecked();
|
| 639 | vm.gridTemplate.data(fwdinfo.portForwardRules);
|
| 640 | vm.rules(fwdinfo.portForwardRules);
|
| 641 | vm.portForwardEnable(fwdinfo.portForwardEnable);
|
| 642 | vm.oriPortForwardEnable(fwdinfo.portForwardEnable);
|
| 643 | refreshTableHeight();
|
| 644 | return;
|
| 645 | }
|
| 646 |
|
| 647 | vm = new PortForwardVM();
|
| 648 | bindContainer(vm);
|
| 649 |
|
| 650 | fixTableHeight();
|
| 651 | renderCheckbox();
|
| 652 |
|
| 653 | $('#virtualServerForm').validate({
|
| 654 | submitHandler: function () {
|
| 655 | vm.enableVirtualServer();
|
| 656 | }
|
| 657 | });
|
| 658 |
|
| 659 | $('#portForwardListForm').validate({
|
| 660 | submitHandler: function () {
|
| 661 | vm.deleteForwardRules();
|
| 662 | }
|
| 663 | });
|
| 664 |
|
| 665 | $('#portForwardForm').validate({
|
| 666 | submitHandler: function () {
|
| 667 | vm.save();
|
| 668 | },
|
| 669 | rules: {
|
| 670 | txtIpAddress: {
|
| 671 | ip_check: true
|
| 672 | },
|
| 673 | txtPortStart: {
|
| 674 | digits: true,
|
| 675 | range: [1, 65535],
|
| 676 | portCompare: "#txtPortEnd"
|
| 677 | },
|
| 678 | txtPortEnd: {
|
| 679 | digits: true,
|
| 680 | range: [1, 65535],
|
| 681 | portCompare: "#txtPortStart"
|
| 682 | },
|
| 683 | txtComment: {
|
| 684 | comment_check: true
|
| 685 | }
|
| 686 | },
|
| 687 | groups: {
|
| 688 | range: "txtPortStart txtPortEnd"
|
| 689 | },
|
| 690 | errorPlacement: function (error, element) {
|
| 691 | if (element.attr("name") == "txtIpAddress") {
|
| 692 | error.appendTo("#ipErrorDiv");
|
| 693 | } else if (element.attr("name") == "txtPortStart" || element.attr("name") == "txtPortEnd") {
|
| 694 | error.appendTo("#portRangeErrorDiv");
|
| 695 | } else
|
| 696 | error.insertAfter(element);
|
| 697 | }
|
| 698 | });
|
| 699 | }
|
| 700 |
|
| 701 | function bindContainer(vm){
|
| 702 | var container = $('#container');
|
| 703 | ko.cleanNode(container[0]);
|
| 704 | ko.applyBindings(vm, container[0]);
|
| 705 |
|
| 706 | }
|
| 707 |
|
| 708 |
|
| 709 | return {
|
| 710 | init: initialize
|
| 711 | };
|
| 712 | });
|
| 713 |
|
| 714 | define("firewall_port_filter","underscore jquery knockout set service".split(" "),
|
| 715 | function (_, $, ko, config, service) {
|
| 716 |
|
| 717 | var PROTOCOLS = {
|
| 718 | ICMP: 'ICMP',
|
| 719 | NONE: 'None'
|
| 720 | };
|
| 721 |
|
| 722 | var columnsTmpl = [{
|
| 723 | columnType: "checkbox",
|
| 724 | rowText: "index",
|
| 725 | width: "4%"
|
| 726 | }, {
|
| 727 | headerTextTrans: "mac_address",
|
| 728 | rowText: "macAddress",
|
| 729 | width: "12%"
|
| 730 | }, {
|
| 731 | headerTextTrans: "ip_type",
|
| 732 | rowText: "ipType",
|
| 733 | width: "5%",
|
| 734 | display: config.IPV6_SUPPORT
|
| 735 | }, {
|
| 736 | headerTextTrans: "source_ip_address",
|
| 737 | rowText: "sourceIpAddress",
|
| 738 | width: "12%"
|
| 739 | }, {
|
| 740 | headerTextTrans: "dest_ip_address",
|
| 741 | rowText: "destIpAddress",
|
| 742 | width: "12%"
|
| 743 | }, {
|
| 744 | headerTextTrans: "protocol",
|
| 745 | rowText: "protocol",
|
| 746 | width: "12%",
|
| 747 | needTrans: true
|
| 748 | }, {
|
| 749 | headerTextTrans: "source_port_range",
|
| 750 | rowText: "sourcePortRange",
|
| 751 | width: "12%"
|
| 752 | }, {
|
| 753 | headerTextTrans: "dest_port_range",
|
| 754 | rowText: "destPortRange",
|
| 755 | width: "12%"
|
| 756 | }, {
|
| 757 | headerTextTrans: "port_filter_action",
|
| 758 | rowText: "action",
|
| 759 | width: "12%",
|
| 760 | needTrans: true
|
| 761 | }, {
|
| 762 | headerTextTrans: "comment",
|
| 763 | rowText: "comment",
|
| 764 | width: "12%"
|
| 765 | }
|
| 766 | ];
|
| 767 |
|
| 768 | var protocolModes = _.map(config.FILTER_PROTOCOL_MODES, function (elem) {
|
| 769 | return new Option(elem.name, elem.value);
|
| 770 | });
|
| 771 | //prot_filter VM
|
| 772 |
|
| 773 | function PortFilterVM() {
|
| 774 | var target = this;
|
| 775 | var info = getPortFilter();
|
| 776 |
|
| 777 | target.oriDefaultPolicy = ko.observable(info.defaultPolicy);
|
| 778 | target.defaultPolicy = ko.observable(info.defaultPolicy);
|
| 779 | target.oriPortFilterEnable = ko.observable(info.portFilterEnable);
|
| 780 | target.portFilterEnable = ko.observable(info.portFilterEnable);
|
| 781 | target.rules = ko.observableArray(info.portFilterRules);
|
| 782 |
|
| 783 | target.ipv6Support = ko.observable(config.IPV6_SUPPORT);
|
| 784 | target.comment = ko.observable('');
|
| 785 | target.selectedMode = ko.observable('5');
|
| 786 | target.modes = ko.observableArray(protocolModes);
|
| 787 | target.sourcePortEnd = ko.observable('');
|
| 788 | target.sourcePortStart = ko.observable('');
|
| 789 | target.destPortEnd = ko.observable('');
|
| 790 | target.destPortStart = ko.observable('');
|
| 791 | target.destIpv6Address = ko.observable('');
|
| 792 | target.sourceIpv6Address = ko.observable('');
|
| 793 | target.sourceIpAddress = ko.observable('');
|
| 794 | target.destIpAddress = ko.observable('');
|
| 795 | target.macAddress = ko.observable('');
|
| 796 | target.portFilterAction = ko.observable('');
|
| 797 |
|
| 798 | target.ipType = ko.observable('ipv4');
|
| 799 |
|
| 800 | //设定,新增,删除回调函数
|
| 801 |
|
| 802 | target.callback = callbackFunc;
|
| 803 |
|
| 804 | //创建列表模板
|
| 805 |
|
| 806 | target.gridTemplate = new ko.simpleGrid.viewModel({
|
| 807 | data: target.rules(),
|
| 808 | idName: "index",
|
| 809 | columns: columnsTmpl,
|
| 810 | tmplType: 'list',
|
| 811 | pageSize: 20
|
| 812 | });
|
| 813 | //default policy change handler
|
| 814 |
|
| 815 | target.policyChangeHandler = policyChangeHandlerFunc;
|
| 816 |
|
| 817 | //保存规则
|
| 818 |
|
| 819 | target.save = saveFunc;
|
| 820 |
|
| 821 | //设定过滤基本信息
|
| 822 |
|
| 823 | target.setPortFilterBasic = setPortFilterBasicFunc;
|
| 824 |
|
| 825 | //清空添加规则输入
|
| 826 |
|
| 827 | target.clear = clearFunc;
|
| 828 |
|
| 829 | //检查新增规则是否已经存在
|
| 830 |
|
| 831 | target.checkExist = checkExistFunc;
|
| 832 |
|
| 833 | //ip类型变化事件监听
|
| 834 |
|
| 835 | target.ipTypeChangeHandler = ipTypeChangeHandlerFunc;
|
| 836 |
|
| 837 | //协议变化事件监听
|
| 838 |
|
| 839 | target.protocolChangeHandler = protocolChangeHandlerFunc;
|
| 840 |
|
| 841 | //删除规则
|
| 842 |
|
| 843 | target.deleteFilterRules = deleteFilterRulesFunc;
|
| 844 |
|
| 845 | //init to call
|
| 846 | target.policyChangeHandler();
|
| 847 |
|
| 848 | //设定,新增,删除回调函数
|
| 849 | function callbackFunc(ret) {
|
| 850 | if (ret.result != "success") {
|
| 851 | errorOverlay();
|
| 852 | } else {
|
| 853 | target.clear();
|
| 854 | initialize(target);
|
| 855 | successOverlay();
|
| 856 | }
|
| 857 | }
|
| 858 | //default policy change handler
|
| 859 | function policyChangeHandlerFunc() {
|
| 860 | var action = target.defaultPolicy() != "1" ? "Drop" : "Accept";
|
| 861 | target.portFilterAction(action);
|
| 862 | return true;
|
| 863 | }
|
| 864 |
|
| 865 | //保存规则
|
| 866 | function saveFunc() {
|
| 867 | target.sourceIpAddress(target.sourceIpAddress().replace(/\s+/g, ''));
|
| 868 | target.destIpAddress(target.destIpAddress().replace(/\s+/g, ''));
|
| 869 | target.sourceIpv6Address(target.sourceIpv6Address().replace(/\s+/g, ''));
|
| 870 | target.destIpv6Address(target.destIpv6Address().replace(/\s+/g, ''));
|
| 871 | target.macAddress(target.macAddress().replace(/\s+/g, ''));
|
| 872 | if (target.ipv6Support() == false) {
|
| 873 | if (target.rules().length >= config.portForwardMax) {
|
| 874 | showAlert({
|
| 875 | msg: "rules_max",
|
| 876 | params: config.portForwardMax
|
| 877 | });
|
| 878 | return;
|
| 879 | }
|
| 880 |
|
| 881 | if (target.checkExist()) {
|
| 882 | showAlert("rule_exist");
|
| 883 | return;
|
| 884 | }
|
| 885 |
|
| 886 | } else {
|
| 887 | var type = target.ipType() == "ipv4" ? "IPv4" : "IPv6";
|
| 888 | var oldRules = _.filter(target.rules(), function (item) {
|
| 889 | return item.ipType == type;
|
| 890 | });
|
| 891 |
|
| 892 | if (oldRules.length >= config.portForwardMax) {
|
| 893 | showAlert({
|
| 894 | msg: "rules_max_v4v6",
|
| 895 | params: [type, config.portForwardMax]
|
| 896 | });
|
| 897 | return;
|
| 898 | }
|
| 899 |
|
| 900 | if (target.checkExist()) {
|
| 901 | showAlert({
|
| 902 | msg: "rule_exist_v4v6",
|
| 903 | params: type
|
| 904 | });
|
| 905 | return;
|
| 906 | }
|
| 907 | }
|
| 908 | showConfirm("confirm_data_effect", function () {
|
| 909 | showLoading();
|
| 910 | var fltParams = {};
|
| 911 | fltParams.macAddress = target.macAddress();
|
| 912 |
|
| 913 | if (target.ipv6Support() && target.ipType() != 'ipv6') {
|
| 914 | fltParams.destIpAddress = target.destIpAddress();
|
| 915 | fltParams.sourceIpAddress = target.sourceIpAddress();
|
| 916 | } else {
|
| 917 | fltParams.destIpAddress = target.destIpv6Address();
|
| 918 | fltParams.sourceIpAddress = target.sourceIpv6Address();
|
| 919 | }
|
| 920 |
|
| 921 | fltParams.ipType = target.ipType();
|
| 922 | fltParams.comment = target.comment();
|
| 923 | fltParams.protocol = target.selectedMode();
|
| 924 | fltParams.action = target.portFilterAction();
|
| 925 | fltParams.sourcePortEnd = target.sourcePortEnd();
|
| 926 | fltParams.sourcePortStart = target.sourcePortStart();
|
| 927 | fltParams.destPortEnd = target.destPortEnd();
|
| 928 | fltParams.destPortStart = target.destPortStart();
|
| 929 | service.setPortFilter(fltParams, target.callback);
|
| 930 | });
|
| 931 | }
|
| 932 |
|
| 933 | //设定过滤基本信息
|
| 934 | function setPortFilterBasicFunc() {
|
| 935 | showLoading();
|
| 936 | var elems = {};
|
| 937 | elems.defaultPolicy = target.defaultPolicy();
|
| 938 | elems.portFilterEnable = target.portFilterEnable();
|
| 939 | service.setPortFilterBasic(elems, target.callback);
|
| 940 | }
|
| 941 | //清空添加规则输入
|
| 942 | function clearFunc() {
|
| 943 | target.comment('');
|
| 944 | target.selectedMode('None');
|
| 945 | target.sourcePortEnd('0');
|
| 946 | target.sourcePortStart('0');
|
| 947 | target.destPortEnd('0');
|
| 948 | target.destPortStart('0');
|
| 949 | target.sourceIpv6Address('');
|
| 950 | target.sourceIpAddress('');
|
| 951 | target.destIpv6Address('');
|
| 952 | target.destIpAddress('');
|
| 953 | target.macAddress('');
|
| 954 | clearValidateMsg();
|
| 955 | }
|
| 956 |
|
| 957 | //检查新增规则是否已经存在
|
| 958 | function checkExistFunc() {
|
| 959 | target.macAddress(target.macAddress().toUpperCase());
|
| 960 | var currIpType = target.ipType().toUpperCase();
|
| 961 | var newRule = {
|
| 962 | macAddress: target.macAddress(),
|
| 963 | destIpAddress: currIpType == "IPV4" ? target.destIpAddress() : target.destIpv6Address(),
|
| 964 | sourceIpAddress: currIpType == "IPV4" ? target.sourceIpAddress() : target.sourceIpv6Address(),
|
| 965 | destPortRange: target.destPortStart() == '0' ? '' : target.destPortStart() + ' - ' + target.destPortEnd(),
|
| 966 | sourcePortRange: target.sourcePortStart() == '0' ? '' : target.sourcePortStart() + ' - ' + target.sourcePortEnd(),
|
| 967 | action: target.portFilterAction() == "Drop" ? "filter_drop" : "filter_accept",
|
| 968 | protocol: transProtocolValue(target.selectedMode()),
|
| 969 | ipType: currIpType
|
| 970 | };
|
| 971 |
|
| 972 | var oldRule;
|
| 973 | var rules = target.rules();
|
| 974 | for (var ki = 0; ki < rules.length; ki++) {
|
| 975 | oldRule = {
|
| 976 | macAddress: rules[ki].macAddress,
|
| 977 | destIpAddress: rules[ki].destIpAddress,
|
| 978 | sourceIpAddress: rules[ki].sourceIpAddress,
|
| 979 | destPortRange: rules[ki].destPortRange,
|
| 980 | sourcePortRange: rules[ki].sourcePortRange,
|
| 981 | action: rules[ki].action,
|
| 982 | protocol: rules[ki].protocol,
|
| 983 | ipType: rules[ki].ipType.toUpperCase()
|
| 984 | };
|
| 985 |
|
| 986 | if (_.isEqual(newRule, oldRule)) {
|
| 987 | return true;
|
| 988 | }
|
| 989 | }
|
| 990 | return false;
|
| 991 | }
|
| 992 |
|
| 993 | //协议变化事件监听
|
| 994 | function protocolChangeHandlerFunc() {
|
| 995 | if (target.selectedMode() == PROTOCOLS.ICMP || target.selectedMode() == PROTOCOLS.NONE) {
|
| 996 | target.sourcePortEnd('0');
|
| 997 | target.sourcePortStart('0');
|
| 998 | target.destPortEnd('0');
|
| 999 | target.destPortStart('0');
|
| 1000 | clearValidateMsg('#portRangeArea');
|
| 1001 | } else {
|
| 1002 | target.sourcePortEnd('65535');
|
| 1003 | target.sourcePortStart('1');
|
| 1004 | target.destPortEnd('65535');
|
| 1005 | target.destPortStart('1');
|
| 1006 | }
|
| 1007 | return true;
|
| 1008 | }
|
| 1009 |
|
| 1010 | //删除规则
|
| 1011 | function deleteFilterRulesFunc() {
|
| 1012 | var ids = target.gridTemplate.selectedIds();
|
| 1013 | if (ids.length == 0) {
|
| 1014 | showAlert("no_data_selected");
|
| 1015 | return;
|
| 1016 | }
|
| 1017 |
|
| 1018 | showConfirm("confirm_data_effect", function () {
|
| 1019 | showLoading('deleting');
|
| 1020 | var rules = {};
|
| 1021 | rules.indexs = ids;
|
| 1022 | service.deleteFilterRules(rules, target.callback);
|
| 1023 | });
|
| 1024 | }
|
| 1025 |
|
| 1026 | }
|
| 1027 |
|
| 1028 | //获取port filter信息
|
| 1029 |
|
| 1030 | function getPortFilter() {
|
| 1031 | return service.getPortFilter();
|
| 1032 | }
|
| 1033 |
|
| 1034 | //ip类型变化事件监听
|
| 1035 | function ipTypeChangeHandlerFunc() {
|
| 1036 | clearValidateMsg();
|
| 1037 | return true;
|
| 1038 | }
|
| 1039 |
|
| 1040 | //初始化port filter view model
|
| 1041 |
|
| 1042 | function initialize(viewModel) {
|
| 1043 | var vm;
|
| 1044 | if (viewModel) {
|
| 1045 | vm = viewModel;
|
| 1046 | var fltinfo = getPortFilter();
|
| 1047 | vm.gridTemplate.clearAllChecked();
|
| 1048 | vm.gridTemplate.data(fltinfo.portFilterRules);
|
| 1049 | vm.defaultPolicy(fltinfo.defaultPolicy);
|
| 1050 | vm.oriDefaultPolicy(fltinfo.defaultPolicy);
|
| 1051 | vm.portFilterEnable(fltinfo.portFilterEnable);
|
| 1052 | vm.oriPortFilterEnable(fltinfo.portFilterEnable);
|
| 1053 | vm.rules(fltinfo.portFilterRules);
|
| 1054 | refreshTableHeight();
|
| 1055 | $('#portFilters').find('tbody').translate();
|
| 1056 | renderCheckbox();
|
| 1057 | $('.notes-content').translate();
|
| 1058 | return;
|
| 1059 | }
|
| 1060 |
|
| 1061 | vm = new PortFilterVM();
|
| 1062 | var container = $('#container');
|
| 1063 | ko.cleanNode(container[0]);
|
| 1064 | ko.applyBindings(vm, container[0]);
|
| 1065 |
|
| 1066 | fixTableHeight();
|
| 1067 |
|
| 1068 | $('#filterBasicForm').validate({
|
| 1069 | submitHandler: function () {
|
| 1070 | showConfirm("confirm_data_effect", function () {
|
| 1071 | vm.setPortFilterBasic();
|
| 1072 | });
|
| 1073 | }
|
| 1074 | });
|
| 1075 |
|
| 1076 | $('#portFilterListForm').validate({
|
| 1077 | submitHandler: function () {
|
| 1078 | vm.deleteFilterRules();
|
| 1079 | }
|
| 1080 | });
|
| 1081 |
|
| 1082 | $('#portFilterForm').validate({
|
| 1083 | submitHandler: function () {
|
| 1084 | vm.save();
|
| 1085 | },
|
| 1086 | rules: {
|
| 1087 | txtMacAddress: {
|
| 1088 | filter_optional: true,
|
| 1089 | mac_check: true
|
| 1090 | },
|
| 1091 | txtDestIpAddress: {
|
| 1092 | ip_check: true
|
| 1093 | },
|
| 1094 | txtSourceIpAddress: {
|
| 1095 | ip_check: true
|
| 1096 | },
|
| 1097 | txtSourceIpv6Address: {
|
| 1098 | ipv6: true
|
| 1099 | },
|
| 1100 | txtDestIpv6Address: {
|
| 1101 | ipv6: true
|
| 1102 | },
|
| 1103 | txtDestPortStart: {
|
| 1104 | digits: true,
|
| 1105 | range: [1, 65535],
|
| 1106 | portCompare: "#txtDestPortEnd"
|
| 1107 | },
|
| 1108 | txtDestPortEnd: {
|
| 1109 | digits: true,
|
| 1110 | range: [1, 65535],
|
| 1111 | portCompare: "#txtDestPortStart"
|
| 1112 | },
|
| 1113 | txtSourcePortStart: {
|
| 1114 | digits: true,
|
| 1115 | range: [1, 65535],
|
| 1116 | portCompare: "#txtSourcePortEnd"
|
| 1117 | },
|
| 1118 | txtSourcePortEnd: {
|
| 1119 | digits: true,
|
| 1120 | range: [1, 65535],
|
| 1121 | portCompare: "#txtSourcePortStart"
|
| 1122 | },
|
| 1123 |
|
| 1124 | txtComment: {
|
| 1125 | comment_check: true
|
| 1126 | }
|
| 1127 | },
|
| 1128 | groups: {
|
| 1129 | destPort: "txtDestPortStart txtDestPortEnd",
|
| 1130 | sourcePort: "txtSourcePortStart txtSourcePortEnd"
|
| 1131 | },
|
| 1132 | errorPlacement: function (error, element) {
|
| 1133 | if (element.attr("name") == "txtMacAddress") {
|
| 1134 | error.appendTo("#macErrorDiv");
|
| 1135 | } else if (element.attr("name") == "txtDestPortStart" || element.attr("name") == "txtDestPortEnd") {
|
| 1136 | error.appendTo("#destPortErrorDiv");
|
| 1137 | } else if (element.attr("name") == "txtSourcePortStart" || element.attr("name") == "txtSourcePortEnd") {
|
| 1138 | error.appendTo("#sourcePortErrorDiv");
|
| 1139 | } else
|
| 1140 | error.insertAfter(element);
|
| 1141 | }
|
| 1142 | });
|
| 1143 | }
|
| 1144 |
|
| 1145 | $.validator.addMethod("filter_optional", function (value, element, param) {
|
| 1146 | var result = _.any(['#txtMacAddress', '#txtDestIpAddress', '#txtSourceIpAddress', '#txtSourceIpv6Address', '#txtDestIpv6Address'],
|
| 1147 | function (item) {
|
| 1148 | var tmp = $(item).val().replace(/\s+/g, '');
|
| 1149 | return $(item + ':visible').length > 0 && tmp != '';
|
| 1150 | });
|
| 1151 |
|
| 1152 | var portResult = _.any(['#txtDestPortStart', '#txtDestPortEnd', '#txtSourcePortStart', '#txtSourcePortEnd'],
|
| 1153 | function (item) {
|
| 1154 | return $(item).val() != '0';
|
| 1155 | });
|
| 1156 |
|
| 1157 | return result || portResult;
|
| 1158 | });
|
| 1159 |
|
| 1160 | return {
|
| 1161 | init: initialize
|
| 1162 | };
|
| 1163 | });
|
| 1164 |
|
| 1165 | //家长控制
|
| 1166 |
|
| 1167 | define("firewall_parental_control","underscore jquery knockout set service".split(" "),
|
| 1168 | function (_, $, ko, config, service) {
|
| 1169 |
|
| 1170 | var maxItem = 10;
|
| 1171 | var pcVm = null;
|
| 1172 | var PAGES = {
|
| 1173 | MAIN: 0,
|
| 1174 | MANAGE: 1,
|
| 1175 | RULE: 2
|
| 1176 | };
|
| 1177 |
|
| 1178 |
|
| 1179 | function ParentalControlVM() {
|
| 1180 | var target = this;
|
| 1181 | var hostNameList = service.getHostNameList({}).devices;
|
| 1182 | target.currentPage = ko.observable(PAGES.MAIN);
|
| 1183 | target.pages = PAGES;
|
| 1184 |
|
| 1185 |
|
| 1186 | target.childGroupList = ko.observable([]);
|
| 1187 | target.childGroupMac = ko.computed(function () {
|
| 1188 | return _.map(target.childGroupList(), function (data) {
|
| 1189 | return data.mac;
|
| 1190 | });
|
| 1191 | });
|
| 1192 |
|
| 1193 | target.currentUserInChildGroup = ko.observable(true);
|
| 1194 | //获取儿童组设备列表
|
| 1195 |
|
| 1196 | target.fetchChildGroupList = fetchChildGroupListFunc;
|
| 1197 |
|
| 1198 | target.fetchChildGroupList();
|
| 1199 |
|
| 1200 | target.manageHandler = manageHandlerFunc;
|
| 1201 | function manageHandlerFunc() {
|
| 1202 | target.currentPage(PAGES.MANAGE);
|
| 1203 | target.fetchAttachedDevices();
|
| 1204 | }
|
| 1205 | target.attachedDevices = ko.observable([]);
|
| 1206 | //获取已连接设备列表
|
| 1207 |
|
| 1208 | target.fetchAttachedDevices = fetchAttachedDevicesFunc;
|
| 1209 |
|
| 1210 |
|
| 1211 | //儿童组设备 标签按钮事件
|
| 1212 |
|
| 1213 | target.backToMainHandler = backToMainHandlerFunc;
|
| 1214 |
|
| 1215 |
|
| 1216 | ko.computed(function () {
|
| 1217 | target.attachedDevices();
|
| 1218 | target.childGroupList();
|
| 1219 | $("#pc_children_group_form").translate();
|
| 1220 | }).extend({
|
| 1221 | notify: 'always',
|
| 1222 | throttle: 300
|
| 1223 | });
|
| 1224 |
|
| 1225 | //添加至儿童组
|
| 1226 |
|
| 1227 | function addChildGroupFun(flag, eleData) {
|
| 1228 | showLoading();
|
| 1229 | service.addChildGroup(eleData, function (data) {
|
| 1230 | target.fetchChildGroupList(function () {
|
| 1231 | target.fetchAttachedDevices(function () {
|
| 1232 | hideLoading();
|
| 1233 | if (flag) {
|
| 1234 | service.logout({}, function () {
|
| 1235 | window.location = 'index.html';
|
| 1236 | });
|
| 1237 | }
|
| 1238 | });
|
| 1239 | });
|
| 1240 | }, function (data) {
|
| 1241 | errorOverlay();
|
| 1242 | });
|
| 1243 | }
|
| 1244 |
|
| 1245 | //移除按钮事件
|
| 1246 |
|
| 1247 | target.removeChildGroupHandler = removeChildGroupHandlerFunc;
|
| 1248 |
|
| 1249 |
|
| 1250 | //添加按钮事件
|
| 1251 |
|
| 1252 | target.addChildGroupHandler = addChildGroupHandlerFunc;
|
| 1253 |
|
| 1254 |
|
| 1255 | target.dealElement = dealElementFunc;
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 | //取消编辑主机名按钮事件
|
| 1260 |
|
| 1261 | target.cancelEditHostNameHandler = cancelEditHostNameHandlerFunc;
|
| 1262 |
|
| 1263 | //主机名编辑保存按钮事件
|
| 1264 |
|
| 1265 | target.saveHostNameHandler = saveHostNameHandlerFunc;
|
| 1266 |
|
| 1267 | //主机名编辑按钮事件
|
| 1268 |
|
| 1269 | target.editHostNameHandler = editHostNameHandlerFunc;
|
| 1270 |
|
| 1271 |
|
| 1272 | target.selectedIds = ko.observableArray([]);
|
| 1273 | target.siteList = ko.observable([]);
|
| 1274 | /////////////////////////////////////////////////////////////////
|
| 1275 | target.disableAdd = ko.computed(function () {
|
| 1276 | return target.siteList().length == maxItem;
|
| 1277 | });
|
| 1278 |
|
| 1279 | ko.computed(function () {
|
| 1280 | target.siteList();
|
| 1281 | target.selectedIds();
|
| 1282 | setTimeout(function () {
|
| 1283 | renderCheckbox();
|
| 1284 | }, 100);
|
| 1285 | $("#pc_site_white_list_form").translate();
|
| 1286 | });
|
| 1287 |
|
| 1288 | //网站白名单添加按钮事件
|
| 1289 |
|
| 1290 | target.openAddSitePopoverHandler = openAddSitePopoverHandlerFunc;
|
| 1291 |
|
| 1292 | //网站白名单列表选择框点击事件
|
| 1293 |
|
| 1294 | target.checkboxClickHandler = checkboxClickHandlerFunc;
|
| 1295 |
|
| 1296 | //获取网站白名单列表
|
| 1297 |
|
| 1298 | target.fetchSiteWhiteList = fetchSiteWhiteListFunc;
|
| 1299 |
|
| 1300 | //网站白名单删除函数
|
| 1301 |
|
| 1302 | function removeSiteWhiteItem(ids) {
|
| 1303 | showConfirm('confirm_data_delete', function () {
|
| 1304 | showLoading();
|
| 1305 | service.removeSiteWhite({
|
| 1306 | ids: ids
|
| 1307 | }, function (data) {
|
| 1308 | target.fetchSiteWhiteList(function () {
|
| 1309 | successOverlay();
|
| 1310 | });
|
| 1311 | }, function (data) {
|
| 1312 | target.fetchSiteWhiteList(function () {
|
| 1313 | errorOverlay();
|
| 1314 | });
|
| 1315 | });
|
| 1316 | });
|
| 1317 | }
|
| 1318 | //网站白名单删除所有按钮事件
|
| 1319 |
|
| 1320 | target.removeAllWhiteSite = removeAllWhiteSiteFunc;
|
| 1321 |
|
| 1322 | //网站白名单删除按钮事件
|
| 1323 |
|
| 1324 | target.removeSelectedWhiteSite = removeSelectedWhiteSiteFunc;
|
| 1325 |
|
| 1326 | //网站白名单移除按钮事件
|
| 1327 |
|
| 1328 | target.removeWhiteSite = removeWhiteSiteFunc;
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 | //网站白名单添加框保存按钮事件
|
| 1333 |
|
| 1334 | target.saveSiteWhite = saveSiteWhiteFunc;
|
| 1335 |
|
| 1336 | //////////////////////////////////////////////////////////////////
|
| 1337 | target.notSave = ko.observable(false);
|
| 1338 | //获取时间限制信息
|
| 1339 |
|
| 1340 | target.fetchTimeLimited = fetchTimeLimitedFunc;
|
| 1341 |
|
| 1342 |
|
| 1343 | //上网时间设置时间表格事件绑定
|
| 1344 |
|
| 1345 | target.bindEvent = bindEventFunc;
|
| 1346 |
|
| 1347 | //上网时间设置保存按钮事件
|
| 1348 |
|
| 1349 | target.saveTimeLimitedHandler = saveTimeLimitedHandlerFunc;
|
| 1350 |
|
| 1351 | //////////////////////////////////////////////////////////////////
|
| 1352 | var isBinded = false;
|
| 1353 | //上网规则标签点击事件
|
| 1354 |
|
| 1355 | target.openRulePage = openRulePageFunc;
|
| 1356 | function openRulePageFunc() {
|
| 1357 | if (target.currentPage() == PAGES.RULE) {
|
| 1358 | return;
|
| 1359 | }
|
| 1360 | target.currentPage(PAGES.RULE);
|
| 1361 | target.currentUserInChildGroup(service.checkCurrentUserInChildGroup().result);
|
| 1362 | initTableData();
|
| 1363 | if (!isBinded) {
|
| 1364 | if (!target.currentUserInChildGroup()) {
|
| 1365 | target.bindEvent();
|
| 1366 | }
|
| 1367 | isBinded = true;
|
| 1368 | }
|
| 1369 | showLoading();
|
| 1370 | target.fetchTimeLimited();
|
| 1371 | target.fetchSiteWhiteList(function () {
|
| 1372 | hideLoading();
|
| 1373 | });
|
| 1374 | }
|
| 1375 |
|
| 1376 | //获取儿童组设备列表
|
| 1377 | function fetchChildGroupListFunc(cb) {
|
| 1378 | service.childGroupList({}, function (data) {
|
| 1379 | target.currentUserInChildGroup(service.checkCurrentUserInChildGroup(data.devices).result);
|
| 1380 | target.childGroupList([]);
|
| 1381 | _.map(data.devices, function (elem, idx) {
|
| 1382 | elem.idx = idx;
|
| 1383 | elem.hostname = pcUtil.getHostName(elem.hostname, elem.mac, hostNameList);
|
| 1384 | });
|
| 1385 | target.childGroupList(data.devices);
|
| 1386 | if (_.isFunction(cb)) {
|
| 1387 | cb.apply(this);
|
| 1388 | }
|
| 1389 | });
|
| 1390 | }
|
| 1391 |
|
| 1392 | //获取已连接设备列表
|
| 1393 | function fetchAttachedDevicesFunc(cb) {
|
| 1394 | target.attachedDevices([]);
|
| 1395 | var counter = 0;
|
| 1396 | var currDevices = [];
|
| 1397 | //RJ45 已连接设备
|
| 1398 | service.getAttachedCableDevices({}, function (data) {
|
| 1399 | counter++;
|
| 1400 | var devs = _.map(data.attachedDevices, function (elem) {
|
| 1401 | elem.idx = _.uniqueId('wireless_');
|
| 1402 | elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
|
| 1403 | elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
|
| 1404 | return elem;
|
| 1405 | });
|
| 1406 | if (counter != 1) {
|
| 1407 | target.attachedDevices(_.flatten([currDevices, devs]));
|
| 1408 | if (_.isFunction(cb)) {
|
| 1409 | cb.apply(this);
|
| 1410 | }
|
| 1411 | } else {
|
| 1412 | currDevices = devs;
|
| 1413 | }
|
| 1414 | });
|
| 1415 |
|
| 1416 | //wifi 已连接设备
|
| 1417 | service.getCurrentlyAttachedDevicesInfo({}, function (data) {
|
| 1418 | counter++;
|
| 1419 | var devs = _.map(data.attachedDevices, function (elem) {
|
| 1420 | elem.idx = _.uniqueId('wireless_');
|
| 1421 | elem.hostName = pcUtil.getHostName(elem.hostName, elem.macAddress, hostNameList);
|
| 1422 | elem.inChildGroup = _.contains(target.childGroupMac(), elem.macAddress);
|
| 1423 | return elem;
|
| 1424 | });
|
| 1425 | if (counter != 1) {
|
| 1426 | target.attachedDevices(_.flatten([currDevices, devs]));
|
| 1427 | if (_.isFunction(cb)) {
|
| 1428 | cb.apply(this);
|
| 1429 | }
|
| 1430 | } else {
|
| 1431 | currDevices = devs;
|
| 1432 | }
|
| 1433 | });
|
| 1434 | }
|
| 1435 | //儿童组设备 标签按钮事件
|
| 1436 | function backToMainHandlerFunc() {
|
| 1437 | target.currentPage(PAGES.MAIN);
|
| 1438 | }
|
| 1439 |
|
| 1440 | //移除按钮事件
|
| 1441 | function removeChildGroupHandlerFunc(ele) {
|
| 1442 | showLoading();
|
| 1443 | service.removeChildGroup(ele, function (data) {
|
| 1444 | target.fetchChildGroupList(function () {
|
| 1445 | target.fetchAttachedDevices(function () {
|
| 1446 | hideLoading();
|
| 1447 | });
|
| 1448 | });
|
| 1449 | }, function (data) {
|
| 1450 | errorOverlay();
|
| 1451 | });
|
| 1452 | }
|
| 1453 |
|
| 1454 | //添加按钮事件
|
| 1455 | function addChildGroupHandlerFunc(data) {
|
| 1456 | var uMacAddr = service.getCurretnMAC();
|
| 1457 | if (uMacAddr != data.macAddress) {
|
| 1458 | addChildGroupFun(false, data);
|
| 1459 | } else {
|
| 1460 | showConfirm("parental_add_self", function () {
|
| 1461 | addChildGroupFun(true, data);
|
| 1462 | })
|
| 1463 | }
|
| 1464 | }
|
| 1465 |
|
| 1466 | //取消编辑主机名按钮事件
|
| 1467 | function cancelEditHostNameHandlerFunc(eleData) {
|
| 1468 | target.dealElement(false, eleData.idx);
|
| 1469 | }
|
| 1470 |
|
| 1471 | //主机名编辑保存按钮事件
|
| 1472 | function saveHostNameHandlerFunc(ele) {
|
| 1473 | var $hostInput = $("#hostname_input_" + ele.idx);
|
| 1474 | var hostname = $.trim($hostInput.val());
|
| 1475 | if (hostname.indexOf(" ") == 0 || hostname.lastIndexOf(" ") == (hostname.length - 1) || /[\*\+\$\[&:,;<>'"\\`\]¥]{1,32}/.test(hostname)) {
|
| 1476 | showAlert('modify_hostname_invalid');
|
| 1477 | return false;
|
| 1478 | }else if (hostname == '') {
|
| 1479 | $(".promptErrorLabel", "#confirm-message-container").text($.i18n.prop("required"));
|
| 1480 | var $closestTD = $hostInput.closest('td').addClass('has-error');
|
| 1481 | addTimeout(function () {
|
| 1482 | $closestTD.removeClass('has-error');
|
| 1483 | }, 5000);
|
| 1484 | showAlert('required');
|
| 1485 | return false;
|
| 1486 | }
|
| 1487 | showLoading();
|
| 1488 | ele.hostname = hostname;
|
| 1489 | service.editHostName(ele, function () {
|
| 1490 | service.getHostNameList({}, function (hostNameData) {
|
| 1491 | hostNameList = hostNameData.devices;
|
| 1492 | target.fetchChildGroupList(function () {
|
| 1493 | hideLoading();
|
| 1494 | });
|
| 1495 | target.fetchAttachedDevices();
|
| 1496 | });
|
| 1497 | }, function () {
|
| 1498 | errorOverlay();
|
| 1499 | });
|
| 1500 | }
|
| 1501 |
|
| 1502 | //主机名编辑按钮事件
|
| 1503 | function editHostNameHandlerFunc(ele) {
|
| 1504 | $("#hostname_input_" + ele.idx).val(ele.hostname);
|
| 1505 | target.dealElement(true, ele.idx);
|
| 1506 | return false;
|
| 1507 | }
|
| 1508 | //网站白名单添加按钮事件
|
| 1509 | function openAddSitePopoverHandlerFunc() {
|
| 1510 | var addNewSiteTmpl = $("#addNewSiteTmpl").html();
|
| 1511 | popover.open({
|
| 1512 | target: $("#openAddSiteBtn"),
|
| 1513 | html: addNewSiteTmpl,
|
| 1514 | width: "300px",
|
| 1515 | validation: addValidation
|
| 1516 | });
|
| 1517 | }
|
| 1518 |
|
| 1519 | //网站白名单列表选择框点击事件
|
| 1520 | function checkboxClickHandlerFunc(eleData, evt) {
|
| 1521 | addTimeout(function () {
|
| 1522 | target.selectedIds(getSelectedValues());
|
| 1523 | }, 100);
|
| 1524 | }
|
| 1525 | //获取网站白名单列表
|
| 1526 | function fetchSiteWhiteListFunc(cb) {
|
| 1527 | service.getSiteWhiteList({}, function (eledata) {
|
| 1528 | target.selectedIds([]);
|
| 1529 | target.siteList(eledata.siteList);
|
| 1530 | _.isFunction(cb) && cb.apply(this);
|
| 1531 | }, function () {
|
| 1532 | target.siteList([]);
|
| 1533 | _.isFunction(cb) && cb.apply(this);
|
| 1534 | });
|
| 1535 | }
|
| 1536 |
|
| 1537 | //网站白名单删除所有按钮事件
|
| 1538 | function removeAllWhiteSiteFunc() {
|
| 1539 | removeSiteWhiteItem(getAllCheckboxValues());
|
| 1540 | }
|
| 1541 | //网站白名单删除按钮事件
|
| 1542 | function removeSelectedWhiteSiteFunc() {
|
| 1543 | removeSiteWhiteItem(getSelectedValues());
|
| 1544 | }
|
| 1545 | //网站白名单移除按钮事件
|
| 1546 | function removeWhiteSiteFunc(ele, evt) {
|
| 1547 | removeSiteWhiteItem([ele.id]);
|
| 1548 | }
|
| 1549 |
|
| 1550 | //网站白名单添加框保存按钮事件
|
| 1551 | function saveSiteWhiteFunc(name, site) {
|
| 1552 | popover.hide();
|
| 1553 | var matched = _.find(target.siteList(), function (one) {
|
| 1554 | return one.site == site;
|
| 1555 | });
|
| 1556 | if (matched) {
|
| 1557 | showAlert("pc_link_exist", function () {
|
| 1558 | setTimeout(function () {
|
| 1559 | popover.show();
|
| 1560 | }, 200);
|
| 1561 | });
|
| 1562 | return false;
|
| 1563 | }
|
| 1564 |
|
| 1565 | showLoading();
|
| 1566 | service.saveSiteWhite({
|
| 1567 | name: name,
|
| 1568 | site: site
|
| 1569 | }, function () {
|
| 1570 | target.fetchSiteWhiteList(function () {
|
| 1571 | popover.close();
|
| 1572 | successOverlay();
|
| 1573 | });
|
| 1574 | }, function () {
|
| 1575 | target.fetchSiteWhiteList(function () {
|
| 1576 | errorOverlay();
|
| 1577 | popover.show();
|
| 1578 | });
|
| 1579 | });
|
| 1580 | }
|
| 1581 |
|
| 1582 | //上网时间设置时间表格事件绑定
|
| 1583 | function bindEventFunc() {
|
| 1584 | $("td:not('.col-head')", "#pc_time_limited_tbody").addClass('cursorhand').die().click(function () {
|
| 1585 | target.notSave(true);
|
| 1586 | $(this).toggleClass('active');
|
| 1587 | }).hover(function () {
|
| 1588 | var $this = $(this);
|
| 1589 | var w = $this.data('week');
|
| 1590 | var h = $this.data('hour');
|
| 1591 | $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").addClass('time_td_hover');
|
| 1592 | $("#col_" + h).addClass('time_td_hover');
|
| 1593 | if ($this.not('.active')) {
|
| 1594 | $this.addClass('time_td_hover');
|
| 1595 | }
|
| 1596 | }, function () {
|
| 1597 | var $this = $(this);
|
| 1598 | var w = $this.data('week');
|
| 1599 | var h = $this.data('hour');
|
| 1600 | $("tr:nth-child(" + (w + 1) + ") td:first-child", "#pc_time_limited_tbody").removeClass('time_td_hover');
|
| 1601 | $("#col_" + h).removeClass('time_td_hover');
|
| 1602 | $this.removeClass('time_td_hover');
|
| 1603 | });
|
| 1604 | }
|
| 1605 |
|
| 1606 | //上网时间设置保存按钮事件
|
| 1607 | function saveTimeLimitedHandlerFunc() {
|
| 1608 | showLoading();
|
| 1609 | var tds = getSelectedTds();
|
| 1610 | var timeStr = getSavedData(tds);
|
| 1611 | service.saveTimeLimited({
|
| 1612 | time: timeStr
|
| 1613 | }, function () {
|
| 1614 | target.notSave(false);
|
| 1615 | successOverlay();
|
| 1616 | }, function () {
|
| 1617 | errorOverlay();
|
| 1618 | });
|
| 1619 | }
|
| 1620 |
|
| 1621 | }
|
| 1622 |
|
| 1623 | function dealElementFunc(flag, idx) {
|
| 1624 | if (flag == false) {
|
| 1625 | $("#edit_btn_" + idx + ",#hostname_txt_" + idx).show();
|
| 1626 | $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).hide();
|
| 1627 | } else {
|
| 1628 | $("#edit_btn_" + idx + ",#hostname_txt_" + idx).hide();
|
| 1629 | $("#save_btn_" + idx + ",#cancel_btn_" + idx + ",#hostname_input_" + idx).show();
|
| 1630 | }
|
| 1631 | }
|
| 1632 |
|
| 1633 | //获取时间限制信息
|
| 1634 | function fetchTimeLimitedFunc() {
|
| 1635 | service.getTimeLimited({}, function (ele) {
|
| 1636 | for (var ki in ele) {
|
| 1637 | for (var idx = 0; idx < ele[ki].length; idx++) {
|
| 1638 | var id = 'td_' + ki + '_' + ele[ki][idx];
|
| 1639 | $("#" + id).addClass('active');
|
| 1640 | }
|
| 1641 | }
|
| 1642 | }, function () {});
|
| 1643 | }
|
| 1644 |
|
| 1645 | var pcUtil = {
|
| 1646 | getHostName: function (hostName, mac, hostNameList) {
|
| 1647 | var ele = _.find(hostNameList, function (ele) {
|
| 1648 | return ele.mac == mac;
|
| 1649 | });
|
| 1650 | return ele ? ele.hostname : hostName;
|
| 1651 | }
|
| 1652 | };
|
| 1653 | function getCheckboxValues(flag) {
|
| 1654 | var selectedValues = [];
|
| 1655 | $(":checkbox" + (flag ? ":checked" : ""), "#pb_white_list").each(function (i, n) {
|
| 1656 | selectedValues.push(n.value)
|
| 1657 | });
|
| 1658 | return selectedValues;
|
| 1659 | }
|
| 1660 | //获取列表中被选中项的value值
|
| 1661 |
|
| 1662 | function getSelectedValues() {
|
| 1663 | return getCheckboxValues(true);
|
| 1664 | }
|
| 1665 | function getAllCheckboxValues() {
|
| 1666 | return getCheckboxValues(false);
|
| 1667 | }
|
| 1668 |
|
| 1669 | //增加网站白名单表单提交函数绑定和校验规则设置
|
| 1670 |
|
| 1671 | function addValidation() {
|
| 1672 | $('#whiteSiteAddForm').validate({
|
| 1673 | submitHandler: function () {
|
| 1674 | var name = $("#siteName").val();
|
| 1675 | var site = $("#siteLink").val();
|
| 1676 | pcVm.saveSiteWhite(name, site);
|
| 1677 | },
|
| 1678 | rules: {
|
| 1679 | siteName: 'siteName_check',
|
| 1680 | siteLink: 'siteLink_check'
|
| 1681 | }
|
| 1682 | });
|
| 1683 | }
|
| 1684 |
|
| 1685 | function getSavedData(timeDatas) {
|
| 1686 | var ret = '';
|
| 1687 | for (var ki in timeDatas) {
|
| 1688 | var hours = _.sortBy(timeDatas[ki], function (n) {
|
| 1689 | return n;
|
| 1690 | });
|
| 1691 | if (timeDatas[ki].length) {
|
| 1692 | ret += ki + '+';
|
| 1693 | ret += hours.join(',');
|
| 1694 | ret += ';'
|
| 1695 | }
|
| 1696 | }
|
| 1697 | return ret.substring(0, ret.length - 1);
|
| 1698 | }
|
| 1699 | //获取时间表格选中的时间
|
| 1700 |
|
| 1701 | function getSelectedTds() {
|
| 1702 | var defaultValue = {
|
| 1703 | '0': [],
|
| 1704 | '1': [],
|
| 1705 | '2': [],
|
| 1706 | '3': [],
|
| 1707 | '4': [],
|
| 1708 | '5': [],
|
| 1709 | '6': []
|
| 1710 | };
|
| 1711 | $("td.active", "#pc_time_limited_tbody").each(function (i, n) {
|
| 1712 | var $this = $(n);
|
| 1713 | var week = $this.data('week');
|
| 1714 | var hour = $this.data('hour');
|
| 1715 | defaultValue[week].push(hour);
|
| 1716 | });
|
| 1717 | return defaultValue;
|
| 1718 | }
|
| 1719 |
|
| 1720 | function convertHour(hour) {
|
| 1721 | if (hour <= 16) {
|
| 1722 | return hour + 7;
|
| 1723 | } else {
|
| 1724 | return hour - 17;
|
| 1725 | }
|
| 1726 | }
|
| 1727 | //初始化时间表格
|
| 1728 |
|
| 1729 | function initTableData() {
|
| 1730 | $("tr", "#pc_time_limited_tbody").each(function (idx, n) {
|
| 1731 | var $tr = $(n);
|
| 1732 | $("td:not(:first)", $tr).each(function (j, m) {
|
| 1733 | var $td = $(m);
|
| 1734 | var hour = convertHour(j);
|
| 1735 | $td.attr({
|
| 1736 | id: 'td_' + idx + '_' + hour
|
| 1737 | }).data({
|
| 1738 | week: idx,
|
| 1739 | hour: hour
|
| 1740 | });
|
| 1741 | });
|
| 1742 | });
|
| 1743 | $("td.active", "#pc_time_limited_tbody").removeClass("active");
|
| 1744 | $("thead td:not(:first)", "#pc_time_limited_form").each(function (idx, n) {
|
| 1745 | var hour = convertHour(idx);
|
| 1746 | $(n).attr({
|
| 1747 | id: 'col_' + hour
|
| 1748 | });
|
| 1749 | });
|
| 1750 | pcVm.notSave(false);
|
| 1751 | }
|
| 1752 |
|
| 1753 |
|
| 1754 | //页面初始化
|
| 1755 |
|
| 1756 | function initialize() {
|
| 1757 |
|
| 1758 | pcVm = new ParentalControlVM();
|
| 1759 | bindContainer(pcVm);
|
| 1760 | }
|
| 1761 | function bindContainer(pcVm)
|
| 1762 | {
|
| 1763 | var container = $('#container');
|
| 1764 | ko.cleanNode(container[0]);
|
| 1765 | ko.applyBindings(pcVm, container[0]);
|
| 1766 | }
|
| 1767 |
|
| 1768 | return {
|
| 1769 | init: initialize
|
| 1770 | };
|
| 1771 | });
|
| 1772 |
|
| 1773 | define("firewall_dmz_set","underscore jquery knockout set service".split(" "),
|
| 1774 | function ( _, $, ko, config, service) {
|
| 1775 |
|
| 1776 | //system dmz setting VM
|
| 1777 |
|
| 1778 | function DmzSettingVM() {
|
| 1779 | var target = this;
|
| 1780 | var dmzInfo = getDmzSetting();
|
| 1781 | target.dmzSetting = ko.observable(dmzInfo.dmzSetting);
|
| 1782 | target.ipAddress = ko.observable(dmzInfo.ipAddress);
|
| 1783 | target.isDataCard = config.PRODUCT_TYPE == 'DATACARD';
|
| 1784 |
|
| 1785 | target.clear = clearFunc;
|
| 1786 | //应用按钮事件
|
| 1787 |
|
| 1788 | target.save = saveFunc;
|
| 1789 |
|
| 1790 | function saveFunc() {
|
| 1791 | showLoading();
|
| 1792 | var params = {};
|
| 1793 | params.dmzSetting = target.dmzSetting();
|
| 1794 | params.ipAddress = target.ipAddress();
|
| 1795 | service.setDmzSetting(params, function (result) {
|
| 1796 | if (result.result != "success") {
|
| 1797 | errorOverlay();
|
| 1798 | } else {
|
| 1799 | target.clear();
|
| 1800 | successOverlay();
|
| 1801 | }
|
| 1802 | });
|
| 1803 | }
|
| 1804 |
|
| 1805 | }
|
| 1806 |
|
| 1807 | function clearFunc() {
|
| 1808 | initialize();
|
| 1809 | }
|
| 1810 |
|
| 1811 |
|
| 1812 | //获取dmz 信息
|
| 1813 |
|
| 1814 | function getDmzSetting() {
|
| 1815 | return service.getDmzSetting();
|
| 1816 | }
|
| 1817 |
|
| 1818 | //初始化DmzSettingVM model
|
| 1819 |
|
| 1820 | function initialize() {
|
| 1821 |
|
| 1822 | var dmzVm = new DmzSettingVM();
|
| 1823 | bindContainer(dmzVm);
|
| 1824 | }
|
| 1825 | function bindContainer(dmzVm){
|
| 1826 | var container = $('#container');
|
| 1827 | ko.cleanNode(container[0]);
|
| 1828 | ko.applyBindings(dmzVm, container[0]);
|
| 1829 | $('#dmzSettingForm').validate({
|
| 1830 | submitHandler: function () {
|
| 1831 | dmzVm.save();
|
| 1832 | },
|
| 1833 | rules: {
|
| 1834 | txtIpAddress: 'dmz_ip_check'
|
| 1835 | }
|
| 1836 | });
|
| 1837 | }
|
| 1838 |
|
| 1839 | return {
|
| 1840 | init: initialize
|
| 1841 | };
|
| 1842 | });
|
| 1843 |
|
| 1844 | define("firewall","underscore jquery knockout set service".split(" "),
|
| 1845 |
|
| 1846 | function(_, $, ko, config, service) {
|
| 1847 |
|
| 1848 | function FirewallVM() {
|
| 1849 | var target = this;
|
| 1850 | target.hasDdns = config.DDNS_SUPPORT;
|
| 1851 | target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
|
| 1852 | target.hasUrlFilter = config.HAS_URL;
|
| 1853 | target.hasUssd = config.HAS_USSD;
|
| 1854 | target.hasUpnp = config.HAS_UPNP;
|
| 1855 | }
|
| 1856 |
|
| 1857 | function initialize() {
|
| 1858 | var fwVm = new FirewallVM();
|
| 1859 | bindingContainer(fwVm);
|
| 1860 | }
|
| 1861 | function bindingContainer(fwVm)
|
| 1862 | {
|
| 1863 | var container = $('#container');
|
| 1864 | ko.cleanNode(container[0]);
|
| 1865 | ko.applyBindings(fwVm, container[0]);
|
| 1866 | }
|
| 1867 | return {
|
| 1868 | init : initialize
|
| 1869 | };
|
| 1870 | });
|
| 1871 |
|
| 1872 | define("ddns","underscore jquery knockout set service".split(" "), function (_, $, ko, config, service) {
|
| 1873 | var ddnsSetModes = _.map(config.DDNSSetMode, newOption);
|
| 1874 | var ddnsProviderList = _.map(config.DDNSDDP, newOption);
|
| 1875 | var ddns_mode_select = _.map(config.ddns_Modeselect, newOption);
|
| 1876 | function newOption(optItem) {
|
| 1877 | return new Option(optItem.name, optItem.value);
|
| 1878 | }
|
| 1879 | function DdnsViewModel() {
|
| 1880 | var target = this;
|
| 1881 | target.hasUssd = config.HAS_USSD;
|
| 1882 | target.hasUpdateCheck = config.HAS_UPDATE_CHECK;
|
| 1883 | var data = service.getDdnsParams();
|
| 1884 | target.ddnsSetModes = ko.observableArray(ddnsSetModes);
|
| 1885 | target.ddnsProviderList = ko.observableArray(ddnsProviderList);
|
| 1886 | target.ddns_mode_select = ko.observableArray(ddns_mode_select);
|
| 1887 | target.currentMode = ko.observable(data.DDNS_Enable);
|
| 1888 | target.currentModeselect = ko.observable(data.DDNS_Mode);
|
| 1889 | target.currentProviderList = ko.observable("dyndns.org");
|
| 1890 | $.each(config.DDNSDDP, function (i, n) {
|
| 1891 | if (data.DDNSProvider == n.value) {
|
| 1892 | target.currentProviderList(data.DDNSProvider);
|
| 1893 | }
|
| 1894 | });
|
| 1895 | target.DDNSaccount = ko.observable(data.DDNSAccount);
|
| 1896 | target.DDNSpasswd = ko.observable(data.DDNSPassword);
|
| 1897 | target.DDNSname = ko.observable(data.DDNS);
|
| 1898 | target.DDNS_HashValue = ko.observable(data.DDNS_Hash_Value);
|
| 1899 | target.isddnsStatusTrans = ko.observable();
|
| 1900 | target.isEnableSet = ko.observable();
|
| 1901 | target.isHashValue = ko.observable();
|
| 1902 | target.isddnsaccount = ko.observable();
|
| 1903 | target.isddnspasswd = ko.observable();
|
| 1904 | target.isDDNSStatus = ko.observable();
|
| 1905 | target.isddnsdomainName = ko.observable();
|
| 1906 | target.isNone = ko.observable();
|
| 1907 | target.onStates = ko.observable();
|
| 1908 | target.showPassword_ddns = ko.observable(false);
|
| 1909 | target.showPasswordHandler_ddns = showPasswordHandler_ddns;
|
| 1910 | changeddnsProviderList();
|
| 1911 | target.changeDdnsProvider = changeDdnsProviderFunc;
|
| 1912 | changeSetDdnsMode();
|
| 1913 | target.changeSetDdnsMode = changeSetDdnsModeFunc;
|
| 1914 | updateScanDdnsStatus();
|
| 1915 | target.apply = applyFunc;
|
| 1916 | function updateScanDdnsStatus() {
|
| 1917 | var trans = "";
|
| 1918 | $.getJSON("/reqproc/proc_get", {
|
| 1919 | cmd: "getddns_status",
|
| 1920 | "_": new Date().getTime()
|
| 1921 | }, function (data) {
|
| 1922 | if (data.getddns_status == "0") {
|
| 1923 | trans = "register successful";
|
| 1924 | target.onStates(true);
|
| 1925 | } else if (data.getddns_status == "1") {
|
| 1926 | trans = "login error";
|
| 1927 | target.onStates(true);
|
| 1928 | } else if (data.getddns_status == "2") {
|
| 1929 | trans = "network error";
|
| 1930 | target.onStates(true);
|
| 1931 | } else if (data.getddns_status == "3") {
|
| 1932 | trans = "registering";
|
| 1933 | target.onStates(true);
|
| 1934 | } else if (data.getddns_status == "4") {
|
| 1935 | trans = "not registered";
|
| 1936 | target.onStates(true);
|
| 1937 | } else if (data.getddns_status == "5") {
|
| 1938 | trans = "error registering";
|
| 1939 | target.onStates(true);
|
| 1940 | } else if (data.getddns_status == "-1") {
|
| 1941 | trans = "";
|
| 1942 | target.onStates(true);
|
| 1943 | }
|
| 1944 | target.isddnsStatusTrans($.i18n.prop(trans));
|
| 1945 | addTimeout(updateScanDdnsStatus, 2000);
|
| 1946 | });
|
| 1947 | }
|
| 1948 | function changeSetDdnsMode() {
|
| 1949 | if (target.currentMode() != "1") {
|
| 1950 | target.isEnableSet(false);
|
| 1951 | } else {
|
| 1952 | target.isEnableSet(true);
|
| 1953 | }
|
| 1954 | return true;
|
| 1955 | }
|
| 1956 | function changeSetDdnsModeFunc() {
|
| 1957 | changeSetDdnsMode();
|
| 1958 | }
|
| 1959 | function showPasswordHandler_ddns() {
|
| 1960 | $("#ddns_secretcode_input").parent().find(".error").hide();
|
| 1961 | var checkbox = $("#showPassword_ddns:checked");
|
| 1962 | if (checkbox && checkbox.length == 0) {
|
| 1963 | target.showPassword_ddns(true);
|
| 1964 | } else {
|
| 1965 | target.showPassword_ddns(false);
|
| 1966 | }
|
| 1967 | }
|
| 1968 | function changeDdnsProviderFunc() {
|
| 1969 | if (data.DDNSProvider != target.currentProviderList()) {
|
| 1970 | target.DDNSaccount("");
|
| 1971 | target.DDNSpasswd("");
|
| 1972 | target.DDNSname("");
|
| 1973 | } else {
|
| 1974 | target.DDNSaccount(data.DDNSAccount);
|
| 1975 | target.DDNSpasswd(data.DDNSPassword);
|
| 1976 | target.DDNSname(data.DDNS);
|
| 1977 | }
|
| 1978 | changeddnsProviderList();
|
| 1979 | }
|
| 1980 | function changeddnsProviderList() {
|
| 1981 | if (target.currentProviderList() != "none") {
|
| 1982 | target.isddnsaccount(true);
|
| 1983 | target.isddnspasswd(true);
|
| 1984 | target.isddnsdomainName(true);
|
| 1985 | target.isHashValue(true);
|
| 1986 | target.isDDNSStatus(true);
|
| 1987 | } else {
|
| 1988 | target.isddnsaccount(false);
|
| 1989 | target.isddnspasswd(false);
|
| 1990 | target.isddnsdomainName(false);
|
| 1991 | target.isHashValue(false);
|
| 1992 | target.isDDNSStatus(false);
|
| 1993 | }
|
| 1994 | if (target.currentProviderList() != "freedns.afraid.org") {
|
| 1995 | target.isHashValue(false);
|
| 1996 | } else {
|
| 1997 | target.isHashValue(true);
|
| 1998 | }
|
| 1999 | return true;
|
| 2000 | }
|
| 2001 | function applyFunc() {
|
| 2002 | showLoading();
|
| 2003 | var params = {};
|
| 2004 | params.goformId = "DDNS";
|
| 2005 | params.DDNS_Enable = target.currentMode();
|
| 2006 | if (target.currentMode() == "1") {
|
| 2007 | params.DDNS_Mode = target.currentModeselect();
|
| 2008 | params.DDNSProvider = target.currentProviderList();
|
| 2009 | if (target.currentProviderList() != "none") {
|
| 2010 | params.DDNS = target.DDNSname();
|
| 2011 | params.DDNSPassword = target.DDNSpasswd();
|
| 2012 | params.DDNSAccount = target.DDNSaccount();
|
| 2013 | }
|
| 2014 | if (target.currentProviderList() == "freedns.afraid.org") {
|
| 2015 | params.DDNS_Hash_Value = target.DDNS_HashValue();
|
| 2016 | }
|
| 2017 | }
|
| 2018 | service.setDDNSForward(params, function (result) {
|
| 2019 | if (result.result == "success") {
|
| 2020 | successOverlay();
|
| 2021 | data = service.getDdnsParams();
|
| 2022 | } else {
|
| 2023 | errorOverlay();
|
| 2024 | }
|
| 2025 | });
|
| 2026 | }
|
| 2027 | }
|
| 2028 | function initialize() {
|
| 2029 | var container = $('#container');
|
| 2030 | ko.cleanNode(container[0]);
|
| 2031 | var vm = new DdnsViewModel();
|
| 2032 | ko.applyBindings(vm, container[0]);
|
| 2033 | $("#ddnsForm").validate({
|
| 2034 | submitHandler: function () {
|
| 2035 | vm.apply();
|
| 2036 | },
|
| 2037 | rules: {
|
| 2038 | ddns_secretcode_input: "secretcode_check",
|
| 2039 | DDNS_Hash_Value: "ddns_hashvalue_check",
|
| 2040 | ddns_secretcode_inputshow: "secretcode_check"
|
| 2041 | },
|
| 2042 | errorPlacement: function (error, element) {
|
| 2043 | var id = element.attr("id");
|
| 2044 | if (id == "ddns_secretcode_input" || id == "ddns_secretcode_inputshow") {
|
| 2045 | error.insertAfter("#lblShowPassword");
|
| 2046 | } else {
|
| 2047 | error.insertAfter(element);
|
| 2048 | }
|
| 2049 | }
|
| 2050 | });
|
| 2051 | }
|
| 2052 | return {
|
| 2053 | init: initialize
|
| 2054 | };
|
| 2055 | });
|
| 2056 |
|
| 2057 |
|
| 2058 | //选网模块
|
| 2059 |
|
| 2060 | define("network_net_select","underscore jquery knockout set service".split(" "),
|
| 2061 | function (_, $, ko, config, service) {
|
| 2062 |
|
| 2063 | var selectModes = _.map(config.AUTO_MODES, function (item) {
|
| 2064 | return new Option(item.name, item.value);
|
| 2065 | });
|
| 2066 |
|
| 2067 | //选网功能view model
|
| 2068 |
|
| 2069 | function NetSelectVM() {
|
| 2070 | var target = this;
|
| 2071 |
|
| 2072 | target.networkList = ko.observableArray([]);
|
| 2073 | target.selectNetwork = ko.observable('');
|
| 2074 | target.enableFlag = ko.observable(true);
|
| 2075 | target.types = ko.observableArray(selectModes);
|
| 2076 | target.selectedType = ko.observable();
|
| 2077 | target.selectMode = ko.observable();
|
| 2078 |
|
| 2079 | target.networkText = networkTextFunc;
|
| 2080 |
|
| 2081 | target.networkStatusId = networkStatusIdFunc;
|
| 2082 |
|
| 2083 | target.networkStatus = networkStatusFunc;
|
| 2084 |
|
| 2085 | target.subnetworkType = subnetworkTypeFunc;
|
| 2086 |
|
| 2087 | target.networkType = networkTypeFunc;
|
| 2088 |
|
| 2089 | target.operatorName = operatorNameFunc;
|
| 2090 |
|
| 2091 | target.networkValue = networkValueFunc;
|
| 2092 |
|
| 2093 | target.networkTypeId = networkTypeIdFunc;
|
| 2094 |
|
| 2095 | target.subnetTypeId = subnetTypeIdFunc;
|
| 2096 | //手动搜网.
|
| 2097 |
|
| 2098 | target.search = searchFunc;
|
| 2099 |
|
| 2100 | //自动选网时设置网络模式.
|
| 2101 |
|
| 2102 | target.save = saveFunc;
|
| 2103 |
|
| 2104 | target.checkEnable = checkEnableFunc;
|
| 2105 |
|
| 2106 | //注册选择的网络.
|
| 2107 |
|
| 2108 | target.register = registerFunc;
|
| 2109 |
|
| 2110 | //init data
|
| 2111 | target.checkEnable();
|
| 2112 | var info = getNetSelectInfo();
|
| 2113 | if ("manual_select" == info.net_select_mode || "manual_select" == info.m_netselect_save) {
|
| 2114 | target.selectMode("manual_select");
|
| 2115 | } else {
|
| 2116 | target.selectMode("auto_select");
|
| 2117 | }
|
| 2118 |
|
| 2119 | target.selectedType(info.net_select);
|
| 2120 |
|
| 2121 | //注册选择的网络.
|
| 2122 | function registerFunc() {
|
| 2123 | showLoading('registering_net');
|
| 2124 | var networkToSet = target.selectNetwork().split(',');
|
| 2125 | service.setNetwork(networkToSet[0], parseInt(networkToSet[1]), parseInt(networkToSet[2]), function (result) {
|
| 2126 | if (result) {
|
| 2127 | target.networkList([]);
|
| 2128 | var autoType = getNetSelectInfo();
|
| 2129 | target.selectedType(autoType.net_select);
|
| 2130 | successOverlay();
|
| 2131 | } else {
|
| 2132 | errorOverlay();
|
| 2133 | }
|
| 2134 | });
|
| 2135 | }
|
| 2136 |
|
| 2137 | function checkEnableFunc() {
|
| 2138 | var status = service.getStatusInfo();
|
| 2139 | if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
|
| 2140 | target.enableFlag(false);
|
| 2141 | } else {
|
| 2142 | target.enableFlag(true);
|
| 2143 | }
|
| 2144 | }
|
| 2145 |
|
| 2146 | //自动选网时设置网络模式.
|
| 2147 | function saveFunc() {
|
| 2148 | showLoading();
|
| 2149 |
|
| 2150 | //AutoSelect call SetBearerPreference
|
| 2151 | var params = {};
|
| 2152 | params.strBearerPreference = target.selectedType();
|
| 2153 | service.setBearerPreference(params, function (result) {
|
| 2154 | if (result.result == "success") {
|
| 2155 | target.networkList([]);
|
| 2156 | successOverlay();
|
| 2157 | } else {
|
| 2158 | errorOverlay();
|
| 2159 | }
|
| 2160 | });
|
| 2161 | }
|
| 2162 |
|
| 2163 | //手动搜网.
|
| 2164 | function searchFunc() {
|
| 2165 | showLoading('searching_net');
|
| 2166 | service.scanForNetwork(function (result, networkList) {
|
| 2167 | hideLoading();
|
| 2168 | if (result) {
|
| 2169 | target.networkList(networkList);
|
| 2170 | for (var i = 0; i < networkList.length; i++) {
|
| 2171 | var n = networkList[i];
|
| 2172 | if (n.nState == '2') {
|
| 2173 | target.selectNetwork(n.strNumeric + ',' + n.nRat + ',' + n.SubAct);
|
| 2174 | return;
|
| 2175 | }
|
| 2176 | }
|
| 2177 | } else {
|
| 2178 | target.networkList([]);
|
| 2179 | }
|
| 2180 | });
|
| 2181 | }
|
| 2182 |
|
| 2183 | function subnetTypeIdFunc(data) {
|
| 2184 | return getSubNetworkTypeTog(data.nRat, data.SubAct);
|
| 2185 | }
|
| 2186 |
|
| 2187 | function networkTypeIdFunc(data) {
|
| 2188 | return getNetworkType(data.nRat);
|
| 2189 | }
|
| 2190 |
|
| 2191 | function networkValueFunc(data) {
|
| 2192 | var result = [];
|
| 2193 | result.push(data.strNumeric); //strNumeric
|
| 2194 | result.push(data.nRat); //nRat
|
| 2195 | result.push(data.SubAct);
|
| 2196 | return result.join(',');
|
| 2197 | }
|
| 2198 |
|
| 2199 | function operatorNameFunc(data) {
|
| 2200 | return data.strShortName;
|
| 2201 | }
|
| 2202 |
|
| 2203 | function networkTypeFunc(data) {
|
| 2204 | var result = getNetworkType(data.nRat);
|
| 2205 | if (result == "auto")
|
| 2206 | result = $.i18n.prop("auto");
|
| 2207 | return result;
|
| 2208 | }
|
| 2209 |
|
| 2210 | function subnetworkTypeFunc(data) {
|
| 2211 | var result = getSubNetworkTypeTog(data.nRat, data.SubAct);
|
| 2212 | return result;
|
| 2213 | }
|
| 2214 |
|
| 2215 | function networkStatusFunc(data) {
|
| 2216 | return $.i18n.prop(getNetworkStatusTog(data.nState));
|
| 2217 | }
|
| 2218 |
|
| 2219 | function networkStatusIdFunc(data) {
|
| 2220 | return getNetworkStatusTog(data.nState);
|
| 2221 | }
|
| 2222 |
|
| 2223 | function networkTextFunc(data) {
|
| 2224 | return data.strNumeric;
|
| 2225 | }
|
| 2226 |
|
| 2227 | }
|
| 2228 |
|
| 2229 | //获取网络选择信息.
|
| 2230 |
|
| 2231 | function getNetSelectInfo() {
|
| 2232 | return service.getNetSelectInfo();
|
| 2233 | }
|
| 2234 |
|
| 2235 | //搜网结果中的状态转换为对应的语言项.
|
| 2236 |
|
| 2237 | function getNetworkStatusTog(status) {
|
| 2238 | if ("3" == status) {
|
| 2239 | return "forbidden";
|
| 2240 | } else if ("2" == status) {
|
| 2241 | return "current";
|
| 2242 | } else if ("1" == status) {
|
| 2243 | return "available";
|
| 2244 | }else if ("0" == status) {
|
| 2245 | return "unknown";
|
| 2246 | }
|
| 2247 | }
|
| 2248 | //子网络类型转换.
|
| 2249 |
|
| 2250 | function getSubNetworkTypeTog(type, subtype) {
|
| 2251 | var type_3g = [2, 4, 5, 6, 8];
|
| 2252 | if ("1" == subtype) {
|
| 2253 | if ("7" == type) {
|
| 2254 | subtype = "FDD-LTE";
|
| 2255 | } else if ($.inArray(type, type_3g) != -1) {
|
| 2256 | subtype = "WCDMA";
|
| 2257 | }else {
|
| 2258 | subtype = "GSM";
|
| 2259 | }
|
| 2260 | } else if ("0" == subtype) {
|
| 2261 | if ("7" == type) {
|
| 2262 | subtype = "TD-LTE";
|
| 2263 | } else if ($.inArray(type, type_3g) != -1) {
|
| 2264 | subtype = "TD-SCDMA";
|
| 2265 | } else {
|
| 2266 | subtype = "GSM";
|
| 2267 | }
|
| 2268 | } else {
|
| 2269 | subtype = "";
|
| 2270 | }
|
| 2271 | return subtype;
|
| 2272 | }
|
| 2273 | //网络类型转换.
|
| 2274 |
|
| 2275 | function getNetworkType(type) {
|
| 2276 | if ("7" == type) {
|
| 2277 | return "4G";
|
| 2278 | } else if ("2" == type) {
|
| 2279 | return "3G";
|
| 2280 | } else if ("0" == type) {
|
| 2281 | return "2G";
|
| 2282 | } else {
|
| 2283 | return "auto";
|
| 2284 | }
|
| 2285 | }
|
| 2286 |
|
| 2287 | function bindContainer(vm){
|
| 2288 |
|
| 2289 | var container = $('#container');
|
| 2290 | ko.cleanNode(container[0]);
|
| 2291 | ko.applyBindings(vm, container[0]);
|
| 2292 | }
|
| 2293 |
|
| 2294 | //初始化选网功能view model.
|
| 2295 |
|
| 2296 | function initialize() {
|
| 2297 | var vm = new NetSelectVM();
|
| 2298 | bindContainer(vm);
|
| 2299 | addInterval(vm.checkEnable, 1000);
|
| 2300 | }
|
| 2301 |
|
| 2302 | return {
|
| 2303 | init: initialize
|
| 2304 | };
|
| 2305 | });
|
| 2306 | define("locknet","jquery knockout service jquery set main".split(" "),
|
| 2307 | function ($, ko, service, config, home) {
|
| 2308 |
|
| 2309 | function initialize() {
|
| 2310 | var container = $('#container')[0];
|
| 2311 | ko.cleanNode(container);
|
| 2312 | var vm = new locknetViewMode();
|
| 2313 | ko.applyBindings(vm, container);
|
| 2314 |
|
| 2315 | $("#frmNetworkLock").validate({
|
| 2316 | submitHandler: function () {
|
| 2317 | vm.unlock();
|
| 2318 | },
|
| 2319 | rules: {
|
| 2320 | txtLockNumber: "unlock_code_check"
|
| 2321 | }
|
| 2322 | });
|
| 2323 | }
|
| 2324 |
|
| 2325 | function locknetViewMode() {
|
| 2326 | var target = this;
|
| 2327 | var curCableMode = false;
|
| 2328 | target.isCPE = config.PRODUCT_TYPE == 'CPE';
|
| 2329 | target.hasRj45 = config.RJ45_SUPPORT;
|
| 2330 | target.hasSms = config.HAS_SMS;
|
| 2331 | target.hasPhonebook = config.HAS_PHONEBOOK;
|
| 2332 | target.isSupportSD = config.SD_CARD_SUPPORT;
|
| 2333 | if (config.WIFI_SUPPORT_QR_SWITCH == false) {
|
| 2334 | target.showQRCode = config.WIFI_SUPPORT_QR_CODE;
|
| 2335 | } else {
|
| 2336 | var wifiInfo = service.getWifiBasic();
|
| 2337 | target.showQRCode = config.WIFI_SUPPORT_QR_CODE && wifiInfo.show_qrcode_flag;
|
| 2338 | }
|
| 2339 | if(config.WIFI_SUPPORT_QR_CODE){
|
| 2340 | target.qrcodeSrc = './pic/qrcode_ssid_wifikey.png?_=' + $.now();
|
| 2341 | } else {
|
| 2342 | target.qrcodeSrc = './pic/res_blacktrans.png';
|
| 2343 | }
|
| 2344 | target.hasParentalControl = ko.observable(config.HAS_PARENTAL_CONTROL && curCableMode);
|
| 2345 | target.deviceInfo = ko.observable([]);
|
| 2346 | target.isHomePage = ko.observable(false);
|
| 2347 | if (window.location.hash == "#main") {
|
| 2348 | target.isHomePage(true);
|
| 2349 | }
|
| 2350 |
|
| 2351 | target.supportUnlock = config.NETWORK_UNLOCK_SUPPORT;
|
| 2352 | target.unlockCode = ko.observable();
|
| 2353 |
|
| 2354 | var info = service.getNetworkUnlockTimes();
|
| 2355 | target.times = ko.observable(info.unlock_nck_time);
|
| 2356 |
|
| 2357 | //显示工作模式设置窗口
|
| 2358 | target.showOpModeWindow = showOpModeWindowFunc;
|
| 2359 |
|
| 2360 | target.isLoggedIn = ko.observable(false);
|
| 2361 | target.enableFlag = ko.observable(false);
|
| 2362 | //解锁
|
| 2363 | target.unlock = unlockFunc;
|
| 2364 |
|
| 2365 | //更新工作模式状态
|
| 2366 | target.refreshOpmodeInfo = refreshOpmodeInfoFunc;
|
| 2367 |
|
| 2368 | //定时检查工作模式状态
|
| 2369 | if (target.hasRj45) {
|
| 2370 | target.refreshOpmodeInfo();
|
| 2371 | addInterval(function () {
|
| 2372 | target.refreshOpmodeInfo();
|
| 2373 | }, 1000);
|
| 2374 | }
|
| 2375 |
|
| 2376 | //更新工作模式状态
|
| 2377 | function refreshOpmodeInfoFunc() {
|
| 2378 | var obj = service.getStatusInfo();
|
| 2379 | target.isLoggedIn(obj.isLoggedIn);
|
| 2380 |
|
| 2381 | if (!curCableMode && checkCableMode(obj.blc_wan_mode)) { //如果有线,则重新加载
|
| 2382 | window.location.reload();
|
| 2383 | return;
|
| 2384 | }
|
| 2385 |
|
| 2386 | curCableMode = checkCableMode(obj.blc_wan_mode);
|
| 2387 | target.hasParentalControl(config.HAS_PARENTAL_CONTROL && curCableMode);
|
| 2388 | if (curCableMode && obj.ethWanMode.toUpperCase() == "DHCP") {
|
| 2389 | target.enableFlag(true);
|
| 2390 | } else if ((!curCableMode && obj.connectStatus != "ppp_disconnected") || (curCableMode && obj.rj45ConnectStatus != "idle" && obj.rj45ConnectStatus != "dead")) {
|
| 2391 | target.enableFlag(false);
|
| 2392 | } else {
|
| 2393 | target.enableFlag(true);
|
| 2394 | }
|
| 2395 | var getMode = (obj.blc_wan_mode == "AUTO_PPP" || obj.blc_wan_mode == "AUTO_PPPOE") ? "AUTO" : obj.blc_wan_mode;
|
| 2396 | var currMode = "";
|
| 2397 | switch (getMode) {
|
| 2398 | case "PPP":
|
| 2399 | currMode = "opmode_gateway";
|
| 2400 | break;
|
| 2401 | case "PPPOE":
|
| 2402 | currMode = "opmode_cable";
|
| 2403 | break;
|
| 2404 | case "AUTO":
|
| 2405 | currMode = "opmode_auto";
|
| 2406 | break;
|
| 2407 | default:
|
| 2408 | break;
|
| 2409 | }
|
| 2410 | $("#opmode").attr("data-trans", currMode).text($.i18n.prop(currMode));
|
| 2411 | }
|
| 2412 |
|
| 2413 | //解锁
|
| 2414 | function unlockFunc() {
|
| 2415 | showLoading();
|
| 2416 | service.unlockNetwork({
|
| 2417 | unlock_network_code: target.unlockCode()
|
| 2418 | }, function (data) {
|
| 2419 | target.unlockCode("");
|
| 2420 | if (data && data.result == "success") {
|
| 2421 | successOverlay();
|
| 2422 | if (window.location.hash == "#main") {
|
| 2423 | setTimeout(function () {
|
| 2424 | window.location.reload();
|
| 2425 | }, 500);
|
| 2426 | } else {
|
| 2427 | window.location.hash = "#main";
|
| 2428 | }
|
| 2429 | } else {
|
| 2430 | var info = service.getNetworkUnlockTimes();
|
| 2431 | target.times(info.unlock_nck_time);
|
| 2432 | errorOverlay();
|
| 2433 | }
|
| 2434 | })
|
| 2435 | }
|
| 2436 |
|
| 2437 | //显示工作模式设置窗口
|
| 2438 | function showOpModeWindowFunc() {
|
| 2439 | showSettingWindow("change_mode", "opmode_popup", "opmode_popup", 400, 300, function () {});
|
| 2440 | }
|
| 2441 | }
|
| 2442 |
|
| 2443 | return {
|
| 2444 | init: initialize
|
| 2445 | };
|
| 2446 | });
|
| 2447 |
|
| 2448 | // RJ45联网设置模块
|
| 2449 |
|
| 2450 | define("network_dial_set_cpe","underscore jquery knockout set service".split(" "),
|
| 2451 | function(_, $, ko, config, service) {
|
| 2452 | var dialActions = _.map(config.dialActions, function(elem){
|
| 2453 | return new Option(elem.name, elem.value);
|
| 2454 | });
|
| 2455 |
|
| 2456 | var dialModes = _.map(config.pppoeModes, function(elem) {
|
| 2457 | return new Option(elem.name, elem.value);
|
| 2458 | });
|
| 2459 |
|
| 2460 | var checkStatusTimer = 0;
|
| 2461 | var checkConCounter = 0;
|
| 2462 | var timeoutTipShowed = false;
|
| 2463 |
|
| 2464 | // 联网设置view model.
|
| 2465 |
|
| 2466 | function PPPoEViewModel() {
|
| 2467 | var pppObj = service.getPppoeParams();
|
| 2468 | var ethParams = pppObj;
|
| 2469 | var target = this;
|
| 2470 |
|
| 2471 | target.staticNoticeShow = ko.observable();
|
| 2472 | target.dhcpNoticeShow = ko.observable();
|
| 2473 | target.pppoeNoticeShow = ko.observable();
|
| 2474 | target.autoNoticeShow = ko.observable();
|
| 2475 | target.staticNotice = ko.observable();
|
| 2476 | target.dhcpNotice = ko.observable();
|
| 2477 | target.pppoeNotice = ko.observable();
|
| 2478 | target.autoNotice = ko.observable();
|
| 2479 | target.dhcpNoticeText = ko.observable();
|
| 2480 | target.staticNoticeText = ko.observable();
|
| 2481 | target.pppoeNoticeText = ko.observable();
|
| 2482 | target.autoNoticeText = ko.observable();
|
| 2483 | target.currentMode = ko.observable(pppObj.ethwan_mode);//auto dhcp pppoe static
|
| 2484 | target.showPassword = ko.observable(false);
|
| 2485 | target.modes = ko.observableArray(dialModes);
|
| 2486 | target.isPppoeMode = ko.observable(false);
|
| 2487 | target.isStaticMode = ko.observable(false);
|
| 2488 | target.isAutoMode = ko.observable(false);
|
| 2489 | target.action = ko.observable();
|
| 2490 | target.btnTrans = ko.observable();
|
| 2491 | target.enableFlag = ko.observable();
|
| 2492 | target.isShowDisbtn = ko.observable();
|
| 2493 | target.isShowCancelbtn = ko.observable();
|
| 2494 |
|
| 2495 | if(pppObj.rj45_state == "dead"){
|
| 2496 | checkRj45DeadTip();
|
| 2497 | } else if(pppObj.rj45_state == "connect"){
|
| 2498 | timeoutTipShowed = true;
|
| 2499 | setRj45CheckTimer("connect");
|
| 2500 | } else if(pppObj.rj45_state == "working"){
|
| 2501 | setRj45WorkingTip();
|
| 2502 | }
|
| 2503 |
|
| 2504 | target.user = ko.observable(pppObj.pppoe_username);
|
| 2505 | target.password = ko.observable(pppObj.pppoe_cc);
|
| 2506 | target.autoUser = ko.observable(pppObj.pppoe_username);
|
| 2507 | target.autoPassword = ko.observable(pppObj.pppoe_cc);
|
| 2508 | target.pppMode = ko.observable(pppObj.ethwan_dialmode);
|
| 2509 | initContronler();
|
| 2510 |
|
| 2511 |
|
| 2512 | //下拉框选择改变下面DIV模块
|
| 2513 | target.changeModeDiv = changeModeDivFunc;
|
| 2514 |
|
| 2515 | target.radioHandler = radioHandlerFunc;
|
| 2516 |
|
| 2517 | target.primaryDNS = ko.observable(pppObj.static_wan_primary_dns);
|
| 2518 | target.secondaryDNS = ko.observable(pppObj.static_wan_secondary_dns);
|
| 2519 | target.ipAddress = ko.observable(pppObj.static_wan_ipaddr);
|
| 2520 | target.subnetMask = ko.observable(pppObj.static_wan_netmask);
|
| 2521 | target.defaultGateway = ko.observable(pppObj.static_wan_gateway);
|
| 2522 |
|
| 2523 | addInterval(function(){
|
| 2524 | ethParams = service.getPppoeParams();
|
| 2525 | pppObj.rj45_state = ethParams.rj45_state;
|
| 2526 | initContronler();
|
| 2527 | }, 1000);
|
| 2528 |
|
| 2529 | // 取消连接按钮事件.
|
| 2530 |
|
| 2531 | target.cancelConnect = cancelConnectFunc;
|
| 2532 |
|
| 2533 | // 应用按钮事件.
|
| 2534 |
|
| 2535 | target.save = saveFunc;
|
| 2536 |
|
| 2537 | //密码显示事件
|
| 2538 | target.showPasswordHandler = function () {
|
| 2539 | var checkbox = $("#showPassword:checked");
|
| 2540 | if (checkbox && checkbox.length == 0) {
|
| 2541 | target.showPassword(true);
|
| 2542 | } else {
|
| 2543 | target.showPassword(false);
|
| 2544 | }
|
| 2545 | };
|
| 2546 |
|
| 2547 | // 更新当前界面状态、按钮、提示语等.
|
| 2548 |
|
| 2549 | function initContronler() {
|
| 2550 | checkRj45DeadTip();
|
| 2551 | if(target.currentMode() == "PPPOE"){
|
| 2552 | target.isPppoeMode(true);
|
| 2553 | target.isStaticMode(false);
|
| 2554 | target.isAutoMode(false);
|
| 2555 | target.staticNoticeShow(false);
|
| 2556 | target.dhcpNoticeShow(false);
|
| 2557 | target.autoNoticeShow(false);
|
| 2558 | } else if(target.currentMode() == "AUTO"){
|
| 2559 | target.isStaticMode(false);
|
| 2560 | target.isPppoeMode(false);
|
| 2561 | target.isAutoMode(true);
|
| 2562 | target.dhcpNoticeShow(false);
|
| 2563 | target.pppoeNoticeShow(false);
|
| 2564 | target.staticNoticeShow(false);
|
| 2565 | } else if(target.currentMode() == "STATIC"){
|
| 2566 | target.isStaticMode(true);
|
| 2567 | target.isPppoeMode(false);
|
| 2568 | target.isAutoMode(false);
|
| 2569 | target.dhcpNoticeShow(false);
|
| 2570 | target.pppoeNoticeShow(false);
|
| 2571 | target.autoNoticeShow(false);
|
| 2572 | } else{
|
| 2573 | target.isStaticMode(false);
|
| 2574 | target.isPppoeMode(false);
|
| 2575 | target.isAutoMode(false);
|
| 2576 | target.staticNoticeShow(false);
|
| 2577 | target.pppoeNoticeShow(false);
|
| 2578 | target.autoNoticeShow(false);
|
| 2579 | }
|
| 2580 | if(ethParams.ethwan_dialmode != "auto_dial" && (pppObj.rj45_state == "working" || pppObj.rj45_state =="connect") ){
|
| 2581 | target.enableFlag(false);
|
| 2582 | } else {
|
| 2583 | target.enableFlag(true);
|
| 2584 | }
|
| 2585 | if(pppObj.rj45_state == "connect"){
|
| 2586 | if(target.pppMode() == "auto_dial"){
|
| 2587 | target.action("connect");
|
| 2588 | }else{
|
| 2589 | target.action("disconnect");
|
| 2590 | }
|
| 2591 | } else if(pppObj.rj45_state == "working"){
|
| 2592 | target.action("disconnect");
|
| 2593 | }else{
|
| 2594 | target.action("connect");
|
| 2595 | }
|
| 2596 | //应用/连接按钮
|
| 2597 | if(target.pppMode() != "auto_dial" && target.currentMode() == ethParams.ethwan_mode){
|
| 2598 | target.btnTrans("connect");
|
| 2599 | } else{
|
| 2600 | target.btnTrans("apply");
|
| 2601 | }
|
| 2602 | if(pppObj.rj45_state != "idle"){
|
| 2603 | $("#pppoeApply").attr("disabled", true);
|
| 2604 | }else {
|
| 2605 | $("#pppoeApply").attr("disabled", false);
|
| 2606 | }
|
| 2607 |
|
| 2608 | //取消/断开按钮
|
| 2609 | target.isShowDisbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "working");
|
| 2610 | target.isShowCancelbtn(target.pppMode() != "auto_dial" && pppObj.rj45_state == "connect");
|
| 2611 |
|
| 2612 | $("#pppoeApply").translate();
|
| 2613 | }
|
| 2614 | // 设置后通过定时检查rj45_state状态,判断连接或断开操作结果.
|
| 2615 |
|
| 2616 | function setRj45CheckTimer(action){
|
| 2617 | checkStatusTimer && window.clearInterval(checkStatusTimer);
|
| 2618 | if("connect" != action){
|
| 2619 | checkStatusTimer = addInterval(function () {
|
| 2620 | checkDisconnectStatus();
|
| 2621 | }, 2000);
|
| 2622 | }else{
|
| 2623 | if(target.currentMode() == "PPPOE"){
|
| 2624 | target.pppoeNoticeShow(true);
|
| 2625 | target.pppoeNotice("pppoe_processing");
|
| 2626 | target.pppoeNoticeText($.i18n.prop("pppoe_processing"));
|
| 2627 | } else if(target.currentMode() == "STATIC"){
|
| 2628 | target.staticNoticeShow(true);
|
| 2629 | target.staticNotice("static_processing");
|
| 2630 | target.staticNoticeText($.i18n.prop("static_processing"));
|
| 2631 | } else if(target.currentMode() == "DHCP"){
|
| 2632 | target.dhcpNoticeShow(true);
|
| 2633 | target.dhcpNotice("dyn_processing");
|
| 2634 | target.dhcpNoticeText($.i18n.prop("dyn_processing"));
|
| 2635 | }else{
|
| 2636 | target.autoNoticeShow(true);
|
| 2637 | target.autoNotice("auto_processing");
|
| 2638 | target.autoNoticeText($.i18n.prop("auto_processing"));
|
| 2639 | }
|
| 2640 | checkStatusTimer = addInterval(function () {
|
| 2641 | checkConnectionStatus();
|
| 2642 | }, 2000);
|
| 2643 | }
|
| 2644 | }
|
| 2645 | // 设置后通过定时检查rj45_state状态,判断连接操作结果.
|
| 2646 |
|
| 2647 | function checkConnectionStatus(){
|
| 2648 | if(checkConCounter < 1){
|
| 2649 | checkConCounter++;
|
| 2650 | return;
|
| 2651 | }
|
| 2652 | if(pppObj.rj45_state == "connect"){
|
| 2653 | if(target.currentMode() != ethParams.ethwan_mode){
|
| 2654 | if(target.currentMode() == "AUTO"){
|
| 2655 | target.autoNoticeShow(true);
|
| 2656 | }else if(target.currentMode() == "PPPOE"){
|
| 2657 | target.pppoeNoticeShow(true);
|
| 2658 | }else if(target.currentMode() == "STATIC"){
|
| 2659 | target.staticNoticeShow(true);
|
| 2660 | }else if(target.currentMode() == "DHCP"){
|
| 2661 | target.dhcpNoticeShow(true);
|
| 2662 | }
|
| 2663 | }
|
| 2664 | if(checkConCounter > 6){
|
| 2665 | if(timeoutTipShowed == false){
|
| 2666 | timeoutTipShowed = true;
|
| 2667 | showAlert("ussd_operation_timeout");
|
| 2668 | }
|
| 2669 | }
|
| 2670 | checkConCounter++;
|
| 2671 | } else if (pppObj.rj45_state == "working") {
|
| 2672 | hideLoading();
|
| 2673 | setRj45WorkingTip();
|
| 2674 | window.clearInterval(checkStatusTimer);
|
| 2675 | } else if (pppObj.rj45_state == "dead") {
|
| 2676 | hideLoading();
|
| 2677 | checkRj45DeadTip();
|
| 2678 | window.clearInterval(checkStatusTimer);
|
| 2679 | } else if(pppObj.rj45_state == "idle"){
|
| 2680 | hideLoading();
|
| 2681 | if(target.currentMode() == "DHCP" && ethParams.ethwan_mode == "DHCP") {
|
| 2682 | timeoutTipShowed == false && target.dhcpNoticeShow(true);
|
| 2683 | target.dhcpNotice("dyn_fail");
|
| 2684 | target.dhcpNoticeText($.i18n.prop("dyn_fail"));
|
| 2685 | }
|
| 2686 | if(target.currentMode() == "STATIC" && ethParams.ethwan_mode == "STATIC") {
|
| 2687 | timeoutTipShowed == false && target.staticNoticeShow(true);
|
| 2688 | target.staticNotice("static_fail");
|
| 2689 | target.staticNoticeText($.i18n.prop("static_fail"));
|
| 2690 | }
|
| 2691 | if(target.currentMode() == "PPPOE" && ethParams.ethwan_mode == "PPPOE") {
|
| 2692 | timeoutTipShowed == false && target.pppoeNoticeShow(true);
|
| 2693 | target.pppoeNotice("pppoe_fail");
|
| 2694 | target.pppoeNoticeText($.i18n.prop("pppoe_fail"));
|
| 2695 | }
|
| 2696 | if(target.currentMode() == "AUTO" && ethParams.ethwan_mode == "AUTO") {
|
| 2697 | timeoutTipShowed == false && target.autoNoticeShow(true);
|
| 2698 | target.autoNotice("auto_fail");
|
| 2699 | target.autoNoticeText($.i18n.prop("auto_fail"));
|
| 2700 | }
|
| 2701 | window.clearInterval(checkStatusTimer);
|
| 2702 | } else{
|
| 2703 | hideLoading();
|
| 2704 | window.clearInterval(checkStatusTimer);
|
| 2705 | }
|
| 2706 | }
|
| 2707 | // 设置连接成功时提示语状态.
|
| 2708 |
|
| 2709 | function setRj45WorkingTip(){
|
| 2710 | if(target.currentMode() == ethParams.ethwan_mode){
|
| 2711 | if(target.currentMode() == "AUTO") {
|
| 2712 | target.autoNoticeShow(true);
|
| 2713 | target.autoNotice("auto_success");
|
| 2714 | target.autoNoticeText($.i18n.prop("auto_success"));
|
| 2715 | }else if(target.currentMode() == "PPPOE") {
|
| 2716 | target.pppoeNoticeShow(true);
|
| 2717 | target.pppoeNotice("pppoe_success");
|
| 2718 | target.pppoeNoticeText($.i18n.prop("pppoe_success"));
|
| 2719 | }else if(target.currentMode() == "STATIC") {
|
| 2720 | target.staticNoticeShow(true);
|
| 2721 | target.staticNotice("static_success");
|
| 2722 | target.staticNoticeText($.i18n.prop("static_success"));
|
| 2723 | }else if(target.currentMode() == "DHCP" ) {
|
| 2724 | target.dhcpNoticeShow(true);
|
| 2725 | target.dhcpNotice("dyn_success");
|
| 2726 | target.dhcpNoticeText($.i18n.prop("dyn_success"));
|
| 2727 | }
|
| 2728 | }
|
| 2729 | }
|
| 2730 |
|
| 2731 | // 设置网线断开提示语状态.
|
| 2732 |
|
| 2733 | function checkRj45DeadTip(){
|
| 2734 | if(pppObj.rj45_state != "dead"){
|
| 2735 | if(target.currentMode() == "AUTO" && target.autoNotice() == "pppoe_msg") {
|
| 2736 | target.autoNoticeShow(false);
|
| 2737 | }else if(target.currentMode() == "PPPOE" && target.pppoeNotice() == "pppoe_msg") {
|
| 2738 | target.pppoeNoticeShow(false);
|
| 2739 | }else if(target.currentMode() == "STATIC" && target.staticNotice() == "pppoe_msg") {
|
| 2740 | target.staticNoticeShow(false);
|
| 2741 | }else if(target.currentMode() == "DHCP" && target.dhcpNotice() == "pppoe_msg") {
|
| 2742 | target.dhcpNoticeShow(false);
|
| 2743 | }
|
| 2744 |
|
| 2745 | } else{
|
| 2746 | target.dhcpNotice("pppoe_msg");
|
| 2747 | target.dhcpNoticeText($.i18n.prop("pppoe_msg"));
|
| 2748 | target.staticNotice("pppoe_msg");
|
| 2749 | target.staticNoticeText($.i18n.prop("pppoe_msg"));
|
| 2750 | target.pppoeNotice("pppoe_msg");
|
| 2751 | target.pppoeNoticeText($.i18n.prop("pppoe_msg"));
|
| 2752 | target.autoNotice("pppoe_msg");
|
| 2753 | target.autoNoticeText($.i18n.prop("pppoe_msg"));
|
| 2754 | if(target.currentMode() == "AUTO") {
|
| 2755 | target.autoNoticeShow(true);
|
| 2756 | }else if(target.currentMode() == "PPPOE") {
|
| 2757 | target.pppoeNoticeShow(true);
|
| 2758 | }else if(target.currentMode() == "STATIC") {
|
| 2759 | target.staticNoticeShow(true);
|
| 2760 | }else if(target.currentMode() == "DHCP") {
|
| 2761 | target.dhcpNoticeShow(true);
|
| 2762 | }
|
| 2763 | }
|
| 2764 | }
|
| 2765 | // 设置后通过定时检查rj45_state状态,判断断开操作结果.
|
| 2766 |
|
| 2767 | function checkDisconnectStatus(){
|
| 2768 | if(checkConCounter < 1){
|
| 2769 | checkConCounter++;
|
| 2770 | } else if (pppObj.rj45_state != "working" && pppObj.rj45_state != "connect") {
|
| 2771 | target.dhcpNoticeShow(false);
|
| 2772 | target.staticNoticeShow(false);
|
| 2773 | target.pppoeNoticeShow(false);
|
| 2774 | target.autoNoticeShow(false);
|
| 2775 | window.clearInterval(checkStatusTimer);
|
| 2776 | successOverlay();
|
| 2777 | } else if(checkConCounter > 6){
|
| 2778 | if(timeoutTipShowed == false){
|
| 2779 | timeoutTipShowed = true;
|
| 2780 | showAlert("ussd_operation_timeout");
|
| 2781 | }
|
| 2782 | window.clearInterval(checkStatusTimer);
|
| 2783 | } else if(checkConCounter < 7) {
|
| 2784 | checkConCounter++;
|
| 2785 | } else {
|
| 2786 | hideLoading();
|
| 2787 | window.clearInterval(checkStatusTimer);
|
| 2788 | }
|
| 2789 | }
|
| 2790 |
|
| 2791 | //应用按钮事件.
|
| 2792 | function saveFunc(){
|
| 2793 | target.dhcpNoticeShow(false);
|
| 2794 | target.staticNoticeShow(false);
|
| 2795 | target.pppoeNoticeShow(false);
|
| 2796 | target.autoNoticeShow(false);
|
| 2797 | if(pppObj.rj45_state == "dead"){
|
| 2798 | showAlert("pppoe_msg");
|
| 2799 | return;
|
| 2800 | }
|
| 2801 | var requestParams = {};
|
| 2802 | if($("#pppoe_mode").val() == "PPPOE") {
|
| 2803 | requestParams = $.extend({}, {
|
| 2804 | goformId: "WAN_GATEWAYMODE_PPPOE",
|
| 2805 | pppoe_username: target.user(),
|
| 2806 | pppoe_cc: target.password()
|
| 2807 | });
|
| 2808 | } else if($("#pppoe_mode").val() == "AUTO") {
|
| 2809 | requestParams = $.extend({}, {
|
| 2810 | goformId: "WAN_GATEWAYMODE_AUTO",
|
| 2811 | pppoe_username: target.autoUser(),
|
| 2812 | pppoe_cc: target.autoPassword()
|
| 2813 | });
|
| 2814 | } else if($("#pppoe_mode").val() == "STATIC") {
|
| 2815 | if(target.ipAddress() == target.defaultGateway()){
|
| 2816 | showAlert("ip_gate_not_same");
|
| 2817 | return;
|
| 2818 | }
|
| 2819 | if(isStaticIPValid(target.ipAddress(), pppObj.lan_ipaddr, pppObj.lan_netmask)){
|
| 2820 | showAlert("ip_innergate_not_same");
|
| 2821 | return;
|
| 2822 | }
|
| 2823 | requestParams = $.extend({}, {
|
| 2824 | goformId: "WAN_GATEWAYMODE_STATIC",
|
| 2825 | static_wan_ipaddr: target.ipAddress(),
|
| 2826 | static_wan_netmask: target.subnetMask(),
|
| 2827 | static_wan_gateway: target.defaultGateway(),
|
| 2828 | static_wan_primary_dns: target.primaryDNS(),
|
| 2829 | static_wan_secondary_dns: target.secondaryDNS(),
|
| 2830 | WAN_MODE: "STATIC"
|
| 2831 | });
|
| 2832 | } else {
|
| 2833 | requestParams = $.extend({}, {
|
| 2834 | goformId: "WAN_GATEWAYMODE_DHCP"
|
| 2835 | });
|
| 2836 | }
|
| 2837 | requestParams.action_link = "connect";
|
| 2838 | requestParams.dial_mode = target.pppMode();
|
| 2839 | showLoading("waiting");
|
| 2840 |
|
| 2841 | service.setPppoeDialMode(requestParams, function(data){
|
| 2842 | if(data.result){
|
| 2843 | target.currentMode($("#pppoe_mode").val());
|
| 2844 | pppObj = service.getPppoeParams();
|
| 2845 | checkConCounter = 0;
|
| 2846 | timeoutTipShowed = false;
|
| 2847 | setRj45CheckTimer("connect");
|
| 2848 | $("#pppoeApply").translate();
|
| 2849 | } else {
|
| 2850 | errorOverlay("pppoe_message_send_fail");
|
| 2851 | }
|
| 2852 | });
|
| 2853 |
|
| 2854 | }
|
| 2855 |
|
| 2856 | //取消连接按钮事件.
|
| 2857 | function cancelConnectFunc(){
|
| 2858 | target.dhcpNoticeShow(false);
|
| 2859 | target.staticNoticeShow(false);
|
| 2860 | target.pppoeNoticeShow(false);
|
| 2861 | target.autoNoticeShow(false);
|
| 2862 | if(pppObj.rj45_state == "dead"){
|
| 2863 | showAlert("pppoe_msg");
|
| 2864 | return;
|
| 2865 | }
|
| 2866 | var requestParams = {
|
| 2867 | dial_mode: target.pppMode(),
|
| 2868 | action_link: "disconnect"
|
| 2869 | };
|
| 2870 | if(pppObj.ethwan_mode == "PPPOE") {
|
| 2871 | requestParams = $.extend(requestParams, {
|
| 2872 | goformId: "WAN_GATEWAYMODE_PPPOE",
|
| 2873 | pppoe_username: pppObj.pppoe_username,
|
| 2874 | pppoe_cc: pppObj.pppoe_cc
|
| 2875 | });
|
| 2876 | }else if(pppObj.ethwan_mode == "AUTO") {
|
| 2877 | requestParams = $.extend(requestParams, {
|
| 2878 | goformId: "WAN_GATEWAYMODE_AUTO",
|
| 2879 | pppoe_username: pppObj.pppoe_username,
|
| 2880 | pppoe_cc: pppObj.pppoe_cc
|
| 2881 | });
|
| 2882 | }else if(pppObj.ethwan_mode == "STATIC") {
|
| 2883 | requestParams = $.extend(requestParams, {
|
| 2884 | goformId: "WAN_GATEWAYMODE_STATIC",
|
| 2885 | static_wan_ipaddr: pppObj.static_wan_ipaddr,
|
| 2886 | static_wan_netmask: pppObj.static_wan_netmask,
|
| 2887 | static_wan_gateway: pppObj.static_wan_gateway,
|
| 2888 | static_wan_primary_dns: pppObj.static_wan_primary_dns,
|
| 2889 | static_wan_secondary_dns: pppObj.static_wan_secondary_dns,
|
| 2890 | WAN_MODE: "STATIC"
|
| 2891 | });
|
| 2892 | }else {
|
| 2893 | requestParams = $.extend(requestParams, {
|
| 2894 | goformId: "WAN_GATEWAYMODE_DHCP"
|
| 2895 | });
|
| 2896 | }
|
| 2897 | showLoading("waiting");
|
| 2898 | service.setPppoeDialMode(requestParams, function(data){
|
| 2899 | if(data.result){
|
| 2900 | checkConCounter = 0;
|
| 2901 | timeoutTipShowed = false;
|
| 2902 | setRj45CheckTimer("disconnect");
|
| 2903 | $("#pppoeApply").translate();
|
| 2904 | } else {
|
| 2905 | errorOverlay("pppoe_message_send_fail");
|
| 2906 | }
|
| 2907 | });
|
| 2908 |
|
| 2909 | }
|
| 2910 |
|
| 2911 | function radioHandlerFunc(){
|
| 2912 | initContronler();
|
| 2913 | return true;
|
| 2914 | }
|
| 2915 |
|
| 2916 | function changeModeDivFunc(){
|
| 2917 | initContronler();
|
| 2918 | }
|
| 2919 |
|
| 2920 | }
|
| 2921 |
|
| 2922 | function bindContainer(vm){
|
| 2923 | var container = $('#container');
|
| 2924 | ko.cleanNode(container[0]);
|
| 2925 | ko.applyBindings(vm, container[0]);
|
| 2926 |
|
| 2927 | }
|
| 2928 | // 联网设置初始化.
|
| 2929 |
|
| 2930 | function initialize() {
|
| 2931 | var vm = new PPPoEViewModel();
|
| 2932 | bindContainer(vm);
|
| 2933 |
|
| 2934 | $("#pppoeApply").translate();
|
| 2935 |
|
| 2936 | $('#pppoeForm').validate({
|
| 2937 | submitHandler : function() {
|
| 2938 | vm.save();
|
| 2939 | },
|
| 2940 | rules: {
|
| 2941 | txtPin: "wps_pin_check",
|
| 2942 | txtIpAddress: "dmz_ip_check",
|
| 2943 | txtSubnetMask: {
|
| 2944 | ipv4: true,
|
| 2945 | subnetmask_check: true
|
| 2946 | },
|
| 2947 | txtDefaultGateway: {
|
| 2948 | ipv4: true,
|
| 2949 | gateway_check: true
|
| 2950 | },
|
| 2951 | txtPrimaryDNS: {
|
| 2952 | ipv4: true,
|
| 2953 | dns_check:true
|
| 2954 | },
|
| 2955 | txtSecondaryDNS: {
|
| 2956 | ipv4: true,
|
| 2957 | dns_check:true
|
| 2958 | }
|
| 2959 | }
|
| 2960 | });
|
| 2961 | }
|
| 2962 |
|
| 2963 |
|
| 2964 | //from 4.0
|
| 2965 | // 有效DNS检查.
|
| 2966 |
|
| 2967 | function validateDns(dns){
|
| 2968 | if ( "0.0.0.0" == dns || "255.255.255.255" == dns) {
|
| 2969 | return false;
|
| 2970 | }
|
| 2971 | return true;
|
| 2972 | }
|
| 2973 | // 联网设置初始化.
|
| 2974 |
|
| 2975 | function isStaticIPValid(ip, lanip, lanmask){
|
| 2976 | if(!ip || !lanip || !lanmask){//各参数不能为空
|
| 2977 | return false;
|
| 2978 | }
|
| 2979 | if(ip == lanip){// 与内网IP相等
|
| 2980 | return true;
|
| 2981 | }
|
| 2982 | var res1 = [], res2 = [], mask = [];
|
| 2983 | addr1 = ip.split(".");
|
| 2984 | addr2 = lanip.split(".");
|
| 2985 | mask = lanmask.split(".");
|
| 2986 | for(var i = 0; i < addr1.length; i += 1){
|
| 2987 | res1.push(parseInt(addr1[i]) & parseInt(mask[i]));
|
| 2988 | res2.push(parseInt(addr2[i]) & parseInt(mask[i]));
|
| 2989 | }
|
| 2990 | if(res1.join(".") == res2.join(".")){//在同一个网段
|
| 2991 | return true;
|
| 2992 | }else{//不在同一个网段
|
| 2993 | return false;
|
| 2994 | }
|
| 2995 | }
|
| 2996 |
|
| 2997 | // 有效子网掩码验证.
|
| 2998 |
|
| 2999 | function isNetmaskIPValid(ip) {
|
| 3000 | if (ip == 255 || ip == 254 || ip == 252 || ip == 248
|
| 3001 | || ip == 240 || ip == 224 || ip == 192 || ip == 128 || ip == 0)
|
| 3002 | {
|
| 3003 | return true;
|
| 3004 | }
|
| 3005 | else
|
| 3006 | {
|
| 3007 | return false;
|
| 3008 | }
|
| 3009 | }
|
| 3010 | // 有效子网掩码检查.
|
| 3011 |
|
| 3012 | function validateNetmask(netmask) {
|
| 3013 | var array = new Array();
|
| 3014 | array = netmask.split(".");
|
| 3015 |
|
| 3016 | if (array.length != 4) {
|
| 3017 | return false;
|
| 3018 | }
|
| 3019 |
|
| 3020 | array[0] = parseInt(array[0]);
|
| 3021 | array[1] = parseInt(array[1]);
|
| 3022 | array[2] = parseInt(array[2]);
|
| 3023 | array[3] = parseInt(array[3]);
|
| 3024 |
|
| 3025 | if (array[3] != 0) {
|
| 3026 | if (array[2] != 255 || array[1] != 255 || array[0] != 255) {
|
| 3027 | return false;
|
| 3028 | } else {
|
| 3029 | if (!isNetmaskIPValid(array[3])) {
|
| 3030 | return false;
|
| 3031 | }
|
| 3032 | }
|
| 3033 | }
|
| 3034 |
|
| 3035 | if (array[2] != 0) {
|
| 3036 | if (array[1] != 255 || array[0] != 255) {
|
| 3037 | return false;
|
| 3038 | } else {
|
| 3039 | if (!isNetmaskIPValid(array[2])) {
|
| 3040 | return false;
|
| 3041 | }
|
| 3042 | }
|
| 3043 | }
|
| 3044 |
|
| 3045 | if (array[1] != 0) {
|
| 3046 | if (array[0] != 255) {
|
| 3047 | return false;
|
| 3048 | } else{
|
| 3049 | if (!isNetmaskIPValid(array[1])) {
|
| 3050 | return false;
|
| 3051 | }
|
| 3052 | }
|
| 3053 | }
|
| 3054 | if(array[0]!=255) {
|
| 3055 | return false;
|
| 3056 | }
|
| 3057 | if ( "0.0.0.0" == netmask || "255.255.255.255" == netmask) {
|
| 3058 | return false;
|
| 3059 | }
|
| 3060 | return true;
|
| 3061 | }
|
| 3062 |
|
| 3063 | // subnetmask_check校验规则
|
| 3064 |
|
| 3065 | jQuery.validator.addMethod("subnetmask_check", function (value, element, param) {
|
| 3066 | var result = validateNetmask(value);
|
| 3067 | return this.optional(element) || result;
|
| 3068 | });
|
| 3069 | // dns_check校验规则
|
| 3070 |
|
| 3071 | jQuery.validator.addMethod("dns_check", function (value, element, param) {
|
| 3072 | var result = validateDns(value);
|
| 3073 | return this.optional(element) || result;
|
| 3074 | });
|
| 3075 | // 有效网关检查.
|
| 3076 |
|
| 3077 | function validateGateway(wanIp, netmaskIp, gatewayIp) {
|
| 3078 | if(myConcat(wanIp,netmaskIp) == myConcat(netmaskIp, gatewayIp)) {
|
| 3079 | return true;
|
| 3080 | } else {
|
| 3081 | return false;
|
| 3082 | }
|
| 3083 | }
|
| 3084 | // IP和子网掩码转换成数组形式并相与,返回相与后的IP.
|
| 3085 |
|
| 3086 | function myConcat(ip1,ip2){
|
| 3087 | var result = [];
|
| 3088 | var iplArr = ip1.split(".");
|
| 3089 | var ip2Arr = ip2.split(".");
|
| 3090 | for(var i = 0; i < iplArr.length;i++){
|
| 3091 | result[i] = (iplArr[i] & ip2Arr[i]);
|
| 3092 | }
|
| 3093 | return result.join(".");
|
| 3094 | }
|
| 3095 | // gateway_check校验规则
|
| 3096 |
|
| 3097 | jQuery.validator.addMethod("gateway_check", function (value, element, param) {
|
| 3098 | var result = validateGateway($('#txtIpAddress').val(), $('#txtSubnetMask').val(), $("#txtDefaultGateway").val());
|
| 3099 | return this.optional(element) || result;
|
| 3100 | });
|
| 3101 |
|
| 3102 | return {
|
| 3103 | init: initialize
|
| 3104 | };
|
| 3105 | });
|
| 3106 | //联网设置模块
|
| 3107 | define("network_dial_set","underscore jquery knockout set service".split(" "),
|
| 3108 | function(_, $, ko, config, service) {
|
| 3109 |
|
| 3110 | //联网设置view model
|
| 3111 | function DialVM() {
|
| 3112 | var dialMode = service.getConnectionMode();
|
| 3113 | var target = this;
|
| 3114 |
|
| 3115 | target.selectMode = ko.observable(dialMode.connectionMode);
|
| 3116 | target.enableFlag = ko.observable(true);
|
| 3117 | target.isAllowedRoaming = ko.observable(dialMode.isAllowedRoaming);
|
| 3118 | var originalRoaming = dialMode.isAllowedRoaming;
|
| 3119 |
|
| 3120 | target.setAllowedRoaming = setAllowedRoamingFunc;
|
| 3121 |
|
| 3122 | var checkboxFlag = $(".checkboxToggle");
|
| 3123 | target.checkEnable = checkEnableFunc;
|
| 3124 |
|
| 3125 | //修改联网模式
|
| 3126 | target.save = saveFunc;
|
| 3127 |
|
| 3128 | function saveFunc() {
|
| 3129 | showLoading();
|
| 3130 | var connMode = target.selectMode();
|
| 3131 | //当选择自动时,下发原先的勾选状态
|
| 3132 | if (connMode == 'auto_dial') {
|
| 3133 | originalRoaming = target.isAllowedRoaming();
|
| 3134 | } else {
|
| 3135 | target.isAllowedRoaming(originalRoaming);
|
| 3136 | }
|
| 3137 | service.setConnectionMode({
|
| 3138 | connectionMode: connMode,
|
| 3139 | isAllowedRoaming: target.isAllowedRoaming()
|
| 3140 | }, function (result) {
|
| 3141 | if (result.result == "success") {
|
| 3142 | successOverlay();
|
| 3143 | } else {
|
| 3144 | errorOverlay();
|
| 3145 | }
|
| 3146 | });
|
| 3147 | }
|
| 3148 |
|
| 3149 | function setAllowedRoamingFunc() {
|
| 3150 | if(!$("#roamBtn").hasClass("disable")){
|
| 3151 | var checkbox = $("#isAllowedRoaming:checked");
|
| 3152 | if(checkbox && checkbox.length == 0 ){
|
| 3153 | target.isAllowedRoaming("on");
|
| 3154 | }else{
|
| 3155 | target.isAllowedRoaming("off");
|
| 3156 | }
|
| 3157 | }
|
| 3158 | }
|
| 3159 |
|
| 3160 | function checkEnableFunc() {
|
| 3161 | var status = service.getStatusInfo();
|
| 3162 |
|
| 3163 | if (status.connectStatus == "ppp_connected" || status.connectStatus == "ppp_connecting") {
|
| 3164 | target.enableFlag(false);
|
| 3165 | disableCheckbox(checkboxFlag);
|
| 3166 | }
|
| 3167 | else {
|
| 3168 | target.enableFlag(true);
|
| 3169 | enableCheckbox(checkboxFlag);
|
| 3170 | }
|
| 3171 | }
|
| 3172 |
|
| 3173 | }
|
| 3174 |
|
| 3175 | //联网设置初始化.
|
| 3176 | function initialize() {
|
| 3177 | var vm = new DialVM();
|
| 3178 | bindContainer(vm);
|
| 3179 |
|
| 3180 | vm.checkEnable();
|
| 3181 | addInterval( vm.checkEnable, 1000);
|
| 3182 | }
|
| 3183 |
|
| 3184 | function bindContainer(vm){
|
| 3185 | var container = $('#container');
|
| 3186 | ko.cleanNode(container[0]);
|
| 3187 | ko.applyBindings(vm, container[0]);
|
| 3188 |
|
| 3189 | }
|
| 3190 |
|
| 3191 | return {
|
| 3192 | init: initialize
|
| 3193 | };
|
| 3194 | });
|
| 3195 | // APN Setting 模块
|
| 3196 | define("network_apn_set","underscore jquery knockout set service".split(" "),
|
| 3197 | function (_, $, ko, config, service) {
|
| 3198 |
|
| 3199 | //获取鉴权方式
|
| 3200 |
|
| 3201 | function getAuthModes() {
|
| 3202 | return _.map(config.APN_AUTH_MODES, function (item) {
|
| 3203 | return new Option(item.name, item.value);
|
| 3204 | });
|
| 3205 | }
|
| 3206 |
|
| 3207 | function getApnPdpTypes() {
|
| 3208 | var pdpTypesArray = [new Option('IPv4', 'IP')];
|
| 3209 | if (config.IPV6_SUPPORT) {
|
| 3210 | pdpTypesArray.push(new Option('IPv6', 'IPv6'));
|
| 3211 | if (config.IPV4V6_SUPPORT) {
|
| 3212 | pdpTypesArray.push(new Option('IPv4v6', 'IPv4v6'));
|
| 3213 | }
|
| 3214 | if (config.IPV4_AND_V6_SUPPORT) {
|
| 3215 | pdpTypesArray.push(new Option('IPv4 & IPv6', 'IPv4v6'));
|
| 3216 | }
|
| 3217 | }
|
| 3218 | return pdpTypesArray;
|
| 3219 | }
|
| 3220 |
|
| 3221 | //获取apn相关信息
|
| 3222 |
|
| 3223 | function getApnSet() {
|
| 3224 | var apnInfo = service.getApnSettings();
|
| 3225 | apnInfo.ipv6ApnConfigs = getApnConfigs(apnInfo.ipv6APNs, true);
|
| 3226 | apnInfo.apnConfigs = getApnConfigs(apnInfo.APNs, false);
|
| 3227 | apnInfo.autoApnConfigs = getAutoApnsConfig(apnInfo.autoApns, apnInfo.autoApnsV6);
|
| 3228 | return apnInfo;
|
| 3229 | }
|
| 3230 | var apnConfigs = {};
|
| 3231 | var ipv6ApnConfigs = {};
|
| 3232 | var autoApnConfigs = {};
|
| 3233 |
|
| 3234 | //解析自动apn信息
|
| 3235 |
|
| 3236 | function getAutoApnsConfig(autoApnV4, autoApnV6) {
|
| 3237 | var autoApnsV4 = [];
|
| 3238 | var autoApnsV6 = [];
|
| 3239 |
|
| 3240 | if (autoApnV4 && autoApnV4.length > 5) {
|
| 3241 | var apnArr = autoApnV4.split("||");
|
| 3242 | for (var ki = 0; ki < apnArr.length; ki++) {
|
| 3243 | if (apnArr[ki] != "") {
|
| 3244 | var apnItem = parseApnItem(apnArr[ki], false);
|
| 3245 | autoApnsV4.push(apnItem);
|
| 3246 | }
|
| 3247 | }
|
| 3248 | }
|
| 3249 | if (autoApnV6 && autoApnV6.length > 5) {
|
| 3250 | var apnArr = autoApnV6.split("||");
|
| 3251 | for (var ki = 0; ki < apnArr.length; ki++) {
|
| 3252 | if (apnArr[ki] != "") {
|
| 3253 | var apnItem = parseApnItem(apnArr[ki], false);
|
| 3254 | autoApnsV6.push(apnItem);
|
| 3255 | }
|
| 3256 | }
|
| 3257 | }
|
| 3258 | return dealAutoApnsV4V6(autoApnsV4, autoApnsV6);
|
| 3259 | }
|
| 3260 | //解析apn信息
|
| 3261 |
|
| 3262 | function getApnConfigs(apnsStr, isIpv6) {
|
| 3263 | var apnCfgs = [];
|
| 3264 | var theApnConfigs = {};
|
| 3265 | if (apnsStr && apnsStr.length > 10) {
|
| 3266 | var apnArr = apnsStr.split("||");
|
| 3267 | for (var ki = 0; ki < apnArr.length; ki++) {
|
| 3268 | if (apnArr[ki] != "") {
|
| 3269 | var apnItem = parseApnItem(apnArr[ki], isIpv6);
|
| 3270 | apnCfgs.push(apnItem);
|
| 3271 | theApnConfigs[apnItem.profileName] = apnItem;
|
| 3272 | }
|
| 3273 | }
|
| 3274 | }
|
| 3275 | if (isIpv6 == false) {
|
| 3276 | apnConfigs = theApnConfigs;
|
| 3277 | } else {
|
| 3278 | ipv6ApnConfigs = theApnConfigs;
|
| 3279 | }
|
| 3280 | return apnCfgs;
|
| 3281 | }
|
| 3282 |
|
| 3283 | //解析单条apn信息
|
| 3284 |
|
| 3285 | function parseApnItem(apnStr, isIpv6) {
|
| 3286 | var apnItem = {};
|
| 3287 | var items = apnStr.split("($)");
|
| 3288 | for (var ki = 0; ki < items.length; ki++) {
|
| 3289 | apnItem.profileName = items[0];
|
| 3290 | apnItem.pdpType = items[7];
|
| 3291 | if (isIpv6 == false) {
|
| 3292 | apnItem.dnsMode = items[10];
|
| 3293 | apnItem.dns1 = items[11];
|
| 3294 | apnItem.dns2 = items[12];
|
| 3295 | apnItem.wanApn = items[1];
|
| 3296 | apnItem.authMode = items[4].toLowerCase();
|
| 3297 | apnItem.username = items[5];
|
| 3298 | apnItem.password = items[6];
|
| 3299 | } else {
|
| 3300 | apnItem.dnsModeV6 = items[10];
|
| 3301 | apnItem.dns1V6 = items[11];
|
| 3302 | apnItem.dns2V6 = items[12];
|
| 3303 | apnItem.wanApnV6 = items[1];
|
| 3304 | apnItem.authModeV6 = items[4].toLowerCase();
|
| 3305 | apnItem.usernameV6 = items[5];
|
| 3306 | apnItem.passwordV6 = items[6];
|
| 3307 | }
|
| 3308 | }
|
| 3309 | return apnItem;
|
| 3310 | }
|
| 3311 | //合并V4\V6自动apn信息
|
| 3312 |
|
| 3313 | function dealAutoApnsV4V6(v4, v6) {
|
| 3314 | autoApnConfigs = {};
|
| 3315 | var autoApns = [];
|
| 3316 | for (var ki = 0; ki < v4.length; ki++) {
|
| 3317 | var apnElem = v4[ki];
|
| 3318 | var itemsV6 = v6[ki];
|
| 3319 | if (itemsV6 && (itemsV6.pdpType == 'IPv6' || itemsV6.pdpType == 'IPv4v6')) {
|
| 3320 | apnElem.usernameV6 = itemsV6.username;
|
| 3321 | apnElem.passwordV6 = itemsV6.password;
|
| 3322 | apnElem.dns1V6 = itemsV6.dns1;
|
| 3323 | apnElem.dns2V6 = itemsV6.dns2;
|
| 3324 | apnElem.wanApnV6 = itemsV6.wanApn;
|
| 3325 | apnElem.authModeV6 = itemsV6.authMode;
|
| 3326 | apnElem.dnsModeV6 = itemsV6.dnsMode;
|
| 3327 | }
|
| 3328 | autoApns.push(apnElem);
|
| 3329 | autoApnConfigs[apnElem.profileName] = apnElem;
|
| 3330 | }
|
| 3331 | return autoApns;
|
| 3332 | }
|
| 3333 |
|
| 3334 | function getProfileOptions(apns) {
|
| 3335 | return _.map(apns, function (item) {
|
| 3336 | return new Option(item.profileName, item.profileName);
|
| 3337 | });
|
| 3338 | }
|
| 3339 |
|
| 3340 | //APNViewModel
|
| 3341 |
|
| 3342 | function APNViewModel() {
|
| 3343 | var target = this;
|
| 3344 | var apnSettings = getApnSet();
|
| 3345 | if (apnSettings.apnNumPreset) {
|
| 3346 | config.maxApnNumber = apnSettings.apnNumPreset;
|
| 3347 | }
|
| 3348 |
|
| 3349 | target.defApn = ko.observable(apnSettings.profileName); //当前默认APN
|
| 3350 | target.apnMode = ko.observable(apnSettings.apnMode);
|
| 3351 | target.autoProfiles = ko.observableArray(getProfileOptions(apnSettings.autoApnConfigs));
|
| 3352 | target.profiles = ko.observableArray(getProfileOptions(apnSettings.apnConfigs));
|
| 3353 | target.wanDial = ko.observable(apnSettings.wanDial);
|
| 3354 |
|
| 3355 | target.showApnDns = ko.observable(config.SHOW_APN_DNS);
|
| 3356 | target.index = ko.observable(apnSettings.currIndex);
|
| 3357 | target.supportIPv6 = ko.observable(config.IPV6_SUPPORT);
|
| 3358 | target.supportIpv4AndIpv6 = ko.observable(config.IPV4_AND_V6_SUPPORT);
|
| 3359 |
|
| 3360 | target.apn = ko.observable(apnSettings.wanApn);
|
| 3361 | target.dnsMode = ko.observable(apnSettings.dnsMode == 'manual' ? 'manual' : 'auto');
|
| 3362 | target.dns1 = ko.observable(apnSettings.dns1);
|
| 3363 | target.dns2 = ko.observable(apnSettings.dns2);
|
| 3364 | target.authModes = ko.observableArray(getAuthModes());
|
| 3365 | target.username = ko.observable(apnSettings.username);
|
| 3366 | target.password = ko.observable(apnSettings.password);
|
| 3367 |
|
| 3368 | target.pdpTypes = ko.observableArray(getApnPdpTypes());
|
| 3369 | target.selectedPdpType = ko.observable(apnSettings.pdpType);
|
| 3370 | target.selectedPdpTypeTmp = ko.observable(apnSettings.pdpType); //the PdpType select's value before chang
|
| 3371 | target.profileName = ko.observable(apnSettings.profileName); //当前编辑框中的
|
| 3372 | target.selectedProfile = ko.observable(apnSettings.profileName); //当前下拉框选择的APN
|
| 3373 |
|
| 3374 | target.showPassword = ko.observable(false);
|
| 3375 |
|
| 3376 | target.apnV6 = ko.observable(apnSettings.wanApnV6);
|
| 3377 | target.dnsModeV6 = ko.observable(apnSettings.dnsModeV6 == 'manual' ? 'manual' : 'auto');
|
| 3378 | target.dns1V6 = ko.observable(apnSettings.dns1V6);
|
| 3379 | target.dns2V6 = ko.observable(apnSettings.dns2V6);
|
| 3380 | target.authModesV6 = ko.observableArray(getAuthModes());
|
| 3381 | target.usernameV6 = ko.observable(apnSettings.usernameV6);
|
| 3382 | target.passwordV6 = ko.observable(apnSettings.passwordV6);
|
| 3383 | target.pdpTypeNote = ko.observable(true);
|
| 3384 | if (apnSettings.autoApnConfigs && apnSettings.autoApnConfigs.length > 0) {
|
| 3385 | target.selectedAutoProfile = ko.observable(apnSettings.autoApnConfigs[0].profileName);
|
| 3386 | } else {
|
| 3387 | target.selectedAutoProfile = ko.observable();
|
| 3388 | }
|
| 3389 |
|
| 3390 | if (config.EMPTY_APN_SUPPORT == false) {
|
| 3391 | $("#apn_ipv4_apn").addClass("required");
|
| 3392 | $("#apn_ipv6_apn").addClass("required");
|
| 3393 | } else {
|
| 3394 | $("#apn_ipv4_apn").removeClass("required");
|
| 3395 | $("#apn_ipv6_apn").removeClass("required");
|
| 3396 | }
|
| 3397 |
|
| 3398 | target.disableProfile = ko.observable(false); //表示处于新增页面
|
| 3399 | target.addApnHide = ko.observable(true);
|
| 3400 | target.defaultCfg = ko.observable(true); //当前选中的是默认APN
|
| 3401 | target.predeterminedCfg = ko.observable(true); //当前选中的是预置的APN
|
| 3402 |
|
| 3403 | target.selectedAuthentication = ko.observable(apnSettings.authMode);
|
| 3404 | target.selectedAuthenticationV6 = ko.observable(apnSettings.authModeV6);
|
| 3405 |
|
| 3406 |
|
| 3407 | target.transApnV6 = ko.observable('apn');
|
| 3408 | target.transDnsModeV6 = ko.observable('apn_dns_mode');
|
| 3409 | target.transDns1V6 = ko.observable('apn_dns1');
|
| 3410 | target.transDns2V6 = ko.observable('apn_dns2');
|
| 3411 | target.transAuthV6 = ko.observable('apn_authentication');
|
| 3412 | target.transUserNameV6 = ko.observable('apn_user_name');
|
| 3413 | target.transPasswordV6 = ko.observable('apn_password');
|
| 3414 |
|
| 3415 | target.transApn = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_ipv4_apn' : 'apn');
|
| 3416 | target.transDnsMode = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns_mode_ipv4' : 'apn_dns_mode');
|
| 3417 | target.transDns1 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns1_ipv4' : 'apn_dns1');
|
| 3418 | target.transDns2 = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_dns2_ipv4' : 'apn_dns2');
|
| 3419 | target.transAuth = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_authentication_ipv4' : 'apn_authentication');
|
| 3420 | target.transUserName = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_user_name_ipv4' : 'apn_user_name');
|
| 3421 | target.transPassword = ko.observable(config.IPV4_AND_V6_SUPPORT ? 'apn_password_ipv4' : 'apn_password');
|
| 3422 |
|
| 3423 | target.setDefaultVisible = ko.observable(!isConnectedNetWork());
|
| 3424 |
|
| 3425 | target.tmp1 = ko.computed(function () {
|
| 3426 | if (target.selectedPdpType() == "IPv6") {
|
| 3427 | target.transApnV6('apn');
|
| 3428 | target.transDnsModeV6('apn_dns_mode');
|
| 3429 | target.transDns1V6('apn_dns1');
|
| 3430 | target.transDns2V6('apn_dns2');
|
| 3431 | target.transAuthV6('apn_authentication');
|
| 3432 | target.transUserNameV6('apn_user_name');
|
| 3433 | target.transPasswordV6('apn_password');
|
| 3434 | } else if (config.IPV4_AND_V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
|
| 3435 | target.transApn('apn_ipv4_apn');
|
| 3436 | target.transDnsMode('apn_dns_mode_ipv4');
|
| 3437 | target.transDns1('apn_dns1_ipv4');
|
| 3438 | target.transDns2('apn_dns2_ipv4');
|
| 3439 | target.transAuth('apn_authentication_ipv4');
|
| 3440 | target.transUserName('apn_user_name_ipv4');
|
| 3441 | target.transPassword('apn_password_ipv4');
|
| 3442 |
|
| 3443 | target.transApnV6('apn_ipv6_apn');
|
| 3444 | target.transDnsModeV6('apn_dns_mode_ipv6');
|
| 3445 | target.transDns1V6('apn_dns1_ipv6');
|
| 3446 | target.transDns2V6('apn_dns2_ipv6');
|
| 3447 | target.transAuthV6('apn_authentication_ipv6');
|
| 3448 | target.transUserNameV6('apn_user_name_ipv6');
|
| 3449 | target.transPasswordV6('apn_password_ipv6');
|
| 3450 | } else if (target.selectedPdpType() == "IP" || target.selectedPdpType() == "IPv4") {
|
| 3451 | target.transApn('apn');
|
| 3452 | target.transDnsMode('apn_dns_mode');
|
| 3453 | target.transDns1('apn_dns1');
|
| 3454 | target.transDns2('apn_dns2');
|
| 3455 | target.transAuth('apn_authentication');
|
| 3456 | target.transUserName('apn_user_name');
|
| 3457 | target.transPassword('apn_password');
|
| 3458 | } else { //config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6'
|
| 3459 | target.transApn('apn');
|
| 3460 | target.transDnsMode('apn_dns_mode');
|
| 3461 | target.transDns1('apn_dns1');
|
| 3462 | target.transDns2('apn_dns2');
|
| 3463 | target.transAuth('apn_authentication');
|
| 3464 | target.transUserName('apn_user_name');
|
| 3465 | target.transPassword('apn_password');
|
| 3466 | }
|
| 3467 | $("#apn_setting_form").translate();
|
| 3468 | });
|
| 3469 |
|
| 3470 | target.autoApnChecked = ko.computed(function () {
|
| 3471 | return target.apnMode() == "auto";
|
| 3472 | });
|
| 3473 |
|
| 3474 | target.hasCapacity = ko.computed(function () {
|
| 3475 | if (target.profiles().length < config.maxApnNumber) {
|
| 3476 | return true;
|
| 3477 | } else {
|
| 3478 | return false;
|
| 3479 | }
|
| 3480 | });
|
| 3481 |
|
| 3482 | target.showDnsV6 = ko.computed(function () {
|
| 3483 | return target.dnsModeV6() == "manual";
|
| 3484 | });
|
| 3485 |
|
| 3486 | target.showDns = ko.computed(function () {
|
| 3487 | return target.dnsMode() == "manual";
|
| 3488 | });
|
| 3489 |
|
| 3490 |
|
| 3491 | checkDefaultProfileStatus();
|
| 3492 | target.checkInputDisable = ko.computed(function () {
|
| 3493 | if (target.apnMode() != "auto" && (target.predeterminedCfg() == false && target.defaultCfg() == true) && !isConnectedNetWork()) {
|
| 3494 | return false;
|
| 3495 | }
|
| 3496 | if (((target.apnMode() != "auto" && (target.predeterminedCfg() || target.defaultCfg()) && !target.disableProfile())) || target.apnMode() == "auto") {
|
| 3497 | return true;
|
| 3498 | }
|
| 3499 | if ((!target.disableProfile() || !(target.predeterminedCfg() || target.defaultCfg())) && target.apnMode() != "auto") {
|
| 3500 | return false;
|
| 3501 | }
|
| 3502 | return false;
|
| 3503 | });
|
| 3504 |
|
| 3505 | var data = service.getDeviceInfo();
|
| 3506 | target.pdpTypeChangeAlert = pdpTypeChangeAlertFunc;
|
| 3507 |
|
| 3508 |
|
| 3509 | target.showAutoApnDetail = ko.computed(function () {
|
| 3510 | if (target.apnMode() != "auto") {
|
| 3511 | return true;
|
| 3512 | } else {
|
| 3513 | return target.autoProfiles().length > 0;
|
| 3514 | }
|
| 3515 | });
|
| 3516 | //密码显示事件
|
| 3517 | target.showPasswordHandler = function () {
|
| 3518 | var checkbox = $("#showPassword:checked");
|
| 3519 | if (checkbox && checkbox.length == 0) {
|
| 3520 | target.showPassword(true);
|
| 3521 | } else {
|
| 3522 | target.showPassword(false);
|
| 3523 | }
|
| 3524 | };
|
| 3525 | //auto apn profile change 事件处理
|
| 3526 |
|
| 3527 | target.autoProfileChangeHandler = autoProfileChangeHandlerFunc;
|
| 3528 |
|
| 3529 |
|
| 3530 | //profile change 事件处理
|
| 3531 |
|
| 3532 | target.profileChangeHandler = profileChangeHandlerFunc;
|
| 3533 |
|
| 3534 |
|
| 3535 | //切换profile时重置下面的显示项
|
| 3536 | target.setUIData = setUIDataFunc;
|
| 3537 |
|
| 3538 |
|
| 3539 | //设置默认apn状态
|
| 3540 |
|
| 3541 | function checkDefaultProfileStatus() {
|
| 3542 | var index = getApnIndex();
|
| 3543 | //默认apn不允许编辑
|
| 3544 | if (target.apnMode() != "auto") { //当前选中与实际不一致的话
|
| 3545 | if (target.selectedProfile() != target.defApn()) {
|
| 3546 | target.defaultCfg(false);
|
| 3547 | } else {
|
| 3548 | target.defaultCfg(true); //默认APN
|
| 3549 | }
|
| 3550 | } else {
|
| 3551 | if (target.selectedAutoProfile() != target.defApn()) {
|
| 3552 | target.defaultCfg(false);
|
| 3553 | } else {
|
| 3554 | target.defaultCfg(true); //默认APN
|
| 3555 | }
|
| 3556 | }
|
| 3557 |
|
| 3558 | if (index >= config.defaultApnSize) {
|
| 3559 | target.predeterminedCfg(false);
|
| 3560 | } else {
|
| 3561 | target.predeterminedCfg(true); //预置APN
|
| 3562 | }
|
| 3563 | }
|
| 3564 |
|
| 3565 |
|
| 3566 | //设置为默认apn
|
| 3567 |
|
| 3568 | target.setDefaultAct = setDefaultActFunc;
|
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 | //APN mode change 事件处理
|
| 3573 |
|
| 3574 | target.apnModeChangeHandler = apnModeChangeHandlerFunc;
|
| 3575 |
|
| 3576 |
|
| 3577 | function doSetDefaultAct() {
|
| 3578 | var index = 0;
|
| 3579 | if (target.apnMode() != 'auto') {
|
| 3580 | index = getApnIndex();
|
| 3581 | target.selectedProfile($("#profile").val());
|
| 3582 | } else {
|
| 3583 | index = getAutoApnIndex();
|
| 3584 | target.selectedAutoProfile($("#autoProfile").val());
|
| 3585 | }
|
| 3586 | var selectedProfileDetail = target.getSelectedManualProfile();
|
| 3587 | service.setDefaultApn({
|
| 3588 | index: index,
|
| 3589 | apnMode: target.apnMode(),
|
| 3590 | pdpType: selectedProfileDetail.pdpType,
|
| 3591 |
|
| 3592 | profileName: selectedProfileDetail.profileName,
|
| 3593 | wanApn: selectedProfileDetail.wanApn,
|
| 3594 | authMode: selectedProfileDetail.authMode,
|
| 3595 | username: selectedProfileDetail.username,
|
| 3596 | password: selectedProfileDetail.password,
|
| 3597 | dnsMode: config.SHOW_APN_DNS ? selectedProfileDetail.dnsMode : 'auto',
|
| 3598 | dns1: config.SHOW_APN_DNS ? selectedProfileDetail.dns1 : '',
|
| 3599 | dns2: config.SHOW_APN_DNS ? selectedProfileDetail.dns2 : ''
|
| 3600 | }, function (data) {
|
| 3601 | if (data.result) {
|
| 3602 | //showLoading("apn_alert_restart");
|
| 3603 | //restartDevice(service);
|
| 3604 | addTimeout(function () {
|
| 3605 | initialize(true);
|
| 3606 | target.apnModeChangeHandler();
|
| 3607 | successOverlay();
|
| 3608 | }, 500);
|
| 3609 | } else {
|
| 3610 | errorOverlay();
|
| 3611 | }
|
| 3612 | }, function (data) {
|
| 3613 | errorOverlay();
|
| 3614 | });
|
| 3615 | }
|
| 3616 |
|
| 3617 | target.getSelectedManualProfile = getSelectedManualProfileFunc;
|
| 3618 |
|
| 3619 |
|
| 3620 | //获取自动apn索引
|
| 3621 |
|
| 3622 | function getAutoApnIndex() {
|
| 3623 | var configs = $("#autoProfile option");
|
| 3624 | for (var ki = 0; ki < configs.length; ki++) {
|
| 3625 | if (configs[ki].value == target.selectedAutoProfile()) {
|
| 3626 | return ki;
|
| 3627 | }
|
| 3628 | }
|
| 3629 | return configs.length - 1;
|
| 3630 | }
|
| 3631 |
|
| 3632 | //获取apn索引
|
| 3633 |
|
| 3634 | function getApnIndex() {
|
| 3635 | var configs = $("#profile option");
|
| 3636 | if (configs.length == 0) {
|
| 3637 | configs = target.profiles();
|
| 3638 | }
|
| 3639 | var ki = 0;
|
| 3640 | for (; ki < configs.length; ki++) {
|
| 3641 | if (configs[ki].value == target.selectedProfile()) {
|
| 3642 | break;
|
| 3643 | }
|
| 3644 | }
|
| 3645 | return ki;
|
| 3646 | }
|
| 3647 |
|
| 3648 | //保存APN设置信息
|
| 3649 |
|
| 3650 | target.saveAct = saveActFunc;
|
| 3651 |
|
| 3652 | //编辑APN信息
|
| 3653 |
|
| 3654 | function editApnSetting(preAct) { //默认设置按钮触发为TRUE
|
| 3655 | showLoading();
|
| 3656 | var apnIndex = getApnIndex();
|
| 3657 | var sameInfo = false;
|
| 3658 | if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
|
| 3659 | sameInfo = true;
|
| 3660 | }
|
| 3661 | var needDoDefault = false;
|
| 3662 | if (preAct || (target.predeterminedCfg() || target.defaultCfg())) {
|
| 3663 | needDoDefault = true;
|
| 3664 | }
|
| 3665 | service.addOrEditApn({
|
| 3666 | profileName: target.profileName(),
|
| 3667 | pdpType: target.selectedPdpType(),
|
| 3668 | index: apnIndex,
|
| 3669 |
|
| 3670 | wanApn: target.apn(),
|
| 3671 | authMode: target.selectedAuthentication(),
|
| 3672 | username: target.username(),
|
| 3673 | password: target.password(),
|
| 3674 | dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
|
| 3675 | dns1: config.SHOW_APN_DNS ? target.dns1() : '',
|
| 3676 | dns2: config.SHOW_APN_DNS ? target.dns2() : '',
|
| 3677 |
|
| 3678 | wanApnV6: sameInfo ? target.apn() : target.apnV6(),
|
| 3679 | authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
|
| 3680 | usernameV6: sameInfo ? target.username() : target.usernameV6(),
|
| 3681 | passwordV6: sameInfo ? target.password() : target.passwordV6(),
|
| 3682 | dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
|
| 3683 | dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
|
| 3684 | dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
|
| 3685 | }, function (data) {
|
| 3686 | if (data.result) {
|
| 3687 | apnSettings = getApnSet();
|
| 3688 | if (target.profileName() != target.selectedProfile()) {
|
| 3689 | var newProfileName = target.profileName();
|
| 3690 | target.profiles(getProfileOptions(apnSettings.apnConfigs));
|
| 3691 | $('#profile').val(newProfileName).trigger('change');
|
| 3692 | }
|
| 3693 | if (needDoDefault == false) {
|
| 3694 | successOverlay();
|
| 3695 | } else {
|
| 3696 | doSetDefaultAct();
|
| 3697 | }
|
| 3698 | } else {
|
| 3699 | errorOverlay();
|
| 3700 | }
|
| 3701 | }, function (data) {
|
| 3702 | errorOverlay();
|
| 3703 | });
|
| 3704 | }
|
| 3705 |
|
| 3706 | //新增APN信息
|
| 3707 |
|
| 3708 | function addNewApnSetting() {
|
| 3709 | showLoading("waiting");
|
| 3710 | var optionLen = $("option", "#profile").length;
|
| 3711 | if (optionLen < config.defaultApnSize) {
|
| 3712 | errorOverlay();
|
| 3713 | return;
|
| 3714 | }
|
| 3715 | // 支持IPv4v6,并且选择IPv4v6时,IPv4 与 IPv6下发相同的信息
|
| 3716 | // 支持IPv4 & v6,并且选择IPv4v6时,IPv4 与 IPv6下发各自的信息
|
| 3717 | var sameInfo = false;
|
| 3718 | if (config.IPV4V6_SUPPORT && target.selectedPdpType() == 'IPv4v6') {
|
| 3719 | sameInfo = true;
|
| 3720 | }
|
| 3721 |
|
| 3722 | service.addOrEditApn({
|
| 3723 | profileName: target.profileName(),
|
| 3724 | pdpType: target.selectedPdpType(),
|
| 3725 | index: optionLen,
|
| 3726 |
|
| 3727 | wanApn: target.apn(),
|
| 3728 | authMode: target.selectedAuthentication(),
|
| 3729 | username: target.username(),
|
| 3730 | password: target.password(),
|
| 3731 | dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
|
| 3732 | dns1: config.SHOW_APN_DNS ? target.dns1() : '',
|
| 3733 | dns2: config.SHOW_APN_DNS ? target.dns2() : '',
|
| 3734 |
|
| 3735 | wanApnV6: sameInfo ? target.apn() : target.apnV6(),
|
| 3736 | authModeV6: sameInfo ? target.selectedAuthentication() : target.selectedAuthenticationV6(),
|
| 3737 | usernameV6: sameInfo ? target.username() : target.usernameV6(),
|
| 3738 | passwordV6: sameInfo ? target.password() : target.passwordV6(),
|
| 3739 | dnsModeV6: config.SHOW_APN_DNS ? (sameInfo ? target.dnsMode() : target.dnsModeV6()) : 'auto',
|
| 3740 | dns1V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns1() : target.dns1V6()) : '',
|
| 3741 | dns2V6: config.SHOW_APN_DNS ? (sameInfo ? target.dns2() : target.dns2V6()) : ''
|
| 3742 | }, function (data) {
|
| 3743 | if (data.result) {
|
| 3744 | apnSettings = getApnSet();
|
| 3745 | if (target.profileName() != target.selectedProfile()) {
|
| 3746 | var newProfileName = target.profileName();
|
| 3747 | target.profiles(getProfileOptions(apnSettings.apnConfigs));
|
| 3748 | $('#profile').val(newProfileName).trigger('change');
|
| 3749 | }
|
| 3750 | doSetDefaultAct();
|
| 3751 | } else {
|
| 3752 | errorOverlay();
|
| 3753 | }
|
| 3754 | }, function (data) {
|
| 3755 | errorOverlay();
|
| 3756 | });
|
| 3757 | }
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 | var tempApn = {};
|
| 3762 | //删除APN
|
| 3763 |
|
| 3764 | target.deleteAct = deleteActFunc;
|
| 3765 |
|
| 3766 | //取消新增APN
|
| 3767 |
|
| 3768 | target.cancelAddAct = cancelAddActFunc;
|
| 3769 |
|
| 3770 | //进入新增APN页面
|
| 3771 |
|
| 3772 | target.addAct = addActFunc;
|
| 3773 | //进入新增APN页面
|
| 3774 | function addActFunc() {
|
| 3775 | clearValidateMsg('#apn_setting_form');
|
| 3776 | target.pdpTypeNote(true);
|
| 3777 | target.disableProfile(true);
|
| 3778 | target.addApnHide(true);
|
| 3779 | tempApn = {
|
| 3780 | profileName: target.profileName(),
|
| 3781 | selectedPdpType: target.selectedPdpType(),
|
| 3782 |
|
| 3783 | wanApnV6: target.apnV6(),
|
| 3784 | dnsModeV6: config.SHOW_APN_DNS ? target.dnsModeV6() : 'auto',
|
| 3785 | dns1V6: config.SHOW_APN_DNS ? target.dns1V6() : '',
|
| 3786 | dns2V6: config.SHOW_APN_DNS ? target.dns2V6() : '',
|
| 3787 | authModeV6: target.selectedAuthenticationV6(),
|
| 3788 | usernameV6: target.usernameV6(),
|
| 3789 | passwordV6: target.passwordV6(),
|
| 3790 |
|
| 3791 | wanApn: target.apn(),
|
| 3792 | dnsMode: config.SHOW_APN_DNS ? target.dnsMode() : 'auto',
|
| 3793 | dns1: config.SHOW_APN_DNS ? target.dns1() : '',
|
| 3794 | dns2: config.SHOW_APN_DNS ? target.dns2() : '',
|
| 3795 | authMode: target.selectedAuthentication(),
|
| 3796 | username: target.username(),
|
| 3797 | password: target.password(),
|
| 3798 |
|
| 3799 | };
|
| 3800 | target.profileName("");
|
| 3801 | target.selectedPdpType("IP");
|
| 3802 | target.selectedPdpTypeTmp("IP");
|
| 3803 |
|
| 3804 | target.apnV6("");
|
| 3805 | target.dnsModeV6("auto");
|
| 3806 | target.dns1V6("");
|
| 3807 | target.dns2V6("");
|
| 3808 | target.selectedAuthenticationV6("none");
|
| 3809 | target.usernameV6("");
|
| 3810 | target.passwordV6("");
|
| 3811 |
|
| 3812 | target.apn("");
|
| 3813 | target.dnsMode("auto");
|
| 3814 | target.dns1("");
|
| 3815 | target.dns2("");
|
| 3816 | target.selectedAuthentication("none");
|
| 3817 | target.username("");
|
| 3818 | target.password("");
|
| 3819 |
|
| 3820 | }
|
| 3821 |
|
| 3822 | //取消新增APN
|
| 3823 | function cancelAddActFunc() {
|
| 3824 | clearValidateMsg('#apn_setting_form');
|
| 3825 | target.pdpTypeNote(false);
|
| 3826 | target.disableProfile(false);
|
| 3827 | target.addApnHide(false);
|
| 3828 | target.profileName(tempApn.profileName);
|
| 3829 | target.selectedPdpType(tempApn.selectedPdpType);
|
| 3830 | target.selectedPdpTypeTmp(tempApn.selectedPdpType);
|
| 3831 |
|
| 3832 | target.apnV6(tempApn.wanApnV6);
|
| 3833 | target.dnsModeV6(tempApn.dnsModeV6);
|
| 3834 | target.dns1V6(tempApn.dns1V6);
|
| 3835 | target.dns2V6(tempApn.dns2V6);
|
| 3836 | target.selectedAuthenticationV6(tempApn.authModeV6);
|
| 3837 | target.usernameV6(tempApn.usernameV6);
|
| 3838 | target.passwordV6(tempApn.passwordV6);
|
| 3839 |
|
| 3840 | target.apn(tempApn.wanApn);
|
| 3841 | target.dnsMode(tempApn.dnsMode);
|
| 3842 | target.dns1(tempApn.dns1);
|
| 3843 | target.dns2(tempApn.dns2);
|
| 3844 | target.selectedAuthentication(tempApn.authMode);
|
| 3845 | target.username(tempApn.username);
|
| 3846 | target.password(tempApn.password);
|
| 3847 |
|
| 3848 | }
|
| 3849 |
|
| 3850 | //删除APN
|
| 3851 | function deleteActFunc() {
|
| 3852 | if (!target.selectedProfile()) {
|
| 3853 | showAlert("apn_no_select_alert");
|
| 3854 | return false;
|
| 3855 | }
|
| 3856 | if (target.predeterminedCfg()) { //预置的apn不允许删除
|
| 3857 | errorOverlay("apn_delete_cant_delete_default");
|
| 3858 | return false;
|
| 3859 | }
|
| 3860 | if (getApnSet().profileName == target.profileName()) {
|
| 3861 | errorOverlay("apn_cant_delete_current");
|
| 3862 | return false;
|
| 3863 | }
|
| 3864 |
|
| 3865 | showConfirm("apn_delete_confirm", function () {
|
| 3866 | showLoading('deleting');
|
| 3867 | service.deleteApn({
|
| 3868 | index: getApnIndex()
|
| 3869 | }, function (data) {
|
| 3870 | if (data.result) {
|
| 3871 | target.profiles(getProfileOptions(getApnSet().apnConfigs));
|
| 3872 | target.selectedProfile(target.defApn());
|
| 3873 | target.profileChangeHandler();
|
| 3874 | successOverlay();
|
| 3875 | } else {
|
| 3876 | errorOverlay();
|
| 3877 | }
|
| 3878 | }, function (data) {
|
| 3879 | errorOverlay();
|
| 3880 | });
|
| 3881 | });
|
| 3882 | }
|
| 3883 |
|
| 3884 | //保存APN设置信息
|
| 3885 | function saveActFunc() {
|
| 3886 | if (!$('#apn_setting_form').valid()) {
|
| 3887 | return false;
|
| 3888 | }
|
| 3889 | if (!target.selectedProfile() && !target.disableProfile()) { //不是增加时的设置需要判断是否选择了Profile
|
| 3890 | showAlert("apn_no_select_alert");
|
| 3891 | return false;
|
| 3892 | }
|
| 3893 | var exist = false;
|
| 3894 | $.each(target.profiles(), function (i, e) {
|
| 3895 | if (e.value == target.profileName()) {
|
| 3896 | exist = true;
|
| 3897 | }
|
| 3898 | });
|
| 3899 |
|
| 3900 | if (target.disableProfile() == false) {
|
| 3901 | if (exist && target.selectedProfile() != target.profileName()) {
|
| 3902 | showInfo("apn_save_profile_exist");
|
| 3903 | return false;
|
| 3904 | }
|
| 3905 | if (target.predeterminedCfg()) { //预置的APN不可以修改
|
| 3906 | errorOverlay();
|
| 3907 | return false;
|
| 3908 | }
|
| 3909 | if (target.predeterminedCfg() || target.defaultCfg()) {
|
| 3910 | //showConfirm("apn_alert", function () {
|
| 3911 | editApnSetting(false);
|
| 3912 | //});
|
| 3913 | } else {
|
| 3914 | editApnSetting(false);
|
| 3915 | }
|
| 3916 | } else {
|
| 3917 |
|
| 3918 | if ($("#profile option").length >= config.maxApnNumber) {
|
| 3919 | showInfo({
|
| 3920 | msg: "apn_profile_full",
|
| 3921 | params: [config.maxApnNumber]
|
| 3922 | });
|
| 3923 | return false;
|
| 3924 | }
|
| 3925 | if (exist) {
|
| 3926 | showInfo("apn_save_profile_exist");
|
| 3927 | return false;
|
| 3928 | }
|
| 3929 | var info = service.getStatusInfo();
|
| 3930 | if (info.connectStatus != "ppp_connected") {
|
| 3931 | //showConfirm("apn_alert", function () {
|
| 3932 | addNewApnSetting();
|
| 3933 | //});
|
| 3934 |
|
| 3935 | } else {
|
| 3936 | showConfirm("apn_diconneted_network_confirm", function () {
|
| 3937 | showLoading('disconnecting');
|
| 3938 | service.disconnect({}, function (data) {
|
| 3939 | if (data.result) {
|
| 3940 | config.connect_flag = true;
|
| 3941 | addNewApnSetting();
|
| 3942 | } else {
|
| 3943 | errorOverlay();
|
| 3944 | }
|
| 3945 | });
|
| 3946 | });
|
| 3947 | }
|
| 3948 | }
|
| 3949 | }
|
| 3950 |
|
| 3951 | function getSelectedManualProfileFunc() {
|
| 3952 | var cfg = {};
|
| 3953 | var profileVal = $("#profile").val();
|
| 3954 | if (typeof target.selectedProfile() == 'undefined') {
|
| 3955 | target.selectedProfile(profileVal);
|
| 3956 | }
|
| 3957 | var cfgV4 = apnConfigs[profileVal];
|
| 3958 | var cfgV6 = ipv6ApnConfigs[profileVal];
|
| 3959 | if (cfgV4 && !cfgV6) {
|
| 3960 | $.extend(cfg, cfgV4);
|
| 3961 | } else if (cfgV4 && cfgV6) {
|
| 3962 | if (!!cfgV4.pdpType) {
|
| 3963 | $.extend(cfg, cfgV6);
|
| 3964 | $.extend(cfg, cfgV4);
|
| 3965 | } else {
|
| 3966 | $.extend(cfg, cfgV4);
|
| 3967 | $.extend(cfg, cfgV6);
|
| 3968 | }
|
| 3969 | }
|
| 3970 | return cfg;
|
| 3971 | }
|
| 3972 |
|
| 3973 | //APN mode change 事件处理
|
| 3974 | function apnModeChangeHandlerFunc(data, event) {
|
| 3975 | if (target.apnMode() != 'auto') {
|
| 3976 | target.profileChangeHandler();
|
| 3977 | } else {
|
| 3978 | if (target.showAutoApnDetail()) {
|
| 3979 | target.autoProfileChangeHandler();
|
| 3980 | }
|
| 3981 | }
|
| 3982 | return true;
|
| 3983 | }
|
| 3984 |
|
| 3985 | //设置为默认apn
|
| 3986 | function setDefaultActFunc() {
|
| 3987 | if (!target.selectedProfile()) {
|
| 3988 | showAlert("apn_no_select_alert");
|
| 3989 | return false;
|
| 3990 | }
|
| 3991 | var connectStatus = service.getConnectionInfo().connectStatus;
|
| 3992 | if (connectStatus == "ppp_connecting") {
|
| 3993 | showAlert({
|
| 3994 | msg: "apn_cant_modify_status",
|
| 3995 | params: [$.i18n.prop("connecting").toLowerCase()]
|
| 3996 | });
|
| 3997 | return false;
|
| 3998 | } else if (connectStatus == "ppp_disconnecting") {
|
| 3999 | showAlert({
|
| 4000 | msg: "apn_cant_modify_status",
|
| 4001 | params: [$.i18n.prop("disconnecting").toLowerCase()]
|
| 4002 | });
|
| 4003 | return false;
|
| 4004 | } else if (connectStatus == "ppp_connected") {
|
| 4005 | showAlert({
|
| 4006 | msg: "apn_cant_modify_status",
|
| 4007 | params: [$.i18n.prop("connected").toLowerCase()]
|
| 4008 | });
|
| 4009 | return false;
|
| 4010 | }
|
| 4011 | if (target.apnMode() == 'auto' || target.predeterminedCfg()) {
|
| 4012 | //showConfirm("apn_alert", function () {
|
| 4013 | showLoading("waiting");
|
| 4014 | doSetDefaultAct();
|
| 4015 | //});
|
| 4016 | } else {
|
| 4017 | if ($('#apn_setting_form').valid() == false) {
|
| 4018 | $(".error:first", "#apn_setting_form").focus();
|
| 4019 | } else {
|
| 4020 | var exist = false;
|
| 4021 | $.each(target.profiles(), function (i, e) {
|
| 4022 | if (e.value == target.profileName()) {
|
| 4023 | exist = true;
|
| 4024 | }
|
| 4025 | });
|
| 4026 | if (exist && target.selectedProfile() != target.profileName()) {
|
| 4027 | showInfo("apn_save_profile_exist");
|
| 4028 | return false;
|
| 4029 | }
|
| 4030 | //showLoading("waiting");
|
| 4031 | //showConfirm("apn_alert", function () {
|
| 4032 | editApnSetting(true);
|
| 4033 | //});
|
| 4034 | }
|
| 4035 | }
|
| 4036 | }
|
| 4037 |
|
| 4038 | //切换profile时重置下面的显示项
|
| 4039 | function setUIDataFunc(data) {
|
| 4040 | clearValidateMsg('#apn_setting_form');
|
| 4041 | if (!data) {
|
| 4042 | return;
|
| 4043 | }
|
| 4044 | target.selectedPdpType(data.pdpType || 'IP');
|
| 4045 | target.selectedPdpTypeTmp(data.pdpType || 'IP');
|
| 4046 | target.profileName(data.profileName);
|
| 4047 |
|
| 4048 | target.apn(data.wanApn);
|
| 4049 | target.dnsMode(data.dnsMode != 'manual' ? 'auto' : 'manual');
|
| 4050 | target.dns1(data.dns1);
|
| 4051 | target.dns2(data.dns2);
|
| 4052 | target.username(data.username);
|
| 4053 | target.password(data.password);
|
| 4054 | target.selectedAuthentication(data.authMode || 'none');
|
| 4055 |
|
| 4056 | target.apnV6(data.wanApnV6);
|
| 4057 | target.dnsModeV6(data.dnsModeV6 != 'manual' ? 'auto' : 'manual');
|
| 4058 | target.dns1V6(data.dns1V6);
|
| 4059 | target.dns2V6(data.dns2V6);
|
| 4060 | target.usernameV6(data.usernameV6);
|
| 4061 | target.passwordV6(data.passwordV6);
|
| 4062 | target.selectedAuthenticationV6(data.authModeV6 || 'none');
|
| 4063 | }
|
| 4064 |
|
| 4065 | //profile change 事件处理
|
| 4066 | function profileChangeHandlerFunc(data, event) {
|
| 4067 | target.pdpTypeNote(true);
|
| 4068 | if (target.apnMode() != 'manual') {
|
| 4069 | return true;
|
| 4070 | }
|
| 4071 | var cfg = target.getSelectedManualProfile();
|
| 4072 | target.setUIData(cfg);
|
| 4073 | checkDefaultProfileStatus();
|
| 4074 | return true;
|
| 4075 | }
|
| 4076 |
|
| 4077 | //auto apn profile change 事件处理
|
| 4078 | function autoProfileChangeHandlerFunc(data, event) {
|
| 4079 | if (target.apnMode() != 'auto') {
|
| 4080 | return true;
|
| 4081 | }
|
| 4082 | var cfg = autoApnConfigs[target.selectedAutoProfile()];
|
| 4083 | target.setUIData(cfg);
|
| 4084 | checkDefaultProfileStatus();
|
| 4085 | return true;
|
| 4086 | }
|
| 4087 |
|
| 4088 | function pdpTypeChangeAlertFunc() {
|
| 4089 | if (target.pdpTypeNote()) {
|
| 4090 | showAlert({
|
| 4091 | msg: "apn_pdptype_change_note",
|
| 4092 | params: [data.lanDomain, data.ipAddress]
|
| 4093 | });
|
| 4094 | }
|
| 4095 | if (target.apnMode() != "auto" && !target.disableProfile()) { //如果是手动非ADD状态,切换PDP类型时,不改变界面显示的各项值
|
| 4096 | if ((config.IPV4_AND_V6_SUPPORT && target.selectedPdpTypeTmp() != 'IPv4v6' && target.selectedPdpType() != 'IPv4v6') || !config.IPV4_AND_V6_SUPPORT) { //
|
| 4097 | if (target.selectedPdpTypeTmp() == 'IPv6') { //V6 -> V4 / V4V6
|
| 4098 | target.apn(target.apnV6());
|
| 4099 | target.dnsMode(target.dnsModeV6());
|
| 4100 | target.dns1(target.dns1V6());
|
| 4101 | target.dns2(target.dns2V6());
|
| 4102 | target.username(target.usernameV6());
|
| 4103 | target.password(target.passwordV6());
|
| 4104 | target.selectedAuthentication(target.selectedAuthenticationV6());
|
| 4105 | } else if (target.selectedPdpType() == 'IPv6') { //V4 / V4V6 -> V6
|
| 4106 | target.apnV6(target.apn());
|
| 4107 | target.dnsModeV6(target.dnsMode());
|
| 4108 | target.dns1V6(target.dns1());
|
| 4109 | target.dns2V6(target.dns2());
|
| 4110 | target.usernameV6(target.username());
|
| 4111 | target.passwordV6(target.password());
|
| 4112 | target.selectedAuthenticationV6(target.selectedAuthentication());
|
| 4113 | }
|
| 4114 | }
|
| 4115 | }
|
| 4116 | target.selectedPdpTypeTmp(target.selectedPdpType());
|
| 4117 | }
|
| 4118 |
|
| 4119 |
|
| 4120 | }
|
| 4121 |
|
| 4122 | //是否已联网
|
| 4123 |
|
| 4124 | function isConnectedNetWork() {
|
| 4125 | var info = service.getConnectionInfo();
|
| 4126 | return info.connectStatus == "ppp_connected";
|
| 4127 | }
|
| 4128 |
|
| 4129 | function initVar() {
|
| 4130 | apnConfigs = {};
|
| 4131 | ipv6ApnConfigs = {};
|
| 4132 | autoApnConfigs = {};
|
| 4133 | }
|
| 4134 | function bindContainer(vm){
|
| 4135 | var container = $('#container');
|
| 4136 | ko.cleanNode(container[0]);
|
| 4137 | ko.applyBindings(vm, container[0]);
|
| 4138 | }
|
| 4139 | //初始化ViewModel
|
| 4140 |
|
| 4141 | function initialize(formInit) {
|
| 4142 | initVar();
|
| 4143 |
|
| 4144 | var vm = new APNViewModel();
|
| 4145 | bindContainer(vm);
|
| 4146 |
|
| 4147 | if (!formInit) {
|
| 4148 | addInterval(function () {
|
| 4149 | vm.setDefaultVisible(!isConnectedNetWork());
|
| 4150 | }, 1000);
|
| 4151 | }
|
| 4152 | $('#apn_setting_form').validate({
|
| 4153 | submitHandler: function () {
|
| 4154 | vm.saveAct();
|
| 4155 | },
|
| 4156 | rules: {
|
| 4157 | profile_name: 'apn_profile_name_check',
|
| 4158 | apn_ipv4_apn: 'apn_check',
|
| 4159 | apn_dns1_ipv4: "ipv4",
|
| 4160 | apn_dns2_ipv4: "ipv4",
|
| 4161 | apn_ipv6_apn: 'apn_check',
|
| 4162 | apn_dns1_ipv6: "ipv6",
|
| 4163 | apn_dns2_ipv6: "ipv6",
|
| 4164 | apn_user_name_ipv4: 'ppp_username_check',
|
| 4165 | apn_secretcode_ipv4: 'ppp_secretcode_check',
|
| 4166 | apn_user_name_ipv6: 'ppp_username_check',
|
| 4167 | apn_secretcode_ipv6: 'ppp_secretcode_check'
|
| 4168 | }
|
| 4169 | });
|
| 4170 | }
|
| 4171 |
|
| 4172 | return {
|
| 4173 | init: initialize
|
| 4174 | };
|
| 4175 | }); |