viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. ## SnorkyCore -- This is the main library of Snorky,
  2. ## aimed to provide the forward over SSH of arbitrary
  3. ## ports.
  4.  
  5. import select, SocketServer, threading, paramiko
  6.  
  7. # Set verbosity (only useful for debugging)
  8. g_verbose = False
  9.  
  10. def verbose(string):
  11. if(g_verbose):
  12. print "=> " + string
  13.  
  14. class SnorkyHandler(SocketServer.BaseRequestHandler):
  15. """The handler for the data exchanged by Snorky and the
  16. server on the SSH server contacted by Snorky"""
  17.  
  18. def handle(self):
  19. """This the overloaded method the actually handles the data. It is
  20. called when the connection is open (and actually it opens the connection
  21. to the ssh server!)."""
  22.  
  23. # We first need to try to obtain the forwarded channel
  24. try:
  25. self.channel = self.transport.open_channel('direct-tcpip',
  26. (self.remote_host, self.remote_port),
  27. (self.local_host , self.local_port))
  28. verbose("Channel opened")
  29. except Exception, e:
  30. verbose("Unable to open the requested channel (%s)" % e)
  31. return
  32.  
  33. # Keep the server going :)
  34. while(True):
  35.  
  36. # Now that we have the channel, we need to build up our handler
  37. # Asynchronous reading from the server and the forwarded
  38. # channel is necessary
  39. r , w, x = select.select([self.request, self.channel], [], [])
  40.  
  41. # Check if we need to read a request from the server, and if it is so,
  42. # write into the channel
  43. if self.request in r:
  44. data = self.request.recv(1024)
  45. if( len(data) == 0 ):
  46. break # Nothing to do, exit...
  47.  
  48. # Ok, transmit on the channel
  49. self.channel.send(data)
  50.  
  51. # Check if we need to read from forwarded channel
  52. if self.channel in r:
  53. data = self.channel.recv(1024)
  54. if( len(data) == 0 ):
  55. break # Nothing to do
  56.  
  57. # Ok, so send to the server!
  58. self.request.send(data)
  59.  
  60. # Connection complete... so
  61. self.channel.close()
  62. self.request.close()
  63.  
  64.  
  65. class SnorkyForwardServer(SocketServer.ThreadingTCPServer):
  66. """This is the server aimed to handle all traffic"""
  67. daemon_threads = True
  68. allow_reuse_address = True
  69.  
  70.  
  71. class SnorkyServerThread(threading.Thread):
  72. """The thread running the server"""
  73.  
  74. def __init__(self, local_host, local_port, remote_host, remote_port, transport):
  75. threading.Thread.__init__(self)
  76. self.transport = transport
  77. self.remote_host = remote_host
  78. self.remote_port = remote_port
  79. self.local_host = local_host
  80. self.local_port = local_port
  81.  
  82. def run(self):
  83. """Overloaded run method so that it runs our customized server"""
  84.  
  85. # We need to define a new SubHandler with tranport in it!
  86. class SnorkySubHandler(SnorkyHandler):
  87. transport = self.transport
  88. remote_host = self.remote_host
  89. remote_port = self.remote_port
  90. local_host = self.local_host
  91. local_port = self.local_port
  92.  
  93. # Start the server
  94. self.server = SnorkyForwardServer((self.local_host, self.local_port), SnorkySubHandler)
  95. self.server.serve_forever()
  96.  
  97.  
  98. class SnorkySSH():
  99. """Provide an abstract interface to the SSH work (forwarding)
  100. using the Paramiko library"""
  101.  
  102. def __init__(self):
  103. # Create the Paramiko Client and tell it we don't bother about
  104. # keys...
  105. self.SSHClient = paramiko.SSHClient()
  106. self.SSHClient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  107.  
  108. # Our status
  109. self.connected = False
  110.  
  111. def authenticate(self, server, username, password):
  112. # Check that we are not connected
  113. if(self.connected):
  114. verbose("We are connected, so doing nothing")
  115. return
  116.  
  117. # Try connecting with Paramiko
  118. try:
  119. self.SSHClient.connect(server, 22, username, password)
  120. self.connected = True
  121. except Exception, e:
  122. verbose("Connection to %s@%s failed" % username, server)
  123. self.connected = False
  124.  
  125. def openTunnel(self, remote_host, local_port, remote_port):
  126. # Check that we are connected
  127. if(self.connected == False):
  128. verbose("We are not connected, please call SnorkySSH.authenticate() first")
  129. return
  130.  
  131. # Get the transport
  132. transport = self.SSHClient.get_transport()
  133.  
  134. # Create the server thread
  135. self.server_thread = SnorkyServerThread('', local_port, remote_host, remote_port, transport)
  136.  
  137. # Start the server
  138. self.server_thread.start()
  139.  
  140. def closeTunnel(self):
  141. """Disconnect from the remote server"""
  142. # Just destroy anything!
  143. self.server_thread.server.shutdown()
  144. del self.server_thread
  145. self.connected = False
  146.