From e4b58975b4c7b59db58f84ba911c4214cc6b3060 Mon Sep 17 00:00:00 2001
From: Jonas Leder <jonas@jonasled.de>
Date: Sat, 2 Jan 2021 00:45:10 +0100
Subject: [PATCH] route banners through proxy when using tor

---
 public/index.php             | 12 ++++++++++--
 public/internal/getImage.php | 24 ++++++++++++++++++++++++
 public/internal/header.php   |  5 +++--
 3 files changed, 37 insertions(+), 4 deletions(-)
 create mode 100644 public/internal/getImage.php

diff --git a/public/index.php b/public/index.php
index 49cd129..9b3d65d 100644
--- a/public/index.php
+++ b/public/index.php
@@ -3,6 +3,14 @@ include "internal/header.php";
 include "internal/footer.php";
 include "internal/mysql.php";
 
+if (strpos($_SERVER['HTTP_HOST'], '.onion') !== false) {
+    $heIMG = "/internal/getImage.php?imgID=1";
+    $abuseIPIMG = "/internal/getImage.php?imgID=2";
+} else {
+    $abuseIPIMG = "https://www.abuseipdb.com/contributor/45130.svg";
+    $heIMG = "https://ipv6.he.net/certification/create_badge.php?pass_name=jonasled&badge=3";
+}
+
 getHeader("Jonas Leder", "home");
 ?>
     <div class="center">
@@ -45,8 +53,8 @@ getHeader("Jonas Leder", "home");
         </div>
         <div id="banner">
         <h2>Banner</h2>
-        <a target="_blank" href="https://ipv6.he.net"><img src="https://ipv6.he.net/certification/create_badge.php?pass_name=jonasled&badge=3"></a>
-        <a target="_blank" href="https://www.abuseipdb.com/user/45130"><img style="background-color: white" src="https://www.abuseipdb.com/contributor/45130.svg" style="width: 401px;"></a>
+        <a target="_blank" href="https://ipv6.he.net"><img src="<?php echo($heIMG); ?>"></a>
+        <a target="_blank" href="https://www.abuseipdb.com/user/45130"><img style="background-color: white" src="<?php echo($abuseIPIMG); ?>" style="width: 401px;"></a>
         </div>
     </div>
 <?php
diff --git a/public/internal/getImage.php b/public/internal/getImage.php
new file mode 100644
index 0000000..781c321
--- /dev/null
+++ b/public/internal/getImage.php
@@ -0,0 +1,24 @@
+<?php
+
+$url = "";
+
+if( isset( $_GET['imgID'] ) )
+{
+    if($_GET['imgID'] == "1") {
+        $url = "https://ipv6.he.net/certification/create_badge.php?pass_name=jonasled&badge=3";
+    } else if($_GET['imgID'] == "2"){
+        $url = "https://www.abuseipdb.com/contributor/45130.svg";
+    } else {
+        die("wrong image id");
+    }
+}
+else
+{
+    die("no image ID set");
+}
+
+$imginfo = getimagesize( $url );
+header("Content-type: ".$imginfo['mime']);
+readfile( $url );
+
+?>
\ No newline at end of file
diff --git a/public/internal/header.php b/public/internal/header.php
index 1964a8f..b7192cc 100644
--- a/public/internal/header.php
+++ b/public/internal/header.php
@@ -1,9 +1,10 @@
 <?php
-include "config.php";
-include "menue.php";
 
 function getHeader($pagetitle, $navselect)
 {
+    include "config.php";
+    include "menue.php";
+
     $menu = getMenu($navselect);
     if (strpos($_SERVER['HTTP_HOST'], '.onion') !== false) {
         $trackURL = $trackURLTor;
-- 
GitLab