raven/lib/routes/ip_tracker.rb

39 lines
715 B
Ruby
Raw Normal View History

2022-12-22 12:50:01 -05:00
require 'ipaddr'
namespace '/ip-tracker' do
get '' do
ip_addresses = IpAddress.all()
ip_addresses.sort! { |a,b| IPAddr.new( a.address ) <=> IPAddr.new( b.address ) }
erb :'ip/ip-tracker', :locals => {
:title => 'IP Tracker',
:ip_addresses => ip_addresses
}
end
get '/add' do
erb :'ip/add', :locals => {
:title => 'Add IP Address'
}
end
post '/add' do
ip = IpAddress.create(
address: params[:ip_address],
dns_name: params[:ip_dns],
comment: params[:ip_comment]
)
redirect '/ip-tracker'
end
2022-12-22 13:08:35 -05:00
get '/delete/:ip_id' do
ip = IpAddress.where(id: params[:ip_id]).first()
ip.delete()
redirect '/ip-tracker'
end
2022-12-22 12:50:01 -05:00
end