add with_ips parameter to SubDomains.listing() and SubDomains.get(); add column ips/ports to domain tablelisting (admin and customer)

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-05-23 13:50:50 +02:00
parent 9b5d3aed97
commit d3a8c8628e
4 changed files with 71 additions and 0 deletions

View File

@@ -410,6 +410,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
* optional, the domain-id * optional, the domain-id
* @param string $domainname * @param string $domainname
* optional, the domainname * optional, the domainname
* @param bool $with_ips
* optional, default true
* *
* @access admin, customer * @access admin, customer
* @return string json-encoded array * @return string json-encoded array
@@ -420,6 +422,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0); $id = $this->getParam('id', true, 0);
$dn_optional = $id > 0; $dn_optional = $id > 0;
$domainname = $this->getParam('domainname', $dn_optional, ''); $domainname = $this->getParam('domainname', $dn_optional, '');
$with_ips = $this->getParam('with_ips', true, true);
// convert possible idn domain to punycode // convert possible idn domain to punycode
if (substr($domainname, 0, 4) != 'xn--') { if (substr($domainname, 0, 4) != 'xn--') {
@@ -478,6 +481,10 @@ class SubDomains extends ApiCommand implements ResourceEntity
} }
$result = Database::pexecute_first($result_stmt, $params, true, true); $result = Database::pexecute_first($result_stmt, $params, true, true);
if ($result) { if ($result) {
$result['ipsandports'] = [];
if ($with_ips) {
$result['ipsandports'] = $this->getIpsForDomain($result['id']);
}
$result['domain_hascert'] = $this->getHasCertValueForDomain((int)$result['id'], (int)$result['parentdomainid']); $result['domain_hascert'] = $this->getHasCertValueForDomain((int)$result['id'], (int)$result['parentdomainid']);
$this->logger()->logAction($this->isAdmin() ? FroxlorLogger::ADM_ACTION : FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get subdomain '" . $result['domain'] . "'"); $this->logger()->logAction($this->isAdmin() ? FroxlorLogger::ADM_ACTION : FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get subdomain '" . $result['domain'] . "'");
return $this->response($result); return $this->response($result);
@@ -854,6 +861,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
/** /**
* lists all subdomain entries * lists all subdomain entries
* *
* @param bool $with_ips
* optional, default true
* @param int $customerid * @param int $customerid
* optional, admin-only, select (sub)domains of a specific customer by id * optional, admin-only, select (sub)domains of a specific customer by id
* @param string $loginname * @param string $loginname
@@ -875,6 +884,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
*/ */
public function listing() public function listing()
{ {
$with_ips = $this->getParam('with_ips', true, true);
if ($this->isAdmin()) { if ($this->isAdmin()) {
// if we're an admin, list all subdomains of all the admins customers // if we're an admin, list all subdomains of all the admins customers
// or optionally for one specific customer identified by id or loginname // or optionally for one specific customer identified by id or loginname
@@ -952,6 +962,10 @@ class SubDomains extends ApiCommand implements ResourceEntity
$result = []; $result = [];
Database::pexecute($domains_stmt, $query_fields, true, true); Database::pexecute($domains_stmt, $query_fields, true, true);
while ($row = $domains_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $domains_stmt->fetch(PDO::FETCH_ASSOC)) {
$row['ipsandports'] = [];
if ($with_ips) {
$row['ipsandports'] = $this->getIpsForDomain($row['id']);
}
$row['domain_hascert'] = $this->getHasCertValueForDomain((int)$row['id'], (int)$row['parentdomainid']); $row['domain_hascert'] = $this->getHasCertValueForDomain((int)$row['id'], (int)$row['parentdomainid']);
$result[] = $row; $result[] = $row;
} }
@@ -961,6 +975,39 @@ class SubDomains extends ApiCommand implements ResourceEntity
]); ]);
} }
/**
* get ips connected to given domain as array
*
* @param number $domain_id
* @param bool $ssl_only
* optional, return only ssl enabled ip's, default false
* @return array
*/
private function getIpsForDomain($domain_id = 0, $ssl_only = false)
{
$fields = '`ips`.ip, `ips`.port, `ips`.ssl';
if ($this->isAdmin()) {
$fields = '`ips`.*';
}
$resultips_stmt = Database::prepare("
SELECT " . $fields . " FROM `" . TABLE_DOMAINTOIP . "` AS `dti`, `" . TABLE_PANEL_IPSANDPORTS . "` AS `ips`
WHERE `dti`.`id_ipandports` = `ips`.`id` AND `dti`.`id_domain` = :domainid " . ($ssl_only ? " AND `ips`.`ssl` = '1'" : ""));
Database::pexecute($resultips_stmt, [
'domainid' => $domain_id
]);
$ipandports = [];
while ($rowip = $resultips_stmt->fetch(PDO::FETCH_ASSOC)) {
if (filter_var($rowip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$rowip['is_ipv6'] = true;
}
$ipandports[] = $rowip;
}
return $ipandports;
}
/** /**
* returns the total number of accessible subdomain entries * returns the total number of accessible subdomain entries
* *

View File

@@ -197,4 +197,16 @@ class Domain
return $result; return $result;
} }
public static function listIPs(array $attributes): string
{
if (isset($attributes['fields']['ipsandports']) && !empty($attributes['fields']['ipsandports'])) {
$iplist = "";
foreach ($attributes['fields']['ipsandports'] as $ipport) {
$iplist .= $ipport['ip'].':'.$ipport['port'].'<br>';
}
return $iplist;
}
return lng('panel.empty');
}
} }

View File

@@ -45,6 +45,12 @@ return [
'label' => lng('domains.domainname'), 'label' => lng('domains.domainname'),
'field' => 'domain_ace', 'field' => 'domain_ace',
], ],
'ipsandports' => [
'label' => lng('admin.ipsandports.ipsandports'),
'field' => 'ipsandports',
'sortable' => false,
'callback' => [Domain::class, 'listIPs'],
],
'c.name' => [ 'c.name' => [
'label' => lng('customer.name'), 'label' => lng('customer.name'),
'field' => 'customer.name', 'field' => 'customer.name',

View File

@@ -39,6 +39,12 @@ return [
'field' => 'domain_ace', 'field' => 'domain_ace',
'callback' => [Domain::class, 'domainExternalLinkInfo'], 'callback' => [Domain::class, 'domainExternalLinkInfo'],
], ],
'ipsandports' => [
'label' => lng('admin.ipsandports.ipsandports'),
'field' => 'ipsandports',
'sortable' => false,
'callback' => [Domain::class, 'listIPs'],
],
'd.documentroot' => [ 'd.documentroot' => [
'label' => lng('panel.path'), 'label' => lng('panel.path'),
'field' => 'documentroot', 'field' => 'documentroot',