From adedc76777b0ac146abfd77f824369488f71005a Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Fri, 20 Nov 2009 17:16:43 -0500 Subject: Allow specification of multiple ports seperated by a , --- config/haproxy/haproxy.inc | 27 ++++++++++++++++++++------- config/haproxy/haproxy_backends_edit.php | 8 +++++--- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'config/haproxy') diff --git a/config/haproxy/haproxy.inc b/config/haproxy/haproxy.inc index e3028e4c..97c5b5a1 100644 --- a/config/haproxy/haproxy.inc +++ b/config/haproxy/haproxy.inc @@ -123,13 +123,26 @@ function haproxy_configure() { if(is_array($a_backends)) { foreach ($a_backends as $backend) { - if($backend['extaddr'] == "any") - $listenip = "listen {$backend['name']}\t\t\t0.0.0.0:".$backend['port']."\n"; - elseif($backend['extaddr']) - $listenip = "listen {$backend['name']}\t\t\t" . $backend['extaddr'] . ":" . $backend['port']."\n"; - else - $listenip = "listen {$backend['name']}\t\t\t" . get_current_wan_address('wan').":" . $backend['port']."\n"; - + // Define our backend name + $backend = "listen {$backend['name']}\n"; + + // Prepare ports for processing by splitting + $backend['port'] .= ","; + $ports = split(",", $backend['port']); + + // Process and add bind directives for ports + foreach($ports as $port) { + if($port) { + if($backend['extaddr'] == "any") + $listenip = "bind\t\t\t0.0.0.0:" . $port . "\n"; + elseif($backend['extaddr']) + $listenip = "bind\t\t\t" . $backend['extaddr'] . ":" . $port ."\n"; + else + $listenip = "bind\t\t\t" . get_current_wan_address('wan').":" . $port ."\n"; + } + } + + fwrite ($fd, "{$backend}"); fwrite ($fd, "{$listenip}"); fwrite ($fd, "\tmode\t\t\t".$backend['type'] . "\n"); fwrite ($fd, "\tlog\t\t\tglobal\n"); diff --git a/config/haproxy/haproxy_backends_edit.php b/config/haproxy/haproxy_backends_edit.php index 61915a70..fe92c5ed 100755 --- a/config/haproxy/haproxy_backends_edit.php +++ b/config/haproxy/haproxy_backends_edit.php @@ -120,8 +120,10 @@ if ($_POST) { if (!is_numeric($_POST['max_connections'])) $input_errors[] = "The field 'Max connections' value is not a number."; - if (!is_numeric($_POST['port'])) - $input_errors[] = "The field 'Port' value is not a number."; + $ports = $_POST['port']; + foreach($ports as $port) + if ($port && !is_numeric($port)) + $input_errors[] = "The field 'Port' value is not a number."; if (!is_numeric($_POST['client_timeout'])) $input_errors[] = "The field 'Client timeout' value is not a number."; @@ -498,7 +500,7 @@ set by the 'retries' parameter (2). Port size="10" maxlength="10"> -
the port to listen to
+
The port to listen to. To specify multiple ports, separate with a comma (,). EXAMPLE: 80,443
-- cgit v1.2.3