refactoring

This commit is contained in:
Saeed Vaziry
2023-08-04 18:28:04 +02:00
parent 8444323cf4
commit 643318fcfc
349 changed files with 3189 additions and 2729 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class CreateUserCommand extends Command
{
public function __construct(protected string $user, protected string $password, protected string $key)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/create-user.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__user__', $this->user)
->replace('__key__', $this->key)
->replace('__password__', $this->password)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeleteSshKeyCommand extends Command
{
public function __construct(protected string $key)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/delete-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__key__', str($this->key)->replace('/', '\/'))
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeploySshKeyCommand extends Command
{
public function __construct(protected string $key)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/deploy-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__key__', addslashes($this->key))
->toString();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class EditFileCommand extends Command
{
public function __construct(protected string $path, protected string $content)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/edit-file.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__path__', $this->path)
->replace('__content__', $this->content)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class GenerateSshKeyCommand extends Command
{
public function __construct(protected string $name)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/generate-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__name__', $this->name)
->toString();
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class GetPublicKeyCommand extends Command
{
public function file(): string
{
return File::get(resource_path('commands/system/get-public-key.sh'));
}
public function content(): string
{
return $this->file();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class ReadSshKeyCommand extends Command
{
public function __construct(protected string $name)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/read-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__name__', $this->name)
->toString();
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class RebootCommand extends Command
{
public function file(): string
{
return File::get(resource_path('commands/system/reboot.sh'));
}
public function content(): string
{
return $this->file();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class RunScript extends Command
{
public function __construct(protected string $path, protected string $script)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/run-script.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__path__', $this->path)
->replace('__script__', make_bash_script($this->script))
->toString();
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class UpgradeCommand extends Command
{
public function file(): string
{
return File::get(resource_path('commands/system/upgrade.sh'));
}
public function content(): string
{
return $this->file();
}
}