diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 16f3cac..b8290c6 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -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); + } + } diff --git a/app/Models/DNS.php b/app/Models/DNS.php index 70f7b63..6cb1df2 100644 --- a/app/Models/DNS.php +++ b/app/Models/DNS.php @@ -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']; diff --git a/app/Models/DiskSpeed.php b/app/Models/DiskSpeed.php index 1094c5a..8d93e8a 100644 --- a/app/Models/DiskSpeed.php +++ b/app/Models/DiskSpeed.php @@ -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']; diff --git a/app/Models/Domains.php b/app/Models/Domains.php index 72001eb..64d76c1 100644 --- a/app/Models/Domains.php +++ b/app/Models/Domains.php @@ -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']; diff --git a/app/Models/IPs.php b/app/Models/IPs.php index 66e7053..cf14220 100644 --- a/app/Models/IPs.php +++ b/app/Models/IPs.php @@ -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; diff --git a/app/Models/Labels.php b/app/Models/Labels.php index 02fd417..0d8104a 100644 --- a/app/Models/Labels.php +++ b/app/Models/Labels.php @@ -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) diff --git a/app/Models/LabelsAssigned.php b/app/Models/LabelsAssigned.php index d1e4b1d..72d88d4 100644 --- a/app/Models/LabelsAssigned.php +++ b/app/Models/LabelsAssigned.php @@ -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'); diff --git a/app/Models/Locations.php b/app/Models/Locations.php index 9956ebf..7f3b131 100644 --- a/app/Models/Locations.php +++ b/app/Models/Locations.php @@ -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 () { diff --git a/app/Models/Misc.php b/app/Models/Misc.php index 21115b0..bcd9459 100644 --- a/app/Models/Misc.php +++ b/app/Models/Misc.php @@ -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() diff --git a/app/Models/NetworkSpeed.php b/app/Models/NetworkSpeed.php index 9879517..565d13b 100644 --- a/app/Models/NetworkSpeed.php +++ b/app/Models/NetworkSpeed.php @@ -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']; diff --git a/app/Models/OS.php b/app/Models/OS.php index 9b2e7e5..506a80c 100644 --- a/app/Models/OS.php +++ b/app/Models/OS.php @@ -13,6 +13,8 @@ class OS extends Model protected $fillable = ['name']; + protected $keyType = 'string'; + protected $table = 'os'; public static function allOS(): array diff --git a/app/Models/Pricing.php b/app/Models/Pricing.php index 494cc23..32ea3ed 100644 --- a/app/Models/Pricing.php +++ b/app/Models/Pricing.php @@ -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 diff --git a/app/Models/Providers.php b/app/Models/Providers.php index e310f3a..00ee1d9 100644 --- a/app/Models/Providers.php +++ b/app/Models/Providers.php @@ -13,6 +13,8 @@ class Providers extends Model protected $fillable = ['name']; + protected $keyType = 'string'; + protected $table = 'providers'; public static function allProviders(): array diff --git a/app/Models/Reseller.php b/app/Models/Reseller.php index df43c73..ecb81c7 100644 --- a/app/Models/Reseller.php +++ b/app/Models/Reseller.php @@ -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; @@ -31,7 +33,7 @@ class Reseller extends Model ->with(['location', 'provider', 'price', 'ips', 'labels', 'labels.label'])->get(); }); } - + public function ips() { return $this->hasMany(IPs::class, 'service_id', 'id'); diff --git a/app/Models/SeedBoxes.php b/app/Models/SeedBoxes.php index 3b82126..9924c2d 100644 --- a/app/Models/SeedBoxes.php +++ b/app/Models/SeedBoxes.php @@ -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']; diff --git a/app/Models/Server.php b/app/Models/Server.php index 4bfd330..683679c 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -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', diff --git a/app/Models/Shared.php b/app/Models/Shared.php index 1cac7c1..b02ccb3 100644 --- a/app/Models/Shared.php +++ b/app/Models/Shared.php @@ -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; diff --git a/app/Models/Yabs.php b/app/Models/Yabs.php index 130a4ac..cb8c7d4 100644 --- a/app/Models/Yabs.php +++ b/app/Models/Yabs.php @@ -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']; diff --git a/app/Process.php b/app/Process.php index dc82dfb..3205798 100644 --- a/app/Process.php +++ b/app/Process.php @@ -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; diff --git a/database/migrations/2022_06_24_010658_alter_yabs_foreign_key.php b/database/migrations/2022_06_24_010658_alter_yabs_foreign_key.php index dc1ddbe..aaca036 100644 --- a/database/migrations/2022_06_24_010658_alter_yabs_foreign_key.php +++ b/database/migrations/2022_06_24_010658_alter_yabs_foreign_key.php @@ -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'); }); diff --git a/database/migrations/2022_06_24_023931_alter_yabs_foreign_key_delete.php b/database/migrations/2022_06_24_023931_alter_yabs_foreign_key_delete.php index c7e90d5..9fdc12c 100644 --- a/database/migrations/2022_06_24_023931_alter_yabs_foreign_key_delete.php +++ b/database/migrations/2022_06_24_023931_alter_yabs_foreign_key_delete.php @@ -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'); }); diff --git a/database/migrations/2022_07_20_011250_add_columns_to_yabs_table.php b/database/migrations/2022_07_20_011250_add_columns_to_yabs_table.php index c89e1c8..cc3dbfb 100644 --- a/database/migrations/2022_07_20_011250_add_columns_to_yabs_table.php +++ b/database/migrations/2022_07_20_011250_add_columns_to_yabs_table.php @@ -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']); }); } }; diff --git a/routes/api.php b/routes/api.php index 78df219..d5307fe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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');