]> andersk Git - test.git/commitdiff
Apparently, CGI mode is hard to figure out. Added an example showing how to
authorMarkus Gutschke <markus@shellinabox.com>
Mon, 17 Aug 2009 17:14:32 +0000 (17:14 +0000)
committerMarkus Gutschke <markus@shellinabox.com>
Mon, 17 Aug 2009 17:14:32 +0000 (17:14 +0000)
use it.

Makefile.am
Makefile.in
debian/docs
shellinabox/cgi-mode-example.sh [new file with mode: 0755]
shellinabox/shellinaboxd.c

index 83b1c02321e18ca2c001c86df1674c3969285fda..725efc67d5096b8be9b36dbf6732348267c2bd90 100644 (file)
@@ -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                                  \
index 88bff5f6cff09c2e9884d747931c9810764cd74f..3c7e1075617c1fb25932b363a6d5bcb46b0170fe 100644 (file)
@@ -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                                  \
index 885f1b8e3cd75ffb547f0fdb9d921a7217d04a74..cdd3d28ca2d1ab5f213930387b30969c074e5dee 100644 (file)
@@ -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 (executable)
index 0000000..bc3e5ca
--- /dev/null
@@ -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 <<EOF
+     <html>
+       <head>
+         <title>Demo CGI for ShellInABox</title>
+       </head>
+       <body>
+         <h1>Shell In A Box</h1>
+
+         <p>This is a demo CGI script for ShellInABox. It shows how to execute
+         ShellInABox in one-shot CGI mode.</p>
+
+         <p>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!</p>
+
+         <p>Use this as a template to write your own custom application -- and
+         don't forget to add appropriate access controls.</p>
+
+         <p>Enter command to run:
+         <form method="POST">
+           <input type="text" name="cmd" style="width: 40em" value="/bin/bash" />
+         </form>
+         </p>
+       </body>
+EOF
+     ;;
+esac
index caa1e580e735ceea41c8ef33d8cefb8772c01d2a..350e3136fc1486dc4b702f09cdb5e3b6fe8b2d0f 100644 (file)
@@ -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);
This page took 0.036923 seconds and 5 git commands to generate.