Merge branch 'Development' of https://github.com/cp6/my-idlers into Development

This commit is contained in:
cp6 2022-08-30 23:37:21 +10:00
commit f36d73c04d
23 changed files with 196 additions and 27 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\DiskSpeed;
use App\Models\Domains;
use App\Models\IPs;
use App\Models\Labels;
@ -14,6 +15,8 @@ use App\Models\Reseller;
use App\Models\SeedBoxes;
use App\Models\Server;
use App\Models\Shared;
use App\Models\Yabs;
use App\Process;
use DataTables;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
@ -467,4 +470,125 @@ class ApiController extends Controller
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
}
public function storeYabs(Request $request)
{
$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);
}
//dd($request->all());
$process = new Process();
$yabs = $process->yabsOutputAsJson($request->server_id, $request->yabs_output);
//dd($yabs);
$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']
]);
}
$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);
}
public function getAllYabs()
{
$yabs = Yabs::allYabs()->toJson(JSON_PRETTY_PRINT);
return response($yabs, 200);
}
protected function getYabs($id)
{
$yabs = Yabs::yabs($id)->toJson(JSON_PRETTY_PRINT);
return response($yabs, 200);
}
}

View File

@ -13,6 +13,8 @@ class DNS extends Model
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = ['id', 'service_id', 'hostname', 'dns_type', 'address', 'server_id', 'domain_id'];
public static $dns_types = ['A', 'AAAA', 'DNAME', 'MX', 'NS', 'SOA', 'TXT', 'URI'];

View File

@ -11,6 +11,8 @@ class DiskSpeed extends Model
public $incrementing = false;
protected $keyType = 'string';
protected $table = 'disk_speed';
protected $fillable = ['id', 'server_id', 'd_4k', 'd_4k_type', 'd_4k_as_mbps', 'd_64k', 'd_64k_type', 'd_64k_as_mbps', 'd_512k', 'd_512k_type', 'd_512k_as_mbps', 'd_1m', 'd_1m_type', 'd_1m_as_mbps'];

View File

@ -15,6 +15,8 @@ class Domains extends Model
protected $table = 'domains';
protected $keyType = 'string';
protected $fillable = ['id', 'domain', 'extension', 'ns1', 'ns2', 'ns3', 'price', 'currency', 'payment_term', 'owned_since', 'provider_id', 'next_due_date'];

View File

@ -14,6 +14,8 @@ class IPs extends Model
public $table = 'ips';
protected $keyType = 'string';
protected $fillable = ['id', 'active', 'service_id', 'address', 'is_ipv4'];
public $incrementing = false;

View File

@ -15,6 +15,8 @@ class Labels extends Model
protected $table = 'labels';
protected $keyType = 'string';
protected $fillable = ['id', 'label', 'server_id', 'server_id_2', 'domain_id', 'domain_id_2', 'shared_id', 'shared_id_2'];
public static function deleteLabelsAssignedTo($service_id)

View File

