Example #1
0
    def refilterTable(self, items, total):
        tab = []
        for k, v in items.items():
            tab.append((k, Utils.intToH(int(v) * 1024)))

        tab.append(('Total', Utils.intToH(total * 1024)))

        return tab
Example #2
0
 def returnPage(res):
     return ctx.tag[
         tags.directive('form searchCache'), tags.h3["Search results"],
         PageHelpers.dataTable(
             (('str', 'Category'), ('str', 'Filename'), ('int', 'Hits'),
              ('int', 'Size'),
              ('',
               '')), [(i[0], i[1], i[2] or 0, Utils.intToH(i[3] or 0),
                       tags.a(href=url.root.child('Squid').
                              child('Flush').child(i[1]))[tags.img(
                                  src='/images/ex.png')]) for i in res],
             sortable=True)]
Example #3
0
            def statSet(type):
                saving = 0
                for t, n, hit, size in cache[type]:
                    h = hit or 0
                    s = size or 0
                    saving += (h * s)

                return [
                    tags.strong["Hits vs Downloads"], tags.br,
                    tags.img(
                        src=
                        '/chart?type=pie&width=500&height=250&lables=Downloads&data=%s&lables=Hits&data=%s'
                        % (len(cache[type]) or 1, totals[type][0] or 1)),
                    tags.br, tags.strong["Efficiency ratio: "],
                    "%.2f" % (len(cache[type]) / float(totals[type][0] + 1)),
                    tags.br, tags.strong["Saving: "],
                    Utils.intToH(saving), tags.br, tags.br
                ]
Example #4
0
            def overallSavings():
                savings = {}
                totalSaving = 1
                for i in ['microsoft', 'linux']:
                    saving = 1
                    for t, n, hit, size in cache[i]:
                        h = hit or 0
                        s = size or 0
                        saving += (h * s)
                    savings[i] = saving
                    totalSaving += saving

                savingCon = []
                for i in ['microsoft', 'linux']:
                    size = Utils.intToH(savings[i])
                    savingCon.append(
                        ("%s%%20[%s]" % (i.capitalize(), size), savings[i]))

                l = '&'.join(
                    ["lables=%s&data=%s" % (i, j) for i, j in savingCon])
                return tags.img(src='/chart?type=pie&width=500&height=250&%s' %
                                l)
