1
0
mirror of https://github.com/cp6/my-idlers.git synced 2024-11-16 15:33:44 +01:00

Merge pull request #17 from cp6/dev

ASN add
This commit is contained in:
corbpie 2021-02-07 01:09:29 +11:00 committed by GitHub
commit 7eb2409d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 12 deletions

View File

@ -37,7 +37,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$idle->viewMoreDomainModal($_GET['id']);//View more details modal
}
} elseif ($_GET['type'] == 'dns_search') {
$idle->getIpForDomain($_GET['hostname'], $_GET['dns_type']);
header('Content-Type: text/html; charset=utf-8');
echo $idle->getIpForDomain($_GET['hostname'], $_GET['dns_type']);
} elseif ($_GET['type'] == 'check_up') {
echo $idle->checkIsUp($_GET['host']);
} elseif ($_GET['type'] == 'object_cards') {

View File

@ -21,6 +21,8 @@ class idlersConfig
const DEFAULT_VIEW = 'CARDS';//CARDS or TABLE
const SAVE_YABS_OUTPUT = true;//true or false
const GET_ASN_INFO = true;//Get ANS name and number
}
class elementHelpers extends idlersConfig
@ -743,7 +745,7 @@ class idlers extends helperFunctions
if ($row['has_yabs'] == 1 && $row['has_st'] == 1) {
$select = $this->dbConnect()->prepare("
SELECT servers.id as server_id,hostname,ipv4,ipv6,`cpu`,cpu_type,cpu_freq,ram,ram_type,ram_mb,swap,swap_type,swap_mb,`disk`,disk_type,disk_gb,bandwidth,bandwidth_type,gb5_single,gb5_multi,gb5_id,aes_ni,amd_v,
is_dedicated,is_cpu_dedicated,was_special,os,ssh_port,still_have,tags,notes,label,virt,has_yabs,has_st,ns1,ns2,DATE_FORMAT(`owned_since`, '%M %Y') as owned_since, `owned_since` as owned_since_raw, `4k`,`4k_type`,`4k_as_mbps`,`64k`,`64k_type`,
is_dedicated,is_cpu_dedicated,was_special,os,ssh_port,still_have,tags,notes,label,asn,virt,has_yabs,has_st,ns1,ns2,DATE_FORMAT(`owned_since`, '%M %Y') as owned_since, `owned_since` as owned_since_raw, `4k`,`4k_type`,`4k_as_mbps`,`64k`,`64k_type`,
`64k_as_mbps`,`512k`,`512k_type`,`512k_as_mbps`,`1m`,`1m_type`,`1m_as_mbps`,
loc.name as location,send,send_type,recieve,recieve_type,price,currency,term,as_usd,per_month,usd_per_month,next_dd,pr.name as provider
FROM servers INNER JOIN disk_speed ds on servers.id = ds.server_id
@ -759,7 +761,7 @@ class idlers extends helperFunctions
} elseif ($row['has_yabs'] == 1 && $row['has_st'] == 0) {
$select = $this->dbConnect()->prepare("
SELECT servers.id as server_id,hostname,ipv4,ipv6,`cpu`,cpu_type,cpu_freq,ram,ram_type,ram_mb,swap,swap_type,swap_mb,`disk`,disk_type,disk_gb,bandwidth,bandwidth_type,gb5_single,gb5_multi,gb5_id,aes_ni,amd_v,
is_dedicated,is_cpu_dedicated,was_special,os,ssh_port,still_have,tags,notes,label,virt,has_yabs,has_st,ns1,ns2,DATE_FORMAT(`owned_since`, '%M %Y') as owned_since, `owned_since` as owned_since_raw, `4k`,`4k_type`,`64k`,`64k_type`,`512k`,`512k_type`,`1m`,`1m_type`,
is_dedicated,is_cpu_dedicated,was_special,os,ssh_port,still_have,tags,notes,label,asn,virt,has_yabs,has_st,ns1,ns2,DATE_FORMAT(`owned_since`, '%M %Y') as owned_since, `owned_since` as owned_since_raw, `4k`,`4k_type`,`64k`,`64k_type`,`512k`,`512k_type`,`1m`,`1m_type`,
loc.name as location,price,currency,term,as_usd,per_month,usd_per_month,next_dd,pr.name as provider
FROM servers INNER JOIN disk_speed ds on servers.id = ds.server_id
INNER JOIN locations loc on servers.location = loc.id
@ -770,7 +772,7 @@ class idlers extends helperFunctions
} else {
$select = $this->dbConnect()->prepare("
SELECT servers.id as server_id,hostname,ipv4,ipv6,`cpu`,cpu_type,cpu_freq,ram,ram_type,ram_mb,swap,swap_type,swap_mb,`disk`,disk_type,disk_gb,
bandwidth,bandwidth_type,gb5_single,gb5_multi,gb5_id,aes_ni,amd_v,is_dedicated,is_cpu_dedicated,was_special,os,ssh_port,still_have,tags,notes,virt,has_yabs,ns1,ns2,label,has_st,
bandwidth,bandwidth_type,gb5_single,gb5_multi,gb5_id,aes_ni,amd_v,is_dedicated,is_cpu_dedicated,was_special,os,ssh_port,still_have,tags,notes,virt,has_yabs,ns1,ns2,label,asn,has_st,
DATE_FORMAT(`owned_since`, '%M %Y') as owned_since,loc.name as location,price,currency,term,as_usd,per_month,usd_per_month,next_dd,pr.name as provider
FROM servers INNER JOIN locations loc on servers.location = loc.id
INNER JOIN providers pr on servers.provider = pr.id INNER JOIN pricing on servers.id = pricing.server_id WHERE servers.id = ? LIMIT 1;");
@ -2287,6 +2289,14 @@ class idlers extends helperFunctions
$this->rowColOpen('row m-row', 'col-12 col-md-6 mm-col');
$this->HTMLphrase('p', 'm-desc', 'Disk ');
$this->HTMLphrase('p', 'm-value', '' . $data['disk'] . '<span class="data-type">' . $data['disk_type'] . '</span>');
$this->tagClose('div');
$this->colOpen('col-12 col-md-6');
if (!is_null($data['asn'])) {
$asn_exp = explode(',', $data['asn']);
$asn_link = "<a href='https://stat.ripe.net/" . $asn_exp[1] . "#tabId=at-a-glance'>$asn_exp[1]</a>";
$this->HTMLphrase('p', 'm-desc', 'ASN ');
$this->HTMLphrase('p', 'm-value', $asn_exp[0] . ' ' . $asn_link);
}
$this->tagClose('div', 2);
$this->rowColOpen('row m-section-row', 'col-12 col-md-6');
@ -3127,6 +3137,25 @@ class idlers extends helperFunctions
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()
{
$this->rowColOpen('row text-center', 'col-12');
@ -3391,7 +3420,6 @@ class idlers extends helperFunctions
$this->outputString('</tbody></table></div>');
}
}
class itemInsert extends idlers
@ -3415,10 +3443,24 @@ class itemInsert extends idlers
(empty($data['ipv4'])) ? $ipv4 = null : $ipv4 = $data['ipv4'];
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
(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']);
$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->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 = $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, $asn]);
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
return $item_id;
}
@ -3433,13 +3475,27 @@ class itemInsert extends idlers
(empty($data['ipv4'])) ? $ipv4 = null : $ipv4 = $data['ipv4'];
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
(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['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'];
$location_id = $this->handleLocation($data['location']);
$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->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 = $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, $asn]);
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
return $item_id;
}

View File

@ -328,6 +328,7 @@ CREATE TABLE IF NOT EXISTS `servers`
`owned_since` date DEFAULT NULL,
`tags` varchar(255) DEFAULT NULL,
`notes` varchar(255) DEFAULT NULL,
`asn` varchar(124) DEFAULT NULL,
`has_yabs` tinyint(1) DEFAULT 0,
`has_st` tinyint(1) DEFAULT 0,
PRIMARY KEY (`id`),

View File

@ -1,2 +0,0 @@
ALTER TABLE `servers`
ADD COLUMN `label` VARCHAR(24) NULL DEFAULT NULL AFTER `hostname`;

2
update1.3to1.4.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE `servers`
ADD COLUMN `asn` VARCHAR(124) NULL DEFAULT NULL AFTER `notes`;