From: soufiane Date: Wed, 22 Nov 2023 10:27:43 +0000 (+0100) Subject: wait #6477 @1:30 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=a64e38188470fc234d118884b5c1aec0e6edb9ac;p=fluidbook-toolbox.git wait #6477 @1:30 --- diff --git a/app/Http/Controllers/Admin/Operations/ServerOperation.php b/app/Http/Controllers/Admin/Operations/ServerOperation.php index bec1a1783..34bc6ece6 100644 --- a/app/Http/Controllers/Admin/Operations/ServerOperation.php +++ b/app/Http/Controllers/Admin/Operations/ServerOperation.php @@ -15,6 +15,7 @@ trait ServerOperation { Route::post($segment . '/{id}/verifyconnection', $controller . '@run'); } + public function setup() { parent::setup(); $this->crud->setEditView('vendor.backpack.crud.edit-external-server'); @@ -25,9 +26,16 @@ trait ServerOperation 'password' => 'required|string|min:8', 'protocol' => 'required|string|max:255', 'username' => 'required|string|max:255', + 'host' => 'required|string|max:255', 'port' => 'nullable|numeric', ]; - $validator = Validator::make($request->all(), $validation); + $validator = Validator::make([ + 'password' => $request->password, + 'protocol' => $request->protocol, + 'username' => $request->username, + 'host' => $request->host, + 'port' => $request->port], $validation); + if ($validator->fails()) { throw new ValidationException($validator); @@ -35,13 +43,15 @@ trait ServerOperation $validator->validate(); - $result = FluidbookExternalInstallServer::verifyServerConnexion($id, $validator); + $result = FluidbookExternalInstallServer::verifyServerConnexion($id, $request->all()); if($result) { - Alert::add('success', __('La connexion a été établie avec succès'))->flash(); + //Alert::add('success', __('La connexion a été établie avec succès'))->flash(); + $data = ['success' => true, 'message' => __('La connexion a été établie avec succès')]; } else { - Alert::add('error', __('La connexion a échouée'))->flash(); + //Alert::add('error', __('La connexion a échouée'))->flash(); + $data = ['error' => true, 'message' => __('La connexion a échouée')]; } - die(); + return response()->json($data); } } diff --git a/app/Models/FluidbookExternalInstallServer.php b/app/Models/FluidbookExternalInstallServer.php index 95d457d21..f395fc606 100644 --- a/app/Models/FluidbookExternalInstallServer.php +++ b/app/Models/FluidbookExternalInstallServer.php @@ -92,16 +92,20 @@ class FluidbookExternalInstallServer extends ExternalServer public static function verifyServerConnexion($id, $data = []) { $server = self::find($id); - $protocol = $data->protocol ?? $server->protocol; - $usr = $data->username ?? $server->username; - $pwd = $data->password ?? $server->password; - $host = $data->host ?? $server->host; + $protocol = $data['protocol'] ?? $server->protocol; + $usr = $data['username'] ?? $server->username; + $pwd = $data['password'] ?? $server->password; + $host = $data['host'] ?? $server->host; if($protocol !== "hosting") { if(!$host) { throw new \Exception('Host missing'); } else { - $connection = ssh2_connect($host, 22); + try { + $connection = ssh2_connect($host, 22); + } catch (\Exception $e) { + + } try { self::$isValidConnexion = ssh2_auth_password($connection, $usr, $pwd); } catch (\Exception $e) { diff --git a/resources/views/vendor/backpack/crud/edit-external-server.blade.php b/resources/views/vendor/backpack/crud/edit-external-server.blade.php index 902c9e7e4..b62239e7a 100644 --- a/resources/views/vendor/backpack/crud/edit-external-server.blade.php +++ b/resources/views/vendor/backpack/crud/edit-external-server.blade.php @@ -15,6 +15,12 @@ //$("#saveActions").prepend("") $("#saveActions").prepend("Tester la connexion") + function removeBtn() { + setTimeout(() => { + $("#message").remove() + }, "3000"); + } + $(document).on("click", "#verifyconnection", function(e) { e.preventDefault(); const data = { @@ -30,13 +36,25 @@ url: '{{url('fluidbook-external-install-server/'.$entry->id)}}/verifyconnection', method: 'post', data: data, - success: function (response) { - console.log(response, 'ok') + success: function (data) { + let type = 'success' + if(data.error) { + type = 'error' + } + $('#saveActions').prepend('
'+data.message+'
') + removeBtn() }, + error: function(data) { + $('#saveActions').prepend('
{{ __('Une erreur est survenue') }}
') + removeBtn() + } }); }) }); + @endpush @include('cubist_back::when')