Example #5
0
        def gotDetails(dlcache, totals):

            cache = {
                'linux': dlcache[0][1],
                'microsoft': dlcache[1][1],
            }

            update = {}

            print totals

            data = [
                ("Linux", 1 + int(totals.get('linux', [0, 1000])[1]) / 1000),
                ("Windows",
                 1 + int(totals.get('microsoft', [0, 1000])[1]) / 1000),
            ]

            pie = tags.img(
                src="/chart?type=pie&width=500&height=250&%s" %
                ('&'.join(["lables=%s&data=%s" % (l, d) for l, d in data])))

            def statSet(type):
                saving = 0
                for t, n, hit, size in cache[type]:
                    h = hit or 0
                    s = size or 0
                    saving += (h * s)

                return [
                    tags.strong["Hits vs Downloads"], tags.br,
                    tags.img(
                        src=
                        '/chart?type=pie&width=500&height=250&lables=Downloads&data=%s&lables=Hits&data=%s'
                        % (len(cache[type]) or 1, totals[type][0] or 1)),
                    tags.br, tags.strong["Efficiency ratio: "],
                    "%.2f" % (len(cache[type]) / float(totals[type][0] + 1)),
                    tags.br, tags.strong["Saving: "],
                    Utils.intToH(saving), tags.br, tags.br
                ]

            def overallSavings():
                savings = {}
                totalSaving = 1
                for i in ['microsoft', 'linux']:
                    saving = 1
                    for t, n, hit, size in cache[i]:
                        h = hit or 0
                        s = size or 0
                        saving += (h * s)
                    savings[i] = saving
                    totalSaving += saving

                savingCon = []
                for i in ['microsoft', 'linux']:
                    size = Utils.intToH(savings[i])
                    savingCon.append(
                        ("%s%%20[%s]" % (i.capitalize(), size), savings[i]))

                l = '&'.join(
                    ["lables=%s&data=%s" % (i, j) for i, j in savingCon])
                return tags.img(src='/chart?type=pie&width=500&height=250&%s' %
                                l)

            tabCols = [
                ('str', 'Filename'),
                #('isodate', 'Last Accessed'),
                #('isodate', 'First Downloaded'),
                ('int', 'Hits'),
                ('int', 'Size'),
            ]

            return ctx.tag[
                PageHelpers.TabSwitcher(
                    (
                        ('Stats', 'panelStats'),
                        ('Windows', 'panelWindows'),
                        ('Linux', 'panelLinux'),
                        #('AntiVirus', 'panelAntivirus')
                    ),
                    id="update"),
                tags.div(id='panelStats', _class='tabPane')[
                    tags.h3["Stats"], tags.strong["Disk utilisation"], tags.br,
                    pie, tags.br, tags.strong["Overall savings"], tags.br,
                    overallSavings(), tags.br, tags.strong["Total Use:"],
                    Utils.intToH(totals['total'][1])],
                tags.div(id='panelWindows', _class='tabPane')[
                    tags.h3[tags.img(src="/images/windows.png"),
                            "Windows update cache"],
                    statSet('microsoft'), tags.h3["Most signficant updates"],
                    PageHelpers.dataTable(tabCols, [(
                        i[1],
                        i[2] or 0,
                        Utils.intToH(i[3] or 0),
                    ) for i in cache.get('microsoft', [])[-10:]],
                                          sortable=True)],
                tags.div(id='panelLinux', _class='tabPane')[
                    tags.h3[tags.img(src="/images/penguin.png"),
                            "Linux update cache"],
                    statSet('linux'), tags.h3["Most signficant updates"],
                    PageHelpers.dataTable(tabCols, [(
                        i[1],
                        i[2] or 0,
                        Utils.intToH(i[3] or 0),
                    ) for i in cache.get('linux', [])[-10:]],
                                          sortable=True)],
                #tags.div(id='panelAntivirus', _class='tabPane')[
                #    ""
                #],
                PageHelpers.LoadTabSwitcher(id="update")]
