mirror of
https://github.com/nextcloud/server.git
synced 2025-02-12 03:59:16 +00:00
![dependabot[bot]](/assets/img/avatar_default.png)
Bumps [nextcloud/coding-standard](https://github.com/nextcloud/coding-standard) from 1.3.1 to 1.3.2. - [Release notes](https://github.com/nextcloud/coding-standard/releases) - [Changelog](https://github.com/nextcloud/coding-standard/blob/master/CHANGELOG.md) - [Commits](https://github.com/nextcloud/coding-standard/compare/v1.3.1...v1.3.2) --- updated-dependencies: - dependency-name: nextcloud/coding-standard dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: provokateurin <kate@provokateurin.de>
71 lines
1.5 KiB
PHP
71 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace OC\Security\Ip;
|
|
|
|
use OCP\IConfig;
|
|
use OCP\IRequest;
|
|
use OCP\Security\Ip\IAddress;
|
|
use OCP\Security\Ip\IRange;
|
|
use OCP\Security\Ip\IRemoteAddress;
|
|
|
|
class RemoteAddress implements IRemoteAddress, IAddress {
|
|
public const SETTING_NAME = 'allowed_admin_ranges';
|
|
|
|
private readonly ?IAddress $ip;
|
|
|
|
public function __construct(
|
|
private IConfig $config,
|
|
IRequest $request,
|
|
) {
|
|
$remoteAddress = $request->getRemoteAddress();
|
|
$this->ip = $remoteAddress === ''
|
|
? null
|
|
: new Address($remoteAddress);
|
|
}
|
|
|
|
public static function isValid(string $ip): bool {
|
|
return Address::isValid($ip);
|
|
}
|
|
|
|
public function matches(IRange ... $ranges): bool {
|
|
return $this->ip === null
|
|
? true
|
|
: $this->ip->matches(... $ranges);
|
|
}
|
|
|
|
public function allowsAdminActions(): bool {
|
|
if ($this->ip === null) {
|
|
return true;
|
|
}
|
|
|
|
$allowedAdminRanges = $this->config->getSystemValue(self::SETTING_NAME, false);
|
|
|
|
// Don't apply restrictions on empty or invalid configuration
|
|
if (
|
|
$allowedAdminRanges === false
|
|
|| !is_array($allowedAdminRanges)
|
|
|| empty($allowedAdminRanges)
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
foreach ($allowedAdminRanges as $allowedAdminRange) {
|
|
if ((new Range($allowedAdminRange))->contains($this->ip)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function __toString(): string {
|
|
return (string)$this->ip;
|
|
}
|
|
}
|