Beispiel #1
0
  ws.on('open', () => {
    if (text) {
      console.log(`posting data to ${url}:\n\n${text}\n`)
      const mime = 'text/plain'
      const arrayBuffer = str2ab(text)
      const abWithMime = arrayBufferWithMime(arrayBuffer, mime)
      send(abWithMime)
    }

    if (filepath) {
      console.log(`posting file data to ${url}:\n\n${filepath}\n`)
      const data = fs.readFileSync(filepath, 'utf8')

      const mime = 'text/plain'
      const arrayBuffer = str2ab(data)
      const abWithMime = arrayBufferWithMime(arrayBuffer, mime)
      send(abWithMime)
    }

    ws.close()
  })
Beispiel #2
0
  socket.on('data', async (buffer) => {
    if (line == 0 && !expired) {
      let data = buffer.toString()
      if (data[0] === '#') {
        const re = /#([a-zA-Z0-9]+)\n?\r?/
        const matches = data.match(re)
        if (matches.length > 1) {
          channel = normalizeChannel(matches[1])
          if (!isValidChannelName(channel)) {
            socket.write(`streamhut: channel name "${channel}" is not available`)
            socket.end()
            return
          }
          line++
          return
        }
      }
    }

    if (!channel) {
      return
    }

    const mime = 'shell'
    const abWithMime = arrayBufferWithMime(buffer.buffer, mime)
    insertStreamLog(channel, buffer)

    const clients = socks[channel]

    if (clients) {
      clients.forEach(client => {
        console.log(`streaming to ${client.id} ${channel}`)
        client.send(abWithMime)
      })
    }
  })