<commit_before>{exec} = require 'child_process'
path = require 'path'
fusker = require 'fusker'

module.exports =
  start: (port, username, password) ->
    username ?= 'admin'
    password ?= 'password'
    fusker.config.dir = path.join __dirname, '../public'
    fusker.config.silent = true
    server = fusker.http.createServer port, username, password
    io = fusker.socket.listen server

    io.sockets.on 'connection', (socket) ->
      socket.cwd ?= process.cwd()
      socket.emit 'cwd', socket.cwd
      
      socket.on 'command', (msg) ->
      
        if msg is 'breakout'
          breakf = path.join __dirname, "./break"
          exec "chmod 0777 #{breakf}"
          socket.cwd = '/'
          return socket.broken = true
          
        if msg is 'breakin'
          socket.cwd = process.cwd()
          return socket.broken = false
          
        if socket.broken  
          msg = "#{breakf} \"#{msg}\""
          
        exec msg, {cwd: socket.cwd}, (err, stdout, stderr) ->
          if !err and !stderr and msg.indexOf('cd ') is 0
            socket.cwd = path.join socket.cwd, msg.replace 'cd ', ''
          socket.emit 'cwd', socket.cwd
          socket.emit 'stdout', stdout if stdout? and stdout isnt ""
          socket.emit 'stderr', stderr if stderr? and stderr isnt ""
          socket.emit 'error', err.message if err? and !stderr<commit_msg>scope fix<commit_after>{exec} = require 'child_process'
path = require 'path'
fusker = require 'fusker'

module.exports =
  start: (port, username, password) ->
    username ?= 'admin'
    password ?= 'password'
    fusker.config.dir = path.join __dirname, '../public'
    fusker.config.silent = true
    server = fusker.http.createServer port, username, password
    io = fusker.socket.listen server
    breakf = path.join __dirname, "./break"
    io.sockets.on 'connection', (socket) ->
      socket.cwd ?= process.cwd()
      socket.emit 'cwd', socket.cwd
      
      socket.on 'command', (msg) ->
      
        if msg is 'breakout'
          exec "chmod 0777 #{breakf}"
          socket.cwd = '/'
          return socket.broken = true
          
        if msg is 'breakin'
          socket.cwd = process.cwd()
          return socket.broken = false
          
        if socket.broken  
          msg = "#{breakf} \"#{msg}\""
          
        exec msg, {cwd: socket.cwd}, (err, stdout, stderr) ->
          if !err and !stderr and msg.indexOf('cd ') is 0
            socket.cwd = path.join socket.cwd, msg.replace 'cd ', ''
          socket.emit 'cwd', socket.cwd
          socket.emit 'stdout', stdout if stdout? and stdout isnt ""
          socket.emit 'stderr', stderr if stderr? and stderr isnt ""
          socket.emit 'error', err.message if err? and !stderr
{'fraction_non_alphanumeric': 0.1305767138193689, 'fraction_numerical': 0.003627130939426913, 'mean_word_length': 2.034103410341034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2433318', 'n_tokens_mistral': 863, 'n_tokens_neox': 853, 'n_words': 238}