Update user API code PHP (Vestacp Class code)
Posted: Thu Nov 30, 2017 8:27 am
Hey everyone,
I am writing an api class for Vestacp, and want to add a code to update users.
Is there a way.
You can download the code for free on
https://gitlab.com/daansk44/vestacontrolpanelapiclasses
I am writing an api class for Vestacp, and want to add a code to update users.
Is there a way.
You can download the code for free on
https://gitlab.com/daansk44/vestacontrolpanelapiclasses
Code: Select all
<?php
class VestaClass
{
// basic
protected $vst_hostname;
protected $vst_username;
protected $vst_password;
protected $vst_returncode;
// User settings
protected $username;
protected $password;
protected $email;
protected $fist_name;
protected $last_name;
// end user settings
// For make database
protected $db_name;
protected $db_user;
protected $db_pass;
// Package
protected $package;
// making domain
protected $domain;
// https://vestacp.com/docs/api/
public function MakeDatabase($vst_hostname, $vst_username, $vst_password, $username, $vst_returncode, $db_name, $db_user, $db_pass)
{
$vst_command = 'v-add-database';
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $db_name,
'arg3' => $db_user,
'arg4' => $db_pass
);
$postdata = http_build_query($postvars);
// Send POST query via cURL
$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) {
return "Database has been successfuly created\n";
} else {
return "Query returned error code: " . $answer . "\n";
}
}
public function MakeUser($vst_hostname, $vst_username, $vst_password, $username, $vst_returncode, $password, $email, $fist_name, $last_name, $package)
{
// Server credentials
$vst_command = 'v-add-user';
// 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) {
return "User account has been successfuly created\n";
} else {
return "Query returned error code: " . $answer . "\n";
}
}
public function MakeWebDNSMail($vst_hostname, $vst_username, $vst_password, $username, $vst_returncode, $domain)
{
// Server credentials
$vst_command = 'v-add-domain';
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $domain
);
$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) {
return "Domain has been successfuly created\n";
} else {
return "Query returned error code: " . $answer . "\n";
}
}
public function GetUsersFromServer($vst_hostname, $vst_username, $vst_password, $username)
{
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $format
);
$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);
// Parse JSON output
$data = json_decode($answer, true);
// Print result
return ($data);
}
public function DeleteUser($vst_hostname, $vst_username, $vst_password, $username, $vst_returncode)
{
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username
);
$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 deleted\n";
} else {
echo "Query returned error code: " . $answer . "\n";
}
}
}
?>