Merge pull request #60 from cp6/Development

Development v2.1.5
This commit is contained in:
corbpie 2022-09-07 16:02:48 +10:00 committed by GitHub
commit 91a1466f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 275 additions and 136 deletions

View File

@ -8,7 +8,7 @@ Despite what the name infers this self hosted web app isn't just for storing idl
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-2.1.3-blue.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Laravel-9.0-red.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/PHP-8.1-purple.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Bootstrap-5.1-pink.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/version-2.1.5-blue.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Laravel-9.0-red.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/PHP-8.1-purple.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Bootstrap-5.1-pink.svg)](https://shields.io/)
<img src="https://raw.githubusercontent.com/cp6/my-idlers/main/public/My%20Idlers%20logo.jpg" width="128" height="128" />
@ -20,26 +20,33 @@ GeekBench 5 scores to do easier comparing and sorting.
[Cloud Five Limited](https://cloud-v.net/) for providing the hosting for demo installation.
## 2.1.3 changes (20th July 2022):
## 2.1.5 changes (7th September 2022):
#### Note:
yabs.sh now has JSON formatted response and it is possible to POST the output directly from calling the script.
This will become the only method to add YABS results but using the form method still works for now.
This version updates the yabs/ POST API to include the server id and your api key:
`http://domain.com/api/yabs/tnSJLyhz/USERAPIKEYISHERE`
Example yabs.sh call to POST the result
`curl -sL yabs.sh | bash -s -- -s "http://domain.com/api/yabs/tnSJLyhz/USERAPIKEYISHERE"`
#### Please run the following if updating from existing install:
```shell
php artisan migrate
php artisan route:cache
php artisan cache:clear
```
* Added YABs to JSON output page
* Added uptime, distro and kernel to YABs inserting
* Added memory swap values to YABs inserting
* Added save YABs as txt file (setting)
* Added back and edit button component with icon
* Updated Reseller model to use relationships + caching
* Updated Misc model to use relationships + caching
* Updated SeedBoxes model to use relationships + caching
* Updated ApiController to use the new model relationship calling (& caching)
* Updated container large screen max width from 1320px to 1420px
* Added YABS JSON parsing
* Updated store YABS API function (Uses yabs.sh JSON)
* Updated YABS POST API request (Uses yabs.sh JSON)
* Updated server show page to display code to run and post a YABS on server
* Updated pricing model insertPricing() func
## Requires

View File

@ -15,6 +15,7 @@ use App\Models\Reseller;
use App\Models\SeedBoxes;
use App\Models\Server;
use App\Models\Shared;
use App\Models\User;
use App\Models\Yabs;
use App\Process;
use DataTables;
@ -310,10 +311,7 @@ class ApiController extends Controller
$server_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(1, $server_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(1, $server_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
if (!is_null($request->ip1)) {
IPs::insertIP($server_id, $request->ip1);
@ -473,113 +471,23 @@ class ApiController extends Controller
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
}
public function storeYabs(Request $request)
public function storeYabs(Request $request, Server $server, string $key): \Illuminate\Http\JsonResponse
{
$rules = array(
'server_id' => 'required|string|size:8',
'yabs_output' => 'required|string',
);
$messages = array(
'required' => ':attribute is required',
'string' => ':attribute must be a string',
'size' => ':attribute must be exactly :size characters'
);
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
return response()->json(['result' => 'fail', 'messages' => $validator->messages()], 400);
$r = User::where('api_token', $key)->first();
if (!isset($r->id)) {
return response()->json(['error' => 'Unauthenticated'], 401);
}
//dd($request->all());
$process = new Process();
$yabs = $process->yabsOutputAsJson($request->server_id, $request->yabs_output);
//dd($yabs);
$insert = Yabs::insertFromJson($request, $server->id);
$yabs_id = Str::random(8);
$yabs_insert = Yabs::create([
'id' => $yabs_id,
'server_id' => $request->server_id,
'has_ipv6' => $yabs['has_ipv6'],
'aes' => $yabs['aes'],
'vm' => $yabs['vm'],
'output_date' => $yabs['output_date'],
'cpu_cores' => $yabs['cpu_cores'],
'cpu_freq' => $yabs['cpu_freq'],
'cpu_model' => $yabs['cpu'],
'ram' => $yabs['ram'],
'ram_type' => $yabs['ram_type'],
'ram_mb' => $yabs['ram_mb'],
'swap' => $yabs['swap'],
'swap_type' => $yabs['swap_type'],
'swap_mb' => $yabs['swap_mb'],
'disk' => $yabs['disk'],
'disk_type' => $yabs['disk_type'],
'disk_gb' => $yabs['disk_gb'],
'gb5_single' => $yabs['GB5_single'],
'gb5_multi' => $yabs['GB5_mult'],
'gb5_id' => $yabs['GB5_id'],
'uptime' => $yabs['uptime'],
'distro' => $yabs['distro'],
'kernel' => $yabs['kernel']
]);
DiskSpeed::create([
'id' => $yabs_id,
'server_id' => $request->server_id,
'd_4k' => $yabs['disk_speed']['4k_total'],
'd_4k_type' => $yabs['disk_speed']['4k_total_type'],
'd_4k_as_mbps' => $yabs['disk_speed']['4k_total_mbps'],
'd_64k' => $yabs['disk_speed']['64k_total'],
'd_64k_type' => $yabs['disk_speed']['64k_total_type'],
'd_64k_as_mbps' => $yabs['disk_speed']['64k_total_mbps'],
'd_512k' => $yabs['disk_speed']['512k_total'],
'd_512k_type' => $yabs['disk_speed']['512k_total_type'],
'd_512k_as_mbps' => $yabs['disk_speed']['512k_total_mbps'],
'd_1m' => $yabs['disk_speed']['1m_total'],
'd_1m_type' => $yabs['disk_speed']['1m_total_type'],
'd_1m_as_mbps' => $yabs['disk_speed']['1m_total_mbps']
]);
foreach ($yabs['network_speed'] as $y) {
NetworkSpeed::create([
'id' => $yabs_id,
'server_id' => $request->server_id,
'location' => $y['location'],
'send' => $y['send'],
'send_type' => $y['send_type'],
'send_as_mbps' => $y['send_type_mbps'],
'receive' => $y['receive'],
'receive_type' => $y['receive_type'],
'receive_as_mbps' => $y['receive_type_mbps']
]);
if ($insert) {
Cache::forget('all_active_servers');//all servers cache
Cache::forget('non_active_servers');//all servers cache
Cache::forget('all_yabs');//Forget the all YABs cache
return response()->json(array('message' => 'Successfully added YABS'), 200);
}
$update_server = DB::table('servers')
->where('id', $request->server_id)
->update([
'ram' => $yabs['ram'],
'ram_type' => $yabs['ram_type'],
'ram_as_mb' => ($yabs['ram_type'] === 'GB') ? ($yabs['ram'] * 1024) : $yabs['ram'],
'disk' => $yabs['disk'],
'disk_type' => $yabs['disk_type'],
'disk_as_gb' => ($yabs['disk_type'] === 'TB') ? ($yabs['disk'] * 1024) : $yabs['disk'],
'cpu' => $yabs['cpu_cores'],
'has_yabs' => 1
]);
Cache::forget('all_active_servers');//all servers cache
Cache::forget('non_active_servers');//all servers cache
Cache::forget('all_yabs');//Forget the all YABs cache
if ($yabs_insert) {
return response()->json(array('result' => 'success', 'yabs_id' => $yabs_id), 200);
}
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
return response()->json(array('error' => 'Server error'), 500);
}
public function getAllYabs()

View File

@ -43,8 +43,7 @@ class DomainsController extends Controller
$domain_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(4, $domain_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(4, $domain_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
Domains::create([
'id' => $domain_id,

View File

@ -41,8 +41,7 @@ class MiscController extends Controller
$misc_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(5, $misc_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(5, $misc_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
Misc::create([
'id' => $misc_id,

View File

@ -57,8 +57,7 @@ class ResellerController extends Controller
$reseller_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(3, $reseller_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(3, $reseller_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
if (!is_null($request->dedicated_ip)) {
IPs::insertIP($reseller_id, $request->dedicated_ip);

View File

@ -47,8 +47,7 @@ class SeedBoxesController extends Controller
$seedbox_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(6, $seedbox_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(6, $seedbox_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
Labels::deleteLabelsAssignedTo($seedbox_id);
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $seedbox_id);

View File

@ -75,10 +75,7 @@ class ServerController extends Controller
$server_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(1, $server_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(1, $server_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
if (!is_null($request->ip1)) {
IPs::insertIP($server_id, $request->ip1);

View File

@ -52,8 +52,7 @@ class SharedController extends Controller
$shared_id = Str::random(8);
$pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->insertPricing(2, $shared_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$pricing->insertPricing(2, $shared_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
Labels::deleteLabelsAssignedTo($shared_id);
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $shared_id);

View File

@ -109,8 +109,9 @@ class Pricing extends Model
DB::table('pricings')->where('service_id', '=', $id)->delete();
}
public function insertPricing(int $type, string $service_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1)
public function insertPricing(int $type, string $service_id, string $currency, float $price, int $term, string $next_due_date, int $is_active = 1)
{
$as_usd = $this->convertToUSD($price, $currency);
return self::create([
'service_type' => $type,
'service_id' => $service_id,
@ -120,7 +121,7 @@ class Pricing extends Model
'as_usd' => $as_usd,
'usd_per_month' => $this->costAsPerMonth($as_usd, $term),
'next_due_date' => $next_due_date,
'active' => ($is_active) ? 1 : 0
'active' => $is_active
]);
}

View File

@ -2,10 +2,14 @@
namespace App\Models;
use DateTime;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class Yabs extends Model
{
@ -101,4 +105,219 @@ class Yabs extends Model
);
}
public static function speedAsMbps(string $string): float
{
$data = explode(" ", $string);
if ($data[0] === 'busy') {
return 0;
}
if ($data[1] === "Gbits/sec") {
return $data[0] * 1000;
} else if ($data[1] === "Mbits/sec") {
return $data[0];
} else {//Kbps
return $data[0] / 1000;
}
}
public static function speedType(string $string): string
{
$data = explode(" ", $string);
if ($data[0] === 'busy') {
return "MBps";
}
if ($data[1] === "Gbits/sec") {
return "GBps";
} else if ($data[1] === "Mbits/sec") {
return "MBps";
} else {//Kbps
return "KBps";
}
}
public static function speedAsFloat(string $string): float
{
$data = explode(" ", $string);
if ($data[0] === 'busy') {
return 0;
}
return (float)$data[0];
}
public static function formatRunTime(string $date): string
{
return DateTime::createFromFormat('Ymd-His', $date)->format('Y-m-d H:i:s');
}
public static function gb5IdFromURL(string $url): int
{
return str_replace("https://browser.geekbench.com/v5/cpu/", "", $url);
}
public static function KBstoMBs(int $kbs): float
{
return $kbs / 1000;
}
public static function insertFromJson($data, string $server_id)
{
$data = (object)$data;
try {
$date_ran = self::formatRunTime($data->time);
$version = $data['version'];
$has_ipv4 = $data['net']['ipv4'];
$has_ipv6 = $data['net']['ipv6'];
//Os
$arch = $data['os']['arch'];
$distro = $data['os']['distro'];
$kernel = $data['os']['kernel'];
$uptime = $data['os']['uptime'];
//Cpu
$model = $data['cpu']['model'];
$cores = $data['cpu']['cores'];
$freq = $data['cpu']['freq'];
$aes = $data['cpu']['aes'];
$virt = $data['cpu']['virt'];
//Ram Disk
$ram = $data['mem']['ram'];
$swap = $data['mem']['swap'];
$disk = $data['mem']['disk'];
if (isset($data['geekbench'][0]) && $data['geekbench'][0]['version'] === 5) {
$gb5_single = $data['geekbench'][0]['single'];
$gb5_multi = $data['geekbench'][0]['multi'];
$gb5_id = self::gb5IdFromURL($data['geekbench'][0]['url']);
} elseif (isset($data['geekbench'][1]) && $data['geekbench'][1]['version'] === 5) {
$gb5_single = $data['geekbench'][1]['single'];
$gb5_multi = $data['geekbench'][1]['multi'];
$gb5_id = self::gb5IdFromURL($data['geekbench'][1]['url']);
} else {
$gb5_single = $gb5_multi = $gb5_id = null;
}
$yabs_id = Str::random(8);
if ($ram > 10) {
$ram_f = ($ram / 1024 / 1024);
$ram_type = 'GB';
} else {
$ram_f = ($ram / 1024);
$ram_type = 'MB';
}
if ($disk > 10000) {
$disk_f = ($ram / 1024 / 1024);
$disk_type = 'TB';
} else {
$disk_f = ($ram / 1024);
$disk_type = 'GB';
}
self::create([
'id' => $yabs_id,
'server_id' => $server_id,
'has_ipv6' => $has_ipv6,
'aes' => $aes,
'vm' => $virt,
'distro' => $distro,
'kernel' => $kernel,
'uptime' => $uptime,
'cpu_model' => $model,
'cpu_cores' => $cores,
'cpu_freq' => (float)$freq,
'ram' => $ram_f,
'ram_type' => $ram_type,
'ram_mb' => ($ram / 1024),
'swap' => $swap / 1024,
'swap_mb' => ($swap / 1024),
'swap_type' => 'MB',
'disk' => $disk_f,
'disk_gb' => ($disk / 1024 / 1024),
'disk_type' => $disk_type,
'output_date' => $date_ran,
'gb5_single' => $gb5_single,
'gb5_multi' => $gb5_multi,
'gb5_id' => $gb5_id
]);
//Fio
foreach ($data['fio'] as $ds) {
if ($ds['bs'] === '4k') {
$d4k = ($ds['speed_rw'] > 1000000) ? ($ds['speed_rw'] / 1000) : $ds['speed_rw'];
$d4k_type = ($ds['speed_rw'] > 1000000) ? 'GB/s' : 'MB/s';
$d4k_mbps = self::KBstoMBs($ds['speed_rw']);
}
if ($ds['bs'] === '64k') {
$d64k = ($ds['speed_rw'] > 1000000) ? ($ds['speed_rw'] / 1000) : $ds['speed_rw'];
$d64k_type = ($ds['speed_rw'] > 1000000) ? 'GB/s' : 'MB/s';
$d64k_mbps = self::KBstoMBs($ds['speed_rw']);
}
if ($ds['bs'] === '512k') {
$d512k = ($ds['speed_rw'] > 1000000) ? ($ds['speed_rw'] / 1000) : $ds['speed_rw'];
$d512k_type = ($ds['speed_rw'] > 1000000) ? 'GB/s' : 'MB/s';
$d512k_mbps = self::KBstoMBs($ds['speed_rw']);
}
if ($ds['bs'] === '1m') {
$d1m = ($ds['speed_rw'] > 1000000) ? ($ds['speed_rw'] / 1000) : $ds['speed_rw'];
$d1m_type = ($ds['speed_rw'] > 1000000) ? 'GB/s' : 'MB/s';
$d1m_mbps = self::KBstoMBs($ds['speed_rw']);
}
}
DiskSpeed::create([
'id' => $yabs_id,
'server_id' => $server_id,
'd_4k' => $d4k,
'd_4k_type' => $d4k_type,
'd_4k_as_mbps' => $d4k_mbps,
'd_64k' => $d64k,
'd_64k_type' => $d64k_type,
'd_64k_as_mbps' => $d64k_mbps,
'd_512k' => $d512k,
'd_512k_type' => $d512k_type,
'd_512k_as_mbps' => $d512k_mbps,
'd_1m' => $d1m,
'd_1m_type' => $d1m_type,
'd_1m_as_mbps' => $d1m_mbps
]);
//Iperf
foreach ($data['iperf'] as $st) {
($has_ipv4) ? $match = 'IPv4' : $match = 'IPv6';
if ($st['mode'] === $match) {
if ($st['send'] !== "busy " || $st['recv'] !== "busy ") {
NetworkSpeed::create([
'id' => $yabs_id,
'server_id' => $server_id,
'location' => $st['loc'],
'send' => self::speedAsFloat($st['send']),
'send_type' => self::speedType($st['send']),
'send_as_mbps' => self::speedAsMbps($st['send']),
'receive' => self::speedAsFloat($st['recv']),
'receive_type' => self::speedType($st['recv']),
'receive_as_mbps' => self::speedAsMbps($st['recv'])
]);
}
}
}
//Update server
$update_server = DB::table('servers')
->where('id', $server_id)
->update([
'ram' => $ram_f,
'ram_type' => $ram_type,
'ram_as_mb' => ($ram / 1024),
'disk' => $disk_f,
'disk_as_gb' => ($disk / 1024 / 1024),
'disk_type' => $disk_type,
'cpu' => $cores,
'has_yabs' => 1
]);
} catch (Exception $e) {//Not valid JSON
return false;
}
return true;
}
}

View File

@ -170,7 +170,7 @@ class Process
public function yabsOutputAsJson(string $server_id, string $data_from_form): array
{
$allowed_versions = ['v2021-12-28', 'v2022-02-18', 'v2022-04-30', 'v2022-05-06', 'v2022-06-11'];
$allowed_versions = ['v2021-12-28', 'v2022-02-18', 'v2022-04-30', 'v2022-05-06', 'v2022-06-11', 'v2022-08-20'];
$file_name = date('Y') . '/' . date('m') . '/' . time() . '.txt';

View File

@ -1,6 +1,14 @@
@section('title')
{{$server_data->hostname}} {{'server'}}
@endsection
@section('scripts')
<script>
function showYabsCode() {
const el = document.querySelector('#yabs_code');
el.classList.remove("d-none");
}
</script>
@endsection
<x-app-layout>
<x-slot name="header">
{{ __('Server details') }}
@ -135,6 +143,9 @@
<x-edit-btn>
<x-slot name="route">{{ route('servers.edit', $server_data->id) }}</x-slot>
</x-edit-btn>
<a href="#" class="btn btn-light btn-sm mx-1" onclick="showYabsCode()">
Show code to add a YABS
</a>
</div>
<div class="col-12 col-lg-6">
@if($server_data->has_yabs)
@ -199,6 +210,7 @@
see Geekbench, disk and network speeds</p>
@endif
</div>
<p id="yabs_code" class="d-none pt-3"><code>curl -sL yabs.sh | bash -s -- -s "{{route('api.store-yabs', [$server_data->id, \Illuminate\Support\Facades\Auth::user()->api_token])}}"</code></p>
</div>
</x-card>
@if(Session::has('timer_version_footer') && Session::get('timer_version_footer') === 1)

View File

@ -74,6 +74,6 @@ Route::middleware('auth:api')->get('online/{hostname}', 'App\Http\Controllers\Ap
Route::middleware('auth:api')->get('dns/{domainName}/{type}', 'App\Http\Controllers\ApiController@getIpForDomain');
Route::middleware('auth:api')->post('yabs/', 'App\Http\Controllers\ApiController@storeYabs');
Route::middleware('throttle:4')->post('yabs/{server}/{key}', 'App\Http\Controllers\ApiController@storeYabs')->name('api.store-yabs');
Route::middleware('auth:api')->get('yabs/', 'App\Http\Controllers\ApiController@getAllYabs');
Route::middleware('auth:api')->get('yabs/{id}', 'App\Http\Controllers\ApiController@getYabs');