/** * Pydio authentication * * @param int $userId ftp username * @return bool FALSE on failure */ function client_pydioAuth($userId) { if (file_exists(GUI_ROOT_DIR . '/data/tmp/failedAJXP.log')) { @unlink(GUI_ROOT_DIR . '/data/tmp/failedAJXP.log'); } $credentials = _client_pydioGetLoginCredentials($userId); if (!$credentials) { set_page_message(tr('Unknown FTP user.'), 'error'); return false; } $contextOptions = array(); // Prepares Pydio absolute Uri to use if (isSecureRequest()) { $contextOptions = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true)); } $pydioBaseUrl = getBaseUrl() . '/ftp/'; $port = getUriPort(); // Pydio authentication $context = stream_context_create(array_merge($contextOptions, array('http' => array('method' => 'GET', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'User-Agent: i-MSCP', 'Connection: close'))))); # Getting secure token $secureToken = file_get_contents("{$pydioBaseUrl}/index.php?action=get_secure_token", false, $context); $postData = http_build_query(array('get_action' => 'login', 'userid' => $credentials[0], 'login_seed' => '-1', "remember_me" => 'false', 'password' => stripcslashes($credentials[1]), '_method' => 'put')); $contextOptions = array_merge($contextOptions, array('http' => array('method' => 'POST', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'Content-Type: application/x-www-form-urlencoded', 'X-Requested-With: XMLHttpRequest', 'Content-Length: ' . strlen($postData), 'User-Agent: i-MSCP', 'Connection: close'), 'content' => $postData))); stream_context_set_default($contextOptions); # TODO Parse the full response and display error message on authentication failure $headers = get_headers("{$pydioBaseUrl}?secure_token={$secureToken}", true); _client_pydioCreateCookies($headers['Set-Cookie']); redirectTo($pydioBaseUrl); exit; }
} } redirectToUiLevel(); $tpl = new iMSCP_pTemplate(); $tpl->define_dynamic(array('layout' => 'shared/layouts/simple.tpl', 'page_message' => 'layout', 'lostpwd_button' => 'page')); $tpl->assign(array('productLongName' => tr('internet Multi Server Control Panel'), 'productLink' => 'http://www.i-mscp.net', 'productCopyright' => tr('© 2010-2015 i-MSCP Team<br/>All Rights Reserved'))); /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); if ($cfg['MAINTENANCEMODE'] && !isset($_GET['admin'])) { $tpl->define_dynamic('page', 'message.tpl'); $tpl->assign(array('TR_PAGE_TITLE' => tr('i-MSCP - Multi Server Control Panel / Maintenance'), 'HEADER_BLOCK' => '', 'BOX_MESSAGE_TITLE' => tr('System under maintenance'), 'BOX_MESSAGE' => isset($cfg['MAINTENANCEMODE_MESSAGE']) ? preg_replace('/\\s\\s+/', '', nl2br(tohtml($cfg['MAINTENANCEMODE_MESSAGE']))) : tr("We are sorry, but the system is currently under maintenance.\nPlease try again later."), 'TR_BACK' => tr('Administrator login'), 'BACK_BUTTON_DESTINATION' => '/index.php?admin=1')); } else { $tpl->define_dynamic(array('page' => 'index.tpl', 'lost_password_support' => 'page', 'ssl_support' => 'page')); $tpl->assign(array('TR_PAGE_TITLE' => tr('i-MSCP - Multi Server Control Panel / Login'), 'TR_LOGIN' => tr('Login'), 'TR_USERNAME' => tr('Username'), 'UNAME' => isset($_POST['uname']) ? tohtml($_POST['uname'], 'htmlAttr') : '', 'TR_PASSWORD' => tr('Password'))); if ($cfg->exists('PANEL_SSL_ENABLED') && $cfg['PANEL_SSL_ENABLED'] == 'yes' && $cfg['BASE_SERVER_VHOST_PREFIX'] != 'https://') { $isSecure = isSecureRequest() ? true : false; $uri = array($isSecure ? 'http://' : 'https://', $_SERVER['SERVER_NAME'], $isSecure ? $cfg['BASE_SERVER_VHOST_HTTP_PORT'] == 80 ? '' : ':' . $cfg['BASE_SERVER_VHOST_HTTP_PORT'] : ($cfg['BASE_SERVER_VHOST_HTTPS_PORT'] == 443 ? '' : ':' . $cfg['BASE_SERVER_VHOST_HTTPS_PORT'])); $tpl->assign(array('SSL_LINK' => tohtml(implode('', $uri), 'htmlAttr'), 'SSL_IMAGE_CLASS' => $isSecure ? 'i_unlock' : 'i_lock', 'TR_SSL' => $isSecure ? tr('Normal connection') : tr('Secure connection'), 'TR_SSL_DESCRIPTION' => $isSecure ? tohtml(tr('Use normal connection (No SSL)'), 'htmlAttr') : tohtml(tr('Use secure connection (SSL)'), 'htmlAttr'))); } else { $tpl->assign('SSL_SUPPORT', ''); } if ($cfg['LOSTPASSWORD']) { $tpl->assign('TR_LOSTPW', tr('Lost password')); } else { $tpl->assign('LOST_PASSWORD_SUPPORT', ''); } } generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); $eventManager::getInstance()->dispatch(iMSCP_Events::onLoginScriptEnd, array('templateEngine' => $tpl)); $tpl->prnt();
/** * PhpMyAdmin authentication * * @param int $dbUserId Database user unique identifier * @return bool FALSE on faillure */ function client_pmaAuth($dbUserId) { $credentials = _client_pmaGetLoginCredentials($dbUserId); if ($credentials) { $postData = http_build_query(array('pma_username' => $credentials[0], 'pma_password' => stripcslashes($credentials[1]))); } else { set_page_message(tr('Unknown SQL user'), 'error'); return false; } $contextOptions = array(); // Prepares PhpMyadmin absolute Uri to use if (isSecureRequest()) { $contextOptions = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true)); } $pmaBaseUrl = getBaseUrl() . '/pma/'; $port = getUriPort(); $contextOptions = array_merge($contextOptions, array('http' => array('method' => 'POST', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($postData), 'User-Agent: i-MSCP', 'Connection: close'), 'content' => $postData, 'max_redirects' => 1))); stream_context_set_default($contextOptions); // Gets the headers from PhpMyAdmin $headers = get_headers($pmaBaseUrl, true); if ($headers && isset($headers['Location'])) { _client_pmaCreateCookies($headers['Set-Cookie']); redirectTo(_client_pmaSetLanguage($headers['Location'])); } set_page_message(tr('An error occurred during authentication.'), 'error'); return false; }
/** * Get URI port * * @return string */ function getUriPort() { $config = iMSCP_Registry::get('config'); return isSecureRequest() ? $config['BASE_SERVER_VHOST_HTTPS_PORT'] == 443 ? '' : $config['BASE_SERVER_VHOST_HTTPS_PORT'] : ($config['BASE_SERVER_VHOST_HTTP_PORT'] == 80 ? '' : $config['BASE_SERVER_VHOST_HTTP_PORT']); }