mirror of https://github.com/MISP/MISP
Merge branch 'develop' of github.com:MISP/MISP into feature-workflow-improvement1
commit
5ce142ed0f
|
@ -758,6 +758,8 @@ class AttributesController extends AppController
|
|||
if (count($existingAttribute) && !$existingAttribute['Attribute']['deleted']) {
|
||||
$this->request->data['Attribute']['id'] = $existingAttribute['Attribute']['id'];
|
||||
$this->request->data['Attribute']['event_id'] = $existingAttribute['Attribute']['event_id'];
|
||||
$this->request->data['Attribute']['object_id'] = $existingAttribute['Attribute']['object_id'];
|
||||
$this->request->data['Attribute']['uuid'] = $existingAttribute['Attribute']['uuid'];
|
||||
$skipTimeCheck = false;
|
||||
if (!isset($this->request->data['Attribute']['timestamp'])) {
|
||||
$this->request->data['Attribute']['timestamp'] = $dateObj->getTimestamp();
|
||||
|
@ -790,7 +792,7 @@ class AttributesController extends AppController
|
|||
}
|
||||
$this->Attribute->Object->updateTimestamp($existingAttribute['Attribute']['object_id']);
|
||||
} else {
|
||||
$result = $this->Attribute->save($this->request->data);
|
||||
$result = $this->Attribute->save($this->request->data, array('fieldList' => Attribute::EDITABLE_FIELDS));
|
||||
if ($result) {
|
||||
$this->Attribute->AttributeTag->handleAttributeTags($this->Auth->user(), $this->request->data['Attribute'], $attribute['Event']['id'], $capture=true);
|
||||
}
|
||||
|
@ -2848,7 +2850,7 @@ class AttributesController extends AppController
|
|||
|
||||
$event = $this->Attribute->Event->find('first', [
|
||||
'recursive' => -1,
|
||||
'conditons' => ['Event.id' => $attribute['Attribute']['event_id']]
|
||||
'conditions' => ['Event.id' => $attribute['Attribute']['event_id']]
|
||||
]);
|
||||
if (!$this->_isRest()) {
|
||||
$this->Attribute->Event->insertLock($this->Auth->user(), $attribute['Attribute']['event_id']);
|
||||
|
|
|
@ -629,6 +629,10 @@ class BackgroundJobsTool
|
|||
];
|
||||
}
|
||||
|
||||
if (!isset($this->settings['supervisor_host'])) {
|
||||
throw new RuntimeException("Required option `supervisor_host` for BackgroundJobsTool is not set.");
|
||||
}
|
||||
|
||||
$host = null;
|
||||
if (substr($this->settings['supervisor_host'], 0, 5) === 'unix:') {
|
||||
if (!defined('CURLOPT_UNIX_SOCKET_PATH')) {
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
class QueryTool
|
||||
{
|
||||
const PDO_MAP = array(
|
||||
'integer' => PDO::PARAM_INT,
|
||||
'float' => PDO::PARAM_STR,
|
||||
'boolean' => PDO::PARAM_BOOL,
|
||||
'string' => PDO::PARAM_STR,
|
||||
'text' => PDO::PARAM_STR,
|
||||
);
|
||||
|
||||
public function quickDelete($table, $field, $value, $model)
|
||||
{
|
||||
$db = $model->getDataSource();
|
||||
$connection = $db->getConnection();
|
||||
if (in_array($db->config['datasource'], ['Database/Mysql', 'Database/MysqlObserver', 'Database/MysqlExtended'])) {
|
||||
$query = $connection->prepare('DELETE FROM ' . $table . ' WHERE ' . $field . ' = :value');
|
||||
} elseif ($db->config['datasource'] == 'Database/Postgres' ) {
|
||||
$query = $connection->prepare('DELETE FROM "' . $table . '" WHERE "' . $field . '" = :value');
|
||||
}
|
||||
$query->bindValue(':value', $value, self::PDO_MAP[$db->introspectType($value)]);
|
||||
$query->execute();
|
||||
}
|
||||
}
|
|
@ -7,6 +7,16 @@ App::uses('Mysql', 'Model/Datasource/Database');
|
|||
*/
|
||||
class MysqlExtended extends Mysql
|
||||
{
|
||||
/**
|
||||
* Output MD5 as binary, that is faster and uses less memory
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function cacheMethodHasher($value)
|
||||
{
|
||||
return md5($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and generates an SQL statement from an array. Handles final clean-up before conversion.
|
||||
*
|
||||
|
@ -87,16 +97,15 @@ class MysqlExtended extends Mysql
|
|||
* @return string|null Rendered SQL expression to be run, otherwise null.\
|
||||
* @see DboSource::renderStatement()
|
||||
*/
|
||||
|
||||
public function renderStatement($type, $data)
|
||||
{
|
||||
if ($type === 'select' && $data['indexHint'] != null) {
|
||||
if ($type === 'select') {
|
||||
extract($data);
|
||||
$having = !empty($having) ? " $having" : '';
|
||||
return trim("SELECT {$fields} FROM {$table} {$alias} {$indexHint} {$joins} {$conditions} {$group}{$having} {$order} {$limit}{$lock}");
|
||||
} else {
|
||||
return parent::renderStatement($type, $data);
|
||||
$lock = !empty($lock) ? " $lock" : '';
|
||||
return rtrim("SELECT {$fields} FROM {$table} {$alias} {$indexHint} {$joins} {$conditions} {$group}{$having} {$order} {$limit}{$lock}");
|
||||
}
|
||||
return parent::renderStatement($type, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,12 +114,93 @@ class MysqlExtended extends Mysql
|
|||
* @param string|null $useIndexHint USE INDEX hint
|
||||
* @return string
|
||||
*/
|
||||
private function __buildIndexHint($useIndexHint = null): string
|
||||
private function __buildIndexHint($useIndexHint = null): ?string
|
||||
{
|
||||
$index = '';
|
||||
if (isset($useIndexHint)) {
|
||||
$index = 'USE INDEX ' . $useIndexHint;
|
||||
return isset($useIndexHint) ? ('USE INDEX ' . $useIndexHint) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce memory usage for insertMulti
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $fields
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
public function insertMulti($table, $fields, $values)
|
||||
{
|
||||
$table = $this->fullTableName($table);
|
||||
$holder = implode(',', array_fill(0, count($fields), '?'));
|
||||
$fields = implode(',', array_map([$this, 'name'], $fields));
|
||||
$pdoMap = [
|
||||
'integer' => PDO::PARAM_INT,
|
||||
'float' => PDO::PARAM_STR,
|
||||
'boolean' => PDO::PARAM_BOOL,
|
||||
'string' => PDO::PARAM_STR,
|
||||
'text' => PDO::PARAM_STR
|
||||
];
|
||||
$columnMap = [];
|
||||
foreach ($values[key($values)] as $key => $val) {
|
||||
if (is_int($val)) {
|
||||
$columnMap[$key] = PDO::PARAM_INT;
|
||||
} elseif (is_bool($val)) {
|
||||
$columnMap[$key] = PDO::PARAM_BOOL;
|
||||
} else {
|
||||
$type = $this->introspectType($val);
|
||||
$columnMap[$key] = $pdoMap[$type];
|
||||
}
|
||||
}
|
||||
return $index;
|
||||
|
||||
$sql = "INSERT INTO $table ($fields) VALUES ";
|
||||
$sql .= implode(',', array_fill(0, count($values), "($holder)"));
|
||||
$statement = $this->_connection->prepare($sql);
|
||||
$valuesList = array();
|
||||
$i = 1;
|
||||
foreach ($values as $value) {
|
||||
foreach ($value as $col => $val) {
|
||||
if ($this->fullDebug) {
|
||||
$valuesList[] = $val;
|
||||
}
|
||||
$statement->bindValue($i, $val, $columnMap[$col]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$result = $statement->execute();
|
||||
$statement->closeCursor();
|
||||
if ($this->fullDebug) {
|
||||
$this->logQuery($sql, $valuesList);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function value($data, $column = null, $null = true)
|
||||
{
|
||||
// Fast check if data is int, then return value
|
||||
if (is_int($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// No need to quote bool values
|
||||
if (is_bool($data)) {
|
||||
return $data ? '1' : '0';
|
||||
}
|
||||
|
||||
// No need to call expensive array_map
|
||||
if (is_array($data) && !empty($data)) {
|
||||
$output = [];
|
||||
foreach ($data as $d) {
|
||||
if (is_int($d)) {
|
||||
$output[] = $d;
|
||||
} else {
|
||||
$output[] = parent::value($d, $column);
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
return parent::value($data, $column, $null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1147,6 +1147,10 @@ class Event extends AppModel
|
|||
return $data[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $event
|
||||
* @return bool
|
||||
*/
|
||||
public function quickDelete(array $event)
|
||||
{
|
||||
$id = (int)$event['Event']['id'];
|
||||
|
@ -1156,7 +1160,7 @@ class Event extends AppModel
|
|||
'fields' => array('Thread.id'),
|
||||
'recursive' => -1
|
||||
));
|
||||
$thread_id = !empty($thread) ? $thread['Thread']['id'] : false;
|
||||
$thread_id = !empty($thread) ? (int)$thread['Thread']['id'] : false;
|
||||
$relations = array(
|
||||
array(
|
||||
'table' => 'attributes',
|
||||
|
@ -1231,10 +1235,17 @@ class Event extends AppModel
|
|||
)
|
||||
);
|
||||
}
|
||||
App::uses('QueryTool', 'Tools');
|
||||
$queryTool = new QueryTool();
|
||||
|
||||
$db = $this->getDataSource();
|
||||
$db->begin();
|
||||
$connection = $db->getConnection();
|
||||
foreach ($relations as $relation) {
|
||||
$queryTool->quickDelete($relation['table'], $relation['foreign_key'], $relation['value'], $this);
|
||||
$query = $connection->prepare('DELETE FROM ' . $db->name($relation['table']) . ' WHERE ' . $db->name($relation['foreign_key']) . ' = :value');
|
||||
$query->bindValue(':value', $relation['value'], PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
}
|
||||
if (!$db->commit()) {
|
||||
return false;
|
||||
}
|
||||
$this->set($event);
|
||||
return $this->delete(null, false);
|
||||
|
|
|
@ -303,34 +303,42 @@ class AadAuthenticateAuthenticate extends BaseAuthenticate
|
|||
'Authorization' => 'Bearer ' . $authdata["access_token"]
|
||||
]
|
||||
];
|
||||
|
||||
$has_next_page = true;
|
||||
$url = self::$auth_provider_user . "/v1.0/me/memberOf";
|
||||
while ($has_next_page) {
|
||||
$response = (new HttpSocket())->get($url, array(), $options);
|
||||
|
||||
$response = (new HttpSocket())->get($url, null, $options);
|
||||
|
||||
if (!$response->isOk()) {
|
||||
$this->_log("warning", "Error received during user group data fetch.");
|
||||
$this->_logHttpError("debug", $url, $response);
|
||||
return false;
|
||||
}
|
||||
|
||||
$groupdata = json_decode($response->body, true); //This should now contain your logged on user memberOf (groups) information
|
||||
if (isset($groupdata["error"])) {
|
||||
$this->_log("warning", "Group data fetch contained an error.");
|
||||
$this->_log("debug", "Response: " . json_encode($groupdata["error"]));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now check if the user has any of the MISP AAD groups enabled
|
||||
foreach ($groupdata["value"] as $group) {
|
||||
$groupdisplayName = $group["displayName"];
|
||||
if ($groupdisplayName == self::$misp_siteadmin) {
|
||||
return self::$misp_siteadmin;
|
||||
if (!$response->isOk()) {
|
||||
$this->_log("warning", "Error received during user group data fetch.");
|
||||
$this->_logHttpError("debug", $url, $response);
|
||||
return false;
|
||||
}
|
||||
if ($groupdisplayName == self::$misp_orgadmin) {
|
||||
return self::$misp_orgadmin;
|
||||
|
||||
$groupdata = json_decode($response->body, true); //This should now contain your logged on user memberOf (groups) information
|
||||
if (isset($groupdata["error"])) {
|
||||
$this->_log("warning", "Group data fetch contained an error.");
|
||||
$this->_log("debug", "Response: " . json_encode($groupdata["error"]));
|
||||
return false;
|
||||
}
|
||||
if ($groupdisplayName == self::$misp_user) {
|
||||
return self::$misp_user;
|
||||
|
||||
// Now check if the user has any of the MISP AAD groups enabled
|
||||
foreach ($groupdata["value"] as $group) {
|
||||
$groupdisplayName = $group["displayName"];
|
||||
if ($groupdisplayName == self::$misp_siteadmin) {
|
||||
return self::$misp_siteadmin;
|
||||
}
|
||||
if ($groupdisplayName == self::$misp_orgadmin) {
|
||||
return self::$misp_orgadmin;
|
||||
}
|
||||
if ($groupdisplayName == self::$misp_user) {
|
||||
return self::$misp_user;
|
||||
}
|
||||
}
|
||||
|
||||
$has_next_page = array_key_exists("@odata.nextLink", $groupdata);
|
||||
if ($has_next_page) {
|
||||
$url = $groupdata["@odata.nextLink"];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b0ffb843b0bb69ea94d3ce9318f5123612b4ccc9
|
||||
Subproject commit 258515f9a8836ce7f49f00242f45d987fac43b24
|
|
@ -1 +1 @@
|
|||
Subproject commit fc12a106f5481e466275799de71e29dd7cf764f7
|
||||
Subproject commit aa251b6a4006372e66f3bf5e946111f6d5f6a2d6
|
|
@ -478,7 +478,7 @@ $(document).ready( function() {
|
|||
return false;
|
||||
}
|
||||
|
||||
$(document).on('keydown', function(e) {
|
||||
$("#chart").on('keydown', function(e) {
|
||||
if (e.which == 69) {
|
||||
if (highlighted == undefined) {
|
||||
showPane(root['nodes'][0], 'selected');
|
||||
|
@ -522,7 +522,7 @@ $(document).ready( function() {
|
|||
});
|
||||
*/
|
||||
|
||||
$(document).on('keydown', function(e) {
|
||||
$("#chart").on('keydown', function(e) {
|
||||
if (e.which == 88) {
|
||||
e.preventDefault();
|
||||
if (e.ctrlKey) {
|
||||
|
|
|
@ -9116,5 +9116,5 @@
|
|||
"uuid": false
|
||||
}
|
||||
},
|
||||
"db_version": "94"
|
||||
"db_version": "95"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue