From 1d8944e08c21254c9e81b46c1edc64e9fde7da8e Mon Sep 17 00:00:00 2001 From: k-paulius Date: Mon, 13 Jul 2015 22:15:10 -0500 Subject: formatted vnstat2 php code --- config/vnstat2/vnstat2.inc | 273 ++++++++++++++++++------------------ config/vnstat2/www/diag_vnstat.php | 84 +++++------ config/vnstat2/www/diag_vnstat2.php | 106 +++++++------- config/vnstat2/www/vnstati.php | 1 - 4 files changed, 234 insertions(+), 230 deletions(-) diff --git a/config/vnstat2/vnstat2.inc b/config/vnstat2/vnstat2.inc index c875be52..afbf270a 100644 --- a/config/vnstat2/vnstat2.inc +++ b/config/vnstat2/vnstat2.inc @@ -1,15 +1,16 @@ 0) { + if ($is_installed == true) { + if ($x > 0) { unset($config['cron']['item'][$x]); write_config(); } @@ -55,8 +57,7 @@ function vnstat2_install_cron($vnstat_cron_value) { } } - -function change_vnstat_conf(){ +function change_vnstat_conf() { conf_mount_rw(); global $config; $config['installedpackages']['vnstat2']['config'][0]['monthrotate'] = $_POST['monthrotate']; @@ -64,21 +65,19 @@ function change_vnstat_conf(){ write_conf_f(); write_config(); - if ($config['installedpackages']['vnstat2']['config'][0]['vnstat_phpfrontend'] == "on"){ - vnstat_php_frontend(); - } - else { - exec("[ -d /usr/local/www/vnstat2 ] && rm -d -R /usr/local/www/vnstat2"); + if ($config['installedpackages']['vnstat2']['config'][0]['vnstat_phpfrontend'] == "on") { + vnstat_php_frontend(); + } else { + exec("[ -d /usr/local/www/vnstat2 ] && rm -d -R /usr/local/www/vnstat2"); } conf_mount_ro(); } -function write_conf_f(){ +function write_conf_f() { global $config; $monthrotate = $config['installedpackages']['vnstat2']['config'][0]['monthrotate']; -// ************ Write new vnstat.conf ***************** - + // ************ Write new vnstat.conf ***************** $vnstat_conf_file = << 'WAN', 'lan' => 'LAN'); + exec("ls /conf/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 = get_real_interface($ifdescr); - If ($real_nic_names3 == $vnstat_nic_out) - { - $ifname_out = convert_friendly_interface_to_friendly_descr($ifdescr); - $iface_title_array_items = "\$iface_title['$vnstat_nic_out'] = '$ifname_out';\n"; - array_push($iface_title_array_items2, $iface_title_array_items); - } - endforeach; + foreach ($ifdescrs as $ifdescr => $ifname) { + $real_nic_names3 = get_real_interface($ifdescr); + if ($real_nic_names3 == $vnstat_nic_out) { + $ifname_out = convert_friendly_interface_to_friendly_descr($ifdescr); + $iface_title_array_items = "\$iface_title['$vnstat_nic_out'] = '$ifname_out';\n"; + array_push($iface_title_array_items2, $iface_title_array_items); + } + } } - $iface_title_array = implode($iface_title_array_items2); + $iface_title_array = implode($iface_title_array_items2); // php in php static items // added to new items for the front end version 1.5.1 - $locale = "\$locale = 'en_US.UTF-8';"; - $language = "\$language = 'en';"; - $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 + // + // There are two possible sources for vnstat data. If the + // variable is set then vnstat is called directly from the PHP script + // to get the interface data. + // + // The other option is to periodically dump the vnstat interface data to + // a file (e.g. by a cronjob). In that case the variable + // must be cleared and set to the location where the dumps + // are stored. Dumps must be named 'vnstat_dump_'. + // + // You can generate vnstat dumps with the command: + // vnstat --dumpdb -i > /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'); + // graphics format to use: svg or png + $graph_format2 - // Font to use for SVG graphs - define('SVG_FONT', 'Verdana'); + // Font to use for PNG graphs + define('GRAPH_FONT',dirname(__FILE__).'/VeraBd.ttf'); - // 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'); + // 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'); ?> EOF; - $hf = fopen("/usr/local/www/vnstat2/config.php","w"); - if(!$hf) { - log_error("could not open /usr/local/www/vnstat2/config.php for writing"); - exit; - } - fwrite($hf, $config_file); - fclose($hf); + $hf = fopen("/usr/local/www/vnstat2/config.php","w"); + if (!$hf) { + log_error("could not open /usr/local/www/vnstat2/config.php for writing"); + exit; + } + fwrite($hf, $config_file); + fclose($hf); } + ?> diff --git a/config/vnstat2/www/diag_vnstat.php b/config/vnstat2/www/diag_vnstat.php index 04e03911..5e6524c7 100644 --- a/config/vnstat2/www/diag_vnstat.php +++ b/config/vnstat2/www/diag_vnstat.php @@ -1,30 +1,30 @@ "; echo $text; @@ -80,7 +80,7 @@ include("head.inc"); if ($pf_version < 2.0) echo "

{$pgtitle}

"; echo "Go Back
"; - if($savemsg) { + if ($savemsg) { echo "
"; print_info_box($savemsg); echo "
"; @@ -89,25 +89,27 @@ include("head.inc"); print_input_errors($input_errors); ?> - - - + + +
- - - - -
-
- - -
-
- -
-
-
- -
+ + + + +
+
+ + + + +
+
+ +
+
+
+ +
diff --git a/config/vnstat2/www/diag_vnstat2.php b/config/vnstat2/www/diag_vnstat2.php index e5ce1de5..504fd534 100644 --- a/config/vnstat2/www/diag_vnstat2.php +++ b/config/vnstat2/www/diag_vnstat2.php @@ -1,30 +1,30 @@ @@ -87,16 +89,18 @@ else
{$pgtitle}

"; - echo "Go Back
"; - if($savemsg) { + } + echo "Go Back
"; + if ($savemsg) { echo "
"; print_info_box($savemsg); echo "
"; } - if ($input_errors) + if ($input_errors) { print_input_errors($input_errors); + } ?>
@@ -107,29 +111,31 @@ else - +

- - - + + +
- - - - -
-
- - -
-
- -
-
-
- -
+ + + + +
+
+ + + + +
+
+ +
+
+
+ +

diff --git a/config/vnstat2/www/vnstati.php b/config/vnstat2/www/vnstati.php index e5ddcd21..01eca208 100644 --- a/config/vnstat2/www/vnstati.php +++ b/config/vnstat2/www/vnstati.php @@ -14,4 +14,3 @@ echo "

{$pgtitle}

";


- -- cgit v1.2.3