45c9ca8c1e0b2c6f20055e4be236a395c1500848
[project/luci.git] / applications / luci-app-noddos / luasrc / view / noddos / clients.htm
1 <%#
2  Copyright (C) 2017 Steven Hessing <steven.hessing@gmail.com>
3   This is free software, licensed under the GNU General Public License v3.
4  /usr/lib/lua/luci/view/clients.htm
5 -%>
6
7 <%-
8
9     require "nixio.fs"
10     require "os"
11
12     local last_modified = "<boottime>"
13     local style = true
14     local v
15     local devdump
16
17     if nixio.fs.access("/var/lib/noddos/DeviceDump.json") then
18         last_modified = os.date("%c", nixio.fs.stat("/var/lib/noddos/DeviceDump.json")['mtime'])
19         io.input("/var/lib/noddos/DeviceDump.json")
20         t = io.read("*all")
21         devdump = luci.jsonc.parse(t)
22         io.input("/var/lib/noddos/DeviceProfiles.json")
23         t = io.read("*all")
24         temp = luci.jsonc.parse(t)
25         devicevalues = {}
26         for i, v in ipairs(temp) do
27             devicevalues[v.DeviceProfileUuid] = v
28         end
29     end
30 -%>
31
32 <%+header%>
33
34 <div class="cbi-map" id="cbi-network">
35     <h2 name="content"><%:Clients%></h2>
36     <div class="cbi-map-descr"><%:The following clients have been discovered on the network. The last discovery was completed at %><%=last_modified%></div>
37
38     <fieldset class="cbi-section">
39         <legend>Recognized Clients</legend>
40         <div class="cbi-section-node">
41             <table class="cbi-section-table">
42                 <tr class="cbi-section-table-titles">
43                     <th class="cbi-section-table-cell">Hostname</th>
44                     <th class="cbi-section-table-cell">IPv4</th>
45                     <th class="cbi-section-table-cell">MAC</th>
46                     <th class="cbi-section-table-cell">Manufacturer</th>
47                     <th class="cbi-section-table-cell">Model</th>
48                     <th class="cbi-section-table-cell">Class</th>
49                 </tr>
50
51                 <%
52                     for i,v in ipairs(devdump) do
53                         if v.DeviceProfileUuid ~= "" then
54                 %>
55                 <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
56                     <td class="cbi-value-field"><%=v.Hostname%></td>
57                     <td class="cbi-value-field"><%=v.Ipv4Address%></td>
58                     <td class="cbi-value-field"><a href="/cgi-bin/clientdetails?mac=<%=v.MacAddress%>"><%=v.MacAddress%></a></td>
59                     <td class="cbi-value-field"><%=devicevalues[v.DeviceProfileUuid].Manufacturer%></td>
60                     <td class="cbi-value-field"><%=devicevalues[v.DeviceProfileUuid].Model%></td>
61                     <td class="cbi-value-field"><%=devicevalues[v.DeviceProfileUuid].ThingClass%></td>
62                 </tr>
63                 <%
64                             style=false
65                         end
66                     end
67                 %>
68             </table>
69         </div>
70     </fieldset>
71     <br />
72     <fieldset class="cbi-section">
73         <legend>Unrecognized Clients</legend>
74         <div class="cbi-section-node">
75             <table class="cbi-section-table">
76                 <tr class="cbi-section-table-titles">
77                     <th class="cbi-section-table-cell">Hostname</th>
78                     <th class="cbi-section-table-cell">IPv4</th>
79                     <th class="cbi-section-table-cell">MAC</th>
80                     <th class="cbi-section-table-cell">Manufacturer</th>
81                     <th class="cbi-section-table-cell">Model</th>
82                     <th class="cbi-section-table-cell">DhcpVendor</th>
83                     <th class="cbi-section-table-cell">DhcpHostname</th>
84                 </tr>
85
86                 <%
87                     for i,v in ipairs(devdump) do
88                         if v.DeviceProfileUuid == "" then
89                 %>
90                 <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
91                     <td class="cbi-value-field"><%=v.Hostname%></td>
92                     <td class="cbi-value-field"><%=v.Ipv4Address%></td>
93                     <td class="cbi-value-field"><a href="/cgi-bin/clientdetails?mac=<%=v.MacAddress%>"><%=v.MacAddress%></a></td>
94                     <td class="cbi-value-field"><%=v.SsdpManufacturer%></td>
95                     <td class="cbi-value-field"><%=v.SsdpModelName%></td>
96                     <td class="cbi-value-field"><%=v.DhcpVendor1%></td>
97                     <td class="cbi-value-field"><%=v.DhcpHostname%></td>
98                 </tr>
99                 <%
100                             style=false
101                         end
102                     end
103                 %>
104             </table>
105         </div>
106     </fieldset>
107
108 </div>
109
110 <%+footer%>
111