aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2025-01-13 13:50:36 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2025-01-13 13:50:36 +0000
commitf14a6d177c29409b104c315ab01bafab2ee924c1 (patch)
tree392006ce98c061ff16ab88f75c891620e22d06b6
parent3ae09df837711b06195fe9694d53212f9df8ce3e (diff)
Resolve "Timeout für HTTP Requests in Ilias-Schnittstelle implementieren"
Closes #5014 Merge request studip/studip!3768
-rw-r--r--app/controllers/admin/ilias_interface.php8
-rw-r--r--app/views/admin/ilias_interface/edit_server.php12
-rw-r--r--lib/ilias_interface/ConnectedIlias.php44
-rw-r--r--lib/ilias_interface/IliasSoap.php24
-rw-r--r--lib/ilias_interface/StudipSoapClient.php4
5 files changed, 82 insertions, 10 deletions
diff --git a/app/controllers/admin/ilias_interface.php b/app/controllers/admin/ilias_interface.php
index 543324e..38fa8fa 100644
--- a/app/controllers/admin/ilias_interface.php
+++ b/app/controllers/admin/ilias_interface.php
@@ -130,6 +130,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
'name' => '',
'version' => '',
'url' => _('https://<URL zur ILIAS-Installation>'),
+ 'http_connection_timeout' => 1,
+ 'http_request_timeout' => 3,
'client' => '',
'ldap_enable' => '',
'reconnect_accounts' => false,
@@ -171,6 +173,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
if (count($info)) {
$this->valid_url = true;
$this->ilias_config['url'] = Request::get('ilias_url');
+ $this->ilias_config['http_connection_timeout'] = (int) Request::get('ilias_http_connection_timeout');
+ $this->ilias_config['http_request_timeout'] = (int) Request::get('ilias_http_request_timeout');
if ($info['version']) {
$this->ilias_version = $info['version'];
$this->ilias_version_date = $info['version_date'];
@@ -220,6 +224,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
if (Request::get('ilias_name')) {
$this->ilias_config['name'] = Request::get('ilias_name');
$this->ilias_config['url'] = Request::get('ilias_url');
+ $this->ilias_config['http_connection_timeout'] = (int) Request::get('ilias_http_connection_timeout');
+ $this->ilias_config['http_request_timeout'] = (int) Request::get('ilias_http_request_timeout');
}
$info = ConnectedIlias::getIliasInfo($this->ilias_config['url']);
if (count($info)) {
@@ -298,6 +304,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
$this->ilias_configs[$index]['version'] = Request::get('ilias_version');
}
$this->ilias_configs[$index]['url'] = Request::get('ilias_url');
+ $this->ilias_configs[$index]['http_connection_timeout'] = (int) Request::get('ilias_http_connection_timeout');
+ $this->ilias_configs[$index]['http_request_timeout'] = (int) Request::get('ilias_http_request_timeout');
if (Request::getInstance()->offsetExists('ilias_client')) {
$this->ilias_configs[$index]['client'] = Request::get('ilias_client');
}
diff --git a/app/views/admin/ilias_interface/edit_server.php b/app/views/admin/ilias_interface/edit_server.php
index 7e72d4c..18c648a 100644
--- a/app/views/admin/ilias_interface/edit_server.php
+++ b/app/views/admin/ilias_interface/edit_server.php
@@ -42,6 +42,14 @@
<span class="required"> <?= _('URL') ?></span>
<input type="text" name="ilias_url" size="50" maxlength="255" value="<?= $ilias_config['url'] ?>" required>
</label>
+ <label>
+ <span class="required"> <?= _('HTTP Connection Timeout (in Sekunden)') ?></span>
+ <input type="number" name="ilias_http_connection_timeout" value="<?= $ilias_config['http_connection_timeout'] ?? 1 ?>" required>
+ </label>
+ <label>
+ <span class="required"> <?= _('HTTP Request Timeout (in Sekunden)') ?></span>
+ <input type="number" name="ilias_http_request_timeout" value="<?= $ilias_config['http_request_timeout'] ?? 3 ?>" required>
+ </label>
<? if ($valid_url) : ?>
<label for="ilias_version">
<span class="required"><?= _('ILIAS Version') ?></span>
@@ -54,10 +62,10 @@
</label>
<label>
<span class="required"> <?= _('Name des ILIAS-Mandanten') ?></span>
- <? if (count($ilias_clients) == 1) : ?>
+ <? if (isset($ilias_clients) && count($ilias_clients) == 1) : ?>
<input type="hidden" name="ilias_client" value="<?=htmlReady($ilias_clients[0])?>">
<div><?=htmlReady($ilias_clients[0])?></div>
- <? elseif (count($ilias_clients) > 1) : ?>
+ <? elseif (isset($ilias_clients) && count($ilias_clients) > 1) : ?>
<select name="ilias_client">
<? foreach ($ilias_clients as $client_name) : ?>
<option value="<?=htmlReady($client_name)?>" <?= $client_name == $ilias_config['client'] ? ' selected' : ''?>><?=htmlReady($client_name)?></option>
diff --git a/lib/ilias_interface/ConnectedIlias.php b/lib/ilias_interface/ConnectedIlias.php
index a917e1a..45f5e3d 100644
--- a/lib/ilias_interface/ConnectedIlias.php
+++ b/lib/ilias_interface/ConnectedIlias.php
@@ -82,7 +82,16 @@ class ConnectedIlias
$this->ilias_int_version = $this->getIntVersion($this->ilias_config['version']);
// init soap client
- $this->soap_client = new IliasSoap($this->index, $this->ilias_config['url'].'/webservice/soap/server.php?wsdl', $this->ilias_config['client'], $this->ilias_int_version, $this->ilias_config['admin'], $this->ilias_config['admin_pw']);
+ $this->soap_client = new IliasSoap(
+ $this->index,
+ $this->ilias_config['url'] . '/webservice/soap/server.php?wsdl',
+ $this->ilias_config['client'],
+ $this->ilias_int_version,
+ $this->ilias_config['admin'],
+ $this->ilias_config['admin_pw'],
+ $this->ilias_config['http_connection_timeout'],
+ $this->ilias_config['http_request_timeout']
+ );
$this->soap_client->setCachingStatus($this->ilias_interface_config['cache']);
// init current user (only if ILIAS installation is active)
@@ -154,14 +163,34 @@ class ConnectedIlias
public static function getIliasInfo($url)
{
$info = [];
+
+ $stream_context = get_default_http_stream_context($url);
+ stream_context_set_option(
+ $stream_context,
+ 'http',
+ 'timeout',
+ 3
+ );
+
// check if url exists
- $check = @get_headers($url . 'login.php');
+ $check = @get_headers($url . 'login.php', false, $stream_context);
if (strpos($check[0], '200') === false) {
return $info;
} else {
$info['url'] = $url;
}
- $soap_client = new IliasSoap('new', $url.'/webservice/soap/server.php?wsdl');
+
+ $soap_client = new IliasSoap(
+ 'new',
+ $url . '/webservice/soap/server.php?wsdl',
+ '',
+ '',
+ '',
+ '',
+ 1,
+ 3
+ );
+
$soap_client->setCachingStatus(false);
if ($client_info = $soap_client->getInstallationInfoXML()) {
$info = array_merge($info, $client_info);
@@ -223,7 +252,14 @@ class ConnectedIlias
}
// check if url exists
- $check = @get_headers($this->ilias_config['url'] . 'webservice/soap/server.php');
+ $stream_context = get_default_http_stream_context($this->ilias_config['url']);
+ stream_context_set_option(
+ $stream_context,
+ 'http',
+ 'timeout',
+ $this->ilias_config['http_request_timeout']
+ );
+ $check = @get_headers($this->ilias_config['url'] . 'webservice/soap/server.php', false, $stream_context);
if (strpos($check[0], '200') === false) {
$this->error[] = sprintf(_('Die URL "%s" ist nicht erreichbar.'), $this->ilias_config['url']);
return false;
diff --git a/lib/ilias_interface/IliasSoap.php b/lib/ilias_interface/IliasSoap.php
index 9168195..6b6226d 100644
--- a/lib/ilias_interface/IliasSoap.php
+++ b/lib/ilias_interface/IliasSoap.php
@@ -44,7 +44,7 @@ class IliasSoap extends StudipSoapClient
* @param string $admin_login ILIAS admin account login
* @param string $admin_password ILIAS admin account password
*/
- public function __construct($index, $soap_path, $ilias_client = '', $ilias_version = '', $admin_login = '', $admin_password = '')
+ public function __construct($index, $soap_path, $ilias_client = '', $ilias_version = '', $admin_login = '', $admin_password = '', $http_connection_timeout = NULL, $http_request_timeout = NULL)
{
$this->index = $index;
$this->ilias_client = $ilias_client;
@@ -53,7 +53,27 @@ class IliasSoap extends StudipSoapClient
$this->admin_password = $admin_password;
$this->separator_string = " / ";
- parent::__construct($soap_path);
+ $stream_context = get_default_http_stream_context($soap_path);
+
+ if (is_int($http_request_timeout)) {
+ stream_context_set_option(
+ $stream_context,
+ 'http',
+ 'timeout',
+ $http_request_timeout
+ );
+ }
+
+ $options = [
+ 'trace' => 0,
+ 'stream_context' => $stream_context
+ ];
+
+ if (is_int($http_connection_timeout)) {
+ $options['connection_timeout'] = $http_connection_timeout;
+ }
+
+ parent::__construct($soap_path, $options);
$this->user_type = "admin";
diff --git a/lib/ilias_interface/StudipSoapClient.php b/lib/ilias_interface/StudipSoapClient.php
index 6a22f86..a92d1e5 100644
--- a/lib/ilias_interface/StudipSoapClient.php
+++ b/lib/ilias_interface/StudipSoapClient.php
@@ -15,10 +15,10 @@ class StudipSoapClient
public $error;
public $faultstring;
- function __construct($path)
+ function __construct($path, $options = ['trace' => 0])
{
try {
- $this->soap_client = new SoapClient($path, ['trace' => 0]);
+ $this->soap_client = new SoapClient($path, $options);
} catch (SoapFault $fault) {
$this->error = "Soap Constructor Error " . $fault->faultcode . ": ".$fault->faultstring;
}