
    Mg                         S SK JrJrJ r Jr  S SKJr  S SKr\" \S9\ " S5       " S S5      5       5       r\" \S9\ " S5       " S S	5      5       5       rg)
    )LINUXWINDOWSpluginrequire)ForeN)platformwific                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
WifiPasswordGetterLINUX   z
A Jarvis plugin for Linux, that will find and display all the profiles of the
wifis that you have connected to and then display the password if selected.

c                     U R                  5       nU R                  X5      nUS:X  a  g U R                  X4S-
     5      nUR                  SS5      S   nUR	                  SX4S-
     -   S-   U-   5        g )Nexit   =Wifi Name: 
Password: )get_wifi_profilesshow_optionsdisplay_passwordsplitsay)selfjarvissprofileschoicepasswordstrip_passwords          J/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/wifi_password_getter.py__call__ WifiPasswordGetterLINUX.__call__   s    ))+""64V((1*)=>!Q/2

=8QJ#77!"$23 	4    c                     [         R                  " SS/S[         R                  [         R                  S9nUR	                  5       u  p#UR                  S5      nU$ )+
Returns the names of the connected wifis.
ls'/etc/NetworkManager/system-connections/T)universal_newlinesstdoutstderr
)
subprocessPopenPIPESTDOUTcommunicater   )r   outresr)   datas        r   r   )WifiPasswordGetterLINUX.get_wifi_profiles   sT      I K26&0oo&0&7&7	9
 )yyr"   c                    Sn[        [        U5      S-
  5       H,  nX$   nUR                  [        U5      S-   U-   5        US-   nM.     UR                  [        U5      S-   5        U R	                  SX3U5      nUS:X  a  gU$ )z
Displays the names of the connected wifis and returns the number of the selected.

Parameters
----------
jarvis: JarvisAPI
    An instance of the JarvisAPI class.
arr: list
    The list with the wifi names.
r   : : Exit Please select a number or Exit: r   )rangelenr   str
get_choice)r   r   arrcountxoptionr   s          r   r   $WifiPasswordGetterLINUX.show_options&   s     s3x!|$AVFJJs5zD(612AIE % 	

3u:()!C!&v7R<Mr"   c                 :     [        UR                  U[        R                  5      5      nXS:X  a  gXR::  a  U$ UR	                  S[        R
                  5         UR	                  S5        Mk  ! [         a#    UR	                  S[        R
                  5         N?f = f)a5  
Returns the number of the selected wifi.

Parameters
----------
input_text: str
    The text to be printed when asking for input.
max_valid_value: int
    The max valid value for the choices.
terminator: int
    The value to terminate the procedure.
jarvis: JarvisAPI
    An instance of the JarvisAPI class.
r8   z7Invalid input! Enter a number from thechoices provided.8Invalid input! Enter a number from the choices provided. intinputr   GREENr   YELLOW
ValueError)r   
input_textmax_valid_value
terminatorr   inserted_values         r   r<   "WifiPasswordGetterLINUX.get_choice>   s     !!$V\\*djj%I!J!/#6))JJ,-1[[: JJrN   !

NKK!!s   .A- A-  A- -*BBc                     Sn[         R                  " SU U 3/SS[         R                  [         R                  S9nUR	                  5       u  pEU$ )zp
Returns the password of the selected wifi.

Parameters
----------
ssid: str
    The name of the selected wifi.
r&   zsudo grep -r '^psk=' T)shellr'   r(   r)   )r+   r,   r-   r.   r/   )r   ssidpathdisplaynew_resr)   s         r   r   (WifiPasswordGetterLINUX.display_password^   sW     9""&;D6$$H#I)-$*4//*4*;*;= $//1r"    N__name__
__module____qualname____firstlineno____doc__r    r   r   r<   r   __static_attributes__rW   r"   r   r   r      s!    40@r"   r   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
WifiPasswordGetterWINDOWSp   z
A Jarvis plugin for Windows, that will find and display all the profiles of the
wifis that you have connected to and then display the password, if selected or
display instantly the password of the requested wifi, e.g. wifi or wifi wifi_name.
c                    U(       a  U R                  X5        g U R                  5       n[        U5      S:X  a!  UR                  S[        R
                  5        g U R                  X5      nUS:X  a  g U R                  XUS-
     5        g )Nr   zNo connected wifi found!r8   r   )r   r   r:   r   r   rI   r   )r   r   r   r   r   s        r   r    "WifiPasswordGetterWINDOWS.__call__y   st    !!&,--/H8}!

