WIP
Signed-off-by: Nguyen Van Nguyen <nguyennv1981@gmail.com>
This commit is contained in:
parent
2325493de7
commit
959d50339a
3 changed files with 48 additions and 3 deletions
|
@ -9,10 +9,13 @@
|
|||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Settings\ZimbraSettings;
|
||||
use App\Support\ZimbraAdminClient;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\SettingsPage;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
|
||||
/**
|
||||
* Zimbra settings page
|
||||
|
@ -52,8 +55,43 @@ class ManageZimbraSettings extends SettingsPage
|
|||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('test_connection')
|
||||
->label(__('Test Connection')),
|
||||
Action::make('test_connection')->action(
|
||||
fn () => $this->testConnection()
|
||||
)->label(__('Test Connection')),
|
||||
];
|
||||
}
|
||||
|
||||
public function afterValidate()
|
||||
{
|
||||
if (!$this->testConnection(false)) {
|
||||
throw (new Halt())->rollBackDatabaseTransaction(false);
|
||||
}
|
||||
}
|
||||
|
||||
private function testConnection(bool $notifySuccess = true): bool
|
||||
{
|
||||
try {
|
||||
$data = $this->getForm()->getState();
|
||||
$client = new ZimbraAdminClient($data['serviceUrl']);
|
||||
$client->auth(
|
||||
$data['adminUser'], $data['adminPassword']
|
||||
);
|
||||
if ($notifySuccess) {
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('Connection to zimbra service success!'))
|
||||
->send();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (\Throwable $t) {
|
||||
logger()->error($t);
|
||||
Notification::make()
|
||||
->warning()
|
||||
->title(__('Connection to zimbra service failed!'))
|
||||
->body($t->getMessage())
|
||||
->send();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Traits\ForwardsCalls;
|
||||
use PsrDiscovery\Implementations\Psr18\Clients;
|
||||
use Zimbra\Admin\AdminApi;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +28,11 @@ class ZimbraAdminClient
|
|||
|
||||
public function __construct(string $serviceUrl)
|
||||
{
|
||||
$debug = config('app.debug');
|
||||
Clients::use(Http::withOptions([
|
||||
'debug' => $debug,
|
||||
'verify' => !$debug,
|
||||
])->buildClient());
|
||||
$this->api = new AdminApi($serviceUrl);
|
||||
$this->api->setLoger(logger());
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
'name' => env('APP_NAME', 'Zimbra Admin Panel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue