/** * Deletes the attribute from another Server * TODO move this to a component * * @return bool true if success, error message if failed */ public function deleteAttributeFromServer($uuid, $server, $HttpSocket = null) { $url = $server['Server']['url']; $authkey = $server['Server']['authkey']; if (null == $HttpSocket) { App::uses('SyncTool', 'Tools'); $syncTool = new SyncTool(); $HttpSocket = $syncTool->setupHttpSocket($server); } $request = array('header' => array('Authorization' => $authkey, 'Accept' => 'application/xml', 'Content-Type' => 'application/xml')); $uri = $url . '/attributes/0?uuid=' . $uuid; // LATER validate HTTPS SSL certificate $this->Dns = ClassRegistry::init('Dns'); if ($this->Dns->testipaddress(parse_url($uri, PHP_URL_HOST))) { // TODO NETWORK for now do not know how to catch the following.. // TODO NETWORK No route to host $response = $HttpSocket->delete($uri, array(), $request); // TODO REST, DELETE, no responce needed } }
public function proxyDiagnostics(&$diagnostic_errors) { $proxyStatus = 0; $proxy = Configure::read('Proxy'); if (!empty($proxy['host'])) { App::uses('SyncTool', 'Tools'); $syncTool = new SyncTool(); try { $HttpSocket = $syncTool->setupHttpSocket(); $proxyResponse = $HttpSocket->get('http://www.example.com/'); } catch (Exception $e) { $proxyStatus = 2; } if (empty($proxyResponse) || $proxyResponse->code > 399) { $proxyStatus = 2; } } else { $proxyStatus = 1; } if ($proxyStatus > 1) { $diagnostic_errors++; } return $proxyStatus; }
/** * Delets this specific event to all remote servers * TODO move this to a component(?) */ private function __deleteEventFromServers($uuid) { // get a list of the servers $this->loadModel('Server'); $servers = $this->Server->find('all', array('conditions' => array('Server.push' => true))); // iterate over the servers and upload the event if (empty($servers)) { return; } App::uses('SyncTool', 'Tools'); foreach ($servers as &$server) { $syncTool = new SyncTool(); $HttpSocket = $syncTool->setupHttpSocket($server); $this->Event->deleteEventFromServer($uuid, $server, $HttpSocket); } }
public function fetchPGPKey($email) { App::uses('SyncTool', 'Tools'); $syncTool = new SyncTool(); $HttpSocket = $syncTool->setupHttpSocket(); $response = $HttpSocket->get('https://pgp.mit.edu/pks/lookup?search=' . $email . '&op=index&fingerprint=on'); if ($response->code != 200) { return $response->code; } $string = str_replace(array("\r", "\n"), "", $response->body); $result = preg_match_all('/<pre>pub(.*?)<\\/pre>/', $string, $matches); $results = $this->__extractPGPInfo($matches[1]); return $results; }
/** * Uploads this specific event to all remote servers * TODO move this to a component * * @return bool true if success, false if, partly, failed */ public function uploadEventToServersRouter($id, $passAlong = null) { // make sure we have all the data of the Event $this->id = $id; $this->recursive = 1; $this->read(); $this->data['Event']['locked'] = 1; // get a list of the servers $serverModel = ClassRegistry::init('Server'); $servers = $serverModel->find('all', array('conditions' => array('Server.push' => true))); // iterate over the servers and upload the event if (empty($servers)) { return true; } $uploaded = true; $failedServers = array(); App::uses('SyncTool', 'Tools'); foreach ($servers as &$server) { $syncTool = new SyncTool(); $HttpSocket = $syncTool->setupHttpSocket($server); //Skip servers where the event has come from. if ($passAlong != $server) { $thisUploaded = $this->uploadEventToServer($this->data, $server, $HttpSocket); if (!$thisUploaded) { $uploaded = !$uploaded ? $uploaded : $thisUploaded; $failedServers[] = $server['Server']['url']; } if (isset($this->data['ShadowAttribute'])) { $serverModel->syncProposals($HttpSocket, $server, null, $id, $this); } } } if (!$uploaded) { return $failedServers; } else { return true; } }
public function enqueuePush() { $timestamp = $this->args[0]; $taskId = $this->args[1]; $org = $this->args[2]; $userId = $this->args[3]; $this->Task->id = $taskId; $task = $this->Task->read(null, $taskId); if ($timestamp != $task['Task']['next_execution_time']) { return; } if ($task['Task']['timer'] > 0) { $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueuePush', $userId, $taskId); } $this->User->recursive = -1; $user = $this->User->read(array('id', 'org', 'email'), $userId); $servers = $this->Server->find('all', array('recursive' => -1, 'conditions' => array('push' => 1))); $count = count($servers); foreach ($servers as $k => $server) { $this->Job->create(); $data = array('worker' => 'default', 'job_type' => 'push', 'job_input' => 'Server: ' . $server['Server']['id'], 'retries' => 0, 'org' => $org, 'process_id' => 'Part of scheduled push', 'message' => 'Pushing.'); $this->Job->save($data); $jobId = $this->Job->id; App::uses('SyncTool', 'Tools'); $syncTool = new SyncTool(); $HttpSocket = $syncTool->setupHttpSocket($server); $result = $this->Server->push($server['Server']['id'], 'full', $jobId, $HttpSocket, $user['User']['email']); } $this->Task->id = $task['Task']['id']; $this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.'); }
/** * Deletes this specific attribute from all remote servers * TODO move this to a component(?) */ private function __deleteAttributeFromServers($uuid) { // get a list of the servers with push active $this->loadModel('Server'); $servers = $this->Server->find('all', array('conditions' => array('push' => 1))); // iterate over the servers and upload the attribute if (empty($servers)) { return; } App::uses('SyncTool', 'Tools'); foreach ($servers as &$server) { $syncTool = new SyncTool(); $HttpSocket = $syncTool->setupHttpSocket($server); $this->Attribute->deleteAttributeFromServer($uuid, $server, $HttpSocket); } }
private function __checkVersion() { if (!$this->_isSiteAdmin()) { throw new MethodNotAllowedException(); } App::uses('SyncTool', 'Tools'); $syncTool = new SyncTool(); try { $HttpSocket = $syncTool->setupHttpSocket(); $response = $HttpSocket->get('https://api.github.com/repos/MISP/MISP/tags'); $tags = $response->body; } catch (Exception $e) { return false; } if ($response->isOK() && !empty($tags)) { $json_decoded_tags = json_decode($tags); // find the latest version tag in the v[major].[minor].[hotfix] format for ($i = 0; $i < count($json_decoded_tags); $i++) { if (preg_match('/^v[0-9]+\\.[0-9]+\\.[0-9]+$/', $json_decoded_tags[$i]->name)) { break; } } return $this->Server->checkVersion($json_decoded_tags[$i]->name); } else { return false; } }