-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhttp_main.rb
58 lines (45 loc) · 1.29 KB
/
http_main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/ruby
# ---------------------
# Web interface which configures ethernet interfaces
# ---------------------
require 'sinatra'
load "get_op_status.rb" # read operationnal status by CLI
load "set_itf_status.rb" # read operationnal status by CLI
# get arguments (port number only)
port_nb = ARGV.shift || 8080
# config: add specific interfaces before automatic discovery
NICs = [ ] + get_network_interfaces()
# confiugure sinatra
set :server, 'thin'
set :port, port_nb
set :bind, '0.0.0.0'
configure do
set :root, '.'
set :views, 'views'
# register html templates beginning vith .html.erb
Tilt.register Tilt::ERBTemplate, 'html.erb'
end
# URL routage
get '/' do
op_datas = get_op_data( NICs )
erb :"index", :locals => { 'op_datas' => op_datas }
# p op_datas
end
get '/configure' do
op_datas = get_op_data( NICs )
itf = params[:itf]
erb :configure, :locals => { 'itf' => itf, 'data' => op_datas[itf] }
end
post '/configure' do
tc_out = set_itf_status params[:itf], params
erb :after_post, :locals => { 'tc_out' => tc_out }
# quick hack: return "<pre> #{tc_out} </pre>"
end
get '/setalias' do
itf = params[:itf]
erb :setalias, :locals => { 'itf' => itf }
end
post '/setalias' do
tc_out = set_itf_alias params[:itf], params
redirect '/'
end