File: //opt/cpvendor/bin/domains.php
<?php
$ret['data'] = [];
$ret['metadata']['result'] = 'ok';
include_once(__DIR__.'/inc.php');
// Get the parameters for data
$args = getopt('o:', ['owner:', 'name:', 'with-php']);
$owner = $args['owner'];
$owner = empty($args['o']) ? $args['owner'] : $args['o'];
$users = cl_user_list();
// If we are accessing as user, give only his domains
if(!empty($_ENV['soft_euid'])){
$tmp = posix_getpwuid($_ENV['soft_euid']);
if(!empty($owner) && $owner != $tmp['name']){
$users = [];
}
$owner = $tmp['name'];
}
if(!empty($users)){
foreach($users as $user => $v){
$v = @json_decode(file_get_contents($globals['users_path'].'/'.$user.'/info'), true);
if(empty($v)){
continue;
}
foreach($v['domains'] as $dk => $dv){
$u = [];
$u['owner'] = $v['user'];
$u['document_root'] = $dv['path'];
$u['is_main'] = $dk == $v['domain'];
// $u['locale_code'] = 'EN_us';
if(isset($args['with-php'])){
$php = empty($dv['php_version']) ? $globals['WU_DEFAULT_PHP'] : $dv['php_version'];
$u['php']['version'] = str_replace('php', '', $php);
$u['php']['ini_path'] = '/usr/local/apps/'.$php.'/etc/php.d';
$u['php']['fpm'] = 'php-fpm'.$u['php']['version'];
$u['php']['is_native'] = false;
}
if(!empty($owner) && $u['owner'] != $owner){
continue;
}
if(!empty($args['name']) && $args['name'] != $dk){
continue;
}
$ret['data'][$dk] = $u;
}
}
}
// CL needs this to be {} when the array is empty
if(empty($ret['data'])){
$ret['data'] = (object) [];
}
echo json_encode($ret, JSON_PRETTY_PRINT)."\n";