Skip to content
Snippets Groups Projects
Commit bef638fe authored by André Noack's avatar André Noack
Browse files

Resolve "TwilloConnector ignoriert Proxy Einstellungen"

parent be2dbace
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,13 @@ class TwilloConnector ...@@ -11,6 +11,13 @@ class TwilloConnector
*/ */
static protected $ticket = null; 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 * 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 * datafield_id in the global config OERCAMPUS_TWILLO_DFNAAIID_DATAFIELD. If either this config or
...@@ -44,9 +51,11 @@ class TwilloConnector ...@@ -44,9 +51,11 @@ class TwilloConnector
{ {
$user_id || $user_id = User::findCurrent()->id; $user_id || $user_id = User::findCurrent()->id;
$base = new EduSharingHelperBase( $base = new EduSharingHelperBase(
'https://www.twillo.de/edu-sharing', self::$twillo_base_url,
file_get_contents($GLOBALS['STUDIP_BASE_PATH']."/config/twillo-private.key"), 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); $authHelper = new EduSharingAuthHelper($base);
if (!static::$ticket) { if (!static::$ticket) {
...@@ -63,11 +72,12 @@ class TwilloConnector ...@@ -63,11 +72,12 @@ class TwilloConnector
$header[] = "Accept: application/json"; $header[] = "Accept: application/json";
$cr = curl_init(); $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_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$body = curl_exec($cr); $body = curl_exec($cr);
$error = curl_error($cr); $error = curl_error($cr);
if ($error) { if ($error) {
...@@ -95,11 +105,13 @@ class TwilloConnector ...@@ -95,11 +105,13 @@ class TwilloConnector
$cr = curl_init(); $cr = curl_init();
curl_setopt($cr, CURLOPT_POST, 1); 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_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$postbody = json_encode([ $postbody = json_encode([
'cm:edu_forcemetadataset' => ['true'], 'cm:edu_forcemetadataset' => ['true'],
'cm:edu_metadataset' => ['mds'], 'cm:edu_metadataset' => ['mds'],
...@@ -121,11 +133,12 @@ class TwilloConnector ...@@ -121,11 +133,12 @@ class TwilloConnector
$cr = curl_init(); $cr = curl_init();
curl_setopt($cr, CURLOPT_POST, 1); 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_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$postbody = json_encode([ $postbody = json_encode([
'ccm:wwwurl' => [$material->getDownloadUrl()], 'ccm:wwwurl' => [$material->getDownloadUrl()],
'ccm:linktype' => ["USER_GENERATED"], 'ccm:linktype' => ["USER_GENERATED"],
...@@ -148,11 +161,12 @@ class TwilloConnector ...@@ -148,11 +161,12 @@ class TwilloConnector
$cr = curl_init(); $cr = curl_init();
curl_setopt($cr, CURLOPT_POST, 1); 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_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
$old_base = URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']); $old_base = URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']);
$permalink = URLHelper::getLink("dispatch.php/oer/market/details/".$material->getId()); $permalink = URLHelper::getLink("dispatch.php/oer/market/details/".$material->getId());
URLHelper::setBaseURL($old_base); URLHelper::setBaseURL($old_base);
...@@ -248,9 +262,10 @@ class TwilloConnector ...@@ -248,9 +262,10 @@ class TwilloConnector
$user_id || $user_id = User::findCurrent()->id; $user_id || $user_id = User::findCurrent()->id;
$base = new EduSharingHelperBase( $base = new EduSharingHelperBase(
'https://www.twillo.de/edu-sharing', self::$twillo_base_url,
file_get_contents($GLOBALS['STUDIP_BASE_PATH']."/config/twillo-private.key"), 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); $authHelper = new EduSharingAuthHelper($base);
if (!static::$ticket) { if (!static::$ticket) {
...@@ -264,10 +279,11 @@ class TwilloConnector ...@@ -264,10 +279,11 @@ class TwilloConnector
$cr = curl_init(); $cr = curl_init();
curl_setopt($cr, CURLOPT_CUSTOMREQUEST, "DELETE"); 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_HTTPHEADER, $header);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cr, CURLOPT_PROXY, self::getHttpProxy());
curl_exec($cr); curl_exec($cr);
curl_close($cr); curl_close($cr);
} }
......
...@@ -25,6 +25,9 @@ class EduSharingAuthHelper extends EduSharingHelperAbstract { ...@@ -25,6 +25,9 @@ class EduSharingAuthHelper extends EduSharingHelperAbstract {
CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 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); $data = json_decode(curl_exec($curl), true);
curl_close($curl); curl_close($curl);
if ( is_null( $data ) ) { if ( is_null( $data ) ) {
...@@ -79,6 +82,9 @@ class EduSharingAuthHelper extends EduSharingHelperAbstract { ...@@ -79,6 +82,9 @@ class EduSharingAuthHelper extends EduSharingHelperAbstract {
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,
is_array($bodyparams) ? json_encode($bodyparams) : (string) $bodyparams 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); $output = curl_exec($curl);
$data = json_decode($output, true); $data = json_decode($output, true);
......
...@@ -5,6 +5,7 @@ class EduSharingHelperBase { ...@@ -5,6 +5,7 @@ class EduSharingHelperBase {
public $privateKey; public $privateKey;
public $appId; public $appId;
public $language = 'de'; public $language = 'de';
public $http_proxy = '';
/** /**
* @param string $baseUrl * @param string $baseUrl
...@@ -17,7 +18,8 @@ class EduSharingHelperBase { ...@@ -17,7 +18,8 @@ class EduSharingHelperBase {
public function __construct( public function __construct(
string $baseUrl, string $baseUrl,
string $privateKey, string $privateKey,
string $appId string $appId,
string $http_proxy = ''
) { ) {
if(!preg_match('/^([a-z]|[A-Z]|[0-9]|[-_])+$/', $appId)) { if(!preg_match('/^([a-z]|[A-Z]|[0-9]|[-_])+$/', $appId)) {
throw new Exception('The given app id contains invalid characters or symbols'); throw new Exception('The given app id contains invalid characters or symbols');
...@@ -25,6 +27,7 @@ class EduSharingHelperBase { ...@@ -25,6 +27,7 @@ class EduSharingHelperBase {
$this->baseUrl=$baseUrl; $this->baseUrl=$baseUrl;
$this->privateKey=$privateKey; $this->privateKey=$privateKey;
$this->appId=$appId; $this->appId=$appId;
$this->http_proxy = $http_proxy;
} }
public function setLanguage(string $language) { public function setLanguage(string $language) {
...@@ -39,4 +42,4 @@ class EduSharingHelperBase { ...@@ -39,4 +42,4 @@ class EduSharingHelperBase {
return $signature; return $signature;
} }
} }
\ No newline at end of file
...@@ -69,6 +69,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract { ...@@ -69,6 +69,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
CURLOPT_RETURNTRANSFER => 1, CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers CURLOPT_HTTPHEADER => $headers
]); ]);
if ($this->base->http_proxy) {
curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
}
$data = json_decode(curl_exec($curl), true); $data = json_decode(curl_exec($curl), true);
$err = curl_errno( $curl ); $err = curl_errno( $curl );
$info = curl_getinfo($curl); $info = curl_getinfo($curl);
...@@ -127,6 +130,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract { ...@@ -127,6 +130,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
CURLOPT_RETURNTRANSFER => 1, CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers CURLOPT_HTTPHEADER => $headers
]); ]);
if ($this->base->http_proxy) {
curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
}
$data = json_decode(curl_exec($curl), true); $data = json_decode(curl_exec($curl), true);
$err = curl_errno( $curl ); $err = curl_errno( $curl );
$info = curl_getinfo($curl); $info = curl_getinfo($curl);
...@@ -160,6 +166,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract { ...@@ -160,6 +166,9 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
CURLOPT_RETURNTRANSFER => 1, CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers CURLOPT_HTTPHEADER => $headers
]); ]);
if ($this->base->http_proxy) {
curl_setopt($curl, CURLOPT_PROXY, $this->base->http_proxy);
}
$data = json_decode(curl_exec($curl), true); $data = json_decode(curl_exec($curl), true);
$err = curl_errno( $curl ); $err = curl_errno( $curl );
$info = curl_getinfo($curl); $info = curl_getinfo($curl);
...@@ -172,4 +181,4 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract { ...@@ -172,4 +181,4 @@ class EduSharingNodeHelper extends EduSharingHelperAbstract {
} }
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment