diff --git a/api.php b/api.php index ce37a48a..1b2861c9 100644 --- a/api.php +++ b/api.php @@ -1,29 +1,38 @@ (2010-) - * @author Maurice Preuß - * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt - * @package API + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can also view it online at + * http://files.froxlor.org/misc/COPYING.txt + * + * @copyright the authors + * @author Froxlor team + * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ +use Froxlor\Api\Api; +use Froxlor\Api\Response; + +require __DIR__ . '/vendor/autoload.php'; +require __DIR__ . '/lib/functions.php'; +require __DIR__ . '/lib/tables.inc.php'; + // Return response try { echo (new Api)->formatMiddleware(@file_get_contents('php://input'))->handle(); } catch (Exception $e) { - echo \Froxlor\Api\Response::jsonErrorResponse($e->getMessage(), $e->getCode()); + echo Response::jsonErrorResponse($e->getMessage(), $e->getCode()); } diff --git a/lib/Froxlor/Api/ApiCommand.php b/lib/Froxlor/Api/ApiCommand.php index 6635ddd1..4f1f47fa 100644 --- a/lib/Froxlor/Api/ApiCommand.php +++ b/lib/Froxlor/Api/ApiCommand.php @@ -1,24 +1,40 @@ (2010-) - * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt - * @package API - * @since 0.10.0 - * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can also view it online at + * http://files.froxlor.org/misc/COPYING.txt + * + * @copyright the authors + * @author Froxlor team + * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ + +namespace Froxlor\Api; + +use Exception; +use Froxlor\Froxlor; +use Froxlor\FroxlorLogger; +use Froxlor\Language; +use Froxlor\System\Mailer; +use Froxlor\Settings; +use Froxlor\Api\Response; +use Froxlor\PhpHelper; +use Froxlor\Database\Database; + abstract class ApiCommand extends ApiParameter { @@ -64,13 +80,6 @@ abstract class ApiCommand extends ApiParameter */ private $internal_call = false; - /** - * language strings array - * - * @var array - */ - protected $lng = null; - /** * froxlor version * @@ -109,9 +118,9 @@ abstract class ApiCommand extends ApiParameter { parent::__construct($params); - $this->version = \Froxlor\Froxlor::VERSION; - $this->dbversion = \Froxlor\Froxlor::DBVERSION; - $this->branding = \Froxlor\Froxlor::BRANDING; + $this->version = Froxlor::VERSION; + $this->dbversion = Froxlor::DBVERSION; + $this->branding = Froxlor::BRANDING; if (!empty($header)) { $this->readUserData($header); @@ -119,14 +128,14 @@ abstract class ApiCommand extends ApiParameter $this->user_data = $userinfo; $this->is_admin = (isset($userinfo['adminsession']) && $userinfo['adminsession'] == 1 && $userinfo['adminid'] > 0) ? true : false; } else { - throw new \Exception("Invalid user data", 500); + throw new Exception("Invalid user data", 500); } - $this->logger = \Froxlor\FroxlorLogger::getInstanceOf($this->user_data); + $this->logger = FroxlorLogger::getInstanceOf($this->user_data); // check whether the user is deactivated if ($this->getUserDetail('deactivated') == 1) { - $this->logger()->logAction(\Froxlor\FroxlorLogger::LOG_ERROR, LOG_INFO, "[API] User '" . $this->getUserDetail('loginnname') . "' tried to use API but is deactivated"); - throw new \Exception("Account suspended", 406); + $this->logger()->logAction(FroxlorLogger::LOG_ERROR, LOG_INFO, "[API] User '" . $this->getUserDetail('loginnname') . "' tried to use API but is deactivated"); + throw new Exception("Account suspended", 406); } $this->initLang(); @@ -134,10 +143,10 @@ abstract class ApiCommand extends ApiParameter /** * Initialize the mailingsystem */ - $this->mail = new \Froxlor\System\Mailer(true); + $this->mail = new Mailer(true); if ($this->debug) { - $this->logger()->logAction(\Froxlor\FroxlorLogger::LOG_ERROR, LOG_DEBUG, "[API] " . get_called_class() . ": " . json_encode($params, JSON_UNESCAPED_SLASHES)); + $this->logger()->logAction(FroxlorLogger::LOG_ERROR, LOG_DEBUG, "[API] " . get_called_class() . ": " . json_encode($params, JSON_UNESCAPED_SLASHES)); } // set internal call flag @@ -145,56 +154,17 @@ abstract class ApiCommand extends ApiParameter } /** - * initialize global $lng variable to have - * localized strings available for the ApiCommands + * initialize language to have localized strings available for the ApiCommands */ private function initLang() { - global $lng; + Language::setLanguage(Settings::Get('panel.standardlanguage')); - // query the whole table - $result_stmt = \Froxlor\Database\Database::query("SELECT * FROM `" . TABLE_PANEL_LANGUAGE . "`"); - - $langs = array(); - // presort languages - while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) { - $langs[$row['language']][] = $row; + if ($this->getUserDetail('language') !== null && isset(Language::getLanguages()[$this->getUserDetail('language')])) { + Language::setLanguage($this->getUserDetail('language')); + } elseif ($this->getUserDetail('def_language') !== null) { + Language::setLanguage($this->getUserDetail('def_language')); } - - // set default language before anything else to - // ensure that we can display messages - $language = \Froxlor\Settings::Get('panel.standardlanguage'); - - if (isset($this->user_data['language']) && isset($langs[$this->user_data['language']])) { - // default: use language from session, #277 - $language = $this->user_data['language']; - } elseif (isset($this->user_data['def_language'])) { - $language = $this->user_data['def_language']; - } - - // include every english language file we can get - foreach ($langs['English'] as $value) { - include_once \Froxlor\FileDir::makeSecurePath(\Froxlor\Froxlor::getInstallDir() . '/' . $value['file']); - } - - // now include the selected language if its not english - if ($language != 'English') { - if (isset($langs[$language])) { - foreach ($langs[$language] as $value) { - include_once \Froxlor\FileDir::makeSecurePath(\Froxlor\Froxlor::getInstallDir() . '/' . $value['file']); - } - } else { - if ($this->debug) { - $this->logger()->logAction(\Froxlor\FroxlorLogger::LOG_ERROR, LOG_DEBUG, "[API] unable to include user-language '" . $language . "'. Not found in database.", 404); - } - } - } - - // last but not least include language references file - include_once \Froxlor\FileDir::makeSecurePath(\Froxlor\Froxlor::getInstallDir() . '/lng/lng_references.php'); - - // set array for ApiCommand - $this->lng = $lng; } /** @@ -242,7 +212,7 @@ abstract class ApiCommand extends ApiParameter * * @param string $detail * - * @return string + * @return string|null */ protected function getUserDetail($detail = null) { @@ -437,7 +407,7 @@ abstract class ApiCommand extends ApiParameter ])) { $by = 'ASC'; } - if (\Froxlor\Settings::Get('panel.natsorting') == 1 && in_array($field, $nat_fields)) { + if (Settings::Get('panel.natsorting') == 1 && in_array($field, $nat_fields)) { // Acts similar to php's natsort(), found in one comment at http://my.opera.com/cpr/blog/show.dml/160556 $order .= "CONCAT( IF( ASCII( LEFT( " . $field . ", 5 ) ) > 57, LEFT( " . $field . ", 1 ), 0 ), @@ -504,7 +474,7 @@ abstract class ApiCommand extends ApiParameter */ protected function response($data = null, int $response_code = 200) { - return \Froxlor\Api\Response::jsonDataResponse($data, $response_code); + return Response::jsonDataResponse($data, $response_code); } /** @@ -541,15 +511,15 @@ abstract class ApiCommand extends ApiParameter $customer_ids[] = $customer['customerid']; } } else { - if (!$this->isInternal() && !empty($customer_hide_option) && \Froxlor\Settings::IsInList('panel.customer_hide_options', $customer_hide_option)) { - throw new \Exception("You cannot access this resource", 405); + if (!$this->isInternal() && !empty($customer_hide_option) && Settings::IsInList('panel.customer_hide_options', $customer_hide_option)) { + throw new Exception("You cannot access this resource", 405); } $customer_ids = array( $this->getUserDetail('customerid') ); } if (empty($customer_ids)) { - throw new \Exception("Required resource unsatisfied.", 405); + throw new Exception("Required resource unsatisfied.", 405); } return $customer_ids; } @@ -578,7 +548,7 @@ abstract class ApiCommand extends ApiParameter )); // check whether the customer has enough resources if (!empty($customer_resource_check) && $customer[$customer_resource_check . '_used'] >= $customer[$customer_resource_check] && $customer[$customer_resource_check] != '-1') { - throw new \Exception("Customer has no more resources available", 406); + throw new Exception("Customer has no more resources available", 406); } } else { $customer = $this->getUserData(); @@ -599,12 +569,12 @@ abstract class ApiCommand extends ApiParameter */ protected static function updateResourceUsage($table = null, $keyfield = null, $key = null, $operator = '+', $resource = null, $extra = null, $step = 1) { - $stmt = \Froxlor\Database\Database::prepare(" + $stmt = Database::prepare(" UPDATE `" . $table . "` SET `" . $resource . "` = `" . $resource . "` " . $operator . " " . (int) $step . " " . $extra . " WHERE `" . $keyfield . "` = :key "); - \Froxlor\Database\Database::pexecute($stmt, array( + Database::pexecute($stmt, array( 'key' => $key ), true, true); } @@ -623,11 +593,11 @@ abstract class ApiCommand extends ApiParameter protected function getMailTemplate($customerdata = null, $group = null, $varname = null, $replace_arr = array(), $default = "") { // get template - $stmt = \Froxlor\Database\Database::prepare(" + $stmt = Database::prepare(" SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` WHERE `adminid`= :adminid AND `language`= :lang AND `templategroup`= :group AND `varname`= :var "); - $result = \Froxlor\Database\Database::pexecute_first($stmt, array( + $result = Database::pexecute_first($stmt, array( "adminid" => $customerdata['adminid'], "lang" => $customerdata['def_language'], "group" => $group, @@ -638,7 +608,7 @@ abstract class ApiCommand extends ApiParameter $content = $result['value'] ?? $default; } // @fixme html_entity_decode - $content = html_entity_decode(\Froxlor\PhpHelper::replaceVariables($content, $replace_arr)); + $content = html_entity_decode(PhpHelper::replaceVariables($content, $replace_arr)); return $content; } @@ -653,8 +623,8 @@ abstract class ApiCommand extends ApiParameter */ private function readUserData($header = null) { - $sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as"); - $result = \Froxlor\Database\Database::pexecute_first($sel_stmt, array( + $sel_stmt = Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as"); + $result = Database::pexecute_first($sel_stmt, array( 'ak' => $header['apikey'], 'as' => $header['secret'] ), true, true); @@ -670,10 +640,10 @@ abstract class ApiCommand extends ApiParameter $key = "customerid"; } else { // neither adminid is > 0 nor customerid is > 0 - sorry man, no way - throw new \Exception("Invalid API credentials", 400); + throw new Exception("Invalid API credentials", 400); } - $sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id"); - $this->user_data = \Froxlor\Database\Database::pexecute_first($sel_stmt, array( + $sel_stmt = Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id"); + $this->user_data = Database::pexecute_first($sel_stmt, array( 'id' => ($this->is_admin ? $result['adminid'] : $result['customerid']) ), true, true); if ($this->is_admin) { @@ -681,6 +651,6 @@ abstract class ApiCommand extends ApiParameter } return true; } - throw new \Exception("Invalid API credentials", 400); + throw new Exception("Invalid API credentials", 400); } } diff --git a/lib/Froxlor/Api/ApiParameter.php b/lib/Froxlor/Api/ApiParameter.php index 6acb2309..b3edfa76 100644 --- a/lib/Froxlor/Api/ApiParameter.php +++ b/lib/Froxlor/Api/ApiParameter.php @@ -1,21 +1,32 @@ (2010-) - * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt - * @package API - * @since 0.10.0 - * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you can also view it online at + * http://files.froxlor.org/misc/COPYING.txt + * + * @copyright the authors + * @author Froxlor team + * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ + +namespace Froxlor\Api; + +use Exception; + abstract class ApiParameter { @@ -63,7 +74,7 @@ abstract class ApiParameter if ($optional === false) { // get module + function for better error-messages $inmod = $this->getModFunctionString(); - throw new \Exception('Requested parameter "' . $param . '" could not be found for "' . $inmod . '"', 404); + throw new Exception('Requested parameter "' . $param . '" could not be found for "' . $inmod . '"', 404); } return $default; } @@ -72,7 +83,7 @@ abstract class ApiParameter if ($optional === false) { // get module + function for better error-messages $inmod = $this->getModFunctionString(); - throw new \Exception('Requested parameter "' . $param . '" is empty where it should not be for "' . $inmod . '"', 406); + throw new Exception('Requested parameter "' . $param . '" is empty where it should not be for "' . $inmod . '"', 406); } return ''; } diff --git a/lib/Froxlor/Api/Commands/Admins.php b/lib/Froxlor/Api/Commands/Admins.php index d48765c1..d554a607 100644 --- a/lib/Froxlor/Api/Commands/Admins.php +++ b/lib/Froxlor/Api/Commands/Admins.php @@ -578,34 +578,34 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt // than actually used by the admin/reseller $res_warning = ""; if ($customers != $result['customers'] && $customers != - 1 && $customers < $result['customers_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'customers'); + $res_warning .= lng('error.setlessthanalreadyused', ['customers']); } if ($domains != $result['domains'] && $domains != - 1 && $domains < $result['domains_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'domains'); + $res_warning .= lng('error.setlessthanalreadyused', ['domains']); } if ($diskspace != $result['diskspace'] && ($diskspace / 1024) != - 1 && $diskspace < $result['diskspace_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'diskspace'); + $res_warning .= lng('error.setlessthanalreadyused', ['diskspace']); } if ($traffic != $result['traffic'] && ($traffic / 1024 / 1024) != - 1 && $traffic < $result['traffic_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'traffic'); + $res_warning .= lng('error.setlessthanalreadyused', ['traffic']); } if ($emails != $result['emails'] && $emails != - 1 && $emails < $result['emails_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'emails'); + $res_warning .= lng('error.setlessthanalreadyused', ['emails']); } if ($email_accounts != $result['email_accounts'] && $email_accounts != - 1 && $email_accounts < $result['email_accounts_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'email accounts'); + $res_warning .= lng('error.setlessthanalreadyused', ['email accounts']); } if ($email_forwarders != $result['email_forwarders'] && $email_forwarders != - 1 && $email_forwarders < $result['email_forwarders_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'email forwarders'); + $res_warning .= lng('error.setlessthanalreadyused', ['email forwarders']); } if ($email_quota != $result['email_quota'] && $email_quota != - 1 && $email_quota < $result['email_quota_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'email quota'); + $res_warning .= lng('error.setlessthanalreadyused', ['email quota']); } if ($ftps != $result['ftps'] && $ftps != - 1 && $ftps < $result['ftps_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'ftps'); + $res_warning .= lng('error.setlessthanalreadyused', ['ftps']); } if ($mysqls != $result['mysqls'] && $mysqls != - 1 && $mysqls < $result['mysqls_used']) { - $res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'mysqls'); + $res_warning .= lng('error.setlessthanalreadyused', ['mysqls']); } if (! empty($res_warning)) { diff --git a/lib/Froxlor/Api/Commands/DomainZones.php b/lib/Froxlor/Api/Commands/DomainZones.php index 0c93ff40..2da17b32 100644 --- a/lib/Froxlor/Api/Commands/DomainZones.php +++ b/lib/Froxlor/Api/Commands/DomainZones.php @@ -101,7 +101,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour if ($record != '@' && $record != '*') { // validate record if (strpos($record, '--') !== false) { - $errors[] = $this->lng['error']['domain_nopunycode']; + $errors[] = lng('error.domain_nopunycode'); } else { // check for wildcard-record $add_wildcard_again = false; @@ -117,7 +117,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour } if (strlen($record) > 63) { - $errors[] = $this->lng['error']['dns_record_toolong']; + $errors[] = lng('error.dns_record_toolong'); } } } @@ -130,27 +130,27 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $content = trim($content); if (empty($content)) { - $errors[] = $this->lng['error']['dns_content_empty']; + $errors[] = lng('error.dns_content_empty'); } // types if ($type == 'A' && filter_var($content, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { - $errors[] = $this->lng['error']['dns_arec_noipv4']; + $errors[] = lng('error.dns_arec_noipv4'); } elseif ($type == 'A') { // check whether there is a CNAME-record for the same resource foreach ($dom_entries as $existing_entries) { if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { - $errors[] = $this->lng['error']['dns_other_nomorerr']; + $errors[] = lng('error.dns_other_nomorerr'); break; } } } elseif ($type == 'AAAA' && filter_var($content, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { - $errors[] = $this->lng['error']['dns_aaaarec_noipv6']; + $errors[] = lng('error.dns_aaaarec_noipv6'); } elseif ($type == 'AAAA') { // check whether there is a CNAME-record for the same resource foreach ($dom_entries as $existing_entries) { if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { - $errors[] = $this->lng['error']['dns_other_nomorerr']; + $errors[] = lng('error.dns_other_nomorerr'); break; } } @@ -159,11 +159,11 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour preg_match($re, $content, $matches); if (empty($matches)) { - $errors[] = $this->lng['error']['dns_content_invalid']; + $errors[] = lng('error.dns_content_invalid'); } elseif (($matches['type'] == 'issue' || $matches['type'] == 'issuewild') && ! \Froxlor\Validate\Validate::validateDomain($matches['domain'])) { - $errors[] = $this->lng['error']['dns_content_invalid']; + $errors[] = lng('error.dns_content_invalid'); } elseif ($matches['type'] == 'iodef' && ! \Froxlor\Validate\Validate::validateUrl($matches['url'])) { - $errors[] = $this->lng['error']['dns_content_invalid']; + $errors[] = lng('error.dns_content_invalid'); } else { $content = $matches[0]; } @@ -177,18 +177,18 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $content .= '.' . $domain; } if (! \Froxlor\Validate\Validate::validateDomain($content, true)) { - $errors[] = $this->lng['error']['dns_cname_invaliddom']; + $errors[] = lng('error.dns_cname_invaliddom'); } else { // check whether there are RR-records for the same resource foreach ($dom_entries as $existing_entries) { if (($existing_entries['type'] == 'A' || $existing_entries['type'] == 'AAAA' || $existing_entries['type'] == 'MX' || $existing_entries['type'] == 'NS') && $existing_entries['record'] == $record) { - $errors[] = $this->lng['error']['dns_cname_nomorerr']; + $errors[] = lng('error.dns_cname_nomorerr'); break; } } // check www-alias setting if ($result['wwwserveralias'] == '1' && $result['iswildcarddomain'] == '0' && $record == 'www') { - $errors[] = $this->lng['error']['no_wwwcnamae_ifwwwalias']; + $errors[] = lng('error.no_wwwcnamae_ifwwwalias'); } } // append trailing dot (again) @@ -197,7 +197,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $content = $content; } elseif ($type == 'MX') { if ($prio === null || $prio < 0) { - $errors[] = $this->lng['error']['dns_mx_prioempty']; + $errors[] = lng('error.dns_mx_prioempty'); } // check for trailing dot if (substr($content, - 1) == '.') { @@ -205,17 +205,17 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $content = substr($content, 0, - 1); } if (! \Froxlor\Validate\Validate::validateDomain($content)) { - $errors[] = $this->lng['error']['dns_mx_needdom']; + $errors[] = lng('error.dns_mx_needdom'); } else { // check whether there is a CNAME-record for the same resource foreach ($dom_entries as $existing_entries) { $fqdn = $existing_entries['record'] . '.' . $domain; if ($existing_entries['type'] == 'CNAME' && $fqdn == $content) { - $errors[] = $this->lng['error']['dns_mx_noalias']; + $errors[] = lng('error.dns_mx_noalias'); break; } elseif ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { - $errors[] = $this->lng['error']['dns_other_nomorerr']; + $errors[] = lng('error.dns_other_nomorerr'); break; } } @@ -229,12 +229,12 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $content = substr($content, 0, - 1); } if (! \Froxlor\Validate\Validate::validateDomain($content)) { - $errors[] = $this->lng['error']['dns_ns_invaliddom']; + $errors[] = lng('error.dns_ns_invaliddom'); } else { // check whether there is a CNAME-record for the same resource foreach ($dom_entries as $existing_entries) { if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { - $errors[] = $this->lng['error']['dns_other_nomorerr']; + $errors[] = lng('error.dns_other_nomorerr'); break; } } @@ -245,14 +245,14 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $content = $content; } elseif ($type == 'SRV') { if ($prio === null || $prio < 0) { - $errors[] = $this->lng['error']['dns_srv_prioempty']; + $errors[] = lng('error.dns_srv_prioempty'); } // check only last part of content, as it can look like: // _service._proto.name. TTL class SRV priority weight port target. $_split_content = explode(" ", $content); // SRV content must be [weight] [port] [target] if (count($_split_content) != 3) { - $errors[] = $this->lng['error']['dns_srv_invalidcontent']; + $errors[] = lng('error.dns_srv_invalidcontent'); } $target = trim($_split_content[count($_split_content) - 1]); if ($target != '.') { @@ -263,13 +263,13 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour } } if ($target != '.' && ! \Froxlor\Validate\Validate::validateDomain($target, true)) { - $errors[] = $this->lng['error']['dns_srv_needdom']; + $errors[] = lng('error.dns_srv_needdom'); } else { // check whether there is a CNAME-record for the same resource foreach ($dom_entries as $existing_entries) { $fqdn = $existing_entries['record'] . '.' . $domain; if ($existing_entries['type'] == 'CNAME' && $fqdn == $target) { - $errors[] = $this->lng['error']['dns_srv_noalias']; + $errors[] = lng('error.dns_srv_noalias'); break; } } @@ -312,7 +312,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour $new = json_encode($new_entry); // compare if ($check_entry === $new) { - $errors[] = $this->lng['error']['dns_duplicate_entry']; + $errors[] = lng('error.dns_duplicate_entry'); unset($check_entry); break; } diff --git a/lib/Froxlor/Api/Commands/EmailAccounts.php b/lib/Froxlor/Api/Commands/EmailAccounts.php index 8836bbc9..c2898735 100644 --- a/lib/Froxlor/Api/Commands/EmailAccounts.php +++ b/lib/Froxlor/Api/Commands/EmailAccounts.php @@ -207,9 +207,9 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso )); // get template for mail subject - $mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_subject', $replace_arr, $this->lng['mails']['pop_success']['subject']); + $mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_subject', $replace_arr, lng('mails.pop_success.subject')); // get template for mail body - $mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_mailbody', $replace_arr, $this->lng['mails']['pop_success']['mailbody']); + $mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_mailbody', $replace_arr, lng('mails.pop_success.mailbody')); $_mailerror = false; $mailerr_msg = ""; @@ -238,9 +238,9 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso // customer wants to send the e-mail to an alternative email address too if (Settings::Get('panel.sendalternativemail') == 1 && ! empty($alternative_email)) { // get template for mail subject - $mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_subject', $replace_arr, $this->lng['mails']['pop_success_alternative']['subject']); + $mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_subject', $replace_arr, lng('mails.pop_success_alternative.subject')); // get template for mail body - $mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_mailbody', $replace_arr, $this->lng['mails']['pop_success_alternative']['mailbody']); + $mail_body = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_mailbody', $replace_arr, lng('mails.pop_success_alternative.mailbody')); $_mailerror = false; try { diff --git a/lib/Froxlor/Api/Commands/FpmDaemons.php b/lib/Froxlor/Api/Commands/FpmDaemons.php index 3490b8f9..9a2c6e56 100644 --- a/lib/Froxlor/Api/Commands/FpmDaemons.php +++ b/lib/Froxlor/Api/Commands/FpmDaemons.php @@ -63,7 +63,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc } if (empty($configs)) { - $configs[] = $this->lng['admin']['phpsettings']['notused']; + $configs[] = lng('admin.phpsettings.notused'); } $row['configs'] = $configs; diff --git a/lib/Froxlor/Api/Commands/Ftps.php b/lib/Froxlor/Api/Commands/Ftps.php index 88319785..12c1467d 100644 --- a/lib/Froxlor/Api/Commands/Ftps.php +++ b/lib/Froxlor/Api/Commands/Ftps.php @@ -249,9 +249,9 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit 'USR_PATH' => \Froxlor\FileDir::makeCorrectDir(str_replace($customer['documentroot'], "/", $path)) ); // get template for mail subject - $mail_subject = $this->getMailTemplate($customer, 'mails', 'new_ftpaccount_by_customer_subject', $replace_arr, $this->lng['mails']['new_ftpaccount_by_customer']['subject']); + $mail_subject = $this->getMailTemplate($customer, 'mails', 'new_ftpaccount_by_customer_subject', $replace_arr, lng('mails.new_ftpaccount_by_customer.subject')); // get template for mail body - $mail_body = $this->getMailTemplate($customer, 'mails', 'new_ftpaccount_by_customer_mailbody', $replace_arr, $this->lng['mails']['new_ftpaccount_by_customer']['mailbody']); + $mail_body = $this->getMailTemplate($customer, 'mails', 'new_ftpaccount_by_customer_mailbody', $replace_arr, lng('mails.new_ftpaccount_by_customer.mailbody')); $_mailerror = false; $mailerr_msg = ""; diff --git a/lib/Froxlor/Api/Commands/Mysqls.php b/lib/Froxlor/Api/Commands/Mysqls.php index 13304fdd..0772829a 100644 --- a/lib/Froxlor/Api/Commands/Mysqls.php +++ b/lib/Froxlor/Api/Commands/Mysqls.php @@ -68,7 +68,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt } // validate whether the dbserver exists - $dbserver = \Froxlor\Validate\Validate::validate($dbserver, html_entity_decode($this->lng['mysql']['mysql_server']), '', '', 0, true); + $dbserver = \Froxlor\Validate\Validate::validate($dbserver, html_entity_decode(lng('mysql.mysql_server')), '', '', 0, true); Database::needRoot(true, $dbserver); Database::needSqlData(); $sql_root = Database::getSqlData(); @@ -124,7 +124,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt // send info-mail? if ($sendinfomail == 1) { - $pma = $this->lng['admin']['notgiven']; + $pma = lng('admin.notgiven'); if (Settings::Get('panel.phpmyadmin_url') != '') { $pma = Settings::Get('panel.phpmyadmin_url'); } @@ -150,9 +150,9 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt ); // get template for mail subject - $mail_subject = $this->getMailTemplate($userinfo, 'mails', 'new_database_by_customer_subject', $replace_arr, $this->lng['mails']['new_database_by_customer']['subject']); + $mail_subject = $this->getMailTemplate($userinfo, 'mails', 'new_database_by_customer_subject', $replace_arr, lng('mails.new_database_by_customer.subject')); // get template for mail body - $mail_body = $this->getMailTemplate($userinfo, 'mails', 'new_database_by_customer_mailbody', $replace_arr, $this->lng['mails']['new_database_by_customer']['mailbody']); + $mail_body = $this->getMailTemplate($userinfo, 'mails', 'new_database_by_customer_mailbody', $replace_arr, lng('mails.new_database_by_customer.mailbody')); $_mailerror = false; $mailerr_msg = ""; diff --git a/lib/functions.php b/lib/functions.php index 21086c8c..4604a90e 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -23,6 +23,8 @@ * @license http://files.froxlor.org/misc/COPYING.txt GPLv2 */ +use Froxlor\Language; + function view($template, $attributes) { $view = file_get_contents(dirname(__DIR__) . '/templates/' . $template); @@ -32,5 +34,5 @@ function view($template, $attributes) function lng(string $identifier, array $arguments = []) { - return \Froxlor\Language::getTranslation($identifier, $arguments); + return Language::getTranslation($identifier, $arguments); }