mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-21 02:41:36 +00:00
Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fb651ab5ce | ||
|
c2625a7352 | ||
|
b72a2ddb1c | ||
|
0e8e6ef56f | ||
|
39fa25aee7 | ||
|
945c2e75c0 | ||
|
82933e29ff | ||
|
82c1f36ef6 | ||
|
e06d23b31a | ||
|
f0e7faa0e7 | ||
|
319fdb44e7 | ||
|
b62c40c97d | ||
|
e39e8c17a2 | ||
|
1391eb32d8 | ||
|
7f5e68e131 | ||
|
431da1b728 | ||
|
8c487a64fa | ||
|
a67e586a5d | ||
|
960db714b7 | ||
|
7da0221ccb | ||
|
9ac5f9ebb3 | ||
|
ed8965b92b |
11
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
11
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Feature request
|
||||
url: https://github.com/vitodeploy/vito/discussions/new?category=ideas
|
||||
about: Share ideas for new features
|
||||
- name: Support
|
||||
url: https://github.com/vitodeploy/vito/discussions/new?category=q-a
|
||||
about: Ask the community for help
|
||||
- name: Discord
|
||||
url: https://discord.gg/uZeeHZZnm5
|
||||
about: Join the community
|
12
.github/ISSUE_TEMPLATE/feature_request.md
vendored
12
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,12 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: feature
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
To request a feature or suggest an idea please add it to the feedback boards
|
||||
|
||||
https://vitodeploy.featurebase.app/
|
@ -34,8 +34,7 @@ ## Useful Links
|
||||
- [Documentation](https://vitodeploy.com)
|
||||
- [Install on Server](https://vitodeploy.com/introduction/installation.html#install-on-vps-recommended)
|
||||
- [Install via Docker](https://vitodeploy.com/introduction/installation.html#install-via-docker)
|
||||
- [Feedbacks](https://vitodeploy.featurebase.app)
|
||||
- [Roadmap](https://vitodeploy.featurebase.app/roadmap)
|
||||
- [Roadmap](https://github.com/orgs/vitodeploy/projects/5)
|
||||
- [Video Demo](https://youtu.be/AbmUOBDOc28)
|
||||
- [Discord](https://discord.gg/uZeeHZZnm5)
|
||||
- [Contribution](/CONTRIBUTING.md)
|
||||
|
@ -2,10 +2,14 @@
|
||||
|
||||
namespace App\Actions\Site;
|
||||
|
||||
use App\Exceptions\SSHUploadFailed;
|
||||
use App\Models\Site;
|
||||
|
||||
class UpdateEnv
|
||||
{
|
||||
/**
|
||||
* @throws SSHUploadFailed
|
||||
*/
|
||||
public function update(Site $site, array $input): void
|
||||
{
|
||||
$site->server->os()->editFile(
|
||||
|
58
app/Actions/Tag/AttachTag.php
Normal file
58
app/Actions/Tag/AttachTag.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tag;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AttachTag
|
||||
{
|
||||
public function attach(User $user, array $input): Tag
|
||||
{
|
||||
$this->validate($input);
|
||||
|
||||
/** @var Server|Site $taggable */
|
||||
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
||||
|
||||
$tag = Tag::query()->where('name', $input['name'])->first();
|
||||
if ($tag) {
|
||||
if (! $taggable->tags->contains($tag->id)) {
|
||||
$taggable->tags()->attach($tag->id);
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
$tag = new Tag([
|
||||
'project_id' => $user->currentProject->id,
|
||||
'name' => $input['name'],
|
||||
'color' => config('core.tag_colors')[array_rand(config('core.tag_colors'))],
|
||||
]);
|
||||
$tag->save();
|
||||
|
||||
$taggable->tags()->attach($tag->id);
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
private function validate(array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'taggable_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'taggable_type' => [
|
||||
'required',
|
||||
Rule::in(config('core.taggable_types')),
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
}
|
49
app/Actions/Tag/CreateTag.php
Normal file
49
app/Actions/Tag/CreateTag.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tag;
|
||||
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateTag
|
||||
{
|
||||
public function create(User $user, array $input): Tag
|
||||
{
|
||||
$this->validate($input);
|
||||
|
||||
$tag = Tag::query()
|
||||
->where('project_id', $user->current_project_id)
|
||||
->where('name', $input['name'])
|
||||
->first();
|
||||
if ($tag) {
|
||||
throw ValidationException::withMessages([
|
||||
'name' => ['Tag with this name already exists.'],
|
||||
]);
|
||||
}
|
||||
|
||||
$tag = new Tag([
|
||||
'project_id' => $user->currentProject->id,
|
||||
'name' => $input['name'],
|
||||
'color' => $input['color'],
|
||||
]);
|
||||
$tag->save();
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
private function validate(array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'color' => [
|
||||
'required',
|
||||
Rule::in(config('core.tag_colors')),
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
}
|
15
app/Actions/Tag/DeleteTag.php
Normal file
15
app/Actions/Tag/DeleteTag.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tag;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DeleteTag
|
||||
{
|
||||
public function delete(Tag $tag): void
|
||||
{
|
||||
DB::table('taggables')->where('tag_id', $tag->id)->delete();
|
||||
$tag->delete();
|
||||
}
|
||||
}
|
36
app/Actions/Tag/DetachTag.php
Normal file
36
app/Actions/Tag/DetachTag.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tag;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\Site;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class DetachTag
|
||||
{
|
||||
public function detach(Tag $tag, array $input): void
|
||||
{
|
||||
$this->validate($input);
|
||||
|
||||
/** @var Server|Site $taggable */
|
||||
$taggable = $input['taggable_type']::findOrFail($input['taggable_id']);
|
||||
|
||||
$taggable->tags()->detach($tag->id);
|
||||
}
|
||||
|
||||
private function validate(array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'taggable_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'taggable_type' => [
|
||||
'required',
|
||||
Rule::in(config('core.taggable_types')),
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
}
|
38
app/Actions/Tag/EditTag.php
Normal file
38
app/Actions/Tag/EditTag.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tag;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class EditTag
|
||||
{
|
||||
public function edit(Tag $tag, array $input): void
|
||||
{
|
||||
$this->validate($input);
|
||||
|
||||
$tag->name = $input['name'];
|
||||
$tag->color = $input['color'];
|
||||
|
||||
$tag->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validate(array $input): void
|
||||
{
|
||||
$rules = [
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'color' => [
|
||||
'required',
|
||||
Rule::in(config('core.tag_colors')),
|
||||
],
|
||||
];
|
||||
Validator::make($input, $rules)->validate();
|
||||
}
|
||||
}
|
@ -9,4 +9,8 @@ final class StorageProvider
|
||||
const FTP = 'ftp';
|
||||
|
||||
const LOCAL = 'local';
|
||||
|
||||
const S3 = 's3';
|
||||
|
||||
const WASABI = 'wasabi';
|
||||
}
|
||||
|
8
app/Exceptions/SSHUploadFailed.php
Executable file
8
app/Exceptions/SSHUploadFailed.php
Executable file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class SSHUploadFailed extends SSHError
|
||||
{
|
||||
//
|
||||
}
|
30
app/Facades/FTP.php
Normal file
30
app/Facades/FTP.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use App\Support\Testing\FTPFake;
|
||||
use FTP\Connection;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static bool|Connection connect(string $host, string $port, bool $ssl = false)
|
||||
* @method static bool login(string $username, string $password, bool|Connection $connection)
|
||||
* @method static void close(bool|Connection $connection)
|
||||
* @method static bool passive(bool|Connection $connection, bool $passive)
|
||||
* @method static bool delete(bool|Connection $connection, string $path)
|
||||
* @method static void assertConnected(string $host)
|
||||
*/
|
||||
class FTP extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor(): string
|
||||
{
|
||||
return 'ftp';
|
||||
}
|
||||
|
||||
public static function fake(): FTPFake
|
||||
{
|
||||
static::swap($fake = new FTPFake());
|
||||
|
||||
return $fake;
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
* @method static string exec(string $command, string $log = '', int $siteId = null, ?bool $stream = false)
|
||||
* @method static string assertExecuted(array|string $commands)
|
||||
* @method static string assertExecutedContains(string $command)
|
||||
* @method static string assertFileUploaded(string $toPath, ?string $content = null)
|
||||
* @method static string getUploadedLocalPath()
|
||||
* @method static disconnect()
|
||||
*/
|
||||
class SSH extends FacadeAlias
|
||||
|
37
app/Helpers/FTP.php
Normal file
37
app/Helpers/FTP.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use FTP\Connection;
|
||||
|
||||
class FTP
|
||||
{
|
||||
public function connect(string $host, string $port, bool $ssl = false): bool|Connection
|
||||
{
|
||||
if ($ssl) {
|
||||
return ftp_ssl_connect($host, $port, 5);
|
||||
}
|
||||
|
||||
return ftp_connect($host, $port, 5);
|
||||
}
|
||||
|
||||
public function login(string $username, string $password, bool|Connection $connection): bool
|
||||
{
|
||||
return ftp_login($connection, $username, $password);
|
||||
}
|
||||
|
||||
public function close(bool|Connection $connection): void
|
||||
{
|
||||
ftp_close($connection);
|
||||
}
|
||||
|
||||
public function passive(bool|Connection $connection, bool $passive): bool
|
||||
{
|
||||
return ftp_pasv($connection, $passive);
|
||||
}
|
||||
|
||||
public function delete(bool|Connection $connection, string $path): bool
|
||||
{
|
||||
return ftp_delete($connection, $path);
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
use App\Exceptions\RepositoryNotFound;
|
||||
use App\Exceptions\RepositoryPermissionDenied;
|
||||
use App\Exceptions\SourceControlIsNotConnected;
|
||||
use App\Exceptions\SSHUploadFailed;
|
||||
use App\Facades\Toast;
|
||||
use App\Helpers\HtmxResponse;
|
||||
use App\Models\Deployment;
|
||||
@ -81,9 +82,12 @@ public function updateEnv(Server $server, Site $site, Request $request): Redirec
|
||||
{
|
||||
$this->authorize('manage', $server);
|
||||
|
||||
app(UpdateEnv::class)->update($site, $request->input());
|
||||
|
||||
Toast::success('Env updated!');
|
||||
try {
|
||||
app(UpdateEnv::class)->update($site, $request->input());
|
||||
Toast::success('Env updated!');
|
||||
} catch (SSHUploadFailed) {
|
||||
Toast::error('Failed to update .env file!');
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
90
app/Http/Controllers/Settings/TagController.php
Normal file
90
app/Http/Controllers/Settings/TagController.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Actions\Tag\AttachTag;
|
||||
use App\Actions\Tag\CreateTag;
|
||||
use App\Actions\Tag\DeleteTag;
|
||||
use App\Actions\Tag\DetachTag;
|
||||
use App\Actions\Tag\EditTag;
|
||||
use App\Facades\Toast;
|
||||
use App\Helpers\HtmxResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TagController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$data = [
|
||||
'tags' => Tag::getByProjectId(auth()->user()->current_project_id)->get(),
|
||||
];
|
||||
|
||||
if ($request->has('edit')) {
|
||||
$data['editTag'] = Tag::find($request->input('edit'));
|
||||
}
|
||||
|
||||
return view('settings.tags.index', $data);
|
||||
}
|
||||
|
||||
public function create(Request $request): HtmxResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $request->user();
|
||||
|
||||
app(CreateTag::class)->create(
|
||||
$user,
|
||||
$request->input(),
|
||||
);
|
||||
|
||||
Toast::success('Tag created.');
|
||||
|
||||
return htmx()->redirect(route('settings.tags'));
|
||||
}
|
||||
|
||||
public function update(Tag $tag, Request $request): HtmxResponse
|
||||
{
|
||||
app(EditTag::class)->edit(
|
||||
$tag,
|
||||
$request->input(),
|
||||
);
|
||||
|
||||
Toast::success('Tag updated.');
|
||||
|
||||
return htmx()->redirect(route('settings.tags'));
|
||||
}
|
||||
|
||||
public function attach(Request $request): RedirectResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $request->user();
|
||||
|
||||
app(AttachTag::class)->attach($user, $request->input());
|
||||
|
||||
return back()->with([
|
||||
'status' => 'tag-created',
|
||||
]);
|
||||
}
|
||||
|
||||
public function detach(Request $request, Tag $tag): RedirectResponse
|
||||
{
|
||||
app(DetachTag::class)->detach($tag, $request->input());
|
||||
|
||||
return back()->with([
|
||||
'status' => 'tag-detached',
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(Tag $tag): RedirectResponse
|
||||
{
|
||||
app(DeleteTag::class)->delete($tag);
|
||||
|
||||
Toast::success('Tag deleted.');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
@ -65,4 +65,9 @@ public function sourceControls(): HasMany
|
||||
{
|
||||
return $this->hasMany(SourceControl::class);
|
||||
}
|
||||
|
||||
public function tags(): HasMany
|
||||
{
|
||||
return $this->hasMany(Tag::class);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@ -214,6 +215,11 @@ public function sshKeys(): BelongsToMany
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function tags(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
public function getSshUser(): string
|
||||
{
|
||||
if ($this->ssh_user) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
@ -126,6 +127,11 @@ public function ssls(): HasMany
|
||||
return $this->hasMany(Ssl::class);
|
||||
}
|
||||
|
||||
public function tags(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SourceControlIsNotConnected
|
||||
*/
|
||||
|
55
app/Models/Tag.php
Normal file
55
app/Models/Tag.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $project_id
|
||||
* @property string $name
|
||||
* @property string $color
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'project_id',
|
||||
'name',
|
||||
'color',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'project_id' => 'int',
|
||||
];
|
||||
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function servers(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Server::class, 'taggable');
|
||||
}
|
||||
|
||||
public function sites(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Site::class, 'taggable');
|
||||
}
|
||||
|
||||
public static function getByProjectId(int $projectId): Builder
|
||||
{
|
||||
return self::query()
|
||||
->where('project_id', $projectId)
|
||||
->orWhereNull('project_id');
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ private function checkConnection(string $subject, string $text): bool
|
||||
'content' => '*'.$subject.'*'."\n".$text,
|
||||
]);
|
||||
|
||||
return $connect->ok();
|
||||
return $connect->successful();
|
||||
}
|
||||
|
||||
public function send(object $notifiable, NotificationInterface $notification): void
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Helpers\FTP;
|
||||
use App\Helpers\Notifier;
|
||||
use App\Helpers\SSH;
|
||||
use App\Helpers\Toast;
|
||||
@ -36,5 +37,8 @@ public function boot(): void
|
||||
$this->app->bind('toast', function () {
|
||||
return new Toast;
|
||||
});
|
||||
$this->app->bind('ftp', function () {
|
||||
return new FTP;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
20
app/SSH/HasS3Storage.php
Normal file
20
app/SSH/HasS3Storage.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH;
|
||||
|
||||
trait HasS3Storage
|
||||
{
|
||||
private function prepareS3Path(string $path, string $prefix = ''): string
|
||||
{
|
||||
$path = trim($path);
|
||||
$path = ltrim($path, '/');
|
||||
$path = preg_replace('/[^a-zA-Z0-9\-_\.\/]/', '_', $path);
|
||||
$path = preg_replace('/\/+/', '/', $path);
|
||||
|
||||
if ($prefix) {
|
||||
$path = trim($prefix, '/').'/'.$path;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
@ -2,9 +2,14 @@
|
||||
|
||||
namespace App\SSH\OS;
|
||||
|
||||
use App\Exceptions\SSHUploadFailed;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use App\SSH\HasScripts;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
class OS
|
||||
{
|
||||
@ -109,14 +114,25 @@ public function reboot(): void
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHUploadFailed
|
||||
*/
|
||||
public function editFile(string $path, ?string $content = null): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('edit-file.sh', [
|
||||
'path' => $path,
|
||||
'content' => $content ?? '',
|
||||
]),
|
||||
);
|
||||
$tmpName = Str::random(10).strtotime('now');
|
||||
try {
|
||||
/** @var FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk('local');
|
||||
$storageDisk->put($tmpName, $content);
|
||||
$this->server->ssh()->upload(
|
||||
$storageDisk->path($tmpName),
|
||||
$path
|
||||
);
|
||||
} catch (Throwable) {
|
||||
throw new SSHUploadFailed();
|
||||
} finally {
|
||||
$this->deleteTempFile($tmpName);
|
||||
}
|
||||
}
|
||||
|
||||
public function readFile(string $path): string
|
||||
@ -200,4 +216,11 @@ public function resourceInfo(): array
|
||||
'disk_free' => str($info)->after('disk_free:')->before(PHP_EOL)->toString(),
|
||||
];
|
||||
}
|
||||
|
||||
private function deleteTempFile(string $name): void
|
||||
{
|
||||
if (Storage::disk('local')->exists($name)) {
|
||||
Storage::disk('local')->delete($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
if ! echo "__content__" | tee __path__; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
@ -1,8 +1,8 @@
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common curl zip unzip git gcc openssl
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common curl zip unzip git gcc openssl ufw
|
||||
git config --global user.email "__email__"
|
||||
git config --global user.name "__name__"
|
||||
|
||||
# Install Node.js
|
||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -;
|
||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install nodejs -y
|
||||
|
@ -117,6 +117,7 @@ public function deleteUser(string $username, string $host): void
|
||||
public function link(string $username, string $host, array $databases): void
|
||||
{
|
||||
$ssh = $this->service->server->ssh();
|
||||
$version = $this->service->version;
|
||||
|
||||
foreach ($databases as $database) {
|
||||
$ssh->exec(
|
||||
@ -124,6 +125,7 @@ public function link(string $username, string $host, array $databases): void
|
||||
'username' => $username,
|
||||
'host' => $host,
|
||||
'database' => $database,
|
||||
'version' => $version,
|
||||
]),
|
||||
'link-user-to-database'
|
||||
);
|
||||
@ -132,10 +134,13 @@ public function link(string $username, string $host, array $databases): void
|
||||
|
||||
public function unlink(string $username, string $host): void
|
||||
{
|
||||
$version = $this->service->version;
|
||||
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/unlink.sh', [
|
||||
'username' => $username,
|
||||
'host' => $host,
|
||||
'version' => $version,
|
||||
]),
|
||||
'unlink-user-from-databases'
|
||||
);
|
||||
|
@ -1,5 +1,16 @@
|
||||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE __database__ TO __username__;"; then
|
||||
USER_TO_LINK='__username__'
|
||||
DB_NAME='__database__'
|
||||
DB_VERSION='__version__'
|
||||
|
||||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"$DB_NAME\" TO $USER_TO_LINK;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
echo "Linking to __database__ finished"
|
||||
# Check if PostgreSQL version is 15 or greater
|
||||
if [ "$DB_VERSION" -ge 15 ]; then
|
||||
if ! sudo -u postgres psql -d "$DB_NAME" -c "GRANT USAGE, CREATE ON SCHEMA public TO $USER_TO_LINK;"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Linking to $DB_NAME finished"
|
||||
|
@ -1,10 +1,16 @@
|
||||
USER_TO_REVOKE='__username__'
|
||||
DB_VERSION='__version__'
|
||||
|
||||
DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
|
||||
|
||||
for DB in $DATABASES; do
|
||||
echo "Revoking privileges in database: $DB"
|
||||
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM $USER_TO_REVOKE;"
|
||||
|
||||
# Check if PostgreSQL version is 15 or greater
|
||||
if [ "$DB_VERSION" -ge 15 ]; then
|
||||
sudo -u postgres psql -d "$DB" -c "REVOKE USAGE, CREATE ON SCHEMA public FROM $USER_TO_REVOKE;"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Privileges revoked from $USER_TO_REVOKE"
|
||||
|
78
app/SSH/Storage/S3.php
Normal file
78
app/SSH/Storage/S3.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\Models\Server;
|
||||
use App\Models\StorageProvider;
|
||||
use App\SSH\HasS3Storage;
|
||||
use App\SSH\HasScripts;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class S3 extends S3AbstractStorage
|
||||
{
|
||||
use HasS3Storage, HasScripts;
|
||||
|
||||
public function __construct(Server $server, StorageProvider $storageProvider)
|
||||
{
|
||||
parent::__construct($server, $storageProvider);
|
||||
$this->setBucketRegion($this->storageProvider->credentials['region']);
|
||||
$this->setApiUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHCommandError
|
||||
*/
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$uploadCommand = $this->getScript('s3/upload.sh', [
|
||||
'src' => $src,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'dest' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$dest),
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
'region' => $this->getBucketRegion(),
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
]);
|
||||
|
||||
$upload = $this->server->ssh()->exec($uploadCommand, 'upload-to-s3');
|
||||
|
||||
if (str_contains($upload, 'Error') || ! str_contains($upload, 'upload:')) {
|
||||
Log::error('Failed to upload to S3', ['output' => $upload]);
|
||||
throw new SSHCommandError('Failed to upload to S3: '.$upload);
|
||||
}
|
||||
|
||||
return [
|
||||
'size' => null, // You can parse the size from the output if needed
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHCommandError
|
||||
*/
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$downloadCommand = $this->getScript('s3/download.sh', [
|
||||
'src' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$src),
|
||||
'dest' => $dest,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
'region' => $this->getBucketRegion(),
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
]);
|
||||
|
||||
$download = $this->server->ssh()->exec($downloadCommand, 'download-from-s3');
|
||||
|
||||
if (! str_contains($download, 'Download successful')) {
|
||||
Log::error('Failed to download from S3', ['output' => $download]);
|
||||
throw new SSHCommandError('Failed to download from S3: '.$download);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void {}
|
||||
}
|
32
app/SSH/Storage/S3AbstractStorage.php
Normal file
32
app/SSH/Storage/S3AbstractStorage.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
abstract class S3AbstractStorage extends AbstractStorage
|
||||
{
|
||||
protected ?string $apiUrl = null;
|
||||
|
||||
protected ?string $bucketRegion = null;
|
||||
|
||||
public function getApiUrl(): string
|
||||
{
|
||||
return $this->apiUrl;
|
||||
}
|
||||
|
||||
public function setApiUrl(?string $region = null): void
|
||||
{
|
||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.amazonaws.com";
|
||||
}
|
||||
|
||||
// Getter and Setter for $bucketRegion
|
||||
public function getBucketRegion(): string
|
||||
{
|
||||
return $this->bucketRegion;
|
||||
}
|
||||
|
||||
public function setBucketRegion(string $region): void
|
||||
{
|
||||
$this->bucketRegion = $region;
|
||||
}
|
||||
}
|
84
app/SSH/Storage/Wasabi.php
Normal file
84
app/SSH/Storage/Wasabi.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\Models\Server;
|
||||
use App\Models\StorageProvider;
|
||||
use App\SSH\HasS3Storage;
|
||||
use App\SSH\HasScripts;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Wasabi extends S3AbstractStorage
|
||||
{
|
||||
use HasS3Storage, HasScripts;
|
||||
|
||||
public function __construct(Server $server, StorageProvider $storageProvider)
|
||||
{
|
||||
parent::__construct($server, $storageProvider);
|
||||
$this->setBucketRegion($this->storageProvider->credentials['region']);
|
||||
$this->setApiUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHCommandError
|
||||
*/
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$uploadCommand = $this->getScript('wasabi/upload.sh', [
|
||||
'src' => $src,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'dest' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$dest),
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
'region' => $this->storageProvider->credentials['region'],
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
]);
|
||||
|
||||
$upload = $this->server->ssh()->exec($uploadCommand, 'upload-to-wasabi');
|
||||
|
||||
if (str_contains($upload, 'Error') || ! str_contains($upload, 'upload:')) {
|
||||
Log::error('Failed to upload to wasabi', ['output' => $upload]);
|
||||
throw new SSHCommandError('Failed to upload to wasabi: '.$upload);
|
||||
}
|
||||
|
||||
return [
|
||||
'size' => null, // You can parse the size from the output if needed
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHCommandError
|
||||
*/
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$downloadCommand = $this->getScript('wasabi/download.sh', [
|
||||
'src' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$src),
|
||||
'dest' => $dest,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
'region' => $this->storageProvider->credentials['region'],
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
]);
|
||||
|
||||
$download = $this->server->ssh()->exec($downloadCommand, 'download-from-wasabi');
|
||||
|
||||
if (! str_contains($download, 'Download successful')) {
|
||||
Log::error('Failed to download from wasabi', ['output' => $download]);
|
||||
throw new SSHCommandError('Failed to download from wasabi: '.$download);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void {}
|
||||
|
||||
public function setApiUrl(?string $region = null): void
|
||||
{
|
||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
||||
$this->apiUrl = "https://{$this->storageProvider->credentials['bucket']}.s3.{$this->getBucketRegion()}.wasabisys.com";
|
||||
}
|
||||
}
|
32
app/SSH/Storage/scripts/s3/download.sh
Normal file
32
app/SSH/Storage/scripts/s3/download.sh
Normal file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configure AWS CLI with provided credentials
|
||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
||||
/usr/local/bin/aws configure set default.region "__region__"
|
||||
|
||||
# Use the provided endpoint in the correct format
|
||||
ENDPOINT="__endpoint__"
|
||||
BUCKET="__bucket__"
|
||||
REGION="__region__"
|
||||
|
||||
# Ensure that DEST does not have a trailing slash
|
||||
SRC="__src__"
|
||||
DEST="__dest__"
|
||||
|
||||
# Download the file from S3
|
||||
echo "Downloading s3://__bucket__/__src__ to __dest__"
|
||||
download_output=$(/usr/local/bin/aws s3 cp "s3://$BUCKET/$SRC" "$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
||||
download_exit_code=$?
|
||||
|
||||
# Log output and exit code
|
||||
echo "Download command output: $download_output"
|
||||
echo "Download command exit code: $download_exit_code"
|
||||
|
||||
# Check if the download was successful
|
||||
if [ $download_exit_code -eq 0 ]; then
|
||||
echo "Download successful"
|
||||
else
|
||||
echo "Download failed"
|
||||
exit 1
|
||||
fi
|
59
app/SSH/Storage/scripts/s3/upload.sh
Normal file
59
app/SSH/Storage/scripts/s3/upload.sh
Normal file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if AWS CLI is installed
|
||||
if ! command -v aws &> /dev/null
|
||||
then
|
||||
echo "AWS CLI is not installed. Installing..."
|
||||
|
||||
# Detect system architecture
|
||||
ARCH=$(uname -m)
|
||||
if [ "$ARCH" == "x86_64" ]; then
|
||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
|
||||
elif [ "$ARCH" == "aarch64" ]; then
|
||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"
|
||||
else
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Download and install AWS CLI
|
||||
sudo curl "$CLI_URL" -o "awscliv2.zip"
|
||||
sudo unzip awscliv2.zip
|
||||
sudo ./aws/install --update
|
||||
sudo rm -rf awscliv2.zip aws
|
||||
|
||||
echo "AWS CLI installation completed."
|
||||
else
|
||||
echo "AWS CLI is already installed."
|
||||
/usr/local/bin/aws --version
|
||||
fi
|
||||
|
||||
# Configure AWS CLI with provided credentials
|
||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
||||
|
||||
# Use the provided endpoint in the correct format
|
||||
ENDPOINT="__endpoint__"
|
||||
BUCKET="__bucket__"
|
||||
REGION="__region__"
|
||||
|
||||
# Ensure that DEST does not have a trailing slash
|
||||
SRC="__src__"
|
||||
DEST="__dest__"
|
||||
|
||||
# Upload the file
|
||||
echo "Uploading __src__ to s3://$BUCKET/$DEST"
|
||||
upload_output=$(/usr/local/bin/aws s3 cp "$SRC" "s3://$BUCKET/$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
||||
upload_exit_code=$?
|
||||
|
||||
# Log output and exit code
|
||||
echo "Upload command output: $upload_output"
|
||||
echo "Upload command exit code: $upload_exit_code"
|
||||
|
||||
# Check if the upload was successful
|
||||
if [ $upload_exit_code -eq 0 ]; then
|
||||
echo "Upload successful"
|
||||
else
|
||||
echo "Upload failed"
|
||||
exit 1
|
||||
fi
|
31
app/SSH/Storage/scripts/wasabi/download.sh
Normal file
31
app/SSH/Storage/scripts/wasabi/download.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configure AWS CLI with provided credentials
|
||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
||||
|
||||
# Use the provided endpoint in the correct format
|
||||
ENDPOINT="__endpoint__"
|
||||
BUCKET="__bucket__"
|
||||
REGION="__region__"
|
||||
|
||||
# Ensure that DEST does not have a trailing slash
|
||||
SRC="__src__"
|
||||
DEST="__dest__"
|
||||
|
||||
# Download the file from S3
|
||||
echo "Downloading s3://__bucket____src__ to __dest__"
|
||||
download_output=$(/usr/local/bin/aws s3 cp "s3://$BUCKET/$SRC" "$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
||||
download_exit_code=$?
|
||||
|
||||
# Log output and exit code
|
||||
echo "Download command output: $download_output"
|
||||
echo "Download command exit code: $download_exit_code"
|
||||
|
||||
# Check if the download was successful
|
||||
if [ $download_exit_code -eq 0 ]; then
|
||||
echo "Download successful"
|
||||
else
|
||||
echo "Download failed"
|
||||
exit 1
|
||||
fi
|
59
app/SSH/Storage/scripts/wasabi/upload.sh
Normal file
59
app/SSH/Storage/scripts/wasabi/upload.sh
Normal file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if AWS CLI is installed
|
||||
if ! command -v aws &> /dev/null
|
||||
then
|
||||
echo "AWS CLI is not installed. Installing..."
|
||||
|
||||
# Detect system architecture
|
||||
ARCH=$(uname -m)
|
||||
if [ "$ARCH" == "x86_64" ]; then
|
||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
|
||||
elif [ "$ARCH" == "aarch64" ]; then
|
||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"
|
||||
else
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Download and install AWS CLI
|
||||
sudo curl "$CLI_URL" -o "awscliv2.zip"
|
||||
sudo unzip awscliv2.zip
|
||||
sudo ./aws/install --update
|
||||
sudo rm -rf awscliv2.zip aws
|
||||
|
||||
echo "AWS CLI installation completed."
|
||||
else
|
||||
echo "AWS CLI is already installed."
|
||||
aws --version
|
||||
fi
|
||||
|
||||
# Configure AWS CLI with provided credentials
|
||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
||||
|
||||
# Use the provided endpoint in the correct format
|
||||
ENDPOINT="__endpoint__"
|
||||
BUCKET="__bucket__"
|
||||
REGION="__region__"
|
||||
|
||||
# Ensure that DEST does not have a trailing slash
|
||||
SRC="__src__"
|
||||
DEST="__dest__"
|
||||
|
||||
# Upload the file
|
||||
echo "Uploading __src__ to s3://$BUCKET/$DEST"
|
||||
upload_output=$(/usr/local/bin/aws s3 cp "$SRC" "s3://$BUCKET/$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
||||
upload_exit_code=$?
|
||||
|
||||
# Log output and exit code
|
||||
echo "Upload command output: $upload_output"
|
||||
echo "Upload command exit code: $upload_exit_code"
|
||||
|
||||
# Check if the upload was successful
|
||||
if [ $upload_exit_code -eq 0 ]; then
|
||||
echo "Upload successful"
|
||||
else
|
||||
echo "Upload failed"
|
||||
exit 1
|
||||
fi
|
@ -41,7 +41,7 @@ public function connect(): bool
|
||||
$isConnected = $connection && $this->login($connection);
|
||||
|
||||
if ($isConnected) {
|
||||
ftp_close($connection);
|
||||
\App\Facades\FTP::close($connection);
|
||||
}
|
||||
|
||||
return $isConnected;
|
||||
@ -58,31 +58,36 @@ public function delete(array $paths): void
|
||||
|
||||
if ($connection && $this->login($connection)) {
|
||||
if ($this->storageProvider->credentials['passive']) {
|
||||
ftp_pasv($connection, true);
|
||||
\App\Facades\FTP::passive($connection, true);
|
||||
}
|
||||
|
||||
foreach ($paths as $path) {
|
||||
ftp_delete($connection, $this->storageProvider->credentials['path'].'/'.$path);
|
||||
\App\Facades\FTP::delete($connection, $this->storageProvider->credentials['path'].'/'.$path);
|
||||
}
|
||||
}
|
||||
|
||||
ftp_close($connection);
|
||||
\App\Facades\FTP::close($connection);
|
||||
}
|
||||
|
||||
private function connection(): bool|Connection
|
||||
{
|
||||
$credentials = $this->storageProvider->credentials;
|
||||
if ($credentials['ssl']) {
|
||||
return ftp_ssl_connect($credentials['host'], $credentials['port'], 5);
|
||||
}
|
||||
|
||||
return ftp_connect($credentials['host'], $credentials['port'], 5);
|
||||
return \App\Facades\FTP::connect(
|
||||
$credentials['host'],
|
||||
$credentials['port'],
|
||||
$credentials['ssl']
|
||||
);
|
||||
}
|
||||
|
||||
private function login(Connection $connection): bool
|
||||
private function login(bool|Connection $connection): bool
|
||||
{
|
||||
$credentials = $this->storageProvider->credentials;
|
||||
|
||||
return ftp_login($connection, $credentials['username'], $credentials['password']);
|
||||
return \App\Facades\FTP::login(
|
||||
$credentials['username'],
|
||||
$credentials['password'],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
}
|
||||
|
57
app/StorageProviders/S3.php
Normal file
57
app/StorageProviders/S3.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\SSH\Storage\S3 as S3Storage;
|
||||
use App\SSH\Storage\Storage;
|
||||
use Aws\S3\Exception\S3Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class S3 extends S3AbstractStorageProvider
|
||||
{
|
||||
public function validationRules(): array
|
||||
{
|
||||
return [
|
||||
'key' => 'required|string',
|
||||
'secret' => 'required|string',
|
||||
'region' => 'required|string',
|
||||
'bucket' => 'required|string',
|
||||
'path' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function credentialData(array $input): array
|
||||
{
|
||||
return [
|
||||
'key' => $input['key'],
|
||||
'secret' => $input['secret'],
|
||||
'region' => $input['region'],
|
||||
'bucket' => $input['bucket'],
|
||||
'path' => $input['path'],
|
||||
];
|
||||
}
|
||||
|
||||
public function connect(): bool
|
||||
{
|
||||
try {
|
||||
$this->setBucketRegion($this->storageProvider->credentials['region']);
|
||||
$this->setApiUrl();
|
||||
$this->buildClientConfig();
|
||||
$this->getClient()->listBuckets();
|
||||
|
||||
return true;
|
||||
} catch (S3Exception $e) {
|
||||
Log::error('Failed to connect to S3', ['exception' => $e]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function ssh(Server $server): Storage
|
||||
{
|
||||
return new S3Storage($server, $this->storageProvider);
|
||||
}
|
||||
|
||||
public function delete(array $paths): void {}
|
||||
}
|
74
app/StorageProviders/S3AbstractStorageProvider.php
Normal file
74
app/StorageProviders/S3AbstractStorageProvider.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\StorageProvider;
|
||||
use Aws\S3\S3Client;
|
||||
|
||||
abstract class S3AbstractStorageProvider extends AbstractStorageProvider implements S3ClientInterface, S3StorageInterface
|
||||
{
|
||||
protected ?string $apiUrl = null;
|
||||
|
||||
protected ?string $bucketRegion = null;
|
||||
|
||||
protected ?S3Client $client = null;
|
||||
|
||||
protected StorageProvider $storageProvider;
|
||||
|
||||
protected array $clientConfig = [];
|
||||
|
||||
public function getApiUrl(): string
|
||||
{
|
||||
return $this->apiUrl;
|
||||
}
|
||||
|
||||
public function setApiUrl(?string $region = null): void
|
||||
{
|
||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.amazonaws.com";
|
||||
}
|
||||
|
||||
public function getBucketRegion(): string
|
||||
{
|
||||
return $this->bucketRegion;
|
||||
}
|
||||
|
||||
public function setBucketRegion(string $region): void
|
||||
{
|
||||
$this->bucketRegion = $region;
|
||||
}
|
||||
|
||||
public function getClient(): S3Client
|
||||
{
|
||||
return new S3Client($this->clientConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the configuration array for the S3 client.
|
||||
* This method can be overridden by child classes to modify the configuration.
|
||||
*/
|
||||
public function buildClientConfig(): array
|
||||
{
|
||||
$this->clientConfig = [
|
||||
'credentials' => [
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
],
|
||||
'region' => $this->getBucketRegion(),
|
||||
'version' => 'latest',
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
];
|
||||
|
||||
return $this->clientConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or update a configuration parameter for the S3 client.
|
||||
*/
|
||||
public function setConfigParam(array $param): void
|
||||
{
|
||||
foreach ($param as $key => $value) {
|
||||
$this->clientConfig[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
10
app/StorageProviders/S3ClientInterface.php
Normal file
10
app/StorageProviders/S3ClientInterface.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use Aws\S3\S3Client;
|
||||
|
||||
interface S3ClientInterface
|
||||
{
|
||||
public function getClient(): S3Client;
|
||||
}
|
14
app/StorageProviders/S3StorageInterface.php
Normal file
14
app/StorageProviders/S3StorageInterface.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
interface S3StorageInterface
|
||||
{
|
||||
public function getApiUrl(): string;
|
||||
|
||||
public function setApiUrl(?string $region = null): void;
|
||||
|
||||
public function getBucketRegion(): string;
|
||||
|
||||
public function setBucketRegion(string $region): void;
|
||||
}
|
85
app/StorageProviders/Wasabi.php
Normal file
85
app/StorageProviders/Wasabi.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\SSH\Storage\Storage;
|
||||
use App\SSH\Storage\Wasabi as WasabiStorage;
|
||||
use Aws\S3\Exception\S3Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Wasabi extends S3AbstractStorageProvider
|
||||
{
|
||||
private const DEFAULT_REGION = 'us-east-1';
|
||||
|
||||
public function validationRules(): array
|
||||
{
|
||||
return [
|
||||
'key' => 'required|string',
|
||||
'secret' => 'required|string',
|
||||
'region' => 'required|string',
|
||||
'bucket' => 'required|string',
|
||||
'path' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function credentialData(array $input): array
|
||||
{
|
||||
return [
|
||||
'key' => $input['key'],
|
||||
'secret' => $input['secret'],
|
||||
'region' => $input['region'],
|
||||
'bucket' => $input['bucket'],
|
||||
'path' => $input['path'],
|
||||
];
|
||||
}
|
||||
|
||||
public function connect(): bool
|
||||
{
|
||||
try {
|
||||
$this->setBucketRegion(self::DEFAULT_REGION);
|
||||
$this->setApiUrl();
|
||||
$this->buildClientConfig();
|
||||
$this->getClient()->listBuckets();
|
||||
|
||||
return true;
|
||||
} catch (S3Exception $e) {
|
||||
Log::error('Failed to connect to S3', ['exception' => $e]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the configuration array for the S3 client.
|
||||
* This method can be overridden by child classes to modify the configuration.
|
||||
*/
|
||||
public function buildClientConfig(): array
|
||||
{
|
||||
$this->clientConfig = [
|
||||
'credentials' => [
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
],
|
||||
'region' => $this->getBucketRegion(),
|
||||
'version' => 'latest',
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
'use_path_style_endpoint' => true,
|
||||
];
|
||||
|
||||
return $this->clientConfig;
|
||||
}
|
||||
|
||||
public function ssh(Server $server): Storage
|
||||
{
|
||||
return new WasabiStorage($server, $this->storageProvider);
|
||||
}
|
||||
|
||||
public function setApiUrl(?string $region = null): void
|
||||
{
|
||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.wasabisys.com";
|
||||
}
|
||||
|
||||
public function delete(array $paths): void {}
|
||||
}
|
60
app/Support/Testing/FTPFake.php
Normal file
60
app/Support/Testing/FTPFake.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Testing;
|
||||
|
||||
use FTP\Connection;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class FTPFake
|
||||
{
|
||||
protected array $connections = [];
|
||||
|
||||
protected array $logins = [];
|
||||
|
||||
public function connect(string $host, string $port, bool $ssl = false): bool|Connection
|
||||
{
|
||||
$this->connections[] = compact('host', 'port', 'ssl');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function login(string $username, string $password, bool|Connection $connection): bool
|
||||
{
|
||||
$this->logins[] = compact('username', 'password');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close(bool|Connection $connection): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function passive(bool|Connection $connection, bool $passive): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function delete(bool|Connection $connection, string $path): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function assertConnected(string $host): void
|
||||
{
|
||||
if (! $this->connections) {
|
||||
Assert::fail('No connections are made');
|
||||
}
|
||||
$connected = false;
|
||||
foreach ($this->connections as $connection) {
|
||||
if ($connection['host'] === $host) {
|
||||
$connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $connected) {
|
||||
Assert::fail('The expected host is not connected');
|
||||
}
|
||||
Assert::assertTrue(true, $connected);
|
||||
}
|
||||
}
|
@ -17,6 +17,12 @@ class SSHFake extends SSH
|
||||
|
||||
protected bool $connectionWillFail = false;
|
||||
|
||||
protected string $uploadedLocalPath;
|
||||
|
||||
protected string $uploadedRemotePath;
|
||||
|
||||
protected string $uploadedContent;
|
||||
|
||||
public function __construct(?string $output = null)
|
||||
{
|
||||
$this->output = $output;
|
||||
@ -63,6 +69,9 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
||||
|
||||
public function upload(string $local, string $remote): void
|
||||
{
|
||||
$this->uploadedLocalPath = $local;
|
||||
$this->uploadedRemotePath = $remote;
|
||||
$this->uploadedContent = file_get_contents($local);
|
||||
$this->log = null;
|
||||
}
|
||||
|
||||
@ -105,4 +114,22 @@ public function assertExecutedContains(string $command): void
|
||||
}
|
||||
Assert::assertTrue(true, $executed);
|
||||
}
|
||||
|
||||
public function assertFileUploaded(string $toPath, ?string $content = null): void
|
||||
{
|
||||
if (! $this->uploadedLocalPath || ! $this->uploadedRemotePath) {
|
||||
Assert::fail('File is not uploaded');
|
||||
}
|
||||
|
||||
Assert::assertEquals($toPath, $this->uploadedRemotePath);
|
||||
|
||||
if ($content) {
|
||||
Assert::assertEquals($content, $this->uploadedContent);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUploadedLocalPath(): string
|
||||
{
|
||||
return $this->uploadedLocalPath;
|
||||
}
|
||||
}
|
||||
|
47
app/View/Components/Editor.php
Normal file
47
app/View/Components/Editor.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Editor extends Component
|
||||
{
|
||||
public string $id;
|
||||
|
||||
public string $name;
|
||||
|
||||
public ?string $value;
|
||||
|
||||
public array $options;
|
||||
|
||||
public function __construct(
|
||||
string $name,
|
||||
?string $value,
|
||||
public string $lang,
|
||||
public bool $readonly = false,
|
||||
public bool $lineNumbers = true,
|
||||
) {
|
||||
$this->id = $name.'-'.Str::random(8);
|
||||
$this->name = $name;
|
||||
$this->value = json_encode($value ?? '');
|
||||
$this->options = $this->getOptions();
|
||||
}
|
||||
|
||||
private function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'lang' => $this->lang,
|
||||
'value' => $this->value,
|
||||
];
|
||||
}
|
||||
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.editor');
|
||||
}
|
||||
}
|
727
composer.lock
generated
727
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -427,11 +427,16 @@
|
||||
\App\Enums\StorageProvider::DROPBOX,
|
||||
\App\Enums\StorageProvider::FTP,
|
||||
\App\Enums\StorageProvider::LOCAL,
|
||||
\App\Enums\StorageProvider::S3,
|
||||
\App\Enums\StorageProvider::WASABI,
|
||||
],
|
||||
'storage_providers_class' => [
|
||||
\App\Enums\StorageProvider::DROPBOX => \App\StorageProviders\Dropbox::class,
|
||||
\App\Enums\StorageProvider::FTP => \App\StorageProviders\Ftp::class,
|
||||
\App\Enums\StorageProvider::FTP => \App\StorageProviders\FTP::class,
|
||||
\App\Enums\StorageProvider::LOCAL => \App\StorageProviders\Local::class,
|
||||
\App\Enums\StorageProvider::S3 => \App\StorageProviders\S3::class,
|
||||
\App\Enums\StorageProvider::WASABI => \App\StorageProviders\Wasabi::class,
|
||||
|
||||
],
|
||||
|
||||
'ssl_types' => [
|
||||
@ -445,4 +450,30 @@
|
||||
30,
|
||||
90,
|
||||
],
|
||||
|
||||
'tag_colors' => [
|
||||
'slate',
|
||||
'gray',
|
||||
'red',
|
||||
'orange',
|
||||
'amber',
|
||||
'yellow',
|
||||
'lime',
|
||||
'green',
|
||||
'emerald',
|
||||
'teal',
|
||||
'cyan',
|
||||
'sky',
|
||||
'blue',
|
||||
'indigo',
|
||||
'violet',
|
||||
'purple',
|
||||
'fuchsia',
|
||||
'pink',
|
||||
'rose',
|
||||
],
|
||||
'taggable_types' => [
|
||||
\App\Models\Server::class,
|
||||
\App\Models\Site::class,
|
||||
],
|
||||
];
|
||||
|
@ -618,8 +618,8 @@
|
||||
'images' => [
|
||||
'ubuntu_18' => '112929540',
|
||||
'ubuntu_20' => '112929454',
|
||||
'ubuntu_22' => '129211873',
|
||||
'ubuntu_24' => '155133621',
|
||||
'ubuntu_22' => '159651797',
|
||||
'ubuntu_24' => '160232537',
|
||||
],
|
||||
],
|
||||
'vultr' => [
|
||||
|
23
database/factories/TagFactory.php
Normal file
23
database/factories/TagFactory.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class TagFactory extends Factory
|
||||
{
|
||||
protected $model = Tag::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'project_id' => 1,
|
||||
'created_at' => Carbon::now(), //
|
||||
'updated_at' => Carbon::now(),
|
||||
'name' => $this->faker->randomElement(['production', 'staging', 'development']),
|
||||
'color' => $this->faker->randomElement(config('core.tag_colors')),
|
||||
];
|
||||
}
|
||||
}
|
29
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
29
database/migrations/2014_10_12_000000_create_users_table.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->string('profile_photo_path', 2048)->nullable();
|
||||
$table->text('two_factor_secret')->nullable();
|
||||
$table->text('two_factor_recovery_codes')->nullable();
|
||||
$table->string('timezone')->default('UTC')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePasswordResetsTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->index();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Get the migration connection name.
|
||||
*/
|
||||
public function getConnection(): ?string
|
||||
{
|
||||
return config('telescope.storage.database.connection');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$schema = Schema::connection($this->getConnection());
|
||||
|
||||
$schema->create('telescope_entries', function (Blueprint $table) {
|
||||
$table->bigIncrements('sequence');
|
||||
$table->uuid('uuid');
|
||||
$table->uuid('batch_id');
|
||||
$table->string('family_hash')->nullable();
|
||||
$table->boolean('should_display_on_index')->default(true);
|
||||
$table->string('type', 20);
|
||||
$table->longText('content');
|
||||
$table->dateTime('created_at')->nullable();
|
||||
|
||||
$table->unique('uuid');
|
||||
$table->index('batch_id');
|
||||
$table->index('family_hash');
|
||||
$table->index('created_at');
|
||||
$table->index(['type', 'should_display_on_index']);
|
||||
});
|
||||
|
||||
$schema->create('telescope_entries_tags', function (Blueprint $table) {
|
||||
$table->uuid('entry_uuid');
|
||||
$table->string('tag');
|
||||
|
||||
$table->primary(['entry_uuid', 'tag']);
|
||||
$table->index('tag');
|
||||
|
||||
$table->foreign('entry_uuid')
|
||||
->references('uuid')
|
||||
->on('telescope_entries')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
|
||||
$schema->create('telescope_monitoring', function (Blueprint $table) {
|
||||
$table->string('tag')->primary();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$schema = Schema::connection($this->getConnection());
|
||||
|
||||
$schema->dropIfExists('telescope_entries_tags');
|
||||
$schema->dropIfExists('telescope_entries');
|
||||
$schema->dropIfExists('telescope_monitoring');
|
||||
}
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->text('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('servers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->string('name')->index();
|
||||
$table->string('ssh_user')->nullable();
|
||||
$table->ipAddress('ip')->index()->nullable();
|
||||
$table->ipAddress('local_ip')->nullable();
|
||||
$table->unsignedInteger('provider_id')->nullable();
|
||||
$table->integer('port')->default(22);
|
||||
$table->string('os');
|
||||
$table->string('type');
|
||||
$table->json('type_data')->nullable();
|
||||
$table->string('provider');
|
||||
$table->json('provider_data')->nullable();
|
||||
$table->longText('authentication')->nullable();
|
||||
$table->longText('public_key')->nullable();
|
||||
$table->string('status')->default('installing');
|
||||
$table->integer('progress')->default(0);
|
||||
$table->string('progress_step')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('servers');
|
||||
}
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('services', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->string('type');
|
||||
$table->json('type_data')->nullable();
|
||||
$table->string('name');
|
||||
$table->string('version');
|
||||
$table->string('status')->default(ServiceStatus::INSTALLING);
|
||||
$table->boolean('is_default')->default(1);
|
||||
$table->string('unit')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('services');
|
||||
}
|
||||
};
|
26
database/migrations/2021_06_25_102220_create_jobs_table.php
Normal file
26
database/migrations/2021_06_25_102220_create_jobs_table.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->integer('attempts');
|
||||
$table->integer('reserved_at')->nullable();
|
||||
$table->integer('available_at');
|
||||
$table->integer('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
}
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('server_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->unsignedBigInteger('site_id')->nullable();
|
||||
$table->string('type');
|
||||
$table->string('name');
|
||||
$table->string('disk');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('server_logs');
|
||||
}
|
||||
};
|
35
database/migrations/2021_06_26_211903_create_sites_table.php
Normal file
35
database/migrations/2021_06_26_211903_create_sites_table.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sites', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id')->index();
|
||||
$table->string('type');
|
||||
$table->json('type_data')->nullable();
|
||||
$table->string('domain')->index();
|
||||
$table->json('aliases')->nullable();
|
||||
$table->string('web_directory')->nullable();
|
||||
$table->string('path');
|
||||
$table->string('php_version')->nullable();
|
||||
$table->string('source_control')->nullable();
|
||||
$table->string('repository')->nullable();
|
||||
$table->string('branch')->nullable();
|
||||
$table->integer('port')->nullable();
|
||||
$table->string('status')->default('installing');
|
||||
$table->integer('progress')->default(0)->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sites');
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('source_controls', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('provider');
|
||||
$table->json('provider_data')->nullable();
|
||||
$table->longText('access_token')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('source_controls');
|
||||
}
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('deployments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('site_id');
|
||||
$table->unsignedBigInteger('deployment_script_id');
|
||||
$table->unsignedInteger('log_id')->nullable();
|
||||
$table->json('commit_data')->nullable();
|
||||
$table->string('commit_id')->nullable();
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('deployments');
|
||||
}
|
||||
};
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\DatabaseStatus;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('databases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->string('name');
|
||||
$table->string('status')->default(DatabaseStatus::CREATING);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('databases');
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\DatabaseUserStatus;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('database_users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->string('username');
|
||||
$table->longText('password')->nullable();
|
||||
$table->json('databases')->nullable();
|
||||
$table->string('host')->default('localhost');
|
||||
$table->string('status')->default(DatabaseUserStatus::CREATING);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('database_users');
|
||||
}
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('firewall_rules', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->string('type');
|
||||
$table->string('protocol');
|
||||
$table->integer('port');
|
||||
$table->ipAddress('source')->default('0.0.0.0');
|
||||
$table->string('mask')->nullable();
|
||||
$table->text('note')->nullable();
|
||||
$table->string('status')->default('creating');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('firewall_rules');
|
||||
}
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cron_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->text('command');
|
||||
$table->string('user');
|
||||
$table->string('frequency');
|
||||
$table->boolean('hidden')->default(0);
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cron_jobs');
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('deployment_scripts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('site_id');
|
||||
$table->string('name')->nullable();
|
||||
$table->longText('content')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('deployment_scripts');
|
||||
}
|
||||
};
|
29
database/migrations/2021_08_14_165326_create_ssls_table.php
Normal file
29
database/migrations/2021_08_14_165326_create_ssls_table.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('ssls', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('site_id');
|
||||
$table->string('type')->default('letsencrypt');
|
||||
$table->string('domains')->nullable();
|
||||
$table->longText('certificate')->nullable();
|
||||
$table->longText('pk')->nullable();
|
||||
$table->longText('ca')->nullable();
|
||||
$table->timestamp('expires_at');
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ssls');
|
||||
}
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('redirects', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('site_id');
|
||||
$table->integer('mode');
|
||||
$table->text('from');
|
||||
$table->text('to');
|
||||
$table->string('status')->default('creating');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('redirects');
|
||||
}
|
||||
};
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('queues', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('server_id')->nullable();
|
||||
$table->unsignedBigInteger('site_id');
|
||||
$table->text('command');
|
||||
$table->string('user');
|
||||
$table->boolean('auto_start')->default(1);
|
||||
$table->boolean('auto_restart')->default(1);
|
||||
$table->integer('numprocs')->default(8);
|
||||
$table->boolean('redirect_stderr')->default(1);
|
||||
$table->string('stdout_logfile')->nullable();
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('queues');
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('ssh_keys', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->string('name');
|
||||
$table->longText('public_key');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ssh_keys');
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('server_ssh_keys', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->unsignedBigInteger('ssh_key_id');
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('server_ssh_keys');
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('git_hooks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('site_id');
|
||||
$table->unsignedBigInteger('source_control_id');
|
||||
$table->string('secret')->unique()->index();
|
||||
$table->json('events');
|
||||
$table->json('actions');
|
||||
$table->string('hook_id')->nullable();
|
||||
$table->json('hook_response')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('git_hooks');
|
||||
}
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('server_providers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->string('profile')->nullable();
|
||||
$table->string('provider');
|
||||
$table->longText('credentials');
|
||||
$table->boolean('connected')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('server_providers');
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('scripts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->string('name');
|
||||
$table->longText('content');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('scripts');
|
||||
}
|
||||
};
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('script_executions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('script_id');
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->string('user')->nullable();
|
||||
$table->timestamp('finished_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('script_executions');
|
||||
}
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('notification_channels', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('provider');
|
||||
$table->string('label');
|
||||
$table->json('data')->nullable();
|
||||
$table->boolean('connected')->default(false);
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('notification_channels');
|
||||
}
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateStorageProvidersTable extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('storage_providers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('provider');
|
||||
$table->string('label')->nullable();
|
||||
$table->string('token', 1000)->nullable();
|
||||
$table->string('refresh_token', 1000)->nullable();
|
||||
$table->boolean('connected')->default(1);
|
||||
$table->timestamp('token_expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('storage_providers');
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('backups', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('type');
|
||||
$table->string('name');
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->unsignedBigInteger('storage_id');
|
||||
$table->unsignedBigInteger('database_id')->nullable();
|
||||
$table->string('interval');
|
||||
$table->bigInteger('keep_backups');
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('backups');
|
||||
}
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('backup_files', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('backup_id');
|
||||
$table->string('name');
|
||||
$table->bigInteger('size')->nullable();
|
||||
$table->string('status');
|
||||
$table->timestamp('restored_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('backup_files');
|
||||
}
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (DB::getDriverName() === 'mysql') {
|
||||
DB::statement('ALTER TABLE firewall_rules MODIFY mask varchar(10) null');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sites', function (Blueprint $table) {
|
||||
$table->longText('ssh_key')->nullable()->after('repository');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sites', function (Blueprint $table) {
|
||||
$table->dropColumn('ssh_key');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('source_controls', function (Blueprint $table) {
|
||||
$table->string('url')->nullable()->after('provider');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('source_controls', function (Blueprint $table) {
|
||||
$table->dropColumn('url');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('source_controls', function (Blueprint $table) {
|
||||
$table->string('profile')->after('provider')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('source_controls', function (Blueprint $table) {
|
||||
$table->dropColumn('profile');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sites', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('source_control_id')->nullable()->after('source_control');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sites', function (Blueprint $table) {
|
||||
$table->dropColumn('source_control_id');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('storage_providers', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('user_id')->after('id');
|
||||
$table->string('profile')->after('user_id');
|
||||
$table->longText('credentials')->nullable()->after('provider');
|
||||
});
|
||||
Schema::table('storage_providers', function (Blueprint $table) {
|
||||
$table->dropColumn(['token', 'refresh_token', 'token_expires_at', 'label', 'connected']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('storage_providers', function (Blueprint $table) {
|
||||
$table->string('token')->nullable();
|
||||
$table->string('refresh_token')->nullable();
|
||||
$table->string('token_expires_at')->nullable();
|
||||
$table->string('label')->nullable();
|
||||
});
|
||||
Schema::table('storage_providers', function (Blueprint $table) {
|
||||
$table->dropColumn(['user_id', 'profile', 'credentials']);
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
$table->dropColumn('name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
$table->string('name')->nullable();
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('backup_files', function (Blueprint $table) {
|
||||
$table->string('restored_to')->after('status')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('backup_files', function (Blueprint $table) {
|
||||
$table->dropColumn('restored_to');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->timestamp('two_factor_confirmed_at')
|
||||
->after('two_factor_recovery_codes')
|
||||
->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'two_factor_confirmed_at',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('projects', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->bigInteger('user_id');
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('projects');
|
||||
}
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('project_id')->nullable()->after('id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->dropColumn('project_id');
|
||||
});
|
||||
}
|
||||
};
|
27
database/migrations/2024_01_01_235900_update_users_table.php
Normal file
27
database/migrations/2024_01_01_235900_update_users_table.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('current_project_id')->nullable()->after('timezone');
|
||||
});
|
||||
User::query()->each(function (User $user) {
|
||||
$project = $user->createDefaultProject();
|
||||
$user->servers()->update(['project_id' => $project->id]);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('current_project_id');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('server_logs', function (Blueprint $table) {
|
||||
$table->boolean('is_remote')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('server_logs', function (Blueprint $table) {
|
||||
$table->dropColumn('is_remote');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('metrics', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('server_id');
|
||||
$table->decimal('load', 5, 2);
|
||||
$table->decimal('memory_total', 15, 0);
|
||||
$table->decimal('memory_used', 15, 0);
|
||||
$table->decimal('memory_free', 15, 0);
|
||||
$table->decimal('disk_total', 15, 0);
|
||||
$table->decimal('disk_used', 15, 0);
|
||||
$table->decimal('disk_free', 15, 0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['server_id', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('metrics');
|
||||
}
|
||||
};
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('role')->default(UserRole::USER);
|
||||
});
|
||||
User::query()->update(['role' => UserRole::ADMIN]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_project', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->unsignedBigInteger('project_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
Project::all()->each(function (Project $project) {
|
||||
$project->users()->attach($project->user_id);
|
||||
});
|
||||
User::all()->each(function (User $user) {
|
||||
$user->current_project_id = $user->projects()->first()?->id;
|
||||
$user->save();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_project');
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->bigInteger('user_id')->nullable();
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('source_controls', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('project_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('source_controls', function (Blueprint $table) {
|
||||
$table->dropColumn('project_id');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->integer('updates')->default(0);
|
||||
$table->timestamp('last_update_check')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->dropColumn('updates');
|
||||
$table->dropColumn('last_update_check');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::dropIfExists('script_executions');
|
||||
|
||||
Schema::create('script_executions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('script_id');
|
||||
$table->unsignedBigInteger('server_log_id')->nullable();
|
||||
$table->string('user');
|
||||
$table->json('variables')->nullable();
|
||||
$table->string('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('script_executions');
|
||||
}
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user