From 07f5140771388c9e0c8a99b0dd2e5d950bdb173b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 14 Oct 2021 15:16:42 +1100 Subject: moving h-source subdir out. --- Application/Controllers/SearchController.php | 267 +++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 Application/Controllers/SearchController.php (limited to 'Application/Controllers/SearchController.php') diff --git a/Application/Controllers/SearchController.php b/Application/Controllers/SearchController.php new file mode 100644 index 0000000..1892f70 --- /dev/null +++ b/Application/Controllers/SearchController.php @@ -0,0 +1,267 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class SearchController extends BaseController +{ + + public function __construct($model, $controller, $queryString) + { + + $this->_topMenuClasses['search'] = " class='currentitem'"; + + parent::__construct($model, $controller, $queryString); + + $this->model('HardwareModel'); + + $data['title'] = 'search - '.Website::$generalName; + $this->append($data); + } + + public function form($lang = 'en') + { + $this->cleverLoad('form'); + $this->right(); + } + + public function results($lang = 'en') + { + Params::$nullQueryValue = 'undef'; + + $argKeys = array( + 'page:forceNat' => 1, + 'action:sanitizeAlphanum' => 'search', + 'type:sanitizeString' => 'notebook', + 'model:sanitizeString' => 'undef', + ); + + $this->setArgKeys($argKeys); + + $this->shift(1); + + if (strcmp($this->viewArgs['action'],'search') === 0) + { + Params::$whereClauseSymbolArray = array('like'); + + $this->m['HardwareModel']->logicalOperators = array('AND','OR'); + + $whereClause = array( + 'type' => $this->viewArgs['type'], + 'level1' => array( + 'model' => "like '%".$this->viewArgs['model']."%'", + 'other_names' => "like '%".$this->viewArgs['model']."%'", + ), +// 'model' => "like '%".$this->viewArgs['model']."%'", +// 'other_names' => "like '%".$this->viewArgs['model']."%'", + '-deleted' => "no", + 'cleared' => "no", + ); + + $recordNumber = $this->m['HardwareModel']->clear()->where($whereClause)->orderBy("id_hard desc")->rowNumber(); + + $data['recordNumber'] = $recordNumber; + + //load the Pages helper + $this->helper('Pages',$this->controller.'/results/'.$this->lang,'page'); + $page = $this->viewArgs['page']; + //set the limit clause + $limit = $this->h['Pages']->getLimit($page,$recordNumber,10); + + $data['table'] = $this->m['HardwareModel']->clear()->select('id_hard,model,type,comm_year,other_names')->where($whereClause)->limit($limit)->orderBy("id_hard desc")->send(); +// echo $this->m['HardwareModel']->getQuery(); + + $data['pageList'] = $this->h['Pages']->render($page-3,7); + + $this->append($data); + $this->cleverLoad('results'); + $this->right(); + } + + } + + public function pciid($lang = 'en') + { + if (isset($_POST['pciid'])) + { + $clean['pciid'] = $this->request->post('pciid','','sanitizePciid'); + $data['table'] = $this->m['HardwareModel']->clear()->select()->where(array('pci_id'=>$clean['pciid']))->send(); + $data['recordNumber'] = 0; + + $this->append($data); + $this->cleverLoad('results'); + $this->right(); + } + } + + public function lspci($lang = 'en') + { + if (isset($_POST['lspci'])) + { + $data['notice'] = null; + + $lspci = $this->request->post('lspci','','sanitizeHtml'); + $lspciResult = array(); + $flag = true; + + if (strlen($lspci)<50000) + { + $lspci = nl2br($lspci); + $lspciArray = explode('
',$lspci); + reset($lspciArray); + while(current($lspciArray) !== false) + { + $item = current($lspciArray); + if( preg_match( '/Slot\:(.*)([0-9a-zA-Z]{2}\:[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1})/i', $item ) ) +// if (stristr($item,'Slot')) + { + $temp = array(); +// class + if (next($lspciArray) !== false) + { + $item = trim(current($lspciArray)); + if( preg_match( '/Class\:(.*)\[(.*)\]/i', $item, $matches ) ) + { + $temp['className'] = sanitizeAll($matches[1]); + $temp['classId'] = sanitizeAll($matches[2]); + } + else + { + $temp['className'] = "unknown"; + $temp['classId'] = "unknown"; + } + } + else + { + $flag = false; + break; + } + +// vendor + if (next($lspciArray) !== false) + { + $item = trim(current($lspciArray)); + if( preg_match( '/Vendor\:(.*)\[(.*)\]/i', $item, $matches ) ) + { + $temp['vendorName'] = sanitizeAll($matches[1]); + $temp['vendorId'] = sanitizeAll($matches[2]); + } + else + { + $temp['vendorName'] = "unknown"; + $temp['vendorId'] = "unknown"; + } + } + else + { + $flag = false; + break; + } + +// device + if (next($lspciArray) !== false) + { + $item = trim(current($lspciArray)); + if( preg_match( '/Device\:(.*)\[(.*)\]/i', $item, $matches ) ) + { + $temp['deviceName'] = sanitizeAll($matches[1]); + $temp['deviceId'] = sanitizeAll($matches[2]); + } + else + { + $temp['deviceName'] = "unknown"; + $temp['deviceId'] = "unknown"; + } + } + else + { + $flag = false; + break; + } + + $lspciResult[] = $temp; + } + next($lspciArray); + } + if (count($lspciResult) === 0 or $flag === false) + { + $data['notice'] = "
".gtext('the text submitted by you does not seem to be the lspci -vmmnn output. Please check the text and try again')."
\n"; + $flag = false; + } + } + else + { + $data['notice'] = "
the lspci output is too long
\n"; + $flag = false; + } + + $data['flag'] = $flag; + + $data['table'] = array(); + $data['notFoundDevices'] = array(); + + if ($flag) + { + $lspciFiltered = array(); + $vendorIDProductIDArray = array(); + foreach ($lspciResult as $device) + { + if (array_key_exists($device['classId'],Hardware::$deviceClasses)) + { + $vendorIDProductIDArray[] = sanitizePciid($device['vendorId'].":".$device['deviceId']); + $lspciFiltered[] = $device; + } + } + if (count($vendorIDProductIDArray) > 0) + { + $whereString = "'".implode("','",$vendorIDProductIDArray)."'"; + $data['table'] = $this->m['HardwareModel']->select()->where(array('pci_id'=>"in($whereString)"))->send(); + + $foundPciidArray = $this->m['HardwareModel'] + ->select('pci_id') + ->where(array('pci_id'=>"in($whereString)")) + ->toList('pci_id') + ->send(); + + $notFoundDevices = array(); //list of devices not found inside the database + $notFoundPciIdList = array(); //to check that it does not take the same device twice + + foreach ($lspciFiltered as $device) + { + if (!in_array($device['vendorId'].":".$device['deviceId'],$foundPciidArray)) + { + if (!in_array($device['vendorId'].":".$device['deviceId'],$notFoundPciIdList)) + { + $notFoundDevices[] = $device; + $notFoundPciIdList[] = $device['vendorId'].":".$device['deviceId']; + } + } + } + + $data['notFoundDevices'] = $notFoundDevices; + } + + } + $this->append($data); + $this->cleverLoad('lspci_results'); + $this->right(); + } + } +} \ No newline at end of file -- cgit v1.2.3