@ -15,6 +15,8 @@ class LabelsAssigned extends Model
protected $fillable = ['label_id', 'service_id'];
protected $keyType = 'string';
public function label()
{
return $this->hasOne(Labels::class, 'id', 'label_id');

View File

@ -15,6 +15,8 @@ class Locations extends Model
protected $table = 'locations';
protected $keyType = 'string';
public static function allLocations(): array
{
return Cache::remember("locations", now()->addMonth(1), function () {

View File

@ -14,6 +14,8 @@ class Misc extends Model
protected $table = 'misc_services';
protected $keyType = 'string';
protected $fillable = ['id', 'name', 'owned_since'];
public static function allMisc()

View File

@ -11,6 +11,8 @@ class NetworkSpeed extends Model
public $incrementing = false;
protected $keyType = 'string';
protected $table = 'network_speed';
protected $fillable = ['id', 'server_id', 'location', 'send', 'send_type', 'send_as_mbps', 'receive', 'receive_type', 'receive_as_mbps', 'created_at', 'updated_at'];

View File

@ -13,6 +13,8 @@ class OS extends Model
protected $fillable = ['name'];
protected $keyType = 'string';
protected $table = 'os';
public static function allOS(): array

View File

@ -13,6 +13,12 @@ class Pricing extends Model
{
use HasFactory;
protected $table = 'pricings';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = ['service_id', 'service_type', 'currency', 'price', 'term', 'as_usd', 'usd_per_month', 'next_due_date'];
private static function refreshRates(): object

View File

@ -13,6 +13,8 @@ class Providers extends Model
protected $fillable = ['name'];
protected $keyType = 'string';
protected $table = 'providers';
public static function allProviders(): array

View File

@ -13,6 +13,8 @@ class Reseller extends Model
protected $table = 'reseller_hosting';
protected $keyType = 'string';
protected $fillable = ['id', 'active', 'accounts', 'main_domain', 'has_dedicated_ip', 'ip', 'reseller_type', 'provider_id', 'location_id', 'bandwidth', 'disk', 'disk_type', 'disk_as_gb', 'domains_limit', 'subdomains_limit', 'ftp_limit', 'email_limit', 'db_limit', 'was_promo', 'owned_since'];
public $incrementing = false;

View File

@ -13,6 +13,8 @@ class SeedBoxes extends Model
protected $table = 'seedboxes';
protected $keyType = 'string';
public $incrementing = false;
protected $fillable = ['id', 'active', 'title', 'hostname', 'seed_box_type', 'provider_id', 'location_id', 'bandwidth', 'port_speed', 'disk', 'disk_type', 'disk_as_gb', 'was_promo', 'owned_since'];

View File

@ -12,6 +12,10 @@ class Server extends Model
{
use HasFactory;
protected $table = 'servers';
protected $keyType = 'string';
public $incrementing = false;
protected $fillable = ['id', 'hostname', 'ipv4', 'ipv6', 'server_type', 'os_id', 'location_id', 'provider_id',

View File

@ -13,6 +13,8 @@ class Shared extends Model
public $table = 'shared_hosting';
protected $keyType = 'string';
protected $fillable = ['id', 'active', 'main_domain', 'has_dedicated_ip', 'ip', 'shared_type', 'provider_id', 'location_id', 'bandwidth', 'disk', 'disk_type', 'disk_as_gb', 'domains_limit', 'subdomains_limit', 'ftp_limit', 'email_limit', 'db_limit', 'was_promo', 'owned_since'];
public $incrementing = false;

View File

@ -13,6 +13,8 @@ class Yabs extends Model
public $incrementing = false;
protected $keyType = 'string';
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', 'uptime', 'distro', 'kernel', 'swap', 'swap_type', 'swap_mb'];

View File

@ -193,8 +193,8 @@ class Process
return array('error_id' => 9, 'error_message' => 'Less than 46 lines');
}
if (str_contains($array[0], "# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #\r")) {
if ($array[1] !== "# Yet-Another-Bench-Script #\r") {
if (str_contains($array[0], "# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #")) {
if (!str_contains($array[1],"# Yet-Another-Bench-Script #")) {
return array('error_id' => 8, 'error_message' => 'Didnt copy output correctly');
}
@ -261,7 +261,7 @@ class Process
if (isset($array[40])) {
if ($version_array[1] === 'v2022-05-06' || $version_array[1] === 'v2022-06-11') {
if ($array[43] === "Geekbench 5 Benchmark Test:\r") {
if (str_contains($array[43], "Geekbench 5 Benchmark Test:")) {
//No ipv6
//Has short ipv4 network speed testing (-r)
$has_ipv6 = false;
@ -270,11 +270,11 @@ class Process
$gb_s = 47;
$gb_m = 48;
$gb_url = 49;
} elseif ($array[45] === "Geekbench 4 Benchmark Test:\r") {
} elseif (str_contains($array[45], "Geekbench 4 Benchmark Test:")) {
return array('error_id' => 6, 'error_message' => 'GeekBench 5 only allowed');
} elseif ($array[45] === "Geekbench 5 test failed. Run manually to determine cause.\r") {
return array('error_id' => 7, 'error_message' => 'GeekBench test failed');
} elseif ($array[46] === "Geekbench 5 Benchmark Test:\r") {
} elseif (str_contains($array[46], "Geekbench 5 Benchmark Test:")) {
//No ipv6
//Has full ipv4 network speed testing
$has_ipv6 = false;
@ -283,7 +283,7 @@ class Process
$gb_s = 44;
$gb_m = 45;
$gb_url = 46;
} elseif ($array[47] === "Geekbench 5 Benchmark Test:\r") {
} elseif (str_contains($array[47], "Geekbench 5 Benchmark Test:")) {
//No ipv6
//Has full ipv4 network speed testing
$has_ipv6 = false;
@ -292,7 +292,7 @@ class Process
$gb_s = 51;
$gb_m = 52;
$gb_url = 53;
} elseif ($array[43] === "iperf3 Network Speed Tests (IPv6):\r") {
} elseif (str_contains($array[43], "iperf3 Network Speed Tests (IPv6):")) {
//HAS ipv6
//Has short ipv4 & ipv6 network speed testing
$has_ipv6 = true;
@ -301,7 +301,7 @@ class Process
$gb_s = 55;
$gb_m = 56;
$gb_url = 57;
} elseif ($array[56] === "Geekbench 5 Benchmark Test:\r") {
} elseif (str_contains($array[56], "Geekbench 5 Benchmark Test:")) {
//HAS ipv6
//Has full ipv4 & ipv6 network speed testing
$has_ipv6 = true;
@ -310,7 +310,7 @@ class Process
$gb_s = 60;
$gb_m = 61;
$gb_url = 62;
} elseif ($array[59] === "Geekbench 5 Benchmark Test:\r") {
} elseif (str_contains($array[59], "Geekbench 5 Benchmark Test:")) {
//HAS ipv6
//Has full ipv4 & ipv6 network speed testing
$has_ipv6 = true;
@ -323,7 +323,7 @@ class Process
return array('error_id' => 5, 'error_message' => 'Not correct YABs command output');
}
} else {
if ($array[45] === "Geekbench 5 Benchmark Test:\r") {
if (str_contains($array[45], "Geekbench 5 Benchmark Test:")) {
//No ipv6
//Has short ipv4 network speed testing (-r)
$has_ipv6 = false;
@ -332,11 +332,11 @@ class Process
$gb_s = 49;
$gb_m = 50;
$gb_url = 51;
} elseif ($array[45] === "Geekbench 4 Benchmark Test:\r") {
} elseif (str_contains($array[45], "Geekbench 4 Benchmark Test:")) {
return array('error_id' => 6, 'error_message' => 'GeekBench 5 only allowed');
} elseif ($array[45] === "Geekbench 5 test failed. Run manually to determine cause.\r") {
} elseif (str_contains($array[45], "Geekbench 5 test failed. Run manually to determine cause.")) {
return array('error_id' => 7, 'error_message' => 'GeekBench test failed');
} elseif ($array[40] === "Geekbench 5 Benchmark Test:\r") {
} elseif (str_contains($array[40], "Geekbench 5 Benchmark Test:")) {
//No ipv6
//Has full ipv4 network speed testing
$has_ipv6 = false;
@ -345,7 +345,7 @@ class Process
$gb_s = 44;
$gb_m = 45;
$gb_url = 46;
} elseif ($array[40] === "iperf3 Network Speed Tests (IPv6):\r") {
} elseif (str_contains($array[40], "iperf3 Network Speed Tests (IPv6):")) {
//HAS ipv6
//Has short ipv4 & ipv6 network speed testing
$has_ipv6 = true;
@ -354,7 +354,7 @@ class Process
$gb_s = 52;
$gb_m = 53;
$gb_url = 54;
} elseif ($array[56] === "Geekbench 5 Benchmark Test:\r") {
} elseif (str_contains($array[56], "Geekbench 5 Benchmark Test:")) {
//HAS ipv6
//Has full ipv4 & ipv6 network speed testing
$has_ipv6 = true;

View File

@ -2,6 +2,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
@ -9,13 +10,17 @@ return new class extends Migration
public function up()
{
Schema::table('disk_speed', function (Blueprint $table) {
$table->dropForeign('ds_fk_yabs');
if (env('DB_CONNECTION') !== 'sqlite') {
$table->dropForeign('ds_fk_yabs');
}
$table->foreign('id', 'ds_fk_yabs')->references('id')->on('yabs')->onDelete('cascade');
});
Schema::table('network_speed', function (Blueprint $table) {
$table->dropForeign('ns_fk_yabs');
if (env('DB_CONNECTION') !== 'sqlite') {
$table->dropForeign('ns_fk_yabs');
}
$table->foreign('id', 'ns_fk_yabs')->references('id')->on('yabs')->onDelete('cascade');
});

View File

@ -4,12 +4,13 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class extends Migration {
public function up()
{
Schema::table('yabs', function (Blueprint $table) {
$table->dropForeign('yabs_fk_servers');
if (env('DB_CONNECTION') !== 'sqlite') {
$table->dropForeign('yabs_fk_servers');
}
$table->foreign('server_id', 'yabs_fk_servers')->references('id')->on('servers')->onDelete('cascade');
});

View File

@ -20,12 +20,7 @@ return new class extends Migration {
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');
$table->dropColumn(['uptime', 'distro', 'kernel', 'swap', 'swap_type', 'swap_mb']);
});
}
};

View File

@ -73,3 +73,7 @@ Route::middleware('auth:api')->get('shared/{id}', 'App\Http\Controllers\ApiContr
Route::middleware('auth:api')->get('online/{hostname}', 'App\Http\Controllers\ApiController@checkHostIsUp');
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('auth:api')->get('yabs/', 'App\Http\Controllers\ApiController@getAllYabs');
Route::middleware('auth:api')->get('yabs/{id}', 'App\Http\Controllers\ApiController@getYabs');