]> andersk Git - test.git/commitdiff
Use JavaScript redirection for attaching the missing slash to
authorMarkus Gutschke <markus@shellinabox.com>
Mon, 27 Jul 2009 18:31:05 +0000 (18:31 +0000)
committerMarkus Gutschke <markus@shellinabox.com>
Mon, 27 Jul 2009 18:31:05 +0000 (18:31 +0000)
the URL. This should make it easier to use reverse proxies. It was
already possible to run shellinaboxd behind a proxy, but a lot of
users got the configuration wrong.

ChangeLog
config.h
configure
configure.ac
demo/vt100.js
shellinabox/root_page.html
shellinabox/shell_in_a_box.js
shellinabox/shell_in_a_box.jspp
shellinabox/shellinaboxd.c
shellinabox/vt100.js

index b5ff00c91061b219c304b04b8b5096f7a1bd9a00..bb06a9ae1c2563dac65f1fa661c97356853979fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-27  Markus Gutschke  <markus@shellinabox.com>
+
+       * Use JavaScript redirection for attaching the missing slash to
+       the URL. This should make it easier to use reverse proxies. It was
+       already possible to run shellinaboxd behind a proxy, but a lot of
+       users got the configuration wrong.
+
 2009-07-08  Markus Gutschke  <markus@shellinabox.com>
 
        * Optionally compress large responses, if the browser accepts
index 66707646fb322e403e5a69a867caf55a8de1fdcb..b70ebf6fc9bcb5fbee2658145dc5ce8e27f82019 100644 (file)
--- a/config.h
+++ b/config.h
 #define STDC_HEADERS 1
 
 /* Most recent revision number in the version control system */
-#define VCS_REVISION "149"
+#define VCS_REVISION "152"
 
 /* Version number of package */
 #define VERSION "2.9"
index b91715165b411b11aae1cdedd57eb17ae233c61c..b95d2e810e692f947f04a3a404765f4d72b8e142 100755 (executable)
--- a/configure
+++ b/configure
@@ -2037,7 +2037,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
-VCS_REVISION=149
+VCS_REVISION=152
 
 
 cat >>confdefs.h <<_ACEOF
index 84d420ef25c1c414d8562e792e64b221d1030f01..4c85c7c2739c40d0d8ef351c7f4ccd4cc5a7eca1 100644 (file)
@@ -2,7 +2,7 @@ AC_PREREQ(2.57)
 
 dnl This is the one location where the authoritative version number is stored
 AC_INIT(shellinabox, 2.9, markus@shellinabox.com)
-VCS_REVISION=149
+VCS_REVISION=152
 AC_SUBST(VCS_REVISION)
 AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}",
                    [Most recent revision number in the version control system])
