From 4f5aa107ea1efb7a1e67da360ab91e7aacbd80a8 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Tue, 15 Sep 2009 15:59:34 +0000 Subject: [PATCH] Added Delete command --- sfatables/commands/Delete.py | 22 +++++++++++++++++----- sfatables/commands/List.py | 1 - sfatables/xmlrule.py | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/sfatables/commands/Delete.py b/sfatables/commands/Delete.py index cac54454..d90c583f 100644 --- a/sfatables/commands/Delete.py +++ b/sfatables/commands/Delete.py @@ -1,4 +1,5 @@ import os, time +from sfatables.globals import * from sfatables.command import Command class Delete(Command): @@ -11,9 +12,20 @@ class Delete(Command): def __init__(self): return - def call(self): - # Override this function - return True + def call(self, command_options, match_options, target_options): + + if (len(command_options.args)<2): + print "Please specify the chain and the rule number to delete, e.g. sfatables -D INCOMING 1" + + chain = command_options.args[0] + + + rule_number = command_options.args[1] + chain_dir = sfatables_config + "/" + chain + + match_path = chain_dir + "/" + "sfatables-%s-match"%rule_number + target_path = chain_dir + "/" + "sfatables-%s-target"%rule_number + + os.unlink(match_path) + os.unlink(target_path) - def __call__(self, option, opt_str, value, parser, *args, **kwargs): - return self.call(option) diff --git a/sfatables/commands/List.py b/sfatables/commands/List.py index e3c124e6..1c383a14 100644 --- a/sfatables/commands/List.py +++ b/sfatables/commands/List.py @@ -16,7 +16,6 @@ class List(Command): def __init__(self): return - def get_info(self, type, xmlextension_path): xmldoc = libxml2.parseFile(xmlextension_path) p = xmldoc.xpathNewContext() diff --git a/sfatables/xmlrule.py b/sfatables/xmlrule.py index 258e75a1..b0f6fdef 100644 --- a/sfatables/xmlrule.py +++ b/sfatables/xmlrule.py @@ -1,4 +1,5 @@ import libxml2 +import libxslt from sfatables.globals import * class XMLRule: @@ -18,11 +19,11 @@ class XMLRule: filepath = 'processors/' + processor # XXX - styledoc = libxml2.parseFile(processor) + styledoc = libxml2.parseFile(filepath) style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseDoc(rspec) result = style.applyStylesheet(doc, None) - processed_result = style.saveResultToString(result, 0) + stylesheet_result = style.saveResultToString(result) style.freeStylesheet() doc.freeDoc() result.freeDoc() -- 2.43.0