File: macs_stats.lua

package info (click to toggle)
ntopng 5.2.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 121,832 kB
  • sloc: javascript: 143,431; cpp: 71,175; ansic: 11,108; sh: 4,687; makefile: 911; python: 587; sql: 512; pascal: 234; perl: 118; ruby: 52; exp: 4
file content (270 lines) | stat: -rw-r--r-- 8,680 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
--
-- (C) 2013-22 - ntop.org
--

dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path

require "lua_utils"
local discover = require("discover_utils")
local page_utils = require("page_utils")

sendHTTPContentTypeHeader('text/html')


page_utils.set_active_menu_entry(page_utils.menu_entries.devices)

if (group_col == nil) then
   group_col = "mac"
end

local have_nedge = ntop.isnEdge()

dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")

local base_url = ntop.getHttpPrefix() .. "/lua/macs_stats.lua"
local page_params = {}

local devices_mode = ""
local devices_mode_filter = ""

if(not isEmptyString(_GET["devices_mode"])) then
   devices_mode = _GET["devices_mode"]
   page_params["devices_mode"] = _GET["devices_mode"]
   devices_mode_filter = '<span class="fas fa-filter"></span>'
end

local manufacturer = nil
local manufacturer_filter = ""
if(not isEmptyString(_GET["manufacturer"])) then
   manufacturer = _GET["manufacturer"]
   page_params["manufacturer"] = manufacturer
   manufacturer_filter = '<span class="fas fa-filter"></span>'
end

local device_type = nil
local devtype_filter = ""
if(not isEmptyString(_GET["device_type"])) then
   device_type = tonumber(_GET["device_type"])
   page_params["device_type"] = device_type
   devtype_filter = '<span class="fas fa-filter"></span>'
end

page_utils.print_page_title('Mac List')

