2023-04-25 08:47:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Server;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Form extends Component
|
|
|
|
{
|
|
|
|
public $server_id;
|
|
|
|
public Server $server;
|
2023-04-26 13:38:50 +00:00
|
|
|
public $uptime;
|
2023-05-02 17:25:47 +00:00
|
|
|
public $dockerVersion;
|
|
|
|
public $dockerComposeVersion;
|
2023-04-25 08:47:13 +00:00
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'server.name' => 'required|min:6',
|
|
|
|
'server.description' => 'nullable',
|
|
|
|
'server.ip' => 'required',
|
|
|
|
'server.user' => 'required',
|
|
|
|
'server.port' => 'required',
|
|
|
|
];
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->server = Server::find($this->server_id);
|
|
|
|
}
|
2023-05-02 13:20:45 +00:00
|
|
|
public function installDocker()
|
|
|
|
{
|
|
|
|
$config = base64_encode('{ "live-restore": true }');
|
2023-05-02 17:15:17 +00:00
|
|
|
runRemoteCommandSync($this->server, [
|
|
|
|
"curl https://releases.rancher.com/install-docker/23.0.sh | sh"
|
|
|
|
]);
|
2023-05-02 13:20:45 +00:00
|
|
|
}
|
2023-05-02 17:25:47 +00:00
|
|
|
public function checkServer()
|
2023-04-26 13:38:50 +00:00
|
|
|
{
|
|
|
|
$this->uptime = runRemoteCommandSync($this->server, ['uptime']);
|
2023-05-02 17:25:47 +00:00
|
|
|
$this->dockerVersion = runRemoteCommandSync($this->server, ['docker version|head -2|grep -i version'], false);
|
|
|
|
$this->dockerComposeVersion = runRemoteCommandSync($this->server, ['docker compose version|head -2|grep -i version'], false);
|
2023-04-26 13:38:50 +00:00
|
|
|
}
|
2023-04-25 08:47:13 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
// $validation = Validator::make($this->server->toArray(), [
|
|
|
|
// 'ip' => [
|
|
|
|
// 'ip'
|
|
|
|
// ],
|
|
|
|
// ]);
|
|
|
|
// if ($validation->fails()) {
|
|
|
|
// foreach ($validation->errors()->getMessages() as $key => $value) {
|
|
|
|
// $this->addError("server.{$key}", $value[0]);
|
|
|
|
// }
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
$this->server->save();
|
|
|
|
}
|
|
|
|
}
|