5t{{C&&v8F|!!&6A:*>?r"   c                     [         R                  " / SQ5      nUR                  SSS9nUR                  S5      n/ nU H7  nSU;   d  M  UR                  S5      nUS   nUSS	 nUR	                  U5        M9     U$ )
r$   )netshwlanshowr   utf-8backslashreplaceerrorsr*   zAll User Profile:r   r8   )r+   check_outputdecoder   append)r   	meta_datar2   r   is        r   r   +WifiPasswordGetterWINDOWS.get_wifi_profiles   s     ++13	0BCzz$A!Q&GGCLaDaG"  r"   c                     SnU H(  nUR                  [        U5      S-   U-   5        US-   nM*     UR                  [        U5      S-   5        U R                  USU5      nU$ )z
Displays the names of the connected wifis and returns the number of the selected.

Parameters
----------
jarvis: JarvisAPI
    An instance of the JarvisAPI class.
profiles: list
    The list with the wifi names.
r   r5   r6   r7   )r   r;   r<   )r   r   r   r>   profiler   s         r   r   &WifiPasswordGetterWINDOWS.show_options   sh     GJJs5zD(723AIE   	

3u:())K!&(r"   c                 *     [        UR                  U[        R                  5      5      nXC:X  a  gX4s=:  a  S:  a   U$   UR	                  S[        R
                  5         Mc  ! [         a#    UR	                  S[        R
                  5         N.f = f)z
Returns the number of the selected wifi.

Parameters
----------
jarvis: JarvisAPI
    An instance of the JarvisAPI class.
input_text: str
    The text to be printed when asking for input.
max_valid_value: int
    The max valid value for the choices.
r8   r   rC   rE   )r   r   rK   rL   rN   s        r   r<   $WifiPasswordGetterWINDOWS.get_choice   s     !!$V\\*djj%I!J!4$::)) ; JJ-.2kk;   !

NKK!!s   .A% A% !A% %*BBc                     [         R                  " SSSSUS/5      nUR                  SSS9nUR                  S	5      nU Vs/ s H"  nS
U;   d  M  UR                  S5      S   SS PM$     nn UR	                  SU-   S-   US   -   5        gs  snf ! [
         a    UR	                  SU-   S-   S-   5         gf = f! [         R                   a#    UR	                  S[        R                  5         gf = f)z
Displays the name and the password of the selected wifi.

Parameters
----------
profile: str
    The name of the selected wifi.
jarvis: JarvisAPI
    An instance of the JarvisAPI class.
re   rf   rg   rt   z	key=clearrh   ri   rj   r*   zKey Contentrl   r   r8   r   r   r   UNKNOWNzTUnable to get the password for this wifi. Make sure you enter the correct wifi name!N)	r+   rm   rn   r   r   
IndexErrorCalledProcessErrorr   rI   )r   r   rt   resultsbs        r   r   *WifiPasswordGetterWINDOWS.display_password   s   	 --&&)WkJLGnnW5GnHGmmD)G '? '1=A+= -qwws|Aq, '  ?7

=72)*,3AJ7 8?  7

=72)*,56 77 ,, 	JJf	sH   AB< 
BB,B< /B B< $B96B< 8B99B< <4C32C3rW   NrX   rW   r"   r   r`   r`   p   s!    @$(!:r"   r`   )	r   r   r   r   coloramar   r+   r   r`   rW   r"   r   <module>r      sl    2 2   	%e e  eP 	't t  tr"   