Ejemplo n.º 1
0
def create_switch(name, management_ip, room, processor):
    switch = Switch(management_ip=management_ip, host=Host(room=room, owner=User.q.get(0), name=name))

    session.add(switch)

    log_room_event("Created switch '{}' with management IP {}.".format(switch.host.name, switch.management_ip),
                   processor, switch.host.room)

    return switch
Ejemplo n.º 2
0
def create_switch(name, management_ip, room, processor):
    switch = Switch(management_ip=management_ip, host=Host(room=room, owner=User.get(0), name=name))

    session.add(switch)

    message = deferred_gettext("Created switch '{}' with management IP {}.")\
        .format(switch.host.name, switch.management_ip)
    log_room_event(message.to_json(),
                   processor, switch.host.room)

    return switch
Ejemplo n.º 3
0
def host_create(owner, room, name, processor):
    host = Host(name=name, owner_id=owner.id, room=room)

    session.add(host)

    message = deferred_gettext(
        u"Created host '{name}' in {dorm} {level}-{room}.".format(
            name=host.name,
            dorm=room.building.short_name,
            level=room.level,
            room=room.number))

    log_user_event(author=processor,
                   user=owner,
                   message=message.to_json())\

    return host
Ejemplo n.º 4
0
def move_in(user, building_id, level, room_number, mac, processor, birthdate=None,
            host_annex=False, begin_membership=True, when=None):
    """Move in a user in a given room and do some initialization.

    The user is given a new Host with an interface of the given mac, a
    UnixAccount, a finance Account, and is made member of important
    groups.  Networking is set up.

    :param User user: The user to move in
    :param int building_id:
    :param int level:
    :param str room_number:
    :param str mac: The mac address of the users pc.
    :param User processor:
    :param Date birthdate: Date of birth`
    :param bool host_annex: when true: if MAC already in use,
        annex host to new user
    :param bool begin_membership: Starts a membership if true
    :param datetime when: The date at which the user should be moved in

    :return: The user object.
    """

    if when and when > session.utcnow():
        return schedule_user_task(task_type=TaskType.USER_MOVE_IN,
                                  due=when,
                                  user=user,
                                  parameters={'building_id': building_id,
                                              'level': level,
                                              'room_number': room_number,
                                              'mac': mac,
                                              'birthdate': birthdate,
                                              'host_annex': host_annex,
                                              'begin_membership': begin_membership},
                                  processor=processor)
    else:
        room = get_room(building_id, level, room_number)

        if birthdate:
            user.birthdate = birthdate

        if begin_membership:
            if user.member_of(config.external_group):
                remove_member_of(user, config.external_group, processor,
                                 closedopen(session.utcnow(), None))

            for group in {config.member_group, config.network_access_group}:
                if not user.member_of(group):
                    make_member_of(user, group, processor, closed(session.utcnow(), None))

        if room:
            user.room = room
            user.address = room.address

            if mac and user.birthdate:
                interface_existing = Interface.q.filter_by(mac=mac).first()

                if interface_existing is not None:
                    if host_annex:
                        host_existing = interface_existing.host
                        host_existing.owner_id = user.id

                        session.session.add(host_existing)
                        migrate_user_host(host_existing, user.room, processor)
                    else:
                        raise MacExistsException
                else:
                    new_host = Host(owner=user, room=room)
                    session.session.add(new_host)
                    session.session.add(Interface(mac=mac, host=new_host))
                    setup_ipv4_networking(new_host)

        msg = deferred_gettext(u"Moved in: {room}")

        log_user_event(author=processor,
                       message=msg.format(room=room.short_name).to_json(),
                       user=user)

        return user
