Subversion Repositories ALCASAR

Rev

Rev 1675 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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