diff --git a/cfg.py b/cfg.py index 013a5bdff..e45f56807 100644 --- a/cfg.py +++ b/cfg.py @@ -35,7 +35,6 @@ port = int(get_item(parser, 'Network', 'port')) html_root = None main_menu = Menu() -base_href = "" if store_file.endswith(".sqlite3"): store_file = os.path.splitext(store_file)[0] diff --git a/menu.py b/menu.py index 90b0af896..93860dcdb 100644 --- a/menu.py +++ b/menu.py @@ -39,10 +39,10 @@ class Menu(): """This method creates a menu item with the parameters, adds that menu item to this menu, and returns the item. - If BASEHREF is true and url start with a slash, prepend the cfg.base_href to it""" + If BASEHREF is true and url start with a slash, prepend the cfg.server_dir to it""" if basehref and url.startswith("/"): - url = cfg.base_href + url + url = cfg.server_dir + url item = Menu(label=label, icon=icon, url=url, order=order) self.items.append(item) diff --git a/modules/installed/apps/apps.py b/modules/installed/apps/apps.py index 2706110ce..efb99ea1a 100644 --- a/modules/installed/apps/apps.py +++ b/modules/installed/apps/apps.py @@ -3,7 +3,6 @@ from gettext import gettext as _ from modules.auth import require from plugin_mount import PagePlugin from forms import Form -from privilegedactions import privilegedaction_run import cfg class Apps(PagePlugin): @@ -12,7 +11,6 @@ class Apps(PagePlugin): self.register_page("apps") self.menu = cfg.main_menu.add_item("Apps", "icon-download-alt", "/apps", 80) self.menu.add_item("Photo Gallery", "icon-picture", "/apps/photos", 35) - self.menu.add_item("Owncloud", "icon-picture", "/apps/owncloud", 35) @cherrypy.expose def index(self): @@ -38,46 +36,3 @@ photos local, backed up, easily accessed and free from the whims of some other websites business model.
""") - @cherrypy.expose - @require() - def owncloud(self, submitted=False, **kwargs): - checkedinfo = { - 'enable' : False, - } - - if submitted: - opts = [] - for k in kwargs.keys(): - if 'on' == kwargs[k]: - shortk = k.split("owncloud_").pop() - checkedinfo[shortk] = True - - for key in checkedinfo.keys(): - if checkedinfo[key]: - opts.append(key) - else: - opts.append('no'+key) - privilegedaction_run("owncloud-setup", opts) - - output, error = privilegedaction_run("owncloud-setup", ['status']) - if error: - raise Exception("something is wrong: " + error) - for option in output.split(): - checkedinfo[option] = True - - main=""" -""" - form = Form(title="Configuration", - action=cfg.server_dir + "/apps/owncloud", - name="configure_owncloud", - message='') - form.checkbox(_("Enable Owncloud"), name="owncloud_enable", id="owncloud_enable", checked=checkedinfo['enable']) - form.hidden(name="submitted", value="True") - form.html(_("When enabled, the owncloud installation will be available from /owncloud/ on the web server.
")) - form.submit(_("Update setup")) - main += form.render() - sidebar_right=""" -Owncloudgives you universal access to your files through a web interface or WebDAV. It also provides a platform to easily view & sync your contacts, calendars and bookmarks across all your devices and enables basic editing right on the web. Installation has minimal server requirements, doesn't need special permissions and is quick. ownCloud is extendable via a simple but powerful API for applications and plugins. -
-""" - return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right) diff --git a/modules/installed/apps/owncloud.py b/modules/installed/apps/owncloud.py new file mode 100644 index 000000000..83a79539c --- /dev/null +++ b/modules/installed/apps/owncloud.py @@ -0,0 +1,73 @@ +import cherrypy +from gettext import gettext as _ +from modules.auth import require +from plugin_mount import PagePlugin, FormPlugin +from forms import Form +from privilegedactions import privilegedaction_run +import cfg +from util import Message + +class Owncloud(PagePlugin): + order = 90 + + def __init__(self, *args, **kwargs): + PagePlugin.__init__(self, *args, **kwargs) + self.register_page("apps.owncloud") + self.register_page("apps.owncloud.configure") + cfg.html_root.apps.menu.add_item("Owncloud", "icon-picture", "/apps/owncloud", 35) + + @cherrypy.expose + @require() + def index(self, **kwargs): + main=""" +ownCloud gives you universal access to your files through a web interface or WebDAV. It also provides a platform to easily view & sync your contacts, calendars and bookmarks across all your devices and enables basic editing right on the web. Installation has minimal server requirements, doesn't need special permissions and is quick. ownCloud is extendable via a simple but powerful API for applications and plugins. +
+""" + sidebar_right = 'Configure Owncloud' + return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right) + +class configure(FormPlugin, PagePlugin): + url = ["/apps/owncloud/configure"] + + sidebar_left = '' + sidebar_right = _("Configure Owncloud") + + def main(self, owncloud_enable=False, message=None, *args, **kwargs): + output, error = privilegedaction_run("owncloud-setup", 'status') + if error: + raise Exception("something is wrong: " + error) + if "enable" in output.split(): + owncloud_enable = True + + form = Form(title="Configuration", + action=cfg.server_dir + "/apps/owncloud/configure/index", + name="configure_owncloud", + message=message) + form.checkbox(_("Enable Owncloud"), name="owncloud_enable", id="owncloud_enable", checked=owncloud_enable) + # hidden field is needed because checkbox doesn't post if not checked + form.hidden(name="submitted", value="True") + form.html(_("When enabled, the owncloud installation will be available from /owncloud/ on the web server.
")) + form.submit(_("Update setup")) + return form.render() + + def process_form(self, **kwargs): + checkedinfo = { + 'enable' : False, + } + + opts = [] + for k in kwargs.keys(): + if 'on' == kwargs[k]: + shortk = k.split("owncloud_").pop() + checkedinfo[shortk] = True + + for key in checkedinfo.keys(): + if checkedinfo[key]: + opts.append(key) + else: + opts.append('no'+key) + privilegedaction_run("owncloud-setup", " ".join(opts)) + + main = self.main(checkedinfo['enable']) + return self.fill_template(title="Owncloud Configuration", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right) + diff --git a/modules/installed/lib/auth_page.py b/modules/installed/lib/auth_page.py index 3f3574c6a..49d7a8de4 100644 --- a/modules/installed/lib/auth_page.py +++ b/modules/installed/lib/auth_page.py @@ -16,7 +16,7 @@ class AuthController(PagePlugin): def on_logout(self, username): """Called on logout""" - def get_loginform(self, username, msg='', from_page="/"): + def get_loginform(self, username, msg='', from_page=cfg.server_dir+"/"): form = Form(title="Login", action=cfg.server_dir + "/auth/login", message=msg) form.text_input(name="from_page", value=from_page, type="hidden") form.text_input("Username", name="username", value=username) @@ -26,7 +26,7 @@ class AuthController(PagePlugin): return self.fill_template(main=form.render(), sidebar_right=" ") @cherrypy.expose - def login(self, username=None, passphrase=None, from_page="/", **kwargs): + def login(self, username=None, passphrase=None, from_page=cfg.server_dir+"/", **kwargs): if username is None or passphrase is None: return self.get_loginform("", from_page=from_page) @@ -39,7 +39,7 @@ class AuthController(PagePlugin): raise cherrypy.HTTPRedirect(from_page or (cfg.server_dir + "/")) @cherrypy.expose - def logout(self, from_page="/"): + def logout(self, from_page=cfg.server_dir+"/"): sess = cherrypy.session username = sess.get(cfg.session_key, None) sess[cfg.session_key] = None diff --git a/modules/installed/services/xmpp.py b/modules/installed/services/xmpp.py index 8881a2bd0..2ed240c21 100644 --- a/modules/installed/services/xmpp.py +++ b/modules/installed/services/xmpp.py @@ -11,52 +11,63 @@ class xmpp(PagePlugin): def __init__(self, *args, **kwargs): PagePlugin.__init__(self, *args, **kwargs) self.register_page("services.xmpp") + self.register_page("services.xmpp.configure") self.register_page("services.xmpp.register") cfg.html_root.services.menu.add_item("XMPP", "icon-comment", "/services/xmpp", 40) @cherrypy.expose @require() - def index(self, submitted=False, **kwargs): - checkedinfo = { - 'inband_enable' : False, - } + def index(self, **kwargs): + main = "XMPP Server Accounts and Configuration
" + sidebar_right = 'Configure XMPP ServerWhen enabled, anyone who can reach this server will be allowed to register an account through an XMPP client.
")) + form.submit(_("Update setup")) + return form.render() + + def process_form(self, **kwargs): + checkedinfo = { + 'inband_enable' : False, + } + + opts = [] + for k in kwargs.keys(): + if 'on' == kwargs[k]: + shortk = k.split("xmpp_").pop() + checkedinfo[shortk] = True for key in checkedinfo.keys(): if checkedinfo[key]: opts.append(key) else: opts.append('no'+key) - privilegedaction_run("xmpp-setup", opts) + privilegedaction_run("xmpp-setup", " ".join(opts)) - output, error = privilegedaction_run("xmpp-setup", ['status']) - if error: - raise Exception("something is wrong: " + error) - for option in output.split(): - checkedinfo[option] = True - - main = "XMPP Server Configuration
" - form = Form(title="Configuration", - action=cfg.server_dir + "/services/xmpp", - name="configure_xmpp", - message='') - form.checkbox(_("Allow In-Band Registration"), name="xmpp_inband_enable", - id="xmpp_inband_enable", checked=checkedinfo['inband_enable']) - form.hidden(name="submitted", value="True") - form.html(_("When enabled, anyone who can reach this server will be allowed to register an account through an XMPP client.
")) - form.submit(_("Update setup")) - main += form.render() - - sidebar_right = """ -Register XMPP Account -""" - return self.fill_template(title="XMPP Server Configuration", main=main, sidebar_right=sidebar_right) + main = self.main(checkedinfo['inband_enable']) + return self.fill_template(title="XMPP Server Configuration", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right) class register(FormPlugin, PagePlugin): url = ["/services/xmpp/register"] @@ -88,7 +99,7 @@ class register(FormPlugin, PagePlugin): if "successfully registered" in output: msg.add = _("Registered account for %s." % username) else: - msg.add = _("Failed to register account for %s: %o" % (username, output)) + msg.add = _("Failed to register account for %s: %s" % (username, output)) cfg.log(msg.text) main = self.main(username, msg=msg.text) diff --git a/modules/owncloud.py b/modules/owncloud.py new file mode 120000 index 000000000..4ae17c8be --- /dev/null +++ b/modules/owncloud.py @@ -0,0 +1 @@ +installed/apps/owncloud.py \ No newline at end of file diff --git a/plinth.py b/plinth.py index ee05cc881..a9bab7b4c 100755 --- a/plinth.py +++ b/plinth.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, sys, argparse +import os, stat, sys, argparse from gettext import gettext as _ import cfg if not os.path.join(cfg.file_root, "vendor") in sys.path: @@ -57,6 +57,9 @@ class Root(plugin_mount.PagePlugin): ## 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: + # if we created a new user db, make sure it can't be read by everyone + userdb_fname = '{}.sqlite3'.format(cfg.user_db) + os.chmod(userdb_fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) raise cherrypy.InternalRedirect('firstboot') elif db['state'] < 5: cfg.log("First Boot state = %d" % db['state']) @@ -135,6 +138,7 @@ def setup(): cfg.log = Logger() load_modules() cfg.html_root = Root() + cfg.users = plugin_mount.UserStoreModule.get_plugins()[0] cfg.page_plugins = plugin_mount.PagePlugin.get_plugins() cfg.log("Loaded %d page plugins" % len(cfg.page_plugins)) diff --git a/templates/base.tmpl b/templates/base.tmpl index 8a162888f..5ec88d4c4 100644 --- a/templates/base.tmpl +++ b/templates/base.tmpl @@ -184,7 +184,7 @@ - +