MINI MINI MANI MO

Path : /lib/python2.7/site-packages/firewall/core/io/
File Upload :
Current File : //lib/python2.7/site-packages/firewall/core/io/ipset.pyc

ó
dߨ[c@sgdZdddgZddljZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
mZmZmZmZmZddlmZmZmZmZdd	lmZmZdd
lmZmZmZmZddl m!Z!ddlm"Z"dd
l#m$Z$defd„ƒYZ%defd„ƒYZ&d„Z'e(d„Z)dS(s$ipset io XML handler, reader, writertIPSettipset_readertipset_writeriÿÿÿÿN(tconfig(	tcheckIPtcheckIP6tcheckIPnMaskt
checkIP6nMaskt
u2b_if_py2t	check_mact
check_porttcheckInterfacet
checkProtocol(tPY2t	IO_ObjecttIO_Object_ContentHandlertIO_Object_XMLGenerator(tIPSET_TYPEStIPSET_CREATE_OPTIONS(tcheck_icmp_nametcheck_icmp_typetcheck_icmpv6_nametcheck_icmpv6_type(tlog(terrors(t
FirewallErrorcBsÓeZdddddidd6fddgffZdZdd	d
dgZidd6dd6dgd6d
gd6dd6Zidgd6dgd6Zd„Zd„Z	d„Z
ed„ƒZd„Z
d„ZRS(tversionttshorttdescriptionttypetoptionstentriess
(ssssa{ss}as)t_t-t:t.tipsettnametoptiontentrytvaluecCsVtt|ƒjƒd|_d|_d|_d|_g|_i|_t	|_
dS(NR(tsuperRt__init__RRRRR RtFalsetapplied(tself((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyR+Cs						cCsEd|_d|_d|_d|_|j2|jjƒt|_dS(NR(	RRRRR RtclearR,R-(R.((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pytcleanupMs				
cCst|jƒ|_t|jƒ|_t|jƒ|_t|jƒ|_d„|jjƒDƒ|_g|jD]}t|ƒ^qn|_dS(s» HACK. I haven't been able to make sax parser return
            strings encoded (because of python 2) instead of in unicode.
            Get rid of it once we throw out python 2 support.cSs+i|]!\}}t|ƒt|ƒ“qS((R(t.0tktv((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pys
<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familytinet6tipv6shash:sipset type '%s' not usableit,is)entry '%s' does not match ipset type '%s'tipR"s invalid address '%s' in '%s'[%d]is.invalid address range '%s' in '%s' for %s (%s)s(invalid address '%s' in '%s' for %s (%s)s0.0.0.0itnets/0shash:net,ifacetmacs00:00:00:00:00:00s invalid mac address '%s' in '%s'tportR#sinvalid port '%s'ticmps(invalid protocol for family '%s' in '%s'sinvalid icmp type '%s' in '%s'ticmpv6s	ipv6-icmps invalid icmpv6 type '%s' in '%s'ttcptsctptudptudplitesinvalid protocol '%s' in '%s'sinvalid port '%s'in '%s'sinvalid port '%s' in '%s'tmarkt0xisinvalid mark '%s' in '%s'Iÿÿÿÿtifaceisinvalid interface '%s' in '%s'(RAs	ipv6-icmp(RBRCRDRE(t
startswithRRt
INVALID_IPSETtsplittlent
INVALID_ENTRYtrangeRRRRtendswithR	RRRRRR
tintt
ValueErrorR(
R(Rt
ipset_typeR8tflagsR4titflagtitemtsplitst_splittip_checktint_val((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pytcheck_entrybs@	*


 		 


	cCs>|dkr4|tkr4ttjd|ƒ‚q4n|dkr:x÷|jƒD]æ}|tkrxttjd|ƒ‚n|dkrþyt||ƒ}Wn1tk
rËttj	d|||fƒ‚nX|d	kr3ttj	d
|||fƒ‚q3qM|dkrM||dkrMttj
||ƒ‚qMqMWndS(NRs'%s' is not valid ipset typeRsipset invalid option '%s'ttimeoutthashsizetmaxelems)Option '%s': Value '%s' is not an integeris#Option '%s': Value '%s' is negativeR8tinetR9(R\R]R^(R_sinet6(RRRtINVALID_TYPEtkeysRRJRPRQt
INVALID_VALUEtINVALID_FAMILY(R.RRVtkeyt	int_value((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyt
_check_configs2		
cCs™d|dkrO|dddkrOt|dƒdkrOttjƒ‚qOnx-|dD]!}tj||d|dƒqZWtt|ƒj|ƒdS(NR\it0iii(RLRRtIPSET_WITH_TIMEOUTRR[R*t
import_config(R.RR(((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyRi3s$(sversionR(sshortR(sdescriptionR(stypeRN(t__name__t
__module__tIMPORT_EXPORT_STRUCTUREtDBUS_SIGNATUREtADDITIONAL_ALNUM_CHARStNonetPARSER_REQUIRED_ELEMENT_ATTRStPARSER_OPTIONAL_ELEMENT_ATTRSR+R0R6tstaticmethodR[RfRi(((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyR,s.




	
			¶	tipset_ContentHandlercBseZd„Zd„ZRS(cCs”tj|||ƒ|jj||ƒ|dkr d|kr~|dtkrkttjd|dƒ‚n|d|j_nd|kr|d|j_	qnð|dkr¯ná|dkr¾nÒ|dkrd}d	|kré|d	}n|d
dkrttj
d|d
ƒ‚n|jjdkra|d
dkrattj
d|d
|jjfƒ‚n|d
dkr•|r•ttj
d|d
ƒ‚n|d
dkryt|ƒ}Wn1tk
rèttj
d|d
|fƒ‚nX|dkrttj
d|d
|fƒ‚qn|d
dkrL|dkrLttj|ƒ‚n|d
|jjkry||jj|d
<qtjd|d
ƒndS(NR%Rs%sRRRR'RR)R&R8R\R]R^sUnknown option '%s'shash:macs%Unsupported option '%s' for type '%s's&Missing mandatory value of option '%s's)Option '%s': Value '%s' is not an integeris#Option '%s': Value '%s' is negativeR_R9s Option %s already set, ignoring.(sfamilystimeoutshashsizesmaxelem(sfamily(sfamilystimeoutshashsizesmaxelem(stimeoutshashsizesmaxelem(sinetsinet6(RtstartElementRVtparser_check_element_attrsRRRR`RRtINVALID_OPTIONRPRQRbRcRRtwarning(R.R&tattrsR)Re((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyRt>sd
	"
cCs9tj||ƒ|dkr5|jjj|jƒndS(NR((Rt
endElementRVR tappendt_element(R.R&((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyRyus(RjRkRtRy(((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyRs=s	7c	Csttƒ}|jdƒs1ttjd|ƒ‚n|d |_|j|jƒ||_||_|j	t
jƒrxtnt
|_|j|_t|ƒ}tjƒ}|j|ƒd||f}t|dƒM}y|j|ƒWn2tjk
r}ttjd|jƒƒ‚nXWdQX~~d|jkrz|jddkrzt|jƒd	krztjd
|jƒ|j2nd	}tƒ}	xÎ|t|jƒkrY|j||	krÞtjd|j|ƒ|jj|ƒqŒy$|j |j||j|j!ƒWn3tk
r7}
tjd|
ƒ|jj|ƒqŒX|	j"|j|ƒ|d
7}qŒW~	t#rp|j$ƒn|S(Ns.xmls'%s' is missing .xml suffixiüÿÿÿs%s/%strsnot a valid ipset file: %sR\Rgis6ipset '%s': timeout option is set, entries are ignoredsEntry %s already set, ignoring.s
%s, ignoring.i(%RRORRtINVALID_NAMER&t
check_nametfilenametpathRIRt
ETC_FIREWALLDR,tTruetbuiltintdefaultRstsaxtmake_parsertsetContentHandlertopentparsetSAXParseExceptionRJtgetExceptionRRLR RRwtsettpopR[RtaddR
R6(RR€R%thandlertparserR&tftmsgRTtentries_setR5((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyRzsZ		
		!
	"	

	$
c
Csg|r|n|j}|jr4d||jf}nd||jf}tjj|ƒrytj|d|ƒWqtk
r™}tj	d||ƒqXntjj
|ƒ}|jtj
ƒrtjj|ƒrtjjtj
ƒsÿtjtj
dƒntj|dƒntj|dddd	ƒ}t|ƒ}|jƒi|jd
6}|jr{|jdkr{|j|d<n|jd
|ƒ|jdƒ|jrú|jdkrú|jdƒ|jdiƒ|j|jƒ|jdƒ|jdƒn|jr\|jdkr\|jdƒ|jdiƒ|j|jƒ|jdƒ|jdƒnx{|jjƒD]j\}	}
|jdƒ|
dkr²|jdi|	d6|
d6ƒn|jdi|	d6ƒ|jdƒqlWxU|jD]J}|jdƒ|jdiƒ|j|ƒ|jdƒ|jdƒqäW|jd
ƒ|jdƒ|jƒ|j ƒ~dS(Ns%s/%ss	%s/%s.xmls%s.oldsBackup of file '%s' failed: %siètmodetwttencodingsUTF-8RRRR%s
s  RRR'R&R)R((!R€RR&tostexiststshutiltcopy2t	ExceptionRterrortdirnameRIRRtmkdirtioRˆRt
startDocumentRRRttignorableWhitespaceRt
charactersRyRRR4t
simpleElementR tendDocumenttclose(R%R€t_pathR&R’tdirpathR‘RRxRdR)R(((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyR­sf	%






!






(*t__doc__t__all__txml.saxR…R—RŸR™tfirewallRtfirewall.functionsRRRRRR	R
RRtfirewall.core.io.io_objectR
RRRtfirewall.core.ipsetRRtfirewall.core.icmpRRRRtfirewall.core.loggerRRtfirewall.errorsRRRsRRoR(((s:/usr/lib/python2.7/site-packages/firewall/core/io/ipset.pyt<module>s$@""ÿ=	3

OHA YOOOO