initial commit of file from CVS for smeserver-openvpn-s2s on Sat Sep 7 19:57:57 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 19:57:57 +10:00
parent 8855fbff54
commit 59fbb967a2
61 changed files with 10315 additions and 2 deletions

View File

@@ -0,0 +1,55 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 2010 Firewall Services
# Daniel Berteaud <daniel@firewall-services.com>
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
use strict;
use esmith::ConfigDB;
use esmith::NetworksDB;
use esmith::event;
my $db = esmith::NetworksDB->open || die "Couldn't open netwoks db\n";
my $ovpndb = esmith::ConfigDB->open_ro('openvpn-s2s') || die "Couldn't open openvpn-s2s db\n";
my @nets = $db->networks;
my @vpnnets = ();
my $vpnnet;
# buils a list of network used by a VPN daemon
foreach my $vpn ($ovpndb->get_all_by_prop(type=>'server'),
$ovpndb->get_all_by_prop(type=>'client')){
foreach (split(/[;,]/,($vpn->prop('RemoteNetworks') || ''))){
my ($vpnnet,undef) = split(/\//, $_);
push @vpnnets, $vpnnet;
}
push @vpnnets, $vpn->prop('RemoteIP');
}
foreach my $net (@nets){
my $key = $net->key;
my $vpn = $db->get_prop($key,"VPN") || '';
if ($vpn ne ''){
unless (grep{ $_ eq $key} @vpnnets){
$db->set_prop($key, type=>'network-deleted');
event_signal("network-delete","$key");
$db->get($key)->delete;
}
}
}

View File

@@ -0,0 +1,49 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 2010 Firewall Services
# Daniel Berteaud <daniel@firewall-services.com>
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
use strict;
use esmith::templates;
use esmith::ConfigDB;
my $db = esmith::ConfigDB->open_ro("openvpn-s2s");
my @clients = $db->get_all_by_prop(type=>'client');
my @servers = $db->get_all_by_prop(type=>'server');
# Remove all the configuration files
unlink </etc/openvpn/s2s/*.conf>;
# And status files
unlink </etc/openvpn/s2s/*-status.txt>;
foreach my $conf (@servers,@clients){
my $key = $conf->key;
my $status = $conf->prop('status') || 'disabled';
if ($status eq 'enabled'){
processTemplate(
{
TEMPLATE_PATH => "/etc/openvpn/s2s/openvpn-s2s.conf",
MORE_DATA => {DB_KEY=>$key},
OUTPUT_FILENAME => "/etc/openvpn/s2s/$key.conf",
});
}
}

View File

@@ -0,0 +1,7 @@
#!/bin/bash
#copy any files needed for the jail
#be sure we have the needed timezone
/bin/cp -L /etc/localtime /etc/openvpn/s2s/etc

View File

@@ -0,0 +1,60 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 2010 Firewall Services
# Daniel Berteaud <daniel@firewall-services.com>
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
use strict;
use esmith::templates;
use esmith::ConfigDB;
my $event = $ARGV [0];
my $vpn = $ARGV [1];
my $lock="/var/lock/subsys/openvpn-s2s";
my $piddir="/var/run/openvpn-s2s";
die "missing vpn name" unless defined $vpn;
my $db = esmith::ConfigDB->open_ro("openvpn-s2s");
my $conf = $db->get($vpn) or die "unknown site to site vpn";
my $key = $conf->key;
my $status = $conf->prop('status') || 'disabled';
if ($status eq 'enabled'){
processTemplate(
{
TEMPLATE_PATH => "/etc/openvpn/s2s/openvpn-s2s.conf",
MORE_DATA => {DB_KEY=>$key},
OUTPUT_FILENAME => "/etc/openvpn/s2s/$key.conf",
});
if ( -f $lock ) {
my $pidf = "$piddir/$key.pid";
if ( -f $pidf ) {
my $pid=`cat $pidf`;
kill 'USR1', $pid || exit 1 ;
exit 0;
}
}
else {
print "openvpn: service not started";
exit 1
}
}

View File

@@ -0,0 +1,34 @@
#!/bin/bash
DOMAIN=$(/sbin/e-smith/db configuration get DomainName)
for VPN in $(/sbin/e-smith/db openvpn-s2s keys); do
URL=$(/sbin/e-smith/db openvpn-s2s getprop $VPN CrlUrl)
AUTH=$(/sbin/e-smith/db openvpn-s2s getprop $VPN Authentication)
if [ ! -z "$URL" -a "$AUTH" == 'TLS' ]; then
/usr/bin/wget --timeout=5 $URL -O /tmp/cacrl.pem > /dev/null 2>&1
/usr/bin/openssl crl -inform PEM -in /tmp/cacrl.pem -text > /dev/null 2>&1
if [ "$?" -eq "0" ]; then
/bin/mv -f /tmp/cacrl.pem /etc/openvpn/s2s/pub/"$VPN"_cacrl.pem > /dev/null 2>&1
else
cat > /tmp/crlmail <<END
An error occured while updating the CRL for the VPN ID $VPN
because openssl didn't recognize the file as a valid CRL.
Below is the copy of the latest CRL downloaded from
$URL
END
cat /tmp/cacrl.pem >> /tmp/crlmail
mail -s 'CRL update failed' admin@$DOMAIN < /tmp/crlmail
fi
rm -f /tmp/cacrl.pem
rm -f /tmp/crlmail
fi
done