chg: [cleanup] Taking out the trash

- old unused functions removed
pull/5616/head
iglocska 2020-02-10 16:10:55 +01:00
parent af881189e5
commit 5a29964924
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 0 additions and 290 deletions

View File

@ -6,8 +6,6 @@ class EventShell extends AppShell
{
public $uses = array('Event', 'Post', 'Attribute', 'Job', 'User', 'Task', 'Whitelist', 'Server', 'Organisation');
public $tasks = array('ConfigLoad');
public function doPublish()
{
$this->ConfigLoad->execute();
@ -91,294 +89,6 @@ class EventShell extends AppShell
return true;
}
public function cachexml()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
$user = $this->User->getAuthUser($userId);
$this->Job->id = $id;
// TEMP: change to passing an options array with the user!!
$eventIds = $this->Event->fetchEventIds($user);
$eventCount = count($eventIds);
$dir = new Folder(APP . 'tmp/cached_exports/xml', true, 0750);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.xml' . '.ADMIN.xml');
} else {
$file = new File($dir->pwd() . DS . 'misp.xml' . '.' . $user['Organisation']['name'] . '.xml');
}
App::uses('XMLConverterTool', 'Tools');
$converter = new XMLConverterTool();
$file->write('<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<response>');
if (!empty($eventIds)) {
foreach ($eventIds as $k => $eventId) {
$temp = $this->Event->fetchEvent($user, array('eventid' => $eventId['Event']['id'], 'includeAttachments' => Configure::read('MISP.cached_attachments')));
$file->append($converter->convert($temp[0], $user['Role']['perm_site_admin']) . PHP_EOL);
$this->Job->saveField('progress', ($k+1) / $eventCount *100);
}
}
$file->append('<xml_version>' . $this->Event->mispVersion . '</xml_version>');
$file->append('</response>' . PHP_EOL);
$file->close();
$timeDelta = (time()-$timeStart);
$this->Job->saveField('progress', 100);
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachejson()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
$user = $this->User->getAuthUser($userId);
$this->Job->id = $id;
// TEMP: change to passing an options array with the user!!
$eventIds = $this->Event->fetchEventIds($user);
$eventCount = count($eventIds);
$dir = new Folder(APP . 'tmp/cached_exports/json', true, 0750);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.json' . '.ADMIN.json');
} else {
$file = new File($dir->pwd() . DS . 'misp.json' . '.' . $user['Organisation']['name'] . '.json');
}
App::uses('JSONConverterTool', 'Tools');
$converter = new JSONConverterTool();
$file->write('{"response":[');
foreach ($eventIds as $k => $eventId) {
$result = $this->Event->fetchEvent($user, array('eventid' => $eventId['Event']['id'], 'includeAttachments' => Configure::read('MISP.cached_attachments')));
$file->append($converter->convert($result[0]));
if ($k < count($eventIds) -1 ) {
$file->append(',');
}
$this->Job->saveField('progress', ($k+1) / $eventCount *100);
}
$file->append(']}');
$file->close();
$timeDelta = (time()-$timeStart);
$this->Job->saveField('progress', 100);
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachestix()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$id = $this->args[1];
$user = $this->User->getAuthUser($userId);
$this->Job->id = $id;
$dir = new Folder(APP . 'tmp/cached_exports/stix', true, 0750);
if ($user['Role']['perm_site_admin']) {
$stixFilePath = $dir->pwd() . DS . 'misp.stix' . '.ADMIN.xml';
} else {
$stixFilePath = $dir->pwd() . DS . 'misp.stix' . '.' . $user['Organisation']['name'] . '.xml';
}
$result = $this->Event->stix(false, false, Configure::read('MISP.cached_attachments'), $user, 'xml', false, false, false, $id, true);
$timeDelta = (time()-$timeStart);
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
if ($result['success']) {
rename($result['data'], $stixFilePath);
unlink($result['data']);
$this->Job->saveField('progress', 100);
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
} else {
$log = ClassRegistry::init('Log');
$log->create();
$log->createLogEntry($user, 'export', 'STIX export failed', $result['message']);
throw new InternalErrorException();
}
}
public function cachehids()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
$id = $this->args[1];
$this->Job->id = $id;
$extra = $this->args[2];
$this->Job->saveField('progress', 1);
$rules = $this->Attribute->hids($user, $extra, '', false, false, false, $id);
$this->Job->saveField('progress', 80);
$dir = new Folder(APP . DS . '/tmp/cached_exports/' . $extra, true, 0750);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.' . $extra . '.ADMIN.txt');
} else {
$file = new File($dir->pwd() . DS . 'misp.' . $extra . '.' . $user['Organisation']['name'] . '.txt');
}
$file->write('');
if (!empty($rules)) {
foreach ($rules as $rule) {
$file->append($rule . PHP_EOL);
}
} else {
$file->append("No exportable " . $type . "s found. " . PHP_EOL);
}
$file->close();
$timeDelta = (time()-$timeStart);
$this->Job->saveField('progress', '100');
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cacherpz()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
$id = $this->args[1];
$this->Job->id = $id;
$extra = $this->args[2];
$this->Job->saveField('progress', 1);
$eventIds = $this->Attribute->Event->fetchEventIds($user, false, false, false, true);
$values = array();
$eventCount = count($eventIds);
if ($eventCount) {
foreach ($eventIds as $k => $eventId) {
$values = array_merge_recursive($values, $this->Attribute->rpz($user, false, $eventId));
if ($k % 10 == 0) $this->Job->saveField('progress', $k * 80 / $eventCount);
}
}
$this->Job->saveField('progress', 80);
$dir = new Folder(APP . DS . '/tmp/cached_exports/' . $extra, true, 0750);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.rpz.ADMIN.txt');
} else {
$file = new File($dir->pwd() . DS . 'misp.rpz.' . $user['Organisation']['name'] . '.txt');
}
App::uses('RPZExport', 'Export');
$rpzExport = new RPZExport();
$rpzSettings = array();
$lookupData = array('policy', 'walled_garden', 'ns', 'email', 'serial', 'refresh', 'retry', 'expiry', 'minimum_ttl', 'ttl', 'ns_alt');
foreach ($lookupData as $v) {
$tempSetting = Configure::read('Plugin.RPZ_' . $v);
if (isset($tempSetting)) $rpzSettings[$v] = Configure::read('Plugin.RPZ_' . $v);
else $rpzSettings[$v] = $this->Server->serverSettings['Plugin']['RPZ_' . $v]['value'];
}
$file->write($rpzExport->export($values, $rpzSettings));
$file->close();
$timeDelta = (time()-$timeStart);
$this->Job->saveField('progress', '100');
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachecsv()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
$id = $this->args[1];
$this->Job->id = $id;
$extra = $this->args[2];
if ($extra == 'csv_all') $ignore = 1;
else $ignore = 0;
// TEMP: change to passing an options array with the user!!
$eventIds = $this->Event->fetchEventIds($user);
$eventCount = count($eventIds);
$attributes = array();
$dir = new Folder(APP . 'tmp/cached_exports/' . $extra, true, 0750);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.' . $extra . '.ADMIN.csv');
} else {
$file = new File($dir->pwd() . DS . 'misp.' . $extra . '.' . $user['Organisation']['name'] . '.csv');
}
$file->write('uuid,event_id,category,type,value,to_ids,date' . PHP_EOL);
foreach ($eventIds as $k => $eventId) {
$chunk = "";
$attributes = $this->Event->csv($user, $eventId['Event']['id'], $ignore);
$attributes = $this->Whitelist->removeWhitelistedFromArray($attributes, true);
foreach ($attributes as $attribute) {
$chunk .= $attribute['Attribute']['uuid'] . ',' . $attribute['Attribute']['event_id'] . ',' . $attribute['Attribute']['category'] . ',' . $attribute['Attribute']['type'] . ',' . $attribute['Attribute']['value'] . ',' . intval($attribute['Attribute']['to_ids']) . ',' . $attribute['Attribute']['timestamp'] . PHP_EOL;
}
$file->append($chunk);
if ($k % 10 == 0) {
$this->Job->saveField('progress', $k / $eventCount * 80);
}
}
$file->close();
$timeDelta = (time()-$timeStart);
$this->Job->saveField('progress', '100');
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachetext()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
$id = $this->args[1];
$this->Job->id = $id;
$types = array_keys($this->Attribute->typeDefinitions);
$typeCount = count($types);
$dir = new Folder(APP . DS . '/tmp/cached_exports/text', true, 0750);
foreach ($types as $k => $type) {
$final = $this->Attribute->text($user, $type);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.text_' . $type . '.ADMIN.txt');
} else {
$file = new File($dir->pwd() . DS . 'misp.text_' . $type . '.' . $user['Organisation']['name'] . '.txt');
}
$file->write('');
foreach ($final as $attribute) {
$file->append($attribute['Attribute']['value'] . PHP_EOL);
}
$file->close();
$this->Job->saveField('progress', $k / $typeCount * 100);
}
$timeDelta = (time()-$timeStart);
$this->Job->saveField('progress', 100);
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachenids()
{
$this->ConfigLoad->execute();
$timeStart = time();
$userId = $this->args[0];
$user = $this->User->getAuthUser($userId);
$id = $this->args[1];
$this->Job->id = $id;
$format = $this->args[2];
$eventIds = array_values($this->Event->fetchEventIds($user, false, false, false, true));
$eventCount = count($eventIds);
$dir = new Folder(APP . DS . '/tmp/cached_exports/' . $format, true, 0750);
if ($user['Role']['perm_site_admin']) {
$file = new File($dir->pwd() . DS . 'misp.' . $format . '.ADMIN.rules');
} else {
$file = new File($dir->pwd() . DS . 'misp.' . $format . '.' . $user['Organisation']['name'] . '.rules');
}
$file->write('');
foreach ($eventIds as $k => $eventId) {
if ($k == 0) {
$temp = $this->Attribute->nids($user, $format, $eventId);
} else {
$temp = $this->Attribute->nids($user, $format, $eventId, true);
}
foreach ($temp as $line) {
$file->append($line . PHP_EOL);
}
if ($k % 10 == 0) {
$this->Job->saveField('progress', $k / $eventCount * 80);
}
}
$file->close();
$timeDelta = time()-$timeStart;
$this->Job->saveField('progress', '100');
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
$this->Job->saveField('date_modified', date("Y-m-d H:i:s"));
}
public function cachebro()
{
$this->ConfigLoad->execute();