
    hl                        S r SSKJr  SSKJrJr  SSKJrJrJ	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Jr   " S
 S5      r " S S5      r\" \R0                  5       " S S5      5       r " S S\R4                  5      rS rg)z\
TAP plugin for creating telnet- and ssh-accessible manhole servers.

@author: Jp Calderone
    )implementer)servicestrports)manholemanhole_sshtelnet)insults)keys)checkersportal)protocol)filepathusagec                        \ rS rSrS rS rSrg)makeTelnetProtocol   c                     Xl         g Nr   )selfr   s     `/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/manhole_tap.py__init__makeTelnetProtocol.__init__   s        c                 j    [         R                  nU R                  4n[         R                  " U/UQ76 $ r   )r   AuthenticatingTelnetProtocolr   TelnetTransport)r   authargss      r   __call__makeTelnetProtocol.__call__   s.    22~%%d2T22r   r   N__name__
__module____qualname____firstlineno__r   r    __static_attributes__ r   r   r   r      s    3r   r   c                        \ rS rSrS rS rSrg)chainedProtocolFactory   c                     Xl         g r   	namespace)r   r.   s     r   r   chainedProtocolFactory.__init__    s    "r   c                 `    [         R                  " [        R                  U R                  5      $ r   )r	   ServerProtocolr   ColoredManholer.   r   s    r   r    chainedProtocolFactory.__call__#   s    %%g&<&<dnnMMr   r-   Nr"   r(   r   r   r*   r*      s    #Nr   r*   c                        \ rS rSrS rS rSrg)_StupidRealm'   c                 (    Xl         X l        X0l        g r   )protocolFactoryprotocolArgsprotocolKwArgs)r   protoakws       r   r   _StupidRealm.__init__)   s    $ r   c                     [         R                  U;   a8  [         R                  U R                  " U R                  0 U R                  D6S 4$ [        5       e)Nc                      g r   r(   r(   r   r   <lambda>,_StupidRealm.requestAvatar.<locals>.<lambda>3   s    r   )r   ITelnetProtocolr9   r:   r;   NotImplementedError)r   avatarId
interfacess      r   requestAvatar_StupidRealm.requestAvatar.   sP    !!Z/&&$$d&7&7O4;N;NO 
 "##r   )r:   r9   r;   N)r#   r$   r%   r&   r   rH   r'   r(   r   r   r6   r6   '   s    !
$r   r6   c                   H    \ rS rSr/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/rS rS	 rS
rg)Options8   )
telnetPorttNzMstrports description of the address on which to listen for telnet connections)sshPortsNzJstrports description of the address on which to listen for ssh connections)passwdpz/etc/passwdz1name of a passwd(5)-format username/password file)	sshKeyDirN<USER DATA DIR>z2Directory where the autogenerated SSH key is kept.)
sshKeyNameNz
server.keyz&Filename of the autogenerated SSH key.)
sshKeySizeNi   z,Size of the automatically generated SSH key.c                 L    [         R                  R                  U 5        S U S'   g )Nr.   )r   rK   r   r3   s    r   r   Options.__init__\   s    t$ [r   c                 J    U S   c  U S   c  [         R                  " S5      eg g )NrM   rO   z<At least one of --telnetPort and --sshPort must be specified)r   
UsageErrorr3   s    r   postOptionsOptions.postOptions`   s5    %$y/*A""N  +B%r   r(   N)r#   r$   r%   r&   optParametersr   r[   r'   r(   r   r   rK   rK   8   s2    	
	
	
	
 	URA!MF!r   rK   c                    [         R                  " 5       nU S   nUc  0 n[        R                  " U S   5      nU S   (       a  [	        [
        R                  [        R                  [        R                  U5      n[        R                  " XC/5      n[        R                  " 5       n[        U5      Ul        [         R                   " U S   U5      nUR#                  U5        U S   (       Ga   [$        R&                  " 5       n[)        U5      Ul        [        R                  " X/5      n	[$        R*                  " U	5      n
U S   S:w  a  U S   nOSSKJn  U" 5       n[0        R2                  " U5      R5                  U S	   5      n[6        R8                  " U[;        U S
   5      5      nXR<                  S'   XR>                  S'   [         R                   " U S   U
5      nUR#                  U5        U$ )a  
Create a manhole server service.

@type options: L{dict}
@param options: A mapping describing the configuration of
the desired service.  Recognized key/value pairs are::

    "telnetPort": strports description of the address on which
                  to listen for telnet connections.  If None,
                  no telnet service will be started.

    "sshPort": strports description of the address on which to
               listen for ssh connections.  If None, no ssh
               service will be started.

    "namespace": dictionary containing desired initial locals
                 for manhole connections.  If None, an empty
                 dictionary will be used.

    "passwd": Name of a passwd(5)-format username/password file.

    "sshKeyDir": The folder that the SSH server key will be kept in.

    "sshKeyName": The filename of the key.

    "sshKeySize": The size of the key, in bits. Default is 4096.

@rtype: L{twisted.application.service.IService}
@return: A manhole service.
r.   rQ   rM   rO   rS   rT   r   )getDataDirectoryrU   rV   s   ssh-rsa) r   MultiServicer   FilePasswordDBr6   r   TelnetBootstrapProtocolr	   r1   r   r2   r   Portalr   ServerFactoryr   r   setServiceParentr   TerminalRealmr*   ConchFactorytwisted.python._appdirsr_   r   FilePathchildr
   _getPersistentRSAKeyint
publicKeysprivateKeys)optionssvcr.   checkertelnetRealmtelnetPortaltelnetFactorytelnetServicesshRealm	sshPortal
sshFactorykeyDirr_   keyLocationsshKey
sshServices                   r   makeServicer}   g   s   > 


 C$I	%%gh&78G|"**""""	
 }}[)< ..0!3L!A (()>N&&s+y,,.*@*K'MM(I6	 --i8
;#44[)F@%'F''/55gl6KL**;GL<Q8RS,2j)-3z*%%gi&8*E
##C(Jr   N)__doc__zope.interfacer   twisted.applicationr   r   twisted.conchr   r   r   twisted.conch.insultsr	   twisted.conch.sshr
   twisted.credr   r   twisted.internetr   twisted.pythonr   r   r   r*   IRealmr6   rK   r}   r(   r   r   <module>r      sv    ' 1 6 6 ) " ) % *3 3N N V]]$ $ $ ,emm ,^Mr   