
    #fd                         S r SSKrSSKrSSKrSSKrSSKJrJr  SSKJ	r	  SSK
r
\
R                  S   S:  a  SSKrOSSKrS rS rS rS	 rS
 rS rg)z'applications.py: common classes for ufw    N)debugwarn)UFWError   c                 v   [         R                  R                  U 5      (       d  [        S5      n[	        U5      eSn0 n[         R
                  " U 5      nUR                  5         Sn[        R                  " S5      nU GHX  nU S-   U-   n[         R                  R                  U5      (       d  M2  UR                  U5      (       a  [        SU-  5        MX  UR                  S5      (       dn  UR                  S5      (       dX  UR                  S	5      (       dB  UR                  S
5      (       d,  UR                  S5      (       d  UR                  S5      (       a  [        SU-  5        M  Sn	 [         R                  " U5      [        R                     n	X:  a  [        S5      U-  n
[!        U
5        GM7  XY-   U:  a  [        S5      U-  n
[!        U
5        GM[  XY-  n["        R$                  S   S:  a  [&        R(                  " 5       nO[*        R(                  " 5       n UR-                  U5        UR/                  5        H  n[1        U5      S:  a  [        S5      U-  n
[!        U
5        M-  [3        U5      (       d  [        S5      U-  n
[!        U
5        MX   [4        R6                  R9                  U5        [        S5      U-  n
[!        U
5        M     GM[     U$ ! [         a    [        S5      U-  n
[!        U
5         GM  f = f! [         a    [        S5      U-  n
[!        U
5         GM  f = f! [         a     Of = fSnUR;                  U5       H_  u  p[1        U5      S:  a  [        S5      U-  n
[!        U
5        Sn  O2[1        U5      S:  d  MB  [        S5      XS.-  n
[!        U
5        Sn  O   U(       a  GM  X;   a  [        S5      U-  n
[!        U
5        0 nUR;                  U5       H
  u  pUUU'   M      [=        UU5        UX<'   GM  ! [         a  n[!        U5         SnAGM  SnAff = f)zlGet profiles found in profiles database.  Returns dictionary with
profile name as key and tuples for fields
z!Profiles directory does not existi   r   z^\./zSkipping '%s': hidden filez	.dpkg-newz	.dpkg-oldz
.dpkg-distz.rpmnewz.rpmsave~zSkipping '%s'zSkipping '%s': couldn't statzSkipping '%s': too bigz*Skipping '%s': too many files read alreadyr   zSkipping '%s': couldn't process@   zSkipping '%s': name too longzSkipping '%s': invalid namez$Skipping '%s': also in /etc/servicesFzSkipping '%s': field too longTi   z4Skipping '%(value)s': value too long for '%(field)s')valuefieldz(Duplicate profile '%s', using last foundN)ospathisdir_r   listdirsortrecompileisfilesearchr   endswithstatST_SIZE	Exceptionr   sysversion_infoConfigParserRawConfigParserconfigparserreadsectionslenvalid_profile_nameufwutilget_services_protoitemsverify_profile)profiles_direrr_msgmax_sizeprofilesfiles
total_sizepatfabs_pathsizewarn_msgcdictpskipkeyr   pdictes                     2/usr/lib/python3/dist-packages/ufw/applications.pyget_profilesr;       s    77==&&78wHHJJ|$E	JJLJ
**V
C#%)ww~~h''::a==.!45::k""ajj&=&=::l##qzz)'<'<::j!!QZZ__/Q'( 	778$T\\2D ?12a8HNx'EF!LHN
A" 002E 002E	JJx  !A1v{;<BX%a((:;qAX++A.CDJX "e J Oc  	78A>HN	0  	:;qAHN	,   D#kk!n
s8b= !@AQGHNDu:$  "/  0,-"< >H ND - }GHANXE#kk!n
"c
 -q%(# QsN   .'K!L	8L4#LL	#L10L14
M MP
P8!P33P8c                     U S:X  a  g [        U 5        g! [         a     Of = f[        R                  " SU 5      (       a  gg)z0Only accept a limited set of characters for nameallFz ^[a-zA-Z0-9][a-zA-Z0-9 _\-\.+]*$T)intr   r   match)names    r:   r#   r#      sI     u}D	 
 
xx3T::s    
""c                     / SQnU HG  nX1;  a  [        S5      XS.-  n[        U5      eX   (       a  M.  [        S5      XS.-  n[        U5      e   US   R                  S5      n U Hl  n[        R                  R                  U5      u  pxUS:X  a  SU;   d  S	U;   a  [        W5      e[        R                  R                  S
X5      n	[        U	5        Mn     g! [         a)  n
[        U
5        [        S5      U -  n[        U5      eSn
A
ff = f)z'Make sure profile has everything needed)titledescriptionportsz/Profile '%(fn)s' missing required field '%(f)s')fnr0   z1Profile '%(fn)s' has empty required field '%(f)s'rD   |any:,ACCEPTzInvalid ports in profile '%s'NT)
r   r   splitr$   r%   parse_port_protocommonUFWRuler   r   )r@   profile
app_fieldsr0   r*   rD   r5   portprotoruler9   s              r:   r(   r(      s   2JIJ $-/G 7##KL"&/1G7##  G""3'E AHH55a8MT~3$;#+w''::%%h<D$K     a34=w s   'A2C 
D$$DDc                 2    SnSnX ;   a  X   (       a  X   nU$ )z#Retrieve the title from the profile rB    rO   sr   s      r:   	get_titlerY      s"    
AEGNNH    c                 2    SnSnX ;   a  X   (       a  X   nU$ )z)Retrieve the description from the profilerU   rC   rV   rW   s      r:   get_descriptionr\      s"    
AEGNNHrZ   c                 P    / nSnX ;   a  X   (       a  X   R                  S5      nU$ )z'Retrieve a list of ports from a profilerD   rF   )rK   )rO   rD   r   s      r:   	get_portsr^      s-    EEGN$$S)LrZ   )__doc__r   r   r   ufw.utilr$   r   r   
ufw.commonr   r   r   r   r   r;   r#   r(   rY   r\   r^   rV   rZ   r:   <module>rb      sY    -" 
 	      
Aup(@rZ   