From 16c994b7871aca623c926cedb7329a2812dc5bf6 Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Sun, 24 Nov 2013 22:07:13 -0600 Subject: [PATCH] Cleaned up missed references to privilegedactions. --- actions.py | 19 ++++++++++++++++++- modules/installed/apps/owncloud.py | 8 ++++---- modules/installed/services/xmpp.py | 16 ++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/actions.py b/actions.py index 1cda7dec8..506aff6b9 100644 --- a/actions.py +++ b/actions.py @@ -79,15 +79,31 @@ import pipes, shlex, subprocess contract.checkmod(__name__) def run(action, options = None, async = False): + """Safely run a specific action as the current user. + See actions._run for more information. + + """ return _run(action, options, async, False) def superuser_run(action, options = None, async = False): + """Safely run a specific action as root. + See actions._run for more information. + + """ return _run(action, options, async, True) def _run(action, options = None, async = False, run_as_root = False): - """Safely run a specific action as root. + """Safely run a specific action as a normal user or root. + + actions are pulled from the actions directory. + + options are added to the action command. + + async: run asynchronously or wait for the command to complete. + + run_as_root: execute the command through sudo. pre: os.sep not in action @@ -96,6 +112,7 @@ def _run(action, options = None, async = False, run_as_root = False): """ DIRECTORY = "actions" + if options == None: options = [] diff --git a/modules/installed/apps/owncloud.py b/modules/installed/apps/owncloud.py index 83a79539c..92b004029 100644 --- a/modules/installed/apps/owncloud.py +++ b/modules/installed/apps/owncloud.py @@ -3,7 +3,7 @@ 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 actions import cfg from util import Message @@ -33,7 +33,7 @@ class configure(FormPlugin, PagePlugin): sidebar_right = _("Configure Owncloud") def main(self, owncloud_enable=False, message=None, *args, **kwargs): - output, error = privilegedaction_run("owncloud-setup", 'status') + output, error = actions.run("owncloud-setup", 'status') if error: raise Exception("something is wrong: " + error) if "enable" in output.split(): @@ -46,7 +46,7 @@ class configure(FormPlugin, PagePlugin): 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.html(_("""

When enabled, the owncloud installation will be available from owncloud on the web server.

""")) form.submit(_("Update setup")) return form.render() @@ -66,7 +66,7 @@ class configure(FormPlugin, PagePlugin): opts.append(key) else: opts.append('no'+key) - privilegedaction_run("owncloud-setup", " ".join(opts)) + actions.superuser_run("owncloud-setup", opts, async=True) 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/services/xmpp.py b/modules/installed/services/xmpp.py index 19f322bd5..f3d48ad7a 100644 --- a/modules/installed/services/xmpp.py +++ b/modules/installed/services/xmpp.py @@ -4,7 +4,7 @@ from modules.auth import require from plugin_mount import PagePlugin, FormPlugin import cfg from forms import Form -from actions import superuser_run +import actions from util import Message class xmpp(PagePlugin): @@ -30,7 +30,7 @@ class configure(FormPlugin, PagePlugin): sidebar_right = _("Configure XMPP Server") def main(self, xmpp_inband_enable=False, message=None, *args, **kwargs): - output, error = superuser_run("xmpp-setup", 'status') + output, error = actions.superuser_run("xmpp-setup", 'status') if error: raise Exception("something is wrong: " + error) if "inband_enable" in output.split(): @@ -64,7 +64,7 @@ class configure(FormPlugin, PagePlugin): opts.append(key) else: opts.append('no'+key) - privilegedaction_run("xmpp-setup", " ".join(opts)) + actions.run("xmpp-setup", opts) 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) @@ -92,7 +92,8 @@ class register(FormPlugin, PagePlugin): if not password: msg.add = _("Must specify a password!") if username and password: - output, error = superuser_run("xmpp-register", [username, password]) + output, error = actions.superuser_run( + "xmpp-register", [username, password]) if error: raise Exception("something is wrong: " + error) @@ -103,5 +104,8 @@ class register(FormPlugin, PagePlugin): cfg.log(msg.text) main = self.main(username, msg=msg.text) - return self.fill_template(title="XMPP Server Configuration", main=main, sidebar_left=self.sidebar_left, sidebar_right=self.sidebar_right) - + return self.fill_template( + title="XMPP Server Configuration", + main=main, + sidebar_left=self.sidebar_left, + sidebar_right=self.sidebar_right)