Ejemplo n.º 1
0
def is_private_logged_in():
    if is_on_local_network():
        return True

    sessions = read_config(private_session_file)
    return _is_logged_in(sessions)
Ejemplo n.º 2
0
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')