Example #6
0
    def render_content(self, ctx, data):
        interfaces = Utils.getInterfaces() + self.sysconf.EthernetDevices.keys(
        )
        params = Utils.parseNet()
        d = {}
        vlans = []
        routes = {}
        types = {}
        vali = []
        traffic = {}
        da = datetime.datetime.now()
        today = "%s%s%s" % (da.day, da.month, da.year)
        for i in interfaces:
            if 'tap' not in i and 'eth' not in i and 'ppp' not in i and 'vlan' not in i:
                continue
            if not "vlan" in i:
                if i in d.keys():
                    pass
                if i in params.keys():
                    types[i] = params[i]['type']
                    routes[i] = [params[i].get('network', '')]
                    if params[i]['type'] == 'static':
                        d[i] = params[i]['ip']
                    if params[i]['type'] == 'manual':
                        d[i] = "Manual"
                    else:
                        d[i] = "DHCP"
                else:
                    types[i] = ""
                    routes[i] = ""
                    d[i] = ""
            else:
                vlans.append((i, params[i]['ip'],
                              tags.a(title="Edit Interface %s" % i,
                                     href="Edit/%s" %
                                     i)[tags.img(src="/images/edit.png")]))
            # Read the traffic counters
            try:
                p = open('/usr/local/tcs/tums/rrd/iface_%s_%stotal.nid' %
                         (i, today)).read().split(':')
                traffic[i] = (float(p[0]), float(p[1]))
            except:
                traffic[i] = (0, 0)

        return ctx.tag[
            tags.h3[tags.img(src="/images/stock-disconnect.png"),
                    self.text.toolsMenuNetconf],
            PageHelpers.TabSwitcher((
                ('Interface Configuration', 'panelIface'),
                ('VLAN Configuration', 'panelVlan'),
                ('IPv6 Tunnel', 'panelTunnel'),
                ('Advanced', 'panelAdvanced'),
            )),
            tags.div(id="panelIface", _class="tabPane")[
                tags.h3["Interfaces"],
                tags.table(width="95%")[[
                    tags.tr[[
                        tags.td[self.roundedBlock(j, [
                            tags.img(src="/images/graphs/iface-%sFS.png" %
                                     j), tags.
                            table[tags.tr(valign="top")[
                                tags.td[tags.strong["Traffic Out (24h): "]],
                                tags.td[Utils.intToH(traffic[j][1])]],
                                  tags.tr(
                                      valign="top"
                                  )[tags.td[tags.strong["Traffic In (24h): "]],
                                    tags.td[Utils.intToH(traffic[j][0])]],
                                  tags.tr(valign="top")[
                                      tags.td[tags.
                                              strong["Configuration Type: "]],
                                      tags.td[types[j] == 'dhcp' and 'DHCP'
                                              or 'Static']],
                                  tags.tr(valign="top")[
                                      tags.td[tags.
                                              strong["Associated Routes: "]],
                                      tags.td[[[k, tags.br] for k in routes.
                                               get(j, ["None"])]]],
                                  tags.tr(
                                      valign="top"
                                  )[tags.td[tags.a(title="Edit Interface %s" %
                                                   j,
                                                   href="Edit/%s" %
                                                   j)[tags.img(
                                                       src="/images/edit.png"),
                                                      " Edit Settings"]],
                                    tags.td[""]]]
                        ])] for j in i if j
                    ]] for i in WebUtils.runIter(1, d.keys())
                ]], tags.br,
                #tags.h3["Add interface"],
                #tags.directive('form addInterface')
            ],
            tags.div(id="panelVlan", _class="tabPane")[
                tags.h3["Configured VLAN Interfaces"],
                PageHelpers.dataTable(('Interface', 'IP', ''), vlans), tags.br,
                tags.h3["Add VLAN"],
                tags.directive('form addVLAN')],
            tags.div(id="panelTunnel", _class="tabPane")[
                tags.h3["Configure IPv6 Tunnel"],
                tags.directive('form tunnelConf')],
            tags.div(id="panelAdvanced", _class="tabPane")
            [tags.h3["Advanced Settings"], tags.
             p["If you are unsure of any of these settings you should almost certainly not change them"],
             tags.directive('form advanced')],
            PageHelpers.LoadTabSwitcher(), ]
