Commit 08f440b8 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

[feature] http_host parameter became optional.

parent 873d80eb
......@@ -1102,24 +1102,42 @@ while ($query = new_loop()) {
# N.B. As of 6.2.15, the http_host parameter will match with the host name
# and path locally detected by server. If remotely detected host name
# and / or path should be differ, the proxy must adjust them.
my $server_name = Sympa::Tools::WWW::get_server_name() || '';
if ($server_name
and my $hostmap = $Conf::Conf{'robot_by_http_host'}->{$server_name}) {
my $selected_robot;
my $request_host = Sympa::Tools::WWW::get_server_name() || '';
my $request_path = $ENV{'REQUEST_URI'} || '';
if ($request_host) {
my $selected_path = '';
my $request_uri = $ENV{'REQUEST_URI'} || '';
while (my ($path, $v) = each %$hostmap) {
if (0 == index $request_uri, $path) { #FIXME:percent-decode
# Longer path wins.
if (length $selected_path < length $path) {
($selected_robot, $selected_path) = ($v, $path);
}
foreach my $rid (Sympa::List::get_robots()) {
my $local_url = Conf::get_robot_conf($rid, 'http_host');
unless ($local_url) {
$local_url = Conf::get_robot_conf($rid, 'wwsympa_url');
} elsif ($local_url =~ m{\A[-+\w]+:}) {
;
} elsif ($local_url =~ m{\A//}) {
$local_url = 'http:' . $local_url;
} else {
$local_url = 'http://' . $local_url;
}
next unless $local_url;
my $uri = URI->new($local_url);
next
unless $uri
and $uri->scheme
and grep { $uri->scheme eq $_ } qw(http https);
my $host = lc ($uri->host || '');
my $path = $uri->path || '/';
#FIXME:might need percent-decode hosts and paths
next
unless $request_host eq $host
and 0 == index $request_path, $path;
# The longest path wins.
($robot, $selected_path) = ($rid, $path)
if length $selected_path < length $path;
}
$robot = $selected_robot;
}
$robot = $Conf::Conf{'host'} unless $robot; #FIXME:Use domain.
$robot ||= $Conf::Conf{'domain'};
 
# Not yet implemented
### Create Robot object
......
......@@ -317,8 +317,8 @@ sub load_robots {
} else {
$param->{'config_hash'}{'robots'}{$robot} = $robot_conf;
}
_check_double_url_usage(
{'config_hash' => $param->{'config_hash'}{'robots'}{$robot}});
#_check_double_url_usage(
# {'config_hash' => $param->{'config_hash'}{'robots'}{$robot}});
}
return undef if ($exiting);
return 1;
......@@ -2377,36 +2377,8 @@ sub _set_listmasters_entry {
return $number_of_valid_email;
}
sub _check_double_url_usage {
my $param = shift;
my ($host, $path);
if (Sympa::Tools::Data::smart_eq(
$param->{'config_hash'}{'http_host'},
qr/^([^\/]+)(\/.*)$/
)
) {
$param->{'config_hash'}{'http_host'} =~ qr/^([^\/]+)(\/.*)$/;
($host, $path) = ($1, $2);
} else {
($host, $path) = ($param->{'config_hash'}{'http_host'}, '/');
}
## Warn listmaster if another virtual host is defined with the same host
## +path
if (defined $Conf{'robot_by_http_host'}{$host}{$path}) {
$log->syslog(
'err',
'Two virtual hosts (%s and %s) are mapped via a single URL "%s%s"',
$Conf{'robot_by_http_host'}{$host}{$path},
$param->{'config_hash'}{'robot_name'},
$host,
$path
);
}
$Conf{'robot_by_http_host'}{$host}{$path} =
$param->{'config_hash'}{'robot_name'};
}
# No longer used.
#sub _check_double_url_usage;
sub _parse_custom_robot_parameters {
my $param = shift;
......
......@@ -1520,12 +1520,10 @@ our @params = (
},
# { your_lists_size: not yet implemented. }
{ 'name' => 'http_host',
'gettext_id' => 'Web domain of a virtual host',
'sample' => 'host.domain.tld',
'default' => 'host.domain.tld',
'gettext_id' => 'URL behind proxy',
'vhost' => '1',
'edit' => '1',
'file' => 'sympa.conf',
'optional' => '1',
},
{ 'name' => 'password_validation',
'gettext_id' =>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment