From fd303bf3c455d1622fc97b83cfeefd2c1789d4eb Mon Sep 17 00:00:00 2001 From: Perry Mason Date: Sun, 8 Feb 2009 13:08:37 +0100 Subject: vnstat config added --- config/vnstat/vnstat.inc | 229 +++++++++++++++++++++++++++++++++++++++++++++++ config/vnstat/vnstat.xml | 33 +++++++ 2 files changed, 262 insertions(+) create mode 100644 config/vnstat/vnstat.inc create mode 100644 config/vnstat/vnstat.xml (limited to 'config') diff --git a/config/vnstat/vnstat.inc b/config/vnstat/vnstat.inc new file mode 100644 index 00000000..26581a40 --- /dev/null +++ b/config/vnstat/vnstat.inc @@ -0,0 +1,229 @@ + 0) + { + unset($config['cron']['item'][$x_name]); + write_config(); + } + configure_cron(); +} + +function vnstat_install_config() { + global $config; +// Unpack and move Vnstat frontend + exec("cd .."); + exec("tar -zxovf /usr/local/pkg/vnstat_php_frontend-1.4.1.tar.gz"); + exec("mv vnstat_php_frontend-1.4.1 /usr/local/www/vnstat"); +// Add cron job to config.xml + $cron_item = array(); + $cron_item['minute'] = "*/1"; + $cron_item['hour'] = "*"; + $cron_item['mday'] = "*"; + $cron_item['month'] = "*"; + $cron_item['wday'] = "*"; + $cron_item['who'] = "root"; + $cron_item['command'] = "/usr/local/bin/vnstat -u"; + $config['cron']['item'][] = $cron_item; + write_config(); + configure_cron(); +// 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): + $ifinfo = get_interface_info($ifdescr); + $real_nic_names = convert_friendly_interface_to_real_interface_name($ifname); + array_push($array_of_real_nic_names, $real_nic_names); + endforeach; + // Get already nic's assigned to vnstat + exec("ls /var/db/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); + } +// Find information to be writing in config.php + // $iface_list_array_items + exec("ls /var/db/vnstat/ | grep -v '\.'", $vnstat_nic_in); + $iface_list_array_items = implode("', '", $vnstat_nic_in); + $iface_list_array = "\$iface_list = array('$iface_list_array_items');"; + // $iface_title_array_items + $iface_title_array_items = array(); + $iface_title_array_items2 = array(); + foreach ($vnstat_nic_in as $vnstat_nic_out) + { + $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_names3 = convert_friendly_interface_to_real_interface_name($ifname); + If ($real_nic_names3 == $vnstat_nic_out) + { + $ifname_out = $ifname; + $iface_title_array_items = "\$iface_title['$vnstat_nic_out'] = '$ifname_out';\n"; + array_push($iface_title_array_items2, $iface_title_array_items); + } + endforeach; + } + $iface_title_array = implode($iface_title_array_items2); + // php in php static items + $vnstat_bin2 = "\$vnstat_bin = '/usr/local/bin/vnstat';"; + $data_dir2 = "\$data_dir = './dumps';"; + $graph_format2 ="\$graph_format='svg';"; + $colorscheme2 = "\$colorscheme['light'] = array("; + $colorscheme3 = "\$colorscheme['red'] = array("; + $colorscheme4 = "\$colorscheme['pfSense'] = array("; + +// ************ Write new config.php ****************** + $config_file = << /path/to/data_dir/vnstat_dump_ + // +$vnstat_bin2 +$data_dir2 + + // graphics format to use: svg or png +$graph_format2 + + // Font to use for PNG graphs + define('GRAPH_FONT',dirname(__FILE__).'/VeraBd.ttf'); + + // Font to use for SVG graphs + define('SVG_FONT', 'Verdana'); + + // color schemes + // colors are defined as R,G,B,ALPHA quads where R, G and B range from 0-255 + // and ALPHA from 0-127 where 0 is opaque and 127 completely transparent. + // + define('DEFAULT_COLORSCHEME', 'pfSense'); + + $colorscheme2 + 'stylesheet' => 'vnstat.css', + 'image_background' => array( 255, 255, 255, 0 ), + 'graph_background' => array( 220, 220, 230, 0 ), + 'graph_background_2' => array( 205, 205, 220, 0 ), + 'grid_stipple_1' => array( 140, 140, 140, 0 ), + 'grid_stipple_2' => array( 200, 200, 200, 0 ), + 'border' => array( 0, 0, 0, 0 ), + 'text' => array( 0, 0, 0, 0 ), + 'rx' => array( 190, 190, 20, 50 ), + 'rx_border' => array( 40, 80, 40, 90 ), + 'tx' => array( 130, 160, 100, 50 ), + 'tx_border' => array( 80, 40, 40, 90 ) + ); + + // A red colorscheme based on a contribution by Enrico Tröger + $colorscheme3 + 'stylesheet' => 'vnstat_red.css', + 'image_background' => array( 225, 225, 225, 0 ), + 'graph_background' => array( 220, 220, 230, 0 ), + 'graph_background_2' => array( 205, 205, 220, 0 ), + 'grid_stipple_1' => array( 140, 140, 140, 0 ), + 'grid_stipple_2' => array( 200, 200, 200, 0 ), + 'border' => array( 0, 0, 0, 0 ), + 'text' => array( 0, 0, 0, 0 ), + 'rx' => array( 190, 20, 20, 50 ), + 'rx_border' => array( 80, 40, 40, 90 ), + 'tx' => array( 130, 130, 130, 50 ), + 'tx_border' => array( 60, 60, 60, 90 ) + ); + + // A red colorscheme based on a contribution by Perry Mason + $colorscheme4 + 'stylesheet' => 'vnstat_pfSense.css', + 'image_background' => array( 240, 240, 240, 0 ), + 'graph_background' => array( 255, 255, 255, 0 ), + 'graph_background_2' => array( 255, 255, 255, 0 ), + 'grid_stipple_1' => array( 144, 0, 0, 0 ), + 'grid_stipple_2' => array( 144, 0, 0, 0 ), + 'border' => array( 0, 0, 0, 0 ), + 'text' => array( 0, 0, 0, 0 ), + 'rx' => array( 190, 20, 20, 50 ), + 'rx_border' => array( 80, 40, 40, 90 ), + 'tx' => array( 130, 130, 130, 50 ), + 'tx_border' => array( 60, 60, 60, 90 ) + ); +?> +EOF; + + $hf = fopen("/usr/local/www/vnstat/config.php","w"); + if(!$hf) { + log_error("could not open /usr/local/www/vnstat/config.php for writing"); + exit; + } + fwrite($hf, $config_file); + fclose($hf); +} +?> + + diff --git a/config/vnstat/vnstat.xml b/config/vnstat/vnstat.xml new file mode 100644 index 00000000..8982d36f --- /dev/null +++ b/config/vnstat/vnstat.xml @@ -0,0 +1,33 @@ + + + + + + Describe your package here + Describe your package requirements here + Currently there are no FAQ items provided. + vnstat + 1.0 + vnstat + /pkg_edit.php?xml=vnstat.xml&id=0 + /usr/local/pkg/vnstat.inc + + vnstat + +
Status
+ /vnstat +
+ + /usr/local/pkg/ + 0644 + http://www.pfsense.com/packages/config/vnstat/vnstat.inc + + + /usr/local/pkg/ + 0644 + http://files.pfsense.org/packages/7/All/vnstat_php_frontend-1.4.1.tar.gz + + + vnstat_install_config(); + vnstat_install_deinstall(); +
-- cgit v1.2.3 From c252270f2a7811812a12ff408bad0f06e8ba583e Mon Sep 17 00:00:00 2001 From: Perry Mason Date: Mon, 9 Feb 2009 12:40:10 +0100 Subject: url changed --- config/vnstat/vnstat.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/vnstat/vnstat.xml b/config/vnstat/vnstat.xml index 8982d36f..2a0c06f5 100644 --- a/config/vnstat/vnstat.xml +++ b/config/vnstat/vnstat.xml @@ -25,7 +25,7 @@ /usr/local/pkg/ 0644 - http://files.pfsense.org/packages/7/All/vnstat_php_frontend-1.4.1.tar.gz + http://www.pfsense.com/packages/config/vnstat/bin/vnstat_php_frontend-1.4.1.tar.gz vnstat_install_config(); -- cgit v1.2.3