Linuxword Global
当前位置: Linux技术 > SolusVM API PHP Class Wrapper

SolusVM-PHP-API-Class

使用前提:先要进SolusVM后台开启API,得到key和hash

官方文档上提供的是POST方式提交数据,但是本人试过后总是报“417 – Expectation Failed”的错误,改用GET传数据后,就没有报错了

具体代码如下:

<?php

// Url to the client API
$url = “https://<MASTER IP>:5656/api/client”;

// Specify the key, hash and action

$postfields[“key”] = “EXAMPLE-API-KEY”;
$postfields[“hash”] = “exaMpleHasH”;
$postfields[“action”] = “reboot”; // reboot, shutdown, boot, status
// Send the query to the solusvm master

// Send the query to the solusvm master
// Note we have to use GET, POST seems to be broken.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . “/command.php?key=”.$postfields[‘key’].”&hash=”.$postfields[‘hash’].”&action=”.$postfields[‘action’].
“&ipaddr=true&bw=true&mem=true&hdd=true”);
// curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

// Parse the returned data and build an array

preg_match_all(‘/<(.*?)>([^<]+)<\/\\1>/i’, $data, $match);
$result = array();
foreach ($match[1] as $x => $y)
{
$result[$y] = $match[2][$x];
}

echo “<pre>”;
print_r($result);
echo “</pre>”;
?>

SolusVM是很多VPS商家使用的一套VPS管理面板,针对客户提供了API功能以便管理账户下的VPS。

在SolusVM后台开启API功能,获取 API Key 和 API Hash(每台VPS对应不同的key和hash,如果账户下有多个机器,则需要分别获取

fd6ea01b36bfde12424444a3e39bf7c6

因为它的API允许直接使用GET方式访问,所以可以把其中信息替换掉,直接从浏览器打开就可以简单操作VPS

需要注意的是,有些商家的管理地址可能是http协议,访问时需注意。

https://SolusVM管理地址/api/client/command.php?key=KEY&hash=HASH&action=操作

其中可用的操作有:

  • reboot(重启)
  • boot(启动)
  • status(状态)
  • shutdown(关机)
  • info(信息)

SolusVM API PHP Class WrapperSolusVM-PHP-API-Class-Master    https://linuxword.com/wp-content/uploads/2022/05/SolusVM-PHP-API-Class-Master.zip
A PHP wrapper class for the SolusVM API which interacts with virtual servers.

version 1.2

Requires
PHP >= 7.4
Usage
First edit lines 11,12,13 in class.php for your hosting providers solusVM URL along with your account API key and API hash

Call the class file on any page that uses it

<?php
require_once('class.php');
Create a new instance on page of use:

$call = new solusClientApi();
Return all server info
$call->allInfo();
array

returns (edited certain values):

{
"status": "online",
"hostname": "myservershostname.com",
"location": "Los Angeles, CA, USA",
"type": "kvm",
"node": "KVM-1.LA.HOST.COM",
"ip_count": 2,
"ip_list": [
"111.222.333.444",
"111.222.333.555",
"111.222.333.666"
],
"mem_total": "512.0",
"mem_used": "220.0",
"mem_used_percent": 42,
"mem_data_type": "MB",
"bw_total": "512.0",
"bw_used": "0.0",
"bw_used_percent": 0,
"bw_data_type": "GB",
"hdd_total": "10.0",
"hdd_used": "5.0",
"hdd_used_percent": 50,
"hdd_data_type": "GB",
"datetime": "2020-04-04 15:56:29"
}
Get server status
$call->getStatus();
bool

IP address count
$call->ipCount();
int

Main ip address
$call->ipMain();
string

IP address from number in array created from list
$call->ip($number);
string

Server type (KVM, OVZ etc)
$call->type();
string

Server hostname
$call->hostname();
string

Server node
$call->node();
string

Server location
$call->location();
string

Reboot server
$call->reboot();
string

Boot server
$call->boot();
string

Shutdown server
$call->shutdown();
string

Total memory for server
$call->totalMem($convert_to, $decimals);
string

Memory available
$call->memAval($convert_to, $decimals);
string

Memory used percent
$call->memUsedPercent($decimals);
string

Memory free percent
$call->memFreePercent($decimals);
string

Total HDD for server
$call->totalHdd($convert_to, $decimals);
string

HDD available
$call->hddAval($convert_to, $decimals);
string

HDD used percent
$call->hddUsedPercent($decimals);
string

HDD free percent
$call->hddFreePercent($decimals);
string

Total bandwidth for server
$call->totalBw($convert_to, $decimals);
string

Bandwidth available
$call->bwAval($convert_to, $decimals);
string

Bandwidth used percent
$call->bwUsedPercent($decimals);
string

Bandwidth free percent
$call->bwFreePercent($decimals);
string

Set up reverse DNS
$call->rdns($ip, $rdns);
string

 

 

「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」

赞(0) 打赏
一分也是爱

支付宝扫一扫打赏

微信扫一扫打赏

上一篇:

下一篇:

相关推荐

博客简介

本站CDN采用VmShell免费提供离中国大陆最近的香港CMI高速网络做支撑,ToToTel打造全球最快速的边沿网络支撑服务,具体详情请见 :https://vmshell.com/ 以及 https://tototel.com/,网站所有的文件和内容禁止大陆网站搬迁复制,谢谢,VPS营销投稿邮箱: admin@linuxxword.com,我们免费帮大家发布,不收取任何费用,请提供完整测试文稿!

精彩评论

友情链接

他们同样是一群网虫,却不是每天泡在网上游走在淘宝和网游之间、刷着本来就快要透支的信用卡。他们或许没有踏出国门一步,但同学却不局限在一国一校,而是遍及全球!申请交换友链

站点统计

  • 文章总数: 2591 篇
  • 草稿数目: 22 篇
  • 分类数目: 6 个
  • 独立页面: 0 个
  • 评论总数: 2 条
  • 链接总数: 0 个
  • 标签总数: 13021 个
  • 注册用户: 139 人
  • 访问总量: 8,649,533 次
  • 最近更新: 2024年11月21日