2013-11-14 23:11:16 -07:00
|
|
|
#!/usr/bin/perl
|
2016-12-23 12:48:36 -07:00
|
|
|
=for comment
|
2015-01-18 12:36:49 -07:00
|
|
|
|
2015-03-09 17:39:04 -06:00
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
2015-01-18 12:36:49 -07:00
|
|
|
Copyright (C) 2015 Conrad Lara
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-03-09 17:39:04 -06:00
|
|
|
Additional Terms:
|
|
|
|
|
|
|
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
|
|
|
Attributions to the AREDN Project must be retained in the source code.
|
|
|
|
If importing this code into a new or existing project attribution
|
|
|
|
to the AREDN project must be added to the source code.
|
|
|
|
|
2016-12-23 22:23:58 -07:00
|
|
|
You must not misrepresent the origin of the material contained within.
|
2015-03-09 17:39:04 -06:00
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version.
|
|
|
|
|
2015-01-18 12:36:49 -07:00
|
|
|
=cut
|
2013-11-14 23:11:16 -07:00
|
|
|
|
|
|
|
# do nothing if olsrd is not running
|
|
|
|
exit if system "ps | grep -v grep | grep -q 'olsrd '";
|
|
|
|
|
|
|
|
($uptime) = `cat /proc/uptime` =~ /^(\d+)/;
|
|
|
|
|
|
|
|
# load the hosts file
|
|
|
|
foreach(`cat /var/run/hosts_olsr 2>/dev/null`)
|
|
|
|
{
|
|
|
|
next unless /^\d/;
|
|
|
|
($ip, $name, $junk, $originator, $mid) = split /\s+/, $_;
|
|
|
|
next unless $originator;
|
|
|
|
next if $originator eq "myself";
|
|
|
|
next unless ($ip eq $originator) or (defined $mid and $mid eq "(mid");
|
|
|
|
if($hosts{$ip}) { $hosts{$ip} .= "/$name" }
|
|
|
|
else { $hosts{$ip} = $name }
|
|
|
|
}
|
|
|
|
|
|
|
|
# find the current neighbors
|
|
|
|
foreach(`echo /links | nc 127.0.0.1 2006 2>/dev/null`)
|
|
|
|
{
|
|
|
|
next unless /^\d/;
|
|
|
|
($my_ip, $ip) = split /\s+/, $_;
|
|
|
|
$history{$ip}{age} = $uptime;
|
|
|
|
$history{$ip}{name} = $hosts{$ip};
|
|
|
|
}
|
|
|
|
|
|
|
|
exit unless keys %history;
|
|
|
|
|
|
|
|
# load and strip the current history
|
|
|
|
foreach(`cat /tmp/node.history 2>/dev/null`)
|
|
|
|
{
|
|
|
|
chomp;
|
|
|
|
($ip, $age, $name) = split / /, $_;
|
|
|
|
next unless $age;
|
|
|
|
next if $history{$ip};
|
|
|
|
next if $uptime - $age > 86400;
|
|
|
|
$name = "" unless $name;
|
|
|
|
$history{$ip}{age} = $age;
|
|
|
|
$history{$ip}{name} = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
# write the new history
|
|
|
|
open(FILE, ">/tmp/node.history") or exit;
|
|
|
|
foreach $ip (keys %history)
|
|
|
|
{
|
|
|
|
printf FILE "%s %s %s\n", $ip, $history{$ip}{age}, $history{$ip}{name};
|
|
|
|
}
|
|
|
|
close(FILE);
|