-
Notifications
You must be signed in to change notification settings - Fork 2
/
wazuh-config.php
67 lines (54 loc) · 2.31 KB
/
wazuh-config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
if (!isset($oreon)) {
exit();
}
$path = './modules/centsoc/';
$attrsTextLong = array("size" => "50");
$attrsTextVeryLong = array("size" => "200");
// Création du formulaire de configuration avec les différents champs
$form = new HTML_QuickFormCustom('Form', 'post', '?p=' . $p);
$form->addElement('header', 'title', _('Centreon Wazuh configuration'));
$form->addElement('text', 'centreon_wazuh_manager_url', _('Wazuh URL'), $attrsTextVeryLong);
$form->addElement('text', 'centreon_wazuh_manager_user', _('Wazuh user login'), $attrsTextLong);
$form->addElement('password', 'centreon_wazuh_manager_password', _('Wazuh password'), $attrsTextLong);
$form->addElement('submit', 'submitC', _("Save"));
$form->addElement('reset', 'reset', _("Reset"));
// Validation du formulaire => enregistrement des valeurs dans la DB
if ($form->validate()) {
$values = $form->getSubmitValues();
$queryInsert = 'UPDATE `options` SET `value` = "%s" WHERE `key` = "%s"';
$pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_wazuh_manager_user']), 'centreon_wazuh_manager_user'));
$pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_wazuh_manager_password']), 'centreon_wazuh_manager_password'));
$pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_wazuh_manager_url']), 'centreon_wazuh_manager_url'));
}
// Récupération des valeurs par défaut
if (!isset($values)) {
$values = array();
$query = 'SELECT `key`, `value` FROM `options` '
. 'WHERE `key` IN '
. '("centreon_wazuh_manager_user", "centreon_wazuh_manager_password", "centreon_wazuh_manager_url")';
try {
$res = $pearDB->query($query);
} catch (\PDOException $e) {
// do nothing to keep same behaviour as previous version
}
while ($row = $res->fetch()) {
$values[$row['key']] = $row['value'];
}
}
$form->setDefaults($values);
/*
*
* Smarty template Init
*
*/
$tpl = new Smarty();
$tpl = initSmartyTpl($path, $tpl);
$tpl->assign('p', $p);
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl, true);
$renderer->setRequiredTemplate('{$label} <font color="red" size="1">*</font>');
$renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->display("wazuh-config.ihtml");
?>