mirror of https://github.com/MISP/MISP
new: [REST client] Templating system added to the rest client
parent
780cc86ca8
commit
5e87558fbb
|
@ -1,8 +1,18 @@
|
|||
<div class="servers form">
|
||||
<div style="position:absolute;right:40px;width:300px;top:90px;">
|
||||
<label for="TemplateSelect">Templates</label>
|
||||
<?php
|
||||
$options = '<option value="">None</option>';
|
||||
foreach ($allValidApis as $endpoint_url => $endpoint_data) {
|
||||
$options .= sprintf('<option value="%s">%s</option>', $endpoint_url, $endpoint_data['api_name']);
|
||||
}
|
||||
echo sprintf('<select id="TemplateSelect">%s</select>', $options);
|
||||
?>
|
||||
<div id="apiInfo"></div>
|
||||
</div>
|
||||
<?php echo $this->Form->create('Server');?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('REST client');?></legend>
|
||||
<div style="position:absolute;right:40px;width:300px;" id="apiInfo"></div>
|
||||
<?php
|
||||
echo $this->Form->input('method', array(
|
||||
'label' => __('Relative path to query'),
|
||||
|
@ -47,6 +57,7 @@
|
|||
));
|
||||
?>
|
||||
<div class="input clear" style="width:100%;">
|
||||
<div id="template_description" style="display:none;width:700px;" class="alert alert-error">Fill out the JSON template above, make sure to replace all placeholder values. Fields with the value "optional" can be removed.</div>
|
||||
<?php
|
||||
echo $this->Form->submit('Run query', array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
|
@ -88,7 +99,34 @@
|
|||
?>
|
||||
<script type="text/javascript">
|
||||
// tooltips
|
||||
var thread = null;
|
||||
function setApiInfoBox() {
|
||||
clearTimeout(thread);
|
||||
var $this = $(this);
|
||||
var payload = {
|
||||
"url": $('#ServerUrl').val()
|
||||
};
|
||||
if (payload) {
|
||||
thread = setTimeout(
|
||||
function() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/servers/getApiInfo',
|
||||
data: payload,
|
||||
success:function (data, textStatus) {
|
||||
$('#apiInfo').html(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
1000
|
||||
);
|
||||
} else {
|
||||
$('#apiInfo').empty();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
var allValidApis = <?php echo json_encode($allValidApis); ?>;
|
||||
insertRawRestResponse();
|
||||
$('.format-toggle-button').bind('click', function() {
|
||||
$('#rest-response-container').empty();
|
||||
|
@ -100,29 +138,17 @@
|
|||
insertJSONRestResponse();
|
||||
}
|
||||
});
|
||||
var thread = null;
|
||||
$('#ServerUrl').keyup(function() {
|
||||
clearTimeout(thread);
|
||||
var $this = $(this);
|
||||
var payload = {
|
||||
"url": $('#ServerUrl').val()
|
||||
};
|
||||
if (payload) {
|
||||
thread = setTimeout(
|
||||
function() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/servers/getApiInfo',
|
||||
data: payload,
|
||||
success:function (data, textStatus) {
|
||||
$('#apiInfo').html(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
1000
|
||||
);
|
||||
} else {
|
||||
$('#apiInfo').empty();
|
||||
setApiInfoBox();
|
||||
});
|
||||
$('#TemplateSelect').change(function() {
|
||||
var selected_template = $('#TemplateSelect').val();
|
||||
if (selected_template !== '') {
|
||||
setApiInfoBox();
|
||||
$('#template_description').show();
|
||||
$('#ServerMethod').val('POST');
|
||||
$('#ServerUrl').val(allValidApis[selected_template].url);
|
||||
$('#ServerBody').val(allValidApis[selected_template].body);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue