From ecf67a02ed091b109a8b08f00fc70555b666ea9e Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 11 Mar 2014 00:18:59 +0100 Subject: [PATCH] Creating correct rooturl. --- flipacoin.cgi | 21 ++++++++++++++++++++- templates/_head.html | 2 +- templates/_header.html | 2 +- templates/created.html | 2 +- templates/usecoin.html | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) 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); diff --git a/templates/_head.html b/templates/_head.html index 9e423cd..d666303 100644 --- a/templates/_head.html +++ b/templates/_head.html @@ -1,3 +1,3 @@ - <!-- TMPL_VAR NAME=HTTP_HOST --> + <!-- TMPL_VAR NAME=ROOTURL --> diff --git a/templates/_header.html b/templates/_header.html index f3fa6ac..0f7e460 100644 --- a/templates/_header.html +++ b/templates/_header.html @@ -9,4 +9,4 @@ patchme@flipacoin.org.
-

- The Internet's first two-party coinflipping service.

+

- The Internet's first two-party coinflipping service.

diff --git a/templates/created.html b/templates/created.html index a625330..f755a87 100644 --- a/templates/created.html +++ b/templates/created.html @@ -7,7 +7,7 @@ > - http:/// + :/// for you.

Send the coin to the other party and tell them to flip it to make a decision. diff --git a/templates/usecoin.html b/templates/usecoin.html index 3f3202e..4691542 100644 --- a/templates/usecoin.html +++ b/templates/usecoin.html @@ -5,7 +5,7 @@ > - http:/// + :///
-- 2.39.2