2013-11-14 23:11:16 -07:00
|
|
|
#!/usr/bin/perl -w -I/www/cgi-bin
|
2015-01-18 12:36:49 -07:00
|
|
|
=for commnet
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2015-01-18 12:36:49 -07:00
|
|
|
=cut
|
2013-11-14 23:11:16 -07:00
|
|
|
|
|
|
|
# this script generates the olsrd config file
|
|
|
|
# static part comes from /etc/config/olsrd.conf
|
|
|
|
# dynamic part depends on the node configuration
|
|
|
|
|
|
|
|
use perlfunc;
|
2015-05-06 22:46:25 -06:00
|
|
|
use ucifunc;
|
2013-11-14 23:11:16 -07:00
|
|
|
|
2015-04-12 21:27:55 -06:00
|
|
|
#Check what config file we are building for
|
|
|
|
if ( !$ARGV[0] ) {
|
|
|
|
$UCI_CONF_FILE="olsrd";
|
|
|
|
} else {
|
|
|
|
$UCI_CONF_FILE=$ARGV[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $UCI_CONF_FILE eq "olsrd6" ) {
|
|
|
|
# We only generate entries for IPv4 at moment"
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-06 22:46:25 -06:00
|
|
|
@names = @hosts = @services = @tunnels = ();
|
2013-11-14 23:11:16 -07:00
|
|
|
|
|
|
|
# canonical names for this node
|
|
|
|
# (they show up in reverse order, make the "official" name last)
|
|
|
|
push @names, $name if ($name = nvram_get("tactical"));
|
|
|
|
push @names, $name if ($name = nvram_get("node"));
|
|
|
|
|
|
|
|
# load the dhcp reservations when in dmz mode
|
|
|
|
if(-f "/etc/config/dmz-mode")
|
|
|
|
{
|
|
|
|
#($lanip, $lanmask, $lanbcast, $lannet) = get_ip4_network("eth0.0");
|
|
|
|
foreach(`cat /etc/ethers`)
|
|
|
|
{
|
|
|
|
next unless ($ip) = /[0-9a-f:]+\s+([\d\.]+)/i;
|
|
|
|
next unless $host = ip2hostname($ip);
|
|
|
|
push @hosts, qq("$ip" "$host");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 20:42:20 -06:00
|
|
|
# Add a name for the dtdlink interface.
|
|
|
|
if ($name = nvram_get("node"))
|
|
|
|
{
|
|
|
|
my ($dtdip,$dtdmask,$dtdbcast,$dtdnet);
|
2015-03-25 00:41:51 -06:00
|
|
|
($dtdip, $dtdmask, $dtdbcast, $dtdnet) = get_ip4_network(get_interface("dtdlink"));
|
2014-06-23 20:42:20 -06:00
|
|
|
push @hosts, qq("$dtdip" "dtdlink.$name.local.mesh");
|
|
|
|
}
|
|
|
|
|
2013-11-14 23:11:16 -07:00
|
|
|
# load the services
|
|
|
|
foreach(`cat /etc/config/services 2>/dev/null`)
|
|
|
|
{
|
|
|
|
next unless /^\w+:\/\/[\w\-\.]+:\d+(\/[^\|]*)?\|(tcp|udp)\|\w/;
|
|
|
|
chomp;
|
|
|
|
push @services, $_;
|
|
|
|
}
|
|
|
|
|
2015-05-06 22:46:25 -06:00
|
|
|
# load the tunnels
|
|
|
|
my @tunnelnames = @section = ();
|
|
|
|
|
|
|
|
$tunnum=50;
|
|
|
|
push(@tunnelnames, &uci_get_names_by_sectiontype("vtun","client"));
|
|
|
|
foreach (@tunnelnames)
|
|
|
|
{
|
|
|
|
$section=&uci_get_named_section("vtun",$_);
|
|
|
|
if ($section->{enabled} eq 1)
|
|
|
|
{
|
|
|
|
push(@tunnels,"tun${tunnum}");
|
|
|
|
$tunnum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$tunnum=60;
|
|
|
|
@tunnelnames=&uci_get_names_by_sectiontype("vtun","server");
|
|
|
|
foreach (@tunnelnames)
|
|
|
|
{
|
|
|
|
$section=&uci_get_named_section("vtun",$_);
|
|
|
|
if ($section->{enabled} eq 1)
|
|
|
|
{
|
|
|
|
push(@tunnels,"tun${tunnum}");
|
|
|
|
$tunnum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 23:11:16 -07:00
|
|
|
|
|
|
|
# add the nameservice plugin
|
|
|
|
push @file, qq(\nLoadPlugin "olsrd_nameservice.so.0.3"\n);
|
|
|
|
push @file, qq({\n);
|
|
|
|
push @file, qq( PlParam "sighup-pid-file" "/var/run/dnsmasq.pid"\n);
|
|
|
|
push @file, qq( PlParam "interval" "30"\n);
|
|
|
|
push @file, qq( PlParam "timeout" "300"\n);
|
|
|
|
push @file, qq( PlParam "name-change-script" "touch /tmp/namechange"\n);
|
|
|
|
#push @file, qq( PlParam "lat" "1"\n);
|
|
|
|
#push @file, qq( PlParam "lon" "2"\n);
|
|
|
|
#push @file, qq( PlParam "laton-file" "/var/run/latlon.js"\n);
|
|
|
|
#push @file, qq( PlParam "laton-infile" "/tmp/latlon.txt"\n);
|
|
|
|
foreach(@names) { push @file, qq( PlParam "name" "$_"\n) }
|
|
|
|
foreach(@hosts) { push @file, qq( PlParam $_\n) }
|
|
|
|
foreach(@services) { push @file, qq( PlParam "service" "$_"\n) }
|
|
|
|
push @file, qq(}\n);
|
|
|
|
|
2015-05-06 22:46:25 -06:00
|
|
|
# add the ACTIVE tunnel interfaces
|
|
|
|
push @file, qq(\nInterface );
|
|
|
|
foreach(@tunnels) { push @file, qq("$_" ) }
|
|
|
|
push @file, qq(\n{\n);
|
|
|
|
push @file, qq( Ip4Broadcast 255.255.255.255\n);
|
|
|
|
push @file, qq(}\n);
|
|
|
|
|
|
|
|
|
2013-11-14 23:11:16 -07:00
|
|
|
# write the file
|
2013-12-02 13:04:54 -07:00
|
|
|
print @file;
|