Bozhidar Slaveykov 1 anno fa
parent
commit
4911892173

BIN
web/Modules/.DS_Store


BIN
web/Modules/LetsEncrypt/.DS_Store


BIN
web/Modules/LetsEncrypt/Actions/acmephp.phar


+ 9 - 0
web/Modules/LetsEncrypt/Actions/acmephp.phar.pubkey

@@ -0,0 +1,9 @@
+-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArRmu5WOZsz50RBvtUU05
+wZ66jQrAjmJ4t9Kj2+iaynX5OY05d9dH9v+JF9x6dCo+D6dSJLcAyA4/Cosq3TW/
+rDVSY9eIUsuxr4OlmguFLfHa9vML9Ot1f/z/4uxXhUuG1w15TkqhIvxbHdMes0mH
+5nA54uHVki5RSQrN08ebawBkxRbp/gG7qvMPxNhBdyTwZ6T7TUJSDWqZYzS6XcjR
+F1qzOhucAo1lqT7B2XBGYdsEHngZNTVlc4VAdj2ZajOSJdEYsOoxXGV20JFS22lr
+I1a4Sp6jm9stBuagttfsI5c2kTplfpMbGEDsj+jeNwY7rFfghy4d0G1xZQKarcBO
+iQIDAQAB
+-----END PUBLIC KEY-----

+ 1 - 0
web/Modules/LetsEncrypt/App/Providers/LetsEncryptServiceProvider.php

@@ -4,6 +4,7 @@ namespace Modules\LetsEncrypt\App\Providers;
 
 
 use App\Events\HostingAccountIsCreated;
 use App\Events\HostingAccountIsCreated;
 use Illuminate\Support\Facades\Blade;
 use Illuminate\Support\Facades\Blade;
+use Illuminate\Support\Facades\Event;
 use Illuminate\Support\ServiceProvider;
 use Illuminate\Support\ServiceProvider;
 use Modules\LetsEncrypt\Listeners\HostingAccountIsCreatedListener;
 use Modules\LetsEncrypt\Listeners\HostingAccountIsCreatedListener;
 use Modules\LetsEncrypt\Providers\Filament\AdminPanelProvider;
 use Modules\LetsEncrypt\Providers\Filament\AdminPanelProvider;

+ 26 - 1
web/Modules/LetsEncrypt/Listeners/HostingAccountIsCreatedListener.php

@@ -2,7 +2,11 @@
 
 
 namespace Modules\LetsEncrypt\Listeners;
 namespace Modules\LetsEncrypt\Listeners;
 
 
+use App\ApiClient;
 use App\Events\HostingAccountIsCreated;
 use App\Events\HostingAccountIsCreated;
+use App\FileManagerApi;
+use App\Settings;
+use App\ShellApi;
 
 
 class HostingAccountIsCreatedListener
 class HostingAccountIsCreatedListener
 {
 {
@@ -20,7 +24,28 @@ class HostingAccountIsCreatedListener
     public function handle(HostingAccountIsCreated $event): void
     public function handle(HostingAccountIsCreated $event): void
     {
     {
 
 
-        dd($event);
+        $generalSettings = Settings::general();
+
+        $acmeConfigYaml = view('letsencrypt::actions.acme-config-yaml', [
+            'domain' => $event->model->domain,
+            'domainRoot' => $event->model->domain_root,
+            'email' => $generalSettings['master_email'],
+            'country' => $generalSettings['master_country'],
+            'locality' => $generalSettings['master_locality'],
+            'organization' => $generalSettings['organization_name'],
+        ])->render();
+
+        $fmApi = new FileManagerApi();
+        $fmApi->filePutContents($event->model->domain_root . '/acme-config.yaml', $acmeConfigYaml);
+
+        $amePHPPharFile = base_path() . '/Modules/LetsEncrypt/Actions/acmephp.phar';
+
+        $phyrePHP = ApiClient::getPhyrePHP();
+        $command = $phyrePHP . ' ' . $amePHPPharFile . ' run ' . $event->model->domain_root . '/acme-config.yaml';
+        $execPhar = ShellApi::exec($command);
+
+
+        dd($execPhar);
 
 
     }
     }
 }
 }

