From 9de6becd9ec2f2fb910889df6d4ed5cc3b43202e Mon Sep 17 00:00:00 2001 From: Bozhidar Slaveykov Date: Sat, 6 Apr 2024 18:20:54 +0300 Subject: [PATCH] update --- .../ModelPhyreServerCreatedListener.php | 12 +++- web/app/Models/PhyreServer.php | 20 ++++++ web/composer.json | 1 + web/composer.lock | 61 ++++++++++++++++++- 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/web/app/Listeners/ModelPhyreServerCreatedListener.php b/web/app/Listeners/ModelPhyreServerCreatedListener.php index 9683e2d..3d5274b 100644 --- a/web/app/Listeners/ModelPhyreServerCreatedListener.php +++ b/web/app/Listeners/ModelPhyreServerCreatedListener.php @@ -4,6 +4,8 @@ namespace App\Listeners; use App\Events\ModelPhyreServerCreated; +use Illuminate\Remote\Connection; +use Spatie\Ssh\Ssh; class ModelPhyreServerCreatedListener { @@ -21,7 +23,15 @@ class ModelPhyreServerCreatedListener public function handle(ModelPhyreServerCreated $event): void { - dd($event); + $username = $event->model->username; + $password = $event->model->password; + $ip = $event->model->ip; + + $process = Ssh::create($username . ':' . $password, $ip) + ->enablePasswordAuthentication() + ->execute('ls'); + + dd($process->getOutput()); } } diff --git a/web/app/Models/PhyreServer.php b/web/app/Models/PhyreServer.php index 8b33bb6..9d776f2 100644 --- a/web/app/Models/PhyreServer.php +++ b/web/app/Models/PhyreServer.php @@ -2,10 +2,30 @@ namespace App\Models; +use App\Events\ModelPhyreServerCreated; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class PhyreServer extends Model { use HasFactory; + + protected $fillable = [ + 'name', + 'ip', + 'port', + 'username', + 'password', + ]; + + public static function boot() + { + parent::boot(); + + static::creating(function ($model) { + event(new ModelPhyreServerCreated($model)); + }); + + } + } diff --git a/web/composer.json b/web/composer.json index 7ee7e4e..c552331 100644 --- a/web/composer.json +++ b/web/composer.json @@ -23,6 +23,7 @@ "mkocansey/bladewind": "^2.4", "nwidart/laravel-modules": "^10.0", "outerweb/filament-settings": "^1.2", + "spatie/ssh": "^1.10", "symfony/process": "^6.3", "symfony/yaml": "^7.0", "tapp/filament-authentication-log": "^3.0", diff --git a/web/composer.lock b/web/composer.lock index 8a19d61..4bc48c7 100644 --- a/web/composer.lock +++ b/web/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4abe345fdbef63cc6393bf28582dc8cf", + "content-hash": "ba2b3ac0d17f502cef5560e3baecf9d0", "packages": [ { "name": "acmephp/core", @@ -6266,6 +6266,65 @@ ], "time": "2024-03-20T07:29:11+00:00" }, + { + "name": "spatie/ssh", + "version": "1.10.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/ssh.git", + "reference": "8a69221ec27112bf463e6da78b21f17c047abd75" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/ssh/zipball/8a69221ec27112bf463e6da78b21f17c047abd75", + "reference": "8a69221ec27112bf463e6da78b21f17c047abd75", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "symfony/process": "^4.4|^5.3|^6.0|^7.0" + }, + "require-dev": { + "pestphp/pest": "^1.22", + "spatie/pest-plugin-snapshots": "^1.1", + "symfony/var-dumper": "^5.3|6.0|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Ssh\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A lightweight package to execute commands over an SSH connection", + "homepage": "https://github.com/spatie/ssh", + "keywords": [ + "spatie", + "ssh" + ], + "support": { + "issues": "https://github.com/spatie/ssh/issues", + "source": "https://github.com/spatie/ssh/tree/1.10.1" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + } + ], + "time": "2024-04-05T09:15:00+00:00" + }, { "name": "swagger-api/swagger-ui", "version": "v5.13.0",