/** * Index action method * * @return void */ public function index() { // Complete one-click updating if ($this->request->getQuery('update') == 2) { clearstatcache(); $updater = new Updater(); $updater->runPost(); $this->redirect(BASE_PATH . APP_URI . '/update/complete'); // Else, compare versions } else { if (version_compare(\Phire\Module::VERSION, $this->sess->updates->phirecms) < 0) { // Get updates via one-click updating if ($this->request->getQuery('update') == 1 && is_writable(__DIR__ . '/../../../../') && is_writable(__DIR__ . '/../../../..' . APP_PATH)) { $updater = new Updater(); $updater->getUpdate(); $this->redirect(BASE_PATH . APP_URI . '/update?update=2'); // Else, use FTP to get updates } else { $this->prepareView('phire/update.phtml'); $this->view->title = 'Update Phire'; $this->view->url = 'http://updates.phirecms.org/releases/phire/phirecms.zip'; $this->view->phire_update_version = $this->sess->updates->phirecms; // Detect one-click updating if (is_writable(__DIR__ . '/../../../../') && is_writable(__DIR__ . '/../../../..' . APP_PATH)) { $this->view->form = false; } else { $fields = $this->application->config()['forms']['Phire\\Form\\Update']; $fields[1]['resource']['value'] = 'phirecms'; $this->view->form = new Form\Update($fields); } // Start update via FTP if ($this->view->form !== false && $this->request->isPost()) { $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $fields = $this->view->form->getFields(); $curl = new Curl('http://updates.phirecms.org/fetch/' . $fields['resource']); $curl->setFields($fields); $curl->setPost(true); $curl->send(); $json = json_decode($curl->getBody(), true); if ($curl->getCode() == 401) { $this->view->form = '<h4 class="error">' . $json['error'] . '</h4>'; } else { clearstatcache(); $updater = new Updater(); $updater->runPost(); $this->redirect(BASE_PATH . APP_URI . '/update/complete'); } } } $this->send(); } } else { $this->redirect(BASE_PATH . APP_URI); } } }
/** * Set the field values * * @param array $values * @return Update */ public function setFieldValues(array $values = null) { parent::setFieldValues($values); if ($_POST && null !== $this->resource) { $curl = new Curl('http://updates.phirecms.org/test'); $curl->setFields($this->getFields()); $curl->setPost(true); $curl->send(); if ($curl->getCode() == 401) { $json = json_decode($curl->getBody(), true); $this->getElement('ftp_address')->addValidator(new Validator\NotEqual($this->ftp_address, $json['error'])); } } return $this; }
/** * Send installation stats * * @param string $name * @param string $version * @return void */ protected function sendStats($name, $version) { $headers = ['Authorization: ' . base64_encode('phire-stats-' . time()), 'User-Agent: ' . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0')]; $curl = new Curl('http://stats.phirecms.org/theme', [CURLOPT_HTTPHEADER => $headers]); $curl->setPost(true); $curl->setFields(['name' => $name, 'version' => $version, 'domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'os' => PHP_OS, 'server' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '', 'php' => PHP_VERSION, 'db' => DB_INTERFACE . (DB_INTERFACE == 'pdo' ? ' (' . DB_TYPE . ')' : '')]); $curl->send(); }