add frontend for new MysqlServer API command
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -91,12 +91,12 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
$test_connection = $this->getParam('test_connection', true, 1);
|
||||
|
||||
// validation
|
||||
$mysql_host = Validate::validate_ip2($mysql_host, true, 'invalidip', true, true, false);
|
||||
if ($mysql_host === false) {
|
||||
$mysql_host = Validate::validateLocalHostname($mysql_host);
|
||||
if ($mysql_host === false) {
|
||||
$mysql_host = Validate::validateDomain($mysql_host);
|
||||
if ($mysql_host === false) {
|
||||
$mysql_host_chk = Validate::validate_ip2($mysql_host, true, 'invalidip', true, true, false);
|
||||
if ($mysql_host_chk === false) {
|
||||
$mysql_host_chk = Validate::validateLocalHostname($mysql_host);
|
||||
if ($mysql_host_chk === false) {
|
||||
$mysql_host_chk = Validate::validateDomain($mysql_host);
|
||||
if ($mysql_host_chk === false) {
|
||||
throw new Exception("Invalid mysql server ip/hostname", 406);
|
||||
}
|
||||
}
|
||||
@@ -170,8 +170,10 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
/**
|
||||
* remove a mysql-server
|
||||
*
|
||||
* @param int $id
|
||||
* optional the number of the mysql server (either id or dbserver must be set)
|
||||
* @param int $dbserver
|
||||
* the number of the mysql-server
|
||||
* optional the number of the mysql server (either id or dbserver must be set)
|
||||
*
|
||||
* @access admin
|
||||
* @throws Exception
|
||||
@@ -181,7 +183,10 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
{
|
||||
$this->validateAccess();
|
||||
|
||||
$dbserver = (int) $this->getParam('dbserver');
|
||||
$id = (int) $this->getParam('id', true, -1);
|
||||
$dn_optional = $id >= 0;
|
||||
$dbserver = (int) $this->getParam('dbserver', $dn_optional, -1);
|
||||
$dbserver = $id >= 0 ? $id : $dbserver;
|
||||
|
||||
if ($dbserver == 0) {
|
||||
throw new Exception('Cannot delete first/default mysql-server', 406);
|
||||
@@ -197,7 +202,7 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
// check whether the server is in use by any customer
|
||||
$result_ms = $this->databasesOnServer(true, $dbserver);
|
||||
if ($result_ms > 0) {
|
||||
Response::standardError('mysqlserverstillhasdbs', '', true);
|
||||
throw new Exception(lng('error.mysqlserverstillhasdbs'), 406);
|
||||
}
|
||||
|
||||
// when removing, remove from list of allowed_mysqlservers from any customers
|
||||
@@ -239,6 +244,7 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
// passwords will not be returned in any case for security reasons
|
||||
unset($sqlrootdata['password']);
|
||||
$sqlrootdata['id'] = $index;
|
||||
$result[$index] = $sqlrootdata;
|
||||
}
|
||||
|
||||
@@ -268,8 +274,10 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
/**
|
||||
* Return info about a specific mysql-server
|
||||
*
|
||||
* @param int $id
|
||||
* optional the number of the mysql server (either id or dbserver must be set)
|
||||
* @param int $dbserver
|
||||
* the number of the mysql-server
|
||||
* optional the number of the mysql server (either id or dbserver must be set)
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws Exception
|
||||
@@ -277,7 +285,10 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$dbserver = (int) $this->getParam('dbserver');
|
||||
$id = (int) $this->getParam('id', true, -1);
|
||||
$dn_optional = $id >= 0;
|
||||
$dbserver = (int) $this->getParam('dbserver', $dn_optional, -1);
|
||||
$dbserver = $id >= 0 ? $id : $dbserver;
|
||||
|
||||
// get all data from lib/userdata
|
||||
require Froxlor::getInstallDir() . "/lib/userdata.inc.php";
|
||||
@@ -297,14 +308,17 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
unset($sql_root[$dbserver]['password']);
|
||||
$sql_root[$dbserver]['id'] = $dbserver;
|
||||
return $this->response($sql_root[$dbserver]);
|
||||
}
|
||||
|
||||
/**
|
||||
* update given mysql-server
|
||||
*
|
||||
* @param int $id
|
||||
* optional the number of the mysql server (either id or dbserver must be set)
|
||||
* @param int $dbserver
|
||||
* the number of the mysql server
|
||||
* optional the number of the mysql server (either id or dbserver must be set)
|
||||
* @param string $mysql_host
|
||||
* ip/hostname of mysql-server
|
||||
* @param string $mysql_port
|
||||
@@ -332,7 +346,10 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
{
|
||||
$this->validateAccess();
|
||||
|
||||
$dbserver = (int) $this->getParam('dbserver');
|
||||
$id = (int) $this->getParam('id', true, -1);
|
||||
$dn_optional = $id >= 0;
|
||||
$dbserver = (int) $this->getParam('dbserver', $dn_optional, -1);
|
||||
$dbserver = $id >= 0 ? $id : $dbserver;
|
||||
|
||||
require Froxlor::getInstallDir() . "/lib/userdata.inc.php";
|
||||
|
||||
@@ -342,7 +359,11 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
|
||||
$result = $sql_root[$dbserver];
|
||||
|
||||
$mysql_host = $this->getParam('mysql_host', true, $result['host']);
|
||||
if ($dbserver == 0) {
|
||||
$mysql_host = $result['host'];
|
||||
} else {
|
||||
$mysql_host = $this->getParam('mysql_host', true, $result['host']);
|
||||
}
|
||||
$mysql_port = $this->getParam('mysql_port', true, $result['port'] ?? 3306);
|
||||
$mysql_ca = $this->getParam('mysql_ca', true, $result['ssl']['caFile'] ?? '');
|
||||
$mysql_verifycert = $this->getBoolParam('mysql_verifycert', true, $result['ssl']['verifyServerCertificate'] ?? 0);
|
||||
@@ -353,12 +374,12 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
$test_connection = $this->getParam('test_connection', true, 1);
|
||||
|
||||
// validation
|
||||
$mysql_host = Validate::validate_ip2($mysql_host, true, 'invalidip', true, true, false);
|
||||
if ($mysql_host === false) {
|
||||
$mysql_host = Validate::validateLocalHostname($mysql_host);
|
||||
if ($mysql_host === false) {
|
||||
$mysql_host = Validate::validateDomain($mysql_host);
|
||||
if ($mysql_host === false) {
|
||||
$mysql_host_chk = Validate::validate_ip2($mysql_host, true, 'invalidip', true, true, false);
|
||||
if ($mysql_host_chk === false) {
|
||||
$mysql_host_chk = Validate::validateLocalHostname($mysql_host);
|
||||
if ($mysql_host_chk === false) {
|
||||
$mysql_host_chk = Validate::validateDomain($mysql_host);
|
||||
if ($mysql_host_chk === false) {
|
||||
throw new Exception("Invalid mysql server ip/hostname", 406);
|
||||
}
|
||||
}
|
||||
@@ -367,6 +388,14 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
$privileged_password = Validate::validate($privileged_password, 'password', '', '', [], true);
|
||||
$description = Validate::validate(trim($description), 'description', Validate::REGEX_DESC_TEXT, '', [], true);
|
||||
|
||||
if ($mysql_host != $result['host']) {
|
||||
// check whether the server is in use by any customer
|
||||
$result_ms = $this->databasesOnServer(true, $dbserver);
|
||||
if ($result_ms > 0) {
|
||||
throw new Exception("Unable to update mysql-host as there are still databases on it", 406);
|
||||
}
|
||||
}
|
||||
|
||||
// testing connection with given credentials
|
||||
if ($test_connection) {
|
||||
$options = array(
|
||||
@@ -491,6 +520,12 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
['sql' => $sql, 'sql_root' => $sql_root],
|
||||
'automatically generated userdata.inc.php for froxlor'
|
||||
);
|
||||
chmod(Froxlor::getInstallDir() . "/lib/userdata.inc.php", 0700);
|
||||
file_put_contents(Froxlor::getInstallDir() . "/lib/userdata.inc.php", $content);
|
||||
chmod(Froxlor::getInstallDir() . "/lib/userdata.inc.php", 0400);
|
||||
clearstatcache();
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
@opcache_invalidate(Froxlor::getInstallDir() . "/lib/userdata.inc.php", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ return [
|
||||
'label' => lng('customer.mysqlserver'),
|
||||
'type' => 'checkbox',
|
||||
'values' => $mysql_servers,
|
||||
'value' => isset($result['allowed_mysqlserver']) && !empty($result['allowed_mysqlserver']) ? json_decode($result['allowed_phpconfigs'], JSON_OBJECT_AS_ARRAY) : [],
|
||||
'value' => isset($result['allowed_mysqlserver']) && !empty($result['allowed_mysqlserver']) ? json_decode($result['allowed_mysqlserver'], JSON_OBJECT_AS_ARRAY) : [],
|
||||
'is_array' => 1
|
||||
],
|
||||
'phpenabled' => [
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
use Froxlor\Settings;
|
||||
|
||||
return [
|
||||
'mysqlserver_add' => [
|
||||
'title' => lng('admin.mysqlserver.add'),
|
||||
'image' => 'fa-solid fa-plus',
|
||||
'self_overview' => ['section' => 'mysqlserver', 'page' => 'mysqlserver'],
|
||||
'sections' => [
|
||||
'section_a' => [
|
||||
'title' => lng('admin.mysqlserver.mysqlserver'),
|
||||
'fields' => [
|
||||
'mysql_host' => [
|
||||
'label' => lng('admin.mysqlserver.host'),
|
||||
'type' => 'text',
|
||||
'mandatory' => true
|
||||
],
|
||||
'mysql_port' => [
|
||||
'label' => lng('admin.mysqlserver.port'),
|
||||
'type' => 'number',
|
||||
'min' => 1,
|
||||
'max' => 65535,
|
||||
'value' => 3306,
|
||||
'mandatory' => true
|
||||
],
|
||||
'description' => [
|
||||
'label' => lng('admin.mysqlserver.caption'),
|
||||
'type' => 'text',
|
||||
],
|
||||
'privileged_user' => [
|
||||
'label' => lng('admin.mysqlserver.user'),
|
||||
'type' => 'text',
|
||||
'mandatory' => true
|
||||
],
|
||||
'privileged_password' => [
|
||||
'label' => lng('admin.mysqlserver.password'),
|
||||
'type' => 'password',
|
||||
'mandatory' => true
|
||||
],
|
||||
'allow_all_customers' => [
|
||||
'label' => lng('admin.mysqlserver.allowall'),
|
||||
'type' => 'checkbox',
|
||||
'value' => '1',
|
||||
'checked' => false
|
||||
],
|
||||
'test_connection' => [
|
||||
'label' => lng('admin.mysqlserver.testconn'),
|
||||
'type' => 'checkbox',
|
||||
'value' => '1',
|
||||
'checked' => true
|
||||
]
|
||||
]
|
||||
],
|
||||
'section_b' => [
|
||||
'title' => lng('admin.mysqlserver.ssl'),
|
||||
'fields' => [
|
||||
'mysql_ca' => [
|
||||
'label' => lng('admin.mysqlserver.ssl_cert_file'),
|
||||
'type' => 'text'
|
||||
],
|
||||
'mysql_verifycert' => [
|
||||
'label' => lng('admin.mysqlserver.verify_ca'),
|
||||
'type' => 'checkbox',
|
||||
'value' => '1',
|
||||
'checked' => false
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
|
||||
return [
|
||||
'mysqlserver_edit' => [
|
||||
'title' => lng('admin.mysqlserver.edit'),
|
||||
'image' => 'fa-solid fa-pen',
|
||||
'self_overview' => ['section' => 'mysqlserver', 'page' => 'mysqlserver'],
|
||||
'sections' => [
|
||||
'section_a' => [
|
||||
'title' => lng('admin.mysqlserver.mysqlserver'),
|
||||
'fields' => [
|
||||
'mysql_host' => [
|
||||
'label' => lng('admin.mysqlserver.host'),
|
||||
'type' => empty($result['id']) ? 'label' : 'text',
|
||||
'value' => $result['host'],
|
||||
'mandatory' => true,
|
||||
],
|
||||
'mysql_port' => [
|
||||
'label' => lng('admin.mysqlserver.port'),
|
||||
'type' => 'number',
|
||||
'min' => 1,
|
||||
'max' => 65535,
|
||||
'value' => $result['port'],
|
||||
'mandatory' => true
|
||||
],
|
||||
'description' => [
|
||||
'label' => lng('admin.mysqlserver.caption'),
|
||||
'type' => 'text',
|
||||
'value' => $result['caption'],
|
||||
],
|
||||
'privileged_user' => [
|
||||
'label' => lng('admin.mysqlserver.user'),
|
||||
'type' => 'text',
|
||||
'value' => $result['user'],
|
||||
'mandatory' => true
|
||||
],
|
||||
'privileged_password' => [
|
||||
'label' => lng('admin.mysqlserver.password_emptynochange'),
|
||||
'type' => 'password'
|
||||
],
|
||||
'allow_all_customers' => [
|
||||
'label' => lng('admin.mysqlserver.allowall'),
|
||||
'type' => 'checkbox',
|
||||
'value' => '1',
|
||||
'checked' => false
|
||||
],
|
||||
'test_connection' => [
|
||||
'label' => lng('admin.mysqlserver.testconn'),
|
||||
'type' => 'checkbox',
|
||||
'value' => '1',
|
||||
'checked' => true
|
||||
]
|
||||
]
|
||||
],
|
||||
'section_b' => [
|
||||
'title' => lng('admin.mysqlserver.ssl'),
|
||||
'fields' => [
|
||||
'mysql_ca' => [
|
||||
'label' => lng('admin.mysqlserver.ssl_cert_file'),
|
||||
'type' => 'text',
|
||||
'value' => $result['ssl']['caFile'] ?? "",
|
||||
],
|
||||
'mysql_verifycert' => [
|
||||
'label' => lng('admin.mysqlserver.verify_ca'),
|
||||
'type' => 'checkbox',
|
||||
'value' => '1',
|
||||
'checked' => $result['ssl']['verifyServerCertificate'] ?? false,
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
0
lib/formfields/admin/mysqlserver/index.html
Normal file
0
lib/formfields/admin/mysqlserver/index.html
Normal file
@@ -182,6 +182,10 @@ return [
|
||||
'label' => lng('admin.ipsandports.ipsandports'),
|
||||
'required_resources' => 'change_serversettings'
|
||||
],
|
||||
[
|
||||
'url' => 'admin_mysqlserver.php?page=mysqlserver',
|
||||
'label' => lng('admin.mysqlserver.mysqlserver'),
|
||||
],
|
||||
[
|
||||
'url' => 'admin_plans.php?page=overview',
|
||||
'label' => lng('admin.plans.plans'),
|
||||
|
||||
89
lib/tablelisting/admin/tablelisting.mysqlserver.php
Normal file
89
lib/tablelisting/admin/tablelisting.mysqlserver.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
use Froxlor\UI\Callbacks\Admin;
|
||||
use Froxlor\UI\Listing;
|
||||
|
||||
return [
|
||||
'mysqlserver_list' => [
|
||||
'title' => lng('admin.mysqlserver.mysqlserver'),
|
||||
'icon' => 'fa-solid fa-server',
|
||||
'self_overview' => ['section' => 'mysqlserver', 'page' => 'mysqlserver'],
|
||||
'columns' => [
|
||||
'id' => [
|
||||
'label' => lng('admin.mysqlserver.dbserver'),
|
||||
'field' => 'id',
|
||||
],
|
||||
'caption' => [
|
||||
'label' => lng('admin.mysqlserver.caption'),
|
||||
'field' => 'caption',
|
||||
],
|
||||
'host' => [
|
||||
'label' => lng('admin.mysqlserver.host'),
|
||||
'field' => 'host',
|
||||
],
|
||||
'port' => [
|
||||
'label' => lng('admin.mysqlserver.port'),
|
||||
'field' => 'port',
|
||||
'class' => 'text-center',
|
||||
],
|
||||
'user' => [
|
||||
'label' => lng('admin.mysqlserver.user'),
|
||||
'field' => 'user',
|
||||
'visible' => [Admin::class, 'canChangeServerSettings']
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('mysqlserver_list', [
|
||||
'caption',
|
||||
'host',
|
||||
'port',
|
||||
]),
|
||||
'actions' => [
|
||||
'edit' => [
|
||||
'icon' => 'fa fa-edit',
|
||||
'title' => lng('panel.edit'),
|
||||
'href' => [
|
||||
'section' => 'mysqlserver',
|
||||
'page' => 'mysqlserver',
|
||||
'action' => 'edit',
|
||||
'id' => ':id'
|
||||
],
|
||||
'visible' => [Admin::class, 'canChangeServerSettings']
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'fa fa-trash',
|
||||
'title' => lng('panel.delete'),
|
||||
'class' => 'btn-danger',
|
||||
'href' => [
|
||||
'section' => 'mysqlserver',
|
||||
'page' => 'mysqlserver',
|
||||
'action' => 'delete',
|
||||
'id' => ':id'
|
||||
],
|
||||
'visible' => [Admin::class, 'canChangeServerSettings']
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -50,7 +50,7 @@ return [
|
||||
'label' => lng('mysql.mysql_server'),
|
||||
'field' => 'dbserver',
|
||||
'callback' => [Mysql::class, 'dbserver'],
|
||||
'visible' => $count_mysqlservers > 1
|
||||
'visible' => $multiple_mysqlservers
|
||||
]
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('mysql_list', [
|
||||
|
||||
Reference in New Issue
Block a user