Hold Tight...

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    ::0
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Gambas
PHP
Delphi
Bash
  • Cybersecurity
  • Generative AI
  • Cloud & Automation
  • Cryptocurrency

Make use of Digital Ocean and Vultr VPS API with PHP wrapper

29/03/2014

My First Experience with an API PHP Wrapper

Here is my first experience with an API PHP wrapper. Digital Ocean and Vultr provide VPS services, so if you don’t want to log into their panel each time you want to perform an action on the VPS node, you can call the droplet functions from your own website and have your own control panel. First, you will need to create your own client ID and API key, both of which can be generated from the Digital Ocean user control panel. Here is the code that I wrote to list all the droplets and perform actions like reboot, shutdown, and power on:

Digital Ocean first method:

HTML
<table class="has-fixed-layout"><tbody><tr><td colspan="6">Data Center Control</td></tr><tr><td>Server ID</td><td>Server Name</td><td>IP</td><td>Status</td><td>Creation Date</td><td>Actions</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td colspan="2">
        Online Droplets: <!--?php echo  "<font color=\"green\">"  . $liveCounter . "</font>"?--><br>
        Offline Droplets: <!--?php echo  "<font color=\"red\">"  . $deadCounter . "</font>"?--><br>
        Total Droplets: <!--?php echo  "<font color=\"black\">"  . $counterSum . "</font>"?--><br>
        <!--?php echo "Query Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br ?-->\n"; ?>
        </td></tr></tbody></table>
HTML

Download

Digital Ocean’s second method:

HTML
<table class="has-fixed-layout"><tbody><tr><td colspan="6">Data Center Control</td></tr><tr><td>Server ID</td><td>Server Name</td><td>IP</td><td>Status</td><td>Creation Date</td><td>Actions</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td colspan="2">
        Online Droplets: <!--?php echo  "<font color=\"green\">"  . $liveCounter . "</font>"?--><br>
        Offline Droplets: <!--?php echo  "<font color=\"red\">"  . $deadCounter . "</font>"?--><br>
        Total Droplets: <!--?php echo  "<font color=\"black\">"  . $counterSum . "</font>"?--><br>
        <!--?php echo "Query Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br ?-->\n"; ?>
        </td></tr></tbody></table>
HTML

You will need DO.class.php to be on the same folder as this script:

Download DO.class.php class from here.

Download do.php code from here.

Sample of a working code on Stealthwalker admin control panel:

DigitalOcean-do-api
DigitalOcean-do-api

You can perform more actions as long you have the node id available actions can be found here.
 


Vulter method:

 

My new experiance is with Vultr Cloud VPS provider you can see their API here. Now let me show you how to wrap it with PHP code its simple with the same concept above except you won’t have an array.

HTML
<table class="has-fixed-layout"><tbody><tr><td colspan="6">Data Center Control</td></tr><tr><td>Server ID</td><td>Server Name</td><td>City</td><td>IP</td><td>Status</td><td>Creation Date</td><td>Bandwidth</td><td>Backups</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td colspan="2">
        Online Droplets: <!--?php echo  "<font color=\"green\">"  . $liveCounter . "</font>"?--><br>
        Offline Droplets: <!--?php echo  "<font color=\"red\">"  . $deadCounter . "</font>"?--><br>
        Total Droplets: <!--?php echo  "<font color=\"black\">"  . $counterSum . "</font>"?--><br>
        <!--?php echo "Query Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br ?-->\n"; ?>
        </td></tr></tbody></table>
HTML
cp-ips

 
Download Vultr Api wrapper code from here
 


Posted in Tech BlogTags:
© 2024 Warith AL Maawali. All Rights Reserved.
Stay Secure, Stay Assured.