2017-01-18 4 views
0

おはようございますSOコミュニティ、PHP/Cpanel - サードパーティアプリケーションなしでcPanelアカウントを作成するには?

私は動的にPHPでcPanelアカウントを作成する方法を見つけようとしています。質問前の調査をしているうちに、私はこの質問がかなり数回聞かれたことに気付き、いくつかの回答がありました。残念ながら、私が見つけた答えは最新のcPanelバージョンでは下がっているようです。私は以下のスクリプトを動作させようとしていたが、運がなかった。 注:私はスクリプトを作成していない、私はちょうどソースを忘れてしまった。パッケージをホスティングしてcPanelアカウントを作成する方法がわかっている場合は、教えてください。

<?php 

############################################################### 
# cPanel WHM Account Creator 1.1 
############################################################### 
# Visit http://www.zubrag.com/scripts/ for updates 
############################################################### 
# Required parameters: 
# - domain - new account domain 
# - user - new account username 
# - password - new account password 
# - package - new account hosting package (plan) 
# - email - contact email 
# 
# Sample run: create-whm-account.php?domain=reseller.com&user=hosting&password=manager&package=unix_500 
# 
# If no parameters passed then input form will be shown to enter data. 
# 
# This script can also be run from another PHP script. This may 
# be helpful if you have some user interface already in place and 
# want to automatically create WHM accounts from there. 
# In this case you have to setup following variables instead of 
# passing them as parameters: 
# - $user_domain - new account domain 
# - $user_name - new account username 
# - $user_pass - new account password 
# - $user_plan - new account hosting package (plan) 
# - $user_email - contact email 
# 
############################################################### 

/////// YOUR WHM LOGIN DATA 
$whm_user = "root";  // reseller username 
$whm_pass = "PASS"; // the password you use to login to WHM 

##################################################################################### 
##############   END OF SETTINGS. DO NOT EDIT BELOW ####################### 
##################################################################################### 

$whm_host = $_SERVER['HTTP_HOST']; 

function getVar($name, $def = '') { 
    if (isset($_REQUEST[$name])) 
    return $_REQUEST[$name]; 
    else 
    return $def; 
} 

// Domain name of new hosting account 
// To create subdomain just pass full subdomain name 
// Example: newuser.zubrag.com 
if (!isset($user_domain)) { 
    $user_domain = getVar('domain'); 
} 

// Username of the new hosting account 
if (!isset($user_name)) { 
    $user_name = getVar('user'); 
} 

// Password for the new hosting account 
if (!isset($user_pass)) { 
    $user_pass = getVar('password'); 
} 

// New hosting account Package 
if (!isset($user_plan)) { 
    $user_plan = getVar('package'); 
} 

// Contact email 
if (!isset($user_email)) { 
    $user_email = getVar('email'); 
} 

// if parameters passed then create account 
if (!empty($user_name)) { 

    // create account on the cPanel server 
    $script = "http://{$whm_user}:{$whm_pass}@{$whm_host}:2086/scripts/wwwacct"; 
    $params = "?plan={$user_plan}&domain={$user_domain}&username={$user_name}&password={$user_pass}&contactemail={$user_email}"; 
    $result = file_get_contents($script.$params); 

    // output result 
    echo "RESULT: " . $result; 
} 
// otherwise show input form 
else { 
$frm = <<<EOD 
<html> 
<head> 
    <title>cPanel/WHM Account Creator</title> 
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> 
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
</head> 
<body> 
    <style> 
    input { border: 1px solid black; } 
    </style> 
<form method="post"> 
<h3>cPanel/WHM Account Creator</h3> 
<table border="0"> 
<tr><td>Domain:</td><td><input name="domain" size="30"></td><td>Subdomain or domain, without www</td></tr> 
<tr><td>Username:</td><td><input name="user" size="30"></td><td>Username to be created</td></tr> 
<tr><td>Password:</td><td><input name="password" size="30"></td><td></td></tr> 
<tr><td>Package:</td><td><input name="package" size="30"></td><td>Package (hosting plan) name. Make sure you cpecify existing package</td></tr> 
<tr><td>Contact Email:</td><td><input name="email" size="30"></td><td></td></tr> 
<tr><td colspan="3"><br /><input type="submit" value="Create Account"></td></tr> 
</table> 
</form> 
</body> 
</html> 
EOD; 
echo $frm; 
} 

?> 

さらに詳しい情報が必要な場合はお知らせください。

はEIDTは、私は最近、問題の原因を発見した ティム

、事前にありがとうございます。 cPanel/WHMは今セキュリティトークンを強制します。だから、上記のスクリプトを使ってログインできたらうまくいくでしょう。私はphpを使ってURLをエコーし​​てみました。それをコピーしてブラウザに貼り付けました。それから、手動でログインするようになりました。いったん完了すると、完全に実行されました。しかし、私はまだそれをPHPで実行することはできません。

アイデア?

+1

ソースは:https://github.com/Ephygtz/cPanel-WHM-automated-account-creator/blob/master/create-whm-account.php –

+0

はソースを提供いただき、ありがとうございます! –

+0

申し訳ありませんが、より最近のcPanel(68.0)バージョンで動作する方法は見つかりましたか? –

答えて

0

こんにちは、

私は少し日付でこの質問を知っているが、私は私の作品解決策を発見しました。下記を参照してください。

<?php 
    Function createAccount ($newDomain = "", $newUser = "", $newPass = "", $newPlan = "", $newEmail = "") { 
     $whm_user = "usename"; 
     $whm_pass = "password"; 
     $whm_host = "example.com"; 

     $newDomain = fixData($newDomain); 
     $newUser = fixData($newUser); 
     $newPlan = fixData($newPlan); 

     If (!empty($newUser)) { 
      // Get new session ID 
      $sessID = newSession($whm_host, $whm_user, $whm_pass); 

      $script = "https://www." . $whm_host . ":2087" . $sessID . "/scripts/wwwacct"; 
      $sData = "?plan={$newPlan}&domain={$newDomain}&username={$newUser}&password={$newPass}&contactemail={$newEmail}"; 

      // Authenticate User for WHM access 
      $context = stream_context_create(array(
       'http' => array(
        'header' => "Authorization: Basic " . base64_encode("{$whm_user}:{$whm_pass}"), 
       ), 
      )); 

      // Get result 
      $result = file_get_contents($script.$sData, false, $context); 
      //Echo "URL: " . $script.$sData . "<br /><br />"; 
      // Echo "Result: " . $result; 

     } Else { 
      Echo "Error: Username is empty!"; 
     } 
    } 


    Function newSession($nHost, $nUser, $nPass) { // Example details 
     $ip = $nHost; 
     $cp_user = $nUser; 
     $cp_pwd = $nPass; 
     $url = "https://$ip:2087/login"; 

     // Create new curl handle 
     $ch=curl_init(); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd"); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 100020); 

     // Execute the curl handle and fetch info then close streams. 
     $f = curl_exec($ch); 
     $h = curl_getinfo($ch); 
     curl_close($ch); 

     // If we had no issues then try to fetch the cpsess 
     if ($f == true and strpos($h['url'],"cpsess")) 
     { 
      // Get the cpsess part of the url 
      $pattern="/.*?(\/cpsess.*?)\/.*?/is"; 
      $preg_res=preg_match($pattern,$h['url'],$cpsess); 
     } 

     // If we have a session then return it otherwise return empty string 
     return (isset($cpsess[1])) ? $cpsess[1] : ""; 
    } 

    Function fixData($data) { 
     $data = str_replace("-","%2D",$data); 
     $data = str_replace(".","%2E",$data); 
     $data = str_replace(" ","%20",$data); 

     return $data; 
    } 

    Function returnData($data) { 
     $data = str_replace("%2D","-",$data); 
     $data = str_replace("%2E",".",$data); 
     $data = str_replace("%20"," ",$data); 

     return $data; 
    } 
    header('Location: https://www.example.com/users'); 
?> 
+0

この方法は残念ながらもう動作しません。 –

関連する問題