use new language class in API

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-28 18:14:00 +02:00
parent 373dfa7ad9
commit a2e95b960f
10 changed files with 156 additions and 164 deletions

37
api.php
View File

@@ -1,29 +1,38 @@
<?php <?php
use Froxlor\Api\Api;
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/lib/tables.inc.php';
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors). * Copyright (c) 2010 the Froxlor Team (see authors).
* *
* For the full copyright and license information, please view the COPYING * This program is free software; you can redistribute it and/or
* file that was distributed with this source code. You can also view the * modify it under the terms of the GNU General Public License
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* *
* @copyright (c) the authors * This program is distributed in the hope that it will be useful,
* @author Froxlor team <team@froxlor.org> (2010-) * but WITHOUT ANY WARRANTY; without even the implied warranty of
* @author Maurice Preuß <hello@envoyr.com> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * GNU General Public License for more details.
* @package API
* *
* 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 <team@froxlor.org>
* @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 // Return response
try { try {
echo (new Api)->formatMiddleware(@file_get_contents('php://input'))->handle(); echo (new Api)->formatMiddleware(@file_get_contents('php://input'))->handle();
} catch (Exception $e) { } catch (Exception $e) {
echo \Froxlor\Api\Response::jsonErrorResponse($e->getMessage(), $e->getCode()); echo Response::jsonErrorResponse($e->getMessage(), $e->getCode());
} }

View File