index 6013cef2ff25b71c6ed2f215e65586e67c927185..1884e8bf80a0a31878f8ab393fca69d210599f97 100644 (file)
@@ -1693,7 +1693,7 @@ VT100.prototype.toggleBell = function() {
 };
 
 VT100.prototype.about = function() {
-  alert("VT100 Terminal Emulator " + "2.9 (revision 149)" +
+  alert("VT100 Terminal Emulator " + "2.9 (revision 152)" +
         "\nCopyright 2008-2009 by Markus Gutschke\n" +
         "For more information check http://shellinabox.com");
 };
index 75ceb110fed206ffb4e3b0b37f3faafd3b51de52..adb3342eda9ae0f8a5a02741f9c1b4f16613018e 100644 (file)
     <title>Shell In A Box</title>
     <link rel="stylesheet" href="styles.css" type="text/css">
     <script type="text/javascript"><!--
+      // Check that our URL is well-formed. Redirect to HTTPS if necessary
+      (function() {
+        var hasSSL = %s;
+        var path   = document.location.pathname;
+        var proto  = hasSSL ? 'https:' : 'http:';
+        if (path.match(/plain/) || !hasSSL) {
+          proto   = 'http:';
+        }
+        path      = path.replace(/\/+/, '/').replace(/\/$/, '');
+        if (!path.match(/(?:\/|\/plain)$/)) {
+          path   += '/';
+        }
+        var url   = proto + '//' + document.location.host + path;
+        if (document.location.search != '' &&
+            document.location.search != '?') {
+          url    += document.location.search;
+        }
+        if (document.location.hash != '' &&
+            document.location.hash != '#') {
+          url    += document.location.hash;
+        }
+        if (url != document.location.href) {
+          document.location.replace(url);
+        }
+      })();
+
       // We would like to hide overflowing lines as this can lead to
       // visually jarring results if the browser substitutes oversized
       // Unicode characters from different fonts. Unfortunately, a bug
index 452268dbc6a95d97989c46456c0bad6b5086ec8f..a360a5df490f9cbc753bac722aad0fa11d0d360d 100644 (file)
@@ -333,7 +333,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) {
           // provide a menu entry to switch between the two.
           var newNode       = document.createElement('li');
           var isSecure;
-          if (document.location.href != '') {
+          if (document.location.hash != '') {
             isSecure        = !this.nextUrl.match(/\?plain$/);
           } else {
             isSecure        =  this.nextUrl.match(/^https:/);
@@ -355,7 +355,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) {
 };
 
 ShellInABox.prototype.about = function() {
-  alert("Shell In A Box version " + "2.9 (revision 149)" +
+  alert("Shell In A Box version " + "2.9 (revision 152)" +
         "\nCopyright 2008-2009 by Markus Gutschke\n" +
         "For more information check http://shellinabox.com" +
         (typeof serverSupportsSSL != 'undefined' && serverSupportsSSL ?
index 29c49e43dba88b02462d132419941b4b3bc8c463..11b91d506664e992a234ec0848e1ca2e2399dae6 100644 (file)
@@ -333,7 +333,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) {
           // provide a menu entry to switch between the two.
           var newNode       = document.createElement('li');
           var isSecure;
-          if (document.location.href != '') {
+          if (document.location.hash != '') {
             isSecure        = !this.nextUrl.match(/\?plain$/);
           } else {
             isSecure        =  this.nextUrl.match(/^https:/);
index db28faf00b1116a8f99a80602b80b9ea2d44bce1..29bde7187e964bc4e43d65fa668de7aff3776d0f 100644 (file)
@@ -468,7 +468,6 @@ static int shellInABoxHttpHandler(HttpConnection *http, void *arg,
 
   // Normalize the path info
   const char *pathInfo    = urlGetPathInfo(url);
-  int trailingSlash       = *pathInfo == '/';
   while (*pathInfo == '/') {
     pathInfo++;
   }
@@ -479,44 +478,26 @@ static int shellInABoxHttpHandler(HttpConnection *http, void *arg,
   }
   int pathInfoLength      = endPathInfo - pathInfo;
 
-  // The root page should always have a trailing slash. If it doesn't do so,
-  // the JavaScript code cannot easily find related resources.
-  if (!pathInfoLength && !trailingSlash) {
-    char *redir           = stringPrintf(NULL,
-                                        "HTTP/1.1 302 Temporary Relocation\r\n"
-                                        "Connection: close\r\n"
-                                        "Content-Length: 0\r\n"
-                                        "Content-Type: text/html\r\n"
-                                        "Location: %s/\r\n"
-                                        "\r\n",
-                                        urlGetURL(url));
-    debug("Redirecting to %s/", urlGetURL(url));
-    httpTransfer(http, redir, strlen(redir));
-  } else if (!pathInfoLength ||
-      (pathInfoLength == 5 && !memcmp(pathInfo, "plain", 5))) {
-    // The root page either serves the AJAX application or redirects to the
-    // secure HTTPS URL.
+  if (!pathInfoLength ||
+      (pathInfoLength == 5 && !memcmp(pathInfo, "plain", 5)) ||
+      (pathInfoLength == 6 && !memcmp(pathInfo, "secure", 6))) {
+    // The root page serves the AJAX application.
     if (contentType &&
         !strncasecmp(contentType, "application/x-www-form-urlencoded", 33)) {
       // XMLHttpRequest carrying data between the AJAX application and the
       // client session.
       return dataHandler(http, arg, buf, len, url);
     }
-    if (enableSSL && !pathInfoLength && strcmp(urlGetProtocol(url), "https")) {
-      httpSendReply(http, 200, "Shell In A Box",
-                    "<script type=\"text/javascript\"><!--\n"
-                      "document.location.replace("
-                        "document.location.href.replace(/^http:/,'https:'));\n"
-                      "--></script>\n"
-                      "<noscript>\n"
-                        "JavaScript must be enabled for ShellInABox\n"
-                      "</noscript>");
-    } else {
-      extern char rootPageStart[];
-      extern char rootPageEnd[];
-      serveStaticFile(http, "text/html; charset=utf-8",
-                      rootPageStart, rootPageEnd);
-    }
+    extern char rootPageStart[];
+    extern char rootPageEnd[];
+    char *rootPage;
+    check(rootPage = malloc(rootPageEnd - rootPageStart + 1));
+    memcpy(rootPage, rootPageStart, rootPageEnd - rootPageStart);
+    rootPage[rootPageEnd - rootPageStart] = '\000';
+    char *html            = stringPrintf(NULL, rootPage,
+                                         enableSSL ? "true" : "false");
+    httpSendReply(http, 200, "OK", html);
+    free(rootPage);
   } else if (pathInfoLength == 8 && !memcmp(pathInfo, "beep.wav", 8)) {
     // Serve the audio sample for the console bell.
     extern char beepStart[];
index 6013cef2ff25b71c6ed2f215e65586e67c927185..1884e8bf80a0a31878f8ab393fca69d210599f97 100644 (file)
@@ -1693,7 +1693,7 @@ VT100.prototype.toggleBell = function() {
 };
 
 VT100.prototype.about = function() {
-  alert("VT100 Terminal Emulator " + "2.9 (revision 149)" +
+  alert("VT100 Terminal Emulator " + "2.9 (revision 152)" +
         "\nCopyright 2008-2009 by Markus Gutschke\n" +
         "For more information check http://shellinabox.com");
 };
This page took 0.072336 seconds and 5 git commands to generate.