diff --git a/plinth.py b/plinth.py index 2dda4287b..00a626ccb 100755 --- a/plinth.py +++ b/plinth.py @@ -83,24 +83,41 @@ def load_modules(): def parse_arguments(): parser = argparse.ArgumentParser(description='Plinth web interface for the FreedomBox.') - parser.add_argument('--pidfile', default="", + parser.add_argument('--pidfile', help='specify a file in which the server may write its pid') - parser.add_argument('--directory', default="/", - help='specify a subdirectory to host the server.') + # FIXME make this work with basehref for static files. + parser.add_argument('--server_dir', + help='specify where to host the server.') args=parser.parse_args() - if args.pidfile: - cfg.pidfile = args.pidfile - else: + set_config(args, "pidfile", "plinth.pid") + set_config(args, "server_dir", "/") + + return cfg + +def set_config(args, element, default): + """Sets *cfg* elements based on *args* values, or uses a reasonable default. + + - If values are passed in from *args*, use those. + - If values are read from the config file, use those. + - If no values have been given, use default. + + """ + try: + # cfg.(element) = args.(element) + setattr(cfg, element, getattr(args, element)) + except AttributeError: + # if it fails, we didn't receive that argument. try: - if not cfg.pidfile: - cfg.pidfile = "plinth.pid" + # if not cfg.(element): cfg.(element) = default + if not getattr(cfg, element): + setattr(cfg, element, default) except AttributeError: - cfg.pidfile = "plinth.pid" - return args + # it wasn't in the config file, but set the default anyway. + setattr(cfg, element, default) def setup(): - args = parse_arguments() + cfg = parse_arguments() try: if cfg.pidfile: @@ -146,12 +163,11 @@ def setup(): '/favicon.ico':{'tools.staticfile.on': True, 'tools.staticfile.filename': "%s/static/theme/favicon.ico" % cfg.file_root}} - cherrypy.tree.mount(cfg.html_root, args.directory, config=config) + cherrypy.tree.mount(cfg.html_root, cfg.server_dir, config=config) cherrypy.engine.signal_handler.subscribe() def main(): setup() - print "%s %d" % (cfg.host, cfg.port) cherrypy.engine.start() cherrypy.engine.block() diff --git a/plinth.sample.config b/plinth.sample.config index 1134b2e81..93cd35595 100644 --- a/plinth.sample.config +++ b/plinth.sample.config @@ -12,6 +12,7 @@ status_log_file = %(data_dir)s/status.log access_log_file = %(data_dir)s/access.log users_dir = %(data_dir)s/users pidfile = %(data_dir)s/pidfile.pid +server_dir = plinth/ [Network] host = 127.0.0.1 diff --git a/share/apache2/plinth.conf b/share/apache2/plinth.conf index f3054aaaf..2cfa9199b 100644 --- a/share/apache2/plinth.conf +++ b/share/apache2/plinth.conf @@ -1,53 +1,53 @@ - ## Use this rule to hang plinth off of plinth.(servername) - ## The DocumentRoot is set by fabric + ## Shared options. DocumentRoot /dev/null - ServerName plinth - ServerAlias plinth.* - ## Force SSL RewriteEngine on ReWriteCond %{SERVER_PORT} !^443$ RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L] + ## Use this rule to hang plinth off of plinth.(servername) + # ServerName plinth + # ServerAlias plinth.* + + ## Shared options. + ProxyPreserveHost on + DocumentRoot /usr/share/plinth/static + ProxyPass /static ! ## Enable SSL SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key ## Use this rule to hang plinth off of plinth.(servername) - ## The DocumentRoot is set by fabric - DocumentRoot /home/fbx/plinth/static - ServerName plinth - ServerAlias plinth.* - ProxyPreserveHost on - ProxyPass /static ! - ProxyPass / http://localhost:8000/ - ProxyPassReverse / http://localhost:8000/ - - Order Deny,Allow - Deny from All - Allow from 10.0.0.0/8 - Allow from 172.16.0.0/12 - Allow from 192.168.0.0/16 - - - ## Use this rule to hang plinth off a subdir. - ## Make sure to provide plinth with a default directory: /plinth - # - # ProxyPass http://localhost:8000/plinth - # ProxyPassReverse http://localhost:8000/plinth - # + # ServerName plinth + # ServerAlias plinth.* + # ProxyPass / http://localhost:8000/ + # ProxyPassReverse / http://localhost:8000/ + # # Order Deny,Allow # Deny from All # Allow from 10.0.0.0/8 # Allow from 172.16.0.0/12 # Allow from 192.168.0.0/16 - # + # + + ## Use this rule to hang plinth off a subdir. + ## Make sure to provide plinth with a default directory: /plinth + + ProxyPass http://localhost:8000/plinth + ProxyPassReverse http://localhost:8000/plinth + + Order Deny,Allow + Deny from All + Allow from 10.0.0.0/8 + Allow from 172.16.0.0/12 + Allow from 192.168.0.0/16 + diff --git a/share/init.d/plinth b/share/init.d/plinth index ff694c482..114fa3240 100755 --- a/share/init.d/plinth +++ b/share/init.d/plinth @@ -17,6 +17,7 @@ NAME=plinth DAEMON=/usr/bin/plinth PID_FILE=/var/run/plinth.pid +SERVER_DIR=/plinth PLINTH_USER=plinth PLINTH_GROUP=plinth @@ -28,7 +29,8 @@ test -x $DAEMON || exit 0 case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" - start_daemon -p $PID_FILE $DAEMON --pidfile=$PID_FILE + start_daemon -p $PID_FILE $DAEMON --pidfile=$PID_FILE \ + --server_dir=$SERVER_DIR log_end_msg $? ;; stop)