diff --git a/Makefile.am b/Makefile.am index 83b1c02..725efc6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,7 @@ EXTRA_DIST = demo/beep.wav \ shellinabox/shellinaboxd.man.in \ shellinabox/shell_in_a_box.js \ shellinabox/vt100.js \ + shellinabox/cgi-mode-example.sh \ debian/README \ debian/README.available \ debian/README.enabled \ diff --git a/Makefile.in b/Makefile.in index 88bff5f..3c7e107 100644 --- a/Makefile.in +++ b/Makefile.in @@ -276,6 +276,7 @@ EXTRA_DIST = demo/beep.wav \ shellinabox/shellinaboxd.man.in \ shellinabox/shell_in_a_box.js \ shellinabox/vt100.js \ + shellinabox/cgi-mode-example.sh \ debian/README \ debian/README.available \ debian/README.enabled \ diff --git a/debian/docs b/debian/docs index 885f1b8..cdd3d28 100644 --- a/debian/docs +++ b/debian/docs @@ -5,3 +5,4 @@ INSTALL NEWS README TODO +shellinabox/cgi-mode-example.sh diff --git a/shellinabox/cgi-mode-example.sh b/shellinabox/cgi-mode-example.sh new file mode 100755 index 0000000..bc3e5ca --- /dev/null +++ b/shellinabox/cgi-mode-example.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# This is a simple demo CGI script that illustrates how to use ShellInABox in +# CGI mode. + +case "${REQUEST_METHOD}" in + POST) + # Retrieve CGI parameter, then start shellinabox with this command + read parms + parms="$(printf "$(echo "${parms}"|sed -e 's/%\(..\)/\\x\1/g;s/%/%%/g')")" + parms="${parms#cmd=}" + shellinaboxd --cgi -t -s "/:$(id -u):$(id -g):HOME:${parms}" + ;; + + *) # First time that the CGI script was called. Show initial HTML page. + printf 'Content-Type: text/html\r\n\r\n' + cat < + + Demo CGI for ShellInABox + + +

Shell In A Box

+ +

This is a demo CGI script for ShellInABox. It shows how to execute + ShellInABox in one-shot CGI mode.

+ +

Please note that we do not implement any access controls. So, this + script is unsafe to use on any untrusted network. It allows anybody + on the Internet to run arbitrary commands on your computer!

+ +

Use this as a template to write your own custom application -- and + don't forget to add appropriate access controls.

+ +

Enter command to run: +

+ +
+

+ +EOF + ;; +esac diff --git a/shellinabox/shellinaboxd.c b/shellinabox/shellinaboxd.c index caa1e58..350e313 100644 --- a/shellinabox/shellinaboxd.c +++ b/shellinabox/shellinaboxd.c @@ -1220,7 +1220,7 @@ int main(int argc, char * const argv[]) { printf("X-ShellInABox-Port: %d\r\n" "X-ShellInABox-Pid: %d\r\n" "Content-type: text/html; charset=utf-8\r\n\r\n", - port, pid); + port, getpid()); printfUnchecked(cgiRoot, port, cgiSessionKey); fflush(stdout); free(cgiRoot);