News:

Wondering if this will always be free?  See why free is better.

Main Menu

Create WHM accounts

Started by kansy, January 14, 2011, 03:30:49 AM

Previous topic - Next topic

kansy

Hello :D

I'm trying to manage the webhosting accounts with SMF + Simpleportal. I'm trying to create the script for making the accounts but there is an error in the script and I can't find it out.

Form:
<form id="form1" name="form1" method="post" action="crearcuenta.php">
  <p>Nombre de usuario cPanel:
  <input type="text" name="1" id="1" />
    <br />
    Contraseña de cPanel:
    <label for="2"></label>
    <input type="password" name="2" id="2" />
    <br />
    <label for="3">Nombre de dominio:</label>
    <input name="3" type="text" id="3" />
    <label for="3">.pewpewhost.com</label>
  <p>
  <input type="submit" name="7" id="7" value="Enviar" />
</form>

crearcuenta.php (It's supposed to create an account in WHM)

<?php
/* HOW TO INSTALL
1 - Save this code as a PHP file (or any file, as long as the server recognizes it as PHP)
2 - Change the configuration part in this file, save it, and upload to your server
3 - Create an empty .txt file in notepad, call it cookie.txt, upload it to your server.
4 - Is your server a unix-like server? CHMOD that file to 777.
    This is not need for windows servers.
*/
// Configure
define("WHM_USER""WHMUSERNAME"); // WHM username
define("WHM_PASS""WHMPASSWORD"); // WHM password
define("WHM_DOMAIN""WHMDOMAIN");   // IP or hostname could be enterred here

// The new account settings!
// Go to line 75 in this file, and change everything to suit your needs.


// cURL class: Thanks to Sean Huber
class CURL {
   var 
$callback false;

function 
setCallback($func_name) {
   
$this->callback $func_name;
}

function 
doRequest($method$url$vars) {
   
$ch curl_init();
   
curl_setopt($chCURLOPT_URL$url);
   
curl_setopt($chCURLOPT_HEADER1);
   
curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
   
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
   
curl_setopt($chCURLOPT_RETURNTRANSFER1);
   
curl_setopt($chCURLOPT_COOKIEJAR'cookie.txt');
   
curl_setopt($chCURLOPT_COOKIEFILE'cookie.txt');
   if (
$method == 'POST') {
       
curl_setopt($chCURLOPT_POST1);
       
curl_setopt($chCURLOPT_POSTFIELDS$vars);
   }
   
$data curl_exec($ch);
   
curl_close($ch);
   if (
$data) {
       if (
$this->callback)
       {
           
$callback $this->callback;
           
$this->callback false;
           return 
call_user_func($callback$data);
       } else {
           return 
$data;
       }
   } else {
       return 
curl_error($ch);
   }
}

function 
get($url) {
   return 
$this->doRequest('GET'$url'NULL');
}

function 
post($url$vars) {
   return 
$this->doRequest('POST'$url$vars);
}
}

// Initialize cURL library
$curl = new CURL;

$text $curl->get("http://" WHM_USER ":" WHM_PASS "@" WHM_DOMAIN .":2086/");

// Create account now
// First going to this form; required, else wont work
$text $curl->get("http://" WHM_USER ":" WHM_PASS "@" WHM_DOMAIN .":2086/scripts2/wwwacctform");

// Fine! Set the options now.
$options "sign=&plan=PLANNAME&domain="$_POST['6']".com&username="$_POST['6']"&password="$_POST['6']"&contactemail="$user_settings['emailAddress']"";

// And post it!
$text $curl->post("http://" WHM_USER ":" WHM_PASS "@" WHM_DOMAIN .":2086/scripts/wwwacct"$options);

// Eventually you can output the text here
echo $text;
?>


When I run everything I get an error in line 72 which is:

$options = "sign=&plan=PLANNAME&domain="$_POST['6']".com&username="$_POST['6']"&password="$_POST['6']"&contactemail="$user_settings['emailAddress']"";

I get everything from the form and the email, from the database.

The error I get is: Parse error: syntax error, unexpected T_VARIABLE

Any help would be awesome. :)

kansy

Okey I found it.

The code should be:
  $options = "sign=&plan=PLANNAME&domain=" . $_POST['6'] . ".com&username=" . $_POST['6'] . "&password=" . $_POST['6'] . "&contactemail=" . $user_settings['emailAddress'];

And also I had to change:

$data = curl_exec($ch);
   curl_close($ch);
   if ($data) {
       if ($this->callback)
       {
           $callback = $this->callback;
           $this->callback = false;
           return call_user_func($callback, $data);
       } else {
           return $data;
       }
   } else {
       return curl_error($ch);
   }


To
   $data = curl_exec($ch);
      if ($data) {
       if ($this->callback)
       {
           $callback = $this->callback;
           $this->callback = false;
           return call_user_func($callback, $data);
       } else {
           return $data;
       }
   } else {
       return curl_error($ch);
   }
   curl_close($ch);


Cheers,

Advertisement: