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 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 = [] 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 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 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 dash_panels(self): if needs_restart(): yield panel('System', 'System restart required', level='danger') updates = len(get_updates()) if updates > 0: yield panel( 'System', 'There are <strong>%d</strong> updates available' % updates, '/%s/general' % self.name, 'info') _, time = run('date "+%a, %d %b %Y %H:%M"') _, result = run('uptime') rest = [x.strip() for x in result.split('up', 1)][1] parts = [x.strip() for x in rest.split(',')] uptime = parts[0] if not 'days' in parts[0] else '%s, %s' % \ tuple(parts[:2]) yield panel('System', 'Date: %s<br />Uptime: %s' % (time, uptime), level='info')
def dash_panels(self): if needs_restart(): yield panel('System', 'System restart required', level='danger') updates = len(get_updates()) if updates > 0: yield panel( 'System', 'There are <strong>%d</strong> updates available' % updates, '/%s/general' % self.name, 'info' ) _, time = run('date "+%a, %d %b %Y %H:%M"') _, result = run('uptime') rest = [x.strip() for x in result.split('up', 1)][1] parts = [x.strip() for x in rest.split(',')] uptime = parts[0] if not 'days' in parts[0] else '%s, %s' % \ tuple(parts[:2]) yield panel('System', 'Date: %s<br />Uptime: %s' % (time, uptime), level='info')
def _get(self, offset=0, limit=None): cmd = 'ykval-export-clients' if offset > 0: cmd += '| tail -n+%d' % (offset + 1) if limit: cmd += '| head -n %d' % limit status, output = run(cmd) if status != 0: return [] return [{ 'id': parts[0], 'label': '%s - %s' % (parts[0], parts[3]), 'Client ID': parts[0], 'Enabled': parts[1] != '0', 'API Key': parts[3] } for parts in [line.split(',') for line in output.splitlines()]]
def _get(self, offset=0, limit=None): cmd = "ykval-export-clients" if offset > 0: cmd += "| tail -n+%d" % (offset + 1) if limit: cmd += "| head -n %d" % limit status, output = run(cmd) if status != 0: return [] return [ { "id": parts[0], "label": "%s - %s" % (parts[0], parts[3]), "Client ID": parts[0], "Enabled": parts[1] != "0", "API Key": parts[3], } for parts in [line.split(",") for line in output.splitlines()] ]
def _size(self): status, output = run('ykval-export-clients | wc -l') return int(output) if status == 0 else 0
def update(self, request): run('apt-get update') return self.redirect('/sys')
def is_freerad_running(): status, _ = run('cat /var/run/freeradius/freeradius.pid | xargs kill -0') return status == 0
def reboot(): run('reboot')
def get_updates(): s, o = run("apt-get upgrade -s | awk -F'[][() ]+' '/^Inst/{print $2}'") packages = o.splitlines() return packages