old_cacti_version = get_cacti_version();
$this->setRuntime(isset($install_params['Runtime']) ? $install_params['Runtime'] : 'unknown');
$step = read_config_option('install_step', true);
log_install_high('step', 'Initial: ' . clean_up_lines(var_export($step, true)));
if ($step === false || $step === null) {
$step = $this->getStepDefault();
}
if ($step == Installer::STEP_INSTALL) {
$install_version = read_config_option('install_version',true);
log_install_high('step', 'Previously complete: ' . clean_up_lines(var_export($install_version, true)));
if ($install_version === false || $install_version === null) {
$install_version = $this->old_cacti_version;
}
$install_params = array();
$install_error = read_config_option('install_error', true);
if (!empty($install_error)) {
$step = Installer::STEP_ERROR;
} elseif (cacti_version_compare(CACTI_VERSION, $install_version, '==')) {
log_install_debug('step', 'Does match: ' . clean_up_lines(var_export($this->old_cacti_version, true)));
$step = Installer::STEP_COMPLETE;
}
} else if ($step >= Installer::STEP_COMPLETE) {
$install_version = read_config_option('install_version',true);
log_install_high('step', 'Previously complete: ' . clean_up_lines(var_export($install_version, true)));
if ($install_version === false || $install_version === null) {
$install_version = CACTI_VERSION;
}
if (!cacti_version_compare($this->old_cacti_version, $install_version, '==')) {
log_install_debug('step', 'Does not match: ' . clean_up_lines(var_export($this->old_cacti_version, true)));
$step = Installer::STEP_WELCOME;
db_execute('DELETE FROM settings WHERE name LIKE \'install_%\'');
} else {
$install_params = array();
}
}
log_install_high('step', 'After: ' . clean_up_lines(var_export($step, true)));
$this->setStep($step);
$this->stepError = false;
$this->iconClass = array(
DB_STATUS_ERROR => 'fa fa-thumbs-down',
DB_STATUS_WARNING => 'fa fa-exclamation-triangle',
DB_STATUS_SUCCESS => 'fa fa-thumbs-up',
DB_STATUS_SKIPPED => 'fa fa-check-circle'
);
$this->errors = array();
$this->eula = read_config_option('install_eula', true);
$this->cronInterval = read_config_option('cron_interval', true);
$this->locales = get_installed_locales();
$this->language = read_user_setting('user_language', get_new_user_default_language(), true);
$this->stepData = null;
$this->theme = (isset($_SESSION['install_theme']) ? $_SESSION['install_theme']:read_config_option('selected_theme', true));
if ($this->theme === false || $this->theme === null) {
$this->setTheme('modern');
}
if ($step < Installer::STEP_INSTALL) {
$this->setDefaults($install_params);
}
log_install_debug('step', 'Error: ' . clean_up_lines(var_export($this->stepError, true)));
log_install_debug('step', 'Done: ' . clean_up_lines(var_export($this->stepCurrent, true)));
}
private function setDefaults($install_params = array()) {
$this->defaultAutomation = array(
array(
'name' => 'Net-SNMP Device',
'hash' => '07d3fe6a52915f99e642d22e27d967a4',
'sysDescrMatch' => 'Linux',
'sysNameMatch' => '',
'sysOidMatch' => '',
'availMethod' => 2,
'sequence' => 1
),
array(
'name' => 'Windows Device',
'hash' => '5b8300be607dce4f030b026a381b91cd',
'sysDescrMatch' => 'Windows',
'sysNameMatch' => '',
'sysOidMatch' => '',
'availMethod' => 2,
'sequence' => 2
),
array(
'name' => 'Cisco Router',
'hash' => 'cae6a879f86edacb2471055783bec6d0',
'sysDescrMatch' => '(Cisco Internetwork Operating System Software|IOS)',
'sysNameMatch' => '',
'sysOidMatch' => '',
'availMethod' => 2,
'sequence' => 3
)
);
$this->templates = $this->getTemplates();
$this->tables = $this->getTables();
$this->paths = install_file_paths();
$this->permissions = $this->getPermissions();
$this->modules = $this->getModules();
$this->setProfile($this->getProfile());
$this->setAutomationMode($this->getAutomationMode());
$this->setAutomationOverride($this->getAutomationOverride());
$this->setAutomationRange($this->getAutomationRange());
$this->setPaths($this->getPaths());
$this->setRRDVersion($this->getRRDVersion(), 'default ');
$this->snmpOptions = $this->getSnmpOptions();
$this->setMode($this->getMode());
log_install_high('','Installer::processParameters(' . clean_up_lines(json_encode($install_params)) . ')');
if (!empty($install_params)) {
$this->processParameters($install_params);
}
if ($this->stepError !== false && $this->stepCurrent > $this->stepError) {
$this->setStep($this->stepError);
}
}
protected function processParameters($params_install = array()) {
if (empty($params_install) || !is_array($params_install)) {
$params_install = array();
}
// Always set the current step first
if (isset($params_install['Step'])) {
$this->setStep($params_install['Step']);
unset($params_install['Step']);
}
foreach ($params_install as $key => $value) {
switch ($key) {
case 'Mode':
$this->setMode($value);
break;
case 'Eula':
$this->setEula($value);
break;
case 'Prev':
$this->buttonPrevious = new InstallerButton($value);
break;
case 'Next':
$this->buttonNext = new InstallerButton($value);
break;
case 'Test':
$this->buttonTest = new InstallerButton($value);
break;
case 'Language':
$this->setLanguage($value);
break;
case 'Profile':
$this->setProfile($value);
break;
case 'CronInterval':
$this->setCronInterval($value);
break;
case 'AutomationMode':
$this->setAutomationMode($value);
break;
case 'AutomationOverride':
$this->setAutomationOverride($value);
break;
case 'AutomationRange':
$this->setAutomationRange($value);
break;
case 'Templates':
$this->setTemplates($value);
break;
case 'Tables':
$this->setTables($value);
break;
case 'Paths':
$this->setPaths($value);
break;
case 'RRDVersion':
$this->setRRDVersion($value);
break;
case 'Theme':
$this->setTheme($value);
break;
case 'SnmpOptions':
$this->setSnmpOptions($value);
break;
case 'Runtime':
break;
default:
log_install_always('badkey',"$key => $value");
}
}
}
public function jsonSerialize() {
if (empty($this->output)) {
$this->output = $this->processCurrentStep();
}
$basics = array(
'Mode' => $this->mode,
'Step' => $this->stepCurrent,
'Errors' => $this->errors
);
$webdata = array();
/* Are we running in either Web or Json mode? */
if ($this->runtime == 'Web' || $this->runtime == 'Json') {
$webdata += array(
'Eula' => $this->eula,
'Prev' => $this->buttonPrevious,
'Next' => $this->buttonNext,
'Test' => $this->buttonTest,
'Theme' => $this->theme,
'StepData' => $this->stepData,
);
}
/* Are we running in only Web mode? */
if ($this->runtime == 'Web') {
$webdata += array(
'Html' => $this->output,
);
}
return array_merge($basics, $webdata);
}
public function getData() {
return $this->jsonSerialize();
}
public function getErrors() {
return (isset($this->errors) && !empty($this->errors)) ? $this->errors : array();
}
function setTrueFalse($param, &$field, $option) {
$value = null;
if ($param === true || $param === 'true' || $param === 'on' || $param === 1 || $param === '1') {
$value = true;
} else if ($param === false || $param === 'false' || $param === '' || $param === 0 || $param === '0') {
$value = false;
}
if ($value !== null) {
set_config_option('install_' . $option, $param);
$field = $value;
}
$result = $value !== null;
log_install_medium('', "setTrueFalse($option, " . var_export($param, true) . " sets $value, returns $result");
return $result;
}
public function addError($step, $section, $item, $text = false) {
if (!isset($this->errors[$section])) {
$this->errors[$section] = array();
}
if ($text === false) {
$this->errors[$section][] = $item;
log_install_medium('errors',"addError($section, $item)");
} else {
$this->errors[$section][$item] = $text;
log_install_medium('errors',"addError($section, $item, $text)");
}
log_install_debug('errors','stepError = ' . $step . ' -> ' . clean_up_lines(var_export($this->stepError, true)));
if ($this->stepError === false || $this->stepError > $step) {
$this->stepError = $step;
}
log_install_debug('errors-json', clean_up_lines(var_export($this->errors, true)));
}
private function setProgress($param_process) {
log_install_always('', "Progress: $param_process");
set_config_option('install_progress', $param_process);
set_config_option('install_updated', microtime(true));
}
public function setRuntime($param_runtime = 'unknown') {
if ($param_runtime == 'Web' || $param_runtime == 'Cli' || $param_runtime == 'Json') {
$this->runtime = $param_runtime;
} else {
$this->addError(Installer::STEP_WELCOME, '', 'Failed to apply specified runtime');
}
}
private function setLanguage($param_language = '') {
if (isset($param_language) && strlen($param_language)) {
$language = apply_locale($param_language);
if (empty($language)) {
$this->addError(Installer::STEP_WELCOME, 'Language', 'Failed to apply specified language');
} else {
$this->language = $param_language;
set_user_setting('user_language', $param_language);
}
}
}
private function setEula($param_eula = '') {
if ($param_eula == 'Accepted' || $param_eula === 'true') {
$param_eula = 1;
} else if (!is_numeric($param_eula)) {
$param_eula = 0;
}
$this->eula = ($param_eula > 0);
if (!$this->eula) {
$this->addError(Installer::STEP_WELCOME, 'Eula','Eula not accepted');
}
set_config_option('install_eula', $this->eula);
}
private function sanitizeRRDVersion($param_rrdver, $default_version = '') {
$rrdver = $default_version;
if (isset($param_rrdver) && strlen($param_rrdver)) {
log_install_debug('rrdversion', 'sanitizeRRDVersion() - Checking for version string');
if (preg_match("/(?:version|v)*\s*((?:[0-9]+\.?)+)/i", $param_rrdver, $matches)) {
log_install_debug('rrdversion', 'sanitizeRRDVersion() - Checking for version string - ' . (cacti_sizeof($matches) - 1) . ' matches found');
if (cacti_sizeof($matches) > 1) {
log_install_debug('rrdversion', 'sanitizeRRDVersion() - Comparing ' . $param_rrdver . ' <= 1.3');
if (cacti_version_compare('1.3', $matches[1], '<=')) {
$rrdver = $matches[1];
log_install_debug('rrdversion', 'sanitizeRRDVersion() - Valid version');
}
}
}
} else if (!empty($default_version)) {
$rrdver = $this->sanitizeRRDVersion($default_version,'1.3');
}
log_install_medium('rrdversion', 'sanitizeRRDVersion() - returning ' . $rrdver);
return $rrdver;
}
private function getRRDVersion() {
$rrdver = read_config_option('install_rrdtool_vrsion');
if (empty($rrdver)) {
log_install_high('rrdversion', 'getRRDVersion(): Getting tool version');
$rrdver = get_rrdtool_version();
if (empty($rrdver)) {
log_install_high('rrdversion', 'getRRDVersion(): Getting installed tool version');
$rrdver = get_installed_rrdtool_version();
}
}
log_install_medium('rrdversion', 'getRRDVersion(): ' . $rrdver);
return $rrdver;
}
private function setRRDVersion($param_rrdver = '', $prefix = '') {
global $config;
if (isset($param_rrdver) && strlen($param_rrdver)) {
$rrdver = $this->sanitizeRRDVersion($param_rrdver,'');
if (empty($rrdver)) {
$this->addError(Installer::STEP_BINARY_LOCATIONS, 'RRDVersion', 'setRRDVersion()', __('Failed to set specified %sRRDTool version: %s', $prefix, $param_rrdver));
} else {
$this->paths['rrdtool_version']['default'] = $param_rrdver;
set_config_option('install_rrdtool_version', $param_rrdver);
set_config_option('rrdtool_version', $param_rrdver);
}
}
}
private function setTheme($param_theme = '') {
global $config;
if (isset($param_theme) && strlen($param_theme)) {
log_install_medium('theme','Checking theme: ' . $param_theme);
$themePath = $config['base_path'] . '/include/themes/' . $param_theme . '/main.css';
if (file_exists($themePath)) {
log_install_debug('theme','Setting theme: ' . $param_theme);
$this->theme = $param_theme;
set_config_option('selected_theme', $this->theme);
} else {
$this->addError(Installer::STEP_WELCOME, 'Theme', __('Invalid Theme Specified'));
}
}
}
private function getPermissions() {
global $config;
$permissions = array('install' => array(), 'always' => array());
$install_paths = array(
$config['base_path'] . '/resource/snmp_queries',
$config['base_path'] . '/resource/script_server',
$config['base_path'] . '/resource/script_queries',
$config['base_path'] . '/scripts',
);
$always_paths = array(
sys_get_temp_dir(),
$config['base_path'] . '/log',
$config['base_path'] . '/cache/boost',
$config['base_path'] . '/cache/mibcache',
$config['base_path'] . '/cache/realtime',
$config['base_path'] . '/cache/spikekill'
);
$install_key = 'always';
if ($this->mode != Installer::MODE_POLLER) {
$install_key = 'install';
}
foreach ($install_paths as $path) {
$valid = (is_resource_writable($path . '/'));
$permissions[$install_key][$path . '/'] = $valid;
log_install_debug('permission',"$path = $valid ($install_key)");
if (!$valid) {
$this->addError(Installer::STEP_PERMISSION_CHECK, 'Permission', $path, __('Path was not writable'));
}
}
foreach ($always_paths as $path) {
$valid = (is_resource_writable($path . '/'));
$permissions['always'][$path . '/'] = $valid;
log_install_debug('permission',"$path = $valid");
if (!$valid) {
$this->addError(Installer::STEP_PERMISSION_CHECK, 'Permission', $path, __('Path is not writable'));
}
}
return $permissions;
}
public function getPaths() {
$paths = array();
foreach ($this->paths as $name => $array) {
if (substr($name, 0, 5) == 'path_' || $name == "settings_sendmail_path") {
if (array_key_exists('default', $array)) {
$paths[$name] = $array['default'];
} else {
$paths[$name] = read_config_option($name);
}
}
}
return $paths;
}
private function setPaths($param_paths = array()) {
global $config;
log_install_debug('paths', "setPaths(): BACKTRACE: " . cacti_debug_backtrace('', false, false));
if (is_array($param_paths)) {
log_install_debug('paths', 'setPaths(' . $this->stepCurrent . ', ' . cacti_count($param_paths) . ')');
/* get all items on the form and write values for them */
foreach ($param_paths as $name => $path) {
$key_exists = array_key_exists($name, $this->paths);
$check = isset($this->paths[$name]['install_check']) ? $this->paths[$name]['install_check'] : 'file_exists';
$optional = isset($this->paths[$name]['install_optional']) ? $this->paths[$name]['install_optional'] : false;
log_install_high('paths', sprintf('setPaths(): name: %-25s, key_exists: %-5s, optional: %-5s, check: %s, path: %s', $name, $key_exists, $optional, $check, $path));
if ($key_exists) {
$should_set = true;
if ($check == 'writable') {
$should_set = is_resource_writable(dirname($path) . '/') || $optional;
if ($should_set) {
$should_set = is_resource_writable($path) || $optional;
}
if (!$should_set && !$optional) {
$this->addError(Installer::STEP_BINARY_LOCATIONS, 'Paths', $name, __('Resource is not writable'));
}
} else if ($check == 'file_exists') {
$should_set = file_exists($path) || $optional;
if (!$should_set) {
$this->addError(Installer::STEP_BINARY_LOCATIONS, 'Paths', $name, __('File not found'));
}
}
if ($should_set && $name == 'path_php_binary') {
$input = mt_rand(2,64);
$output = shell_exec(
$path . ' -q ' . $config['base_path'] .
'/install/cli_test.php ' . $input);
if ($output != $input * $input) {
$this->addError(Installer::STEP_BINARY_LOCATIONS, 'Paths', $name, __('PHP did not return expected result'));
$should_set = false;
}
}
if ($should_set) {
unset($this->errors['Paths'][$name]);
set_config_option($name, empty($path)?'':$path);
}
$this->paths[$name]['default'] = $path;
log_install_debug('paths', sprintf('setPaths(): name: %-25s, key_exists: %-5s, optional: %-5s, should_set: %3s, check: %s', $name, $key_exists, $optional, $should_set?'Yes':'No',$check));
log_install_debug('paths', sprintf('setPaths(): name: %-25s, data: %s', $name, clean_up_lines(var_export($this->paths[$name], true))));
} else {
$this->addError(Installer::STEP_BINARY_LOCATIONS, 'Paths', $name, __('Unexpected path parameter'));
}
}
}
}
private function getProfile() {
$db_profile = read_config_option('install_profile', true);
if (empty($db_profile)) {
$db_profile = db_fetch_cell('SELECT id FROM data_source_profiles WHERE `default` = \'on\' LIMIT 1');
if ($db_profile === false) {
$db_profile = db_fetch_cell('SELECT id FROM data_source_profiles ORDER BY id LIMIT 1');
}
}
log_install_medium('automation', 'getProfile() returns with ' . $db_profile);
return $db_profile;
}
private function setProfile($param_profile = null) {
if (!empty($param_profile)) {
$valid = db_fetch_cell_prepared('SELECT id FROM data_source_profiles WHERE id = ?', array($param_profile));
if ($valid === false || $valid != $param_profile) {
$this->addError(Installer::STEP_PROFILE_AND_AUTOMATION, 'Profile', __('Failed to apply specified profile %s != %s', $valid, $param_profile));
} else {
$this->profile = $valid;
set_config_option('install_profile', $valid);
}
}
log_install_medium('automation',"setProfile($param_profile) returns with $this->profile");
}
private function setAutomationMode($param_mode = null) {
if ($param_mode != null) {
if (!$this->setTrueFalse($param_mode, $this->automationMode, 'automation_mode')) {
$this->addError(Installer::STEP_PROFILE_AND_AUTOMATION, 'Automation','Mode', __('Failed to apply specified mode: %s', $param_mode));
}
}
log_install_medium('automation',"setAutomationMode($param_mode) returns with $this->automationMode");
}
private function setAutomationOverride($param_override = null) {
if ($param_override != null) {
if (!$this->setTrueFalse($param_override, $this->automationOverride, 'automation_override')) {
$this->addError(Installer::STEP_PROFILE_AND_AUTOMATION, 'Automation','Override', __('Failed to apply specified automation override: %s', $param_override));
}
}
log_install_medium('automation',"setAutomationOverride($param_override) returns with $this->automationOverride");
}
private function setCronInterval($param_mode = null) {
global $cron_intervals;
if ($param_mode != null) {
if (array_key_exists($param_mode, $cron_intervals)) {
$this->cronInterval = $param_mode;
set_config_option('cron_interval', $param_mode);
} else {
$this->addError(Installer::STEP_PROFILE_AND_AUTOMATION, 'Poller','Cron', __('Failed to apply specified cron interval'));
}
}
log_install_medium('automation',"setCronInterval($param_mode) returns with $this->cronInterval");
}
public function getAutomationRange() {
$range = read_config_option('install_automation_range', true);
if (empty($range)) {
$row = db_fetch_row('SELECT id, subnet_range FROM automation_networks LIMIT 1');
$enabled = 0;
$network = '';
log_install_debug('automation', "getAutomationRange(): found '" . clean_up_lines(var_export($row, true)));
if (!empty($row)) {
$range = $row['subnet_range'];
}
}
$result = empty($range) ? '192.168.0.1/24' : $range;
log_install_medium('automation',"getAutomationRange() returns '$result'");
return $result;
}
private function setAutomationRange($param_range = null) {
if (!empty($param_range)) {
$ip_details = cacti_pton($param_range);
if ($ip_details === false) {
$this->addError(Installer::STEP_PROFILE_AND_AUTOMATION, 'Automation', 'Range', __('Failed to apply specified Automation Range'));
} else {
$this->automationRange = $param_range;
set_config_option('install_automation_range', $param_range);
}
}
log_install_medium('automation',"setAutomationRange($param_range) returns with $this->automationRange");
}
private function getSnmpOptions() {
global $fields_snmp_item_with_retry;
$db_snmp_options = db_fetch_assoc('SELECT name, value FROM settings where name like \'install_snmp_option_%\'');
$options = array();
foreach ($db_snmp_options as $row) {
$key = str_replace('install_snmp_option_', '', $row['name']);
$options[$key] = $row['value'];
}
log_install_debug('snmp_options','Option array: ' . clean_up_lines(var_export($options, true)));
return $options;
}
private function setSnmpOptions($param_snmp_options = array()) {
global $fields_snmp_item_with_retry;
$known_snmp_options = $fields_snmp_item_with_retry;
if (is_array($param_snmp_options)) {
db_execute('DELETE FROM settings WHERE name like \'install_snmp_option_%\'');
log_install_medium('snmp_options',"Updating snmp_options");
log_install_debug('snmp_options',"Parameter data:" . clean_up_lines(var_export($param_snmp_options, true)));
$known_map = array(
'SnmpVersion' => 'snmp_version' ,
'SnmpCommunity' => 'snmp_community' ,
'SnmpSecurityLevel' => 'snmp_security_level' ,
'SnmpUsername' => 'snmp_username' ,
'SnmpAuthProtocol' => 'snmp_auth_protocol' ,
'SnmpPassword' => 'snmp_password' ,
'SnmpPrivProtocol' => 'snmp_priv_protocol' ,
'SnmpPrivPassphrase' => 'snmp_priv_passphrase' ,
'SnmpContext' => 'snmp_context' ,
'SnmpEngineId' => 'snmp_engine_id' ,
'SnmpPort' => 'snmp_port' ,
'SnmpTimeout' => 'snmp_timeout' ,
'SnmpMaxOids' => 'max_oids' ,
'SnmpRetries' => 'snmp_retries' ,
);
foreach ($param_snmp_options as $option_name => $option_value) {
log_install_high('snmp_options',"snmp_option: ". clean_up_lines(var_export($option_name, true)));
$bad_option = true;
if (array_key_exists($option_name, $known_map)) {
$key = $known_map[$option_name];
log_install_debug('snmp_options',"snmp_option found:" . clean_up_lines(var_export($key, true)));
if (array_key_exists($key, $known_snmp_options)) {
$bad_option = false;
log_install_high('snmp_options',"snmp_option set:" . clean_up_lines(var_export($option_value, true)));
log_install_debug('snmp_options',"Set snmp_option: install_snmp_option_$key = $option_value");
set_config_option("install_snmp_option_$key", $option_value);
}
}
if ($bad_option) {
$this->addError(Installer::STEP_TEMPLATE_INSTALL, 'SnmpOptions', $option_name, __('No matching snmp option exists'));
}
}
}
}
private function getModules() {
global $config;
if ($config['cacti_server_os'] == 'unix') {
$extensions = array(
array('name' => 'ctype', 'installed' => false),
array('name' => 'date', 'installed' => false),
array('name' => 'filter', 'installed' => false),
array('name' => 'gettext', 'installed' => false),
array('name' => 'gd', 'installed' => false),
array('name' => 'gmp', 'installed' => false),
array('name' => 'hash', 'installed' => false),
array('name' => 'json', 'installed' => false),
array('name' => 'ldap', 'installed' => false),
array('name' => 'mbstring', 'installed' => false),
array('name' => 'openssl', 'installed' => false),
array('name' => 'pcre', 'installed' => false),
array('name' => 'PDO', 'installed' => false),
array('name' => 'pdo_mysql', 'installed' => false),
array('name' => 'posix', 'installed' => false),
array('name' => 'session', 'installed' => false),
array('name' => 'simplexml', 'installed' => false),
array('name' => 'sockets', 'installed' => false),
array('name' => 'spl', 'installed' => false),
array('name' => 'standard', 'installed' => false),
array('name' => 'xml', 'installed' => false),
array('name' => 'zlib', 'installed' => false)
);
} elseif (version_compare(PHP_VERSION, '5.4.5') < 0) {
$extensions = array(
array('name' => 'ctype', 'installed' => false),
array('name' => 'date', 'installed' => false),
array('name' => 'filter', 'installed' => false),
array('name' => 'gettext', 'installed' => false),
array('name' => 'gd', 'installed' => false),
array('name' => 'gmp', 'installed' => false),
array('name' => 'hash', 'installed' => false),
array('name' => 'json', 'installed' => false),
array('name' => 'ldap', 'installed' => false),
array('name' => 'mbstring', 'installed' => false),
array('name' => 'openssl', 'installed' => false),
array('name' => 'pcre', 'installed' => false),
array('name' => 'PDO', 'installed' => false),
array('name' => 'pdo_mysql', 'installed' => false),
array('name' => 'session', 'installed' => false),
array('name' => 'simplexml', 'installed' => false),
array('name' => 'sockets', 'installed' => false),
array('name' => 'spl', 'installed' => false),
array('name' => 'standard', 'installed' => false),
array('name' => 'xml', 'installed' => false),
array('name' => 'zlib', 'installed' => false)
);
} else {
$extensions = array(
array('name' => 'com_dotnet','installed' => false),
array('name' => 'ctype', 'installed' => false),
array('name' => 'date', 'installed' => false),
array('name' => 'filter', 'installed' => false),
array('name' => 'gettext', 'installed' => false),
array('name' => 'gd', 'installed' => false),
array('name' => 'gmp', 'installed' => false),
array('name' => 'hash', 'installed' => false),
array('name' => 'json', 'installed' => false),
array('name' => 'mbstring', 'installed' => false),
array('name' => 'openssl', 'installed' => false),
array('name' => 'pcre', 'installed' => false),
array('name' => 'PDO', 'installed' => false),
array('name' => 'pdo_mysql', 'installed' => false),
array('name' => 'ldap', 'installed' => false),
array('name' => 'session', 'installed' => false),
array('name' => 'simplexml', 'installed' => false),
array('name' => 'sockets', 'installed' => false),
array('name' => 'spl', 'installed' => false),
array('name' => 'standard', 'installed' => false),
array('name' => 'xml', 'installed' => false),
array('name' => 'zlib', 'installed' => false)
);
}
$ext = verify_php_extensions($extensions);
foreach ($ext as $e) {
if (!$e['installed']) {
$this->addError(Installer::STEP_CHECK_DEPENDENCIES, 'Modules', $e['name'] . ' is missing');
}
}
return $ext;
}
private function getTemplates() {
$known_templates = install_setup_get_templates();
$db_templates = array_rekey(
db_fetch_assoc('SELECT name, value FROM settings where name like \'install_template_%\''),
'name', 'value');
$hasTemplates = read_config_option('install_has_templates', true);
$selected = array();
$select_count = 0;
log_install_debug('templates','getTemplates(): First: ' . (empty($hasTemplates) ? 'Yes' : 'No') . ', Templates - ' . clean_up_lines(var_export($known_templates, true)));
log_install_debug('templates','getTemplates(): DB: ' . clean_up_lines(var_export($db_templates, true)));
foreach ($known_templates as $known) {
$filename = $known['filename'];
$key_base = str_replace(".", "_", $filename);
$key_install = 'install_template_' . $key_base;
$key_check = 'chk_template_' . $key_base;
log_install_high('templates','getTemplates(): Checking template ' . $known['name'] . ' using base: ' . $key_base);
log_install_debug('templates','getTemplates(): Checking template ' . $known['name'] . ' using key.: ' . $key_install);
log_install_debug('templates','getTemplates(): Checking template ' . $known['name'] . ' filename..: ' . $filename);
$value = '';
if (array_key_exists($key_install, $db_templates)) {
$value = $db_templates[$key_install];
}
log_install_debug('templates','getTemplates(): Checking template ' . $known['name'] . ' against...: ' . $value);
$isSelected = !empty($hasTemplates) && ($value == $filename);
$selected[$key_check] = $isSelected;
if ($isSelected) {
$select_count++;
}
}
$selected['all'] = ($select_count == cacti_count($selected) || empty($hasTemplates));
log_install_high('templates', 'getTemplates(): Returning with ' . clean_up_lines(var_export($selected, true)));
return $selected;
}
private function setTemplates($param_templates = array()) {
if (is_array($param_templates)) {
db_execute('DELETE FROM settings WHERE name like \'install_template_%\'');
$known_templates = install_setup_get_templates();
log_install_medium('templates',"setTemplates(): Updating templates");
log_install_debug('templates',"setTemplates(): Parameter data:" . clean_up_lines(var_export($param_templates, true)));
log_install_debug('templates',"setTemplates(): Template data:" . clean_up_lines(var_export($known_templates, true)));
foreach ($param_templates as $name => $enabled) {
$template = false;
log_install_high('templates','setTemplates(): ' . $name . ' => ' . ($enabled ? 'true' : 'false'));
foreach ($known_templates as $known) {
$filename = $known['filename'];
$key = 'chk_template_' . str_replace(".", "_", $filename);
if ($name == $key || $name == $filename) {
$template = $known;
break;
}
}
if ($template === false) {
$this->addError(Installer::STEP_TEMPLATE_INSTALL, 'Templates', $name, __('No matching template exists'));
} else {
$key = str_replace(".", "_", $template['filename']);
$value = ($enabled ? $template['filename'] : '');
log_install_high('templates',"setTemplates(): Using key: install_template_$key = " . $value);
if ($enabled) {
set_config_option("install_template_$key", $value);
}
}
}
set_config_option('install_has_templates', true);
}
}
private function getTables() {
$known_tables = install_setup_get_tables();
$db_tables = array_rekey(
db_fetch_assoc('SELECT name, value FROM settings where name like \'install_table_%\''),
'name', 'value');
$hasTables = read_config_option('install_has_tables', true);
$selected = array();
$select_count = 0;
foreach ($known_tables as $known) {
$table = $known['Name'];
$key = $known['Name'];
$option = '';
if (array_key_exists('install_table_' . $key, $db_tables)) {
$option = $db_tables['install_table_' . $key];
}
$isSelected = !empty($hasTables) && (!empty($option));
$selected['chk_table_' . $key] = $isSelected;
if ($isSelected) {
$select_count++;
}
}
$selected['all'] = ($select_count == cacti_count($selected) || empty($hasTables));
return $selected;
}
private function setTables($param_tables = array()) {
if (is_array($param_tables)) {
db_execute('DELETE FROM settings WHERE name like \'install_table_%\'');
$known_tables = install_setup_get_tables();
log_install_medium('tables',"setTables(): Updating Tables");
log_install_debug('tables',"setTables(): Parameter data:" . clean_up_lines(var_export($param_tables, true)));
foreach ($known_tables as $known) {
$name = $known['Name'];
$key = 'chk_table_' . $name;
log_install_high('tables',"setTables(): Checking table '$name' against key $key ...");
log_install_debug('tables',"setTables(): Table: ". clean_up_lines(var_export($known, true)));
if (!empty($param_tables[$key]) || !empty($param_tables["all"])) {
$table = $param_tables[$key];
log_install_high('tables',"setTables(): install_table_$name = $name");
set_config_option("install_table_$name", $name);
}
}
set_config_option('install_has_tables', true);
}
}
public function getMode() {
if (isset($this->mode)) {
$mode = $this->mode;
} else {
$mode = Installer::MODE_INSTALL;
if ($this->old_cacti_version != 'new_install') {
if (cacti_version_compare($this->old_cacti_version, CACTI_VERSION, '=')) {
$equal = '=';
$mode = Installer::MODE_NONE;
} else if (cacti_version_compare($this->old_cacti_version, CACTI_VERSION, '<')) {
$equal = '<';
$mode = Installer::MODE_UPGRADE;
} else {
$equal = '>=';
$mode = Installer::MODE_DOWNGRADE;
}
log_install_high('mode','getMode(): Version Mode - ' . clean_up_lines(var_export($this->old_cacti_version, true))
. $equal . clean_up_lines(var_export(CACTI_VERSION, true)));
} elseif ($this->hasRemoteDatabaseInfo()) {
$mode = Installer::MODE_POLLER;
}
if ($mode == Installer::MODE_POLLER || $mode == Installer::MODE_INSTALL) {
$db_mode = read_config_option('install_mode', true);
log_install_high('mode','getMode(): DB Install mode ' . clean_up_lines(var_export($db_mode, true)));
if ($db_mode !== false) {
$mode = $db_mode;
}
}
}
log_install_high('mode','getMode(): ' . clean_up_lines(var_export($mode, true)));
return $mode;
}
private function setMode($param_mode = 0) {
if (intval($param_mode) > Installer::MODE_NONE && intval($param_mode) <= Installer::MODE_DOWNGRADE) {
log_install_high('mode','setMode(' . $param_mode . ')');
set_config_option('install_mode', $param_mode);
$this->mode = $param_mode;
$this->updateButtons();
} else if ($param_mode != 0) {
$this->addError(Installer::STEP_INSTALL_TYPE, 'mode', 'Failed to apply mode: ' . $param_mode);
}
}
private function getStepDefault() {
$mode = $this->getMode();
$step = $mode == Installer::MODE_NONE ? Installer::STEP_COMPLETE : Installer::STEP_WELCOME;
log_install_medium('step', "getStepDefault(): Resetting to $step as not found ($mode)");
return $step;
}
public function getStep() {
return $this->stepCurrent;
}
private function setStep($param_step = -1) {
$step = Installer::STEP_WELCOME;
if (empty($param_step)) {
$param_step = 1;
}
if (intval($param_step) > Installer::STEP_NONE && intval($param_step) <= Installer::STEP_ERROR) {
if ($param_step == Installer::STEP_WELCOME || $step <= Installer::STEP_INSTALL_CONFIRM || $step < $param_step) {
$step = $param_step;
}
}
if ($step == Installer::STEP_NONE) {
$step == Installer::STEP_WELCOME;
}
log_install_debug('step', 'setStep(): ' . var_export($step, true));
log_install_debug('step', "setStep():" . cacti_debug_backtrace('', false, false, 1));
// Make current step the first if it is unknown
log_install_high('step', 'setStep(): stepError ' . clean_up_lines(var_export($this->stepError, true)) . ' < ' . clean_up_lines(var_export($step, true)));
if ($this->stepError !== false && $this->stepError < $step) {
$step = $this->stepError;
}
$this->stepCurrent = ($step == Installer::STEP_NONE ? Installer::STEP_WELCOME : $step);
$this->stepPrevious = Installer::STEP_NONE;
$this->stepNext = Installer::STEP_NONE;
if ($step <= Installer::STEP_COMPLETE) {
$this->stepNext = ($step >= Installer::STEP_COMPLETE ? Installer::STEP_NONE : $step + 1);
if ($step >= Installer::STEP_WELCOME) {
$this->stepPrevious = ($step <= Installer::STEP_WELCOME ? Installer::STEP_NONE : $step - 1);
}
}
set_config_option('install_step', $this->stepCurrent);
$this->updateButtons();
set_config_option('install_prev', $this->stepPrevious);
set_config_option('install_next', $this->stepNext);
}
public function shouldRedirectToHome() {
return ($this->old_cacti_version == CACTI_VERSION);
}
public function shouldExitWithReason() {
if ($this->isDatabaseEmpty()) {
return Installer::EXIT_DB_EMPTY;
} elseif ($this->isDatabaseTooOld()) {
return Installer::EXIT_DB_OLD;
}
return false;
}
public function isDatabaseEmpty() {
return empty($this->old_cacti_version);
}
public function isDatabaseTooOld() {
return preg_match('/^0\.6/', $this->old_cacti_version);
}
public function isNewInstall() {
return ($this->old_cacti_version == 'new_install');
}
public function isPre_v0_8_UpgradeNeeded() {
return version_compare($this->old_cacti_version, '0.8.5a', '<=');
}
public function hasRemoteDatabaseInfo() {
global $rdatabase_default;
return !empty($rdatabase_default);
}
public function isConfigurationWritable() {
global $config;
return is_resource_writable($config['base_path'] . '/include/config.php');
}
public function isRemoteDatabaseGood() {
global $rdatabase_default, $rdatabase_username, $rdatabase_hostname, $rdatabase_port;
return (isset($rdatabase_default) &&
isset($rdatabase_username) &&
isset($rdatabase_hostname) &&
isset($rdatabase_port)) ? true : false;
}
public function exitWithReason($reason) {
global $config;
switch ($reason) {
case Installer::EXIT_DB_EMPTY:
return $this->exitSqlNeeded();
case Installer::EXIT_DB_OLD:
return $this->exitDbTooOld();
default:
return $this->exitWithUnknownReason($reason);
}
}
private function exitWithUnknownReason($reason) {
$output = Installer::sectionTitleError();
$output .= Installer::sectionNormal(__('An unexpected reason was given for preventing this maintenance session.'));
$output .= Installer::sectionNormal(__('Please report this to the Cacti Group.'));
$output .= Installer::sectionCode(__('Unknown Reason: %s', $reason));
return $output;
}
private function exitDbTooOld() {
$output = Installer::sectionTitleError();
$output .= Installer::sectionNormal(__('You are attempting to install Cacti %s onto a 0.6.x database. Unfortunately, this can not be performed.', CACTI_VERSION));
$output .= Installer::sectionNormal(__('To be able continue, you MUST create a new database, import "cacti.sql" into it:', CACTI_VERSION));
$output .= Installer::sectionCode(__("mysql -u %s -p [new_database] < cacti.sql", $database_username, $database_default));
$output .= Installer::sectionNormal(__('You MUST then update "include/config.php" to point to the new database.'));
$output .= Installer::sectionNormal(__('NOTE: Your existing data will not be modified, nor will it or any history be available to the new install'));
return $output;
}
private function exitSqlNeeded() {
global $config, $database_username, $database_default, $database_password;
$output = Installer::sectionTitleError();
$output .= Installer::sectionNormal(__("You have created a new database, but have not yet imported the 'cacti.sql' file. At the command line, execute the following to continue:"));
$output .= Installer::sectionCode(__("mysql -u %s -p %s < cacti.sql", $database_username, $database_default));
$output .= Installer::sectionNormal(__("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."));
$output .= Installer::sectionNormal(__("You MUST also import MySQL TimeZone information into MySQL and grant the Cacti user SELECT access to the mysql.time_zone_name table"));
if ($config['cacti_server_os'] == 'unix') {
$output .= Installer::sectionNormal(__("On Linux/UNIX, run the following as 'root' in a shell:"));
$output .= Installer::sectionCode(__("mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql"));
} else {
$output .= Installer::sectionNormal(__("On Windows, you must follow the instructions here Time zone description table. Once that is complete, you can issue the following command to grant the Cacti user access to the tables:"));
}
$output .= Installer::sectionNormal(__("Then run the following within MySQL as an administrator:"));
$output .= Installer::sectionCode(__("mysql > GRANT SELECT ON mysql.time_zone_name to '%s'@'localhost' IDENTIFIED BY '%s'", $database_username, $database_password));
return $output;
}
public static function sectionTitleError($title = '') {
if (empty($title)) {
$title = __('Error');
}
return Installer::sectionTitle($title, null, 'cactiInstallSectionTitleError');
}
public static function sectionTitle($title = '', $id = '', $class = '') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
return Installer::section($title, $id, $class, 'cactiInstallSectionTitle', 'h2');
}
public static function sectionSubTitle($title = '', $id = '', $class = '') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
$subtitle = Installer::section($title, $id, $class, 'cactiInstallSectionTitle', 'h3');
$subtitle .= '
';
return $subtitle;
}
public static function sectionSubTitleEnd() {
return '
';
}
public static function sectionNormal($text = '', $id = '', $class = '') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
$class .= ' cactiInstallSectionNormal';
return Installer::section($text, $id, trim($class), 'cactiInstallSection', 'p');
}
public static function sectionNote($text = '', $id = '', $class = '') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
$class .= ' cactiInstallSectionNote';
return Installer::section('' . __('NOTE:') . '' . $text . '', $id, trim($class), '', 'p');
}
public static function sectionWarning($text = '', $id = '', $class = '') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
$class .= ' cactiInstallSectionWarning';
return Installer::section('' . __('WARNING:') . '' . $text . '', $id, trim($class), '', 'p');
}
public static function sectionError($text = '', $id = '', $class = '') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
$class .= ' cactiInstallSectionError';
return Installer::section('' . __('ERROR:') . '' . $text . '', $id, trim($class), '', 'p');
}
public static function sectionCode($text = '', $id = '', $class = '', $elementType = 'p') {
if (empty($class)) {
$class = '';
}
if (empty($id)) {
$id = '';
}
$class .= ' cactiInstallSectionCode';
return Installer::section($text, $id, trim($class), '', $elementType);
}
public static function section($text = '', $id = '', $class = '', $baseClass = 'cactiInstallSection', $elementType = 'div') {
if (empty($elementType)) {
$elementType = 'div';
}
$output = '<' . $elementType;
if (empty($baseClass)) {
$baseClass = 'cactiInstallSection';
}
if (!empty($class)) {
$baseClass = trim($baseClass . ' ' . $class);
}
if (!empty($baseClass)) {
$output .= ' class=\'' . $baseClass . '\'';
}
if (!empty($id)) {
$output .= ' id=\'' . $id . '\'';
}
$output .= '>' . $text . '' . $elementType . '>';
return $output;
}
private function updateButtons() {
if (empty($this->buttonNext)) {
$this->buttonNext = new InstallerButton();
}
if (empty($this->buttonPrevious)) {
$this->buttonPrevious = new InstallerButton();
}
if (empty($this->buttonTest)) {
$this->buttonTest = new InstallerButton();
$this->buttonTest->Enabled = false;
$this->buttonTest->Text = __('Test Connection');
}
$this->buttonNext->Text = __('Next');
$this->buttonPrevious->Text = __('Previous');
$this->buttonTest->Visible = false;
$this->buttonTest->setStep(Installer::STEP_TEST_REMOTE);
switch($this->stepCurrent) {
case Installer::STEP_WELCOME:
$this->buttonNext->Text = __('Begin');
break;
case Installer::STEP_INSTALL_CONFIRM:
/* checkdependencies - send to install/upgrade */
if ($this->mode == Installer::MODE_UPGRADE) {
$this->buttonNext->Text = __('Upgrade');
} elseif ($this->mode == Installer::MODE_DOWNGRADE) {
$this->buttonNext->Text = __('Downgrade');
}
break;
case Installer::STEP_PERMISSION_CHECK:
switch ($this->mode) {
case Installer::MODE_INSTALL:
case Installer::MODE_POLLER:
$this->stepNext = Installer::STEP_BINARY_LOCATIONS;
break;
case Installer::MODE_UPGRADE:
case Installer::MODE_DOWNGRADE:
$this->stepNext = Installer::STEP_CHECK_TABLES;
break;
}
break;
case Installer::STEP_PERMISSION_CHECK:
switch ($this->mode) {
case Installer::MODE_UPGRADE:
case Installer::MODE_DOWNGRADE:
$this->stepPrevious = Installer::STEP_INSTALL_TYPE;
break;
}
break;
case Installer::STEP_INSTALL_CONFIRM:
/* upgrade - if user upgrades send to settings check */
if ($this->isPre_v0_8_UpgradeNeeded()) {
/* upgrade - if user runs old version send to upgrade-oldversion */
$this->stepNext = Installer::STEP_INSTALL_OLD;
} else {
$this->stepNext = Installer::STEP_INSTALL;
}
break;
case Installer::STEP_CHECK_TABLES:
if ($this->mode == Installer::MODE_UPGRADE ||
$this->mode == Installer::MODE_DOWNGRADE) {
$this->stepPrevious = Installer::STEP_PERMISSION_CHECK;
}
break;
case Installer::STEP_COMPLETE:
$this->stepPrevious = Installer::STEP_NONE;
break;
}
$this->buttonNext->setStep($this->stepNext);
$this->buttonPrevious->setStep($this->stepPrevious);
}
/****************************************
* The following functions process the *
* various steps of the install process *
****************************************/
/**************************************************
* The following sections of code are all related
* to the installation process of the current step
**************************************************/
public function processCurrentStep() {
$exitReason = $this->shouldExitWithReason();
if ($exitReason !== false) {
$this->buttonNext->Enabled = false;
$this->buttonPrevious->Enabled = false;
$this->buttonTest->Enabled = false;
return $this->exitWithReason($exitReason);
}
switch ($this->stepCurrent) {
case Installer::STEP_WELCOME:
return $this->processStepWelcome();
case Installer::STEP_CHECK_DEPENDENCIES:
return $this->processStepCheckDependancies();
case Installer::STEP_INSTALL_TYPE:
return $this->processStepMode();
case Installer::STEP_BINARY_LOCATIONS:
return $this->processStepBinaryLocations();
case Installer::STEP_PERMISSION_CHECK:
return $this->processStepPermissionCheck();
case Installer::STEP_PROFILE_AND_AUTOMATION:
return $this->processStepProfileAndAutomation();
case Installer::STEP_TEMPLATE_INSTALL:
return $this->processStepTemplateInstall();
case Installer::STEP_CHECK_TABLES:
return $this->processStepCheckTables();
case Installer::STEP_INSTALL_CONFIRM:
return $this->processStepInstallConfirm();
case Installer::STEP_INSTALL:
return $this->processStepInstall();
case Installer::STEP_ERROR:
case Installer::STEP_COMPLETE:
return $this->processStepComplete();
}
return $this->exitWithReason((0 - $this->stepCurrent));
}
public function processStepWelcome() {
global $config;
$output = Installer::sectionTitle(__('Cacti Version') . ' ' . CACTI_VERSION . ' - ' . __('License Agreement'));
$output .= Installer::sectionNormal(__('Thanks for taking the time to download and install Cacti, the complete graphing solution for your network. Before you can start making cool graphs, there are a few pieces of data that Cacti needs to know.'));
$output .= Installer::sectionNormal(__('Make sure you have read and followed the required steps needed to install Cacti before continuing. Install information can be found for Unix and Win32-based operating systems.', '../docs/html/install_unix.html', '../docs/html/install_windows.html'));
if ($this->mode == Installer::MODE_UPGRADE) {
$output .= Installer::sectionNote(__('This process will guide you through the steps for upgrading from version \'%s\'. ',$this->old_cacti_version));
$output .= Installer::sectionNormal(__('Also, if this is an upgrade, be sure to reading the Upgrade information file.', '../docs/html/upgrade.html'));
}
if ($this->mode == Installer::MODE_DOWNGRADE) {
$output .= Installer::sectionNote(__('It is NOT recommended to downgrade as the database structure may be inconsistent'));
}
$output .= Installer::sectionNormal(__('Cacti is licensed under the GNU General Public License, you must agree to its provisions before continuing:'));
$output .= Installer::sectionCode(
__('This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.') . '
' .
__('This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.')
);
$langOutput = '';
$themePath = $config['base_path'] . '/include/themes/';
$themes = glob($themePath . '*', GLOB_ONLYDIR);
$themeOutput = '';
$eula = ($this->eula) ? ' checked' : '';
$output .= Installer::sectionNormal('' . __('Select default theme: ') . $themeOutput . ''.$langOutput.'');
$this->stepData = array('Eula' => $this->eula, 'Theme' => $this->theme, 'Language' => $this->language);
$this->buttonNext->Enabled = ($this->eula == 1);
return $output;
}
public function processStepCheckDependancies() {
global $config;
global $database_default, $database_username, $database_port;
global $rdatabase_default, $rdatabase_username, $rdatabase_port;
$enabled = array(
'location' => DB_STATUS_SUCCESS,
'php_timezone' => DB_STATUS_SUCCESS,
'php_modules' => DB_STATUS_SUCCESS,
'php_optional' => DB_STATUS_SUCCESS,
'mysql_timezone' => DB_STATUS_SUCCESS,
'mysql_performance' => DB_STATUS_SUCCESS
);
$output = Installer::sectionTitle(__('Pre-installation Checks'));
$output .= Installer::sectionSubTitle(__('Location checks'), 'location');
// Get request URI and break into parts
$test_request_uri = $_SERVER['REQUEST_URI'];
$test_request_parts = parse_url($test_request_uri);
$test_request_path = $test_request_parts['path'];
$test_request_len = strlen($test_request_parts['path']);
// Get current script name (filename only)
$test_script_name = basename($_SERVER['SCRIPT_NAME']);
$test_script_len = strlen($test_script_name);
// Get end of the path of URI and see if it's our script
$test_script_part = substr($test_request_path, $test_request_len - $test_script_len);
$test_script_result = strcmp($test_script_part, $test_script_name);
// Assume desired path is the URI
$test_final_path = $test_request_parts['path'];
// Script was found in path, so remove it
if ($test_script_result === 0) {
$test_final_path = substr($test_final_path,0,strlen($test_final_path) - $test_script_len);
}
// Add the install subfolder to defined path location
// and check if it matches, if not there will likely be problems
$test_config_path = $config['url_path'] . 'install/';
$test_compare_result = strcmp($test_config_path,$test_final_path);
// The path was not what we expected so print an error
if ($test_compare_result !== 0) {
$output .= Installer::sectionNormal('' . __('ERROR:') . ' ' . __('Please update config.php with the correct relative URI location of Cacti (url_path).') . '');
$enabled['location'] = DB_STATUS_ERROR;
} else {
$output .= Installer::sectionNormal(__('Your Cacti configuration has the relative correct path (url_path) in config.php.'));
}
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('PHP - Module Support (Required)'), 'php_modules');
$output .= Installer::sectionNormal(__('Cacti requires several PHP Modules to be installed to work properly. If any of these are not installed, you will be unable to continue the installation until corrected. In addition, for optimal system performance Cacti should be run with certain MySQL system variables set. Please follow the MySQL recommendations at your discretion. Always seek the MySQL documentation if you have any questions.'));
$output .= Installer::sectionNormal(__('The following PHP extensions are mandatory, and MUST be installed before continuing your Cacti install.'));
ob_start();
html_start_box(__('Required PHP Modules'), '100%', false, '3', '', false);
html_header(array(__('Name'), __('Required'), __('Installed')));
$enabled['php_modules'] = version_compare(PHP_VERSION, '5.4.0', '<') ? DB_STATUS_ERROR : DB_STATUS_SUCCESS;
form_alternate_row('phpline',true);
form_selectable_cell(__('PHP Version'), '');
form_selectable_cell('5.4.0+', '');
form_selectable_cell((version_compare(PHP_VERSION, '5.4.0', '<') ? "" . PHP_VERSION . "" : "" . PHP_VERSION . ""), '');
form_end_row();
$output .= Installer::sectionNormal(ob_get_contents());
ob_clean();
foreach ($this->modules as $id =>$e) {
form_alternate_row('line' . $id);
form_selectable_cell($e['name'], '');
form_selectable_cell('' . __('Yes') . '', '');
form_selectable_cell(($e['installed'] ? '' . __('Yes') . '' : '' . __('No') . ''), '');
form_end_row();
if (!$e['installed']) {
$enabled['php_modules'] = DB_STATUS_ERROR;
}
}
html_end_box(false);
$output .= Installer::sectionNormal(ob_get_contents());
ob_clean();
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('PHP - Module Support (Optional)'), 'php_optional');
$output .= Installer::sectionNormal(__('The following PHP extensions are recommended, and should be installed before continuing your Cacti install. NOTE: If you are planning on supporting SNMPv3 with IPv6, you should not install the php-snmp module at this time.'));
$extensions = array(
array('name' => 'snmp', 'installed' => false),
);
$ext = verify_php_extensions($extensions);
$ext[] = array('name' => 'TrueType Text', 'installed' => function_exists('imagettftext'));
$ext[] = array('name' => 'TrueType Box', 'installed' => function_exists('imagettfbbox'));
html_start_box(__('Optional Modules'), '100%', false, '3', '', false);
html_header(array(__('Name'), __('Optional'), __('Installed')));
foreach ($ext as $id => $e) {
form_alternate_row('line' . $id, true);
form_selectable_cell($e['name'], '');
form_selectable_cell('' . __('Yes') . '', '');
form_selectable_cell(($e['installed'] ? '' . __('Yes') . '' : '' . __('No') . ''), '');
form_end_row();
if (!$e['installed']) $enabled['php_optional'] = DB_STATUS_WARNING;
}
html_end_box();
$output .= Installer::sectionNormal(ob_get_contents());
ob_clean();
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('PHP - Timezone Support'), 'php_timezone');
if (ini_get('date.timezone') == '') {
$output .= Installer::sectionNormal('' . __('ERROR:') . ' ' . __('Your Web Servers PHP Timezone settings have not been set. Please edit php.ini and uncomment the \'date.timezone\' setting and set it to the Web Servers Timezone per the PHP installation instructions prior to installing Cacti.') . '');
$enabled['php_timezone'] = DB_STATUS_ERROR;
} else {
$output .= Installer::sectionNormal(__('Your Web Servers PHP is properly setup with a Timezone.'));
}
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('MySQL - TimeZone Support'), 'mysql_timezone');
$mysql_timezone_access = db_fetch_assoc('SHOW COLUMNS FROM mysql.time_zone_name', false);
if (cacti_sizeof($mysql_timezone_access)) {
$timezone_populated = db_fetch_cell('SELECT COUNT(*) FROM mysql.time_zone_name');
if (!$timezone_populated) {
$output .= Installer::sectionNormal('' . __('ERROR:') . ' ' . __('Your MySQL TimeZone database is not populated. Please populate this database before proceeding.') . '');
$enabled['mysql_timezone'] = DB_STATUS_ERROR;
}
} else {
$output .= Installer::sectionNormal('' . __('ERROR:') . ' ' . __('Your Cacti database login account does not have access to the MySQL TimeZone database. Please provide the Cacti database account "select" access to the "time_zone_name" table in the "mysql" database, and populate MySQL\'s TimeZone information before proceeding.') . '');
$enabled['mysql_timezone'] = DB_STATUS_ERROR;
}
if ($enabled['mysql_timezone'] == DB_STATUS_SUCCESS) {
$output .= Installer::sectionNormal(__('Your Cacti database account has access to the MySQL TimeZone database and that database is populated with global TimeZone information.'));
}
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('MySQL - Settings'), 'mysql_performance');
$output .= Installer::sectionNormal(__('These MySQL performance tuning settings will help your Cacti system perform better without issues for a longer time.'));
html_start_box(__('Recommended MySQL System Variable Settings'), '100%', false, '3', '', false);
$output_temp = ob_get_contents();
ob_clean();
$enabled['mysql_performance'] = utilities_get_mysql_recommendations();
$output_util = ob_get_contents();
ob_clean();
html_end_box(false);
$output .= Installer::sectionNormal($output_temp . $output_util . ob_get_contents());
ob_end_clean();
$output .= Installer::sectionSubTitleEnd();
$this->stepData = array('Sections' => $enabled);
$this->buttonNext->Enabled = $enabled['php_modules'] != DB_STATUS_ERROR;
return $output;
}
public function processStepMode() {
global $config;
global $database_default, $database_username, $database_hostname, $database_port;
global $rdatabase_default, $rdatabase_username, $rdatabase_hostname, $rdatabase_port;
// install/upgrade
$output = Installer::sectionTitle(__('Installation Type'));
switch ($this->mode) {
case Installer::MODE_UPGRADE:
// upgrade detected
$output .= Installer::sectionSubTitle(__('Upgrade'));
$output .= Installer::sectionNormal(__('Upgrade from %s to %s', $this->old_cacti_version, CACTI_VERSION));
$output .= Installer::sectionWarning(__('In the event of issues, It is highly recommended that you clear your browser cache, closing then reopening your browser (not just the tab Cacti is on) and retrying, before raising an issue with The Cacti Group'));
$output .= Installer::sectionNormal(__('On rare occasions, we have had reports from users who experience some minor issues due to changes in the code. These issues are caused by the browser retaining pre-upgrade code and whilst we have taken steps to minimise the chances of this, it may still occur. If you need instructions on how to clear your browser cache, https://www.refreshyourcache.com/ is a good starting point.'));
$output .= Installer::sectionNormal(__('If after clearing your cache and restarting your browser, you still experience issues, please raise the issue with us and we will try to identify the cause of it.'));
$output .= Installer::sectionSubTitleEnd();
break;
case Installer::MODE_DOWNGRADE:
$output .= Installer::sectionSubTitle(__('Upgrade'));
$output .= Installer::sectionNormal(__('Downgrade from %s to %s', $this->old_cacti_version, CACTI_VERSION));
$output .= Installer::sectionWarning(__('You appears to be downgrading to a previous version. Database changes made for the newer version will not be reversed and could cause issues.'));
$output .= Installer::sectionSubTitleEnd();
break;
default:
// new install
$output .= Installer::sectionSubTitle(__('Please select the type of installation'));
$output .= Installer::sectionNormal(__('Installation options:'));
$output .= Installer::sectionNormal(
'
'.
'
' . __('New Primary Server') . ' - ' . __('Choose this for the Primary site.') . '
' .
'
' . __('New Remote Poller') . ' - ' . __('Remote Pollers are used to access networks that are not readily accessible to the Primary site.') . '
' .
'
'
);
$selectedInstall = '';
$selectedPoller = '';
$sections = array(
'connection_local' => 0,
'connection_remote' => 0,
'error_file' => 0,
'error_poller' => 0,
'poller_vars' => 0,
);
$this->buttonNext->Enabled = true;
switch ($this->mode) {
case Installer::MODE_POLLER:
$selectedPoller = ' selected';
$sections['connection_local'] = 1;
$sections['connection_remote'] = 1;
$sections['error_file'] = !$this->isConfigurationWritable();
$sections['error_poller'] = !$this->isRemoteDatabaseGood();
if ($sections['error_poller']) {
$sections['poller_vars'] = 1;
$sections['connection_remote'] = 0;
}
if (!($sections['error_file'] || $sections['error_poller'])) {
$this->buttonNext->Enabled = true;
$this->buttonTest->Enabled = true;
$this->buttonTest->Visible = true;
} else {
$this->buttonNext->Enabled = false;
$this->buttonNext->Visible = false;
}
break;
default:
$selectedInstall = ' selected';
$sections['connection_local'] = 1;
break;
}
$output .= Installer::sectionNormal(
''
);
$output .= Installer::sectionNormal(__('The following information has been determined from Cacti\'s configuration file. If it is not correct, please edit "include/config.php" before continuing.'));
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('Local Database Connection Information'), 'connection_local');
$output .= Installer::sectionCode(
__('Database: %s', $database_default) . ' ' .
__('Database User: %s', $database_username) . ' ' .
__('Database Hostname: %s', $database_hostname) . ' ' .
__('Port: %s', $database_port) . ' ' .
__('Server Operating System Type: %s', $config['cacti_server_os']) . ' '
);
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('Central Database Connection Information'), 'connection_remote');
$output .= Installer::sectionCode(
__('Database: %s', $rdatabase_default) . ' ' .
__('Database User: %s', $rdatabase_username) . ' ' .
__('Database Hostname: %s', $rdatabase_hostname) . ' ' .
__('Port: %s', $rdatabase_port) . ' ' .
__('Server Operating System Type: %s', $config['cacti_server_os']) . ' '
);
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('Configuration Readonly!'), 'error_file');
$output .= Installer::sectionNormal('' . __('ERROR:') . ' ' . __('Your config.php file must be writable by the web server during install in order to configure the Remote poller. Once installation is complete, you must set this file to Read Only to prevent possible security issues.') . '');
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('Configuration of Poller'), 'error_poller');
$output .= Installer::sectionNormal('' . __('ERROR:') . ' ' . __('Your Remote Cacti Poller information has not been included in your config.php file. Please review the config.php.dist, and set the variables: $rdatabase_default, $rdatabase_username, etc. These variables must be set and point back to your Primary Cacti database server. Correct this and try again.') . '','config_remote');
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('Remote Poller Variables'), 'poller_vars');
$output .= Installer::sectionNormal(__('The variables that must be set in the config.php file include the following:'));
$output .= Installer::sectionCode(
'$rdatabase_type = \'mysql\'; ' .
'$rdatabase_default = \'cacti\'; ' .
'$rdatabase_hostname = \'cacti.example.com\'; // Central Cacti server. ' .
'$rdatabase_username = \'cactiuser\'; ' .
'$rdatabase_password = \'cactiuser\'; ' .
'$rdatabase_port = \'3306\'; ' .
'$rdatabase_ssl = false; '
);
$output .= Installer::sectionNormal(__('The Installer automatically assigns a $poller_id and adds it to the config.php file.'), 'config_remote_poller');
$output .= Installer::sectionNormal(__('Once the variables are all set in the config.php file, you must also grant the $rdatabase_username access to the main Cacti database server. Follow the same procedure you would with any other Cacti install. You may then press the \'Test Connection\' button. If the test is successful you will be able to proceed and complete the install.'), 'config_remote_var');
$output .= Installer::sectionSubTitleEnd();
$output .= Installer::sectionSubTitle(__('Additional Steps After Installation'), 'poller_vars');
$output .= Installer::sectionNormal(__('It essential that the Central Cacti server can communicate via MySQL to each remote Cacti database server. Once the install is complete, you must edit the Remote Data Collector and ensure the settings are correct. You can verify using the \'Test Connection\' when editing the Remote Data Collector.'), 'config_remote_db');
$this->stepData = array('Sections' => $sections);
$this->buttonNext->Enabled = ($this->mode != MODE_POLLER);
break;
}
return $output;
}
public function processStepBinaryLocations() {
$output = Installer::sectionTitle(__('Critical Binary Locations and Versions'));
$output .= Installer::sectionNormal(__('Make sure all of these values are correct before continuing.'));
if (!empty($this->errors)) {
$output .= Installer::sectionWarning(__('One or more paths appear to be incorrect, unable to proceed'));
}
$i = 0;
ob_start();
print '
';
/* find the appropriate value for each 'config name' above by config.php, database,
* or a default for fall back */
$class = 'odd';
$errors = array();
if (isset($this->errors) && array_key_exists('Paths', $this->errors)) {
$errors = $this->errors['Paths'];
}
foreach ($this->paths as $name => $array) {
$class = ($class == 'even' ? 'odd':'even');
$current_value = '';
if (isset($array['default'])) {
$current_value = $array['default'];
}
log_install_debug('paths','processStepBinaryLocations(): Displaying ' . $array['friendly_name'] . ' (' . $name . ' - ' . $class . '): ' . $current_value);
/* run a check on the path specified only if specified above, then fill a string with
the results ('FOUND' or 'NOT FOUND') so they can be displayed on the form */
$form_check_string = '';
/* draw the acual header and textbox on the form */
print "
" . $array['friendly_name'] . "
" . $array['description'] . "
";
print "
";
$data = array('text' => 'Valid');
if (array_key_exists($name, $errors)) {
$data['text'] = $errors[$name];
$data['error'] = true;
}
switch ($array['method']) {
case 'textbox':
form_text_box($name, $current_value, '', '', '40', 'text');
break;
case 'filepath':
form_filepath_box($name, $current_value, '', '', '40', 'text', 0, $data);
break;
case 'drop_array':
form_dropdown($name, $array['array'], '', '', $current_value, '', '');
break;
}
/*** Disable ouput of error for now, pending QA ***
if (isset($this->errors['Paths'][$name])) {
print Installer::sectionError(__($this->errors['Paths'][$name]));
}
*/
print '
';
print '
';
$i++;
}
print '
';
$html = ob_get_contents();
$output .= Installer::sectionNormal($html);
ob_end_clean();
return $output;
}
public function processStepPermissionCheck() {
global $config;
/* Print message and error logs */
$output = Installer::sectionTitle(__('Directory Permission Checks'));
$output .= Installer::sectionNormal(__('Please ensure the directory permissions below are correct before proceeding. During the install, these directories need to be owned by the Web Server user. These permission changes are required to allow the Installer to install Device Template packages which include XML and script files that will be placed in these directories. If you choose not to install the packages, there is an \'install_package.php\' cli script that can be used from the command line after the install is complete.'));
if ($this->mode == Installer::MODE_INSTALL) {
$output .= Installer::sectionNormal(__('After the install is complete, you can make some of these directories read only to increase security.'));
} else {
$output .= Installer::sectionNormal(__('These directories will be required to stay read writable after the install so that the Cacti remote synchronization process can update them as the Main Cacti Web Site changes'));
}
$sections = array();
if ($this->mode != Installer::MODE_POLLER) {
$output .= Installer::sectionSubTitle(__('Required Writable at Install Time Only'), 'writable_install');
$sections['writable_install'] = DB_STATUS_SUCCESS;
$class = 'even';
foreach($this->permissions['install'] as $path => $valid) {
$class = ($class == 'even' ? 'odd':'even');
/* draw the acual header and textbox on the form */
$output .= "
';
}
/* Print help message for unix and windows if directory is not writable */
if (($config['cacti_server_os'] == 'unix') && isset($writable)) {
$output .= Installer::sectionSubTitleEnd();
$running_user = get_running_user();
$sections['host_access'] = DB_STATUS_WARNING;
$output .= Installer::sectionSubTitle(__('Ensure Host Process Has Access'),'host_access');
$output .= Installer::sectionNormal(__('Make sure your webserver has read and write access to the entire folder structure.'));
$output .= Installer::sectionNormal(__('Example:'));
if ($config['cacti_server_os'] == 'win32') {
$output .= Installer::sectionCode(__('%s should have MODIFY permission to the above directories', $running_user));
} else {
$output .= Installer::sectionCode(__('chown -R %s.%s %s/resource/', $running_user, $running_user, $config['base_path']));
$output .= Installer::sectionNormal(__('For SELINUX-users make sure that you have the correct permissions or set \'setenforce 0\' temporarily.'));
}
} elseif (($config['cacti_server_os'] == 'win32') && isset($writable)){
$output .= Installer::sectionNormal(__('Check Permissions'));
}else {
$output .= Installer::sectionNormal('' . __('All folders are writable') . '');
}
if ($this->mode != Installer::MODE_POLLER) {
$output .= Installer::sectionNote(__('If you are installing packages, once the packages are installed, you should change the scripts directory back to read only as this presents some exposure to the web site.'));
} else {
$output .= Installer::sectionNote(__('For remote pollers, it is critical that the paths that you will be updating frequently, including the plugins, scripts, and resources paths have read/write access as the data collector will have to update these paths from the main web server content.'));
}
$this->buttonNext->Enabled = !isset($writable);
$this->stepData = array('Sections' => $sections);
return $output;
}
public function processStepProfileAndAutomation() {
global $cron_intervals;
$profiles = db_fetch_assoc('SELECT dsp.id, dsp.name, dsp.default
FROM data_source_profiles AS dsp
ORDER BY dsp.step, dsp.name');
if (cacti_sizeof($profiles)) {
$output = Installer::sectionTitle(__('Default Profile'));
$output .= Installer::sectionNormal(__('Please select the default Data Source Profile to be used for polling sources. This is the maximum amount of time between scanning devices for information so the lower the polling interval, the more work is placed on the Cacti Server host. Also, select the intended, or configured Cron interval that you wish to use for Data Collection.'));
$fields_schedule = array(
'default_profile' => array(
'method' => 'drop_sql',
'friendly_name' => __('Default Profile'),
'sql' => 'SELECT dsp.id, dsp.name, dsp.default FROM data_source_profiles AS dsp ORDER BY dsp.step, dsp.name',
'value' => '|arg1:default_profile|',
),
'cron_interval' => array(
'method' => 'drop_array',
'friendly_name' => __('Cron Interval'),
'array' => $cron_intervals,
'value' => '|arg1:cron_interval|',
)
);
ob_start();
$values = array('default_profile' => $this->profile, 'cron_interval' => $this->cronInterval);
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_schedule, $values),
)
);
$html = ob_get_contents();
ob_end_clean();
$output .= Installer::sectionNormal($html);
$output .= Installer::sectionTitle(__('Default Automation Network'));
$output .= Installer::sectionNormal(__('Cacti can automatically scan the network once installation has completed. This will utilise the network range below to work out the range of IPs that can be scanned. A predefined set of options are defined for scanning which include using both \'public\' and \'private\' communities.'));
$output .= Installer::sectionNormal(__('If your devices require a different set of options to be used first, you may define them below and they will be utilized before the defaults'));
$output .= Installer::sectionNormal(__('All options may be adjusted post installation'));
global $fields_snmp_item_with_retry;
$output .= Installer::sectionSubTitle(__('Default Options'));
$fields_automation = array(
'automation_mode' => array(
'method' => 'checkbox',
'friendly_name' => __('Scan Mode'),
'value' => '|arg1:automation_mode|',
),
'automation_range' => array(
'method' => 'textbox',
'friendly_name' => __('Network Range'),
'value' => '|arg1:automation_range|',
'max_length' => '100',
),
'automation_override' => array(
'method' => 'checkbox',
'friendly_name' => __('Additional Defaults'),
'value' => '|arg1:automation_override|',
)
);
ob_start();
$values = array(
'automation_mode' => $this->automationMode ? 'on' : '',
'automation_range' => $this->automationRange,
'automation_override' => $this->automationOverride ? 'on' : '',
);
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_automation, $values),
)
);
$html = ob_get_contents();
$output .= Installer::sectionNormal($html);
$output .= Installer::sectionSubTitle(__('Additional SNMP Options'), 'automation_snmp_options');
ob_clean();
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_snmp_item_with_retry, $this->snmpOptions),
)
);
$html = ob_get_contents();
$output .= Installer::sectionNormal($html);
ob_end_clean();
} else {
$output = Installer::sectionTitleError(__('Error Locating Profiles'));
$ouptut .= Installer::sectionNormal(__('The installation cannot continue because no profiles could be found.'));
$output .= Installer::sectionNote(__('This may occur if you have a blank database and have not yet imported the cacti.sql file'));
$output .= Installer::sectionCode('mysql> source cacti.sql');
}
return $output;
}
public function processStepTemplateInstall() {
$output = Installer::sectionTitle(__('Template Setup'));
$output .= Installer::sectionNormal(__('Please select the Device Templates that you wish to use after the Install. If you Operating System is Windows, you need to ensure that you select the \'Windows Device\' Template. If your Operating System is Linux/UNIX, make sure you select the \'Local Linux Machine\' Device Template.'));
$templates = install_setup_get_templates();
ob_start();
html_start_box(__('Templates'), '100%', false, '3', 'center', '', '');
html_header_checkbox(array(__('Name'), __('Description'), __('Author'), __('Homepage')));
foreach ($templates as $id => $p) {
form_alternate_row('line' . $id, true);
form_selectable_cell($p['name'], $id);
form_selectable_cell($p['description'], $id);
form_selectable_cell($p['author'], $id);
if ($p['homepage'] != '') {
form_selectable_cell('' . $p['homepage'] . '', $id);
} else {
form_selectable_cell('', $id);
}
form_checkbox_cell($p['name'], 'template_' . str_replace(".", "_", $p['filename']));
form_end_row();
}
html_end_box(false);
$output .= Installer::sectionNormal(ob_get_contents());
ob_end_clean();
$output .= Installer::sectionNormal(__('Device Templates allow you to monitor and graph a vast assortment of data within Cacti. After you select the desired Device Templates, press \'Finish\' and the installation will complete. Please be patient on this step, as the importation of the Device Templates can take a few minutes.'));
$this->stepData = array('Templates' => $this->templates);
return $output;
}
public function processStepCheckTables() {
$output = Installer::sectionTitle(__('Database Collation'));
$collation_vars = db_fetch_assoc('SHOW VARIABLES LIKE "collation_database";');
$collation_value = '';
$collation_valid = false;
if (cacti_sizeof($collation_vars)) {
$collation_value = $collation_vars[0]['Value'];
$collation_valid = ($collation_value == 'utf8mb4_unicode_ci');
}
if ($collation_valid) {
$output .= Installer::sectionNormal(__('Your databse default collation appears to be UTF8 compliant'));
} else {
$output .= Installer::sectionNormal(__('Your database default collaction does NOT appear to be UTF8 compliant'));
$output .= Installer::sectionWarning(__('Any tables created by plugins may have issues linked against Cacti Core tables if the collation is not matched'));
$output .= Installer::sectionNormal(__('Please ensure your database is changed from \'%s\' to \'utf8mb4_unicode_ci\'', $collation_value));
}
$output .= Installer::sectionTitle(__('Table Setup'));
$tables = install_setup_get_tables();
if (cacti_sizeof($tables)) {
$output .= Installer::sectionNormal(__('The following tables should be converted to UTF8 and InnoDB. Please select the tables that you wish to convert during the installation process.'));
$output .= Installer::sectionWarning(__('Conversion of tables may take some time especially on larger tables. The conversion of these tables will occur in the background but will not prevent the installer from completing. This may slow down some servers if there are not enough resources for MySQL to handle the conversion.'));
$show_warning=false;
ob_start();
html_start_box(__('Tables'), '100%', false, '3', 'center', '', '');
html_header_checkbox(array(__('Name'), __('Collation'), __('Engine'), __('Rows')));
foreach ($tables as $id => $p) {
$enabled = ($p['Rows'] < 1000000 ? true : false);
$style = ($enabled ? '' : 'text-decoration: line-through;');
form_alternate_row('line' . $id, true, $enabled);
form_selectable_cell($p['Name'], $id, '', $style);
form_selectable_cell($p['Collation'], $id, '', $style);
form_selectable_cell($p['Engine'], $id, '', $style);
form_selectable_cell($p['Rows'], $id, '', $style);
if ($enabled) {
form_checkbox_cell($p['Name'], 'table_' . $p['Name']);
} else {
$show_warning=true;
form_selectable_cell('', $id, '', $style);
}
form_end_row();
}
html_end_box(false);
$output .= Installer::sectionNormal(ob_get_contents());
if ($show_warning) {
$output .= Installer::sectionTitleError(__('WARNING'));
$output .= Installer::sectionNormal(__('One or more tables are too large to convert during the installation. You should use the cli/convert_tables.php script to perform the conversion.'));
$output .= Installer::sectionCode(read_config_option('path_php_binary') . ' -q ' . $config['base_path'] . 'cli/convert_tables.php -u -i');
}
ob_end_clean();
} else {
$output .= Installer::sectionNormal(__('All your tables appear to be UTF8 compliant'));
}
$this->stepData = array('Tables' => $this->tables);
return $output;
}
public function processStepInstallConfirm() {
switch ($this->mode) {
case Installer::MODE_UPGRADE:
$title = __('Confirm Upgrade');
$button = __('Upgrade');
break;
case Installer::MODE_DOWNGRADE:
$title = __('Confirm Downgrade');
$button = __('Downgrade');
break;
default:
$title = __('Confirm Installation');
$button = __('Install');
break;
}
if ($this->mode == Installer::MODE_DOWNGRADE) {
$output = Installer::sectionTitleError(__('DOWNGRADE DETECTED'));
$output .= Installer::sectionCode(__('YOU MUST MANAUALLY CHANGE THE CACTI DATABASE TO REVERT ANY UPGRADE CHANGES THAT HAVE BEEN MADE. THE INSTALLER HAS NO METHOD TO DO THIS AUTOMATICALLY FOR YOU'));
$output .= Installer::sectionNormal(__('Downgrading should only be performed when absolutely necessary and doing so may break your installlation'));
} else {
$output = Installer::sectionTitle($title);
$output .= Installer::sectionNormal(__('Your Cacti Server is almost ready. Please check that you are happy to proceed.'));
$output .= Installer::sectionNote(
__('Press \'%s\' then click \'%s\' to complete the installation process after selecting your Device Templates.', $title, $button)
);
}
$output .= Installer::sectionNormal('