Plinth now hosted on (server)/plinth.

Plinth has been moved from plinth.(server).local to (server)/plinth.
*plinth.py* has been updated to take a new *--server_dir* argument,
which *share/init.d/plinth* now provides.  *plinth.sample.config* has
also been updated.

Actually, the whole package has been moved to a more Debian-friendly
configuration.  *share/apache2/plinth.conf* has been updated to
reflect the standard Debian directories.  It seems to make more sense
this way, as (other than FreedomMaker, which now uses this package
anyway) no other tools or derivatives use this system.  The
configuration can be patched out by other distributions easily enough.
This commit is contained in:
Nick Daly 2013-10-27 16:01:28 -05:00
parent 1da32164e5
commit 421f20005e
4 changed files with 61 additions and 42 deletions

View File

@ -83,24 +83,41 @@ def load_modules():
def parse_arguments(): def parse_arguments():
parser = argparse.ArgumentParser(description='Plinth web interface for the FreedomBox.') 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') help='specify a file in which the server may write its pid')
parser.add_argument('--directory', default="/", # FIXME make this work with basehref for static files.
help='specify a subdirectory to host the server.') parser.add_argument('--server_dir',
help='specify where to host the server.')
args=parser.parse_args() args=parser.parse_args()
if args.pidfile: set_config(args, "pidfile", "plinth.pid")
cfg.pidfile = args.pidfile set_config(args, "server_dir", "/")
else:
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: try:
if not cfg.pidfile: # if not cfg.(element): cfg.(element) = default
cfg.pidfile = "plinth.pid" if not getattr(cfg, element):
setattr(cfg, element, default)
except AttributeError: except AttributeError:
cfg.pidfile = "plinth.pid" # it wasn't in the config file, but set the default anyway.
return args setattr(cfg, element, default)
def setup(): def setup():
args = parse_arguments() cfg = parse_arguments()
try: try:
if cfg.pidfile: if cfg.pidfile:
@ -146,12 +163,11 @@ def setup():
'/favicon.ico':{'tools.staticfile.on': True, '/favicon.ico':{'tools.staticfile.on': True,
'tools.staticfile.filename': 'tools.staticfile.filename':
"%s/static/theme/favicon.ico" % cfg.file_root}} "%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() cherrypy.engine.signal_handler.subscribe()
def main(): def main():
setup() setup()
print "%s %d" % (cfg.host, cfg.port)
cherrypy.engine.start() cherrypy.engine.start()
cherrypy.engine.block() cherrypy.engine.block()

View File

@ -12,6 +12,7 @@ status_log_file = %(data_dir)s/status.log
access_log_file = %(data_dir)s/access.log access_log_file = %(data_dir)s/access.log
users_dir = %(data_dir)s/users users_dir = %(data_dir)s/users
pidfile = %(data_dir)s/pidfile.pid pidfile = %(data_dir)s/pidfile.pid
server_dir = plinth/
[Network] [Network]
host = 127.0.0.1 host = 127.0.0.1

View File

@ -1,53 +1,53 @@
<VirtualHost *:80> <VirtualHost *:80>
## Use this rule to hang plinth off of plinth.(servername) ## Shared options.
## The DocumentRoot is set by fabric
DocumentRoot /dev/null DocumentRoot /dev/null
ServerName plinth
ServerAlias plinth.*
## Force SSL ## Force SSL
RewriteEngine on RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$ ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L] RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
## Use this rule to hang plinth off of plinth.(servername)
# ServerName plinth
# ServerAlias plinth.*
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
## Shared options.
ProxyPreserveHost on
DocumentRoot /usr/share/plinth/static
ProxyPass /static !
## Enable SSL ## Enable SSL
SSLEngine on SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
## Use this rule to hang plinth off of plinth.(servername) ## Use this rule to hang plinth off of plinth.(servername)
## The DocumentRoot is set by fabric # ServerName plinth
DocumentRoot /home/fbx/plinth/static # ServerAlias plinth.*
ServerName plinth # ProxyPass / http://localhost:8000/
ServerAlias plinth.* # ProxyPassReverse / http://localhost:8000/
ProxyPreserveHost on # <Proxy *>
ProxyPass /static !
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
<Proxy *>
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
</Proxy>
## Use this rule to hang plinth off a subdir.
## Make sure to provide plinth with a default directory: /plinth
# <Location /plinth>
# ProxyPass http://localhost:8000/plinth
# ProxyPassReverse http://localhost:8000/plinth
#
# Order Deny,Allow # Order Deny,Allow
# Deny from All # Deny from All
# Allow from 10.0.0.0/8 # Allow from 10.0.0.0/8
# Allow from 172.16.0.0/12 # Allow from 172.16.0.0/12
# Allow from 192.168.0.0/16 # Allow from 192.168.0.0/16
# </Location> # </Proxy>
## Use this rule to hang plinth off a subdir.
## Make sure to provide plinth with a default directory: /plinth
<Location /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
</Location>
</VirtualHost> </VirtualHost>

View File

@ -17,6 +17,7 @@ NAME=plinth
DAEMON=/usr/bin/plinth DAEMON=/usr/bin/plinth
PID_FILE=/var/run/plinth.pid PID_FILE=/var/run/plinth.pid
SERVER_DIR=/plinth
PLINTH_USER=plinth PLINTH_USER=plinth
PLINTH_GROUP=plinth PLINTH_GROUP=plinth
@ -28,7 +29,8 @@ test -x $DAEMON || exit 0
case "$1" in case "$1" in
start) start)
log_daemon_msg "Starting $DESC" "$NAME" 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 $? log_end_msg $?
;; ;;
stop) stop)