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.

67 lines
1.6 KiB

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