add new server
add new private key check server connection
This commit is contained in:
@@ -10,6 +10,7 @@ class Form extends Component
|
||||
{
|
||||
public $server_id;
|
||||
public Server $server;
|
||||
public $uptime;
|
||||
|
||||
protected $rules = [
|
||||
'server.name' => 'required|min:6',
|
||||
@@ -22,6 +23,10 @@ class Form extends Component
|
||||
{
|
||||
$this->server = Server::find($this->server_id);
|
||||
}
|
||||
public function checkConnection()
|
||||
{
|
||||
$this->uptime = runRemoteCommandSync($this->server, ['uptime']);
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
55
app/Http/Livewire/Server/New/ByIp.php
Normal file
55
app/Http/Livewire/Server/New/ByIp.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Server\New;
|
||||
|
||||
use App\Models\PrivateKey;
|
||||
use App\Models\Server;
|
||||
use Livewire\Component;
|
||||
|
||||
class ByIp extends Component
|
||||
{
|
||||
public $private_keys;
|
||||
public int $private_key_id;
|
||||
public $new_private_key_name;
|
||||
public $new_private_key_description;
|
||||
public $new_private_key_value;
|
||||
|
||||
public string $ip;
|
||||
public string $user = 'root';
|
||||
public int $port = 22;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->private_keys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
||||
}
|
||||
public function setPrivateKey($private_key_id)
|
||||
{
|
||||
$this->private_key_id = $private_key_id;
|
||||
}
|
||||
public function addPrivateKey()
|
||||
{
|
||||
$this->new_private_key_value = trim($this->new_private_key_value);
|
||||
if (!str_ends_with($this->new_private_key_value, "\n")) {
|
||||
$this->new_private_key_value .= "\n";
|
||||
}
|
||||
PrivateKey::create([
|
||||
'name' => $this->new_private_key_name,
|
||||
'description' => $this->new_private_key_description,
|
||||
'private_key' => $this->new_private_key_value,
|
||||
'team_id' => session('currentTeam')->id
|
||||
]);
|
||||
session('currentTeam')->privateKeys = $this->private_keys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
$server = Server::create([
|
||||
'name' => fake()->company,
|
||||
'ip' => $this->ip,
|
||||
'user' => $this->user,
|
||||
'port' => $this->port,
|
||||
'team_id' => session('currentTeam')->id,
|
||||
'private_key_id' => $this->private_key_id
|
||||
]);
|
||||
return redirect()->route('server.show', $server->uuid);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,12 @@ namespace App\Models;
|
||||
|
||||
class PrivateKey extends BaseModel
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'private_key',
|
||||
'team_id',
|
||||
];
|
||||
public function servers()
|
||||
{
|
||||
return $this->hasMany(Server::class);
|
||||
|
||||
@@ -12,6 +12,14 @@ class Server extends BaseModel
|
||||
]);
|
||||
});
|
||||
}
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'ip',
|
||||
'user',
|
||||
'port',
|
||||
'team_id',
|
||||
'private_key_id',
|
||||
];
|
||||
public function destinations()
|
||||
{
|
||||
return $this->hasMany(PrivateKey::class);
|
||||
|
||||
@@ -4,6 +4,9 @@ namespace App\Models;
|
||||
|
||||
class ServerSetting extends BaseModel
|
||||
{
|
||||
protected $fillable = [
|
||||
'server_id'
|
||||
];
|
||||
public function server()
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
|
||||
@@ -12,13 +12,16 @@ class Team extends BaseModel
|
||||
'name',
|
||||
'personal_team'
|
||||
];
|
||||
public function projects() {
|
||||
public function projects()
|
||||
{
|
||||
return $this->hasMany(Project::class);
|
||||
}
|
||||
public function servers() {
|
||||
public function servers()
|
||||
{
|
||||
return $this->hasMany(Server::class);
|
||||
}
|
||||
public function applications() {
|
||||
public function applications()
|
||||
{
|
||||
return $this->hasManyThrough(Application::class, Project::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ class User extends Authenticatable
|
||||
$model->uuid = (string) new Cuid2(7);
|
||||
});
|
||||
}
|
||||
public function isRoot() {
|
||||
public function isRoot()
|
||||
{
|
||||
return $this->id == 0;
|
||||
}
|
||||
public function teams()
|
||||
|
||||
Reference in New Issue
Block a user