-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowtoken
executable file
·49 lines (43 loc) · 1.93 KB
/
showtoken
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
# rfc6238 - RFC6238-compliant TOTP token generator with Steam Authenticator support
# Copyright (C) 2020-2020 Johannes Bauer
#
# This file is part of rfc6238.
#
# rfc6238 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; this program is ONLY licensed under
# version 3 of the License, later versions are explicitly excluded.
#
# rfc6238 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rfc6238; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Johannes Bauer <JohannesBauer@gmx.de>
import time
import sys
import os
from FriendlyArgumentParser import FriendlyArgumentParser
from Account import Account
run_dir = os.path.dirname(os.path.realpath(__file__))
default_accounts_file = run_dir + "/accounts.json"
parser = FriendlyArgumentParser(description = "Display a number of RFC6238-based TOTP codes")
parser.add_argument("-d", "--token-db", metavar = "filename", type = str, default = default_accounts_file, help = "Specifies accounts file to use, a JSON file which stores all secrets. Defaults to %(default)s.")
parser.add_argument("-t", "--timeout", metavar = "secs", type = int, default = 120, help = "Quit after this number of seconds. Defaults to %(default)d.")
args = parser.parse_args(sys.argv[1:])
accounts = Account.load_accounts_from_file(args.token_db)
def clrscr():
sys.stdout.write("\x1b[H\x1b[2J\x1b[3J")
sys.stdout.flush()
length = max(len(account.name) for account in accounts)
for i in range(args.timeout):
clrscr()
for account in accounts:
account.print_token(length)
time.sleep(1)
clrscr()