+ 15 - 0
web/Modules/LetsEncrypt/resources/views/actions/acme-config-yaml.blade.php

@@ -0,0 +1,15 @@
+contact_email: {{ $email }}
+
+defaults:
+  distinguished_name:
+    country: {{ $country }}
+    locality: {{ $locality }}
+    organization_name: {{ $organization }}
+  solver: http
+
+certificates:
+  - domain: {{ $domain }}
+    solver:
+      name: http-file
+      adapter: local
+      root: {{ $domainRoot }}

+ 11 - 0
web/app/ApiClient.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App;
+
+class ApiClient
+{
+    public static function getPhyrePHP()
+    {
+        return "/usr/local/phyre/php/bin/php";
+    }
+}

+ 28 - 0
web/app/Filament/Pages/Settings/Settings.php

@@ -0,0 +1,28 @@
+<?php
+namespace App\Filament\Pages\Settings;
+
+use Closure;
+use Filament\Forms\Components\Tabs;
+use Filament\Forms\Components\TextInput;
+use Outerweb\FilamentSettings\Filament\Pages\Settings as BaseSettings;
+
+class Settings extends BaseSettings
+{
+    public function schema(): array|Closure
+    {
+        return [
+            Tabs::make('Settings')
+                ->schema([
+                    Tabs\Tab::make('General')
+                        ->schema([
+                            TextInput::make('general.brand_name'),
+                            TextInput::make('general.master_domain'),
+                            TextInput::make('general.master_email'),
+                            TextInput::make('general.master_country'),
+                            TextInput::make('general.master_locality'),
+                            TextInput::make('general.organization_name'),
+                        ]),
+                ]),
+        ];
+    }
+}

+ 8 - 0
web/app/Providers/Filament/AdminPanelProvider.php

@@ -2,6 +2,7 @@
 
 
 namespace App\Providers\Filament;
 namespace App\Providers\Filament;
 
 
+use App\Filament\Pages\Settings\Settings;
 use Filament\Http\Middleware\Authenticate;
 use Filament\Http\Middleware\Authenticate;
 use Filament\Http\Middleware\DisableBladeIconComponents;
 use Filament\Http\Middleware\DisableBladeIconComponents;
 use Filament\Http\Middleware\DispatchServingFilamentEvent;
 use Filament\Http\Middleware\DispatchServingFilamentEvent;
@@ -17,6 +18,7 @@ use Illuminate\Routing\Middleware\SubstituteBindings;
 use Illuminate\Session\Middleware\AuthenticateSession;
 use Illuminate\Session\Middleware\AuthenticateSession;
 use Illuminate\Session\Middleware\StartSession;
 use Illuminate\Session\Middleware\StartSession;
 use Illuminate\View\Middleware\ShareErrorsFromSession;
 use Illuminate\View\Middleware\ShareErrorsFromSession;
