2011-06-10 21:55:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
|
|
|
* http://www.mysqldumper.net
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
|
|
|
* @subpackage Controllers
|
|
|
|
* @version SVN: $Rev$
|
|
|
|
* @author $Author$
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Install controller
|
|
|
|
*
|
|
|
|
* Controller to handle actions triggered on install process
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
|
|
|
* @subpackage Controllers
|
|
|
|
*/
|
2012-08-21 20:22:56 +00:00
|
|
|
class InstallController extends Msd_Controller_Action
|
2011-06-10 21:55:32 +00:00
|
|
|
{
|
2012-08-21 20:22:56 +00:00
|
|
|
/**
|
|
|
|
* @var Msd_Config
|
|
|
|
*/
|
|
|
|
public $config;
|
|
|
|
/**
|
|
|
|
* @var Msd_DynamicConfig
|
|
|
|
*/
|
|
|
|
public $dynamicConfig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Msd_Language
|
|
|
|
*/
|
|
|
|
public $lang;
|
|
|
|
|
2011-06-10 21:55:32 +00:00
|
|
|
/**
|
|
|
|
* Init controller
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$layout = Zend_Layout::getMvcInstance();
|
|
|
|
$layout->setLayout('install');
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->version = new Msd_Version();
|
2011-06-10 21:55:32 +00:00
|
|
|
$_SESSION['msd_install'] = true;
|
2012-08-21 20:22:56 +00:00
|
|
|
if ($this->_request->getActionName() != 'badversion!' && !$this->version->checkPhpVersion()) {
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->_forward(
|
|
|
|
'badversion',
|
|
|
|
'install',
|
|
|
|
'default',
|
|
|
|
array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'message' => 'L_PHP_VERSION_TOO_OLD'
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->_config->setParam('interface.theme', 'msd');
|
|
|
|
$this->_config->setParam('paths.iconPath', 'css/msd/icons');
|
|
|
|
$this->_config->setParam('configFile', 'mysqldumper.ini');
|
|
|
|
$this->view->config = $this->_config;
|
2012-08-21 20:27:36 +00:00
|
|
|
$lang = isset($_SESSION['msd_lang']) ? $_SESSION['msd_lang'] : 'en';
|
|
|
|
$translator = Msd_Language::getInstance();
|
|
|
|
$this->view->lang = $translator->loadLanguage($lang);
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start installation process
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2012-08-21 20:22:56 +00:00
|
|
|
// delete cookie from further installation if present to not import old values
|
2011-06-10 21:55:32 +00:00
|
|
|
if (isset($_SESSION['msd_autologin'])) {
|
|
|
|
setcookie('msd_autologin', null, null, '/');
|
|
|
|
$_SESSION['msd_autologin'] = array();
|
|
|
|
}
|
|
|
|
Zend_Session_Namespace::resetSingleInstance('MySQLDumper');
|
|
|
|
if ($this->_request->isPost()) {
|
|
|
|
$language = $this->_getParam('language');
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->_config->setParam('interface.language', $language);
|
|
|
|
$this->_config->setParam('general.title', 'MySQLDumper');
|
|
|
|
$this->_config->setParam('configFile', 'mysqldumper.ini');
|
2011-06-10 21:55:32 +00:00
|
|
|
$_SESSION['msd_lang'] = $language;
|
2012-08-21 20:22:56 +00:00
|
|
|
$redirectUrl = $this->view->url(array('controller' => 'install', 'action' => 'step2'), null, true);
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->_response->setRedirect($redirectUrl);
|
|
|
|
}
|
|
|
|
// set selected languge
|
2012-08-21 20:22:56 +00:00
|
|
|
$language = $this->_getParam('language', null);
|
|
|
|
$languages = $this->_lang->getAvailableLanguages();
|
2011-06-10 21:55:32 +00:00
|
|
|
|
|
|
|
// check user browser language
|
2012-08-21 20:22:56 +00:00
|
|
|
$locale = new Zend_Locale();
|
2011-06-10 21:55:32 +00:00
|
|
|
$browserLocale = array_keys($locale->getBrowser());
|
|
|
|
|
|
|
|
// get default or last selected language
|
|
|
|
if ($language === null) {
|
|
|
|
if (isset($_SESSION['msd_lang'])) {
|
|
|
|
$language = $_SESSION['msd_lang'];
|
|
|
|
} else {
|
|
|
|
foreach ($browserLocale as $localeCode) {
|
|
|
|
if (array_key_exists($localeCode, $languages)) {
|
|
|
|
$language = $localeCode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Msd_Language::getInstance()->loadLanguage($language);
|
|
|
|
$this->view->language = $language;
|
|
|
|
$this->view->stepInfo = array(
|
|
|
|
'language' => $language,
|
|
|
|
'stepInfo' => array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'number' => 1,
|
|
|
|
'description' => $this->_lang->getTranslator()
|
|
|
|
->_('L_SELECT_LANGUAGE')
|
|
|
|
. ' (' . $language . ')'));
|
|
|
|
$languagesStatus = array();
|
2011-06-10 21:55:32 +00:00
|
|
|
foreach ($languages as $langId => $langName) {
|
|
|
|
$languagesStatus[$langId] = array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'langName' => $langName,
|
2011-06-10 21:55:32 +00:00
|
|
|
'installed' => file_exists(
|
2012-08-04 10:40:48 +00:00
|
|
|
APPLICATION_PATH . '/language/' . $langId . '/lang.php'
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->_config->setParam('interface.language', $language);
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->view->languages = $languagesStatus;
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->view->lang = Msd_Language::getInstance();
|
|
|
|
Msd_Registry::setConfig($this->_config);
|
|
|
|
$this->view->config = Msd_Registry::getConfig();
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step 2 - check directories
|
|
|
|
*
|
|
|
|
* Make sure work-directories exist and are writable.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function step2Action()
|
|
|
|
{
|
2012-08-21 20:22:56 +00:00
|
|
|
$language = $this->_config->getParam('interface.language');
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->view->stepInfo = array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'language' => $language,
|
2011-06-10 21:55:32 +00:00
|
|
|
'firstStepOK' => true,
|
2012-08-21 20:22:56 +00:00
|
|
|
'stepInfo' => array(
|
|
|
|
'number' => 2,
|
|
|
|
'description' => $this->_lang->getTranslator()->_('L_CHECK_DIRS'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
2012-08-21 20:22:56 +00:00
|
|
|
$creationStatus = array();
|
|
|
|
$checkDirs = array(
|
|
|
|
'work' => $this->_config->getParam('paths.work'),
|
|
|
|
'config' => $this->_config->getParam('paths.config'),
|
|
|
|
'log' => $this->_config->getParam('paths.log'),
|
|
|
|
'backup' => $this->_config->getParam('paths.backup'),
|
|
|
|
'iconpath' => $this->_config->getParam('paths.iconPath')
|
2011-06-10 21:55:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($checkDirs as $checkDir) {
|
|
|
|
clearstatcache();
|
|
|
|
if (!is_dir($checkDir)) {
|
|
|
|
@mkdir($checkDir, 0777);
|
|
|
|
}
|
|
|
|
clearstatcache();
|
2012-08-21 20:22:56 +00:00
|
|
|
$checkExists = file_exists($checkDir);
|
|
|
|
$checkWritable = Msd_File::isWritable($checkDir, 0777);
|
2011-06-10 21:55:32 +00:00
|
|
|
$creationStatus[$checkDir] = array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'chmod' => Msd_File::getChmod($checkDir),
|
|
|
|
'exists' => $checkExists,
|
2011-06-10 21:55:32 +00:00
|
|
|
'writable' => $checkWritable,
|
|
|
|
);
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->view->status = $creationStatus;
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
if (!in_array(false, $creationStatus)) {
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->_config->setParam('configFile', 'mysqldumper');
|
|
|
|
//$this->_config->save();
|
2011-06-10 21:55:32 +00:00
|
|
|
$redirectUrl = $this->view->url(array('controller' => 'install', 'action' => 'step3'), null, true);
|
|
|
|
$this->_response->setRedirect($redirectUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step 3 - Enter administrative user
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function step3Action()
|
|
|
|
{
|
2012-08-21 20:22:56 +00:00
|
|
|
$language = $this->_config->getParam('interface.language');
|
|
|
|
$form = new Application_Form_Install_User();
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->view->stepInfo = array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'language' => $language,
|
|
|
|
'firstStepOK' => true,
|
2011-06-10 21:55:32 +00:00
|
|
|
'secondStepOK' => true,
|
2012-08-21 20:22:56 +00:00
|
|
|
'stepInfo' => array(
|
|
|
|
'number' => 3,
|
|
|
|
'description' => $this->_lang->getTranslator()->_('L_AUTHENTICATE'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
if ($this->_request->isPost()) {
|
|
|
|
$postData = $this->_request->getParams();
|
2012-08-21 20:22:56 +00:00
|
|
|
$form->getElement('pass_confirm')->getValidator('Identical')->setToken($postData['pass']);
|
2011-06-10 21:55:32 +00:00
|
|
|
if ($form->isValid($postData)) {
|
|
|
|
$ini = new Msd_Ini();
|
2012-10-27 13:39:33 +00:00
|
|
|
$ini->set('user[\'' . $postData['user'] . '\']', md5($postData['pass']), 'users');
|
2012-08-04 10:40:48 +00:00
|
|
|
$ini->saveFile(APPLICATION_PATH . '/configs/users.ini');
|
2011-06-10 21:55:32 +00:00
|
|
|
$redirectUrl = $this->view->url(array('controller' => 'install', 'action' => 'step4'), null, true);
|
|
|
|
$this->_response->setRedirect($redirectUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->view->lang = Msd_Language::getInstance();
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Step 4 - Enter database params
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function step4Action()
|
|
|
|
{
|
2012-08-21 20:22:56 +00:00
|
|
|
$language = $this->_config->getParam('interface.language');
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->view->stepInfo = array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'language' => $language,
|
|
|
|
'firstStepOK' => true,
|
2011-06-10 21:55:32 +00:00
|
|
|
'secondStepOK' => true,
|
2012-08-21 20:22:56 +00:00
|
|
|
'thirdStepOK' => true,
|
|
|
|
'stepInfo' => array(
|
|
|
|
'number' => 4,
|
|
|
|
'description' => $this->_lang->getTranslator()->_('L_DBPARAMETER'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->_request->isPost()) {
|
|
|
|
$options = array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'host' => $this->_getParam('host'),
|
|
|
|
'user' => $this->_getParam('user'),
|
|
|
|
'pass' => $this->_getParam('pass'),
|
2011-06-10 21:55:32 +00:00
|
|
|
'manual' => $this->_getParam('manual'),
|
2012-08-21 20:22:56 +00:00
|
|
|
'port' => $this->_getParam('port'),
|
2011-06-10 21:55:32 +00:00
|
|
|
'socket' => $this->_getParam('socket'),
|
|
|
|
);
|
2012-08-21 20:22:56 +00:00
|
|
|
|
|
|
|
$dbAdapter = Msd_Db::getAdapter($options);
|
|
|
|
try {
|
|
|
|
$this->view->databases = $dbAdapter->getDatabaseNames();
|
|
|
|
$this->view->success = true;
|
|
|
|
$this->_config->setParam('dbuser', $options);
|
|
|
|
if (!$this->version->checkMysqlVersion()) {
|
|
|
|
$this->_forward(
|
|
|
|
'badversion',
|
|
|
|
'install',
|
|
|
|
'default',
|
|
|
|
array(
|
|
|
|
'message' => 'L_MYSQL_VERSION_TOO_OLD'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (Msd_Exception $e) {
|
|
|
|
$this->view->errorMessage = $e->getMessage();
|
|
|
|
$this->view->success = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 16:43:15 +00:00
|
|
|
$saveParam = $this->_getParam('save', null);
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->_config->setParam('dbuser', $options);
|
2012-08-22 16:43:15 +00:00
|
|
|
if ($saveParam == 1) {
|
2012-08-21 20:22:56 +00:00
|
|
|
$this->_config->setParam('general.title', 'MySQLDumper');
|
|
|
|
$this->_config->setParam('dbuser.defaultDb', $this->_getParam('defaultDb'));
|
|
|
|
$this->_config->save('mysqldumper.ini');
|
2012-08-22 16:43:15 +00:00
|
|
|
Msd_Registry::setConfig($this->_config);
|
2011-06-10 21:55:32 +00:00
|
|
|
unset($_SESSION['msd_lang']);
|
|
|
|
unset($_SESSION['msd_install']);
|
2012-08-22 16:43:15 +00:00
|
|
|
$this->_config->load('mysqldumper.ini');
|
2011-06-10 21:55:32 +00:00
|
|
|
$redirectUrl = $this->view->url(array('controller' => 'index', 'action' => 'index', null, true));
|
|
|
|
$this->_response->setRedirect($redirectUrl);
|
|
|
|
}
|
|
|
|
}
|
2012-08-21 20:30:21 +00:00
|
|
|
$this->view->lang = Msd_Language::getInstance();
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax action for loading language packs
|
|
|
|
*
|
|
|
|
* @return string Json response
|
|
|
|
*/
|
|
|
|
public function ajaxAction()
|
|
|
|
{
|
|
|
|
Zend_Layout::getMvcInstance()->disableLayout();
|
|
|
|
Zend_Controller_Front::getInstance()->setParam('noViewRenderer', true);
|
|
|
|
$this->_response->setHeader('Content-Type', 'text/javascript');
|
|
|
|
$language = $this->_request->getParam('lang');
|
2012-08-21 20:22:56 +00:00
|
|
|
$version = new Msd_Version();
|
|
|
|
$files = array(
|
2012-08-04 10:40:48 +00:00
|
|
|
'lang' => ':language/lang.php',
|
|
|
|
'flag' => ':language/flag.gif'
|
2011-06-10 21:55:32 +00:00
|
|
|
);
|
|
|
|
if ($language === null) {
|
|
|
|
if (!isset($_SESSION['langlist'])) {
|
2012-08-21 20:22:56 +00:00
|
|
|
$languages = $this->_lang->getAvailableLanguages();
|
2011-06-10 21:55:32 +00:00
|
|
|
$_SESSION['langlist'] = array_keys($languages);
|
|
|
|
}
|
|
|
|
rsort($_SESSION['langlist']);
|
|
|
|
$language = array_pop($_SESSION['langlist']);
|
|
|
|
}
|
|
|
|
if ($language === null) {
|
|
|
|
unset($_SESSION['langlist']);
|
|
|
|
echo json_encode('done');
|
|
|
|
return;
|
|
|
|
}
|
2012-08-21 20:22:56 +00:00
|
|
|
$update = new Msd_Update(APPLICATION_PATH . '/configs/update.ini');
|
2011-06-10 21:55:32 +00:00
|
|
|
$update->setUpdateParam('language', $language);
|
|
|
|
$update->setUpdateParam('version', $version->getMsdVersion());
|
|
|
|
$updateResult = $update->doUpdate('language', $files);
|
|
|
|
if (!($updateResult === true)) {
|
|
|
|
switch ($updateResult['action']) {
|
|
|
|
case 'connection':
|
|
|
|
$message = array('L_UPDATE_CONNECTION_FAILED',
|
2012-08-21 20:22:56 +00:00
|
|
|
$updateResult['server']);
|
2011-06-10 21:55:32 +00:00
|
|
|
break;
|
|
|
|
case 'saveresponse':
|
|
|
|
$message = array('L_UPDATE_ERROR_RESPONSE',
|
2012-08-21 20:22:56 +00:00
|
|
|
$updateResult['status']);
|
2011-06-10 21:55:32 +00:00
|
|
|
break;
|
|
|
|
case 'createfile':
|
|
|
|
$message = array('L_WRONG_RIGHTS',
|
2012-08-21 20:22:56 +00:00
|
|
|
$updateResult['file'],
|
|
|
|
'0777');
|
2011-06-10 21:55:32 +00:00
|
|
|
break;
|
|
|
|
case 'getrequest':
|
|
|
|
$message = array('L_UPDATE_ERROR_RESPONSE',
|
2012-08-21 20:22:56 +00:00
|
|
|
$updateResult['status']);
|
2011-06-10 21:55:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$message = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($message !== '') {
|
|
|
|
$this->view
|
2012-08-21 20:22:56 +00:00
|
|
|
->popUpMessage()
|
|
|
|
->addMessage(
|
|
|
|
'update-message',
|
|
|
|
'L_LOGIN',
|
|
|
|
$message,
|
|
|
|
array(
|
|
|
|
'modal' => true,
|
|
|
|
'dialogClass' => 'error'
|
|
|
|
)
|
|
|
|
);
|
2011-06-10 21:55:32 +00:00
|
|
|
$updateResult['message'] = (string)$this->view->popUpMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(
|
|
|
|
array(
|
2012-08-21 20:22:56 +00:00
|
|
|
'language' => $language,
|
|
|
|
'success' => ($updateResult === true) ? true : false,
|
|
|
|
'error' => ($updateResult === true) ? '' : $updateResult
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP or MySQL version requirements are not met.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function badversionAction()
|
|
|
|
{
|
|
|
|
$translator = Msd_Language::getInstance()->getTranslator();
|
2012-08-21 20:22:56 +00:00
|
|
|
$messageId = $this->_request->get('message');
|
|
|
|
$message = $translator->_($messageId);
|
2011-06-10 21:55:32 +00:00
|
|
|
if ($messageId == 'L_PHP_VERSION_TOO_OLD') {
|
|
|
|
$this->view->message = sprintf(
|
|
|
|
$message,
|
|
|
|
$this->version->getRequiredPhpVersion(),
|
|
|
|
PHP_VERSION
|
|
|
|
);
|
|
|
|
} else {
|
2012-08-21 20:22:56 +00:00
|
|
|
$dbObject = Msd_Db::getAdapter();
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->view->message = sprintf(
|
|
|
|
$message,
|
|
|
|
$dbObject->getServerInfo(),
|
|
|
|
$this->version->getRequiredMysqlVersion()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|