From 4b44741c689a78be4cc86ec307d6d72aeb34eac7 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa
Your photos might well be the most valuable digital property you have, so why trust it to companies that have no investment in the sentimental value of your family snaps? Keep those diff --git a/modules/installed/apps/owncloud.py b/modules/installed/apps/owncloud.py index 6fc1d6622..1dcca2241 100644 --- a/modules/installed/apps/owncloud.py +++ b/modules/installed/apps/owncloud.py @@ -6,7 +6,8 @@ from forms import Form import actions import cfg import service -from util import Message +import util + class Owncloud(PagePlugin, FormPlugin): order = 90 @@ -42,7 +43,8 @@ class Owncloud(PagePlugin, FormPlugin):
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.
""" - return self.fill_template(title="Owncloud", main=main, sidebar_right=sidebar_right) + return util.render_template(title="Owncloud", main=main, + sidebar_right=sidebar_right) def form(self, owncloud_enable, message=None): form = Form(title="Configuration", diff --git a/modules/installed/first_boot.py b/modules/installed/first_boot.py index 47315f9a7..3c80858dd 100644 --- a/modules/installed/first_boot.py +++ b/modules/installed/first_boot.py @@ -4,11 +4,11 @@ from gettext import gettext as _ from plugin_mount import PagePlugin, PluginMount, FormPlugin from modules.auth import require, add_user from forms import Form -import util as u from withsqlite.withsqlite import sqlite_db import cfg import config from model import User +import util """First Boot: Initial Plinth Configuration. @@ -118,7 +118,7 @@ class FirstBoot(PagePlugin): form.submit("Box it up!") main += form.render() - return self.fill_template( + return util.render_template( template="base", title=_("First Boot!"), main=main, @@ -155,7 +155,7 @@ href="../router">continue to see the rest of the web interface. # # TODO: switch to HTTPS # raise cherrypy.InternalRedirect('state1') - return self.fill_template( + return util.render_template( template="base", title=_("Installing the Certificate"), main=main, diff --git a/modules/installed/help/help.py b/modules/installed/help/help.py index e05123bf5..1f8407af5 100644 --- a/modules/installed/help/help.py +++ b/modules/installed/help/help.py @@ -3,6 +3,9 @@ import cherrypy from gettext import gettext as _ from plugin_mount import PagePlugin import cfg +import util + + class Help(PagePlugin): order = 20 # order of running init in PagePlugins def __init__(self, *args, **kwargs): @@ -43,11 +46,12 @@ class Help(PagePlugin): the question frequency is currently zero for all questions. """ % {'box':cfg.box_name} - return self.fill_template(title="Documentation and FAQ", main=main) + return util.render_template(title="Documentation and FAQ", main=main) @cherrypy.expose def about(self): - return self.fill_template(title=_("About the %s" % cfg.box_name), main=""" + return util.render_template(title=_("About the %s" % cfg.box_name), + main="""
We live in a world where our use of the network is mediated by those who often do not have our best @@ -82,7 +86,8 @@ class View(PagePlugin): def default(self, page=''): if page not in ['design', 'plinth', 'hacking', 'faq']: raise cherrypy.HTTPError(404, "The path '/help/view/%s' was not found." % page) - return self.fill_template(template="err", main="
Sorry, as much as I would like to show you that page, I don't seem to have a page named %s!
" % page) + with open(os.path.join("doc", "%s.part.html" % page), 'r') as IF: main = IF.read() - return self.fill_template(title=_("%s Documentation" % cfg.product_name), main=main) + return util.render_template(title=_("%s Documentation" % + cfg.product_name), main=main) diff --git a/modules/installed/lib/auth_page.py b/modules/installed/lib/auth_page.py index 49d7a8de4..f8778e1e2 100644 --- a/modules/installed/lib/auth_page.py +++ b/modules/installed/lib/auth_page.py @@ -1,9 +1,14 @@ +""" +Controller to provide login and logout actions +""" + import cherrypy import cfg from plugin_mount import PagePlugin from modules.forms import Form from auth import * -# Controller to provide login and logout actions +import util + class AuthController(PagePlugin): def __init__(self, *args, **kwargs): @@ -23,7 +28,7 @@ class AuthController(PagePlugin): form.text_input("Passphrase", name="passphrase", type="password") form.submit(label="Login") - return self.fill_template(main=form.render(), sidebar_right=" ") + return util.render_template(main=form.render(), sidebar_right=" ") @cherrypy.expose def login(self, username=None, passphrase=None, from_page=cfg.server_dir+"/", **kwargs): diff --git a/modules/installed/privacy/privacy.py b/modules/installed/privacy/privacy.py index 802c42f81..5b9127d36 100644 --- a/modules/installed/privacy/privacy.py +++ b/modules/installed/privacy/privacy.py @@ -3,6 +3,8 @@ from gettext import gettext as _ from plugin_mount import PagePlugin from modules.auth import require import cfg +import util + class Privacy(PagePlugin): order = 20 # order of running init in PagePlugins @@ -27,7 +29,8 @@ class Privacy(PagePlugin): placeholder and a promise: privacy is important enough that it is a founding consideration, not an afterthought. """ - return self.fill_template(title=_("Privacy Control Panel"), main=main, + return util.render_template(title=_("Privacy Control Panel"), + main=main, sidebar_right=_("""Statement of PrinciplesWhen we say your privacy is important, it's not just an empty pleasantry. We really mean it. Your privacy control panel should give you fine-grained diff --git a/modules/installed/privacy/tor.py b/modules/installed/privacy/tor.py index 78a60d068..8396a15e0 100644 --- a/modules/installed/privacy/tor.py +++ b/modules/installed/privacy/tor.py @@ -25,6 +25,8 @@ from plugin_mount import PagePlugin from modules.auth import require import actions import cfg +import util + class tor(PagePlugin): order = 30 # order of running init in PagePlugins @@ -58,4 +60,4 @@ class tor(PagePlugin): main += "
Eventually we will display a bunch of info, graphs and logs about the routing functions here.
+ return util.render_template(title="Router Information", main=""" +Eventually we will display a bunch of info, graphs and logs about +the routing functions here.
""") diff --git a/modules/installed/router/pagekite.py b/modules/installed/router/pagekite.py index 666d1a0fe..10d86dbb7 100644 --- a/modules/installed/router/pagekite.py +++ b/modules/installed/router/pagekite.py @@ -89,8 +89,8 @@ PageKite ''').format(server_dir=cfg.server_dir) - return self.fill_template(title=_("Public Visibility (PageKite)"), - main=main, sidebar_right=sidebar_right) + return util.render_template(title=_("Public Visibility (PageKite)"), + main=main, sidebar_right=sidebar_right) class configure(FormPlugin, PagePlugin): # pylint: disable-msg=C0103 diff --git a/modules/installed/router/router.py b/modules/installed/router/router.py index 105d3d69d..d17496ae3 100644 --- a/modules/installed/router/router.py +++ b/modules/installed/router/router.py @@ -1,11 +1,9 @@ -from urlparse import urlparse -import os, cherrypy -from gettext import gettext as _ -from plugin_mount import PagePlugin, PluginMount, FormPlugin +import cherrypy +from plugin_mount import PagePlugin, FormPlugin from modules.auth import require from forms import Form -from util import * import cfg +import util class router(PagePlugin): order = 9 # order of running init in PagePlugins @@ -28,18 +26,20 @@ class router(PagePlugin): @cherrypy.expose @require() def wireless(self): - return self.fill_template(title="Wireless", main="wireless setup: essid, etc.
") + return util.render_template(title="Wireless", + main="wireless setup: essid, etc.
") @cherrypy.expose @require() def firewall(self): - return self.fill_template(title="Firewall", main="Iptables twiddling.
") + return util.render_template(title="Firewall", + main="Iptables twiddling.
") @cherrypy.expose @require() def hotspot(self): - return self.fill_template(title="Hotspot and Mesh", main="connection sharing setup.
") - + return util.render_template(title="Hotspot and Mesh", + main="connection sharing setup.
") class setup(PagePlugin): @@ -70,18 +70,18 @@ can rival those of high-end routers costing hundreds of dollars. Configure" menu.""" % {'product':cfg.box_name} else: parts['main'] += "router name, domain name, router IP, dhcp
" - return self.fill_template(**parts) + return util.render_template(**parts) @cherrypy.expose @require() def ddns(self): - return self.fill_template(title="Dynamic DNS", main="Masquerade setup
") + return util.render_template(title="Dynamic DNS", main="Masquerade setup
") @cherrypy.expose @require() def mac_address(self): - return self.fill_template(title="MAC Address Cloning", - main="Your router can pretend to have a different MAC address on any interface.
") + return util.render_template(title="MAC Address Cloning", + main="Your router can pretend to have a different MAC address on any interface.
") class wan(FormPlugin, PagePlugin): @@ -127,7 +127,7 @@ class wan(FormPlugin, PagePlugin): if not cfg.users.expert(): return '' - store = filedict_con(cfg.store_file, 'router') + store = util.filedict_con(cfg.store_file, 'router') defaults = {'connect_type': 'DHCP'} for key, value in defaults.items(): if not key in kwargs: @@ -136,10 +136,10 @@ class wan(FormPlugin, PagePlugin): except KeyError: store[key] = kwargs[key] = value - form = Form(title="WAN Connection", - action=cfg.server_dir + "/router/setup/wan/index", - name="wan_connection_form", - message=message) + form = Form(title="WAN Connection", + action=cfg.server_dir + "/router/setup/wan/index", + name="wan_connection_form", + message=message) form.dropdown('Connection Type', vals=["DHCP", "Static IP"], id="connect_type") form.html('Your %s is also an OpenID machine. It can generate credentials that allow you to log in to many websites without the need to remember or enter a separate username and diff --git a/modules/installed/services/xmpp.py b/modules/installed/services/xmpp.py index 46063bfc1..6c189afe0 100644 --- a/modules/installed/services/xmpp.py +++ b/modules/installed/services/xmpp.py @@ -6,7 +6,8 @@ import cfg from forms import Form import actions import service -from util import Message +import util + class xmpp(PagePlugin): def __init__(self, *args, **kwargs): @@ -32,7 +33,7 @@ class xmpp(PagePlugin): main = "
XMPP Server Accounts and Configuration
" sidebar_right = 'Configure XMPP ServerThe %s can make your spare hard drives accessible to your local network, thus acting as a NAS server. We currently support sharing files via NFS and SMB. @@ -46,7 +49,8 @@ class PrinterSharing(PagePlugin):
TODO: Setup and install SAMBA
TODO: Setup and install CUPS
""" - return self.fill_template(title="Printer Sharing", main=main, sidebar_right=""" + return util.render_template(title="Printer Sharing", main=main, + sidebar_right=""" Share Your PrinterThe %s can share your printer via Samba and CUPS.
""" % cfg.box_name) diff --git a/modules/installed/system/config.py b/modules/installed/system/config.py index 6e1f62e2a..1ca1801aa 100644 --- a/modules/installed/system/config.py +++ b/modules/installed/system/config.py @@ -52,7 +52,7 @@ class Config(PagePlugin): parts['title'] = _("Configure this {box_name}") \ .format(box_name=cfg.box_name) - return self.fill_template(**parts) # pylint: disable-msg=W0142 + return util.render_template(**parts) # pylint: disable-msg=W0142 def valid_hostname(name): diff --git a/modules/installed/system/diagnostics.py b/modules/installed/system/diagnostics.py index b87afb68d..6de341079 100644 --- a/modules/installed/system/diagnostics.py +++ b/modules/installed/system/diagnostics.py @@ -25,6 +25,8 @@ from auth import require from plugin_mount import PagePlugin import actions import cfg +import util + class diagnostics(PagePlugin): order = 30 @@ -42,7 +44,7 @@ class diagnostics(PagePlugin): properly. It may take a minute to complete. """) main += '' - return self.fill_template(title=_("System Diagnostics"), main=main) + return util.render_template(title=_("System Diagnostics"), main=main) class test(PagePlugin): order = 31 @@ -66,4 +68,4 @@ class test(PagePlugin): for line in output.split('\n'): main += line + "" - return self.fill_template(title=_("Diagnostic Test"), main=main) + return util.render_template(title=_("Diagnostic Test"), main=main) diff --git a/modules/installed/system/firewall.py b/modules/installed/system/firewall.py index 069dfb658..aa09c86dd 100644 --- a/modules/installed/system/firewall.py +++ b/modules/installed/system/firewall.py @@ -27,6 +27,7 @@ import cfg from modules.auth import require from plugin_mount import PagePlugin import service as service_module +import util class Firewall(PagePlugin): @@ -65,7 +66,8 @@ pre-installed with {box_name}. On any Debian based system (such as {box_name}) you may install it using the command 'aptitude install firewalld'''').format(box_name=cfg.box_name) - return self.fill_template(title=_("Firewall"), main=main + status) + return util.render_template(title=_("Firewall"), + main=main + status) if not self.get_enabled_status(): status = _(''' @@ -75,7 +77,8 @@ enabled by default on {box_name}. On any Debian based system (such as or in case of system with systemd 'systemctl start firewalld' ''').format(box_name=cfg.box_name) - return self.fill_template(title=_("Firewall"), main=main + status) + return util.render_template(title=_("Firewall"), + main=main + status) internal_enabled_sevices = self.get_enabled_services(zone='internal') external_enabled_sevices = self.get_enabled_services(zone='external') @@ -129,8 +132,8 @@ or in case of system with systemd 'systemctl start firewalld' service it is automatically permitted in the firewall and you disable a service is automatically disabled in the firewall.''' - return self.fill_template(title=_("Firewall"), main=main + - services_info + footnote) + return util.render_template(title=_("Firewall"), main=main + + services_info + footnote) def get_installed_status(self): """Return whether firewall is installed""" diff --git a/modules/installed/system/packages.py b/modules/installed/system/packages.py index 276939358..ed2262d36 100644 --- a/modules/installed/system/packages.py +++ b/modules/installed/system/packages.py @@ -5,7 +5,7 @@ from plugin_mount import PagePlugin, FormPlugin from forms import Form import actions import cfg -from util import Message +import util class Packages(PagePlugin, FormPlugin): order = 20 @@ -52,12 +52,12 @@ class Packages(PagePlugin, FormPlugin):aptitude purge modules
aptitude install modules
The modules should depend on the appropriate Debian packages.
""") - main += self.form(self, Message(output), args, kwargs) + main += self.form(self, util.Message(output), args, kwargs) sidebar_right = _(""" HelpOn this page, you can add or remove %s plugins to your %s.
Plugins are just Debian packages, so Debian's usual package management features should make this job fairly easy.
""" % (cfg.product_name, cfg.box_name)) - return self.fill_template(title=_("Add/Remove Plugins"), main=main, sidebar_right=sidebar_right) + return util.render_template(title=_("Add/Remove Plugins"), main=main, sidebar_right=sidebar_right) def form(self, message=None, *args, **kwargs): output, error = actions.run("module-manager", ["list-available"]) diff --git a/modules/installed/system/system.py b/modules/installed/system/system.py index 906a5b3ca..758f5eff1 100644 --- a/modules/installed/system/system.py +++ b/modules/installed/system/system.py @@ -1,17 +1,8 @@ -import os import cherrypy -try: - import simplejson as json -except ImportError: - import json from gettext import gettext as _ -from filedict import FileDict -from auth import require -from plugin_mount import PagePlugin, FormPlugin +from plugin_mount import PagePlugin import cfg -from forms import Form -from model import User -from util import * +import util sys_dir = "modules/installed/sys" @@ -27,7 +18,7 @@ class Sys(PagePlugin): @cherrypy.expose def index(self): - return self.fill_template(title=_("System Configuration"), main=_(""" + return util.render_template(title=_("System Configuration"), main=_("""In this section, you can control the %(product)s's
underlying system, as opposed to its various applications and
services. These options affect the %(product)s at its most
diff --git a/modules/installed/system/users.py b/modules/installed/system/users.py
index b2a7d2578..4f89da459 100644
--- a/modules/installed/system/users.py
+++ b/modules/installed/system/users.py
@@ -1,11 +1,12 @@
-import os, cherrypy
+import cherrypy
from gettext import gettext as _
from auth import require, add_user
from plugin_mount import PagePlugin, FormPlugin
import cfg
from forms import Form
-from util import *
from model import User
+import util
+
class users(PagePlugin):
order = 20 # order of running init in PagePlugins
@@ -19,7 +20,9 @@ class users(PagePlugin):
@require()
def index(self):
sidebar_right = 'Add User
Edit Users'
- return self.fill_template(title="Manage Users and Groups", sidebar_right=sidebar_right)
+ return util.render_template(title="Manage Users and Groups",
+ sidebar_right=sidebar_right)
+
class add(FormPlugin, PagePlugin):
url = ["/sys/users/add"]
@@ -34,9 +37,9 @@ class add(FormPlugin, PagePlugin):
def main(self, username='', name='', email='', message=None, *args, **kwargs):
form = Form(title="Add User",
- action=cfg.server_dir + "/sys/users/add/index",
- name="add_user_form",
- message=message)
+ action=cfg.server_dir + "/sys/users/add/index",
+ name="add_user_form",
+ message=message)
form.text_input(_("Username"), name="username", value=username)
form.text_input(_("Full name"), name="name", value=name)
form.text_input(_("Email"), name="email", value=email)
@@ -45,7 +48,7 @@ class add(FormPlugin, PagePlugin):
return form.render()
def process_form(self, username=None, name=None, email=None, password=None, **kwargs):
- msg = Message()
+ msg = util.Message()
error = add_user(username, password, name, email, False)
if error:
@@ -55,7 +58,10 @@ class add(FormPlugin, PagePlugin):
cfg.log(msg.text)
main = self.main(username, name, email, msg=msg.text)
- return self.fill_template(title="Manage Users and Groups", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right)
+ return util.render_template(title="Manage Users and Groups", main=main,
+ sidebar_left=self.sidebar_left,
+ sidebar_right=self.sidebar_right)
+
class edit(FormPlugin, PagePlugin):
url = ["/sys/users/edit"]
@@ -68,7 +74,7 @@ class edit(FormPlugin, PagePlugin):
"Delete User" to remove users from %s and the %s
system.
Deleting users is permanent!
""" % (cfg.product_name, cfg.box_name)) - def main(self, msg=''): + def main(self, msg='', **kwargs): users = cfg.users.get_all() add_form = Form(title=_("Edit or Delete User"), action=cfg.server_dir + "/sys/users/edit", message=msg) add_form.html('DeleteCould not find a user with username of %s!
" % kwargs['username']) - return self.fill_template(template="err", title=_("Unknown User"), main=main, - sidebar_left=self.sidebar_left, sidebar_right=sidebar_right) + return util.render_template(template="err", + title=_("Unknown User"), main=main, + sidebar_left=self.sidebar_left, + sidebar_right=sidebar_right) main = _("""Edit User '%s'""" % u['username']) sidebar_right = '' - return self.fill_template(title="Manage Users and Groups", main=main, sidebar_left=self.sidebar_left, sidebar_right=sidebar_right) + return util.render_template(title="Manage Users and Groups", main=main, + sidebar_left=self.sidebar_left, + sidebar_right=sidebar_right) diff --git a/plinth.py b/plinth.py index c453787e0..2e5198f29 100755 --- a/plinth.py +++ b/plinth.py @@ -33,7 +33,7 @@ __status__ = "Development" import urlparse def error_page(status, dynamic_msg, stock_msg): - return u.page_template(template="err", title=status, main="%s
%s" % (dynamic_msg, stock_msg)) + return u.render_template(template="err", title=status, main="%s
%s" % (dynamic_msg, stock_msg)) def error_page_404(status, message, traceback, version): return error_page(status, message, """If you believe this
diff --git a/plugin_mount.py b/plugin_mount.py
index 69ff94552..e3a58c81c 100644
--- a/plugin_mount.py
+++ b/plugin_mount.py
@@ -1,8 +1,8 @@
import cherrypy
from modules.auth import require
import cfg
-from util import *
-import util as u
+import util
+
class PluginMount(type):
"""See http://martyalchin.com/2008/jan/10/simple-plugin-framework/ for documentation"""
@@ -87,9 +87,6 @@ class PagePlugin:
cfg.log.info("Registering page: %s" % url)
_setattr_deep(cfg.html_root, url, self)
- def fill_template(self, *args, **kwargs):
- return u.page_template(*args, **kwargs)
-
def forms(self, url, *args, **kwargs):
for form in cfg.forms:
if url in form.url:
@@ -98,7 +95,7 @@ class PagePlugin:
parts = get_parts(form, None, *args, **kwargs)
return parts
- return {'sidebar_left':left, 'sidebar_right':right, 'main':main}
+
class FormPlugin():
"""
@@ -138,11 +135,10 @@ class FormPlugin():
order = 50
url = []
- js = ''
def __init__(self, *args, **kwargs):
- for u in self.url:
- path = u.split("/")[1:] + [self.__class__.__name__]
+ for unit in self.url:
+ path = unit.split("/")[1:] + [self.__class__.__name__]
_setattr_deep(cfg.html_root, path, self)
cfg.log("Registered page: %s" % '.'.join(path))
@@ -156,20 +152,12 @@ class FormPlugin():
if kwargs:
kwargs['message'] = self.process_form(**kwargs)
parts = get_parts(self, **kwargs)
- return self.fill_template(**parts)
-
+ return util.render_template(**parts)
+
def process_form(self, **kwargs):
"""Process the form. Return any message as a result of processing."""
pass
- def fill_template(self, *args, **kwargs):
- if not 'js' in kwargs:
- try:
- kwargs['js'] = self.js
- except AttributeError:
- pass
- cfg.log("%%%%%%%%%%% %s" % kwargs)
- return u.page_template(*args, **kwargs)
class UserStoreModule:
"""
diff --git a/util.py b/util.py
index 8e5d305c8..20a5cba92 100644
--- a/util.py
+++ b/util.py
@@ -62,7 +62,7 @@ class Message():
self.text += "
%s" % text
-def page_template(template='login_nav', **kwargs):
+def render_template(template='login_nav', **kwargs):
for key in ['sidebar_left', 'sidebar_right', 'main', 'js', 'onload', 'nav',
'css', 'title', 'basehref']:
if not key in kwargs: