summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-03-22 13:22:24 +0100
committerAleksander Machniak <alec@alec.pl>2014-03-22 13:22:24 +0100
commit2369305ad8f54b69e5ff751609dbb077c77ef4bb (patch)
tree9e2888622e411fa3b3e80da832a7c2ce8782fb76
parent57330612612a77e309945429fa0e832a58a17ce9 (diff)
parent6446d0ac9798f75e4fb4e4fd600585212546a270 (diff)
Merge pull request #167 from Steffen185/allow_url_fopen_off
Make modcss.inc work with allow_url_fopen = Off
-rw-r--r--program/steps/utils/modcss.inc45
1 files changed, 31 insertions, 14 deletions
diff --git a/program/steps/utils/modcss.inc b/program/steps/utils/modcss.inc
index c8a7cb524..749f01829 100644
--- a/program/steps/utils/modcss.inc
+++ b/program/steps/utils/modcss.inc
@@ -33,24 +33,41 @@ if (!preg_match('~^(https?)://~i', $realurl, $matches)) {
exit("Invalid URL");
}
-if (!ini_get('allow_url_fopen')) {
+if (ini_get('allow_url_fopen')) {
+ $scheme = strtolower($matches[1]);
+ $options = array(
+ $scheme => array(
+ 'method' => 'GET',
+ 'timeout' => 15,
+ )
+ );
+
+ $context = stream_context_create($options);
+ $source = @file_get_contents($realurl, false, $context);
+
+ // php.net/manual/en/reserved.variables.httpresponseheader.php
+ $headers = implode("\n", (array)$http_response_header);
+} else if (function_exists('curl_init')) {
+ $curl = curl_init($realurl);
+ curl_setopt($curl, CURLOPT_TIMEOUT, 15);
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
+ curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
+ curl_setopt($curl, CURLOPT_ENCODING, '');
+ curl_setopt($curl, CURLOPT_HEADER, true);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ $data = curl_exec($curl);
+
+ if ($data !== false) {
+ list($headers, $source) = explode("\r\n\r\n", $data, 2);
+ } else {
+ $headers = false;
+ $source = false;
+ }
+} else {
header('HTTP/1.1 403 Forbidden');
exit("HTTP connections disabled");
}
-$scheme = strtolower($matches[1]);
-$options = array(
- $scheme => array(
- 'method' => 'GET',
- 'timeout' => 15,
- )
-);
-
-$context = stream_context_create($options);
-$source = @file_get_contents($realurl, false, $context);
-
-// php.net/manual/en/reserved.variables.httpresponseheader.php
-$headers = implode("\n", (array)$http_response_header);
$ctype = '~Content-Type:\s+text/(css|plain)~i';
if ($source !== false && preg_match($ctype, $headers)) {