Last active
January 12, 2018 19:48
-
-
Save levidurfee/d15f4394b56f78b094a1d1a4ecd12a45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function digitalOcean($DO_API_TOKEN) { | |
$endpoint = "https://api.digitalocean.com/v2/droplets?per_page=200"; | |
$headers[] = "Content-type: application/json"; | |
$headers[] = "Authorization: Bearer $DO_API_TOKEN"; | |
$curl = curl_init(); | |
curl_setopt_array($curl, [ | |
CURLOPT_HTTPHEADER => $headers, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_URL => $endpoint, | |
]); | |
$response = curl_exec($curl); | |
return json_decode($response)->droplets; | |
} | |
?> | |
<html> | |
<header> | |
<style> | |
#name {width:960px; margin:auto;} | |
#name table {width:100%;} | |
.tables:nth-child(even) {background:rgba(204,204,204,.3);} | |
.off {background:rgba(220,53,69,.3);} | |
.active {background:rgba(40,167,69,.3);} | |
</style> | |
</header> | |
<body> | |
<div id="name"> | |
<?php | |
function template($nameOfAccount, $DOapi) { | |
echo '<h2>'.$nameOfAccount.'</h2>'; | |
echo '<table> | |
<tr> | |
<td width="200px"><strong>Name</strong></td> | |
<td width="60px"><strong>IP Address</strong></td> | |
<td width="60px"><strong>Status</strong></td> | |
<td width="60px"><strong>Memory</strong></td> | |
<td width="60px"><strong>Disk</strong></td> | |
<td width="60px"><strong>$/Month</strong></td> | |
</tr>'; | |
for ($i = 0; $i < count($DOapi); $i++) { | |
echo '<tr class="tables"> | |
<td width="200px">'.$DOapi[$i]->name.'</td> | |
<td width="60px">'.$DOapi[$i]->networks->v4[0]->ip_address.'</td> | |
<td width="60px" class="'.$DOapi[$i]->status.'">'.$DOapi[$i]->status.'</td> | |
<td width="60px">'.$DOapi[$i]->memory.'</td> | |
<td width="60px">'.$DOapi[$i]->disk.'</td> | |
<td width="60px">$'.$DOapi[$i]->size->price_monthly.'</td> | |
</tr>'; | |
} | |
echo '</table>'; | |
} | |
template('[email protected]', digitalOcean('DO API KEY')); | |
?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment