瀏覽代碼

shell 界面删除控制;

demon 8 年之前
父節點
當前提交
434e615ef9

+ 2 - 2
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/LinuxShellService.java

@ -83,8 +83,8 @@ public class LinuxShellService {
                    logger.error("sendMessage to broker server failed, broker:" + broker.getURL() + ", msg:" + msg);
                    continue;
                }else {
                    System.out.println("发送shell请求到broker成功!!!");
                    //TODO shell执行成功,见执行结果返回到中心显示。
                    logger.debug("发送shell请求到broker成功");
                    // shell执行成功,见执行结果返回到中心zbus显示。
                    ServiceShell serviceShell = objectMapper.readValue(msg,ServiceShell.class);
                    Producer producer = new Producer(zbusBroker, ServiceFlowConstant.SHELL_RESPONSE + "@" + serviceShell.getTenant());
                    producer.createMQ();    //确定为创建消息队列需要显示调用

+ 4 - 1
hos-broker/src/main/java/com/yihu/hos/broker/common/shell/SSHLinuxTool.java

@ -1,6 +1,7 @@
package com.yihu.hos.broker.common.shell;
import com.jcraft.jsch.*;
import com.yihu.hos.core.file.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -104,8 +105,10 @@ public class SSHLinuxTool {
                    throw new Exception("network error.");
                }
                String result = FileUtil.readFileText(data);
                System.out.println("FileUtil獲取内容:"+result);
                //转换输出结果并打印出来
                String temp = new String(data, 0, nLen, "iso8859-1");
                String temp = new String(data, 0, nLen, "utf-8");
                System.out.println(temp);
                return temp;
            }

+ 13 - 5
src/main/java/com/yihu/hos/remoteManage/controller/RemoteShellController.java

