Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section General Discussion
  • Search

How PHP works with Vestacp through web api?

General questions about VestaCP
Post Reply
  • Print view
Advanced search
7 posts • Page 1 of 1
truytim123
Posts: 7
Joined: Fri Nov 20, 2015 8:00 am

How PHP works with Vestacp through web api?
  • Quote

Post by truytim123 » Sun Jan 03, 2016 3:17 pm

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";
}
?>
Top

ttcttctw
Posts: 26
Joined: Thu May 28, 2015 2:49 am
Contact:
Contact ttcttctw
Website

Re: How PHP works with Vestacp through web api?
  • Quote

Post by ttcttctw » Mon Jan 04, 2016 1:22 am

Can you post the output of this code? So I can take a look on what's happen.
Top

truytim123
Posts: 7
Joined: Fri Nov 20, 2015 8:00 am

Re: How PHP works with Vestacp through web api?
  • Quote

Post by truytim123 » Mon Jan 04, 2016 10:45 am

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
Top

truytim123
Posts: 7
Joined: Fri Nov 20, 2015 8:00 am

Re: How PHP works with Vestacp through web api?
  • Quote

Post by truytim123 » Mon Jan 04, 2016 11:31 am

can anyone help me?
Top

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

Os: CentOS 6x
Web: apache + nginx
Re: How PHP works with Vestacp through web api?
  • Quote

Post by tjebbeke » Mon Jan 04, 2016 12:42 pm

can you try with:

Code: Select all

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

truytim123
Posts: 7
Joined: Fri Nov 20, 2015 8:00 am

Re: How PHP works with Vestacp through web api?
  • Quote

Post by truytim123 » Mon Jan 04, 2016 7:18 pm

Thanks you! it's work.

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

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

Os: CentOS 6x
Web: apache + nginx
Re: How PHP works with Vestacp through web api?
  • Quote

Post by tjebbeke » Mon Jan 04, 2016 9:52 pm

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?
Top


Post Reply
  • Print view

7 posts • Page 1 of 1

Return to “General Discussion”



  • 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