From 5be1e17bcee7d4bf590a1c8008a62863619e8574 Mon Sep 17 00:00:00 2001 From: Cristian Bell Date: Tue, 27 Sep 2016 15:53:43 +0200 Subject: [PATCH] Revert "fix: missing new TLDs in free text import, solves #1149 (#1574)" This reverts commit e3bb9d3a4204ca00931e3f77afc318aaf292382e. --- app/Controller/EventsController.php | 4 +--- app/Lib/Tools/ComplexTypeTool.php | 21 ++++------------- app/Model/Warninglist.php | 22 ------------------ app/View/Events/resolved_attributes.ctp | 31 ++++++++++--------------- 4 files changed, 18 insertions(+), 60 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 6fa88719a..f93a30e33 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -2795,9 +2795,7 @@ class EventsController extends AppController { if ($this->request->is('post')) { App::uses('ComplexTypeTool', 'Tools'); $complexTypeTool = new ComplexTypeTool(); - $this->loadModel('Warninglist'); - $IANATLDentries = $this->Warninglist->getAllIANAEntries(); - $resultArray = $complexTypeTool->checkComplexRouter($this->request->data['Attribute']['value'], 'FreeText', $IANATLDentries); + $resultArray = $complexTypeTool->checkComplexRouter($this->request->data['Attribute']['value'], 'FreeText'); foreach ($resultArray as $key => $r) { $temp = array(); foreach ($r['types'] as $type) { diff --git a/app/Lib/Tools/ComplexTypeTool.php b/app/Lib/Tools/ComplexTypeTool.php index f796ce5a5..769f5ede9 100644 --- a/app/Lib/Tools/ComplexTypeTool.php +++ b/app/Lib/Tools/ComplexTypeTool.php @@ -10,7 +10,7 @@ class ComplexTypeTool { '/\.+/' => '.' ); - public function checkComplexRouter($input, $type, $IANATLDentries) { + public function checkComplexRouter($input, $type) { switch ($type) { case 'File': return $this->checkComplexFile($input); @@ -19,7 +19,7 @@ class ComplexTypeTool { return $this->checkComplexCnC($input); break; case 'FreeText': - return $this->checkFreeText($input, $IANATLDentries); + return $this->checkFreeText($input); break; default: return false; @@ -73,7 +73,7 @@ class ComplexTypeTool { return array_values($array); } - public function checkFreeText($input, $IANATLDentries) { + public function checkFreeText($input) { $iocArray = preg_split("/\r\n|\n|\r|\s|\s+|,|;/", $input); $quotedText = explode('"', $input); foreach ($quotedText as $k => $temp) { @@ -93,7 +93,7 @@ class ComplexTypeTool { $ioc = trim($ioc, ','); $ioc = preg_replace('/\p{C}+/u', '', $ioc); if (empty($ioc)) continue; - $typeArray = $this->__resolveType($ioc, $IANATLDentries); + $typeArray = $this->__resolveType($ioc); if ($typeArray === false) continue; $temp = $typeArray; if (!isset($temp['value'])) $temp['value'] = $ioc; @@ -112,9 +112,8 @@ class ComplexTypeTool { 128 => array('single' => array('sha512'), 'composite' => array('filename|sha512')) ); - private function __resolveType($input, $IANATLDentries) { + private function __resolveType($input) { $input = trim($input); - // check for composite (|) attributes if (strpos($input, '|')) { $compositeParts = explode('|', $input); if (count($compositeParts) == 2) { @@ -157,16 +156,6 @@ class ComplexTypeTool { // check for domain name, hostname, filename if (strpos($inputRefanged, '.') !== false) { $temp = explode('.', $inputRefanged); - // check for the new TLDs as known by IANA (if the Warninglists are not empty) - if (!empty($IANATLDentries)) { - $stringEnd = $temp[count($temp)-1]; - if (in_array($stringEnd, $IANATLDentries)) { - $types = array('filename', 'domain'); - if (count($temp) > 2) - $types[] = 'url'; - return array('types' => $types, 'to_ids' => true, 'default_type' => 'filename', 'merge_categories' => true); - } - } // TODO: use a more flexible matching approach, like the one below (that still doesn't support non-ASCII domains) //if (filter_var($input, FILTER_VALIDATE_URL)) { if (preg_match('/^([-\pL\pN]+\.)+([a-z][a-z]|biz|cat|com|edu|gov|int|mil|net|org|pro|tel|aero|arpa|asia|coop|info|jobs|mobi|name|museum|travel)(:[0-9]{2,5})?$/iu', $inputRefanged)) { diff --git a/app/Model/Warninglist.php b/app/Model/Warninglist.php index b60be1c8f..ef47eac83 100644 --- a/app/Model/Warninglist.php +++ b/app/Model/Warninglist.php @@ -236,26 +236,4 @@ class Warninglist extends AppModel{ if (in_array($value, $listValues)) return true; return false; } - - public function getAllIANAEntries() { - $result = $this->find('first', array( - 'conditions' => array('Warninglist.name' => 'TLDs as known by IANA', 'enabled' => 1), - 'recursive' => -1, - 'contain' => array( - 'WarninglistEntry' => array( - 'fields' => array('WarninglistEntry.value') - ) - ) - )); - if ((count($result))>0) { - return array_map( - function ($element) { - return strtolower($element['value']); - }, - $result['WarninglistEntry'] - ); - } else { - return []; - } - } } diff --git a/app/View/Events/resolved_attributes.ctp b/app/View/Events/resolved_attributes.ctp index c1c543b2f..fd01e7b67 100644 --- a/app/View/Events/resolved_attributes.ctp +++ b/app/View/Events/resolved_attributes.ctp @@ -29,7 +29,7 @@ Similar Attributes Category Type - IDS + IDS Comment Actions @@ -55,7 +55,7 @@ echo $this->Form->input('Attribute' . $k . 'Value', array( 'label' => false, 'value' => h($item['value']), - 'style' => 'padding:0;height:20px;margin-bottom:0;width:90%;', + 'style' => 'padding:0px;height:20px;margin-bottom:0px;width:90%;', 'div' => false )); ?> @@ -98,24 +98,17 @@ } ?> -