mirror of https://github.com/MISP/MISP
commit
4c02d2de1e
|
@ -120,8 +120,6 @@ class ApiController extends AppController
|
|||
}
|
||||
|
||||
$rest_history_item = array(
|
||||
'org_id' => $this->Auth->user('org_id'),
|
||||
'user_id' => $this->Auth->user('id'),
|
||||
'headers' => $logHeaders,
|
||||
'body' => $historyBody,
|
||||
'url' => $request['url'],
|
||||
|
@ -223,9 +221,7 @@ class ApiController extends AppController
|
|||
$rest_history_item['outcome'] = $response->code;
|
||||
|
||||
$this->loadModel('RestClientHistory');
|
||||
$this->RestClientHistory->create();
|
||||
$this->RestClientHistory->save($rest_history_item);
|
||||
$this->RestClientHistory->cleanup($this->Auth->user('id'));
|
||||
$this->RestClientHistory->insert($this->Auth->user(), $rest_history_item);
|
||||
|
||||
return $viewData;
|
||||
}
|
||||
|
|
|
@ -363,7 +363,7 @@ class AppController extends Controller
|
|||
{
|
||||
// Notifications and homepage is not necessary for AJAX or REST requests
|
||||
$user = $this->Auth->user();
|
||||
if ($user && !$this->_isRest() && !$this->request->is('ajax')) {
|
||||
if ($user && !$this->_isRest() && isset($this->User) && !$this->request->is('ajax')) {
|
||||
$hasNotifications = $this->User->hasNotifications($user);
|
||||
$this->set('hasNotifications', $hasNotifications);
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
App::uses('AppController', 'Controller');
|
||||
|
||||
/**
|
||||
* @property RestClientHistory $RestClientHistory
|
||||
*/
|
||||
class RestClientHistoryController extends AppController
|
||||
{
|
||||
public $components = array(
|
||||
|
@ -37,19 +39,16 @@ class RestClientHistoryController extends AppController
|
|||
}
|
||||
if ($this->_isRest()) {
|
||||
$list = $this->RestClientHistory->find('all', $params);
|
||||
} else {
|
||||
$this->paginate = array_merge($this->paginate, $params);
|
||||
$list = $this->paginate();
|
||||
}
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($list, $this->response->type());
|
||||
} else {
|
||||
$this->set('bookmarked', $bookmarked);
|
||||
$this->set('list', $list);
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
$this->paginate = array_merge($this->paginate, $params);
|
||||
$list = $this->paginate();
|
||||
$this->set('bookmarked', $bookmarked);
|
||||
$this->set('list', array_column($list, 'RestClientHistory'));
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
|
|
|
@ -4,19 +4,35 @@ App::uses('AppModel', 'Model');
|
|||
class RestClientHistory extends AppModel
|
||||
{
|
||||
public $belongsTo = array(
|
||||
'Org' => array(
|
||||
'className' => 'Organisation',
|
||||
'foreignKey' => 'org_id',
|
||||
'order' => array(),
|
||||
'fields' => array('id', 'name', 'uuid')
|
||||
),
|
||||
'User' => array(
|
||||
'className' => 'User',
|
||||
'foreignKey' => 'user_id',
|
||||
'order' => array(),
|
||||
'fields' => array('id', 'email')
|
||||
),
|
||||
);
|
||||
'Org' => array(
|
||||
'className' => 'Organisation',
|
||||
'foreignKey' => 'org_id',
|
||||
'order' => array(),
|
||||
'fields' => array('id', 'name', 'uuid')
|
||||
),
|
||||
'User' => array(
|
||||
'className' => 'User',
|
||||
'foreignKey' => 'user_id',
|
||||
'order' => array(),
|
||||
'fields' => array('id', 'email')
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @param array $user
|
||||
* @param array $history
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function insert(array $user, array $history)
|
||||
{
|
||||
$history['org_id'] = $user['org_id'];
|
||||
$history['user_id'] = $user['id'];
|
||||
|
||||
$this->create();
|
||||
$this->save($history, ['atomic' => false]);
|
||||
$this->cleanup($user['id']);
|
||||
}
|
||||
|
||||
public function cleanup($user_id)
|
||||
{
|
||||
|
@ -35,6 +51,6 @@ class RestClientHistory extends AppModel
|
|||
'NOT' => array(
|
||||
'RestClientHistory.id' => $keepIds
|
||||
)
|
||||
));
|
||||
), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
}
|
||||
echo '</div>';
|
||||
}
|
||||
if (!empty($data['data'])): ?>
|
||||
if (isset($data['data'])): ?>
|
||||
<h3><?= __('Response') ?></h3>
|
||||
<div><span class="bold"><?= __('Queried URL') ?></span>: <?= h($data['url']) ?></div>
|
||||
<div><span class="bold"><?= __('Response code') ?></span>: <?= h($data['code']) ?></div>
|
||||
|
|
|
@ -2,46 +2,46 @@
|
|||
$data_container = $bookmarked ? 'rest_client_bookmarks' : 'rest_client_history';
|
||||
foreach ($list as $k => $item) {
|
||||
$name = '';
|
||||
if (!empty($item['RestClientHistory']['bookmark_name'])) {
|
||||
if (!empty($item['bookmark_name'])) {
|
||||
$name = sprintf(
|
||||
'<span class="bold">%s</span> - ',
|
||||
h($item['RestClientHistory']['bookmark_name'])
|
||||
h($item['bookmark_name'])
|
||||
);
|
||||
}
|
||||
$name .= sprintf(
|
||||
'%s - %s',
|
||||
h($item['RestClientHistory']['http_method']),
|
||||
h($item['http_method']),
|
||||
sprintf(
|
||||
'<a href="#" onClick="loadRestClientHistory(%s, %s);">%s</a>',
|
||||
'<a href="#" onclick="loadRestClientHistory(%s, %s);">%s</a>',
|
||||
$k,
|
||||
$data_container,
|
||||
h($item['RestClientHistory']['url'])
|
||||
h($item['url'])
|
||||
)
|
||||
);
|
||||
$colour = 'green';
|
||||
if (intval($item['RestClientHistory']['outcome']) >= 300) {
|
||||
$colour = 'orange';
|
||||
}
|
||||
if (intval($item['RestClientHistory']['outcome']) >= 400) {
|
||||
if (intval($item['outcome']) >= 400) {
|
||||
$colour = 'red';
|
||||
} else if (intval($item['outcome']) >= 300) {
|
||||
$colour = 'orange';
|
||||
} else {
|
||||
$colour = 'green';
|
||||
}
|
||||
echo sprintf(
|
||||
'<div title="%s" class="useCursorPointer">(%s) %s %s</div>',
|
||||
sprintf(
|
||||
"URL: %s\n\nHeaders: %s\n\nBody: %s",
|
||||
h($item['RestClientHistory']['url']),
|
||||
h($item['RestClientHistory']['headers']),
|
||||
h($item['RestClientHistory']['body'])
|
||||
h($item['url']),
|
||||
h($item['headers']),
|
||||
h($item['body'])
|
||||
),
|
||||
sprintf(
|
||||
'<span class="bold %s">%s</span>',
|
||||
$colour,
|
||||
h($item['RestClientHistory']['outcome'])
|
||||
h($item['outcome'])
|
||||
),
|
||||
$name,
|
||||
sprintf(
|
||||
'<a href="#" class="fa fa-trash black" title="Delete" aria-label="Delete" onclick="removeRestClientHistoryItem(\'%s\');"></a>',
|
||||
h($item['RestClientHistory']['id'])
|
||||
h($item['id'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
/* Codacy comment to notify that baseurl is a read-only global variable. */
|
||||
/* global baseurl */
|
||||
|
||||
|
@ -5,16 +7,12 @@
|
|||
var thread = null;
|
||||
function setApiInfoBox(isTyping) {
|
||||
clearTimeout(thread);
|
||||
if (isTyping) {
|
||||
var delay = 200;
|
||||
} else {
|
||||
var delay = 0;
|
||||
}
|
||||
var $this = $(this);
|
||||
var payload = {
|
||||
"url": extractPathFromUrl($('#ServerUrl').val())
|
||||
};
|
||||
if (payload) {
|
||||
var url = $('#ServerUrl').val();
|
||||
if (url) {
|
||||
var delay = isTyping ? 200 : 0;
|
||||
var payload = {
|
||||
"url": extractPathFromUrl(url)
|
||||
};
|
||||
thread = setTimeout(
|
||||
function() {
|
||||
$.ajax({
|
||||
|
@ -35,16 +33,17 @@ function setApiInfoBox(isTyping) {
|
|||
}
|
||||
|
||||
function loadRestClientHistory(k, data_container) {
|
||||
$('#ServerMethod').val(data_container[k]['RestClientHistory']['http_method']);
|
||||
$('#ServerUseFullPath').prop("checked", data_container[k]['RestClientHistory']['use_full_path']);
|
||||
$('#ServerShowResult').prop("checked", data_container[k]['RestClientHistory']['show_result']);
|
||||
$('#ServerSkipSslValidation').prop("checked", data_container[k]['RestClientHistory']['skip_ssl_validation']);
|
||||
$('#ServerUrl').val(data_container[k]['RestClientHistory']['url']);
|
||||
$('#ServerHeader').val(data_container[k]['RestClientHistory']['headers']);
|
||||
var data = data_container[k];
|
||||
$('#ServerMethod').val(data['http_method']);
|
||||
$('#ServerUseFullPath').prop("checked", data['use_full_path']);
|
||||
$('#ServerShowResult').prop("checked", data['show_result']);
|
||||
$('#ServerSkipSslValidation').prop("checked", data['skip_ssl_validation']);
|
||||
$('#ServerUrl').val(data['url']);
|
||||
$('#ServerHeader').val(data['headers']);
|
||||
toggleRestClientBookmark();
|
||||
cm.setValue(data_container[k]['RestClientHistory']['body'])
|
||||
cm.setValue(data['body'])
|
||||
|
||||
var url = extractPathFromUrl(data_container[k]['RestClientHistory']['url'])
|
||||
var url = extractPathFromUrl(data['url'])
|
||||
$('#TemplateSelect').val(url).trigger("chosen:updated");
|
||||
updateQueryTool(url, false);
|
||||
$('#querybuilder').find('select').trigger('chosen:updated');
|
||||
|
@ -168,10 +167,14 @@ var debounceTimerUpdate;
|
|||
$('#template_description').show();
|
||||
$('#ServerMethod').val('POST');
|
||||
var server_url_changed = $('#ServerUrl').val() != allValidApis[selected_template].url;
|
||||
$('#ServerUrl').val(allValidApis[selected_template].url);
|
||||
$('#ServerUrl').data('urlWithoutParam', selected_template);
|
||||
$('#ServerUrl')
|
||||
.val(allValidApis[selected_template].url)
|
||||
.data('urlWithoutParam', selected_template);
|
||||
|
||||
var body_value = cm.getValue();
|
||||
var body_changed = allValidApis[previously_selected_template] !== undefined ? allValidApis[previously_selected_template].body != body_value : true;
|
||||
var body_changed = allValidApis[previously_selected_template] !== undefined ?
|
||||
JSON.stringify(allValidApis[previously_selected_template].body, null, 4) !== body_value :
|
||||
true;
|
||||
var refreshBody = (body_value === '' || (server_url_changed && !body_changed))
|
||||
if (refreshBody) {
|
||||
var body = JSON.stringify(allValidApis[selected_template].body, null, 4);
|
||||
|
|
Loading…
Reference in New Issue