diff --git a/auth_changepassword.php b/auth_changepassword.php index dd2ac01fb..c732e5e8d 100644 --- a/auth_changepassword.php +++ b/auth_changepassword.php @@ -36,7 +36,7 @@ if (!isset($_SESSION['sess_user_id'])) { } $user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id'])); -$version = db_fetch_cell('SELECT cacti FROM version'); +$version = get_cacti_version(); $auth_method = read_config_option('auth_method'); if ($auth_method != 1 && $user['realm'] != 0) { diff --git a/auth_login.php b/auth_login.php index bc3aa343e..32d233c57 100644 --- a/auth_login.php +++ b/auth_login.php @@ -60,7 +60,7 @@ if (read_config_option('auth_method') == '2') { } $username = sanitize_search_string($username); -$version = db_fetch_cell('SELECT cacti FROM version'); +$version = get_cacti_version(); /* process login */ $copy_user = false; diff --git a/cli/add_data_query.php b/cli/add_data_query.php index ea2c62201..87a2df267 100644 --- a/cli/add_data_query.php +++ b/cli/add_data_query.php @@ -212,7 +212,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Data Query Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/add_device.php b/cli/add_device.php index 8fdea90e6..c737771ab 100644 --- a/cli/add_device.php +++ b/cli/add_device.php @@ -450,7 +450,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Device Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/add_graph_template.php b/cli/add_graph_template.php index c3d687c47..4667f729d 100644 --- a/cli/add_graph_template.php +++ b/cli/add_graph_template.php @@ -173,7 +173,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Graph Template Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/add_graphs.php b/cli/add_graphs.php index 271b64015..d5f49849c 100644 --- a/cli/add_graphs.php +++ b/cli/add_graphs.php @@ -682,7 +682,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Graphs Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/add_perms.php b/cli/add_perms.php index 6614b7a2c..d4324282c 100644 --- a/cli/add_perms.php +++ b/cli/add_perms.php @@ -243,7 +243,7 @@ if (sizeof($parms) == 0) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Permissions Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/add_tree.php b/cli/add_tree.php index 3f90f15d0..488e6490b 100644 --- a/cli/add_tree.php +++ b/cli/add_tree.php @@ -311,7 +311,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Tree Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/analyze_database.php b/cli/analyze_database.php index 0ea8941c7..e02ae1224 100644 --- a/cli/analyze_database.php +++ b/cli/analyze_database.php @@ -89,7 +89,7 @@ if (sizeof($tables)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Analyze Database Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/convert_innodb.php b/cli/convert_innodb.php index d5f276aa5..f0eed9e8b 100644 --- a/cli/convert_innodb.php +++ b/cli/convert_innodb.php @@ -120,7 +120,7 @@ if (sizeof($tables)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Database Conversion Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/copy_user.php b/cli/copy_user.php index e0cb5e002..628fd1128 100644 --- a/cli/copy_user.php +++ b/cli/copy_user.php @@ -78,7 +78,7 @@ print "User copied...\n"; /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Copy User Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/data_template_associate_rra.php b/cli/data_template_associate_rra.php index b54d9c325..11d773a8a 100644 --- a/cli/data_template_associate_rra.php +++ b/cli/data_template_associate_rra.php @@ -143,7 +143,7 @@ function associate($data_template_id, $data_rra, $debug, $quiet) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Data Template Associate RRD Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/host_update_template.php b/cli/host_update_template.php index adf756b1d..b34199201 100644 --- a/cli/host_update_template.php +++ b/cli/host_update_template.php @@ -159,7 +159,7 @@ if (db_fetch_cell("SELECT id FROM host_template WHERE id=$template") > 0) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Retemplate Host Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/import_package.php b/cli/import_package.php index 6c99dbeb9..b5754f702 100644 --- a/cli/import_package.php +++ b/cli/import_package.php @@ -143,7 +143,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Import Template Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/import_template.php b/cli/import_template.php index 7e886b98e..92b24ffc9 100644 --- a/cli/import_template.php +++ b/cli/import_template.php @@ -141,7 +141,7 @@ if (sizeof($parms)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Import Template Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/poller_data_sources_reapply_names.php b/cli/poller_data_sources_reapply_names.php index 301370cfc..2e4c83c2c 100644 --- a/cli/poller_data_sources_reapply_names.php +++ b/cli/poller_data_sources_reapply_names.php @@ -151,7 +151,7 @@ foreach ($data_source_list as $data_source) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Reapply Data Source Names Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/poller_graphs_reapply_names.php b/cli/poller_graphs_reapply_names.php index 0c6de70c6..556c1f720 100644 --- a/cli/poller_graphs_reapply_names.php +++ b/cli/poller_graphs_reapply_names.php @@ -147,7 +147,7 @@ foreach ($graph_list as $graph) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Reapply graph Names Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/poller_output_empty.php b/cli/poller_output_empty.php index fc9fdb6a7..dbc60b39b 100644 --- a/cli/poller_output_empty.php +++ b/cli/poller_output_empty.php @@ -89,7 +89,7 @@ rrd_close($rrdtool_pipe); /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Process Poller Output Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/poller_reindex_hosts.php b/cli/poller_reindex_hosts.php index 2c648acab..a71a39c47 100644 --- a/cli/poller_reindex_hosts.php +++ b/cli/poller_reindex_hosts.php @@ -139,7 +139,7 @@ if (sizeof($data_queries)) { /* display_help - displays the usage of the function */ function display_help () { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Reindex Host Utility, Version $version, " . COPYRIGHT_YEARS . "\n\n"; echo "usage: poller_reindex_hosts.php --id=[host_id|all] [--qid=[ID|all]] [--host-descr=[description]]\n"; echo " [-d] [-h] [--help] [-v] [--version]\n\n"; diff --git a/cli/rebuild_poller_cache.php b/cli/rebuild_poller_cache.php index eefde7650..bb1710860 100644 --- a/cli/rebuild_poller_cache.php +++ b/cli/rebuild_poller_cache.php @@ -128,7 +128,7 @@ ini_set('max_execution_time', $max_execution); /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Rebuild Poller Cache Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/removespikes.php b/cli/removespikes.php index 742ed816a..892707af2 100644 --- a/cli/removespikes.php +++ b/cli/removespikes.php @@ -1295,7 +1295,7 @@ function calculateStandardDeviation($items) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Spike Remover Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/reorder_data_query.php b/cli/reorder_data_query.php index f64e2dd97..a949a0375 100644 --- a/cli/reorder_data_query.php +++ b/cli/reorder_data_query.php @@ -152,7 +152,7 @@ if (sizeof($data_queries)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Reorder Data Query Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/repair_database.php b/cli/repair_database.php index e194a0534..c6e16522e 100644 --- a/cli/repair_database.php +++ b/cli/repair_database.php @@ -207,7 +207,7 @@ if ($total_rows > 0 && !$force) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Database Repair Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/repair_templates.php b/cli/repair_templates.php index 0e28efa8e..34ad0c5fc 100644 --- a/cli/repair_templates.php +++ b/cli/repair_templates.php @@ -137,7 +137,7 @@ if (sizeof($damaged_template_ids)) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Database Template Repair Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/sqltable_to_php.php b/cli/sqltable_to_php.php index 1134bc3a1..8b702343e 100644 --- a/cli/sqltable_to_php.php +++ b/cli/sqltable_to_php.php @@ -194,7 +194,7 @@ function sql_clean($text) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Add Device Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/structure_rra_paths.php b/cli/structure_rra_paths.php index 51b3f95a7..6dc948163 100644 --- a/cli/structure_rra_paths.php +++ b/cli/structure_rra_paths.php @@ -223,7 +223,7 @@ function disable_poller() { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Structured Paths Creation Utility, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/cli/upgrade_database.php b/cli/upgrade_database.php index 820c5d6a4..ca3df5800 100644 --- a/cli/upgrade_database.php +++ b/cli/upgrade_database.php @@ -23,15 +23,15 @@ +-------------------------------------------------------------------------+ */ -// do NOT run this script through a web browser +/* do NOT run this script through a web browser */ if (!isset($_SERVER['argv'][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) { die('
This script is only meant to run at the command line.'); } -// We are not talking to the browser +/* We are not talking to the browser */ $no_http_headers = true; -// allow the upgrade script to run for as long as it needs to +/* allow the upgrade script to run for as long as it needs to */ ini_set('max_execution_time', '0'); include(dirname(__FILE__) . '/../include/global.php'); @@ -39,16 +39,16 @@ include_once($config['base_path'] . '/lib/data_query.php'); include_once($config['base_path'] . '/lib/utility.php'); include_once($config['base_path'] . '/install/functions.php'); -// process calling arguments +/* process calling arguments */ $parms = $_SERVER['argv']; array_shift($parms); global $debug, $cli_upgrade, $session; -$debug = FALSE; -$cli_upgrade = TRUE; -$session = array(); -$force_version = NULL; +$debug = true; +$cli_upgrade = true; +$session = array(); +$forcever = ''; if (sizeof($parms)) { foreach($parms as $parameter) { @@ -60,141 +60,121 @@ if (sizeof($parms)) { } switch ($arg) { - case '--force_version': - $force_version = $value; + case '--forcever': + $forcever = $value; break; case '-d': case '--debug': $debug = TRUE; break; - case '--database_version': - display_database_version(); - exit; + case '--version': + case '-V': + case '-v': + display_version(); case '--help': case '-H': case '-h': display_help(); exit; default: - print "ERROR: Invalid Parameter " . $parameter . PHP_EOL . PHP_EOL; + echo "ERROR: Invalid Parameter " . $parameter . PHP_EOL . PHP_EOL; display_help(); exit; } } } -// we need to rerun the upgrade, force the current version -if (empty($force_version)) { - $old_cacti_version = db_fetch_cell('SELECT cacti FROM version'); +/* we need to rerun the upgrade, force the current version */ +if ($forcever == '') { + $old_cacti_version = get_cacti_version(); } else { - $old_cacti_version = $force_version; + $old_cacti_version = $forcever; } -$old_cacti_version = trim($old_cacti_version); -// do a version check +/* try to find current (old) version in the array */ +$old_version_index = (array_key_exists($old_cacti_version, $cacti_version_codes) ? $old_cacti_version : ''); + +/* do a version check */ if ($old_cacti_version == CACTI_VERSION) { - print "Your Cacti is already up to date." . PHP_EOL; + echo "Your Cacti is already up to date." . PHP_EOL; exit; -} -if (version_compare($old_cacti_version, '0.7', '<')) { - print 'You are attempting to install cacti ' . CACTI_VERSION . ' onto a 0.6.x database.' . PHP_EOL . "To continue, you must create a new database, import 'cacti.sql' into it," . PHP_EOL . "and\tupdate 'include/config.php' to point to the new database." . PHP_EOL; +} elseif ($old_cacti_version < 0.7) { + echo 'You are attempting to install cacti ' . CACTI_VERSION . ' onto a 0.6.x database.' . PHP_EOL . "To continue, you must create a new database, import 'cacti.sql' into it," . PHP_EOL . "and\tupdate 'include/config.php' to point to the new database." . PHP_EOL; exit; -} -if (empty($old_cacti_version)) { - print "You have created a new database, but have not yet imported the 'cacti.sql' file." . PHP_EOL; +} elseif (empty($old_cacti_version)) { + echo "You have created a new database, but have not yet imported the 'cacti.sql' file." . PHP_EOL; exit; -} -if ($old_cacti_version == 'new_install') { - print "You can not upgrade a new installation" . PHP_EOL; - exit; -} -if (! array_key_exists($old_cacti_version, $cacti_version_codes)) { - print "Invalid Cacti version $old_cacti_version, cannot upgrade to " . CACTI_VERSION . PHP_EOL; +} elseif ($old_version_index == '') { + echo "Invalid Cacti version $old_cacti_version, cannot upgrade to " . CACTI_VERSION . PHP_EOL; exit; } // loop through versions from old version to the current, performing updates for each version in the chain -foreach ($cacti_version_codes as $cacti_upgrade_version => $hash_code) { +foreach ($cacti_version_codes as $cacti_version => $hash_code) { // skip versions old than the database version - if (version_compare($old_cacti_version, $cacti_upgrade_version, '>=')) { + if (version_compare($old_cacti_version, $cacti_version, '>=')) { continue; } // construct version upgrade include path - $upgrade_file = dirname(__FILE__) . '/../install/upgrades/' . str_replace('.', '_', $cacti_upgrade_version) . '.php'; - $upgrade_function = 'upgrade_to_' . str_replace('.', '_', $cacti_upgrade_version); + $upgrade_file = dirname(__FILE__) . '/../install/upgrades/' . str_replace('.', '_', $cacti_version) . '.php'; + $upgrade_function = 'upgrade_to_' . str_replace('.', '_', $cacti_version); // check for upgrade version file, then include, check for function and execute - print 'Upgrading to ' . $cacti_upgrade_version . ' '; + echo 'Upgrading to ' . $cacti_version . ' '; if (file_exists($upgrade_file)) { include($upgrade_file); - print PHP_EOL; + echo PHP_EOL; if (function_exists($upgrade_function)) { call_user_func($upgrade_function); - print_upgrade_results($cacti_upgrade_version); + db_install_errors($cacti_version); } else { - print 'Error: upgrade function (' . $upgrade_function . ') not found' . PHP_EOL;; + echo 'Error: upgrade function (' . $upgrade_function . ') not found' . PHP_EOL;; } } else { - print "no actions" . PHP_EOL; + echo "no actions" . PHP_EOL; } - if (CACTI_VERSION == $cacti_upgrade_version) { + if (CACTI_VERSION == $cacti_version) { break; } } db_execute("UPDATE version SET cacti = '" . CACTI_VERSION . "'"); -/* - * Print upgrade results for requested version - */ -function print_upgrade_results($cacti_version) { - global $session, $debug; +function db_install_errors($cacti_version) { + global $session; - // if sessions are working for cli, use it - if (isset($_SESSION)) { - $session = $_SESSION; - } - - if (array_key_exists($cacti_version, $session['cacti_db_install_cache'])) { - foreach ($session['cacti_db_install_cache'][$cacti_version] as $action) { - if ($action['status'] == 0) { - print " DB Error: " . $action['sql'] . PHP_EOL; - } elseif ($debug) { - print " DB Success: " . $action['sql'] . PHP_EOL; + if (sizeof($session)) { + foreach ($session as $sc) { + if (isset($sc[$cacti_version])) { + foreach ($sc[$cacti_version] as $value => $sql) { + if ($value == 0) { + echo " DB Error: " . $sql . PHP_EOL; + } + } } } } } -/* - * Display database version information - */ -function display_database_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); - print 'Database Version: ' . trim($version) . PHP_EOL; +/* display_version - displays version information */ +function display_version() { + $version = get_cacti_version(); + echo "Cacti Database Upgrade Utility, Version $version, " . COPYRIGHT_YEARS . PHP_EOL; } -/* - * Display cli help - */ +/* display_help - displays the usage of the function */ function display_help () { - print 'Cacti Database Upgrade Utility, Version ' . CACTI_VERSION . ', ' . COPYRIGHT_YEARS . PHP_EOL; - print PHP_EOL; - print "usage: upgrade_database.php [--debug] [--force_version=VERSION] [--database_version]" . PHP_EOL; - print PHP_EOL; - print "--force_version - Force the starting version, say " . CACTI_VERSION . PHP_EOL; - print "--database_version - Display database version and exit" . PHP_EOL; - print "--debug - Display verbose output during execution" . PHP_EOL; - print PHP_EOL; - print PHP_EOL; - print "Command line Cacti database upgrade tool. You must execute" . PHP_EOL; - print "this command as a super user, or someone who can write a PHP session file." . PHP_EOL; - print "Typically, this user account will be apache, www-run, or root." . PHP_EOL; - print PHP_EOL; - print "If you are running a beta or alpha version of Cacti and need to rerun" . PHP_EOL; - print "the upgrade script, simply set the force_version to the previous version." . PHP_EOL; - print PHP_EOL; + display_version(); + + echo PHP_EOL . "usage: upgrade_database.php [--debug] [--forcever=VERSION]" . PHP_EOL . PHP_EOL; + echo "A command line version of the Cacti database upgrade tool. You must execute" . PHP_EOL; + echo "this command as a super user, or someone who can write a PHP session file." . PHP_EOL; + echo "Typically, this user account will be apache, www-run, or root." . PHP_EOL . PHP_EOL; + echo "If you are running a beta or alpha version of Cacti and need to rerun" . PHP_EOL; + echo "the upgrade script, simply set the forcever to the previous release." . PHP_EOL . PHP_EOL; + echo "--forcever - Force the starting version, say " . CACTI_VERSION . PHP_EOL; + echo "--debug - Display verbose output during execution" . PHP_EOL . PHP_EOL; } diff --git a/cmd.php b/cmd.php index db17ecbdf..67d89ead6 100644 --- a/cmd.php +++ b/cmd.php @@ -104,7 +104,7 @@ function open_snmp_session($host_id, &$item) { } function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Legacy Host Data Collector, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 1d030ebad..38070ec6b 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -13,6 +13,7 @@ Cacti CHANGELOG -feature: Updated Dutch language -feature: Updating PHPMailer to 5.2.23 -feature: Support input-output Data Query types +-feature: Introduce new get_cacti_version() to reduce database calls on pages 1.1.6 -issue#620: The table poller_data_template_field_mappings can get out of sync when manipulating data templates diff --git a/include/auth.php b/include/auth.php index a1a541492..5a8cf9941 100644 --- a/include/auth.php +++ b/include/auth.php @@ -27,7 +27,7 @@ global $current_user; include('./include/global.php'); if (!isset($config['cacti_db_version'])) { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); $config['cacti_db_version'] = $version; } else { $version = $config['cacti_db_version']; diff --git a/install/index.php b/install/index.php index 06b66bccf..5269f24e9 100644 --- a/install/index.php +++ b/install/index.php @@ -44,8 +44,7 @@ ini_set('max_execution_time', '0'); $cacti_versions = array_keys($cacti_version_codes); -$old_cacti_version = db_fetch_cell('SELECT cacti FROM version'); -$old_cacti_version = trim($old_cacti_version); +$old_cacti_version = get_cacti_version(); /* do a version check */ if ($old_cacti_version == CACTI_VERSION) { diff --git a/lib/functions.php b/lib/functions.php index eb1454a17..29c0707e4 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -4696,3 +4696,14 @@ function date_time_format() { return $date; } +/** get_cacti_version Generic function to get the cacti version */ +function get_cacti_version() { + static $version = ''; + + if ($version == '') { + $version = trim(db_fetch_cell('SELECT cacti FROM version LIMIT 1')); + } + + return $version; +} + diff --git a/lib/reports.php b/lib/reports.php index 8fd51f318..c3bc1e29d 100644 --- a/lib/reports.php +++ b/lib/reports.php @@ -27,7 +27,7 @@ * @param string $_title - title of the new report */ function duplicate_reports($_id, $_title) { - global $fields_reports_edit, $current_user; + global $fields_reports_edit; reports_log(__FUNCTION__ . ', id: ' . $_id, false, 'REPORTS TRACE', POLLER_VERBOSITY_MEDIUM); $report = db_fetch_row_prepared('SELECT * FROM reports WHERE id = ?', array($_id)); @@ -371,7 +371,7 @@ function generate_report($report, $force = false) { $report['bcc'] = ''; } - $v = db_fetch_cell('SELECT cacti FROM version'); + $v = get_cacti_version(); $headers['User-Agent'] = 'Cacti-Reports-v' . $v; $error = mailer( diff --git a/logout.php b/logout.php index 22b1dcacb..783bad6ed 100644 --- a/logout.php +++ b/logout.php @@ -34,7 +34,7 @@ api_plugin_hook('logout_pre_session_destroy'); setcookie(session_name(), '', time() - 3600, $config['url_path']); session_destroy(); -$version = db_fetch_cell('SELECT cacti FROM version'); +$version = get_cacti_version(); api_plugin_hook('logout_post_session_destroy'); diff --git a/permission_denied.php b/permission_denied.php index c473d31f7..bd2819f59 100644 --- a/permission_denied.php +++ b/permission_denied.php @@ -24,7 +24,7 @@ include('./include/auth.php'); -$version = db_fetch_cell('SELECT cacti FROM version'); +$version = get_cacti_version(); if (isset($_SERVER['HTTP_REFERER'])) { $goBack = "[" . __('Return') . " | " . __('Login Again') . "]"; diff --git a/poller.php b/poller.php index b1d4e7961..d65255cfa 100644 --- a/poller.php +++ b/poller.php @@ -688,7 +688,7 @@ function spikekill_poller_bottom () { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Main Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_automation.php b/poller_automation.php index 4270711f0..9bdd5c7cd 100644 --- a/poller_automation.php +++ b/poller_automation.php @@ -717,7 +717,7 @@ function discoverDevices($network_id, $thread) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); print "Cacti Network Discovery Scanner, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_boost.php b/poller_boost.php index afb048da5..731906b84 100644 --- a/poller_boost.php +++ b/poller_boost.php @@ -31,7 +31,7 @@ $no_http_headers = true; /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); print "Cacti Boost RRD Update Poller, Version $version " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_commands.php b/poller_commands.php index 16c6f8e3c..d28db4770 100644 --- a/poller_commands.php +++ b/poller_commands.php @@ -145,7 +145,7 @@ db_execute_prepared('REPLACE INTO settings (name, value) VALUES (?, ?)', /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); print "Cacti Poller Commands Poller, Version $version " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_dsstats.php b/poller_dsstats.php index 80ab6efcf..e9a73dc0e 100644 --- a/poller_dsstats.php +++ b/poller_dsstats.php @@ -31,7 +31,7 @@ $no_http_headers = true; /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Data Source Staitistcs Poller, Version $version " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_export.php b/poller_export.php index c9f84a270..aa02ca75c 100644 --- a/poller_export.php +++ b/poller_export.php @@ -90,7 +90,7 @@ graph_export($force); /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Graph Export Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_maintenance.php b/poller_maintenance.php index c34febdc1..0c22b50dd 100644 --- a/poller_maintenance.php +++ b/poller_maintenance.php @@ -485,7 +485,7 @@ function maint_debug($message) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Maintenance Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_realtime.php b/poller_realtime.php index cf8bc9dfa..b5ff1b2ce 100644 --- a/poller_realtime.php +++ b/poller_realtime.php @@ -166,7 +166,7 @@ db_close(); /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Realtime Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_recovery.php b/poller_recovery.php index cbf535d63..c18001b53 100644 --- a/poller_recovery.php +++ b/poller_recovery.php @@ -31,7 +31,7 @@ $no_http_headers = true; /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); print "Cacti Boost RRD Update Poller, Version $version " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_reports.php b/poller_reports.php index 45aab44b4..f15a44ebd 100644 --- a/poller_reports.php +++ b/poller_reports.php @@ -31,7 +31,7 @@ $no_http_headers = true; /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti Reporting Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; } diff --git a/poller_spikekill.php b/poller_spikekill.php index c5dfebf97..56c06d5d7 100644 --- a/poller_spikekill.php +++ b/poller_spikekill.php @@ -210,7 +210,7 @@ function kill_spikes($templates, &$found) { /* display_version - displays version information */ function display_version() { - $version = db_fetch_cell('SELECT cacti FROM version'); + $version = get_cacti_version(); echo "Cacti SpikeKiller Batch Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; }