/** * Execute the controller. * * @return boolean * * @since 1.0 * @throws \RuntimeException */ public function execute() { $input = $this->getInput(); $data = ['php_version' => $input->getRaw('php_version'), 'db_version' => $input->getRaw('db_version'), 'cms_version' => $input->getRaw('cms_version'), 'unique_id' => $input->getString('unique_id'), 'db_type' => $input->getString('db_type'), 'server_os' => $input->getString('server_os')]; // Backup the original POST before manipulating/validating data $originalData = $data; // Validate the submitted data $data['php_version'] = $this->checkPHPVersion($data['php_version']); $data['cms_version'] = $this->checkCMSVersion($data['cms_version']); $data['db_type'] = $this->checkDatabaseType($data['db_type']); $data['db_version'] = $this->validateVersionNumber($data['db_version']); // We require at a minimum a unique ID and the CMS version if (empty($data['unique_id']) || empty($data['cms_version'])) { $this->getApplication()->getLogger()->info('Missing required data from request.', ['postData' => $originalData]); throw new \RuntimeException('There was an error storing the data.', 401); } // If the below data does not pass tests, we do not accept the POST if ($data['php_version'] === false || $data['cms_version'] === false || $data['db_type'] === false || $data['db_version'] === false) { $this->getApplication()->getLogger()->info('The request data is invalid.', ['postData' => $originalData]); throw new \RuntimeException('Invalid data submission.', 401); } $this->model->save((object) $data); $response = ['error' => false, 'message' => 'Data saved successfully']; $this->getApplication()->setBody(json_encode($response)); return true; }
/** * Execute the controller. * * @return boolean * * @since 1.0 * @throws \RuntimeException */ public function execute() { $input = $this->getInput(); $data = ['php_version' => $input->getRaw('php_version'), 'db_version' => $input->getRaw('db_version'), 'cms_version' => $input->getRaw('cms_version')]; // Filter the submitted version data. $data = array_map(function ($value) { return preg_replace('/[^0-9.-]/', '', $value); }, $data); $data['unique_id'] = $input->getString('unique_id'); $data['db_type'] = $input->getString('db_type'); $data['server_os'] = $input->getString('server_os'); // We require at a minimum a unique ID and the CMS version if (empty($data['unique_id']) || empty($data['cms_version'])) { throw new \RuntimeException('There was an error storing the data.', 401); } $this->model->save((object) $data); $response = ['error' => false, 'message' => 'Data saved successfully']; $this->getApplication()->setBody(json_encode($response)); return true; }
/** * Method to render the view. * * @return string The rendered view. * * @since 1.0 */ public function render() { $items = $this->model->getItems(); $data = ['php_version' => [], 'db_type' => [], 'db_version' => [], 'cms_version' => [], 'server_os' => []]; foreach ($items as $item) { foreach ($data as $key => $value) { if (!isset($data[$key][$item->{$key}])) { $data[$key][$item->{$key}] = 0; } $data[$key][$item->{$key}]++; } } $tmp = []; foreach ($data as $key => $value) { foreach ($value as $name => $count) { $tmp[$key][] = ['name' => $name, 'count' => $count]; } } $data = $tmp; $data['total'] = count($items); $this->addData('data', $data); return parent::render(); }