forked from szafranski/RH-ota
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnet_hotspot_manual_11.py
executable file
·247 lines (181 loc) · 8.15 KB
/
net_hotspot_manual_11.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import os
from modules import clear_the_screen, Bcolors, rhim_load_config
# Set the Wi-Fi country in raspi-config's Localisation Options:
# sudo raspi-config
# ( 4. point -> I4 - Change WiFi country -> select -> enter -> finish )
def step_four():
while True:
print("""Step 4.
Connect PC to WiFi network:
name: RH-TIMER
password: timerpass
if you have any problems connecting wifi with new name,
try "forgetting" the (old) network in PC's WiFi settings
and than try again
Now you should be able to enter the timer typing in the browser:
10.10.10.10 (or: 10.10.10.10:5000) - using WiFi
172.20.20.20 (or: 172.20.20.20:5000) - using ethernet.
{green}Reboot by pressing 'r'{endc}
{yellow}Exit by pressing 'e'{endc}
""".format(yellow=Bcolors.YELLOW_S, green=Bcolors.GREEN_S, endc=Bcolors.ENDC))
selection = input()
if selection == 'r':
os.system("sudo reboot")
elif selection == 'e':
break
else:
main()
def step_three():
while True:
os.system("sudo cp /etc/dhcpcd.conf.ap /etc/dhcpcd.conf")
os.system("sudo cp /etc/dnsmasq.conf.ap /etc/dnsmasq.conf")
print("""
{bold}Step 3.{endc}
After rebooting you can connect to the timer, via Wifi or ethernet.
WiFi: 10.10.10.10 (or: 10.10.10.10:5000)
ethernet: 172.20.20.20 (172.20.20.20:5000)
You can enter Access Point extra menu after rebooting
and check how you can connect to the internet.
{green}r - Reboot by pressing{endc}
{yellow}e - Exit by pressing{endc}
""".format(bold=Bcolors.BOLD, yellow=Bcolors.YELLOW_S, green=Bcolors.GREEN_S, endc=Bcolors.ENDC))
selection = input()
if selection == 'r':
os.system("sudo reboot")
elif selection == 'e':
break
else:
main()
def step_zero(config):
def step_one(config):
while True:
after_installing_raspap = """
{bold}Step 2.{endc}
Next step requires performing some actions in GUI.
You may write those information down or take a picture etc.
You can also print file 'step_two.txt' from 'net_ap' folder.
Remember to do it BEFORE rebooting.
After performing step 2. and connecting to timer again,
come back to this menu and enter step 3.
connect PC to WiFi network:
name: raspi-webgui
password: ChangeMe
enter IP address: 10.3.141.1 (or: 10.3.141.1:8080) in the browser
Username: admin
Password: secret
Click:
"Hotspot" (left menu) -> SSID (enter name you want, eg. "RH-TIMER")
Wireless Mode (change to 802.11n - 2.4GHz)
save settings
Click:
"Security" tab
PSK (enter password that you want to have, eg. "timerpass")
save settings
DON'T CHANGE ANY OTHER SETTINGS IN GUI!
Click:
"System" (left menu) and "Reboot"
reboot and connect to newly-created WiFi network using new password
{red} -- Read carefully whole instruction from above before rebooting --{endc}
{green}r - Reboot by pressing{endc}
{yellow}e - Exit by pressing{endc}
""".format(bold=Bcolors.BOLD, red=Bcolors.RED, endc=Bcolors.ENDC,
yellow=Bcolors.YELLOW_S, green=Bcolors.GREEN_S)
os.system(f"./scripts/hotspot_manual.sh {config.user}")
os.system("curl -sL https://install.raspap.com | bash -s -- -y")
print(after_installing_raspap)
selection = input()
if selection == 'r':
os.system("sudo reboot")
elif selection == 'e':
break
while True:
clear_the_screen()
print("""
After performing this process your Raspberry Pi can be used as standalone
Access Point. You won't need additional router for connecting with it.
You won't be able to connect to any router or hotspot wirelessly.
You will still have ability to connect it to the Internet sharing device,
like router or PC via ethernet cable. You will also be able to connect with
the timer via Wifi from PC or mobile phone etc. - if you had range.
If during this process you would want to check detailed instructions,
you can enter 'net_ap' folder from this repo, on your mobile phone etc.
This process will require few reboots. Do you want to continue?
{green}y - Yes, let's do it{endc}
3 - Enter "Step 3." - check it after first two steps
x - Enter Access Point extra menu - check it after operation
{yellow}e - Exit to main menu{endc}
""".format(yellow=Bcolors.YELLOW_S, green=Bcolors.GREEN_S, endc=Bcolors.ENDC))
selection = input()
if selection == 'y':
step_one(config)
elif selection == '3':
step_three()
elif selection == 'x':
ap_menu()
elif selection == 'e':
break
else:
main()
def ap_menu():
def second_page():
while True:
clear_the_screen()
print("""
When Raspberry configuration has been changed so it performs
as Access Point or as a DHCP client (normal mode),
configuration file is being copied with a proper name.
Next you have to reboot, so changes can be applied.
When you setup Pi as a client, you can just connect
it to the router. If you are using PC as a internet sharing
device, you have to enable that option in OS settings.
Instructions for Windows can be found in net_ap folder.
If you want to connect to Raspberry via SSH or VNC,
when it's in client mode you have to know its IP address.
Check it in router settings page or using special program
'Advanced IP Scanner' on a PC. If you are using Pi as a AP,
its IP is always 172.20.20.20 (ethernet). Remember to disable
internet sharing functionality on your PC's OS, when Raspberry
is in Access Point mode.
Remember that you can always connect to the timer (eg. from yet
another device) via WiFi. It's wireless IP is 10.10.10.10.
You can also read/print those instructions. File 'detailed.txt',
in net_ap folder.
{green}k - OK{endc}
""".format(yellow=Bcolors.YELLOW_S, green=Bcolors.GREEN_S, endc=Bcolors.ENDC))
selection = input()
if selection == 'k':
break
def first_page():
while True:
clear_the_screen()
print("""\n
Right now you have your Access Point configured. However,
there is still an option to maintain internet connection.
You will be able to connect the Pi via ethernet to the router
or PC - with internet sharing option enabled. It requires changes
in configuration file. Those will be performed automatically,
after entering '{green}netcfg{endc}' or '{green}apcfg{endc}' in command line.
Remember to reboot the timer after every change. Instruction
can be also found in 'apconf.txt' file in net_ap folder.
Remember that regardless how you have your Raspberry configured
in a given moment, you can always connect to it using WiFi.
It can be helpful if you don't remember how your timer was configured
when you left it or when some troubleshooting is required.
Open second page, for detailed explanation.
{green_s}s - Second page{endc}
{yellow}e - Exit to menu{endc}
""".format(yellow=Bcolors.YELLOW_S, green_s=Bcolors.GREEN_S, green=Bcolors.GREEN,
endc=Bcolors.ENDC))
selection = input()
if selection == 's':
second_page()
elif selection == 'e':
break
first_page()
def net_hotspot_manual_11(config):
step_zero(config)
def main():
config = rhim_load_config()
net_hotspot_manual_11(config)
if __name__ == "__main__":
main()