update api and ajax handling and response
This commit is contained in:
75
lib/Froxlor/Api/Api.php
Normal file
75
lib/Froxlor/Api/Api.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Froxlor\Api;
|
||||
|
||||
use Exception;
|
||||
use voku\helper\AntiXSS;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* 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-)
|
||||
* @author Maurice Preuß <hello@envoyr.com>
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
*
|
||||
*/
|
||||
class Api
|
||||
{
|
||||
protected array $headers;
|
||||
|
||||
/**
|
||||
* Api constructor.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->headers = getallheaders();
|
||||
|
||||
// set header for the response
|
||||
header("Accept: application/json");
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// check whether API interface is enabled after all
|
||||
if (\Froxlor\Settings::Get('api.enabled') != 1) {
|
||||
throw new Exception('API is not enabled. Please contact the administrator if you think this is wrong.', 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming api request to our backend.
|
||||
*
|
||||
* @param mixed $request
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle($request)
|
||||
{
|
||||
// validate content
|
||||
$request = \Froxlor\Api\FroxlorRPC::validateRequest($request);
|
||||
$request = (new AntiXSS())->xss_clean(
|
||||
$this->stripcslashesDeep($request)
|
||||
);
|
||||
|
||||
// now actually do it
|
||||
$cls = "\\Froxlor\\Api\\Commands\\" . $request['command']['class'];
|
||||
$method = $request['command']['method'];
|
||||
$apiObj = new $cls([
|
||||
'apikey' => $_SERVER['PHP_AUTH_USER'],
|
||||
'secret' => $_SERVER['PHP_AUTH_PW']
|
||||
], $request['params']);
|
||||
|
||||
// call the method with the params if any
|
||||
return $apiObj->$method();
|
||||
}
|
||||
|
||||
private function stripcslashesDeep($value)
|
||||
{
|
||||
return is_array($value) ? array_map([$this, 'stripcslashesDeep'], $value) : stripcslashes($value);
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
*/
|
||||
protected function getUserDetail($detail = null)
|
||||
{
|
||||
return (isset($this->user_data[$detail]) ? $this->user_data[$detail] : null);
|
||||
return ($this->user_data[$detail] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,32 +463,16 @@ abstract class ApiCommand extends ApiParameter
|
||||
return json_decode($json_result, true)['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* return api-compatible response in JSON format and send corresponding http-header
|
||||
*
|
||||
* @param int $status
|
||||
* @param string $status_message
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string json-encoded response message
|
||||
*/
|
||||
protected function response($status, $status_message, $data = null)
|
||||
/**
|
||||
* return api-compatible response in JSON format and send corresponding http-header
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $response_code
|
||||
* @return string json-encoded response message
|
||||
*/
|
||||
protected function response($data = null, int $response_code = 200)
|
||||
{
|
||||
if (isset($_SERVER["SERVER_PROTOCOL"]) && ! empty($_SERVER["SERVER_PROTOCOL"])) {
|
||||
$resheader = $_SERVER["SERVER_PROTOCOL"] . " " . $status;
|
||||
if (! empty($status_message)) {
|
||||
$resheader .= ' ' . str_replace("\n", " ", $status_message);
|
||||
}
|
||||
header($resheader);
|
||||
}
|
||||
|
||||
$response = array();
|
||||
$response['status'] = $status;
|
||||
$response['status_message'] = $status_message;
|
||||
$response['data'] = $data;
|
||||
|
||||
$json_response = json_encode($response, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
return $json_response;
|
||||
return \Froxlor\Api\Response::jsonDataResponse($data, $response_code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -75,7 +75,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_admins']);
|
||||
return $this->response($result['num_admins']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -109,7 +109,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] get admin '" . $result['loginname'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "loginname '" . $loginname . "'");
|
||||
throw new \Exception("Admin with " . $key . " could not be found", 404);
|
||||
@@ -364,7 +364,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = $this->apiCall('Admins.get', array(
|
||||
'id' => $adminid
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -677,7 +677,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = $this->apiCall('Admins.get', array(
|
||||
'id' => $result['adminid']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -775,7 +775,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] deleted admin '" . $result['loginname'] . "'");
|
||||
\Froxlor\User::updateCounters();
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -817,7 +817,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result['loginfail_count'] = 0;
|
||||
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] unlocked admin '" . $result['loginname'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@ class ApiKeys extends \Froxlor\Api\ApiCommand
|
||||
{
|
||||
|
||||
public function listing()
|
||||
{}
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function listingCount()
|
||||
{}
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
$result = $this->apiCall('Certificates.get', array(
|
||||
'id' => $domain['id']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Domain '" . $domain['domain'] . "' already has a certificate. Did you mean to call update?", 406);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
if (! $result) {
|
||||
throw new \Exception("Domain '" . $domain['domain'] . "' does not have a certificate.", 412);
|
||||
}
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +168,7 @@ class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
$result = $this->apiCall('Certificates.get', array(
|
||||
'id' => $domain['id']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
}
|
||||
$result[] = $cert;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -258,7 +258,7 @@ class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
$certs_stmt = Database::prepare($certs_stmt_query);
|
||||
$result = Database::pexecute_first($certs_stmt, $qry_params, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_certs']);
|
||||
return $this->response($result['num_certs']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ class Certificates extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::DELETE_DOMAIN_SSL, $chk['domain']);
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] removed ssl-certificate for '" . $chk['domain'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Unable to determine SSL certificate. Maybe no access?", 406);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class Cronjobs extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceE
|
||||
'id' => $id
|
||||
), true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("cronjob with id #" . $id . " could not be found", 404);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class Cronjobs extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceE
|
||||
$result = $this->apiCall('Cronjobs.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class Cronjobs extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceE
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -175,7 +175,7 @@ class Cronjobs extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceE
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_crons']);
|
||||
return $this->response($result['num_crons']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
|
||||
@@ -111,7 +111,7 @@ class CustomerBackups extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::CREATE_CUSTOMER_BACKUP, $task_data);
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] added customer-backup job for '" . $customer['loginname'] . "'. Target directory: " . $userpath);
|
||||
return $this->response(200, "successful", $task_data);
|
||||
return $this->response($task_data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +170,7 @@ class CustomerBackups extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
}
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list customer-backups");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -204,7 +204,7 @@ class CustomerBackups extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
$result_count ++;
|
||||
}
|
||||
}
|
||||
return $this->response(200, "successful", $result_count);
|
||||
return $this->response($result_count);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +239,7 @@ class CustomerBackups extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
'tid' => $entry
|
||||
), true, true);
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] deleted planned customer-backup #" . $entry);
|
||||
return $this->response(200, "successful", true);
|
||||
return $this->response(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -133,7 +133,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
}
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_customers']);
|
||||
return $this->response($result['num_customers']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -223,7 +223,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
}
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get customer '" . $result['loginname'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "loginname '" . $loginname . "'");
|
||||
throw new \Exception("Customer with " . $key . " could not be found", 404);
|
||||
@@ -823,7 +823,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
$result = $this->apiCall('Customers.get', array(
|
||||
'loginname' => $loginname
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
}
|
||||
@@ -1420,7 +1420,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
$result = $this->apiCall('Customers.get', array(
|
||||
'id' => $result['customerid']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1657,7 +1657,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::CREATE_QUOTA);
|
||||
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] deleted customer '" . $result['loginname'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -1699,7 +1699,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
$result['loginfail_count'] = 0;
|
||||
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] unlocked customer '" . $result['loginname'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -1769,7 +1769,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
$result = $this->apiCall('Customers.get', array(
|
||||
'id' => $c_result['customerid']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = $this->apiCall('DirOptions.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +186,7 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get directory options for '" . $result['path'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = "id #" . $id;
|
||||
throw new \Exception("Directory option with " . $key . " could not be found", 404);
|
||||
@@ -275,7 +275,7 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = $this->apiCall('DirOptions.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +315,7 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list directory-options");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -347,7 +347,7 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_htaccess']);
|
||||
return $this->response($result['num_htaccess']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
), true, true);
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] deleted directory-option for '" . str_replace($customer_data['documentroot'], '/', $result['path']) . "'");
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_VHOST);
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,7 +111,7 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
|
||||
$result = $this->apiCall('DirProtections.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +173,7 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get directory protection for '" . $result['path'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "username '" . $username . "'");
|
||||
throw new \Exception("Directory protection with " . $key . " could not be found", 404);
|
||||
@@ -258,7 +258,7 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
|
||||
$result = $this->apiCall('DirProtections.get', array(
|
||||
'id' => $result['id']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,7 +298,7 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list directory-protections");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -330,7 +330,7 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_htpasswd']);
|
||||
return $this->response($result['num_htpasswd']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,6 +386,6 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] deleted htpasswd for '" . $result['username'] . " (" . $result['path'] . ")'");
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_VHOST);
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
$result = $this->apiCall('DomainZones.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
// return $errors
|
||||
throw new \Exception(implode("\n", $errors), 406);
|
||||
@@ -392,7 +392,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
$zonefile = (string) $zone;
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get dns-zone for '" . $result['domain'] . "'");
|
||||
return $this->response(200, "successful", explode("\n", $zonefile));
|
||||
return $this->response(explode("\n", $zonefile));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -452,7 +452,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
while ($row = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -496,7 +496,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
'did' => $id
|
||||
), true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_dns']);
|
||||
return $this->response($result['num_dns']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,8 +543,8 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
if ($del_stmt->rowCount() > 0) {
|
||||
// re-generate bind configs
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_DNS);
|
||||
return $this->response(200, "successful", true);
|
||||
return $this->response(true);
|
||||
}
|
||||
return $this->response(304, "successful", true);
|
||||
return $this->response(null, 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -100,7 +100,7 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
}
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_domains']);
|
||||
return $this->response($result['num_domains']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -156,7 +156,7 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
$result['ipsandports'] = $this->getIpsForDomain($result['id']);
|
||||
}
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] get domain '" . $result['domain'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "domainname '" . $domainname . "'");
|
||||
throw new \Exception("Domain with " . $key . " could not be found", 404);
|
||||
@@ -866,7 +866,7 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
$result = $this->apiCall('Domains.get', array(
|
||||
'domainname' => $domain
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
@@ -1833,7 +1833,7 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
$result = $this->apiCall('Domains.get', array(
|
||||
'domainname' => $result['domain']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -1994,7 +1994,7 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_VHOST);
|
||||
// Using nameserver, insert a task which rebuilds the server config
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_DNS);
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
}
|
||||
@@ -404,7 +404,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,6 +507,6 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
Customers::decreaseUsage($customer['customerid'], 'email_quota_used', '', $quota);
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] deleted email account for '" . $result['email_full'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
];
|
||||
}
|
||||
|
||||
return $this->response(200, "successful", [
|
||||
return $this->response([
|
||||
'count' => count($destination),
|
||||
'list' => $destination
|
||||
]);
|
||||
@@ -210,7 +210,7 @@ class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
|
||||
$result['destination'] = explode(' ', $result['destination']);
|
||||
|
||||
return $this->response(200, "successful", count($result['destination']));
|
||||
return $this->response(count($result['destination']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +280,7 @@ class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Unknown forwarder id", 404);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $email_full
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
}
|
||||
@@ -181,7 +181,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get email address '" . $result['email_full'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "emailaddr '" . $emailaddr . "'");
|
||||
throw new \Exception("Email address with " . $key . " could not be found", 404);
|
||||
@@ -280,7 +280,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = $this->apiCall('Emails.get', array(
|
||||
'emailaddr' => $result['email_full']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,7 +319,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list email-addresses");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -349,7 +349,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_emails']);
|
||||
return $this->response($result['num_emails']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,6 +423,6 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
Customers::decreaseUsage($customer['customerid'], 'emails_used');
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] deleted email address '" . $result['email_full'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$fpmdaemons[] = $row;
|
||||
}
|
||||
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($fpmdaemons),
|
||||
'list' => $fpmdaemons
|
||||
));
|
||||
@@ -93,7 +93,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_fpms']);
|
||||
return $this->response($result['num_fpms']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -121,7 +121,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
'id' => $id
|
||||
), true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("fpm-daemon with id #" . $id . " could not be found", 404);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = $this->apiCall('FpmDaemons.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -356,7 +356,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = $this->apiCall('FpmDaemons.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -402,7 +402,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_VHOST);
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_INFO, "[API] fpm-daemon setting '" . $result['description'] . "' has been deleted by '" . $this->getUserDetail('loginname') . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
// zum update schritt #1 -> download
|
||||
if ($isnewerversion == 1) {
|
||||
$text = 'There is a newer version available: "' . $_version . '" (Your current version is: ' . $this->version . ')';
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'isnewerversion' => $isnewerversion,
|
||||
'version' => $_version,
|
||||
'message' => $text,
|
||||
@@ -83,7 +83,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
));
|
||||
} elseif ($isnewerversion == 0) {
|
||||
// all good
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'isnewerversion' => $isnewerversion,
|
||||
'version' => $version_label,
|
||||
'message' => "",
|
||||
@@ -95,13 +95,13 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->response(300, "successful", array(
|
||||
return $this->response(array(
|
||||
'isnewerversion' => 0,
|
||||
'version' => $this->version . $this->branding,
|
||||
'message' => 'Version-check not available due to missing php-curl extension',
|
||||
'link' => UPDATE_URI . '/pretty',
|
||||
'additional_info' => ""
|
||||
));
|
||||
), 502);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_DNS);
|
||||
// cron.d file
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_CRON);
|
||||
return $this->response(200, "successful", true);
|
||||
return $this->response(true);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception($e->getMessage(), 406);
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "User " . $this->getUserDetail('loginname') . " exported settings");
|
||||
$json_export = \Froxlor\SImExporter::export();
|
||||
return $this->response(200, "successful", $json_export);
|
||||
return $this->response($json_export);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
'value' => $row['value']
|
||||
);
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -197,7 +197,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
{
|
||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||
$setting = $this->getParam('key');
|
||||
return $this->response(200, "successful", Settings::Get($setting));
|
||||
return $this->response(Settings::Get($setting));
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
throw new \Exception("Setting '" . $setting . "' could not be found");
|
||||
}
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] Changing setting '" . $setting . "' from '" . $oldvalue . "' to '" . $value . "'");
|
||||
return $this->response(200, "successful", Settings::Set($setting, $value, true));
|
||||
return $this->response(Settings::Set($setting, $value, true));
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -240,7 +240,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
*/
|
||||
public function generatePassword()
|
||||
{
|
||||
return $this->response(200, "successful", \Froxlor\System\Crypt::generatePassword());
|
||||
return $this->response(\Froxlor\System\Crypt::generatePassword());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +256,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
$integrity = new \Froxlor\Database\IntegrityCheck();
|
||||
$result = $integrity->checkAll();
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", "OK");
|
||||
return $this->response("OK");
|
||||
}
|
||||
throw new \Exception("Some checks failed.", 406);
|
||||
}
|
||||
@@ -333,7 +333,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
}
|
||||
|
||||
// return the list
|
||||
return $this->response(200, "successful", $functions);
|
||||
return $this->response($functions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -281,7 +281,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
$result = $this->apiCall('Ftps.get', array(
|
||||
'username' => $username
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
@@ -342,7 +342,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get ftp-user '" . $result['username'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "username '" . $username . "'");
|
||||
throw new \Exception("FTP user with " . $key . " could not be found", 404);
|
||||
@@ -469,7 +469,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
'username' => $result['username']
|
||||
));
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] updated ftp-user '" . $result['username'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,7 +505,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list ftp-users");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -533,7 +533,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_ftps']);
|
||||
return $this->response($result['num_ftps']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,6 +641,6 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
Customers::decreaseUsage($customer_data['customerid'], 'ftps_used', $resetaccnumber);
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_WARNING, "[API] deleted ftp-user '" . $result['username'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -85,7 +85,7 @@ class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
}
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_plans']);
|
||||
return $this->response($result['num_plans']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -120,7 +120,7 @@ class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] get hosting-plan '" . $result['name'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "planname '" . $planname . "'");
|
||||
throw new \Exception("Hosting-plan with " . $key . " could not be found", 404);
|
||||
@@ -246,7 +246,7 @@ class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
$result = $this->apiCall('HostingPlans.get', array(
|
||||
'planname' => $name
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -393,7 +393,7 @@ class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
);
|
||||
Database::pexecute($upd_stmt, $update_data, true, true);
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] updated hosting-plan '" . $result['name'] . "'");
|
||||
return $this->response(200, "successful", $update_data);
|
||||
return $this->response($update_data);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -431,7 +431,7 @@ class HostingPlans extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resou
|
||||
'id' => $id
|
||||
), true, true);
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] deleted hosting-plan '" . $result['name'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -82,7 +82,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
SELECT COUNT(*) as num_ips FROM `" . TABLE_PANEL_IPSANDPORTS . "` " . $ip_where);
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_ips']);
|
||||
return $this->response($result['num_ips']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -116,7 +116,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
), true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] get ip " . $result['ip'] . " " . $result['port']);
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("IP/port with id #" . $id . " could not be found", 404);
|
||||
}
|
||||
@@ -310,7 +310,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
$result = $this->apiCall('IpsAndPorts.get', array(
|
||||
'id' => $ins_data['id']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -520,7 +520,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
$result = $this->apiCall('IpsAndPorts.get', array(
|
||||
'id' => $result['id']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -589,7 +589,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_DNS);
|
||||
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_WARNING, "[API] deleted IP/port '" . $result['ip'] . ":" . $result['port'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
} else {
|
||||
\Froxlor\UI\Response::standard_error('cantdeletesystemip', '', true);
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = $this->apiCall('Mysqls.get', array(
|
||||
'dbname' => $username
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
}
|
||||
@@ -273,7 +273,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
Database::needRoot(false);
|
||||
$result['size'] = $mbdata['MB'] ?? 0;
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get database '" . $result['databasename'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "dbname '" . $dbname . "'");
|
||||
throw new \Exception("MySQL database with " . $key . " could not be found", 404);
|
||||
@@ -365,7 +365,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = $this->apiCall('Mysqls.get', array(
|
||||
'dbname' => $result['databasename']
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,7 +436,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
Database::needRoot(false);
|
||||
}
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -463,7 +463,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_dbs']);
|
||||
return $this->response($result['num_dbs']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,6 +525,6 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
Customers::decreaseUsage($customer['customerid'], 'mysqls_used', $resetaccnumber);
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_WARNING, "[API] deleted database '" . $result['databasename'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
$phpconfigs[] = $row;
|
||||
}
|
||||
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($phpconfigs),
|
||||
'list' => $phpconfigs
|
||||
));
|
||||
@@ -137,7 +137,7 @@ class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_phps']);
|
||||
return $this->response($result['num_phps']);
|
||||
}
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
@@ -165,7 +165,7 @@ class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
'id' => $id
|
||||
), true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("php-config with id #" . $id . " could not be found", 404);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
));
|
||||
|
||||
$this->addForAllCustomers($allow_all_customers, $ins_data['id']);
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -573,7 +573,7 @@ class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
));
|
||||
|
||||
$this->addForAllCustomers($allow_all_customers, $id);
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
@@ -624,7 +624,7 @@ class PhpSettings extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
|
||||
\Froxlor\System\Cronjob::inserttask(\Froxlor\Cron\TaskId::REBUILD_VHOST);
|
||||
$this->logger()->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_INFO, "[API] php setting '" . $result['description'] . "' has been deleted by '" . $this->getUserDetail('loginname') . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = $this->apiCall('SubDomains.get', array(
|
||||
'id' => $subdomain_id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
throw new \Exception("No more resources available", 406);
|
||||
}
|
||||
@@ -451,7 +451,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get subdomain '" . $result['domain'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
$key = ($id > 0 ? "id #" . $id : "domainname '" . $domainname . "'");
|
||||
throw new \Exception("Subdomain with " . $key . " could not be found", 404);
|
||||
@@ -744,7 +744,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
$result = $this->apiCall('SubDomains.get', array(
|
||||
'id' => $id
|
||||
));
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -848,7 +848,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
while ($row = $domains_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -913,7 +913,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
");
|
||||
$result = Database::pexecute_first($domains_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_subdom']);
|
||||
return $this->response($result['num_subdom']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1031,7 +1031,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
Customers::decreaseUsage($customer['customerid'], 'subdomains_used');
|
||||
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_WARNING, "[API] deleted subdomain '" . $result['domain'] . "'");
|
||||
return $this->response(200, "successful", $result);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,7 +74,7 @@ class SysLog extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list log-entries");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
@@ -129,7 +129,7 @@ class SysLog extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
|
||||
$result = Database::pexecute_first($result_stmt, $params, true, true);
|
||||
if ($result) {
|
||||
return $this->response(200, "successful", $result['num_logs']);
|
||||
return $this->response($result['num_logs']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ class SysLog extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$params['trunc'] = $truncatedate;
|
||||
Database::pexecute($result_stmt, $params, true, true);
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_WARNING, "[API] truncated the froxlor syslog");
|
||||
return $this->response(200, "successful", true);
|
||||
return $this->response(true);
|
||||
}
|
||||
throw new \Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class Traffic extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn
|
||||
$result[] = $row;
|
||||
}
|
||||
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] list traffic");
|
||||
return $this->response(200, "successful", array(
|
||||
return $this->response(array(
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
));
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Froxlor\Api;
|
||||
|
||||
use Exception;
|
||||
use voku\helper\AntiXSS;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
@@ -11,116 +15,118 @@ namespace Froxlor\Api;
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @author Maurice Preuß <hello@envoyr.com>
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*
|
||||
*/
|
||||
class FroxlorRPC
|
||||
{
|
||||
/**
|
||||
* validate a given request
|
||||
*
|
||||
* @param $request
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function validateRequest($request): array
|
||||
{
|
||||
// make basic authentication
|
||||
if (!isset($_SERVER['PHP_AUTH_USER']) || !self::validateAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
|
||||
header('WWW-Authenticate: Basic realm="API"');
|
||||
throw new Exception('Unauthenticated. Please provide api user credentials.', 401);
|
||||
}
|
||||
|
||||
/**
|
||||
* validate a given request
|
||||
*
|
||||
* @param array $request
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
// check if present
|
||||
if (empty($request)) {
|
||||
throw new Exception('Empty request body.', 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);
|
||||
}
|
||||
self::validateAuth($request['header']['apikey'], $request['header']['secret']);
|
||||
// decode json request
|
||||
$decoded_request = json_decode($request, true);
|
||||
|
||||
// check command
|
||||
return self::validateBody($request);
|
||||
}
|
||||
// is it valid?
|
||||
if (is_null($decoded_request)) {
|
||||
throw new Exception('Invalid JSON Format.', 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* validates the given api credentials
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $secret
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return boolean
|
||||
*/
|
||||
private static function validateAuth($key, $secret)
|
||||
{
|
||||
$sel_stmt = \Froxlor\Database\Database::prepare("
|
||||
return self::validateBody($decoded_request);
|
||||
}
|
||||
|
||||
/**
|
||||
* validates the given api credentials
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $secret
|
||||
* @return boolean
|
||||
*/
|
||||
private static function validateAuth(string $key, string $secret): bool
|
||||
{
|
||||
$sel_stmt = \Froxlor\Database\Database::prepare(
|
||||
"
|
||||
SELECT ak.*, a.api_allowed as admin_api_allowed, c.api_allowed as cust_api_allowed, c.deactivated
|
||||
FROM `api_keys` ak
|
||||
LEFT JOIN `panel_admins` a ON a.adminid = ak.adminid
|
||||
LEFT JOIN `panel_customers` c ON c.customerid = ak.customerid
|
||||
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()) && (($result['customerid'] == 0 && $result['admin_api_allowed'] == 1) || ($result['customerid'] > 0 && $result['cust_api_allowed'] == 1 && $result['deactivated'] == 0))) {
|
||||
// get user to check whether api call is allowed
|
||||
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']));
|
||||
if (in_array($access_ip, $ip_list)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new \Exception("Invalid authorization credentials", 403);
|
||||
}
|
||||
"
|
||||
);
|
||||
$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(
|
||||
)) && (($result['customerid'] == 0 && $result['admin_api_allowed'] == 1) || ($result['customerid'] > 0 && $result['cust_api_allowed'] == 1 && $result['deactivated'] == 0))) {
|
||||
// get user to check whether api call is allowed
|
||||
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']));
|
||||
if (in_array($access_ip, $ip_list)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* validates the given command
|
||||
*
|
||||
* @param array $request
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function validateBody($request)
|
||||
{
|
||||
// check body
|
||||
if (! isset($request['body']) || empty($request['body'])) {
|
||||
throw new \Exception("Invalid request body", 400);
|
||||
}
|
||||
/**
|
||||
* validates the given command
|
||||
*
|
||||
* @param array $request
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function validateBody($request)
|
||||
{
|
||||
// check command exists
|
||||
if (empty($request['command'])) {
|
||||
throw new Exception("Please provide a command.", 400);
|
||||
}
|
||||
|
||||
// check command exists
|
||||
if (! isset($request['body']['command']) || empty($request['body']['command'])) {
|
||||
throw new \Exception("No command given", 400);
|
||||
}
|
||||
$command = explode(".", $request['command']);
|
||||
|
||||
$command = explode(".", $request['body']['command']);
|
||||
|
||||
if (count($command) != 2) {
|
||||
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\\Api\\Commands\\' . $command[0];
|
||||
if (! class_exists($apiclass) || ! @method_exists($apiclass, $command[1])) {
|
||||
throw new \Exception("Unknown command", 400);
|
||||
}
|
||||
return array(
|
||||
'command' => array(
|
||||
'class' => $command[0],
|
||||
'method' => $command[1]
|
||||
),
|
||||
'params' => isset($request['body']['params']) ? $request['body']['params'] : null
|
||||
);
|
||||
}
|
||||
if (count($command) != 2) {
|
||||
throw new Exception("The given command is invalid.", 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\\Api\\Commands\\' . $command[0];
|
||||
if (!class_exists($apiclass) || !@method_exists($apiclass, $command[1])) {
|
||||
throw new Exception("Unknown command", 400);
|
||||
}
|
||||
return array(
|
||||
'command' => array(
|
||||
'class' => $command[0],
|
||||
'method' => $command[1]
|
||||
),
|
||||
'params' => $request['params'] ?? null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
37
lib/Froxlor/Api/Response.php
Normal file
37
lib/Froxlor/Api/Response.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Froxlor\Api;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* 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-)
|
||||
* @author Maurice Preuß <hello@envoyr.com>
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
*
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
public static function jsonResponse($data = null, int $response_code = 200)
|
||||
{
|
||||
http_response_code($response_code);
|
||||
|
||||
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
public static function jsonDataResponse($data = null, int $response_code = 200)
|
||||
{
|
||||
return self::jsonResponse(['data' => $data], $response_code);
|
||||
}
|
||||
|
||||
public static function jsonErrorResponse($message = null, int $response_code = 200)
|
||||
{
|
||||
return self::jsonResponse(['message' => $message], $response_code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user