'
. __('You are attempting to install Cacti %s onto a 0.6.x database. To continue, you must create a new database, import "cacti.sql" into it, and update "include/config.php" to point to the new database.', $config['cacti_version']) . '
'
. __('You have created a new database, but have not yet imported the "cacti.sql" file. At the command line, execute the following to continue:
mysql -u $database_username -p $database_default < cacti.sql
This error may also be generated if the cacti database user does not have correct permissions on the Cacti database. Please ensure that the Cacti database user has the ability to SELECT, INSERT, DELETE, UPDATE, CREATE, ALTER, DROP, INDEX on the Cacti database.') . '
';
exit;
}
function test_database_connection() {
$database_type = 'mysql';
$database_default = get_request_var('database_default');
$database_hostname = get_request_var('database_hostname');
$database_username = get_request_var('database_username');
$database_password = get_request_var('database_password');
$database_port = get_request_var('database_port');
$database_ssl = isset_request_var('database_ssl') ? true:false;
$connection = db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port, $database_ssl);
if (is_object($connection)) {
db_close($connection);
print 'Connection Sucsessful';
}else{
print 'Connection Failed';
}
}
function verify_php_extensions($extensions) {
for ($i = 0; $i < count($extensions); $i++) {
if (extension_loaded($extensions[$i]['name'])){
$extensions[$i]['installed'] = true;
}
}
return $extensions;
}
function db_install_execute($sql) {
$status = (db_execute($sql) ? 1 : 0);
db_install_add_cache ($status, $sql);
}
function db_install_add_column ($table, $column) {
// Example: db_install_add_column ('plugin_config', array('name' => 'test' . rand(1, 200), 'type' => 'varchar (255)', 'NULL' => false));
$sql = 'ALTER TABLE `' . $table . '` ADD `' . $column['name'] . '`';
if (!db_column_exists($table, $column['name'], false)) {
$status = db_add_column($table, $column, false);
} else {
$status = 2;
}
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)) {
$status = db_install_execute($sql);
} else {
db_install_add_cache (2, $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 $upgrade_version;
$sql_install_cache = (isset($_SESSION['sess_sql_install_cache']) ? $_SESSION['sess_sql_install_cache'] : array());
$sql_install_cache{sizeof($sql_install_cache)}[$upgrade_version][$status] = $sql;
$_SESSION['sess_sql_install_cache'] = $sql_install_cache;
}
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:/progra~1/php', 'c:/net-snmp/bin', 'c:/progra~1/net-snmp/bin', 'd:/usr/bin', 'd:/net-snmp/bin', 'd:/progra~1/net-snmp/bin', 'd:/cacti', 'd:/rrdtool', 'd:/spine', 'd:/php', 'd:/progra~1/php');
}else{
$search_paths = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
}
for ($i=0; $i") !== FALSE) {
$binary_signature = base64_decode(trim(str_replace(array('', ''), '', $x)));
$x = " \n";
}
$xml .= "$x";
}
fclose($f);
// Verify Signature
$ok = openssl_verify($xml, $binary_signature, $public_key);
if ($ok == 1) {
//print " File is signed correctly\n";
} elseif ($ok == 0) {
//print " ERROR: File has been tampered with\n";
//exit;
return;
} else {
//print " ERROR: Could not verify signature!\n";
//exit;
return;
}
//print "Loading Plugin Information from package\n";
$xmlget = simplexml_load_string($xml);
$data = to_array($xmlget);
$plugin = $data['info']['name'];
//print "Verifying each files signature\n";
if (isset($data['files']['file']['data'])) {
$data['files']['file'] = array($data['files']['file']);
}
foreach ($data['files']['file'] as $f) {
$binary_signature = base64_decode($f['filesignature']);
$fdata = base64_decode($f['data']);
$ok = openssl_verify($fdata, $binary_signature, $public_key);
if ($ok == 1) {
//print " File OK : " . $f['name'] . "\n";
} else {
//print " ERROR: Could not verify signature for file: " . $f['name'] . "\n";
//exit;
return;
}
}
include_once($config['base_path'] . "/lib/import.php");
$p = $config['base_path'];
$error = false;
//print "Writing Files\n";
foreach ($data['files']['file'] as $f) {
$fdata = base64_decode($f['data']);
$name = $f['name'];
if (substr($name, 0, 8) == 'scripts/' || substr($name, 0, 9) == 'resource/') {
$filename = "$p/$name";
//print " Writing $filename\n";
$file = fopen($filename,'wb');
fwrite($file ,$fdata, strlen($fdata));
fclose($file);
clearstatcache();
if (!file_exists($filename)) {
//print " Unable to create directory: $filename\n";
}
} else {
$debug_data = import_xml_data($fdata, false, 1);
}
}
//print "File creation complete\n";
}
function to_array ($data) {
if (is_object($data)) {
$data = get_object_vars($data);
}
return (is_array($data)) ? array_map(__FUNCTION__,$data) : $data;
}
/* Here, we define each name, default value, type, and path check for each value
we want the user to input. The "name" field must exist in the 'settings' table for
this to work. Cacti also uses different default values depending on what OS it is
running on. */
function install_file_paths () {
global $config, $settings;
/* RRDTool Binary Path */
$input = array();
$input['path_rrdtool'] = $settings['path']['path_rrdtool'];
if ($config['cacti_server_os'] == 'unix') {
$which_rrdtool = find_best_path('rrdtool');
if (config_value_exists('path_rrdtool')) {
$input['path_rrdtool']['default'] = read_config_option('path_rrdtool');
}else if (!empty($which_rrdtool)) {
$input['path_rrdtool']['default'] = $which_rrdtool;
}else{
$input['path_rrdtool']['default'] = '/usr/local/bin/rrdtool';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_rrdtool = find_best_path('rrdtool.exe');
if (config_value_exists('path_rrdtool')) {
$input['path_rrdtool']['default'] = read_config_option('path_rrdtool');
}else if (!empty($which_rrdtool)) {
$input['path_rrdtool']['default'] = $which_rrdtool;
}else{
$input['path_rrdtool']['default'] = 'c:/rrdtool/rrdtool.exe';
}
}
/* PHP Binary Path */
$input['path_php_binary'] = $settings['path']['path_php_binary'];
if ($config['cacti_server_os'] == 'unix') {
$which_php = find_best_path('php');
if (config_value_exists('path_php_binary')) {
$input['path_php_binary']['default'] = read_config_option('path_php_binary');
}else if (!empty($which_php)) {
$input['path_php_binary']['default'] = $which_php;
}else{
$input['path_php_binary']['default'] = '/usr/bin/php';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_php = find_best_path('php.exe');
if (config_value_exists('path_php_binary')) {
$input['path_php_binary']['default'] = read_config_option('path_php_binary');
}else if (!empty($which_php)) {
$input['path_php_binary']['default'] = $which_php;
}else{
$input['path_php_binary']['default'] = 'c:/php/php.exe';
}
}
/* snmpwalk Binary Path */
$input['path_snmpwalk'] = $settings['path']['path_snmpwalk'];
if ($config['cacti_server_os'] == 'unix') {
$which_snmpwalk = find_best_path('snmpwalk');
if (config_value_exists('path_snmpwalk')) {
$input['path_snmpwalk']['default'] = read_config_option('path_snmpwalk');
}else if (!empty($which_snmpwalk)) {
$input['path_snmpwalk']['default'] = $which_snmpwalk;
}else{
$input['path_snmpwalk']['default'] = '/usr/local/bin/snmpwalk';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_snmpwalk = find_best_path('snmpwalk.exe');
if (config_value_exists('path_snmpwalk')) {
$input['path_snmpwalk']['default'] = read_config_option('path_snmpwalk');
}else if (!empty($which_snmpwalk)) {
$input['path_snmpwalk']['default'] = $which_snmpwalk;
}else{
$input['path_snmpwalk']['default'] = 'c:/net-snmp/bin/snmpwalk.exe';
}
}
/* snmpget Binary Path */
$input['path_snmpget'] = $settings['path']['path_snmpget'];
if ($config['cacti_server_os'] == 'unix') {
$which_snmpget = find_best_path('snmpget');
if (config_value_exists('path_snmpget')) {
$input['path_snmpget']['default'] = read_config_option('path_snmpget');
}else if (!empty($which_snmpget)) {
$input['path_snmpget']['default'] = $which_snmpget;
}else{
$input['path_snmpget']['default'] = '/usr/local/bin/snmpget';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_snmpget = find_best_path('snmpget.exe');
if (config_value_exists('path_snmpget')) {
$input['path_snmpget']['default'] = read_config_option('path_snmpget');
}else if (!empty($which_snmpget)) {
$input['path_snmpget']['default'] = $which_snmpget;
}else{
$input['path_snmpget']['default'] = 'c:/net-snmp/bin/snmpget.exe';
}
}
/* snmpbulkwalk Binary Path */
$input['path_snmpbulkwalk'] = $settings['path']['path_snmpbulkwalk'];
if ($config['cacti_server_os'] == 'unix') {
$which_snmpbulkwalk = find_best_path('snmpbulkwalk');
if (config_value_exists('path_snmpbulkwalk')) {
$input['path_snmpbulkwalk']['default'] = read_config_option('path_snmpbulkwalk');
}else if (!empty($which_snmpbulkwalk)) {
$input['path_snmpbulkwalk']['default'] = $which_snmpbulkwalk;
}else{
$input['path_snmpbulkwalk']['default'] = '/usr/local/bin/snmpbulkwalk';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_snmpbulkwalk = find_best_path('snmpbulkwalk.exe');
if (config_value_exists('path_snmpbulkwalk')) {
$input['path_snmpbulkwalk']['default'] = read_config_option('path_snmpbulkwalk');
}else if (!empty($which_snmpbulkwalk)) {
$input['path_snmpbulkwalk']['default'] = $which_snmpbulkwalk;
}else{
$input['path_snmpbulkwalk']['default'] = 'c:/net-snmp/bin/snmpbulkwalk.exe';
}
}
/* snmpgetnext Binary Path */
$input['path_snmpgetnext'] = $settings['path']['path_snmpgetnext'];
if ($config['cacti_server_os'] == 'unix') {
$which_snmpgetnext = find_best_path('snmpgetnext');
if (config_value_exists('path_snmpgetnext')) {
$input['path_snmpgetnext']['default'] = read_config_option('path_snmpgetnext');
}else if (!empty($which_snmpgetnext)) {
$input['path_snmpgetnext']['default'] = $which_snmpgetnext;
}else{
$input['path_snmpgetnext']['default'] = '/usr/local/bin/snmpgetnext';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_snmpgetnext = find_best_path('snmpgetnext.exe');
if (config_value_exists('path_snmpgetnext')) {
$input['path_snmpgetnext']['default'] = read_config_option('path_snmpgetnext');
}else if (!empty($which_snmpgetnext)) {
$input['path_snmpgetnext']['default'] = $which_snmpgetnext;
}else{
$input['path_snmpgetnext']['default'] = 'c:/net-snmp/bin/snmpgetnext.exe';
}
}
/* snmptrap Binary Path */
$input['path_snmptrap'] = $settings['path']['path_snmptrap'];
if ($config['cacti_server_os'] == 'unix') {
$which_snmptrap = find_best_path('snmptrap');
if (config_value_exists('path_snmptrap')) {
$input['path_snmptrap']['default'] = read_config_option('path_snmptrap');
}else if (!empty($which_snmptrap)) {
$input['path_snmptrap']['default'] = $which_snmptrap;
}else{
$input['path_snmptrap']['default'] = '/usr/local/bin/snmptrap';
}
}elseif ($config['cacti_server_os'] == 'win32') {
$which_snmptrap = find_best_path('snmptrap.exe');
if (config_value_exists('path_snmptrap')) {
$input['path_snmptrap']['default'] = read_config_option('path_snmptrap');
}else if (!empty($which_snmptrap)) {
$input['path_snmptrap']['default'] = $which_snmptrap;
}else{
$input['path_snmptrap']['default'] = 'c:/net-snmp/bin/snmptrap.exe';
}
}
/* log file path */
$input['path_cactilog'] = $settings['path']['path_cactilog'];
$input['path_cactilog']['description'] = 'The path to your Cacti log file.';
if (config_value_exists('path_cactilog')) {
$input['path_cactilog']['default'] = read_config_option('path_cactilog');
} else {
$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\.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';
}else if (preg_match('/^RRDtool 1\.2\./', $out_array[0])) {
$input['rrdtool_version']['default'] = 'rrd-1.2.x';
}else if (preg_match('/^RRDtool 1\.0\./', $out_array[0])) {
$input['rrdtool_version']['default'] = 'rrd-1.0.x';
}
}
}
return $input;
}
/* default value for this variable */
if (!isset_request_var('install_type')) {
set_request_var('install_type', '0');
}
/* defaults for the install type dropdown */
if ($old_cacti_version == 'new_install') {
$default_install_type = '1';
}else{
$default_install_type = '3';
}
/* pre-processing that needs to be done for each step */
if (isset_request_var('step') && get_filter_request_var('step') > 0) {
$step = get_filter_request_var('step');
switch($step) {
case '1':
/* license&welcome - send to checkdependencies */
$previous_step = 0;
$step++;
break;
case '2':
$previous_step = 1;
/* checkdependencies - send to install/upgrade */
$step++;
break;
case '3':
$previous_step = 2;
if (get_filter_request_var('install_type') == '1') {
/* install - New Primary Server */
$step = 4;
}elseif (get_filter_request_var('install_type') == '2') {
/* install - New Remote Poller */
$step = 10;
}elseif (get_filter_request_var('install_type') == '3') {
/* install/upgrade - if user chooses "Upgrade" send to upgrade */
$step = 8;
}
break;
case '4':
$previous_step = 4;
/* settingscheck - send to settings-install */
$step = 5;
break;
case '5':
$previous_step = 5;
/* settings-install - send to template-import */
$step = 6;
break;
case '6':
$previous_step = 6;
/* template-import - send to installfinal */
$step = 7;
break;
case '7':
break;
case '8':
$previous_step = 8;
/* upgrade - if user upgrades send to settingscheck */
if ($old_version_index <= array_search('0.8.5a', $cacti_versions)) {
/* upgrade - if user runs old version send to upgrade-oldversion*/
$step = 9;
}else{
$step = 4;
}
break;
case '9':
$previous_step = 8;
/* upgrade-oldversion - if user upgrades from old version send to settingscheck */
$step = 4;
break;
case '10':
$previous_step = 3;
$step = 4;
break;
}
} else {
$previous_step = 0;
$step = 1;
}
/* installfinal - Install templates, change cacti version and send to login page */
if ($step == '7') {
include_once('../lib/data_query.php');
include_once('../lib/utility.php');
/* look for templates that have been checked for install */
$install = Array();
foreach ($_POST as $post => $v) {
if (substr($post, 0, 4) == 'chk_' && is_numeric(substr($post, 4))) {
$install[] = substr($post, 4);
}
}
/* install templates */
$templates = plugin_setup_get_templates(1);
if (!empty($install)) {
foreach ($install as $i) {
plugin_setup_install_template($templates[$i]['filename'], 1, $templates[$i]['interval']);
}
}
/* clear session */
setcookie(session_name(),'',time() - 3600,$config['url_path']);
kill_session_var('sess_config_array');
kill_session_var('sess_host_cache_array');
/* pre-fill poller cache with initial data on a new install only */
if ($old_cacti_version == 'new_install') {
/* just in case we have hard drive graphs to deal with */
$host_id = db_fetch_cell("SELECT id FROM host WHERE hostname='127.0.0.1'");
if (!empty($host_id)) {
run_data_query($host_id, 6);
}
/* it's always a good idea to re-populate the poller cache to make sure everything is refreshed and up-to-date */
repopulate_poller_cache();
/* fill up the snmpcache */
snmpagent_cache_rebuilt();
/* generate RSA key pair */
rsa_check_keypair();
}
/* change cacti version */
db_execute('DELETE FROM version');
db_execute("INSERT INTO version (cacti) VALUES ('" . $config["cacti_version"] . "')");
/* send to login page */
header ('Location: ../index.php');
exit;
/* upgrade */
}elseif (($step == '8') && (get_filter_request_var('install_type') == '3')) {
/* if the version is not found, die */
if (!is_int($old_version_index)) {
print "
" . __('Error') . "
"
. __('Invalid Cacti version %1$s, cannot upgrade to %2$s', $old_cacti_version, $config['cacti_version']) . "
";
exit;
}
/* loop from the old version to the current, performing updates for each version in between */
for ($i=($old_version_index+1); $iCacti Server Installation/Upgrade
include/themes/modern/main.css' type='text/css' rel='stylesheet'>
include/themes/modern/jquery.zoom.css' type='text/css' rel='stylesheet'>
include/themes/modern/jquery-ui.css' type='text/css' rel='stylesheet'>
include/themes/modern/default/style.css' type='text/css' rel='stylesheet'>
include/themes/modern/jquery.multiselect.css' type='text/css' rel='stylesheet'>
include/themes/modern/jquery.timepicker.css' type='text/css' rel='stylesheet'>
include/themes/modern/jquery.colorpicker.css' type='text/css' rel='stylesheet'>
include/themes/modern/pace.css' type='text/css' rel='stylesheet'>
include/fa/css/font-awesome.css' type='text/css' rel='stylesheet'>
images/favicon.ico' rel='shortcut icon'>
images/cacti_logo.gif' sizes='96x96'>