@@ -1,24 +1,40 @@
<?php <?php
namespace Froxlor\Api;
use Exception;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors). * Copyright (c) 2010 the Froxlor Team (see authors).
* *
* For the full copyright and license information, please view the COPYING * This program is free software; you can redistribute it and/or
* file that was distributed with this source code. You can also view the * modify it under the terms of the GNU General Public License
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* *
* @copyright (c) the authors * This program is distributed in the hope that it will be useful,
* @author Froxlor team <team@froxlor.org> (2010-) * but WITHOUT ANY WARRANTY; without even the implied warranty of
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* @package API * GNU General Public License for more details.
* @since 0.10.0 *
* * 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 <team@froxlor.org>
* @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 abstract class ApiCommand extends ApiParameter
{ {
@@ -64,13 +80,6 @@ abstract class ApiCommand extends ApiParameter
*/ */
private $internal_call = false; private $internal_call = false;
/**
* language strings array
*
* @var array
*/
protected $lng = null;
/** /**
* froxlor version * froxlor version
* *
@@ -109,9 +118,9 @@ abstract class ApiCommand extends ApiParameter
{ {
parent::__construct($params); parent::__construct($params);
$this->version = \Froxlor\Froxlor::VERSION; $this->version = Froxlor::VERSION;
$this->dbversion = \Froxlor\Froxlor::DBVERSION; $this->dbversion = Froxlor::DBVERSION;
$this->branding = \Froxlor\Froxlor::BRANDING; $this->branding = Froxlor::BRANDING;
if (!empty($header)) { if (!empty($header)) {
$this->readUserData($header); $this->readUserData($header);
@@ -119,14 +128,14 @@ abstract class ApiCommand extends ApiParameter
$this->user_data = $userinfo; $this->user_data = $userinfo;
$this->is_admin = (isset($userinfo['adminsession']) && $userinfo['adminsession'] == 1 && $userinfo['adminid'] > 0) ? true : false; $this->is_admin = (isset($userinfo['adminsession']) && $userinfo['adminsession'] == 1 && $userinfo['adminid'] > 0) ? true : false;
} else { } 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 // check whether the user is deactivated
if ($this->getUserDetail('deactivated') == 1) { 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"); $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); throw new Exception("Account suspended", 406);
} }
$this->initLang(); $this->initLang();
@@ -134,10 +143,10 @@ abstract class ApiCommand extends ApiParameter
/** /**
* Initialize the mailingsystem * Initialize the mailingsystem
*/ */
$this->mail = new \Froxlor\System\Mailer(true); $this->mail = new Mailer(true);
if ($this->debug) { 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 // set internal call flag
@@ -145,56 +154,17 @@ abstract class ApiCommand extends ApiParameter
} }
/** /**
* initialize global $lng variable to have * initialize language to have localized strings available for the ApiCommands
* localized strings available for the ApiCommands
*/ */
private function initLang() private function initLang()
{ {
global $lng; Language::setLanguage(Settings::Get('panel.standardlanguage'));
// query the whole table if ($this->getUserDetail('language') !== null && isset(Language::getLanguages()[$this->getUserDetail('language')])) {
$result_stmt = \Froxlor\Database\Database::query("SELECT * FROM `" . TABLE_PANEL_LANGUAGE . "`"); Language::setLanguage($this->getUserDetail('language'));
} elseif ($this->getUserDetail('def_language') !== null) {
$langs = array(); Language::setLanguage($this->getUserDetail('def_language'));
// presort languages
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$langs[$row['language']][] = $row;
} }
// 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 * @param string $detail
* *
* @return string * @return string|null
*/ */
protected function getUserDetail($detail = null) protected function getUserDetail($detail = null)
{ {
@@ -437,7 +407,7 @@ abstract class ApiCommand extends ApiParameter
])) { ])) {
$by = 'ASC'; $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 // 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, $order .= "CONCAT( IF( ASCII( LEFT( " . $field . ", 5 ) ) > 57,
LEFT( " . $field . ", 1 ), 0 ), LEFT( " . $field . ", 1 ), 0 ),
@@ -504,7 +474,7 @@ abstract class ApiCommand extends ApiParameter
*/ */
protected function response($data = null, int $response_code = 200) 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']; $customer_ids[] = $customer['customerid'];
} }
} else { } else {
if (!$this->isInternal() && !empty($customer_hide_option) && \Froxlor\Settings::IsInList('panel.customer_hide_options', $customer_hide_option)) { 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); throw new Exception("You cannot access this resource", 405);
} }
$customer_ids = array( $customer_ids = array(
$this->getUserDetail('customerid') $this->getUserDetail('customerid')
); );
} }
if (empty($customer_ids)) { if (empty($customer_ids)) {
throw new \Exception("Required resource unsatisfied.", 405); throw new Exception("Required resource unsatisfied.", 405);
} }
return $customer_ids; return $customer_ids;
} }
@@ -578,7 +548,7 @@ abstract class ApiCommand extends ApiParameter
)); ));
// check whether the customer has enough resources // 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') { 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 { } else {
$customer = $this->getUserData(); $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) 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 . "` UPDATE `" . $table . "`
SET `" . $resource . "` = `" . $resource . "` " . $operator . " " . (int) $step . " " . $extra . " SET `" . $resource . "` = `" . $resource . "` " . $operator . " " . (int) $step . " " . $extra . "
WHERE `" . $keyfield . "` = :key WHERE `" . $keyfield . "` = :key
"); ");
\Froxlor\Database\Database::pexecute($stmt, array( Database::pexecute($stmt, array(
'key' => $key 'key' => $key
), true, true); ), true, true);
} }
@@ -623,11 +593,11 @@ abstract class ApiCommand extends ApiParameter
protected function getMailTemplate($customerdata = null, $group = null, $varname = null, $replace_arr = array(), $default = "") protected function getMailTemplate($customerdata = null, $group = null, $varname = null, $replace_arr = array(), $default = "")
{ {
// get template // get template
$stmt = \Froxlor\Database\Database::prepare(" $stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` WHERE `adminid`= :adminid SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` WHERE `adminid`= :adminid
AND `language`= :lang AND `templategroup`= :group AND `varname`= :var 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'], "adminid" => $customerdata['adminid'],
"lang" => $customerdata['def_language'], "lang" => $customerdata['def_language'],
"group" => $group, "group" => $group,
@@ -638,7 +608,7 @@ abstract class ApiCommand extends ApiParameter
$content = $result['value'] ?? $default; $content = $result['value'] ?? $default;
} }
// @fixme html_entity_decode // @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; return $content;
} }
@@ -653,8 +623,8 @@ abstract class ApiCommand extends ApiParameter
*/ */
private function readUserData($header = null) private function readUserData($header = null)
{ {
$sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as"); $sel_stmt = Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
$result = \Froxlor\Database\Database::pexecute_first($sel_stmt, array( $result = Database::pexecute_first($sel_stmt, array(
'ak' => $header['apikey'], 'ak' => $header['apikey'],
'as' => $header['secret'] 'as' => $header['secret']
), true, true); ), true, true);
@@ -670,10 +640,10 @@ abstract class ApiCommand extends ApiParameter
$key = "customerid"; $key = "customerid";
} else { } else {
// neither adminid is > 0 nor customerid is > 0 - sorry man, no way // 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"); $sel_stmt = Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id");
$this->user_data = \Froxlor\Database\Database::pexecute_first($sel_stmt, array( $this->user_data = Database::pexecute_first($sel_stmt, array(
'id' => ($this->is_admin ? $result['adminid'] : $result['customerid']) 'id' => ($this->is_admin ? $result['adminid'] : $result['customerid'])
), true, true); ), true, true);
if ($this->is_admin) { if ($this->is_admin) {
@@ -681,6 +651,6 @@ abstract class ApiCommand extends ApiParameter
} }
return true; return true;
} }
throw new \Exception("Invalid API credentials", 400); throw new Exception("Invalid API credentials", 400);
} }
} }

