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

<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
/**
* Enable Fail2ban Configuration
*
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
*
*/
class Fail2banEnableCommand extends Command
{
// destination to jail
const DESTINATION_FAIL2BAN_JAIL_DIRECTORY = '/etc/fail2ban/jail.d';
// source to jail
const SOURCE_FAIL2BAN_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::SOURCE_FAIL2BAN_JAIL_DIRECTORY.'/'.$configuration.'.conf';
// configuration not found
if (!file_exists($source)) {
$this->error('fail2ban...configuration not found');
exit();
}
$destination = self::DESTINATION_FAIL2BAN_JAIL_DIRECTORY.'/'.$configuration.'.conf';
// configuration already enabled
if (file_exists($destination)) {
$this->info('fail2ban...configuration already enabled');
exit();
}
copy($source, $destination);
exec('service fail2ban restart');
$this->info('Fail2ban...'.$configuration.' enabled');
}
}