[REBOL] Re: [shell core] Shell access for rebol/core on win32
From: luke:marmaladefoo at: 10-Jan-2004 15:05
Oops I spotted a mistake in my last post, python script
should be as follows. I've reincluded the rebol client too.
The script got broken when I tried to tidy it up too much...
- Luke
________PYTHON CGI SHELL SERVER SCRIPT_______
#!/c:\python22\bin\python.exe
import cgi
import win32pipe
import base64
print "Content-Type: text/plain\n\n"
#get the cgi form data
form = cgi.FieldStorage()
#assume cmd is base64 encoded
base64cmd = form["cmd"].value
cmd = base64.decodestring(base64cmd)
#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()
_______END PYTHON SCRIPT___________
_______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)
]
____END REBOL SHELL CLIENT FUNCTION__
From: "Luke" <[luke--marmaladefoo--com]>
To: [rebol-list--rebol--com]
Date sent: Sat, 10 Jan 2004 14:14:34 -0000
Subject: [REBOL] [shell core] Shell access for rebol/core on win32
Priority: normal
Send reply to: [rebol-list--rebol--com]
> 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
> __________________________________________
> --
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
>
__________________________________________
Various gadgets widgets, links and chat
http://www.marmaladefoo.com
__________________________________________<