Ide bikin billing pengganti v7


Status
Not open for further replies.

ryraNetworks

Apprentice 2.0
iNota itu om,, cari murah 30rb/bln kl ga salah,, malah nasib... skrg sdh ga dikembangkan lagi,,
pdhl kebutuhan saya sebenernya sederhana, asal bisa create domain & hosting otomatis sama form order & billing aja utk pengingat tagihan

maKanya kl ada produk indo yg harganya bersahabat saya sangat mendukung..
 

Rockman

Hosting Guru
Verified Provider
iNota itu om,, cari murah 30rb/bln kl ga salah,, malah nasib... skrg sdh ga dikembangkan lagi,,
pdhl kebutuhan saya sebenernya sederhana, asal bisa create domain & hosting otomatis sama form order & billing aja utk pengingat tagihan
maKanya kl ada produk indo yg harganya bersahabat saya sangat mendukung..

Kita masih bisa menggunakan script creator account otomatis untuk order hosting dengan mengintegrasikan 2 script dari Lautaro Angélico ( sumber http://www.webhostingtalk.com/showthread.php?t=1251440 )

Code:
<?php
/* --------------------------------------------------------------------

  cPanel/WHM Account Creator

  @version    1.0.0
  @author    Lautaro Angélico

  --------------------------------------------------------------------- */

class cPHPAC {

    private $request_url;
    public $error;
    public $error_msg;
    public $return_data;
 
    private $password_limit;
 
    private $whm_ip;
    private $whm_port;
    private $whm_https;
    private $whm_user;
    private $whm_pass;
    private $whm_plan;
 
    private $account_username;
    private $account_password;
    private $account_email;
    private $account_domain;
 
    function __construct() {
 
        ($this->check($this->password_limit)) ? null : $this->password_limit = 32;
        ($this->check($this->whm_port)) ? null : $this->whm_port = 2087;
        ($this->check($this->whm_https)) ? null : $this->whm_https = true;
 
    }
 
    function createAccount($user,$pass,$email,$domain) {
        if($this->check($user) && $this->check($pass) && $this->check($email) && $this->check($domain)) {
            $this->account_username = $user;
            $this->account_password = $pass;
            $this->account_email = $email;
            $this->account_domain = $domain;
            if($this->validateUsername() && $this->validatePassword() && $this->validateEmail()) {
                $create = $this->callAPI();
                $result = json_decode($create, true);
                if($result['result'][0]['status'] == 0) {
                    $this->error = true;
                    $this->error_msg = $result['result'][0]['statusmsg'];
                } else {
                    // SUCCESS!
                    $return = array(
                        'status' => 1,
                        'statusmsg' => $result['result'][0]['statusmsg'],
                        'domain' => $this->account_domain,
                        'ip' => $result['result'][0]['options']['ip'],
                        'username' => $this->account_username,
                        'password' => $this->account_password,
                        'email' => $this->account_email,
                        'package' => $result['result'][0]['options']['package'],
                        'ns1' => $result['result'][0]['options']['nameserver'],
                        'ns2' => $result['result'][0]['options']['nameserver2']
                    );
                    $this->return_data = $return;
                }
            }
        } else {
            $this->error = true;
            $this->error_msg = "Please provide all the required information to create a new account.";
        }
    }
 
    function validateUsername() {
        $usr = $this->account_username;
        $chk = (bool)preg_match("/^[0-9a-zA-Z]+$/", $usr);
        if($chk) {
            if(strlen($usr) >= 1 && strlen($usr) <= 8) {
                $this->error = false;
                return true;
            } else {
                $this->error = true;
                $this->error_msg = "The username length must be 1 to 8 characters.";
                return false;
            }
        } else {
            $this->error = true;
            $this->error_msg = "The username can contain letters and numbers only.";
            return false;
        }
    }
 
    function validatePassword() {
        $pass = $this->account_password;
        if(strlen($pass) >= 6 && strlen($pass) <= $this->password_limit) {
            $this->error = false;
            return true;
        } else {
            $this->error = true;
            $this->error_msg = "The password length is not valid.";
            return false;
        }
    }
 
    function validateEmail() {
        $email = $this->account_email;
        $chk = (bool)preg_match("/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i", $email);
        if($chk) {
            $this->error = false;
            return true;
        } else {
            $this->error = true;
            $this->error_msg = "The email address is invalid.";
            return false;
        }
    }
 
    public function setIP($ip_address) {
        $this->whm_ip = $ip_address;
    }
 
    public function setPort($port=2087) {
        $this->whm_port = $port;
    }
 
    public function useHTTPS($cond) {
        if($cond) {
            $this->whm_https = true;
        } else {
            $this->whm_https = false;
        }
    }
 
    public function setUsername($username) {
        $this->whm_user = $username;
    }
 
    public function setPassword($password) {
        $this->whm_pass = $password;
    }
 
    public function setPasswordLimit($value) {
        if($value >= 6) {
            $this->password_limit = $value;
        } else {
            $this->password_limit = 6;
        }
    }
 
    public function setPlan($plan) {
        $this->whm_plan = $plan;
    }
 
    private function buildRequestURL() {
        ($this->whm_https) ? $build_req_url = 'https://' : $build_req_url = 'http://';
        $build_req_url .= $this->whm_ip;
        $build_req_url .= ':';
        $build_req_url .= $this->whm_port;
        $build_req_url .= '/';
        $build_req_url .= 'json-api/createacct?';
        $build_req_url .= 'username=' . $this->account_username;
        $build_req_url .= '&password=' . $this->account_password;
        $build_req_url .= '&contactemail=' . $this->account_email;
        $build_req_url .= '&plan=' . $this->whm_plan;
        $build_req_url .= '&domain=' . $this->account_domain;
        $build_req_url .= '&useregns=0&reseller=0';
        $this->request_url = $build_req_url;
    }
 
    private function callAPI() {
        $this->buildRequestURL();
        $query = $this->request_url;
 
        $curl = curl_init();  
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
        curl_setopt($curl, CURLOPT_HEADER,0);      
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        $header[0] = "Authorization: Basic " . base64_encode($this->whm_user.":".$this->whm_pass) . "\n\r";
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_URL, $query);
        $result = curl_exec($curl);
 
        if ($result == false) {
            // cURL ERROR
            $this->error = true;
            $this->error_msg = '[CURL] ' . curl_error($curl);
        }
 
        curl_close($curl);
        return $result;
    }
 
    function check($value) {
        if((@count($value)>0 and !@empty($value) and @isset($value)) || $value=='0') {
            return true;
        }
    }
 
}
?>