Ejemplo n.º 5
0
def move_in(user: User,
            building_id: int,
            level: int,
            room_number: str,
            mac: str | None,
            processor: User | None = None,
            birthdate: date = None,
            host_annex: bool = False,
            begin_membership: bool = True,
            when: datetime | None = None):
    """Move in a user in a given room and do some initialization.

    The user is given a new Host with an interface of the given mac, a
    UnixAccount, a finance Account, and is made member of important
    groups.  Networking is set up.

    :param User user: The user to move in
    :param building_id:
    :param level:
    :param room_number:
    :param mac: The mac address of the users pc.
    :param processor:
    :param birthdate: Date of birth`
    :param host_annex: when true: if MAC already in use,
        annex host to new user
    :param begin_membership: Starts a membership if true
    :param when: The date at which the user should be moved in

    :return: The user object.
    """

    if when and when > session.utcnow():
        task_params = UserMoveInParams(building_id=building_id,
                                       level=level,
                                       room_number=room_number,
                                       mac=mac,
                                       birthdate=birthdate,
                                       host_annex=host_annex,
                                       begin_membership=begin_membership)
        return schedule_user_task(task_type=TaskType.USER_MOVE_IN,
                                  due=when,
                                  user=user,
                                  parameters=task_params,
                                  processor=processor)
    if user.room is not None:
        raise ValueError("user is already living in a room.")

    room = get_room(building_id, level, room_number)

    if birthdate:
        user.birthdate = birthdate

    if begin_membership:
        for group in {config.external_group, config.pre_member_group}:
            if user.member_of(group):
                remove_member_of(user, group, processor,
                                 closedopen(session.utcnow(), None))

        for group in {config.member_group, config.network_access_group}:
            if not user.member_of(group):
                make_member_of(user, group, processor,
                               closed(session.utcnow(), None))

    if room:
        user.room = room
        user.address = room.address

        if mac and user.birthdate:
            interface_existing = Interface.q.filter_by(mac=mac).first()

            if interface_existing is not None:
                if host_annex:
                    host_existing = interface_existing.host
                    host_existing.owner_id = user.id

                    session.session.add(host_existing)
                    migrate_user_host(host_existing, user.room, processor)
                else:
                    raise MacExistsException
            else:
                new_host = Host(owner=user, room=room)
                session.session.add(new_host)
                session.session.add(Interface(mac=mac, host=new_host))
                setup_ipv4_networking(new_host)

    user_send_mail(user, UserMovedInTemplate(), True)

    msg = deferred_gettext("Moved in: {room}")

    log_user_event(author=processor if processor is not None else user,
                   message=msg.format(room=room.short_name).to_json(),
                   user=user)

    return user
Ejemplo n.º 6
0
Archivo: user.py Proyecto: JuKu/pycroft
def move_in(user,
            building,
            level,
            room_number,
            mac,
            processor,
            birthdate=None,
            traffic_group_id=None,
            host_annex=False,
            begin_membership=True):
    """Create a new user in a given room and do some initialization.

    The user is given a new Host with an interface of the given mac, a
    UnixAccount, a finance Account, and is made member of important
    groups.  Networking is set up.

    :param User user: The user to move in
    :param Building building: See :py:func:`create_member`
    :param int level: See :py:func:`create_member`
    :param str room_number: See :py:func:`create_member`
    :param str mac: The mac address of the users pc.
    :param User processor: See :py:func:`create_member
    :param Date birthdate: Date of birth`
    :param int traffic_group_id: the id of the chosen traffic group to
        be used instead of the building's default one.
    :param bool host_annex: when true: if MAC already in use,
        annex host to new user
    :param bool begin_membership: Starts a membership if true
    :return: The user object.
    """

    room = Room.q.filter_by(number=room_number, level=level,
                            building=building).one()

    user.room = room

    if birthdate:
        user.birthdate = birthdate

    if begin_membership:
        if user.member_of(config.external_group):
            remove_member_of(user, config.external_group, processor,
                             closedopen(session.utcnow(), None))

        for group in {config.member_group, config.network_access_group}:
            if not user.member_of(group):
                make_member_of(user, group, processor,
                               closed(session.utcnow(), None))

    interface_existing = Interface.q.filter_by(mac=mac).first()

    if interface_existing is not None:
        if host_annex:
            host_existing = interface_existing.host
            host_existing.owner_id = user.id

            session.session.add(host_existing)
            migrate_user_host(host_existing, user.room, processor)
        else:
            raise MacExistsException
    else:
        new_host = Host(owner=user, room=room)
        session.session.add(new_host)
        session.session.add(Interface(mac=mac, host=new_host))
        setup_ipv4_networking(new_host)

    setup_traffic_group(user, processor, traffic_group_id)
    try:
        grant_initial_credit(user)
    except NoTrafficGroup as e:
        raise ValueError("User {} could not be assigned a traffic group. "
                         "Please specify one manually.".format(user)) from e

    msg = deferred_gettext(u"Moved in: {dorm} {level}-{room}")

    log_user_event(author=processor,
                   message=msg.format(dorm=building.short_name,
                                      level=level,
                                      room=room_number).to_json(),
                   user=user)

    return user
Ejemplo n.º 7
0
def host_edit(host_id):
    if (host := Host.get(host_id)) is None:
        flash("Host existiert nicht.", 'error')
        abort(404)
Ejemplo n.º 8
0
def interface_create(host_id):
    if (host := Host.get(host_id)) is None:
        flash("Host existiert nicht.", 'error')
        abort(404)
Ejemplo n.º 9
0
def host_interfaces_json(host_id):
    if (host := Host.get(host_id)) is None:
        flash("Host existiert nicht.", 'error')
        abort(404)