[REBOL] [shell core] Shell access for rebol/core on win32
From: luke:marmaladefoo at: 10-Jan-2004 14:14
Dear list
I've been annoyed at the lack of shell access in REBOL for
some time now. So I have implemented a simple fix. I
know others have done other fixes, but this works for me.
This setup is for Windows, for unix you would have to
write a slightly different cgi page.
It requires a cgi-compatible webserver (e.g. Apache,
Xitami etc) and python with the python win32 extensions.
python: http://www.python.org/
python win32 extensions:
http://starship.python.net/crew/mhammond/win32/Downloads.html
My contribution are the two scripts below. One REBOL
script which sends the command to the python cgi script
running on a webserver on the same machine. I use Xitami
because it is small and easy to configure, but if you are
running Apache, that should work too.
It uses base64 encoding of the command-line and
response to ensure correct transfer of data without
corruption.
It could be tightened up to increase security (e.g. only
permit connections from 127.0.0.1), but that is left as an
exercise for the reader.
Enjoy!
- Luke
_____REBOL SHELL CLIENT___________
;---the function "call"
;---relies on a python CGI-script which takes one argument "cmd" (base64 encoded command)
;---and returns the result base64 encoded.
;---you will have to set shell-server-url as appropriate
shell-call: func [shell-string /local rslt shell-server-url] [
shell-server-url: http://localhost/cgi-bin/python/execute-cmd.py
rslt: read to-url rejoin [shell-server-url "?cmd=" enbase/base shell-string 64]
return to-string (debase/base :rslt 64)
]
_____PYTHON CGI SHELL SERVER____________
#!/c:\python22\bin\python.exe
import cgi
import win32pipe
import base64
print "Content-Type: text/plain\n\n"
#assume cmd is base64 encoded
cmd = base64.decodestring(The_Form["cmd"].value)
#open a pipe with that command
f = win32pipe.popen(cmd)
#return the response base64 encoded
print base64.encodestring(f.read())
#close the pipe
f.close()
__________________________________________
Various gadgets widgets, links and chat
http://www.marmaladefoo.com
__________________________________________<