mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-22 07:30:25 +00:00
update
This commit is contained in:
parent
ed8b0fb50d
commit
9c6c3795cd
7 changed files with 189 additions and 0 deletions
34
web/Modules/Customer/App/Filament/Pages/PHPMyAdmin.php
Normal file
34
web/Modules/Customer/App/Filament/Pages/PHPMyAdmin.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Customer\App\Filament\Pages;
|
||||
|
||||
use App\Models\HostingSubscription;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class PHPMyAdmin extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'phyre_customer-database-php';
|
||||
|
||||
protected static string $view = 'customer::filament.pages.phpmyadmin';
|
||||
|
||||
protected static ?string $navigationGroup = 'Hosting';
|
||||
|
||||
protected static ?string $navigationLabel = 'phpMyAdmin';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $slug = 'phpmyadmin';
|
||||
|
||||
protected static ?string $title = 'phpMyAdmin';
|
||||
|
||||
|
||||
protected function getViewData(): array
|
||||
{
|
||||
$findHostingSubscriptions = HostingSubscription::all();
|
||||
|
||||
return [
|
||||
'hostingSubscriptions' => $findHostingSubscriptions,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Customer\App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Customer;
|
||||
use App\Models\HostingSubscription;
|
||||
use App\Models\PHPMyAdminSSOToken;
|
||||
|
||||
class PHPMyAdminController extends Controller
|
||||
{
|
||||
public function login($id)
|
||||
{
|
||||
|
||||
$hostingSubscription = HostingSubscription::where('id', $id)
|
||||
// ->where('customer_id', auth()->user()->id)// TODO
|
||||
->first();
|
||||
|
||||
// Delete old sso tokens
|
||||
PHPMyAdminSSOToken::where('customer_id', $hostingSubscription->customer_id)
|
||||
->where('hosting_subscription_id', $hostingSubscription->id)
|
||||
->delete();
|
||||
|
||||
// Create new sso token
|
||||
$ssoToken = new PHPMyAdminSSOToken();
|
||||
$ssoToken->customer_id = $hostingSubscription->customer_id;
|
||||
$ssoToken->hosting_subscription_id = $hostingSubscription->id;
|
||||
$ssoToken->token = md5(uniqid() . time() . $hostingSubscription->customer_id . $hostingSubscription->id);
|
||||
$ssoToken->expires_at = now()->addMinutes(1);
|
||||
$ssoToken->ip_address = request()->ip();
|
||||
$ssoToken->user_agent = request()->userAgent();
|
||||
$ssoToken->save();
|
||||
|
||||
$currentUrl = url('/');
|
||||
$currentUrl = str_replace(':8443', ':8440', $currentUrl);
|
||||
|
||||
return redirect($currentUrl . '/phyre-sso.php?server=1&token=' . $ssoToken->token);
|
||||
|
||||
}
|
||||
|
||||
public function validateToken()
|
||||
{
|
||||
$token = request()->input('token');
|
||||
$ssoToken = PHPMyAdminSSOToken::where('token', $token)->first();
|
||||
if (!$ssoToken) {
|
||||
return response()->json(['error' => 'Invalid token'], 400);
|
||||
}
|
||||
|
||||
if ($ssoToken->expires_at < now()) {
|
||||
return response()->json(['error' => 'Token expired'], 400);
|
||||
}
|
||||
|
||||
// Delete token after validation
|
||||
$ssoToken->delete();
|
||||
|
||||
$hostingSubscription = HostingSubscription::where('id', $ssoToken->hosting_subscription_id)->first();
|
||||
if (!$hostingSubscription) {
|
||||
return response()->json(['error' => 'Invalid hosting subscription'], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'databaseLoginDetails' => [
|
||||
'host' => '127.0.0.1',
|
||||
'username' => $hostingSubscription->system_username,
|
||||
'password' => $hostingSubscription->system_password,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace Modules\Customer\App\Providers\Filament;
|
|||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
use Filament\Navigation\NavigationItem;
|
||||
use Filament\Pages;
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<x-filament-panels::page>
|
||||
|
||||
|
||||
<div class="grid grid-cols-4 gap-4">
|
||||
@foreach($hostingSubscriptions as $hostingSubscription)
|
||||
|
||||
<x-filament::section>
|
||||
<div class="flex flex-col gap-4">
|
||||
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<svg class="w-12" viewBox="-7 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
||||
<title>server</title>
|
||||
<path d="M1.125 10.156h15.875c0.594 0 1.125 0.531 1.125 1.125v2.625c0 0.625-0.531 1.125-1.125 1.125h-15.875c-0.625 0-1.125-0.5-1.125-1.125v-2.625c0-0.594 0.5-1.125 1.125-1.125zM16.75 12.844v-0.5c0-0.188-0.188-0.375-0.375-0.375h-2c-0.219 0-0.375 0.188-0.375 0.375v0.5c0 0.219 0.156 0.375 0.375 0.375h2c0.188 0 0.375-0.156 0.375-0.375zM1.125 15.906h15.875c0.594 0 1.125 0.5 1.125 1.125v2.625c0 0.625-0.531 1.125-1.125 1.125h-15.875c-0.625 0-1.125-0.5-1.125-1.125v-2.625c0-0.625 0.5-1.125 1.125-1.125zM16.75 18.594v-0.5c0-0.188-0.188-0.375-0.375-0.375h-2c-0.219 0-0.375 0.188-0.375 0.375v0.5c0 0.219 0.156 0.375 0.375 0.375h2c0.188 0 0.375-0.156 0.375-0.375zM1.125 21.656h15.875c0.594 0 1.125 0.5 1.125 1.125v2.625c0 0.625-0.531 1.125-1.125 1.125h-15.875c-0.625 0-1.125-0.5-1.125-1.125v-2.625c0-0.625 0.5-1.125 1.125-1.125zM16.75 24.344v-0.5c0-0.219-0.188-0.375-0.375-0.375h-2c-0.219 0-0.375 0.156-0.375 0.375v0.5c0 0.219 0.156 0.375 0.375 0.375h2c0.188 0 0.375-0.156 0.375-0.375zM17 9.313h-15.875c-0.188 0-0.375 0.031-0.531 0.094l1.906-2.594c0.375-0.5 1.188-0.906 1.813-0.906h9.5c0.594 0 1.406 0.406 1.781 0.906l1.938 2.594c-0.188-0.063-0.375-0.094-0.531-0.094z"></path>
|
||||
</svg>
|
||||
<h3 class="text-2xl">
|
||||
{{ $hostingSubscription->domain }}
|
||||
</h3>
|
||||
|
||||
</div>
|
||||
|
||||
<x-filament::button
|
||||
href="{{route('customer.phpmyadmin.login', $hostingSubscription->id)}}"
|
||||
tag="a"
|
||||
>
|
||||
Login
|
||||
</x-filament::button>
|
||||
</div>
|
||||
|
||||
</x-filament::section>
|
||||
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
</x-filament-panels::page>
|
|
@ -14,3 +14,5 @@ use Modules\Customer\App\Http\Controllers\CustomerController;
|
|||
|
|
||||
*/
|
||||
|
||||
Route::get('/customer/phpMyAdmin/login/{id}', [\Modules\Customer\App\Http\Controllers\PHPMyAdminController::class, 'login'])
|
||||
->name('customer.phpmyadmin.login');
|
||||
|
|
14
web/app/Models/PHPMyAdminSSOToken.php
Normal file
14
web/app/Models/PHPMyAdminSSOToken.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PHPMyAdminSSOToken extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'phpmyadmin_sso_tokens';
|
||||
|
||||
}
|
|
@ -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
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('phpmyadmin_sso_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('customer_id');
|
||||
$table->unsignedBigInteger('hosting_subscription_id')->nullable();
|
||||
$table->string('token');
|
||||
$table->dateTime('expires_at');
|
||||
$table->string('ip_address');
|
||||
$table->string('user_agent');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('phpmyadmin_sso_tokens');
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue