/** * 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; }
/** * 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 base URL * * @return string */ function getBaseUrl() { $port = getUriPort(); return getUriScheme() . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''); }