=for comment
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (c) 2015 Darryl Quinn
See Contributors file for additional contributors
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
sub get_server_dns()
{
my @list;
my $uciresult;
my ($rc,$dns)=&uci_get_indexed_option("vtun","network","0","dns");
return $dns;
}
#################################
# get base network from config
#################################
sub get_server_network_address()
{
my @list;
my $uciresult;
my ($rc,$server_net)=&uci_get_indexed_option("vtun","network","0","start");
if($rc eq 0 and $server_net ne "")
{
# to facilitate overrides (ie. moving the server to a new node)
# read the file into $mac
@list = split('\.', $server_net);
}
else
{
# or, calc based on eth0 mac address, then store it.
$mac=get_mac("eth0");
@MACS=split(/:/, $mac);
push @list, "172";
push @list, "31";
push @list, hex $MACS[5];
# strip off the high bits
push @list, ((hex $MACS[4]) << 2) & 255;
$server_net=sprintf("%d.%d.%d.%d",$list[0],$list[1],$list[2],$list[3]);
#($rc,$uciresult)=&uci_add_sectiontype("vtun","network");
($rc,$uciresult)=&uci_set_indexed_option("vtun","network","0","start",$server_net);
$rc=&uci_commit("vtun");
}
return @list;
}
sub get_active_tun()
{
my @active_tun;
foreach(`ps -w|grep vtun|grep ' tun '`)
{
@parts = $_ =~ /.*\:.*-(172-31-.*)\stun\stun.*/g;1;
$parts[0] =~ s/\-/\./g;
push(@active_tun,$parts[0]);
}
return @active_tun;
}
# INPUT arg: Array of active tunnel IP's, IP of the tunnel network you are checking
sub is_tunnel_active()
{
my ($n, @active_tun) = @_;
my $match=0;
foreach(@active_tun){
#print "a=$_, n=$n\n";
if($n eq $_) {
$match = 1;
last;
}
}
return $match; # the return value of the do block
}
##########################
# Add OLSRD interfaces - NOT NEEDED
##########################
sub add_olsrd_interfaces() {
my ($sname,$tunstart,$tuncount) = @_;
my $tuns;
&uci_add_named_section("olsrd",$sname,"Interface");
&uci_set_named_option("olsrd",$sname,"Ip4Broadcast","255.255.255.255");
# delete all interfaces first
&uci_delete_named_option("olsrd",$sname,"interfaces");
for my $i (0..$tuncount-1) {
$tuns=$tuns . " " if $i;
$tuns=$tuns . "tun" . $tunstart;
$tunstart++;
}
&uci_add_list_named_option("olsrd",$sname,"interfaces","$tuns");
&uci_commit("olsrd");
}
##########################
# Add network interfaces tun50 thru tun69 - called on install
##########################
sub add_network_interfaces() {
for (my $tunnum=50; $tunnum<=69; $tunnum++)
{
&uci_add_named_section("network.tun","tun${tunnum}","interface");
&uci_set_named_option("network.tun","tun${tunnum}","ifname","tun${tunnum}");
&uci_set_named_option("network.tun","tun${tunnum}","proto","none");
}
&uci_commit("network.tun");
&uci_clone("network.tun");
}
#################################
# Check Freespace on / filesystem
#################################
sub check_freespace()
{
my $fs = `df / | grep -v '^Filesystem' | awk 'NF=6{print \$4}NF==5{print \$3}{}'`;
chomp $fs;
return $fs;
}
##########################
# Config firewall to allow port 5525 on WAN interface
##########################
sub open_5525_on_wan() {
my $rc;
$rc=&uci_add_sectiontype("firewall.tun","rule");
$rc=&uci_set_indexed_option("firewall.tun","rule","-1","src","wan");
$rc=&uci_set_indexed_option("firewall.tun","rule","-1","dest_port","5525");
$rc=&uci_set_indexed_option("firewall.tun","rule","-1","proto","tcp");
$rc=&uci_set_indexed_option("firewall.tun","rule","-1","target","ACCEPT");
$rc=&uci_commit("firewall.tun");
$rc=&uci_clone("firewall.tun");
}
sub vpn_setup_required()
{
my ($navpage) = @_;
http_header();
html_header("$node setup", 1);
print "
";
print "\n";
navbar($navpage);
print " |
";
#################
# messages
#################
if(@cli_err)
{
print "ERROR: ";
foreach(@cli_err) { print "$_ " }
print " |
\n";
}
print " ";
print "Tunnel software needs to be installed. ";
print "";
print " |
\n";
print "