diff options
Diffstat (limited to 'plinth.py')
-rwxr-xr-x | plinth.py | 70 |
1 files changed, 42 insertions, 28 deletions
@@ -1,7 +1,6 @@ #!/usr/bin/env python import os, sys, argparse -#import logging from gettext import gettext as _ import cfg if not os.path.join(cfg.file_root, "vendor") in sys.path: @@ -13,27 +12,32 @@ from cherrypy.process.plugins import Daemonizer Daemonizer(cherrypy.engine).subscribe() import plugin_mount -from util import * +import util as u + from logger import Logger #from modules.auth import AuthController, require, member_of, name_is +from vendor.withsqlite.withsqlite import sqlite_db +from vendor.exmachina.exmachina import ExMachinaClient import socket __version__ = "0.2.14" __author__ = "James Vasile" -__copyright__ = "Copyright 2011, James Vasile" +__copyright__ = "Copyright 2011-2013, James Vasile" __license__ = "GPLv3 or later" __maintainer__ = "James Vasile" __email__ = "james@jamesvasile.com" __status__ = "Development" def error_page(status, dynamic_msg, stock_msg): - return page_template(template="err", title=status, main="<p>%s</p>%s" % (dynamic_msg, stock_msg)) + return u.page_template(template="err", title=status, main="<p>%s</p>%s" % (dynamic_msg, stock_msg)) def error_page_404(status, message, traceback, version): - return error_page(status, message, """<p>If you believe this missing page should exist, please file a - bug with either the Plinth project or the people responsible for - the module you are trying to access.</p> + return error_page(status, message, """<p>If you believe this + missing page should exist, please file a bug with either the Plinth + project (<a href="https://github.com/jvasile/plinth/issues">it has + an issue tracker</a>) or the people responsible for the module you + are trying to access.</p> <p>Sorry for the mistake.</p> """) @@ -42,13 +46,20 @@ def error_page_500(status, message, traceback, version): cfg.log.error("500 Internal Server Error. Trackback is above.") more="""<p>This is an internal error and not something you caused or can fix. Please report the error on the <a - href="https://github.com/seandiggity/Plinth/issues">bug tracker</a> so + href="https://github.com/jvasile/Plinth/issues">bug tracker</a> so we can fix it.</p>""" return error_page(status, message, "<p>%s</p><pre>%s</pre>" % (more, "\n".join(traceback.split("\n")))) class Root(plugin_mount.PagePlugin): @cherrypy.expose def index(self): + ## TODO: firstboot hijacking root should probably be in the firstboot module with a hook in plinth.py + with sqlite_db(cfg.store_file, table="firstboot") as db: + if not 'state' in db: + raise cherrypy.InternalRedirect('/firstboot') + elif db['state'] < 5: + cfg.log("First Boot state = %d" % db['state']) + raise cherrypy.InternalRedirect('/firstboot/state%d' % db['state']) if cherrypy.session.get(cfg.session_key, None): raise cherrypy.InternalRedirect('/router') else: @@ -79,8 +90,12 @@ def parse_arguments(): if args.pidfile: cfg.pidfile = args.pidfile else: - if not cfg.pidfile: + try: + if not cfg.pidfile: cfg.pidfile = "plinth.pid" + except AttributeError: + cfg.pidfile = "plinth.pid" + if args.listen_exmachina_key: # this is where we optionally try to read in a shared secret key to # authenticate connections to exmachina @@ -129,25 +144,24 @@ def setup(): # Configure default server cherrypy.config.update( - { 'server.socket_host': cfg.host, - 'server.socket_port': cfg.port, - 'server.thread_pool':10, - 'tools.staticdir.root': cfg.file_root, - 'tools.sessions.on':True, - 'tools.auth.on':True, - 'tools.sessions.storage_type':"file", - 'tools.sessions.timeout':90, - 'tools.sessions.storage_path': - "%s/data/cherrypy_sessions" % cfg.file_root, - }) - - config = {'/': {'tools.staticdir.root': '%s/static' % cfg.file_root, - 'tools.proxy.on':True,}, - '/static': {'tools.staticdir.on': True, - 'tools.staticdir.dir':"."}, - '/favicon.ico':{'tools.staticfile.on':True, - 'tools.staticfile.filename': - "%s/static/theme/favicon.ico" % cfg.file_root}} + {'server.socket_host': cfg.host, + 'server.socket_port': cfg.port, + 'server.thread_pool':10, + 'tools.staticdir.root': cfg.file_root, + 'tools.sessions.on':True, + 'tools.auth.on':True, + 'tools.sessions.storage_type':"file", + 'tools.sessions.timeout':90, + 'tools.sessions.storage_path':"%s/cherrypy_sessions" % cfg.data_dir,}) + + config = { + '/': {'tools.staticdir.root': '%s/static' % cfg.file_root, + 'tools.proxy.on': True,}, + '/static': {'tools.staticdir.on': True, + 'tools.staticdir.dir': "."}, + '/favicon.ico':{'tools.staticfile.on': True, + 'tools.staticfile.filename': + "%s/static/theme/favicon.ico" % cfg.file_root}} cherrypy.tree.mount(cfg.html_root, '/', config=config) cherrypy.engine.signal_handler.subscribe() |