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

Add a new IP address through API

Questions regarding the API
Application Programming Interface
Post Reply
  • Print view
Advanced search
1 post • Page 1 of 1
SaharsVesta
Posts: 9
Joined: Thu Jun 20, 2019 8:27 am

Os: CentOS 6x
Web: apache + nginx
Add a new IP address through API
  • Quote

Post by SaharsVesta » Fri Jun 21, 2019 12:12 pm

There is anyway to do that?

UPDATE: Nevermind, i created one for who need:

Code: Select all

<?php
// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_command = 'v-add-sys-ip';

// Account
$IP = '1.2.3.4';
$NETMASK = '255.255.255.240';
$INTERFACE = 'eth0';
$USER = 'admin';
$IP_STATUS = '';
$IP_NAME = '';
$NAT_IP = '';

// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'cmd' => $vst_command,
    'arg1' => $IP,
    'arg2' => $NETMASK,	
    'arg3' => $INTERFACE,
    'arg4' => $USER,
    'arg5' => $IP_STATUS,
    'arg6' => $IP_NAME,
    'arg7' => $NAT_IP
);
$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
print_r($data);

?>
Top


Post Reply
  • Print view
1 post • 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