X-Git-Url: https://git.treefish.org/wirbrennen/flipacoin.git/blobdiff_plain/b2900427fcc70eef171c1547e69477b22896bc1e..refs/heads/dev:/flipacoin.cgi diff --git a/flipacoin.cgi b/flipacoin.cgi index 15ac6a4..cba07b1 100755 --- a/flipacoin.cgi +++ b/flipacoin.cgi @@ -15,11 +15,28 @@ my $flippedcoinsindb=0; my $template; +sub setprotocolparam { + { + no warnings 'uninitialized'; + if( length $ENV{HTTPS} ) { + $template->param(PROTOCOL => "https"); + } + else { + $template->param(PROTOCOL => "http"); + } + } +} + sub printpage { $template->param(COINLIFETIME => $COINLIFETIME); $template->param(FLIPPEDCOINSINDB => $flippedcoinsindb); $template->param(COINSINDB => $coinsindb); - $template->param(HTTP_HOST => $ENV{HTTP_HOST}); + + my $rootloc = $ENV{SCRIPT_FILENAME}; + $rootloc =~ s/$ENV{DOCUMENT_ROOT}//g; + $rootloc =~ s/\/[^\/]*$//g; + $template->param( ROOTURL => $ENV{HTTP_HOST} . $rootloc ); + print "Content-type: text/html\n\n", $template->output; } @@ -86,6 +103,7 @@ elsif ( length($requestedcoinid) == 0 && $requestedaction eq "create" ) { $template = HTML::Template->new(filename => 'created.html'); $template->param(NEWCOINID => $newcoinid); + setprotocolparam(); } elsif ( length($requestedcoinid) > 0 ) { if ( ! exists $coins_db{$requestedcoinid} ) { @@ -99,6 +117,7 @@ elsif ( length($requestedcoinid) > 0 ) { $template->param(REQUESTEDCOINID => $requestedcoinid); $template->param(COINCREATIONTIME => localtime($coininfo[0]).""); + setprotocolparam(); if ( $coininfosize == 1 && $requestedaction eq "" ) { $template->param(STATUS_NOTYETFLIPPED => 1);