Skip to content

Commit

Permalink
Setup - remove proxy settings gui from Admin/Server tab, and add an e…
Browse files Browse the repository at this point in the history
…xternal condition checking connectivity to a proxy
  • Loading branch information
daniwe4 authored and klees committed Nov 6, 2020
1 parent 3b186cb commit 0108454
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 162 deletions.
159 changes: 0 additions & 159 deletions Modules/SystemFolder/classes/class.ilObjSystemFolderGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,6 @@ public function setServerInfoSubTabs($a_activate)
$ilTabs->addSubTabTarget("server_data", $ilCtrl->getLinkTarget($this, "showServerInfo"));

if ($rbacsystem->checkAccess("write", $this->object->getRefId())) {
$ilTabs->addSubTabTarget("proxy", $ilCtrl->getLinkTarget($this, "showProxy"));
$ilTabs->addSubTabTarget("java_server", $ilCtrl->getLinkTarget($this, "showJavaServer"));
$ilTabs->addSubTabTarget("webservices", $ilCtrl->getLinkTarget($this, "showWebServices"));
}
Expand Down Expand Up @@ -1997,164 +1996,6 @@ public function saveJavaServerObject()
$tpl->setContent($this->form->getHtml());
}
}

/**
*
* Show proxy settings
*
* @access public
*
*/
public function showProxyObject()
{
$tpl = $this->tpl;
$ilAccess = $this->access;
$ilErr = $this->error;

if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
}

require_once './Services/Http/classes/class.ilProxySettings.php';

$this->initProxyForm();
$this->form->setValuesByArray(array(
'proxy_status' => ilProxySettings::_getInstance()->isActive(),
'proxy_host' => ilProxySettings::_getInstance()->getHost(),
'proxy_port' => ilProxySettings::_getInstance()->getPort()
));
if (ilProxySettings::_getInstance()->isActive()) {
$this->printProxyStatus();
}

$tpl->setContent($this->form->getHTML());
}

/**
*
* Print proxy settings
*
* @access private
*
*/
private function printProxyStatus()
{
try {
ilProxySettings::_getInstance()->checkConnection();
$this->form->getItemByPostVar('proxy_availability')->setHTML(
'<img src="' . ilUtil::getImagePath('icon_ok.svg') . '" /> ' .
$this->lng->txt('proxy_connectable')
);
} catch (ilProxyException $e) {
$this->form->getItemByPostVar('proxy_availability')->setHTML(
'<img src="' . ilUtil::getImagePath('icon_not_ok.svg') . '" /> ' .
$this->lng->txt('proxy_not_connectable')
);
ilUtil::sendFailure(sprintf($this->lng->txt('proxy_socket_error'), $e->getMessage()));
}
}

/**
*
* Save proxy settings
*
* @access public
*
*/
public function saveProxyObject()
{
$tpl = $this->tpl;
$ilAccess = $this->access;
$ilErr = $this->error;
$lng = $this->lng;

if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$ilErr->raiseError($lng->txt('permission_denied'), $ilErr->MESSAGE);
}

require_once './Services/Http/classes/class.ilProxySettings.php';

$this->initProxyForm();
$isFormValid = $this->form->checkInput();
ilProxySettings::_getInstance()->isActive((int) $this->form->getInput('proxy_status'))
->setHost(trim($this->form->getInput('proxy_host')))
->setPort(trim($this->form->getInput('proxy_port')));
if ($isFormValid) {
if (ilProxySettings::_getInstance()->isActive()) {
if (!strlen(ilProxySettings::_getInstance()->getHost())) {
$isFormValid = false;
$this->form->getItemByPostVar('proxy_host')->setAlert($lng->txt('msg_input_is_required'));
}
if (!strlen(ilProxySettings::_getInstance()->getPort())) {
$isFormValid = false;
$this->form->getItemByPostVar('proxy_port')->setAlert($lng->txt('msg_input_is_required'));
}
if (!preg_match('/[0-9]{1,}/', ilProxySettings::_getInstance()->getPort()) ||
ilProxySettings::_getInstance()->getPort() < 0 ||
ilProxySettings::_getInstance()->getPort() > 65535) {
$isFormValid = false;
$this->form->getItemByPostVar('proxy_port')->setAlert($lng->txt('proxy_port_numeric'));
}
}

if ($isFormValid) {
ilProxySettings::_getInstance()->save();
ilUtil::sendSuccess($lng->txt('saved_successfully'));
if (ilProxySettings::_getInstance()->isActive()) {
$this->printProxyStatus();
}
} else {
ilUtil::sendFailure($lng->txt('form_input_not_valid'));
}
}