Example #7
0
class Page(Reports.Page):
    docFactory = loaders.xmlfile('overview.xml',
                                 templateDir=Settings.BaseDir + '/templates')

    def roundedBlock(self, title, content):
        return tags.div(_class="roundedBlock")[tags.img(
            src="/images/network-small.png"), tags.h1[title],
                                               tags.div[content]]

    def yearGraph(self, iface, stat):
        # This guy generates an image tag which makes a pyCha

        inset = []
        outset = []
        lables = []

        tmax = max([i[1] for i in stat])
        tmaxo = max([i[0] for i in stat])
        if tmaxo > tmax:
            tmax = tmaxo

        if tmax > 1000:
            off = 1000
            cstart = "/chart?type=line&width=500&height=200&ylab=Data+volume+(GBytes)&legright=y"
        else:
            off = 1
            cstart = "/chart?type=line&width=500&height=200&ylab=Data+volume+(MBytes)&legright=y"

        for data in stat:
            inset.append(data[0] / off)
            outset.append(data[1] / off)
            lables.append('%.2d %s' % (data[3], data[2]))

        cstart += "&set=In&data=%s" % ('+'.join([str(i) for i in inset]))
        cstart += "&set=Out&data=%s" % ('+'.join([str(i) for i in outset]))

        for lable in lables:
            cstart += "&lables=%s" % lable

        return tags.img(src=cstart)

    def getStats(self):
        # Get rolling monthly stats for 12 months on each interface
        interfaces = Utils.getInterfaces()
        stat = {}
        da = datetime.datetime.now()

        year = da.year

        stats = os.listdir('/usr/local/tcs/tums/rrd/')

        for n in stats:
            if not ((str(year) in n) or (str(year - 1) in n)):
                # Ditch superflous years without hesitation
                continue

            if not 'total' in n:
                continue

            if n[-4:] != ".nid":
                continue
            # Figure out interface
            iface = n.split('_')[1]
            date = n.split('_')[2].replace('total.nid', '')
            segYear = int(date[-4:])

            date = time.localtime(
                os.stat('/usr/local/tcs/tums/rrd/%s' % n).st_mtime)

            if segYear == date[0]:
                # Probably ok
                segMonth = date[1]
            else:
                # Someone has messed with the time stamp on the file :(
                sm = date[-6:-4]
                if int(sm) > 12:
                    segMonth = int(sm[1])
                else:
                    segMonth = int(sm)

            # Grab the contents...
            l = open('/usr/local/tcs/tums/rrd/%s' % n)
            try:
                iin, iout = [
                    int(float(i) / 1000000)
                    for i in l.read().strip('\n').strip().split(':')
                ]
            except:
                inn, iout = (0, 0)

            if iface not in stat:
                stat[iface] = {}

            stamp = "%s%.2d" % (segYear, segMonth)
            if stamp in stat[iface]:
                stat[iface][stamp][0] += iin
                stat[iface][stamp][1] += iout
            else:
                stat[iface][stamp] = [iin, iout, segYear, segMonth]
        newstat = {}
        for iface, detail in stat.items():
            dlist = detail.keys()
            dlist.sort()
            # Pick the most recent 12
            ourlist = dlist[-12:]
            newstat[iface] = []

            # Reconstruct an ordered set for each interface instead of an unordered dictionary
            for n in ourlist:
                newstat[iface].append(detail[n])

        return newstat

    def render_content(self, ctx, seg):
        interfaces = Utils.getInterfaces()
        stat = {}
        da = datetime.datetime.now()
        month = "%s%s" % (da.month, da.year)

        lastmonth = "%s%s" % (
            (da.month - 1) or 12,  # 12th month if current month is 1
            (da.month - 1) and da.year
            or da.year - 1  # Previous year if current month is 1
        )
        today = "%s%s%s" % (da.day, da.month, da.year)
        for i in interfaces:
            if not 'tap' in i and not 'eth' in i and not 'ppp' in i:
                continue
            stat[i] = {'24': [0, 0], 'month': [0, 0], 'lastmonth': [0, 0]}
            # Read the traffic counters
            try:
                p = open('/usr/local/tcs/tums/rrd/iface_%s_%stotal.nid' %
                         (i, today)).read().split(':')
                stat[i]['24'] = (float(p[0]), float(p[1]))  # Last 24 Hours
                # Try figure out the whole day

                for fi in os.listdir('/usr/local/tcs/tums/rrd/'):

                    if 'iface_%s' % i in fi and "%stotal.nid" % month in fi:
                        p = open('/usr/local/tcs/tums/rrd/' +
                                 fi).read().split(':')
                        for j in xrange(2):
                            stat[i]['month'][j] += float(p[j])

                    if 'iface_%s' % i in fi and "%stotal.nid" % lastmonth in fi:
                        p = open('/usr/local/tcs/tums/rrd/' +
                                 fi).read().split(':')
                        for j in xrange(2):
                            stat[i]['lastmonth'][j] += float(p[j])

            except Exception, e:
                stat[i]['24'] = (0, 0)
                stat[i]['month'] = (0, 0)

        yearStats = self.getStats()

        return ctx.tag[
            tags.h3[tags.img(src="/images/system.png"),
                    " Interface Statistics"],
            tags.table(width="95%")[[
                tags.tr[[
                    tags.td[self.roundedBlock(j, [
                        tags.img(src="/images/graphs/iface-%sFS.png" %
                                 j), tags.h3["Traffic"],
                        self.yearGraph(j, yearStats[j]),
                        tags.table(cellpadding=5)[tags.tr(valign="top")[
                            tags.td[tags.strong["Today: "]],
                            tags.td[tags.table(cellspacing=0, cellpadding=0)[
                                tags.tr[tags.td["Out: "], tags.
                                        td[Utils.intToH(stat[j]['24'][1])], ],
                                tags.tr[tags.td["In: "], tags.
                                        td[Utils.intToH(stat[j]['24'][0])]]]]],
                                                  tags.tr(
                                                      valign="top"
                                                  )[tags.
                                                    td[tags.
                                                       strong["This Month: "]],
                                                    tags.td[tags.table(
                                                        cellspacing=0,
                                                        cellpadding=0
                                                    )[tags.tr[
                                                        tags.td["Out: "],
                                                        tags.td[Utils.intToH(
                                                            stat[j]['month'][1]
                                                        )], ], tags.
                                                      tr[tags.td["In: "],
                                                         tags.td[Utils.intToH(
                                                             stat[j]['month'][0]
                                                         )]]]]],
                                                  tags.tr(
                                                      valign="top"
                                                  )[tags.td[tags.strong[
                                                      "Previous Month: "]],
                                                    tags.td[tags.table(
                                                        cellspacing=0,
                                                        cellpadding=0
                                                    )[tags.tr[
                                                        tags.td["Out: "], tags.
                                                        td[Utils.intToH(stat[
                                                            j]['lastmonth'][1]
                                                                        )], ],
                                                      tags.
                                                      tr[tags.td["In: "], tags.
                                                         td[Utils.intToH(stat[
                                                             j]['lastmonth'][0]
                                                                         )]]]]],
                                                  ]
                    ])] for j in i if j
                ]] for i in WebUtils.runIter(1, stat.keys())
            ]]]
