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. git-svn-id: https://shellinabox.googlecode.com/svn/trunk@152 0da03de8-d603-11dd-86c2-0f8696b7b6f9
This commit is contained in:
parent
09386df071
commit
052a47aa08
10 changed files with 55 additions and 41 deletions
|
@ -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
|
||||
|
|
2
config.h
2
config.h
|
@ -135,7 +135,7 @@
|
|||
#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"
|
||||
|
|
2
configure
vendored
2
configure
vendored
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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");
|
||||
};
|
||||
|
|
|
@ -50,6 +50,32 @@
|
|||
<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
|
||||
|
|
|
@ -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 ?
|
||||
|
|
|
@ -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:/);
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -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");
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue