Merge remote-tracking branch 'parent/main' into kb_migration_development
This commit is contained in:
commit
551a676161
67 changed files with 751 additions and 548 deletions
|
@ -11,7 +11,7 @@ module Mastodon
|
|||
true
|
||||
end
|
||||
|
||||
option :severity, required: true, enum: %w(no_access sign_up_requires_approval), desc: 'Severity of the block'
|
||||
option :severity, required: true, enum: %w(no_access sign_up_requires_approval sign_up_block), desc: 'Severity of the block'
|
||||
option :comment, aliases: [:c], desc: 'Optional comment'
|
||||
option :duration, aliases: [:d], type: :numeric, desc: 'Duration of the block in seconds'
|
||||
option :force, type: :boolean, aliases: [:f], desc: 'Overwrite existing blocks'
|
||||
|
@ -36,6 +36,12 @@ module Mastodon
|
|||
failed = 0
|
||||
|
||||
addresses.each do |address|
|
||||
unless valid_ip_address?(address)
|
||||
say("#{address} is invalid", :red)
|
||||
failed += 1
|
||||
next
|
||||
end
|
||||
|
||||
ip_block = IpBlock.find_by(ip: address)
|
||||
|
||||
if ip_block.present? && !options[:force]
|
||||
|
@ -79,6 +85,12 @@ module Mastodon
|
|||
skipped = 0
|
||||
|
||||
addresses.each do |address|
|
||||
unless valid_ip_address?(address)
|
||||
say("#{address} is invalid", :yellow)
|
||||
skipped += 1
|
||||
next
|
||||
end
|
||||
|
||||
ip_blocks = if options[:force]
|
||||
IpBlock.where('ip >>= ?', address)
|
||||
else
|
||||
|
@ -126,5 +138,12 @@ module Mastodon
|
|||
:red
|
||||
end
|
||||
end
|
||||
|
||||
def valid_ip_address?(ip_address)
|
||||
IPAddr.new(ip_address)
|
||||
true
|
||||
rescue IPAddr::InvalidAddressError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue