Subversion Repositories ALCASAR

Rev

Rev 2809 | Details | Compare with Previous | 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';
3108 rexy 22
require __DIR__ . '/includes/utilities.php';
2809 rexy 23
require __DIR__ . '/includes/vnstat.php';
24
require __DIR__ . '/includes/config.php';
25
 
3108 rexy 26
if (isset($vnstat_config)) {
27
    $vnstat_cmd = $vnstat_bin_dir.' --config '.$vnstat_config;
28
} else {
29
    $vnstat_cmd = $vnstat_bin_dir;
30
}
31
 
32
if (empty($graph_type)) {
33
    $graph_type = 'linear';
34
}
35
 
2809 rexy 36
// Initiaite vnStat class
3108 rexy 37
$vnstat = new vnStat($vnstat_cmd);
2809 rexy 38
 
39
// Initiate Smarty
40
$smarty = new Smarty();
41
 
42
// Set the current year
43
$smarty->assign('year', date("Y"));
44
 
45
// Set the list of interfaces
46
$interface_list = $vnstat->getInterfaces();
47
 
48
// Set the current interface
49
$thisInterface = "";
50
 
51
if (isset($_GET['i'])) {
52
    $interfaceChosen = rawurldecode($_GET['i']);
53
 
54
    if (in_array($interfaceChosen, $interface_list, true)) {
55
        $thisInterface = $interfaceChosen;
56
    } else {
57
        $thisInterface = reset($interface_list);
58
    }
59
} else {
60
    // Assume they mean the first interface
61
    $thisInterface = reset($interface_list);
62
}
63
 
3108 rexy 64
$smarty->assign('graph_type', $graph_type);
2809 rexy 65
 
66
$smarty->assign('current_interface', $thisInterface);
67
 
68
// Assign interface options
3108 rexy 69
$smarty->assign('interface_list', $interface_list);
2809 rexy 70
 
3108 rexy 71
// JsonVersion
72
$smarty->assign('jsonVersion', $vnstat->getVnstatJsonVersion());
73
 
2809 rexy 74
// Populate table data
3108 rexy 75
if ($vnstat->getVnstatJsonVersion() > 1) {
76
    $fiveData = $vnstat->getInterfaceData('five', 'table', $thisInterface);
77
    $smarty->assign('fiveTableData', $fiveData);
78
}
79
 
2809 rexy 80
$hourlyData = $vnstat->getInterfaceData('hourly', 'table', $thisInterface);
81
$smarty->assign('hourlyTableData', $hourlyData);
82
 
83
$dailyData = $vnstat->getInterfaceData('daily', 'table', $thisInterface);
84
$smarty->assign('dailyTableData', $dailyData);
85
 
86
$monthlyData = $vnstat->getInterfaceData('monthly', 'table', $thisInterface);
87
$smarty->assign('monthlyTableData', $monthlyData);
88
 
89
$top10Data = $vnstat->getInterfaceData('top10', 'table', $thisInterface);
90
$smarty->assign('top10TableData', $top10Data);
91
 
92
// Populate graph data
3108 rexy 93
if ($vnstat->getVnstatJsonVersion() > 1) {
94
    $fiveGraphData = $vnstat->getInterfaceData('five', 'graph', $thisInterface);
95
    $smarty->assign('fiveGraphData', $fiveGraphData);
96
    $smarty->assign('fiveLargestPrefix', $fiveGraphData[0]['delimiter']);
97
    $smarty->assign('fiveBase', $fiveGraphData[0]['base']);
98
}
99
 
2809 rexy 100
$hourlyGraphData = $vnstat->getInterfaceData('hourly', 'graph', $thisInterface);
101
$smarty->assign('hourlyGraphData', $hourlyGraphData);
3108 rexy 102
$smarty->assign('hourlyLargestPrefix', $hourlyGraphData[0]['delimiter']);
103
$smarty->assign('hourlyBase', $hourlyGraphData[0]['base']);
2809 rexy 104
 
105
$dailyGraphData = $vnstat->getInterfaceData('daily', 'graph', $thisInterface);
106
$smarty->assign('dailyGraphData', $dailyGraphData);
3108 rexy 107
$smarty->assign('dailyLargestPrefix', $dailyGraphData[0]['delimiter']);
108
$smarty->assign('dailyBase', $dailyGraphData[0]['base']);
2809 rexy 109
 
110
$monthlyGraphData = $vnstat->getInterfaceData('monthly', 'graph', $thisInterface);
111
$smarty->assign('monthlyGraphData', $monthlyGraphData);
3108 rexy 112
$smarty->assign('monthlyLargestPrefix', $monthlyGraphData[0]['delimiter']);
2809 rexy 113
 
114
// Display the page
115
$smarty->display('templates/site_index.tpl');
116
 
117
?>