/** * Return search specs * * @param string $filename config file name * * @return array */ public function get($filename) { // Load data if it is not already in the object's cache: if (!isset($this->searchSpecs[$filename])) { // Connect to searchspecs cache: $cache = null !== $this->cacheManager ? $this->cacheManager->getCache('searchspecs') : false; // Determine full configuration file path: $fullpath = Locator::getBaseConfigPath($filename); $local = Locator::getLocalConfigPath($filename); // Generate cache key: $cacheKey = $filename . '-' . (file_exists($fullpath) ? filemtime($fullpath) : 0); if (!empty($local)) { $cacheKey .= '-local-' . filemtime($local); } $cacheKey = md5($cacheKey); // Generate data if not found in cache: if ($cache === false || !($results = $cache->getItem($cacheKey))) { $results = file_exists($fullpath) ? Yaml::parse(file_get_contents($fullpath)) : []; if (!empty($local)) { $localResults = Yaml::parse(file_get_contents($local)); foreach ($localResults as $key => $value) { $results[$key] = $value; } } if ($cache !== false) { $cache->setItem($cacheKey, $results); } } $this->searchSpecs[$filename] = $results; } return $this->searchSpecs[$filename]; }
/** * Return search specs * * @param string $filename config file name * * @return array */ public function get($filename) { // Load data if it is not already in the object's cache: if (!isset($this->searchSpecs[$filename])) { $this->searchSpecs[$filename] = $this->getFromPaths(Locator::getBaseConfigPath($filename), Locator::getLocalConfigPath($filename)); } return $this->searchSpecs[$filename]; }
/** * Load the specified configuration file. * * @param string $filename config file name * @param string $path path relative to VuFind base (optional; defaults * to config/vufind * * @return Config */ protected function loadConfigFile($filename, $path = 'config/vufind') { // If we don't have a local config file in config/vufind, check for it in // config/finna and load from there if found. $localConfig = Locator::getLocalConfigPath($filename, $path); if ($localConfig === null) { $localConfig = Locator::getLocalConfigPath($filename, 'config/finna'); if ($localConfig !== null) { return parent::loadConfigFile($filename, 'config/finna'); } } return parent::loadConfigFile($filename, $path); }
/** * Standard setup method. * * @return void */ public static function setUpBeforeClass() { // Create test files: $parentPath = Locator::getLocalConfigPath('unit-test-parent.ini', null, true); $parent = "[Section1]\n" . "a=1\nb=2\nc=3\n" . "[Section2]\n" . "d=4\ne=5\nf=6\n" . "[Section3]\n" . "g=7\nh=8\ni=9\n"; $childPath = Locator::getLocalConfigPath('unit-test-child.ini', null, true); $child = "[Section1]\n" . "j=10\nk=11\nl=12\n" . "[Section2]\n" . "m=13\nn=14\no=15\n" . "[Parent_Config]\n" . "path=\"{$parentPath}\"\n" . "override_full_sections=Section1\n"; // Fail if we are unable to write files: if (null === $parentPath || null === $childPath || !file_put_contents($parentPath, $parent) || !file_put_contents($childPath, $child)) { self::$writeFailed = true; return; } // Mark for cleanup: self::$filesToDelete = [$parentPath, $childPath]; }
/** * Restore configurations to the state they were in prior to a call to * changeConfig(). * * @return void */ protected function restoreConfigs() { foreach ($this->modifiedConfigs as $current) { $file = $current . '.ini'; $local = ConfigLocator::getLocalConfigPath($file, null, true); $backup = $local . '.bak'; // Do we have a backup? If so, restore from it; otherwise, just // delete the local file, as it did not previously exist: unlink($local); if (file_exists($backup)) { rename($backup, $local); } } }
/** * Display summary of installation status * * @return mixed */ public function homeAction() { // If the cache is messed up, nothing is going to work right -- check that // first: $cache = $this->getServiceLocator()->get('VuFind\\CacheManager'); if ($cache->hasDirectoryCreationError()) { return $this->redirect()->toRoute('install-fixcache'); } // First find out which version we are upgrading: if (!isset($this->cookie->sourceDir) || !is_dir($this->cookie->sourceDir)) { return $this->forwardTo('Upgrade', 'GetSourceDir'); } // Next figure out which version(s) are involved: if (!isset($this->cookie->oldVersion) || !isset($this->cookie->newVersion)) { return $this->forwardTo('Upgrade', 'EstablishVersions'); } // Now make sure we have a configuration file ready: if (!isset($this->cookie->configOkay) || !$this->cookie->configOkay) { return $this->redirect()->toRoute('upgrade-fixconfig'); } // Now make sure the database is up to date: if (!isset($this->cookie->databaseOkay) || !$this->cookie->databaseOkay) { return $this->redirect()->toRoute('upgrade-fixdatabase'); } // Check for missing metadata in the resource table; note that we do a // redirect rather than a forward here so that a submit button clicked // in the database action doesn't cause the metadata action to also submit! if (!isset($this->cookie->metadataOkay) || !$this->cookie->metadataOkay) { return $this->redirect()->toRoute('upgrade-fixmetadata'); } // We're finally done -- display any warnings that we collected during // the process. $allWarnings = array_merge(isset($this->cookie->warnings) ? $this->cookie->warnings : [], (array) $this->session->warnings); foreach ($allWarnings as $warning) { $this->flashMessenger()->addMessage($warning, 'info'); } return $this->createViewModel(['configDir' => dirname(ConfigLocator::getLocalConfigPath('config.ini', null, true)), 'importDir' => LOCAL_OVERRIDE_DIR . '/import', 'oldVersion' => $this->cookie->oldVersion]); }
/** * Disable auto-configuration. * * @return mixed */ public function doneAction() { $config = ConfigLocator::getLocalConfigPath('config.ini', null, true); $writer = new ConfigWriter($config); $writer->set('System', 'autoConfigure', 0); if (!$writer->save()) { return $this->forwardTo('Install', 'fixbasicconfig'); } return $this->createViewModel(['configDir' => dirname($config)]); }
/** * Construct the OpenUrl helper. * * @param ServiceManager $sm Service manager. * * @return OpenUrl */ public static function getOpenUrl(ServiceManager $sm) { $config = $sm->getServiceLocator()->get('VuFind\\Config')->get('config'); $file = \VuFind\Config\Locator::getLocalConfigPath('OpenUrlRules.json'); if ($file === null) { $file = \VuFind\Config\Locator::getLocalConfigPath('OpenUrlRules.json', 'config/finna'); if ($file === null) { $file = \VuFind\Config\Locator::getConfigPath('OpenUrlRules.json'); } } $openUrlRules = json_decode(file_get_contents($file), true); return new OpenUrl($sm->get('context'), $openUrlRules, isset($config->OpenURL) ? $config->OpenURL : null); }
/** * Test @parent_yaml directive. * * @return void */ public function testParentYaml() { if (self::$writeFailed) { $this->markTestSkipped('Could not write test configurations.'); } $reader = new SearchSpecsReader(); $core = Locator::getLocalConfigPath('middle.yaml', null, true); $local = Locator::getLocalConfigPath('bottom.yaml', null, true); $this->assertEquals(['top' => 'foo', 'middle' => 'bar', 'bottom' => 'baz'], $this->callMethod($reader, 'getFromPaths', [$core, $local])); }
/** * Convert hash algorithms * Expected parameters: oldmethod:oldkey (or none) newmethod:newkey * * @return \Zend\Console\Response */ public function switchdbhashAction() { // Validate command line arguments: $argv = $this->consoleOpts->getRemainingArgs(); if (count($argv) < 1) { Console::writeLine('Expected parameters: newmethod [newkey]'); return $this->getFailureResponse(); } // Pull existing encryption settings from the configuration: $config = $this->getConfig(); if (!isset($config->Authentication->encrypt_ils_password) || !isset($config->Authentication->ils_encryption_key) || !$config->Authentication->encrypt_ils_password) { $oldhash = 'none'; $oldkey = null; } else { $oldhash = isset($config->Authentication->ils_encryption_algo) ? $config->Authentication->ils_encryption_algo : 'blowfish'; $oldkey = $config->Authentication->ils_encryption_key; } // Pull new encryption settings from arguments: $newhash = $argv[0]; $newkey = isset($argv[1]) ? $argv[1] : $oldkey; // No key specified AND no key on file = fatal error: if ($newkey === null) { Console::writeLine('Please specify a key as the second parameter.'); return $this->getFailureResponse(); } // If no changes were requested, abort early: if ($oldkey == $newkey && $oldhash == $newhash) { Console::writeLine('No changes requested -- no action needed.'); return $this->getSuccessResponse(); } // Initialize Mcrypt first, so we can catch any illegal algorithms before // making any changes: try { if ($oldhash != 'none') { $oldCrypt = new Mcrypt(['algorithm' => $oldhash]); } $newCrypt = new Mcrypt(['algorithm' => $newhash]); } catch (\Exception $e) { Console::writeLine($e->getMessage()); return $this->getFailureResponse(); } // Next update the config file, so if we are unable to write the file, // we don't go ahead and make unwanted changes to the database: $configPath = ConfigLocator::getLocalConfigPath('config.ini', null, true); Console::writeLine("\tUpdating {$configPath}..."); $writer = new ConfigWriter($configPath); $writer->set('Authentication', 'encrypt_ils_password', true); $writer->set('Authentication', 'ils_encryption_algo', $newhash); $writer->set('Authentication', 'ils_encryption_key', $newkey); if (!$writer->save()) { Console::writeLine("\tWrite failed!"); return $this->getFailureResponse(); } // Now do the database rewrite: $userTable = $this->getServiceLocator()->get('VuFind\\DbTablePluginManager')->get('User'); $users = $userTable->select(function ($select) { $select->where->isNotNull('cat_username'); }); Console::writeLine("\tConverting hashes for " . count($users) . ' user(s).'); foreach ($users as $row) { $pass = null; if ($oldhash != 'none' && isset($row['cat_pass_enc'])) { $oldcipher = new BlockCipher($oldCrypt); $oldcipher->setKey($oldkey); $pass = $oldcipher->decrypt($row['cat_pass_enc']); } else { $pass = $row['cat_password']; } $newcipher = new BlockCipher($newCrypt); $newcipher->setKey($newkey); $row['cat_password'] = null; $row['cat_pass_enc'] = $newcipher->encrypt($pass); $row->save(); } // If we got this far, all went well! Console::writeLine("\tFinished."); return $this->getSuccessResponse(); }