Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[iptables] Config option for rulefile location

[errors] Handle plugins with interface priorities
  • Loading branch information...
commit 28686ffd9b4d96c64be102a83faa29d0c74c94fc 1 parent 0258305
@Eugeny Eugeny authored
Showing with 26 additions and 6 deletions.
  1. +7 −1 ajenti/error.py
  2. +19 −5 plugins/iptables/backend.py
View
8 ajenti/error.py
@@ -25,7 +25,13 @@ def make_report(app, err):
for p in app.class_list():
i = ''
if hasattr(p, '_implements'):
- i = ','.join([x.__name__ for x in p._implements])
+ imps = []
+ for imp in p._implements:
+ try:
+ imps.append(imp[0])
+ except:
+ imps.append(imp)
+ i = ','.join([x.__name__ for x in imps])
pr += '%s [%s]\n' % (p.__name__, i)
return (('Ajenti %s bug report\n' +
View
24 plugins/iptables/backend.py
@@ -318,16 +318,28 @@ class Config(ClusteredConfig):
name = 'Firewall'
id = 'iptables'
files = [('/etc', 'iptables.up.rules')]
- run_after = ['cat /etc/iptables.up.rules | iptables-restore']
+ run_after = [] # set at runtime
tables = {}
apply_shell = 'cat /etc/iptables.up.rules | iptables-restore'
-
+
+ def __init__(self):
+ if self.app.config.has_option('iptables', 'rules_file'):
+ self.rules_file = self.app.config.get('iptables', 'rules_file')
+ else:
+ if os.path.exists('/etc/iptables'):
+ self.rules_file = '/etc/iptables/rules'
+ else:
+ self.rules_file = '/etc/iptables.up.rules' # webmin import
+ self.apply_shell = 'cat %s | iptables-restore' % self.rules_file
+ self.run_after = [self.apply_shell]
+
+
def load_runtime(self):
shell('iptables -L -t filter')
shell('iptables -L -t mangle')
shell('iptables -L -t nat')
- shell('iptables-save > /etc/iptables.up.rules')
+ shell('iptables-save > %s' % self.rules_file)
self.load()
def apply_now(self):
@@ -341,7 +353,8 @@ def set_autostart(self, active):
b = self.app.get_backend(IConfig)
b.set_autostart(active)
- def load(self, file='/etc/iptables.up.rules'):
+ def load(self, file=None):
+ file = file or self.rules_file
self.tables = {}
try:
data = self.open(file).read().split('\n')
@@ -369,7 +382,8 @@ def dump(self):
s += '%s\n' % self.tables[r].dump()
return s
- def save(self, file='/etc/iptables.up.rules'):
+ def save(self, file=None):
+ file = file or self.rules_file
self.open(file, 'w').write(self.dump())
def table_index(self, name):
Please sign in to comment.
Something went wrong with that request. Please try again.