diff --git a/calls.php b/calls.php index 3ccaa9c..0b71e8d 100644 --- a/calls.php +++ b/calls.php @@ -62,6 +62,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } elseif ($_POST['type'] == 'server_modal_edit') {//Update the server info $update->updateServerFromModal(); $update->updateServerPricingFromModal(); + if (!is_null($_POST['me_yabs']) && !empty($_POST['me_yabs'])){ + $update->updateYabsData(); + } } elseif ($_POST['type'] == 'shared_hosting_modal_edit') {//Update the shared hosting info $update->updateSharedHostingFromModal(); $update->updateSharedHostingPricingFromModal(); diff --git a/class.php b/class.php index 04a8077..db5d040 100644 --- a/class.php +++ b/class.php @@ -1134,6 +1134,12 @@ class idlers extends helperFunctions $this->outputString(""); $this->tagClose('div', 2); + $this->rowColOpen('form-row', 'col-12'); + $this->htmlPhrase('p', 'm-desc', 'Update YABs disk & network speeds:'); + $this->outputString(""); + $this->tagClose('div', 2); + $this->rowColOpen('form-row', 'col-12'); $this->tagOpen('div', 'input-group'); $this->inputPrepend('Tags'); @@ -3058,4 +3064,67 @@ class itemUpdate extends idlers 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; + } + } + } \ No newline at end of file diff --git a/my_idlers.sql b/my_idlers.sql index 3ff830d..d95249c 100644 --- a/my_idlers.sql +++ b/my_idlers.sql @@ -13,21 +13,21 @@ USE `idlers`; -- Dumping structure for table my_idlers.disk_speed CREATE TABLE IF NOT EXISTS `disk_speed` ( - `server_id` char(8) NOT NULL, - `4k` float DEFAULT NULL, - `4k_type` char(4) DEFAULT NULL, - `4k_as_mbps` float DEFAULT NULL, - `64k` float DEFAULT NULL, - `64k_type` char(4) DEFAULT NULL, - `64k_as_mbps` float DEFAULT NULL, - `512k` float DEFAULT NULL, - `512k_type` char(4) DEFAULT NULL, - `512k_as_mbps` float DEFAULT NULL, - `1m` float DEFAULT NULL, - `1m_type` char(4) DEFAULT NULL, - `1m_as_mbps` float DEFAULT NULL, - `datetime` datetime DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`server_id`) + `server_id` char(8) NOT NULL, + `4k` float DEFAULT NULL, + `4k_type` char(4) DEFAULT NULL, + `4k_as_mbps` float DEFAULT NULL, + `64k` float DEFAULT NULL, + `64k_type` char(4) DEFAULT NULL, + `64k_as_mbps` float DEFAULT NULL, + `512k` float DEFAULT NULL, + `512k_type` char(4) DEFAULT NULL, + `512k_as_mbps` float DEFAULT NULL, + `1m` float DEFAULT NULL, + `1m_type` char(4) DEFAULT NULL, + `1m_as_mbps` float DEFAULT NULL, + `datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE KEY `Index 1` (`server_id`, `datetime`) ) ENGINE = InnoDB DEFAULT CHARSET = latin1; diff --git a/update.sql b/update.sql index 2f06d34..df9097f 100644 --- a/update.sql +++ b/update.sql @@ -5,4 +5,10 @@ ALTER TABLE `servers` ADD COLUMN `ssh_port` INT(11) NULL DEFAULT '22' AFTER `os`; ALTER TABLE `servers` - ADD COLUMN `notes` VARCHAR(255) NULL DEFAULT NULL AFTER `tags`; \ No newline at end of file + ADD COLUMN `notes` VARCHAR(255) NULL DEFAULT NULL AFTER `tags`; + +ALTER TABLE `disk_speed` + DROP PRIMARY KEY; + +ALTER TABLE `disk_speed` + ADD UNIQUE INDEX `Index 1` (`server_id`, `datetime`); \ No newline at end of file