Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 1
<?php
2
 
3
/*
4
 * Copyright (C) 2019 Alexander Marston (alexander.marston@gmail.com)
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
 
20
// Require includes
21
require __DIR__ . '/vendor/autoload.php';
22
require __DIR__ . '/includes/vnstat.php';
23
require __DIR__ . '/includes/utilities.php';
24
require __DIR__ . '/includes/config.php';
25
 
26
// Initiaite vnStat class
27
$vnstat = new vnStat($vnstat_bin_dir);
28
 
29
// Initiate Smarty
30
$smarty = new Smarty();
31
 
32
// Set the current year
33
$smarty->assign('year', date("Y"));
34
 
35
// Set the list of interfaces
36
$interface_list = $vnstat->getInterfaces();
37
 
38
// Set the current interface
39
$thisInterface = "";
40
 
41
if (isset($_GET['i'])) {
42
    $interfaceChosen = rawurldecode($_GET['i']);
43
 
44
    if (in_array($interfaceChosen, $interface_list, true)) {
45
        $thisInterface = $interfaceChosen;
46
    } else {
47
        $thisInterface = reset($interface_list);
48
    }
49
} else {
50
    // Assume they mean the first interface
51
    $thisInterface = reset($interface_list);
52
}
53
 
54
 
55
$smarty->assign('current_interface', $thisInterface);
56
 
57
// Assign interface options
58
$smarty->assign('interface_list', $vnstat->getInterfaces());
59
 
60
// Populate table data
61
$hourlyData = $vnstat->getInterfaceData('hourly', 'table', $thisInterface);
62
$smarty->assign('hourlyTableData', $hourlyData);
63
 
64
$dailyData = $vnstat->getInterfaceData('daily', 'table', $thisInterface);
65
$smarty->assign('dailyTableData', $dailyData);
66
 
67
$monthlyData = $vnstat->getInterfaceData('monthly', 'table', $thisInterface);
68
$smarty->assign('monthlyTableData', $monthlyData);
69
 
70
$top10Data = $vnstat->getInterfaceData('top10', 'table', $thisInterface);
71
$smarty->assign('top10TableData', $top10Data);
72
 
73
// Populate graph data
74
$hourlyGraphData = $vnstat->getInterfaceData('hourly', 'graph', $thisInterface);
75
$smarty->assign('hourlyGraphData', $hourlyGraphData);
76
$smarty->assign('hourlyLargestPrefix', $hourlyGraphData[1]['delimiter']);
77
 
78
$dailyGraphData = $vnstat->getInterfaceData('daily', 'graph', $thisInterface);
79
$smarty->assign('dailyGraphData', $dailyGraphData);
80
$smarty->assign('dailyLargestPrefix', $dailyGraphData[1]['delimiter']);
81
 
82
$monthlyGraphData = $vnstat->getInterfaceData('monthly', 'graph', $thisInterface);
83
$smarty->assign('monthlyGraphData', $monthlyGraphData);
84
$smarty->assign('monthlyLargestPrefix', $monthlyGraphData[1]['delimiter']);
85
 
86
// Display the page
87
$smarty->display('templates/site_index.tpl');
88
 
89
?>