Skip to content

Commit

Permalink
Curl: make proxy-settings and curl DI ready
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Oct 2, 2024
1 parent 6ab4c51 commit dde5322
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function achieve(Setup\Environment $environment): Setup\Environment
{
$client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
$admin_interaction = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
$factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
$settings = $factory->settingsFor("common");

$session_max_idle = $this->config->getSessionMaxIdle();

Expand All @@ -69,7 +71,7 @@ public function achieve(Setup\Environment $environment): Setup\Environment

$key = bin2hex(random_bytes(32));
$this->generateServerInfoFile($key);
var_dump($this->getPHPIniValues($key));
var_dump($this->getPHPIniValues($settings, $key));
die();
list($cookie_lifetime, $gc_maxlifetime) = $this->getPHPIniValues();

Expand Down Expand Up @@ -109,9 +111,12 @@ protected function getPHPIniPathForApache(string $url): string
return exec("wget -q -O - {$url} | grep 'Loaded Configuration File' | cut -d '<' -f5 | cut -d '>' -f2");
}

protected function getPHPIniValues(string $key): array
protected function getPHPIniValues(ilSetting $settings, string $key): array
{
$curl = new ilCurlConnection("http://doil/trunk10/server_info.php?token=$key");
$curl = new ilCurlConnection(
"http://doil/trunk10/server_info.php?token=$key",
new ilProxySettings($settings)
);
$curl->init();
// try {
// $curl = new ilCurlConnection("http://doil/trunk10/server_info.php?token=$key");
Expand All @@ -129,7 +134,6 @@ protected function getPHPIniValues(string $key): array

// $curl->exec();
// var_dump($curl->getResponseBody());
die();
return explode(",", $foo);
}

Expand Down
12 changes: 5 additions & 7 deletions components/ILIAS/Http_/classes/class.ilProxySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ class ilProxySettings
protected string $host = '';
protected int $port = 80;
protected bool $active = false;
protected ilSetting $setting;

protected function __construct()
{
global $DIC;

$this->setting = $DIC->settings();
public function __construct(
protected ilSetting $setting
) {
$this->read();
}

public static function _getInstance(): ilProxySettings
{
if (null === self::$_instance) {
self::$_instance = new self();
global $DIC;
self::$_instance = new self($DIC->settings());
}

return self::$_instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@
*/
class ilCurlConnection
{
protected string $url = '';

/** @var CurlHandle|resource|null $ch */
protected $ch = null;
private string $header_plain = '';
private array $header_arr = array();
private string $response_body = '';

public function __construct(string $a_url = '')
{
$this->url = $a_url;

public function __construct(
protected string $url = '',
protected ?ilProxySettings $proxy_settings = null
) {
if (!self::_isCurlExtensionLoaded()) {
throw new ilCurlConnectionException('Curl extension not enabled.');
}
Expand Down Expand Up @@ -87,7 +85,7 @@ final public function init(bool $set_proxy = true): bool

if ($set_proxy) {
// use a proxy, if configured by ILIAS
$proxy = ilProxySettings::_getInstance();
$proxy = $this->proxy_settings ?? ilProxySettings::_getInstance();
if ($proxy->isActive()) {
$this->setOpt(CURLOPT_HTTPPROXYTUNNEL, true);

Expand Down

0 comments on commit dde5322

Please sign in to comment.