Page 1 of 1

How PHP works with Vestacp through web api?

Posted: Sun Jan 03, 2016 3:17 pm
by truytim123
Hey guys! Looking forward to your help. Thank you!
I installed Vestacp, I have an idea to turn it into DDNS domain with subdomains.
I'm having a problem is how to create sub domains with A record IP account with PHP.
Please guide me!

I am using this code, but it is not working.

Code: Select all

<?php
// Server credentials
$vst_hostname = 'abc.com';
$vst_username = 'admin';
$vst_password = 'password';
$vst_returncode = 'yes';
$vst_command = 'v-add-dns-record';

// New Domain
    $username = 'admin';
    $domain = 'abc.com';
    $record = 'test.abc.com'; // SUBDOMAIN.YOUR.DOMAIN
    $type = 'A';$value = '8.8.8.8';

// Prepare POST query
$postvars = array(    'user' => $vst_username,
    'password' => $vst_password,
    'returncode' => $vst_returncode,
    'cmd' => $vst_command,
    'arg1' => $username,
    'arg2' => $domain,
    'arg3' => $record,
    'arg4' => $type,
    'arg5' => $value
);
 $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 "DNS ZONE " . $record ." has been successfully created and points to " . $value . "\n";
} else {
    echo "Could not create " . $record . "\nQuery returned error code: " .$answer. "\n";
}
?>

Re: How PHP works with Vestacp through web api?

Posted: Mon Jan 04, 2016 1:22 am
by ttcttctw
Can you post the output of this code? So I can take a look on what's happen.

Re: How PHP works with Vestacp through web api?

Posted: Mon Jan 04, 2016 10:45 am
by truytim123
I coppy it on vestacp.com/doc api but it is not working . you need the output : "user=admin&password=password&returncode=yes&cmd=v-add-dns-record&arg1=admin&arg2=abc.com&arg3=test.abc.com&arg4=A&arg5=8.8.8.8"

I put this php file in the folder public_html

Re: How PHP works with Vestacp through web api?

Posted: Mon Jan 04, 2016 11:31 am
by truytim123
can anyone help me?

Re: How PHP works with Vestacp through web api?

Posted: Mon Jan 04, 2016 12:42 pm
by tjebbeke
can you try with:

Code: Select all

$username = 'admin';
$domain = 'abc.com';
$record = 'test';
$type = 'A';
$value = '8.8.8.8';

Re: How PHP works with Vestacp through web api?

Posted: Mon Jan 04, 2016 7:18 pm
by truytim123
Thanks you! it's work.

Can you help me again? How to set dns forward for 8.8.8.8 & 8.8.4.4

Re: How PHP works with Vestacp through web api?

Posted: Mon Jan 04, 2016 9:52 pm
by tjebbeke
truytim123 wrote:Thank you! it's work.

Can you help me again? How to set DNS forward for 8.8.8.8 & 8.8.4.4
What do you want to achieve? You can change your DNS settings in /etc/resolv.conf. But that might not be what you're looking for?