Making it easier to host the terminal on non-root URLs by always redirecting to a URL that includes a trailing slash.

git-svn-id: https://shellinabox.googlecode.com/svn/trunk@140 0da03de8-d603-11dd-86c2-0f8696b7b6f9
This commit is contained in:
zodiac 2009-07-06 16:27:11 +00:00
parent 8ff79d1ce7
commit bb4dbaa5f5
12 changed files with 51 additions and 9 deletions

View file

@ -1,3 +1,8 @@
2009-07-06 Markus Gutschke <markus@shellinabox.com>
* Making it easier to host the terminal on non-root URLs by always
redirecting to a URL that includes a trailing slash.
2009-07-05 Markus Gutschke <markus@shellinabox.com> 2009-07-05 Markus Gutschke <markus@shellinabox.com>
* Released version 2.9 * Released version 2.9

View file

@ -132,7 +132,7 @@
#define STDC_HEADERS 1 #define STDC_HEADERS 1
/* Most recent revision number in the version control system */ /* Most recent revision number in the version control system */
#define VCS_REVISION "139" #define VCS_REVISION "140"
/* Version number of package */ /* Version number of package */
#define VERSION "2.9" #define VERSION "2.9"

2
configure vendored
View file

@ -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 ac_compiler_gnu=$ac_cv_c_compiler_gnu
VCS_REVISION=139 VCS_REVISION=140
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF

View file

@ -2,7 +2,7 @@ AC_PREREQ(2.57)
dnl This is the one location where the authoritative version number is stored dnl This is the one location where the authoritative version number is stored
AC_INIT(shellinabox, 2.9, markus@shellinabox.com) AC_INIT(shellinabox, 2.9, markus@shellinabox.com)
VCS_REVISION=139 VCS_REVISION=140
AC_SUBST(VCS_REVISION) AC_SUBST(VCS_REVISION)
AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}", AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}",
[Most recent revision number in the version control system]) [Most recent revision number in the version control system])

View file

@ -1693,7 +1693,7 @@ VT100.prototype.toggleBell = function() {
}; };
VT100.prototype.about = function() { VT100.prototype.about = function() {
alert("VT100 Terminal Emulator " + "2.9 (revision 139)" + alert("VT100 Terminal Emulator " + "2.9 (revision 140)" +
"\nCopyright 2008-2009 by Markus Gutschke\n" + "\nCopyright 2008-2009 by Markus Gutschke\n" +
"For more information check http://shellinabox.com"); "For more information check http://shellinabox.com");
}; };

View file

@ -128,6 +128,7 @@ const char *urlGetPath(URL *url);
const char *urlGetPathInfo(URL *url); const char *urlGetPathInfo(URL *url);
const char *urlGetQuery(URL *url); const char *urlGetQuery(URL *url);
const char *urlGetAnchor(URL *url); const char *urlGetAnchor(URL *url);
const char *urlGetURL(URL *url);
const HashMap *urlGetArgs(URL *url); const HashMap *urlGetArgs(URL *url);
HashMap *newHashMap(void (*destructor)(void *arg, char *key, char *value), HashMap *newHashMap(void (*destructor)(void *arg, char *key, char *value),
void *arg); void *arg);

View file

@ -42,6 +42,7 @@ urlGetPath
urlGetPathInfo urlGetPathInfo
urlGetQuery urlGetQuery
urlGetAnchor urlGetAnchor
urlGetURL
urlGetArgs urlGetArgs
newHashMap newHashMap
deleteHashMap deleteHashMap

View file

