/** * Start a dashboard session. * * It doesn't follow the normal pattern since it's working off Drupal's login * forms directly. This will be refactored when there's a direct CLI auth * mechanism in the API itself. * * Many thanks to Amitai and the gang at: https://drupal.org/node/89710 */ function auth($email, $password) { if (!$email) { $email = drush_get_option('email'); } $host = TERMINUS_HOST; $url = 'https://' . $host . '/login'; $ch = curl_init(); if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); } // Set URL and other appropriate options. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Grab URL and pass it to the browser. $result = curl_exec($ch); if (curl_errno($ch) != 0) { $err = curl_error($ch); curl_close($ch); return \Terminus::error("Dashboard unavailable: {$err}"); } $form_build_id = get_form_build_id($result); // Attempt to log in. $login_data = array('email' => $email, 'password' => $password, 'form_build_id' => $form_build_id, 'form_id' => 'atlas_login_form', 'op' => 'Login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data); curl_setopt($ch, CURLOPT_HEADER, 1); $result = curl_exec($ch); if (curl_errno($ch) != 0) { $err = curl_error($ch); return \Terminus::error("Dashboard unavailable: {$err}"); } // Close cURL resource, and free up system resources. curl_close($ch); $set_cookie_header = parse_drupal_headers($result, 'Set-Cookie'); if (!$set_cookie_header) { return \Terminus::error('Authentication failed. Please check your credentials and try again.'); } $session = get_session_from_header($set_cookie_header); if (!$session) { return \Terminus::error('Session not found. Please check your credentials and try again.'); } // Get the UUID. $user_uuid = get_user_uuid_from_headers($result); if (!\Terminus\Utils\is_valid_uuid($user_uuid)) { return \Terminus::error('Could not determine user UUID. Please check your credentials and try again.'); } // Prepare credentials for storage. $data = array('user_uuid' => $user_uuid, 'session' => $session, 'session_expire_time' => get_session_expiration_from_header($set_cookie_header), 'email' => $email); return $data; }
protected function _validateSiteUuid($site) { if (\Terminus\Utils\is_valid_uuid($site) && property_exists($this->sites, $site)) { $this->_siteInfo =& $this->sites[$site]; $this->_siteInfo->site_uuid = $site; } elseif ($this->_siteInfo = $this->fetch_site($site)) { $site = $this->_siteInfo->site_uuid; } else { Terminus::error("Unable to locate the requested site."); } return $site; }