mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 15:33:44 +01:00
Added get ASN feature
Get the ASN name and number for the servers ip adress. This is able to be turned off with the CONST GET_ASN_INFO. Thanks to ripe.net for this service
This commit is contained in:
parent
c927d166a4
commit
374fb846e5
76
class.php
76
class.php
@ -21,6 +21,8 @@ class idlersConfig
|
|||||||
const DEFAULT_VIEW = 'CARDS';//CARDS or TABLE
|
const DEFAULT_VIEW = 'CARDS';//CARDS or TABLE
|
||||||
|
|
||||||
const SAVE_YABS_OUTPUT = true;//true or false
|
const SAVE_YABS_OUTPUT = true;//true or false
|
||||||
|
|
||||||
|
const GET_ASN_INFO = true;//Get ANS name and number
|
||||||
}
|
}
|
||||||
|
|
||||||
class elementHelpers extends idlersConfig
|
class elementHelpers extends idlersConfig
|
||||||
@ -3099,11 +3101,19 @@ class idlers extends helperFunctions
|
|||||||
|
|
||||||
public function getIpForDomain(string $domain, string $type = 'A'): string
|
public function getIpForDomain(string $domain, string $type = 'A'): string
|
||||||
{//Gets IP from A record for a domain
|
{//Gets IP from A record for a domain
|
||||||
$data = json_decode(file_get_contents("https://whatsmydns.net/api/details?server=428&type=$type&query=$domain"), true);
|
switch ($type) {
|
||||||
if (isset($data['data'][0]['response'][0])) {
|
case "A":
|
||||||
if (strlen($data['data'][0]['response'][0]) > 6) {
|
$data = dns_get_record($domain, DNS_A);
|
||||||
return $data['data'][0]['response'][0];
|
if (isset($data['0']['ip'])) {
|
||||||
}
|
return $data['0']['ip'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "AAAA":
|
||||||
|
$data = dns_get_record($domain, DNS_AAAA);
|
||||||
|
if (isset($data['0']['ipv6'])) {
|
||||||
|
return $data['0']['ipv6'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return "";//Doesnt exist/null/empty/invalid
|
return "";//Doesnt exist/null/empty/invalid
|
||||||
}
|
}
|
||||||
@ -3119,6 +3129,25 @@ class idlers extends helperFunctions
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAsnInfo(string $ip)
|
||||||
|
{//Thanks ripe.net
|
||||||
|
$data = json_decode(@file_get_contents("https://stat.ripe.net/data/whois/data.json?resource=$ip"), true);
|
||||||
|
if (isset($data) && $data['status_code'] == 200) {
|
||||||
|
$origin = $desc = '';
|
||||||
|
foreach ($data['data']['irr_records'][0] as $rec) {
|
||||||
|
if ($rec['key'] == 'descr') {
|
||||||
|
$desc = $rec['value'];
|
||||||
|
}
|
||||||
|
if ($rec['key'] == 'origin') {
|
||||||
|
$origin .= $rec['value'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "$desc, AS$origin";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function viewSwitcherIcon()
|
protected function viewSwitcherIcon()
|
||||||
{
|
{
|
||||||
$this->rowColOpen('row text-center', 'col-12');
|
$this->rowColOpen('row text-center', 'col-12');
|
||||||
@ -3383,7 +3412,6 @@ class idlers extends helperFunctions
|
|||||||
$this->outputString('</tbody></table></div>');
|
$this->outputString('</tbody></table></div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class itemInsert extends idlers
|
class itemInsert extends idlers
|
||||||
@ -3407,10 +3435,24 @@ class itemInsert extends idlers
|
|||||||
(empty($data['ipv4'])) ? $ipv4 = null : $ipv4 = $data['ipv4'];
|
(empty($data['ipv4'])) ? $ipv4 = null : $ipv4 = $data['ipv4'];
|
||||||
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
|
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
|
||||||
(empty($data['label'])) ? $label = null : $label = $data['label'];
|
(empty($data['label'])) ? $label = null : $label = $data['label'];
|
||||||
|
if (self::GET_ASN_INFO) {
|
||||||
|
if (!is_null($ipv4)) {
|
||||||
|
$asn = $this->getAsnInfo($ipv4);
|
||||||
|
} elseif (!is_null($ipv6)) {
|
||||||
|
$asn = $this->getAsnInfo($ipv6);
|
||||||
|
} else {
|
||||||
|
$asn = null;
|
||||||
|
}
|
||||||
|
if (empty($asn)) {
|
||||||
|
$asn = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$asn = null;
|
||||||
|
}
|
||||||
$location_id = $this->handleLocation($data['location']);
|
$location_id = $this->handleLocation($data['location']);
|
||||||
$provider_id = $this->handleProvider($data['provider']);
|
$provider_id = $this->handleProvider($data['provider']);
|
||||||
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `servers` (id, hostname, location, provider, ipv4,ipv6, owned_since, os, is_cpu_dedicated, is_dedicated, was_special, bandwidth, virt, has_yabs, ns1, ns2, ssh_port, label) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
|
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `servers` (id, hostname, location, provider, ipv4,ipv6, owned_since, os, is_cpu_dedicated, is_dedicated, was_special, bandwidth, virt, has_yabs, ns1, ns2, ssh_port, label, asn) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
|
||||||
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $ipv4, $ipv6, $data['owned_since'], $data['os'], $dedi_cpu, $dedi, $offer, $data['bandwidth'], $data['virt'], $data['has_yabs'], $data['ns1'], $data['ns2'], $data['ssh_port'], $label]);
|
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $ipv4, $ipv6, $data['owned_since'], $data['os'], $dedi_cpu, $dedi, $offer, $data['bandwidth'], $data['virt'], $data['has_yabs'], $data['ns1'], $data['ns2'], $data['ssh_port'], $label, $asn]);
|
||||||
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
|
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
|
||||||
return $item_id;
|
return $item_id;
|
||||||
}
|
}
|
||||||
@ -3425,13 +3467,27 @@ class itemInsert extends idlers
|
|||||||
(empty($data['ipv4'])) ? $ipv4 = null : $ipv4 = $data['ipv4'];
|
(empty($data['ipv4'])) ? $ipv4 = null : $ipv4 = $data['ipv4'];
|
||||||
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
|
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
|
||||||
(empty($data['label'])) ? $label = null : $label = $data['label'];
|
(empty($data['label'])) ? $label = null : $label = $data['label'];
|
||||||
|
if (self::GET_ASN_INFO) {
|
||||||
|
if (!is_null($ipv4)) {
|
||||||
|
$asn = $this->getAsnInfo($ipv4);
|
||||||
|
} elseif (!is_null($ipv6)) {
|
||||||
|
$asn = $this->getAsnInfo($ipv6);
|
||||||
|
} else {
|
||||||
|
$asn = null;
|
||||||
|
}
|
||||||
|
if (empty($asn)) {
|
||||||
|
$asn = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$asn = null;
|
||||||
|
}
|
||||||
($data['ram_type'] == 'GB') ? $ram_mb = $this->GBtoMB($data['ram']) : $ram_mb = $data['ram'];
|
($data['ram_type'] == 'GB') ? $ram_mb = $this->GBtoMB($data['ram']) : $ram_mb = $data['ram'];
|
||||||
($data['swap_type'] == 'GB') ? $swap_mb = $this->GBtoMB($data['swap']) : $swap_mb = $data['swap'];
|
($data['swap_type'] == 'GB') ? $swap_mb = $this->GBtoMB($data['swap']) : $swap_mb = $data['swap'];
|
||||||
($data['disk_type'] == 'TB') ? $disk_gb = $this->TBtoGB($data['disk']) : $disk_gb = $data['disk'];
|
($data['disk_type'] == 'TB') ? $disk_gb = $this->TBtoGB($data['disk']) : $disk_gb = $data['disk'];
|
||||||
$location_id = $this->handleLocation($data['location']);
|
$location_id = $this->handleLocation($data['location']);
|
||||||
$provider_id = $this->handleProvider($data['provider']);
|
$provider_id = $this->handleProvider($data['provider']);
|
||||||
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `servers` (id, hostname, location, provider, ipv4,ipv6, owned_since, os, is_cpu_dedicated, is_dedicated, was_special, bandwidth, virt, cpu, cpu_freq, ram, ram_type, swap, swap_type, disk, disk_type, ram_mb, swap_mb, disk_gb, ns1, ns2, ssh_port, label) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
|
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `servers` (id, hostname, location, provider, ipv4,ipv6, owned_since, os, is_cpu_dedicated, is_dedicated, was_special, bandwidth, virt, cpu, cpu_freq, ram, ram_type, swap, swap_type, disk, disk_type, ram_mb, swap_mb, disk_gb, ns1, ns2, ssh_port, label, asn) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
|
||||||
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $ipv4, $ipv6, $data['owned_since'], $data['os'], $dedi_cpu, $dedi, $offer, $data['bandwidth'], $data['virt'], $data['cpu_amount'], $data['cpu_speed'], $data['ram'], $data['ram_type'], $data['swap'], $data['swap_type'], $data['disk'], $data['disk_type'], $ram_mb, $swap_mb, $disk_gb, $data['ns1'], $data['ns2'], $data['ssh_port'], $label]);
|
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $ipv4, $ipv6, $data['owned_since'], $data['os'], $dedi_cpu, $dedi, $offer, $data['bandwidth'], $data['virt'], $data['cpu_amount'], $data['cpu_speed'], $data['ram'], $data['ram_type'], $data['swap'], $data['swap_type'], $data['disk'], $data['disk_type'], $ram_mb, $swap_mb, $disk_gb, $data['ns1'], $data['ns2'], $data['ssh_port'], $label, $asn]);
|
||||||
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
|
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
|
||||||
return $item_id;
|
return $item_id;
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ CREATE TABLE IF NOT EXISTS `servers`
|
|||||||
(
|
(
|
||||||
`id` char(8) NOT NULL,
|
`id` char(8) NOT NULL,
|
||||||
`hostname` varchar(124) DEFAULT NULL,
|
`hostname` varchar(124) DEFAULT NULL,
|
||||||
`label` varchar(24) DEFAULT NULL,
|
`label` varchar(24) DEFAULT NULL,
|
||||||
`location` int(11) DEFAULT NULL,
|
`location` int(11) DEFAULT NULL,
|
||||||
`provider` int(11) DEFAULT NULL,
|
`provider` int(11) DEFAULT NULL,
|
||||||
`ipv4` varchar(124) DEFAULT NULL,
|
`ipv4` varchar(124) DEFAULT NULL,
|
||||||
@ -328,6 +328,7 @@ CREATE TABLE IF NOT EXISTS `servers`
|
|||||||
`owned_since` date DEFAULT NULL,
|
`owned_since` date DEFAULT NULL,
|
||||||
`tags` varchar(255) DEFAULT NULL,
|
`tags` varchar(255) DEFAULT NULL,
|
||||||
`notes` varchar(255) DEFAULT NULL,
|
`notes` varchar(255) DEFAULT NULL,
|
||||||
|
`asn` varchar(124) DEFAULT NULL,
|
||||||
`has_yabs` tinyint(1) DEFAULT 0,
|
`has_yabs` tinyint(1) DEFAULT 0,
|
||||||
`has_st` tinyint(1) DEFAULT 0,
|
`has_st` tinyint(1) DEFAULT 0,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE `servers`
|
|
||||||
ADD COLUMN `label` VARCHAR(24) NULL DEFAULT NULL AFTER `hostname`;
|
|
2
update1.3to1.4.sql
Normal file
2
update1.3to1.4.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `servers`
|
||||||
|
ADD COLUMN `asn` VARCHAR(124) NULL DEFAULT NULL AFTER `notes`;
|
Loading…
Reference in New Issue
Block a user