more api-documentation and code-formatting

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-11-25 10:04:09 +01:00
parent 983e1ce6ad
commit f6e0298d25
7 changed files with 247 additions and 148 deletions

View File

@@ -64,7 +64,7 @@ class Admins extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') == 1 || ($this->getUserDetail('adminid') == $id || $this->getUserDetail('loginname') == $loginname))) {
$result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_ADMINS . "`
@@ -165,7 +165,7 @@ class Admins extends ApiCommand implements ResourceEntity
public function add()
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
// required parameters
$name = $this->getParam('name');
$email = $this->getParam('email');
@@ -176,7 +176,7 @@ class Admins extends ApiCommand implements ResourceEntity
$custom_notes = $this->getParam('custom_notes', true, '');
$custom_notes_show = $this->getParam('custom_notes_show', true, 0);
$password = $this->getParam('admin_password', true, '');
$diskspace = $this->getUlParam('diskspace', 'diskspace_ul', true, 0);
$traffic = $this->getUlParam('traffic', 'traffic_ul', true, 0);
$customers = $this->getUlParam('customers', 'customers_ul', true, 0);
@@ -189,39 +189,39 @@ class Admins extends ApiCommand implements ResourceEntity
$ftps = $this->getUlParam('ftps', 'ftps_ul', true, 0);
$tickets = $this->getUlParam('tickets', 'tickets_ul', true, 0);
$mysqls = $this->getUlParam('mysqls', 'mysqls_ul', true, 0);
$customers_see_all = $this->getParam('customers_see_all', true, 0);
$domains_see_all = $this->getParam('domains_see_all', true, 0);
$tickets_see_all = $this->getParam('tickets_see_all', true, 0);
$caneditphpsettings = $this->getParam('caneditphpsettings', true, 0);
$change_serversettings = $this->getParam('change_serversettings', true, 0);
$ipaddress = $this->getParam('ipaddress', true, - 1);
// validation
$name = validate($name, 'name', '', '', array(), true);
$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);
if (Settings::Get('system.mail_quota_enabled') != '1') {
$email_quota = - 1;
}
if (Settings::Get('ticket.enabled') != '1') {
$tickets = - 1;
}
$password = validate($password, 'password', '', '', array(), true);
// only check if not empty,
// cause empty == generate password automatically
if ($password != '') {
$password = validatePassword($password, true);
}
$diskspace = $diskspace * 1024;
$traffic = $traffic * 1024 * 1024;
// Check if the account already exists
// do not check via api as we skip any permission checks for this task
$loginname_check_stmt = Database::prepare("
@@ -230,7 +230,7 @@ class Admins extends ApiCommand implements ResourceEntity
$loginname_check = Database::pexecute_first($loginname_check_stmt, array(
'login' => $loginname
), true, true);
// Check if an admin with the loginname already exists
// do not check via api as we skip any permission checks for this task
$loginname_check_admin_stmt = Database::prepare("
@@ -239,7 +239,7 @@ class Admins extends ApiCommand implements ResourceEntity
$loginname_check_admin = Database::pexecute_first($loginname_check_admin_stmt, array(
'login' => $loginname
), true, true);
if (strtolower($loginname_check['loginname']) == strtolower($loginname) || strtolower($loginname_check_admin['loginname']) == strtolower($loginname)) {
standard_error('loginnameexists', $loginname, true);
} // Accounts which match systemaccounts are not allowed, filtering them
@@ -250,33 +250,33 @@ class Admins extends ApiCommand implements ResourceEntity
} elseif (! validateEmail($email)) {
standard_error('emailiswrong', $email, true);
} else {
if ($customers_see_all != '1') {
$customers_see_all = '0';
}
if ($domains_see_all != '1') {
$domains_see_all = '0';
}
if ($caneditphpsettings != '1') {
$caneditphpsettings = '0';
}
if ($change_serversettings != '1') {
$change_serversettings = '0';
}
if ($tickets_see_all != '1') {
$tickets_see_all = '0';
}
if ($password == '') {
$password = generatePassword();
}
$_theme = Settings::Get('panel.default_theme');
$ins_data = array(
'loginname' => $loginname,
'password' => makeCryptPassword($password),
@@ -305,7 +305,7 @@ class Admins extends ApiCommand implements ResourceEntity
'custom_notes' => $custom_notes,
'custom_notes_show' => $custom_notes_show
);
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_ADMINS . "` SET
`loginname` = :loginname,
@@ -336,11 +336,11 @@ class Admins extends ApiCommand implements ResourceEntity
`custom_notes_show` = :custom_notes_show
");
Database::pexecute($ins_stmt, $ins_data, true, true);
$adminid = Database::lastInsertId();
$ins_data['adminid'] = $adminid;
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added admin '" . $loginname . "'");
// get all admin-data for return-array
$result = $this->apiCall('Admins.get', array(
'id' => $adminid
@@ -442,17 +442,17 @@ class Admins extends ApiCommand implements ResourceEntity
public function update()
{
if ($this->isAdmin()) {
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$result = $this->apiCall('Admins.get', array(
'id' => $id,
'loginname' => $loginname
));
$id = $result['adminid'];
if ($this->getUserDetail('change_serversettings') == 1 || $result['adminid'] == $this->getUserDetail('adminid')) {
// parameters
$name = $this->getParam('name', true, $result['name']);
@@ -463,7 +463,7 @@ class Admins extends ApiCommand implements ResourceEntity
$custom_notes = $this->getParam('custom_notes', true, $result['custom_notes']);
$custom_notes_show = $this->getParam('custom_notes_show', true, $result['custom_notes_show']);
$theme = $this->getParam('theme', true, $result['theme']);
// you cannot edit some of the details of yourself
if ($result['adminid'] == $this->getUserDetail('adminid')) {
$deactivated = $result['deactivated'];
@@ -487,7 +487,7 @@ class Admins extends ApiCommand implements ResourceEntity
$ipaddress = ($result['ip'] != - 1 ? json_decode($result['ip'], true) : - 1);
} else {
$deactivated = $this->getParam('deactivated', true, $result['deactivated']);
$dec_places = Settings::Get('panel.decimal_places');
$diskspace = $this->getUlParam('diskspace', 'diskspace_ul', true, round($result['diskspace'] / 1024, $dec_places));
$traffic = $this->getUlParam('traffic', 'traffic_ul', true, round($result['traffic'] / (1024 * 1024), $dec_places));
@@ -501,18 +501,18 @@ class Admins extends ApiCommand implements ResourceEntity
$ftps = $this->getUlParam('ftps', 'ftps_ul', true, $result['ftps']);
$tickets = $this->getUlParam('tickets', 'tickets_ul', true, $result['tickets']);
$mysqls = $this->getUlParam('mysqls', 'mysqls_ul', true, $result['mysqls']);
$customers_see_all = $this->getParam('customers_see_all', true, $result['customers_see_all']);
$domains_see_all = $this->getParam('domains_see_all', true, $result['domains_see_all']);
$tickets_see_all = $this->getParam('tickets_see_all', true, $result['tickets_see_all']);
$caneditphpsettings = $this->getParam('caneditphpsettings', true, $result['caneditphpsettings']);
$change_serversettings = $this->getParam('change_serversettings', true, $result['change_serversettings']);
$ipaddress = $this->getParam('ipaddress', true, ($result['ip'] != - 1 ? json_decode($result['ip'], true) : - 1));
$diskspace = $diskspace * 1024;
$traffic = $traffic * 1024 * 1024;
}
// validation
$name = validate($name, 'name', '', '', array(), true);
$idna_convert = new idna_convert_wrapper();
@@ -521,54 +521,54 @@ class Admins extends ApiCommand implements ResourceEntity
$custom_notes = validate(str_replace("\r\n", "\n", $custom_notes), 'custom_notes', '/^[^\0]*$/', '', array(), true);
$theme = validate($theme, 'theme', '', '', array(), true);
$password = validate($password, 'password', '', '', array(), true);
if (Settings::Get('system.mail_quota_enabled') != '1') {
$email_quota = - 1;
}
if (Settings::Get('ticket.enabled') != '1') {
$tickets = - 1;
}
if (empty($theme)) {
$theme = Settings::Get('panel.default_theme');
}
if (! validateEmail($email)) {
standard_error('emailiswrong', $email, true);
} else {
if ($deactivated != '1') {
$deactivated = '0';
}
if ($customers_see_all != '1') {
$customers_see_all = '0';
}
if ($domains_see_all != '1') {
$domains_see_all = '0';
}
if ($caneditphpsettings != '1') {
$caneditphpsettings = '0';
}
if ($change_serversettings != '1') {
$change_serversettings = '0';
}
if ($tickets_see_all != '1') {
$tickets_see_all = '0';
}
if ($password != '') {
$password = validatePassword($password, true);
$password = makeCryptPassword($password);
} else {
$password = $result['password'];
}
// check if a resource was set to something lower
// than actually used by the admin/reseller
$res_warning = "";
@@ -605,11 +605,11 @@ class Admins extends ApiCommand implements ResourceEntity
if ($mysqls != $result['mysqls'] && $mysqls != - 1 && $mysqls < $result['mysqls_used']) {
$res_warning .= sprintf($this->lng['error']['setlessthanalreadyused'], 'mysqls');
}
if (! empty($res_warning)) {
throw new Exception($res_warning, 406);
}
$upd_data = array(
'password' => $password,
'name' => $name,
@@ -639,7 +639,7 @@ class Admins extends ApiCommand implements ResourceEntity
'theme' => $theme,
'adminid' => $id
);
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_ADMINS . "` SET
`password` = :password,
@@ -672,7 +672,7 @@ class Admins extends ApiCommand implements ResourceEntity
");
Database::pexecute($upd_stmt, $upd_data, true, true);
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] edited admin '" . $result['loginname'] . "'");
// get all admin-data for return-array
$result = $this->apiCall('Admins.get', array(
'id' => $result['adminid']
@@ -702,18 +702,18 @@ class Admins extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$result = $this->apiCall('Admins.get', array(
'id' => $id,
'loginname' => $loginname
));
$id = $result['adminid'];
// don't be stupid
if ($id == $this->getUserDetail('adminid')) {
standard_error('youcantdeleteyourself', '', true);
}
// delete admin
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = :adminid
@@ -721,7 +721,7 @@ class Admins extends ApiCommand implements ResourceEntity
Database::pexecute($del_stmt, array(
'adminid' => $id
), true, true);
// delete the traffic-usage
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_TRAFFIC_ADMINS . "` WHERE `adminid` = :adminid
@@ -729,7 +729,7 @@ class Admins extends ApiCommand implements ResourceEntity
Database::pexecute($del_stmt, array(
'adminid' => $id
), true, true);
// delete the diskspace usage
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_DISKSPACE_ADMINS . "` WHERE `adminid` = :adminid
@@ -737,7 +737,7 @@ class Admins extends ApiCommand implements ResourceEntity
Database::pexecute($del_stmt, array(
'adminid' => $id
), true, true);
// set admin-id of the old admin's customer to current admins
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET
@@ -747,7 +747,7 @@ class Admins extends ApiCommand implements ResourceEntity
'userid' => $this->getUserDetail('adminid'),
'adminid' => $id
), true, true);
// set admin-id of the old admin's domains to current admins
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_DOMAINS . "` SET
@@ -757,7 +757,7 @@ class Admins extends ApiCommand implements ResourceEntity
'userid' => $this->getUserDetail('adminid'),
'adminid' => $id
), true, true);
// delete old admin's api keys if exists (no customer keys)
$upd_stmt = Database::prepare("
DELETE FROM `" . TABLE_API_KEYS . "` WHERE
@@ -766,7 +766,7 @@ class Admins extends ApiCommand implements ResourceEntity
Database::pexecute($upd_stmt, array(
'adminid' => $id
), true, true);
// set admin-id of the old admin's api-keys to current admins
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_API_KEYS . "` SET
@@ -776,7 +776,7 @@ class Admins extends ApiCommand implements ResourceEntity
'userid' => $this->getUserDetail('adminid'),
'adminid' => $id
), true, true);
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] deleted admin '" . $result['loginname'] . "'");
updateCounters();
return $this->response(200, "successfull", $result);
@@ -802,13 +802,13 @@ class Admins extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$result = $this->apiCall('Admins.get', array(
'id' => $id,
'loginname' => $loginname
));
$id = $result['adminid'];
$result_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_ADMINS . "` SET
`loginfail_count` = '0'
@@ -819,7 +819,7 @@ class Admins extends ApiCommand implements ResourceEntity
), true, true);
// set the new value for result-array
$result['loginfail_count'] = 0;
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] unlocked admin '" . $result['loginname'] . "'");
return $this->response(200, "successfull", $result);
}

