mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
- 2.x - console
This commit is contained in:
@ -3,24 +3,14 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ConsoleController extends Controller
|
||||
{
|
||||
public function index(Server $server): View
|
||||
{
|
||||
$this->authorize('manage', $server);
|
||||
|
||||
return view('console.index', [
|
||||
'server' => $server,
|
||||
]);
|
||||
}
|
||||
|
||||
public function run(Server $server, Request $request)
|
||||
{
|
||||
$this->authorize('manage', $server);
|
||||
$this->authorize('update', $server);
|
||||
|
||||
$this->validate($request, [
|
||||
'user' => [
|
||||
@ -34,7 +24,11 @@ public function run(Server $server, Request $request)
|
||||
function () use ($server, $request) {
|
||||
$ssh = $server->ssh($request->user);
|
||||
$log = 'console-'.time();
|
||||
$ssh->exec(command: $request->command, log: $log, stream: true);
|
||||
$ssh->exec(command: $request->command, log: $log, stream: true, streamCallback: function ($output) {
|
||||
echo $output;
|
||||
ob_flush();
|
||||
flush();
|
||||
});
|
||||
},
|
||||
200,
|
||||
[
|
||||
|
@ -3,94 +3,17 @@
|
||||
namespace App\Web\Pages\Servers\Console\Widgets;
|
||||
|
||||
use App\Models\Server;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Console extends Component implements HasForms
|
||||
class Console extends Component
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
public Server $server;
|
||||
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
public bool $running = false;
|
||||
|
||||
public string $output = '';
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
public function render(): View
|
||||
{
|
||||
$this->data['user'] = $this->server->ssh_user;
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('data')
|
||||
->schema([
|
||||
Grid::make()
|
||||
->columns(6)
|
||||
->schema([
|
||||
Select::make('user')
|
||||
->options([
|
||||
'root' => 'root',
|
||||
'vito' => 'vito',
|
||||
])
|
||||
->maxWidth('sm')
|
||||
->hiddenLabel(),
|
||||
TextInput::make('command')
|
||||
->hiddenLabel()
|
||||
->placeholder('Command')
|
||||
->columnSpan(5)
|
||||
->suffixActions(
|
||||
[
|
||||
Action::make('run')
|
||||
->label('Run')
|
||||
->icon('heroicon-o-play')
|
||||
->color('primary')
|
||||
->visible(! $this->running)
|
||||
->action(function () {
|
||||
$this->running = true;
|
||||
$ssh = $this->server->ssh($this->data['user']);
|
||||
$log = 'console-'.time();
|
||||
$ssh->exec(command: $this->data['command'], log: $log, stream: true, streamCallback: function ($output) {
|
||||
$this->output .= $output;
|
||||
$this->stream(
|
||||
to: 'output',
|
||||
content: $output,
|
||||
);
|
||||
});
|
||||
}),
|
||||
Action::make('stop')
|
||||
->view('web.components.dynamic-widget', [
|
||||
'widget' => StopCommand::class,
|
||||
'params' => [],
|
||||
]),
|
||||
],
|
||||
),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return <<<'BLADE'
|
||||
<div>
|
||||
<x-console-view wire:stream="output">
|
||||
{{ $this->output }}
|
||||
</x-console-view>
|
||||
<div class="mt-5">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
</div>
|
||||
BLADE;
|
||||
return view('web.components.console', [
|
||||
'server' => $this->server,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,12 @@ public function infolist(Infolist $infolist): Infolist
|
||||
->suffixAction(
|
||||
EditTags::infolist($this->server)
|
||||
),
|
||||
|
||||
TextEntry::make('public_key')
|
||||
->label('Public Key')
|
||||
->limit(30)
|
||||
->inlineLabel()
|
||||
->copyable()
|
||||
->tooltip('Copy public key to clipboard'),
|
||||
]),
|
||||
])
|
||||
->record($this->server);
|
||||
|
Reference in New Issue
Block a user