Code:
<?php

include('cphpac.class.php');

$cPHPAC = new cPHPAC();
$cPHPAC->setIP("127.0.0.1"); // Set the cPanel/WHM IP Address
$cPHPAC->setUsername("whm_username"); // Set the cPanel/WHM username
$cPHPAC->setPassword("whm_password"); // Set the cPanel/WHM password
$cPHPAC->setPlan("whm_plan_x"); // Set the package that will be used

/*
 * OPTIONAL SETTINGS:
 * The following settings are optional, meaning that, if not
 * set, they will use the default value.
 */
#$cPHPAC->useHTTPS(true); // default: true
#$cPHPAC->setPort(2087); // default: 2087 (Set the cPanel/WHM port)
#$cPHPAC->setPasswordLimit(12); // default: 32 (This limits the user password to X characters)


// Check if form is submitted
if(isset($_POST['submit'])) {
 
    // We send the data collected with the form
    $cPHPAC->createAccount($_POST['request_user'],$_POST['request_pass'],$_POST['request_email'],$_POST['request_domain']);
 
    // Check for errors
    if($cPHPAC->error) {
 
        // Print any errors
        print_r('[ERROR] ' . $cPHPAC->error_msg);
 
    } else {
 
        // SUCCES: print the response array data
        // you can do whatever you want with this data.. like sending
        // an email to the user maybe ???
        echo '<pre>';
        print_r($cPHPAC->return_data);
        echo '</pre>';
 
    }
 
} else {

    // VERY SIMPLE FORM
    echo '
        <form action="" method="post">
            <table cellspacing="5" cellpadding="3">
                <tr>
                    <td><b>Username:</b></td>
                    <td><input type="text" name="request_user" /></td>
                </tr>
                <tr>
                    <td><b>Password:</b></td>
                    <td><input type="password" name="request_pass" /></td>
                </tr>
                <tr>
                    <td><b>Email:</b></td>
                    <td><input type="text" name="request_email" /></td>
                </tr>
                <tr>
                    <td><b>Domain:</b></td>
                    <td><input type="text" name="request_domain" /></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="submit" /></td>
                </tr>
            </table>
        </form>
    ';
}
?>

Salah satu pendatang baru billing open source " hopebilling.com " juga menggunakan script tersebut diatas, script Lautaro Angélico lebih sempurna dibanding script dari zubrag..
 
Last edited:
Status
Not open for further replies.

Top