2013-11-06 10:52:18 +01:00
|
|
|
<?php
|
|
|
|
App::uses('AppModel', 'Model');
|
|
|
|
/**
|
|
|
|
* Job Model
|
|
|
|
*
|
|
|
|
* @property Job $Job
|
|
|
|
*/
|
|
|
|
class Job extends AppModel {
|
2016-06-04 01:08:16 +02:00
|
|
|
|
2016-01-10 19:45:33 +01:00
|
|
|
public $belongsTo = array(
|
|
|
|
'Org' => array(
|
|
|
|
'className' => 'Organisation',
|
|
|
|
'foreignKey' => 'org_id',
|
|
|
|
'order' => array(),
|
|
|
|
'fields' => array('id', 'name', 'uuid')
|
|
|
|
),
|
|
|
|
);
|
2016-06-04 01:08:16 +02:00
|
|
|
|
2015-04-20 13:32:34 +02:00
|
|
|
public function beforeValidate($options = array()) {
|
|
|
|
parent::beforeValidate();
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
if (empty($this->data['Job']['id'])) {
|
|
|
|
$this->data['Job']['date_created'] = $date;
|
|
|
|
$this->data['Job']['date_modified'] = $date;
|
|
|
|
} else {
|
|
|
|
$this->data['Job']['date_modified'] = $date;
|
|
|
|
}
|
|
|
|
}
|
2016-06-04 01:08:16 +02:00
|
|
|
|
2016-01-10 19:45:33 +01:00
|
|
|
public function cache($type, $user, $target, $jobOrg = null) {
|
2014-01-02 15:51:41 +01:00
|
|
|
$extra = null;
|
|
|
|
$extra2 = null;
|
|
|
|
$shell = 'Event';
|
|
|
|
$this->create();
|
|
|
|
$data = array(
|
|
|
|
'worker' => 'cache',
|
|
|
|
'job_type' => 'cache_' . $type,
|
|
|
|
'job_input' => $target,
|
|
|
|
'status' => 0,
|
|
|
|
'retries' => 0,
|
2015-04-20 11:46:55 +02:00
|
|
|
'org_id' => $user['org_id'],
|
2014-01-02 15:51:41 +01:00
|
|
|
'message' => 'Fetching events.',
|
|
|
|
);
|
|
|
|
if ($type === 'md5' || $type === 'sha1') {
|
|
|
|
$extra = $type;
|
|
|
|
$type = 'hids';
|
|
|
|
}
|
|
|
|
if ($type === 'csv_all' || $type === 'csv_sig') {
|
|
|
|
$extra = $type;
|
|
|
|
$type = 'csv';
|
|
|
|
}
|
|
|
|
if ($type === 'suricata' || $type === 'snort') {
|
|
|
|
$extra = $type;
|
|
|
|
$type = 'nids';
|
2016-01-10 19:45:33 +01:00
|
|
|
$extra2 = isset($user['nids_sid']) ? $user['nids_sid'] : 0;
|
2014-01-02 15:51:41 +01:00
|
|
|
}
|
2015-05-20 16:23:42 +02:00
|
|
|
if ($type === 'rpz') $extra = $type;
|
2014-01-02 15:51:41 +01:00
|
|
|
$this->save($data);
|
|
|
|
$id = $this->id;
|
|
|
|
$process_id = CakeResque::enqueue(
|
|
|
|
'cache',
|
|
|
|
$shell . 'Shell',
|
2015-04-20 11:46:55 +02:00
|
|
|
array('cache' . $type, $user['id'], $id, $extra, $extra2),
|
2014-01-02 15:51:41 +01:00
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->saveField('process_id', $process_id);
|
|
|
|
return $id;
|
|
|
|
}
|
2013-11-06 10:52:18 +01:00
|
|
|
}
|