def asociarSmartphone(): global usersLogged global uid uid = None Read.changeEnableRegister(False) accessGranted = False mensaje = None if request.remote_addr in usersLogged: resetTimeout(request.remote_addr) if request.method == 'POST': uid = request.form.get('uid') description = request.form.get('descripcion') hostname = request.form.get('hostname') authSmart = request.form.get('master') print( str(usersLogged[request.remote_addr]) + ' ' + str(uid) + ' ' + str(hostname) + ' ' + str(description) + ' ' + str(authSmart)) try: uH = userHandler.USERHANDLER() added = uH.addSmartphone(uid, description, hostname, authSmart) if (added == False): uH.updateSmartphone(uid, description, hostname, authSmart) mensaje, related = uH.relateSmartphone( usersLogged[request.remote_addr], uid) except Exception as e: print(str(e)) finally: uH.close() else: return redirect('/') print(str(usersLogged)) return render_template("asociarSmartphone.html", mensaje=mensaje)
def registro(): global usersLogged accessGranted = False if request.remote_addr in usersLogged: accessGranted = True else: if request.method == 'POST': user = request.form.get('user') passwd = request.form.get('passwd') description = request.form.get('description') try: uH = userHandler.USERHANDLER() accessGranted = uH.newUser(user, passwd, description, request.remote_addr) if accessGranted: fH = fileHandler.FILEHANDLER() timers[request.remote_addr] = threading.Timer( int(fH.readParam('usertimeout')), logoutUser, [request.remote_addr]) timers[request.remote_addr].start() usersLogged[request.remote_addr] = user return redirect('/') except Exception as e: print(str(e)) finally: uH.close() print(str(usersLogged)) return render_template("register.html", accessGranted=accessGranted)
def end(signal, frame): print('CTRL+C catched') uH = userHandler.USERHANDLER() try: uH.logoutAllUsers() except Exception as e: print(str(e)) finally: uH.close() sys.exit(0)
def logout(): global usersLogged uH = userHandler.USERHANDLER() try: user = usersLogged[request.remote_addr] ip = request.remote_addr if ip in usersLogged: uH.logout(user) usersLogged.pop(ip) except Exception as e: pass finally: uH.close() return redirect('/')
def logoutUser(*args): global usersLogged ip = str(args[0]) try: user = usersLogged[ip] if ip in usersLogged: uH = userHandler.USERHANDLER() uH.logout(user) usersLogged.pop(ip) print(ip + ' session closed') except Exception as e: pass finally: uH.close()
def finPrograma(): global usersLogged if request.remote_addr in usersLogged: resetTimeout(request.remote_addr) uH = userHandler.USERHANDLER() uH.logoutAllUsers() try: s = socket.socket() s.connect(('127.0.0.1', 65000)) s.send(b'x00x05') s.close() except Exception as e: print(str(e)) return redirect("/menu/calefaccion", code=302) else: return redirect('/')
def distanceThread(cond, kill): global alarmSet global collected print('distance thread') distanceHand = distanceHandler.DISTANCEHANDLER() while not kill.is_set(): distance = distanceHand.distance() if (distance != 0.0): print(str(distance) + 'm') if ((distance <= 1.5) and (alarmSet == False)): uH = userHandler.USERHANDLER() try: nConnectedDevices = uH.countDevicesAtHome() finally: uH.close() #If nobody is at home if (nConnectedDevices == 0): collected = 'x00x06' robotStateChange(cond, collected) time.sleep(1)
def index(): global usersLogged global timers accessGranted = False if (request.remote_addr in usersLogged): accessGranted = True if request.method == 'POST': print('***POST***') user = request.form.get('user') passwd = request.form.get('passwd') ip = request.remote_addr try: uH = userHandler.USERHANDLER() accessGranted = uH.getAccess(user, passwd, ip) except Exception as e: print(str(e)) finally: uH.close() if (accessGranted): fH = fileHandler.FILEHANDLER() timers[ip] = threading.Timer(int(fH.readParam('usertimeout')), logoutUser, [ip]) timers[ip].start() usersLogged[ip] = user templateData = { 'warningAccess': False, 'accesGranted': accessGranted, 'user': user } return render_template('index.html', **templateData) else: templateData = { 'warningAccess': True, 'accesGranted': accessGranted } return render_template('index.html', **templateData) templateData = {'warningAccess': False, 'accesGranted': accessGranted} return render_template('index.html', **templateData)