本帖最后由 Bendy 于 2013-6-21 23:20 编辑
在WHMCS后台可以控制IPMI机器的电源项目...开/关 等.
要求WHMCS所在机器安装OpenIPMI组件
- yum install OpenIPMI OpenIPMI-tools
复制代码 而且PHP要允许EXEC这个危险函数(执行内部程序)
还要配置WHMCS产品..选择该模块功能
产品还要新增三个自定义区域,名称分别是ipmiip/ipmiuser/ipmipass 类型为文本框
然后..就没有然后了...
- <?php
- #save as [whmcs]/modules/servers/ipmi/ipmi.php
- function ipmi_ClientArea($params) {
- # Output can be returned like this, or defined via a clientarea.tpl ipmi file (see docs for more info)
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
-
- $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power status";
- $power=substr(exec($cmd),17);
- $p="https://$ipmiip/";
- $code = "机器电源状态: $power 用户名:$ipmiuser 密码:$ipmipass <a href="$p" target="_blank" style="color:#cc0000">登陆到IPMI页面</a>";
- return $code;
- }
- function ipmi_AdminLink($params) {
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
- $i=explode(".",$ipmiip);
- $p="https://$ipmiip/"
- $code = "<a href="$p" target="_blank" style="color:#cc0000">登陆到IPMI页面</a>";
- return $code;
- }
- function ipmi_LoginLink($params) {
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
- $i=explode(".",$ipmiip);
- $p="https://$ipmiip/"
- $code = "<a href="$p" target="_blank" style="color:#cc0000">登陆到IPMI页面</a>";
- return $code;
- }
- function ipmi_reboot($params) {
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
- $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power reset";
- $return=exec($cmd);
- if ($return=="") $return = "success";
- return $return;
- }
- function ipmi_off($params) {
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
- $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power off";
- $return=exec($cmd);
- if ($return=="") $return = "success";
- return $return;
- }
- function ipmi_on($params) {
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
- $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power on";
- $return=exec($cmd);
- if ($return=="") $return = "success";
- return $return;
- }
- function ipmi_cycle($params) {
- $ipmiip = $params['customfields']["ipmiip"];
- $ipmiuser = $params['customfields']["ipmiuser"];
- $ipmipass = $params['customfields']["ipmipass"];
- $cmd="ipmitool -H $ipmiip -U user -P $pass -I lanplus power cycle";
- $return=exec($cmd);
- if ($return=="") $return = "success";
- return $return;
- }
- function ipmi_ClientAreaCustomButtonArray() {
- $buttonarray = array(
- "重启RESET" => "reboot",
- "电源重置POWER_CYCLE" => "cycle",
- "电源关闭POWER_OFF" => "off",
- "电源开启POWER_ON" => "on",
- );
- return $buttonarray;
- }
- function ipmi_AdminCustomButtonArray() {
- $buttonarray = array(
- "重启RESET" => "reboot",
- "电源重置POWER_CYCLE" => "cycle",
- "电源关闭POWER_OFF" => "off",
- "电源开启POWER_ON" => "on",
- );
- return $buttonarray;
- }
- ?>
复制代码 |