mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2024-11-17 06:56:13 +01:00
gem: refactor to prepare supporting flexible list headers
This commit is contained in:
parent
406ed867f7
commit
39d2b3ce94
@ -50,20 +50,36 @@ thead {
|
|||||||
<div>
|
<div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<td class="first">Common Name</td>
|
<% status.client_list_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle">Real Address</td>
|
<% if i == 0 %>
|
||||||
<td class="middle">Data Received</td>
|
<td class="first">
|
||||||
<td class="middle">Data Sent</td>
|
<% elsif i == status.client_list_headers.length-1 %>
|
||||||
<td class="last">Connected Since</td>
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<%= header %></td>
|
||||||
|
<% end %>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% status.client_list.each do |client| %>
|
<% status.client_list.each do |client| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="first"><%= client[0] %></td>
|
<% status.client_list_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle"><%= client[1] %></td>
|
<% if i == 0 %>
|
||||||
<td class="middle"><%= client[2].to_i.as_bytes %></td>
|
<td class="first">
|
||||||
<td class="middle"><%= client[3].to_i.as_bytes %></td>
|
<% elsif i == status.client_list_headers.length-1 %>
|
||||||
<td class="last"><%= client[4].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<% if header =~ /(Received|Sent)/ %>
|
||||||
|
<%= client[i].to_i.as_bytes %></td>
|
||||||
|
<% elsif client[i].is_a? DateTime %>
|
||||||
|
<%= client[i].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
||||||
|
<% else %>
|
||||||
|
<%= client[i] %></td>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -74,18 +90,34 @@ thead {
|
|||||||
<div>
|
<div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<td class="first">Virtual Address</td>
|
<% status.routing_table_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle">Common Name</td>
|
<% if i == 0 %>
|
||||||
<td class="middle">Real Address</td>
|
<td class="first">
|
||||||
<td class="last">Last Ref</td>
|
<% elsif i == status.routing_table_headers.length-1 %>
|
||||||
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<%= header %></td>
|
||||||
|
<% end %>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% status.routing_table.each do |route| %>
|
<% status.routing_table.each do |route| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="first"><%= route[0] %></td>
|
<% status.routing_table_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle"><%= route[1] %></td>
|
<% if i == 0 %>
|
||||||
<td class="middle"><%= route[2] %></td>
|
<td class="first">
|
||||||
<td class="last"><%= route[3].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
<% elsif i == status.routing_table_headers.length-1 %>
|
||||||
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<% if route[i].is_a? DateTime %>
|
||||||
|
<%= route[i].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
||||||
|
<% else %>
|
||||||
|
<%= route[i] %></td>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -11,7 +11,9 @@ module OpenVPNStatusWeb
|
|||||||
|
|
||||||
text.lines.each do |line|
|
text.lines.each do |line|
|
||||||
parts = line.strip.split(sep)
|
parts = line.strip.split(sep)
|
||||||
|
status.client_list_headers = ['Common Name', 'Real Address', 'Data Received', 'Data Sent', 'Connected Since']
|
||||||
status.client_list << parse_client(parts[1..5]) if parts[0] == 'CLIENT_LIST'
|
status.client_list << parse_client(parts[1..5]) if parts[0] == 'CLIENT_LIST'
|
||||||
|
status.routing_table_headers = ['Virtual Address', 'Common Name', 'Real Address', 'Last Ref']
|
||||||
status.routing_table << parse_route(parts[1..4]) if parts[0] == 'ROUTING_TABLE'
|
status.routing_table << parse_route(parts[1..4]) if parts[0] == 'ROUTING_TABLE'
|
||||||
status.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS'
|
status.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS'
|
||||||
end
|
end
|
||||||
|
@ -26,7 +26,9 @@ module OpenVPNStatusWeb
|
|||||||
end
|
end
|
||||||
|
|
||||||
status = Status.new
|
status = Status.new
|
||||||
|
status.client_list_headers = ['Common Name', 'Real Address', 'Data Received', 'Data Sent', 'Connected Since']
|
||||||
status.client_list = client_list[2..-1].map { |client| parse_client(client) }
|
status.client_list = client_list[2..-1].map { |client| parse_client(client) }
|
||||||
|
status.routing_table_headers = ['Virtual Address', 'Common Name', 'Real Address', 'Last Ref']
|
||||||
status.routing_table = routing_table[1..-1].map { |route| parse_route(route) }
|
status.routing_table = routing_table[1..-1].map { |route| parse_route(route) }
|
||||||
status.global_stats = global_stats.map { |global| parse_global(global) }
|
status.global_stats = global_stats.map { |global| parse_global(global) }
|
||||||
status
|
status
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
class Status
|
class Status
|
||||||
|
attr_accessor :client_list_headers
|
||||||
attr_accessor :client_list
|
attr_accessor :client_list
|
||||||
|
attr_accessor :routing_table_headers
|
||||||
attr_accessor :routing_table
|
attr_accessor :routing_table
|
||||||
attr_accessor :global_stats
|
attr_accessor :global_stats
|
||||||
end
|
end
|
||||||
|
@ -32,6 +32,10 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.client_list[0].length).to eq(status.client_list_headers.length)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with routing table' do
|
context 'with routing table' do
|
||||||
@ -55,6 +59,10 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.routing_table[0].length).to eq(status.routing_table_headers.length)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses global stats' do
|
it 'parses global stats' do
|
||||||
|
@ -31,6 +31,10 @@ describe OpenVPNStatusWeb::Parser::V1 do
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.client_list[0].length).to eq(status.client_list_headers.length)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with routing table' do
|
context 'with routing table' do
|
||||||
@ -54,6 +58,10 @@ describe OpenVPNStatusWeb::Parser::V1 do
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.routing_table[0].length).to eq(status.routing_table_headers.length)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses global stats' do
|
it 'parses global stats' do
|
||||||
|
Loading…
Reference in New Issue
Block a user