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.

70 lines
1.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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. * @author Björn Hase, Tentakelfabrik
  10. * @license http://opensource.org/licenses/MIT The MIT License
  11. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  12. *
  13. */
  14. class Fail2banEnableCommand extends Command
  15. {
  16. // destination to jail
  17. const DESTINATION_FAIL2BAN_JAIL_DIRECTORY = '/etc/fail2ban/jail.d';
  18. // source to jail
  19. const SOURCE_FAIL2BAN_JAIL_DIRECTORY = '/resources/fail2ban/jail.d';
  20. /**
  21. * The signature of the command.
  22. *
  23. * @var string
  24. */
  25. protected $signature = 'fail2ban:enable {configuration}';
  26. /**
  27. * The description of the command.
  28. *
  29. * @var string
  30. */
  31. protected $description = 'enable fail2ban configuration';
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. // getting configuration
  40. $configuration = $this->argument('configuration');
  41. $source = base_path().self::SOURCE_FAIL2BAN_JAIL_DIRECTORY.'/'.$configuration.'.conf';
  42. // configuration not found
  43. if (!file_exists($source)) {
  44. $this->error('fail2ban...configuration not found');
  45. exit();
  46. }
  47. $destination = self::DESTINATION_FAIL2BAN_JAIL_DIRECTORY.'/'.$configuration.'.conf';
  48. // configuration already enabled
  49. if (file_exists($destination)) {
  50. $this->info('fail2ban...configuration already enabled');
  51. exit();
  52. }
  53. copy($source, $destination);
  54. system('service fail2ban restart');
  55. $this->info('Fail2ban...'.$configuration.' enabled');
  56. }
  57. }