finish Mysqls.update, untested
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -229,7 +229,6 @@ if ($page == 'admins'
|
|||||||
} elseif($action == 'edit'
|
} elseif($action == 'edit'
|
||||||
&& $id != 0
|
&& $id != 0
|
||||||
) {
|
) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$json_result = Admins::getLocal($userinfo, array(
|
$json_result = Admins::getLocal($userinfo, array(
|
||||||
'id' => $id
|
'id' => $id
|
||||||
|
|||||||
@@ -172,48 +172,12 @@ if ($page == 'overview') {
|
|||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
if (isset($result['databasename']) && $result['databasename'] != '') {
|
if (isset($result['databasename']) && $result['databasename'] != '') {
|
||||||
if (!isset($sql_root[$result['dbserver']]) || !is_array($sql_root[$result['dbserver']])) {
|
|
||||||
$result['dbserver'] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
||||||
// Only change Password if it is set, do nothing if it is empty! -- PH 2004-11-29
|
try {
|
||||||
$password = validate($_POST['mysql_password'], 'password');
|
$json_result = Mysqls::getLocal($userinfo, $_POST)->update();
|
||||||
if ($password != '') {
|
} catch (Exception $e) {
|
||||||
// validate password
|
dynamic_error($e->getMessage());
|
||||||
$password = validatePassword($password);
|
|
||||||
|
|
||||||
if ($password == $result['databasename']) {
|
|
||||||
standard_error('passwordshouldnotbeusername');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begin root-session
|
|
||||||
Database::needRoot(true);
|
|
||||||
foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) {
|
|
||||||
$stmt = Database::prepare("SET PASSWORD FOR :dbname@:host = PASSWORD(:password)");
|
|
||||||
$params = array(
|
|
||||||
"dbname" => $result['databasename'],
|
|
||||||
"host" => $mysql_access_host,
|
|
||||||
"password" => $password
|
|
||||||
);
|
|
||||||
Database::pexecute($stmt, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt = Database::prepare("FLUSH PRIVILEGES");
|
|
||||||
Database::pexecute($stmt);
|
|
||||||
Database::needRoot(false);
|
|
||||||
// End root-session
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the Database description -- PH 2004-11-29
|
|
||||||
$log->logAction(USR_ACTION, LOG_INFO, "edited database '" . $result['databasename'] . "'");
|
|
||||||
$databasedescription = validate($_POST['description'], 'description');
|
|
||||||
$stmt = Database::prepare("UPDATE `" . TABLE_PANEL_DATABASES . "`
|
|
||||||
SET `description` = :desc
|
|
||||||
WHERE `customerid` = :customerid
|
|
||||||
AND `id` = :id"
|
|
||||||
);
|
|
||||||
Database::pexecute($stmt, array("desc" => $databasedescription, "customerid" => $userinfo['customerid'], "id" => $id));
|
|
||||||
redirectTo($filename, array('page' => $page, 's' => $s));
|
redirectTo($filename, array('page' => $page, 's' => $s));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|||||||
@@ -319,8 +319,126 @@ class Mysqls extends ApiCommand implements ResourceEntity
|
|||||||
throw new Exception("MySQL database with " . $key . " could not be found", 404);
|
throw new Exception("MySQL database with " . $key . " could not be found", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update a mysql database entry by either id or dbname
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* optional, the database-id
|
||||||
|
* @param string $dbname
|
||||||
|
* optional, the databasename
|
||||||
|
* @param int $dbserver
|
||||||
|
* optional, specify database-server, default is none
|
||||||
|
* @param string $mysql_password
|
||||||
|
* optional, update password for the database
|
||||||
|
* @param string $description
|
||||||
|
* optional, description for database
|
||||||
|
*
|
||||||
|
* @access admin, customer
|
||||||
|
* @throws Exception
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function update()
|
public function update()
|
||||||
{}
|
{
|
||||||
|
$id = $this->getParam('id', true, 0);
|
||||||
|
$dn_optional = ($id <= 0 ? false : true);
|
||||||
|
$dbname = $this->getParam('dbname', $dn_optional, '');
|
||||||
|
$dbserver = $this->getParam('dbserver', true, - 1);
|
||||||
|
|
||||||
|
if ($id <= 0 && empty($dbname)) {
|
||||||
|
throw new Exception("Either 'id' or 'dbname' parameter must be given", 406);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) {
|
||||||
|
throw new Exception("You cannot access this resource", 405);
|
||||||
|
}
|
||||||
|
|
||||||
|
$json_result = Mysqls::getLocal($this->getUserData(), array(
|
||||||
|
'id' => $id,
|
||||||
|
'dbname' => $dbname,
|
||||||
|
'dbserver' => $dbserver
|
||||||
|
))->get();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$id = $result['id'];
|
||||||
|
|
||||||
|
// paramters
|
||||||
|
$password = $this->getParam('mysql_password', true, '');
|
||||||
|
$databasedescription = $this->getParam('description', true, '');
|
||||||
|
|
||||||
|
// validation
|
||||||
|
$password = validate($password, 'password', '', '', array(), true);
|
||||||
|
$password = validatePassword($password, true);
|
||||||
|
$databasedescription = validate(trim($databasedescription), 'description', '', '', array(), true);
|
||||||
|
|
||||||
|
// validate whether the dbserver exists
|
||||||
|
$dbserver = validate($dbserver, html_entity_decode($this->lng['mysql']['mysql_server']), '', '', 0, true);
|
||||||
|
Database::needRoot(true, $dbserver);
|
||||||
|
Database::needSqlData();
|
||||||
|
$sql_root = Database::getSqlData();
|
||||||
|
Database::needRoot(false);
|
||||||
|
if (! isset($sql_root) || ! is_array($sql_root)) {
|
||||||
|
throw new ErrorException("Database server with index #" . $dbserver . " is unknown", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($sendinfomail != 1) {
|
||||||
|
$sendinfomail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get needed customer info to reduce the mysql-usage-counter by one
|
||||||
|
if ($this->isAdmin()) {
|
||||||
|
// get customer id
|
||||||
|
$customer_id = $this->getParam('customer_id');
|
||||||
|
$json_result = Customers::getLocal($this->getUserData(), array(
|
||||||
|
'id' => $result['customerid']
|
||||||
|
))->get();
|
||||||
|
$customer = json_decode($json_result, true)['data'];
|
||||||
|
// check whether the customer has enough resources to get the database added
|
||||||
|
if ($customer['mysqls_used'] >= $customer['mysqls'] && $customer['mysqls'] != '-1') {
|
||||||
|
throw new Exception("Customer has no more resources available", 406);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$customer_id = $this->getUserDetail('customer_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($password != '') {
|
||||||
|
// validate password
|
||||||
|
$password = validatePassword($password, true);
|
||||||
|
|
||||||
|
if ($password == $result['databasename']) {
|
||||||
|
standard_error('passwordshouldnotbeusername', '', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Begin root-session
|
||||||
|
Database::needRoot(true, $result['dbserver']);
|
||||||
|
foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) {
|
||||||
|
$stmt = Database::prepare("SET PASSWORD FOR :dbname@:host = PASSWORD(:password)");
|
||||||
|
$params = array(
|
||||||
|
"dbname" => $result['databasename'],
|
||||||
|
"host" => $mysql_access_host,
|
||||||
|
"password" => $password
|
||||||
|
);
|
||||||
|
Database::pexecute($stmt, $params, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = Database::prepare("FLUSH PRIVILEGES");
|
||||||
|
Database::pexecute($stmt, null, true, true);
|
||||||
|
Database::needRoot(false);
|
||||||
|
// End root-session
|
||||||
|
}
|
||||||
|
$stmt = Database::prepare("
|
||||||
|
UPDATE `" . TABLE_PANEL_DATABASES . "`
|
||||||
|
SET `description` = :desc
|
||||||
|
WHERE `customerid` = :customerid
|
||||||
|
AND `id` = :id
|
||||||
|
");
|
||||||
|
$params = array(
|
||||||
|
"desc" => $databasedescription,
|
||||||
|
"customerid" => ($this->isAdmin() ? $customer['customerid'] : $this->getUserDetail('customerid')),
|
||||||
|
"id" => $id
|
||||||
|
);
|
||||||
|
Database::pexecute($stmt, $params, true, true);
|
||||||
|
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] updated mysql-database '" . $result['databasename'] . "'");
|
||||||
|
return $this->response(200, "successfull", $params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list all databases, if called from an admin, list all databases of all customers you are allowed to view, or specify id or loginname for one specific customer
|
* list all databases, if called from an admin, list all databases of all customers you are allowed to view, or specify id or loginname for one specific customer
|
||||||
|
|||||||
Reference in New Issue
Block a user