コード例 #1
0
ファイル: mainwin.py プロジェクト: blu25/LaserQueue
def main():
	global calculated_time, elapsed_time
	queue = Queue()
	estimateT = threading.Thread(target=getestimate)
	# elapsedT = threading.Thread(target=getelapsed)
	estimateT.start()
	# elapsedåT.start()
	temppath = os.path.expanduser(os.path.join("~", "AppData", "Local", "Temp"))
	lelap, lcalc = elapsed_time, calculated_time

	json.dump({}, open(os.path.join(temppath, "toscript.json"), "w"))

	while True:
		if os.path.exists(os.path.join(temppath, "toscript.json")):
			dataf = open(os.path.join(temppath, "toscript.json"))
			datat = dataf.read()
			try:
				data = json.loads(datat)
				if data and data["action"] != null:
					print(data)
			except:
				if "action" in data and data["action"] != "null":
					print(datat)
			if data:
				try:
					comm.parseData(queue, data)
				except: pass
				json.dump(comm.generateData(queue, calculated_time, elapsed_time), open(os.path.join(temppath, "topage.json"), "w"))
				json.dump({}, open(os.path.join(temppath, "toscript.json"), "w"), {})
				if data["action"] != "null": print(queue.queue)
		elif lelap != elapsed_time or lcalc != calculated_time:
			json.dump(open(os.path.join(temppath, "topage.json"), "w"), comm.generateData(queue, calculated_time, elapsed_time))
コード例 #2
0
ファイル: main.py プロジェクト: disegnovitruviano/LaserQueue
def process(data):
	global queue, shamed, sessions
	if data:
		try:
			queue.metapriority()
			x = comm.parseData(queue, sessions, data)
			if "action" in data and data["action"] != "null":
				sessions.update()
				if args.backup:
					json.dump(queue.queue, open("cache.json", "w"), indent=2)
					sids.cache(sessions)
			if x and type(x) is str:
				if x == "uuddlrlrba":
					if config["easter_eggs"]:
						serveToAllConnections({"action":"rickroll"})
					else:
						cprint(bcolors.YELLOW + "This is a serious establishment, son. I'm dissapointed in you.")
				elif x == "refresh":
					if config["allow_force_refresh"]:
						serveToAllConnections({"action":"refresh"})
					else:
						cprint(bcolors.YELLOW + "Force refresh isn't enabled. (config.json, allow_force_refresh)")
				elif x == "sorry":
					if data["sid"][:int(len(data["sid"])/2)] in shamed:
						shamed.remove(data["sid"][:int(len(data["sid"])/2)])
				else:
					cprint(bcolors.YELLOW + x)
				time.sleep(0.2)
			else:
				if x is False:
					shamed.append(data["sid"][:int(len(data["sid"])/2)])
				return comm.generateData(queue, sessions, shamed)
		except Exception as e: 
			cprint(bcolors.YELLOW + str(e))
コード例 #3
0
def process(data, ws):
    """
	Process data from an incoming socket, and serve the result to everyone.
	"""
    global queue, sessions, socks, queuehash
    if data:
        # Parse the data through the socket command handler
        x = comm.parseData(queue, ws, socks, sessions, data)
        # Back up the queue
        if args.backup:
            json.dump(queue.queue,
                      open("cache.json", "w"),
                      indent=2,
                      sort_keys=True)
        # If the socket handler had an error, report it to the socket
        if x and type(x) is str:
            serve_connection(
                {
                    "action": "notification",
                    "title": "Failed to process data",
                    "text": x
                }, ws)
            color_print(x, color=ansi_colors.YELLOW)
        # If the queue changed, serve it
        if queuehash != hash(str(queue.queue)):
            queuehash = hash(str(queue.queue))
            serve_connections(comm.generateData(queue.serialize()), socks)
コード例 #4
0
def upkeep():
    """
	Thread to perform tasks asynchronously.
	"""
    global socks, queue, authed, sessions, queuehash, pluginUpkeeps
    while True:
        try:
            # Keep everything in line
            sessions.update()
            # Deauth everyone who dropped from auth
            newauths = sessions.allauth()
            if authed != newauths:
                deauthed = [i for i in authed if i not in newauths]
                authed = sessions.allauth()
                for i in deauthed:
                    ws = socks[i]
                    if ws:
                        serve_connection({"action": "deauthed"}, ws)
            # Remove closed socks
            for i in socks:
                if not i.open:
                    sessions.sids.remove(sessions._get(get_sec_key(i)))

            for module in pluginUpkeeps:
                try:
                    module.upkeep(queue=queue,
                                  sessions=sessions,
                                  sockets=socks)
                except:
                    color_print(format_traceback(
                        e,
                        format("Error while processing {plugin}.upkeep:",
                               plugin=module.__name__)),
                                color=ansi_colors.YELLOW)
                    pluginUpkeeps.remove(module)

            # If the queue changed, serve it
            queue.metapriority()
            if queuehash != hash(str(queue.queue)):
                queuehash = hash(str(queue.queue))
                serve_connections(comm.generateData(queue.serialize()), socks)

            time.sleep(config["refreshRate"] / 1000)
        except Exception as e:  # Error reporting
            color_print(format_traceback(e, "Error in upkeep thread:"),
                        color=ansi_colors.YELLOW)
