Skip to content

Commit

Permalink
Merge pull request #137 from vitodeploy/phpmyadmin
Browse files Browse the repository at this point in the history
add phpmyadmin
  • Loading branch information
saeedvaziry authored Mar 27, 2024
2 parents a7ba095 + c66c508 commit d01d406
Show file tree
Hide file tree
Showing 58 changed files with 432 additions and 95 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ bash <(curl -Ls https://raw.githubusercontent.com/vitodeploy/vito/1.x/scripts/in
- Prettier
- Postcss
- Flowbite
- svgrepo.com
55 changes: 55 additions & 0 deletions app/Actions/Service/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Actions\Service;

use App\Enums\ServiceStatus;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

class Create
{
public function create(Server $server, array $input): Service
{
$this->validate($server, $input);

$service = new Service([
'name' => $input['type'],
'type' => $input['type'],
'version' => $input['version'],
'status' => ServiceStatus::INSTALLING,
]);

Validator::make($input, $service->handler()->creationRules($input))->validate();

$service->type_data = $service->handler()->creationData($input);

$service->save();

$service->handler()->create();

dispatch(function () use ($service) {
$service->handler()->install();
$service->status = ServiceStatus::READY;
$service->save();
})->catch(function () use ($service) {
$service->handler()->delete();
$service->delete();
})->onConnection('ssh');

return $service;
}

private function validate(Server $server, array $input): void
{
Validator::make($input, [
'type' => [
'required',
Rule::in(config('core.add_on_services')),
Rule::unique('services', 'type')->where('server_id', $server->id),
],
'version' => 'required',
])->validate();
}
}
4 changes: 3 additions & 1 deletion app/Enums/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ final class Database

const MYSQL80 = 'mysql80';

const MARIADB = 'mariadb';
const MARIADB103 = 'mariadb103';

const MARIADB104 = 'mariadb104';

const POSTGRESQL12 = 'postgresql12';

Expand Down
2 changes: 2 additions & 0 deletions app/Enums/SiteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ final class SiteType
const LARAVEL = 'laravel';

const WORDPRESS = 'wordpress';

const PHPMYADMIN = 'phpmyadmin';
}
12 changes: 12 additions & 0 deletions app/Http/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace App\Http\Controllers;

use App\Actions\Service\Create;
use App\Facades\Toast;
use App\Helpers\HtmxResponse;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class ServiceController extends Controller
{
Expand Down Expand Up @@ -62,4 +65,13 @@ public function disable(Server $server, Service $service): RedirectResponse

return back();
}

public function install(Server $server, Request $request): HtmxResponse
{
app(Create::class)->create($server, $request->input());

Toast::success('Service is being uninstalled!');

return htmx()->back();
}
}
17 changes: 10 additions & 7 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\Service\Manage;
use App\Exceptions\ServiceInstallationFailed;
use App\SSH\Services\AddOnServices\AbstractAddOnService;
use App\SSH\Services\Database\Database as DatabaseHandler;
use App\SSH\Services\Firewall\Firewall as FirewallHandler;
use App\SSH\Services\PHP\PHP as PHPHandler;
Expand Down Expand Up @@ -53,7 +54,9 @@ public static function boot(): void
parent::boot();

static::creating(function (Service $service) {
$service->unit = config('core.service_units')[$service->name][$service->server->os][$service->version];
if (array_key_exists($service->name, config('core.service_units'))) {
$service->unit = config('core.service_units')[$service->name][$service->server->os][$service->version];
}
});
}

Expand All @@ -63,7 +66,7 @@ public function server(): BelongsTo
}

public function handler(
): PHPHandler|WebserverHandler|DatabaseHandler|FirewallHandler|ProcessManagerHandler|RedisHandler {
): PHPHandler|WebserverHandler|DatabaseHandler|FirewallHandler|ProcessManagerHandler|RedisHandler|AbstractAddOnService {
$handler = config('core.service_handlers')[$this->name];

return new $handler($this);
Expand All @@ -81,26 +84,26 @@ public function validateInstall($result): void

public function start(): void
{
app(Manage::class)->start($this);
$this->unit && app(Manage::class)->start($this);
}

public function stop(): void
{
app(Manage::class)->stop($this);
$this->unit && app(Manage::class)->stop($this);
}

public function restart(): void
{
app(Manage::class)->restart($this);
$this->unit && app(Manage::class)->restart($this);
}

public function enable(): void
{
app(Manage::class)->enable($this);
$this->unit && app(Manage::class)->enable($this);
}

public function disable(): void
{
app(Manage::class)->disable($this);
$this->unit && app(Manage::class)->disable($this);
}
}
17 changes: 17 additions & 0 deletions app/SSH/OS/OS.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,21 @@ public function runScript(string $path, string $script, ?int $siteId = null): Se

return $ssh->log;
}

public function download(string $url, string $path): string
{
return $this->server->ssh()->exec(
$this->getScript('download.sh', [
'url' => $url,
'path' => $path,
])
);
}

