mirror of https://github.com/huashengdun/webssh
				
				
				
			
						commit
						984c2827ec
					
				|  | @ -377,6 +377,12 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): | ||||||
|             raise InvalidValueError('Invalid port: {}'.format(value)) |             raise InvalidValueError('Invalid port: {}'.format(value)) | ||||||
|         return port |         return port | ||||||
| 
 | 
 | ||||||
|  |     def get_source_address(self): | ||||||
|  |         value = self.get_value('source_address') | ||||||
|  |         if not is_valid_ip_address(value): | ||||||
|  |             raise InvalidValueError('Invalid source ip address: {}'.format(value)) | ||||||
|  |         return value | ||||||
|  | 
 | ||||||
|     def lookup_hostname(self, hostname, port): |     def lookup_hostname(self, hostname, port): | ||||||
|         key = hostname if port == 22 else '[{}]:{}'.format(hostname, port) |         key = hostname if port == 22 else '[{}]:{}'.format(hostname, port) | ||||||
| 
 | 
 | ||||||
|  | @ -395,6 +401,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): | ||||||
|         privatekey, filename = self.get_privatekey() |         privatekey, filename = self.get_privatekey() | ||||||
|         passphrase = self.get_argument('passphrase', u'') |         passphrase = self.get_argument('passphrase', u'') | ||||||
|         totp = self.get_argument('totp', u'') |         totp = self.get_argument('totp', u'') | ||||||
|  |         source_address = self.get_source_address() | ||||||
| 
 | 
 | ||||||
|         if isinstance(self.policy, paramiko.RejectPolicy): |         if isinstance(self.policy, paramiko.RejectPolicy): | ||||||
|             self.lookup_hostname(hostname, port) |             self.lookup_hostname(hostname, port) | ||||||
|  | @ -404,8 +411,19 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): | ||||||
|         else: |         else: | ||||||
|             pkey = None |             pkey = None | ||||||
| 
 | 
 | ||||||
|  |         if source_address: | ||||||
|  |             logging.info("Binding socket for source ip {}".format(source_address)) | ||||||
|  |             sock = socket.socket() | ||||||
|  |             sock.settimeout(options.timeout)  # Set a timeout on blocking socket operations | ||||||
|  |             try: | ||||||
|  |                 sock.bind((source_address, 0)) | ||||||
|  |             except OSError: | ||||||
|  |                 raise InvalidValueError('Unable to bind source address {} socket'.format(source_address)) | ||||||
|  |         else: | ||||||
|  |             sock = None | ||||||
|  | 
 | ||||||
|         self.ssh_client.totp = totp |         self.ssh_client.totp = totp | ||||||
|         args = (hostname, port, username, password, pkey) |         args = (hostname, port, username, password, pkey, sock) | ||||||
|         logging.debug(args) |         logging.debug(args) | ||||||
| 
 | 
 | ||||||
|         return args |         return args | ||||||
|  | @ -451,6 +469,14 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): | ||||||
|         dst_addr = args[:2] |         dst_addr = args[:2] | ||||||
|         logging.info('Connecting to {}:{}'.format(*dst_addr)) |         logging.info('Connecting to {}:{}'.format(*dst_addr)) | ||||||
| 
 | 
 | ||||||
|  |         sock = args[5] | ||||||
|  |         if sock: | ||||||
|  |             logging.info('Connecting source address socket') | ||||||
|  |             try: | ||||||
|  |                 sock.connect(dst_addr) | ||||||
|  |             except socket.error: | ||||||
|  |                 raise ValueError('Unable to connect source address socket to {}:{}'.format(*dst_addr)) | ||||||
|  | 
 | ||||||
|         try: |         try: | ||||||
|             ssh.connect(*args, timeout=options.timeout) |             ssh.connect(*args, timeout=options.timeout) | ||||||
|         except socket.error: |         except socket.error: | ||||||
|  |  | ||||||
|  | @ -77,6 +77,8 @@ | ||||||
|             <input class="form-control" type="password" id="totp" name="totp" value=""> |             <input class="form-control" type="password" id="totp" name="totp" value=""> | ||||||
|           </div> |           </div> | ||||||
|           <div class="col"> |           <div class="col"> | ||||||
|  |             <label for="source_address">Source Address (optional)</label> | ||||||
|  |             <input class="form-control" type="text" id="source_address" name="source_address" value=""> | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|         <input type="hidden" id="term" name="term" value="xterm-256color"> |         <input type="hidden" id="term" name="term" value="xterm-256color"> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 mzsombor
						mzsombor