Merge branch 'ent-4774-welcome-to-pandorafms' into ent-EDF

This commit is contained in:
fbsanchez 2019-11-07 14:06:07 +01:00
commit ef14de075e
1 changed files with 154 additions and 66 deletions

View File

@ -47,6 +47,19 @@ class WelcomeWindow extends Wizard
'cancelWelcome', 'cancelWelcome',
]; ];
/**
* Tasks.
*
* @var array
*/
private $tasks = [
'welcome_mail_configured',
'welcome_id_agent',
'welcome_module',
'welcome_alert',
'welcome_task',
];
/** /**
* Url of controller. * Url of controller.
* *
@ -197,6 +210,19 @@ class WelcomeWindow extends Wizard
global $config; global $config;
$this->step = $config['welcome_state']; $this->step = $config['welcome_state'];
// Get step available.
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;
} else if (empty($config['welcome_mail_configured']) === true) {
$this->step = W_CONFIGURE_MAIL;
}
return $this->step; return $this->step;
} }
@ -212,7 +238,61 @@ class WelcomeWindow extends Wizard
{ {
$this->step = $step; $this->step = $step;
config_update_value('welcome_state', $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;
} }
@ -264,41 +344,32 @@ class WelcomeWindow extends Wizard
$li_create_alert_class = 'grey'; $li_create_alert_class = 'grey';
$li_create_discovery_class = 'green'; $li_create_discovery_class = 'green';
switch ($this->step) { if (empty($config['welcome_mail_configured']) === false) {
case W_CREATE_AGENT:
$btn_configure_mail_class = ' completed'; $btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' pending'; }
$li_create_module_class = 'green';
break;
case W_CREATE_MODULE: if (empty($config['welcome_id_agent']) === false) {
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed'; $btn_create_agent_class = ' completed';
$btn_create_module_class = ' pending'; $btn_create_module_class = ' pending';
$li_create_module_class = 'green'; $li_create_module_class = 'green';
$li_create_alert_class = 'green'; }
break;
case W_CREATE_ALERT: if (empty($config['welcome_module']) === false) {
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed';
$btn_create_module_class = ' completed'; $btn_create_module_class = ' completed';
$btn_create_alert_class = ' pending'; $btn_create_alert_class = ' pending';
$li_create_module_class = 'green'; $li_create_module_class = 'green';
$li_create_alert_class = 'green'; }
break;
case W_CREATE_TASK: if (empty($config['welcome_alert']) === false) {
$btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed';
$btn_create_module_class = ' completed';
$btn_create_alert_class = ' completed'; $btn_create_alert_class = ' completed';
$btn_create_discovery_class = ' pending';
$li_create_module_class = 'green';
$li_create_alert_class = 'green'; $li_create_alert_class = 'green';
break; }
case WELCOME_FINISHED: if (empty($config['welcome_task']) === false) {
$btn_create_discovery_class = ' completed';
}
if ((int) $config['welcome_state'] === WELCOME_FINISHED) {
// Nothing left to do. // Nothing left to do.
$btn_configure_mail_class = ' completed'; $btn_configure_mail_class = ' completed';
$btn_create_agent_class = ' completed'; $btn_create_agent_class = ' completed';
@ -307,13 +378,6 @@ class WelcomeWindow extends Wizard
$btn_create_discovery_class = ' completed'; $btn_create_discovery_class = ' completed';
$li_create_module_class = 'green'; $li_create_module_class = 'green';
$li_create_alert_class = 'green'; $li_create_alert_class = 'green';
break;
default:
case W_CONFIGURE_MAIL:
// Nothing done yet.
$btn_configure_mail_class = ' pending';
break;
} }
$form = [ $form = [
@ -537,6 +601,7 @@ class WelcomeWindow extends Wizard
global $config; global $config;
if (isset($config['welcome_state']) === false) { if (isset($config['welcome_state']) === false) {
$this->completeStep();
$this->setStep(W_CONFIGURE_MAIL); $this->setStep(W_CONFIGURE_MAIL);
} }
@ -549,7 +614,7 @@ class WelcomeWindow extends Wizard
} }
if ($must_run === false if ($must_run === false
|| $config['welcome_state'] === WELCOME_FINISHED || ((int) $config['welcome_state']) === WELCOME_FINISHED
) { ) {
// Do not show if finished. // Do not show if finished.
return false; return false;
@ -566,13 +631,14 @@ class WelcomeWindow extends Wizard
* After mail configuration: enable agent step. * After mail configuration: enable agent step.
*/ */
if ($this->step == W_CONFIGURE_MAIL) { if ($this->step === W_CONFIGURE_MAIL) {
if ($sec2 === 'godmode/setup/setup' if ($sec2 === 'godmode/setup/setup'
&& get_parameter('section', '') == 'general' && get_parameter('section', '') == 'general'
&& get_parameter('update_config', false) !== false && get_parameter('update_config', false) !== false
) { ) {
// Mail configuration have been processed. // Mail configuration have been processed.
$_SESSION['configured_mail'] = true; $this->step = W_CONFIGURE_MAIL;
$this->completeStep();
$this->setStep(W_CREATE_AGENT); $this->setStep(W_CREATE_AGENT);
} else if ($sec2 === 'godmode/setup/setup' } else if ($sec2 === 'godmode/setup/setup'
&& get_parameter('section', '') === 'general' && get_parameter('section', '') === 'general'
@ -580,7 +646,7 @@ class WelcomeWindow extends Wizard
// Mail configuration is being processed. // Mail configuration is being processed.
return false; return false;
} else if (empty($sec2) === true) { } else if (empty($sec2) === true) {
// If at main page, show welcome. // Show main page.
return true; return true;
} }
} }
@ -598,11 +664,20 @@ class WelcomeWindow extends Wizard
&& get_parameter('create_agent', false) !== false && get_parameter('create_agent', false) !== false
) { ) {
// Agent have been created. Store. // Agent have been created. Store.
// Here complete step is not needed because is already done
// by setWelcomeAgent.
$this->setWelcomeAgent( $this->setWelcomeAgent(
db_get_value( // Non yet processed. Get next available ID.
'MAX(id_agente)', db_get_value_sql(
sprintf(
'SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "%s"
AND TABLE_NAME = "%s"',
$config['dbname'],
'tagente' 'tagente'
) )
)
); );
$this->setStep(W_CREATE_MODULE); $this->setStep(W_CREATE_MODULE);
return true; return true;
@ -613,6 +688,8 @@ class WelcomeWindow extends Wizard
// If at main page, show welcome. // If at main page, show welcome.
return true; return true;
} }
} else if ($this->step === W_CREATE_AGENT) {
$this->step = W_CREATE_MODULE;
} }
/* /*
@ -630,6 +707,7 @@ class WelcomeWindow extends Wizard
&& get_parameter('create_module', false) !== false && get_parameter('create_module', false) !== false
) { ) {
// Module have been created. // Module have been created.
$this->completeStep();
$this->setStep(W_CREATE_ALERT); $this->setStep(W_CREATE_ALERT);
return true; return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente' } else if ($sec2 === 'godmode/agentes/configurar_agente'
@ -658,6 +736,7 @@ class WelcomeWindow extends Wizard
&& get_parameter('create_alert', false) !== false && get_parameter('create_alert', false) !== false
) { ) {
// Alert have been created. // Alert have been created.
$this->completeStep();
$this->setStep(W_CREATE_TASK); $this->setStep(W_CREATE_TASK);
return true; return true;
} else if ($sec2 === 'godmode/agentes/configurar_agente' } else if ($sec2 === 'godmode/agentes/configurar_agente'
@ -679,24 +758,33 @@ class WelcomeWindow extends Wizard
* After discovery task creation: finish. * After discovery task creation: finish.
*/ */
if ($this->step === W_CREATE_TASK) {
// Create Discovery task is pending. // Create Discovery task is pending.
// Host&Devices finishses on page 2. // Host&Devices finishses on page 2.
if ($sec2 === 'godmode/servers/discovery' if ($sec2 === 'godmode/servers/discovery'
&& get_parameter('page', 0) == 2 && get_parameter('page', 0) == 2
) { ) {
// Discovery task have been created. // Discovery task have been created.
$this->setStep(WELCOME_FINISHED); $this->step = W_CREATE_TASK;
$this->completeStep();
// Check if all other tasks had been completed.
if ($this->checkAllTasks() === true) {
// Finished! do not show. // Finished! do not show.
$this->setStep(WELCOME_FINISHED);
return false; return false;
}
return true;
} else if ($sec2 == 'godmode/servers/discovery') { } else if ($sec2 == 'godmode/servers/discovery') {
// Discovery task is being created. // Discovery task is being created.
return false; return false;
} else if (empty($sec2) === true) {
// If at main page, show welcome.
return true;
} }
// Check if all other tasks had been completed.
if ($this->checkAllTasks() === true) {
// Finished! do not show.
$this->setStep(WELCOME_FINISHED);
return false;
} }
if ($this->step === WELCOME_FINISHED) { if ($this->step === WELCOME_FINISHED) {