找回密码
 立即注册
查看: 8950|回复: 0

原创WHMCS-IPMI管理模块

[复制链接]
发表于 2013-6-21 14:40:24 | 显示全部楼层 |阅读模式
在WHMCS后台可以控制IPMI机器的电源项目...开/关  等.
! V! R& c( n7 `0 ~: X3 x2 |: [要求WHMCS所在机器安装OpenIPMI组件
# Z; Y0 b5 K& c) m( k9 v0 o; u2 [* L- R& C! J8 s
yum install OpenIPMI OpenIPMI-tools: D- ?5 N5 Z$ _2 \$ i% p

6 J6 j) i2 G9 r: q而且PHP要允许EXEC这个危险函数(执行内部程序)
: @- ]: ~2 K6 c/ C
( j0 Y6 W# X, T8 h! P5 i1 S# N还要配置WHMCS产品..选择该模块功能3 x( [  B" K+ U5 H5 O( m5 R/ g
产品还要新增三个自定义区域,名称分别是ipmiip/ipmiuser/ipmipass  类型为文本框 % W) r/ p, v# M
然后..就没有然后了...- v5 S' V' T; A0 m7 |
3 K+ f' E0 x9 T* R5 L% C. W8 X
[mw_shl_code=php,true]
! W* `- I1 e6 C- K<?php" Z! N0 ~0 F# d' C
#save as [whmcs]/modules/servers/ipmi/ipmi.php ' Q7 P+ O8 e/ u  G; S4 N% E4 f! y
- A0 T3 F7 E. q2 s8 k0 K7 B: D
function ipmi_ClientArea($params) {# e- |1 F0 ]8 V  N! F. ~
        # Output can be returned like this, or defined via a clientarea.tpl ipmi file (see docs for more info)
' U! {. P, p+ I, K        $ipmiip = $params['customfields']["ipmiip"];* G( [# O7 l+ J& S2 E" |3 ]  v1 H
        $ipmiuser = $params['customfields']["ipmiuser"];1 O! W$ N7 B( Y- b
        $ipmipass = $params['customfields']["ipmipass"];
& I4 z1 r' z  H; ]( v- M        ' J4 i: f1 B" n" t
        $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power status";
% X) U2 i/ H' L8 ^$ u% M9 [' {5 M        $power=substr(exec($cmd),17);
+ B8 r4 s5 P6 F5 T7 |( ^        $p="https://$ipmiip/";6 m6 P; M9 H2 q: N# N! B: j
        $code = "机器电源状态: $power  用户名ipmiuser 密码ipmipass <a href=\"$p\" target=\"_blank\" style=\"color:#cc0000\">登陆到IPMI页面</a>";
, ~8 S3 `1 o+ Q/ j        return $code;+ L, c- \$ H0 b& K
}, P! P8 q! w1 n; e: p# ~4 j

" O2 @, J; P% m/ dfunction ipmi_AdminLink($params) {% l+ x8 F1 R5 D7 u" M2 S) ^9 H% j
        $ipmiip = $params['customfields']["ipmiip"];
2 D; j* e# L$ R' ]/ v        $ipmiuser = $params['customfields']["ipmiuser"];% G9 D/ ]  s; g& j4 @# S
        $ipmipass = $params['customfields']["ipmipass"];, G0 W; D* e1 F& r! f: d
        $i=explode(".",$ipmiip);* z8 t( J& s# D. A
        $p="https://$ipmiip/"
- i0 `( k; }; s0 o8 Y        $code = "<a href=\"$p\" target=\"_blank\" style=\"color:#cc0000\">登陆到IPMI页面</a>";! W& Y5 E0 D* f: ]# ]; M) z0 q
        return $code;8 _8 Q% F7 q+ A) E+ [# \& d& l
}
& g$ f( `( h& Y7 a/ x5 n+ z7 ^& f8 o
function ipmi_LoginLink($params) {( I5 m: K4 K6 }/ f3 P0 B6 |. ]
        $ipmiip = $params['customfields']["ipmiip"];
/ H  C( g4 N- L7 j$ z        $ipmiuser = $params['customfields']["ipmiuser"];% u& ~8 u* x$ V6 H
        $ipmipass = $params['customfields']["ipmipass"];
7 o) h7 d3 l9 h        $i=explode(".",$ipmiip);
& z0 t9 Z9 P7 g        $p="https://$ipmiip/"9 d* h1 t- \8 P& e* H
        $code = "<a href=\"$p\" target=\"_blank\" style=\"color:#cc0000\">登陆到IPMI页面</a>";; s  }+ `$ E8 \0 d" Z6 W" T2 l
        return $code;
  P$ r' Q% z2 L, O}! a; X7 E7 g8 k* V  b9 s! T

* S4 |7 N6 h6 B/ Z* }* ^# `9 |function ipmi_reboot($params) {
" z; C( i1 `: C  Y4 o* R        $ipmiip = $params['customfields']["ipmiip"];
3 F' E" S* A8 h$ ?8 Q        $ipmiuser = $params['customfields']["ipmiuser"];
: U/ {0 \9 U9 [9 \/ j        $ipmipass = $params['customfields']["ipmipass"];
! r# g4 W9 A$ i# ?- _8 p        $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power reset";
' t; Z0 X+ {+ j9 j3 Q# ]        $return=exec($cmd);
" K  \! v) b9 E2 z. m4 F6 ?: T. Q; {: ^        if ($return=="") $return = "success";
; O3 b8 T; b6 T        return $return;* g, `% ^8 _/ ?+ X2 h: Y) \; Y* Y
}
4 |2 q! C$ `+ J: w& c# H9 P
; f, m( l$ P( J+ ~* ^function ipmi_shutdown($params) {
& N) @, k7 j0 z% b        $ipmiip = $params['customfields']["ipmiip"];' _/ M9 [! p7 n( i) p
        $ipmiuser = $params['customfields']["ipmiuser"];6 ]; q, p2 k8 V8 O
        $ipmipass = $params['customfields']["ipmipass"];1 I3 f6 e2 h, u# h
        $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power off";2 {" H) Q6 D& Z. Q* G1 r
        $return=exec($cmd);- w+ o; \# v1 ~% x0 m/ `; I
        if ($return=="") $return = "success";
* R' {! M$ g( n6 E! q6 Z, G        return $return;
: H* B6 Z. v/ V3 s}
- @3 z3 l$ `: x
5 ]# O- w- g' I8 b4 C8 X' R  kfunction ipmi_on($params) {
; A2 f2 c  a  t# q+ R( [! b        $ipmiip = $params['customfields']["ipmiip"];2 U6 C/ J3 n: r6 |* V' F5 Y& ~
        $ipmiuser = $params['customfields']["ipmiuser"];
1 p' b! E' C& B8 M# X3 R        $ipmipass = $params['customfields']["ipmipass"];
& L1 G5 q9 U# p8 a0 H7 _        $cmd="ipmitool -H $ipmiip -U $ipmiuser -P $ipmipass -I lanplus power on";
. A3 q1 ~5 P2 m. q( E        $return=exec($cmd);2 F+ z# |. x# O* [' X! l
        if ($return=="") $return = "success";
; U0 E6 C5 T; b% `- {8 R8 u        return $return;! U+ r# _  U; h3 a% t
}7 N0 z* i+ \5 `  E8 B
7 U9 Y/ A9 r( p; K0 x! s
function ipmi_cycle($params) {
" C7 }' x  W0 \/ |        $ipmiip = $params['customfields']["ipmiip"];1 v. p7 w& N: d- H, n' x
        $ipmiuser = $params['customfields']["ipmiuser"];
7 {6 `; ^" R% ?        $ipmipass = $params['customfields']["ipmipass"];4 v" f( o0 G# P* E, V
        $cmd="ipmitool -H $ipmiip -U user -P $pass -I lanplus power cycle";
6 h; ^" ?* _, |8 K) e5 r        $return=exec($cmd);' I) F, L5 ]( n% B# T7 a
        if ($return=="") $return = "success";
$ Q, y$ z1 T4 T$ e3 i7 m/ i- @$ {        return $return;4 v- }2 V8 ^# y
}) C- P, U! P, F. l5 j3 [

1 o4 K) N; O2 @% m' Mfunction ipmi_ClientAreaCustomButtonArray() {6 q; O, X3 x9 i( V& r  H6 z& r6 U
        $buttonarray = array(
" N! M( Z7 W' D: t        "重启RESET" => "reboot",
( R% F: h  c% S, H        "电源重置POWER_CYCLE" => "cycle",
2 C- _8 `0 X, a( y0 w! t        "电源关闭POWER_OFF" => "off",# O$ j3 P! e2 b
        "电源开启POWER_ON" => "on",0 _2 p3 I; w5 X, Y
        );% w  ~5 _' Z. J
        return $buttonarray;" s, B+ p- i. A# S' A* U
}+ k+ v; P/ z" D1 C- b4 u! N

6 v# B1 C3 b- Rfunction ipmi_AdminCustomButtonArray() {
2 Q: @& m5 C. B) ]+ C; E        $buttonarray = array(+ z9 Z& P( k- u
        "重启RESET" => "reboot",
. p2 y) W6 I, H% u- {        "电源重置POWER_CYCLE" => "cycle",7 Y) w! d; M" \7 l6 N
        "电源关闭POWER_OFF" => "off",
3 t5 G" i# B* V8 ^5 l3 i        "电源开启POWER_ON" => "on",' e  M) q( _* `, e# a
        );
# k' n( Q( ]) S1 k        return $buttonarray;/ Y3 d0 ~! \0 n& K4 X
}1 X: ~  B& h* C& \) x6 N9 B
?>
$ t6 E% C6 ]& ]4 f0 t- t[/mw_shl_code]
2 c) J. n! R+ W* N8 e4 q; l0 Z
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|第一站论坛 ( 蜀ICP备06004864号-6 )

GMT+8, 2024-5-6 20:29 , Processed in 0.060118 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表