public function unzip(string $path): string
{
return $this->server->ssh()->exec(
'unzip '.$path
);
}
}
3 changes: 3 additions & 0 deletions app/SSH/OS/scripts/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if ! wget __url__ -O __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
23 changes: 23 additions & 0 deletions app/SSH/PHPMyAdmin/PHPMyAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\SSH\PHPMyAdmin;

use App\Models\Site;
use App\SSH\HasScripts;

class PHPMyAdmin
{
use HasScripts;

public function install(Site $site): void
{
$site->server->ssh()->exec(
$this->getScript('install.sh', [
'version' => $site->type_data['version'],
'path' => $site->path,
]),
'install-phpmyadmin',
$site->id
);
}
}
25 changes: 25 additions & 0 deletions app/SSH/PHPMyAdmin/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
sudo rm -rf phpmyadmin

sudo rm -rf __path__

if ! wget https://files.phpmyadmin.net/phpMyAdmin/__version__/phpMyAdmin-__version__-all-languages.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi

if ! unzip phpMyAdmin-__version__-all-languages.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi

if ! rm -rf phpMyAdmin-__version__-all-languages.zip; then
echo 'VITO_SSH_ERROR' && exit 1
fi

if ! mv phpMyAdmin-__version__-all-languages __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi

if ! mv __path__/config.sample.inc.php __path__/config.inc.php; then
echo 'VITO_SSH_ERROR' && exit 1
fi

echo "PHPMyAdmin installed!"
18 changes: 18 additions & 0 deletions app/SSH/Services/AddOnServices/AbstractAddOnService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\SSH\Services\AddOnServices;

use App\SSH\Services\ServiceInterface;

abstract class AbstractAddOnService implements ServiceInterface
{
abstract public function creationRules(array $input): array;

abstract public function creationData(array $input): array;

abstract public function create(): void;

abstract public function delete(): void;

abstract public function data(): array;
}
49 changes: 49 additions & 0 deletions app/SiteTypes/PHPMyAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\SiteTypes;

use Illuminate\Validation\Rule;

class PHPMyAdmin extends PHPSite
{
public function supportedFeatures(): array
{
return [
//
];
}

public function createRules(array $input): array
{
return [
'php_version' => [
'required',
Rule::in($this->site->server->installedPHPVersions()),
],
'version' => 'required|string',
];
}

public function createFields(array $input): array
{
return [
'web_directory' => '',
'php_version' => $input['php_version'] ?? '',
];
}

public function data(array $input): array
{
return [
'version' => $input['version'],
];
}

public function install(): void
{
$this->site->server->webserver()->handler()->createVHost($this->site);
$this->progress(30);
app(\App\SSH\PHPMyAdmin\PHPMyAdmin::class)->install($this->site);
$this->progress(65);
}
}
6 changes: 6 additions & 0 deletions config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\ServerProviders\Vultr;
use App\SiteTypes\Laravel;
use App\SiteTypes\PHPBlank;
use App\SiteTypes\PHPMyAdmin;
use App\SiteTypes\PHPSite;
use App\SiteTypes\Wordpress;
use App\SourceControlProviders\Bitbucket;
Expand Down Expand Up @@ -177,6 +178,9 @@
'ufw' => Ufw::class,
'supervisor' => Supervisor::class,
],
'add_on_services' => [
// add-on services
],
'service_units' => [
'nginx' => [
'ubuntu_18' => [
Expand Down Expand Up @@ -320,12 +324,14 @@
\App\Enums\SiteType::PHP_BLANK,
\App\Enums\SiteType::LARAVEL,
\App\Enums\SiteType::WORDPRESS,
\App\Enums\SiteType::PHPMYADMIN,
],
'site_types_class' => [
\App\Enums\SiteType::PHP => PHPSite::class,
\App\Enums\SiteType::PHP_BLANK => PHPBlank::class,
\App\Enums\SiteType::LARAVEL => Laravel::class,
\App\Enums\SiteType::WORDPRESS => Wordpress::class,
\App\Enums\SiteType::PHPMYADMIN => PHPMyAdmin::class,
],

/*
Expand Down
1 change: 0 additions & 1 deletion public/build/assets/app-a972b4b2.css

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/app-eff15392.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resources/css/app.css": {
"file": "assets/app-a972b4b2.css",
"file": "assets/app-eff15392.css",
"isEntry": true,
"src": "resources/css/app.css"
},
Expand Down
10 changes: 9 additions & 1 deletion public/static/images/supervisor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion public/static/images/ufw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions resources/views/application/phpmyadmin-app.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<x-simple-card class="flex items-center justify-between">
<span>PHPMyAdmin is installed and ready to use!</span>
<x-secondary-button :href="$site->getUrl()" target="_blank">Open</x-secondary-button>
</x-simple-card>
</div>
2 changes: 1 addition & 1 deletion resources/views/application/wordpress-app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span>
{{ __("Your Wordpress site is installed and ready to use! ") }}
</span>
<x-secondary-button :href="$site->url" target="_blank">
<x-secondary-button :href="$site->getUrl()" target="_blank">
{{ __("Open Website") }}
</x-secondary-button>
</x-simple-card>
Expand Down
Loading

0 comments on commit d01d406

Please sign in to comment.