转载:SolusVM提供的API让我用烂手机wap功能管理VPS
分类:运维技术日期:2012-02-07 - 11:52:43作者:老谢
以下代码转自:http://dao.daimaku.com
老谢的烂手机终于也能简单的操作vps了,有个重启功能足矣,诺基亚继续坚挺着
<?php ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); if (!empty($_GET['action'])) { $action = $_GET['action']; $sure = $_GET['sure']; if ('boot' == $action && empty($sure)) { echo '您确定要启动VPS吗?<a href="vps?action=boot&sure=1">确定</a>'; } elseif ('reboot' == $action && empty($sure)) { echo '您确定要重新启动VPS吗?<a href="vps?action=reboot&sure=1">确定</a>'; } elseif ($action != 'status' && $action != 'boot' && $action != 'reboot') { echo "操作错误!"; } else { $key = "API KEY 在控制面板可获取"; $hash = "API HASH 在控制面板可获取"; $url = "http://SolusVM管理地址/api/client/command.php?key=$key&hash=$hash&action=$action"; $data = file_get_contents($url); // 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]; } //错误信息 if ($result["status"] == "error") { echo $result["statusmsg"]; } elseif ($result["status"] == "success") { if ($result["statusmsg"] == "online") { echo "The virtual server is online!"; } elseif ($result["statusmsg"] == "offline") { echo "The virtual server is offline!"; } elseif ($result["statusmsg"] == "rebooted") { echo "The virtual server has been rebooted!"; } elseif ($result["statusmsg"] == "shutdown") { echo "The virtual server has been shutdown!"; } elseif ($result["statusmsg"] == "booted") { echo "The virtual server has been booted!"; } else { echo "Status message unknown!"; } } } echo '<hr>'; } ?> <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml;charset=UTF-8"/> <meta http-equiv="Cache-control" content="no-cache" /> <title>VPS管理</title> </head> <body> <ul> <li><a href="vps.php?action=status">查看状态</a> </li> <li><a href="vps.php?action=boot">启动VPS</a> <br /></li> <li><a href="vps.php?action=reboot">重启VPS</a></li> </ul> </body> </html> |
沙发, 老谢这种华丽斑斓的代码颜色~~~~~~~~~~~~~~~~~~~
这个就是代码高亮啊,这个你都不知道?
@suN 锅锅~~~
呵呵~Android淡定飘过~
@DickWu 羡慕一把~
从未用过cps
我看会很痛苦
我试过但是不行,期待谢大哥指点迷津!
@连仕彤 solusvm提供了api权限么?api填写正确么?
额~~~有asp的代码吗?