View File

@@ -1,21 +1,32 @@
<?php <?php
namespace Froxlor\Api;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors). * Copyright (c) 2010 the Froxlor Team (see authors).
* *
* For the full copyright and license information, please view the COPYING * This program is free software; you can redistribute it and/or
* file that was distributed with this source code. You can also view the * modify it under the terms of the GNU General Public License
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* *
* @copyright (c) the authors * This program is distributed in the hope that it will be useful,
* @author Froxlor team <team@froxlor.org> (2010-) * but WITHOUT ANY WARRANTY; without even the implied warranty of
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* @package API * GNU General Public License for more details.
* @since 0.10.0 *
* * 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 <team@froxlor.org>
* @license http://files.froxlor.org/misc/COPYING.txt GPLv2
*/ */
namespace Froxlor\Api;
use Exception;
abstract class ApiParameter abstract class ApiParameter
{ {
@@ -63,7 +74,7 @@ abstract class ApiParameter
if ($optional === false) { if ($optional === false) {
// get module + function for better error-messages // get module + function for better error-messages
$inmod = $this->getModFunctionString(); $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; return $default;
} }
@@ -72,7 +83,7 @@ abstract class ApiParameter
if ($optional === false) { if ($optional === false) {
// get module + function for better error-messages // get module + function for better error-messages
$inmod = $this->getModFunctionString(); $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 ''; return '';
} }

View File

@@ -578,34 +578,34 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// than actually used by the admin/reseller // than actually used by the admin/reseller
$res_warning = ""; $res_warning = "";
if ($customers != $result['customers'] && $customers != - 1 && $customers < $result['customers_used']) { 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']) { 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']) { 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']) { 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']) { 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']) { 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']) { 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']) { 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']) { 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']) { 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)) { if (! empty($res_warning)) {

View File

@@ -101,7 +101,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
if ($record != '@' && $record != '*') { if ($record != '@' && $record != '*') {
// validate record // validate record
if (strpos($record, '--') !== false) { if (strpos($record, '--') !== false) {
$errors[] = $this->lng['error']['domain_nopunycode']; $errors[] = lng('error.domain_nopunycode');
} else { } else {
// check for wildcard-record // check for wildcard-record
$add_wildcard_again = false; $add_wildcard_again = false;
@@ -117,7 +117,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
} }
if (strlen($record) > 63) { 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); $content = trim($content);
if (empty($content)) { if (empty($content)) {
$errors[] = $this->lng['error']['dns_content_empty']; $errors[] = lng('error.dns_content_empty');
} }
// types // types
if ($type == 'A' && filter_var($content, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { 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') { } elseif ($type == 'A') {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource
foreach ($dom_entries as $existing_entries) { foreach ($dom_entries as $existing_entries) {
if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) {
$errors[] = $this->lng['error']['dns_other_nomorerr']; $errors[] = lng('error.dns_other_nomorerr');
break; break;
} }
} }
} elseif ($type == 'AAAA' && filter_var($content, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { } 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') { } elseif ($type == 'AAAA') {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource
foreach ($dom_entries as $existing_entries) { foreach ($dom_entries as $existing_entries) {
if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) {
$errors[] = $this->lng['error']['dns_other_nomorerr']; $errors[] = lng('error.dns_other_nomorerr');
break; break;
} }
} }
@@ -159,11 +159,11 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
preg_match($re, $content, $matches); preg_match($re, $content, $matches);
if (empty($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'])) { } 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'])) { } elseif ($matches['type'] == 'iodef' && ! \Froxlor\Validate\Validate::validateUrl($matches['url'])) {
$errors[] = $this->lng['error']['dns_content_invalid']; $errors[] = lng('error.dns_content_invalid');
} else { } else {
$content = $matches[0]; $content = $matches[0];
} }
@@ -177,18 +177,18 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$content .= '.' . $domain; $content .= '.' . $domain;
} }
if (! \Froxlor\Validate\Validate::validateDomain($content, true)) { if (! \Froxlor\Validate\Validate::validateDomain($content, true)) {
$errors[] = $this->lng['error']['dns_cname_invaliddom']; $errors[] = lng('error.dns_cname_invaliddom');
} else { } else {
// check whether there are RR-records for the same resource // check whether there are RR-records for the same resource
foreach ($dom_entries as $existing_entries) { 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) { 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; break;
} }
} }
// check www-alias setting // check www-alias setting
if ($result['wwwserveralias'] == '1' && $result['iswildcarddomain'] == '0' && $record == 'www') { 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) // append trailing dot (again)
@@ -197,7 +197,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$content = $content; $content = $content;
} elseif ($type == 'MX') { } elseif ($type == 'MX') {
if ($prio === null || $prio < 0) { if ($prio === null || $prio < 0) {
$errors[] = $this->lng['error']['dns_mx_prioempty']; $errors[] = lng('error.dns_mx_prioempty');
} }
// check for trailing dot // check for trailing dot
if (substr($content, - 1) == '.') { if (substr($content, - 1) == '.') {
@@ -205,17 +205,17 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$content = substr($content, 0, - 1); $content = substr($content, 0, - 1);
} }
if (! \Froxlor\Validate\Validate::validateDomain($content)) { if (! \Froxlor\Validate\Validate::validateDomain($content)) {
$errors[] = $this->lng['error']['dns_mx_needdom']; $errors[] = lng('error.dns_mx_needdom');
} else { } else {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource
foreach ($dom_entries as $existing_entries) { foreach ($dom_entries as $existing_entries) {
$fqdn = $existing_entries['record'] . '.' . $domain; $fqdn = $existing_entries['record'] . '.' . $domain;
if ($existing_entries['type'] == 'CNAME' && $fqdn == $content) { if ($existing_entries['type'] == 'CNAME' && $fqdn == $content) {
$errors[] = $this->lng['error']['dns_mx_noalias']; $errors[] = lng('error.dns_mx_noalias');
break; break;
} }
elseif ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { elseif ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) {
$errors[] = $this->lng['error']['dns_other_nomorerr']; $errors[] = lng('error.dns_other_nomorerr');
break; break;
} }
} }
@@ -229,12 +229,12 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$content = substr($content, 0, - 1); $content = substr($content, 0, - 1);
} }
if (! \Froxlor\Validate\Validate::validateDomain($content)) { if (! \Froxlor\Validate\Validate::validateDomain($content)) {
$errors[] = $this->lng['error']['dns_ns_invaliddom']; $errors[] = lng('error.dns_ns_invaliddom');
} else { } else {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource
foreach ($dom_entries as $existing_entries) { foreach ($dom_entries as $existing_entries) {
if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) { if ($existing_entries['type'] == 'CNAME' && $existing_entries['record'] == $record) {
$errors[] = $this->lng['error']['dns_other_nomorerr']; $errors[] = lng('error.dns_other_nomorerr');
break; break;
} }
} }
@@ -245,14 +245,14 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$content = $content; $content = $content;
} elseif ($type == 'SRV') { } elseif ($type == 'SRV') {
if ($prio === null || $prio < 0) { 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: // check only last part of content, as it can look like:
// _service._proto.name. TTL class SRV priority weight port target. // _service._proto.name. TTL class SRV priority weight port target.
$_split_content = explode(" ", $content); $_split_content = explode(" ", $content);
// SRV content must be [weight] [port] [target] // SRV content must be [weight] [port] [target]
if (count($_split_content) != 3) { 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]); $target = trim($_split_content[count($_split_content) - 1]);
if ($target != '.') { if ($target != '.') {
@@ -263,13 +263,13 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
} }
} }
if ($target != '.' && ! \Froxlor\Validate\Validate::validateDomain($target, true)) { if ($target != '.' && ! \Froxlor\Validate\Validate::validateDomain($target, true)) {
$errors[] = $this->lng['error']['dns_srv_needdom']; $errors[] = lng('error.dns_srv_needdom');
} else { } else {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource
foreach ($dom_entries as $existing_entries) { foreach ($dom_entries as $existing_entries) {
$fqdn = $existing_entries['record'] . '.' . $domain; $fqdn = $existing_entries['record'] . '.' . $domain;
if ($existing_entries['type'] == 'CNAME' && $fqdn == $target) { if ($existing_entries['type'] == 'CNAME' && $fqdn == $target) {
$errors[] = $this->lng['error']['dns_srv_noalias']; $errors[] = lng('error.dns_srv_noalias');
break; break;
} }
} }
@@ -312,7 +312,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$new = json_encode($new_entry); $new = json_encode($new_entry);
// compare // compare
if ($check_entry === $new) { if ($check_entry === $new) {
$errors[] = $this->lng['error']['dns_duplicate_entry']; $errors[] = lng('error.dns_duplicate_entry');
unset($check_entry); unset($check_entry);
break; break;
} }

View File

@@ -207,9 +207,9 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
)); ));
// get template for mail subject // 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 // 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; $_mailerror = false;
$mailerr_msg = ""; $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 // customer wants to send the e-mail to an alternative email address too
if (Settings::Get('panel.sendalternativemail') == 1 && ! empty($alternative_email)) { if (Settings::Get('panel.sendalternativemail') == 1 && ! empty($alternative_email)) {
// get template for mail subject // 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 // 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; $_mailerror = false;
try { try {

View File

@@ -63,7 +63,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
} }
if (empty($configs)) { if (empty($configs)) {
$configs[] = $this->lng['admin']['phpsettings']['notused']; $configs[] = lng('admin.phpsettings.notused');
} }
$row['configs'] = $configs; $row['configs'] = $configs;

View File

@@ -249,9 +249,9 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
'USR_PATH' => \Froxlor\FileDir::makeCorrectDir(str_replace($customer['documentroot'], "/", $path)) 'USR_PATH' => \Froxlor\FileDir::makeCorrectDir(str_replace($customer['documentroot'], "/", $path))
); );
// get template for mail subject // 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 // 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; $_mailerror = false;
$mailerr_msg = ""; $mailerr_msg = "";

