first commit

This commit is contained in:
pgmr3
2023-12-22 17:21:31 +01:00
commit dde03b1d27
57 changed files with 6287 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapConformance extends RdapObject {
protected $rdapConformance;
/**
* @return void
*/
public function dumpContents(): void {
echo nl2br('- ' . $this->getRdapConformance() . PHP_EOL);
}
/**
* @return string|null
*/
public function getRdapConformance(): ?string {
return $this->rdapConformance;
}
}

View File

@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapDescription extends RdapObject {
/**
* @var string|null
*/
protected $description;
/**
* RdapDescription constructor.
* @param string $key
* @param mixed $content
*/
public function __construct(string $key, $content) {
parent::__construct($key, null);
if (is_array($content)) {
$this->description = $content[0];
} else {
$this->description = $content;
}
}
/**
* @return void
*/
public function dumpContents(): void {
echo nl2br(' - Description: ' . $this->getDescription() . PHP_EOL);
}
/**
* @return string
*/
public function getDescription(): string {
return $this->description??'';
}
}

View File

@@ -0,0 +1,193 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapEntity extends RdapObject {
/**
* @var string|null
*/
protected $type;
/**
* @var string
*/
protected $lang;
/*
* @var string
*/
protected $handle;
/**
* @var null|RdapStatus[]
*/
protected $status;
/**
* @var null|string
*/
protected $port43;
/**
* @var RdapVcard[]|null
*/
protected $vcards ;
protected $vcardArray ;
protected $objectClassName;
protected $remarks;
/**
* @var RdapRole[]|null
*/
protected $roles;
/**
* @var null|RdapPublicId[]
*/
protected $publicIds;
protected $entities ;
protected $events;
protected $links;
protected $legalRepresentative;
protected $nicbrDomainCount;
protected $nicbrInetCount;
protected $nicbrAutnumCount;
public function __construct(string $key, $content) {
parent::__construct($key, $content);
if ($this->vcardArray && count($this->vcardArray) > 0) {
foreach ($this->vcardArray as $id => $vcard) {
if (is_array($vcard)) {
foreach ($vcard as $v) {
if (is_array($v)) {
foreach ($v as $card) {
$this->vcards[] = new RdapVcard($card[0], $card[1], $card[2], $card[3]);
}
}
}
} else {
$this->type = $vcard;
}
}
unset($this->vcardArray);
}
}
/**
* @return string
*/
public function getLanguage(): string {
return $this->lang;
}
/**
* @return string
*/
public function getRoles(): string {
$return = '';
if (is_array($this->roles)) {
foreach ($this->roles as $role) {
if ($return !== '') {
$return .= ', ';
}
$return .= $role->getRole();
}
}
return $return;
}
/**
*
*/
public function dumpContents(): void {
echo nl2br('- Handle: ' . $this->getHandle() . PHP_EOL);
if (isset($this->roles)) {
foreach ($this->roles as $role) {
echo nl2br('- Role: ' . $role->getRole() . PHP_EOL);
}
}
//if (isset($this->port43)) {
// echo '- Port 43 whois: ' . $this->getPort43() . PHP_EOL;
//}
if (isset($this->publicIds) && is_array($this->publicIds)) {
foreach ($this->publicIds as $publicid) {
$publicid->dumpContents();
}
}
if (is_array($this->vcards) && (count($this->vcards) > 0)) {
foreach ($this->vcards as $vcard) {
$vcard->dumpContents();
}
}
}
/**
* @return string|null
*/
public function getHandle() {
if (is_array($this->handle)){
return $this->handle[0];
}
else {
return $this->handle;
}
}
/**
* @return null|string
*/
public function getPort43() {
return $this->port43;
}
public function getEntities() {
return $this->entities;
}
public function getPublicIds() {
return $this->publicIds;
}
public function getVcards() {
return $this->vcards;
}
public function getEvents(){
return $this->events;
}
public function getLinks(){
return $this->links;
}
public function getLegalRepresentative(){
return $this->legalRepresentative;
}
public function getRemarks(){
return $this->remarks;
}
public function getStatus(){
return $this->status;
}
public function getNicbrDomainCount(){
return $this->nicbrDomainCount;
}
public function getNicbrInetCount(){
return $this->nicbrInetCount;
}
public function getNicbrAutnumCount(){
return $this->nicbrAutnumCount;
}
}