@ -327,6 +327,7 @@ void initURL(struct URL *url, const struct HttpConnection *http,
url->pathinfo = strdup(httpGetPathInfo(http)); url->pathinfo = strdup(httpGetPathInfo(http));
url->query = strdup(httpGetQuery(http)); url->query = strdup(httpGetQuery(http));
url->anchor = NULL; url->anchor = NULL;
url->url = NULL;
initHashMap(&url->args, urlDestroyHashMapEntry, NULL); initHashMap(&url->args, urlDestroyHashMapEntry, NULL);
if (!strcmp(http->method, "GET")) { if (!strcmp(http->method, "GET")) {
urlParseQueryString(url, url->query, strlen(url->query)); urlParseQueryString(url, url->query, strlen(url->query));
@ -345,6 +346,7 @@ void destroyURL(struct URL *url) {
free(url->pathinfo); free(url->pathinfo);
free(url->query); free(url->query);
free(url->anchor); free(url->anchor);
free(url->url);
destroyHashMap(&url->args); destroyHashMap(&url->args);
} }
} }
@ -390,6 +392,23 @@ const char *urlGetAnchor(struct URL *url) {
return url->anchor; return url->anchor;
} }
const char *urlGetURL(struct URL *url) {
if (!url->url) {
const char *host = urlGetHost(url);
int s_size = 8 + strlen(host) + 25 + strlen(url->path);
check(*(char **)&url->url = malloc(s_size + 1));
*url->url = '\000';
strncat(url->url, url->protocol, s_size);
strncat(url->url, "://", s_size);
strncat(url->url, host, s_size);
if (url->port != (strcmp(url->protocol, "http") ? 443 : 80)) {
snprintf(strrchr(url->url, '\000'), 25, ":%d", url->port);
}
strncat(url->url, url->path, s_size);
}
return url->url;
}
const struct HashMap *urlGetArgs(struct URL *url) { const struct HashMap *urlGetArgs(struct URL *url) {
return &url->args; return &url->args;
} }

View file

@ -61,6 +61,7 @@ struct URL {
char *pathinfo; char *pathinfo;
char *query; char *query;
char *anchor; char *anchor;
char *url;
struct HashMap args; struct HashMap args;
}; };
@ -79,6 +80,7 @@ const char *urlGetPath(struct URL *url);
const char *urlGetPathInfo(struct URL *url); const char *urlGetPathInfo(struct URL *url);
const char *urlGetQuery(struct URL *url); const char *urlGetQuery(struct URL *url);
const char *urlGetAnchor(struct URL *url); const char *urlGetAnchor(struct URL *url);
const char *urlGetURL(struct URL *url);
const struct HashMap *urlGetArgs(struct URL *url); const struct HashMap *urlGetArgs(struct URL *url);
#endif /* URL_H__ */ #endif /* URL_H__ */

View file

@ -355,7 +355,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) {
}; };
ShellInABox.prototype.about = function() { ShellInABox.prototype.about = function() {
alert("Shell In A Box version " + "2.9 (revision 139)" + alert("Shell In A Box version " + "2.9 (revision 140)" +
"\nCopyright 2008-2009 by Markus Gutschke\n" + "\nCopyright 2008-2009 by Markus Gutschke\n" +
"For more information check http://shellinabox.com" + "For more information check http://shellinabox.com" +
(typeof serverSupportsSSL != 'undefined' && serverSupportsSSL ? (typeof serverSupportsSSL != 'undefined' && serverSupportsSSL ?

View file

@ -468,6 +468,7 @@ static int shellInABoxHttpHandler(HttpConnection *http, void *arg,
// Normalize the path info // Normalize the path info
const char *pathInfo = urlGetPathInfo(url); const char *pathInfo = urlGetPathInfo(url);
int trailingSlash = *pathInfo == '/';
while (*pathInfo == '/') { while (*pathInfo == '/') {
pathInfo++; pathInfo++;
} }
@ -478,10 +479,23 @@ static int shellInABoxHttpHandler(HttpConnection *http, void *arg,
} }
int pathInfoLength = endPathInfo - pathInfo; 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 // The root page either serves the AJAX application or redirects to the
// secure HTTPS URL. // secure HTTPS URL.
if (!pathInfoLength ||
(pathInfoLength == 5 && !memcmp(pathInfo, "plain", 5))) {
if (contentType && if (contentType &&
!strncasecmp(contentType, "application/x-www-form-urlencoded", 33)) { !strncasecmp(contentType, "application/x-www-form-urlencoded", 33)) {
// XMLHttpRequest carrying data between the AJAX application and the // XMLHttpRequest carrying data between the AJAX application and the

View file

@ -1693,7 +1693,7 @@ VT100.prototype.toggleBell = function() {
}; };
VT100.prototype.about = function() { VT100.prototype.about = function() {
alert("VT100 Terminal Emulator " + "2.9 (revision 139)" + alert("VT100 Terminal Emulator " + "2.9 (revision 140)" +
"\nCopyright 2008-2009 by Markus Gutschke\n" + "\nCopyright 2008-2009 by Markus Gutschke\n" +
"For more information check http://shellinabox.com"); "For more information check http://shellinabox.com");
}; };