File: //opt/cpvendor/bin/db_info
#!/usr/local/emps/bin/php
<?php
$ret['data']['mysql'] = [];
$ret['metadata']['result'] = 'ok';
include_once(__DIR__.'/inc.php');
// Get the MySQL root details
$access['login'] = 'root';
$access['password'] = trim(file_get_contents('/var/webuzo/my.conf'));
$access['host'] = 'localhost';
$access['port'] = 3306;
$ret['data']['mysql']['access'] = $access;
// Get the mapping i.e. the users list
$users = cl_user_list();
//print_r($users);
foreach($users as $user => $v){
$mysql = @json_decode(file_get_contents($globals['users_path'].'/'.$user.'/mysql'), true);
//echo $globals['users_path'].'/'.$user.'/mysql'."\n";
if(empty($mysql['localhost']['dbusers'])){
continue;
}
$ret['data']['mysql']['mapping'][$user] = array_keys($mysql['localhost']['dbusers']);
}
// CL needs this to be {} when the array is empty
if(empty($ret['data']['mysql']['mapping'])){
$ret['data']['mysql']['mapping'] = (object) [];
}
echo json_encode($ret, JSON_PRETTY_PRINT)."\n";