/** * Compares the hashes of a list of files with what is actually on the disk. * * @param array $hashes [file] => hash * * @return array List of errors, [file] => missing or mismatch */ public static function compareHashes(array $hashes) { $cwd = getcwd(); chdir(XenForo_Application::getInstance()->getRootDir()); $errors = array(); foreach ($hashes as $file => $hash) { if (file_exists($file)) { if (XenForo_Helper_Hash::getFileContentsHash(file_get_contents($file)) != $hash) { $errors[$file] = 'mismatch'; } } else { $errors[$file] = 'missing'; } } chdir($cwd); return $errors; }
public function actionIndex() { if ($this->_getUpgradeModel()->getNewestUpgradeVersionId() > XenForo_Application::$versionId) { return $this->responseError(new XenForo_Phrase('upgrade_found_newer_than_version')); } if ($this->_getUpgradeModel()->getLatestUpgradeVersionId() === XenForo_Application::$versionId && XenForo_Application::get('options')->currentVersionId >= XenForo_Application::$versionId) { return $this->responseView('XenForo_Install_View_Upgrade_Current', 'upgrade_current'); } if (class_exists('XenForo_Install_Data_FileSums')) { $hashes = XenForo_Install_Data_FileSums::getHashes(); foreach ($hashes as $key => $hash) { if (!preg_match('#^(\\./)?(install/|library/XenForo/Install/|library/XenForo/Application.php)#', $key)) { unset($hashes[$key]); } } $fileErrors = XenForo_Helper_Hash::compareHashes($hashes); $hashesExist = true; } else { $fileErrors = array(); $hashesExist = false; } $db = XenForo_Application::getDb(); return $this->responseView('XenForo_Install_View_Upgrade_Start', 'upgrade_start', array('targetVersion' => XenForo_Application::$version, 'errors' => $this->_getInstallModel()->getRequirementErrors($db), 'warnings' => $this->_getInstallModel()->getRequirementWarnings($db), 'isCliRecommended' => $this->_getUpgradeModel()->isCliUpgradeRecommended(), 'cliCommand' => $this->_getUpgradeModel()->getCliCommand(), 'fileErrors' => $fileErrors, 'hashesExist' => $hashesExist)); }
$installModel = XenForo_Model::create('XenForo_Install_Model_Install'); $cliHelper = new XenForo_Install_CliHelper(); if ($upgradeModel->getNewestUpgradeVersionId() > XenForo_Application::$versionId) { $cliHelper->triggerFatalError('An upgrade was found for a version of XenForo that is newer than the uploaded files. Please reupload all of the files for the new version and reload this page.'); } if ($upgradeModel->getLatestUpgradeVersionId() === XenForo_Application::$versionId && XenForo_Application::get('options')->currentVersionId >= XenForo_Application::$versionId) { //$cliHelper->triggerFatalError('You are already running the latest version.'); } if (class_exists('XenForo_Install_Data_FileSums')) { $hashes = XenForo_Install_Data_FileSums::getHashes(); foreach ($hashes as $key => $hash) { if (!preg_match('#^(\\./)?(install/|library/XenForo/Install/|library/XenForo/Application.php)#', $key)) { unset($hashes[$key]); } } $fileErrors = XenForo_Helper_Hash::compareHashes($hashes); $hashesExist = true; } else { $fileErrors = array(); $hashesExist = false; } if ($fileErrors) { $cliHelper->printWarning("Some files do not contain the expected contents:\n\t" . implode("\n\t", array_keys($fileErrors)) . "\nContinue only if you're sure."); } $lastCompletedVersion = $upgradeModel->getLatestUpgradeVersionId(); $cliHelper->printMessage(sprintf("Current version: %s\nUpgrade target: %s (%s)", $lastCompletedVersion, XenForo_Application::$versionId, XenForo_Application::$version), 2); do { $response = $cliHelper->askQuestion('Are you sure you want to upgrade? [y/n]'); if ($cliHelper->validateYesNoAnswer($response, $continue)) { if (!$continue) { $cliHelper->triggerFatalError("You chose to not continue with the upgrade. Process terminated.");
public function actionFileCheck() { if ($this->_request->isPost()) { $hashes = XenForo_Install_Data_FileSums::getHashes(); XenForo_CodeEvent::fire('file_health_check', array($this, &$hashes)); $errors = XenForo_Helper_Hash::compareHashes($hashes); $viewParams = array('errors' => $errors, 'hashes' => $hashes); } else { $viewParams = array('form' => true); } return $this->responseView('XenForo_ViewAdmin_Tools_FileCheck', 'tools_file_check', $viewParams); }
public function run($addonId, $path) { $addOn = XenForo_Model::create('XenForo_Model_AddOn')->getAddonById($addonId); $fileExport = new ExportHelper('addon'); $rootNode = $fileExport->getRootNode(); $rootNode->setAttribute('addon_id', $addOn['addon_id']); $rootNode->setAttribute('title', $addOn['title']); $rootNode->setAttribute('version_string', 'Build: {@revision}'); $rootNode->setAttribute('version_id', '{@revision}'); $rootNode->setAttribute('url', $addOn['url']); $rootNode->setAttribute('install_callback_class', $addOn['install_callback_class']); $rootNode->setAttribute('install_callback_method', $addOn['install_callback_method']); $rootNode->setAttribute('uninstall_callback_class', $addOn['uninstall_callback_class']); $rootNode->setAttribute('uninstall_callback_method', $addOn['uninstall_callback_method']); $fileExport->save($path . '/addon.xml'); $exports = array('admin_navigation', array('admin_permissions', 'XenForo_Model_Admin'), 'admin_templates', array('code_events', false, 'appendEventsAddOnXml'), array('code_event_listeners', 'XenForo_Model_CodeEvent', 'appendEventListenersAddOnXml'), array('cron', false, 'appendCronEntriesAddOnXml'), 'email_templates', array('options', false, false, 'optiongroups'), 'permissions', 'phrases', array('route_prefixes', 'XenForo_Model_RoutePrefix', 'appendPrefixesAddOnXml'), 'templates'); foreach ($exports as $export) { $model = false; $method = false; $name = false; if (is_array($export)) { if (!empty($export[1])) { $model = $export[1]; } if (!empty($export[2])) { $method = $export[2]; } if (!empty($export[3])) { $name = $export[3]; } $export = $export[0]; } $camel = Zend_Filter::filterStatic($export, 'Word_UnderscoreToCamelCase'); if (!$model) { $model = 'XenForo_Model_' . $camel; if (substr($model, strlen($model) - 1) == 's') { $model = substr($model, 0, -1); } } $model = XenForo_Model::create($model); $fileExport = new ExportHelper($name ? $name : $export); if (!$method) { $method = 'append' . $camel . 'AddonXml'; } $model->{$method}($fileExport->getRootNode(), $addonId); $fileExport->save($path . '/' . $export . '.xml'); } // Well that code was meant to be better than that... oh well, these following ones are better done seperate foreach (array(-1 => 'admin_', 0 => '') as $styleId => $prefix) { $model = XenForo_Model::create('XenForo_Model_StyleProperty'); $fileExport = new ExportHelper($prefix . 'style_properties'); $model->appendStylePropertyXml($fileExport->getRootNode(), $styleId, $addonId); $fileExport->save($path . '/' . $prefix . 'style_properties.xml'); } // Hardcode for now $file = $path . '/../library/Merc/' . str_replace('merc', '', $addonId) . '/FileSums.php'; if (file_exists($file)) { $hashes = XenForo_Helper_Hash::hashDirectory(realpath($path . '/../'), array('.js', '.php')); $remove = substr(realpath(dirname($file)), 0, strpos(realpath(dirname($file)), 'library')); foreach ($hashes as $k => $h) { unset($hashes[$k]); $hashes[str_replace($remove, '', $k)] = $h; } file_put_contents($file, XenForo_Helper_Hash::getHashClassCode('Merc_' . str_replace('merc', '', $addonId) . '_FileSums', $hashes)); } }
public static function generateHashesFile(array $addOn, DevHelper_Config_Base $config, array $directories) { $hashes = array(); /** @var XenForo_Application $application */ $application = XenForo_Application::getInstance(); $root = rtrim(realpath($application->getRootDir()), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $excludes = $config->getExportExcludes(); foreach ($directories as $key => $directory) { $directoryHashes = XenForo_Helper_Hash::hashDirectory($directory, array('.php', '.js')); foreach ($directoryHashes as $filePath => $hash) { if (strpos($filePath, 'DevHelper') === false and strpos($filePath, 'FileSums') === false) { $relative = str_replace($root, '', $filePath); $excluded = false; foreach ($excludes as $exclude) { if (strpos($relative, $exclude) === 0) { $excluded = true; break; } } if ($excluded) { continue; } $hashes[$relative] = $hash; } } } $fileSumsClassName = self::getClassName($addOn['addon_id'], 'FileSums', $config); $fileSumsContents = XenForo_Helper_Hash::getHashClassCode($fileSumsClassName, $hashes); self::writeClass($fileSumsClassName, $fileSumsContents); }