Skip to content

Commit

Permalink
start server side app
Browse files Browse the repository at this point in the history
  • Loading branch information
citronneur@gmail.com authored and citronneur@gmail.com committed Feb 9, 2014
1 parent 120f142 commit ec97136
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
17 changes: 12 additions & 5 deletions rdpy/network/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
@author: sylvain
'''

class LayerMode(object):
NONE = 0
SERVER = 1
CLIENT = 2

class Layer(object):
'''
Network abstraction for protocol
Try as possible to divide user protocol in layer
default implementation is a transparent layer
'''
def __init__(self, presentation = None):
def __init__(self, mode = LayerMode.NONE, presentation = None):
'''
Constructor
@param presentation: Layer which handled connect and recv messages
Expand All @@ -17,6 +22,8 @@ def __init__(self, presentation = None):
self._presentation = presentation
#transport layer under layer in model
self._transport = None
#register layer mode
self._mode = mode
#auto set transport layer of own presentation layer
if not self._presentation is None:
self._presentation._transport = self
Expand Down Expand Up @@ -62,13 +69,13 @@ class LayerAutomata(Layer):
layer with automata state
we can set next recv function used
'''
def __init__(self, presentation = None):
def __init__(self, mode, presentation = None):
'''
Constructor
@param presentation: presentation Layer
'''
#call parent constructor
Layer.__init__(self, presentation)
Layer.__init__(self, mode, presentation)

def setNextState(self, callback = None):
'''
Expand All @@ -93,12 +100,12 @@ class RawLayer(protocol.Protocol, LayerAutomata):
allow this protocol to wait until expected size of packet
and use Layer automata to call next automata state
'''
def __init__(self, presentation = None):
def __init__(self, mode, presentation = None):
'''
Constructor
'''
#call parent automata
LayerAutomata.__init__(self, presentation)
LayerAutomata.__init__(self, mode, presentation)
#data buffer received from twisted network layer
self._buffer = ""
#len of next packet pass to next state function
Expand Down
6 changes: 3 additions & 3 deletions rdpy/protocol/rdp/rdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class Factory(protocol.Factory):
'''
Factory of RDP protocol
'''
def __init__(self):
pass
def __init__(self, mode):
self._mode = mode

def buildProtocol(self, addr):
return tpkt.TPKT(tpdu.TPDU(mcs.MCS(sil.SIL())));
return tpkt.TPKT(tpdu.TPDU(mcs.MCS(sil.SIL(self._mode))));

def startedConnecting(self, connector):
print 'Started to connect.'
Expand Down
4 changes: 2 additions & 2 deletions rdpy/protocol/rdp/sil.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ class SIL(LayerAutomata):
Global channel for mcs that handle session
identification user, licensing management, and capabilities exchange
'''
def __init__(self):
def __init__(self, mode):
'''
Constructor
'''
LayerAutomata.__init__(self, None)
LayerAutomata.__init__(self, mode, None)
#set by mcs layer channel init
self._channelId = UInt16Be()
#logon info send from client to server
Expand Down
11 changes: 7 additions & 4 deletions rdpy/protocol/rdp/tpdu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''
@author: sylvain
'''
from rdpy.network.layer import LayerAutomata
from rdpy.network.layer import LayerAutomata, LayerMode
from rdpy.network.type import UInt8, UInt16Le, UInt16Be, UInt32Le, CompositeType, sizeof
from rdpy.network.error import InvalidExpectedDataException
from rdpy.network.const import ConstAttributes, TypeAttributes
Expand Down Expand Up @@ -95,12 +95,12 @@ class TPDU(LayerAutomata):
TPDU layer management
there is an connection automata
'''
def __init__(self, presentation = None):
def __init__(self, presentation):
'''
Constructor
@param presentation: MCS layer
'''
LayerAutomata.__init__(self, presentation)
LayerAutomata.__init__(self, presentation._mode, presentation)
#default selectedProtocol is SSl because is the only supported
#in this version of RDPY
#client requested selectedProtocol
Expand All @@ -113,7 +113,10 @@ def connect(self):
connection request
for client send a connection request packet
'''
self.sendConnectionRequest()
if self._mode == LayerMode.CLIENT:
self.sendConnectionRequest()
else:
self.setNextState(self.recvConnectionRequest)

def recvConnectionConfirm(self, data):
'''
Expand Down
4 changes: 2 additions & 2 deletions rdpy/protocol/rdp/tpkt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''
@author: sylvain
'''
from rdpy.network.layer import RawLayer
from rdpy.network.layer import RawLayer, LayerMode
from rdpy.network.type import UInt8, UInt16Be, sizeof

class TPKT(RawLayer):
Expand All @@ -17,7 +17,7 @@ def __init__(self, presentation = None):
'''
Constructor
'''
RawLayer.__init__(self, presentation)
RawLayer.__init__(self, LayerMode.NONE, presentation)
#last packet version read from header
self._lastPacketVersion = UInt8()
#length may be coded on more than 1 bytes
Expand Down
4 changes: 2 additions & 2 deletions rdpy/rdpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
@author: sylvain
'''
from rdpy.protocol.rdp import rdp

from rdpy.network.layer import LayerMode


if __name__ == '__main__':
from twisted.internet import reactor
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
#reactor.connectTCP("192.168.1.90", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS()))))
reactor.connectTCP("192.168.135.165", 3389, rdp.Factory())
reactor.connectTCP("192.168.135.165", 3389, rdp.Factory(LayerMode.CLIENT))
reactor.run()
3 changes: 2 additions & 1 deletion rdpy/rdpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
sys.path.insert(1, os.path.join(sys.path[0], '..'))

from rdpy.protocol.rdp import rdp
from rdpy.network.layer import LayerMode

if __name__ == '__main__':
from twisted.internet import reactor
reactor.listenTCP(33389, rdp.Factory())
reactor.listenTCP(33389, rdp.Factory(LayerMode.SERVER))
reactor.run()

0 comments on commit ec97136

Please sign in to comment.