diff --git a/AUTH.php b/AUTH.php new file mode 100644 index 0000000..b65e1c0 --- /dev/null +++ b/AUTH.php @@ -0,0 +1,4 @@ +selfDestruct(); \ No newline at end of file diff --git a/README.md b/README.md index acb2923..b33afbf 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ V2 build is going to be a complete overhaul of My idlers with the project being 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.4-blue.svg)](https://shields.io/) + +[![Generic badge](https://img.shields.io/badge/version-1.5-blue.svg)](https://shields.io/) ## 1.4 changes: **If you have version 1.3 already installed please run ```update1.3to1.4.sql```** diff --git a/calls.php b/calls.php index e26aed4..8cbf4e6 100644 --- a/calls.php +++ b/calls.php @@ -2,99 +2,108 @@ header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json'); require_once('class.php'); -$idle = new idlers(); - -if ($_SERVER['REQUEST_METHOD'] === 'GET') { - if (isset($_GET['type'])) { - if ($_GET['type'] == 'server') { - echo $idle->serverData($_GET['id']); - } elseif ($_GET['type'] == 'search') { - header('Content-Type: text/html; charset=utf-8'); - echo $idle->searchResults($_GET['value']); - } elseif ($_GET['type'] == 'shared_hosting') { - echo $idle->sharedHostingData($_GET['id']); - } elseif ($_GET['type'] == 'domain') { - echo $idle->domainData($_GET['id']); - } elseif ($_GET['type'] == 'yabsModal') { - header('Content-Type: text/html; charset=utf-8'); - echo $idle->showYabsModal($_GET['id']);//Not used anymore. Still here for debugging - } elseif ($_GET['type'] == 'infoCard') { - header('Content-Type: text/html; charset=utf-8'); - echo $idle->infoCard();//Info card for the "info" tab - } elseif ($_GET['type'] == 'autocomplete') { - if ($_GET['input'] == 'location') { - $idle->locationsAutoCompleteGET($_GET['value']);//Auto complete locations input - } elseif ($_GET['input'] == 'provider') { - $idle->providersAutoCompleteGET($_GET['value']);//Auto complete providers input +$auth = new auth(); +$auth->sessionStartIfNone(); +if (isset($_SESSION['token'])) { + $idle = new idlers(); + if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['type'])) { + if ($_GET['type'] == 'server') { + echo $idle->serverData($_GET['id']); + } elseif ($_GET['type'] == 'search') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->searchResults($_GET['value']); + } elseif ($_GET['type'] == 'shared_hosting') { + echo $idle->sharedHostingData($_GET['id']); + } elseif ($_GET['type'] == 'domain') { + echo $idle->domainData($_GET['id']); + } elseif ($_GET['type'] == 'yabsModal') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->showYabsModal($_GET['id']);//Not used anymore. Still here for debugging + } elseif ($_GET['type'] == 'infoCard') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->infoCard();//Info card for the "info" tab + } elseif ($_GET['type'] == 'autocomplete') { + if ($_GET['input'] == 'location') { + $idle->locationsAutoCompleteGET($_GET['value']);//Auto complete locations input + } elseif ($_GET['input'] == 'provider') { + $idle->providersAutoCompleteGET($_GET['value']);//Auto complete providers input + } + } elseif ($_GET['type'] == 'view_more_modal') { + header('Content-Type: text/html; charset=utf-8'); + if ($_GET['value'] == 'server') { + $idle->viewMoreModal($_GET['id']);//View more details modal + } elseif ($_GET['value'] == 'shared') { + $idle->viewMoreSharedHostingModal($_GET['id']);//View more details modal + } elseif ($_GET['value'] == 'domain') { + $idle->viewMoreDomainModal($_GET['id']);//View more details modal + } + } elseif ($_GET['type'] == 'dns_search') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->getIpForDomain($_GET['hostname'], $_GET['dns_type']); + } elseif ($_GET['type'] == 'check_up') { + echo $idle->checkIsUp($_GET['host']); + } elseif ($_GET['type'] == 'object_cards') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->objectCards(); + } 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 ($_GET['type'] == 'view_more_modal') { - header('Content-Type: text/html; charset=utf-8'); - if ($_GET['value'] == 'server') { - $idle->viewMoreModal($_GET['id']);//View more details modal - } elseif ($_GET['value'] == 'shared') { - $idle->viewMoreSharedHostingModal($_GET['id']);//View more details modal - } elseif ($_GET['value'] == 'domain') { - $idle->viewMoreDomainModal($_GET['id']);//View more details modal - } - } elseif ($_GET['type'] == 'dns_search') { - header('Content-Type: text/html; charset=utf-8'); - echo $idle->getIpForDomain($_GET['hostname'], $_GET['dns_type']); - } elseif ($_GET['type'] == 'check_up') { - echo $idle->checkIsUp($_GET['host']); - } elseif ($_GET['type'] == 'object_cards') { - header('Content-Type: text/html; charset=utf-8'); - echo $idle->objectCards(); - } 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') { - if (isset($_POST['order_form'])) { - header('Content-Type: text/html; charset=utf-8'); - echo $idle->orderTable($_POST['order_by']);//Returns order table - } else { - 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 - $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)); + } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['order_form'])) { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->orderTable($_POST['order_by']);//Returns order table + } else { + 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 + $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 + $insert->insertSharedHosting(); + } elseif (isset($_POST['domain_form'])) {//From domain form + $insert->insertDomain(); + } + } elseif (isset($_POST['action']) && $_POST['action'] == 'update') { + $update = new itemUpdate($_POST); + if (isset($_POST['me_delete']) || isset($_POST['sh_me_delete']) || isset($_POST['d_me_delete'])) {//Delete object $update->deleteObjectData(); - echo $response_code; - exit; + } 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(); + } elseif ($_POST['type'] == 'domain_modal_edit') {//Update the domain info + $update->updateDomainFromModal(); + $update->updateDomainPricingFromModal(); } - } elseif (isset($_POST['manual'])) {//From add form manual - $insert->insertBasic(); - } elseif (isset($_POST['shared_hosting_form'])) {//From shared hosting form - $insert->insertSharedHosting(); - } elseif (isset($_POST['domain_form'])) {//From domain form - $insert->insertDomain(); - } - } elseif (isset($_POST['action']) && $_POST['action'] == 'update') { - $update = new itemUpdate($_POST); - if (isset($_POST['me_delete']) || isset($_POST['sh_me_delete']) || isset($_POST['d_me_delete'])) {//Delete object - $update->deleteObjectData(); - } 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(); - } elseif ($_POST['type'] == 'domain_modal_edit') {//Update the domain info - $update->updateDomainFromModal(); - $update->updateDomainPricingFromModal(); } + header('Location:index.php'); + die(); } - header('Location:index.php'); - die(); } -} \ No newline at end of file +} else { + header('HTTP/1.1 401 Unauthorized'); + echo json_encode(array( + 'code' => 401, + 'message' => 'Unauthorized')); + exit; +} diff --git a/class.php b/class.php index 87956f8..2d64b70 100644 --- a/class.php +++ b/class.php @@ -23,6 +23,11 @@ class idlersConfig const SAVE_YABS_OUTPUT = true;//true or false const GET_ASN_INFO = true;//Get ANS name and number + + //Failed attempts before ip locked from attempting login + const FAIL_ATTEMPTS_ALLOWED = 4; + //Minutes to lock ip for + const IP_LOCK_MINUTES = 10; } class elementHelpers extends idlersConfig @@ -1403,7 +1408,7 @@ class idlers extends helperFunctions $this->colOpen('col-12 col-md-6 mm-col'); $this->tagOpen('div', 'input-group'); $this->inputPrepend('Bandwidth'); - $this->numberInput('me_bandwidth', '', 'form-control', false, 1, 9999); + $this->numberInput('me_bandwidth', '', 'form-control', false, 0, 9999); $this->outputString('