startup.py
def check_cred(ssid, password):
    '''Validates ssid and password and returns True if valid and False if not valid'''
    wpadir = currentdir + '/wpa/'
    testconf = wpadir + 'test.conf'
    wpalog = wpadir + 'wpa.log'
    wpapid = wpadir + 'wpa.pid'

    if not os.path.exists(wpadir):
        os.mkdir(wpadir)

    for _file in [testconf, wpalog, wpapid]:
        if os.path.exists(_file):
            os.remove(_file)

    # Generate temp wpa.conf
    result = subprocess.check_output(['wpa_passphrase', ssid, password])
    with open(testconf, 'w') as f:
        f.write(result.decode('utf-8'))

    def stop_ap(stop):
        if stop:
            # Services need to be stopped to free up wlan0 interface
            print(subprocess.check_output(['systemctl', "daemon-reload"]))
            print(subprocess.check_output(['systemctl', "stop", "hostapd", "dnsmasq", "dhcpcd"]))
        else:
            print(subprocess.check_output(['systemctl', "daemon-reload"]))
            print(subprocess.check_output(['systemctl', "restart", "dnsmasq", "dhcpcd"]))
            time.sleep(15)
            print(subprocess.check_output(['systemctl', "restart", "hostapd"]))

    # Sentences to check for
    fail = "CTRL-EVENT-ASSOC-REJECT"
    success = "CTRL-EVENT-CONNECTED"

    stop_ap(True)

    result = subprocess.check_output(['wpa_supplicant',
                                      "-Dnl80211",
                                      "-iwlan0",
                                      "-c/" + testconf,
                                      "-f", wpalog,
                                      "-B",
                                      "-P", wpapid])

    checkwpa = True
    while checkwpa:
        with open(wpalog, 'r') as f:
            content = f.read()
            if success in content:
                valid_psk = True
                checkwpa = False
            elif fail in content:
                valid_psk = False
                checkwpa = False
            else:
                continue

    # Kill wpa_supplicant to stop it from setting up dhcp, dns
    with open(wpapid, 'r') as p:
        pid = p.read()
        pid = int(pid.strip())
        os.kill(pid, signal.SIGTERM)

    stop_ap(False) # Restart services
    return valid_psk
Validates ssid and password and returns True if valid and False if not valid
Validates ssid and password and returns True if valid and False if not valid
Validates ssid and password and returns True if valid and False if not valid
def check_cred(ssid, password):
    wpadir = currentdir + '/wpa/'
    testconf = wpadir + 'test.conf'
    wpalog = wpadir + 'wpa.log'
    wpapid = wpadir + 'wpa.pid'
    if not os.path.exists(wpadir):
        os.mkdir(wpadir)
    for _file in [testconf, wpalog, wpapid]:
        if os.path.exists(_file):
            os.remove(_file)
    result = subprocess.check_output(['wpa_passphrase', ssid, password])
    with open(testconf, 'w') as f:
        f.write(result.decode('utf-8'))
    def stop_ap(stop):
        if stop:
            print(subprocess.check_output(['systemctl', "daemon-reload"]))
            print(subprocess.check_output(['systemctl', "stop", "hostapd", "dnsmasq", "dhcpcd"]))
        else:
            print(subprocess.check_output(['systemctl', "daemon-reload"]))
            print(subprocess.check_output(['systemctl', "restart", "dnsmasq", "dhcpcd"]))
            time.sleep(15)
            print(subprocess.check_output(['systemctl', "restart", "hostapd"]))
    fail = "CTRL-EVENT-ASSOC-REJECT"
    success = "CTRL-EVENT-CONNECTED"
    stop_ap(True)
    result = subprocess.check_output(['wpa_supplicant',
                                      "-Dnl80211",
                                      "-iwlan0",
                                      "-c/" + testconf,
                                      "-f", wpalog,
                                      "-B",
                                      "-P", wpapid])
    checkwpa = True
    while checkwpa:
        with open(wpalog, 'r') as f:
            content = f.read()
            if success in content:
                valid_psk = True
                checkwpa = False
            elif fail in content:
                valid_psk = False
                checkwpa = False
            else:
                continue
    with open(wpapid, 'r') as p:
        pid = p.read()
        pid = int(pid.strip())
        os.kill(pid, signal.SIGTERM)
    stop_ap(False) 
    return valid_psk
def check_cred ( ssid , password ) : wpadir = currentdir + '/wpa/' testconf = wpadir + 'test.conf' wpalog = wpadir + 'wpa.log' wpapid = wpadir + 'wpa.pid' if not os . path . exists ( wpadir ) : os . mkdir ( wpadir ) for _file in [ testconf , wpalog , wpapid ] : if os . path . exists ( _file ) : os . remove ( _file ) result = subprocess . check_output ( [ 'wpa_passphrase' , ssid , password ] ) with open ( testconf , 'w' ) as f : f . write ( result . decode ( 'utf-8' ) ) def stop_ap ( stop ) : if stop : print ( subprocess . check_output ( [ 'systemctl' , "daemon-reload" ] ) ) print ( subprocess . check_output ( [ 'systemctl' , "stop" , "hostapd" , "dnsmasq" , "dhcpcd" ] ) ) else : print ( subprocess . check_output ( [ 'systemctl' , "daemon-reload" ] ) ) print ( subprocess . check_output ( [ 'systemctl' , "restart" , "dnsmasq" , "dhcpcd" ] ) ) time . sleep ( 15 ) print ( subprocess . check_output ( [ 'systemctl' , "restart" , "hostapd" ] ) ) fail = "CTRL-EVENT-ASSOC-REJECT" success = "CTRL-EVENT-CONNECTED" stop_ap ( True ) result = subprocess . check_output ( [ 'wpa_supplicant' , "-Dnl80211" , "-iwlan0" , "-c/" + testconf , "-f" , wpalog , "-B" , "-P" , wpapid ] ) checkwpa = True while checkwpa : with open ( wpalog , 'r' ) as f : content = f . read ( ) if success in content : valid_psk = True checkwpa = False elif fail in content : valid_psk = False checkwpa = False else : continue with open ( wpapid , 'r' ) as p : pid = p . read ( ) pid = int ( pid . strip ( ) ) os . kill ( pid , signal . SIGTERM ) stop_ap ( False ) return valid_psk
Validates ssid and password and returns True if valid and False if not valid
Validates ssid and password and returns True if valid and False if not valid
'''Validates ssid and password and returns True if valid and False if not valid''' # Generate temp wpa.conf # Services need to be stopped to free up wlan0 interface # Sentences to check for # Kill wpa_supplicant to stop it from setting up dhcp, dns # Restart services
ssid
password