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()
def doConnect(data): """handles a connect from liquidsoap Keyword arguments: data -- list of headers """ logger.info('connect request %s' % (json.dumps(data),)) try: auth = data['Authorization'].strip().split(' ') if auth[0].lower() == 'basic': username, password = base64.b64decode(auth[1]).split(':', 1) if username == 'source': username, password = password.split(username_delimiter, 1) else: raise ValueError user = User.authenticate(username, password) if user.get_setting(code='use_icy'): if 'ice-genre' in data: user.set_setting(data['ice-genre'],code='icy_show_genre') if 'ice-name' in data: user.set_setting(data['ice-name'],code='icy_show_name') if 'ice-description' in data: user.set_setting(data['ice-description'],code='icy_show_description') show = init_show(user) rfk.database.session.commit() logger.info('accepted connect for %s' %(user.username,)) print user.user except (rexc.base.UserNotFoundException, rexc.base.InvalidPasswordException, KeyError): logger.info('rejected connect') kick()
def doConnect(data): """Handles a connect from liquidsoap Keyword arguments: data -- list of headers """ # better to not store any passwords in our logs safe_dump = data.copy() safe_dump.pop('Authorization', None) logger.info('doConnect: connect request %s' % (json.dumps(safe_dump), )) rfk.database.session.commit() try: auth = data['Authorization'].strip().split(' ') if auth[0].lower() == 'basic': try: username, password = base64.b64decode( auth[1]).decode('utf-8').split(':', 1) except UnicodeDecodeError: username, password = base64.b64decode( auth[1]).decode('latin-1').split(':', 1) if username == 'source': username, password = password.split(username_delimiter, 1) else: raise ValueError user = User.authenticate(username, password) if user.get_setting(code='use_icy'): if 'ice-genre' in data: user.set_setting(data['ice-genre'], code='icy_show_genre') if 'ice-name' in data: user.set_setting(data['ice-name'], code='icy_show_name') if 'ice-description' in data: user.set_setting(data['ice-description'], code='icy_show_description') show = init_show(user) logger.info('doConnect: accepted connect for %s' % (user.username, )) print user.user except (rexc.base.UserNotFoundException, rexc.base.InvalidPasswordException, KeyError): logger.info('doConnect: rejected connect, initiate kick...') kick() rfk.database.session.commit()
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'
def doConnect(data): """Handles a connect from liquidsoap Keyword arguments: data -- list of headers """ publish_show = False # better to not store any passwords in our logs safe_dump = data.copy() safe_dump.pop('Authorization', None) logger.info('doConnect: connect request %s' % (json.dumps(safe_dump),)) rfk.database.session.commit() try: auth = data['Authorization'].strip().split(' ') if auth[0].lower() == 'basic': try: username, password = base64.b64decode(auth[1]).decode('utf-8').split(':', 1) except UnicodeDecodeError: username, password = base64.b64decode(auth[1]).decode('latin-1').split(':', 1) if username == 'source': username, password = password.split(username_delimiter, 1) else: raise ValueError user = User.authenticate(username, password) if user.get_setting(code='use_icy'): if 'ice-genre' in data: user.set_setting(data['ice-genre'], code='icy_show_genre') if 'ice-name' in data: user.set_setting(data['ice-name'], code='icy_show_name') if 'ice-description' in data: user.set_setting(data['ice-description'], code='icy_show_description') show = init_show(user) publish_show = show.show logger.info('doConnect: accepted connect for %s' % (user.username,)) print user.user except (rexc.base.UserNotFoundException, rexc.base.InvalidPasswordException, KeyError): logger.info('doConnect: rejected connect, initiate kick...') kick() rfk.database.session.commit() publish.show_change(publish_show)
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()