From f432e364b2acdf561eaaef02d110c821ab4cb451 Mon Sep 17 00:00:00 2001 From: Matthew Grooms Date: Tue, 26 Aug 2008 23:49:04 +0000 Subject: Set some important default values for the new OpenVPN interface screens. Add functions and interface code to handle local port conflict detection and resolution. --- etc/inc/openvpn.inc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'etc/inc/openvpn.inc') diff --git a/etc/inc/openvpn.inc b/etc/inc/openvpn.inc index 1225f40..f7c8d7f 100644 --- a/etc/inc/openvpn.inc +++ b/etc/inc/openvpn.inc @@ -40,6 +40,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* DISABLE_PHP_LINT_CHECKING */ require_once('config.inc'); require_once('pfsense-utils.inc'); @@ -56,12 +57,12 @@ function openvpn_vpnid_used($vpnid) { if (is_array($config['openvpn']['openvpn-server'])) foreach ($config['openvpn']['openvpn-server'] as $id => & $settings) - if( $vpnid == $settings['vpnid'] ) + if ($vpnid == $settings['vpnid']) return true; if (is_array($config['openvpn']['openvpn-client'])) foreach ($config['openvpn']['openvpn-client'] as $id => & $settings) - if( $vpnid == $settings['vpnid'] ) + if ($vpnid == $settings['vpnid']) return true; return false; @@ -76,6 +77,33 @@ function openvpn_vpnid_next() { return $vpnid; } +function openvpn_port_used($prot, $port) { + global $config; + + if (is_array($config['openvpn']['openvpn-server'])) + foreach ($config['openvpn']['openvpn-server'] as $id => & $settings) + if ($port == $settings['local_port'] && + $prot == $settings['protocol']) + return $settings['vpnid']; + + if (is_array($config['openvpn']['openvpn-client'])) + foreach ($config['openvpn']['openvpn-client'] as $id => & $settings) + if ($port == $settings['local_port'] && + $prot == $settings['protocol']) + return $settings['vpnid']; + + return 0; +} + +function openvpn_port_next($prot) { + + $port = 1194; + while(openvpn_port_used($prot, $port)) + $port++; + + return $port; +} + function openvpn_get_cipherlist() { $ciphers = array(); -- cgit v1.1