Exemple #1
0
 def on_open(self, info):
     """Register new handler with MessageNotifier."""
     StatusConnection.CLIENTS.register(self)
     with session_scope() as session:
         latest = query.get_latest_data(session)
     self.send(latest)
     LOG.debug('Registered client')
 def open(self):
     """Register new handler with MessageNotifier."""
     StatusHandler.CLIENTS.register(self)
     with session_scope() as session:
         latest = query.get_latest_data(session)
     self.write_message(latest)
     LOG.debug('Registered client')
Exemple #3
0
 def on_open(self, info):
     """Register new handler with MessageNotifier."""
     StatusConnection.CLIENTS.register(self)
     with session_scope() as session:
         latest = query.get_latest_data(session)
     self.send(latest)
     LOG.debug('Registered client')
Exemple #4
0
def persist(session, data, flush=True):
    """Persist data to configured DB and return persisted object
    in a consistent state.

    **Note:** will log what's being persisted, so don't put clear text password
    into `__str__()`."""
    LOG.debug('Persisting data {}'.format(data))
    session.add(data)
    if flush:
        session.flush()
    return data
    def post(self):
        now = datetime.now()
        remote_ip = self.request.remote_ip

        with session_scope() as session:
            last = query.get_last_login_attempt(session, remote_ip)
            if last is None:
                last = LoginAttempt(None, remote_ip)
                persist(session, last)
            else:
                if (now - last.timestamp) < timedelta(seconds=options.mac_update_interval):
                    LOG.warning("Too frequent attempts to update, remote IP address is %s", remote_ip)
                    raise HTTPError(403, "Too frequent")
                else:
                    last.timestamp = now
                    persist(session, last)

        try:
            password = self.get_argument("password")
            macs = self.get_argument("macs")
        except MissingArgumentError:
            LOG.warning("MAC update received malformed parameters: %s", self.request.arguments)
            raise HTTPError(400, "Bad parameters list")

        if not secure_compare(password, options.mac_update_password):
            LOG.warning("Client provided wrong password for MAC update!")
            raise HTTPError(403, "Wrong password")

        LOG.info("Authorized request to update list of checked-in users from IP address %s", remote_ip)

        macs = json.loads(macs)

        with session_scope() as session:
            names = session.\
                query(distinct(User.name)).\
                filter(User.userid == MACToUser.userid).\
                filter(MACToUser.mac_hash .in_ (macs)).\
                all()

        MACUpdateHandler.ROSTER = [n[0] for n in names]
        LOG.debug("Updated list of checked in users: %s", MACUpdateHandler.ROSTER)
Exemple #6
0
 def unregister(self, client):
     """Remove the handler from the clients list."""
     LOG.debug('Removing client {} from {}'.format(client, self.name))
     self.clients.remove(client)
Exemple #7
0
 def register(self, client):
     """Add a new handler to the clients list."""
     LOG.debug('Adding client {} to {}'.format(client, self.name))
     self.clients.append(client)
Exemple #8
0
def delete(session, data):
    """Delete data from DB."""
    LOG.debug('Deleting {}'.format(data))
    session.delete(data)
Exemple #9
0
 def unregister(self, client):
     """Remove the handler from the clients list."""
     LOG.debug('Removing client {} from {}'.format(client, self.name))
     self.clients.remove(client)
Exemple #10
0
 def register(self, client):
     """Add a new handler to the clients list."""
     LOG.debug('Adding client {} to {}'.format(client, self.name))
     self.clients.append(client)
Exemple #11
0
 def on_close(self):
     """Unregister this handler when the connection is closed."""
     StatusConnection.CLIENTS.unregister(self)
     LOG.debug('Unregistered client.')
 def on_close(self):
     """Unregister this handler when the connection is closed."""
     StatusHandler.CLIENTS.unregister(self)
     LOG.debug('Unregistered client.')
 def unregister(self, client):
     """Remove the handler from the clients list."""
     LOG.debug('Removing client %r from %r', client, self.name)
     self.clients.remove(client)
 def register(self, client):
     """Add a new handler to the clients list."""
     LOG.debug('Adding client %r to %r', client, self.name)
     self.clients.append(client)
def delete(session, data):
    """Delete data from DB."""
    LOG.debug('Deleting %r', data)
    session.delete(data)