FIX: squelch __unserialize, __serialize deprecation warnings (Preferences) FIX: cgroupv2 metrics attempt non-existent read of io.stat metadata on root (Cgroup) FIX: vhost ip registration location (apache/configure) CHG: move apache,jail to php,enabled. Jail feature is now all-or-nothing dependent upon PHP-FPM presence. CHG: /etc/php.ini editable within VFS. Edit produces a copy-up behavior (Opcenter\Provisioning) CHG: resolve recursive usage of symbolic messages (Error Reporter) CHG: clarify cp-api lookup errors (Auth) CHG: update apache,jail => php,enabled references (modules) CHG: add s-nail, python3 package names on EL9/EL10 (packages/install) CHG: update valkey-compat-redis location on Rocky 10 (packages/install)
194 lines
5.1 KiB
PHP
194 lines
5.1 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
* Copyright (C) Apis Networks, Inc - All Rights Reserved.
|
|
*
|
|
* Unauthorized copying of this file, via any medium, is
|
|
* strictly prohibited without consent. Any dissemination of
|
|
* material herein is prohibited.
|
|
*
|
|
* For licensing inquiries email <licensing@apisnetworks.com>
|
|
*
|
|
* Written by Matt Saladna <matt@apisnetworks.com>, June 2019
|
|
*/
|
|
|
|
use Opcenter\Service\ServiceValidator;
|
|
use Opcenter\SiteConfiguration;
|
|
|
|
/**
|
|
* Grant access to info/ helpers
|
|
*/
|
|
trait AccountInfoTrait {
|
|
use ContextableTrait;
|
|
|
|
private static array $serviceVariableRemaps = [];
|
|
|
|
|
|
/**
|
|
* Get all service configuration
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getServices(): array
|
|
{
|
|
return $this->getAuthContext()->getAccount()->conf;
|
|
}
|
|
|
|
/**
|
|
* Get unsynchronized configuration
|
|
*
|
|
* @param string $service
|
|
* @return array|null
|
|
*/
|
|
protected function getNewServices(string $service = null): ?array
|
|
{
|
|
$s = $this->getAuthContext()->getAccount()->new;
|
|
if ($service) {
|
|
return $s[$service] ?? null;
|
|
}
|
|
|
|
return $s;
|
|
}
|
|
|
|
/**
|
|
* Get previous configuration
|
|
*
|
|
* @param string $service
|
|
* @return array|null
|
|
*/
|
|
protected function getOldServices(string $service = null): ?array
|
|
{
|
|
$s = $this->getAuthContext()->getAccount()->old;
|
|
if ($service) {
|
|
return $s[$service] ?? null;
|
|
}
|
|
|
|
return $s;
|
|
}
|
|
|
|
/**
|
|
* Get current service configuration
|
|
*
|
|
* @param string|null $svc
|
|
* @return array|null
|
|
*/
|
|
protected function getActiveServices(string $svc = null): ?array
|
|
{
|
|
$s = $this->getAuthContext()->getAccount()->cur;
|
|
if ($svc) {
|
|
return $s[$svc] ?? null;
|
|
}
|
|
|
|
return $s;
|
|
}
|
|
|
|
/**
|
|
* Get service configuration
|
|
*
|
|
* Alias to getServiceValue($service, $parameter)
|
|
*
|
|
* @param string $service
|
|
* @param string|null $parameter
|
|
* @return mixed
|
|
*/
|
|
protected function getConfig(string $service, string $parameter = null)
|
|
{
|
|
return $this->getServiceValue($service, $parameter);
|
|
}
|
|
|
|
/**
|
|
* mixed get_service_value(string, string)
|
|
* Get site configuration value from <FST>/info/current
|
|
*
|
|
* @param string $service service type to look up data
|
|
* @param string $parameter|null name of the service type subset to return data
|
|
* @param mixed $default default value
|
|
* @return mixed
|
|
*/
|
|
protected function getServiceValue(string $service, string $parameter = null, $default = null)
|
|
{
|
|
if ($this->getAuthContext()->level & PRIVILEGE_ADMIN) {
|
|
return $default;
|
|
}
|
|
|
|
$metadata = $this->getAuthContext()->getAccount();
|
|
// service renamed, e.g. apache,webuser => php,user
|
|
if (array_key_exists($key = "{$service}.{$parameter}", self::$serviceVariableRemaps)) {
|
|
if (null === self::$serviceVariableRemaps[$key]) {
|
|
return $default;
|
|
}
|
|
|
|
$parts = explode('.', self::$serviceVariableRemaps[$key], 2);
|
|
deprecated(SiteConfiguration::MSG_SERVICE_PARAM_RENAMED, [
|
|
'svcold' => $service,
|
|
'paramold' => $parameter,
|
|
'svcnew' => $parts[0],
|
|
'paramnew' => $parts[1]
|
|
]);
|
|
[$service,$parameter] = $parts;
|
|
}
|
|
|
|
$conf = $metadata->cur[$service] ?? $metadata->new[$service] ?? null;
|
|
|
|
if (null === $conf) {
|
|
// newer platform remaps
|
|
$remap = array_get(SiteConfiguration::MODULE_REMAP, $service);
|
|
if ($remap && $remap !== $service) {
|
|
return $this->getServiceValue($remap, $parameter, $default);
|
|
}
|
|
|
|
return $default;
|
|
}
|
|
|
|
if (!$parameter) {
|
|
return $conf;
|
|
}
|
|
|
|
if (array_key_exists($parameter, $conf)) {
|
|
return $conf[$parameter] ?? $default;
|
|
}
|
|
|
|
$remap = SiteConfiguration::serviceValueRemapClass($service, $parameter);
|
|
self::$serviceVariableRemaps[$key] = $remap ? ServiceValidator::configize($remap) : null;
|
|
|
|
return $this->getServiceValue($service, $parameter, $default);
|
|
}
|
|
|
|
/**
|
|
* Journals data to <site config>/info/new/<$svc_name>
|
|
* Invokes reconfigure hook when EditVirtDomain is used
|
|
*
|
|
* @param string $service
|
|
* @param string $parameter
|
|
* @param mixed $value
|
|
* @return Auth_Info_Account
|
|
*/
|
|
protected function setConfigJournal(string $service, string $parameter, $value): \Auth_Info_Account
|
|
{
|
|
return $this->setConfig($service, $parameter, $value, true);
|
|
}
|
|
|
|
/**
|
|
* Writes out configuration immediately to <site config>/info/current/<$svc_name>
|
|
* *Does not* invoke reconfigure hook when EditVirtDomain is used
|
|
*
|
|
* @param string $service service
|
|
* @param string $parameter service parameter
|
|
* @param mixed $value service value
|
|
* @param bool $journal write to unsynchronized journal (new/)
|
|
* @return Auth_Info_Account
|
|
*/
|
|
protected function setConfig(string $service, string $parameter, $value, bool $journal = false): \Auth_Info_Account
|
|
{
|
|
$conf = $this->getAuthContext()->getAccount();
|
|
// hook into \Auth_Info_Account()
|
|
$conf->change($service, array($parameter => $value), $journal);
|
|
if ($journal) {
|
|
$new = $conf->new;
|
|
} else {
|
|
$new = $conf->cur;
|
|
}
|
|
\DataStream::get($this->getAuthContext())->query('common_save_service_information_backend', $new, $journal);
|
|
return $this->getAuthContext()->reset();
|
|
}
|
|
} |