ó
Ý#2Nc           @   so   d  Z  d Z d Z d Z d Z d d l Z d d l Z d d l m Z e j	 d ƒ Z
 d	 e f d
 „  ƒ  YZ d S(   s   Yaroslav Halhenkos   $Revision: $s	   $Date:  $s%   Copyright (c) 2007 Yaroslav Halchenkot   GPLiÿÿÿÿN(   t   SafeConfigParsers   fail2ban.client.configt   SafeConfigParserWithIncludesc           B   s5   e  Z d  Z d Z g  d „ Z e e ƒ Z d „  Z RS(   s  
	Class adds functionality to SafeConfigParser to handle included
	other configuration files (or may be urls, whatever in the future)

	File should have section [includes] and only 2 options implemented
	are 'files_before' and 'files_after' where files are listed 1 per
	line.

	Example:

[INCLUDES]
before = 1.conf
         3.conf

after = 1.conf

	It is a simple implementation, so just basic care is taken about
	recursion. Includes preserve right order, ie new files are
	inserted to the list of read configs before original, and their
	includes correspondingly so the list should follow the leaves of
	the tree.

	I wasn't sure what would be the right way to implement generic (aka c++
	template) so we could base at any *configparser class... so I will
	leave it for the future

	t   INCLUDESc         C   sC  t  } t ƒ  } | j |  ƒ t j j |  ƒ } d g  f d g  f g } | j | j ƒ  k r$xÆ | D]» \ } } | | j | j ƒ k rb | j	 | j | ƒ } x | j
 d ƒ D]k }	 t j j |	 ƒ rÌ |	 }
 n t j j | |	 ƒ }
 |
 | k ró q« n  | |  g } | | j |
 | ƒ 7} q« Wqb qb Wn  | d d |  g | d d S(   sŽ   
		Given 1 config resource returns list of included files
		(recursively) with the original one as well
		Simple loops are taken care about
		t   beforet   afters   
i    i   (   R   R   t   readt   ost   patht   dirnamet   SECTION_NAMEt   sectionst   optionst   gett   splitt   isabst   joint   getIncludes(   t   resourcet   seent   SCPWIt   parsert   resourceDirt   newFilest   option_namet   option_listt   newResourcest   newResourcet   rt   s(    (    s-   /usr/share/fail2ban/client/configparserinc.pyR   A   s$    		$c         C   sf   g  } t  | t ƒ s! | g } n  x! | D] } | t j | ƒ 7} q( Wt j d | ƒ t j |  | ƒ S(   Ns   Reading files: %s(   t
   isinstancet   listR   R   t   logSyst   debugR   R   (   t   selft	   filenamest   fileNamesFullt   filename(    (    s-   /usr/share/fail2ban/client/configparserinc.pyR   d   s    (   t   __name__t
   __module__t   __doc__R
   R   t   staticmethodR   (    (    (    s-   /usr/share/fail2ban/client/configparserinc.pyR   !   s
    (   t
   __author__t   __revision__t   __date__t   __copyright__t   __license__t   loggingR   t   ConfigParserR   t	   getLoggerR    R   (    (    (    s-   /usr/share/fail2ban/client/configparserinc.pyt   <module>   s   