Through an instance of this class, you have complete control over
your firewall.
Methods
|
|
|
|
__init__
|
__init__ (
self,
firewallBrand=None,
substitutionDict={},
)
Return an instance of the Firewall class.
Initialize a Firewall object.
- firewallBrand
a string or a list of strings amongst
which the firewall will be selected.
- substitutionDict
the dictionary used to substitute some
predefined strings in XML files.
|
|
__repr__
|
__repr__ ( self )
Return the representation for a Firewall object.
|
|
_create
|
_create (
self,
action='append',
pos=None,
target='drop',
direction='in',
source='0.0.0.0/0.0.0.0',
destination='0.0.0.0/0.0.0.0',
interface='',
proto='',
sport='',
dport='',
log=0,
)
Create a set of rules with the given parameters.
By default the direction is in and the target is drop .
|
|
_loadFirewall
|
_loadFirewall ( self, brand=None )
Detect the firewall and import related modules.
Exceptions
|
|
DetectFirewallError, 'unable to detect the firewall'
|
|
|
_parseXMLFile
|
_parseXMLFile ( self, fname )
Parse a XML file, return a list of Rule objects.
|
|
_parseXMLString
|
_parseXMLString ( self, s )
Parse a XML string, with substitution of the user supplied
substituition dictionary.
|
|
_runCommand
|
_runCommand ( self, cmd )
Execute a given command. Return 0 for error.
|
|
_runRule
|
_runRule ( self, r )
Execute a given rule.
|
|
_subDictSubstitution
|
_subDictSubstitution ( self, s )
Substitute well known strings in the given XML string with
user supplied data.
|
|
checkRule
|
checkRule ( self, rule )
If a rule is actually running, return the rule index,
-1 otherwise.
|
|
createNewRules
|
createNewRules (
self,
*args,
*kw,
)
Create new rules with the given parameters.
|
|
dumpRulesUDC
|
dumpRulesUDC ( self, direction )
Dump rules in the given chain, merging rules in
user-defined chains; return a list of Rule objects.
This method should be called only when you've user-defined
chains in your running set of rules. The policy of the chain
is considered.
|
|
forceFirewall
|
forceFirewall ( self, firewallBrand )
Force the use of the given firewall.
|
|
getFirewallName
|
getFirewallName ( self )
Return the name of the running firewall.
|
|
getPolicy
|
getPolicy ( self, direction )
Return a Rule object representing the policy for the given chain.
|
|
getRuleBuilder
|
getRuleBuilder ( self )
Return the RuleBuilder object used to create new rules.
|
|
getRuleClass
|
getRuleClass ( self )
Return the class that represents a Rule for this firewall.
|
|
getRuleCommands
|
getRuleCommands ( self, rules )
Return a list of commands for the given rule or list of rules.
|
|
getSubstitutionDict
|
getSubstitutionDict ( self )
Get the substitution dictionary.
|
|
getXMLRules
|
getXMLRules ( self, rules )
Return a list of XML strings for the given rule or list of rules.
|
|
isForced
|
isForced ( self )
Return true if the used firewall was forced.
|
|
listChains
|
listChains ( self )
Return the list of defined chains.
|
|
listCommandRules
|
listCommandRules ( self, direction )
Return a list of commands for the given direction.
|
|
listRules
|
listRules ( self, direction )
Return the list of rules in the given direction.
|
|
listXMLRules
|
listXMLRules ( self, direction )
Return a list of XML strings; one for every running rule.
|
|
newRulesFromXMLFile
|
newRulesFromXMLFile ( self, fileName )
Parse XML file.
Parse a XML file, and return a list of rules.
- fileName
the name of the file to parse.
|
|
newRulesFromXMLString
|
newRulesFromXMLString ( self, xmlString )
New rules from XML strings.
Parse a XML string and return a list of rules.
|
|
runNewRules
|
runNewRules (
self,
*args,
*kw,
)
Create and run new rules with the given parameters.
|
|
runRules
|
runRules ( self, rules )
Execute a given rule or list of rules.
|
|
runXMLFile
|
runXMLFile ( self, fileName )
Parse an XML file and run the resulting set of rules.
|
|
runXMLString
|
runXMLString ( self, xmlString )
Parse an XML string and run the resulting set of rules.
|
|
setSubstitutionDict
|
setSubstitutionDict ( self, substitutionDict )
Set the substitution dictionary.
Exceptions
|
|
ValueError, 'the key or value "' + str( val ) + '" is not a string'
ValueError, 'the substitutionDict must be a dictionary'
|
|