-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHASduck_config.py
executable file
·228 lines (202 loc) · 5.82 KB
/
HASduck_config.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/python3
#
# HASduck Config
#
#
# Usage: HASduck_config.py
#
#
# 20210303-1300
#
#
# Import Libraries
#
import argparse
import configparser
import json
import os
import sys
import time
#
# VARIABLES
#
hasDUCKver="HASduck v1.0"
hasVIOLETcfg = "cfg/hasVIOLET.json"
hasDUCKcfg = "cfg/hasDUCK.json"
hvdnLOGO = "cfg/hvdn-logo.xbm"
#
# CLASSES
#
class Duckwalk:
def __init__(self):
self.cfgjson = hasDUCKcfg
with open(self.cfgjson) as configFileJson:
jsonConfig = json.load(configFileJson)
self.message = jsonConfig["0"]["message"]
self.interval = jsonConfig["0"]["interval"]
self.interval_start = time.time()
self.interval_stop = int(self.interval_start + self.interval)
self.trigger = jsonConfig["0"]["trigger"] # values include bluetooth, custo, gps, none, wifi
self.trigger_value = jsonConfig["0"]["trigger_value"]
self.action = jsonConfig["0"]["action"] # values include custom, next, reset, quit
self.duration = jsonConfig["0"]["duration"]
self.duration_start = time.time()
self.duration_stop = int(self.duration_start + self.duration)
return
def trigger(self, ttype, tvalue):
return
def action(self, taction):
return
#
# FUNCTIONS
#
def main_menu():
os.system("clear")
print ()
print ('- - - - - HASduck Config Tool - - - - -')
print ()
print (' 1 Message ',Ducky.message)
print (' 2 Interval ',Ducky.interval)
print (' 3 Trigger ',Ducky.trigger, Ducky.trigger_value)
print (' 4 Action ',Ducky.action)
print (' 5 Duration ',Ducky.duration)
print ()
print ('- - - - - - - - - - - - - - - -')
print()
print (' 9 Quick Guide ')
print (' 99 Write changes ')
print (' 0 Exit Menu ')
print ()
fun = input('Select option: ')
if fun=="1":
setducky_message()
elif fun=="2":
setducky_interval()
elif fun=="3":
setducky_trigger()
elif fun=="4":
setducky_action()
elif fun=="5":
setducky_duration()
elif fun=="9":
show_quickguide()
elif fun=="99":
write_changes()
elif fun=="0":
exit(0)
else:
print ("Programmer error: unrecognized option")
pass
def setducky_message():
print ()
print ('--')
Ducky.message = input('-- Enter message: ')
return
def setducky_interval():
print ()
print ('--')
Ducky.interval = input('Enter seconds between message being sent: ')
return
def setducky_trigger():
print ()
print ('-- Trigger Type: ')
print ('-- ')
funnier = input('-- (b)luetooth, (c)ustom, (g)ps, (n)one, or (w)ifi: ')
if funnier=="b":
Ducky.trigger = "bluetooth"
Ducky.trigger_value = input('-- Value: ')
elif funnier=="c":
Ducky.trigger = "custom"
Ducky.trigger_value = input('-- Value: ')
elif funnier=="g":
Ducky.trigger = "gps"
Ducky.trigger_value = input('-- Value: ')
elif funnier=="n":
Ducky.trigger = "none"
Ducky.trigger_value = "0"
elif funnier=="w":
Ducky.trigger = "wifi"
Ducky.trigger_value = input('-- Value: ')
else:
print ("Programmer error: unrecognized option")
Ducky.trigger = "none"
Ducky.trigger_value = "0"
return
def setducky_action():
print ()
print ('-- Action Type: ')
print ('-- ')
funnier = input('-- (c)ustom, (n)ext, (r)eset, or (q)uit: ')
if funnier=="c":
Ducky.action = "custom"
elif funnier=="n":
Ducky.action = "next"
elif funnier=="r":
Ducky.action = "reset"
elif funnier=="q":
Ducky.action = "quit"
else:
print ("Programmer error: unrecognized option")
Ducky.action = "reset"
return
def setducky_duration():
print ()
print ('--')
Ducky.duration = input('Enter duration of beacon in seconds: ')
return
def show_quickguide():
os.system("clear")
print ()
print ('HASduck Framework')
print ()
print ('To make this a smart beacon we have created a short command set, order specific, all lower case:')
print ()
print (' message ')
print (' then followed with whatever your message is. No quotes required')
print ()
print (' interval')
print (' followed with number of seconds between message transmissions')
print ()
print (' trigger')
print (' during countdown to the next interval, a trigger can be set. Trigger values include')
print (' when signals are detected (wifi or bluetooth), current GPS location and custom triggers')
print (' can be written in Python.')
print ()
print (' action ')
print (' given a trigger, what action can be taken. This includes reset, next, custom, quit')
print ()
print (' duration')
print (' How long in seconds until the beacon stops')
print ()
print ('NOTE: Trigger types and actions have yet to be coded. For now beacon runs for interval and duration')
print ('specified.')
print ()
print ()
programPause = input("Press the <ENTER> key to continue...")
return
def write_changes():
with open(Ducky.cfgjson) as configReadFile:
data = json.load(configReadFile)
time.sleep(3)
data["0"]["message"] = Ducky.message
data["0"]["interval"] = int(Ducky.interval)
data["0"]["trigger"] = Ducky.trigger
data["0"]["trigger_value"] = Ducky.trigger_value
data["0"]["action"] = Ducky.action
data["0"]["duration"] = int(Ducky.duration)
print ('Updating hasDUCK.json')
with open(Ducky.cfgjson, 'w') as configWriteFile:
json.dump(data, configWriteFile, indent=3)
time.sleep(3)
#
# SETUP
#
#
# OBJECTS
#
Ducky = Duckwalk()
#
# MAIN
#
while True:
main_menu()