use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
use \Cubist\Backpack\Http\Controllers\Operations\ReviseOperation;
-
+
/*
--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Admin\Operations;
+
+use App\Models\FluidbookExternalInstallServer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Validation\ValidationException;
+use Prologue\Alerts\Facades\Alert;
+
+trait ServerOperation
+{
+ protected function setupEditRoutes($segment, $routeName, $controller)
+ {
+ Route::post($segment . '/{id}/verifyconnection', $controller . '@run');
+ }
+ public function setup() {
+ parent::setup();
+ $this->crud->setEditView('vendor.backpack.crud.edit-external-server');
+ }
+
+ protected function run(Request $request, $id) {
+ $validation = [
+ 'password' => 'required|string|min:8',
+ 'protocol' => 'required|string|max:255',
+ 'username' => 'required|string|max:255',
+ 'port' => 'nullable|numeric',
+ ];
+ $validator = Validator::make($request->all(), $validation);
+
+ if ($validator->fails()) {
+ throw new ValidationException($validator);
+ }
+
+ $validator->validate();
+
+ $result = FluidbookExternalInstallServer::verifyServerConnexion($id, $validator);
+ if($result) {
+ Alert::add('success', __('La connexion a été établie avec succès'))->flash();
+ } else {
+ Alert::add('error', __('La connexion a échouée'))->flash();
+ }
+
+ die();
+ }
+}
namespace App\Models;
+use App\Http\Controllers\Admin\Operations\ServerOperation;
use Cubist\Backpack\Magic\Fields\Checkbox;
use Cubist\Backpack\Magic\Fields\Table;
use Cubist\Backpack\Magic\Fields\Text;
'singular' => 'serveur',
'plural' => 'serveurs'];
+ protected static $isValidConnexion = false;
+
protected static $_permissionBase = 'fluidbook-external-install-server';
+ protected $_operations = [ServerOperation::class];
protected static function _getOneServer($server)
{
}
}
+ 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;
+
+ if($protocol !== "hosting") {
+ if(!$host) {
+ throw new \Exception('Host missing');
+ } else {
+ $connection = ssh2_connect($host, 22);
+ try {
+ self::$isValidConnexion = ssh2_auth_password($connection, $usr, $pwd);
+ } catch (\Exception $e) {
+
+ }
+ ssh2_disconnect($connection);
+ }
+ } else {
+ self::$isValidConnexion = file_exists("/mnt/hosting/status");
+ }
+
+ return self::$isValidConnexion;
+ }
+
}
--- /dev/null
+@push('crud_fields_scripts')
+ <script>
+ jQuery(document).ready(function ($) {
+
+ // When clicking on a locale link in the dropdown menu, it doesn't preserve
+ // the current tab because this is stored in the hash and managed by JS.
+ // To overcome this, we catch the locale links and append the hash to them...
+ $(document).on('click', '.dropdown-menu a[href*="?locale="]', function(event) {
+ event.preventDefault();
+ window.location.href = $(this).attr('href') + document.location.hash;
+ });
+
+ console.log('{{$entry->id}}')
+
+ //$("#saveActions").prepend("<button id='verifyconnection' class='btn btn-primary mr-3'>Tester la connexion</button>")
+ $("#saveActions").prepend("<a id='verifyconnection' class='btn btn-primary mr-3' href='verifyconnection'>Tester la connexion</a>")
+
+ $(document).on("click", "#verifyconnection", function(e) {
+ e.preventDefault();
+ const data = {
+ id: {{$entry->id}},
+ protocol: $('[name=protocol]').val(),
+ host: $('[name=host]').val(),
+ port: $('[name=port]').val(),
+ username: $('[name=username]').val(),
+ password: $('[name=password]').val(),
+ _token: $('[name=_token]').val(),
+ }
+ $.ajax({
+ url: '{{url('fluidbook-external-install-server/'.$entry->id)}}/verifyconnection',
+ method: 'post',
+ data: data,
+ success: function (response) {
+ console.log(response, 'ok')
+ },
+ });
+ })
+ });
+ </script>
+@endpush
+
+@include('cubist_back::when')
+@include('crud::edit')