Browse Source

initial commit

main
ghost 12 months ago
parent
commit
6bbe001254
  1. 1
      .gitignore
  2. 32
      README.md
  3. 13
      composer.json
  4. 49
      composer.lock
  5. 92
      src/public/dig.php

1
.gitignore vendored

@ -0,0 +1 @@
/vendor/

32
README.md

@ -1,2 +1,34 @@
# dns-api # dns-api
Simple DNS API Simple DNS API
## Install
```
git clone https://github.com/YGGverse/dns-api.git
cd dns-api
composer install
```
## Run
```
cd src/public
php -S localhost:8080
```
## Usage
### Dig
#### Single record
```
dig.php?name=php.net&record=A
```
#### Multiple records
```
dig.php?name=php.net&records[]=A&records[]=AAAA
```

13
composer.json

@ -0,0 +1,13 @@
{
"name": "yggverse/dns-api",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"Yggverse\\DnsApi\\": "src/"
}
},
"require": {
"yggverse/dns": "^1.0"
}
}

49
composer.lock generated

@ -0,0 +1,49 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4fd3c797b2c98cf2e93558b64c5da47b",
"packages": [
{
"name": "yggverse/dns",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/YGGverse/dns-php.git",
"reference": "e54a40bb673e3c4cb87d8d7275adc7121042281e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/YGGverse/dns-php/zipball/e54a40bb673e3c4cb87d8d7275adc7121042281e",
"reference": "e54a40bb673e3c4cb87d8d7275adc7121042281e",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-4": {
"Yggverse\\Dns\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"support": {
"issues": "https://github.com/YGGverse/dns-php/issues",
"source": "https://github.com/YGGverse/dns-php/tree/1.0.0"
},
"time": "2023-12-15T16:19:42+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

92
src/public/dig.php

@ -0,0 +1,92 @@
<?php
// Set headers
header('Content-Type: application/json; charset=utf-8');
// Load dependencies
require_once(__DIR__ . '/../../vendor/autoload.php');
// Valid name required to continue
if (empty($_GET['name']) || !is_string($_GET['name']) || !\Yggverse\Dns\Dig::isHostName($_GET['name']))
{
exit(
json_encode(
[
'success' => false,
'message' => _('valid name required')
]
)
);
}
// Valid records required to continue
$records = [];
if (isset($_GET['record']) && is_string($_GET['record']) && \Yggverse\Dns\Dig::isRecord($_GET['record']))
{
$records[] = $_GET['record'];
}
if (isset($_GET['records']) && is_array($_GET['records']))
{
foreach ($_GET['records'] as $record)
{
if (is_string($record) && \Yggverse\Dns\Dig::isRecord($record))
{
$records[] = $record;
}
}
}
// At least one record required
if (empty($records))
{
exit(
json_encode(
[
'success' => false,
'message' => sprintf(
_('valid record(s) required: %s'),
implode(
',',
array_unique(
$records
)
)
)
]
)
);
}
// Resolve begin
if (!$result = \Yggverse\Dns\Dig::records($_GET['name'], array_unique($records)))
{
exit(
json_encode(
[
'success' => false,
'message' => sprintf(
_('%s records for %s not found'),
implode(
',',
array_unique(
$records
)
),
$_GET['name']
)
]
)
);
}
// Done
exit(
json_encode(
[
'success' => true,
'records' => $result
]
)
);
Loading…
Cancel
Save