From 7077a9001f0365b087b808a87da2a12d31f3c5af Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 10 Sep 2021 15:32:48 -0700 Subject: [PATCH] Factor out function to get default server param --- save_server.cgi | 13 +------------ virtualmin-nginx-lib.pl | 7 +++++++ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/save_server.cgi b/save_server.cgi index aedd2cc..e3a3276 100644 --- a/save_server.cgi +++ b/save_server.cgi @@ -81,17 +81,6 @@ else { &nginx_text_parse("server_name", $server, undef, '^\S+$', undef, 1); $name = $in{'server_name'}; - # Get param for default server - my $ver = &get_nginx_version(); - my $defserv; - if ($ver > 0.8 || - $ver =~ /^0\.8\.(\d+)/ && $1 >= 21) { - $defserv = "default_server"; - } - else { - $defserv = "default"; - } - # Addresses to accept connections on # XXX preserve existing args my $i = 0; @@ -129,7 +118,7 @@ else { # Other random options my @words = ( $ip ); if ($in{"default_$i"}) { - push(@words, $defserv); + push(@words, &get_default_server_param()); } if ($in{"ssl_$i"}) { push(@words, "ssl"); diff --git a/virtualmin-nginx-lib.pl b/virtualmin-nginx-lib.pl index f27f40a..be5aff9 100644 --- a/virtualmin-nginx-lib.pl +++ b/virtualmin-nginx-lib.pl @@ -533,6 +533,13 @@ sub get_default return $dir ? $dir->{'default'} : undef; } +sub get_default_server_param +{ +my $ver = &get_nginx_version(); +return &compare_version_numbers($ver, "0.8.21") >= 0 ? + "default_server" : "default"; +} + # list_nginx_modules() # Returns a list of enabled modules. Includes those compiled in by default # unless disabled, plus extra compiled in at build time.