Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tasks to ban/unban IP addresses in jails #209

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
* [`fail2ban::define`](#fail2ban--define): == Define: fail2ban::define
* [`fail2ban::jail`](#fail2ban--jail): == Define: fail2ban::jail

### Tasks

* [`banip`](#banip): Ban IPs in a jail
* [`unban`](#unban): Unban IP in all jails and database
* [`unbanip`](#unbanip): Unban IP in a jail

## Classes

### <a name="fail2ban"></a>`fail2ban`
Expand Down Expand Up @@ -705,3 +711,59 @@ Data type: `Optional[String]`

Default value: `$fail2ban::config_file_require`

## Tasks

### <a name="banip"></a>`banip`

Ban IPs in a jail

**Supports noop?** false

#### Parameters

##### `jail`

Data type: `String[1]`

The jail to operate on

##### `ips`

Data type: `Array[Stdlib::IP::Address]`

IP addresses to ban

### <a name="unban"></a>`unban`

Unban IP in all jails and database

**Supports noop?** false

#### Parameters

##### `ips`

Data type: `Array[Stdlib::IP::Address]`

IP addresses to unban

### <a name="unbanip"></a>`unbanip`

Unban IP in a jail

**Supports noop?** false

#### Parameters

##### `jail`

Data type: `String[1]`

The jail to operate on

##### `ips`

Data type: `Array[Stdlib::IP::Address]`

IP addresses to unban

17 changes: 17 additions & 0 deletions tasks/banip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"description": "Ban IPs in a jail",
"input_method": "stdin",
"files": [
"ruby_task_helper/files/task_helper.rb"
],
"parameters": {
"jail": {
"description": "The jail to operate on",
"type": "String[1]"
},
"ips": {
"description": "IP addresses to ban",
"type": "Array[Stdlib::IP::Address]"
}
}
}
17 changes: 17 additions & 0 deletions tasks/banip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../../ruby_task_helper/files/task_helper'

class Fail2banBanipTask < TaskHelper
def task(jail:, ips:, **_kwargs)
command = ['fail2ban-client', 'set', jail, 'banip'] + ips

pid = Process.spawn(*command)
Process.wait(pid)

nil
end
end

Fail2banBanipTask.run if $PROGRAM_NAME == __FILE__
13 changes: 13 additions & 0 deletions tasks/unban.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "Unban IP in all jails and database",
"input_method": "stdin",
"files": [
"ruby_task_helper/files/task_helper.rb"
],
"parameters": {
"ips": {
"description": "IP addresses to unban",
"type": "Array[Stdlib::IP::Address]"
}
}
}
17 changes: 17 additions & 0 deletions tasks/unban.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../../ruby_task_helper/files/task_helper'

class Fail2banUnbanTask < TaskHelper
def task(ips:, **_kwargs)
command = %w[fail2ban-client unban] + ips

pid = Process.spawn(*command)
Process.wait(pid)

nil
end
end

Fail2banUnbanTask.run if $PROGRAM_NAME == __FILE__
17 changes: 17 additions & 0 deletions tasks/unbanip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"description": "Unban IP in a jail",
"input_method": "stdin",
"files": [
"ruby_task_helper/files/task_helper.rb"
],
"parameters": {
"jail": {
"description": "The jail to operate on",
"type": "String[1]"
},
"ips": {
"description": "IP addresses to unban",
"type": "Array[Stdlib::IP::Address]"
}
}
}
17 changes: 17 additions & 0 deletions tasks/unbanip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../../ruby_task_helper/files/task_helper'

class Fail2banUnbanipTask < TaskHelper
def task(jail:, ips:, **_kwargs)
command = ['fail2ban-client', 'set', jail, 'unbanip'] + ips

pid = Process.spawn(*command)
Process.wait(pid)

nil
end
end

Fail2banUnbanipTask.run if $PROGRAM_NAME == __FILE__
Loading