41 lines
787 B
Ruby
41 lines
787 B
Ruby
|
require 'ipaddr'
|
||
|
|
||
|
class Raven
|
||
|
class IpTrackerController
|
||
|
|
||
|
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
|
||
|
|
||
|
get '/delete/:ip_id' do
|
||
|
ip = IpAddress.where(id: params[:ip_id]).first()
|
||
|
ip.delete()
|
||
|
|
||
|
redirect '/ip-tracker'
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|