From 739d13602c90eaab130d27c74ea5e9bc1623486e Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Wed, 20 Jan 2021 15:21:17 +0100
Subject: [PATCH] now directly generating the new proxy links

---
 app/Models/Result.php | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/app/Models/Result.php b/app/Models/Result.php
index 5fef5fd52..f53b286e9 100644
--- a/app/Models/Result.php
+++ b/app/Models/Result.php
@@ -360,17 +360,37 @@ class Result
     # Erstellt aus einem Link einen Proxy-Link für unseren Proxy-Service
     public function generateProxyLink($link)
     {
-        if (!$link) {
+        if (!$link || empty($link)) {
             return "";
         }
 
-        # Link to our new Proxy software:
-        $pw = md5(env('PROXY_PASSWORD') . $link);
+        $parts = parse_url($link);
+        $host = null;
+        $path = null;
 
-        $proxyUrl = base64_encode(str_rot13($link));
-        $proxyUrl = urlencode(str_replace("/", "<<SLASH>>", $proxyUrl));
+        $proxyUrl = "https://proxy.metager.de/";
 
-        return "https://proxy.metager.de/" . $pw . "/" . $proxyUrl;
+        if(!empty($parts["host"])){
+            $proxyUrl .= $parts["host"];
+            if(!empty($parts["path"])){
+                $proxyUrl .= "/" . trim($parts["path"], "/");
+            }
+        }
+
+        // We need to generate the correct password for the Proxy URLs
+        // It's an hmac sha256 hash of the url having the proxy password as secret
+        $password = hash_hmac("sha256", $link, env("PROXY_PASSWORD", "unsecure_password"));
+
+        $urlParameters = [
+            "url" => $link,
+            "password" => $password,
+        ];
+
+        $params = http_build_query($urlParameters, "", "&", PHP_QUERY_RFC3986);
+
+        $proxyUrl .= "?" . $params;
+
+        return $proxyUrl;
     }
 
     /* Liest aus einer URL alle Informationen aus
-- 
GitLab