put Api-Commands into namespaces

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-18 09:46:36 +01:00
parent c7e5df95e7
commit 4c27efa4ae
30 changed files with 831 additions and 667 deletions

View File

@@ -1,8 +1,8 @@
<?php <?php
require __DIR__ . '/lib/classes/api/api_includes.inc.php'; require __DIR__ . '/vendor/autoload.php';
// check whether API interface is enabled after all // check whether API interface is enabled after all
if (Settings::Get('api.enabled') != 1) { if (\Froxlor\Settings::Get('api.enabled') != 1) {
// not enabled // not enabled
header("Status: 404 Not found", 404); header("Status: 404 Not found", 404);
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not found", 404); header($_SERVER["SERVER_PROTOCOL"] . " 404 Not found", 404);
@@ -30,9 +30,9 @@ if (is_null($decoded_request)) {
// validate content // validate content
try { try {
$request = FroxlorRPC::validateRequest($decoded_request); $request = \Froxlor\Api\FroxlorRPC::validateRequest($decoded_request);
// now actually do it // now actually do it
$cls = $request['command']['class']; $cls = "\Froxlor\Api\Commands\\" . $request['command']['class'];
$method = $request['command']['method']; $method = $request['command']['method'];
$apiObj = new $cls($decoded_request['header'], $request['params']); $apiObj = new $cls($decoded_request['header'], $request['params']);
// call the method with the params if any // call the method with the params if any

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\Api;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -42,14 +43,14 @@ abstract class ApiCommand extends ApiParameter
/** /**
* logger interface * logger interface
* *
* @var FroxlorLogger * @var \FroxlorLogger
*/ */
private $logger = null; private $logger = null;
/** /**
* mail interface * mail interface
* *
* @var PHPMailer * @var \PHPMailer
*/ */
private $mail = null; private $mail = null;
@@ -90,11 +91,11 @@ abstract class ApiCommand extends ApiParameter
* @param array $userinfo * @param array $userinfo
* optional, passed via WebInterface (instead of $header) * optional, passed via WebInterface (instead of $header)
* *
* @throws Exception * @throws \Exception
*/ */
public function __construct($header = null, $params = null, $userinfo = null) public function __construct($header = null, $params = null, $userinfo = null)
{ {
global $lng, $version, $dbversion, $branding; global $version, $dbversion, $branding;
parent::__construct($params); parent::__construct($params);
@@ -108,14 +109,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 = 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(LOG_ERROR, LOG_INFO, "[API] User '" . $this->getUserDetail('loginnname') . "' tried to use API but is deactivated"); $this->logger()->logAction(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();
@@ -135,17 +136,17 @@ abstract class ApiCommand extends ApiParameter
global $lng; global $lng;
// query the whole table // query the whole table
$result_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_LANGUAGE . "`"); $result_stmt = \Froxlor\Database\Database::query("SELECT * FROM `" . TABLE_PANEL_LANGUAGE . "`");
$langs = array(); $langs = array();
// presort languages // presort languages
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$langs[$row['language']][] = $row; $langs[$row['language']][] = $row;
} }
// set default language before anything else to // set default language before anything else to
// ensure that we can display messages // ensure that we can display messages
$language = Settings::Get('panel.standardlanguage'); $language = \Froxlor\Settings::Get('panel.standardlanguage');
if (isset($this->user_data['language']) && isset($langs[$this->user_data['language']])) { if (isset($this->user_data['language']) && isset($langs[$this->user_data['language']])) {
// default: use language from session, #277 // default: use language from session, #277
@@ -156,14 +157,14 @@ abstract class ApiCommand extends ApiParameter
// include every english language file we can get // include every english language file we can get
foreach ($langs['English'] as $value) { foreach ($langs['English'] as $value) {
include_once makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']); include_once \Froxlor\FileDir::makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']);
} }
// now include the selected language if its not english // now include the selected language if its not english
if ($language != 'English') { if ($language != 'English') {
if (isset($langs[$language])) { if (isset($langs[$language])) {
foreach ($langs[$language] as $value) { foreach ($langs[$language] as $value) {
include_once makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']); include_once \Froxlor\FileDir::makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']);
} }
} else { } else {
if ($this->debug) { if ($this->debug) {
@@ -181,35 +182,36 @@ abstract class ApiCommand extends ApiParameter
/** /**
* initialize mail interface so an API wide mail-object is available * initialize mail interface so an API wide mail-object is available
* @throws phpmailerException *
* @throws \phpmailerException
*/ */
private function initMail() private function initMail()
{ {
/** /**
* Initialize the mailingsystem * Initialize the mailingsystem
*/ */
$this->mail = new PHPMailer(true); $this->mail = new \PHPMailer(true);
$this->mail->CharSet = "UTF-8"; $this->mail->CharSet = "UTF-8";
if (Settings::Get('system.mail_use_smtp')) { if (\Froxlor\Settings::Get('system.mail_use_smtp')) {
$this->mail->isSMTP(); $this->mail->isSMTP();
$this->mail->Host = Settings::Get('system.mail_smtp_host'); $this->mail->Host = \Froxlor\Settings::Get('system.mail_smtp_host');
$this->mail->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false; $this->mail->SMTPAuth = \Froxlor\Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
$this->mail->Username = Settings::Get('system.mail_smtp_user'); $this->mail->Username = \Froxlor\Settings::Get('system.mail_smtp_user');
$this->mail->Password = Settings::Get('system.mail_smtp_passwd'); $this->mail->Password = \Froxlor\Settings::Get('system.mail_smtp_passwd');
if (Settings::Get('system.mail_smtp_usetls')) { if (\Froxlor\Settings::Get('system.mail_smtp_usetls')) {
$this->mail->SMTPSecure = 'tls'; $this->mail->SMTPSecure = 'tls';
} else { } else {
$this->mail->SMTPAutoTLS = false; $this->mail->SMTPAutoTLS = false;
} }
$this->mail->Port = Settings::Get('system.mail_smtp_port'); $this->mail->Port = \Froxlor\Settings::Get('system.mail_smtp_port');
} }
if ( PHPMailer::validateAddress(Settings::Get('panel.adminmail')) !== false) { if (\PHPMailer::validateAddress(\Froxlor\Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76 // set return-to address and custom sender-name, see #76
$this->mail->setFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname')); $this->mail->setFrom(\Froxlor\Settings::Get('panel.adminmail'), \Froxlor\Settings::Get('panel.adminmail_defname'));
if (Settings::Get('panel.adminmail_return') != '') { if (\Froxlor\Settings::Get('panel.adminmail_return') != '') {
$this->mail->addReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname')); $this->mail->addReplyTo(\Froxlor\Settings::Get('panel.adminmail_return'), \Froxlor\Settings::Get('panel.adminmail_defname'));
} }
} }
} }
@@ -225,7 +227,7 @@ abstract class ApiCommand extends ApiParameter
* array of parameters for the command * array of parameters for the command
* *
* @return ApiCommand * @return ApiCommand
* @throws Exception * @throws \Exception
*/ */
public static function getLocal($userinfo = null, $params = null) public static function getLocal($userinfo = null, $params = null)
{ {
@@ -267,7 +269,7 @@ abstract class ApiCommand extends ApiParameter
/** /**
* return logger instance * return logger instance
* *
* @return FroxlorLogger * @return \FroxlorLogger
*/ */
protected function logger() protected function logger()
{ {
@@ -277,7 +279,7 @@ abstract class ApiCommand extends ApiParameter
/** /**
* return mailer instance * return mailer instance
* *
* @return PHPMailer * @return \PHPMailer
*/ */
protected function mailer() protected function mailer()
{ {
@@ -295,7 +297,7 @@ abstract class ApiCommand extends ApiParameter
protected function apiCall($command = null, $params = null) protected function apiCall($command = null, $params = null)
{ {
$_command = explode(".", $command); $_command = explode(".", $command);
$module = $_command[0]; $module = __NAMESPACE__ . "\Commands\\" . $_command[0];
$function = $_command[1]; $function = $_command[1];
$json_result = $module::getLocal($this->getUserData(), $params)->{$function}(); $json_result = $module::getLocal($this->getUserData(), $params)->{$function}();
return json_decode($json_result, true)['data']; return json_decode($json_result, true)['data'];
@@ -335,7 +337,7 @@ abstract class ApiCommand extends ApiParameter
* @param string $customer_hide_option * @param string $customer_hide_option
* optional, when called as customer, some options might be hidden due to the panel.customer_hide_options ettings * optional, when called as customer, some options might be hidden due to the panel.customer_hide_options ettings
* *
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
protected function getAllowedCustomerIds($customer_hide_option = '') protected function getAllowedCustomerIds($customer_hide_option = '')
@@ -363,15 +365,15 @@ abstract class ApiCommand extends ApiParameter
$customer_ids[] = $customer['customerid']; $customer_ids[] = $customer['customerid'];
} }
} else { } else {
if (! empty($customer_hide_option) && Settings::IsInList('panel.customer_hide_options', $customer_hide_option)) { if (! empty($customer_hide_option) && \Froxlor\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;
} }
@@ -386,7 +388,7 @@ abstract class ApiCommand extends ApiParameter
* @param string $customer_resource_check * @param string $customer_resource_check
* optional, when called as admin, check the resources of the target customer * optional, when called as admin, check the resources of the target customer
* *
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
protected function getCustomerData($customer_resource_check = '') protected function getCustomerData($customer_resource_check = '')
@@ -400,7 +402,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();
@@ -420,12 +422,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 = Database::prepare(" $stmt = \Froxlor\Database\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
"); ");
Database::pexecute($stmt, array( \Froxlor\Database\Database::pexecute($stmt, array(
'key' => $key 'key' => $key
), true, true); ), true, true);
} }
@@ -444,16 +446,17 @@ 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 = Database::prepare(" $stmt = \Froxlor\Database\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 = Database::pexecute_first($stmt, array( $result = \Froxlor\Database\Database::pexecute_first($stmt, array(
"adminid" => $customerdata['adminid'], "adminid" => $customerdata['adminid'],
"lang" => $customerdata['def_language'], "lang" => $customerdata['def_language'],
"group" => $group, "group" => $group,
"var" => $varname "var" => $varname
), true, true); ), true, true);
// @fixme html_entity_decode
$content = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default), $replace_arr)); $content = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default), $replace_arr));
return $content; return $content;
} }
@@ -464,13 +467,13 @@ abstract class ApiCommand extends ApiParameter
* @param array $header * @param array $header
* api-request header * api-request header
* *
* @throws Exception * @throws \Exception
* @return boolean * @return boolean
*/ */
private function readUserData($header = null) private function readUserData($header = null)
{ {
$sel_stmt = Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as"); $sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
$result = Database::pexecute_first($sel_stmt, array( $result = \Froxlor\Database\Database::pexecute_first($sel_stmt, array(
'ak' => $header['apikey'], 'ak' => $header['apikey'],
'as' => $header['secret'] 'as' => $header['secret']
), true, true); ), true, true);
@@ -486,10 +489,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 = Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id"); $sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id");
$this->user_data = Database::pexecute_first($sel_stmt, array( $this->user_data = \Froxlor\Database\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) {
@@ -497,6 +500,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,4 +1,5 @@
<?php <?php
namespace Froxlor\Api;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -30,7 +31,7 @@ abstract class ApiParameter
* @param array $params * @param array $params
* optional, array of parameters (var=>value) for the command * optional, array of parameters (var=>value) for the command
* *
* @throws Exception * @throws \Exception
*/ */
public function __construct($params = null) public function __construct($params = null)
{ {
@@ -52,7 +53,7 @@ abstract class ApiParameter
* @param mixed $default * @param mixed $default
* value which is returned if optional=true and param is not set * value which is returned if optional=true and param is not set
* *
* @throws Exception * @throws \Exception
* @return mixed * @return mixed
*/ */
protected function getParam($param = null, $optional = false, $default = '') protected function getParam($param = null, $optional = false, $default = '')
@@ -62,7 +63,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;
} }
@@ -71,7 +72,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 '';
} }
@@ -117,7 +118,7 @@ abstract class ApiParameter
* value which is returned if optional=true and param is not set * value which is returned if optional=true and param is not set
* *
* @return mixed * @return mixed
* @throws Exception * @throws \Exception
*/ */
protected function getUlParam($param = null, $ul_field = null, $optional = false, $default = 0) protected function getUlParam($param = null, $ul_field = null, $optional = false, $default = 0)
{ {

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,14 +19,14 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Admins extends ApiCommand implements ResourceEntity class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* lists all admin entries * lists all admin entries
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -36,7 +40,7 @@ class Admins extends ApiCommand implements ResourceEntity
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
$result = array(); $result = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
return $this->response(200, "successfull", array( return $this->response(200, "successfull", array(
@@ -44,7 +48,7 @@ class Admins extends ApiCommand implements ResourceEntity
'list' => $result 'list' => $result
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -56,7 +60,7 @@ class Admins extends ApiCommand implements ResourceEntity
* optional, the loginname * optional, the loginname
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -78,9 +82,9 @@ class Admins extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "loginname '" . $loginname . "'"); $key = ($id > 0 ? "id #" . $id : "loginname '" . $loginname . "'");
throw new Exception("Admin with " . $key . " could not be found", 404); throw new \Exception("Admin with " . $key . " could not be found", 404);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -159,7 +163,7 @@ class Admins extends ApiCommand implements ResourceEntity
* optional, list of ip-address id's; default -1 (all IP's) * optional, list of ip-address id's; default -1 (all IP's)
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -199,7 +203,8 @@ class Admins extends ApiCommand implements ResourceEntity
// validation // validation
$name = validate($name, 'name', '', '', array(), true); $name = validate($name, 'name', '', '', array(), true);
$idna_convert = new idna_convert_wrapper(); // @fixme idna_convert_wrapper
$idna_convert = new \idna_convert_wrapper();
$email = $idna_convert->encode(validate($email, 'email', '', '', array(), true)); $email = $idna_convert->encode(validate($email, 'email', '', '', array(), true));
$def_language = validate($def_language, 'default language', '', '', array(), true); $def_language = validate($def_language, 'default language', '', '', array(), true);
$custom_notes = validate(str_replace("\r\n", "\n", $custom_notes), 'custom_notes', '/^[^\0]*$/', '', array(), true); $custom_notes = validate(str_replace("\r\n", "\n", $custom_notes), 'custom_notes', '/^[^\0]*$/', '', array(), true);
@@ -348,7 +353,7 @@ class Admins extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -436,7 +441,7 @@ class Admins extends ApiCommand implements ResourceEntity
* optional, list of ip-address id's; default -1 (all IP's) * optional, list of ip-address id's; default -1 (all IP's)
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -456,7 +461,8 @@ class Admins extends ApiCommand implements ResourceEntity
if ($this->getUserDetail('change_serversettings') == 1 || $result['adminid'] == $this->getUserDetail('adminid')) { if ($this->getUserDetail('change_serversettings') == 1 || $result['adminid'] == $this->getUserDetail('adminid')) {
// parameters // parameters
$name = $this->getParam('name', true, $result['name']); $name = $this->getParam('name', true, $result['name']);
$idna_convert = new idna_convert_wrapper(); // @fixme idna_convert_wrapper
$idna_convert = new \idna_convert_wrapper();
$email = $this->getParam('email', true, $idna_convert->decode($result['email'])); $email = $this->getParam('email', true, $idna_convert->decode($result['email']));
$password = $this->getParam('admin_password', true, ''); $password = $this->getParam('admin_password', true, '');
$def_language = $this->getParam('def_language', true, $result['def_language']); $def_language = $this->getParam('def_language', true, $result['def_language']);
@@ -515,7 +521,8 @@ class Admins extends ApiCommand implements ResourceEntity
// validation // validation
$name = validate($name, 'name', '', '', array(), true); $name = validate($name, 'name', '', '', array(), true);
$idna_convert = new idna_convert_wrapper(); // @fixme idna_convert_wrapper
$idna_convert = new \idna_convert_wrapper();
$email = $idna_convert->encode(validate($email, 'email', '', '', array(), true)); $email = $idna_convert->encode(validate($email, 'email', '', '', array(), true));
$def_language = validate($def_language, 'default language', '', '', array(), true); $def_language = validate($def_language, 'default language', '', '', array(), true);
$custom_notes = validate(str_replace("\r\n", "\n", $custom_notes), 'custom_notes', '/^[^\0]*$/', '', array(), true); $custom_notes = validate(str_replace("\r\n", "\n", $custom_notes), 'custom_notes', '/^[^\0]*$/', '', array(), true);
@@ -607,7 +614,7 @@ class Admins extends ApiCommand implements ResourceEntity
} }
if (! empty($res_warning)) { if (! empty($res_warning)) {
throw new Exception($res_warning, 406); throw new \Exception($res_warning, 406);
} }
$upd_data = array( $upd_data = array(
@@ -681,7 +688,7 @@ class Admins extends ApiCommand implements ResourceEntity
} }
} }
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -693,7 +700,7 @@ class Admins extends ApiCommand implements ResourceEntity
* optional, the loginname * optional, the loginname
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -781,7 +788,7 @@ class Admins extends ApiCommand implements ResourceEntity
updateCounters(); updateCounters();
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -793,7 +800,7 @@ class Admins extends ApiCommand implements ResourceEntity
* optional, the loginname * optional, the loginname
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function unlock() public function unlock()
@@ -823,7 +830,7 @@ class Admins extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] unlocked admin '" . $result['loginname'] . "'"); $this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] unlocked admin '" . $result['loginname'] . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Certificates extends ApiCommand implements ResourceEntity class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -33,7 +37,7 @@ class Certificates extends ApiCommand implements ResourceEntity
* optional * optional
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -43,7 +47,7 @@ class Certificates extends ApiCommand implements ResourceEntity
$domainname = $this->getParam('domainname', $dn_optional, ''); $domainname = $this->getParam('domainname', $dn_optional, '');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$domain = $this->apiCall('SubDomains.get', array( $domain = $this->apiCall('SubDomains.get', array(
@@ -70,7 +74,7 @@ class Certificates extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Domain '" . $domain['domain'] . "' already has a certificate. Did you mean to call update?", 406); throw new \Exception("Domain '" . $domain['domain'] . "' already has a certificate. Did you mean to call update?", 406);
} }
/** /**
@@ -82,7 +86,7 @@ class Certificates extends ApiCommand implements ResourceEntity
* optional, the domainname * optional, the domainname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -92,7 +96,7 @@ class Certificates extends ApiCommand implements ResourceEntity
$domainname = $this->getParam('domainname', $dn_optional, ''); $domainname = $this->getParam('domainname', $dn_optional, '');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$domain = $this->apiCall('SubDomains.get', array( $domain = $this->apiCall('SubDomains.get', array(
@@ -124,7 +128,7 @@ class Certificates extends ApiCommand implements ResourceEntity
* optional * optional
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -134,7 +138,7 @@ class Certificates extends ApiCommand implements ResourceEntity
$domainname = $this->getParam('domainname', $dn_optional, ''); $domainname = $this->getParam('domainname', $dn_optional, '');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$domain = $this->apiCall('SubDomains.get', array( $domain = $this->apiCall('SubDomains.get', array(
@@ -159,7 +163,7 @@ class Certificates extends ApiCommand implements ResourceEntity
* lists all certificate entries * lists all certificate entries
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -187,7 +191,7 @@ class Certificates extends ApiCommand implements ResourceEntity
$certs_stmt = Database::prepare($certs_stmt_query); $certs_stmt = Database::prepare($certs_stmt_query);
Database::pexecute($certs_stmt, $qry_params, true, true); Database::pexecute($certs_stmt, $qry_params, true, true);
$result = array(); $result = array();
while ($cert = $certs_stmt->fetch(PDO::FETCH_ASSOC)) { while ($cert = $certs_stmt->fetch(\PDO::FETCH_ASSOC)) {
// respect froxlor-hostname // respect froxlor-hostname
if ($cert['domainid'] == 0) { if ($cert['domainid'] == 0) {
$cert['domain'] = Settings::Get('system.hostname'); $cert['domain'] = Settings::Get('system.hostname');
@@ -208,7 +212,7 @@ class Certificates extends ApiCommand implements ResourceEntity
* @param int $id * @param int $id
* *
* @return array * @return array
* @throws Exception * @throws \Exception
*/ */
public function delete() public function delete()
{ {
@@ -263,7 +267,7 @@ class Certificates extends ApiCommand implements ResourceEntity
* optional default false * optional default false
* *
* @return boolean * @return boolean
* @throws Exception * @throws \Exception
*/ */
private function addOrUpdateCertificate($domainid = 0, $ssl_cert_file = '', $ssl_key_file = '', $ssl_ca_file = '', $ssl_cert_chainfile = '', $do_insert = false) private function addOrUpdateCertificate($domainid = 0, $ssl_cert_file = '', $ssl_key_file = '', $ssl_ca_file = '', $ssl_cert_chainfile = '', $do_insert = false)
{ {

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Cronjobs extends ApiCommand implements ResourceEntity class Cronjobs extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -23,7 +27,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
*/ */
public function add() public function add()
{ {
throw new Exception('You cannot add new cronjobs yet.', 303); throw new \Exception('You cannot add new cronjobs yet.', 303);
} }
/** /**
@@ -33,7 +37,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
* cronjob-id * cronjob-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -50,9 +54,9 @@ class Cronjobs extends ApiCommand implements ResourceEntity
if ($result) { if ($result) {
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("cronjob with id #" . $id . " could not be found", 404); throw new \Exception("cronjob with id #" . $id . " could not be found", 404);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -67,7 +71,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
* optional interval for the cronjob (MINUTE, HOUR, DAY, WEEK or MONTH) * optional interval for the cronjob (MINUTE, HOUR, DAY, WEEK or MONTH)
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -118,14 +122,14 @@ class Cronjobs extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
* lists all cronjob entries * lists all cronjob entries
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -137,7 +141,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
"); ");
Database::pexecute($result_stmt); Database::pexecute($result_stmt);
$result = array(); $result = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
return $this->response(200, "successfull", array( return $this->response(200, "successfull", array(
@@ -145,7 +149,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
'list' => $result 'list' => $result
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -153,6 +157,6 @@ class Cronjobs extends ApiCommand implements ResourceEntity
*/ */
public function delete() public function delete()
{ {
throw new Exception('You cannot delete system cronjobs.', 303); throw new \Exception('You cannot delete system cronjobs.', 303);
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,24 +19,24 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class CustomerBackups extends ApiCommand implements ResourceEntity class CustomerBackups extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* check whether backup is enabled systemwide and if accessable for customer (hide_options) * check whether backup is enabled systemwide and if accessable for customer (hide_options)
* *
* @throws Exception * @throws \Exception
*/ */
private function validateAccess() private function validateAccess()
{ {
if (Settings::Get('system.backupenabled') != 1) { if (Settings::Get('system.backupenabled') != 1) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.backup')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.backup')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
} }
@@ -52,7 +56,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
* *
* @access admin, customer * @access admin, customer
* @return array * @return array
* @throws Exception * @throws \Exception
*/ */
public function add() public function add()
{ {
@@ -114,7 +118,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
*/ */
public function get() public function get()
{ {
throw new Exception('You cannot get a planned backup. Try CustomerBackups.listing()', 303); throw new \Exception('You cannot get a planned backup. Try CustomerBackups.listing()', 303);
} }
/** /**
@@ -123,7 +127,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
*/ */
public function update() public function update()
{ {
throw new Exception('You cannot update a planned backup. You need to delete it and re-add it.', 303); throw new \Exception('You cannot update a planned backup. You need to delete it and re-add it.', 303);
} }
/** /**
@@ -135,7 +139,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
* optional, admin-only, select backup-jobs of a specific customer by loginname * optional, admin-only, select backup-jobs of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -148,7 +152,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
$sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20'"); $sel_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20'");
Database::pexecute($sel_stmt); Database::pexecute($sel_stmt);
$result = array(); $result = array();
while ($entry = $sel_stmt->fetch(PDO::FETCH_ASSOC)) { while ($entry = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
$entry['data'] = json_decode($entry['data'], true); $entry['data'] = json_decode($entry['data'], true);
if (in_array($entry['data']['customerid'], $customer_ids)) { if (in_array($entry['data']['customerid'], $customer_ids)) {
$result[] = $entry; $result[] = $entry;
@@ -172,7 +176,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
* optional, required when called as admin (if $customerid is not specified) * optional, required when called as admin (if $customerid is not specified)
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return bool * @return bool
*/ */
public function delete() public function delete()
@@ -197,6 +201,6 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
} }
} }
} }
throw new Exception('Backup job with id #' . $entry . ' could not be found', 404); throw new \Exception('Backup job with id #' . $entry . ' could not be found', 404);
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,14 +19,14 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Customers extends ApiCommand implements ResourceEntity class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* lists all customer entries * lists all customer entries
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -44,7 +48,7 @@ class Customers extends ApiCommand implements ResourceEntity
} }
Database::pexecute($result_stmt, $params, true, true); Database::pexecute($result_stmt, $params, true, true);
$result = array(); $result = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
return $this->response(200, "successfull", array( return $this->response(200, "successfull", array(
@@ -52,7 +56,7 @@ class Customers extends ApiCommand implements ResourceEntity
'list' => $result 'list' => $result
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -64,7 +68,7 @@ class Customers extends ApiCommand implements ResourceEntity
* optional, the loginname * optional, the loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -86,7 +90,7 @@ class Customers extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (($id > 0 && $id != $this->getUserDetail('customerid')) || ! empty($loginname) && $loginname != $this->getUserDetail('loginname')) { if (($id > 0 && $id != $this->getUserDetail('customerid')) || ! empty($loginname) && $loginname != $this->getUserDetail('loginname')) {
throw new Exception("You cannot access data of other customers", 401); throw new \Exception("You cannot access data of other customers", 401);
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "`
@@ -105,7 +109,7 @@ class Customers extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "loginname '" . $loginname . "'"); $key = ($id > 0 ? "id #" . $id : "loginname '" . $loginname . "'");
throw new Exception("Customer with " . $key . " could not be found", 404); throw new \Exception("Customer with " . $key . " could not be found", 404);
} }
/** /**
@@ -204,7 +208,7 @@ class Customers extends ApiCommand implements ResourceEntity
* optional, whether to store the default index file to customers homedir * optional, whether to store the default index file to customers homedir
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -263,7 +267,8 @@ class Customers extends ApiCommand implements ResourceEntity
$city = validate($city, 'city', '', '', array(), true); $city = validate($city, 'city', '', '', array(), true);
$phone = validate($phone, 'phone', '/^[0-9\- \+\(\)\/]*$/', '', array(), true); $phone = validate($phone, 'phone', '/^[0-9\- \+\(\)\/]*$/', '', array(), true);
$fax = validate($fax, 'fax', '/^[0-9\- \+\(\)\/]*$/', '', array(), true); $fax = validate($fax, 'fax', '/^[0-9\- \+\(\)\/]*$/', '', array(), true);
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$email = $idna_convert->encode(validate($email, 'email', '', '', array(), true)); $email = $idna_convert->encode(validate($email, 'email', '', '', array(), true));
$customernumber = validate($customernumber, 'customer number', '/^[A-Za-z0-9 \-]*$/Di', '', array(), true); $customernumber = validate($customernumber, 'customer number', '/^[A-Za-z0-9 \-]*$/Di', '', array(), true);
$def_language = validate($def_language, 'default language', '', '', array(), true); $def_language = validate($def_language, 'default language', '', '', array(), true);
@@ -639,7 +644,7 @@ class Customers extends ApiCommand implements ResourceEntity
try { try {
$std_domain = $this->apiCall('Domains.add', $ins_data); $std_domain = $this->apiCall('Domains.add', $ins_data);
$domainid = $std_domain['id']; $domainid = $std_domain['id'];
} catch (Exception $e) { } catch (\Exception $e) {
$this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to add standard-subdomain: " . $e->getMessage()); $this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to add standard-subdomain: " . $e->getMessage());
} }
@@ -713,10 +718,10 @@ class Customers extends ApiCommand implements ResourceEntity
'company' => $company 'company' => $company
))); )));
$this->mailer()->send(); $this->mailer()->send();
} catch (phpmailerException $e) { } catch (\phpmailerException $e) {
$mailerr_msg = $e->errorMessage(); $mailerr_msg = $e->errorMessage();
$_mailerror = true; $_mailerror = true;
} catch (Exception $e) { } catch (\Exception $e) {
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
@@ -737,9 +742,9 @@ class Customers extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -844,7 +849,7 @@ class Customers extends ApiCommand implements ResourceEntity
* optional, change theme * optional, change theme
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -863,7 +868,8 @@ class Customers extends ApiCommand implements ResourceEntity
// parameters // parameters
$move_to_admin = intval_ressource($this->getBoolParam('move_to_admin', true, 0)); $move_to_admin = intval_ressource($this->getBoolParam('move_to_admin', true, 0));
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$email = $this->getParam('email', true, $idna_convert->decode($result['email'])); $email = $this->getParam('email', true, $idna_convert->decode($result['email']));
$name = $this->getParam('name', true, $result['name']); $name = $this->getParam('name', true, $result['name']);
$firstname = $this->getParam('firstname', true, $result['firstname']); $firstname = $this->getParam('firstname', true, $result['firstname']);
@@ -911,7 +917,8 @@ class Customers extends ApiCommand implements ResourceEntity
// validation // validation
if ($this->isAdmin()) { if ($this->isAdmin()) {
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$name = validate($name, 'name', '', '', array(), true); $name = validate($name, 'name', '', '', array(), true);
$firstname = validate($firstname, 'first name', '', '', array(), true); $firstname = validate($firstname, 'first name', '', '', array(), true);
$company = validate($company, 'company', '', '', array(), true); $company = validate($company, 'company', '', '', array(), true);
@@ -991,7 +998,7 @@ class Customers extends ApiCommand implements ResourceEntity
try { try {
$std_domain = $this->apiCall('Domains.add', $ins_data); $std_domain = $this->apiCall('Domains.add', $ins_data);
$domainid = $std_domain['id']; $domainid = $std_domain['id'];
} catch (Exception $e) { } catch (\Exception $e) {
$this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to add standard-subdomain: " . $e->getMessage()); $this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to add standard-subdomain: " . $e->getMessage());
} }
@@ -1014,7 +1021,7 @@ class Customers extends ApiCommand implements ResourceEntity
'id' => $result['standardsubdomain'], 'id' => $result['standardsubdomain'],
'is_stdsubdomain' => 1 'is_stdsubdomain' => 1
)); ));
} catch (Exception $e) { } catch (\Exception $e) {
$this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to delete standard-subdomain: " . $e->getMessage()); $this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to delete standard-subdomain: " . $e->getMessage());
} }
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] automatically deleted standardsubdomain for user '" . $result['loginname'] . "'"); $this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] automatically deleted standardsubdomain for user '" . $result['loginname'] . "'");
@@ -1086,10 +1093,11 @@ class Customers extends ApiCommand implements ResourceEntity
Database::needRoot(true); Database::needRoot(true);
$last_dbserver = 0; $last_dbserver = 0;
$dbm = new DbManager($this->logger()); // @fixme dbManager
$dbm = new \DbManager($this->logger());
// For each of them // For each of them
while ($row_database = $databases_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row_database = $databases_stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($last_dbserver != $row_database['dbserver']) { if ($last_dbserver != $row_database['dbserver']) {
$dbm->getManager()->flushPrivileges(); $dbm->getManager()->flushPrivileges();
@@ -1377,7 +1385,7 @@ class Customers extends ApiCommand implements ResourceEntity
* optional, default false * optional, default false
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -1405,9 +1413,10 @@ class Customers extends ApiCommand implements ResourceEntity
Database::needRoot(true); Database::needRoot(true);
$last_dbserver = 0; $last_dbserver = 0;
$dbm = new DbManager($this->logger()); // @fixme db manager
$dbm = new \DbManager($this->logger());
while ($row_database = $databases_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row_database = $databases_stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($last_dbserver != $row_database['dbserver']) { if ($last_dbserver != $row_database['dbserver']) {
Database::needRoot(true, $row_database['dbserver']); Database::needRoot(true, $row_database['dbserver']);
$dbm->getManager()->flushPrivileges(); $dbm->getManager()->flushPrivileges();
@@ -1435,7 +1444,7 @@ class Customers extends ApiCommand implements ResourceEntity
Database::pexecute($did_stmt, array( Database::pexecute($did_stmt, array(
'id' => $id 'id' => $id
), true, true); ), true, true);
while ($row = $did_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $did_stmt->fetch(\PDO::FETCH_ASSOC)) {
// remove domain->ip connection // remove domain->ip connection
$stmt = Database::prepare("DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_domain` = :did"); $stmt = Database::prepare("DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_domain` = :did");
Database::pexecute($stmt, array( Database::pexecute($stmt, array(
@@ -1501,7 +1510,7 @@ class Customers extends ApiCommand implements ResourceEntity
Database::pexecute($result2_stmt, array( Database::pexecute($result2_stmt, array(
'id' => $id 'id' => $id
), true, true); ), true, true);
while ($row = $result2_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result2_stmt->fetch(\PDO::FETCH_ASSOC)) {
// delete ftp-quotatallies by username // delete ftp-quotatallies by username
$stmt = Database::prepare("DELETE FROM `" . TABLE_FTP_QUOTATALLIES . "` WHERE `name` = :name"); $stmt = Database::prepare("DELETE FROM `" . TABLE_FTP_QUOTATALLIES . "` WHERE `name` = :name");
Database::pexecute($stmt, array( Database::pexecute($stmt, array(
@@ -1595,11 +1604,12 @@ class Customers extends ApiCommand implements ResourceEntity
inserttask('10'); inserttask('10');
// move old tickets to archive // move old tickets to archive
$tickets = ticket::customerHasTickets($id); // @fixme ticket
$tickets = \ticket::customerHasTickets($id);
if ($tickets !== false && isset($tickets[0])) { if ($tickets !== false && isset($tickets[0])) {
foreach ($tickets as $ticket) { foreach ($tickets as $ticket) {
$now = time(); $now = time();
$mainticket = ticket::getInstanceOf($result, (int) $ticket); $mainticket = \ticket::getInstanceOf($result, (int) $ticket);
$mainticket->Set('lastchange', $now, true, true); $mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '1', true, true); $mainticket->Set('lastreplier', '1', true, true);
$mainticket->Set('status', '3', true, true); $mainticket->Set('status', '3', true, true);
@@ -1612,7 +1622,7 @@ class Customers extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] deleted customer '" . $result['loginname'] . "'"); $this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] deleted customer '" . $result['loginname'] . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -1624,7 +1634,7 @@ class Customers extends ApiCommand implements ResourceEntity
* optional, the loginname * optional, the loginname
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function unlock() public function unlock()
@@ -1654,7 +1664,7 @@ class Customers extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] unlocked customer '" . $result['loginname'] . "'"); $this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] unlocked customer '" . $result['loginname'] . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -1669,7 +1679,7 @@ class Customers extends ApiCommand implements ResourceEntity
* target-admin-id * target-admin-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function move() public function move()
@@ -1688,7 +1698,7 @@ class Customers extends ApiCommand implements ResourceEntity
// check if target-admin is the current admin // check if target-admin is the current admin
if ($adminid == $c_result['adminid']) { if ($adminid == $c_result['adminid']) {
throw new Exception("Cannot move customer to the same admin/reseller as he currently is assigned to", 406); throw new \Exception("Cannot move customer to the same admin/reseller as he currently is assigned to", 406);
} }
// get target admin // get target admin
@@ -1733,7 +1743,7 @@ class Customers extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class DirOptions extends ApiCommand implements ResourceEntity class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -39,16 +43,16 @@ class DirOptions extends ApiCommand implements ResourceEntity
* optional, custom 500 error string/file * optional, custom 500 error string/file
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// get needed customer info to reduce the email-address-counter by one // get needed customer info to reduce the email-address-counter by one
@@ -134,13 +138,13 @@ class DirOptions extends ApiCommand implements ResourceEntity
* id of dir-protection entry * id of dir-protection entry
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
@@ -169,7 +173,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) { if (Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_HTACCESS . "` SELECT * FROM `" . TABLE_PANEL_HTACCESS . "`
@@ -185,7 +189,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = "id #" . $id; $key = "id #" . $id;
throw new Exception("Directory option with " . $key . " could not be found", 404); throw new \Exception("Directory option with " . $key . " could not be found", 404);
} }
/** /**
@@ -209,7 +213,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
* optional, custom 500 error string/file * optional, custom 500 error string/file
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -283,13 +287,13 @@ class DirOptions extends ApiCommand implements ResourceEntity
* optional, admin-only, select directory-protections of a specific customer by loginname * optional, admin-only, select directory-protections of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$customer_ids = $this->getAllowedCustomerIds('extras.pathoptions'); $customer_ids = $this->getAllowedCustomerIds('extras.pathoptions');
@@ -299,7 +303,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
WHERE `customerid` IN (" . implode(', ', $customer_ids) . ") WHERE `customerid` IN (" . implode(', ', $customer_ids) . ")
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list directory-options"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list directory-options");
@@ -316,19 +320,19 @@ class DirOptions extends ApiCommand implements ResourceEntity
* id of dir-protection entry * id of dir-protection entry
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id'); $id = $this->getParam('id');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.pathoptions')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// get directory-option // get directory-option

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class DirProtections extends ApiCommand implements ResourceEntity class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -32,16 +36,16 @@ class DirProtections extends ApiCommand implements ResourceEntity
* optional name/description for the protection * optional name/description for the protection
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// get needed customer info to reduce the email-address-counter by one // get needed customer info to reduce the email-address-counter by one
@@ -125,13 +129,13 @@ class DirProtections extends ApiCommand implements ResourceEntity
* optional, the username * optional, the username
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
@@ -162,7 +166,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) { if (Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_HTPASSWDS . "` SELECT * FROM `" . TABLE_PANEL_HTPASSWDS . "`
@@ -178,7 +182,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "username '" . $username . "'"); $key = ($id > 0 ? "id #" . $id : "username '" . $username . "'");
throw new Exception("Directory protection with " . $key . " could not be found", 404); throw new \Exception("Directory protection with " . $key . " could not be found", 404);
} }
/** /**
@@ -198,7 +202,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
* optional name/description for the protection * optional name/description for the protection
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -276,13 +280,13 @@ class DirProtections extends ApiCommand implements ResourceEntity
* optional, admin-only, select directory-protections of a specific customer by loginname * optional, admin-only, select directory-protections of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$customer_ids = $this->getAllowedCustomerIds('extras.directoryprotection'); $customer_ids = $this->getAllowedCustomerIds('extras.directoryprotection');
@@ -292,7 +296,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
WHERE `customerid` IN (" . implode(', ', $customer_ids) . ") WHERE `customerid` IN (" . implode(', ', $customer_ids) . ")
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list directory-protections"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list directory-protections");
@@ -311,13 +315,13 @@ class DirProtections extends ApiCommand implements ResourceEntity
* optional, the username * optional, the username
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
@@ -325,7 +329,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
$username = $this->getParam('username', $un_optional, ''); $username = $this->getParam('username', $un_optional, '');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'extras.directoryprotection')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// get directory protection // get directory protection

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class DomainZones extends ApiCommand implements ResourceEntity class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -37,13 +41,13 @@ class DomainZones extends ApiCommand implements ResourceEntity
* optional, default 18000 * optional, default 18000
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if (Settings::Get('system.dnsenabled') != '1') { if (Settings::Get('system.dnsenabled') != '1') {
throw new Exception("DNS server not enabled on this system", 405); throw new \Exception("DNS server not enabled on this system", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
@@ -65,14 +69,15 @@ class DomainZones extends ApiCommand implements ResourceEntity
$ttl = $this->getParam('ttl', true, 18000); $ttl = $this->getParam('ttl', true, 18000);
if ($result['parentdomainid'] != '0') { if ($result['parentdomainid'] != '0') {
throw new Exception("DNS zones can only be generated for the main domain, not for subdomains", 406); throw new \Exception("DNS zones can only be generated for the main domain, not for subdomains", 406);
} }
if ($result['subisbinddomain'] != '1') { if ($result['subisbinddomain'] != '1') {
standard_error('dns_domain_nodns', '', true); standard_error('dns_domain_nodns', '', true);
} }
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$domain = $idna_convert->encode($result['domain']); $domain = $idna_convert->encode($result['domain']);
// select all entries // select all entries
@@ -80,7 +85,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
Database::pexecute($sel_stmt, array( Database::pexecute($sel_stmt, array(
'did' => $id 'did' => $id
), true, true); ), true, true);
$dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC); $dom_entries = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
// validation // validation
$errors = array(); $errors = array();
@@ -285,7 +290,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
// return $errors // return $errors
throw new Exception(implode("\n", $errors)); throw new \Exception(implode("\n", $errors));
} }
/** /**
@@ -297,13 +302,13 @@ class DomainZones extends ApiCommand implements ResourceEntity
* optional, the domain name * optional, the domain name
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
{ {
if (Settings::Get('system.dnsenabled') != '1') { if (Settings::Get('system.dnsenabled') != '1') {
throw new Exception("DNS server not enabled on this system", 405); throw new \Exception("DNS server not enabled on this system", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
@@ -318,7 +323,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
$id = $result['id']; $id = $result['id'];
if ($result['parentdomainid'] != '0') { if ($result['parentdomainid'] != '0') {
throw new Exception("DNS zones can only be generated for the main domain, not for subdomains", 406); throw new \Exception("DNS zones can only be generated for the main domain, not for subdomains", 406);
} }
if ($result['subisbinddomain'] != '1') { if ($result['subisbinddomain'] != '1') {
@@ -338,7 +343,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
*/ */
public function update() public function update()
{ {
throw new Exception('You cannot update a dns zone entry. You need to delete it and re-add it.', 303); throw new \Exception('You cannot update a dns zone entry. You need to delete it and re-add it.', 303);
} }
/** /**
@@ -347,7 +352,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
*/ */
public function listing() public function listing()
{ {
throw new Exception('You cannot list dns zones. To get all domains use Domains.listing() or SubDomains.listing()', 303); throw new \Exception('You cannot list dns zones. To get all domains use Domains.listing() or SubDomains.listing()', 303);
} }
/** /**
@@ -360,13 +365,13 @@ class DomainZones extends ApiCommand implements ResourceEntity
* optional, the domain name * optional, the domain name
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return bool * @return bool
*/ */
public function delete() public function delete()
{ {
if (Settings::Get('system.dnsenabled') != '1') { if (Settings::Get('system.dnsenabled') != '1') {
throw new Exception("DNS server not enabled on this system", 405); throw new \Exception("DNS server not enabled on this system", 405);
} }
$entry_id = $this->getParam('entry_id'); $entry_id = $this->getParam('entry_id');

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,14 +19,14 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Domains extends ApiCommand implements ResourceEntity class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* lists all domain entries * lists all domain entries
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -43,7 +47,7 @@ class Domains extends ApiCommand implements ResourceEntity
} }
Database::pexecute($result_stmt, $params); Database::pexecute($result_stmt, $params);
$result = array(); $result = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
return $this->response(200, "successfull", array( return $this->response(200, "successfull", array(
@@ -51,7 +55,7 @@ class Domains extends ApiCommand implements ResourceEntity
'list' => $result 'list' => $result
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -65,7 +69,7 @@ class Domains extends ApiCommand implements ResourceEntity
* optional, default false * optional, default false
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -78,7 +82,8 @@ class Domains extends ApiCommand implements ResourceEntity
// convert possible idn domain to punycode // convert possible idn domain to punycode
if (substr($domainname, 0, 4) != 'xn--') { if (substr($domainname, 0, 4) != 'xn--') {
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$domainname = $idna_convert->encode($domainname); $domainname = $idna_convert->encode($domainname);
} }
@@ -100,9 +105,9 @@ class Domains extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "domainname '" . $domainname . "'"); $key = ($id > 0 ? "id #" . $id : "domainname '" . $domainname . "'");
throw new Exception("Domain with " . $key . " could not be found", 404); throw new \Exception("Domain with " . $key . " could not be found", 404);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -179,7 +184,7 @@ class Domains extends ApiCommand implements ResourceEntity
* optional whether to enable oscp-stapling for this domain. default 0 (false), requires SSL * optional whether to enable oscp-stapling for this domain. default 0 (false), requires SSL
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -235,7 +240,8 @@ class Domains extends ApiCommand implements ResourceEntity
standard_error('domain_nopunycode', '', true); standard_error('domain_nopunycode', '', true);
} }
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$domain = $idna_convert->encode(preg_replace(array( $domain = $idna_convert->encode(preg_replace(array(
'/\:(\d)+$/', '/\:(\d)+$/',
'/^https?\:\/\//' '/^https?\:\/\//'
@@ -446,7 +452,7 @@ class Domains extends ApiCommand implements ResourceEntity
'id' => $aliasdomain 'id' => $aliasdomain
), true, true); ), true, true);
$ipdata_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid"); $ipdata_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid");
while ($origip = $origipresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($origip = $origipresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
$_origip_tmp = Database::pexecute_first($ipdata_stmt, array( $_origip_tmp = Database::pexecute_first($ipdata_stmt, array(
'ipid' => $origip['id_ipandports'] 'ipid' => $origip['id_ipandports']
), true, true); ), true, true);
@@ -498,7 +504,8 @@ class Domains extends ApiCommand implements ResourceEntity
$issubof = '0'; $issubof = '0';
} }
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
if ($domain == '') { if ($domain == '') {
standard_error(array( standard_error(array(
'stringisempty', 'stringisempty',
@@ -648,9 +655,9 @@ class Domains extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -736,7 +743,7 @@ class Domains extends ApiCommand implements ResourceEntity
* optional whether to enable oscp-stapling for this domain. default 0 (false), requires SSL * optional whether to enable oscp-stapling for this domain. default 0 (false), requires SSL
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -829,7 +836,7 @@ class Domains extends ApiCommand implements ResourceEntity
$email_forwarders = 0; $email_forwarders = 0;
$email_accounts = 0; $email_accounts = 0;
while ($domain_emails_row = $domain_emails_result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($domain_emails_row = $domain_emails_result_stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($domain_emails_row['destination'] != '') { if ($domain_emails_row['destination'] != '') {
$domain_emails_row['destination'] = explode(' ', makeCorrectDestination($domain_emails_row['destination'])); $domain_emails_row['destination'] = explode(' ', makeCorrectDestination($domain_emails_row['destination']));
$email_forwarders += count($domain_emails_row['destination']); $email_forwarders += count($domain_emails_row['destination']);
@@ -1086,7 +1093,7 @@ class Domains extends ApiCommand implements ResourceEntity
'aliasdomain' => $aliasdomain 'aliasdomain' => $aliasdomain
), true, true); ), true, true);
$ipdata_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid"); $ipdata_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid");
while ($origip = $origipresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($origip = $origipresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
$_origip_tmp = Database::pexecute_first($ipdata_stmt, array( $_origip_tmp = Database::pexecute_first($ipdata_stmt, array(
'ipid' => $origip['id_ipandports'] 'ipid' => $origip['id_ipandports']
), true, true); ), true, true);
@@ -1413,7 +1420,7 @@ class Domains extends ApiCommand implements ResourceEntity
'id' => $id 'id' => $id
), true, true); ), true, true);
while ($row = $domainidsresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $domainidsresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
$del_stmt = Database::prepare(" $del_stmt = Database::prepare("
DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_domain` = :rowid DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_domain` = :rowid
@@ -1461,7 +1468,7 @@ class Domains extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] updated domain '" . $result['domain'] . "'"); $this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] updated domain '" . $result['domain'] . "'");
return $this->response(200, "successfull", $update_data); return $this->response(200, "successfull", $update_data);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -1477,7 +1484,7 @@ class Domains extends ApiCommand implements ResourceEntity
* optional, default false, specify whether it's a std-subdomain you are deleting as it does not count as subdomain-resource * optional, default false, specify whether it's a std-subdomain you are deleting as it does not count as subdomain-resource
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -1509,7 +1516,7 @@ class Domains extends ApiCommand implements ResourceEntity
), true, true); ), true, true);
$idString = array(); $idString = array();
$paramString = array(); $paramString = array();
while ($subRow = $subresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($subRow = $subresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
$idString[] = "`domainid` = :domain_" . (int) $subRow['id']; $idString[] = "`domainid` = :domain_" . (int) $subRow['id'];
$paramString['domain_' . $subRow['id']] = $subRow['id']; $paramString['domain_' . $subRow['id']] = $subRow['id'];
} }
@@ -1619,7 +1626,7 @@ class Domains extends ApiCommand implements ResourceEntity
inserttask('4'); inserttask('4');
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -1631,7 +1638,7 @@ class Domains extends ApiCommand implements ResourceEntity
* @param boolean $ssl * @param boolean $ssl
* default false * default false
* *
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
private function validateIpAddresses($p_ipandports = null, $ssl = false, $edit_id = 0) private function validateIpAddresses($p_ipandports = null, $ssl = false, $edit_id = 0)
@@ -1640,7 +1647,7 @@ class Domains extends ApiCommand implements ResourceEntity
// system-default, check here if there is none // system-default, check here if there is none
// this is not required for ssl-enabled ip's // this is not required for ssl-enabled ip's
if ($edit_id <= 0 && ! $ssl && empty($p_ipandports)) { if ($edit_id <= 0 && ! $ssl && empty($p_ipandports)) {
throw new Exception("No IPs given, unable to add domain (no default IPs set?)", 406); throw new \Exception("No IPs given, unable to add domain (no default IPs set?)", 406);
} }
// convert given value(s) correctly // convert given value(s) correctly
@@ -1694,7 +1701,7 @@ class Domains extends ApiCommand implements ResourceEntity
Database::pexecute($ipsresult_stmt, array( Database::pexecute($ipsresult_stmt, array(
'id' => $edit_id 'id' => $edit_id
), true, true); ), true, true);
while ($ipsresultrow = $ipsresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($ipsresultrow = $ipsresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
$ipandports[] = $ipsresultrow['id_ipandports']; $ipandports[] = $ipsresultrow['id_ipandports'];
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class EmailAccounts extends ApiCommand implements ResourceEntity class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -39,13 +43,13 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
* optional, sends the welcome message to the new account (needed for creation, without the user won't be able to login before any mail is received), default 1 (true) * optional, sends the welcome message to the new account (needed for creation, without the user won't be able to login before any mail is received), default 1 (true)
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->getUserDetail('email_accounts_used') < $this->getUserDetail('email_accounts') || $this->getUserDetail('email_accounts') == '-1') { if ($this->getUserDetail('email_accounts_used') < $this->getUserDetail('email_accounts') || $this->getUserDetail('email_accounts') == '-1') {
@@ -78,13 +82,14 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$id = $result['id']; $id = $result['id'];
$email_full = $result['email_full']; $email_full = $result['email_full'];
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$username = $idna_convert->decode($email_full); $username = $idna_convert->decode($email_full);
$password = validate($email_password, 'password', '', '', array(), true); $password = validate($email_password, 'password', '', '', array(), true);
$password = validatePassword($password, true); $password = validatePassword($password, true);
if ($result['popaccountid'] != 0) { if ($result['popaccountid'] != 0) {
throw new Exception("Email address '" . $email_full . "' has already an account assigned.", 406); throw new \Exception("Email address '" . $email_full . "' has already an account assigned.", 406);
} }
if (checkMailAccDeletionState($email_full)) { if (checkMailAccDeletionState($email_full)) {
@@ -215,10 +220,10 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body)); $this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
$this->mailer()->addAddress($email_full); $this->mailer()->addAddress($email_full);
$this->mailer()->send(); $this->mailer()->send();
} catch (phpmailerException $e) { } catch (\phpmailerException $e) {
$mailerr_msg = $e->errorMessage(); $mailerr_msg = $e->errorMessage();
$_mailerror = true; $_mailerror = true;
} catch (Exception $e) { } catch (\Exception $e) {
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
@@ -245,10 +250,10 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body)); $this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
$this->mailer()->addAddress($idna_convert->encode($alternative_email), getCorrectUserSalutation($customer)); $this->mailer()->addAddress($idna_convert->encode($alternative_email), getCorrectUserSalutation($customer));
$this->mailer()->send(); $this->mailer()->send();
} catch (phpmailerException $e) { } catch (\phpmailerException $e) {
$mailerr_msg = $e->errorMessage(); $mailerr_msg = $e->errorMessage();
$_mailerror = true; $_mailerror = true;
} catch (Exception $e) { } catch (\Exception $e) {
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
@@ -270,7 +275,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
/** /**
@@ -279,7 +284,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
*/ */
public function get() public function get()
{ {
throw new Exception('You cannot directly get an email account. You need to call Emails.get()', 303); throw new \Exception('You cannot directly get an email account. You need to call Emails.get()', 303);
} }
/** /**
@@ -299,13 +304,13 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
* optional, update password * optional, update password
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// parameter // parameter
@@ -321,7 +326,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$id = $result['id']; $id = $result['id'];
if (empty($result['popaccountid']) || $result['popaccountid'] == 0) { if (empty($result['popaccountid']) || $result['popaccountid'] == 0) {
throw new Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406); throw new \Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406);
} }
$password = $this->getParam('email_password', true, ''); $password = $this->getParam('email_password', true, '');
@@ -393,7 +398,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
*/ */
public function listing() public function listing()
{ {
throw new Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303); throw new \Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303);
} }
/** /**
@@ -411,13 +416,13 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
* optional, default false * optional, default false
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// parameter // parameter
@@ -434,7 +439,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
$id = $result['id']; $id = $result['id'];
if (empty($result['popaccountid']) || $result['popaccountid'] == 0) { if (empty($result['popaccountid']) || $result['popaccountid'] == 0) {
throw new Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406); throw new \Exception("Email address '" . $result['email_full'] . "' has no account assigned.", 406);
} }
// get needed customer info to reduce the email-account-counter by one // get needed customer info to reduce the email-account-counter by one

View File

@@ -1,5 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* 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).
@@ -15,7 +18,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class EmailForwarders extends ApiCommand implements ResourceEntity class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -33,13 +36,13 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
* email-address to add as forwarder * email-address to add as forwarder
* *
* @access admin,customer * @access admin,customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->getUserDetail('email_forwarders_used') < $this->getUserDetail('email_forwarders') || $this->getUserDetail('email_forwarders') == '-1') { if ($this->getUserDetail('email_forwarders_used') < $this->getUserDetail('email_forwarders') || $this->getUserDetail('email_forwarders') == '-1') {
@@ -51,7 +54,8 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
$destination = $this->getParam('destination'); $destination = $this->getParam('destination');
// validation // validation
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$destination = $idna_convert->encode($destination); $destination = $idna_convert->encode($destination);
$result = $this->apiCall('Emails.get', array( $result = $this->apiCall('Emails.get', array(
@@ -103,7 +107,7 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
/** /**
@@ -112,7 +116,7 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
*/ */
public function get() public function get()
{ {
throw new Exception('You cannot directly get an email forwarder. You need to call Emails.get()', 303); throw new \Exception('You cannot directly get an email forwarder. You need to call Emails.get()', 303);
} }
/** /**
@@ -121,7 +125,7 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
*/ */
public function update() public function update()
{ {
throw new Exception('You cannot update an email forwarder. You need to delete the entry and create a new one.', 303); throw new \Exception('You cannot update an email forwarder. You need to delete the entry and create a new one.', 303);
} }
/** /**
@@ -130,7 +134,7 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
*/ */
public function listing() public function listing()
{ {
throw new Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303); throw new \Exception('You cannot directly list email forwarders. You need to call Emails.listing()', 303);
} }
/** /**
@@ -148,13 +152,13 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
* id of the forwarder to delete * id of the forwarder to delete
* *
* @access admin,customer * @access admin,customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// parameter // parameter
@@ -205,6 +209,6 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Unknown forwarder id", 404); throw new \Exception("Unknown forwarder id", 404);
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Emails extends ApiCommand implements ResourceEntity class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -33,13 +37,13 @@ class Emails extends ApiCommand implements ResourceEntity
* optional, admin-only, the loginname * optional, admin-only, the loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->getUserDetail('emails_used') < $this->getUserDetail('emails') || $this->getUserDetail('emails') == '-1') { if ($this->getUserDetail('emails_used') < $this->getUserDetail('emails') || $this->getUserDetail('emails') == '-1') {
@@ -53,7 +57,8 @@ class Emails extends ApiCommand implements ResourceEntity
// validation // validation
if (substr($domain, 0, 4) != 'xn--') { if (substr($domain, 0, 4) != 'xn--') {
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$domain = $idna_convert->encode(validate($domain, 'domain', '', '', array(), true)); $domain = $idna_convert->encode(validate($domain, 'domain', '', '', array(), true));
} }
@@ -138,7 +143,7 @@ class Emails extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
/** /**
@@ -150,7 +155,7 @@ class Emails extends ApiCommand implements ResourceEntity
* optional, the email-address * optional, the email-address
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -175,7 +180,7 @@ class Emails extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "emailaddr '" . $emailaddr . "'"); $key = ($id > 0 ? "id #" . $id : "emailaddr '" . $emailaddr . "'");
throw new Exception("Email address with " . $key . " could not be found", 404); throw new \Exception("Email address with " . $key . " could not be found", 404);
} }
/** /**
@@ -193,13 +198,13 @@ class Emails extends ApiCommand implements ResourceEntity
* optional * optional
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// if enabling catchall is not allowed by settings, we do not need // if enabling catchall is not allowed by settings, we do not need
@@ -266,7 +271,7 @@ class Emails extends ApiCommand implements ResourceEntity
* optional, admin-only, select email addresses of a specific customer by loginname * optional, admin-only, select email addresses of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -281,7 +286,7 @@ class Emails extends ApiCommand implements ResourceEntity
WHERE m.`customerid` IN (" . implode(", ", $customer_ids) . ") WHERE m.`customerid` IN (" . implode(", ", $customer_ids) . ")
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list email-addresses"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list email-addresses");
@@ -306,13 +311,13 @@ class Emails extends ApiCommand implements ResourceEntity
* optional, delete email data from filesystem, default: 0 (false) * optional, delete email data from filesystem, default: 0 (false)
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'email')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,14 +19,14 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class FpmDaemons extends ApiCommand implements ResourceEntity class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* lists all fpm-daemon entries * lists all fpm-daemon entries
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -35,7 +39,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
"); ");
$fpmdaemons = array(); $fpmdaemons = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) { while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
$query_params = array( $query_params = array(
'id' => $row['id'] 'id' => $row['id']
@@ -48,7 +52,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
$configs = array(); $configs = array();
if (Database::num_rows() > 0) { if (Database::num_rows() > 0) {
while ($row2 = $configresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row2 = $configresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
$configs[] = $row2['description']; $configs[] = $row2['description'];
} }
} }
@@ -66,7 +70,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
'list' => $fpmdaemons 'list' => $fpmdaemons
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -76,7 +80,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
* fpm-daemon-id * fpm-daemon-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -93,9 +97,9 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
if ($result) { if ($result) {
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("fpm-daemon with id #" . $id . " could not be found", 404); throw new \Exception("fpm-daemon with id #" . $id . " could not be found", 404);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -122,7 +126,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
* optional, limit execution to the following extensions, default '.php' * optional, limit execution to the following extensions, default '.php'
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -153,7 +157,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
'dynamic', 'dynamic',
'ondemand' 'ondemand'
))) { ))) {
throw new ErrorException("Unknown process manager", 406); throw new \Exception("Unknown process manager", 406);
} }
if (empty($limit_extensions)) { if (empty($limit_extensions)) {
$limit_extensions = '.php'; $limit_extensions = '.php';
@@ -201,7 +205,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -233,7 +237,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
* optional, limit execution to the following extensions, default '.php' * optional, limit execution to the following extensions, default '.php'
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -269,7 +273,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
'dynamic', 'dynamic',
'ondemand' 'ondemand'
))) { ))) {
throw new ErrorException("Unknown process manager", 406); throw new \Exception("Unknown process manager", 406);
} }
if (empty($limit_extensions)) { if (empty($limit_extensions)) {
$limit_extensions = '.php'; $limit_extensions = '.php';
@@ -318,7 +322,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -328,7 +332,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
* fpm-daemon-id * fpm-daemon-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -364,6 +368,6 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon setting '" . $result['description'] . "' has been deleted by '" . $this->getUserDetail('loginname') . "'"); $this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon setting '" . $result['description'] . "' has been deleted by '" . $this->getUserDetail('loginname') . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,14 +19,14 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Froxlor extends ApiCommand class Froxlor extends \Froxlor\Api\ApiCommand
{ {
/** /**
* checks whether there is a newer version of froxlor available * checks whether there is a newer version of froxlor available
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return string * @return string
*/ */
public function checkUpdate() public function checkUpdate()
@@ -35,7 +39,7 @@ class Froxlor extends ApiCommand
$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
$latestversion = HttpClient::urlGet(UPDATE_URI); $latestversion = \Froxlor\Http\HttpClient::urlGet(UPDATE_URI);
$latestversion = explode('|', $latestversion); $latestversion = explode('|', $latestversion);
if (is_array($latestversion) && count($latestversion) >= 1) { if (is_array($latestversion) && count($latestversion) >= 1) {
@@ -95,7 +99,7 @@ class Froxlor extends ApiCommand
'additional_info' => "" 'additional_info' => ""
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -105,7 +109,7 @@ class Froxlor extends ApiCommand
* content of exported froxlor-settings json file * content of exported froxlor-settings json file
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return bool * @return bool
*/ */
public function importSettings() public function importSettings()
@@ -114,7 +118,7 @@ class Froxlor extends ApiCommand
$json_str = $this->getParam('json_str'); $json_str = $this->getParam('json_str');
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "User " . $this->getUserDetail('loginname') . " imported settings"); $this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "User " . $this->getUserDetail('loginname') . " imported settings");
try { try {
SImExporter::import($json_str); \Froxlor\SImExporter::import($json_str);
inserttask('1'); inserttask('1');
inserttask('10'); inserttask('10');
// Using nameserver, insert a task which rebuilds the server config // Using nameserver, insert a task which rebuilds the server config
@@ -122,35 +126,35 @@ class Froxlor extends ApiCommand
// cron.d file // cron.d file
inserttask('99'); inserttask('99');
return $this->response(200, "successfull", true); return $this->response(200, "successfull", true);
} catch (Exception $e) { } catch (\Exception $e) {
throw new Exception($e->getMessage(), 406); throw new \Exception($e->getMessage(), 406);
} }
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
* export settings * export settings
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return string json-string * @return string json-string
*/ */
public function exportSettings() public function exportSettings()
{ {
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) { if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "User " . $this->getUserDetail('loginname') . " exported settings"); $this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "User " . $this->getUserDetail('loginname') . " exported settings");
$json_export = SImExporter::export(); $json_export = \Froxlor\SImExporter::export();
return $this->response(200, "successfull", $json_export); return $this->response(200, "successfull", $json_export);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
* return a list of all settings * return a list of all settings
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listSettings() public function listSettings()
@@ -161,7 +165,7 @@ class Froxlor extends ApiCommand
"); ");
Database::pexecute($sel_stmt, null, true, true); Database::pexecute($sel_stmt, null, true, true);
$result = array(); $result = array();
while ($row = $sel_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = array( $result[] = array(
'key' => $row['settinggroup'] . '.' . $row['varname'], 'key' => $row['settinggroup'] . '.' . $row['varname'],
'value' => $row['value'] 'value' => $row['value']
@@ -172,7 +176,7 @@ class Froxlor extends ApiCommand
'list' => $result 'list' => $result
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -182,7 +186,7 @@ class Froxlor extends ApiCommand
* settinggroup.varname couple * settinggroup.varname couple
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return string * @return string
*/ */
public function getSetting() public function getSetting()
@@ -191,7 +195,7 @@ class Froxlor extends ApiCommand
$setting = $this->getParam('key'); $setting = $this->getParam('key');
return $this->response(200, "successfull", Settings::Get($setting)); return $this->response(200, "successfull", Settings::Get($setting));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -203,25 +207,25 @@ class Froxlor extends ApiCommand
* optional the new value, default is '' * optional the new value, default is ''
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return string * @return string
*/ */
public function updateSetting() public function updateSetting()
{ {
// currently not implemented as it required validation too so no wrong settings are being stored via API // currently not implemented as it required validation too so no wrong settings are being stored via API
throw new Exception("Not available yet.", 501); 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, '');
$oldvalue = Settings::Get($setting); $oldvalue = Settings::Get($setting);
if (is_null($oldvalue)) { if (is_null($oldvalue)) {
throw new Exception("Setting '" . $setting . "' could not be found"); throw new \Exception("Setting '" . $setting . "' could not be found");
} }
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] Changing setting '" . $setting . "' from '" . $oldvalue . "' to '" . $value . "'"); $this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] Changing setting '" . $setting . "' from '" . $oldvalue . "' to '" . $value . "'");
return $this->response(200, "successfull", Settings::Set($setting, $value, true)); return $this->response(200, "successfull", Settings::Set($setting, $value, true));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -231,7 +235,7 @@ class Froxlor extends ApiCommand
* optional, return list of functions for a specific module * optional, return list of functions for a specific module
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function listFunctions() public function listFunctions()
@@ -255,7 +259,7 @@ class Froxlor extends ApiCommand
} }
} else { } else {
// check all the modules // check all the modules
$path = FROXLOR_INSTALL_DIR . '/lib/classes/api/commands/'; $path = \Froxlor\Froxlor::getInstallDir() . '/lib/Froxlor/Api/Commands/';
// valid directory? // valid directory?
if (is_dir($path)) { if (is_dir($path)) {
// create RecursiveIteratorIterator // create RecursiveIteratorIterator
@@ -264,13 +268,13 @@ class Froxlor extends ApiCommand
foreach ($its as $it) { foreach ($its as $it) {
// does it match the Filename pattern? // does it match the Filename pattern?
$matches = array(); $matches = array();
if (preg_match("/^class\.(.+)\.php$/i", $it->getFilename(), $matches)) { if (preg_match("/^(.+)\.php$/i", $it->getFilename(), $matches)) {
// check for existence // check for existence
try { try {
// set the module to be in our namespace // set the module to be in our namespace
$mod = $matches[1]; $mod = $matches[1];
$this->requireModules($mod); $this->requireModules($mod);
} catch (Exception $e) { } catch (\Exception $e) {
// @todo log? // @todo log?
continue; continue;
} }
@@ -289,7 +293,7 @@ class Froxlor extends ApiCommand
} }
} else { } else {
// yikes - no valid directory to check // yikes - no valid directory to check
throw new Exception("Cannot search directory '" . $path . "'. No such directory.", 500); throw new \Exception("Cannot search directory '" . $path . "'. No such directory.", 500);
} }
} }
@@ -304,7 +308,7 @@ class Froxlor extends ApiCommand
* @param string $module * @param string $module
* @param string $function * @param string $function
* *
* @throws Exception * @throws \Exception
* @return array|bool * @return array|bool
*/ */
private function getParamListFromDoc($module = null, $function = null) private function getParamListFromDoc($module = null, $function = null)
@@ -396,7 +400,7 @@ class Froxlor extends ApiCommand
* *
* @param string|array $modules * @param string|array $modules
* *
* @throws Exception * @throws \Exception
*/ */
private function requireModules($modules = null) private function requireModules($modules = null)
{ {
@@ -410,17 +414,18 @@ class Froxlor extends ApiCommand
// check all the modules // check all the modules
foreach ($modules as $module) { foreach ($modules as $module) {
try { try {
$module = "\Froxlor\Api\Commands\\" . $module;
// can we use the class? // can we use the class?
if (class_exists($module)) { if (class_exists($module)) {
continue; continue;
} else { } else {
throw new Exception('The required class "' . $module . '" could not be found but the module-file exists', 404); throw new \Exception('The required class "' . $module . '" could not be found but the module-file exists', 404);
} }
} catch (Exception $e) { } catch (\Exception $e) {
// The autoloader will throw an Exception // The autoloader will throw an Exception
// that the required class could not be found // that the required class could not be found
// but we want a nicer error-message for this here // but we want a nicer error-message for this here
throw new Exception('The required module "' . $module . '" could not be found', 404); throw new \Exception('The required module "' . $module . '" could not be found', 404);
} }
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Ftps extends ApiCommand implements ResourceEntity class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -39,13 +43,13 @@ class Ftps extends ApiCommand implements ResourceEntity
* required when called as admin, not needed when called as customer * required when called as admin, not needed when called as customer
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'ftp')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'ftp')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
if ($this->getUserDetail('ftps_used') < $this->getUserDetail('ftps') || $this->getUserDetail('ftps') == '-1') { if ($this->getUserDetail('ftps_used') < $this->getUserDetail('ftps') || $this->getUserDetail('ftps') == '-1') {
@@ -76,7 +80,8 @@ class Ftps extends ApiCommand implements ResourceEntity
if (Settings::Get('customer.ftpatdomain') == '1') { if (Settings::Get('customer.ftpatdomain') == '1') {
$ftpusername = validate(trim($ftpusername), 'username', '/^[a-zA-Z0-9][a-zA-Z0-9\-_]+\$?$/', '', array(), true); $ftpusername = validate(trim($ftpusername), 'username', '/^[a-zA-Z0-9][a-zA-Z0-9\-_]+\$?$/', '', array(), true);
if (substr($ftpdomain, 0, 4) != 'xn--') { if (substr($ftpdomain, 0, 4) != 'xn--') {
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$ftpdomain = $idna_convert->encode(validate($ftpdomain, 'domain', '', '', array(), true)); $ftpdomain = $idna_convert->encode(validate($ftpdomain, 'domain', '', '', array(), true));
} }
} }
@@ -148,7 +153,7 @@ class Ftps extends ApiCommand implements ResourceEntity
"name" => $customer['loginname'] "name" => $customer['loginname']
), true, true); ), true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$stmt = Database::prepare("INSERT INTO `" . TABLE_FTP_QUOTATALLIES . "` $stmt = Database::prepare("INSERT INTO `" . TABLE_FTP_QUOTATALLIES . "`
(`name`, `quota_type`, `bytes_in_used`, `bytes_out_used`, `bytes_xfer_used`, `files_in_used`, `files_out_used`, `files_xfer_used`) (`name`, `quota_type`, `bytes_in_used`, `bytes_out_used`, `bytes_xfer_used`, `files_in_used`, `files_out_used`, `files_xfer_used`)
VALUES (:name, 'user', :bytes_in_used, '0', '0', '0', '0', '0') VALUES (:name, 'user', :bytes_in_used, '0', '0', '0', '0', '0')
@@ -202,10 +207,10 @@ class Ftps extends ApiCommand implements ResourceEntity
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body)); $this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
$this->mailer()->addAddress($customer['email'], getCorrectUserSalutation($customer)); $this->mailer()->addAddress($customer['email'], getCorrectUserSalutation($customer));
$this->mailer()->send(); $this->mailer()->send();
} catch (phpmailerException $e) { } catch (\phpmailerException $e) {
$mailerr_msg = $e->errorMessage(); $mailerr_msg = $e->errorMessage();
$_mailerror = true; $_mailerror = true;
} catch (Exception $e) { } catch (\Exception $e) {
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
@@ -225,7 +230,7 @@ class Ftps extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
/** /**
@@ -237,7 +242,7 @@ class Ftps extends ApiCommand implements ResourceEntity
* optional, the username * optional, the username
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -270,7 +275,7 @@ class Ftps extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (Settings::IsInList('panel.customer_hide_options', 'ftp')) { if (Settings::IsInList('panel.customer_hide_options', 'ftp')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_FTP_USERS . "` SELECT * FROM `" . TABLE_FTP_USERS . "`
@@ -286,7 +291,7 @@ class Ftps extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "username '" . $username . "'"); $key = ($id > 0 ? "id #" . $id : "username '" . $username . "'");
throw new Exception("FTP user with " . $key . " could not be found", 404); throw new \Exception("FTP user with " . $key . " could not be found", 404);
} }
/** /**
@@ -308,13 +313,13 @@ class Ftps extends ApiCommand implements ResourceEntity
* required when called as admin, not needed when called as customer * required when called as admin, not needed when called as customer
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
{ {
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'ftp')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'ftp')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
@@ -420,7 +425,7 @@ class Ftps extends ApiCommand implements ResourceEntity
* optional, admin-only, select ftp-users of a specific customer by loginname * optional, admin-only, select ftp-users of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -432,7 +437,7 @@ class Ftps extends ApiCommand implements ResourceEntity
WHERE `customerid` IN (" . implode(", ", $customer_ids) . ") WHERE `customerid` IN (" . implode(", ", $customer_ids) . ")
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list ftp-users"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list ftp-users");
@@ -453,7 +458,7 @@ class Ftps extends ApiCommand implements ResourceEntity
* optional, default false * optional, default false
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -464,7 +469,7 @@ class Ftps extends ApiCommand implements ResourceEntity
$delete_userfiles = $this->getBoolParam('delete_userfiles', true, 0); $delete_userfiles = $this->getBoolParam('delete_userfiles', true, 0);
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'ftp')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'ftp')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
// get ftp-user // get ftp-user

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\Api\Commands;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,8 +16,9 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class HostingPlans extends ApiCommand implements ResourceEntity class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
public function add() public function add()
{} {}
@@ -31,6 +33,4 @@ class HostingPlans extends ApiCommand implements ResourceEntity
public function delete() public function delete()
{} {}
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,14 +19,14 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class IpsAndPorts extends ApiCommand implements ResourceEntity class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* lists all ip/port entries * lists all ip/port entries
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -38,7 +42,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
"); ");
Database::pexecute($result_stmt, null, true, true); Database::pexecute($result_stmt, null, true, true);
$result = array(); $result = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
return $this->response(200, "successfull", array( return $this->response(200, "successfull", array(
@@ -46,7 +50,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
'list' => $result 'list' => $result
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -56,7 +60,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
* ip-port-id * ip-port-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -66,7 +70,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
if (! empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != - 1) { if (! empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != - 1) {
$allowed_ips = json_decode($this->getUserDetail('ip'), true); $allowed_ips = json_decode($this->getUserDetail('ip'), true);
if (! in_array($id, $allowed_ips)) { if (! in_array($id, $allowed_ips)) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
@@ -79,9 +83,9 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] get ip " . $result['ip'] . " " . $result['port']); $this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] get ip " . $result['ip'] . " " . $result['port']);
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("IP/port with id #" . $id . " could not be found", 404); throw new \Exception("IP/port with id #" . $id . " could not be found", 404);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -116,7 +120,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
* optional, requires $ssl = 1, default empty * optional, requires $ssl = 1, default empty
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -248,7 +252,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -286,7 +290,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
* *
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -434,7 +438,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -444,7 +448,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
* ip-port-id * ip-port-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -511,6 +515,6 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
standard_error('ipstillhasdomains', '', true); standard_error('ipstillhasdomains', '', true);
} }
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
} }

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Mysqls extends ApiCommand implements ResourceEntity class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -33,7 +37,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
* required when called as admin, not needed when called as customer * required when called as admin, not needed when called as customer
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -60,7 +64,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
$sql_root = Database::getSqlData(); $sql_root = Database::getSqlData();
Database::needRoot(false); Database::needRoot(false);
if (! isset($sql_root) || ! is_array($sql_root)) { if (! isset($sql_root) || ! is_array($sql_root)) {
throw new ErrorException("Database server with index #" . $dbserver . " is unknown", 404); throw new \Exception("Database server with index #" . $dbserver . " is unknown", 404);
} }
if ($sendinfomail != 1) { if ($sendinfomail != 1) {
@@ -75,7 +79,8 @@ class Mysqls extends ApiCommand implements ResourceEntity
'mysql_lastaccountnumber' => ($this->isAdmin() ? $customer['mysql_lastaccountnumber'] : $this->getUserDetail('mysql_lastaccountnumber')) 'mysql_lastaccountnumber' => ($this->isAdmin() ? $customer['mysql_lastaccountnumber'] : $this->getUserDetail('mysql_lastaccountnumber'))
); );
// create database, user, set permissions, etc.pp. // create database, user, set permissions, etc.pp.
$dbm = new DbManager($this->logger()); // @fixme dbManager
$dbm = new \DbManager($this->logger());
$username = $dbm->createDatabase($newdb_params['loginname'], $password, $newdb_params['mysql_lastaccountnumber']); $username = $dbm->createDatabase($newdb_params['loginname'], $password, $newdb_params['mysql_lastaccountnumber']);
// we've checked against the password in dbm->createDatabase // we've checked against the password in dbm->createDatabase
@@ -145,10 +150,10 @@ class Mysqls extends ApiCommand implements ResourceEntity
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body)); $this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
$this->mailer()->addAddress($userinfo['email'], getCorrectUserSalutation($userinfo)); $this->mailer()->addAddress($userinfo['email'], getCorrectUserSalutation($userinfo));
$this->mailer()->send(); $this->mailer()->send();
} catch (phpmailerException $e) { } catch (\phpmailerException $e) {
$mailerr_msg = $e->errorMessage(); $mailerr_msg = $e->errorMessage();
$_mailerror = true; $_mailerror = true;
} catch (Exception $e) { } catch (\Exception $e) {
$mailerr_msg = $e->getMessage(); $mailerr_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
@@ -167,7 +172,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
/** /**
@@ -181,7 +186,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
* optional, specify database-server, default is none * optional, specify database-server, default is none
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -213,7 +218,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
$params['dbserver'] = $dbserver; $params['dbserver'] = $dbserver;
} }
} else { } else {
throw new Exception("You do not have any customers yet", 406); throw new \Exception("You do not have any customers yet", 406);
} }
} else { } else {
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
@@ -228,7 +233,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (Settings::IsInList('panel.customer_hide_options', 'mysql')) { if (Settings::IsInList('panel.customer_hide_options', 'mysql')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_DATABASES . "` SELECT * FROM `" . TABLE_PANEL_DATABASES . "`
@@ -252,14 +257,14 @@ class Mysqls extends ApiCommand implements ResourceEntity
Database::pexecute($mbdata_stmt, array( Database::pexecute($mbdata_stmt, array(
"table_schema" => $result['databasename'] "table_schema" => $result['databasename']
), true, true); ), true, true);
$mbdata = $mbdata_stmt->fetch(PDO::FETCH_ASSOC); $mbdata = $mbdata_stmt->fetch(\PDO::FETCH_ASSOC);
Database::needRoot(false); Database::needRoot(false);
$result['size'] = $mbdata['MB']; $result['size'] = $mbdata['MB'];
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] get database '" . $result['databasename'] . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] get database '" . $result['databasename'] . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "dbname '" . $dbname . "'"); $key = ($id > 0 ? "id #" . $id : "dbname '" . $dbname . "'");
throw new Exception("MySQL database with " . $key . " could not be found", 404); throw new \Exception("MySQL database with " . $key . " could not be found", 404);
} }
/** /**
@@ -277,7 +282,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
* optional, description for database * optional, description for database
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -288,7 +293,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
$dbserver = $this->getParam('mysql_server', true, - 1); $dbserver = $this->getParam('mysql_server', true, - 1);
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result = $this->apiCall('Mysqls.get', array( $result = $this->apiCall('Mysqls.get', array(
@@ -365,7 +370,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
* optional, admin-only, select dbs of a specific customer by loginname * optional, admin-only, select dbs of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -380,7 +385,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
if ($dbserver < 0) { if ($dbserver < 0) {
// use all dbservers // use all dbservers
$dbservers_stmt = Database::query("SELECT DISTINCT `dbserver` FROM `" . TABLE_PANEL_DATABASES . "`"); $dbservers_stmt = Database::query("SELECT DISTINCT `dbserver` FROM `" . TABLE_PANEL_DATABASES . "`");
$dbservers = $dbservers_stmt->fetchAll(PDO::FETCH_ASSOC); $dbservers = $dbservers_stmt->fetchAll(\PDO::FETCH_ASSOC);
} else { } else {
// use specific dbserver // use specific dbserver
$dbservers = array( $dbservers = array(
@@ -398,7 +403,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
), true, true); ), true, true);
// Begin root-session // Begin root-session
Database::needRoot(true, $_dbserver['dbserver']); Database::needRoot(true, $_dbserver['dbserver']);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$mbdata_stmt = Database::prepare(" $mbdata_stmt = Database::prepare("
SELECT SUM(data_length + index_length) as MB FROM information_schema.TABLES SELECT SUM(data_length + index_length) as MB FROM information_schema.TABLES
WHERE table_schema = :table_schema WHERE table_schema = :table_schema
@@ -407,7 +412,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
Database::pexecute($mbdata_stmt, array( Database::pexecute($mbdata_stmt, array(
"table_schema" => $row['databasename'] "table_schema" => $row['databasename']
), true, true); ), true, true);
$mbdata = $mbdata_stmt->fetch(PDO::FETCH_ASSOC); $mbdata = $mbdata_stmt->fetch(\PDO::FETCH_ASSOC);
$row['size'] = $mbdata['MB']; $row['size'] = $mbdata['MB'];
$result[] = $row; $result[] = $row;
} }
@@ -431,7 +436,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
* optional, specify database-server, default is none * optional, specify database-server, default is none
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -442,7 +447,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
$dbserver = $this->getParam('mysql_server', true, - 1); $dbserver = $this->getParam('mysql_server', true, - 1);
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result = $this->apiCall('Mysqls.get', array( $result = $this->apiCall('Mysqls.get', array(
@@ -454,7 +459,8 @@ class Mysqls extends ApiCommand implements ResourceEntity
// Begin root-session // Begin root-session
Database::needRoot(true, $result['dbserver']); Database::needRoot(true, $result['dbserver']);
$dbm = new DbManager($this->logger()); // @fixme dbManager
$dbm = new \DbManager($this->logger());
$dbm->getManager()->deleteDatabase($result['databasename']); $dbm->getManager()->deleteDatabase($result['databasename']);
Database::needRoot(false); Database::needRoot(false);
// End root-session // End root-session

View File

@@ -1,4 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,7 +19,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class PhpSettings extends ApiCommand implements ResourceEntity class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -25,7 +29,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
* optional, also include subdomains to the list domains that use the config, default 0 (false) * optional, also include subdomains to the list domains that use the config, default 0 (false)
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -43,7 +47,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
"); ");
$phpconfigs = array(); $phpconfigs = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) { while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
$query_params = array( $query_params = array(
'id' => $row['id'] 'id' => $row['id']
); );
@@ -65,7 +69,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
SELECT DISTINCT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` SELECT DISTINCT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "`
WHERE `standardsubdomain` > 0 ORDER BY `standardsubdomain` ASC;"); WHERE `standardsubdomain` > 0 ORDER BY `standardsubdomain` ASC;");
$ssdids = array(); $ssdids = array();
while ($ssd = $ssdids_res->fetch(PDO::FETCH_ASSOC)) { while ($ssd = $ssdids_res->fetch(\PDO::FETCH_ASSOC)) {
$ssdids[] = $ssd['standardsubdomain']; $ssdids[] = $ssd['standardsubdomain'];
} }
if (count($ssdids) > 0) { if (count($ssdids) > 0) {
@@ -79,7 +83,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
Database::pexecute($domainresult_stmt, $query_params, true, true); Database::pexecute($domainresult_stmt, $query_params, true, true);
if (Database::num_rows() > 0) { if (Database::num_rows() > 0) {
while ($row2 = $domainresult_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row2 = $domainresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($row2['parentdomainid'] != 0) { if ($row2['parentdomainid'] != 0) {
$subdomains[] = $row2['domain']; $subdomains[] = $row2['domain'];
} else { } else {
@@ -108,7 +112,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
'list' => $phpconfigs 'list' => $phpconfigs
)); ));
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -118,7 +122,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
* php-settings-id * php-settings-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -135,9 +139,9 @@ class PhpSettings extends ApiCommand implements ResourceEntity
if ($result) { if ($result) {
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("php-config with id #" . $id . " could not be found", 404); throw new \Exception("php-config with id #" . $id . " could not be found", 404);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -187,7 +191,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
* optional limitation of php-file-extensions if FPM is used, default is fpm-daemon-value * optional limitation of php-file-extensions if FPM is used, default is fpm-daemon-value
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -260,7 +264,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
'dynamic', 'dynamic',
'ondemand' 'ondemand'
))) { ))) {
throw new ErrorException("Unknown process manager", 406); throw new \Exception("Unknown process manager", 406);
} }
if (empty($limit_extensions)) { if (empty($limit_extensions)) {
$limit_extensions = '.php'; $limit_extensions = '.php';
@@ -337,7 +341,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -388,7 +392,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
* optional limitation of php-file-extensions if FPM is used, default is fpm-daemon-value * optional limitation of php-file-extensions if FPM is used, default is fpm-daemon-value
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -455,7 +459,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
'dynamic', 'dynamic',
'ondemand' 'ondemand'
))) { ))) {
throw new ErrorException("Unknown process manager", 406); throw new \Exception("Unknown process manager", 406);
} }
if (empty($limit_extensions)) { if (empty($limit_extensions)) {
$limit_extensions = '.php'; $limit_extensions = '.php';
@@ -533,7 +537,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
/** /**
@@ -543,7 +547,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
* php-settings-id * php-settings-id
* *
* @access admin * @access admin
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -584,6 +588,6 @@ class PhpSettings extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] php setting '" . $result['description'] . "' has been deleted by '" . $this->getUserDetail('loginname') . "'"); $this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] php setting '" . $result['description'] . "' has been deleted by '" . $this->getUserDetail('loginname') . "'");
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("Not allowed to execute given command.", 403); throw new \Exception("Not allowed to execute given command.", 403);
} }
} }

View File

@@ -1,5 +1,8 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
use Froxlor\Settings as Settings;
/** /**
* 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).
@@ -15,7 +18,7 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class SubDomains extends ApiCommand implements ResourceEntity class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
@@ -51,7 +54,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
* required when called as admin, not needed when called as customer * required when called as admin, not needed when called as customer
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function add() public function add()
@@ -91,7 +94,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
standard_error('domain_nopunycode', '', true); standard_error('domain_nopunycode', '', true);
} }
$idna_convert = new idna_convert_wrapper(); // @fixme idna_convert_wrapper
$idna_convert = new \idna_convert_wrapper();
$subdomain = $idna_convert->encode(preg_replace(array( $subdomain = $idna_convert->encode(preg_replace(array(
'/\:(\d)+$/', '/\:(\d)+$/',
'/^https?\:\/\//' '/^https?\:\/\//'
@@ -315,7 +319,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
)); ));
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
throw new Exception("No more resources available", 406); throw new \Exception("No more resources available", 406);
} }
/** /**
@@ -327,7 +331,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
* optional, the domainname * optional, the domainname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function get() public function get()
@@ -338,7 +342,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
// convert possible idn domain to punycode // convert possible idn domain to punycode
if (substr($domainname, 0, 4) != 'xn--') { if (substr($domainname, 0, 4) != 'xn--') {
$idna_convert = new idna_convert_wrapper(); // @fixme idna_convert_wrapper
$idna_convert = new \idna_convert_wrapper();
$domainname = $idna_convert->encode($domainname); $domainname = $idna_convert->encode($domainname);
} }
@@ -363,7 +368,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
'iddn' => ($id <= 0 ? $domainname : $id) 'iddn' => ($id <= 0 ? $domainname : $id)
); );
} else { } else {
throw new Exception("You do not have any customers yet", 406); throw new \Exception("You do not have any customers yet", 406);
} }
} else { } else {
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
@@ -378,7 +383,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (Settings::IsInList('panel.customer_hide_options', 'domains')) { if (Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result_stmt = Database::prepare(" $result_stmt = Database::prepare("
SELECT d.*, pd.`subcanemaildomain`, pd.`isbinddomain` as subisbinddomain SELECT d.*, pd.`subcanemaildomain`, pd.`isbinddomain` as subisbinddomain
@@ -397,7 +402,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
return $this->response(200, "successfull", $result); return $this->response(200, "successfull", $result);
} }
$key = ($id > 0 ? "id #" . $id : "domainname '" . $domainname . "'"); $key = ($id > 0 ? "id #" . $id : "domainname '" . $domainname . "'");
throw new Exception("Subdomain with " . $key . " could not be found", 404); throw new \Exception("Subdomain with " . $key . " could not be found", 404);
} }
/** /**
@@ -437,7 +442,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
* required when called as admin, not needed when called as customer * required when called as admin, not needed when called as customer
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function update() public function update()
@@ -447,7 +452,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
$domainname = $this->getParam('domainname', $dn_optional, ''); $domainname = $this->getParam('domainname', $dn_optional, '');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result = $this->apiCall('SubDomains.get', array( $result = $this->apiCall('SubDomains.get', array(
@@ -576,7 +581,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
$stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`= :customerid AND `domainid`= :domainid"); $stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`= :customerid AND `domainid`= :domainid");
Database::pexecute($stmt, $params, true, true); Database::pexecute($stmt, $params, true, true);
$idna_convert = new idna_convert_wrapper(); // @fixme idna
$idna_convert = new \idna_convert_wrapper();
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] automatically deleted mail-table entries for '" . $idna_convert->decode($result['domain']) . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] automatically deleted mail-table entries for '" . $idna_convert->decode($result['domain']) . "'");
} }
@@ -641,8 +647,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
inserttask('1'); inserttask('1');
inserttask('4'); inserttask('4');
// @fixme idna
$idna_convert = new idna_convert_wrapper(); $idna_convert = new \idna_convert_wrapper();
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] edited domain '" . $idna_convert->decode($result['domain']) . "'"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] edited domain '" . $idna_convert->decode($result['domain']) . "'");
} }
$result = $this->apiCall('SubDomains.get', array( $result = $this->apiCall('SubDomains.get', array(
@@ -655,7 +661,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
* lists all subdomain entries * lists all subdomain entries
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -686,7 +692,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
} }
} else { } else {
if (Settings::IsInList('panel.customer_hide_options', 'domains')) { if (Settings::IsInList('panel.customer_hide_options', 'domains')) {
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')
@@ -713,7 +719,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
"customerid" => $customer_id, "customerid" => $customer_id,
"standardsubdomain" => $customer_stdsubs[$customer_id] "standardsubdomain" => $customer_stdsubs[$customer_id]
), true, true); ), true, true);
while ($row = $domains_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $domains_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
} }
@@ -732,7 +738,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
* optional, the domainname * optional, the domainname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public function delete() public function delete()
@@ -742,7 +748,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
$domainname = $this->getParam('domainname', $dn_optional, ''); $domainname = $this->getParam('domainname', $dn_optional, '');
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) { if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405); throw new \Exception("You cannot access this resource", 405);
} }
$result = $this->apiCall('SubDomains.get', array( $result = $this->apiCall('SubDomains.get', array(
@@ -755,7 +761,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
$customer = $this->getCustomerData(); $customer = $this->getCustomerData();
if (! $this->isAdmin() && $result['caneditdomain'] == 0) { if (! $this->isAdmin() && $result['caneditdomain'] == 0) {
throw new Exception("You cannot edit this resource", 405); throw new \Exception("You cannot edit this resource", 405);
} }
if ($result['isemaildomain'] == '1') { if ($result['isemaildomain'] == '1') {
@@ -846,7 +852,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
* @param boolean $_doredirect * @param boolean $_doredirect
* *
* @return string validated path * @return string validated path
* @throws Exception * @throws \Exception
*/ */
private function validateDomainDocumentRoot($path = null, $url = null, $customer = null, $completedomain = null, &$_doredirect = false) private function validateDomainDocumentRoot($path = null, $url = null, $customer = null, $completedomain = null, &$_doredirect = false)
{ {

View File

@@ -1,4 +1,7 @@
<?php <?php
namespace Froxlor\Api\Commands;
use Froxlor\Database as Database;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -15,37 +18,37 @@
* @since 0.10.0 * @since 0.10.0
* *
*/ */
class Traffic extends ApiCommand implements ResourceEntity class Traffic extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
{ {
/** /**
* You cannot add traffic data * You cannot add traffic data
* *
* @throws Exception * @throws \Exception
*/ */
public function add() public function add()
{ {
throw new Exception('You cannot add traffic data', 303); throw new \Exception('You cannot add traffic data', 303);
} }
/** /**
* to get specific traffic details use year, month and/or day parameter for Traffic.listing() * to get specific traffic details use year, month and/or day parameter for Traffic.listing()
* *
* @throws Exception * @throws \Exception
*/ */
public function get() public function get()
{ {
throw new Exception('To get specific traffic details use year, month and/or day parameter for Traffic.listing()', 303); throw new \Exception('To get specific traffic details use year, month and/or day parameter for Traffic.listing()', 303);
} }
/** /**
* You cannot update traffic data * You cannot update traffic data
* *
* @throws Exception * @throws \Exception
*/ */
public function update() public function update()
{ {
throw new Exception('You cannot update traffic data', 303); throw new \Exception('You cannot update traffic data', 303);
} }
/** /**
@@ -65,7 +68,7 @@ class Traffic extends ApiCommand implements ResourceEntity
* optional, admin-only, select traffic of a specific customer by loginname * optional, admin-only, select traffic of a specific customer by loginname
* *
* @access admin, customer * @access admin, customer
* @throws Exception * @throws \Exception
* @return array count|list * @return array count|list
*/ */
public function listing() public function listing()
@@ -103,7 +106,7 @@ class Traffic extends ApiCommand implements ResourceEntity
WHERE `adminid` = :adminid" . $where_str); WHERE `adminid` = :adminid" . $where_str);
} }
Database::pexecute($result_stmt, $params, true, true); Database::pexecute($result_stmt, $params, true, true);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row; $result[] = $row;
} }
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list traffic"); $this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] list traffic");
@@ -116,10 +119,10 @@ class Traffic extends ApiCommand implements ResourceEntity
/** /**
* You cannot delete traffic data * You cannot delete traffic data
* *
* @throws Exception * @throws \Exception
*/ */
public function delete() public function delete()
{ {
throw new Exception('You cannot delete traffic data', 303); throw new \Exception('You cannot delete traffic data', 303);
} }
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\Api;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -23,19 +24,19 @@ class FroxlorRPC
* *
* @param array $request * @param array $request
* *
* @throws Exception * @throws \Exception
* @return array * @return array
*/ */
public static function validateRequest($request) public static function validateRequest($request)
{ {
// check header // check header
if (! isset($request['header']) || empty($request['header'])) { if (! isset($request['header']) || empty($request['header'])) {
throw new Exception("Invalid request header", 400); throw new \Exception("Invalid request header", 400);
} }
// check authorization // check authorization
if (! isset($request['header']['apikey']) || empty($request['header']['apikey']) || ! isset($request['header']['secret']) || empty($request['header']['secret'])) { if (! isset($request['header']['apikey']) || empty($request['header']['apikey']) || ! isset($request['header']['secret']) || empty($request['header']['secret'])) {
throw new Exception("No authorization credentials given", 400); throw new \Exception("No authorization credentials given", 400);
} }
self::validateAuth($request['header']['apikey'], $request['header']['secret']); self::validateAuth($request['header']['apikey'], $request['header']['secret']);
@@ -49,13 +50,13 @@ class FroxlorRPC
* @param string $key * @param string $key
* @param string $secret * @param string $secret
* *
* @throws Exception * @throws \Exception
* @return boolean * @return boolean
*/ */
private static function validateAuth($key, $secret) private static function validateAuth($key, $secret)
{ {
$sel_stmt = Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as"); $sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
$result = Database::pexecute_first($sel_stmt, array( $result = \Froxlor\Database\Database::pexecute_first($sel_stmt, array(
'ak' => $key, 'ak' => $key,
'as' => $secret 'as' => $secret
), true, true); ), true, true);
@@ -73,7 +74,7 @@ class FroxlorRPC
} }
} }
} }
throw new Exception("Invalid authorization credentials", 403); throw new \Exception("Invalid authorization credentials", 403);
} }
/** /**
@@ -82,30 +83,30 @@ class FroxlorRPC
* @param array $request * @param array $request
* *
* @return array * @return array
* @throws Exception * @throws \Exception
*/ */
private static function validateBody($request) private static function validateBody($request)
{ {
// check body // check body
if (! isset($request['body']) || empty($request['body'])) { if (! isset($request['body']) || empty($request['body'])) {
throw new Exception("Invalid request body", 400); throw new \Exception("Invalid request body", 400);
} }
// check command exists // check command exists
if (! isset($request['body']['command']) || empty($request['body']['command'])) { if (! isset($request['body']['command']) || empty($request['body']['command'])) {
throw new Exception("No command given", 400); throw new \Exception("No command given", 400);
} }
$command = explode(".", $request['body']['command']); $command = explode(".", $request['body']['command']);
if (count($command) != 2) { if (count($command) != 2) {
throw new Exception("Invalid command", 400); throw new \Exception("Invalid command", 400);
} }
// simply check for file-existance, as we do not want to use our autoloader because this way // simply check for file-existance, as we do not want to use our autoloader because this way
// it will recognize non-api classes+methods as valid commands // it will recognize non-api classes+methods as valid commands
$apiclass = FROXLOR_INSTALL_DIR . '/lib/classes/api/commands/class.' . $command[0] . '.php'; $apiclass = \Froxlor\Froxlor::getInstallDir() . '/lib/Froxlor/Api/Commands/' . $command[0] . '.php';
if (! file_exists($apiclass) || ! @method_exists($command[0], $command[1])) { if (! file_exists($apiclass) || ! @method_exists($command[0], $command[1])) {
throw new Exception("Unknown command", 400); throw new \Exception("Unknown command", 400);
} }
return array( return array(
'command' => array( 'command' => array(

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\Api;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.

56
lib/Froxlor/Froxlor.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace Froxlor;
final class Froxlor
{
// Main version variable
const VERSION = '0.10.0';
// Database version (YYYYMMDDC where C is a daily counter)
const DBVERSION = '201812170';
// Distribution branding-tag (used for Debian etc.)
const BRANDING = '';
/**
* return path to where froxlor is installed, e.g.
* /var/www/froxlor
*
* @return string
*/
public static function getInstallDir()
{
return dirname(dirname(__DIR__));
}
/**
* return basic version
*
* @return string
*/
public static function getVersion()
{
return self::VERSION;
}
/**
* return version + branding
*
* @return string
*/
public static function getFullVersion()
{
return self::VERSION . self::BRANDING;
}
/**
* return version + branding and database-version
*
* @return string
*/
public static function getVersionString()
{
return self::getFullVersion() . ' (' . self::DBVERSION . ')';
}
}

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\Http;
class HttpClient class HttpClient
{ {
@@ -12,10 +13,9 @@ class HttpClient
*/ */
public static function urlGet($url, $follow_location = true) public static function urlGet($url, $follow_location = true)
{ {
include FROXLOR_INSTALL_DIR . '/lib/version.inc.php';
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Froxlor/' . $version); curl_setopt($ch, CURLOPT_USERAGENT, 'Froxlor/' . \Froxlor\Froxlor::getVersion());
if ($follow_location) { if ($follow_location) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
} }
@@ -40,11 +40,10 @@ class HttpClient
*/ */
public static function fileGet($url, $target) public static function fileGet($url, $target)
{ {
include FROXLOR_INSTALL_DIR . '/lib/version.inc.php';
$fh = fopen($target, 'w'); $fh = fopen($target, 'w');
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Froxlor/' . $version); curl_setopt($ch, CURLOPT_USERAGENT, 'Froxlor/' . \Froxlor\Froxlor::getVersion());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_TIMEOUT, 50);
// give curl the file pointer so that it can write to it // give curl the file pointer so that it can write to it

View File

@@ -1,4 +1,7 @@
<?php <?php
namespace Froxlor;
use Froxlor\Database as Database;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -48,7 +51,7 @@ class SImExporter
'system.mysql_access_host', 'system.mysql_access_host',
'system.lastcronrun', 'system.lastcronrun',
'system.defaultip', 'system.defaultip',
'system.defaultsslip'. 'system.defaultsslip',
'system.last_tasks_run', 'system.last_tasks_run',
'system.last_archive_run', 'system.last_archive_run',
'system.leprivatekey', 'system.leprivatekey',
@@ -61,7 +64,7 @@ class SImExporter
SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` ORDER BY `settingid` ASC SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` ORDER BY `settingid` ASC
"); ");
$_data = array(); $_data = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
$index = $row['settinggroup'] . "." . $row['varname']; $index = $row['settinggroup'] . "." . $row['varname'];
if (! in_array($index, self::$_no_export)) { if (! in_array($index, self::$_no_export)) {
$_data[$index] = $row['value']; $_data[$index] = $row['value'];
@@ -71,7 +74,7 @@ class SImExporter
$_data['_sha'] = sha1(var_export($_data, true)); $_data['_sha'] = sha1(var_export($_data, true));
$_export = json_encode($_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); $_export = json_encode($_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
if (! $_export) { if (! $_export) {
throw new Exception("Error exporting settings: " . json_last_error_msg()); throw new \Exception("Error exporting settings: " . json_last_error_msg());
} }
return $_export; return $_export;
} }
@@ -87,13 +90,13 @@ class SImExporter
$_dbversion = isset($_data['panel.db_version']) ? $_data['panel.db_version'] : false; $_dbversion = isset($_data['panel.db_version']) ? $_data['panel.db_version'] : false;
// check if we have everything we need // check if we have everything we need
if (! $_sha || ! $_version || ! $_dbversion) { if (! $_sha || ! $_version || ! $_dbversion) {
throw new Exception("Invalid froxlor settings data. Unable to import."); throw new \Exception("Invalid froxlor settings data. Unable to import.");
} }
// validate import file // validate import file
unset($_data['_sha']); unset($_data['_sha']);
// compare // compare
if ($_sha != sha1(var_export($_data, true))) { if ($_sha != sha1(var_export($_data, true))) {
throw new Exception("SHA check of import data failed. Unable to import."); throw new \Exception("SHA check of import data failed. Unable to import.");
} }
// do not import version info - but we need that to possibily update settings // do not import version info - but we need that to possibily update settings
// when there were changes in the variable-name or similar // when there were changes in the variable-name or similar
@@ -124,6 +127,6 @@ class SImExporter
// all good // all good
return true; return true;
} }
throw new Exception("Invalid JSON data: " . json_last_error_msg()); throw new \Exception("Invalid JSON data: " . json_last_error_msg());
} }
} }