Subversion Repositories ALCASAR

Rev

Rev 1675 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1533 richard 1
<?php
2
    //
3
    // vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
4
    //
5
    // This program is free software; you can redistribute it and/or modify
6
    // it under the terms of the GNU General Public License as published by
7
    // the Free Software Foundation; either version 2 of the License, or
8
    // (at your option) any later version.
9
    //
10
    // This program is distributed in the hope that it will be useful,
11
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    // GNU General Public License for more details.
14
    //
15
    // You should have received a copy of the GNU General Public License
16
    // along with this program; if not, write to the Free Software
17
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
    //
19
    //
1675 richard 20
    // see file COPYING or at http://www.gnu.org/licenses/gpl.html
1533 richard 21
    // for more information.
22
    //
23
    require 'config.php';
24
    require 'localize.php';
25
    require 'vnstat.php';
26
 
27
    validate_input();
28
 
29
    require "./themes/$style/theme.php";
30
 
31
    function write_side_bar()
32
    {
33
        global $iface, $page, $graph, $script, $style;
1675 richard 34
        global $iface_list, $iface_title;
1533 richard 35
        global $page_list, $page_title;
1675 richard 36
 
1533 richard 37
        $p = "&amp;graph=$graph&amp;style=$style";
38
 
39
        print "<ul class=\"iface\">\n";
40
        foreach ($iface_list as $if)
41
        {
1675 richard 42
            if ($iface == $if) {
43
                print "<li class=\"iface active\">";
44
            } else {
45
                print "<li class=\"iface\">";
46
            }
47
            print "<a href=\"$script?if=$if$p\">";
1533 richard 48
            if (isset($iface_title[$if]))
49
            {
50
                print $iface_title[$if];
51
            }
52
            else
53
            {
54
                print $if;
55
            }
1675 richard 56
            print "</a>";
1533 richard 57
            print "<ul class=\"page\">\n";
58
            foreach ($page_list as $pg)
59
            {
60
                print "<li class=\"page\"><a href=\"$script?if=$if$p&amp;page=$pg\">".$page_title[$pg]."</a></li>\n";
61
            }
62
            print "</ul></li>\n";
63
        }
1675 richard 64
        print "</ul>\n";
1533 richard 65
    }
66
 
1675 richard 67
 
1533 richard 68
    function kbytes_to_string($kb)
69
    {
1675 richard 70
 
71
        global $byte_notation;
72
 
1533 richard 73
        $units = array('TB','GB','MB','KB');
74
        $scale = 1024*1024*1024;
75
        $ui = 0;
76
 
1675 richard 77
        $custom_size = isset($byte_notation) && in_array($byte_notation, $units);
78
 
79
        while ((($kb < $scale) && ($scale > 1)) || $custom_size)
1533 richard 80
        {
81
            $ui++;
82
            $scale = $scale / 1024;
1675 richard 83
 
84
            if ($custom_size && $units[$ui] == $byte_notation) {
85
                break;
86
            }
87
        }
88
 
1533 richard 89
        return sprintf("%0.2f %s", ($kb/$scale),$units[$ui]);
90
    }
1675 richard 91
 
1533 richard 92
    function write_summary()
93
    {
94
        global $summary,$top,$day,$hour,$month;
95
 
96
        $trx = $summary['totalrx']*1024+$summary['totalrxk'];
97
        $ttx = $summary['totaltx']*1024+$summary['totaltxk'];
98
 
99
        //
100
        // build array for write_data_table
101
        //
102
 
1675 richard 103
        $sum = array();
1533 richard 104
 
1675 richard 105
        if (count($day) > 0 && count($hour) > 0 && count($month) > 0) {
106
            $sum[0]['act'] = 1;
107
            $sum[0]['label'] = T('This hour');
108
            $sum[0]['rx'] = $hour[0]['rx'];
109
            $sum[0]['tx'] = $hour[0]['tx'];
1533 richard 110
 
1675 richard 111
            $sum[1]['act'] = 1;
112
            $sum[1]['label'] = T('This day');
113
            $sum[1]['rx'] = $day[0]['rx'];
114
            $sum[1]['tx'] = $day[0]['tx'];
1533 richard 115
 
1675 richard 116
            $sum[2]['act'] = 1;
117
            $sum[2]['label'] = T('This month');
118
            $sum[2]['rx'] = $month[0]['rx'];
119
            $sum[2]['tx'] = $month[0]['tx'];
120
 
121
            $sum[3]['act'] = 1;
122
            $sum[3]['label'] = T('All time');
123
            $sum[3]['rx'] = $trx;
124
            $sum[3]['tx'] = $ttx;
125
        }
126
 
1533 richard 127
        write_data_table(T('Summary'), $sum);
128
        print "<br/>\n";
129
        write_data_table(T('Top 10 days'), $top);
130
    }
1675 richard 131
 
132
 
