Ejemplo n.º 1
0
    def post(self, sid=0):
        listener = db.c.fetch_row(
            "SELECT user_id, listener_key FROM r4_listeners WHERE listener_relay = %s AND listener_icecast_id = %s",
            (self.relay, self.get_argument("client")),
        )
        if not listener:
            # removal not working is normal, since any reconnecting listener gets a new listener ID
            # self.append("      RMFAIL: %s %s." % ('{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client"))))
            return

        db.c.update(
            "UPDATE r4_listeners SET listener_purge = TRUE WHERE listener_relay = %s AND listener_icecast_id = %s",
            (self.relay, self.get_argument("client")),
        )
        if listener["user_id"] > 1:
            db.c.update(
                "UPDATE r4_request_line SET line_expiry_tune_in = %s WHERE user_id = %s",
                (timestamp() + 600, listener["user_id"]),
            )
            cache.set_user(listener["user_id"], "listener_record", None)
            sync_to_front.sync_frontend_user_id(listener["user_id"])
        else:
            sync_to_front.sync_frontend_key(listener["listener_key"])
        self.append("%s remove: %s %s." % (
            "{:<5}".format(listener["user_id"]),
            "{:<15}".format(self.relay),
            "{:<10}".format(self.get_argument("client")),
        ))
        self.failed = False
Ejemplo n.º 2
0
	def add_registered(self, sid):
		real_key = db.c.fetch_var("SELECT radio_listenkey FROM phpbb_users WHERE user_id = %s", (self.user_id,))
		if real_key != self.listen_key:
			raise APIException("invalid_argument", reason="mismatched listen_key.")
		tunedin = db.c.fetch_var("SELECT COUNT(*) FROM r4_listeners WHERE user_id = %s", (self.user_id,))
		if tunedin:
			db.c.update(
				"UPDATE r4_listeners "
				"SET sid = %s, listener_ip = %s, listener_purge = FALSE, listener_icecast_id = %s, listener_relay = %s, listener_agent = %s "
				"WHERE user_id = %s",
				(sid, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent, self.user_id))
			self.append("Registered user %s record updated to be tuned in to %s." % (self.user_id, sid))
			self.failed = False
		else:
			db.c.update("INSERT INTO r4_listeners "
				"(sid, user_id, listener_ip, listener_icecast_id, listener_relay, listener_agent) "
				"VALUES (%s, %s, %s, %s, %s, %s)",
				(sid, self.user_id, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent))
			self.append("Registered user %s is now tuned in." % self.user_id)
			self.failed = False
		if not self.failed:
			u = user.User(self.user_id)
			u.get_listener_record(use_cache=False)
			if u.has_requests():
				u.put_in_request_line(sid)
		sync_to_front.sync_frontend_user_id(self.user_id)
Ejemplo n.º 3
0
    def post(self, sid):
        listener = db.c.fetch_row(
            "SELECT user_id, listener_ip FROM r4_listeners WHERE listener_relay = %s AND listener_icecast_id = %s",
            (self.relay, self.get_argument("client")))
        if not listener:
            return self.append(
                "No user record to delete for client %s on relay %s." %
                (self.get_argument("client"), self.relay))

        db.c.update(
            "UPDATE r4_listeners SET listener_purge = TRUE WHERE listener_relay = %s AND listener_icecast_id = %s",
            (self.relay, self.get_argument("client")))
        if listener['user_id'] > 1:
            self.append("Registered user ID %s flagged for removal." %
                        (listener['user_id'], ))
            db.c.update(
                "UPDATE r4_request_line SET line_expiry_tune_in = %s WHERE user_id = %s",
                (time.time() + 600, listener['user_id']))
            cache.set_user(listener['user_id'], "listener_record", None)
            sync_to_front.sync_frontend_user_id(listener['user_id'])
        else:
            self.append(
                "Anonymous user, client ID %s relay %s flagged for removal." %
                (self.get_argument("client"), self.relay))
            sync_to_front.sync_frontend_ip(listener['listener_ip'])
        self.failed = False
Ejemplo n.º 4
0
    def post(self, sid):
        listener = db.c.fetch_row(
            "SELECT user_id, listener_ip FROM r4_listeners WHERE listener_relay = %s AND listener_icecast_id = %s",
            (self.relay, self.get_argument("client")))
        if not listener:
            self.append("      RMFAIL: %s %s %s." % (sid, '{:<15}'.format(
                self.relay), '{:<10}'.format(self.get_argument("client"))))
            return

        db.c.update(
            "UPDATE r4_listeners SET listener_purge = TRUE WHERE listener_relay = %s AND listener_icecast_id = %s",
            (self.relay, self.get_argument("client")))
        if listener['user_id'] > 1:
            db.c.update(
                "UPDATE r4_request_line SET line_expiry_tune_in = %s WHERE user_id = %s",
                (time.time() + 600, listener['user_id']))
            cache.set_user(listener['user_id'], "listener_record", None)
            sync_to_front.sync_frontend_user_id(listener['user_id'])
        else:
            sync_to_front.sync_frontend_ip(listener['listener_ip'])
        self.append(
            "%s remove: %s %s %s." %
            ('{:<5}'.format(listener['user_id']), sid, '{:<15}'.format(
                self.relay), '{:<10}'.format(self.get_argument("client"))))
        self.failed = False
