Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
    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())
Beispiel #4
0
    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())
Beispiel #5
0
 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
Beispiel #6
0
 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
Beispiel #7
0
    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')
Beispiel #8
0
 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
Beispiel #9
0
    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')
Beispiel #10
0
    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()]]
Beispiel #11
0
    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()]]
Beispiel #12
0
    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()]
        ]
Beispiel #13
0
 def _size(self):
     status, output = run('ykval-export-clients | wc -l')
     return int(output) if status == 0 else 0
Beispiel #14
0
 def _size(self):
     status, output = run('ykval-export-clients | wc -l')
     return int(output) if status == 0 else 0
Beispiel #15
0
 def update(self, request):
     run('apt-get update')
     return self.redirect('/sys')
Beispiel #16
0
def is_freerad_running():
    status, _ = run('cat /var/run/freeradius/freeradius.pid | xargs kill -0')
    return status == 0
Beispiel #17
0
def reboot():
    run('reboot')
Beispiel #18
0
def get_updates():
    s, o = run("apt-get upgrade -s | awk -F'[][() ]+' '/^Inst/{print $2}'")
    packages = o.splitlines()
    return packages
Beispiel #19
0
 def update(self, request):
     run('apt-get update')
     return self.redirect('/sys')
Beispiel #20
0
def get_updates():
    s, o = run("apt-get upgrade -s | awk -F'[][() ]+' '/^Inst/{print $2}'")
    packages = o.splitlines()
    return packages
Beispiel #21
0
def reboot():
    run('reboot')
Beispiel #22
0
def is_freerad_running():
    status, _ = run('cat /var/run/freeradius/freeradius.pid | xargs kill -0')
    return status == 0