#1
|
|||
|
|||
測試一下發文
台灣網域名稱俱樂部 > 電腦與網路技術 > 電腦網路相關技術
Forbidden You don't have permission to access /newthread.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. |
#2
|
|||
|
|||
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>"); //還沒完喔, 一次沒辦法發完, 請接下一篇 ... |
#4
|
|||
|
|||
我無法一次發完...不知道是不是新版的 vbb 在 [code] 的部份有什麼限制
|
#5
|
|||
|
|||
請接第一篇的程式
代碼:
// functions // function fConnect($host, $port, $timeout) { if ($port == 443) $host = "ssl://$host"; $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fp) { echo "$errstr ($errno)<br />\n"; exit(); } else { return $fp; } } function fGet($fp, $host, $path, $extra) { $getContent = "GET $path HTTP/1.1\r\n"; $getContent .= "Host: $host\r\n"; $getContent .= "Accept: */*\r\n"; $getContent .= "Accept-Language: zh-tw\r\n"; $getContent .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n"; $getContent .= "Connection: Keep-Alive"; if ($extra != "") $getContent .= "\r\n$extra"; fputs($fp, $getContent."\r\n\r\n"); } function fPost($fp, $host, $path, $data, $extra) { $dataLength = strlen($data); $postContent = "POST $path HTTP/1.1\r\n"; $postContent .= "Host: $host\r\n"; $postContent .= "Content-Type: application/x-www-form-urlencoded\r\n"; $postContent .= "Content-Length: $dataLength\r\n"; $postContent .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n"; $postContent .= "Connection: Keep-Alive"; if ($extra != "") $postContent .= "\r\n$extra"; $postContent .= "\r\n\r\n"; $postContent .= $data; fputs($fp, $postContent); } function fContentAllTill($fp, $till) { $content = ""; while (!feof($fp)) { @$tmp = fgets($fp, 16192); if ($tmp) $content .= $tmp; if (strstr($tmp, $till)) break; } return $content; } function parseCPAT($content) { if (preg_match("/CP_AT=([^;]{20,40});/", $content, $tmp)) { return $tmp[1]; } return null; } function parseCookies($content) { $rtn = ""; while (preg_match("/Set-Cookie: (.*)\r/", $content, $tmp)) { if ($rtn != "") $rtn .= "\r\n"; $rtn .= "Cookie: {$tmp[1]}"; $content = str_replace($tmp[0], "", $content); } return $rtn; } function parseInitialPassword($content) { if (preg_match("/<input type=\"hidden\" name=\"initialPassword\" value=\"(.{6})\">/", $content, $tmp)) { return $tmp[1]; } return null; } ?> DONE! |
#7
|
|||
|
|||
不知道是不是 AJAX 的部分有限制還是說有 bug?可能要問一下本站的 CTO (技術長) CKMARK 才知道
|
#8
|
|||
|
|||
不知要怎麼使用這一個PHP程式?直接在支援PHP的SERVER上執行就可以了嗎?
謝謝 |
#9
|
|||
|
|||
有需要 windows 版 php with ssl 的人可以抓:
http://68.3.100.153:4561/wmh/php4ts.withSSL.rar 裡面有三個 dll 是 php 4.3.11 的,版本接近的 php (4.3.x) 都可以通用 libeay32.dll php4ts.dll ssleay32.dll 全部複製到 %systemroot%/system32/ 目錄下並重新啟動 apache 即可,當然記得先備份自己的檔案,免得不能用又無法復原。 |
#10
|
|||
|
|||
引用:
只需要 php,但是 php 需要支援 ssl ,如果沒有的話應該可以請管理者幫你,我去國外申請的空間就有支援。 |