freedombone-utils-mesh 18KB

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