make lng, version, dbversion and branding protected variables of ApiCommand to avoid the need of 'global' statement
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -60,6 +60,34 @@ abstract class ApiCommand
|
|||||||
*/
|
*/
|
||||||
private $cmd_params = null;
|
private $cmd_params = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* language strings array
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $lng = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* froxlor version
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $version = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* froxlor dbversion
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $dbversion = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* froxlor version-branding
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $branding = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param array $header
|
* @param array $header
|
||||||
@@ -73,8 +101,11 @@ abstract class ApiCommand
|
|||||||
*/
|
*/
|
||||||
public function __construct($header = null, $params = null, $userinfo = null)
|
public function __construct($header = null, $params = null, $userinfo = null)
|
||||||
{
|
{
|
||||||
global $lng;
|
global $lng, $version, $dbversion, $branding;
|
||||||
|
|
||||||
|
$this->version = $version;
|
||||||
|
$this->dbversion = $dbversion;
|
||||||
|
$this->branding = $branding;
|
||||||
$this->cmd_params = $params;
|
$this->cmd_params = $params;
|
||||||
if (! empty($header)) {
|
if (! empty($header)) {
|
||||||
$this->readUserData($header);
|
$this->readUserData($header);
|
||||||
@@ -93,6 +124,7 @@ abstract class ApiCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->initLang();
|
$this->initLang();
|
||||||
|
$this->lng = $lng;
|
||||||
$this->initMail();
|
$this->initMail();
|
||||||
|
|
||||||
if ($this->debug) {
|
if ($this->debug) {
|
||||||
|
|||||||
@@ -438,37 +438,37 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
// 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($lng['error']['setlessthanalreadyused'], 'customers');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'domains');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'diskspace');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'traffic');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'emails');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'email accounts');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'email forwarders');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'email quota');
|
$res_warning .= sprintf($this->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($lng['error']['setlessthanalreadyused'], 'ftps');
|
$res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'ftps');
|
||||||
}
|
}
|
||||||
if ($tickets != $result['tickets'] && $tickets != -1 && $tickets < $result['tickets_used']) {
|
if ($tickets != $result['tickets'] && $tickets != -1 && $tickets < $result['tickets_used']) {
|
||||||
$res_warning .= sprintf($lng['error']['setlessthanalreadyused'], 'tickets');
|
$res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'tickets');
|
||||||
}
|
}
|
||||||
if ($mysqls != $result['mysqls'] && $mysqls != -1 && $mysqls < $result['mysqls_used']) {
|
if ($mysqls != $result['mysqls'] && $mysqls != -1 && $mysqls < $result['mysqls_used']) {
|
||||||
$res_warning .= sprintf($lng['error']['setlessthanalreadyused'], 'mysqls');
|
$res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'mysqls');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($res_warning)) {
|
if (!empty($res_warning)) {
|
||||||
|
|||||||
@@ -97,8 +97,6 @@ class Customers extends ApiCommand implements ResourceEntity
|
|||||||
|
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
global $lng;
|
|
||||||
|
|
||||||
if ($this->isAdmin()) {
|
if ($this->isAdmin()) {
|
||||||
if ($this->getUserDetail('customers_used') < $this->getUserDetail('customers') || $this->getUserDetail('customers') == '-1') {
|
if ($this->getUserDetail('customers_used') < $this->getUserDetail('customers') || $this->getUserDetail('customers') == '-1') {
|
||||||
|
|
||||||
@@ -600,7 +598,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
|||||||
'adminid' => $this->getUserDetail('adminid'),
|
'adminid' => $this->getUserDetail('adminid'),
|
||||||
'deflang' => $def_language
|
'deflang' => $def_language
|
||||||
), true, true);
|
), true, true);
|
||||||
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $lng['mails']['createcustomer']['subject']), $replace_arr));
|
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['createcustomer']['subject']), $replace_arr));
|
||||||
|
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
||||||
@@ -609,7 +607,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
|||||||
'adminid' => $this->getUserDetail('adminid'),
|
'adminid' => $this->getUserDetail('adminid'),
|
||||||
'deflang' => $def_language
|
'deflang' => $def_language
|
||||||
), true, true);
|
), true, true);
|
||||||
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $lng['mails']['createcustomer']['mailbody']), $replace_arr));
|
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $this->lng['mails']['createcustomer']['mailbody']), $replace_arr));
|
||||||
|
|
||||||
$_mailerror = false;
|
$_mailerror = false;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($configs)) {
|
if (empty($configs)) {
|
||||||
$configs[] = $lng['admin']['phpsettings']['notused'];
|
$configs[] = $this->lng['admin']['phpsettings']['notused'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$row['configs'] = $configs;
|
$row['configs'] = $configs;
|
||||||
|
|||||||
@@ -26,14 +26,12 @@ class Froxlor extends ApiCommand
|
|||||||
*/
|
*/
|
||||||
public function checkUpdate()
|
public function checkUpdate()
|
||||||
{
|
{
|
||||||
global $version, $branding;
|
|
||||||
|
|
||||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||||
// log our actions
|
// log our actions
|
||||||
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
|
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
|
||||||
|
|
||||||
// check for new version
|
// check for new version
|
||||||
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $version);
|
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $this->version);
|
||||||
$latestversion = HttpClient::urlGet(UPDATE_URI);
|
$latestversion = HttpClient::urlGet(UPDATE_URI);
|
||||||
$latestversion = explode('|', $latestversion);
|
$latestversion = explode('|', $latestversion);
|
||||||
|
|
||||||
@@ -44,7 +42,7 @@ class Froxlor extends ApiCommand
|
|||||||
|
|
||||||
// add the branding so debian guys are not gettings confused
|
// add the branding so debian guys are not gettings confused
|
||||||
// about their version-number
|
// about their version-number
|
||||||
$version_label = $_version . $branding;
|
$version_label = $_version . $this->branding;
|
||||||
$version_link = $_link;
|
$version_link = $_link;
|
||||||
$message_addinfo = $_message;
|
$message_addinfo = $_message;
|
||||||
|
|
||||||
@@ -53,7 +51,7 @@ class Froxlor extends ApiCommand
|
|||||||
// check for customized version to not output
|
// check for customized version to not output
|
||||||
// "There is a newer version of froxlor" besides the error-message
|
// "There is a newer version of froxlor" besides the error-message
|
||||||
$isnewerversion = - 1;
|
$isnewerversion = - 1;
|
||||||
} elseif (version_compare2($version, $_version) == - 1) {
|
} elseif (version_compare2($this->version, $_version) == - 1) {
|
||||||
// there is a newer version - yay
|
// there is a newer version - yay
|
||||||
$isnewerversion = 1;
|
$isnewerversion = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -64,7 +62,7 @@ class Froxlor extends ApiCommand
|
|||||||
// anzeige über version-status mit ggfls. formular
|
// anzeige über version-status mit ggfls. formular
|
||||||
// zum update schritt #1 -> download
|
// zum update schritt #1 -> download
|
||||||
if ($isnewerversion == 1) {
|
if ($isnewerversion == 1) {
|
||||||
$text = 'There is a newer version available: "' . $_version . '" (Your current version is: ' . $version . ')';
|
$text = 'There is a newer version available: "' . $_version . '" (Your current version is: ' . $this->version . ')';
|
||||||
return $this->response(200, "successfull", array(
|
return $this->response(200, "successfull", array(
|
||||||
'message' => $text,
|
'message' => $text,
|
||||||
'link' => $version_link,
|
'link' => $version_link,
|
||||||
@@ -82,13 +80,15 @@ class Froxlor extends ApiCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @TODO import settings
|
*
|
||||||
|
* @todo import settings
|
||||||
*/
|
*/
|
||||||
public function importSettings()
|
public function importSettings()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @TODO export settings to file
|
*
|
||||||
|
* @todo export settings to file
|
||||||
*/
|
*/
|
||||||
public function exportSettings()
|
public function exportSettings()
|
||||||
{}
|
{}
|
||||||
@@ -100,6 +100,7 @@ class Froxlor extends ApiCommand
|
|||||||
*/
|
*/
|
||||||
public function listSettings()
|
public function listSettings()
|
||||||
{
|
{
|
||||||
|
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||||
$sel_stmt = Database::prepare("
|
$sel_stmt = Database::prepare("
|
||||||
SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` ORDER BY settinggroup ASC, varname ASC
|
SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` ORDER BY settinggroup ASC, varname ASC
|
||||||
");
|
");
|
||||||
@@ -116,6 +117,8 @@ class Froxlor extends ApiCommand
|
|||||||
'list' => $result
|
'list' => $result
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
throw new Exception("Not allowed to execute given command.", 403);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a setting by settinggroup.varname couple
|
* return a setting by settinggroup.varname couple
|
||||||
@@ -148,6 +151,9 @@ class Froxlor extends ApiCommand
|
|||||||
*/
|
*/
|
||||||
public function updateSetting()
|
public function updateSetting()
|
||||||
{
|
{
|
||||||
|
// currently not implemented as it required validation too so no wrong settings are being stored via API
|
||||||
|
throw new Exception("Not available yet.", 501);
|
||||||
|
|
||||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||||
$setting = $this->getParam('key');
|
$setting = $this->getParam('key');
|
||||||
$value = $this->getParam('value', true, '');
|
$value = $this->getParam('value', true, '');
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($domains)) {
|
if (empty($domains)) {
|
||||||
$domains[] = $lng['admin']['phpsettings']['notused'];
|
$domains[] = $this->lng['admin']['phpsettings']['notused'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether this is our default config
|
// check whether this is our default config
|
||||||
|
|||||||
Reference in New Issue
Block a user