aio-interface: allow to manage the community containers via the AIO interface (#6443)

Signed-off-by: Simon L. <szaimen@e.mail.de>
Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
This commit is contained in:
Simon L. 2025-05-30 09:32:51 +02:00 committed by GitHub
parent 17ec503bf3
commit 673b1db07e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 220 additions and 205 deletions

View file

@ -3,6 +3,7 @@
namespace AIO\Data;
use AIO\Auth\PasswordGenerator;
use AIO\Container\CommunityContainer;
use AIO\Controller\DockerController;
class ConfigurationManager
@ -75,7 +76,7 @@ class ConfigurationManager
if (!file_exists(DataConst::GetBackupArchivesList())) {
return '';
}
$content = file_get_contents(DataConst::GetBackupArchivesList());
if ($content === '') {
return '';
@ -95,7 +96,7 @@ class ConfigurationManager
if ($lastBackupTime === "") {
return '';
}
return $lastBackupTime;
}
@ -103,7 +104,7 @@ class ConfigurationManager
if (!file_exists(DataConst::GetBackupArchivesList())) {
return [];
}
$content = file_get_contents(DataConst::GetBackupArchivesList());
if ($content === '') {
return [];
@ -114,7 +115,7 @@ class ConfigurationManager
foreach($backupLines as $lines) {
if ($lines !== "") {
$backupTimesTemp = explode(',', $lines);
$backupTimes[] = $backupTimesTemp[1];
$backupTimes[] = $backupTimesTemp[1];
}
}
@ -140,7 +141,7 @@ class ConfigurationManager
}
}
public function isClamavEnabled() : bool {
public function isClamavEnabled() : bool {
$config = $this->GetConfig();
if (isset($config['isClamavEnabled']) && $config['isClamavEnabled'] === 1) {
return true;
@ -375,7 +376,7 @@ class ConfigurationManager
$testUrl = $protocol . $domain . ':443';
curl_setopt($ch, CURLOPT_URL, $testUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = (string)curl_exec($ch);
# Get rid of trailing \n
@ -474,7 +475,7 @@ class ConfigurationManager
} elseif ($location !== '' && $repo !== '') {
throw new InvalidSettingConfigurationException("Location and remote repo url are mutually exclusive!");
}
if ($location !== '') {
$isValidPath = false;
if (str_starts_with($location, '/') && !str_ends_with($location, '/')) {
@ -629,7 +630,7 @@ class ConfigurationManager
if (!file_exists(DataConst::GetBackupPublicKey())) {
return "";
}
return trim(file_get_contents(DataConst::GetBackupPublicKey()));
}
@ -771,7 +772,7 @@ class ConfigurationManager
if (!preg_match("#^[0-1][0-9]:[0-5][0-9]$#", $time) && !preg_match("#^2[0-3]:[0-5][0-9]$#", $time)) {
throw new InvalidSettingConfigurationException("You did not enter a correct time! One correct example is '04:00'!");
}
if ($enableAutomaticUpdates === false) {
$time .= PHP_EOL . 'automaticUpdatesAreNotEnabled';
} else {
@ -1008,16 +1009,59 @@ class ConfigurationManager
}
private function GetCommunityContainers() : string {
$envVariableName = 'AIO_COMMUNITY_CONTAINERS';
$configName = 'aio_community_containers';
$defaultValue = '';
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
$config = $this->GetConfig();
if(!isset($config['aio_community_containers'])) {
$config['aio_community_containers'] = '';
}
return $config['aio_community_containers'];
}
public function GetEnabledCommunityContainers() : array {
/** @return list<CommunityContainer> */
public function listAvailableCommunityContainers() : array {
$cc = [];
$dir = scandir(DataConst::GetCommunityContainersDirectory());
if ($dir === false) {
return $cc;
}
foreach ($dir as $id) {
$filePath = DataConst::GetCommunityContainersDirectory() . '/' . $id . '/' . $id . '.json';
$fileContents = apcu_fetch($filePath);
if (!is_string($fileContents)) {
$fileContents = file_get_contents($filePath);
if (is_string($fileContents)) {
apcu_add($filePath, $fileContents);
}
}
$json = is_string($fileContents) ? json_decode($fileContents) : false;
if(is_array($json) && is_array($json['aio_services_v1'])) {
foreach ($json['aio_services_v1'] as $service) {
$documentation = is_string($service['documentation']) ? $service['documentation'] : '';
if (is_string($service['display_name'])) {
$cc[] = new CommunityContainer(
$id,
$service['display_name'],
$documentation);
}
break;
}
}
}
return $cc;
}
/** @return list<string> */
public function GetEnabledCommunityContainers(): array {
return explode(' ', $this->GetCommunityContainers());
}
public function SetEnabledCommunityContainers(array $enabledCommunityContainers) : void {
$config = $this->GetConfig();
$config['aio_community_containers'] = implode(' ', $enabledCommunityContainers);
$this->WriteConfig($config);
}
private function GetEnabledDriDevice() : string {
$envVariableName = 'NEXTCLOUD_ENABLE_DRI_DEVICE';
$configName = 'nextcloud_enable_dri_device';