Esempio n. 1
0
def doAuth(username, password):
    """authenticates the user
    this function will also disconnect the current user
    if the user to be authenticated has a show registered.
    if that happened this function will print false to the
    user since we need a graceperiod to actually disconnect
    the other user.
    
    Keyword arguments:
    username
    password
    
    """
    if username == 'source':
        username, password = password.split(username_delimiter)
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            if kick():
                logger.info('kicking user')
                sys.stdout.write('false')
                return
        logger.info('accepted auth for %s' %(username,))
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('rejected auth for %s (invalid password)' %(username,))
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('rejected auth for %s (invalid user)' %(username,))
        sys.stdout.write('false')
    rfk.database.session.commit()
Esempio n. 2
0
def doAuth(username, password):
    """authenticates the user
    this function will also disconnect the current user
    if the user to be authenticated has a show registered.
    if that happened this function will print false to the
    user since we need a graceperiod to actually disconnect
    the other user.
    
    Keyword arguments:
    username
    password
    
    """
    if username == 'source':
        try:
            username, password = password.split(username_delimiter)
        except ValueError:
            pass
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            if kick():
                logger.info('kicking user')
                sys.stdout.write('false')
                return
        logger.info('accepted auth for %s' % (username,))
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('rejected auth for %s (invalid password)' % (username,))
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('rejected auth for %s (invalid user)' % (username,))
        sys.stdout.write('false')
    rfk.database.session.commit()
Esempio n. 3
0
def init_show(user):
    """Initializes a show

        it either takes a planned show or an unplanned show if it's still running
        if non of them is found a new unplanned show is added and initialized
        if a new show was initialized the old one will be ended and the streamer status will be resetted
    """

    show = Show.get_current_show(user)
    if show is None:
        show = Show()
        if user.get_setting(code='use_icy'):
            show.add_tags(
                Tag.parse_tags(user.get_setting(code='icy_show_genre') or ''))
            show.description = user.get_setting(
                code='icy_show_description') or ''
            show.name = user.get_setting(code='icy_show_name') or ''
        else:
            show.add_tags(
                Tag.parse_tags(user.get_setting(code='show_def_tags') or ''))
            show.description = user.get_setting(code='show_def_desc') or ''
            show.name = user.get_setting(code='show_def_name') or ''
        show.logo = user.get_setting(code='show_def_logo') or None
        show.flags = Show.FLAGS.UNPLANNED
        show.add_user(user)
    elif show.flags == Show.FLAGS.UNPLANNED:
        # just check if there is a planned show to transition to
        s = Show.get_current_show(user, only_planned=True)
        if s is not None:
            show = s
    us = show.get_usershow(user)
    us.status = UserShow.STATUS.STREAMING
    rfk.database.session.commit()
    unfinished_shows = UserShow.query.filter(
        UserShow.status == UserShow.STATUS.STREAMING,
        UserShow.show != show).all()
    for us in unfinished_shows:
        if us.show.flags & Show.FLAGS.UNPLANNED:
            us.show.end_show()
        if us.status == UserShow.STATUS.STREAMING:
            us.status = UserShow.STATUS.STREAMED
        rfk.database.session.commit()
    return show
