def __call__(self, request): from yubiadmin.apps import apps panels = [panel for app in apps if not getattr(app, 'disabled', False) and hasattr(app, 'dash_panels') for panel in app.dash_panels] request.environ['yubiadmin.response'].extend('content', render('dashboard', panels=panels))
def general(self, request): alerts = [] form = RadTestForm() if 'username' in request.params: form.process(request.params) username = form.username.data password = form.password.data secret = form.client_secret.data cmd = 'radtest "%s" "%s" localhost 0 "%s"' % (username, password, secret) status, output = run(cmd) alert = {'title': 'Command: %s' % cmd} alert['message'] = '<pre style="white-space: pre-wrap;">%s</pre>' \ % output if status == 0: alert['type'] = 'success' elif status == 1: alert['type'] = 'warn' else: alert['type'] = 'error' alert['message'] = 'There was an error running the command. ' \ 'Exit code: %d' % status alerts.append(alert) return render('freerad/general', form=form, alerts=alerts, running=is_freerad_running())
def general(self, request): alerts = [] form = RadTestForm() if 'username' in request.params: form.process(request.params) username = form.username.data password = form.password.data secret = form.client_secret.data cmd = 'radtest %s %s localhost 0 %s' % (username, password, secret) status, output = run(cmd) alert = {'title': 'Command: %s' % cmd} alert['message'] = '<pre style="white-space: pre-wrap;">%s</pre>' \ % output if status == 0: alert['type'] = 'success' elif status == 1: alert['type'] = 'warn' else: alert['type'] = 'error' alert['message'] = 'There was an error running the command. ' \ 'Exit code: %d' % status alerts.append(alert) return render('freerad/general', form=form, alerts=alerts, running=is_freerad_running())
def __call__(self, request): module_name = request.path_info_pop() apps_data = OrderedDict() for app in apps: app_data = inspect_app(app) apps_data[app_data['name']] = (app, app_data) modules = [data for (_, data) in apps_data.values()] if not module_name: module_name = 'dashboard' if not module_name in apps_data: raise exc.HTTPNotFound app, module = apps_data[module_name] if module['disabled']: raise exc.HTTPNotFound request.environ['yubiadmin.response'] = render( 'content', modules=modules, module=module, title='YubiAdmin - %s' % module_name ) resp = app(request) if not resp: return request.environ['yubiadmin.response'] return resp
def reboot(self, request): if 'now' in request.params: run('reboot') else: timer = Timer(1, run, args=('reboot', )) timer.start() alerts = [{'type': 'warn', 'message': 'Rebooting System...'}] return render('/sys/general', alerts=alerts)
def general(self, request): alerts = [] if needs_restart(): alerts.append({ 'message': 'The machine needs to reboot.', 'type': 'error' }) return render('/sys/general', alerts=alerts, updates=get_updates())
def reboot(self, request): if 'now' in request.params: run('reboot') else: timer = Timer(1, run, args=('reboot',)) timer.start() alerts = [{'type': 'warn', 'message': 'Rebooting System...'}] return render('/sys/general', alerts=alerts)
def create(self, request): status, output = run("ykval-gen-clients --urandom") if status == 0: parts = [x.strip() for x in output.split(",")] return render("val/client_created", client_id=parts[0], api_key=parts[1]) resp = self.list() resp.data["alerts"] = [ {"type": "error", "title": "Error generating client:", "message": "Command exited with status: %d" % status} ] return resp
def __call__(self, request): module_name = request.path_info_pop() section_name = request.path_info_pop() apps_data = OrderedDict() for app in apps: app_data = inspect_app(app) apps_data[app_data['name']] = (app, app_data) modules = [data for (_, data) in apps_data.values()] if not module_name: return render('index', modules=modules) if not module_name in apps_data: raise exc.HTTPNotFound app, module = apps_data[module_name] if module['disabled']: raise exc.HTTPNotFound if not section_name: section_name = module['sections'][0]['name'] raise exc.HTTPSeeOther(location=request.path + '/' + section_name) if not hasattr(app, section_name): raise exc.HTTPNotFound section = next((section for section in module['sections'] if section['name'] == section_name), None) resp = getattr(app, section_name)(request) if isinstance(resp, Response): return resp return render( 'app_base', modules=modules, module=module, section=section, title='YubiAdmin - %s - %s' % (module_name, section_name), page=resp )
def __call__(self, request): module_name = request.path_info_pop() section_name = request.path_info_pop() apps_data = OrderedDict() for app in apps: app_data = inspect_app(app) apps_data[app_data['name']] = (app, app_data) modules = [data for (_, data) in apps_data.values()] if not module_name: return render('index', modules=modules) if not module_name in apps_data: raise exc.HTTPNotFound app, module = apps_data[module_name] if module['disabled']: raise exc.HTTPNotFound if not section_name: section_name = module['sections'][0]['name'] raise exc.HTTPSeeOther(location=request.path + '/' + section_name) if not hasattr(app, section_name): raise exc.HTTPNotFound section = next((section for section in module['sections'] if section['name'] == section_name), None) resp = getattr(app, section_name)(request) if isinstance(resp, Response): return resp return render('app_base', modules=modules, module=module, section=section, title='YubiAdmin - %s - %s' % (module_name, section_name), page=resp)
def create(self, request): status, output = run('ykval-gen-clients --urandom') if status == 0: parts = [x.strip() for x in output.split(',')] return render('val/client_created', client_id=parts[0], api_key=parts[1]) resp = self.list() resp.data['alerts'] = [ {'type': 'error', 'title': 'Error generating client:', 'message': 'Command exited with status: %d' % status}] return resp
def dist_upgrade(self, request): if get_updates(): return Response(app_iter=Updater()) else: alerts = [{'message': 'Software is up to date!'}] return render('/sys/general', alerts=alerts)
def general(self, request): alerts = [] if needs_restart(): alerts.append({'message': 'The machine needs to reboot.', 'type': 'error'}) return render('/sys/general', alerts=alerts, updates=get_updates())