diff --git a/app/Http/Controllers/frontend/ServiceController.php b/app/Http/Controllers/frontend/ServiceController.php index ec79a69..aa8e6d2 100644 --- a/app/Http/Controllers/frontend/ServiceController.php +++ b/app/Http/Controllers/frontend/ServiceController.php @@ -739,6 +739,61 @@ class ServiceController extends Controller } } + /** + * Change public IP for VM (request-based), logs request. + */ + public function changeIP(Request $request) + { + try { + $user = customer(); + if (!$user) { + return response()->json([ + 'error' => true, + 'message' => __('Chưa đăng nhập. Vui lòng đăng nhập để sử dụng tính năng này.'), + ], 401); + } + + $validated = FacadesValidator::make($request->all(), [ + 'product_id' => 'required|string|max:255', + 'ip' => ['required', 'string', 'regex:/^(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})$/'], + ]); + + if ($validated->fails()) { + return response()->json([ + 'error' => true, + 'message' => __('Dữ liệu không hợp lệ'), + 'errors' => $validated->errors(), + ], 422); + } + + $productId = $this->sanitizeInput($request->product_id); + $desiredIp = $this->sanitizeInput($request->ip); + + // Persist an audit log entry for ops to handle allocation if needed + Log::info('Khách yêu cầu đổi IP', [ + 'user_id' => $user->id, + 'product_vmware_id' => $productId, + 'desired_ip' => $desiredIp, + ]); + + // Here you could enqueue a Job to validate/assign IP from pool + // For now, return accepted message + return response()->json([ + 'error' => false, + 'message' => __('Yêu cầu đổi IP đã được ghi nhận, chúng tôi sẽ xử lý trong thời gian sớm nhất.'), + ]); + } catch (\Exception $e) { + Log::error('Lỗi changeIP', [ + 'user_id' => customer()?->id, + 'error' => $e->getMessage(), + ]); + return response()->json([ + 'error' => true, + 'message' => __('Có lỗi xảy ra khi đổi IP'), + ], 500); + } + } + /** * Secure remove snapshot using session authentication - NO BEARER TOKEN */ diff --git a/public/css/app.css b/public/css/app.css index 5362117..fe1a8e7 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -6153,6 +6153,13 @@ } } } + .hover\:border-blue-300 { + &:hover { + @media (hover: hover) { + border-color: var(--color-blue-300); + } + } + } .hover\:border-gray-300 { &:hover { @media (hover: hover) { diff --git a/resources/views/frontend/service/partials/change-ip-modal.blade.php b/resources/views/frontend/service/partials/change-ip-modal.blade.php new file mode 100644 index 0000000..8426877 --- /dev/null +++ b/resources/views/frontend/service/partials/change-ip-modal.blade.php @@ -0,0 +1,30 @@ +@props(['invoice']) + + +
+
+ {{ __('Đổi địa chỉ IP') }} + {{ __('Nhập địa chỉ IP mới mà bạn muốn sử dụng.') }} +
+ +
+ @csrf + + + + {{ __('Địa chỉ IP mới') }} + + {{ __('Vui lòng nhập IPv4 hợp lệ. Yêu cầu sẽ được xử lý nếu khả dụng.') }} + + +
+ + {{ __('Hủy') }} + + {{ __('Đồng ý') }} +
+
+
+
+ + diff --git a/resources/views/frontend/service/partials/control-buttons/change-ip-button.blade.php b/resources/views/frontend/service/partials/control-buttons/change-ip-button.blade.php new file mode 100644 index 0000000..448ec56 --- /dev/null +++ b/resources/views/frontend/service/partials/control-buttons/change-ip-button.blade.php @@ -0,0 +1,15 @@ +{{-- Change IP Trigger --}} + +
+
+
+ + + +
+ {{ __('Đổi IP') }} +
+
+
+ + diff --git a/resources/views/frontend/service/partials/vm-control-panel.blade.php b/resources/views/frontend/service/partials/vm-control-panel.blade.php index 156d6ab..109884a 100644 --- a/resources/views/frontend/service/partials/vm-control-panel.blade.php +++ b/resources/views/frontend/service/partials/vm-control-panel.blade.php @@ -44,6 +44,7 @@ @if ($isPoweredOn) @include('frontend.service.partials.control-buttons.snapshot-button') @include('frontend.service.partials.control-buttons.reset-password-button') + @include('frontend.service.partials.control-buttons.change-ip-button') @endif @@ -60,6 +61,7 @@ 'invoice' => $invoice, 'isWindows' => $isWindows, ]) + @include('frontend.service.partials.change-ip-modal', ['invoice' => $invoice]) @include('frontend.service.partials.change-remote-port-modal', ['invoice' => $invoice]) @endif diff --git a/routes/web.php b/routes/web.php index fb1e11a..78bac51 100644 --- a/routes/web.php +++ b/routes/web.php @@ -521,6 +521,7 @@ Route::middleware("CustomerLoginCheck")->group(function () { Route::post('secure/reinstall-vm', 'reinstallVM')->name('service.reinstall.vm'); Route::post('secure/reset-vm-password', 'resetVMPassword')->name('service.reset.vm.password'); Route::post('secure/change-remote-port', 'changeRemotePort')->name('service.change.remote.port'); + Route::post('secure/change-ip', 'changeIP')->name('service.change.ip'); Route::post('secure/start-vm', 'startVM')->name('service.start.vm'); Route::post('secure/stop-vm', 'stopVM')->name('service.stop.vm'); Route::post('secure/reboot-vm', 'rebootVM')->name('service.reboot.vm');