refactor examples and client factory
This commit is contained in:
11
README.md
11
README.md
@@ -1,2 +1,11 @@
|
|||||||
depend : python-qt4, python-twisted, python-qt4reactor
|
# RDPY Remote Desktop Protoc in Python
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
* python2.7
|
||||||
|
* python-twisted
|
||||||
|
|
||||||
|
## Requirements for examples
|
||||||
|
* python-qt4
|
||||||
|
* python-qt4reactor
|
||||||
|
|
||||||
this project is still in progress.
|
this project is still in progress.
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class QAdaptor(object):
|
|||||||
@param e: qEvent
|
@param e: qEvent
|
||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class RfbAdaptor(RfbObserver, QAdaptor):
|
class RfbAdaptor(RfbObserver, QAdaptor):
|
||||||
'''
|
'''
|
||||||
@@ -159,7 +158,7 @@ class QRemoteDesktop(QtGui.QWidget):
|
|||||||
#because we can update image only in paint
|
#because we can update image only in paint
|
||||||
#event function. When protocol receive image
|
#event function. When protocol receive image
|
||||||
#we will stock into refresh list
|
#we will stock into refresh list
|
||||||
#and in paiont event paint list of all refresh iomages
|
#and in paiont event paint list of all refresh images
|
||||||
self._refresh = []
|
self._refresh = []
|
||||||
#bind mouse event
|
#bind mouse event
|
||||||
self.setMouseTracking(True)
|
self.setMouseTracking(True)
|
||||||
|
|||||||
6
rdpy/display/rle.py
Normal file
6
rdpy/display/rle.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
'''
|
||||||
|
@author: citronneur
|
||||||
|
@file: implement run length encoding algorithm use in RDP protocol to compress bit
|
||||||
|
@see: http://msdn.microsoft.com/en-us/library/dd240593.aspx
|
||||||
|
'''
|
||||||
|
|
||||||
@@ -11,6 +11,84 @@ from rdpy.display.qt import RDPAdaptor, RfbAdaptor, QRemoteDesktop
|
|||||||
from rdpy.protocol.rdp import rdp
|
from rdpy.protocol.rdp import rdp
|
||||||
from rdpy.protocol.rfb import rfb
|
from rdpy.protocol.rfb import rfb
|
||||||
|
|
||||||
|
class RDPClientQtFactory(rdp.ClientFactory):
|
||||||
|
'''
|
||||||
|
Factory create a RDP GUI client
|
||||||
|
'''
|
||||||
|
def __init__(self):
|
||||||
|
'''
|
||||||
|
ctor that init qt context and protocol needed
|
||||||
|
'''
|
||||||
|
#create qt widget
|
||||||
|
self._w = QRemoteDesktop()
|
||||||
|
self._w.resize(1024, 800)
|
||||||
|
self._w.setWindowTitle('rdpyclient-rdp')
|
||||||
|
self._w.show()
|
||||||
|
#build protocol
|
||||||
|
rdp.ClientFactory.__init__(self, RDPAdaptor(self._w))
|
||||||
|
|
||||||
|
def startedConnecting(self, connector):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def clientConnectionLost(self, connector, reason):
|
||||||
|
'''
|
||||||
|
connection lost event
|
||||||
|
@param connector: twisted connector use for rdp connection (use reconnect to restart connection)
|
||||||
|
@param reason: str use to advertise reason of lost connection
|
||||||
|
'''
|
||||||
|
QtGui.QMessageBox.warning(self._w, "Warning", "Lost connection : %s"%reason)
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
'''
|
||||||
|
connection failed event
|
||||||
|
@param connector: twisted connector use for rdp connection (use reconnect to restart connection)
|
||||||
|
@param reason: str use to advertise reason of lost connection
|
||||||
|
'''
|
||||||
|
QtGui.QMessageBox.warning(self._w, "Warning", "Connection failed : %s"%reason)
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
|
class RFBClientQtFactory(rfb.ClientFactory):
|
||||||
|
'''
|
||||||
|
Factory create a VNC GUI client
|
||||||
|
'''
|
||||||
|
def __init__(self):
|
||||||
|
'''
|
||||||
|
ctor that init qt context and protocol needed
|
||||||
|
'''
|
||||||
|
#create qt widget
|
||||||
|
self._w = QRemoteDesktop()
|
||||||
|
self._w.resize(1024, 800)
|
||||||
|
self._w.setWindowTitle('rdpyclient-vnc')
|
||||||
|
self._w.show()
|
||||||
|
|
||||||
|
rfb.ClientFactory.__init__(self, RfbAdaptor(self._w))
|
||||||
|
|
||||||
|
def startedConnecting(self, connector):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def clientConnectionLost(self, connector, reason):
|
||||||
|
'''
|
||||||
|
connection lost event
|
||||||
|
@param connector: twisted connector use for vnc connection (use reconnect to restart connection)
|
||||||
|
@param reason: str use to advertise reason of lost connection
|
||||||
|
'''
|
||||||
|
QtGui.QMessageBox.warning(self._w, "Warning", "Lost connection : %s"%reason)
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
'''
|
||||||
|
connection failed event
|
||||||
|
@param connector: twisted connector use for vnc connection (use reconnect to restart connection)
|
||||||
|
@param reason: str use to advertise reason of lost connection
|
||||||
|
'''
|
||||||
|
QtGui.QMessageBox.warning(self._w, "Warning", "Connection failed : %s"%reason)
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#create application
|
#create application
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
@@ -19,18 +97,13 @@ if __name__ == '__main__':
|
|||||||
import qt4reactor
|
import qt4reactor
|
||||||
qt4reactor.install()
|
qt4reactor.install()
|
||||||
|
|
||||||
#create widget
|
|
||||||
w = QRemoteDesktop()
|
|
||||||
w.resize(1024, 800)
|
|
||||||
w.setWindowTitle('rdpyclient')
|
|
||||||
w.show()
|
|
||||||
|
|
||||||
if sys.argv[3] == 'rdp':
|
if sys.argv[3] == 'rdp':
|
||||||
factory = rdp.Factory(RDPAdaptor(w))
|
factory = RDPClientQtFactory()
|
||||||
else:
|
else:
|
||||||
factory = rfb.ClientFactory(RfbAdaptor(w))
|
factory = RFBClientQtFactory()
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
reactor.connectTCP(sys.argv[1], int(sys.argv[2]), factory)
|
reactor.connectTCP(sys.argv[1], int(sys.argv[2]), factory)
|
||||||
reactor.run()
|
reactor.runReturn()
|
||||||
sys.exit(app.exec_())
|
app.exec_()
|
||||||
|
reactor.stop()
|
||||||
@@ -33,30 +33,24 @@ class RDP(object):
|
|||||||
for rectangle in bitmapUpdateData.rectangles._array:
|
for rectangle in bitmapUpdateData.rectangles._array:
|
||||||
observer.notifyBitmapUpdate(rectangle.destLeft.value, rectangle.destTop.value, rectangle.destRight.value, rectangle.destBottom.value, rectangle.width.value, rectangle.height.value, rectangle.bitsPerPixel.value, (rectangle.flags & pdu.BitmapFlag.BITMAP_COMPRESSION).value, rectangle.bitmapDataStream.value)
|
observer.notifyBitmapUpdate(rectangle.destLeft.value, rectangle.destTop.value, rectangle.destRight.value, rectangle.destBottom.value, rectangle.width.value, rectangle.height.value, rectangle.bitsPerPixel.value, (rectangle.flags & pdu.BitmapFlag.BITMAP_COMPRESSION).value, rectangle.bitmapDataStream.value)
|
||||||
|
|
||||||
class Factory(protocol.Factory):
|
class ClientFactory(protocol.Factory):
|
||||||
'''
|
'''
|
||||||
Factory of Client RDP protocol
|
Factory of Client RDP protocol
|
||||||
'''
|
'''
|
||||||
def __init__(self, observer):
|
def __init__(self, observer):
|
||||||
'''
|
'''
|
||||||
ctor
|
ctor
|
||||||
@param observer: observer use by rdp protocol to handle events
|
@param observer: observer use by rdp protocol to handle events must implement RDPObserver
|
||||||
'''
|
'''
|
||||||
self._observer = observer
|
self._observer = observer
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
|
'''
|
||||||
|
Function call from twisted and build rdp protocol stack
|
||||||
|
'''
|
||||||
rdp = RDP()
|
rdp = RDP()
|
||||||
rdp.addObserver(self._observer)
|
rdp.addObserver(self._observer)
|
||||||
return tpkt.TPKT(tpdu.TPDU(mcs.MCS(pdu.PDU(LayerMode.CLIENT, rdp))));
|
return tpkt.TPKT(tpdu.TPDU(mcs.MCS(pdu.PDU(LayerMode.CLIENT, rdp))));
|
||||||
|
|
||||||
def startedConnecting(self, connector):
|
|
||||||
print 'Started to connect.'
|
|
||||||
|
|
||||||
def clientConnectionLost(self, connector, reason):
|
|
||||||
print 'Lost connection. Reason:', reason
|
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
|
||||||
print 'Connection failed. Reason:', reason
|
|
||||||
|
|
||||||
class RDPObserver(object):
|
class RDPObserver(object):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -425,21 +425,12 @@ class ClientFactory(protocol.Factory):
|
|||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
'''
|
'''
|
||||||
function call by twisted on connection
|
function call by twisted on connection
|
||||||
@param addr: adresse where client try to connect
|
@param addr: adress where client try to connect
|
||||||
'''
|
'''
|
||||||
protocol = Rfb(LayerMode.CLIENT)
|
protocol = Rfb(LayerMode.CLIENT)
|
||||||
protocol.addObserver(self._observer)
|
protocol.addObserver(self._observer)
|
||||||
self._observer.setProtocol(protocol)
|
self._observer.setProtocol(protocol)
|
||||||
return protocol
|
return protocol
|
||||||
|
|
||||||
def startedConnecting(self, connector):
|
|
||||||
print 'Started to connect.'
|
|
||||||
|
|
||||||
def clientConnectionLost(self, connector, reason):
|
|
||||||
print 'Lost connection. Reason:', reason
|
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
|
||||||
print 'Connection failed. Reason:', reason
|
|
||||||
|
|
||||||
class RfbObserver(object):
|
class RfbObserver(object):
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user