Added new "--localhost-only" command line option.

git-svn-id: https://shellinabox.googlecode.com/svn/trunk@125 0da03de8-d603-11dd-86c2-0f8696b7b6f9
This commit is contained in:
zodiac@gmail.com 2009-06-21 19:55:20 +00:00
parent 6dbbe62310
commit 5ec8c4c19b
10 changed files with 31 additions and 19 deletions

View file

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

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
VCS_REVISION=124
VCS_REVISION=125
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
AC_INIT(shellinabox, 2.8, markus@shellinabox.com)
VCS_REVISION=124
VCS_REVISION=125
AC_SUBST(VCS_REVISION)
AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}",
[Most recent revision number in the version control system])

View file

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

View file

@ -66,8 +66,8 @@ typedef struct ServerConnection ServerConnection;
typedef struct Server Server;
typedef struct URL URL;
Server *newCGIServer(int portMin, int portMax, int timeout);
Server *newServer(int port);
Server *newCGIServer(int localhostOnly, int portMin, int portMax, int timeout);
Server *newServer(int localhostOnly, int port);
void deleteServer(Server *server);
int serverGetListeningPort(Server *server);
int serverGetFd(Server *server);

View file

@ -170,18 +170,20 @@ static int serverQuitHandler(struct HttpConnection *http, void *arg) {
return HTTP_DONE;
}
struct Server *newCGIServer(int portMin, int portMax, int timeout) {
struct Server *newCGIServer(int localhostOnly, int portMin, int portMax,
int timeout) {
struct Server *server;
check(server = malloc(sizeof(struct Server)));
initServer(server, portMin, portMax, timeout);
initServer(server, localhostOnly, portMin, portMax, timeout);
return server;
}
struct Server *newServer(int port) {
return newCGIServer(port, port, -1);
struct Server *newServer(int localhostOnly, int port) {
return newCGIServer(localhostOnly, port, port, -1);
}
void initServer(struct Server *server, int portMin, int portMax, int timeout) {
void initServer(struct Server *server, int localhostOnly, int portMin,
int portMax, int timeout) {
server->looping = 0;
server->exitAll = 0;
server->serverTimeout = timeout;
@ -196,7 +198,8 @@ void initServer(struct Server *server, int portMin, int portMax, int timeout) {
&true, sizeof(true)));
struct sockaddr_in serverAddr = { 0 };
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = INADDR_ANY;
serverAddr.sin_addr.s_addr = htonl(localhostOnly
? INADDR_LOOPBACK : INADDR_ANY);
// Linux unlike BSD does not have support for picking a local port range.
// So, we have to randomly pick a port from our allowed port range, and then

View file

@ -78,9 +78,11 @@ struct Server {
struct SSLSupport ssl;
};
struct Server *newCGIServer(int portMin, int portMax, int timeout);
struct Server *newServer(int port);
void initServer(struct Server *server, int portMin, int portMax, int timeout);
struct Server *newCGIServer(int localhostOnly, int portMin, int portMax,
int timeout);
struct Server *newServer(int localhostOnly, int port);
void initServer(struct Server *server, int localhostOnly, int portMin,
int portMax, int timeout);
void destroyServer(struct Server *server);
void deleteServer(struct Server *server);
int serverGetListeningPort(struct Server *server);

View file

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

View file

@ -79,6 +79,7 @@
static int port;
static int portMin;
static int portMax;
static int localhostOnly = 0;
static int noBeep = 0;
static int numericHosts = 0;
static int enableSSL = 1;
@ -595,6 +596,7 @@ static void usage(void) {
" -f, --static-file=URL:FILE serve static file from URL path\n"
" -g, --group=GID switch to this group (default: %s)\n"
" -h, --help print this message\n"
" --localhost-only only listen on 127.0.0.1\n"
" --no-beep suppress all audio output\n"
" -n, --numeric do not resolve hostnames\n"
" -p, --port=PORT select a port (default: %d)\n"
@ -664,6 +666,7 @@ static void parseArgs(int argc, char * const argv[]) {
{ "debug", 0, 0, 'd' },
{ "static-file", 1, 0, 'f' },
{ "group", 1, 0, 'g' },
{ "localhost-only", 0, 0, 0 },
{ "no-beep", 0, 0, 0 },
{ "numeric", 0, 0, 'n' },
{ "port", 1, 0, 'p' },
@ -781,6 +784,9 @@ static void parseArgs(int argc, char * const argv[]) {
fatal("Duplicate --group option.");
}
runAsGroup = parseGroup(optarg, NULL);
} else if (!idx--) {
// Localhost Only
localhostOnly = 1;
} else if (!idx--) {
// No Beep
noBeep = 1;
@ -962,7 +968,7 @@ int main(int argc, char * const argv[]) {
// Create a new web server
Server *server;
if (port) {
check(server = newServer(port));
check(server = newServer(localhostOnly, port));
dropPrivileges();
setUpSSL(server);
} else {
@ -982,7 +988,8 @@ int main(int argc, char * const argv[]) {
_exit(0);
}
check(!NOINTR(close(fds[0])));
check(server = newCGIServer(portMin, portMax, AJAX_TIMEOUT));
check(server = newCGIServer(localhostOnly, portMin, portMax,
AJAX_TIMEOUT));
cgiServer = server;
setUpSSL(server);

View file

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