Filter email options based on backend in Alert settings (#9461)

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
This commit is contained in:
Tony Murray
2018-11-19 15:04:33 -06:00
committed by Neil Lathwood
parent ceea9d4981
commit ec69150099
2 changed files with 105 additions and 67 deletions

View File

@@ -1271,7 +1271,7 @@ function generate_dynamic_config_panel($title, $config_groups, $items = array(),
if (!empty($items)) {
foreach ($items as $item) {
$output .= '
<div class="form-group has-feedback">
<div class="form-group has-feedback ' . (isset($item['class']) ? $item['class'] : '') . '">
<label for="' . $item['name'] . '"" class="col-sm-4 control-label">' . $item['descr'] . ' </label>
<div data-toggle="tooltip" title="' . $config_groups[$item['name']]['config_descr'] . '" class="toolTip fa fa-fw fa-lg fa-question-circle"></div>
<div class="col-sm-4">
@@ -1297,7 +1297,7 @@ function generate_dynamic_config_panel($title, $config_groups, $items = array(),
';
} elseif ($item['type'] == 'select') {
$output .= '
<select id="' . $config_groups[$item['name']]['name'] . '" class="form-control" name="global-config-select" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">
<select id="' . ($config_groups[$item['name']]['name'] ?: $item['name']) . '" class="form-control" name="global-config-select" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">
';
if (!empty($item['options'])) {
foreach ($item['options'] as $option) {

View File

@@ -13,6 +13,7 @@
*/
use LibreNMS\Authentication\LegacyAuth;
use LibreNMS\Config;
$no_refresh = true;
@@ -336,71 +337,94 @@ $general_conf = array(
]
);
$mail_conf = array(
array('name' => 'alert.transports.mail',
'descr' => 'Enable email alerting',
'type' => 'checkbox',
),
array('name' => 'email_backend',
'descr' => 'How to deliver mail',
'options' => $config['email_backend_options'],
'type' => 'select',
),
array('name' => 'email_user',
'descr' => 'From name',
'type' => 'text',
),
array('name' => 'email_from',
'descr' => 'From email address',
'type' => 'text',
'pattern' => '[a-zA-Z0-9_\-\.\+]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,18}',
),
array('name' => 'email_html',
'descr' => 'Use HTML emails',
'type' => 'checkbox',
),
array('name' => 'email_sendmail_path',
'descr' => 'Sendmail path',
'type' => 'text',
),
array('name' => 'email_smtp_host',
'descr' => 'SMTP Host',
'type' => 'text',
'pattern' => '[a-zA-Z0-9_\-\.]+',
),
array('name' => 'email_smtp_port',
'descr' => 'SMTP Port',
'type' => 'numeric',
'required' => true,
),
array('name' => 'email_smtp_timeout',
'descr' => 'SMTP Timeout',
'type' => 'numeric',
'required' => true,
),
array('name' => 'email_smtp_secure',
'descr' => 'SMTP Secure',
'type' => 'select',
'options' => $config['email_smtp_secure_options'],
),
array('name' => 'email_auto_tls',
'descr' => 'SMTP Auto TLS Support',
'type' => 'select',
'options' => array('true', 'false'),
),
array('name' => 'email_smtp_auth',
'descr' => 'SMTP Authentication',
'type' => 'checkbox',
),
array('name' => 'email_smtp_username',
'descr' => 'SMTP Authentication Username',
'type' => 'text',
),
array('name' => 'email_smtp_password',
'descr' => 'SMTP Authentication Password',
'type' => 'password',
),
);
$mail_conf = [
[
'name' => 'alert.transports.mail',
'descr' => 'Enable email alerting',
'type' => 'checkbox',
],
[
'name' => 'email_backend',
'descr' => 'How to deliver mail',
'options' => Config::get('email_backend_options', ['mail', 'sendmail', 'smtp']),
'type' => 'select',
],
[
'name' => 'email_user',
'descr' => 'From name',
'type' => 'text',
],
[
'name' => 'email_from',
'descr' => 'From email address',
'type' => 'text',
'pattern' => '[a-zA-Z0-9_\-\.\+]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,18}',
],
[
'name' => 'email_html',
'descr' => 'Use HTML emails',
'type' => 'checkbox',
],
[
'name' => 'email_sendmail_path',
'descr' => 'Sendmail path',
'type' => 'text',
'class' => 'sendmail-form',
],
[
'name' => 'email_smtp_host',
'descr' => 'SMTP Host',
'type' => 'text',
'pattern' => '[a-zA-Z0-9_\-\.]+',
'class' => 'smtp-form',
],
[
'name' => 'email_smtp_port',
'descr' => 'SMTP Port',
'type' => 'numeric',
'class' => 'smtp-form',
'required' => true,
],
[
'name' => 'email_smtp_timeout',
'descr' => 'SMTP Timeout',
'type' => 'numeric',
'class' => 'smtp-form',
'required' => true,
],
[
'name' => 'email_smtp_secure',
'descr' => 'SMTP Secure',
'type' => 'select',
'class' => 'smtp-form',
'options' => Config::get('email_smtp_secure_options', ['', 'tls', 'ssl']),
],
[
'name' => 'email_auto_tls',
'descr' => 'SMTP Auto TLS Support',
'type' => 'select',
'class' => 'smtp-form',
'options' => ['true', 'false'],
],
[
'name' => 'email_smtp_auth',
'descr' => 'SMTP Authentication',
'type' => 'checkbox',
'class' => 'smtp-form',
],
[
'name' => 'email_smtp_username',
'descr' => 'SMTP Authentication Username',
'type' => 'text',
'class' => 'smtp-form',
],
[
'name' => 'email_smtp_password',
'descr' => 'SMTP Authentication Password',
'type' => 'password',
'class' => 'smtp-form',
],
];
echo '
<div class="panel-group" id="accordion">
@@ -1745,6 +1769,20 @@ echo '
});
});
$('#email_backend').change(function () {
var type = this.value;
if (type === 'sendmail') {
$('.smtp-form').hide();
$('.sendmail-form').show();
} else if (type === 'smtp') {
$('.sendmail-form').hide();
$('.smtp-form').show();
} else {
$('.smtp-form').hide();
$('.sendmail-form').hide();
}
}).change(); // trigger initially
apiIndex = 0;
// Add API config