print [[
      <div id="table-mac"></div>
	 <script>
	 var url_update = "]]

print(getPageUrl(ntop.getHttpPrefix().."/lua/get_macs_data.lua", page_params))

print ('";')
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/mac_stats_id.inc")

print [[
           $("#table-mac").datatable({
              title: '',
			url: url_update ,
]]

local title

if devices_mode == "source_macs_only" then
   if device_type then
      title = i18n("mac_stats.layer_2_dev_devices", {device_type=discover.devtype2string(device_type)})
   else
      title = i18n("mac_stats.layer_2_source_devices", {device_type=""})
   end
else
   if device_type then
      title = i18n("mac_stats.dev_layer_2_devices", {device_type=discover.devtype2string(device_type)})
   else
      title = i18n("mac_stats.all_layer_2_devices", {device_type=""})
   end
end

if manufacturer ~= nil then
 title = i18n("mac_stats.layer_2_devices_with_manufacturer",{title=title, manufacturer=manufacturer})
end


print ('rowCallback: function ( row ) { return mac_table_setID(row); },')
print[[
        tableCallback: function()  { $("#dt-bottom-details > .float-left > p").first().append('. ]]
print(i18n('mac_stats.idle_devices_not_listed'))
print[['); },]]

-- Set the preference table
preference = tablePreferences("rows_number",_GET["perPage"])
if (preference ~= "") then print ('perPage: '..preference.. ",\n") end

-- Automatic default sorted. NB: the column must exist.
print ('sort: [ ["' .. getDefaultTableSort("macs") ..'","' .. getDefaultTableSortOrder("macs").. '"] ],')

print('buttons: [')

   -- Filter MACS
   -- table.clone needed to modify some parameters while keeping the original unchanged
   local macs_params = table.clone(page_params)
   macs_params.devices_mode = nil
   print('\'<div class="btn-group"><button class="btn btn-link dropdown-toggle" data-bs-toggle="dropdown">'..i18n("mac_stats.filter_macs")..devices_mode_filter..'<span class="caret"></span></button> <ul class="dropdown-menu scrollable-dropdown" role="menu" style="min-width: 90px;"><li><a class="dropdown-item" href="')
   print(getPageUrl(base_url, macs_params))
   print('">'..i18n("mac_stats.all_devices")..'</a></li>')

   -- Source MACs only
   print('<li><a class="dropdown-item '.. (devices_mode == "source_macs_only" and 'active' or '') ..'" href="')
   macs_params.devices_mode = "source_macs_only"
   print(getPageUrl(base_url, macs_params))
   print('">'..i18n("mac_stats.source_macs")..'</a></li>')

   print("</div>'")

   -- Filter Manufacturers
   -- table.clone needed to modify some parameters while keeping the original unchanged
   local manufacturer_params = table.clone(page_params)
   manufacturer_params.manufacturer = nil
   print[[, '\
       <div class="btn-group float-right">\
       <button class="btn btn-link dropdown-toggle" data-bs-toggle="dropdown">]] print(i18n("mac_stats.manufacturer")) print(manufacturer_filter) print[[<span class="caret"></span></button>\
       <ul class="dropdown-menu scrollable-dropdown" role="menu" id="flow_dropdown">\
          <li><a class="dropdown-item" href="]] print(getPageUrl(base_url, manufacturer_params)) print[[">]] print(i18n("mac_stats.all_manufacturers")) print[[</a></li>\
   ]]

for manuf, count in pairsByKeys(interface.getMacManufacturers(nil, nil, device_type), asc) do
   local _manuf = string.gsub(string.gsub(manuf, "'", "&#39;"), "\"", "&quot;")
      manufacturer_params.manufacturer = manuf
      print('<li><a class="dropdown-item '.. (manufacturer == manuf and 'active' or '') ..'" href="'..getPageUrl(base_url, manufacturer_params)..'">'.._manuf..' ('..count..')'..'</a></li>')
   end
   print[[
       </ul>\
    </div>\
   ']]

   -- Filter Device Type
   -- table.clone needed to modify some parameters while keeping the original unchanged
   local devicetype_params = table.clone(page_params)
   devicetype_params.device_type = nil
   print[[, '\
       <div class="btn-group float-right">\
       <button class="btn btn-link dropdown-toggle" data-bs-toggle="dropdown">]] print(i18n("details.device_type")) print(devtype_filter) print[[<span class="caret"></span></button>\
       <ul class="dropdown-menu scrollable-dropdown" role="menu" id="flow_dropdown">\
          <li><a class="dropdown-item" href="]] print(getPageUrl(base_url, devicetype_params)) print[[">]] print(i18n("mac_stats.all_devices")) print[[</a></li>\
   ]]

   for typeidx, count in pairsByKeys(interface.getMacDeviceTypes(nil, nil, manufacturer, device_type), asc) do
      devicetype_params.device_type = typeidx
      print('<li><a class="dropdown-item '.. (typeidx == device_type and 'active' or '') ..'" href="'..getPageUrl(base_url, devicetype_params)..'">'.. discover.devtype2string(typeidx) ..' ('..count..')'..'</a></li>')
   end
   print[[
       </ul>\
    </div>\
   ']]

   print(" ],")

print [[
	       showPagination: true,
	        columns: [
           {
                                title: "Key",
                                field: "key",
                                hidden: true,
                                css: {
                                   textAlign: 'center'
                                }
           },
                         {
			     title: "]] print(i18n("mac_address")) print[[",
				 field: "column_mac",
				 sortable: true,
                             css: {
			        textAlign: 'left'
			     }
				 },
                         {
			     title: "]] print(i18n("mac_stats.manufacturer")) print[[",
				 field: "column_manufacturer",
				 sortable: true,
                             css: {
			        textAlign: 'left'
			     }
				 },
			     {
			     title: "]] print(i18n("details.device_type")) print[[",
				 field: "column_device_type",
				 sortable: false,
				 },{
			     title: "]] print(i18n("name")) print[[",
				 field: "column_name",
				 sortable: false,
	 	             css: {
			        textAlign: 'left'
			     }

				 },{
			     title: "]] print(i18n("hosts_stats.hosts")) print[[",
				 field: "column_hosts",
				 sortable: true,
                             css: {
			        textAlign: 'center'
			     }

				 },
			     {
			     title: "]] print(i18n("mac_stats.arp_total")) print[[",
				 field: "column_arp_total",
             hidden: ]] print(ternary(have_nedge, "true", "false")) print[[,
				 sortable: true,
                             css: {
			        textAlign: 'center'
			     }

				 },
			     {
			     title: "]] print(i18n("seen_since")) print[[",
				 field: "column_since",
				 sortable: true,
                             css: {
			        textAlign: 'center'
			     }

				 },
]]

print [[
			     {
			     title: "]] print(i18n("breakdown")) print[[",
				 field: "column_breakdown",
				 sortable: false,
	 	             css: {
			        textAlign: 'center'
			     }
				 },
			     {
			     title: "]] print(i18n("throughput")) print[[",
				 field: "column_thpt",
				 sortable: true,
	 	             css: {
			        textAlign: 'right'
			     }
				 },
			     {
			     title: "]] print(i18n("traffic")) print[[",
				 field: "column_traffic",
				 sortable: true,
	 	             css: {
			        textAlign: 'right'
			     }
				 }
			     ]
	       });


       </script>



]]

dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")