Skip to content

Commit

Permalink
network_manager: the ip detection was fixed.
Browse files Browse the repository at this point in the history
The IP parser changes:
* The first IP is used for displaying, the link-local IP are ignored.
* The link-local IP is used when no other IP was found.
  • Loading branch information
KonstantinSudakov committed Jan 24, 2019
1 parent 129707a commit 15d02d7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps-tools/network_manager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<script src="../assets/popupstack.js"></script>
<script src="../assets/help-system/help-system.js"></script>
<script src="js/help-nm.js"></script>
<script src="js/manager.js?3"></script>
<script src="js/manager.js?4"></script>
<script src="js/analytics-main.js"></script>
</head>

Expand Down
56 changes: 44 additions & 12 deletions apps-tools/network_manager/js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,56 @@
});
};

WIZARD.GetFirstAddress = function(obj) {
var ip = null;
var mask = null;

for (var i = 0; i < obj.length; ++i) {
ip = obj[i].split(" ")[1].split("/")[0];
mask = obj[i].split(" ")[1].split("/")[1];

// Link-local address checking.
// Do not use it if it is not the only one.
if (!ip.startsWith("169.254.")) {
// Return the first address.
break;
}
}

return {ip: ip, mask: mask};
};

WIZARD.ParseAddress = function(text) {
// inet ip/mask
var infoRegexp = /inet\s+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/\d+/g;
var infoMatch = text.match(infoRegexp);
var ip = null;
var mask = null;

if (infoMatch !== null) {
var info = WIZARD.GetFirstAddress(infoMatch);
ip = info.ip;
mask = info.mask;
}

return {ip: ip, mask: mask};
};

WIZARD.GetWlan0Status = function() {
$.ajax({
url: '/get_wlan0_status',
type: 'GET'
}).success(function(msg) {
var IPaddr = msg.match(/inet\s+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/2[0-90]\b/);
var info = WIZARD.ParseAddress(msg);

if (IPaddr == null) {
if ((info.ip === null) || (info.mask === null)) {
if (!WIZARD.WIFIConnected && !WIZARD.accessPointCreated){
$('#wlan0_address_label').text("None");
}
return;
}

IPaddr = IPaddr[0].split(" ")[1].split("/")[0];
var Mask = msg.match(/inet\s+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/2[0-90]\b/);
Mask = Mask[0].split(" ")[1].split("/")[1];

$('#wlan0_address_label').text(IPaddr + " / " + Mask);
$('#wlan0_address_label').text("" + info.ip + " / " + info.mask);

}).done(function(msg) {});
};
Expand All @@ -164,13 +195,14 @@
url: '/get_eth0_status',
type: 'GET'
}).success(function(msg) {
var info = WIZARD.ParseAddress(msg);
var gateway = msg.split("gateway:")[1].split("\n")[0];
var IPaddr = msg.match(/inet\s+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/2[0-90]\b/);
IPaddr = IPaddr[0].split(" ")[1].split("/")[0];
var Mask = msg.match(/inet\s+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/2[0-90]\b/);
Mask = Mask[0].split(" ")[1].split("/")[1];

$('#eth0_address_label').text(IPaddr + " / " + Mask);
if (!gateway) {
gateway = "None";
}

$('#eth0_address_label').text((info.ip !== null && info.mask !== null) ? "" + info.ip + " / " + info.mask : "None");
$('#eth0_gateway_label').text(gateway);

}).done(function(msg) {});
Expand Down

0 comments on commit 15d02d7

Please sign in to comment.