Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Configuration management #5328

Draft
wants to merge 7 commits into
base: enh/noid/optimize-psalm
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions php/psalm.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config"
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="templates"/>
<directory name="src"/>
<file name="public/index.php"/>
</projectFiles>
<projectFiles>
<directory name="templates"/>
<directory name="src"/>
<file name="public/index.php"/>
</projectFiles>
</psalm>
26 changes: 13 additions & 13 deletions php/src/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

use AIO\Data\ConfigurationManager;
use AIO\Data\DataConst;
use \DateTime;
use AIO\Data\InvalidSettingConfigurationException;
use DateTime;

class AuthManager {
readonly class AuthManager {
private const string SESSION_KEY = 'aio_authenticated';
private ConfigurationManager $configurationManager;

public function __construct(ConfigurationManager $configurationManager) {
$this->configurationManager = $configurationManager;
/** @throws InvalidSettingConfigurationException */
public function CheckCredentials(string $password): bool {
$config = ConfigurationManager::loadConfigFile();
return hash_equals($config->GetPassword(), $password);
}

public function CheckCredentials(string $password) : bool {
return hash_equals($this->configurationManager->GetPassword(), $password);
/** @throws InvalidSettingConfigurationException */
public function CheckToken(string $token): bool {
$config = ConfigurationManager::loadConfigFile();
return hash_equals($config->GetToken(), $token);
}

public function CheckToken(string $token) : bool {
return hash_equals($this->configurationManager->GetToken(), $token);
}

public function SetAuthState(bool $isLoggedIn) : void {
public function SetAuthState(bool $isLoggedIn): void {

if (!$this->IsAuthenticated() && $isLoggedIn === true) {
$date = new DateTime();
Expand All @@ -40,7 +40,7 @@ public function SetAuthState(bool $isLoggedIn) : void {
$_SESSION[self::SESSION_KEY] = $isLoggedIn;
}

public function IsAuthenticated() : bool {
public function IsAuthenticated(): bool {
return isset($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY] === true;
}
}
18 changes: 10 additions & 8 deletions php/src/Auth/PasswordGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace AIO\Auth;

use AIO\Data\ConfigurationManager;
use Random\RandomException;

class PasswordGenerator
{
private array $words = [
class PasswordGenerator {

private const array WORDS = [
'abacus',
'abdomen',
'abdominal',
Expand Down Expand Up @@ -7785,14 +7785,16 @@ class PasswordGenerator
'zoom',
];

public function GeneratePassword(int $length) : string {

/** @throws RandomException */
static function GeneratePassword(int $length): string {
$password = '';

for($i = 0; $i < $length; $i ++) {
if($password !== '') {
for ($i = 0; $i < $length; $i++) {
if ($password !== '') {
$password = $password . ' ';
}
$password = $password . $this->words[random_int(0, 7775)];
$password = $password . PasswordGenerator::WORDS[random_int(0, 7775)];
}

return $password;
Expand Down
58 changes: 28 additions & 30 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

class ContainerDefinitionFetcher
{
private ConfigurationManager $configurationManager;
private \DI\Container $container;

public function __construct(
ConfigurationManager $configurationManager,
\DI\Container $container
)
{
$this->configurationManager = $configurationManager;
$this->container = $container;
}

Expand All @@ -47,9 +44,10 @@ public function GetContainerById(string $id): Container
private function GetDefinition(): array
{
$data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true);
$config = ConfigurationManager::loadConfigFile();

$additionalContainerNames = [];
foreach ($this->configurationManager->GetEnabledCommunityContainers() as $communityContainer) {
foreach ($config->aioCommunityContainers as $communityContainer) {
if ($communityContainer !== '') {
$path = DataConst::GetCommunityContainersDirectory() . '/' . $communityContainer . '/' . $communityContainer . '.json';
$additionalData = json_decode(file_get_contents($path), true);
Expand All @@ -64,46 +62,46 @@ private function GetDefinition(): array
$containers = [];
foreach ($data['aio_services_v1'] as $entry) {
if ($entry['container_name'] === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) {
if (!$config->isClamavEnabled()) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-onlyoffice') {
if (!$this->configurationManager->isOnlyofficeEnabled()) {
if (!$config->isOnlyofficeEnabled()) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-collabora') {
if (!$this->configurationManager->isCollaboraEnabled()) {
if (!$config->isCollaboraEnabled()) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-talk') {
if (!$this->configurationManager->isTalkEnabled()) {
if (!$config->talkEnabled) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-talk-recording') {
if (!$this->configurationManager->isTalkRecordingEnabled()) {
if (!$config->isTalkRecordingEnabled()) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-imaginary') {
if (!$this->configurationManager->isImaginaryEnabled()) {
if (!$config->imaginaryEnabled) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-fulltextsearch') {
if (!$this->configurationManager->isFulltextsearchEnabled()) {
if (!$config->fulltextsearchEnabled) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-docker-socket-proxy') {
if (!$this->configurationManager->isDockerSocketProxyEnabled()) {
if (!$config->dockerSocketProxyEnabled) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-whiteboard') {
if (!$this->configurationManager->isWhiteboardEnabled()) {
if (!$config->whiteboardEnabled) {
continue;
}
}

$ports = new ContainerPorts();
if (isset($entry['ports'])) {
foreach ($entry['ports'] as $value) {
foreach ($entry['ports'] as $value) {
$ports->AddPort(
new ContainerPort(
$value['port_number'],
Expand All @@ -118,34 +116,34 @@ private function GetDefinition(): array
if (isset($entry['volumes'])) {
foreach ($entry['volumes'] as $value) {
if($value['source'] === '%BORGBACKUP_HOST_LOCATION%') {
$value['source'] = $this->configurationManager->GetBorgBackupHostLocation();
$value['source'] = $config->getBorgLocation();
if($value['source'] === '') {
continue;
}
}
if($value['source'] === '%NEXTCLOUD_MOUNT%') {
$value['source'] = $this->configurationManager->GetNextcloudMount();
$value['source'] = $config->nextcloudMount;
if($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%NEXTCLOUD_DATADIR%') {
$value['source'] = $this->configurationManager->GetNextcloudDatadirMount();
$value['source'] = $config->nextcloudDatadir;
if ($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%WATCHTOWER_DOCKER_SOCKET_PATH%') {
$value['source'] = $this->configurationManager->GetDockerSocketPath();
$value['source'] = $config->dockerSocketPath;
if($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%NEXTCLOUD_TRUSTED_CACERTS_DIR%') {
$value['source'] = $this->configurationManager->GetTrustedCacertsDir();
$value['source'] = $config->trustedCacertsDir;
if($value['source'] === '') {
continue;
}
}
if ($value['destination'] === '%NEXTCLOUD_MOUNT%') {
$value['destination'] = $this->configurationManager->GetNextcloudMount();
$value['destination'] = $config->nextcloudMount;
if($value['destination'] === '') {
continue;
}
Expand Down Expand Up @@ -173,46 +171,46 @@ private function GetDefinition(): array
}
foreach ($valueDependsOn as $value) {
if ($value === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) {
if (!$config->isClamavEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-onlyoffice') {
if (!$this->configurationManager->isOnlyofficeEnabled()) {
if (!$config->isOnlyofficeEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-collabora') {
if (!$this->configurationManager->isCollaboraEnabled()) {
if (!$config->isCollaboraEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-talk') {
if (!$this->configurationManager->isTalkEnabled()) {
if (!$config->talkEnabled) {
continue;
}
} elseif ($value === 'nextcloud-aio-talk-recording') {
if (!$this->configurationManager->isTalkRecordingEnabled()) {
if (!$config->isTalkRecordingEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-imaginary') {
if (!$this->configurationManager->isImaginaryEnabled()) {
if (!$config->imaginaryEnabled) {
continue;
}
} elseif ($value === 'nextcloud-aio-fulltextsearch') {
if (!$this->configurationManager->isFulltextsearchEnabled()) {
if (!$config->fulltextsearchEnabled) {
continue;
}
} elseif ($value === 'nextcloud-aio-docker-socket-proxy') {
if (!$this->configurationManager->isDockerSocketProxyEnabled()) {
if (!$config->dockerSocketProxyEnabled) {
continue;
}
} elseif ($value === 'nextcloud-aio-whiteboard') {
if (!$this->configurationManager->isWhiteboardEnabled()) {
if (!$config->whiteboardEnabled) {
continue;
}
}
$dependsOn[] = $value;
}
}

$variables = new ContainerEnvironmentVariables();
if (isset($entry['environment'])) {
foreach ($entry['environment'] as $value) {
Expand Down
Loading
Loading