aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Noack <noack@data-quest.de>2022-02-03 10:48:42 +0000
committerAndré Noack <noack@data-quest.de>2022-02-03 10:48:42 +0000
commitbef638fe11a9f87dd9f5b4e56cab9bd36b7c86f7 (patch)
treefdbba6a6fbfa8cd0dff71bf030d88ef64636a24a
parentbe2dbace9771f25550c1f5642b0371284357cb6d (diff)
Resolve "TwilloConnector ignoriert Proxy Einstellungen"
-rw-r--r--lib/classes/TwilloConnector.php34
-rw-r--r--vendor/edu-sharing-plugin/edu-sharing-auth-helper.php6
-rw-r--r--vendor/edu-sharing-plugin/edu-sharing-helper-base.php7
-rw-r--r--vendor/edu-sharing-plugin/edu-sharing-node-helper.php11
4 files changed, 46 insertions, 12 deletions
diff --git a/lib/classes/TwilloConnector.php b/lib/classes/TwilloConnector.php
index e91d912..7a57583 100644
--- a/lib/classes/TwilloConnector.php
+++ b/lib/classes/TwilloConnector.php
@@ -11,6 +11,13 @@ class TwilloConnector
*/
static protected $ticket = null;
+ static public $twillo_base_url = 'https://www.twillo.de/edu-sharing';
+
+ public static function getHttpProxy()
+ {
+ $stream_context_options = stream_context_get_options(get_default_http_stream_context(self::$twillo_base_url));
+ return isset($stream_context_options['http']['proxy']) ? Config::get()->HTTP_PROXY : '';
+ }
/**
* Returns the DFN-AAI-ID for the given user. This ID must be the content of a datafield with the
* datafield_id in the global config OERCAMPUS_TWILLO_DFNAAIID_DATAFIELD. If either this config or
@@ -44,9 +51,11 @@ class TwilloConnector
{
$user_id || $user_id = User::findCurrent()->id;
$base = new EduSharingHelperBase(
- 'https://www.twillo.de/edu-sharing',
+ self::$twillo_base_url,
file_get_contents($GLOBALS['STUDIP_BASE_PATH']."/config/twillo-private.key"),
- Config::get()->OERCAMPUS_TWILLO_APPID // 'data-quest-Test'
+ Config::get()->OERCAMPUS_TWILLO_APPID,
+ self::getHttpProxy()
+ // 'data-quest-Test'
);
$authHelper = new EduSharingAuthHelper($base);
if (!static::$ticket) {
@@ -63,11 +72,12 @@ class TwilloConnector
$header[] = "Accept: application/json";
$cr = curl_init();
- curl_setopt($cr, CURLOPT_URL, 'https://www.twillo.de/edu-sharing/rest/node/v1/nodes/-home-/-userhome-/children');
+ curl_setopt($cr, CURLOPT_URL, self::$twillo_base_url . '/rest/node/v1/nodes/-home-/-userhome-/children');
curl_setopt($cr, CURLOPT_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
+ curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$body = curl_exec($cr);
$error = curl_error($cr);
if ($error) {
@@ -95,11 +105,13 @@ class TwilloConnector
$cr = curl_init();
curl_setopt($cr, CURLOPT_POST, 1);
- curl_setopt($cr, CURLOPT_URL, 'https://www.twillo.de/edu-sharing/rest/node/v1/nodes/-home-/-userhome-/children?type=cm%3Afolder&renameIfExists=false&assocType=&versionComment=');
+ curl_setopt($cr, CURLOPT_URL, self::$twillo_base_url . '/rest/node/v1/nodes/-home-/-userhome-/children?type=cm%3Afolder&renameIfExists=false&assocType=&versionComment=');
curl_setopt($cr, CURLOPT_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
+ curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
+
$postbody = json_encode([
'cm:edu_forcemetadataset' => ['true'],
'cm:edu_metadataset' => ['mds'],
@@ -121,11 +133,12 @@ class TwilloConnector
$cr = curl_init();
curl_setopt($cr, CURLOPT_POST, 1);
- curl_setopt($cr, CURLOPT_URL, 'https://www.twillo.de/edu-sharing/rest/node/v1/nodes/-home-/'.$subfolder_id.'/children?type=ccm%3Aio&renameIfExists=true');
+ curl_setopt($cr, CURLOPT_URL, self::$twillo_base_url . '/rest/node/v1/nodes/-home-/'.$subfolder_id.'/children?type=ccm%3Aio&renameIfExists=true');
curl_setopt($cr, CURLOPT_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
+ curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$postbody = json_encode([
'ccm:wwwurl' => [$material->getDownloadUrl()],
'ccm:linktype' => ["USER_GENERATED"],
@@ -148,11 +161,12 @@ class TwilloConnector
$cr = curl_init();
curl_setopt($cr, CURLOPT_POST, 1);
- curl_setopt($cr, CURLOPT_URL, 'https://www.twillo.de/edu-sharing/rest/node/v1/nodes/-home-/'.$material['published_id_on_twillo'].'/metadata?versionComment=METADATA_UPDATE');
+ curl_setopt($cr, CURLOPT_URL, self::$twillo_base_url . '/rest/node/v1/nodes/-home-/'.$material['published_id_on_twillo'].'/metadata?versionComment=METADATA_UPDATE');
curl_setopt($cr, CURLOPT_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
+ curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$old_base = URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']);
$permalink = URLHelper::getLink("dispatch.php/oer/market/details/".$material->getId());
URLHelper::setBaseURL($old_base);
@@ -248,9 +262,10 @@ class TwilloConnector
$user_id || $user_id = User::findCurrent()->id;
$base = new EduSharingHelperBase(
- 'https://www.twillo.de/edu-sharing',
+ self::$twillo_base_url,
file_get_contents($GLOBALS['STUDIP_BASE_PATH']."/config/twillo-private.key"),
- Config::get()->OERCAMPUS_TWILLO_APPID // 'data-quest-Test'
+ Config::get()->OERCAMPUS_TWILLO_APPID,
+ self::getHttpProxy()// 'data-quest-Test'
);
$authHelper = new EduSharingAuthHelper($base);
if (!static::$ticket) {
@@ -264,10 +279,11 @@ class TwilloConnector
$cr = curl_init();
curl_setopt($cr, CURLOPT_CUSTOMREQUEST, "DELETE");
- curl_setopt($cr, CURLOPT_URL, 'https://www.twillo.de/edu-sharing/rest/node/v1/nodes/-home-/'.$oer_id);
+ curl_setopt($cr, CURLOPT_URL, self::$twillo_base_url . '/rest/node/v1/nodes/-home-/'.$oer_id);
curl_setopt($cr, CURLOPT_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
+ curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
curl_exec($cr);
curl_close($cr);
}
diff --git a/vendor/edu-sharing-plugin/edu-sharing-auth-helper.php b/vendor/edu-sharing-plugin/edu-sharing-auth-helper.php
index 071c0c6..ef9dec1 100644
--- a/vendor/edu-sharing-plugin/edu-sharing-auth-helper.php
+++ b/vendor/edu-sharing-plugin/edu-sharing-auth-helper.php
@@ -25,6 +25,9 @@ class EduSharingAuthHelper extends EduSharingHelperAbstract {
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 5
]);
+ if ($this->base->http_proxy) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
+ }
$data = json_decode(curl_exec($curl), true);
curl_close($curl);
if ( is_null( $data ) ) {
@@ -79,6 +82,9 @@ class EduSharingAuthHelper extends EduSharingHelperAbstract {
CURLOPT_POSTFIELDS,
is_array($bodyparams) ? json_encode($bodyparams) : (string) $bodyparams
);
+ if ($this->base->http_proxy) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
+ }
$output = curl_exec($curl);
$data = json_decode($output, true);
diff --git a/vendor/edu-sharing-plugin/edu-sharing-helper-base.php b/vendor/edu-sharing-plugin/edu-sharing-helper-base.php
index ac3e2f6..4c6f6da 100644
--- a/vendor/edu-sharing-plugin/edu-sharing-helper-base.php
+++ b/vendor/edu-sharing-plugin/edu-sharing-helper-base.php
@@ -5,6 +5,7 @@ class EduSharingHelperBase {
public $privateKey;
public $appId;
public $language = 'de';
+ public $http_proxy = '';
/**
* @param string $baseUrl
@@ -17,7 +18,8 @@ class EduSharingHelperBase {
public function __construct(
string $baseUrl,
string $privateKey,
- string $appId
+ string $appId,
+ string $http_proxy = ''
) {
if(!preg_match('/^([a-z]|[A-Z]|[0-9]|[-_])+$/', $appId)) {
throw new Exception('The given app id contains invalid characters or symbols');
@@ -25,6 +27,7 @@ class EduSharingHelperBase {
$this->baseUrl=$baseUrl;
$this->privateKey=$privateKey;
$this->appId=$appId;
+ $this->http_proxy = $http_proxy;
}
public function setLanguage(string $language) {
@@ -39,4 +42,4 @@ class EduSharingHelperBase {
return $signature;
}
-} \ No newline at end of file
+}
diff --git a/vendor/edu-sharing-plugin/edu-sharing-node-helper.php b/vendor/edu-sharing-plugin/edu-sharing-node-helper.php
index 112d7d8..6c7a18e 100644
--- a/vendor/edu-sharing-plugin/edu-sharing-node-helper.php
+++ b/vendor/edu-sharing-plugin/edu-sharing-node-helper.php
@@ -69,6 +69,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers
]);
+ if ($this->base->http_proxy) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
+ }
$data = json_decode(curl_exec($curl), true);
$err = curl_errno( $curl );
$info = curl_getinfo($curl);
@@ -127,6 +130,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers
]);
+ if ($this->base->http_proxy) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
+ }
$data = json_decode(curl_exec($curl), true);
$err = curl_errno( $curl );
$info = curl_getinfo($curl);
@@ -160,6 +166,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers
]);
+ if ($this->base->http_proxy) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
+ }
$data = json_decode(curl_exec($curl), true);
$err = curl_errno( $curl );
$info = curl_getinfo($curl);
@@ -172,4 +181,4 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
}
}
-} \ No newline at end of file
+}