mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
www/caddy: Implement gettext() function for localization in php controllers and model (#3980)
This commit is contained in:
+1
-6
@@ -76,16 +76,11 @@ class DiagnosticsController extends ApiMutableModelControllerBase
|
||||
// Decode JSON to PHP array
|
||||
$responseArray = json_decode($response, true);
|
||||
|
||||
// Since errors are handled by the caddy_diagnostics script and returned as json, check for an error key in the response
|
||||
if (isset($responseArray['error'])) {
|
||||
// Handle the error
|
||||
return ["status" => "failed", "message" => $responseArray['message']];
|
||||
}
|
||||
|
||||
// Assuming the response structure is like { "content": "actual Caddyfile content here" }
|
||||
if (!isset($responseArray['content'])) {
|
||||
return ["status" => "failed", "message" => "Caddyfile content not found"];
|
||||
}
|
||||
|
||||
// Return the response as an array which gets automatically encoded to JSON
|
||||
return ["status" => "success", "content" => $responseArray['content']];
|
||||
}
|
||||
|
||||
@@ -68,6 +68,6 @@ class ServiceController extends ApiMutableServiceControllerBase
|
||||
}
|
||||
|
||||
// If unable to parse the expected JSON output, return a generic error message
|
||||
return ["status" => "failed", "message" => "Unable to parse the validation result."];
|
||||
return ["status" => "failed", "message" => gettext("Unable to parse the validation result.")];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class Caddy extends BaseModel
|
||||
{
|
||||
// 1. Check domain-port combinations
|
||||
// 2. Check subdomain-port combinations
|
||||
private function checkForUniquePortCombos($items, $messages, $type = 'domain')
|
||||
private function checkForUniquePortCombos($items, $messages)
|
||||
{
|
||||
$combos = [];
|
||||
foreach ($items as $item) {
|
||||
@@ -59,9 +59,9 @@ class Caddy extends BaseModel
|
||||
if (isset($combos[$comboKey])) {
|
||||
// Use dynamic $key for message referencing
|
||||
$messages->appendMessage(new Message(
|
||||
"Duplicate entry: The combination of $type '$fromDomainOrSubdomain' and port '$port' is already used. Each $type and port pairing must be unique.",
|
||||
$type === 'domain' ? $key . ".FromDomain" : $key . ".FromDomain", // Adjusted to use dynamic key
|
||||
"Duplicate" . ucfirst($type) . "Port"
|
||||
sprintf(gettext("Duplicate entry: The combination of '%s' and port '%s' is already used. Each combination of domain/subdomain and port must be unique."), $fromDomainOrSubdomain, $port),
|
||||
$key . ".FromDomain", // Adjusted to use dynamic key
|
||||
"DuplicateDomainPort"
|
||||
));
|
||||
} else {
|
||||
$combos[$comboKey] = true;
|
||||
@@ -98,7 +98,7 @@ class Caddy extends BaseModel
|
||||
if (!$isValid) {
|
||||
$key = $subdomain->__reference; // Dynamic key based on subdomain reference
|
||||
$messages->appendMessage(new Message(
|
||||
"Invalid subdomain configuration: '$subdomainName' does not fall under any configured wildcard domain.",
|
||||
sprintf(gettext("Invalid subdomain configuration: '%s' does not fall under any configured wildcard domain."), $subdomainName),
|
||||
$key . ".FromDomain", // Use dynamic key for message referencing
|
||||
"InvalidSubdomain"
|
||||
));
|
||||
@@ -112,9 +112,9 @@ class Caddy extends BaseModel
|
||||
{
|
||||
$messages = parent::performValidation($validateFullModel);
|
||||
// 1. Check domain-port combinations
|
||||
$this->checkForUniquePortCombos($this->reverseproxy->reverse->iterateItems(), $messages, 'domain');
|
||||
$this->checkForUniquePortCombos($this->reverseproxy->reverse->iterateItems(), $messages);
|
||||
// 2. Check subdomain-port combinations
|
||||
$this->checkForUniquePortCombos($this->reverseproxy->subdomain->iterateItems(), $messages, 'subdomain');
|
||||
$this->checkForUniquePortCombos($this->reverseproxy->subdomain->iterateItems(), $messages);
|
||||
// 3. Check that subdomains are under a wildcard or exact domain
|
||||
$this->checkSubdomainsAgainstDomains($this->reverseproxy->subdomain->iterateItems(), $this->reverseproxy->reverse->iterateItems(), $messages);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user