This commit is contained in:
Bozhidar 2024-09-27 15:57:06 +03:00
parent a2c83d02a8
commit 97483c85f2
5 changed files with 137 additions and 2 deletions

View file

@ -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(),
];
}
}

View file

@ -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('/'),
];
}
}

View file

@ -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,
];
}
}

View file

@ -3,7 +3,7 @@ sudo apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql dovecot-sieve dovecot-managesieved -yq
sudo DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install postfix postfix-mysql -yq
sudo apt-get --no-install-recommends install mailutils -yq
sudo apt-get --no-install-recommends install opendkim opendkim-tools -yq
sudo apt-get --no-install-recommends install opendkim opendkim-tools postfix-policyd-spf-python postfix-pcre -yq
sudo apt-get --no-install-recommends install spamassassin spamc -yq
sudo apt-get --no-install-recommends install clamav clamav-daemon -yq
sudo apt-get --no-install-recommends install amavisd-new -yq
@ -14,6 +14,10 @@ ufw allow 587
ufw allow 465
ufw allow 993
mkdir -p /etc/opendkim/keys
chown -R opendkim:opendkim /etc/opendkim
chmod go-rw /etc/opendkim/keys
echo "Done!"

View file

@ -2,7 +2,7 @@
{{-- @if(auth()->id())
<script>
<script>
let hiddenJobQueueNotifications = [];
function hideJobQueueNotification(jobId) {
hiddenJobQueueNotifications.push(jobId);