def boot(self): # create thread for hostapd and connect get_Hostapd_Response function self.reactor = ProcessHostapd( {self.getHostapdPath: [C.DOCKERHOSTAPDCONF_PATH]}, "MDSNjD") self.reactor.setObjectName("hostapd_{}".format(self.ID)) self.reactor.statusAP_connected.connect(self.get_Hostapd_Response) self.reactor.statusAPError.connect(self.get_error_hostapdServices)
class Static(Mode): configRoot = "static" subConfig = "static" ID = "static" Name = "Wireless Static AP Mode" def __init__(self, parent=0): super(Static, self).__init__(parent) self.confgSecurity = [] @property def Settings(self): return StaticSettings.getInstance() def getSettings(self): return self.Settings def Initialize(self): self.Settings.Configure() if not (self.Settings.checkNetworkAP()): sys.exit(1) self.check_Wireless_Security() # add extra hostapd settings self.addExtraHostapdSettings() ignore = ("interface=", "ssid=", "channel=", "essid=") with open(C.HOSTAPDCONF_PATH, "w") as apconf: for i in self.Settings.SettingsAP["hostapd"]: apconf.write(i) apconf.close() def boot(self): # create thread for hostapd and connect get_Hostapd_Response functio self.reactor = ProcessHostapd( {self.getHostapdPath: [C.HOSTAPDCONF_PATH]}, "MDSNjD" ) self.reactor.setObjectName("hostapd_{}".format(self.ID)) self.reactor.statusAP_connected.connect(self.get_Hostapd_Response) self.reactor.statusAPError.connect(self.get_error_hostapdServices) def get_Hostapd_Response(self, data): if self.conf.get("accesspoint", "status_ap", format=bool): print( display_messages( "{} client has left AP ".format(setcolor(data, color="red")), info=True, ) ) def setNetworkManager(self, interface=str, Remove=False): """ mac address of interface to exclude """ networkmanager = C.NETWORKMANAGER config = configparser.RawConfigParser() MAC = Linux.get_interface_mac(interface) exclude = { "MAC": "mac:{}".format(MAC), "interface": "interface-name:{}".format(interface), } if not Remove: if path.exists(networkmanager): config.read(networkmanager) try: config.add_section("keyfile") except configparser.DuplicateSectionError: config.set( "keyfile", "unmanaged-devices", "{}".format( exclude["interface"] if MAC != None else exclude["MAC"] ), ) else: config.set( "keyfile", "unmanaged-devices", "{}".format( exclude["interface"] if MAC != None else exclude["MAC"] ), ) finally: with open(networkmanager, "wb") as configfile: config.write(configfile) return True return False elif Remove: if path.exists(networkmanager): config.read(networkmanager) try: config.remove_option("keyfile", "unmanaged-devices") with open(networkmanager, "wb") as configfile: config.write(configfile) return True except configparser.NoSectionError: return True return False
class Docker(Mode): configRoot = "docker" subConfig = "docker" ID = "docker" Name = "Wireless Docker AP Mode" def __init__(self, parent=0): super(Docker, self).__init__(parent) self.confgSecurity = [] @property def Settings(self): return DockerSettings.getInstance() def getSettings(self): return self.Settings def Initialize(self): # settings ap self.Settings.Configure() if not (self.Settings.checkNetworkAP()): sys.exit(1) self.check_Wireless_Security() # add extra hostapd settings self.addExtraHostapdSettings() ignore = ("interface=", "ssid=", "channel=", "essid=") with open(C.DOCKERHOSTAPDCONF_PATH, "w") as apconf: for i in self.Settings.SettingsAP["hostapd"]: apconf.write(i) apconf.close() def boot(self): # create thread for hostapd and connect get_Hostapd_Response function self.reactor = ProcessHostapd( {self.getHostapdPath: [C.DOCKERHOSTAPDCONF_PATH]}, "MDSNjD") self.reactor.setObjectName("hostapd_{}".format(self.ID)) self.reactor.statusAP_connected.connect(self.get_Hostapd_Response) self.reactor.statusAPError.connect(self.get_error_hostapdServices) def setIptables(self): # this mehtod is called when post start all threads self.interfacesLink = Refactor.get_interfaces() print( display_messages("sharing internet connection with NAT...", info=True)) self.ifaceHostapd = self.conf.get("accesspoint", "interface") iptables_file = { "iptables.ipv4.nat": [ "# Generated by iptables-save v1.6.0 on Sun Jun 5 11:18:08 2016" "*nat" ":PREROUTING ACCEPT [123:11003]" ":INPUT ACCEPT [5:1402]" ":OUTPUT ACCEPT [2:152]" ":POSTROUTING ACCEPT [0:0]" ":DOCKER - [0:0]" "-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER" "-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER" "-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE" "-A POSTROUTING -o $inet -j MASQUERADE" "COMMIT" "# Completed on Sun Jun 5 11:18:08 2016" "# Generated by iptables-save v1.6.0 on Sun Jun 5 11:18:08 2016" "*filter" ":INPUT ACCEPT [320:23582]" ":FORWARD ACCEPT [0:0]" ":OUTPUT ACCEPT [194:28284]" ":DOCKER - [0:0]" "-A FORWARD -o docker0 -j DOCKER" "-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT" "-A FORWARD -i docker0 ! -o docker0 -j ACCEPT" "-A FORWARD -i docker0 -o docker0 -j ACCEPT" "-A FORWARD -i $inet -o $wlan -m state --state RELATED,ESTABLISHED -j ACCEPT" "-A FORWARD -i $wlan -o $inet -j ACCEPT" "COMMIT" "# Completed on Sun Jun 5 11:18:08 2016" ] } with open(C.DOCKERIPTABLESPATH, "w") as f: for line in iptables_file["iptables.ipv4.nat"]: try: if "$inet" in line: line = line.replace( "$inet", self.interfacesLink["activated"][0]) if "$wlan" in line: line = line.replace("$wlan", self.ifaceHostapd) f.write("{}\n".format(line)) except Exception: pass f.close() popen("iptables-restore < {}".format(C.DOCKERIPTABLESPATH)) def get_Hostapd_Response(self, data): if self.conf.get("accesspoint", "status_ap", format=bool): print( display_messages( "{} client has left AP ".format(setcolor(data, color="red")), info=True, )) def setNetworkManager(self, interface=str, Remove=False): """ mac address of interface to exclude """ networkmanager = C.NETWORKMANAGER config = configparser.RawConfigParser() MAC = Linux.get_interface_mac(interface) exclude = { "MAC": "mac:{}".format(MAC), "interface": "interface-name:{}".format(interface), } if not Remove: if path.exists(networkmanager): config.read(networkmanager) try: config.add_section("keyfile") except configparser.DuplicateSectionError: config.set( "keyfile", "unmanaged-devices", "{}".format(exclude["interface"] if MAC != None else exclude["MAC"]), ) else: config.set( "keyfile", "unmanaged-devices", "{}".format(exclude["interface"] if MAC != None else exclude["MAC"]), ) finally: with open(networkmanager, "wb") as configfile: config.write(configfile) return True return False elif Remove: if path.exists(networkmanager): config.read(networkmanager) try: config.remove_option("keyfile", "unmanaged-devices") with open(networkmanager, "wb") as configfile: config.write(configfile) return True except configparser.NoSectionError: return True return False