【问题标题】:How to limit commands in jQuery terminal如何在 jQuery 终端中限制命令
【发布时间】:2017-05-09 02:04:21
【问题描述】:

我一直在我的应用程序分支中使用 wterm,但现在猜测已经很老了并且已停产。我已经尝试迁移到 jquery-terminal,但我不太了解如何配置。

使用旧 wterm:
https://github.com/wanderleihuttel/webacula/blob/branch-7.4/application/views/scripts/bconsole/wterminal.phtml

当前:
https://github.com/wanderleihuttel/webacula/blob/branch-7.5/application/views/scripts/bconsole/wterminal.phtml

有简单的模式配置吗?并且只包含我允许的命令?

我目前的功能:

$('#wterm').terminal(function(command, term) {
    term.pause();
    if(command != ""){
       $.post('<?php echo $this->baseUrl, '/bconsole/cmd' ?>', {'bcommand': command, 'command': cmd }).then(function(response) {
           term.echo(response,{raw:true}).resume();
       });
    } else{
      term.exec('clear').resume();  
    } //end if
  }, 
  {
    greetings: welcome,
    prompt: 'bconsole> ',
    height: 400,
    onBlur: function(){
       return false;
    }
  }
);

【问题讨论】:

    标签: jquery-terminal


    【解决方案1】:

    您可以使用它(如果您只想执行 cmd 对象列表中的命令),但如果您希望此终端是公共的,您还应该过滤服务器上的命令。

    var available = Object.keys(cmd);
    
    $('#wterm').terminal(function(command, term) {
        term.pause();
        var name = $.terminal.parse_command(command).name;
        // run only commands that are on the list
        if (available.indexOf(name) != -1) {
           $.post('<?php echo $this->baseUrl, '/bconsole/cmd' ?>', {'bcommand': command, 'command': cmd }).then(function(response) {
               term.echo(response,{raw:true}).resume();
           });
        } else{
          term.exec('clear').resume();  
        } //end if
      }, 
      {
        greetings: welcome,
        prompt: 'bconsole> ',
        height: 400,
        onBlur: function(){
           return false;
        }
      }
    );
    

    【讨论】:

    • 谢谢。成功了!
    猜你喜欢
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2022-01-06
    • 2020-11-11
    • 1970-01-01
    • 2018-09-23
    相关资源
    最近更新 更多