コード例 #1
0
 def _get_rule_from_dialog(self):
     action = self._get_combobox_value('action_cbox').lower()
     if self.ui.protocol_cbox.get_sensitive():
         protocol = self._get_combobox_value('protocol_cbox').lower()
     else:
         protocol = 'any'
     rule = UFWRule(action, protocol)
     # position
     pos = self.ui.position_adjustment.get_value()
     rule.set_position(pos)
     # direction
     direction = ('in' if self.ui.in_rbutton.get_active() else 'out')
     rule.set_direction(direction)
     # logtype
     log_map = {'Off': '', 'New Connections': 'log', 'Packets': 'log-all'}
     logtype = log_map[self._get_combobox_value('rule_logging_cbox')]
     rule.set_logtype(logtype)
     # src
     if self.ui.src_addr_custom_rbutton.get_active():
         addr = self.ui.src_addr_custom_entry.get_text()
         rule.set_src(addr)
     # src port
     port = gfw.util.ANY_PORT
     if self.ui.src_port_custom_rbutton.get_active():
         port = self.ui.src_port_custom_entry.get_text()
     elif self.ui.src_app_rbutton.get_active():
         port = self._get_combobox_value('src_app_cbox')
         rule.sapp = port
     rule.set_port(port, 'src')
     # dst
     if self.ui.dst_addr_custom_rbutton.get_active():
         addr = self.ui.dst_addr_custom_entry.get_text()
         rule.set_dst(addr)
     # dst port
     port = gfw.util.ANY_PORT
     if self.ui.dst_port_custom_rbutton.get_active():
         port = self.ui.dst_port_custom_entry.get_text()
     elif self.ui.dst_app_rbutton.get_active():
         port = self._get_combobox_value('dst_app_cbox')
         rule.dapp = port
     rule.set_port(port, 'dst')
     return rule