get rid of the need for allow_url_fopen
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
60
lib/classes/cURL/class.HttpClient.php
Normal file
60
lib/classes/cURL/class.HttpClient.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class HttpClient
|
||||
{
|
||||
|
||||
/**
|
||||
* Executes simple GET request
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function urlGet($url)
|
||||
{
|
||||
include FROXLOR_INSTALL_DIR . '/lib/version.inc.php';
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Froxlor/' . $version);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($ch);
|
||||
if ($output === false) {
|
||||
$e = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new \Exception("Curl error: " . $e);
|
||||
}
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads and stores a file from an url
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $target
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function fileGet($url, $target)
|
||||
{
|
||||
include FROXLOR_INSTALL_DIR . '/lib/version.inc.php';
|
||||
$fh = fopen($target, 'w');
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Froxlor/' . $version);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
|
||||
//give curl the file pointer so that it can write to it
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fh);
|
||||
$output = curl_exec($ch);
|
||||
if ($output === false) {
|
||||
$e = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new \Exception("Curl error: " . $e);
|
||||
}
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -216,9 +216,8 @@ class lescript
|
||||
// simple self check
|
||||
if (Settings::Get('system.disable_le_selfcheck') == '0')
|
||||
{
|
||||
$selfcheckContextOptions = array('http' => array('header' => "User-Agent: Froxlor/".$this->version));
|
||||
$selfcheckContext = stream_context_create($selfcheckContextOptions);
|
||||
if ($payload !== trim(@file_get_contents($uri, false, $selfcheckContext))) {
|
||||
$selfcheckpayload = HttpClient::urlGet($uri);
|
||||
if ($payload !== trim($selfcheckpayload)) {
|
||||
$errmsg = json_encode(error_get_last());
|
||||
if ($errmsg != "null") {
|
||||
$errmsg = "; PHP error: " . $errmsg;
|
||||
|
||||
@@ -233,13 +233,8 @@ class lescript_v2
|
||||
|
||||
// simple self check
|
||||
if (Settings::Get('system.disable_le_selfcheck') == '0') {
|
||||
$selfcheckContextOptions = array(
|
||||
'http' => array(
|
||||
'header' => "User-Agent: Froxlor/" . $this->version
|
||||
)
|
||||
);
|
||||
$selfcheckContext = stream_context_create($selfcheckContextOptions);
|
||||
if ($payload !== trim(@file_get_contents($uri, false, $selfcheckContext))) {
|
||||
$selfcheckpayload = HttpClient::urlGet($uri);
|
||||
if ($payload !== trim($selfcheckpayload)) {
|
||||
$errmsg = json_encode(error_get_last());
|
||||
if ($errmsg != "null") {
|
||||
$errmsg = "; PHP error: " . $errmsg;
|
||||
|
||||
Reference in New Issue
Block a user