Merge pull request #3 from cp6/features

1.1 Updates & fixes
This commit is contained in:
corbpie 2021-01-25 11:59:50 +11:00 committed by GitHub
commit 62b6a4ea8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 232 additions and 63 deletions

View File

@ -5,7 +5,21 @@ A web app for displaying, organizing and storing information about servers (VPS)
Despite what the name infers this self hosted web app isn't just for storing idling server information.
By using a [YABs](https://github.com/masonr/yet-another-bench-script) output you can get disk & network speed values along with GeekBench 5 scores to do easier comparing and sorting.
[![Generic badge](https://img.shields.io/badge/version-1.0-blue.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/version-1.1-blue.svg)](https://shields.io/)
## 1.1 changes:
**If you have version 1.0 please run ```update.sql```**
* Added notes input for servers
* Added SSH port input for servers
* Added YABs update disk & network speed values (Keeps history)
* Added red button for closing modals
* Added `update.sql` for pre-existing installations only.
* Fixed page jumping horizontally when opening modals
* Fixed search showing duplicates when typing fast
* Fixed adding provider and locations return id
* Updated `my_idlers.sql` for changes
* Updated view YABs modal to be wider
* Updated config constants to new class at top of ```class.php```
## Requires
@ -36,8 +50,11 @@ By using a [YABs](https://github.com/masonr/yet-another-bench-script) output you
* Download [the zip](https://github.com/cp6/my-idlers/archive/main.zip) and unpack the files from ```my-idlers-main/``` into your directory of choice.
* Run `my_idlers.sql` in MySQL.
* Edit ```class.php``` lines ```544-547``` for your MySQL details.
* Edit ```class.php``` lines ```539-541``` for card order type.
* **Only run ```update.sql``` if you have version 1.0 installed.**
* Edit ```class.php``` lines ```13-16``` for your MySQL details.
* Edit ```class.php``` lines ```8-10``` for card order type.
## Notes
@ -69,10 +86,10 @@ or
[![Screenshot1](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data.jpg)](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data.jpg)
[![screenshot2](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-MORE.jpg)](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-MORE.jpg)
[![screenshot2](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-MORE-1.1.jpg)](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-MORE-1.1.jpg)
[![screenshot3](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-EDIT.jpg)](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-EDIT.jpg)
[![screenshot3](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-EDIT-1.1.jpg)](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-EDIT-1.1.jpg)
[![screenshot4](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-order-table.png)](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-order-table.png)

View File

@ -57,6 +57,10 @@ body {
.container {
max-width: 960px
}
.modal-lg {
max-width: 800px;
}
}
@media (min-width: 1200px) {
@ -889,10 +893,6 @@ button.close {
-webkit-appearance: none
}
.modal-open {
overflow: hidden
}
.modal-open .modal {
overflow-x: hidden;
overflow-y: auto
@ -1314,7 +1314,7 @@ button.close {
border-color: #3a73cf
}
.btn-main:active {
.btn-main:active, .btn-second:active, .btn-third:active {
background-image: none
}
@ -1330,8 +1330,16 @@ button.close {
border-color: #2ea69a
}
.btn-second:active {
background-image: none
.btn-third {
color: #f7f7f7;
background-color: #f06f6f;
border-color: #df4b4b;
}
.btn-third:hover, .btn-third:focus, .btn-third:active {
color: #f7f7f7;
background-color: #d05555;
border-color: #a62e2e;
}
.view-yabs-btn {
@ -1532,7 +1540,7 @@ input:checked + .slider:before {
}
.form-control:disabled, .form-control[readonly] {
background-color: #202125
background-color: #f0f0f0;
}
.search-result {

View File

@ -299,6 +299,8 @@ function modalServerEdit(id) {
$("#me_ram_type").val(result["ram_type"]);
$("#me_swap_type").val(result["swap_type"]);
$("#me_virt").val(result["virt"]);
$("#me_ssh_port").val(result["ssh_port"]);
$("#me_notes").val(result["notes"]);
}
});
}
@ -350,7 +352,7 @@ function modalEditDomain(id) {
function yabsModalView(hostname, id) {
if ($('#yabsTextBox').length)
{
$('#yabsTextBox').remove();
$('#yabsTextBox').remove();
}
$.ajax({
type: "GET",
@ -363,7 +365,16 @@ function yabsModalView(hostname, id) {
});
}
$('#searchInput').keyup(function() {
//https://stackoverflow.com/a/1909508
function delay(fn, ms) {
let timer = 0
return function(...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
$('#searchInput').keyup(delay(function (e) {
var search_term = this.value;
$('#searchDivBody').empty();
$.ajax({
@ -374,4 +385,4 @@ $('#searchInput').keyup(function() {
$('#searchDivBody').append(result);
}
});
});
}, 500));

View File

@ -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();

178
class.php
View File

@ -1,6 +1,22 @@
<?php
class elementHelpers
class idlersConfig
{
const PAGE_TITLE = 'My idlers';
const PAGE_DESC = 'My idlers listing server, shared hosting and domains information and data.';
const SRV_SORT_TYPE = 'HOSTNAME_ASC';//Server card sort type
const SH_SORT_TYPE = 'HOSTNAME_ASC';//Shared hosting sort type
const DC_SORT_TYPE = 'HOSTNAME_ASC';//Domains sort type
//Options: PRICE_DESC, PRICE_ASC, DUE_DESC, DUE_ASC, OWNED_SINCE_DESC,OWNED_SINCE_ASC, HOSTNAME_DESC & HOSTNAME_ASC
const DB_HOSTNAME = '127.0.0.1';
const DB_NAME = 'idlers';
const DB_USERNAME = 'root';
const DB_PASSWORD = '';
}
class elementHelpers extends idlersConfig
{
//Minimizes lines used + opening and closing of <?PHP tag
protected function tagOpen(string $tag = 'div', string $class = '', string $id = '')
@ -533,19 +549,6 @@ class helperFunctions extends elementHelpers
class idlers extends helperFunctions
{
const PAGE_TITLE = 'My idlers';
const PAGE_DESC = 'My idlers listing server, shared hosting and domains information and data.';
const SRV_SORT_TYPE = 'HOSTNAME_ASC';//Server card sort type
const SH_SORT_TYPE = 'HOSTNAME_ASC';//Shared hosting sort type
const DC_SORT_TYPE = 'HOSTNAME_ASC';//Domains sort type
//Options: PRICE_DESC, PRICE_ASC, DUE_DESC, DUE_ASC, OWNED_SINCE_DESC,OWNED_SINCE_ASC, HOSTNAME_DESC & HOSTNAME_ASC
const DB_HOSTNAME = '127.0.0.1';
const DB_NAME = 'idlers';
const DB_USERNAME = 'root';
const DB_PASSWORD = '';
protected function dbConnect()
{
$options = array(
@ -627,7 +630,7 @@ class idlers extends helperFunctions
$this->tagClose('div', 3);
$this->outputString('<div class="modal fade" id="yabsModal" tabindex="-1" role="dialog" aria-labelledby="yabsmodalview" aria-hidden="true">');
$this->outputString('<div class="modal-dialog" role="document">');
$this->outputString('<div class="modal-dialog modal-lg" role="document">');
$this->outputString('<div class="modal-content text-center">');
$this->tagOpen('div', 'modal-header');
$this->outputString('<h4 class="modal-title w-100" id="yabs_hostname_header"></h4>');
@ -689,7 +692,7 @@ class idlers extends helperFunctions
if ($row['has_yabs'] == 1) {
$select = $this->dbConnect()->prepare("
SELECT servers.id as server_id,hostname,ipv4,ipv6,`cpu`,cpu_type,cpu_freq,ram,ram_type,swap,swap_type,`disk`,disk_type,bandwidth,bandwidth_type,gb5_single,gb5_multi,gb5_id,aes_ni,amd_v,
is_dedicated,is_cpu_dedicated,was_special,os,still_have,tags,virt,has_yabs,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,virt,has_yabs,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,send,send_type,recieve,recieve_type,price,currency,term,as_usd,per_month,next_dd,pr.name as provider
FROM servers INNER JOIN disk_speed ds on servers.id = ds.server_id
INNER JOIN speed_tests st on servers.id = st.server_id INNER JOIN locations loc on servers.location = loc.id
@ -704,7 +707,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,swap,swap_type,`disk`,disk_type,
bandwidth,bandwidth_type,gb5_single,gb5_multi,gb5_id,aes_ni,amd_v,is_dedicated,is_cpu_dedicated,was_special,os,still_have,tags,virt,has_yabs,ns1,ns2,
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,
DATE_FORMAT(`owned_since`, '%M %Y') as owned_since,loc.name as location,price,currency,term,as_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;");
@ -1042,12 +1045,17 @@ class idlers extends helperFunctions
$this->tagClose('select');
$this->tagClose('div', 3);
$this->rowColOpen('form-row', 'col-12');
$this->rowColOpen('form-row', 'col-12 col-md-6');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('Virt');
$this->selectElement('me_virt');
$this->virtSelectOptions();
$this->tagClose('select');
$this->tagClose('div', 2);
$this->colOpen('col-12 col-md-6');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('SSH Port');
$this->textInput('me_ssh_port');
$this->tagClose('div', 3);
$this->rowColOpen('form-row', 'col-12');
@ -1055,7 +1063,6 @@ class idlers extends helperFunctions
$this->inputPrepend('IPv4');
$this->textInput('me_ipv4');
$this->tagClose('div', 3);
$this->rowColOpen('form-row', 'col-12');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('IPv6');
@ -1121,6 +1128,18 @@ class idlers extends helperFunctions
$this->tagClose('select');
$this->tagClose('div', 3);
$this->rowColOpen('form-row', 'col-12');
$this->htmlPhrase('p', 'm-desc', 'Notes:');
$this->outputString("<textarea class='form-control' id='me_notes' name='me_notes' rows='4' cols='40' maxlength='255'>");
$this->outputString("</textarea>");
$this->tagClose('div', 2);
$this->rowColOpen('form-row', 'col-12');
$this->htmlPhrase('p', 'm-desc', 'Update YABs disk & network speeds:');
$this->outputString("<textarea class='form-control' id='me_yabs' name='me_yabs' rows='4' cols='40' placeholder='First line must be: # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #'>");
$this->outputString("</textarea>");
$this->tagClose('div', 2);
$this->rowColOpen('form-row', 'col-12');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('Tags');
@ -1682,14 +1701,19 @@ class idlers extends helperFunctions
$this->outputString('<label class="switch"><input type="checkbox" name="dedi_cpu" id="dedi_cpu"><span class="slider round"></span></label>');
$this->tagClose('div', 2);
$this->rowColOpen('form-row', 'col-12 col-md-6');
$this->rowColOpen('form-row', 'col-12 col-md-4');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('SSH');
$this->numberInput('ssh_port', '22', 'form-control', true, 1, 999999, 1);
$this->tagClose('div', 2);
$this->colOpen('col-12 col-md-4');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('Virt');
$this->selectElement('virt');
$this->virtSelectOptions();
$this->tagClose('select');
$this->tagClose('div', 2);
$this->colOpen('col-12 col-md-6');
$this->colOpen('col-12 col-md-4');
$this->tagOpen('div', 'input-group');
$this->inputPrepend('OS');
$this->selectElement('os');
@ -1801,7 +1825,7 @@ class idlers extends helperFunctions
} else {//NO
$insert = $this->dbConnect()->prepare('INSERT INTO `locations` (`name`) VALUES (?);');
$insert->execute([$provider]);
return $db->lastInsertId();
return $this->dbConnect()->lastInsertId();
}
}
@ -1815,7 +1839,7 @@ class idlers extends helperFunctions
} else {//NO
$insert = $this->dbConnect()->prepare('INSERT INTO `providers` (`name`) VALUES (?);');
$insert->execute([$provider]);
return $db->lastInsertId();
return $this->dbConnect()->lastInsertId();
}
}
@ -1892,6 +1916,13 @@ class idlers extends helperFunctions
$this->outputString('<code><p class="m-value">' . $data['ns2'] . '</p></code>');
$this->tagClose('div', 2);
$this->rowColOpen('row m-row', 'col-4');
$this->HTMLphrase('p', 'm-desc', 'SSH Port');
$this->tagClose('div');
$this->colOpen('col-8');
$this->HTMLphrase('p', 'm-value', '<code>' . $data['ssh_port'] . '</code>');
$this->tagClose('div', 2);
$this->rowColOpen('row m-row', 'col-4');
$this->HTMLphrase('p', 'm-desc', 'Bandwidth');
$this->tagClose('div');
@ -2095,6 +2126,18 @@ class idlers extends helperFunctions
}
}
}
$this->rowColOpen('row m-section-row', 'col-12 text-center');
$this->htmlPhrase('p', 'm-section-text', 'Notes');
$this->outputString("<textarea class='form-control' id='server_notes' name='server_notes' rows='4' cols='40' maxlength='255' disabled>");
if (is_null($data['notes']) || empty($data['notes'])){
$this->outputString('');
} else {
$this->outputString($data['notes']);
}
$this->outputString("</textarea>");
$this->tagClose('div', 2);
$this->rowColOpen('row m-section-row', 'col-12 text-center');
$this->HTMLphrase('p', 'm-section-text', 'Tags');
$this->tagClose('div', 2);
@ -2109,9 +2152,16 @@ class idlers extends helperFunctions
$this->tagClose('ul');
$this->tagClose('div', 3);
if (file_exists("yabs/{$data['server_id']}.txt")) {
$this->rowColOpen('row', 'col-12 text-center');
$this->rowColOpen('row text-center', 'col-12 col-md-6');
$this->outputString('<a class="btn btn-main view-yabs-btn" id="viewYabs" value="' . $item_id . '" data-target="#yabsModal" data-toggle="modal" href="#" role="button">View YABs</a>');
$this->tagClose('div', 2);
$this->tagClose('div');
$this->colOpen('col-12 col-md-6');
$this->outputString('<a class="btn btn-third" id="closeViewMoreModal" role="button" data-dismiss="modal">Close</a>');
$this->tagClose('div',2);
} else {
$this->rowColOpen('row text-center', 'col-12');
$this->outputString('<a class="btn btn-third" id="closeViewMoreModal" role="button" data-dismiss="modal">Close</a>');
$this->tagClose('div',2);
}
}
@ -2705,6 +2755,9 @@ class idlers extends helperFunctions
$this->outputString(file_get_contents("yabs/$item_id.txt"));
$this->tagClose('textarea');
$this->tagClose('form');
$this->rowColOpen('row text-center', 'col-12');
$this->outputString('<a class="btn btn-third" role="button" data-dismiss="modal">Close YABs</a>');
$this->tagClose('div',2);
}
}
@ -2730,8 +2783,8 @@ class itemInsert extends idlers
(empty($data['ipv6'])) ? $ipv6 = null : $ipv6 = $data['ipv6'];
$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) VALUES (?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?)');
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $data['ipv4'], $ipv6, $data['owned_since'], $data['os'], $dedi_cpu, $dedi, $offer, $data['bandwidth'], $data['virt'], $data['has_yabs'], $data['ns1'], $data['ns2']]);
$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) VALUES (?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?)');
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $data['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']]);
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
return $item_id;
}
@ -2749,8 +2802,8 @@ class itemInsert extends idlers
($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) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $data['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']]);
$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) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
$insert->execute([$item_id, $data['hostname'], $location_id, $provider_id, $data['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']]);
$this->insertPrice($data['price'], $data['currency'], $data['term'], $data['next_due_date']);
return $item_id;
}
@ -2924,8 +2977,8 @@ class itemUpdate extends idlers
} 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` = ? 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'], $this->item_id]);
$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` = ? 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'], $this->item_id]);
}
public function updateServerPricingFromModal()
@ -3011,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;
}
}
}

View File

@ -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;
@ -322,9 +322,11 @@ CREATE TABLE IF NOT EXISTS `servers`
`is_cpu_dedicated` tinyint(1) DEFAULT '0',
`was_special` tinyint(1) DEFAULT '0',
`os` int(11) DEFAULT NULL,
`ssh_port` int(11) DEFAULT '22',
`still_have` tinyint(1) DEFAULT '1',
`owned_since` date DEFAULT NULL,
`tags` varchar(255) DEFAULT NULL,
`notes` varchar(255) DEFAULT NULL,
`has_yabs` tinyint(1) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Index 2` (`ipv4`, `hostname`, `ipv6`)

View File

@ -1,2 +1,14 @@
ALTER TABLE `disk_speed`
ADD COLUMN `datetime` DATETIME NULL DEFAULT CURRENT_TIMESTAMP AFTER `1m_as_mbps`;
ADD COLUMN `datetime` DATETIME NULL DEFAULT CURRENT_TIMESTAMP AFTER `1m_as_mbps`;
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`;
ALTER TABLE `disk_speed`
DROP PRIMARY KEY;
ALTER TABLE `disk_speed`
ADD UNIQUE INDEX `Index 1` (`server_id`, `datetime`);