Subversion Repositories ALCASAR

Rev

Rev 2809 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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