Added more YABs value saving & YABs save txt setting

Added more YABs value saving (uptime, distro, kernel and swap memory)
Added setting for saving YABs output to txt yes/no
This commit is contained in:
cp6 2022-07-20 12:51:45 +10:00
parent b9aed757ad
commit 47bfcea4c8
8 changed files with 110 additions and 16 deletions

View File

@ -30,6 +30,7 @@ class SettingsController extends Controller
'show_server_value_location' => 'required|boolean',
'show_server_value_price' => 'required|boolean',
'show_server_value_yabs' => 'required|boolean',
'save_yabs_as_txt' => 'required|boolean',
'default_currency' => 'required',
'default_server_os' => 'required',
'due_soon_amount' => 'required|integer|between:0,12',
@ -49,6 +50,7 @@ class SettingsController extends Controller
'show_server_value_location' => $request->show_server_value_location,
'show_server_value_price' => $request->show_server_value_price,
'show_server_value_yabs' => $request->show_server_value_yabs,
'save_yabs_as_txt' => $request->save_yabs_as_txt,
'default_currency' => $request->default_currency,
'default_server_os' => $request->default_server_os,
'due_soon_amount' => $request->due_soon_amount,

View File

@ -52,12 +52,18 @@ class YabsController extends Controller
'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']
'gb5_id' => $yabs['GB5_id'],
'uptime' => $yabs['uptime'],
'distro' => $yabs['distro'],
'kernel' => $yabs['kernel']
]);
DiskSpeed::create([

View File

@ -36,6 +36,7 @@ class Settings extends Model
Session::put('show_server_value_yabs', $settings[0]->show_server_value_yabs ?? 0);
Session::put('show_server_value_provider', $settings[0]->show_server_value_provider ?? 0);
Session::put('show_server_value_location', $settings[0]->show_server_value_location ?? 0);
Session::put('save_yabs_as_txt', $settings[0]->save_yabs_as_txt ?? 0);
Session::put('default_currency', $settings[0]->default_currency ?? 'USD');
Session::put('default_server_os', $settings[0]->default_server_os ?? 1);
Session::put('due_soon_amount', $settings[0]->due_soon_amount ?? 6);

View File

@ -15,7 +15,7 @@ class Yabs extends Model
protected $table = 'yabs';
protected $fillable = ['id', 'server_id', 'has_ipv6', 'aes', 'vm', 'output_date', 'cpu_cores', 'cpu_freq', 'cpu_model', 'ram', 'ram_type', 'ram_mb', 'disk', 'disk_type', 'disk_gb', 'gb5_single', 'gb5_multi', 'gb5_id', '4k', '4k_type', '4k_as_mbps', '64k', '64k_type', '64k_as_mbps', '512k', '512k_type', '512k_as_mbps', '1m', '1m_type', '1m_as_mbps', 'location', 'send', 'send_type', 'send_as_mbps', 'receive', 'receive_type', 'receive_as_mbps'];
protected $fillable = ['id', 'server_id', 'has_ipv6', 'aes', 'vm', 'output_date', 'cpu_cores', 'cpu_freq', 'cpu_model', 'ram', 'ram_type', 'ram_mb', 'disk', 'disk_type', 'disk_gb', 'gb5_single', 'gb5_multi', 'gb5_id', '4k', '4k_type', '4k_as_mbps', '64k', '64k_type', '64k_as_mbps', '512k', '512k_type', '512k_as_mbps', '1m', '1m_type', '1m_as_mbps', 'location', 'send', 'send_type', 'send_as_mbps', 'receive', 'receive_type', 'receive_as_mbps', 'uptime', 'distro', 'kernel', 'swap', 'swap_type', 'swap_mb'];
public static function yabs(string $yabs_id)
{
@ -54,14 +54,17 @@ class Yabs extends Model
foreach ($data->network_speed as $ns) {
$speed_tests[] = array(
'location' => $ns->location,
'send' => $ns->send.' '.$ns->send_type,
'receive' => $ns->receive.' '.$ns->receive_type,
'send' => $ns->send . ' ' . $ns->send_type,
'receive' => $ns->receive . ' ' . $ns->receive_type,
);
}
return array(
'date_time' => $data->output_date,
'location' => $data->server->location->name,
'provider' => $data->server->provider->name,
'uptime' => $data->uptime,
'distro' => $data->distro,
'kernel' => $data->kernel,
'cpu' => array(
'cores' => $data->cpu_cores,
'speed_mhz' => $data->cpu_freq,
@ -72,17 +75,21 @@ class Yabs extends Model
'GB5_multi' => $data->gb5_multi,
),
'ram' => array(
'amount' => $data->ram.' '.$data->ram_type,
'amount' => $data->ram . ' ' . $data->ram_type,
'mb' => $data->ram_mb,
'swap' => array(
'amount' => $data->swap ?? null . ' ' . $data->swap_type ?? null,
'mb' => $data->swap_mb ?? null,
),
),
'disk' => array(
'amount' => $data->disk.' '.$data->disk_type,
'amount' => $data->disk . ' ' . $data->disk_type,
'gb' => $data->disk_gb,
'speed_tests' => array(
'4k' => $data->disk_speed->d_4k.' '.$data->disk_speed->d_4k_type,
'64k' => $data->disk_speed->d_64k.' '.$data->disk_speed->d_64k_type,
'512k' => $data->disk_speed->d_512k.' '.$data->disk_speed->d_512k_type,
'1m' => $data->disk_speed->d_1m.' '.$data->disk_speed->d_1m_type,
'4k' => $data->disk_speed->d_4k . ' ' . $data->disk_speed->d_4k_type,
'64k' => $data->disk_speed->d_64k . ' ' . $data->disk_speed->d_64k_type,
'512k' => $data->disk_speed->d_512k . ' ' . $data->disk_speed->d_512k_type,
'1m' => $data->disk_speed->d_1m . ' ' . $data->disk_speed->d_1m_type,
),
),
'network' => array(

View File

@ -3,6 +3,7 @@
namespace App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
class Process
@ -169,22 +170,24 @@ class Process
public function yabsOutputAsJson(string $server_id, string $data_from_form): array
{
$file_name = 'tempYabs.txt';
$allowed_versions = ['v2021-12-28', 'v2022-02-18', 'v2022-04-30', 'v2022-05-06', 'v2022-06-11'];
$file_name = date('Y') . '/' . date('m') . '/' . time() . '.txt';
Storage::disk('local')->put($file_name, $data_from_form);
$file = Storage::disk('local')->get($file_name);
if ($file) {
$array = explode("\n", $file);
if (!Session::get('save_yabs_as_txt')) {//Check if we want YABs txt to stay
Storage::disk('local')->delete($file_name);//Delete file
}
} else {
return array('error_id' => 10, 'error_message' => 'Issue writing/reading txt file');
}
//dd($array);
//dd($array);//Good for debugging the lines
if (count($array) < 46) {
return array('error_id' => 9, 'error_message' => 'Less than 46 lines');
@ -213,6 +216,9 @@ class Process
$io_6 = explode(' ', preg_replace('!\s+!', ' ', $array[33]));
(str_contains($array[13], 'Enabled')) ? $aes_ni = true : $aes_ni = false;
(str_contains($array[14], 'Enabled')) ? $vm_amd_v = true : $vm_amd_v = false;
$uptime = str_replace(["Uptime : ", "\r"], '', $array[10]);
$distro = str_replace(["Distro : ", "\r"], '', $array[18]);
$kernel = str_replace(["Kernel : ", "\r"], '', $array[19]);
} else {
$cpu = $this->trimRemoveR(str_replace(':', '', strstr($array[10], ': ')));
$cpu_spec = explode(' ', strstr($array[11], ': '));//: 2 @ 3792.872 MHz
@ -304,7 +310,7 @@ class Process
$gb_s = 60;
$gb_m = 61;
$gb_url = 62;
}elseif ($array[59] === "Geekbench 5 Benchmark Test:\r") {
} elseif ($array[59] === "Geekbench 5 Benchmark Test:\r") {
//HAS ipv6
//Has full ipv4 & ipv6 network speed testing
$has_ipv6 = true;
@ -397,7 +403,10 @@ class Process
'vm' => $vm_amd_v,
'GB5_single' => $geekbench_single,
'GB5_mult' => $geekbench_multi,
'GB5_id' => $gb5_id
'GB5_id' => $gb5_id,
'uptime' => $uptime ?? null,
'distro' => $distro ?? null,
'kernel' => $kernel ?? null,
];
$output['disk_speed'] = $disk_test_arr;

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up()
{
Schema::table('yabs', function (Blueprint $table) {
$table->string('uptime')->nullable()->default(null)->after('gb5_id');
$table->string('distro')->nullable()->default(null)->after('gb5_id');
$table->string('kernel')->nullable()->default(null)->after('gb5_id');
$table->float('swap')->nullable()->default(null)->after('ram_mb');
$table->char('swap_type', 2)->nullable()->default(null)->after('ram_mb');
$table->float('swap_mb')->nullable()->default(null)->after('ram_mb');
});
}
public function down()
{
Schema::table('yabs', function (Blueprint $table) {
$table->dropColumn('uptime');
$table->dropColumn('distro');
$table->dropColumn('kernel');
$table->dropColumn('swap');
$table->dropColumn('swap_type', 2);
$table->dropColumn('swap_mb');
});
}
};

View File

@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->boolean('save_yabs_as_txt')->default(false)->after('show_server_value_yabs');
});
}
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('save_yabs_as_txt');
});
}
};

View File

@ -107,6 +107,22 @@
</x-currency-select>
</div>
</div>
<div class="row mt-3">
<div class="col-12 col-md-6 mb-3">
<div class="input-group">
<div class="input-group-prepend"><span
class="input-group-text">Save YABs input to txt</span></div>
<select class="form-control" name="save_yabs_as_txt">
<option value="1" {{ ($setting[0]->save_yabs_as_txt === 1) ? 'selected' : '' }}>
Yes
</option>
<option value="0" {{ ($setting[0]->save_yabs_as_txt === 0) ? 'selected' : '' }}>
No
</option>
</select>
</div>
</div>
</div>
<p>Only if <i>Show servers to public</i> is <b>YES</b> do these apply:</p>
<div class="row mt-3">
<div class="col-12 col-md-6 mb-3">