protected function run(Request $request, $id) {
$validation = [
'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([
'password' => $request->password,
- 'protocol' => $request->protocol,
'username' => $request->username,
'host' => $request->host,
'port' => $request->port], $validation);
if ($validator->fails()) {
+ $result = ['error' => true, 'message' => __('Des champs sont manquants')];
throw new ValidationException($validator);
}
- $validator->validate();
+ $validateData = $validator->validate();
- $result = FluidbookExternalInstallServer::verifyServerConnexion($id, $request->all());
- if($result) {
- //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();
- $data = ['error' => true, 'message' => __('La connexion a échouée')];
- }
+ $result = FluidbookExternalInstallServer::verifyServerConnexion($id, $validateData);
- return response()->json($data);
+ return response()->json($result);
}
}
parent::setFields();
$this->addField('redirections', Table::class, __('Redirections'), ['entity_singular' => __('redirection'), 'columns' => ['from' => __('De'), 'to' => __('Vers')], 'when' => ['protocol' => 'hosting']]);
$this->addField('allows_root', Checkbox::class, __('Autoriser le chargement à la racine (sur le chemin de base)'), ['default' => false]);
-
}
public function onSaved(): bool
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 {
- try {
- $connection = ssh2_connect($host, 22);
- } catch (\Exception $e) {
-
- }
- try {
- $fingerprint = ssh2_fingerprint($connection,
- SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);
- } catch (\Exception $e) {
-
- }
-
- if(!$fingerprint) {
- throw new \Exception('Fingerprint missing');
- }
-
- try {
- self::$isValidConnexion = ssh2_auth_password($connection, $usr, $pwd);
- } catch (\Exception $e) {
-
- }
- ssh2_disconnect($connection);
- }
+ $server = static::find($id);
+ $data = [
+ 'username' => $data['username'] ?? $server->username,
+ 'password' => $data['password'] ?? $server->password,
+ 'host' => $data['host'] ?? $server->host,
+ 'port' => $data['port'] ?? $server->port ?? 22,
+ ];
+
+ $result = static::find($id)->getTransferDriver()->checkConnexion($data);
+ //dump($result);
+ if($result === true) {
+ $result_['success'] = true;
} else {
- self::$isValidConnexion = file_exists("/mnt/hosting/status");
+ $result_['error'] = true;
}
-
- return self::$isValidConnexion;
+ $result_['message'] = $result === true ? __("La connexion a été établie avec succès") : static::messages()[$result];
+ return $result_;
}
-
- public static function listFluidbook()
+ public static function listFluidbook($id)
{
/*return DB::table('fluidbook_external_install_server')
->join('fluidbook_publication', 'fluidbook_external_install_server.name', '=', 'fluidbook_publication.c_title')
->groupBy('fluidbook_external_install_server.host')
->toArray();*/
}
+
+ public static function messages() {
+ return [
+ __("L'hôte est manquant"),
+ __("L'hôte ou le mot de passe est invalide"),
+ __("La connexion a échouée"),
+ __("Le dossier n'a pas été monté"),
+ __("Le protocol est indisponible"),
+ ];
+ }
}