Пример #1
0
    def index(self):
        """Tunnel administration."""
        c.rows = []
        host_q = Session.query(Host)
        tunnel_q = Session.query(Tunnel)
        checkin_q = Session.query(Checkin)

        # walk through all known hosts
        for host in host_q.all():

            # find the tunnel record for this host
            tunnel = tunnel_q.filter_by(mac=host.mac).one()

            # update tunnel enabled flag (unless just arriving)
            if request.POST.has_key("update"):
                if request.POST.has_key(host.get_mac()):
                    tunnel.set_port(h.get_free_port())
                    tunnel.set_enabled(True)
                else:
                    tunnel.set_port(0)
                    tunnel.set_enabled(False)
                Session.save_or_update(tunnel)

            # find most recent checkin, if any
            checkins = checkin_q.filter_by(mac=host.mac)
            latest = checkins.order_by(Checkin.tstamp.desc()).first()
            temp = latest.temp
            tstamp = latest.tstamp
            blurb = secs_to_blurb(tstamp)

            # build output for template
            enabled = ['','checked'][tunnel.enabled]
            c.rows.append((host.get_mac(), enabled, tunnel.get_port(),
                host.get_type(), host.get_host(), host.get_cust(),
                host.get_desc(), tstamp, blurb, temp))

        Session.commit()
        return render('/admin.mako')
Пример #2
0
                abort(400, 'Invalid username: "******": %s' % (mac, str(e)))
            try:
                c.tunnel.set_username(username)
            except:
                abort(400, 'Invalid username: "******"' % username)
            try:
                c.tunnel.set_random_password()
            except:
                abort(400, 'Invalid password')
            try:
                c.tunnel.set_port(0)
            except:
                abort(400, 'Invalid port')

            # create unix account
            retcode = h.admit_to_jail(c.tunnel.get_username(),
                    c.host.get_host())
            if retcode:
                abort(500, '%d' % retcode)
            h.set_password(str(c.tunnel.get_username()),
                    str(c.tunnel.get_password()))

            # store new record
            Session.save_or_update(c.tunnel)
            Session.commit()

        if d.has_key('debug'):
            return render('/reg.mako')
        return ''