0
0
mirror of https://github.com/urlgrey/hsmm-pi synced 2025-10-06 00:12:53 +02:00

Read olsrd hosts file instead of doing DNS lookups.

This commit is contained in:
Clayton Smith
2016-04-03 20:05:40 -04:00
parent f17beaf8fa
commit 3d94124b81
2 changed files with 37 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ class StatusController extends AppController {
public function index() {
$this->set('mesh_links', $this->get_mesh_info('links'));
$this->set('mesh_routes', $this->get_mesh_info('routes')['routes']);
$this->set('mesh_hosts', $this->get_mesh_hosts());
$this->set('mesh_services', $this->get_mesh_services());
$this->set('mesh_node_locations', $this->get_mesh_node_locations());
$this->load_node_attributes();
@@ -54,6 +55,33 @@ class StatusController extends AppController {
}
}
private function get_mesh_hosts() {
$hosts = array();
if (file_exists("/var/run/hosts_olsr")) {
$handle = @fopen("/var/run/hosts_olsr", "r");
if ($handle) {
while (($buffer = fgets($handle, 1024)) !== false) {
if ($buffer != null) {
$host_s = trim(substr($buffer, 0, strpos($buffer, '#')));
if (strlen($host_s) > 0) {
$host_parts = explode("\t", $host_s);
if (sizeof($host_parts) >= 2) {
$ip = $host_parts[0];
$name = $host_parts[1];
if (!array_key_exists($ip, $hosts)) {
$hosts[$ip] = $name;
}
}
}
}
}
fclose($handle);
}
}
return $hosts;
}
private function get_mesh_services() {
$services = array();
if (file_exists("/var/run/services_olsr")) {

View File

@@ -49,10 +49,12 @@ if ($mesh_links != NULL && sizeof($mesh_links['links']) > 0) {
<th>Link Quality</th>
</tr>
<?php
$neighbor_ips = array();
foreach ($mesh_links['links'] as $node) {
$neighbor_ips[$node['remoteIP']] = 1;
?>
<tr>
<?php $node_hostname = gethostbyaddr($node['remoteIP']);?>
<?php $node_hostname = $mesh_hosts[$node['remoteIP']];?>
<td><a href="http://<?php echo $node_hostname;?>:8080/"><?php echo $node_hostname;?></a>
<?php
if (array_key_exists($node['remoteIP'], $mesh_node_locations)) {
@@ -100,10 +102,13 @@ if ($mesh_routes != NULL && sizeof($mesh_routes) > 0) {
</tr>
<?php
foreach ($mesh_routes as $node) {
$node_hostname = gethostbyaddr($node['destination']);
if (substr($node_hostname, 0, 8) === "dtdlink.") {
continue;
if ($node['genmask'] < 32) continue;
if (array_key_exists($node['destination'], $neighbor_ips)) continue;
$node_hostname = $mesh_hosts[$node['destination']];
if (!$node_hostname) {
$node_hostname = $node['destination'];
}
if (substr($node_hostname, 0, 8) === "dtdlink.") continue;
?>
<tr>
<td><a href="http://<?php echo $node_hostname;?>:8080/"><?php echo $node_hostname;?></a>