~ubuntu-branches/ubuntu/wily/ntopng/wily

« back to all changes in this revision

Viewing changes to scripts/lua/get_user_info.lua

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2014-07-27 16:13:47 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140727161347-0i8n5upu69ibq5d2
Tags: 1.2.0+dfsg1-1
* Imported Upstream version 1.2.0+dfsg1
* Update watch rule for new upstream naming convention.
* get-roig-source: Support both +svn and ~svn in version.
* Remove external hiredis from orig tarball.
* Remove Rickshaw from orig tarball.
* Remove documentation without source from orig tarball and insert an http
* Remove corrupted unused serializeCFJSON-0.1.js from orig tarball.
  link to it in README.Debian.
* Remove nDPI from orig tarball.
* Remove all debian/missing-sources files that are now included not-minified
  by upstream. Remove build-deps on node-uglify and cleancss.
* Remove references to third-party/redis-lua (removed upstream).
* Update copyright.
* Refresh patches and remove those merged upstream.
* Add external-hiredis.patch to use system libhiredis.
* Add rickshaw-keep-one.patch to remove references to additional rickshaw
  library.
* Add no-svn.patch to drop requirement on SVN.
* Add manpage.patch to fix usage of minus signs, hyphens, and dashes,
  missing space and line breaks.
* Add rickshaw.patch to use single rickshaw.{css,js} files.
* Split library removing part of build-flags.patch into remove-libs.patch.
* Rename debian-defaults.patch to path-defaults.patch and use installation
  path from configure.
* Use dh-autoreconf instead of autotools-dev.
* Add build-dep on libsqlite3-dev.
* Update build-dep on newer libndpi-dev.
* Cleanup of dh_install rules.
* Fix typo in font-awesome symlink path and remove and updates symlink links
  in ntopng-data/
* Remove executable bit to non executable files.
* Use system linjs-jquery tablesorter and form.
* Add Build-Dep on libhiredis-dev.
* Remove empty httpdocs/ssl directory.
* Add systemd support.
* Stop supporting ENABLED in /etc/default/ntopng and debian/NEWS to notify
  users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- (C) 2014 - ntop.org
 
3
--
 
4
 
 
5
dirs = ntop.getDirs()
 
6
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
 
7
 
 
8
require "lua_utils"
 
9
require "flow_utils"
 
10
 
 
11
sendHTTPHeader('text/html')
 
12
 
 
13
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc")
 
14
 
 
15
page = _GET["page"]
 
16
if(page == nil) then page = "UserApps" end
 
17
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
 
18
 
 
19
user_key = _GET["user"]
 
20
host_key = _GET["host"]
 
21
application = _GET["application"]
 
22
 
 
23
if(user_key == nil) then
 
24
   print("<div class=\"alert alert-danger\"><img src=/img/warning.png> Missing user name</div>")
 
25
else
 
26
  if(host_key ~= nil) then
 
27
    name = ntop.getResolvedAddress(host_key)
 
28
    if (name == nil) then
 
29
      name = host_key
 
30
    end
 
31
  end
 
32
  print [[
 
33
            <nav class="navbar navbar-default" role="navigation">
 
34
              <div class="navbar-collapse collapse">
 
35
      <ul class="nav navbar-nav">
 
36
            <li><a href="#"><i class="fa fa-user fa-lg"></i> ]] print(user_key) if(host_key ~= nil) then print(' - <i class="fa fa-building fa-lg"></i> '..name) end print [[  </a></li>
 
37
   ]]
 
38
 
 
39
 
 
40
if(page == "UserApps") then active=' class="active"' else active = "" end
 
