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