Page 1 of 1

Add a new IP address through API

Posted: Fri Jun 21, 2019 12:12 pm
by SaharsVesta
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);

?>