OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

4 years ago
  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use Log;
  6. /**
  7. *
  8. *
  9. *
  10. */
  11. class Fail2banEnableCommand extends Command
  12. {
  13. const FAIL2BAN_JAIL_DIRECTORY = '/etc/fail2ban/jail.d';
  14. const RESOURCES_JAIL_DIRECTORY = '/resources/fail2ban/jail.d';
  15. /**
  16. * The signature of the command.
  17. *
  18. * @var string
  19. */
  20. protected $signature = 'fail2ban:enable {configuration}';
  21. /**
  22. * The description of the command.
  23. *
  24. * @var string
  25. */
  26. protected $description = 'enable fail2ban configuration';
  27. /**
  28. * Execute the console command.
  29. *
  30. * @return mixed
  31. */
  32. public function handle()
  33. {
  34. // getting configuration
  35. $configuration = $this->argument('configuration');
  36. $source = base_path().self::RESOURCES_JAIL_DIRECTORY.'/'.$configuration.'.conf';
  37. // configuration not found
  38. if (!file_exists($source)) {
  39. $this->error('fail2ban...configuration not found');
  40. exit();
  41. }
  42. $destination = self::FAIL2BAN_JAIL_DIRECTORY.'/'.$configuration.'.conf';
  43. copy($source, $destination);
  44. $this->info('fail2ban...'.$configuration.' enabled');
  45. exec('service fail2ban restart');
  46. }
  47. }