');
$this->outputString('
');
$this->tagOpen('div', 'modal-content');
$this->tagOpen('div', 'modal-header');
$this->outputString('');
$this->outputString('
');
}
public function infoCard()
{
$select = $this->dbConnect()->prepare("SELECT COUNT(*), SUM(`cpu`), SUM(`disk_gb`), SUM(`ram_mb`), SUM(`swap_mb`), SUM(`bandwidth`), SUM(`was_special`), SUM(`gb5_single`), SUM(`gb5_multi`) FROM `servers`;");
$select->execute();
$row = $select->fetchAll(PDO::FETCH_ASSOC)[0];
$inactive_servers = $this->dbConnect()->prepare("SELECT COUNT(*) as inactive FROM `servers` WHERE `still_have` = 0;");
$inactive_servers->execute();
$inactive_servers_count = $inactive_servers->fetch()['inactive'];
$kvm = $this->dbConnect()->prepare("SELECT COUNT(*) as kvm_count FROM `servers` WHERE `virt` = 'KVM';");
$kvm->execute();
$kvm_count = $kvm->fetch()['kvm_count'];
$ovz = $this->dbConnect()->prepare("SELECT COUNT(*) as ovz_count FROM `servers` WHERE `virt` = 'OVZ';");
$ovz->execute();
$ovz_count = $ovz->fetch()['ovz_count'];
$dedi = $this->dbConnect()->prepare("SELECT COUNT(*) as dedi_count FROM `servers` WHERE `virt` = 'DEDI';");
$dedi->execute();
$dedi_count = $dedi->fetch()['dedi_count'];
$lxc = $this->dbConnect()->prepare("SELECT COUNT(*) as lxc_count FROM `servers` WHERE `virt` = 'LXC';");
$lxc->execute();
$lxc_count = $lxc->fetch()['lxc_count'];
$domains = $this->dbConnect()->prepare("SELECT COUNT(*) as domains_count FROM `domains` WHERE `still_have` = 1;");
$domains->execute();
$domains_count = $domains->fetch()['domains_count'];
$domains_inactive = $this->dbConnect()->prepare("SELECT COUNT(*) as domains_count FROM `domains` WHERE `still_have` = 0;");
$domains_inactive->execute();
$domains_inactive_count = $domains_inactive->fetch()['domains_count'];
$sh = $this->dbConnect()->prepare("SELECT COUNT(*) as sh_count FROM `shared_hosting` WHERE `still_have` = 1;");
$sh->execute();
$sh_count = $sh->fetch()['sh_count'];
$sh_inactive = $this->dbConnect()->prepare("SELECT COUNT(*) as sh_count FROM `shared_hosting` WHERE `still_have` = 0;");
$sh_inactive->execute();
$sh_inactive_count = $sh_inactive->fetch()['sh_count'];
$cpu_freq = $this->dbConnect()->prepare("SELECT `cpu_freq` FROM `servers` ORDER BY `cpu_freq` DESC LIMIT 1;");
$cpu_freq->execute();
$fastest_cpu_freq = $cpu_freq->fetch()['cpu_freq'];
$single_high = $this->dbConnect()->prepare("SELECT `gb5_single` FROM `servers` ORDER BY `gb5_single` DESC LIMIT 1;");
$single_high->execute();
$highest_single_gb5 = $single_high->fetch()['gb5_single'];
$multi_high = $this->dbConnect()->prepare("SELECT `gb5_multi` FROM `servers` ORDER BY `gb5_multi` DESC LIMIT 1;");
$multi_high->execute();
$highest_multi_gb5 = $multi_high->fetch()['gb5_multi'];
$oldest = $this->dbConnect()->prepare("SELECT `hostname`, `owned_since` FROM `servers` ORDER BY `owned_since`;");
$oldest->execute();
$oldest_row = $oldest->fetchAll(PDO::FETCH_ASSOC)[0];
$oldest_d = $this->dbConnect()->prepare("SELECT `domain`, `owned_since` FROM `domains` ORDER BY `owned_since`;");
$oldest_d->execute();
if (isset($oldest_d->fetchAll(PDO::FETCH_ASSOC)[0])) {
$oldest_d_row = $oldest_d->fetchAll(PDO::FETCH_ASSOC)[0];
} else {
$oldest_d_row = array('domain' => null, 'owned_since' => null);
}
$sel_price = $this->dbConnect()->prepare("SELECT `as_usd`, `term`, `usd_per_month` FROM `pricing`;");
$sel_price->execute();
$tally = 0;
$pm_tally = 0;
while ($row1 = $sel_price->fetch(PDO::FETCH_ASSOC)) {
$cost = $row1['as_usd'];
$term = $row1['term'];
$pm = $row1['usd_per_month'];
$pm_tally = ($pm_tally + $pm);
if ($term == 1) {
$tally = $tally + ($cost * 12);
} elseif ($term == 2) {
$tally = $tally + ($cost * 4);
} elseif ($term == 3) {
$tally = $tally + ($cost * 2);
} elseif ($term == 4) {
$tally = $tally + $cost;
} elseif ($term == 4) {
$tally = $tally + ($cost / 2);
} elseif ($term == 4) {
$tally = $tally + ($cost / 3);
}
}
$this->outputString("
");
$this->tagOpen('div', 'card-header text-center');
$this->HTMLphrase('h2', '', 'My idlers info');
$this->tagClose('div');
$this->tagOpen('div', 'card-body');
$this->rowColOpen('row info-row', 'col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total servers:
' . $row['COUNT(*)'] . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total shared hosting:
' . $sh_count . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total domains:
' . $domains_count . '');
$this->tagClose('div', 2);
$this->rowColOpen('row info-row', 'col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'KVM/OVZ/DEDI/LXC:
' . $kvm_count . '/' . $ovz_count . '/' . $dedi_count . '/' . $lxc_count . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'No longer have servers:
' . $inactive_servers_count . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'No longer have domains/shared:
' . $domains_inactive_count . '/' . $sh_inactive_count . '');
$this->tagClose('div', 2);
$this->rowColOpen('row info-row', 'col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total CPU:
' . $row['SUM(`cpu`)'] . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Fastest CPU:
' . $fastest_cpu_freq . 'Mhz');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total disk:
' . number_format($row['SUM(`disk_gb`)'], 0) . 'GB');
$this->tagClose('div', 2);
$this->rowColOpen('row info-row', 'col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total bandwidth:
' . number_format($row['SUM(`bandwidth`)'], 0) . 'TB');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total ram:
' . number_format($row['SUM(`ram_mb`)'], 2) . 'MB');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total swap:
' . number_format($row['SUM(`swap_mb`)'], 2) . 'MB');
$this->tagClose('div', 2);
$this->rowColOpen('row info-row', 'col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total gb5_single:
' . number_format($row['SUM(`gb5_single`)'], 0) . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total gb5_multi:
' . number_format($row['SUM(`gb5_multi`)'], 0) . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Highest single/multi:
' . $highest_single_gb5 . '/' . $highest_multi_gb5 . '');
$this->tagClose('div', 2);
$this->rowColOpen('row info-row', 'col-12 col-md-4');;
$this->HTMLphrase('p', 'info-desc', 'Special priced:
' . $row['SUM(`was_special`)'] . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Oldest server:
' . $oldest_row['hostname'] . ' ' . $oldest_row['owned_since'] . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Oldest domain:
' . $oldest_d_row['domain'] . ' ' . $oldest_d_row['owned_since'] . '');
$this->tagClose('div', 2);
$this->rowColOpen('row info-row', 'col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total cost p/m USD:
$' . $pm_tally . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->HTMLphrase('p', 'info-desc', 'Total cost per year USD:
$' . $tally . '');
$this->tagClose('div');
$this->colOpen('col-12 col-md-4');
$this->tagClose('div', 4);
}
protected function hasPassedDate(string $the_date)
{
if (new DateTime() > new DateTime($the_date)) {
//current date time has passed $the_date
return true;
} else {
//current date time has NOT passed $the_date
return false;
}
}
protected function nextDueDate(int $term, string $last_dd)
{
$date = new DateTime($last_dd);
if ($term == 1) {
$date->add(new DateInterval('P1M'));
} elseif ($term == 2) {
$date->add(new DateInterval('P3M'));
} elseif ($term == 3) {
$date->add(new DateInterval('P6M'));
} elseif ($term == 4) {
$date->add(new DateInterval('P1Y'));
} elseif ($term == 5) {
$date->add(new DateInterval('P2Y'));
} elseif ($term == 6) {
$date->add(new DateInterval('P3Y'));
}
return $date->format('Y-m-d');
}
protected function processDueDate(string $item_id, int $term, $last_dd)
{//Will return days until due. Will update if passed due date and then return days until due
if (is_null($last_dd)) {
return "-";//Due date not set
} else {
if ($this->hasPassedDate($last_dd)) {
$update = $this->dbConnect()->prepare("UPDATE `pricing` SET `next_dd` = ? WHERE `server_id` = ? LIMIT 1;");
$new_dd = $this->nextDueDate($term, $last_dd);
$update->execute([$new_dd, $item_id]);
return $this->daysAway($new_dd);
} else {
return $this->daysAway($last_dd);
}
}
}
public function showYabsModal(string $item_id)
{
$this->tagOpen('form');
$this->outputString('
');
}
}
class itemInsert extends idlers
{
public string $item_id;
public array $data;
public function __construct(array $data)
{
$this->item_id = $this->genId();
$this->data = $data;
}
public function insertBasicWithYabs()
{//Insert data from form EXCEPT the YABs output
$data = $this->data;
$item_id = $this->item_id;
(isset($data['dedi_cpu'])) ? $dedi_cpu = 1 : $dedi_cpu = 0;
($data['virt'] == 'DEDI') ? $dedi = 1 : $dedi = 0;
(isset($data['was_offer'])) ? $offer = 1 : $offer = 0;
(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, 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;
}
public function insertBasic()
{//Manual form insert (NO YABs)
$data = $this->data;
$item_id = $this->item_id;
(isset($data['dedi_cpu'])) ? $dedi_cpu = 1 : $dedi_cpu = 0;
($data['virt'] == 'DEDI') ? $dedi = 1 : $dedi = 0;
(isset($data['was_offer'])) ? $offer = 1 : $offer = 0;
(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, 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;
}
public function insertSharedHosting()
{//domains form insert
$data = $this->data;
$item_id = $this->item_id;
($data['shared_storage_type'] == 'TB') ? $disk_gb = $this->TBtoGB($data['shared_storage']) : $disk_gb = $data['shared_storage'];
(isset($data['shared_was_offer'])) ? $offer = 1 : $offer = 0;
$location_id = $this->handleLocation($data['shared_location']);
$provider_id = $this->handleProvider($data['shared_provider']);
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `shared_hosting` (id, domain, domains_limit, emails, disk, disk_type, disk_as_gb, ftp, db, bandwidth, provider, location, was_special, still_have, type, owned_since) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
$insert->execute([$item_id, $data['shared_domain'], $data['shared_domains_amount'], $data['shared_emails'], $data['shared_storage'], $data['shared_storage_type'], $disk_gb, $data['shared_ftp'], $data['shared_db_amount'], $data['shared_bandwidth'], $provider_id, $location_id, $offer, '1', $data['shared_type'], $data['shared_owned_since']]);
$this->insertPrice($data['shared_price'], $data['shared_currency'], $data['shared_term'], $data['shared_next_due_date']);
return $item_id;
}
public function insertDomain()
{//domains form insert
$data = $this->data;
$domain_id = $this->item_id;
$provider_id = $this->handleProvider($data['domain_provider']);
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `domains` (id, domain, provider, owned_since) VALUES (?,?,?,?)');
$insert->execute([$domain_id, $data['domain'], $provider_id, $data['domain_owned_since']]);
$this->insertPrice($data['domain_price'], $data['domain_currency'], $data['domain_term'], $data['domain_next_due_date']);
return $domain_id;
}
public function insertYabsData()
{//YABS data handler
$file_name = 'yabsFromForm.txt';
$logfile = fopen($file_name, "w") or die("Unable to open file!");
fwrite($logfile, $this->data['yabs']);
fclose($logfile);
$file = @fopen($file_name, 'r');
if ($file) {
$array = explode("\n", fread($file, filesize($file_name)));
//echo json_encode($array);
//exit;
}
if (count($array) < 50) {
return 9;//Less than 50 lines
}
if (strpos($array[0], '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #') !== false) {
if ($array[1] == "\r") {
return 8;//Didnt copy output correctly
}
$version_array = explode(' ', preg_replace('!\s+!', ' ', $this->trimRemoveR($array[2])));
$version = $version_array[1];//YABs version
if ($version == 'v2020-12-29') {
$cpu = $this->trimRemoveR(str_replace(':', '', strstr($array[10], ': ')));
$cpu_spec = explode(' ', strstr($array[11], ': '));//: 2 @ 3792.872 MHz
$cpu_cores = $cpu_spec[1];
$cpu_freq = $cpu_spec[3];
$ram_line = $this->trimRemoveR(str_replace(':', '', strstr($array[14], ': ')));
$ram = floatval($ram_line);
$ram_type = $this->datatype($ram_line);
$swap_line = $this->trimRemoveR(str_replace(':', '', strstr($array[15], ': ')));
$swap = floatval($swap_line);
$swap_type = $this->datatype($swap_line);
$disk_line = $this->trimRemoveR(str_replace(':', '', strstr($array[16], ': ')));
$disk = floatval($disk_line);
$disk_type = $this->datatype($disk_line);
$io_3 = explode(' ', preg_replace('!\s+!', ' ', $array[24]));
$io_6 = explode(' ', preg_replace('!\s+!', ' ', $array[30]));
(strpos($array[12], 'Enabled') !== false) ? $aes_ni = 1 : $aes_ni = 0;
(strpos($array[13], 'Enabled') !== false) ? $vm_amd_v = 1 : $vm_amd_v = 0;
$d4k_as_mbps = $this->diskSpeedAsMbps($io_3[3], $this->floatValue($io_3[2]));
$d64k_as_mbps = $this->diskSpeedAsMbps($io_3[7], $this->floatValue($io_3[6]));
$d512k_as_mbps = $this->diskSpeedAsMbps($io_6[3], $this->floatValue($io_6[2]));
$d1m_as_mbps = $this->diskSpeedAsMbps($io_6[7], $this->floatValue($io_6[6]));
$disk_test_arr = array($this->item_id, $this->floatValue($io_3[2]), $io_3[3], $this->floatValue($io_3[6]), $io_3[7], $this->floatValue($io_6[2]), $io_6[3], $this->floatValue($io_6[6]), $io_6[7], $d4k_as_mbps, $d64k_as_mbps, $d512k_as_mbps, $d1m_as_mbps);
$this->insertDiskTest($disk_test_arr);
if (isset($array[40])) {
if ($array[45] == "Geekbench 5 Benchmark Test:\r") {
//No ipv6
//Has short ipv4 network speed testing (-r)
$start_st = 36;
$end_st = 43;
$gb_s = 49;
$gb_m = 50;
$gb_url = 51;
} elseif ($array[45] == "Geekbench 4 Benchmark Test:\r") {
return 6;//GeekBench 5 only allowed
} elseif ($array[45] == "Geekbench 5 test failed. Run manually to determine cause.") {
return 7;//GeekBench test failed
} elseif ($array[40] == "Geekbench 5 Benchmark Test:\r") {
//No ipv6
//Has full ipv4 network speed testing
$start_st = 36;
$end_st = 38;
$gb_s = 44;
$gb_m = 45;
$gb_url = 46;
} elseif ($array[40] == "iperf3 Network Speed Tests (IPv6):\r") {
//HAS ipv6
//Has short ipv4 & ipv6 network speed testing
$start_st = 36;
$end_st = 38;
$gb_s = 52;
$gb_m = 53;
$gb_url = 54;
} elseif ($array[55] == "Geekbench 5 Benchmark Test:\r") {
//HAS ipv6
//Has full ipv4 & ipv6 network speed testing
$start_st = 36;
$end_st = 43;
$gb_s = 59;
$gb_m = 60;
$gb_url = 61;
} else {
return 5;//Not correct YABs command output
}
} else {
return 4;//Not correct format
}
$geekbench_single = $this->intValue($array[$gb_s]);
$geekbench_multi = $this->intValue($array[$gb_m]);
$geek_full_url = explode(' ', preg_replace('!\s+!', ' ', $array[$gb_url]));
$gb5_id = substr($geek_full_url[3], strrpos($geek_full_url[3], '/') + 1);//
$has_a_speed_test = false;
for ($i = $start_st; $i <= $end_st; $i++) {
if (strpos($array[$i], 'busy') !== false) {
//Has a "busy" result, No insert
} else {
$data = explode(' ', preg_replace('!\s+!', ' ', $array[$i]));
$send_as_mbps = $this->networkSpeedAsMbps($this->yabsSpeedValues($data)['send_type'], $this->yabsSpeedValues($data)['send']);
$recieve_as_mbps = $this->networkSpeedAsMbps($this->yabsSpeedValues($data)['receive_type'], $this->yabsSpeedValues($data)['receive']);
$insert = $this->dbConnect()->prepare('INSERT INTO `speed_tests` (`server_id`, `location`, `send`, `send_type`,`send_as_mbps`, `recieve`,`recieve_type`, `recieve_as_mbps`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
$insert->execute([$this->item_id, $this->yabsSpeedLoc($data)['location'], $this->yabsSpeedValues($data)['send'], $this->yabsSpeedValues($data)['send_type'], $send_as_mbps, $this->yabsSpeedValues($data)['receive'], $this->yabsSpeedValues($data)['receive_type'], $recieve_as_mbps]);
$has_a_speed_test = true;
}
}
if ($has_a_speed_test) {
$update_st = $this->dbConnect()->prepare('UPDATE `servers` SET `has_st` = 1 WHERE `id` = ? LIMIT 1;');
$update_st->execute([$this->item_id]);
}
($ram_type == 'GB') ? $ram_mb = $this->GBtoMB($ram) : $ram_mb = $ram;
($swap_type == 'GB') ? $swap_mb = $this->GBtoMB($swap) : $swap_mb = $swap;
($disk_type == 'TB') ? $disk_gb = $this->TBtoGB($disk) : $disk_gb = $disk;
$update = $this->dbConnect()->prepare('UPDATE `servers` SET `cpu` = ?, `cpu_freq` = ?, `cpu_type` = ?, ram = ?, ram_type = ?, swap = ?, swap_type = ?, disk = ?, disk_type = ?, `aes_ni` = ?, `amd_v` = ?, gb5_single = ?, gb5_multi = ?, gb5_id = ?, ram_mb = ?, swap_mb = ?, disk_gb = ? WHERE `id` = ? LIMIT 1;');
$update->execute([$cpu_cores, $cpu_freq, $cpu, $ram, $ram_type, $swap, $swap_type, $disk, $disk_type, $aes_ni, $vm_amd_v, $geekbench_single, $geekbench_multi, $gb5_id, $ram_mb, $swap_mb, $disk_gb, $this->item_id]);
if (self::SAVE_YABS_OUTPUT) {
$this->saveYABS($this->data['yabs'], "{$this->item_id}.txt");
}
return 1;
} else {
return 2;//Wrong version
}
} else {
return 3;//Didnt start at right spot
}
}
protected function insertDiskTest(array $results)
{//Insert disk io results from the built array
$insert = $this->dbConnect()->prepare("INSERT IGNORE INTO `disk_speed` (`server_id`, `4k`, `4k_type`, `64k`, `64k_type`, `512k`, `512k_type`, `1m`, `1m_type`, `4k_as_mbps`, `64k_as_mbps`, `512k_as_mbps`, `1m_as_mbps`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);");
return $insert->execute([$this->item_id, $results[1], $results[2], $results[3], $results[4], $results[5], $results[6], $results[7], $results[8], $results[9], $results[10], $results[11], $results[12]]);
}
protected function insertPrice(string $price, string $currency, int $term, string $next_dd)
{//Insert price data
$as_usd = $this->convertToUSD($price, $currency);
$insert = $this->dbConnect()->prepare("INSERT IGNORE INTO `pricing` (server_id, price, currency, term, as_usd, per_month, usd_per_month, next_dd) VALUES (?,?,?,?,?,?,?,?);");
return $insert->execute([$this->item_id, $price, $currency, $term, $as_usd, $this->costAsPerMonth($price, $term), $this->costAsPerMonth($as_usd, $term), $next_dd]);
}
}
class itemUpdate extends idlers
{
public string $item_id;
public string $type;
public array $data;
public function __construct(array $data)
{
$this->data = $data;
if (isset($data['sh_me_server_id'])) {
$this->item_id = $data['sh_me_server_id'];
$this->type = 'SHARED';
} elseif (isset($data['d_me_server_id'])) {
$this->item_id = $data['d_me_server_id'];
$this->type = 'DOMAIN';
} else {
$this->item_id = $data['me_server_id'];
$this->type = 'SERVER';
}
}
public function updateServerFromModal()
{
$data = $this->data;
if (!isset($data['me_non_active'])) {
$this->updateActiveStatus(1);
} elseif ($data['me_non_active'] == 'on') {
$this->updateActiveStatus(0);
}
$update = $this->dbConnect()->prepare("UPDATE `servers` SET `hostname` = ?,`ipv4` = ?,`ipv6` = ?,`cpu` = ?,`bandwidth` = ?,`disk` = ?,`ram` = ?,`ram_type` = ?,`swap` = ?,`swap_type` = ?, `virt` = ?, `tags` = ?, `owned_since` = ?, `ns1` = ?, `ns2` = ?, `ssh_port` = ?, `notes` = ?, `label` = ? WHERE `id`= ? LIMIT 1;");
return $update->execute([$data['me_hostname'], $data['me_ipv4'], $data['me_ipv6'], $data['me_cpu_amount'], $data['me_bandwidth'], $data['me_disk'], $data['me_ram'], $data['me_ram_type'], $data['me_swap'], $data['me_swap_type'], $data['me_virt'], $data['me_tags'], $data['me_owned_since'], $data['me_ns1'], $data['me_ns2'], $data['me_ssh_port'], $data['me_notes'], $data['me_label'], $this->item_id]);
}
public function updateServerPricingFromModal()
{
$data = $this->data;
$as_usd = $this->convertToUSD($data['me_price'], $data['me_currency']);
$update = $this->dbConnect()->prepare("UPDATE `pricing` SET `price` = ?,`currency` = ?,`term` = ?,`as_usd` = ?,`per_month` = ?, `usd_per_month` = ?, `next_dd` = ? WHERE `server_id`= ? LIMIT 1;");
return $update->execute([$data['me_price'], $data['me_currency'], $data['me_term'], $as_usd, $this->costAsPerMonth($data['me_price'], $data['me_term']), $this->costAsPerMonth($as_usd, $data['me_term']), $data['me_next_dd'], $this->item_id]);
}
public function updateSharedHostingFromModal()
{
$data = $this->data;
if (!isset($data['sh_me_non_active'])) {
$this->updateActiveStatus(1);
} elseif ($data['sh_me_non_active'] == 'on') {
$this->updateActiveStatus(0);
}
$update = $this->dbConnect()->prepare("UPDATE `shared_hosting` SET `domain` = ?,`domains_limit` = ?,`emails` = ?,`disk` = ?,`disk_as_gb` = ?,`disk_type` = ?,`ftp` = ?,`db` = ?,`bandwidth` = ?,`owned_since` = ? WHERE `id`= ? LIMIT 1;");
return $update->execute([$data['sh_me_hostname'], $data['sh_me_domains_count'], $data['sh_me_emails'], $data['sh_me_storage'], $data['sh_me_storage'], 'GB', $data['sh_me_ftp'], $data['sh_me_db'], $data['sh_me_bandwidth'], $data['sh_me_owned_since'], $this->item_id]);
}
public function updateSharedHostingPricingFromModal()
{
$data = $this->data;
$as_usd = $this->convertToUSD($data['sh_me_price'], $data['sh_me_currency']);
$update = $this->dbConnect()->prepare("UPDATE `pricing` SET `price` = ?,`currency` = ?,`term` = ?,`as_usd` = ?,`per_month` = ?, `usd_per_month` = ?, `next_dd` = ? WHERE `server_id`= ? LIMIT 1;");
return $update->execute([$data['sh_me_price'], $data['sh_me_currency'], $data['sh_me_term'], $as_usd, $this->costAsPerMonth($data['sh_me_price'], $data['sh_me_term']), $this->costAsPerMonth($as_usd, $data['sh_me_term']), $data['sh_me_next_dd'], $this->item_id]);
}
public function updateDomainFromModal()
{
$data = $this->data;
if (!isset($data['d_me_non_active'])) {
$this->updateActiveStatus(1);
} elseif ($data['d_me_non_active'] == 'on') {
$this->updateActiveStatus(0);
}
(!empty($_POST['d_me_attached_to'])) ? $attached_to = $_POST['d_me_attached_to'] : $attached_to = null;
$update = $this->dbConnect()->prepare("UPDATE `domains` SET `domain` = ?,`ns1` = ?,`ns2` = ?,`owned_since` = ?, `attached_to` = ? WHERE `id`= ? LIMIT 1;");
return $update->execute([$data['d_me_hostname'], $data['d_me_ns1'], $data['d_me_ns2'], $data['d_me_owned_since'], $attached_to, $this->item_id]);
}
public function updateDomainPricingFromModal()
{
$data = $this->data;
$as_usd = $this->convertToUSD($data['d_me_price'], $data['d_me_currency']);
$update = $this->dbConnect()->prepare("UPDATE `pricing` SET `price` = ?,`currency` = ?,`term` = ?,`as_usd` = ?,`per_month` = ?, `usd_per_month` = ?, `next_dd` = ? WHERE `server_id`= ? LIMIT 1;");
return $update->execute([$data['d_me_price'], $data['d_me_currency'], $data['d_me_term'], $as_usd, $this->costAsPerMonth($data['d_me_price'], $data['d_me_term']), $this->costAsPerMonth($as_usd, $data['d_me_term']), $data['d_me_next_dd'], $this->item_id]);
}
public function deleteObjectData()
{//Delete server data from all relevant tables
if ($this->type == 'SHARED') {
$table = 'shared_hosting';
} elseif ($this->type == 'DOMAIN') {
$table = 'domains';
} else {
$table = 'servers';
}
$item_id = $this->item_id;
$del_server = $this->dbConnect()->prepare("DELETE FROM `$table` WHERE `id` = ? LIMIT 1;");
$del_server->execute([$item_id]);
$del_pricing = $this->dbConnect()->prepare("DELETE FROM `pricing` WHERE `server_id` = ? LIMIT 1;");
$del_pricing->execute([$item_id]);
if ($this->type == 'SERVER') {
$del_disk = $this->dbConnect()->prepare("DELETE FROM `disk_speed` WHERE `server_id` = ?;");
$del_disk->execute([$item_id]);
$del_speed = $this->dbConnect()->prepare("DELETE FROM `speed_tests` WHERE `server_id` = ?;");
$del_speed->execute([$item_id]);
$this->deleteYabsForId($item_id);//Delete saved YABs
}
}
protected function updateActiveStatus(int $status)
{
if ($this->type == 'SHARED') {
$table = 'shared_hosting';
} elseif ($this->type == 'DOMAIN') {
$table = 'domains';
} else {
$table = 'servers';
}
$update = $this->dbConnect()->prepare("UPDATE `$table` SET `still_have` = ? WHERE `id` = ? LIMIT 1;");
return $update->execute([$status, $this->item_id]);
}
public function updateYabsData(bool $save_yabs = true)
{//YABS data handler
$file_name = 'yabsFromForm.txt';
$logfile = fopen($file_name, "w") or die("Unable to open file!");
fwrite($logfile, $this->data['me_yabs']);
if ($save_yabs) {
$this->saveYABS($this->data['me_yabs'], "{$this->item_id}_" . date('Y-m-d') . ".txt");
}
fclose($logfile);
$file = @fopen($file_name, 'r');
if ($file) {
$array = explode("\n", fread($file, filesize($file_name)));
}
if (strpos($array[0], '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #') !== false || count($array) < 50) {
$io_3 = explode(' ', preg_replace('!\s+!', ' ', $array[24]));
$io_6 = explode(' ', preg_replace('!\s+!', ' ', $array[30]));
(strpos($array[12], 'Enabled') !== false) ? $aes_ni = 1 : $aes_ni = 0;
(strpos($array[13], 'Enabled') !== false) ? $vm_amd_v = 1 : $vm_amd_v = 0;
$d4k_as_mbps = $this->diskSpeedAsMbps($io_3[3], $this->floatValue($io_3[2]));
$d64k_as_mbps = $this->diskSpeedAsMbps($io_3[7], $this->floatValue($io_3[6]));
$d512k_as_mbps = $this->diskSpeedAsMbps($io_6[3], $this->floatValue($io_6[2]));
$d1m_as_mbps = $this->diskSpeedAsMbps($io_6[7], $this->floatValue($io_6[6]));
$disk_test_arr = array($this->item_id, $this->floatValue($io_3[2]), $io_3[3], $this->floatValue($io_3[6]), $io_3[7], $this->floatValue($io_6[2]), $io_6[3], $this->floatValue($io_6[6]), $io_6[7], $d4k_as_mbps, $d64k_as_mbps, $d512k_as_mbps, $d1m_as_mbps);
$insert = $this->dbConnect()->prepare("INSERT IGNORE INTO `disk_speed` (`server_id`, `4k`, `4k_type`, `64k`, `64k_type`, `512k`, `512k_type`, `1m`, `1m_type`, `4k_as_mbps`, `64k_as_mbps`, `512k_as_mbps`, `1m_as_mbps`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);");
$insert->execute([$this->item_id, $disk_test_arr[1], $disk_test_arr[2], $disk_test_arr[3], $disk_test_arr[4], $disk_test_arr[5], $disk_test_arr[6], $disk_test_arr[7], $disk_test_arr[8], $disk_test_arr[9], $disk_test_arr[10], $disk_test_arr[11], $disk_test_arr[12]]);
if ($array[45] == "Geekbench 5 Benchmark Test:\r") {
//No ipv6
//Has short ipv4 network speed testing (-r)
$start_st = 36;
$end_st = 43;
} elseif ($array[40] == "Geekbench 5 Benchmark Test:\r") {
//No ipv6
//Has full ipv4 network speed testing
$start_st = 36;
$end_st = 38;
} elseif ($array[40] == "iperf3 Network Speed Tests (IPv6):\r") {
//HAS ipv6
//Has short ipv4 & ipv6 network speed testing
$start_st = 36;
$end_st = 38;
} elseif ($array[55] == "Geekbench 5 Benchmark Test:\r") {
//HAS ipv6
//Has full ipv4 & ipv6 network speed testing
$start_st = 36;
$end_st = 43;
}
for ($i = $start_st; $i <= $end_st; $i++) {
if (strpos($array[$i], 'busy') !== false) {
//Has a "busy" result, No insert
} else {
$data = explode(' ', preg_replace('!\s+!', ' ', $array[$i]));
$send_as_mbps = $this->networkSpeedAsMbps($this->yabsSpeedValues($data)['send_type'], $this->yabsSpeedValues($data)['send']);
$recieve_as_mbps = $this->networkSpeedAsMbps($this->yabsSpeedValues($data)['receive_type'], $this->yabsSpeedValues($data)['receive']);
$insert = $this->dbConnect()->prepare('INSERT IGNORE INTO `speed_tests` (`server_id`, `location`, `send`, `send_type`,`send_as_mbps`, `recieve`,`recieve_type`, `recieve_as_mbps`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
$insert->execute([$this->item_id, $this->yabsSpeedLoc($data)['location'], $this->yabsSpeedValues($data)['send'], $this->yabsSpeedValues($data)['send_type'], $send_as_mbps, $this->yabsSpeedValues($data)['receive'], $this->yabsSpeedValues($data)['receive_type'], $recieve_as_mbps]);
}
}
return true;
} else {//Not formatted right
return false;
}
}
}
class auth extends idlers
{
public string $token;
private string $user;
private string $ip_address;
public function selfDestruct()
{
$select = $this->dbConnect()->prepare("SELECT `user` FROM `auth`;");
$select->execute();
$user_count = $select->rowCount();
if ($user_count == 0) {
//Begin create user
$this->createAccountForm();
} else {
//User already exists
//Delete AUTH.php
$this->deleteAuthFile();
}
}
protected function createAccountForm()
{
if (isset($_POST['pass']) && isset($_POST['user'])) {
//Form submitted
$this->insertAccount($_POST['user'], $_POST['pass']);
} else {
$this->pageHead();
$this->rowColOpen('row text-center', 'col-12');
$this->tagOpen('div', 'card');
$this->tagOpen('div', 'card-header');
$this->HTMLphrase('h1', '', 'Create account');
$this->HTMLphrase('p', '', 'If you are seeing this there are currently 0 accounts. Once 1 is created this file gets deleted.');
$this->tagClose('div');
$this->tagOpen('div', 'card-body');
$this->outputString('