Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section Scripting / API
  • Search

Problems with adding user

Questions regarding the API
Application Programming Interface
Locked
  • Print view
Advanced search
5 posts • Page 1 of 1
cdg
Posts: 48
Joined: Sun Aug 16, 2015 3:11 am
Contact:
Contact cdg
Website

Os: Ubuntu 15x
Web: apache + nginx
Problems with adding user

Post by cdg » Sun Aug 16, 2015 3:24 am

I don't know if I'm just doing this wrong or what the problem is. I'm trying to make a signup page for Vesta on my site using the API example here: https://vestacp.com/docs/api/ but it is not working. I asked this on a different forum (http://stackoverflow.com/questions/3202 ... -in-action) and still have no answer. It tells me that the user account is successfully created and i know that it is connecting to my server correctly but the accounts are not being created. It has been made apparent to me that variables such as

Code: Select all

$username = 'username';
should be

Code: Select all

$username = $_POST['username'];name = $_POST['username'];
and that the script says fist_name rather than first_name. If there is a different version of this or a way to fix this it would be much appreciated. Thanks.
Top

tjebbeke
Collaborator
Posts: 783
Joined: Mon May 11, 2015 8:43 am
Contact:
Contact tjebbeke
Website

Os: CentOS 6x
Web: apache + nginx
Re: Problems with adding user

Post by tjebbeke » Mon Aug 17, 2015 12:28 pm

Try this:

Code: Select all

<form action="process.php" method="post">
Username:<br>
<input type="text" name="username">
<br>
Firstname:<br>
<input type="text" name="firstname">
<br>
Name:<br>
<input type="text" name="name">
<br>
Password:<br>
<input type="password" name="password">
<br>
Email Address:<br>
<input type="email" name="email">
<br><br>
<input type="submit" value="Submit">
</form>
process.php

Code: Select all

<?php
// Server credentials
$vst_hostname = 'MYSERVERADDRESS';
$vst_username = 'admin';
$vst_password = 'ADMINPASSWORD';
$vst_returncode = 'yes';
$vst_command = 'v-add-user';

// New Account
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email']; 
$package = 'default'; // $package = 'Free'; //Free package exist on server?
$fist_name = $_POST['firstname']; 
$last_name = $_POST['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, 'http://' . $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";
}
?>
Top

cdg
Posts: 48
Joined: Sun Aug 16, 2015 3:11 am
Contact:
Contact cdg
Website

Os: Ubuntu 15x
Web: apache + nginx
Re: Problems with adding user

Post by cdg » Mon Oct 05, 2015 10:31 pm

I finally got the form working, the problem was in the post query sectio, where it was trying to post fist_name rather than first_name. Thank you so much!
Top

www.rinku31
Posts: 21
Joined: Thu Jun 04, 2015 9:22 am

Re: Problems with adding user

Post by www.rinku31 » Wed Mar 09, 2016 9:49 am

Yes

turn on errors while developing script:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Problems with adding user

Post by skurudo » Fri Sep 23, 2016 12:36 pm

API documentation and examples:
http://vestacp.com/docs/API.pdf

CLI commands list and descriptions:
http://vestacp.com/docs/CLI.txt

-> viewtopic.php?f=18&t=12610
Top


Locked
  • Print view

5 posts • Page 1 of 1

Return to “Scripting / API”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password