01ed0f3080
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
229 lines
8.6 KiB
PHP
229 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace KTXC\Module;
|
|
|
|
use KTXC\Console\Firewall\FirewallMaintenanceCommand;
|
|
use KTXC\Console\Firewall\FirewallSetupCommand;
|
|
use KTXC\Service\FirewallService;
|
|
use KTXC\Service\SystemFirewallLogService;
|
|
use KTXC\Service\SystemFirewallRuleService;
|
|
use KTXC\Service\SystemFirewallStatusService;
|
|
use KTXC\Service\TenantFirewallLogService;
|
|
use KTXC\Service\TenantFirewallRuleService;
|
|
use KTXC\Service\TenantFirewallStatusService;
|
|
use KTXF\Event\DeliveryMode;
|
|
use KTXF\Event\EventListenerRegistrarInterface;
|
|
use KTXF\Event\SecurityEvent;
|
|
use KTXF\Module\ModuleBrowserInterface;
|
|
use KTXF\Module\ModuleConsoleInterface;
|
|
use KTXF\Module\ModuleInstanceAbstract;
|
|
|
|
/**
|
|
* Core Module
|
|
*
|
|
* Provides core system functionality and permissions
|
|
*/
|
|
class Module extends ModuleInstanceAbstract implements ModuleConsoleInterface, ModuleBrowserInterface
|
|
{
|
|
public function __construct(
|
|
private readonly EventListenerRegistrarInterface $events,
|
|
) {
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
$this->events->listen(
|
|
'core',
|
|
SecurityEvent::AUTH_FAILURE,
|
|
FirewallService::class,
|
|
'handleAuthFailure',
|
|
priority: 100,
|
|
);
|
|
|
|
foreach ([
|
|
SecurityEvent::AUTH_SUCCESS,
|
|
SecurityEvent::ACCESS_DENIED,
|
|
SecurityEvent::BRUTE_FORCE_DETECTED,
|
|
SecurityEvent::RATE_LIMIT_EXCEEDED,
|
|
SecurityEvent::SUSPICIOUS_ACTIVITY,
|
|
SecurityEvent::FIREWALL_RULE_CREATED,
|
|
SecurityEvent::FIREWALL_RULE_EXTENDED,
|
|
SecurityEvent::FIREWALL_RULE_ENABLED,
|
|
SecurityEvent::FIREWALL_RULE_DISABLED,
|
|
SecurityEvent::FIREWALL_RULE_REMOVED,
|
|
SecurityEvent::FIREWALL_SETTINGS_UPDATED,
|
|
] as $event) {
|
|
$this->events->listen(
|
|
'core',
|
|
$event,
|
|
FirewallService::class,
|
|
'logSecurityEvent',
|
|
DeliveryMode::Deferred,
|
|
);
|
|
}
|
|
}
|
|
|
|
public function handle(): string
|
|
{
|
|
return 'core';
|
|
}
|
|
|
|
public function label(): string
|
|
{
|
|
return 'Core System';
|
|
}
|
|
|
|
public function author(): string
|
|
{
|
|
return 'Vallarx';
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return 'Core system functionality and user features';
|
|
}
|
|
|
|
public function version(): string
|
|
{
|
|
return '0.0.1';
|
|
}
|
|
|
|
public function permissions(): array
|
|
{
|
|
return [
|
|
// Core User Permissions
|
|
'user.profile.read' => [
|
|
'label' => 'Read Own Profile',
|
|
'description' => 'View own user profile information',
|
|
'group' => 'User Profile'
|
|
],
|
|
'user.profile.update' => [
|
|
'label' => 'Update Own Profile',
|
|
'description' => 'Edit own user profile information',
|
|
'group' => 'User Profile'
|
|
],
|
|
'user.settings.read' => [
|
|
'label' => 'Read Own Settings',
|
|
'description' => 'View own user settings',
|
|
'group' => 'User Settings'
|
|
],
|
|
'user.settings.update' => [
|
|
'label' => 'Update Own Settings',
|
|
'description' => 'Edit own user settings',
|
|
'group' => 'User Settings'
|
|
],
|
|
|
|
// Module Management
|
|
'module_manager.modules.view' => [
|
|
'label' => 'View Modules',
|
|
'description' => 'View list of installed and available modules',
|
|
'group' => 'Module Management'
|
|
],
|
|
'module_manager.modules.manage' => [
|
|
'label' => 'Manage Modules',
|
|
'description' => 'Install, uninstall, enable, and disable modules',
|
|
'group' => 'Module Management'
|
|
],
|
|
'module_manager.modules.*' => [
|
|
'label' => 'Full Module Management',
|
|
'description' => 'All module management operations',
|
|
'group' => 'Module Management'
|
|
],
|
|
|
|
// Firewall Management
|
|
TenantFirewallRuleService::PERMISSION_READ => [
|
|
'label' => 'View Tenant Firewall Rules',
|
|
'description' => 'View firewall rules owned by the current tenant',
|
|
'group' => 'Firewall Management'
|
|
],
|
|
TenantFirewallRuleService::PERMISSION_MANAGE => [
|
|
'label' => 'Manage Tenant Firewall Rules',
|
|
'description' => 'Create, disable, and remove firewall rules owned by the current tenant',
|
|
'group' => 'Firewall Management'
|
|
],
|
|
TenantFirewallLogService::PERMISSION_READ => [
|
|
'label' => 'View Tenant Firewall Logs',
|
|
'description' => 'View firewall security and audit logs owned by the current tenant',
|
|
'group' => 'Firewall Management'
|
|
],
|
|
TenantFirewallStatusService::PERMISSION_SETTINGS_READ => [
|
|
'label' => 'View Tenant Firewall Settings',
|
|
'description' => 'View effective firewall settings for the current tenant',
|
|
'group' => 'Firewall Management'
|
|
],
|
|
TenantFirewallStatusService::PERMISSION_SETTINGS_MANAGE => [
|
|
'label' => 'Manage Tenant Firewall Settings',
|
|
'description' => 'Update firewall settings for the current tenant',
|
|
'group' => 'Firewall Management'
|
|
],
|
|
SystemFirewallRuleService::PERMISSION_READ => [
|
|
'label' => 'View System Firewall Rules',
|
|
'description' => 'View firewall rules that apply to every tenant',
|
|
'group' => 'System Administration'
|
|
],
|
|
SystemFirewallRuleService::PERMISSION_MANAGE => [
|
|
'label' => 'Manage System Firewall Rules',
|
|
'description' => 'Create, disable, and remove firewall rules that apply to every tenant',
|
|
'group' => 'System Administration'
|
|
],
|
|
SystemFirewallLogService::PERMISSION_READ => [
|
|
'label' => 'View System Firewall Logs',
|
|
'description' => 'View firewall security and audit logs across tenants',
|
|
'group' => 'System Administration'
|
|
],
|
|
SystemFirewallStatusService::PERMISSION_MAINTENANCE_READ => [
|
|
'label' => 'View Firewall Maintenance Status',
|
|
'description' => 'View the last firewall cleanup result and operational status',
|
|
'group' => 'System Administration'
|
|
],
|
|
SystemFirewallStatusService::PERMISSION_SETTINGS_MANAGE => [
|
|
'label' => 'Manage Tenant Firewall Settings System-Wide',
|
|
'description' => 'Update firewall settings for any tenant',
|
|
'group' => 'System Administration'
|
|
],
|
|
'system.admin' => [
|
|
'label' => 'System Administrator',
|
|
'description' => 'Full system access (superuser)',
|
|
'group' => 'System Administration'
|
|
],
|
|
'*' => [
|
|
'label' => 'All Permissions',
|
|
'description' => 'Grants access to all features and operations',
|
|
'group' => 'System Administration'
|
|
],
|
|
];
|
|
}
|
|
|
|
public function registerCI(): array
|
|
{
|
|
return [
|
|
FirewallSetupCommand::class,
|
|
FirewallMaintenanceCommand::class,
|
|
\KTXC\Console\Event\EventsDebugCommand::class,
|
|
\KTXC\Console\Module\ModuleListCommand::class,
|
|
\KTXC\Console\Module\ModuleEnableCommand::class,
|
|
\KTXC\Console\Module\ModuleDisableCommand::class,
|
|
\KTXC\Console\Module\ModuleInstallCommand::class,
|
|
\KTXC\Console\Module\ModuleUninstallCommand::class,
|
|
\KTXC\Console\Module\ModuleUpgradeCommand::class,
|
|
\KTXC\Console\Tenant\TenantCreateCommand::class,
|
|
\KTXC\Console\Tenant\TenantListCommand::class,
|
|
\KTXC\Console\Tenant\TenantDeleteCommand::class,
|
|
\KTXC\Console\Tenant\TenantAuthEnableCommand::class,
|
|
\KTXC\Console\User\UserCreateCommand::class,
|
|
\KTXC\Console\User\UserListCommand::class,
|
|
\KTXC\Console\User\UserDeleteCommand::class,
|
|
\KTXC\Console\Role\RoleCreateCommand::class,
|
|
\KTXC\Console\Role\RoleListCommand::class,
|
|
\KTXC\Console\Role\RoleDeleteCommand::class,
|
|
\KTXC\Console\Role\RoleAssignCommand::class,
|
|
\KTXC\Console\Role\RoleRevokeCommand::class,
|
|
];
|
|
}
|
|
|
|
public function registerBI(): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|