查看單個文章
  #2  
舊 2006-05-04, 02:00 AM
wmh wmh 目前離線
進階會員
 
註冊日期: 2004-08-27
文章: 310
預設

A create user sample code for 'Gmail for your domain' written in PHP.

以下範例可以透過 php 去申請一個帳號(沒錯只有一個, 因為還沒有介面, 只有一個流程), 只要修改前幾行, php 的部分需要有 SSL 支援. 期待有人繼續修改為完整的介面, 當然我有空也會繼續改寫.

代碼:
<?php

//Gmail for your domain settings
$dn['domain']	= "mydomain.com";	//你的 domain name
$dn['username'] = "admin";		//管理者帳號
$dn['password'] = "passofadmin";	//管理者密碼

//To Create Account
$ac['firstName'] = "Hunter";		//以下幾個是要申請的帳號資料, 不贅述了
$ac['lastName'] = "Wu";		//
$ac['userName'] = "huntertest";	//
$ac['passwordAlpha'] = "123456";	//
$ac['passwordBeta'] =  "123456";	//

/*** don't change below ***/

$host = "www.google.com";
$port = "443";
$pathDashboard = 		"/hosted/{$dn['domain']}/Dashboard";
$pathLoginAction = 	"/hosted/{$dn['domain']}/LoginAction";
$pathCreateUser = 	"/hosted/{$dn['domain']}/CreateUser";
$pathCreateUserAction = "/hosted/{$dn['domain']}/CreateUserAction";
$timeout = 30;

//1.Connect and get CP_AT

$fp = fConnect($host, $port, $timeout);
fGet($fp, $host, $pathDashboard, "");
$content = fContentAllTill($fp, "</html>");

$cp_at = parseCPAT($content);
if ($cp_at == null) {
	echo "Get CP_AT error!";
	exit;
}

//2.LoginAction

$fp = fConnect($host, $port, $timeout);
$data = "at=$cp_at".
		"&continue=https://www.google.com$pathDashboard".
		"&service=CPanel".
		"&userName={$dn['username']}".
		"&password={$dn['password']}";
fPost($fp, $host, $pathLoginAction, $data, "Cookie: CP_AT=$cp_at");
$content = fContentAllTill($fp, "Server:");
$cookies = parseCookies($content);

//3.Dashboard

$fp = fConnect($host, $port, $timeout);
fGet($fp, $host, $pathDashboard, $cookies.";CP_AT=$cp_at");
$content = fContentAllTill($fp, "</html>");

//4.CreateUserPage

$fp = fConnect($host, $port, $timeout);
fGet($fp, $host, $pathCreateUser, $cookies.";CP_AT=$cp_at");
$content = fContentAllTill($fp, "</html>");
$initialPassword = parseInitialPassword($content);

//5.CreateUser

$fp = fConnect($host, $port, $timeout);
$data = "at=$cp_at".
		"&initialPassword=$initialPassword".
		"&firstName={$ac['firstName']}".
		"&lastName={$ac['lastName']}".
		"&userName={$ac['userName']}".
		"&password.isSet=true".
		"&password.newPasswords.alpha={$ac['passwordAlpha']}".
		"&password.newPasswords.beta={$ac['passwordBeta']}".
		"&add+user=Add+User";
fPost($fp, $host, $pathCreateUserAction, $data, $cookies.";CP_AT=$cp_at");
$content = fContentAllTill($fp, "</html>");

//還沒完喔, 一次沒辦法發完, 請接下一篇 ...
回覆時引用此篇文章