mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 23:42:32 +01:00
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
28
assets/js/scripts.min.js
vendored
28
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,8 +50,12 @@ $(document).ready(function () {
|
|||||||
url: "calls.php",
|
url: "calls.php",
|
||||||
data: $("#yabsForm").serialize(),
|
data: $("#yabsForm").serialize(),
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
|
if (result.length == 1) {
|
||||||
|
alert('ERROR: ' + YABSdebug(result));
|
||||||
|
} else {
|
||||||
location.reload();
|
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
|
||||||
|
27
class.php
27
class.php
@ -3220,9 +3220,16 @@ 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
|
||||||
|
if ($version == 'v2020-12-29') {
|
||||||
$cpu = $this->trimRemoveR(str_replace(':', '', strstr($array[10], ': ')));
|
$cpu = $this->trimRemoveR(str_replace(':', '', strstr($array[10], ': ')));
|
||||||
$cpu_spec = explode(' ', strstr($array[11], ': '));//: 2 @ 3792.872 MHz
|
$cpu_spec = explode(' ', strstr($array[11], ': '));//: 2 @ 3792.872 MHz
|
||||||
$cpu_cores = $cpu_spec[1];
|
$cpu_cores = $cpu_spec[1];
|
||||||
@ -3246,6 +3253,7 @@ class itemInsert extends idlers
|
|||||||
$d1m_as_mbps = $this->diskSpeedAsMbps($io_6[7], $this->floatValue($io_6[6]));
|
$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);
|
$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);
|
$this->insertDiskTest($disk_test_arr);
|
||||||
|
if (isset($array[40])) {
|
||||||
if ($array[45] == "Geekbench 5 Benchmark Test:\r") {
|
if ($array[45] == "Geekbench 5 Benchmark Test:\r") {
|
||||||
//No ipv6
|
//No ipv6
|
||||||
//Has short ipv4 network speed testing (-r)
|
//Has short ipv4 network speed testing (-r)
|
||||||
@ -3254,6 +3262,10 @@ class itemInsert extends idlers
|
|||||||
$gb_s = 49;
|
$gb_s = 49;
|
||||||
$gb_m = 50;
|
$gb_m = 50;
|
||||||
$gb_url = 51;
|
$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") {
|
} elseif ($array[40] == "Geekbench 5 Benchmark Test:\r") {
|
||||||
//No ipv6
|
//No ipv6
|
||||||
//Has full ipv4 network speed testing
|
//Has full ipv4 network speed testing
|
||||||
@ -3278,6 +3290,11 @@ class itemInsert extends idlers
|
|||||||
$gb_s = 59;
|
$gb_s = 59;
|
||||||
$gb_m = 60;
|
$gb_m = 60;
|
||||||
$gb_url = 61;
|
$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_single = $this->intValue($array[$gb_s]);
|
||||||
$geekbench_multi = $this->intValue($array[$gb_m]);
|
$geekbench_multi = $this->intValue($array[$gb_m]);
|
||||||
@ -3305,10 +3322,12 @@ class itemInsert extends idlers
|
|||||||
($disk_type == 'TB') ? $disk_gb = $this->TBtoGB($disk) : $disk_gb = $disk;
|
($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 = $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]);
|
$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;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
//Not formatted right
|
return 2;//Wrong version
|
||||||
return false;
|
}
|
||||||
|
} else {
|
||||||
|
return 3;//Didnt start at right spot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user