def is_private_logged_in(): if is_on_local_network(): return True sessions = read_config(private_session_file) return _is_logged_in(sessions)
hash_file = '/home/bacso/myhouse/hash/login' USERNAME = '******' PASSWORD = '******' USERNAME_PUBLIC = 'public' USERNAME_PRIVATE = 'private' output = '' if is_on_local_network(): output = html_output('logged_in.html') output.add_parameter( 'data', 'No login needed, you are on the local network') else: data = cgi.FieldStorage() if data: hashes = read_config(hash_file) username = data[USERNAME].value if username == USERNAME_PUBLIC or username == USERNAME_PRIVATE: m = hashlib.sha256() m.update(data[PASSWORD].value) if hashes[username] == m.hexdigest(): expires = datetime.now() + expire_time_in_hours data = {os.environ['REMOTE_ADDR']: str(expires)} if username == USERNAME_PUBLIC: write_config(public_session_file, data) else: write_config(private_session_file, data) if is_private_logged_in(): output = html_output('logged_in.html')