/** * init setup framework */ public static function initFramework() { Setup_Core::setupConfig(); Setup_Core::setupTempDir(); //Database Connection must be setup before cache because setupCache uses constant "SQL_TABLE_PREFIX" Setup_Core::setupDatabaseConnection(); Setup_Core::setupStreamWrapper(); //Cache must be setup before User Locale because otherwise Zend_Locale tries to setup //its own cache handler which might result in a open_basedir restriction depending on the php.ini settings Setup_Core::setupCache(); Setup_Core::setupBuildConstants(); // setup a temporary user locale/timezone. This will be overwritten later but we // need to handle exceptions during initialisation process such as seesion timeout Setup_Core::set('locale', new Zend_Locale('en_US')); Setup_Core::set(Tinebase_Core::USERTIMEZONE, 'UTC'); Setup_Core::setupUserLocale(); header('X-API: http://www.tine20.org/apidocs/tine20/'); }
/** * handle request (call -ApplicationName-_Cli.-MethodName- or -ApplicationName-_Cli.getHelp) * * @param Zend_Console_Getopt $_opts * @param boolean $exitAfterHandle * @return void */ public function handle(Zend_Console_Getopt $_opts, $exitAfterHandle = true) { Setup_Core::set(Setup_Core::USER, 'setupuser'); $result = 0; if (isset($_opts->install)) { $this->_install($_opts); } elseif (isset($_opts->update)) { $result = $this->_update($_opts); } elseif (isset($_opts->uninstall)) { $this->_uninstall($_opts); } elseif (isset($_opts->list)) { $result = $this->_listInstalled(); } elseif (isset($_opts->sync_accounts_from_ldap)) { $this->_importAccounts($_opts); } elseif (isset($_opts->sync_passwords_from_ldap)) { $this->_syncPasswords($_opts); } elseif (isset($_opts->egw14import)) { $this->_egw14Import($_opts); } elseif (isset($_opts->check_requirements)) { $this->_checkRequirements($_opts); } elseif (isset($_opts->setconfig)) { $this->_setConfig($_opts); } elseif (isset($_opts->create_admin)) { $this->_createAdminUser($_opts); } elseif (isset($_opts->getconfig)) { $this->_getConfig($_opts); } elseif (isset($_opts->reset_demodata)) { $this->_resetDemodata($_opts); } elseif (isset($_opts->updateAllImportExportDefinitions)) { $this->_updateAllImportExportDefinitions($_opts); } elseif (isset($_opts->backup)) { $this->_backup($_opts); } elseif (isset($_opts->restore)) { $this->_restore($_opts); } if ($exitAfterHandle) { exit($result); } }
/** * handle request (call -ApplicationName-_Cli.-MethodName- or -ApplicationName-_Cli.getHelp) * * @param Zend_Console_Getopt $_opts * @return void */ public function handle(Zend_Console_Getopt $_opts) { Setup_Core::set(Setup_Core::USER, 'setupuser'); if (isset($_opts->install)) { $this->_install($_opts); } elseif (isset($_opts->update)) { $this->_update($_opts); } elseif (isset($_opts->uninstall)) { $this->_uninstall($_opts); } elseif (isset($_opts->list)) { $this->_listInstalled(); } elseif (isset($_opts->sync_accounts_from_ldap)) { $this->_importAccounts($_opts); } elseif (isset($_opts->egw14import)) { $this->_egw14Import($_opts); } elseif (isset($_opts->check_requirements)) { $this->_checkRequirements($_opts); } elseif (isset($_opts->setconfig)) { $this->_setConfig($_opts); } elseif (isset($_opts->create_admin)) { $this->_createAdminUser($_opts); } }
/** * checks the environment * * @return array with success/failure values for the given attributes * */ private function _check() { foreach ($this->values as $key => $value) { if ($value['tag'] == 'ENVIROMENT') { switch ($value['attributes']['NAME']) { case 'Zend': $required = $value['attributes']['VERSION']; $zend = Zend_Version::VERSION; $operator = $value['attributes']['OPERATOR'] == 'biggerThan' ? '>' : '<'; $text = $value['attributes']['NAME'] . ' ' . $operator . ' ' . $required; if (version_compare($zend, $required, $operator)) { $data[] = array($text, 'SUCCESS'); } else { $data[] = array($text . ' (version is ' . $zend . ')', 'FAILURE'); } break; case 'PHP': if (version_compare($value['attributes']['VERSION'], phpversion(), '<=')) { $data[] = array($value['attributes']['NAME'], 'SUCCESS'); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' PHP version incompatible: ' . phpversion() . ' < ' . $value['attributes']['VERSION']); $data[] = array($value['attributes']['NAME'], 'FAILURE'); } break; case 'MySQL': // get setup controller for database connection if (Setup_Core::configFileExists()) { $dbConfig = Tinebase_Core::getConfig()->database; $hostnameWithPort = isset($dbConfig->port) ? $dbConfig->host . ':' . $dbConfig->port : $dbConfig->host; $link = @mysql_connect($hostnameWithPort, $dbConfig->username, $dbConfig->password); if (!$link) { //die('Could not connect to mysql database: ' . mysql_error()); Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'Could not connect to mysql database: ' . mysql_error()); Setup_Core::set(Setup_Core::CHECKDB, FALSE); } $mysqlVersion = @mysql_get_server_info(); } else { $mysqlVersion = @mysql_get_client_info(); } // some version strings have more than just the version preg_match('/\\d+\\.\\d+\\.\\d+/', $mysqlVersion, $matches); $mysqlVersion = is_array($matches) ? $matches[0] : $mysqlVersion; $text = $value['attributes']['NAME']; if (version_compare($value['attributes']['VERSION'], $mysqlVersion, '<=')) { $data[] = array($text, 'SUCCESS'); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' MySQL version incompatible: ' . $mysqlVersion . ' < ' . $value['attributes']['VERSION']); $data[] = array($text, 'FAILURE'); } break; case 'PgSQL': $pgsqlVersion = '0.0.0'; // get setup controller for database connection if (Setup_Core::configFileExists()) { $dbConfig = Tinebase_Core::getConfig()->database; $hostname = $dbConfig->host; $port = isset($dbConfig->port) ? $dbConfig->port : '5432'; $user = $dbConfig->username; $password = $dbConfig->password; $link = @pg_connect("host={$hostname} port={$port} user={$user} password={$password}"); if (PGSQL_CONNECTION_BAD === pg_connection_status($link)) { //die('Could not connect to postgresql database: ' . pg_errormessage()); Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'Could not connect to postgresql database: ' . pg_errormessage()); Setup_Core::set(Setup_Core::CHECKDB, FALSE); } else { $pgsqlVersion = @pg_version($link); $pgsqlVersion = $pgsqlVersion['server']; } } $text = $value['attributes']['NAME']; if (version_compare($value['attributes']['VERSION'], $pgsqlVersion, '<=')) { $data[] = array($text, 'SUCCESS'); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' PostgreSQL version incompatible: ' . $pgsqlVersion . ' < ' . $value['attributes']['VERSION']); $data[] = array($text, 'FAILURE'); } break; default: $data[] = array($value['attributes']['NAME'], 'FAILURE'); break; } } else { if ($value['tag'] == 'EXTENSION') { //print_r($this->loadedExtensions); foreach ($value as $extensionArray) { if (is_array($extensionArray)) { $succeeded = false; if (in_array($extensionArray['NAME'], $this->loadedExtensions)) { $passed[] = true; if ($this->values[$key + 1]['tag'] == 'INISET') { $iniSettings = ini_get_all($extensionArray['NAME']); //print_r($iniSettings); $i = 1; while ($values[$key + $i]['tag'] == 'INISET') { switch ($values[$key + $i]['attributes']['OPERATOR']) { case '<=': if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] <= $values[$key + $i]['attributes']['VALUE']) { $passed[] = false; } break; case '==': if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] == $values[$key + $i]['attributes']['VALUE']) { $passed[] = false; } break; case '>=': if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] >= $values[$key + $i]['attributes']['VALUE']) { $passed[] = false; } break; default: break; } $i++; } } // end INISET if (!in_array(false, $passed)) { $succeeded = true; } unset($passed); unset($iniSettings); } if ($succeeded) { $data[] = array($extensionArray['NAME'], 'SUCCESS'); } else { $data[] = array($extensionArray['NAME'], 'FAILURE'); } } } } } // end EXTENSION } // end foreach return $data; }
/** * create new setup user session * * @param string $_username * @param string $_password * @return bool */ public function login($_username, $_password) { $setupAuth = new Setup_Auth($_username, $_password); $authResult = Zend_Auth::getInstance()->authenticate($setupAuth); if ($authResult->isValid()) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Valid credentials, setting username in session and registry.'); Tinebase_Session::regenerateId(); Setup_Core::set(Setup_Core::USER, $_username); Setup_Session::getSessionNamespace()->setupuser = $_username; return true; } else { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Invalid credentials! ' . print_r($authResult->getMessages(), TRUE)); Tinebase_Session::expireSessionCookie(); sleep(2); return false; } }
/** * test load config */ public function testLoadConfig() { // register user first Setup_Core::set(Setup_Core::USER, 'setupuser'); $result = $this->_json->loadConfig(); $this->assertTrue(is_array($result), 'result is no array'); $this->assertTrue(isset($result['database']), 'db config not found'); $this->assertGreaterThan(1, count($result)); }