コード例 #5
0
def server(websocket, path):
    """
	The process that's spawned for each websocket connection.
	"""
    global queue, socks, sessions
    # Allow all processes to serve to this
    socks.append(websocket)
    # Serve the latest queue to this socket
    serve_connection(comm.generateData(queue.serialize()), websocket)
    while True:
        # Get the latest message
        message = yield from websocket.recv()
        # Kill off the connection if the socket is broken
        if not message: break
        try:
            # Load the message
            messagedata = json.loads(message)
            # Only use messages if they have an action
            if "action" in messagedata:
                # Make a form of the message used only for display
                displaymessage = message[:]
                if "pass" in messagedata:
                    displaymessage = json.loads(displaymessage)
                    # Replace the password with asterisks
                    displaymessage["pass"] = "******" * len(displaymessage["pass"])
                    displaymessage = json.dumps(displaymessage, sort_keys=True)
                authstate = sessions.check(get_sec_key(websocket))
                color = ansi_colors.MAGENTA if authstate and args.loud else ""
                color_print(displaymessage, color=color)
                # Run the processing subroutine
                process(messagedata, websocket)
        except Exception as e:  # Error reporting
            color_print(format_traceback(e, "Error while serving WebSockets:"),
                        color=ansi_colors.YELLOW)
            if config["send_notifications"]:
                serve_connection(
                    {  # Tell the socket about it
                        "action": "notification",
                        "title": type(e).__name__,
                        "text": str(e)
                    },
                    websocket)
    # Make sure processes don't serve to a dead socket
    socks.remove(websocket)
コード例 #6
0
ファイル: main.py プロジェクト: LaserQueue/LaserQueue
def server(websocket, path):
	"""
	The process that's spawned for each websocket connection.
	"""
	global queue, socks, sessions
	# Allow all processes to serve to this
	socks.append(websocket)
	# Serve the latest queue to this socket
	serve_connection(comm.generateData(queue.serialize()), websocket)
	while True:
		# Get the latest message
		message = yield from websocket.recv()
		# Kill off the connection if the socket is broken
		if not message: break
		try:
			# Load the message
			messagedata = json.loads(message)
			# Only use messages if they have an action
			if "action" in messagedata:
				# Make a form of the message used only for display
				displaymessage = message[:]
				if "pass" in messagedata:
					displaymessage = json.loads(displaymessage)
					# Replace the password with asterisks
					displaymessage["pass"] = "******"*len(displaymessage["pass"])
					displaymessage = json.dumps(displaymessage, sort_keys=True)
				authstate = sessions.check(get_sec_key(websocket))
				color = ansi_colors.MAGENTA if authstate and args.loud else ""
				color_print(displaymessage, color=color)
				# Run the processing subroutine
				process(messagedata, websocket)
		except Exception as e: # Error reporting
			color_print(format_traceback(e, "Error while serving WebSockets:"), color=ansi_colors.YELLOW)
			if config["send_notifications"]:
				serve_connection({ # Tell the socket about it
						"action": "notification",
						"title": type(e).__name__,
						"text": str(e)
					}, websocket)
	# Make sure processes don't serve to a dead socket
	socks.remove(websocket)
コード例 #7
0
ファイル: main.py プロジェクト: LaserQueue/LaserQueue
def upkeep():
	"""
	Thread to perform tasks asynchronously.
	"""
	global socks, queue, authed, sessions, queuehash, pluginUpkeeps
	while True:
		try:
			# Keep everything in line
			sessions.update()
			# Deauth everyone who dropped from auth
			newauths = sessions.allauth()
			if authed != newauths:
				deauthed = [i for i in authed if i not in newauths]
				authed = sessions.allauth()
				for i in deauthed:
					ws = socks[i]
					if ws:
						serve_connection({"action":"deauthed"}, ws)
			# Remove closed socks
			for i in socks:
				if not i.open:
					sessions.sids.remove(sessions._get(get_sec_key(i)))

			for module in pluginUpkeeps:
				try:
					module.upkeep(queue=queue, sessions=sessions, sockets=socks)
				except:
					color_print(format_traceback(e, format("Error while processing {plugin}.upkeep:", plugin=module.__name__)), color=ansi_colors.YELLOW)
					pluginUpkeeps.remove(module)

			# If the queue changed, serve it
			queue.metapriority()
			if queuehash != hash(str(queue.queue)):
				queuehash = hash(str(queue.queue))
				serve_connections(comm.generateData(queue.serialize()), socks)

			time.sleep(config["refreshRate"]/1000)
		except Exception as e: # Error reporting
			color_print(format_traceback(e, "Error in upkeep thread:"), color=ansi_colors.YELLOW)
コード例 #8
0
ファイル: main.py プロジェクト: LaserQueue/LaserQueue
def process(data, ws):
	"""
	Process data from an incoming socket, and serve the result to everyone.
	"""
	global queue, sessions, socks, queuehash
	if data:
		# Parse the data through the socket command handler
		x = comm.parseData(queue, ws, socks, sessions, data)
		# Back up the queue
		if args.backup:
			json.dump(queue.queue, open("cache.json", "w"), indent=2, sort_keys=True)
		# If the socket handler had an error, report it to the socket
		if x and type(x) is str:
			serve_connection({
					"action": "notification",
					"title": "Failed to process data",
					"text": x
				}, ws)
			color_print(x, color=ansi_colors.YELLOW)
		# If the queue changed, serve it
		if queuehash != hash(str(queue.queue)):
			queuehash = hash(str(queue.queue))
			serve_connections(comm.generateData(queue.serialize()), socks)