def statuspage(request): """Serve the status page """ check_nat = actions.run("dynamicdns", ["get-nat"]) last_update = actions.run("dynamicdns", ["get-last-success"]) no_nat = check_nat.strip() == "no" nat_unchecked = check_nat.strip() == "unknown" timer = actions.run("dynamicdns", ["get-timer"]) if no_nat: LOGGER.info("we are not behind a NAT") if nat_unchecked: LOGGER.info("we did not checked if we are behind a NAT") return TemplateResponse( request, "dynamicdns_status.html", { "title": _("Status of dynamicdns Client"), "no_nat": no_nat, "nat_unchecked": nat_unchecked, "timer": timer, "last_update": last_update, "subsubmenu": subsubmenu, }, )
def test_breakout_up(self): """3A. Users can't call actions above the actions directory. Tests both a relative and a literal path. """ for action in ('../echo', '/bin/echo'): with self.assertRaises(ValueError): run(action, ['hi'])
def repo_exists(name): """Check whether a remote repository exists.""" try: actions.run('gitweb', ['check-repo-exists', '--url', name]) except ActionError: return False return True
def test_breakout_up(self): """3A. Users can't call actions above the actions directory. Tests both a relative and a literal path. """ options="hi" for arg in ("../echo", "/bin/echo"): with self.assertRaises(ValueError): run(arg, options)
def get_status(): """Get the current settings.""" output = actions.run('deluge', ['get-enabled']) enabled = (output.strip() == 'yes') output = actions.run('deluge', ['is-running']) is_running = (output.strip() == 'yes') status = {'enabled': enabled, 'is_running': is_running} return status
def test_breakout_actions(self): """3C. Actions can't be used to run other actions. If multiple actions are specified, bail out. """ # Counting is safer than actual badness. actions = ('echo ""; echo $((1+1))', 'echo "" && echo $((1+1))', 'echo "" || echo $((1+1))') options = ('good', '') for action in actions: for option in options: with self.assertRaises(ValueError): run(action, [option])
def test_multiple_options_and_output(self): """4. Multiple options can be provided as a list or as a tuple. 5. Output is returned from the command. """ options = '1 2 3 4 5 6 7 8 9' output = run('echo', options.split()) output = output.rstrip('\n') self.assertEqual(options, output) output = run('echo', tuple(options.split())) output = output.rstrip('\n') self.assertEqual(options, output)
def add_shortcuts(): sites = actions.run('ikiwiki', ['get-sites']).split('\n') sites = [name for name in sites if name != ''] for site in sites: frontpage.add_shortcut( 'ikiwiki_' + site, site, url='/ikiwiki/' + site, login_required=False, icon='ikiwiki')
def __call__(self, value): """Validate a directory.""" if not value.startswith('/'): raise ValidationError(_('Invalid directory name.'), 'invalid') command = ['validate-directory', '--path', value] if self.check_creatable: command.append('--check-creatable') elif self.check_writable: command.append('--check-writable') if self.username: output = actions.run_as_user('storage', command, become_user=self.username) else: output = actions.run('storage', command) if 'ValidationError' in output: error_nr = int(output.strip().split()[1]) if error_nr == 1: raise ValidationError(_('Directory does not exist.'), 'invalid') elif error_nr == 2: raise ValidationError(_('Path is not a directory.'), 'invalid') elif error_nr == 3: raise ValidationError( _('Directory is not readable by the user.'), 'invalid') elif error_nr == 4: raise ValidationError( _('Directory is not writable by the user.'), 'invalid')
def run(arguments, superuser=True, input=None): """Run a given command and raise exception if there was an error""" command = 'pagekite' if superuser: return actions.superuser_run(command, arguments, input=input) else: return actions.run(command, arguments, input=input)
def manage(request): """Manage existing wikis and blogs.""" sites = actions.run("ikiwiki", ["get-sites"]).split("\n") sites = [name for name in sites if name != ""] return TemplateResponse( request, "ikiwiki_manage.html", {"title": _("Manage Wikis and Blogs"), "subsubmenu": subsubmenu, "sites": sites} )
def _run(arguments, superuser=False): """Run a given command and raise exception if there was an error""" command = 'dynamicdns' if superuser: return actions.superuser_run(command, arguments) else: return actions.run(command, arguments)
def test_action_path(monkeypatch): """Test that in development mode, python action scripts get the correct PYTHONPATH""" monkeypatch.setitem(os.environ, 'PYTHONPATH', '') plinth_path = run('test_path').strip() su_plinth_path = superuser_run('test_path').strip() assert plinth_path.startswith(cfg.file_root) assert plinth_path == su_plinth_path
def _run(arguments, superuser=False): """Run an given command and raise exception if there was an error""" command = 'firewall' if superuser: return actions.superuser_run(command, arguments) else: return actions.run(command, arguments)
def _run(arguments, superuser=True): """Run a given command and raise exception if there was an error""" command = 'pagekite-configure' if superuser: return actions.superuser_run(command, arguments) else: return actions.run(command, arguments)
def _run(arguments, superuser=False, input=None): """Run a given command and raise exception if there was an error.""" command = 'dynamicdns' if superuser: return actions.superuser_run(command, arguments, input=input) else: return actions.run(command, arguments, input=input)
def manage(request): """Manage existing wikis and blogs.""" sites = actions.run('ikiwiki', ['get-sites']).split('\n') sites = [name for name in sites if name != ''] return TemplateResponse(request, 'ikiwiki_manage.html', {'title': _('Manage Wikis and Blogs'), 'subsubmenu': subsubmenu, 'sites': sites})
def _run(self, cmd, arguments, superuser=True, **kwargs): """Run a backups or sshfs action script command.""" try: if superuser: return actions.superuser_run(cmd, arguments, **kwargs) return actions.run(cmd, arguments, **kwargs) except ActionError as err: self.reraise_known_error(err)
def refresh_sites(self): """Refresh blog and wiki list""" sites = actions.run('ikiwiki', ['get-sites']).split('\n') sites = [name.split(' ', 1) for name in sites if name != ''] for site in sites: if not 'shortcut-ikiwiki-' + site[0] in self.components: self.add_shortcut(site[0], site[1]) return sites
def get_status(): """Get the current settings from server.""" output = actions.run('mumble', ['get-enabled']) enabled = (output.strip() == 'yes') output = actions.superuser_run('mumble', ['is-running']) is_running = (output.strip() == 'yes') status = {'enabled': enabled, 'is_running': is_running} return status
def _get_branches(repo): """Get all the branches in the repository.""" branch_data = json.loads( actions.run('gitweb', ['get-branches', '--name', repo])) default_branch = branch_data['default_branch'] branches = branch_data['branches'] if default_branch not in branches: branches.insert(0, default_branch) return [(branch, branch) for branch in branches]
def repo_info(repo): """Get information about repository.""" output = actions.run('gitweb', ['repo-info', '--name', repo]) info = json.loads(output) if info['access'] == 'private': info['is_private'] = True else: info['is_private'] = False del info['access'] return info
def test_breakout_option_string(self): """3D. Option strings can't be used to run other actions. Verify that shell control characters aren't interpreted. """ options = ('; echo hello', '&& echo hello', '|| echo hello', '& echo hello', r'\; echo hello', '| echo hello', r':;!&\/$%@`"~#*(){}[]|+=') for option in options: output = run('echo', [option]) output = output.rstrip('\n') self.assertEqual(option, output)
def get_status(): """Get the current settings from server.""" output = actions.run('privoxy', ['get-enabled']) enabled = (output.strip() == 'yes') output = actions.superuser_run('privoxy', ['is-running']) is_running = (output.strip() == 'yes') status = {'enabled': enabled, 'is_running': is_running} return status
def statuspage(request): """Serve the status page """ check_nat = actions.run('dynamicdns', ['get-nat']) last_update = actions.run('dynamicdns', ['get-last-success']) no_nat = check_nat.strip() == 'no' nat_unchecked = check_nat.strip() == 'unknown' timer = actions.run('dynamicdns', ['get-timer']) if no_nat: LOGGER.info('we are not behind a NAT') if nat_unchecked: LOGGER.info('we did not checked if we are behind a NAT') return TemplateResponse(request, 'dynamicdns_status.html', {'title': _('Status of dynamicdns Client'), 'no_nat': no_nat, 'nat_unchecked': nat_unchecked, 'timer': timer, 'last_update': last_update, 'subsubmenu': subsubmenu})
def statuspage(request): """Serve the status page.""" check_nat = actions.run('dynamicdns', ['get-nat']) last_update = actions.run('dynamicdns', ['get-last-success']) no_nat = check_nat.strip() == 'no' nat_unchecked = check_nat.strip() == 'unknown' timer = actions.run('dynamicdns', ['get-timer']) if no_nat: logger.info('Not behind a NAT') if nat_unchecked: logger.info('Did not check if behind a NAT') return TemplateResponse(request, 'dynamicdns_status.html', {'title': _('Dynamic DNS Status'), 'no_nat': no_nat, 'nat_unchecked': nat_unchecked, 'timer': timer, 'last_update': last_update, 'subsubmenu': subsubmenu})
def init(): """Intialize the module.""" menu = cfg.main_menu.get('apps:index') menu.add_urlname(_('Web Proxy (Privoxy)'), 'glyphicon-cloud-upload', 'privoxy:index', 50) output = actions.run('privoxy', ['get-enabled']) enabled = (output.strip() == 'yes') global service service = service_module.Service( 'privoxy', _('Privoxy Web Proxy'), is_external=False, enabled=enabled)
def init(): """Intialize the Transmission module.""" menu = cfg.main_menu.get('apps:index') menu.add_urlname(_('BitTorrent (Transmission)'), 'glyphicon-save', 'transmission:index', 100) output = actions.run('transmission', ['get-enabled']) enabled = (output.strip() == 'yes') global service service = service_module.Service( 'transmission', _('Transmission BitTorrent'), ['http', 'https'], is_external=True, enabled=enabled)
def init(): """Intialize the Mumble module.""" menu = cfg.main_menu.get('apps:index') menu.add_urlname(_('Voice Chat (Mumble)'), 'glyphicon-headphones', 'mumble:index', 50) output = actions.run('mumble', ['get-enabled']) enabled = (output.strip() == 'yes') global service service = service_module.Service( 'mumble-plinth', _('Mumble Voice Chat Server'), is_external=True, enabled=enabled)
def get_status(): """Get the current settings from Transmission server.""" output = actions.run('transmission', ['get-enabled']) enabled = (output.strip() == 'yes') output = actions.superuser_run('transmission', ['is-running']) is_running = (output.strip() == 'yes') configuration = open(TRANSMISSION_CONFIG, 'r').read() status = json.loads(configuration) status = {key.translate(str.maketrans({'-': '_'})): value for key, value in status.items()} status['enabled'] = enabled status['is_running'] = is_running status['hostname'] = socket.gethostname() return status
def register(request): """Serve the registration form.""" form = None vhosts = actions.run("xmpp", ["get-vhosts"]).split() if request.method == "POST": form = RegisterForm(vhosts, request.POST, prefix="xmpp") # pylint: disable-msg=E1101 if form.is_valid(): _register_user(request, form.cleaned_data) form = RegisterForm(vhosts, prefix="xmpp") else: form = RegisterForm(vhosts, prefix="xmpp") return TemplateResponse( request, "xmpp_register.html", {"title": _("Register XMPP Account"), "form": form, "subsubmenu": subsubmenu} )
def test_breakout_option_list(self): """3D. Option lists can't be used to run other actions. Verify that shell control characters aren't interpreted in option lists. """ option_lists = ((';', 'echo', 'hello'), ('&&', 'echo', 'hello'), ('||', 'echo', 'hello'), ('&', 'echo', 'hello'), (r'\;', 'echo' 'hello'), ('|', 'echo', 'hello'), ('', 'echo', '', 'hello'), # Empty option argument tuple(r':;!&\/$%@`"~#*(){}[]|+=')) for options in option_lists: output = run('echo', options) output = output.rstrip('\n') expected_output = ' '.join(options) self.assertEqual(output, expected_output)
def test_breakout_actions(self): """3C. Actions can't be used to run other actions. If multiple actions are specified, bail out. """ # counting is safer than actual badness. actions = ("echo ''; echo $((1+1))", "echo '' && echo $((1+1))", "echo '' || echo $((1+1))") options = ("good", "") for action in actions: for option in options: with self.assertRaises(ValueError): output = run(action, option) # if it somewhow doesn't error, we'd better not evaluate # the data. self.assertFalse("2" in output[0])
def register(request): """Serve the registration form.""" form = None vhosts = actions.run('xmpp', ['get-vhosts']).split() if request.method == 'POST': form = RegisterForm(vhosts, request.POST, prefix='xmpp') # pylint: disable-msg=E1101 if form.is_valid(): _register_user(request, form.cleaned_data) form = RegisterForm(vhosts, prefix='xmpp') else: form = RegisterForm(vhosts, prefix='xmpp') return TemplateResponse( request, 'xmpp_register.html', { 'title': _('Register XMPP Account'), 'form': form, 'subsubmenu': subsubmenu })
def is_enabled(): """Return whether the module is enabled.""" output = actions.run('owncloud-setup', ['status']) return 'enable' in output.split()
def get_status(): """Return the current status""" """ToDo: use key/value instead of hard coded value list""" status = {} output = actions.run("dynamicdns", ["status"]) details = output.split() status["enabled"] = output.split()[0] == "enabled" if len(details) > 1: if details[1] == "disabled": status["dynamicdns_server"] = "" else: status["dynamicdns_server"] = details[1].replace("'", "") else: status["dynamicdns_server"] = "" if len(details) > 2: if details[2] == "disabled": status["dynamicdns_domain"] = "" else: status["dynamicdns_domain"] = details[2] status["dynamicdns_domain"] = details[2].replace("'", "") else: status["dynamicdns_domain"] = "" if len(details) > 3: if details[3] == "disabled": status["dynamicdns_user"] = "" else: status["dynamicdns_user"] = details[3].replace("'", "") else: status["dynamicdns_user"] = "" if len(details) > 4: if details[4] == "disabled": status["dynamicdns_secret"] = "" else: status["dynamicdns_secret"] = details[4].replace("'", "") else: status["dynamicdns_secret"] = "" if len(details) > 5: if details[5] == "disabled": status["dynamicdns_ipurl"] = "" else: status["dynamicdns_ipurl"] = details[5].replace("'", "") else: status["dynamicdns_ipurl"] = "" if len(details) > 6: if details[6] == "disabled": status["dynamicdns_update_url"] = "" else: status["dynamicdns_update_url"] = details[6].replace("'", "") else: status["dynamicdns_update_url"] = "" if len(details) > 7: status["disable_SSL_cert_check"] = output.split()[7] == "enabled" else: status["disable_SSL_cert_check"] = False if len(details) > 8: status["use_http_basic_auth"] = output.split()[8] == "enabled" else: status["use_http_basic_auth"] = False if not status["dynamicdns_server"] and not status["dynamicdns_update_url"]: status["service_type"] = "GnuDIP" elif not status["dynamicdns_server"] and status["dynamicdns_update_url"]: status["service_type"] = "other" else: status["service_type"] = "GnuDIP" return status
def get_status(): """Return the current status""" output = actions.run('xmpp-setup', 'status') return {'inband_enabled': 'inband_enable' in output.split()}
def get_status(): """Return the current status""" output = actions.run('owncloud-setup', ['status']) return {'enabled': 'enable' in output.split()}
def get_context_data(self, **kwargs): """Return the data to be used for rendering templates.""" context = super(UserChangePassword, self).get_context_data(**kwargs) output = actions.run('check-user-exists', [self.kwargs['slug']]) context['is_posix_user'] = '******' in output return context
def get_status(): """Return the current status""" """ToDo: use key/value instead of hard coded value list""" status = {} output = actions.run('dynamicdns', 'status') details = output.split() status['enabled'] = (output.split()[0] == 'enabled') if len(details) > 1: if details[1] == 'disabled': status['dynamicdns_server'] = '' else: status['dynamicdns_server'] = details[1].replace("'", "") else: status['dynamicdns_server'] = '' if len(details) > 2: if details[2] == 'disabled': status['dynamicdns_domain'] = '' else: status['dynamicdns_domain'] = details[2] status['dynamicdns_domain'] = details[2].replace("'", "") else: status['dynamicdns_domain'] = '' if len(details) > 3: if details[3] == 'disabled': status['dynamicdns_user'] = '' else: status['dynamicdns_user'] = details[3].replace("'", "") else: status['dynamicdns_user'] = '' if len(details) > 4: if details[4] == 'disabled': status['dynamicdns_secret'] = '' else: status['dynamicdns_secret'] = details[4].replace("'", "") else: status['dynamicdns_secret'] = '' if len(details) > 5: if details[5] == 'disabled': status['dynamicdns_ipurl'] = '' else: status['dynamicdns_ipurl'] = details[5].replace("'", "") else: status['dynamicdns_ipurl'] = '' if len(details) > 6: if details[6] == 'disabled': status['dynamicdns_update_url'] = '' else: status['dynamicdns_update_url'] = details[6].replace("'", "") else: status['dynamicdns_update_url'] = '' if len(details) > 7: status['disable_SSL_cert_check'] = (output.split()[7] == 'enabled') else: status['disable_SSL_cert_check'] = False if len(details) > 8: status['use_http_basic_auth'] = (output.split()[8] == 'enabled') else: status['use_http_basic_auth'] = False if not status['dynamicdns_server'] and not status['dynamicdns_update_url']: status['service_type'] = 'GnuDIP' elif not status['dynamicdns_server'] and status['dynamicdns_update_url']: status['service_type'] = 'other' else: status['service_type'] = 'GnuDIP' return status
def get_context_data(self, **kwargs): """Return the data to be used for rendering templates.""" context = super(UserUpdate, self).get_context_data(**kwargs) output = actions.run('check-user-exists', [self.object.username]) context['is_posix_user'] = '******' in output return context