#fddZddlZddlZddlZddlZddlmZmZddlm Z ddl Z e jddkrddl Z nddl Z dZdZdZd Zd Zd Zy) z'applications.py: common classes for ufwN)debugwarn)UFWErrorctjj|std}t |d}i}tj |}|j d}tjd}|D]}|dz|z}tjj|s,|j|rtd|zL|jdsU|jdsD|jd s3|jd s"|jd s|jd rtd |zd} tj|tj} | |kDrtd|z} t!|  || z|kDrtd|z} t!| -|| z }t"j$ddkrt'j(} nt+j(} | j-|| j/D]} t1| dkDrtd| z} t!| +t3| std| z} t!| P t4j6j9| td| z} t!|  |S#t$rtd|z} t!| YHwxYw#t$rtd|z} t!| YqwxYw#t$rYnwxYwd} | j;| D]^\}}t1|dkDrtd| z} t!| d} n0t1|dkDs@td| |dz} t!| d} n| ri| |vrtd| z} t!| i}| j;| D] \}}|||<  t=| |||| <#t$r}t!|Yd}~d}~wwxYw)zwGet profiles found in profiles database. Returns dictionary with profile name as key and tuples for fields z!Profiles directory does not existirz^\./zSkipping '%s': hidden filez .dpkg-newz .dpkg-oldz .dpkg-distz.rpmnewz.rpmsave~z Skipping '%s'zSkipping '%s': couldn't statzSkipping '%s': too bigz*Skipping '%s': too many files read alreadyrzSkipping '%s': couldn't process@zSkipping '%s': name too longzSkipping '%s': invalid namez$Skipping '%s': also in /etc/servicesFzSkipping '%s': field too longTiz4Skipping '%(value)s': value too long for '%(field)s')valuefieldz(Duplicate profile '%s', using last foundN)ospathisdir_rlistdirsortrecompileisfilesearchrendswithstatST_SIZE Exceptionrsys version_info ConfigParserRawConfigParser configparserreadsectionslenvalid_profile_nameufwutilget_services_protoitemsverify_profile) profiles_direrr_msgmax_sizeprofilesfiles total_sizepatfabs_pathsizewarn_msgcdictpskipkeyr pdictes 2/usr/lib/python3/dist-packages/ufw/applications.py get_profilesr; s 77== &78wHH JJ| $E JJLJ **V C c#%)ww~~h'  ::a= .!4 5  ::k "ajj&= ::l #qzz)'< ::j !QZZ_ /Q' (  778$T\\2D (?12a8H N   x 'EF!LH N d   A  " 002E 002E  JJx !1 A1v{;<BX%a(:;qAX ++A.CDJX1 ecJ Oc 78A>H N  0 :;qAH N  ,  D#kk!n  Us8b= !@AQGHNDu:$ "/ 0,-"< >HND H}GHANXE#kk!n # U"c  # q%(#  Q sN<&J*K8K-"KK"K*)K*- K98K92O O$ OO$cv|dk(ry t|y#t$rYnwxYwtjd|ryy)z0Only accept a limited set of characters for nameallFz ^[a-zA-Z0-9][a-zA-Z0-9 _\-\.+]*$T)intrrmatch)names r:r#r#sF u}  D      xx3T: s   c gd}|D]C}||vrtd||dz}t|||r)td||dz}t||djd} |D]h}tjj |\}}|dk(rd|vsd |vr ttj jd ||} t| j y #t$r)} t| td |z}t|d } ~ wwxYw)z'Make sure profile has everything needed)title descriptionportsz/Profile '%(fn)s' missing required field '%(f)s')fnr0z1Profile '%(fn)s' has empty required field '%(f)s'rD|any:,ACCEPTzInvalid ports in profile '%s'NT) rrsplitr$r%parse_port_protocommonUFWRulerr) r@profile app_fieldsr0r*rDr5portprotoruler9s r:r(r(s&2J  $ G IJ $1-/G7# #KL"&Q/1G7# # $ G  " "3 'E   AHH55a8MT5~3$;#+w''::%%ht>Dc*d}d}||vr ||r||}|S)z#Retrieve the title from the profilerBrOsr s r: get_titlerYs( A E GEN EN Hc*d}d}||vr ||r||}|S)z)Retrieve the description from the profilerUrCrVrWs r:get_descriptionr\s( A E GEN EN HrZcHg}d}||vr||r||jd}|S)z'Retrieve a list of ports from a profilerDrF)rK)rOrDr s r: get_portsr^s3 E E GEN$$S) LrZ)__doc__r rrufw.utilr$rr ufw.commonrrrrrr;r#r(rYr\r^rVrZr:rbsY-"   Aup(@  rZ