'test' . rand(1, 200), 'type' => 'varchar (255)', 'NULL' => false)); $status = 1; $sql = 'ALTER TABLE `' . $table . '` ADD `' . $column['name'] . '`'; if (!db_column_exists($table, $column['name'], false)) { $status = db_add_column($table, $column, false); } elseif (!$ignore) { $status = 2; } else { $status = 1; } db_install_add_cache ($status, $sql); } function db_install_add_key ($table, $type, $key, $columns) { if (!is_array($columns)) { $columns = array($columns); } $sql = 'ALTER TABLE `' . $table . '` ADD ' . $type . ' ' . $key . '(' . implode(',', $columns) . ')'; if (db_index_exists($table, $key, false)) { $type = str_ireplace('UNIQUE ', '', $type); db_install_execute("ALTER TABLE $table DROP $type $key"); } db_install_execute($sql); } function db_install_drop_table ($table) { $sql = 'DROP TABLE `' . $table . '`'; if (db_table_exists($table, false)) { db_install_execute ($sql); } else { db_install_add_cache (2, $sql); } } function db_install_rename_table ($table, $newname) { $sql = 'RENAME TABLE `' . $table . '` TO `' . $newname . '`'; if (db_table_exists($table, false) && !db_table_exists($newname, false)) { db_install_execute ($sql); } else { db_install_add_cache (2, $sql); } } function db_install_drop_column ($table, $column) { $sql = 'ALTER TABLE `' . $table . '` DROP `' . $column . '`'; if (db_column_exists($table, $column, false)) { $status = (db_remove_column ($table, $column) ? 1 : 0); } else { $status = 2; } db_install_add_cache ($status, $sql); } function db_install_add_cache ($status, $sql) { global $cacti_upgrade_version; // add query to upgrade results array by version to the cli global session $cache_file = read_config_option('install_cache_db'); if (!empty($cache_file)) { file_put_contents($cache_file, '<[version]> ' . $cacti_upgrade_version . ' <[status]> ' . $status . ' <[sql]> ' . clean_up_lines($sql) . PHP_EOL, FILE_APPEND); } } function find_best_path($binary_name) { global $config; if ($config['cacti_server_os'] == 'win32') { $search_paths = array( 'c:/usr/bin', 'c:/cacti', 'c:/rrdtool', 'c:/spine', 'c:/php', 'c:/net-snmp/bin', 'c:/progra~1/net-snmp/bin', 'c:/progra~1/php', 'c:/progra~1/spine', 'c:/progra~1/spine/bin', 'd:/usr/bin', 'd:/cacti', 'd:/rrdtool', 'd:/spine', 'd:/php', 'd:/net-snmp/bin', 'd:/progra~1/net-snmp/bin', 'd:/progra~1/php', 'd:/progra~1/spine', 'd:/progra~1/spine/bin' ); } else { $search_paths = array( '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin', '/usr/local/spine/bin', '/usr/spine/bin' ); } for ($i=0; $i $name, 'description' => 'Path for ' . $name, 'method' => 'filepath', 'max_length' => 255, 'default' => '' ); log_install('file', "$name: Locations ($os)" . PHP_EOL . var_export($defaultPaths, true)); if (isset($settings) && isset($settings['path']) && isset($settings['path']['path_'.$name])) { $tool = $settings['path']['path_'.$name]; } $which_tool = ''; if (config_value_exists('path_'.$name)) { $which_tool = read_config_option('path_'.$name, true); log_install('file', "Using config location: $which_tool"); } if (empty($which_tool) && isset($defaultPaths[$os])) { $defaultPath = $defaultPaths[$config['cacti_server_os']]; $basename = basename($defaultPath); log_install('file', "Searching best path with location: $defaultPath"); $which_tool = find_best_path($basename); log_install('file', "Searching best path with location return: $which_tool"); } if (empty($which_tool)) { $which_tool = $defaultPath; log_install('file', "Nothing found defaulting to $defaultPath"); } $tool['default'] = $which_tool; return $tool; } function install_file_paths () { global $config, $settings; $input = array(); /* PHP Binary Path */ $input['path_php_binary'] = install_tool_path('php_binary', array( 'unix' => '/usr/bin/php', 'win32' => 'c:/php/php.exe' )); /* RRDtool Binary Path */ $input['path_rrdtool'] = install_tool_path('rrdtool', array( 'unix' => '/usr/local/bin/rrdtool', 'win32' => 'c:/rrdtool/rrdtool.exe' )); /* snmpwalk Binary Path */ $input['path_snmpwalk'] = install_tool_path('snmpwalk', array( 'unix' => '/usr/local/bin/snmpwalk', 'win32' => 'c:/net-snmp/bin/snmpwalk.exe' )); /* snmpget Binary Path */ $input['path_snmpget'] = install_tool_path('snmpget', array( 'unix' => '/usr/local/bin/snmpget', 'win32' => 'c:/net-snmp/bin/snmpget.exe' )); /* snmpbulkwalk Binary Path */ $input['path_snmpbulkwalk'] = install_tool_path('snmpbulkwalk', array( 'unix' => '/usr/local/bin/snmpbulkwalk', 'win32' => 'c:/net-snmp/bin/snmpbulkwalk.exe' )); /* snmpgetnext Binary Path */ $input['path_snmpgetnext'] = install_tool_path('snmpgetnext', array( 'unix' => '/usr/local/bin/snmpgetnext', 'win32' => 'c:/net-snmp/bin/snmpgetnext.exe' )); /* snmptrap Binary Path */ $input['path_snmptrap'] = install_tool_path('snmptrap', array( 'unix' => '/usr/local/bin/snmptrap', 'win32' => 'c:/net-snmp/bin/snmptrap.exe' )); /* spine Binary Path */ $input['path_spine'] = install_tool_path('spine', array( 'unix' => '/usr/local/spine/bin/spine', 'win32' => 'c:/spine/bin/spine.exe' )); /* log file path */ $input['path_cactilog'] = $settings['path']['path_cactilog']; if (empty($input['path_cactilog']['default'])) { $input['path_cactilog']['default'] = $config['base_path'] . '/log/cacti.log'; } /* Theme */ $input['selected_theme'] = $settings['visual']['selected_theme']; $input['selected_theme']['description'] = __('Please select one of the available Themes to skin your Cacti with.'); if (config_value_exists('selected_theme')) { $input['selected_theme']['default'] = read_config_option('selected_theme'); } else { $input['selected_theme']['default'] = 'modern'; } /* RRDtool Version */ if ((@file_exists($input['path_rrdtool']['default'])) && (($config['cacti_server_os'] == 'win32') || (is_executable($input['path_rrdtool']['default']))) ) { $input['rrdtool_version'] = $settings['general']['rrdtool_version']; $out_array = array(); exec("\"" . $input['path_rrdtool']['default'] . "\"", $out_array); if (sizeof($out_array) > 0) { if (preg_match('/^RRDtool 1\.7/', $out_array[0])) { $input['rrdtool_version']['default'] = 'rrd-1.7.x'; }else if (preg_match('/^RRDtool 1\.6/', $out_array[0])) { $input['rrdtool_version']['default'] = 'rrd-1.6.x'; }else if (preg_match('/^RRDtool 1\.5/', $out_array[0])) { $input['rrdtool_version']['default'] = 'rrd-1.5.x'; }else if (preg_match('/^RRDtool 1\.4\./', $out_array[0])) { $input['rrdtool_version']['default'] = 'rrd-1.4.x'; }else if (preg_match('/^RRDtool 1\.3\./', $out_array[0])) { $input['rrdtool_version']['default'] = 'rrd-1.3.x'; } } } return $input; } function remote_update_config_file() { global $config, $rdatabase_type, $rdatabase_hostname, $rdatabase_username, $rdatabase_password, $rdatabase_default, $rdatabase_type, $rdatabase_port, $rdatabase_ssl; global $database_type, $database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port, $database_ssl; $failure = ''; $newfile = array(); $config_file = $config['base_path'] . '/include/config.php'; $connection = db_connect_real($rdatabase_hostname, $rdatabase_username, $rdatabase_password, $rdatabase_default, $rdatabase_type, $rdatabase_port, $rdatabase_ssl); if (is_object($connection)) { if (function_exists('gethostname')) { $hostname = gethostname(); } else { $hostname = php_uname('n'); } // Check for an existing poller $poller_id = db_fetch_cell_prepared('SELECT id FROM poller WHERE hostname = ?', array($hostname), true, $connection); if (empty($poller_id)) { $save['name'] = __('New Poller'); $save['hostname'] = $hostname; $save['dbdefault'] = $database_default; $save['dbhost'] = $database_hostname; $save['dbuser'] = $database_username; $save['dbpass'] = $database_password; $save['dbport'] = $database_port; $save['dbssl'] = $database_ssl; $poller_id = sql_save($save, 'poller', 'id', true, $connection); } if (!empty($poller_id)) { if (is_writable($config_file)) { $file_array = file($config_file); if (sizeof($file_array)) { foreach($file_array as $line) { if (strpos(trim($line), "\$poller_id") !== false) { $newfile[] = "\$poller_id = $poller_id;" . PHP_EOL; } else { $newfile[] = $line; } } $fp = fopen($config_file, 'w'); foreach($newfile as $line) { fwrite($fp, $line); } fclose($fp); } else { $failure = 'Failed to read configuration file'; } } else { $failure = 'Configuration file is not writable'; } } else { $failure = 'Unable to obtain poller id for this server'; } db_close($connection); } else { $failure = 'Failed to connect database'; } return $failure; } function import_colors() { global $config; if (!file_exists(dirname(__FILE__) . '/colors.csv')) { return false; } $contents = file(dirname(__FILE__) . '/colors.csv'); if (count($contents)) { foreach($contents as $line) { $line = trim($line); $parts = explode(',',$line); $natural = $parts[0]; $hex = $parts[1]; $name = $parts[2]; $id = db_fetch_cell("SELECT hex FROM colors WHERE hex='$hex'"); if (!empty($id)) { db_execute("UPDATE colors SET name='$name', read_only='on' WHERE hex='$hex'"); } else { db_execute("INSERT INTO colors (name, hex, read_only) VALUES ('$name', '$hex', 'on')"); } } } return true; }