|
24 | 24 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
25 | 25 | use Symfony\Component\Security\Core\User\UserInterface;
|
26 | 26 | use Symfony\Component\Validator\Constraints as Assert;
|
| 27 | +use Symfony\Component\Yaml\Yaml; |
27 | 28 | use ZipStream\Option\Archive;
|
28 | 29 | use ZipStream\ZipStream;
|
29 | 30 | use Chamilo\CoreBundle\Component\Utils\ActionIcon;
|
@@ -4307,12 +4308,8 @@ function api_get_version()
|
4307 | 4308 | */
|
4308 | 4309 | function api_get_software_name()
|
4309 | 4310 | {
|
4310 |
| - $name = api_get_configuration_value('software_name'); |
4311 |
| - if (!empty($name)) { |
4312 |
| - return $name; |
4313 |
| - } else { |
4314 |
| - return 'Chamilo'; |
4315 |
| - } |
| 4311 | + $name = api_get_env_variable('SOFTWARE_NAME', 'Chamilo'); |
| 4312 | + return $name; |
4316 | 4313 | }
|
4317 | 4314 |
|
4318 | 4315 | function api_get_status_list()
|
@@ -5213,7 +5210,7 @@ function api_is_valid_secret_key($original_key_secret, $security_key)
|
5213 | 5210 | return false;
|
5214 | 5211 | }
|
5215 | 5212 |
|
5216 |
| - return (string) $original_key_secret === sha1($security_key); |
| 5213 | + return (string) $original_key_secret === hash('sha512', $security_key); |
5217 | 5214 | }
|
5218 | 5215 |
|
5219 | 5216 | /**
|
@@ -6816,6 +6813,65 @@ function api_get_configuration_value($variable)
|
6816 | 6813 | return false;
|
6817 | 6814 | }
|
6818 | 6815 |
|
| 6816 | +/** |
| 6817 | + * Loads hosting limits from the YAML file. |
| 6818 | + * |
| 6819 | + * @return array The hosting limits. |
| 6820 | + */ |
| 6821 | +function load_hosting_limits(): array |
| 6822 | +{ |
| 6823 | + $container = Container::$container; |
| 6824 | + |
| 6825 | + $hostingLimits = $container->getParameter('hosting_limits'); |
| 6826 | + |
| 6827 | + return $hostingLimits['urls'] ?? []; |
| 6828 | +} |
| 6829 | + |
| 6830 | +/** |
| 6831 | + * Gets a specific hosting limit. |
| 6832 | + * |
| 6833 | + * @param int $urlId The URL ID. |
| 6834 | + * @param string $limitName The name of the limit. |
| 6835 | + * @return mixed The value of the limit, or null if not found. |
| 6836 | + */ |
| 6837 | +function get_hosting_limit(int $urlId, string $limitName): mixed |
| 6838 | +{ |
| 6839 | + $limits = load_hosting_limits(); |
| 6840 | + |
| 6841 | + foreach ($limits[$urlId] as $limitArray) { |
| 6842 | + if (isset($limitArray[$limitName])) { |
| 6843 | + return $limitArray[$limitName]; |
| 6844 | + } |
| 6845 | + } |
| 6846 | + |
| 6847 | + return null; |
| 6848 | +} |
| 6849 | + |
| 6850 | + |
| 6851 | +/** |
| 6852 | + * Retrieves an environment variable value with validation and handles boolean conversion. |
| 6853 | + * |
| 6854 | + * @param string $variable The name of the environment variable. |
| 6855 | + * @param mixed $default The default value to return if the variable is not set. |
| 6856 | + * @return mixed The value of the environment variable, converted to boolean if necessary, or the default value. |
| 6857 | + */ |
| 6858 | +function api_get_env_variable(string $variable, mixed $default = null): mixed |
| 6859 | +{ |
| 6860 | + if (Container::$container->hasParameter($variable)) { |
| 6861 | + $value = Container::$container->getParameter($variable); |
| 6862 | + |
| 6863 | + if ($value === '0') { |
| 6864 | + return false; |
| 6865 | + } |
| 6866 | + if ($value === '1') { |
| 6867 | + return true; |
| 6868 | + } |
| 6869 | + |
| 6870 | + return $value; |
| 6871 | + } |
| 6872 | + |
| 6873 | + return $default; |
| 6874 | +} |
6819 | 6875 | /**
|
6820 | 6876 | * Retreives and returns a value in a hierarchical configuration array
|
6821 | 6877 | * api_get_configuration_sub_value('a/b/c') returns api_get_configuration_value('a')['b']['c'].
|
|
0 commit comments