Esempio n. 1
0
	def add_anonymous(self, sid):
		# Here we'll erase any extra records for the same IP address (shouldn't happen but you never know, especially
		# if the system gets a reset).  There is a small flaw here; there's a chance we'll pull in 2 clients with the same client ID.
		# I (rmcauley) am classifying this as "collatoral damage" - an anon user who is actively using the website
		# can re-tune-in on the small chance that this occurs.
		records = db.c.fetch_list("SELECT listener_icecast_id FROM r4_listeners WHERE listener_ip = %s", (self.get_argument("ip"),))
		if len(records) == 0:
			db.c.update("INSERT INTO r4_listeners "
					"(sid, listener_ip, user_id, listener_relay, listener_agent, listener_icecast_id) "
					"VALUES (%s, %s, %s, %s, %s, %s)",
				(sid, self.get_argument("ip"), 1, self.relay, self.get_argument("agent"), self.get_argument("client")))
			sync_to_front.sync_frontend_ip(self.get_argument("ip"))
			self.append("Anonymous user from IP %s is now tuned in with record." % self.get_argument("ip"))
			self.failed = False
		else:
			# Keep one valid entry on file for the listener by popping once
			records.pop()
			# Erase the rest
			while len(records) > 1:
				db.c.update("DELETE FROM r4_listeners WHERE listener_icecast_id = %s", (records.pop(),))
				log.debug("ldetect", "Deleted extra record for icecast ID %s from IP %s." % (self.get_argument("client"), self.get_argument("ip")))
			db.c.update("UPDATE r4_listeners SET listener_icecast_id = %s, listener_purge = FALSE WHERE listener_ip = %s", (self.get_argument("client"), self.get_argument("ip")))
			self.append("Anonymous user from IP %s record updated." % self.get_argument("ip"))
			self.failed = False
		sync_to_front.sync_frontend_ip(self.get_argument("ip"))
Esempio n. 2
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
Esempio n. 3
0
    def post(self, sid=0):  #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:
            # 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_ip(listener['listener_ip'])
        self.append(
            "%s remove: %s %s." %
            ('{:<5}'.format(listener['user_id']), '{:<15}'.format(
                self.relay), '{:<10}'.format(self.get_argument("client"))))
        self.failed = False
Esempio 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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
 def add_anonymous(self, sid):
     # Here we'll erase any extra records for the same IP address (shouldn't happen but you never know, especially
     # if the system gets a reset).  There is a small flaw here; there's a chance we'll pull in 2 clients with the same client ID.
     # I (rmcauley) am classifying this as "collatoral damage" - an anon user who is actively using the website
     # can re-tune-in on the small chance that this occurs.
     records = db.c.fetch_list(
         "SELECT listener_icecast_id FROM r4_listeners WHERE listener_ip = %s AND user_id = 1",
         (self.get_argument("ip"), ))
     if len(records) == 0:
         db.c.update(
             "INSERT INTO r4_listeners "
             "(sid, listener_ip, user_id, listener_relay, listener_agent, listener_icecast_id) "
             "VALUES (%s, %s, %s, %s, %s, %s)",
             (sid, self.get_argument("ip"), 1, self.relay,
              self.get_argument("agent"), self.get_argument("client")))
         sync_to_front.sync_frontend_ip(self.get_argument("ip"))
         self.append(
             "%s new   : %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.failed = False
     else:
         # Keep one valid entry on file for the listener by popping once
         records.pop()
         # Erase the rest
         while len(records) > 1:
             db.c.update(
                 "DELETE FROM r4_listeners WHERE listener_icecast_id = %s",
                 (records.pop(), ))
             log.debug(
                 "ldetect",
                 "Deleted extra record for icecast ID %s from IP %s." %
                 (self.get_argument("client"), self.get_argument("ip")))
         db.c.update(
             "UPDATE r4_listeners SET listener_icecast_id = %s, listener_purge = FALSE, listener_relay = %s WHERE listener_ip = %s",
             (self.get_argument("client"), self.get_argument("ip"),
              self.relay))
         self.append(
             "%s update: %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.failed = False
     sync_to_front.sync_frontend_ip(self.get_argument("ip"))