mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
webui: Added validation for Oxidized API URL config (#7978)
* Add http:// to oxidized URLs missing them. * Fixed typo. * Form validation instead of backend fix. * Don't update setting on invalid pattern.
This commit is contained in:
@ -2173,4 +2173,9 @@ label {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.validation:invalid {
|
||||||
|
border-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1260,8 +1260,9 @@ function generate_dynamic_config_panel($title, $config_groups, $items = array(),
|
|||||||
if ($item['type'] == 'checkbox') {
|
if ($item['type'] == 'checkbox') {
|
||||||
$output .= '<input id="' . $item['name'] . '" type="checkbox" name="global-config-check" ' . $config_groups[$item['name']]['config_checked'] . ' data-on-text="Yes" data-off-text="No" data-size="small" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">';
|
$output .= '<input id="' . $item['name'] . '" type="checkbox" name="global-config-check" ' . $config_groups[$item['name']]['config_checked'] . ' data-on-text="Yes" data-off-text="No" data-size="small" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">';
|
||||||
} elseif ($item['type'] == 'text') {
|
} elseif ($item['type'] == 'text') {
|
||||||
|
$pattern = isset($item['pattern']) ? ' required pattern="' . $item['pattern'] . '"' : "";
|
||||||
$output .= '
|
$output .= '
|
||||||
<input id="' . $item['name'] . '" class="form-control" type="text" name="global-config-input" value="' . $config_groups[$item['name']]['config_value'] . '" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">
|
<input id="' . $item['name'] . '" class="form-control validation" type="text" name="global-config-input" value="' . $config_groups[$item['name']]['config_value'] . '" data-config_id="' . $config_groups[$item['name']]['config_id'] . '"' . $pattern . '>
|
||||||
<span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span>
|
<span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span>
|
||||||
';
|
';
|
||||||
} elseif ($item['type'] == 'password') {
|
} elseif ($item['type'] == 'password') {
|
||||||
|
@ -87,22 +87,25 @@ $(document).ready(function() {
|
|||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var config_id = $this.data("config_id");
|
var config_id = $this.data("config_id");
|
||||||
var config_value = $this.val();
|
var config_value = $this.val();
|
||||||
$.ajax({
|
var required = $this.prop('required');
|
||||||
type: 'POST',
|
if (required == false) {
|
||||||
url: 'ajax_form.php',
|
$.ajax({
|
||||||
data: {type: "update-config-item", config_id: config_id, config_value: config_value},
|
type: 'POST',
|
||||||
dataType: "json",
|
url: 'ajax_form.php',
|
||||||
success: function (data) {
|
data: {type: "update-config-item", config_id: config_id, config_value: config_value},
|
||||||
if (data.status == 'ok') {
|
dataType: "json",
|
||||||
toastr.success('Config updated');
|
success: function (data) {
|
||||||
} else {
|
if (data.status == 'ok') {
|
||||||
|
toastr.success('Config updated');
|
||||||
|
} else {
|
||||||
|
toastr.error(data.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
toastr.error(data.message);
|
toastr.error(data.message);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
error: function () {
|
}
|
||||||
toastr.error(data.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Select config ajax calls
|
// Select config ajax calls
|
||||||
|
@ -12,6 +12,7 @@ $oxidized_conf = array(
|
|||||||
array('name' => 'oxidized.url',
|
array('name' => 'oxidized.url',
|
||||||
'descr' => 'URL to your Oxidized API',
|
'descr' => 'URL to your Oxidized API',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
|
'pattern' => '[a-zA-Z0-9]{1,5}://.*',
|
||||||
),
|
),
|
||||||
array('name' => 'oxidized.features.versioning',
|
array('name' => 'oxidized.features.versioning',
|
||||||
'descr' => 'Enable config versioning access',
|
'descr' => 'Enable config versioning access',
|
||||||
|
Reference in New Issue
Block a user