/** * 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(); }
/** * Get update info * * @param boolean $live * @return \ArrayObject */ public function getUpdates($live = true) { $updates = ['phirecms' => null, 'modules' => []]; if ($live) { $headers = ['Authorization: ' . base64_encode('phire-updater-' . 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://updates.phirecms.org/latest/phirecms', [CURLOPT_HTTPHEADER => $headers]); $curl->send(); if ($curl->getCode() == 200) { $json = json_decode($curl->getBody(), true); $updates['phirecms'] = $json['version']; } $modules = Table\Modules::findAll(); if ($modules->hasRows()) { foreach ($modules->rows() as $module) { $curl = new Curl('http://updates.phirecms.org/latest/' . $module->name, [CURLOPT_HTTPHEADER => $headers]); $curl->send(); if ($curl->getCode() == 200) { $json = json_decode($curl->getBody(), true); $updates['modules'][$module->name] = $json['version']; } } } } return new \ArrayObject($updates, \ArrayObject::ARRAY_AS_PROPS); }
public function index() { $this->console->write(); $this->console->write(' Fetching: ' . $this->console->colorize('phirecms/phirecms', Console::BOLD_CYAN) . '...', false); // Get latest version of phirecms $url = $this->urls['phirecms'] . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret; $curl = new Curl($url, $this->options); $curl->send(); if ($curl->getCode() == 200) { $body = json_decode($curl->getBody(), true); $this->json['phirecms'] = isset($body['tag_name']) ? $body['tag_name'] : $this->current['phirecms']; $this->console->write(); } else { $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.'); } // Get latest versions of modules foreach ($this->modules as $module) { // Get version $this->console->write(' Fetching: ' . $this->console->colorize($module, Console::BOLD_CYAN) . '...', false); $url = str_replace('[{module}]', $module, $this->urls['module']) . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret; $curl = new Curl($url, $this->options); $curl->send(); if ($curl->getCode() == 200) { $body = json_decode($curl->getBody(), true); if (isset($body['tag_name'])) { $this->json['modules'][$module] = $body['tag_name']; // Get file if (!isset($this->current['modules'][$module]) || isset($this->current['modules'][$module]) && version_compare($this->current['modules'][$module], $this->json['modules'][$module]) < 0) { $this->console->write(' Downloading...', false); if (file_exists(__DIR__ . '/../../public/releases/modules/' . $module . '.zip')) { unlink(__DIR__ . '/../../public/releases/modules/' . $module . '.zip'); } $file = str_replace(['[{file}]', '[{tag_name}]'], [$module, $body['tag_name']], $this->urls['file']); file_put_contents(__DIR__ . '/../../public/releases/modules/' . $module . '-' . $body['tag_name'] . '.zip', file_get_contents($file)); chmod(__DIR__ . '/../../public/releases/modules/' . $module . '-' . $body['tag_name'] . '.zip', 0777); } $this->console->write(' Complete.'); } } else { $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.'); } } $this->console->write(); // Get latest versions of themes foreach ($this->themes as $theme) { // Get version $this->console->write(' Fetching: ' . $this->console->colorize($theme, Console::BOLD_CYAN) . '...', false); $url = str_replace('[{theme}]', $theme, $this->urls['theme']) . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret; $curl = new Curl($url, $this->options); $curl->send(); if ($curl->getCode() == 200) { $body = json_decode($curl->getBody(), true); if (isset($body['tag_name'])) { $this->json['themes'][$theme] = $body['tag_name']; // Get file if (!isset($this->current['themes'][$theme]) || isset($this->current['themes'][$theme]) && version_compare($this->current['themes'][$theme], $this->json['themes'][$theme]) < 0) { $this->console->write(' Downloading...', false); if (file_exists(__DIR__ . '/../../public/releases/themes/' . $theme . '.zip')) { unlink(__DIR__ . '/../../public/releases/themes/' . $theme . '.zip'); } $file = str_replace(['[{file}]', '[{tag_name}]'], [$theme, $body['tag_name']], $this->urls['file']); file_put_contents(__DIR__ . '/../../public/releases/themes/' . $theme . '-' . $body['tag_name'] . '.zip', file_get_contents($file)); chmod(__DIR__ . '/../../public/releases/themes/' . $theme . '-' . $body['tag_name'] . '.zip', 0777); } $this->console->write(' Complete.'); } } else { $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.'); } } // Write new 'updates.json' file if (file_exists(__DIR__ . '/../../data/updates.json')) { unlink(__DIR__ . '/../../data/updates.json'); } file_put_contents(__DIR__ . '/../../data/updates.json', json_encode($this->json, JSON_PRETTY_PRINT)); $this->console->write(); $this->console->write(' Done!'); $this->console->write(); }