$this->form->setValuesByPost();
$tpl->setContent($this->form->getHTML());
}

/**
*
* Initialize proxy settings form
*
* @access public
*
*/
private function initProxyForm()
{
$lng = $this->lng;
$ilCtrl = $this->ctrl;

$this->setServerInfoSubTabs('proxy');

include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
$this->form = new ilPropertyFormGUI();
$this->form->setFormAction($ilCtrl->getFormAction($this, 'saveProxy'));

// Proxy status
$proxs = new ilCheckboxInputGUI($lng->txt('proxy_status'), 'proxy_status');
$proxs->setInfo($lng->txt('proxy_status_info'));
$proxs->setValue(1);
$this->form->addItem($proxs);

// Proxy availability
$proxa = new ilCustomInputGUI('', 'proxy_availability');
$proxs->addSubItem($proxa);

// Proxy
$prox = new ilTextInputGUI($lng->txt('proxy_host'), 'proxy_host');
$prox->setInfo($lng->txt('proxy_host_info'));
$proxs->addSubItem($prox);

// Proxy Port
$proxp = new ilTextInputGUI($lng->txt('proxy_port'), 'proxy_port');
$proxp->setInfo($lng->txt('proxy_port_info'));
$proxp->setSize(10);
$proxp->setMaxLength(10);
$proxs->addSubItem($proxp);

// save and cancel commands
$this->form->addCommandButton('saveProxy', $lng->txt('save'));
}

public function addToExternalSettingsForm($a_form_id)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

/* Copyright (c) 2020 Daniel Weise <[email protected]> Extended GPL, see docs/LICENSE */

use ILIAS\Setup;
use ILIAS\Setup\Condition\ExternalConditionObjective;

class ProxyConnectableCondition extends ExternalConditionObjective
{
public function __construct($config)
{
return parent::__construct(
"Can establish a connection to proxy",
function (Setup\Environment $env) use ($config) : bool {
try {
$host = $config->getProxyHost();
if (strspn($host, '.0123456789') != strlen($host) && strstr($host, '/') === false) {
$host = gethostbyname($host);
}
$port = $config->getProxyPort() % 65536;

if (!fsockopen($host, $port, $errno, $errstr, 10)) {
throw new Exception("Can`t establish connection to proxy.");
}
} catch (\Exception $e) {
return false;
}

return true;
},
"Can`t establish connection to proxy."
);
}
}
15 changes: 12 additions & 3 deletions Services/Http/classes/Setup/class.ilHttpSetupAgent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
<?php declare(strict_types=1);

/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
/* Copyright (c) 2020 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */

use ILIAS\Setup;
use ILIAS\Refinery;
Expand Down Expand Up @@ -63,7 +63,16 @@ public function getArrayToConfigTransformation() : Refinery\Transformation
*/
public function getInstallObjective(Setup\Config $config = null) : Setup\Objective
{
return new ilHttpConfigStoredObjective($config);
$http_config_stored = new ilHttpConfigStoredObjective($config);

if (!$config->isProxyEnabled()) {
return $http_config_stored;
}

return new Setup\Objective\ObjectiveWithPreconditions(
$http_config_stored,
new ProxyConnectableCondition($config)
);
}

/**
Expand Down

0 comments on commit 0108454

Please sign in to comment.