41
print('<li'..active..'><a href="?user='.. user_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=UserApps">Applications</a></li>\n')
 
42
 
 
43
if(page == "UserProtocols") then active=' class="active"' else active = "" end
 
44
print('<li'..active..'><a href="?user='.. user_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=UserProtocols">Protocols</a></li>\n')
 
45
 
 
46
if(page == "Flows") then active=' class="active"' else active = "" end
 
47
print('<li'..active..'><a href="?user='.. user_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows">Flow</a></li>\n')
 
48
 
 
49
 
 
50
print('</ul>\n\t</div>\n\t\t</nav>\n')
 
51
 
 
52
 
 
53
if(page == "UserApps") then
 
54
print [[
 
55
    <table class="table table-bordered table-striped">
 
56
      <tr><th class="text-center">
 
57
      <h4>Top Applications</h4>
 
58
        <td><div class="pie-chart" id="topApps"></div></td>
 
59
      
 
60
      </th>
 
61
    </tr>]]
 
62
 
 
63
 print [[
 
64
      </table>
 
65
<script type='text/javascript'>
 
66
window.onload=function() {
 
67
   var refresh = 3000 /* ms */;
 
68
                    do_pie("#topApps", '/lua/user_stats.lua', { user: "]] print(user_key) print [[", mode: "apps" ]] 
 
69
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
 
70
print [[
 
71
 }, "", refresh);
 
72
}
 
73
</script>
 
74
]]
 
75
 
 
76
elseif(page == "UserProtocols") then
 
77
 
 
78
print [[
 
79
  <br>
 
80
  <!-- Left Tab -->
 
81
  <div class="tabbable tabs-left">
 
82
    
 
83
    <ul class="nav nav-tabs">
 
84
      <li class="active"><a href="#l7" data-toggle="tab">L7 Protocols</a></li>
 
85
      <li><a href="#l4" data-toggle="tab">L4 Protocols</a></li>
 
86
    </ul>
 
87
    
 
88
      <!-- Tab content-->
 
89
      <div class="tab-content">
 
90
 
 
91
        <div class="tab-pane active" id="l7">
 
92
          <table class="table table-bordered table-striped">
 
93
            <tr>
 
94
              <th class="text-center">Top L7 Protocols</th>
 
95
              <td><div class="pie-chart" id="topL7"></div></td>
 
96
          </tr>
 
97
          </table>
 
98
        </div> <!-- Tab l7-->
 
99
 
 
100
 
 
101
        <div class="tab-pane" id="l4">
 
102
          <table class="table table-bordered table-striped">
 
103
            <tr>
 
104
              <th class="text-center">Top L4 Protocols</th>
 
105
              <td><div class="pie-chart" id="topL4"></div></td>
 
106
          </tr>
 
107
          </table>
 
108
        </div> <!-- Tab l4-->
 
109
 
 
110
      </div> <!-- End Tab content-->
 
111
    </div> <!-- End Left Tab -->
 
112
 
 
113
]]
 
114
 
 
115
 print [[
 
116
      </table>
 
117
<script type='text/javascript'>
 
118
window.onload=function() {
 
119
   var refresh = 3000 /* ms */;
 
120
                    do_pie("#topL7", '/lua/user_stats.lua', { user: "]] print(user_key) print [[", mode: "l7" ]] 
 
121
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
 
122
print [[
 
123
 }, "", refresh);
 
124
                    do_pie("#topL4", '/lua/user_stats.lua', { user: "]] print(user_key) print [[", mode: "l4" ]] 
 
125
if (host_key ~= nil) then print(", host: \""..host_key.."\"") end
 
126
print [[
 
127
 }, "", refresh);
 
128
}
 
129
</script>
 
130
]]
 
131
 
 
132
elseif(page == "Flows") then
 
133
 
 
134
stats = interface.getNdpiStats()
 
135
num_param = 0
 
136
 
 
137
print [[
 
138
      <div id="table-hosts"></div>
 
139
   <script>
 
140
   $("#table-hosts").datatable({
 
141
      url: "/lua/get_flows_data.lua]] 
 
142
if(application ~= nil) then
 
143
   print("?application="..application)
 
144
   num_param = num_param + 1
 
145
end
 
146
 
 
147
if(user_key ~= nil) then
 
148
  if (num_param > 0) then
 
149
    print("&")
 
150
  else
 
151
    print("?")
 
152
  end
 
153
   print("user="..user_key)
 
154
   num_param = num_param + 1
 
155
end
 
156
 
 
157
if(host_key ~= nil) then
 
158
  if (num_param > 0) then
 
159
    print("&")
 
160
  else
 
161
    print("?")
 
162
  end
 
163
  print("host="..host_key)
 
164
  num_param = num_param + 1
 
165
end
 
166
 
 
167
print [[",
 
168
         showPagination: true,
 
169
         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">]]
 
170
 
 
171
print('<li><a href="/lua/get_user_info.lua?user='.. user_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows">All Proto</a></li>')
 
172
for key, value in pairsByKeys(stats["ndpi"], asc) do
 
173
   class_active = ''
 
174
   if(key == application) then
 
175
      class_active = ' class="active"'
 
176
   end
 
177
   print('<li '..class_active..'><a href="/lua/get_user_info.lua?user='.. user_key) if(host_key ~= nil) then print("&host="..host_key) end print('&page=Flows&application=' .. key..'">'..key..'</a></li>')
 
178
end
 
179
 
 
180
 
 
181
print("</ul> </div>' ],\n")
 
182
 
 
183
 
 
184
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/sflows_stats_top.inc")
 
185
 
 
186
prefs = ntop.getPrefs()
 
187
 
 
188
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/sflows_stats_bottom.inc")
 
189
 
 
190
 
 
191
 
 
192
 
 
193
end -- If page
 
194
 
 
195
 
 
196
 
 
197
end
 
198
 
 
199
 
 
200
 
 
201
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")