first commit

This commit is contained in:
编码猿
2024-09-27 01:01:17 +08:00
commit 14b8ae24fa
198 changed files with 22193 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
# middleware to serve the results of shell commands
# Listens to POST /run/
{spawn} = require('child_process')
module.exports = (workingDir, useLoginShell) ->
args = if useLoginShell then ['-l'] else []
# the Connect middleware
(req, res, next) ->
return next() unless req.method == 'POST' and req.url == '/run/'
shell = spawn 'bash', args, cwd: workingDir
command = ''
req.on 'data', (chunk) -> shell.stdin.write chunk
req.on 'end', ->
setStatusOnce = (status) ->
res.writeHead status
setStatusOnce = ->
shell.stderr.on 'data', (d) ->
setStatusOnce 500
res.write d
shell.stdout.on 'data', (d) ->
setStatusOnce 200
res.write d
shell.on 'error', (err) ->
setStatusOnce 500
res.write err.message
shell.on 'close', ->
setStatusOnce 200
res.end()
shell.stdin.write '\n'
shell.stdin.end()