$msg]
);
}
/**
* Checks if target method is available to be called using AJAX.
*
* @param string $method Target method.
*
* @return boolean True allowed, false not.
*/
public function ajaxMethod($method)
{
global $config;
// Check access.
check_login();
return in_array($method, $this->AJAXMethods);
}
/**
* Constructor.
*
* @param boolean $must_run Must run or not.
* @param string $ajax_controller Controller.
*
* @return object
* @throws Exception On error.
*/
public function __construct(
bool $must_run=false,
$ajax_controller='include/ajax/welcome_window'
) {
$this->ajaxController = $ajax_controller;
if ($this->initialize($must_run) !== true) {
throw new Exception('Must not be shown');
}
return $this;
}
/**
* Main method.
*
* @return void
*/
public function run()
{
ui_require_css_file('new_installation_welcome_window');
echo '
';
?>
';
}
/**
* Method to cancel welcome modal window.
*
* @return void
*/
public function cancelWelcome()
{
// Config update value.
$this->setStep(WELCOME_FINISHED);
}
/**
* Return current step.
*
* @return integer Step.
*/
public function getStep(): int
{
global $config;
$this->step = $config['welcome_state'];
// Get step available.
if (empty($config['welcome_mail_configured']) === true
&& get_parameter('sec2') == 'godmode/setup/setup'
&& get_parameter('section', '') == 'general'
&& get_parameter('update_config', false) !== false
) {
$this->step = W_CONFIGURE_MAIL;
} else if (empty($config['welcome_id_agent']) === true) {
$this->step = W_CREATE_AGENT;
} else if (empty($config['welcome_module']) === true) {
$this->step = W_CREATE_MODULE;
} else if (empty($config['welcome_alert']) === true) {
$this->step = W_CREATE_ALERT;
} else if (empty($config['welcome_task']) === true) {
$this->step = W_CREATE_TASK;
}
return $this->step;
}
/**
* Sets current step.
*
* @param integer $step Current step.
*
* @return void
*/
public function setStep(int $step)
{
$this->step = $step;
config_update_value('welcome_state', $step);
}
/**
* Completes current step.
*
* @return void
*/
public function completeStep()
{
switch ($this->step) {
case W_CONFIGURE_MAIL:
config_update_value('welcome_mail_configured', true);
break;
case W_CREATE_AGENT:
config_update_value('welcome_id_agent', true);
break;
case W_CREATE_MODULE:
config_update_value('welcome_module', true);
break;
case W_CREATE_ALERT:
config_update_value('welcome_alert', true);
break;
case W_CREATE_TASK:
config_update_value('welcome_task', true);
break;
default:
// Ignore.
break;
}
}
/**
* Check if all tasks had been completed.
*
* @return boolean All completed or not.
*/
public function checkAllTasks()
{
global $config;
foreach ($this->tasks as $t) {
if (empty($config[$t]) === true) {
return false;
}
}
return true;
}
/**
* Retrieve current welcome agent id.
*
* @return integer Agent id (created).
*/
public function getWelcomeAgent()
{
global $config;
return (isset($config['welcome_id_agent']) === true) ? $config['welcome_id_agent'] : '';
}
/**
* Saves current welcome agent (latest created).
*
* @param integer $id_agent Agent id.
*
* @return void
*/
public function setWelcomeAgent(int $id_agent)
{
config_update_value('welcome_id_agent', $id_agent);
}
/**
* Loads a welcome window form
*
* @return​ ​string HTML code for form.
*
* @return void Runs loadWelcomeWindow (AJAX).
*/
public function loadWelcomeWindow()
{
global $config;
$flag_task = false;
$form = [
'action' => '#',
'id' => 'welcome_form',
'onsubmit' => 'this.dialog("close");',
'class' => 'modal',
];
if (enterprise_installed() === true) {
$logo_url = ENTERPRISE_DIR.'/'.$logo_url;
}
if (check_acl($config['id_user'], 0, 'PM')) {
$flag_um = false;
$flag_cm = false;
$flag_su = false;
$flag_lv = false;
$btn_update_manager_class = ' fail';
$btn_configure_mail_class = ' fail';
$btn_servers_up_class = ' fail';
$btn_license_valid_class = ' fail';
$li_update_manager_class = 'row_grey';
$li_configure_mail_class = 'row_grey';
$li_servers_up_class = 'row_grey';
$li_license_valid_class = 'row_grey';
include_once 'include/functions_update_manager.php';
if (update_manager_verify_registration()) {
$btn_update_manager_class = '';
$li_update_manager_class = 'row_green';
$flag_um = true;
}
if (empty($config['welcome_mail_configured']) === false) {
$btn_configure_mail_class = '';
$li_configure_mail_class = 'row_green';
$flag_cm = true;
}
include_once 'include/functions_servers.php';
if (check_all_servers_up() === true) {
$btn_servers_up_class = '';
$li_servers_up_class = 'row_green';
$flag_su = true;
}
if (enterprise_installed()) {
$license_valid = true;
enterprise_include_once('include/functions_license.php');
$license = enterprise_hook('license_get_info');
$days_to_expiry = ((strtotime($license['expiry_date']) - time()) / (60 * 60 * 24));
if ($license === ENTERPRISE_NOT_HOOK || $days_to_expiry <= 30) {
$license_valid = false;
}
if ($license_valid === true) {
$btn_license_valid_class = '';
$li_license_valid_class = 'row_green';
$flag_lv = true;
} else {
$btn_license_valid_class = 'fail';
$li_license_valid_class = 'row_grey';
$flag_lv = false;
}
} else {
$btn_license_valid_class = 'fail';
$li_license_valid_class = 'row_grey';
$flag_lv = false;
}
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_diagnosis',
'class' => 'flex-row flex-items-center w98p ',
'direct' => 1,
'block_content' => [
[
'label' => __('Post-installation status diagnostic'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_diagnosis',
'id' => 'lbl_diagnosis',
],
],
],
];
if ($flag_um === false || $flag_cm === false || $flag_su === false || $flag_lv === false) {
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_update_manager',
'class' => 'hole flex-row flex-items-center w98p '.$li_update_manager_class,
'direct' => 1,
'block_content' => [
[
'label' => __('Warp Update registration'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_update_manager',
'id' => 'lbl_update_manager',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => [
'class' => (empty($btn_update_manager_class) === false) ? $btn_update_manager_class : 'invisible_important',
'mode' => 'onlyIcon',
],
'name' => 'btn_update_manager_conf',
'id' => 'btn_update_manager_conf',
],
],
],
];
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_configure_mail',
'class' => 'hole flex-row flex-items-center w98p '.$li_configure_mail_class,
'direct' => 1,
'block_content' => [
[
'label' => __('Default mail to send alerts'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_create_agent',
'id' => 'lbl_create_agent',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => [
'class' => (empty($btn_configure_mail_class) === false) ? $btn_configure_mail_class : 'invisible_important',
'mode' => 'onlyIcon',
],
'name' => 'btn_email_conf',
'id' => 'btn_email_conf',
],
],
],
];
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_servers_up',
'class' => 'hole flex-row flex-items-center w98p '.$li_servers_up_class,
'direct' => 1,
'block_content' => [
[
'label' => __('All servers running'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_servers_up',
'id' => 'lbl_servers_up',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => [
'class' => (empty($btn_servers_up_class) === false) ? $btn_servers_up_class : 'invisible_important',
'mode' => 'onlyIcon',
],
'name' => 'btn_servers_up_conf',
'id' => 'btn_servers_up_conf',
],
],
],
];
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_license_valid',
'class' => 'hole flex-row flex-items-center w98p '.$li_license_valid_class,
'direct' => 1,
'block_content' => [
[
'label' => __('Enterprise licence valid'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_license_valid',
'id' => 'lbl_license_valid',
],
],
[
'arguments' => [
'label' => '',
'type' => 'button',
'attributes' => [
'class' => (empty($btn_license_valid_class) === false) ? $btn_license_valid_class : 'invisible_important',
'mode' => 'onlyIcon',
],
'name' => 'btn_license_valid_conf',
'id' => 'btn_license_valid_conf',
],
],
],
];
} else {
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_all_correct',
'class' => 'hole flex-row flex-items-center w98p',
'direct' => 1,
'block_content' => [
[
'label' => __('It seems that your Pandora FMS is working correctly and registered with ID:
#'.$config['pandora_uid'].'.
For more information use the self-diagnosis tool.'),
'arguments' => [
'class' => 'first_lbl w98p',
'name' => 'lbl_all_correct',
'id' => 'lbl_all_correct',
],
],
],
];
}
if ($flag_um === false || $flag_cm === false || $flag_su === false || $flag_lv === false) {
$flag_task = true;
}
}
// Task to do.
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_task_todo',
'class' => 'flex-row flex-items-center w98p',
'direct' => 1,
'block_content' => [
[
'label' => __('Task to perform'),
'arguments' => [
'class' => 'first_lbl',
'name' => 'lbl_task_todo',
'id' => 'lbl_task_todo',
],
],
],
];
$fields['wizard_agent'] = __('Agent installation wizard');
$fields['check_web'] = __('Create WEB monitoring');
$fields['check_connectivity'] = __('Create network monitoring');
$fields['check_net'] = __('Discover my network');
$fields['check_mail_alert'] = __('Create email alert');
$inputs[] = [
'wrapper' => 'div',
'block_id' => 'div_wizard_agent',
'class' => 'flex space-between w98p',
'direct' => 1,
'block_content' => [
[
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'task_to_perform',
'selected' => '',
'return' => true,
'nothing' => \__('Please select one'),
'nothing_value' => '',
],
],
[
'arguments' => [
'label' => __("Let's do it!"),
'type' => 'button',
'attributes' => [
'class' => 'secondary',
'icon' => 'next',
],
'name' => 'go_wizard',
'id' => 'go_wizard',
],
],
],
];
$output = $this->printForm(
[
'form' => $form,
'inputs' => $inputs,
],
true
);
$output .= $this->loadJS($flag_task);
echo $output;
?>
'next', 'style' => 'margin-top:15px; float:right;']);
?>
'next', 'style' => 'margin-top:15px; float:right;']);
?>
'next', 'style' => 'margin-top:15px; float:right;']);
?>
'.__('Latest value').':
'.html_print_image('images/spinner.gif', true).''
);
$condition = alerts_get_alert_templates(['(id IN (1,3) OR name = "'.io_safe_input('Unknown condition').'")'], ['id', 'name']);
echo html_print_label_input_block(
__('Contition'),
html_print_select(
index_array($condition, 'id', 'name'),
'id_condition',
'',
'',
__('Select'),
'',
true,
false,
true,
'w100p',
false,
'width: 100%;',
false,
false,
false,
'',
false,
false,
true
)
);
echo html_print_submit_button(__('Create'), 'alert_mail', false, ['icon' => 'next', 'style' => 'margin-top:15px; float:right;']);
?>
completeStep();
$this->setStep(W_CONFIGURE_MAIL);
}
// Check current page.
$sec2 = get_parameter('sec2', '');
// Search also does not fulfill sec2.
if (empty($sec2) === true) {
$sec2 = get_parameter('keywords', '');
}
if ($must_run === false
|| ((int) $config['welcome_state']) === WELCOME_FINISHED
) {
// Do not show if finished.
return false;
}
$this->step = $this->getStep();
$this->agent = $this->getWelcomeAgent();
/*
* Configure mail. Control current flow.
*
* On empty sec2: show current step.
* On setup page: do not show.
* After mail configuration: enable agent step.
*/
if ($this->step === W_CONFIGURE_MAIL) {
if ($sec2 === 'godmode/setup/setup'
&& get_parameter('section', '') == 'general'
&& get_parameter('update_config', false) !== false
) {
// Mail configuration have been processed.
$this->step = W_CONFIGURE_MAIL;
$this->completeStep();
$this->setStep(W_CREATE_AGENT);
} else if ($sec2 === 'godmode/setup/setup'
&& get_parameter('section', '') === 'general'
) {
// Mail configuration is being processed.
return false;
} else if (empty($sec2) === true) {
// Show main page.
return true;
}
}
/*
* Create agent. Control current flow.
*
* Welcome wizard is shown if you create your first agent.
*
*/
if (empty($config['welcome_id_agent']) === true) {
// Create agent is pending.
if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('create_agent', false) !== false
) {
// Agent have been created. Store.
// Here complete step is not needed because is already done
// by setWelcomeAgent.
$this->setWelcomeAgent(
// Non yet processed. Get next available ID.
db_get_value_sql(
sprintf(
'SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "%s"
AND TABLE_NAME = "%s"',
$config['dbname'],
'tagente'
)
)
);
$this->setStep(W_CREATE_MODULE);
return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente') {
// Agent is being created.
return false;
} else if (empty($sec2) === true) {
// If at main page, show welcome.
return true;
}
} else if ($this->step === W_CREATE_AGENT) {
$this->step = W_CREATE_MODULE;
}
/*
* Create module. Control current flow.
*
* On empty sec2: show current step.
* On module creation page: do not show.
* After module creation: enable alert step.
*/
if ($this->step === W_CREATE_MODULE) {
// Create module is pending.
if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'module'
&& get_parameter('create_module', false) !== false
) {
// Module have been created.
$this->completeStep();
$this->setStep(W_CREATE_ALERT);
return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'module'
) {
// Module is being created.
return false;
} else if (empty($sec2) === true) {
// If at main page, show welcome.
return true;
}
}
/*
* Create alert. Control current flow.
*
* On empty sec2: show current step.
* On alert creation page: do not show.
* After alert creation: enable discovery task step.
*/
if ($this->step === W_CREATE_ALERT) {
// Create alert is pending.
if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'alert'
&& get_parameter('create_alert', false) !== false
) {
// Alert have been created.
$this->completeStep();
$this->setStep(W_CREATE_TASK);
return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente'
&& get_parameter('tab', '') === 'alert'
) {
// Alert is being created.
return false;
} else if (empty($sec2) === true) {
// If at main page, show welcome.
return true;
}
}
/*
* Create discovery task. Control current flow.
*
* On empty sec2: show current step.
* On discovery task creation page: do not show.
* After discovery task creation: finish.
*/
// Create Discovery task is pending.
// Host&Devices finishses on page 2.
if ($sec2 === 'godmode/servers/discovery'
&& (int) get_parameter('page') === 2
) {
// Discovery task have been created.
$this->step = W_CREATE_TASK;
$this->completeStep();
// Check if all other tasks had been completed.
if ($this->checkAllTasks() === true) {
// Finished! do not show.
$this->setStep(WELCOME_FINISHED);
return false;
}
return true;
} else if ($sec2 == 'godmode/servers/discovery') {
// Discovery task is being created.
return false;
}
// Check if all other tasks had been completed.
if ($this->checkAllTasks() === true) {
// Finished! do not show.
$this->setStep(WELCOME_FINISHED);
return false;
} else if (empty($sec2) === true) {
// Pending tasks.
return true;
}
if ($this->step === WELCOME_FINISHED) {
// Welcome tutorial finished.
return false;
}
// Return a reference to the new object.
return false;
}
/**
* Load JS content.
* function that enables the functions to the buttons when its action is
* completed.
* Assign the url of each button.
*
* @return string HTML code for javascript functionality.
*/
public function loadJS($flag_task=false)
{
ob_start();
?>