Example #8
0
    def render_content(self, ctx, data):
        table = []
        header = []
        title = "?"
        total = 0
        tin = 0
        tout = 0
        other = []
        if self.ip:
            # Render a hosts overview, utilisation by port
            title = "Internet Usage by port for %s during %s" % (
                self.ip, self.dateStamp())
            portStats = self.flowDb.getPortBreakdownForIp(
                self.month, self.year, self.ip, self.day)
            header = [
                "Port", "Traffic In", "Traffic Out", "Percentage of Total"
            ]
            for port, inout in portStats.items():
                if (inout[0] + inout[1]) > 1024:
                    table.append([
                        inout[0] + inout[1],
                        self.resolvePort(port),
                        Utils.intToH(inout[0]),
                        Utils.intToH(inout[1])
                    ])
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]

        elif self.view == "Ports":
            title = "Internet Usage by port for all users during %s" % (
                self.dateStamp())
            header = [
                "Port", "Traffic In", "Traffic Out", "Percentage of Total"
            ]
            portStats = self.flowDb.getPortTotals(self.month, self.year,
                                                  self.day)
            portList = []
            for port, inout in portStats.items():
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]
                if (inout[0] + inout[1]) > 1024:
                    # discard the data if it's not of valuable size
                    table.append([
                        inout[0] + inout[1],
                        self.resolvePort(port),
                        Utils.intToH(inout[0]),
                        Utils.intToH(inout[1])
                    ])
                portList.append(port)

            # sort this data before we create the port distribution
            portList.sort()

        else:
            title = "Internet Usage by IP during %s" % (self.dateStamp())
            header = [
                "IP Address", "Traffic In", "Traffic Out",
                "Percentage of Total"
            ]
            ipStats = self.flowDb.getVolumeTotalByIp(self.month, self.year,
                                                     self.day)
            for ip, inout in ipStats.items():
                table.append([
                    inout[0] + inout[1],
                    tags.a(href=url.root.child("NetworkStats").child(
                        "Host").child(ip).child(self.dateLink()),
                           title="View detail")[ip],
                    Utils.intToH(inout[0]),
                    Utils.intToH(inout[1])
                ])
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]

        table.sort()
        table = [
            i[1:] + [PageHelpers.progressBar(float(i[0]) / float(total))]
            for i in table
        ]
        table.append([
            tags.a(href=url.root.child("NetworkStats").child("Ports").child(
                self.dateLink()),
                   title="View port usage for this time")['All'],
            Utils.intToH(tin),
            Utils.intToH(tout),
            PageHelpers.progressBar(1)
        ])

        return ctx.tag[
            tags.h2[tags.img(src="/images/netflow.png"),
                    " Network utilisation"],
            tags.img(src="/images/cisco.png",
                     style="position:absolute; margin-left:25em;"),
            tags.directive('form dateRange'), tags.h3[title],
            #other,
            PageHelpers.dataTable(header, reversed(table)), tags.br,
            tags.a(name="us")[''], tags.
            p[tags.strong["* Unknown Services:"],
              """ Because large volumes of traffic are undefinable (MSN, Bittorrent, etc),
            during the aggregation process we must lump "high ports" (ports >1024) which can not be defined into a bigger subset called "Unknown Services".
            The reason for this is that this data is often a small amount of noise but accounts for many individual packets, 
            accounting the value of each of these ports will not provide any useful data to the person viewing it as the application 
            responsible for it is undefined. Processing the data without this aggregation also increases the volume of data considerably, 
            and the resources required to view it. If the value is extremely high, the most likely reasons are a virus infection or Bittorent activity.
            """]]
