
    h\                     @   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r  SSKJr  SSKJrJr  SSKJr  SSKJr  SSKJrJrJrJrJrJrJrJr  SSKJ r   SSK!J"r"J#r#J$r$J%r%  SS	K&J'r'J(r(   " S
 S\RR                  5      r* " S S\(RV                  5      r,Sq-Sq.Sq/Sq0S r1S r2S r3 " S S\#Rh                  5      r5 " S S\Rl                  5      r6 " S S\Rn                  5      r7 " S S\Rp                  5      r8 " S S\Rr                  5      r:\;S:X  a  \2" 5         gg)z2
Implementation module for the `tkconch` command.
    N)ListTuple)error)isInKnownHosts)channelcommon
connection
forwardingkeyssession	transportuserauth)tkvt100)deferprotocolreactor	tksupport)logusagec                   2    \ rS rSrS rS rS rS rS rSr	g)	TkConchMenu&   c                 (   [         R                  R                  " U /UQ70 UD6  U R                  R	                  S5        [         R
                  " 5       U l        U R                  R                  S5        [         R                  " U SSSS9R                  SSSS9  [         R                  " U 5      U l        U R                  R                  S	S	SS
S9  [         R                  " U SSSS9R                  SS	SS9  [         R                  " U 5      U l        U R                  R                  S	S	S	S
S9  [         R                  " U SSSS9R                  SSSS9  [         R                  " U 5      U l        U R                  R                  S	S	SS
S9  [         R                  " U SSSS9R                  SSSS9  [         R                  " U 5      U l        U R                  R                  S	S	SS
S9  [         R                  " U SSSS9R                  SSSS9  [         R                  " U 5      U l        U R                  R                  S	SS
S9  [         R                   " X R"                  SS9R                  SSS
S9  [         R                  " U SS9R                  SSSS9  [         R$                  " U SSS9U l        U R&                  R                  S	S	SS
S9  [         R                   " U SU R(                  S9R                  SSS9  [         R                   " U SU R*                  S9R                  SSS9  [         R                  " U 5      U l        U R,                  R                  S	SS
S9  [         R                  " U SS9R                  SSS
S9  [         R                  " U 5      U l        U R.                  R                  S	SS
S9  [         R                  " U S S9R                  SSS
S9  [         R0                  " U S!U R                  SS"9U l        U R2                  R                  S	S#S9  [         R0                  " U S$U R                  S%S"9U l        U R4                  R                  SS#S9  [         R                  " U S&S9R                  SSS'S
S9  [         R                  " U SSS(S9R                  SS)SS9  [         R                  " U S*S+9U l        U R6                  R                  S	S	S)S
S9  [         R                  " U SSS,S9R                  SS-SS9  [         R                  " U S.S+9U l        U R8                  R                  S	S	S-S
S9  [         R                  " U SSS/S9R                  SS0SS9  [         R                  " U S1S+9U l        U R:                  R                  S	S	S0S
S9  [         R                   " U S2U R<                  S9R                  SSS3S
S9  U R?                  SSS4S59  U RA                  S	SS	S59  U R                  RC                  S6[D        RF                  5        g )7NTkConchlocalwleftHostname)anchorjustifytext   )columnrowsticky   nesw)r#   
columnspanr$   r%   PortUsername   Command   Identity   Browse)commandr!   zPort Forwarding)r!      r   )heightwidthAdd)r!   r1      )r#   r$   Remove   HostLocal)r!   variablevalue	   RemoteremotezAdvanced Options
   Cipher   cipher)nameMAC   maczEscape Char   escapezConnect!   @   )weightminsizeWM_DELETE_WINDOW)$TkinterFrame__init__mastertitle	StringVarlocalRemoteVarsetLabelgridEntryhostportuserr1   identityButtongetIdentityFileListboxforwards
addForwardremoveForwardforwardPortforwardHostRadiobuttonlocalForwardremoteForwardrC   rG   rI   	doConnectgrid_rowconfiguregrid_columnconfigurer   sysexit)selfargsparamss      d/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/scripts/tkconch.pyrQ   TkConchMenu.__init__'   s   t5d5f5)$%//1(d3ZHMM!C 	N 	
 MM$'			aA1VDd3VDII!C 	J 	
 MM$'			aA1VDd3ZHMM!C 	N 	
 MM$'			aA1VDd3YGLL!C 	M 	
 }}T*qaGd3ZHMM!C 	N 	
  d+!6:t%9%9INN!F 	O 	
 	d!2388qQT8UQa@!qHt%AFFaUVFWt(D4F4FGLL! 	M 	
 #==.QAf=d(--QAf-M"==.QAf=d(--QAf-M#//w)<)<G
 	aQ/$00x$*=*=X
 	qa0d!34996 	: 	
 	d3XFKK"S 	L 	
 mmDx8aRGd3UCHH"S 	I 	
 ==E2Q1"VDd3]KPP"S 	Q 	
 mmDx8aRGt*dnnEJJ6 	K 	

 	qB7!!!Aq!9/:    c                     [         R                  " 5       nU(       aU  U R                  R                  S[        R
                  5        U R                  R                  [        R
                  U5        g g Nr   )tkFileDialogaskopenfilenamer]   deleterO   ENDinsert)rn   rs     rq   r_   TkConchMenu.getIdentityFile   sH    ((*MM  GKK0MM  a0 rs   c                    U R                   R                  5       nU R                   R                  S[        R                  5        U R
                  R                  5       nU R
                  R                  S[        R                  5        U R                  R                  5       S:X  a1  U R                  R                  [        R                  SU SU 35        g U R                  R                  [        R                  SU SU 35        g )Nr   r   L::R:)	rd   getrx   rO   ry   re   rU   ra   rz   )rn   r[   rZ   s      rq   rb   TkConchMenu.addForward   s    ##%7;;/##%7;;/""$/MM  4&$.@AMM  4&$.@Ars   c                     U R                   R                  5       nU(       a  U R                   R                  US   5        g g ru   )ra   curselectionremove)rn   curs     rq   rc   TkConchMenu.removeForward   s2    mm((*MM  Q( rs   c                 n	   SnU R                   R                  5       [        S'   U R                  R                  5       [        S'   U R                  R                  5       [        S'   U R
                  R                  5       [        S'   U R                  R                  5       nU R                  R                  5       nU R                  R                  5       nU(       a:  U[        R                  ;   a  U/[        l
        O[        R                  " SS5        SnU(       aA  U[        R                  ;   a  U/[        l        O U(       a  [        R                  " SS	5        SnU(       a  US
:X  a
  S [        S'   OvUS   S:X  a1  [        U5      S:X  a"  [        [!        US   5      S-
  5      [        S'   O<[        U5      S:X  a
  U[        S'   O#U(       a  [        R                  " SSU-  5        SnU R"                  R                  5       (       a7  [        R$                  R'                  U R"                  R                  5       5        U R(                  R                  S[*        R,                  5       H>  nUS   S:X  a  [        R/                  USS  5        M&  [        R1                  USS  5        M@     S[        S   ;   a*  [        S   R3                  SS5      u  [        S'   [        S'   [        S   (       a  [        S   (       d   U(       a  [        R                  " SS5        SnU(       Ga~  U R4                  R7                  5         U R4                  R9                  5         [        S   (       a@  [:        R<                  n[>        R@                  " [:        RB                  5        U[:        l        O[>        RD                  " 5         [F        [>        l$        [        R$                  (       d  SS/[        l        [        S   n[K        [        S   =(       d    S5      n[>        RL                  " Xx45        [N        RP                  " Xx[S        5       5        [T        R4                  RW                  5         [T        R4                  RY                  SR[                  [        S   [        S   5      5        g U R]                  5         g )Nr"   rZ   r[   r\   r1   r   zBad cipher.r   zBad MAC.nonerI   ^r&   rK   zBad escape character '%s'.L@zMissing host or username.r   z~/.ssh/id_rsaz~/.ssh/id_dsa   z{}@{} - TkConch)/rZ   r   optionsr[   r\   r1   rC   rG   rI   SSHClientTransportsupportedCipherstkMessageBox	showerrorsupportedMACslenchrordr]   	identitysappendra   rO   ry   opt_localforwardopt_remoteforwardsplitrR   quitdestroyrl   stdoutr   startLoggingstderrdiscardLogshandleErrordeferrintmsgr   
connectTCPSSHClientFactoryframe	deiconifyrS   formatfocus)	rn   finishedrC   rG   rI   linerealoutrZ   r[   s	            rq   ri   TkConchMenu.doConnect   s<   ))--/))--/))--/!\\--/	"hhlln"+<<<7=h"3&&y-@(666475"0&&y*=$(!c!c&kQ&6$'F1I(;$<!V!$*!&&y2NQW2WX==$$T]]%6%6%89MM%%a5DAw#~((ab2))$qr(3	 6 '&/!/6v/D/DS!/L,GFOWV_wvH""9.IJHKKKK!u~**  ,$
!$CJ$$%4o$F!6?Dwv,"-DGGTL!t+;+=>LL""$LL!(('&/J JJLrs   )rC   r1   rI   re   rd   ra   rZ   r]   rg   rU   rG   r[   rh   r\   N)
__name__
__module____qualname____firstlineno__rQ   r_   rb   rc   ri   __static_attributes__ rs   rq   r   r   &   s    \;|1B)
Frs   r   c                      \ rS rSr% Sr/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ S	Q/ S
Q/r/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/r\R                  R                  r
\R                  R                  r\R                  " S/\R                  " \
 V Vs/ s H  oR!                  5       PM     snn 5      \R                  " \ V Vs/ s H  oR!                  5       PM     snn 5      \R"                  " SS9\R"                  " SS9S.\R$                  " 5       \R"                  " SS9\R"                  " SSS9/S9r/ r\\   \S'   / r\\\\\\4   4      \S'   / r\\\\\\4   4      \S'   S rS  rS! rS" rS# r S$r!g%s  snn f s  snn f )&GeneralOptions   z,Usage:    tkconch [options] host [command]
 )r\   lNzLog in using this user name.)r]   iz~/.ssh/identityz&Identity for public key authentication)rI   e~z(Set escape character; ``none'' = disable)rC   cNzSelect encryption algorithm.)macsmNz.Specify MAC algorithms for protocol version 2.)r[   pNz7Connect to this port.  Server must be on the same port.)localforwardr   Nz<listen-port:host:port   Forward local port to remote address)remoteforwardRNz<listen-port:host:port   Forward remote port to local address)ttytz-Tty; allocate a tty even if command is given.)nottyTzDo not allocate a tty.)versionVzDisplay version number only.)compressCzEnable compression.)noshellNz"Do not execute a shell or command.)	subsystemsz-Invoke command (mandatory) as SSH2 subsystem.)r   vzLog to stderr)ansilogaz!Print the received data to stdout)r   r   zlisten-port:host:port)descr)rC   r   r   r   r1   argumentT)r   repeat)mutuallyExclusive
optActionsextraActionsr   localForwardsremoteForwardsc                 :    U R                   R                  U5        g N)r   r   )rn   r   s     rq   opt_identityGeneralOptions.opt_identity  s    a rs   c                     UR                  S5      u  p#n[        U5      n[        U5      nU R                  R                  X#U445        g Nr   )r   r   r   r   )rn   f	localPort
remoteHost
remotePorts        rq   r   GeneralOptions.opt_localforward   sB    ,-GGCL)	z	N	_
!!9:.F"GHrs   c                     UR                  S5      u  p#n[        U5      n[        U5      nU R                  R                  X#U445        g r   )r   r   r   r   )rn   r   r   connHostconnPorts        rq   r    GeneralOptions.opt_remoteforward&  sB    )*&
h_
x=""J80D#EFrs   c                 ,    S/[         R                  SS& g )Nzlibr   r"   )r   supportedCompressionsrn   s    rq   opt_compressGeneralOptions.opt_compress,  s    9?0015rs   c                 f    U(       a   US   U S'   SR                  USS  5      U S'   g SU S'   SU S'   g )Nr   rZ    r"   r1    )join)rn   ro   s     rq   	parseArgsGeneralOptions.parseArgs/  s<    7DL!hhtABx0DODL DOrs   r   N)"r   r   r   r   synopsisoptParametersoptFlagsr   r   r   _ciphersr   _macsr   CompletionsCompleteListdecode	CompleterCompleteUserAtHostcompDatar   r   str__annotations__r   r   r   r   r   r   r   r   r   r   ).0r   s   00rq   r   r      s   H 	<VH=MV	
	
M, 	F080>K%=	H ++<<H((66E  +,((h)Gh((*h)GH&&E'BEq
E'BC!OO2IJ"__3JK	
 $$&OO),OO*T:
H ItCy79M4c5c?23498:NDsE#s(O345:!IGA!E *H'Bs   	E1:E7r   c                   ^^ [         R                  (       a  [        S5      e[        R                  " 5       m/ nU4UU4S jjnU[         l        [         R                  U 5        [         R                  R                  5         T$ )Nzcan't ask 2 questions at once!c                   > U (       d  g U S:X  a  [         R                  " 5         U S:X  aD  [        R                  S5        SR	                  U5      nAS [        l        TR                  U5        g S[        U 5      s=::  a  S:  a2  O  O/UR                  U 5        T(       a  [        R                  U 5        g g [        U 5      S:X  a5  U(       a-  T(       a  [        R                  S5        UR                  5         g g g )	Nz
r          r8   z )	r   stopr   writer   callbackr   r   pop)chrespstrespdechos      rq   gotChar!deferredAskFrame.<locals>.gotCharE  s    <LLN:KKWWT]F!ENJJv3r7 S KKOB W\dK(HHJ #\rs   )r   r  
ValueErrorr   Deferredr  canvasfocus_force)questionr  r  r  r  s    `  @rq   deferredAskFramer  ?  s^    ~~9::AD  * EN	KK	LLHrs   c            
         [         R                  SS  n SU ;   a%  U R                  S5      nXUS-    U -   n XS-   US-   2	 U S S   H7  n U R                  U5      nUS S S:X  a  XS-      S   S:w  a	  / XUS-   & M5  M7  M9     [        R
                  " 5       nUR                  5         [        R                  " 5       n[        U5      q	[        R                  [        R                  [        R                  SS9  [        5       q [        R                  U 5        [        R+                  5        HS  u  pgU(       d  M  [-        [        U5      (       d  M%  [/        [        U5      R1                  [        R2                  U5        MU     [        R4                   H?  u  nu  p[        R6                  R1                  [        R2                  S
U SU	 SU
 35        MA     / [        l        [        R8                   H?  u  nu  p[        R6                  R1                  [        R2                  SU SU	 SU
 35        MA     / [        l        [:        R<                  " US S9qURA                  S[:        RB                  [>        RD                  -  S-   [:        RF                  [>        RH                  -  S-   4-  5        [>        R                  [        R                  S9  [J        RL                  " U5        UR                  5         [        S   (       a  [        S   (       d  S[        S   ;   a  [        RO                  5         OURQ                  5         [R        RT                  " 5         [         R(                  " [V        5        g ! [         a     GM:  f = f! [         R"                   aC  n[%        S	U-  5        [        R'                  5         [         R(                  " S5         S nAGNS nAff = f)Nr"   z-lr&   r-   z-or   -)sidefillexpandz	ERROR: %sr~   r   r   )r  z%dx%dr+   )r  rZ   r\   r   ),rl   argvindexr  rO   TkwithdrawToplevelr   menupackTOPBOTHr   r   parseOptionsr   
UsageErrorprintopt_helprm   itemshasattrgetattrrz   ry   r   ra   r   r   
VT100Framer   geometry	fontWidthr4   
fontHeightr3   r   installri   mainloopr   run
exitStatus)ro   r   argroottopukr   r   rhrps              rq   r6  r6  `  s   88AB<Dt|JJtA%QQAw	

3A2Aw$4A;q>S#8"$Q $9  ::<DMMO



CsDII7;;W\\!I<GT"
 1q!!D!##GKK3   ,,8BW[[Bqc2$at*<= -G--8BW[[Bqc2$at*<= .Gtd3EMMu{{*Q.0B0BU\\0QTU0U
V	W 
JJGKKJ dMMOGFOwv0FKKMHHZI  		  kAos*   /M0 N 0
M?>M?O8OOc                      SSK Jn   Sq[        R                  " U R                  5       5        [        R                  " 5         e )Nr   failurer&   )twisted.pythonrA  r7  r   errFailurer   r
  r@  s    rq   r   r     s+    & JGGGOOLLN	rs   c                   *    \ rS rSrSrS rS rS rSrg)r   i  Tc                 .    [         R                  " 5         g r   )r   r
  r   s    rq   stopFactorySSHClientFactory.stopFactory  s    rs   c                     [        5       $ r   )r   )rn   addrs     rq   buildProtocolSSHClientFactory.buildProtocol  s    !##rs   c                 f    [         R                  " SSUR                   SUR                   35        g )Nr   zConnection Failed, Reason:
 z: )r   showwarningtyper<   )rn   	connectorreasons      rq   clientConnectionFailed'SSHClientFactory.clientConnectionFailed  s+      +FKK=6<<.I	
rs   r   N)	r   r   r   r   noisyrG  rK  rR  r   r   rs   rq   r   r     s    E$
rs   r   c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
r   i  c                     SX4-  q g )NzDconch:	Remote side disconnected with error code %i
conch:	reason: %s)r7  )rn   codedescs      rq   receiveErrorSSHClientTransport.receiveError  s     Vl 	rs   c                 P    SX4-  q [        R                  R                  XU5        g )Nz>conch:	Sending disconnect with error code %i
conch:	reason: %s)r7  r   r   sendDisconnect)rn   rW  rQ  s      rq   r\  !SSHClientTransport.sendDisconnect  s/     Pn 	 	$$33DGrs   c                 b    U(       d  [         S   (       a  [        R                  " SU-  5        g g )Nr   zReceived Debug Message: %s)r   r   r   )rn   alwaysDisplaymessagelangs       rq   receiveDebugSSHClientTransport.receiveDebug  s"    GENGG07:; +rs   c                    [        [        S   USS 05      nUS:X  a  [        R                  " S5      $ US:X  a*  [        R                  " [
        R                  " S5      5      $ [        S   U R                  R                  5       R                  :X  a  [        S   n[        S   nOvSR                  [        S   U R                  R                  5       R                  5      nSR                  [        S   U R                  R                  5       R                  5      n[        R                  " U5      S   nS	R                  US
SS.U   U5      nUS-  n[        US5      R                  U R                  XU5      $ )NrZ   zknown-hostsr"   r&   bad host keyz{} ({})z{},{}r   zNThe authenticity of host '{}' can't be established.
{} key fingerprint is {}.DSARSAs   ssh-dsss   ssh-rsaz9
Are you sure you want to continue connecting (yes/no)? )r   r   r   succeedfailr   
ConchErrorr   getPeerrZ   r   r   getNSr  addCallback_cbVerifyHostKey)rn   pubKeyfingerprintgoodKeyrZ   khHostkeyTypequess           rq   verifyHostKey SSHClientTransport.verifyHostKey  sA   
 !&=$:OPa<==##\::e..~>??v$.."8"8":"?"??v  ''9O9O9Q9V9VW 9O9O9Q9V9VWll6*1-G#V"6w?  QQD#D!,88%%vw rs   c           	         UR                  5       S;  a'  [        SS5      R                  U R                  X#U5      $ UR                  5       S:X  a+  [        R                  S5        [        R                  " S5      e [        R                  SU< SS	S
S.U   < S35        [        [        R                  R                  S5      S5       n[        R                  " U5      nUR                  SU SU SU 35        S S S 5        g ! , (       d  f       g = f! [         a&    [        R                   " 5         [        R                  ef = f)N)yesnozPlease type  'yes' or 'no': r"   rz  zHost key verification failed.
re  zWarning: Permanently added 'z' (rf  rg  rh  z) to the list of known hosts.
z~/.ssh/known_hostsr   
r   )lowerr  rn  ro  r   r  r   rk  openospath
expanduserbase64	b64encodeBaseExceptionr   r   )rn   ansrp  rs  rt  known_hosts
encodedKeys          rq   ro  #SSHClientTransport._cbVerifyHostKey  s   99;m+#$BAFRR%%vw  99;$KK;<"">22	#KK 5A'JL
 bgg(()=>D#--f5
!!Bvhay*"FG EDD  	#JJL"""	#s+   <AD 	1D:D 
DD D 0Ec                     [         S   (       a
  [         S   nO[        R                  " 5       nU R                  [	        U[        5       5      5        g )Nr\   )r   getpassgetuserrequestServiceSSHUserAuthClientSSHConnection)rn   r\   s     rq   connectionSecure#SSHClientTransport.connectionSecure  s6    6?6?D??$D-dMODErs   r   N)r   r   r   r   rY  r\  rb  rv  ro  r  r   r   rs   rq   r   r     s"    
H<
:#*Frs   r   c                   F    \ rS rSr% / r\\   \S'   S	S jrS r	S r
S rSrg)
r  i  	usedFilesNc                 n    U(       d#  SR                  U R                  [        S   5      n[        US5      $ )Nz{}@{}'s password: rZ   r   )r   r\   r   r  )rn   prompts     rq   getPasswordSSHUserAuthClient.getPassword  s,    )00GFOLF**rs   c                    [         R                   Vs/ s H  oU R                  ;  d  M  UPM     nnU(       d  g US   n[        R                  " U5        U R                  R                  U5        [        R                  R                  U5      nUS-  n[        R                  R                  U5      (       d  g  [        R                  R                  U5      R                  5       $ s  snf ! [         a    U R                  5       s $ f = f)Nr   z.pub)r   r   r  r   r   r   r~  r  r  existsr   KeyfromFileblobr  getPublicKey)rn   xfilesfiles       rq   r  SSHUserAuthClient.getPublicKey  s    #--I-q$..1H-IQxd#ww!!$'ww~~d##	'88$$T*//11 J  	'$$&&	's   C'C':,C, ,D	D	c                    [         R                  R                  U R                  S   5      n[         R                  R	                  U5      (       d  g  [
        R                  " [        R                  R                  U5      R                  5      $ ! [        R                   aZ  nUR                  S   S:X  a=  SU R                  S   -  n[        US5      R                  U R                  S5      s S nA$  S nAg S nAff = f)Nr   zencrypted key with no passwordEnter passphrase for key '%s': )r~  r  r  r  r  r   ri  r   r  r  	keyObjectBadKeyErrorro   r  rn  _cbGetPrivateKey)rn   r  r   r  s       rq   getPrivateKeySSHUserAuthClient.getPrivateKey  s    ww!!$.."45ww~~d##	Y==!2!24!8!B!BCC 	Yvvay<<:T^^B=OO'2>>t?T?TVWXX =	Ys   <B C>$A
C9.C>9C>c                 b   [         R                  R                  U R                  S   5      n [        R
                  R                  X1S9R                  $ ! [        R                   aE    US:X  a  e SU R                  S   -  n[        US5      R                  U R                  US-   5      s $ f = f)Nr  )passwordr&   r  r   r"   )r~  r  r  r  r   r  r  r  r  r  rn  r  )rn   r  countr  r  s        rq   r  "SSHUserAuthClient._cbGetPrivateKey  s    ww!!$.."45	88$$T$8BBB 	z69KKF#FA.::%%uqy 		s   &A AB.-B.r   r   )r   r   r   r   r  r   r  r  r  r  r  r  r   r   rs   rq   r  r    s%    ItCy+
' 	Y
rs   r  c                       \ rS rSrS rSrg)r  i,  c           	      :   [         S   (       d  U R                  [        5       5        [         R                  (       aS  [         R                   H?  u  p[        R
                  " U[        R                  " X[        R                  5      5        MA     [         R                  (       aw  [         R                   Hb  u  p2[        R                  " SR                  X25      5        [        R                  " SU45      nU R                  SU5        X R                  U'   Md     g g )Nr   z&asking for remote forwarding for {}:{}z0.0.0.0ztcpip-forward)r   openChannel
SSHSessionr   r   	listenTCPr
   SSHListenForwardingFactory SSHListenClientForwardingChannelr   r   r   r   packGlobal_tcpip_forwardsendGlobalRequest)rn   r   hostportr   datas        rq   serviceStartedSSHConnection.serviceStarted-  s    y!Z\*  '.'<'<#	!!99
(S(S (= !!(/(>(>$
<CC"
 "::Iz;RS&&=2:##J/ )? "rs   r   N)r   r   r   r   r  r   r   rs   rq   r  r  ,  s    ;rs   r  c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)r  iD  s   sessionc                 l   SU l         [        R                  " 5       n[        S   (       a  U R                  Ul        OU R                  Ul        U R                  Ul        UR
                  [        l
        [        R                  R                  5         [        S   (       a:  U R                  R                  U S[        R                   " [        S   5      5        GO,[        S   (       a  [        S   (       aV  ["        R$                  R'                  SS5      nS	n[        R(                  " X4S
5      nU R                  R                  U SU5        U R                  R                  U S[        R                   " [        S   5      5        O[        S   (       dV  ["        R$                  R'                  SS5      nS	n[        R(                  " X4S
5      nU R                  R                  U SU5        U R                  R                  U SS5        U R                  R*                  R*                  R-                  S5        g )Nr"   rI   r   s	   subsystemr1   r   TERMxterm)   P   r   r   r   s   pty-reqexecr   s   shellrs   )
escapeModer   SSHSessionClientr   handleInputdataReceivedr  sendEOFconnectionLostr   r  r  r  connsendRequestr   NSr~  environr   packRequest_pty_reqr   setTcpNoDelay)rn   foor   termwinSize
ptyReqDatas         rq   channelOpenSSHSession.channelOpenG  s}    $$&8!--AN!ZZAN<<  ";II!!$fii	@R6STYu~zz~~fg6($88K
		%%dJ
CII!!$		'):L0MN7#zz~~fg6($88K
		%%dJ
CII!!$#6		%%33A6rs   c                 x   US;   a  SU l         U R                  U5        g U R                   S:X  a  U[        S   :X  a  SU l         g U R                   S:X  a  SU l         US:X  a,  [        R                  " S5        [
        R                  " 5         g US:X  a9  [        R                  " [        R                  " 5       [        R                  5        g US:X  a;  [        R                  " S	5        U R                  R                  R                  5         g U R                  S
U-   5        g SU l         U R                  U5        g )N)r{  r  r"   rI   r&   .zdisconnecting from escaper   zrekeying connectionr   r   )r  r  r   r   r   r   r
  r~  killgetpidsignalSIGSTOPr  r   sendKexInit)rn   chars     rq   r  SSHSession.handleInputh  s    <DOJJt__!dgh.?&?DO__!DOs{34		V^^4-.		##//1JJsTz"DOJJtrs   c                     UR                  S5      n[        S   (       a  [        [        U5      5        [        R                  U5        g )Nzutf-8r   )r   r   r+  reprr   r  rn   r  s     rq   r  SSHSession.dataReceived  s0    {{7#9$t*Drs   c                     U[         R                  :X  a`  [        R                  " S[	        U5      -  5        [
        R                  R                  U5        [
        R                  R                  5         g g )Nzgot %s stderr data)	r	   EXTENDED_DATA_STDERRr   r   r   rl   r   r  flush)rn   r   r  s      rq   extReceivedSSHSession.extReceived  sM    
///GG(3t945JJT"JJ 0rs   c                 l    [         R                  " S5        [        R                  R	                  5         g )Nzgot eof)r   r   rl   stdincloser   s    rq   eofReceivedSSHSession.eofReceived  s    			rs   c                     [         R                  " SU -  5        [        U R                  R                  5      S:X  a  [
        R                  " 5         g g )Nz	closed %sr"   )r   r   r   r  channelsr   r
  r   s    rq   closedSSHSession.closed  s8    d"#tyy!!"a'LLN (rs   c                     [        [        R                  " SU5      S   5      q[        R
                  " S[        -  5        g )Nz>Lr   zexit status: %s)r   structunpackr7  r   r   r  s     rq   request_exit_statusSSHSession.request_exit_status  s.    tT2156
!J./rs   c                 :    U R                   R                  U 5        g r   )r  r  r   s    rq   r  SSHSession.sendEOF  s    		$rs   )r  N)r   r   r   r   rD   r  r  r  r  r  r  r  r  r   r   rs   rq   r  r  D  s0    D7B4
0
 rs   r  __main__)<__doc__r  r  r~  r  r  rl   tkinterrO   tkinter.filedialog
filedialogrv   tkinter.messagebox
messageboxr   typingr   r   twisted.conchr   twisted.conch.client.defaultr   twisted.conch.sshr   r   r	   r
   r   r   r   r   twisted.conch.uir   twisted.internetr   r   r   r   rB  r   r   rP   r   Optionsr   r   r%  r7  r   r  r6  r   ClientFactoryr   r   r  r  
SSHChannelr  r   r   rs   rq   <module>r     s  

   	   
  ) )   7	 	 	 % @ @ %z'-- zzR!U]] R!l 
B0f

x-- 
 LF55 LF^-22 -`;J,, ;0Y ## Y x zE rs   