+use Outerweb\FilamentSettings\Filament\Plugins\FilamentSettingsPlugin;
 
 
 class AdminPanelProvider extends PanelProvider
 class AdminPanelProvider extends PanelProvider
 {
 {
@@ -36,6 +38,12 @@ class AdminPanelProvider extends PanelProvider
             ->pages([
             ->pages([
                 Pages\Dashboard::class,
                 Pages\Dashboard::class,
             ])
             ])
+            ->plugins([
+                FilamentSettingsPlugin::make()
+                ->pages([
+                    Settings::class,
+                ])
+            ])
             ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
             ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
             ->widgets([
             ->widgets([
                 Widgets\AccountWidget::class,
                 Widgets\AccountWidget::class,

+ 30 - 0
web/app/Settings.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App;
+
+class Settings
+{
+    public static $general = [
+        'brand_name' => 'Phyre Panel',
+        'master_domain' => '',
+        'master_email' => '',
+        'master_country' => '',
+        'master_locality' => '',
+        'organization_name' => '',
+    ];
+
+    public static function general()
+    {
+        $settings = setting('general');
+        if (!empty($settings)) {
+            foreach ($settings as $key => $value) {
+                if (isset(self::$general[$key])) {
+                    self::$general[$key] = $value;
+                }
+            }
+        }
+
+        return self::$general;
+    }
+
+}

+ 2 - 0
web/composer.json

@@ -19,7 +19,9 @@
         "laravel/tinker": "^2.8",
         "laravel/tinker": "^2.8",
         "mkocansey/bladewind": "^2.4",
         "mkocansey/bladewind": "^2.4",
         "nwidart/laravel-modules": "^10.0",
         "nwidart/laravel-modules": "^10.0",
+        "outerweb/filament-settings": "^1.2",
         "symfony/process": "^6.3",
         "symfony/process": "^6.3",
+        "symfony/yaml": "^7.0",
         "wikimedia/composer-merge-plugin": "^2.1"
         "wikimedia/composer-merge-plugin": "^2.1"
     },
     },
     "require-dev": {
     "require-dev": {

+ 180 - 72
web/composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
         "This file is @generated automatically"
     ],
     ],
-    "content-hash": "91465f398b2f15e47d8ac1fb10247588",
+    "content-hash": "ff8c4be52b0fdfdcc29302b03f0e456f",
     "packages": [
     "packages": [
         {
         {
             "name": "acmephp/core",
             "name": "acmephp/core",
@@ -4577,6 +4577,114 @@
             ],
             ],
             "time": "2024-01-09T09:30:37+00:00"
             "time": "2024-01-09T09:30:37+00:00"
         },
         },
+        {
+            "name": "outerweb/filament-settings",
+            "version": "v1.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/outer-web/filament-settings.git",
+                "reference": "5c5c58e7271269de1f81af8acdade9ad4c319b6a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/outer-web/filament-settings/zipball/5c5c58e7271269de1f81af8acdade9ad4c319b6a",
+                "reference": "5c5c58e7271269de1f81af8acdade9ad4c319b6a",
+                "shasum": ""
+            },
+            "require": {
+                "filament/filament": "^3.2",
+                "laravel/framework": "^10.0|^11.0",
+                "outerweb/settings": "^1.0",
+                "php": "^8.0",
+                "spatie/laravel-package-tools": "^1.16"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Outerweb\\FilamentSettings\\FilamentSettingsServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src\\Helpers\\helpers.php"
+                ],
+                "psr-4": {
+                    "Outerweb\\FilamentSettings\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Outerweb",
+                    "email": "info@outerweb.be"
+                }
+            ],
+            "description": "This package adds a way to interact with outerweb/settings in Filament.",
+            "homepage": "https://github.com/outer-web/filament-settings",
+            "support": {
+                "issues": "https://github.com/outer-web/filament-settings/issues",
+                "source": "https://github.com/outer-web/filament-settings/tree/v1.2.0"
+            },
+            "time": "2024-03-25T15:53:11+00:00"
+        },
+        {
+            "name": "outerweb/settings",
+            "version": "v1.0.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/outer-web/settings.git",
+                "reference": "259a0742b986ecb5f7e74a02c0c495330b6010d3"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/outer-web/settings/zipball/259a0742b986ecb5f7e74a02c0c495330b6010d3",
+                "reference": "259a0742b986ecb5f7e74a02c0c495330b6010d3",
+                "shasum": ""
+            },
+            "require": {
+                "laravel/framework": "^10.0|^11.0",
+                "php": "^8.0",
+                "spatie/laravel-package-tools": "^1.16"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Outerweb\\Settings\\SettingsServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src\\Helpers\\helpers.php"
+                ],
+                "psr-4": {
+                    "Outerweb\\Settings\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Outerweb",
+                    "email": "info@outerweb.be"
+                }
+            ],
+            "description": "This package adds application wide settings stored in your database.",
+            "homepage": "https://github.com/outer-web/settings",
+            "support": {
+                "issues": "https://github.com/outer-web/settings/issues",
+                "source": "https://github.com/outer-web/settings/tree/v1.0.3"
+            },
+            "time": "2024-03-12T20:47:31+00:00"
+        },
         {
         {
             "name": "phpoption/phpoption",
             "name": "phpoption/phpoption",
             "version": "1.9.2",
             "version": "1.9.2",
@@ -7972,6 +8080,77 @@
             ],
             ],
             "time": "2024-02-15T11:23:52+00:00"
             "time": "2024-02-15T11:23:52+00:00"
         },
         },
