From 607bd9b118ffd32b53647464f8c01b4a1d488ee8 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 17 Nov 2015 17:35:02 +0100 Subject: olsrd package fixes - Fix service handling - Fix plugin paths - Disable the dynamic gateways options since the required plugin is missing in the package - Add input validations - Some other cleanups --- config/olsrd/olsrd.inc | 156 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 111 insertions(+), 45 deletions(-) (limited to 'config') diff --git a/config/olsrd/olsrd.inc b/config/olsrd/olsrd.inc index 4e15f9cf..f65c1168 100644 --- a/config/olsrd/olsrd.inc +++ b/config/olsrd/olsrd.inc @@ -2,7 +2,7 @@ /* olsrd.inc part of pfSense (https://www.pfSense.org/) - Copyright (C) 2012 Ermal Luçi + Copyright (C) 2006 Scott Ullrich Copyright (C) 2015 ESF, LLC All rights reserved. @@ -28,27 +28,36 @@ POSSIBILITY OF SUCH DAMAGE. */ require_once("config.inc"); +require_once("service-utils.inc"); +require_once("util.inc"); + +$pfs_version = substr(trim(file_get_contents("/etc/version")), 0, 3); +if ($pfs_version == "2.1" || $pfs_version == "2.2") { + define('OLSRD_LOCALBASE', '/usr/pbi/olsrd-' . php_uname("m") . '/local'); +} else { + define('OLSRD_LOCALBASE', '/usr/local'); +} function setup_wireless_olsr() { global $config, $g; - if ($g['platform'] == 'jail' || !$config['installedpackages']['olsrd'] || !$config['installedpackages']) { - return; - } - if (isset($config['system']['developerspew'])) { - $mt = microtime(); - echo "setup_wireless_olsr($interface) being called $mt\n"; - } conf_mount_rw(); - foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) { - $olsr_enable = $olsrd['enable']; - if ($olsr_enable <> "on") { - if (is_process_running("olsrd")) { - mwexec("/usr/bin/killall olsrd", true); - } - return; + if (is_array($config['installedpackages']['olsrd'])) { + $olsrd_config = $config['installedpackages']['olsrd']['config'][0]; + } else { + $olsrd_config = array(); + } + + /* If disabled, stop service if needed, unlink the rc script and do nothing else */ + if ($olsrd_config['enable'] != "on") { + if (is_service_running("olsrd")) { + stop_service("olsrd"); } + unlink_if_exists("/usr/local/etc/rc.d/olsrd.sh"); + return; + } else { + /* parse package config and create configuration file */ $fd = fopen("{$g['varetc_path']}/olsr.conf", "w"); if ($olsrd['announcedynamicroute'] or $olsrd['enableannounce'] == "on") { @@ -64,7 +73,8 @@ function setup_wireless_olsr() { } else { $enableannounce = ""; } - + + $pluginpath = OLSRD_LOCALBASE . '/lib'; $olsr .= << "olsrd.sh", + "start" => $olsrd_start, + "stop" => $olsrd_stop + ) + ); + if (is_service_running("olsrd")) { + restart_service("olsrd"); + } else { + start_service("olsrd"); + } } - sleep(2); - mwexec_bg("/usr/local/sbin/olsrd -f {$g['varetc_path']}/olsr.conf"); conf_mount_ro(); } +function validate_form_olsrd($post, &$input_errors) { + /* + if ($post['iface_array'] == "") { + $input_errors[] = 'You must select at least one interface for OSLRD.'; + } + */ + if ($post['enablehttpinfo']) { + if (!$post['port'] || !$post['allowedhttpinfohost'] || !$post['allowedhttpinfosubnet']) { + $input_errors[] = "'HTTPInfo Port', 'Allowed Host(s) IP Address/Subnet' and 'Allowed Host(s) Netmask' must be filled in when HTTPInfo Plugin is enabled."; + } + if ($post['port'] && !is_port($post['port'])) { + $input_errors[] = "Invalid port entered for 'HTTPInfo Port'."; + } + if ($post['allowedhttpinfohost'] && !is_ipaddrv4($post['allowedhttpinfohost'])) { + $input_errors[] = "Invalid IPv4 address entered for 'Allowed Host(s) IP Address/Subnet'."; + } + if ($post['allowedhttpinfosubnet'] && !is_ipaddrv4($post['allowedhttpinfosubnet'])) { + $input_errors[] = "Invalid IPv4 address entered for 'Allowed Host(s) Netmask'."; + } + if ($post['allowedhttpinfohost'] && is_ipaddrv4($post['allowedhttpinfohost']) && $post['allowedhttpinfosubnet'] && is_ipaddrv4($post['allowedhttpinfosubnet'])) { + $cidr = 32 - log((ip2long($post['allowedhttpinfosubnet']) ^ ip2long('255.255.255.255')) + 1, 2); + $acl = "{$post['allowedhttpinfohost']}/{$cidr}"; + if (!is_subnetv4($acl)) { + $input_errors[] = "'{$post['allowedhttpinfohost']}/{$post['allowedhttpinfosubnet']}' is not a valid IPv4 subnet."; + } + } + } + if ($post['enabledyngw']) { + if (!$post['ping'] || !$post['polling']) { + $input_errors[] = "'Ping IP Address' and 'Poll Interval' must be filled in when 'Enable Dynamic Gateway' is checked."; + } + if ($post['ping'] && !is_ipaddrv4($post['ping'])) { + $input_errors[] = "Invalid IPv4 address entered for 'Ping IP Address'."; + } + if ($post['polling'] && (!is_numericint($post['polling']) || ($post['polling'] < 1))) { + $input_errors[] = "'Poll Interval' must be numeric integer greater than 0."; + } + } +} + +function php_deinstall_olsrd() { + global $g; + unlink_if_exists("{$g['varetc_path']}/olsr.conf"); + unlink_if_exists("{$g['tmp_path']}/olsrkey.txt"); +} + ?> -- cgit v1.2.3