diff --git a/app/Document.php b/app/Document.php index 6158f61ee3632585936a7678b932c84f10f78681..5e5ba7ba2e942a06dd8331cd058269d0042cfdf4 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 fc8aef5089fe893f11a9fb947d0944d3463eb1bd..e8132b8c53ad1a7f10a90daedb7f4327827e9279 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 f02d65ff1bac6b3694913e2a8b6189a7deb85742..21d6b284cdae639a192bccd075b80d89882c78f7 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.