Exemple #1
0
def ui_login():
    """
    Handle authentication steps during user login.
    """
    if client_conn.is_login():
        print("You already login")
        return
    # Connect to server
    print("Username: "******"Login success")
    else:
        print("Login failure")
        return
    # Download the filelist
    status = client_conn.download(mylist)
    if status:
        # List exist on server and successfuly downloaded
        filelist.load(password, "salt", mylist)
    else:
        # List not exist on server
        pass
Exemple #2
0
def ui_listfile():
    if not client_conn.is_login():
        print("Please login first")
        return
    # Get share files
    client_conn.get_share()
    # Listing
    filelist.listing()
Exemple #3
0
def ui_delete():
    if not client_conn.is_login():
        print("Please login first")
        return
    print("Filename: ", end='')
    filename = input()
    record = filelist.get(filename)
    if record:
        client_conn.delete(record['filename_rand'])
    filelist.delete(filename)
Exemple #4
0
def exit_program():
    """
    Save the list before exit the program.
    """
    os.system("rm -f *.data")
    if client_conn.is_login():
        filelist.save(password, "salt", mylist)
        client_conn.upload(mylist)
        client_conn.logout()
    print("Bye")
    sys.exit()
Exemple #5
0
def ui_download():
    if not client_conn.is_login():
        print("Please login first")
        return
    print("Filename: ", end='')
    filename = input()
    print("Save as: ", end='')
    saveas = input()
    status = client_conn.download_file(filename, saveas)
    if status:
        print("Download success")
    else:
        print("Download failure")
Exemple #6
0
def ui_logout():
    """
    Handle the logout events.
    """
    if client_conn.is_login():
        filelist.save(password, "salt", mylist)
        client_conn.upload(mylist)
    status = client_conn.logout()
    filelist.mylist = {}
    if status:
        print("Logout success")
    else:
        print("Logout failure")
Exemple #7
0
def ui_share():
    if not client_conn.is_login():
        print("Please login first")
        return
    # Enter recipient username
    print("Invite people (username): ", end='')
    recipient = input().strip()
    # Recipient's email
    recv_email = None
    print("Recipient's email address: ", end='')
    recv_email = input().strip()

    # Get target's public key
    choice = None
    while choice != "1" and choice != "2":
        print("Obtain the recipent's public key:")
        print(" 1) Download from Hong Kong Post")
        print(" 2) Input from file (debug)")
        print("Choice [1,2]: ", end='')
        choice = input().strip()
    public_key = None
    try:
        if choice == "1":
            # Download from HK Post
            public_key = rsa.get_cert(recv_email, True)
            sender = "*****@*****.**"
        if choice == "2":
            # Import from file
            sender = "*****@*****.**"
            filename = "key/public_key.pem"
            public_key = rsa.load_public_cert_from_file(filename)
    except Exception as e:
        log.print_exception(e)
        log.print_error("error", "failed to load cert")
        return 

    # Get user's private key to signoff
    if os.path.isfile("/home/star/.ssh/me.key.pem2"):
        private_key = rsa.load_private_cert_from_file("/home/star/.ssh/me.key.pem2")
    else:
        private_key = rsa.load_private_cert_from_file("key/private_key.pem")

    # Encrypt the filelist record
    print("File to share: ", end='')
    filename = input()
    record = filelist.export_record(filename, sender, recv_email, public_key, private_key)
    if record == None:
        print("Failed to share file")
        return
    # Send to server
    client_conn.share(recipient, record)
Exemple #8
0
def ui_upload():
    """
    Encrypte the file and upload.
    """
    if not client_conn.is_login():
        print("Please login first")
        #return
    print("Filename: ", end='')
    filename = input()
    status = client_conn.upload_file(filename)
    if status:
        print("Upload success")
    else:
        print("Upload failure")
Exemple #9
0
def print_help():
    """
    Print the available command list.
    """
    print()
    print()
    if client_conn.is_login():
        print("Login as: "+ client_conn.username())
    print("Help:")
    print("General:")
    print("  c   create a new account")
    print("  i   login")
    print("  o   logout")
    print("  p   print this menu")
    print("  q   logout and quit")
    print()
    print("Files:")
    print("  d   download file")
    print("  l   list file")
    print("  r   delete file")
    print("  s   share file")
    print("  u   upload file")
    print()