Skip to content

Commit

Permalink
add support for duo (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
onlykey authored Jan 18, 2022
1 parent 0b3cd8b commit 3a60674
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 172 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Or you can run commands in an interactive shell like this:

```
$ onlykey-cli
OnlyKey CLI v1.2.7
OnlyKey CLI v1.2.8
Press the right arrow to insert the suggestion.
Press Control-C to retry. Control-D to exit.
Expand Down
74 changes: 54 additions & 20 deletions onlykey/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,29 @@ def prompt_pin():
print(only_key.read_string())
print ()
elif sys.argv[1] == 'getlabels':
tmp = {}
for slot in only_key.getlabels():
tmp[slot.name] = slot
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
for slot_name in slots:
print(tmp[slot_name].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print()
tmp = {}
only_key.set_time(time.time())
okversion = only_key.read_string()
if okversion[19] == 'c':
for slot in only_key.getlabels():
tmp[slot.name] = slot
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
for slot_name in slots:
print(tmp[slot_name].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print()
else:
for slot in only_key.getduolabels():
tmp[slot.name] = slot
slots = iter(['Green 1a', 'Green 2a', 'Green 3a', 'Green 1b', 'Green 2b', 'Green 3b', 'Blue 1a', 'Blue 2a', 'Blue 3a', 'Blue 1b', 'Blue 2b', 'Blue 3b', 'Yellow 1a', 'Yellow 2a', 'Yellow 3a', 'Yellow 1b', 'Yellow 2b', 'Yellow 3b', 'Purple 1a', 'Purple 2a', 'Purple 3a', 'Purple 1b', 'Purple 2b', 'Purple 3b'])
for slot_name in slots:
print(tmp[slot_name].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print()
elif sys.argv[1] == 'getkeylabels':
tmp = {}
for slot in only_key.getkeylabels():
Expand Down Expand Up @@ -155,6 +170,8 @@ def prompt_pin():
slot_id = 11
elif sys.argv[2] == '6b':
slot_id = 12
else:
slot_id = int(sys.argv[2])
except:
print("setslot [id] [type] [value]")
print("[id] must be slot number 1a - 6b")
Expand Down Expand Up @@ -357,7 +374,7 @@ def prompt_pin():
elif sys.argv[1] == 'wipemode':
only_key.setslot(1, MessageField.WIPEMODE, int(sys.argv[2]))
elif sys.argv[1] == 'keytypespeed':
only_key.setslot(1, MessageField.KEYTYPESPEED, int(sys.argv[2]))
only_key.setslot(int(sys.argv[2]), MessageField.KEYTYPESPEED, int(sys.argv[3]))
elif sys.argv[1] == 'ledbrightness':
only_key.setslot(1, MessageField.LEDBRIGHTNESS, int(sys.argv[2]))
elif sys.argv[1] == 'touchsense':
Expand All @@ -379,7 +396,7 @@ def prompt_pin():
elif sys.argv[1] == 'hmackeymode':
only_key.setslot(1, MessageField.HMACMODE, int(sys.argv[2]))
elif sys.argv[1] == 'version':
print('OnlyKey CLI v1.2.7')
print('OnlyKey CLI v1.2.8')
elif sys.argv[1] == 'fwversion':
only_key.set_time(time.time())
okversion = only_key.read_string()
Expand Down Expand Up @@ -456,7 +473,7 @@ def prompt_pin():
else:

# Print help.
print('OnlyKey CLI v1.2.7')
print('OnlyKey CLI v1.2.8')
print('Control-D to exit.')
print()

Expand Down Expand Up @@ -527,14 +544,29 @@ def mprompt():
print(only_key.read_string())
print()
elif data[0] == 'getlabels':
tmp = {}
for slot in only_key.getlabels():
tmp[slot.name] = slot
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
for slot_name in slots:
print(tmp[slot_name].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print()
tmp = {}
only_key.set_time(time.time())
okversion = only_key.read_string()
if okversion[19] == 'c':
for slot in only_key.getlabels():
tmp[slot.name] = slot
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
for slot_name in slots:
print(tmp[slot_name].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print()
else:
for slot in only_key.getduolabels():
tmp[slot.name] = slot
slots = iter(['Green 1a', 'Green 2a', 'Green 3a', 'Green 1b', 'Green 2b', 'Green 3b', 'Blue 1a', 'Blue 2a', 'Blue 3a', 'Blue 1b', 'Blue 2b', 'Blue 3b', 'Yellow 1a', 'Yellow 2a', 'Yellow 3a', 'Yellow 1b', 'Yellow 2b', 'Yellow 3b', 'Purple 1a', 'Purple 2a', 'Purple 3a', 'Purple 1b', 'Purple 2b', 'Purple 3b'])
for slot_name in slots:
print(tmp[slot_name].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print(tmp[next(slots)].to_str().replace('ÿ'," "))
print()
elif data[0] == 'getkeylabels':
tmp = {}
for slot in only_key.getkeylabels():
Expand Down Expand Up @@ -568,6 +600,8 @@ def mprompt():
slot_id = 11
elif data[1] == '6b':
slot_id = 12
else:
slot_id = int(data[1])
except:
print("setslot [id] [type] [value]")
print("[id] must be slot number 1a - 6b")
Expand Down Expand Up @@ -839,7 +873,7 @@ def mprompt():
continue
elif data[0] == 'version':
try:
print('OnlyKey CLI v1.2.7')
print('OnlyKey CLI v1.2.8')
except:
continue
elif data[0] == 'fwversion':
Expand Down
Loading

0 comments on commit 3a60674

Please sign in to comment.