Example #9
0
    def render_content(self, ctx, data):
        table = []
        header = []
        title = "?"
        total = 0
        tin = 0 
        tout = 0
        other = []
        extraStats = ""
        internet = None
        if self.ip and self.view == "Host":
            # Render a hosts overview, utilisation by port
            title = "Local Internet Usage by port for %s during %s" % (self.ip.replace('0.0.0.0', 'Vulani Server'), self.dateStamp())
            portStats = self.flowDb.getPortBreakdownForIp(self.month, self.year, self.ip, self.day)
            header = ["Port", "Traffic In", "Traffic Out", "Percentage of Total"]
            for port, inout in portStats.items():
                if (inout[0] + inout[1]) > 1024:
                    table.append([inout[0]+inout[1],self.resolvePort(port), Utils.intToH(inout[0]), Utils.intToH(inout[1])])
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]

        elif self.view == "Ports":
            title = "Local Internet Usage by port for all users during %s" % (self.dateStamp())
            header = ["Port", "Traffic In", "Traffic Out", "Percentage of Total"]
            portStats = self.flowDb.getPortTotals(self.month, self.year, self.day)
            portList = []
            for port, inout in portStats.items():
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]
                if (inout[0] + inout[1]) > 1024:
                    # discard the data if it's not of valuable size
                    table.append([inout[0]+inout[1], self.resolvePort(port), Utils.intToH(inout[0]), Utils.intToH(inout[1])])
                portList.append(port)

            # sort this data before we create the port distribution
            portList.sort()

        elif self.view=="Interface":
            title = "Local Internet Usage by IP or username for all users during %s on interface %s" % (
                self.dateStamp(), 
                Utils.getInterfaceFromIndex(self.sysconf, self.index)
            )
            header = ["Port", "Traffic In", "Traffic Out", "Percentage of Total"]
            ipStats = self.flowDb.getVolumeTotalByIp(self.month, self.year, self.day, self.index)
            for ip, inout in ipStats.items():
                ipn = ip
                if ip == '0.0.0.0':
                    ipn = "Vulani Server"
                    
                table.append([
                    inout[0]+inout[1],
                    tags.a(
                        href=url.root.child("NetworkStats").child("InterfaceIP").child(str(self.index)).child(ip).child(self.day).child(self.month).child(self.year), title="View detail"
                    )[ipn], 
                    Utils.intToH(inout[0]), 
                    Utils.intToH(inout[1])
                ])
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]

        elif self.view=="InterfacePorts":
            title = "Local Internet Usage by port for all users during %s on interface %s" % (
                self.dateStamp(),
                Utils.getInterfaceFromIndex(self.sysconf, self.index)
            )
            header = ["Port", "Traffic In", "Traffic Out", "Percentage of Total"]
            portStats = self.flowDb.getPortTotals(self.month, self.year, self.day, self.index)
            portList = []
            for port, inout in portStats.items():
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]
                if (inout[0] + inout[1]) > 1024:
                    # discard the data if it's not of valuable size
                    table.append([inout[0]+inout[1], self.resolvePort(port), Utils.intToH(inout[0]), Utils.intToH(inout[1])])
                portList.append(port)

            # sort this data before we create the port distribution
            portList.sort()

        elif self.view=="InterfaceIP":
            title = "Local Internet Usage by port for %s during %s on interface %s" % (
                self.ip,
                self.dateStamp(),
                Utils.getInterfaceFromIndex(self.sysconf, self.index)
            )
            header = ["Port", "Traffic In", "Traffic Out", "Percentage of Total"]

            # Render a hosts overview, utilisation by port
            portStats = self.flowDb.getPortBreakdownForIp(self.month, self.year, self.ip, self.day, self.index)

            header = ["Port", "Traffic In", "Traffic Out", "Percentage of Total"]
            for port, inout in portStats.items():
                if (inout[0] + inout[1]) > 1024:
                    table.append([inout[0]+inout[1],self.resolvePort(port), Utils.intToH(inout[0]), Utils.intToH(inout[1])])
                total += inout[0] + inout[1]
                tin += inout[0]
                tout += inout[1]

        else:
            title = "Local Internet Usage by IP or username during %s" % (self.dateStamp())
            header = ["IP Address", "Traffic In", "Traffic Out", "Percentage of Total"]
            ipStats = self.flowDb.getVolumeTotalByIp(self.month, self.year, self.day)
            
            userGraph = "/chart?type=pie&width=500&height=250&legright=y&"
            userSet = []
            for ip, inout in ipStats.items():
                ipn = ip
                if ip == '0.0.0.0':
                    ipn = "Vulani Server"
                merged = inout[0]+inout[1]
                table.append([
                    merged,
                    tags.a(href=url.root.child("NetworkStats").child("Host").child(ip).child(self.day).child(self.month).child(self.year), title="View detail")[ipn], 
                    Utils.intToH(inout[0]), 
                    Utils.intToH(inout[1])
                ])
                total += merged
                tin += inout[0]
                tout += inout[1]

                userSet.append((merged, ipn))
            
            userSet.sort()
            userGraph += "&".join(["lables=%s&data=%s" % (ipn, utotal) for utotal, ipn in reversed(userSet[-5:])])
            otherUsersTotal = total - sum([utotal for utotal, ipn in userSet[-5:]])
            userGraph += "&lables=%s&data=%s" % ("Other Users", otherUsersTotal)

            extraStats = [tags.img(src=userGraph), tags.br]

            # Sort out our interface list
            totals = self.flowDb.getTotalIndex(self.month, self.year, self.day)
            print totals
            indexTable = []
            itotal, itin, itout = (0,0,0)
            ifDone = []

            totalGraph = "/chart?type=pie&width=500&height=250&legright=y&"

            totalSet = []
            interfaces = []
            for index, inout in totals.items():
                iface = Utils.getInterfaceFromIndex(self.sysconf, index)
                if not iface:
                    continue
                interfaces.append(iface)
                indexTable.append([
                    inout[0]+inout[1],
                    tags.a(href=url.root.child("NetworkStats").child("Interface").child(index).child(self.day).child(self.month).child(self.year), title="View detail")[iface],
                    Utils.intToH(inout[0]),
                    Utils.intToH(inout[1])
                ])
                itotal += inout[0] + inout[1]
                itin += inout[0]
                itout += inout[1]

                totalSet.append("lables=%s&data=%s" % (iface, inout[0]+inout[1]))

            totalGraph+= '&'.join(totalSet)

            indexTable.sort()

            indexTable = [i[1:]+[PageHelpers.progressBar(float(i[0])/float(itotal), colour="#f8be0f")] for i in indexTable]
            indexTable.append([
                tags.a(href=url.root.child("NetworkStats").child("Ports").child(self.day).child(self.month).child(self.year), title="View port usage for this time")['Total Usage'], 
                Utils.intToH(itin), Utils.intToH(itout), PageHelpers.progressBar(1)
            ])

            other = [
                tags.h3['Internet usage by network interface'], 
                tags.img(src=totalGraph), tags.br, 
                PageHelpers.dataTable(header, reversed(indexTable)),tags.br
            ]

            if self.day == 0:
                # Generate a bar graph of usage per day
                nids, maxDays, maxunit = NetUtils.getNIDdaySummary(self.year, self.month)

                cstart = "/chart?type=line&width=500&height=200&legright=y"

                if maxunit > (1000**3):
                    scale = 1000**3
                    unit = "GBytes"
                else:
                    scale = 1000**2
                    unit = "MBytes"
                cstart += "&ylab=Data+volume+(%s)" % unit

                tdata = []
                for ifa in interfaces:
                    if not ifa in nids:
                        continue
                    ndata = []
                    dset = ["0" for i in range(maxDays)]
                    for day, vols in nids[ifa]:
                        dset[day-1] = "%d" % int((vols[0]+vols[1])/scale)
                    cstart += "&set=%s&data=%s" % (ifa, '+'.join(dset))
            
                for d in range(maxDays):
                    cstart += "&lables=%s" % (d+1)

                other.insert(0, tags.img(src=cstart))

        # Sort the table and add internet usage
        table.sort()
        if internet:
            table.append(internet)
        
        # Reformat our table with progress bars
        table = [i[1:]+[PageHelpers.progressBar(float(i[0])/float(total), colour="#f8be0f")] for i in table]

        # Add the 'Total' total to the table.
        if self.index:
            table.append([
                tags.a(href=url.root.child("NetworkStats").child("InterfacePorts").child(str(self.index)).child(self.day).child(self.month).child(self.year), title="View port usage for this time")['Total Usage'], 
                Utils.intToH(tin), Utils.intToH(tout), PageHelpers.progressBar(1)
            ])
        else:
            table.append([
                tags.a(href=url.root.child("NetworkStats").child("Ports").child(self.day).child(self.month).child(self.year), title="View port usage for this time")['Total Usage'], 
                Utils.intToH(tin), Utils.intToH(tout), PageHelpers.progressBar(1)
            ])

        return ctx.tag[
            tags.h2[tags.img(src="/images/netflow.png")," Network utilisation"],
            tags.directive('form dateRange'),
            other,
            tags.h3[title],
            extraStats,
            PageHelpers.dataTable(header, reversed(table)),tags.br,
            tags.a(name="us")[''],
            tags.p[tags.strong["* Unknown Services:"],""" Because large volumes of traffic are undefinable (MSN, Bittorrent, etc),
            during the aggregation process we must lump "high ports" (ports >1024) which can not be defined into a bigger subset called "Unknown Services".
            The reason for this is that this data is often a small amount of noise but accounts for many individual packets, 
            accounting the value of each of these ports will not provide any useful data to the person viewing it as the application 
            responsible for it is undefined. Processing the data without this aggregation also increases the volume of data considerably, 
            and the resources required to view it. If the value is extremely high, the most likely reasons are a virus infection or Bittorent activity.
            """]
        ]