Add 'readonly_ips' option, to allow readonly access for certain IPs when 'private' option is enabled.

This commit is contained in:
Rob Vermaas 2017-09-22 11:36:49 +00:00
parent b828224fee
commit 2318baaade
No known key found for this signature in database
GPG key ID: E114A5F264A8AE8E

View file

@ -12,6 +12,7 @@ use Nix::Config;
use Encode; use Encode;
use File::Basename; use File::Basename;
use JSON; use JSON;
use List::MoreUtils qw{any};
# Put this controller at top-level. # Put this controller at top-level.
__PACKAGE__->config->{namespace} = ''; __PACKAGE__->config->{namespace} = '';
@ -20,7 +21,12 @@ __PACKAGE__->config->{namespace} = '';
sub noLoginNeeded { sub noLoginNeeded {
my ($c) = @_; my ($c) = @_;
return $c->request->path eq "google-login" || my $hostname = $c->request->headers->header('X-Forwarded-For') || $c->request->hostname;
my $readonly_ips = $c->config->{readonly_ips} // "";
my $whitelisted = any { $_ == $hostname } split(/,/, $readonly_ips);
return $whitelisted ||
$c->request->path eq "google-login" ||
$c->request->path eq "login" || $c->request->path eq "login" ||
$c->request->path eq "logo" || $c->request->path eq "logo" ||
$c->request->path =~ /^static\//; $c->request->path =~ /^static\//;