Revision 25786714
Added by Dmitri Dolguikh over 8 years ago
lib/smart_proxy_main.rb | ||
---|---|---|
|
||
::Sinatra::Base.set :run, false
|
||
::Sinatra::Base.set :root, APP_ROOT
|
||
::Sinatra::Base.set :views, APP_ROOT + '/views'
|
||
::Sinatra::Base.set :public_folder, APP_ROOT + '/public'
|
||
::Sinatra::Base.set :logging, false # we are not going to use Rack::Logger
|
||
::Sinatra::Base.use ::Proxy::LoggerMiddleware # instead, we have our own logging middleware
|
||
::Sinatra::Base.use ::Rack::CommonLogger, ::Proxy::Log.logger
|
modules/dhcp/dhcp_api.rb | ||
---|---|---|
|
||
get "/?" do
|
||
begin
|
||
if request.accept? 'application/json'
|
||
content_type :json
|
||
content_type :json
|
||
|
||
log_halt 404, "No subnets found on server @{name}" unless server.subnets
|
||
server.subnets.map{|s| {:network => s.network, :netmask => s.netmask, :options => s.options}}.to_json
|
||
else
|
||
erb :"dhcp/index"
|
||
end
|
||
log_halt 404, "No subnets found on server @{name}" unless server.subnets
|
||
server.subnets.map{|s| {:network => s.network, :netmask => s.netmask, :options => s.options}}.to_json
|
||
rescue => e
|
||
log_halt 400, e
|
||
end
|
||
... | ... | |
load_subnet
|
||
load_subnet_data
|
||
|
||
if request.accept? 'application/json'
|
||
content_type :json
|
||
{:reservations => server.all_hosts(@subnet.network), :leases => server.all_leases(@subnet.network)}.to_json
|
||
else
|
||
erb :"dhcp/show"
|
||
end
|
||
content_type :json
|
||
{:reservations => server.all_hosts(@subnet.network), :leases => server.all_leases(@subnet.network)}.to_json
|
||
rescue => e
|
||
log_halt 400, e
|
||
end
|
modules/root/root_api.rb | ||
---|---|---|
begin
|
||
plugin_names = ::Proxy::Plugins.enabled_plugins.collect(&:plugin_name).collect(&:to_s).sort
|
||
@features = plugin_names - ['foreman_proxy']
|
||
if request.accept? 'application/json'
|
||
content_type :json
|
||
@features.to_json
|
||
else
|
||
erb :"features/index"
|
||
end
|
||
content_type :json
|
||
@features.to_json
|
||
rescue => e
|
||
log_halt 400, e
|
||
end
|
public/css/styles.css | ||
---|---|---|
#wrapper{
|
||
width:80%;
|
||
margin:auto;
|
||
}
|
||
|
||
#header{
|
||
background-color:#ade;
|
||
}
|
||
|
||
#header>h1{
|
||
font-size:200%;
|
||
}
|
||
|
||
h1{
|
||
font-size:150%;
|
||
}
|
||
|
||
h2{
|
||
font-size:130%;
|
||
font-family:sans-serif;
|
||
}
|
||
|
||
#content{
|
||
margin:12px 0;
|
||
float:left;
|
||
}
|
||
|
||
#side_bar{
|
||
margin:12px 0;
|
||
width :30%;
|
||
float:right;
|
||
clear:none;
|
||
background-color:#ddd;
|
||
}
|
||
|
||
#footer{
|
||
clear:both;
|
||
background-color:#ade;
|
||
font-size:75%;
|
||
font-family:sans-serif;
|
||
color:#333;
|
||
border-top:solid 1px #69a;
|
||
text-align:center;
|
||
}
|
||
|
||
ol{
|
||
clear:both;
|
||
background-color:#ade;
|
||
display:block;
|
||
}
|
||
|
||
li {
|
||
padding:5px 10px 0 10px;
|
||
margin-right:2px;
|
||
}
|
||
|
||
#nav li {
|
||
color:white;
|
||
text-align:center;
|
||
display:inline;
|
||
background-color: #69a;
|
||
|
||
}
|
||
|
||
a{
|
||
text-decoration:none;
|
||
}
|
views/dhcp/index.erb | ||
---|---|---|
<h2>Subnets</h2>
|
||
<ul>
|
||
<% @subnets.sort.each do |subnet| %>
|
||
<a href="/dhcp/<%= subnet.network %>"><li><%= subnet %></li></a>
|
||
<% end %>
|
||
</ul>
|
||
<%="Total of #{@subnets.size} subnets" %>
|
views/dhcp/show.erb | ||
---|---|---|
<h2><%= @subnet %></h2>
|
||
<h3>Records</h3>
|
||
<table>
|
||
<th> IP </th>
|
||
<th> MAC </th>
|
||
<th> TFTP Server </th>
|
||
<th> Boot Filename </th>
|
||
<th> Hostname </th>
|
||
<th> Delete </th>
|
||
<% @subnet.reservations.sort.each do |record| %>
|
||
<tr>
|
||
<td><%= record.ip %></td>
|
||
<td><%= record.mac %></td>
|
||
<td><%= record.nextServer %></td>
|
||
<td><%= record.filename %></td>
|
||
<td><%= record.name %></td>
|
||
<td>
|
||
<form action="<%= "/dhcp/#{@subnet.network}/#{record.mac}" %>" method="post">
|
||
<input name='_method' type='hidden' value='delete' />
|
||
<div>
|
||
<input name='commit' type='submit' value='delete' />
|
||
</div>
|
||
</form>
|
||
</td>
|
||
</tr>
|
||
<% end %>
|
||
</table>
|
||
<%= "Total of #{@subnet.reservations.size} reservations" %>
|
||
<br>
|
||
<h3>Leases</h3>
|
||
<table>
|
||
<th> IP </th>
|
||
<th> MAC </th>
|
||
<th> Lease Starts </th>
|
||
<th> Lease Ends </th>
|
||
<th> Lease State </th>
|
||
<% @subnet.leases.sort.each do |record| %>
|
||
<tr>
|
||
<td><%= record.ip %></td>
|
||
<td><%= record.mac %></td>
|
||
<td><%= record.starts %></td>
|
||
<td><%= record.ends %></td>
|
||
<td><%= record.state %></td>
|
||
</tr>
|
||
<% end %>
|
||
</table>
|
||
<%="Total of #{@subnet.leases.size} leases" %>
|
||
<br>
|
||
<%="Total of #{@subnet.size} records" %>
|
views/features/index.erb | ||
---|---|---|
<h2>Suported features</h2>
|
||
<ul>
|
||
<% @features.sort.each do |feature| %>
|
||
<li><%= feature %></li>
|
||
<% end %>
|
||
</ul>
|
views/layout.erb | ||
---|---|---|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<html>
|
||
<head>
|
||
<title>DHCP Web interface</title>
|
||
<link href='/css/styles.css' rel='stylesheet' />
|
||
</head>
|
||
<body>
|
||
<div id='wrapper'>
|
||
<div id='header'>
|
||
<h1>DHCP Browser</h1>
|
||
<div id='nav'>
|
||
<ol>
|
||
<a href='/dhcp'> <li>Home</li> </a>
|
||
<a href='/features'> <li>Features</li> </a>
|
||
</ol>
|
||
</div>
|
||
</div>
|
||
<div id='content'>
|
||
<%= yield %>
|
||
</div>
|
||
<div id='footer'>
|
||
<p> © 2010 <a href='mailto:ohadlevy@gmail.com'> Ohad Levy </a> </p>
|
||
</div>
|
||
</div>
|
||
</body>
|
||
</html>
|
Also available in: Unified diff
Fixes #13947 - removed html views for dhcp and root modules