/** * Returns validator list * * @param ConfigFile $cf Config file instance * * @return array */ public static function getValidators(ConfigFile $cf) { static $validators = null; if ($validators !== null) { return $validators; } $validators = $cf->getDbEntry('_validators', array()); if (defined('PMA_SETUP')) { return $validators; } // not in setup script: load additional validators for user // preferences we need original config values not overwritten // by user preferences, creating a new PMA\libraries\Config instance is a // better idea than hacking into its code $uvs = $cf->getDbEntry('_userValidators', array()); foreach ($uvs as $field => $uv_list) { $uv_list = (array) $uv_list; foreach ($uv_list as &$uv) { if (!is_array($uv)) { continue; } for ($i = 1, $nb = count($uv); $i < $nb; $i++) { if (mb_substr($uv[$i], 0, 6) == 'value:') { $uv[$i] = PMA_arrayRead(mb_substr($uv[$i], 6), $GLOBALS['PMA_Config']->base_settings); } } } $validators[$field] = isset($validators[$field]) ? array_merge((array) $validators[$field], $uv_list) : $uv_list; } return $validators; }
/** * Common initialization for user preferences modification pages * * @param ConfigFile $cf Config file instance * * @return void */ function PMA_userprefsPageInit(ConfigFile $cf) { $forms_all_keys = PMA_readUserprefsFieldNames($GLOBALS['forms']); $cf->resetConfigData(); // start with a clean instance $cf->setAllowedKeys($forms_all_keys); $cf->setCfgUpdateReadMapping(array('Server/hide_db' => 'Servers/1/hide_db', 'Server/only_db' => 'Servers/1/only_db')); $cf->updateWithGlobalConfig($GLOBALS['cfg']); }
/** * Test for ConfigGenerator::getConfigFile * * @return void * @group medium */ public function testGetConfigFile() { unset($_SESSION['eol']); $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['server'] = 0; $cf = new ConfigFile(); $_SESSION['ConfigFile0'] = array('a', 'b', 'c'); $_SESSION['ConfigFile0']['Servers'] = array(array(1, 2, 3)); $cf->setPersistKeys(array("1/", 2)); $result = ConfigGenerator::getConfigFile($cf); $this->assertContains("<?php\n" . "/*\n" . " * Generated configuration file\n" . " * Generated by: phpMyAdmin " . $GLOBALS['PMA_Config']->get('PMA_VERSION') . " setup script\n", $result); $this->assertContains("/* Servers configuration */\n" . '$i = 0;' . "\n\n" . "/* Server: localhost [0] */\n" . '$i++;' . "\n" . '$cfg[\'Servers\'][$i][\'0\'] = 1;' . "\n" . '$cfg[\'Servers\'][$i][\'1\'] = 2;' . "\n" . '$cfg[\'Servers\'][$i][\'2\'] = 3;' . "\n\n" . "/* End of servers configuration */\n\n", $result); $this->assertContains('?>', $result); }
/** * Test for ConfigFile::getConfigArray * * @return void * @test */ public function testGetConfigArray() { $this->object->setPersistKeys(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE)); $this->object->set('Array/test', array('x', 'y')); $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); $this->assertEquals(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value, 'Array/test' => array('x', 'y')), $this->object->getConfigArray()); }
/** * Test for ConfigGenerator::getConfigFile * * @return void * @group medium */ public function testGetConfigFile() { $GLOBALS['cfg']['AvailableCharsets'] = array(); unset($_SESSION['eol']); $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['server'] = 0; $cf = new ConfigFile(); $_SESSION['ConfigFile0'] = array('a', 'b', 'c'); $_SESSION['ConfigFile0']['Servers'] = array(array(1, 2, 3)); $cf->setPersistKeys(array("1/", 2)); /* TODO: This is sometimes one second off... */ $date = date(DATE_RFC1123); $result = ConfigGenerator::getConfigFile($cf); $this->assertContains("<?php\n" . "/*\n" . " * Generated configuration file\n" . " * Generated by: phpMyAdmin " . $GLOBALS['PMA_Config']->get('PMA_VERSION') . " setup script\n" . " * Date: " . $date . "\n" . " */\n\n", $result); $this->assertContains("/* Servers configuration */\n" . '$i = 0;' . "\n\n" . "/* Server: localhost [0] */\n" . '$i++;' . "\n" . '$cfg[\'Servers\'][$i][\'0\'] = 1;' . "\n" . '$cfg[\'Servers\'][$i][\'1\'] = 2;' . "\n" . '$cfg[\'Servers\'][$i][\'2\'] = 3;' . "\n\n" . "/* End of servers configuration */\n\n", $result); $this->assertContains('?>', $result); }
/** * Fills out {@link userprefs_keys} and {@link userprefs_disallow} * * @return void */ private function _loadUserprefsInfo() { if ($this->_userprefsKeys !== null) { return; } $this->_userprefsKeys = array_flip(PMA_readUserprefsFieldNames()); // read real config for user preferences display $userprefs_disallow = defined('PMA_SETUP') ? $this->_configFile->get('UserprefsDisallow', array()) : $GLOBALS['cfg']['UserprefsDisallow']; $this->_userprefsDisallow = array_flip($userprefs_disallow); }
/** * Generate server part of config file * * @param ConfigFile $cf Config file * @param string $crlf Carriage return char * @param array $servers Servers list * * @return string */ protected static function getServerPart(ConfigFile $cf, $crlf, $servers) { if ($cf->getServerCount() === 0) { return null; } $ret = "/* Servers configuration */{$crlf}\$i = 0;" . $crlf . $crlf; foreach ($servers as $id => $server) { $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [{$id}] ", '*/', '-') . "*/" . $crlf . '$i++;' . $crlf; foreach ($server as $k => $v) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); $ret .= "\$cfg['Servers'][\$i]['{$k}'] = " . (is_array($v) && self::_isZeroBasedArray($v) ? self::_exportZeroBasedArray($v, $crlf) : var_export($v, true)) . ';' . $crlf; } $ret .= $crlf; } $ret .= '/* End of servers configuration */' . $crlf . $crlf; return $ret; }
/** * If we are on a server with open_basedir, we must move the file * before opening it. The FAQ 1.11 explains how to create the "./tmp" * directory - if needed * * @todo move check of $cfg['TempDir'] into Config? * @access public * @return boolean whether uploaded file is fine or not */ public function checkUploadedFile() { if ($this->isReadable()) { return true; } $tmp_subdir = ConfigFile::getDefaultTempDirectory(); if (@is_writable($tmp_subdir)) { // cannot create directory or access, point user to FAQ 1.11 $this->_error_message = Message::error(__('Error moving the uploaded file, see [doc@faq1-11]FAQ 1.11[/doc].')); return false; } $new_file_to_upload = tempnam(realpath($tmp_subdir), basename($this->getName())); // suppress warnings from being displayed, but not from being logged // any file access outside of open_basedir will issue a warning ob_start(); $move_uploaded_file_result = move_uploaded_file($this->getName(), $new_file_to_upload); ob_end_clean(); if (!$move_uploaded_file_result) { $this->_error_message = Message::error(__('Error while moving uploaded file.')); return false; } $this->setName($new_file_to_upload); $this->isTemp(true); if (!$this->isReadable()) { $this->_error_message = Message::error(__('Cannot read uploaded file.')); return false; } return true; }
/** * Kanji file encoding convert * * @param string $file the name of the file to convert * @param string $enc the destination encoding code * @param string $kana set 'kana' convert to JIS-X208-kana * * @return string the name of the converted file */ public static function kanjiFileConv($file, $enc, $kana) { if ($enc == '' && $kana == '') { return $file; } $tmpfname = tempnam(ConfigFile::getDefaultTempDirectory(), $enc); $fpd = fopen($tmpfname, 'wb'); $fps = fopen($file, 'r'); self::kanjiChangeOrder(); while (!feof($fps)) { $line = fgets($fps, 4096); $dist = self::kanjiStrConv($line, $enc, $kana); fputs($fpd, $dist); } // end while self::kanjiChangeOrder(); fclose($fps); fclose($fpd); unlink($file); return $tmpfname; }