-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tasks to ban/unban IP addresses in jails
The fail2ban-client tool allows a large panel of acions. Start with the most simple and frequently used ones to ban/unban IP addresses in fail2ban jails. Next time I lock me out of a system through SSH, I will be happy to rely on these tasks with choria to unlock me.
- Loading branch information
Showing
7 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |