/** * Obtains an authorization token for the specified domain * administrator. The admin_email and admin_password * parameteters are always required. captcha_token and * captcha_response should be the empty string unless * a CAPTCHA response is required. */ function GetAuthToken($admin_email, $admin_password, $captcha_token, $captcha_response) { $post_url = "https://www.google.com/accounts/ClientLogin"; $post_data = "accountType=HOSTED&Email=" . $admin_email . "&Passwd=" . $admin_password; if ($captcha_token != "") { $post_data .= "&logintoken=" . urlencode($captcha_token); } if ($captcha_response != "") { $post_data .= "&logincaptcha=" . urlencode($captcha_response); } $result = ExecutePost($post_url, $post_data); /* * If we were successful, return the authentication token * in the "SID=..." line. If CAPTCHA authentication is * required, return an error message indicating as much. * Otherwise, just return whatever error message we got. */ if ($result && preg_match('/^SID=(\\S+)/', $result, $parsed_sid_line)) { return $parsed_sid_line[1]; } else { if ($result && preg_match('/Error=CaptchaRequired/', $result) && preg_match('/CaptchaToken=(\\S+)/', $result, $token) && preg_match('/CaptchaUrl=(\\S+)/', $result, $url)) { $full_url = "https://www.google.com/accounts/" . $url[1]; return "Authentication failed. Please retry with token " . $token[1] . " and the text you see at " . $full_url; } else { return $result; } } }
/** * Retrieves specified report for the domain and date specified. * An authorization token (obtained with GetAuthToken()) and * the domain must also be provided. * $report_name can be one of the following values: * - accounts * - activity * - disk_space * - email_clients * - quota_limit_accounts * - summary * - suspended_accounts */ function RetrieveReport($token, $domain, $date, $report_name, $report_description) { global $service_url; /* Set up the XML document to POST. */ $post_document = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $post_document .= '<rest xmlns="google:accounts:rest:protocol"' . ' xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">' . "\n"; $post_document .= ' <type>Report</type>' . "\n"; $post_document .= ' <token>' . $token . '</token>' . "\n"; $post_document .= ' <domain>' . $domain . '</domain>' . "\n"; $post_document .= ' <date>' . $date . '</date>' . "\n"; $post_document .= ' <reportType>daily</reportType>' . "\n"; $post_document .= ' <reportName>' . $report_name . '</reportName>' . "\n"; $post_document .= '</rest>' . "\n"; /* Execute the POST. */ $result = ExecutePost($service_url, $post_document); if (!$result) { return "Unable to retrieve " . $report_description . " Report. (Unknown error)"; } else { return $result; } }
/** * Deletes the specified alias. An authorization token * (obtained with GetAuthToken()) and the domain must * also be provided. */ function DeleteAlias($token, $domain, $alias_name) { global $service_url, $service_version; /* Set up the XML document to POST. */ $post_document = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $post_document .= '<hs:rest xmlns:hs="google:accounts:rest:protocol"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . "\n"; $post_document .= '<hs:type>Alias</hs:type>' . "\n"; $post_document .= '<hs:token>' . $token . '</hs:token>' . "\n"; $post_document .= '<hs:domain>' . $domain . '</hs:domain>' . "\n"; $post_document .= '<hs:queryKey>aliasName</hs:queryKey>' . "\n"; $post_document .= '<hs:queryData>' . $alias_name . '</hs:queryData>' . "\n"; $post_document .= '</hs:rest>' . "\n"; /* Execute the POST. */ $result = ExecutePost($service_url . "/" . $service_version . "/Delete/Alias", $post_document); if (!$result) { return "Unable to delete alias. (Unknown error)"; } else { return $result; } }
/** * Updates the specified user's account status. If $status * is "locked", the user's email account is disabled; if * $status is "unlocked", the user's email account is enabled. * * An authorization token and domain must also be provided. */ function SetAccountStatus($token, $domain, $user_name, $status) { global $service_url, $service_version; /* Set up the XML document to POST. */ $post_document = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $post_document .= '<hs:rest xmlns:hs="google:accounts:rest:protocol"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . "\n"; $post_document .= '<hs:type>Account</hs:type>' . "\n"; $post_document .= '<hs:token>' . $token . '</hs:token>' . "\n"; $post_document .= '<hs:domain>' . $domain . '</hs:domain>' . "\n"; $post_document .= '<hs:queryKey>userName</hs:queryKey>' . "\n"; $post_document .= '<hs:queryData>' . $user_name . '</hs:queryData>' . "\n"; $post_document .= '<hs:UpdateSection>' . "\n"; $post_document .= ' <hs:accountStatus>' . $status . '</hs:accountStatus>' . "\n"; $post_document .= '</hs:UpdateSection>' . "\n"; $post_document .= '</hs:rest>' . "\n"; /* Execute the POST. */ $result = ExecutePost($service_url . "/" . $service_version . "/Update/Account/Status", $post_document); if (!$result) { return "Unable to change account status. (Unknown error)"; } else { return $result; } }