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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
--
-- (C) 2014-15-15 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
require "flow_utils"
sendHTTPHeader('text/html; charset=iso-8859-1')
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc")
page = _GET["page"]
if(page == nil) then page = "Protocols" end
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
pid_key = _GET["pid"]
name_key = _GET["name"]
host_key = _GET["host"]
application = _GET["application"]
general_process = 0
interface.select(ifname)
if((pid_key == nil) and (name_key == nil))then
print("<div class=\"alert alert-danger\"><img src=/img/warning.png> Missing pid name</div>")
else
if ((name_key ~= nil) and (pid_key == nil) and (host_key == nil)) then
general_process = 1
end
-- Prepare displayed value
if (pid_key ~= nil) then
flows = interface.findPidFlows(tonumber(pid_key))
err_label = "PID"
err_val = pid_key
elseif (name_key ~= nil) then
flows = interface.findNameFlows(name_key)
err = "Name"
err_val = name_key
end
num = 0;
if(flows ~= nil) then
for key, value in pairs(flows) do
num = num + 1
end
end
if(num == 0) then
print("<div class=\"alert alert-danger\"><img src=".. ntop.getHttpPrefix() .. "/img/warning.png> No traffic detected for this process, flow process expired, or process terminated.</div>")
else
if(host_key ~= nil) then
name = ntop.getResolvedAddress(host_key)
if (name == nil) then
name = host_key
end
end
print [[
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav"> ]]
if(pid_key ~= nil)then
print [[ <li><a href="#">Pid: ]] print(pid_key) if(host_key ~= nil) then print(" - IP: "..name) end print [[ </a></li>]]
elseif (name_key ~= nil)then
print [[ <li><a href="#">]] print (getApplicationLabel(name_key)) if(host_key ~= nil) then print(" - IP: "..host_key) end print [[ </a></li>]]
end
if(page == "Protocols") then active=' class="active"' else active = "" end
if (pid_key ~= nil) then
print('<li'..active..'><a href="?pid='.. pid_key) if(host_key ~= nil) then print("&host="..name) end print('&page=Protocols">Protocols</a></li>\n')
elseif (name_key ~= nil) then
print('<li'..active..'><a href="?name='.. name_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Protocols">Protocols</a></li>\n')
end
if (general_process == 1) then
if(page == "Hosts") then active=' class="active"' else active = "" end
if (pid_key ~= nil) then
print('<li'..active..'><a href="?pid='.. pid_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Hosts">Hosts</a></li>\n')
elseif (name_key ~= nil) then
print('<li'..active..'><a href="?name='.. name_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Hosts">Hosts</a></li>\n')
end
end
if(page == "Flows") then active=' class="active"' else active = "" end
if (pid_key ~= nil) then
print('<li'..active..'><a href="?pid='.. pid_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows">Flows</a></li>\n')
elseif (name_key ~= nil) then
print('<li'..active..'><a href="?name='.. name_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows">Flows</a></li>\n')
end
print [[ <li><a href="javascript:history.go(-1)"><i class='fa fa-reply'></i></a> ]]
-- End Tab Menu
print('</ul>\n\t</div>\n\t</nav>\n')
if(page == "Protocols") then
print [[
<br>
<!-- Left Tab -->
<ul class="nav nav-tabs">
]]
print [[<li class="active"><a href="#l7" data-toggle="tab">L7 Protocols</a></li> ]]
print [[<li><a href="#l4" data-toggle="tab">L4 Protocols</a></li>]]
print [[
</ul>
<!-- Tab content-->
<div class="tab-content">
]]
print [[
<div class="tab-pane active" id="l7">
<table class="table table-bordered table-striped">
<tr>
<th class="text-center">Top L7 Protocols</th>
<td><div class="pie-chart" id="topL7"></div></td>
</tr>
</table>
</div> <!-- Tab l7-->
]]
print [[
<div class="tab-pane" id="l4">
<table class="table table-bordered table-striped">
<tr>
<th class="text-center">Top L4 Protocols</th>
<td><div class="pie-chart" id="topL4"></div></td>
</tr>
</table>
</div> <!-- Tab l4-->
]]
print [[
</div> <!-- End Tab content-->
</table>
]]
print [[
<script type='text/javascript'>
window.onload=function() {
var refresh = 3000 /* ms */;
]]
if(pid_key ~= nil)then
print [[
do_pie("#topL7", ']]
print (ntop.getHttpPrefix())
print [[/lua/pid_stats.lua', { "pid": ]] print(pid_key) print [[, "mode": "l7" ]]
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
print [[
}, "", refresh);
do_pie("#topL4", ']]
print (ntop.getHttpPrefix())
print [[/lua/pid_stats.lua', { "pid": ]] print(pid_key) print [[, "mode": "l4" ]]
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
print [[
}, "", refresh);
]]
elseif (name_key ~= nil)then
print [[
do_pie("#topL7", ']]
print (ntop.getHttpPrefix())
print [[/lua/pid_stats.lua', { "name": "]] print(name_key) print [[", "mode": "l7" ]]
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
print [[
}, "", refresh);
do_pie("#topL4", ']]
print (ntop.getHttpPrefix())
print [[/lua/pid_stats.lua', { "name": "]] print(name_key) print [[", "mode": "l4" ]]
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
print [[
}, "", refresh); ]]
end
print [[
}
</script>
]]
elseif(page == "Flows") then
stats = interface.getnDPIStats()
num_param = 0
print [[
<div id="table-hosts"></div>
<script>
$("#table-hosts").datatable({
url: "]]
print (ntop.getHttpPrefix())
print [[/lua/get_flows_data.lua]]
if(application ~= nil) then
print("?application="..application)
num_param = num_param + 1
end
if(pid_key ~= nil) then
if (num_param > 0) then
print("&")
else
print("?")
end
print("pid="..pid_key)
num_param = num_param + 1
end
if(name_key ~= nil) then
if (num_param > 0) then
print("&")
else
print("?")
end
print("name="..name_key)
num_param = num_param + 1
end
if(host_key ~= nil) then
if (num_param > 0) then
print("&")
else
print("?")
end
print("host="..host_key)
num_param = num_param + 1
end
print('",')
-- Set the preference table
preference = tablePreferences("rows_number", _GET["perPage"])
if (preference ~= "") then print ('perPage: '..preference.. ",\n") end
print [[ showPagination: true,
buttons: [ '<div class="btn-group"><button class="btn btn-link dropdown-toggle" data-toggle="dropdown">Applications<span class="caret"></span></button> <ul class="dropdown-menu" id="flow_dropdown">]]
if (pid_key ~= nil) then
print('<li><a href="'..ntop.getHttpPrefix()..'/lua/get_process_info.lua?pid='.. pid_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows">All Proto</a></li>')
end
if (name_key ~= nil) then
print('<li><a href="'..ntop.getHttpPrefix()..'/lua/get_process_info.lua?name='.. name_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows">All Proto</a></li>')
end
for key, value in pairsByKeys(stats["ndpi"], asc) do
class_active = ''
if(key == application) then
class_active = ' class="active"'
end
if (pid_key ~= nil) then
print('<li '..class_active..'><a href="'..ntop.getHttpPrefix()..'/lua/get_process_info.lua?pid='.. pid_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows&application=' .. key..'">'..key..'</a></li>')
end
if (name_key ~= nil) then
print('<li '..class_active..'><a href="'..ntop.getHttpPrefix()..'/lua/get_process_info.lua?name='.. name_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows&application=' .. key..'">'..key..'</a></li>')
end
end
print("</ul> </div>' ],\n")
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/sflows_stats_top.inc")
prefs = ntop.getPrefs()
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/sflows_stats_bottom.inc")
elseif(page == "Hosts") then
print [[
<br>
<!-- Left Tab -->
<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
]]
print [[<li class="active"><a href="#topHost" data-toggle="tab">Top Hosts</a></li> ]]
print [[
</ul>
<!-- Tab content-->
<div class="tab-content">
]]
print [[
<div class="tab-pane active" id="topHost">
<table class="table table-bordered table-striped">
<tr>
<th class="text-center span3">Top Hosts Traffic</th>
<td><div class="pie-chart" id="topHosts"></div></td>
</tr>
</table>
</div> <!-- Tab l7-->
]]
print [[
</div> <!-- End Tab content-->
</div> <!-- End Left Tab -->
</table>
]]
print [[
<script type='text/javascript'>
window.onload=function() {
var refresh = 3000 /* ms */;
]]
if(pid_key ~= nil)then
print [[
do_pie("#topHosts", ']]
print (ntop.getHttpPrefix())
print [[/lua/pid_stats.lua', { "pid": ]] print(pid_key) print [[", "mode": "host" }, "", refresh);
]]
elseif (name_key ~= nil)then
print [[
do_pie("#topHosts", ']]
print (ntop.getHttpPrefix())
print [[/lua/pid_stats.lua', { "name": "]] print(name_key) print [[", "mode": "host" }, "", refresh);
]]
end
print [[
}
</script>
]]
end -- If page
end -- Error one
end -- Error two
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|