Warith AL Maawali

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    127.0.0.1
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Delphi
Gambas
Bash
PHP
  • Infrastructures
  • Digital Forensics
  • Cryptocurrency
  • Cloud & Server Management

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:


<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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td colspan="2">
Online Droplets: <!--?php echo "&lt;font color=\"green\"&gt;" . $liveCounter . "&lt;/font&gt;"?--><br>
Offline Droplets: <!--?php echo "&lt;font color=\"red\"&gt;" . $deadCounter . "&lt;/font&gt;"?--><br>
Total Droplets: <!--?php echo "&lt;font color=\"black\"&gt;" . $counterSum . "&lt;/font&gt;"?--><br>
<!--?php echo "Query Time: " . "&lt;font color=\"green\"&gt;" . (time() - $loadingtime) . "s &lt;/font&gt;&lt;br ?-->\n"; ?&gt;
</td></tr></tbody></table>

Download

Digital Ocean second method:

 <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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td colspan="2">
Online Droplets: <!--?php echo "&lt;font color=\"green\"&gt;" . $liveCounter . "&lt;/font&gt;"?--><br>
Offline Droplets: <!--?php echo "&lt;font color=\"red\"&gt;" . $deadCounter . "&lt;/font&gt;"?--><br>
Total Droplets: <!--?php echo "&lt;font color=\"black\"&gt;" . $counterSum . "&lt;/font&gt;"?--><br>
<!--?php echo "Query Time: " . "&lt;font color=\"green\"&gt;" . (time() - $loadingtime) . "s &lt;/font&gt;&lt;br ?-->\n"; ?&gt;
</td></tr></tbody></table>

			

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.


<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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td colspan="2">
Online Droplets: <!--?php echo "&lt;font color=\"green\"&gt;" . $liveCounter . "&lt;/font&gt;"?--><br>
Offline Droplets: <!--?php echo "&lt;font color=\"red\"&gt;" . $deadCounter . "&lt;/font&gt;"?--><br>
Total Droplets: <!--?php echo "&lt;font color=\"black\"&gt;" . $counterSum . "&lt;/font&gt;"?--><br>
<!--?php echo "Query Time: " . "&lt;font color=\"green\"&gt;" . (time() - $loadingtime) . "s &lt;/font&gt;&lt;br ?-->\n"; ?&gt;
</td></tr></tbody></table>


cp-ips

 
Download Vultr Api wrapper code from here
 


 

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