Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <[email protected]>
  • Loading branch information
docjyJ committed Sep 25, 2024
1 parent 1e4f32f commit f7dfdf3
Show file tree
Hide file tree
Showing 9 changed files with 844 additions and 968 deletions.
14 changes: 7 additions & 7 deletions php/src/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

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

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

public function __construct(
private ConfigurationManager $configurationManager
) {
}

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

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

public function SetAuthState(bool $isLoggedIn): void {
Expand Down
4 changes: 2 additions & 2 deletions php/src/Auth/PasswordGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Random\RandomException;

readonly class PasswordGenerator {
class PasswordGenerator {

private const array WORDS = [
'abacus',
Expand Down Expand Up @@ -7787,7 +7787,7 @@


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

for ($i = 0; $i < $length; $i++) {
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
52 changes: 25 additions & 27 deletions php/src/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,70 @@
use Psr\Http\Message\ServerRequestInterface as Request;

readonly class ConfigurationController {

public function __construct(
private ConfigurationManager $configurationManager
) {
}

public function SetConfig(Request $request, Response $response, array $args): Response {
try {
$body = $request->getParsedBody();
if (is_array($body)) {
$config = ConfigurationManager::loadConfigFile();

if (is_string($body['domain']))
$this->configurationManager->SetDomain($body['domain']);
$config->setDomain($body['domain']);

$currentMasterPassword = is_string($body['current-master-password']) ? $body['current-master-password'] : null;
$newMasterPassword = is_string($body['new-master-password']) ? $body['new-master-password'] : null;
if ($currentMasterPassword !== null || $newMasterPassword !== null)
$this->configurationManager->ChangeMasterPassword($currentMasterPassword ?? '', $newMasterPassword ?? '');
$config->changeMasterPassword($currentMasterPassword ?? '', $newMasterPassword ?? '');

if (is_string($body['borg_backup_host_location']))
$this->configurationManager->SetBorgBackupHostLocation($body['borg_backup_host_location']);
$config->setBorgLocation($body['borg_backup_host_location']);

$borgRestoreHostLocation = is_string($body['borg_restore_host_location']) ? $body['borg_restore_host_location'] : null;
$borgRestorePassword = is_string($body['borg_restore_password']) ? $body['borg_restore_password'] : null;
if ($borgRestoreHostLocation !== null || $borgRestorePassword !== null)
$this->configurationManager->SetBorgRestoreHostLocationAndPassword($borgRestoreHostLocation ?? '', $borgRestorePassword ?? '');
$config->setBorgRestoreLocationAndPassword($borgRestoreHostLocation ?? '', $borgRestorePassword ?? '');

if (is_string($body['daily_backup_time']))
$this->configurationManager->SetDailyBackupTime(
ConfigurationManager::SetDailyBackupTime(
$body['daily_backup_time'],
isset($body['automatic_updates']),
isset($body['success_notification']));

if (isset($body['delete_daily_backup_time']))
$this->configurationManager->DeleteDailyBackupTime();
$config->deleteTimezone();

if (is_string($body['additional_backup_directories']))
$this->configurationManager->SetAdditionalBackupDirectories($body['additional_backup_directories']);
ConfigurationManager::SetAdditionalBackupDirectories($body['additional_backup_directories']);

if (isset($body['delete_timezone']))
$this->configurationManager->DeleteTimezone();
$config->DeleteTimezone();

if (is_string($body['timezone']))
$this->configurationManager->SetTimezone($body['timezone']);
$config->SetTimezone($body['timezone']);

if (isset($body['options-form'])) {
if (isset($body['collabora']) && isset($body['onlyoffice']))
throw new InvalidSettingConfigurationException("Collabora and Onlyoffice are not allowed to be enabled at the same time!");
$this->configurationManager->SetClamavEnabledState(isset($body['clamav']) ? 1 : 0);
$this->configurationManager->SetOnlyofficeEnabledState(isset($body['onlyoffice']) ? 1 : 0);
$this->configurationManager->SetCollaboraEnabledState(isset($body['collabora']) ? 1 : 0);
$this->configurationManager->SetTalkEnabledState(isset($body['talk']) ? 1 : 0);
$this->configurationManager->SetTalkRecordingEnabledState(isset($body['talk-recording']) ? 1 : 0);
$this->configurationManager->SetImaginaryEnabledState(isset($body['imaginary']) ? 1 : 0);
$this->configurationManager->SetFulltextsearchEnabledState(isset($body['fulltextsearch']) ? 1 : 0);
$this->configurationManager->SetDockerSocketProxyEnabledState(isset($body['docker-socket-proxy']) ? 1 : 0);
$this->configurationManager->SetWhiteboardEnabledState(isset($body['whiteboard']) ? 1 : 0);
$config->enableClamav(isset($body['clamav']));
$config->enableOnlyoffice(isset($body['onlyoffice']));
$config->enableCollabora(isset($body['collabora']));
$config->talkEnabled = isset($body['talk']);
$config->enableTalkRecording(isset($body['talk-recording']));
$config->imaginaryEnabled = isset($body['imaginary']);
$config->fulltextsearchEnabled = isset($body['fulltextsearch']);
$config->dockerSocketProxyEnabled = isset($body['docker-socket-proxy']);
$config->whiteboardEnabled = isset($body['whiteboard']);
}

if (isset($body['delete_collabora_dictionaries']))
$this->configurationManager->DeleteCollaboraDictionaries();
$config->DeleteCollaboraDictionaries();

if (is_string($body['collabora_dictionaries']))
$this->configurationManager->SetCollaboraDictionaries($body['collabora_dictionaries']);
$config->SetCollaboraDictionaries($body['collabora_dictionaries']);

if (isset($body['delete_borg_backup_host_location']))
$this->configurationManager->DeleteBorgBackupHostLocation();
$config->deleteBorgLocation();

ConfigurationManager::storeConfigFile($config);
}

return $response->withStatus(201)->withHeader('Location', '/');
Expand Down
Loading

0 comments on commit f7dfdf3

Please sign in to comment.