Added basic IP tracker functionality
This commit is contained in:
parent
97ced7d80e
commit
10345d5238
18
db/migrations/0005_add_ip_table.rb
Normal file
18
db/migrations/0005_add_ip_table.rb
Normal file
@ -0,0 +1,18 @@
|
||||
Sequel.migration do
|
||||
|
||||
up do
|
||||
create_table(:ip_addresses) do
|
||||
primary_key :id
|
||||
String :address, null: false
|
||||
String :dns_name
|
||||
String :comment
|
||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
end
|
||||
end
|
||||
|
||||
down do
|
||||
drop_table(:ip_addresses)
|
||||
end
|
||||
|
||||
end
|
5
lib/models/ip_address.rb
Normal file
5
lib/models/ip_address.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class IpAddress < Sequel::Model
|
||||
|
||||
|
||||
|
||||
end
|
@ -5,3 +5,5 @@ require_relative 'routes/item.rb'
|
||||
require_relative 'routes/license.rb'
|
||||
|
||||
require_relative 'routes/search.rb'
|
||||
|
||||
require_relative 'routes/ip_tracker.rb'
|
||||
|
31
lib/routes/ip_tracker.rb
Normal file
31
lib/routes/ip_tracker.rb
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
||||
|
||||
end
|
1
raven.rb
1
raven.rb
@ -26,6 +26,7 @@ require_relative 'lib/models/item.rb'
|
||||
require_relative 'lib/models/item_comment.rb'
|
||||
require_relative 'lib/models/license.rb'
|
||||
require_relative 'lib/models/license_comment.rb'
|
||||
require_relative 'lib/models/ip_address.rb'
|
||||
|
||||
# Load helper functions
|
||||
require_relative 'lib/helpers.rb'
|
||||
|
32
views/ip/add.erb
Normal file
32
views/ip/add.erb
Normal file
@ -0,0 +1,32 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>Add new IP address</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<form action="/ip-tracker/add" method="POST" class="u-full-width">
|
||||
<div class="row">
|
||||
<div class="six columns">
|
||||
<label for="ip_address">IP address:</label>
|
||||
<input class="u-full-width" type="text" placeholder="192.168.1.20" id="ip_address" name="ip_address">
|
||||
</div>
|
||||
|
||||
<div class="six columns">
|
||||
<label for="ip_dns">DNS name:</label>
|
||||
<input class="u-full-width" type="text" placeholder="test.example.com" id="ip_dns" name="ip_dns">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<label for="ip_comment">Comments:</label>
|
||||
<input class="u-full-width" type="text" placeholder="My thoughts on this address..." id="ip_comment" name="ip_comment">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
27
views/ip/ip-tracker.erb
Normal file
27
views/ip/ip-tracker.erb
Normal file
@ -0,0 +1,27 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<% if ip_addresses.length > 0 %>
|
||||
<p><a href="/ip-tracker/add">Add new address</a></p>
|
||||
<table class="u-full-width">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<th>DNS Name</th>
|
||||
<th>Comments</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% ip_addresses.each do |ip| %>
|
||||
<tr>
|
||||
<td><%= ip.address %></td>
|
||||
<td><%= ip.dns_name %></td>
|
||||
<td><%= ip.comment %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>There are no IP addresses to show at this time. Trying <a href="/ip-tracker/add">adding some</a>.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
@ -4,5 +4,6 @@
|
||||
<li><a href="/">Dashboard <i class="fa-solid fa-gauge"></i></a></li>
|
||||
<li><a href="/item/list">Items <i class="fa-solid fa-desktop"></i></a></li>
|
||||
<li><a href="/license/list">Licenses <i class="fa-solid fa-floppy-disk"></i></a></li>
|
||||
<li><a href="/ip-tracker">IP Tracker <i class="fa-solid fa-network-wired"></i></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
Loading…
Reference in New Issue
Block a user