diff --git a/README.md b/README.md index d8d26ad..f6d30c8 100644 --- a/README.md +++ b/README.md @@ -90,22 +90,25 @@ or ### Screenshots -[](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/02/my-idlers-self-hosted-server-info-cards.jpg) +[](https://cdn.write.corbpie.com/wp-content/uploads/2021/02/my-idlers-self-hosted-server-info-table.jpg) -[](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/02/my-idlers-self-hosted-server-info-more-modal.jpg) +[](https://cdn.write.corbpie.com/wp-content/uploads/2021/02/my-idlers-self-hosted-server-info-edit-modal.jpg) -[](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/02/my-idlers-self-hosted-server-info-order-servers.jpg) +[](https://cdn.write.corbpie.com/wp-content/uploads/2021/02/my-idlers-self-hosted-server-info-search.jpg) -[](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/02/my-idlers-self-hosted-server-info-summary-card.jpg) +[](https://cdn.write.corbpie.com/wp-content/uploads/2021/02/my-idlers-self-hosted-server-info-compare-two-servers.jpg) -[](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-tally-card.png) - -[](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-data-table-view.png) +[](https://cdn.write.corbpie.com/wp-content/uploads/2021/02/my-idlers-self-hosted-server-info-add-server-from-yabs.jpg) +[](https://cdn.write.corbpie.com/wp-content/uploads/2021/02/my-idlers-self-hosted-server-info-add-shared-hosting.jpg) [](https://cdn.write.corbpie.com/wp-content/uploads/2021/01/my-idlers-self-hosted-server-domain-information-auto-location.gif) diff --git a/assets/css/style.css b/assets/css/style.css index 5691985..fea7246 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -51,6 +51,9 @@ body { .container { max-width: 720px } + .nav-link { + padding: .5rem 0.45rem; + } } @media (min-width: 992px) { @@ -1184,10 +1187,27 @@ button.close { background: #00ff340f; } -.objects-table th:first-child, .objects-table td:first-child { +.objects-table th:first-child, .objects-table td:first-child, .compare-table th:first-child, .compare-table td:first-child { position: sticky; left: 0; background-color: #f6f6f6; + text-align: left; +} + +.compare-table td, .compare-table th { + text-align: center; +} + +.plus-td { + background: #71ed7136; +} + +.neg-td { + background: #ed827136; +} + +.equal-td { + background: #6189ff26; } .table-btn { @@ -1540,4 +1560,10 @@ input:checked + .slider:before { .modal-lg { max-width: 800px; } +} + +@media (max-width: 700px) { + .nav-link { + padding: 0.5rem 0.45rem; + } } \ No newline at end of file diff --git a/assets/js/scripts.min.js b/assets/js/scripts.min.js index 4cb5c1b..99ab497 100644 --- a/assets/js/scripts.min.js +++ b/assets/js/scripts.min.js @@ -18,6 +18,30 @@ jQuery Tags 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 () { $("#yabsForm").submit(function (e) { e.preventDefault(e); @@ -26,7 +50,11 @@ $(document).ready(function () { url: "calls.php", data: $("#yabsForm").serialize(), success: function (result) { - location.reload(); + if (result.length == 1) { + alert('ERROR: ' + YABSdebug(result)); + } else { + location.reload(); + } } }); }); @@ -155,8 +183,37 @@ $(document).ready(function () { } else if ($("#tableViewDiv").hasClass("active")){ loadTable(); } + + //Compare section + $("#compare_s1").change(function () { + var server1_id = $("#compare_s1 option:selected").val(); + var server2_id = $("#compare_s2 option:selected").val(); + if (server2_id.length !== 0) { + compareTableCall(server1_id, server2_id); + } + }); + $("#compare_s2").change(function () { + var server2_id = $("#compare_s2 option:selected").val(); + var server1_id = $("#compare_s1 option:selected").val(); + if (server1_id.length !== 0) { + compareTableCall(server1_id, server2_id); + } + }); + }); +function compareTableCall(id1, id2) { + $("#compareTableDiv").empty(); + $.ajax({ + type: "GET", + url: "calls.php", + data: {"type": "compare_table", "server1": id1, "server2": id2}, + success: function (result) { + $("#compareTableDiv").append(result); + } + }); +} + function loadCards(){ $.ajax({ type: "GET", diff --git a/calls.php b/calls.php index 6e6c01f..b615b98 100644 --- a/calls.php +++ b/calls.php @@ -46,6 +46,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } elseif ($_GET['type'] == 'object_tables') { header('Content-Type: text/html; charset=utf-8'); echo $idle->objectTables(); + } elseif ($_GET['type'] == 'compare_table') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->compareTable($_GET['server1'], $_GET['server2']); } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { @@ -56,8 +59,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($_POST['action']) && $_POST['action'] == 'insert') {//From an insert 'type' form $insert = new itemInsert($_POST); if (isset($_POST['from_yabs'])) {//From add form YABs - $insert->insertBasicWithYabs();//Insert basic data from form - $insert->insertYabsData();//Insert YABs data from the form + $id = $insert->insertBasicWithYabs();//Insert basic data from 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 $insert->insertBasic(); } elseif (isset($_POST['shared_hosting_form'])) {//From shared hosting form diff --git a/class.php b/class.php index 3277c13..d8f2bc9 100644 --- a/class.php +++ b/class.php @@ -19,6 +19,8 @@ class idlersConfig const COLOR_TABLE = true; const DEFAULT_VIEW = 'CARDS';//CARDS or TABLE + + const SAVE_YABS_OUTPUT = true;//true or false } class elementHelpers extends idlersConfig @@ -566,6 +568,20 @@ class helperFunctions extends elementHelpers $date = new DateTime($ahead_date); return $date->diff($today)->format("%a"); } + + protected function deleteYabsForId(string $id) + { + if ($handle = opendir("yabs/")) { + while (false !== ($file = readdir($handle))) { + if ('.' === $file) continue; + if (strpos($file, $id) !== false) { + unlink("yabs/$file"); + } + } + closedir($handle); + } + } + } class idlers extends helperFunctions @@ -596,7 +612,7 @@ class idlers extends helperFunctions protected function pageContents() { - $this->navTabs(array('Services', 'Add', 'Order', 'Info', 'Search'), array('#services', '#add_server', '#order', '#info', '#search')); + $this->navTabs(array('Services', 'Add', 'Order', 'Info', 'Search', 'Compare'), array('#services', '#add_server', '#order', '#info', '#search', '#compare')); $this->outputString('
' . $this->idToObjectName($data['attached_to']) . '
');
+ if (!is_null($data['attached_to']) && !empty($data['attached_to'])) {
+ $this->outputString('' . $this->idToObjectName($data['attached_to']) . '
');
+ } else {
+ $this->outputString('');
+ }
$this->tagClose('div', 2);
@@ -3136,6 +3162,236 @@ class idlers extends helperFunctions
}
return $id;
}
+
+ protected function checkPHPversion()
+ {
+ if (version_compare(PHP_VERSION, '7.4') === -1) {
+ echo "";
+ exit;
+ }
+ }
+
+ //Compare functions
+ protected function compatibleComparesSelect()
+ {
+ $select = $this->dbConnect()->prepare("SELECT `id`, `hostname` FROM `servers` WHERE `has_yabs` = 1 AND `has_st` = 1 ORDER BY `hostname`;");
+ $select->execute();
+ $rows = $select->fetchAll(PDO::FETCH_ASSOC);
+ $this->rowColOpen('form-row', 'col-12 col-md-6 mm-col');
+ $this->tagOpen('div', 'input-group');
+ $this->inputPrepend('Server 1');
+ $this->selectElement('compare_s1');
+ $this->selectOption('', '', true);//Empty
+ foreach ($rows as $aserver) {
+ $this->selectOption($aserver['hostname'], $aserver['id']);
+ }
+ $this->tagClose('select');
+ $this->tagClose('div', 2);
+ $this->colOpen('col-12 col-md-6 mm-col');
+ $this->tagOpen('div', 'input-group');
+ $this->inputPrepend('Server 2');
+ $this->selectElement('compare_s2');
+ $this->selectOption('', '', true);
+ foreach ($rows as $aserver) {
+ $this->selectOption($aserver['hostname'], $aserver['id']);
+ }
+ $this->tagClose('select');
+ $this->tagClose('div', 3);
+ }
+
+ protected function compareSection()
+ {
+ $this->compatibleComparesSelect();
+ $this->tagOpen('div', '', 'compareTableDiv');
+ $this->tagClose('div');
+ }
+
+ protected function tableRowCompare(string $val1, string $val2, string $value_type = '', bool $is_int = true)
+ {
+ $value_append = '' . $value_type . '';
+ if ($is_int) {
+ $val1 = intval($val1);
+ $val2 = intval($val2);
+ }
+ if ($val1 > $val2) {//val1 is greater than val2
+ $result = '+' . ($val1 - $val2);
+ if (!empty($value_type)) {
+ $result = '+' . ($val1 - $val2) . $value_append;
+ $val1 = $val1 . $value_append;
+ $val2 = $val2 . $value_append;
+ }
+ $this->tableTd('td-nowrap', $val1);
+ $this->tableTd('td-nowrap plus-td', $result);
+ $this->tableTd('td-nowrap', $val2);
+ } elseif ($val1 < $val2) {//val1 is less than val2
+ $result = '-' . ($val2 - $val1);
+ if (!empty($value_type)) {
+ $result = '-' . ($val2 - $val1) . $value_append;
+ $val1 = $val1 . $value_append;
+ $val2 = $val2 . $value_append;
+ }
+ $this->tableTd('td-nowrap', $val1);
+ $this->tableTd('td-nowrap neg-td', $result);
+ $this->tableTd('td-nowrap', $val2);
+ } else {//Equal
+ $result = 0;
+ if (!empty($value_type)) {
+ $result = '0' . $value_append;
+ $val1 = $val1 . $value_append;
+ $val2 = $val2 . $value_append;
+ }
+ $this->tableTd('td-nowrap', $val1);
+ $this->tableTd('td-nowrap equal-td', $result);
+ $this->tableTd('td-nowrap', $val2);
+ }
+ }
+
+ public function compareTable(string $server1_id, string $server2_id)
+ {
+ $server1_data = json_decode($this->serverData($server1_id), true);
+ $server2_data = json_decode($this->serverData($server2_id), true);
+
+ $this->tableHeader(array('', $server1_data['hostname'], 'DIF', $server2_data['hostname']), 'table compare-table', 'compareTable');
+
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'CPU count');
+ $this->tableRowCompare($server1_data['cpu'], $server2_data['cpu']);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'CPU freq');
+ $this->tableRowCompare($this->mhzToGhz($server1_data['cpu_freq']), $this->mhzToGhz($server2_data['cpu_freq']), 'Ghz', false);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Ram');
+ $this->tableRowCompare($server1_data['ram_mb'], $server2_data['ram_mb'], 'MB');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Swap');
+ $this->tableRowCompare($server1_data['swap_mb'], $server2_data['swap_mb'], 'MB');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Disk');
+ $this->tableRowCompare($server1_data['disk_gb'], $server2_data['disk_gb'], 'GB');
+ $this->tagClose('tr');
+ if ($server1_data['has_yabs'] == 1 && $server2_data['has_yabs'] == 1) {
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'GB5 single');
+ $this->tableRowCompare($server1_data['gb5_single'], $server2_data['gb5_single']);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'GB5 multi');
+ $this->tableRowCompare($server1_data['gb5_multi'], $server2_data['gb5_multi']);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', '4k disk');
+ $this->tableRowCompare($server1_data['4k_as_mbps'], $server2_data['4k_as_mbps'], 'MB/s');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', '64k disk');
+ $this->tableRowCompare($server1_data['64k_as_mbps'], $server2_data['64k_as_mbps'], 'MB/s');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', '512k disk');
+ $this->tableRowCompare($server1_data['512k_as_mbps'], $server2_data['512k_as_mbps'], 'MB/s');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', '1m disk');
+ $this->tableRowCompare($server1_data['1m_as_mbps'], $server2_data['1m_as_mbps'], 'MB/s');
+ $this->tagClose('tr');
+ }
+ if ($server1_data['has_st'] == 1 && $server2_data['has_st'] == 1) {
+ if (isset($server1_data[0]) && isset($server2_data[0])) {
+ if ($server1_data[0]['location'] == $server2_data[0]['location']) {
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', $server1_data[0]['location'] . ' send');
+ $this->tableRowCompare($server1_data[0]['send_as_mbps'], $server2_data[0]['send_as_mbps'], 'MBps');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', $server1_data[0]['location'] . ' recieve');
+ $this->tableRowCompare($server1_data[0]['recieve_as_mbps'], $server2_data[0]['recieve_as_mbps'], 'MBps');
+ $this->tagClose('tr');
+ }
+ }
+ if (isset($server1_data[1]) && isset($server2_data[1])) {
+ if ($server1_data[1]['location'] == $server2_data[1]['location']) {
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', $server1_data[1]['location'] . ' send');
+ $this->tableRowCompare($server1_data[1]['send_as_mbps'], $server2_data[1]['send_as_mbps'], 'MBps');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', $server1_data[1]['location'] . ' recieve');
+ $this->tableRowCompare($server1_data[1]['recieve_as_mbps'], $server2_data[1]['recieve_as_mbps'], 'MBps');
+ $this->tagClose('tr');
+ }
+ }
+ if (isset($server1_data[2]) && isset($server2_data[2])) {
+ if ($server1_data[2]['location'] == $server2_data[2]['location']) {
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', $server1_data[2]['location'] . ' send');
+ $this->tableRowCompare($server1_data[2]['send_as_mbps'], $server2_data[2]['send_as_mbps'], 'MBps');
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', $server1_data[2]['location'] . ' recieve');
+ $this->tableRowCompare($server1_data[2]['recieve_as_mbps'], $server2_data[2]['recieve_as_mbps'], 'MBps');
+ $this->tagClose('tr');
+ }
+ }
+ }
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'USD p/m');
+ $this->tableRowCompare($server1_data['usd_per_month'], $server2_data['usd_per_month'], 'p/m', false);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Actual price');
+ $this->tableTd('td-nowrap', $server1_data['price'] . '' . $server1_data['currency'] . '' . ' ' . $this->paymentTerm($server1_data['term']));
+ $this->tableTd('td-nowrap equal-td', '');
+ $this->tableTd('td-nowrap', $server2_data['price'] . '' . $server2_data['currency'] . '' . ' ' . $this->paymentTerm($server2_data['term']));
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ if ($server1_data['price'] > 0 && $server2_data['price'] > 0) {
+ $this->tableTd('td-nowrap', 'CPU per USD');
+ $this->tableRowCompare(number_format(($server1_data['usd_per_month'] / $server1_data['cpu']), 2), number_format(($server2_data['usd_per_month'] / $server2_data['cpu']), 2), '', false);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Disk GB per USD');
+ $this->tableRowCompare(($server1_data['disk_gb'] / $server1_data['usd_per_month']), ($server2_data['disk_gb'] / $server2_data['usd_per_month']), 'GB', true);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Ram MB per USD');
+ $this->tableRowCompare(($server1_data['ram_mb'] / $server1_data['usd_per_month']), ($server2_data['ram_mb'] / $server2_data['usd_per_month']), 'MB', true);
+ $this->tagClose('tr');
+ if ($server1_data['has_yabs'] == 1 && $server2_data['has_yabs'] == 1) {
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'GB5 single per USD');
+ $this->tableRowCompare(($server1_data['gb5_single'] / $server1_data['usd_per_month']), ($server2_data['gb5_single'] / $server2_data['usd_per_month']), '', true);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'GB5 multi per USD');
+ $this->tableRowCompare(($server1_data['gb5_multi'] / $server1_data['usd_per_month']), ($server2_data['gb5_multi'] / $server2_data['usd_per_month']), '', true);
+ $this->tagClose('tr');
+ }
+ }
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Location');
+ $this->tableTd('td-nowrap', $server1_data['location']);
+ $this->tableTd('td-nowrap equal-td', '');
+ $this->tableTd('td-nowrap', $server2_data['location']);
+ $this->tagClose('tr');
+ $this->tagOpen('tr');
+ $this->tableTd('td-nowrap', 'Provider');
+ $this->tableTd('td-nowrap', $server1_data['provider']);
+ $this->tableTd('td-nowrap equal-td', '');
+ $this->tableTd('td-nowrap', $server2_data['provider']);
+ $this->tagClose('tr');
+ $this->tableTd('td-nowrap', 'Owned since');
+ $this->tableTd('td-nowrap', $server1_data['owned_since']);
+ $this->tableTd('td-nowrap equal-td', '');
+ $this->tableTd('td-nowrap', $server2_data['owned_since']);
+ $this->tagClose('tr');
+ $this->outputString('