From 08ed466fe53f97da1b95ff8088a9ae61b11a6b3d Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 3 Feb 2015 14:14:03 -0500 Subject: Various fixes for vnstat2 for 2.2 and others. Version bump for new binaries. --- config/vnstat2/vnstat2.inc | 96 ++++++++++++++++++++++++-------------- config/vnstat2/vnstat2.xml | 2 +- config/vnstat2/www/vnstat2_img.php | 4 +- 3 files changed, 64 insertions(+), 38 deletions(-) (limited to 'config/vnstat2') diff --git a/config/vnstat2/vnstat2.inc b/config/vnstat2/vnstat2.inc index 7418530f..f248083e 100644 --- a/config/vnstat2/vnstat2.inc +++ b/config/vnstat2/vnstat2.inc @@ -1,4 +1,5 @@ 'WAN', 'lan' => 'LAN'); + for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { + $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; + } + foreach ($ifdescrs as $ifdescr => $ifname) { + $real_nic_names = convert_friendly_interface_to_real_interface_name($ifdescr); + array_push($array_of_real_nic_names, $real_nic_names); + } + $vnstat_nic = array_map('basename', glob($vnstat_db_prefix . '/*', GLOB_ONLYDIR)); + + // Compare real NICs with NICs assigned to vnstat + $leftovers = array_diff($array_of_real_nic_names, $vnstat_nic); + // Create database for each NIC + foreach ($leftovers as $nic) { + exec("/usr/local/bin/vnstat -u -i ". escapeshellarg($nic)); + } + + conf_mount_ro(); +} + function vnstat_install_config() { - global $config; + $vnstat_db_prefix = "/conf/vnstat"; conf_mount_rw(); // Create vnstat database dir where it also will work for nanobsd -// exec("[ -d /var/db/vnstat ] && mv /var/db/vnstat /conf/vnstat"); - exec("[ -d /usr/local/pkg/vnstat2/vnstat ] && mv /usr/local/pkg/vnstat2/vnstat /conf/vnstat"); - exec("[ ! -d /conf/vnstat ] && mkdir /conf/vnstat"); -// Check for pbi install and arch type then create symlinks - if (file_exists('/usr/pbi/vnstat-i386')) { exec("ln -s /usr/local/etc/vnstat.conf /usr/pbi/vnstat-i386/etc/vnstat.conf"); } - if (file_exists('/usr/pbi/vnstat-amd64')) { exec("ln -s /usr/local/etc/vnstat.conf /usr/pbi/vnstat-amd64/etc/vnstat.conf"); } + if (is_dir("/usr/local/pkg/vnstat2/vnstat")) { + @rename("/usr/local/pkg/vnstat2/vnstat", $vnstat_db_prefix); + } + if (!is_dir($vnstat_db_prefix)) { + @mkdir($vnstat_db_prefix); + } + vnstat_link_config(); // Add MonthRotate value to config.xml and write /usr/local/etc/vnstat.conf $no_monthrotate = $config['installedpackages']['vnstat2']['config'][0]['monthrotate']; if ($no_monthrotate == ""){ $config['installedpackages']['vnstat2']['config'][0]['monthrotate'] = "1"; } $no_vnstat_phpfrontend = $config['installedpackages']['vnstat2']['config'][0]['vnstat_phpfrontend']; - if ($no_vnstat_phpfrontend == "on"){ - vnstat_php_frontend(); + if ($no_vnstat_phpfrontend == "on"){ + vnstat_php_frontend(); } write_conf_f(); // Add cron job to config.xml vnstat2_install_cron(true); -// get system nic's and create a database for them - $array_of_real_nic_names = array(); - $array_of_custom_nic_names = array(); - $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN'); - for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) { - $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr']; - } - foreach ($ifdescrs as $ifdescr => $ifname): - $real_nic_names = convert_friendly_interface_to_real_interface_name($ifdescr); - array_push($array_of_real_nic_names, $real_nic_names); - endforeach; - // Get already nic's assigned to vnstat - exec("ls /conf/vnstat/ | grep -v '\.'", $vnstat_nic); - // Compare real nic's with nic's assigned to vnstat - $result = array_diff($array_of_real_nic_names, $vnstat_nic); - // Create database for each nic - foreach ($result as $result2) - { - exec("/usr/local/bin/vnstat -u -i ". $result2); - } - write_config(); - conf_mount_ro(); + vnstat_create_nic_dbs(); + write_config(); + conf_mount_ro(); } function vnstat_php_frontend(){ diff --git a/config/vnstat2/vnstat2.xml b/config/vnstat2/vnstat2.xml index ab07f004..94b7cfc1 100644 --- a/config/vnstat2/vnstat2.xml +++ b/config/vnstat2/vnstat2.xml @@ -7,7 +7,7 @@ Describe your package requirements here Currently there are no FAQ items provided. vnstat2 - 1.0 + 11.2,3 Vnstat2 /pkg_edit.php?xml=vnstat2.xml&id=0 /usr/local/pkg/vnstat2/vnstat2.inc diff --git a/config/vnstat2/www/vnstat2_img.php b/config/vnstat2/www/vnstat2_img.php index 85644309..a83c3b06 100644 --- a/config/vnstat2/www/vnstat2_img.php +++ b/config/vnstat2/www/vnstat2_img.php @@ -1,6 +1,6 @@ -- cgit v1.2.3