o Fa@sdZddlZddlZddlZddlZddlmZmZddlm Z ddl Z e j ddkr0ddl Z nddl Z ddZdd Zd d Zd d ZddZddZdS)z'applications.py: common classes for ufwN)debugwarn)UFWErrorc Cs6tj|std}t|d}i}t|}|d}td}|D]s}|d|}tj |s4q$| |r@t d|q$| ds^| ds^| d s^| d s^| d s^| d ret d |q$d} z t |t j} Wntytd|} t| Yq$w| |krtd|} t| q$|| |krtd|} t| q$|| 7}tjddkrt} nt} z| |Wntytd|} t| Yq$w| D]} t| dkrtd| } t| qt| std| } t| qztj| td| } t| WqtyYnwd} | | D]2\}}t|dkr7td| } t| d} nt|dkrOtd| |d} t| d} nq| rUq| |vrdtd| } t| i}| | D] \}}|||<qkz t| |||| <Wqty}z t|WYd}~qd}~wwq$|S)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 pdicter82/usr/lib/python3/dist-packages/ufw/applications.py get_profiles s                             3r:cCsB|dkrdSzt|WdStyYnwtd|rdSdS)z0Only accept a limited set of characters for nameallFz ^[a-zA-Z0-9][a-zA-Z0-9 _\-\.+]*$T)intrrmatch)namer8r8r9r!s  r!c Csgd}|D]$}||vrtd||d}t|||s*td||d}t|q|dd}z,|D]&}tj|\}}|dkrOd|vsKd |vrOt|tjd ||} t| q5Wd St yx} zt| td |}t|d } ~ ww)z'Make sure profile has everything needed)title descriptionportsz/Profile '%(fn)s' missing required field '%(f)s')fnr.z1Profile '%(fn)s' has empty required field '%(f)s'rA|any:,ACCEPTzInvalid ports in profile '%s'NT) rrsplitr"r#parse_port_protocommonUFWRulerr) r>profile app_fieldsr.r(rAr3portprotoruler7r8r8r9r&s:   r&cC$d}d}||vr||r||}|S)z#Retrieve the title from the profiler?r8rLsr r8r8r9 get_title rUcCrQ)z)Retrieve the description from the profilerRr@r8rSr8r8r9get_descriptionrVrWcCs*g}d}||vr||r||d}|S)z'Retrieve a list of ports from a profilerArC)rH)rLrAr r8r8r9 get_portss rX)__doc__r rrufw.utilr"rr ufw.commonrrrrrr:r!r&rUrWrXr8r8r8r9s"  x