PHPLoginAsExample

From Rackspace Email & Apps API
Revision as of 16:58, 25 August 2008 by APIAdmin (talk | contribs) (New page: This is a PHP script that can be used by administrators to login to the webmail client as a user, without using the user's passwword.. This is often useful when troubleshooting. Please n...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a PHP script that can be used by administrators to login to the webmail client as a user, without using the user's passwword.. This is often useful when troubleshooting. Please note: replace the admin username included in the code with the username of a real admin account-- preferably a limited admin with no rights to do anything in the control panel.

Put the PHP script on a PHP-aware web server, and navigate to the page using your browser. Enter the email address of the person whose email account needs to be viewed, then put in the password of the administrative account you configured for use with this script. Please note that this script does not rely on nusoap, but instead assumes that PHP has been compiled for SOAP support-- but it should be easy to write this script to use nusoap instead.



<?
function show_form($username="", $detail="") {
?>
<html>
<head><title>Login tool</title></head><body>
<form action="myself.php" method="post">
<br>
Email address: <input type=text name=email value="<?echo $email?>"><br><br>
Admin password: <input type=password name=detail value="<?echo $detail?>"><br>
<input type=submit>
</form>
</body>
</html>
<? }

$email = $_POST['email'];
$detail = $_POST['detail'];

if(isset($email)) {
  if(isset($detail)) {
    $splitaddress = explode("@", $email);
    $client = new SoapClient('https://secure.webmail.us/mail31/soap/soap_server.php?wsdl', array('trace' => true, 'exceptions' => true));

  $res = $client->__soapCall('LoginUserWebmail',
    array('ResellerUsername' => 'LoginAsAdminUser',
    'ResellerPassword' => $detail,
    'HostName' => $splitaddress[1],
    'UserID' => $splitaddress[0],''));
  if ($client->fault) {
    echo "FAULT: ";
  print_r($res);
  exit;
  }

  header("Location: https://secure.webmail.us/mail/src/redirect.php?user_name=$email&emailaddress=$email&sessionID=$res[SessionID]");
 } 
  else { show_form($email,detail); }
}
else { show_form($email,$detail); }
?>