|
@@ -0,0 +1,310 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# Used to enable or disable BMX7 mesh protocol on wlanX
|
|
12
|
+#
|
|
13
|
+# License
|
|
14
|
+# =======
|
|
15
|
+#
|
|
16
|
+# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
|
|
17
|
+#
|
|
18
|
+# This program is free software: you can redistribute it and/or modify
|
|
19
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
20
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
21
|
+# (at your option) any later version.
|
|
22
|
+#
|
|
23
|
+# This program is distributed in the hope that it will be useful,
|
|
24
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
+# GNU Affero General Public License for more details.
|
|
27
|
+#
|
|
28
|
+# You should have received a copy of the GNU Affero General Public License
|
|
29
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
+
|
|
31
|
+PROJECT_NAME='freedombone'
|
|
32
|
+COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
|
|
33
|
+
|
|
34
|
+# hotspot passphrase must be 5 characters or longer
|
|
35
|
+HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
|
|
36
|
+
|
|
37
|
+source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
|
|
38
|
+source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
|
|
39
|
+
|
|
40
|
+mesh_protocol_init
|
|
41
|
+update_wifi_adaptors
|
|
42
|
+
|
|
43
|
+if [ ! $IFACE ]; then
|
|
44
|
+ echo $'No wlan adaptor'
|
|
45
|
+ exit 0
|
|
46
|
+fi
|
|
47
|
+
|
|
48
|
+function status {
|
|
49
|
+ bmx7 -c status
|
|
50
|
+}
|
|
51
|
+
|
|
52
|
+function stop {
|
|
53
|
+ if [ -z "$IFACE" ]; then
|
|
54
|
+ echo 'error: unable to find wifi interface, not enabling BMX7 mesh'
|
|
55
|
+ return
|
|
56
|
+ fi
|
|
57
|
+
|
|
58
|
+ systemctl stop dnsmasq
|
|
59
|
+ systemctl disable dnsmasq
|
|
60
|
+ systemctl stop bmx7
|
|
61
|
+ systemctl disable bmx7
|
|
62
|
+
|
|
63
|
+ if [ "$EIFACE" ]; then
|
|
64
|
+ ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
|
|
65
|
+ if [[ "$ethernet_connected" != "0" ]]; then
|
|
66
|
+ systemctl stop hostapd
|
|
67
|
+ ifconfig $EIFACE down -promisc
|
|
68
|
+ fi
|
|
69
|
+ fi
|
|
70
|
+
|
|
71
|
+ avahi-autoipd -k $BRIDGE
|
|
72
|
+ avahi-autoipd -k $IFACE
|
|
73
|
+ ifconfig $IFACE down -promisc
|
|
74
|
+
|
|
75
|
+ ifconfig $IFACE mtu 1500
|
|
76
|
+ ifconfig $IFACE down
|
|
77
|
+ iwconfig $IFACE mode managed
|
|
78
|
+
|
|
79
|
+ if [ $IFACE_SECONDARY ]; then
|
|
80
|
+ systemctl stop hostapd
|
|
81
|
+ systemctl disable hostapd
|
|
82
|
+ ifconfig $IFACE_SECONDARY mtu 1500
|
|
83
|
+ ifconfig $IFACE_SECONDARY down
|
|
84
|
+ iwconfig $IFACE_SECONDARY mode managed
|
|
85
|
+ fi
|
|
86
|
+
|
|
87
|
+ disable_mesh_firewall
|
|
88
|
+
|
|
89
|
+ systemctl restart network-manager
|
|
90
|
+
|
|
91
|
+ if [ -f $MESH_CURRENT_PROTOCOL ]; then
|
|
92
|
+ rm $MESH_CURRENT_PROTOCOL
|
|
93
|
+ fi
|
|
94
|
+}
|
|
95
|
+
|
|
96
|
+function verify {
|
|
97
|
+ # TODO
|
|
98
|
+ echo -n ''
|
|
99
|
+}
|
|
100
|
+
|
|
101
|
+function add_wifi_interface {
|
|
102
|
+ ifname=$1
|
|
103
|
+ ifssid=$WIFI_SSID
|
|
104
|
+ if [ $2 ]; then
|
|
105
|
+ ifssid=$2
|
|
106
|
+ fi
|
|
107
|
+ ifmode=ad-hoc
|
|
108
|
+ if [ $3 ]; then
|
|
109
|
+ ifmode=$3
|
|
110
|
+ fi
|
|
111
|
+ ifchannel=$CHANNEL
|
|
112
|
+ if [ $4 ]; then
|
|
113
|
+ ifchannel=$4
|
|
114
|
+ fi
|
|
115
|
+
|
|
116
|
+ ifconfig $ifname down
|
|
117
|
+ ifconfig $ifname mtu 1500
|
|
118
|
+ peermac=$(assign_peer_address)
|
|
119
|
+ if [ ! $peermac ]; then
|
|
120
|
+ echo $"Unable to obtain MAC address for $peermac on $ifname"
|
|
121
|
+ return
|
|
122
|
+ fi
|
|
123
|
+ ifconfig $ifname hw ether $peermac
|
|
124
|
+ echo $"$ifname assigned MAC address $peermac"
|
|
125
|
+ iwconfig $ifname enc off
|
|
126
|
+ iwconfig $ifname mode $ifmode essid $ifssid channel $ifchannel
|
|
127
|
+
|
|
128
|
+ ifconfig $ifname up
|
|
129
|
+}
|
|
130
|
+
|
|
131
|
+function start {
|
|
132
|
+ update_wifi_adaptors
|
|
133
|
+
|
|
134
|
+ if [ -z "$IFACE" ] ; then
|
|
135
|
+ echo 'error: unable to find wifi interface, not enabling BMX7 mesh'
|
|
136
|
+ exit 723657
|
|
137
|
+ fi
|
|
138
|
+ echo "info: enabling BMX7 mesh network $WIFI_SSID on $IFACE"
|
|
139
|
+
|
|
140
|
+ mesh_protocol_stop
|
|
141
|
+
|
|
142
|
+ systemctl stop network-manager
|
|
143
|
+ sleep 5
|
|
144
|
+
|
|
145
|
+ systemctl stop dnsmasq
|
|
146
|
+ systemctl disable dnsmasq
|
|
147
|
+
|
|
148
|
+ # remove an avahi service which isn't used
|
|
149
|
+ if [ -f /etc/avahi/services/udisks.service ]; then
|
|
150
|
+ sudo rm /etc/avahi/services/udisks.service
|
|
151
|
+ fi
|
|
152
|
+
|
|
153
|
+ global_rate_limit
|
|
154
|
+
|
|
155
|
+ # Might have to re-enable wifi
|
|
156
|
+ rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
|
|
157
|
+
|
|
158
|
+ secondary_wifi_available=
|
|
159
|
+ if [ $IFACE_SECONDARY ]; then
|
|
160
|
+ if [[ $IFACE != $IFACE_SECONDARY ]]; then
|
|
161
|
+ if [ -d /etc/hostapd ]; then
|
|
162
|
+ if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
|
|
163
|
+ secondary_wifi_available=1
|
|
164
|
+ else
|
|
165
|
+ echo $'Hotspot passphrase is too short'
|
|
166
|
+ fi
|
|
167
|
+ fi
|
|
168
|
+ fi
|
|
169
|
+ fi
|
|
170
|
+
|
|
171
|
+ add_wifi_interface $IFACE $WIFI_SSID ad-hoc $CHANNEL
|
|
172
|
+ ifconfig $IFACE up promisc
|
|
173
|
+
|
|
174
|
+ if [ ! $secondary_wifi_available ]; then
|
|
175
|
+ sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE}|g" /etc/systemd/system/bmx7.service
|
|
176
|
+ else
|
|
177
|
+ sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
|
|
178
|
+ fi
|
|
179
|
+
|
|
180
|
+ systemctl daemon-reload
|
|
181
|
+ systemctl enable bmx7
|
|
182
|
+ systemctl start bmx7
|
|
183
|
+
|
|
184
|
+ avahi-autoipd --force-bind --daemonize --wait $IFACE
|
|
185
|
+
|
|
186
|
+ # NOTE: Don't connect the secondary wifi device. hostapd will handle that by itself
|
|
187
|
+
|
|
188
|
+ ethernet_connected='0'
|
|
189
|
+ if [ "$EIFACE" ] ; then
|
|
190
|
+ ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
|
|
191
|
+ if [[ "$ethernet_connected" != "0" ]]; then
|
|
192
|
+ echo $'Trying ethernet bridge to the internet'
|
|
193
|
+ ifconfig $EIFACE up promisc
|
|
194
|
+ echo $'End of ethernet bridge'
|
|
195
|
+ else
|
|
196
|
+ echo $"$EIFACE is not connected"
|
|
197
|
+ fi
|
|
198
|
+ fi
|
|
199
|
+
|
|
200
|
+ enable_mesh_seconary_wifi
|
|
201
|
+
|
|
202
|
+ enable_mesh_firewall
|
|
203
|
+
|
|
204
|
+ systemctl restart avahi-daemon
|
|
205
|
+
|
|
206
|
+ enable_mesh_scuttlebot
|
|
207
|
+ enable_mesh_tor
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+ sed -i "s|server_name .*|server_name ${HOSTNAME}.local;|g" /etc/nginx/sites-available/git_ssb
|
|
211
|
+
|
|
212
|
+ systemctl restart nginx
|
|
213
|
+
|
|
214
|
+ verify
|
|
215
|
+
|
|
216
|
+ echo "bmx7" > $MESH_CURRENT_PROTOCOL
|
|
217
|
+}
|
|
218
|
+
|
|
219
|
+function monitor {
|
|
220
|
+ if [ -z "$IFACE" ] ; then
|
|
221
|
+ echo 'error: unable to find wifi interface, not enabling BMX7 mesh'
|
|
222
|
+ exit 723657
|
|
223
|
+ fi
|
|
224
|
+
|
|
225
|
+ clear
|
|
226
|
+ echo ''
|
|
227
|
+ echo $'*** Stopping network ***'
|
|
228
|
+ echo ''
|
|
229
|
+
|
|
230
|
+ stop
|
|
231
|
+
|
|
232
|
+ echo "info: monitoring mesh network $WIFI_SSID on $IFACE"
|
|
233
|
+
|
|
234
|
+ systemctl stop network-manager
|
|
235
|
+ sleep 5
|
|
236
|
+
|
|
237
|
+ clear
|
|
238
|
+ echo ''
|
|
239
|
+ echo $'*** Setting firewall rate limit ***'
|
|
240
|
+ echo ''
|
|
241
|
+
|
|
242
|
+ global_rate_limit
|
|
243
|
+
|
|
244
|
+ clear
|
|
245
|
+ echo ''
|
|
246
|
+ echo $'*** Enabling wifi adaptor in monitor mode ***'
|
|
247
|
+ echo ''
|
|
248
|
+
|
|
249
|
+ # Might have to re-enable wifi
|
|
250
|
+ rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
|
|
251
|
+
|
|
252
|
+ ifconfig $IFACE down
|
|
253
|
+ ifconfig $IFACE mtu 1500
|
|
254
|
+ ifconfig $IFACE hw ether $(assign_peer_address)
|
|
255
|
+ iwconfig $IFACE enc off
|
|
256
|
+ iwconfig $IFACE mode monitor channel $CHANNEL
|
|
257
|
+ sleep 1
|
|
258
|
+ iwconfig $IFACE ap $CELLID
|
|
259
|
+
|
|
260
|
+ ifconfig $IFACE up
|
|
261
|
+
|
|
262
|
+ horst -i $IFACE
|
|
263
|
+
|
|
264
|
+ clear
|
|
265
|
+ echo ''
|
|
266
|
+ echo $'*** Restarting the network daemon. This may take a while. ***'
|
|
267
|
+ echo ''
|
|
268
|
+
|
|
269
|
+ start
|
|
270
|
+}
|
|
271
|
+
|
|
272
|
+if ! grep -q "$IFACE" /proc/net/dev; then
|
|
273
|
+ echo 'Interface $IFACE was not found'
|
|
274
|
+ stop
|
|
275
|
+ exit 1
|
|
276
|
+fi
|
|
277
|
+
|
|
278
|
+case "$1" in
|
|
279
|
+ start|stop|status|monitor)
|
|
280
|
+ $1
|
|
281
|
+ ;;
|
|
282
|
+ restart)
|
|
283
|
+ clear
|
|
284
|
+ echo ''
|
|
285
|
+ echo $'*** Stopping BMX7 mesh network connection ***'
|
|
286
|
+ echo ''
|
|
287
|
+ stop
|
|
288
|
+ sleep 10
|
|
289
|
+ clear
|
|
290
|
+ echo ''
|
|
291
|
+ echo $'*** Starting BMX7 mesh network connection ***'
|
|
292
|
+ echo ''
|
|
293
|
+ start
|
|
294
|
+ ;;
|
|
295
|
+ ping)
|
|
296
|
+ ping $2
|
|
297
|
+ ;;
|
|
298
|
+ data)
|
|
299
|
+ bmx7 -lc traffic=$IFACE
|
|
300
|
+ ;;
|
|
301
|
+ ls|list)
|
|
302
|
+ avahi-browse -atl
|
|
303
|
+ ;;
|
|
304
|
+ *)
|
|
305
|
+ echo "error: invalid parameter $1"
|
|
306
|
+ echo 'usage: $0 {start|stop|restart|status|ping|ls|list}'
|
|
307
|
+ exit 2
|
|
308
|
+ ;;
|
|
309
|
+esac
|
|
310
|
+exit 0
|