Пример #1
0
    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)
Пример #2
0
# Copyright (C) 2013 Stefano Sanfilippo
# Copyright (C) 2013 BITS development team
#
# This file is part of bitsd, which is released under the terms of
# GNU GPLv3. See COPYING at top level for more information.
#
"""
Fill Database with Markdown pages.
"""

# DO NOT REMOVE
import bitsd.properties

from bitsd.persistence import start
from bitsd.persistence.models import Page
from bitsd.persistence.engine import persist, session_scope
from tornado.options import parse_config_file

if __name__ == '__main__':
    try:
        parse_config_file('/etc/bitsd.conf')
    except IOError:
        print("No /etc/bitsd.conf found, ignoring.")

    start()

    with open('INFO.md', 'r') as info:
        infopage = Page('Info', info.read().decode('utf-8'))
        with session_scope() as session:
            persist(session, infopage)
Пример #3
0
def usermod(session, username, password):
    """"Modify password for existing user."""
    user = get_user(session, username)
    user.password = Hasher.encrypt(password)
    persist(session, user)
Пример #4
0
def useradd(session, username, password):
    """Add user with hashed password to database"""
    user = User(username, Hasher.encrypt(password))
    persist(session, user)
Пример #5
0
def usermod(session, username, password):
    """"Modify password for existing user."""
    user = get_user(session, username)
    user.password = Hasher.encrypt(password)
    persist(session, user)
Пример #6
0
def useradd(session, username, password):
    """Add user with hashed password to database"""
    user = User(username, Hasher.encrypt(password))
    persist(session, user)
Пример #7
0
#
# This file is part of bitsd, which is released under the terms of
# GNU GPLv3. See COPYING at top level for more information.
#

"""
Fill Database with Markdown pages.
"""

# DO NOT REMOVE
import bitsd.properties

from bitsd.persistence import start
from bitsd.persistence.models import Page
from bitsd.persistence.engine import persist, session_scope
from tornado.options import parse_config_file


if __name__ == '__main__':
    try:
        parse_config_file('/etc/bitsd.conf')
    except IOError:
        print ("No /etc/bitsd.conf found, ignoring.")

    start()

    with open('INFO.md', 'r') as info:
        infopage = Page('Info', info.read().decode('utf-8'))
        with session_scope() as session:
            persist(session, infopage)