Updated storeYabs API function
Updated storeYabs API function Now used to insert YABS from the POST request -s flag
This commit is contained in:
parent
c79f67916e
commit
badb640bd9
|
@ -15,6 +15,7 @@ use App\Models\Reseller;
|
||||||
use App\Models\SeedBoxes;
|
use App\Models\SeedBoxes;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Shared;
|
use App\Models\Shared;
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\Yabs;
|
use App\Models\Yabs;
|
||||||
use App\Process;
|
use App\Process;
|
||||||
use DataTables;
|
use DataTables;
|
||||||
|
@ -470,113 +471,23 @@ class ApiController extends Controller
|
||||||
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
|
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(
|
$r = User::where('api_token', $key)->first();
|
||||||
'server_id' => 'required|string|size:8',
|
if (!isset($r->id)) {
|
||||||
'yabs_output' => 'required|string',
|
return response()->json(['error' => 'Unauthenticated'], 401);
|
||||||
);
|
|
||||||
|
|
||||||
$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());
|
$insert = Yabs::insertFromJson($request, $server->id);
|
||||||
$process = new Process();
|
|
||||||
$yabs = $process->yabsOutputAsJson($request->server_id, $request->yabs_output);
|
|
||||||
//dd($yabs);
|
|
||||||
|
|
||||||
$yabs_id = Str::random(8);
|
if ($insert) {
|
||||||
|
Cache::forget('all_active_servers');//all servers cache
|
||||||
$yabs_insert = Yabs::create([
|
Cache::forget('non_active_servers');//all servers cache
|
||||||
'id' => $yabs_id,
|
Cache::forget('all_yabs');//Forget the all YABs cache
|
||||||
'server_id' => $request->server_id,
|
return response()->json(array('message' => 'Successfully added YABS'), 200);
|
||||||
'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')
|
return response()->json(array('error' => 'Server error'), 500);
|
||||||
->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()
|
public function getAllYabs()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user