Fixed '(Allow|Deny) Once' actions.

This commit is contained in:
Simone Margaritelli 2017-04-18 13:58:07 +02:00
parent af1bb27e6a
commit c82f2ad1a4
2 changed files with 18 additions and 16 deletions

View file

@ -51,8 +51,9 @@ class Snitch:
if verdict is None:
with self.lock:
c.hostname = self.dns.get_hostname(c.dst_addr)
( verdict, apply_for_all ) = UI.prompt_user(c)
self.rules.add_rule( c, verdict, apply_for_all )
( save, verdict, apply_for_all ) = UI.prompt_user(c)
if save:
self.rules.add_rule( c, verdict, apply_for_all )
return verdict

View file

@ -24,6 +24,19 @@ from opensnitch.rule import Rule
# TODO: Implement tray icon and menu.
# TODO: Implement rules editor.
class UI:
CHOICES = [ 'Allow Once',
'Allow All',
'Deny Once',
'Deny All' ]
RESULTS = [ \
# save | verdict | all
( False, Rule.ACCEPT, False ),
( True, Rule.ACCEPT, True ),
( False, Rule.DROP, False ),
( True, Rule.DROP, True )
]
@staticmethod
def prompt_user( c ):
title = 'OpenSnitch'
@ -34,19 +47,7 @@ class UI:
c.proto.upper(),
c.dst_port,
" (%s)" % c.service if c.service is not None else '' )
choices = [ 'Allow Once',
'Allow All',
'Deny Once',
'Deny All' ]
idx = g.indexbox(msg, title, choices)
results = [ \
( Rule.ACCEPT, False ),
( Rule.ACCEPT, True ),
( Rule.DROP, False ),
( Rule.DROP, True )
]
return results[idx]
idx = g.indexbox( msg, title, UI.CHOICES )
return UI.RESULTS[idx]