'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, $session; if (isset($_SESSION)) { $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; }else{ $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 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; } 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; $written = false; $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;\n"; }else{ $newfile[] = $line; } } $fp = fopen($config_file, 'w'); foreach($newfile as $line) { fwrite($fp, $line); } fclose($fp); $written = true; } } } db_close($connection); } return $written; }