Pārlūkot izejas kodu

Experimental bmx6 on mesh

Bob Mottram 7 gadus atpakaļ
vecāks
revīzija
e3627b666f

+ 2
- 0
Makefile Parādīt failu

@@ -28,6 +28,7 @@ install:
28 28
 	cp img/avatars/* ${DESTDIR}/usr/share/${APP}/avatars
29 29
 	cp src/* ${DESTDIR}${PREFIX}/bin
30 30
 	cp src/${APP}-mesh-batman ${DESTDIR}${PREFIX}/bin/batman
31
+	cp src/${APP}-mesh-bmx6 ${DESTDIR}${PREFIX}/bin/bmx
31 32
 	cp src/${APP}-backup-local ${DESTDIR}${PREFIX}/bin/backup
32 33
 	cp src/${APP}-backup-local ${DESTDIR}${PREFIX}/bin/backup2friends
33 34
 	cp src/${APP}-restore-local ${DESTDIR}${PREFIX}/bin/restore
@@ -60,6 +61,7 @@ uninstall:
60 61
 	rm -f ${PREFIX}/bin/restore
61 62
 	rm -f ${PREFIX}/bin/restorefromfriend
62 63
 	rm -f ${PREFIX}/bin/batman
64
+	rm -f ${PREFIX}/bin/bmx
63 65
 	rm -rf /etc/${APP}
64 66
 	rm -f ${PREFIX}/bin/control
65 67
 	rm -f ${PREFIX}/bin/controluser

+ 63
- 0
src/freedombone-image-customise Parādīt failu

@@ -13,6 +13,8 @@
13 13
 # License
14 14
 # =======
15 15
 #
16
+# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
17
+#
16 18
 # This program is free software: you can redistribute it and/or modify
17 19
 # it under the terms of the GNU Affero General Public License as published by
18 20
 # the Free Software Foundation, either version 3 of the License, or
@@ -123,6 +125,9 @@ ENABLE_ZERONET=
123 125
 
124 126
 MESH_TEXT_EDITOR='pluma'
125 127
 
128
+BMX6_REPO="https://github.com/bashrc/bmx6"
129
+BMX6_COMMIT='20db4cf5abc129b8d4d2a341bb9265a92e7c3d50'
130
+
126 131
 PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
127 132
 
128 133
 function configure_backports {
@@ -653,6 +658,63 @@ mesh_shutdown_script() {
653 658
     chroot "$rootdir" systemctl enable meshshutdown
654 659
 }
655 660
 
661
+install_bmx6() {
662
+    git clone $BMX6_REPO $rootdir/etc/bmx6
663
+
664
+    cat <<EOF > $rootdir/usr/bin/install_bmx6
665
+#!/bin/bash
666
+cd /etc/bmx6
667
+git checkout $BMX6_COMMIT -b $BMX6_COMMIT
668
+make
669
+make install
670
+
671
+cd /etc/bmx6/lib/bmx6_http_info
672
+make
673
+make install
674
+
675
+cd /etc/bmx6/lib/bmx6_json
676
+make
677
+make install
678
+
679
+cd /etc/bmx6/lib/bmx6_quagga
680
+make
681
+make install
682
+
683
+cd /etc/bmx6/lib/bmx6_sms
684
+make
685
+make install
686
+
687
+cd /etc/bmx6/lib/bmx6_table
688
+make
689
+make install
690
+
691
+cd /etc/bmx6/lib/bmx6_topology
692
+make
693
+make install
694
+EOF
695
+    chroot "$rootdir" chmod +x /usr/bin/install_bmx6
696
+    chroot "$rootdir" /usr/bin/install_bmx6
697
+
698
+    if [ ! -f $rootdir/usr/sbin/bmx6 ]; then
699
+        echo $'bmx6 was not installed'
700
+        exit 79835292
701
+    fi
702
+
703
+    echo '[Unit]' > $rootdir/etc/systemd/system/bmx6.service
704
+    echo 'Description=BMX6 mesh routing protocol' >> $rootdir/etc/systemd/system/bmx6.service
705
+    echo 'Requires=network.target' >> $rootdir/etc/systemd/system/bmx6.service
706
+    echo 'After=network.target' >> $rootdir/etc/systemd/system/bmx6.service
707
+    echo '' >> $rootdir/etc/systemd/system/bmx6.service
708
+    echo '[Service]' >> $rootdir/etc/systemd/system/bmx6.service
709
+    echo 'User=root' >> $rootdir/etc/systemd/system/bmx6.service
710
+    echo 'Group=root' >> $rootdir/etc/systemd/system/bmx6.service
711
+    echo 'ExecStart=/usr/sbin/bmx6 dev=wlan0' >> $rootdir/etc/systemd/system/bmx6.service
712
+    echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/bmx6.service
713
+    echo '' >> $rootdir/etc/systemd/system/bmx6.service
714
+    echo '[Install]' >> $rootdir/etc/systemd/system/bmx6.service
715
+    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/bmx6.service
716
+}
717
+
656 718
 initialise_mesh() {
657 719
     if [[ $VARIANT != "mesh"* ]]; then
658 720
         return
@@ -692,6 +754,7 @@ initialise_mesh() {
692 754
     configure_firewall
693 755
     install_avahi
694 756
     install_batman
757
+    install_bmx6
695 758
     mesh_shutdown_script
696 759
     install_vpn
697 760
     install_tomb

+ 4
- 0
src/freedombone-image-mesh Parādīt failu

@@ -1415,6 +1415,10 @@ if [ -f $MESH_INSTALL_SETUP ]; then
1415 1415
     systemctl disable tor
1416 1416
     echo $'TOR disabled' >> $INSTALL_LOG
1417 1417
 
1418
+    systemctl stop bmx6
1419
+    systemctl disable bmx6
1420
+    echo $'BMX6 disabled' >> $INSTALL_LOG
1421
+
1418 1422
     #tomb slam all
1419 1423
     tmp_ram_disk 100
1420 1424
     enable_predictable_device_names

+ 9
- 298
src/freedombone-mesh-batman Parādīt failu

@@ -35,57 +35,7 @@ COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
35 35
 HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
36 36
 
37 37
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
38
-
39
-if [[ $1 == "start" ]]; then
40
-    # install avahi
41
-    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
42
-    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
43
-    sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf
44
-    sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf
45
-    sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf
46
-    sed -i "s|hosts:.*|hosts:          files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
47
-fi
48
-
49
-# Mesh definition
50
-WIFI_SSID='mesh'
51
-if [ -f $COMPLETION_FILE ]; then
52
-    if grep -q "WIFI_SSID:" $COMPLETION_FILE; then
53
-        WIFI_SSID=$(cat $COMPLETION_FILE | grep "WIFI_SSID:" | awk -F ':' '{print $2}')
54
-    fi
55
-    sed -i "s|WIFI_SSID:.*|WIFI_SSID:${WIFI_SSID}|g" $COMPLETION_FILE
56
-fi
57
-CELLID='any'
58
-
59
-CHANNEL=2
60
-HOTSPOT_CHANNEL=6
61
-if [ -f $COMPLETION_FILE ]; then
62
-    if grep -q "Wifi channel:" $COMPLETION_FILE; then
63
-        CHANNEL=$(cat $COMPLETION_FILE | grep "Wifi channel:" | awk -F ':' '{print $2}')
64
-    fi
65
-    sed -i "s|Wifi channel:.*|Wifi channel:${CHANNEL}|g" $COMPLETION_FILE
66
-fi
67
-
68
-ZERONET_PORT=15441
69
-IPFS_PORT=4001
70
-TOX_PORT=33445
71
-TRACKER_PORT=6969
72
-LIBREVAULT_PORT=42345
73
-TAHOELAFS_PORT=50213
74
-GIT_SSB_PORT=7718
75
-NGINX_GIT_SSB_PORT=7719
76
-
77
-# Ethernet bridge definition (bridged to bat0)
78
-BRIDGE=br-mesh
79
-BRIDGE_HOTSPOT=br-hotspot
80
-IFACE=
81
-IFACE_SECONDARY=
82
-EIFACE=eth0
83
-WLAN_ADAPTORS=$(count_wlan)
84
-
85
-if [ $WLAN_ADAPTORS -eq 0 ]; then
86
-    echo $'No wlan adaptors found'
87
-    exit 0
88
-fi
38
+source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
89 39
 
90 40
 update_wifi_adaptors
91 41
 
@@ -98,23 +48,6 @@ if [ -e /etc/default/batctl ]; then
98 48
     . /etc/default/batctl
99 49
 fi
100 50
 
101
-function get_ipv4_wlan {
102
-    echo $(ip -o -f inet addr show dev "$IFACE" | awk '{print $4}' | awk 'END {print}' | awk -F '/' '{print $1}')
103
-}
104
-
105
-function mesh_hotspot_ip_address {
106
-    echo $(ip -o -f inet addr show dev "${BRIDGE}" | awk '{print $4}' | awk 'END {print}' | awk -F '/' '{print $1}')
107
-}
108
-
109
-function global_rate_limit {
110
-    if ! grep -q "tcp_challenge_ack_limit" /etc/sysctl.conf; then
111
-        echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> /etc/sysctl.conf
112
-    else
113
-        sed -i 's|net.ipv4.tcp_challenge_ack_limit.*|net.ipv4.tcp_challenge_ack_limit = 999999999|g' /etc/sysctl.conf
114
-    fi
115
-    sysctl -p -q
116
-}
117
-
118 51
 function status {
119 52
     batctl o
120 53
 }
@@ -160,44 +93,7 @@ function stop {
160 93
 
161 94
     rmmod batman-adv
162 95
 
163
-    iptables -D INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT
164
-    iptables -D INPUT -p udp --dport $TRACKER_PORT -j ACCEPT
165
-    iptables -D INPUT -p tcp --dport 80 -j ACCEPT
166
-    iptables -D INPUT -p udp --dport 80 -j ACCEPT
167
-    iptables -D INPUT -p tcp --dport 548 -j ACCEPT
168
-    iptables -D INPUT -p udp --dport 548 -j ACCEPT
169
-    iptables -D INPUT -p tcp --dport 5353 -j ACCEPT
170
-    iptables -D INPUT -p udp --dport 5353 -j ACCEPT
171
-    iptables -D INPUT -p tcp --dport 5354 -j ACCEPT
172
-    iptables -D INPUT -p udp --dport 5354 -j ACCEPT
173
-    iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
174
-    iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
175
-    iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
176
-    iptables -D INPUT -p udp --dport $IPFS_PORT -j ACCEPT
177
-    iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
178
-    iptables -D INPUT -p udp --dport $TOX_PORT -j ACCEPT
179
-    iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
180
-    iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
181
-    iptables -D INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
182
-    # SSB/Scuttlebot/Patchwork
183
-    iptables -D INPUT -p tcp --dport $GIT_SSB_PORT -j ACCEPT
184
-    iptables -D INPUT -p udp --dport 8008 -j ACCEPT
185
-    iptables -D INPUT -p tcp --dport 8008 -j ACCEPT
186
-    iptables -D INPUT -p udp --dport 8010 -j ACCEPT
187
-    iptables -D INPUT -p tcp --dport 8010 -j ACCEPT
188
-    # vpn over the internet
189
-    iptables -D INPUT -p tcp --dport 653 -j ACCEPT
190
-    iptables -D INPUT -p udp --dport 653 -j ACCEPT
191
-    iptables -D INPUT -i ${EIFACE} -m state --state NEW -p tcp --dport 1194 -j ACCEPT
192
-    iptables -D INPUT -i tun+ -j ACCEPT
193
-    iptables -D FORWARD -i tun+ -j ACCEPT
194
-    iptables -D FORWARD -i tun+ -o ${EIFACE} -m state --state RELATED,ESTABLISHED -j ACCEPT
195
-    iptables -D FORWARD -i ${EIFACE} -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
196
-    iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o ${EIFACE} -j MASQUERADE
197
-    iptables -D OUTPUT -o tun+ -j ACCEPT
198
-
199
-    echo 0 > /proc/sys/net/ipv4/ip_forward
200
-    sed -i 's|net.ipv4.ip_forward=.*|net.ipv4.ip_forward=0|g' /etc/sysctl.conf
96
+    disable_mesh_firewall
201 97
 
202 98
     systemctl restart network-manager
203 99
 }
@@ -215,21 +111,6 @@ function verify {
215 111
     rm $tempfile
216 112
 }
217 113
 
218
-function assign_peer_address {
219
-    for i in {1..6}; do
220
-        number=$RANDOM
221
-        let "number %= 255"
222
-        octet=$(echo "obase=16;$number" | bc)
223
-        if [ ${#octet} -lt 2 ]; then
224
-            octet="0${octet}"
225
-        fi
226
-        if [ $i -gt 1 ]; then
227
-            echo -n ":"
228
-        fi
229
-        echo -n "${octet}"
230
-    done
231
-}
232
-
233 114
 function add_wifi_interface {
234 115
     ifname=$1
235 116
     ifssid=$WIFI_SSID
@@ -261,53 +142,6 @@ function add_wifi_interface {
261 142
     ifconfig $ifname up
262 143
 }
263 144
 
264
-function mesh_create_app_downloads_page {
265
-    if [ ! -d /root/$PROJECT_NAME/image_build/mesh_apps ]; then
266
-        return
267
-    fi
268
-    if [ ! -d /var/www/html ]; then
269
-        return
270
-    fi
271
-    # Don't go straight to cryptpad when navigating to the peer's IP address
272
-    if [ -L /etc/nginx/sites-enabled/cryptpad ]; then
273
-        rm /etc/nginx/sites-enabled/cryptpad
274
-        ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
275
-        if [ -d /etc/cryptpad ]; then
276
-            systemctl stop cryptpad
277
-            systemctl disable cryptpad
278
-        fi
279
-        systemctl restart nginx
280
-    fi
281
-    # Don't show the cryptpad icon on the desktop
282
-    if [ -f /home/fbone/Desktop/cryptpad.desktop ]; then
283
-        mv /home/fbone/Desktop/cryptpad.desktop /home/fbone/.cryptpad.desktop
284
-    fi
285
-
286
-    cp /root/$PROJECT_NAME/website/EN/meshindex.html /var/www/html/index.html
287
-    if [ ! -f /var/www/html/ssb.apk ]; then
288
-        cp /root/$PROJECT_NAME/image_build/mesh_apps/ssb.apk /var/www/html/ssb.apk
289
-    fi
290
-    if [ ! -f /var/www/html/trifa.apk ]; then
291
-        cp /root/$PROJECT_NAME/image_build/mesh_apps/trifa.apk /var/www/html/trifa.apk
292
-    fi
293
-    if [ ! -d /var/www/html/images ]; then
294
-        mkdir /var/www/html/images
295
-    fi
296
-    if [ ! -f /var/www/html/images/logo.png ]; then
297
-        cp /root/$PROJECT_NAME/img/logo.png /var/www/html/images/logo.png
298
-    fi
299
-    if [ ! -f /var/www/html/images/ssb.png ]; then
300
-        cp /root/$PROJECT_NAME/img/icon_patchwork.png /var/www/html/images/ssb.png
301
-    fi
302
-    if [ ! -f /var/www/html/images/trifa.png ]; then
303
-        cp /root/$PROJECT_NAME/img/trifa.png /var/www/html/images/trifa.png
304
-    fi
305
-    if [ ! -f /var/www/html/freedombone.css ]; then
306
-        cp /root/$PROJECT_NAME/website/freedombone.css /var/www/html/freedombone.css
307
-    fi
308
-    chown -R www-data:www-data /var/www/html/*
309
-}
310
-
311 145
 function start {
312 146
     update_wifi_adaptors
313 147
 
@@ -320,6 +154,8 @@ function start {
320 154
     systemctl stop network-manager
321 155
     sleep 5
322 156
 
157
+    systemctl stop bmx6
158
+    systemctl disable bmx6
323 159
     systemctl stop dnsmasq
324 160
     systemctl disable dnsmasq
325 161
 
@@ -374,142 +210,17 @@ function start {
374 210
     ifconfig $BRIDGE up
375 211
     dhclient $BRIDGE
376 212
 
377
-    if [ $secondary_wifi_available ]; then
378
-        sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
379
-
380
-        mesh_hotspot_address=$(mesh_hotspot_ip_address)
381
-        if [[ "$mesh_hotspot_address" == *'.'* ]]; then
382
-            echo "interface=${IFACE_SECONDARY}" > /etc/hostapd/hostapd.conf
383
-            echo "bridge=${BRIDGE}" >> /etc/hostapd/hostapd.conf
384
-            echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
385
-            echo "country_code=UK" >> /etc/hostapd/hostapd.conf
386
-            echo "ssid=${WIFI_SSID}-${mesh_hotspot_address}" >> /etc/hostapd/hostapd.conf
387
-            echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
388
-            echo "channel=${HOTSPOT_CHANNEL}" >> /etc/hostapd/hostapd.conf
389
-            echo 'wpa=2' >> /etc/hostapd/hostapd.conf
390
-            echo "wpa_passphrase=$HOTSPOT_PASSPHRASE" >> /etc/hostapd/hostapd.conf
391
-            echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
392
-            echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
393
-            echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
394
-            echo 'auth_algs=1' >> /etc/hostapd/hostapd.conf
395
-            echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
396
-
397
-            sed -i "s|#interface=.*|interface=${IFACE_SECONDARY}|g" /etc/dnsmasq.conf
398
-            sed -i "s|interface=.*|interface=${IFACE_SECONDARY}|g" /etc/dnsmasq.conf
399
-            sed -i "s|listen-address=.*|listen-address=127.0.0.1,$mesh_hotspot_address|g" /etc/dnsmasq.conf
400
-            sed -i 's|#listen-address|listen-address|g' /etc/dnsmasq.conf
401
-            systemctl enable dnsmasq
402
-            systemctl restart dnsmasq
403
-
404
-            systemctl enable hostapd
405
-            systemctl restart hostapd
406
-            mesh_create_app_downloads_page
407
-        else
408
-            secondary_wifi_available=
409
-            echo $'WARNING: No IP address could be obtained for the hotspot'
410
-        fi
411
-    fi
412
-
413
-    if [ ! $secondary_wifi_available ]; then
414
-        systemctl stop hostapd
415
-        systemctl disable hostapd
416
-
417
-        # Recreate the cryptpad symlink
418
-        if [ -f /etc/nginx/sites-available/cryptpad ]; then
419
-            if [ -L /etc/nginx/sites-enabled/cryptpad ]; then
420
-                rm /etc/nginx/sites-enabled/default
421
-            fi
422
-            systemctl enable cryptpad
423
-            systemctl start cryptpad
424
-
425
-            if [ ! -L /etc/nginx/sites-enabled/cryptpad ]; then
426
-                ln -s /etc/nginx/sites-available/cryptpad /etc/nginx/sites-enabled/cryptpad
427
-                systemctl restart nginx
428
-            fi
429
-        fi
430
-        if [ -f /home/fbone/.cryptpad.desktop ]; then
431
-            mv /home/fbone/.cryptpad.desktop /home/fbone/Desktop/cryptpad.desktop
432
-        fi
433
-    fi
213
+    enable_mesh_seconary_wifi
434 214
 
435
-    iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
436
-    iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
437
-    iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT
438
-    iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT
439
-    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
440
-    iptables -A INPUT -p udp --dport 80 -j ACCEPT
441
-    iptables -A INPUT -p tcp --dport 548 -j ACCEPT
442
-    iptables -A INPUT -p udp --dport 548 -j ACCEPT
443
-    iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
444
-    iptables -A INPUT -p udp --dport 5353 -j ACCEPT
445
-    iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
446
-    iptables -A INPUT -p udp --dport 5354 -j ACCEPT
447
-    iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
448
-    iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
449
-    iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
450
-    iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
451
-    iptables -A INPUT -p udp --dport $TOX_PORT -j ACCEPT
452
-    iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
453
-    iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
454
-    iptables -A INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
455
-    # SSB/Scuttlebot/Patchwork
456
-    iptables -A INPUT -p tcp --dport $GIT_SSB_PORT -j ACCEPT
457
-    iptables -A INPUT -p udp --dport 8008 -j ACCEPT
458
-    iptables -A INPUT -p tcp --dport 8008 -j ACCEPT
459
-    iptables -A INPUT -p udp --dport 8010 -j ACCEPT
460
-    iptables -A INPUT -p tcp --dport 8010 -j ACCEPT
461
-    # vpn over the internet
462
-    # Note: the vpn firewall settings are needed in order for Patchwork
463
-    # to discover local peers
464
-    iptables -A INPUT -p tcp --dport 653 -j ACCEPT
465
-    iptables -A INPUT -p udp --dport 653 -j ACCEPT
466
-    iptables -A INPUT -i ${EIFACE} -m state --state NEW -p tcp --dport 1194 -j ACCEPT
467
-    iptables -A INPUT -i tun+ -j ACCEPT
468
-    iptables -A FORWARD -i tun+ -j ACCEPT
469
-    iptables -A FORWARD -i tun+ -o ${EIFACE} -m state --state RELATED,ESTABLISHED -j ACCEPT
470
-    iptables -A FORWARD -i ${EIFACE} -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
471
-    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ${EIFACE} -j MASQUERADE
472
-    iptables -A OUTPUT -o tun+ -j ACCEPT
473
-    echo 1 > /proc/sys/net/ipv4/ip_forward
474
-    sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
475
-    sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
476
-    sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' /etc/sysctl.conf
215
+    enable_mesh_firewall
477 216
 
478 217
     systemctl restart avahi-daemon
479 218
 
480
-    if [ -f /etc/scuttlebot/.ssb/config ]; then
481
-        ethernet_connected=$(cat /sys/class/net/eth0/carrier)
482
-        if [[ "$ethernet_connected" != "0" ]]; then
483
-            sed -i "s|\"host\": .*|\"host\": \"$(get_ipv4_wlan)\",|g" /etc/scuttlebot/.ssb/config
484
-            systemctl restart scuttlebot
485
-        else
486
-            if [ ! -f /etc/nginx/sites-available/git_ssb ]; then
487
-                systemctl stop scuttlebot
488
-            else
489
-                systemctl restart scuttlebot
490
-            fi
491
-        fi
492
-    fi
219
+    enable_mesh_scuttlebot
220
+    enable_mesh_tor
493 221
 
494
-    # if we have an ethernet connection to an internet router then create
495
-    # an onion address for this peer
496
-    if [[ "$ethernet_connected" != "0" ]]; then
497
-        systemctl enable tor
498
-        systemctl start tor
499
-        HIDDEN_SERVICE_PATH=/var/lib/tor/hidden_service_
500
-        if [ ! -f ${HIDDEN_SERVICE_PATH}mesh/hostname ]; then
501
-            echo "HiddenServiceDir ${HIDDEN_SERVICE_PATH}mesh/" >> /etc/tor/torrc
502
-            echo "HiddenServicePort 653 127.0.0.1:653" >> /etc/tor/torrc
503
-            systemctl restart tor
504
-        fi
505
-    else
506
-        systemctl stop tor
507
-        systemctl disable tor
508
-    fi
509
-
510
-    sed -i "s|\"host\":.*|\"host\": \"${HOSTNAME}.local\",|g" /etc/scuttlebot/.ssb/config
511 222
     sed -i "s|server_name .*|server_name ${HOSTNAME}.local;|g" /etc/nginx/sites-available/git_ssb
512
-    systemctl restart scuttlebot
223
+
513 224
     systemctl restart nginx
514 225
 
515 226
     verify

+ 301
- 0
src/freedombone-mesh-bmx6 Parādīt failu

@@ -0,0 +1,301 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Used to enable or disable BMX6 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
+update_wifi_adaptors
41
+
42
+if [ ! $IFACE ]; then
43
+    echo $'No wlan adaptor'
44
+    exit 0
45
+fi
46
+
47
+function status {
48
+    bmx6 -c status
49
+}
50
+
51
+function stop {
52
+    if [ -z "$IFACE" ]; then
53
+        echo 'error: unable to find wifi interface, not enabling BMX6 mesh'
54
+        return
55
+    fi
56
+
57
+    systemctl stop dnsmasq
58
+    systemctl disable dnsmasq
59
+    systemctl stop bmx6
60
+    systemctl disable bmx6
61
+
62
+    if [ "$EIFACE" ]; then
63
+        ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
64
+        if [[ "$ethernet_connected" != "0" ]]; then
65
+            systemctl stop hostapd
66
+            ifconfig $EIFACE down -promisc
67
+        fi
68
+    fi
69
+
70
+    avahi-autoipd -k $BRIDGE
71
+    avahi-autoipd -k $IFACE
72
+    ifconfig $IFACE down -promisc
73
+
74
+    ifconfig $IFACE mtu 1500
75
+    ifconfig $IFACE down
76
+    iwconfig $IFACE mode managed
77
+
78
+    if [ $IFACE_SECONDARY ]; then
79
+        systemctl stop hostapd
80
+        systemctl disable hostapd
81
+        ifconfig $IFACE_SECONDARY mtu 1500
82
+        ifconfig $IFACE_SECONDARY down
83
+        iwconfig $IFACE_SECONDARY mode managed
84
+    fi
85
+
86
+    disable_mesh_firewall
87
+
88
+    systemctl restart network-manager
89
+}
90
+
91
+function verify {
92
+    # TODO
93
+}
94
+
95
+function add_wifi_interface {
96
+    ifname=$1
97
+    ifssid=$WIFI_SSID
98
+    if [ $2 ]; then
99
+        ifssid=$2
100
+    fi
101
+    ifmode=ad-hoc
102
+    if [ $3 ]; then
103
+        ifmode=$3
104
+    fi
105
+    ifchannel=$CHANNEL
106
+    if [ $4 ]; then
107
+        ifchannel=$4
108
+    fi
109
+
110
+    ifconfig $ifname down
111
+    ifconfig $ifname mtu 1500
112
+    peermac=$(assign_peer_address)
113
+    if [ ! $peermac ]; then
114
+        echo $"Unable to obtain MAC address for $peermac on $ifname"
115
+        return
116
+    fi
117
+    ifconfig $ifname hw ether $peermac
118
+    echo $"$ifname assigned MAC address $peermac"
119
+    iwconfig $ifname enc off
120
+    iwconfig $ifname mode $ifmode essid $ifssid channel $ifchannel
121
+
122
+    ifconfig $ifname up
123
+}
124
+
125
+function start {
126
+    update_wifi_adaptors
127
+
128
+    if [ -z "$IFACE" ] ; then
129
+        echo 'error: unable to find wifi interface, not enabling BMX6 mesh'
130
+        exit 723657
131
+    fi
132
+    echo "info: enabling BMX6 mesh network $WIFI_SSID on $IFACE"
133
+
134
+    batman stop
135
+    systemctl stop network-manager
136
+    sleep 5
137
+
138
+    systemctl stop dnsmasq
139
+    systemctl disable dnsmasq
140
+
141
+    # remove an avahi service which isn't used
142
+    if [ -f /etc/avahi/services/udisks.service ]; then
143
+        sudo rm /etc/avahi/services/udisks.service
144
+    fi
145
+
146
+    global_rate_limit
147
+
148
+    # Might have to re-enable wifi
149
+    rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
150
+
151
+    secondary_wifi_available=
152
+    if [ $IFACE_SECONDARY ]; then
153
+        if [[ $IFACE != $IFACE_SECONDARY ]]; then
154
+            if [ -d /etc/hostapd ]; then
155
+                if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
156
+                    secondary_wifi_available=1
157
+                else
158
+                    echo $'Hotspot passphrase is too short'
159
+                fi
160
+            fi
161
+        fi
162
+    fi
163
+
164
+    add_wifi_interface $IFACE $WIFI_SSID ad-hoc $CHANNEL
165
+    ifconfig $IFACE up promisc
166
+
167
+    if [ ! $secondary_wifi_available ]; then
168
+        sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE}|g" /etc/systemd/system/bmx6.service
169
+    else
170
+        sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
171
+    fi
172
+
173
+    systemctl daemon-reload
174
+    systemctl enable bmx6
175
+    systemctl start bmx6
176
+
177
+    avahi-autoipd --force-bind --daemonize --wait $IFACE
178
+
179
+    # NOTE: Don't connect the secondary wifi device. hostapd will handle that by itself
180
+
181
+    ethernet_connected='0'
182
+    if [ "$EIFACE" ] ; then
183
+        ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
184
+        if [[ "$ethernet_connected" != "0" ]]; then
185
+            echo $'Trying ethernet bridge to the internet'
186
+            ifconfig $EIFACE up promisc
187
+            echo $'End of ethernet bridge'
188
+        else
189
+            echo $"$EIFACE is not connected"
190
+        fi
191
+    fi
192
+
193
+    enable_mesh_seconary_wifi
194
+
195
+    enable_mesh_firewall
196
+
197
+    systemctl restart avahi-daemon
198
+
199
+    enable_mesh_scuttlebot
200
+    enable_mesh_tor
201
+
202
+
203
+    sed -i "s|server_name .*|server_name ${HOSTNAME}.local;|g" /etc/nginx/sites-available/git_ssb
204
+
205
+    systemctl restart nginx
206
+
207
+    verify
208
+}
209
+
210
+function monitor {
211
+    if [ -z "$IFACE" ] ; then
212
+        echo 'error: unable to find wifi interface, not enabling BMX6 mesh'
213
+        exit 723657
214
+    fi
215
+
216
+    clear
217
+    echo ''
218
+    echo $'*** Stopping network ***'
219
+    echo ''
220
+
221
+    stop
222
+
223
+    echo "info: monitoring mesh network $WIFI_SSID on $IFACE"
224
+
225
+    systemctl stop network-manager
226
+    sleep 5
227
+
228
+    clear
229
+    echo ''
230
+    echo $'*** Setting firewall rate limit ***'
231
+    echo ''
232
+
233
+    global_rate_limit
234
+
235
+    clear
236
+    echo ''
237
+    echo $'*** Enabling wifi adaptor in monitor mode ***'
238
+    echo ''
239
+
240
+    # Might have to re-enable wifi
241
+    rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
242
+
243
+    ifconfig $IFACE down
244
+    ifconfig $IFACE mtu 1500
245
+    ifconfig $IFACE hw ether $(assign_peer_address)
246
+    iwconfig $IFACE enc off
247
+    iwconfig $IFACE mode monitor channel $CHANNEL
248
+    sleep 1
249
+    iwconfig $IFACE ap $CELLID
250
+
251
+    ifconfig $IFACE up
252
+
253
+    horst -i $IFACE
254
+
255
+    clear
256
+    echo ''
257
+    echo $'*** Restarting the network daemon. This may take a while. ***'
258
+    echo ''
259
+
260
+    start
261
+}
262
+
263
+if ! grep -q "$IFACE" /proc/net/dev; then
264
+    echo 'Interface $IFACE was not found'
265
+    stop
266
+    exit 1
267
+fi
268
+
269
+case "$1" in
270
+    start|stop|status|monitor)
271
+        $1
272
+        ;;
273
+    restart)
274
+        clear
275
+        echo ''
276
+        echo $'*** Stopping BMX6 mesh network connection ***'
277
+        echo ''
278
+        stop
279
+        sleep 10
280
+        clear
281
+        echo ''
282
+        echo $'*** Starting BMX6 mesh network connection ***'
283
+        echo ''
284
+        start
285
+        ;;
286
+    ping)
287
+        ping $2
288
+        ;;
289
+    data)
290
+        bmx6 -lc traffic=$IFACE
291
+        ;;
292
+    ls|list)
293
+        avahi-browse -atl
294
+        ;;
295
+    *)
296
+        echo "error: invalid parameter $1"
297
+        echo 'usage: $0 {start|stop|restart|status|ping|ls|list}'
298
+        exit 2
299
+        ;;
300
+esac
301
+exit 0

+ 343
- 0
src/freedombone-utils-mesh Parādīt failu

@@ -0,0 +1,343 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# mesh utilities used by the batman and bmx commands
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
+if [[ $1 == "start" ]]; then
32
+    # install avahi
33
+    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
34
+    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
35
+    sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf
36
+    sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf
37
+    sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf
38
+    sed -i "s|hosts:.*|hosts:          files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
39
+fi
40
+
41
+# Mesh definition
42
+WIFI_SSID='mesh'
43
+if [ -f $COMPLETION_FILE ]; then
44
+    if grep -q "WIFI_SSID:" $COMPLETION_FILE; then
45
+        WIFI_SSID=$(cat $COMPLETION_FILE | grep "WIFI_SSID:" | awk -F ':' '{print $2}')
46
+    fi
47
+    sed -i "s|WIFI_SSID:.*|WIFI_SSID:${WIFI_SSID}|g" $COMPLETION_FILE
48
+fi
49
+CELLID='any'
50
+
51
+CHANNEL=2
52
+HOTSPOT_CHANNEL=6
53
+if [ -f $COMPLETION_FILE ]; then
54
+    if grep -q "Wifi channel:" $COMPLETION_FILE; then
55
+        CHANNEL=$(cat $COMPLETION_FILE | grep "Wifi channel:" | awk -F ':' '{print $2}')
56
+    fi
57
+    sed -i "s|Wifi channel:.*|Wifi channel:${CHANNEL}|g" $COMPLETION_FILE
58
+fi
59
+
60
+ZERONET_PORT=15441
61
+IPFS_PORT=4001
62
+TOX_PORT=33445
63
+TRACKER_PORT=6969
64
+LIBREVAULT_PORT=42345
65
+TAHOELAFS_PORT=50213
66
+GIT_SSB_PORT=7718
67
+NGINX_GIT_SSB_PORT=7719
68
+
69
+# Ethernet bridge definition (bridged to bat0)
70
+BRIDGE=br-mesh
71
+BRIDGE_HOTSPOT=br-hotspot
72
+IFACE=
73
+IFACE_SECONDARY=
74
+EIFACE=eth0
75
+WLAN_ADAPTORS=$(count_wlan)
76
+
77
+if [ $WLAN_ADAPTORS -eq 0 ]; then
78
+    echo $'No wlan adaptors found'
79
+    exit 0
80
+fi
81
+
82
+function get_ipv4_wlan {
83
+    echo $(ip -o -f inet addr show dev "$IFACE" | awk '{print $4}' | awk 'END {print}' | awk -F '/' '{print $1}')
84
+}
85
+
86
+function mesh_hotspot_ip_address {
87
+    echo $(ip -o -f inet addr show dev "${BRIDGE}" | awk '{print $4}' | awk 'END {print}' | awk -F '/' '{print $1}')
88
+}
89
+
90
+function global_rate_limit {
91
+    if ! grep -q "tcp_challenge_ack_limit" /etc/sysctl.conf; then
92
+        echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> /etc/sysctl.conf
93
+    else
94
+        sed -i 's|net.ipv4.tcp_challenge_ack_limit.*|net.ipv4.tcp_challenge_ack_limit = 999999999|g' /etc/sysctl.conf
95
+    fi
96
+    sysctl -p -q
97
+}
98
+
99
+function assign_peer_address {
100
+    for i in {1..6}; do
101
+        number=$RANDOM
102
+        let "number %= 255"
103
+        octet=$(echo "obase=16;$number" | bc)
104
+        if [ ${#octet} -lt 2 ]; then
105
+            octet="0${octet}"
106
+        fi
107
+        if [ $i -gt 1 ]; then
108
+            echo -n ":"
109
+        fi
110
+        echo -n "${octet}"
111
+    done
112
+}
113
+
114
+function mesh_create_app_downloads_page {
115
+    if [ ! -d /root/$PROJECT_NAME/image_build/mesh_apps ]; then
116
+        return
117
+    fi
118
+    if [ ! -d /var/www/html ]; then
119
+        return
120
+    fi
121
+    # Don't go straight to cryptpad when navigating to the peer's IP address
122
+    if [ -L /etc/nginx/sites-enabled/cryptpad ]; then
123
+        rm /etc/nginx/sites-enabled/cryptpad
124
+        ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
125
+        if [ -d /etc/cryptpad ]; then
126
+            systemctl stop cryptpad
127
+            systemctl disable cryptpad
128
+        fi
129
+        systemctl restart nginx
130
+    fi
131
+    # Don't show the cryptpad icon on the desktop
132
+    if [ -f /home/fbone/Desktop/cryptpad.desktop ]; then
133
+        mv /home/fbone/Desktop/cryptpad.desktop /home/fbone/.cryptpad.desktop
134
+    fi
135
+
136
+    cp /root/$PROJECT_NAME/website/EN/meshindex.html /var/www/html/index.html
137
+    if [ ! -f /var/www/html/ssb.apk ]; then
138
+        cp /root/$PROJECT_NAME/image_build/mesh_apps/ssb.apk /var/www/html/ssb.apk
139
+    fi
140
+    if [ ! -f /var/www/html/trifa.apk ]; then
141
+        cp /root/$PROJECT_NAME/image_build/mesh_apps/trifa.apk /var/www/html/trifa.apk
142
+    fi
143
+    if [ ! -d /var/www/html/images ]; then
144
+        mkdir /var/www/html/images
145
+    fi
146
+    if [ ! -f /var/www/html/images/logo.png ]; then
147
+        cp /root/$PROJECT_NAME/img/logo.png /var/www/html/images/logo.png
148
+    fi
149
+    if [ ! -f /var/www/html/images/ssb.png ]; then
150
+        cp /root/$PROJECT_NAME/img/icon_patchwork.png /var/www/html/images/ssb.png
151
+    fi
152
+    if [ ! -f /var/www/html/images/trifa.png ]; then
153
+        cp /root/$PROJECT_NAME/img/trifa.png /var/www/html/images/trifa.png
154
+    fi
155
+    if [ ! -f /var/www/html/freedombone.css ]; then
156
+        cp /root/$PROJECT_NAME/website/freedombone.css /var/www/html/freedombone.css
157
+    fi
158
+    chown -R www-data:www-data /var/www/html/*
159
+}
160
+
161
+function enable_mesh_firewall {
162
+    iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
163
+    iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
164
+    iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT
165
+    iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT
166
+    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
167
+    iptables -A INPUT -p udp --dport 80 -j ACCEPT
168
+    iptables -A INPUT -p tcp --dport 548 -j ACCEPT
169
+    iptables -A INPUT -p udp --dport 548 -j ACCEPT
170
+    iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
171
+    iptables -A INPUT -p udp --dport 5353 -j ACCEPT
172
+    iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
173
+    iptables -A INPUT -p udp --dport 5354 -j ACCEPT
174
+    iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
175
+    iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
176
+    iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
177
+    iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
178
+    iptables -A INPUT -p udp --dport $TOX_PORT -j ACCEPT
179
+    iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
180
+    iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
181
+    iptables -A INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
182
+    # SSB/Scuttlebot/Patchwork
183
+    iptables -A INPUT -p tcp --dport $GIT_SSB_PORT -j ACCEPT
184
+    iptables -A INPUT -p udp --dport 8008 -j ACCEPT
185
+    iptables -A INPUT -p tcp --dport 8008 -j ACCEPT
186
+    iptables -A INPUT -p udp --dport 8010 -j ACCEPT
187
+    iptables -A INPUT -p tcp --dport 8010 -j ACCEPT
188
+    # vpn over the internet
189
+    # Note: the vpn firewall settings are needed in order for Patchwork
190
+    # to discover local peers
191
+    iptables -A INPUT -p tcp --dport 653 -j ACCEPT
192
+    iptables -A INPUT -p udp --dport 653 -j ACCEPT
193
+    iptables -A INPUT -i ${EIFACE} -m state --state NEW -p tcp --dport 1194 -j ACCEPT
194
+    iptables -A INPUT -i tun+ -j ACCEPT
195
+    iptables -A FORWARD -i tun+ -j ACCEPT
196
+    iptables -A FORWARD -i tun+ -o ${EIFACE} -m state --state RELATED,ESTABLISHED -j ACCEPT
197
+    iptables -A FORWARD -i ${EIFACE} -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
198
+    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ${EIFACE} -j MASQUERADE
199
+    iptables -A OUTPUT -o tun+ -j ACCEPT
200
+    echo 1 > /proc/sys/net/ipv4/ip_forward
201
+    sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
202
+    sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
203
+    sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' /etc/sysctl.conf
204
+}
205
+
206
+function disable_mesh_firewall {
207
+    iptables -D INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT
208
+    iptables -D INPUT -p udp --dport $TRACKER_PORT -j ACCEPT
209
+    iptables -D INPUT -p tcp --dport 80 -j ACCEPT
210
+    iptables -D INPUT -p udp --dport 80 -j ACCEPT
211
+    iptables -D INPUT -p tcp --dport 548 -j ACCEPT
212
+    iptables -D INPUT -p udp --dport 548 -j ACCEPT
213
+    iptables -D INPUT -p tcp --dport 5353 -j ACCEPT
214
+    iptables -D INPUT -p udp --dport 5353 -j ACCEPT
215
+    iptables -D INPUT -p tcp --dport 5354 -j ACCEPT
216
+    iptables -D INPUT -p udp --dport 5354 -j ACCEPT
217
+    iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT
218
+    iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT
219
+    iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
220
+    iptables -D INPUT -p udp --dport $IPFS_PORT -j ACCEPT
221
+    iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
222
+    iptables -D INPUT -p udp --dport $TOX_PORT -j ACCEPT
223
+    iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
224
+    iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
225
+    iptables -D INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
226
+    # SSB/Scuttlebot/Patchwork
227
+    iptables -D INPUT -p tcp --dport $GIT_SSB_PORT -j ACCEPT
228
+    iptables -D INPUT -p udp --dport 8008 -j ACCEPT
229
+    iptables -D INPUT -p tcp --dport 8008 -j ACCEPT
230
+    iptables -D INPUT -p udp --dport 8010 -j ACCEPT
231
+    iptables -D INPUT -p tcp --dport 8010 -j ACCEPT
232
+    # vpn over the internet
233
+    iptables -D INPUT -p tcp --dport 653 -j ACCEPT
234
+    iptables -D INPUT -p udp --dport 653 -j ACCEPT
235
+    iptables -D INPUT -i ${EIFACE} -m state --state NEW -p tcp --dport 1194 -j ACCEPT
236
+    iptables -D INPUT -i tun+ -j ACCEPT
237
+    iptables -D FORWARD -i tun+ -j ACCEPT
238
+    iptables -D FORWARD -i tun+ -o ${EIFACE} -m state --state RELATED,ESTABLISHED -j ACCEPT
239
+    iptables -D FORWARD -i ${EIFACE} -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
240
+    iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o ${EIFACE} -j MASQUERADE
241
+    iptables -D OUTPUT -o tun+ -j ACCEPT
242
+
243
+    echo 0 > /proc/sys/net/ipv4/ip_forward
244
+    sed -i 's|net.ipv4.ip_forward=.*|net.ipv4.ip_forward=0|g' /etc/sysctl.conf
245
+}
246
+
247
+function enable_mesh_scuttlebot {
248
+    if [ -f /etc/scuttlebot/.ssb/config ]; then
249
+        ethernet_connected=$(cat /sys/class/net/eth0/carrier)
250
+        if [[ "$ethernet_connected" != "0" ]]; then
251
+            sed -i "s|\"host\": .*|\"host\": \"$(get_ipv4_wlan)\",|g" /etc/scuttlebot/.ssb/config
252
+            systemctl restart scuttlebot
253
+        else
254
+            if [ ! -f /etc/nginx/sites-available/git_ssb ]; then
255
+                systemctl stop scuttlebot
256
+            else
257
+                systemctl restart scuttlebot
258
+            fi
259
+        fi
260
+    fi
261
+    sed -i "s|\"host\":.*|\"host\": \"${HOSTNAME}.local\",|g" /etc/scuttlebot/.ssb/config
262
+    systemctl restart scuttlebot
263
+}
264
+
265
+function enable_mesh_tor {
266
+    # if we have an ethernet connection to an internet router then create
267
+    # an onion address for this peer
268
+    if [[ "$ethernet_connected" != "0" ]]; then
269
+        systemctl enable tor
270
+        systemctl start tor
271
+        HIDDEN_SERVICE_PATH=/var/lib/tor/hidden_service_
272
+        if [ ! -f ${HIDDEN_SERVICE_PATH}mesh/hostname ]; then
273
+            echo "HiddenServiceDir ${HIDDEN_SERVICE_PATH}mesh/" >> /etc/tor/torrc
274
+            echo "HiddenServicePort 653 127.0.0.1:653" >> /etc/tor/torrc
275
+            systemctl restart tor
276
+        fi
277
+    else
278
+        systemctl stop tor
279
+        systemctl disable tor
280
+    fi
281
+}
282
+
283
+function enable_mesh_seconary_wifi {
284
+    if [ $secondary_wifi_available ]; then
285
+        sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
286
+
287
+        mesh_hotspot_address=$(mesh_hotspot_ip_address)
288
+        if [[ "$mesh_hotspot_address" == *'.'* ]]; then
289
+            echo "interface=${IFACE_SECONDARY}" > /etc/hostapd/hostapd.conf
290
+            echo "bridge=${BRIDGE}" >> /etc/hostapd/hostapd.conf
291
+            echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
292
+            echo "country_code=UK" >> /etc/hostapd/hostapd.conf
293
+            echo "ssid=${WIFI_SSID}-${mesh_hotspot_address}" >> /etc/hostapd/hostapd.conf
294
+            echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
295
+            echo "channel=${HOTSPOT_CHANNEL}" >> /etc/hostapd/hostapd.conf
296
+            echo 'wpa=2' >> /etc/hostapd/hostapd.conf
297
+            echo "wpa_passphrase=$HOTSPOT_PASSPHRASE" >> /etc/hostapd/hostapd.conf
298
+            echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
299
+            echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
300
+            echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
301
+            echo 'auth_algs=1' >> /etc/hostapd/hostapd.conf
302
+            echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
303
+
304
+            sed -i "s|#interface=.*|interface=${IFACE_SECONDARY}|g" /etc/dnsmasq.conf
305
+            sed -i "s|interface=.*|interface=${IFACE_SECONDARY}|g" /etc/dnsmasq.conf
306
+            sed -i "s|listen-address=.*|listen-address=127.0.0.1,$mesh_hotspot_address|g" /etc/dnsmasq.conf
307
+            sed -i 's|#listen-address|listen-address|g' /etc/dnsmasq.conf
308
+            systemctl enable dnsmasq
309
+            systemctl restart dnsmasq
310
+
311
+            systemctl enable hostapd
312
+            systemctl restart hostapd
313
+            mesh_create_app_downloads_page
314
+        else
315
+            secondary_wifi_available=
316
+            echo $'WARNING: No IP address could be obtained for the hotspot'
317
+        fi
318
+    fi
319
+
320
+    if [ ! $secondary_wifi_available ]; then
321
+        systemctl stop hostapd
322
+        systemctl disable hostapd
323
+
324
+        # Recreate the cryptpad symlink
325
+        if [ -f /etc/nginx/sites-available/cryptpad ]; then
326
+            if [ -L /etc/nginx/sites-enabled/cryptpad ]; then
327
+                rm /etc/nginx/sites-enabled/default
328
+            fi
329
+            systemctl enable cryptpad
330
+            systemctl start cryptpad
331
+
332
+            if [ ! -L /etc/nginx/sites-enabled/cryptpad ]; then
333
+                ln -s /etc/nginx/sites-available/cryptpad /etc/nginx/sites-enabled/cryptpad
334
+                systemctl restart nginx
335
+            fi
336
+        fi
337
+        if [ -f /home/fbone/.cryptpad.desktop ]; then
338
+            mv /home/fbone/.cryptpad.desktop /home/fbone/Desktop/cryptpad.desktop
339
+        fi
340
+    fi
341
+}
342
+
343
+# NOTE: deliberately there is no "exit 0"