View File

@@ -49,7 +49,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
* optional whether to backup web-data, default is 0 (false)
* @param int $customerid
* required when called as admin, not needed when called as customer
*
*
* @access admin, customer
* @return array
*/
@@ -132,7 +132,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
* optional, admin-only, select backup-jobs of a specific customer by id
* @param string $loginname
* optional, admin-only, select backup-jobs of a specific customer by loginname
*
*
* @access admin, customer
* @throws Exception
* @return array count|list
@@ -169,7 +169,7 @@ class CustomerBackups extends ApiCommand implements ResourceEntity
* optional, required when called as admin (if $loginname is not specified)
* @param string $loginname
* optional, required when called as admin (if $customerid is not specified)
*
*
* @access admin, customer
* @throws Exception
* @return bool

View File

@@ -172,7 +172,7 @@ class Domains extends ApiCommand implements ResourceEntity
* @param bool $hsts_preload
* optional whether or not to preload HSTS header value
* @param bool $ocsp_stapling
* optional whether to enable oscp-stapling for this domain. default ß (false), requires SSL
* optional whether to enable oscp-stapling for this domain. default 0 (false), requires SSL
*
* @access admin
* @throws Exception
@@ -745,7 +745,7 @@ class Domains extends ApiCommand implements ResourceEntity
* @param bool $hsts_preload
* optional whether or not to preload HSTS header value
* @param bool $ocsp_stapling
* optional whether to enable oscp-stapling for this domain. default ß (false), requires SSL
* optional whether to enable oscp-stapling for this domain. default 0 (false), requires SSL
*
* @access admin
* @throws Exception

