From e732b03ead7f7e57b82738fb432f2f4b5dc8254a Mon Sep 17 00:00:00 2001 From: apnar Date: Tue, 4 Sep 2012 00:14:37 +0000 Subject: Add interface group on install, remove it on uninstall, and add interfaces to it. --- config/tinc/tinc.inc | 46 +++++++++++++++++++++++++++++++++++++++++++++ config/tinc/tinc_config.xml | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'config/tinc') diff --git a/config/tinc/tinc.inc b/config/tinc/tinc.inc index c191de5a..0881eeac 100644 --- a/config/tinc/tinc.inc +++ b/config/tinc/tinc.inc @@ -68,6 +68,7 @@ function tinc_save() { else { $_output = "ifconfig \$INTERFACE " . $tincconf['localip'] . " netmask " . $tincconf['vpnnetmask'] . "\n"; + $_output .= "ifconfig \$INTERFACE group tinc\n"; } file_put_contents('/usr/local/etc/tinc/tinc-up',$_output); chmod("/usr/local/etc/tinc/tinc-up", 0744); @@ -155,6 +156,17 @@ function tinc_install() { $GLOBALS['config']['interfaces'][$newifname]['if'] = "tun0"; */ + /* Create Interface Group */ + if (!is_array($GLOBALS['config']['ifgroups']['ifgroupentry'])) + $GLOBALS['config']['ifgroups']['ifgroupentry'] = array(); + + $a_ifgroups = &$GLOBALS['config']['ifgroups']['ifgroupentry']; + $ifgroupentry = array(); + $ifgroupentry['members'] = ''; + $ifgroupentry['descr'] = 'tinc mesh VPN interface group'; + $ifgroupentry['ifname'] = 'tinc'; + $a_ifgroups[] = $ifgroupentry; + /* XXX: Do not remove this. */ mwexec("/bin/rm -f /tmp/config.cache"); @@ -165,6 +177,40 @@ function tinc_install() { } function tinc_deinstall() { + /* Remove Interface Group */ + conf_mount_rw(); + config_lock(); + if (!is_array($GLOBALS['config']['ifgroups']['ifgroupentry'])) + $GLOBALS['config']['ifgroups']['ifgroupentry'] = array(); + + $a_ifgroups = &$GLOBALS['config']['ifgroups']['ifgroupentry']; + + $myid=-1; + $i = 0; + foreach ($a_ifgroups as $ifgroupentry) + { + if($ifgroupentry['ifname']=='tinc') + { + $myid=$i; + break; + } + $i++; + } + + if ($myid >= 0 && $a_ifgroups[$myid]) + { + $members = explode(" ", $a_ifgroups[$_GET['id']]['members']); + foreach ($members as $ifs) + { + $realif = get_real_interface($ifs); + if ($realif) + mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$_GET['id']]['ifname']); + } + unset($a_ifgroups[$myid]); + mwexec("/bin/rm -f /tmp/config.cache"); + write_config(); + } + rmdir_recursive("/var/tmp/tinc"); rmdir_recursive("/usr/local/etc/tinc*"); unlink_if_exists("/usr/local/etc/rc.d/tinc.sh"); diff --git a/config/tinc/tinc_config.xml b/config/tinc/tinc_config.xml index 6c3cce71..3878450f 100644 --- a/config/tinc/tinc_config.xml +++ b/config/tinc/tinc_config.xml @@ -144,7 +144,7 @@ Interface Up Script tinc_up - This script is executed right after the tinc daemon has connected to the virtual network device. By default a tinc-up file is created that brings up the tinc interface with the IP Address and Netmask specified above. Entering a value here complely replaces the default script so be sure to bring up the interface in this script. + This script is executed right after the tinc daemon has connected to the virtual network device. By default a tinc-up file is created that brings up the tinc interface with the IP Address and Netmask specified above and adds it to the tinc interface group. Entering a value here complely replaces the default script so be sure to bring up the interface in this script. textarea base64 8 -- cgit v1.2.3