Ejemplo n.º 5
0
	def add_registered(self, sid):
		real_key = db.c.fetch_var("SELECT radio_listenkey FROM phpbb_users WHERE user_id = %s", (self.user_id,))
		if real_key != self.listen_key:
			raise APIException("invalid_argument", reason="mismatched listen_key.")
		tunedin = db.c.fetch_var("SELECT COUNT(*) FROM r4_listeners WHERE user_id = %s", (self.user_id,))
		if tunedin:
			db.c.update(
				"UPDATE r4_listeners "
				"SET sid = %s, listener_ip = %s, listener_purge = FALSE, listener_icecast_id = %s, listener_relay = %s, listener_agent = %s "
				"WHERE user_id = %s",
				(sid, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent, self.user_id))
			self.append("%s update: %s %s %s %s %s %s." % ('{:<5}'.format(self.user_id), sid, '{:<15}'.format(self.get_argument("ip")), '{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client")), self.agent, self.listen_key))
			self.failed = False
		else:
			db.c.update("INSERT INTO r4_listeners "
				"(sid, user_id, listener_ip, listener_icecast_id, listener_relay, listener_agent) "
				"VALUES (%s, %s, %s, %s, %s, %s)",
				(sid, self.user_id, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent))
			self.append("%s new   : %s %s %s %s %s %s." % ('{:<5}'.format(self.user_id), sid, '{:<15}'.format(self.get_argument("ip")), '{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client")), self.agent, self.listen_key))
			self.failed = False
		if not self.failed:
			u = user.User(self.user_id)
			u.get_listener_record(use_cache=False)
			if u.has_requests():
				u.put_in_request_line(sid)
		sync_to_front.sync_frontend_user_id(self.user_id)
Ejemplo n.º 6
0
	def post(self, sid):
		listener = db.c.fetch_row("SELECT user_id, listener_ip FROM r4_listeners WHERE listener_relay = %s AND listener_icecast_id = %s",
								 (self.relay, self.get_argument("client")))
		if not listener:
			return self.append("No user record to delete for client %s on relay %s." % (self.get_argument("client"), self.relay))

		db.c.update("UPDATE r4_listeners SET listener_purge = TRUE WHERE listener_relay = %s AND listener_icecast_id = %s", (self.relay, self.get_argument("client")))
		if listener['user_id'] > 1:
			self.append("Registered user ID %s flagged for removal." % (listener['user_id'],))
			db.c.update("UPDATE r4_request_line SET line_expiry_tune_in = %s WHERE user_id = %s", (time.time() + 600, listener['user_id']))
			cache.set_user(listener['user_id'], "listener_record", None)
			sync_to_front.sync_frontend_user_id(listener['user_id'])
		else:
			self.append("Anonymous user, client ID %s relay %s flagged for removal." % (self.get_argument("client"), self.relay))
			sync_to_front.sync_frontend_ip(listener['listener_ip'])
		self.failed = False
Ejemplo n.º 7
0
	def post(self, sid):	#pylint: disable=W0221
		listener = db.c.fetch_row("SELECT user_id, listener_ip FROM r4_listeners WHERE listener_relay = %s AND listener_icecast_id = %s",
								 (self.relay, self.get_argument("client")))
		if not listener:
			self.append("      RMFAIL: %s %s %s." % (sid, '{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client"))))
			return

		db.c.update("UPDATE r4_listeners SET listener_purge = TRUE WHERE listener_relay = %s AND listener_icecast_id = %s", (self.relay, self.get_argument("client")))
		if listener['user_id'] > 1:
			db.c.update("UPDATE r4_request_line SET line_expiry_tune_in = %s WHERE user_id = %s", (time.time() + 600, listener['user_id']))
			cache.set_user(listener['user_id'], "listener_record", None)
			sync_to_front.sync_frontend_user_id(listener['user_id'])
		else:
			sync_to_front.sync_frontend_ip(listener['listener_ip'])
		self.append("%s remove: %s %s %s." % ('{:<5}'.format(listener['user_id']), sid, '{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client"))))
		self.failed = False
Ejemplo n.º 8
0
	def add_registered(self, sid):
		tunedin = db.c.fetch_var("SELECT COUNT(*) FROM r4_listeners WHERE user_id = %s", (self.user_id,))
		if tunedin:
			db.c.update(
				"UPDATE r4_listeners "
				"SET sid = %s, listener_ip = %s, listener_purge = FALSE, listener_icecast_id = %s, listener_relay = %s, listener_agent = %s "
				"WHERE user_id = %s",
				(sid, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent, self.user_id))
			self.append("Registered user %s record updated." % self.user_id)
			self.failed = False
		else:
			db.c.update("INSERT INTO r4_listeners "
				"(sid, user_id, listener_ip, listener_icecast_id, listener_relay, listener_agent) "
				"VALUES (%s, %s, %s, %s, %s, %s)",
				(sid, self.user_id, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent))
			self.append("Registered user %s is now tuned in." % self.user_id)
			self.failed = False
		if not self.failed:
			u = user.User(self.user_id)
			u.get_listener_record(use_cache=False)
			if u.has_requests():
				u.put_in_request_line(sid)
		sync_to_front.sync_frontend_user_id(self.user_id)