1533 richard 133
    function write_data_table($caption, $tab)
134
    {
135
        print "<table width=\"100%\" cellspacing=\"0\">\n";
136
        print "<caption>$caption</caption>\n";
137
        print "<tr>";
138
        print "<th class=\"label\" style=\"width:120px;\">&nbsp;</th>";
139
        print "<th class=\"label\">".T('In')."</th>";
140
        print "<th class=\"label\">".T('Out')."</th>";
1675 richard 141
        print "<th class=\"label\">".T('Total')."</th>";
1533 richard 142
        print "</tr>\n";
143
 
144
        for ($i=0; $i<count($tab); $i++)
145
        {
146
            if ($tab[$i]['act'] == 1)
147
            {
148
                $t = $tab[$i]['label'];
149
                $rx = kbytes_to_string($tab[$i]['rx']);
150
                $tx = kbytes_to_string($tab[$i]['tx']);
151
                $total = kbytes_to_string($tab[$i]['rx']+$tab[$i]['tx']);
152
                $id = ($i & 1) ? 'odd' : 'even';
153
                print "<tr>";
154
                print "<td class=\"label_$id\">$t</td>";
155
                print "<td class=\"numeric_$id\">$rx</td>";
156
                print "<td class=\"numeric_$id\">$tx</td>";
157
                print "<td class=\"numeric_$id\">$total</td>";
158
                print "</tr>\n";
159
             }
160
        }
161
        print "</table>\n";
162
    }
163
 
164
    get_vnstat_data();
165
 
166
    //
167
    // html start
168
    //
169
    header('Content-type: text/html; charset=utf-8');
170
    print '<?xml version="1.0"?>';
2527 fabien.rak 171
 
172
    # Choice of language
173
    $Language = 'en';
174
    if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
175
    {
176
        $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
177
        $Language = strtolower(substr(chop($Langue[0]),0,2)); 
178
    }
179
    if($Language == 'fr')
180
    {
181
        $l_Pagename = "Traffic Global";
182
    }
183
    else
184
    {
185
        $l_Pagename = "Global Traffic";
186
    }
1675 richard 187
?>
1533 richard 188
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
189
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
190
<head>
2527 fabien.rak 191
    <title>vnStat - PHP frontend</title>
192
    <link rel="stylesheet" type="text/css" href="themes/<?php echo $style ?>/style.css"/>
193
    <link rel="stylesheet" href="../../manager/htdocs/style.css">
1533 richard 194
</head>
195
<body>
196
 
2527 fabien.rak 197
<table class="tableTop" border="0" cellspacing="0" cellpadding="0" >
198
    <tbody>     
199
        <tr>
200
            <th class="thBasicACC" >
201
                <?echo "$l_Pagename";?>
202
            </th>
203
        </tr>
204
    </tbody>
205
    <tr bgcolor="#FFCC66" class="trSizeACC">
206
        <td class="tdSizeACC">
207
            <img src="/images/pix.gif" width="1" height="2">
208
        </td>
209
    </tr>
210
</table>
211
 
212
<div class="frameBorderACC test">
213
 
214
<div  id="wrap" >
215
  <div  id="sidebar"><?php write_side_bar(); ?></div>
216
   <div id="content" style="width: 70%">
217
    <div id="header" ><?php print T('Traffic data for ').(isset($iface_title[$iface]) ? $iface_title[$iface] : '')." ($iface)";?></div>
218
    <div id="main" ">
1533 richard 219
    <?php
220
    $graph_params = "if=$iface&amp;page=$page&amp;style=$style";
221
    if ($page != 's')
222
        if ($graph_format == 'svg') {
2527 fabien.rak 223
         print "<object type=\"image/svg+xml\" width=\"692\" height=\"297\" data=\"graph_svg.php?$graph_params\"></object>\n";
1533 richard 224
        } else {
2527 fabien.rak 225
         print "<img src=\"graph.php?$graph_params\" alt=\"graph\"/>\n";
1533 richard 226
        }
227
 
228
    if ($page == 's')
229
    {
230
        write_summary();
231
    }
232
    else if ($page == 'h')
1675 richard 233
    {
234
        write_data_table(T('Last 24 hours'), $hour);
1533 richard 235
    }
236
    else if ($page == 'd')
237
    {
1675 richard 238
        write_data_table(T('Last 30 days'), $day);
1533 richard 239
    }
240
    else if ($page == 'm')
241
    {
1675 richard 242
        write_data_table(T('Last 12 months'), $month);
1533 richard 243
    }
244
    ?>
245
    </div>
1675 richard 246
    <div id="footer"><a href="http://www.sqweek.com/">vnStat PHP frontend</a> 1.5.2 - &copy;2006-2011 Bjorge Dijkstra (bjd _at_ jooz.net)</div>
1533 richard 247
  </div>
248
</div>
2527 fabien.rak 249
</div>
1533 richard 250
 
251
</body></html>