在django中集成tightvnc

来源:互联网 发布:java发起get请求 编辑:程序博客网 时间:2024/06/05 15:51

下载和copy文件

下载tightvnc,并将html和jar包都拷贝到项目相应位置中。

例如:

osi_web/templates/viewer-applet.html

ui_content/tightvnc-jviewer.jar

这里html文件我直接给改了。


修改模版

viewer-applet.html ,

<param name="Host" value="{{ Host }}" /> <!-- Host to connect. Default:  the host from which the applet was loaded. -->                        <param name="Port" value="5901" /> <!-- Port number to connect. Default: 5900 -->
这里端口默认为 5901


修改views.py

def vncviewer(request,ip):    t = get_template('viewer-applet.html')    html = t.render(RequestContext(request, {        'version': '1.0',        'Host': ip,    }))    return HttpResponse(html)
这里ip从页面url传递过来

修改urls.py

(r'system/vncviewer/(?P<ip>.+)$', 'osi_web.views.vncviewer'),

页面

这里用的是公司的前端组件,大概意思都差不多

{                                id : "btn_vnc",                                text : "远程连接",                                disabled : false,                                iconCls : "icon-add",                                handler : _(function() {                                        this.initvncView(this.systems.getSelectedModels()[0]['interfaces']['eth0']['ip_address']);                                }).bind(this)                        }

initvncView : function(ip){            window.open("vncviewer/" + ip);    }
效果如下,如果浏览器尚未安装java支持的话,需要安装支持。


关于浏览器安装java支持

在windows下相对好装一点,基本按照提示安装即可
在linux比较麻烦,可以搜索有个叫icedtea-web的包,这个是别人适配好的浏览器插件,我测的在fedora中是可用的
yum install icedtea-web



0 0
原创粉丝点击