diff options
author | jim-p <jimp@pfsense.org> | 2012-02-23 16:23:40 -0500 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2012-02-23 16:24:23 -0500 |
commit | d3a2337a7225c38655e20c918291adb95b7a3391 (patch) | |
tree | 45e2f5adde70e6e19100628101789a89b199db97 | |
parent | 0b84b20037281f431dca248700d2b74b0c29d0f5 (diff) | |
download | pfsense-d3a2337a7225c38655e20c918291adb95b7a3391.zip pfsense-d3a2337a7225c38655e20c918291adb95b7a3391.tar.gz |
While we're at it, allow hostnames for syslog servers, since that is also valid.
-rw-r--r-- | etc/inc/util.inc | 10 | ||||
-rwxr-xr-x | usr/local/www/diag_logs_settings.php | 19 |
2 files changed, 23 insertions, 6 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc index 420ca0e..b370d69 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -497,6 +497,16 @@ function is_ipaddrwithport($ipport) { } } +function is_hostnamewithport($hostport) { + $parts = explode(":", $hostport); + $port = array_pop($parts); + if (count($parts) == 1) { + return is_hostname($parts[0]) && is_port($port); + } else { + return false; + } +} + /* returns true if $ipaddr is a valid dotted IPv4 address or an alias thereof */ function is_ipaddroralias($ipaddr) { global $config; diff --git a/usr/local/www/diag_logs_settings.php b/usr/local/www/diag_logs_settings.php index b247044..be34612 100755 --- a/usr/local/www/diag_logs_settings.php +++ b/usr/local/www/diag_logs_settings.php @@ -69,20 +69,27 @@ $pconfig['disablelocallogging'] = isset($config['syslog']['disablelocallogging'] if (!$pconfig['nentries']) $pconfig['nentries'] = 50; +function is_valid_syslog_server($target) { + return (is_ipaddr($target) + || is_ipaddrwithport($target) + || is_hostname($target) + || is_hostnamewithport($target)); +} + if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ - if ($_POST['enable'] && (!is_ipaddr($_POST['remoteserver']) && !is_ipaddrwithport($_POST['remoteserver']))) { - $input_errors[] = gettext("A valid IP address or IP:Port must be specified for remote syslog server #1."); + if ($_POST['enable'] && !is_valid_syslog_server($_POST['remoteserver'])) { + $input_errors[] = gettext("A valid IP address/hosname or IP/hostname:port must be specified for remote syslog server #1."); } - if ($_POST['enable'] && $_POST['remoteserver2'] && (!is_ipaddr($_POST['remoteserver2']) && !is_ipaddrwithport($_POST['remoteserver2']))) { - $input_errors[] = gettext("A valid IP address or IP:Port must be specified for remote syslog server #2."); + if ($_POST['enable'] && $_POST['remoteserver2'] && !is_valid_syslog_server($_POST['remoteserver2'])) { + $input_errors[] = gettext("A valid IP address/hosname or IP/hostname:port must be specified for remote syslog server #2."); } - if ($_POST['enable'] && $_POST['remoteserver3'] && (!is_ipaddr($_POST['remoteserver3']) && !is_ipaddrwithport($_POST['remoteserver3']))) { - $input_errors[] = gettext("A valid IP address or IP:Port must be specified for remote syslog server #3."); + if ($_POST['enable'] && $_POST['remoteserver3'] && !is_valid_syslog_server($_POST['remoteserver3'])) { + $input_errors[] = gettext("A valid IP address/hosname or IP/hostname:port must be specified for remote syslog server #3."); } if (($_POST['nentries'] < 5) || ($_POST['nentries'] > 2000)) { |