+        {
+            "name": "symfony/yaml",
+            "version": "v7.0.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/yaml.git",
+                "reference": "2d4fca631c00700597e9442a0b2451ce234513d3"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/yaml/zipball/2d4fca631c00700597e9442a0b2451ce234513d3",
+                "reference": "2d4fca631c00700597e9442a0b2451ce234513d3",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=8.2",
+                "symfony/polyfill-ctype": "^1.8"
+            },
+            "conflict": {
+                "symfony/console": "<6.4"
+            },
+            "require-dev": {
+                "symfony/console": "^6.4|^7.0"
+            },
+            "bin": [
+                "Resources/bin/yaml-lint"
+            ],
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Yaml\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Loads and dumps YAML files",
+            "homepage": "https://symfony.com",
+            "support": {
+                "source": "https://github.com/symfony/yaml/tree/v7.0.3"
+            },
+            "funding": [
+                {
+                    "url": "https://symfony.com/sponsor",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/fabpot",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2024-01-23T15:02:46+00:00"
+        },
         {
         {
             "name": "tijsverkoyen/css-to-inline-styles",
             "name": "tijsverkoyen/css-to-inline-styles",
             "version": "v2.2.7",
             "version": "v2.2.7",
@@ -10613,77 +10792,6 @@
             ],
             ],
             "time": "2024-04-02T06:30:22+00:00"
             "time": "2024-04-02T06:30:22+00:00"
         },
         },
-        {
-            "name": "symfony/yaml",
-            "version": "v7.0.3",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/symfony/yaml.git",
-                "reference": "2d4fca631c00700597e9442a0b2451ce234513d3"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/symfony/yaml/zipball/2d4fca631c00700597e9442a0b2451ce234513d3",
-                "reference": "2d4fca631c00700597e9442a0b2451ce234513d3",
-                "shasum": ""
-            },
-            "require": {
-                "php": ">=8.2",
-                "symfony/polyfill-ctype": "^1.8"
-            },
-            "conflict": {
-                "symfony/console": "<6.4"
-            },
-            "require-dev": {
-                "symfony/console": "^6.4|^7.0"
-            },
-            "bin": [
-                "Resources/bin/yaml-lint"
-            ],
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "Symfony\\Component\\Yaml\\": ""
-                },
-                "exclude-from-classmap": [
-                    "/Tests/"
-                ]
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Fabien Potencier",
-                    "email": "fabien@symfony.com"
-                },
-                {
-                    "name": "Symfony Community",
-                    "homepage": "https://symfony.com/contributors"
-                }
-            ],
-            "description": "Loads and dumps YAML files",
-            "homepage": "https://symfony.com",
-            "support": {
-                "source": "https://github.com/symfony/yaml/tree/v7.0.3"
-            },
-            "funding": [
-                {
-                    "url": "https://symfony.com/sponsor",
-                    "type": "custom"
-                },
-                {
-                    "url": "https://github.com/fabpot",
-                    "type": "github"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
-                    "type": "tidelift"
-                }
-            ],
-            "time": "2024-01-23T15:02:46+00:00"
-        },
         {
         {
             "name": "theseer/tokenizer",
             "name": "theseer/tokenizer",
             "version": "1.2.3",
             "version": "1.2.3",

+ 26 - 0
web/database/migrations/2024_04_02_120943_create_settings_table.php

@@ -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(config('settings.database_table_name'), function (Blueprint $table) {
+            $table->id();
+            $table->string('key')
+                ->unique()
+                ->index();
+            $table->json('value')
+                ->nullable();
+            $table->timestamps();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists(config('settings.database_table_name'));
+    }
+};

+ 11 - 0
web/routes/web.php

@@ -36,3 +36,14 @@ Route::get('/', function () {
     return view('welcome');
     return view('welcome');
 
 
 });
 });
+
+Route::get('dev', function () {
+
+    $findWebsite = \App\Models\Website::where('id', 11)->first();
+    $findWebsite->domain_root = '/var/www/' . $findWebsite->domain;
+    $findWebsite->save();
+
+    event(new \App\Events\HostingAccountIsCreated($findWebsite));
+
+
+});