From cbe927567ab118d8dbd2604bc573e1d85ec529c2 Mon Sep 17 00:00:00 2001 From: Dominik Pfennig <dominik@suma-ev.de> Date: Fri, 24 Mar 2017 12:18:04 +0100 Subject: [PATCH] Kleinere Bugfixes --- app/Document.php | 4 ++++ app/HtmlDocument.php | 22 +++++++++++++++++----- app/Http/Controllers/ProxyController.php | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Document.php b/app/Document.php index 6158f61..5e5ba7b 100644 --- a/app/Document.php +++ b/app/Document.php @@ -106,6 +106,10 @@ abstract class Document $abs .= '@'; } + if (!isset($host)) { + #die(var_dump($this->baseUrl)); + } + $abs .= $host; /* did somebody sneak in a port? */ if (isset($port)) { diff --git a/app/HtmlDocument.php b/app/HtmlDocument.php index fc8aef5..e8132b8 100644 --- a/app/HtmlDocument.php +++ b/app/HtmlDocument.php @@ -36,11 +36,13 @@ class HtmlDocument extends Document $dom->loadHtml($this->htmlString); foreach ($dom->getElementsByTagName('base') as $base) { - $href = $base->getAttribute('href'); - # Convert all relative Links to absolute Ones - $href = $this->convertRelativeToAbsoluteLink($href); - $this->baseUrl = $href; - # Delete Base Tag + if ($base->hasAttribute("href")) { + $href = $base->getAttribute('href'); + # Convert all relative Links to absolute Ones + $href = $this->convertRelativeToAbsoluteLink($href); + $this->baseUrl = $href; + # Delete Base Tag + } $base->parentNode->removeChild($base); } @@ -290,6 +292,16 @@ class HtmlDocument extends Document $cssElement->proxifyContent(); $el->setAttribute("style", $cssElement->getResult()); } + + # Some old sites might use the background attribute Let's parse them, too + if ($el->hasAttribute("background")) { + # Convert all relative Links to absolute Ones + $el->setAttribute("background", $this->convertRelativeToAbsoluteLink($el->getAttribute("background"))); + # Convert all Links to the proxified Version + # All of this Links should NOT target to the top Level + $el->setAttribute("background", $this->proxifyUrl($el->getAttribute("background"), false)); + } + # We Will Remove all Javascript Event attributes # To keep things simple we're gonna remove all Attributes which names start with "on" foreach ($el->attributes as $attr) { diff --git a/app/Http/Controllers/ProxyController.php b/app/Http/Controllers/ProxyController.php index f02d65f..21d6b28 100644 --- a/app/Http/Controllers/ProxyController.php +++ b/app/Http/Controllers/ProxyController.php @@ -153,6 +153,7 @@ class ProxyController extends Controller $httpcode = $result["http_code"]; extract(parse_url($targetUrl)); + $base = $scheme . "://" . $host; # We will parse whether we have a parser for this document type. -- GitLab