|
|
- <?php
-
- namespace App\Commands;
-
- use Illuminate\Console\Scheduling\Schedule;
- use LaravelZero\Framework\Commands\Command;
-
- use Log;
-
- /**
- *
- *
- *
- */
- class Fail2banEnableCommand extends Command
- {
- const FAIL2BAN_JAIL_DIRECTORY = '/etc/fail2ban/jail.d';
- const RESOURCES_JAIL_DIRECTORY = '/resources/fail2ban/jail.d';
-
- /**
- * The signature of the command.
- *
- * @var string
- */
- protected $signature = 'fail2ban:enable {configuration}';
-
- /**
- * The description of the command.
- *
- * @var string
- */
- protected $description = 'enable fail2ban configuration';
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- // getting configuration
- $configuration = $this->argument('configuration');
-
- $source = base_path().self::RESOURCES_JAIL_DIRECTORY.'/'.$configuration.'.conf';
-
- // configuration not found
- if (!file_exists($source)) {
- $this->error('fail2ban...configuration not found');
- exit();
- }
-
- $destination = self::FAIL2BAN_JAIL_DIRECTORY.'/'.$configuration.'.conf';
-
- copy($source, $destination);
- $this->info('fail2ban...'.$configuration.' enabled');
-
- exec('service fail2ban restart');
- }
- }
|