]> git.treefish.org Git - wirbrennen/flipacoin.git/blobdiff - flipacoin.cgi
Creating correct rooturl.
[wirbrennen/flipacoin.git] / flipacoin.cgi
index 95bf6c1761af28a8e3c1d4cd2dc36d32801f68fe..cba07b1e87a45d519c25b15dd67d56691cc990ca 100755 (executable)
@@ -15,10 +15,28 @@ my $flippedcoinsindb=0;
 
 my $template;
 
 
 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);
 sub printpage {
     $template->param(COINLIFETIME => $COINLIFETIME);
     $template->param(FLIPPEDCOINSINDB => $flippedcoinsindb);
     $template->param(COINSINDB => $coinsindb);
+    
+    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;
 }
 
     print "Content-type: text/html\n\n", $template->output;
 }
 
@@ -85,7 +103,7 @@ elsif ( length($requestedcoinid) == 0 && $requestedaction eq "create" ) {
 
     $template = HTML::Template->new(filename => 'created.html');
     $template->param(NEWCOINID => $newcoinid);
 
     $template = HTML::Template->new(filename => 'created.html');
     $template->param(NEWCOINID => $newcoinid);
-    $template->param(HTTP_HOST => $ENV{HTTP_HOST});
+    setprotocolparam();
 }
 elsif ( length($requestedcoinid) > 0 ) {
     if ( ! exists $coins_db{$requestedcoinid} ) {
 }
 elsif ( length($requestedcoinid) > 0 ) {
     if ( ! exists $coins_db{$requestedcoinid} ) {
@@ -98,22 +116,23 @@ elsif ( length($requestedcoinid) > 0 ) {
     $template = HTML::Template->new(filename => 'usecoin.html');
 
     $template->param(REQUESTEDCOINID => $requestedcoinid);
     $template = HTML::Template->new(filename => 'usecoin.html');
 
     $template->param(REQUESTEDCOINID => $requestedcoinid);
-    $template->param(HTTP_HOST => $ENV{HTTP_HOST});
     $template->param(COINCREATIONTIME => localtime($coininfo[0])."");
     $template->param(COINCREATIONTIME => localtime($coininfo[0])."");
+    setprotocolparam();
 
     if ( $coininfosize == 1 && $requestedaction eq "" ) {
 
     if ( $coininfosize == 1 && $requestedaction eq "" ) {
-       $template->param(NOTYETFLIPPED => 1);
+       $template->param(STATUS_NOTYETFLIPPED => 1);
     }
     elsif ( $coininfosize == 1 && $requestedaction eq "flip" ) {
        $result = int(rand(2));
        $coins_db{$requestedcoinid} = $coins_db{$requestedcoinid} .
            "," . time .
            "," . $result;
     }
     elsif ( $coininfosize == 1 && $requestedaction eq "flip" ) {
        $result = int(rand(2));
        $coins_db{$requestedcoinid} = $coins_db{$requestedcoinid} .
            "," . time .
            "," . $result;
-       $template->param(COINSTATUS => "Just flipped");
+       $template->param(STATUS_JUSTFLIPPED => 1);
        $template->param(COINRESULT => translateresult($result));
     }
     elsif ( $coininfosize == 3 ) {
        $template->param(COINRESULT => translateresult($result));
     }
     elsif ( $coininfosize == 3 ) {
-       $template->param(COINSTATUS => "Flipped @ " . localtime($coininfo[1]));
+       $template->param(STATUS_FLIPPED => 1);
+       $template->param(COINFLIPPEDTIME => localtime($coininfo[1])."");
        $template->param(COINRESULT => translateresult($coininfo[2]));
     }
 }
        $template->param(COINRESULT => translateresult($coininfo[2]));
     }
 }