-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2c83d0
commit 97483c8
Showing
5 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
web/Modules/Email/App/Filament/Resources/DomainsResource/Pages/ListDomains.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Modules\Email\App\Filament\Resources\DomainsResource\Pages; | ||
|
||
use Modules\Email\App\Filament\Resources\EmailDomainResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListDomains extends ListRecords | ||
{ | ||
protected static string $resource = EmailDomainResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
web/Modules/Email/App/Filament/Resources/EmailDomainResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Modules\Email\App\Filament\Resources; | ||
|
||
use App\Models\Domain; | ||
use Modules\Email\App\Filament\Resources\DomainsResource\Pages; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\SoftDeletingScope; | ||
use Modules\Email\App\Models\EmailBox; | ||
use Modules\Email\DkimDomainSetup; | ||
|
||
class EmailDomainResource extends Resource | ||
{ | ||
protected static ?string $model = Domain::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-inbox-stack'; | ||
|
||
protected static ?string $navigationGroup = 'Email'; | ||
|
||
protected static ?int $navigationSort = 0; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
|
||
|
||
|
||
|
||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('domain') | ||
->searchable() | ||
->sortable(), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\Action::make('dkimSetup') | ||
->label('DKIM Setup') | ||
->action(function (Domain $record) { | ||
$output = DkimDomainSetup::run($record->domain); | ||
dd($output); | ||
}) | ||
->icon('heroicon-o-pencil'), | ||
]) | ||
->bulkActions([ | ||
// Tables\Actions\BulkActionGroup::make([ | ||
// Tables\Actions\DeleteBulkAction::make(), | ||
// ]), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListDomains::route('/'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Modules\Email; | ||
|
||
class DkimDomainSetup | ||
{ | ||
|
||
public static function run($domain) | ||
{ | ||
$dkimPrivateKeyFile = '/etc/opendkim/keys/'.$domain.'/dkim.private'; | ||
$dkimTextFile = '/etc/opendkim/keys/'.$domain.'/dkim.txt'; | ||
|
||
if (is_file($dkimPrivateKeyFile)) { | ||
return [ | ||
'privateKey' => file_get_contents($dkimPrivateKeyFile), | ||
'text' => file_get_contents($dkimTextFile), | ||
]; | ||
} | ||
|
||
shell_exec('sudo mkdir -p /etc/opendkim/keys/'.$domain); | ||
shell_exec('sudo chown -R opendkim:opendkim /etc/opendkim/keys/'.$domain); | ||
shell_exec('sudo chmod go-rw /etc/opendkim/keys/'.$domain); | ||
|
||
$output = shell_exec('sudo opendkim-genkey -b 2048 -D /etc/opendkim/keys/'.$domain.' -h rsa-sha256 -r -s dkim -d '.$domain.' -v'); | ||
|
||
$dkimPrivateKey = file_get_contents($dkimPrivateKeyFile); | ||
$dkimText = file_get_contents($dkimTextFile); | ||
|
||
return [ | ||
'privateKey' => $dkimPrivateKey, | ||
'text' => $dkimText, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters