use File::Spec;
use Module::Load::Conditional qw(can_load);
use POSIX ();
+use YAML qw/Load/;
use ZOOM;
use C4::Boolean;
return defined($it)? C4::Boolean::true_p($it): undef;
}
+=head2 yaml_preference
+
+Retrieves the required system preference value, and converts it
+from YAML into a Perl data structure. It throws an exception if
+the value cannot be properly decoded as YAML.
+
+=cut
+
+sub yaml_preference {
+ my ( $self, $preference ) = @_;
+
+ my $yaml = eval { YAML::Load( $self->preference( $preference ) ); };
+ if ($@) {
+ warn "Unable to parse $preference syspref : $@";
+ return;
+ }
+
+ return $yaml;
+}
+
=head2 enable_syspref_cache
C4::Context->enable_syspref_cache();
return C4::Context->config('tmp_path') || File::Spec->tmpdir;
}
+=head3 set_remote_address
+
+set_remote_address should be called at the beginning of every script
+that is *not* running under plack in order to the REMOTE_ADDR environment
+variable to be set correctly.
+
+=cut
+
+sub set_remote_address {
+ if ( C4::Context->config('koha_trusted_proxies') ) {
+ require CGI;
+ my $cgi = CGI->new;
+ my $header = $cgi->http('HTTP_X_FORWARDED_FOR');
+
+ if ($header) {
+ require Koha::Middleware::RealIP;
+ $ENV{REMOTE_ADDR} = Koha::Middleware::RealIP::get_real_ip( $ENV{REMOTE_ADDR}, $header );
+ }
+ }
+}
1;