jquery-terminal

How to limit commands in jQuery terminal


I've been using wterm in my application fork, but now is guess is very old and discontinued. I've try to migrate to jquery-terminal, but I didn't understand well how configure.

With old wterm:
https://github.com/wanderleihuttel/webacula/blob/branch-7.4/application/views/scripts/bconsole/wterminal.phtml

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

There is a easy mode to configure? And include only the commands I allow?

My current function:

$('#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;
    }
  }
);

Solution

  • You can use this, (if you want to only execute commands that are on the list of cmd object) but you should also filter commands on the sever if you want this terminal to be public.

    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;
        }
      }
    );