@ -47,14 +47,12 @@ public class RemoteShellController extends BaseController {
    public Result sendShell(
            @ApiParam(name = "command", value = "shell命令")
            @RequestParam(value = "command", required = false) String command,
//            @ApiParam(name = "tenant", value = "租户名称")
//            @RequestParam(value = "tenant", required = false) String tenant,
            @ApiParam(name = "disCon", value = "是否断开会话连接")
            @RequestParam(value = "disCon", required = true) boolean disCon) {
        String result = "";
        try {
            //TODO 发送shell命令 消息
            System.out.println("发送shell请求:"+command);
            System.out.println("发送shell请求:" + command);
            remoteShellService.sendShell(command, disCon);
            return Result.success("shell请求发送成功!");
        } catch (Exception e) {
@ -73,8 +71,18 @@ public class RemoteShellController extends BaseController {
            //TODO 如何去除等待时间,目前添加sleep是因为需要等待zbus回调方法的返回结果;
            Thread.sleep(2000);
            String attachment = LocalContext.getContext().getAttachment(ContextAttributes.TENANT_NAME);
            result = LocalContext.getContext().getAttachment(ContextAttributes.SHELL_RESPONSE+attachment);
            System.out.println("接口返回结果:"+result);
            result = LocalContext.getContext().getAttachment(ContextAttributes.SHELL_RESPONSE + attachment);
            int count = 0;
            while (result == null) {
                count++;
                Thread.sleep(2000);
                result = LocalContext.getContext().getAttachment(ContextAttributes.SHELL_RESPONSE + attachment);
                //获取失败时,尝试再一次获取结果
                if (count > 2) {
                    break;
                }
            }
            System.out.println("接口返回结果:" + result);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

+ 20 - 0
src/main/java/com/yihu/hos/tenant/controller/TenantController.java

@ -180,6 +180,26 @@ public class TenantController extends BaseController{
        }
    }
    /**
     * 新建数据库
     * @param request
     * @return
     */
    @RequestMapping(value = "/createDB" , produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public Result createDB(HttpServletRequest request,
                           @ApiParam(name = "dbName", value = "数据库名称", allowMultiple = true)
                           @RequestPart() String dbName) {
        try {
            tenantService.createDB(dbName);
            return Result.success("新建数据库成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("新建数据库失败!");
        }
    }
    /**
     *  //TODO 后 独立到对应的rest接口中

+ 4 - 1
src/main/java/com/yihu/hos/tenant/dao/TenantDao.java

@ -59,6 +59,9 @@ public class TenantDao extends SQLGeneralDAO {
    }
    public void createDB(String dbName) throws Exception {
        String sql = "CREATE DATABASE "+dbName;
        super.execute(sql);
    }
}

+ 5 - 0
src/main/java/com/yihu/hos/tenant/service/TenantService.java

@ -131,5 +131,10 @@ public class TenantService {
        }
    }
    @Transactional
    public Result createDB(String dbName) throws Exception {
        tenantDao.createDB(dbName);
        return Result.success("新建成功");
    }
}

+ 7 - 1
src/main/webapp/WEB-INF/ehr/jsp/monitor/shell/shell.jsp

@ -17,11 +17,17 @@
    <!-- ####### 查询条件部分 ####### -->
    <div class="m-form-inline">
        <div class="m-form-group">
            <div class="m-form-control left" >
                <label style="font-size: 16px;font-weight: bold;">终端服务器控制台</label>
            </div>
        </div>
        <div class="m-form-group">
            <div class="m-form-control left" >
               <input type="checkbox" id="disCon" aria-valuetext="保持会话连接" checked="checked" />保持会话连接
            </div>
        </div>
    </div>
    <!--######菜单信息表######-->

+ 41 - 3
src/main/webapp/WEB-INF/ehr/jsp/monitor/shell/shellJs.jsp

@ -33,17 +33,23 @@
        anthorize: function (id) {
        },
        sendShell:function(command){
            var disCon;
            var statuaValue = $("#disCon").ischecked;
            if("checked" == statuaValue){
                disCon = true;
            }else{
                disCon = false;
            }
            $.ajax({ //ajax处理
                type: "GET",
                url : "${contextRoot}/shell/sendShell",
                dataType : "json",
                data:{command:command,disCon:false},
                data:{command:command,disCon:disCon},
                cache:false,
                success :function(data){
                    if(data.successFlg) {
                        var flg = data.successFlg;
                        if(flg){
                            debugger
                            shell.getShellBack();
                        }else{
                            alert("shell请求命令失败!");
@ -70,7 +76,20 @@
                    if(data.successFlg) {
                        var flg = data.successFlg;
                        if(flg){
                            $("#main_text").val(data.message);
                            debugger
                            //TODO 字体颜色textare无法解析,所以暂时去除,后面看看有没有其他控件可以比较完美的支持
                            var content=data.message.myReplace("\\u001B\\[0m\\u001B\\[01;31m","").myReplace("\\u001B\\[0m","").myReplace("\\u001B\\[01;31m","").myReplace("\\u001B\\[01;34m","");
                            if(content.endsWith("]# ")){
                                $("#main_text").keydown(function(){
                                    PingBi(8);
                                });
                                $("#main_text").val(content);
                            }else{
                                $("#main_text").val(content+"\n ~]# ");
                                $("#main_text").keydown(function(){
                                    PingBi(8);
                                });
                            }
                        }else{
                            alert("shell请求命令失败!");
                        }
@ -94,6 +113,25 @@
    };
    function PingBi(id){
        var command = $("#main_text").val();
        var arr=command.split("\r\n");
        var currentCommand = arr[0];
        var k=window.event.keyCode;
        /* 以]# 结束的一行,使之无法删除*/
        if(k==id && currentCommand.endsWith("]# ")){
            window.event.keyCode=0;
            window.event.returnValue=false;
            return false;
        }
    }
    String.prototype.myReplace=function(f,e){//吧f替换成e
        var reg=new RegExp(f,"g"); //创建正则RegExp对象
        return this.replace(reg,e);
    }
    $(function () {
        shell.init();
        shell.sendShell("\n");