def getsettings(): settings = configlib.load_settings() process = subprocess.Popen(["/home/pi/quickpi/scripts/getmac.sh", "wlan0"], stdout=subprocess.PIPE) (output, err) = process.communicate() settings["WIFIMAC"] = output.decode("utf-8") process = subprocess.Popen(["/home/pi/quickpi/scripts/getmac.sh", "eth0"], stdout=subprocess.PIPE) (output, err) = process.communicate() settings["ETHMAC"] = output.decode("utf-8") return json.dumps(settings)
def login(): settings = configlib.load_settings() skippwdset = request.args.get('skippwdset') print("skippwdset", skippwdset) if request.method == 'GET': if "WEBCONFIGPASSWORD" in settings: return send_from_directory('.', "login.html") else: if skippwdset: user = User() user.id = 'admin' flask_login.login_user(user) return redirect('/') else: return send_from_directory('.', "chgpwd.html") if "WEBCONFIGPASSWORD" in settings: print("I have a stored password") if configlib.validate_password(request.form['password']): user = User() user.id = 'admin' #print("Valid password") flask_login.login_user(user) return redirect('/') else: #print("Password doesn't match") return redirect(url_for('login') + "?badpassword=1") else: password = request.form['password'] cpassword = request.form['password'] if password == cpassword: settings["WEBCONFIGPASSWORD"] = password configlib.save_settings(settings) #return send_from_directory('.', "login.html") return redirect(url_for('login')) return 'Bad login'
def savesettings(): if not flask_login.current_user.is_authenticated: return 'Not authenticated', 403 settings = configlib.load_settings() json = request.get_json() staticnetwork = "0" bluetoothenabled = "0" useproxy = "0" useproxyuser = "******" disabletunnel = "0" staticnetwork_eth = "0" updatesshpass = "******" if json["isstaticip"]: staticnetwork = "1" if json["isstaticip_eth"]: staticnetwork_eth = "1" if json["isbluetoothenabled"]: bluetoothenabled = "1" if json["useproxy"]: useproxy = "1" if json["useproxyuser"]: useproxyuser = "******" if json["disabletunnel"]: disabletunnel = "1" if json["updatesshpass"]: updatesshpass = "******" settings["SSID"] = json["ssid"] if json["password"].strip(): settings["PASSWORD"] = json["password"] settings["STATICNETWORK"] = staticnetwork settings["STATICIPADDR"] = removewhitespace(json["ip"]) settings["STATICMASK"] = removewhitespace(json["sn"]) settings["STATICGATEWAY"] = removewhitespace(json["gw"]) settings["STATICDNS"] = removewhitespace(json["ns"]) settings["STATICNETWORK_ETH"] = staticnetwork_eth settings["STATICIPADDR_ETH"] = removewhitespace(json["ip_eth"]) settings["STATICMASK_ETH"] = removewhitespace(json["sn_eth"]) settings["STATICGATEWAY_ETH"] = removewhitespace(json["gw_eth"]) settings["STATICDNS_ETH"] = removewhitespace(json["ns_eth"]) settings["ENABLEBLUETOOTH"] = bluetoothenabled settings["NAME"] = removewhitespace(json["qname"]) settings["SCHOOL"] = removewhitespace(json["school"]) settings["USEPROXY"] = useproxy settings["USEPROXYUSER"] = useproxyuser settings["PROXYADDRESS"] = removewhitespace(json["proxyaddress"]) settings["PROXYPORT"] = removewhitespace(json["proxyport"]) settings["PROXYUSER"] = removewhitespace(json["proxyuser"]) settings["HIDEAPPASSWORD"] = "******" settings["DISABLETUNNEL"] = disabletunnel if json["proxypassword"].strip(): settings["PROXYPASSWORD"] = removewhitespace(json["proxypassword"]) settings["UPDATESSHPASSWORD"] = updatesshpass if json["systempassword"].strip(): settings["WEBCONFIGPASSWORD"] = removewhitespace( json["systempassword"]) configlib.save_settings(settings) print(request.get_json()) return "OK"
def setPassword(userName: str, password: str): p = subprocess.Popen(["/usr/sbin/chpasswd"], universal_newlines=True, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = p.communicate(userName + ":" + password + "\n") assert p.wait() == 0 if stdout or stderr: raise Exception("Error encountered changing the password!") #setPassword("pi", "patito") settings = configlib.load_settings() updatepassword = False havepassword = False try: if settings["UPDATESSHPASSWORD"] == "1": print("Update ssh password set") updatepassword = True except: pass password = "" try: if settings["WEBCONFIGPASSWORD"]: password = settings["WEBCONFIGPASSWORD"]