Skip to content

Commit

Permalink
First test
Browse files Browse the repository at this point in the history
  • Loading branch information
docjyJ committed Sep 21, 2024
1 parent cd4c294 commit 12b9317
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 143 deletions.
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>
5 changes: 3 additions & 2 deletions php/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// Log whole log messages
ini_set('log_errors_max_len', '0');

use AIO\Controller\ConfigurationController;
use DI\Container;
use Slim\Csrf\Guard;
use Slim\Factory\AppFactory;
Expand Down Expand Up @@ -68,7 +69,7 @@
$app->post('/api/auth/login', AIO\Controller\LoginController::class . ':TryLogin');
$app->get('/api/auth/getlogin', AIO\Controller\LoginController::class . ':GetTryLogin');
$app->post('/api/auth/logout', AIO\Controller\LoginController::class . ':Logout');
$app->post('/api/configuration', \AIO\Controller\ConfigurationController::class . ':SetConfig');
$app->post('/api/configuration', ConfigurationController::class);

// Views
$app->get('/containers', function (Request $request, Response $response, array $args) use ($container) {
Expand Down Expand Up @@ -125,7 +126,7 @@
'is_dri_device_enabled' => $configurationManager->isDriDeviceEnabled(),
'is_talk_recording_enabled' => $configurationManager->isTalkRecordingEnabled(),
'is_docker_socket_proxy_enabled' => $configurationManager->isDockerSocketProxyEnabled(),
'is_whiteboard_enabled' => $configurationManager->isWhiteboardEnabled(),
'is_whiteboard_enabled' => $configurationManager->isWhiteboardEnabled(),
]);
})->setName('profile');
$app->get('/login', function (Request $request, Response $response, array $args) use ($container) {
Expand Down
2 changes: 1 addition & 1 deletion php/src/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

class AuthManager {
private const string SESSION_KEY = 'aio_authenticated';
Expand Down
14 changes: 8 additions & 6 deletions php/src/Auth/PasswordGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace AIO\Auth;

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

class PasswordGenerator
{
class PasswordGenerator {

/** @var string[] */
private array $words = [
'abacus',
'abdomen',
Expand Down Expand Up @@ -7785,11 +7786,12 @@ class PasswordGenerator
'zoom',
];

public function GeneratePassword(int $length) : string {
/** @throws RandomException */
public 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)];
Expand Down
184 changes: 62 additions & 122 deletions php/src/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,144 +2,84 @@

namespace AIO\Controller;

use AIO\ContainerDefinitionFetcher;
use AIO\Data\ConfigurationManager;
use AIO\Data\InvalidSettingConfigurationException;
use AIO\Docker\DockerActionManager;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class ConfigurationController
{
class ConfigurationController {
private ConfigurationManager $configurationManager;

public function __construct(
ConfigurationManager $configurationManager
) {
public function __construct(ConfigurationManager $configurationManager) {
$this->configurationManager = $configurationManager;
}

public function SetConfig(Request $request, Response $response, array $args) : Response {
try {
if (isset($request->getParsedBody()['domain'])) {
$domain = $request->getParsedBody()['domain'] ?? '';
$this->configurationManager->SetDomain($domain);
}

if (isset($request->getParsedBody()['current-master-password']) || isset($request->getParsedBody()['new-master-password'])) {
$currentMasterPassword = $request->getParsedBody()['current-master-password'] ?? '';
$newMasterPassword = $request->getParsedBody()['new-master-password'] ?? '';
$this->configurationManager->ChangeMasterPassword($currentMasterPassword, $newMasterPassword);
}

if (isset($request->getParsedBody()['borg_backup_host_location'])) {
$location = $request->getParsedBody()['borg_backup_host_location'] ?? '';
$this->configurationManager->SetBorgBackupHostLocation($location);
}

if (isset($request->getParsedBody()['borg_restore_host_location']) || isset($request->getParsedBody()['borg_restore_password'])) {
$restoreLocation = $request->getParsedBody()['borg_restore_host_location'] ?? '';
$borgPassword = $request->getParsedBody()['borg_restore_password'] ?? '';
$this->configurationManager->SetBorgRestoreHostLocationAndPassword($restoreLocation, $borgPassword);
}

if (isset($request->getParsedBody()['daily_backup_time'])) {
if (isset($request->getParsedBody()['automatic_updates'])) {
$enableAutomaticUpdates = true;
} else {
$enableAutomaticUpdates = false;
}
if (isset($request->getParsedBody()['success_notification'])) {
$successNotification = true;
} else {
$successNotification = false;
}
$dailyBackupTime = $request->getParsedBody()['daily_backup_time'] ?? '';
$this->configurationManager->SetDailyBackupTime($dailyBackupTime, $enableAutomaticUpdates, $successNotification);
}

if (isset($request->getParsedBody()['delete_daily_backup_time'])) {
$this->configurationManager->DeleteDailyBackupTime();
}

if (isset($request->getParsedBody()['additional_backup_directories'])) {
$additionalBackupDirectories = $request->getParsedBody()['additional_backup_directories'] ?? '';
$this->configurationManager->SetAdditionalBackupDirectories($additionalBackupDirectories);
}

if (isset($request->getParsedBody()['delete_timezone'])) {
$this->configurationManager->DeleteTimezone();
}

if (isset($request->getParsedBody()['timezone'])) {
$timezone = $request->getParsedBody()['timezone'] ?? '';
$this->configurationManager->SetTimezone($timezone);
}
public function __invoke(Request $request, Response $response, array $args): Response {
return $this->SetConfig($request, $response);
}

if (isset($request->getParsedBody()['options-form'])) {
if (isset($request->getParsedBody()['collabora']) && isset($request->getParsedBody()['onlyoffice'])) {
throw new InvalidSettingConfigurationException("Collabora and Onlyoffice are not allowed to be enabled at the same time!");
}
if (isset($request->getParsedBody()['clamav'])) {
$this->configurationManager->SetClamavEnabledState(1);
} else {
$this->configurationManager->SetClamavEnabledState(0);
}
if (isset($request->getParsedBody()['onlyoffice'])) {
$this->configurationManager->SetOnlyofficeEnabledState(1);
} else {
$this->configurationManager->SetOnlyofficeEnabledState(0);
}
if (isset($request->getParsedBody()['collabora'])) {
$this->configurationManager->SetCollaboraEnabledState(1);
} else {
$this->configurationManager->SetCollaboraEnabledState(0);
}
if (isset($request->getParsedBody()['talk'])) {
$this->configurationManager->SetTalkEnabledState(1);
} else {
$this->configurationManager->SetTalkEnabledState(0);
}
if (isset($request->getParsedBody()['talk-recording'])) {
$this->configurationManager->SetTalkRecordingEnabledState(1);
} else {
$this->configurationManager->SetTalkRecordingEnabledState(0);
}
if (isset($request->getParsedBody()['imaginary'])) {
$this->configurationManager->SetImaginaryEnabledState(1);
} else {
$this->configurationManager->SetImaginaryEnabledState(0);
}
if (isset($request->getParsedBody()['fulltextsearch'])) {
$this->configurationManager->SetFulltextsearchEnabledState(1);
} else {
$this->configurationManager->SetFulltextsearchEnabledState(0);
}
if (isset($request->getParsedBody()['docker-socket-proxy'])) {
$this->configurationManager->SetDockerSocketProxyEnabledState(1);
} else {
$this->configurationManager->SetDockerSocketProxyEnabledState(0);
}
if (isset($request->getParsedBody()['whiteboard'])) {
$this->configurationManager->SetWhiteboardEnabledState(1);
} else {
$this->configurationManager->SetWhiteboardEnabledState(0);
public function SetConfig(Request $request, Response $response): Response {
try {
$body = $request->getParsedBody();
if (is_array($body)) {
if (is_string($body['domain']))
$this->configurationManager->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 ?? '');

if (is_string($body['borg_backup_host_location']))
$this->configurationManager->SetBorgBackupHostLocation($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 ?? '');

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

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

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

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

if (is_string($body['timezone']))
$this->configurationManager->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);
}
}

if (isset($request->getParsedBody()['delete_collabora_dictionaries'])) {
$this->configurationManager->DeleteCollaboraDictionaries();
}
if (isset($body['delete_collabora_dictionaries']))
$this->configurationManager->DeleteCollaboraDictionaries();

if (isset($request->getParsedBody()['collabora_dictionaries'])) {
$collaboraDictionaries = $request->getParsedBody()['collabora_dictionaries'] ?? '';
$this->configurationManager->SetCollaboraDictionaries($collaboraDictionaries);
}
if (is_string($body['collabora_dictionaries']))
$this->configurationManager->SetCollaboraDictionaries($body['collabora_dictionaries']);

if (isset($request->getParsedBody()['delete_borg_backup_host_location'])) {
$this->configurationManager->DeleteBorgBackupHostLocation();
if (isset($body['delete_borg_backup_host_location']))
$this->configurationManager->DeleteBorgBackupHostLocation();
}

return $response->withStatus(201)->withHeader('Location', '/');
} catch (InvalidSettingConfigurationException $ex) {
$response->getBody()->write($ex->getMessage());
Expand Down

0 comments on commit 12b9317

Please sign in to comment.