本篇以HP ILO口管理为例,其虽然分pc server和刀片机以及ilo代数,不过其内部原理基本都是一致的。HP ilo的console管理有两种,一种使用的是java applet技术,另一种使用的是.net xbap技术。这里先说前者,也是用的比较多的java applet技术。
一、有关java applet技术
Applet 是一种 Java 程序,它是内嵌在web浏览器中运行java程序的技术。Applet 类没有main()函数,其生命周期包含四部分init 、start、stop、destory:
其实除了上面介绍的四种方法外,其还有一种paint方法,该方法在 start() 方法之后立即被调用,或者在 Applet 需要重绘在浏览器的时候调用。paint() 方法实际上继承于 java.awt。
二、java applet应用示例
创建一个简单的HelloWorldApplet.java 代码,内容如下:
import java.applet.*;
import java.awt.*;
public class HelloWorldApplet extends Applet
{
public void paint (Graphics g)
{
g.drawString ("Hello java applet,my site:361way.com ", 25, 50);
}
}
编译为class文件,再创建一个html页面,引用该文件:
The Hello, World AppletIf your browser was Java-enabled, a "Hello, World"
message would appear here.
此时可以通过appletviewer指令查看,也可以使用支持java的浏览器查看(IE\firefox\chrome都支持,不过要启用java插件)。
也可以使用浏览器访问,浏览器使用时,一般在html页面的 code前还会加basecode参数,即指定该class或jar文件的来源路径,这个可以是相对路径,也可以是绝对路径:
或
浏览器查看的结果如下:
点击运行后,就会返回"Hello java applet,my site:361way.com " 。
三、HP ilo口之java applet
访问ilo口的json/login_session页面,post登陆信息,会返回session key信息,这个可以用shell 很简单的实现:
address=https://10.212.52.98
username=ilousername
password=ilopassword
session_key=$(
curl -fsS \
--insecure \
"$address/json/login_session" \
--data "{\"method\":\"login\",\"user_login\":\"$username\",\"password\":\"$password\"}" |
sed 's/.*"session_key":"\([a-f0-9]\{32\}\)".*/\1/'
) || {
echo "Error retrieving session key" >&2
exit 1
}
接下来分析页面,会发现在点击console口调用时,引用startJavarc方法,通过IE DOM资源管理器查找了对应的javascript调用内容如下(难得表扬下微软,这个功能确实在查找时比firefox好用一些):
function startIrc() {
iLO.startIrc(me.rc_https);
}
function startJavaRc() {
iLO.setCookie("irc",["last","jrc"]);
iLO.startJavaRc(me.rc_https);
}
该方法被定义在 https://$address/js/iLO.js 文件,有startirc和startjavarc两个函数(代码不黏了,下一篇再粘)。通过startjavarc函数,可以看到其调用applet的页面为"$address/html/java_irc.html?sessionKey=${session_key}&lang=en" (这个不看js,单纯在firefox的网络页面中也能看到),通过get方法获取对应的页面关键内容为:
var _app = navigator.appName;
var skey = getSearchValue(location.search,"sessionKey");
var langId = getSearchValue(location.search,"lang");
var rport = window.name;
if (_app == 'Netscape') {
document.writeln("
document.writeln("type=\"application/x-java-applet\"");
document.writeln("archive=/html/intgapp_099.jar width=200 height=100");
document.writeln("RCINFO0=\"MHgxDWZjYzYwNDAyM2UxNDZhYzI0YTdiN2M2ZGM3MzE0ZDQ3\"");
document.writeln("RCINFO1=\""+skey+"\"");
document.writeln("RCINFO3E=\"1\"");
document.writeln("RCINFO6=\""+rport+"\"");
document.writeln("RCINFO7=\"35791394\"");
document.writeln("RCINFO8=\"1\"");
document.writeln("RCINFOA=\"1\"");
document.writeln("RCINFOB=\"A4E3F9D86FE5B1D076780BEEBC3FE09B\"");
document.writeln("RCINFOC=\"F29E12581A79FD660C565004EA8FD2BD\"");
document.writeln("RCINFOD=\"102603\"");
document.writeln("RCINFOM=\"1\"");
document.writeln("RCINFOMM=\"1\"");
document.writeln("RCINFON=\"0\"");
document.writeln("RCINFOO=\"3389\"");
document.writeln("RCINFOLANG=\""+langId+"\"");
document.writeln("INFO0\=\"7AC3BDEBC9AC64E85734454B53BB73CE\"");
document.writeln("INFO1\=\"17988\"");
document.writeln("INFO2\=\"composite\"");
document.writeln("INFO3\=\"linux-mt4s\"");
document.writeln("INTGTITLE=\"Integrated Remote Console\">");
document.writeln("");
document.writeln("Download JVM from above link, if the Remote Console applet is not displayed");
document.writeln("
document.writeln("<\/noembed>");
document.writeln("<\/embed>");
}
else if (_app == 'Microsoft Internet Explorer') {
document.writeln("
document.writeln("ARCHIVE=/html/intgapp_099.jar width=200 height=100>");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("Download JVM from above link, if the Remote Console applet is not displayed");
document.writeln("
document.writeln("<\/APPLET>");
}
else {
alert('Message from Generic Browser');
}
可以看到上面四个变量里,第一个会判断浏览器类型,根据IE和火狐选择执行不同的代码,另一个关键参数就是skey ---- sesskonkey ,该参数实际上上面我们已经拿到。上面可以看到,其实际主要调用了/html/intgapp_099.jar文件,该文件可以下载下来细看里面的内容。不过了解了原理后,该jar包内容是可以忽略的。不过直接使用该返回内容保存为html页面打开是不通访问console内容的,因为这个是通过js调用,内嵌页面的方式出来的,所以这里没有指定另一个关键的参数,basecode。接下来需要做的就是在code代码行增加 codebase参数即可实现console的自动调用。
通过写好的python自动处理脚本,即可实现一键打开管理口内容:
不过该html页面是无法通过appletviewer进行调用的,因为script 明确指定是浏览器调用,如果想要通过appletviewer进行调用,可以使用上面示例中的方法,修改该页面内容就行了。