-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (51 loc) · 1.88 KB
/
main.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
from tkinter import *
import os
from resources_helper import *
root = Tk()
root.title("Headless Generator")
root.iconbitmap(default=resource_path("icon.ico"))
# Labels and Text entry
countryLabel = Label(root, text="Country code")
countryLabel.grid(column=0, row=0, pady=6, padx=12)
country = Entry(root)
country.insert(0, "US")
country.grid(column=1, row=0, pady=6, padx=12)
ssidLabel = Label(root, text="Network SSID ")
ssidLabel.grid(column=0, row=1, pady=6, padx=12)
ssid = Entry(root)
ssid.grid(column=1, row=1, pady=6, padx=12)
passwordLabel = Label(root, text="Network password")
passwordLabel.grid(column=0, row=2, pady=6, padx=12)
password = Entry(root)
password.grid(column=1, row=2, pady=6, padx=12)
########################
# SSH checkbox
ssh_state = BooleanVar()
ssh_checkbox = Checkbutton(root, text="Enable SSH", variable=ssh_state)
ssh_checkbox.grid(columnspan=2, sticky=N+S, pady=6)
# Button
genButton = Button(root, text="Generate Files", command=lambda: write_files())
genButton.grid(columnspan=2, sticky=N+S, pady=6)
def getSupplicant():
# Array should be initialized at write file calling
# to get it properly filled with fext fields
supplicant = f"""\
country={country.get()}
update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={{
ssid="{ssid.get()}"
psk="{password.get()}"
}}
"""
return supplicant
def write_file(lines, filename):
with open(filename, "w+") as f:
f.writelines(lines) if type(list) == list else f.write(lines) # Compatible with \n formated array or multiline f-string
createdLabel = Label(root, text=f'{filename} created')
createdLabel.grid(columnspan=2, sticky=N+S, pady=6)
def write_files():
# call the write function for all files
write_file(getSupplicant(), "wpa_supplicant.conf")
write_file('', "SSH") if (ssh_state.get()) else None # Create SSH file if checkbox enabled
root.mainloop()