summaryrefslogtreecommitdiffstats
path: root/module/remote
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2009-11-26 22:05:11 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2009-11-26 22:05:11 +0100
commit523e2857c47cdef1da6b43523bcf7871ed9e1d63 (patch)
treed70f49afb347c656e90050497a07711cb382f61d /module/remote
parentbasic curses cli (diff)
downloadpyload-523e2857c47cdef1da6b43523bcf7871ed9e1d63.tar.xz
complete new file_list, cleaned up
Diffstat (limited to 'module/remote')
-rw-r--r--module/remote/ClientHandler.py24
-rw-r--r--module/remote/ClientSocket.py63
-rw-r--r--module/remote/RequestHandler.py64
-rw-r--r--module/remote/RequestObject.py18
4 files changed, 0 insertions, 169 deletions
diff --git a/module/remote/ClientHandler.py b/module/remote/ClientHandler.py
deleted file mode 100644
index 9653db9ae..000000000
--- a/module/remote/ClientHandler.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
-authored by: RaNaN
-
-this module handels the incoming requests
-
-"""
-import hashlib
-
-from Crypto.Cipher import Blowfish
-from RequestHandler import RequestHandler
-
-class ClientHandler(RequestHandler):
- def __init__(self, client, pw):
- self.client = client
- key = hashlib.sha256(pw)
- self.bf = Blowfish.new(key.hexdigest(), Blowfish.MODE_ECB)
-
- def proceed(self, data):
- obj = self.decrypt(data)
-
- self.client.data_arrived(obj) \ No newline at end of file
diff --git a/module/remote/ClientSocket.py b/module/remote/ClientSocket.py
deleted file mode 100644
index 0e6a5ed53..000000000
--- a/module/remote/ClientSocket.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
-authored by: RaNaN
-
-socket for connecting to the core's server
-
-"""
-import asynchat
-import asyncore
-import socket
-import threading
-
-from ClientHandler import ClientHandler
-from RequestObject import RequestObject
-
-class SocketThread(threading.Thread):
- def __init__(self, adress, port, pw, client):
- threading.Thread.__init__(self)
- self.setDaemon(True)
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((adress, port))
- self.socket = ClientSocket(sock, pw, client)
- self.start()
-
- def run(self):
- asyncore.loop()
- print "loop closed"
-
- def push_exec(self, function, args=[]):
- obj = RequestObject()
- obj.command = "exec"
- obj.function = function
- obj.args = args
- self.push(obj)
-
- def push(self, obj):
- self.socket.push_obj(obj)
-
-
-class ClientSocket(asynchat.async_chat):
- def __init__(self, sock, pw, client):
- asynchat.async_chat.__init__(self, sock)
- self.data = ""
- self.handler = ClientHandler(client, pw)
- self.set_terminator("\n")
- #self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
-
- def handle_close(self):
- print "Disconnected from", self.getpeername()
- self.close()
-
- def collect_incoming_data(self, data):
- self.data += data
-
- def found_terminator(self):
- self.handler.proceed(self.data)
- self.data = ""
-
- def push_obj(self, obj):
- string = self.handler.encrypt(obj)
- self.push(string) \ No newline at end of file
diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py
deleted file mode 100644
index a879d2297..000000000
--- a/module/remote/RequestHandler.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
-authored by: RaNaN
-
-this module handels the incoming requests
-
-"""
-
-import base64
-import hashlib
-import random
-import string
-
-import cPickle
-from Crypto.Cipher import Blowfish
-from RequestObject import RequestObject
-
-
-class RequestHandler:
- def __init__(self, core):
- self.core = core
- key = hashlib.sha256(core.config['remote']['password'])
- self.bf = Blowfish.new(key.hexdigest(), Blowfish.MODE_ECB)
-
- def proceed(self, data):
- obj = self.decrypt(data)
-
- if obj.command == "exec":
- func = getattr(self.core, obj.function)
- obj.data = func( * obj.args)
- else:
- obj.data = "error happend"
-
- return self.encrypt(obj)
-
-
- def decrypt(self, dec_str):
- try:
- dec_str = base64.standard_b64decode(dec_str)
- dec_str = self.bf.decrypt(dec_str)
-
- dec_str = dec_str[:-(int(dec_str[-1], 16) + 1)]
- obj = cPickle.loads(dec_str)
- except:
- obj = RequestObject()
-
- return obj
-
- def encrypt(self, obj):
- enc_str = cPickle.dumps(obj, 1)
- padding = len(enc_str) % 16
- padding = 16 - padding
-
- p_str = ""
- for i in range(padding - 1):
- p_str += random.choice(string.letters + string.digits + string.punctuation)
- p_str += hex(len(p_str)).replace("0x", "")
- enc_str += p_str
-
- enc_str = self.bf.encrypt(enc_str)
- enc_str = base64.standard_b64encode(enc_str)
- return enc_str + "\n"
diff --git a/module/remote/RequestObject.py b/module/remote/RequestObject.py
deleted file mode 100644
index 54ea837a6..000000000
--- a/module/remote/RequestObject.py
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
-authored by: RaNaN
-
-represents the object for interaction
-
-"""
-class RequestObject(object):
- def __init__(self):
- self.version = 0
- self.sender = "ip"
- self.status = {}
- self.command = None
- self.function = ""
- self.args = []
- self.data = None