Skip to content

Instantly share code, notes, and snippets.

@gonter
Last active March 9, 2020 18:54
Show Gist options
  • Save gonter/594210e2e274925c83e0fac365024365 to your computer and use it in GitHub Desktop.
Save gonter/594210e2e274925c83e0fac365024365 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use LWP::Simple;
use Data::Dumper;
$Data::Dumper::Indent= 1;
use FileHandle;
binmode( STDOUT, ':utf8' ); autoflush STDOUT 1;
binmode( STDERR, ':utf8' ); autoflush STDERR 1;
binmode( STDIN, ':utf8' );
if (exists ($ENV{'GATEWAY_INTERFACE'}))
{ # CGI evaluation
# open (LOG, '|/usr/bin/logger -t oai-proxy');
open (LOG, '>>:utf8', '/tmp/oai-proxy');
autoflush LOG 1;
print <<'EOX';
Content-Type: text/xml;charset=UTF-8
EOX
my ($method, $query_string)= map { $ENV{$_} } qw(REQUEST_METHOD QUERY_STRING);
# print LOG "<pre>\n", "env: ", Dumper (\%ENV), "</pre>\n";
my %vars= map { my ($an, $av)= split('=', $_, 2); $av =~ s#%([\dA-Fa-f]{2})#chr(hex($1))#ge; $an => $av } split ('&', $query_string);
# print LOG "<pre>\nvars: ", Dumper(\%vars), "</pre>\n";
$vars{set}= 'all_published' if ($vars{verb} eq 'ListIdentifiers' && !(exists ($vars{set}) || exists($vars{resumptionToken})));
$vars{metadataPrefix}= 'oai_ddi' if ($vars{metadataPrefix} eq 'ddi');
my $real_url= 'https://data.aussda.at/oai?' . join ('&', map { join ('=', $_, $vars{$_}) } keys %vars);
print LOG "oai-proxy: real_url=[$real_url]\n";
my $content= get($real_url);
my @res= split ("\n", $content);
foreach my $l (@res)
{
$l =~ s#<adminEmail>.*</adminEmail>#<adminEmail>AUSSDA Team info\@aussda.at</adminEmail>#;
$l =~ s#data.aussda.at#data2.aussda.at#g;
print $l, "\n";
}
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment