parameters: (self, selected_target)
return_statement: return False, "End of Session"
docstring: #####################
          ### START_SESSION ###
          #####################
docstring_summary: #####################
          ### START_SESSION ###
          #####################
docstring_tokens: ##################### ### START_SESSION ### #####################
function: def connect_to_target(self, selected_target):
          """
          #####################
          ### START_SESSION ###
          #####################
          """
          extra_info = self.engine.get_target_extra_info()
          _status, _error = True, u''
  
          Logger().info(u"Fetching protocol")
          kv = {}
          if _status:
              target_login_info = self.engine.get_target_login_info(
                  selected_target
              )
              proto_info = self.engine.get_target_protocols(selected_target)
              kv[u'proto_dest'] = proto_info.protocol
              kv[u'target_str'] = target_login_info.get_target_str()
  
          if _status:
              kv['password'] = 'pass'
  
              # id to recognize primary user for session probe
              kv['primary_user_id'] = self.engine.get_username()
  
              # register signal
              signal.signal(signal.SIGUSR1, self.kill_handler)
              signal.signal(signal.SIGUSR2, self.check_handler)
  
              Logger().info(u"Starting Session, effective login='%s'" %
                            self.effective_login)
  
              user = self.engine.get_username()
              uname = self.effective_login or target_login_info.account_login
  
              # Add connection to the observer
              session_id, start_time, error_msg = self.engine.start_session(
                  selected_target,
                  self.pid,
                  self.effective_login
              )
              if session_id is None:
                  _status, _error = False, \
                      TR(u"start_session_failed") + " (" + error_msg + ")"
  
          if _status:
              record_warning = SESMANCONF[u'sesman'].get('record_warning', True)
              if record_warning and extra_info.is_recorded:
                  _status, _error = self.interactive_ask_recording(
                      user
                  )
  
          if _status:
              timeclose, _status, _error = self.check_deconnection_time(
                  selected_target
              )
              if timeclose is not None:
                  kv['timeclose'] = timeclose
  
          if _status:
              # add "Year-Month-Day" subdirectory to record path
              date_path = start_time.strftime("%Y-%m-%d")
              rec_path = os.path.join(LOCAL_TRACE_PATH_RDP, date_path)
              self.record_filebase = self.generate_record_filebase(
                  session_id,
                  user,
                  uname,
                  start_time
              )
              kv['record_filebase'] = self.record_filebase
              kv['record_subdirectory'] = date_path
              # TODO kv[u'record_path'] = LOCAL_TRACE_PATH_RDP
              Logger().info(u"Session will be recorded in %s" %
                            self.record_filebase)
              try:
                  _status, _error = self.create_record_path_directory(
                      rec_path
                  )
                  if _status and extra_info.is_recorded:
                      _status, _error = self.load_video_recording(
                          rec_path, user
                      )
                  if _status:
                      _status, _error = self.load_session_log_redirection(
                          rec_path
                      )
                  if _status:
                      encryption_key, sign_key = self.get_trace_keys()
                      kv['encryption_key'] = encryption_key
                      kv['sign_key'] = sign_key
              except Exception:
                  import traceback
                  Logger().debug("%s" % traceback.format_exc())
                  _status, _error = False, TR(u"Connection closed by client")
  
          if not _status:
              self.send_data({u'rejected': _error})
  
          if _status:
              kv[u'session_id'] = session_id
              trace_written = False  # reminder to write_trace later
              pattern_kill, pattern_notify = self.engine.get_restrictions(
                  selected_target, "RDP"
              )
              if pattern_kill:
                  self.send_data({u'module': u'transitory',
                                  u'pattern_kill': pattern_kill})
              if pattern_notify:
                  self.send_data({u'module': u'transitory',
                                  u'pattern_notify': pattern_notify})
  
          if _status:
              module = kv.get(u'proto_dest')
              if module not in [u'RDP', u'VNC', u'INTERNAL']:
                  module = u'RDP'
              if self.internal_target:
                  module = u'INTERNAL'
              kv[u'module'] = module
              # proto = u'RDP' if  kv.get(u'proto_dest') != u'VNC' else u'VNC'
  
          self.shared[u'recording_started'] = 'False'
  
          self.reporting_reason = None
          self.reporting_target = None
          self.reporting_message = None
  
          try_next = False
          close_box = False
  
          if _status:
              for physical_target in self.engine.get_effective_target(
                      selected_target
              ):
                  try_next = False
                  close_box = False
                  kv[u'recording_started'] = "False"
  
                  cstatus, infos = self.engine.check_target(physical_target,
                                                            self.pid,
                                                            None)
                  if cstatus != APPROVAL_ACCEPTED:
                      Logger().info("Jump server unavailable (%s)"
                                    % infos.get('message'))
                      _status = False
                      continue
  
                  physical_info = self.engine.get_physical_target_info(
                      physical_target
                  )
                  if not _status:
                      physical_target = None
                      break
  
                  physical_proto_info = self.engine.get_target_protocols(
                      physical_target
                  )
                  application = self.engine.get_application(selected_target)
                  conn_opts = self.engine.get_target_conn_options(
                      physical_target
                  )
                  if (physical_proto_info.protocol == u'RDP'
                      or physical_proto_info.protocol == u'VNC'):
                      if physical_proto_info.protocol == u'RDP':
                          kv[u'proxy_opt'] = ",".join(
                              physical_proto_info.subprotocols
                          )
  
                      kv.update(self.fetch_connectionpolicy(conn_opts))
  
                  kv.update(self._load_kerberos_armoring_options(conn_opts))
  
                  kv[u'disable_tsk_switch_shortcuts'] = u'no'
                  if application:
                      app_params = self.engine.get_app_params(
                          selected_target,
                          physical_target
                      )
                      if not app_params:
                          continue
                      kv[u'alternate_shell'] = app_params.program
                      if app_params.params is not None:
                          kv[u'shell_arguments'] = app_params.params
                      kv[u'shell_working_directory'] = app_params.workingdir
  
                      kv[u'target_application'] = "%s@%s" % \
                          (target_login_info.account_name,
                           target_login_info.target_name)
                      if app_params.params is not None:
                          if u'${USER}' in app_params.params:
                              kv[u'target_application_account'] = \
                                  target_login_info.account_login or \
                                  self.target_context.login or ""
                          if u'${PASSWORD}' in app_params.params:
                              kv[u'target_application_password'] = (
                                  self.engine.get_target_password(
                                      selected_target
                                  )
                                  or self.engine.get_primary_password(
                                      selected_target
                                  )
                                  or ''
                              )
                      self.target_app_rights[kv[u'target_application']] = (
                          selected_target, app_params
                      )
  
                      # kv[u'target_application'] = selected_target.service_login
                      kv[u'disable_tsk_switch_shortcuts'] = u'yes'
                  self.cn = target_login_info.target_name
  
                  if self.target_context.host:
                      kv[u'target_host'] = self.target_context.host
                      kv[u'target_device'] = self.target_context.showname()
                  else:
                      kv[u'target_host'] = physical_info.device_host
  
                  kv[u'target_login'] = physical_info.account_login
                  if (not kv.get(u'target_login')
                      and self.target_context.login
                      and not application):
                      # on application,
                      # login in target_context is the login of application
                      kv[u'target_login'] = self.target_context.login
  
                  kv[u'target_port'] = physical_info.service_port
                  kv[u'device_id'] = physical_info.device_id
  
                  try:
                      auth_policy_methods = self.engine.get_target_auth_methods(
                          physical_target)
                      Logger().info("auth_mode_passthrough=%s" %
                                    self.passthrough_mode)
  
                      target_password = ''
                      if self.passthrough_mode:
                          kv[u'target_login'] = self.passthrough_target_login
                          if self.shared.get(u'password') == MAGICASK:
                              target_password = u''
                          else:
                              target_password = self.shared.get(u'password')
                          # Logger().info(
                          #     "auth_mode_passthrough target_password=%s" %
                          #     target_password
                          # )
                          kv[u'password'] = u'password'
                      elif PASSWORD_VAULT in auth_policy_methods:
                          target_passwords = self.engine.get_target_passwords(
                              physical_target
                          )
                          target_password = u'\x01'.join(target_passwords)
  
                      if (not target_password
                          and PASSWORD_MAPPING in auth_policy_methods):
                          target_password = (
                              self.engine.get_primary_password(physical_target)
                              or ''
                          )
  
                      force_sc_auth = conn_opts.get(
                          u'rdp', {}
                      ).get(
                          u'force_smartcard_authentication', False
                      )
                      Logger().info("force_smartcard_authentication = %s" %
                                    force_sc_auth)
                      allow_interactive_password = (
                          (PASSWORD_INTERACTIVE in auth_policy_methods
                           or self.passthrough_mode)
                          and not force_sc_auth
                      )
                      allow_interactive_login = not force_sc_auth
  
                      kv[u'target_password'] = target_password
                      is_interactive_login = (
                          not bool(kv.get('target_login'))
                          and not force_sc_auth
                      )
                      extra_kv, _status, _error = self.complete_target_info(
                          kv, allow_interactive_password,
                          allow_interactive_login)
                      kv.update(extra_kv)
  
                      if self.target_context.host:
                          self._physical_target_host = self.target_context.host
                      elif ('/' in physical_info.device_host
                            and extra_kv.get(u'target_host') != MAGICASK):
                          self._physical_target_host = \
                              extra_kv.get(u'target_host')
                      else:
                          self._physical_target_host = physical_info.device_host
  
                      Logger().info(
                          u"Send critic notification "
                          u"(every attempt to connect to some physical node)"
                      )
                      if extra_info.is_critical:
                          Logger().info("CRITICAL CONNECTION")
                          import socket
                          self.engine.NotifyConnectionToCriticalEquipment(
                              (u'APP' if application else proto_info.protocol),
                              self.shared.get(u'login'),
                              socket.getfqdn(self.shared.get(u'ip_client')),
                              self.shared.get(u'ip_client'),
                              self.shared.get(u'target_login'),
                              self.shared.get(u'target_device'),
                              self._physical_target_host,
                              ctime(),
                              None
                          )
  
                      update_args = {
                          "is_application": bool(application),
                          "target_host": self._physical_target_host,
                          "session_log_path": self.full_log_path
                      }
                      if is_interactive_login:
                          update_args["effective_login"] = kv.get('target_login')
                      if self.shared.get('width'):
                          update_args["video_width"] = \
                              int(self.shared.get('width'))
                      if self.shared.get('height'):
                          update_args["video_height"] = \
                              int(self.shared.get('height'))
  
                      self.engine.update_session_target(physical_target,
                                                        **update_args)
  
                      if (_status
                          and 'vnc_over_ssh' in conn_opts
                          and conn_opts.get("vnc_over_ssh").get("enable")):
                          _status, _error = \
                              self._load_vnc_over_ssh_options(
                                  kv, conn_opts
                              )
  
                      if not _status:
                          Logger().info(
                              u"(%s):%s:REJECTED : User message: \"%s\"" % (
                                  mundane(self.shared.get(u'ip_client')),
                                  mundane(self.shared.get(u'login')),
                                  _error
                              )
                          )
  
                          kv = {
                              u"login": u"",
                              u'password': u"",
                              u'target_login': u"",
                              u'target_password': u"",
                              u'target_device': u"",
                              u'target_host': u"",
                              u'rejected': _error,
                          }
  
                      try_next = False
                      logtimer.stop("CHECKOUT_TARGET")
                      try:
                          ###########
                          # SEND KV #
                          ###########
                          self.send_data(kv)
  
                          Logger().info(
                              u"Added connection to active Bastion services"
                          )
  
                          # Looping on keepalived socket
                          while True:
                              r = []
                              got_signal = False
                              try:
                                  r, w, x = select([self.proxy_conx], [], [],
                                                   KEEPALIVE_TIMEOUT)
                              except BastionSignal as e:
                                  Logger().info("Got Signal %s" % e)
                                  got_signal = True
                              except Exception as e:
                                  if DEBUG:
                                      Logger().info("exception: '%s'" % e)
                                      import traceback
                                      Logger().info("<<<<%s>>>>" %
                                                    traceback.format_exc())
                                  raise
                              self.engine.keepalive(timeout=KEEPALIVE_TIMEOUT)
                              current_time = time()
                              if self.check_session_parameters:
                                  self.update_session_parameters(current_time)
                                  self.check_session_parameters = False
                              self.rtmanager.check(current_time)
                              if self.proxy_conx in r:
                                  _status, _error = self.receive_data(
                                      Sesman.EXPECTING_KEYS,
                                      blocking_call=False
                                  )
  
                                  if self._changed_keys:
                                      self.update_session_data(
                                          self._changed_keys
                                      )
  
                                  self.process_target_connection_time()
  
                                  if self.shared.get(u'auth_notify'):
                                      self.handle_auth_notify(physical_target)
                                      self.shared[u'auth_notify'] = u''
  
                                  if (not trace_written
                                      and (self.shared.get('recording_started')
                                           == 'True')):
                                      _status, _error = \
                                          self.handle_recording_started()
                                      trace_written = True
  
                                  if self.shared.get("pm_request"):
                                      self._manage_pm()
  
                                  self.handle_shadowing()
  
                                  if self.shared.get(u'reporting'):
                                      report_status = self.handle_reporting()
                                      if not report_status:
                                          try_next = True
                                          break
  
                                  if self.shared.get(u'disconnect_reason_ack'):
                                      break
  
                                  if self.shared.get(u'auth_channel_target'):
                                      self.handle_auth_channel_target(
                                          selected_target
                                      )
                                      self.shared[u'auth_channel_target'] = u''
                                  if self.shared.get(u'module') == u"close":
                                      break
                                  if self.shared.get(u'keepalive') == MAGICASK:
                                      self.send_data({u'keepalive': u'True'})
                              # r can be empty
                              else:
                                  # (if self.proxy_conx in r)
                                  if not self.internal_target and not got_signal:
                                      Logger().info(u'Missing Keepalive')
                                      Logger().error(u'break connection')
                                      break
                          if self.shared.get(u'module') == u"close":
                              close_box = True
                          Logger().debug(u"End Of Keep Alive")
  
                      except AuthentifierSocketClosed:
                          if DEBUG:
                              import traceback
                              Logger().info(
                                  u"RDP/VNC connection terminated by client"
                              )
                              Logger().info("<<<%s>>>" % traceback.format_exc())
                      except Exception:
                          if DEBUG:
                              import traceback
                              Logger().info(
                                  u"RDP/VNC connection terminated by client"
                              )
                              Logger().info("<<<%s>>>" % traceback.format_exc())
                      if not try_next:
                          break
                  finally:
                      self.engine.release_target(physical_target)
  
          self.engine.release_all_target()
          Logger().info(u"Stop session ...")
          # Notify WabEngine to stop connection if it has been
          # launched successfully
          self.engine.stop_session(title=u"End session")
          if self.tun_process:
              self.tun_process.stop()
              self.tun_process = None
          Logger().info(u"Stop session done.")
          if self.shared.get(u"module") == u"close":
              if close_box and self.back_selector:
                  try:
                      self.send_data({u'module': u'close_back',
                                      u'selector': u'False'})
                      while True:
                          _status, _error = self.receive_data()
                          if (_status
                              and self.shared.get(u'selector') == MAGICASK):
                              return None, "Go back to selector"
                  except Exception:
                      _status, _error = False, "End of Session"
              else:
                  self.send_data({u'module': u'close'})
          # Error
          if try_next:
              _status, _error = self.interactive_close(self.reporting_target,
                                                       self.reporting_message)
  
          try:
              Logger().info(u"Close connection ...")
  
              self.proxy_conx.close()
  
              Logger().info(u"Close connection done.")
          except IOError:
              if DEBUG:
                  Logger().info(u"Close connection: Exception")
                  Logger().info("<<<<%s>>>>" % traceback.format_exc())
          return False, "End of Session"
function_tokens: def connect_to_target ( self , selected_target ) : extra_info = self . engine . get_target_extra_info ( ) _status , _error = True , u'' Logger ( ) . info ( u"Fetching protocol" ) kv = { } if _status : target_login_info = self . engine . get_target_login_info ( selected_target ) proto_info = self . engine . get_target_protocols ( selected_target ) kv [ u'proto_dest' ] = proto_info . protocol kv [ u'target_str' ] = target_login_info . get_target_str ( ) if _status : kv [ 'password' ] = 'pass' # id to recognize primary user for session probe kv [ 'primary_user_id' ] = self . engine . get_username ( ) # register signal signal . signal ( signal . SIGUSR1 , self . kill_handler ) signal . signal ( signal . SIGUSR2 , self . check_handler ) Logger ( ) . info ( u"Starting Session, effective login='%s'" % self . effective_login ) user = self . engine . get_username ( ) uname = self . effective_login or target_login_info . account_login # Add connection to the observer session_id , start_time , error_msg = self . engine . start_session ( selected_target , self . pid , self . effective_login ) if session_id is None : _status , _error = False , TR ( u"start_session_failed" ) + " (" + error_msg + ")" if _status : record_warning = SESMANCONF [ u'sesman' ] . get ( 'record_warning' , True ) if record_warning and extra_info . is_recorded : _status , _error = self . interactive_ask_recording ( user ) if _status : timeclose , _status , _error = self . check_deconnection_time ( selected_target ) if timeclose is not None : kv [ 'timeclose' ] = timeclose if _status : # add "Year-Month-Day" subdirectory to record path date_path = start_time . strftime ( "%Y-%m-%d" ) rec_path = os . path . join ( LOCAL_TRACE_PATH_RDP , date_path ) self . record_filebase = self . generate_record_filebase ( session_id , user , uname , start_time ) kv [ 'record_filebase' ] = self . record_filebase kv [ 'record_subdirectory' ] = date_path # TODO kv[u'record_path'] = LOCAL_TRACE_PATH_RDP Logger ( ) . info ( u"Session will be recorded in %s" % self . record_filebase ) try : _status , _error = self . create_record_path_directory ( rec_path ) if _status and extra_info . is_recorded : _status , _error = self . load_video_recording ( rec_path , user ) if _status : _status , _error = self . load_session_log_redirection ( rec_path ) if _status : encryption_key , sign_key = self . get_trace_keys ( ) kv [ 'encryption_key' ] = encryption_key kv [ 'sign_key' ] = sign_key except Exception : import traceback Logger ( ) . debug ( "%s" % traceback . format_exc ( ) ) _status , _error = False , TR ( u"Connection closed by client" ) if not _status : self . send_data ( { u'rejected' : _error } ) if _status : kv [ u'session_id' ] = session_id trace_written = False # reminder to write_trace later pattern_kill , pattern_notify = self . engine . get_restrictions ( selected_target , "RDP" ) if pattern_kill : self . send_data ( { u'module' : u'transitory' , u'pattern_kill' : pattern_kill } ) if pattern_notify : self . send_data ( { u'module' : u'transitory' , u'pattern_notify' : pattern_notify } ) if _status : module = kv . get ( u'proto_dest' ) if module not in [ u'RDP' , u'VNC' , u'INTERNAL' ] : module = u'RDP' if self . internal_target : module = u'INTERNAL' kv [ u'module' ] = module # proto = u'RDP' if  kv.get(u'proto_dest') != u'VNC' else u'VNC' self . shared [ u'recording_started' ] = 'False' self . reporting_reason = None self . reporting_target = None self . reporting_message = None try_next = False close_box = False if _status : for physical_target in self . engine . get_effective_target ( selected_target ) : try_next = False close_box = False kv [ u'recording_started' ] = "False" cstatus , infos = self . engine . check_target ( physical_target , self . pid , None ) if cstatus != APPROVAL_ACCEPTED : Logger ( ) . info ( "Jump server unavailable (%s)" % infos . get ( 'message' ) ) _status = False continue physical_info = self . engine . get_physical_target_info ( physical_target ) if not _status : physical_target = None break physical_proto_info = self . engine . get_target_protocols ( physical_target ) application = self . engine . get_application ( selected_target ) conn_opts = self . engine . get_target_conn_options ( physical_target ) if ( physical_proto_info . protocol == u'RDP' or physical_proto_info . protocol == u'VNC' ) : if physical_proto_info . protocol == u'RDP' : kv [ u'proxy_opt' ] = "," . join ( physical_proto_info . subprotocols ) kv . update ( self . fetch_connectionpolicy ( conn_opts ) ) kv . update ( self . _load_kerberos_armoring_options ( conn_opts ) ) kv [ u'disable_tsk_switch_shortcuts' ] = u'no' if application : app_params = self . engine . get_app_params ( selected_target , physical_target ) if not app_params : continue kv [ u'alternate_shell' ] = app_params . program if app_params . params is not None : kv [ u'shell_arguments' ] = app_params . params kv [ u'shell_working_directory' ] = app_params . workingdir kv [ u'target_application' ] = "%s@%s" % ( target_login_info . account_name , target_login_info . target_name ) if app_params . params is not None : if u'${USER}' in app_params . params : kv [ u'target_application_account' ] = target_login_info . account_login or self . target_context . login or "" if u'${PASSWORD}' in app_params . params : kv [ u'target_application_password' ] = ( self . engine . get_target_password ( selected_target ) or self . engine . get_primary_password ( selected_target ) or '' ) self . target_app_rights [ kv [ u'target_application' ] ] = ( selected_target , app_params ) # kv[u'target_application'] = selected_target.service_login kv [ u'disable_tsk_switch_shortcuts' ] = u'yes' self . cn = target_login_info . target_name if self . target_context . host : kv [ u'target_host' ] = self . target_context . host kv [ u'target_device' ] = self . target_context . showname ( ) else : kv [ u'target_host' ] = physical_info . device_host kv [ u'target_login' ] = physical_info . account_login if ( not kv . get ( u'target_login' ) and self . target_context . login and not application ) : # on application, # login in target_context is the login of application kv [ u'target_login' ] = self . target_context . login kv [ u'target_port' ] = physical_info . service_port kv [ u'device_id' ] = physical_info . device_id try : auth_policy_methods = self . engine . get_target_auth_methods ( physical_target ) Logger ( ) . info ( "auth_mode_passthrough=%s" % self . passthrough_mode ) target_password = '' if self . passthrough_mode : kv [ u'target_login' ] = self . passthrough_target_login if self . shared . get ( u'password' ) == MAGICASK : target_password = u'' else : target_password = self . shared . get ( u'password' ) # Logger().info( #     "auth_mode_passthrough target_password=%s" % #     target_password # ) kv [ u'password' ] = u'password' elif PASSWORD_VAULT in auth_policy_methods : target_passwords = self . engine . get_target_passwords ( physical_target ) target_password = u'\x01' . join ( target_passwords ) if ( not target_password and PASSWORD_MAPPING in auth_policy_methods ) : target_password = ( self . engine . get_primary_password ( physical_target ) or '' ) force_sc_auth = conn_opts . get ( u'rdp' , { } ) . get ( u'force_smartcard_authentication' , False ) Logger ( ) . info ( "force_smartcard_authentication = %s" % force_sc_auth ) allow_interactive_password = ( ( PASSWORD_INTERACTIVE in auth_policy_methods or self . passthrough_mode ) and not force_sc_auth ) allow_interactive_login = not force_sc_auth kv [ u'target_password' ] = target_password is_interactive_login = ( not bool ( kv . get ( 'target_login' ) ) and not force_sc_auth ) extra_kv , _status , _error = self . complete_target_info ( kv , allow_interactive_password , allow_interactive_login ) kv . update ( extra_kv ) if self . target_context . host : self . _physical_target_host = self . target_context . host elif ( '/' in physical_info . device_host and extra_kv . get ( u'target_host' ) != MAGICASK ) : self . _physical_target_host = extra_kv . get ( u'target_host' ) else : self . _physical_target_host = physical_info . device_host Logger ( ) . info ( u"Send critic notification " u"(every attempt to connect to some physical node)" ) if extra_info . is_critical : Logger ( ) . info ( "CRITICAL CONNECTION" ) import socket self . engine . NotifyConnectionToCriticalEquipment ( ( u'APP' if application else proto_info . protocol ) , self . shared . get ( u'login' ) , socket . getfqdn ( self . shared . get ( u'ip_client' ) ) , self . shared . get ( u'ip_client' ) , self . shared . get ( u'target_login' ) , self . shared . get ( u'target_device' ) , self . _physical_target_host , ctime ( ) , None ) update_args = { "is_application" : bool ( application ) , "target_host" : self . _physical_target_host , "session_log_path" : self . full_log_path } if is_interactive_login : update_args [ "effective_login" ] = kv . get ( 'target_login' ) if self . shared . get ( 'width' ) : update_args [ "video_width" ] = int ( self . shared . get ( 'width' ) ) if self . shared . get ( 'height' ) : update_args [ "video_height" ] = int ( self . shared . get ( 'height' ) ) self . engine . update_session_target ( physical_target , * * update_args ) if ( _status and 'vnc_over_ssh' in conn_opts and conn_opts . get ( "vnc_over_ssh" ) . get ( "enable" ) ) : _status , _error = self . _load_vnc_over_ssh_options ( kv , conn_opts ) if not _status : Logger ( ) . info ( u"(%s):%s:REJECTED : User message: \"%s\"" % ( mundane ( self . shared . get ( u'ip_client' ) ) , mundane ( self . shared . get ( u'login' ) ) , _error ) ) kv = { u"login" : u"" , u'password' : u"" , u'target_login' : u"" , u'target_password' : u"" , u'target_device' : u"" , u'target_host' : u"" , u'rejected' : _error , } try_next = False logtimer . stop ( "CHECKOUT_TARGET" ) try : ########### # SEND KV # ########### self . send_data ( kv ) Logger ( ) . info ( u"Added connection to active Bastion services" ) # Looping on keepalived socket while True : r = [ ] got_signal = False try : r , w , x = select ( [ self . proxy_conx ] , [ ] , [ ] , KEEPALIVE_TIMEOUT ) except BastionSignal as e : Logger ( ) . info ( "Got Signal %s" % e ) got_signal = True except Exception as e : if DEBUG : Logger ( ) . info ( "exception: '%s'" % e ) import traceback Logger ( ) . info ( "<<<<%s>>>>" % traceback . format_exc ( ) ) raise self . engine . keepalive ( timeout = KEEPALIVE_TIMEOUT ) current_time = time ( ) if self . check_session_parameters : self . update_session_parameters ( current_time ) self . check_session_parameters = False self . rtmanager . check ( current_time ) if self . proxy_conx in r : _status , _error = self . receive_data ( Sesman . EXPECTING_KEYS , blocking_call = False ) if self . _changed_keys : self . update_session_data ( self . _changed_keys ) self . process_target_connection_time ( ) if self . shared . get ( u'auth_notify' ) : self . handle_auth_notify ( physical_target ) self . shared [ u'auth_notify' ] = u'' if ( not trace_written and ( self . shared . get ( 'recording_started' ) == 'True' ) ) : _status , _error = self . handle_recording_started ( ) trace_written = True if self . shared . get ( "pm_request" ) : self . _manage_pm ( ) self . handle_shadowing ( ) if self . shared . get ( u'reporting' ) : report_status = self . handle_reporting ( ) if not report_status : try_next = True break if self . shared . get ( u'disconnect_reason_ack' ) : break if self . shared . get ( u'auth_channel_target' ) : self . handle_auth_channel_target ( selected_target ) self . shared [ u'auth_channel_target' ] = u'' if self . shared . get ( u'module' ) == u"close" : break if self . shared . get ( u'keepalive' ) == MAGICASK : self . send_data ( { u'keepalive' : u'True' } ) # r can be empty else : # (if self.proxy_conx in r) if not self . internal_target and not got_signal : Logger ( ) . info ( u'Missing Keepalive' ) Logger ( ) . error ( u'break connection' ) break if self . shared . get ( u'module' ) == u"close" : close_box = True Logger ( ) . debug ( u"End Of Keep Alive" ) except AuthentifierSocketClosed : if DEBUG : import traceback Logger ( ) . info ( u"RDP/VNC connection terminated by client" ) Logger ( ) . info ( "<<<%s>>>" % traceback . format_exc ( ) ) except Exception : if DEBUG : import traceback Logger ( ) . info ( u"RDP/VNC connection terminated by client" ) Logger ( ) . info ( "<<<%s>>>" % traceback . format_exc ( ) ) if not try_next : break finally : self . engine . release_target ( physical_target ) self . engine . release_all_target ( ) Logger ( ) . info ( u"Stop session ..." ) # Notify WabEngine to stop connection if it has been # launched successfully self . engine . stop_session ( title = u"End session" ) if self . tun_process : self . tun_process . stop ( ) self . tun_process = None Logger ( ) . info ( u"Stop session done." ) if self . shared . get ( u"module" ) == u"close" : if close_box and self . back_selector : try : self . send_data ( { u'module' : u'close_back' , u'selector' : u'False' } ) while True : _status , _error = self . receive_data ( ) if ( _status and self . shared . get ( u'selector' ) == MAGICASK ) : return None , "Go back to selector" except Exception : _status , _error = False , "End of Session" else : self . send_data ( { u'module' : u'close' } ) # Error if try_next : _status , _error = self . interactive_close ( self . reporting_target , self . reporting_message ) try : Logger ( ) . info ( u"Close connection ..." ) self . proxy_conx . close ( ) Logger ( ) . info ( u"Close connection done." ) except IOError : if DEBUG : Logger ( ) . info ( u"Close connection: Exception" ) Logger ( ) . info ( "<<<<%s>>>>" % traceback . format_exc ( ) ) return False , "End of Session"