If you use VestaCP this code will allow you to allow signups on your VPS


I was browse through the community forum for the control panel that I am currently using, which is VestaCP, I came across this tread titled โ€œVestaCP API for web hosting signup automationโ€.

The person who posted this suspected that the issue was in the section of โ€œ// New Accountsection ofโ€ after testing it for myself I was able to confirm that the issue was in that section.

I decided to replace what they posted was $username = ‘demo’; with $username = ‘<?php echo $_POST[“username”]; ?>’; unfortunately, that did not work either. So I change the code back to what they posted to see what else would be able to work then I had remembered I had asked a question about how to modify a code to handle a form submission, they said I should use $username = htmlspecialchars($_REQUEST[‘username’]); and after replacing what they posted username = ‘demo’; to $username = htmlspecialchars($_REQUEST[‘username’]); it worked successfully.

signup.html

<form action="action.php" method="post">
Choose Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
E-mail: <input type="text" name="email"><br>
First Name: <input type="text" name="fist_name"><br>
Last Name: <input type="text" name="last_name"><br>
<input type="submit"> </form>

The code that is posted below is the action, copy all of the code, and save it as action.php.

<?php

// Server credentials
$vst_hostname = 'i.e. cpanel.website.tld';
$vst_username = 'admin';
$vst_password = 'password to login to your control panel with admin access';
$vst_returncode = 'yes';
$vst_command = 'v-add-user';

// New Account
$username = htmlspecialchars($_REQUEST['username']);
$password = htmlspecialchars($_REQUEST['password']);
$email = htmlspecialchars($_REQUEST['email']);
$package = 'FreeUsers';
$fist_name = htmlspecialchars($_REQUEST['fist_name']);
$last_name = htmlspecialchars($_REQUEST['last_name']);


// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'returncode' => $vst_returncode,
    'cmd' => $vst_command,
    'arg1' => $username,
    'arg2' => $password,
    'arg3' => $email,
    'arg4' => $package,
    'arg5' => $fist_name,
    'arg6' => $last_name
);
$postdata = http_build_query($postvars);

// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);

// Check result
if($answer == 0) {
    echo "User account has been successfuly created\n";
} else {
    echo "Query returned error code: " .$answer. "\n";
}
?>


Comments

Comments are hidden, you must click on show comments to read and/or post your own.