View File

@@ -0,0 +1,36 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapEvent extends RdapObject {
protected $events;
public function __construct(string $key, $content) {
parent::__construct($key, null);
if (isset($content[0])) {
foreach ($content as $c) {
$this->events[$c['eventAction']] = $c['eventDate'];
}
} else {
$this->events[$content['eventAction']] = $content['eventDate'];
}
}
/**
* @return array|null
*/
public function getEvents(): ?array {
return $this->events;
}
/**
* @return void
*/
public function dumpContents(): void {
if (is_array($this->events)) {
foreach ($this->events as $action => $date) {
echo nl2br(" - $action: $date\n");
}
}
}
}

View File

@@ -0,0 +1,74 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapLink extends RdapObject {
/**
* @var string
*/
protected $rel;
/**
* @var string
*/
protected $href;
/**
* @var string
*/
protected $type;
/**
* @var string
*/
protected $value;
public function __construct(string $key, $content) {
parent::__construct($key, null);
if (is_array($content)) {
//print_r($content);
if (isset($content[0])) {
if (isset($content[0]['rel'])){
$this->rel = $content[0]['rel'];
}
$this->href = $content[0]['href'];
$this->type = $content[0]['type'];
if (isset($content[0]['value'])){//fie
$this->value = $content[0]['value'];
}//fie
} else {
if (isset($content['rel'])){
$this->rel = $content['rel'];
}
$this->href = $content['href'];
$this->type = $content['type'];
if (isset($content['value'])){//fie
$this->value = $content['value'];
}//fie
}
}
}
public function dumpContents(): void {
//fie org echo ' - Link: ' . $this->rel . ': ', $this->href . ' (' . $this->title . ")\n";
echo nl2br(' - Link: ' . $this->href . "\n");//fie
}
/**
* @return string
*/
public function getRel(): string {
return $this->rel;
}
/**
* @return string
*/
public function getHref(): string {
return $this->href;
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
}

View File

@@ -0,0 +1,59 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapNameserver extends RdapObject {
/**
* @var string
*/
protected $ldhName;
/**
* @var null|RdapStatus
*/
protected $status;
/**
* @var RdapLink[]|null
*/
protected $links;
/** @var RdapEvent[] */
protected $events ;
protected $ipAddresses;
/**
* @return string
*/
public function getStatus(): string {
$return = '';
if (is_array($this->status)) {
foreach ($this->status as $status) {
if ($return !== '') {
$return .= ', ';
}
$return .= $status;
}
}
return $return;
}
/**
* @return void
*/
public function dumpContents(): void {
echo nl2br('- Object Classname: ' . $this->getObjectClassname() . PHP_EOL);
echo nl2br('- LDH Name: ' . $this->ldhName . PHP_EOL);
if (isset($this->status)) {
//echo "- Status: ".$this->status->getStatus().PHP_EOL;
}
if (isset($this->links)) {
foreach ($this->links as $link) {
$link->dumpContents();
}
}
if (isset($this->events)) {
foreach ($this->events as $event) {
$event->dumpContents();
}
}
}
}

View File

@@ -0,0 +1,68 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapNotice extends RdapObject {
protected $title;
protected $type ;
/**
* @var RdapDescription[]|null
*/
protected $description;
/**
* @var RdapLink[]|null
*/
protected $links;
public function __construct(string $key, $content) {
$this->objectClassName = 'Notice';
parent::__construct($key, $content);
}
/**
* @return void
*/
public function dumpContents(): void {
echo nl2br('- ' . $this->getTitle() . ": " . $this->getType() . PHP_EOL);
if (is_array($this->description)) {
foreach ($this->description as $descr) {
$descr->dumpContents();
}
}
if (is_array($this->links)) {
foreach ($this->links as $link) {
$link->dumpContents();
}
}
}
/**
* @return string|null
*/
public function getTitle(): ?string {
return $this->title;
}
/**
* @return string|null
*/
public function getType(): ?string {
return $this->type;
}
/**
* @return array
*/
public function getDescription(): array {
$return = '';
if (is_array($this->description)) {
foreach ($this->description as $descr) {
$return .= $descr . PHP_EOL;
}
} else {
$return = $this->description;
}
return $return;
}
}

View File

@@ -0,0 +1,138 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
use Metaregistrar\RDAP\RdapException;
/**
* This is the parent class for all RdapXXXXX objects. This class will interpret the json that was received and convert it into objects that give back the data required
* Class RdapObject
*
* @package Metaregistrar\RDAP
*/
class RdapObject {
/**
* @var string
*/
protected $objectClassName;
/**
* RdapObject constructor.
*
* @param string $key
* @param mixed $content
*
* @throws \Metaregistrar\RDAP\RdapException
*/
public function __construct(string $key, $content) {
if ($content) {
if (is_array($content)) {
foreach ($content as $contentKey => $contentValue) {
if (is_array($contentValue)) {
if (is_numeric($contentKey)) {
foreach ($contentValue as $k => $v) {
$this->{$k}[] = self::createObject($k, $v);
}
} else {
$this->{$contentKey}[] = self::createObject($contentKey, $contentValue);
}
} else {
$this->{$contentKey} = $contentValue;
}
}
} else {
$var = lcfirst(str_replace('Metaregistrar\RDAP\Data\\', '', $key));
$this->{$var} = $content;
}
}
}
/**
*
*
* @param $key
* @param $value
*
* @return mixed
* @throws \Metaregistrar\RDAP\RdapException
*/
private static function createObject($key, $value) {
if (is_numeric($key)) {
if (is_array($value)) {
throw new RdapException("'$key' can not be an array.");
}
return $value;
}
return self::KeyToObject($key, $value);
}
/**
*
*
* @param string $name
* @param mixed $content
*
* @return mixed
*/
public static function KeyToObject(string $name, $content) {
$name = self::KeyToObjectName($name);
if (class_exists($name)) {
return new $name($name, $content);
}
return $content;
}
/**
*
*
* @param string $name
*
* @return string
*/
private static function KeyToObjectName(string $name): string {
switch ($name) {
case 'rdapConformance':
return RdapConformance::class;
case 'entities':
return RdapEntity::class;
case 'remarks':
return RdapRemark::class;
case 'links':
return RdapLink::class;
case 'notices':
return RdapNotice::class;
case 'events':
return RdapEvent::class;
case 'roles':
return RdapRole::class;
case 'description':
return RdapDescription::class;
case 'port43':
return RdapPort43::class;
case 'nameservers':
return RdapNameserver::class;
case 'secureDNS':
return RdapSecureDNS::class;
case 'status':
return RdapStatus::class;
case 'publicIds':
return RdapPublicId::class;
default:
return $name;
}
}
/**
* @return string
*/
final public function getObjectClassname(): string {
if (is_string($this->objectClassName)) {
return $this->objectClassName;
} else {
return '';
}
}
}

View File

@@ -0,0 +1,6 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapPort43 extends RdapObject {
}

View File

@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapPublicId extends RdapObject {
protected $ids;
public function __construct(string $key, $content) {
$this->objectClassName = 'PublicId';
parent::__construct($key, null);
if (is_array($content)) {
foreach ($content as $id) {
$this->ids[$id['type']] = $id['identifier'];
}
}
}
public function dumpContents(): void {
foreach ($this->ids as $type => $identifier) {
echo nl2br("- $type: $identifier\n");
}
}
public function getIds(){
return $this->ids;
}
}

View File

@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapRemark extends RdapObject {
protected $description = [];
/**
* @return void
*/
public function dumpContents(): void {
foreach ($this->getDescription() as $description) {
$description->dumpContents();
}
}
/**
* @return RdapDescription[]
*/
public function getDescription(): array {
return $this->description;
}
}

View File

@@ -0,0 +1,19 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapRole extends RdapObject {
/**
* @return void
*/
public function dumpContents(): void {
echo nl2br('- Role: ' . $this->getRole() . PHP_EOL);
}
/**
* @return mixed
*/
public function getRole() {
return $this->{0};
}
}

View File

@@ -0,0 +1,148 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapSecureDNS extends RdapObject {
/**
* @var bool
*/
protected $rdapSecureDNS;
/**
* @var null|string
*/
protected $delegationSigned;
/**
* @var null|int
*/
protected $maxSigLife;
/**
* @var null|array
*/
protected $dsData;
/**
* @var null|string
*/
protected $keyTag;
/**
* @var null|string
*/
protected $digestType;
/**
* @var null|string
*/
protected $digest;
/**
* @var null|string
*/
protected $algorithm;
/**
* @return boolean
*/
public function isRdapSecureDNS(): bool {
return $this->rdapSecureDNS;
}
/**
* @return void
*/
public function dumpContents(): void {
if ($this->delegationSigned) {
echo nl2br("- Domain name is signed\n");
} else {
echo nl2br("- Domain name is not signed\n");
}
if ($this->getKeyTag()) {
$this->dumpDigest();
}
if ($this->getDsData()) {
$this->dumpDnskey();
}
}
/**
* @return null|string
*/
public function getKeyTag(): ?string {
if (is_array($this->keyTag)) {
return (string)array_shift($this->keyTag);
}
return $this->keyTag;
}
/**
* @return void
*/
public function dumpDigest(): void {
echo nl2br('- Delegation signed: ' . $this->getDelegationSigned() . PHP_EOL);
echo nl2br('- Max sig life: ' . $this->getMaxSigLife() . PHP_EOL);
echo nl2br('- Keytag: ' . $this->getKeyTag() . PHP_EOL);
echo nl2br('- Algorithm: ' . $this->getAlgorithm() . PHP_EOL);
echo nl2br('- Digest Type :' . $this->getDigestType() . PHP_EOL);
echo nl2br('- Digest: ' . $this->getDigest() . PHP_EOL);
}
/**
* @return null|string
*/
public function getDelegationSigned(): ?string {
return $this->delegationSigned;
}
/**
* @return int|null
*/
public function getMaxSigLife(): ?int {
return $this->maxSigLife;
}
/**
* @return null|string
*/
public function getAlgorithm(): ?string {
if (is_array($this->algorithm)) {
return (string)array_shift($this->algorithm);
}
return $this->algorithm;
}
/**
* @return null|string
*/
public function getDigestType(): ?string {
if (is_array($this->digestType)) {
return (string)array_shift($this->digestType);
}
return $this->digestType;
}
/**
* @return null|string
*/
public function getDigest(): ?string {
if (is_array($this->digest)) {
return (string)array_shift($this->digest);
}
return $this->digest;
}
/**
* @return array|null
*/
public function getDsData(): ?array {
return $this->dsData;
}
/**
* @return void
*/
public function dumpDnskey(): void {
echo nl2br('- Delegation signed: ' . $this->getDelegationSigned() . PHP_EOL);
echo nl2br('- Max sig life: ' . $this->getMaxSigLife() . PHP_EOL);
echo nl2br('- DNS Key: ' . implode(', ', $this->getDsData()) . PHP_EOL);
}
}

View File

@@ -0,0 +1,25 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapStatus extends RdapObject {
/**
* @var null|string
*/
protected $rdapStatus;
/**
* @return void
*/
public function dumpContents(): void {
echo nl2br('- Status: ' . $this->getStatus() . PHP_EOL);
}
/**
* @return null|string
*/
public function getStatus(): ?string{
return $this->rdapStatus ?? $this->{0} ?? null;
}
}

117
RDAP/src/Data/RdapVcard.php Normal file
View File

@@ -0,0 +1,117 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Data;
final class RdapVcard {
/**
* @var null|string
*/
protected $name;
/**
* @var null|string
*/
protected $fieldtype;
protected $content;
/**
* @var null|int
*/
protected $preference;
/**
* @var null|array
*/
protected $contenttypes;
public function __construct($name, $extras, $type, $contents) {
$this->name = $name;
if (is_array($extras)) {
if (isset($extras['type'])) {
if (is_array($extras['type'])) {
foreach ($extras['type'] as $contentType) {
$this->contenttypes[] = $contentType;
}
} else {
$this->contenttypes[] = $extras['type'];
}
}
if (isset($extras['pref'])) {
$this->preference = $extras['pref'];
}
}
$this->fieldtype = $type;
$this->content = $contents;
}
public function getName(): ?string {
return $this->name;
}
public function getFieldtype(): ?string {
return $this->fieldtype;
}
public function getContentTypes(): ?array {
return $this->contenttypes;
}
public function dumpContents(): void {
echo nl2br(' - ' . $this->getContent() . PHP_EOL);
}
public function getContent(): ?string {
if ($this->name === 'version') {
return 'Version: ' . $this->content;
}
if ($this->name === 'tel') {
return 'Type: ' . $this->fieldtype . ', Preference: ' . $this->preference . ', Content: ' . $this->content . ' (' . $this->dumpContentTypes() . ')';
}
if ($this->name === 'email') {
return 'Type: ' . $this->name . ', Content: ' . $this->content;
}
if ($this->name === 'adr') {
$return = 'Type: ' . $this->name . ', Content: ';
foreach ($this->content as $content) {
if (is_array($content)) {
foreach ($content as $cont) {
$return .= $cont . ' ';
}
} else if (trim($content) !== '') {
$return .= $content . ' ';
}
}
return $return;
}
if ($this->name === 'fn') {
return 'Type: ' . $this->name . ', Content: ' . $this->content;
}
if ($this->name === 'kind') {
return 'Kind: ' . $this->content;
}
if ($this->name === 'ISO-3166-1-alpha-2') {
return 'Language: ' . $this->content . ' (' . $this->name . ')';
}
return null;
}
public function getContentSimple(){
return $this->content;
}
public function dumpContentTypes(): string {
$return = '';
if (is_array($this->contenttypes)) {
foreach ($this->contenttypes as $type) {
if ($return !== '') {
$return .= ', ';
}
$return .= $type;
}
}
return $return;
}
}

239
RDAP/src/Rdap.php Normal file
View File

@@ -0,0 +1,239 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP;
include './src/Data/RdapObject.php';//fie
include './src/Data/RdapConformance.php';//fie
include './src/Data/RdapDescription.php';//fie
include './src/Data/RdapEntity.php';//fie
include './src/Data/RdapEvent.php';//fie
include './src/Data/RdapLink.php';//fie
include './src/Data/RdapNameserver.php';//fie
include './src/Data/RdapNotice.php';//fie
include './src/Data/RdapPort43.php';//fie
include './src/Data/RdapPublicId.php';//fie
include './src/Data/RdapRemark.php';//fie
include './src/Data/RdapRole.php';//fie
include './src/Data/RdapSecureDNS.php';//fie
include './src/Data/RdapStatus.php';//fie
include './src/Data/RdapVcard.php';//fie
include './src/Responses/RdapResponse.php';//fie
include './src/Responses/RdapAsnResponse.php';//fie
include './src/Responses/RdapIpResponse.php';//fie
//include './src/RdapException.php';//fie
use Metaregistrar\RDAP\Responses\RdapResponse;
use Metaregistrar\RDAP\Responses\RdapAsnResponse;
use Metaregistrar\RDAP\Responses\RdapIpResponse;
use Metaregistrar\RDAP\RdapException; //fie
class Rdap {
public const ASN = 'asn';
public const IPV4 = 'ipv4';
public const IPV6 = 'ipv6';
public const NS = 'ns';
public const DOMAIN = 'domain';
public const SEARCH = 'search';
public const HOME = 'home';
private static $protocols = [
'ipv4' => [self::HOME => 'https://data.iana.org/rdap/ipv4.json', self::SEARCH => 'ip/'],
'domain' => [self::HOME => 'https://data.iana.org/rdap/dns.json', self::SEARCH => 'domain/'],
'ns' => [self::HOME => 'https://data.iana.org/rdap/dns.json', self::SEARCH => 'nameserver/'],
'ipv6' => [self::HOME => 'https://data.iana.org/rdap/ipv6.json', self::SEARCH => 'ip/'],
'asn' => [self::HOME => 'https://data.iana.org/rdap/asn.json', self::SEARCH => 'autnum/']
];
private $protocol;
private $publicationdate = '';
private $version = '';
private $description = '';
/**
* Rdap constructor.
*
* @param string $protocol
*
* @throws \Metaregistrar\RDAP\RdapException
*/
public function __construct(string $protocol) {
if (($protocol !== self::ASN) && ($protocol !== self::IPV4) && ($protocol !== self::IPV6) && ($protocol !== self::DOMAIN)) {
throw new RdapException('Protocol ' . $protocol . ' is not recognized by this rdap client implementation');
}
$this->protocol = $protocol;
}
/**
* @return string
*/
public function getPublicationdate(): string {
return $this->publicationdate;
}
/**
* @param string $publicationdate
*/
public function setPublicationdate(string $publicationdate): void {
$this->publicationdate = $publicationdate;
}
/**
* @return string
*/
public function getVersion(): string {
return $this->version;
}
/**
* @param string $version
*/
public function setVersion(string $version): void {
$this->version = $version;
}
/**
* @return string
*/
public function getDescription(): string {
return $this->description;
}
/**
* @param string $description
*/
public function setDescription(string $description): void {
$this->description = $description;
}
/**
*
*
* @param string $search
*
* @return \Metaregistrar\RDAP\Responses\RdapAsnResponse|\Metaregistrar\RDAP\Responses\RdapIpResponse|\Metaregistrar\RDAP\Responses\RdapResponse|null
* @throws \Metaregistrar\RDAP\RdapException
*/
public function search(string $search): ?RdapResponse {
if (!isset($search) || ($search === '')) {
throw new RdapException('Search parameter may not be empty');
}
$search = trim($search);
if ((!is_string($search)) && in_array($this->getProtocol(), [self::DOMAIN, self::NS, self::IPV4, self::IPV6], true)) {
throw new RdapException('Search parameter must be a string for ipv4, ipv6, domain or nameserver searches');
}
if ((!is_numeric($search)) && ($this->getProtocol() === self::ASN)) {
throw new RdapException('Search parameter must be a number or a string with numeric info for asn searches');
}
//Domain string ohne . abfangen
if ( (is_string($search)) && (count(explode('.', $search, 2))<2) && ($this->getProtocol() === self::DOMAIN)) {
throw new RdapException('Search parameter must be a string with xxx.tld info for domain searches');
}
$parameter = $this->prepareSearch($search);
$services = $this->readRoot();
foreach ($services as $service) {
foreach ($service[0] as $number) {
// ip address range match
if (strpos($number, '-') > 0) {
[$start, $end] = explode('-', $number);
if (($parameter >= $start) && ($parameter <= $end)) {
// check for slash as last character in the server name, if not, add it
if ($service[1][0][strlen($service[1][0]) - 1] !== '/') {
$service[1][0] .= '/';
}
$rdap = file_get_contents($service[1][0] . self::$protocols[$this->protocol][self::SEARCH] . $search);
return $this->createResponse($this->getProtocol(), $rdap);
}
} else {
// exact match
if ($number === $parameter) {
// check for slash as last character in the server name, if not, add it
if ($service[1][0][strlen($service[1][0]) - 1] !== '/') {
$service[1][0] .= '/';
}
$rdap = file_get_contents($service[1][0] . self::$protocols[$this->protocol][self::SEARCH] . $search);
return $this->createResponse($this->getProtocol(), $rdap);
}
}
}
}
return null;
}
/**
* @return string
*/
public function getProtocol(): string {
return $this->protocol;
}
private function prepareSearch(string $string): string {
switch ($this->getProtocol()) {
case self::IPV4:
[$start] = explode('.', $string);
return $start . '.0.0.0/8';
case self::IPV6: //fie
//[$start] = explode('.', $string);
//return $start . '.0.0.0/8';
return $string;//fie
case self::DOMAIN:
$extension = explode('.', $string, 2);
return $extension[1];
default:
return $string;
}
}
/**
* @return array
*/
private function readRoot(): array {
$rdap = file_get_contents(self::$protocols[$this->protocol][self::HOME]);
$json = json_decode($rdap, false);
$this->setDescription($json->description);
$this->setPublicationdate($json->publication);
$this->setVersion($json->version);
return $json->services;
}
/**
*
*
* @param string $protocol
* @param string $json
*
* @return \Metaregistrar\RDAP\Responses\RdapResponse
* @throws \Metaregistrar\RDAP\RdapException
*/
protected function createResponse(string $protocol, string $json): RdapResponse {
switch ($protocol) {
case self::IPV4:
return new RdapIpResponse($json);
case self::IPV6: //fie
return new RdapIpResponse($json);//fie
case self::ASN:
return new RdapAsnResponse($json);
default:
return new RdapResponse($json);
}
}
public function case(): void {
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Metaregistrar\RDAP;
use Exception;
class RdapException extends Exception {
}

View File

@@ -0,0 +1,6 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Responses;
class RdapAsnResponse extends RdapResponse {
}

View File

@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Responses;
final class RdapIpResponse extends RdapResponse {
protected $startAddress;
protected $endAddress;
protected $ipVersion;
protected $country;
/**
* @return string
*/
public function getStartAddress(): string {
return $this->startAddress;
}
/**
* @return string
*/
public function getEndAddress(): string {
return $this->endAddress;
}
/**
* @return string
*/
public function getIpVersion(): string {
return $this->ipVersion;
}
/**
* @return string
*/
public function getCountry(): string {
return $this->country;
}
}

View File

@@ -0,0 +1,231 @@
<?php declare(strict_types=1);
namespace Metaregistrar\RDAP\Responses;
use Metaregistrar\RDAP\Data\RdapConformance;
use Metaregistrar\RDAP\Data\RdapEntity;
use Metaregistrar\RDAP\Data\RdapEvent;
use Metaregistrar\RDAP\Data\RdapLink;
use Metaregistrar\RDAP\Data\RdapNameserver;
use Metaregistrar\RDAP\Data\RdapNotice;
use Metaregistrar\RDAP\Data\RdapObject;
use Metaregistrar\RDAP\Data\RdapRemark;
use Metaregistrar\RDAP\Data\RdapSecureDNS;
use Metaregistrar\RDAP\Data\RdapStatus;
use Metaregistrar\RDAP\RdapException;
class RdapResponse {
/**
* @var string|null
*/
private $objectClassName;
/**
* @var string|null
*/
private $ldhName ;
/**
* @var string
*/
private $handle = '';
/*
* @var string
*/
private $name = '';
/**
* @var string
*/
private $type = '';
/**
* @var null|RdapConformance[]
*/
private $rdapConformance;
/**
* @var null|RdapEntity[]
*/
private $entities;
/**
* @var null|RdapLink[]
*/
private $links;
/**
* @var null|RdapRemark[]
*/
private $remarks;
/**
* @var null|RdapNotice[]
*/
private $notices;
/**
* @var null|RdapEvent[]
*/
private $events;
/**
* @var null|string
*/
private $port43;
/**
* @var null|RdapNameserver[]
*/
private $nameservers;
/**
* @var null|RdapStatus[]
*/
private $status;
/**
* @var null|RdapSecureDNS[]
*/
private $secureDNS;
/**
* @var int
*/
private $errorCode;
/**
* @var string
*/
private $title;
/**
* RdapResponse constructor.
*
* @param string $json
*
* @throws \Metaregistrar\RDAP\RdapException
*/
public function __construct(string $json) {
if ($data = json_decode($json, true)) {
foreach ($data as $key => $value) {
if (is_array($value)) {
// $value is an array
foreach ($value as $k => $v) {
$this->{$key}[] = RdapObject::KeyToObject($key, $v);
}
} else {
// $value is not an array, just create a var with this value (startAddress endAddress ipVersion etc etc)
$this->{$key} = $value;
}
}
} else {
throw new RdapException('Response object could not be validated as proper JSON');
}
}
/**
* @return string
*/
final public function getHandle(): string {
return $this->handle;
}
/**
* @return RdapConformance[]|null
*/
final public function getConformance(): ?array {
return $this->rdapConformance;
}
/**
* @return string
*/
final public function getName(): string {
return $this->name;
}
/**
* @return string
*/
final public function getType(): string {
return $this->type;
}
/**
* @return RdapEntity[]|null
*/
final public function getEntities(): ?array {
return $this->entities;
}
/**
* @return RdapLink[]|null
*/
final public function getLinks(): ?array {
return $this->links;
}
/**
* @return RdapRemark[]|null
*/
final public function getRemarks(): ?array {
return $this->remarks;
}
/**
* @return RdapNotice[]|null
*/
final public function getNotices(): ?array {
return $this->notices;
}
/**
* @return string|null
*/
final public function getPort43(): ?string {
return $this->port43;
}
/**
* @return RdapNameserver[]|null
*/
final public function getNameservers(): ?array {
return $this->nameservers;
}
/**
* @return RdapStatus[]|null
*/
final public function getStatus(): ?array {
return $this->status;
}
/**
* @return RdapEvent[]|null
*/
final public function getEvents(): ?array {
return $this->events;
}
/**
* @return string|null
*/
final public function getClassname(): ?string {
return $this->objectClassName;
}
/**
* @return string|null
*/
final public function getLDHName(): ?string {
return $this->ldhName;
}
/**
* @return RdapSecureDNS[]|null
*/
final public function getSecureDNS(): ?array {
return $this->secureDNS;
}
/**
* @return int|null
*/
final public function getErrorCode(): ?int {
return $this->errorCode;
}
/**
* @return string|null
*/
final public function getTitle(): ?string {
return $this->title;
}
}