Esempio n. 4
0
def init_show(user):
    """inititalizes a show
        it either takes a planned show or an unplanned show if it's still running
        if non of them is found a new unplanned show is added and initialized
        if a new show was initialized the old one will be ended and the streamer staus will be resettet
    """
    logger.info("init_show: entering")
    logger.info("init_show: user {}".format(str(user)))
    show = Show.get_current_show(user)
    if show is None:
        logger.info("init_show: None")
        show = Show()
        if user.get_setting(code='use_icy'):
            show.add_tags(Tag.parse_tags(user.get_setting(code='icy_show_genre') or ''))
            show.description = user.get_setting(code='icy_show_description') or ''
            show.name = user.get_setting(code='icy_show_name') or ''
        else:
            show.add_tags(Tag.parse_tags(user.get_setting(code='show_def_tags') or ''))
            show.description = user.get_setting(code='show_def_desc') or ''
            show.name = user.get_setting(code='show_def_name') or ''
        show.flags = Show.FLAGS.UNPLANNED
        show.add_user(user)
    elif show.flags == Show.FLAGS.UNPLANNED:
        logger.info("init_show: UNPLANNED")
        #just check if there is a planned show to transition to
        s = Show.get_current_show(user, only_planned=True)
        if s is not None:
            logger.info("init_show: found planned")
            show = s        
    us = show.get_usershow(user)
    us.status = UserShow.STATUS.STREAMING
    rfk.database.session.flush()
    unfinished_shows = UserShow.query.filter(UserShow.status == UserShow.STATUS.STREAMING,
                                             UserShow.show != show).all()
    for us in unfinished_shows:
        if us.show.flags & Show.FLAGS.UNPLANNED:
            us.show.end_show()
        if us.status == UserShow.STATUS.STREAMING:
           us.status = UserShow.STATUS.STREAMED
        rfk.database.session.flush() 
    return show
Esempio n. 5
0
def liquidsoap_auth():
    """Authenticates a user

    This function will also disconnect the current user
    if the user to be authenticated has a show registered.
    If that happens this function will print false to the
    user since we need a grace period to actually disconnect
    the other user. Which means that the user has to reconnect!

    Keyword arguments:
        - username
        - password
    """

    data = request.get_json()
    username, password = data['username'], data['password']

    if username == 'source':
        try:
            username, password = password.split(username_delimiter)
        except ValueError:
            pass
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            logger.info('liquidsoap_auth: cleaning harbor because of planned show')
            if kick():
                logger.info('liquidsoap_auth: harbor is now clean, reconnect pl0x')
                session.commit()
                return 'false'
            else:
                logger.info('liquidsoap_auth: harbor was empty, go ahead')
        logger.info('liquidsoap_auth: accepted auth for %s' % username)
        session.commit()
        return 'true'
    except rexc.base.InvalidPasswordException:
        logger.info('liquidsoap_auth: rejected auth for %s (invalid password)' % username)
        session.commit()
        return 'false'
    except rexc.base.UserNotFoundException:
        logger.info('liquidsoap_auth: rejected auth for %s (invalid user)' % username)
        session.commit()
        return 'false'
Esempio n. 6
0
def doAuth(username, password):
    """Authenticates a user

    This function will also disconnect the current user
    if the user to be authenticated has a show registered.
    If that happens this function will print false to the
    user since we need a grace period to actually disconnect
    the other user. (Which means that the user has to reconnect.)
    
    Keyword arguments:
        - username
        - password
    """

    if username == 'source':
        try:
            username, password = password.split(username_delimiter)
        except ValueError:
            pass
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            logger.info('doAuth: cleaning harbor because of planned show')
            if kick():
                sys.stdout.write('false')
                logger.info('doAuth: harbor is now clean, reconnect pl0x')
                rfk.database.session.commit()
                return
            else:
                logger.info('doAuth: harbor was empty, go ahead')
        logger.info('doAuth: accepted auth for %s' % username)
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('doAuth: rejected auth for %s (invalid password)' % username)
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('doAuth: rejected auth for %s (invalid user)' % username)
        sys.stdout.write('false')

    rfk.database.session.commit()
def doAuth(username, password):
    """Authenticates a user

    This function will also disconnect the current user
    if the user to be authenticated has a show registered.
    If that happens this function will print false to the
    user since we need a grace period to actually disconnect
    the other user. (Which means that the user has to reconnect.)
    
    Keyword arguments:
        - username
        - password
    """

    if username == 'source':
        try:
            username, password = password.split(username_delimiter)
        except ValueError:
            pass
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            logger.info('cleaning harbor')
            if kick():
                sys.stdout.write('false')
                logger.info('harbor is now clean, reconnect pl0x')
                rfk.database.session.commit()
                return
            else:
                logger.info('harbor was empty, go ahead')
        logger.info('accepted auth for %s' % (username))
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('rejected auth for %s (invalid password)' % (username))
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('rejected auth for %s (invalid user)' % (username))
        sys.stdout.write('false')

    rfk.database.session.commit()