Skip to content
Commits on Source (3)
...@@ -32,7 +32,7 @@ class ilObjMediaObjectAccess implements ilWACCheckingClass ...@@ -32,7 +32,7 @@ class ilObjMediaObjectAccess implements ilWACCheckingClass
$this->access = $DIC->access(); $this->access = $DIC->access();
} }
public function canBeDelivered(ilWACPath $ilWACPath) public function canBeDelivered(ilWACPath $ilWACPath) : bool
{ {
preg_match("/.\\/data\\/.*\\/mm_([0-9]*)\\/.*/ui", $ilWACPath->getPath(), $matches); preg_match("/.\\/data\\/.*\\/mm_([0-9]*)\\/.*/ui", $ilWACPath->getPath(), $matches);
$obj_id = $matches[1]; $obj_id = $matches[1];
......
<?php declare(strict_types = 1); <?php declare(strict_types = 1);
use ILIAS\Setup; /**
/******************************************************************************
*
* This file is part of ILIAS, a powerful learning management system * This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V. * published by ILIAS open source e-Learning e.V.
* *
...@@ -14,20 +11,63 @@ use ILIAS\Setup; ...@@ -14,20 +11,63 @@ use ILIAS\Setup;
* *
* If this is not the case or you just want to try ILIAS, you'll find * If this is not the case or you just want to try ILIAS, you'll find
* us at: * us at:
* https://www.ilias.de * https://www.ilias.de
* https://github.com/ILIAS-eLearning * https://github.com/ILIAS-eLearning
* *
*****************************************************************************/ *********************************************************************/
/** use ILIAS\Setup;
* @author Ingmar Szmais <iszmais@databay.de> use ILIAS\Refinery;
*/ use ILIAS\Setup\Environment;
class ilNotificationUpdateAgent extends Setup\Agent\NullAgent
class ilNotificationUpdateAgent implements Setup\Agent
{ {
use Setup\Agent\HasNoNamedObjective;
public function hasConfig() : bool
{
return false;
}
public function getArrayToConfigTransformation() : Refinery\Transformation
{
throw new LogicException('Agent has no config.');
}
public function getInstallObjective(Setup\Config $config = null) : Setup\Objective
{
return new Setup\Objective\NullObjective();
}
public function getUpdateObjective(Setup\Config $config = null) : Setup\Objective public function getUpdateObjective(Setup\Config $config = null) : Setup\Objective
{ {
return new ilDatabaseUpdateStepsExecutedObjective( return new class(new ilNotificationUpdateSteps()) extends ilDatabaseUpdateStepsExecutedObjective {
new ilNotificationUpdateSteps() public function getPreconditions(Environment $environment) : array
); {
$preconditions = parent::getPreconditions($environment);
$preconditions[] = new ilTreeAdminNodeAddedObjective(
'nota',
'Notification Service Administration Object'
);
return $preconditions;
}
};
}
public function getBuildArtifactObjective() : Setup\Objective
{
return new Setup\Objective\NullObjective();
}
public function getStatusObjective(Setup\Metrics\Storage $storage) : Setup\Objective
{
return new Setup\Objective\NullObjective();
}
public function getMigrations() : array
{
return [];
} }
} }
<?php declare(strict_types = 1); <?php declare(strict_types = 1);
/****************************************************************************** /**
*
* This file is part of ILIAS, a powerful learning management system * This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V. * published by ILIAS open source e-Learning e.V.
* *
...@@ -12,29 +11,23 @@ ...@@ -12,29 +11,23 @@
* *
* If this is not the case or you just want to try ILIAS, you'll find * If this is not the case or you just want to try ILIAS, you'll find
* us at: * us at:
* https://www.ilias.de * https://www.ilias.de
* https://github.com/ILIAS-eLearning * https://github.com/ILIAS-eLearning
* *
*****************************************************************************/ *********************************************************************/
use ILIAS\Notifications\ilNotificationSetupHelper;
/**
* @author Ingmar Szmais <iszmais@databay.de>
*/
class ilNotificationUpdateSteps implements ilDatabaseUpdateSteps class ilNotificationUpdateSteps implements ilDatabaseUpdateSteps
{ {
protected \ilDBInterface $db; protected ilDBInterface $db;
public function prepare(ilDBInterface $db) : void public function prepare(ilDBInterface $db) : void
{ {
$this->db = $db; $this->db = $db;
} }
public function step_1() : void public function step_1() : void
{ {
include_once('./Services/Migration/DBUpdate_3560/classes/class.ilDBUpdateNewObjectType.php'); // Creation of administration node forced by \ilTreeAdminNodeAddedObjective
ilDBUpdateNewObjectType::addAdminNode('nota', 'Notification Service Administration Object');
} }
public function step_2() : void public function step_2() : void
......
...@@ -10,10 +10,8 @@ class ilContentStyleWAC implements ilWACCheckingClass ...@@ -10,10 +10,8 @@ class ilContentStyleWAC implements ilWACCheckingClass
/** /**
* @param ilWACPath $ilWACPath * @param ilWACPath $ilWACPath
*
* @return bool
*/ */
public function canBeDelivered(ilWACPath $ilWACPath) public function canBeDelivered(ilWACPath $ilWACPath) : bool
{ {
//preg_match("/.\\/data\\/.*\\/mm_([0-9]*)\\/.*/ui", $ilWACPath->getPath(), $matches); //preg_match("/.\\/data\\/.*\\/mm_([0-9]*)\\/.*/ui", $ilWACPath->getPath(), $matches);
return true; return true;
......
...@@ -20,17 +20,17 @@ ...@@ -20,17 +20,17 @@
*/ */
class ilWACException extends ilException class ilWACException extends ilException
{ {
const CODE_NO_TYPE = 9001; public const CODE_NO_TYPE = 9001;
const CODE_NO_PATH = 9002; public const CODE_NO_PATH = 9002;
const ACCESS_WITHOUT_CHECK = 9003; public const ACCESS_WITHOUT_CHECK = 9003;
const NO_CHECKING_INSTANCE = 9004; public const NO_CHECKING_INSTANCE = 9004;
const WRONG_PATH_TYPE = 9005; public const WRONG_PATH_TYPE = 9005;
const INITIALISATION_FAILED = 9006; public const INITIALISATION_FAILED = 9006;
const DATA_DIR_NON_WRITEABLE = 9007; public const DATA_DIR_NON_WRITEABLE = 9007;
const ACCESS_DENIED = 9010; public const ACCESS_DENIED = 9010;
const ACCESS_DENIED_NO_PUB = 9011; public const ACCESS_DENIED_NO_PUB = 9011;
const ACCESS_DENIED_NO_LOGIN = 9012; public const ACCESS_DENIED_NO_LOGIN = 9012;
const MAX_LIFETIME = 9013; public const MAX_LIFETIME = 9013;
/** /**
* @var array * @var array
*/ */
...@@ -57,7 +57,7 @@ class ilWACException extends ilException ...@@ -57,7 +57,7 @@ class ilWACException extends ilException
$message = self::$messages[$code]; $message = self::$messages[$code];
if ($this->isNonEmptyString($additional_message)) { if ($this->isNonEmptyString($additional_message)) {
$message = "\"{$this->message}\" with additional message: \"$additional_message\""; $message = "\"$this->message\" with additional message: \"$additional_message\"";
} }
//ilWACLog::getInstance()->write('Exception in ' . $this->getFile() . ':' . $this->getLine() . ': ' . $message); //ilWACLog::getInstance()->write('Exception in ' . $this->getFile() . ':' . $this->getLine() . ': ' . $message);
......
<?php
// declare(strict_types=1);
namespace ILIAS\WebAccessChecker;
use ILIAS\HTTP\Services;
/******************************************************************************
*
* This file is part of ILIAS, a powerful learning management system.
*
* ILIAS is licensed with the GPL-3.0, you should have received a copy
* of said license along with the source code.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*****************************************************************************/
/**
* Trait HttpServiceAware
*
* This trait provide a convenient way to consume the global http state
* and aids to reduce code duplication.
*
* Please only use this trait if you need the global http state from a
* static context! Otherwise consider to pass the http global state via constructor (DI).
*
* @author Nicolas Schäfli <ns@studer-raimann.ch>
* @version 1.0
* @since 5.3
*
* @Internal
*/
trait HttpServiceAware
{
private static $http;
/**
* Fetches the global http state from ILIAS.
*
* The GlobalHttpStore is stored after the first
* invocation.
*
* @return Services The current http global state of ILIAS.
* @since 5.3
*/
protected static function http()
{
if (self::$http === null) {
self::$http = $GLOBALS['DIC']['http'];
}
return self::$http;
}
}
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
*/ */
class ilWACPath class ilWACPath
{ {
const DIR_DATA = "data"; public const DIR_DATA = "data";
const DIR_SEC = "sec"; public const DIR_SEC = "sec";
/** /**
* Copy this without to regex101.com and test with some URL of files * Copy this without to regex101.com and test with some URL of files
*/ */
const REGEX = "(?<prefix>.*?)(?<path>(?<path_without_query>(?<secure_path_id>(?<module_path>\/data\/(?<client>[\w\-\.]*)\/(?<sec>sec\/|)(?<module_type>.*?)\/(?<module_identifier>.*\/|)))(?<appendix>[^\?\n]*)).*)"; public const REGEX = "(?<prefix>.*?)(?<path>(?<path_without_query>(?<secure_path_id>(?<module_path>\/data\/(?<client>[\w\-\.]*)\/(?<sec>sec\/|)(?<module_type>.*?)\/(?<module_identifier>.*\/|)))(?<appendix>[^\?\n]*)).*)";
/** /**
* @var string[] * @var string[]
*/ */
...@@ -117,7 +117,7 @@ class ilWACPath ...@@ -117,7 +117,7 @@ class ilWACPath
$module_path = ('.' . (!isset($result['module_path']) || is_null($result['module_path']) ? '' : $result['module_path'])); $module_path = ('.' . (!isset($result['module_path']) || is_null($result['module_path']) ? '' : $result['module_path']));
} }
$this->setModulePath("$module_path"); $this->setModulePath($module_path);
$this->setInSecFolder(isset($result['sec']) && $result['sec'] === 'sec/'); $this->setInSecFolder(isset($result['sec']) && $result['sec'] === 'sec/');
$this->setPathWithoutQuery( $this->setPathWithoutQuery(
'.' . (!isset($result['path_without_query']) || is_null($result['path_without_query']) ? '' : $result['path_without_query']) '.' . (!isset($result['path_without_query']) || is_null($result['path_without_query']) ? '' : $result['path_without_query'])
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
use ILIAS\HTTP\Cookies\CookieFactory; use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Cookies\CookieFactoryImpl; use ILIAS\HTTP\Cookies\CookieFactoryImpl;
use ILIAS\HTTP\Services; use ILIAS\HTTP\Services;
use ILIAS\WebAccessChecker\HttpServiceAware;
use ILIAS\WebAccessChecker\PathType; use ILIAS\WebAccessChecker\PathType;
use ILIAS\HTTP\GlobalHttpState; use ILIAS\HTTP\GlobalHttpState;
...@@ -29,14 +28,12 @@ use ILIAS\HTTP\GlobalHttpState; ...@@ -29,14 +28,12 @@ use ILIAS\HTTP\GlobalHttpState;
*/ */
class ilWACSignedPath class ilWACSignedPath
{ {
use HttpServiceAware; public const WAC_TOKEN_ID = 'il_wac_token';
public const WAC_TIMESTAMP_ID = 'il_wac_ts';
const WAC_TOKEN_ID = 'il_wac_token'; public const WAC_TTL_ID = 'il_wac_ttl';
const WAC_TIMESTAMP_ID = 'il_wac_ts'; public const TS_SUFFIX = 'ts';
const WAC_TTL_ID = 'il_wac_ttl'; public const TTL_SUFFIX = 'ttl';
const TS_SUFFIX = 'ts'; public const MAX_LIFETIME = 600;
const TTL_SUFFIX = 'ttl';
const MAX_LIFETIME = 600;
protected ?ilWACPath $path_object = null; protected ?ilWACPath $path_object = null;
protected ?ilWACToken $token_instance = null; protected ?ilWACToken $token_instance = null;
...@@ -80,7 +77,7 @@ class ilWACSignedPath ...@@ -80,7 +77,7 @@ class ilWACSignedPath
. $this->getTokenInstance()->getToken(); . $this->getTokenInstance()->getToken();
} }
$path = $path . '&' . self::WAC_TTL_ID . '=' . $this->getTokenInstance()->getTTL(); $path .= '&' . self::WAC_TTL_ID . '=' . $this->getTokenInstance()->getTTL();
return $path . '&' . self::WAC_TIMESTAMP_ID . '=' return $path . '&' . self::WAC_TIMESTAMP_ID . '='
. $this->getTokenInstance()->getTimestamp(); . $this->getTokenInstance()->getTimestamp();
...@@ -214,6 +211,7 @@ class ilWACSignedPath ...@@ -214,6 +211,7 @@ class ilWACSignedPath
*/ */
public static function signFile(string $path_to_file) : string public static function signFile(string $path_to_file) : string
{ {
global $DIC;
if ($path_to_file === '' || $path_to_file === '0') { if ($path_to_file === '' || $path_to_file === '0') {
return ''; return '';
} }
...@@ -221,7 +219,7 @@ class ilWACSignedPath ...@@ -221,7 +219,7 @@ class ilWACSignedPath
if ($ilWACPath->getClient() === '' || $ilWACPath->getClient() === '0') { if ($ilWACPath->getClient() === '' || $ilWACPath->getClient() === '0') {
return $path_to_file; return $path_to_file;
} }
$obj = new self($ilWACPath, self::http(), new CookieFactoryImpl()); $obj = new self($ilWACPath, $DIC->http(), new CookieFactoryImpl());
$obj->setType(PathType::FILE); $obj->setType(PathType::FILE);
$obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds()); $obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());
...@@ -230,7 +228,8 @@ class ilWACSignedPath ...@@ -230,7 +228,8 @@ class ilWACSignedPath
public static function signFolderOfStartFile(string $start_file_path) : void public static function signFolderOfStartFile(string $start_file_path) : void
{ {
$obj = new self(new ilWACPath($start_file_path), self::http(), new CookieFactoryImpl()); global $DIC;
$obj = new self(new ilWACPath($start_file_path), $DIC->http(), new CookieFactoryImpl());
$obj->setType(PathType::FOLDER); $obj->setType(PathType::FOLDER);
$obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds()); $obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
$obj->saveFolderToken(); $obj->saveFolderToken();
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
class ilWACToken class ilWACToken
{ {
const SALT_FILE_PATH = './data/wacsalt.php'; private const SALT_FILE_PATH = './data/wacsalt.php';
protected static string $SALT = ''; protected static string $SALT = '';
protected string $session_id = ''; protected string $session_id = '';
protected int $timestamp = 0; protected int $timestamp = 0;
...@@ -45,7 +45,7 @@ class ilWACToken ...@@ -45,7 +45,7 @@ class ilWACToken
$this->setClient($client); $this->setClient($client);
$this->setPath($path); $this->setPath($path);
$session_id = session_id(); $session_id = session_id();
$this->setSessionId($session_id ? $session_id : '-'); $this->setSessionId($session_id ?: '-');
if (isset($_SERVER['REMOTE_ADDR'])) { if (isset($_SERVER['REMOTE_ADDR'])) {
$this->setIp($_SERVER['REMOTE_ADDR']); $this->setIp($_SERVER['REMOTE_ADDR']);
} }
......
...@@ -27,13 +27,13 @@ use Psr\Http\Message\UriInterface; ...@@ -27,13 +27,13 @@ use Psr\Http\Message\UriInterface;
*/ */
class ilWebAccessChecker class ilWebAccessChecker
{ {
const DISPOSITION = 'disposition'; public const DISPOSITION = 'disposition';
const STATUS_CODE = 'status_code'; public const STATUS_CODE = 'status_code';
const REVALIDATE = 'revalidate'; public const REVALIDATE = 'revalidate';
const CM_FILE_TOKEN = 1; public const CM_FILE_TOKEN = 1;
const CM_FOLDER_TOKEN = 2; public const CM_FOLDER_TOKEN = 2;
const CM_CHECKINGINSTANCE = 3; public const CM_CHECKINGINSTANCE = 3;
const CM_SECFOLDER = 4; public const CM_SECFOLDER = 4;
protected ?ilWACPath $path_object = null; protected ?ilWACPath $path_object = null;
protected bool $checked = false; protected bool $checked = false;
...@@ -108,28 +108,15 @@ class ilWebAccessChecker ...@@ -108,28 +108,15 @@ class ilWebAccessChecker
if ($ilWACSignedPath->isFolderSigned() && $this->isRevalidateFolderTokens()) { if ($ilWACSignedPath->isFolderSigned() && $this->isRevalidateFolderTokens()) {
$ilWACSignedPath->revalidatingFolderToken(); $ilWACSignedPath->revalidatingFolderToken();
} }
$this->setChecked(true);
return true;
} else {
$this->setChecked(true);
return false;
} }
$this->setChecked(true);
return $canBeDelivered;
} }
// none of the checking mechanisms could have been applied. no access // none of the checking mechanisms could have been applied. no access
$this->setChecked(true); $this->setChecked(true);
if ($this->getPathObject()->isInSecFolder()) { $this->addAppliedCheckingMethod(self::CM_SECFOLDER);
$this->addAppliedCheckingMethod(self::CM_SECFOLDER); return !$this->getPathObject()->isInSecFolder();
return false;
} else {
$this->addAppliedCheckingMethod(self::CM_SECFOLDER);
return true;
}
} }
protected function sendHeader(string $message) : void protected function sendHeader(string $message) : void
...@@ -166,7 +153,7 @@ class ilWebAccessChecker ...@@ -166,7 +153,7 @@ class ilWebAccessChecker
&& $e->getCode() !== ilWACException::ACCESS_DENIED_NO_LOGIN) { && $e->getCode() !== ilWACException::ACCESS_DENIED_NO_LOGIN) {
throw $e; throw $e;
} }
if (($e instanceof Exception && $e->getMessage() == 'Authentication failed.') if (($e instanceof Exception && $e->getMessage() === 'Authentication failed.')
|| $e->getCode() === ilWACException::ACCESS_DENIED_NO_LOGIN) { || $e->getCode() === ilWACException::ACCESS_DENIED_NO_LOGIN) {
$this->initAnonymousSession(); $this->initAnonymousSession();
$this->checkUser(); $this->checkUser();
...@@ -183,7 +170,7 @@ class ilWebAccessChecker ...@@ -183,7 +170,7 @@ class ilWebAccessChecker
{ {
global $DIC; global $DIC;
$on_login_page = !$this->isRequestNotFromLoginPage(); $on_login_page = !$this->isRequestNotFromLoginPage();
$is_anonymous = ((int) $DIC->user()->getId() === (int) ANONYMOUS_USER_ID); $is_anonymous = ($DIC->user()->getId() === ANONYMOUS_USER_ID);
$is_null_user = ($DIC->user()->getId() === 0); $is_null_user = ($DIC->user()->getId() === 0);
$pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section'); $pub_section_activated = (bool) $DIC['ilSetting']->get('pub_section');
$isset = isset($DIC['ilSetting']); $isset = isset($DIC['ilSetting']);
...@@ -213,7 +200,7 @@ class ilWebAccessChecker ...@@ -213,7 +200,7 @@ class ilWebAccessChecker
global $DIC; global $DIC;
$is_user = $DIC->user() instanceof ilObjUser; $is_user = $DIC->user() instanceof ilObjUser;
$user_id_is_zero = ((int) $DIC->user()->getId() === 0); $user_id_is_zero = ($DIC->user()->getId() === 0);
$not_on_login_page = $this->isRequestNotFromLoginPage(); $not_on_login_page = $this->isRequestNotFromLoginPage();
if (!$is_user || ($user_id_is_zero && $not_on_login_page)) { if (!$is_user || ($user_id_is_zero && $not_on_login_page)) {
throw new ilWACException(ilWACException::ACCESS_DENIED_NO_LOGIN); throw new ilWACException(ilWACException::ACCESS_DENIED_NO_LOGIN);
...@@ -333,15 +320,14 @@ class ilWebAccessChecker ...@@ -333,15 +320,14 @@ class ilWebAccessChecker
$ilAuthSession = $DIC['ilAuthSession']; $ilAuthSession = $DIC['ilAuthSession'];
$ilAuthSession->init(); $ilAuthSession->init();
$ilAuthSession->regenerateId(); $ilAuthSession->regenerateId();
$a_id = (int) ANONYMOUS_USER_ID; $ilAuthSession->setUserId(ANONYMOUS_USER_ID);
$ilAuthSession->setUserId($a_id); $ilAuthSession->setAuthenticated(false, ANONYMOUS_USER_ID);
$ilAuthSession->setAuthenticated(false, $a_id); $DIC->user()->setId(ANONYMOUS_USER_ID);
$DIC->user()->setId($a_id);
} }
protected function isRequestNotFromLoginPage() : bool protected function isRequestNotFromLoginPage() : bool
{ {
$referrer = (string) ($_SERVER['HTTP_REFERER'] ?? ''); $referrer = $_SERVER['HTTP_REFERER'] ?? '';
$not_on_login_page = (strpos($referrer, 'login.php') === false $not_on_login_page = (strpos($referrer, 'login.php') === false
&& strpos($referrer, '&baseClass=ilStartUpGUI') === false); && strpos($referrer, '&baseClass=ilStartUpGUI') === false);
......
...@@ -25,6 +25,6 @@ namespace ILIAS\WebAccessChecker; ...@@ -25,6 +25,6 @@ namespace ILIAS\WebAccessChecker;
*/ */
interface PathType interface PathType
{ {
const FILE = 1; public const FILE = 1;
const FOLDER = 2; public const FOLDER = 2;
} }
...@@ -20,9 +20,5 @@ ...@@ -20,9 +20,5 @@
*/ */
interface ilWACCheckingClass interface ilWACCheckingClass
{ {
public function canBeDelivered(ilWACPath $ilWACPath) : bool;
/**
* @return bool
*/
public function canBeDelivered(ilWACPath $ilWACPath);
} }
...@@ -14,15 +14,15 @@ require_once('./libs/composer/vendor/autoload.php'); ...@@ -14,15 +14,15 @@ require_once('./libs/composer/vendor/autoload.php');
$container = new \ILIAS\DI\Container(); $container = new \ILIAS\DI\Container();
//manually init http service //manually init http service
$container['http.request_factory'] = fn ($c) => new \ILIAS\HTTP\Request\RequestFactoryImpl(); $container['http.request_factory'] = static fn ($c) => new \ILIAS\HTTP\Request\RequestFactoryImpl();
$container['http.response_factory'] = fn ($c) => new \ILIAS\HTTP\Response\ResponseFactoryImpl(); $container['http.response_factory'] = static fn ($c) => new \ILIAS\HTTP\Response\ResponseFactoryImpl();
$container['http.cookie_jar_factory'] = fn ($c) => new \ILIAS\HTTP\Cookies\CookieJarFactoryImpl(); $container['http.cookie_jar_factory'] = static fn ($c) => new \ILIAS\HTTP\Cookies\CookieJarFactoryImpl();
$container['http.response_sender_strategy'] = fn ($c) => new \ILIAS\HTTP\Response\Sender\DefaultResponseSenderStrategy(); $container['http.response_sender_strategy'] = static fn ($c) => new \ILIAS\HTTP\Response\Sender\DefaultResponseSenderStrategy();
$container['http'] = fn ($c) => new \ILIAS\HTTP\Services($c); $container['http'] = static fn ($c) => new \ILIAS\HTTP\Services($c);
$GLOBALS["DIC"] = $container; $GLOBALS["DIC"] = $container;
......