put Api-Commands into namespaces
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
8
api.php
8
api.php
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
require __DIR__ . '/lib/classes/api/api_includes.inc.php';
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// check whether API interface is enabled after all
|
||||
if (Settings::Get('api.enabled') != 1) {
|
||||
if (\Froxlor\Settings::Get('api.enabled') != 1) {
|
||||
// not enabled
|
||||
header("Status: 404 Not found", 404);
|
||||
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not found", 404);
|
||||
@@ -30,9 +30,9 @@ if (is_null($decoded_request)) {
|
||||
|
||||
// validate content
|
||||
try {
|
||||
$request = FroxlorRPC::validateRequest($decoded_request);
|
||||
$request = \Froxlor\Api\FroxlorRPC::validateRequest($decoded_request);
|
||||
// now actually do it
|
||||
$cls = $request['command']['class'];
|
||||
$cls = "\Froxlor\Api\Commands\\" . $request['command']['class'];
|
||||
$method = $request['command']['method'];
|
||||
$apiObj = new $cls($decoded_request['header'], $request['params']);
|
||||
// call the method with the params if any
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace Froxlor\Api;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,12 +9,12 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
abstract class ApiCommand extends ApiParameter
|
||||
{
|
||||
@@ -42,14 +43,14 @@ abstract class ApiCommand extends ApiParameter
|
||||
/**
|
||||
* logger interface
|
||||
*
|
||||
* @var FroxlorLogger
|
||||
* @var \FroxlorLogger
|
||||
*/
|
||||
private $logger = null;
|
||||
|
||||
/**
|
||||
* mail interface
|
||||
*
|
||||
* @var PHPMailer
|
||||
* @var \PHPMailer
|
||||
*/
|
||||
private $mail = null;
|
||||
|
||||
@@ -90,11 +91,11 @@ abstract class ApiCommand extends ApiParameter
|
||||
* @param array $userinfo
|
||||
* optional, passed via WebInterface (instead of $header)
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($header = null, $params = null, $userinfo = null)
|
||||
{
|
||||
global $lng, $version, $dbversion, $branding;
|
||||
global $version, $dbversion, $branding;
|
||||
|
||||
parent::__construct($params);
|
||||
|
||||
@@ -108,14 +109,14 @@ abstract class ApiCommand extends ApiParameter
|
||||
$this->user_data = $userinfo;
|
||||
$this->is_admin = (isset($userinfo['adminsession']) && $userinfo['adminsession'] == 1 && $userinfo['adminid'] > 0) ? true : false;
|
||||
} else {
|
||||
throw new Exception("Invalid user data", 500);
|
||||
throw new \Exception("Invalid user data", 500);
|
||||
}
|
||||
$this->logger = FroxlorLogger::getInstanceOf($this->user_data);
|
||||
$this->logger = \FroxlorLogger::getInstanceOf($this->user_data);
|
||||
|
||||
// check whether the user is deactivated
|
||||
if ($this->getUserDetail('deactivated') == 1) {
|
||||
$this->logger()->logAction(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();
|
||||
@@ -135,17 +136,17 @@ abstract class ApiCommand extends ApiParameter
|
||||
global $lng;
|
||||
|
||||
// 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();
|
||||
// presort languages
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$langs[$row['language']][] = $row;
|
||||
}
|
||||
|
||||
// set default language before anything else to
|
||||
// ensure that we can display messages
|
||||
$language = Settings::Get('panel.standardlanguage');
|
||||
$language = \Froxlor\Settings::Get('panel.standardlanguage');
|
||||
|
||||
if (isset($this->user_data['language']) && isset($langs[$this->user_data['language']])) {
|
||||
// default: use language from session, #277
|
||||
@@ -156,14 +157,14 @@ abstract class ApiCommand extends ApiParameter
|
||||
|
||||
// include every english language file we can get
|
||||
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
|
||||
if ($language != 'English') {
|
||||
if (isset($langs[$language])) {
|
||||
foreach ($langs[$language] as $value) {
|
||||
include_once makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']);
|
||||
include_once \Froxlor\FileDir::makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']);
|
||||
}
|
||||
} else {
|
||||
if ($this->debug) {
|
||||
@@ -181,35 +182,36 @@ abstract class ApiCommand extends ApiParameter
|
||||
|
||||
/**
|
||||
* initialize mail interface so an API wide mail-object is available
|
||||
* @throws phpmailerException
|
||||
*
|
||||
* @throws \phpmailerException
|
||||
*/
|
||||
private function initMail()
|
||||
{
|
||||
/**
|
||||
* Initialize the mailingsystem
|
||||
*/
|
||||
$this->mail = new PHPMailer(true);
|
||||
$this->mail = new \PHPMailer(true);
|
||||
$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->Host = Settings::Get('system.mail_smtp_host');
|
||||
$this->mail->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
|
||||
$this->mail->Username = Settings::Get('system.mail_smtp_user');
|
||||
$this->mail->Password = Settings::Get('system.mail_smtp_passwd');
|
||||
if (Settings::Get('system.mail_smtp_usetls')) {
|
||||
$this->mail->Host = \Froxlor\Settings::Get('system.mail_smtp_host');
|
||||
$this->mail->SMTPAuth = \Froxlor\Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
|
||||
$this->mail->Username = \Froxlor\Settings::Get('system.mail_smtp_user');
|
||||
$this->mail->Password = \Froxlor\Settings::Get('system.mail_smtp_passwd');
|
||||
if (\Froxlor\Settings::Get('system.mail_smtp_usetls')) {
|
||||
$this->mail->SMTPSecure = 'tls';
|
||||
} else {
|
||||
$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
|
||||
$this->mail->setFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
|
||||
if (Settings::Get('panel.adminmail_return') != '') {
|
||||
$this->mail->addReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname'));
|
||||
$this->mail->setFrom(\Froxlor\Settings::Get('panel.adminmail'), \Froxlor\Settings::Get('panel.adminmail_defname'));
|
||||
if (\Froxlor\Settings::Get('panel.adminmail_return') != '') {
|
||||
$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
|
||||
*
|
||||
* @return ApiCommand
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getLocal($userinfo = null, $params = null)
|
||||
{
|
||||
@@ -267,7 +269,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
/**
|
||||
* return logger instance
|
||||
*
|
||||
* @return FroxlorLogger
|
||||
* @return \FroxlorLogger
|
||||
*/
|
||||
protected function logger()
|
||||
{
|
||||
@@ -277,7 +279,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
/**
|
||||
* return mailer instance
|
||||
*
|
||||
* @return PHPMailer
|
||||
* @return \PHPMailer
|
||||
*/
|
||||
protected function mailer()
|
||||
{
|
||||
@@ -295,7 +297,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
protected function apiCall($command = null, $params = null)
|
||||
{
|
||||
$_command = explode(".", $command);
|
||||
$module = $_command[0];
|
||||
$module = __NAMESPACE__ . "\Commands\\" . $_command[0];
|
||||
$function = $_command[1];
|
||||
$json_result = $module::getLocal($this->getUserData(), $params)->{$function}();
|
||||
return json_decode($json_result, true)['data'];
|
||||
@@ -335,7 +337,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
* @param string $customer_hide_option
|
||||
* optional, when called as customer, some options might be hidden due to the panel.customer_hide_options ettings
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllowedCustomerIds($customer_hide_option = '')
|
||||
@@ -363,15 +365,15 @@ abstract class ApiCommand extends ApiParameter
|
||||
$customer_ids[] = $customer['customerid'];
|
||||
}
|
||||
} else {
|
||||
if (! empty($customer_hide_option) && Settings::IsInList('panel.customer_hide_options', $customer_hide_option)) {
|
||||
throw new Exception("You cannot access this resource", 405);
|
||||
if (! empty($customer_hide_option) && \Froxlor\Settings::IsInList('panel.customer_hide_options', $customer_hide_option)) {
|
||||
throw new \Exception("You cannot access this resource", 405);
|
||||
}
|
||||
$customer_ids = array(
|
||||
$this->getUserDetail('customerid')
|
||||
);
|
||||
}
|
||||
if (empty($customer_ids)) {
|
||||
throw new Exception("Required resource unsatisfied.", 405);
|
||||
throw new \Exception("Required resource unsatisfied.", 405);
|
||||
}
|
||||
return $customer_ids;
|
||||
}
|
||||
@@ -386,7 +388,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
* @param string $customer_resource_check
|
||||
* optional, when called as admin, check the resources of the target customer
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function getCustomerData($customer_resource_check = '')
|
||||
@@ -400,7 +402,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
));
|
||||
// check whether the customer has enough resources
|
||||
if (! empty($customer_resource_check) && $customer[$customer_resource_check . '_used'] >= $customer[$customer_resource_check] && $customer[$customer_resource_check] != '-1') {
|
||||
throw new Exception("Customer has no more resources available", 406);
|
||||
throw new \Exception("Customer has no more resources available", 406);
|
||||
}
|
||||
} else {
|
||||
$customer = $this->getUserData();
|
||||
@@ -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)
|
||||
{
|
||||
$stmt = Database::prepare("
|
||||
$stmt = \Froxlor\Database\Database::prepare("
|
||||
UPDATE `" . $table . "`
|
||||
SET `" . $resource . "` = `" . $resource . "` " . $operator . " " . (int) $step . " " . $extra . "
|
||||
WHERE `" . $keyfield . "` = :key
|
||||
");
|
||||
Database::pexecute($stmt, array(
|
||||
\Froxlor\Database\Database::pexecute($stmt, array(
|
||||
'key' => $key
|
||||
), true, true);
|
||||
}
|
||||
@@ -444,16 +446,17 @@ abstract class ApiCommand extends ApiParameter
|
||||
protected function getMailTemplate($customerdata = null, $group = null, $varname = null, $replace_arr = array(), $default = "")
|
||||
{
|
||||
// get template
|
||||
$stmt = Database::prepare("
|
||||
$stmt = \Froxlor\Database\Database::prepare("
|
||||
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` WHERE `adminid`= :adminid
|
||||
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'],
|
||||
"lang" => $customerdata['def_language'],
|
||||
"group" => $group,
|
||||
"var" => $varname
|
||||
), true, true);
|
||||
// @fixme html_entity_decode
|
||||
$content = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default), $replace_arr));
|
||||
return $content;
|
||||
}
|
||||
@@ -464,13 +467,13 @@ abstract class ApiCommand extends ApiParameter
|
||||
* @param array $header
|
||||
* api-request header
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return boolean
|
||||
*/
|
||||
private function readUserData($header = null)
|
||||
{
|
||||
$sel_stmt = Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
|
||||
$result = Database::pexecute_first($sel_stmt, array(
|
||||
$sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
|
||||
$result = \Froxlor\Database\Database::pexecute_first($sel_stmt, array(
|
||||
'ak' => $header['apikey'],
|
||||
'as' => $header['secret']
|
||||
), true, true);
|
||||
@@ -486,10 +489,10 @@ abstract class ApiCommand extends ApiParameter
|
||||
$key = "customerid";
|
||||
} else {
|
||||
// neither adminid is > 0 nor customerid is > 0 - sorry man, no way
|
||||
throw new Exception("Invalid API credentials", 400);
|
||||
throw new \Exception("Invalid API credentials", 400);
|
||||
}
|
||||
$sel_stmt = Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id");
|
||||
$this->user_data = Database::pexecute_first($sel_stmt, array(
|
||||
$sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `" . $table . "` WHERE `" . $key . "` = :id");
|
||||
$this->user_data = \Froxlor\Database\Database::pexecute_first($sel_stmt, array(
|
||||
'id' => ($this->is_admin ? $result['adminid'] : $result['customerid'])
|
||||
), true, true);
|
||||
if ($this->is_admin) {
|
||||
@@ -497,6 +500,6 @@ abstract class ApiCommand extends ApiParameter
|
||||
}
|
||||
return true;
|
||||
}
|
||||
throw new Exception("Invalid API credentials", 400);
|
||||
throw new \Exception("Invalid API credentials", 400);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace Froxlor\Api;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,12 +9,12 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
abstract class ApiParameter
|
||||
{
|
||||
@@ -30,7 +31,7 @@ abstract class ApiParameter
|
||||
* @param array $params
|
||||
* optional, array of parameters (var=>value) for the command
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($params = null)
|
||||
{
|
||||
@@ -52,7 +53,7 @@ abstract class ApiParameter
|
||||
* @param mixed $default
|
||||
* value which is returned if optional=true and param is not set
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getParam($param = null, $optional = false, $default = '')
|
||||
@@ -62,7 +63,7 @@ abstract class ApiParameter
|
||||
if ($optional === false) {
|
||||
// get module + function for better error-messages
|
||||
$inmod = $this->getModFunctionString();
|
||||
throw new Exception('Requested parameter "' . $param . '" could not be found for "' . $inmod . '"', 404);
|
||||
throw new \Exception('Requested parameter "' . $param . '" could not be found for "' . $inmod . '"', 404);
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
@@ -71,7 +72,7 @@ abstract class ApiParameter
|
||||
if ($optional === false) {
|
||||
// get module + function for better error-messages
|
||||
$inmod = $this->getModFunctionString();
|
||||
throw new Exception('Requested parameter "' . $param . '" is empty where it should not be for "' . $inmod . '"', 406);
|
||||
throw new \Exception('Requested parameter "' . $param . '" is empty where it should not be for "' . $inmod . '"', 406);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -88,7 +89,7 @@ abstract class ApiParameter
|
||||
* default: false
|
||||
* @param mixed $default
|
||||
* value which is returned if optional=true and param is not set
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBoolParam($param = null, $optional = false, $default = false)
|
||||
@@ -117,7 +118,7 @@ abstract class ApiParameter
|
||||
* value which is returned if optional=true and param is not set
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getUlParam($param = null, $ul_field = null, $optional = false, $default = 0)
|
||||
{
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,21 +12,21 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class Admins extends ApiCommand implements ResourceEntity
|
||||
class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* lists all admin entries
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -36,7 +40,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
Database::pexecute($result_stmt, null, true, true);
|
||||
$result = array();
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successfull", array(
|
||||
@@ -44,7 +48,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -78,9 +82,9 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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)
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -199,7 +203,8 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
|
||||
// validation
|
||||
$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));
|
||||
$def_language = validate($def_language, 'default language', '', '', 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);
|
||||
}
|
||||
}
|
||||
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)
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -456,7 +461,8 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
if ($this->getUserDetail('change_serversettings') == 1 || $result['adminid'] == $this->getUserDetail('adminid')) {
|
||||
// parameters
|
||||
$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']));
|
||||
$password = $this->getParam('admin_password', true, '');
|
||||
$def_language = $this->getParam('def_language', true, $result['def_language']);
|
||||
@@ -515,7 +521,8 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
|
||||
// validation
|
||||
$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));
|
||||
$def_language = validate($def_language, 'default language', '', '', 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)) {
|
||||
throw new Exception($res_warning, 406);
|
||||
throw new \Exception($res_warning, 406);
|
||||
}
|
||||
|
||||
$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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -781,7 +788,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
||||
updateCounters();
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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'] . "'");
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -43,7 +47,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
$domainname = $this->getParam('domainname', $dn_optional, '');
|
||||
|
||||
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(
|
||||
@@ -70,7 +74,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -92,7 +96,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
$domainname = $this->getParam('domainname', $dn_optional, '');
|
||||
|
||||
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(
|
||||
@@ -124,7 +128,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
* optional
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -134,7 +138,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
$domainname = $this->getParam('domainname', $dn_optional, '');
|
||||
|
||||
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(
|
||||
@@ -159,7 +163,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
* lists all certificate entries
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -187,7 +191,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
$certs_stmt = Database::prepare($certs_stmt_query);
|
||||
Database::pexecute($certs_stmt, $qry_params, true, true);
|
||||
$result = array();
|
||||
while ($cert = $certs_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($cert = $certs_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
// respect froxlor-hostname
|
||||
if ($cert['domainid'] == 0) {
|
||||
$cert['domain'] = Settings::Get('system.hostname');
|
||||
@@ -208,7 +212,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
* @param int $id
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
@@ -263,7 +267,7 @@ class Certificates extends ApiCommand implements ResourceEntity
|
||||
* optional default false
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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()
|
||||
{
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -50,9 +54,9 @@ class Cronjobs extends ApiCommand implements ResourceEntity
|
||||
if ($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)
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -118,14 +122,14 @@ class Cronjobs extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -137,7 +141,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
Database::pexecute($result_stmt);
|
||||
$result = array();
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successfull", array(
|
||||
@@ -145,7 +149,7 @@ class Cronjobs extends ApiCommand implements ResourceEntity
|
||||
'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()
|
||||
{
|
||||
throw new Exception('You cannot delete system cronjobs.', 303);
|
||||
throw new \Exception('You cannot delete system cronjobs.', 303);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,31 +12,31 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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)
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function validateAccess()
|
||||
{
|
||||
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')) {
|
||||
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')) {
|
||||
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
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
@@ -114,7 +118,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
|
||||
*/
|
||||
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()
|
||||
{
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
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'");
|
||||
Database::pexecute($sel_stmt);
|
||||
$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);
|
||||
if (in_array($entry['data']['customerid'], $customer_ids)) {
|
||||
$result[] = $entry;
|
||||
@@ -172,7 +176,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
|
||||
* optional, required when called as admin (if $customerid is not specified)
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,21 +12,21 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class Customers extends ApiCommand implements ResourceEntity
|
||||
class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* lists all customer entries
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -44,7 +48,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
Database::pexecute($result_stmt, $params, true, true);
|
||||
$result = array();
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successfull", array(
|
||||
@@ -52,7 +56,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
'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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -86,7 +90,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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("
|
||||
SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
||||
@@ -105,7 +109,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -263,7 +267,8 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
$city = validate($city, 'city', '', '', array(), true);
|
||||
$phone = validate($phone, 'phone', '/^[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));
|
||||
$customernumber = validate($customernumber, 'customer number', '/^[A-Za-z0-9 \-]*$/Di', '', array(), true);
|
||||
$def_language = validate($def_language, 'default language', '', '', array(), true);
|
||||
@@ -639,7 +644,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
try {
|
||||
$std_domain = $this->apiCall('Domains.add', $ins_data);
|
||||
$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());
|
||||
}
|
||||
|
||||
@@ -713,10 +718,10 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
'company' => $company
|
||||
)));
|
||||
$this->mailer()->send();
|
||||
} catch (phpmailerException $e) {
|
||||
} catch (\phpmailerException $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
@@ -737,9 +742,9 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -863,7 +868,8 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
// parameters
|
||||
$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']));
|
||||
$name = $this->getParam('name', true, $result['name']);
|
||||
$firstname = $this->getParam('firstname', true, $result['firstname']);
|
||||
@@ -911,7 +917,8 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
|
||||
// validation
|
||||
if ($this->isAdmin()) {
|
||||
$idna_convert = new idna_convert_wrapper();
|
||||
// @fixme idna
|
||||
$idna_convert = new \idna_convert_wrapper();
|
||||
$name = validate($name, 'name', '', '', array(), true);
|
||||
$firstname = validate($firstname, 'first name', '', '', array(), true);
|
||||
$company = validate($company, 'company', '', '', array(), true);
|
||||
@@ -991,7 +998,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
try {
|
||||
$std_domain = $this->apiCall('Domains.add', $ins_data);
|
||||
$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());
|
||||
}
|
||||
|
||||
@@ -1014,7 +1021,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
'id' => $result['standardsubdomain'],
|
||||
'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_NOTICE, "[API] automatically deleted standardsubdomain for user '" . $result['loginname'] . "'");
|
||||
@@ -1086,10 +1093,11 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
Database::needRoot(true);
|
||||
$last_dbserver = 0;
|
||||
|
||||
$dbm = new DbManager($this->logger());
|
||||
// @fixme dbManager
|
||||
$dbm = new \DbManager($this->logger());
|
||||
|
||||
// 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']) {
|
||||
$dbm->getManager()->flushPrivileges();
|
||||
@@ -1377,7 +1385,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
* optional, default false
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -1405,9 +1413,10 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
Database::needRoot(true);
|
||||
$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']) {
|
||||
Database::needRoot(true, $row_database['dbserver']);
|
||||
$dbm->getManager()->flushPrivileges();
|
||||
@@ -1435,7 +1444,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($did_stmt, array(
|
||||
'id' => $id
|
||||
), true, true);
|
||||
while ($row = $did_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $did_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
// remove domain->ip connection
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_domain` = :did");
|
||||
Database::pexecute($stmt, array(
|
||||
@@ -1501,7 +1510,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($result2_stmt, array(
|
||||
'id' => $id
|
||||
), true, true);
|
||||
while ($row = $result2_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result2_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
// delete ftp-quotatallies by username
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_FTP_QUOTATALLIES . "` WHERE `name` = :name");
|
||||
Database::pexecute($stmt, array(
|
||||
@@ -1595,11 +1604,12 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
inserttask('10');
|
||||
|
||||
// move old tickets to archive
|
||||
$tickets = ticket::customerHasTickets($id);
|
||||
// @fixme ticket
|
||||
$tickets = \ticket::customerHasTickets($id);
|
||||
if ($tickets !== false && isset($tickets[0])) {
|
||||
foreach ($tickets as $ticket) {
|
||||
$now = time();
|
||||
$mainticket = ticket::getInstanceOf($result, (int) $ticket);
|
||||
$mainticket = \ticket::getInstanceOf($result, (int) $ticket);
|
||||
$mainticket->Set('lastchange', $now, true, true);
|
||||
$mainticket->Set('lastreplier', '1', 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'] . "'");
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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'] . "'");
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function move()
|
||||
@@ -1688,7 +1698,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
|
||||
// check if target-admin is the current admin
|
||||
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
|
||||
@@ -1733,7 +1743,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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')) {
|
||||
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
|
||||
@@ -134,13 +138,13 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
||||
* id of dir-protection entry
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
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);
|
||||
@@ -169,7 +173,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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("
|
||||
SELECT * FROM `" . TABLE_PANEL_HTACCESS . "`
|
||||
@@ -185,7 +189,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
{
|
||||
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');
|
||||
|
||||
@@ -299,7 +303,7 @@ class DirOptions extends ApiCommand implements ResourceEntity
|
||||
WHERE `customerid` IN (" . implode(', ', $customer_ids) . ")
|
||||
");
|
||||
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;
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
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');
|
||||
|
||||
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
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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')) {
|
||||
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
|
||||
@@ -125,13 +129,13 @@ class DirProtections extends ApiCommand implements ResourceEntity
|
||||
* optional, the username
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
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);
|
||||
@@ -162,7 +166,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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("
|
||||
SELECT * FROM `" . TABLE_PANEL_HTPASSWDS . "`
|
||||
@@ -178,7 +182,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
{
|
||||
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');
|
||||
|
||||
@@ -292,7 +296,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
|
||||
WHERE `customerid` IN (" . implode(', ', $customer_ids) . ")
|
||||
");
|
||||
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;
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
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);
|
||||
@@ -325,7 +329,7 @@ class DirProtections extends ApiCommand implements ResourceEntity
|
||||
$username = $this->getParam('username', $un_optional, '');
|
||||
|
||||
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
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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);
|
||||
@@ -65,14 +69,15 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
||||
$ttl = $this->getParam('ttl', true, 18000);
|
||||
|
||||
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') {
|
||||
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']);
|
||||
|
||||
// select all entries
|
||||
@@ -80,7 +85,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($sel_stmt, array(
|
||||
'did' => $id
|
||||
), true, true);
|
||||
$dom_entries = $sel_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$dom_entries = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// validation
|
||||
$errors = array();
|
||||
@@ -285,7 +290,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
// 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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
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);
|
||||
@@ -318,7 +323,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
||||
$id = $result['id'];
|
||||
|
||||
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') {
|
||||
@@ -338,7 +343,7 @@ class DomainZones extends ApiCommand implements ResourceEntity
|
||||
*/
|
||||
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()
|
||||
{
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
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');
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,21 +12,21 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class Domains extends ApiCommand implements ResourceEntity
|
||||
class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* lists all domain entries
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -43,7 +47,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
Database::pexecute($result_stmt, $params);
|
||||
$result = array();
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successfull", array(
|
||||
@@ -51,7 +55,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -78,7 +82,8 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
|
||||
// convert possible idn domain to punycode
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -100,9 +105,9 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -235,7 +240,8 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
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(
|
||||
'/\:(\d)+$/',
|
||||
'/^https?\:\/\//'
|
||||
@@ -446,7 +452,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
'id' => $aliasdomain
|
||||
), true, true);
|
||||
$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(
|
||||
'ipid' => $origip['id_ipandports']
|
||||
), true, true);
|
||||
@@ -498,7 +504,8 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
$issubof = '0';
|
||||
}
|
||||
|
||||
$idna_convert = new idna_convert_wrapper();
|
||||
// @fixme idna
|
||||
$idna_convert = new \idna_convert_wrapper();
|
||||
if ($domain == '') {
|
||||
standard_error(array(
|
||||
'stringisempty',
|
||||
@@ -648,9 +655,9 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -829,7 +836,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
$email_forwarders = 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'] != '') {
|
||||
$domain_emails_row['destination'] = explode(' ', makeCorrectDestination($domain_emails_row['destination']));
|
||||
$email_forwarders += count($domain_emails_row['destination']);
|
||||
@@ -1086,7 +1093,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
'aliasdomain' => $aliasdomain
|
||||
), true, true);
|
||||
$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(
|
||||
'ipid' => $origip['id_ipandports']
|
||||
), true, true);
|
||||
@@ -1413,7 +1420,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
'id' => $id
|
||||
), true, true);
|
||||
|
||||
while ($row = $domainidsresult_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $domainidsresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
||||
$del_stmt = Database::prepare("
|
||||
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'] . "'");
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -1509,7 +1516,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
), true, true);
|
||||
$idString = 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'];
|
||||
$paramString['domain_' . $subRow['id']] = $subRow['id'];
|
||||
}
|
||||
@@ -1619,7 +1626,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
inserttask('4');
|
||||
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
|
||||
* default false
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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
|
||||
// this is not required for ssl-enabled ip's
|
||||
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
|
||||
@@ -1694,7 +1701,7 @@ class Domains extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($ipsresult_stmt, array(
|
||||
'id' => $edit_id
|
||||
), true, true);
|
||||
while ($ipsresultrow = $ipsresult_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($ipsresultrow = $ipsresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$ipandports[] = $ipsresultrow['id_ipandports'];
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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)
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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') {
|
||||
@@ -78,13 +82,14 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
$id = $result['id'];
|
||||
|
||||
$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);
|
||||
$password = validate($email_password, 'password', '', '', array(), true);
|
||||
$password = validatePassword($password, true);
|
||||
|
||||
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)) {
|
||||
@@ -215,10 +220,10 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
|
||||
$this->mailer()->addAddress($email_full);
|
||||
$this->mailer()->send();
|
||||
} catch (phpmailerException $e) {
|
||||
} catch (\phpmailerException $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
@@ -245,10 +250,10 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
|
||||
$this->mailer()->addAddress($idna_convert->encode($alternative_email), getCorrectUserSalutation($customer));
|
||||
$this->mailer()->send();
|
||||
} catch (phpmailerException $e) {
|
||||
} catch (\phpmailerException $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
@@ -270,7 +275,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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()
|
||||
{
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
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
|
||||
@@ -321,7 +326,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
$id = $result['id'];
|
||||
|
||||
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, '');
|
||||
@@ -393,7 +398,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
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
|
||||
@@ -434,7 +439,7 @@ class EmailAccounts extends ApiCommand implements ResourceEntity
|
||||
$id = $result['id'];
|
||||
|
||||
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
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
@@ -15,7 +18,7 @@
|
||||
* @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
|
||||
*
|
||||
* @access admin,customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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') {
|
||||
@@ -51,7 +54,8 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
$destination = $this->getParam('destination');
|
||||
|
||||
// validation
|
||||
$idna_convert = new idna_convert_wrapper();
|
||||
// @fixme idna
|
||||
$idna_convert = new \idna_convert_wrapper();
|
||||
$destination = $idna_convert->encode($destination);
|
||||
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
@@ -103,7 +107,7 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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
|
||||
*
|
||||
* @access admin,customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
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
|
||||
@@ -205,6 +209,6 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
throw new Exception("Unknown forwarder id", 404);
|
||||
throw new \Exception("Unknown forwarder id", 404);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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') {
|
||||
@@ -53,7 +57,8 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
|
||||
// validation
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -138,7 +143,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -175,7 +180,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
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
|
||||
@@ -266,7 +271,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
* optional, admin-only, select email addresses of a specific customer by loginname
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -281,7 +286,7 @@ class Emails extends ApiCommand implements ResourceEntity
|
||||
WHERE m.`customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||
");
|
||||
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;
|
||||
}
|
||||
$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)
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
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);
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,21 +12,21 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -35,7 +39,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
|
||||
$fpmdaemons = array();
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
||||
$query_params = array(
|
||||
'id' => $row['id']
|
||||
@@ -48,7 +52,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
|
||||
$configs = array();
|
||||
if (Database::num_rows() > 0) {
|
||||
while ($row2 = $configresult_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row2 = $configresult_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$configs[] = $row2['description'];
|
||||
}
|
||||
}
|
||||
@@ -66,7 +70,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -93,9 +97,9 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
if ($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'
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -153,7 +157,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
'dynamic',
|
||||
'ondemand'
|
||||
))) {
|
||||
throw new ErrorException("Unknown process manager", 406);
|
||||
throw new \Exception("Unknown process manager", 406);
|
||||
}
|
||||
if (empty($limit_extensions)) {
|
||||
$limit_extensions = '.php';
|
||||
@@ -201,7 +205,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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'
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -269,7 +273,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
'dynamic',
|
||||
'ondemand'
|
||||
))) {
|
||||
throw new ErrorException("Unknown process manager", 406);
|
||||
throw new \Exception("Unknown process manager", 406);
|
||||
}
|
||||
if (empty($limit_extensions)) {
|
||||
$limit_extensions = '.php';
|
||||
@@ -318,7 +322,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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') . "'");
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,21 +12,21 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class Froxlor extends ApiCommand
|
||||
class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* checks whether there is a newer version of froxlor available
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function checkUpdate()
|
||||
@@ -35,7 +39,7 @@ class Froxlor extends ApiCommand
|
||||
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
|
||||
|
||||
// check for new version
|
||||
$latestversion = HttpClient::urlGet(UPDATE_URI);
|
||||
$latestversion = \Froxlor\Http\HttpClient::urlGet(UPDATE_URI);
|
||||
$latestversion = explode('|', $latestversion);
|
||||
|
||||
if (is_array($latestversion) && count($latestversion) >= 1) {
|
||||
@@ -89,13 +93,13 @@ class Froxlor extends ApiCommand
|
||||
}
|
||||
return $this->response(300, "successfull", array(
|
||||
'isnewerversion' => 0,
|
||||
'version' => $this->version.$this->branding,
|
||||
'version' => $this->version . $this->branding,
|
||||
'message' => 'Version-check not available due to missing php-curl extension',
|
||||
'link' => UPDATE_URI.'/pretty',
|
||||
'link' => UPDATE_URI . '/pretty',
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function importSettings()
|
||||
@@ -114,7 +118,7 @@ class Froxlor extends ApiCommand
|
||||
$json_str = $this->getParam('json_str');
|
||||
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "User " . $this->getUserDetail('loginname') . " imported settings");
|
||||
try {
|
||||
SImExporter::import($json_str);
|
||||
\Froxlor\SImExporter::import($json_str);
|
||||
inserttask('1');
|
||||
inserttask('10');
|
||||
// Using nameserver, insert a task which rebuilds the server config
|
||||
@@ -122,35 +126,35 @@ class Froxlor extends ApiCommand
|
||||
// cron.d file
|
||||
inserttask('99');
|
||||
return $this->response(200, "successfull", true);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception($e->getMessage(), 406);
|
||||
} catch (\Exception $e) {
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return string json-string
|
||||
*/
|
||||
public function exportSettings()
|
||||
{
|
||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||
$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);
|
||||
}
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listSettings()
|
||||
@@ -161,7 +165,7 @@ class Froxlor extends ApiCommand
|
||||
");
|
||||
Database::pexecute($sel_stmt, null, true, true);
|
||||
$result = array();
|
||||
while ($row = $sel_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = array(
|
||||
'key' => $row['settinggroup'] . '.' . $row['varname'],
|
||||
'value' => $row['value']
|
||||
@@ -172,7 +176,7 @@ class Froxlor extends ApiCommand
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function getSetting()
|
||||
@@ -191,7 +195,7 @@ class Froxlor extends ApiCommand
|
||||
$setting = $this->getParam('key');
|
||||
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 ''
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function updateSetting()
|
||||
{
|
||||
// currently not implemented as it required validation too so no wrong settings are being stored via API
|
||||
throw new Exception("Not available yet.", 501);
|
||||
throw new \Exception("Not available yet.", 501);
|
||||
|
||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||
$setting = $this->getParam('key');
|
||||
$value = $this->getParam('value', true, '');
|
||||
$oldvalue = Settings::Get($setting);
|
||||
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 . "'");
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function listFunctions()
|
||||
@@ -255,7 +259,7 @@ class Froxlor extends ApiCommand
|
||||
}
|
||||
} else {
|
||||
// check all the modules
|
||||
$path = FROXLOR_INSTALL_DIR . '/lib/classes/api/commands/';
|
||||
$path = \Froxlor\Froxlor::getInstallDir() . '/lib/Froxlor/Api/Commands/';
|
||||
// valid directory?
|
||||
if (is_dir($path)) {
|
||||
// create RecursiveIteratorIterator
|
||||
@@ -264,13 +268,13 @@ class Froxlor extends ApiCommand
|
||||
foreach ($its as $it) {
|
||||
// does it match the Filename pattern?
|
||||
$matches = array();
|
||||
if (preg_match("/^class\.(.+)\.php$/i", $it->getFilename(), $matches)) {
|
||||
if (preg_match("/^(.+)\.php$/i", $it->getFilename(), $matches)) {
|
||||
// check for existence
|
||||
try {
|
||||
// set the module to be in our namespace
|
||||
$mod = $matches[1];
|
||||
$this->requireModules($mod);
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
// @todo log?
|
||||
continue;
|
||||
}
|
||||
@@ -289,7 +293,7 @@ class Froxlor extends ApiCommand
|
||||
}
|
||||
} else {
|
||||
// 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 $function
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array|bool
|
||||
*/
|
||||
private function getParamListFromDoc($module = null, $function = null)
|
||||
@@ -396,7 +400,7 @@ class Froxlor extends ApiCommand
|
||||
*
|
||||
* @param string|array $modules
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function requireModules($modules = null)
|
||||
{
|
||||
@@ -410,17 +414,18 @@ class Froxlor extends ApiCommand
|
||||
// check all the modules
|
||||
foreach ($modules as $module) {
|
||||
try {
|
||||
$module = "\Froxlor\Api\Commands\\" . $module;
|
||||
// can we use the class?
|
||||
if (class_exists($module)) {
|
||||
continue;
|
||||
} 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
|
||||
// that the required class could not be found
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class Ftps extends ApiCommand implements ResourceEntity
|
||||
class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -39,56 +43,57 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
* required when called as admin, not needed when called as customer
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
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') {
|
||||
|
||||
|
||||
// required paramters
|
||||
$path = $this->getParam('path');
|
||||
$password = $this->getParam('ftp_password');
|
||||
|
||||
|
||||
// parameters
|
||||
$description = $this->getParam('ftp_description', true, '');
|
||||
$sendinfomail = $this->getBoolParam('sendinfomail', true, 0);
|
||||
$shell = $this->getParam('shell', true, '/bin/false');
|
||||
|
||||
|
||||
$ftpusername = $this->getParam('ftp_username', true, '');
|
||||
$ftpdomain = $this->getParam('ftp_domain', true, '');
|
||||
|
||||
|
||||
// validation
|
||||
$password = validate($password, 'password', '', '', array(), true);
|
||||
$password = validatePassword($password, true);
|
||||
$description = validate(trim($description), 'description', '', '', array(), true);
|
||||
|
||||
|
||||
if (Settings::Get('system.allow_customer_shell') == '1') {
|
||||
$shell = validate(trim($shell), 'shell', '', '', array(), true);
|
||||
} else {
|
||||
$shell = "/bin/false";
|
||||
}
|
||||
|
||||
|
||||
if (Settings::Get('customer.ftpatdomain') == '1') {
|
||||
$ftpusername = validate(trim($ftpusername), 'username', '/^[a-zA-Z0-9][a-zA-Z0-9\-_]+\$?$/', '', array(), true);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$params = array();
|
||||
// get needed customer info to reduce the ftp-user-counter by one
|
||||
$customer = $this->getCustomerData('ftps');
|
||||
|
||||
|
||||
if ($sendinfomail != 1) {
|
||||
$sendinfomail = 0;
|
||||
}
|
||||
|
||||
|
||||
if (Settings::Get('customer.ftpatdomain') == '1') {
|
||||
if ($ftpusername == '') {
|
||||
standard_error(array(
|
||||
@@ -103,7 +108,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
"domain" => $ftpdomain,
|
||||
"customerid" => $customer['customerid']
|
||||
), true, true);
|
||||
|
||||
|
||||
if ($ftpdomain_check && $ftpdomain_check['domain'] != $ftpdomain) {
|
||||
standard_error('maindomainnonexist', $ftpdomain, true);
|
||||
}
|
||||
@@ -111,14 +116,14 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
} else {
|
||||
$username = $customer['loginname'] . Settings::Get('customer.ftpprefix') . (intval($customer['ftp_lastaccountnumber']) + 1);
|
||||
}
|
||||
|
||||
|
||||
$username_check_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_FTP_USERS . "` WHERE `username` = :username
|
||||
");
|
||||
$username_check = Database::pexecute_first($username_check_stmt, array(
|
||||
"username" => $username
|
||||
), true, true);
|
||||
|
||||
|
||||
if (! empty($username_check) && $username_check['username'] = $username) {
|
||||
standard_error('usernamealreadyexists', $username, true);
|
||||
} elseif ($username == $password) {
|
||||
@@ -126,7 +131,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
} else {
|
||||
$path = makeCorrectDir($customer['documentroot'] . '/' . $path);
|
||||
$cryptPassword = makeCryptPassword($password);
|
||||
|
||||
|
||||
$stmt = Database::prepare("INSERT INTO `" . TABLE_FTP_USERS . "`
|
||||
(`customerid`, `username`, `description`, `password`, `homedir`, `login_enabled`, `uid`, `gid`, `shell`)
|
||||
VALUES (:customerid, :username, :description, :password, :homedir, 'y', :guid, :guid, :shell)");
|
||||
@@ -140,15 +145,15 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
"shell" => $shell
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT `bytes_in_used` FROM `" . TABLE_FTP_QUOTATALLIES . "` WHERE `name` = :name
|
||||
");
|
||||
Database::pexecute($result_stmt, array(
|
||||
"name" => $customer['loginname']
|
||||
), 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 . "`
|
||||
(`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')
|
||||
@@ -158,7 +163,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
"bytes_in_used" => $row['bytes_in_used']
|
||||
), true, true);
|
||||
}
|
||||
|
||||
|
||||
$stmt = Database::prepare("
|
||||
UPDATE `" . TABLE_FTP_GROUPS . "`
|
||||
SET `members` = CONCAT_WS(',',`members`, :username)
|
||||
@@ -174,13 +179,13 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer['customerid'], 'ftps_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'ftp_lastaccountnumber');
|
||||
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($customer['adminid'], 'ftps_used');
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added ftp-account '" . $username . " (" . $path . ")'");
|
||||
inserttask(5);
|
||||
|
||||
|
||||
if ($sendinfomail == 1) {
|
||||
$replace_arr = array(
|
||||
'SALUTATION' => getCorrectUserSalutation($customer),
|
||||
@@ -202,19 +207,19 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
|
||||
$this->mailer()->addAddress($customer['email'], getCorrectUserSalutation($customer));
|
||||
$this->mailer()->send();
|
||||
} catch (phpmailerException $e) {
|
||||
} catch (\phpmailerException $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
|
||||
|
||||
if ($_mailerror) {
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_ERR, "[API] Error sending mail: " . $mailerr_msg);
|
||||
standard_error('errorsendingmail', $customer['email'], true);
|
||||
}
|
||||
|
||||
|
||||
$this->mailer()->clearAddresses();
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] added ftp-user '" . $username . "'");
|
||||
@@ -225,7 +230,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -245,7 +250,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
$id = $this->getParam('id', true, 0);
|
||||
$un_optional = ($id <= 0 ? false : true);
|
||||
$username = $this->getParam('username', $un_optional, '');
|
||||
|
||||
|
||||
$params = array();
|
||||
if ($this->isAdmin()) {
|
||||
if ($this->getUserDetail('customers_see_all') == false) {
|
||||
@@ -259,7 +264,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_FTP_USERS . "`
|
||||
WHERE `customerid` IN (".implode(", ", $customer_ids).")
|
||||
WHERE `customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||
AND (`id` = :idun OR `username` = :idun)
|
||||
");
|
||||
} else {
|
||||
@@ -270,7 +275,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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("
|
||||
SELECT * FROM `" . TABLE_FTP_USERS . "`
|
||||
@@ -286,7 +291,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,17 +311,17 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
* optional, default /bin/false (not changeable when deactivated)
|
||||
* @param int $customerid
|
||||
* required when called as admin, not needed when called as customer
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
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);
|
||||
$un_optional = ($id <= 0 ? false : true);
|
||||
$username = $this->getParam('username', $un_optional, '');
|
||||
@@ -326,17 +331,17 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
'username' => $username
|
||||
));
|
||||
$id = $result['id'];
|
||||
|
||||
|
||||
// parameters
|
||||
$path = $this->getParam('path', true, '');
|
||||
$password = $this->getParam('ftp_password', true, '');
|
||||
$description = $this->getParam('ftp_description', true, $result['description']);
|
||||
$shell = $this->getParam('shell', true, $result['shell']);
|
||||
|
||||
|
||||
// validation
|
||||
$password = validate($password, 'password', '', '', array(), true);
|
||||
$description = validate(trim($description), 'description', '', '', array(), true);
|
||||
|
||||
|
||||
if (Settings::Get('system.allow_customer_shell') == '1') {
|
||||
$shell = validate(trim($shell), 'shell', '', '', array(), true);
|
||||
} else {
|
||||
@@ -345,17 +350,17 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
|
||||
// get needed customer info to reduce the ftp-user-counter by one
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
|
||||
// password update?
|
||||
if ($password != '') {
|
||||
// validate password
|
||||
$password = validatePassword($password, true);
|
||||
|
||||
|
||||
if ($password == $result['username']) {
|
||||
standard_error('passwordshouldnotbeusername', '', true);
|
||||
}
|
||||
$cryptPassword = makeCryptPassword($password);
|
||||
|
||||
|
||||
$stmt = Database::prepare("UPDATE `" . TABLE_FTP_USERS . "`
|
||||
SET `password` = :password
|
||||
WHERE `customerid` = :customerid
|
||||
@@ -368,11 +373,11 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
), true, true);
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] updated ftp-account password for '" . $result['username'] . "'");
|
||||
}
|
||||
|
||||
|
||||
// path update?
|
||||
if ($path != '') {
|
||||
$path = makeCorrectDir($customer['documentroot'] . '/' . $path);
|
||||
|
||||
|
||||
if ($path != $result['homedir']) {
|
||||
$stmt = Database::prepare("UPDATE `" . TABLE_FTP_USERS . "`
|
||||
SET `homedir` = :homedir
|
||||
@@ -390,7 +395,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
// it's the task for "new ftp" but that will
|
||||
// create all directories and correct their permissions
|
||||
inserttask(5);
|
||||
|
||||
|
||||
$stmt = Database::prepare("
|
||||
UPDATE `" . TABLE_FTP_USERS . "`
|
||||
SET `description` = :desc, `shell` = :shell
|
||||
@@ -420,7 +425,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
* optional, admin-only, select ftp-users of a specific customer by loginname
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -429,10 +434,10 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
$result = array();
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_FTP_USERS . "`
|
||||
WHERE `customerid` IN (".implode(", ", $customer_ids).")
|
||||
WHERE `customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||
");
|
||||
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;
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -462,18 +467,18 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
$un_optional = ($id <= 0 ? false : true);
|
||||
$username = $this->getParam('username', $un_optional, '');
|
||||
$delete_userfiles = $this->getBoolParam('delete_userfiles', true, 0);
|
||||
|
||||
|
||||
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
|
||||
$result = $this->apiCall('Ftps.get', array(
|
||||
'id' => $id,
|
||||
'username' => $username
|
||||
));
|
||||
$id = $result['id'];
|
||||
|
||||
|
||||
if ($this->isAdmin()) {
|
||||
// get customer-data
|
||||
$customer_data = $this->apiCall('Customers.get', array(
|
||||
@@ -482,7 +487,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
} else {
|
||||
$customer_data = $this->getUserData();
|
||||
}
|
||||
|
||||
|
||||
// add usage of this ftp-user to main-ftp user of customer if different
|
||||
if ($result['username'] != $customer_data['loginname']) {
|
||||
$stmt = Database::prepare("UPDATE `" . TABLE_FTP_USERS . "`
|
||||
@@ -501,13 +506,13 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
}
|
||||
|
||||
|
||||
// remove all quotatallies
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_FTP_QUOTATALLIES . "` WHERE `name` = :name");
|
||||
Database::pexecute($stmt, array(
|
||||
"name" => $result['username']
|
||||
), true, true);
|
||||
|
||||
|
||||
// remove user itself
|
||||
$stmt = Database::prepare("
|
||||
DELETE FROM `" . TABLE_FTP_USERS . "` WHERE `customerid` = :customerid AND `id` = :id
|
||||
@@ -516,7 +521,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
"customerid" => $customer_data['customerid'],
|
||||
"id" => $id
|
||||
), true, true);
|
||||
|
||||
|
||||
// update ftp-groups
|
||||
$stmt = Database::prepare("
|
||||
UPDATE `" . TABLE_FTP_GROUPS . "` SET
|
||||
@@ -527,7 +532,7 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
"username" => "," . $result['username'],
|
||||
"customerid" => $customer_data['customerid']
|
||||
), true, true);
|
||||
|
||||
|
||||
// refs #293
|
||||
if ($delete_userfiles == 1) {
|
||||
inserttask('8', $customer_data['loginname'], $result['homedir']);
|
||||
@@ -537,13 +542,13 @@ class Ftps extends ApiCommand implements ResourceEntity
|
||||
inserttask(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// decrease ftp-user usage for customer
|
||||
$resetaccnumber = ($customer_data['ftps_used'] == '1') ? " , `ftp_lastaccountnumber`='0'" : '';
|
||||
Customers::decreaseUsage($customer_data['customerid'], 'ftps_used', $resetaccnumber);
|
||||
// update admin usage
|
||||
Admins::decreaseUsage(($this->isAdmin() ? $customer_data['adminid'] : $this->getUserDetail('adminid')), 'ftps_used');
|
||||
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] deleted ftp-user '" . $result['username'] . "'");
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,15 +9,16 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class HostingPlans extends ApiCommand implements ResourceEntity
|
||||
class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
|
||||
public function add()
|
||||
{}
|
||||
|
||||
@@ -31,6 +33,4 @@ class HostingPlans extends ApiCommand implements ResourceEntity
|
||||
|
||||
public function delete()
|
||||
{}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,21 +12,21 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -38,7 +42,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
Database::pexecute($result_stmt, null, true, true);
|
||||
$result = array();
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successfull", array(
|
||||
@@ -46,7 +50,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -66,7 +70,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
if (! empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != - 1) {
|
||||
$allowed_ips = json_decode($this->getUserDetail('ip'), true);
|
||||
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("
|
||||
@@ -79,9 +83,9 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] get ip " . $result['ip'] . " " . $result['port']);
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -248,7 +252,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,9 +288,9 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
* @param string $ssl_cert_chainfile
|
||||
* optional, requires $ssl = 1, default empty
|
||||
*
|
||||
*
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -434,7 +438,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -511,6 +515,6 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
|
||||
standard_error('ipstillhasdomains', '', true);
|
||||
}
|
||||
}
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class Mysqls extends ApiCommand implements ResourceEntity
|
||||
class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -33,26 +37,26 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
* required when called as admin, not needed when called as customer
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->getUserDetail('mysqls_used') < $this->getUserDetail('mysqls') || $this->getUserDetail('mysqls') == '-1') {
|
||||
|
||||
|
||||
// required paramters
|
||||
$password = $this->getParam('mysql_password');
|
||||
|
||||
|
||||
// parameters
|
||||
$dbserver = $this->getParam('mysql_server', true, 0);
|
||||
$databasedescription = $this->getParam('description', true, '');
|
||||
$sendinfomail = $this->getBoolParam('sendinfomail', true, 0);
|
||||
|
||||
|
||||
// validation
|
||||
$password = validate($password, 'password', '', '', array(), true);
|
||||
$password = validatePassword($password, true);
|
||||
$databasedescription = validate(trim($databasedescription), 'description', '', '', array(), true);
|
||||
|
||||
|
||||
// validate whether the dbserver exists
|
||||
$dbserver = validate($dbserver, html_entity_decode($this->lng['mysql']['mysql_server']), '', '', 0, true);
|
||||
Database::needRoot(true, $dbserver);
|
||||
@@ -60,29 +64,30 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$sql_root = Database::getSqlData();
|
||||
Database::needRoot(false);
|
||||
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) {
|
||||
$sendinfomail = 0;
|
||||
}
|
||||
|
||||
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
$customer = $this->getCustomerData('mysqls');
|
||||
|
||||
|
||||
$newdb_params = array(
|
||||
'loginname' => ($this->isAdmin() ? $customer['loginname'] : $this->getUserDetail('loginname')),
|
||||
'mysql_lastaccountnumber' => ($this->isAdmin() ? $customer['mysql_lastaccountnumber'] : $this->getUserDetail('mysql_lastaccountnumber'))
|
||||
);
|
||||
// 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']);
|
||||
|
||||
|
||||
// we've checked against the password in dbm->createDatabase
|
||||
if ($username == false) {
|
||||
standard_error('passwordshouldnotbeusername', '', true);
|
||||
}
|
||||
|
||||
|
||||
// add database info to froxlor
|
||||
$stmt = Database::prepare("
|
||||
INSERT INTO `" . TABLE_PANEL_DATABASES . "`
|
||||
@@ -101,27 +106,27 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
$databaseid = Database::lastInsertId();
|
||||
$params['id'] = $databaseid;
|
||||
|
||||
|
||||
// update customer usage
|
||||
Customers::increaseUsage($customer['customerid'], 'mysqls_used');
|
||||
Customers::increaseUsage($customer['customerid'], 'mysql_lastaccountnumber');
|
||||
|
||||
|
||||
// update admin usage
|
||||
Admins::increaseUsage($this->getUserDetail('adminid'), 'mysqls_used');
|
||||
|
||||
|
||||
// send info-mail?
|
||||
if ($sendinfomail == 1) {
|
||||
$pma = $this->lng['admin']['notgiven'];
|
||||
if (Settings::Get('panel.phpmyadmin_url') != '') {
|
||||
$pma = Settings::Get('panel.phpmyadmin_url');
|
||||
}
|
||||
|
||||
|
||||
Database::needRoot(true, $dbserver);
|
||||
Database::needSqlData();
|
||||
$sql_root = Database::getSqlData();
|
||||
Database::needRoot(false);
|
||||
$userinfo = $customer;
|
||||
|
||||
|
||||
$replace_arr = array(
|
||||
'SALUTATION' => getCorrectUserSalutation($userinfo),
|
||||
'CUST_NAME' => getCorrectUserSalutation($userinfo), // < keep this for compatibility
|
||||
@@ -145,29 +150,29 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$this->mailer()->msgHTML(str_replace("\n", "<br />", $mail_body));
|
||||
$this->mailer()->addAddress($userinfo['email'], getCorrectUserSalutation($userinfo));
|
||||
$this->mailer()->send();
|
||||
} catch (phpmailerException $e) {
|
||||
} catch (\phpmailerException $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
|
||||
|
||||
if ($_mailerror) {
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_ERR, "[API] Error sending mail: " . $mailerr_msg);
|
||||
standard_error('errorsendingmail', $userinfo['email'], true);
|
||||
}
|
||||
|
||||
|
||||
$this->mailer()->clearAddresses();
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] added mysql-database '" . $username . "'");
|
||||
|
||||
|
||||
$result = $this->apiCall('Mysqls.get', array(
|
||||
'dbname' => $username
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -190,7 +195,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$dn_optional = ($id <= 0 ? false : true);
|
||||
$dbname = $this->getParam('dbname', $dn_optional, '');
|
||||
$dbserver = $this->getParam('mysql_server', true, - 1);
|
||||
|
||||
|
||||
if ($this->isAdmin()) {
|
||||
if ($this->getUserDetail('customers_see_all') != 1) {
|
||||
// if it's a reseller or an admin who cannot see all customers, we need to check
|
||||
@@ -204,7 +209,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
if (count($customer_ids) > 0) {
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_PANEL_DATABASES . "`
|
||||
WHERE " . ($id > 0 ? "`id` = :iddn" : "`databasename` = :iddn") . ($dbserver >= 0 ? " AND `dbserver` = :dbserver" : "") . " AND `customerid` IN (".implode(", ", $customer_ids).")
|
||||
WHERE " . ($id > 0 ? "`id` = :iddn" : "`databasename` = :iddn") . ($dbserver >= 0 ? " AND `dbserver` = :dbserver" : "") . " AND `customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||
");
|
||||
$params = array(
|
||||
'iddn' => ($id <= 0 ? $dbname : $id)
|
||||
@@ -213,7 +218,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$params['dbserver'] = $dbserver;
|
||||
}
|
||||
} else {
|
||||
throw new Exception("You do not have any customers yet", 406);
|
||||
throw new \Exception("You do not have any customers yet", 406);
|
||||
}
|
||||
} else {
|
||||
$result_stmt = Database::prepare("
|
||||
@@ -228,7 +233,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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("
|
||||
SELECT * FROM `" . TABLE_PANEL_DATABASES . "`
|
||||
@@ -252,14 +257,14 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($mbdata_stmt, array(
|
||||
"table_schema" => $result['databasename']
|
||||
), true, true);
|
||||
$mbdata = $mbdata_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$mbdata = $mbdata_stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
Database::needRoot(false);
|
||||
$result['size'] = $mbdata['MB'];
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] get database '" . $result['databasename'] . "'");
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -286,37 +291,37 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$dn_optional = ($id <= 0 ? false : true);
|
||||
$dbname = $this->getParam('dbname', $dn_optional, '');
|
||||
$dbserver = $this->getParam('mysql_server', true, - 1);
|
||||
|
||||
|
||||
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(
|
||||
'id' => $id,
|
||||
'dbname' => $dbname,
|
||||
'mysql_server' => $dbserver
|
||||
));
|
||||
$id = $result['id'];
|
||||
|
||||
|
||||
// paramters
|
||||
$password = $this->getParam('mysql_password', true, '');
|
||||
$databasedescription = $this->getParam('description', true, '');
|
||||
|
||||
|
||||
// validation
|
||||
$password = validate($password, 'password', '', '', array(), true);
|
||||
$databasedescription = validate(trim($databasedescription), 'description', '', '', array(), true);
|
||||
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
|
||||
if ($password != '') {
|
||||
// validate password
|
||||
$password = validatePassword($password, true);
|
||||
|
||||
|
||||
if ($password == $result['databasename']) {
|
||||
standard_error('passwordshouldnotbeusername', '', true);
|
||||
}
|
||||
|
||||
|
||||
// Begin root-session
|
||||
Database::needRoot(true, $result['dbserver']);
|
||||
foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) {
|
||||
@@ -328,7 +333,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
}
|
||||
|
||||
|
||||
$stmt = Database::prepare("FLUSH PRIVILEGES");
|
||||
Database::pexecute($stmt, null, true, true);
|
||||
Database::needRoot(false);
|
||||
@@ -346,7 +351,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
"id" => $id
|
||||
);
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] updated mysql-database '" . $result['databasename'] . "'");
|
||||
$result = $this->apiCall('Mysqls.get', array(
|
||||
'dbname' => $result['databasename']
|
||||
@@ -365,7 +370,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
* optional, admin-only, select dbs of a specific customer by loginname
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -380,7 +385,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
if ($dbserver < 0) {
|
||||
// use all dbservers
|
||||
$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 {
|
||||
// use specific dbserver
|
||||
$dbservers = array(
|
||||
@@ -389,7 +394,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
foreach ($customer_ids as $customer_id) {
|
||||
foreach ($dbservers as $_dbserver) {
|
||||
Database::pexecute($result_stmt, array(
|
||||
@@ -398,7 +403,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
), true, true);
|
||||
// Begin root-session
|
||||
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("
|
||||
SELECT SUM(data_length + index_length) as MB FROM information_schema.TABLES
|
||||
WHERE table_schema = :table_schema
|
||||
@@ -407,7 +412,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($mbdata_stmt, array(
|
||||
"table_schema" => $row['databasename']
|
||||
), true, true);
|
||||
$mbdata = $mbdata_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$mbdata = $mbdata_stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$row['size'] = $mbdata['MB'];
|
||||
$result[] = $row;
|
||||
}
|
||||
@@ -431,7 +436,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
* optional, specify database-server, default is none
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -440,9 +445,9 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
$dn_optional = ($id <= 0 ? false : true);
|
||||
$dbname = $this->getParam('dbname', $dn_optional, '');
|
||||
$dbserver = $this->getParam('mysql_server', true, - 1);
|
||||
|
||||
|
||||
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(
|
||||
@@ -451,20 +456,21 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
||||
'mysql_server' => $dbserver
|
||||
));
|
||||
$id = $result['id'];
|
||||
|
||||
|
||||
// Begin root-session
|
||||
Database::needRoot(true, $result['dbserver']);
|
||||
$dbm = new DbManager($this->logger());
|
||||
// @fixme dbManager
|
||||
$dbm = new \DbManager($this->logger());
|
||||
$dbm->getManager()->deleteDatabase($result['databasename']);
|
||||
Database::needRoot(false);
|
||||
// End root-session
|
||||
|
||||
|
||||
// delete from table
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_DATABASES . "` WHERE `id` = :id");
|
||||
Database::pexecute($stmt, array(
|
||||
"id" => $id
|
||||
), true, true);
|
||||
|
||||
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
$customer = $this->getCustomerData();
|
||||
$mysql_used = $customer['mysqls_used'];
|
||||
@@ -1,4 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +12,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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)
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -43,7 +47,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
");
|
||||
|
||||
$phpconfigs = array();
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$query_params = array(
|
||||
'id' => $row['id']
|
||||
);
|
||||
@@ -51,7 +55,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
$query = "SELECT * FROM `" . TABLE_PANEL_DOMAINS . "`
|
||||
WHERE `phpsettingid` = :id";
|
||||
|
||||
if (!$with_subdomains) {
|
||||
if (! $with_subdomains) {
|
||||
$query .= " AND `parentdomainid` = '0'";
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
SELECT DISTINCT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
||||
WHERE `standardsubdomain` > 0 ORDER BY `standardsubdomain` ASC;");
|
||||
$ssdids = array();
|
||||
while ($ssd = $ssdids_res->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($ssd = $ssdids_res->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$ssdids[] = $ssd['standardsubdomain'];
|
||||
}
|
||||
if (count($ssdids) > 0) {
|
||||
@@ -79,7 +83,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($domainresult_stmt, $query_params, true, true);
|
||||
|
||||
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) {
|
||||
$subdomains[] = $row2['domain'];
|
||||
} else {
|
||||
@@ -108,7 +112,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
'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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -135,9 +139,9 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
if ($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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -260,7 +264,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
'dynamic',
|
||||
'ondemand'
|
||||
))) {
|
||||
throw new ErrorException("Unknown process manager", 406);
|
||||
throw new \Exception("Unknown process manager", 406);
|
||||
}
|
||||
if (empty($limit_extensions)) {
|
||||
$limit_extensions = '.php';
|
||||
@@ -337,7 +341,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -455,7 +459,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
'dynamic',
|
||||
'ondemand'
|
||||
))) {
|
||||
throw new ErrorException("Unknown process manager", 406);
|
||||
throw new \Exception("Unknown process manager", 406);
|
||||
}
|
||||
if (empty($limit_extensions)) {
|
||||
$limit_extensions = '.php';
|
||||
@@ -533,7 +537,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
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') . "'");
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
use Froxlor\Settings as Settings;
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
@@ -15,7 +18,7 @@
|
||||
* @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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
@@ -91,7 +94,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
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(
|
||||
'/\:(\d)+$/',
|
||||
'/^https?\:\/\//'
|
||||
@@ -315,7 +319,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
));
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function get()
|
||||
@@ -338,7 +342,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
|
||||
// convert possible idn domain to punycode
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -363,7 +368,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
'iddn' => ($id <= 0 ? $domainname : $id)
|
||||
);
|
||||
} else {
|
||||
throw new Exception("You do not have any customers yet", 406);
|
||||
throw new \Exception("You do not have any customers yet", 406);
|
||||
}
|
||||
} else {
|
||||
$result_stmt = Database::prepare("
|
||||
@@ -378,7 +383,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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("
|
||||
SELECT d.*, pd.`subcanemaildomain`, pd.`isbinddomain` as subisbinddomain
|
||||
@@ -397,7 +402,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
return $this->response(200, "successfull", $result);
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
@@ -447,7 +452,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
$domainname = $this->getParam('domainname', $dn_optional, '');
|
||||
|
||||
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(
|
||||
@@ -576,7 +581,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
Database::pexecute($stmt, $params, true, true);
|
||||
$stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid`= :customerid AND `domainid`= :domainid");
|
||||
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']) . "'");
|
||||
}
|
||||
|
||||
@@ -641,8 +647,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
|
||||
inserttask('1');
|
||||
inserttask('4');
|
||||
|
||||
$idna_convert = new idna_convert_wrapper();
|
||||
// @fixme idna
|
||||
$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']) . "'");
|
||||
}
|
||||
$result = $this->apiCall('SubDomains.get', array(
|
||||
@@ -655,7 +661,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
* lists all subdomain entries
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -686,7 +692,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
} else {
|
||||
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(
|
||||
$this->getUserDetail('customerid')
|
||||
@@ -713,7 +719,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
"customerid" => $customer_id,
|
||||
"standardsubdomain" => $customer_stdsubs[$customer_id]
|
||||
), true, true);
|
||||
while ($row = $domains_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $domains_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
@@ -732,7 +738,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
* optional, the domainname
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function delete()
|
||||
@@ -742,7 +748,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
$domainname = $this->getParam('domainname', $dn_optional, '');
|
||||
|
||||
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(
|
||||
@@ -755,7 +761,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
$customer = $this->getCustomerData();
|
||||
|
||||
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') {
|
||||
@@ -846,7 +852,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
* @param boolean $_doredirect
|
||||
*
|
||||
* @return string validated path
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function validateDomainDocumentRoot($path = null, $url = null, $customer = null, $completedomain = null, &$_doredirect = false)
|
||||
{
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
namespace Froxlor\Api\Commands;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,44 +11,44 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @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
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
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()
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array count|list
|
||||
*/
|
||||
public function listing()
|
||||
@@ -95,7 +98,7 @@ class Traffic extends ApiCommand implements ResourceEntity
|
||||
if (! $this->isAdmin() || ($this->isAdmin() && $customer_traffic)) {
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_PANEL_TRAFFIC . "`
|
||||
WHERE `customerid` IN (".implode(", ", $customer_ids).")" . $where_str);
|
||||
WHERE `customerid` IN (" . implode(", ", $customer_ids) . ")" . $where_str);
|
||||
} else {
|
||||
$params['adminid'] = $this->getUserDetail('adminid');
|
||||
$result_stmt = Database::prepare("
|
||||
@@ -103,7 +106,7 @@ class Traffic extends ApiCommand implements ResourceEntity
|
||||
WHERE `adminid` = :adminid" . $where_str);
|
||||
}
|
||||
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;
|
||||
}
|
||||
$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
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
throw new Exception('You cannot delete traffic data', 303);
|
||||
throw new \Exception('You cannot delete traffic data', 303);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace Froxlor\Api;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,12 +9,12 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
class FroxlorRPC
|
||||
{
|
||||
@@ -23,22 +24,22 @@ class FroxlorRPC
|
||||
*
|
||||
* @param array $request
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public static function validateRequest($request)
|
||||
{
|
||||
// check header
|
||||
if (! isset($request['header']) || empty($request['header'])) {
|
||||
throw new Exception("Invalid request header", 400);
|
||||
throw new \Exception("Invalid request header", 400);
|
||||
}
|
||||
|
||||
|
||||
// check authorization
|
||||
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']);
|
||||
|
||||
|
||||
// check command
|
||||
return self::validateBody($request);
|
||||
}
|
||||
@@ -49,19 +50,19 @@ class FroxlorRPC
|
||||
* @param string $key
|
||||
* @param string $secret
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @return boolean
|
||||
*/
|
||||
private static function validateAuth($key, $secret)
|
||||
{
|
||||
$sel_stmt = Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
|
||||
$result = Database::pexecute_first($sel_stmt, array(
|
||||
$sel_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `api_keys` WHERE `apikey` = :ak AND `secret` = :as");
|
||||
$result = \Froxlor\Database\Database::pexecute_first($sel_stmt, array(
|
||||
'ak' => $key,
|
||||
'as' => $secret
|
||||
), true, true);
|
||||
if ($result) {
|
||||
if ($result['apikey'] == $key && $result['secret'] == $secret && ($result['valid_until'] == -1 || $result['valid_until'] >= time())) {
|
||||
if (!empty($result['allowed_from'])) {
|
||||
if ($result['apikey'] == $key && $result['secret'] == $secret && ($result['valid_until'] == - 1 || $result['valid_until'] >= time())) {
|
||||
if (! empty($result['allowed_from'])) {
|
||||
// @todo allow specification and validating of whole subnets later
|
||||
$ip_list = explode(",", $result['allowed_from']);
|
||||
$access_ip = inet_ntop(inet_pton($_SERVER['REMOTE_ADDR']));
|
||||
@@ -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
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function validateBody($request)
|
||||
{
|
||||
// check 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
|
||||
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']);
|
||||
|
||||
|
||||
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
|
||||
// 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])) {
|
||||
throw new Exception("Unknown command", 400);
|
||||
throw new \Exception("Unknown command", 400);
|
||||
}
|
||||
return array(
|
||||
'command' => array(
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace Froxlor\Api;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,12 +9,12 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*/
|
||||
interface ResourceEntity
|
||||
{
|
||||
56
lib/Froxlor/Froxlor.php
Normal file
56
lib/Froxlor/Froxlor.php
Normal 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 . ')';
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace Froxlor\Http;
|
||||
|
||||
class HttpClient
|
||||
{
|
||||
@@ -12,10 +13,9 @@ class HttpClient
|
||||
*/
|
||||
public static function urlGet($url, $follow_location = true)
|
||||
{
|
||||
include FROXLOR_INSTALL_DIR . '/lib/version.inc.php';
|
||||
$ch = curl_init();
|
||||
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) {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class HttpClient
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Downloads and stores a file from an url
|
||||
*
|
||||
@@ -40,14 +40,13 @@ class HttpClient
|
||||
*/
|
||||
public static function fileGet($url, $target)
|
||||
{
|
||||
include FROXLOR_INSTALL_DIR . '/lib/version.inc.php';
|
||||
$fh = fopen($target, 'w');
|
||||
$ch = curl_init();
|
||||
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_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
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fh);
|
||||
$output = curl_exec($ch);
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
namespace Froxlor;
|
||||
|
||||
use Froxlor\Database as Database;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -8,14 +11,14 @@
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <d00p@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2018-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
* @since 0.9.39
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <d00p@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2018-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
* @since 0.9.39
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -48,7 +51,7 @@ class SImExporter
|
||||
'system.mysql_access_host',
|
||||
'system.lastcronrun',
|
||||
'system.defaultip',
|
||||
'system.defaultsslip'.
|
||||
'system.defaultsslip',
|
||||
'system.last_tasks_run',
|
||||
'system.last_archive_run',
|
||||
'system.leprivatekey',
|
||||
@@ -61,7 +64,7 @@ class SImExporter
|
||||
SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` ORDER BY `settingid` ASC
|
||||
");
|
||||
$_data = array();
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$index = $row['settinggroup'] . "." . $row['varname'];
|
||||
if (! in_array($index, self::$_no_export)) {
|
||||
$_data[$index] = $row['value'];
|
||||
@@ -71,7 +74,7 @@ class SImExporter
|
||||
$_data['_sha'] = sha1(var_export($_data, true));
|
||||
$_export = json_encode($_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
if (! $_export) {
|
||||
throw new Exception("Error exporting settings: " . json_last_error_msg());
|
||||
throw new \Exception("Error exporting settings: " . json_last_error_msg());
|
||||
}
|
||||
return $_export;
|
||||
}
|
||||
@@ -87,13 +90,13 @@ class SImExporter
|
||||
$_dbversion = isset($_data['panel.db_version']) ? $_data['panel.db_version'] : false;
|
||||
// check if we have everything we need
|
||||
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
|
||||
unset($_data['_sha']);
|
||||
// compare
|
||||
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
|
||||
// when there were changes in the variable-name or similar
|
||||
@@ -124,6 +127,6 @@ class SImExporter
|
||||
// all good
|
||||
return true;
|
||||
}
|
||||
throw new Exception("Invalid JSON data: " . json_last_error_msg());
|
||||
throw new \Exception("Invalid JSON data: " . json_last_error_msg());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user