View File

@@ -68,7 +68,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
} }
// validate whether the dbserver exists // 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::needRoot(true, $dbserver);
Database::needSqlData(); Database::needSqlData();
$sql_root = Database::getSqlData(); $sql_root = Database::getSqlData();
@@ -124,7 +124,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// send info-mail? // send info-mail?
if ($sendinfomail == 1) { if ($sendinfomail == 1) {
$pma = $this->lng['admin']['notgiven']; $pma = lng('admin.notgiven');
if (Settings::Get('panel.phpmyadmin_url') != '') { if (Settings::Get('panel.phpmyadmin_url') != '') {
$pma = 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 // 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 // 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; $_mailerror = false;
$mailerr_msg = ""; $mailerr_msg = "";

View File

@@ -23,6 +23,8 @@
* @license http://files.froxlor.org/misc/COPYING.txt GPLv2 * @license http://files.froxlor.org/misc/COPYING.txt GPLv2
*/ */
use Froxlor\Language;
function view($template, $attributes) function view($template, $attributes)
{ {
$view = file_get_contents(dirname(__DIR__) . '/templates/' . $template); $view = file_get_contents(dirname(__DIR__) . '/templates/' . $template);
@@ -32,5 +34,5 @@ function view($template, $attributes)
function lng(string $identifier, array $arguments = []) function lng(string $identifier, array $arguments = [])
{ {
return \Froxlor\Language::getTranslation($identifier, $arguments); return Language::getTranslation($identifier, $arguments);
} }