View File

@@ -29,38 +29,38 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin()) {
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] list fpm-daemons");
$result = Database::query("
SELECT * FROM `" . TABLE_PANEL_FPMDAEMONS . "` ORDER BY `description` ASC
");
$fpmdaemons = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$query_params = array(
'id' => $row['id']
);
$query = "SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `fpmsettingid` = :id";
$configresult_stmt = Database::prepare($query);
Database::pexecute($configresult_stmt, $query_params, true, true);
$configs = array();
if (Database::num_rows() > 0) {
while ($row2 = $configresult_stmt->fetch(PDO::FETCH_ASSOC)) {
$configs[] = $row2['description'];
}
}
if (empty($configs)) {
$configs[] = $this->lng['admin']['phpsettings']['notused'];
}
$row['configs'] = $configs;
$fpmdaemons[] = $row;
}
return $this->response(200, "successfull", array(
'count' => count($fpmdaemons),
'list' => $fpmdaemons
@@ -83,7 +83,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin()) {
$id = $this->getParam('id');
$result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_FPMDAEMONS . "` WHERE `id` = :id
");
@@ -101,6 +101,26 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
/**
* create a new fpm-daemon entry
*
* @param string $description
* @param string $reload_cmd
* @param string $config_dir
* @param string $pm
* optional, process-manager, one of 'static', 'dynamic' or 'ondemand', default 'static'
* @param int $max_children
* optional, default 0
* @param int $start_servers
* optional, default 0
* @param int $min_spare_servers
* optional, default 0
* @param int $max_spare_servers
* optional, default 0
* @param int $max_requests
* optional, default 0
* @param int $idle_timeout
* optional, default 0
* @param string $limit_extensions
* optional, limit execution to the following extensions, default '.php'
*
* @access admin
* @throws Exception
* @return array
@@ -108,12 +128,12 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
public function add()
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
// required parameter
$description = $this->getParam('description');
$reload_cmd = $this->getParam('reload_cmd');
$config_dir = $this->getParam('config_dir');
// parameters
$pmanager = $this->getParam('pm', true, 'static');
$max_children = $this->getParam('max_children', true, 0);
@@ -123,7 +143,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
$max_requests = $this->getParam('max_requests', true, 0);
$idle_timeout = $this->getParam('idle_timeout', true, 0);
$limit_extensions = $this->getParam('limit_extensions', true, '.php');
// validation
$description = validate($description, 'description', '', '', array(), true);
$reload_cmd = validate($reload_cmd, 'reload_cmd', '', '', array(), true);
@@ -139,11 +159,11 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
$limit_extensions = '.php';
}
$limit_extensions = validate($limit_extensions, 'limit_extensions', '/^(\.[a-z]([a-z0-9]+)\ ?)+$/', '', array(), true);
if (strlen($description) == 0 || strlen($description) > 50) {
standard_error('descriptioninvalid', '', true);
}
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_FPMDAEMONS . "` SET
`description` = :desc,
@@ -173,7 +193,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
);
Database::pexecute($ins_stmt, $ins_data);
$id = Database::lastInsertId();
inserttask('1');
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon with description '" . $description . "' has been created by '" . $this->getUserDetail('loginname') . "'");
$result = $this->apiCall('FpmDaemons.get', array(
@@ -188,7 +208,30 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
* update a fpm-daemon entry by given id
*
* @param int $id
*
* fpm-daemon id
* @param string $description
* optional
* @param string $reload_cmd
* optional
* @param string $config_dir
* optional
* @param string $pm
* optional, process-manager, one of 'static', 'dynamic' or 'ondemand', default 'static'
* @param int $max_children
* optional, default 0
* @param int $start_servers
* optional, default 0
* @param int $min_spare_servers
* optional, default 0
* @param int $max_spare_servers
* optional, default 0
* @param int $max_requests
* optional, default 0
* @param int $idle_timeout
* optional, default 0
* @param string $limit_extensions
* optional, limit execution to the following extensions, default '.php'
*
* @access admin
* @throws Exception
* @return array
@@ -196,14 +239,14 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
public function update()
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
// required parameter
$id = $this->getParam('id');
$result = $this->apiCall('FpmDaemons.get', array(
'id' => $id
));
// parameters
$description = $this->getParam('description', true, $result['description']);
$reload_cmd = $this->getParam('reload_cmd', true, $result['reload_cmd']);
@@ -216,7 +259,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
$max_requests = $this->getParam('max_requests', true, $result['max_requests']);
$idle_timeout = $this->getParam('idle_timeout', true, $result['idle_timeout']);
$limit_extensions = $this->getParam('limit_extensions', true, $result['limit_extensions']);
// validation
$description = validate($description, 'description', '', '', array(), true);
$reload_cmd = validate($reload_cmd, 'reload_cmd', '', '', array(), true);
@@ -232,11 +275,11 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
$limit_extensions = '.php';
}
$limit_extensions = validate($limit_extensions, 'limit_extensions', '/^(\.[a-z]([a-z0-9]+)\ ?)+$/', '', array(), true);
if (strlen($description) == 0 || strlen($description) > 50) {
standard_error('descriptioninvalid', '', true);
}
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_FPMDAEMONS . "` SET
`description` = :desc,
@@ -267,7 +310,7 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
'id' => $id
);
Database::pexecute($upd_stmt, $upd_data, true, true);
inserttask('1');
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon with description '" . $description . "' has been updated by '" . $this->getUserDetail('loginname') . "'");
$result = $this->apiCall('FpmDaemons.get', array(
@@ -292,15 +335,15 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
$id = $this->getParam('id');
if ($id == 1) {
standard_error('cannotdeletedefaultphpconfig', '', true);
}
$result = $this->apiCall('FpmDaemons.get', array(
'id' => $id
));
// set default fpm daemon config for all php-config that use this config that is to be deleted
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_PHPCONFIGS . "` SET
@@ -309,14 +352,14 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
Database::pexecute($upd_stmt, array(
'id' => $id
), true, true);
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_FPMDAEMONS . "` WHERE `id` = :id
");
Database::pexecute($del_stmt, array(
'id' => $id
), true, true);
inserttask('1');
$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);

View File

@@ -30,23 +30,23 @@ class Froxlor extends ApiCommand
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
// log our actions
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] checking for updates");
// check for new version
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $this->version);
$latestversion = HttpClient::urlGet(UPDATE_URI);
$latestversion = explode('|', $latestversion);
if (is_array($latestversion) && count($latestversion) >= 1) {
$_version = $latestversion[0];
$_message = isset($latestversion[1]) ? $latestversion[1] : '';
$_link = isset($latestversion[2]) ? $latestversion[2] : '';
// add the branding so debian guys are not gettings confused
// about their version-number
$version_label = $_version . $this->branding;
$version_link = $_link;
$message_addinfo = $_message;
// not numeric -> error-message
if (! preg_match('/^((\d+\\.)(\d+\\.)(\d+\\.)?(\d+)?(\-(svn|dev|rc)(\d+))?)$/', $_version)) {
// check for customized version to not output
@@ -59,7 +59,7 @@ class Froxlor extends ApiCommand
// nothing new
$isnewerversion = 0;
}
// anzeige über version-status mit ggfls. formular
// zum update schritt #1 -> download
if ($isnewerversion == 1) {
@@ -93,7 +93,7 @@ class Froxlor extends ApiCommand
/**
*
* @todo export settings to file
* @todo export settings
*
* @access admin
*/
@@ -166,7 +166,7 @@ class Froxlor extends ApiCommand
{
// currently not implemented as it required validation too so no wrong settings are being stored via API
throw new Exception("Not available yet.", 501);
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
$setting = $this->getParam('key');
$value = $this->getParam('value', true, '');
@@ -193,7 +193,7 @@ class Froxlor extends ApiCommand
public function listFunctions()
{
$module = $this->getParam('module', true, '');
$functions = array();
if ($module != null) {
// check existence
@@ -234,7 +234,7 @@ class Froxlor extends ApiCommand
$reflection = new \ReflectionClass($mod);
$_functions = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($_functions as $func) {
if ($func->class == $mod && $func->isPublic() && !$func->isStatic()) {
if ($func->class == $mod && $func->isPublic() && ! $func->isStatic()) {
array_push($functions, array_merge(array(
'module' => $matches[1],
'function' => $func->name
@@ -248,7 +248,7 @@ class Froxlor extends ApiCommand
throw new Exception("Cannot search directory '" . $path . "'. No such directory.", 500);
}
}
// return the list
return $this->response(200, "successfull", $functions);
}
@@ -274,7 +274,7 @@ class Froxlor extends ApiCommand
'head' => 'There is no comment-block for "' . $module . '.' . $function . '"'
);
}
$clines = explode("\n", $comment);
$result = array();
$result['params'] = array();

View File

@@ -30,8 +30,8 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') || ! empty($this->getUserDetail('ip')))) {
$this->logger()->logAction(ADM_ACTION, LOG_NOTICE, "[API] list ips and ports");
$ip_where = "";
if (!empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != -1) {
$ip_where = "WHERE `id` IN (".implode(", ", json_decode($this->getUserDetail('ip'), true)).")";
if (! empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != - 1) {
$ip_where = "WHERE `id` IN (" . implode(", ", json_decode($this->getUserDetail('ip'), true)) . ")";
}
$result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` " . $ip_where . " ORDER BY `ip` ASC, `port` ASC
@@ -63,9 +63,9 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') || ! empty($this->getUserDetail('ip')))) {
$id = $this->getParam('id');
if (!empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != -1) {
if (! empty($this->getUserDetail('ip')) && $this->getUserDetail('ip') != - 1) {
$allowed_ips = json_decode($this->getUserDetail('ip'), true);
if (!in_array($id, $allowed_ips)) {
if (! in_array($id, $allowed_ips)) {
throw new Exception("You cannot access this resource", 405);
}
}
@@ -87,6 +87,34 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
/**
* create a new ip/port entry
*
* @param string $ip
* @param int $port
* optional, default 80
* @param bool $listen_statement
* optional, default 0 (false)
* @param bool $namevirtualhost_statement
* optional, default 0 (false)
* @param bool $vhostcontainer
* optional, default 0 (false)
* @param string $specialsettings
* optional, default empty
* @param bool $vhostcontainer_servername_statement
* optional, default 0 (false)
* @param string $default_vhostconf_domain
* optional, defatul empty
* @param string $docroot
* optional, default empty (point to froxlor)
* @param bool $ssl
* optional, default 0 (false)
* @param string $ssl_cert_file
* optional, requires $ssl = 1, default empty
* @param string $ssl_key_file
* optional, requires $ssl = 1, default empty
* @param string $ssl_ca_file
* optional, requires $ssl = 1, default empty
* @param string $ssl_cert_chainfile
* optional, requires $ssl = 1, default empty
*
* @access admin
* @throws Exception
* @return array
@@ -94,7 +122,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
public function add()
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
$ip = validate_ip2($this->getParam('ip'), false, 'invalidip', false, false, false, true);
$port = validate($this->getParam('port', true, 80), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
'stringisempty',
@@ -107,7 +135,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$vhostcontainer_servername_statement = ! empty($this->getParam('vhostcontainer_servername_statement', true, 1)) ? 1 : 0;
$default_vhostconf_domain = validate(str_replace("\r\n", "\n", $this->getParam('default_vhostconf_domain', true, '')), 'default_vhostconf_domain', '/^[^\0]*$/', '', array(), true);
$docroot = validate($this->getParam('docroot', true, ''), 'docroot', '', '', array(), true);
if ((int) Settings::Get('system.use_ssl') == 1) {
$ssl = ! empty($this->getParam('ssl', true, 0)) ? intval($this->getParam('ssl', true, 0)) : 0;
$ssl_cert_file = validate($this->getParam('ssl_cert_file', $ssl, ''), 'ssl_cert_file', '', '', array(), true);
@@ -121,49 +149,49 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$ssl_ca_file = '';
$ssl_cert_chainfile = '';
}
if ($listen_statement != '1') {
$listen_statement = '0';
}
if ($namevirtualhost_statement != '1') {
$namevirtualhost_statement = '0';
}
if ($vhostcontainer != '1') {
$vhostcontainer = '0';
}
if ($vhostcontainer_servername_statement != '1') {
$vhostcontainer_servername_statement = '0';
}
if ($ssl != '1') {
$ssl = '0';
}
if ($ssl_cert_file != '') {
$ssl_cert_file = makeCorrectFile($ssl_cert_file);
}
if ($ssl_key_file != '') {
$ssl_key_file = makeCorrectFile($ssl_key_file);
}
if ($ssl_ca_file != '') {
$ssl_ca_file = makeCorrectFile($ssl_ca_file);
}
if ($ssl_cert_chainfile != '') {
$ssl_cert_chainfile = makeCorrectFile($ssl_cert_chainfile);
}
if (strlen(trim($docroot)) > 0) {
$docroot = makeCorrectDir($docroot);
} else {
$docroot = '';
}
$result_checkfordouble_stmt = Database::prepare("
SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`
WHERE `ip` = :ip AND `port` = :port");
@@ -171,11 +199,11 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
'ip' => $ip,
'port' => $port
));
if ($result_checkfordouble['id'] != '') {
standard_error('myipnotdouble', '', true);
}
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_IPSANDPORTS . "`
SET
@@ -205,11 +233,11 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
);
Database::pexecute($ins_stmt, $ins_data);
$ins_data['id'] = Database::lastInsertId();
inserttask('1');
// Using nameserver, insert a task which rebuilds the server config
inserttask('4');
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ip = '[' . $ip . ']';
}
@@ -227,7 +255,35 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
* update ip/port entry by given id
*
* @param int $id
*
* @param string $ip
* optional
* @param int $port
* optional, default 80
* @param bool $listen_statement
* optional, default 0 (false)
* @param bool $namevirtualhost_statement
* optional, default 0 (false)
* @param bool $vhostcontainer
* optional, default 0 (false)
* @param string $specialsettings
* optional, default empty
* @param bool $vhostcontainer_servername_statement
* optional, default 0 (false)
* @param string $default_vhostconf_domain
* optional, defatul empty
* @param string $docroot
* optional, default empty (point to froxlor)
* @param bool $ssl
* optional, default 0 (false)
* @param string $ssl_cert_file
* optional, requires $ssl = 1, default empty
* @param string $ssl_key_file
* optional, requires $ssl = 1, default empty
* @param string $ssl_ca_file
* optional, requires $ssl = 1, default empty
* @param string $ssl_cert_chainfile
* optional, requires $ssl = 1, default empty
*
* @access admin
* @throws ErrorException
* @return array
@@ -240,7 +296,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$result = $this->apiCall('IpsAndPorts.get', array(
'id' => $id
));
$ip = validate_ip2($this->getParam('ip', true, $result['ip']), false, 'invalidip', false, false, false, true);
$port = validate($this->getParam('port', true, $result['port']), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
'stringisempty',
@@ -253,7 +309,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$vhostcontainer_servername_statement = $this->getParam('vhostcontainer_servername_statement', true, $result['vhostcontainer_servername_statement']);
$default_vhostconf_domain = validate(str_replace("\r\n", "\n", $this->getParam('default_vhostconf_domain', true, $result['default_vhostconf_domain'])), 'default_vhostconf_domain', '/^[^\0]*$/', '', array(), true);
$docroot = validate($this->getParam('docroot', true, $result['docroot']), 'docroot', '', '', array(), true);
if ((int) Settings::Get('system.use_ssl') == 1) {
$ssl = $this->getParam('ssl', true, $result['ssl']);
$ssl_cert_file = validate($this->getParam('ssl_cert_file', $ssl, $result['ssl_cert_file']), 'ssl_cert_file', '', '', array(), true);
@@ -267,7 +323,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$ssl_ca_file = '';
$ssl_cert_chainfile = '';
}
$result_checkfordouble_stmt = Database::prepare("
SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`
WHERE `ip` = :ip AND `port` = :port
@@ -276,7 +332,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
'ip' => $ip,
'port' => $port
));
$result_sameipotherport_stmt = Database::prepare("
SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`
WHERE `ip` = :ip AND `id` <> :id
@@ -285,55 +341,55 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
'ip' => $ip,
'id' => $id
), true, true);
if ($listen_statement != '1') {
$listen_statement = '0';
}
if ($namevirtualhost_statement != '1') {
$namevirtualhost_statement = '0';
}
if ($vhostcontainer != '1') {
$vhostcontainer = '0';
}
if ($vhostcontainer_servername_statement != '1') {
$vhostcontainer_servername_statement = '0';
}
if ($ssl != '1') {
$ssl = '0';
}
if ($ssl_cert_file != '') {
$ssl_cert_file = makeCorrectFile($ssl_cert_file);
}
if ($ssl_key_file != '') {
$ssl_key_file = makeCorrectFile($ssl_key_file);
}
if ($ssl_ca_file != '') {
$ssl_ca_file = makeCorrectFile($ssl_ca_file);
}
if ($ssl_cert_chainfile != '') {
$ssl_cert_chainfile = makeCorrectFile($ssl_cert_chainfile);
}
if (strlen(trim($docroot)) > 0) {
$docroot = makeCorrectDir($docroot);
} else {
$docroot = '';
}
if ($result['ip'] != $ip && $result['ip'] == Settings::Get('system.ipaddress') && $result_sameipotherport['id'] == '') {
standard_error('cantchangesystemip', '', true);
} elseif ($result_checkfordouble['id'] != '' && $result_checkfordouble['id'] != $id) {
standard_error('myipnotdouble', '', true);
} else {
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_IPSANDPORTS . "`
SET
@@ -364,11 +420,11 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
'id' => $id
);
Database::pexecute($upd_stmt, $upd_data);
inserttask('1');
// Using nameserver, insert a task which rebuilds the server config
inserttask('4');
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] changed IP/port from '" . $result['ip'] . ":" . $result['port'] . "' to '" . $ip . ":" . $port . "'");
$result = $this->apiCall('IpsAndPorts.get', array(
@@ -405,7 +461,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$result_checkdomain = Database::pexecute_first($result_checkdomain_stmt, array(
'id' => $id
), true, true);
if (empty($result_checkdomain)) {
if (! in_array($result['id'], explode(',', Settings::Get('system.defaultip'))) && ! in_array($result['id'], explode(',', Settings::Get('system.defaultsslip')))) {
@@ -419,7 +475,7 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
'id' => $id,
'ip' => $result['ip']
));
if (($result['ip'] != Settings::Get('system.ipaddress')) || ($result['ip'] == Settings::Get('system.ipaddress') && $result_sameipotherport['id'] != '')) {
$del_stmt = Database::prepare("

View File

@@ -374,7 +374,7 @@ class PhpSettings extends ApiCommand implements ResourceEntity
* optional number of seconds for idle-timeout if FPM is used, default is fpm-daemon-value
* @param string $limit_extensions
* optional limitation of php-file-extensions if FPM is used, default is fpm-daemon-value
*
*
* @access admin
* @throws Exception
* @return array