Skip to content
Snippets Groups Projects
Commit 662d3d67 authored by Philipp Schüttlöffel's avatar Philipp Schüttlöffel Committed by Marcus Eibrink-Lunzenauer
Browse files

Resolve "Timeout für HTTP Requests in Ilias-Schnittstelle implementieren"

Closes #5014

Merge request studip/studip!3768
parent 9f9481fd
No related branches found
No related tags found
No related merge requests found
...@@ -130,6 +130,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController ...@@ -130,6 +130,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
'name' => '', 'name' => '',
'version' => '', 'version' => '',
'url' => _('https://<URL zur ILIAS-Installation>'), 'url' => _('https://<URL zur ILIAS-Installation>'),
'http_connection_timeout' => 1,
'http_request_timeout' => 3,
'client' => '', 'client' => '',
'ldap_enable' => '', 'ldap_enable' => '',
'reconnect_accounts' => false, 'reconnect_accounts' => false,
...@@ -171,6 +173,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController ...@@ -171,6 +173,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
if (count($info)) { if (count($info)) {
$this->valid_url = true; $this->valid_url = true;
$this->ilias_config['url'] = Request::get('ilias_url'); $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']) { if ($info['version']) {
$this->ilias_version = $info['version']; $this->ilias_version = $info['version'];
$this->ilias_version_date = $info['version_date']; $this->ilias_version_date = $info['version_date'];
...@@ -220,6 +224,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController ...@@ -220,6 +224,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
if (Request::get('ilias_name')) { if (Request::get('ilias_name')) {
$this->ilias_config['name'] = Request::get('ilias_name'); $this->ilias_config['name'] = Request::get('ilias_name');
$this->ilias_config['url'] = Request::get('ilias_url'); $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']); $info = ConnectedIlias::getIliasInfo($this->ilias_config['url']);
if (count($info)) { if (count($info)) {
...@@ -298,6 +304,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController ...@@ -298,6 +304,8 @@ class Admin_IliasInterfaceController extends AuthenticatedController
$this->ilias_configs[$index]['version'] = Request::get('ilias_version'); $this->ilias_configs[$index]['version'] = Request::get('ilias_version');
} }
$this->ilias_configs[$index]['url'] = Request::get('ilias_url'); $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')) { if (Request::getInstance()->offsetExists('ilias_client')) {
$this->ilias_configs[$index]['client'] = Request::get('ilias_client'); $this->ilias_configs[$index]['client'] = Request::get('ilias_client');
} }
......
...@@ -42,6 +42,14 @@ ...@@ -42,6 +42,14 @@
<span class="required"> <?= _('URL') ?></span> <span class="required"> <?= _('URL') ?></span>
<input type="text" name="ilias_url" size="50" maxlength="255" value="<?= $ilias_config['url'] ?>" required> <input type="text" name="ilias_url" size="50" maxlength="255" value="<?= $ilias_config['url'] ?>" required>
</label> </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) : ?> <? if ($valid_url) : ?>
<label for="ilias_version"> <label for="ilias_version">
<span class="required"><?= _('ILIAS Version') ?></span> <span class="required"><?= _('ILIAS Version') ?></span>
...@@ -54,10 +62,10 @@ ...@@ -54,10 +62,10 @@
</label> </label>
<label> <label>
<span class="required"> <?= _('Name des ILIAS-Mandanten') ?></span> <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])?>"> <input type="hidden" name="ilias_client" value="<?=htmlReady($ilias_clients[0])?>">
<div><?=htmlReady($ilias_clients[0])?></div> <div><?=htmlReady($ilias_clients[0])?></div>
<? elseif (count($ilias_clients) > 1) : ?> <? elseif (isset($ilias_clients) && count($ilias_clients) > 1) : ?>
<select name="ilias_client"> <select name="ilias_client">
<? foreach ($ilias_clients as $client_name) : ?> <? foreach ($ilias_clients as $client_name) : ?>
<option value="<?=htmlReady($client_name)?>" <?= $client_name == $ilias_config['client'] ? ' selected' : ''?>><?=htmlReady($client_name)?></option> <option value="<?=htmlReady($client_name)?>" <?= $client_name == $ilias_config['client'] ? ' selected' : ''?>><?=htmlReady($client_name)?></option>
......
...@@ -82,7 +82,16 @@ class ConnectedIlias ...@@ -82,7 +82,16 @@ class ConnectedIlias
$this->ilias_int_version = $this->getIntVersion($this->ilias_config['version']); $this->ilias_int_version = $this->getIntVersion($this->ilias_config['version']);
// init soap client // 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']); $this->soap_client->setCachingStatus($this->ilias_interface_config['cache']);
// init current user (only if ILIAS installation is active) // init current user (only if ILIAS installation is active)
...@@ -154,14 +163,34 @@ class ConnectedIlias ...@@ -154,14 +163,34 @@ class ConnectedIlias
public static function getIliasInfo($url) public static function getIliasInfo($url)
{ {
$info = []; $info = [];
$stream_context = get_default_http_stream_context($url);
stream_context_set_option(
$stream_context,
'http',
'timeout',
3
);
// check if url exists // 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) { if (strpos($check[0], '200') === false) {
return $info; return $info;
} else { } else {
$info['url'] = $url; $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); $soap_client->setCachingStatus(false);
if ($client_info = $soap_client->getInstallationInfoXML()) { if ($client_info = $soap_client->getInstallationInfoXML()) {
$info = array_merge($info, $client_info); $info = array_merge($info, $client_info);
...@@ -223,7 +252,14 @@ class ConnectedIlias ...@@ -223,7 +252,14 @@ class ConnectedIlias
} }
// check if url exists // 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) { if (strpos($check[0], '200') === false) {
$this->error[] = sprintf(_('Die URL "%s" ist nicht erreichbar.'), $this->ilias_config['url']); $this->error[] = sprintf(_('Die URL "%s" ist nicht erreichbar.'), $this->ilias_config['url']);
return false; return false;
......
...@@ -44,7 +44,7 @@ class IliasSoap extends StudipSoapClient ...@@ -44,7 +44,7 @@ class IliasSoap extends StudipSoapClient
* @param string $admin_login ILIAS admin account login * @param string $admin_login ILIAS admin account login
* @param string $admin_password ILIAS admin account password * @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->index = $index;
$this->ilias_client = $ilias_client; $this->ilias_client = $ilias_client;
...@@ -53,7 +53,27 @@ class IliasSoap extends StudipSoapClient ...@@ -53,7 +53,27 @@ class IliasSoap extends StudipSoapClient
$this->admin_password = $admin_password; $this->admin_password = $admin_password;
$this->separator_string = " / "; $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"; $this->user_type = "admin";
......
...@@ -15,10 +15,10 @@ class StudipSoapClient ...@@ -15,10 +15,10 @@ class StudipSoapClient
public $error; public $error;
public $faultstring; public $faultstring;
function __construct($path) function __construct($path, $options = ['trace' => 0])
{ {
try { try {
$this->soap_client = new SoapClient($path, ['trace' => 0]); $this->soap_client = new SoapClient($path, $options);
} catch (SoapFault $fault) { } catch (SoapFault $fault) {
$this->error = "Soap Constructor Error " . $fault->faultcode . ": ".$fault->faultstring; $this->error = "Soap Constructor Error " . $fault->faultcode . ": ".$fault->faultstring;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment