Merge pull request #54 from jvalleroy/bugfixes

Bugfixes
This commit is contained in:
Nick Daly 2013-11-18 20:18:38 -08:00
commit 83b4425a5a
9 changed files with 130 additions and 87 deletions

1
cfg.py
View File

@ -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]

View File

@ -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)

View File

@ -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.</p>
""")
@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(_("<p>When enabled, the owncloud installation will be available from /owncloud/ on the web server.</p>"))
form.submit(_("Update setup"))
main += form.render()
sidebar_right="""
<strong>Owncloud</strong><p>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.
</p>
"""
return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right)

View File

@ -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="""
<p>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.
</p>
"""
sidebar_right = '<strong><a href="'+cfg.server_dir+'/apps/owncloud/configure">Configure Owncloud</a></strong>'
return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right)
class configure(FormPlugin, PagePlugin):
url = ["/apps/owncloud/configure"]
sidebar_left = ''
sidebar_right = _("<strong>Configure Owncloud</strong>")
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(_("<p>When enabled, the owncloud installation will be available from /owncloud/ on the web server.</p>"))
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)

View File

@ -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

View File

@ -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 = "<p>XMPP Server Accounts and Configuration</p>"
sidebar_right = '<strong><a href="'+cfg.server_dir+'/services/xmpp/configure">Configure XMPP Server</a></strong><br />'
sidebar_right = sidebar_right + '<strong><a href="'+cfg.server_dir+'/services/xmpp/register">Register XMPP Account</a></strong>'
return self.fill_template(title="XMPP Server", main=main, sidebar_right=sidebar_right)
if submitted:
opts = []
for k in kwargs.keys():
if 'on' == kwargs[k]:
shortk = k.split("xmpp_").pop()
checkedinfo[shortk] = True
class configure(FormPlugin, PagePlugin):
url = ["/services/xmpp/configure"]
sidebar_left = ''
sidebar_right = _("<strong>Configure XMPP Server</strong>")
def main(self, xmpp_inband_enable=False, message=None, *args, **kwargs):
output, error = privilegedaction_run("xmpp-setup", 'status')
if error:
raise Exception("something is wrong: " + error)
if "inband_enable" in output.split():
xmpp_inband_enable = True
form = Form(title="Configure XMPP Server",
action=cfg.server_dir + "/services/xmpp/configure/index",
name="configure_xmpp_form",
message=message)
form.checkbox(_("Allow In-Band Registration"), name="xmpp_inband_enable",
id="xmpp_inband_enable", checked=xmpp_inband_enable)
# hidden field is needed because checkbox doesn't post if not checked
form.hidden(name="submitted", value="True")
form.html(_("<p>When enabled, anyone who can reach this server will be allowed to register an account through an XMPP client.</p>"))
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 = "<p>XMPP Server Configuration</p>"
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(_("<p>When enabled, anyone who can reach this server will be allowed to register an account through an XMPP client.</p>"))
form.submit(_("Update setup"))
main += form.render()
sidebar_right = """
<strong><a href="/services/xmpp/register">Register XMPP Account</a></strong>
"""
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)

1
modules/owncloud.py Symbolic link
View File

@ -0,0 +1 @@
installed/apps/owncloud.py

View File

@ -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))

View File

@ -184,7 +184,7 @@
<script type="text/javascript" src="$basehref/static/theme/js/libs/jquery.min.js"></script>
<!-- Bootstrap JS, most files commented out until we know what we need -->
<!--<script type="text/javascript" src="$basehref/static/theme/js/libs/bootstrap/bootstrap.js"></script>-->
<script type="text/javascript" src="$basehref/static/theme/js/libs/bootstrap/bootstrap-min.js"></script>
<script type="text/javascript" src="$basehref/static/theme/js/libs/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="$basehref/static/theme/js/libs/bootstrap/button.js"></script>
<script type="text/javascript" src="$basehref/static/theme/js/libs/bootstrap/dropdown.js"></script>
<script type="text/javascript" src="$basehref/static/theme/js/libs/bootstrap/collapse.js"></script>