Added YABs insert error handling & messages
Makes possiblility of corrupt DB data less and wont go through with insert if conditions arent met.
This commit is contained in:
parent
c00e8d7671
commit
9ef12f08b1
30
assets/js/scripts.min.js
vendored
30
assets/js/scripts.min.js
vendored
|
@ -18,6 +18,30 @@ jQuery Tags
|
||||||
CUSTOM SCRIPTS/FUNCS
|
CUSTOM SCRIPTS/FUNCS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function YABSdebug(result){
|
||||||
|
if (result == 1){
|
||||||
|
return 'Success';
|
||||||
|
} else if (result == 2){
|
||||||
|
return 'Wrong version';
|
||||||
|
} else if (result == 3){
|
||||||
|
return 'Didnt start at right spot';
|
||||||
|
} else if (result == 4){
|
||||||
|
return 'Not correct format';
|
||||||
|
} else if (result == 5){
|
||||||
|
return 'Not a correct YABs command output';
|
||||||
|
} else if (result == 6){
|
||||||
|
return 'GeekBench 5 only allowed';
|
||||||
|
} else if (result == 7){
|
||||||
|
return 'GeekBench test failed';
|
||||||
|
} else if (result == 8){
|
||||||
|
return 'Didnt copy output correctly';
|
||||||
|
} else if (result == 9){
|
||||||
|
return 'Less than 50 lines';
|
||||||
|
} else {
|
||||||
|
return 'Unknown '+result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("#yabsForm").submit(function (e) {
|
$("#yabsForm").submit(function (e) {
|
||||||
e.preventDefault(e);
|
e.preventDefault(e);
|
||||||
|
@ -26,7 +50,11 @@ $(document).ready(function () {
|
||||||
url: "calls.php",
|
url: "calls.php",
|
||||||
data: $("#yabsForm").serialize(),
|
data: $("#yabsForm").serialize(),
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
location.reload();
|
if (result.length == 1) {
|
||||||
|
alert('ERROR: ' + YABSdebug(result));
|
||||||
|
} else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
11
calls.php
11
calls.php
|
@ -56,8 +56,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||||
if (isset($_POST['action']) && $_POST['action'] == 'insert') {//From an insert 'type' form
|
if (isset($_POST['action']) && $_POST['action'] == 'insert') {//From an insert 'type' form
|
||||||
$insert = new itemInsert($_POST);
|
$insert = new itemInsert($_POST);
|
||||||
if (isset($_POST['from_yabs'])) {//From add form YABs
|
if (isset($_POST['from_yabs'])) {//From add form YABs
|
||||||
$insert->insertBasicWithYabs();//Insert basic data from form
|
$id = $insert->insertBasicWithYabs();//Insert basic data from form
|
||||||
$insert->insertYabsData();//Insert YABs data from the form
|
$response_code = $insert->insertYabsData();//Insert YABs data from the form
|
||||||
|
if ($response_code != 1) {
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
$update = new itemUpdate(array('me_server_id' => $id));
|
||||||
|
$update->deleteObjectData();
|
||||||
|
echo $response_code;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
} elseif (isset($_POST['manual'])) {//From add form manual
|
} elseif (isset($_POST['manual'])) {//From add form manual
|
||||||
$insert->insertBasic();
|
$insert->insertBasic();
|
||||||
} elseif (isset($_POST['shared_hosting_form'])) {//From shared hosting form
|
} elseif (isset($_POST['shared_hosting_form'])) {//From shared hosting form
|
||||||
|
|
185
class.php
185
class.php
|
@ -3220,95 +3220,114 @@ class itemInsert extends idlers
|
||||||
//echo json_encode($array);
|
//echo json_encode($array);
|
||||||
//exit;
|
//exit;
|
||||||
}
|
}
|
||||||
if (strpos($array[0], '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #') !== false || count($array) < 50) {
|
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_array = explode(' ', preg_replace('!\s+!', ' ', $this->trimRemoveR($array[2])));
|
||||||
$version = $version_array[1];//YABs version
|
$version = $version_array[1];//YABs version
|
||||||
$cpu = $this->trimRemoveR(str_replace(':', '', strstr($array[10], ': ')));
|
if ($version == 'v2020-12-29') {
|
||||||
$cpu_spec = explode(' ', strstr($array[11], ': '));//: 2 @ 3792.872 MHz
|
$cpu = $this->trimRemoveR(str_replace(':', '', strstr($array[10], ': ')));
|
||||||
$cpu_cores = $cpu_spec[1];
|
$cpu_spec = explode(' ', strstr($array[11], ': '));//: 2 @ 3792.872 MHz
|
||||||
$cpu_freq = $cpu_spec[3];
|
$cpu_cores = $cpu_spec[1];
|
||||||
$ram_line = $this->trimRemoveR(str_replace(':', '', strstr($array[14], ': ')));
|
$cpu_freq = $cpu_spec[3];
|
||||||
$ram = floatval($ram_line);
|
$ram_line = $this->trimRemoveR(str_replace(':', '', strstr($array[14], ': ')));
|
||||||
$ram_type = $this->datatype($ram_line);
|
$ram = floatval($ram_line);
|
||||||
$swap_line = $this->trimRemoveR(str_replace(':', '', strstr($array[15], ': ')));
|
$ram_type = $this->datatype($ram_line);
|
||||||
$swap = floatval($swap_line);
|
$swap_line = $this->trimRemoveR(str_replace(':', '', strstr($array[15], ': ')));
|
||||||
$swap_type = $this->datatype($swap_line);
|
$swap = floatval($swap_line);
|
||||||
$disk_line = $this->trimRemoveR(str_replace(':', '', strstr($array[16], ': ')));
|
$swap_type = $this->datatype($swap_line);
|
||||||
$disk = floatval($disk_line);
|
$disk_line = $this->trimRemoveR(str_replace(':', '', strstr($array[16], ': ')));
|
||||||
$disk_type = $this->datatype($disk_line);
|
$disk = floatval($disk_line);
|
||||||
$io_3 = explode(' ', preg_replace('!\s+!', ' ', $array[24]));
|
$disk_type = $this->datatype($disk_line);
|
||||||
$io_6 = explode(' ', preg_replace('!\s+!', ' ', $array[30]));
|
$io_3 = explode(' ', preg_replace('!\s+!', ' ', $array[24]));
|
||||||
(strpos($array[12], 'Enabled') !== false) ? $aes_ni = 1 : $aes_ni = 0;
|
$io_6 = explode(' ', preg_replace('!\s+!', ' ', $array[30]));
|
||||||
(strpos($array[13], 'Enabled') !== false) ? $vm_amd_v = 1 : $vm_amd_v = 0;
|
(strpos($array[12], 'Enabled') !== false) ? $aes_ni = 1 : $aes_ni = 0;
|
||||||
$d4k_as_mbps = $this->diskSpeedAsMbps($io_3[3], $this->floatValue($io_3[2]));
|
(strpos($array[13], 'Enabled') !== false) ? $vm_amd_v = 1 : $vm_amd_v = 0;
|
||||||
$d64k_as_mbps = $this->diskSpeedAsMbps($io_3[7], $this->floatValue($io_3[6]));
|
$d4k_as_mbps = $this->diskSpeedAsMbps($io_3[3], $this->floatValue($io_3[2]));
|
||||||
$d512k_as_mbps = $this->diskSpeedAsMbps($io_6[3], $this->floatValue($io_6[2]));
|
$d64k_as_mbps = $this->diskSpeedAsMbps($io_3[7], $this->floatValue($io_3[6]));
|
||||||
$d1m_as_mbps = $this->diskSpeedAsMbps($io_6[7], $this->floatValue($io_6[6]));
|
$d512k_as_mbps = $this->diskSpeedAsMbps($io_6[3], $this->floatValue($io_6[2]));
|
||||||
$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);
|
$d1m_as_mbps = $this->diskSpeedAsMbps($io_6[7], $this->floatValue($io_6[6]));
|
||||||
$this->insertDiskTest($disk_test_arr);
|
$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);
|
||||||
if ($array[45] == "Geekbench 5 Benchmark Test:\r") {
|
$this->insertDiskTest($disk_test_arr);
|
||||||
//No ipv6
|
if (isset($array[40])) {
|
||||||
//Has short ipv4 network speed testing (-r)
|
if ($array[45] == "Geekbench 5 Benchmark Test:\r") {
|
||||||
$start_st = 36;
|
//No ipv6
|
||||||
$end_st = 43;
|
//Has short ipv4 network speed testing (-r)
|
||||||
$gb_s = 49;
|
$start_st = 36;
|
||||||
$gb_m = 50;
|
$end_st = 43;
|
||||||
$gb_url = 51;
|
$gb_s = 49;
|
||||||
} elseif ($array[40] == "Geekbench 5 Benchmark Test:\r") {
|
$gb_m = 50;
|
||||||
//No ipv6
|
$gb_url = 51;
|
||||||
//Has full ipv4 network speed testing
|
} elseif ($array[45] == "Geekbench 4 Benchmark Test:\r") {
|
||||||
$start_st = 36;
|
return 6;//GeekBench 5 only allowed
|
||||||
$end_st = 38;
|
} elseif ($array[45] == "Geekbench 5 test failed. Run manually to determine cause.") {
|
||||||
$gb_s = 44;
|
return 7;//GeekBench test failed
|
||||||
$gb_m = 45;
|
} elseif ($array[40] == "Geekbench 5 Benchmark Test:\r") {
|
||||||
$gb_url = 46;
|
//No ipv6
|
||||||
} elseif ($array[40] == "iperf3 Network Speed Tests (IPv6):\r") {
|
//Has full ipv4 network speed testing
|
||||||
//HAS ipv6
|
$start_st = 36;
|
||||||
//Has short ipv4 & ipv6 network speed testing
|
$end_st = 38;
|
||||||
$start_st = 36;
|
$gb_s = 44;
|
||||||
$end_st = 38;
|
$gb_m = 45;
|
||||||
$gb_s = 52;
|
$gb_url = 46;
|
||||||
$gb_m = 53;
|
} elseif ($array[40] == "iperf3 Network Speed Tests (IPv6):\r") {
|
||||||
$gb_url = 54;
|
//HAS ipv6
|
||||||
} elseif ($array[55] == "Geekbench 5 Benchmark Test:\r") {
|
//Has short ipv4 & ipv6 network speed testing
|
||||||
//HAS ipv6
|
$start_st = 36;
|
||||||
//Has full ipv4 & ipv6 network speed testing
|
$end_st = 38;
|
||||||
$start_st = 36;
|
$gb_s = 52;
|
||||||
$end_st = 43;
|
$gb_m = 53;
|
||||||
$gb_s = 59;
|
$gb_url = 54;
|
||||||
$gb_m = 60;
|
} elseif ($array[55] == "Geekbench 5 Benchmark Test:\r") {
|
||||||
$gb_url = 61;
|
//HAS ipv6
|
||||||
}
|
//Has full ipv4 & ipv6 network speed testing
|
||||||
$geekbench_single = $this->intValue($array[$gb_s]);
|
$start_st = 36;
|
||||||
$geekbench_multi = $this->intValue($array[$gb_m]);
|
$end_st = 43;
|
||||||
$geek_full_url = explode(' ', preg_replace('!\s+!', ' ', $array[$gb_url]));
|
$gb_s = 59;
|
||||||
$gb5_id = substr($geek_full_url[3], strrpos($geek_full_url[3], '/') + 1);//
|
$gb_m = 60;
|
||||||
$has_a_speed_test = false;
|
$gb_url = 61;
|
||||||
for ($i = $start_st; $i <= $end_st; $i++) {
|
} else {
|
||||||
if (strpos($array[$i], 'busy') !== false) {
|
return 5;//Not correct YABs command output
|
||||||
//Has a "busy" result, No insert
|
}
|
||||||
} else {
|
} else {
|
||||||
$data = explode(' ', preg_replace('!\s+!', ' ', $array[$i]));
|
return 4;//Not correct format
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
$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]);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 2;//Wrong version
|
||||||
}
|
}
|
||||||
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]);
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
//Not formatted right
|
return 3;//Didnt start at right spot
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user