17,10 → 17,10 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// |
// |
// see file COPYING or at http://www.gnu.org/licenses/gpl.html |
// see file COPYING or at http://www.gnu.org/licenses/gpl.html |
// for more information. |
// |
|
|
// |
// Valid values for other parameters you can pass to the script. |
// Input parameters will always be limited to one of the values listed here. |
39,17 → 39,17 |
{ |
die('can\'t determine script name!'); |
} |
|
|
$page_list = array('s','h','d','m'); |
|
|
$graph_list = array('large','small','none'); |
|
|
$page_title['s'] = T('summary'); |
$page_title['h'] = T('hours'); |
$page_title['d'] = T('days'); |
$page_title['m'] = T('months'); |
|
|
|
// |
// functions |
// |
83,14 → 83,14 |
} |
|
$tp = "./themes/$style"; |
if (!is_dir($tp) || !file_exists("$tp/theme.php") || !preg_match('/^[a-z0-9-_]+$/i', $style)) |
if (!is_dir($tp) || !file_exists("$tp/theme.php")) |
{ |
$style = DEFAULT_COLORSCHEME; |
} |
} |
|
|
|
function get_vnstat_data($use_label=true) |
function get_vnstat_data() |
{ |
global $iface, $vnstat_bin, $data_dir; |
global $hour,$day,$month,$top,$summary; |
100,7 → 100,7 |
if (file_exists("$data_dir/vnstat_dump_$iface")) |
{ |
$vnstat_data = file("$data_dir/vnstat_dump_$iface"); |
} |
} |
else |
{ |
$vnstat_data = array(); |
123,14 → 123,10 |
$month = array(); |
$top = array(); |
|
if (strpos($vnstat_data[0], 'Error') !== false) { |
return; |
} |
|
// |
// extract data |
// |
foreach($vnstat_data as $line) |
foreach($vnstat_data as $line) |
{ |
$d = explode(';', trim($line)); |
if ($d[0] == 'd') |
139,16 → 135,16 |
$day[$d[1]]['rx'] = $d[3] * 1024 + $d[5]; |
$day[$d[1]]['tx'] = $d[4] * 1024 + $d[6]; |
$day[$d[1]]['act'] = $d[7]; |
if ($d[2] != 0 && $use_label) |
if ($d[2] != 0) |
{ |
$day[$d[1]]['label'] = strftime(T('datefmt_days'),$d[2]); |
$day[$d[1]]['img_label'] = strftime(T('datefmt_days_img'), $d[2]); |
} |
elseif($use_label) |
else |
{ |
$day[$d[1]]['label'] = ''; |
$day[$d[1]]['img_label'] = ''; |
} |
$day[$d[1]]['img_label'] = ''; |
} |
} |
else if ($d[0] == 'm') |
{ |
156,15 → 152,15 |
$month[$d[1]]['rx'] = $d[3] * 1024 + $d[5]; |
$month[$d[1]]['tx'] = $d[4] * 1024 + $d[6]; |
$month[$d[1]]['act'] = $d[7]; |
if ($d[2] != 0 && $use_label) |
if ($d[2] != 0) |
{ |
$month[$d[1]]['label'] = strftime(T('datefmt_months'), $d[2]); |
$month[$d[1]]['img_label'] = strftime(T('datefmt_months_img'), $d[2]); |
} |
else if ($use_label) |
else |
{ |
$month[$d[1]]['label'] = ''; |
$month[$d[1]]['img_label'] = ''; |
$month[$d[1]]['img_label'] = ''; |
} |
} |
else if ($d[0] == 'h') |
173,7 → 169,7 |
$hour[$d[1]]['rx'] = $d[3]; |
$hour[$d[1]]['tx'] = $d[4]; |
$hour[$d[1]]['act'] = 1; |
if ($d[2] != 0 && $use_label) |
if ($d[2] != 0) |
{ |
$st = $d[2] - ($d[2] % 3600); |
$et = $st + 3600; |
180,7 → 176,7 |
$hour[$d[1]]['label'] = strftime(T('datefmt_hours'), $st).' - '.strftime(T('datefmt_hours'), $et); |
$hour[$d[1]]['img_label'] = strftime(T('datefmt_hours_img'), $d[2]); |
} |
else if ($use_label) |
else |
{ |
$hour[$d[1]]['label'] = ''; |
$hour[$d[1]]['img_label'] = ''; |
187,16 → 183,13 |
} |
} |
else if ($d[0] == 't') |
{ |
{ |
$top[$d[1]]['time'] = $d[2]; |
$top[$d[1]]['rx'] = $d[3] * 1024 + $d[5]; |
$top[$d[1]]['tx'] = $d[4] * 1024 + $d[6]; |
$top[$d[1]]['act'] = $d[7]; |
if($use_label) |
{ |
$top[$d[1]]['label'] = strftime(T('datefmt_top'), $d[2]); |
$top[$d[1]]['img_label'] = ''; |
} |
$top[$d[1]]['label'] = strftime(T('datefmt_top'), $d[2]); |
$top[$d[1]]['img_label'] = ''; |
} |
else |
{ |
203,9 → 196,16 |
$summary[$d[0]] = isset($d[1]) ? $d[1] : ''; |
} |
} |
if (count($day) == 0) |
$day[0] = 'nodata'; |
rsort($day); |
|
rsort($day); |
if (count($month) == 0) |
$month[0] = 'nodata'; |
rsort($month); |
|
if (count($hour) == 0) |
$hour[0] = 'nodata'; |
rsort($hour); |
} |
?> |