/** * authenticate user * * @return Zend_Auth_Result */ public function authenticate() { if (isset(Setup_Core::getConfig()->setupuser)) { $setupConfig = Setup_Core::getConfig()->setupuser; $givenPassword = self::isMd5($setupConfig->password) ? md5($this->_password) : $this->_password; if ($setupConfig->username == $this->_username && $setupConfig->password == $givenPassword) { $code = Zend_Auth_Result::SUCCESS; $messages = array('Login successful'); } else { #Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . " $setupConfig->username == $this->_username && $setupConfig->password == $this->_password "); $code = Zend_Auth_Result::FAILURE; $messages = array('Login failed'); } } else { $code = Zend_Auth_Result::FAILURE; $messages = array('No setup user found in config.inc.php'); } $result = new Zend_Auth_Result($code, $this->_username, $messages); return $result; }
/** * restore * * @param $options array( * 'backupDir' => string // location of backup to restore * 'config' => bool // restore config * 'db' => bool // restore database * 'files' => bool // restore files * ) * * @param $options * @throws Exception */ public function restore($options) { if (!isset($options['backupDir'])) { throw new Exception("you need to specify the backupDir"); } if ($options['config']) { $configBackupFile = $options['backupDir'] . '/tine20_config.tar.bz2'; if (!file_exists($configBackupFile)) { throw new Exception("{$configBackupFile} not found"); } $configDir = isset($options['configDir']) ? $options['configDir'] : false; if (!$configDir) { $configFile = stream_resolve_include_path('config.inc.php'); if (!$configFile) { throw new Exception("can't detect configDir, please use configDir option"); } $configDir = dirname($configFile); } `cd {$configDir}; tar xf {$configBackupFile}`; } Setup_Core::setupConfig(); $config = Setup_Core::getConfig(); if ($options['db']) { $this->_backend->restore($options['backupDir']); } $filesDir = isset($config->filesdir) ? $config->filesdir : false; if ($options['files']) { $filesBackupFile = $options['backupDir'] . '/tine20_files.tar.bz2'; if (!file_exists($filesBackupFile)) { throw new Exception("{$filesBackupFile} not found"); } `cd {$filesDir}; tar xf {$filesBackupFile}`; } }
/** * write config to a file * * @param array $_data * @param boolean $_merge * @param string $_filename * @return Zend_Config */ public function writeConfigToFile($_data, $_merge, $_filename) { // merge config data and active config if ($_merge) { $activeConfig = Setup_Core::getConfig(); $config = new Zend_Config($activeConfig->toArray(), true); $config->merge(new Zend_Config($_data)); } else { $config = new Zend_Config($_data); } // write to file Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating config.inc.php'); $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => $_filename)); $writer->write(); return $config; }
/** * update to 0.28 * - repair db charset for users with non default utf8 client charset */ public function update_27() { $config = Setup_Core::getConfig(); $tableprefix = $config->database->tableprefix; // have a second db connection with default charset $orgDb = Zend_Db::factory('Pdo_Mysql', $config->database->toArray()); // fix for signed / unsigned problem $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>id</name> <type>integer</type> <autoincrement>true</autoincrement> </field> '); $this->_backend->alterCol('addressbook', $declaration); /** addressbook: store image in separate table **/ $tableDefinition = ' <table> <name>addressbook_image</name> <version>1</version> <declaration> <field> <name>contact_id</name> <type>integer</type> <notnull>true</notnull> </field> <field> <name>image</name> <type>blob</type> </field> <index> <name>contact_id</name> <primary>true</primary> <field> <name>contact_id</name> </field> </index> <index> <name>addressbook_image::contact_id-addressbook::id</name> <field> <name>contact_id</name> </field> <foreign>true</foreign> <reference> <table>addressbook</table> <field>id</field> <ondelete>CASCADE</ondelete> </reference> </index> </declaration> </table> '; $table = Setup_Backend_Schema_Table_Factory::factory('String', $tableDefinition); $this->_backend->createTable($table); $select = $orgDb->select()->from("{$tableprefix}addressbook", array('id'))->where($orgDb->quoteIdentifier('jpegphoto') . " IS NOT NULL"); $contactIds = $orgDb->fetchAll($select); foreach ($contactIds as $contactId) { $contactId = $contactId['id']; $select = $orgDb->select()->from("{$tableprefix}addressbook", array('id', 'jpegphoto'))->where($orgDb->quoteInto($orgDb->quoteIdentifier('id') . ' = ?', $contactId)); $imageData = $orgDb->fetchRow($select); $orgDb->insert("{$tableprefix}addressbook_image", array('contact_id' => $imageData['id'], 'image' => base64_encode($imageData['jpegphoto']))); } $this->_backend->dropCol('addressbook', 'jpegphoto'); /** convert serialized object into json objects **/ $select = $orgDb->select()->from("{$tableprefix}filter", array('id', 'filters')); $filters = $orgDb->fetchAll($select); foreach ($filters as $filter) { $filterObject = unserialize($filter['filters']); $orgDb->update("{$tableprefix}filter", array('filters' => Zend_Json::encode($filterObject)), $orgDb->quoteInto($orgDb->quoteIdentifier('id') . ' = ?', $filter['id'])); } /** convert db contenets for installations which had a clientcharset != utf8 **/ $originalCharset = array_value('Value', array_value(0, $orgDb->query("SHOW VARIABLES LIKE 'character_set_client'")->fetchAll())); if (strtolower($originalCharset) != 'utf8') { $this->_db->query("SET FOREIGN_KEY_CHECKS=0"); $orgDb->query("SET FOREIGN_KEY_CHECKS=0"); // build the list of tables to convert $tables = array(); $rawTables = $this->_db->query("SHOW TABLES")->fetchAll(); foreach ($rawTables as $rawTable) { $tableName = array_values($rawTable); $tableName = $tableName[0]; if (preg_match("/^{$tableprefix}/", $tableName) && $tableName != "{$tableprefix}addressbook_image") { $tables[] = $tableName; } } // the actual charset conversion is done by the db. foreach ($tables as $tableName) { Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Converting table ' . $tableName); //$this->_db->query("SET character_set_client = '$originalCharset'"); $select = $orgDb->select()->from($tableName); $result = $orgDb->fetchAll($select); $orgDb->query("TRUNCATE TABLE " . $this->_db->quoteIdentifier($tableName)); //$this->_db->query("SET character_set_client = 'utf8'"); foreach ($result as $row) { try { $this->_db->insert($tableName, $row); } catch (Zend_Db_Statement_Exception $zdse) { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $zdse->getMessage()); // try to convert strings if failure if (preg_match('/(description|title|note|old_value|org_name|adr_one_street)/', $zdse->getMessage(), $match)) { $field = $match[1]; Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Converting field ' . $field . (array_key_exists('id', $row) ? ' of record ' . $row['id'] : '')); $row[$field] = utf8_encode($row[$field]); $this->_db->insert($tableName, $row); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not convert field'); throw $zdse; } } } } $this->_db->query("SET FOREIGN_KEY_CHECKS=1"); } $orgDb->closeConnection(); $this->setApplicationVersion('Tinebase', '0.28'); }