#!/usr/bin/perl =for commnet Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks 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 . 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. You must not misrepresent the origin of the material conained within. Modified versions must be modified to attribute to the original source and be marked in reasonable ways as differentiate it from the original version. =cut # 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);