ó ÆðH_c@sÍdZdZdZddlZddlZddlmZmZddlm Z m Z m Z dd l m Z mZmZmZe eƒZd dd „ƒYZd e fd „ƒYZdefd„ƒYZdS(s?Cyril Jaquier, Yaroslav Halchenko, Serg G. Brester (aka sebres)s\Copyright (c) 2004 Cyril Jaquier, 2007 Yaroslav Halchenko, 2015 Serg G. Brester (aka sebres)tGPLiÿÿÿÿN(t NoOptionErrortNoSectionErrori(tsystSafeConfigParserWithIncludestlogLeveli(t getLoggert_as_boolt _merge_dictstsubstituteRecursiveTagst ConfigReadercBsªeZdZddd„Zd„Zd„Zed„ƒZe d„Z dd„Z d„Z d „Z e d „Zd „Zd „Zed „Zeid„Zd„ZRS(skGeneric config reader class. A caching adapter which automatically reuses already shared configuration. cKsyd|_d|_|dk r*||_n|dk rT||_||_d|_n!|jdkrut||_ndS(N(tNonet _cfg_sharet_cfgt_cfg_share_kwargst_cfg_share_basedirtConfigReaderUnshared(tselft use_configt share_configtkwargs((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyt__init__,s        cCs)|jr|jj|ƒn ||_dS(N(R t setBaseDirR(Rtbasedir((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR:s cCs!|jr|jjƒS|jSdS(N(R t getBaseDirR(R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR@s  cCs|jS(N(R (R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyRFscCsy|js|j|ƒn|r;|jjdk r;|jjStjd||jjƒƒ|jj|ƒ}||j_|S(sÈ Overloads a default (not shared) read of config reader. To prevent mutiple reads of config files with it includes, reads into the config reader, if it was not yet cached/shared by 'name'. s Loading configs for %s under %s N(R t_create_unsharedtread_cfg_filesR tlogSystinfoRtread(Rtnametoncetret((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyRJs   tcCs£|j r|jdk r|jj|ƒ|_|jsŸtd|j|j|_|jdk rw|jj|jƒn|j|j|qs(R tsectionstAttributeError(R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR&os cCs-y|jj|ƒSWntk r(tSXdS(N(R t has_sectionR'tFalse(Rtsec((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR(us cCs5|r|jj||ƒS||jjj|iƒkS(N(R t has_optiont _sectionsR"(RR*toptt withDefault((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR+{scCs|jjƒj|ƒdS(N(R t get_defaultstupdate(Rtd((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pytmerge_defaultsscOs>y|jj|||ŽSWntk r9t|ƒ‚nXdS(N(R t merge_sectionR'R(RtsectiontargsR((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR3‚s cCs;y|jj||ƒSWntk r6t|ƒ‚nXdS(sŽReturn a list of option names for the given section name. Parameter `withDefault` controls the include of names from section `[DEFAULT]` N(R toptionsR'R(RR4R.((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR6ˆs cCsGy#|jj||d|d|ƒSWntk rBt|ƒ‚nXdS(Ntrawtvars(R R"R'R(RR*R-R7R8((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR"’s# cOs>y|jj|||ŽSWntk r9t|ƒ‚nXdS(N(R t getOptionsR'R(RR4R5R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR9˜s N(t__name__t __module__t__doc__R RRRtpropertyRtTrueRRR&R(R+R2R3R)R6R"R9(((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR &s          RcBsJeZdZdZdd„Zd„Zd„Zd„Zde d„Z RS(s’Unshared config reader (previously ConfigReader). Do not use this class (internal not shared/cached represenation). Use ConfigReader instead. s /etc/fail2bancOs-tj|||Žd|_|j|ƒdS(N(RRR RR(RRR5R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR¨s cCs.|dkrtj}n|jdƒ|_dS(Nt/(R RtDEFAULT_BASEDIRtrstript_basedir(RR((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR­s  cCs|jS(N(RB(R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR²scCsãtjj|jƒs+td|jƒ‚n|jdƒrOtjj|ƒ}ntjj|j|ƒ}tj d||jƒ|dg}|d}|t t j d|ƒƒ7}|j |dƒ|t t j d|ƒƒ7}t tjj|ƒ}t|ƒr™tj d d j|ƒƒtj||ƒ}g|D]}||kr2|^q2}|rrtjd d j|ƒƒn|r|tStjd ||jƒƒtStjd |d|jƒdd j|ƒgtt|ƒƒƒtSdS(Ns/Base configuration directory %s does not exist s./s Reading configs for %s under %s s.confs.ds %s/*.confs.locals %s/*.localsReading config files: %ss, sCould not read config files: %ss0Found no accessible config files for %r under %ss(Found no accessible config files for %r sunder %ssamong existing ones: (tostpathtexistsRBt ValueErrorR#tabspathtjoinRtdebugtsortedtglobtappendtfiltertlenRRterrorR>RR)tbool(Rtfilenametbasenamet config_filest config_dirtconfig_files_readtcftmissed((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyRµs8   %   (c Csñtƒ}|dkri}nxÌ|D]Ä}t|ttfƒrzt|ƒdkrd|\}}}qŠ|d\}}}n||\}}||krœq%nyŒ|dkrÒ|j||ƒ} | dkrw%qnK|dkr|j||ƒ} | dkrw%qn|j||d|ƒ} | ||LsR.R:sknown/(RZRmRR R9t _configOptst_optsRnR(R6R)R R#R"(RtpOptstalltgetoptR-Rh((Rs@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyR9@s4      cCs t|ƒS(N(R(Rtvalue((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyt_convert_to_boolean^scCszy|j|SWndtk ruy"|jjd|d|jƒ}Wn tttfk rcd}nX||j|<|SXdS(sÈGet combined definition option (as string) using pre-set and init options as preselection (values with higher precedence as specified in section). Can be used only after calling of getOptions. RyR8N( RotKeyErrorR tget_exRnRRRFR (RReRh((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyt getCombOptionas "  cCsÈ|j}|jr't||jƒ}nt|ƒs7iSt|ƒjƒ}xH|D]@}tjj|ƒ}|rP|j ƒ\}}|j |ƒqPqPWt |d|d|j ƒ}|sÄt dƒ‚n|S(Ntignoretaddrepls/recursive tag definitions unable to be resolved(R}RmRRNtsettcopyRtCONDITIONAL_REtmatchtgroupstaddR R…RF(RR†t combinedoptsR%tcondtopts((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyt getCombinedqs      cCs t‚dS(N(tNotImplementedError(R((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pytconvert…s((R:R;R<R|RRkRuRlRwRRxR)R9R‚R…R‘R“(((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyRjs          ((t __author__t __copyright__t __license__RKRCt ConfigParserRRtconfigparserincRRRthelpersRRRR R:RR RRj(((s@/usr/lib/python2.7/site-packages/fail2ban/client/configreader.pyts  " yv