How to use ports method in mountebank

Best JavaScript code snippet using mountebank

port_forward_tr069.js

Source:port_forward_tr069.js Github

copy

Full Screen

1import {anlixDocumentReady} from '../src/common.index.js';2import Validator from './device_validator.js';3import {setPortForwardStorage,4 getPortForwardStorage,5 deletePortForwardStorage} from './session_storage.js';6const t = i18next.t;7let triggerRedAlert = function(message) {8 if ($('#port-forward-tr069-modal-alert')[0].classList.contains('d-block')) {9 $('#port-forward-tr069-modal-alert')10 .append(11 $('<hr>'),12 )13 .append(14 $('<h5>')15 .html(message),16 );17 } else {18 $('#port-forward-tr069-modal-alert')19 .removeClass('d-none')20 .addClass('d-block')21 .html(22 $('<h5>')23 .html(message),24 );25 setTimeout(function() {26 $('#port-forward-tr069-modal-alert')27 .removeClass('d-block')28 .addClass('d-none');29 }, 2500);30 }31};32let showIncompatibilityMessage = function(compatibility) {33 let portInputs = $('.port-forward-tr069-port-input');34 let isRangeOfPorts = $('#port-forward-tr069-'+35 'range-of-ports-checkbox')[0];36 let isAsymOpening = $('#port-forward-tr069-asym-opening-checkbox')[0];37 let compatInfoDiv = $('#port-forward-tr069-modal-compat-info');38 let compatInfoMessage = $('#port-forward-tr069-modal-compat-info-message');39 let compatInfoList = $('#port-forward-tr069-modal-compat-info-list');40 let message = t('tr069PortOpenningIncompatibilityMessage', {41 model: getPortForwardStorage('model'),42 version: getPortForwardStorage('version'),43 });44 let show = false;45 compatInfoList.html('');46 if (!compatibility.simpleSymmetric) {47 show = true;48 compatInfoList.append(49 $('<li>').html(t('simpleSymmetric')),50 );51 }52 if (!compatibility.simpleAsymmetric) {53 show = true;54 compatInfoList.append(55 $('<li>').html(t('simpleAsymmetric')),56 );57 }58 if (!compatibility.rangeSymmetric) {59 show = true;60 compatInfoList.append(61 $('<li>').html(t('symmetricRangeOfPorts')),62 );63 }64 if (!compatibility.rangeAsymmetric) {65 show = true;66 compatInfoList.append(67 $('<li>').html(t('asymmetricRangeOfPorts')),68 );69 }70 message += '';71 if (show) {72 compatInfoDiv73 .removeClass('d-none')74 .addClass('d-block');75 compatInfoMessage76 .html(message);77 } else {78 compatInfoDiv79 .removeClass('d-block')80 .addClass('d-none');81 }82 if (!compatibility.simpleSymmetric) {83 portInputs[0].disabled = portInputs[1].disabled =84 portInputs[2].disabled = portInputs[3].disabled = true;85 }86 if (!compatibility.simpleAsymmetric) {87 isAsymOpening.disabled = true;88 }89 if (!compatibility.rangeSymmetric) {90 isRangeOfPorts.disabled = true;91 }92};93window.checkAdvancedOptions = function() {94 let compatibility = getPortForwardStorage('compatibility');95 let isRangeOfPorts = $('#port-forward-tr069-range-of-ports-checkbox')[0];96 let isAsymOpening = $('#port-forward-tr069-asym-opening-checkbox')[0];97 let advOptionsLabel = $('#port-forward-tr069-advanced-options-labels')[0];98 let portBox = $('.port-forward-tr069-port');99 let portLabel = $('.port-forward-tr069-port-label');100 let portInputs = $('.port-forward-tr069-port-input');101 if (compatibility.simpleSymmetric &&102 compatibility.simpleAsymmetric &&103 !compatibility.rangeAsymmetric) {104 if (isRangeOfPorts.checked) {105 isAsymOpening.disabled = true;106 } else {107 isAsymOpening.disabled = false;108 }109 if (isAsymOpening.checked) {110 isRangeOfPorts.disabled = true;111 } else {112 isRangeOfPorts.disabled = false;113 }114 }115 if (isRangeOfPorts.checked == false && isAsymOpening.checked == false) {116 advOptionsLabel.className = 'row d-none';117 portBox[1].className = portBox[2].className =118 portBox[3].className = 'col-md-2 col-4 port-forward-tr069-port d-none';119 portLabel[0].innerHTML = 'Porta';120 portInputs[1].value = portInputs[2].value = portInputs[3].value = '';121 } else if (isRangeOfPorts.checked != isAsymOpening.checked) {122 advOptionsLabel.className = 'row d-none';123 portBox[1].className = 'col-md-2 col-4 port-forward-tr069-port';124 portBox[2].className =125 portBox[3].className = 'col-md-2 col-4 port-forward-tr069-port d-none';126 portInputs[2].value = portInputs[3].value = '';127 if (isRangeOfPorts.checked) {128 portLabel[0].innerHTML = t('Initial');129 portLabel[1].innerHTML = t('Final');130 } else {131 portLabel[0].innerHTML = t('Source');132 portLabel[1].innerHTML = t('Destination');133 }134 } else if (isRangeOfPorts.checked == true && isAsymOpening.checked == true) {135 advOptionsLabel.className = 'row';136 portBox[1].className = portBox[2].className =137 portBox[3].className = 'col-md-2 col-4 port-forward-tr069-port';138 portLabel[0].innerHTML = portLabel[2].innerHTML = t('Initial');139 portLabel[1].innerHTML = portLabel[3].innerHTML = t('Final');140 }141};142let checkPortsValues = function(portsValues) {143 let i;144 let isPortsNumber = true;145 let isPortsOnRange = true;146 let isPortsNotEmpty = true;147 let isRangeOfSameSize = true;148 let isRangeNegative = true;149 let isRangeOfPorts =150 $('#port-forward-tr069-range-of-ports-checkbox')[0].checked;151 let isAsymOpening = $('#port-forward-tr069-asym-opening-checkbox')[0].checked;152 let checkUntil = 1;153 let portToCheck;154 if (isRangeOfPorts == isAsymOpening) {155 if (isRangeOfPorts) {156 checkUntil = 4;157 }158 } else {159 checkUntil = 2;160 }161 if (Array.isArray(portsValues)) {162 for (i = 0; i < checkUntil; i++) {163 portToCheck = portsValues[i];164 if (portToCheck == '') {165 isPortsNotEmpty = false;166 } else if (isNaN(parseInt(portToCheck))) {167 isPortsNumber = false;168 } else if (!(parseInt(portToCheck) >= 1 &&169 parseInt(portToCheck) <= 65535 &&170 parseInt(portToCheck) != 22 &&171 parseInt(portToCheck) != 23 &&172 parseInt(portToCheck) != 80 &&173 parseInt(portToCheck) != 443 &&174 parseInt(portToCheck) != 7547 &&175 parseInt(portToCheck) != 58000)) {176 isPortsOnRange = false;177 }178 }179 } else {180 isPortsNumber = false;181 }182 if (!isPortsNumber) {183 triggerRedAlert(t('portsShouldBeNumbers!'));184 } else {185 if (isRangeOfPorts) {186 let firstSlice = parseInt(portsValues[1]) - parseInt(portsValues[0]);187 if (isAsymOpening) {188 let secondSlice = parseInt(portsValues[3]) - parseInt(portsValues[2]);189 if (firstSlice != secondSlice) {190 isRangeOfSameSize = false;191 }192 if (firstSlice < 1 || secondSlice < 1) {193 isRangeNegative = false;194 }195 } else {196 if (firstSlice < 1) {197 isRangeNegative = false;198 }199 }200 }201 }202 if (!isPortsOnRange) {203 triggerRedAlert(t('tr069ValidPortsInstructions'));204 }205 if (!isPortsNotEmpty) {206 triggerRedAlert(t('fieldsShouldBeFilled!'));207 }208 if (!isRangeOfSameSize) {209 triggerRedAlert(t('portRangesAreDifferentInSize!'));210 }211 if (!isRangeNegative) {212 triggerRedAlert(t('portRangesHaveLimitsInverted'));213 }214 return (isPortsNumber && isPortsOnRange &&215 isPortsNotEmpty && isRangeOfSameSize && isRangeNegative);216};217window.removeOnePortMapping = function(input) {218 let ip = input.dataset['ip'];219 let portMapping = input.dataset['portMapping'];220 let listOfMappings = getPortForwardStorage('listOfMappings');221 let portsBadges = getPortForwardStorage('portsBadges-' + ip);222 let ports = portMapping.split(/-|:/).map((p) => parseInt(p));223 let isRangeOfPorts = portMapping.includes('-');224 if (portsBadges.length == 1) {225 window.removeSetOfPortMapping(input);226 } else {227 /* remove the one port mapping */228 portsBadges = portsBadges.filter((p) => {229 return p != portMapping;230 });231 if (ports.length == 1) {232 // 'ip' | 'ports[0]'233 listOfMappings = listOfMappings.filter((l) => {234 return l.external_port_start != ports[0];235 });236 } else if (ports.length == 2) {237 // 'ip' | 'ports[0]-ports[1]'238 if (isRangeOfPorts) {239 listOfMappings = listOfMappings.filter((l) => {240 return l.external_port_start != ports[0] &&241 l.external_port_end != ports[1];242 });243 } else {244 // 'ip' | 'ports[0]:ports[1]'245 listOfMappings = listOfMappings.filter((l) => {246 return l.external_port_start != ports[0] &&247 l.internal_port_start != ports[1];248 });249 }250 } else if (ports.length == 4) {251 // 'ip' | 'ports[0]-ports[1]:ports[2]-ports[3]'252 listOfMappings = listOfMappings.filter((l) => {253 return l.external_port_start != ports[0] &&254 l.external_port_end != ports[1] &&255 l.internal_port_start != ports[2] &&256 l.internal_port_end != ports[3];257 });258 } else {259 triggerRedAlert(t('unexpectedErrorHappened'));260 }261 /* *** */262 setPortForwardStorage('listOfMappings', listOfMappings);263 setPortForwardStorage('portsBadges-' + ip, portsBadges);264 $(input.parentElement).remove();265 }266};267window.removeSetOfPortMapping = function(input) {268 let ip = input.dataset['ip'];269 let portMappingTable = $('#port-forward-tr069-table');270 let listOfMappings = getPortForwardStorage('listOfMappings');271 listOfMappings = listOfMappings.filter((lm) => {272 return ip != lm.ip;273 });274 setPortForwardStorage('listOfMappings', listOfMappings);275 setPortForwardStorage('portsBadges-' + ip, null);276 portMappingTable.find('[data-ip="' + ip + '"]').remove();277};278window.removeAllPortMapping = function() {279 let portMappingTable = $('#port-forward-tr069-table');280 // get needful variables281 let deviceId = getPortForwardStorage('deviceId');282 let serialId = getPortForwardStorage('serialId');283 let model = getPortForwardStorage('model');284 let version = getPortForwardStorage('version');285 let lanSubnet = getPortForwardStorage('lanSubnet');286 let lanSubmask = getPortForwardStorage('lanSubmask');287 let compatibility = getPortForwardStorage('compatibility');288 // clean dom table and session storage289 portMappingTable.empty();290 deletePortForwardStorage();291 // return needful variables to session storage292 setPortForwardStorage('deviceId', deviceId);293 setPortForwardStorage('serialId', serialId);294 setPortForwardStorage('model', model);295 setPortForwardStorage('version', version);296 setPortForwardStorage('lanSubnet', lanSubnet);297 setPortForwardStorage('lanSubmask', lanSubmask);298 setPortForwardStorage('compatibility', compatibility);299};300let checkOverlappingPorts = function(ip, listOfMappings,301 ports, isRangeOfPorts) {302 let ret = false;303 let i;304 for (i = 0; i < listOfMappings.length; i++) {305 if (ports.length == 1) {306 if ((ports[0] >= listOfMappings[i].external_port_start &&307 ports[0] <= listOfMappings[i].external_port_end) ||308 (ip == listOfMappings[i].ip &&309 ports[0] >= listOfMappings[i].internal_port_start &&310 ports[0] <= listOfMappings[i].internal_port_end)) {311 ret = true;312 }313 } else if (ports.length == 2) {314 if (isRangeOfPorts) {315 if ((ports[0] >= listOfMappings[i].external_port_start &&316 ports[0] <= listOfMappings[i].external_port_end) ||317 (ports[1] >= listOfMappings[i].external_port_start &&318 ports[1] <= listOfMappings[i].external_port_end) ||319 (ip == listOfMappings[i].ip &&320 ports[0] >= listOfMappings[i].internal_port_start &&321 ports[0] <= listOfMappings[i].internal_port_end) ||322 (ip == listOfMappings[i].ip &&323 ports[1] >= listOfMappings[i].internal_port_start &&324 ports[1] <= listOfMappings[i].internal_port_end)) {325 ret = true;326 }327 } else {328 if ((ports[0] >= listOfMappings[i].external_port_start &&329 ports[0] <= listOfMappings[i].external_port_end) ||330 (ip == listOfMappings[i].ip &&331 ports[1] >= listOfMappings[i].internal_port_start &&332 ports[1] <= listOfMappings[i].internal_port_end)) {333 ret = true;334 }335 }336 } else if (ports.length == 4) {337 if ((ports[0] >= listOfMappings[i].external_port_start &&338 ports[0] <= listOfMappings[i].external_port_end) ||339 (ports[1] >= listOfMappings[i].external_port_start &&340 ports[1] <= listOfMappings[i].external_port_end) ||341 (ip == listOfMappings[i].ip &&342 ports[2] >= listOfMappings[i].internal_port_start &&343 ports[2] <= listOfMappings[i].internal_port_end) ||344 (ip == listOfMappings[i].ip &&345 ports[3] >= listOfMappings[i].internal_port_start &&346 ports[3] <= listOfMappings[i].internal_port_end)) {347 ret = true;348 }349 } else {350 triggerRedAlert(t('unexpectedErrorHappened'));351 }352 }353 return ret;354};355let putPortMapping = function(ip, ports) {356 /*357 listOfMappings: [{358 ip: String,359 external_port_start: Number,360 external_port_end: Number,361 internal_port_start: Number,362 internal_port_end: Number,363 }]364 */365 let i;366 let isOverlapping = false;367 let portMappingTable = $('#port-forward-tr069-table');368 let isRangeOfPorts = $('#port-forward-tr069-'+369 'range-of-ports-checkbox')[0].checked;370 let compatibility = getPortForwardStorage('compatibility');371 let listOfMappings = getPortForwardStorage('listOfMappings');372 let portsBadges = getPortForwardStorage('portsBadges-' + ip);373 if (portsBadges == null) {374 portsBadges = [];375 }376 if (listOfMappings == null) {377 listOfMappings = [];378 }379 isOverlapping = checkOverlappingPorts(ip, listOfMappings,380 ports, isRangeOfPorts);381 if (isOverlapping) {382 triggerRedAlert(t('portsAreOverlapping!'));383 return;384 } else {385 if (ports.length == 1) {386 // 'ip' | 'ports[0]'387 if (compatibility.simpleSymmetric) {388 portsBadges.push(ports[0].toString());389 listOfMappings.push({390 'ip': ip,391 'external_port_start': ports[0],392 'external_port_end': ports[0],393 'internal_port_start': ports[0],394 'internal_port_end': ports[0],395 });396 } else {397 triggerRedAlert(t('incompatibleOption!'));398 return;399 }400 } else if (ports.length == 2) {401 // 'ip' | 'ports[0]-ports[1]'402 if (isRangeOfPorts) {403 if (compatibility.rangeSymmetric) {404 portsBadges.push(ports[0].toString()+405 '-' + ports[1].toString());406 listOfMappings.push({407 'ip': ip,408 'external_port_start': ports[0],409 'external_port_end': ports[1],410 'internal_port_start': ports[0],411 'internal_port_end': ports[1],412 });413 } else {414 triggerRedAlert(t('incompatibleOption!'));415 return;416 }417 } else {418 // 'ip' | 'ports[0]:ports[1]'419 if (compatibility.simpleAsymmetric) {420 portsBadges.push(ports[0].toString()+421 ':' + ports[1].toString());422 listOfMappings.push({423 'ip': ip,424 'external_port_start': ports[0],425 'external_port_end': ports[0],426 'internal_port_start': ports[1],427 'internal_port_end': ports[1],428 });429 } else {430 triggerRedAlert(t('incompatibleOption!'));431 return;432 }433 }434 } else if (ports.length == 4) {435 // 'ip' | 'ports[0]-ports[1]:ports[2]-ports[3]'436 if (compatibility.rangeAsymmetric) {437 portsBadges.push(ports[0].toString()+438 '-' + ports[1].toString() +439 ':' + ports[2].toString() +440 '-' + ports[3].toString());441 listOfMappings.push({442 'ip': ip,443 'external_port_start': ports[0],444 'external_port_end': ports[1],445 'internal_port_start': ports[2],446 'internal_port_end': ports[3],447 });448 } else {449 triggerRedAlert(t('incompatibleOption!'));450 return;451 }452 } else {453 triggerRedAlert(t('unexpectedErrorHappened'));454 return;455 }456 let listOfBadges = $('<td>').addClass('align-items-center')457 .addClass('justify-content-center');458 for (i = 0; i < portsBadges.length; i++) {459 listOfBadges.append(460 $('<div>')461 .addClass('badge badge-primary badge-pill mr-2 mb-1')462 .append(463 $('<label>')464 .css('margin-top', '0.4rem')465 .addClass('mr-1')466 .html(467 portsBadges[i],468 ),469 )470 .append(471 $('<a>')472 .addClass('close')473 .attr('onclick', 'removeOnePortMapping(this)')474 .attr('data-ip', ip)475 .attr('data-port-mapping', portsBadges[i])476 .addClass('white-text')477 .html('&times;')),478 );479 }480 portMappingTable.find('[data-ip="' + ip + '"]').remove();481 portMappingTable.append(482 $('<tr>').append(483 $('<td>')484 .addClass('text-left')485 .append(486 $('<span>')487 .css('display', 'block')488 .html(ip),489 ),490 listOfBadges,491 $('<td>')492 .addClass('text-right')493 .append(494 $('<button>')495 .append(496 $('<div>')497 .addClass('fas fa-times fa-lg'),498 )499 .addClass('btn btn-sm btn-danger my-0 mr-0')500 .attr('type', 'button')501 .attr('onclick', 'removeSetOfPortMapping(this)')502 .attr('data-ip', ip),503 ),504 ).addClass('bounceIn')505 .attr('data-ip', ip),506 );507 setPortForwardStorage('listOfMappings', listOfMappings);508 setPortForwardStorage('portsBadges-' + ip, portsBadges);509 }510};511window.checkPortMappingInputs = function() {512 let i;513 let deviceIp = getPortForwardStorage('lanSubnet');514 let maskBits = getPortForwardStorage('lanSubmask');515 let ipAddressGiven = $('#port-forward-tr069-ip-address-input')[0].value;516 let portsInputs = $('.port-forward-tr069-port-input');517 let isAddressValid;518 let isPortsValid;519 let portsValues = [];520 let validator = new Validator();521 isAddressValid = validator.checkAddressSubnetRange(deviceIp,522 ipAddressGiven, maskBits);523 if (!isAddressValid) {524 triggerRedAlert(t('invalidIpAddress!'));525 } else {526 for (i = 0; i < portsInputs.length; i++) {527 portsValues.push(portsInputs[i].value);528 }529 isPortsValid = checkPortsValues(portsValues);530 portsValues = [];531 for (i = 0; i < portsInputs.length; i++) {532 if (!isNaN(parseInt(portsInputs[i].value))) {533 portsValues.push(parseInt(portsInputs[i].value));534 }535 }536 if (isAddressValid && isPortsValid) {537 putPortMapping(ipAddressGiven, portsValues);538 }539 }540};541let fillSessionStorage = function(rules) {542 let i;543 let portsBadges = {};544 let listOfIps = [];545 for (i = 0; i < rules.length; i++) {546 if (portsBadges[rules[i].ip] == undefined) {547 portsBadges[rules[i].ip] = [];548 listOfIps.push(rules[i].ip);549 }550 // build portsBadges list from list of mappings551 // 'ip' | 'ports[0]'552 if (rules[i].external_port_start ==553 rules[i].external_port_end &&554 rules[i].external_port_end ==555 rules[i].internal_port_start &&556 rules[i].internal_port_start ==557 rules[i].internal_port_end) {558 portsBadges[rules[i].ip].push(rules[i].external_port_start.toString());559 } else if (rules[i].external_port_start ==560 // 'ip' | 'ports[0]-ports[1]'561 rules[i].internal_port_start &&562 rules[i].external_port_start <563 rules[i].external_port_end) {564 portsBadges[rules[i].ip].push(''+565 rules[i].external_port_start.toString()+566 '-'+567 rules[i].external_port_end.toString(),568 );569 } else if (rules[i].external_port_start ==570 // 'ip' | 'ports[0]:ports[1]'571 rules[i].external_port_end &&572 rules[i].external_port_start !=573 rules[i].internal_port_start) {574 portsBadges[rules[i].ip].push(''+575 rules[i].external_port_start.toString()+576 ':'+577 rules[i].internal_port_start.toString(),578 );579 } else if (rules[i].external_port_start <580 // 'ip' | 'ports[0]-ports[1]:ports[2]-ports[3]'581 rules[i].external_port_end &&582 rules[i].internal_port_start <583 rules[i].internal_port_end) {584 portsBadges[rules[i].ip].push(''+585 rules[i].external_port_start.toString()+586 '-'+587 rules[i].external_port_end.toString()+588 ':'+589 rules[i].internal_port_start.toString()+590 '-'+591 rules[i].internal_port_end.toString(),592 );593 }594 for (let li of listOfIps) {595 setPortForwardStorage('listOfMappings', rules);596 setPortForwardStorage('portsBadges-' + li, portsBadges[li]);597 buildMappingTable(li);598 }599 }600};601let buildMappingTable = function(ip) {602 let portsBadges = getPortForwardStorage('portsBadges-' + ip);603 let portMappingTable = $('#port-forward-tr069-table');604 let listOfBadges = $('<td>').addClass('align-items-center')605 .addClass('justify-content-center');606 for (let i = 0; i < portsBadges.length; i++) {607 listOfBadges.append(608 $('<div>')609 .addClass('badge badge-primary badge-pill mr-2 mb-1')610 .append(611 $('<label>')612 .css('margin-top', '0.4rem')613 .addClass('mr-1')614 .html(615 portsBadges[i],616 ),617 )618 .append(619 $('<a>')620 .addClass('close')621 .attr('onclick', 'removeOnePortMapping(this)')622 .attr('data-ip', ip)623 .attr('data-port-mapping', portsBadges[i])624 .addClass('white-text')625 .html('&times;')),626 );627 }628 portMappingTable.find('[data-ip="' + ip + '"]').remove();629 portMappingTable.append(630 $('<tr>').append(631 $('<td>')632 .addClass('text-left')633 .append(634 $('<span>')635 .css('display', 'block')636 .html(ip),637 ),638 listOfBadges,639 $('<td>')640 .addClass('text-right')641 .append(642 $('<button>')643 .append(644 $('<div>')645 .addClass('fas fa-times fa-lg'),646 )647 .addClass('btn btn-sm btn-danger my-0 mr-0')648 .attr('type', 'button')649 .attr('onclick', 'removeSetOfPortMapping(this)')650 .attr('data-ip', ip),651 ),652 ).addClass('bounceIn')653 .attr('data-ip', ip),654 );655};656anlixDocumentReady.add(function() {657 $(document).on('click', '.btn-port-forward-tr069-modal', function(event) {658 let row = $(event.target).parents('tr');659 // clean modal660 let portMappingTable = $('#port-forward-tr069-table');661 let portInputs = $('.port-forward-tr069-port-input');662 for (let i = 0; i < portInputs.length; i++) {663 portInputs[i].value = '';664 }665 $('#port-forward-tr069-range-of-ports-checkbox')[0].checked = false;666 $('#port-forward-tr069-asym-opening-checkbox')[0].checked = false;667 $('#port-forward-tr069-ip-address-input')[0].value = '';668 portMappingTable.empty();669 deletePortForwardStorage();670 setPortForwardStorage('deviceId', row.data('deviceid'));671 setPortForwardStorage('serialId', row.data('serialid'));672 setPortForwardStorage('model', row.data('deviceModel'));673 setPortForwardStorage('version', row.data('deviceVersion'));674 setPortForwardStorage('lanSubnet', row.data('lanSubnet'));675 setPortForwardStorage('lanSubmask', row.data('lanSubmask'));676 $.ajax({677 type: 'GET',678 url: '/devicelist/uiportforward/' + getPortForwardStorage('deviceId'),679 dataType: 'json',680 success: function(res) {681 if (res.success) {682 fillSessionStorage(res.content);683 setPortForwardStorage('compatibility', res.compatibility);684 window.checkAdvancedOptions();685 $('#port-forward-tr069-main-label').text(686 getPortForwardStorage('serialId'));687 $('#port-forward-tr069-modal').modal('show');688 showIncompatibilityMessage(res.compatibility);689 if (res.xmlWarning) {690 $('#port-forward-tr069-modal-reboot-info')691 .removeClass('d-none')692 .addClass('d-block');693 } else {694 $('#port-forward-tr069-modal-reboot-info')695 .removeClass('d-block')696 .addClass('d-none');697 }698 } else {699 let badge = $(event.target).closest('.actions-opts')700 .find('.badge-warning');701 if (res.message) {702 badge.text(status + ': ' + res.message);703 badge.show();704 setTimeout(function() {705 badge.hide();706 }, 1500);707 }708 }709 },710 });711 });712 $(document).on('click', '#port-forward-tr069-submit-button',713 function(event) {714 $.ajax({715 type: 'POST',716 url: '/devicelist/uiportforward/' + getPortForwardStorage('deviceId'),717 dataType: 'json',718 data: JSON.stringify({719 'content': (getPortForwardStorage('listOfMappings') == null ?720 '[]' :721 JSON.stringify(getPortForwardStorage('listOfMappings'))),722 }),723 contentType: 'application/json',724 success: function(res) {725 if (res.success) {726 swal.fire({727 title: t('Success!'),728 icon: 'success',729 confirmButtonColor: '#4db6ac',730 });731 } else {732 swal.fire({733 title: t('failedToApplyPortOpenning'),734 text: res.message,735 icon: 'error',736 confirmButtonColor: '#4db6ac',737 });738 }739 },740 error: function(xhr, status, error) {741 swal.fire({742 title: t('failedToApplyPortOpenning'),743 text: error,744 icon: 'error',745 confirmButtonColor: '#4db6ac',746 });747 },748 });749 });...

Full Screen

Full Screen

Worker-thread-multi-port.js

Source:Worker-thread-multi-port.js Github

copy

Full Screen

1onmessage = function(event) {2 if (event.data == "noport") {3 if (event.ports && !event.ports.length)4 testPassed("event.ports is non-null and zero length when no port sent");5 else6 testFailed("event.ports is null or non-zero length when no port sent");7 } else if (event.data == "zero ports") {8 if (event.ports && !event.ports.length)9 testPassed("event.ports is non-null and zero length when empty array sent");10 else11 testFailed("event.ports is null or non-zero length when empty array sent");12 } else if (event.data == "two ports") {13 if (!event.ports) {14 testFailed("event.ports should be non-null when ports sent");15 return;16 }17 if (event.ports.length == 2)18 testPassed("event.ports contains two ports when two ports sent");19 else20 testFailed("event.ports contained " + event.ports.length + " when two ports sent");21 } else if (event.data == "failed ports") {22 if (event.ports.length == 2)23 testPassed("event.ports contains two ports when two ports re-sent after error");24 else25 testFailed("event.ports contained " + event.ports.length + " when two ports re-sent after error");26 } else if (event.data == "noargs") {27 try {28 postMessage();29 testFailed("postMessage() did not throw");30 } catch (e) {31 testPassed("postMessage() threw exception: " + e);32 }33 } else34 testFailed("Received unexpected message: " + event.data);35};36function testPassed(msg) {37 postMessage("PASS"+msg);38}39function testFailed(msg) {40 postMessage("FAIL"+msg);...

Full Screen

Full Screen

serial_getPorts.https.any.js

Source:serial_getPorts.https.any.js Github

copy

Full Screen

1// META: script=/resources/test-only-api.js2// META: script=/serial/resources/common.js3// META: script=resources/automation.js4serial_test(async (t, fake) => {5 fake.addPort();6 fake.addPort();7 let ports = await navigator.serial.getPorts();8 assert_equals(ports.length, 2);9 assert_true(ports[0] instanceof SerialPort);10 assert_true(ports[1] instanceof SerialPort);11}, 'getPorts() returns the set of configured fake ports');12serial_test(async (t, fake) => {13 fake.addPort();14 let portsFirst = await navigator.serial.getPorts();15 assert_equals(portsFirst.length, 1, 'first call returns one port');16 assert_true(portsFirst[0] instanceof SerialPort);17 let portsSecond = await navigator.serial.getPorts();18 assert_equals(portsSecond.length, 1, 'second call returns one port');19 assert_true(portsSecond[0] instanceof SerialPort);20 assert_true(portsFirst[0] === portsSecond[0]);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var request = require('request');3var assert = require('assert');4mb.create({5}, function (error) {6 assert.ifError(error);7 console.log('mountebank started');8 request({9 json: {10 {11 {12 equals: {13 }14 }15 {16 is: {17 }18 }19 }20 }21 }, function (error, response, body) {22 assert.ifError(error);23 console.log('Stub created');24 console.log(body);25 request({26 }, function (error, response, body) {27 assert.ifError(error);28 console.log('Request sent');29 console.log(body);30 request({31 }, function (error, response, body) {32 assert.ifError(error);33 console.log('Stub deleted');34 console.log(body);35 request({36 }, function (error, response, body) {37 assert.ifError(error);38 console.log('mountebank stopped');39 console.log(body);40 });41 });42 });43 });44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var fs = require('fs');3var port = 2525;4var imposters = JSON.parse(fs.readFileSync('imposters.json', 'utf8'));5mb.create(port, imposters, function (error, server) {6 if (error) {7 console.error(error);8 }9 else {10 console.log('mb running on port ' + port);11 }12});13{14 {15 {16 {17 "is": {18 "headers": {19 },20 "body": {21 }22 }23 }24 }25 }26}27mb.create(port, imposters, function (error, server) {28 if (error) {29 console.error(error);30 }31 else {32 console.log('mb running on port ' + port);33 mb.createImposter(3000, { protocol: "http" }, function (error, imposter) {34 if (error) {35 console.error(error);36 }37 else {38 console.log('imposter created on port 3000');39 }40 });41 }42});43mb.create(port, imposters, function (error, server) {44 if (error) {45 console.error(error);46 }47 else {48 console.log('mb running on port ' + port);49 mb.createImposter(3000, { protocol: "http" }, function (error, imposter) {50 if (error) {51 console.error(error);52 }53 else {54 console.log('imposter created on port 3000');55 }56 });57 }58});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank'),2 imposters = [{port: 3000, protocol: 'http'}];3mb.create(port, imposters, function (error) {4 console.log('Mountebank started on port %s', port);5});6var mb = require('mountebank'),7 config = 'config.json';8mb.create(port, config, function (error) {9 console.log('Mountebank started on port %s', port);10});11{12 {13 }14}15mb.create(port, imposters, callback)16mb.create(port, config, callback)17mb.create(port, imposters, config, callback)18mb.create(port, config, imposters, callback)19mb.create(port, imposters, config, options, callback)20mb.create(port, config, imposters, options, callback)21mb.create(port, imposters, options, callback)22mb.create(port, config, options, callback)23mb.create(port, options, callback)24mb.create(port, callback)25mb.create(port)26mb.create()27mb.create(options)28mb.create(options, callback)29mb.create(imposters, config, callback)30mb.create(imposters, config, options, callback)31mb.create(imposters, options, callback)32mb.create(config, callback)33mb.create(config, options, callback)34mb.create(imposters, callback)35mb.create(imposters, config, options, callback)36mb.create(imposters, options, callback)37mb.create(config, imposters, callback)38mb.create(config, imposters, options, callback)39mb.create(config, options, callback)40mb.create(imposters, config, options, callback)41mb.create(imposters, options, callback)42mb.create(config, imposters, options, callback)43mb.create(config, options, callback)44mb.create(imposters, config, options, callback)45mb.create(imposters, options, callback)46mb.create(config, imposters, options, callback)47mb.create(config, options, callback)48mb.create(imposters, config, options, callback)49mb.create(imposters, options, callback)50mb.create(config, imposters, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log'}, function (error, mbInstance) {3 if (error) {4 console.error('Error creating mbInstance', error);5 } else {6 console.log('mbInstance created', mbInstance);7 }8});9var mb = require('mountebank');10mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log'}, function (error, mbInstance) {11 if (error) {12 console.error('Error creating mbInstance', error);13 } else {14 console.log('mbInstance created', mbInstance);15 }16});17var mb = require('mountebank');18mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log'}, function (error, mbInstance) {19 if (error) {20 console.error('Error creating mbInstance', error);21 } else {22 console.log('mbInstance created', mbInstance);23 }24});25var mb = require('mountebank');26mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log'}, function (error, mbInstance) {27 if (error) {28 console.error('Error creating mbInstance', error);29 } else {30 console.log('mbInstance created', mbInstance);31 }32});33var mb = require('mountebank');34mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log'}, function (error, mbInstance) {35 if (error) {36 console.error('Error creating mbInstance', error);37 } else {38 console.log('mbInstance created', mbInstance);39 }40});41var mb = require('mountebank');42mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log'}, function (error, mbInstance) {43 if (error) {44 console.error('Error creating mbInstance', error);45 } else {46 console.log('mbInstance created', mbInstance);47 }48});49var mb = require('mount

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var mbPort = 2526;4var mb = mb.create({5});6mb.start().then(function () {7 mb.createImposter({port: port}, function (err, imposter) {8 imposter.addStub({9 {10 is: {11 }12 }13 }, function (err, stub) {14 console.log('stub added');15 });16 });17});18var mb = require('mountebank');19var port = 2525;20var mbPort = 2526;21var mb = mb.create({22});23mb.start().then(function () {24 mb.createImposter({port: port}, function (err, imposter) {25 imposter.addStub({26 {27 is: {28 }29 }30 }, function (err, stub) {31 console.log('stub added');32 });33 });34});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.create({allowInjection:true, debug:true}, function (error, mb) {3 if (error) {4 console.error('Failed to start mb', error);5 }6 else {7 console.log('mb started on port', mb.port);8 }9});10var mb = require('mountebank');11mb.create({allowInjection:true, debug:true}, function (error, mb) {12 if (error) {13 console.error('Failed to start mb', error);14 }15 else {16 console.log('mb started on port', mb.port);17 }18});19from mountebank import create20mb = create({allowInjection:true, debug:true})21print('mb started on port', mb.port)22mb = Mountebank.create({allowInjection:true, debug:true})23using Mountebank;24using System;25{26 {27 static void Main(string[] args)28 {29 var mb = Mountebank.Create(new MountebankOptions { AllowInjection = true, Debug = true });30 Console.WriteLine("mb started on port {0}", mb.Port);31 }32 }33}34using Mountebank;35using System;36{37 {38 static void Main(string[] args)39 {40 var mb = Mountebank.Create(new MountebankOptions { AllowInjection = true, Debug = true });41 Console.WriteLine("mb started on port {0}", mb.Port);42 }43 }44}45int main() {46 auto mb = Mountebank::Create({{ true, true }

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var assert = require('assert');3var request = require('request');4var port = 2525;5mb.create(port, function (error, mb) {6 assert.ifError(error);7 mb.post('/imposters', {8 stubs: [{9 predicates: [{10 equals: { path: '/test' }11 }],12 responses: [{13 is: { body: 'OK' }14 }]15 }]16 }, function (error, response) {17 assert.ifError(error);18 assert.ifError(error);19 assert.equal(body, 'OK');20 mb.del('/imposters', function (error) {21 assert.ifError(error);22 mb.stop(function (error) {23 assert.ifError(error);24 });25 });26 });27 });28});29var mb = require('mountebank');30var assert = require('assert');31var request = require('request');32var port = 2525;33mb.create(port, function (error, mb) {34 assert.ifError(error);35 mb.post('/imposters', {36 stubs: [{37 predicates: [{38 equals: { path: '/test' }39 }],40 responses: [{41 is: { body: 'OK' }42 }]43 }]44 }, function (error, response) {45 assert.ifError(error);46 assert.ifError(error);47 assert.equal(body, 'OK');48 mb.del('/imposters', function (error) {49 assert.ifError(error);50 mb.stop(function (error) {51 assert.ifError(error);52 });53 });54 });55 });56});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank'),2 stub = {3 predicates: [{4 equals: {5 }6 }],7 responses: [{8 is: {9 }10 }]11 };12mb.create(port, host, protocol, stub, function (error, response) {13 if (error) {14 console.log(error);15 } else {16 console.log(response);17 }18});19var mb = require('mountebank'),20 stub = {21 predicates: [{22 equals: {23 }24 }],25 responses: [{26 is: {27 }28 }]29 };30mb.create(port, host, protocol, stub, function (error, response) {31 if (error) {32 console.log(error);33 } else {34 console.log(response);35 }36});37var mb = require('mountebank'),38 stub = {39 predicates: [{40 equals: {41 }42 }],43 responses: [{44 is: {45 }46 }]47 };48mb.create(port, host, protocol, stub, function (error, response) {49 if (error) {50 console.log(error);51 } else {52 console.log(response);53 }54});55var mb = require('mountebank'),

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const mb = require('mountebank');3const client = require('./client');4const PORT = 2525;5const IMPOSTER_PORT = 3000;6describe('client', () => {7 let server;8 before(done => {9 mb.create({ port: PORT, pidfile: 'mb.pid', logfile: 'mb.log' }, () => {10 server = mb.create({11 });12 server.start(done);13 });14 });15 after(done => {16 server.stop(() => {17 mb.stop({ port: PORT }, done);18 });19 });20 it('should return a response', done => {21 const mock = {22 {23 {24 equals: {25 }26 }27 {28 is: {29 headers: {30 },31 body: JSON.stringify({ message: 'Hello World!' })32 }33 }34 }35 };36 server.addStub(mock, () => {37 client.get('/test', (err, res) => {38 assert.equal(res.statusCode, 200);39 assert.equal(res.headers['content-type'], 'application/json');40 assert.deepEqual(JSON.parse(res.body), { message: 'Hello World!' });41 done();42 });43 });44 });45});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful