//全局 var host_ssh_list = []; //刷新页面 $(window).unload(function(){ for (i in host_ssh_list) { host_ssh_list[i].close(); } return false; }); function appPost(method,args,callback){ var _args = null; if (typeof(args) == 'string'){ _args = JSON.stringify(toArrayObject(args)); } else { _args = JSON.stringify(args); } var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); $.post('/plugins/run', {name:'webssh', func:method, args:_args}, function(data) { layer.close(loadT); if (!data.status){ layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); return; } if(typeof(callback) == 'function'){ callback(data); } },'json'); } function appAsyncPost(method,args){ var _args = null; if (typeof(args) == 'string'){ _args = JSON.stringify(toArrayObject(args)); } else { _args = JSON.stringify(args); } return syncPost('/plugins/run', {name:'webssh', func:method, args:_args}); } function appPostCallbak(method, args, callback){ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); var req_data = {}; req_data['name'] = 'webssh'; req_data['func'] = method; args['version'] = '1.0'; if (typeof(args) == 'string'){ req_data['args'] = JSON.stringify(toArrayObject(args)); } else { req_data['args'] = JSON.stringify(args); } $.post('/plugins/callback', req_data, function(data) { layer.close(loadT); if (!data.status){ layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); return; } if(typeof(callback) == 'function'){ callback(data); } },'json'); } $(document).ready(function(){ var tag = $.getUrlParam('tag'); if(tag == 'webssh'){ webShell_Load(); } }); function webShell_Resize(){ var cur_ssh = $('.term_item_tab .list .active'); var data = $(cur_ssh).data(); var item = host_ssh_list[data.id]; item.term.focus(); item.term.fit(); item.resize({ cols: item.term.cols, rows: item.term.rows}); } function webShell_Load(){ changeDivH(); $(window).resize(function(){ changeDivH(); webShell_Resize(); }); $('.term_content_tab .term-tool-button').click(function(){ if ($(this).hasClass('tool-show')){ $('#term_box_view').css('margin-right',300); $('.term_tootls').css('display',"block"); $(this).removeClass('tool-show').addClass('tool-hide'); $(this).find('span').removeClass('glyphicon-menu-left').addClass('glyphicon-menu-right'); } else { $('#term_box_view').css('margin-right',0); $('.term_tootls').css('display',"none"); $(this).removeClass('tool-hide').addClass('tool-show'); $(this).find('span').removeClass('glyphicon-menu-right').addClass('glyphicon-menu-left'); } webShell_Resize(); }); $('.full_exit_screen').click(function(ele){ if($(this).hasClass('glyphicon-resize-full')){ requestFullScreen($('#term_box_view')[0]); $(this).removeClass('glyphicon-resize-full').addClass('glyphicon-resize-small'); } else{ exitFull(); $(this).removeClass('glyphicon-resize-small').addClass('glyphicon-resize-full'); } }); $('.addServer').click(function(){ webShell_addServer(); }); $('.tootls_host_btn').click(function(){ webShell_addServer(); }); $('.tootls_commonly_btn').click(function(){ webShell_cmd(); }); // 切换服务器终端视图 $('.term_item_tab .list').on('click', 'span.item', function (ev) { var index = $(this).index(); var data = $(this).data(); if ($(this).hasClass('addServer')) { } else if ($(this).hasClass('tab_tootls')) { } else { $(this).addClass('active').siblings().removeClass('active'); $('.term_content_tab .term_item:eq(' + index + ')').addClass('active').siblings().removeClass('active'); webShell_Resize(); } }); $('.term_item_tab').on('click', '.icon-trem-close', function () { var id = $(this).parent().data('id'); webShell_removeTermView(id); }) //服务器列表和常用命令 webShell_getHostList(); //服务器列表和命令切换 $('.term_tootls .tab-nav span').click(function(){ var list_type = $(this).attr('data-type'); if (!$(this).hasClass('on')){ $('.term_tootls .tab-nav span').removeClass('on'); $(this).addClass('on'); $('.term_tootls .tab-con .tab-block').removeClass('on') if (list_type == 'host'){ $('.term_tootls .tab-con .tab-block').eq(0).addClass('on'); webShell_getHostList(); } if (list_type == 'shell'){ $('.term_tootls .tab-con .tab-block').eq(1).addClass('on'); webShell_getCmdList(); } } }); webShell_Menu(); // webShell_Resize(); // $('.term_content_tab .term-tool-button').click(); } function changeDivH(){ var l = $(window).height(); $('#term_box_view').parent().css('height',l-80); $('#xterm-viewport').css('height',l-80); $('.tootls_host_list').css('display','block').css('height',l-192); $('.tootls_commonly_list').css('display','block').css('height',l-192); } // 窗口状态改变 function fullScreenChange(el, callback) { el.addEventListener("fullscreenchange", function () { callback && callback(document.fullscreen); }); el.addEventListener("webkitfullscreenchange", function () { callback && callback(document.webkitIsFullScreen); }); el.addEventListener("mozfullscreenchange", function () { callback && callback(document.mozFullScreen); }); el.addEventListener("msfullscreenchange", function () { callback && callback(document.msFullscreenElement); }); } // 全屏 function requestFullScreen(element) { var requestMethod = element.requestFullScreen || //W3C element.webkitRequestFullScreen || //Chrome等 element.mozRequestFullScreen || //FireFox element.msRequestFullScreen; //IE11 if (requestMethod) { requestMethod.call(element); }else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } } //退出全屏 function exitFull() { var exitMethod = document.exitFullscreen || //W3C document.mozCancelFullScreen || //Chrome等 document.webkitExitFullscreen || //FireFox document.webkitExitFullscreen; //IE11 if (exitMethod) { exitMethod.call(document); }else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } } function webShell_getCmdList(){ appPost('get_cmd_list', {}, function(rdata){ var rdata = $.parseJSON(rdata.data); var alist = rdata.data; var tli = ''; for (var i = 0; i < alist.length; i++) { tli+='