def fromXml(str): elem = etree.XML(str) if elem.tag != 'rule': error("ERROR: Invalid XML, expected \'rule\' element", ERROR_INVALID_XML_NO_RULE) action=elem.get('action', '').lower() if action == '': error("ERROR: Invalid XML, no action specified", ERROR_INVALID_XML_NO_ACTION_XML) protocol=elem.get('protocol', ANY_PROTOCOL).lower() rule = UFWRule(action, protocol) rule.position=int(elem.get('position', 0)) rule.direction=elem.get('direction', 'in').lower() rule.dapp=elem.get('dapp', '') rule.sapp=elem.get('sapp', '') rule.dport=elem.get('dport', ANY_PORT) rule.sport=elem.get('sport', ANY_PORT) rule.dst=elem.get('dst', ANY_ADDR) rule.src=elem.get('src', ANY_ADDR) rule.interface_in=elem.get('interface_in', '') rule.interface_out=elem.get('interface_out', '') rule.logtype=elem.get('logtype', '').lower() rule.v6=elem.get('v6', 'False').lower() == "true" return rule